16#if defined(__OFFLOAD_CUDA)
18#elif defined(__OFFLOAD_HIP)
19#include <hip/hip_runtime_api.h>
20#elif defined(__OFFLOAD_OPENCL)
21#include <libxstream/libxstream.h>
24#if defined(__OFFLOAD_PROFILING)
25#if defined(__OFFLOAD_CUDA)
26#include <nvtx3/nvToolsExt.h>
27#elif defined(__OFFLOAD_HIP) && defined(__HIP_PLATFORM_AMD__)
28#include <roctracer/roctx.h>
54#if defined(__OFFLOAD_CUDA)
55 CUresult error = cuInit(0);
56 if (error != CUDA_SUCCESS) {
57 fprintf(stderr,
"ERROR: %s %d %s %d\n",
"cuInit failed with error: ", error,
61#elif defined(__OFFLOAD_HIP)
62 OFFLOAD_CHECK(hipInit(0));
63#elif defined(__OFFLOAD_OPENCL)
64 OFFLOAD_CHECK(libxstream_init());
74#if defined(__OFFLOAD_CUDA)
75 OFFLOAD_CHECK(cudaGetDeviceCount(&count));
76#elif defined(__OFFLOAD_HIP)
77 OFFLOAD_CHECK(hipGetDeviceCount(&count));
78#elif defined(__OFFLOAD_OPENCL)
79 OFFLOAD_CHECK(libxstream_device_count(&count));
101#if defined(__OFFLOAD_CUDA)
103#elif defined(__OFFLOAD_HIP)
105#elif defined(__OFFLOAD_OPENCL)
116void offload_timeset(
const char *message) {
117#if defined(__OFFLOAD_PROFILING)
118#if defined(__OFFLOAD_CUDA)
121 for (
size_t i = 0;
i < strlen(message);
i++) {
122 hash +=
i * message[
i] * message[
i];
124 nvtxEventAttributes_t eventAttrib = {0};
125 eventAttrib.version = NVTX_VERSION;
126 eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
127 eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
128 eventAttrib.message.ascii = message;
129 eventAttrib.colorType = NVTX_COLOR_ARGB;
131 eventAttrib.payloadType = NVTX_PAYLOAD_TYPE_INT64;
132 eventAttrib.payload.llValue = 123;
133 eventAttrib.category = 42;
134 nvtxRangePushEx(&eventAttrib);
135#elif defined(__OFFLOAD_HIP) && defined(__HIP_PLATFORM_AMD__)
136 roctxRangePushA(message);
147#if defined(__OFFLOAD_PROFILING)
148#if defined(__OFFLOAD_CUDA)
150#elif defined(__OFFLOAD_HIP) && defined(__HIP_PLATFORM_AMD__)
160void offload_mem_info(
size_t *free,
size_t *total) {
161#if defined(__OFFLOAD_CUDA)
162 OFFLOAD_CHECK(cudaMemGetInfo(free, total));
163#elif defined(__OFFLOAD_HIP)
164 OFFLOAD_CHECK(hipMemGetInfo(free, total));
165#elif defined(__OFFLOAD_OPENCL)
166 OFFLOAD_CHECK(libxstream_mem_info(free, total));
176#if defined(__OFFLOAD)
177 offloadMallocHost(ptr__, size__);
178 return offloadSuccess;
180 *ptr__ = malloc(size__);
189#if defined(__OFFLOAD)
190 offloadFreeHost(ptr__);
191 return offloadSuccess;
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_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.
int offload_get_chosen_device(void)
Returns the chosen device.
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)