Class: Ignis::CUDA::GraphExecutable

Inherits:
Object
  • Object
show all
Defined in:
lib/nvruby/cuda/graph.rb

Overview

Executable CUDA Graph ready for launch.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph, flags: 0) ⇒ GraphExecutable

Returns a new instance of GraphExecutable.

Parameters:

  • graph (Graph)

    Source graph

  • flags (Integer) (defaults to: 0)

    Instantiation flags



171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/nvruby/cuda/graph.rb', line 171

def initialize(graph, flags: 0)
  GraphBindings.ensure_loaded!

  exec_ptr = FFI::MemoryPointer.new(:pointer)
  status = GraphBindings.cudaGraphInstantiate(exec_ptr, graph.handle, flags)
  GraphBindings.check_status!(status, 'cudaGraphInstantiate')

  @handle = exec_ptr.read_pointer
  @source_graph = graph
  @launch_count = 0
  @destroyed = false
end

Instance Attribute Details

#handleFFI::Pointer (readonly)

Returns Native executable graph handle.

Returns:

  • (FFI::Pointer)

    Native executable graph handle



161
162
163
# File 'lib/nvruby/cuda/graph.rb', line 161

def handle
  @handle
end

#launch_countInteger (readonly)

Returns Number of times this graph has been launched.

Returns:

  • (Integer)

    Number of times this graph has been launched



167
168
169
# File 'lib/nvruby/cuda/graph.rb', line 167

def launch_count
  @launch_count
end

#source_graphGraph (readonly)

Returns Source graph.

Returns:

  • (Graph)

    Source graph



164
165
166
# File 'lib/nvruby/cuda/graph.rb', line 164

def source_graph
  @source_graph
end

Instance Method Details

#destroy!void

This method returns an undefined value.

Destroy the executable graph.



229
230
231
232
233
234
235
236
237
# File 'lib/nvruby/cuda/graph.rb', line 229

def destroy!
  return if @destroyed

  status = GraphBindings.cudaGraphExecDestroy(@handle)
  GraphBindings.check_status!(status, 'cudaGraphExecDestroy')

  @destroyed = true
  @handle = nil
end

#destroyed?Boolean

Returns:

  • (Boolean)


223
224
225
# File 'lib/nvruby/cuda/graph.rb', line 223

def destroyed?
  @destroyed
end

#launch(stream: nil) ⇒ self

Launch the executable graph.

Parameters:

  • stream (Stream, nil) (defaults to: nil)

    Stream to launch on (default stream if nil)

Returns:

  • (self)

Raises:



187
188
189
190
191
192
193
194
195
196
# File 'lib/nvruby/cuda/graph.rb', line 187

def launch(stream: nil)
  raise InvalidOperationError, 'GraphExecutable already destroyed' if @destroyed

  stream_handle = stream ? Graph.to_ffi_ptr(stream.to_ptr) : FFI::Pointer::NULL
  status = GraphBindings.cudaGraphLaunch(@handle, stream_handle)
  GraphBindings.check_status!(status, 'cudaGraphLaunch')

  @launch_count += 1
  self
end

#update!Boolean

Update the executable graph from its source graph.

Returns:

  • (Boolean)

    True if update succeeded

Raises:



213
214
215
216
217
218
219
220
# File 'lib/nvruby/cuda/graph.rb', line 213

def update!
  raise InvalidOperationError, 'GraphExecutable already destroyed' if @destroyed

  result_ptr = FFI::MemoryPointer.new(:int)
  status = GraphBindings.cudaGraphExecUpdate(@handle, @source_graph.handle, result_ptr)

  status.zero?
end

#upload(stream: nil) ⇒ self

Upload the graph to the device for faster first launch.

Parameters:

  • stream (Stream, nil) (defaults to: nil)

Returns:

  • (self)

Raises:



201
202
203
204
205
206
207
208
209
# File 'lib/nvruby/cuda/graph.rb', line 201

def upload(stream: nil)
  raise InvalidOperationError, 'GraphExecutable already destroyed' if @destroyed

  stream_handle = stream ? Graph.to_ffi_ptr(stream.to_ptr) : FFI::Pointer::NULL
  status = GraphBindings.cudaGraphUpload(@handle, stream_handle)
  GraphBindings.check_status!(status, 'cudaGraphUpload')

  self
end