Module: SGC::Cuda::CudaMemory

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

Class Method Summary collapse

Class Method Details

.memcpy(dst_ptr, src_ptr, nbytes, memcpy_kind) ⇒ Object

Copy nbytes from the memory at src_ptr to the memory at dst_ptr.

Parameters:

  • dst_ptr (#ptr)

    Destination of the memory copy.

  • src_ptr (#ptr)

    Source of the memory copy.

  • nbytes (Integer)

    The number of bytes to copy.

  • memcpy_kind (Symbol)

    The direction of the memory copy specified with one of the following:

    • :HOST_TO_HOST

    • :HOST_TO_DEVICE

    • :DEVICE_TO_HOST

    • :DEVICE_TO_DEVICE



76
77
78
79
# File 'lib/cuda/runtime/memory.rb', line 76

def memcpy(dst_ptr, src_ptr, nbytes, memcpy_kind)
    status = API::cudaMemcpy(dst_ptr.ptr, src_ptr.ptr, nbytes, memcpy_kind)
    Pvt::handle_error(status, "Failed to copy memory.")
end

.memcpy_dtod(dst_ptr, src_ptr, nbytes) ⇒ Object

Copy nbytes from the device memory at src_ptr to the device memory at dst_ptr.



102
103
104
# File 'lib/cuda/runtime/memory.rb', line 102

def memcpy_dtod(dst_ptr, src_ptr, nbytes)
    memcpy(dst_ptr, src_ptr, nbytes, :DEVICE_TO_DEVICE)
end

.memcpy_dtoh(dst_ptr, src_ptr, nbytes) ⇒ Object

Copy nbytes from the device memory at src_ptr to the host memory at dst_ptr.



96
97
98
# File 'lib/cuda/runtime/memory.rb', line 96

def memcpy_dtoh(dst_ptr, src_ptr, nbytes)
    memcpy(dst_ptr, src_ptr, nbytes, :DEVICE_TO_HOST)
end

.memcpy_htod(dst_ptr, src_ptr, nbytes) ⇒ Object

Copy nbytes from the host memory at src_ptr to the device memory at dst_ptr.



90
91
92
# File 'lib/cuda/runtime/memory.rb', line 90

def memcpy_htod(dst_ptr, src_ptr, nbytes)
    memcpy(dst_ptr, src_ptr, nbytes, :HOST_TO_DEVICE)
end

.memcpy_htoh(dst_ptr, src_ptr, nbytes) ⇒ Object

Copy nbytes from the host memory at src_ptr to the host memory at dst_ptr.



84
85
86
# File 'lib/cuda/runtime/memory.rb', line 84

def memcpy_htoh(dst_ptr, src_ptr, nbytes)
    memcpy(dst_ptr, src_ptr, nbytes, :HOST_TO_HOST)
end