Module: SGC::CU::CUMemory

Defined in:
lib/cuda/driver/memory.rb

Class Method Summary collapse

Class Method Details

.mem_infoHash{ :free, :total }

Returns A hash with the amount of free and total device memory in bytes.

Returns:

  • (Hash{ :free, :total })

    A hash with the amount of free and total device memory in bytes.



122
123
124
125
126
127
128
# File 'lib/cuda/driver/memory.rb', line 122

def mem_info
    pfree = FFI::MemoryPointer.new(:size_t)
    ptotal = FFI::MemoryPointer.new(:size_t)
    status = API::cuMemGetInfo(pfree, ptotal)
    Pvt::handle_error(status, "Failed to get memory information.")
    { free: API::read_size_t(pfree), total: API::read_size_t(ptotal) }
end

.memcpy(dst_ptr, src_ptr, nbytes) ⇒ Object

Copy nbytes from the memory at src_ptr to the memory at dst_ptr. The type of memory (host or device) is inferred from the pointer value.



37
38
39
40
41
# File 'lib/cuda/driver/memory.rb', line 37

def memcpy(dst_ptr, src_ptr, nbytes)
    status = API::cuMemcpy(dst_ptr.to_api, src_ptr.to_api, nbytes)
    Pvt::handle_error(status, "Failed to copy memory: size = #{nbytes}")
    nil
end

.memcpy_async(dst_ptr, src_ptr, nbytes, stream) ⇒ Object

Copy nbytes from the memory at src_ptr to the memory at dst_ptr on stream asynchronously. The type of memory (host or device) is inferred from the pointer value.



47
48
49
50
51
52
# File 'lib/cuda/driver/memory.rb', line 47

def memcpy_async(dst_ptr, src_ptr, nbytes, stream)
    s = Pvt::parse_stream(stream)
    status = API::cuMemcpyAsync(dst_ptr.to_api, src_ptr.to_api, nbytes, s)
    Pvt::handle_error(status, "Failed to copy memory asynchronously: size = #{nbytes}")
    nil
end

.memcpy_dtod(dst_devptr, src_devptr, nbytes) ⇒ Object

Copy nbytes from the device memory at src_devptr to the device memory at dst_devptr asynchronously.



101
102
103
104
105
# File 'lib/cuda/driver/memory.rb', line 101

def memcpy_dtod(dst_devptr, src_devptr, nbytes)
    status = API::cuMemcpyDtoD(dst_devptr.to_api, src_devptr.to_api, nbytes)
    Pvt::handle_error(status, "Failed to copy memory from device to device asynchronously: size = #{nbytes}.")
    nil
end

.memcpy_dtod_async(dst_devptr, src_devptr, nbytes, stream) ⇒ Object

Note:

Not implemented yet.

Copy nbytes from the device memory at src_devptr to the device memory at dst_devptr on stream asynchronously.



112
113
114
115
116
117
# File 'lib/cuda/driver/memory.rb', line 112

def memcpy_dtod_async(dst_devptr, src_devptr, nbytes, stream)
    s = Pvt::parse_stream(stream)
    status = API::cuMemcpyDtoDAsync(dst_devptr.to_api, src_devptr.to_api, nbytes, s)
    Pvt::handle_error(status, "Failed to copy memory from device to device asynchronously: size = #{nbytes}.")
    nil
end

.memcpy_dtoh(dst_mem, src_devptr, nbytes) ⇒ Object

Copy nbytes from the device memory at src_devptr to the host memory at dst_mem.



79
80
81
82
83
# File 'lib/cuda/driver/memory.rb', line 79

def memcpy_dtoh(dst_mem, src_devptr, nbytes)
    status = API::cuMemcpyDtoH(dst_mem.ptr, src_devptr.to_api, nbytes)
    Pvt::handle_error(status, "Failed to copy memory from device to host: size = #{nbytes}")
    nil
end

.memcpy_dtoh_async(dst_mem, src_devptr, nbytes, stream) ⇒ Object

Note:

The dst_mem should be page-locked memory.

Note:

Not implemented yet.

Copy nbytes from the device memory at src_devptr to the host memory at dst_mem on stream asynchronously.



91
92
93
94
95
96
# File 'lib/cuda/driver/memory.rb', line 91

def memcpy_dtoh_async(dst_mem, src_devptr, nbytes, stream)
    s = Pvt::parse_stream(stream)
    status = API::cuMemcpyDtoHAsync(dst_mem.ptr, src_devptr.to_api, nbytes, s)
    Pvt::handle_error(status, "Failed to copy memory from device to host asynchronously: size = #{nbytes}")
    nil
end

.memcpy_htod(dst_devptr, src_mem, nbytes) ⇒ Object

Copy nbytes from the host memory at src_mem to the device memory at dst_devptr.



57
58
59
60
61
# File 'lib/cuda/driver/memory.rb', line 57

def memcpy_htod(dst_devptr, src_mem, nbytes)
    status = API::cuMemcpyHtoD(dst_devptr.to_api, src_mem.ptr, nbytes)
    Pvt::handle_error(status, "Failed to copy memory from host to device: size = #{nbytes}")
    nil
end

.memcpy_htod_async(dst_devptr, src_mem, nbytes, stream) ⇒ Object

Note:

The src_mem should be page-locked memory.

Note:

Not implemented yet.

Copy nbytes from the host memory at src_mem to the device memory at dst_devptr on stream asynchronously.



69
70
71
72
73
74
# File 'lib/cuda/driver/memory.rb', line 69

def memcpy_htod_async(dst_devptr, src_mem, nbytes, stream)
    s = Pvt::parse_stream(stream)
    status = API::cuMemcpyHtoDAsync(dst_devptr.to_api, src_mem.ptr, nbytes, s)
    Pvt::handle_error(status, "Failed to copy memory from host to device asynchronously: size = #{nbytes}")
    nil
end