Class: Cumo::CUDA::Function

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

Overview

A kernel of a loaded Module, ready to launch.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod, ptr, name) ⇒ Function

Returns a new instance of Function.



8
9
10
11
12
# File 'lib/cumo/cuda/function.rb', line 8

def initialize(mod, ptr, name)
  @mod = mod
  @ptr = ptr
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/cumo/cuda/function.rb', line 6

def name
  @name
end

Instance Method Details

#launch(args, grid:, block:, shared_mem: 0, stream: nil) ⇒ Object

Launches the kernel on the current stream, the one Cumo's own kernels run on, so it runs after the operations issued before it and before the ones issued after.

An NArray argument hands over its device pointer, so the kernel sees the elements themselves; it has to be contiguous. An Integer is passed as a long long and a Float as a double. Anything else goes as packed bytes: [n].pack("l") is an int, [x].pack("f") a float, and a packed struct is a struct passed by value.

grid and block take one to three sizes each; shared_mem is the dynamic shared memory in bytes; stream: is a Stream to launch on instead of the current one.

Raises:

  • (TypeError)


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

def launch(args, grid:, block:, shared_mem: 0, stream: nil)
  unless shared_mem.is_a?(Integer) && shared_mem >= 0
    raise ArgumentError, "shared_mem is a byte count, got #{shared_mem.inspect}"
  end
  raise TypeError, "stream: takes a Stream, got a #{stream.class}" unless stream.nil? || stream.is_a?(Stream)
  Driver.cuLaunchKernel(@ptr, *dims(grid, "grid"), *dims(block, "block"), shared_mem, stream&.handle, args)
end