Browse code

lavu/opencl: add opencl public error API

Reviewed-by: Stefano Sabatini <stefasab@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

highgod0401 authored on 2013/04/28 09:47:20
Showing 3 changed files
... ...
@@ -163,7 +163,7 @@ static const OpenclErrorMsg opencl_err_msg[] = {
163 163
     {CL_INVALID_DEVICE_PARTITION_COUNT,                 "INVALID DEVICE PARTITION COUNT"},
164 164
 };
165 165
 
166
-static const char *opencl_errstr(cl_int status)
166
+const char *av_opencl_errstr(cl_int status)
167 167
 {
168 168
     int i;
169 169
     for (i = 0; i < sizeof(opencl_err_msg); i++) {
... ...
@@ -202,7 +202,7 @@ static int get_device_list(AVOpenCLDeviceList *device_list)
202 202
     status = clGetPlatformIDs(0, NULL, &device_list->platform_num);
203 203
     if (status != CL_SUCCESS) {
204 204
         av_log(&opencl_ctx, AV_LOG_ERROR,
205
-               "Could not get OpenCL platform ids: %s\n", opencl_errstr(status));
205
+               "Could not get OpenCL platform ids: %s\n", av_opencl_errstr(status));
206 206
         return AVERROR_EXTERNAL;
207 207
     }
208 208
     platform_ids = av_mallocz(device_list->platform_num * sizeof(cl_platform_id));
... ...
@@ -211,7 +211,7 @@ static int get_device_list(AVOpenCLDeviceList *device_list)
211 211
     status = clGetPlatformIDs(device_list->platform_num, platform_ids, NULL);
212 212
     if (status != CL_SUCCESS) {
213 213
         av_log(&opencl_ctx, AV_LOG_ERROR,
214
-                "Could not get OpenCL platform ids: %s\n", opencl_errstr(status));
214
+                "Could not get OpenCL platform ids: %s\n", av_opencl_errstr(status));
215 215
         ret = AVERROR_EXTERNAL;
216 216
         goto end;
217 217
     }
... ...
@@ -257,7 +257,7 @@ static int get_device_list(AVOpenCLDeviceList *device_list)
257 257
                                         devices_num[j], device_ids, NULL);
258 258
                 if (status != CL_SUCCESS) {
259 259
                     av_log(&opencl_ctx, AV_LOG_WARNING,
260
-                            "Could not get device ID: %s:\n", opencl_errstr(status));
260
+                            "Could not get device ID: %s:\n", av_opencl_errstr(status));
261 261
                     av_freep(&device_ids);
262 262
                     continue;
263 263
                 }
... ...
@@ -276,7 +276,7 @@ static int get_device_list(AVOpenCLDeviceList *device_list)
276 276
                                              NULL);
277 277
                     if (status != CL_SUCCESS) {
278 278
                         av_log(&opencl_ctx, AV_LOG_WARNING,
279
-                                "Could not get device name: %s\n", opencl_errstr(status));
279
+                                "Could not get device name: %s\n", av_opencl_errstr(status));
280 280
                         continue;
281 281
                     }
282 282
                     device_list->platform_node[i]->device_num++;
... ...
@@ -417,7 +417,7 @@ int av_opencl_create_kernel(AVOpenCLKernelEnv *env, const char *kernel_name)
417 417
                 break;
418 418
         }
419 419
         if (status != CL_SUCCESS) {
420
-            av_log(&opencl_ctx, AV_LOG_ERROR, "Could not create OpenCL kernel: %s\n", opencl_errstr(status));
420
+            av_log(&opencl_ctx, AV_LOG_ERROR, "Could not create OpenCL kernel: %s\n", av_opencl_errstr(status));
421 421
             ret = AVERROR_EXTERNAL;
422 422
             goto end;
423 423
         }
... ...
@@ -439,7 +439,7 @@ void av_opencl_release_kernel(AVOpenCLKernelEnv *env)
439 439
     status = clReleaseKernel(env->kernel);
440 440
     if (status != CL_SUCCESS) {
441 441
         av_log(&opencl_ctx, AV_LOG_ERROR, "Could not release kernel: %s\n",
442
-              opencl_errstr(status));
442
+              av_opencl_errstr(status));
443 443
     }
444 444
     env->kernel = NULL;
445 445
     env->command_queue = NULL;
... ...
@@ -527,14 +527,14 @@ static int init_opencl_env(OpenclContext *opencl_ctx, AVOpenCLExternalEnv *ext_o
527 527
                                                        NULL, NULL, &status);
528 528
             if (status != CL_SUCCESS) {
529 529
                 av_log(opencl_ctx, AV_LOG_ERROR,
530
-                       "Could not get OpenCL context from device type: %s\n", opencl_errstr(status));
530
+                       "Could not get OpenCL context from device type: %s\n", av_opencl_errstr(status));
531 531
                 return AVERROR_EXTERNAL;
532 532
             }
533 533
             opencl_ctx->command_queue = clCreateCommandQueue(opencl_ctx->context, opencl_ctx->device_id,
534 534
                                                           0, &status);
535 535
             if (status != CL_SUCCESS) {
536 536
                 av_log(opencl_ctx, AV_LOG_ERROR,
537
-                       "Could not create OpenCL command queue: %s\n", opencl_errstr(status));
537
+                       "Could not create OpenCL command queue: %s\n", av_opencl_errstr(status));
538 538
                 return AVERROR_EXTERNAL;
539 539
             }
540 540
         }
... ...
@@ -567,7 +567,7 @@ static int compile_kernel_file(OpenclContext *opencl_ctx)
567 567
                                                                                 &status);
568 568
     if(status != CL_SUCCESS) {
569 569
         av_log(opencl_ctx, AV_LOG_ERROR,
570
-               "Could not create OpenCL program with source code: %s\n", opencl_errstr(status));
570
+               "Could not create OpenCL program with source code: %s\n", av_opencl_errstr(status));
571 571
         return AVERROR_EXTERNAL;
572 572
     }
573 573
     if (!opencl_ctx->programs[opencl_ctx->program_count]) {
... ...
@@ -578,7 +578,7 @@ static int compile_kernel_file(OpenclContext *opencl_ctx)
578 578
                             opencl_ctx->build_options, NULL, NULL);
579 579
     if (status != CL_SUCCESS) {
580 580
         av_log(opencl_ctx, AV_LOG_ERROR,
581
-               "Could not compile OpenCL kernel: %s\n", opencl_errstr(status));
581
+               "Could not compile OpenCL kernel: %s\n", av_opencl_errstr(status));
582 582
         return AVERROR_EXTERNAL;
583 583
     }
584 584
     opencl_ctx->program_count++;
... ...
@@ -629,7 +629,7 @@ void av_opencl_uninit(void)
629 629
             status = clReleaseProgram(opencl_ctx.programs[i]);
630 630
             if (status != CL_SUCCESS) {
631 631
                 av_log(&opencl_ctx, AV_LOG_ERROR,
632
-                       "Could not release OpenCL program: %s\n", opencl_errstr(status));
632
+                       "Could not release OpenCL program: %s\n", av_opencl_errstr(status));
633 633
             }
634 634
             opencl_ctx.programs[i] = NULL;
635 635
         }
... ...
@@ -638,7 +638,7 @@ void av_opencl_uninit(void)
638 638
         status = clReleaseCommandQueue(opencl_ctx.command_queue);
639 639
         if (status != CL_SUCCESS) {
640 640
             av_log(&opencl_ctx, AV_LOG_ERROR,
641
-                   "Could not release OpenCL command queue: %s\n", opencl_errstr(status));
641
+                   "Could not release OpenCL command queue: %s\n", av_opencl_errstr(status));
642 642
         }
643 643
         opencl_ctx.command_queue = NULL;
644 644
     }
... ...
@@ -646,7 +646,7 @@ void av_opencl_uninit(void)
646 646
         status = clReleaseContext(opencl_ctx.context);
647 647
         if (status != CL_SUCCESS) {
648 648
             av_log(&opencl_ctx, AV_LOG_ERROR,
649
-                   "Could not release OpenCL context: %s\n", opencl_errstr(status));
649
+                   "Could not release OpenCL context: %s\n", av_opencl_errstr(status));
650 650
         }
651 651
         opencl_ctx.context = NULL;
652 652
     }
... ...
@@ -662,7 +662,7 @@ int av_opencl_buffer_create(cl_mem *cl_buf, size_t cl_buf_size, int flags, void
662 662
     cl_int status;
663 663
     *cl_buf = clCreateBuffer(opencl_ctx.context, flags, cl_buf_size, host_ptr, &status);
664 664
     if (status != CL_SUCCESS) {
665
-        av_log(&opencl_ctx, AV_LOG_ERROR, "Could not create OpenCL buffer: %s\n", opencl_errstr(status));
665
+        av_log(&opencl_ctx, AV_LOG_ERROR, "Could not create OpenCL buffer: %s\n", av_opencl_errstr(status));
666 666
         return AVERROR_EXTERNAL;
667 667
     }
668 668
     return 0;
... ...
@@ -676,7 +676,7 @@ void av_opencl_buffer_release(cl_mem *cl_buf)
676 676
     status = clReleaseMemObject(*cl_buf);
677 677
     if (status != CL_SUCCESS) {
678 678
         av_log(&opencl_ctx, AV_LOG_ERROR,
679
-               "Could not release OpenCL buffer: %s\n", opencl_errstr(status));
679
+               "Could not release OpenCL buffer: %s\n", av_opencl_errstr(status));
680 680
     }
681 681
     memset(cl_buf, 0, sizeof(*cl_buf));
682 682
 }
... ...
@@ -690,7 +690,7 @@ int av_opencl_buffer_write(cl_mem dst_cl_buf, uint8_t *src_buf, size_t buf_size)
690 690
 
691 691
     if (status != CL_SUCCESS) {
692 692
         av_log(&opencl_ctx, AV_LOG_ERROR,
693
-               "Could not map OpenCL buffer: %s\n", opencl_errstr(status));
693
+               "Could not map OpenCL buffer: %s\n", av_opencl_errstr(status));
694 694
         return AVERROR_EXTERNAL;
695 695
     }
696 696
     memcpy(mapped, src_buf, buf_size);
... ...
@@ -698,7 +698,7 @@ int av_opencl_buffer_write(cl_mem dst_cl_buf, uint8_t *src_buf, size_t buf_size)
698 698
     status = clEnqueueUnmapMemObject(opencl_ctx.command_queue, dst_cl_buf, mapped, 0, NULL, NULL);
699 699
     if (status != CL_SUCCESS) {
700 700
         av_log(&opencl_ctx, AV_LOG_ERROR,
701
-               "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status));
701
+               "Could not unmap OpenCL buffer: %s\n", av_opencl_errstr(status));
702 702
         return AVERROR_EXTERNAL;
703 703
     }
704 704
     return 0;
... ...
@@ -713,7 +713,7 @@ int av_opencl_buffer_read(uint8_t *dst_buf, cl_mem src_cl_buf, size_t buf_size)
713 713
 
714 714
     if (status != CL_SUCCESS) {
715 715
         av_log(&opencl_ctx, AV_LOG_ERROR,
716
-               "Could not map OpenCL buffer: %s\n", opencl_errstr(status));
716
+               "Could not map OpenCL buffer: %s\n", av_opencl_errstr(status));
717 717
         return AVERROR_EXTERNAL;
718 718
     }
719 719
     memcpy(dst_buf, mapped, buf_size);
... ...
@@ -721,7 +721,7 @@ int av_opencl_buffer_read(uint8_t *dst_buf, cl_mem src_cl_buf, size_t buf_size)
721 721
     status = clEnqueueUnmapMemObject(opencl_ctx.command_queue, src_cl_buf, mapped, 0, NULL, NULL);
722 722
     if (status != CL_SUCCESS) {
723 723
         av_log(&opencl_ctx, AV_LOG_ERROR,
724
-               "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status));
724
+               "Could not unmap OpenCL buffer: %s\n", av_opencl_errstr(status));
725 725
         return AVERROR_EXTERNAL;
726 726
     }
727 727
     return 0;
... ...
@@ -750,7 +750,7 @@ int av_opencl_buffer_write_image(cl_mem dst_cl_buf, size_t cl_buffer_size, int d
750 750
                                 0, NULL, NULL, &status);
751 751
     if (status != CL_SUCCESS) {
752 752
         av_log(&opencl_ctx, AV_LOG_ERROR,
753
-               "Could not map OpenCL buffer: %s\n", opencl_errstr(status));
753
+               "Could not map OpenCL buffer: %s\n", av_opencl_errstr(status));
754 754
         return AVERROR_EXTERNAL;
755 755
     }
756 756
     temp = mapped;
... ...
@@ -762,7 +762,7 @@ int av_opencl_buffer_write_image(cl_mem dst_cl_buf, size_t cl_buffer_size, int d
762 762
     status = clEnqueueUnmapMemObject(opencl_ctx.command_queue, dst_cl_buf, mapped, 0, NULL, NULL);
763 763
     if (status != CL_SUCCESS) {
764 764
         av_log(&opencl_ctx, AV_LOG_ERROR,
765
-               "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status));
765
+               "Could not unmap OpenCL buffer: %s\n", av_opencl_errstr(status));
766 766
         return AVERROR_EXTERNAL;
767 767
     }
768 768
     return 0;
... ...
@@ -792,7 +792,7 @@ int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_n
792 792
 
793 793
     if (status != CL_SUCCESS) {
794 794
         av_log(&opencl_ctx, AV_LOG_ERROR,
795
-               "Could not map OpenCL buffer: %s\n", opencl_errstr(status));
795
+               "Could not map OpenCL buffer: %s\n", av_opencl_errstr(status));
796 796
         return AVERROR_EXTERNAL;
797 797
     }
798 798
     temp = mapped;
... ...
@@ -805,7 +805,7 @@ int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_n
805 805
     status = clEnqueueUnmapMemObject(opencl_ctx.command_queue, src_cl_buf, mapped, 0, NULL, NULL);
806 806
     if (status != CL_SUCCESS) {
807 807
         av_log(&opencl_ctx, AV_LOG_ERROR,
808
-               "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status));
808
+               "Could not unmap OpenCL buffer: %s\n", av_opencl_errstr(status));
809 809
         return AVERROR_EXTERNAL;
810 810
     }
811 811
     return 0;
... ...
@@ -155,6 +155,14 @@ AVOpenCLExternalEnv *av_opencl_alloc_external_env(void);
155 155
 void av_opencl_free_external_env(AVOpenCLExternalEnv **ext_opencl_env);
156 156
 
157 157
 /**
158
+ * Get OpenCL error string.
159
+ *
160
+ * @param status    OpenCL error code
161
+ * @return OpenCL error string
162
+ */
163
+const char *av_opencl_errstr(cl_int status);
164
+
165
+/**
158 166
  * Register kernel code.
159 167
  *
160 168
  *  The registered kernel code is stored in a global context, and compiled
... ...
@@ -75,7 +75,7 @@
75 75
  */
76 76
 
77 77
 #define LIBAVUTIL_VERSION_MAJOR  52
78
-#define LIBAVUTIL_VERSION_MINOR  28
78
+#define LIBAVUTIL_VERSION_MINOR  29
79 79
 #define LIBAVUTIL_VERSION_MICRO 100
80 80
 
81 81
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \