Class: SGC::Cuda::CudaDeviceMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/cuda/runtime/memory.rb

Class Method Summary collapse

Class Method Details

.free(devptr) ⇒ Object

Free the device memory at devptr.


55
56
57
58
59
60
# File 'lib/cuda/runtime/memory.rb', line 55

def self.free(devptr)
    status = API::cudaFree(devptr.ptr)
    Pvt::handle_error(status, "Failed to free the device memory.")
    devptr.ptr = 0
    nil
end

.malloc(nbytes) ⇒ *SGC::Memory::MemoryPointer

Note:

The returned memory pointer is enabled to call free method on itself.

Allocate memory on the device.


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cuda/runtime/memory.rb', line 40

def self.malloc(nbytes)
    p = SGC::Memory::MemoryPointer.new
    status = API::cudaMalloc(p.ref, nbytes)
    Pvt::handle_error(status, "Failed to allocate memory on the device: nbytes = #{nbytes}")
    p.instance_eval %{
        def free
            CudaDeviceMemory.free(self)
        end
    }
    p
end