15#if defined(__OFFLOAD_CUDA)
17#elif defined(__OFFLOAD_HIP)
18#include <hip/hip_runtime_api.h>
19#elif defined(__OFFLOAD_OPENCL)
20#include <libxstream/libxstream.h>
23#if defined(__OFFLOAD_PROFILING)
24#if defined(__OFFLOAD_CUDA)
25#include <nvtx3/nvToolsExt.h>
26#elif defined(__OFFLOAD_HIP) && defined(__HIP_PLATFORM_AMD__)
27#include <roctracer/roctx.h>
53#if defined(__OFFLOAD_CUDA)
54 CUresult error = cuInit(0);
55 if (error != CUDA_SUCCESS) {
56 fprintf(stderr,
"ERROR: %s %d %s %d\n",
"cuInit failed with error: ", error,
60#elif defined(__OFFLOAD_HIP)
61 OFFLOAD_CHECK(hipInit(0));
62#elif defined(__OFFLOAD_OPENCL)
63 OFFLOAD_CHECK(libxstream_init());
73#if defined(__OFFLOAD_CUDA)
74 OFFLOAD_CHECK(cudaGetDeviceCount(&count));
75#elif defined(__OFFLOAD_HIP)
76 OFFLOAD_CHECK(hipGetDeviceCount(&count));
77#elif defined(__OFFLOAD_OPENCL)
78 OFFLOAD_CHECK(libxstream_device_count(&count));
100#if defined(__OFFLOAD_CUDA)
102#elif defined(__OFFLOAD_HIP)
104#elif defined(__OFFLOAD_OPENCL)
116#if defined(__OFFLOAD_PROFILING)
117#if defined(__OFFLOAD_CUDA)
120 for (
size_t i = 0;
i < strlen(message);
i++) {
121 hash +=
i * message[
i] * message[
i];
123 nvtxEventAttributes_t eventAttrib = {0};
124 eventAttrib.version = NVTX_VERSION;
125 eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
126 eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
127 eventAttrib.message.ascii = message;
128 eventAttrib.colorType = NVTX_COLOR_ARGB;
130 eventAttrib.payloadType = NVTX_PAYLOAD_TYPE_INT64;
131 eventAttrib.payload.llValue = 123;
132 eventAttrib.category = 42;
133 nvtxRangePushEx(&eventAttrib);
134#elif defined(__OFFLOAD_HIP) && defined(__HIP_PLATFORM_AMD__)
135 roctxRangePushA(message);
146#if defined(__OFFLOAD_PROFILING)
147#if defined(__OFFLOAD_CUDA)
149#elif defined(__OFFLOAD_HIP) && defined(__HIP_PLATFORM_AMD__)
160#if defined(__OFFLOAD_CUDA)
161 OFFLOAD_CHECK(cudaMemGetInfo(free, total));
162#elif defined(__OFFLOAD_HIP)
163 OFFLOAD_CHECK(hipMemGetInfo(free, total));
164#elif defined(__OFFLOAD_OPENCL)
165 OFFLOAD_CHECK(libxstream_mem_info(free, total));
175#if defined(__OFFLOAD)
176 offloadMallocHost(ptr__, size__);
177 return offloadSuccess;
179 *ptr__ = malloc(size__);
188#if defined(__OFFLOAD)
189 offloadFreeHost(ptr__);
190 return offloadSuccess;
202#if defined(__OFFLOAD_CUDA)
203 OFFLOAD_CHECK(cudaDeviceSynchronize());
204#elif defined(__OFFLOAD_HIP)
205 OFFLOAD_CHECK(hipDeviceSynchronize());
static unsigned int hash(const dbm_task_t task)
Private hash function based on Szudzik's elegant pairing. Using unsigned int to return a positive num...
static void const int const int i
const uint32_t colormap[]
int offload_get_device_count(void)
Returns the number of available devices.
void offload_mem_info(size_t *free, size_t *total)
Gets free and total device memory.
void offload_activate_chosen_device(void)
Activates the device selected via offload_set_chosen_device().
int offload_host_free(void *ptr__)
free pinned memory (or simple free when there is no gpu)
static int chosen_device_id
void offload_timestop(void)
Ends a timing range.
void offload_device_synchronize(void)
Blocks until all outstanding device work has completed.
void offload_timeset(const char *message)
Starts a timing range.
int offload_get_chosen_device(void)
Returns the chosen device.
void offload_set_chosen_device(int device_id)
Selects the chosen device to be used.
void offload_init(void)
Initialize runtime.
int offload_host_malloc(void **ptr__, const size_t size__)
Allocate pinned memory (or simple malloc when there is no gpu).