Class: SGC::CU::CUModule

Inherits:
Object
  • Object
show all
Defined in:
lib/cuda/driver/module.rb

Instance Method Summary (collapse)

Constructor Details

- (CUModule) initialize

Allocate a CUDA module.



37
38
39
# File 'lib/cuda/driver/module.rb', line 37

def initialize
    @pmod = FFI::MemoryPointer.new(:CUModule)
end

Instance Method Details

- (CUFunction) function(name)

Lookup for a CUDA function corresponds to the function name name in the loaded compute module. A compute module was loaded with #load and alike methods.

Parameters:

  • name (String)

    The name of the function to lookup in the loaded compute modules.

Returns:

  • (CUFunction)

    The CUDA function corresponds to name in the loaded compute module.



98
99
100
101
102
103
# File 'lib/cuda/driver/module.rb', line 98

def function(name)
    p = FFI::MemoryPointer.new(:CUFunction)
    status = API::cuModuleGetFunction(p, self.to_api, name)
    Pvt::handle_error(status, "Failed to get module function: name = #{name}.")
    CUFunction.send(:new, p)
end

- (Array(CUDevicePtr, Integer)) global(name)

Lookup for the device pointer and the size of the global variable name in the loaded compute modules.

Parameters:

  • name (String)

    The name of the global variable to lookup in the loaded compute modules.

Returns:

  • (Array(CUDevicePtr, Integer))

    An array with a device pointer to the global variable and its size in bytes.



109
110
111
112
113
114
115
# File 'lib/cuda/driver/module.rb', line 109

def global(name)
    pdevptr = FFI::MemoryPointer.new(:CUDevicePtr)
    psize = FFI::MemoryPointer.new(:size_t)
    status = API::cuModuleGetGlobal(pdevptr, psize, self.to_api, name)
    Pvt::handle_error(status, "Failed to get module global: name = #{name}.")
    [CUDevicePtr.send(:new, pdevptr), API::read_size_t(psize)]
end

- (CUModule) load(path)

Load a compute module from the file at path into the current CUDA context. The file should be a cubin file or a PTX file.

A PTX file may be obtained by compiling the .cu file using nvcc with -ptx option.

$ nvcc -ptx vadd.cu

Parameters:

  • path (String)

    The path of the file to load.

Returns:



50
51
52
53
54
# File 'lib/cuda/driver/module.rb', line 50

def load(path)
    status = API::cuModuleLoad(@pmod, path)
    Pvt::handle_error(status, "Failed to load module: path = #{path}.")
    self
end

- (CUModule) load_data(image_str)

Load a compute module from the String image_str into the current CUDA context.

Parameters:

  • image_str (String)

    A string which contains a cubin or a PTX data.

Returns:

See Also:



62
63
64
65
66
# File 'lib/cuda/driver/module.rb', line 62

def load_data(image_str)
    status = API::cuModuleLoadData(@pmod, image_str)
    Pvt::handle_error(status, "Failed to load module data.")
    self
end

- (Object) load_data_ex

Note:

Not implemented yet.

Raises:

  • (NotImplementedError)

See Also:



72
73
74
# File 'lib/cuda/driver/module.rb', line 72

def load_data_ex
    raise NotImplementedError
end

- (Object) load_fat_binary

Note:

Not implemented yet.

Raises:

  • (NotImplementedError)

See Also:



80
81
82
# File 'lib/cuda/driver/module.rb', line 80

def load_fat_binary
    raise NotImplementedError
end

- (Object) surfref(name)

Note:

Not implemented yet.

Returns A surface texture reference corresponds to the surface name in the loaded compute module.

Returns:

  • A surface texture reference corresponds to the surface name in the loaded compute module.

Raises:

  • (NotImplementedError)


129
130
131
# File 'lib/cuda/driver/module.rb', line 129

def surfref(name)
    raise NotImplementedError
end

- (Object) texref(name)

Note:

Not implemented yet.

Returns A texture reference corresponds to the texture name in the loaded compute module.

Returns:

  • A texture reference corresponds to the texture name in the loaded compute module.

Raises:

  • (NotImplementedError)


121
122
123
# File 'lib/cuda/driver/module.rb', line 121

def texref(name)
    raise NotImplementedError
end

- (CUModule) unload

Unload this CUDA module from the current CUDA context.

Returns:



87
88
89
90
91
# File 'lib/cuda/driver/module.rb', line 87

def unload
    status = API::cuModuleUnload(self.to_api)
    Pvt::handle_error(status, "Failed to unload module.")
    self
end