COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
context.py
1 
37 
38 from carmaWrap import context
39 import numpy as np
40 
41 
42 class Context:
43  """
44  Python class for wrapping a CarmaContext
45  """
46 
47  def __init__(self, devices=None):
48  """ Initializes a Context object
49 
50  Parameters
51  ------------
52  devices: (list): (optionnal) list of devices to use. Default is 0
53  """
54  if devices is None:
55  self.context = context.get_instance_1gpu(0)
56  self.devices = 0
57  else:
58  if isinstance(devices, list):
59  devices = np.array(devices, dtype=np.int32)
60  else:
61  raise TypeError("Devices must be a list of integer")
62  self.devices = devices
63  self.context = context.get_instance_ngpu(devices)
64 
65  def getActiveDevice(self):
66  """ Return the index of the current active device """
67  return self.context.active_device
68 
69  def setActiveDevice(self, index: int):
70  """ Set the device index as the active device """
71  if index in self.devices:
72  self.context.set_active_device(index)
73  else:
74  raise ValueError("Index given is not valid")
75 
76  def enableTensorCores(self):
77  """ Enable the tensor cores math mode """
78  self.context.activate_tensor_cores(True)
79 
80  def disableTensorCores(self):
81  """ Disable the tensor cores math mode """
82  self.context.activate_tensor_cores(True)
naga.context.Context.devices
devices
Definition: context.py:56
naga.context.Context
Python class for wrapping a CarmaContext.
Definition: context.py:45
naga.context.Context.context
context
Definition: context.py:55
set_active_device
#define set_active_device(new_device, silent)
Definition: carma_context.h:97
naga.context.Context.disableTensorCores
def disableTensorCores(self)
Disable the tensor cores math mode.
Definition: context.py:81
naga.context.Context.setActiveDevice
def setActiveDevice(self, int index)
Set the device index as the active device.
Definition: context.py:70
naga.context.Context.enableTensorCores
def enableTensorCores(self)
Enable the tensor cores math mode.
Definition: context.py:77
naga.context.Context.getActiveDevice
def getActiveDevice(self)
Return the index of the current active device.
Definition: context.py:66
naga.context.Context.__init__
def __init__(self, devices=None)
Initializes a Context object.
Definition: context.py:53