Class: Ignis::JIT::CompiledKernel

Inherits:
Object
  • Object
show all
Defined in:
lib/nvruby/jit/compiled_kernel.rb

Overview

Represents compiled CUDA code (CUBIN binary) Device-agnostic representation that can be loaded onto any compatible GPU Thread-safe immutable object suitable for caching

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cubin_data:, compute_capability:, kernel_name:, source_code: nil, compile_options: []) ⇒ CompiledKernel

Create a new CompiledKernel

Parameters:

  • cubin_data (String)

    The compiled CUBIN binary

  • compute_capability (Integer)

    Target compute capability

  • kernel_name (String)

    Kernel function name

  • source_code (String, nil) (defaults to: nil)

    Original source code

  • compile_options (Array<String>) (defaults to: [])

    Options used for compilation



36
37
38
39
40
41
42
43
44
45
# File 'lib/nvruby/jit/compiled_kernel.rb', line 36

def initialize(cubin_data:, compute_capability:, kernel_name:, source_code: nil, compile_options: [])
  @cubin_data = cubin_data.freeze
  @cubin_size = cubin_data.bytesize
  @compute_capability = compute_capability
  @kernel_name = kernel_name.freeze
  @source_code = source_code&.freeze
  @compile_options = compile_options.map(&:freeze).freeze
  @compiled_at = Time.now.freeze
  freeze
end

Instance Attribute Details

#compile_optionsArray<String> (readonly)

Returns Compilation options used.

Returns:

  • (Array<String>)

    Compilation options used



25
26
27
# File 'lib/nvruby/jit/compiled_kernel.rb', line 25

def compile_options
  @compile_options
end

#compiled_atTime (readonly)

Returns Compilation timestamp.

Returns:

  • (Time)

    Compilation timestamp



28
29
30
# File 'lib/nvruby/jit/compiled_kernel.rb', line 28

def compiled_at
  @compiled_at
end

#compute_capabilityInteger (readonly)

Returns Target compute capability (e.g., 89 for sm_89).

Returns:

  • (Integer)

    Target compute capability (e.g., 89 for sm_89)



16
17
18
# File 'lib/nvruby/jit/compiled_kernel.rb', line 16

def compute_capability
  @compute_capability
end

#cubin_dataString (readonly)

Returns The compiled CUBIN binary data.

Returns:

  • (String)

    The compiled CUBIN binary data



10
11
12
# File 'lib/nvruby/jit/compiled_kernel.rb', line 10

def cubin_data
  @cubin_data
end

#cubin_sizeInteger (readonly)

Returns Size of the CUBIN data in bytes.

Returns:

  • (Integer)

    Size of the CUBIN data in bytes



13
14
15
# File 'lib/nvruby/jit/compiled_kernel.rb', line 13

def cubin_size
  @cubin_size
end

#kernel_nameString (readonly)

Returns Kernel function name.

Returns:

  • (String)

    Kernel function name



22
23
24
# File 'lib/nvruby/jit/compiled_kernel.rb', line 22

def kernel_name
  @kernel_name
end

#source_codeString (readonly)

Returns The original source code (for debugging).

Returns:

  • (String)

    The original source code (for debugging)



19
20
21
# File 'lib/nvruby/jit/compiled_kernel.rb', line 19

def source_code
  @source_code
end

Instance Method Details

#compatible_with?(target_cc) ⇒ Boolean

Check if compatible with a given compute capability

Parameters:

  • target_cc (Integer)

    Target compute capability

Returns:

  • (Boolean)

    True if this kernel can run on target



75
76
77
# File 'lib/nvruby/jit/compiled_kernel.rb', line 75

def compatible_with?(target_cc)
  target_cc >= @compute_capability
end

#inspectString

Get detailed inspection

Returns:

  • (String)


64
65
66
67
68
69
70
# File 'lib/nvruby/jit/compiled_kernel.rb', line 64

def inspect
  "#<Ignis::JIT::CompiledKernel:0x#{object_id.to_s(16)} " \
    "kernel=#{@kernel_name.inspect} " \
    "sm=#{@compute_capability} " \
    "size=#{@cubin_size} " \
    "compiled_at=#{@compiled_at.strftime('%Y-%m-%d %H:%M:%S')}>"
end

#load(device_id: 0) ⇒ KernelModule

Load this compiled kernel onto a specific device

Parameters:

  • device_id (Integer) (defaults to: 0)

    Device index to load onto

Returns:

Raises:



51
52
53
54
# File 'lib/nvruby/jit/compiled_kernel.rb', line 51

def load(device_id: 0)
  Ignis.set_device(device_id)
  KernelModule.new(self, device_id: device_id)
end

#to_sString

Get a string representation

Returns:

  • (String)


58
59
60
# File 'lib/nvruby/jit/compiled_kernel.rb', line 58

def to_s
  "#<Ignis::JIT::CompiledKernel #{@kernel_name} sm_#{@compute_capability} #{@cubin_size} bytes>"
end