1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373
|
//
// opencl_loader.cpp
// libOpenCL_loader
//
// Created by Guohui Wang on 4/23/18.
// Copyright © 2019 Guohui Wang. All rights reserved.
//
#ifdef __ANDROID__
#include "opencl_loader.h"
#include "opencl_header_private.h"
#include <iostream>
#include <memory>
#ifdef __ANDROID_API__
#include <android/log.h>
#define CL_LOADER_LOG(...) \
__android_log_print(ANDROID_LOG_VERBOSE, "libopencl_loader", __VA_ARGS__)
#define CL_LOADER_LOGD(...) \
__android_log_print(ANDROID_LOG_DEBUG, "libopencl_loader", __VA_ARGS__)
#define CL_LOADER_LOGW(...) \
__android_log_print(ANDROID_LOG_WARN, "libopencl_loader", __VA_ARGS__)
#define CL_LOADER_LOGE(...) \
__android_log_print(ANDROID_LOG_ERROR, "libopencl_loader", __VA_ARGS__)
#else
#define CL_LOADER_LOG(...) printf(__VA_ARGS__)
#define CL_LOADER_LOGD(...) printf(__VA_ARGS__)
#define CL_LOADER_LOGW(...) printf(__VA_ARGS__)
#define CL_LOADER_LOGE(...) printf(__VA_ARGS__)
#endif
#if defined(_WIN32) || defined(_WIN64)
#define WIN32_LEAN_AND_MEAN
#define WIN64_LEAN_AND_MEAN
#define VC_EXTRALEAN
#include <windows.h>
#define strdup _strdup
typedef HMODULE CL_LOADER_DYNLIB_HANDLE;
#define CL_LOADER_DLOPEN LoadLibraryA
#define CL_LOADER_CLCLOSE FreeLibrary
#define CL_LOADER_DLSYM GetProcAddress
#else
#include <dlfcn.h>
typedef void* CL_LOADER_DYNLIB_HANDLE;
#define CL_LOADER_DLOPEN(LIB) dlopen(LIB, RTLD_LAZY)
#define CL_LOADER_CLCLOSE dlclose
#define CL_LOADER_DLSYM dlsym
#endif
static CL_LOADER_DYNLIB_HANDLE handle = nullptr;
#define REINTERPRET_CAST_FUNC(fn) \
fn = reinterpret_cast<fn##_func>(CL_LOADER_DLSYM(libraryHandle, #fn));
namespace OpenCLHelper {
namespace {
/* Declare local function stubs to be casted to the opencl functions at runtime
*/
using clBuildProgram_func = cl_int (*)(cl_program,
cl_uint,
const cl_device_id*,
const char*,
void (*pfn_notify)(cl_program, void*),
void*);
using clEnqueueNDRangeKernel_func = cl_int (*)(cl_command_queue,
cl_kernel,
cl_uint,
const size_t*,
const size_t*,
const size_t*,
cl_uint,
const cl_event*,
cl_event*);
using clSetKernelArg_func = cl_int (*)(cl_kernel, cl_uint, size_t, const void*);
using clReleaseMemObject_func = cl_int (*)(cl_mem);
using clEnqueueUnmapMemObject_func = cl_int (*)(cl_command_queue,
cl_mem,
void*,
cl_uint,
const cl_event*,
cl_event*);
using clRetainCommandQueue_func = cl_int (*)(cl_command_queue command_queue);
using clReleaseContext_func = cl_int (*)(cl_context);
using clReleaseEvent_func = cl_int (*)(cl_event);
using clEnqueueWriteBuffer_func = cl_int (*)(cl_command_queue,
cl_mem,
cl_bool,
size_t,
size_t,
const void*,
cl_uint,
const cl_event*,
cl_event*);
using clEnqueueReadBuffer_func = cl_int (*)(cl_command_queue,
cl_mem,
cl_bool,
size_t,
size_t,
void*,
cl_uint,
const cl_event*,
cl_event*);
using clGetProgramBuildInfo_func = cl_int (*)(cl_program,
cl_device_id,
cl_program_build_info,
size_t,
void*,
size_t*);
using clRetainProgram_func = cl_int (*)(cl_program program);
using clEnqueueMapBuffer_func = void* (*) (cl_command_queue,
cl_mem,
cl_bool,
cl_map_flags,
size_t,
size_t,
cl_uint,
const cl_event*,
cl_event*,
cl_int*);
using clReleaseCommandQueue_func = cl_int (*)(cl_command_queue);
using clCreateProgramWithBinary_func = cl_program (*)(cl_context,
cl_uint,
const cl_device_id*,
const size_t*,
const unsigned char**,
cl_int*,
cl_int*);
using clRetainContext_func = cl_int (*)(cl_context context);
using clReleaseProgram_func = cl_int (*)(cl_program program);
using clFlush_func = cl_int (*)(cl_command_queue command_queue);
using clGetProgramInfo_func =
cl_int (*)(cl_program, cl_program_info, size_t, void*, size_t*);
using clGetSupportedImageFormats_func = cl_int (*)(cl_context context,
cl_mem_flags,
cl_mem_object_type,
cl_uint,
cl_image_format*,
cl_uint*);
using clCreateKernel_func = cl_kernel (*)(cl_program, const char*, cl_int*);
using clRetainKernel_func = cl_int (*)(cl_kernel kernel);
using clCreateBuffer_func =
cl_mem (*)(cl_context, cl_mem_flags, size_t, void*, cl_int*);
using clCreateProgramWithSource_func =
cl_program (*)(cl_context, cl_uint, const char**, const size_t*, cl_int*);
using clReleaseKernel_func = cl_int (*)(cl_kernel);
using clCreateCommandQueue_func =
cl_command_queue (*)(cl_context,
cl_device_id,
cl_command_queue_properties,
cl_int*);
using clCreateContextFromType_func = cl_context (*)(
const cl_context_properties*,
cl_device_type,
void(CL_CALLBACK* /* pfn_notify*/)(const char*, const void*, size_t, void*),
void*,
cl_int*);
using clGetContextInfo_func =
cl_int (*)(cl_context, cl_context_info, size_t, void*, size_t*);
using clGetDeviceInfo_func =
cl_int (*)(cl_device_id, cl_device_info, size_t, void*, size_t*);
using clGetPlatformIDs_func = cl_int (*)(cl_uint, cl_platform_id*, cl_uint*);
using clGetPlatformInfo_func =
cl_int (*)(cl_platform_id, cl_platform_info, size_t, void*, size_t*);
using clRetainDevice_func = cl_int (*)(cl_device_id);
using clReleaseDevice_func = cl_int (*)(cl_device_id);
using clCreateContext_func =
cl_context (*)(const cl_context_properties*,
cl_uint,
const cl_device_id*,
void(CL_CALLBACK*)(const char*, const void*, size_t, void*),
void*,
cl_int*);
using clFinish_func = cl_int (*)(cl_command_queue);
using clGetDeviceIDs_func = cl_int (*)(cl_platform_id,
cl_device_type,
cl_uint,
cl_device_id*,
cl_uint*);
using clEnqueueFillBuffer_func = cl_int (*)(cl_command_queue,
cl_mem,
const void*,
size_t,
size_t,
size_t,
cl_uint,
const cl_event*,
cl_event*);
using clCreateImage_func = cl_mem (*)(cl_context,
cl_mem_flags,
const cl_image_format*,
const cl_image_desc*,
void*,
cl_int*);
using clEnqueueReadImage_func =
cl_int (*)(cl_command_queue /* command_queue */,
cl_mem /* image */,
cl_bool /* blocking_read */,
const size_t* /* origin[3] */,
const size_t* /* region[3] */,
size_t /* row_pitch */,
size_t /* slice_pitch */,
void* /* ptr */,
cl_uint /* num_events_in_wait_list */,
const cl_event* /* event_wait_list */,
cl_event* /* event */);
using clEnqueueWriteImage_func =
cl_int (*)(cl_command_queue /* command_queue */,
cl_mem /* image */,
cl_bool /* blocking_write */,
const size_t* /* origin[3] */,
const size_t* /* region[3] */,
size_t /* input_row_pitch */,
size_t /* input_slice_pitch */,
const void* /* ptr */,
cl_uint /* num_events_in_wait_list */,
const cl_event* /* event_wait_list */,
cl_event* /* event */);
using clEnqueueMapImage_func = void* (*) (cl_command_queue,
cl_mem,
cl_bool,
cl_map_flags,
const size_t*,
const size_t*,
size_t*,
size_t*,
cl_uint,
const cl_event*,
cl_event*,
cl_int*);
using clGetKernelWorkGroupInfo_func = cl_int (*)(cl_kernel,
cl_device_id,
cl_kernel_work_group_info,
size_t,
void*,
size_t*);
using clWaitForEvents_func = cl_int (*)(cl_uint, const cl_event*);
using clGetEventProfilingInfo_func =
cl_int (*)(cl_event, cl_profiling_info, size_t, void*, size_t*);
using clCreateImage2D_func = cl_mem (*)(cl_context,
cl_mem_flags,
const cl_image_format*,
size_t,
size_t,
size_t,
void*,
cl_int*);
using clRetainMemObject_func = cl_int (*)(cl_mem);
using clRetainEvent_func = cl_int (*)(cl_event);
class CLSymbols
{
public:
static std::shared_ptr<CLSymbols> symbolsInstance;
static CLSymbols& Get()
{
if (!CLSymbols::symbolsInstance) {
CLSymbols::symbolsInstance =
std::shared_ptr<CLSymbols>(new CLSymbols(handle));
}
return *CLSymbols::symbolsInstance;
}
static void Reset()
{
CLSymbols::symbolsInstance = nullptr;
}
clBuildProgram_func clBuildProgram = nullptr;
clEnqueueNDRangeKernel_func clEnqueueNDRangeKernel = nullptr;
clSetKernelArg_func clSetKernelArg = nullptr;
clReleaseKernel_func clReleaseKernel = nullptr;
clCreateProgramWithSource_func clCreateProgramWithSource = nullptr;
clCreateBuffer_func clCreateBuffer = nullptr;
clRetainKernel_func clRetainKernel = nullptr;
clCreateKernel_func clCreateKernel = nullptr;
clGetProgramInfo_func clGetProgramInfo = nullptr;
clFlush_func clFlush = nullptr;
clReleaseProgram_func clReleaseProgram = nullptr;
clRetainContext_func clRetainContext = nullptr;
clCreateProgramWithBinary_func clCreateProgramWithBinary = nullptr;
clReleaseCommandQueue_func clReleaseCommandQueue = nullptr;
clEnqueueMapBuffer_func clEnqueueMapBuffer = nullptr;
clRetainProgram_func clRetainProgram = nullptr;
clGetProgramBuildInfo_func clGetProgramBuildInfo = nullptr;
clEnqueueReadBuffer_func clEnqueueReadBuffer = nullptr;
clEnqueueWriteBuffer_func clEnqueueWriteBuffer = nullptr;
clReleaseEvent_func clReleaseEvent = nullptr;
clReleaseContext_func clReleaseContext = nullptr;
clRetainCommandQueue_func clRetainCommandQueue = nullptr;
clEnqueueUnmapMemObject_func clEnqueueUnmapMemObject = nullptr;
clReleaseMemObject_func clReleaseMemObject = nullptr;
clCreateCommandQueue_func clCreateCommandQueue = nullptr;
clCreateContextFromType_func clCreateContextFromType = nullptr;
clGetContextInfo_func clGetContextInfo = nullptr;
clGetDeviceInfo_func clGetDeviceInfo = nullptr;
clGetSupportedImageFormats_func clGetSupportedImageFormats = nullptr;
clGetPlatformIDs_func clGetPlatformIDs = nullptr;
clGetPlatformInfo_func clGetPlatformInfo = nullptr;
clRetainDevice_func clRetainDevice = nullptr;
clReleaseDevice_func clReleaseDevice = nullptr;
clCreateContext_func clCreateContext = nullptr;
clFinish_func clFinish = nullptr;
clGetDeviceIDs_func clGetDeviceIDs = nullptr;
clEnqueueFillBuffer_func clEnqueueFillBuffer = nullptr;
clCreateImage_func clCreateImage = nullptr;
clEnqueueReadImage_func clEnqueueReadImage = nullptr;
clEnqueueWriteImage_func clEnqueueWriteImage = nullptr;
clEnqueueMapImage_func clEnqueueMapImage = nullptr;
clGetKernelWorkGroupInfo_func clGetKernelWorkGroupInfo = nullptr;
clWaitForEvents_func clWaitForEvents = nullptr;
clGetEventProfilingInfo_func clGetEventProfilingInfo = nullptr;
clCreateImage2D_func clCreateImage2D = nullptr;
clRetainMemObject_func clRetainMemObject = nullptr;
clRetainEvent_func clRetainEvent = nullptr;
private:
CLSymbols(CL_LOADER_DYNLIB_HANDLE libraryHandle)
{
if (libraryHandle == nullptr) {
#if defined(_WIN32)
std::cerr
<< "OpenCL function invoked without call to CLLoader::Init()"
<< std::endl;
#else
std::cerr
<< "OpenCL function invoked without call to CLLoader::Init() "
<< dlerror() << std::endl;
#endif
return;
}
// TODO: We can also load these lazily, but then it might hide runtime
// issues
//
REINTERPRET_CAST_FUNC(clBuildProgram);
REINTERPRET_CAST_FUNC(clEnqueueNDRangeKernel)
REINTERPRET_CAST_FUNC(clSetKernelArg);
REINTERPRET_CAST_FUNC(clReleaseKernel)
REINTERPRET_CAST_FUNC(clCreateProgramWithSource);
REINTERPRET_CAST_FUNC(clCreateBuffer);
REINTERPRET_CAST_FUNC(clRetainKernel);
REINTERPRET_CAST_FUNC(clCreateKernel);
REINTERPRET_CAST_FUNC(clGetProgramInfo);
REINTERPRET_CAST_FUNC(clFlush);
REINTERPRET_CAST_FUNC(clReleaseProgram);
REINTERPRET_CAST_FUNC(clRetainContext);
REINTERPRET_CAST_FUNC(clCreateProgramWithBinary);
REINTERPRET_CAST_FUNC(clReleaseCommandQueue);
REINTERPRET_CAST_FUNC(clEnqueueMapBuffer);
REINTERPRET_CAST_FUNC(clRetainProgram);
REINTERPRET_CAST_FUNC(clGetProgramBuildInfo);
REINTERPRET_CAST_FUNC(clEnqueueReadBuffer);
REINTERPRET_CAST_FUNC(clEnqueueWriteBuffer);
REINTERPRET_CAST_FUNC(clReleaseEvent);
REINTERPRET_CAST_FUNC(clRetainCommandQueue);
REINTERPRET_CAST_FUNC(clEnqueueUnmapMemObject);
REINTERPRET_CAST_FUNC(clReleaseMemObject);
REINTERPRET_CAST_FUNC(clCreateCommandQueue);
REINTERPRET_CAST_FUNC(clCreateContextFromType);
REINTERPRET_CAST_FUNC(clGetContextInfo);
REINTERPRET_CAST_FUNC(clGetSupportedImageFormats);
REINTERPRET_CAST_FUNC(clGetDeviceInfo);
REINTERPRET_CAST_FUNC(clGetPlatformIDs);
REINTERPRET_CAST_FUNC(clGetPlatformInfo);
REINTERPRET_CAST_FUNC(clRetainDevice);
REINTERPRET_CAST_FUNC(clReleaseDevice);
REINTERPRET_CAST_FUNC(clCreateContext);
REINTERPRET_CAST_FUNC(clFinish);
REINTERPRET_CAST_FUNC(clGetDeviceIDs);
REINTERPRET_CAST_FUNC(clCreateImage);
REINTERPRET_CAST_FUNC(clEnqueueReadImage);
REINTERPRET_CAST_FUNC(clEnqueueWriteImage);
REINTERPRET_CAST_FUNC(clEnqueueMapImage);
REINTERPRET_CAST_FUNC(clGetKernelWorkGroupInfo);
REINTERPRET_CAST_FUNC(clWaitForEvents);
REINTERPRET_CAST_FUNC(clGetEventProfilingInfo);
REINTERPRET_CAST_FUNC(clCreateImage2D);
REINTERPRET_CAST_FUNC(clRetainMemObject);
REINTERPRET_CAST_FUNC(clRetainEvent);
}
};
std::shared_ptr<CLSymbols> CLSymbols::symbolsInstance(nullptr);
} // namespace
class Impl
{
public:
static Impl& Instance()
{
static Impl impl;
return impl;
}
void Exit()
{
if (handle) {
CL_LOADER_CLCLOSE(handle);
handle = nullptr;
}
CLSymbols::Reset();
}
const std::string& GetLibPath()
{
return openedLib;
}
int Init()
{
#if defined(_WIN32)
const char* openclLibPath[] = {"C:\\Windows\\System32\\OpenCL.dll",
"OpenCL.dll"};
const int numOpenclLibPath = 2;
#elif defined(_WIN64)
const char* openclLibPath[] = {"C:\\Windows\\SysWOW64\\OpenCL.dll",
"OpenCL.dll"};
const int numOpenclLibPath = 2;
#elif defined(__APPLE__)
const char* openclLibPath[] = {
"/System/Library/Frameworks/OpenCL.framework/OpenCL"
"/Library/Frameworks/OpenCL.framework/OpenCL"};
const int numOpenclLibPath = 2;
#elif defined(__ANDROID_API__)
const char* openclLibPath[] = {
// Typical libOpenCL location
"/system/lib/libOpenCL.so",
"/system/lib/egl/libOpenCL.so",
"/system/vendor/lib/libOpenCL.so",
"/system/vendor/lib/egl/libOpenCL.so",
"/system/lib64/libOpenCL.so",
"/system/lib64/egl/libOpenCL.so",
"/system/vendor/lib64/libOpenCL.so",
"/system/vendor/lib64/egl/libOpenCL.so",
// Qualcomm Adreno A3xx
"/system/lib/libllvm-a3xx.so",
// ARM Mali series
"/system/lib/libGLES_mali.so",
"/system/lib/egl/libGLES_mali.so",
"/system/vendor/lib/libGLES_mali.so",
"/system/vendor/lib/egl/libGLES_mali.so",
"/system/lib64/libGLES_mali.so",
"/system/lib64/egl/libGLES_mali.so",
"/system/vendor/lib64/libGLES_mali.so",
"/system/vendor/lib64/egl/libGLES_mali.so",
// Imagination PowerVR Series
"/system/lib/libPVROCL.so",
"/system/lib/egl/libPVROCL.so",
"/system/vendor/lib/libPVROCL.so",
"/system/vendor/lib/egl/libPVROCL.so",
"/system/lib64/libPVROCL.so",
"/system/lib64/egl/libPVROCL.so",
"/system/vendor/lib64/libPVROCL.so",
"/system/vendor/lib64/egl/libPVROCL.so",
// Last try
"libOpenCL.so",
"libGLES_mali.so",
"libPVROCL.so"};
const int numOpenclLibPath = 28;
#else
const char* openclLibPath[] = {"libOpenCL.so"};
const int numOpenclLibPath = 1;
#endif
for (int i = 0; i < numOpenclLibPath; i++) {
if ((handle = CL_LOADER_DLOPEN(openclLibPath[i]))) {
CL_LOADER_LOGD("Index %d, using the Shared library:%s\n",
i,
openclLibPath[i]);
openedLib = openclLibPath[i];
CL_LOADER_LOGD("Loaded OpenCL library:%s\n", openedLib.c_str());
break;
}
}
if (handle == NULL) {
return CL_LOADER_FAILED_LOCATE_LIB_OPENCL;
}
// Check if all the symbols are loaded successfully.
if (CLSymbols::Get().clBuildProgram == nullptr ||
CLSymbols::Get().clEnqueueNDRangeKernel == nullptr ||
CLSymbols::Get().clSetKernelArg == nullptr ||
CLSymbols::Get().clReleaseKernel == nullptr ||
CLSymbols::Get().clCreateProgramWithSource == nullptr ||
CLSymbols::Get().clCreateBuffer == nullptr ||
CLSymbols::Get().clRetainKernel == nullptr ||
CLSymbols::Get().clCreateKernel == nullptr ||
CLSymbols::Get().clGetProgramInfo == nullptr ||
CLSymbols::Get().clFlush == nullptr ||
CLSymbols::Get().clReleaseProgram == nullptr ||
CLSymbols::Get().clRetainContext == nullptr ||
CLSymbols::Get().clCreateProgramWithBinary == nullptr ||
CLSymbols::Get().clReleaseCommandQueue == nullptr ||
CLSymbols::Get().clEnqueueMapBuffer == nullptr ||
CLSymbols::Get().clRetainProgram == nullptr ||
CLSymbols::Get().clGetProgramBuildInfo == nullptr ||
CLSymbols::Get().clEnqueueReadBuffer == nullptr ||
CLSymbols::Get().clEnqueueWriteBuffer == nullptr ||
CLSymbols::Get().clReleaseEvent == nullptr ||
CLSymbols::Get().clRetainCommandQueue == nullptr ||
CLSymbols::Get().clEnqueueUnmapMemObject == nullptr ||
CLSymbols::Get().clReleaseMemObject == nullptr ||
CLSymbols::Get().clCreateCommandQueue == nullptr ||
CLSymbols::Get().clCreateContextFromType == nullptr ||
CLSymbols::Get().clGetContextInfo == nullptr ||
CLSymbols::Get().clGetDeviceInfo == nullptr ||
CLSymbols::Get().clGetPlatformIDs == nullptr ||
CLSymbols::Get().clGetPlatformInfo == nullptr ||
CLSymbols::Get().clRetainDevice == nullptr ||
CLSymbols::Get().clReleaseDevice == nullptr ||
CLSymbols::Get().clCreateContext == nullptr ||
CLSymbols::Get().clFinish == nullptr ||
CLSymbols::Get().clGetDeviceIDs == nullptr ||
CLSymbols::Get().clCreateImage == nullptr ||
CLSymbols::Get().clEnqueueMapImage == nullptr ||
CLSymbols::Get().clGetKernelWorkGroupInfo == nullptr ||
CLSymbols::Get().clWaitForEvents == nullptr ||
CLSymbols::Get().clGetEventProfilingInfo == nullptr ||
CLSymbols::Get().clCreateImage2D == nullptr ||
CLSymbols::Get().clRetainMemObject == nullptr ||
CLSymbols::Get().clRetainEvent == nullptr ||
CLSymbols::Get().clEnqueueReadImage == nullptr ||
CLSymbols::Get().clEnqueueWriteImage == nullptr ||
CLSymbols::Get().clGetSupportedImageFormats == nullptr) {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
return CL_LOADER_SUCCESS;
}
private:
Impl() : openedLib("Unknown location")
{
}
private:
std::string openedLib;
};
int Loader::Init()
{
return Impl::Instance().Init();
}
const std::string& Loader::GetLibPath()
{
return Impl::Instance().GetLibPath();
}
void Loader::Exit()
{
return Impl::Instance().Exit();
}
} // namespace OpenCLHelper
using CLSymbols = OpenCLHelper::CLSymbols;
CL_LOADER_EXPORT cl_int clBuildProgram(
cl_program program,
cl_uint num_devices,
const cl_device_id* device_list,
const char* options,
void(CL_CALLBACK* pfn_notify)(cl_program program, void* user_data),
void* user_data)
{
auto func = CLSymbols::Get().clBuildProgram;
if (func != nullptr) {
return func(
program, num_devices, device_list, options, pfn_notify, user_data);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clEnqueueNDRangeKernel(cl_command_queue command_queue,
cl_kernel kernel,
cl_uint work_dim,
const size_t* global_work_offset,
const size_t* global_work_size,
const size_t* local_work_size,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event)
{
auto func = CLSymbols::Get().clEnqueueNDRangeKernel;
if (func != nullptr) {
return func(command_queue,
kernel,
work_dim,
global_work_offset,
global_work_size,
local_work_size,
num_events_in_wait_list,
event_wait_list,
event);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clSetKernelArg(cl_kernel kernel,
cl_uint arg_index,
size_t arg_size,
const void* arg_value)
{
auto func = CLSymbols::Get().clSetKernelArg;
if (func != nullptr) {
return func(kernel, arg_index, arg_size, arg_value);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clReleaseMemObject(cl_mem memobj)
{
auto func = CLSymbols::Get().clReleaseMemObject;
if (func != nullptr) {
return func(memobj);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clEnqueueUnmapMemObject(cl_command_queue command_queue,
cl_mem memobj,
void* mapped_ptr,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event)
{
auto func = CLSymbols::Get().clEnqueueUnmapMemObject;
if (func != nullptr) {
return func(command_queue,
memobj,
mapped_ptr,
num_events_in_wait_list,
event_wait_list,
event);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clRetainCommandQueue(cl_command_queue command_queue)
{
auto func = CLSymbols::Get().clRetainCommandQueue;
if (func != nullptr) {
return func(command_queue);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clReleaseContext(cl_context context)
{
auto func = CLSymbols::Get().clReleaseContext;
if (func != nullptr) {
return func(context);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clReleaseEvent(cl_event event)
{
auto func = CLSymbols::Get().clReleaseEvent;
if (func != nullptr) {
return func(event);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clEnqueueWriteBuffer(cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_write,
size_t offset,
size_t size,
const void* ptr,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event)
{
auto func = CLSymbols::Get().clEnqueueWriteBuffer;
if (func != nullptr) {
return func(command_queue,
buffer,
blocking_write,
offset,
size,
ptr,
num_events_in_wait_list,
event_wait_list,
event);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clEnqueueReadBuffer(cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_read,
size_t offset,
size_t size,
void* ptr,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event)
{
auto func = CLSymbols::Get().clEnqueueReadBuffer;
if (func != nullptr) {
return func(command_queue,
buffer,
blocking_read,
offset,
size,
ptr,
num_events_in_wait_list,
event_wait_list,
event);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clGetProgramBuildInfo(cl_program program,
cl_device_id device,
cl_program_build_info param_name,
size_t param_value_size,
void* param_value,
size_t* param_value_size_ret)
{
auto func = CLSymbols::Get().clGetProgramBuildInfo;
if (func != nullptr) {
return func(program,
device,
param_name,
param_value_size,
param_value,
param_value_size_ret);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clRetainProgram(cl_program program)
{
auto func = CLSymbols::Get().clRetainProgram;
if (func != nullptr) {
return func(program);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
void* clEnqueueMapBuffer(cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_map,
cl_map_flags map_flags,
size_t offset,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event,
cl_int* errcode_ret)
{
auto func = CLSymbols::Get().clEnqueueMapBuffer;
if (func != nullptr) {
return func(command_queue,
buffer,
blocking_map,
map_flags,
offset,
size,
num_events_in_wait_list,
event_wait_list,
event,
errcode_ret);
} else {
if (errcode_ret != nullptr) {
*errcode_ret = CL_LOADER_FAILED_MAP_SYMBOL;
}
return nullptr;
}
}
CL_LOADER_EXPORT cl_int clReleaseCommandQueue(cl_command_queue command_queue)
{
auto func = CLSymbols::Get().clReleaseCommandQueue;
if (func != nullptr) {
return func(command_queue);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_program
clCreateProgramWithBinary(cl_context context,
cl_uint num_devices,
const cl_device_id* device_list,
const size_t* lengths,
const unsigned char** binaries,
cl_int* binary_status,
cl_int* errcode_ret)
{
auto func = CLSymbols::Get().clCreateProgramWithBinary;
if (func != nullptr) {
return func(context,
num_devices,
device_list,
lengths,
binaries,
binary_status,
errcode_ret);
} else {
if (errcode_ret != nullptr) {
*errcode_ret = CL_LOADER_FAILED_MAP_SYMBOL;
}
return nullptr;
}
}
CL_LOADER_EXPORT cl_int clRetainContext(cl_context context)
{
auto func = CLSymbols::Get().clRetainContext;
if (func != nullptr) {
return func(context);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clReleaseProgram(cl_program program)
{
auto func = CLSymbols::Get().clReleaseProgram;
if (func != nullptr) {
return func(program);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clFlush(cl_command_queue command_queue)
{
auto func = CLSymbols::Get().clFlush;
if (func != nullptr) {
return func(command_queue);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clGetProgramInfo(cl_program program,
cl_program_info param_name,
size_t param_value_size,
void* param_value,
size_t* param_value_size_ret)
{
auto func = CLSymbols::Get().clGetProgramInfo;
if (func != nullptr) {
return func(program,
param_name,
param_value_size,
param_value,
param_value_size_ret);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_kernel clCreateKernel(cl_program program,
const char* kernel_name,
cl_int* errcode_ret)
{
auto func = CLSymbols::Get().clCreateKernel;
if (func != nullptr) {
return func(program, kernel_name, errcode_ret);
} else {
if (errcode_ret != nullptr) {
*errcode_ret = CL_LOADER_FAILED_MAP_SYMBOL;
}
return nullptr;
}
}
CL_LOADER_EXPORT cl_int clRetainKernel(cl_kernel kernel)
{
auto func = CLSymbols::Get().clRetainKernel;
if (func != nullptr) {
return func(kernel);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_mem clCreateBuffer(cl_context context,
cl_mem_flags flags,
size_t size,
void* host_ptr,
cl_int* errcode_ret)
{
auto func = CLSymbols::Get().clCreateBuffer;
if (func != nullptr) {
return func(context, flags, size, host_ptr, errcode_ret);
} else {
if (errcode_ret != nullptr) {
*errcode_ret = CL_LOADER_FAILED_MAP_SYMBOL;
}
return nullptr;
}
}
CL_LOADER_EXPORT cl_program clCreateProgramWithSource(cl_context context,
cl_uint count,
const char** strings,
const size_t* lengths,
cl_int* errcode_ret)
{
auto func = CLSymbols::Get().clCreateProgramWithSource;
if (func != nullptr) {
return func(context, count, strings, lengths, errcode_ret);
} else {
if (errcode_ret != nullptr) {
*errcode_ret = CL_LOADER_FAILED_MAP_SYMBOL;
}
return nullptr;
}
}
CL_LOADER_EXPORT cl_int clReleaseKernel(cl_kernel kernel)
{
auto func = CLSymbols::Get().clReleaseKernel;
if (func != nullptr) {
return func(kernel);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_command_queue
clCreateCommandQueue(cl_context context,
cl_device_id device,
cl_command_queue_properties properties,
cl_int* errcode_ret)
{
auto func = CLSymbols::Get().clCreateCommandQueue;
if (func != nullptr) {
return func(context, device, properties, errcode_ret);
} else {
if (errcode_ret != nullptr) {
*errcode_ret = CL_LOADER_FAILED_MAP_SYMBOL;
}
return nullptr;
}
}
CL_LOADER_EXPORT cl_context clCreateContextFromType(
const cl_context_properties* properties,
cl_device_type device_type,
void(CL_CALLBACK* pfn_notify)(const char*, const void*, size_t, void*),
void* user_data,
cl_int* errcode_ret)
{
auto func = CLSymbols::Get().clCreateContextFromType;
if (func != nullptr) {
return func(
properties, device_type, pfn_notify, user_data, errcode_ret);
} else {
if (errcode_ret != nullptr) {
*errcode_ret = CL_LOADER_FAILED_MAP_SYMBOL;
}
return nullptr;
}
}
CL_LOADER_EXPORT cl_int clGetContextInfo(cl_context context,
cl_context_info param_name,
size_t param_value_size,
void* param_value,
size_t* param_value_size_ret)
{
auto func = CLSymbols::Get().clGetContextInfo;
if (func != nullptr) {
return func(context,
param_name,
param_value_size,
param_value,
param_value_size_ret);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int
clGetSupportedImageFormats(cl_context context,
cl_mem_flags flags,
cl_mem_object_type image_type,
cl_uint num_entries,
cl_image_format* image_formats,
cl_uint* num_image_formats)
{
auto func = CLSymbols::Get().clGetSupportedImageFormats;
if (func != nullptr) {
return func(context,
flags,
image_type,
num_entries,
image_formats,
num_image_formats);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clGetDeviceInfo(cl_device_id device,
cl_device_info param_name,
size_t param_value_size,
void* param_value,
size_t* param_value_size_ret)
{
auto func = CLSymbols::Get().clGetDeviceInfo;
if (func != nullptr) {
return func(device,
param_name,
param_value_size,
param_value,
param_value_size_ret);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clGetPlatformIDs(cl_uint num_entries,
cl_platform_id* platforms,
cl_uint* num_platforms)
{
auto func = CLSymbols::Get().clGetPlatformIDs;
if (func != nullptr) {
return func(num_entries, platforms, num_platforms);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clGetPlatformInfo(cl_platform_id platform,
cl_platform_info param_name,
size_t param_value_size,
void* param_value,
size_t* param_value_size_ret)
{
auto func = CLSymbols::Get().clGetPlatformInfo;
if (func != nullptr) {
return func(platform,
param_name,
param_value_size,
param_value,
param_value_size_ret);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clRetainDevice(cl_device_id device)
{
auto func = CLSymbols::Get().clRetainDevice;
if (func != nullptr) {
return func(device);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clReleaseDevice(cl_device_id device)
{
auto func = CLSymbols::Get().clReleaseDevice;
if (func != nullptr) {
return func(device);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_context clCreateContext(
const cl_context_properties* properties,
cl_uint num_devices,
const cl_device_id* devices,
void(CL_CALLBACK* pfn_notify)(const char*, const void*, size_t, void*),
void* user_data,
cl_int* errcode_ret)
{
auto func = CLSymbols::Get().clCreateContext;
if (func != nullptr) {
return func(properties,
num_devices,
devices,
pfn_notify,
user_data,
errcode_ret);
} else {
if (errcode_ret != nullptr) {
*errcode_ret = CL_LOADER_FAILED_MAP_SYMBOL;
}
return nullptr;
}
}
CL_LOADER_EXPORT cl_int clFinish(cl_command_queue command_queue)
{
auto func = CLSymbols::Get().clFinish;
if (func != nullptr) {
return func(command_queue);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clGetDeviceIDs(cl_platform_id platform,
cl_device_type device_type,
cl_uint num_entries,
cl_device_id* devices,
cl_uint* num_devices)
{
auto func = CLSymbols::Get().clGetDeviceIDs;
if (func != nullptr) {
return func(platform, device_type, num_entries, devices, num_devices);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clEnqueueFillBuffer(cl_command_queue command_queue,
cl_mem buffer,
const void* pattern,
size_t pattern_size,
size_t offset,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event)
{
auto func = CLSymbols::Get().clEnqueueFillBuffer;
if (func != nullptr) {
return func(command_queue,
buffer,
pattern,
pattern_size,
offset,
size,
num_events_in_wait_list,
event_wait_list,
event);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_mem clCreateImage(cl_context context,
cl_mem_flags flags,
const cl_image_format* image_format,
const cl_image_desc* image_desc,
void* host_ptr,
cl_int* errcode_ret)
{
auto func = CLSymbols::Get().clCreateImage;
if (func != nullptr) {
return func(
context, flags, image_format, image_desc, host_ptr, errcode_ret);
} else {
if (errcode_ret != nullptr) {
*errcode_ret = CL_LOADER_FAILED_MAP_SYMBOL;
}
return nullptr;
}
}
void* clEnqueueMapImage(cl_command_queue command_queue,
cl_mem image,
cl_bool blocking_map,
cl_map_flags map_flags,
const size_t* origin,
const size_t* region,
size_t* image_row_pitch,
size_t* image_slice_pitch,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event,
cl_int* errcode_ret)
{
auto func = CLSymbols::Get().clEnqueueMapImage;
if (func != nullptr) {
return func(command_queue,
image,
blocking_map,
map_flags,
origin,
region,
image_row_pitch,
image_slice_pitch,
num_events_in_wait_list,
event_wait_list,
event,
errcode_ret);
} else {
if (errcode_ret != nullptr) {
*errcode_ret = CL_LOADER_FAILED_MAP_SYMBOL;
}
return nullptr;
}
}
CL_LOADER_EXPORT cl_int clEnqueueReadImage(cl_command_queue command_queue,
cl_mem image,
cl_bool blocking_map,
const size_t* origin,
const size_t* region,
size_t image_row_pitch,
size_t image_slice_pitch,
void* ptr,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event)
{
auto func = CLSymbols::Get().clEnqueueReadImage;
if (func != nullptr) {
return func(command_queue,
image,
blocking_map,
origin,
region,
image_row_pitch,
image_slice_pitch,
ptr,
num_events_in_wait_list,
event_wait_list,
event);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clEnqueueWriteImage(cl_command_queue command_queue,
cl_mem image,
cl_bool blocking_map,
const size_t* origin,
const size_t* region,
size_t image_row_pitch,
size_t image_slice_pitch,
const void* ptr,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event)
{
auto func = CLSymbols::Get().clEnqueueWriteImage;
if (func != nullptr) {
return func(command_queue,
image,
blocking_map,
origin,
region,
image_row_pitch,
image_slice_pitch,
ptr,
num_events_in_wait_list,
event_wait_list,
event);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int
clGetKernelWorkGroupInfo(cl_kernel kernel,
cl_device_id device,
cl_kernel_work_group_info param_name,
size_t param_value_size,
void* param_value,
size_t* param_value_size_ret)
{
auto func = CLSymbols::Get().clGetKernelWorkGroupInfo;
if (func != nullptr) {
return func(kernel,
device,
param_name,
param_value_size,
param_value,
param_value_size_ret);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clWaitForEvents(cl_uint num_events,
const cl_event* event_list)
{
auto func = CLSymbols::Get().clWaitForEvents;
if (func != nullptr) {
return func(num_events, event_list);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clGetEventProfilingInfo(cl_event event,
cl_profiling_info param_name,
size_t param_value_size,
void* param_value,
size_t* param_value_size_ret)
{
auto func = CLSymbols::Get().clGetEventProfilingInfo;
if (func != nullptr) {
return func(event,
param_name,
param_value_size,
param_value,
param_value_size_ret);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_mem clCreateImage2D(cl_context context,
cl_mem_flags flags,
const cl_image_format* format,
size_t width,
size_t height,
size_t row_pitch,
void* host_ptr,
cl_int* errcode_ret)
{
auto func = CLSymbols::Get().clCreateImage2D;
if (func != nullptr) {
return func(context,
flags,
format,
width,
height,
row_pitch,
host_ptr,
errcode_ret);
} else {
if (errcode_ret != nullptr) {
*errcode_ret = CL_LOADER_FAILED_MAP_SYMBOL;
}
return nullptr;
}
}
CL_LOADER_EXPORT cl_int clRetainMemObject(cl_mem mem)
{
auto func = CLSymbols::Get().clRetainMemObject;
if (func != nullptr) {
return func(mem);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
CL_LOADER_EXPORT cl_int clRetainEvent(cl_event event)
{
auto func = CLSymbols::Get().clRetainEvent;
if (func != nullptr) {
return func(event);
} else {
return CL_LOADER_FAILED_MAP_SYMBOL;
}
}
#endif
|