Module: Cumo::CUDA::Driver
- Defined in:
- ext/cumo/cuda/driver.c
Constant Summary collapse
- CU_JIT_INPUT_CUBIN =
INT2NUM(CU_JIT_INPUT_CUBIN)
- CU_JIT_INPUT_FATBINARY =
INT2NUM(CU_JIT_INPUT_FATBINARY)
- CU_JIT_INPUT_LIBRARY =
INT2NUM(CU_JIT_INPUT_LIBRARY)
- CU_JIT_INPUT_OBJECT =
INT2NUM(CU_JIT_INPUT_OBJECT)
- CU_JIT_INPUT_PTX =
INT2NUM(CU_JIT_INPUT_PTX)
Class Method Summary collapse
-
.cuCtxCreate(flags, dev) ⇒ Object
////////////////////////////////////////////.
- .cuCtxGetCurrent ⇒ Object
-
.cuDeviceGet(ordinal) ⇒ Object
////////////////////////////////////////////.
-
.cuLinkAddData(state, type, data, name) ⇒ Object
TODO(sonots): Support options.
-
.cuLinkAddFile(state, type, path) ⇒ Object
TODO(sonots): Support options.
- .cuLinkComplete(state) ⇒ Object
-
.cuLinkCreate ⇒ Object
TODO(sonots): Support options.
- .cuLinkDestroy(state) ⇒ Object
- .cuModuleGetFunction(hmod, name) ⇒ Object
- .cuModuleGetGlobal(hmod, name) ⇒ Object
- .cuModuleLoad(fname) ⇒ Object
- .cuModuleLoadData(image) ⇒ Object
- .cuModuleUnload(hmod) ⇒ Object
Class Method Details
.cuCtxCreate(flags, dev) ⇒ Object
////////////////////////////////////////////
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'ext/cumo/cuda/driver.c', line 32 static VALUE rb_cuCtxCreate(VALUE self, VALUE flags, VALUE dev) { unsigned int _flags = NUM2INT(flags); CUdevice _dev = (CUdevice)NUM2INT(dev); CUcontext _pctx; CUresult status; #if defined(CUDA_VERSION) && CUDA_VERSION >= 13000 status = cuCtxCreate(&_pctx, NULL, _flags, _dev); #else status = cuCtxCreate(&_pctx, _flags, _dev); #endif check_status(status); return SIZET2NUM((size_t)_pctx); } |
.cuCtxGetCurrent ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'ext/cumo/cuda/driver.c', line 50 static VALUE rb_cuCtxGetCurrent(VALUE self) { CUcontext ctx; CUresult status; status = cuCtxGetCurrent(&ctx); check_status(status); return SIZET2NUM((size_t)ctx); } |
.cuDeviceGet(ordinal) ⇒ Object
////////////////////////////////////////////
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'ext/cumo/cuda/driver.c', line 66 static VALUE rb_cuDeviceGet(VALUE self, VALUE ordinal) { int _ordinal = NUM2INT(ordinal); CUdevice _device; CUresult status; status = cuDeviceGet(&_device, _ordinal); check_status(status); return INT2NUM(_device); } |
.cuLinkAddData(state, type, data, name) ⇒ Object
TODO(sonots): Support options.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'ext/cumo/cuda/driver.c', line 104 static VALUE rb_cuLinkAddData(VALUE self, VALUE state, VALUE type, VALUE data, VALUE name) { CUjitInputType _type = (CUjitInputType)NUM2INT(type); // The image may be a cubin, so it is taken by length and allowed to hold // NUL bytes; the name is a plain C string cuLinkAddData reports errors with. void* _data = (void *)StringValuePtr(data); size_t _size = RSTRING_LEN(data); const char* _name = StringValueCStr(name); CUlinkState _state = (CUlinkState)cumo_cuda_handle_get(&link_states, state, "CUlinkState"); CUresult status; struct cuLinkAddDataParam param = {_state, _type, _data, _size, _name, 0, (CUjit_option*)0, (void**)0}; status = (CUresult)rb_thread_call_without_gvl(cuLinkAddData_without_gvl_cb, ¶m, NULL, NULL); //status = cuLinkAddData(_state, _type, _data, _size, _name, 0, (CUjit_option*)0, (void**)0); RB_GC_GUARD(data); RB_GC_GUARD(name); check_status(status); return Qnil; } |
.cuLinkAddFile(state, type, path) ⇒ Object
TODO(sonots): Support options.
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'ext/cumo/cuda/driver.c', line 145 static VALUE rb_cuLinkAddFile(VALUE self, VALUE state, VALUE type, VALUE path) { CUjitInputType _type = (CUjitInputType)NUM2INT(type); const char* _path = StringValueCStr(path); CUlinkState _state = (CUlinkState)cumo_cuda_handle_get(&link_states, state, "CUlinkState"); CUresult status; struct cuLinkAddFileParam param = {_state, _type, _path, 0, (CUjit_option*)0, (void **)0}; status = (CUresult)rb_thread_call_without_gvl(cuLinkAddFile_without_gvl_cb, ¶m, NULL, NULL); //status = cuLinkAddFile(_state, _type, _path, 0, (CUjit_option*)0, (void **)0); RB_GC_GUARD(path); check_status(status); return Qnil; } |
.cuLinkComplete(state) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'ext/cumo/cuda/driver.c', line 177 static VALUE rb_cuLinkComplete(VALUE self, VALUE state) { CUlinkState _state = (CUlinkState)cumo_cuda_handle_get(&link_states, state, "CUlinkState"); void* _cubinOut; size_t _sizeOut; CUresult status; struct cuLinkCompleteParam param = {_state, &_cubinOut, &_sizeOut}; status = (CUresult)rb_thread_call_without_gvl(cuLinkComplete_without_gvl_cb, ¶m, NULL, NULL); //status = cuLinkComplete(_state, &_cubinOut, &_sizeOut); check_status(status); return rb_str_new((char *)_cubinOut, _sizeOut); } |
.cuLinkCreate ⇒ Object
TODO(sonots): Support options.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'ext/cumo/cuda/driver.c', line 210 static VALUE rb_cuLinkCreate(VALUE self) { CUlinkState state; CUresult status; struct cuLinkCreateParam param = {0, (CUjit_option*)0, (void**)0, &state}; status = (CUresult)rb_thread_call_without_gvl(cuLinkCreate_without_gvl_cb, ¶m, NULL, NULL); //status = cuLinkCreate(0, (CUjit_option*)0, (void**)0, &state); check_status(status); cumo_cuda_handle_set_add(&link_states, (size_t)state); return SIZET2NUM((size_t)state); } |
.cuLinkDestroy(state) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'ext/cumo/cuda/driver.c', line 238 static VALUE rb_cuLinkDestroy(VALUE self, VALUE state) { CUlinkState _state = (CUlinkState)cumo_cuda_handle_take(&link_states, state, "CUlinkState"); CUresult status; struct cuLinkDestroyParam param = {_state}; status = (CUresult)rb_thread_call_without_gvl(cuLinkDestroy_without_gvl_cb, ¶m, NULL, NULL); //status = cuLinkDestroy(_state); check_status(status); return Qnil; } |
.cuModuleGetFunction(hmod, name) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'ext/cumo/cuda/driver.c', line 267 static VALUE rb_cuModuleGetFunction(VALUE self, VALUE hmod, VALUE name) { CUfunction _hfunc; const char* _name = StringValueCStr(name); CUmodule _hmod = (CUmodule)cumo_cuda_handle_get(&modules, hmod, "CUmodule"); CUresult status; struct cuModuleGetFunctionParam param = {&_hfunc, _hmod, _name}; status = (CUresult)rb_thread_call_without_gvl(cuModuleGetFunction_without_gvl_cb, ¶m, NULL, NULL); //status = cuModuleGetFunction(&_hfunc, _hmod, _name); RB_GC_GUARD(name); check_status(status); return SIZET2NUM((size_t)_hfunc); } |
.cuModuleGetGlobal(hmod, name) ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'ext/cumo/cuda/driver.c', line 300 static VALUE rb_cuModuleGetGlobal(VALUE self, VALUE hmod, VALUE name) { CUdeviceptr _dptr; size_t _bytes; const char* _name = StringValueCStr(name); CUmodule _hmod = (CUmodule)cumo_cuda_handle_get(&modules, hmod, "CUmodule"); CUresult status; VALUE ret; struct cuModuleGetGlobalParam param = {&_dptr, &_bytes, _hmod, _name}; status = (CUresult)rb_thread_call_without_gvl(cuModuleGetGlobal_without_gvl_cb, ¶m, NULL, NULL); //status = cuModuleGetGlobal(&_dptr, &_bytes, _hmod, _name); RB_GC_GUARD(name); check_status(status); // _dptr addresses device memory, which the host cannot read directly. ret = rb_str_new(NULL, (long)_bytes); check_status(cuMemcpyDtoH(RSTRING_PTR(ret), _dptr, _bytes)); return ret; } |
.cuModuleLoad(fname) ⇒ Object
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'ext/cumo/cuda/driver.c', line 337 static VALUE rb_cuModuleLoad(VALUE self, VALUE fname) { CUmodule _module; const char* _fname = StringValueCStr(fname); CUresult status; struct cuModuleLoadParam param = {&_module, _fname}; status = (CUresult)rb_thread_call_without_gvl(cuModuleLoad_without_gvl_cb, ¶m, NULL, NULL); //status = cuModuleLoad(&_module, _fname); RB_GC_GUARD(fname); check_status(status); cumo_cuda_handle_set_add(&modules, (size_t)_module); return SIZET2NUM((size_t)_module); } |
.cuModuleLoadData(image) ⇒ Object
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'ext/cumo/cuda/driver.c', line 368 static VALUE rb_cuModuleLoadData(VALUE self, VALUE image) { CUmodule _module; // A cubin is binary, so the image is not required to be NUL-free. const void* _image = (void*)StringValuePtr(image); CUresult status; struct cuModuleLoadDataParam param = {&_module, _image}; status = (CUresult)rb_thread_call_without_gvl(cuModuleLoadData_without_gvl_cb, ¶m, NULL, NULL); //status = cuModuleLoadData(&_module, _image); RB_GC_GUARD(image); check_status(status); cumo_cuda_handle_set_add(&modules, (size_t)_module); return SIZET2NUM((size_t)_module); } |
.cuModuleUnload(hmod) ⇒ Object
399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'ext/cumo/cuda/driver.c', line 399 static VALUE rb_cuModuleUnload(VALUE self, VALUE hmod) { CUmodule _hmod = (CUmodule)cumo_cuda_handle_take(&modules, hmod, "CUmodule"); CUresult status; struct cuModuleUnloadParam param = {_hmod}; status = (CUresult)rb_thread_call_without_gvl(cuModuleUnload_without_gvl_cb, ¶m, NULL, NULL); //status = cuModuleUnload(_hmod); check_status(status); return Qnil; } |