Module: Ignis::CUDA::RuntimeAPI
- Defined in:
- lib/nvruby/cuda/runtime_api.rb
Overview
CUDA Runtime API — Fiddle-only hot-path bindings.
Rule: This file uses ONLY Fiddle for hot-path calls (malloc, free, memcpy, stream, event, sync). FFI struct calls (cudaGetDeviceProperties) live in device_props.rb (Rule 4: never mix FFI and Fiddle in the same file).
Cross-platform: Uses Ignis::Platform to resolve cudart path on Windows/Linux.
Constant Summary collapse
- MEMCPY_HOST_TO_HOST =
CUDA memory copy directions
0- MEMCPY_HOST_TO_DEVICE =
1- MEMCPY_DEVICE_TO_HOST =
2- MEMCPY_DEVICE_TO_DEVICE =
3- MEMCPY_DEFAULT =
4- DEVICE_SCHEDULE_AUTO =
CUDA device flags
0- DEVICE_SCHEDULE_SPIN =
1- DEVICE_SCHEDULE_YIELD =
2- DEVICE_SCHEDULE_BLOCKING_SYNC =
4- DEVICE_MAP_HOST =
8- DEVICE_LMEM_RESIZE_TO_MAX =
16- HOST_ALLOC_DEFAULT =
CUDA host alloc flags
0- HOST_ALLOC_PORTABLE =
1- HOST_ALLOC_MAPPED =
2- HOST_ALLOC_WRITECOMBINED =
4- CUDART_LIB =
Resolve CUDA runtime library path at load time. Uses Ignis::Platform if available, falls back to OS detection.
if defined?(Ignis::Platform) Ignis::Platform.cudart_path elsif RUBY_PLATFORM.match?(/mswin|mingw|cygwin/i) File.join('C:', 'Program Files', 'NVIDIA GPU Computing Toolkit', 'CUDA', 'v13.0', 'bin', 'cudart64_130.dll') else 'libcudart.so.13' end
Class Attribute Summary collapse
-
.handle ⇒ Fiddle::Handle?
readonly
The loaded DLL handle.
Backward-Compatible Shims collapse
-
.cudaDeviceGetAttribute(ptr_out, attr_id, device) ⇒ Integer
Status.
-
.cudaDeviceGetDefaultMemPool(pool_ptr, device) ⇒ Integer
Status.
-
.cudaDeviceReset ⇒ Integer
Status.
-
.cudaDeviceSetMemPool(device, pool) ⇒ Integer
Status.
-
.cudaDeviceSynchronize ⇒ Integer
Status.
-
.cudaEventCreate(ptr_out) ⇒ Integer
Status.
-
.cudaEventDestroy(event) ⇒ Integer
Status.
-
.cudaEventElapsedTime(ms_ptr, start_event, end_event) ⇒ Integer
Status.
-
.cudaEventRecord(event, stream) ⇒ Integer
Status.
-
.cudaEventSynchronize(event) ⇒ Integer
Status.
-
.cudaFree(ptr) ⇒ Integer
Status.
-
.cudaFreeAsync(ptr, stream) ⇒ Integer
Status.
-
.cudaFreeHost(ptr) ⇒ Integer
Status.
-
.cudaGetDevice(ptr_out) ⇒ Integer
Status.
-
.cudaGetDeviceCount(ptr_out) ⇒ Integer
Status.
-
.cudaGetDeviceProperties(prop_ptr, device) ⇒ Integer
Status.
- .cudaGetErrorName(status) ⇒ String
- .cudaGetErrorString(status) ⇒ String
-
.cudaGetLastError ⇒ Integer
Status.
-
.cudaHostAlloc(ptr_ptr, size, flags) ⇒ Integer
Status.
-
.cudaHostRegister(ptr, size, flags) ⇒ Integer
Status.
-
.cudaHostUnregister(ptr) ⇒ Integer
Status.
-
.cudaMalloc(ptr_ptr, size) ⇒ Integer
Status.
-
.cudaMallocAsync(ptr_out, size, stream) ⇒ Integer
Status.
-
.cudaMallocFromPoolAsync(ptr_ptr, size, pool, stream) ⇒ Integer
Status.
-
.cudaMallocHost(ptr_ptr, size) ⇒ Integer
Status.
-
.cudaMemcpy(dst, src, count, kind) ⇒ Integer
Status.
-
.cudaMemcpyAsync(dst, src, count, kind, stream) ⇒ Integer
Status.
-
.cudaMemGetInfo(free_ptr, total_ptr) ⇒ Integer
Status.
-
.cudaMemPoolCreate(pool_ptr, props) ⇒ Integer
Status.
-
.cudaMemPoolDestroy(pool) ⇒ Integer
Status.
-
.cudaMemPoolGetAttribute(pool, attr, value_ptr) ⇒ Integer
Status.
-
.cudaMemPoolSetAttribute(pool, attr, value_ptr) ⇒ Integer
Status.
-
.cudaMemset(ptr, value, count) ⇒ Integer
Status.
-
.cudaMemsetAsync(ptr, value, count, stream) ⇒ Integer
Status.
-
.cudaPeekAtLastError ⇒ Integer
Status.
-
.cudaRuntimeGetVersion(ptr_out) ⇒ Integer
Status.
-
.cudaSetDevice(device_id) ⇒ Integer
CUDA status code.
-
.cudaStreamCreate(ptr_out) ⇒ Integer
Status.
-
.cudaStreamDestroy(stream) ⇒ Integer
Status.
-
.cudaStreamSynchronize(stream) ⇒ Integer
Status.
Class Method Summary collapse
-
.check_status!(status, context = 'CUDA operation') ⇒ void
Check CUDA status and raise error if not success.
-
.device_get_attribute(attr_id, device) ⇒ Integer
Attribute value.
- .device_reset ⇒ void
- .device_synchronize ⇒ void
-
.driver_version ⇒ Integer
CUDA driver version.
-
.ensure_loaded! ⇒ void
Ensure the CUDA runtime is loaded and all functions are bound.
-
.event_create ⇒ Fiddle::Pointer
Create a CUDA event.
-
.event_destroy(event) ⇒ void
Destroy a CUDA event.
-
.event_elapsed_time(start_event, end_event) ⇒ Float
Compute elapsed time between two events.
-
.event_record(event, stream) ⇒ void
Record an event in a stream.
-
.event_synchronize(event) ⇒ void
Block until event completes.
-
.free(ptr) ⇒ void
Free device memory.
- .free_async(ptr, stream) ⇒ void
-
.free_host(ptr) ⇒ void
Free pinned host memory.
-
.get_device ⇒ Integer
Current device index.
-
.get_device_count ⇒ Integer
Number of CUDA devices.
-
.get_error_name(status) ⇒ String
Get error name for a status code.
-
.get_error_string(status) ⇒ String
Get error string for a status code.
-
.get_last_error ⇒ Integer
Last error code.
-
.host_alloc(size, flags = HOST_ALLOC_DEFAULT) ⇒ Fiddle::Pointer
Allocate pinned host memory.
- .loaded? ⇒ Boolean
-
.malloc(size) ⇒ Fiddle::Pointer
Allocate device memory.
-
.malloc_async(size, stream) ⇒ Fiddle::Pointer
Device pointer.
-
.mem_get_info ⇒ Hash
Query GPU memory info.
-
.memcpy(dst, src, count, kind) ⇒ void
Copy memory.
-
.memcpy_async(dst, src, count, kind, stream) ⇒ void
Async memory copy.
-
.memset(ptr, value, count) ⇒ void
Set device memory.
-
.peek_at_last_error ⇒ Integer
Last error without clearing.
-
.runtime_version ⇒ Integer
CUDA runtime version.
- .set_device(device) ⇒ void
-
.stream_create ⇒ Fiddle::Pointer
Create a CUDA stream.
-
.stream_destroy(stream) ⇒ void
Destroy a CUDA stream.
-
.stream_query(stream) ⇒ Boolean
Query stream completion status.
-
.stream_synchronize(stream) ⇒ void
Synchronize a stream (blocks until all commands complete).
Class Attribute Details
.handle ⇒ Fiddle::Handle? (readonly)
Returns the loaded DLL handle.
54 55 56 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 54 def handle @handle end |
Class Method Details
.check_status!(status, context = 'CUDA operation') ⇒ void
This method returns an undefined value.
Check CUDA status and raise error if not success.
402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 402 def check_status!(status, context = 'CUDA operation') return if status.zero? ensure_loaded! error_name = get_error_name(status) error_string = get_error_string(status) raise CudaRuntimeError.new( "#{context}: #{error_name} - #{error_string}", cuda_code: status ) end |
.cudaDeviceGetAttribute(ptr_out, attr_id, device) ⇒ Integer
Returns status.
544 545 546 547 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 544 def cudaDeviceGetAttribute(ptr_out, attr_id, device) ensure_loaded! @functions[:cudaDeviceGetAttribute].call(ptr_out, attr_id, device) end |
.cudaDeviceGetDefaultMemPool(pool_ptr, device) ⇒ Integer
Returns status.
745 746 747 748 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 745 def cudaDeviceGetDefaultMemPool(pool_ptr, device) ensure_loaded! @functions[:cudaDeviceGetDefaultMemPool]&.call(pool_ptr, device) || 0 end |
.cudaDeviceReset ⇒ Integer
Returns status.
521 522 523 524 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 521 def cudaDeviceReset ensure_loaded! @functions[:cudaDeviceReset].call end |
.cudaDeviceSetMemPool(device, pool) ⇒ Integer
Returns status.
763 764 765 766 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 763 def cudaDeviceSetMemPool(device, pool) ensure_loaded! @functions[:cudaDeviceSetMemPool]&.call(device, pool) || 0 end |
.cudaDeviceSynchronize ⇒ Integer
Returns status.
515 516 517 518 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 515 def cudaDeviceSynchronize ensure_loaded! @functions[:cudaDeviceSynchronize].call end |
.cudaEventCreate(ptr_out) ⇒ Integer
Returns status.
631 632 633 634 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 631 def cudaEventCreate(ptr_out) ensure_loaded! @functions[:cudaEventCreate].call(ptr_out) end |
.cudaEventDestroy(event) ⇒ Integer
Returns status.
637 638 639 640 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 637 def cudaEventDestroy(event) ensure_loaded! @functions[:cudaEventDestroy].call(event) end |
.cudaEventElapsedTime(ms_ptr, start_event, end_event) ⇒ Integer
Returns status.
655 656 657 658 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 655 def cudaEventElapsedTime(ms_ptr, start_event, end_event) ensure_loaded! @functions[:cudaEventElapsedTime].call(ms_ptr, start_event, end_event) end |
.cudaEventRecord(event, stream) ⇒ Integer
Returns status.
643 644 645 646 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 643 def cudaEventRecord(event, stream) ensure_loaded! @functions[:cudaEventRecord].call(event, stream) end |
.cudaEventSynchronize(event) ⇒ Integer
Returns status.
649 650 651 652 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 649 def cudaEventSynchronize(event) ensure_loaded! @functions[:cudaEventSynchronize].call(event) end |
.cudaFree(ptr) ⇒ Integer
Returns status.
559 560 561 562 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 559 def cudaFree(ptr) ensure_loaded! @functions[:cudaFree].call(ptr) end |
.cudaFreeAsync(ptr, stream) ⇒ Integer
Returns status.
720 721 722 723 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 720 def cudaFreeAsync(ptr, stream) ensure_loaded! @functions[:cudaFreeAsync].call(ptr, stream) end |
.cudaFreeHost(ptr) ⇒ Integer
Returns status.
607 608 609 610 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 607 def cudaFreeHost(ptr) ensure_loaded! @functions[:cudaFreeHost].call(ptr) end |
.cudaGetDevice(ptr_out) ⇒ Integer
Returns status.
535 536 537 538 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 535 def cudaGetDevice(ptr_out) ensure_loaded! @functions[:cudaGetDevice].call(ptr_out) end |
.cudaGetDeviceCount(ptr_out) ⇒ Integer
Returns status.
528 529 530 531 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 528 def cudaGetDeviceCount(ptr_out) ensure_loaded! @functions[:cudaGetDeviceCount].call(ptr_out) end |
.cudaGetDeviceProperties(prop_ptr, device) ⇒ Integer
Returns status.
775 776 777 778 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 775 def cudaGetDeviceProperties(prop_ptr, device) ensure_loaded! @functions[:cudaGetDeviceProperties]&.call(prop_ptr, device) || 0 end |
.cudaGetErrorName(status) ⇒ String
680 681 682 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 680 def cudaGetErrorName(status) get_error_name(status) end |
.cudaGetErrorString(status) ⇒ String
674 675 676 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 674 def cudaGetErrorString(status) get_error_string(status) end |
.cudaGetLastError ⇒ Integer
Returns status.
661 662 663 664 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 661 def cudaGetLastError ensure_loaded! @functions[:cudaGetLastError].call end |
.cudaHostAlloc(ptr_ptr, size, flags) ⇒ Integer
Returns status.
600 601 602 603 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 600 def cudaHostAlloc(ptr_ptr, size, flags) ensure_loaded! @functions[:cudaHostAlloc].call(ptr_ptr, size, flags) end |
.cudaHostRegister(ptr, size, flags) ⇒ Integer
Returns status.
688 689 690 691 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 688 def cudaHostRegister(ptr, size, flags) ensure_loaded! @functions[:cudaHostRegister]&.call(ptr, size, flags) || 0 end |
.cudaHostUnregister(ptr) ⇒ Integer
Returns status.
695 696 697 698 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 695 def cudaHostUnregister(ptr) ensure_loaded! @functions[:cudaHostUnregister]&.call(ptr) || 0 end |
.cudaMalloc(ptr_ptr, size) ⇒ Integer
Returns status.
552 553 554 555 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 552 def cudaMalloc(ptr_ptr, size) ensure_loaded! @functions[:cudaMalloc].call(ptr_ptr, size) end |
.cudaMallocAsync(ptr_out, size, stream) ⇒ Integer
Returns status.
712 713 714 715 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 712 def cudaMallocAsync(ptr_out, size, stream) ensure_loaded! @functions[:cudaMallocAsync].call(ptr_out, size, stream) end |
.cudaMallocFromPoolAsync(ptr_ptr, size, pool, stream) ⇒ Integer
Returns status.
739 740 741 742 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 739 def cudaMallocFromPoolAsync(ptr_ptr, size, pool, stream) ensure_loaded! @functions[:cudaMallocFromPoolAsync]&.call(ptr_ptr, size, pool, stream) || 0 end |
.cudaMallocHost(ptr_ptr, size) ⇒ Integer
Returns status.
703 704 705 706 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 703 def cudaMallocHost(ptr_ptr, size) ensure_loaded! @functions[:cudaMallocHost]&.call(ptr_ptr, size) || cudaHostAlloc(ptr_ptr, size, 0) end |
.cudaMemcpy(dst, src, count, kind) ⇒ Integer
Returns status.
565 566 567 568 569 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 565 def cudaMemcpy(dst, src, count, kind) ensure_loaded! kind_int = resolve_memcpy_kind(kind) @functions[:cudaMemcpy].call(dst, src, count, kind_int) end |
.cudaMemcpyAsync(dst, src, count, kind, stream) ⇒ Integer
Returns status.
572 573 574 575 576 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 572 def cudaMemcpyAsync(dst, src, count, kind, stream) ensure_loaded! kind_int = resolve_memcpy_kind(kind) @functions[:cudaMemcpyAsync].call(dst, src, count, kind_int, stream) end |
.cudaMemGetInfo(free_ptr, total_ptr) ⇒ Integer
Returns status.
591 592 593 594 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 591 def cudaMemGetInfo(free_ptr, total_ptr) ensure_loaded! @functions[:cudaMemGetInfo].call(free_ptr, total_ptr) end |
.cudaMemPoolCreate(pool_ptr, props) ⇒ Integer
Returns status.
769 770 771 772 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 769 def cudaMemPoolCreate(pool_ptr, props) ensure_loaded! @functions[:cudaMemPoolCreate]&.call(pool_ptr, props) || 0 end |
.cudaMemPoolDestroy(pool) ⇒ Integer
Returns status.
733 734 735 736 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 733 def cudaMemPoolDestroy(pool) ensure_loaded! @functions[:cudaMemPoolDestroy]&.call(pool) || 0 end |
.cudaMemPoolGetAttribute(pool, attr, value_ptr) ⇒ Integer
Returns status.
757 758 759 760 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 757 def cudaMemPoolGetAttribute(pool, attr, value_ptr) ensure_loaded! @functions[:cudaMemPoolGetAttribute]&.call(pool, attr, value_ptr) || 0 end |
.cudaMemPoolSetAttribute(pool, attr, value_ptr) ⇒ Integer
Returns status.
751 752 753 754 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 751 def cudaMemPoolSetAttribute(pool, attr, value_ptr) ensure_loaded! @functions[:cudaMemPoolSetAttribute]&.call(pool, attr, value_ptr) || 0 end |
.cudaMemset(ptr, value, count) ⇒ Integer
Returns status.
579 580 581 582 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 579 def cudaMemset(ptr, value, count) ensure_loaded! @functions[:cudaMemset].call(ptr, value, count) end |
.cudaMemsetAsync(ptr, value, count, stream) ⇒ Integer
Returns status.
585 586 587 588 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 585 def cudaMemsetAsync(ptr, value, count, stream) ensure_loaded! @functions[:cudaMemsetAsync].call(ptr, value, count, stream) end |
.cudaPeekAtLastError ⇒ Integer
Returns status.
667 668 669 670 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 667 def cudaPeekAtLastError ensure_loaded! @functions[:cudaPeekAtLastError].call end |
.cudaRuntimeGetVersion(ptr_out) ⇒ Integer
Returns status.
727 728 729 730 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 727 def cudaRuntimeGetVersion(ptr_out) ensure_loaded! @functions[:cudaRuntimeGetVersion].call(ptr_out) end |
.cudaSetDevice(device_id) ⇒ Integer
Returns CUDA status code.
509 510 511 512 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 509 def cudaSetDevice(device_id) ensure_loaded! @functions[:cudaSetDevice].call(device_id) end |
.cudaStreamCreate(ptr_out) ⇒ Integer
Returns status.
613 614 615 616 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 613 def cudaStreamCreate(ptr_out) ensure_loaded! @functions[:cudaStreamCreate].call(ptr_out) end |
.cudaStreamDestroy(stream) ⇒ Integer
Returns status.
619 620 621 622 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 619 def cudaStreamDestroy(stream) ensure_loaded! @functions[:cudaStreamDestroy].call(stream) end |
.cudaStreamSynchronize(stream) ⇒ Integer
Returns status.
625 626 627 628 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 625 def cudaStreamSynchronize(stream) ensure_loaded! @functions[:cudaStreamSynchronize].call(stream) end |
.device_get_attribute(attr_id, device) ⇒ Integer
Returns attribute value.
119 120 121 122 123 124 125 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 119 def device_get_attribute(attr_id, device) ensure_loaded! ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT) status = @functions[:cudaDeviceGetAttribute].call(ptr, attr_id, device) check_status!(status, 'cudaDeviceGetAttribute') ptr[0, Fiddle::SIZEOF_INT].unpack1('l') end |
.device_reset ⇒ void
This method returns an undefined value.
110 111 112 113 114 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 110 def device_reset ensure_loaded! status = @functions[:cudaDeviceReset].call check_status!(status, 'cudaDeviceReset') end |
.device_synchronize ⇒ void
This method returns an undefined value.
103 104 105 106 107 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 103 def device_synchronize ensure_loaded! status = @functions[:cudaDeviceSynchronize].call check_status!(status, 'cudaDeviceSynchronize') end |
.driver_version ⇒ Integer
Returns CUDA driver version.
389 390 391 392 393 394 395 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 389 def driver_version ensure_loaded! ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT) status = @functions[:cudaDriverGetVersion].call(ptr) check_status!(status, 'cudaDriverGetVersion') ptr[0, Fiddle::SIZEOF_INT].unpack1('l') end |
.ensure_loaded! ⇒ void
This method returns an undefined value.
Ensure the CUDA runtime is loaded and all functions are bound.
59 60 61 62 63 64 65 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 59 def ensure_loaded! return if @loaded @handle = Fiddle::Handle.new(CUDART_LIB) attach_all_functions! @loaded = true end |
.event_create ⇒ Fiddle::Pointer
Create a CUDA event.
293 294 295 296 297 298 299 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 293 def event_create ensure_loaded! ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP) status = @functions[:cudaEventCreate].call(ptr) check_status!(status, 'cudaEventCreate') Fiddle::Pointer.new(ptr[0, Fiddle::SIZEOF_VOIDP].unpack1('Q')) end |
.event_destroy(event) ⇒ void
This method returns an undefined value.
Destroy a CUDA event.
304 305 306 307 308 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 304 def event_destroy(event) ensure_loaded! status = @functions[:cudaEventDestroy].call(event) check_status!(status, 'cudaEventDestroy') end |
.event_elapsed_time(start_event, end_event) ⇒ Float
Compute elapsed time between two events.
333 334 335 336 337 338 339 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 333 def event_elapsed_time(start_event, end_event) ensure_loaded! ms_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_FLOAT) status = @functions[:cudaEventElapsedTime].call(ms_ptr, start_event, end_event) check_status!(status, 'cudaEventElapsedTime') ms_ptr[0, Fiddle::SIZEOF_FLOAT].unpack1('e') end |
.event_record(event, stream) ⇒ void
This method returns an undefined value.
Record an event in a stream.
314 315 316 317 318 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 314 def event_record(event, stream) ensure_loaded! status = @functions[:cudaEventRecord].call(event, stream) check_status!(status, 'cudaEventRecord') end |
.event_synchronize(event) ⇒ void
This method returns an undefined value.
Block until event completes.
323 324 325 326 327 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 323 def event_synchronize(event) ensure_loaded! status = @functions[:cudaEventSynchronize].call(event) check_status!(status, 'cudaEventSynchronize') end |
.free(ptr) ⇒ void
This method returns an undefined value.
Free device memory.
145 146 147 148 149 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 145 def free(ptr) ensure_loaded! status = @functions[:cudaFree].call(ptr) check_status!(status, 'cudaFree') end |
.free_async(ptr, stream) ⇒ void
This method returns an undefined value.
240 241 242 243 244 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 240 def free_async(ptr, stream) ensure_loaded! status = @functions[:cudaFreeAsync].call(ptr, stream) check_status!(status, 'cudaFreeAsync') end |
.free_host(ptr) ⇒ void
This method returns an undefined value.
Free pinned host memory.
202 203 204 205 206 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 202 def free_host(ptr) ensure_loaded! status = @functions[:cudaFreeHost].call(ptr) check_status!(status, 'cudaFreeHost') end |
.get_device ⇒ Integer
Returns current device index.
86 87 88 89 90 91 92 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 86 def get_device ensure_loaded! ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT) status = @functions[:cudaGetDevice].call(ptr) check_status!(status, 'cudaGetDevice') ptr[0, Fiddle::SIZEOF_INT].unpack1('l') end |
.get_device_count ⇒ Integer
Returns number of CUDA devices.
77 78 79 80 81 82 83 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 77 def get_device_count ensure_loaded! ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT) status = @functions[:cudaGetDeviceCount].call(ptr) check_status!(status, 'cudaGetDeviceCount') ptr[0, Fiddle::SIZEOF_INT].unpack1('l') end |
.get_error_name(status) ⇒ String
Get error name for a status code.
369 370 371 372 373 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 369 def get_error_name(status) ensure_loaded! ptr = @functions[:cudaGetErrorName].call(status) Fiddle::Pointer.new(ptr).to_s end |
.get_error_string(status) ⇒ String
Get error string for a status code.
360 361 362 363 364 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 360 def get_error_string(status) ensure_loaded! ptr = @functions[:cudaGetErrorString].call(status) Fiddle::Pointer.new(ptr).to_s end |
.get_last_error ⇒ Integer
Returns last error code.
346 347 348 349 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 346 def get_last_error ensure_loaded! @functions[:cudaGetLastError].call end |
.host_alloc(size, flags = HOST_ALLOC_DEFAULT) ⇒ Fiddle::Pointer
Allocate pinned host memory.
191 192 193 194 195 196 197 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 191 def host_alloc(size, flags = HOST_ALLOC_DEFAULT) ensure_loaded! ptr_buf = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP) status = @functions[:cudaHostAlloc].call(ptr_buf, size, flags) check_status!(status, "cudaHostAlloc(#{size})") Fiddle::Pointer.new(ptr_buf[0, Fiddle::SIZEOF_VOIDP].unpack1('Q')) end |
.loaded? ⇒ Boolean
68 69 70 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 68 def loaded? @loaded end |
.malloc(size) ⇒ Fiddle::Pointer
Allocate device memory.
134 135 136 137 138 139 140 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 134 def malloc(size) ensure_loaded! ptr_buf = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP) status = @functions[:cudaMalloc].call(ptr_buf, size) check_status!(status, "cudaMalloc(#{size})") Fiddle::Pointer.new(ptr_buf[0, Fiddle::SIZEOF_VOIDP].unpack1('Q')) end |
.malloc_async(size, stream) ⇒ Fiddle::Pointer
Returns device pointer.
229 230 231 232 233 234 235 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 229 def malloc_async(size, stream) ensure_loaded! ptr_buf = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP) status = @functions[:cudaMallocAsync].call(ptr_buf, size, stream) check_status!(status, "cudaMallocAsync(#{size})") Fiddle::Pointer.new(ptr_buf[0, Fiddle::SIZEOF_VOIDP].unpack1('Q')) end |
.mem_get_info ⇒ Hash
Query GPU memory info.
210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 210 def mem_get_info ensure_loaded! free_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_SIZE_T) total_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_SIZE_T) status = @functions[:cudaMemGetInfo].call(free_ptr, total_ptr) check_status!(status, 'cudaMemGetInfo') { free_bytes: free_ptr[0, Fiddle::SIZEOF_SIZE_T].unpack1('Q'), total_bytes: total_ptr[0, Fiddle::SIZEOF_SIZE_T].unpack1('Q') } end |
.memcpy(dst, src, count, kind) ⇒ void
This method returns an undefined value.
Copy memory.
157 158 159 160 161 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 157 def memcpy(dst, src, count, kind) ensure_loaded! status = @functions[:cudaMemcpy].call(dst, src, count, kind) check_status!(status, "cudaMemcpy(#{count} bytes, kind=#{kind})") end |
.memcpy_async(dst, src, count, kind, stream) ⇒ void
This method returns an undefined value.
Async memory copy.
170 171 172 173 174 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 170 def memcpy_async(dst, src, count, kind, stream) ensure_loaded! status = @functions[:cudaMemcpyAsync].call(dst, src, count, kind, stream) check_status!(status, "cudaMemcpyAsync(#{count} bytes)") end |
.memset(ptr, value, count) ⇒ void
This method returns an undefined value.
Set device memory.
181 182 183 184 185 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 181 def memset(ptr, value, count) ensure_loaded! status = @functions[:cudaMemset].call(ptr, value, count) check_status!(status, "cudaMemset(#{count} bytes)") end |
.peek_at_last_error ⇒ Integer
Returns last error without clearing.
352 353 354 355 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 352 def peek_at_last_error ensure_loaded! @functions[:cudaPeekAtLastError].call end |
.runtime_version ⇒ Integer
Returns CUDA runtime version.
380 381 382 383 384 385 386 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 380 def runtime_version ensure_loaded! ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT) status = @functions[:cudaRuntimeGetVersion].call(ptr) check_status!(status, 'cudaRuntimeGetVersion') ptr[0, Fiddle::SIZEOF_INT].unpack1('l') end |
.set_device(device) ⇒ void
This method returns an undefined value.
96 97 98 99 100 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 96 def set_device(device) ensure_loaded! status = @functions[:cudaSetDevice].call(device) check_status!(status, 'cudaSetDevice') end |
.stream_create ⇒ Fiddle::Pointer
Create a CUDA stream.
252 253 254 255 256 257 258 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 252 def stream_create ensure_loaded! ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP) status = @functions[:cudaStreamCreate].call(ptr) check_status!(status, 'cudaStreamCreate') Fiddle::Pointer.new(ptr[0, Fiddle::SIZEOF_VOIDP].unpack1('Q')) end |
.stream_destroy(stream) ⇒ void
This method returns an undefined value.
Destroy a CUDA stream.
263 264 265 266 267 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 263 def stream_destroy(stream) ensure_loaded! status = @functions[:cudaStreamDestroy].call(stream) check_status!(status, 'cudaStreamDestroy') end |
.stream_query(stream) ⇒ Boolean
Query stream completion status.
281 282 283 284 285 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 281 def stream_query(stream) ensure_loaded! status = @functions[:cudaStreamQuery].call(stream) status.zero? end |
.stream_synchronize(stream) ⇒ void
This method returns an undefined value.
Synchronize a stream (blocks until all commands complete).
272 273 274 275 276 |
# File 'lib/nvruby/cuda/runtime_api.rb', line 272 def stream_synchronize(stream) ensure_loaded! status = @functions[:cudaStreamSynchronize].call(stream) check_status!(status, 'cudaStreamSynchronize') end |