Skip to content

Commit 19b9957

Browse files
committed
Fix warnings when compiling with gcc
Also, rename device_id -> device and platform_id to platform.
1 parent dd7982f commit 19b9957

File tree

9 files changed

+104
-109
lines changed

9 files changed

+104
-109
lines changed

backends/ispc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static int ispc_chk_env(struct ispc_backend *ispc) {
188188
static int ispc_sync(struct nomp_backend_t *bnd) { return 0; }
189189

190190
int ispc_init(struct nomp_backend_t *bnd, const int platform_type,
191-
const int device_id) {
191+
const int device) {
192192
ispcrtSetErrorFunc(ispcrt_error);
193193
if (platform_type < 0 | platform_type >= 2) {
194194
return nomp_log(NOMP_USER_INPUT_IS_INVALID, NOMP_ERROR,
@@ -198,11 +198,11 @@ int ispc_init(struct nomp_backend_t *bnd, const int platform_type,
198198
uint32_t num_devices =
199199
ispcrtGetDeviceCount(nomp_to_ispc_device[platform_type]);
200200
chk_ispcrt("get device count", rt_error);
201-
if (device_id < 0 || device_id >= num_devices) {
201+
if (device < 0 || device >= num_devices) {
202202
return nomp_log(NOMP_USER_INPUT_IS_INVALID, NOMP_ERROR,
203-
ERR_STR_USER_DEVICE_IS_INVALID, device_id);
203+
ERR_STR_USER_DEVICE_IS_INVALID, device);
204204
}
205-
ISPCRTDevice device = ispcrtGetDevice(platform_type, device_id);
205+
ISPCRTDevice device = ispcrtGetDevice(platform_type, device);
206206
chk_ispcrt("device get", rt_error);
207207

208208
struct ispc_backend *ispc = bnd->bptr = nomp_calloc(struct ispc_backend, 1);

backends/opencl.c

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static const char *ERR_STR_OPENCL_FAILURE = "%s failed with error code: %d.";
1919
}
2020

2121
struct opencl_backend_t {
22-
cl_device_id device_id;
22+
cl_device_id device;
2323
cl_command_queue queue;
2424
cl_context ctx;
2525
};
@@ -81,10 +81,10 @@ static int opencl_knl_build(struct nomp_backend_t *bnd, struct nomp_prog_t *prg,
8181
ocl_prg->prg = NULL, ocl_prg->knl = NULL;
8282

8383
size_t log_size;
84-
clGetProgramBuildInfo(ocl_prg->prg, ocl->device_id, CL_PROGRAM_BUILD_LOG, 0,
84+
clGetProgramBuildInfo(ocl_prg->prg, ocl->device, CL_PROGRAM_BUILD_LOG, 0,
8585
NULL, &log_size);
8686
char *log = nomp_calloc(char, log_size);
87-
clGetProgramBuildInfo(ocl_prg->prg, ocl->device_id, CL_PROGRAM_BUILD_LOG,
87+
clGetProgramBuildInfo(ocl_prg->prg, ocl->device, CL_PROGRAM_BUILD_LOG,
8888
log_size, log, NULL);
8989
int err = nomp_log(NOMP_OPENCL_FAILURE, NOMP_ERROR,
9090
"clBuildProgram failed with error:\n %s.", log);
@@ -145,7 +145,8 @@ static int opencl_finalize(struct nomp_backend_t *bnd) {
145145
return 0;
146146
}
147147

148-
static int opencl_device_query(struct nomp_backend_t *bnd, cl_device_id id) {
148+
static int opencl_device_query(struct nomp_backend_t *bnd,
149+
cl_device_id device) {
149150
#define set_string_aux(KEY, VAL) \
150151
{ \
151152
PyObject *obj = PyUnicode_FromString(VAL); \
@@ -156,7 +157,7 @@ static int opencl_device_query(struct nomp_backend_t *bnd, cl_device_id id) {
156157
#define set_string_info(PARAM, KEY) \
157158
{ \
158159
char string[BUFSIZ]; \
159-
check(clGetDeviceInfo(id, PARAM, sizeof(string), string, NULL), \
160+
check(clGetDeviceInfo(device, PARAM, sizeof(string), string, NULL), \
160161
"clGetDeviceInfo"); \
161162
set_string_aux(KEY, string); \
162163
}
@@ -166,7 +167,7 @@ static int opencl_device_query(struct nomp_backend_t *bnd, cl_device_id id) {
166167
set_string_info(CL_DRIVER_VERSION, "device::driver");
167168

168169
cl_device_type type;
169-
check(clGetDeviceInfo(id, CL_DEVICE_TYPE, sizeof(type), &type, NULL),
170+
check(clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(type), &type, NULL),
170171
"clGetDeviceInfo");
171172
PyObject *obj = NULL;
172173
if (type & CL_DEVICE_TYPE_CPU)
@@ -186,45 +187,41 @@ static int opencl_device_query(struct nomp_backend_t *bnd, cl_device_id id) {
186187
return 0;
187188
}
188189

189-
int opencl_init(struct nomp_backend_t *bnd, const int platform_id,
190-
const int device_id) {
191-
cl_uint num_platforms;
192-
check(clGetPlatformIDs(0, NULL, &num_platforms), "clGetPlatformIDs");
193-
if (platform_id < 0 | platform_id >= (int)num_platforms) {
190+
int opencl_init(struct nomp_backend_t *bnd, const int platform,
191+
const int device) {
192+
cl_uint n_platforms;
193+
check(clGetPlatformIDs(0, NULL, &n_platforms), "clGetPlatformIDs");
194+
if (platform < 0 || platform >= (int)n_platforms) {
194195
return nomp_log(NOMP_USER_INPUT_IS_INVALID, NOMP_ERROR,
195196
"Platform id %d provided to libnomp is not valid.",
196-
platform_id);
197+
platform);
197198
}
198199

199-
cl_platform_id *cl_platforms = nomp_calloc(cl_platform_id, num_platforms);
200-
check(clGetPlatformIDs(num_platforms, cl_platforms, &num_platforms),
200+
cl_platform_id *platforms = nomp_calloc(cl_platform_id, n_platforms);
201+
check(clGetPlatformIDs(n_platforms, platforms, &n_platforms),
201202
"clGetPlatformIDs");
202-
cl_platform_id platform = cl_platforms[platform_id];
203-
nomp_free(&cl_platforms);
204203

205-
cl_uint num_devices;
206-
check(clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices),
204+
cl_uint n_devices;
205+
check(clGetDeviceIDs(platforms[platform], CL_DEVICE_TYPE_ALL, 0, NULL,
206+
&n_devices),
207207
"clGetDeviceIDs");
208-
if (device_id < 0 || device_id >= (int)num_devices) {
208+
if (device < 0 || device >= (int)n_devices) {
209209
return nomp_log(NOMP_USER_INPUT_IS_INVALID, NOMP_ERROR,
210-
ERR_STR_USER_DEVICE_IS_INVALID, device_id);
210+
ERR_STR_USER_DEVICE_IS_INVALID, device);
211211
}
212212

213-
cl_device_id *cl_devices = nomp_calloc(cl_device_id, num_devices);
214-
check(clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, num_devices, cl_devices,
215-
&num_devices),
213+
cl_device_id *devices = nomp_calloc(cl_device_id, n_devices);
214+
check(clGetDeviceIDs(platforms[platform], CL_DEVICE_TYPE_ALL, n_devices,
215+
devices, &n_devices),
216216
"clGetDeviceIDs");
217-
cl_device_id device = cl_devices[device_id];
218-
nomp_free(&cl_devices);
219-
220-
nomp_check(opencl_device_query(bnd, device));
221217

222218
struct opencl_backend_t *ocl = nomp_calloc(struct opencl_backend_t, 1);
223-
ocl->device_id = device;
219+
ocl->device = devices[device];
224220
cl_int err;
225-
ocl->ctx = clCreateContext(NULL, 1, &device, NULL, NULL, &err);
221+
ocl->ctx = clCreateContext(NULL, 1, &ocl->device, NULL, NULL, &err);
226222
check(err, "clCreateContext");
227-
ocl->queue = clCreateCommandQueueWithProperties(ocl->ctx, device, 0, &err);
223+
ocl->queue =
224+
clCreateCommandQueueWithProperties(ocl->ctx, ocl->device, 0, &err);
228225
check(err, "clCreateCommandQueueWithProperties");
229226

230227
bnd->bptr = (void *)ocl;
@@ -235,6 +232,10 @@ int opencl_init(struct nomp_backend_t *bnd, const int platform_id,
235232
bnd->sync = opencl_sync;
236233
bnd->finalize = opencl_finalize;
237234

235+
nomp_check(opencl_device_query(bnd, ocl->device));
236+
237+
nomp_free(&devices), nomp_free(&platforms);
238+
238239
return 0;
239240
}
240241

backends/sycl.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static const char *ERR_STR_SYCL_FAILURE = "SYCL backend failed with error: %s.";
1313
}
1414

1515
struct sycl_backend {
16-
sycl::device device_id;
16+
sycl::device device;
1717
sycl::queue queue;
1818
sycl::context ctx;
1919
char *compiler, *compiler_flags;
@@ -30,7 +30,7 @@ static int sycl_update(struct nomp_backend_t *bnd, struct nomp_mem_t *m,
3030

3131
if (op & NOMP_ALLOC) {
3232
chk_sycl(m->bptr = sycl::malloc_device(NOMP_MEM_BYTES(start, end, usize),
33-
sycl->device_id, sycl->ctx););
33+
sycl->device, sycl->ctx););
3434
}
3535

3636
if (op & NOMP_TO) {
@@ -139,27 +139,27 @@ static int check_env(struct sycl_backend *sycl) {
139139
return 0;
140140
}
141141

142-
int sycl_init(struct nomp_backend_t *bnd, const int platform_id,
143-
const int device_id) {
142+
int sycl_init(struct nomp_backend_t *bnd, const int platform,
143+
const int device) {
144144
struct sycl_backend *sycl = nomp_calloc(struct sycl_backend, 1);
145145
bnd->bptr = (void *)sycl;
146146

147147
auto sycl_platforms = sycl::platform().get_platforms();
148-
if (platform_id < 0 | platform_id >= sycl_platforms.size()) {
148+
if (platform < 0 | platform >= sycl_platforms.size()) {
149149
return nomp_log(NOMP_USER_INPUT_IS_INVALID, NOMP_ERROR,
150150
"Platform id %d provided to libnomp is not valid.",
151-
platform_id);
151+
platform);
152152
}
153153

154-
auto sycl_pdevices = sycl_platforms[platform_id].get_devices();
155-
if (device_id < 0 || device_id >= sycl_pdevices.size()) {
154+
auto sycl_pdevices = sycl_platforms[platform].get_devices();
155+
if (device < 0 || device >= sycl_pdevices.size()) {
156156
return nomp_log(NOMP_USER_INPUT_IS_INVALID, NOMP_ERROR,
157-
ERR_STR_USER_DEVICE_IS_INVALID, device_id);
157+
ERR_STR_USER_DEVICE_IS_INVALID, device);
158158
}
159159

160-
sycl->device_id = sycl_pdevices[device_id];
161-
sycl->ctx = sycl::context(sycl->device_id);
162-
sycl->queue = sycl::queue(sycl->ctx, sycl->device_id);
160+
sycl->device = sycl_pdevices[device];
161+
sycl->ctx = sycl::context(sycl->device);
162+
sycl->queue = sycl::queue(sycl->ctx, sycl->device);
163163
check_env(sycl);
164164

165165
bnd->update = sycl_update;

backends/unified-cuda-hip-impl.h

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
#define backend_t TOKEN_PASTE(DRIVER, _backend_t)
5959
struct backend_t {
60-
int device_id;
60+
int device;
6161
backendDeviceProp_t prop;
6262
};
6363

@@ -104,11 +104,6 @@ static int backend_update(struct nomp_backend_t *bnd, struct nomp_mem_t *m,
104104
return 0;
105105
}
106106

107-
#define backend_update_ptr TOKEN_PASTE(DRIVER, _update_ptr)
108-
static void backend_update_ptr(void **p, size_t *size, struct nomp_mem_t *m) {
109-
*p = (void *)m->bptr, *size = sizeof(m->bptr);
110-
}
111-
112107
#define backend_knl_build TOKEN_PASTE(DRIVER, _knl_build)
113108
static int backend_knl_build(struct nomp_backend_t *bnd,
114109
struct nomp_prog_t *prg, const char *source,
@@ -193,9 +188,9 @@ static int backend_finalize(struct nomp_backend_t *bnd) {
193188
}
194189

195190
#define backend_device_query TOKEN_PASTE(DRIVER, _device_query)
196-
static int backend_device_query(struct nomp_backend_t *bnd, int device_id) {
191+
static int backend_device_query(struct nomp_backend_t *bnd, int device) {
197192
backendDeviceProp_t prop;
198-
check_driver(backendGetDeviceProperties(&prop, device_id));
193+
check_driver(backendGetDeviceProperties(&prop, device));
199194

200195
#define set_string_aux(KEY, VAL) \
201196
{ \
@@ -232,23 +227,21 @@ static int backend_device_query(struct nomp_backend_t *bnd, int device_id) {
232227
}
233228

234229
#define backend_init TOKEN_PASTE(DRIVER, _init)
235-
int backend_init(struct nomp_backend_t *bnd, const int platform_id,
236-
const int device_id) {
230+
int backend_init(struct nomp_backend_t *bnd, const int platform,
231+
const int device) {
237232
int num_devices;
238233
check_driver(backendGetDeviceCount(&num_devices));
239-
if (device_id < 0 || device_id >= num_devices) {
234+
if (device < 0 || device >= num_devices) {
240235
return nomp_log(NOMP_USER_INPUT_IS_INVALID, NOMP_ERROR,
241-
ERR_STR_USER_DEVICE_IS_INVALID, device_id);
236+
ERR_STR_USER_DEVICE_IS_INVALID, device);
242237
}
243238

244-
check_driver(backendSetDevice(device_id));
239+
check_driver(backendSetDevice(device));
245240
check_driver(backendFree(0));
246241

247-
nomp_check(backend_device_query(bnd, device_id));
248-
249242
struct backend_t *backend = nomp_calloc(struct backend_t, 1);
250-
backend->device_id = device_id;
251-
check_driver(backendGetDeviceProperties(&backend->prop, device_id));
243+
backend->device = device;
244+
check_driver(backendGetDeviceProperties(&backend->prop, device));
252245

253246
bnd->bptr = (void *)backend;
254247
bnd->update = backend_update;
@@ -258,6 +251,8 @@ int backend_init(struct nomp_backend_t *bnd, const int platform_id,
258251
bnd->sync = backend_sync;
259252
bnd->finalize = backend_finalize;
260253

254+
nomp_check(backend_device_query(bnd, device));
255+
261256
return 0;
262257
}
263258

@@ -267,7 +262,6 @@ int backend_init(struct nomp_backend_t *bnd, const int platform_id,
267262
#undef backend_knl_free
268263
#undef backend_knl_run
269264
#undef backend_knl_build
270-
#undef backend_update_ptr
271265
#undef backend_update
272266
#undef backend_compile
273267

include/nomp-impl.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct nomp_mem_t {
3939
#define NOMP_MEM_BYTES(start, end, usize) (((end) - (start)) * (usize))
4040

4141
struct nomp_arg_t {
42-
char name[NOMP_MAX_BUFSIZ];
42+
char name[NOMP_MAX_BUFSIZ + 1];
4343
size_t size;
4444
unsigned type;
4545
void *ptr;
@@ -69,8 +69,8 @@ struct nomp_prog_t {
6969

7070
struct nomp_backend_t {
7171
// User configurations of the backend.
72-
int platform_id, device_id, verbose, profile;
73-
char backend[NOMP_MAX_BUFSIZ], install_dir[PATH_MAX];
72+
int platform, device, verbose, profile;
73+
char backend[NOMP_MAX_BUFSIZ + 1], install_dir[PATH_MAX + 1];
7474
// Pointers to backend functions used for backend dispatch.
7575
int (*update)(struct nomp_backend_t *, struct nomp_mem_t *,
7676
const nomp_map_direction_t op, size_t start, size_t end,
@@ -110,12 +110,12 @@ extern "C" {
110110
* occurred during the initialization, otherwise returns 0.
111111
*
112112
* @param[in] backend Target backend for code generation.
113-
* @param[in] platform_id Target platform id.
114-
* @param[in] device_id Target device id.
113+
* @param[in] platform Target platform id.
114+
* @param[in] device Target device id.
115115
* @return int
116116
*/
117-
int opencl_init(struct nomp_backend_t *backend, const int platform_id,
118-
const int device_id);
117+
int opencl_init(struct nomp_backend_t *backend, const int platform,
118+
const int device);
119119

120120
/**
121121
* @ingroup nomp_backend_init
@@ -127,12 +127,12 @@ int opencl_init(struct nomp_backend_t *backend, const int platform_id,
127127
* occurred during the initialization, otherwise returns 0.
128128
*
129129
* @param[in] backend Target backend for code generation.
130-
* @param[in] platform_id Target platform id.
131-
* @param[in] device_id Target device id.
130+
* @param[in] platform Target platform id.
131+
* @param[in] device Target device id.
132132
* @return int
133133
*/
134-
int sycl_init(struct nomp_backend_t *backend, const int platform_id,
135-
const int device_id);
134+
int sycl_init(struct nomp_backend_t *backend, const int platform,
135+
const int device);
136136

137137
/**
138138
* @ingroup nomp_backend_init
@@ -143,12 +143,12 @@ int sycl_init(struct nomp_backend_t *backend, const int platform_id,
143143
* error occurred during the initialization, otherwise returns 0.
144144
*
145145
* @param[in] backend Target backend for code generation.
146-
* @param[in] platform_id Target platform id.
147-
* @param[in] device_id Target device id.
146+
* @param[in] platform Target platform id.
147+
* @param[in] device Target device id.
148148
* @return int
149149
*/
150-
int cuda_init(struct nomp_backend_t *backend, const int platform_id,
151-
const int device_id);
150+
int cuda_init(struct nomp_backend_t *backend, const int platform,
151+
const int device);
152152

153153
/**
154154
* @ingroup nomp_backend_init
@@ -159,12 +159,12 @@ int cuda_init(struct nomp_backend_t *backend, const int platform_id,
159159
* error occurred during the initialization, otherwise returns 0.
160160
*
161161
* @param[in] backend Target backend for code generation.
162-
* @param[in] platform_id Target platform id.
163-
* @param[in] device_id Target device id.
162+
* @param[in] platform Target platform id.
163+
* @param[in] device Target device id.
164164
* @return int
165165
*/
166-
int hip_init(struct nomp_backend_t *backend, const int platform_id,
167-
const int device_id);
166+
int hip_init(struct nomp_backend_t *backend, const int platform,
167+
const int device);
168168

169169
/**
170170
* @ingroup nomp_backend_init
@@ -176,11 +176,11 @@ int hip_init(struct nomp_backend_t *backend, const int platform_id,
176176
*
177177
* @param[in] backend Target backend for code generation.
178178
* @param[in] platform_type Target platform type.
179-
* @param[in] device_id Target device id.
179+
* @param[in] device Target device id.
180180
* @return int
181181
*/
182182
int ispc_init(struct nomp_backend_t *backend, const int platform_type,
183-
const int device_id);
183+
const int device);
184184

185185
#ifdef __cplusplus
186186
}

0 commit comments

Comments
 (0)