.cu file implementing the module functionalities
must define the preprocessor macro name ROCKY_CUDA_API.
*Currently, the CUDA-related hooks are
four: ROCKY_PLUGIN_INITIALIZE_CUDA,
ROCKY_PLUGIN_BEGIN_ITERATION_CUDA,
ROCKY_PLUGIN_PRE_OUTPUT_CUDA_SYNC_DATA,
and ROCKY_PLUGIN_TEAR_DOWN_CUDA.
CUDA_MALLOC
This macro must be used to allocate a block of memory in a device for storing custom data. This allocation must be made before any copy operation of custom data to a device. Parameters:-
device_ptrA pointer that after successful memory allocation will point to the memory address in a device at which the custom data will be stored. Prior to its utilization in the macro, this pointer must be a null pointer, otherwise a runtime error will be thrown. -
sizeAn integer value that indicates the number of bytes that must be allocated in the device.
CUDA_MALLOC_TYPE
A variant ofCUDA_MALLOC that, instead of receiving the number of bytes that must
be allocated in the device, receives the type of data that
will be stored and the number of elements as parameters, if it happens to be an array.
Parameters:
-
device_ptrA pointer that after successful memory allocation will point to the memory address in a device at which the custom data will be stored. Prior to its utilization in the macro, this pointer must be a null pointer, otherwise a runtime error will be thrown. -
countAn integer value that indicates the number of elements of the same type that will be stored in the allocated memory. -
typeThe type of variable that will be stored in the device, which can be a C++ built-in type or a custom data structure.
CUDA_COPY_H2D
This macro must be used to copy custom data from the host to a device. Prior to this copy operation, the right amount of memory must have already been allocated within the device, otherwise a segmentation fault will occur. Note: The data type being copied must be trivially copyable otherwise a compilation error will raise. Parameters:-
device_ptrDestination memory address within a device. -
host_ptrSource memory address within the host. -
countAn integer value that indicates the number of elements of the same type that will be copied.
CUDA_COPY_D2H
This macro performs the inverse operation ofCUDA_COPY_H2D, that is, it copies data
from the device back to the host. This operation may be needed when
processed data must be made available to the host in order to be saved
or delivered to the Rocky UI for visualization.
Note: The data type being copied must be trivially copyable otherwise a compilation error will raise.
Parameters:
-
host_ptrDestination memory address within the host. -
device_ptrSource memory address within a device. -
countAn integer value that indicates the number of elements of the same type that will be copied.
CUDA_MEMSET
This macro sets a memory block within a device to a given value. It is commonly used to reset a block of memory that previously contained some data to zero. Parameters:-
device_ptrMemory address within the device where the block begins. -
valueThe value to be defined for each byte within the memory block. -
countAn integer value that indicates the number of elements of the same type that currently occupy the memory block.
CUDA_FREE
This macro must be used to free the memory block allocated previously byCUDA_MALLOC.
Parameters:
-
device_ptrDevice pointer that points to the memory block that must be freed.