• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

georgia-tech-db / eva / #832

12 Oct 2023 08:31AM UTC coverage: 0.0% (-68.5%) from 68.493%
#832

push

circle-ci

xzdandy
Minor

0 of 12331 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/evadb/executor/execution_context.py
1
# coding=utf-8
2
# Copyright 2018-2023 EvaDB
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
import os
×
16
import random
×
17
from typing import List
×
18

19
from evadb.configuration.configuration_manager import ConfigurationManager
×
20
from evadb.constants import NO_GPU
×
21
from evadb.utils.generic_utils import get_gpu_count, is_gpu_available
×
22

23

24
class Context:
×
25
    """
26
    Stores the context information of the executor, i.e.,
27
    if using spark, name of the application, current spark executors,
28
    if using horovod: current rank etc.
29
    """
30

31
    def __new__(cls):
×
32
        if not hasattr(cls, "_instance"):
×
33
            cls._instance = super(Context, cls).__new__(cls)
×
34
        return cls._instance
×
35

36
    def __init__(self):
×
37
        self._config_manager = ConfigurationManager()
×
38
        self._gpus = self._populate_gpu_ids()
×
39

40
    @property
×
41
    def gpus(self):
×
42
        return self._gpus
×
43

44
    def _populate_gpu_from_config(self) -> List:
×
45
        # Populate GPU IDs from yaml config file.
46
        gpu_conf = self._config_manager.get_value("executor", "gpu_ids")
×
47
        available_gpus = [i for i in range(get_gpu_count())]
×
48
        return list(set(available_gpus) & set(gpu_conf))
×
49

50
    def _populate_gpu_from_env(self) -> List:
×
51
        # Populate GPU IDs from env variable.
52
        gpu_conf = map(
×
53
            lambda x: x.strip(),
54
            os.environ.get("CUDA_VISIBLE_DEVICES", "").strip().split(","),
55
        )
56
        gpu_conf = list(filter(lambda x: x, gpu_conf))
×
57
        gpu_conf = [int(gpu_id) for gpu_id in gpu_conf]
×
58
        available_gpus = [i for i in range(get_gpu_count())]
×
59
        return list(set(available_gpus) & set(gpu_conf))
×
60

61
    def _populate_gpu_ids(self) -> List:
×
62
        # Populate available GPU IDs from Torch library. Then, select subset of GPUs
63
        # from available GPUs based on user configuration.
64
        if not is_gpu_available():
×
65
            return []
×
66
        gpus = self._populate_gpu_from_config()
×
67
        if len(gpus) == 0:
×
68
            gpus = self._populate_gpu_from_env()
×
69
        return gpus
×
70

71
    def _select_random_gpu(self) -> str:
×
72
        """
73
        A random GPU selection strategy
74
        Returns:
75
            (str): GPU device ID
76
        """
77
        return random.choice(self.gpus)
×
78

79
    def gpu_device(self) -> str:
×
80
        """
81
        Selects a GPU on which the task can be executed
82
        Returns:
83
             (str): GPU device ID
84
        """
85
        if self.gpus:
×
86
            # TODO: Should allow choosing GPU based on Spark and Horovod
87
            return self._select_random_gpu()
×
88
        return NO_GPU
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc