Class: Cumo::CUDA::NVRTCProgram

Inherits:
Object
  • Object
show all
Defined in:
lib/cumo/cuda/nvrtc_program.rb

Instance Method Summary collapse

Constructor Details

#initialize(src, name: "default_program", headers: [], include_names: [], name_expressions: []) ⇒ NVRTCProgram

name_expressions: names such as "kernel" whose mangled names lowered_name answers once the program is compiled.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cumo/cuda/nvrtc_program.rb', line 9

def initialize(src, name: "default_program", headers: [], include_names: [], name_expressions: [])
  @ptr = nil
  @src = src # should be UTF-8
  @name = name # should be UTF-8
  name_expressions.each do |expr|
    raise TypeError, "a name expression is a String, got a #{expr.class}" unless expr.is_a?(String)
  end
  @ptr = NVRTC.nvrtcCreateProgram(src, name, headers, include_names)
  begin
    name_expressions.each { |expr| NVRTC.nvrtcAddNameExpression(@ptr, expr) }
  rescue Exception
    destroy
    raise
  end
end

Instance Method Details

#compile(options: []) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/cumo/cuda/nvrtc_program.rb', line 35

def compile(options: [])
  begin
    NVRTC.nvrtcCompileProgram(@ptr, options)
    return NVRTC.nvrtcGetPTX(@ptr)
  rescue NVRTCError
    log = NVRTC.nvrtcGetProgramLog(@ptr)
    raise CompileError.new(log, @src, @name, options)
  end
end

#destroyObject



29
30
31
32
33
# File 'lib/cumo/cuda/nvrtc_program.rb', line 29

def destroy
  return unless @ptr
  NVRTC.nvrtcDestroyProgram(@ptr)
  @ptr = nil
end

#lowered_name(name_expression) ⇒ Object



25
26
27
# File 'lib/cumo/cuda/nvrtc_program.rb', line 25

def lowered_name(name_expression)
  NVRTC.nvrtcGetLoweredName(@ptr, name_expression)
end