File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed
Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -223,6 +223,21 @@ $ python3 -m unittest discover -v
223223inside the build directory in the folder with python wrapper ` python/pycubool/` .
224224So, the wrapper will be able to automatically locate required lib file.
225225
226+ # ## Python package runtime config
227+
228+ ** Pycubool** Python-package can be configured before import by the following environment variables:
229+
230+ - ` CUBOOL_PATH` - custom path to compiled cubool library object.
231+ Without that variable by default the package will try to find library in the package folder.
232+
233+ - ` CUBOOL_BACKEND` - allows to select backend for execution.
234+ By default library selects cuda if present. Pass value ` cpu` to force cpu computations,
235+ even if cuda backend is presented and supported for selection.
236+
237+ - ` CUBOOL_MEM` - type of the memory to use if run computations in cuda backend.
238+ By default library uses device memory. If pass in the variable value ` managed` , then
239+ backend will be configured to use cuda managed memory for resources allocation.
240+
226241# # Usage
227242
228243The following C++ code snipped demonstrates, how library functions and
Original file line number Diff line number Diff line change @@ -278,7 +278,7 @@ namespace cubool {
278278 << " sharedMemoryPerBlockKiBs: " << caps.sharedMemoryPerBlockKiBs ;
279279 }
280280 else {
281- stream << " Cuda device is not presented" ;
281+ stream << " Cuda device is not presented (fallback to cpu backend) " ;
282282 }
283283
284284 stream << LogStream::cmt;
Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ class Wrapper:
4444
4545 def __init__ (self ):
4646 self .loaded_dll = None
47+ self .is_managed = Wrapper .__get_use_managed_mem ()
48+ self .force_cpu = Wrapper .__get_force_cpu ()
4749
4850 try :
4951 # Try from config if present
@@ -62,7 +64,9 @@ def __del__(self):
6264 self .__release_library ()
6365
6466 def __setup_library (self ):
65- status = self .loaded_dll .cuBool_Initialize (ctypes .c_uint (bridge .get_init_hints (False , False )))
67+ status = self .loaded_dll .cuBool_Initialize (ctypes .c_uint (bridge .get_init_hints (
68+ force_cpu_backend = self .force_cpu , is_gpu_mem_managed = self .is_managed )))
69+
6670 bridge .check (status )
6771
6872 def __release_library (self ):
@@ -76,3 +80,19 @@ def __get_lib_path(cls, prefix):
7680 return prefix / entry
7781
7882 return None
83+
84+ @classmethod
85+ def __get_force_cpu (cls ):
86+ try :
87+ memory = os .environ ["CUBOOL_BACKEND" ]
88+ return True if memory .lower () == "cpu" else False
89+ except KeyError :
90+ return False
91+
92+ @classmethod
93+ def __get_use_managed_mem (cls ):
94+ try :
95+ memory = os .environ ["CUBOOL_MEM" ]
96+ return True if memory .lower () == "managed" else False
97+ except KeyError :
98+ return False
You can’t perform that action at this time.
0 commit comments