summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunyan He <junyan.he@intel.com>2016-04-21 00:44:17 +0800
committerJunyan He <junyan.he@intel.com>2016-04-21 00:44:17 +0800
commit3710d95552f2c5d55578b22638e6b38f193e5d6f (patch)
tree228f0217dc8bafcf599b61487d4d78fe0bcf06e3
parentc64f7afc8a79c8e231d4955b57b8684d0b1e1800 (diff)
alloc
-rw-r--r--libclapi/cl_context.c30
-rw-r--r--libclapi/cl_device_id.c18
-rw-r--r--libclapi/cl_internals.h3
3 files changed, 24 insertions, 27 deletions
diff --git a/libclapi/cl_context.c b/libclapi/cl_context.c
index 5e0ea756..5d0f2b6c 100644
--- a/libclapi/cl_context.c
+++ b/libclapi/cl_context.c
@@ -108,34 +108,34 @@ static cl_context cl_context_new(const cl_context_properties *properties,
cl_context ctx = NULL;
cl_uint i;
- ctx = CALLOC(struct _cl_context);
+ ctx = CL_CALLOC(1, sizeof(_cl_context));
if (ctx == NULL)
return NULL;
- ctx->devices = CALLOC_ARRAY(cl_device_id, num_devices);
+ ctx->devices = CL_CALLOC(num_devices, sizeof(cl_device_id));
if (ctx->devices == NULL) {
- cl_free(ctx);
+ CL_FREE(ctx);
return NULL;
}
/* Create the private pointer array if device > 1 */
if (num_devices > 1) {
- ctx->pdata = CALLOC_ARRAY(void*, num_devices);
+ ctx->pdata = CL_CALLOC(num_devices, sizeof(void*));
if (ctx->pdata == NULL) {
- cl_free(ctx->devices);
- cl_free(ctx);
+ CL_FREE(ctx->devices);
+ CL_FREE(ctx);
return NULL;
}
}
if(properties != NULL && prop_len > 0) {
- ctx->prop_user = CALLOC_ARRAY(cl_context_properties, prop_len);
+ ctx->prop_user = CL_CALLOC(prop_len, sizeof(cl_context_properties));
if (ctx->prop_user == NULL) {
- cl_free(ctx->devices);
+ CL_FREE(ctx->devices);
if (ctx->device_num > 1) {
- cl_free(ctx->pdata);
+ CL_FREE(ctx->pdata);
}
- cl_free(ctx);
+ CL_FREE(ctx);
return NULL;
}
@@ -176,12 +176,12 @@ static void cl_context_delete(cl_context ctx)
}
if (ctx->device_num > 1) {
- cl_free(ctx->pdata);
+ CL_FREE(ctx->pdata);
}
- cl_free(ctx->prop_user);
- cl_free(ctx->devices);
+ CL_FREE(ctx->prop_user);
+ CL_FREE(ctx->devices);
ctx->magic = CL_MAGIC_DEAD_HEADER; /* For safety */
- cl_free(ctx);
+ CL_FREE(ctx);
}
LOCAL void cl_release_context(cl_context ctx)
@@ -198,7 +198,7 @@ LOCAL void cl_release_context(cl_context ctx)
assert(err == CL_SUCCESS);
if (barrier_events_list) {
assert(barrier_events_num > 0);
- cl_free(barrier_events_list);
+ CL_FREE(barrier_events_list);
}
/* We are not done yet */
diff --git a/libclapi/cl_device_id.c b/libclapi/cl_device_id.c
index 8c6b7b7f..30667698 100644
--- a/libclapi/cl_device_id.c
+++ b/libclapi/cl_device_id.c
@@ -66,7 +66,7 @@ static cl_int cl_get_device_ids(cl_platform_id platform, cl_device_type device_t
if (cl_driver_inited == 0) {
- char* dir_path = cl_malloc((strlen(OCL_DRIVER_DIRS) + 1) * sizeof(char));
+ char* dir_path = CL_MALLOC((strlen(OCL_DRIVER_DIRS) + 1) * sizeof(char));
strcpy(dir_path, OCL_DRIVER_DIRS);
cl_driver_inited = 1;
@@ -96,11 +96,11 @@ static cl_int cl_get_device_ids(cl_platform_id platform, cl_device_type device_t
continue;
/* Try to dlopen it. */
- path = cl_malloc(len + strlen(p) + 1 + 1);
+ path = CL_MALLOC(len + strlen(p) + 1 + 1);
sprintf(path, "%s/%s", p, dirp->d_name);
handle = dlopen(path, RTLD_LAZY | RTLD_LOCAL);
if (!handle) {
- cl_free(path);
+ CL_FREE(path);
continue;
}
@@ -118,19 +118,19 @@ static cl_int cl_get_device_ids(cl_platform_id platform, cl_device_type device_t
drv = (cl_driver)dlsym(handle, driver_name);
if (drv == NULL) {
dlclose(handle);
- cl_free(path);
+ CL_FREE(path);
continue;
}
/* Try it.*/
if (cl_driver_check(drv) != CL_SUCCESS || drv->init(platform) != CL_SUCCESS) {
dlclose(handle);
- cl_free(path);
+ CL_FREE(path);
continue;
}
cl_driver_num++;
- cl_driver_backend tmp_d = cl_realloc(cl_all_drivers, cl_driver_num * sizeof(_cl_driver_backend));
+ cl_driver_backend tmp_d = CL_REALLOC(cl_all_drivers, cl_driver_num * sizeof(_cl_driver_backend));
cl_all_drivers = tmp_d;
cl_all_drivers[cl_driver_num - 1].path_name = path;
cl_all_drivers[cl_driver_num - 1].handle = handle;
@@ -141,7 +141,7 @@ static cl_int cl_get_device_ids(cl_platform_id platform, cl_device_type device_t
p = strtok(NULL,":");
}
- cl_free(dir_path);
+ CL_FREE(dir_path);
}
if (cl_driver_num) {
@@ -150,7 +150,7 @@ static cl_int cl_get_device_ids(cl_platform_id platform, cl_device_type device_t
for (i = 0; i < cl_driver_num; i++) {
if (cl_all_drivers[i].drv->get_device_ids(platform, device_type, 0, NULL, &tmp_n) == CL_SUCCESS) {
if (devices && tmp_n) {
- cl_device_id *tmp_devices = cl_calloc(tmp_n, sizeof(cl_device_id));
+ cl_device_id *tmp_devices = CL_CALLOC(tmp_n, sizeof(cl_device_id));
if (cl_all_drivers[i].drv->get_device_ids(
platform, device_type, tmp_n, tmp_devices, &tmp_n) == CL_SUCCESS) {
for (j = 0; j < tmp_n; j++) {
@@ -161,7 +161,7 @@ static cl_int cl_get_device_ids(cl_platform_id platform, cl_device_type device_t
total_dev_num++;
}
}
- cl_free(tmp_devices);
+ CL_FREE(tmp_devices);
} else {
total_dev_num += tmp_n;
}
diff --git a/libclapi/cl_internals.h b/libclapi/cl_internals.h
index 4192a20b..1c6b03c0 100644
--- a/libclapi/cl_internals.h
+++ b/libclapi/cl_internals.h
@@ -377,9 +377,6 @@ do { \
} while (0)
#define ELEMENTS(x) (sizeof(x)/sizeof(*(x)))
-#define CALLOC_STRUCT(T) (struct T*) cl_calloc(1, sizeof(struct T))
-#define CALLOC(T) (T*) cl_calloc(1, sizeof(T))
-#define CALLOC_ARRAY(T, N) (T*) cl_calloc(N, sizeof(T))
#define MEMZERO(x) do { memset((x),0,sizeof(*(x))); } while (0)
/* Run some code and catch errors */