Class: Ignis::JIT::Kernel
- Inherits:
-
Object
- Object
- Ignis::JIT::Kernel
- Defined in:
- lib/nvruby/jit/kernel.rb
Overview
High-level kernel execution interface Provides easy-to-use launch configuration and argument marshaling
Defined Under Namespace
Classes: U64
Instance Attribute Summary collapse
-
#kernel_module ⇒ KernelModule
readonly
The underlying kernel module.
-
#launch_count ⇒ Integer
readonly
Total number of times this kernel has been launched.
-
#total_launch_time ⇒ Float
readonly
Total time spent in kernel launches (seconds).
Class Method Summary collapse
-
.calc_grid_size(total_elements, block_size: 256) ⇒ Array<Integer>
Calculate optimal grid size for a given element count.
Instance Method Summary collapse
-
#device_id ⇒ Integer
Get the device this kernel is loaded on.
-
#initialize(kernel_module) ⇒ Kernel
constructor
Create a new Kernel wrapper.
-
#inspect ⇒ String
Get detailed inspection.
-
#launch(grid:, block:, args: [], shared_mem: 0, stream: nil) ⇒ self
Launch the kernel with specified configuration.
-
#launch_sync(grid:, block:, args: [], shared_mem: 0) ⇒ self
Synchronous kernel launch with automatic device synchronization.
-
#name ⇒ String
Get the kernel function name.
-
#stats ⇒ Hash
Get execution statistics.
-
#to_s ⇒ String
Get a string representation.
Constructor Details
#initialize(kernel_module) ⇒ Kernel
Create a new Kernel wrapper
19 20 21 22 23 24 |
# File 'lib/nvruby/jit/kernel.rb', line 19 def initialize(kernel_module) @kernel_module = kernel_module @launch_count = 0 @total_launch_time = 0.0 @mutex = Mutex.new end |
Instance Attribute Details
#kernel_module ⇒ KernelModule (readonly)
Returns The underlying kernel module.
9 10 11 |
# File 'lib/nvruby/jit/kernel.rb', line 9 def kernel_module @kernel_module end |
#launch_count ⇒ Integer (readonly)
Returns Total number of times this kernel has been launched.
12 13 14 |
# File 'lib/nvruby/jit/kernel.rb', line 12 def launch_count @launch_count end |
#total_launch_time ⇒ Float (readonly)
Returns Total time spent in kernel launches (seconds).
15 16 17 |
# File 'lib/nvruby/jit/kernel.rb', line 15 def total_launch_time @total_launch_time end |
Class Method Details
.calc_grid_size(total_elements, block_size: 256) ⇒ Array<Integer>
Calculate optimal grid size for a given element count
89 90 91 92 |
# File 'lib/nvruby/jit/kernel.rb', line 89 def self.calc_grid_size(total_elements, block_size: 256) blocks = (total_elements + block_size - 1) / block_size [blocks] end |
Instance Method Details
#device_id ⇒ Integer
Get the device this kernel is loaded on
34 35 36 |
# File 'lib/nvruby/jit/kernel.rb', line 34 def device_id @kernel_module.device_id end |
#inspect ⇒ String
Get detailed inspection
116 117 118 119 120 121 |
# File 'lib/nvruby/jit/kernel.rb', line 116 def inspect "#<Ignis::JIT::Kernel:0x#{object_id.to_s(16)} " \ "name=#{name.inspect} " \ "device=#{device_id} " \ "launches=#{@launch_count}>" end |
#launch(grid:, block:, args: [], shared_mem: 0, stream: nil) ⇒ self
Launch the kernel with specified configuration
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/nvruby/jit/kernel.rb', line 47 def launch(grid:, block:, args: [], shared_mem: 0, stream: nil) raise InvalidOperationError, "Kernel module has been destroyed" if @kernel_module.destroyed? start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) Ignis.set_device(device_id) param_pointers = marshal_arguments(args) stream_ptr = extract_stream_pointer(stream) DriverAPIBindings.launch_kernel( @kernel_module.function_handle, grid_dim: normalize_dims(grid), block_dim: normalize_dims(block), kernel_params: param_pointers, shared_mem: shared_mem, stream: stream_ptr ) @mutex.synchronize do @launch_count += 1 @total_launch_time += Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time end self end |
#launch_sync(grid:, block:, args: [], shared_mem: 0) ⇒ self
Synchronous kernel launch with automatic device synchronization
79 80 81 82 83 |
# File 'lib/nvruby/jit/kernel.rb', line 79 def launch_sync(grid:, block:, args: [], shared_mem: 0) launch(grid: grid, block: block, args: args, shared_mem: shared_mem, stream: nil) Ignis.synchronize self end |
#name ⇒ String
Get the kernel function name
28 29 30 |
# File 'lib/nvruby/jit/kernel.rb', line 28 def name @kernel_module.kernel_name end |
#stats ⇒ Hash
Get execution statistics
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/nvruby/jit/kernel.rb', line 96 def stats @mutex.synchronize do { kernel_name: name, device_id: device_id, launch_count: @launch_count, total_launch_time: @total_launch_time, avg_launch_time: @launch_count.positive? ? @total_launch_time / @launch_count : 0.0 } end end |
#to_s ⇒ String
Get a string representation
110 111 112 |
# File 'lib/nvruby/jit/kernel.rb', line 110 def to_s "#<Ignis::JIT::Kernel #{name} device=#{device_id} launches=#{@launch_count}>" end |