warp_drive.managers.pycuda_managers package¶
Submodules¶
warp_drive.managers.pycuda_managers.pycuda_data_manager module¶
- class warp_drive.managers.pycuda_managers.pycuda_data_manager.CudaTensorHolder(t)¶
Bases:
pycuda._driver.PointerHolderBase
A class that facilitates casting tensors to pointers.
- class warp_drive.managers.pycuda_managers.pycuda_data_manager.PyCUDADataManager(num_agents: Optional[int] = None, num_envs: Optional[int] = None, blocks_per_env: int = 1, episode_length: Optional[int] = None)¶
Bases:
warp_drive.managers.data_manager.CUDADataManager
- pull_data_from_device(name: str)¶
Fetch the values of device array back to the host
- Parameters
name – name of the device array
returns: a host copy of scalar data or numpy array fetched back from the device array
- reset_device(name: Optional[str] = None)¶
Reset the device array values back to the host array values Note: this reset is not a device-only execution, but incurs data transfer from host to device
- Parameters
name – (optional) reset a device array by name, if None, reset all arrays
warp_drive.managers.pycuda_managers.pycuda_function_manager module¶
- class warp_drive.managers.pycuda_managers.pycuda_function_manager.PyCUDAEnvironmentReset(function_manager: warp_drive.managers.pycuda_managers.pycuda_function_manager.PyCUDAFunctionManager)¶
Bases:
warp_drive.managers.function_manager.CUDAEnvironmentReset
PyCUDA Environment Reset: Manages the env reset when the game is terminated inside GPU. With this, the GPU can automatically reset and restart example_envs by itself.
prerequisite: PyCUDAFunctionManager is initialized, and the default function list has been successfully launched
Example
Please refer to tutorials
- custom_reset(args: Optional[list] = None, block=None, grid=None)¶
- register_custom_reset_function(data_manager: warp_drive.managers.pycuda_managers.pycuda_data_manager.PyCUDADataManager, reset_function_name=None)¶
- reset_when_done_deterministic(data_manager: warp_drive.managers.pycuda_managers.pycuda_data_manager.PyCUDADataManager, mode: str = 'if_done', undo_done_after_reset: bool = True)¶
Monitor the done flag for each env. If any env is done, it will reset this particular env without interrupting other example_envs. The reset includes copy the starting values of this env back, and turn off the done flag. Therefore, this env can safely get restarted.
- Parameters
data_manager – PyCUDADataManager object
mode – “if_done”: reset an env if done flag is observed for that env, “force_reset”: reset all env in a hard way
undo_done_after_reset – If True, turn off the done flag
and reset timestep after all data have been reset (the flag should be True for most cases)
- class warp_drive.managers.pycuda_managers.pycuda_function_manager.PyCUDAFunctionManager(num_agents: int = 1, num_envs: int = 1, blocks_per_env: int = 1, process_id: int = 0)¶
Bases:
warp_drive.managers.function_manager.CUDAFunctionManager
- property compile¶
- compile_and_load_cuda(env_name: str, template_header_file: str, template_runner_file: str, template_path: Optional[str] = None, default_functions_included: bool = True, customized_env_registrar: Optional[warp_drive.utils.env_registrar.EnvironmentRegistrar] = None, event_messenger=None)¶
Compile a template source code, so self.num_agents and self.num_envs will replace the template code at compile time. Note: self.num_agents: total number of agents for each env, it defines the default block size self.num_envs: number of example_envs in parallel,
it defines the default grid size
- Parameters
env_name – name of the environment for the build
template_header_file – template header, e.g., “template_env_config.h”
template_runner_file – template runner, e.g., “template_env_runner.cu”
template_path – template path, by default,
it is f”{ROOT_PATH}/warp_drive/cuda_includes/” :param default_functions_included: load default function lists :param customized_env_registrar: CustomizedEnvironmentRegistrar object
it provides the customized env info (e.g., source code path)for the build
- Parameters
event_messenger – multiprocessing Event to sync up the build
when using multiple processes
- property cuda_function_names¶
- initialize_default_functions()¶
Default function list defined in the src/core. They can be initialized if the CUDA compilation includes src/core
- initialize_functions(func_names: Optional[list] = None)¶
- Parameters
func_names – list of kernel function names in the cuda mdoule
Initialize the shared constants in the runtime. :param data_manager: PyCUDADataManager object :param constant_names: names of constants managed by CUDADataManager
- load_cuda_from_binary_file(cubin: str, default_functions_included: bool = True)¶
Load cuda module from the pre-compiled cubin file
- Parameters
cubin – the binary (.cubin) directory
default_functions_included – load default function lists
- load_cuda_from_source_code(code: str, default_functions_included: bool = True)¶
Load cuda module from the source code NOTE: the source code is in string text format, not the directory of the source code. :param code: source code in the string text format :param default_functions_included: load default function lists
- class warp_drive.managers.pycuda_managers.pycuda_function_manager.PyCUDALogController(function_manager: warp_drive.managers.pycuda_managers.pycuda_function_manager.PyCUDAFunctionManager)¶
Bases:
warp_drive.managers.function_manager.CUDALogController
PyCUDA Log Controller: manages the CUDA logger inside GPU for all the data having the flag log_data_across_episode = True. The log function will only work for one particular env, even there are multiple example_envs running together.
prerequisite: PyCUDAFunctionManager is initialized, and the default function list has been successfully launched
Example
Please refer to tutorials
- class warp_drive.managers.pycuda_managers.pycuda_function_manager.PyCUDASampler(function_manager: warp_drive.managers.pycuda_managers.pycuda_function_manager.PyCUDAFunctionManager)¶
Bases:
warp_drive.managers.function_manager.CUDASampler
PyCUDA Sampler: controls probability sampling inside GPU. A fast and lightweight implementation compared to the functionality provided by torch.Categorical.sample() It accepts the Pytorch tensor as distribution and gives out the sampled action index
prerequisite: PyCUDAFunctionManager is initialized, and the default function list has been successfully launched
Example
Please refer to tutorials
- static assign(data_manager: warp_drive.managers.pycuda_managers.pycuda_data_manager.PyCUDADataManager, actions: numpy.ndarray, action_name: str)¶
Assign action to the action array directly. T his may be used for env testing or debugging purpose. :param data_manager: PyCUDADataManager object :param actions: actions array provided by the user :param action_name: the name of action array that will record the sampled actions
- init_random(seed: Optional[int] = None)¶
Init random function for all the threads :param seed: random seed selected for the initialization
- sample(data_manager: warp_drive.managers.pycuda_managers.pycuda_data_manager.PyCUDADataManager, distribution: torch.Tensor, action_name: str)¶
Sample based on the distribution
- Parameters
data_manager – PyCUDADataManager object
distribution – Torch distribution tensor in the shape of
(num_env, num_agents, num_actions) :param action_name: the name of action array that will record the sampled actions