Class: Ignis::CUDA::GraphExecutable
- Inherits:
-
Object
- Object
- Ignis::CUDA::GraphExecutable
- Defined in:
- lib/nvruby/cuda/graph.rb
Overview
Executable CUDA Graph ready for launch.
Instance Attribute Summary collapse
-
#handle ⇒ FFI::Pointer
readonly
Native executable graph handle.
-
#launch_count ⇒ Integer
readonly
Number of times this graph has been launched.
-
#source_graph ⇒ Graph
readonly
Source graph.
Instance Method Summary collapse
-
#destroy! ⇒ void
Destroy the executable graph.
- #destroyed? ⇒ Boolean
-
#initialize(graph, flags: 0) ⇒ GraphExecutable
constructor
A new instance of GraphExecutable.
-
#launch(stream: nil) ⇒ self
Launch the executable graph.
-
#update! ⇒ Boolean
Update the executable graph from its source graph.
-
#upload(stream: nil) ⇒ self
Upload the graph to the device for faster first launch.
Constructor Details
#initialize(graph, flags: 0) ⇒ GraphExecutable
Returns a new instance of GraphExecutable.
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
#handle ⇒ FFI::Pointer (readonly)
Returns Native executable graph handle.
161 162 163 |
# File 'lib/nvruby/cuda/graph.rb', line 161 def handle @handle end |
#launch_count ⇒ Integer (readonly)
Returns 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_graph ⇒ Graph (readonly)
Returns 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
223 224 225 |
# File 'lib/nvruby/cuda/graph.rb', line 223 def destroyed? @destroyed end |
#launch(stream: nil) ⇒ self
Launch the executable graph.
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.
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.
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 |