Class: Ignis::JIT::KernelModule
- Inherits:
-
Object
- Object
- Ignis::JIT::KernelModule
- Defined in:
- lib/nvruby/jit/kernel_module.rb
Overview
Represents a loaded CUDA module on a specific device Manages the CUmodule handle and CUfunction extraction Handles automatic cleanup via finalizer
Instance Attribute Summary collapse
-
#compiled_kernel ⇒ CompiledKernel
readonly
The compiled kernel this module was loaded from.
-
#device_id ⇒ Integer
readonly
Device ID this module is loaded on.
-
#function_handle ⇒ FFI::Pointer
readonly
The CUfunction handle.
-
#loaded_at ⇒ Time
readonly
When this module was loaded.
-
#module_handle ⇒ FFI::Pointer
readonly
The CUmodule handle.
Instance Method Summary collapse
-
#destroy! ⇒ void
Unload the module from GPU memory.
-
#destroyed? ⇒ Boolean
Check if this module has been destroyed.
-
#initialize(compiled_kernel, device_id: 0) ⇒ KernelModule
constructor
Create a new KernelModule by loading compiled code onto a device.
-
#inspect ⇒ String
Get detailed inspection.
-
#kernel_name ⇒ String
Get the kernel function name.
-
#to_kernel ⇒ Kernel
Create a Kernel instance for execution.
-
#to_s ⇒ String
Get a string representation.
Constructor Details
#initialize(compiled_kernel, device_id: 0) ⇒ KernelModule
Create a new KernelModule by loading compiled code onto a device
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nvruby/jit/kernel_module.rb', line 28 def initialize(compiled_kernel, device_id: 0) @compiled_kernel = compiled_kernel @device_id = device_id @loaded_at = Time.now @destroyed = false @mutex = Mutex.new load_module! extract_function! setup_finalizer end |
Instance Attribute Details
#compiled_kernel ⇒ CompiledKernel (readonly)
Returns The compiled kernel this module was loaded from.
10 11 12 |
# File 'lib/nvruby/jit/kernel_module.rb', line 10 def compiled_kernel @compiled_kernel end |
#device_id ⇒ Integer (readonly)
Returns Device ID this module is loaded on.
13 14 15 |
# File 'lib/nvruby/jit/kernel_module.rb', line 13 def device_id @device_id end |
#function_handle ⇒ FFI::Pointer (readonly)
Returns The CUfunction handle.
19 20 21 |
# File 'lib/nvruby/jit/kernel_module.rb', line 19 def function_handle @function_handle end |
#loaded_at ⇒ Time (readonly)
Returns When this module was loaded.
22 23 24 |
# File 'lib/nvruby/jit/kernel_module.rb', line 22 def loaded_at @loaded_at end |
#module_handle ⇒ FFI::Pointer (readonly)
Returns The CUmodule handle.
16 17 18 |
# File 'lib/nvruby/jit/kernel_module.rb', line 16 def module_handle @module_handle end |
Instance Method Details
#destroy! ⇒ void
This method returns an undefined value.
Unload the module from GPU memory
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nvruby/jit/kernel_module.rb', line 61 def destroy! @mutex.synchronize do return if @destroyed if @module_handle && !@module_handle.null? DriverAPIBindings.unload_module(@module_handle) end @module_handle = nil @function_handle = nil @destroyed = true Ignis.logger.debug("Unloaded kernel module: #{kernel_name} from device #{@device_id}") end end |
#destroyed? ⇒ Boolean
Check if this module has been destroyed
49 50 51 |
# File 'lib/nvruby/jit/kernel_module.rb', line 49 def destroyed? @mutex.synchronize { @destroyed } end |
#inspect ⇒ String
Get detailed inspection
85 86 87 88 89 90 91 |
# File 'lib/nvruby/jit/kernel_module.rb', line 85 def inspect status = @destroyed ? "destroyed" : "loaded" "#<Ignis::JIT::KernelModule:0x#{object_id.to_s(16)} " \ "kernel=#{kernel_name.inspect} " \ "device=#{@device_id} " \ "status=#{status}>" end |
#kernel_name ⇒ String
Get the kernel function name
43 44 45 |
# File 'lib/nvruby/jit/kernel_module.rb', line 43 def kernel_name @compiled_kernel.kernel_name end |
#to_kernel ⇒ Kernel
Create a Kernel instance for execution
55 56 57 |
# File 'lib/nvruby/jit/kernel_module.rb', line 55 def to_kernel Kernel.new(self) end |
#to_s ⇒ String
Get a string representation
79 80 81 |
# File 'lib/nvruby/jit/kernel_module.rb', line 79 def to_s "#<Ignis::JIT::KernelModule #{kernel_name} device=#{@device_id}>" end |