mirror of https://git.ffmpeg.org/ffmpeg.git
OpenCL: Fix ABI incompatibility issues
AVOpenCLDeviceNode and AVOpenCLPlatformNode used fixed static buffer for holding the device and platform name. This patch modifies these structures to use pointers instead. The memory required to hold the names is now dynamically allocated, the size for which is determined by querying appropriate OpenCL runtime APIs. Signed-off-by: Maneesh Gupta <maneesh.gupta@amd.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
cf234552b8
commit
91305c6026
|
@ -181,9 +181,11 @@ static void free_device_list(AVOpenCLDeviceList *device_list)
|
||||||
if (!device_list->platform_node[i])
|
if (!device_list->platform_node[i])
|
||||||
continue;
|
continue;
|
||||||
for (j = 0; j < device_list->platform_node[i]->device_num; j++) {
|
for (j = 0; j < device_list->platform_node[i]->device_num; j++) {
|
||||||
|
av_freep(&(device_list->platform_node[i]->device_node[j]->device_name));
|
||||||
av_freep(&(device_list->platform_node[i]->device_node[j]));
|
av_freep(&(device_list->platform_node[i]->device_node[j]));
|
||||||
}
|
}
|
||||||
av_freep(&device_list->platform_node[i]->device_node);
|
av_freep(&device_list->platform_node[i]->device_node);
|
||||||
|
av_freep(&(device_list->platform_node[i]->platform_name));
|
||||||
av_freep(&device_list->platform_node[i]);
|
av_freep(&device_list->platform_node[i]);
|
||||||
}
|
}
|
||||||
av_freep(&device_list->platform_node);
|
av_freep(&device_list->platform_node);
|
||||||
|
@ -198,6 +200,8 @@ static int get_device_list(AVOpenCLDeviceList *device_list)
|
||||||
cl_platform_id *platform_ids = NULL;
|
cl_platform_id *platform_ids = NULL;
|
||||||
cl_device_id *device_ids = NULL;
|
cl_device_id *device_ids = NULL;
|
||||||
AVOpenCLDeviceNode *device_node = NULL;
|
AVOpenCLDeviceNode *device_node = NULL;
|
||||||
|
size_t platform_name_size = 0;
|
||||||
|
size_t device_name_size = 0;
|
||||||
status = clGetPlatformIDs(0, NULL, &device_list->platform_num);
|
status = clGetPlatformIDs(0, NULL, &device_list->platform_num);
|
||||||
if (status != CL_SUCCESS) {
|
if (status != CL_SUCCESS) {
|
||||||
av_log(&opencl_ctx, AV_LOG_ERROR,
|
av_log(&opencl_ctx, AV_LOG_ERROR,
|
||||||
|
@ -232,8 +236,25 @@ static int get_device_list(AVOpenCLDeviceList *device_list)
|
||||||
}
|
}
|
||||||
device_list->platform_node[i]->platform_id = platform_ids[i];
|
device_list->platform_node[i]->platform_id = platform_ids[i];
|
||||||
status = clGetPlatformInfo(platform_ids[i], CL_PLATFORM_VENDOR,
|
status = clGetPlatformInfo(platform_ids[i], CL_PLATFORM_VENDOR,
|
||||||
sizeof(device_list->platform_node[i]->platform_name),
|
0, NULL, &platform_name_size);
|
||||||
|
if (status != CL_SUCCESS) {
|
||||||
|
av_log(&opencl_ctx, AV_LOG_WARNING,
|
||||||
|
"Could not get size of platform name: %s\n", av_opencl_errstr(status));
|
||||||
|
} else {
|
||||||
|
device_list->platform_node[i]->platform_name = av_malloc(platform_name_size * sizeof(char));
|
||||||
|
if (!device_list->platform_node[i]->platform_name) {
|
||||||
|
av_log(&opencl_ctx, AV_LOG_WARNING,
|
||||||
|
"Could not allocate memory for device name: %s\n", av_opencl_errstr(status));
|
||||||
|
} else {
|
||||||
|
status = clGetPlatformInfo(platform_ids[i], CL_PLATFORM_VENDOR,
|
||||||
|
platform_name_size * sizeof(char),
|
||||||
device_list->platform_node[i]->platform_name, NULL);
|
device_list->platform_node[i]->platform_name, NULL);
|
||||||
|
if (status != CL_SUCCESS) {
|
||||||
|
av_log(&opencl_ctx, AV_LOG_WARNING,
|
||||||
|
"Could not get platform name: %s\n", av_opencl_errstr(status));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
total_devices_num = 0;
|
total_devices_num = 0;
|
||||||
for (j = 0; j < FF_ARRAY_ELEMS(device_type); j++) {
|
for (j = 0; j < FF_ARRAY_ELEMS(device_type); j++) {
|
||||||
status = clGetDeviceIDs(device_list->platform_node[i]->platform_id,
|
status = clGetDeviceIDs(device_list->platform_node[i]->platform_id,
|
||||||
|
@ -271,8 +292,21 @@ static int get_device_list(AVOpenCLDeviceList *device_list)
|
||||||
device_node->device_id = device_ids[k];
|
device_node->device_id = device_ids[k];
|
||||||
device_node->device_type = device_type[j];
|
device_node->device_type = device_type[j];
|
||||||
status = clGetDeviceInfo(device_node->device_id, CL_DEVICE_NAME,
|
status = clGetDeviceInfo(device_node->device_id, CL_DEVICE_NAME,
|
||||||
sizeof(device_node->device_name), device_node->device_name,
|
0, NULL, &device_name_size);
|
||||||
NULL);
|
if (status != CL_SUCCESS) {
|
||||||
|
av_log(&opencl_ctx, AV_LOG_WARNING,
|
||||||
|
"Could not get size of device name: %s\n", av_opencl_errstr(status));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
device_node->device_name = av_malloc(device_name_size * sizeof(char));
|
||||||
|
if (!device_node->device_name) {
|
||||||
|
av_log(&opencl_ctx, AV_LOG_WARNING,
|
||||||
|
"Could not allocate memory for device name: %s\n", av_opencl_errstr(status));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
status = clGetDeviceInfo(device_node->device_id, CL_DEVICE_NAME,
|
||||||
|
device_name_size * sizeof(char),
|
||||||
|
device_node->device_name, NULL);
|
||||||
if (status != CL_SUCCESS) {
|
if (status != CL_SUCCESS) {
|
||||||
av_log(&opencl_ctx, AV_LOG_WARNING,
|
av_log(&opencl_ctx, AV_LOG_WARNING,
|
||||||
"Could not get device name: %s\n", av_opencl_errstr(status));
|
"Could not get device name: %s\n", av_opencl_errstr(status));
|
||||||
|
|
|
@ -44,21 +44,15 @@
|
||||||
|
|
||||||
#define AV_OPENCL_KERNEL( ... )# __VA_ARGS__
|
#define AV_OPENCL_KERNEL( ... )# __VA_ARGS__
|
||||||
|
|
||||||
#define AV_OPENCL_MAX_KERNEL_NAME_SIZE 150
|
|
||||||
|
|
||||||
#define AV_OPENCL_MAX_DEVICE_NAME_SIZE 100
|
|
||||||
|
|
||||||
#define AV_OPENCL_MAX_PLATFORM_NAME_SIZE 100
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int device_type;
|
int device_type;
|
||||||
char device_name[AV_OPENCL_MAX_DEVICE_NAME_SIZE];
|
char *device_name;
|
||||||
cl_device_id device_id;
|
cl_device_id device_id;
|
||||||
} AVOpenCLDeviceNode;
|
} AVOpenCLDeviceNode;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
cl_platform_id platform_id;
|
cl_platform_id platform_id;
|
||||||
char platform_name[AV_OPENCL_MAX_PLATFORM_NAME_SIZE];
|
char *platform_name;
|
||||||
int device_num;
|
int device_num;
|
||||||
AVOpenCLDeviceNode **device_node;
|
AVOpenCLDeviceNode **device_node;
|
||||||
} AVOpenCLPlatformNode;
|
} AVOpenCLPlatformNode;
|
||||||
|
|
Loading…
Reference in New Issue