|
20 | 20 | return cast<pi_result>(reterr); \
|
21 | 21 | }
|
22 | 22 |
|
| 23 | +const char SupportedVersion[] = "1.1"; |
23 | 24 | // Want all the needed casts be explicit, do not define conversion operators.
|
24 | 25 | template <class To, class From> To cast(From value) {
|
25 | 26 | // TODO: see if more sanity checks are possible.
|
@@ -452,6 +453,7 @@ pi_result OCL(piEnqueueMemBufferMap)(
|
452 | 453 | return ret_err;
|
453 | 454 | }
|
454 | 455 |
|
| 456 | +/* |
455 | 457 | // TODO: Remove the 'OclPtr' extension used with the PI_APIs.
|
456 | 458 | // Forward calls to OpenCL RT.
|
457 | 459 | #define _PI_CL(pi_api, ocl_api) \
|
@@ -539,4 +541,105 @@ _PI_CL(piEnqueueMemBufferMap, OCL(piEnqueueMemBufferMap))
|
539 | 541 | _PI_CL(piEnqueueMemUnmap, clEnqueueUnmapMemObject)
|
540 | 542 |
|
541 | 543 | #undef _PI_CL
|
| 544 | +*/ |
| 545 | + |
| 546 | +pi_result piPluginInit(pi_plugin *PluginInit) { |
| 547 | + strcpy(PluginInit->PluginVersion, SupportedVersion); |
| 548 | + int CompareVersions = strcmp(PluginInit->PiVersion, SupportedVersion); |
| 549 | + if (CompareVersions < 0) { |
| 550 | + // PI interface supports lower version of PI. |
| 551 | + assert(false && "incompatible versions.!!\n"); |
| 552 | + return PI_INVALID_OPERATION; |
| 553 | + } else { |
| 554 | + // PI interface supports higher version or the same version. |
| 555 | + |
| 556 | +#define _PI_CL(pi_api, ocl_api) \ |
| 557 | + (PluginInit->PiFunctionTable).pi_api = (decltype(&::pi_api))(&ocl_api); |
| 558 | + |
| 559 | + // Platform |
| 560 | + _PI_CL(piPlatformsGet, OCL(piPlatformsGet)) |
| 561 | + _PI_CL(piPlatformGetInfo, clGetPlatformInfo) |
| 562 | + // Device |
| 563 | + _PI_CL(piDevicesGet, OCL(piDevicesGet)) |
| 564 | + _PI_CL(piDeviceGetInfo, clGetDeviceInfo) |
| 565 | + _PI_CL(piDevicePartition, clCreateSubDevices) |
| 566 | + _PI_CL(piDeviceRetain, clRetainDevice) |
| 567 | + _PI_CL(piDeviceRelease, clReleaseDevice) |
| 568 | + _PI_CL(piextDeviceSelectBinary, OCL(piextDeviceSelectBinary)) |
| 569 | + _PI_CL(piextGetDeviceFunctionPointer, OCL(piextGetDeviceFunctionPointer)) |
| 570 | + // Context |
| 571 | + _PI_CL(piContextCreate, OCL(piContextCreate)) |
| 572 | + _PI_CL(piContextGetInfo, clGetContextInfo) |
| 573 | + _PI_CL(piContextRetain, clRetainContext) |
| 574 | + _PI_CL(piContextRelease, clReleaseContext) |
| 575 | + // Queue |
| 576 | + _PI_CL(piQueueCreate, OCL(piQueueCreate)) |
| 577 | + _PI_CL(piQueueGetInfo, clGetCommandQueueInfo) |
| 578 | + _PI_CL(piQueueFinish, clFinish) |
| 579 | + _PI_CL(piQueueRetain, clRetainCommandQueue) |
| 580 | + _PI_CL(piQueueRelease, clReleaseCommandQueue) |
| 581 | + // Memory |
| 582 | + _PI_CL(piMemBufferCreate, OCL(piMemBufferCreate)) |
| 583 | + _PI_CL(piMemImageCreate, OCL(piMemImageCreate)) |
| 584 | + _PI_CL(piMemGetInfo, clGetMemObjectInfo) |
| 585 | + _PI_CL(piMemImageGetInfo, clGetImageInfo) |
| 586 | + _PI_CL(piMemRetain, clRetainMemObject) |
| 587 | + _PI_CL(piMemRelease, clReleaseMemObject) |
| 588 | + _PI_CL(piMemBufferPartition, OCL(piMemBufferPartition)) |
| 589 | + // Program |
| 590 | + _PI_CL(piProgramCreate, OCL(piProgramCreate)) |
| 591 | + _PI_CL(piclProgramCreateWithSource, OCL(piclProgramCreateWithSource)) |
| 592 | + _PI_CL(piclProgramCreateWithBinary, OCL(piclProgramCreateWithBinary)) |
| 593 | + _PI_CL(piProgramGetInfo, clGetProgramInfo) |
| 594 | + _PI_CL(piProgramCompile, clCompileProgram) |
| 595 | + _PI_CL(piProgramBuild, clBuildProgram) |
| 596 | + _PI_CL(piProgramLink, OCL(piProgramLink)) |
| 597 | + _PI_CL(piProgramGetBuildInfo, clGetProgramBuildInfo) |
| 598 | + _PI_CL(piProgramRetain, clRetainProgram) |
| 599 | + _PI_CL(piProgramRelease, clReleaseProgram) |
| 600 | + // Kernel |
| 601 | + _PI_CL(piKernelCreate, OCL(piKernelCreate)) |
| 602 | + _PI_CL(piKernelSetArg, clSetKernelArg) |
| 603 | + _PI_CL(piKernelGetInfo, clGetKernelInfo) |
| 604 | + _PI_CL(piKernelGetGroupInfo, clGetKernelWorkGroupInfo) |
| 605 | + _PI_CL(piKernelGetSubGroupInfo, clGetKernelSubGroupInfo) |
| 606 | + _PI_CL(piKernelRetain, clRetainKernel) |
| 607 | + _PI_CL(piKernelRelease, clReleaseKernel) |
| 608 | + // Event |
| 609 | + _PI_CL(piEventCreate, OCL(piEventCreate)) |
| 610 | + _PI_CL(piEventGetInfo, clGetEventInfo) |
| 611 | + _PI_CL(piEventGetProfilingInfo, clGetEventProfilingInfo) |
| 612 | + _PI_CL(piEventsWait, clWaitForEvents) |
| 613 | + _PI_CL(piEventSetCallback, clSetEventCallback) |
| 614 | + _PI_CL(piEventSetStatus, clSetUserEventStatus) |
| 615 | + _PI_CL(piEventRetain, clRetainEvent) |
| 616 | + _PI_CL(piEventRelease, clReleaseEvent) |
| 617 | + // Sampler |
| 618 | + _PI_CL(piSamplerCreate, OCL(piSamplerCreate)) |
| 619 | + _PI_CL(piSamplerGetInfo, clGetSamplerInfo) |
| 620 | + _PI_CL(piSamplerRetain, clRetainSampler) |
| 621 | + _PI_CL(piSamplerRelease, clReleaseSampler) |
| 622 | + // Queue commands |
| 623 | + _PI_CL(piEnqueueKernelLaunch, clEnqueueNDRangeKernel) |
| 624 | + _PI_CL(piEnqueueNativeKernel, clEnqueueNativeKernel) |
| 625 | + _PI_CL(piEnqueueEventsWait, clEnqueueMarkerWithWaitList) |
| 626 | + _PI_CL(piEnqueueMemBufferRead, clEnqueueReadBuffer) |
| 627 | + _PI_CL(piEnqueueMemBufferReadRect, clEnqueueReadBufferRect) |
| 628 | + _PI_CL(piEnqueueMemBufferWrite, clEnqueueWriteBuffer) |
| 629 | + _PI_CL(piEnqueueMemBufferWriteRect, clEnqueueWriteBufferRect) |
| 630 | + _PI_CL(piEnqueueMemBufferCopy, clEnqueueCopyBuffer) |
| 631 | + _PI_CL(piEnqueueMemBufferCopyRect, clEnqueueCopyBufferRect) |
| 632 | + _PI_CL(piEnqueueMemBufferFill, clEnqueueFillBuffer) |
| 633 | + _PI_CL(piEnqueueMemImageRead, clEnqueueReadImage) |
| 634 | + _PI_CL(piEnqueueMemImageWrite, clEnqueueWriteImage) |
| 635 | + _PI_CL(piEnqueueMemImageCopy, clEnqueueCopyImage) |
| 636 | + _PI_CL(piEnqueueMemImageFill, clEnqueueFillImage) |
| 637 | + _PI_CL(piEnqueueMemBufferMap, OCL(piEnqueueMemBufferMap)) |
| 638 | + _PI_CL(piEnqueueMemUnmap, clEnqueueUnmapMemObject) |
| 639 | + |
| 640 | +#undef _PI_CL |
| 641 | + } |
| 642 | + return PI_SUCCESS; |
542 | 643 | }
|
| 644 | + |
| 645 | +} // end extern 'C' |
0 commit comments