blob: 3829187c8b844344aebf0d3387e57e83b5b1862d [file] [log] [blame]
Srikrishna Iyer9d9d86f2021-03-02 00:15:51 -08001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4
5import logging as log
6import os
Srikrishna Iyer9d9d86f2021-03-02 00:15:51 -08007
Srikrishna Iyer37b0c992021-03-23 16:27:26 -07008from Launcher import Launcher
Srikrishna Iyer9d9d86f2021-03-02 00:15:51 -08009from LocalLauncher import LocalLauncher
10from LsfLauncher import LsfLauncher
Sharon Topaz1fb830b2021-06-03 22:22:56 +030011from SgeLauncher import SgeLauncher
Srikrishna Iyer9d9d86f2021-03-02 00:15:51 -080012
13try:
Udi Jonnalagaddab6070c22021-04-20 10:46:50 -070014 from edacloudlauncher.EdaCloudLauncher import EdaCloudLauncher
Srikrishna Iyer9d9d86f2021-03-02 00:15:51 -080015 EDACLOUD_LAUNCHER_EXISTS = True
16except ImportError:
17 EDACLOUD_LAUNCHER_EXISTS = False
18
Srikrishna Iyer37b0c992021-03-23 16:27:26 -070019# The chosen launcher class.
Srikrishna Iyer206721c2021-04-15 15:23:08 -070020_LAUNCHER_CLS = None
Srikrishna Iyer9d9d86f2021-03-02 00:15:51 -080021
22
23def set_launcher_type(is_local=False):
24 '''Sets the launcher type that will be used to launch the jobs.
25
26 The env variable `DVSIM_LAUNCHER` is used to identify what launcher system
27 to use. This variable is specific to the user's work site. It is meant to
28 be set externally before invoking DVSim. Valid values are [local, lsf,
29 edacloud]. If --local arg is supplied then the local launcher takes
30 precedence.
31 '''
32
33 launcher = os.environ.get("DVSIM_LAUNCHER", "local")
34 if is_local:
35 launcher = "local"
Srikrishna Iyer37b0c992021-03-23 16:27:26 -070036 Launcher.variant = launcher
Srikrishna Iyer9d9d86f2021-03-02 00:15:51 -080037
Srikrishna Iyer206721c2021-04-15 15:23:08 -070038 global _LAUNCHER_CLS
Srikrishna Iyer9d9d86f2021-03-02 00:15:51 -080039 if launcher == "local":
Srikrishna Iyer206721c2021-04-15 15:23:08 -070040 _LAUNCHER_CLS = LocalLauncher
Srikrishna Iyer9d9d86f2021-03-02 00:15:51 -080041
42 elif launcher == "lsf":
Srikrishna Iyer206721c2021-04-15 15:23:08 -070043 _LAUNCHER_CLS = LsfLauncher
Srikrishna Iyer9d9d86f2021-03-02 00:15:51 -080044
Sharon Topaz1fb830b2021-06-03 22:22:56 +030045 elif launcher == "sge":
46 _LAUNCHER_CLS = SgeLauncher
47
Srikrishna Iyer37b0c992021-03-23 16:27:26 -070048 # These custom launchers are site specific. They may not be committed to
49 # the open source repo.
Srikrishna Iyer9d9d86f2021-03-02 00:15:51 -080050 elif launcher == "edacloud" and EDACLOUD_LAUNCHER_EXISTS:
Srikrishna Iyer206721c2021-04-15 15:23:08 -070051 _LAUNCHER_CLS = EdaCloudLauncher
Srikrishna Iyer9d9d86f2021-03-02 00:15:51 -080052
53 else:
54 log.error("Launcher {} set using DVSIM_LAUNCHER env var does not "
55 "exist. Using local launcher instead.".format(launcher))
Srikrishna Iyer206721c2021-04-15 15:23:08 -070056 _LAUNCHER_CLS = LocalLauncher
57
58
59def get_launcher_cls():
60 '''Returns the chosen launcher class.'''
61
62 assert _LAUNCHER_CLS is not None
63 return _LAUNCHER_CLS
Srikrishna Iyer9d9d86f2021-03-02 00:15:51 -080064
65
66def get_launcher(deploy):
67 '''Returns an instance of a launcher.
68
69 'deploy' is an instance of the deploy class to with the launcher is paired.
70 '''
71
Srikrishna Iyer206721c2021-04-15 15:23:08 -070072 assert _LAUNCHER_CLS is not None
73 return _LAUNCHER_CLS(deploy)