Skip to content

Commit

Permalink
ocl: adjusted internal interface
Browse files Browse the repository at this point in the history
* Adjusted c_dbcsr_acc_opencl_flags_atomics.
* Code/interface comment.
  • Loading branch information
hfp committed Mar 22, 2024
1 parent abf8fcf commit ba435bf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
16 changes: 9 additions & 7 deletions src/acc/opencl/acc_opencl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,16 +1150,17 @@ int c_dbcsr_acc_opencl_wgsize(cl_device_id device, cl_kernel kernel, size_t* max


int c_dbcsr_acc_opencl_flags_atomics(const c_dbcsr_acc_opencl_device_t* devinfo, c_dbcsr_acc_opencl_atomic_fp_t kind,
const char* exts[], int exts_maxlen, char flags[], size_t flags_maxlen) {
const char* exts[], size_t* exts_maxlen, char flags[], size_t flags_maxlen) {
cl_device_id device_id = NULL;
int result = 0, ext1, ext2;
for (ext1 = 0; ext1 < exts_maxlen; ++ext1) {
size_t ext1, ext2;
int result = 0;
for (ext1 = 0; ext1 < (NULL != exts_maxlen ? *exts_maxlen : 0); ++ext1) {
if (NULL == exts[ext1] || '\0' == *exts[ext1]) break;
}
for (ext2 = ext1 + 1; ext2 < exts_maxlen; ++ext2) {
for (ext2 = ext1 + 1; ext2 < (NULL != exts_maxlen ? *exts_maxlen : 0); ++ext2) {
if (NULL == exts[ext2] || '\0' == *exts[ext2]) break;
}
if (NULL != devinfo && ext2 < exts_maxlen &&
if (NULL != devinfo && NULL != exts_maxlen && ext2 < *exts_maxlen &&
EXIT_SUCCESS == clGetContextInfo(devinfo->context, CL_CONTEXT_DEVICES, sizeof(cl_device_id), &device_id, NULL))
{
const char* atomic_type = "";
Expand Down Expand Up @@ -1227,8 +1228,9 @@ int c_dbcsr_acc_opencl_flags_atomics(const c_dbcsr_acc_opencl_device_t* devinfo,
&fp_atomics, NULL) &&
0 != (/*add*/ (1 << 1) & fp_atomics))
{
# if 0 /* enabling this permitted extension in source code causes compiler warning */
exts[ext2] = "cl_ext_float_atomics";
# if 1 /* enabling this permitted extension in source code causes compiler warning */
*exts_maxlen = ext2; /* quietly report extension by reducing exts_maxlen */
# endif
atomic_exp = (c_dbcsr_acc_opencl_atomic_fp_64 == kind
? "atomic_fetch_add_explicit((GLOBAL_VOLATILE(atomic_double)*)A,B,"
Expand Down Expand Up @@ -1323,7 +1325,7 @@ int c_dbcsr_acc_opencl_flags(


int c_dbcsr_acc_opencl_kernel(int source_is_file, const char source[], const char kernel_name[], const char build_params[],
const char build_options[], const char try_build_options[], int* try_ok, const char* const extnames[], int num_exts,
const char build_options[], const char try_build_options[], int* try_ok, const char* const extnames[], size_t num_exts,
cl_kernel* kernel) {
char buffer[ACC_OPENCL_BUFFERSIZE] = "", buffer_name[ACC_OPENCL_MAXSTRLEN * 2];
int ok = EXIT_SUCCESS, source_is_cl = 1, nchar;
Expand Down
6 changes: 3 additions & 3 deletions src/acc/opencl/acc_opencl.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ typedef struct c_dbcsr_acc_opencl_device_t {
c_dbcsr_acc_opencl_stream_t stream;
/** OpenCL compiler flag (language standard). */
char std_flag[16];
/** OpenCL support-level of device. */
/** OpenCL support-level (major and minor). */
cl_int std_level[2], std_clevel[2];
/** Kind of device (GPU, CPU, or other). */
cl_device_type type;
Expand Down Expand Up @@ -389,13 +389,13 @@ int c_dbcsr_acc_opencl_wgsize(cl_device_id device, cl_kernel kernel, size_t* max
* are are meant to be compiler-flags.
*/
int c_dbcsr_acc_opencl_kernel(int source_is_file, const char source[], const char kernel_name[], const char build_params[],
const char build_options[], const char try_build_options[], int* try_ok, const char* const extnames[], int num_exts,
const char build_options[], const char try_build_options[], int* try_ok, const char* const extnames[], size_t num_exts,
cl_kernel* kernel);
/** Per-thread variant of c_dbcsr_acc_device_synchronize. */
int c_dbcsr_acc_opencl_device_synchronize(ACC_OPENCL_LOCKTYPE* lock, int thread_id);
/** Assemble flags to support atomic operations. */
int c_dbcsr_acc_opencl_flags_atomics(const c_dbcsr_acc_opencl_device_t* devinfo, c_dbcsr_acc_opencl_atomic_fp_t kind,
const char* exts[], int exts_maxlen, char flags[], size_t flags_maxlen);
const char* exts[], size_t* exts_maxlen, char flags[], size_t flags_maxlen);
/** Combines build-params and build-options, optional flags (try_build_options). */
int c_dbcsr_acc_opencl_flags(
const char build_params[], const char build_options[], const char try_build_options[], char buffer[], size_t buffer_size);
Expand Down
6 changes: 3 additions & 3 deletions src/acc/opencl/smm/opencl_libsmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ int libsmm_acc_process(const int* host_param_stack, const int* dev_param_stack,
const char *extensions[] = {NULL, NULL}, *const env_devid = getenv("OPENCL_LIBSMM_SMM_DEVID");
const unsigned int devuid = (NULL == env_devid || '\0' == *env_devid) ? c_dbcsr_acc_opencl_config.device.uid
: (unsigned int)strtoul(env_devid, NULL, 0);
size_t wgsize_max, wgsize_prf, sgs = 0;
size_t nextensions = sizeof(extensions) / sizeof(*extensions), wgsize_max, wgsize_prf, sgs = 0;
opencl_libsmm_smm_t new_config;
if (NULL == config) {
memset(&new_config, 0, sizeof(new_config));
Expand Down Expand Up @@ -1263,7 +1263,7 @@ int libsmm_acc_process(const int* host_param_stack, const int* dev_param_stack,
/* apply support for FP-atomics */
if (0 < nchar && (int)sizeof(build_params) > nchar) {
nchar = c_dbcsr_acc_opencl_flags_atomics(&c_dbcsr_acc_opencl_config.device, tkind, extensions,
sizeof(extensions) / sizeof(*extensions), build_params + nchar, sizeof(build_params) - nchar);
&nextensions, build_params + nchar, sizeof(build_params) - nchar);
}
else result = EXIT_FAILURE;
if (0 < nchar && (int)sizeof(build_params) > nchar) {
Expand All @@ -1290,7 +1290,7 @@ int libsmm_acc_process(const int* host_param_stack, const int* dev_param_stack,
const char* const env_kernel = getenv("OPENCL_LIBSMM_SMM_KERNEL");
result = c_dbcsr_acc_opencl_kernel(NULL == env_kernel ? 0 : 1,
NULL == env_kernel ? OPENCL_KERNELS_SOURCE_MULTIPLY : env_kernel, fname, build_params, buffer, NULL /*cl_try*/,
NULL /*cl_try_ok*/, extensions, sizeof(extensions) / sizeof(*extensions), new_config.kernel + kernel_idx);
NULL /*cl_try_ok*/, extensions, nextensions, new_config.kernel + kernel_idx);
if (EXIT_SUCCESS == result) {
size_t wgsize_max_kernel = wgsize_max;
result = c_dbcsr_acc_opencl_wgsize(
Expand Down

0 comments on commit ba435bf

Please sign in to comment.