Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 1 | # Copyright lowRISC contributors. |
| 2 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | |
| 5 | import logging as log |
| 6 | import os |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 7 | |
Srikrishna Iyer | 37b0c99 | 2021-03-23 16:27:26 -0700 | [diff] [blame] | 8 | from Launcher import Launcher |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 9 | from LocalLauncher import LocalLauncher |
| 10 | from LsfLauncher import LsfLauncher |
Sharon Topaz | 1fb830b | 2021-06-03 22:22:56 +0300 | [diff] [blame] | 11 | from SgeLauncher import SgeLauncher |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 12 | |
| 13 | try: |
Udi Jonnalagadda | b6070c2 | 2021-04-20 10:46:50 -0700 | [diff] [blame] | 14 | from edacloudlauncher.EdaCloudLauncher import EdaCloudLauncher |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 15 | EDACLOUD_LAUNCHER_EXISTS = True |
| 16 | except ImportError: |
| 17 | EDACLOUD_LAUNCHER_EXISTS = False |
| 18 | |
Srikrishna Iyer | 37b0c99 | 2021-03-23 16:27:26 -0700 | [diff] [blame] | 19 | # The chosen launcher class. |
Srikrishna Iyer | 206721c | 2021-04-15 15:23:08 -0700 | [diff] [blame] | 20 | _LAUNCHER_CLS = None |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 21 | |
| 22 | |
| 23 | def 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 Iyer | 37b0c99 | 2021-03-23 16:27:26 -0700 | [diff] [blame] | 36 | Launcher.variant = launcher |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 37 | |
Srikrishna Iyer | 206721c | 2021-04-15 15:23:08 -0700 | [diff] [blame] | 38 | global _LAUNCHER_CLS |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 39 | if launcher == "local": |
Srikrishna Iyer | 206721c | 2021-04-15 15:23:08 -0700 | [diff] [blame] | 40 | _LAUNCHER_CLS = LocalLauncher |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 41 | |
| 42 | elif launcher == "lsf": |
Srikrishna Iyer | 206721c | 2021-04-15 15:23:08 -0700 | [diff] [blame] | 43 | _LAUNCHER_CLS = LsfLauncher |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 44 | |
Sharon Topaz | 1fb830b | 2021-06-03 22:22:56 +0300 | [diff] [blame] | 45 | elif launcher == "sge": |
| 46 | _LAUNCHER_CLS = SgeLauncher |
| 47 | |
Srikrishna Iyer | 37b0c99 | 2021-03-23 16:27:26 -0700 | [diff] [blame] | 48 | # These custom launchers are site specific. They may not be committed to |
| 49 | # the open source repo. |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 50 | elif launcher == "edacloud" and EDACLOUD_LAUNCHER_EXISTS: |
Srikrishna Iyer | 206721c | 2021-04-15 15:23:08 -0700 | [diff] [blame] | 51 | _LAUNCHER_CLS = EdaCloudLauncher |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 52 | |
| 53 | else: |
| 54 | log.error("Launcher {} set using DVSIM_LAUNCHER env var does not " |
| 55 | "exist. Using local launcher instead.".format(launcher)) |
Srikrishna Iyer | 206721c | 2021-04-15 15:23:08 -0700 | [diff] [blame] | 56 | _LAUNCHER_CLS = LocalLauncher |
| 57 | |
| 58 | |
| 59 | def get_launcher_cls(): |
| 60 | '''Returns the chosen launcher class.''' |
| 61 | |
| 62 | assert _LAUNCHER_CLS is not None |
| 63 | return _LAUNCHER_CLS |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 64 | |
| 65 | |
| 66 | def 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 Iyer | 206721c | 2021-04-15 15:23:08 -0700 | [diff] [blame] | 72 | assert _LAUNCHER_CLS is not None |
| 73 | return _LAUNCHER_CLS(deploy) |