diff --git a/opencl/.clang-format b/opencl/.clang-format new file mode 100644 index 0000000000..5572a72cdd --- /dev/null +++ b/opencl/.clang-format @@ -0,0 +1,10 @@ +Language: Cpp +BasedOnStyle: Google +AlignEscapedNewlinesLeft: false +AlignOperands: false +ColumnLimit: 100 +AlwaysBreakTemplateDeclarations: false +DerivePointerAlignment: false +IndentFunctionDeclarationAfterType: false +MaxEmptyLinesToKeep: 2 +SortIncludes: false diff --git a/opencl/.gitattributes b/opencl/.gitattributes new file mode 100644 index 0000000000..0c5af14b55 --- /dev/null +++ b/opencl/.gitattributes @@ -0,0 +1,20 @@ +# Set the default behavior, in case people don't have core.autolf set. +* text=auto + +# Explicitly declare text files you want to always be normalized and converted +# to have LF line endings on checkout. +*.c text eol=lf +*.cpp text eol=lf +*.cc text eol=lf +*.h text eol=lf +*.hpp text eol=lf +*.txt text eol=lf + +# Define files to support auto-remove trailing white space +# Need to run the command below, before add modified file(s) to the staging area +# git config filter.trimspace.clean 'sed -e "s/[[:space:]]*$//g"' +*.cpp filter=trimspace +*.c filter=trimspace +*.h filter=trimspacecpp +*.hpp filter=trimspace +*.md filter=trimspace diff --git a/opencl/.gitignore b/opencl/.gitignore new file mode 100644 index 0000000000..eb4ded6295 --- /dev/null +++ b/opencl/.gitignore @@ -0,0 +1,14 @@ +.* +!.gitignore +*.d +*.o +*.obj +*.gch +*.pch +*.so +*.dll +*.a +*.lib +*.exe +*.out +build \ No newline at end of file diff --git a/opencl/CMakeLists.txt b/opencl/CMakeLists.txt new file mode 100644 index 0000000000..212880fff5 --- /dev/null +++ b/opencl/CMakeLists.txt @@ -0,0 +1,115 @@ +cmake_minimum_required(VERSION 3.5.1) + +if (POLICY CMP0048) + cmake_policy(SET CMP0048 NEW) + set(PROJ_VERSION VERSION 1.5.0) +endif() + +project(opencl) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +# Set default libdir to be "lib" for ROCm, distros will override this anyway: +set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "Library install directory") + +include(GNUInstallDirs) + +option(BUILD_TESTS "Enable building OpenCL tests" OFF) +option(BUILD_ICD "Enable building OpenCL ICD Loader" ON) +option(EMU_ENV "Enable building for emulation environment" OFF) +option(FILE_REORG_BACKWARD_COMPATIBILITY "Enable File Reorganization backward compatibility" ON) + + +set(OPENCL_ICD_LOADER_HEADERS_DIR "${CMAKE_CURRENT_LIST_DIR}/khronos/headers/opencl2.2" CACHE PATH "") +if(BUILD_ICD) + add_subdirectory(khronos/icd) +else() + find_package(OpenCL REQUIRED) +endif() +add_subdirectory(amdocl) +add_subdirectory(tools/clinfo) +add_subdirectory(tools/cltrace) +if(BUILD_TESTS) + add_subdirectory(tests/ocltst) +endif() + +###--- Packaging ------------------------------------------------------------### + +# DEV package +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/khronos/headers/opencl2.2/CL" + DESTINATION include + COMPONENT DEV + USE_SOURCE_PERMISSIONS + PATTERN cl_d3d10.h EXCLUDE + PATTERN cl_d3d11.h EXCLUDE + PATTERN cl_dx9_media_sharing.h EXCLUDE + PATTERN cl_egl.h EXCLUDE) + +############################# +# Packaging steps +############################# +if(NOT WIN32) +find_package(ROCM QUIET CONFIG PATHS /opt/rocm) +if(ROCM_FOUND) + include(ROCMSetupVersion) + rocm_setup_version( VERSION "2.0.0" ) +else() + set(PROJECT_VERSION "2.0.0") +endif() + +#set a name for icd file +set(OPENCL_AMD_ICD_FILE "amdocl64.icd") +if (DEFINED ROCM_PATCH_VERSION) + # set unique name for ICD file for each jenkins build + # Use ENV variable CPACK_RPM_PACKAGE_RELEASE, which is having build number + set(PACKAGE_RELEASE_VERSION "") + if(DEFINED ENV{CPACK_RPM_PACKAGE_RELEASE}) + set(PACKAGE_RELEASE_VERSION $ENV{CPACK_RPM_PACKAGE_RELEASE}) + endif() + if(PACKAGE_RELEASE_VERSION) + # Replace "." to "_" in package version string. So file name will have .icd as extension + string(REPLACE "." "_" PACKAGE_RELEASE_VERSION ${PACKAGE_RELEASE_VERSION}) + else() + # set a default value + set(PACKAGE_RELEASE_VERSION "9999") + endif() + set(OPENCL_AMD_ICD_FILE "amdocl64_${ROCM_PATCH_VERSION}_${PACKAGE_RELEASE_VERSION}.icd") +endif() + +if(BUILD_ICD) + get_target_property(OPENCL_LIB_VERSION_MAJOR OpenCL SOVERSION) + get_target_property(OPENCL_LIB_VERSION_STRING OpenCL VERSION) +endif() + +#Set Package Version +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) +if(DEFINED ENV{ROCM_LIBPATCH_VERSION}) + set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}.$ENV{ROCM_LIBPATCH_VERSION}") + message("Using CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}") +endif() + +set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/rocm" CACHE PATH "Package Installation path for OpenCL") +#ROCM_PATH is needed to create symlink of libraries +if(NOT DEFINED ROCM_PATH) + string(REPLACE "/opencl" "" ROCM_PATH ${CPACK_PACKAGING_INSTALL_PREFIX}) +endif() +message (STATUS "ROCM Installation path(ROCM_PATH): ${ROCM_PATH}") + +#Package: rocm-opencl,rocm-opencl-dev/devel,rocm-ocl-icd + +if(BUILD_ICD) + set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/packages/rocm-ocl-icd) + configure_file(packaging/rocm-ocl-icd.postinst ${BUILD_DIR}/postinst @ONLY) + configure_file(packaging/rocm-ocl-icd.prerm ${BUILD_DIR}/prerm @ONLY) + configure_file(packaging/rocm-ocl-icd.rpm_post ${BUILD_DIR}/rpm_post @ONLY) + configure_file(packaging/rocm-ocl-icd.rpm_postun ${BUILD_DIR}/rpm_postun @ONLY) +endif() + +add_subdirectory(packaging) + +#File reorg Backward compatibility function +if(FILE_REORG_BACKWARD_COMPATIBILITY) + include(opencl-backward-compat.cmake) +endif() + +endif() diff --git a/opencl/LICENSE.txt b/opencl/LICENSE.txt new file mode 100644 index 0000000000..57378c6698 --- /dev/null +++ b/opencl/LICENSE.txt @@ -0,0 +1,20 @@ +Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/opencl/README.md b/opencl/README.md new file mode 100644 index 0000000000..6358426ea0 --- /dev/null +++ b/opencl/README.md @@ -0,0 +1,54 @@ +# OpenCL™ Compatible Runtime + +- OpenCL 2.0 compatible language runtime +- Supports offline and in-process/in-memory compilation + +## DISCLAIMER + +The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions, and typographical errors. The information contained herein is subject to change and may be rendered inaccurate for many reasons, including but not limited to product and roadmap changes, component and motherboard versionchanges, new model and/or product releases, product differences between differing manufacturers, software changes, BIOS flashes, firmware upgrades, or the like. Any computer system has risks of security vulnerabilities that cannot be completely prevented or mitigated.AMD assumes no obligation to update or otherwise correct or revise this information. However, AMD reserves the right to revise this information and to make changes from time to time to the content hereof without obligation of AMD to notify any person of such revisions or changes.THIS INFORMATION IS PROVIDED ‘AS IS.” AMD MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE CONTENTS HEREOF AND ASSUMES NO RESPONSIBILITY FOR ANY INACCURACIES, ERRORS, OR OMISSIONS THAT MAY APPEAR IN THIS INFORMATION. AMD SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT WILL AMD BE LIABLE TO ANY PERSON FOR ANY RELIANCE, DIRECT, INDIRECT, SPECIAL, OR OTHER CONSEQUENTIAL DAMAGES ARISING FROM THE USE OF ANY INFORMATION CONTAINED HEREIN, EVEN IF AMD IS EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. AMD, the AMD Arrow logo, and combinations thereof are trademarks of Advanced Micro Devices, Inc. Other product names used in this publication are for identification purposes only and may be trademarks of their respective companies. + +© 2021 Advanced Micro Devices, Inc. All Rights Reserved. + +## Getting the source code +Download the git projects using the following commands: + +```bash +git clone -b main https://github.com/RadeonOpenCompute/ROCm-OpenCL-Runtime.git +``` + +## Repository branches + +The repository maintains several branches. The branches that are of importance are: + +- Main branch: This is the stable branch. It is up to date with the latest release branch, for example, if the latest ROCM release is rocm-4.1, main branch will be the repository based on this release. +- Develop branch: This is the default branch, on which the new features are still under development and visible. While this maybe of interest to many, it should be noted that this branch and the features under development might not be stable. +- Release branches: These are branches corresponding to each ROCM release, listed with release tags, such as rocm-4.0, rocm-4.1, etc. + +## Setup OpenCL +Copy the amdocl64.icd file to /etc/OpenCL/vendors + +```bash +sudo cp api/opencl/config/amdocl64.icd /etc/OpenCL/vendors/ +``` + +## Building +Follow these steps: + +- Build ROCclr first. Follow the steps in the following link to build ROCclr + [ROCclr Readme](https://github.com/ROCm-Developer-Tools/ROCclr) + In this step, $OPENCL_DIR and $ROCclr_DIR are defined. + +- Building OpenCL +Run these commands: + +```bash +cd "$OPENCL_DIR" +mkdir -p build; cd build +cmake -DUSE_COMGR_LIBRARY=ON -DCMAKE_PREFIX_PATH="$ROCclr_DIR/build;/opt/rocm/" .. +make -j$(nproc) +``` + +Note: For release build, add "-DCMAKE_BUILD_TYPE=Release" to the cmake command line. + +--- +OpenCL™ is registered Trademark of Apple diff --git a/opencl/amdocl/CMakeLists.txt b/opencl/amdocl/CMakeLists.txt new file mode 100644 index 0000000000..e720c76ab8 --- /dev/null +++ b/opencl/amdocl/CMakeLists.txt @@ -0,0 +1,123 @@ +# Copyright (c) 2020 - 2021 Advanced Micro Devices, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +cmake_minimum_required(VERSION 3.5) + +project(amdocl) + +option(BUILD_SHARED_LIBS "Build the shared library" ON) + +if(ADDRESS_SANITIZER) + set(ASAN_LINKER_FLAGS "-fsanitize=address") + set(ASAN_COMPILER_FLAGS "-fno-omit-frame-pointer -fsanitize=address") + + if(NOT CMAKE_COMPILER_IS_GNUCC) + if(BUILD_SHARED_LIBS) + set(ASAN_COMPILER_FLAGS "${ASAN_COMPILER_FLAGS} -shared-libsan") + set(ASAN_LINKER_FLAGS "${ASAN_LINKER_FLAGS} -shared-libsan") + else() + set(ASAN_LINKER_FLAGS "${ASAN_LINKER_FLAGS} -static-libsan") + endif() + endif() + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ASAN_COMPILER_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ASAN_COMPILER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ASAN_LINKER_FLAGS} -s -Wl,--build-id=sha1") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ASAN_LINKER_FLAGS} -Wl,--build-id=sha1") +endif() + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") +find_package(ROCclr) + +if(BUILD_SHARED_LIBS) + add_library(amdocl SHARED) + # Windows doesn't have a strip utility, so CMAKE_STRIP won't be set. + if((CMAKE_BUILD_TYPE STREQUAL "Release") AND NOT ("${CMAKE_STRIP}" STREQUAL "")) + add_custom_command(TARGET amdocl POST_BUILD COMMAND ${CMAKE_STRIP} $) + endif() +else() + add_library(amdocl STATIC) +endif() + +set_target_properties(amdocl PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + POSITION_INDEPENDENT_CODE ON) + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set_target_properties(amdocl PROPERTIES OUTPUT_NAME "amdocl64") +else() + set_target_properties(amdocl PROPERTIES OUTPUT_NAME "amdocl32") +endif() + +target_sources(amdocl PRIVATE + cl_command.cpp + cl_context.cpp + cl_counter.cpp + cl_d3d9.cpp + cl_d3d10.cpp + cl_d3d11.cpp + cl_device.cpp + cl_event.cpp + cl_execute.cpp + cl_gl.cpp + cl_icd.cpp + cl_kernel_info_amd.cpp + cl_memobj.cpp + cl_p2p_amd.cpp + cl_pipe.cpp + cl_platform_amd.cpp + cl_profile_amd.cpp + cl_program.cpp + cl_sampler.cpp + cl_sdi_amd.cpp + cl_svm.cpp + cl_thread_trace_amd.cpp) + +if(WIN32) + target_sources(amdocl PRIVATE + cl_runtime.cpp) +endif() + +if(BUILD_SHARED_LIBS) + if(WIN32) + target_sources(amdocl PRIVATE amdocl.def) + else() + # -Bsymbolic is required to make sure all AMD OpenCL runtime symbols are resolved internally + # Otherwise ld might resolve them using symbols from the OpenCL ICD + target_link_libraries(amdocl PRIVATE "-Wl,-Bsymbolic") + target_link_libraries(amdocl PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/amdocl.map") + set_target_properties(amdocl PROPERTIES LINK_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/amdocl.map") + endif() +endif() + +if(WIN32) + configure_file(amdocl.rc.in amdocl_info.rc @ONLY) + target_sources(amdocl PRIVATE amdocl_info.rc) +endif() + +target_link_libraries(amdocl PUBLIC rocclr) + +INSTALL(TARGETS amdocl + COMPONENT MAIN + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/opencl/amdocl/amdocl.def b/opencl/amdocl/amdocl.def new file mode 100644 index 0000000000..d16f85b2f8 --- /dev/null +++ b/opencl/amdocl/amdocl.def @@ -0,0 +1,125 @@ +EXPORTS +clBuildProgram +clCreateBuffer +clCreateCommandQueue +clCreateContext +clCreateContextFromType +clCreateFromGLBuffer +clCreateFromGLRenderbuffer +clCreateFromGLTexture2D +clCreateFromGLTexture3D +clCreateImage2D +clCreateImage3D +clCreateKernel +clCreateKernelsInProgram +clCreateProgramWithBinary +clCreateProgramWithSource +clCreateSampler +clEnqueueAcquireGLObjects +clEnqueueBarrier +clEnqueueCopyBuffer +clEnqueueCopyBufferToImage +clEnqueueCopyImage +clEnqueueCopyImageToBuffer +clEnqueueMapBuffer +clEnqueueMapImage +clEnqueueMarker +clEnqueueNDRangeKernel +clEnqueueNativeKernel +clEnqueueReadBuffer +clEnqueueReadImage +clEnqueueReleaseGLObjects +clEnqueueTask +clEnqueueUnmapMemObject +clEnqueueWaitForEvents +clEnqueueWriteBuffer +clEnqueueWriteImage +clFinish +clFlush +clGetCommandQueueInfo +clGetContextInfo +clGetDeviceIDs +clGetDeviceInfo +clGetEventInfo +clGetEventProfilingInfo +clGetExtensionFunctionAddress +clGetGLObjectInfo +clGetGLTextureInfo +clGetImageInfo +clGetKernelInfo +clGetKernelWorkGroupInfo +clGetMemObjectInfo +clGetPlatformIDs +clGetPlatformInfo +clGetProgramBuildInfo +clGetProgramInfo +clGetSamplerInfo +clGetSupportedImageFormats +clReleaseCommandQueue +clReleaseContext +clReleaseEvent +clReleaseKernel +clReleaseMemObject +clReleaseProgram +clReleaseSampler +clRetainCommandQueue +clRetainContext +clRetainEvent +clRetainKernel +clRetainMemObject +clRetainProgram +clRetainSampler +clSetCommandQueueProperty +clSetKernelArg +clUnloadCompiler +clWaitForEvents +clIcdGetPlatformIDsKHR +clCreateUserEvent +clSetUserEventStatus +clSetEventCallback +clSetMemObjectDestructorCallback +clCreateSubBuffer +clEnqueueReadBufferRect +clEnqueueWriteBufferRect +clEnqueueCopyBufferRect + +clCompileProgram +clCreateFromGLTexture +clCreateImage +clCreateProgramWithBuiltInKernels +clCreateSubDevices +clEnqueueBarrierWithWaitList +clEnqueueFillBuffer +clEnqueueFillImage +clEnqueueMarkerWithWaitList +clEnqueueMigrateMemObjects +clGetExtensionFunctionAddressForPlatform +clGetKernelArgInfo +clLinkProgram +clReleaseDevice +clRetainDevice +clUnloadPlatformCompiler + +clCreateCommandQueueWithProperties +clCreateSamplerWithProperties +clCreatePipe +clGetPipeInfo +clSVMAlloc +clSVMFree +clSetKernelArgSVMPointer +clSetKernelExecInfo +clEnqueueSVMFree +clEnqueueSVMMemcpy +clEnqueueSVMMemFill +clEnqueueSVMMap +clEnqueueSVMUnmap + +clCloneKernel +clCreateProgramWithIL +clEnqueueSVMMigrateMem +clGetDeviceAndHostTimer +clGetHostTimer +clGetKernelSubGroupInfo +clSetDefaultDeviceCommandQueue + +clCreateProgramWithIL diff --git a/opencl/amdocl/amdocl.def.in b/opencl/amdocl/amdocl.def.in new file mode 100644 index 0000000000..650c3ff7fa --- /dev/null +++ b/opencl/amdocl/amdocl.def.in @@ -0,0 +1,174 @@ +EXPORTS +clBuildProgram +clCreateBuffer +clCreateCommandQueue +clCreateContext +clCreateContextFromType +clCreateFromGLBuffer +clCreateFromGLRenderbuffer +clCreateFromGLTexture2D +clCreateFromGLTexture3D +clCreateImage2D +clCreateImage3D +clCreateKernel +clCreateKernelsInProgram +clCreateProgramWithBinary +clCreateProgramWithSource +clCreateSampler +clEnqueueAcquireGLObjects +clEnqueueBarrier +clEnqueueCopyBuffer +clEnqueueCopyBufferToImage +clEnqueueCopyImage +clEnqueueCopyImageToBuffer +clEnqueueMapBuffer +clEnqueueMapImage +clEnqueueMarker +clEnqueueNDRangeKernel +clEnqueueNativeKernel +clEnqueueReadBuffer +clEnqueueReadImage +clEnqueueReleaseGLObjects +clEnqueueTask +clEnqueueUnmapMemObject +clEnqueueWaitForEvents +clEnqueueWriteBuffer +clEnqueueWriteImage +clFinish +clFlush +clGetCommandQueueInfo +clGetContextInfo +clGetDeviceIDs +clGetDeviceInfo +clGetEventInfo +clGetEventProfilingInfo +clGetExtensionFunctionAddress +clGetGLObjectInfo +clGetGLTextureInfo +clGetImageInfo +clGetKernelInfo +clGetKernelWorkGroupInfo +clGetMemObjectInfo +clGetPlatformIDs +clGetPlatformInfo +clGetProgramBuildInfo +clGetProgramInfo +clGetSamplerInfo +clGetSupportedImageFormats +clReleaseCommandQueue +clReleaseContext +clReleaseEvent +clReleaseKernel +clReleaseMemObject +clReleaseProgram +clReleaseSampler +clRetainCommandQueue +clRetainContext +clRetainEvent +clRetainKernel +clRetainMemObject +clRetainProgram +clRetainSampler +clSetCommandQueueProperty +clSetKernelArg +clUnloadCompiler +clWaitForEvents +clIcdGetPlatformIDsKHR +clCreateUserEvent +clSetUserEventStatus +clSetEventCallback +clSetMemObjectDestructorCallback +clCreateSubBuffer +clEnqueueReadBufferRect +clEnqueueWriteBufferRect +clEnqueueCopyBufferRect + +#if (OPENCL_MAJOR > 1) || (OPENCL_MAJOR == 1 && OPENCL_MINOR >= 2) +clCompileProgram +clCreateFromGLTexture +clCreateImage +clCreateProgramWithBuiltInKernels +clCreateSubDevices +clEnqueueBarrierWithWaitList +clEnqueueFillBuffer +clEnqueueFillImage +clEnqueueMarkerWithWaitList +clEnqueueMigrateMemObjects +clGetExtensionFunctionAddressForPlatform +clGetKernelArgInfo +clLinkProgram +clReleaseDevice +clRetainDevice +clUnloadPlatformCompiler +#endif + +#if (OPENCL_MAJOR >= 2) +clCreateCommandQueueWithProperties +clCreateSamplerWithProperties +clCreatePipe +clGetPipeInfo +clSVMAlloc +clSVMFree +clSetKernelArgSVMPointer +clSetKernelExecInfo +clEnqueueSVMFree +clEnqueueSVMMemcpy +clEnqueueSVMMemFill +clEnqueueSVMMap +clEnqueueSVMUnmap +#endif + +#if (OPENCL_MAJOR > 2) || (OPENCL_MAJOR == 2 && OPENCL_MINOR >= 1) +clCloneKernel +clCreateProgramWithIL +clEnqueueSVMMigrateMem +clGetDeviceAndHostTimer +clGetHostTimer +clGetKernelSubGroupInfo +clSetDefaultDeviceCommandQueue +#endif + +#if !defined(WITH_LIGHTNING_COMPILER) +aclCompilerInit +aclCompilerFini +aclCompilerVersion +aclVersionSize +aclGetErrorString +aclGetArchInfo +aclGetDeviceInfo +aclGetTargetInfo +aclGetArchitecture +aclGetFamily +aclGetChip +aclBinaryInit +aclBinaryFini +aclReadFromFile +aclReadFromMem +aclWriteToFile +aclWriteToMem +aclCreateFromBinary +aclBinaryVersion +aclInsertSection +aclRemoveSection +aclExtractSection +aclInsertSymbol +aclRemoveSymbol +aclExtractSymbol +aclDbgAddArgument +aclDbgRemoveArgument +aclQueryInfo +aclCompile +aclLink +aclGetCompilerLog +aclRetrieveType +aclSetType +aclConvertType +aclDisassemble +aclInsertKernelStatistics +aclGetDeviceBinary +aclDumpBinary +#endif // !defined(WITH_LIGHTNING_COMPILER) + +#if (OPENCL_MAJOR > 2) || (OPENCL_MAJOR == 2 && OPENCL_MINOR >= 1) +clCreateProgramWithIL +#endif diff --git a/opencl/amdocl/amdocl.map b/opencl/amdocl/amdocl.map new file mode 100644 index 0000000000..d379214455 --- /dev/null +++ b/opencl/amdocl/amdocl.map @@ -0,0 +1,165 @@ +OPENCL_1.0 { +global: + clBuildProgram; + clCreateBuffer; + clCreateCommandQueue; + clCreateContext; + clCreateContextFromType; + clCreateFromD3D10Buffer; + clCreateFromGLBuffer; + clCreateFromGLRenderbuffer; + clCreateFromGLTexture2D; + clCreateFromGLTexture3D; + clCreateImage2D; + clCreateImage3D; + clCreateImageFromD3D10Resource; + clCreateKernel; + clCreateKernelsInProgram; + clCreateProgramWithBinary; + clCreateProgramWithSource; + clCreateSampler; + clEnqueueAcquireExternalObjects; + clEnqueueAcquireGLObjects; + clEnqueueBarrier; + clEnqueueCopyBuffer; + clEnqueueCopyBufferToImage; + clEnqueueCopyImage; + clEnqueueCopyImageToBuffer; + clEnqueueMapBuffer; + clEnqueueMapImage; + clEnqueueMarker; + clEnqueueNDRangeKernel; + clEnqueueNativeKernel; + clEnqueueReadBuffer; + clEnqueueReadImage; + clEnqueueReleaseExternalObjects; + clEnqueueReleaseGLObjects; + clEnqueueTask; + clEnqueueUnmapMemObject; + clEnqueueWaitForEvents; + clEnqueueWriteBuffer; + clEnqueueWriteImage; + clFinish; + clFlush; + clGetCommandQueueInfo; + clGetContextInfo; + clGetDeviceIDs; + clGetDeviceInfo; + clGetEventInfo; + clGetEventProfilingInfo; + clGetExtensionFunctionAddress; + clGetGLObjectInfo; + clGetGLTextureInfo; + clGetImageInfo; + clGetKernelInfo; + clGetKernelWorkGroupInfo; + clGetMemObjectInfo; + clGetPlatformIDs; + clGetPlatformInfo; + clGetProgramBuildInfo; + clGetProgramInfo; + clGetSamplerInfo; + clGetSupportedImageFormats; + clReleaseCommandQueue; + clReleaseContext; + clReleaseEvent; + clReleaseKernel; + clReleaseMemObject; + clReleaseProgram; + clReleaseSampler; + clRetainCommandQueue; + clRetainContext; + clRetainEvent; + clRetainKernel; + clRetainMemObject; + clRetainProgram; + clRetainSampler; + clSetCommandQueueProperty; + clSetKernelArg; + clUnloadCompiler; + clWaitForEvents; + clIcdGetPlatformIDsKHR; +local: + *; +}; + + +OPENCL_1.1 { +global: + clCreateUserEvent; + clSetUserEventStatus; + clSetEventCallback; + clSetMemObjectDestructorCallback; + clCreateSubBuffer; + clEnqueueReadBufferRect; + clEnqueueWriteBufferRect; + clEnqueueCopyBufferRect; + + aclGetTargetInfo; + aclCompilerInit; + aclCompilerFini; + aclReadFromMem; + aclReadFromFile; + aclBinaryInit; + aclBinaryFini; + aclWriteToMem; + aclInsertSection; + aclExtractSection; + aclRemoveSection; + aclQueryInfo; + aclDbgAddArgument; + aclExtractSymbol; + aclInsertSymbol; + aclRemoveSymbol; + aclCompile; + aclInsertKernelStatistics; + aclDisassemble; +} OPENCL_1.0; + +OPENCL_1.2 { +global: + clCompileProgram; + clCreateFromGLTexture; + clCreateImage; + clCreateProgramWithBuiltInKernels; + clCreateSubDevices; + clEnqueueBarrierWithWaitList; + clEnqueueFillBuffer; + clEnqueueFillImage; + clEnqueueMarkerWithWaitList; + clEnqueueMigrateMemObjects; + clGetExtensionFunctionAddressForPlatform; + clGetKernelArgInfo; + clLinkProgram; + clReleaseDevice; + clRetainDevice; + clUnloadPlatformCompiler; +} OPENCL_1.1; + +OPENCL_2.0 { +global: + clCreateCommandQueueWithProperties; + clCreateSamplerWithProperties; + clCreatePipe; + clGetPipeInfo; + clSVMAlloc; + clSVMFree; + clSetKernelArgSVMPointer; + clSetKernelExecInfo; + clEnqueueSVMFree; + clEnqueueSVMMemcpy; + clEnqueueSVMMemFill; + clEnqueueSVMMap; + clEnqueueSVMUnmap; +} OPENCL_1.2; + +OPENCL_2.1 { +global: + clCloneKernel; + clCreateProgramWithIL; + clEnqueueSVMMigrateMem; + clGetDeviceAndHostTimer; + clGetHostTimer; + clGetKernelSubGroupInfo; + clSetDefaultDeviceCommandQueue; +} OPENCL_2.0; diff --git a/opencl/amdocl/amdocl.map.in b/opencl/amdocl/amdocl.map.in new file mode 100644 index 0000000000..32acfd33a1 --- /dev/null +++ b/opencl/amdocl/amdocl.map.in @@ -0,0 +1,214 @@ +OPENCL_1.0 { +global: + clBuildProgram; + clCreateBuffer; + clCreateCommandQueue; + clCreateContext; + clCreateContextFromType; + clCreateFromD3D10Buffer; + clCreateFromGLBuffer; + clCreateFromGLRenderbuffer; + clCreateFromGLTexture2D; + clCreateFromGLTexture3D; + clCreateImage2D; + clCreateImage3D; + clCreateImageFromD3D10Resource; + clCreateKernel; + clCreateKernelsInProgram; + clCreateProgramWithBinary; + clCreateProgramWithSource; + clCreateSampler; + clEnqueueAcquireExternalObjects; + clEnqueueAcquireGLObjects; + clEnqueueBarrier; + clEnqueueCopyBuffer; + clEnqueueCopyBufferToImage; + clEnqueueCopyImage; + clEnqueueCopyImageToBuffer; + clEnqueueMapBuffer; + clEnqueueMapImage; + clEnqueueMarker; + clEnqueueNDRangeKernel; + clEnqueueNativeKernel; + clEnqueueReadBuffer; + clEnqueueReadImage; + clEnqueueReleaseExternalObjects; + clEnqueueReleaseGLObjects; + clEnqueueTask; + clEnqueueUnmapMemObject; + clEnqueueWaitForEvents; + clEnqueueWriteBuffer; + clEnqueueWriteImage; + clFinish; + clFlush; + clGetCommandQueueInfo; + clGetContextInfo; + clGetDeviceIDs; + clGetDeviceInfo; + clGetEventInfo; + clGetEventProfilingInfo; + clGetExtensionFunctionAddress; + clGetGLObjectInfo; + clGetGLTextureInfo; + clGetImageInfo; + clGetKernelInfo; + clGetKernelWorkGroupInfo; + clGetMemObjectInfo; + clGetPlatformIDs; + clGetPlatformInfo; + clGetProgramBuildInfo; + clGetProgramInfo; + clGetSamplerInfo; + clGetSupportedImageFormats; + clReleaseCommandQueue; + clReleaseContext; + clReleaseEvent; + clReleaseKernel; + clReleaseMemObject; + clReleaseProgram; + clReleaseSampler; + clRetainCommandQueue; + clRetainContext; + clRetainEvent; + clRetainKernel; + clRetainMemObject; + clRetainProgram; + clRetainSampler; + clSetCommandQueueProperty; + clSetKernelArg; + clUnloadCompiler; + clWaitForEvents; + clIcdGetPlatformIDsKHR; +local: + *; +}; + +#if (OPENCL_MAJOR > 1) || (OPENCL_MAJOR == 1 && OPENCL_MINOR >= 1) +OPENCL_1.1 { +global: + clCreateUserEvent; + clSetUserEventStatus; + clSetEventCallback; + clSetMemObjectDestructorCallback; + clCreateSubBuffer; + clEnqueueReadBufferRect; + clEnqueueWriteBufferRect; + clEnqueueCopyBufferRect; + + aclGetTargetInfo; + aclCompilerInit; + aclCompilerFini; + aclReadFromMem; + aclReadFromFile; + aclBinaryInit; + aclBinaryFini; + aclWriteToMem; + aclInsertSection; + aclExtractSection; + aclRemoveSection; + aclQueryInfo; + aclDbgAddArgument; + aclExtractSymbol; + aclInsertSymbol; + aclRemoveSymbol; + aclCompile; + aclInsertKernelStatistics; + aclDisassemble; +} OPENCL_1.0; +#endif + +#if (OPENCL_MAJOR > 1) || (OPENCL_MAJOR == 1 && OPENCL_MINOR >= 2) +OPENCL_1.2 { +global: + clCompileProgram; + clCreateFromGLTexture; + clCreateImage; + clCreateProgramWithBuiltInKernels; + clCreateSubDevices; + clEnqueueBarrierWithWaitList; + clEnqueueFillBuffer; + clEnqueueFillImage; + clEnqueueMarkerWithWaitList; + clEnqueueMigrateMemObjects; + clGetExtensionFunctionAddressForPlatform; + clGetKernelArgInfo; + clLinkProgram; + clReleaseDevice; + clRetainDevice; + clUnloadPlatformCompiler; +} OPENCL_1.1; +#endif + +#if (OPENCL_MAJOR >= 2) +OPENCL_2.0 { +global: + clCreateCommandQueueWithProperties; + clCreateSamplerWithProperties; + clCreatePipe; + clGetPipeInfo; + clSVMAlloc; + clSVMFree; + clSetKernelArgSVMPointer; + clSetKernelExecInfo; + clEnqueueSVMFree; + clEnqueueSVMMemcpy; + clEnqueueSVMMemFill; + clEnqueueSVMMap; + clEnqueueSVMUnmap; +} OPENCL_1.2; +#endif + +#if (OPENCL_MAJOR > 2) || (OPENCL_MAJOR == 2 && OPENCL_MINOR >= 1) +OPENCL_2.1 { +global: + clCloneKernel; + clCreateProgramWithIL; + clEnqueueSVMMigrateMem; + clGetDeviceAndHostTimer; + clGetHostTimer; + clGetKernelSubGroupInfo; + clSetDefaultDeviceCommandQueue; +} OPENCL_2.0; +#endif + +ACL_0.8 { +global: + aclCompilerInit; + aclCompilerFini; + aclCompilerVersion; + aclVersionSize; + aclGetErrorString; + aclGetArchInfo; + aclGetDeviceInfo; + aclGetTargetInfo; + aclGetArchitecture; + aclGetFamily; + aclGetChip; + aclBinaryInit; + aclBinaryFini; + aclReadFromFile; + aclReadFromMem; + aclWriteToFile; + aclWriteToMem; + aclCreateFromBinary; + aclBinaryVersion; + aclInsertSection; + aclRemoveSection; + aclExtractSection; + aclInsertSymbol; + aclRemoveSymbol; + aclExtractSymbol; + aclDbgAddArgument; + aclDbgRemoveArgument; + aclQueryInfo; + aclCompile; + aclLink; + aclGetCompilerLog; + aclRetrieveType; + aclSetType; + aclConvertType; + aclDisassemble; + aclInsertKernelStatistics; + aclGetDeviceBinary; + aclDumpBinary; +}; diff --git a/opencl/amdocl/amdocl.rc b/opencl/amdocl/amdocl.rc new file mode 100644 index 0000000000..1793116e1a --- /dev/null +++ b/opencl/amdocl/amdocl.rc @@ -0,0 +1,75 @@ +#define STR(__macro__) #__macro__ +#define XSTR(__macro__) STR(__macro__) + +#if defined(_DEBUG) +#define DEBUG_ONLY(x) x +#else +#define DEBUG_ONLY(x) +#endif + +#define VERSION_PREFIX_MAJOR 2 +#define VERSION_PREFIX_MINOR 0 + + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winresrc.h" +#include "utils/versions.hpp" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 10,0,AMD_PLATFORM_BUILD_NUMBER,AMD_PLATFORM_REVISION_NUMBER + PRODUCTVERSION 10,0,AMD_PLATFORM_BUILD_NUMBER,AMD_PLATFORM_REVISION_NUMBER + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "Comments", " \0" + VALUE "CompanyName", "Advanced Micro Devices Inc.\0" + VALUE "FileDescription", AMD_PLATFORM_NAME " OpenCL " XSTR(VERSION_PREFIX_MAJOR) "." XSTR(VERSION_PREFIX_MINOR) " Runtime\0" + VALUE "FileVersion", "10.0." XSTR(AMD_PLATFORM_BUILD_NUMBER) "." XSTR(AMD_PLATFORM_REVISION_NUMBER) + VALUE "InternalName", "OpenCL" + VALUE "LegalCopyright", "Copyright (c) 2011 - 2021 Advanced Micro Devices Inc.\0" + VALUE "OriginalFilename", "OpenCL.dll" + VALUE "ProductName", "OpenCL " XSTR(VERSION_PREFIX_MAJOR) "." XSTR(VERSION_PREFIX_MINOR) " " AMD_PLATFORM_INFO "\0" + VALUE "ProductVersion", "10.0." XSTR(AMD_PLATFORM_BUILD_NUMBER) "." XSTR(AMD_PLATFORM_REVISION_NUMBER) + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// diff --git a/opencl/amdocl/amdocl.rc.in b/opencl/amdocl/amdocl.rc.in new file mode 100644 index 0000000000..1c51afd4b1 --- /dev/null +++ b/opencl/amdocl/amdocl.rc.in @@ -0,0 +1,75 @@ +#define STR(__macro__) #__macro__ +#define XSTR(__macro__) STR(__macro__) + +#if defined(_DEBUG) +#define DEBUG_ONLY(x) x +#else +#define DEBUG_ONLY(x) +#endif + +#define VERSION_PREFIX_MAJOR 2 +#define VERSION_PREFIX_MINOR 0 + + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winresrc.h" +#include "utils/versions.hpp" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 10,0,AMD_PLATFORM_BUILD_NUMBER,AMD_PLATFORM_REVISION_NUMBER + PRODUCTVERSION 10,0,AMD_PLATFORM_BUILD_NUMBER,AMD_PLATFORM_REVISION_NUMBER + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "Comments", " \0" + VALUE "CompanyName", "Advanced Micro Devices Inc.\0" + VALUE "FileDescription", AMD_PLATFORM_NAME " OpenCL " XSTR(VERSION_PREFIX_MAJOR) "." XSTR(VERSION_PREFIX_MINOR) " Runtime\0" + VALUE "FileVersion", "10.0." XSTR(AMD_PLATFORM_BUILD_NUMBER) "." XSTR(AMD_PLATFORM_REVISION_NUMBER) + VALUE "InternalName", "OpenCL" + VALUE "LegalCopyright", "Copyright (c) 2011 - 2022 Advanced Micro Devices Inc.\0" + VALUE "OriginalFilename", "OpenCL.dll" + VALUE "ProductName", "OpenCL " XSTR(VERSION_PREFIX_MAJOR) "." XSTR(VERSION_PREFIX_MINOR) " " AMD_PLATFORM_INFO "\0" + VALUE "ProductVersion", "10.0." XSTR(AMD_PLATFORM_BUILD_NUMBER) "." XSTR(AMD_PLATFORM_REVISION_NUMBER) + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// diff --git a/opencl/amdocl/cl_agent_amd.h b/opencl/amdocl/cl_agent_amd.h new file mode 100644 index 0000000000..623b41e819 --- /dev/null +++ b/opencl/amdocl/cl_agent_amd.h @@ -0,0 +1,187 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef __OPENCL_CL_AGENT_AMD_H +#define __OPENCL_CL_AGENT_AMD_H + +#include +#include "cl_icd_amd.h" + +#define cl_amd_agent 1 + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef const struct _cl_agent cl_agent; + +#define CL_AGENT_VERSION_1_0 100 + +/* Context Callbacks */ + +typedef void(CL_CALLBACK* acContextCreate_fn)(cl_agent* /* agent */, cl_context /* context */); + +typedef void(CL_CALLBACK* acContextFree_fn)(cl_agent* /* agent */, cl_context /* context */); + +/* Command Queue Callbacks */ + +typedef void(CL_CALLBACK* acCommandQueueCreate_fn)(cl_agent* /* agent */, + cl_command_queue /* queue */); + +typedef void(CL_CALLBACK* acCommandQueueFree_fn)(cl_agent* /* agent */, + cl_command_queue /* queue */); + +/* Event Callbacks */ + +typedef void(CL_CALLBACK* acEventCreate_fn)(cl_agent* /* agent */, cl_event /* event */, + cl_command_type /* type */); + +typedef void(CL_CALLBACK* acEventFree_fn)(cl_agent* /* agent */, cl_event /* event */); + +typedef void(CL_CALLBACK* acEventStatusChanged_fn)(cl_agent* /* agent */, cl_event /* event */, + cl_int /* execution_status */, + cl_long /* epoch_time_stamp */); + +/* Memory Object Callbacks */ + +typedef void(CL_CALLBACK* acMemObjectCreate_fn)(cl_agent* /* agent */, cl_mem /* memobj */); + +typedef void(CL_CALLBACK* acMemObjectFree_fn)(cl_agent* /* agent */, cl_mem /* memobj */); + +typedef void(CL_CALLBACK* acMemObjectAcquired_fn)(cl_agent* /* agent */, cl_mem /* memobj */, + cl_device_id /* device */, + cl_long /* elapsed_time */); + +/* Sampler Callbacks */ + +typedef void(CL_CALLBACK* acSamplerCreate_fn)(cl_agent* /* agent */, cl_sampler /* sampler */); + +typedef void(CL_CALLBACK* acSamplerFree_fn)(cl_agent* /* agent */, cl_sampler /* sampler */); + +/* Program Callbacks */ + +typedef void(CL_CALLBACK* acProgramCreate_fn)(cl_agent* /* agent */, cl_program /* program */); + +typedef void(CL_CALLBACK* acProgramFree_fn)(cl_agent* /* agent */, cl_program /* program */); + +typedef void(CL_CALLBACK* acProgramBuild_fn)(cl_agent* /* agent */, cl_program /* program */); + +/* Kernel Callbacks */ + +typedef void(CL_CALLBACK* acKernelCreate_fn)(cl_agent* /* agent */, cl_kernel /* kernel */); + +typedef void(CL_CALLBACK* acKernelFree_fn)(cl_agent* /* agent */, cl_kernel /* kernel */); + +typedef void(CL_CALLBACK* acKernelSetArg_fn)(cl_agent* /* agent */, cl_kernel /* kernel */, + cl_int /* arg_index */, size_t /* size */, + const void* /* value_ptr */); + +typedef struct _cl_agent_callbacks { + /* Context Callbacks */ + acContextCreate_fn ContextCreate; + acContextFree_fn ContextFree; + + /* Command Queue Callbacks */ + acCommandQueueCreate_fn CommandQueueCreate; + acCommandQueueFree_fn CommandQueueFree; + + /* Event Callbacks */ + acEventCreate_fn EventCreate; + acEventFree_fn EventFree; + acEventStatusChanged_fn EventStatusChanged; + + /* Memory Object Callbacks */ + acMemObjectCreate_fn MemObjectCreate; + acMemObjectFree_fn MemObjectFree; + acMemObjectAcquired_fn MemObjectAcquired; + + /* Sampler Callbacks */ + acSamplerCreate_fn SamplerCreate; + acSamplerFree_fn SamplerFree; + + /* Program Callbacks */ + acProgramCreate_fn ProgramCreate; + acProgramFree_fn ProgramFree; + acProgramBuild_fn ProgramBuild; + + /* Kernel Callbacks */ + acKernelCreate_fn KernelCreate; + acKernelFree_fn KernelFree; + acKernelSetArg_fn KernelSetArg; + +} cl_agent_callbacks; + +typedef cl_uint cl_agent_capability_action; + +#define CL_AGENT_ADD_CAPABILITIES 0x0 +#define CL_AGENT_RELINQUISH_CAPABILITIES 0x1 + +typedef struct _cl_agent_capabilities { + cl_bitfield canGenerateContextEvents : 1; + cl_bitfield canGenerateCommandQueueEvents : 1; + cl_bitfield canGenerateEventEvents : 1; + cl_bitfield canGenerateMemObjectEvents : 1; + cl_bitfield canGenerateSamplerEvents : 1; + cl_bitfield canGenerateProgramEvents : 1; + cl_bitfield canGenerateKernelEvents : 1; + +} cl_agent_capabilities; + +struct _cl_agent { + cl_int(CL_API_CALL* GetVersionNumber)(cl_agent* /* agent */, cl_int* /* version_ret */); + + cl_int(CL_API_CALL* GetPlatform)(cl_agent* /* agent */, cl_platform_id* /* platform_id_ret */); + + cl_int(CL_API_CALL* GetTime)(cl_agent* /* agent */, cl_long* /* time_nanos */); + + cl_int(CL_API_CALL* SetCallbacks)(cl_agent* /* agent */, + const cl_agent_callbacks* /* callbacks */, size_t /* size */); + + + cl_int(CL_API_CALL* GetPotentialCapabilities)(cl_agent* /* agent */, + cl_agent_capabilities* /* capabilities */); + + cl_int(CL_API_CALL* GetCapabilities)(cl_agent* /* agent */, + cl_agent_capabilities* /* capabilities */); + + cl_int(CL_API_CALL* SetCapabilities)(cl_agent* /* agent */, + const cl_agent_capabilities* /* capabilities */, + cl_agent_capability_action /* action */); + + + cl_int(CL_API_CALL* GetICDDispatchTable)(cl_agent* /* agent */, + cl_icd_dispatch_table* /* table */, size_t /* size */); + + cl_int(CL_API_CALL* SetICDDispatchTable)(cl_agent* /* agent */, + const cl_icd_dispatch_table* /* table */, + size_t /* size */); + + /* add Kernel/Program helper functions, etc... */ +}; + +extern cl_int CL_CALLBACK clAgent_OnLoad(cl_agent* /* agent */); + +extern void CL_CALLBACK clAgent_OnUnload(cl_agent* /* agent */); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __OPENCL_CL_AGENT_AMD_H */ diff --git a/opencl/amdocl/cl_command.cpp b/opencl/amdocl/cl_command.cpp new file mode 100644 index 0000000000..d016bcd672 --- /dev/null +++ b/opencl/amdocl/cl_command.cpp @@ -0,0 +1,421 @@ +/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" + +#include "platform/object.hpp" +#include "platform/context.hpp" +#include "platform/command.hpp" +#include "platform/agent.hpp" + +/*! \addtogroup API + * @{ + * + * \addtogroup CL_Queues + * + * OpenCL objects such as memory objects, program and kernel objects are + * created using a context. Operations on these objects are performed using + * a command-queue. The command-queue can be used to queue a set of operations + * (referred to as commands) in order. Having multiple command-queues allows + * applications to queue multiple independent commands without requiring + * synchronization. Note that this should work as long as these objects are + * not being shared. Sharing of objects across multiple command-queues will + * require the application to perform appropriate synchronization. + * + * @{ + */ + +/*! \brief Create a command-queue on a specific device. + * + * \param context must be a valid OpenCL context. + * + * \param device must be a device associated with context. It can either be + * in the list of devices specified when context is created using + * clCreateContext or have the same device type as device type specified wheni + * context is created using clCreateContextFromType. + * + * \param properties specifies a list of properties for the command-queue. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A valid non-zero command-queue and \a errcode_ret is set to + * CL_SUCCESS if the command-queue is created successfully or a NULL value + * with one of the following error values returned \a in errcode_ret: + * - CL_INVALID_CONTEXT if context is not a valid. + * - CL_INVALID_DEVICE if device is not a valid device or is not associated + * with context + * - CL_INVALID_VALUE if values specified in properties are not valid. + * - CL_INVALID_QUEUE_PROPERTIES if values specified in properties are valid + * but are not supported by the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY_RET(cl_command_queue, clCreateCommandQueueWithProperties, + (cl_context context, cl_device_id device, + const cl_queue_properties* queue_properties, cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + return (cl_command_queue)0; + } + + amd::Context& amdContext = *as_amd(context); + amd::Device& amdDevice = *as_amd(device); + + if (!is_valid(device) || !amdContext.containsDevice(&amdDevice)) { + *not_null(errcode_ret) = CL_INVALID_DEVICE; + return (cl_command_queue)0; + } + + cl_command_queue_properties properties = 0; + const struct QueueProperty { + cl_queue_properties name; + union { + cl_queue_properties raw; + // FIXME_lmoriche: Check with Khronos. cl_queue_properties is an intptr, + // but cl_command_queue_properties is a bitfield (truncate?). + // cl_command_queue_properties properties; + cl_uint size; + } value; + }* p = reinterpret_cast(queue_properties); + + uint queueSize = amdDevice.info().queueOnDevicePreferredSize_; + uint queueRTCUs = amd::CommandQueue::RealTimeDisabled; + amd::CommandQueue::Priority priority = amd::CommandQueue::Priority::Normal; + if (p != NULL) + while (p->name != 0) { + switch (p->name) { + case CL_QUEUE_PROPERTIES: + // FIXME_lmoriche: See comment above. + // properties = p->value.properties; + properties = static_cast(p->value.raw); + break; + case CL_QUEUE_SIZE: + queueSize = p->value.size; + break; +#define CL_QUEUE_REAL_TIME_COMPUTE_UNITS_AMD 0x404f + case CL_QUEUE_REAL_TIME_COMPUTE_UNITS_AMD: + queueRTCUs = p->value.size; + break; +#define CL_QUEUE_MEDIUM_PRIORITY_AMD 0x4050 + case CL_QUEUE_MEDIUM_PRIORITY_AMD: + priority = amd::CommandQueue::Priority::Medium; + if (p->value.size != 0) { + queueRTCUs = p->value.size; + } + break; + default: + *not_null(errcode_ret) = CL_INVALID_QUEUE_PROPERTIES; + LogWarning("invalid property name"); + return (cl_command_queue)0; + } + ++p; + } + + if (queueSize > amdDevice.info().queueOnDeviceMaxSize_) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_command_queue)0; + } + + if ((queueRTCUs != amd::CommandQueue::RealTimeDisabled) && + ((queueRTCUs > amdDevice.info().numRTCUs_) || (queueRTCUs == 0) + || (queueRTCUs < amdDevice.info().granularityRTCUs_))) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_command_queue)0; + } + + amd::CommandQueue* queue = NULL; + { + amd::ScopedLock lock(amdContext.lock()); + + // Check if the app creates a host queue + if (!(properties & CL_QUEUE_ON_DEVICE)) { + queue = new amd::HostQueue(amdContext, amdDevice, properties, queueRTCUs, priority); + } else { + // Is it a device default queue + if (properties & CL_QUEUE_ON_DEVICE_DEFAULT) { + queue = amdContext.defDeviceQueue(amdDevice); + // If current context has one already then return it + if (NULL != queue) { + queue->retain(); + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(queue); + } + } + // Check if runtime can allocate a new device queue on this context + if (amdContext.isDevQueuePossible(amdDevice)) { + queue = new amd::DeviceQueue(amdContext, amdDevice, properties, queueSize); + } + } + + if (queue == NULL || !queue->create()) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + delete queue; + return (cl_command_queue)0; + } + } + + if (amd::Agent::shouldPostCommandQueueEvents()) { + amd::Agent::postCommandQueueCreate(as_cl(queue->asCommandQueue())); + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(queue); +} +RUNTIME_EXIT + +RUNTIME_ENTRY_RET(cl_command_queue, clCreateCommandQueue, + (cl_context context, cl_device_id device, cl_command_queue_properties properties, + cl_int* errcode_ret)) { + const cl_queue_properties cprops[] = {CL_QUEUE_PROPERTIES, + static_cast(properties), 0}; + return clCreateCommandQueueWithProperties(context, device, properties ? cprops : NULL, + errcode_ret); +} +RUNTIME_EXIT + +/*! \brief Replaces the default command queue on the device + * + * \param context must be a valid OpenCL context. + * + * \param device must be a device associated with context. + * + * \param command_queue specifies the default command-queue. + * + * \reture One of the following values: + * - CL_SUCCESS if the function executed successfully. + * - CL_INVALID_CONTEXT if \a context is not a valid context. + * - CL_INVALID_DEVICE if \a device is not a valid device or is not + * associated with context. + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command- + * queue for device. + */ +RUNTIME_ENTRY(cl_int, clSetDefaultDeviceCommandQueue, + (cl_context context, cl_device_id device, cl_command_queue command_queue)) { + if (!is_valid(context)) { + return CL_INVALID_CONTEXT; + } + + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::Context* amdContext = as_amd(context); + amd::Device* amdDevice = as_amd(device); + if (!is_valid(device) || !amdContext->containsDevice(amdDevice)) { + return CL_INVALID_DEVICE; + } + + amd::DeviceQueue* deviceQueue = as_amd(command_queue)->asDeviceQueue(); + if ((deviceQueue == NULL) || (amdContext != &deviceQueue->context()) || + (amdDevice != &deviceQueue->device())) { + return CL_INVALID_COMMAND_QUEUE; + } + + { + amd::ScopedLock lock(amdContext->lock()); + amdContext->setDefDeviceQueue(*amdDevice, deviceQueue); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Increment the \a command_queue reference count. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid + * command-queue. + * + * clCreateCommandQueue performs an implicit retain. This is very helpful for + * 3rd party libraries, which typically get a command-queue passed to them + * by the application. However, it is possible that the application may delete + * the command-queue without informing the library. Allowing functions to + * attach to (i.e. retain) and release a command-queue solves the problem of a + * command-queue being used by a library no longer being valid. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clRetainCommandQueue, (cl_command_queue command_queue)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + as_amd(command_queue)->retain(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Decrement the \a command_queue reference count. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid + * command-queue. + * + * After the command_queue reference count becomes zero and all commands queued + * to \a command_queue have finished (eg. kernel executions, memory object + * updates etc.), the command-queue is deleted. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clReleaseCommandQueue, (cl_command_queue command_queue)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + as_amd(command_queue)->release(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Query information about a command-queue. + * + * \param command_queue specifies the command-queue being queried. + * + * \param param_name specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result + * being queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type. + * If param_value is NULL, it is ignored. + * + * \param param_value_size_ret returns the actual size in bytes of data being + * queried by \a param_value. If \a param_value_size_ret is NULL, + * it is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid + * command-queue. + * - CL_INVALID_VALUE if \a param_name is not one of the supported + * values or if size in bytes specified by \a param_value_size is < size of + * return type and \a param_value is not a NULL value. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clGetCommandQueueInfo, + (cl_command_queue command_queue, cl_command_queue_info param_name, + size_t param_value_size, void* param_value, size_t* param_value_size_ret)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + switch (param_name) { + case CL_QUEUE_CONTEXT: { + cl_context context = const_cast(as_cl(&as_amd(command_queue)->context())); + return amd::clGetInfo(context, param_value_size, param_value, param_value_size_ret); + } + case CL_QUEUE_DEVICE: { + cl_device_id device = const_cast(as_cl(&as_amd(command_queue)->device())); + return amd::clGetInfo(device, param_value_size, param_value, param_value_size_ret); + } + case CL_QUEUE_PROPERTIES: { + cl_command_queue_properties properties = as_amd(command_queue)->properties().value_; + return amd::clGetInfo(properties, param_value_size, param_value, param_value_size_ret); + } + case CL_QUEUE_REFERENCE_COUNT: { + cl_uint count = as_amd(command_queue)->referenceCount(); + return amd::clGetInfo(count, param_value_size, param_value, param_value_size_ret); + } + case CL_QUEUE_SIZE: { + const amd::DeviceQueue* deviceQueue = as_amd(command_queue)->asDeviceQueue(); + if (NULL == deviceQueue) { + return CL_INVALID_COMMAND_QUEUE; + } + cl_uint size = deviceQueue->size(); + return amd::clGetInfo(size, param_value_size, param_value, param_value_size_ret); + } + case CL_QUEUE_THREAD_HANDLE_AMD: { + const amd::HostQueue* hostQueue = as_amd(command_queue)->asHostQueue(); + if (NULL == hostQueue) { + return CL_INVALID_COMMAND_QUEUE; + } + const void* handle = hostQueue->thread().handle(); + return amd::clGetInfo(handle, param_value_size, param_value, param_value_size_ret); + } + case CL_QUEUE_DEVICE_DEFAULT: { + const amd::Device& device = as_amd(command_queue)->device(); + amd::CommandQueue* defQueue = as_amd(command_queue)->context().defDeviceQueue(device); + cl_command_queue queue = defQueue ? as_cl(defQueue) : NULL; + return amd::clGetInfo(queue, param_value_size, param_value, param_value_size_ret); + } + default: + break; + } + + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +/*! \brief Enable or disable the properties of a command-queue. + * + * \param command_queue specifies the command-queue being queried. + * + * \param properties specifies the new command-queue properties to be applied + * to \a command_queue . + * + * \param enable determines whether the values specified by properties are + * enabled (if enable is CL_TRUE) or disabled (if enable is CL_FALSE) for the + * command-queue . + * + * \param old_properties returns the command-queue properties before they were + * changed by clSetCommandQueueProperty. If \a old_properties is NULL, + * it is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the command-queue properties are successfully updated. + * - CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue. + * - CL_INVALID_VALUE if the values specified in properties are not valid. + * - CL_INVALID_QUEUE_PROPERTIES if values specified in properties are + * not supported by the device. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clSetCommandQueueProperty, + (cl_command_queue command_queue, cl_command_queue_properties properties, + cl_bool enable, cl_command_queue_properties* old_properties)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + *not_null(old_properties) = as_amd(command_queue)->properties().value_; + + if (properties & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) { + clFinish(command_queue); + } + + bool success; + if (enable == CL_TRUE) { + success = as_amd(command_queue)->properties().set(properties); + } else { + success = as_amd(command_queue)->properties().clear(properties); + } + + return success ? CL_SUCCESS : CL_INVALID_QUEUE_PROPERTIES; +} +RUNTIME_EXIT + +/*! @} + * @} + */ diff --git a/opencl/amdocl/cl_common.hpp b/opencl/amdocl/cl_common.hpp new file mode 100644 index 0000000000..a1680030c0 --- /dev/null +++ b/opencl/amdocl/cl_common.hpp @@ -0,0 +1,158 @@ +/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef CL_COMMON_HPP_ +#define CL_COMMON_HPP_ + +#ifdef _WIN32 +#include +#include +#include +#endif +#include + +#include "top.hpp" +#include "vdi_common.hpp" + +//! Helper function to check "properties" parameter in various functions +int checkContextProperties( + const cl_context_properties *properties, + bool* offlineDevices); + +namespace amd { + +template +static inline cl_int +clGetInfo( + T& field, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret) +{ + const void *valuePtr; + size_t valueSize; + + std::tie(valuePtr, valueSize) + = detail::ParamInfo::type>::get(field); + + *not_null(param_value_size_ret) = valueSize; + + cl_int ret = CL_SUCCESS; + if (param_value != NULL && param_value_size < valueSize) { + if ((param_value_size == 0) || !std::is_pointer() || !std::is_same::type>::type, char>()) { + return CL_INVALID_VALUE; + } + // For char* and char[] params, we will at least fill up to + // param_value_size, then return an error. + valueSize = param_value_size; + static_cast(param_value)[--valueSize] = '\0'; + ret = CL_INVALID_VALUE; + } + + if (param_value != NULL) { + ::memcpy(param_value, valuePtr, valueSize); + if (param_value_size > valueSize) { + ::memset(static_cast
(param_value) + valueSize, + '\0', param_value_size - valueSize); + } + } + + return ret; +} + +static inline cl_int +clSetEventWaitList( + Command::EventWaitList& eventWaitList, + const amd::HostQueue& hostQueue, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list) +{ + if ((num_events_in_wait_list == 0 && event_wait_list != NULL) + || (num_events_in_wait_list != 0 && event_wait_list == NULL)) { + return CL_INVALID_EVENT_WAIT_LIST; + } + + while (num_events_in_wait_list-- > 0) { + cl_event event = *event_wait_list++; + Event* amdEvent = as_amd(event); + if (!is_valid(event)) { + return CL_INVALID_EVENT_WAIT_LIST; + } + if (&hostQueue.context() != &amdEvent->context()) { + return CL_INVALID_CONTEXT; + } + if ((amdEvent->command().queue() != &hostQueue) && !amdEvent->notifyCmdQueue()) { + return CL_INVALID_EVENT_WAIT_LIST; + } + eventWaitList.push_back(amdEvent); + } + return CL_SUCCESS; +} + +//! Common function declarations for CL-external graphics API interop +cl_int clEnqueueAcquireExtObjectsAMD(cl_command_queue command_queue, + cl_uint num_objects, const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, + cl_event* event, cl_command_type cmd_type); +cl_int clEnqueueReleaseExtObjectsAMD(cl_command_queue command_queue, + cl_uint num_objects, const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, + cl_event* event, cl_command_type cmd_type); + +} // namespace amd + +extern "C" { + +#if defined(CL_VERSION_1_1) +extern CL_API_ENTRY cl_int CL_API_CALL +clSetCommandQueueProperty( + cl_command_queue command_queue, + cl_command_queue_properties properties, + cl_bool enable, + cl_command_queue_properties *old_properties) CL_API_SUFFIX__VERSION_1_0; +#endif // CL_VERSION_1_1 + +extern CL_API_ENTRY cl_mem CL_API_CALL +clConvertImageAMD( + cl_context context, + cl_mem image, + const cl_image_format * image_format, + cl_int * errcode_ret); + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateBufferFromImageAMD( + cl_context context, + cl_mem image, + cl_int * errcode_ret); + +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithAssemblyAMD( + cl_context context, + cl_uint count, + const char ** strings, + const size_t * lengths, + cl_int * errcode_ret); + +} // extern "C" + +//! \endcond + +#endif /*CL_COMMON_HPP_*/ diff --git a/opencl/amdocl/cl_context.cpp b/opencl/amdocl/cl_context.cpp new file mode 100644 index 0000000000..3b68a10bd5 --- /dev/null +++ b/opencl/amdocl/cl_context.cpp @@ -0,0 +1,558 @@ +/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include "vdi_common.hpp" +#include "platform/context.hpp" +#include "device/device.hpp" +#include "platform/runtime.hpp" +#include "platform/agent.hpp" +#ifdef _WIN32 +#include "cl_d3d9_amd.hpp" +#include "cl_d3d10_amd.hpp" +#include "cl_d3d11_amd.hpp" +#endif // _WIN32 +#include "cl_kernel_info_amd.h" +#include "cl_profile_amd.h" +#include "cl_platform_amd.h" +#include "cl_sdi_amd.h" +#include "cl_thread_trace_amd.h" +#include "cl_p2p_amd.h" + +#include +#include +#include "CL/cl_gl.h" + +/*! \addtogroup API + * @{ + * + * \addtogroup CL_Contexts + * @{ + */ + +/*! \brief Create an OpenCL context. + * + * An OpenCL context is created with one or more devices. Contexts are used by + * the OpenCL runtime for managing objects such as command-queues, memory, + * program and kernel objects and for executing kernels on one or more devices + * specified in the context. + * + * \param properties is reserved and must be zero. + * + * \param num_devices is the number of devices specified in the \a devices + * argument. + * + * \param devices is a pointer to a list of unique devices returned by + * clGetDevices. If more than one device is specified in devices, + * a selection criteria may be applied to determine if the list of devices + * specified can be used together to create a context. + * + * \param pfn_notify is a callback function that can be registered by the + * application. This callback function will be used by the runtime to report + * information on errors that occur in this context. This callback function + * may be called asynchronously by the runtime. If \a pfn_notify is NULL, + * no callback function is registered. + * + * \param user_data will be passed as the user_data argument when \a pfn_notify + * is called. \a user_data can be NULL. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A valid non-zero context and errcode_ret is set to CL_SUCCESS + * if the context is created successfully or NULL with the following + * error values stored in \a errcode_ret: + * - CL_INVALID_VALUE if \a properties is not zero. + * - CL_INVALID_VALUE if \a devices is NULL. + * - CL_INVALID_VALUE if \a num_devices is equal to zero. + * - CL_INVALID_DEVICE if \a devices contains an invalid device. + * - CL_INVALID_DEVICE_LIST if more than one device is specified in + * \a devices and the list of devices specified cannot be used together + * to create a context. + * - CL_DEVICE_NOT_AVAILABLE if a device in \a devices is currently not + * available even though the device was returned by clGetDevices. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY_RET(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)) { + cl_int errcode; + amd::Context::Info info; + + errcode = amd::Context::checkProperties(properties, &info); + if (CL_SUCCESS != errcode) { + *not_null(errcode_ret) = errcode; + return (cl_context)0; + } + + if (num_devices == 0 || devices == NULL) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_context)0; + } + + std::vector devices_; + for (cl_uint i = 0; i < num_devices; ++i) { + // FIXME_lmoriche: Set errcode_ret to CL_DEVICE_NOT_AVAILABLE if a + // device in devices is no longer available. + cl_device_id device = devices[i]; + + if (!is_valid(device)) { + *not_null(errcode_ret) = CL_INVALID_DEVICE; + return (cl_context)0; + } + devices_.push_back(as_amd(device)); + } + + amd::Context* context = new amd::Context(devices_, info); + if (context == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_context)0; + } + + if (CL_SUCCESS != (errcode = context->create(properties))) { + context->release(); + *not_null(errcode_ret) = errcode; + return (cl_context)0; + } + + if (amd::Agent::shouldPostContextEvents()) { + amd::Agent::postContextCreate(as_cl(context)); + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(context); +} +RUNTIME_EXIT + +/*! \brief Create an OpenCL context from a device type that identifies the + * specific device(s) to use. + * + * \param properties is reserved and must be zero. + * + * \param device_type is a bit-field that identifies the type of device. + * + * \param pfn_notify described in clCreateContext. + * + * \param user_data described in clCreateContext. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A valid non-zero context and errcode_ret is set to CL_SUCCESS + * if the context is created successfully or NULL with the following error + * values stored in errcode_ret: + * - CL_INVALID_VALUE if \a properties is not zero. + * - CL_INVALID_DEVICE_TYPE if \a device_type is not a valid value. + * - CL_DEVICE_NOT_AVAILABLE if no devices that match \a device_type + * are currently available. + * - CL_DEVICE_NOT_FOUND if no devices that match \a device_type were found. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY_RET(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)) { + amd::Context::Info info; + cl_int errcode = amd::Context::checkProperties(properties, &info); + if (errcode != CL_SUCCESS) { + *not_null(errcode_ret) = errcode; + return (cl_context)0; + } + + // Get the devices of the given type. + cl_uint num_devices; + bool offlineDevices = (info.flags_ & amd::Context::OfflineDevices) ? true : false; + if (!amd::Device::getDeviceIDs(device_type, 0, NULL, &num_devices, offlineDevices)) { + *not_null(errcode_ret) = CL_DEVICE_NOT_FOUND; + return (cl_context)0; + } + + assert(num_devices > 0 && "Should have returned an error!"); + cl_device_id* devices = (cl_device_id*)alloca(num_devices * sizeof(cl_device_id)); + + if (!amd::Device::getDeviceIDs(device_type, num_devices, devices, NULL, offlineDevices)) { + *not_null(errcode_ret) = CL_DEVICE_NOT_FOUND; + return (cl_context)0; + } + + // Create a new context with the devices + cl_context context = + clCreateContext(properties, num_devices, devices, pfn_notify, user_data, errcode_ret); + + return context; +} +RUNTIME_EXIT + +/*! \brief Increment the context reference count. + * + * \return One of the following values: + * - CL_INVALID_CONTEXT if context is not a valid OpenCL context. + * - CL_SUCCESS if the function is executed successfully. + * + * clCreateContext and clCreateContextFromType perform an implicit retain. + * This is very helpful for 3rd party libraries, which typically get a context + * passed to them by the application. + * However, it is possible that the application may delete the context without + * informing the library. Allowing functions to attach to (i.e. retain) and + * release a context solves the problem of a context being used by a library + * no longer being valid. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clRetainContext, (cl_context context)) { + if (!is_valid(context)) { + return CL_INVALID_CONTEXT; + } + as_amd(context)->retain(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Decrement the context reference count. + * + * \return One of the following values: + * - CL_INVALID_CONTEXT if context is not a valid OpenCL context. + * - CL_SUCCESS if the function is executed successfully. + * + * After the context reference count becomes zero and all the objects attached + * to context (such as memory objects, command-queues) are released, + * the context is deleted. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clReleaseContext, (cl_context context)) { + if (!is_valid(context)) { + return CL_INVALID_CONTEXT; + } + as_amd(context)->release(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Query information about a context. + * + * \param context specifies the OpenCL context being queried. + * + * \param param_name is an enum that specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result being + * queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size specifies the size in bytes of memory pointed to by + * \a param_value. This size must be greater than or equal to the size of + * return type. + * + * \param param_value_size_ret returns the actual size in bytes of data being + * queried by \a param_value. If \a param_value_size_ret is NULL, + * it is ignored. + * + * \return One of the following values: + * - CL_INVALID_CONTEXT if context is not a valid context. + * - CL_INVALID_VALUE if \a param_name is not one of the supported values + * or if size in bytes specified by \a param_value_size is < size of return + * type and \a param_value is not a NULL value. + * - CL_SUCCESS if the function is executed successfully. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(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)) { + if (!is_valid(context)) { + return CL_INVALID_CONTEXT; + } + + switch (param_name) { + case CL_CONTEXT_REFERENCE_COUNT: { + cl_uint count = as_amd(context)->referenceCount(); + return amd::clGetInfo(count, param_value_size, param_value, param_value_size_ret); + } + case CL_CONTEXT_NUM_DEVICES: { + cl_uint numDevices = (cl_uint)as_amd(context)->devices().size(); + return amd::clGetInfo(numDevices, param_value_size, param_value, param_value_size_ret); + } + case CL_CONTEXT_DEVICES: { + const std::vector& devices = as_amd(context)->devices(); + size_t numDevices = devices.size(); + size_t valueSize = numDevices * sizeof(cl_device_id*); + + if (param_value != NULL && param_value_size < valueSize) { + return CL_INVALID_VALUE; + } + *not_null(param_value_size_ret) = valueSize; + if (param_value != NULL) { + cl_device_id* device_list = (cl_device_id*)param_value; + for (const auto& it : devices) { + *device_list++ = const_cast(as_cl(it)); + } + } + return CL_SUCCESS; + } + case CL_CONTEXT_PROPERTIES: { + const amd::Context* amdContext = as_amd(context); + size_t valueSize = amdContext->info().propertiesSize_; + + if (param_value != NULL && param_value_size < valueSize) { + return CL_INVALID_VALUE; + } + *not_null(param_value_size_ret) = valueSize; + if ((param_value != NULL) && (valueSize != 0)) { + ::memcpy(param_value, amdContext->properties(), valueSize); + } + return CL_SUCCESS; + } +#ifdef _WIN32 + case CL_CONTEXT_D3D10_DEVICE_KHR: { + // Not defined in the ext.spec, but tested in the conf.test + // Guessing functionality from the test... + if (param_value != NULL && param_value_size < sizeof(void*)) { + return CL_INVALID_VALUE; + } + const amd::Context* amdContext = as_amd(context); + if (!(amdContext->info().flags_ & amd::Context::D3D10DeviceKhr)) { + return CL_INVALID_VALUE; + } + *not_null(param_value_size_ret) = sizeof(intptr_t); + if (param_value != NULL) { + *(intptr_t*)param_value = + reinterpret_cast(amdContext->info().hDev_[amd::Context::D3D10DeviceKhrIdx]); + } + return CL_SUCCESS; + } + case CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR: { + if (param_value != NULL && param_value_size < sizeof(cl_bool)) { + return CL_INVALID_VALUE; + } + *not_null(param_value_size_ret) = sizeof(cl_bool); + if (param_value != NULL) { + *(cl_bool*)param_value = CL_TRUE; + } + return CL_SUCCESS; + } + case CL_CONTEXT_D3D11_DEVICE_KHR: { + // Not defined in the ext.spec, but tested in the conf.test + // Guessing functionality from the test... + if (param_value != NULL && param_value_size < sizeof(void*)) { + return CL_INVALID_VALUE; + } + const amd::Context* amdContext = as_amd(context); + if (!(amdContext->info().flags_ & amd::Context::D3D11DeviceKhr)) { + return CL_INVALID_VALUE; + } + *not_null(param_value_size_ret) = sizeof(intptr_t); + if (param_value != NULL) { + *(intptr_t*)param_value = + reinterpret_cast(amdContext->info().hDev_[amd::Context::D3D11DeviceKhrIdx]); + } + return CL_SUCCESS; + } + case CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR: { + if (param_value != NULL && param_value_size < sizeof(cl_bool)) { + return CL_INVALID_VALUE; + } + *not_null(param_value_size_ret) = sizeof(cl_bool); + if (param_value != NULL) { + *(cl_bool*)param_value = CL_TRUE; + } + return CL_SUCCESS; + } + case CL_CONTEXT_ADAPTER_D3D9_KHR: { + if (param_value != NULL && param_value_size < sizeof(void*)) { + return CL_INVALID_VALUE; + } + const amd::Context* amdContext = as_amd(context); + if (!(amdContext->info().flags_ & amd::Context::D3D9DeviceKhr)) { + return CL_INVALID_VALUE; + } + *not_null(param_value_size_ret) = sizeof(intptr_t); + if (param_value != NULL) { + *(intptr_t*)param_value = + reinterpret_cast(amdContext->info().hDev_[amd::Context::D3D9DeviceKhrIdx]); + } + return CL_SUCCESS; + } + case CL_CONTEXT_ADAPTER_D3D9EX_KHR: { + if (param_value != NULL && param_value_size < sizeof(void*)) { + return CL_INVALID_VALUE; + } + const amd::Context* amdContext = as_amd(context); + if (!(amdContext->info().flags_ & amd::Context::D3D9DeviceEXKhr)) { + return CL_INVALID_VALUE; + } + *not_null(param_value_size_ret) = sizeof(intptr_t); + if (param_value != NULL) { + *(intptr_t*)param_value = + reinterpret_cast(amdContext->info().hDev_[amd::Context::D3D9DeviceEXKhrIdx]); + } + return CL_SUCCESS; + } + case CL_CONTEXT_ADAPTER_DXVA_KHR: { + if (param_value != NULL && param_value_size < sizeof(void*)) { + return CL_INVALID_VALUE; + } + const amd::Context* amdContext = as_amd(context); + if (!(amdContext->info().flags_ & amd::Context::D3D9DeviceVAKhr)) { + return CL_INVALID_VALUE; + } + *not_null(param_value_size_ret) = sizeof(intptr_t); + if (param_value != NULL) { + *(intptr_t*)param_value = + reinterpret_cast(amdContext->info().hDev_[amd::Context::D3D9DeviceVAKhrIdx]); + } + return CL_SUCCESS; + } +#endif //_WIN32 + default: + break; + } + + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +/*! \brief returns the address of the extension function named by + * funcname for a given platform. The pointer returned should be cast + * to a function pointer type matching the extension functions definition + * defined in the appropriate extension specification and header file. + * A return value of NULL indicates that the specified function does not + * exist for the implementation or platform is not a valid platform. + * A non-NULL return value for \a clGetExtensionFunctionAddressForPlatform + * does not guarantee that an extension function is actually supported by + * the platform. The application must also make a corresponding query using + * \a clGetPlatformInfo(platform, CL_PLATFORM_EXTENSIONS, ... ) or + * \a clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, ... ) to determine if + * an extension is supported by the OpenCL implementation. + * + * \version 1.2r07 + */ +CL_API_ENTRY void* CL_API_CALL clGetExtensionFunctionAddressForPlatform(cl_platform_id platform, + const char* funcname) { + if (platform != NULL && platform != AMD_PLATFORM) { + return NULL; + } + + return clGetExtensionFunctionAddress(funcname); +} + +CL_API_ENTRY void* CL_API_CALL clGetExtensionFunctionAddress(const char* func_name) { +#define CL_EXTENSION_ENTRYPOINT_CHECK(name) \ + if (!strcmp(func_name, #name)) return reinterpret_cast(name); +#define CL_EXTENSION_ENTRYPOINT_CHECK2(name1, name2) \ + if (!strcmp(func_name, #name1)) return reinterpret_cast(name2); + + switch (func_name[2]) { + case 'C': + CL_EXTENSION_ENTRYPOINT_CHECK(clCreateEventFromGLsyncKHR); + CL_EXTENSION_ENTRYPOINT_CHECK(clCreatePerfCounterAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clCreateThreadTraceAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clCreateFromGLBuffer); + CL_EXTENSION_ENTRYPOINT_CHECK(clCreateFromGLTexture2D); + CL_EXTENSION_ENTRYPOINT_CHECK(clCreateFromGLTexture3D); + CL_EXTENSION_ENTRYPOINT_CHECK(clCreateFromGLRenderbuffer); +#ifdef _WIN32 + CL_EXTENSION_ENTRYPOINT_CHECK(clCreateFromD3D10BufferKHR); + CL_EXTENSION_ENTRYPOINT_CHECK(clCreateFromD3D10Texture2DKHR); + CL_EXTENSION_ENTRYPOINT_CHECK(clCreateFromD3D10Texture3DKHR); + CL_EXTENSION_ENTRYPOINT_CHECK(clCreateFromDX9MediaSurfaceKHR); +#endif //_WIN32 + CL_EXTENSION_ENTRYPOINT_CHECK(clConvertImageAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clCreateBufferFromImageAMD); +#if defined(cl_khr_il_program) || defined(CL_VERSION_2_1) + CL_EXTENSION_ENTRYPOINT_CHECK2(clCreateProgramWithILKHR,clCreateProgramWithIL); +#endif // defined(cl_khr_il_program) || defined(CL_VERSION_2_1) +#if cl_amd_assembly_program + CL_EXTENSION_ENTRYPOINT_CHECK(clCreateProgramWithAssemblyAMD); +#endif // cl_amd_assembly_program + break; + case 'D': + break; + case 'E': + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueBeginPerfCounterAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueEndPerfCounterAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueAcquireGLObjects); + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueReleaseGLObjects); + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueBindThreadTraceBufferAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueThreadTraceCommandAMD); +#ifdef _WIN32 + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueAcquireD3D10ObjectsKHR); + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueReleaseD3D10ObjectsKHR); + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueAcquireDX9MediaSurfacesKHR); + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueReleaseDX9MediaSurfacesKHR); +#endif //_WIN32 + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueWaitSignalAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueWriteSignalAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueMakeBuffersResidentAMD); +#if cl_amd_copy_buffer_p2p + CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueCopyBufferP2PAMD); +#endif // cl_amd_copy_buffer_p2p + break; + case 'G': + CL_EXTENSION_ENTRYPOINT_CHECK(clGetKernelInfoAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clGetPerfCounterInfoAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clGetGLObjectInfo); + CL_EXTENSION_ENTRYPOINT_CHECK(clGetGLTextureInfo); + CL_EXTENSION_ENTRYPOINT_CHECK(clGetGLContextInfoKHR); + CL_EXTENSION_ENTRYPOINT_CHECK(clGetThreadTraceInfoAMD); +#ifdef _WIN32 + CL_EXTENSION_ENTRYPOINT_CHECK(clGetDeviceIDsFromD3D10KHR); + CL_EXTENSION_ENTRYPOINT_CHECK(clGetDeviceIDsFromDX9MediaAdapterKHR); + CL_EXTENSION_ENTRYPOINT_CHECK(clGetPlaneFromImageAMD); +#endif //_WIN32 +#if defined(cl_khr_sub_groups) || defined(CL_VERSION_2_1) + CL_EXTENSION_ENTRYPOINT_CHECK2(clGetKernelSubGroupInfoKHR,clGetKernelSubGroupInfo); +#endif // defined(cl_khr_sub_groups) || defined(CL_VERSION_2_1) + break; + case 'I': + CL_EXTENSION_ENTRYPOINT_CHECK(clIcdGetPlatformIDsKHR); + break; + case 'R': + CL_EXTENSION_ENTRYPOINT_CHECK(clReleasePerfCounterAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clRetainPerfCounterAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clReleaseThreadTraceAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clRetainThreadTraceAMD); + break; + case 'S': + CL_EXTENSION_ENTRYPOINT_CHECK(clSetThreadTraceParamAMD); + CL_EXTENSION_ENTRYPOINT_CHECK(clSetDeviceClockModeAMD); + break; + case 'U': + CL_EXTENSION_ENTRYPOINT_CHECK(clUnloadPlatformAMD); + default: + break; + } + + return NULL; +} + +RUNTIME_ENTRY(cl_int, clTerminateContextKHR, (cl_context context)) { return CL_INVALID_CONTEXT; } +RUNTIME_EXIT + + +/*! @} + * @} + */ diff --git a/opencl/amdocl/cl_counter.cpp b/opencl/amdocl/cl_counter.cpp new file mode 100644 index 0000000000..c885723c46 --- /dev/null +++ b/opencl/amdocl/cl_counter.cpp @@ -0,0 +1,127 @@ +/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include + +#include "platform/object.hpp" +#include "platform/context.hpp" +#include "platform/command.hpp" +#include "platform/counter.hpp" + +#ifdef cl_amd_atomic_counters + +/*! \addtogroup API + * @{ + * \addtogroup CL_Counters + * + * Counter objects ... + * + * @{ + */ + +/*! \brief + * + * \version 1.1r18 + */ +RUNTIME_ENTRY_RET(cl_counter_amd, clCreateCounterAMD, + (cl_context context, cl_counter_flags_amd flags, cl_uint value, + cl_int* errcode_ret)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + return (cl_counter_amd)0; +} +RUNTIME_EXIT + +/*! \brief + * + * \version 1.1r18 + */ +RUNTIME_ENTRY(cl_int, clGetCounterInfoAMD, + (cl_counter_amd counter, cl_counter_info_amd param_name, size_t param_value_size, + void* param_value, size_t* param_value_size_ret)) { + return CL_INVALID_COUNTER_AMD; +} +RUNTIME_EXIT + +/*! \brief Increment the counter reference count. + * + * \return CL_SUCCESS if the function is executed successfully. It returns + * CL_INVALID_COUNTER if \a counter is not a valid counter object. + * + * The OpenCL commands that return a counter perform an implicit retain. + * + * \version 1.1r18 + */ +RUNTIME_ENTRY(cl_int, clRetainCounterAMD, (cl_counter_amd counter)) { + if (!is_valid(counter)) { + return CL_INVALID_COUNTER_AMD; + } + as_amd(counter)->retain(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Decrement the counter reference count. + * + * \return CL_SUCCESS if the function is executed successfully. It returns + * CL_INVALID_EVENT if \a counter is not a valid counter object. + * + * The counter object is deleted once the reference count becomes zero. + * + * \version 1.1r18 + */ +RUNTIME_ENTRY(cl_int, clReleaseCounterAMD, (cl_counter_amd counter)) { + if (!is_valid(counter)) { + return CL_INVALID_COUNTER_AMD; + } + as_amd(counter)->release(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief + * + * \version 1.1r18 + */ +RUNTIME_ENTRY(cl_int, clEnqueueReadCounterAMD, + (cl_command_queue command_queue, cl_counter_amd counter, cl_bool blocking_read, + cl_uint* value, cl_uint num_events_in_wait_list, const cl_event* event_wait_list, + cl_event* event)) { + return CL_INVALID_COUNTER_AMD; +} +RUNTIME_EXIT + +/*! \brief + * + * \version 1.1r18 + */ +RUNTIME_ENTRY(cl_int, clEnqueueWriteCounterAMD, + (cl_command_queue command_queue, cl_counter_amd counter, cl_bool blocking_write, + cl_uint value, cl_uint num_events_in_wait_list, const cl_event* event_wait_list, + cl_event* event)) { + return CL_INVALID_COUNTER_AMD; +} +RUNTIME_EXIT + +/*! @} + * @} + */ + +#endif // cl_amd_atomic_counters diff --git a/opencl/amdocl/cl_d3d10.cpp b/opencl/amdocl/cl_d3d10.cpp new file mode 100644 index 0000000000..0402f6e051 --- /dev/null +++ b/opencl/amdocl/cl_d3d10.cpp @@ -0,0 +1,1451 @@ +/* Copyright (c) 2009 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifdef _WIN32 + +#include "top.hpp" + +#include "cl_common.hpp" +#include "cl_d3d10_amd.hpp" +#include "platform/command.hpp" + +#include +#include + + +/*! \addtogroup API + * @{ + * + * \addtogroup CL_D3D10_Interops + * + * This section discusses OpenCL functions that allow applications to use Direct3D 10 + * resources (buffers/textures) as OpenCL memory objects. This allows efficient sharing of + * data between OpenCL and Direct3D 10. The OpenCL API can be used to execute kernels that + * read and/or write memory objects that are also the Direct3D resources. + * An OpenCL image object can be created from a D3D10 texture object. An + * OpenCL buffer object can be created from a D3D10 buffer object (index/vertex). + * + * @} + * \addtogroup clGetDeviceIDsFromD3D10KHR + * @{ + */ + +RUNTIME_ENTRY(cl_int, clGetDeviceIDsFromD3D10KHR, + (cl_platform_id platform, cl_d3d10_device_source_khr d3d_device_source, + void* d3d_object, cl_d3d10_device_set_khr d3d_device_set, cl_uint num_entries, + cl_device_id* devices, cl_uint* num_devices)) { + cl_int errcode; + ID3D10Device* d3d10_device = NULL; + cl_device_id* gpu_devices; + cl_uint num_gpu_devices = 0; + bool create_d3d10Device = false; + static const bool VALIDATE_ONLY = true; + HMODULE d3d10Module = NULL; + + if (platform != NULL && platform != AMD_PLATFORM) { + LogWarning("\"platrform\" is not a valid AMD platform"); + return CL_INVALID_PLATFORM; + } + if (((num_entries > 0 || num_devices == NULL) && devices == NULL) || + (num_entries == 0 && devices != NULL)) { + return CL_INVALID_VALUE; + } + // Get GPU devices + errcode = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 0, NULL, &num_gpu_devices); + if (errcode != CL_SUCCESS && errcode != CL_DEVICE_NOT_FOUND) { + return CL_INVALID_VALUE; + } + + if (!num_gpu_devices) { + *not_null(num_devices) = 0; + return CL_DEVICE_NOT_FOUND; + } + + switch (d3d_device_source) { + case CL_D3D10_DEVICE_KHR: + d3d10_device = static_cast(d3d_object); + break; + case CL_D3D10_DXGI_ADAPTER_KHR: { + typedef HRESULT(WINAPI * LPD3D10CREATEDEVICE)(IDXGIAdapter*, D3D10_DRIVER_TYPE, HMODULE, UINT, + UINT32, ID3D10Device**); + static LPD3D10CREATEDEVICE dynamicD3D10CreateDevice = NULL; + + d3d10Module = LoadLibrary("D3D10.dll"); + if (d3d10Module == NULL) { + return CL_INVALID_PLATFORM; + } + + dynamicD3D10CreateDevice = + (LPD3D10CREATEDEVICE)GetProcAddress(d3d10Module, "D3D10CreateDevice"); + + IDXGIAdapter* dxgi_adapter = static_cast(d3d_object); + HRESULT hr = dynamicD3D10CreateDevice(dxgi_adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, + D3D10_SDK_VERSION, &d3d10_device); + if (SUCCEEDED(hr) && (NULL != d3d10_device)) { + create_d3d10Device = true; + } else { + FreeLibrary(d3d10Module); + return CL_INVALID_VALUE; + } + } break; + default: + LogWarning("\"d3d_device_source\" is invalid"); + return CL_INVALID_VALUE; + } + + switch (d3d_device_set) { + case CL_PREFERRED_DEVICES_FOR_D3D10_KHR: + case CL_ALL_DEVICES_FOR_D3D10_KHR: { + gpu_devices = (cl_device_id*)alloca(num_gpu_devices * sizeof(cl_device_id)); + + errcode = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, num_gpu_devices, gpu_devices, NULL); + if (errcode != CL_SUCCESS) { + break; + } + + void* external_device[amd::Context::DeviceFlagIdx::LastDeviceFlagIdx] = {}; + external_device[amd::Context::DeviceFlagIdx::D3D10DeviceKhrIdx] = d3d10_device; + + std::vector compatible_devices; + for (cl_uint i = 0; i < num_gpu_devices; ++i) { + cl_device_id device = gpu_devices[i]; + if (is_valid(device) && + as_amd(device)->bindExternalDevice(amd::Context::Flags::D3D10DeviceKhr, external_device, + NULL, VALIDATE_ONLY)) { + compatible_devices.push_back(as_amd(device)); + } + } + if (compatible_devices.size() == 0) { + *not_null(num_devices) = 0; + errcode = CL_DEVICE_NOT_FOUND; + break; + } + + auto it = compatible_devices.cbegin(); + cl_uint compatible_count = std::min(num_entries, (cl_uint)compatible_devices.size()); + + while (compatible_count--) { + *devices++ = as_cl(*it++); + --num_entries; + } + while (num_entries--) { + *devices++ = (cl_device_id)0; + } + + *not_null(num_devices) = (cl_uint)compatible_devices.size(); + } break; + + default: + LogWarning("\"d3d_device_set\" is invalid"); + errcode = CL_INVALID_VALUE; + } + + if (create_d3d10Device) { + d3d10_device->Release(); + FreeLibrary(d3d10Module); + } + return errcode; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clCreateFromD3D10BufferKHR + * @{ + */ + +/*! \brief Creates an OpenCL buffer object from a Direct3D 10 resource. + * + * \param context is a valid OpenCL context. + * + * \param flags is a bit-field that is used to specify usage information. + * Only CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY and CL_MEM_READ_WRITE values + * can be used. + * + * \param pD3DResource is a valid pointer to a D3D10 resource of type ID3D10Buffer. + * + * \return valid non-zero OpenCL buffer object and \a errcode_ret is set + * to CL_SUCCESS if the buffer object is created successfully. It returns a NULL + * value with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a context is not a valid context or if Direct3D 10 + * interoperatbility has not been initialized between context and the ID3D10Device + * from which pD3DResource was created. + * - CL_INVALID_VALUE if values specified in \a clFlags are not valid. + * - CL_INVALID_D3D_RESOURCE if \a pD3DResource is not of type ID3D10Buffer. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33? + */ + +RUNTIME_ENTRY_RET(cl_mem, clCreateFromD3D10BufferKHR, + (cl_context context, cl_mem_flags flags, ID3D10Buffer* pD3DResource, + cl_int* errcode_ret)) { + cl_mem clMemObj = NULL; + + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return clMemObj; + } + if (!flags) flags = CL_MEM_READ_WRITE; + if (!(((flags & CL_MEM_READ_ONLY) == CL_MEM_READ_ONLY) || + ((flags & CL_MEM_WRITE_ONLY) == CL_MEM_WRITE_ONLY) || + ((flags & CL_MEM_READ_WRITE) == CL_MEM_READ_WRITE))) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return clMemObj; + } + if (!pD3DResource) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("parameter \"pD3DResource\" is a NULL pointer"); + return clMemObj; + } + return ( + amd::clCreateBufferFromD3D10ResourceAMD(*as_amd(context), flags, pD3DResource, errcode_ret)); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clCreateImageFromD3D10Resource + * @{ + */ + +/*! \brief Create an OpenCL 2D or 3D image object from a D3D10 resource. + * + * \param context is a valid OpenCL context. + * + * \param flags is a bit-field that is used to specify usage information. + * Only CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY and CL_MEM_READ_WRITE values + * can be used. + * + * \param pD3DResource is a valid pointer to a D3D10 resource of type + * ID3D10Texture2D, ID3D10Texture2D, or ID3D10Texture3D. + * If pD3DResource is of type ID3D10Texture1D then the created image object + * will be a 1D mipmapped image object. + * If pD3DResource is of type ID3D10Texture2D and was not created with flag + * D3D10_RESOURCE_MISC_TEXTURECUBE then the created image object will be a + * 2D mipmapped image object. + * If pD3DResource is of type ID3D10Texture2D and was created with flag + * D3D10_RESOURCE_MISC_TEXTURECUBE then the created image object will be + * a cubemap mipmapped image object. + * errocde_ret returns CL_INVALID_D3D_RESOURCE if an OpenCL memory object has + * already been created from pD3DResource in context. + * If pD3DResource is of type ID3D10Texture3D then the created image object will + * be a 3D mipmapped imageobject. + * + * \return valid non-zero OpenCL image object and \a errcode_ret is set + * to CL_SUCCESS if the image object is created successfully. It returns a NULL + * value with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a context is not a valid context or if Direct3D 10 + * interoperatbility has not been initialized between context and the ID3D10Device + * from which pD3DResource was created. + * - CL_INVALID_VALUE if values specified in \a flags are not valid. + * - CL_INVALID_D3D_RESOURCE if \a pD3DResource is not of type ID3D10Texture1D, + * ID3D10Texture2D, or ID3D10Texture3D. + * - CL_INVALID_D3D_RESOURCE if an OpenCL memory object has already been created + * from \a pD3DResource in context. + * - CL_INVALID_IMAGE_FORMAT if the Direct3D 10 texture format does not map + * to an appropriate OpenCL image format. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r48? + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateImageFromD3D10Resource, + (cl_context context, cl_mem_flags flags, ID3D10Resource* pD3DResource, + UINT subresource, int* errcode_ret, UINT dimension)) { + cl_mem clMemObj = NULL; + + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return clMemObj; + } + if (!flags) flags = CL_MEM_READ_WRITE; + if (!(((flags & CL_MEM_READ_ONLY) == CL_MEM_READ_ONLY) || + ((flags & CL_MEM_WRITE_ONLY) == CL_MEM_WRITE_ONLY) || + ((flags & CL_MEM_READ_WRITE) == CL_MEM_READ_WRITE))) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return clMemObj; + } + if (!pD3DResource) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("parameter \"pD3DResource\" is a NULL pointer"); + return clMemObj; + } + + // Verify context init'ed for interop + ID3D10Device* pDev; + pD3DResource->GetDevice(&pDev); + if (pDev == NULL) { + *not_null(errcode_ret) = CL_INVALID_D3D10_DEVICE_KHR; + LogWarning("Cannot retrieve D3D10 device from D3D10 resource"); + return (cl_mem)0; + } + pDev->Release(); + if (!((*as_amd(context)).info().flags_ & amd::Context::D3D10DeviceKhr)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("\"amdContext\" is not created from D3D10 device"); + return (cl_mem)0; + } + + // Check for image support + const std::vector& devices = as_amd(context)->devices(); + bool supportPass = false; + bool sizePass = false; + for (const auto& it : devices) { + if (it->info().imageSupport_) { + supportPass = true; + } + } + if (!supportPass) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + LogWarning("there are no devices in context to support images"); + return (cl_mem)0; + } + + switch (dimension) { +#if 0 + case 1: + return(amd::clCreateImage1DFromD3D10ResourceAMD( + *as_amd(context), + flags, + pD3DResource, + subresource, + errcode_ret)); +#endif // 0 + case 2: + return (amd::clCreateImage2DFromD3D10ResourceAMD(*as_amd(context), flags, pD3DResource, + subresource, errcode_ret)); + case 3: + return (amd::clCreateImage3DFromD3D10ResourceAMD(*as_amd(context), flags, pD3DResource, + subresource, errcode_ret)); + default: + break; + } + + *not_null(errcode_ret) = CL_INVALID_D3D10_RESOURCE_KHR; + return (cl_mem)0; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clCreateFromD3D10Texture2DKHR + * @{ + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateFromD3D10Texture2DKHR, + (cl_context context, cl_mem_flags flags, ID3D10Texture2D* resource, + UINT subresource, cl_int* errcode_ret)) { + return clCreateImageFromD3D10Resource(context, flags, resource, subresource, errcode_ret, 2); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clCreateFromD3D10Texture3DKHR + * @{ + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateFromD3D10Texture3DKHR, + (cl_context context, cl_mem_flags flags, ID3D10Texture3D* resource, + UINT subresource, cl_int* errcode_ret)) { + return clCreateImageFromD3D10Resource(context, flags, resource, subresource, errcode_ret, 3); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clEnqueueAcquireD3D10ObjectsKHR + * @{ + */ +RUNTIME_ENTRY(cl_int, clEnqueueAcquireD3D10ObjectsKHR, + (cl_command_queue command_queue, cl_uint num_objects, const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event)) { + return amd::clEnqueueAcquireExtObjectsAMD(command_queue, num_objects, mem_objects, + num_events_in_wait_list, event_wait_list, event, + CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clEnqueueReleaseD3D10ObjectsKHR + * @{ + */ +RUNTIME_ENTRY(cl_int, clEnqueueReleaseD3D10ObjectsKHR, + (cl_command_queue command_queue, cl_uint num_objects, const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event)) { + return amd::clEnqueueReleaseExtObjectsAMD(command_queue, num_objects, mem_objects, + num_events_in_wait_list, event_wait_list, event, + CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR); +} +RUNTIME_EXIT + + +// +// +// namespace amd +// +// +namespace amd { +/*! @} + * \addtogroup CL-D3D10 interop helper functions + * @{ + */ + + +//******************************************************************* +// +// Internal implementation of CL API functions +// +//******************************************************************* +// +// clCreateBufferFromD3D10ResourceAMD +// +cl_mem clCreateBufferFromD3D10ResourceAMD(Context& amdContext, cl_mem_flags flags, + ID3D10Resource* pD3DResource, int* errcode_ret) { + // Verify pD3DResource is a buffer + D3D10_RESOURCE_DIMENSION rType; + pD3DResource->GetType(&rType); + if (rType != D3D10_RESOURCE_DIMENSION_BUFFER) { + *not_null(errcode_ret) = CL_INVALID_D3D10_RESOURCE_KHR; + return (cl_mem)0; + } + + D3D10Object obj; + int errcode = D3D10Object::initD3D10Object(amdContext, pD3DResource, 0, obj); + if (CL_SUCCESS != errcode) { + *not_null(errcode_ret) = errcode; + return (cl_mem)0; + } + + BufferD3D10* pBufferD3D10 = new (amdContext) BufferD3D10(amdContext, flags, obj); + if (!pBufferD3D10) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_mem)0; + } + if (!pBufferD3D10->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + pBufferD3D10->release(); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(pBufferD3D10); +} +#if 0 +// There is no support for 1D images in the base imagee code +// +// clCreateImage1DFromD3D10ResourceAMD +// +cl_mem clCreateImage1DFromD3D10ResourceAMD( + Context& amdContext, + cl_mem_flags flags, + ID3D10Resource* pD3DResource, + UINT subresource, + int* errcode_ret) +{ + + // Verify the resource is a 1D texture + D3D10_RESOURCE_DIMENSION rType; + pD3DResource->GetType(&rType); + if(rType != D3D10_RESOURCE_DIMENSION_TEXTURE1D) { + *not_null(errcode_ret) = CL_INVALID_D3D10_RESOURCE_KHR; + return (cl_mem) 0; + } + + D3D10Object obj; + int errcode = D3D10Object::initD3D10Object(pD3DResource, subresource, obj); + if(CL_SUCCESS != errcode) + { + *not_null(errcode_ret) = errcode; + return (cl_mem) 0; + } + + Image1DD3D10 *pImage1DD3D10 = new Image1DD3D10(amdContext, flags, obj); + if(!pImage1DD3D10) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_mem) 0; + } + if (!pImage1DD3D10->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + pImage1DD3D10->release(); + return (cl_mem) 0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(pImage1DD3D10); +} +#endif + +// +// clCreateImage2DFromD3D10ResourceAMD +// +cl_mem clCreateImage2DFromD3D10ResourceAMD(Context& amdContext, cl_mem_flags flags, + ID3D10Resource* pD3DResource, UINT subresource, + int* errcode_ret) { + // Verify the resource is a 2D texture + D3D10_RESOURCE_DIMENSION rType; + pD3DResource->GetType(&rType); + if (rType != D3D10_RESOURCE_DIMENSION_TEXTURE2D) { + *not_null(errcode_ret) = CL_INVALID_D3D10_RESOURCE_KHR; + return (cl_mem)0; + } + + D3D10Object obj; + int errcode = D3D10Object::initD3D10Object(amdContext, pD3DResource, subresource, obj); + if (CL_SUCCESS != errcode) { + *not_null(errcode_ret) = errcode; + return (cl_mem)0; + } + + Image2DD3D10* pImage2DD3D10 = new (amdContext) Image2DD3D10(amdContext, flags, obj); + if (!pImage2DD3D10) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_mem)0; + } + if (!pImage2DD3D10->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + pImage2DD3D10->release(); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(pImage2DD3D10); +} + +// +// clCreateImage2DFromD3D10ResourceAMD +// +cl_mem clCreateImage3DFromD3D10ResourceAMD(Context& amdContext, cl_mem_flags flags, + ID3D10Resource* pD3DResource, UINT subresource, + int* errcode_ret) { + // Verify the resource is a 2D texture + D3D10_RESOURCE_DIMENSION rType; + pD3DResource->GetType(&rType); + if (rType != D3D10_RESOURCE_DIMENSION_TEXTURE3D) { + *not_null(errcode_ret) = CL_INVALID_D3D10_RESOURCE_KHR; + return (cl_mem)0; + } + + D3D10Object obj; + int errcode = D3D10Object::initD3D10Object(amdContext, pD3DResource, subresource, obj); + if (CL_SUCCESS != errcode) { + *not_null(errcode_ret) = errcode; + return (cl_mem)0; + } + + Image3DD3D10* pImage3DD3D10 = new (amdContext) Image3DD3D10(amdContext, flags, obj); + if (!pImage3DD3D10) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_mem)0; + } + if (!pImage3DD3D10->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + pImage3DD3D10->release(); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(pImage3DD3D10); +} + +// +// Helper function SyncD3D10Objects +// +void SyncD3D10Objects(std::vector& memObjects) { + Memory*& mem = memObjects.front(); + if (!mem) { + LogWarning("\nNULL memory object\n"); + return; + } + InteropObject* interop = mem->getInteropObj(); + if (!interop) { + LogWarning("\nNULL interop object\n"); + return; + } + D3D10Object* d3d10Obj = interop->asD3D10Object(); + if (!d3d10Obj) { + LogWarning("\nNULL D3D10 object\n"); + return; + } + ID3D10Query* query = d3d10Obj->getQuery(); + if (!query) { + LogWarning("\nNULL ID3D10Query\n"); + return; + } + query->End(); + BOOL data = FALSE; + while (S_OK != query->GetData(&data, sizeof(BOOL), 0)) { + } +} + +// +// Class D3D10Object implementation +// +size_t D3D10Object::getElementBytes(DXGI_FORMAT dxgiFmt) { + size_t bytesPerPixel; + + switch (dxgiFmt) { + case DXGI_FORMAT_R32G32B32A32_TYPELESS: + case DXGI_FORMAT_R32G32B32A32_FLOAT: + case DXGI_FORMAT_R32G32B32A32_UINT: + case DXGI_FORMAT_R32G32B32A32_SINT: + bytesPerPixel = 16; + break; + + case DXGI_FORMAT_R32G32B32_TYPELESS: + case DXGI_FORMAT_R32G32B32_FLOAT: + case DXGI_FORMAT_R32G32B32_UINT: + case DXGI_FORMAT_R32G32B32_SINT: + bytesPerPixel = 12; + break; + + case DXGI_FORMAT_R16G16B16A16_TYPELESS: + case DXGI_FORMAT_R16G16B16A16_FLOAT: + case DXGI_FORMAT_R16G16B16A16_UNORM: + case DXGI_FORMAT_R16G16B16A16_UINT: + case DXGI_FORMAT_R16G16B16A16_SNORM: + case DXGI_FORMAT_R16G16B16A16_SINT: + case DXGI_FORMAT_R32G32_TYPELESS: + case DXGI_FORMAT_R32G32_FLOAT: + case DXGI_FORMAT_R32G32_UINT: + case DXGI_FORMAT_R32G32_SINT: + case DXGI_FORMAT_R32G8X24_TYPELESS: + case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: + case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: + case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: + bytesPerPixel = 8; + break; + + case DXGI_FORMAT_R10G10B10A2_TYPELESS: + case DXGI_FORMAT_R10G10B10A2_UNORM: + case DXGI_FORMAT_R10G10B10A2_UINT: + case DXGI_FORMAT_R11G11B10_FLOAT: + case DXGI_FORMAT_R8G8B8A8_TYPELESS: + case DXGI_FORMAT_R8G8B8A8_UNORM: + case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: + case DXGI_FORMAT_R8G8B8A8_UINT: + case DXGI_FORMAT_R8G8B8A8_SNORM: + case DXGI_FORMAT_R8G8B8A8_SINT: + case DXGI_FORMAT_R16G16_TYPELESS: + case DXGI_FORMAT_R16G16_FLOAT: + case DXGI_FORMAT_R16G16_UNORM: + case DXGI_FORMAT_R16G16_UINT: + case DXGI_FORMAT_R16G16_SNORM: + case DXGI_FORMAT_R16G16_SINT: + case DXGI_FORMAT_R32_TYPELESS: + case DXGI_FORMAT_D32_FLOAT: + case DXGI_FORMAT_R32_FLOAT: + case DXGI_FORMAT_R32_UINT: + case DXGI_FORMAT_R32_SINT: + case DXGI_FORMAT_R24G8_TYPELESS: + case DXGI_FORMAT_D24_UNORM_S8_UINT: + case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: + case DXGI_FORMAT_X24_TYPELESS_G8_UINT: + + case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: + case DXGI_FORMAT_R8G8_B8G8_UNORM: + case DXGI_FORMAT_G8R8_G8B8_UNORM: + + case DXGI_FORMAT_B8G8R8A8_UNORM: + case DXGI_FORMAT_B8G8R8X8_UNORM: + bytesPerPixel = 4; + break; + + case DXGI_FORMAT_R8G8_TYPELESS: + case DXGI_FORMAT_R8G8_UNORM: + case DXGI_FORMAT_R8G8_UINT: + case DXGI_FORMAT_R8G8_SNORM: + case DXGI_FORMAT_R8G8_SINT: + case DXGI_FORMAT_R16_TYPELESS: + case DXGI_FORMAT_R16_FLOAT: + case DXGI_FORMAT_D16_UNORM: + case DXGI_FORMAT_R16_UNORM: + case DXGI_FORMAT_R16_UINT: + case DXGI_FORMAT_R16_SNORM: + case DXGI_FORMAT_R16_SINT: + + case DXGI_FORMAT_B5G6R5_UNORM: + case DXGI_FORMAT_B5G5R5A1_UNORM: + bytesPerPixel = 2; + break; + + case DXGI_FORMAT_R8_TYPELESS: + case DXGI_FORMAT_R8_UNORM: + case DXGI_FORMAT_R8_UINT: + case DXGI_FORMAT_R8_SNORM: + case DXGI_FORMAT_R8_SINT: + case DXGI_FORMAT_A8_UNORM: + case DXGI_FORMAT_R1_UNORM: + bytesPerPixel = 1; + break; + + + case DXGI_FORMAT_BC1_TYPELESS: + case DXGI_FORMAT_BC1_UNORM: + case DXGI_FORMAT_BC1_UNORM_SRGB: + case DXGI_FORMAT_BC2_TYPELESS: + case DXGI_FORMAT_BC2_UNORM: + case DXGI_FORMAT_BC2_UNORM_SRGB: + case DXGI_FORMAT_BC3_TYPELESS: + case DXGI_FORMAT_BC3_UNORM: + case DXGI_FORMAT_BC3_UNORM_SRGB: + case DXGI_FORMAT_BC4_TYPELESS: + case DXGI_FORMAT_BC4_UNORM: + case DXGI_FORMAT_BC4_SNORM: + case DXGI_FORMAT_BC5_TYPELESS: + case DXGI_FORMAT_BC5_UNORM: + case DXGI_FORMAT_BC5_SNORM: + // Less than 1 byte per pixel - needs special consideration + bytesPerPixel = 0; + break; + + default: + bytesPerPixel = 0; + _ASSERT(FALSE); + break; + } + return bytesPerPixel; +} + +cl_image_format D3D10Object::getCLFormatFromDXGI(DXGI_FORMAT dxgiFmt) { + cl_image_format fmt; + + //! @todo [odintsov]: add real fmt conversion from DXGI to CL + fmt.image_channel_order = 0; // CL_RGBA; + fmt.image_channel_data_type = 0; // CL_UNSIGNED_INT8; + + switch (dxgiFmt) { + case DXGI_FORMAT_R32G32B32A32_TYPELESS: + fmt.image_channel_order = CL_RGBA; + break; + + case DXGI_FORMAT_R32G32B32A32_FLOAT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_FLOAT; + break; + + case DXGI_FORMAT_R32G32B32A32_UINT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNSIGNED_INT32; + break; + + case DXGI_FORMAT_R32G32B32A32_SINT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_SIGNED_INT32; + break; + + case DXGI_FORMAT_R32G32B32_TYPELESS: + fmt.image_channel_order = CL_RGB; + break; + + case DXGI_FORMAT_R32G32B32_FLOAT: + fmt.image_channel_order = CL_RGB; + fmt.image_channel_data_type = CL_FLOAT; + break; + + case DXGI_FORMAT_R32G32B32_UINT: + fmt.image_channel_order = CL_RGB; + fmt.image_channel_data_type = CL_UNSIGNED_INT32; + break; + + case DXGI_FORMAT_R32G32B32_SINT: + fmt.image_channel_order = CL_RGB; + fmt.image_channel_data_type = CL_SIGNED_INT32; + break; + + case DXGI_FORMAT_R16G16B16A16_TYPELESS: + fmt.image_channel_order = CL_RGBA; + break; + + case DXGI_FORMAT_R16G16B16A16_FLOAT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_HALF_FLOAT; + break; + + case DXGI_FORMAT_R16G16B16A16_UNORM: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNORM_INT16; + break; + + case DXGI_FORMAT_R16G16B16A16_UINT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNSIGNED_INT16; + break; + + case DXGI_FORMAT_R16G16B16A16_SNORM: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_SNORM_INT16; + break; + + case DXGI_FORMAT_R16G16B16A16_SINT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_SIGNED_INT16; + break; + + case DXGI_FORMAT_R32G32_TYPELESS: + fmt.image_channel_order = CL_RG; + break; + + case DXGI_FORMAT_R32G32_FLOAT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_FLOAT; + break; + + case DXGI_FORMAT_R32G32_UINT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_UNSIGNED_INT32; + break; + + case DXGI_FORMAT_R32G32_SINT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_SIGNED_INT32; + break; + + case DXGI_FORMAT_R32G8X24_TYPELESS: + break; + + case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: + break; + + case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: + break; + + case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: + break; + + case DXGI_FORMAT_R10G10B10A2_TYPELESS: + fmt.image_channel_order = CL_RGBA; + break; + + case DXGI_FORMAT_R10G10B10A2_UNORM: + fmt.image_channel_order = CL_RGBA; + break; + + case DXGI_FORMAT_R10G10B10A2_UINT: + fmt.image_channel_order = CL_RGBA; + break; + + case DXGI_FORMAT_R11G11B10_FLOAT: + fmt.image_channel_order = CL_RGB; + break; + + case DXGI_FORMAT_R8G8B8A8_TYPELESS: + fmt.image_channel_order = CL_RGBA; + break; + + case DXGI_FORMAT_R8G8B8A8_UNORM: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_R8G8B8A8_UINT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNSIGNED_INT8; + break; + + case DXGI_FORMAT_R8G8B8A8_SNORM: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_SNORM_INT8; + break; + + case DXGI_FORMAT_R8G8B8A8_SINT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_SIGNED_INT8; + break; + + case DXGI_FORMAT_R16G16_TYPELESS: + fmt.image_channel_order = CL_RG; + break; + + case DXGI_FORMAT_R16G16_FLOAT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_HALF_FLOAT; + break; + + case DXGI_FORMAT_R16G16_UNORM: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_UNORM_INT16; + break; + + case DXGI_FORMAT_R16G16_UINT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_UNSIGNED_INT16; + break; + + case DXGI_FORMAT_R16G16_SNORM: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_SNORM_INT16; + break; + + case DXGI_FORMAT_R16G16_SINT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_SIGNED_INT16; + break; + + case DXGI_FORMAT_R32_TYPELESS: + fmt.image_channel_order = CL_R; + break; + + case DXGI_FORMAT_D32_FLOAT: + break; + + case DXGI_FORMAT_R32_FLOAT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_FLOAT; + break; + + case DXGI_FORMAT_R32_UINT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNSIGNED_INT32; + break; + + case DXGI_FORMAT_R32_SINT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_SIGNED_INT32; + break; + + case DXGI_FORMAT_R24G8_TYPELESS: + fmt.image_channel_order = CL_RG; + break; + + case DXGI_FORMAT_D24_UNORM_S8_UINT: + break; + + case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: + break; + + case DXGI_FORMAT_X24_TYPELESS_G8_UINT: + break; + + case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: + break; + + case DXGI_FORMAT_R8G8_B8G8_UNORM: + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_G8R8_G8B8_UNORM: + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_B8G8R8A8_UNORM: + fmt.image_channel_order = CL_BGRA; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_B8G8R8X8_UNORM: + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_R8G8_TYPELESS: + fmt.image_channel_order = CL_RG; + break; + + case DXGI_FORMAT_R8G8_UNORM: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_R8G8_UINT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_UNSIGNED_INT8; + break; + + case DXGI_FORMAT_R8G8_SNORM: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_SNORM_INT8; + break; + + case DXGI_FORMAT_R8G8_SINT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_SIGNED_INT8; + break; + + case DXGI_FORMAT_R16_TYPELESS: + fmt.image_channel_order = CL_R; + break; + + case DXGI_FORMAT_R16_FLOAT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_HALF_FLOAT; + break; + + case DXGI_FORMAT_D16_UNORM: + fmt.image_channel_data_type = CL_UNORM_INT16; + break; + + case DXGI_FORMAT_R16_UNORM: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNORM_INT16; + break; + + case DXGI_FORMAT_R16_UINT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNSIGNED_INT16; + break; + + case DXGI_FORMAT_R16_SNORM: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_SNORM_INT16; + break; + + case DXGI_FORMAT_R16_SINT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_SIGNED_INT16; + break; + + case DXGI_FORMAT_B5G6R5_UNORM: + fmt.image_channel_data_type = CL_UNORM_SHORT_565; + break; + + case DXGI_FORMAT_B5G5R5A1_UNORM: + fmt.image_channel_order = CL_BGRA; + break; + + case DXGI_FORMAT_R8_TYPELESS: + fmt.image_channel_order = CL_R; + break; + + case DXGI_FORMAT_R8_UNORM: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_R8_UINT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNSIGNED_INT8; + break; + + case DXGI_FORMAT_R8_SNORM: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_SNORM_INT8; + break; + + case DXGI_FORMAT_R8_SINT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_SIGNED_INT8; + break; + + case DXGI_FORMAT_A8_UNORM: + fmt.image_channel_order = CL_A; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_R1_UNORM: + fmt.image_channel_order = CL_R; + break; + + case DXGI_FORMAT_BC1_TYPELESS: + case DXGI_FORMAT_BC1_UNORM: + case DXGI_FORMAT_BC1_UNORM_SRGB: + case DXGI_FORMAT_BC2_TYPELESS: + case DXGI_FORMAT_BC2_UNORM: + case DXGI_FORMAT_BC2_UNORM_SRGB: + case DXGI_FORMAT_BC3_TYPELESS: + case DXGI_FORMAT_BC3_UNORM: + case DXGI_FORMAT_BC3_UNORM_SRGB: + case DXGI_FORMAT_BC4_TYPELESS: + case DXGI_FORMAT_BC4_UNORM: + case DXGI_FORMAT_BC4_SNORM: + case DXGI_FORMAT_BC5_TYPELESS: + case DXGI_FORMAT_BC5_UNORM: + case DXGI_FORMAT_BC5_SNORM: + break; + + default: + _ASSERT(FALSE); + break; + } + + return fmt; +} + +size_t D3D10Object::getResourceByteSize() { + size_t bytes = 1; + + //! @todo [odintsov]: take into consideration the mip level?! + + switch (objDesc_.objDim_) { + case D3D10_RESOURCE_DIMENSION_BUFFER: + bytes = objDesc_.objSize_.ByteWidth; + break; + + case D3D10_RESOURCE_DIMENSION_TEXTURE3D: + bytes = objDesc_.objSize_.Depth; + + case D3D10_RESOURCE_DIMENSION_TEXTURE2D: + bytes *= objDesc_.objSize_.Height; + + case D3D10_RESOURCE_DIMENSION_TEXTURE1D: + bytes *= objDesc_.objSize_.Width * getElementBytes(); + break; + + default: + LogError("getResourceByteSize: unknown type of D3D10 resource"); + bytes = 0; + break; + } + return bytes; +} + +int D3D10Object::initD3D10Object(const Context& amdContext, ID3D10Resource* pRes, UINT subres, + D3D10Object& obj) { + ID3D10Device* pDev; + HRESULT hr; + ScopedLock sl(resLock_); + + // Check if this ressource has already been used for interop + for (const auto& it : resources_) { + if (it.first == (void*)pRes && it.second == subres) { + return CL_INVALID_D3D10_RESOURCE_KHR; + } + } + + (obj.pD3D10Res_ = pRes)->GetDevice(&pDev); + + if (!pDev) { + return CL_INVALID_D3D10_DEVICE_KHR; + } + + D3D10_QUERY_DESC desc = {D3D10_QUERY_EVENT, 0}; + pDev->CreateQuery(&desc, &obj.pQuery_); + +#define SET_SHARED_FLAGS() \ + { \ + obj.pD3D10ResOrig_ = obj.pD3D10Res_; \ + memcpy(&obj.objDescOrig_, &obj.objDesc_, sizeof(D3D10ObjDesc_t)); \ + /* @todo - Check device type and select right usage for resource */ \ + /* For now get only DPU path, CPU path for buffers */ \ + /* will not worl on DEFAUL resources */ \ + /*desc.Usage = D3D10_USAGE_STAGING;*/ \ + desc.Usage = D3D10_USAGE_DEFAULT; \ + desc.MiscFlags = D3D10_RESOURCE_MISC_SHARED; \ + desc.CPUAccessFlags = 0; \ + } + +#define STORE_SHARED_FLAGS(restype) \ + { \ + if (S_OK == hr && obj.pD3D10Res_) { \ + obj.objDesc_.objFlags_.d3d10Usage_ = desc.Usage; \ + obj.objDesc_.objFlags_.bindFlags_ = desc.BindFlags; \ + obj.objDesc_.objFlags_.miscFlags_ = desc.MiscFlags; \ + obj.objDesc_.objFlags_.cpuAccessFlags_ = desc.CPUAccessFlags; \ + } else { \ + LogError("\nCannot create shared " #restype "\n"); \ + return CL_INVALID_D3D10_RESOURCE_KHR; \ + } \ + } + +#define SET_BINDING() \ + { \ + switch (desc.Format) { \ + case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: \ + case DXGI_FORMAT_D32_FLOAT: \ + case DXGI_FORMAT_D24_UNORM_S8_UINT: \ + case DXGI_FORMAT_D16_UNORM: \ + desc.BindFlags = D3D10_BIND_DEPTH_STENCIL; \ + break; \ + default: \ + desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET; \ + break; \ + } \ + } + + pRes->GetType(&obj.objDesc_.objDim_); + + // Init defaults + obj.objDesc_.objSize_.Height = 1; + obj.objDesc_.objSize_.Depth = 1; + obj.objDesc_.mipLevels_ = 1; + obj.objDesc_.arraySize_ = 1; + obj.objDesc_.dxgiFormat_ = DXGI_FORMAT_UNKNOWN; + obj.objDesc_.dxgiSampleDesc_ = dxgiSampleDescDefault; + + switch (obj.objDesc_.objDim_) { + case D3D10_RESOURCE_DIMENSION_BUFFER: // = 1, + { + D3D10_BUFFER_DESC desc; + (reinterpret_cast(pRes))->GetDesc(&desc); + obj.objDesc_.objSize_.ByteWidth = desc.ByteWidth; + obj.objDesc_.objFlags_.d3d10Usage_ = desc.Usage; + obj.objDesc_.objFlags_.bindFlags_ = desc.BindFlags; + obj.objDesc_.objFlags_.cpuAccessFlags_ = desc.CPUAccessFlags; + obj.objDesc_.objFlags_.miscFlags_ = desc.MiscFlags; + // Handle D3D10Buffer without shared handle - create + // a duplicate with shared handle to provide for CAL + if (!(obj.objDesc_.objFlags_.miscFlags_ & D3D10_RESOURCE_MISC_SHARED)) { + SET_SHARED_FLAGS(); + desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET; + hr = pDev->CreateBuffer(&desc, NULL, (ID3D10Buffer**)&obj.pD3D10Res_); + STORE_SHARED_FLAGS(ID3D10Buffer); + } + } break; + + case D3D10_RESOURCE_DIMENSION_TEXTURE1D: // = 2, + { + D3D10_TEXTURE1D_DESC desc; + (reinterpret_cast(pRes))->GetDesc(&desc); + + if (subres) { + // Calculate correct size of the subresource + UINT miplevel = subres; + if (desc.ArraySize > 1) { + miplevel = subres % desc.ArraySize; + } + if (miplevel >= desc.MipLevels) { + LogWarning("\nMiplevel >= number of miplevels\n"); + } + if (subres >= desc.MipLevels * desc.ArraySize) { + return CL_INVALID_VALUE; + } + desc.Width >>= miplevel; + if (!desc.Width) { + desc.Width = 1; + } + } + obj.objDesc_.objSize_.Width = desc.Width; + obj.objDesc_.mipLevels_ = desc.MipLevels; + obj.objDesc_.arraySize_ = desc.ArraySize; + obj.objDesc_.dxgiFormat_ = desc.Format; + obj.objDesc_.objFlags_.d3d10Usage_ = desc.Usage; + obj.objDesc_.objFlags_.bindFlags_ = desc.BindFlags; + obj.objDesc_.objFlags_.cpuAccessFlags_ = desc.CPUAccessFlags; + obj.objDesc_.objFlags_.miscFlags_ = desc.MiscFlags; + // Handle D3D10Texture1D without shared handle - create + // a duplicate with shared handle and provide it for CAL + // Workaround for subresource > 0 in shared resource + if (subres) obj.objDesc_.objFlags_.miscFlags_ &= ~(D3D10_RESOURCE_MISC_SHARED); + if (!(obj.objDesc_.objFlags_.miscFlags_ & D3D10_RESOURCE_MISC_SHARED)) { + SET_SHARED_FLAGS(); + SET_BINDING(); + obj.objDesc_.mipLevels_ = desc.MipLevels = 1; + obj.objDesc_.arraySize_ = desc.ArraySize = 1; + hr = pDev->CreateTexture1D(&desc, NULL, (ID3D10Texture1D**)&obj.pD3D10Res_); + STORE_SHARED_FLAGS(ID3D10Texture1D); + } + } break; + + case D3D10_RESOURCE_DIMENSION_TEXTURE2D: // = 3, + { + D3D10_TEXTURE2D_DESC desc; + (reinterpret_cast(pRes))->GetDesc(&desc); + + if (subres) { + // Calculate correct size of the subresource + UINT miplevel = subres; + if (desc.ArraySize > 1) { + miplevel = subres % desc.MipLevels; + } + if (miplevel >= desc.MipLevels) { + LogWarning("\nMiplevel >= number of miplevels\n"); + } + if (subres >= desc.MipLevels * desc.ArraySize) { + return CL_INVALID_VALUE; + } + desc.Width >>= miplevel; + if (!desc.Width) { + desc.Width = 1; + } + desc.Height >>= miplevel; + if (!desc.Height) { + desc.Height = 1; + } + } + obj.objDesc_.objSize_.Width = desc.Width; + obj.objDesc_.objSize_.Height = desc.Height; + obj.objDesc_.mipLevels_ = desc.MipLevels; + obj.objDesc_.arraySize_ = desc.ArraySize; + obj.objDesc_.dxgiFormat_ = desc.Format; + obj.objDesc_.dxgiSampleDesc_ = desc.SampleDesc; + obj.objDesc_.objFlags_.d3d10Usage_ = desc.Usage; + obj.objDesc_.objFlags_.bindFlags_ = desc.BindFlags; + obj.objDesc_.objFlags_.cpuAccessFlags_ = desc.CPUAccessFlags; + obj.objDesc_.objFlags_.miscFlags_ = desc.MiscFlags; + // Handle D3D10Texture2D without shared handle - create + // a duplicate with shared handle and provide it for CAL + // Workaround for subresource > 0 in shared resource + if (subres) obj.objDesc_.objFlags_.miscFlags_ &= ~(D3D10_RESOURCE_MISC_SHARED); + if (!(obj.objDesc_.objFlags_.miscFlags_ & D3D10_RESOURCE_MISC_SHARED)) { + SET_SHARED_FLAGS(); + SET_BINDING(); + obj.objDesc_.mipLevels_ = desc.MipLevels = 1; + obj.objDesc_.arraySize_ = desc.ArraySize = 1; + hr = pDev->CreateTexture2D(&desc, NULL, (ID3D10Texture2D**)&obj.pD3D10Res_); + STORE_SHARED_FLAGS(ID3D10Texture2D); + } + } break; + + case D3D10_RESOURCE_DIMENSION_TEXTURE3D: // = 4 + { + D3D10_TEXTURE3D_DESC desc; + (reinterpret_cast(pRes))->GetDesc(&desc); + + if (subres) { + // Calculate correct size of the subresource + UINT miplevel = subres; + if (miplevel >= desc.MipLevels) { + LogWarning("\nMiplevel >= number of miplevels\n"); + } + if (subres >= desc.MipLevels) { + return CL_INVALID_VALUE; + } + desc.Width >>= miplevel; + if (!desc.Width) { + desc.Width = 1; + } + desc.Height >>= miplevel; + if (!desc.Height) { + desc.Height = 1; + } + desc.Depth >>= miplevel; + if (!desc.Depth) { + desc.Depth = 1; + } + } + obj.objDesc_.objSize_.Width = desc.Width; + obj.objDesc_.objSize_.Height = desc.Height; + obj.objDesc_.objSize_.Depth = desc.Depth; + obj.objDesc_.mipLevels_ = desc.MipLevels; + obj.objDesc_.dxgiFormat_ = desc.Format; + obj.objDesc_.objFlags_.d3d10Usage_ = desc.Usage; + obj.objDesc_.objFlags_.bindFlags_ = desc.BindFlags; + obj.objDesc_.objFlags_.cpuAccessFlags_ = desc.CPUAccessFlags; + obj.objDesc_.objFlags_.miscFlags_ = desc.MiscFlags; + // Handle D3D10Texture3D without shared handle - create + // a duplicate with shared handle and provide it for CAL + // Workaround for subresource > 0 in shared resource + if (obj.objDesc_.mipLevels_ > 1) + obj.objDesc_.objFlags_.miscFlags_ &= ~(D3D10_RESOURCE_MISC_SHARED); + if (!(obj.objDesc_.objFlags_.miscFlags_ & D3D10_RESOURCE_MISC_SHARED)) { + SET_SHARED_FLAGS(); + SET_BINDING(); + obj.objDesc_.mipLevels_ = desc.MipLevels = 1; + hr = pDev->CreateTexture3D(&desc, NULL, (ID3D10Texture3D**)&obj.pD3D10Res_); + STORE_SHARED_FLAGS(ID3D10Texture3D); + } + } break; + + default: + LogError("unknown type of D3D10 resource"); + return CL_INVALID_D3D10_RESOURCE_KHR; + } + obj.subRes_ = subres; + pDev->Release(); + // Check for CL format compatibilty + if (obj.objDesc_.objDim_ != D3D10_RESOURCE_DIMENSION_BUFFER) { + cl_image_format clFmt = obj.getCLFormatFromDXGI(obj.objDesc_.dxgiFormat_); + amd::Image::Format imageFormat(clFmt); + if (!imageFormat.isSupported(amdContext)) { + return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + } + } + resources_.push_back({pRes, subres}); + return CL_SUCCESS; +} + +bool D3D10Object::copyOrigToShared() { + // Don't copy if there is no orig + if (NULL == getD3D10ResOrig()) return true; + + ID3D10Device* d3dDev; + pD3D10Res_->GetDevice(&d3dDev); + if (!d3dDev) { + LogError("\nCannot get D3D10 device from D3D10 resource\n"); + return false; + } + // Any usage source can be read by GPU + d3dDev->CopySubresourceRegion(pD3D10Res_, 0, 0, 0, 0, pD3D10ResOrig_, subRes_, NULL); + + // Flush D3D queues and make sure D3D stuff is finished + d3dDev->Flush(); + pQuery_->End(); + BOOL data = FALSE; + while ((S_OK != pQuery_->GetData(&data, sizeof(BOOL), 0)) || (data != TRUE)) { + } + + d3dDev->Release(); + return true; +} + +bool D3D10Object::copySharedToOrig() { + // Don't copy if there is no orig + if (NULL == getD3D10ResOrig()) return true; + + ID3D10Device* d3dDev; + pD3D10Res_->GetDevice(&d3dDev); + if (!d3dDev) { + LogError("\nCannot get D3D10 device from D3D10 resource\n"); + return false; + } + + d3dDev->CopySubresourceRegion(pD3D10ResOrig_, subRes_, 0, 0, 0, pD3D10Res_, 0, NULL); + + d3dDev->Release(); + return true; +} + +std::vector> D3D10Object::resources_; +Monitor D3D10Object::resLock_; + +// +// Class BufferD3D10 implementation +// +void BufferD3D10::initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(BufferD3D10)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); +} + +// +// Class Image1DD3D10 implementation +// + +void Image1DD3D10::initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(Image1DD3D10)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); +} + +// +// Class Image2DD3D10 implementation +// + +void Image2DD3D10::initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(Image2DD3D10)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); +} + +// +// Class Image3DD3D10 implementation +// +void Image3DD3D10::initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(Image3DD3D10)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); +} + +} // namespace amd + +#endif //_WIN32 diff --git a/opencl/amdocl/cl_d3d10_amd.hpp b/opencl/amdocl/cl_d3d10_amd.hpp new file mode 100644 index 0000000000..c0ef6adba2 --- /dev/null +++ b/opencl/amdocl/cl_d3d10_amd.hpp @@ -0,0 +1,339 @@ +/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef CL_D3D10_AMD_HPP_ +#define CL_D3D10_AMD_HPP_ + +#include "cl_common.hpp" + +#include "platform/context.hpp" +#include "platform/memory.hpp" + +#include + +namespace amd +{ + +typedef struct +{ + union + { + UINT ByteWidth; + UINT Width; + }; + UINT Height; + UINT Depth; +} D3D10ObjSize_t; + +typedef struct +{ + D3D10_USAGE d3d10Usage_; + UINT bindFlags_; + UINT cpuAccessFlags_; + UINT miscFlags_; +} D3D10Flags_t; + +typedef struct +{ + D3D10_RESOURCE_DIMENSION objDim_; + D3D10ObjSize_t objSize_; + D3D10Flags_t objFlags_; + UINT mipLevels_; + UINT arraySize_; + DXGI_FORMAT dxgiFormat_; + DXGI_SAMPLE_DESC dxgiSampleDesc_; +} D3D10ObjDesc_t; + +const DXGI_SAMPLE_DESC dxgiSampleDescDefault = {1, 0}; + +//! Class D3D10Object keeps all the info about the D3D10 object +//! from which the CL object is created +class D3D10Object : public InteropObject +{ +private: + ID3D10Resource* pD3D10Aux_; + + // @todo: TBD: Do we need to sync data after access + // or it'll be done by the D3D driver? + cl_int cliChecksum_; + bool releaseResources_; + + static bool createSharedResource(D3D10Object& obj); + static std::vector> resources_; + //! Global lock. + static Monitor resLock_; + +protected: + ID3D10Resource* pD3D10Res_; + ID3D10Resource* pD3D10ResOrig_; + ID3D10Query* pQuery_; + D3D10ObjDesc_t objDesc_; + D3D10ObjDesc_t objDescOrig_; + UINT subRes_; + +public: + // Default constructor + D3D10Object() + :pD3D10Aux_(NULL) + ,cliChecksum_(0) + ,releaseResources_(false) + ,pD3D10Res_(NULL) + ,pD3D10ResOrig_(NULL) + ,pQuery_(NULL) + ,subRes_(0) + { + memset(&objDesc_,0,sizeof(objDesc_)); + memset(&objDescOrig_,0,sizeof(objDescOrig_)); + } + // Copy constructor + D3D10Object(D3D10Object& d3d10obj) + : pQuery_(NULL) + { + *this = d3d10obj; + this->releaseResources_ = true; + // Add reference to the D3D10 resource to prevent its disappearance + if(pD3D10ResOrig_) { + pD3D10ResOrig_->AddRef(); + } + else if(pD3D10Res_) { + pD3D10Res_->AddRef(); + } + } + + //! Virtual destructor + virtual ~D3D10Object() + { + ScopedLock sl(resLock_); + if(releaseResources_) { + // Decrement reference to the D3D10 objects + if(pD3D10Res_) pD3D10Res_->Release(); + if(pD3D10Aux_) pD3D10Aux_->Release(); + if(pD3D10ResOrig_) pD3D10ResOrig_->Release(); + if(pQuery_) pQuery_->Release(); + // Check if this resource has already been used for interop + if(resources_.size()) { + for(auto& it = resources_.cbegin(); it != resources_.cend(); it++) { + if(((pD3D10ResOrig_ && (*it).first == (void*) pD3D10ResOrig_) + || ((*it).first == (void*) pD3D10Res_)) + && (*it).second == subRes_) { + resources_.erase(it); + break; + } + } + } + } + } + + static int initD3D10Object(const Context& amdContext, ID3D10Resource* pRes, UINT subresource, + D3D10Object& obj); + + D3D10Object* asD3D10Object() { return this; } + +//! D3D10Object query functions to get D3D10 info from member variables + ID3D10Resource* getD3D10Resource() const {return pD3D10Res_;} + ID3D10Resource* getD3D10ResOrig() const {return pD3D10ResOrig_;} + D3D10_USAGE getUsage() const { return objDesc_.objFlags_.d3d10Usage_; } + void setD3D10AuxRes(ID3D10Resource* pAux) {pD3D10Aux_ = pAux;} + ID3D10Resource* getD3D10AuxRes() const {return pD3D10Aux_;} + ID3D10Query* getQuery() const {return pQuery_;} + + UINT getWidth() const {return objDesc_.objSize_.Width;} + UINT getHeight() const {return objDesc_.objSize_.Height;} + UINT getDepth() const {return objDesc_.objSize_.Depth;} + size_t getElementBytes(DXGI_FORMAT dxgiFomat); + size_t getElementBytes() {return getElementBytes(objDesc_.dxgiFormat_);} + DXGI_FORMAT getDxgiFormat() {return objDesc_.dxgiFormat_;} + UINT getSubresource() const {return subRes_;} + const D3D10ObjDesc_t* getObjDesc() const { return &objDesc_; } + + //! Returns bytes per pixel > 0 if conversion successful, 0 otherwise; + //! if formats are not compatible, cl format channel + //! order and type are set to 0 + cl_image_format getCLFormatFromDXGI(DXGI_FORMAT dxgiFmt); + cl_image_format getCLFormatFromDXGI() + { + return getCLFormatFromDXGI(objDesc_.dxgiFormat_); + } + size_t getResourceByteSize(); + + // On acquire copy data from original resource to shared resource + virtual bool copyOrigToShared(); + // On release copy data from shared copy to the original resource + virtual bool copySharedToOrig(); +}; + +//! Class BufferD3D10 is derived from classes Buffer and D3D10Object +//! where the former keeps all data for CL object and +//! the latter keeps all data for D3D10 object +class BufferD3D10 : public D3D10Object, public Buffer +{ +protected: + //! Initializes the device memory array which is nested + // after 'BufferD3D10' object in memory layout. + virtual void initDeviceMemory(); +public: + //! BufferD3D10 constructor just calls constructors of base classes + //! to pass down the parameters + BufferD3D10( + Context& amdContext, + cl_mem_flags clFlags, + D3D10Object& d3d10obj) + : // Call base classes constructors + D3D10Object(d3d10obj), + Buffer( + amdContext, + clFlags, + d3d10obj.getResourceByteSize()) + { + setInteropObj(this); + } + virtual ~BufferD3D10() {} +}; + +//! Class Image1DD3D10 is derived from classes Image1D and D3D10Object +//! where the former keeps all data for CL object and +//! the latter keeps all data for D3D10 object +class Image1DD3D10 : public D3D10Object, public Image +{ +protected: + //! Initializes the device memory array which is nested + // after'Image1DD3D10' object in memory layout. + virtual void initDeviceMemory(); +public: + //! Image1DD3D10 constructor just calls constructors of base classes + //! to pass down the parameters + Image1DD3D10( + Context& amdContext, + cl_mem_flags clFlags, + D3D10Object& d3d10obj) + : // Call base classes constructors + D3D10Object(d3d10obj), + Image( + amdContext, + CL_MEM_OBJECT_IMAGE1D, + clFlags, + getCLFormatFromDXGI(d3d10obj.getDxgiFormat()), //format, + d3d10obj.getWidth(), + 1, + 1, + d3d10obj.getWidth() * d3d10obj.getElementBytes(), //rowPitch), + 0) + { + setInteropObj(this); + } + virtual ~Image1DD3D10() {} +}; + +//! Class Image2DD3D10 is derived from classes Image2D and D3D10Object +//! where the former keeps all data for CL object and +//! the latter keeps all data for D3D10 object +class Image2DD3D10 : public D3D10Object, public Image +{ +protected: + //! Initializes the device memory array which is nested + // after'Image2DD3D10' object in memory layout. + virtual void initDeviceMemory(); +public: + //! Image2DD3D10 constructor just calls constructors of base classes + //! to pass down the parameters + Image2DD3D10( + Context& amdContext, + cl_mem_flags clFlags, + D3D10Object& d3d10obj) + : // Call base classes constructors + D3D10Object(d3d10obj), + Image( + amdContext, + CL_MEM_OBJECT_IMAGE2D, + clFlags, + getCLFormatFromDXGI(d3d10obj.getDxgiFormat()), //format, + d3d10obj.getWidth(), + d3d10obj.getHeight(), + 1, + d3d10obj.getWidth() * d3d10obj.getElementBytes(), //rowPitch), + 0) + { + setInteropObj(this); + } + virtual ~Image2DD3D10() {} +}; + +//! Class Image3DD3D10 is derived from classes Image3D and D3D10Object +//! where the former keeps all data for CL object and +//! the latter keeps all data for D3D10 object +class Image3DD3D10 : public D3D10Object, public Image +{ +protected: + //! Initializes the device memory array which is nested + // after'Image3DD3D10' object in memory layout. + virtual void initDeviceMemory(); +public: +//! Image2DD3D10 constructor just calls constructors of base classes +//! to pass down the parameters + Image3DD3D10( + Context& amdContext, + cl_mem_flags clFlags, + D3D10Object& d3d10obj) + : // Call base classes constructors + D3D10Object(d3d10obj), + Image( + amdContext, + CL_MEM_OBJECT_IMAGE3D, + clFlags, + getCLFormatFromDXGI(d3d10obj.getDxgiFormat()), //format, + d3d10obj.getWidth(), + d3d10obj.getHeight(), + d3d10obj.getDepth(), + d3d10obj.getWidth() * d3d10obj.getElementBytes(), //rowPitch), + d3d10obj.getWidth() * d3d10obj.getHeight() * d3d10obj.getElementBytes()) + { + setInteropObj(this); + } + virtual ~Image3DD3D10() {} +}; + +//! Functions for executing the D3D10 related stuff +cl_mem clCreateBufferFromD3D10ResourceAMD( + Context& amdContext, + cl_mem_flags flags, + ID3D10Resource* pD3DResource, + int* errcode_ret); +cl_mem clCreateImage1DFromD3D10ResourceAMD( + Context& amdContext, + cl_mem_flags flags, + ID3D10Resource* pD3DResource, + UINT subresource, + int* errcode_ret); +cl_mem clCreateImage2DFromD3D10ResourceAMD( + Context& amdContext, + cl_mem_flags flags, + ID3D10Resource* pD3DResource, + UINT subresource, + int* errcode_ret); +cl_mem clCreateImage3DFromD3D10ResourceAMD( + Context& amdContext, + cl_mem_flags flags, + ID3D10Resource* pD3DResource, + UINT subresource, + int* errcode_ret); +void SyncD3D10Objects(std::vector& memObjects); +} //namespace amd + +#endif //CL_D3D10_AMD_HPP_ diff --git a/opencl/amdocl/cl_d3d11.cpp b/opencl/amdocl/cl_d3d11.cpp new file mode 100644 index 0000000000..dfc2408d45 --- /dev/null +++ b/opencl/amdocl/cl_d3d11.cpp @@ -0,0 +1,1571 @@ +/* Copyright (c) 2009 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifdef _WIN32 + +#include "top.hpp" + +#include "cl_d3d11_amd.hpp" +#include "platform/command.hpp" + +#include +#include + +/*! \addtogroup API + * @{ + * + * \addtogroup CL_D3D11_Interops + * + * This section discusses OpenCL functions that allow applications to use Direct3D 11 + * resources (buffers/textures) as OpenCL memory objects. This allows efficient sharing of + * data between OpenCL and Direct3D 11. The OpenCL API can be used to execute kernels that + * read and/or write memory objects that are also the Direct3D resources. + * An OpenCL image object can be created from a D3D11 texture object. An + * OpenCL buffer object can be created from a D3D11 buffer object (index/vertex). + * + * @} + * \addtogroup clGetDeviceIDsFromD3D11KHR + * @{ + */ + +RUNTIME_ENTRY(cl_int, clGetDeviceIDsFromD3D11KHR, + (cl_platform_id platform, cl_d3d11_device_source_khr d3d_device_source, + void* d3d_object, cl_d3d11_device_set_khr d3d_device_set, cl_uint num_entries, + cl_device_id* devices, cl_uint* num_devices)) { + cl_int errcode; + ID3D11Device* d3d11_device = NULL; + cl_device_id* gpu_devices; + cl_uint num_gpu_devices = 0; + bool create_d3d11Device = false; + static const bool VALIDATE_ONLY = true; + HMODULE d3d11Module = NULL; + + if (platform != NULL && platform != AMD_PLATFORM) { + LogWarning("\"platrform\" is not a valid AMD platform"); + return CL_INVALID_PLATFORM; + } + if (((num_entries > 0 || num_devices == NULL) && devices == NULL) || + (num_entries == 0 && devices != NULL)) { + return CL_INVALID_VALUE; + } + // Get GPU devices + errcode = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 0, NULL, &num_gpu_devices); + if (errcode != CL_SUCCESS && errcode != CL_DEVICE_NOT_FOUND) { + return CL_INVALID_VALUE; + } + + if (!num_gpu_devices) { + *not_null(num_devices) = 0; + return CL_DEVICE_NOT_FOUND; + } + + switch (d3d_device_source) { + case CL_D3D11_DEVICE_KHR: + d3d11_device = static_cast(d3d_object); + break; + case CL_D3D11_DXGI_ADAPTER_KHR: { + static PFN_D3D11_CREATE_DEVICE dynamicD3D11CreateDevice = NULL; + + d3d11Module = LoadLibrary("D3D11.dll"); + if (d3d11Module == NULL) { + return CL_INVALID_PLATFORM; + } + + dynamicD3D11CreateDevice = + (PFN_D3D11_CREATE_DEVICE)GetProcAddress(d3d11Module, "D3D11CreateDevice"); + + IDXGIAdapter* dxgi_adapter = static_cast(d3d_object); + D3D_FEATURE_LEVEL requestedFeatureLevels[] = {D3D_FEATURE_LEVEL_10_0}; + D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0; + HRESULT hr = dynamicD3D11CreateDevice(dxgi_adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, + requestedFeatureLevels, 1, D3D11_SDK_VERSION, + &d3d11_device, &featureLevel, NULL); + if (SUCCEEDED(hr) && (NULL != d3d11_device)) { + create_d3d11Device = true; + } else { + FreeLibrary(d3d11Module); + return CL_INVALID_VALUE; + } + } break; + default: + LogWarning("\"d3d_device_source\" is invalid"); + return CL_INVALID_VALUE; + } + + switch (d3d_device_set) { + case CL_PREFERRED_DEVICES_FOR_D3D11_KHR: + case CL_ALL_DEVICES_FOR_D3D11_KHR: { + gpu_devices = (cl_device_id*)alloca(num_gpu_devices * sizeof(cl_device_id)); + + errcode = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, num_gpu_devices, gpu_devices, NULL); + if (errcode != CL_SUCCESS) { + break; + } + + std::vector compatible_devices; + for (cl_uint i = 0; i < num_gpu_devices; ++i) { + void* external_device[amd::Context::DeviceFlagIdx::LastDeviceFlagIdx] = {}; + external_device[amd::Context::DeviceFlagIdx::D3D11DeviceKhrIdx] = d3d11_device; + + cl_device_id device = gpu_devices[i]; + if (is_valid(device) && + as_amd(device)->bindExternalDevice(amd::Context::Flags::D3D11DeviceKhr, external_device, + NULL, VALIDATE_ONLY)) { + compatible_devices.push_back(as_amd(device)); + } + } + if (compatible_devices.size() == 0) { + *not_null(num_devices) = 0; + errcode = CL_DEVICE_NOT_FOUND; + break; + } + + auto it = compatible_devices.cbegin(); + cl_uint compatible_count = std::min(num_entries, (cl_uint)compatible_devices.size()); + + while (compatible_count--) { + *devices++ = as_cl(*it++); + --num_entries; + } + while (num_entries--) { + *devices++ = (cl_device_id)0; + } + + *not_null(num_devices) = (cl_uint)compatible_devices.size(); + } break; + + default: + LogWarning("\"d3d_device_set\" is invalid"); + errcode = CL_INVALID_VALUE; + } + + if (create_d3d11Device) { + d3d11_device->Release(); + FreeLibrary(d3d11Module); + } + return errcode; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clCreateFromD3D11BufferKHR + * @{ + */ + +/*! \brief Creates an OpenCL buffer object from a Direct3D 10 resource. + * + * \param context is a valid OpenCL context. + * + * \param flags is a bit-field that is used to specify usage information. + * Only CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY and CL_MEM_READ_WRITE values + * can be used. + * + * \param pD3DResource is a valid pointer to a D3D11 resource of type ID3D11Buffer. + * + * \return valid non-zero OpenCL buffer object and \a errcode_ret is set + * to CL_SUCCESS if the buffer object is created successfully. It returns a NULL + * value with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a context is not a valid context or if Direct3D 10 + * interoperatbility has not been initialized between context and the ID3D11Device + * from which pD3DResource was created. + * - CL_INVALID_VALUE if values specified in \a clFlags are not valid. + * - CL_INVALID_D3D_RESOURCE if \a pD3DResource is not of type ID3D11Buffer. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33? + */ + +RUNTIME_ENTRY_RET(cl_mem, clCreateFromD3D11BufferKHR, + (cl_context context, cl_mem_flags flags, ID3D11Buffer* pD3DResource, + cl_int* errcode_ret)) { + cl_mem clMemObj = NULL; + + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return clMemObj; + } + if (!flags) flags = CL_MEM_READ_WRITE; + if (!(((flags & CL_MEM_READ_ONLY) == CL_MEM_READ_ONLY) || + ((flags & CL_MEM_WRITE_ONLY) == CL_MEM_WRITE_ONLY) || + ((flags & CL_MEM_READ_WRITE) == CL_MEM_READ_WRITE))) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return clMemObj; + } + if (!pD3DResource) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("parameter \"pD3DResource\" is a NULL pointer"); + return clMemObj; + } + return ( + amd::clCreateBufferFromD3D11ResourceAMD(*as_amd(context), flags, pD3DResource, errcode_ret)); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clCreateImageFromD3D11Resource + * @{ + */ + +/*! \brief Create an OpenCL 2D or 3D image object from a D3D11 resource. + * + * \param context is a valid OpenCL context. + * + * \param flags is a bit-field that is used to specify usage information. + * Only CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY and CL_MEM_READ_WRITE values + * can be used. + * + * \param pD3DResource is a valid pointer to a D3D11 resource of type + * ID3D11Texture2D, ID3D11Texture2D, or ID3D11Texture3D. + * If pD3DResource is of type ID3D11Texture1D then the created image object + * will be a 1D mipmapped image object. + * If pD3DResource is of type ID3D11Texture2D and was not created with flag + * D3D11_RESOURCE_MISC_TEXTURECUBE then the created image object will be a + * 2D mipmapped image object. + * If pD3DResource is of type ID3D11Texture2D and was created with flag + * D3D11_RESOURCE_MISC_TEXTURECUBE then the created image object will be + * a cubemap mipmapped image object. + * errocde_ret returns CL_INVALID_D3D_RESOURCE if an OpenCL memory object has + * already been created from pD3DResource in context. + * If pD3DResource is of type ID3D11Texture3D then the created image object will + * be a 3D mipmapped imageobject. + * + * \return valid non-zero OpenCL image object and \a errcode_ret is set + * to CL_SUCCESS if the image object is created successfully. It returns a NULL + * value with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a context is not a valid context or if Direct3D 11 + * interoperatbility has not been initialized between context and the ID3D11Device + * from which pD3DResource was created. + * - CL_INVALID_VALUE if values specified in \a flags are not valid. + * - CL_INVALID_D3D_RESOURCE if \a pD3DResource is not of type ID3D11Texture1D, + * ID3D11Texture2D, or ID3D11Texture3D. + * - CL_INVALID_D3D_RESOURCE if an OpenCL memory object has already been created + * from \a pD3DResource in context. + * - CL_INVALID_IMAGE_FORMAT if the Direct3D 11 texture format does not map + * to an appropriate OpenCL image format. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r48? + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateImageFromD3D11Resource, + (cl_context context, cl_mem_flags flags, ID3D11Resource* pD3DResource, + UINT subresource, int* errcode_ret, UINT dimension)) { + cl_mem clMemObj = NULL; + + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return clMemObj; + } + if (!flags) flags = CL_MEM_READ_WRITE; + if (!(((flags & CL_MEM_READ_ONLY) == CL_MEM_READ_ONLY) || + ((flags & CL_MEM_WRITE_ONLY) == CL_MEM_WRITE_ONLY) || + ((flags & CL_MEM_READ_WRITE) == CL_MEM_READ_WRITE))) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return clMemObj; + } + if (!pD3DResource) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("parameter \"pD3DResource\" is a NULL pointer"); + return clMemObj; + } + + // Verify context init'ed for interop + ID3D11Device* pDev; + pD3DResource->GetDevice(&pDev); + if (pDev == NULL) { + *not_null(errcode_ret) = CL_INVALID_D3D11_DEVICE_KHR; + LogWarning("Cannot retrieve D3D11 device from D3D11 resource"); + return (cl_mem)0; + } + pDev->Release(); + if (!((*as_amd(context)).info().flags_ & amd::Context::D3D11DeviceKhr)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("\"amdContext\" is not created from D3D11 device"); + return (cl_mem)0; + } + + // Check for image support + const std::vector& devices = as_amd(context)->devices(); + bool supportPass = false; + bool sizePass = false; + for (const auto& it : devices) { + if (it->info().imageSupport_) { + supportPass = true; + } + } + if (!supportPass) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + LogWarning("there are no devices in context to support images"); + return (cl_mem)0; + } + + switch (dimension) { +#if 0 + case 1: + return(amd::clCreateImage1DFromD3D11ResourceAMD( + *as_amd(context), + flags, + pD3DResource, + subresource, + errcode_ret)); +#endif // 0 + case 2: + return (amd::clCreateImage2DFromD3D11ResourceAMD(*as_amd(context), flags, pD3DResource, + subresource, errcode_ret)); + case 3: + return (amd::clCreateImage3DFromD3D11ResourceAMD(*as_amd(context), flags, pD3DResource, + subresource, errcode_ret)); + default: + break; + } + + *not_null(errcode_ret) = CL_INVALID_D3D11_RESOURCE_KHR; + return (cl_mem)0; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clCreateFromD3D11Texture2DKHR + * @{ + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateFromD3D11Texture2DKHR, + (cl_context context, cl_mem_flags flags, ID3D11Texture2D* resource, + UINT subresource, cl_int* errcode_ret)) { + return clCreateImageFromD3D11Resource(context, flags, resource, subresource, errcode_ret, 2); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clCreateFromD3D11Texture3DKHR + * @{ + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateFromD3D11Texture3DKHR, + (cl_context context, cl_mem_flags flags, ID3D11Texture3D* resource, + UINT subresource, cl_int* errcode_ret)) { + return clCreateImageFromD3D11Resource(context, flags, resource, subresource, errcode_ret, 3); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clEnqueueAcquireD3D11ObjectsKHR + * @{ + */ +RUNTIME_ENTRY(cl_int, clEnqueueAcquireD3D11ObjectsKHR, + (cl_command_queue command_queue, cl_uint num_objects, const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event)) { + return amd::clEnqueueAcquireExtObjectsAMD(command_queue, num_objects, mem_objects, + num_events_in_wait_list, event_wait_list, event, + CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clEnqueueReleaseD3D11ObjectsKHR + * @{ + */ +RUNTIME_ENTRY(cl_int, clEnqueueReleaseD3D11ObjectsKHR, + (cl_command_queue command_queue, cl_uint num_objects, const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event)) { + return amd::clEnqueueReleaseExtObjectsAMD(command_queue, num_objects, mem_objects, + num_events_in_wait_list, event_wait_list, event, + CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clGetPlaneFromImageAMD + * @{ + */ +RUNTIME_ENTRY_RET(cl_mem, clGetPlaneFromImageAMD, + (cl_context context, cl_mem mem, cl_uint plane, cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return 0; + } + if (mem == 0) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return 0; + } + if (!is_valid(mem)) { + *not_null(errcode_ret) = CL_INVALID_MEM_OBJECT; + return 0; + } + amd::Memory* amdMem = as_amd(mem); + amd::Context& amdContext = *as_amd(context); + if (amdMem->getInteropObj() == NULL) { + *not_null(errcode_ret) = CL_INVALID_MEM_OBJECT; + return 0; + } + amd::Image2DD3D11* pImage = reinterpret_cast(amdMem); + ID3D11Resource* pD3DResource = pImage->getD3D11Resource(); + // Verify the resource is a 2D texture + D3D11_RESOURCE_DIMENSION rType; + pD3DResource->GetType(&rType); + if (rType != D3D11_RESOURCE_DIMENSION_TEXTURE2D) { + *not_null(errcode_ret) = CL_INVALID_D3D11_RESOURCE_KHR; + return (cl_mem)0; + } + + amd::D3D11Object obj; + int errcode = amd::D3D11Object::initD3D11Object(amdContext, pD3DResource, 0, obj, plane); + if (CL_SUCCESS != errcode) { + *not_null(errcode_ret) = errcode; + return (cl_mem)0; + } + + amd::Image2DD3D11* pImage2DD3D11 = + new (amdContext) amd::Image2DD3D11(amdContext, pImage->getMemFlags(), obj); + if (!pImage2DD3D11) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_mem)0; + } + if (!pImage2DD3D11->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + pImage2DD3D11->release(); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(pImage2DD3D11); +} +RUNTIME_EXIT + +// +// +// namespace amd +// +// +namespace amd { +/*! @} + * \addtogroup CL-D3D11 interop helper functions + * @{ + */ + + +//******************************************************************* +// +// Internal implementation of CL API functions +// +//******************************************************************* +// +// clCreateBufferFromD3D11ResourceAMD +// +cl_mem clCreateBufferFromD3D11ResourceAMD(Context& amdContext, cl_mem_flags flags, + ID3D11Resource* pD3DResource, int* errcode_ret) { + // Verify pD3DResource is a buffer + D3D11_RESOURCE_DIMENSION rType; + pD3DResource->GetType(&rType); + if (rType != D3D11_RESOURCE_DIMENSION_BUFFER) { + *not_null(errcode_ret) = CL_INVALID_D3D11_RESOURCE_KHR; + return (cl_mem)0; + } + + D3D11Object obj; + int errcode = D3D11Object::initD3D11Object(amdContext, pD3DResource, 0, obj); + if (CL_SUCCESS != errcode) { + *not_null(errcode_ret) = errcode; + return (cl_mem)0; + } + + BufferD3D11* pBufferD3D11 = new (amdContext) BufferD3D11(amdContext, flags, obj); + if (!pBufferD3D11) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_mem)0; + } + if (!pBufferD3D11->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + pBufferD3D11->release(); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(pBufferD3D11); +} + +// +// clCreateImage2DFromD3D11ResourceAMD +// +cl_mem clCreateImage2DFromD3D11ResourceAMD(Context& amdContext, cl_mem_flags flags, + ID3D11Resource* pD3DResource, UINT subresource, + int* errcode_ret) { + // Verify the resource is a 2D texture + D3D11_RESOURCE_DIMENSION rType; + pD3DResource->GetType(&rType); + if (rType != D3D11_RESOURCE_DIMENSION_TEXTURE2D) { + *not_null(errcode_ret) = CL_INVALID_D3D11_RESOURCE_KHR; + return (cl_mem)0; + } + + D3D11Object obj; + int errcode = D3D11Object::initD3D11Object(amdContext, pD3DResource, subresource, obj); + if (CL_SUCCESS != errcode) { + *not_null(errcode_ret) = errcode; + return (cl_mem)0; + } + + Image2DD3D11* pImage2DD3D11 = new (amdContext) Image2DD3D11(amdContext, flags, obj); + if (!pImage2DD3D11) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_mem)0; + } + if (!pImage2DD3D11->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + pImage2DD3D11->release(); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(pImage2DD3D11); +} + +// +// clCreateImage2DFromD3D11ResourceAMD +// +cl_mem clCreateImage3DFromD3D11ResourceAMD(Context& amdContext, cl_mem_flags flags, + ID3D11Resource* pD3DResource, UINT subresource, + int* errcode_ret) { + // Verify the resource is a 2D texture + D3D11_RESOURCE_DIMENSION rType; + pD3DResource->GetType(&rType); + if (rType != D3D11_RESOURCE_DIMENSION_TEXTURE3D) { + *not_null(errcode_ret) = CL_INVALID_D3D11_RESOURCE_KHR; + return (cl_mem)0; + } + + D3D11Object obj; + int errcode = D3D11Object::initD3D11Object(amdContext, pD3DResource, subresource, obj); + if (CL_SUCCESS != errcode) { + *not_null(errcode_ret) = errcode; + return (cl_mem)0; + } + + Image3DD3D11* pImage3DD3D11 = new (amdContext) Image3DD3D11(amdContext, flags, obj); + if (!pImage3DD3D11) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_mem)0; + } + if (!pImage3DD3D11->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + pImage3DD3D11->release(); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(pImage3DD3D11); +} + +size_t D3D11Object::getResourceByteSize() { + size_t bytes = 1; + + //! @todo [odintsov]: take into consideration the mip level?! + + switch (objDesc_.objDim_) { + case D3D11_RESOURCE_DIMENSION_BUFFER: + bytes = objDesc_.objSize_.ByteWidth; + break; + + case D3D11_RESOURCE_DIMENSION_TEXTURE3D: + bytes = objDesc_.objSize_.Depth; + + case D3D11_RESOURCE_DIMENSION_TEXTURE2D: + bytes *= objDesc_.objSize_.Height; + + case D3D11_RESOURCE_DIMENSION_TEXTURE1D: + bytes *= objDesc_.objSize_.Width * getElementBytes(); + break; + + default: + LogError("getResourceByteSize: unknown type of D3D11 resource"); + bytes = 0; + break; + } + return bytes; +} + +cl_uint D3D11Object::getMiscFlag() { + if ((objDesc_.dxgiFormat_ == DXGI_FORMAT_NV12) || + (objDesc_.dxgiFormat_ == DXGI_FORMAT_P010)) { + return 1; + } + else if (objDesc_.dxgiFormat_ == DXGI_FORMAT_YUY2) { + return 3; + } + return 0; +} + +int D3D11Object::initD3D11Object(const Context& amdContext, ID3D11Resource* pRes, UINT subres, + D3D11Object& obj, INT plane) { + ID3D11Device* pDev; + HRESULT hr; + ScopedLock sl(resLock_); + + // Check if this ressource has already been used for interop + for (const auto& it : resources_) { + if (it.first == (void*)pRes && it.second.first == subres && + it.second.second == plane) { + return CL_INVALID_D3D11_RESOURCE_KHR; + } + } + + (obj.pD3D11Res_ = pRes)->GetDevice(&pDev); + + if (!pDev) { + return CL_INVALID_D3D11_DEVICE_KHR; + } + + D3D11_QUERY_DESC desc = {D3D11_QUERY_EVENT, 0}; + pDev->CreateQuery(&desc, &obj.pQuery_); + +#define SET_SHARED_FLAGS() \ + { \ + obj.pD3D11ResOrig_ = obj.pD3D11Res_; \ + /* @todo - Check device type and select right usage for resource */ \ + /* For now get only DPU path, CPU path for buffers */ \ + /* will not worl on DEFAUL resources */ \ + /*desc.Usage = D3D11_USAGE_STAGING;*/ \ + desc.Usage = D3D11_USAGE_DEFAULT; \ + desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED; \ + desc.CPUAccessFlags = 0; \ + } + +#define STORE_SHARED_FLAGS_BUFFER(restype) \ + { \ + if (S_OK == hr && obj.pD3D11Res_) { \ + obj.objDesc_.objFlags_.d3d11Usage_ = desc.Usage; \ + obj.objDesc_.objFlags_.bindFlags_ = desc.BindFlags; \ + obj.objDesc_.objFlags_.miscFlags_ = desc.MiscFlags; \ + obj.objDesc_.objFlags_.cpuAccessFlags_ = desc.CPUAccessFlags; \ + obj.objDesc_.objFlags_.structureByteStride_ = desc.StructureByteStride; \ + } else { \ + LogError("\nCannot create shared " #restype "\n"); \ + return CL_INVALID_D3D11_RESOURCE_KHR; \ + } \ + } + +#define STORE_SHARED_FLAGS(restype) \ + { \ + if (S_OK == hr && obj.pD3D11Res_) { \ + obj.objDesc_.objFlags_.d3d11Usage_ = desc.Usage; \ + obj.objDesc_.objFlags_.bindFlags_ = desc.BindFlags; \ + obj.objDesc_.objFlags_.miscFlags_ = desc.MiscFlags; \ + obj.objDesc_.objFlags_.cpuAccessFlags_ = desc.CPUAccessFlags; \ + } else { \ + LogError("\nCannot create shared " #restype "\n"); \ + return CL_INVALID_D3D11_RESOURCE_KHR; \ + } \ + } + +#define SET_BINDING() \ + { \ + switch (desc.Format) { \ + case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: \ + case DXGI_FORMAT_D32_FLOAT: \ + case DXGI_FORMAT_D24_UNORM_S8_UINT: \ + case DXGI_FORMAT_D16_UNORM: \ + desc.BindFlags = D3D11_BIND_DEPTH_STENCIL; \ + break; \ + default: \ + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; \ + break; \ + } \ + } + + pRes->GetType(&obj.objDesc_.objDim_); + + // Init defaults + obj.objDesc_.objSize_.Height = 1; + obj.objDesc_.objSize_.Depth = 1; + obj.objDesc_.mipLevels_ = 1; + obj.objDesc_.arraySize_ = 1; + obj.objDesc_.dxgiFormat_ = DXGI_FORMAT_UNKNOWN; + obj.objDesc_.dxgiSampleDesc_ = dxgiSampleDescDefault; + + switch (obj.objDesc_.objDim_) { + case D3D11_RESOURCE_DIMENSION_BUFFER: // = 1, + { + D3D11_BUFFER_DESC desc; + (reinterpret_cast(pRes))->GetDesc(&desc); + obj.objDesc_.objSize_.ByteWidth = desc.ByteWidth; + obj.objDesc_.objFlags_.d3d11Usage_ = desc.Usage; + obj.objDesc_.objFlags_.bindFlags_ = desc.BindFlags; + obj.objDesc_.objFlags_.cpuAccessFlags_ = desc.CPUAccessFlags; + obj.objDesc_.objFlags_.miscFlags_ = desc.MiscFlags; + obj.objDesc_.objFlags_.structureByteStride_ = desc.StructureByteStride; + // Handle D3D11Buffer without shared handle - create + // a duplicate with shared handle to provide for CAL + if (!(obj.objDesc_.objFlags_.miscFlags_ & D3D11_RESOURCE_MISC_SHARED)) { + SET_SHARED_FLAGS(); + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; + hr = pDev->CreateBuffer(&desc, NULL, (ID3D11Buffer**)&obj.pD3D11Res_); + STORE_SHARED_FLAGS_BUFFER(ID3D11Buffer); + } + } break; + + case D3D11_RESOURCE_DIMENSION_TEXTURE1D: // = 2, + { + D3D11_TEXTURE1D_DESC desc; + (reinterpret_cast(pRes))->GetDesc(&desc); + + if (subres) { + // Calculate correct size of the subresource + UINT miplevel = subres; + if (desc.ArraySize > 1) { + miplevel = subres % desc.ArraySize; + } + if (miplevel >= desc.MipLevels) { + LogWarning("\nMiplevel >= number of miplevels\n"); + } + if (subres >= desc.MipLevels * desc.ArraySize) { + return CL_INVALID_VALUE; + } + desc.Width >>= miplevel; + if (!desc.Width) { + desc.Width = 1; + } + } + obj.objDesc_.objSize_.Width = desc.Width; + obj.objDesc_.mipLevels_ = desc.MipLevels; + obj.objDesc_.arraySize_ = desc.ArraySize; + obj.objDesc_.dxgiFormat_ = desc.Format; + obj.objDesc_.objFlags_.d3d11Usage_ = desc.Usage; + obj.objDesc_.objFlags_.bindFlags_ = desc.BindFlags; + obj.objDesc_.objFlags_.cpuAccessFlags_ = desc.CPUAccessFlags; + obj.objDesc_.objFlags_.miscFlags_ = desc.MiscFlags; + // Handle D3D11Texture1D without shared handle - create + // a duplicate with shared handle and provide it for CAL + // Workaround for subresource > 0 in shared resource + if (subres) obj.objDesc_.objFlags_.miscFlags_ &= ~(D3D11_RESOURCE_MISC_SHARED); + if (!(obj.objDesc_.objFlags_.miscFlags_ & D3D11_RESOURCE_MISC_SHARED)) { + SET_SHARED_FLAGS(); + SET_BINDING(); + obj.objDesc_.mipLevels_ = desc.MipLevels = 1; + obj.objDesc_.arraySize_ = desc.ArraySize = 1; + hr = pDev->CreateTexture1D(&desc, NULL, (ID3D11Texture1D**)&obj.pD3D11Res_); + STORE_SHARED_FLAGS(ID3D11Texture1D); + } + } break; + + case D3D11_RESOURCE_DIMENSION_TEXTURE2D: // = 3, + { + D3D11_TEXTURE2D_DESC desc; + (reinterpret_cast(pRes))->GetDesc(&desc); + + if (subres) { + // Calculate correct size of the subresource + UINT miplevel = subres; + if (desc.ArraySize > 1) { + miplevel = subres % desc.MipLevels; + } + if (miplevel >= desc.MipLevels) { + LogWarning("\nMiplevel >= number of miplevels\n"); + } + if (subres >= desc.MipLevels * desc.ArraySize) { + return CL_INVALID_VALUE; + } + desc.Width >>= miplevel; + if (!desc.Width) { + desc.Width = 1; + } + desc.Height >>= miplevel; + if (!desc.Height) { + desc.Height = 1; + } + } + obj.objDesc_.objSize_.Width = desc.Width; + obj.objDesc_.objSize_.Height = desc.Height; + obj.objDesc_.mipLevels_ = desc.MipLevels; + obj.objDesc_.arraySize_ = desc.ArraySize; + obj.objDesc_.dxgiFormat_ = desc.Format; + obj.objDesc_.dxgiSampleDesc_ = desc.SampleDesc; + obj.objDesc_.objFlags_.d3d11Usage_ = desc.Usage; + obj.objDesc_.objFlags_.bindFlags_ = desc.BindFlags; + obj.objDesc_.objFlags_.cpuAccessFlags_ = desc.CPUAccessFlags; + obj.objDesc_.objFlags_.miscFlags_ = desc.MiscFlags; + + // Handle D3D11Texture2D without shared handle - create + // a duplicate with shared handle and provide it for CAL + // Workaround for subresource > 0 in shared resource + if (subres) obj.objDesc_.objFlags_.miscFlags_ &= ~(D3D11_RESOURCE_MISC_SHARED); + if (!(obj.objDesc_.objFlags_.miscFlags_ & D3D11_RESOURCE_MISC_SHARED)) { + SET_SHARED_FLAGS(); + SET_BINDING(); + obj.objDesc_.mipLevels_ = desc.MipLevels = 1; + obj.objDesc_.arraySize_ = desc.ArraySize = 1; + hr = pDev->CreateTexture2D(&desc, NULL, (ID3D11Texture2D**)&obj.pD3D11Res_); + STORE_SHARED_FLAGS(ID3D11Texture2D); + } + + if ((desc.Format == DXGI_FORMAT_NV12) || (desc.Format == DXGI_FORMAT_P010)) { + if (plane == -1) { + obj.objDesc_.objSize_.Height += obj.objDesc_.objSize_.Height / 2; + } + if (plane == 1) { + obj.objDesc_.objSize_.Width /= 2; + obj.objDesc_.objSize_.Height /= 2; + } + } + // RGBA8 covers 2 pixels, thus divide width by 2 + if (desc.Format == DXGI_FORMAT_YUY2) { + obj.objDesc_.objSize_.Width /= 2; + } + } break; + + case D3D11_RESOURCE_DIMENSION_TEXTURE3D: // = 4 + { + D3D11_TEXTURE3D_DESC desc; + (reinterpret_cast(pRes))->GetDesc(&desc); + + if (subres) { + // Calculate correct size of the subresource + UINT miplevel = subres; + if (miplevel >= desc.MipLevels) { + LogWarning("\nMiplevel >= number of miplevels\n"); + } + if (subres >= desc.MipLevels) { + return CL_INVALID_VALUE; + } + desc.Width >>= miplevel; + if (!desc.Width) { + desc.Width = 1; + } + desc.Height >>= miplevel; + if (!desc.Height) { + desc.Height = 1; + } + desc.Depth >>= miplevel; + if (!desc.Depth) { + desc.Depth = 1; + } + } + obj.objDesc_.objSize_.Width = desc.Width; + obj.objDesc_.objSize_.Height = desc.Height; + obj.objDesc_.objSize_.Depth = desc.Depth; + obj.objDesc_.mipLevels_ = desc.MipLevels; + obj.objDesc_.dxgiFormat_ = desc.Format; + obj.objDesc_.objFlags_.d3d11Usage_ = desc.Usage; + obj.objDesc_.objFlags_.bindFlags_ = desc.BindFlags; + obj.objDesc_.objFlags_.cpuAccessFlags_ = desc.CPUAccessFlags; + obj.objDesc_.objFlags_.miscFlags_ = desc.MiscFlags; + // Handle D3D11Texture3D without shared handle - create + // a duplicate with shared handle and provide it for CAL + // Workaround for subresource > 0 in shared resource + if (obj.objDesc_.mipLevels_ > 1) + obj.objDesc_.objFlags_.miscFlags_ &= ~(D3D11_RESOURCE_MISC_SHARED); + if (!(obj.objDesc_.objFlags_.miscFlags_ & D3D11_RESOURCE_MISC_SHARED)) { + SET_SHARED_FLAGS(); + SET_BINDING(); + obj.objDesc_.mipLevels_ = desc.MipLevels = 1; + hr = pDev->CreateTexture3D(&desc, NULL, (ID3D11Texture3D**)&obj.pD3D11Res_); + STORE_SHARED_FLAGS(ID3D11Texture3D); + } + } break; + + default: + LogError("unknown type of D3D11 resource"); + return CL_INVALID_D3D11_RESOURCE_KHR; + } + obj.subRes_ = subres; + obj.plane_ = plane; + pDev->Release(); + // Check for CL format compatibilty + if (obj.objDesc_.objDim_ != D3D11_RESOURCE_DIMENSION_BUFFER) { + cl_image_format clFmt = obj.getCLFormatFromDXGI(obj.objDesc_.dxgiFormat_, plane); + amd::Image::Format imageFormat(clFmt); + if (!imageFormat.isSupported(amdContext)) { + return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + } + } + resources_.push_back({pRes, {subres, plane}}); + return CL_SUCCESS; +} + +bool D3D11Object::copyOrigToShared() { + // Don't copy if there is no orig + if (NULL == getD3D11ResOrig()) return true; + + ID3D11Device* d3dDev; + pD3D11Res_->GetDevice(&d3dDev); + if (!d3dDev) { + LogError("\nCannot get D3D11 device from D3D11 resource\n"); + return false; + } + ID3D11DeviceContext* pImmediateContext = NULL; + d3dDev->GetImmediateContext(&pImmediateContext); + if (!pImmediateContext) { + LogError("\nCannot get D3D11 device context"); + return false; + } + assert(pD3D11ResOrig_ != NULL); + // Any usage source can be read by GPU + pImmediateContext->CopySubresourceRegion(pD3D11Res_, 0, 0, 0, 0, pD3D11ResOrig_, subRes_, NULL); + + // Flush D3D queues and make sure D3D stuff is finished + { + ScopedLock sl(resLock_); // protect from multiple + pImmediateContext->Flush(); + pImmediateContext->End(pQuery_); + BOOL data = FALSE; + while (S_OK != pImmediateContext->GetData(pQuery_, &data, sizeof(BOOL), 0)) { + } + } + + pImmediateContext->Release(); + d3dDev->Release(); + return true; +} + +bool D3D11Object::copySharedToOrig() { + // Don't copy if there is no orig + if (NULL == getD3D11ResOrig()) return true; + + ID3D11Device* d3dDev; + pD3D11Res_->GetDevice(&d3dDev); + if (!d3dDev) { + LogError("\nCannot get D3D11 device from D3D11 resource\n"); + return false; + } + ID3D11DeviceContext* pImmediateContext = NULL; + d3dDev->GetImmediateContext(&pImmediateContext); + if (!pImmediateContext) { + LogError("\nCannot get D3D11 device context"); + return false; + } + assert(pD3D11ResOrig_); + pImmediateContext->CopySubresourceRegion(pD3D11ResOrig_, subRes_, 0, 0, 0, pD3D11Res_, 0, NULL); + pImmediateContext->Release(); + + d3dDev->Release(); + return true; +} + +std::vector>> D3D11Object::resources_; +Monitor D3D11Object::resLock_; + +// +// Class BufferD3D11 implementation +// +void BufferD3D11::initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(BufferD3D11)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); +} + +// +// Class Image1DD3D11 implementation +// +void Image1DD3D11::initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(Image1DD3D11)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); +} + +// +// Class Image2DD3D11 implementation +// + +void Image2DD3D11::initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(Image2DD3D11)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); +} + +// +// Class Image3DD3D11 implementation +// +void Image3DD3D11::initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(Image3DD3D11)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); +} + +// +// Helper function SyncD3D11Objects +// +void SyncD3D11Objects(std::vector& memObjects) { + Memory*& mem = memObjects.front(); + if (!mem) { + LogWarning("\nNULL memory object\n"); + return; + } + InteropObject* interop = mem->getInteropObj(); + if (!interop) { + LogWarning("\nNULL interop object\n"); + return; + } + D3D11Object* d3dObj = interop->asD3D11Object(); + if (!d3dObj) { + LogWarning("\nNULL D3D11 object\n"); + return; + } + ID3D11Query* query = d3dObj->getQuery(); + if (!query) { + LogWarning("\nNULL ID3D11Query\n"); + return; + } + ID3D11Device* d3dDev; + query->GetDevice(&d3dDev); + if (!d3dDev) { + LogError("\nCannot get D3D11 device from D3D11 resource\n"); + return; + } + ID3D11DeviceContext* pImmediateContext = NULL; + d3dDev->GetImmediateContext(&pImmediateContext); + if (!pImmediateContext) { + LogError("\nCannot get D3D11 device context"); + return; + } + pImmediateContext->Release(); + + // Flush D3D queues and make sure D3D stuff is finished + { + ScopedLock sl(d3dObj->getResLock()); + pImmediateContext->End(query); + BOOL data = FALSE; + while ((S_OK != pImmediateContext->GetData(query, &data, sizeof(BOOL), 0)) || (data != TRUE)) { + } + } + + d3dDev->Release(); +} + +// +// Class D3D11Object implementation +// +size_t D3D11Object::getElementBytes(DXGI_FORMAT dxgiFmt, cl_uint plane) { + size_t bytesPerPixel; + + switch (dxgiFmt) { + case DXGI_FORMAT_R32G32B32A32_TYPELESS: + case DXGI_FORMAT_R32G32B32A32_FLOAT: + case DXGI_FORMAT_R32G32B32A32_UINT: + case DXGI_FORMAT_R32G32B32A32_SINT: + bytesPerPixel = 16; + break; + + case DXGI_FORMAT_R32G32B32_TYPELESS: + case DXGI_FORMAT_R32G32B32_FLOAT: + case DXGI_FORMAT_R32G32B32_UINT: + case DXGI_FORMAT_R32G32B32_SINT: + bytesPerPixel = 12; + break; + + case DXGI_FORMAT_R16G16B16A16_TYPELESS: + case DXGI_FORMAT_R16G16B16A16_FLOAT: + case DXGI_FORMAT_R16G16B16A16_UNORM: + case DXGI_FORMAT_R16G16B16A16_UINT: + case DXGI_FORMAT_R16G16B16A16_SNORM: + case DXGI_FORMAT_R16G16B16A16_SINT: + case DXGI_FORMAT_R32G32_TYPELESS: + case DXGI_FORMAT_R32G32_FLOAT: + case DXGI_FORMAT_R32G32_UINT: + case DXGI_FORMAT_R32G32_SINT: + case DXGI_FORMAT_R32G8X24_TYPELESS: + case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: + case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: + case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: + bytesPerPixel = 8; + break; + + case DXGI_FORMAT_R10G10B10A2_TYPELESS: + case DXGI_FORMAT_R10G10B10A2_UNORM: + case DXGI_FORMAT_R10G10B10A2_UINT: + case DXGI_FORMAT_R11G11B10_FLOAT: + case DXGI_FORMAT_R8G8B8A8_TYPELESS: + case DXGI_FORMAT_R8G8B8A8_UNORM: + case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: + case DXGI_FORMAT_R8G8B8A8_UINT: + case DXGI_FORMAT_R8G8B8A8_SNORM: + case DXGI_FORMAT_R8G8B8A8_SINT: + case DXGI_FORMAT_R16G16_TYPELESS: + case DXGI_FORMAT_R16G16_FLOAT: + case DXGI_FORMAT_R16G16_UNORM: + case DXGI_FORMAT_R16G16_UINT: + case DXGI_FORMAT_R16G16_SNORM: + case DXGI_FORMAT_R16G16_SINT: + case DXGI_FORMAT_R32_TYPELESS: + case DXGI_FORMAT_D32_FLOAT: + case DXGI_FORMAT_R32_FLOAT: + case DXGI_FORMAT_R32_UINT: + case DXGI_FORMAT_R32_SINT: + case DXGI_FORMAT_R24G8_TYPELESS: + case DXGI_FORMAT_D24_UNORM_S8_UINT: + case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: + case DXGI_FORMAT_X24_TYPELESS_G8_UINT: + + case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: + case DXGI_FORMAT_R8G8_B8G8_UNORM: + case DXGI_FORMAT_G8R8_G8B8_UNORM: + + case DXGI_FORMAT_B8G8R8A8_UNORM: + case DXGI_FORMAT_B8G8R8X8_UNORM: + + case DXGI_FORMAT_YUY2: + bytesPerPixel = 4; + break; + + case DXGI_FORMAT_R8G8_TYPELESS: + case DXGI_FORMAT_R8G8_UNORM: + case DXGI_FORMAT_R8G8_UINT: + case DXGI_FORMAT_R8G8_SNORM: + case DXGI_FORMAT_R8G8_SINT: + case DXGI_FORMAT_R16_TYPELESS: + case DXGI_FORMAT_R16_FLOAT: + case DXGI_FORMAT_D16_UNORM: + case DXGI_FORMAT_R16_UNORM: + case DXGI_FORMAT_R16_UINT: + case DXGI_FORMAT_R16_SNORM: + case DXGI_FORMAT_R16_SINT: + + case DXGI_FORMAT_B5G6R5_UNORM: + case DXGI_FORMAT_B5G5R5A1_UNORM: + bytesPerPixel = 2; + break; + + case DXGI_FORMAT_R8_TYPELESS: + case DXGI_FORMAT_R8_UNORM: + case DXGI_FORMAT_R8_UINT: + case DXGI_FORMAT_R8_SNORM: + case DXGI_FORMAT_R8_SINT: + case DXGI_FORMAT_A8_UNORM: + case DXGI_FORMAT_R1_UNORM: + bytesPerPixel = 1; + break; + + + case DXGI_FORMAT_BC1_TYPELESS: + case DXGI_FORMAT_BC1_UNORM: + case DXGI_FORMAT_BC1_UNORM_SRGB: + case DXGI_FORMAT_BC2_TYPELESS: + case DXGI_FORMAT_BC2_UNORM: + case DXGI_FORMAT_BC2_UNORM_SRGB: + case DXGI_FORMAT_BC3_TYPELESS: + case DXGI_FORMAT_BC3_UNORM: + case DXGI_FORMAT_BC3_UNORM_SRGB: + case DXGI_FORMAT_BC4_TYPELESS: + case DXGI_FORMAT_BC4_UNORM: + case DXGI_FORMAT_BC4_SNORM: + case DXGI_FORMAT_BC5_TYPELESS: + case DXGI_FORMAT_BC5_UNORM: + case DXGI_FORMAT_BC5_SNORM: + // Less than 1 byte per pixel - needs special consideration + bytesPerPixel = 0; + break; + case DXGI_FORMAT_NV12: + bytesPerPixel = 1; + if (plane == 1) { + bytesPerPixel = 2; + } + break; + case DXGI_FORMAT_P010: + bytesPerPixel = 2; + if (plane == 1) { + bytesPerPixel = 4; + } + break; + default: + bytesPerPixel = 0; + _ASSERT(FALSE); + break; + } + return bytesPerPixel; +} + +cl_image_format D3D11Object::getCLFormatFromDXGI(DXGI_FORMAT dxgiFmt, cl_uint plane) { + cl_image_format fmt; + + //! @todo [odintsov]: add real fmt conversion from DXGI to CL + fmt.image_channel_order = 0; // CL_RGBA; + fmt.image_channel_data_type = 0; // CL_UNSIGNED_INT8; + + switch (dxgiFmt) { + case DXGI_FORMAT_R32G32B32A32_TYPELESS: + fmt.image_channel_order = CL_RGBA; + break; + + case DXGI_FORMAT_R32G32B32A32_FLOAT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_FLOAT; + break; + + case DXGI_FORMAT_R32G32B32A32_UINT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNSIGNED_INT32; + break; + + case DXGI_FORMAT_R32G32B32A32_SINT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_SIGNED_INT32; + break; + + case DXGI_FORMAT_R32G32B32_TYPELESS: + fmt.image_channel_order = CL_RGB; + break; + + case DXGI_FORMAT_R32G32B32_FLOAT: + fmt.image_channel_order = CL_RGB; + fmt.image_channel_data_type = CL_FLOAT; + break; + + case DXGI_FORMAT_R32G32B32_UINT: + fmt.image_channel_order = CL_RGB; + fmt.image_channel_data_type = CL_UNSIGNED_INT32; + break; + + case DXGI_FORMAT_R32G32B32_SINT: + fmt.image_channel_order = CL_RGB; + fmt.image_channel_data_type = CL_SIGNED_INT32; + break; + + case DXGI_FORMAT_R16G16B16A16_TYPELESS: + fmt.image_channel_order = CL_RGBA; + break; + + case DXGI_FORMAT_R16G16B16A16_FLOAT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_HALF_FLOAT; + break; + + case DXGI_FORMAT_R16G16B16A16_UNORM: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNORM_INT16; + break; + + case DXGI_FORMAT_R16G16B16A16_UINT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNSIGNED_INT16; + break; + + case DXGI_FORMAT_R16G16B16A16_SNORM: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_SNORM_INT16; + break; + + case DXGI_FORMAT_R16G16B16A16_SINT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_SIGNED_INT16; + break; + + case DXGI_FORMAT_R32G32_TYPELESS: + fmt.image_channel_order = CL_RG; + break; + + case DXGI_FORMAT_R32G32_FLOAT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_FLOAT; + break; + + case DXGI_FORMAT_R32G32_UINT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_UNSIGNED_INT32; + break; + + case DXGI_FORMAT_R32G32_SINT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_SIGNED_INT32; + break; + + case DXGI_FORMAT_R32G8X24_TYPELESS: + break; + + case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: + break; + + case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: + break; + + case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: + break; + + case DXGI_FORMAT_R10G10B10A2_TYPELESS: + fmt.image_channel_order = CL_RGBA; + break; + + case DXGI_FORMAT_R10G10B10A2_UNORM: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNORM_INT_101010; + break; + + case DXGI_FORMAT_R10G10B10A2_UINT: + fmt.image_channel_order = CL_RGBA; + break; + + case DXGI_FORMAT_R11G11B10_FLOAT: + fmt.image_channel_order = CL_RGB; + break; + + case DXGI_FORMAT_R8G8B8A8_TYPELESS: + fmt.image_channel_order = CL_RGBA; + break; + + case DXGI_FORMAT_R8G8B8A8_UNORM: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_R8G8B8A8_UINT: + case DXGI_FORMAT_YUY2: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNSIGNED_INT8; + break; + + case DXGI_FORMAT_R8G8B8A8_SNORM: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_SNORM_INT8; + break; + + case DXGI_FORMAT_R8G8B8A8_SINT: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_SIGNED_INT8; + break; + + case DXGI_FORMAT_R16G16_TYPELESS: + fmt.image_channel_order = CL_RG; + break; + + case DXGI_FORMAT_R16G16_FLOAT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_HALF_FLOAT; + break; + + case DXGI_FORMAT_R16G16_UNORM: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_UNORM_INT16; + break; + + case DXGI_FORMAT_R16G16_UINT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_UNSIGNED_INT16; + break; + + case DXGI_FORMAT_R16G16_SNORM: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_SNORM_INT16; + break; + + case DXGI_FORMAT_R16G16_SINT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_SIGNED_INT16; + break; + + case DXGI_FORMAT_R32_TYPELESS: + fmt.image_channel_order = CL_R; + break; + + case DXGI_FORMAT_D32_FLOAT: + break; + + case DXGI_FORMAT_R32_FLOAT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_FLOAT; + break; + + case DXGI_FORMAT_R32_UINT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNSIGNED_INT32; + break; + + case DXGI_FORMAT_R32_SINT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_SIGNED_INT32; + break; + + case DXGI_FORMAT_R24G8_TYPELESS: + fmt.image_channel_order = CL_RG; + break; + + case DXGI_FORMAT_D24_UNORM_S8_UINT: + break; + + case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: + break; + + case DXGI_FORMAT_X24_TYPELESS_G8_UINT: + break; + + case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: + break; + + case DXGI_FORMAT_R8G8_B8G8_UNORM: + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_G8R8_G8B8_UNORM: + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_B8G8R8A8_UNORM: + fmt.image_channel_order = CL_BGRA; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_B8G8R8X8_UNORM: + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_R8G8_TYPELESS: + fmt.image_channel_order = CL_RG; + break; + + case DXGI_FORMAT_R8G8_UNORM: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_R8G8_UINT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_UNSIGNED_INT8; + break; + + case DXGI_FORMAT_R8G8_SNORM: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_SNORM_INT8; + break; + + case DXGI_FORMAT_R8G8_SINT: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_SIGNED_INT8; + break; + + case DXGI_FORMAT_R16_TYPELESS: + fmt.image_channel_order = CL_R; + break; + + case DXGI_FORMAT_R16_FLOAT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_HALF_FLOAT; + break; + + case DXGI_FORMAT_D16_UNORM: + fmt.image_channel_data_type = CL_UNORM_INT16; + break; + + case DXGI_FORMAT_R16_UNORM: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNORM_INT16; + break; + + case DXGI_FORMAT_R16_UINT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNSIGNED_INT16; + break; + + case DXGI_FORMAT_R16_SNORM: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_SNORM_INT16; + break; + + case DXGI_FORMAT_R16_SINT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_SIGNED_INT16; + break; + + case DXGI_FORMAT_B5G6R5_UNORM: + fmt.image_channel_data_type = CL_UNORM_SHORT_565; + break; + + case DXGI_FORMAT_B5G5R5A1_UNORM: + fmt.image_channel_order = CL_BGRA; + break; + + case DXGI_FORMAT_R8_TYPELESS: + fmt.image_channel_order = CL_R; + break; + + case DXGI_FORMAT_R8_UNORM: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_R8_UINT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNSIGNED_INT8; + break; + + case DXGI_FORMAT_R8_SNORM: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_SNORM_INT8; + break; + + case DXGI_FORMAT_R8_SINT: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_SIGNED_INT8; + break; + + case DXGI_FORMAT_A8_UNORM: + fmt.image_channel_order = CL_A; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case DXGI_FORMAT_R1_UNORM: + fmt.image_channel_order = CL_R; + break; + + case DXGI_FORMAT_BC1_TYPELESS: + case DXGI_FORMAT_BC1_UNORM: + case DXGI_FORMAT_BC1_UNORM_SRGB: + case DXGI_FORMAT_BC2_TYPELESS: + case DXGI_FORMAT_BC2_UNORM: + case DXGI_FORMAT_BC2_UNORM_SRGB: + case DXGI_FORMAT_BC3_TYPELESS: + case DXGI_FORMAT_BC3_UNORM: + case DXGI_FORMAT_BC3_UNORM_SRGB: + case DXGI_FORMAT_BC4_TYPELESS: + case DXGI_FORMAT_BC4_UNORM: + case DXGI_FORMAT_BC4_SNORM: + case DXGI_FORMAT_BC5_TYPELESS: + case DXGI_FORMAT_BC5_UNORM: + case DXGI_FORMAT_BC5_SNORM: + break; + case DXGI_FORMAT_NV12: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNSIGNED_INT8; + if (plane == 1) { + fmt.image_channel_order = CL_RG; + } + break; + case DXGI_FORMAT_P010: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNSIGNED_INT16; + if (plane == 1) { + fmt.image_channel_order = CL_RG; + } + break; + default: + _ASSERT(FALSE); + break; + } + + return fmt; +} + +} // namespace amd + +#endif //_WIN32 diff --git a/opencl/amdocl/cl_d3d11_amd.hpp b/opencl/amdocl/cl_d3d11_amd.hpp new file mode 100644 index 0000000000..6112cb6a80 --- /dev/null +++ b/opencl/amdocl/cl_d3d11_amd.hpp @@ -0,0 +1,348 @@ +/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef CL_D3D11_AMD_HPP_ +#define CL_D3D11_AMD_HPP_ + +#include "cl_d3d10_amd.hpp" +#include "platform/context.hpp" +#include "platform/memory.hpp" + +#include + +extern CL_API_ENTRY cl_mem CL_API_CALL +clGetPlaneFromImageAMD( + cl_context /* context */, + cl_mem /* mem */, + cl_uint /* plane */, + cl_int* /* errcode_ret */); + +namespace amd +{ + +typedef struct +{ + union + { + UINT ByteWidth; + UINT Width; + }; + UINT Height; + UINT Depth; +} D3D11ObjSize_t; + +typedef struct +{ + D3D11_USAGE d3d11Usage_; + UINT bindFlags_; + UINT cpuAccessFlags_; + UINT miscFlags_; + UINT structureByteStride_; +} D3D11Flags_t; + +typedef struct +{ + D3D11_RESOURCE_DIMENSION objDim_; + D3D11ObjSize_t objSize_; + D3D11Flags_t objFlags_; + UINT mipLevels_; + UINT arraySize_; + DXGI_FORMAT dxgiFormat_; + DXGI_SAMPLE_DESC dxgiSampleDesc_; +} D3D11ObjDesc_t; + +//! Class D3D11Object keeps all the info about the D3D11 object +//! from which the CL object is created +class D3D11Object : public InteropObject +{ +private: + ID3D11Resource* pD3D11Aux_; + + // @todo: TBD: Do we need to sync data after access + // or it'll be done by the D3D driver? + cl_int cliChecksum_; + bool releaseResources_; + + static bool createSharedResource(D3D11Object& obj); + static std::vector>> resources_; +protected: + //! Global lock. + static Monitor resLock_; + + ID3D11Resource* pD3D11Res_; + ID3D11Resource* pD3D11ResOrig_; + ID3D11Query* pQuery_; + D3D11ObjDesc_t objDesc_; + UINT subRes_; + INT plane_; + +public: + // Default constructor + D3D11Object() + :pD3D11Aux_(NULL) + ,cliChecksum_(0) + ,releaseResources_(false) + ,pD3D11Res_(NULL) + ,pD3D11ResOrig_(NULL) + ,pQuery_(NULL) + ,subRes_(NULL) + ,plane_(NULL) + { + memset(&objDesc_,0,sizeof(objDesc_)); + } + // Copy constructor + D3D11Object(D3D11Object& d3d11obj) + : pQuery_(NULL) + { + *this = d3d11obj; + this->releaseResources_ = true; + // Add reference to the D3D11 resource to prevent its disappearance + if(pD3D11ResOrig_) { + pD3D11ResOrig_->AddRef(); + } + else if(pD3D11Res_) { + pD3D11Res_->AddRef(); + } + assert(pD3D11Res_ != pD3D11ResOrig_); + } + + //! Virtual destructor + virtual ~D3D11Object() + { + ScopedLock sl(resLock_); + if(releaseResources_) { + // Decrement reference to the D3D11 objects + if(pD3D11Res_) pD3D11Res_->Release(); + if(pD3D11Aux_) pD3D11Aux_->Release(); + if(pD3D11ResOrig_) pD3D11ResOrig_->Release(); + if(pQuery_) pQuery_->Release(); + // Check if this resource has already been used for interop + if(resources_.size()) { + for(auto& it = resources_.cbegin(); it != resources_.cend(); it++) { + if(((pD3D11ResOrig_ && (*it).first == (void*) pD3D11ResOrig_) + || ((*it).first == (void*) pD3D11Res_)) + && (*it).second.first == subRes_ + && (*it).second.second == plane_) { + resources_.erase(it); + break; + } + } + } + } + } + + static int initD3D11Object(const Context& amdContext, ID3D11Resource* pRes, UINT subresource, + D3D11Object& obj, INT plane = -1); + + D3D11Object* asD3D11Object() { return this; } + +//! D3D11Object query functions to get D3D11 info from member variables + ID3D11Resource* getD3D11Resource() const {return pD3D11Res_;} + ID3D11Resource* getD3D11ResOrig() const {return pD3D11ResOrig_;} + D3D11_USAGE getUsage() const { return objDesc_.objFlags_.d3d11Usage_; } + void setD3D11AuxRes(ID3D11Resource* pAux) {pD3D11Aux_ = pAux;} + ID3D11Resource* getD3D11AuxRes() const {return pD3D11Aux_;} + ID3D11Query* getQuery() const {return pQuery_;} + Monitor& getResLock() { return resLock_;} + UINT getWidth() const {return objDesc_.objSize_.Width;} + UINT getHeight() const {return objDesc_.objSize_.Height;} + UINT getDepth() const {return objDesc_.objSize_.Depth;} + size_t getElementBytes(DXGI_FORMAT dxgiFomat, cl_uint plane); + size_t getElementBytes() {return getElementBytes(objDesc_.dxgiFormat_, plane_);} + DXGI_FORMAT getDxgiFormat() {return objDesc_.dxgiFormat_;} + UINT getSubresource() const {return subRes_;} + INT getPlane() const {return plane_;} + const D3D11ObjDesc_t* getObjDesc() const { return &objDesc_; } + + cl_uint getMiscFlag(void); + //! Returns bytes per pixel > 0 if conversion successful, 0 otherwise; + //! if formats are not compatible, cl format channel + //! order and type are set to 0 + cl_image_format getCLFormatFromDXGI(DXGI_FORMAT dxgiFmt, cl_uint plane); + cl_image_format getCLFormatFromDXGI() + { + return getCLFormatFromDXGI(objDesc_.dxgiFormat_, plane_); + } + size_t getResourceByteSize(); + + // On acquire copy data from original resource to shared resource + virtual bool copyOrigToShared(); + // On release copy data from shared copy to the original resource + virtual bool copySharedToOrig(); +}; + +//! Class BufferD3D11 is derived from classes Buffer and D3D11Object +//! where the former keeps all data for CL object and +//! the latter keeps all data for D3D11 object +class BufferD3D11 : public D3D11Object, public Buffer +{ +protected: + //! Initializes the device memory array which is nested + // after'BufferD3D11' object in memory layout. + virtual void initDeviceMemory(); +public: +//! BufferD3D11 constructor just calls constructors of base classes +//! to pass down the parameters + BufferD3D11( + Context& amdContext, + cl_mem_flags clFlags, + D3D11Object& d3d11obj) + : // Call base classes constructors + D3D11Object(d3d11obj), + Buffer( + amdContext, + clFlags, + d3d11obj.getResourceByteSize()) + { + setInteropObj(this); + } + virtual ~BufferD3D11() {} +}; + +//! Class Image1DD3D11 is derived from classes Image1D and D3D11Object +//! where the former keeps all data for CL object and +//! the latter keeps all data for D3D11 object +class Image1DD3D11 : public D3D11Object, public Image +{ +protected: + //! Initializes the device memory array which is nested + // after'Image1DD3D11' object in memory layout. + virtual void initDeviceMemory(); +public: +//! Image1DD3D11 constructor just calls constructors of base classes +//! to pass down the parameters + Image1DD3D11( + Context& amdContext, + cl_mem_flags clFlags, + D3D11Object& d3d11obj) + : // Call base classes constructors + D3D11Object(d3d11obj), + Image( + amdContext, + CL_MEM_OBJECT_IMAGE1D, + clFlags, + getCLFormatFromDXGI(d3d11obj.getDxgiFormat(), d3d11obj.getPlane()), //format, + d3d11obj.getWidth(), + 1, + 1, + d3d11obj.getWidth() * d3d11obj.getElementBytes(), //rowPitch), + 0) + { + setInteropObj(this); + } + virtual ~Image1DD3D11() {} +}; + +//! Class Image2DD3D11 is derived from classes Image2D and D3D11Object +//! where the former keeps all data for CL object and +//! the latter keeps all data for D3D11 object +class Image2DD3D11 : public Image, public D3D11Object +{ +protected: + //! Initializes the device memory array which is nested + // after'Image2DD3D11' object in memory layout. + virtual void initDeviceMemory(); +public: +//! Image2DD3D11 constructor just calls constructors of base classes +//! to pass down the parameters + Image2DD3D11( + Context& amdContext, + cl_mem_flags clFlags, + D3D11Object& d3d11obj) + : // Call base classes constructors + D3D11Object(d3d11obj), + Image( + amdContext, + CL_MEM_OBJECT_IMAGE2D, + clFlags, + getCLFormatFromDXGI(d3d11obj.getDxgiFormat(), d3d11obj.getPlane()), //format, + d3d11obj.getWidth(), + d3d11obj.getHeight(), + 1, + d3d11obj.getWidth() * d3d11obj.getElementBytes(), //rowPitch), + 0) + { + setInteropObj(this); + } + virtual ~Image2DD3D11() {} +}; + +//! Class Image3DD3D11 is derived from classes Image3D and D3D11Object +//! where the former keeps all data for CL object and +//! the latter keeps all data for D3D11 object +class Image3DD3D11 : public D3D11Object, public Image +{ +protected: + //! Initializes the device memory array which is nested + // after'Image3DD3D11' object in memory layout. + virtual void initDeviceMemory(); +public: +//! Image2DD3D11 constructor just calls constructors of base classes +//! to pass down the parameters + Image3DD3D11( + Context& amdContext, + cl_mem_flags clFlags, + D3D11Object& d3d11obj) + : // Call base classes constructors + D3D11Object(d3d11obj), + Image( + amdContext, + CL_MEM_OBJECT_IMAGE3D, + clFlags, + getCLFormatFromDXGI(d3d11obj.getDxgiFormat(), d3d11obj.getPlane()), //format, + d3d11obj.getWidth(), + d3d11obj.getHeight(), + d3d11obj.getDepth(), + d3d11obj.getWidth() * d3d11obj.getElementBytes(), //rowPitch), + d3d11obj.getWidth() * d3d11obj.getHeight() * d3d11obj.getElementBytes()) + { + setInteropObj(this); + } + virtual ~Image3DD3D11() {} +}; + +//! Functions for executing the D3D11 related stuff +cl_mem clCreateBufferFromD3D11ResourceAMD( + Context& amdContext, + cl_mem_flags flags, + ID3D11Resource* pD3DResource, + int* errcode_ret); +cl_mem clCreateImage1DFromD3D11ResourceAMD( + Context& amdContext, + cl_mem_flags flags, + ID3D11Resource* pD3DResource, + UINT subresource, + int* errcode_ret); +cl_mem clCreateImage2DFromD3D11ResourceAMD( + Context& amdContext, + cl_mem_flags flags, + ID3D11Resource* pD3DResource, + UINT subresource, + int* errcode_ret); +cl_mem clCreateImage3DFromD3D11ResourceAMD( + Context& amdContext, + cl_mem_flags flags, + ID3D11Resource* pD3DResource, + UINT subresource, + int* errcode_ret); +void SyncD3D11Objects(std::vector& memObjects); +} //namespace amd + +#endif //CL_D3D11_AMD_HPP_ diff --git a/opencl/amdocl/cl_d3d9.cpp b/opencl/amdocl/cl_d3d9.cpp new file mode 100644 index 0000000000..956dbfb359 --- /dev/null +++ b/opencl/amdocl/cl_d3d9.cpp @@ -0,0 +1,855 @@ +/* Copyright (c) 2012 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifdef _WIN32 + +#include "top.hpp" + +#include "cl_d3d9_amd.hpp" +#include "platform/command.hpp" + +#include +#include + +#define D3DFMT_NV_12 static_cast(MAKEFOURCC('N', 'V', '1', '2')) +#define D3DFMT_P010 static_cast(MAKEFOURCC('P', '0', '1', '0')) +#define D3DFMT_YV_12 static_cast(MAKEFOURCC('Y', 'V', '1', '2')) +#define D3DFMT_YUY2 static_cast(MAKEFOURCC('Y', 'U', 'Y', '2')) + + +RUNTIME_ENTRY(cl_int, clGetDeviceIDsFromDX9MediaAdapterKHR, + (cl_platform_id platform, cl_uint num_media_adapters, + cl_dx9_media_adapter_type_khr* media_adapters_type, void* media_adapters, + cl_dx9_media_adapter_set_khr media_adapter_set, cl_uint num_entries, + cl_device_id* devices, cl_uint* num_devices)) { + cl_int errcode; + // Accept an array of DX9 devices here as the spec mention of array of num_media_adapters size. + IDirect3DDevice9Ex** d3d9_device = static_cast(media_adapters); + cl_device_id* gpu_devices = NULL; + cl_uint num_gpu_devices = 0; + static const bool VALIDATE_ONLY = true; + + if (platform != NULL && platform != AMD_PLATFORM) { + LogWarning("\"platrform\" is not a valid AMD platform"); + return CL_INVALID_PLATFORM; + } + // check if input parameter are correct + if ((num_media_adapters == 0) || (media_adapters_type == NULL) || (media_adapters == NULL) || + (media_adapter_set != CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR && + media_adapter_set != CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR) || + (num_entries == 0 && devices != NULL)) { + return CL_INVALID_VALUE; + } + // Get GPU devices + errcode = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 0, NULL, &num_gpu_devices); + if (errcode != CL_SUCCESS && errcode != CL_DEVICE_NOT_FOUND) { + return CL_INVALID_VALUE; + } + + if (!num_gpu_devices) { + *not_null(num_devices) = 0; + return CL_DEVICE_NOT_FOUND; + } + + switch (media_adapter_set) { + case CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR: + case CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR: { + gpu_devices = new cl_device_id[num_gpu_devices]; + errcode = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, num_gpu_devices, gpu_devices, NULL); + if (errcode != CL_SUCCESS) { + break; + } + + std::vector compatible_devices; + for (cl_uint i = 0; i < num_gpu_devices; ++i) { + cl_device_id device = gpu_devices[i]; + amd::Context::Flags context_flag; + amd::Context::DeviceFlagIdx devIdx; + switch (media_adapters_type[i]) { + case CL_ADAPTER_D3D9_KHR: + context_flag = amd::Context::Flags::D3D9DeviceKhr; + devIdx = amd::Context::DeviceFlagIdx::D3D9DeviceKhrIdx; + break; + case CL_ADAPTER_D3D9EX_KHR: + context_flag = amd::Context::Flags::D3D9DeviceEXKhr; + devIdx = amd::Context::DeviceFlagIdx::D3D9DeviceEXKhrIdx; + break; + case CL_ADAPTER_DXVA_KHR: + context_flag = amd::Context::Flags::D3D9DeviceVAKhr; + devIdx = amd::Context::DeviceFlagIdx::D3D9DeviceVAKhrIdx; + break; + } + + for (cl_uint j = 0; j < num_media_adapters; ++j) { + // Since there can be multiple DX9 adapters passed in the array we need to validate + // interopability with each. + void* external_device[amd::Context::DeviceFlagIdx::LastDeviceFlagIdx] = {}; + external_device[devIdx] = d3d9_device[j]; + + if (is_valid(device) && (media_adapters_type[j] == CL_ADAPTER_D3D9EX_KHR) && + as_amd(device)->bindExternalDevice(context_flag, external_device, NULL, + VALIDATE_ONLY)) { + compatible_devices.push_back(as_amd(device)); + } + } + } + if (compatible_devices.size() == 0) { + *not_null(num_devices) = 0; + errcode = CL_DEVICE_NOT_FOUND; + break; + } + + auto it = compatible_devices.cbegin(); + cl_uint compatible_count = std::min(num_entries, (cl_uint)compatible_devices.size()); + + while (compatible_count--) { + *devices++ = as_cl(*it++); + --num_entries; + } + while (num_entries--) { + *devices++ = (cl_device_id)0; + } + + *not_null(num_devices) = (cl_uint)compatible_devices.size(); + } break; + + default: + LogWarning("\"d3d9_device_set\" is invalid"); + errcode = CL_INVALID_VALUE; + } + + delete[] gpu_devices; + return errcode; +} +RUNTIME_EXIT + +RUNTIME_ENTRY_RET(cl_mem, clCreateFromDX9MediaSurfaceKHR, + (cl_context context, cl_mem_flags flags, + cl_dx9_media_adapter_type_khr adapter_type, void* surface_info, cl_uint plane, + cl_int* errcode_ret)) { + cl_mem clMemObj = NULL; + + cl_dx9_surface_info_khr* cl_surf_info = NULL; + + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return clMemObj; + } + + if (!flags) flags = CL_MEM_READ_WRITE; + if (!(((flags & CL_MEM_READ_ONLY) == CL_MEM_READ_ONLY) || + ((flags & CL_MEM_WRITE_ONLY) == CL_MEM_WRITE_ONLY) || + ((flags & CL_MEM_READ_WRITE) == CL_MEM_READ_WRITE))) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return clMemObj; + } + + if ((adapter_type != CL_ADAPTER_D3D9_KHR) && (adapter_type != CL_ADAPTER_D3D9EX_KHR) && + (adapter_type != CL_ADAPTER_DXVA_KHR)) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return clMemObj; + } + + if (!surface_info) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("parameter \"pD3DResource\" is a NULL pointer"); + return clMemObj; + } + + cl_surf_info = (cl_dx9_surface_info_khr*)surface_info; + IDirect3DSurface9* pD3D9Resource = cl_surf_info->resource; + HANDLE shared_handle = cl_surf_info->shared_handle; + + if (!pD3D9Resource) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("parameter \"surface_info\" is a NULL pointer"); + return clMemObj; + } + + D3DSURFACE_DESC Desc; + pD3D9Resource->GetDesc(&Desc); + + if ((Desc.Format != D3DFMT_NV_12) && + (Desc.Format != D3DFMT_P010) && + (Desc.Format != D3DFMT_YV_12) && (plane != 0)) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("The plane has to be Zero if the surface format is non-planar !"); + return clMemObj; + } + + // Check for image support + const std::vector& devices = as_amd(context)->devices(); + bool supportPass = false; + bool sizePass = false; + for (const auto& it : devices) { + if (it->info().imageSupport_) { + supportPass = true; + } + } + if (!supportPass) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + LogWarning("there are no devices in context to support images"); + return (cl_mem)0; + } + // Verify the resource is a 2D image + return amd::clCreateImage2DFromD3D9ResourceAMD(*as_amd(context), flags, adapter_type, + cl_surf_info, plane, errcode_ret); +} +RUNTIME_EXIT + +RUNTIME_ENTRY(cl_int, clEnqueueAcquireDX9MediaSurfacesKHR, + (cl_command_queue command_queue, cl_uint num_objects, const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event)) { + return amd::clEnqueueAcquireExtObjectsAMD(command_queue, num_objects, mem_objects, + num_events_in_wait_list, event_wait_list, event, + CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR); +} +RUNTIME_EXIT + +RUNTIME_ENTRY(cl_int, clEnqueueReleaseDX9MediaSurfacesKHR, + (cl_command_queue command_queue, cl_uint num_objects, const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event)) { + return amd::clEnqueueReleaseExtObjectsAMD(command_queue, num_objects, mem_objects, + num_events_in_wait_list, event_wait_list, event, + CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR); +} +RUNTIME_EXIT + +// +// +// namespace amd +// +// +namespace amd { +/*! @} + * \addtogroup CL-D3D9 interop helper functions + * @{ + */ +// +// Class D3D9Object implementation +// +std::vector> D3D9Object::resources_; +Monitor D3D9Object::resLock_; + +// +// clCreateImage2DFromD3D9ResourceAMD +// +cl_mem clCreateImage2DFromD3D9ResourceAMD(Context& amdContext, cl_mem_flags flags, + cl_dx9_media_adapter_type_khr adapter_type, + cl_dx9_surface_info_khr* surface_info, cl_uint plane, + int* errcode_ret) { + cl_dx9_surface_info_khr* cl_surf_info = reinterpret_cast(surface_info); + IDirect3DSurface9* pD3D9Resource = cl_surf_info->resource; + HANDLE shared_handle = cl_surf_info->shared_handle; + + D3D9Object obj; + cl_int errcode = D3D9Object::initD3D9Object(amdContext, adapter_type, surface_info, plane, obj); + if (CL_SUCCESS != errcode) { + *not_null(errcode_ret) = errcode; + return (cl_mem)0; + } + + Image2DD3D9* pImage2DD3D9 = new (amdContext) Image2DD3D9(amdContext, flags, obj); + if (!pImage2DD3D9) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_mem)0; + } + if (!pImage2DD3D9->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + pImage2DD3D9->release(); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(pImage2DD3D9); +} + +// +// Helper function SyncD3D9Objects +// +void SyncD3D9Objects(std::vector& memObjects) { + Memory*& mem = memObjects.front(); + if (!mem) { + LogWarning("\nNULL memory object\n"); + return; + } + InteropObject* interop = mem->getInteropObj(); + if (!interop) { + LogWarning("\nNULL interop object\n"); + return; + } + D3D9Object* d3d9Obj = interop->asD3D9Object(); + if (!d3d9Obj) { + LogWarning("\nNULL D3D9 object\n"); + return; + } + IDirect3DQuery9* query = d3d9Obj->getQuery(); + if (!query) { + LogWarning("\nNULL IDirect3DQuery9\n"); + return; + } + ScopedLock sl(d3d9Obj->getResLock()); + query->Issue(D3DISSUE_END); + BOOL data = FALSE; + while (S_OK != query->GetData(&data, sizeof(BOOL), D3DGETDATA_FLUSH)) { + } +} + +// +// Class D3D10Object implementation +// +size_t D3D9Object::getElementBytes(D3DFORMAT d3d9Format, cl_uint plane) { + size_t bytesPerPixel; + + switch (d3d9Format) { + case D3DFMT_UNKNOWN: + case D3DFMT_UYVY: + case D3DFMT_DXT1: + case D3DFMT_DXT2: + case D3DFMT_DXT3: + case D3DFMT_DXT4: + case D3DFMT_DXT5: + case D3DFMT_VERTEXDATA: + case D3DFMT_D32: + case D3DFMT_D15S1: + case D3DFMT_D24S8: + case D3DFMT_D24X8: + case D3DFMT_D24X4S4: + case D3DFMT_D16: + case D3DFMT_INDEX16: + case D3DFMT_INDEX32: + case D3DFMT_MULTI2_ARGB8: + case D3DFMT_CxV8U8: + // Less than 1 byte per pixel - needs special consideration + bytesPerPixel = 0; + break; + + case D3DFMT_R3G3B2: + case D3DFMT_P8: + case D3DFMT_A8: + case D3DFMT_L8: + case D3DFMT_A4L4: + bytesPerPixel = 1; + break; + + case D3DFMT_R16F: + case D3DFMT_R5G6B5: + case D3DFMT_X1R5G5B5: + case D3DFMT_A1R5G5B5: + case D3DFMT_A4R4G4B4: + case D3DFMT_A8R3G3B2: + case D3DFMT_X4R4G4B4: + case D3DFMT_A8P8: + case D3DFMT_A8L8: + case D3DFMT_V8U8: + case D3DFMT_L6V5U5: + case D3DFMT_D16_LOCKABLE: + case D3DFMT_L16: + bytesPerPixel = 2; + break; + + case D3DFMT_R8G8B8: + case D3DFMT_D24FS8: + bytesPerPixel = 3; + break; + + case D3DFMT_D32F_LOCKABLE: + case D3DFMT_A8R8G8B8: + case D3DFMT_R32F: + case D3DFMT_X8R8G8B8: + case D3DFMT_A2B10G10R10: + case D3DFMT_A8B8G8R8: + case D3DFMT_X8B8G8R8: + case D3DFMT_G16R16: + case D3DFMT_A2R10G10B10: + case D3DFMT_Q8W8V8U8: + case D3DFMT_X8L8V8U8: + case D3DFMT_V16U16: + case D3DFMT_A2W10V10U10: + case D3DFMT_R8G8_B8G8: + case D3DFMT_G8R8_G8B8: + case D3DFMT_G16R16F: + case D3DFMT_YUY2: + bytesPerPixel = 4; + break; + + case D3DFMT_G32R32F: + case D3DFMT_A16B16G16R16: + case D3DFMT_A16B16G16R16F: + case D3DFMT_Q16W16V16U16: + bytesPerPixel = 8; + break; + case D3DFMT_A32B32G32R32F: + bytesPerPixel = 16; + break; + //#if !defined(D3D_DISABLE_9EX) + // case D3DFMT_D32_LOCKABLE: + // case D3DFMT_S8_LOCKABLE: + //#endif // !D3D_DISABLE_9EX + case D3DFMT_NV_12: + if (plane == 0) { + bytesPerPixel = 1; + } else if (plane == 1) { + bytesPerPixel = 2; + } // plane != 0 or != 1 shouldn't happen here + break; + case D3DFMT_P010: + if (plane == 0) { + bytesPerPixel = 2; + } else if (plane == 1) { + bytesPerPixel = 4; + } // plane != 0 or != 1 shouldn't happen here + break; + case D3DFMT_YV_12: + bytesPerPixel = 1; + break; + + default: + bytesPerPixel = 0; + _ASSERT(FALSE); + break; + } + return bytesPerPixel; +} + +void setObjDesc(amd::D3D9ObjDesc_t& objDesc, D3DSURFACE_DESC& resDesc, cl_uint plane) { + objDesc.d3dPool_ = resDesc.Pool; + objDesc.resType_ = resDesc.Type; + objDesc.usage_ = resDesc.Usage; + objDesc.d3dFormat_ = resDesc.Format; + switch (resDesc.Format) { + case D3DFMT_NV_12: + case D3DFMT_P010: + objDesc.surfRect_.left = 0; + objDesc.surfRect_.top = 0; + if (plane == 0) { + objDesc.objSize_.Height = resDesc.Height; + objDesc.objSize_.Width = resDesc.Width; + objDesc.surfRect_.right = resDesc.Width; // resDesc.Width/2-1; + objDesc.surfRect_.bottom = 3 * resDesc.Height / 2; + ; // 3*resDesc.Height/2-1; + } else if (plane == 1) { + objDesc.objSize_.Height = resDesc.Height / 2; + objDesc.objSize_.Width = resDesc.Width / 2; + objDesc.surfRect_.right = resDesc.Width; // resDesc.Width/2-1; + objDesc.surfRect_.bottom = 3 * resDesc.Height / 2; + ; // 3*resDesc.Height/2-1; + } // plane != 0 or != 1 shouldn't happen here + break; + case D3DFMT_YV_12: + objDesc.surfRect_.left = 0; + if (plane == 0) { + objDesc.objSize_.Height = resDesc.Height; + objDesc.objSize_.Width = resDesc.Width; + objDesc.surfRect_.top = 0; + objDesc.surfRect_.right = resDesc.Width - 1; + objDesc.surfRect_.bottom = resDesc.Height - 1; + } else if (plane == 1) { + objDesc.objSize_.Height = resDesc.Height / 2; + objDesc.objSize_.Width = resDesc.Width / 2; + objDesc.surfRect_.top = resDesc.Height; + objDesc.surfRect_.right = resDesc.Width / 2 - 1; + objDesc.surfRect_.bottom = 3 * resDesc.Height / 2 - 1; + } else if (plane == 2) { + objDesc.objSize_.Height = resDesc.Height / 2; + objDesc.objSize_.Width = resDesc.Width / 2; + objDesc.surfRect_.top = 3 * resDesc.Height / 2; + objDesc.surfRect_.right = resDesc.Width / 2 - 1; + objDesc.surfRect_.bottom = 2 * resDesc.Height - 1; + } // plane > 0 or > 2 shouldn't happen here + break; + default: + objDesc.objSize_.Height = resDesc.Height; + objDesc.objSize_.Width = resDesc.Width; + objDesc.surfRect_.left = 0; + objDesc.surfRect_.top = 0; + objDesc.surfRect_.right = resDesc.Width - 1; + objDesc.surfRect_.bottom = resDesc.Height - 1; + if (resDesc.Format == D3DFMT_YUY2) { + objDesc.objSize_.Width >>= 1; + } + break; + } +} + +int D3D9Object::initD3D9Object(const Context& amdContext, + cl_dx9_media_adapter_type_khr adapter_type, + cl_dx9_surface_info_khr* cl_surf_info, cl_uint plane, + D3D9Object& obj) { + ScopedLock sl(resLock_); + + IDirect3DDevice9Ex* pDev9Ex = NULL; + cl_int errcode = CL_SUCCESS; + + // Check if this ressource has already been used for interop + IDirect3DSurface9* pD3D9res = cl_surf_info->resource; + HANDLE shared_handle = cl_surf_info->shared_handle; + + if ((adapter_type == CL_ADAPTER_D3D9_KHR) || (adapter_type == CL_ADAPTER_DXVA_KHR)) { + return CL_INVALID_DX9_MEDIA_ADAPTER_KHR; // Not supported yet + } + + for (const auto& it : resources_) { + if (it.first.surfInfo.resource == cl_surf_info->resource && it.first.surfPlane == plane) { + return CL_INVALID_D3D9_RESOURCE_KHR; + } + } + + HRESULT hr; + D3DQUERYTYPE desc = D3DQUERYTYPE_EVENT; + + D3DSURFACE_DESC resDesc; + if (D3D_OK != pD3D9res->GetDesc(&resDesc)) { + return CL_INVALID_D3D9_RESOURCE_KHR; + } + + hr = pD3D9res->GetContainer(IID_IDirect3DDevice9Ex, (void**)&pDev9Ex); + if (hr == D3D_OK) { + pDev9Ex->CreateQuery(desc, &(obj.pQuery_)); + } else { + return CL_INVALID_D3D9_RESOURCE_KHR; // d3d9ex should be supported + } + + obj.handleShared_ = shared_handle; + obj.surfPlane_ = plane; + obj.surfInfo_ = *cl_surf_info; + obj.adapterType_ = adapter_type; + + // Init defaults + setObjDesc(obj.objDescOrig_, resDesc, plane); + obj.objDesc_ = obj.objDescOrig_; + + // shared handle cases if the shared_handle is NULL + // first check if the format is NV12 or YV12, which we need special handling + if (NULL == shared_handle) { + bool found = false; + for (const auto& it : resources_) { + if (it.first.surfInfo.resource == cl_surf_info->resource && + it.first.surfPlane != plane) { + obj.handleShared_ = it.second.surfInfo.shared_handle; + obj.pD3D9Res_ = it.second.surfInfo.resource; + obj.pD3D9Res_->AddRef(); + obj.objDesc_ = obj.objDescOrig_; + found = true; + break; + } + } + if (!found) { + obj.handleShared_ = 0; + hr = pDev9Ex->CreateOffscreenPlainSurface(resDesc.Width, resDesc.Height, resDesc.Format, + resDesc.Pool, &obj.pD3D9Res_, &obj.handleShared_); + + if (D3D_OK != hr) { + errcode = CL_INVALID_D3D9_RESOURCE_KHR; + } + } + + // put the original info into the obj + obj.pD3D9ResOrig_ = pD3D9res; + obj.pD3D9ResOrig_->AddRef(); // addRef in case lost the resource + } else { + // Share the original resource + obj.pD3D9ResOrig_ = NULL; + obj.pD3D9Res_ = pD3D9res; + obj.pD3D9Res_->AddRef(); + } + + // Release the Ex interface + if (pDev9Ex) pDev9Ex->Release(); + + // Check for CL format compatibilty + if (obj.objDesc_.resType_ == D3DRTYPE_SURFACE) { + cl_image_format clFmt = obj.getCLFormatFromD3D9(obj.objDesc_.d3dFormat_, plane); + amd::Image::Format imageFormat(clFmt); + if (!imageFormat.isSupported(amdContext)) { + return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + } + } + + TD3D9RESINFO d3d9ObjOri = {*cl_surf_info, plane}; + TD3D9RESINFO d3d9ObjShared = {{obj.pD3D9Res_, obj.handleShared_}, plane}; + + if (errcode == CL_SUCCESS) { + resources_.push_back({d3d9ObjOri, d3d9ObjShared}); + } + + return errcode; +} +cl_uint D3D9Object::getMiscFlag() { + switch (objDescOrig_.d3dFormat_) { + case D3DFMT_NV_12: + case D3DFMT_P010: + return 1; + break; + case D3DFMT_YV_12: + return 2; + break; + case D3DFMT_YUY2: + return 3; + break; + default: + return 0; + break; + } +} + +cl_image_format D3D9Object::getCLFormatFromD3D9() { + return getCLFormatFromD3D9(objDesc_.d3dFormat_, surfPlane_); +} + +cl_image_format D3D9Object::getCLFormatFromD3D9(D3DFORMAT d3d9Fmt, cl_uint plane) { + cl_image_format fmt; + + fmt.image_channel_order = 0; // CL_RGBA; + fmt.image_channel_data_type = 0; // CL_UNSIGNED_INT8; + + switch (d3d9Fmt) { + case D3DFMT_R32F: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_FLOAT; + break; + + case D3DFMT_R16F: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_HALF_FLOAT; + break; + + case D3DFMT_L16: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNORM_INT16; + break; + + case D3DFMT_A8: + fmt.image_channel_order = CL_A; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case D3DFMT_L8: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case D3DFMT_G32R32F: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_FLOAT; + break; + + case D3DFMT_G16R16F: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_HALF_FLOAT; + break; + + case D3DFMT_G16R16: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_UNORM_INT16; + break; + + case D3DFMT_A8L8: + fmt.image_channel_order = CL_RG; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case D3DFMT_A32B32G32R32F: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_FLOAT; + break; + + case D3DFMT_A16B16G16R16F: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_HALF_FLOAT; + break; + + case D3DFMT_A16B16G16R16: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNORM_INT16; + break; + + case D3DFMT_A8B8G8R8: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case D3DFMT_X8B8G8R8: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case D3DFMT_A8R8G8B8: + fmt.image_channel_order = CL_BGRA; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case D3DFMT_X8R8G8B8: + fmt.image_channel_order = CL_BGRA; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + case D3DFMT_NV_12: + fmt.image_channel_data_type = CL_UNORM_INT8; + if (plane == 0) { + fmt.image_channel_order = CL_R; + } else if (plane == 1) { + fmt.image_channel_order = CL_RG; + } + break; + case D3DFMT_P010: + fmt.image_channel_data_type = CL_UNORM_INT16; + if (plane == 0) { + fmt.image_channel_order = CL_R; + } else if (plane == 1) { + fmt.image_channel_order = CL_RG; + } + break; + case D3DFMT_YV_12: + fmt.image_channel_order = CL_R; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + case D3DFMT_YUY2: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNSIGNED_INT8; + break; + case D3DFMT_UNKNOWN: + case D3DFMT_R8G8B8: + case D3DFMT_R5G6B5: + case D3DFMT_X1R5G5B5: + case D3DFMT_A1R5G5B5: + case D3DFMT_A4R4G4B4: + case D3DFMT_R3G3B2: + case D3DFMT_A8R3G3B2: + case D3DFMT_X4R4G4B4: + case D3DFMT_A2B10G10R10: + case D3DFMT_A2R10G10B10: + case D3DFMT_A8P8: + case D3DFMT_P8: + case D3DFMT_A4L4: + case D3DFMT_V8U8: + case D3DFMT_L6V5U5: + case D3DFMT_X8L8V8U8: + case D3DFMT_Q8W8V8U8: + case D3DFMT_V16U16: + case D3DFMT_A2W10V10U10: + case D3DFMT_UYVY: + case D3DFMT_R8G8_B8G8: + case D3DFMT_G8R8_G8B8: + case D3DFMT_DXT1: + case D3DFMT_DXT2: + case D3DFMT_DXT3: + case D3DFMT_DXT4: + case D3DFMT_DXT5: + case D3DFMT_D16_LOCKABLE: + case D3DFMT_D32: + case D3DFMT_D15S1: + case D3DFMT_D24S8: + case D3DFMT_D24X8: + case D3DFMT_D24X4S4: + case D3DFMT_D16: + case D3DFMT_D32F_LOCKABLE: + case D3DFMT_D24FS8: + //#if !defined(D3D_DISABLE_9EX) + case D3DFMT_D32_LOCKABLE: + case D3DFMT_S8_LOCKABLE: + //#endif // !D3D_DISABLE_9EX + case D3DFMT_VERTEXDATA: + case D3DFMT_INDEX16: + case D3DFMT_INDEX32: + case D3DFMT_Q16W16V16U16: + case D3DFMT_MULTI2_ARGB8: + case D3DFMT_CxV8U8: + //#if !defined(D3D_DISABLE_9EX) + case D3DFMT_A1: + case D3DFMT_A2B10G10R10_XR_BIAS: + case D3DFMT_BINARYBUFFER: + _ASSERT(FALSE); // NOT SURPPORTED + break; + //#endif // !D3D_DISABLE_9EX + default: + _ASSERT(FALSE); + break; + } + + return fmt; +} + +bool D3D9Object::copyOrigToShared() { + // Don't copy if there is no orig + if (NULL == getD3D9ResOrig()) return true; + + IDirect3DDevice9Ex* d3dDev; + HRESULT hr; + ScopedLock sl(getResLock()); + + IDirect3DSurface9* srcSurf = getD3D9ResOrig(); + IDirect3DSurface9* dstSurf = getD3D9Resource(); + + hr = getD3D9Resource()->GetContainer(IID_IDirect3DDevice9Ex, (void**)&d3dDev); + if (hr != D3D_OK || !d3dDev) { + LogError("\nCannot get D3D9 device from D3D9 surface\n"); + return false; + } + + hr = d3dDev->StretchRect(srcSurf, NULL, dstSurf, NULL, D3DTEXF_NONE); + if (hr != D3D_OK) { + LogError("\ncopy original surface to shared surface failed\n"); + return false; + } + // Flush D3D queues and make sure D3D stuff is finished + pQuery_->Issue(D3DISSUE_END); + BOOL data; + while ((D3D_OK != pQuery_->GetData(&data, sizeof(BOOL), D3DGETDATA_FLUSH)) && (data != TRUE)) { + } + + if (d3dDev) d3dDev->Release(); + return true; +} + +bool D3D9Object::copySharedToOrig() { + // Don't copy if there is no orig + if (NULL == getD3D9ResOrig()) return true; + + IDirect3DDevice9Ex* d3dDev; + HRESULT hr; + ScopedLock sl(getResLock()); + + hr = getD3D9Resource()->GetContainer(IID_IDirect3DDevice9Ex, (void**)&d3dDev); + if (hr != D3D_OK || !d3dDev) { + LogError("\nCannot get D3D9 device from D3D9 surface\n"); + return false; + } + + hr = d3dDev->StretchRect(getD3D9Resource(), NULL, getD3D9ResOrig(), NULL, D3DTEXF_NONE); + if (hr != D3D_OK) { + LogError("\ncopy shared surface to original surface failed\n"); + return false; + } + + if (d3dDev) d3dDev->Release(); + return true; +} + +void Image2DD3D9::initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(Image2DD3D9)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); +} + +} // namespace amd + +#endif //_WIN32 diff --git a/opencl/amdocl/cl_d3d9_amd.hpp b/opencl/amdocl/cl_d3d9_amd.hpp new file mode 100644 index 0000000000..c1967408af --- /dev/null +++ b/opencl/amdocl/cl_d3d9_amd.hpp @@ -0,0 +1,218 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +/* $Revision$ on $Date$ */ + +#ifndef __OPENCL_CL_D3D9_AMD_H +#define __OPENCL_CL_D3D9_AMD_H + +#include "cl_common.hpp" +#include "platform/context.hpp" +#include "platform/memory.hpp" + +#include + +/* cl_amd_d3d9_sharing extension */ +#define cl_amd_d3d9_sharing 1 + +/* cl_amd_d3d9_sharing error codes */ +#define CL_INVALID_D3D9_DEVICE_KHR -1021 +#define CL_INVALID_D3D9_RESOURCE_KHR -1022 + +/* cl_amd_d3d9_sharing enumerations */ +#define CL_CONTEXT_D3D9_DEVICE_KHR 0x4039 + +namespace amd +{ +typedef struct +{ + union + { + UINT ByteWidth; + UINT Width; + }; + UINT Height; + UINT Depth; +} D3D9ObjSize_t; + +typedef struct +{ + D3D9ObjSize_t objSize_; + D3DFORMAT d3dFormat_; + D3DRESOURCETYPE resType_; + UINT usage_; + D3DPOOL d3dPool_; + D3DMULTISAMPLE_TYPE msType_; + UINT msQuality_; + UINT mipLevels_; + UINT fvf_; + RECT surfRect_; +} D3D9ObjDesc_t; + +typedef struct d3d9ResInfo { + cl_dx9_surface_info_khr surfInfo; + cl_uint surfPlane; +} TD3D9RESINFO; + + +//typedef std::pair TD3D9OBJINFO; + +//! Class D3D9Object keeps all the info about the D3D9 object +//! from which the CL object is created +class D3D9Object : public InteropObject +{ +private: + IDirect3DSurface9* pD3D9Aux_; + cl_int cliChecksum_; + bool releaseResources_; + static bool createSharedResource(D3D9Object& obj); + static std::vector> resources_; + + //!Global lock + static Monitor resLock_; + cl_uint surfPlane_; + cl_dx9_surface_info_khr surfInfo_; + +protected: + IDirect3DSurface9* pD3D9Res_; + IDirect3DSurface9* pD3D9ResOrig_; + IDirect3DQuery9* pQuery_; + D3D9ObjDesc_t objDesc_; + D3D9ObjDesc_t objDescOrig_; + HANDLE handleOrig_; + HANDLE handleShared_; + RECT srcSurfRect; + RECT SharedSurfRect; + cl_dx9_media_adapter_type_khr adapterType_; + +public: +//! D3D9Object constructor initializes memeber variables + D3D9Object() + : releaseResources_(false), + pQuery_(NULL) + { + // @todo Incorrect initialization!!! + memset(this, 0, sizeof(D3D9Object)); + } + //copy constructor + D3D9Object(D3D9Object& d3d9obj) + :pQuery_(NULL) + { + *this = d3d9obj; + this->releaseResources_ = true; + } + + //virtual destructor + virtual ~D3D9Object() + { + ScopedLock sl(resLock_); + if(releaseResources_) { + if(pD3D9ResOrig_) pD3D9ResOrig_->Release(); + if(pD3D9Res_) pD3D9Res_->Release(); + if(pD3D9Aux_) pD3D9Aux_->Release(); + if(pQuery_) pQuery_->Release(); + //if the resouce is being used + if(resources_.size()) { + for(auto& it = resources_.cbegin(); it != resources_.cend(); it++) { + if( surfInfo_.resource && + ((*it).first.surfInfo.resource == surfInfo_.resource) && + ((*it).first.surfPlane == surfPlane_)) { + resources_.erase(it); + break; + } + } + } + } + } + static int initD3D9Object(const Context& amdContext, cl_dx9_media_adapter_type_khr adapter_type, + cl_dx9_surface_info_khr* cl_surf_info, cl_uint plane, D3D9Object& obj); + cl_uint getMiscFlag(void); + + D3D9Object* asD3D9Object() {return this;} + IDirect3DSurface9* getD3D9Resource() const {return pD3D9Res_;} + HANDLE getD3D9SharedHandle() const {return handleShared_;} + IDirect3DSurface9* getD3D9ResOrig() const {return pD3D9ResOrig_;} + RECT* getSrcSurfRect() {return &objDesc_.surfRect_;} + RECT* getSharedSurfRect() {return &objDescOrig_.surfRect_;} + void setD3D9AuxRes(IDirect3DSurface9* pAux) {pD3D9Aux_ = pAux;} + IDirect3DSurface9* getD3D9AuxRes() {return pD3D9Aux_;} + IDirect3DQuery9* getQuery() const {return pQuery_;} + Monitor & getResLock() { return resLock_;} + UINT getWidth() const {return objDesc_.objSize_.Width;} + UINT getHeight() const {return objDesc_.objSize_.Height;} + cl_uint getPlane() const {return surfPlane_;} + cl_dx9_media_adapter_type_khr getAdapterType() const { return adapterType_;}; + const cl_dx9_surface_info_khr& getSurfInfo() const {return surfInfo_;}; + size_t getElementBytes(D3DFORMAT d3d9Format, cl_uint plane); + size_t getElementBytes() {return getElementBytes(objDesc_.d3dFormat_, surfPlane_);} + D3DFORMAT getD3D9Format() {return objDesc_.d3dFormat_;} + D3D9ObjDesc_t* getObjDesc() {return &objDesc_;} + cl_image_format getCLFormatFromD3D9(); + cl_image_format getCLFormatFromD3D9(D3DFORMAT d3d9Fmt, cl_uint plane); + // On acquire copy data from original resource to shared resource + virtual bool copyOrigToShared(); + // On release copy data from shared copy to the original resource + virtual bool copySharedToOrig(); +}; + +class Image2DD3D9 : public D3D9Object , public Image +{ +protected: + //! Initializes the device memory array which is nested + // after'Image2DD3D9' object in memory layout. + virtual void initDeviceMemory(); +public: +//! Image2DD3D9 constructor just calls constructors of base classes +//! to pass down the parameters + Image2DD3D9( + Context& amdContext, + cl_mem_flags clFlags, + D3D9Object& d3d9obj) + : // Call base classes constructors + D3D9Object(d3d9obj), + Image( + amdContext, + CL_MEM_OBJECT_IMAGE2D, + clFlags, + d3d9obj.getCLFormatFromD3D9(), + d3d9obj.getWidth(), + d3d9obj.getHeight(), + 1, + d3d9obj.getWidth() * d3d9obj.getElementBytes(), //rowPitch), + 0) + { + setInteropObj(this); + } + virtual ~Image2DD3D9() {} +}; + +cl_mem clCreateImage2DFromD3D9ResourceAMD( + Context& amdContext, + cl_mem_flags flags, + cl_dx9_media_adapter_type_khr adapter_type, + cl_dx9_surface_info_khr* surface_info, + cl_uint plane, + int* errcode_ret); + +void SyncD3D9Objects(std::vector& memObjects); + +} //namespace amd + +#endif /* __OPENCL_CL_D3D9_AMD_H */ diff --git a/opencl/amdocl/cl_device.cpp b/opencl/amdocl/cl_device.cpp new file mode 100644 index 0000000000..9e2e6f68ae --- /dev/null +++ b/opencl/amdocl/cl_device.cpp @@ -0,0 +1,496 @@ +/* Copyright (c) 2008 - 2022 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include "vdi_common.hpp" +#include "device/device.hpp" +#include "platform/runtime.hpp" +#include "utils/versions.hpp" +#include "os/os.hpp" +#include "cl_semaphore_amd.h" + +#include "CL/cl_ext.h" + +#include // for alloca + +/*! \addtogroup API + * @{ + * + * \addtogroup CL_PlatformInfo + * @{ + */ + +/*! \brief Get the list of available platforms. + * + * \param num_entries is the number of cl_platform_id entries that can be added + * to platforms. If \a platforms is not NULL, the \a num_entries must be greater + * than zero. + * + * \param platforms returns a list of OpenCL platforms found. The cl_platform_id + * values returned in \a platforms can be used to identify a specific OpenCL + * platform. If \a platforms argument is NULL, this argument is ignored. The + * number of OpenCL platforms returned is the mininum of the value specified by + * \a num_entries or the number of OpenCL platforms available. + * + * \param num_platforms returns the number of OpenCL platforms available. If + * \a num_platforms is NULL, this argument is ignored. + * + * \return CL_INVALID_VALUE if num_entries is equal to zero and platforms is not + * NULL or if both num_platforms and platforms are NULL, and returns CL_SUCCESS + * if the function is executed successfully. + * + * \version 1.0r33 + */ + +RUNTIME_ENTRY(cl_int, clGetPlatformIDs, + (cl_uint num_entries, cl_platform_id* platforms, cl_uint* num_platforms)) { + if (!amd::Runtime::initialized()) { + amd::Runtime::init(); + } + + if (((num_entries > 0 || num_platforms == NULL) && platforms == NULL) || + (num_entries == 0 && platforms != NULL)) { + return CL_INVALID_VALUE; + } + if (num_platforms != NULL && platforms == NULL) { + *num_platforms = 1; + return CL_SUCCESS; + } + + assert(platforms != NULL && "check the code above"); + *platforms = AMD_PLATFORM; + + *not_null(num_platforms) = 1; + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Get specific information about the OpenCL platform. + * + * \param param_name is an enum that identifies the platform information being + * queried. + * + * \param param_value is a pointer to memory location where appropriate values + * for a given \a param_name will be returned. If \a param_value is NULL, + * it is ignored. + * + * \param param_value_size specifies the size in bytes of memory pointed to by + * \a param_value. This size in bytes must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data being + * queried by param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * \return One of the following values: + * - CL_INVALID_VALUE if \a param_name is not one of the supported + * values or if size in bytes specified by \a param_value_size is < size of + * return type and \a param_value is not a NULL value. + * - CL_SUCCESS if the function is executed successfully. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(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)) { + if (platform != NULL && platform != AMD_PLATFORM) { + return CL_INVALID_PLATFORM; + } + + const char* value = NULL; + switch (param_name) { + case CL_PLATFORM_PROFILE: + value = "FULL_PROFILE"; + break; + case CL_PLATFORM_VERSION: + value = "OpenCL " XSTR(OPENCL_MAJOR) "." XSTR(OPENCL_MINOR) " " AMD_PLATFORM_INFO; + break; + case CL_PLATFORM_NAME: + value = AMD_PLATFORM_NAME; + break; + case CL_PLATFORM_VENDOR: + value = "Advanced Micro Devices, Inc."; + break; + case CL_PLATFORM_EXTENSIONS: + value = "cl_khr_icd " +#ifdef _WIN32 + "cl_khr_d3d10_sharing " + "cl_khr_d3d11_sharing " + "cl_khr_dx9_media_sharing " +#endif //_WIN32 + "cl_amd_event_callback " +#if defined(WITH_COMPILER_LIB) + "cl_amd_offline_devices " +#endif // defined(WITH_COMPILER_LIB) + ; + break; + case CL_PLATFORM_ICD_SUFFIX_KHR: + value = "AMD"; + break; + case CL_PLATFORM_HOST_TIMER_RESOLUTION: { + cl_ulong resolution = (cl_ulong)amd::Os::timerResolutionNanos(); + return amd::clGetInfo(resolution, param_value_size, param_value, param_value_size_ret); + } + default: + break; + } + if (value != NULL) { + return amd::clGetInfo(value, param_value_size, param_value, param_value_size_ret); + } + + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_Devices + * @{ + */ + +/*! \brief Get the list of available devices. + * + * \param device_type is a bitfield that identifies the type of OpenCL device. + * The \a device_type can be used to query specific OpenCL devices or all + * OpenCL devices available. + * + * \param num_entries is the number of cl_device_id entries that can be added + * to devices. If devices is not NULL, the \a num_entries must be greater than + * zero. + * + * \param devices returns a list of OpenCL devices found. The cl_device_id + * values returned in devices can be used to identify a specific OpenCL device. + * If \a devices argument is NULL, this argument is ignored. The number of + * OpenCL devices returned is the mininum of value specified by \a num_entries + * or the number of OpenCL devices whose type matches device_type. + * + * \param num_devices returns the number of OpenCL devices available that match + * device_type. If \a num_devices is NULL, this argument is ignored. + * + * \return One of the following values: + * - CL_INVALID_DEVICE_TYPE if \a device_type is not a valid value. + * - CL_INVALID_VALUE if \a num_entries is equal to zero and devices is + * not NULL or if both \a num_devices and \a devices are NULL. + * - CL_DEVICE_ NOT_FOUND if no OpenCL devices that matched \a device_type + * were found. + * - CL_SUCCESS if the function is executed successfully. + * + * The application can query specific capabilities of the OpenCL device(s) + * returned by clGetDeviceIDs. This can be used by the application to + * determine which device(s) to use. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clGetDeviceIDs, + (cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, + cl_device_id* devices, cl_uint* num_devices)) { + if (platform != NULL && platform != AMD_PLATFORM) { + return CL_INVALID_PLATFORM; + } + + if (((num_entries > 0 || num_devices == NULL) && devices == NULL) || + (num_entries == 0 && devices != NULL)) { + return CL_INVALID_VALUE; + } + + // Get all available devices + if (!amd::Device::getDeviceIDs(device_type, num_entries, devices, num_devices, false)) { + return CL_DEVICE_NOT_FOUND; + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \fn clGetDeviceInfo + * + * \brief Get specific information about an OpenCL device. + * + * \param device is a device returned by clGetDeviceIDs. + * + * \param param_name is an enum that identifies the device information being + * queried. + * + * \param param_value is a pointer to memory location where appropriate values + * for a given \a param_name will be returned. If \a param_value is NULL, + * it is ignored. + * + * \param param_value_size specifies the size in bytes of memory pointed to + * by \a param_value. This size in bytes must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data being + * queried by param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * \return One of the following values: + * - CL_INVALID_DEVICE if device is not valid. + * - CL_INVALID_VALUE if param_name is not one of the supported values + * or if size in bytes specified by \a param_value_size is < size of return + * type and \a param_value is not a NULL value. + * - CL_SUCCESS if the function is executed successfully. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(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)) { + if (!is_valid(device)) { + return CL_INVALID_DEVICE; + } + +#define CASE(param_name, field_name) \ + case param_name: \ + return amd::clGetInfo(as_amd(device)->info().field_name, param_value_size, param_value, \ + param_value_size_ret); + + switch (param_name) { + case CL_DEVICE_TYPE: { + // For cl_device_type, we need to mask out the default bit. + cl_device_type device_type = as_amd(device)->type(); + return amd::clGetInfo(device_type, param_value_size, param_value, param_value_size_ret); + } + CASE(CL_DEVICE_VENDOR_ID, vendorId_); + CASE(CL_DEVICE_MAX_COMPUTE_UNITS, maxComputeUnits_); + CASE(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, maxWorkItemDimensions_); + CASE(CL_DEVICE_MAX_WORK_GROUP_SIZE, preferredWorkGroupSize_); + CASE(CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD, preferredWorkGroupSize_); + CASE(CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD, maxWorkGroupSize_); + CASE(CL_DEVICE_MAX_WORK_ITEM_SIZES, maxWorkItemSizes_); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, preferredVectorWidthChar_); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, preferredVectorWidthShort_); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, preferredVectorWidthInt_); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, preferredVectorWidthLong_); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, preferredVectorWidthFloat_); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, preferredVectorWidthDouble_); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, preferredVectorWidthDouble_); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, nativeVectorWidthChar_); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, nativeVectorWidthShort_); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, nativeVectorWidthInt_); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, nativeVectorWidthLong_); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, nativeVectorWidthFloat_); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, nativeVectorWidthDouble_); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, nativeVectorWidthDouble_); + CASE(CL_DEVICE_MAX_CLOCK_FREQUENCY, maxEngineClockFrequency_); + CASE(CL_DEVICE_ADDRESS_BITS, addressBits_); + CASE(CL_DEVICE_MAX_READ_IMAGE_ARGS, maxReadImageArgs_); + CASE(CL_DEVICE_MAX_WRITE_IMAGE_ARGS, maxWriteImageArgs_); + CASE(CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS, maxReadWriteImageArgs_); + CASE(CL_DEVICE_MAX_MEM_ALLOC_SIZE, maxMemAllocSize_); + CASE(CL_DEVICE_IMAGE2D_MAX_WIDTH, image2DMaxWidth_); + CASE(CL_DEVICE_IMAGE2D_MAX_HEIGHT, image2DMaxHeight_); + CASE(CL_DEVICE_IMAGE3D_MAX_WIDTH, image3DMaxWidth_); + CASE(CL_DEVICE_IMAGE3D_MAX_HEIGHT, image3DMaxHeight_); + CASE(CL_DEVICE_IMAGE3D_MAX_DEPTH, image3DMaxDepth_); + CASE(CL_DEVICE_IMAGE_SUPPORT, imageSupport_); + CASE(CL_DEVICE_MAX_PARAMETER_SIZE, maxParameterSize_); + CASE(CL_DEVICE_MAX_SAMPLERS, maxSamplers_); + CASE(CL_DEVICE_MEM_BASE_ADDR_ALIGN, memBaseAddrAlign_); + CASE(CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, minDataTypeAlignSize_); + CASE(CL_DEVICE_HALF_FP_CONFIG, halfFPConfig_); + CASE(CL_DEVICE_SINGLE_FP_CONFIG, singleFPConfig_); + CASE(CL_DEVICE_DOUBLE_FP_CONFIG, doubleFPConfig_); + CASE(CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, globalMemCacheType_); + CASE(CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, globalMemCacheLineSize_); + CASE(CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, globalMemCacheSize_); + CASE(CL_DEVICE_GLOBAL_MEM_SIZE, globalMemSize_); + CASE(CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, maxConstantBufferSize_); + CASE(CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD, preferredConstantBufferSize_); + CASE(CL_DEVICE_MAX_CONSTANT_ARGS, maxConstantArgs_); + CASE(CL_DEVICE_LOCAL_MEM_TYPE, localMemType_); + CASE(CL_DEVICE_LOCAL_MEM_SIZE, localMemSize_); + CASE(CL_DEVICE_ERROR_CORRECTION_SUPPORT, errorCorrectionSupport_); + CASE(CL_DEVICE_HOST_UNIFIED_MEMORY, hostUnifiedMemory_); + CASE(CL_DEVICE_PROFILING_TIMER_RESOLUTION, profilingTimerResolution_); + CASE(CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, profilingTimerOffset_); + CASE(CL_DEVICE_ENDIAN_LITTLE, littleEndian_); + CASE(CL_DEVICE_AVAILABLE, available_); + CASE(CL_DEVICE_COMPILER_AVAILABLE, compilerAvailable_); + CASE(CL_DEVICE_EXECUTION_CAPABILITIES, executionCapabilities_); + CASE(CL_DEVICE_SVM_CAPABILITIES, svmCapabilities_); + CASE(CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, preferredPlatformAtomicAlignment_); + CASE(CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, preferredGlobalAtomicAlignment_); + CASE(CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, preferredLocalAtomicAlignment_); + CASE(CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, queueProperties_); + CASE(CL_DEVICE_PLATFORM, platform_); + CASE(CL_DEVICE_NAME, name_); + CASE(CL_DEVICE_VENDOR, vendor_); + CASE(CL_DRIVER_VERSION, driverVersion_); + CASE(CL_DEVICE_PROFILE, profile_); + CASE(CL_DEVICE_VERSION, version_); + CASE(CL_DEVICE_OPENCL_C_VERSION, oclcVersion_); + CASE(CL_DEVICE_EXTENSIONS, extensions_); + CASE(CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT, maxAtomicCounters_); + CASE(CL_DEVICE_TOPOLOGY_AMD, deviceTopology_); + CASE(CL_DEVICE_MAX_SEMAPHORE_SIZE_AMD, maxSemaphoreSize_); + CASE(CL_DEVICE_BOARD_NAME_AMD, boardName_); + CASE(CL_DEVICE_SPIR_VERSIONS, spirVersions_); + CASE(CL_DEVICE_IL_VERSION, spirVersions_); + CASE(CL_DEVICE_MAX_PIPE_ARGS, maxPipeArgs_); + CASE(CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, maxPipeActiveReservations_); + CASE(CL_DEVICE_PIPE_MAX_PACKET_SIZE, maxPipePacketSize_); + CASE(CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE, maxGlobalVariableSize_); + CASE(CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE, globalVariablePreferredTotalSize_); + CASE(CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, queueOnDeviceProperties_); + CASE(CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, queueOnDevicePreferredSize_); + CASE(CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, queueOnDeviceMaxSize_); + CASE(CL_DEVICE_MAX_ON_DEVICE_QUEUES, maxOnDeviceQueues_); + CASE(CL_DEVICE_MAX_ON_DEVICE_EVENTS, maxOnDeviceEvents_); + CASE(CL_DEVICE_LINKER_AVAILABLE, linkerAvailable_); + CASE(CL_DEVICE_BUILT_IN_KERNELS, builtInKernels_); + CASE(CL_DEVICE_IMAGE_MAX_BUFFER_SIZE, imageMaxBufferSize_); + CASE(CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, imageMaxArraySize_); + case CL_DEVICE_PARENT_DEVICE: { + cl_device_id parent = (cl_device_id)0; + return amd::clGetInfo(parent, param_value_size, param_value, param_value_size_ret); + } + CASE(CL_DEVICE_PARTITION_MAX_SUB_DEVICES, maxComputeUnits_); + case CL_DEVICE_PARTITION_PROPERTIES: { + cl_device_partition_property cl_property = {}; + return amd::clGetInfo(cl_property, param_value_size, param_value, param_value_size_ret); + } + case CL_DEVICE_PARTITION_AFFINITY_DOMAIN: { + cl_device_affinity_domain deviceAffinity = {}; + return amd::clGetInfo(deviceAffinity, param_value_size, param_value, param_value_size_ret); + } + case CL_DEVICE_PARTITION_TYPE: { + cl_device_partition_property cl_property = {}; + return amd::clGetInfo(cl_property, param_value_size, param_value, param_value_size_ret); + } + case CL_DEVICE_REFERENCE_COUNT: { + cl_uint count = as_amd(device)->referenceCount(); + return amd::clGetInfo(count, param_value_size, param_value, param_value_size_ret); + } + CASE(CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, preferredInteropUserSync_); + CASE(CL_DEVICE_PRINTF_BUFFER_SIZE, printfBufferSize_); + CASE(CL_DEVICE_IMAGE_PITCH_ALIGNMENT, imagePitchAlignment_); + CASE(CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT, imageBaseAddressAlignment_); + + default: + break; + } + if (as_amd(device)->type() == CL_DEVICE_TYPE_GPU) { + switch (param_name) { + case CL_DEVICE_GLOBAL_FREE_MEMORY_AMD: { + // Free memory should contain 2 values: + // total free memory and the biggest free block + size_t freeMemory[2]; + if (!as_amd(device)->globalFreeMemory(freeMemory)) { + return CL_INVALID_DEVICE; + } + if (param_value_size < sizeof(freeMemory)) { + // Return just total free memory if the app provided space for one value + return amd::clGetInfo(freeMemory[0], param_value_size, param_value, param_value_size_ret); + } else { + return amd::clGetInfo(freeMemory, param_value_size, param_value, param_value_size_ret); + } + } + CASE(CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, simdPerCU_); + CASE(CL_DEVICE_SIMD_WIDTH_AMD, simdWidth_); + CASE(CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, simdInstructionWidth_); + CASE(CL_DEVICE_WAVEFRONT_WIDTH_AMD, wavefrontWidth_); + case CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD: { + cl_uint globalMemChannels = as_amd(device)->info().vramBusBitWidth_ / 32; + return amd::clGetInfo(globalMemChannels, param_value_size, param_value, param_value_size_ret); + } + CASE(CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, globalMemChannelBanks_); + CASE(CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, globalMemChannelBankWidth_); + CASE(CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, localMemSizePerCU_); + CASE(CL_DEVICE_LOCAL_MEM_BANKS_AMD, localMemBanks_); + CASE(CL_DEVICE_THREAD_TRACE_SUPPORTED_AMD, threadTraceEnable_); + case CL_DEVICE_GFXIP_MAJOR_AMD: { + cl_uint major = as_amd(device)->isa().versionMajor(); + return amd::clGetInfo(major, param_value_size, param_value, param_value_size_ret); + } + case CL_DEVICE_GFXIP_MINOR_AMD: { + cl_uint minor = as_amd(device)->isa().versionMinor(); + return amd::clGetInfo(minor, param_value_size, param_value, param_value_size_ret); + } + CASE(CL_DEVICE_AVAILABLE_ASYNC_QUEUES_AMD, numAsyncQueues_); +#define CL_DEVICE_MAX_REAL_TIME_COMPUTE_QUEUES_AMD 0x404D +#define CL_DEVICE_MAX_REAL_TIME_COMPUTE_UNITS_AMD 0x404E +#define CL_DEVICE_MAX_REAL_TIME_COMPUTE_UNITS_GRANULARITY_AMD 0x403A + CASE(CL_DEVICE_MAX_REAL_TIME_COMPUTE_QUEUES_AMD, numRTQueues_); + CASE(CL_DEVICE_MAX_REAL_TIME_COMPUTE_UNITS_AMD, numRTCUs_); + CASE(CL_DEVICE_MAX_REAL_TIME_COMPUTE_UNITS_GRANULARITY_AMD, granularityRTCUs_); + case CL_DEVICE_NUM_P2P_DEVICES_AMD: { + cl_uint num_p2p_devices = as_amd(device)->p2pDevices_.size(); + return amd::clGetInfo(num_p2p_devices, param_value_size, param_value, param_value_size_ret); + } + case CL_DEVICE_P2P_DEVICES_AMD: { + uint valueSize = as_amd(device)->p2pDevices_.size() * sizeof(cl_device_id); + if (param_value != NULL) { + if ((param_value_size < valueSize) || (param_value_size == 0)) { + return CL_INVALID_VALUE; + } + } else { + return CL_INVALID_VALUE; + } + memcpy(param_value, as_amd(device)->p2pDevices_.data(), valueSize); + *not_null(param_value_size_ret) = valueSize; + if (param_value != NULL && param_value_size > valueSize) { + ::memset(static_cast(param_value) + valueSize, '\0', param_value_size - valueSize); + } + return CL_SUCCESS; + } + CASE(CL_DEVICE_PCIE_ID_AMD, pcieDeviceId_); + default: + break; + } + } +#undef CASE + + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +RUNTIME_ENTRY(cl_int, clCreateSubDevices, + (cl_device_id in_device, const cl_device_partition_property* partition_properties, + cl_uint num_entries, cl_device_id* out_devices, cl_uint* num_devices)) { + if (!is_valid(in_device)) { + return CL_INVALID_DEVICE; + } + if (partition_properties == NULL || *partition_properties == 0u) { + return CL_INVALID_VALUE; + } + if ((num_devices == NULL && out_devices == NULL) || (num_entries == 0 && out_devices != NULL)) { + return CL_INVALID_VALUE; + } + + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +RUNTIME_ENTRY(cl_int, clRetainDevice, (cl_device_id device)) { + if (!is_valid(device)) { + return CL_INVALID_DEVICE; + } + as_amd(device)->retain(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +RUNTIME_ENTRY(cl_int, clReleaseDevice, (cl_device_id device)) { + if (!is_valid(device)) { + return CL_INVALID_DEVICE; + } + as_amd(device)->release(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * @} + */ diff --git a/opencl/amdocl/cl_event.cpp b/opencl/amdocl/cl_event.cpp new file mode 100644 index 0000000000..65b4f45e64 --- /dev/null +++ b/opencl/amdocl/cl_event.cpp @@ -0,0 +1,387 @@ +/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" + +#include "platform/object.hpp" +#include "platform/context.hpp" +#include "platform/command.hpp" + +/*! \addtogroup API + * @{ + * \addtogroup CL_Events + * + * Event objects can be used to refer to a kernel execution command: + * - clEnqueueNDRangeKernel + * - clEnqueueTask + * - clEnqueueNativeKernel + * + * or read, write, map and copy commands on memory objects: + * - clEnqueue{Read|Write|Map}{Buffer|Image} + * - clEnqueueCopy{Buffer|Image} + * - clEnqueueCopyBufferToImage + * - clEnqueueCopyImageToBuffer + * + * An event object can be used to track the execution status of a command. + * The execution status of a command at any given point in time can be + * CL_QUEUED (is currently in the command queue), + * CL_RUNNING (device is currently executing this command), + * CL_COMPLETE (command has successfully completed) or the appropriate error + * code if the command was abnormally terminated (this may be caused by a bad + * memory access etc.). The error code returned by a terminated command is + * a negative integer value. A command is considered to be complete if its + * execution status is CL_COMPLETE or is a negative integer value. + * + * If the execution of a command is terminated, the command-queue associated + * with this terminated command, and the associated context (and all other + * command-queues in this context) may no longer be available. The behavior of + * OpenCL API calls that use this context (and command-queues associated with + * this context) are now considered to be implementationdefined. The user + * registered callback function specified when context is created can be used + * to report appropriate error information. + * + * @{ + */ + + +/*! \brief Wait on the host thread for commands identified by event objects in + * event_list to complete. + * + * A command is considered complete if its execution status is CL_COMPLETE or + * a negative value. The events specified in event_list act as synchronization + * points. + * + * \return One of the following values: + * - CL_SUCCESS if the function was executed successfully. + * - CL_INVALID_VALUE if \a num_events is zero + * - CL_INVALID_CONTEXT if events specified in \a event_list do not belong to + * the same context + * - CL_INVALID_EVENT if event objects specified in \a event_list are not valid + * event objects. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clWaitForEvents, (cl_uint num_events, const cl_event* event_list)) { + if (num_events == 0 || event_list == NULL) { + return CL_INVALID_VALUE; + } + + const amd::Context* prevContext = NULL; + const amd::HostQueue* prevQueue = NULL; + + for (cl_uint i = 0; i < num_events; ++i) { + cl_event event = event_list[i]; + + if (!is_valid(event)) { + return CL_INVALID_EVENT; + } + + // Make sure all the events are associated with the same context + const amd::Context* context = &as_amd(event)->context(); + if (prevContext != NULL && prevContext != context) { + return CL_INVALID_CONTEXT; + } + prevContext = context; + + // Flush the command queues associated with event1...eventN + amd::HostQueue* queue = as_amd(event)->command().queue(); + if (queue != NULL && prevQueue != queue) { + queue->flush(); + } + prevQueue = queue; + } + + bool allSucceeded = true; + while (num_events-- > 0) { + allSucceeded &= as_amd(*event_list++)->awaitCompletion(); + } + return allSucceeded ? CL_SUCCESS : CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST; +} +RUNTIME_EXIT + +/*! \brief Return information about the event object. + * + * \param event specifies the event object being queried. + * + * \param param_name specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result being + * queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data copied + * to \a param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * Using clGetEventInfo to determine if a command identified by event has + * finished execution (i.e. CL_EVENT_COMMAND_EXECUTION_STATUS returns + * CL_COMPLETE) is not a synchronization point i.e. there are no guarantees + * that the memory objects being modified by command associated with event will + * be visible to other enqueued commands. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully + * - CL_INVALID_VALUE if \a param_name is not valid, or if size in bytes + * specified by \a param_value_size is < size of return type and + * \a param_value is not NULL + * - CL_INVALID_EVENT if \a event is a not a valid event object. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clGetEventInfo, + (cl_event event, cl_event_info param_name, size_t param_value_size, void* param_value, + size_t* param_value_size_ret)) { + if (!is_valid(event)) { + return CL_INVALID_EVENT; + } + + switch (param_name) { + case CL_EVENT_CONTEXT: { + amd::Context& amdCtx = const_cast(as_amd(event)->context()); + cl_context context = as_cl(&amdCtx); + return amd::clGetInfo(context, param_value_size, param_value, param_value_size_ret); + } + case CL_EVENT_COMMAND_QUEUE: { + amd::Command& command = as_amd(event)->command(); + cl_command_queue queue = command.queue() == NULL + ? NULL + : const_cast(as_cl(command.queue()->asCommandQueue())); + return amd::clGetInfo(queue, param_value_size, param_value, param_value_size_ret); + } + case CL_EVENT_COMMAND_TYPE: { + cl_command_type type = as_amd(event)->command().type(); + return amd::clGetInfo(type, param_value_size, param_value, param_value_size_ret); + } + case CL_EVENT_COMMAND_EXECUTION_STATUS: { + as_amd(event)->notifyCmdQueue(); + cl_int status = as_amd(event)->command().status(); + return amd::clGetInfo(status, param_value_size, param_value, param_value_size_ret); + } + case CL_EVENT_REFERENCE_COUNT: { + cl_uint count = as_amd(event)->referenceCount(); + return amd::clGetInfo(count, param_value_size, param_value, param_value_size_ret); + } + default: + break; + } + + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +/*! \brief Increment the event reference count. + * + * \return CL_SUCCESS if the function is executed successfully. It returns + * CL_INVALID_EVENT if \a event is not a valid event object. + * + * The OpenCL commands that return an event perform an implicit retain. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clRetainEvent, (cl_event event)) { + if (!is_valid(event)) { + return CL_INVALID_EVENT; + } + as_amd(event)->retain(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Decrement the event reference count. + * + * \return CL_SUCCESS if the function is executed successfully. It returns + * CL_INVALID_EVENT if \a event is not a valid event object. + * + * The event object is deleted once the reference count becomes zero, the + * specific command identified by this event has completed (or terminated) and + * there are no commands in the command-queues of a context that require a wait + * for this event to complete. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clReleaseEvent, (cl_event event)) { + if (!is_valid(event)) { + return CL_INVALID_EVENT; + } + as_amd(event)->release(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Creates a user event object. + * + * User events allow applications to enqueue commands that wait on a user event + * to finish before the command is executed by the device. + * + * \return a valid non-zero event object and errcode_ret is set to CL_SUCCESS + * if the user event object is created successfully. Otherwise, it returns + * a NULL value with one of the following error values returned in errcode_ret: + * - CL_INVALID_CONTEXT if context is not a valid context. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host. + * + * The execution status of the user event object created is set to CL_SUBMITTED. + * + * \version 1.1r15 + */ +RUNTIME_ENTRY_RET(cl_event, clCreateUserEvent, (cl_context context, cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + return (cl_event)0; + } + + amd::Event* event = new amd::UserEvent(*as_amd(context)); + if (event == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_event)0; + } + + event->retain(); + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(event); +} +RUNTIME_EXIT + +/*! \brief Sets the execution status of a user event object. + * + * \a event is a user event object created using clCreateUserEvent. + * \a execution_status specifies the new execution status to be set and can be + * CL_COMPLETE or a negative integer value to indicate an error. + * clSetUserEventStatus can only be called once to change the execution status + * of event. + * + * \return CL_SUCCESS if the function was executed successfully. Otherwise, + * it returns one of the following errors: + * - CL_INVALID_EVENT if event is not a valid user event object. + * - CL_INVALID_VALUE if the execution_status is not CL_COMPLETE or + * a negative integer value. + * - CL_INVALID_OPERATION if the execution_status for event has already been + * changed by a previous call to clSetUserEventStatus. + * + * \version 1.1r15 + */ +RUNTIME_ENTRY(cl_int, clSetUserEventStatus, (cl_event event, cl_int execution_status)) { + if (!is_valid(event)) { + return CL_INVALID_EVENT; + } + if (execution_status > CL_COMPLETE) { + return CL_INVALID_VALUE; + } + + if (!as_amd(event)->setStatus(execution_status)) { + return CL_INVALID_OPERATION; + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Registers a user callback function for a specific command execution + * status. + * + * The registered callback function will be called when the execution status + * of command associated with event changes to the execution status specified + * by command_exec_status. + * + * Each call to clSetEventCallback registers the specified user callback + * function on a callback stack associated with event. The order in which the + * registered user callback functions are called is undefined. + * + * \a event is a valid event object. + * \a command_exec_callback_type specifies the command execution status for + * which the callback is registered. The command execution callback mask + * values for which a callback can be registered are: CL_COMPLETE. + * There is no guarantee that the callback functions registered for various + * execution status values for an event will be called in the exact order + * that the execution status of a command changes. + * \a pfn_event_notify is the event callback function that can be registered + * by the application. This callback function may be called asynchronously + * by the OpenCL implementation. It is the application’s responsibility to + * ensure that the callback function is thread-safe. The parameters to this + * callback function are: + * event is the event object for which the callback function is invoked. + * event_command_exec_status represents the execution status of command + * for which this callback function is invoked. If the callback is called + * as the result of the command associated with event being abnormally + * terminated, an appropriate error code for the error that caused the + * termination will be passed to event_command_exec_status instead. + * \a user_data is a pointer to user supplied data. user_data will be passed as + * the user_data argument when pfn_notify is called. user_data can be NULL. + * + * All callbacks registered for an event object must be called. All enqueued + * callbacks shall be called before the event object is destroyed. Callbacks + * must return promptly. The behavior of calling expensive system routines, + * OpenCL API calls to create contexts or command-queues, or blocking OpenCL + * operations from the following list below, in a callback is undefined. + * clFinish, clWaitForEvents, blocking calls to clEnqueueReadBuffer, + * clEnqueueReadBufferRect, clEnqueueWriteBuffer, clEnqueueWriteBufferRect, + * blocking calls to clEnqueueReadImage and clEnqueueWriteImage, blocking + * calls to clEnqueueMapBuffer and clEnqueueMapImage, blocking calls to + * clBuildProgram + * + * If an application needs to wait for completion of a routine from the above + * list in a callback, please use the non-blocking form of the function, and + * assign a completion callback to it to do the remainder of your work. + * Note that when a callback (or other code) enqueues commands to a + * command-queue, the commands are not required to begin execution until the + * queue is flushed. In standard usage, blocking enqueue calls serve this role + * by implicitly flushing the queue. Since blocking calls are not permitted in + * callbacks, those callbacks that enqueue commands on a command queue should + * either call clFlush on the queue before returning or arrange for clFlush + * to be called later on another thread. + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise, + * it returns one of the following errors: + * - CL_INVALID_EVENT if event is not a valid event object or is a user event + * object created using clCreateUserEvent. + * - CL_INVALID_VALUE if pfn_event_notify is NULL or if + * command_exec_callback_type is not a valid command execution status. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host. + * + * \version 1.1r15 + */ +RUNTIME_ENTRY(cl_int, clSetEventCallback, + (cl_event event, cl_int command_exec_callback_type, + void(CL_CALLBACK* pfn_notify)(cl_event event, cl_int command_exec_status, + void* user_data), + void* user_data)) { + if (!is_valid(event)) { + return CL_INVALID_EVENT; + } + + if (pfn_notify == NULL || command_exec_callback_type < CL_COMPLETE || + command_exec_callback_type > CL_QUEUED) { + return CL_INVALID_VALUE; + } + + if (!as_amd(event)->setCallback(command_exec_callback_type, pfn_notify, user_data)) { + return CL_OUT_OF_HOST_MEMORY; + } + + as_amd(event)->notifyCmdQueue(); + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * @} + */ diff --git a/opencl/amdocl/cl_execute.cpp b/opencl/amdocl/cl_execute.cpp new file mode 100644 index 0000000000..e1d5be268c --- /dev/null +++ b/opencl/amdocl/cl_execute.cpp @@ -0,0 +1,1111 @@ +/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include "vdi_common.hpp" + +#include "platform/kernel.hpp" +#include "platform/ndrange.hpp" +#include "platform/command.hpp" +#include "platform/program.hpp" +#include "os/os.hpp" + +/*! \addtogroup API + * @{ + * + * \addtogroup CL_Exec Executing Kernel Objects + * + * @{ + */ + +/*! \brief Enqueue a command to execute a kernel on a device. + * + * \param command_queue is a valid command-queue. The kernel will be queued + * for execution on the device associated with \a command_queue. + * + * \param kernel is a valid kernel object. The OpenCL context associated with + * \a kernel and \a command-queue must be the same. + * + * \param work_dim is the number of dimensions used to specify the global + * work-items and work-items in the work-group. \a work_dim must be greater + * than zero and less than or equal to three. + * + * \param global_work_offset must currently be a NULL value. In a future + * revision of OpenCL, \a global_work_offset can be used to specify an array + * of \a work_dim unsigned values that describe the offset used to calculate + * the global ID of a work-item instead of having the global IDs always start + * at offset (0, 0, 0). + * + * \param global_work_size points to an array of \a work_dim unsigned values + * that describe the number of global work-items in \a work_dim dimensions + * that will execute the kernel function. The total number of global + * work-items is computed as global_work_size[0] * ... + * * global_work_size[work_dim - 1]. + * + * \param local_work_size points to an array of \a work_dim unsigned values + * that describe the number of work-items that make up a work-group (also + * referred to as the size of the work-group) that will execue the kernel + * specified by kernel. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, then + * this particular command does not wait on any event to complete. + * If \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. + * + * \param event returns an event object that identifies this particular kernel + * execution instance. Event objects are unique and can be used to identify a + * particular kernel execution instance later on. If \a event is NULL, no + * event will be created for this kernel execution instance and therefore it + * will not be possible for the application to query or queue a wait for this + * particular kernel execution instance. + * + * The total number of work-items in a work-group is computed as + * local_work_size[0] * ... * local_work_size[work_dim - 1]. + * The total number of work-items in the work-group must be less than or equal + * to the CL_DEVICE_MAX_WORK_GROUP_SIZE. The explicitly specified + * \a local_work_size will be used to determine how to break the global work- + * items specified by global_work_size into appropriate work-group instances. + * If \a local_work_size is specified, the values specified in + * \a global_work_size[0], ..., global_work_size[work_dim - 1] must be evenly + * divisable by the corresponding values specified in \a local_work_size[0], + * ..., local_work_size[work_dim - 1]. \a local_work_size can also be a NULL + * value in which case the OpenCL implementation will determine how to be + * break the global work-items into appropriate work-groups. + * + * If \a local_work_size is NULL and no work-group size is specified when the + * kernel is compiled, the OpenCL implementation will determine how to break + * the global work-items specified by \a global_work_size into appropriate + * work-group instances. The work-group size to be used for kernel can also be + * specified in the program source using the + * __attribute__((reqd_work_group_size(X, Y, Z))) qualifier. In this case the + * size of work group specified by \a local_work_size must match the value + * specified by the \a reqd_work_group_size attribute qualifier. + * + * These work-group instances are executed in parallel across multiple + * compute units or concurrently on the same compute unit. Each work-item + * is uniquely identified by a global identifier. The global ID, which can be + * read inside the kernel is computed using the value given by + * \a global_work_size and \a global_work_offset. + * + * \return One of the following values: + * + * - CL_SUCCESS if the kernel execution was successfully queued + * + * - CL_INVALID_PROGRAM_EXECUTABLE if there is no successfully built program + * executable available for device associated with \a command_queue. + * + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue + * + * - CL_INVALID_KERNEL if \a kernel is not a valid kernel object. + * + * - CL_INVALID_CONTEXT if context associated with command_queue and kernel are + * not the same or if the context associated with command_queue and events in + * event_wait_list are not the same. + * + * - CL_INVALID_KERNEL_ARGS if the kernel argument values have not been + * specified or are not valid for the device on which kernel will be + * executed. + * + * - CL_INVALID_WORK_DIMENSION if \a work_dim is not a valid value + * (i.e. a value between 1 and 3). + * + * - CL_INVALID_WORK_GROUP_SIZE if \a local_work_size is specified and number + * of workitems specified by \a global_work_size is not evenly divisable by + * size of work-given by \a local_work_size or does not match the work-group + * size specified for kernel using the + * __attribute__((reqd_work_group_size(X, Y, Z))) qualifier in program + * source. + * + * - CL_INVALID_GLOBAL_OFFSET if \a global_work_offset is not NULL. + * + * - CL_OUT_OF_RESOURCES if there is a failure to queue the execution instance + * of \a kernel on the command-queue because of insufficient resources + * needed to execute the kernel. For example, the explicitly specified + * \a local_work_dim in range causes a failure to execute the kernel because + * of insufficient resources such as registers or local memory. Another + * example would be the number of read-only image args used in kernel exceed + * the CL_DEVICE_MAX_READ_IMAGE_ARGS value for device or the number of + * write-only image args used in kernel exceed the + * CL_DEVICE_MAX_WRITE_IMAGE_ARGS value for device or the number of samplers + * used in kernel exceed CL_DEVICE_MAX_SAMPLERS for device. + * + * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory + * for image or buffer objects specified as arguments to kernel. + * + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in + * \a event_wait_list are not valid events. + * + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(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)) { + *not_null(event) = NULL; + + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + if (!is_valid(kernel)) { + return CL_INVALID_KERNEL; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + const amd::Kernel* amdKernel = as_amd(kernel); + if (&hostQueue.context() != &amdKernel->program().context()) { + return CL_INVALID_CONTEXT; + } + + const amd::Device& device = hostQueue.device(); + const device::Kernel* devKernel = amdKernel->getDeviceKernel(device); + if (devKernel == NULL) { + return CL_INVALID_PROGRAM_EXECUTABLE; + } + + if (amdKernel->parameters().getSvmSystemPointersSupport() == FGS_YES && + !(device.info().svmCapabilities_ & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM)) { + // The user indicated that this kernel will access SVM system pointers, + // but the device does not support them. + return CL_INVALID_OPERATION; + } + + if (work_dim < 1 || work_dim > 3) { + return CL_INVALID_WORK_DIMENSION; + } +#if !defined(CL_VERSION_1_1) + if (global_work_offset != NULL) { + return CL_INVALID_GLOBAL_OFFSET; + } +#endif // CL_VERSION + if (global_work_size == NULL) { + return CL_INVALID_VALUE; + } + + if (local_work_size == NULL) { + static size_t zeroes[3] = {0, 0, 0}; + local_work_size = zeroes; + } else { + size_t numWorkItems = 1; + for (cl_uint dim = 0; dim < work_dim; ++dim) { + if ((devKernel->workGroupInfo()->compileSize_[0] != 0) && + (local_work_size[dim] != devKernel->workGroupInfo()->compileSize_[dim])) { + return CL_INVALID_WORK_GROUP_SIZE; + } + // >32bits global work size is not supported. + if ((global_work_size[dim] == 0) || (global_work_size[dim] > static_cast(0xffffffff))) { + return CL_INVALID_GLOBAL_WORK_SIZE; + } + numWorkItems *= local_work_size[dim]; + } + // Make sure local work size is valid + if ((numWorkItems == 0) || (numWorkItems > devKernel->workGroupInfo()->size_)) { + return CL_INVALID_WORK_GROUP_SIZE; + } + // Check if uniform was requested and validate dimensions + if (devKernel->workGroupInfo()->uniformWorkGroupSize_) { + for (cl_uint dim = 0; dim < work_dim; ++dim) { + if ((global_work_size[dim] % local_work_size[dim]) != 0) { + return CL_INVALID_WORK_GROUP_SIZE; + } + } + } + } + + // Check that all parameters have been defined. + if (!amdKernel->parameters().check()) { + return CL_INVALID_KERNEL_ARGS; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::NDRangeContainer ndrange((size_t)work_dim, global_work_offset, global_work_size, + local_work_size); + amd::NDRangeKernelCommand* command = + new amd::NDRangeKernelCommand(hostQueue, eventWaitList, *as_amd(kernel), ndrange); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + // ndrange is now owned by command. Do not delete it! + + // Make sure we have memory for the command execution + cl_int result = command->captureAndValidate(); + if (result != CL_SUCCESS) { + delete command; + return result; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Enqueue a command to execute a kernel on a device. + * The kernel is executed using a single work-item. + * + * \param command_queue is a valid command-queue. The kernel will be queued + * for execution on the device associated with \a command_queue. + * + * \param kernel is a valid kernel object. The OpenCL context associated with + * \a kernel and \a command-queue must be the same. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, then + * this particular command does not wait on any event to complete. + * If \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. + * + * \param event returns an event objects that identifies this particular kernel + * execution instance. Event objects are unique and can be used to identify a + * particular kernel execution instance later on. If \a event is NULL, no event + * will be created for this kernel execution instance and therefore it will not + * be possible for the application to query or queue a wait for this particular + * kernel execution instance. + * + * \return One of the following values: + * - CL_SUCCESS if the kernel execution was successfully queued. + * - CL_INVALID_PROGRAM_EXECUTABLE if there is no successfully built program + * executable available for device associated with \a command_queue. + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_KERNEL if \a kernel is not a valid kernel object. + * - CL_INVALID_KERNEL_ARGS if the kernel argument values have not been + * specified or are not valid for the device on which kernel will be + * executed. + * - CL_INVALID_WORK_GROUP_SIZE if a work-group size is specified for + * kernel using the __attribute__((reqd_work_group_size(X, Y, Z))) + * qualifier in program source and is not (1, 1, 1). + * - CL_OUT_OF_RESOURCES if there is a failure to queue the execution instance + * of kernel on the command-queue because of insufficient resources needed + * to execute the kernel. For example, the explicitly specified + * \a local_work_dim in range causes a failure to execute the kernel because + * of insufficient resources such as registers or local memory. Another + * example would be the number of read-only image args used in kernel exceed + * the CL_DEVICE_MAX_READ_IMAGE_ARGS value for device or the number of + * write-only image args used in kernel exceed the + * CL_DEVICE_MAX_WRITE_IMAGE_ARGS value for device or the number of samplers + * used in kernel exceed CL_DEVICE_MAX_SAMPLERS for device. + * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory + * for image or buffer objects specified as arguments to kernel. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clEnqueueTask, + (cl_command_queue command_queue, cl_kernel kernel, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + static size_t const globalWorkSize[3] = {1, 0, 0}; + static size_t const localWorkSize[3] = {1, 0, 0}; + + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::HostQueue* hostQueue = as_amd(command_queue)->asHostQueue(); + if (NULL == hostQueue) { + return CL_INVALID_COMMAND_QUEUE; + } + + return hostQueue->dispatch_->clEnqueueNDRangeKernel( + command_queue, kernel, 1, NULL, globalWorkSize, localWorkSize, num_events_in_wait_list, + event_wait_list, event); +} +RUNTIME_EXIT + +/*! \brief Enqueue a command to execute a native C/C++ function not compiled + * using the OpenCL compiler. + * + * \param command_queue is a valid command-queue. A native user function can + * only be executed on a command-queue created on a device that has + * CL_EXEC_NATIVE_KERNEL capability set in CL_DEVICE_EXECUTION_CAPABILITIES. + * + * \param user_func is a pointer to a host-callable user function. + * + * \param args is a pointer to the args list that \a user_func should be called + * with. + * + * \param cb_args is the size in bytes of the args list that args points to. + * The data pointed to by \a args and \a cb_args bytes in size will be copied + * and a pointer to this copied region will be passed to \a user_func. The copy + * needs to be done because the memory objects (cl_mem values) that args may + * contain need to be modified and replaced by appropriate pointers to global + * memory. When clEnqueueNativeKernel returns, the memory region pointed to by + * args can be reused by the application. + * + * \param num_mem_objects is the number of buffer objects that are passed in + * args. + * + * \param mem_list is a list of valid buffer objects, if \a num_mem_objects > 0 + * + * \param args_mem_loc is a pointer to appropriate locations that args points + * to where memory object handles (cl_mem values) are stored. Before the user + * function is executed, the memory object handles are replaced by pointers to + * global memory. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list + * + * \param event_wait_list as described in clEnqueueNDRangeKernel. + * + * \param event returns an event objects that identifies this particular kernel + * execution instance. Event objects are unique and can be used to identify a + * particular kernel execution instance later on. If \a event is NULL, no event + * will be created for this kernel execution instance and therefore it will not + * be possible for the application to query or queue a wait for this particular + * kernel execution instance. + * + * \return One of the following values: + * - CL_SUCCESS if the user function execution instance was successfully queued + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_VALUE if \a user_func is NULL, or if \a args is a NULL value + * and \a num_mem_objects > 0 or if \a num_mem_objects > 0 and \a mem_list + * is NULL. + * - CL_INVALID_OPERATION if device cannot execute the native kernel. + * - CL_INVALID_MEM_OBJECT if one or more memory objects specified in + * \a mem_list are not valid or are not buffer objects. + * - CL_OUT_OF_RESOURCES if there is a failure to queue the execution instance + * of kernel on the command-queue because of insufficient resources needed + * to execute the kernel. + * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory + * for buffer objects specified as arguments to \a kernel. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clEnqueueNativeKernel, + (cl_command_queue command_queue, void(CL_CALLBACK* user_func)(void*), void* args, + size_t cb_args, cl_uint num_mem_objects, const cl_mem* mem_list, + const void** args_mem_loc, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + *not_null(event) = NULL; + + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + const amd::Device& device = hostQueue.device(); + + if (!(device.info().executionCapabilities_ & CL_EXEC_NATIVE_KERNEL)) { + return CL_INVALID_OPERATION; + } + + if (user_func == NULL || (num_mem_objects > 0 && (mem_list == NULL || args_mem_loc == NULL)) || + (num_mem_objects == 0 && (mem_list != NULL || args_mem_loc != NULL)) || + (args == NULL && (cb_args > 0 || num_mem_objects > 0)) || (args != NULL && cb_args == 0)) { + return CL_INVALID_VALUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + for (size_t i = 0; i < num_mem_objects; ++i) { + cl_mem obj = mem_list[i]; + if (!is_valid(obj)) { + return CL_INVALID_MEM_OBJECT; + } + } + + amd::NativeFnCommand* command = new amd::NativeFnCommand( + hostQueue, eventWaitList, user_func, args, cb_args, num_mem_objects, mem_list, args_mem_loc); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * + * \addtogroup CL_Order Out of order Execution of Kernels and Memory Commands + * + * The OpenCL functions that are submitted to a command-queue are queued in + * the order the calls are made but can be configured to execute in-order or + * out-of-order. The properties argument in clCreateCommandQueue can be used + * to specify the execution order. + * + * If the CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE property of a command-queue + * is not set, the commands queued to a command-queue execute in order. + * For example, if an application calls clEnqueueNDRangeKernel to execute + * kernel A followed by a clEnqueueNDRangeKernel to execute kernel B, + * the application can assume that kernel A finishes first and then kernel B + * is executed. If the memory objects output by kernel A are inputs to kernel B + * then kernel B will see the correct data in memory objects produced + * by execution of kernel A. If the CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE + * property of a commandqueue is set, then there is no guarantee that kernel A + * will finish before kernel B starts execution. + * + * Applications can configure the commands queued to a command-queue to + * execute out-of-order by setting the CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE + * property of the commandqueue. This can be specified when the command-queue + * is created or can be changed dynamically using clSetCommandQueueProperty. + * In out-of-order execution mode there is no guarantee that the queued + * commands will finish execution in the order they were queued. As there is + * no guarantee that kernels will be executed in order i.e. based on when + * the clEnqueueNDRangeKernel calls are made within a command-queue, it is + * therefore possible that an earlier clEnqueueNDRangeKernel call to execute + * kernel A identified by event A may execute and/or finish later than a + * clEnqueueNDRangeKernel call to execute kernel B which was called by the + * application at a later point in time. To guarantee a specific order of + * execution of kernels, a wait on a particular event (in this case event A) + * can be used. The wait for event A can be specified in the event_wait_list + * argument to clEnqueueNDRangeKernel for kernel B. + * + * In addition, a wait for events or a barrier function can be queued to the + * command-queue. The wait for events command ensures that previously queued + * commands identified by the list of events to wait for have finished before + * the next batch of commands is executed. The barrier ensures that all + * previously queued commands in a command-queue have finished execution + * before the next batch of commands is executed. + * + * Similarly, commands to read, write, copy or map memory objects that are + * queued after clEnqueueNDRangeKernel, clEnqueueTask or clEnqueueNativeKernel + * commands are not guaranteed to wait for kernels scheduled for execution + * to have completed (if the CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE property + * is set). To ensure correct ordering of commands, the event object returned + * by clEnqueueNDRangeKernel, clEnqueueTask or clEnqueueNativeKernel can be + * used to queue a wait for event or a barrier command can be queued that must + * complete before reads or writes to the memory object(s) occur. + * + * @{ + */ + +/*! \brief Enqueue a marker command to \a command_queue. + * + * The marker command returns an event which can be used by to queue a wait on + * this marker event i.e. wait for all commands queued before the marker + * command to complete. + * + * \return One of the following values: + * - CL_SUCCESS if the function is successfully executed + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue + * - CL_INVALID_VALUE if \a event is a NULL value + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clEnqueueMarker, (cl_command_queue command_queue, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::HostQueue* hostQueue = as_amd(command_queue)->asHostQueue(); + if (NULL == hostQueue) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::Command* command = new amd::Marker(*hostQueue, true); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief enqueues a marker command which waits for either a list of events + * to complete, or if the list is empty it waits for all commands previously + * enqueued in \a command_queue to complete before it completes. This command + * returns an event which can be waited on, i.e. this event can be waited on + * to insure that all events either in the \a event_wait_list or all + * previously enqueued commands, queued before this command to + * \a command_queue, have completed. + * + * \param command_queue is a valid command-queue. + * + * \param num_events_in_wait_list specifies the number of events given + * by \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. + * If \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must + * be greater than 0. The events specified in event_wait_list act as + * synchronization points. The context associated with events in + * \a event_wait_list and \a command_queue must be the same. The + * memory associated with \a event_wait_list can be reused or freed after + * the function returns. + * If \a event_wait_list is NULL, then this particular command waits until + * all previous enqueued commands to \a command_queue have completed. + * + * \param event returns an event object that identifies this particular + * kernel execution instance. Event objects are unique and can be used to + * identify this marker command later on. + * + * \return CL_SUCCESS if the function is successfully executed. + * Otherwise, it returns one of the following errors: + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid \a command-queue. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by + * the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY(cl_int, clEnqueueMarkerWithWaitList, + (cl_command_queue command_queue, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::HostQueue* hostQueue = as_amd(command_queue)->asHostQueue(); + if (NULL == hostQueue) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, *hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::Command* command = new amd::Marker(*hostQueue, true, eventWaitList); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Enqueue a wait for a specific event or a list of events to complete + * before any future commands queued in the command-queue are executed. + * + * \param command_queue is a valid command-queue. + * + * \param num_events specifies the number of events given by \a event_list. + * + * \param event_list is the list of events. Each event in \a event_list must + * be a valid event object returned by a previous call to: + * - clEnqueueNDRangeKernel + * - clEnqueueTask + * - clEnqueueNativeKernel + * - clEnqueue{Read|Write|Map}{Buffer|Image} + * - clEnqueueCopy{Buffer|Image} + * - clEnqueueCopyBufferToImage + * - clEnqueueCopyImageToBuffer + * - clEnqueueMarker. + * The events specified in \a event_list act as synchronization points. + * + * \return One of the following values: + * - CL_SUCCESS if the function was successfully executed. + * - CL_INVALID_COMMAND_QUEUE if c\a ommand_queue is not a valid command-queue + * - CL_INVALID_VALUE if \a num_events is zero or \a event_list is NULL + * - CL_INVALID_EVENT if event objects specified in \a event_list are not valid + * events + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clEnqueueWaitForEvents, + (cl_command_queue command_queue, cl_uint num_events, const cl_event* event_list)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events, event_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::Command* command = new amd::Marker(hostQueue, false, eventWaitList); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + command->enqueue(); + command->release(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Enqueue a barrier operation. + * + * The clEnqueueBarrier command ensures that all queued commands in + * \a command_queue have finished execution before the next batch of commands + * can begin execution. clEnqueueBarrier is a synchronization point. + * + * \return One of the following values: + * - CL_SUCCESS if the function was executed successfully + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clEnqueueBarrier, (cl_command_queue command_queue)) { + //! @todo: Unimplemented(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief enqueues a barrier command which waits for either a list of events + * to complete, or if the list is empty it waits for all commands previously + * enqueued in \a command_queue to complete before it completes. This command + * blocks command execution, that is, any following commands enqueued after it + * do not execute until it completes. This command returns an event which can + * be waited on, i.e. this event can be waited on to insure that all events + * either in the \a event_wait_list or all previously enqueued commands, + * queued before this command to command_queue, have completed + * + * \param command_queue is a valid command-queue. + * + * \param num_events_in_wait_list specifies the number of events given + * by \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. + * If \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must + * be greater than 0. The events specified in event_wait_list act as + * synchronization points. The context associated with events in + * \a event_wait_list and \a command_queue must be the same. The + * memory associated with \a event_wait_list can be reused or freed after + * the function returns. + * If \a event_wait_list is NULL, then this particular command waits until + * all previous enqueued commands to \a command_queue have completed. + * + * \param event returns an event object that identifies this particular + * kernel execution instance. Event objects are unique and can be used to + * identify this marker command later on. + * + * \return CL_SUCCESS if the function is successfully executed. + * Otherwise, it returns one of the following errors: + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid \a command-queue. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by + * the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY(cl_int, clEnqueueBarrierWithWaitList, + (cl_command_queue command_queue, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::HostQueue* hostQueue = as_amd(command_queue)->asHostQueue(); + if (NULL == hostQueue) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, *hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + //!@note: with the current runtime architecture and in-order execution + //! barrier and marker should be the same operation + amd::Command* command = new amd::Marker(*hostQueue, true, eventWaitList); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * + * \addtogroup CL_Profiling Profiling Operations on Memory Objects and Kernels + * + * Profiling of OpenCL functions that are enqueued as commands to a + * command-queue. The specific functions being referred to are: + * - clEnqueue{Read|Write|Map}Buffer, + * - clEnqueue{Read|Write|Map}Image, + * - clEnqueueCopy{Buffer|Image}, + * - clEnqueueCopyImageToBuffer, + * - clEnqueueCopyBufferToImage, + * - clEnqueueNDRangeKernel , + * - clEnqueueTask and + * - clEnqueueNativeKernel. + * These enqueued commands are identified by unique event objects. + * + * Event objects can be used to capture profiling information that measure + * execution time of a command. Profiling of OpenCL commands can be enabled + * either by using a command-queue created with CL_QUEUE_PROFILING_ENABLE + * flag set in properties arguments to clCreateCommandQueue or by setting the + * CL_QUEUE_PROFILING_ENABLE flag in properties arguments to + * clSetCommandQueueProperty. + * + * @{ + */ + +/*! \brief Return profiling information for the command associated with event. + * + * \param event specifies the event object. + * + * \param param_name specifies the profiling data to query. + * + * \param param_value is a pointer to memory where the appropriate result being + * queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type + * + * \param param_value_size_ret returns the actual size in bytes of data copied + * to \a param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * The unsigned 64-bit values returned can be used to measure the time in + * nano-seconds consumed by OpenCL commands. OpenCL devices are required to + * correctly track time across changes in frequency and p-states. The + * CL_DEVICE_PROFILING_TIMER_RESOLUTION specifies the resolution of the timer + * i.e. the number of nanoseconds elapsed before the timer is incremented. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully and the profiling + * information has been recorded + * - CL_PROFILING_INFO_NOT_AVAILABLE if the profiling information is currently + * not available (because the command identified by event has not completed) + * - CL_INVALID_VALUE if \a param_name is not valid, or if size in bytes + * specified by param_value_size is < size of return type and \a param_value + * is not NULL + * - CL_INVALID_EVENT if \a event is a not a valid event object. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(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)) { + if (!is_valid(event)) { + return CL_INVALID_EVENT; + } + + if (!as_amd(event)->profilingInfo().enabled_) { + return CL_PROFILING_INFO_NOT_AVAILABLE; + } + + if (param_value != NULL && param_value_size < sizeof(cl_ulong)) { + return CL_INVALID_VALUE; + } + + *not_null(param_value_size_ret) = sizeof(cl_ulong); + if (param_value != NULL) { + cl_ulong value = 0; + switch (param_name) { + case CL_PROFILING_COMMAND_END: + case CL_PROFILING_COMMAND_COMPLETE: + value = as_amd(event)->profilingInfo().end_; + break; + + case CL_PROFILING_COMMAND_START: + value = as_amd(event)->profilingInfo().start_; + break; + + case CL_PROFILING_COMMAND_SUBMIT: + value = as_amd(event)->profilingInfo().submitted_; + break; + + case CL_PROFILING_COMMAND_QUEUED: + value = as_amd(event)->profilingInfo().queued_; + break; + + default: + return CL_INVALID_VALUE; + } + if (value == 0) { + return CL_PROFILING_INFO_NOT_AVAILABLE; + } + *(cl_ulong*)param_value = value; + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Returns a reasonably synchronized pair of timestamps from the device + * timer and the host timer as seen by device. + * + * \param device a device returned by clGetDeviceIDs. + * + * \param device_timestamp will be updated with the value of the current timer + * in nanoseconds. The resolution of the timer is the same as the device + * profiling timer returned by clGetDeviceInfo and the + * CL_DEVICE_PROFILING_TIMER_RESOLUTION query. + * + * \param host_timestamp will be updated with the value of the current timer + * in nanoseconds at the closest possible point in time to that at which + * device_timer was returned. The resolution of the timer may be queried + * via clGetPlatformInfo and the flag CL_PLATFORM_HOST_TIMER_RESOLUTION. + * + * Returns a reasonably synchronized pair of timestamps from the device + * timer and the host timer as seen by device. Implementations may need + * to execute this query with a high latency in order to provide reasonable + * synchronization of the timestamps. The host timestamp and device timestamp + * returned by this function and clGetHostTimer each have an implementation + * defined timebase. The timestamps will always be in their respective timebases + * regardless of which query function is used. The timestamp returned from + * clGetEventProfilingInfo for an event on a device and a device timestamp + * queried from the same device will always be in the same timebase. + * + * \return One of the following values: + * - CL_SUCCESS if a time value in host_timestamp is provided + * - CL_INVALID_DEVICE if device is not a valid OpenCL device. + * - CL_INVALID_VALUE if host_timestamp is NULL. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + */ +RUNTIME_ENTRY(cl_int, clGetDeviceAndHostTimer, + (cl_device_id device, cl_ulong * device_timestamp, + cl_ulong * host_timestamp)) { + + if (!is_valid(device)) { + return CL_INVALID_DEVICE; + } + + if (!device_timestamp || !host_timestamp) { + return CL_INVALID_VALUE; + } + + // The device timestamp and host timestamp use the same timebase. + *device_timestamp = *host_timestamp = amd::Os::timeNanos(); + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Return the current value of the host clock as seen by device. + * + * \param device a device returned by clGetDeviceIDs. + * + * \param host_timestamp will be updated with the value of the current timer + * in nanoseconds. The resolution of the timer may be queried via + * clGetPlatformInfo and the flag CL_PLATFORM_HOST_TIMER_RESOLUTION. + * + * Return the current value of the host clock as seen by device. This value + * is in the same timebase as the host_timestamp returned from + * clGetDeviceAndHostTimer. The implementation will return with as low a + * latency as possible to allow a correlation with a subsequent application + * sampled time. The host timestamp and device timestamp returned by this + * function and clGetDeviceAndHostTimer each have an implementation defined + * timebase. The timestamps will always be in their respective timebases + * regardless of which query function is used. The timestamp returned from + * clGetEventProfilingInfo for an event on a device and a device timestamp + * queried from the same device will always be in the same timebase. + * + * \return One of the following values: + * + * - CL_SUCCESS if a time value in host_timestamp is provided + * - CL_INVALID_DEVICE if device is not a valid OpenCL device. + * - CL_INVALID_VALUE if host_timestamp is NULL. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + */ +RUNTIME_ENTRY(cl_int, clGetHostTimer, + (cl_device_id device, cl_ulong * host_timestamp)) { + + if (!is_valid(device)) { + return CL_INVALID_DEVICE; + } + + if (!host_timestamp) { + return CL_INVALID_VALUE; + } + + *host_timestamp = amd::Os::timeNanos(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_FlushFinish Flush and Finish + * @{ + */ + +/*! \brief Issue all previously queued OpenCL commands in \a command_queue to + * the device associated with command_queue. + * + * clFlush only guarantees that all queued commands to \a command_queue get + * issued to the appropriate device. There is no guarantee that they will be + * complete after clFlush returns. + * + * \return One of the following values: + * - CL_SUCCESS if the function call was executed successfully + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * Any blocking commands queued in a command-queue such as + * clEnqueueRead{Image|Buffer} with \a blocking_read set to CL_TRUE, + * clEnqueueWrite{Image|Buffer} with \a blocking_write set to CL_TRUE, + * clEnqueueMap{Buffer|Image} with \a blocking_map set to CL_TRUE or + * clWaitForEvents perform an implicit flush of the command-queue. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clFlush, (cl_command_queue command_queue)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::HostQueue* hostQueue = as_amd(command_queue)->asHostQueue(); + if (NULL == hostQueue) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::Command* command = new amd::Marker(*hostQueue, false); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + command->enqueue(); + command->release(); + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Block until all previously queued OpenCL runtime commands in + * \a command_queue are issued to the associated device and have completed. + * + * clFinish does not return until all queued commands in \a command_queue have + * been processed and completed. clFinish is also a synchronization point. + * + * \return One of the following values: + * - CL_SUCCESS if the function call was executed successfully. + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clFinish, (cl_command_queue command_queue)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::HostQueue* hostQueue = as_amd(command_queue)->asHostQueue(); + if (NULL == hostQueue) { + return CL_INVALID_COMMAND_QUEUE; + } + + hostQueue->finish(); + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * @} + */ diff --git a/opencl/amdocl/cl_gl.cpp b/opencl/amdocl/cl_gl.cpp new file mode 100644 index 0000000000..5c46bd54ea --- /dev/null +++ b/opencl/amdocl/cl_gl.cpp @@ -0,0 +1,2474 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "top.hpp" + +#ifdef _WIN32 +#include +#include +#include +// This is necessary since there are common GL/D3D10 functions +#include "cl_d3d9_amd.hpp" +#include "cl_d3d10_amd.hpp" +#include "cl_d3d11_amd.hpp" +#endif //_WIN32 + +#include +#include + +#include +#include +#include + +#include "cl_common.hpp" +#include "cl_gl_amd.hpp" + +#include "device/device.hpp" + +/* The pixel internal format for DOPP texture defined in gl_enum.h */ +#define GL_BGR8_ATI 0x8083 +#define GL_BGRA8_ATI 0x8088 + +#include +#include + + +/*! \addtogroup API + * @{ + * + * \addtogroup CL_GL_Interops + * + * This section discusses OpenCL functions that allow applications to + * use OpenGL buffer/texture/render-buffer objects as OpenCL memory + * objects. This allows efficient sharing of data between these OpenCL + * and OpenGL. The OpenCL API can be used to execute kernels that read + * and/or write memory objects that are also an OpenGL buffer object + * or a texture. An OpenCL image object can be created from an OpenGL + * texture or renderbuffer object. An OpenCL buffer object can be + * created from an OpenGL buffer object. An OpenCL memory object can + * be created from an OpenGL texture/buffer/render-buffer object or + * the default system provided framebuffer if any only if the OpenCL + * clContext has been created from a GL clContext. OpenGL contexts are + * created using platform specific APIs (EGL, CGL, WGL, GLX are some + * of the platform specific APIs that allow applications to create GL + * contexts). The appropriate platform API (such as EGL, CGL, WGL, + * GLX) will be extended to allow a CL clContext to be created from a + * GL clContext. Creating an OpenCL memory object from the default + * system provided framebuffer will also require an appropriate + * extension to the platform API. Refer to the appropriate platform + * API documentation to understand how to create a CL clContext from a + * GL clContext and creating a CL memory object from the default + * system provided framebuffer. + * + * @{ + * + * \addtogroup clCreateFromGLBuffer + * + * @{ + */ + +/*! \brief Creates an OpenCL buffer object from an OpenGL buffer object. + * + * \param clContext is a valid OpenCL clContext created from an OpenGL clContext. + * + * \param clFlags is a bit-field that is used to specify usage information. Only + * CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY and CL_MEM_READ_WRITE can be used. + * + * \param glBufferName is a GL buffer object name. The GL buffer + * object must have a data store created though it does not need to + * be initialized. The size of the data store will be used to + * determine the size of the CL buffer object. + * + * \param pCpuMem is a pointer to the buffer data that may already be + * allocated by the application. The size of the buffer that pCpuMem points + * to must be >= \a size bytes. Passing in a pointer to an already allocated + * buffer on the host and using it as a buffer object allows applications to + * share data efficiently with kernels and the host. + * + * \param errcode_ret will return an appropriate error code. If errcode_ret + * is NULL, no error code is returned. + * + * \return valid non-zero OpenCL buffer object and errcode_ret is set + * to CL_SUCCESS if the buffer object is created successfully. It + * returns a NULL value with one of the following error values + * returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a clContext is not a valid clContext. + * - CL_INVALID_VALUE if values specified in \a clFlags are not valid. + * - CL_INVALID_GL_OBJECT if glBufferName is not a GL buffer object or is a + * GL buffer object but does not have a data store created. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r29 + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateFromGLBuffer, + (cl_context context, cl_mem_flags flags, GLuint bufobj, cl_int* errcode_ret)) { + cl_mem clMemObj = NULL; + + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return clMemObj; + } + + if (!(((flags & CL_MEM_READ_ONLY) == CL_MEM_READ_ONLY) || + ((flags & CL_MEM_WRITE_ONLY) == CL_MEM_WRITE_ONLY) || + ((flags & CL_MEM_READ_WRITE) == CL_MEM_READ_WRITE))) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return clMemObj; + } + + return (amd::clCreateFromGLBufferAMD(*as_amd(context), flags, bufobj, errcode_ret)); +} +RUNTIME_EXIT + +/*! \brief creates the following: + * - an OpenCL 2D image object from an OpenGL 2D texture object + * or a single face of an OpenGL cubemap texture object, + * - an OpenCL 2D image array object from an OpenGL 2D texture array object, + * - an OpenCL 1D image object from an OpenGL 1D texture object, + * - an OpenCL 1D image buffer object from an OpenGL texture buffer object, + * - an OpenCL 1D image array object from an OpenGL 1D texture array object, + * - an OpenCL 3D image object from an OpenGL 3D texture object. + * + * \param clContext is a valid OpenCL clContext created from an OpenGL clContext. + * + * \param clFlags is a bit-field that is used to specify usage information. + * Only CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY and CL_MEM_READ_WRITE values + * can be used. + * + * \param texture_target must be GL_TEXTURE_1D, GL_TEXTURE_1D_ARRAY, + * GL_TEXTURE_BUFFER, GL_TEXTURE_2D_ARRAY, GL_TEXTURE_3D, + * GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP_POSITIVE_X, + * GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, + * GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, + * GL_TEXTURE_CUBE_MAP_NEGATIVE_Z or GL_TEXTURE_RECTANGLE_ARB. + * + * \param miplevel is the mipmap level to be used. If \a texture_target + * is GL_TEXTURE_BUFFER, \a miplevel must be 0. + * + * \param texture is a GL 1D, 2D, 3D, 1D array, 2D array, cubemap, + * rectangle or buffer texture object. + * The texture object must be a complete texture as per + * OpenGL rules on texture completeness. The texture format and dimensions + * defined by OpenGL for the specified miplevel of the texture will be + * used to create the OpenCL image memory object. Only GL texture formats + * that map to appropriate image channel order and data type can be used + * to create the the OpenCL image memory object. + * + * \param errcode_ret will return an appropriate error code. If \a + * errcode_ret is NULL, no error code is returned. + * + * \return A valid non-zero OpenCL image object and \a errcode_ret is set to + * CL_SUCCESS if the image object is created successfully. It returns a NULL value + * with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a clContext is not a valid clContext or was not + * created from a GL clContext. + * - CL_INVALID_VALUE if values specified in \a clFlags are not valid. + * - CL_INVALID_MIP_LEVEL if \a miplevel is not a valid mip-level for \a texture. + * - CL_INVALID_GL_OBJECT if \a texture is not an appropriate GL 2D texture, + * cubemap or texture rectangle. + * - CL_INVALID_IMAGE_FORMAT_DESCRIPTOR if the OpenGL texture format does not + * map to an appropriate OpenCL image format. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateFromGLTexture, + (cl_context context, cl_mem_flags flags, GLenum texture_target, GLint miplevel, + GLuint texture, cl_int* errcode_ret)) { + cl_mem clMemObj = NULL; + + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return clMemObj; + } + + if (!(((flags & CL_MEM_READ_ONLY) == CL_MEM_READ_ONLY) || + ((flags & CL_MEM_WRITE_ONLY) == CL_MEM_WRITE_ONLY) || + ((flags & CL_MEM_READ_WRITE) == CL_MEM_READ_WRITE))) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return clMemObj; + } + + const std::vector& devices = as_amd(context)->devices(); + bool supportPass = false; + bool sizePass = false; + for (const auto& it : devices) { + if (it->info().imageSupport_) { + supportPass = true; + } + } + if (!supportPass) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + LogWarning("there are no devices in context to support images"); + return static_cast(0); + } + + return amd::clCreateFromGLTextureAMD(*as_amd(context), flags, texture_target, miplevel, texture, + errcode_ret); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clCreateFromGLTexture2D + * @{ + */ + +/*! \brief Create an OpenCL 2D image object from an OpenGL 2D texture object. + * + * \param clContext is a valid OpenCL clContext created from an OpenGL clContext. + * + * \param clFlags is a bit-field that is used to specify usage information. + * Only CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY and CL_MEM_READ_WRITE values + * can be used. + * + * \param target must be GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP_POSITIVE_X, + * GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, + * GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, + * GL_TEXTURE_CUBE_MAP_NEGATIVE_Z or GL_TEXTURE_RECTANGLE_ARB. + * + * \param miplevel is the mipmap level to be used. + * + * \param texture is a GL 2D texture, cubemap or texture rectangle + * object name. The texture object must be a complete texture as per + * OpenGL rules on texture completeness. The \a texture format and + * dimensions specified using appropriate glTexImage2D call for \a + * miplevel will be used to create the 2D image object. Only GL + * texture formats that map to appropriate image channel order and + * data type can be used to create the 2D image object. + * + * \param errcode_ret will return an appropriate error code. If \a + * errcode_ret is NULL, no error code is returned. + * + * \return A valid non-zero OpenCL image object and \a errcode_ret is set to + * CL_SUCCESS if the image object is created successfully. It returns a NULL value + * with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a clContext is not a valid clContext or was not + * created from a GL clContext. + * - CL_INVALID_VALUE if values specified in \a clFlags are not valid. + * - CL_INVALID_MIP_LEVEL if \a miplevel is not a valid mip-level for \a texture. + * - CL_INVALID_GL_OBJECT if \a texture is not an appropriate GL 2D texture, + * cubemap or texture rectangle. + * - CL_INVALID_IMAGE_FORMAT_DESCRIPTOR if the OpenGL texture format does not + * map to an appropriate OpenCL image format. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r29 + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateFromGLTexture2D, + (cl_context context, cl_mem_flags flags, GLenum target, GLint miplevel, + GLuint texture, cl_int* errcode_ret)) { + cl_mem clMemObj = NULL; + + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return clMemObj; + } + + if (!(((flags & CL_MEM_READ_ONLY) == CL_MEM_READ_ONLY) || + ((flags & CL_MEM_WRITE_ONLY) == CL_MEM_WRITE_ONLY) || + ((flags & CL_MEM_READ_WRITE) == CL_MEM_READ_WRITE))) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return clMemObj; + } + + const std::vector& devices = as_amd(context)->devices(); + bool supportPass = false; + bool sizePass = false; + for (const auto& it : devices) { + if (it->info().imageSupport_) { + supportPass = true; + } + } + if (!supportPass) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + LogWarning("there are no devices in context to support images"); + return static_cast(0); + } + + return amd::clCreateFromGLTextureAMD(*as_amd(context), flags, target, miplevel, texture, + errcode_ret); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clCreateFromGLTexture3D + * @{ + */ + +/*! \brief Create an OpenCL 3D image object from an OpenGL 3D texture object. + * + * \param clContext is a valid OpenCL clContext created from an OpenGL clContext. + * + * \param clFlags is a bit-field that is used to specify usage information. + * Only CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY and CL_MEM_READ_WRITE values + * can be used. + * + * \param target must be GL_TEXTURE_3D. + * + * \param miplevel is the mipmap level to be used. + * + * \param texture is a GL 3D texture object [name]. + * The texture object must be a complete texture as per OpenGL rules on texture + * completeness. The \a texture format and dimensions specified using appropriate + * glTexImage3D call for \a miplevel will be used to create the 3D image object. + * Only GL texture formats that map to appropriate image channel order and + * data type can be used to create the 3D image object. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A valid non-zero OpenCL image object and \a errcode_ret is set to + * CL_SUCCESS if the image object is created successfully. It returns a NULL value + * with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a clContext is not a valid clContext or was not + * created from a GL clContext. + * - CL_INVALID_VALUE if values specified in \a clFlags are not valid. + * - CL_INVALID_MIP_LEVEL if \a miplevel is not a valid mip-level for \a texture. + * - CL_INVALID_GL_OBJECT if \a texture is not an GL 3D texture. + * - CL_INVALID_IMAGE_FORMAT_DESCRIPTOR if the OpenGL texture format does not + * map to an appropriate OpenCL image format. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r29 + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateFromGLTexture3D, + (cl_context context, cl_mem_flags flags, GLenum target, GLint miplevel, + GLuint texture, cl_int* errcode_ret)) { + cl_mem clMemObj = NULL; + + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return clMemObj; + } + + if (!(((flags & CL_MEM_READ_ONLY) == CL_MEM_READ_ONLY) || + ((flags & CL_MEM_WRITE_ONLY) == CL_MEM_WRITE_ONLY) || + ((flags & CL_MEM_READ_WRITE) == CL_MEM_READ_WRITE))) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return clMemObj; + } + + const std::vector& devices = as_amd(context)->devices(); + bool supportPass = false; + bool sizePass = false; + for (const auto& it : devices) { + if (it->info().imageSupport_) { + supportPass = true; + } + } + if (!supportPass) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + LogWarning("there are no devices in context to support images"); + return static_cast(0); + } + + return amd::clCreateFromGLTextureAMD(*as_amd(context), flags, target, miplevel, texture, + errcode_ret); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clCreateFromGLRenderbuffer + * @{ + */ + +/*! \brief Create an OpenCL 2D image object from an OpenGL renderbuffer object. + * + * \param clContext is a valid OpenCL clContext created from an OpenGL clContext. + * + * \param clFlags is a bit-field that is used to specify usage information. + * Only CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY and CL_MEM_READ_WRITE values + * can be used. + * + * \param renderbuffer is a GL renderbuffer object name. The renderbuffer + * storage must be specified before the image object can be created. Only + * GL renderbuffer formats that map to appropriate image channel order and + * data type can be used to create the 2D image object. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A valid non-zero OpenCL image object and \a errcode_ret is set + * to CL_SUCCESS if the image object is created successfully. It returns a + * NULL value with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a clContext is not a valid clContext or was not + * created from a GL clContext. + * - CL_INVALID_VALUE if values specified in \a clFlags are not valid. + * - CL_INVALID_GL_OBJECT if \a renderbuffer is not an GL renderbuffer object. + * - CL_INVALID_IMAGE_FORMAT_DESCRIPTOR if the OpenGL renderbuffer format + * does not map to an appropriate OpenCL image format. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r29 + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateFromGLRenderbuffer, (cl_context context, cl_mem_flags flags, + GLuint renderbuffer, cl_int* errcode_ret)) { + cl_mem clMemObj = NULL; + + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return clMemObj; + } + + if (!(((flags & CL_MEM_READ_ONLY) == CL_MEM_READ_ONLY) || + ((flags & CL_MEM_WRITE_ONLY) == CL_MEM_WRITE_ONLY) || + ((flags & CL_MEM_READ_WRITE) == CL_MEM_READ_WRITE))) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return clMemObj; + } + + return (amd::clCreateFromGLRenderbufferAMD(*as_amd(context), flags, renderbuffer, errcode_ret)); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clGetGLObjectInfo + * @{ + */ + +/*! \brief Query GL object type from a CL memory object. + * + * \param memobj [is a valid cl_mem object created from a GL object]. + * + * \param gl_object_type returns the type of GL object attached to memobj + * and can be CL_GL_OBJECT_BUFFER, CL_GL_OBJECT_TEXTURE2D, + * CL_GL_OBJECT_TEXTURE_RECTANGLE, CL_GL_OBJECT_TEXTURE3D, or + * CL_GL_OBJECT_RENDERBUFFER. If \a gl_object_type is NULL, it is ignored. + * + * \param gl_object_name returns the GL object name used to create memobj. + * If \a gl_object_name is NULL, it is ignored. + * + * \return One of the following values is returned: + * - CL_SUCCESS if the call was executed successfully. + * - CL_INVALID_MEM_OBJECT if \a memobj is not a valid OpenCL memory object. + * - CL_INVALID_GL_OBJECT if there is no GL object associated with \a memobj. + * + * \version 1.0r29 + */ +RUNTIME_ENTRY(cl_int, clGetGLObjectInfo, + (cl_mem memobj, cl_gl_object_type* gl_object_type, GLuint* gl_object_name)) { + if (!is_valid(memobj)) { + LogWarning("\"memobj\" is not a valid cl_mem object"); + return CL_INVALID_MEM_OBJECT; + } + + amd::InteropObject* interop = as_amd(memobj)->getInteropObj(); + if (NULL == interop) { + LogWarning("CL object \"memobj\" is not created from GL object"); + return CL_INVALID_GL_OBJECT; + } + + amd::GLObject* glObject = interop->asGLObject(); + if (NULL == glObject) { + LogWarning("CL object \"memobj\" is not created from GL object"); + return CL_INVALID_GL_OBJECT; + } + + cl_int result; + + cl_gl_object_type clGLType = glObject->getCLGLObjectType(); + result = amd::clGetInfo(clGLType, sizeof(cl_gl_object_type), gl_object_type, NULL); + + GLuint glName = glObject->getGLName(); + result |= amd::clGetInfo(glName, sizeof(GLuint), gl_object_name, NULL); + + return result; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clGetGLTextureInfo + * @{ + */ + +/*! \brief Query additional information about the GL texture object associated + * with \a memobj. + * + * \param memobj [is a valid cl_mem object created from a GL object]. + * + * \param param_name specifies what additional information about the GL + * texture object associated with \a memobj to query: + * - CL_GL_TEXTURE_TARGET (GLenum) to query the \a target argument specified + * in clCreateGLTexture2D or clCreateGLTexture3D calls. + * - CL_GL_MIPMAP_LEVEL (GLint) to query the \a miplevel argument specified + * in clCreateGLTexture2D or clCreateGLTexture3D calls. + * + * \param param_value is a pointer to memory where the appropriate result + * being queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type as + * described for \a param_name argumnet (GLenum or GLint). + * \a param_value_size_ret returns the actual size in bytes of data copied to + * \a param_value. If \a param_value_size_ret is NULL, it is ignored + * + * \return One of the following values is returned: + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_MEM_OBJECT if \a memobj is not a valid OpenCL memory object. + * - CL_INVALID_GL_OBJECT if there is no GL texture object (2D or 3D texture) + * associated with \a memobj. + * - CL_INVALID_VALUE if \a param_name is not valid, or if size in bytes + * specified by \a param_value_size is < size of return type required by + * \a param_name and \a param_value is not NULL, or if \a param_value and + * \a param_value_size_ret are NULL. + * + * \version 1.0r29 + */ +RUNTIME_ENTRY(cl_int, clGetGLTextureInfo, + (cl_mem memobj, cl_gl_texture_info param_name, size_t param_value_size, + void* param_value, size_t* param_value_size_ret)) { + if (!is_valid(memobj)) { + LogWarning("\"memobj\" is not a valid cl_mem object"); + return CL_INVALID_MEM_OBJECT; + } + amd::InteropObject* interop = as_amd(memobj)->getInteropObj(); + if (NULL == interop) { + LogWarning("CL object \"memobj\" is not created from GL object"); + return CL_INVALID_GL_OBJECT; + } + amd::GLObject* glObject = interop->asGLObject(); + if ((NULL == glObject) || (NULL != glObject->asBufferGL())) { + LogWarning("CL object \"memobj\" is not created from GL texture"); + return CL_INVALID_GL_OBJECT; + } + + switch (param_name) { + case CL_GL_TEXTURE_TARGET: { + GLenum glTarget = glObject->getGLTarget(); + if (glTarget == GL_TEXTURE_CUBE_MAP) { + glTarget = glObject->getCubemapFace(); + } + return amd::clGetInfo(glTarget, param_value_size, param_value, param_value_size_ret); + } + case CL_GL_MIPMAP_LEVEL: { + GLint mipLevel = glObject->getGLMipLevel(); + return amd::clGetInfo(mipLevel, param_value_size, param_value, param_value_size_ret); + } + case CL_GL_NUM_SAMPLES: { + GLsizei numSamples = glObject->getNumSamples(); + return amd::clGetInfo(numSamples, param_value_size, param_value, param_value_size_ret); + } + default: + LogWarning("Unknown param_name in clGetGLTextureInfoAMD"); + break; + } + + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clEnqueueAcquireExtObjects + * @{ + */ + +/*! \brief Acquire OpenCL memory objects that have been created from external + * objects (OpenGL, D3D). + * + * \param command_queue is a valid command-queue. + * + * \param num_objects is the number of memory objects to be acquired + * in \a mem_objects. + * + * \param mem_objects is a pointer to a list of CL memory objects that refer + * to a GL object (buffer/texture/renderbuffer objects or the framebuffer). + * + * \param event_wait_list specify [is a pointer to] events that need to + * complete before this particular command can be executed. + * If \a event_wait_list is NULL, then this particular command does not wait + * on any event to complete. If \a event_wait_list is NULL, + * \a num_events_in_wait_list must be 0. If \a event_wait_list is not NULL, + * the list of events pointed to by \a event_wait_list must be valid and + * \a num_events_in_wait_list must be greater than 0. The events specified in + * \a event_wait_list act as synchronization points. + * + * \param num_events_in_wait_list specify the number of events in + * \a event_wait_list. It must be 0 if \a event_wait_list is NULL. It must be + * greater than 0 if \a event_wait_list is not NULL. + * + * \param event returns an event object that identifies this particular + * command and can be used to query or queue a wait for this particular + * command to complete. \a event can be NULL in which case it will not be + * possible for the application to query the status of this command or queue a + * wait for this command to complete. + * + * \return One of the following values is returned: + * - CL_SUCCESS if the function is executed successfully. + * - CL_SUCCESS if \a num_objects is 0 and \a mem_objects is NULL; the + * function does nothing. + * - CL_INVALID_VALUE if \a num_objects is zero and \a mem_objects is not a + * NULL value or if \a num_objects > 0 and \a mem_objects is NULL. + * - CL_INVALID_MEM_OBJECT if memory objects in \a mem_objects are not valid + * OpenCL memory objects. + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if clContext associated with \a command_queue was not + * created from an OpenGL clContext. + * - CL_INVALID_GL_OBJECT if memory objects in \a mem_objects have not been + * created from a GL object(s). + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host. + * + * \version 1.0r29 + */ +RUNTIME_ENTRY(cl_int, clEnqueueAcquireGLObjects, + (cl_command_queue command_queue, cl_uint num_objects, const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event)) { + return amd::clEnqueueAcquireExtObjectsAMD(command_queue, num_objects, mem_objects, + num_events_in_wait_list, event_wait_list, event, + CL_COMMAND_ACQUIRE_GL_OBJECTS); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clEnqueueReleaseGLObjects + * @{ + */ + +/*! \brief Release OpenCL memory objects that have been created from OpenGL + * objects. + * + * \param command_queue is a valid command-queue [which is associated with the + * OpenCL clContext releasing the OpenGL objects]. + * + * \param num_objects is the number of memory objects to be released + * in \a mem_objects. + * + * \param mem_objects is a pointer to a list of CL memory objects that refer + * to a GL object (buffer/texture/renderbuffer objects or the framebuffer). + * + * \param event_wait_list specify [is a pointer to] events that need to + * complete before this particular command can be executed. + * If \a event_wait_list is NULL, then this particular command does not wait + * on any event to complete. If \a event_wait_list is NULL, + * \a num_events_in_wait_list must be 0. If \a event_wait_list is not NULL, + * the list of events pointed to by \a event_wait_list must be valid and + * \a num_events_in_wait_list must be greater than 0. The events specified in + * \a event_wait_list act as synchronization points. + * + * \param num_events_in_wait_list specify the number of events in + * \a event_wait_list. It must be 0 if \a event_wait_list is NULL. It must be + * greater than 0 if \a event_wait_list is not NULL. + * + * \param event returns an event object that identifies this particular + * command and can be used to query or queue a wait for this particular + * command to complete. \a event can be NULL in which case it will not be + * possible for the application to query the status of this command or queue a + * wait for this command to complete. + * + * \return One of the following values is returned: + * - CL_SUCCESS if the function is executed successfully. + * - CL_SUCCESS if \a num_objects is 0 and \a mem_objects is NULL; the + * function does nothing. + * - CL_INVALID_VALUE if \a num_objects is zero and \a mem_objects is not a + * NULL value or if \a num_objects > 0 and \a mem_objects is NULL. + * - CL_INVALID_MEM_OBJECT if memory objects in \a mem_objects are not valid + * OpenCL memory objects. + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if clContext associated with \a command_queue was not + * created from an OpenGL clContext. + * - CL_INVALID_GL_OBJECT if memory objects in \a mem_objects have not been + * created from a GL object(s). + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host. + * + * \version 1.0r29 + */ +RUNTIME_ENTRY(cl_int, clEnqueueReleaseGLObjects, + (cl_command_queue command_queue, cl_uint num_objects, const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event)) { + return amd::clEnqueueReleaseExtObjectsAMD(command_queue, num_objects, mem_objects, + num_events_in_wait_list, event_wait_list, event, + CL_COMMAND_RELEASE_GL_OBJECTS); +} +RUNTIME_EXIT + +/*! @} +* \addtogroup clCreateEventFromGLsyncKHR +* @{ +*/ + +/*! \brief Creates an event object linked to an OpenGL sync object. +* Completion of such an event object is equivalent to waiting for completion +* of the fence command associated with the linked GL sync object. +* +* \param context is valid OpenCL context created from an OpenGL context +* or share group, using the cl_khr_gl_sharing extension. +* +* \param sync is the 'name' of a sync object in the GL share group associated +* with context. +* +* \param errcode_ret Returns an appropriate error code as described below. +* If errcode_ret is NULL, no error code is returned. +* +* \return a valid OpenCL event object and errcode_ret is set to CL_SUCCESS +* if the event object is created successfully.Otherwise, it returns a NULL +* value with one of the following error values returned in errcode_ret: +* - CL_INVALID_CONTEXT if context is not a valid context or was not created +* from a GL context. +* - CL_INVALID_GL_OBJECT if sync is not the name of a sync object in the +* GL share group associated with context. +* +* \version 1.1 +*/ + +RUNTIME_ENTRY_RET(cl_event, clCreateEventFromGLsyncKHR, + (cl_context context, cl_GLsync clGLsync, cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return nullptr; + } + // create event of fence sync type + amd::ClGlEvent* clglEvent = new amd::ClGlEvent(*as_amd(context)); + if (clglEvent == nullptr) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + LogWarning("Memory allocation of clglEvent object failed"); + return nullptr; + } + clglEvent->context().glenv()->glFlush_(); + // initially set the status of fence as queued + clglEvent->setStatus(CL_SUBMITTED); + // store GLsync id of the fence in event in order to associate them together + clglEvent->setData(clGLsync); + amd::Event* evt = clglEvent; + evt->retain(); + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(evt); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup clGetGLContextInfoKHR + * @{ + */ + +/*! \brief This f-n is defined in CL extension cl_khr_gl_sharing and serves + * the purpose of quering current device and all devices that support + * CL-GL interoperability. + * + * \param properties points to an , which is a array of + * ordered pairs terminated with zero. If an + * attribute is not specified in , then its default value + * (listed in table 4.attr) is used (it is said to be specified + * implicitly). If is NULL or empty (points to a list + * whose first value is zero), all attributes take on their default + * values. + * + * \param param_name may accept one of the following enumerated values: + * - CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 + * - CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type as + * described for \a param_name argumnet (GLenum or GLint). + * \a param_value_size_ret returns the actual size in bytes of data copied to + * \a param_value. If \a param_value_size_ret is NULL, it is ignored + * + * \param param_value is a pointer to memory where the appropriate result + * being queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type as + * described for \a param_name argumnet (GLenum or GLint). + * \a param_value_size_ret returns the actual size in bytes of data copied to + * \a param_value. If \a param_value_size_ret is NULL, it is ignored + * + * \return one of the following values is returned: + * - CL_SUCCESS if the function is executed successfully. + * - CL_SUCCESS if \a num_objects is 0 and \a mem_objects is NULL; the + * function does nothing. + * - CL_INVALID_VALUE if \a num_objects is zero and \a mem_objects is not a + * NULL value or if \a num_objects > 0 and \a mem_objects is NULL. + * - CL_INVALID_MEM_OBJECT if memory objects in \a mem_objects are not valid + * OpenCL memory objects. + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if clContext associated with \a command_queue was not + * created from an OpenGL clContext. + * - CL_INVALID_GL_OBJECT if memory objects in \a mem_objects have not been + * created from a GL object(s). + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host. + * - CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR if + * + * \version 1.0r47 + */ +RUNTIME_ENTRY(cl_int, clGetGLContextInfoKHR, + (const cl_context_properties* properties, cl_gl_context_info param_name, + size_t param_value_size, void* param_value, size_t* param_value_size_ret)) { + cl_int errcode; + cl_device_id* gpu_devices; + cl_uint num_gpu_devices = 0; + amd::Context::Info info; + static const bool VALIDATE_ONLY = true; + + errcode = amd::Context::checkProperties(properties, &info); + if (CL_SUCCESS != errcode) { + return errcode; + } + + if (!(info.flags_ & amd::Context::GLDeviceKhr)) { + // No GL context is specified + return CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR; + } + + // Get devices + errcode = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 0, NULL, &num_gpu_devices); + if (errcode != CL_SUCCESS && errcode != CL_DEVICE_NOT_FOUND) { + return CL_INVALID_VALUE; + } + + if (!num_gpu_devices) { + return CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR; + } + + switch (param_name) { + case CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR: + // Return the CL device currently associated with the specified OpenGL context. + if (num_gpu_devices) { + gpu_devices = (cl_device_id*)alloca(num_gpu_devices * sizeof(cl_device_id)); + + errcode = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, num_gpu_devices, gpu_devices, NULL); + if (errcode != CL_SUCCESS) { + return errcode; + } + + for (cl_uint i = 0; i < num_gpu_devices; ++i) { + cl_device_id device = gpu_devices[i]; + if (is_valid(device) && + as_amd(device)->bindExternalDevice(info.flags_, info.hDev_, info.hCtx_, + VALIDATE_ONLY)) { + return amd::clGetInfo(device, param_value_size, param_value, param_value_size_ret); + } + } + + *not_null(param_value_size_ret) = 0; + } + break; + + case CL_DEVICES_FOR_GL_CONTEXT_KHR: { + // List of all CL devices that can be associated with the specified OpenGL context. + cl_uint total_devices = num_gpu_devices; + size_t size = total_devices * sizeof(cl_device_id); + + cl_device_id* devices = (cl_device_id*)alloca(size); + + errcode = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, total_devices, + devices, NULL); + if (errcode != CL_SUCCESS) { + return errcode; + } + + std::vector compatible_devices; + + for (cl_uint i = 0; i < total_devices; ++i) { + cl_device_id device = devices[i]; + if (is_valid(device) && + as_amd(device)->bindExternalDevice(info.flags_, info.hDev_, info.hCtx_, + VALIDATE_ONLY)) { + compatible_devices.push_back(as_amd(device)); + } + } + + size_t deviceCount = compatible_devices.size(); + size_t deviceCountSize = deviceCount * sizeof(cl_device_id); + + if (param_value != NULL && param_value_size < deviceCountSize) { + return CL_INVALID_VALUE; + } + + *not_null(param_value_size_ret) = deviceCountSize; + + if (param_value != NULL) { + cl_device_id* deviceList = (cl_device_id*)param_value; + for (const auto& it : compatible_devices) { + *deviceList++ = as_cl(it); + } + } + + return CL_SUCCESS; + } break; + + default: + LogWarning("\"param_name\" is not valid"); + return CL_INVALID_VALUE; + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +// +// +// namespace amd +// +// +namespace amd { + +typedef struct { + GLenum glBinding; + GLenum glTarget; +} TargetBindings_t; + +/*! @} + * \addtogroup CL-GL interop helper functions + * @{ + */ + +//! Function clearGLErrors() to clear all GL error bits, if any +void clearGLErrors(const Context& amdContext) { + GLenum glErr, glLastErr = GL_NO_ERROR; + while (1) { + glErr = amdContext.glenv()->glGetError_(); + if (glErr == GL_NO_ERROR || glErr == glLastErr) { + break; + } + glLastErr = glErr; + LogWarning("GL error"); + } +} + +GLenum checkForGLError(const Context& amdContext) { + GLenum glRetErr = GL_NO_ERROR; + GLenum glErr; + while (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + glRetErr = glErr; // Just return the last GL error + LogWarning("Check GL error"); + } + return glRetErr; +} + +//! Function getCLFormatFromGL returns "true" if GL format +//! is compatible with CL format, "false" otherwise. +bool getCLFormatFromGL(const Context& amdContext, GLint gliInternalFormat, + cl_image_format* pclImageFormat, int* piBytesPerPixel, cl_mem_flags flags) { + bool bRetVal = false; + + /* + Available values for "image_channel_order" + ========================================== + CL_R + CL_A + CL_INTENSITY + CL_LUMINANCE + CL_RG + CL_RA + CL_RGB + CL_RGBA + CL_ARGB + CL_BGRA + + Available values for "image_channel_data_type" + ============================================== + CL_SNORM_INT8 + CL_SNORM_INT16 + CL_UNORM_INT8 + CL_UNORM_INT16 + CL_UNORM_SHORT_565 + CL_UNORM_SHORT_555 + CL_UNORM_INT_101010 + CL_SIGNED_INT8 + CL_SIGNED_INT16 + CL_SIGNED_INT32 + CL_UNSIGNED_INT8 + CL_UNSIGNED_INT16 + CL_UNSIGNED_INT32 + CL_HALF_FLOAT + CL_FLOAT + */ + + switch (gliInternalFormat) { + case GL_RGB10_EXT: + pclImageFormat->image_channel_order = CL_RGBA; + pclImageFormat->image_channel_data_type = CL_UNORM_INT_101010; + *piBytesPerPixel = 4; + bRetVal = true; + break; + + case GL_RGB10_A2: + pclImageFormat->image_channel_order = CL_RGB; + pclImageFormat->image_channel_data_type = CL_UNORM_INT_101010; + *piBytesPerPixel = 4; + bRetVal = true; + break; + + case GL_BGR8_ATI: + case GL_BGRA8_ATI: + pclImageFormat->image_channel_order = CL_BGRA; + pclImageFormat->image_channel_data_type = CL_UNORM_INT8; // CL_UNSIGNED_INT8; + *piBytesPerPixel = 4; + bRetVal = true; + break; + + case GL_ALPHA8: + pclImageFormat->image_channel_order = CL_A; + pclImageFormat->image_channel_data_type = CL_UNORM_INT8; // CL_UNSIGNED_INT8; + *piBytesPerPixel = 1; + bRetVal = true; + break; + + case GL_R8: + case GL_R8UI: + pclImageFormat->image_channel_order = CL_R; + pclImageFormat->image_channel_data_type = + (gliInternalFormat == GL_R8) ? CL_UNORM_INT8 : CL_UNSIGNED_INT8; + *piBytesPerPixel = 1; + bRetVal = true; + break; + + case GL_R8I: + pclImageFormat->image_channel_order = CL_R; + pclImageFormat->image_channel_data_type = CL_SIGNED_INT8; + *piBytesPerPixel = 1; + bRetVal = true; + break; + + case GL_RG8: + case GL_RG8UI: + pclImageFormat->image_channel_order = CL_RG; + pclImageFormat->image_channel_data_type = + (gliInternalFormat == GL_RG8) ? CL_UNORM_INT8 : CL_UNSIGNED_INT8; + *piBytesPerPixel = 2; + bRetVal = true; + break; + + case GL_RG8I: + pclImageFormat->image_channel_order = CL_RG; + pclImageFormat->image_channel_data_type = CL_SIGNED_INT8; + *piBytesPerPixel = 2; + bRetVal = true; + break; + + case GL_RGB8: + case GL_RGB8UI: + pclImageFormat->image_channel_order = CL_RGB; + pclImageFormat->image_channel_data_type = + (gliInternalFormat == GL_RGB8) ? CL_UNORM_INT8 : CL_UNSIGNED_INT8; + *piBytesPerPixel = 3; + bRetVal = true; + break; + + case GL_RGB8I: + pclImageFormat->image_channel_order = CL_RGB; + pclImageFormat->image_channel_data_type = CL_SIGNED_INT8; + *piBytesPerPixel = 3; + bRetVal = true; + break; + + case GL_RGBA: + case GL_RGBA8: + case GL_RGBA8UI: + pclImageFormat->image_channel_order = CL_RGBA; + pclImageFormat->image_channel_data_type = + (gliInternalFormat == GL_RGBA8UI) ? CL_UNSIGNED_INT8 : CL_UNORM_INT8; + *piBytesPerPixel = 4; + bRetVal = true; + break; + + case GL_RGBA8I: + pclImageFormat->image_channel_order = CL_RGBA; + pclImageFormat->image_channel_data_type = CL_SIGNED_INT8; + *piBytesPerPixel = 4; + bRetVal = true; + break; + + case GL_R16: + case GL_R16UI: + pclImageFormat->image_channel_order = CL_R; + pclImageFormat->image_channel_data_type = + (gliInternalFormat == GL_R16) ? CL_UNORM_INT16 : CL_UNSIGNED_INT16; + bRetVal = true; + *piBytesPerPixel = 2; + break; + + case GL_R16I: + pclImageFormat->image_channel_order = CL_R; + pclImageFormat->image_channel_data_type = CL_SIGNED_INT16; + *piBytesPerPixel = 2; + bRetVal = true; + break; + + case GL_R16F: + pclImageFormat->image_channel_order = CL_R; + pclImageFormat->image_channel_data_type = CL_HALF_FLOAT; + *piBytesPerPixel = 2; + bRetVal = true; + break; + + case GL_RG16: + case GL_RG16UI: + pclImageFormat->image_channel_order = CL_RG; + pclImageFormat->image_channel_data_type = + (gliInternalFormat == GL_RG16) ? CL_UNORM_INT16 : CL_UNSIGNED_INT16; + *piBytesPerPixel = 4; + bRetVal = true; + break; + + case GL_RG16I: + pclImageFormat->image_channel_order = CL_RG; + pclImageFormat->image_channel_data_type = CL_SIGNED_INT16; + *piBytesPerPixel = 4; + bRetVal = true; + break; + + case GL_RG16F: + pclImageFormat->image_channel_order = CL_RG; + pclImageFormat->image_channel_data_type = CL_HALF_FLOAT; + *piBytesPerPixel = 4; + bRetVal = true; + break; + + case GL_RGB16: + case GL_RGB16UI: + pclImageFormat->image_channel_order = CL_RGB; + pclImageFormat->image_channel_data_type = + (gliInternalFormat == GL_RGB16) ? CL_UNORM_INT16 : CL_UNSIGNED_INT16; + *piBytesPerPixel = 6; + bRetVal = true; + break; + + case GL_RGB16I: + pclImageFormat->image_channel_order = CL_RGB; + pclImageFormat->image_channel_data_type = CL_SIGNED_INT16; + *piBytesPerPixel = 6; + bRetVal = true; + break; + + case GL_RGB16F: + pclImageFormat->image_channel_order = CL_RGB; + pclImageFormat->image_channel_data_type = CL_HALF_FLOAT; + *piBytesPerPixel = 6; + bRetVal = true; + break; + + case GL_RGBA16: + case GL_RGBA16UI: + pclImageFormat->image_channel_order = CL_RGBA; + pclImageFormat->image_channel_data_type = + (gliInternalFormat == GL_RGBA16) ? CL_UNORM_INT16 : CL_UNSIGNED_INT16; + *piBytesPerPixel = 8; + bRetVal = true; + break; + + case GL_RGBA16I: + pclImageFormat->image_channel_order = CL_RGBA; + pclImageFormat->image_channel_data_type = CL_SIGNED_INT16; + *piBytesPerPixel = 8; + bRetVal = true; + break; + + case GL_RGBA16F: + pclImageFormat->image_channel_order = CL_RGBA; + pclImageFormat->image_channel_data_type = CL_HALF_FLOAT; + *piBytesPerPixel = 8; + bRetVal = true; + break; + + case GL_R32I: + pclImageFormat->image_channel_order = CL_R; + pclImageFormat->image_channel_data_type = CL_SIGNED_INT32; + *piBytesPerPixel = 4; + bRetVal = true; + break; + + case GL_R32UI: + pclImageFormat->image_channel_order = CL_R; + pclImageFormat->image_channel_data_type = CL_UNSIGNED_INT32; + *piBytesPerPixel = 4; + bRetVal = true; + break; + + case GL_R32F: + pclImageFormat->image_channel_order = CL_R; + pclImageFormat->image_channel_data_type = CL_FLOAT; + *piBytesPerPixel = 4; + bRetVal = true; + break; + + case GL_RG32I: + pclImageFormat->image_channel_order = CL_RG; + pclImageFormat->image_channel_data_type = CL_SIGNED_INT32; + *piBytesPerPixel = 8; + bRetVal = true; + break; + + case GL_RG32UI: + pclImageFormat->image_channel_order = CL_RG; + pclImageFormat->image_channel_data_type = CL_UNSIGNED_INT32; + *piBytesPerPixel = 8; + bRetVal = true; + break; + + case GL_RG32F: + pclImageFormat->image_channel_order = CL_RG; + pclImageFormat->image_channel_data_type = CL_FLOAT; + *piBytesPerPixel = 8; + bRetVal = true; + break; + + case GL_RGB32I: + pclImageFormat->image_channel_order = CL_RGB; + pclImageFormat->image_channel_data_type = CL_SIGNED_INT32; + *piBytesPerPixel = 12; + bRetVal = true; + break; + + case GL_RGB32UI: + pclImageFormat->image_channel_order = CL_RGB; + pclImageFormat->image_channel_data_type = CL_UNSIGNED_INT32; + *piBytesPerPixel = 12; + bRetVal = true; + break; + + case GL_RGB32F: + pclImageFormat->image_channel_order = CL_RGB; + pclImageFormat->image_channel_data_type = CL_FLOAT; + *piBytesPerPixel = 12; + bRetVal = true; + break; + + case GL_RGBA32I: + pclImageFormat->image_channel_order = CL_RGBA; + pclImageFormat->image_channel_data_type = CL_SIGNED_INT32; + *piBytesPerPixel = 16; + bRetVal = true; + break; + + case GL_RGBA32UI: + pclImageFormat->image_channel_order = CL_RGBA; + pclImageFormat->image_channel_data_type = CL_UNSIGNED_INT32; + *piBytesPerPixel = 16; + bRetVal = true; + break; + + case GL_RGBA32F: + pclImageFormat->image_channel_order = CL_RGBA; + pclImageFormat->image_channel_data_type = CL_FLOAT; + *piBytesPerPixel = 16; + bRetVal = true; + break; + case GL_DEPTH_COMPONENT32F: + pclImageFormat->image_channel_order = CL_DEPTH; + pclImageFormat->image_channel_data_type = CL_FLOAT; + *piBytesPerPixel = 4; + bRetVal = true; + break; + case GL_DEPTH_COMPONENT16: + pclImageFormat->image_channel_order = CL_DEPTH; + pclImageFormat->image_channel_data_type = CL_UNORM_INT16; + *piBytesPerPixel = 2; + bRetVal = true; + break; + case GL_DEPTH24_STENCIL8: + pclImageFormat->image_channel_order = CL_DEPTH_STENCIL; + pclImageFormat->image_channel_data_type = CL_UNORM_INT24; + *piBytesPerPixel = 4; + bRetVal = true; + break; + case GL_DEPTH32F_STENCIL8: + pclImageFormat->image_channel_order = CL_DEPTH_STENCIL; + pclImageFormat->image_channel_data_type = CL_FLOAT; + *piBytesPerPixel = 5; + bRetVal = true; + break; + default: + LogWarning("unsupported GL internal format"); + break; + } + amd::Image::Format imageFormat(*pclImageFormat); + if (bRetVal && !imageFormat.isSupported(amdContext, 0, flags)) { + bRetVal = false; + } + return bRetVal; +} + +void BufferGL::initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(BufferGL)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); +} + +static GLenum clChannelDataTypeToGlType(cl_channel_type channel_type) { + // Pick + // GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, + // GL_UNSIGNED_INT, GL_FLOAT, GL_2_BYTES, GL_3_BYTES, GL_4_BYTES + // or GL_DOUBLE + switch (channel_type) { + case CL_SNORM_INT8: + return GL_BYTE; + case CL_SNORM_INT16: + return GL_SHORT; + case CL_UNORM_INT8: + return GL_UNSIGNED_BYTE; + case CL_UNORM_INT16: + return GL_UNSIGNED_SHORT; + case CL_SIGNED_INT8: + return GL_BYTE; + case CL_SIGNED_INT16: + return GL_SHORT; + case CL_SIGNED_INT32: + return GL_INT; + case CL_UNSIGNED_INT8: + return GL_UNSIGNED_BYTE; + case CL_UNSIGNED_INT16: + return GL_UNSIGNED_SHORT; + case CL_UNSIGNED_INT32: + return GL_UNSIGNED_INT; + case CL_FLOAT: + return GL_FLOAT; + case CL_UNORM_INT_101010: + return GL_UNSIGNED_INT_10_10_10_2; + case CL_HALF_FLOAT: + case CL_UNORM_SHORT_565: + case CL_UNORM_SHORT_555: + default: + guarantee(false, "Unexpected CL type."); + return 0; + } +} + +static GLenum glInternalFormatToGlFormat(GLenum internalFormat) { + switch (internalFormat) { + // Base internal formats + case GL_RGBA: + case GL_BGRA: + return internalFormat; + // Sized internal formats + case GL_RGBA8: + case GL_RGBA16: + case GL_RGBA16F: + case GL_RGBA32F: + return GL_RGBA; + case GL_RGBA8I: + case GL_RGBA8UI: + case GL_RGBA16I: + case GL_RGBA16UI: + case GL_RGBA32I: + case GL_RGBA32UI: + return GL_RGBA_INTEGER; + + default: + guarantee(false, "Unexpected GL internal format."); + return 0; + } +} + +void ImageGL::initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(ImageGL)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); +} + +//******************************************************************* +// +// Internal implementation of CL API functions +// +//******************************************************************* + +// +// clCreateFromGLBufferAMD +// +cl_mem clCreateFromGLBufferAMD(Context& amdContext, cl_mem_flags flags, GLuint bufobj, + cl_int* errcode_ret) { + BufferGL* pBufferGL = NULL; + GLenum glErr; + GLenum glTarget = GL_ARRAY_BUFFER; + GLint gliSize = 0; + GLint gliMapped = 0; + + // Verify context init'ed for interop + if (!amdContext.glenv() || !amdContext.glenv()->isAssociated()) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("\"amdContext\" is not created from GL context or share list"); + return (cl_mem)0; + } + + // Add this scope to bound the scoped lock + { + GLFunctions::SetIntEnv ie(amdContext.glenv()); + if (!ie.isValid()) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("\"amdContext\" is not created from GL context or share list"); + return as_cl(0); + } + + // Verify GL buffer object + clearGLErrors(amdContext); + if ((GL_FALSE == amdContext.glenv()->glIsBuffer_(bufobj)) || + (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_()))) { + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("\"bufobj\" is not a GL buffer object"); + return (cl_mem)0; + } + + // It seems that CL spec is not concerned with GL_BUFFER_USAGE, so skip it + + // Check if size is available - data store is created + + amdContext.glenv()->glBindBuffer_(glTarget, bufobj); + clearGLErrors(amdContext); + amdContext.glenv()->glGetBufferParameteriv_(glTarget, GL_BUFFER_SIZE, &gliSize); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("cannot get the GL buffer size"); + return (cl_mem)0; + } + if (gliSize == 0) { + //@todo - check why sometime the size is zero + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("the GL buffer's data store is not created"); + return (cl_mem)0; + } + + // Mapping will be done at acquire time (sync point) + + } // Release scoped lock + + // Now create BufferGL object + pBufferGL = new (amdContext) BufferGL(amdContext, flags, gliSize, 0, bufobj); + + if (!pBufferGL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + LogWarning("cannot create object of class BufferGL"); + return (cl_mem)0; + } + + if (!pBufferGL->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + pBufferGL->release(); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + + // Create interop object + if (pBufferGL->getInteropObj() == NULL) { + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("cannot create object of class BufferGL"); + return (cl_mem)0; + } + + // Fixme: If more than one device is present in the context, we choose the first device. + // We should come up with a more elegant solution to handle this. + assert(amdContext.devices().size() == 1); + + const auto it = amdContext.devices().cbegin(); + const amd::Device& dev = *(*it); + + device::Memory* mem = pBufferGL->getDeviceMemory(dev); + if (NULL == mem) { + LogPrintfError("Can't allocate memory size - 0x%08X bytes!", pBufferGL->getSize()); + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + return (cl_mem)0; + } + mem->processGLResource(device::Memory::GLDecompressResource); + + return as_cl(pBufferGL); +} + +cl_mem clCreateFromGLTextureAMD(Context& amdContext, cl_mem_flags clFlags, GLenum target, + GLint miplevel, GLuint texture, int* errcode_ret) { + ImageGL* pImageGL = NULL; + GLenum glErr; + GLenum glTarget = 0; + GLenum glInternalFormat; + cl_image_format clImageFormat; + uint dim = 1; + cl_mem_object_type clType; + cl_gl_object_type clGLType; + GLsizei numSamples = 1; + + // Verify context init'ed for interop + if (!amdContext.glenv() || !amdContext.glenv()->isAssociated()) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("\"amdContext\" is not created from GL context or share list"); + return static_cast(0); + } + + GLint gliTexWidth = 1; + GLint gliTexHeight = 1; + GLint gliTexDepth = 1; + + // Add this scope to bound the scoped lock + { + GLFunctions::SetIntEnv ie(amdContext.glenv()); + if (!ie.isValid()) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("\"amdContext\" is not created from GL context or share list"); + return as_cl(0); + } + + // Verify GL texture object + clearGLErrors(amdContext); + if ((GL_FALSE == amdContext.glenv()->glIsTexture_(texture)) || + (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_()))) { + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("\"texture\" is not a GL texture object"); + return static_cast(0); + } + + bool image = true; + + // Check target value validity + switch (target) { + case GL_TEXTURE_BUFFER: + glTarget = GL_TEXTURE_BUFFER; + dim = 1; + clType = CL_MEM_OBJECT_IMAGE1D_BUFFER; + clGLType = CL_GL_OBJECT_TEXTURE_BUFFER; + image = false; + break; + + case GL_TEXTURE_1D: + glTarget = GL_TEXTURE_1D; + dim = 1; + clType = CL_MEM_OBJECT_IMAGE1D; + clGLType = CL_GL_OBJECT_TEXTURE1D; + break; + + case GL_TEXTURE_CUBE_MAP_POSITIVE_X: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: + glTarget = GL_TEXTURE_CUBE_MAP; + dim = 2; + clType = CL_MEM_OBJECT_IMAGE2D; + clGLType = CL_GL_OBJECT_TEXTURE2D; + break; + + case GL_TEXTURE_1D_ARRAY: + glTarget = GL_TEXTURE_1D_ARRAY; + dim = 2; + clType = CL_MEM_OBJECT_IMAGE1D_ARRAY; + clGLType = CL_GL_OBJECT_TEXTURE1D_ARRAY; + break; + + case GL_TEXTURE_2D: + glTarget = GL_TEXTURE_2D; + dim = 2; + clType = CL_MEM_OBJECT_IMAGE2D; + clGLType = CL_GL_OBJECT_TEXTURE2D; + break; + + case GL_TEXTURE_2D_MULTISAMPLE: + glTarget = GL_TEXTURE_2D_MULTISAMPLE; + dim = 2; + clType = CL_MEM_OBJECT_IMAGE2D; + clGLType = CL_GL_OBJECT_TEXTURE2D; + break; + + case GL_TEXTURE_RECTANGLE_ARB: + glTarget = GL_TEXTURE_RECTANGLE_ARB; + dim = 2; + clType = CL_MEM_OBJECT_IMAGE2D; + clGLType = CL_GL_OBJECT_TEXTURE2D; + break; + + case GL_TEXTURE_2D_ARRAY: + glTarget = GL_TEXTURE_2D_ARRAY; + dim = 3; + clType = CL_MEM_OBJECT_IMAGE2D_ARRAY; + clGLType = CL_GL_OBJECT_TEXTURE2D_ARRAY; + break; + + case GL_TEXTURE_3D: + glTarget = GL_TEXTURE_3D; + dim = 3; + clType = CL_MEM_OBJECT_IMAGE3D; + clGLType = CL_GL_OBJECT_TEXTURE3D; + break; + + default: + // wrong value + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid \"target\" value"); + return static_cast(0); + break; + } + + amdContext.glenv()->glBindTexture_(glTarget, texture); + + // Check if size is available - data store is created + if (image) { + // Check mipmap level for "texture" name + GLint gliTexBaseLevel; + GLint gliTexMaxLevel; + + clearGLErrors(amdContext); + amdContext.glenv()->glGetTexParameteriv_(glTarget, GL_TEXTURE_BASE_LEVEL, &gliTexBaseLevel); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_MIP_LEVEL; + LogWarning("Cannot get base mipmap level of a GL \"texture\" object"); + return static_cast(0); + } + clearGLErrors(amdContext); + amdContext.glenv()->glGetTexParameteriv_(glTarget, GL_TEXTURE_MAX_LEVEL, &gliTexMaxLevel); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_MIP_LEVEL; + LogWarning("Cannot get max mipmap level of a GL \"texture\" object"); + return static_cast(0); + } + if ((gliTexBaseLevel > miplevel) || (miplevel > gliTexMaxLevel)) { + *not_null(errcode_ret) = CL_INVALID_MIP_LEVEL; + LogWarning("\"miplevel\" is not a valid mipmap level of the GL \"texture\" object"); + return static_cast(0); + } + + // Get GL texture format and check if it's compatible with CL format + clearGLErrors(amdContext); + amdContext.glenv()->glGetTexLevelParameteriv_(target, miplevel, GL_TEXTURE_INTERNAL_FORMAT, + (GLint*)&glInternalFormat); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("Cannot get internal format of \"miplevel\" of GL \"texture\" object"); + return static_cast(0); + } + + amdContext.glenv()->glGetTexLevelParameteriv_(target, miplevel, GL_TEXTURE_SAMPLES, + (GLint*)&numSamples); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("Cannot get numbers of samples of GL \"texture\" object"); + return static_cast(0); + } + if (numSamples > 1) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("MSAA \"texture\" object is not suppoerted for the device"); + return static_cast(0); + } + + // Now get CL format from GL format and bytes per pixel + int iBytesPerPixel = 0; + if (!getCLFormatFromGL(amdContext, glInternalFormat, &clImageFormat, &iBytesPerPixel, + clFlags)) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("\"texture\" format does not map to an appropriate CL image format"); + return static_cast(0); + } + + switch (dim) { + case 3: + clearGLErrors(amdContext); + amdContext.glenv()->glGetTexLevelParameteriv_(target, miplevel, GL_TEXTURE_DEPTH, + &gliTexDepth); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("Cannot get the depth of \"miplevel\" of GL \"texure\""); + return static_cast(0); + } + // Fall trough to process other dimensions... + case 2: + clearGLErrors(amdContext); + amdContext.glenv()->glGetTexLevelParameteriv_(target, miplevel, GL_TEXTURE_HEIGHT, + &gliTexHeight); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("Cannot get the height of \"miplevel\" of GL \"texure\""); + return static_cast(0); + } + // Fall trough to process other dimensions... + case 1: + clearGLErrors(amdContext); + amdContext.glenv()->glGetTexLevelParameteriv_(target, miplevel, GL_TEXTURE_WIDTH, + &gliTexWidth); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("Cannot get the width of \"miplevel\" of GL \"texure\""); + return static_cast(0); + } + break; + default: + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid \"target\" value"); + return static_cast(0); + } + } else { + GLint size; + + // In case target is GL_TEXTURE_BUFFER + GLint backingBuffer; + clearGLErrors(amdContext); + amdContext.glenv()->glGetTexLevelParameteriv_( + glTarget, 0, GL_TEXTURE_BUFFER_DATA_STORE_BINDING, &backingBuffer); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("Cannot get backing buffer for GL \"texture buffer\" object"); + return static_cast(0); + } + amdContext.glenv()->glBindBuffer_(glTarget, backingBuffer); + + // Get GL texture format and check if it's compatible with CL format + clearGLErrors(amdContext); + amdContext.glenv()->glGetIntegerv_(GL_TEXTURE_BUFFER_FORMAT_EXT, + reinterpret_cast(&glInternalFormat)); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("Cannot get internal format of \"miplevel\" of GL \"texture\" object"); + return static_cast(0); + } + + // Now get CL format from GL format and bytes per pixel + int iBytesPerPixel = 0; + if (!getCLFormatFromGL(amdContext, glInternalFormat, &clImageFormat, &iBytesPerPixel, + clFlags)) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("\"texture\" format does not map to an appropriate CL image format"); + return static_cast(0); + } + + clearGLErrors(amdContext); + amdContext.glenv()->glGetBufferParameteriv_(glTarget, GL_BUFFER_SIZE, &size); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("Cannot get internal format of \"miplevel\" of GL \"texture\" object"); + return static_cast(0); + } + + gliTexWidth = size / iBytesPerPixel; + } + size_t imageSize = (clType == CL_MEM_OBJECT_IMAGE1D_ARRAY) ? static_cast(gliTexHeight) + : static_cast(gliTexDepth); + + if (!amd::Image::validateDimensions( + amdContext.devices(), clType, static_cast(gliTexWidth), + static_cast(gliTexHeight), static_cast(gliTexDepth), imageSize)) { + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("The GL \"texture\" data store is not created or out of supported dimensions"); + return static_cast(0); + } + + // PBO and mapping will be done at "acquire" time (sync point) + + } // Release scoped lock + + target = (glTarget == GL_TEXTURE_CUBE_MAP) ? target : 0; + + pImageGL = new (amdContext) + ImageGL(amdContext, clType, clFlags, clImageFormat, static_cast(gliTexWidth), + static_cast(gliTexHeight), static_cast(gliTexDepth), glTarget, + texture, miplevel, glInternalFormat, clGLType, numSamples, target); + + if (!pImageGL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + LogWarning("Cannot create class ImageGL - out of memory?"); + return static_cast(0); + } + + if (!pImageGL->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + pImageGL->release(); + return static_cast(0); + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(pImageGL); +} + +// +// clCreateFromGLRenderbufferDAMD +// +cl_mem clCreateFromGLRenderbufferAMD(Context& amdContext, cl_mem_flags clFlags, GLuint renderbuffer, + int* errcode_ret) { + ImageGL* pImageGL = NULL; + GLenum glErr; + + GLenum glTarget = GL_RENDERBUFFER; + GLenum glInternalFormat; + cl_image_format clImageFormat; + + // Verify context init'ed for interop + if (!amdContext.glenv() || !amdContext.glenv()->isAssociated()) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("\"amdContext\" is not created from GL context or share list"); + return (cl_mem)0; + } + + GLint gliRbWidth; + GLint gliRbHeight; + + // Add this scope to bound the scoped lock + { + GLFunctions::SetIntEnv ie(amdContext.glenv()); + if (!ie.isValid()) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("\"amdContext\" is not created from GL context or share list"); + return as_cl(0); + } + + // Verify GL renderbuffer object + clearGLErrors(amdContext); + if ((GL_FALSE == amdContext.glenv()->glIsRenderbufferEXT_(renderbuffer)) || + (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_()))) { + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("\"renderbuffer\" is not a GL texture object"); + return (cl_mem)0; + } + + amdContext.glenv()->glBindRenderbuffer_(glTarget, renderbuffer); + + // Get GL RB format and check if it's compatible with CL format + clearGLErrors(amdContext); + amdContext.glenv()->glGetRenderbufferParameterivEXT_(glTarget, GL_RENDERBUFFER_INTERNAL_FORMAT, + (GLint*)&glInternalFormat); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("Cannot get internal format of GL \"renderbuffer\" object"); + return (cl_mem)0; + } + + // Now get CL format from GL format and bytes per pixel + int iBytesPerPixel = 0; + if (!getCLFormatFromGL(amdContext, glInternalFormat, &clImageFormat, &iBytesPerPixel, + clFlags)) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("\"renderbuffer\" format does not map to an appropriate CL image format"); + return (cl_mem)0; + } + + // Check if size is available - data store is created + clearGLErrors(amdContext); + amdContext.glenv()->glGetRenderbufferParameterivEXT_(glTarget, GL_RENDERBUFFER_WIDTH, + &gliRbWidth); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("Cannot get the width of GL \"renderbuffer\""); + return (cl_mem)0; + } + if (gliRbWidth == 0) { + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("The GL \"renderbuffer\" data store is not created"); + return (cl_mem)0; + } + clearGLErrors(amdContext); + amdContext.glenv()->glGetRenderbufferParameterivEXT_(glTarget, GL_RENDERBUFFER_HEIGHT, + &gliRbHeight); + if (GL_NO_ERROR != (glErr = amdContext.glenv()->glGetError_())) { + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("Cannot get the height of GL \"renderbuffer\""); + return (cl_mem)0; + } + if (gliRbHeight == 0) { + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + LogWarning("The GL \"renderbuffer\" data store is not created"); + return (cl_mem)0; + } + + // PBO and mapping will be done at "acquire" time (sync point) + + } // Release scoped lock + + pImageGL = + new (amdContext) ImageGL(amdContext, CL_MEM_OBJECT_IMAGE2D, clFlags, clImageFormat, + (size_t)gliRbWidth, (size_t)gliRbHeight, 1, glTarget, renderbuffer, + 0, glInternalFormat, CL_GL_OBJECT_RENDERBUFFER, 0); + + if (!pImageGL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + LogWarning("Cannot create class ImageGL from renderbuffer - out of memory?"); + return (cl_mem)0; + } + + if (!pImageGL->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + pImageGL->release(); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(pImageGL); +} + +// +// clEnqueueAcquireExtObjectsAMD +// + +static cl_int clSetInteropObjects(cl_uint num_objects, const cl_mem* mem_objects, + std::vector& interopObjects) { + if ((num_objects == 0 && mem_objects != NULL) || (num_objects != 0 && mem_objects == NULL)) { + return CL_INVALID_VALUE; + } + + while (num_objects-- > 0) { + cl_mem obj = *mem_objects++; + if (!is_valid(obj)) { + return CL_INVALID_MEM_OBJECT; + } + + amd::Memory* mem = as_amd(obj); + if (mem->getInteropObj() == NULL) { + return CL_INVALID_GL_OBJECT; + } + + interopObjects.push_back(mem); + } + return CL_SUCCESS; +} + +cl_int clEnqueueAcquireExtObjectsAMD(cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event, + cl_command_type cmd_type) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (cmd_type == CL_COMMAND_ACQUIRE_GL_OBJECTS) { + GLFunctions* gl_functions = hostQueue.context().glenv(); + // Verify context init'ed for interop + if (!gl_functions || !gl_functions->isAssociated()) { + LogWarning("\"amdContext\" is not created from GL context or share list"); + return CL_INVALID_CONTEXT; + } + // If the cl_khr_gl_event extension is supported, then the OpenCL implementation will ensure + // that any such pending OpenGL operations are complete for an OpenGL context bound + // to the same thread as the OpenCL context. + if (hostQueue.device().settings().checkExtension(ClKhrGlEvent)) { + gl_functions->WaitCurrentGlContext(hostQueue.context().info()); + } + } + + std::vector memObjects; + cl_int err = clSetInteropObjects(num_objects, mem_objects, memObjects); + if (err != CL_SUCCESS) { + return err; + } + + amd::Command::EventWaitList eventWaitList; + err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + +#ifdef _WIN32 + if ((hostQueue.context().info().flags_ & amd::Context::InteropUserSync) == 0) { + //! Make sure D3D10 queues are flushed and all commands are finished + //! before CL side would access interop objects + if (cmd_type == CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR) { + SyncD3D10Objects(memObjects); + } + //! Make sure D3D11 queues are flushed and all commands are finished + //! before CL side would access interop objects + if (cmd_type == CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR) { + SyncD3D11Objects(memObjects); + } + //! Make sure D3D9 queues are flushed and all commands are finished + //! before CL side would access interop objects + if (cmd_type == CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR) { + SyncD3D9Objects(memObjects); + } + } +#endif //_WIN32 + + //! Now create command and enqueue + amd::AcquireExtObjectsCommand* command = new amd::AcquireExtObjectsCommand( + hostQueue, eventWaitList, num_objects, memObjects, cmd_type); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} + + +// +// clEnqueueReleaseExtObjectsAMD +// +cl_int clEnqueueReleaseExtObjectsAMD(cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event, + cl_command_type cmd_type) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + std::vector memObjects; + cl_int err = clSetInteropObjects(num_objects, mem_objects, memObjects); + if (err != CL_SUCCESS) { + return err; + } + + amd::Command::EventWaitList eventWaitList; + err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + //! Now create command and enqueue + amd::ReleaseExtObjectsCommand* command = new amd::ReleaseExtObjectsCommand( + hostQueue, eventWaitList, num_objects, memObjects, cmd_type); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + +#ifdef _WIN32 + if ((hostQueue.context().info().flags_ & amd::Context::InteropUserSync) == 0) { + //! Make sure CL command queue is flushed and all commands are finished + //! before D3D10 side would access interop resources + if (cmd_type == CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR || + cmd_type == CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR || + cmd_type == CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR) { + command->awaitCompletion(); + } + } +#endif //_WIN32 + // If the cl_khr_gl_event extension is supported, then the OpenCL implementation will ensure + // that any pending OpenCL operations are complete for an OpenGL context bound + // to the same thread as the OpenCL context. + if (cmd_type == CL_COMMAND_RELEASE_GL_OBJECTS) { + GLFunctions* gl_functions = hostQueue.context().glenv(); + // Verify context init'ed for interop + if (!gl_functions || !gl_functions->isAssociated()) { + LogWarning("\"amdContext\" is not created from GL context or share list"); + return CL_INVALID_CONTEXT; + } + if (hostQueue.device().settings().checkExtension(ClKhrGlEvent) && + gl_functions->IsCurrentGlContext(hostQueue.context().info())) { + command->awaitCompletion(); + } + } + + *not_null(event) = as_cl(&command->event()); + + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} + +// Placed here as opposed to command.cpp, as glext.h and cl_gl_amd.hpp will have +// to be included because of the GL calls +bool ClGlEvent::waitForFence() { + GLenum ret; + // get fence id associated with fence event + GLsync gs = reinterpret_cast(command().data()); + if (!gs) return false; + +// Try to use DC and GLRC of current thread, if it doesn't exist +// create a new GL context on this thread, which is shared with the original context + +#ifdef _WIN32 + HDC tempDC_ = context().glenv()->wglGetCurrentDC_(); + HGLRC tempGLRC_ = context().glenv()->wglGetCurrentContext_(); + // Set DC and GLRC + if (tempDC_ && tempGLRC_) { + ret = context().glenv()->glClientWaitSync_(gs, GL_SYNC_FLUSH_COMMANDS_BIT, + static_cast(-1)); + if (!(ret == GL_ALREADY_SIGNALED || ret == GL_CONDITION_SATISFIED)) return false; + } else { + tempDC_ = context().glenv()->getDC(); + tempGLRC_ = context().glenv()->getIntGLRC(); + if (!context().glenv()->init(reinterpret_cast(tempDC_), + reinterpret_cast(tempGLRC_))) + return false; + + // Make the newly created GL context current to this thread + context().glenv()->setIntEnv(); + // If fence has not yet executed, wait till it finishes + ret = context().glenv()->glClientWaitSync_(gs, GL_SYNC_FLUSH_COMMANDS_BIT, + static_cast(-1)); + if (!(ret == GL_ALREADY_SIGNALED || ret == GL_CONDITION_SATISFIED)) return false; + // Since we're done making GL calls, restore whatever context was previously current to this + // thread + context().glenv()->restoreEnv(); + } +#else // Lnx + Display* tempDpy_ = context().glenv()->glXGetCurrentDisplay_(); + GLXDrawable tempDrawable_ = context().glenv()->glXGetCurrentDrawable_(); + GLXContext tempCtx_ = context().glenv()->glXGetCurrentContext_(); + // Set internal Display and GLXContext + if (tempDpy_ && tempCtx_) { + ret = context().glenv()->glClientWaitSync_(gs, GL_SYNC_FLUSH_COMMANDS_BIT, + static_cast(-1)); + if (!(ret == GL_ALREADY_SIGNALED || ret == GL_CONDITION_SATISFIED)) return false; + } else { + if (!context().glenv()->init(reinterpret_cast(context().glenv()->getIntDpy()), + reinterpret_cast(context().glenv()->getIntCtx()))) + return false; + + // Make the newly created GL context current to this thread + context().glenv()->setIntEnv(); + // If fence has not yet executed, wait till it finishes + ret = context().glenv()->glClientWaitSync_(gs, GL_SYNC_FLUSH_COMMANDS_BIT, + static_cast(-1)); + if (!(ret == GL_ALREADY_SIGNALED || ret == GL_CONDITION_SATISFIED)) return false; + // Since we're done making GL calls, restore whatever context was previously current to this + // thread + context().glenv()->restoreEnv(); + } +#endif + // If we reach this point, fence should have completed + setStatus(CL_COMPLETE); + return true; +} + +// +// GLFunctions implementation +// + +#ifdef _WIN32 +#define CONVERT_CHAR_GLUBYTE +#else //!_WIN32 +#define CONVERT_CHAR_GLUBYTE (GLubyte*) +#endif //!_WIN32 + +#define GLPREFIX(rtype, fcn, dclargs) \ + if (!(fcn##_ = (PFN_##fcn)GETPROCADDRESS(libHandle_, #fcn))) { \ + if (!(fcn##_ = (PFN_##fcn)GetProcAddress_(reinterpret_cast(#fcn)))) ++missed_; \ + } + +GLFunctions::SetIntEnv::SetIntEnv(GLFunctions* env) : env_(env) { + env_->getLock().lock(); + + // Set environment (DC and GLRC) + isValid_ = env_->setIntEnv(); +} + +GLFunctions::SetIntEnv::~SetIntEnv() { + // Restore environment (CL DC and CL GLRC) + env_->restoreEnv(); + + env_->getLock().unlock(); +} + +GLFunctions::GLFunctions(HMODULE h, bool isEGL) + : libHandle_(h), + missed_(0), + eglDisplay_(EGL_NO_DISPLAY), + eglOriginalContext_(EGL_NO_CONTEXT), + eglInternalContext_(EGL_NO_CONTEXT), + eglTempContext_(EGL_NO_CONTEXT), + isEGL_(isEGL), +#ifdef _WIN32 + hOrigGLRC_(0), + hDC_(0), + hIntGLRC_(0) +#else //!_WIN32 + Dpy_(0), + Drawable_(0), + origCtx_(0), + intDpy_(0), + intDrawable_(0), + intCtx_(0), + XOpenDisplay_(NULL), + XCloseDisplay_(NULL), + glXGetCurrentDrawable_(NULL), + glXGetCurrentDisplay_(NULL), + glXGetCurrentContext_(NULL), + glXChooseVisual_(NULL), + glXCreateContext_(NULL), + glXDestroyContext_(NULL), + glXMakeCurrent_(NULL) +#endif //!_WIN32 +{ +#define VERIFY_POINTER(p) \ + if (NULL == p) { \ + missed_++; \ + } + + if (isEGL_) { + GetProcAddress_ = (PFN_xxxGetProcAddress)GETPROCADDRESS(h, "eglGetProcAddress"); + eglGetCurrentContext_ = (PFN_eglGetCurrentContext)GETPROCADDRESS(h, "eglGetCurrentContext"); + VERIFY_POINTER(eglGetCurrentContext_) + } else { + GetProcAddress_ = (PFN_xxxGetProcAddress)GETPROCADDRESS(h, API_GETPROCADDR); + } +#ifndef _WIN32 + // Initialize pointers to X11/GLX functions + // We can not link with these functions on compile time since we need to support + // console mode. In console mode X server and X server components may be absent. + // Hence linking with X11 or libGL will fail module image loading in console mode.-tzachi cohen + + if (!isEGL_) { + glXGetCurrentDrawable_ = (PFNglXGetCurrentDrawable)GETPROCADDRESS(h, "glXGetCurrentDrawable"); + VERIFY_POINTER(glXGetCurrentDrawable_) + glXGetCurrentDisplay_ = (PFNglXGetCurrentDisplay)GETPROCADDRESS(h, "glXGetCurrentDisplay"); + VERIFY_POINTER(glXGetCurrentDisplay_) + glXGetCurrentContext_ = (PFNglXGetCurrentContext)GETPROCADDRESS(h, "glXGetCurrentContext"); + VERIFY_POINTER(glXGetCurrentContext_) + glXChooseVisual_ = (PFNglXChooseVisual)GETPROCADDRESS(h, "glXChooseVisual"); + VERIFY_POINTER(glXChooseVisual_) + glXCreateContext_ = (PFNglXCreateContext)GETPROCADDRESS(h, "glXCreateContext"); + VERIFY_POINTER(glXCreateContext_) + glXDestroyContext_ = (PFNglXDestroyContext)GETPROCADDRESS(h, "glXDestroyContext"); + VERIFY_POINTER(glXDestroyContext_) + glXMakeCurrent_ = (PFNglXMakeCurrent)GETPROCADDRESS(h, "glXMakeCurrent"); + VERIFY_POINTER(glXMakeCurrent_) + + HMODULE hXModule = (HMODULE)Os::loadLibrary("libX11.so.6"); + if (NULL != hXModule) { + XOpenDisplay_ = (PFNXOpenDisplay)GETPROCADDRESS(hXModule, "XOpenDisplay"); + VERIFY_POINTER(XOpenDisplay_) + XCloseDisplay_ = (PFNXCloseDisplay)GETPROCADDRESS(hXModule, "XCloseDisplay"); + VERIFY_POINTER(XCloseDisplay_) + } else { + missed_ += 2; + } + } +// Initialize pointers to GL functions +#include "gl_functions.hpp" +#else + if (!isEGL_) { + wglCreateContext_ = (PFN_wglCreateContext)GETPROCADDRESS(h, "wglCreateContext"); + VERIFY_POINTER(wglCreateContext_) + wglGetCurrentContext_ = (PFN_wglGetCurrentContext)GETPROCADDRESS(h, "wglGetCurrentContext"); + VERIFY_POINTER(wglGetCurrentContext_) + wglGetCurrentDC_ = (PFN_wglGetCurrentDC)GETPROCADDRESS(h, "wglGetCurrentDC"); + VERIFY_POINTER(wglGetCurrentDC_) + wglDeleteContext_ = (PFN_wglDeleteContext)GETPROCADDRESS(h, "wglDeleteContext"); + VERIFY_POINTER(wglDeleteContext_) + wglMakeCurrent_ = (PFN_wglMakeCurrent)GETPROCADDRESS(h, "wglMakeCurrent"); + VERIFY_POINTER(wglMakeCurrent_) + wglShareLists_ = (PFN_wglShareLists)GETPROCADDRESS(h, "wglShareLists"); + VERIFY_POINTER(wglShareLists_) + } +#endif +} + +GLFunctions::~GLFunctions() { +#ifdef _WIN32 + if (hIntGLRC_) { + if (!wglDeleteContext_(hIntGLRC_)) { + DWORD dwErr = GetLastError(); + LogWarning("Cannot delete GLRC"); + } + } +#else //!_WIN32 + if (intDpy_) { + if (intCtx_) { + glXDestroyContext_(intDpy_, intCtx_); + intCtx_ = NULL; + } + XCloseDisplay_(intDpy_); + intDpy_ = NULL; + } +#endif //!_WIN32 +} + +void GLFunctions::WaitCurrentGlContext(const amd::Context::Info& info) const { + if (IsCurrentGlContext(info)) { + glFinish_(); + } +} + +bool GLFunctions::init(intptr_t hdc, intptr_t hglrc) { + if (isEGL_) { + eglDisplay_ = (EGLDisplay)hdc; + eglOriginalContext_ = (EGLContext)hglrc; + return true; + } + +#ifdef _WIN32 + DWORD err; + + if (missed_) { + return false; + } + + if (!hdc) { + hDC_ = wglGetCurrentDC_(); + } else { + hDC_ = (HDC)hdc; + } + hOrigGLRC_ = (HGLRC)hglrc; + if (!(hIntGLRC_ = wglCreateContext_(hDC_))) { + err = GetLastError(); + return false; + } + if (!wglShareLists_(hOrigGLRC_, hIntGLRC_)) { + err = GetLastError(); + return false; + } + + bool makeCurrentNull = false; + + if (wglGetCurrentContext_() == NULL) { + wglMakeCurrent_(hDC_, hIntGLRC_); + + makeCurrentNull = true; + } + +// Initialize pointers to GL functions +#include "gl_functions.hpp" + + if (makeCurrentNull) { + wglMakeCurrent_(NULL, NULL); + } + + if (missed_ == 0) { + return true; + } +#else //!_WIN32 + if (!missed_) { + if (!hdc) { + Dpy_ = glXGetCurrentDisplay_(); + } else { + Dpy_ = (Display*)hdc; + } + Drawable_ = glXGetCurrentDrawable_(); + origCtx_ = (GLXContext)hglrc; + + int attribList[] = {GLX_RGBA, None}; + if (!(intDpy_ = XOpenDisplay_(DisplayString(Dpy_)))) { +#if defined(ATI_ARCH_X86) + asm("int $3"); +#endif + } + intDrawable_ = DefaultRootWindow(intDpy_); + + XVisualInfo* vis; + int defaultScreen = DefaultScreen(intDpy_); + if (!(vis = glXChooseVisual_(intDpy_, defaultScreen, attribList))) { + return false; + } + if (!(intCtx_ = glXCreateContext_(intDpy_, vis, origCtx_, true))) { + return false; + } + return true; + } +#endif //!_WIN32 + return false; +} + +bool GLFunctions::setIntEnv() { + if (isEGL_) { + return true; + } +#ifdef _WIN32 + // Save current DC and GLRC + tempDC_ = wglGetCurrentDC_(); + tempGLRC_ = wglGetCurrentContext_(); + // Set internal DC and GLRC + if (tempDC_ != getDC() || tempGLRC_ != getIntGLRC()) { + if (!wglMakeCurrent_(getDC(), getIntGLRC())) { + DWORD err = GetLastError(); + LogWarning("cannot set internal GL environment"); + return false; + } + } +#else //!_WIN32 + tempDpy_ = glXGetCurrentDisplay_(); + tempDrawable_ = glXGetCurrentDrawable_(); + tempCtx_ = glXGetCurrentContext_(); + // Set internal Display and GLXContext + if (tempDpy_ != getDpy() || tempCtx_ != getIntCtx()) { + if (!glXMakeCurrent_(getIntDpy(), getIntDrawable(), getIntCtx())) { + LogWarning("cannot set internal GL environment"); + return false; + } + } +#endif //!_WIN32 + + return true; +} + +bool GLFunctions::restoreEnv() { + if (isEGL_) { + // eglMakeCurrent( ); + return true; + } +#ifdef _WIN32 + // Restore original DC and GLRC + if (!wglMakeCurrent_(tempDC_, tempGLRC_)) { + DWORD err = GetLastError(); + LogWarning("cannot restore original GL environment"); + return false; + } +#else //!_WIN32 + // Restore Display and GLXContext + if (tempDpy_) { + if (!glXMakeCurrent_(tempDpy_, tempDrawable_, tempCtx_)) { + LogWarning("cannot restore original GL environment"); + return false; + } + } else { + // Just release internal context + if (!glXMakeCurrent_(getIntDpy(), None, NULL)) { + LogWarning("cannot reelase internal GL environment"); + return false; + } + } +#endif //!_WIN32 + + return true; +} + +} // namespace amd diff --git a/opencl/amdocl/cl_gl_amd.hpp b/opencl/amdocl/cl_gl_amd.hpp new file mode 100644 index 0000000000..86ffbccd78 --- /dev/null +++ b/opencl/amdocl/cl_gl_amd.hpp @@ -0,0 +1,397 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef CL_GL_AMD_HPP_ +#define CL_GL_AMD_HPP_ + +#ifdef _WIN32 +#include +#else //!_WIN32 +#include +#endif //!_WIN32 + +#include +#include +#include "CL/cl_gl.h" +#ifndef _WIN32 +#include +#endif //!_WIN32 + +#include +#include +#include + +#include "platform/context.hpp" +#include "platform/command.hpp" + +namespace amd +{ + +//! Class GLObject keeps all the info about the GL object +//! from which the CL object is created +class GLObject : public InteropObject +{ +protected: + cl_gl_object_type clGLType_; //!< CL GL object type + GLenum glTarget_; + GLuint gluiName_; + GLint gliMipLevel_; + GLenum glInternalFormat_; + GLint gliWidth_; + GLint gliHeight_; + GLint gliDepth_; + GLenum glCubemapFace_; + GLsizei glNumSamples_; + +public: +//! GLObject constructor initializes member variables + GLObject( + GLenum glTarget, + GLuint gluiName, + GLint gliMipLevel, + GLenum glInternalFormat, + GLint gliWidth, + GLint gliHeight, + GLint gliDepth, + cl_gl_object_type clGLType, + GLenum glCubemapFace, + GLsizei glNumSamples + ): // Initialization of member variables + clGLType_(clGLType), + glTarget_(glTarget), + gluiName_(gluiName), + gliMipLevel_(gliMipLevel), + glInternalFormat_(glInternalFormat), + gliWidth_(gliWidth), + gliHeight_(gliHeight), + gliDepth_(gliDepth), + glCubemapFace_(glCubemapFace), + glNumSamples_(glNumSamples) + { + } + + virtual ~GLObject() {} + virtual GLObject* asGLObject() {return this;} + +//! GLObject query functions to get GL info from member variables + GLenum getGLTarget() const {return glTarget_;} + GLuint getGLName() const {return gluiName_;} + GLint getGLMipLevel() const {return gliMipLevel_;} + GLenum getGLInternalFormat() const {return glInternalFormat_;} + GLint getGLSize() const {return gliWidth_;} + GLint getGLWidth() const {return gliWidth_;} + GLint getGLHeight() const {return gliHeight_;} + GLint getGLDepth() const {return gliDepth_;} + cl_gl_object_type getCLGLObjectType() const { return clGLType_; } + GLenum getCubemapFace() const {return glCubemapFace_;} + GLsizei getNumSamples() const { return glNumSamples_;} +}; + + +//! Class BufferGL is drived from classes Buffer and GLObject +//! where the former keeps all data for CL object and +//! the latter keeps all data for GL object +class BufferGL : public Buffer, public GLObject +{ +protected: + //! Initializes the device memory array which is nested + // after'BufferGL' object in memory layout. + virtual void initDeviceMemory(); +public: +//! BufferGL constructor just calls constructors of base classes +//! to pass down the parameters + BufferGL( + Context& amdContext, + cl_mem_flags clFlags, + size_t uiSizeInBytes, + GLenum glTarget, + GLuint gluiName) + : // Call base classes constructors + Buffer( + amdContext, + clFlags, + uiSizeInBytes + ), + GLObject( + glTarget, + gluiName, + 0, // Mipmap level default + GL_ARRAY_BUFFER, // Just init to some value + (GLint) uiSizeInBytes, + 1, + 1, + CL_GL_OBJECT_BUFFER, + 0, + 0 + ) + { + setInteropObj(this); + } + virtual ~BufferGL() {} + + virtual BufferGL* asBufferGL() { return this; } +}; + + +//! Class ImageGL is derived from classes Image and GLObject +//! where the former keeps all data for CL object and +//! the latter keeps all data for GL object +class ImageGL : public Image, public GLObject +{ +public: + //! ImageGL constructor just calls constructors of base classes + //! to pass down the parameters + ImageGL( + Context& amdContext, + cl_mem_object_type clType, + cl_mem_flags clFlags, + const Format& format, + size_t width, + size_t height, + size_t depth, + GLenum glTarget, + GLuint gluiName, + GLint gliMipLevel, + GLenum glInternalFormat, + cl_gl_object_type clGLType, + GLsizei numSamples, + GLenum glCubemapFace = 0) + : Image(amdContext, clType, clFlags, format, width, height, depth, + Format(format).getElementSize() * width, + Format(format).getElementSize() * width * depth) + , GLObject(glTarget, gluiName, gliMipLevel, glInternalFormat, + static_cast(width), static_cast(height), + static_cast(depth), clGLType, glCubemapFace,numSamples) + { + setInteropObj(this); + } + + virtual ~ImageGL() {} + +protected: + //! Initializes the device memory array which is nested + // after'BufferGL' object in memory layout. + virtual void initDeviceMemory(); +}; + + typedef EGLContext (*PFN_eglGetCurrentContext) (); +#ifdef _WIN32 +#define APICALL WINAPI +#define GETPROCADDRESS GetProcAddress +#define API_GETPROCADDR "wglGetProcAddress" +#define FCN_STR_TYPE LPCSTR + typedef PROC (WINAPI* PFN_xxxGetProcAddress) (LPCSTR fcnName); + typedef HGLRC (APICALL* PFN_wglCreateContext) (HDC hdc); + typedef HGLRC (APICALL* PFN_wglGetCurrentContext) (void); + typedef HDC (APICALL* PFN_wglGetCurrentDC) (void); + typedef BOOL (APICALL* PFN_wglDeleteContext) (HGLRC hglrc); + typedef BOOL (APICALL* PFN_wglMakeCurrent) (HDC hdc, HGLRC hglrc); + typedef BOOL (APICALL* PFN_wglShareLists) (HGLRC hglrc1, HGLRC hglrc2); +#else //!_WIN32 +#define APICALL // __stdcall //??? todo odintsov +#define API_GETPROCADDR "glXGetProcAddress" +#define GETPROCADDRESS dlsym +#define FCN_STR_TYPE const GLubyte* +#define WINAPI +#define PROC void* + typedef void* (*PFN_xxxGetProcAddress) (const GLubyte* procName); + // X11 typedef + typedef Display* (*PFNXOpenDisplay)(_Xconst char* display_name ); + typedef int (*PFNXCloseDisplay)(Display* display ); + + //glx typedefs + typedef GLXDrawable (*PFNglXGetCurrentDrawable)(); + typedef Display* (*PFNglXGetCurrentDisplay)(); + typedef GLXContext (*PFNglXGetCurrentContext)( void ); + typedef XVisualInfo* (*PFNglXChooseVisual)(Display *dpy, int screen, int *attribList); + typedef GLXContext(*PFNglXCreateContext)(Display* dpy,XVisualInfo* vis,GLXContext shareList,Bool direct); + typedef void(*PFNglXDestroyContext)(Display* dpy, GLXContext ctx); + typedef Bool(*PFNglXMakeCurrent)( Display* dpy, GLXDrawable drawable, GLXContext ctx); + typedef void* HMODULE; +#endif //!_WIN32 + +#define GLPREFIX(rtype, fcn, dclargs) \ + typedef rtype (APICALL* PFN_##fcn) dclargs; + +// Declare prototypes for GL functions +#include "gl_functions.hpp" + +class GLFunctions +{ +public: + //! Locks any access to the virtual GPUs + class SetIntEnv : public amd::StackObject { + public: + //! Default constructor + SetIntEnv(GLFunctions* env); + + //! Destructor + ~SetIntEnv(); + + //! Checks if the environment setup was successful + bool isValid() const { return isValid_; } + + private: + GLFunctions* env_; //!< GL environment + bool isValid_; //!< If TRUE, then it's a valid setup + }; + +private: + HMODULE libHandle_; + int missed_; // Indicates how many GL functions not init'ed, if any + + amd::Monitor lock_; + + EGLDisplay eglDisplay_; + EGLContext eglOriginalContext_; + EGLContext eglInternalContext_; + EGLContext eglTempContext_; + bool isEGL_; + PFN_eglGetCurrentContext eglGetCurrentContext_; + +#ifdef _WIN32 + HGLRC hOrigGLRC_; + HDC hDC_; + HGLRC hIntGLRC_; // handle for internal GLRC to access shared context + HDC tempDC_; + HGLRC tempGLRC_; + +public: + PFN_wglCreateContext wglCreateContext_; + PFN_wglGetCurrentContext wglGetCurrentContext_; + PFN_wglGetCurrentDC wglGetCurrentDC_; + PFN_wglDeleteContext wglDeleteContext_; + PFN_wglMakeCurrent wglMakeCurrent_; + PFN_wglShareLists wglShareLists_; +#else +public: + Display* Dpy_; + GLXDrawable Drawable_; + GLXContext origCtx_; + Display* intDpy_; + Window intDrawable_; + GLXContext intCtx_; + Display* tempDpy_; + GLXDrawable tempDrawable_; + GLXContext tempCtx_; + + //pointers to X11 functions + PFNXOpenDisplay XOpenDisplay_; + PFNXCloseDisplay XCloseDisplay_; + + //pointers to GLX functions + PFNglXGetCurrentDrawable glXGetCurrentDrawable_; + PFNglXGetCurrentDisplay glXGetCurrentDisplay_; + PFNglXGetCurrentContext glXGetCurrentContext_; + PFNglXChooseVisual glXChooseVisual_; + PFNglXCreateContext glXCreateContext_; + PFNglXDestroyContext glXDestroyContext_; + PFNglXMakeCurrent glXMakeCurrent_; +#endif +public: + + GLFunctions(HMODULE h, bool isEGL); + ~GLFunctions(); + + bool IsCurrentGlContext(const amd::Context::Info& info) const { + if (isEGL_) { + return ((info.hCtx_ != nullptr) && (eglGetCurrentContext_ != nullptr) && + (info.hCtx_ == eglGetCurrentContext_())); + } else { +#ifdef _WIN32 + return ((info.hCtx_ != nullptr) && (info.hCtx_ == wglGetCurrentContext_())); +#else + return ((info.hCtx_ != nullptr) && (info.hCtx_ == glXGetCurrentContext_())); +#endif // _WIN32 + } + } + + void WaitCurrentGlContext(const amd::Context::Info& info) const; + + // Query CL-GL context association + bool isAssociated() const + { + if (isEGL_ && eglDisplay_ && eglOriginalContext_) return true; +#ifdef _WIN32 + if(hDC_ && hOrigGLRC_) return true; +#else //!_WIN32 + if(Dpy_ && origCtx_) return true; +#endif //!_WIN32 + return false; + } + bool isEGL() const + { + return isEGL_; + } + // Accessor methods +#ifdef _WIN32 + HGLRC getOrigGLRC() const {return hOrigGLRC_;} + HDC getDC() const {return hDC_;} + HGLRC getIntGLRC() const {return hIntGLRC_;} +#else //!_WIN32 + Display* getDpy() const {return Dpy_;} + GLXDrawable getDrawable() const {return Drawable_;} + GLXContext getOrigCtx() const {return origCtx_;} + + Display* getIntDpy() const {return intDpy_;} + GLXDrawable getIntDrawable() const {return intDrawable_;} + GLXContext getIntCtx() const {return intCtx_;} + + EGLDisplay getEglDpy() const { return eglDisplay_; } + EGLContext getEglOrigCtx() const { return eglOriginalContext_; } +#endif //!_WIN32 + + // Initialize GL dynamic library and function pointers + bool init(intptr_t hdc, intptr_t hglrc); + + // Return true if successful, false - if error occurred + bool setIntEnv(); + bool restoreEnv(); + + amd::Monitor& getLock() { return lock_; } + + PFN_xxxGetProcAddress GetProcAddress_; + +#define GLPREFIX(rtype, fcn, dclargs) \ + PFN_##fcn fcn##_; +// Declare pointers to GL functions +#include "gl_functions.hpp" +}; + +//! Functions for executing the GL related stuff +cl_mem clCreateFromGLBufferAMD(Context& amdContext, cl_mem_flags flags, + GLuint bufobj, cl_int* errcode_ret); +cl_mem clCreateFromGLTextureAMD(Context& amdContext, cl_mem_flags flags, + GLenum target, GLint miplevel, GLuint texture, int* errcode_ret); +cl_mem clCreateFromGLRenderbufferAMD(Context& amdContext, cl_mem_flags flags, + GLuint renderbuffer, int* errcode_ret); + +bool +getCLFormatFromGL( + const Context& amdContext, + GLint gliInternalFormat, + cl_image_format* pclImageFormat, + int* piBytesPerPixel, + cl_mem_flags flags +); + +} //namespace amd + +#endif //CL_GL_AMD_HPP_ diff --git a/opencl/amdocl/cl_icd.cpp b/opencl/amdocl/cl_icd.cpp new file mode 100644 index 0000000000..4fce08b06c --- /dev/null +++ b/opencl/amdocl/cl_icd.cpp @@ -0,0 +1,295 @@ +/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include "vdi_common.hpp" +#ifdef _WIN32 +#include +#include "cl_d3d9_amd.hpp" +#include "cl_d3d10_amd.hpp" +#include "cl_d3d11_amd.hpp" +#endif //_WIN32 + +#include + +amd::PlatformIDS amd::PlatformID::Platform = //{ NULL }; + {amd::ICDDispatchedObject::icdVendorDispatch_}; + +static cl_int CL_API_CALL icdGetPlatformInfo(cl_platform_id platform, cl_platform_info param_name, + size_t param_value_size, void* param_value, + size_t* param_value_size_ret) { + if (platform != reinterpret_cast(&amd::PlatformID::Platform)) { + return CL_INVALID_PLATFORM; + } + + return clGetPlatformInfo(NULL, param_name, param_value_size, param_value, param_value_size_ret); +} + +static cl_int CL_API_CALL icdGetDeviceIDs(cl_platform_id platform, cl_device_type device_type, + cl_uint num_entries, cl_device_id* devices, + cl_uint* num_devices) { + return clGetDeviceIDs(NULL, device_type, num_entries, devices, num_devices); +} + +static cl_int CL_API_CALL icdGetDeviceInfo(cl_device_id device, cl_device_info param_name, + size_t param_value_size, void* param_value, + size_t* param_value_size_ret) { + if (param_name == CL_DEVICE_PLATFORM) { + // Return the ICD platform instead of the default NULL platform. + cl_platform_id platform = reinterpret_cast(&amd::PlatformID::Platform); + return amd::clGetInfo(platform, param_value_size, param_value, param_value_size_ret); + } + + return clGetDeviceInfo(device, param_name, param_value_size, param_value, param_value_size_ret); +} + +cl_icd_dispatch amd::ICDDispatchedObject::icdVendorDispatch_[] = { + {NULL /* should not get called */, icdGetPlatformInfo, icdGetDeviceIDs, icdGetDeviceInfo, + clCreateContext, clCreateContextFromType, clRetainContext, clReleaseContext, clGetContextInfo, + clCreateCommandQueue, clRetainCommandQueue, clReleaseCommandQueue, clGetCommandQueueInfo, + clSetCommandQueueProperty, clCreateBuffer, clCreateImage2D, clCreateImage3D, clRetainMemObject, + clReleaseMemObject, clGetSupportedImageFormats, clGetMemObjectInfo, clGetImageInfo, + clCreateSampler, clRetainSampler, clReleaseSampler, clGetSamplerInfo, + clCreateProgramWithSource, clCreateProgramWithBinary, clRetainProgram, clReleaseProgram, + clBuildProgram, clUnloadCompiler, clGetProgramInfo, clGetProgramBuildInfo, clCreateKernel, + clCreateKernelsInProgram, clRetainKernel, clReleaseKernel, clSetKernelArg, clGetKernelInfo, + clGetKernelWorkGroupInfo, clWaitForEvents, clGetEventInfo, clRetainEvent, clReleaseEvent, + clGetEventProfilingInfo, clFlush, clFinish, clEnqueueReadBuffer, clEnqueueWriteBuffer, + clEnqueueCopyBuffer, clEnqueueReadImage, clEnqueueWriteImage, clEnqueueCopyImage, + clEnqueueCopyImageToBuffer, clEnqueueCopyBufferToImage, clEnqueueMapBuffer, clEnqueueMapImage, + clEnqueueUnmapMemObject, clEnqueueNDRangeKernel, clEnqueueTask, clEnqueueNativeKernel, + clEnqueueMarker, clEnqueueWaitForEvents, clEnqueueBarrier, clGetExtensionFunctionAddress, + clCreateFromGLBuffer, clCreateFromGLTexture2D, clCreateFromGLTexture3D, + clCreateFromGLRenderbuffer, clGetGLObjectInfo, clGetGLTextureInfo, clEnqueueAcquireGLObjects, + clEnqueueReleaseGLObjects, clGetGLContextInfoKHR, + WINDOWS_SWITCH(clGetDeviceIDsFromD3D10KHR, NULL), + WINDOWS_SWITCH(clCreateFromD3D10BufferKHR, NULL), + WINDOWS_SWITCH(clCreateFromD3D10Texture2DKHR, NULL), + WINDOWS_SWITCH(clCreateFromD3D10Texture3DKHR, NULL), + WINDOWS_SWITCH(clEnqueueAcquireD3D10ObjectsKHR, NULL), + WINDOWS_SWITCH(clEnqueueReleaseD3D10ObjectsKHR, NULL), clSetEventCallback, clCreateSubBuffer, + clSetMemObjectDestructorCallback, clCreateUserEvent, clSetUserEventStatus, + clEnqueueReadBufferRect, clEnqueueWriteBufferRect, clEnqueueCopyBufferRect, + NULL, NULL, NULL, clCreateEventFromGLsyncKHR, + + /* OpenCL 1.2*/ + clCreateSubDevices, clRetainDevice, clReleaseDevice, clCreateImage, + clCreateProgramWithBuiltInKernels, clCompileProgram, clLinkProgram, clUnloadPlatformCompiler, + clGetKernelArgInfo, clEnqueueFillBuffer, clEnqueueFillImage, clEnqueueMigrateMemObjects, + clEnqueueMarkerWithWaitList, clEnqueueBarrierWithWaitList, + clGetExtensionFunctionAddressForPlatform, clCreateFromGLTexture, + + WINDOWS_SWITCH(clGetDeviceIDsFromD3D11KHR, NULL), + WINDOWS_SWITCH(clCreateFromD3D11BufferKHR, NULL), + WINDOWS_SWITCH(clCreateFromD3D11Texture2DKHR, NULL), + WINDOWS_SWITCH(clCreateFromD3D11Texture3DKHR, NULL), + WINDOWS_SWITCH(clCreateFromDX9MediaSurfaceKHR, NULL), + WINDOWS_SWITCH(clEnqueueAcquireD3D11ObjectsKHR, NULL), + WINDOWS_SWITCH(clEnqueueReleaseD3D11ObjectsKHR, NULL), + + WINDOWS_SWITCH(clGetDeviceIDsFromDX9MediaAdapterKHR, + NULL), // KHRpfn_clGetDeviceIDsFromDX9MediaAdapterKHR + // clGetDeviceIDsFromDX9MediaAdapterKHR; + WINDOWS_SWITCH( + clEnqueueAcquireDX9MediaSurfacesKHR, + NULL), // KHRpfn_clEnqueueAcquireDX9MediaSurfacesKHR clEnqueueAcquireDX9MediaSurfacesKHR; + WINDOWS_SWITCH( + clEnqueueReleaseDX9MediaSurfacesKHR, + NULL), // KHRpfn_clEnqueueReleaseDX9MediaSurfacesKHR clEnqueueReleaseDX9MediaSurfacesKHR; + + NULL, + NULL, NULL, NULL, + + clCreateCommandQueueWithProperties, clCreatePipe, clGetPipeInfo, clSVMAlloc, clSVMFree, + clEnqueueSVMFree, clEnqueueSVMMemcpy, clEnqueueSVMMemFill, clEnqueueSVMMap, clEnqueueSVMUnmap, + clCreateSamplerWithProperties, clSetKernelArgSVMPointer, clSetKernelExecInfo, + clGetKernelSubGroupInfo, + clCloneKernel, + clCreateProgramWithIL, + clEnqueueSVMMigrateMem, + clGetDeviceAndHostTimer, + clGetHostTimer, + clGetKernelSubGroupInfo, + clSetDefaultDeviceCommandQueue, + + clSetProgramReleaseCallback, + clSetProgramSpecializationConstant }}; + +#if defined(_WIN32) +#include + +#pragma comment(lib, "shlwapi.lib") + +static bool ShouldLoadPlatform() { + // Get the OpenCL ICD registry values + HKEY platformsKey = NULL; + if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Khronos\\OpenCL\\Vendors", 0, KEY_READ, + &platformsKey) != ERROR_SUCCESS) + return true; + + std::vector registryValues; + DWORD dwIndex = 0; + while (true) { + char cszLibraryName[1024] = {0}; + DWORD dwLibraryNameSize = sizeof(cszLibraryName); + DWORD dwLibraryNameType = 0; + DWORD dwValue = 0; + DWORD dwValueSize = sizeof(dwValue); + + if (RegEnumValueA(platformsKey, dwIndex++, cszLibraryName, &dwLibraryNameSize, NULL, + &dwLibraryNameType, (LPBYTE)&dwValue, &dwValueSize) != ERROR_SUCCESS) + break; + // Require that the value be a DWORD and equal zero + if (dwLibraryNameType != REG_DWORD || dwValue != 0) { + continue; + } + registryValues.push_back(cszLibraryName); + } + RegCloseKey(platformsKey); + + HMODULE hm = NULL; + if (!GetModuleHandleExA( + GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (LPCSTR)&ShouldLoadPlatform, &hm)) + return true; + + char cszDllPath[1024] = {0}; + if (!GetModuleFileNameA(hm, cszDllPath, sizeof(cszDllPath))) return true; + + // If we are loaded from the DriverStore, then there should be a registry + // value matching our current module absolute path. + if (std::find(registryValues.begin(), registryValues.end(), cszDllPath) == registryValues.end()) + return true; + + LPSTR cszFileName; + char buffer[1024] = {0}; + if (!GetFullPathNameA(cszDllPath, sizeof(buffer), buffer, &cszFileName)) return true; + + // We found an absolute path in the registry that matched this DLL, now + // check if there is also an entry with the same filename. + if (std::find(registryValues.begin(), registryValues.end(), cszFileName) == registryValues.end()) + return true; + + // Lastly, check if there is a DLL with the same name in the System folder. + char cszSystemPath[1024] = {0}; +#if defined(ATI_BITS_32) + if (!GetSystemWow64DirectoryA(cszSystemPath, sizeof(cszSystemPath))) +#endif // defined(ATI_BITS_32) + if (!GetSystemDirectoryA(cszSystemPath, sizeof(cszSystemPath))) return true; + + std::string systemDllPath; + systemDllPath.append(cszSystemPath).append("\\").append(cszFileName); + if (!PathFileExistsA(systemDllPath.c_str())) { + return true; + } + + // If we get here, then all 3 conditions are true: + // - An entry in the registry with an absolute path matches the current DLL + // - An entry in the registry with a relative path matches the current DLL + // - A DLL with the same name was found in the system directory + // + // We should not load this platform! + + return false; +} + +#else + +#include + +// If there is only one platform, load it. +// If there is more than one platform, only load platforms that have visible devices +// If all platforms have no devices available, only load the PAL platform +static bool ShouldLoadPlatform() { + bool shouldLoad = true; + + if (!amd::Runtime::initialized()) { + amd::Runtime::init(); + } + const int numDevices = amd::Device::numDevices(CL_DEVICE_TYPE_GPU, false); + + void *otherPlatform = nullptr; + if (amd::IS_LEGACY) { + otherPlatform = dlopen("libamdocl64.so", RTLD_LAZY); + if (otherPlatform != nullptr) { // Present platform exists + shouldLoad = numDevices > 0; + } + } else { + otherPlatform = dlopen("libamdocl-orca64.so", RTLD_LAZY); + if (otherPlatform != nullptr) { // Legacy platform exists + // gcc4.8 doesn't support casting void* to a function pointer + // Work around this by creating a typedef untill we upgrade the compiler + typedef void*(*clGetFunctionAddress_t)(const char *); + typedef cl_int(*clIcdGetPlatformIDs_t)(cl_uint, cl_platform_id *, cl_uint *); + + clGetFunctionAddress_t legacyGetFunctionAddress = + reinterpret_cast(dlsym(otherPlatform, "clGetExtensionFunctionAddress")); + clIcdGetPlatformIDs_t legacyGetPlatformIDs = + reinterpret_cast(legacyGetFunctionAddress("clIcdGetPlatformIDsKHR")); + + cl_uint numLegacyPlatforms = 0; + legacyGetPlatformIDs(0, nullptr, &numLegacyPlatforms); + + shouldLoad = (numDevices > 0) || (numLegacyPlatforms == 0); + } + } + + if (otherPlatform != nullptr) { + dlclose(otherPlatform); + } + + return shouldLoad; +} + +#endif // defined(_WIN32) + +CL_API_ENTRY cl_int CL_API_CALL clIcdGetPlatformIDsKHR(cl_uint num_entries, + cl_platform_id* platforms, + cl_uint* num_platforms) { + if (((num_entries > 0 || num_platforms == NULL) && platforms == NULL) || + (num_entries == 0 && platforms != NULL)) { + return CL_INVALID_VALUE; + } + + static bool shouldLoad = true; + + static std::once_flag initOnce; + std::call_once(initOnce, [](){ shouldLoad = ShouldLoadPlatform(); }); + + if (!shouldLoad) { + *not_null(num_platforms) = 0; + return CL_SUCCESS; + } + + if (!amd::Runtime::initialized()) { + amd::Runtime::init(); + } + + if (num_platforms != NULL && platforms == NULL) { + *num_platforms = 1; + return CL_SUCCESS; + } + + assert(platforms != NULL && "check the code above"); + *platforms = reinterpret_cast(&amd::PlatformID::Platform); + + *not_null(num_platforms) = 1; + return CL_SUCCESS; +} diff --git a/opencl/amdocl/cl_icd_amd.h b/opencl/amdocl/cl_icd_amd.h new file mode 100644 index 0000000000..69408e75ac --- /dev/null +++ b/opencl/amdocl/cl_icd_amd.h @@ -0,0 +1,739 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +#ifndef __OPENCL_CL_ICD_H +#define __OPENCL_CL_ICD_H + +#include +#include + +#define cl_khr_icd 1 + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef cl_int(CL_API_CALL* clGetPlatformIDs_fn)( + cl_uint /* num_entries */, cl_platform_id* /* platforms */, + cl_uint* /* num_platforms */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetPlatformInfo_fn)( + cl_platform_id /* platform */, cl_platform_info /* param_name */, size_t /* param_value_size */, + void* /* param_value */, size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetDeviceIDs_fn)( + cl_platform_id /* platform */, cl_device_type /* device_type */, cl_uint /* num_entries */, + cl_device_id* /* devices */, cl_uint* /* num_devices */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetDeviceInfo_fn)( + cl_device_id /* device */, cl_device_info /* param_name */, size_t /* param_value_size */, + void* /* param_value */, size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_context(CL_API_CALL* clCreateContext_fn)( + 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 */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_context(CL_API_CALL* clCreateContextFromType_fn)( + 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 */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clRetainContext_fn)(cl_context /* context */) + CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clReleaseContext_fn)(cl_context /* context */) + CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetContextInfo_fn)( + cl_context /* context */, cl_context_info /* param_name */, size_t /* param_value_size */, + void* /* param_value */, size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_command_queue(CL_API_CALL* clCreateCommandQueue_fn)( + cl_context /* context */, cl_device_id /* device */, + cl_command_queue_properties /* properties */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clRetainCommandQueue_fn)(cl_command_queue /* command_queue */) + CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clReleaseCommandQueue_fn)(cl_command_queue /* command_queue */) + CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetCommandQueueInfo_fn)( + cl_command_queue /* command_queue */, cl_command_queue_info /* param_name */, + size_t /* param_value_size */, void* /* param_value */, + size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clSetCommandQueueProperty_fn)( + cl_command_queue /* command_queue */, cl_command_queue_properties /* properties */, + cl_bool /* enable */, + cl_command_queue_properties* /* old_properties */) /*CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED*/; + +typedef cl_mem(CL_API_CALL* clCreateBuffer_fn)( + cl_context /* context */, cl_mem_flags /* flags */, size_t /* size */, void* /* host_ptr */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_mem(CL_API_CALL* clCreateSubBuffer_fn)( + cl_mem /* buffer */, cl_mem_flags /* flags */, cl_buffer_create_type /* buffer_create_type */, + const void* /* buffer_create_info */, cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; + +typedef cl_mem(CL_API_CALL* clCreateImage2D_fn)( + cl_context /* context */, cl_mem_flags /* flags */, const cl_image_format* /* image_format */, + size_t /* image_width */, size_t /* image_height */, size_t /* image_row_pitch */, + void* /* host_ptr */, cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_mem(CL_API_CALL* clCreateImage3D_fn)( + cl_context /* context */, cl_mem_flags /* flags */, const cl_image_format* /* image_format */, + size_t /* image_width */, size_t /* image_height */, size_t /* image_depth */, + size_t /* image_row_pitch */, size_t /* image_slice_pitch */, void* /* host_ptr */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clRetainMemObject_fn)(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clReleaseMemObject_fn)(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetSupportedImageFormats_fn)( + 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 */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetMemObjectInfo_fn)( + cl_mem /* memobj */, cl_mem_info /* param_name */, size_t /* param_value_size */, + void* /* param_value */, size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetImageInfo_fn)( + cl_mem /* image */, cl_image_info /* param_name */, size_t /* param_value_size */, + void* /* param_value */, size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clSetMemObjectDestructorCallback_fn)( + cl_mem /* memobj */, + void(CL_CALLBACK* /*pfn_notify*/)(cl_mem /* memobj */, void* /*user_data*/), + void* /*user_data */) CL_API_SUFFIX__VERSION_1_1; + +/* Sampler APIs */ +typedef cl_sampler(CL_API_CALL* clCreateSampler_fn)( + cl_context /* context */, cl_bool /* normalized_coords */, + cl_addressing_mode /* addressing_mode */, cl_filter_mode /* filter_mode */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clRetainSampler_fn)(cl_sampler /* sampler */) + CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clReleaseSampler_fn)(cl_sampler /* sampler */) + CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetSamplerInfo_fn)( + cl_sampler /* sampler */, cl_sampler_info /* param_name */, size_t /* param_value_size */, + void* /* param_value */, size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Program Object APIs */ +typedef cl_program(CL_API_CALL* clCreateProgramWithSource_fn)( + cl_context /* context */, cl_uint /* count */, const char** /* strings */, + const size_t* /* lengths */, cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithIL(cl_context /* context */, + const void * /* strings */, size_t /* lengths */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_2_0; + +typedef cl_program(CL_API_CALL* clCreateProgramWithILKHR_fn)( + cl_context /* context */, const void* /* il */, size_t /* length */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; + +typedef cl_program(CL_API_CALL* clCreateProgramWithBinary_fn)( + 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 */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clRetainProgram_fn)(cl_program /* program */) + CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clReleaseProgram_fn)(cl_program /* program */) + CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clBuildProgram_fn)( + 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 */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clUnloadCompiler_fn)(void) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetProgramInfo_fn)( + cl_program /* program */, cl_program_info /* param_name */, size_t /* param_value_size */, + void* /* param_value */, size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetProgramBuildInfo_fn)( + 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 */) CL_API_SUFFIX__VERSION_1_0; + +/* Kernel Object APIs */ +typedef cl_kernel(CL_API_CALL* clCreateKernel_fn)( + cl_program /* program */, const char* /* kernel_name */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clCreateKernelsInProgram_fn)( + cl_program /* program */, cl_uint /* num_kernels */, cl_kernel* /* kernels */, + cl_uint* /* num_kernels_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clRetainKernel_fn)(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clReleaseKernel_fn)(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clSetKernelArg_fn)(cl_kernel /* kernel */, cl_uint /* arg_index */, + size_t /* arg_size */, const void* /* arg_value */) + CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetKernelInfo_fn)( + cl_kernel /* kernel */, cl_kernel_info /* param_name */, size_t /* param_value_size */, + void* /* param_value */, size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetKernelWorkGroupInfo_fn)( + 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 */) CL_API_SUFFIX__VERSION_1_0; + +/* Event Object APIs */ +typedef cl_int(CL_API_CALL* clWaitForEvents_fn)( + cl_uint /* num_events */, const cl_event* /* event_list */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetEventInfo_fn)( + cl_event /* event */, cl_event_info /* param_name */, size_t /* param_value_size */, + void* /* param_value */, size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_event(CL_API_CALL* clCreateUserEvent_fn)( + cl_context /* context */, cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; + +typedef cl_int(CL_API_CALL* clRetainEvent_fn)(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clReleaseEvent_fn)(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clSetUserEventStatus_fn)( + cl_event /* event */, cl_int /* execution_status */) CL_API_SUFFIX__VERSION_1_1; + +typedef cl_int(CL_API_CALL* clSetEventCallback_fn)( + cl_event /* event */, cl_int /* command_exec_callback_type */, + void(CL_CALLBACK* /* pfn_notify */)(cl_event, cl_int, void*), + void* /* user_data */) CL_API_SUFFIX__VERSION_1_1; + +/* Profiling APIs */ +typedef cl_int(CL_API_CALL* clGetEventProfilingInfo_fn)( + cl_event /* event */, cl_profiling_info /* param_name */, size_t /* param_value_size */, + void* /* param_value */, size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Flush and Finish APIs */ +typedef cl_int(CL_API_CALL* clFlush_fn)(cl_command_queue /* command_queue */) + CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clFinish_fn)(cl_command_queue /* command_queue */) + CL_API_SUFFIX__VERSION_1_0; + +/* Enqueued Commands APIs */ +typedef cl_int(CL_API_CALL* clEnqueueReadBuffer_fn)( + cl_command_queue /* command_queue */, cl_mem /* buffer */, cl_bool /* blocking_read */, + size_t /* offset */, size_t /* cb */, void* /* ptr */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueReadBufferRect_fn)( + cl_command_queue /* command_queue */, cl_mem /* buffer */, cl_bool /* blocking_read */, + const size_t* /* buffer_offset */, const size_t* /* host_offset */, const size_t* /* region */, + size_t /* buffer_row_pitch */, size_t /* buffer_slice_pitch */, size_t /* host_row_pitch */, + size_t /* host_slice_pitch */, void* /* ptr */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_1_1; + +typedef cl_int(CL_API_CALL* clEnqueueWriteBuffer_fn)( + cl_command_queue /* command_queue */, cl_mem /* buffer */, cl_bool /* blocking_write */, + size_t /* offset */, size_t /* cb */, const void* /* ptr */, + cl_uint /* num_events_in_wait_list */, const cl_event* /* event_wait_list */, + cl_event* /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueWriteBufferRect_fn)( + cl_command_queue /* command_queue */, cl_mem /* buffer */, cl_bool /* blocking_read */, + const size_t* /* buffer_offset */, const size_t* /* host_offset */, const size_t* /* region */, + size_t /* buffer_row_pitch */, size_t /* buffer_slice_pitch */, size_t /* host_row_pitch */, + size_t /* host_slice_pitch */, const void* /* ptr */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_1_1; + +typedef cl_int(CL_API_CALL* clEnqueueCopyBuffer_fn)( + cl_command_queue /* command_queue */, cl_mem /* src_buffer */, cl_mem /* dst_buffer */, + size_t /* src_offset */, size_t /* dst_offset */, size_t /* cb */, + cl_uint /* num_events_in_wait_list */, const cl_event* /* event_wait_list */, + cl_event* /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueCopyBufferRect_fn)( + cl_command_queue /* command_queue */, cl_mem /* src_buffer */, cl_mem /* dst_buffer */, + const size_t* /* src_origin */, const size_t* /* dst_origin */, const size_t* /* region */, + size_t /* src_row_pitch */, size_t /* src_slice_pitch */, size_t /* dst_row_pitch */, + size_t /* dst_slice_pitch */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_1_1; + +typedef cl_int(CL_API_CALL* clEnqueueReadImage_fn)( + 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 */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueWriteImage_fn)( + 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 */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueCopyImage_fn)( + cl_command_queue /* command_queue */, cl_mem /* src_image */, cl_mem /* dst_image */, + const size_t* /* src_origin[3] */, const size_t* /* dst_origin[3] */, + const size_t* /* region[3] */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueCopyImageToBuffer_fn)( + cl_command_queue /* command_queue */, cl_mem /* src_image */, cl_mem /* dst_buffer */, + const size_t* /* src_origin[3] */, const size_t* /* region[3] */, size_t /* dst_offset */, + cl_uint /* num_events_in_wait_list */, const cl_event* /* event_wait_list */, + cl_event* /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueCopyBufferToImage_fn)( + cl_command_queue /* command_queue */, cl_mem /* src_buffer */, cl_mem /* dst_image */, + size_t /* src_offset */, const size_t* /* dst_origin[3] */, const size_t* /* region[3] */, + cl_uint /* num_events_in_wait_list */, const cl_event* /* event_wait_list */, + cl_event* /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef void*(CL_API_CALL* clEnqueueMapBuffer_fn)( + cl_command_queue /* command_queue */, cl_mem /* buffer */, cl_bool /* blocking_map */, + cl_map_flags /* map_flags */, size_t /* offset */, size_t /* cb */, + cl_uint /* num_events_in_wait_list */, const cl_event* /* event_wait_list */, + cl_event* /* event */, cl_int* /* errcode_ret */)CL_API_SUFFIX__VERSION_1_0; + +typedef void*(CL_API_CALL* clEnqueueMapImage_fn)( + cl_command_queue /* command_queue */, cl_mem /* image */, cl_bool /* blocking_map */, + cl_map_flags /* map_flags */, const size_t* /* origin[3] */, const size_t* /* region[3] */, + 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 */)CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueUnmapMemObject_fn)( + 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 */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueNDRangeKernel_fn)( + 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 */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueTask_fn)(cl_command_queue /* command_queue */, + cl_kernel /* kernel */, + cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, + cl_event* /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueNativeKernel_fn)( + cl_command_queue /* command_queue */, void(CL_CALLBACK* user_func)(void*), void* /* args */, + size_t /* cb_args */, cl_uint /* num_mem_objects */, const cl_mem* /* mem_list */, + const void** /* args_mem_loc */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueMarker_fn)(cl_command_queue /* command_queue */, + cl_event* /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueWaitForEvents_fn)( + cl_command_queue /* command_queue */, cl_uint /* num_events */, + const cl_event* /* event_list */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueBarrier_fn)(cl_command_queue /* command_queue */) + CL_API_SUFFIX__VERSION_1_0; + +typedef void*(CL_API_CALL* clGetExtensionFunctionAddress_fn)(const char* /* func_name */) + CL_API_SUFFIX__VERSION_1_0; + +typedef cl_mem(CL_API_CALL* clCreateFromGLBuffer_fn)( + cl_context /* context */, cl_mem_flags /* flags */, cl_GLuint /* bufobj */, + int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_mem(CL_API_CALL* clCreateFromGLTexture2D_fn)( + cl_context /* context */, cl_mem_flags /* flags */, cl_GLenum /* target */, + cl_GLint /* miplevel */, cl_GLuint /* texture */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_mem(CL_API_CALL* clCreateFromGLTexture3D_fn)( + cl_context /* context */, cl_mem_flags /* flags */, cl_GLenum /* target */, + cl_GLint /* miplevel */, cl_GLuint /* texture */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_mem(CL_API_CALL* clCreateFromGLRenderbuffer_fn)( + cl_context /* context */, cl_mem_flags /* flags */, cl_GLuint /* renderbuffer */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetGLObjectInfo_fn)( + cl_mem /* memobj */, cl_gl_object_type* /* gl_object_type */, + cl_GLuint* /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clGetGLTextureInfo_fn)( + cl_mem /* memobj */, cl_gl_texture_info /* param_name */, size_t /* param_value_size */, + void* /* param_value */, size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_event(CL_API_CALL* clCreateEventFromGLsyncKHR_fn)( + cl_context /* context */, cl_GLsync /* cl_GLsync */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; + +typedef cl_int(CL_API_CALL* clEnqueueAcquireGLObjects_fn)( + cl_command_queue /* command_queue */, cl_uint /* num_objects */, + const cl_mem* /* mem_objects */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clEnqueueReleaseGLObjects_fn)( + cl_command_queue /* command_queue */, cl_uint /* num_objects */, + const cl_mem* /* mem_objects */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int(CL_API_CALL* clCreateSubDevices_fn)( + cl_device_id /* in_device */, const cl_device_partition_property* /* properties */, + cl_uint /* num_entries */, cl_device_id* /* out_devices */, + cl_uint* /* num_devices */) CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int(CL_API_CALL* clRetainDevice_fn)(cl_device_id /* device */) + CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int(CL_API_CALL* clReleaseDevice_fn)(cl_device_id /* device */) + CL_API_SUFFIX__VERSION_1_2; + +typedef cl_mem(CL_API_CALL* clCreateImage_fn)(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 */) CL_API_SUFFIX__VERSION_1_2; + +typedef cl_program(CL_API_CALL* clCreateProgramWithBuiltInKernels_fn)( + cl_context /* context */, cl_uint /* num_devices */, const cl_device_id* /* device_list */, + const char* /* kernel_names */, cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int(CL_API_CALL* clCompileProgram_fn)( + cl_program /* program */, cl_uint /* num_devices */, const cl_device_id* /* device_list */, + const char* /* options */, cl_uint /* num_input_headers */, + const cl_program* /* input_headers */, const char** /* header_include_names */, + void(CL_CALLBACK* pfn_notify)(cl_program program, void* user_data), + void* /* user_data */) CL_API_SUFFIX__VERSION_1_2; + +typedef cl_program(CL_API_CALL* clLinkProgram_fn)( + cl_context /* context */, cl_uint /* num_devices */, const cl_device_id* /* device_list */, + const char* /* options */, cl_uint /* num_input_programs */, + const cl_program* /* input_programs */, + void(CL_CALLBACK* pfn_notify)(cl_program program, void* user_data), void* /* user_data */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int(CL_API_CALL* clUnloadPlatformCompiler_fn)(cl_platform_id /* platform */) + CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int(CL_API_CALL* clGetKernelArgInfo_fn)( + cl_kernel /* kernel */, cl_uint /* arg_indx */, cl_kernel_arg_info /* param_name */, + size_t /* param_value_size */, void* /* param_value */, + size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int(CL_API_CALL* clEnqueueFillBuffer_fn)( + 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 */) CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int(CL_API_CALL* clEnqueueFillImage_fn)( + cl_command_queue /* command_queue */, cl_mem /* image */, const void* /* fill_color */, + const size_t* /* origin */, const size_t* /* region */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int(CL_API_CALL* clEnqueueMigrateMemObjects_fn)( + cl_command_queue /* command_queue */, cl_uint /* num_mem_objects */, + const cl_mem* /* mem_objects */, cl_mem_migration_flags /* flags */, + cl_uint /* num_events_in_wait_list */, const cl_event* /* event_wait_list */, + cl_event* /* event */) CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int(CL_API_CALL* clEnqueueMarkerWithWaitList_fn)( + cl_command_queue /* command_queue */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int(CL_API_CALL* clEnqueueBarrierWithWaitList_fn)( + cl_command_queue /* command_queue */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_1_2; + +typedef void*(CL_API_CALL* clGetExtensionFunctionAddressForPlatform_fn)( + cl_platform_id /* platform */, const char* /* funcname */)CL_API_SUFFIX__VERSION_1_2; + +typedef cl_mem(CL_API_CALL* clCreateFromGLTexture_fn)( + cl_context /* context */, cl_mem_flags /* flags */, cl_GLenum /* texture_target */, + cl_GLint /* miplevel */, cl_GLuint /* texture */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; + +typedef cl_command_queue(CL_API_CALL* clCreateCommandQueueWithProperties_fn)( + cl_context /* context */, cl_device_id /* device */, + const cl_queue_properties* /* properties */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; + +typedef cl_sampler(CL_API_CALL* clCreateSamplerWithProperties_fn)( + cl_context /* context */, const cl_sampler_properties* /* properties */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; + +typedef void*(CL_API_CALL* clSVMAlloc_fn)(cl_context /* context */, cl_svm_mem_flags /* flags */, + size_t /* size */, + cl_uint /* alignment */)CL_API_SUFFIX__VERSION_2_0; + +typedef void(CL_API_CALL* clSVMFree_fn)(cl_context /* context */, + void* /* svm_pointer */) CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int(CL_API_CALL* clSetKernelArgSVMPointer_fn)( + cl_kernel /* kernel */, cl_uint /* arg_index */, + const void* /* arg_value */) CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int(CL_API_CALL* clSetKernelExecInfo_fn)( + cl_kernel /* kernel */, cl_kernel_exec_info /* param_name */, size_t /* param_value_size */, + const void* /* param_value */) CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int(CL_API_CALL* clEnqueueSVMFree_fn)( + cl_command_queue /* command_queue */, cl_uint /* num_svm_pointers */, + void* [] /* svm_pointers */, + void(CL_CALLBACK* /* pfn_free_func */)(cl_command_queue /* queue */, + cl_uint /* num_svm_pointers */, + void* [] /* svm_pointers */, void* /* user_data */), + void* /* user_data */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int(CL_API_CALL* clEnqueueSVMMemcpy_fn)( + cl_command_queue /* command_queue */, cl_bool /* blocking_copy */, void* /* dst_ptr */, + const void* /* src_ptr */, size_t /* size */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int(CL_API_CALL* clEnqueueSVMMemFill_fn)( + cl_command_queue /* command_queue */, void* /* svm_ptr */, const void* /* pattern */, + size_t /* pattern_size */, size_t /* size */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int(CL_API_CALL* clEnqueueSVMMap_fn)( + cl_command_queue /* command_queue */, cl_bool /* blocking_map */, cl_map_flags /* flags */, + void* /* svm_ptr */, size_t /* size */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */) CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int(CL_API_CALL* clEnqueueSVMUnmap_fn)(cl_command_queue /* command_queue */, + void* /* svm_ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, + cl_event* /* event */) CL_API_SUFFIX__VERSION_2_0; + +typedef cl_mem(CL_API_CALL* clCreatePipe_fn)(cl_context /* context */, cl_mem_flags /* flags */, + cl_uint /* pipe_packet_size */, + cl_uint /* pipe_max_packets */, + const cl_pipe_properties* /* properties */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int(CL_API_CALL* clGetPipeInfo_fn)( + cl_mem /* pipe */, cl_pipe_info /* param_name */, size_t /* param_value_size */, + void* /* param_value */, size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int(CL_API_CALL* clGetKernelSubGroupInfoKHR_fn)( + cl_kernel /* kernel */, cl_device_id /* device */, cl_kernel_sub_group_info /* param_name */, + size_t /* input_value_size */, const void* /* input_value */, size_t /* param_value_size */, + void* /* param_value */, size_t* /* param_value_size_ret */) CL_API_SUFFIX__VERSION_2_0; + + +typedef cl_int(CL_API_CALL* clSetDefaultDeviceCommandQueue_fn)( + cl_context /* context */, cl_device_id /* device */, + cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_2_1; + +typedef cl_kernel(CL_API_CALL* clCloneKernel_fn)( + cl_kernel /* source_kernel */, cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_2_1; + +typedef cl_int (CL_API_CALL* clEnqueueSVMMigrateMem_fn)( + cl_command_queue /* command_queue */, cl_uint /* num_svm_pointers */, + const void ** /* svm_pointers */, const size_t * /* sizes */, + cl_mem_migration_flags /* flags */, cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, cl_event * /* event */) CL_API_SUFFIX__VERSION_2_1; + +typedef cl_int (CL_API_CALL* clGetDeviceAndHostTimer_fn)( + cl_device_id /* device */, cl_ulong * /* device_timestamp */, + cl_ulong * /* host_timestamp */) CL_API_SUFFIX__VERSION_2_1; + +typedef cl_int (CL_API_CALL* clGetHostTimer_fn)( + cl_device_id /* device */, cl_ulong * /* host_timestamp */) CL_API_SUFFIX__VERSION_2_1; + +typedef cl_int (CL_API_CALL* clSetProgramSpecializationConstant_fn)( + cl_program /* program */, cl_uint /* spec_id */, size_t /* spec_size */, + const void* /* spec_value */) CL_API_SUFFIX__VERSION_2_2; + +typedef cl_int (CL_API_CALL* clSetProgramReleaseCallback_fn)( + cl_program /* program */, + void (CL_CALLBACK * /* pfn_notify */)(cl_program program, void * user_data), + void * /* user_data */) CL_API_SUFFIX__VERSION_2_2; + +typedef struct _cl_icd_dispatch_table { + /* OpenCL 1.0 */ + clGetPlatformIDs_fn GetPlatformIDs; + clGetPlatformInfo_fn GetPlatformInfo; + clGetDeviceIDs_fn GetDeviceIDs; + clGetDeviceInfo_fn GetDeviceInfo; + clCreateContext_fn CreateContext; + clCreateContextFromType_fn CreateContextFromType; + clRetainContext_fn RetainContext; + clReleaseContext_fn ReleaseContext; + clGetContextInfo_fn GetContextInfo; + clCreateCommandQueue_fn CreateCommandQueue; + clRetainCommandQueue_fn RetainCommandQueue; + clReleaseCommandQueue_fn ReleaseCommandQueue; + clGetCommandQueueInfo_fn GetCommandQueueInfo; + clSetCommandQueueProperty_fn SetCommandQueueProperty; + clCreateBuffer_fn CreateBuffer; + clCreateImage2D_fn CreateImage2D; + clCreateImage3D_fn CreateImage3D; + clRetainMemObject_fn RetainMemObject; + clReleaseMemObject_fn ReleaseMemObject; + clGetSupportedImageFormats_fn GetSupportedImageFormats; + clGetMemObjectInfo_fn GetMemObjectInfo; + clGetImageInfo_fn GetImageInfo; + clCreateSampler_fn CreateSampler; + clRetainSampler_fn RetainSampler; + clReleaseSampler_fn ReleaseSampler; + clGetSamplerInfo_fn GetSamplerInfo; + clCreateProgramWithSource_fn CreateProgramWithSource; + clCreateProgramWithBinary_fn CreateProgramWithBinary; + clRetainProgram_fn RetainProgram; + clReleaseProgram_fn ReleaseProgram; + clBuildProgram_fn BuildProgram; + clUnloadCompiler_fn UnloadCompiler; + clGetProgramInfo_fn GetProgramInfo; + clGetProgramBuildInfo_fn GetProgramBuildInfo; + clCreateKernel_fn CreateKernel; + clCreateKernelsInProgram_fn CreateKernelsInProgram; + clRetainKernel_fn RetainKernel; + clReleaseKernel_fn ReleaseKernel; + clSetKernelArg_fn SetKernelArg; + clGetKernelInfo_fn GetKernelInfo; + clGetKernelWorkGroupInfo_fn GetKernelWorkGroupInfo; + clWaitForEvents_fn WaitForEvents; + clGetEventInfo_fn GetEventInfo; + clRetainEvent_fn RetainEvent; + clReleaseEvent_fn ReleaseEvent; + clGetEventProfilingInfo_fn GetEventProfilingInfo; + clFlush_fn Flush; + clFinish_fn Finish; + clEnqueueReadBuffer_fn EnqueueReadBuffer; + clEnqueueWriteBuffer_fn EnqueueWriteBuffer; + clEnqueueCopyBuffer_fn EnqueueCopyBuffer; + clEnqueueReadImage_fn EnqueueReadImage; + clEnqueueWriteImage_fn EnqueueWriteImage; + clEnqueueCopyImage_fn EnqueueCopyImage; + clEnqueueCopyImageToBuffer_fn EnqueueCopyImageToBuffer; + clEnqueueCopyBufferToImage_fn EnqueueCopyBufferToImage; + clEnqueueMapBuffer_fn EnqueueMapBuffer; + clEnqueueMapImage_fn EnqueueMapImage; + clEnqueueUnmapMemObject_fn EnqueueUnmapMemObject; + clEnqueueNDRangeKernel_fn EnqueueNDRangeKernel; + clEnqueueTask_fn EnqueueTask; + clEnqueueNativeKernel_fn EnqueueNativeKernel; + clEnqueueMarker_fn EnqueueMarker; + clEnqueueWaitForEvents_fn EnqueueWaitForEvents; + clEnqueueBarrier_fn EnqueueBarrier; + clGetExtensionFunctionAddress_fn GetExtensionFunctionAddress; + clCreateFromGLBuffer_fn CreateFromGLBuffer; + clCreateFromGLTexture2D_fn CreateFromGLTexture2D; + clCreateFromGLTexture3D_fn CreateFromGLTexture3D; + clCreateFromGLRenderbuffer_fn CreateFromGLRenderbuffer; + clGetGLObjectInfo_fn GetGLObjectInfo; + clGetGLTextureInfo_fn GetGLTextureInfo; + clEnqueueAcquireGLObjects_fn EnqueueAcquireGLObjects; + clEnqueueReleaseGLObjects_fn EnqueueReleaseGLObjects; + clGetGLContextInfoKHR_fn GetGLContextInfoKHR; + void* _reservedForD3D10KHR[6]; + + /* OpenCL 1.1 */ + clSetEventCallback_fn SetEventCallback; + clCreateSubBuffer_fn CreateSubBuffer; + clSetMemObjectDestructorCallback_fn SetMemObjectDestructorCallback; + clCreateUserEvent_fn CreateUserEvent; + clSetUserEventStatus_fn SetUserEventStatus; + clEnqueueReadBufferRect_fn EnqueueReadBufferRect; + clEnqueueWriteBufferRect_fn EnqueueWriteBufferRect; + clEnqueueCopyBufferRect_fn EnqueueCopyBufferRect; + + void* _reservedForDeviceFissionEXT[3]; + clCreateEventFromGLsyncKHR_fn CreateEventFromGLsyncKHR; + + /* OpenCL 1.2 */ + clCreateSubDevices_fn CreateSubDevices; + clRetainDevice_fn RetainDevice; + clReleaseDevice_fn ReleaseDevice; + clCreateImage_fn CreateImage; + clCreateProgramWithBuiltInKernels_fn CreateProgramWithBuiltInKernels; + clCompileProgram_fn CompileProgram; + clLinkProgram_fn LinkProgram; + clUnloadPlatformCompiler_fn UnloadPlatformCompiler; + clGetKernelArgInfo_fn GetKernelArgInfo; + clEnqueueFillBuffer_fn EnqueueFillBuffer; + clEnqueueFillImage_fn EnqueueFillImage; + clEnqueueMigrateMemObjects_fn EnqueueMigrateMemObjects; + clEnqueueMarkerWithWaitList_fn EnqueueMarkerWithWaitList; + clEnqueueBarrierWithWaitList_fn EnqueueBarrierWithWaitList; + clGetExtensionFunctionAddressForPlatform_fn GetExtensionFunctionAddressForPlatform; + clCreateFromGLTexture_fn CreateFromGLTexture; + + /* cl_khr_d3d11_sharing, cl_khr_dx9_media_sharing */ + void* _reservedForD3DExtensions[10]; + + /* cl_khr_egl_image, cl_khr_egl_event */ + void* _reservedForEGLExtensions[4]; + + /* OpenCL 2.0 */ + clCreateCommandQueueWithProperties_fn CreateCommandQueueWithProperties; + clCreatePipe_fn CreatePipe; + clGetPipeInfo_fn GetPipeInfo; + clSVMAlloc_fn SVMAlloc; + clSVMFree_fn SVMFree; + clEnqueueSVMFree_fn EnqueueSVMFree; + clEnqueueSVMMemcpy_fn EnqueueSVMMemcpy; + clEnqueueSVMMemFill_fn EnqueueSVMMemFill; + clEnqueueSVMMap_fn EnqueueSVMMap; + clEnqueueSVMUnmap_fn EnqueueSVMUnmap; + clCreateSamplerWithProperties_fn CreateSamplerWithProperties; + clSetKernelArgSVMPointer_fn SetKernelArgSVMPointer; + clSetKernelExecInfo_fn SetKernelExecInfo; + /* cl_khr_sub_groups */ + clGetKernelSubGroupInfoKHR_fn GetKernelSubGroupInfoKHR; + + /* OpenCL 2.1 */ + clCloneKernel_fn CloneKernel; + clCreateProgramWithILKHR_fn CreateProgramWithILKHR; + clEnqueueSVMMigrateMem_fn EnqueueSVMMigrateMem; + clGetDeviceAndHostTimer_fn GetDeviceAndHostTimer; + clGetHostTimer_fn GetHostTimer; + clGetKernelSubGroupInfoKHR_fn GetKernelSubGroupInfo; + clSetDefaultDeviceCommandQueue_fn SetDefaultDeviceCommandQueue; + + /* OpenCL 2.2 */ + clSetProgramReleaseCallback_fn SetProgramReleaseCallback; + clSetProgramSpecializationConstant_fn SetProgramSpecializationConstant; + +} cl_icd_dispatch_table; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __OPENCL_CL_ICD_H */ diff --git a/opencl/amdocl/cl_kernel.h b/opencl/amdocl/cl_kernel.h new file mode 100644 index 0000000000..25eb849c59 --- /dev/null +++ b/opencl/amdocl/cl_kernel.h @@ -0,0 +1,165 @@ +/* Copyright (c) 2012 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef CL_KERNEL_H_ +#define CL_KERNEL_H_ + +struct clk_builtins_t; + +// This must be a multiple of sizeof(cl_ulong16) +#define __CPU_SCRATCH_SIZE 128 + +#define CLK_PRIVATE_MEMORY_SIZE (16 * 1024) + +struct clk_thread_info_block_t { + // Warning! The size of this struct needs to be a multiple + // of 16 when compiling 64 bit + + struct clk_builtins_t const* builtins; + void* local_mem_base; + void* local_scratch; + const void* table_base; + size_t pad; + + uint work_dim; + size_t global_offset[4]; /*dim0,dim1,dim2,invalid(dim<0||dim>2)*/ + size_t global_size[4]; /*dim0,dim1,dim2,invalid(dim<0||dim>2)*/ + + size_t enqueued_local_size[4]; + size_t local_size[4]; /*dim0,dim1,dim2,invalid(dim<0||dim>2)*/ + size_t local_id[4]; /*dim0,dim1,dim2,invalid(dim<0||dim>2)*/ + size_t group_id[4]; /*dim0,dim1,dim2,invalid(dim<0||dim>2)*/ +}; + +typedef enum clk_value_type_t { + T_VOID, + T_CHAR, + T_SHORT, + T_INT, + T_LONG, + T_FLOAT, + T_DOUBLE, + T_POINTER, + T_CHAR2, + T_CHAR3, + T_CHAR4, + T_CHAR8, + T_CHAR16, + T_SHORT2, + T_SHORT3, + T_SHORT4, + T_SHORT8, + T_SHORT16, + T_INT2, + T_INT3, + T_INT4, + T_INT8, + T_INT16, + T_LONG2, + T_LONG3, + T_LONG4, + T_LONG8, + T_LONG16, + T_FLOAT2, + T_FLOAT3, + T_FLOAT4, + T_FLOAT8, + T_FLOAT16, + T_DOUBLE2, + T_DOUBLE3, + T_DOUBLE4, + T_DOUBLE8, + T_DOUBLE16, + T_SAMPLER, + T_SEMA, + T_STRUCT, + T_QUEUE, + T_PAD +} clk_value_type_t; + +typedef enum clk_address_space_t { + A_PRIVATE, + A_LOCAL, + A_CONSTANT, + A_GLOBAL, + A_REGION +} clk_address_space_t; + +// kernel arg access qualifier and type qualifier +typedef enum clk_arg_qualifier_t { + Q_NONE = 0, + + // for image type only, access qualifier + Q_READ = 1, + Q_WRITE = 2, + + // for pointer type only + Q_CONST = 4, // pointee + Q_RESTRICT = 8, + Q_VOLATILE = 16, // pointee + Q_PIPE = 32 // pipe + +} clk_arg_qualifier_t; + +#pragma pack(push, 4) +struct clk_parameter_descriptor_t { + clk_value_type_t type; + clk_address_space_t space; + uint qualifier; + const char* name; +}; +#pragma pack(pop) + +//#define CLK_LOCAL_MEM_FENCE (1 << 0) +//#define CLK_GLOBAL_MEM_FENCE (1 << 1) + +struct clk_builtins_t { + /* Synchronization functions */ + void (*barrier_ptr)(cl_mem_fence_flags flags); + + /* AMD Only builtins: FIXME_lmoriche (extension) */ + void* reserved; + int (*printf_ptr)(const char* format, ...); +}; + +enum clk_natures_t { KN_HAS_BARRIER = 1 << 0, KN_WG_LEVEL = 1 << 1 }; + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4200) +#endif + +#if !defined(__OPENCL_VERSION__) || __OPENCL_VERSION__ >= 200 + +typedef struct clk_pipe_t { + size_t read_idx; + size_t write_idx; + size_t end_idx; + char padding[128 - 3 * sizeof(size_t)]; + char packets[]; +} clk_pipe_t; + +#endif + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +#endif /*CL_KERNEL_H_*/ diff --git a/opencl/amdocl/cl_kernel_info_amd.cpp b/opencl/amdocl/cl_kernel_info_amd.cpp new file mode 100644 index 0000000000..cc0b585b41 --- /dev/null +++ b/opencl/amdocl/cl_kernel_info_amd.cpp @@ -0,0 +1,134 @@ +/* Copyright (c) 2009 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include "cl_kernel_info_amd.h" +#include "platform/kernel.hpp" +#include "platform/ndrange.hpp" +#include "platform/command.hpp" + +/*! \addtogroup API + * @{ + * + * \addtogroup AMD_Extensions + * @{ + * + */ + +/*! \brief Retrieves the kernel information. + * + * \param kernel specifies the kernel object being queried. + * + * \param device identifies a specific device in the list of devices associated + * with \a kernel. The list of devices is the list of devices in the OpenCL + * context that is associated with \a kernel. If the list of devices associated + * with kernel is a single device, \a device can be a NULL value. + * + * \param param_name specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result + * being queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data copied + * to \a param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully + * - CL_INVALID_VALUE if \a param_name is not valid, or if size in bytes + * specified by \a param_value_size is < size of return type and + * \a param_value is not NULL + * - CL_INVALID_KERNEL if \a kernel is a not a valid program object + */ +RUNTIME_ENTRY(cl_int, clGetKernelInfoAMD, + (cl_kernel kernel, cl_device_id device, cl_kernel_info_amd param_name, + size_t param_value_size, void* param_value, size_t* param_value_size_ret)) { + // Check if we have a valid device + if (!is_valid(device)) { + return CL_INVALID_DEVICE; + } + + // Check if we have a valid performance counter + if (!is_valid(kernel)) { + return CL_INVALID_KERNEL; + } + + // Find the kernel, associated with the specified device + const device::Kernel* devKernel = as_amd(kernel)->getDeviceKernel(*as_amd(device)); + + // Make sure we found a valid kernel + if (devKernel == NULL) { + return CL_INVALID_KERNEL; + } + + // Get the corresponded parameters + switch (param_name) { + case CL_KERNELINFO_SCRATCH_REGS: + return amd::clGetInfo(devKernel->workGroupInfo()->scratchRegs_, param_value_size, param_value, + param_value_size_ret); + case CL_KERNELINFO_WAVEFRONT_PER_SIMD: + return amd::clGetInfo(devKernel->workGroupInfo()->wavefrontPerSIMD_, param_value_size, + param_value, param_value_size_ret); + case CL_KERNELINFO_WAVEFRONT_SIZE: + return amd::clGetInfo(devKernel->workGroupInfo()->wavefrontSize_, param_value_size, + param_value, param_value_size_ret); + case CL_KERNELINFO_AVAILABLE_GPRS: + return amd::clGetInfo(devKernel->workGroupInfo()->availableGPRs_, param_value_size, + param_value, param_value_size_ret); + case CL_KERNELINFO_USED_GPRS: + return amd::clGetInfo(devKernel->workGroupInfo()->usedGPRs_, param_value_size, param_value, + param_value_size_ret); + case CL_KERNELINFO_AVAILABLE_SGPRS: + return amd::clGetInfo(devKernel->workGroupInfo()->availableSGPRs_, param_value_size, + param_value, param_value_size_ret); + case CL_KERNELINFO_USED_SGPRS: + return amd::clGetInfo(devKernel->workGroupInfo()->usedSGPRs_, param_value_size, param_value, + param_value_size_ret); + case CL_KERNELINFO_AVAILABLE_VGPRS: + return amd::clGetInfo(devKernel->workGroupInfo()->availableVGPRs_, param_value_size, + param_value, param_value_size_ret); + case CL_KERNELINFO_USED_VGPRS: + return amd::clGetInfo(devKernel->workGroupInfo()->usedVGPRs_, param_value_size, param_value, + param_value_size_ret); + case CL_KERNELINFO_AVAILABLE_LDS_SIZE: + return amd::clGetInfo(devKernel->workGroupInfo()->availableLDSSize_, param_value_size, + param_value, param_value_size_ret); + case CL_KERNELINFO_USED_LDS_SIZE: + return amd::clGetInfo(devKernel->workGroupInfo()->usedLDSSize_, param_value_size, param_value, + param_value_size_ret); + case CL_KERNELINFO_AVAILABLE_STACK_SIZE: + return amd::clGetInfo(devKernel->workGroupInfo()->availableStackSize_, param_value_size, + param_value, param_value_size_ret); + case CL_KERNELINFO_USED_STACK_SIZE: + return amd::clGetInfo(devKernel->workGroupInfo()->usedStackSize_, param_value_size, + param_value, param_value_size_ret); + default: + return CL_INVALID_VALUE; + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * @} + */ diff --git a/opencl/amdocl/cl_kernel_info_amd.h b/opencl/amdocl/cl_kernel_info_amd.h new file mode 100644 index 0000000000..ab12bb9ea4 --- /dev/null +++ b/opencl/amdocl/cl_kernel_info_amd.h @@ -0,0 +1,87 @@ +/* Copyright (c) 2009 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef __CL_KERNEL_INFO_AMD_H +#define __CL_KERNEL_INFO_AMD_H + +#include "CL/cl_platform.h" + +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus*/ + +typedef cl_uint cl_kernel_info_amd; + +/* cl_kernel_info */ +enum KernelInfoAMD { + CL_KERNELINFO_NONE = 0x0, + CL_KERNELINFO_SCRATCH_REGS, + CL_KERNELINFO_WAVEFRONT_PER_SIMD, + CL_KERNELINFO_WAVEFRONT_SIZE, + CL_KERNELINFO_AVAILABLE_GPRS, + CL_KERNELINFO_USED_GPRS, + CL_KERNELINFO_AVAILABLE_LDS_SIZE, + CL_KERNELINFO_USED_LDS_SIZE, + CL_KERNELINFO_AVAILABLE_STACK_SIZE, + CL_KERNELINFO_USED_STACK_SIZE, + CL_KERNELINFO_AVAILABLE_SGPRS, + CL_KERNELINFO_USED_SGPRS, + CL_KERNELINFO_AVAILABLE_VGPRS, + CL_KERNELINFO_USED_VGPRS, + CL_KERNELINFO_LAST +}; + +/*! \brief Retrieves the kernel information. + * + * \param kernel specifies the kernel object being queried. + * + * \param device identifies a specific device in the list of devices associated + * with \a kernel. The list of devices is the list of devices in the OpenCL + * context that is associated with \a kernel. If the list of devices associated + * with kernel is a single device, \a device can be a NULL value. + * + * \param param_name specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result + * being queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data copied + * to \a param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully + * - CL_INVALID_VALUE if \a param_name is not valid, or if size in bytes + * specified by \a param_value_size is < size of return type and + * \a param_value is not NULL + * - CL_INVALID_KERNEL if \a kernel is a not a valid program object + */ +extern CL_API_ENTRY cl_int CL_API_CALL clGetKernelInfoAMD( + cl_kernel /* kernel */, cl_device_id /* device */, cl_kernel_info_amd /* param_name */, + size_t /* param_value_size */, void* /* param_value */, size_t* /* param_value_size_ret */ + ) CL_API_SUFFIX__VERSION_1_0; + +#ifdef __cplusplus +} /*extern "C"*/ +#endif /*__cplusplus*/ + +#endif /*__CL_KERNEL_INFO_AMD_H*/ diff --git a/opencl/amdocl/cl_memobj.cpp b/opencl/amdocl/cl_memobj.cpp new file mode 100644 index 0000000000..6dceea6186 --- /dev/null +++ b/opencl/amdocl/cl_memobj.cpp @@ -0,0 +1,4716 @@ +/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" + +#include "platform/context.hpp" +#include "platform/command.hpp" +#include "platform/memory.hpp" +#include + +#ifdef _WIN32 +#include +#include "cl_d3d9_amd.hpp" +#include "cl_d3d10_amd.hpp" +#include "cl_d3d11_amd.hpp" +#endif //_WIN32 + +#include + +/*! \addtogroup API + * @{ + * + * \addtogroup CL_MemObjs + * + * Memory objects are categorized into two types: buffer objects, and image + * objects. A buffer object stores a one-dimensional collection of elements + * whereas an image object is used to store a two- or three- dimensional + * texture, frame-buffer or image. + * + * Elements of a buffer object can be a scalar data type (such as an int, + * float), vector data type, or a user-defined structure. An image object is + * used to represent a buffer that can be used as a texture or a frame-buffer. + * The elements of an image object are selected from a list of predefined + * image formats. The minimum number of elements in a memory object is one. + * + * @{ + * + * \addtogroup CL_CreatingBuffer + * + * @{ + */ + +/*! \brief Helper function to validate cl_mem_flags + * + * chkReadWrite: true: check the flag CL_MEM_KERNEL_READ_AND_WRITE + * false: don't check the falg CL_MEM_KERNEL_READ_AND_WRITE + * \return true of flags are valid, otherwise - false +*/ +static bool validateFlags(cl_mem_flags flags, bool chkReadWrite = false) { + // check flags for validity + cl_bitfield temp = flags & (CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY); + if (chkReadWrite) { + temp |= (flags & CL_MEM_KERNEL_READ_AND_WRITE); + } + + if (temp && + !(CL_MEM_READ_WRITE == temp || CL_MEM_WRITE_ONLY == temp || + (chkReadWrite && (CL_MEM_KERNEL_READ_AND_WRITE == temp || + (CL_MEM_KERNEL_READ_AND_WRITE | CL_MEM_READ_WRITE) == temp)) || + CL_MEM_READ_ONLY == temp)) { + return false; + } + + if ((flags & (CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR)) == + (CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR)) { + return false; + } + if ((flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) == + (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) { + return false; + } + + if ((flags & CL_MEM_EXTERNAL_PHYSICAL_AMD) && + (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | + CL_MEM_READ_WRITE | CL_MEM_READ_ONLY))) { + return false; + } + + if ((flags & CL_MEM_BUS_ADDRESSABLE_AMD) && + (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR))) { + return false; + } + + return true; +} + +/*! \brief Helper function to validate cl_image_desc + * + * \return true of cl_image_desc parameters are valid, otherwise - false + * + * image_type describes the image type and must be either CL_MEM_OBJECT_IMAGE1D, + * CL_MEM_OBJECT_IMAGE1D_BUFFER, CL_MEM_OBJECT_IMAGE1D_ARRAY, + * CL_MEM_OBJECT_IMAGE2D, CL_MEM_OBJECT_IMAGE2D_ARRAY or CL_MEM_OBJECT_IMAGE3D. + * + * image_width is the width of the image in pixels. For a 2D image and + * image array, the image width must be <= CL_DEVICE_IMAGE2D_MAX_WIDTH. + * For a 3D image, the image width must be <= CL_DEVICE_IMAGE3D_MAX_WIDTH. + * For a 1D image buffer, the image width must be <= CL_DEVICE_IMAGE_MAX_BUFFER_SIZE. + * For a 1D image and 1D image array, the image width must be + * <= CL_DEVICE_IMAGE2D_MAX_WIDTH. + * + * image_height is height of the image in pixels. This is only used if + * the image is a 2D, 3D or 2D image array. For a 2D image or image array, + * the image height must be <= CL_DEVICE_IMAGE2D_MAX_HEIGHT. For a 3D image, + * the image height must be <= CL_DEVICE_IMAGE3D_MAX_HEIGHT. + * + * image_depth is the depth of the image in pixels. This is only used if + * the image is a 3D image and must be a value > 1 and + * <= CL_DEVICE_IMAGE3D_MAX_DEPTH. + * + * image_array_size is the number of images in the image array. This is only + * used if the image is a 1D or 2D image array. The values for + * image_array_size, if specified, must be between 1 and + * CL_DEVICE_IMAGE_MAX_ARRAY_SIZE. + * + * image_row_pitch is the scan-line pitch in bytes. This must be 0 if + * host_ptr is NULL and can be either 0 or >= image_width * size of element in + * bytes if host_ptr is not NULL. If host_ptr is not NULL and image_row_pitch = 0, + * image_row_pitch is calculated as image_width * size of element in bytes. + * If image_row_pitch is not 0, it must be a multiple of the image element + * size in bytes. + * + * image_slice_pitch is the size in bytes of each 2D slice in the 3D image or + * the size in bytes of each image in a 1D or 2D image array. This must be 0 + * if host_ptr is NULL. If host_ptr is not NULL, image_slice_pitch can be either + * 0 or >= image_row_pitch * image_height for a 2D image array or 3D image and + * can be either 0 or >= image_row_pitch for a 1D image array. If host_ptr is + * not NULL and image_slice_pitch = 0, image_slice_pitch is calculated as + * image_row_pitch * image_height for a 2D image array or 3D image and + * image_row_pitch for a 1D image array. If image_slice_pitch is not 0, it must + * be a multiple of the image_row_pitch. + * + * num_mip_levels and num_samples must be 0. + * + * buffer refers to a valid buffer memory object if image_type is + * CL_MEM_OBJECT_IMAGE1D_BUFFER. Otherwise it must be NULL. For a 1D image + * buffer object, the image pixels are taken from the buffer object’s + * data store. When the contents of a buffer object’s data store are modified, + * those changes are reflected in the contents of the 1D image buffer object + * and vice-versa at corresponding sychronization points. The image_width + * size of element in bytes must be <= size of buffer object data store. + */ +static bool validateImageDescriptor(const std::vector& devices, + const amd::Image::Format imageFormat, const cl_image_desc* desc, + void* hostPtr, size_t& imageRowPitch, size_t& imageSlicePitch) { + if (desc == NULL) { + return false; + } + + // Check if any device supports mipmaps + bool mipMapSupport = false; + for (auto& dev : devices) { + if (dev->settings().checkExtension(ClKhrMipMapImage)) { + mipMapSupport = true; + break; + } + } + + // Check if any device can accept mipmaps + if ((desc->num_mip_levels != 0) && (!mipMapSupport || (hostPtr != NULL))) { + return false; + } + + if (desc->num_samples != 0) { + return false; + } + + amd::Buffer* buffer = NULL; + size_t elemSize = imageFormat.getElementSize(); + bool imageBuffer = false; + + if (desc->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER || + (desc->mem_object != NULL && desc->image_type == CL_MEM_OBJECT_IMAGE2D)) { + if (desc->mem_object == NULL) { + return false; + } + buffer = as_amd(desc->mem_object)->asBuffer(); + if (buffer == NULL) { + return false; + } + if ((desc->image_width * desc->image_height * elemSize) > buffer->getSize()) { + return false; + } + imageBuffer = true; + } else if (desc->mem_object != NULL) { + return false; + } + + imageRowPitch = desc->image_row_pitch; + imageSlicePitch = desc->image_slice_pitch; + + switch (desc->image_type) { + case CL_MEM_OBJECT_IMAGE3D: + case CL_MEM_OBJECT_IMAGE2D_ARRAY: + case CL_MEM_OBJECT_IMAGE1D_ARRAY: + // check slice pitch + if (hostPtr == NULL) { + if (imageSlicePitch != 0) { + return false; + } + } + // Fall through to process pitch... + case CL_MEM_OBJECT_IMAGE2D: + case CL_MEM_OBJECT_IMAGE1D: + // check row pitch rules + if (hostPtr == NULL && !imageBuffer) { + if (imageRowPitch != 0) { + return false; + } + } else if (imageRowPitch != 0) { + if ((imageRowPitch < desc->image_width * elemSize) || ((imageRowPitch % elemSize) != 0)) { + return false; + } + } + if (imageRowPitch == 0) { + if (desc->mem_object != nullptr) { + imageRowPitch = amd::alignUp(desc->image_width, + devices[0]->info().imagePitchAlignment_) * elemSize; + } else { + imageRowPitch = desc->image_width * elemSize; + } + } + break; + case CL_MEM_OBJECT_IMAGE1D_BUFFER: + break; + default: + return false; + break; + } + + // Extra slice validation for three dimensional images + if ((desc->image_type == CL_MEM_OBJECT_IMAGE3D) || + (desc->image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY)) { + if (imageSlicePitch != 0) { + if ((imageSlicePitch < (imageRowPitch * desc->image_height)) || + ((imageSlicePitch % imageRowPitch) != 0)) { + return false; + } + } + if (imageSlicePitch == 0) { + imageSlicePitch = imageRowPitch * desc->image_height; + } + } else if (desc->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) { + if (imageSlicePitch != 0) { + if ((imageSlicePitch % imageRowPitch) != 0) { + return false; + } + } + if (imageSlicePitch == 0) { + imageSlicePitch = imageRowPitch; + } + } + + return true; +} + +class ImageViewRef : public amd::EmbeddedObject { + private: + amd::Image* ref_; + // Do not copy image view references. + ImageViewRef& operator=(const ImageViewRef& sref); + + public: + explicit ImageViewRef() : ref_(NULL) {} + ~ImageViewRef() { + if (ref_ != NULL) { + ref_->release(); + } + } + + ImageViewRef& operator=(amd::Image* sref) { + ref_ = sref; + return *this; + } + amd::Image* operator()() const { return ref_; } +}; + +/*! \brief Create a buffer object. + * + * \param context is a valid OpenCL context used to create the buffer object. + * + * \param flags is a bit-field that is used to specify allocation and usage + * information such as the memory arena that should be used to allocate the + * buffer object and how it will be used. + * + * \param size is the size in bytes of the buffer memory object to be + * allocated. + * + * \param host_ptr is a pointer to the buffer data that may already be + * allocated by the application. The size of the buffer that host_ptr points + * to must be >= \a size bytes. Passing in a pointer to an already allocated + * buffer on the host and using it as a buffer object allows applications to + * share data efficiently with kernels and the host. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A valid non-zero buffer object and \a errcode_ret is set to + * CL_SUCCESS if the buffer object is created successfully or a NULL value + * with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a context is not a valid context. + * - CL_INVALID_VALUE if values specified in \a flags are not valid. + * - CL_INVALID_BUFFER_SIZE if \a size is 0 or is greater than + * CL_DEVICE_MAX_MEM_ALLOC_SIZE value. + * - CL_INVALID_HOST_PTR if host_ptr is NULL and CL_MEM_USE_HOST_PTR or + * CL_MEM_COPY_HOST_PTR are set in \a flags or if \a host_ptr is not NULL but + * CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in \a flags. + * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory + * for buffer object. + * - CL_INVALID_OPERATION if the buffer object cannot be created for all + * devices in \a context. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateBuffer, (cl_context context, cl_mem_flags flags, size_t size, + void* host_ptr, cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + return NULL; + } + // check flags for validity + if (!validateFlags(flags)) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return (cl_mem)0; + } + // check size + if (size == 0) { + *not_null(errcode_ret) = CL_INVALID_BUFFER_SIZE; + LogWarning("invalid parameter \"size = 0\""); + return (cl_mem)0; + } + const std::vector& devices = as_amd(context)->devices(); + bool sizePass = false; + for (auto& dev : devices) { + if ((dev->info().maxMemAllocSize_ >= size) || + (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR))) { + sizePass = true; + break; + } + } + if (!sizePass) { + *not_null(errcode_ret) = CL_INVALID_BUFFER_SIZE; + LogWarning("invalid parameter \"size\""); + return (cl_mem)0; + } + + // check host_ptr consistency + if (host_ptr == NULL) { + if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_EXTERNAL_PHYSICAL_AMD)) { + *not_null(errcode_ret) = CL_INVALID_HOST_PTR; + LogWarning("invalid parameter \"host_ptr\""); + return (cl_mem)0; + } + } else { + if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_EXTERNAL_PHYSICAL_AMD))) { + *not_null(errcode_ret) = CL_INVALID_HOST_PTR; + LogWarning("invalid parameter \"host_ptr\""); + return (cl_mem)0; + } + + if (flags & CL_MEM_EXTERNAL_PHYSICAL_AMD) { + flags |= CL_MEM_WRITE_ONLY; + + cl_bus_address_amd* bus_address = reinterpret_cast(host_ptr); + + if (bus_address->surface_bus_address == 0) { + *not_null(errcode_ret) = CL_INVALID_HOST_PTR; + LogWarning("invalid parameter \"surface bus address\""); + return static_cast(NULL); + } + + if (bus_address->surface_bus_address & (amd::Os::pageSize() - 1)) { + *not_null(errcode_ret) = CL_INVALID_HOST_PTR; + LogWarning("invalid parameter \"surface bus address\""); + return static_cast(NULL); + } + + if (bus_address->marker_bus_address == 0) { + *not_null(errcode_ret) = CL_INVALID_HOST_PTR; + LogWarning("invalid parameter \"marker bus address\""); + return static_cast(NULL); + } + + if (bus_address->marker_bus_address & (amd::Os::pageSize() - 1)) { + *not_null(errcode_ret) = CL_INVALID_HOST_PTR; + LogWarning("invalid parameter \"marker bus address\""); + return static_cast(NULL); + } + } + } + + // check extensions flag consistency + if ((flags & CL_MEM_USE_PERSISTENT_MEM_AMD) && + (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | CL_MEM_EXTERNAL_PHYSICAL_AMD | + CL_MEM_BUS_ADDRESSABLE_AMD))) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("conflicting flags CL_MEM_USE_PERSISTENT_MEM_AMD and host memory specific flags"); + return (cl_mem)0; + } + + if ((flags & CL_MEM_EXTERNAL_PHYSICAL_AMD) || (flags & CL_MEM_BUS_ADDRESSABLE_AMD)) { + size = (size + (amd::Os::pageSize() - 1)) & (~(amd::Os::pageSize() - 1)); + } + + amd::Context& amdContext = *as_amd(context); + amd::Memory* mem = NULL; + // check if the ptr is in the svm space, if yes, we need return SVM buffer + amd::Memory* svmMem = amd::MemObjMap::FindMemObj(host_ptr); + if ((NULL != svmMem) && (flags & CL_MEM_USE_HOST_PTR)) { + size_t svmSize = svmMem->getSize(); + size_t offset = static_cast
(host_ptr) - static_cast
(svmMem->getSvmPtr()); + if (size + offset > svmSize) { + LogWarning("invalid parameter \"size\""); + return (cl_mem)0; + } + mem = new (amdContext) amd::Buffer(*svmMem, flags, offset, size); + svmMem->setHostMem(host_ptr); + } else { + mem = new (amdContext) amd::Buffer(amdContext, flags, size); + } + + if (mem == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_mem)0; + } + + if (!mem->create(host_ptr)) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + mem->release(); + return NULL; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(mem); +} +RUNTIME_EXIT + +RUNTIME_ENTRY_RET(cl_mem, clCreateSubBuffer, + (cl_mem mem, cl_mem_flags flags, cl_buffer_create_type buffer_create_type, + const void* buffer_create_info, cl_int* errcode_ret)) { + if (!is_valid(mem) || as_amd(mem)->asBuffer() == NULL) { + *not_null(errcode_ret) = CL_INVALID_MEM_OBJECT; + return NULL; + } + amd::Buffer& buffer = *as_amd(mem)->asBuffer(); + + // check flags for validity + if (!validateFlags(flags) || (buffer_create_type != CL_BUFFER_CREATE_TYPE_REGION)) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return NULL; + } + + if (buffer.getMemFlags() & (CL_MEM_EXTERNAL_PHYSICAL_AMD | CL_MEM_BUS_ADDRESSABLE_AMD)) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return NULL; + } + + const cl_buffer_region* region = (const cl_buffer_region*)buffer_create_info; + + // Check sub buffer offset alignment + bool alignmentPass = false; + const std::vector& devices = buffer.getContext().devices(); + for (auto& dev : devices) { + cl_uint deviceAlignmentBytes = dev->info().memBaseAddrAlign_ >> 3; + if (region->origin == amd::alignDown(region->origin, deviceAlignmentBytes)) { + alignmentPass = true; + } + } + + // Return an error if the offset is misaligned on all devices + if (!alignmentPass) { + *not_null(errcode_ret) = CL_MISALIGNED_SUB_BUFFER_OFFSET; + return NULL; + } + + // check size + if ((region->size == 0) || (region->origin + region->size) > buffer.getSize()) { + *not_null(errcode_ret) = CL_INVALID_BUFFER_SIZE; + return NULL; + } + + amd::Memory* mem = new (buffer.getContext()) + amd::Buffer(buffer, (flags) ? flags : buffer.getMemFlags(), region->origin, region->size); + if (mem == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return NULL; + } + + if (!mem->create(NULL)) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + mem->release(); + return NULL; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(mem); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_ReadWriteBuffer + * @{ + */ + +/*! \brief Enqueue a command to read from a buffer object to host memory. + * + * \param command_queue refers to the command-queue in which the read / write + * command will be queued. \a command_queue and \a buffer must be created with + * the same OpenCL context. + * + * \param buffer refers to a valid buffer object. + * + * \param blocking_read indicates if the read operation is blocking or + * nonblocking. If \a blocking_read is CL_TRUE i.e. the read command is + * blocking, clEnqueueReadBuffer does not return until the buffer data has been + * read and copied into memory pointed to by ptr. + * If \a blocking_read is CL_FALSE i.e. the read command is non-blocking, + * clEnqueueReadBuffer queues a non-blocking read command and returns. The + * contents of the buffer that ptr points to cannot be used until the read + * command has completed. The \a event argument returns an event object which + * can be used to query the execution status of the read command. When the read + * command has completed, the contents of the buffer that ptr points to can be + * used by the application. + * + * \param offset is the offset in bytes in the buffer object to read from or + * write to. + * + * \param cb is the size in bytes of data being read or written. + * + * \param ptr is the pointer to buffer in host memory where data is to be read + * into or to be written from. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, + * then this particular command does not wait on any event to complete. + * If \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. + * + * \param event returns an event object that identifies this particular read + * command and can be used to query or queue a wait for this particular command + * to complete. \a event can be NULL in which case it will not be possible for + * the application to query the status of this command or queue a wait for this + * command to complete. + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise it + * returns one of the following errors: + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with \a command_queue and + * \a buffer are not the same. + * - CL_INVALID_MEM_OBJECT if \a buffer is not a valid buffer object. + * - CL_INVALID_VALUE if the region being read or written specified by (offset, + * cb) is out of bounds or if \a ptr is a NULL value. + * - CL_INVALID_OPERATION if \a clEnqueueReadBuffer is called on buffer which + * has been created with CL_MEM_HOST_WRITE_ONLY or CL_MEM_HOST_NO_ACCESS. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and \a + * num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY(cl_int, clEnqueueReadBuffer, + (cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, + size_t cb, void* ptr, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(buffer)) { + return CL_INVALID_MEM_OBJECT; + } + amd::Buffer* srcBuffer = as_amd(buffer)->asBuffer(); + if (srcBuffer == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + if (srcBuffer->getMemFlags() & (CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS)) { + return CL_INVALID_OPERATION; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != srcBuffer->getContext()) { + return CL_INVALID_CONTEXT; + } + + if (ptr == NULL) { + return CL_INVALID_VALUE; + } + + amd::Coord3D srcOffset(offset, 0, 0); + amd::Coord3D srcSize(cb, 1, 1); + + if (!srcBuffer->validateRegion(srcOffset, srcSize)) { + return CL_INVALID_VALUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::CopyMetadata copyMetadata(!blocking_read, amd::CopyMetadata::CopyEnginePreference::SDMA); + amd::ReadMemoryCommand* command = new amd::ReadMemoryCommand( + hostQueue, CL_COMMAND_READ_BUFFER, eventWaitList, *srcBuffer, srcOffset, srcSize, + ptr, 0, 0, copyMetadata); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + if (blocking_read) { + command->awaitCompletion(); + } + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Enqueue a command to write to a buffer object from host memory. + * + * \param command_queue refers to the command-queue in which the read / write + * command will be queued. \a command_queue and \a buffer must be created with + * the same OpenCL context. + * + * \param buffer refers to a valid buffer object. + * + * \param blocking_write indicates if the write operation is blocking or + * non-blocking. If \a blocking_write is CL_TRUE, the OpenCL implementation + * copies the data referred to by \a ptr and enqueues the write operation in + * the command-queue. The memory pointed to by \a ptr can be reused by the + * application after the clEnqueueWriteBuffer call returns. If + * \a blocking_write is CL_FALSE, the OpenCL implementation will use \a ptr to + * perform a nonblocking write. As the write is non-blocking the implementation + * can return immediately. The memory pointed to by \a ptr cannot be reused by + * the application after the call returns. The \a event argument returns an + * event object which can be used to query the execution status of the write + * command. When the write command has completed, the memory pointed to by + * \a ptr can then be reused by the application + * + * \param offset is the offset in bytes in the buffer object to read from or + * write to. + * + * \param cb is the size in bytes of data being read or written. + * + * \param ptr is the pointer to buffer in host memory where data is to be read + * into or to be written from. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, + * then this particular command does not wait on any event to complete. + * If \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. + * + * \param event returns an event object that identifies this particular write + * command and can be used to query or queue a wait for this particular command + * to complete. \a event can be NULL in which case it will not be possible for + * the application to query the status of this command or queue a wait for this + * command to complete. + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise it + * returns one of the following errors: + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with \a command_queue and + * \a buffer are not the same. + * - CL_INVALID_MEM_OBJECT if \a buffer is not a valid buffer object. + * - CL_INVALID_VALUE if the region being read or written specified by (offset, + * cb) is out of bounds or if \a ptr is a NULL value. + * - CL_INVALID_OPERATION if \a clEnqueueWriteBuffer is called on buffer which + * has been created with CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_NO_ACCESS. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and \a + * num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clEnqueueWriteBuffer, + (cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset, + size_t cb, const void* ptr, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(buffer)) { + return CL_INVALID_MEM_OBJECT; + } + amd::Buffer* dstBuffer = as_amd(buffer)->asBuffer(); + if (dstBuffer == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + if (dstBuffer->getMemFlags() & (CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)) { + return CL_INVALID_OPERATION; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != dstBuffer->getContext()) { + return CL_INVALID_CONTEXT; + } + + if (ptr == NULL) { + return CL_INVALID_VALUE; + } + + amd::Coord3D dstOffset(offset, 0, 0); + amd::Coord3D dstSize(cb, 1, 1); + + if (!dstBuffer->validateRegion(dstOffset, dstSize)) { + return CL_INVALID_VALUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::CopyMetadata copyMetadata(!blocking_write, amd::CopyMetadata::CopyEnginePreference::SDMA); + amd::WriteMemoryCommand* command = new amd::WriteMemoryCommand( + hostQueue, CL_COMMAND_WRITE_BUFFER, eventWaitList, *dstBuffer, dstOffset, dstSize, + ptr, 0, 0, copyMetadata); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + if (blocking_write) { + command->awaitCompletion(); + } + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Enqueues a command to copy a buffer object to another + * + * \param command_queue refers to the command-queue in which the copy command + * will be queued. The OpenCL context associated with \a command_queue, + * \a src_buffer and \a dst_buffer must be the same. + * + * \param src_buffer is the source buffer object. + * + * \param dst_buffer is the destination buffer object. + * + * \param src_offset refers to the offset where to begin reading data in + * \a src_buffer. + * + * \param dst_offset refers to the offset where to begin copying data in + * \a dst_buffer. + * + * \param cb refers to the size in bytes to copy. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, + * then this particular command does not wait on any event to complete. + * If \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. + * + * \param event returns an event object that identifies this particular copy + * command and can be used to query or queue a wait for this particular command + * to complete. \a event can be NULL in which case it will not be possible for + * the application to query the status of this command or queue and wait for + * this command to complete. clEnqueueBarrier can be used instead. + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise it + * returns one of the following errors: + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with \a command_queue, + * \a src_buffer and \a dst_buffer are not the same. + * - CL_INVALID_MEM_OBJECT if \a src_buffer and \a dst_buffer are not valid + * buffer objects. + * - CL_INVALID_VALUE if \a src_offset, \a dst_offset, \a cb, \a src_offset + + * \a cb or \a dst_offset + \a cb require accessing elements outside the + * buffer memory objects. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clEnqueueCopyBuffer, + (cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, + size_t src_offset, size_t dst_offset, size_t cb, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(src_buffer) || !is_valid(dst_buffer)) { + return CL_INVALID_MEM_OBJECT; + } + amd::Buffer* srcBuffer = as_amd(src_buffer)->asBuffer(); + amd::Buffer* dstBuffer = as_amd(dst_buffer)->asBuffer(); + if (srcBuffer == NULL || dstBuffer == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != srcBuffer->getContext() || + hostQueue.context() != dstBuffer->getContext()) { + return CL_INVALID_CONTEXT; + } + + amd::Coord3D srcOffset(src_offset, 0, 0); + amd::Coord3D dstOffset(dst_offset, 0, 0); + amd::Coord3D size(cb, 1, 1); + + if (!srcBuffer->validateRegion(srcOffset, size) || !dstBuffer->validateRegion(dstOffset, size)) { + return CL_INVALID_VALUE; + } + + if (srcBuffer == dstBuffer && ((src_offset <= dst_offset && dst_offset < src_offset + cb) || + (dst_offset <= src_offset && src_offset < dst_offset + cb))) { + return CL_MEM_COPY_OVERLAP; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::CopyMemoryCommand* command = + new amd::CopyMemoryCommand(hostQueue, CL_COMMAND_COPY_BUFFER, eventWaitList, *srcBuffer, + *dstBuffer, srcOffset, dstOffset, size); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief clEnqueueReadBufferRect enqueues commands to read a 2D or 3D rectangular + * region from a buffer object to host memory. + * + * \param command_queue refers to the command-queue in which the read / write + * command will be queued. command_queue and buffer must be created with the same + * OpenCL context. buffer refers to a valid buffer object. + * + * \param blocking_read indicates if the read operations are blocking or + * nonblocking. + * If \a blocking_read is CL_TRUE i.e. the read command is blocking, + * clEnqueueReadBufferRect does not return until the buffer data has been read + * and copied into memory pointed to by ptr. + * If blocking_read is CL_FALSE i.e. the read command is non-blocking, + * clEnqueueReadBufferRect queues a non-blocking read command and returns. + * The contents of the buffer that ptr points to cannot be used until + * the read command has completed. The event argument returns an event object + * which can be used to query the execution status of the read command. + * When the read command has completed, the contents of the buffer that + * ptr points to can be used by the application. + * + * \buffer_origin defines the (x, y, z) offset in the memory region associated + * with buffer. For a 2D rectangle region, the z value given by buffer_origin[2] + * should be 0. The offset in bytes is computed as + * buffer_origin[2] * buffer_slice_pitch + buffer_origin[1] * buffer_row_pitch + + * buffer_origin[0]. + * + * \host_origin defines the (x, y, z) offset in the memory region pointed to + * by ptr. For a 2D rectangle region, the z value given by host_origin[2] + * should be 0. The offset in bytes is computed as + * host_origin[2] * host_slice_pitch + host_origin[1] * host_row_pitch + + * host_origin[0]. + * + * \param region defines the (width, height, depth) in bytes of the 2D or 3D + * rectangle being read or written. + * For a 2D rectangle copy, the depth value given by region[2] should be 1. + * + * \param buffer_row_pitch is the length of each row in bytes to be used for + * the memory region associated with buffer. If \a buffer_row_pitch is 0, + * \a buffer_row_pitch is computed as region[0]. + * + * \param buffer_slice_pitch is the length of each 2D slice in bytes to be used + * for the memory region associated with buffer. If \a buffer_slice_pitch is 0, + * \a buffer_slice_pitch is computed as region[1] * \a buffer_row_pitch. + * + * \param host_row_pitch is the length of each row in bytes to be used for + * the memory region pointed to by ptr. If \a host_row_pitch is 0, \a host_row_pitch + * is computed as region[0]. + * + * \param host_slice_pitch is the length of each 2D slice in bytes to be used + * for the memory region pointed to by ptr. If \a host_slice_pitch is 0, + * \a host_slice_pitch is computed as region[1] * \a host_row_pitch. + * ptr is the pointer to buffer in host memory where data is to be read into + * or to be written from. + * + * \param event_wait_list and \a num_events_in_wait_list specify events that + * need to complete before this particular command can be executed. + * If \a event_wait_list is NULL, then this particular command does not wait on any + * event to complete. If \a event_wait_list is NULL, \a num_events_in_wait_list + * must be 0. If \a event_wait_list is not NULL, the list of events pointed to + * by \a event_wait_list must be valid and \a num_events_in_wait_list + * must be greater than 0. The events specified in \a event_wait_list act as + * synchronization points. The context associated with events in + * \a event_wait_list and \a command_queue must be the same. + * + * \param event returns an event object that identifies this particular + * read / write command and can be used to query or queue a wait for this + * particular command to complete. event can be NULL in which case it will not + * be possible for the application to query the status of this command or queue a + * wait for this command to complete. + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise, + * it returns one of the following errors: + * - CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with command_queue and + * buffer are not the same or if the context associated with \a command_queue + * and events in event_wait_list are not the same. + * - CL_INVALID_MEM_OBJECT if buffer is not a valid buffer object. + * - CL_INVALID_VALUE if the region being read or written specified by + * (buffer_origin, region) is out of bounds. + * - CL_INVALID_VALUE if ptr is a NULL value. + * - CL_INVALID_OPERATION if \a clEnqueueReadBufferRect is called on buffer which + * has been created with CL_MEM_HOST_WRITE_ONLY or CL_MEM_HOST_NO_ACCESS. + * - CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_MISALIGNED_SUB_BUFFER_OFFSET if buffer is a sub-buffer object and offset + * specified when the sub-buffer object is created is not aligned to + * - CL_DEVICE_MEM_BASE_ADDR_ALIGN value for device associated with queue. + * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory + * for data store associated with buffer. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY(cl_int, clEnqueueReadBufferRect, + (cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, + const size_t* buffer_origin, const size_t* host_origin, const size_t* region, + size_t buffer_row_pitch, size_t buffer_slice_pitch, size_t host_row_pitch, + size_t host_slice_pitch, void* ptr, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + // Validate command queue + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + // Validate opencl buffer + if (!is_valid(buffer)) { + return CL_INVALID_MEM_OBJECT; + } + amd::Buffer* srcBuffer = as_amd(buffer)->asBuffer(); + if (srcBuffer == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + if (srcBuffer->getMemFlags() & (CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS)) { + return CL_INVALID_OPERATION; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != srcBuffer->getContext()) { + return CL_INVALID_CONTEXT; + } + // Make sure we have a valid system memory pointer + if (ptr == NULL) { + return CL_INVALID_VALUE; + } + + // Create buffer rectangle info structure + amd::BufferRect bufRect; + amd::BufferRect hostRect; + + if (!bufRect.create(buffer_origin, region, buffer_row_pitch, buffer_slice_pitch) || + !hostRect.create(host_origin, region, host_row_pitch, host_slice_pitch)) { + return CL_INVALID_VALUE; + } + + amd::Coord3D srcStart(bufRect.start_, 0, 0); + amd::Coord3D srcEnd(bufRect.end_, 1, 1); + + if (!srcBuffer->validateRegion(srcStart, srcEnd)) { + return CL_INVALID_VALUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::Coord3D size(region[0], region[1], region[2]); + amd::CopyMetadata copyMetadata(!blocking_read, amd::CopyMetadata::CopyEnginePreference::SDMA); + amd::ReadMemoryCommand* command = + new amd::ReadMemoryCommand(hostQueue, CL_COMMAND_READ_BUFFER_RECT, eventWaitList, *srcBuffer, + srcStart, size, ptr, bufRect, hostRect, copyMetadata); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + if (blocking_read) { + command->awaitCompletion(); + } + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief clEnqueueWriteBufferRect enqueues commands to write a 2D or 3D + * rectangular region to a buffer object from host memory. + * + * \param command_queue refers to the command-queue in which the read / write + * command will be queued. command_queue and buffer must be created with the same + * OpenCL context. buffer refers to a valid buffer object. + * + * \param blocking_write indicates if the write operations are blocking or + * nonblocking. + * If \a blocking_write is CL_TRUE, the OpenCL implementation copies the data + * referred to by ptr and enqueues the write operation in the command-queue. + * The memory pointed to by ptr can be reused by the application after + * the clEnqueueWriteBufferRect call returns. + * If \a blocking_write is CL_FALSE, the OpenCL implementation will use ptr to + * perform a nonblocking write. As the write is non-blocking the implementation + * can return immediately. The memory pointed to by ptr cannot be reused by + * the application after the call returns. The event argument returns + * an event object which can be used to query the execution status of the write + * command. When the write command has completed, the memory pointed to by ptr + * can then be reused by the application. + * + * \buffer_origin defines the (x, y, z) offset in the memory region associated + * with buffer. For a 2D rectangle region, the z value given by buffer_origin[2] + * should be 0. The offset in bytes is computed as + * buffer_origin[2] * buffer_slice_pitch + buffer_origin[1] * buffer_row_pitch + + * buffer_origin[0]. + * + * \host_origin defines the (x, y, z) offset in the memory region pointed to + * by ptr. For a 2D rectangle region, the z value given by host_origin[2] + * should be 0. The offset in bytes is computed as + * host_origin[2] * host_slice_pitch + host_origin[1] * host_row_pitch + + * host_origin[0]. + * + * \param region defines the (width, height, depth) in bytes of the 2D or 3D + * rectangle being read or written. + * For a 2D rectangle copy, the depth value given by region[2] should be 1. + * + * \param buffer_row_pitch is the length of each row in bytes to be used for + * the memory region associated with buffer. If \a buffer_row_pitch is 0, + * \a buffer_row_pitch is computed as region[0]. + * + * \param buffer_slice_pitch is the length of each 2D slice in bytes to be used + * for the memory region associated with buffer. If \a buffer_slice_pitch is 0, + * \a buffer_slice_pitch is computed as region[1] * \a buffer_row_pitch. + * + * \param host_row_pitch is the length of each row in bytes to be used for + * the memory region pointed to by ptr. If \a host_row_pitch is 0, \a host_row_pitch + * is computed as region[0]. + * + * \param host_slice_pitch is the length of each 2D slice in bytes to be used + * for the memory region pointed to by ptr. If \a host_slice_pitch is 0, + * \a host_slice_pitch is computed as region[1] * \a host_row_pitch. + * ptr is the pointer to buffer in host memory where data is to be read into + * or to be written from. + * + * \param event_wait_list and \a num_events_in_wait_list specify events that + * need to complete before this particular command can be executed. + * If \a event_wait_list is NULL, then this particular command does not wait on any + * event to complete. If \a event_wait_list is NULL, \a num_events_in_wait_list + * must be 0. If \a event_wait_list is not NULL, the list of events pointed to + * by \a event_wait_list must be valid and \a num_events_in_wait_list + * must be greater than 0. The events specified in \a event_wait_list act as + * synchronization points. The context associated with events in + * \a event_wait_list and \a command_queue must be the same. + * + * \param event returns an event object that identifies this particular + * read / write command and can be used to query or queue a wait for this + * particular command to complete. event can be NULL in which case it will not + * be possible for the application to query the status of this command or queue a + * wait for this command to complete. + * + * clEnqueueReadBufferRect and clEnqueueWriteBufferRect + * \return CL_SUCCESS if the function is executed successfully. Otherwise, + * it returns one of the following errors: + * - CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with command_queue and + * buffer are not the same or if the context associated with \a command_queue + * and events in event_wait_list are not the same. + * - CL_INVALID_MEM_OBJECT if buffer is not a valid buffer object. + * - CL_INVALID_VALUE if the region being read or written specified by + * (buffer_origin, region) is out of bounds. + * - CL_INVALID_VALUE if ptr is a NULL value. + * - CL_INVALID_OPERATION if \a clEnqueueWriteBufferRect is called on buffer + * which has been created with CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_NO_ACCESS. + * - CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_MISALIGNED_SUB_BUFFER_OFFSET if buffer is a sub-buffer object and offset + * specified when the sub-buffer object is created is not aligned to + * - CL_DEVICE_MEM_BASE_ADDR_ALIGN value for device associated with queue. + * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory + * for data store associated with buffer. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host. + */ +RUNTIME_ENTRY(cl_int, clEnqueueWriteBufferRect, + (cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, + const size_t* buffer_origin, const size_t* host_origin, const size_t* region, + size_t buffer_row_pitch, size_t buffer_slice_pitch, size_t host_row_pitch, + size_t host_slice_pitch, const void* ptr, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(buffer)) { + return CL_INVALID_MEM_OBJECT; + } + amd::Buffer* dstBuffer = as_amd(buffer)->asBuffer(); + if (dstBuffer == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + if (dstBuffer->getMemFlags() & (CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)) { + return CL_INVALID_OPERATION; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != dstBuffer->getContext()) { + return CL_INVALID_CONTEXT; + } + + if (ptr == NULL) { + return CL_INVALID_VALUE; + } + + // Create buffer rectangle info structure + amd::BufferRect bufRect; + amd::BufferRect hostRect; + + if (!bufRect.create(buffer_origin, region, buffer_row_pitch, buffer_slice_pitch) || + !hostRect.create(host_origin, region, host_row_pitch, host_slice_pitch)) { + return CL_INVALID_VALUE; + } + + amd::Coord3D dstStart(bufRect.start_, 0, 0); + amd::Coord3D dstEnd(bufRect.end_, 1, 1); + + if (!dstBuffer->validateRegion(dstStart, dstEnd)) { + return CL_INVALID_VALUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::Coord3D size(region[0], region[1], region[2]); + amd::CopyMetadata copyMetadata(!blocking_write, amd::CopyMetadata::CopyEnginePreference::SDMA); + amd::WriteMemoryCommand* command = + new amd::WriteMemoryCommand(hostQueue, CL_COMMAND_WRITE_BUFFER_RECT, eventWaitList, + *dstBuffer, dstStart, size, ptr, bufRect, hostRect, copyMetadata); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + if (blocking_write) { + command->awaitCompletion(); + } + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Enqueues a command to copy a 2D or 3D rectangular region from + * the buffer object identified by \a src_buffer to a 2D or 3D region + * in the buffer object identified by \a dst_buffer. + * + * \param command_queue refers to the command-queue in which the copy command + * will be queued. The OpenCL context associated with command_queue, + * \a src_buffer and \a dst_buffer must be the same. + * + * \param src_origin defines the (x, y, z) offset in the memory region + * associated with \a src_buffer. For a 2D rectangle region, the z value given + * by src_origin[2] should be 0. The offset in bytes is computed as + * src_origin[2] * src_slice_pitch + src_origin[1] * src_row_pitch + src_origin[0]. + * + * \param dst_origin defines the (x, y, z) offset in the memory region + * associated with \a dst_buffer. For a 2D rectangle region, the z value given + * by dst_origin[2] should be 0. The offset in bytes is computed as + * dst_origin[2] * dst_slice_pitch + dst_origin[1] * dst_row_pitch + dst_origin[0]. + * + * \param region defines the (width, height, depth) in bytes of the 2D or 3D + * rectangle being copied. For a 2D rectangle, the depth value given by + * region[2] should be 1. + * + * \param pasrc_row_pitch is the length of each row in bytes to be used for + * the memory region associated with src_buffer. If src_row_pitch is 0, + * src_row_pitch is computed as region[0]. + * + * \param src_slice_pitch is the length of each 2D slice in bytes to be used + * for the memory region associated with src_buffer. If src_slice_pitch is 0, + * src_slice_pitch is computed as region[1] * src_row_pitch. + * + * \param dst_row_pitch is the length of each row in bytes to be used for + * the memory region associated with dst_buffer. If dst_row_pitch is 0, + * dst_row_pitch is computed as region[0]. + * + * \param dst_slice_pitch is the length of each 2D slice in bytes to be used + * for the memory region associated with dst_buffer. If dst_slice_pitch is 0, + * dst_slice_pitch is computed as region[1] * dst_row_pitch. + * + * \param event_wait_list and num_events_in_wait_list specify events that + * need to complete before this particular command can be executed. + * If event_wait_list is NULL, then this particular command does not wait on + * any event to complete. If event_wait_list is NULL, num_events_in_wait_list + * must be 0. If event_wait_list is not NULL, the list of events pointed to by + * event_wait_list must be valid and num_events_in_wait_list must be greater + * than 0. The events specified in event_wait_list act as synchronization + * points. The context associated with events in event_wait_list and + * command_queue must be the same. + * + * \param event returns an event object that identifies this particular copy + * command and can be used to query or queue a wait for this particular + * command to complete. event can be NULL in which case it will not be + * possible for the application to query the status of this command or queue + * a wait for this command to complete. clEnqueueBarrier can be used instead. + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise, + * it returns one of the following errors: + * - CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with command_queue, + * \a src_buffer and \a dst_buffer are not the same or if the context + * associated with \a command_queue and in \a event_wait_list are not the same. + * - CL_INVALID_MEM_OBJECT if \a src_buffer and \a dst_buffer are not valid + * buffer objects. + * - CL_INVALID_VALUE if (\a src_offset, \a region) or (\a dst_offset, + * \a region) require accessing elements outside the \a src_buffer and + * \a dst_buffer buffer objects respectively. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in + * \a event_wait_list are not valid events. + * - CL_MEM_COPY_OVERLAP if \a src_buffer and \a dst_buffer are the same + * buffer object and the source and destination regions overlap. + * - CL_MISALIGNED_SUB_BUFFER_OFFSET if \a src_buffer is a sub-buffer object + * and offset specified when the sub-buffer object is created is + * not aligned to CL_DEVICE_MEM_BASE_ADDR_ALIGN value for device + * associated with queue. + * - CL_MISALIGNED_SUB_BUFFER_OFFSET if dst_buffer is a sub-buffer object + * and offset specified when the sub-buffer object is created is not + * aligned to CL_DEVICE_MEM_BASE_ADDR_ALIGN value for device associated + * with queue. + * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate + * memory for data store associated with src_buffer or dst_buffer. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources + * required by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host + * + */ +RUNTIME_ENTRY(cl_int, clEnqueueCopyBufferRect, + (cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, + const size_t* src_origin, const size_t* dst_origin, const size_t* region, + size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, + size_t dst_slice_pitch, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(src_buffer) || !is_valid(dst_buffer)) { + return CL_INVALID_MEM_OBJECT; + } + amd::Buffer* srcBuffer = as_amd(src_buffer)->asBuffer(); + amd::Buffer* dstBuffer = as_amd(dst_buffer)->asBuffer(); + if (srcBuffer == NULL || dstBuffer == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != srcBuffer->getContext() || + hostQueue.context() != dstBuffer->getContext()) { + return CL_INVALID_CONTEXT; + } + + // Create buffer rectangle info structure + amd::BufferRect srcRect; + amd::BufferRect dstRect; + + if (!srcRect.create(src_origin, region, src_row_pitch, src_slice_pitch) || + !dstRect.create(dst_origin, region, dst_row_pitch, dst_slice_pitch)) { + return CL_INVALID_VALUE; + } + + amd::Coord3D srcStart(srcRect.start_, 0, 0); + amd::Coord3D dstStart(dstRect.start_, 0, 0); + amd::Coord3D srcEnd(srcRect.end_, 1, 1); + amd::Coord3D dstEnd(dstRect.end_, 1, 1); + + if (!srcBuffer->validateRegion(srcStart, srcEnd) || + !dstBuffer->validateRegion(dstStart, dstEnd)) { + return CL_INVALID_VALUE; + } + + // Check if regions overlap each other + if ((srcBuffer == dstBuffer) && + (std::abs(static_cast(src_origin[0]) - static_cast(dst_origin[0])) < + static_cast(region[0])) && + (std::abs(static_cast(src_origin[1]) - static_cast(dst_origin[1])) < + static_cast(region[1])) && + (std::abs(static_cast(src_origin[2]) - static_cast(dst_origin[2])) < + static_cast(region[2]))) { + return CL_MEM_COPY_OVERLAP; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::Coord3D size(region[0], region[1], region[2]); + amd::CopyMemoryCommand* command = + new amd::CopyMemoryCommand(hostQueue, CL_COMMAND_COPY_BUFFER_RECT, eventWaitList, *srcBuffer, + *dstBuffer, srcStart, dstStart, size, srcRect, dstRect); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_MemoryCallback + * @{ + */ + +/*! \brief Registers a user callback function that will be called when the + * memory object is deleted and its resources freed. + * + * Each call to clSetMemObjectDestructorCallback registers the specified user + * callback function on a callback stack associated with memobj. The registered + * user callback functions are called in the reverse order in which they were + * registered. The user callback functions are called and then the memory + * object’s resources are freed and the memory object is deleted. + * This provides a mechanism for the application (and libraries) using memobj + * to be notified when the memory referenced by host_ptr, specified when + * the memory object is created and used as the storage bits for the memory + * object, can be reused or freed. + * + * \a memobj is a valid memory object. + * \a pfn_notify is the callback function that can be registered by the + * application. This callback function may be called asynchronously by the + * OpenCL implementation. It is the application’s responsibility to ensure + * that the callback function is thread-safe. The parameters to this callback + * function are: + * - memobj is the memory object being deleted. + * - user_data is a pointer to user supplied data. + * If pfn_notify is NULL, no callback function is registered for memobj. + * \a user_data will be passed as the user_data argument when pfn_notify is + * called. user_data can be NULL. + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise it + * returns one of the following errors: + * - CL_INVALID_MEM_OBJECT if memobj is not a valid memory object. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host. + * + * NOTE: When the user callback function is called by the implementation, the + * contents of the memory region pointed to by host_ptr (if the memory object is + * created with CL_MEM_USE_HOST_PTR) are undefined. The callback function is + * typically used by the application to either free or reuse the memory region + * pointed to by host_ptr. The behavior of calling expensive system routines, + * OpenCL API calls to create contexts or command-queues, or blocking OpenCL + * operations from the following list below, in a callback is undefined. + * + * \version 1.1r17 + */ +RUNTIME_ENTRY(cl_int, clSetMemObjectDestructorCallback, + (cl_mem memobj, void(CL_CALLBACK* pfn_notify)(cl_mem memobj, void* user_data), + void* user_data)) { + if (!is_valid(memobj)) { + return CL_INVALID_MEM_OBJECT; + } + + if (pfn_notify == NULL) { + return CL_INVALID_VALUE; + } + + if (!as_amd(memobj)->setDestructorCallback(pfn_notify, user_data)) { + return CL_OUT_OF_HOST_MEMORY; + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_RetRelMemory + * @{ + */ + +/*! \brief Increment the \a memobj reference count. + * + * \return CL_SUCCESS if the function is executed successfully or + * CL_INVALID_MEM_OBJECT if \a memobj is not a valid memory object. + * + * clCreateBuffer and clCreateImage{2D|3D} perform an implicit retain. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clRetainMemObject, (cl_mem memobj)) { + if (!is_valid(memobj)) { + return CL_INVALID_MEM_OBJECT; + } + as_amd(memobj)->retain(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Decrement the \a memobj reference count. + * + * After the \a memobj reference count becomes zero and commands queued for + * execution on a command-queue(s) that use \a memobj have finished, the + * memory object is deleted. + * + * \return CL_SUCCESS if the function is executed successfully or + * CL_INVALID_MEM_OBJECT if \a memobj is not a valid memory object. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clReleaseMemObject, (cl_mem memobj)) { + if (!is_valid(memobj)) { + return CL_INVALID_MEM_OBJECT; + } + as_amd(memobj)->release(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_CreatingImage + * @{ + */ + +/*! \brief Create a (1D, or 2D) image object. + * + * \param context is a valid OpenCL context on which the image object is to be + * created. + * + * \param flags is a bit-field that is used to specify allocation and usage + * information about the image memory object being created. + * + * \param image_format is a pointer to a structure that describes format + * properties of the image to be allocated. + * + * \param image_width is the width of the image in pixels. Must be greater + * than or equal to 1. + * + * \param image_height is the height of the image in pixels. Must be greater + * than or equal to 1. + * + * \param image_row_pitch is the scan-line pitch in bytes. This must be 0 if + * \a host_ptr is NULL and can be either 0 or >= \a image_width * size of + * element in bytes if \a host_ptr is not NULL. If \a host_ptr is not NULL and + * \a image_row_pitch = 0, \a image_row_pitch is calculated as + * \a image_width * size of element in bytes. + * + * \param host_ptr is a pointer to the image data that may already be allocated + * by the application. The size of the buffer that \a host_ptr points to must + * be >= \a image_row_pitch * \a image_height. The size of each element in + * bytes must be a power of 2. Passing in a pointer to an already allocated + * buffer on the host and using it as a memory object allows applications to + * share data efficiently with kernels and the host. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A valid non-zero image object and errcode_ret is set to CL_SUCCESS + * if the image object is created successfully. It returns a NULL value with + * one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a context is not a valid context. + * - CL_INVALID_VALUE if values specified in \a flags are not valid. + * - CL_INVALID_IMAGE_FORMAT_DESCRIPTOR if values specified in \a image_format + * are not valid or if \a image_format is NULL. + * - CL_INVALID_IMAGE_SIZE if \a image_width or \a image_height are 0 or if + * they exceed values specified in CL_DEVICE_IMAGE2D_MAX_WIDTH or + * CL_DEVICE_IMAGE2D_MAX_HEIGHT respectively or if values specified by + * \a image_row_pitch do not follow rules described in the argument + * description above. + * - CL_INVALID_HOST_PTR if \a host_ptr is NULL and CL_MEM_USE_HOST_PTR or + * CL_MEM_COPY_HOST_PTR are set in \a flags or if \a host_ptr is not NULL + * but CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in \a flags. + * - CL_IMAGE_FORMAT_NOT_SUPPORTED if the \a image_format is not supported. + * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory + * for image object. + * - CL_INVALID_OPERATION if the image object as specified by the + * \a image_format, \a flags and dimensions cannot be created for all devices + * in context that support images or if there are no devices in context that + * support images. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateImage2D, + (cl_context context, cl_mem_flags flags, const cl_image_format* image_format, + size_t image_width, size_t image_height, size_t image_row_pitch, void* host_ptr, + cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return (cl_mem)0; + } + // check flags for validity + if (!validateFlags(flags)) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return (cl_mem)0; + } + // check format + if (image_format == NULL) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("invalid parameter \"image_format\""); + return (cl_mem)0; + } + + const amd::Image::Format imageFormat(*image_format); + if (!imageFormat.isValid()) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("invalid parameter \"image_format\""); + return (cl_mem)0; + } + + amd::Context& amdContext = *as_amd(context); + if (!imageFormat.isSupported(amdContext)) { + *not_null(errcode_ret) = CL_IMAGE_FORMAT_NOT_SUPPORTED; + LogWarning("invalid parameter \"image_format\""); + return (cl_mem)0; + } + // check size parameters + if (image_width == 0 || image_height == 0) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_SIZE; + LogWarning("invalid parameter \"image_width\" or \"image_height\""); + return (cl_mem)0; + } + const std::vector& devices = as_amd(context)->devices(); + bool supportPass = false; + bool sizePass = false; + for (auto& dev : devices) { + if (dev->info().imageSupport_) { + supportPass = true; + if (dev->info().image2DMaxWidth_ >= image_width && + dev->info().image2DMaxHeight_ >= image_height) { + sizePass = true; + break; + } + } + } + if (!supportPass) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + LogWarning("there are no devices in context to support images"); + return (cl_mem)0; + } + if (!sizePass) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_SIZE; + LogWarning("invalid parameter \"image_width\" or \"image_height\""); + return (cl_mem)0; + } + // check row pitch rules + if (host_ptr == NULL) { + if (image_row_pitch) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_SIZE; + LogWarning("invalid parameter \"image_row_pitch\""); + return (cl_mem)0; + } + } else if (image_row_pitch) { + size_t elemSize = imageFormat.getElementSize(); + if ((image_row_pitch < image_width * elemSize) || (image_row_pitch % elemSize)) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_SIZE; + LogWarning("invalid parameter \"image_row_pitch\""); + return (cl_mem)0; + } + } + // check host_ptr consistency + if (host_ptr == NULL) { + if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) { + *not_null(errcode_ret) = CL_INVALID_HOST_PTR; + LogWarning("invalid parameter \"host_ptr\""); + return (cl_mem)0; + } + } else { + if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) { + *not_null(errcode_ret) = CL_INVALID_HOST_PTR; + LogWarning("invalid parameter \"host_ptr\""); + return (cl_mem)0; + } + } + + // CL_IMAGE_FORMAT_NOT_SUPPORTED ??? + + if (image_row_pitch == 0) { + image_row_pitch = image_width * imageFormat.getElementSize(); + } + + amd::Image* image = + new (amdContext) amd::Image(amdContext, CL_MEM_OBJECT_IMAGE2D, flags, imageFormat, + image_width, image_height, 1, image_row_pitch, 0); + if (image == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + LogWarning("cannot allocate resources"); + return (cl_mem)0; + } + + // CL_MEM_OBJECT_ALLOCATION_FAILURE + if (!image->create(host_ptr)) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + image->release(); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return (cl_mem)as_cl(image); +} +RUNTIME_EXIT + +/*! \brief Create a 3D image object. + * + * \param context is a valid OpenCL context on which the image object is to be + * created. + * + * \param flags is a bit-field that is used to specify allocation and usage + * information about the image memory object being created. + * + * \param image_format is a pointer to a structure that describes format + * properties of the image to be allocated. + * + * \param image_width is the width of the image in pixels. Must be greater + * than or equal to 1. + * + * \param image_height is the height of the image in pixels. Must be greater + * than or equal to 1. + * + * \param image_depth is the depth of the image in pixels. This must be a + * value > 1. + * + * \param image_row_pitch is the scan-line pitch in bytes. This must be 0 if + * \a host_ptr is NULL and can be either 0 or >= \a image_width * size of + * element in bytes if \a host_ptr is not NULL. If \a host_ptr is not NULL and + * \a image_row_pitch = 0, \a image_row_pitch is calculated as + * \a image_width * size of element in bytes. + * + * \param image_slice_pitch is the size in bytes of each 2D slice in the 3D + * image. This must be 0 if \a host_ptr is NULL and can be either 0 or >= + * \a image_row_pitch * \a image_height if \a host_ptr is not NULL. + * If \a host_ptr is not NULL and \a image_slice_pitch = 0, + * \a image_slice_pitch is calculated as \a image_row_pitch * \a image_height. + * + * \param host_ptr is a pointer to the image data that may already be allocated + * by the application. The size of the buffer that \a host_ptr points to must + * be >= \a image_row_pitch * \a image_height * \a image_depth. The size of + * each element in bytes must be a power of 2. Passing in a pointer to an + * already allocated buffer on the host and using it as a memory object allows + * applications to share data efficiently with kernels and the host. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return valid non-zero image object created and the \a errcode_ret is set to + * CL_SUCCESS if the image object is created successfully. It returns a NULL + * value with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a context is not a valid context. + * - CL_INVALID_VALUE if values specified in \a flags are not valid. + * - CL_INVALID_IMAGE_FORMAT_DESCRIPTOR if values specified in \a image_format + * are not valid or if \a image_format is NULL. + * - CL_INVALID_IMAGE_SIZE if \a image_width, \a image_height or \a image_depth + * are 0 or if they exceed values specified in CL_DEVICE_IMAGE3D_MAX_WIDTH, + * CL_DEVICE_IMAGE3D_MAX_HEIGHT or CL_DEVICE_IMAGE3D_MAX_DEPTH respectively + * or if values specified by \a image_row_pitch and \a image_slice_pitch do + * not follow rules described in the argument description above. + * - CL_INVALID_HOST_PTR if \a host_ptr is NULL and CL_MEM_USE_HOST_PTR or + * CL_MEM_COPY_HOST_PTR are set in \a flags or if \a host_ptr is not NULL but + * CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in \a flags. + * - CL_IMAGE_FORMAT_NOT_SUPPORTED if the \a image_format is not supported. + * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory + * for image object. + * - CL_INVALID_OPERATION if the image object as specified by the + * \a image_format, \a flags and dimensions cannot be created for all devices + * in context that support images, or if there are no devices in context that + * support images. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY_RET(cl_mem, clCreateImage3D, + (cl_context context, cl_mem_flags flags, const cl_image_format* image_format, + size_t image_width, size_t image_height, size_t image_depth, + size_t image_row_pitch, size_t image_slice_pitch, void* host_ptr, + cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return (cl_mem)0; + } + // check flags for validity + if (!validateFlags(flags)) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return (cl_mem)0; + } + // check format + if (image_format == NULL) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("invalid parameter \"image_format\""); + return (cl_mem)0; + } + amd::Image::Format imageFormat(*image_format); + + if (!imageFormat.isValid()) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("invalid parameter \"image_format\""); + return (cl_mem)0; + } + + amd::Context& amdContext = *as_amd(context); + if (!imageFormat.isSupported(amdContext)) { + *not_null(errcode_ret) = CL_IMAGE_FORMAT_NOT_SUPPORTED; + LogWarning("invalid parameter \"image_format\""); + return (cl_mem)0; + } + // check size parameters + if (image_width == 0 || image_height == 0 || image_depth <= 1) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_SIZE; + LogWarning("invalid size parameter(s)"); + return (cl_mem)0; + } + const std::vector& devices = as_amd(context)->devices(); + bool supportPass = false; + bool sizePass = false; + for (auto& dev : devices) { + if (dev->info().imageSupport_) { + supportPass = true; + if ((dev->info().image3DMaxWidth_ >= image_width) && + (dev->info().image3DMaxHeight_ >= image_height) && + (dev->info().image3DMaxDepth_ >= image_depth)) { + sizePass = true; + break; + } + } + } + if (!supportPass) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + LogWarning("there are no devices in context to support images"); + return (cl_mem)0; + } + if (!sizePass) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_SIZE; + LogWarning("invalid size parameter(s)"); + return (cl_mem)0; + } + // check row pitch rules + if (host_ptr == NULL) { + if (image_row_pitch) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_SIZE; + LogWarning("invalid parameter \"image_row_pitch\""); + return (cl_mem)0; + } + } else if (image_row_pitch) { + size_t elemSize = imageFormat.getElementSize(); + if ((image_row_pitch < image_width * elemSize) || (image_row_pitch % elemSize)) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_SIZE; + LogWarning("invalid parameter \"image_row_pitch\""); + return (cl_mem)0; + } + } + // check slice pitch + if (host_ptr == NULL) { + if (image_slice_pitch) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_SIZE; + LogWarning("invalid parameter \"image_row_pitch\""); + return (cl_mem)0; + } + } else if (image_slice_pitch) { + size_t elemSize = imageFormat.getElementSize(); + if ((image_slice_pitch < image_row_pitch * image_height) || + (image_slice_pitch % image_row_pitch)) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_SIZE; + LogWarning("invalid parameter \"image_row_pitch\""); + return (cl_mem)0; + } + } + // check host_ptr consistency + if (host_ptr == NULL) { + if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) { + *not_null(errcode_ret) = CL_INVALID_HOST_PTR; + LogWarning("invalid parameter \"host_ptr\""); + return (cl_mem)0; + } + } else { + if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) { + *not_null(errcode_ret) = CL_INVALID_HOST_PTR; + LogWarning("invalid parameter \"host_ptr\""); + return (cl_mem)0; + } + } + + // CL_IMAGE_FORMAT_NOT_SUPPORTED ??? + + if (image_row_pitch == 0) { + image_row_pitch = image_width * imageFormat.getElementSize(); + } + if (image_slice_pitch == 0) { + image_slice_pitch = image_row_pitch * image_height; + } + + amd::Image* image = new (amdContext) + amd::Image(amdContext, CL_MEM_OBJECT_IMAGE3D, flags, imageFormat, image_width, image_height, + image_depth, image_row_pitch, image_slice_pitch); + if (image == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + LogWarning("cannot allocate resources"); + return (cl_mem)0; + } + + // CL_MEM_OBJECT_ALLOCATION_FAILURE + if (!image->create(host_ptr)) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + image->release(); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return (cl_mem)as_cl(image); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_QueryImageFormat + * @{ + */ + +/*! \brief Get the list of supported image formats. + * + * \param context is a valid OpenCL context on which the image object(s) will + * be created. + * + * \param flags is a bit-field that is used to specify allocation and usage + * information about the image memory object being created. + * + * \param image_type describes the image type and must be either + * CL_MEM_OBJECT_IMAGE1D, CL_MEM_OBJECT_IMAGE1D_BUFFER, CL_MEM_OBJECT_IMAGE2D, + * CL_MEM_OBJECT_IMAGE3D, CL_MEM_OBJECT_IMAGE1D_ARRAY or + * CL_MEM_OBJECT_IMAGE2D_ARRAY. + * + * \param num_entries specifies the number of entries that can be returned in + * the memory location given by \a image_formats. + * + * \param image_formats is a pointer to a memory location where the list of + * supported image formats are returned. Each entry describes a cl_image_format + * structure supported by the runtime. If \a image_formats is NULL, it is + * ignored. + * + * \param num_image_formats is the actual number of supported image formats for + * a specific context and values specified by \a flags. If \a num_image_formats + * is NULL, it is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully + * - CL_INVALID_CONTEXT if \a context is not a valid context + * - CL_INVALID_VALUE if \a flags or \a image_type are not valid, or if + * \a num_entries is 0 and \a image_formats is not NULL + * + * \version 1.2r08 + */ +RUNTIME_ENTRY(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)) { + if (!is_valid(context)) { + LogWarning("invalid parameter \"context\""); + return CL_INVALID_CONTEXT; + } + // check flags for validity + if (!validateFlags(flags, true)) { + LogWarning("invalid parameter \"flags\""); + return CL_INVALID_VALUE; + } + // chack image_type + switch (image_type) { + case CL_MEM_OBJECT_IMAGE1D_BUFFER: + case CL_MEM_OBJECT_IMAGE1D: + case CL_MEM_OBJECT_IMAGE1D_ARRAY: + case CL_MEM_OBJECT_IMAGE2D: + case CL_MEM_OBJECT_IMAGE2D_ARRAY: + case CL_MEM_OBJECT_IMAGE3D: + break; + + default: + LogWarning("invalid parameter \"image_type\""); + return CL_INVALID_VALUE; + } + if (num_entries == 0 && image_formats != NULL) { + LogWarning("invalid parameter \"num_entries\""); + return CL_INVALID_VALUE; + } + + const amd::Context& amdContext = *as_amd(context); + + if (image_formats != NULL) { + amd::Image::getSupportedFormats(amdContext, image_type, num_entries, image_formats, flags); + } + if (num_image_formats != NULL) { + *num_image_formats = amd::Image::numSupportedFormats(amdContext, image_type, flags); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + + +/*! @} + * \addtogroup CL_ReadWriteImage + * @{ + */ + +/*! \brief Enqueue a command to read from a 2D or 3D image object to host memory + * + * \param command_queue refers to the command-queue in which the read + * command will be queued. \a command_queue and \a image must be created with + * the same OpenCL context. + * + * \param image refers to a valid 2D or 3D image object. + * + * \param blocking_read indicates if the read is blocking or nonblocking. If + * \a blocking_read is CL_TRUE i.e. the read command is blocking, + * clEnqueueReadImage does not return until the buffer data has been read and + * copied into memory pointed to by \a ptr. If \a blocking_read is CL_FALSE + * i.e. the read command is non-blocking, clEnqueueReadImage queues a + * non-blocking read command and returns. The contents of the buffer that + * \a ptr points to cannot be used until the read command has completed. + * The \a event argument returns an event object which can be used to query the + * execution status of the read command. When the read command has completed, + * the contents of the buffer that ptr points to can be used by the application + * + * \param origin defines the (x, y, z) offset in the image from where to read + * or write. If image is a 2D image object, the z value given by origin[2] must + * be 0. + * + * \param region defines the (width, height, depth) of the 2D or 3D rectangle + * being read or written. If image is a 2D image object, the depth value given + * by region[2] must be 1. + * + * \param row_pitch in clEnqueueReadImage is the length of each row in bytes. + * This value must be greater than or equal to the element size in bytes + * width. If \a row_pitch is set to 0, the appropriate row pitch is calculated + * based on the size of each element in bytes multiplied by width. + * + * \param slice_pitch in clEnqueueReadImage clEnqueueWriteImage is the size + * in bytes of the 2D slice of the 3D region of a 3D image being read or + * written respectively. This must be 0 if image is a 2D image. This value + * must be greater than or equal to row_pitch * height. If \a slice_pitch is + * set to 0, the appropriate slice pitch is calculated based on the + * \a row_pitch * \a height. + * + * \param ptr is the pointer to a buffer in host memory where image data is + * to be read from. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, then this + * particular command does not wait on any event to complete. If + * \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. + * + * \param event returns an event object that identifies this particular read + * command and can be used to query or queue a wait for this particular command + * to complete. \a event can be NULL in which case it will not be possible for + * the application to query the status of this command or queue a wait for this + * command to complete. + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise it + * returns one of the following errors: + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with \a command_queue and + * \a image are not the same. + * - CL_INVALID_MEM_OBJECT if \a image is not a valid image object. + * - CL_INVALID_VALUE if the region being read specified by \a origin and + * \a region is out of bounds or if \a ptr is a NULL value. + * - CL_INVALID_VALUE if \a image is a 2D image object and \a origin[2] is not + * equal to 0 or \a region[2] is not equal to 1 or \a slice_pitch is not + * equal to 0. + * - CL_INVALID_OPERATION if \a clEnqueueReadImage is called on image which + * has been created with CL_MEM_HOST_WRITE_ONLY or CL_MEM_HOST_NO_ACCESS. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_INVALID_VALUE if blocking_read is CL_FALSE and \a event is NULL. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY(cl_int, clEnqueueReadImage, + (cl_command_queue command_queue, cl_mem image, cl_bool blocking_read, + const size_t* origin, const size_t* region, 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)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(image)) { + return CL_INVALID_MEM_OBJECT; + } + amd::Image* srcImage = as_amd(image)->asImage(); + if (srcImage == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + if (srcImage->getMemFlags() & (CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS)) { + return CL_INVALID_OPERATION; + } + + if (srcImage->getImageFormat().image_channel_order == CL_DEPTH_STENCIL) { + return CL_INVALID_OPERATION; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != srcImage->getContext()) { + return CL_INVALID_CONTEXT; + } + + if (ptr == NULL) { + return CL_INVALID_VALUE; + } + + amd::Coord3D srcOrigin(origin[0], origin[1], origin[2]); + amd::Coord3D srcRegion(region[0], region[1], region[2]); + + ImageViewRef mip; + if (srcImage->getMipLevels() > 1) { + // Create a view for the specified mip level + mip = srcImage->createView(srcImage->getContext(), srcImage->getImageFormat(), NULL, + origin[srcImage->getDims()]); + if (mip() == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + // Reset the mip level value to 0, since a view was created + if (srcImage->getDims() < 3) { + srcOrigin.c[srcImage->getDims()] = 0; + } + srcImage = mip(); + } + + if (!srcImage->validateRegion(srcOrigin, srcRegion) || + !srcImage->isRowSliceValid(row_pitch, slice_pitch, region[0], region[1])) { + return CL_INVALID_VALUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::CopyMetadata copyMetadata(!blocking_read, amd::CopyMetadata::CopyEnginePreference::SDMA); + amd::ReadMemoryCommand* command = + new amd::ReadMemoryCommand(hostQueue, CL_COMMAND_READ_IMAGE, eventWaitList, *srcImage, + srcOrigin, srcRegion, ptr, row_pitch, slice_pitch, copyMetadata); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + if (blocking_read) { + command->awaitCompletion(); + } + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Enqueue a command to write to a 2D or 3D image object from host + * memory + * + * \param command_queue refers to the command-queue in which the write + * command will be queued. \a command_queue and \a image must be created with + * the same OpenCL context. + * + * \param image refers to a valid 2D or 3D image object. + * + * \param blocking_write indicates if the write operation is blocking or + * nonblocking. If blocking_write is CL_TRUE, the OpenCL implementation copies + * the data referred to by \a ptr and enqueues the write command in the + * command-queue. The memory pointed to by ptr can be reused by the application + * after the clEnqueueWriteImage call returns. If blocking_write is CL_FALSE, + * the OpenCL implementation will use ptr to perform a nonblocking write. As + * the write is non-blocking the implementation can return immediately. The + * memory pointed to by ptr cannot be reused by the application after the call + * returns. The event argument returns an event object which can be used to + * query the execution status of the write command. When the write command has + * completed, the memory pointed to by ptr can then be reused by the + * application. + * + * \param origin defines the (x, y, z) offset in the image from where to read + * or write. If image is a 2D image object, the z value given by origin[2] must + * be 0. + * + * \param region defines the (width, height, depth) of the 2D or 3D rectangle + * being read or written. If image is a 2D image object, the depth value given + * by region[2] must be 1. + * + * \param input_row_pitch in is the length of each row in bytes. + * This value must be greater than or equal to the element size in bytes + * width. If \a input_row_pitch is set to 0, the appropriate row pitch is + * calculated based on the size of each element in bytes multiplied by width. + * + * \param input_slice_pitch is the size + * in bytes of the 2D slice of the 3D region of a 3D image being read or + * written respectively. This must be 0 if image is a 2D image. This value + * must be greater than or equal to input_row_pitch * height. If + * \a input_slice_pitch is set to 0, the appropriate slice pitch is calculated + * based on the \a input_row_pitch * \a height. + * + * \param ptr is the pointer to a buffer in host memory where image data is + * to be written to. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, then this + * particular command does not wait on any event to complete. If + * \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. + * + * \param event returns an event object that identifies this particular write + * command and can be used to query or queue a wait for this particular command + * to complete. \a event can be NULL in which case it will not be possible for + * the application to query the status of this command or queue a wait for this + * command to complete. + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise it + * returns one of the following errors: + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with \a command_queue and + * \a image are not the same. + * - CL_INVALID_MEM_OBJECT if \a image is not a valid image object. + * - CL_INVALID_VALUE if the region being written specified by \a origin and + * \a region is out of bounds or if \a ptr is a NULL value. + * - CL_INVALID_VALUE if \a image is a 2D image object and \a origin[2] is not + * equal to 0 or \a region[2] is not equal to 1 or \a slice_pitch is not + * equal to 0. + * - CL_INVALID_OPERATION if \a clEnqueueWriteImage is called on image which + * has been created with CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_NO_ACCESS. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_INVALID_VALUE if blocking_write is CL_FALSE and \a event is NULL. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clEnqueueWriteImage, + (cl_command_queue command_queue, cl_mem image, cl_bool blocking_write, + const size_t* origin, const size_t* region, 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)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(image)) { + return CL_INVALID_MEM_OBJECT; + } + amd::Image* dstImage = as_amd(image)->asImage(); + if (dstImage == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + if (dstImage->getMemFlags() & (CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)) { + return CL_INVALID_OPERATION; + } + + if (dstImage->getImageFormat().image_channel_order == CL_DEPTH_STENCIL) { + return CL_INVALID_OPERATION; + } + + if (dstImage->getDims() == 2 && origin[2] != 0) { + return CL_INVALID_VALUE; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != dstImage->getContext()) { + return CL_INVALID_CONTEXT; + } + + if (ptr == NULL) { + return CL_INVALID_VALUE; + } + + amd::Coord3D dstOrigin(origin[0], origin[1], origin[2]); + amd::Coord3D dstRegion(region[0], region[1], region[2]); + ImageViewRef mip; + if (dstImage->getMipLevels() > 1) { + // Create a view for the specified mip level + mip = dstImage->createView(dstImage->getContext(), dstImage->getImageFormat(), NULL, + origin[dstImage->getDims()]); + if (mip() == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + // Reset the mip level value to 0, since a view was created + if (dstImage->getDims() < 3) { + dstOrigin.c[dstImage->getDims()] = 0; + } + dstImage = mip(); + } + + if (!dstImage->validateRegion(dstOrigin, dstRegion) || + !dstImage->isRowSliceValid(input_row_pitch, input_slice_pitch, region[0], region[1])) { + return CL_INVALID_VALUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::CopyMetadata copyMetadata(!blocking_write, amd::CopyMetadata::CopyEnginePreference::SDMA); + amd::WriteMemoryCommand* command = + new amd::WriteMemoryCommand(hostQueue, CL_COMMAND_WRITE_IMAGE, eventWaitList, *dstImage, + dstOrigin, dstRegion, ptr, input_row_pitch, input_slice_pitch, + copyMetadata); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + if (blocking_write) { + command->awaitCompletion(); + } + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Enqueue a command to copy image objects. + * + * \param command_queue refers to the command-queue in which the copy command + * will be queued. The OpenCL context associated with \a command_queue, + * \a src_image and \a dst_image must be the same. + * + * \param src_image is the source image object. + * + * \param dst_image is the destination image object. + * + * \param src_origin defines the starting (x, y, z) location in \a src_image + * from where to start the data copy. If \a src_image is a 2D image object, + * the z value given by \a src_origin[2] must be 0. + * + * \param dst_origin defines the starting (x, y, z) location in \a dst_image + * from where to start the data copy. If \a dst_image is a 2D image object, + * the z value given by \a dst_origin[2] must be 0. + * + * \param region defines the (width, height, depth) of the 2D or 3D rectangle + * to copy. If \a src_image or \a dst_image is a 2D image object, the depth + * value given by \a region[2] must be 1. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, then + * this particular command does not wait on any event to complete. If + * \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. If + * \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. + * + * \param event returns an event object that identifies this particular copy + * command and can be used to query or queue a wait for this particular + * command to complete. \a event can be NULL in which case it will not be + * possible for the application to query the status of this command or queue + * a wait for this command to complete. clEnqueueBarrier can be used instead. + * It is currently a requirement that the \a src_image and \a dst_image image + * memory objects for clEnqueueCopyImage must have the exact image format + * (i.e. channel order and channel data type must match). + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise it + * returns one of the following errors: + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with \a command_queue, + * \a src_image and \a dst_image are not the same. + * - CL_INVALID_MEM_OBJECT if \a src_image and \a dst_image are not valid image + * objects. + * - CL_IMAGE_FORMAT_MISMATCH if src_image and dst_image do not use the same + * image format. + * - CL_INVALID_VALUE if the 2D or 3D rectangular region specified by + * \a src_origin and \a src_origin + \a region refers to a region outside + * \a src_image, or if the 2D or 3D rectangular region specified by + * \a dst_origin and \a dst_origin + \a region refers to a region outside + * \a dst_image. + * - CL_INVALID_VALUE if \a src_image is a 2D image object and \a origin[2] is + * not equal to 0 or \a region[2] is not equal to 1. + * - CL_INVALID_VALUE if \a dst_image is a 2D image object and \a dst_origin[2] + * is not equal to 0 or \a region[2] is not equal to 1. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clEnqueueCopyImage, + (cl_command_queue command_queue, cl_mem src_image, cl_mem dst_image, + const size_t* src_origin, const size_t* dst_origin, const size_t* region, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(src_image) || !is_valid(dst_image)) { + return CL_INVALID_MEM_OBJECT; + } + amd::Image* srcImage = as_amd(src_image)->asImage(); + amd::Image* dstImage = as_amd(dst_image)->asImage(); + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != srcImage->getContext() || + hostQueue.context() != dstImage->getContext()) { + return CL_INVALID_CONTEXT; + } + + if (srcImage->getImageFormat() != dstImage->getImageFormat()) { + return CL_IMAGE_FORMAT_MISMATCH; + } + + if (srcImage->getImageFormat().image_channel_order == CL_DEPTH_STENCIL) { + return CL_INVALID_OPERATION; + } + + amd::Coord3D srcOrigin(src_origin[0], src_origin[1], src_origin[2]); + amd::Coord3D dstOrigin(dst_origin[0], dst_origin[1], dst_origin[2]); + amd::Coord3D copyRegion(region[0], region[1], region[2]); + + ImageViewRef srcMip; + if (srcImage->getMipLevels() > 1) { + // Create a view for the specified mip level + srcMip = srcImage->createView(srcImage->getContext(), srcImage->getImageFormat(), NULL, + src_origin[srcImage->getDims()]); + if (srcMip() == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + // Reset the mip level value to 0, since a view was created + if (srcImage->getDims() < 3) { + srcOrigin.c[srcImage->getDims()] = 0; + } + srcImage = srcMip(); + } + + if (!srcImage->validateRegion(srcOrigin, copyRegion)) { + return CL_INVALID_VALUE; + } + + ImageViewRef dstMip; + if (dstImage->getMipLevels() > 1) { + // Create a view for the specified mip level + dstMip = dstImage->createView(dstImage->getContext(), dstImage->getImageFormat(), NULL, + dst_origin[dstImage->getDims()]); + if (dstMip() == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + // Reset the mip level value to 0, since a view was created + if (dstImage->getDims() < 3) { + dstOrigin.c[dstImage->getDims()] = 0; + } + dstImage = dstMip(); + } + + if (!dstImage->validateRegion(dstOrigin, copyRegion)) { + return CL_INVALID_VALUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + if (src_image == dst_image) { + if ((src_origin[0] <= dst_origin[0] && dst_origin[0] < src_origin[0] + region[0]) || + (dst_origin[0] <= src_origin[0] && src_origin[0] < dst_origin[0] + region[0]) || + (src_origin[1] <= dst_origin[1] && dst_origin[1] < src_origin[1] + region[1]) || + (dst_origin[1] <= src_origin[1] && src_origin[1] < dst_origin[1] + region[1])) { + return CL_MEM_COPY_OVERLAP; + } + if (srcImage->getDims() > 2) { + if ((src_origin[2] <= dst_origin[2] && dst_origin[2] < src_origin[2] + region[2]) || + (dst_origin[2] <= src_origin[2] && src_origin[2] < dst_origin[2] + region[2])) { + return CL_MEM_COPY_OVERLAP; + } + } + } + + amd::CopyMemoryCommand* command = + new amd::CopyMemoryCommand(hostQueue, CL_COMMAND_COPY_IMAGE, eventWaitList, *srcImage, + *dstImage, srcOrigin, dstOrigin, copyRegion); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_CopyingImageBuffer + * @{ + */ + +/*! \brief Enqueue a command to copy an image object to a buffer object. + * + * \param command_queue must be a valid command-queue. The OpenCL context + * associated with \a command_queue, \a src_image and \a dst_buffer must be + * the same. + * + * \param src_image is a valid image object. + * + * \param dst_buffer is a valid buffer object. + * + * \param src_origin defines the (x, y, z) offset in the image from where to + * copy. If \a src_image is a 2D image object, the z value given by + * \a src_origin[2] must be 0. + * + * \param region defines the (width, height, depth) of the 2D or 3D rectangle + * to copy. If \a src_image is a 2D image object, the depth value given by + * \a region[2] must be 1. + * + * \param dst_offset refers to the offset where to begin copying data in + * \a dst_buffer. The size in bytes of the region to be copied referred to as + * \a dst_cb is computed as width * height * depth * bytes/image element if + * \a src_image is a 3D image object and is computed as + * width * height * bytes/image element if \a src_image is a 2D image object. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, then this + * particular command does not wait on any event to complete. If + * \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. + * + * \param event returns an event object that identifies this particular copy + * command and can be used to query or queue a wait for this particular + * command to complete. \a event can be NULL in which case it will not be + * possible for the application to query the status of this command or queue a + * wait for this command to complete. clEnqueueBarrier can be used instead. + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise it + * returns one of the following errors: + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with \a command_queue, + * \a src_image and \a dst_buffer are not the same. + * - CL_INVALID_MEM_OBJECT if \a src_image is not a valid image object or + * \a dst_buffer is not a valid buffer object. + * - CL_INVALID_VALUE if the 2D or 3D rectangular region specified by + * \a src_origin and \a src_origin + \a region refers to a region outside + * \a src_image, or if the region specified by \a dst_offset and + * \a dst_offset + \a dst_cb to a region outside \a dst_buffer. + * - CL_INVALID_VALUE if \a src_image is a 2D image object and \a src_origin[2] + * is not equal to 0 or \a region[2] is not equal to 1. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clEnqueueCopyImageToBuffer, + (cl_command_queue command_queue, cl_mem src_image, cl_mem dst_buffer, + const size_t* src_origin, const size_t* region, size_t dst_offset, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(src_image) || !is_valid(dst_buffer)) { + return CL_INVALID_MEM_OBJECT; + } + + amd::Image* srcImage = as_amd(src_image)->asImage(); + amd::Buffer* dstBuffer = as_amd(dst_buffer)->asBuffer(); + if (srcImage == NULL || dstBuffer == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != srcImage->getContext() || + hostQueue.context() != dstBuffer->getContext()) { + return CL_INVALID_CONTEXT; + } + + if (srcImage->getImageFormat().image_channel_order == CL_DEPTH_STENCIL) { + return CL_INVALID_OPERATION; + } + + amd::Coord3D srcOrigin(src_origin[0], src_origin[1], src_origin[2]); + amd::Coord3D dstOffset(dst_offset, 0, 0); + amd::Coord3D srcRegion(region[0], region[1], region[2]); + amd::Coord3D copySize( + region[0] * region[1] * region[2] * srcImage->getImageFormat().getElementSize(), 0, 0); + + ImageViewRef mip; + if (srcImage->getMipLevels() > 1) { + // Create a view for the specified mip level + mip = srcImage->createView(srcImage->getContext(), srcImage->getImageFormat(), NULL, + src_origin[srcImage->getDims()]); + if (mip() == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + // Reset the mip level value to 0, since a view was created + if (srcImage->getDims() < 3) { + srcOrigin.c[srcImage->getDims()] = 0; + } + srcImage = mip(); + } + + if (!srcImage->validateRegion(srcOrigin, srcRegion) || + !dstBuffer->validateRegion(dstOffset, copySize)) { + return CL_INVALID_VALUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::CopyMemoryCommand* command = + new amd::CopyMemoryCommand(hostQueue, CL_COMMAND_COPY_IMAGE_TO_BUFFER, eventWaitList, + *srcImage, *dstBuffer, srcOrigin, dstOffset, srcRegion); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Enqueue a command to copy a buffer object to an image object. + * + * \param command_queue must be a valid command-queue. The OpenCL context + * associated with \a command_queue, \a src_buffer and \a dst_image must be + * the same. + * + * \param src_buffer is a valid buffer object. + * + * \param dst_image is a valid image object. + * + * \param src_offset refers to the offset where to begin copying data in + * \a src_buffer. + * + * \param dst_origin defines the (x, y, z) offset in the image from where to + * copy. If \a dst_image is a 2D image object, the z value given by + * \a dst_origin[2] must be 0. + * + * \param region defines the (width, height, depth) of the 2D or 3D rectangle + * to copy. If dst_image is a 2D image object, the depth value given by + * \a region[2] must be 1. The size in bytes of the region to be copied from + * \a src_buffer referred to as \a src_cb is computed as + * width * height * depth * bytes/image element if \a dst_image is a 3D image + * object and is computed as width * height * bytes/image element if + * \a dst_image is a 2D image object. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, then + * this particular command does not wait on any event to complete. If + * \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. + * + * \param event returns an event object that identifies this particular copy + * command and can be used to query or queue a wait for this particular command + * to complete. \a event can be NULL in which case it will not be possible for + * the application to query the status of this command or queue a wait for + * this command to complete. clEnqueueBarrier can be used instead. + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise it + * returns one of the following errors: + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with \a command_queue, + * \a src_buffer and \a dst_image are not the same. + * - CL_INVALID_MEM_OBJECT if \a src_buffer is not a valid buffer object or + * \a dst_image is not a valid image object. + * - CL_INVALID_VALUE if the 2D or 3D rectangular region specified by + * \a dst_origin and \a dst_origin + \a region refers to a region outside + * \a dst_image, or if the region specified by \a src_offset and + * \a src_offset + \a src_cb to a region outside \a src_buffer. + * - CL_INVALID_VALUE if \a dst_image is a 2D image object and \a dst_origin[2] + * is not equal to 0 or \a region[2] is not equal to 1. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in + * \a event_wait_list are not valid events. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clEnqueueCopyBufferToImage, + (cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_image, + size_t src_offset, const size_t* dst_origin, const size_t* region, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(src_buffer) || !is_valid(dst_image)) { + return CL_INVALID_MEM_OBJECT; + } + amd::Buffer* srcBuffer = as_amd(src_buffer)->asBuffer(); + amd::Image* dstImage = as_amd(dst_image)->asImage(); + if (srcBuffer == NULL || dstImage == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != srcBuffer->getContext() || + hostQueue.context() != dstImage->getContext()) { + return CL_INVALID_CONTEXT; + } + + if (dstImage->getImageFormat().image_channel_order == CL_DEPTH_STENCIL) { + return CL_INVALID_OPERATION; + } + + amd::Coord3D dstOrigin(dst_origin[0], dst_origin[1], dst_origin[2]); + amd::Coord3D srcOffset(src_offset, 0, 0); + amd::Coord3D dstRegion(region[0], region[1], region[2]); + amd::Coord3D copySize( + region[0] * region[1] * region[2] * dstImage->getImageFormat().getElementSize(), 0, 0); + + ImageViewRef mip; + if (dstImage->getMipLevels() > 1) { + // Create a view for the specified mip level + mip = dstImage->createView(dstImage->getContext(), dstImage->getImageFormat(), NULL, + dst_origin[dstImage->getDims()]); + if (mip() == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + // Reset the mip level value to 0, since a view was created + if (dstImage->getDims() < 3) { + dstOrigin.c[dstImage->getDims()] = 0; + } + dstImage = mip(); + } + + if (!srcBuffer->validateRegion(srcOffset, copySize) || + !dstImage->validateRegion(dstOrigin, dstRegion)) { + return CL_INVALID_VALUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::CopyMemoryCommand* command = + new amd::CopyMemoryCommand(hostQueue, CL_COMMAND_COPY_BUFFER_TO_IMAGE, eventWaitList, + *srcBuffer, *dstImage, srcOffset, dstOrigin, dstRegion); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_MapUnmap + * @{ + */ + +/*! \brief Enqueue a command to map a region of a buffer object into the + * host address. + * + * \param command_queue must be a valid command-queue. + * + * \param blocking_map indicates if the map operation is blocking or + * non-blocking. If \a blocking_map is CL_TRUE, clEnqueueMapBuffer does not + * return until the specified region in \a buffer can be mapped. If + * \a blocking_map is CL_FALSE i.e. map operation is non-blocking, the pointer + * to the mapped region returned by clEnqueueMapBuffer cannot be used until the + * map command has completed. The event argument returns an event object which + * can be used to query the execution status of the map command. When the map + * command is completed, the application can access the contents of the mapped + * region using the pointer returned by clEnqueueMapBuffer. + * + * \param map_flags is a bit-field and can be set to CL_MAP_READ to indicate + * that the region specified by (\a offset, \a cb) in the buffer object is + * being mapped for reading, and/or CL_MAP_WRITE to indicate that the region + * specified by (\a offset, \a cb) in the buffer object is being mapped for + * writing. + * + * \param buffer is a valid buffer object. The OpenCL context associated with + * \a command_queue and \a buffer must be the same. + * + * \param offset is the offset in bytes of the region in the buffer object + * that is being mapped + * + * \param cb is the size in bytes of the region in the buffer object that + * is being mapped. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, then + * this particular command does not wait on any event to complete. If + * \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. If + * \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. + * + * \param event returns an event object that identifies this particular + * command and can be used to query or queue a wait for this particular + * command to complete. \a event can be NULL in which case it will not be + * possible for the application to query the status of this command or queue + * a wait for this command to complete. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A pointer to the mapped region if buffer is a memory object + * created with clCreateBuffer and the region specified by (offset , cb) + * is a valid region in the buffer object and is successfully mapped into the + * host address space . The \a errcode_ret is set to CL_SUCCESS. + * A NULL pointer is returned otherwise with one of the following error values + * returned in \a errcode_ret: + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if context associated with \a command_queue and + * \a buffer are not the same. + * - CL_INVALID_MEM_OBJECT if \a buffer is not a valid buffer object. + * - CL_INVALID_OPERATION if buffer has been created with + * CL_MEM_HOST_WRITE_ONLY or CL_MEM_HOST_NO_ACCESS and CL_MAP_READ + * is set in map_flags or if buffer has been created with + * CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_NO_ACCESS and CL_MAP_WRITE or + * CL_MAP_WRITE_INVALIDATE_REGION is set in map_flags. + * - CL_INVALID_VALUE if region being mapped given by (\a offset, \a cb) is out + * of bounds or if values specified in \a map_flags are not valid. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in + * \a event_wait_list are not valid events. + * - CL_MEM_O BJECT_MAP_FAILURE if there is a failure to map the specified + * region in the host address space. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * The pointer returned maps a region starting at \a offset and is atleast + * \a cb bytes in size. The result of a memory access outside this region is + * undefined. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY_RET(void*, clEnqueueMapBuffer, + (cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_map, + cl_map_flags map_flags, size_t offset, size_t cb, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, + cl_event* event, cl_int* errcode_ret)) { + if (!is_valid(command_queue)) { + *not_null(errcode_ret) = CL_INVALID_COMMAND_QUEUE; + return NULL; + } + + if (!is_valid(buffer)) { + *not_null(errcode_ret) = CL_INVALID_MEM_OBJECT; + return NULL; + } + amd::Buffer* srcBuffer = as_amd(buffer)->asBuffer(); + if (srcBuffer == NULL) { + *not_null(errcode_ret) = CL_INVALID_MEM_OBJECT; + return NULL; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + *not_null(errcode_ret) = CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != srcBuffer->getContext()) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + return NULL; + } + + if ((srcBuffer->getMemFlags() & (CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS)) && + (map_flags & CL_MAP_READ)) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + return NULL; + } + + if ((srcBuffer->getMemFlags() & (CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)) && + (map_flags & (CL_MAP_WRITE | CL_MAP_WRITE_INVALIDATE_REGION))) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + return NULL; + } + + if (srcBuffer->getMemFlags() & CL_MEM_EXTERNAL_PHYSICAL_AMD) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + return NULL; + } + + amd::Coord3D srcOffset(offset); + amd::Coord3D srcSize(cb); + + if (!srcBuffer->validateRegion(srcOffset, srcSize)) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return NULL; + } + + // Wait for possible pending operations + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + *not_null(errcode_ret) = err; + return (void*)0; + } + + // Make sure we have memory for the command execution + device::Memory* mem = srcBuffer->getDeviceMemory(hostQueue.device()); + if (NULL == mem) { + LogPrintfError("Can't allocate memory size - 0x%08X bytes!", srcBuffer->getSize()); + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + return NULL; + } + // Attempt to allocate the map target now (whether blocking or non-blocking) + void* mapPtr = mem->allocMapTarget(srcOffset, srcSize, map_flags); + if (NULL == mapPtr) { + *not_null(errcode_ret) = CL_MAP_FAILURE; + return NULL; + } + + // Allocate a map command for the queue thread + amd::MapMemoryCommand* command = new amd::MapMemoryCommand( + hostQueue, CL_COMMAND_MAP_BUFFER, eventWaitList, *srcBuffer, map_flags, + blocking_map ? true : false, srcOffset, srcSize, nullptr, nullptr, mapPtr); + if (command == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return NULL; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + return NULL; + } + + if (srcBuffer->getMemFlags() & CL_MEM_USE_PERSISTENT_MEM_AMD) { + // [Windows VidMM restriction] + // Runtime can't map persistent memory if it's still busy or + // even wasn't submitted to HW from the worker thread yet + hostQueue.finish(); + } + + // Send the map command for processing + command->enqueue(); + + // A blocking map has to wait for completion + if (blocking_map) { + command->awaitCompletion(); + } + + // Save the command event if applicaiton has requested it + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + *not_null(errcode_ret) = CL_SUCCESS; + srcBuffer->incMapCount(); + return mapPtr; +} +RUNTIME_EXIT + +/*! \brief Enqueue a command to map a region in an image object given into + * the host address. + * + * \param command_queue must be a valid command-queue. + * + * \param image is a valid image object. The OpenCL context associated with + * \a command_queue and \a image must be the same. + * + * \param blocking_map indicates if the map operation is blocking or + * non-blocking. If \a blocking_map is CL_TRUE, clEnqueueMapImage does not + * return until the specified region in image is mapped. If \a blocking_map is + * CL_FALSE i.e. map operation is non-blocking, the pointer to the mapped + * region returned by clEnqueueMapImage cannot be used until the map command + * has completed. The event argument returns an event object which can be used + * to query the execution status of the map command. When the map command is + * completed, the application can access the contents of the mapped region + * using the pointer returned by clEnqueueMapImage. + * + * \param map_flags is a bit-field and can be set to CL_MAP_READ to indicate + * that the region specified by (\a origin, \a region) in the image object is + * being mapped for reading, and/or CL_MAP_WRITE to indicate that the region + * specified by (\a origin, \a region) in the image object is being mapped for + * writing. + * + * \param origin defines the (x, y, z) offset in pixels in the image or (x, y) + * offset and the image index in the image array. If image is a 2D image + * object, origin[2] must be 0. If image is a 1D image or 1D image buffer + * object, origin[1] and origin[2] must be 0. If image is a 1D image array + * object, origin[2] must be 0. If image is a 1D image array object, origin[1] + * describes the image index in the 1D image array. If image is a 2D image + * array object, origin[2] describes the image index in the 2D image array. + * + * \param region defines the (width, height, depth) in pixels of the 1D, 2D or + * 3D rectangle or the (width, height) in pixels in pixels of the 1D or 2D + * rectangle and the image index of an image array. If image is a 2D image + * object, region[2] must be 1. If image is a 1D image or 1D image buffer + * object, region[1] and region[2] must be 1. If image is a 1D image array + * object, region[1] and region[2] must be 1. If image is a 2D image array + * object, region[2] must be 1. + * + * \param origin define the (x, y, z) offset of the 2D or 3D rectangle region + * that is to be mapped. If image is a 2D image object, the z value given by + * \a origin[2] must be 0. + * + * \param region define the (width, height, depth) of the 2D or 3D rectangle + * region that is to be mapped. If image is a 2D image object, the depth value + * given by \a region[2] must be 1. + * + * \param image_row_pitch returns the scan-line pitch in bytes for the mapped + * region. This must be a non- NULL value. + * + * \param image_slice_pitch returns the size in bytes of each 2D slice for the + * mapped region. For a 2D image this argument is ignored. For a 3D image this + * must be a non-NULL value. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before + * clEnqueueMapImage can be executed. If \a event_wait_list is NULL, then + * clEnqueueMapImage does not wait on any event to complete. If + * \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. If + * \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. + * + * \param event returns an event object that identifies this particular command + * and can be used to query or queue a wait for this particular command to + * complete. \a event can be NULL in which case it will not be possible for the + * application to query the status of this command or queue a wait for this + * command to complete + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A pointer to the mapped region if image is a memory object + * created with clCreateImage {2D|3D}, and the 2D or 3D rectangle specified + * by origin and region is a valid region in the image object and can be + * mapped into the host address space. + * The \a errcode_ret is set to CL_SUCCESS. A NULL pointer is returned + * otherwise with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if context associated with \a command_queue and + * \a image are not the same. + * - CL_INVALID_MEM_OBJECT if \a image is not a valid image object. + * - CL_INVALID_VALUE if region being mapped given by + * (\a origin, \a origin + \a region) is out of bounds or if values + * specified in \a map_flags are not valid. + * - CL_INVALID_VALUE if values in origin and region do not follow rules + * described in the argument description for origin and region. + * - CL_INVALID_VALUE if \a image is a 2D image object and \a origin[2] is not + * equal to 0 or \a region[2] is not equal to 1. + * - CL_INVALID_VALUE if \a image_row_pitch is NULL. + * - CL_INVALID_VALUE if \a image is a 3D image object and \a image_slice_pitch + * is NULL. + * - CL_INVALID_IMAGE_FORMAT if image format (image channel order and data + * type) for image are not supported by device associated with queue. + * - CL_INVALID_OPERATION if buffer has been created with + * CL_MEM_HOST_WRITE_ONLY or CL_MEM_HOST_NO_ACCESS and CL_MAP_READ + * is set in map_flags or if buffer has been created with + * CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_NO_ACCESS and CL_MAP_WRITE or + * CL_MAP_WRITE_INVALIDATE_REGION is set in map_flags. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_MEM_OBJECT_MAP_FAILURE if there is a failure to map the specified + * region in the host address space. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * The pointer returned maps a 2D or 3D region starting at origin and is + * at least (\a image_row_pitch * \a region[1] + \a region[0]) pixels in size + * for a 2D image, and is at least (\a image_slice_pitch * \a region[2] + + * \a image_row_pitch * \a region[1] + \a region[0]) pixels in size for a 3D + * image. The result of a memory access outside this region is undefined. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY_RET(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)) { + if (!is_valid(command_queue)) { + *not_null(errcode_ret) = CL_INVALID_COMMAND_QUEUE; + return NULL; + } + + if (!is_valid(image)) { + *not_null(errcode_ret) = CL_INVALID_MEM_OBJECT; + return NULL; + } + amd::Image* srcImage = as_amd(image)->asImage(); + if (srcImage == NULL) { + *not_null(errcode_ret) = CL_INVALID_MEM_OBJECT; + return NULL; + } + + if (srcImage->getImageFormat().image_channel_order == CL_DEPTH_STENCIL) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + return NULL; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + *not_null(errcode_ret) = CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != srcImage->getContext()) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + return NULL; + } + + if ((srcImage->getMemFlags() & (CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS)) && + (map_flags & CL_MAP_READ)) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + return NULL; + } + + if ((srcImage->getMemFlags() & (CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)) && + (map_flags & (CL_MAP_WRITE | CL_MAP_WRITE_INVALIDATE_REGION))) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + return NULL; + } + + if ((srcImage->getDims() == 1) && ((region[1] != 1) || (region[2] != 1))) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return NULL; + } + + if ((srcImage->getDims() == 2) && (region[2] != 1)) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return NULL; + } + + amd::Coord3D srcOrigin(origin[0], origin[1], origin[2]); + amd::Coord3D srcRegion(region[0], region[1], region[2]); + + ImageViewRef mip; + if (srcImage->getMipLevels() > 1) { + // Create a view for the specified mip level + mip = srcImage->createView(srcImage->getContext(), srcImage->getImageFormat(), hostQueue.vdev(), + origin[srcImage->getDims()]); + if (mip() == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return NULL; + } + // Reset the mip level value to 0, since a view was created + if (srcImage->getDims() < 3) { + srcOrigin.c[srcImage->getDims()] = 0; + } + srcImage->incMapCount(); + srcImage = mip(); + // Retain this view until unmap is done + srcImage->retain(); + } + + if (!srcImage->validateRegion(srcOrigin, srcRegion)) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return NULL; + } + + // Wait for possible pending operations + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + *not_null(errcode_ret) = err; + return (void*)0; + } + + // Make sure we have memory for the command execution + device::Memory* mem = srcImage->getDeviceMemory(hostQueue.device()); + if (NULL == mem) { + LogPrintfError("Can't allocate memory size - 0x%08X bytes!", srcImage->getSize()); + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + return NULL; + } + // Attempt to allocate the map target now (whether blocking or non-blocking) + void* mapPtr = mem->allocMapTarget(srcOrigin, srcRegion, map_flags, + image_row_pitch, image_slice_pitch); + if (NULL == mapPtr) { + *not_null(errcode_ret) = CL_MAP_FAILURE; + return NULL; + } + + // Allocate a map command for the queue thread + amd::MapMemoryCommand* command = new amd::MapMemoryCommand( + hostQueue, CL_COMMAND_MAP_IMAGE, eventWaitList, *srcImage, map_flags, + blocking_map ? true : false, srcOrigin, srcRegion, nullptr, nullptr, mapPtr); + if (command == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return NULL; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + return NULL; + } + + if (srcImage->getMemFlags() & CL_MEM_USE_PERSISTENT_MEM_AMD) { + // [Windows VidMM restriction] + // Runtime can't map persistent memory if it's still busy or + // even wasn't submitted to HW from the worker thread yet + hostQueue.finish(); + } + + // Send the map command for processing + command->enqueue(); + + // A blocking map has to wait for completion + if (blocking_map) { + command->awaitCompletion(); + } + + // Save the command event if applicaiton has requested it + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + *not_null(errcode_ret) = CL_SUCCESS; + srcImage->incMapCount(); + + return mapPtr; +} +RUNTIME_EXIT + +/*! \brief Enqueue a command to unmap a previously mapped region of a memory i + * object. + * + * Reads or writes from the host using the pointer returned by + * clEnqueueMapBuffer or clEnqueueMapImage are considered to be complete. + * + * \param command_queue must be a valid command-queue. + * + * \param memobj is a valid memory object. The OpenCL context associated with + * \a command_queue and \a memobj must be the same. + * + * \param mapped_ptr is the host address returned by a previous call to + * clEnqueueMapBuffer or clEnqueueMapImage for \a memobj. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before + * clEnqueueUnmapMemObject can be executed. If \a event_wait_list is NULL, + * then clEnqueueUnmapMemObject does not wait on any event to complete. If + * \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. If + * \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. + * + * \param event returns an event object that identifies this particular command + * and can be used to query or queue a wait for this particular command to + * complete. \a event can be NULL in which case it will not be possible for the + * application to query the status of this command or queue a wait for this + * command to complete. clEnqueueBarrier can be used instead. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue + * - CL_INVALID_MEM_OBJECT if \a memobj is not a valid memory object. + * - CL_INVALID_VALUE if \a mapped_ptr is not a valid pointer returned by + * clEnqueueMapBuffer or clEnqueueMapImage for \a memobj. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or if \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * - CL_INVALID_CONTEXT if context associated with \a command_queue and + * \a memobj are not the same. + * + * clEnqueueMapBuffer and clEnqueueMapImage increments the mapped count of the + * memory object. Multiple calls to clEnqueueMapBuffer or clEnqueueMapImage on + * the same memory object will increment this mapped count by appropriate number + * of calls. clEnqueueUnmapMemObject decrements the mapped count of the memory + * object. clEnqueueMapBuffer and clEnqueueMapImage act as synchronization + * points for a region of the memory object being mapped. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(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)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(memobj)) { + return CL_INVALID_MEM_OBJECT; + } + + amd::Memory* amdMemory = as_amd(memobj); + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != amdMemory->getContext()) { + return CL_INVALID_CONTEXT; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::UnmapMemoryCommand* command = new amd::UnmapMemoryCommand( + hostQueue, CL_COMMAND_UNMAP_MEM_OBJECT, eventWaitList, *amdMemory, mapped_ptr); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + device::Memory* mem = amdMemory->getDeviceMemory(hostQueue.device()); + bool blocking = false; + if (mem->isPersistentMapped()) { + blocking = true; + } + + amdMemory->decMapCount(); + command->enqueue(); + + if (blocking) { + LogInfo("blocking wait in unmapping function"); + command->awaitCompletion(); + } + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_MemObjQuery + * @{ + */ + +/*! \brief Get information that is common to all memory objects (buffer and + * image objects) + * + * \param memobj specifies the memory object being queried. + * + * \param param_name specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result being + * queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data being + * queried by \a param_value. If \a param_value_size_ret is NULL, it is + * ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_VALUE if \a param_name is not valid, or if size in bytes + * specified by \a param_value_size is < size of return type. + * - CL_INVALID_MEM_OBJECT if \a memobj is a not a valid memory object. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clGetMemObjectInfo, + (cl_mem memobj, cl_mem_info param_name, size_t param_value_size, void* param_value, + size_t* param_value_size_ret)) { + if (!is_valid(memobj)) { + return CL_INVALID_MEM_OBJECT; + } + + switch (param_name) { + case CL_MEM_TYPE: { + cl_mem_object_type type = as_amd(memobj)->getType(); + return amd::clGetInfo(type, param_value_size, param_value, param_value_size_ret); + } + case CL_MEM_FLAGS: { + cl_mem_flags flags = as_amd(memobj)->getMemFlags(); + return amd::clGetInfo(flags, param_value_size, param_value, param_value_size_ret); + } + case CL_MEM_SIZE: { + size_t size = as_amd(memobj)->getSize(); + return amd::clGetInfo(size, param_value_size, param_value, param_value_size_ret); + } + case CL_MEM_HOST_PTR: { + amd::Memory* memory = as_amd(memobj); + const void* hostPtr = + (memory->getMemFlags() & CL_MEM_USE_HOST_PTR) ? memory->getHostMem() : NULL; + return amd::clGetInfo(hostPtr, param_value_size, param_value, param_value_size_ret); + } + case CL_MEM_MAP_COUNT: { + cl_uint count = as_amd(memobj)->mapCount(); + return amd::clGetInfo(count, param_value_size, param_value, param_value_size_ret); + } + case CL_MEM_REFERENCE_COUNT: { + cl_uint count = as_amd(memobj)->referenceCount(); + return amd::clGetInfo(count, param_value_size, param_value, param_value_size_ret); + } + case CL_MEM_CONTEXT: { + cl_context context = as_cl(&as_amd(memobj)->getContext()); + return amd::clGetInfo(context, param_value_size, param_value, param_value_size_ret); + } + case CL_MEM_ASSOCIATED_MEMOBJECT: { + amd::Memory* amdParent = as_amd(memobj)->parent(); + if ((NULL != amdParent) && (NULL != amdParent->getSvmPtr()) && + (NULL == amdParent->parent())) { + amdParent = NULL; + } + cl_mem parent = as_cl(amdParent); + return amd::clGetInfo(parent, param_value_size, param_value, param_value_size_ret); + } + case CL_MEM_OFFSET: { + size_t mem_offset = as_amd(memobj)->getOrigin(); + return amd::clGetInfo(mem_offset, param_value_size, param_value, param_value_size_ret); + } + case CL_MEM_USES_SVM_POINTER: { + cl_bool usesSvmPointer = as_amd(memobj)->usesSvmPointer(); + return amd::clGetInfo(usesSvmPointer, param_value_size, param_value, param_value_size_ret); + } +#ifdef _WIN32 + case CL_MEM_D3D10_RESOURCE_KHR: { + ID3D10Resource* pRes; + + amd::InteropObject* interop = ((amd::Memory*)as_amd(memobj))->getInteropObj(); + if (interop) { + amd::D3D10Object* d3d10obj = interop->asD3D10Object(); + if (d3d10obj) { + pRes = d3d10obj->getD3D10ResOrig(); + if (!pRes) { + pRes = d3d10obj->getD3D10Resource(); + } + } + return amd::clGetInfo(pRes, param_value_size, param_value, param_value_size_ret); + } + break; + } + case CL_MEM_D3D11_RESOURCE_KHR: { + ID3D11Resource* pRes; + + amd::InteropObject* interop = ((amd::Memory*)as_amd(memobj))->getInteropObj(); + if (interop) { + amd::D3D11Object* d3d11obj = interop->asD3D11Object(); + if (d3d11obj) { + pRes = d3d11obj->getD3D11ResOrig(); + if (!pRes) { + pRes = d3d11obj->getD3D11Resource(); + } + } + return amd::clGetInfo(pRes, param_value_size, param_value, param_value_size_ret); + } + break; + } + case CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR: { + amd::InteropObject* interop = ((amd::Memory*)as_amd(memobj))->getInteropObj(); + if (interop) { + amd::D3D9Object* d3d9obj = interop->asD3D9Object(); + if (d3d9obj) + return amd::clGetInfo(d3d9obj->getSurfInfo(), param_value_size, param_value, + param_value_size_ret); + else + return CL_INVALID_MEM_OBJECT; + } else + return CL_INVALID_MEM_OBJECT; + break; + } + case CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR: { + cl_dx9_media_adapter_type_khr adapterType; + + amd::InteropObject* interop = ((amd::Memory*)as_amd(memobj))->getInteropObj(); + if (interop) { + amd::D3D9Object* d3d9obj = interop->asD3D9Object(); + if (d3d9obj) { + adapterType = d3d9obj->getAdapterType(); + } + return amd::clGetInfo(adapterType, param_value_size, param_value, param_value_size_ret); + } + break; + } +#endif //_WIN32 + default: + break; + } + + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +/*! \brief Get information specific to an image object. + * + * \param obj specifies the image object being queried. + * + * \param param_name specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result being + * queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data being + * queried by \a param_value. If \a param_value_size_ret is NULL, it is + * ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully + * - CL_INVALID_VALUE if \a param_name is not valid, or if size in bytes + * specified by \a param_value_size is < size of return type and + * \a param_value is not NULL. + * - CL_INVALID_MEM_OBJECT if \a image is a not a valid image object. + * + * \version 1.2r09 + */ +RUNTIME_ENTRY(cl_int, clGetImageInfo, + (cl_mem memobj, cl_image_info param_name, size_t param_value_size, void* param_value, + size_t* param_value_size_ret)) { + if (!is_valid(memobj)) { + return CL_INVALID_MEM_OBJECT; + } + amd::Image* image = as_amd(memobj)->asImage(); + if (image == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + switch (param_name) { + case CL_IMAGE_FORMAT: { + cl_image_format format = image->getImageFormat(); + return amd::clGetInfo(format, param_value_size, param_value, param_value_size_ret); + } + case CL_IMAGE_ELEMENT_SIZE: { + size_t elementSize = image->getImageFormat().getElementSize(); + return amd::clGetInfo(elementSize, param_value_size, param_value, param_value_size_ret); + } + case CL_IMAGE_ROW_PITCH: { + size_t rowPitch = image->getRowPitch(); + return amd::clGetInfo(rowPitch, param_value_size, param_value, param_value_size_ret); + } + case CL_IMAGE_SLICE_PITCH: { + size_t slicePitch = image->getSlicePitch(); + return amd::clGetInfo(slicePitch, param_value_size, param_value, param_value_size_ret); + } + case CL_IMAGE_WIDTH: { + size_t width = image->getWidth(); + return amd::clGetInfo(width, param_value_size, param_value, param_value_size_ret); + } + case CL_IMAGE_HEIGHT: { + size_t height = image->getHeight(); + if ((image->getType() == CL_MEM_OBJECT_IMAGE1D) || + (image->getType() == CL_MEM_OBJECT_IMAGE1D_ARRAY) || + (image->getType() == CL_MEM_OBJECT_IMAGE1D_BUFFER)) { + height = 0; + } + return amd::clGetInfo(height, param_value_size, param_value, param_value_size_ret); + } + case CL_IMAGE_DEPTH: { + size_t depth = image->getDepth(); + if ((image->getType() == CL_MEM_OBJECT_IMAGE1D_BUFFER) || + (image->getType() == CL_MEM_OBJECT_IMAGE1D_ARRAY) || + (image->getType() == CL_MEM_OBJECT_IMAGE2D_ARRAY) || + (image->getType() == CL_MEM_OBJECT_IMAGE1D) || + (image->getType() == CL_MEM_OBJECT_IMAGE2D)) { + depth = 0; + } + return amd::clGetInfo(depth, param_value_size, param_value, param_value_size_ret); + } + case CL_IMAGE_ARRAY_SIZE: { + size_t arraySize = 0; + if (image->getType() == CL_MEM_OBJECT_IMAGE1D_ARRAY) { + arraySize = image->getHeight(); + } else if (image->getType() == CL_MEM_OBJECT_IMAGE2D_ARRAY) { + arraySize = image->getDepth(); + } + return amd::clGetInfo(arraySize, param_value_size, param_value, param_value_size_ret); + } + case CL_IMAGE_BUFFER: { + cl_mem buffer = 0; + amd::Memory* parent = image->parent(); + while (parent && (parent->asBuffer() == NULL)) { + parent = parent->parent(); + } + buffer = as_cl(parent); + return amd::clGetInfo(buffer, param_value_size, param_value, param_value_size_ret); + } + case CL_IMAGE_NUM_MIP_LEVELS: { + cl_uint numMipLevels = image->getMipLevels(); + return amd::clGetInfo(numMipLevels, param_value_size, param_value, param_value_size_ret); + } + case CL_IMAGE_NUM_SAMPLES: { + cl_uint numSamples = 0; + return amd::clGetInfo(numSamples, param_value_size, param_value, param_value_size_ret); + } + case CL_IMAGE_BYTE_PITCH_AMD: { + size_t bytePitch = image->getBytePitch(); + return amd::clGetInfo(bytePitch, param_value_size, param_value, param_value_size_ret); + } +#ifdef _WIN32 + case CL_IMAGE_D3D10_SUBRESOURCE_KHR: { + amd::InteropObject* interop = ((amd::Memory*)as_amd(memobj))->getInteropObj(); + if (!interop) { + return CL_INVALID_MEM_OBJECT; + } + amd::D3D10Object* d3d10obj = interop->asD3D10Object(); + if (!d3d10obj) { + return CL_INVALID_MEM_OBJECT; + } + UINT subresource = d3d10obj->getSubresource(); + return amd::clGetInfo(subresource, param_value_size, param_value, param_value_size_ret); + } + case CL_IMAGE_D3D11_SUBRESOURCE_KHR: { + amd::InteropObject* interop = ((amd::Memory*)as_amd(memobj))->getInteropObj(); + if (!interop) { + return CL_INVALID_MEM_OBJECT; + } + amd::D3D11Object* d3d11obj = interop->asD3D11Object(); + if (!d3d11obj) { + return CL_INVALID_MEM_OBJECT; + } + UINT subresource = d3d11obj->getSubresource(); + return amd::clGetInfo(subresource, param_value_size, param_value, param_value_size_ret); + } + case CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR: { + amd::InteropObject* interop = ((amd::Memory*)as_amd(memobj))->getInteropObj(); + if (!interop) { + return CL_INVALID_MEM_OBJECT; + } + amd::D3D9Object* d3d9obj = interop->asD3D9Object(); + if (!d3d9obj) { + return CL_INVALID_MEM_OBJECT; + } + return amd::clGetInfo(d3d9obj->getSurfInfo(), param_value_size, param_value, + param_value_size_ret); + } + case CL_IMAGE_DX9_MEDIA_PLANE_KHR: { + amd::InteropObject* interop = ((amd::Memory*)as_amd(memobj))->getInteropObj(); + if (!interop) { + return CL_INVALID_MEM_OBJECT; + } + amd::D3D9Object* d3d9obj = interop->asD3D9Object(); + if (!d3d9obj) { + return CL_INVALID_MEM_OBJECT; + } + cl_uint plane = d3d9obj->getPlane(); + return amd::clGetInfo(plane, param_value_size, param_value, param_value_size_ret); + } +#endif //_WIN32 + default: + break; + } + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +/*! \brief creates a 1D image, 1D image buffer, 1D image array, 2D image, + * 2D image array and 3D image object + * + * \param context is a valid OpenCL context on which the image object is + * to be created. + * + * \param flags is a bit-field that is used to specify allocation and usage + * information about the image memory object being created and is described + * in table 5.3. If value specified for flags is 0, the default is used which + * is CL_MEM_READ_WRITE. + * + * \param image_format is a pointer to a structure that describes format + * properties of the image to be allocated. Refer to section 5.3.1.1 for + * a detailed description of the image format descriptor. + * + * \param image_desc is a pointer to a structure that describes type and + * dimensions of the image to be allocated. Refer to section 5.3.1.2 for + * a detailed description of the image descriptor. + * + * \param host_ptr is a pointer to the image data that may already be + * allocated by the application. Refer to table below for a description of + * how large the buffer that host_ptr points to must be. + * CL_MEM_OBJECT_IMAGE1D >= image_row_pitch + * CL_MEM_OBJECT_IMAGE1D_BUFFER >= image_row_pitch + * CL_MEM_OBJECT_IMAGE2D >= image_row_pitch * image_height + * CL_MEM_OBJECT_IMAGE3D >= image_slice_pitch * image_depth + * CL_MEM_OBJECT_IMAGE1D_ARRAY >= image_slice_pitch * image_array_size + * CL_MEM_OBJECT_IMAGE2D_ARRAY >= image_slice_pitch * image_array_size + * For a 3D image or 2D image array, the image data specified by \a host_ptr + * is stored as a linear sequence of adjacent 2D image slices or 2D images + * respectively. Each 2D image is a linear sequence of adjacent scanlines. + * Each scanline is a linear sequence of image elements. + * For a 2D image array, the image data specified by \a host_ptr is stored + * as a linear sequence of adjacent scanlines. Each scanline is a linear + * sequence of image elements. + * For a 1D image array, the image data specified by \a host_ptr is stored + * as a linear sequence of adjacent 1D images respectively. Each 1D image + * or 1D image buffer is a single scanline which is a linear sequence of + * adjacent elements. + * + * \param errcode_ret will return an appropriate error code. + * If \a errcode_ret is NULL, no error code is returned. + * + * \return a valid non-zero image object created and the \a errcode_ret is + * set to CL_SUCCESS if the image object is created successfully. Otherwise, + * it returns a NULL value with one of the following error values + * returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a context is not a valid context. + * - CL_INVALID_VALUE if values specified in \a flags are not valid. + * - CL_INVALID_IMAGE_FORMAT_DESCRIPTOR if values specified in \a image_format + * are not valid or if \a image_format is NULL. + * - CL_INVALID_IMAGE_DESCRIPTOR if values specified in \a image_desc are + * not valid or if \a image_desc is NULL. + * - CL_INVALID_HOST_PTR if \a host_ptr in \a image_desc is NULL and + * CL_MEM_USE_HOST_PTR or CL_MEM_COPY_HOST_PTR are set in \a flags or + * if \a host_ptr is not NULL, but CL_MEM_COPY_HOST_PTR or + * CL_MEM_USE_HOST_PTR are not set in \a flags. + * - CL_INVALID_VALUE if a 1D image buffer is being created and + * the buffer object was created with CL_MEM_WRITE_ONLY and \a flags + * specifies CL_MEM_READ_WRITE or CL_MEM_READ_ONLY, or if the buffer object + * was created with CL_MEM_READ_ONLY and \a flags specifies + * CL_MEM_READ_WRITE or CL_MEM_WRITE_ONLY, or if \a flags specifies + * CL_MEM_USE_HOST_PTR or CL_MEM_ALLOC_HOST_PTR or CL_MEM_COPY_HOST_PTR. + * - CL_IMAGE_FORMAT_NOT_SUPPORTED if the image_format is not supported. + * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory + * for image object. + * - CL_INVALID_OPERATION if there are no devices in \a context that support + * images + * - CL_DEVICE_IMAGE_SUPPORT specified in table 4.3 is CL_FALSE). + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY_RET(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)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter: context"); + return (cl_mem)0; + } + // check flags for validity + if (!validateFlags(flags)) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter: flags"); + return (cl_mem)0; + } + // check format + if (image_format == NULL) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("invalid parameter: image_format"); + return (cl_mem)0; + } + + const amd::Image::Format imageFormat(*image_format); + if (!imageFormat.isValid()) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("invalid parameter: image_format"); + return (cl_mem)0; + } + + amd::Context& amdContext = *as_amd(context); + + if (!imageFormat.isSupported(amdContext, image_desc->image_type)) { + *not_null(errcode_ret) = CL_IMAGE_FORMAT_NOT_SUPPORTED; + LogWarning("invalid parameter: image_format"); + return (cl_mem)0; + } + + // check host_ptr consistency + if (host_ptr == NULL) { + if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) { + *not_null(errcode_ret) = CL_INVALID_HOST_PTR; + LogWarning("invalid parameter: host_ptr"); + return (cl_mem)0; + } + } else { + if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) { + *not_null(errcode_ret) = CL_INVALID_HOST_PTR; + LogWarning("invalid parameter: host_ptr"); + return (cl_mem)0; + } + } + + const std::vector& devices = as_amd(context)->devices(); + bool supportPass = false; + for (auto& dev : devices) { + if (dev->info().imageSupport_) { + supportPass = true; + break; + } + } + + if (!supportPass) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + LogWarning("there are no devices in context to support images"); + return (cl_mem)0; + } + + if (!amd::Image::validateDimensions(devices, image_desc->image_type, image_desc->image_width, + image_desc->image_height, image_desc->image_depth, + image_desc->image_array_size)) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_SIZE; + LogWarning("invalid parameter: image dimensions exceeding max"); + return (cl_mem)0; + } + + size_t imageRowPitch = 0; + size_t imageSlicePitch = 0; + if (!validateImageDescriptor(devices, imageFormat, image_desc, host_ptr, imageRowPitch, + imageSlicePitch)) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_DESCRIPTOR; + LogWarning("invalid parameter: image_desc"); + return (cl_mem)0; + } + + // Validate mip level + if (image_desc->num_mip_levels != 0) { + size_t maxDim = std::max(image_desc->image_width, image_desc->image_height); + maxDim = std::max(maxDim, image_desc->image_depth); + uint mipLevels; + for (mipLevels = 0; maxDim > 0; maxDim >>= 1, mipLevels++) + ; + if (mipLevels < image_desc->num_mip_levels) { + *not_null(errcode_ret) = CL_INVALID_MIP_LEVEL; + LogWarning("Invalid mip level"); + return (cl_mem)0; + } + } + amd::Image* image = NULL; + + switch (image_desc->image_type) { + case CL_MEM_OBJECT_IMAGE1D: + image = new (amdContext) + amd::Image(amdContext, CL_MEM_OBJECT_IMAGE1D, flags, imageFormat, image_desc->image_width, + 1, 1, imageRowPitch, 0, image_desc->num_mip_levels); + break; + case CL_MEM_OBJECT_IMAGE2D: + if (image_desc->mem_object != NULL) { + amd::Buffer& buffer = *(as_amd(image_desc->mem_object)->asBuffer()); + if (&amdContext != &buffer.getContext()) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter: context"); + return (cl_mem)0; + } + + // host_ptr is not supported, the buffer object is used instead. + if ((flags & (CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR)) != 0) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter: flags"); + return (cl_mem)0; + } + + cl_uint pitchAlignment = 0; + for (unsigned int i = 0; i < devices.size(); ++i) { + if (pitchAlignment < devices[i]->info().imagePitchAlignment_) { + pitchAlignment = devices[i]->info().imagePitchAlignment_; + } + } + if ((imageRowPitch % pitchAlignment) != 0) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("invalid parameter: flags"); + return (cl_mem)0; + } + + image = new (amdContext) amd::Image( + buffer, CL_MEM_OBJECT_IMAGE2D, (flags != 0) ? flags : buffer.getMemFlags(), imageFormat, + image_desc->image_width, image_desc->image_height, 1, imageRowPitch, imageSlicePitch); + } else { + image = new (amdContext) amd::Image(amdContext, CL_MEM_OBJECT_IMAGE2D, flags, imageFormat, + image_desc->image_width, image_desc->image_height, 1, + imageRowPitch, 0, image_desc->num_mip_levels); + } + break; + case CL_MEM_OBJECT_IMAGE3D: + image = new (amdContext) + amd::Image(amdContext, CL_MEM_OBJECT_IMAGE3D, flags, imageFormat, image_desc->image_width, + image_desc->image_height, image_desc->image_depth, imageRowPitch, + imageSlicePitch, image_desc->num_mip_levels); + break; + case CL_MEM_OBJECT_IMAGE1D_BUFFER: { + amd::Buffer& buffer = *(as_amd(image_desc->mem_object)->asBuffer()); + if (&amdContext != &buffer.getContext()) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter: context"); + return (cl_mem)0; + } + + // host_ptr is not supported, the buffer object is used instead. + if ((flags & (CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR)) != 0) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter: flags"); + return (cl_mem)0; + } + + image = new (amdContext) amd::Image( + buffer, CL_MEM_OBJECT_IMAGE1D_BUFFER, (flags != 0) ? flags : buffer.getMemFlags(), + imageFormat, image_desc->image_width, 1, 1, imageRowPitch, imageSlicePitch); + } break; + case CL_MEM_OBJECT_IMAGE1D_ARRAY: + image = + new (amdContext) amd::Image(amdContext, CL_MEM_OBJECT_IMAGE1D_ARRAY, flags, imageFormat, + image_desc->image_width, image_desc->image_array_size, 1, + imageRowPitch, imageSlicePitch, image_desc->num_mip_levels); + break; + case CL_MEM_OBJECT_IMAGE2D_ARRAY: + image = new (amdContext) amd::Image( + amdContext, CL_MEM_OBJECT_IMAGE2D_ARRAY, flags, imageFormat, image_desc->image_width, + image_desc->image_height, image_desc->image_array_size, imageRowPitch, imageSlicePitch, + image_desc->num_mip_levels); + break; + default: { + *not_null(errcode_ret) = CL_INVALID_IMAGE_DESCRIPTOR; + LogWarning("invalid parameter: image_desc"); + return reinterpret_cast(image); + } break; + } + + if (image == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + LogWarning("cannot allocate resources"); + return (cl_mem)0; + } + + if (!image->create(host_ptr)) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + image->release(); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return (cl_mem)as_cl(image); +} +RUNTIME_EXIT + +/*! \brief Enqueues a command to fill a buffer object with + * a pattern of a given pattern size. + * + * \param command_queue refers to the command-queue in which + * the fill command will be queued. The OpenCL context associated with + * command_queue and buffer must be the same. + * + * \param buffer is a valid buffer object. + * + * \param pattern is a pointer to the data pattern of size pattern_size + * in bytes. pattern will be used to fill a region in buffer starting + * at offset and is cb bytes in size. The data pattern must be a scalar or + * vector integer or floating-point data type supported by OpenCL + * as described in sections 6.1.1 and 6.1.2. For example, if buffer is + * to be filled with a pattern of float4 values, then pattern will be + * a pointer to a cl_float4 value and pattern_size will be sizeof(cl_float4). + * The maximum value of pattern_size is the size of the largest integer or + * floating-point vector data type supported by the OpenCL device. + * + * \param offset is the location in bytes of the region being filled + * in buffer and must be a multiple of pattern_size. size is the size + * in bytes of region being filled in buffer and must be a multiple + * of pattern_size. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifes events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, + * then this particular command does not wait on any event to complete. + * If \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and a\ num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. The context associated with events in + * \a event_wait_list and \a command_queue must be the same. + * The memory associated with \a event_wait_list can be reused or + * freed after the function returns. + * + * \param event returns an event object that identifies this particular command + * and can be used to query or queue a wait for this particular command to + * complete. \a event can be NULL in which case it will not be possible for the + * application to query the status of this command or queue a wait for this + * command to complete. clEnqueueBarrierWithWaitList can be used instead. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_CONTEXT if context associated with \a command_queue and + * \a buffer are not the same or if the \a context associated with + * \a command_queue and \a events in \a event_wait_list are not the same. + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue + * - CL_INVALID_MEM_OBJECT if \a memobj is not a valid memory object. + * - CL_INVALID_VALUE if pattern is NULL or if pattern_size is 0 or if + * \a pattern_size is one of {1, 2, 4, 8, 16, 32, 64, 128}. + * - CL_INVALID_VALUE if \a offset or \a offset + \a size require accessing + * elements outside the \a buffer object respectively. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or if \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY(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)) { + amd::Buffer* fillBuffer; + + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(buffer)) { + return CL_INVALID_MEM_OBJECT; + } + + fillBuffer = as_amd(buffer)->asBuffer(); + if (fillBuffer == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + if ((pattern == NULL) || (pattern_size == 0) || + (pattern_size > amd::FillMemoryCommand::MaxFillPatterSize) || + ((pattern_size & (pattern_size - 1)) != 0)) { + return CL_INVALID_VALUE; + } + + // Offset must be a multiple of pattern_size + if ((offset % pattern_size) != 0) { + return CL_INVALID_VALUE; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != fillBuffer->getContext()) { + return CL_INVALID_CONTEXT; + } + + amd::Coord3D fillOffset(offset, 0, 0); + amd::Coord3D fillSize(size, 1, 1); + // surface takes [pitch, width, height] + amd::Coord3D surface(size, size, 1); + if (!fillBuffer->validateRegion(fillOffset, fillSize)) { + return CL_INVALID_VALUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::FillMemoryCommand* command = + new amd::FillMemoryCommand(hostQueue, CL_COMMAND_FILL_BUFFER, eventWaitList, *fillBuffer, + pattern, pattern_size, fillOffset, fillSize, surface); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief enqueues a command to fill an image object with + * a specified color. + * + * \param command_queue refers to the command-queue in which + * the fill command will be queued. The OpenCL context associated with + * command_queue and buffer must be the same. + * + * \param buffer is a valid buffer object. + * + * \param fill_color is the fill color. The fill color is a four + * component RGBA floating-point color value if the image channel data type + * is not an unnormalized signed and unsigned integer type, is a four + * component signed integer value if the image channel data type is + * an unnormalized signed integer type and is a four component unsigned + * integer value if the image channel data type is an unormalized + * unsigned integer type. The fill color will be converted to + * the appropriate image channel format and order associated with image + * as described in sections 6.11.13 and 8.3. + * + * \param origin defines the (x, y, z) offset in pixels in the image + * or (x, y) offset and the image index in the image array. If image is + * a 2D image object, origin[2] must be 0. If image is a 1D image or 1D + * image buffer object, origin[1] and origin[2] must be 0. If image is + * a 1D image array object, origin[2] must be 0. If image is a 1D image array + * object, origin[1] describes the image index in the 1D image array. + * If image is a 2D image array object, origin[2] describes the image index + * in the 2D image array. + * + * \param region defines the (width, height, depth) in pixels of + * the 1D, 2D or 3D rectangle or the (width, height) in pixels in pixels of + * the 1D or 2D rectangle and the image index of an image array. If image is + * a 2D image object, region[2] must be 1. If image is a 1D image or + * 1D image buffer object, region[1] and region[2] must be 1. If image is + * a 1D image array object, region[1] and region[2] must be 1. + * If image is a 2D image array object, region[2] must be 1. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifes events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, + * then this particular command does not wait on any event to complete. + * If \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and a\ num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. The context associated with events in + * \a event_wait_list and \a command_queue must be the same. + * The memory associated with \a event_wait_list can be reused or + * freed after the function returns. + * + * \param event returns an event object that identifies this particular command + * and can be used to query or queue a wait for this particular command to + * complete. \a event can be NULL in which case it will not be possible for + * the application to query the status of this command or queue a wait for this + * command to complete. clEnqueueBarrierWithWaitList can be used instead. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_CONTEXT if context associated with \a command_queue and + * \a buffer are not the same or if the \a context associated with + * \a command_queue and \a events in \a event_wait_list are not the same. + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue + * - CL_INVALID_MEM_OBJECT if \a memobj is not a valid memory object. + * - CL_INVALID_VALUE if fill_color is NULL. + * - CL_INVALID_VALUE if the region being filled as specified by origin and + * region is out of bounds. + * - CL_INVALID_VALUE if values in origin and region do not follow rules + * described in the argument description for origin and region. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or if \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_INVALID_IMAGE_SIZE if image dimensions (image width, height, specified + * or compute row + * - CL_INVALID_IMAGE_FORMAT if image format (image channel order and data type) + * for image are not supported by device associated with queue. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY(cl_int, clEnqueueFillImage, + (cl_command_queue command_queue, cl_mem image, const void* fill_color, + const size_t* origin, const size_t* region, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + amd::Image* fillImage; + + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(image)) { + return CL_INVALID_MEM_OBJECT; + } + + if (fill_color == NULL) { + return CL_INVALID_VALUE; + } + + fillImage = as_amd(image)->asImage(); + if (fillImage == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != fillImage->getContext()) { + return CL_INVALID_CONTEXT; + } + + if (fillImage->getImageFormat().image_channel_order == CL_DEPTH_STENCIL) { + return CL_INVALID_OPERATION; + } + + amd::Coord3D fillOrigin(origin[0], origin[1], origin[2]); + amd::Coord3D fillRegion(region[0], region[1], region[2]); + // surface takes [pitch, width, height] + amd::Coord3D surface(region[0], region[0], region[2]); + + ImageViewRef mip; + if (fillImage->getMipLevels() > 1) { + // Create a view for the specified mip level + mip = fillImage->createView(fillImage->getContext(), fillImage->getImageFormat(), nullptr, + origin[fillImage->getDims()]); + if (mip() == nullptr) { + return CL_OUT_OF_HOST_MEMORY; + } + // Reset the mip level value to 0, since a view was created + if (fillImage->getDims() < 3) { + fillOrigin.c[fillImage->getDims()] = 0; + } + fillImage = mip(); + } + + if (!fillImage->validateRegion(fillOrigin, fillRegion)) { + return CL_INVALID_VALUE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::FillMemoryCommand* command = new amd::FillMemoryCommand( + hostQueue, CL_COMMAND_FILL_IMAGE, eventWaitList, *fillImage, fill_color, + sizeof(cl_float4), // @note color size is always 16 bytes value + fillOrigin, fillRegion, surface); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Enqueues a command to indicate which device a set of memory objects + * should be associated with. Typically, memory objects are implicitly + * migrated to a device for which enqueued commands, using the memory object, + * are targeted. \a clEnqueueMigrateMemObjects allows this migration to be + * explicitly performed ahead of the dependent commands. This allows a user to + * preemptively change the association of a memory object, through regular + * command queue scheduling, in order to prepare for another upcoming + * command. This also permits an application to overlap the placement of + * memory objects with other unrelated operations before these memory objects + * are needed potentially hiding transfer latencies. Once the event, returned + * from \a clEnqueueMigrateMemObjects, has been marked \a CL_COMPLETE + * the memory objects specified in \a mem_objects have been successfully + * migrated to the device associated with \a command_queue. The migrated memory + * object shall remain resident on the device until another command is enqueued + * that either implicitly or explicitly migrates it away. + * \a clEnqueueMigrateMemObjects can also be used to direct the initial + * placement of a memory object, after creation, possibly avoiding the initial + * overhead of instantiating the object on the first enqueued command to use it. + * The user is responsible for managing the event dependencies, associated with + * this command, in order to avoid overlapping access to memory objects. + * Improperly specified event dependencies passed to + * \a clEnqueueMigrateMemObjects could result in undefined results. + * + * \param command_queue is a valid command-queue. The specified set of memory + * objects in \a mem_objects will be migrated to the OpenCL device associated + * with \a command_queue or to the host if the \a CL_MIGRATE_MEM_OBJECT_HOST + * has been specified. + * + * \param num_mem_objects is the number of memory objects specified in + * \a mem_objects. \a mem_objects is a pointer to a list of memory objects. + * + * \param flags is a bit-field that is used to specify migration options. + * The following table describes the possible values for flags. + * cl_mem_migration flags Description + * CL_MIGRATE_MEM_OBJECT_HOST This flag indicates that the specified set + * of memory objects are to be migrated to the + * host, regardless of the target command-queue. + * CL_MIGRATE_MEM_OBJECT_ This flag indicates that the contents of the set + * CONTENT_UNDEFINED of memory objects are undefined after migration. + * The specified set of memory objects are migrated + * to the device associated with \a command_queue + * without incurring + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifes events that need to complete before this + * particular command can be executed. If \a event_wait_list is NULL, + * then this particular command does not wait on any event to complete. + * If \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. + * If \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and a\ num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. The context associated with events in + * \a event_wait_list and \a command_queue must be the same. + * The memory associated with \a event_wait_list can be reused or + * freed after the function returns. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue + * - CL_INVALID_CONTEXT if the context associated with \a command_queue + * and memory objects in \a mem_objects are not the same or if the context + * associated with \a command_queue and events in \a event_wait_list + * are not the same. + * - CL_INVALID_MEM_OBJECT if any of the memory objects in \a mem_objects + * is not a valid memory object. + * - CL_INVALID_VALUE if \a num_mem_objects is zero or + * if \a mem_objects is NULL. + * - CL_INVALID_VALUE if flags is not 0 or any of the values described + * in the table above + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or if \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate + * memory for the specified set of memory objects in \a mem_objects. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host. + * + * \version 1.2r15 + */ +RUNTIME_ENTRY(cl_int, clEnqueueMigrateMemObjects, + (cl_command_queue command_queue, cl_uint num_mem_objects, const cl_mem* mem_objects, + cl_mem_migration_flags flags, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if ((num_mem_objects == 0) || (mem_objects == NULL)) { + return CL_INVALID_VALUE; + } + + if (flags & ~(CL_MIGRATE_MEM_OBJECT_HOST | CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED)) { + return CL_INVALID_VALUE; + } + + std::vector memObjects; + for (uint i = 0; i < num_mem_objects; ++i) { + if (!is_valid(mem_objects[i])) { + return CL_INVALID_MEM_OBJECT; + } + amd::Memory* memory = as_amd(mem_objects[i]); + if (hostQueue.context() != memory->getContext()) { + return CL_INVALID_CONTEXT; + } + memObjects.push_back(memory); + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::MigrateMemObjectsCommand* command = new amd::MigrateMemObjectsCommand( + hostQueue, CL_COMMAND_MIGRATE_MEM_OBJECTS, eventWaitList, memObjects, flags); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +RUNTIME_ENTRY_RET(cl_mem, clConvertImageAMD, + (cl_context context, cl_mem image, const cl_image_format* image_format, + cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter: context"); + return (cl_mem)0; + } + // check format + if (image_format == NULL) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("invalid parameter: image_format"); + return (cl_mem)0; + } + const amd::Image::Format imageFormat(*image_format); + if (!imageFormat.isValid()) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("invalid parameter: image_format"); + return (cl_mem)0; + } + + amd::Context& amdContext = *as_amd(context); + if (!imageFormat.isSupported(amdContext)) { + *not_null(errcode_ret) = CL_IMAGE_FORMAT_NOT_SUPPORTED; + LogWarning("invalid parameter: image_format"); + return (cl_mem)0; + } + amd::Image* amdImage = as_amd(image)->asImage(); + amd::Image* converted_image = amdImage->createView(amdContext, imageFormat, NULL); + + if (converted_image == NULL) { + *not_null(errcode_ret) = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + LogWarning("cannot allocate resources"); + return (cl_mem)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return (cl_mem)as_cl(converted_image); +} +RUNTIME_EXIT + +RUNTIME_ENTRY_RET(cl_mem, clCreateBufferFromImageAMD, + (cl_context context, cl_mem image, cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter: context"); + return (cl_mem)0; + } + + amd::Context& amdContext = *as_amd(context); + const std::vector& devices = amdContext.devices(); + bool supportPass = false; + for (auto& dev : devices) { + if (dev->info().bufferFromImageSupport_) { + supportPass = true; + break; + } + } + + if (!supportPass) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + LogWarning("there are no devices in context to support buffer from image"); + return (cl_mem)0; + } + + amd::Image* amdImage = as_amd(image)->asImage(); + if (!is_valid(image) || amdImage == NULL) { + *not_null(errcode_ret) = CL_INVALID_MEM_OBJECT; + return NULL; + } + + amd::Memory* mem = new (amdContext) amd::Buffer(*amdImage, 0, 0, amdImage->getSize()); + if (mem == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_mem)0; + } + + if (!mem->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + mem->release(); + return NULL; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return (cl_mem)as_cl(mem); +} +RUNTIME_EXIT + +/*! @} + * @} + * @} + */ diff --git a/opencl/amdocl/cl_p2p_amd.cpp b/opencl/amdocl/cl_p2p_amd.cpp new file mode 100644 index 0000000000..b59e8a3c6f --- /dev/null +++ b/opencl/amdocl/cl_p2p_amd.cpp @@ -0,0 +1,106 @@ +/* Copyright (c) 2015 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include + +#include "cl_p2p_amd.h" +#include "platform/object.hpp" + +RUNTIME_ENTRY(cl_int, clEnqueueCopyBufferP2PAMD, + (cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, + size_t src_offset, size_t dst_offset, size_t cb, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(src_buffer) || !is_valid(dst_buffer)) { + return CL_INVALID_MEM_OBJECT; + } + amd::Buffer* srcBuffer = as_amd(src_buffer)->asBuffer(); + amd::Buffer* dstBuffer = as_amd(dst_buffer)->asBuffer(); + if (srcBuffer == NULL || dstBuffer == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if ((hostQueue.context() != srcBuffer->getContext()) && + (hostQueue.context() != dstBuffer->getContext())) { + return CL_INVALID_CONTEXT; + } + + amd::Coord3D srcOffset(src_offset, 0, 0); + amd::Coord3D dstOffset(dst_offset, 0, 0); + amd::Coord3D size(cb, 1, 1); + + if (!srcBuffer->validateRegion(srcOffset, size) || !dstBuffer->validateRegion(dstOffset, size)) { + return CL_INVALID_VALUE; + } + + if (srcBuffer == dstBuffer && + ((src_offset <= dst_offset && dst_offset < src_offset + cb) || + (dst_offset <= src_offset && src_offset < dst_offset + cb))) { + return CL_MEM_COPY_OVERLAP; + } + + amd::Command::EventWaitList eventWaitList; + if ((num_events_in_wait_list == 0 && event_wait_list != NULL) || + (num_events_in_wait_list != 0 && event_wait_list == NULL)) { + return CL_INVALID_EVENT_WAIT_LIST; + } + + while (num_events_in_wait_list-- > 0) { + cl_event event = *event_wait_list++; + amd::Event* amdEvent = as_amd(event); + if (!is_valid(event)) { + return CL_INVALID_EVENT_WAIT_LIST; + } + eventWaitList.push_back(amdEvent); + } + + amd::CopyMemoryP2PCommand* command = + new amd::CopyMemoryP2PCommand(hostQueue, CL_COMMAND_COPY_BUFFER, eventWaitList, *srcBuffer, + *dstBuffer, srcOffset, dstOffset, size); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT diff --git a/opencl/amdocl/cl_p2p_amd.h b/opencl/amdocl/cl_p2p_amd.h new file mode 100644 index 0000000000..962df3d22e --- /dev/null +++ b/opencl/amdocl/cl_p2p_amd.h @@ -0,0 +1,39 @@ +/* Copyright (c) 2017 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef __CL_P2P_AMD_H +#define __CL_P2P_AMD_H + +#include "CL/cl_ext.h" + +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus*/ + +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueCopyBufferP2PAMD( + cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, + size_t src_offset, size_t dst_offset, size_t cb, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; + +#ifdef __cplusplus +} /*extern "C"*/ +#endif /*__cplusplus*/ + +#endif diff --git a/opencl/amdocl/cl_pipe.cpp b/opencl/amdocl/cl_pipe.cpp new file mode 100644 index 0000000000..b271910120 --- /dev/null +++ b/opencl/amdocl/cl_pipe.cpp @@ -0,0 +1,190 @@ +/* Copyright (c) 2013 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include "platform/memory.hpp" +#include "platform/context.hpp" +#include "platform/command.hpp" + +/*! \addtogroup API + * @{ + * + * \addtogroup CL_Pipes + * @{ + */ + +/*! \brief creates a pipe object. + * + * \param context is a valid OpenCL context used to create the pipe object. + * + * \param flags is a bit-field that is used to specify allocation and usage + * information such as the memory arena that should be used to allocate the pipe + * object and how it will be used. Only CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY, + * CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS can be specified when creating a + * pipe object. If value specified for flags is 0, the default is used which is + * CL_MEM_READ_WRITE. + * + * \param pipe_packet_size is the size in bytes of a pipe packet. + * + * \param pipe_max_packets specifies the pipe capacity by specifying the maximum + * number of packets the pipe can hold. + * + * \param properties specifies a list of properties for the pipe and their + * corresponding values. Each property name is immediately followed by the + * corresponding desired value. The list is terminated with 0. + * + * In OpenCL 2.0, properties must be NULL. + * + * \param errcode_ret will return an appropriate error code. + * If \a errcode_ret is NULL, no error code is returned. + * + * \return a valid non-zero pipe object and \a errcode_ret is set to CL_SUCCESS + * if the pipe object is created successfully. Otherwise, it returns a NULL + * value with one of the following error values returned in errcode_ret: + * - CL_INVALID_CONTEXT if context is not a valid context. + * - CL_INVALID_VALUE if values specified in flags are not as defined above. + * - CL_INVALID_VALUE if properties is not NULL. + * - CL_INVALID_PIPE_SIZE if pipe_packet_size is 0 or the pipe_packet_size + * exceeds CL_DEVICE_PIPE_MAX_PACKET_SIZE value for all devices in context + * or if pipe_max_packets is 0. + * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory + * for the pipe object. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 2.0r19 + */ +RUNTIME_ENTRY_RET(cl_mem, clCreatePipe, + (cl_context context, cl_mem_flags flags, cl_uint pipe_packet_size, + cl_uint pipe_max_packets, const cl_pipe_properties* properties, + cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + return NULL; + } + + // check flags for validity + cl_bitfield temp = + flags & (CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_HOST_NO_ACCESS); + + if (temp && + !(CL_MEM_READ_WRITE == temp || CL_MEM_WRITE_ONLY == temp || CL_MEM_READ_ONLY == temp || + CL_MEM_HOST_NO_ACCESS == temp)) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid parameter \"flags\""); + return (cl_mem)0; + } + + size_t size = sizeof(struct clk_pipe_t) + pipe_packet_size * pipe_max_packets; + + const std::vector& devices = as_amd(context)->devices(); + bool sizePass = false; + for (const auto& it : devices) { + if (it->info().maxMemAllocSize_ >= size) { + sizePass = true; + break; + } + } + + // check size + if (pipe_packet_size == 0 || pipe_max_packets == 0 || !sizePass) { + *not_null(errcode_ret) = CL_INVALID_PIPE_SIZE; + LogWarning("invalid parameter \"size = 0 or size > CL_DEVICE_PIPE_MAX_PACKET_SIZE\""); + return (cl_mem)0; + } + + amd::Context& amdContext = *as_amd(context); + amd::Memory* mem = new (amdContext) + amd::Pipe(amdContext, flags, size, (size_t)pipe_packet_size, (size_t)pipe_max_packets); + if (mem == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_mem)0; + } + + if (!mem->create()) { + *not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE; + mem->release(); + return NULL; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(mem); +} +RUNTIME_EXIT + +/*! \brief Get information specific to a pipe object created with clCreatePipe. + * + * \param param_name specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result being + * queried is returned. If param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by param_value. This size must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data being + * queried by param_value. If param_value_size_ret is NULL, it is ignored. + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise, it + * returns one of the following errors: + * - CL_INVALID_VALUE if param_name is not valid, or if size in bytes specified + * by param_value_size is < size of return type and param_value is not NULL. + * - CL_INVALID_MEM_OBJECT if pipe is a not a valid pipe object. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 2.0r19 + */ +RUNTIME_ENTRY(cl_int, clGetPipeInfo, + (cl_mem memobj, cl_image_info param_name, size_t param_value_size, void* param_value, + size_t* param_value_size_ret)) { + if (!is_valid(memobj)) { + return CL_INVALID_MEM_OBJECT; + } + + amd::Pipe* pipe = as_amd(memobj)->asPipe(); + if (pipe == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + switch (param_name) { + case CL_PIPE_PACKET_SIZE: { + cl_uint packetSize = pipe->getPacketSize(); + return amd::clGetInfo(packetSize, param_value_size, param_value, param_value_size_ret); + } + case CL_PIPE_MAX_PACKETS: { + cl_uint count = pipe->getMaxNumPackets(); + return amd::clGetInfo(count, param_value_size, param_value, param_value_size_ret); + } + default: + break; + } + + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +/*! @} + * @} + */ diff --git a/opencl/amdocl/cl_platform_amd.cpp b/opencl/amdocl/cl_platform_amd.cpp new file mode 100644 index 0000000000..9dc1beaf67 --- /dev/null +++ b/opencl/amdocl/cl_platform_amd.cpp @@ -0,0 +1,45 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include "vdi_common.hpp" +#include "cl_platform_amd.h" +#include + +/*! \addtogroup API + * @{ + * + * \addtogroup AMD_Extensions + * @{ + * + */ + +RUNTIME_ENTRY(cl_int, clUnloadPlatformAMD, (cl_platform_id platform)) { + if (AMD_PLATFORM == platform) { + amd::Runtime::tearDown(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + + +/*! @} + * @} + */ diff --git a/opencl/amdocl/cl_platform_amd.h b/opencl/amdocl/cl_platform_amd.h new file mode 100644 index 0000000000..2763491e27 --- /dev/null +++ b/opencl/amdocl/cl_platform_amd.h @@ -0,0 +1,45 @@ +/* Copyright (c) 2009 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +// AMD-specific platform management extensions + +#ifndef __CL_PLATFORM_AMD_H +#define __CL_PLATFORM_AMD_H + +#include "CL/cl_platform.h" + +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus*/ + +/*! \brief Unloads the specified platform, handling all required cleanup. + * + * @todo This is still somewhat of a stub. It only works for the AMD + * platform and just forces shutdown of all devices (to get PM4 + * capture working). It should handle ICD unregistration as well. + */ +extern CL_API_ENTRY cl_int CL_API_CALL clUnloadPlatformAMD(cl_platform_id platform) + CL_API_SUFFIX__VERSION_1_0; + +#ifdef __cplusplus +} /*extern "C"*/ +#endif /*__cplusplus*/ + +#endif /*__CL_AMD_PROFILE_H*/ diff --git a/opencl/amdocl/cl_profile_amd.cpp b/opencl/amdocl/cl_profile_amd.cpp new file mode 100644 index 0000000000..e5d7fe5b61 --- /dev/null +++ b/opencl/amdocl/cl_profile_amd.cpp @@ -0,0 +1,386 @@ +/* Copyright (c) 2009 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include "cl_profile_amd.h" +#include "platform/context.hpp" +#include "platform/command.hpp" +#include "platform/perfctr.hpp" +#include "device/device.hpp" +#include + +/*! \addtogroup API + * @{ + * + * \addtogroup AMD_Extensions + * @{ + * + */ + +/*! \brief Creates a new HW performance counter + * for the specified OpenCL context. + * + * \param device must be a valid OpenCL device. + * + * \param block_index index of the HW block to configure. + * + * \param counter_index index of the hardware counter + * within the block to configure. + * + * \param event_index Event you wish to count with + * the counter specified by block_index + counter_index + * + * \param perf_counter the created perfcounter object + * + * \param errcode_ret A non zero value if OpenCL failed to create PerfCounter + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_DEVICE if the specified context is invalid. + * - CL_INVALID_OPERATION if we couldn't create the object + * + * \return Created perfcounter object + */ +RUNTIME_ENTRY_RET(cl_perfcounter_amd, clCreatePerfCounterAMD, + (cl_device_id device, cl_perfcounter_property* properties, cl_int* errcode_ret)) { + // Make sure we have a valid device object + if (!is_valid(device)) { + *not_null(errcode_ret) = CL_INVALID_DEVICE; + return NULL; + } + + // Make sure we have a valid pointer to the performance counter properties + if (NULL == properties) { + return NULL; + } + + amd::PerfCounter::Properties perfProperties; + size_t size = 0; + while (properties[size] != CL_PERFCOUNTER_NONE) { + if (properties[size] < CL_PERFCOUNTER_LAST) { + perfProperties[properties[size]] = static_cast(properties[size + 1]); + size += 2; + } else { + return NULL; + } + } + + // Create the device perf counter + amd::PerfCounter* perfCounter = new amd::PerfCounter(*as_amd(device), perfProperties); + + if (perfCounter == NULL) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + return NULL; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(perfCounter); +} +RUNTIME_EXIT + +/*! \brief Destroy a performance counter object. + * + * \param perf_counter the perfcounter object for release + * + * \return A non zero value if OpenCL failed to release PerfCounter + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_OPERATION if we failed to release the object + */ +RUNTIME_ENTRY(cl_int, clReleasePerfCounterAMD, (cl_perfcounter_amd perf_counter)) { + if (!is_valid(perf_counter)) { + return CL_INVALID_OPERATION; + } + as_amd(perf_counter)->release(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Increments the perfcounter object reference count. + * + * \param perf_counter the perfcounter object for retain + * + * \return A non zero value if OpenCL failed to retain PerfCounter + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_OPERATION if we failed to release the object + */ +RUNTIME_ENTRY(cl_int, clRetainPerfCounterAMD, (cl_perfcounter_amd perf_counter)) { + if (!is_valid(perf_counter)) { + return CL_INVALID_OPERATION; + } + as_amd(perf_counter)->retain(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Enqueues the begin command for the specified counters. + * + * \param command_queue must be a valid OpenCL command queue. + * + * \param num_perf_counters the number of perfcounter objects in the array. + * + * \param perf_counters specifies an array of perfcounter objects. + * + * \param event_wait_list specify [is a pointer to] events that need to + * complete before this particular command can be executed. + * If \a event_wait_list is NULL, then this particular command does not wait + * on any event to complete. If \a event_wait_list is NULL, + * \a num_events_in_wait_list must be 0. If \a event_wait_list is not NULL, + * the list of events pointed to by \a event_wait_list must be valid and + * \a num_events_in_wait_list must be greater than 0. The events specified in + * \a event_wait_list act as synchronization points. + * + * \param num_events_in_wait_list specify the number of events in + * \a event_wait_list. It must be 0 if \a event_wait_list is NULL. It must be + * greater than 0 if \a event_wait_list is not NULL. + * + * \param event returns an event object that identifies this particular + * command and can be used to query or queue a wait for this particular + * command to complete. \a event can be NULL in which case it will not be + * possible for the application to query the status of this command or queue a + * wait for this command to complete. + * + * \return A non zero value if OpenCL failed to release PerfCounter + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_OPERATION if we failed to enqueue the begin operation + * - CL_INVALID_COMMAND_QUEUE if the queue is + */ +RUNTIME_ENTRY(cl_int, clEnqueueBeginPerfCounterAMD, + (cl_command_queue command_queue, cl_uint num_perf_counters, + cl_perfcounter_amd* perf_counters, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if ((num_perf_counters == 0) || (perf_counters == NULL)) { + return CL_INVALID_OPERATION; + } + + amd::HostQueue* hostQueue = as_amd(command_queue)->asHostQueue(); + if (NULL == hostQueue) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::PerfCounterCommand::PerfCounterList counters; + + // Place all counters into the list + for (cl_uint i = 0; i < num_perf_counters; ++i) { + amd::PerfCounter* amdPerf = as_amd(perf_counters[i]); + if (&hostQueue->device() == &amdPerf->device()) { + counters.push_back(amdPerf); + } else { + return CL_INVALID_DEVICE; + } + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, *hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + // Create a new command for the performance counters + amd::PerfCounterCommand* command = new amd::PerfCounterCommand( + *hostQueue, eventWaitList, counters, amd::PerfCounterCommand::Begin); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Submit the command to the device + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Enqueues the end command for the specified counters. + * + * \param command_queue must be a valid OpenCL command queue. + * + * \param num_perf_counters the number of perfcounter objects in the array. + * + * \param perf_counters specifies an array of perfcounter objects. + * + * \param event_wait_list specify [is a pointer to] events that need to + * complete before this particular command can be executed. + * If \a event_wait_list is NULL, then this particular command does not wait + * on any event to complete. If \a event_wait_list is NULL, + * \a num_events_in_wait_list must be 0. If \a event_wait_list is not NULL, + * the list of events pointed to by \a event_wait_list must be valid and + * \a num_events_in_wait_list must be greater than 0. The events specified in + * \a event_wait_list act as synchronization points. + * + * \param num_events_in_wait_list specify the number of events in + * \a event_wait_list. It must be 0 if \a event_wait_list is NULL. It must be + * greater than 0 if \a event_wait_list is not NULL. + * + * \param event returns an event object that identifies this particular + * command and can be used to query or queue a wait for this particular + * command to complete. \a event can be NULL in which case it will not be + * possible for the application to query the status of this command or queue a + * wait for this command to complete. + * + * \return A non zero value if OpenCL failed to release PerfCounter + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_OPERATION if we failed to enqueue the end operation + */ +RUNTIME_ENTRY(cl_int, clEnqueueEndPerfCounterAMD, + (cl_command_queue command_queue, cl_uint num_perf_counters, + cl_perfcounter_amd* perf_counters, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if ((num_perf_counters == 0) || (perf_counters == NULL)) { + return CL_INVALID_OPERATION; + } + + amd::HostQueue* hostQueue = as_amd(command_queue)->asHostQueue(); + if (NULL == hostQueue) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::PerfCounterCommand::PerfCounterList counters; + + // Place all counters into the list + for (cl_uint i = 0; i < num_perf_counters; ++i) { + amd::PerfCounter* amdPerf = as_amd(perf_counters[i]); + if (&hostQueue->device() == &amdPerf->device()) { + counters.push_back(amdPerf); + } else { + return CL_INVALID_DEVICE; + } + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, *hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + // Create a new command for the performance counters + amd::PerfCounterCommand* command = new amd::PerfCounterCommand( + *hostQueue, eventWaitList, counters, amd::PerfCounterCommand::End); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Submit the command to the device + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Retrieves the results from the counter objects. + * + * \param num_perf_counter the perfcounter object for the information query. + * + * \param perf_counters specifies an array of perfcounter objects. + * + * \param wait_event specifies the wait event, returned in + * the clEnqueueEndPerfCounterAMD. + * + * \param wait true if OpenCL should wait for the perfcounter data. + * + * \param values must be a valid pointer to an array of 64-bit values + * and the array size must be equal to num_perf_counters. + * + * \return + * - CL_SUCCESS if the function is executed successfully. + * - CL_PROFILING_INFO_NOT_AVAILABLE if event isn't finished. + * - CL_INVALID_OPERATION if we failed to get the data + */ +RUNTIME_ENTRY(cl_int, clGetPerfCounterInfoAMD, + (cl_perfcounter_amd perf_counter, cl_perfcounter_info param_name, + size_t param_value_size, void* param_value, size_t* param_value_size_ret)) { + // Check if we have a valid performance counter + if (!is_valid(perf_counter)) { + return CL_INVALID_OPERATION; + } + + // Find the kernel, associated with the specified device + const device::PerfCounter* devCounter = as_amd(perf_counter)->getDeviceCounter(); + + // Make sure we found a valid performance counter + if (devCounter == NULL) { + return CL_INVALID_OPERATION; + } + + // Get the corresponded parameters + switch (param_name) { + case CL_PERFCOUNTER_REFERENCE_COUNT: { + cl_uint count = as_amd(perf_counter)->referenceCount(); + // Return the reference counter + return amd::clGetInfo(count, param_value_size, param_value, param_value_size_ret); + } + case CL_PERFCOUNTER_GPU_BLOCK_INDEX: + case CL_PERFCOUNTER_GPU_COUNTER_INDEX: + case CL_PERFCOUNTER_GPU_EVENT_INDEX: { + cl_ulong data = devCounter->getInfo(param_name); + // Return the device performance counter information + return amd::clGetInfo(data, param_value_size, param_value, param_value_size_ret); + } + case CL_PERFCOUNTER_DATA: { + cl_ulong data = devCounter->getInfo(param_name); + if (static_cast(0xffffffffffffffffULL) == data) { + return CL_PROFILING_INFO_NOT_AVAILABLE; + } + // Return the device performance counter result + return amd::clGetInfo(data, param_value_size, param_value, param_value_size_ret); + } + default: + return CL_INVALID_VALUE; + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +RUNTIME_ENTRY(cl_int, clSetDeviceClockModeAMD, + (cl_device_id device, cl_set_device_clock_mode_input_amd set_clock_mode_input, + cl_set_device_clock_mode_output_amd* set_clock_mode_output)) { + // Make sure we have a valid device object + if (!is_valid(device)) { + return CL_INVALID_DEVICE; + } + if (set_clock_mode_input.clock_mode >= CL_DEVICE_CLOCK_MODE_COUNT_AMD) { + return CL_INVALID_VALUE; + } + amd::Device* amdDevice = as_amd(device); + bool ret = amdDevice->SetClockMode(set_clock_mode_input, set_clock_mode_output); + return (ret == true)? CL_SUCCESS : CL_INVALID_OPERATION; +} +RUNTIME_EXIT + +/*! @} + * @} + */ diff --git a/opencl/amdocl/cl_profile_amd.h b/opencl/amdocl/cl_profile_amd.h new file mode 100644 index 0000000000..400d05b28b --- /dev/null +++ b/opencl/amdocl/cl_profile_amd.h @@ -0,0 +1,189 @@ +/* Copyright (c) 2009 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef __CL_PROFILE_AMD_H +#define __CL_PROFILE_AMD_H + +#include "CL/cl_platform.h" + +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus*/ + +typedef struct _cl_perfcounter_amd* cl_perfcounter_amd; +typedef cl_ulong cl_perfcounter_property; +typedef cl_uint cl_perfcounter_info; + +/* cl_perfcounter_info */ +enum PerfcounterInfo { + CL_PERFCOUNTER_NONE = 0x0, + CL_PERFCOUNTER_REFERENCE_COUNT = 0x1, + CL_PERFCOUNTER_DATA = 0x2, + CL_PERFCOUNTER_GPU_BLOCK_INDEX = 0x3, + CL_PERFCOUNTER_GPU_COUNTER_INDEX = 0x4, + CL_PERFCOUNTER_GPU_EVENT_INDEX = 0x5, + CL_PERFCOUNTER_LAST +}; + +/********************************* +* Set device clock mode data +*********************************/ +enum cl_DeviceClockMode_AMD { + CL_DEVICE_CLOCK_MODE_DEFAULT_AMD = 0x0, /*Device clocks and other power settings are restored to default*/ + CL_DEVICE_CLOCK_MODE_QUERY_AMD = 0x1, /*Queries the current device clock ratios. Leaves the clock mode of the device unchanged*/ + CL_DEVICE_CLOCK_MODE_PROFILING_AMD = 0x2, /*Scale down from peak ratio*/ + CL_DEVICE_CLOCK_MODE_MINIMUMMEMORY_AMD = 0x3, /* Memory clock is set to the lowest available level*/ + CL_DEVICE_CLOCK_MODE_MINIMUMENGINE_AMD = 0x4, /*Engine clock is set to the lowest available level*/ + CL_DEVICE_CLOCK_MODE_PEAK_AMD = 0x5, /*Clocks set to maximum when possible. Fan set to maximum.*/ + CL_DEVICE_CLOCK_MODE_QUERYPROFILING_AMD = 0x6, /*Queries the profiling device clock ratios. Leaves the clock mode of the device unchanged*/ + CL_DEVICE_CLOCK_MODE_QUERYPEAK_AMD = 0x7, /*Queries the peak device clock ratios.Leaves the clock mode of the device unchanged*/ + CL_DEVICE_CLOCK_MODE_COUNT_AMD = 0x8, /*Maxmium count of device clock mode*/ +}; + +typedef struct _cl_set_device_clock_mode_input_amd +{ + /* specify the clock mode for AMD GPU device*/ + cl_DeviceClockMode_AMD clock_mode; +} cl_set_device_clock_mode_input_amd; + +typedef struct _cl_set_device_clock_mode_output_amd +{ + /*Ratio of current mem clock to peak clock as obtained from DeviceProperties::maxGpuClock*/ + cl_float memory_clock_ratio_to_peak; + /*Ratio of current gpu core clock to peak clock as obtained from DeviceProperties::maxGpuClock*/ + cl_float engine_clock_ratio_to_peak; +} cl_set_device_clock_mode_output_amd; + +/*! \brief Creates a new HW performance counter + * for the specified OpenCL context. + * + * \param device must be a valid OpenCL device. + * + * \param properties the list of properties of the hardware counter + * + * \param errcode_ret A non zero value if OpenCL failed to create PerfCounter + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_CONTEXT if the specified context is invalid. + * - CL_OUT_OF_RESOURCES if we couldn't create the object + * + * \return the created perfcounter object + */ +extern CL_API_ENTRY cl_perfcounter_amd CL_API_CALL clCreatePerfCounterAMD( + cl_device_id /* device */, cl_perfcounter_property* /* properties */, cl_int* /* errcode_ret */ + ) CL_API_SUFFIX__VERSION_1_0; + +/*! \brief Destroy a performance counter object. + * + * \param perf_counter the perfcounter object for release + * + * \return A non zero value if OpenCL failed to release PerfCounter + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_OPERATION if we failed to release the object + */ +extern CL_API_ENTRY cl_int CL_API_CALL clReleasePerfCounterAMD(cl_perfcounter_amd /* perf_counter */ + ) CL_API_SUFFIX__VERSION_1_0; + +/*! \brief Increments the perfcounter object reference count. + * + * \param perf_counter the perfcounter object for retain + * + * \return A non zero value if OpenCL failed to retain PerfCounter + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_OPERATION if we failed to release the object + */ +extern CL_API_ENTRY cl_int CL_API_CALL clRetainPerfCounterAMD(cl_perfcounter_amd /* perf_counter */ + ) CL_API_SUFFIX__VERSION_1_0; + +/*! \brief Enqueues the begin command for the specified counters. + * + * \param command_queue must be a valid OpenCL command queue. + * + * \param num_perf_counters the number of perfcounter objects in the array. + * + * \param perf_counters specifies an array of perfcounter objects. + * + * \return A non zero value if OpenCL failed to release PerfCounter + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_OPERATION if we failed to enqueue the begin operation + */ +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueBeginPerfCounterAMD( + cl_command_queue /* command_queue */, cl_uint /* num_perf_counters */, + cl_perfcounter_amd* /* perf_counters */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */ + ) CL_API_SUFFIX__VERSION_1_0; + +/*! \brief Enqueues the end command for the specified counters. + * + * \param command_queue must be a valid OpenCL command queue. + * + * \param num_perf_counters the number of perfcounter objects in the array. + * + * \param perf_counters specifies an array of perfcounter objects. + * + * \param event the event object associated with the end operation. + * + * \return A non zero value if OpenCL failed to release PerfCounter + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_OPERATION if we failed to enqueue the end operation + */ +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueEndPerfCounterAMD( + cl_command_queue /* command_queue */, cl_uint /* num_perf_counters */, + cl_perfcounter_amd* /* perf_counters */, cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, cl_event* /* event */ + ) CL_API_SUFFIX__VERSION_1_0; + +/*! \brief Retrieves the results from the counter objects. + * + * \param perf_counter specifies a perfcounter objects for query. + * + * \param param_name specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result + * being queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data copied + * to \a param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * \param values must be a valid pointer to an array of 64-bit values + * and the array size must be equal to num_perf_counters. + * + * \return + * - CL_SUCCESS if the function is executed successfully. + * - CL_PROFILING_INFO_NOT_AVAILABLE if event isn't finished. + * - CL_INVALID_OPERATION if we failed to get the data + */ +extern CL_API_ENTRY cl_int CL_API_CALL clGetPerfCounterInfoAMD( + cl_perfcounter_amd /* perf_counter */, cl_perfcounter_info /* param_name */, + size_t /* param_value_size */, void* /* param_value */, size_t* /* param_value_size_ret */ + ) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL clSetDeviceClockModeAMD( + cl_device_id /* device*/, cl_set_device_clock_mode_input_amd /* Clock_Mode_Input */, + cl_set_device_clock_mode_output_amd* /* Clock_Mode_Output */ + ) CL_API_SUFFIX__VERSION_1_0; + +#ifdef __cplusplus +} /*extern "C"*/ +#endif /*__cplusplus*/ + +#endif /*__CL_PROFILE_AMD_H*/ diff --git a/opencl/amdocl/cl_program.cpp b/opencl/amdocl/cl_program.cpp new file mode 100644 index 0000000000..6ad7ab364d --- /dev/null +++ b/opencl/amdocl/cl_program.cpp @@ -0,0 +1,2016 @@ +/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include "vdi_common.hpp" +#include "platform/context.hpp" +#include "platform/program.hpp" +#include "platform/kernel.hpp" +#include "platform/sampler.hpp" +#include "cl_semaphore_amd.h" + +#include + +static amd::Program* createProgram(cl_context context, cl_uint num_devices, + const cl_device_id* device_list, cl_int* errcode_ret) { + // Create the program + amd::Program* program = new amd::Program(*as_amd(context)); + if (program == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return NULL; + } + + // Add programs for all devices in the context. + if (device_list == NULL) { + const std::vector& devices = as_amd(context)->devices(); + for (const auto& it : devices) { + if (program->addDeviceProgram(*it) == CL_OUT_OF_HOST_MEMORY) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + program->release(); + return NULL; + } + } + return program; + } + + *not_null(errcode_ret) = CL_SUCCESS; + for (cl_uint i = 0; i < num_devices; ++i) { + cl_device_id device = device_list[i]; + + if (!is_valid(device) || !as_amd(context)->containsDevice(as_amd(device))) { + *not_null(errcode_ret) = CL_INVALID_DEVICE; + program->release(); + return NULL; + } + + cl_int status = program->addDeviceProgram(*as_amd(device)); + if (status == CL_OUT_OF_HOST_MEMORY) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + program->release(); + return NULL; + } + } + return program; +} + +/*! \addtogroup API + * @{ + * + * \addtogroup CL_Programs + * + * An OpenCL program consists of a set of kernels that are identified as + * functions declared with the __kernel qualifier in the program source. + * OpenCL programs may also contain auxiliary functions and constant data that + * can be used by __kernel functions. The program executable can be generated + * online or offline by the OpenCL compiler for the appropriate + * target device(s). + * + * @{ + * + * \addtogroup CL_CreatingPrograms + * @{ + */ + +/*! \brief Create a program object for a context, and loads the source code + * specified by the text strings in the strings array into the program object. + * + * \param context must be a valid OpenCL context. + * + * \param count is the number of pointers in \a strings + * + * \param strings is an array of \a count pointers to optionally + * null-terminated character strings that make up the source code. + * + * \param lengths is an array with the number of chars in each string (the + * string length). If an element in lengths is zero, its accompanying string + * is null-terminated. If lengths is NULL, all strings in the strings argument + * are considered null-terminated. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A valid non-zero program object and errcode_ret is set to + * \a CL_SUCCESS if the program object is created successfully. It returns a + * NULL value with one of the following error values returned in + * \a errcode_ret: + * - CL_INVALID_CONTEXT if \a context is not a valid context. + * - CL_INVALID_VALUE if \a count is zero or if \a strings or any entry in + * \a strings is NULL. + * - CL_COMPILER_NOT_AVAILABLE if a compiler is not available. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY_RET(cl_program, clCreateProgramWithSource, + (cl_context context, cl_uint count, const char** strings, const size_t* lengths, + cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + return (cl_program)0; + } + if (count == 0 || strings == NULL) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_program)0; + } + + std::string sourceCode; + for (cl_uint i = 0; i < count; ++i) { + if (strings[i] == NULL) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_program)0; + } + if (lengths && lengths[i] != 0) { + sourceCode.append(strings[i], lengths[i]); + } else { + sourceCode.append(strings[i]); + } + } + if (sourceCode.empty()) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_program)0; + } + + // Create the program + amd::Program* program = new amd::Program(*as_amd(context), sourceCode, amd::Program::OpenCL_C); + if (program == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_program)0; + } + + // Add programs for all devices in the context. + const std::vector& devices = as_amd(context)->devices(); + for (const auto& it : devices) { + if (program->addDeviceProgram(*it) == CL_OUT_OF_HOST_MEMORY) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + program->release(); + return (cl_program)0; + } + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(program); +} +RUNTIME_EXIT + +/*! \brief Create a program object for a context, and loads the IL into the + * program object. + * + * \param context must be a valid OpenCL context. + * + * \param string is a pointer to IL. + * + * \param length is the size in bytes of IL. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A valid non-zero program object and errcode_ret is set to + * \a CL_SUCCESS if the program object is created successfully. It returns a + * NULL value with one of the following error values returned in + * \a errcode_ret: + * - CL_INVALID_CONTEXT if \a context is not a valid context. + * - CL_INVALID_VALUE if \a il is NULL or \a length is zero. + * - CL_INVALID_VALUE if the \a length-byte memory pointed to by \a il does + * not contain well-formed intermediate language input appropriate for the + * deployment environment in which the OpenCL platform is running. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY_RET(cl_program, clCreateProgramWithIL, + (cl_context context, const void* il, size_t length, cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + return (cl_program)0; + } + if (length == 0 || il == NULL) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_program)0; + } + + // Create the program + amd::Program* program = new amd::Program(*as_amd(context), amd::Program::SPIRV); + if (program == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_program)0; + } + + // Add programs for all devices in the context. + const std::vector& devices = as_amd(context)->devices(); + for (const auto& it : devices) { + if (program->addDeviceProgram(*it, il, length) == CL_OUT_OF_HOST_MEMORY) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + program->release(); + return (cl_program)0; + } + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(program); +} +RUNTIME_EXIT + +/*! \brief Create a program object for a context, and loads the binary images + * into the program object. + * + * \param context must be a valid OpenCL context. + * + * \param device_list is a pointer to a list of devices that are in context. + * \a device_list must be a non-NULL value. The binaries are loaded for devices + * specified in this list. + * + * \param num_devices is the number of devices listed in \a device_list. + * + * \param device_list The devices associated with the program object. The + * list of devices specified by \a device_list must be devices associated with + * \a context. + * + * \param lengths is an array of the size in bytes of the program binaries to + * be loaded for devices specified by \a device_list. + * + * \param binaries is an array of pointers to program binaries to be loaded + * for devices specified by \a device_list. For each device given by + * \a device_list[i], the pointer to the program binary for that device is + * given by \a binaries[i] and the length of this corresponding binary is given + * by \a lengths[i]. \a lengths[i] cannot be zero and \a binaries[i] cannot be + * a NULL pointer. The program binaries specified by binaries contain the bits + * that describe the program executable that will be run on the device(s) + * associated with context. The program binary can consist of either or both: + * - Device-specific executable(s) + * - Implementation specific intermediate representation (IR) which will be + * converted to the device-specific executable. + * + * \param binary_status returns whether the program binary for each device + * specified in \a device_list was loaded successfully or not. It is an array + * of \a num_devices entries and returns CL_SUCCESS in \a binary_status[i] if + * binary was successfully loaded for device specified by \a device_list[i]; + * otherwise returns CL_INVALID_VALUE if \a lengths[i] is zero or if + * \a binaries[i] is a NULL value or CL_INVALID_BINARY in \a binary_status[i] + * if program binary is not a valid binary for the specified device. + * If \a binary_status is NULL, it is ignored. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A valid non-zero program object and \a errcode_ret is set to + * CL_SUCCESS if the program object is created successfully. It returns a NULL + * value with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a context is not a valid context. + * - CL_INVALID_VALUE if \a device_list is NULL or \a num_devices is zero. + * - CL_INVALID_DEVICE if OpenCL devices listed in \a device_list are not in + * the list of devices associated with \a context + * - CL_INVALID_VALUE if \a lengths or \a binaries are NULL or if any entry + * in \a lengths[i] is zero or \a binaries[i] is NULL. + * - CL_INVALID_BINARY if an invalid program binary was encountered for any + * device. \a binary_status will return specific status for each device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY_RET(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)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + return (cl_program)0; + } + if (num_devices == 0 || device_list == NULL || binaries == NULL || lengths == NULL) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_program)0; + } + + amd::Program* program = new amd::Program(*as_amd(context)); + if (program == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_program)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + for (cl_uint i = 0; i < num_devices; ++i) { + cl_device_id device = device_list[i]; + + if (!is_valid(device) || !as_amd(context)->containsDevice(as_amd(device))) { + *not_null(errcode_ret) = CL_INVALID_DEVICE; + program->release(); + return (cl_program)0; + } + if (binaries[i] == NULL || lengths[i] == 0) { + if (binary_status != NULL) { + binary_status[i] = CL_INVALID_VALUE; + } + *not_null(errcode_ret) = CL_INVALID_VALUE; + continue; + } + + cl_int status = program->addDeviceProgram(*as_amd(device), binaries[i], lengths[i]); + + *not_null(errcode_ret) = status; + + if (status == CL_OUT_OF_HOST_MEMORY) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + program->release(); + return (cl_program)0; + } + + if (binary_status != NULL) { + binary_status[i] = status; + } + } + return as_cl(program); +} +RUNTIME_EXIT + +RUNTIME_ENTRY_RET(cl_program, clCreateProgramWithAssemblyAMD, + (cl_context context, cl_uint count, const char** strings, const size_t* lengths, + cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + return (cl_program)0; + } + if (count == 0 || strings == NULL) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_program)0; + } + + std::string assembly; + for (cl_uint i = 0; i < count; ++i) { + if (strings[i] == NULL) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_program)0; + } + if (lengths && lengths[i] != 0) { + assembly.append(strings[i], lengths[i]); + } else { + assembly.append(strings[i]); + } + } + if (assembly.empty()) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_program)0; + } + + // Create the program + amd::Program* program = new amd::Program(*as_amd(context), assembly, amd::Program::Assembly); + if (program == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_program)0; + } + + // Add programs for all devices in the context. + const std::vector& devices = as_amd(context)->devices(); + for (const auto& it : devices) { + if (program->addDeviceProgram(*it) == CL_OUT_OF_HOST_MEMORY) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + program->release(); + return (cl_program)0; + } + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(program); +} +RUNTIME_EXIT + +/*! \brief Increment the program reference count. + * + * clCreateProgram does an implicit retain. + * + * \return CL_SUCCESS if the function is executed successfully. It returns + * CL_INVALID_PROGRAM if \a program is not a valid program object. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clRetainProgram, (cl_program program)) { + if (!is_valid(program)) { + return CL_INVALID_PROGRAM; + } + as_amd(program)->retain(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Decrement the program reference count. + * + * The program object is deleted after all kernel objects associated with + * \a program have been deleted and the program reference count becomes zero. + * + * \return CL_SUCCESS if the function is executed successfully. It returns + * CL_INVALID_PROGRAM if \a program is not a valid program object. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clReleaseProgram, (cl_program program)) { + if (!is_valid(program)) { + return CL_INVALID_PROGRAM; + } + as_amd(program)->release(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_Build + * @{ + */ + +/*! \brief Build (compile & link) a program executable from the program source + * or binary for all the devices or a specific device(s) in the OpenCL context + * associated with program. + * + * OpenCL allows program executables to be built using the sources or binaries. + * + * \param program is the program object. + * + * \param device_list is a pointer to a list of devices associated with + * \a program. If \a device_list is a NULL value, the program executable is + * built for all devices associated with \a program for which a source or + * binary has been loaded. If \a device_list is a non-NULL value, the program + * executable is built for devices specified in this list for which a source + * or binary has been loaded. + * + * \param num_devices is the number of devices listed in \a device_list. + * + * \param options is a pointer to a string that describes the build options to + * be used for building the program executable. + * + * \param pfn_notify is a function pointer to a notification routine. The + * notification routine allows an application to register a callback function + * which will be called when the program executable has been built + * (successfully or unsuccessfully). If \a pfn_notify is not NULL, + * clBuildProgram does not need to wait for the build to complete and can + * return immediately. If \a pfn_notify is NULL, clBuildProgram does not + * return until the build has completed. This callback function may be called + * asynchronously by the OpenCL implementation. It is the application's + * responsibility to ensure that the callback function is thread-safe. + * + * \param user_data will be passed as the argument when \a pfn_notify is + * called. \a user_data can be NULL. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully + * - CL_INVALID_PROGRAM if \a program is not a valid program object + * - CL_INVALID_VALUE if \a device_list is NULL and \a num_devices is greater + * than zero, or if \a device_list is not NULL and \a num_devices is zero, + * - CL_INVALID_DEVICE if OpenCL devices listed in \a device_list are not in + * the list of devices associated with \a program + * - CL_INVALID_BINARY if \a program is created with clCreateWithProgramBinary + * and devices listed in \a device_list do not have a valid program binary + * loaded + * - CL_INVALID_BUILD_OPTIONS if the build options specified by \a options are + * invalid + * - CL_INVALID_OPERATION if the build of a program executable for any of the + * devices listed in \a device_list by a previous call to clBuildProgram for + * \a program has not completed + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(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)) { + if (!is_valid(program)) { + return CL_INVALID_PROGRAM; + } + if ((num_devices > 0 && device_list == NULL) || (num_devices == 0 && device_list != NULL)) { + return CL_INVALID_VALUE; + } + if (pfn_notify == nullptr && user_data != nullptr) { + return CL_INVALID_VALUE; + } + + amd::Program* amdProgram = as_amd(program); + + if (device_list == NULL) { + // build for all devices in the context. + return amdProgram->build(amdProgram->context().devices(), options, pfn_notify, user_data); + } + + std::vector devices(num_devices); + for (cl_uint i = 0; i < num_devices; ++i) { + amd::Device* device = as_amd(device_list[i]); + if (!amdProgram->context().containsDevice(device)) { + return CL_INVALID_DEVICE; + } + devices[i] = device; + } + return amdProgram->build(devices, options, pfn_notify, user_data); +} +RUNTIME_EXIT + +/*! \brief compiles a program's source for all the devices or a specific + * device(s) in the OpenCL context associated with program. The pre-processor + * runs before the program sources are compiled. + * The compiled binary is built for all devices associated with program or + * the list of devices specified. The compiled binary can be queried using + * \a clGetProgramInfo(program, CL_PROGRAM_BINARIES, ...) and can be specified + * to \a clCreateProgramWithBinary to create a new program object. + * + * \param program is the program object that is the compilation target. + * + * \param device_list is a pointer to a list of devices associated with program. + * If device_list is a NULL value, the compile is performed for all devices + * associated with program. If device_list is a non-NULL value, the compile is + * performed for devices specified in this list. + * + * \param num_devices is the number of devices listed in \a device_list. + * + * \param options is a pointer to a null-terminated string of characters that + * describes the compilation options to be used for building the program + * executable. The list of supported options is as described in section 5.6.4. + * + * \param num_input_headers specifies the number of programs that describe + * headers in the array referenced by input_headers. + * + * \param input_headers is an array of program embedded headers created with + * \a clCreateProgramWithSource. + * + * \param header_include_names is an array that has a one to one correspondence + * with input_headers. + * Each entry in \a header_include_names specifies the include name used by + * source in program that comes from an embedded header. The corresponding entry + * in input_headers identifies the program object which contains the header + * source to be used. The embedded headers are first searched before the headers + * in the list of directories specified by the -I compile option (as described in + * section 5.6.4.1). If multiple entries in header_include_names refer to the same + * header name, the first one encountered will be used. + * + * \param pfn_notify is a function pointer to a notification routine. The + * notification routine is a callback function that an application can register + * and which will be called when the program executable has been built + * (successfully or unsuccessfully). If pfn_notify is not NULL, + * \a clCompileProgram does not need to wait for the compiler to complete and can + * return immediately. If \a pfn_notify is NULL, \a clCompileProgram does not + * return until the compiler has completed. This callback function may be called + * asynchronously by the OpenCL implementation. It is the application's + * responsibility to ensure that the callback function is thread-safe. + * + * \param user_data will be passed as an argument when pfn_notify is called. + * \a user_data can be NULL. + * + * \return CL_SUCCESS if the function is executed successfully. Otherwise, it + * returns one of the following errors: + * - CL_INVALID_PROGRAM if program is not a valid program object. + * - CL_INVALID_VALUE if device_list is NULL and num_devices is greater than + * zero, or if \a device_list is not NULL and \a num_devices is zero. + * - CL_INVALID_VALUE if num_input_headers is zero and \a header_include_names + * or input_headers are not NULL or if num_input_headers is not zero and + * \a header_include_names or input_headers are NULL. + * - CL_INVALID_VALUE if \a pfn_notify is NULL but \a user_data is not NULL. + * - CL_INVALID_DEVICE if OpenCL devices listed in device_list are not in the + * list of devices associated with program + * - CL_INVALID_COMPILER_OPTIONS if the compiler options specified by options + * are invalid. + * - CL_INVALID_OPERATION if the compilation or build of a program executable + * for any of the devices listed in device_list by a previous call to + * \a clCompileProgram or \a clBuildProgram for program has not completed. + * - CL_COMPILER_NOT_AVAILABLE if a compiler is not available i.e. + * - CL_DEVICE_COMPILER_AVAILABLE specified in table 4.3 is set to CL_FALSE. + * - CL_COMPILE_PROGRAM_FAILURE if there is a failure to compile the program + * source. This error will be returned if clCompileProgram does not return + * until the compile has completed. + * - CL_INVALID_OPERATION if there are kernel objects attached to program. + * - CL_INVALID_OPERATION if program has no source i.e. it has not been created + * with \a clCreateProgramWithSource. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY(cl_int, clCompileProgram, + (cl_program program, cl_uint num_devices, const cl_device_id* device_list, + const char* options, cl_uint num_input_headers, const cl_program* input_headers, + const char** header_include_names, + void(CL_CALLBACK* pfn_notify)(cl_program program, void* user_data), + void* user_data)) { + if (!is_valid(program)) { + return CL_INVALID_PROGRAM; + } + if ((num_devices > 0 && device_list == NULL) || (num_devices == 0 && device_list != NULL)) { + return CL_INVALID_VALUE; + } + if ((num_input_headers > 0 && (input_headers == NULL || header_include_names == NULL)) || + (num_input_headers == 0 && (input_headers != NULL || header_include_names != NULL))) { + return CL_INVALID_VALUE; + } + if (pfn_notify == NULL && user_data != NULL) { + return CL_INVALID_VALUE; + } + + amd::Program* amdProgram = as_amd(program); + if (amdProgram->referenceCount() > 1) { + return CL_INVALID_OPERATION; + } + + std::vector headerPrograms(num_input_headers); + for (cl_uint i = 0; i < num_input_headers; ++i) { + if (!is_valid(input_headers[i])) { + return CL_INVALID_OPERATION; + } + const amd::Program* headerProgram = as_amd(input_headers[i]); + headerPrograms[i] = headerProgram; + } + + if (device_list == NULL) { + // compile for all devices in the context. + return amdProgram->compile(amdProgram->context().devices(), num_input_headers, headerPrograms, + header_include_names, options, pfn_notify, user_data); + } + + std::vector devices(num_devices); + + for (cl_uint i = 0; i < num_devices; ++i) { + amd::Device* device = as_amd(device_list[i]); + if (!amdProgram->context().containsDevice(device)) { + return CL_INVALID_DEVICE; + } + devices[i] = device; + } + + return amdProgram->compile(devices, num_input_headers, headerPrograms, header_include_names, + options, pfn_notify, user_data); +} +RUNTIME_EXIT + +/*! \brief links a set of compiled program objects and libraries for all + * the devices or a specific device(s) in the OpenCL context and creates + * an executable. clLinkProgram creates a new program object which contains + * this executable. The executable binary can be queried using + * \a clGetProgramInfo(program, CL_PROGRAM_BINARIES, ...) and can be specified + * to \a clCreateProgramWithBinary to create a new program object. + * The devices associated with the returned program object will be the list + * of devices specified by device_list or if device_list is NULL it will be + * the list of devices associated with context. + * + * \param context must be a valid OpenCL context. + * + * \param device_list is a pointer to a list of devices that are in context. + * If device_list is a NULL value, the link is performed for all devices + * associated with context for which a compiled object is available. + * If device_list is a non-NULL value, the compile is performed for devices + * specified in this list for which a source has been loaded. + * + * \param num_devices is the number of devices listed in device_list. + * + * \param options is a pointer to a null-terminated string of characters + * that describes the link options to be used for building the program + * executable. The list of supported options is as described in section 5.6.5. + * + * \param num_input_programs specifies the number of programs in array + * referenced by input_programs. + * + * \param input_programs is an array of program objects that are compiled + * binaries or libraries that are to be linked to create the program executable. + * For each device in device_list or if device_list is NULL the list of devices + * associated with context, the following cases occur: + * All programs specified by input_programs contain a compiled binary or + * library for the device. In this case, a link is performed to generate + * a program executable for this device. None of the programs contain + * a compiled binary or library for that device. In this case, no link is + * performed and there will be no program executable generated for this device. + * All other cases will return a CL_INVALID_OPERATION error. + * + * \param pfn_notify is a function pointer to a notification routine. + * The notification routine is a callback function that an application can + * register and which will be called when the program executable has been built + * (successfully or unsuccessfully). If \a pfn_notify is not NULL, + * \a clLinkProgram does not need to wait for the linker to complete and can + * return immediately. Once the linker has completed, the \a pfn_notify + * callback function is called with a valid program object (if the link was + * successful) or NULL (if the link encountered a failure). This callback + * function may be called asynchronously by the OpenCL implementation. It is + * the application's responsibility to ensure that the callback function is + * thread-safe. If \a pfn_notify is NULL, \a clLinkProgram does not return + * until the linker has completed. clLinkProgram returns a valid non-zero + * program object (if the link was successful) or NULL (if the link + * encountered a failure). + * + * \a user_data will be passed as an argument when \a pfn_notify is called. + * user_data can be NULL. + * + * \return a valid non-zero program object and errcode_ret is set to CL_SUCCESS + * if the link was successful in generating a program executable for at least + * one device and the program object was created successfully. If \a pfn_notify + * is not NULL, \a clLinkProgram returns a NULL program object and + * \a errcode_ret is set to CL_SUCCESS if the function was executed + * successfully. Otherwise, it returns one of the following errors: + * - CL_INVALID_CONTEXT if context is not a valid context. + * - CL_INVALID_VALUE if device_list is NULL and num_devices is greater than + * zero, or if \a device_list is not NULL and \a num_devices is zero. + * - CL_INVALID_VALUE if \a num_input_programs is zero and \a input_programs + * is NULL or if \a num_input_programs is zero and \a input_programs is not + * NULL or if \a num_input_programs is not zero and \a input_programs is NULL. + * - CL_INVALID_PROGRAM if programs specified in \a input_programs are not + * valid program objects. + * - CL_INVALID_VALUE if \a pfn_notify is NULL but \a user_data is not NULL. + * - CL_INVALID_DEVICE if OpenCL devices listed in \a device_list are not in + * the list of devices associated with context + * - CL_INVALID_LINKER_OPTIONS if the linker options specified by options are + * invalid. + * - CL_INVALID_OPERATION if the compilation or build of a program executable + * for any of the devices listed in \a device_list by a previous call to + * clCompileProgram or clBuildProgram for program has not completed. + * - CL_INVALID_OPERATION if the rules for devices containing compiled binaries + * or libraries as described in \a input_programs argument above are + * not followed. + * - CL_LINKER_NOT_AVAILABLE if a linker is not available i.e. + * - CL_DEVICE_LINKER_AVAILABLE specified in table 4.3 is set to CL_FALSE. + * - CL_LINK_PROGRAM_FAILURE if there is a failure to link the compiled + * binaries and/or libraries. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY_RET(cl_program, clLinkProgram, + (cl_context context, cl_uint num_devices, const cl_device_id* device_list, + const char* options, cl_uint num_input_programs, + const cl_program* input_programs, + void(CL_CALLBACK* pfn_notify)(cl_program program, void* user_data), + void* user_data, cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + return (cl_program)0; + } + + if ((num_devices > 0 && device_list == NULL) || (num_devices == 0 && device_list != NULL)) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_program)0; + } + + if (num_input_programs == 0 || input_programs == NULL) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_program)0; + } + + if (pfn_notify == NULL && user_data != NULL) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_program)0; + } + + std::vector inputPrograms(num_input_programs); + for (cl_uint i = 0; i < num_input_programs; ++i) { + if (!is_valid(input_programs[i])) { + *not_null(errcode_ret) = CL_INVALID_PROGRAM; + return (cl_program)0; + } + amd::Program* inputProgram = as_amd(input_programs[i]); + inputPrograms[i] = inputProgram; + } + + amd::Program* program = createProgram(context, num_devices, device_list, errcode_ret); + if (program == NULL) return (cl_program)0; + + *not_null(errcode_ret) = CL_SUCCESS; + cl_int status; + + if (device_list == NULL) { + // compile for all devices in the context. + status = program->link(as_amd(context)->devices(), num_input_programs, inputPrograms, options, + pfn_notify, user_data); + } else { + std::vector devices(num_devices); + + for (cl_uint i = 0; i < num_devices; ++i) { + amd::Device* device = as_amd(device_list[i]); + if (!as_amd(context)->containsDevice(device)) { + program->release(); + *not_null(errcode_ret) = CL_INVALID_DEVICE; + return (cl_program)0; + } + devices[i] = device; + } + + status = + program->link(devices, num_input_programs, inputPrograms, options, pfn_notify, user_data); + } + *not_null(errcode_ret) = status; + if (status == CL_SUCCESS) { + return as_cl(program); + } + + program->release(); + return (cl_program)0; +} +RUNTIME_EXIT + +/*! \brief creates a program object for a context, and loads the information + * related to the built-in kernels into a program object. + * + * \param context must be a valid OpenCL context. + * + * \param num_devices is the number of devices listed in device_list. + * + * \param device_list is a pointer to a list of devices that are in context. + * \a device_list must be a non-NULL value. The built-in kernels are loaded + * for devices specified in this list. The devices associated with the + * program object will be the list of devices specified by \a device_list. + * The list of devices specified by \a device_list must be devices associated + * with context. + * + * \param kernel_names is a semi-colon separated list of built-in kernel names. + * + * \return a valid non-zero program object and \a errcode_ret is set to + * CL_SUCCESS if the program object is created successfully. Otherwise, it + * returns a NULL value with one of the following error values returned + * in errcode_ret: + * - CL_INVALID_CONTEXT if context is not a valid context. + * - CL_INVALID_VALUE if device_list is NULL or num_devices is zero. + * - CL_INVALID_VALUE if kernel_names is NULL or kernel_names contains a kernel + * name that is not supported by any of the devices in \a device_list. + * - CL_INVALID_DEVICE if devices listed in device_list are not in the list + * of devices associated with context. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY_RET(cl_program, clCreateProgramWithBuiltInKernels, + (cl_context context, cl_uint num_devices, const cl_device_id* device_list, + const char* kernel_names, cl_int* errcode_ret)) { + //!@todo Add implementation + amd::Program* program = NULL; + Unimplemented(); + return as_cl(program); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_Unloading + * @{ + */ + +/*! \brief Allows the implementation to release the resources allocated by + * the OpenCL compiler for platform. This is a hint from the application + * and does not guarantee that the compiler will not be used in the future + * or that the compiler will actually be unloaded by the implementation. + * Calls to \a clBuildProgram, \a clCompileProgram or \a clLinkProgram after + * \a clUnloadPlatformCompiler will reload the compiler, + * if necessary, to build the appropriate program executable. + * + * \return CL_SUCCESS if the function is executed successfully. + * Otherwise, it returns one of the following errors: + * - CL_INVALID_PLATFORM if platform is not a valid platform. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY(cl_int, clUnloadPlatformCompiler, (cl_platform_id platform)) { + if (platform != NULL && platform != AMD_PLATFORM) { + return CL_INVALID_PLATFORM; + } + + //! @todo: Implement Compiler::unload() + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Allow to runtime to release the resources allocated by the OpenCL + * compiler. + * + * This is a hint from the application and does not guarantee that the compiler + * will not be used in the future or that the compiler will actually be + * unloaded by the implementation. + * + * Calls to clBuildProgram after clUnloadCompiler may reload the compiler, + * if necessary, to build the appropriate program executable. + * + * \return This call currently always returns CL_SUCCESS + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clUnloadCompiler, (void)) { + //! @todo: Implement Compiler::unload() + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_ProgramQueries + * @{ + */ + +/*! \brief Return information about the program object. + * + * \param program specifies the program object being queried. + * + * \param param_name specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result + * being queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data copied + * to \a param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully + * - CL_INVALID_VALUE if \a param_name is not valid, or if size in bytes + * specified by \a param_value_size is < size of return type and + * \a param_value is not NULL + * - CL_INVALID_PROGRAM_EXECUTABLE if param_name is + * CL_PROGRAM_NUM_KERNELS or CL_PROGRAM_KERNEL_NAMES and a successful + * program executable has not been built for at least one device in the list + * of devices associated with program. + * - CL_INVALID_PROGRAM if \a program is a not a valid program object + * + * \version 1.2r07 + */ +RUNTIME_ENTRY(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)) { + if (!is_valid(program)) { + return CL_INVALID_PROGRAM; + } + + switch (param_name) { + case CL_PROGRAM_REFERENCE_COUNT: { + cl_uint count = as_amd(program)->referenceCount(); + return amd::clGetInfo(count, param_value_size, param_value, param_value_size_ret); + } + case CL_PROGRAM_CONTEXT: { + cl_context context = const_cast(as_cl(&as_amd(program)->context())); + return amd::clGetInfo(context, param_value_size, param_value, param_value_size_ret); + } + case CL_PROGRAM_NUM_DEVICES: { + cl_uint numDevices = (cl_uint)as_amd(program)->deviceList().size(); + return amd::clGetInfo(numDevices, param_value_size, param_value, param_value_size_ret); + } + case CL_PROGRAM_DEVICES: { + const amd::Program::devicelist_t& devices = as_amd(program)->deviceList(); + const size_t numDevices = devices.size(); + const size_t valueSize = numDevices * sizeof(cl_device_id); + + if (param_value != NULL && param_value_size < valueSize) { + return CL_INVALID_VALUE; + } + *not_null(param_value_size_ret) = valueSize; + if (param_value != NULL) { + cl_device_id* device_list = (cl_device_id*)param_value; + for (const auto& it : devices) { + *device_list++ = const_cast(as_cl(it)); + } + if (param_value_size > valueSize) { + ::memset(static_cast
(param_value) + valueSize, '\0', + param_value_size - valueSize); + } + } + return CL_SUCCESS; + } + case CL_PROGRAM_SOURCE: { + const char* source = as_amd(program)->sourceCode().c_str(); + return amd::clGetInfo(source, param_value_size, param_value, param_value_size_ret); + } + case CL_PROGRAM_BINARY_SIZES: { + amd::Program* amdProgram = as_amd(program); + const amd::Program::devicelist_t& devices = amdProgram->deviceList(); + const size_t numBinaries = devices.size(); + const size_t valueSize = numBinaries * sizeof(size_t); + + if (param_value != NULL && param_value_size < valueSize) { + return CL_INVALID_VALUE; + } + *not_null(param_value_size_ret) = valueSize; + if (param_value != NULL) { + size_t* binary_sizes = (size_t*)param_value; + for (const auto& it : devices) { + *binary_sizes++ = amdProgram->getDeviceProgram(*it)->binary().second; + } + if (param_value_size > valueSize) { + ::memset(static_cast
(param_value) + valueSize, '\0', + param_value_size - valueSize); + } + } + return CL_SUCCESS; + } + case CL_PROGRAM_BINARIES: { + amd::Program* amdProgram = as_amd(program); + const amd::Program::devicelist_t& devices = amdProgram->deviceList(); + const size_t numBinaries = devices.size(); + const size_t valueSize = numBinaries * sizeof(char*); + + if (param_value != NULL && param_value_size < valueSize) { + return CL_INVALID_VALUE; + } + *not_null(param_value_size_ret) = valueSize; + if (param_value != NULL) { + char** binaries = (char**)param_value; + for (const auto& it : devices) { + const device::Program::binary_t& binary = amdProgram->getDeviceProgram(*it)->binary(); + // If an entry value in the array is NULL, + // then runtime should skip copying the program binary + if (*binaries != NULL) { + ::memcpy(*binaries, binary.first, binary.second); + } + binaries++; + } + if (param_value_size > valueSize) { + ::memset(static_cast
(param_value) + valueSize, '\0', + param_value_size - valueSize); + } + } + return CL_SUCCESS; + } + case CL_PROGRAM_NUM_KERNELS: { + if (as_amd(program)->symbolsPtr() == NULL) { + return CL_INVALID_PROGRAM_EXECUTABLE; + } + size_t numKernels = as_amd(program)->symbols().size(); + return amd::clGetInfo(numKernels, param_value_size, param_value, param_value_size_ret); + } + case CL_PROGRAM_KERNEL_NAMES: { + const char* kernelNames = as_amd(program)->kernelNames().c_str(); + return amd::clGetInfo(kernelNames, param_value_size, param_value, param_value_size_ret); + } + default: + break; + } + + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +/*! \brief Return build information for each device in the program object. + * + * \param program specifies the program object being queried. + * + * \param device specifies the device for which build information is being + * queried. device must be a valid device associated with \a program. + * + * \param param_name specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result being + * queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type + * + * \param param_value_size_ret returns the actual size in bytes of data copied + * to \a param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully + * - CL_INVALID_DEVICE if \a device is not in the list of devices associated + * with \a program + * - CL_INVALID_VALUE if \a param_name is not valid, or if size in bytes + * specified by \a param_value_size is < size of return type and + * \a param_value is not NULL + * - CL_INVALID_PROGRAM if \a program is a not a valid program object + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(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)) { + if (!is_valid(program)) { + return CL_INVALID_PROGRAM; + } + if (!is_valid(device)) { + return CL_INVALID_DEVICE; + } + + const device::Program* devProgram = as_amd(program)->getDeviceProgram(*as_amd(device)); + if (devProgram == NULL) { + return CL_INVALID_DEVICE; + } + + switch (param_name) { + case CL_PROGRAM_BUILD_STATUS: { + cl_build_status status = devProgram->buildStatus(); + return amd::clGetInfo(status, param_value_size, param_value, param_value_size_ret); + } + case CL_PROGRAM_BUILD_OPTIONS: { + const std::string optionsStr = devProgram->lastBuildOptionsArg(); + const char* options = optionsStr.c_str(); + return amd::clGetInfo(options, param_value_size, param_value, param_value_size_ret); + } + case CL_PROGRAM_BUILD_LOG: { + const std::string logstr = as_amd(program)->programLog() + devProgram->buildLog().c_str(); + const char* log = logstr.c_str(); + return amd::clGetInfo(log, param_value_size, param_value, param_value_size_ret); + } + case CL_PROGRAM_BINARY_TYPE: { + const device::Program::type_t devProgramType = devProgram->type(); + cl_uint type; + switch (devProgramType) { + case device::Program::TYPE_NONE: { + type = CL_PROGRAM_BINARY_TYPE_NONE; + break; + } + case device::Program::TYPE_COMPILED: { + type = CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT; + break; + } + case device::Program::TYPE_LIBRARY: { + type = CL_PROGRAM_BINARY_TYPE_LIBRARY; + break; + } + case device::Program::TYPE_EXECUTABLE: { + type = CL_PROGRAM_BINARY_TYPE_EXECUTABLE; + break; + } + case device::Program::TYPE_INTERMEDIATE: { + type = CL_PROGRAM_BINARY_TYPE_INTERMEDIATE; + break; + } + default: + return CL_INVALID_VALUE; + } + return amd::clGetInfo(type, param_value_size, param_value, param_value_size_ret); + } + case CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE: { + size_t size = devProgram->globalVariableTotalSize(); + return amd::clGetInfo(size, param_value_size, param_value, param_value_size_ret); + } + default: + break; + } + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +/*! \brief Sets the values of a SPIR-V specialization constants. + * + * \param program must be a valid OpenCL program created from a SPIR-V module. + * + * \param spec id_ identifies the SPIR-V specialization constant whose value will be set. + * + * \param spec_size specifies the size in bytes of the data pointed to by spec_value. This should + * be 1 for boolean constants. For all other constant types this should match the size of the + * specialization constant in the SPIR-V module. + * + * \param spec_value is a pointer to the memory location that contains the value of the + * specialization constant. The data pointed to by \a spec_value are copied and can be safely + * reused by the application after \a clSetProgramSpecializationConstant returns. This + * specialization value will be used by subsequent calls to \a clBuildProgram until another call to + * \a clSetProgramSpecializationConstant changes it. If a specialization constant is a boolean + * constant, _spec value_should be a pointer to a cl_uchar value. A value of zero will set the + * specialization constant to false; any other value will set it to true. + * + * Calling this function multiple times for the same specialization constant shall cause the last + * provided value to override any previously specified value. The values are used by a subsequent + * \a clBuildProgram call for the program. + * + * Application is not required to provide values for every specialization constant contained in + * SPIR-V module. SPIR-V provides default values for all specialization constants. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_PROGRAM if program is not a valid program object created from a SPIR-V module. + * - CL_INVALID_SPEC_ID if spec_id is not a valid specialization constant ID + * - CL_INVALID_VALUE if spec_size does not match the size of the specialization constant in the + * SPIR-V module, or if spec_value is NULL. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL + * implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL + * implementation on the host. + * + * \version 2.2-3 + */ +RUNTIME_ENTRY(cl_int, clSetProgramSpecializationConstant, + (cl_program program, cl_uint spec_id, size_t spec_size, const void* spec_value)) { + if (!is_valid(program)) { + return CL_INVALID_PROGRAM; + } + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +/*! \brief registers a user callback function with a program object. Each call to + * \a clSetProgramReleaseCallback registers the specified user callback function on a callback stack + * associated with program. The registered user callback functions are called in the reverse order + * in which they were registered. The user callback functions are called after destructors (if any) + * for program scope global variables (if any) are called and before the program is released. + * This provides a mechanism for the application (and libraries) to be notified when destructors + * are complete. + * + * \param program is a valid program object + * + * \param pfn_notify is the callback function that can be registered by the application. This + * callback function may be called asynchronously by the OpenCL implementation. It is the + * application's responsibility to ensure that the callback function is thread safe. The parameters + * to this callback function are: + * - \a prog is the program object whose destructors are being called. When the user callback is + * called by the implementation, this program object is not longer valid. \a prog is only provided + * for reference purposes. + * - \a user_data is a pointer to user supplied data. \a user_data will be passed as the + * \a user_data argument when pfn_notify is called. user data can be NULL. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_PROGRAM if program is not a valid program object. + * - CL_INVALID_VALUE if pfn_notify is NULL. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL + * implementation on the device. + * + * \version 2.2-3 + */ +RUNTIME_ENTRY(cl_int, clSetProgramReleaseCallback, + (cl_program program, void (CL_CALLBACK *pfn_notify)( + cl_program program, void *user_data + ), void *user_data)) { + if (!is_valid(program)) { + return CL_INVALID_PROGRAM; + } + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +/*! @} + * @} + * + * \addtogroup CL_Kernels + * + * A kernel is a function declared in a program. A kernel is identified by the + * __kernel qualifier applied to any function in a program. A kernel object + * encapsulates the specific __kernel function declared in a program and + * the argument values to be used when executing this __kernel function. + * + * @{ + * + * \addtogroup CL_CreateKernel + * @{ + */ + +/*! \brief Create a kernel object. + * + * \param program is a program object with a successfully built executable. + * + * \param kernel_name is a function name in the program declared with the + * __kernel qualifier. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A valid non-zero kernel object and \a errcode_ret is set to + * CL_SUCCESS if the kernel object is created successfully. It returns a NULL + * value with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_PROGRAM if \a program is not a valid program object + * - CL_INVALID_PROGRAM_EXECUTABLE if there is no successfully built executable + * for \a program. + * - CL_INVALID_KERNEL_NAME if \a kernel_name is not found in \a program. + * - CL_INVALID_KERNEL_DEFINITION if the function definition for __kernel + * function given by \a kernel_name such as the number of arguments, the + * argument types are not the same for all devices for which the program + * executable has been built. + * - CL_INVALID_VALUE if \a kernel_name is NULL. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY_RET(cl_kernel, clCreateKernel, + (cl_program program, const char* kernel_name, cl_int* errcode_ret)) { + if (!is_valid(program)) { + *not_null(errcode_ret) = CL_INVALID_PROGRAM; + return (cl_kernel)0; + } + if (kernel_name == NULL) { + *not_null(errcode_ret) = CL_INVALID_VALUE; + return (cl_kernel)0; + } + /* FIXME_lmoriche, FIXME_spec: What are we supposed to do here? + * if (!as_amd(program)->containsOneSuccesfullyBuiltProgram()) + * { + * *NotNull(errcode) = CL_INVALID_PROGRAM_EXECUTABLE; + * return (cl_kernel) 0; + * } + */ + amd::Program* amd_program = as_amd(program); + + if (!amd_program->load()) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_kernel)0; + } + + const amd::Symbol* symbol = amd_program->findSymbol(kernel_name); + if (symbol == NULL) { + *not_null(errcode_ret) = CL_INVALID_KERNEL_NAME; + return (cl_kernel)0; + } + + amd::Kernel* kernel = new amd::Kernel(*amd_program, *symbol, kernel_name); + if (kernel == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_kernel)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(kernel); +} +RUNTIME_EXIT + +/*! \brief Create kernel objects for all kernel functions in program. + * + * Kernel objects may not be created for any __kernel functions in program + * that do not have the same function definition across all devices for which + * a program executable has been successfully built. + * + * \param program is a program object with a successfully built executable. + * + * \param num_kernels is the size of memory pointed to by \a kernels specified + * as the number of cl_kernel entries. + * + * \param kernels is the buffer where the kernel objects for kernels in + * \a program will be returned. If \a kernels is NULL, it is ignored. + * If \a kernels is not NULL, \a num_kernels must be greater than or equal + * to the number of kernels in program. + * + * \param num_kernels_ret is the number of kernels in program. If + * \a num_kernels_ret is NULL, it is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the kernel objects were successfully allocated + * - CL_INVALID_PROGRAM if \a program is not a valid program object + * - CL_INVALID_PROGRAM_EXECUTABLE if there is no successfully built executable + * for any device in \a program + * - CL_INVALID_VALUE if \a kernels is not NULL and \a num_kernels is less + * than the number of kernels in program + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * Kernel objects can only be created once you have a program object with a + * valid program source or binary loaded into the program object and the + * program executable has been successfully built for one or more devices + * associated with \a program. No changes to the program executable are + * allowed while there are kernel objects associated with a program object. + * This means that calls to clBuildProgram return CL_INVALID_OPERATION if there + * are kernel objects attached to a program object. The OpenCL context + * associated with program will be the context associated with kernel. + * Devices associated with a program object for which a valid program + * executable has been built can be used to execute kernels declared in the + * program object. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clCreateKernelsInProgram, (cl_program program, cl_uint num_kernels, + cl_kernel* kernels, cl_uint* num_kernels_ret)) { + if (!is_valid(program)) { + return CL_INVALID_PROGRAM; + } + + amd::Program* amd_program = as_amd(program); + + if (!amd_program->load()) { + return CL_OUT_OF_HOST_MEMORY; + } + + cl_uint numKernels = (cl_uint)amd_program->symbols().size(); + + if (kernels != NULL && num_kernels < numKernels) { + return CL_INVALID_VALUE; + } + *not_null(num_kernels_ret) = numKernels; + if (kernels == NULL) { + return CL_SUCCESS; + } + + const amd::Program::symbols_t& symbols = amd_program->symbols(); + cl_kernel* result = kernels; + + for (const auto& it : symbols) { + amd::Kernel* kernel = new amd::Kernel(*amd_program, it.second, it.first); + if (kernel == NULL) { + while (--result >= kernels) { + as_amd(*result)->release(); + } + return CL_OUT_OF_HOST_MEMORY; + } + *result++ = as_cl(kernel); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Increment the kernel reference count. + * + * \return CL_SUCCESS if the function is executed successfully. It returns + * CL_INVALID_KERNEL if \a kernel is not a valid kernel object. + * + * clCreateKernel or clCreateKernelsInProgram do an implicit retain. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clRetainKernel, (cl_kernel kernel)) { + if (!is_valid(kernel)) { + return CL_INVALID_KERNEL; + } + as_amd(kernel)->retain(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Decrement the kernel reference count. + * + * \return CL_SUCCESS if the function is executed successfully. It returns + * CL_INVALID_KERNEL if \a kernel is not a valid kernel object. + * + * The kernel object is deleted once the number of instances that are retained + * to \a kernel become zero and after all queued execution instances of + * \a kernel have finished. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clReleaseKernel, (cl_kernel kernel)) { + if (!is_valid(kernel)) { + return CL_INVALID_KERNEL; + } + as_amd(kernel)->release(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Makes a shallow copy of the kernel object, its arguments and any + * information passed to the kernel object using \a clSetKernelExecInfo. If + * the kernel object was ready to be enqueued before copying it, the clone of + * the kernel object is ready to enqueue. + * + * \param source_kernel is a valid cl_kernel object that will be copied. + * source_kernel will not be modified in any way by this function. + * + * \param errcode_ret will be assigned an appropriate error code. If + * errcode_ret is NULL, no error code is returned. + * + * \return a valid non-zero kernel object and errcode_ret is set to + * CL_SUCCESS if the kernel is successfully copied. Otherwise it returns a + * NULL value with one of the following error values returned in errcode_ret: + * - CL_INVALID_KERNEL if kernel is not a valid kernel object. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources + * required by the OpenCL implementation on the host. + * + * \version 2.1r01 + */ +RUNTIME_ENTRY_RET(cl_kernel, clCloneKernel, + (cl_kernel source_kernel, cl_int* errcode_ret)) { + if (!is_valid(source_kernel)) { + *not_null(errcode_ret) = CL_INVALID_KERNEL; + return (cl_kernel)0; + } + + amd::Kernel* kernel = new amd::Kernel(*as_amd(source_kernel)); + if (kernel == NULL) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + return (cl_kernel)0; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(kernel); +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_SettingArgs + * @{ + */ + +/*! \brief Set the argument value for a specific argument of a kernel. + * + * \param kernel is a valid kernel object. + * + * \param arg_index is the argument index. Arguments to the kernel are referred + * by indices that go from 0 for the leftmost argument to n - 1, where n is the + * total number of arguments declared by a kernel. + * + * \param arg_value is a pointer to data that should be used as the argument + * value for argument specified by \a arg_index. The argument data pointed to + * by \a arg_value is copied and the \a arg_value pointer can therefore be + * reused by the application after clSetKernelArg returns. If the argument is + * a memory object (buffer or image), the \a arg_value entry will be a pointer + * to the appropriate buffer or image object. The memory object must be created + * with the context associated with the kernel object. If the argument is + * declared with the __local qualifier, the \a arg_value entry must be NULL. + * For all other kernel arguments, the \a arg_value entry must be a pointer to + * the actual data to be used as argument value. The memory object specified + * as argument value must be a buffer object if the argument is declared to be + * a pointer of a built-in or user defined type with the __global or __constant + * qualifier. If the argument is declared with the __constant qualifier, the + * size in bytes of the memory object cannot exceed + * CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE and the number of arguments declared + * with the __constant qualifier cannot exceed CL_DEVICE_MAX_CONSTANT_ARGS. The + * memory object specified as argument value must be a 2D image object if the + * argument is declared to be of type image2d_t. The memory object specified as + * argument value must be a 3D image object if argument is declared to be of + * type image3d_t. If the argument is of type sampler_t, the arg_value entry + * must be a pointer to the sampler object. + * + * \param arg_size specifies the size of the argument value. If the argument is + * a memory object, the size is the size of the buffer or image object type. + * For arguments declared with the __local qualifier, the size specified will + * be the size in bytes of the buffer that must be allocated for the __local + * argument. If the argument is of type sampler_t, the arg_size value must be + * equal to sizeof(cl_sampler). For all other arguments, the size will be the + * size of argument type. + * + * \return One of the following values: + * - CL_SUCCESS if the function was executed successfully + * - CL_INVALID_KERNEL if \a kernel is not a valid kernel object. + * - CL_INVALID_ARG_INDEX if \a arg_index is not a valid argument index. + * - CL_INVALID_ARG_VALUE if \a arg_value specified is NULL for an argument + * that is not declared with the __local qualifier or vice-versa. + * - CL_INVALID_MEM_OBJECT for an argument declared to be a memory object but + * the specified \a arg_value is not a valid memory object. + * - CL_INVALID_SAMPLER for an argument declared to be of type sampler_t but + * the specified \a arg_value is not a valid sampler object. + * - CL_INVALID_ARG_SIZE if \a arg_size does not match the size of the data + * type for an argument that is not a memory object or if the argument is a + * memory object and \a arg_size != sizeof(cl_mem) or if \a arg_size is zero + * and the argument is declared with the __local qualifier or if the + * argument is a sampler and arg_size != sizeof(cl_sampler). + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clSetKernelArg, + (cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void* arg_value)) { + if (!is_valid(kernel)) { + return CL_INVALID_KERNEL; + } + + const amd::KernelSignature& signature = as_amd(kernel)->signature(); + if (arg_index >= signature.numParameters()) { + return CL_INVALID_ARG_INDEX; + } + + const amd::KernelParameterDescriptor& desc = signature.at(arg_index); + const bool is_local = (desc.addressQualifier_ == CL_KERNEL_ARG_ADDRESS_LOCAL); + if (((arg_value == NULL) && !is_local && (desc.type_ != T_POINTER)) || + ((arg_value != NULL) && is_local)) { + as_amd(kernel)->parameters().reset(static_cast(arg_index)); + return CL_INVALID_ARG_VALUE; + } + if (!is_local && (desc.type_ == T_POINTER) && (arg_value != NULL)) { + cl_mem memObj = *static_cast(arg_value); + amd::RuntimeObject* pObject = as_amd(memObj); + if (NULL != memObj && amd::RuntimeObject::ObjectTypeMemory != pObject->objectType()) { + as_amd(kernel)->parameters().reset(static_cast(arg_index)); + return CL_INVALID_MEM_OBJECT; + } + } else if ((desc.type_ == T_SAMPLER) && !is_valid(*static_cast(arg_value))) { + return CL_INVALID_SAMPLER; + } else if (desc.type_ == T_QUEUE) { + cl_command_queue queue = *static_cast(arg_value); + if (!is_valid(queue)) { + as_amd(kernel)->parameters().reset(static_cast(arg_index)); + return CL_INVALID_DEVICE_QUEUE; + } + if (NULL == as_amd(queue)->asDeviceQueue()) { + as_amd(kernel)->parameters().reset(static_cast(arg_index)); + return CL_INVALID_DEVICE_QUEUE; + } + } + if ((!is_local && (arg_size != desc.size_)) || (is_local && (arg_size == 0))) { + if (LP64_ONLY(true ||) ((desc.type_ != T_POINTER) && (desc.type_ != T_SAMPLER)) || + (arg_size != sizeof(void*))) { + as_amd(kernel)->parameters().reset(static_cast(arg_index)); + return CL_INVALID_ARG_SIZE; + } + } + + as_amd(kernel)->parameters().set(static_cast(arg_index), arg_size, arg_value); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * \addtogroup CL_KernelQuery + * @{ + */ + +/*! \brief Return information about the kernel object. + * + * \param kernel specifies the kernel object being queried. + * + * \param param_name specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result + * being queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data copied + * to \a param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully + * - CL_INVALID_VALUE if \a param_name is not valid, or if size in bytes + * specified by \a param_value_size is < size of return type and + * \a param_value is not NULL + * - CL_INVALID_KERNEL if \a kernel is a not a valid kernel object. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clGetKernelInfo, + (cl_kernel kernel, cl_kernel_info param_name, size_t param_value_size, + void* param_value, size_t* param_value_size_ret)) { + // Check if we have a valid kernel + if (!is_valid(kernel)) { + return CL_INVALID_KERNEL; + } + + const amd::Kernel* amdKernel = as_amd(kernel); + + // Get the corresponded parameters + switch (param_name) { + case CL_KERNEL_FUNCTION_NAME: { + const char* name = amdKernel->name().c_str(); + // Return the kernel's name + return amd::clGetInfo(name, param_value_size, param_value, param_value_size_ret); + } + case CL_KERNEL_NUM_ARGS: { + cl_uint numParam = static_cast(amdKernel->signature().numParameters()); + // Return the number of kernel's parameters + return amd::clGetInfo(numParam, param_value_size, param_value, param_value_size_ret); + } + case CL_KERNEL_REFERENCE_COUNT: { + cl_uint count = amdKernel->referenceCount(); + // Return the reference counter + return amd::clGetInfo(count, param_value_size, param_value, param_value_size_ret); + } + case CL_KERNEL_CONTEXT: { + cl_context context = const_cast(as_cl(&amdKernel->program().context())); + // Return the context, associated with the program + return amd::clGetInfo(context, param_value_size, param_value, param_value_size_ret); + } + case CL_KERNEL_PROGRAM: { + cl_program program = const_cast(as_cl(&amdKernel->program())); + // Return the program, associated with the kernel + return amd::clGetInfo(program, param_value_size, param_value, param_value_size_ret); + } + case CL_KERNEL_ATTRIBUTES: { + const char* name = amdKernel->signature().attributes().c_str(); + // Return the kernel attributes + return amd::clGetInfo(name, param_value_size, param_value, param_value_size_ret); + } + default: + return CL_INVALID_VALUE; + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Returns information about the arguments of a kernel. Kernel + * argument information is only available if the program object associated + * with kernel is created with \a clCreateProgramWithSource and the program + * executable is built with the -cl-kernel-arg-info option specified in + * options argument to clBuildProgram or clCompileProgram. + * + * \param kernel specifies the kernel object being queried. + * + * \param param_name specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result + * being queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data copied + * to \a param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully + * - CL_INVALID_VALUE if \a param_name is not valid, or if size in bytes + * specified by \a param_value_size is < size of return type and + * \a param_value is not NULL + * - CL_INVALID_KERNEL if \a kernel is a not a valid kernel object. + * + * \version 1.2r07 + */ +RUNTIME_ENTRY(cl_int, clGetKernelArgInfo, + (cl_kernel kernel, cl_uint arg_indx, cl_kernel_arg_info param_name, + size_t param_value_size, void* param_value, size_t* param_value_size_ret)) { + // Check if we have a valid kernel + if (!is_valid(kernel)) { + return CL_INVALID_KERNEL; + } + + amd::Kernel* amdKernel = as_amd(kernel); + + const amd::KernelSignature& signature = amdKernel->signature(); + if (arg_indx >= signature.numParameters()) { + return CL_INVALID_ARG_INDEX; + } + + const amd::KernelParameterDescriptor& desc = signature.at(arg_indx); + + // Get the corresponded parameters + switch (param_name) { + case CL_KERNEL_ARG_ADDRESS_QUALIFIER: { + cl_kernel_arg_address_qualifier qualifier = desc.addressQualifier_; + return amd::clGetInfo(qualifier, param_value_size, param_value, param_value_size_ret); + } + case CL_KERNEL_ARG_ACCESS_QUALIFIER: { + cl_kernel_arg_access_qualifier qualifier = desc.accessQualifier_; + return amd::clGetInfo(qualifier, param_value_size, param_value, param_value_size_ret); + } + case CL_KERNEL_ARG_TYPE_NAME: { + const char* typeName = desc.typeName_.c_str(); + // Return the argument's type name + return amd::clGetInfo(typeName, param_value_size, param_value, param_value_size_ret); + } + case CL_KERNEL_ARG_TYPE_QUALIFIER: { + cl_kernel_arg_type_qualifier qualifier = desc.typeQualifier_; + return amd::clGetInfo(qualifier, param_value_size, param_value, param_value_size_ret); + } + case CL_KERNEL_ARG_NAME: { + const char* name = desc.name_.c_str(); + // Return the argument's name + return amd::clGetInfo(name, param_value_size, param_value, param_value_size_ret); + } + default: + return CL_INVALID_VALUE; + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Return information about the kernel object that may be specific + * to a device. + * + * \param kernel specifies the kernel object being queried. + * + * \param device identifies a specific device in the list of devices associated + * with \a kernel. The list of devices is the list of devices in the OpenCL + * context that is associated with \a kernel. If the list of devices associated + * with kernel is a single device, \a device can be a NULL value. + * + * \param param_name specifies the information to query + * + * \param param_value is a pointer to memory where the appropriate result being + * queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data copied + * to \a param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully, + * - CL_INVALID_DEVICE if \a device is not in the list of devices associated + * with \a kernel or if \a device is NULL but there are more than one + * devices in the associated with \a kernel + * - CL_INVALID_VALUE if \a param_name is not valid, or if size in bytes + * specified by \a param_value_size is < size of return type and + * \a param_value is not NULL + * - CL_INVALID_KERNEL if \a kernel is a not a valid kernel object. + * + * \version 1.2r15 + */ +RUNTIME_ENTRY(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)) { + // Check if we have a valid device + if (!is_valid(device)) { + return CL_INVALID_DEVICE; + } + + // Check if we have a valid kernel + if (!is_valid(kernel)) { + return CL_INVALID_KERNEL; + } + + + const amd::Device& amdDevice = *as_amd(device); + // Find the kernel, associated with the specified device + const device::Kernel* devKernel = as_amd(kernel)->getDeviceKernel(amdDevice); + + // Make sure we found a valid kernel + if (devKernel == NULL) { + return CL_INVALID_KERNEL; + } + + // Get the corresponded parameters + switch (param_name) { + case CL_KERNEL_WORK_GROUP_SIZE: { + // Return workgroup size + return amd::clGetInfo(devKernel->workGroupInfo()->size_, param_value_size, param_value, + param_value_size_ret); + } + case CL_KERNEL_COMPILE_WORK_GROUP_SIZE: { + // Return the compile workgroup size + return amd::clGetInfo(devKernel->workGroupInfo()->compileSize_, param_value_size, param_value, + param_value_size_ret); + } + case CL_KERNEL_LOCAL_MEM_SIZE: { + // Return the amount of used local memory + const size_t align = amdDevice.info().minDataTypeAlignSize_; + cl_ulong memSize = as_amd(kernel)->parameters().localMemSize(align) + + amd::alignUp(devKernel->workGroupInfo()->localMemSize_, align); + return amd::clGetInfo(memSize, param_value_size, param_value, param_value_size_ret); + } + case CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE: { + // Return the compile workgroup size + return amd::clGetInfo(devKernel->workGroupInfo()->preferredSizeMultiple_, param_value_size, + param_value, param_value_size_ret); + } + case CL_KERNEL_PRIVATE_MEM_SIZE: { + // Return the compile workgroup size + return amd::clGetInfo(devKernel->workGroupInfo()->privateMemSize_, param_value_size, + param_value, param_value_size_ret); + } + case CL_KERNEL_GLOBAL_WORK_SIZE: { + return CL_INVALID_VALUE; + } + case CL_KERNEL_MAX_SEMAPHORE_SIZE_AMD: { + return amd::clGetInfo(amdDevice.info().maxSemaphoreSize_, param_value_size, param_value, + param_value_size_ret); + } + default: + return CL_INVALID_VALUE; + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Returns information about the kernel object. + * + * \param kernel specifies the kernel object being queried. + * + * \param device identifies a specific device in the list of devices associated + * with kernel. The list of devices is the list of devices in the OpenCL context + * that is associated with kernel. If the list of devices associated with kernel + * is a single device, device can be a NULL value. + * + * \param param_name specifies the information to query. The list of supported + * param_name types and the information returned in param_value by + * clGetKernelSubGroupInfo is described in the table below. + * + * \param input_value_size is used to specify the size in bytes of memory + * pointed to by input_value. This size must be == size of input type as + * described in the table below. + * + * \param input_value is a pointer to memory where the appropriate + * parameterization of the query is passed from. If input_value is NULL, it is + * ignored. + * + * \param param_value is a pointer to memory where the appropriate result being + * queried is returned. If param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by param_value. This size must be >= size of return type as + * described in the table below. + * + * \param param_value_size_ret returns the actual size in bytes of data copied + * to param_value. If param_value_size_ret is NULL, it is ignored. + * + * \return CL_SUCCESS if the function is executed successfully. + * Otherwise, it returns one of the following errors: + * + * - CL_INVALID_DEVICE if device is not in the list of devices associated with + * kernel or if device is NULL but there is more than one device associated + * with kernel. + * - CL_INVALID_VALUE if param_name is not valid, or if size in bytes specified + * by param_value_size is < size of return type as described in the table + * above and param_value is not NULL. + * - CL_INVALID_VALUE if param_name is CL_KERNEL_SUB_GROUP_SIZE_FOR_NDRANGE and + * the size in bytes specified by input_value_size is not valid or if + * input_value is NULL. + * - CL_INVALID_KERNEL if kernel is a not a valid kernel object. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by + * the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 2.0r12 + */ +RUNTIME_ENTRY(cl_int, clGetKernelSubGroupInfo, + (cl_kernel kernel, cl_device_id device, cl_kernel_sub_group_info param_name, + size_t input_value_size, const void* input_value, size_t param_value_size, + void* param_value, size_t* param_value_size_ret)) { + // Check if we have a valid device + if (!is_valid(device)) { + return CL_INVALID_DEVICE; + } + + // Check if we have a valid kernel + if (!is_valid(kernel)) { + return CL_INVALID_KERNEL; + } + + + const amd::Device& amdDevice = *as_amd(device); + // Find the kernel, associated with the specified device + const device::Kernel* devKernel = as_amd(kernel)->getDeviceKernel(amdDevice); + + // Make sure we found a valid kernel + if (devKernel == NULL) { + return CL_INVALID_KERNEL; + } + + // Get the corresponded parameters + switch (param_name) { + case CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE: + case CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE: { + // Infer the number of dimensions from 'input_value_size' + size_t dims = input_value_size / sizeof(size_t); + if (dims == 0 || dims > 3 || input_value_size != dims * sizeof(size_t)) { + return CL_INVALID_VALUE; + } + + // Get the linear workgroup size + size_t workGroupSize = ((size_t*)input_value)[0]; + for (size_t i = 1; i < dims; ++i) { + workGroupSize *= ((size_t*)input_value)[i]; + } + + // Get the subgroup size. GPU devices sub-groups are wavefronts. + size_t subGroupSize = as_amd(device)->info().wavefrontWidth_; + + size_t numSubGroups = (workGroupSize + subGroupSize - 1) / subGroupSize; + + + return amd::clGetInfo((param_name == CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR) + ? subGroupSize + : numSubGroups, + param_value_size, param_value, param_value_size_ret); + } + case CL_KERNEL_COMPILE_NUM_SUB_GROUPS: { + size_t numSubGroups = 0; + return amd::clGetInfo(numSubGroups, param_value_size, param_value, param_value_size_ret); + } + case CL_KERNEL_MAX_NUM_SUB_GROUPS: { + size_t waveSize = as_amd(device)->info().wavefrontWidth_; + size_t numSubGroups = (devKernel->workGroupInfo()->size_ + waveSize - 1) / waveSize; + return amd::clGetInfo(numSubGroups, param_value_size, param_value, param_value_size_ret); + } + case CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT: { + if (input_value_size != sizeof(size_t)) { + return CL_INVALID_VALUE; + } + size_t numSubGroups = ((size_t*)input_value)[0]; + + // Infer the number of dimensions from 'param_value_size' + size_t dims = param_value_size / sizeof(size_t); + if (dims == 0 || dims > 3 || param_value_size != dims * sizeof(size_t)) { + return CL_INVALID_VALUE; + } + *not_null(param_value_size_ret) = param_value_size; + + size_t localSize; + localSize = numSubGroups * as_amd(device)->info().wavefrontWidth_; + if (localSize > devKernel->workGroupInfo()->size_) { + ::memset(param_value, '\0', dims * sizeof(size_t)); + return CL_SUCCESS; + } + + switch (dims) { + case 3: + ((size_t*)param_value)[2] = 1; + case 2: + ((size_t*)param_value)[1] = 1; + case 1: + ((size_t*)param_value)[0] = localSize; + } + return CL_SUCCESS; + } + default: + return CL_INVALID_VALUE; + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * @} + * @} + */ diff --git a/opencl/amdocl/cl_runtime.cpp b/opencl/amdocl/cl_runtime.cpp new file mode 100644 index 0000000000..c4b9f42502 --- /dev/null +++ b/opencl/amdocl/cl_runtime.cpp @@ -0,0 +1,59 @@ +/* Copyright (c) 2008 - 2022 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "thread/thread.hpp" +#include "platform/runtime.hpp" + +#include +#include + +#ifdef DEBUG +static int reportHook(int reportType, char* message, int* returnValue) { + if (returnValue) { + *returnValue = 1; + } + std::cerr << message; + ::exit(3); + return TRUE; +} +#endif // DEBUG + +extern "C" BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) { + switch (reason) { + case DLL_PROCESS_ATTACH: +#ifdef DEBUG + if (!::getenv("AMD_OCL_ENABLE_MESSAGE_BOX")) { + _CrtSetReportHook(reportHook); + _set_error_mode(_OUT_TO_STDERR); + } +#endif // DEBUG + break; + case DLL_PROCESS_DETACH: + amd::Runtime::setLibraryDetached(); + break; + case DLL_THREAD_DETACH: { + amd::Thread* thread = amd::Thread::current(); + delete thread; + } break; + default: + break; + } + return true; +} diff --git a/opencl/amdocl/cl_sampler.cpp b/opencl/amdocl/cl_sampler.cpp new file mode 100644 index 0000000000..8241710c64 --- /dev/null +++ b/opencl/amdocl/cl_sampler.cpp @@ -0,0 +1,359 @@ +/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" + +#include "platform/context.hpp" +#include "platform/sampler.hpp" + + +/*! \addtogroup API + * @{ + * + * \addtogroup CL_Samplers + * + * A sampler object describes how to sample an image when the image is read + * in the kernel. The built-in functions to read from an image in a kernel + * take a sampler as an argument. The sampler arguments to the image read + * function can be sampler objects created using OpenCL functions and passed + * as argument values to the kernel or can be samplers declared inside + * a kernel. + * + * @{ + */ + +/*! \brief Create a sampler object. + * + * \param context must be a valid OpenCL context. + * + * \param specifies a list of sampler property names and their corresponding + * values. Each sampler property name is immediately followed by the + * corresponding desired value. The list is terminated with 0. If a supported + * property and its value is not specified in sampler_properties, its default + * value will be used. sampler_properties can be NULL in which case the default + * values for supported sampler properties will be used. + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A valid non-zero sampler object and \a errcode_ret is set to + * CL_SUCCESS if the sampler object is created successfully. It returns a NULL + * value with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a context is not a valid context. + * - CL_INVALID_VALUE if the property name in sampler_properties is not a + * supported property name, if the value specified for a supported property + * name is not valid, or if the same property name is specified more than + * once + * - CL_INVALID_OPERATION if images are not supported by any device associated + * with context + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 2.0r19 + */ +RUNTIME_ENTRY_RET(cl_sampler, clCreateSamplerWithProperties, + (cl_context context, const cl_sampler_properties* sampler_properties, + cl_int* errcode_ret)) { + if (!is_valid(context)) { + *not_null(errcode_ret) = CL_INVALID_CONTEXT; + LogWarning("invalid parameter \"context\""); + return (cl_sampler)0; + } + + cl_bool normalizedCoords = CL_TRUE; + cl_addressing_mode addressingMode = CL_ADDRESS_CLAMP; + cl_filter_mode filterMode = CL_FILTER_NEAREST; +#ifndef CL_FILTER_NONE +#define CL_FILTER_NONE 0x1142 +#endif + cl_filter_mode mipFilterMode = CL_FILTER_NONE; + float minLod = 0.f; + float maxLod = CL_MAXFLOAT; + + const struct SamplerProperty { + cl_sampler_properties name; + union { + cl_sampler_properties raw; + cl_bool normalizedCoords; + cl_addressing_mode addressingMode; + cl_filter_mode filterMode; + cl_float lod; + } value; + }* p = reinterpret_cast(sampler_properties); + + if (p != NULL) + while (p->name != 0) { + switch (p->name) { + case CL_SAMPLER_NORMALIZED_COORDS: + normalizedCoords = p->value.normalizedCoords; + break; + case CL_SAMPLER_ADDRESSING_MODE: + addressingMode = p->value.addressingMode; + break; + case CL_SAMPLER_FILTER_MODE: + filterMode = p->value.filterMode; + break; + case CL_SAMPLER_MIP_FILTER_MODE: + mipFilterMode = p->value.filterMode; + break; + case CL_SAMPLER_LOD_MIN: + minLod = p->value.lod; + break; + case CL_SAMPLER_LOD_MAX: + maxLod = p->value.lod; + break; + default: + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid property name"); + return (cl_sampler)0; + } + ++p; + } + + // Check sampler validity + // Check addressing mode + switch (addressingMode) { + case CL_ADDRESS_NONE: + case CL_ADDRESS_CLAMP_TO_EDGE: + case CL_ADDRESS_CLAMP: + break; + case CL_ADDRESS_REPEAT: + if (!normalizedCoords) { + // repeat mode cannot be used with unnormalized coordinates + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid combination for sampler"); + return (cl_sampler)0; + } + break; + case CL_ADDRESS_MIRRORED_REPEAT: + if (!normalizedCoords) { + // repeat mode cannot be used with unnormalized coordinates + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid combination for sampler"); + return (cl_sampler)0; + } + break; + default: + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid addressing mode"); + return (cl_sampler)0; + } + // Check filter mode + switch (filterMode) { + case CL_FILTER_NEAREST: + case CL_FILTER_LINEAR: + break; + default: + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid filter mode"); + return (cl_sampler)0; + } + switch (mipFilterMode) { + case CL_FILTER_NONE: + case CL_FILTER_NEAREST: + case CL_FILTER_LINEAR: + break; + default: + *not_null(errcode_ret) = CL_INVALID_VALUE; + LogWarning("invalid filter mode"); + return (cl_sampler)0; + } + // Create instance of Sampler + amd::Sampler* sampler = + new amd::Sampler(*as_amd(context), + normalizedCoords == CL_TRUE, // To get rid of VS warning C4800 + addressingMode, filterMode, mipFilterMode, minLod, maxLod); + if (!sampler) { + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + LogWarning("not enough host memory"); + return (cl_sampler)0; + } + + if (!sampler->create()) { + delete sampler; + *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; + LogWarning("Runtime failed sampler creation!"); + return as_cl(0); + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(sampler); +} +RUNTIME_EXIT + +/*! \brief Create a sampler object. + * + * \param context must be a valid OpenCL context. + * + * \param addressing_mode specifies how out of range image coordinates are + * handled when reading from an image. This can be set to CL_ADDRESS_REPEAT, + * CL_ADDRESS_CLAMP_TO_EDGE, CL_ADDRESS_CLAMP and CL_ADDRESS_NONE. + * + * \param filter_mode specifies the type of filter that must be applied when + * reading an image. This can be CL_FILTER_NEAREST or CL_FILTER_LINEAR. + * + * \param normalized_coords determines if the image coordinates specified are + * normalized (if \a normalized_coords is not zero) or not (if + * \a normalized_coords is zero). + * + * \param errcode_ret will return an appropriate error code. If \a errcode_ret + * is NULL, no error code is returned. + * + * \return A valid non-zero sampler object and \a errcode_ret is set to + * CL_SUCCESS if the sampler object is created successfully. It returns a NULL + * value with one of the following error values returned in \a errcode_ret: + * - CL_INVALID_CONTEXT if \a context is not a valid context. + * - CL_INVALID_VALUE if \a addressing_mode, \a filter_mode or + * \a normalized_coords or combination of these argument values are not + * valid. + * - CL_INVALID_OPERATION if images are not supported by any device associated + * with context + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the runtime. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY_RET(cl_sampler, clCreateSampler, (cl_context context, cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, cl_int* errcode_ret)) { + const cl_sampler_properties sprops[] = {CL_SAMPLER_NORMALIZED_COORDS, + static_cast(normalized_coords), + CL_SAMPLER_ADDRESSING_MODE, + static_cast(addressing_mode), + CL_SAMPLER_FILTER_MODE, + static_cast(filter_mode), + 0}; + return clCreateSamplerWithProperties(context, sprops, errcode_ret); +} +RUNTIME_EXIT + +/*! \brief Increment the sampler reference count. + * + * clCreateSampler does an implicit retain. + * + * \return CL_SUCCESS if the function is executed successfully. It returns + * CL_INVALID_SAMPLER if \a sampler is not a valid sampler object. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clRetainSampler, (cl_sampler sampler)) { + if (!is_valid(sampler)) { + return CL_INVALID_SAMPLER; + } + as_amd(sampler)->retain(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Decrement the sampler reference count. + * + * The sampler object is deleted after the reference count becomes zero and + * commands queued for execution on a command-queue(s) that use sampler have + * finished. + * + * \return CL_SUCCESS if the function is executed successfully. It returns + * CL_INVALID_SAMPLER if \a sampler is not a valid sampler object. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clReleaseSampler, (cl_sampler sampler)) { + if (!is_valid(sampler)) { + return CL_INVALID_SAMPLER; + } + as_amd(sampler)->release(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Return information about the sampler object. + * + * \param sampler specifies the sampler being queried. + * + * \param param_name specifies the information to query. + * + * \param param_value is a pointer to memory where the appropriate result + * being queried is returned. If \a param_value is NULL, it is ignored. + * + * \param param_value_size is used to specify the size in bytes of memory + * pointed to by \a param_value. This size must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data copied + * to \a param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully + * - CL_INVALID_VALUE if \a param_name is not valid, or if size in bytes + * specified by \a param_value_size is < size of return type and + * \a param_value is not NULL + * - CL_INVALID_SAMPLER if \a sampler is a not a valid sampler object. + * + * \version 1.0r33 + */ +RUNTIME_ENTRY(cl_int, clGetSamplerInfo, + (cl_sampler sampler, cl_sampler_info param_name, size_t param_value_size, + void* param_value, size_t* param_value_size_ret)) { + if (!is_valid(sampler)) { + return CL_INVALID_SAMPLER; + } + + switch (param_name) { + case CL_SAMPLER_REFERENCE_COUNT: { + cl_uint count = as_amd(sampler)->referenceCount(); + return amd::clGetInfo(count, param_value_size, param_value, param_value_size_ret); + } + case CL_SAMPLER_CONTEXT: { + cl_context context = as_cl(&as_amd(sampler)->context()); + return amd::clGetInfo(context, param_value_size, param_value, param_value_size_ret); + } + case CL_SAMPLER_ADDRESSING_MODE: { + cl_addressing_mode addressing = as_amd(sampler)->addressingMode(); + return amd::clGetInfo(addressing, param_value_size, param_value, param_value_size_ret); + } + case CL_SAMPLER_FILTER_MODE: { + cl_filter_mode filter = as_amd(sampler)->filterMode(); + return amd::clGetInfo(filter, param_value_size, param_value, param_value_size_ret); + } + case CL_SAMPLER_NORMALIZED_COORDS: { + cl_bool normalized = as_amd(sampler)->normalizedCoords(); + return amd::clGetInfo(normalized, param_value_size, param_value, param_value_size_ret); + } + case CL_SAMPLER_MIP_FILTER_MODE: { + cl_filter_mode mipFilter = as_amd(sampler)->mipFilter(); + return amd::clGetInfo(mipFilter, param_value_size, param_value, param_value_size_ret); + } + case CL_SAMPLER_LOD_MIN: { + cl_float minLod = as_amd(sampler)->minLod(); + return amd::clGetInfo(minLod, param_value_size, param_value, param_value_size_ret); + } + case CL_SAMPLER_LOD_MAX: { + cl_float maxLod = as_amd(sampler)->maxLod(); + return amd::clGetInfo(maxLod, param_value_size, param_value, param_value_size_ret); + } + default: + break; + } + + return CL_INVALID_VALUE; +} +RUNTIME_EXIT + +/*! @} + * @} + */ diff --git a/opencl/amdocl/cl_sdi_amd.cpp b/opencl/amdocl/cl_sdi_amd.cpp new file mode 100644 index 0000000000..ef86757886 --- /dev/null +++ b/opencl/amdocl/cl_sdi_amd.cpp @@ -0,0 +1,241 @@ +/* Copyright (c) 2012 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include "cl_sdi_amd.h" +#include "platform/context.hpp" +#include "platform/command.hpp" +#include "platform/memory.hpp" +#include + + +RUNTIME_ENTRY(cl_int, clEnqueueWaitSignalAMD, + (cl_command_queue command_queue, cl_mem mem_object, cl_uint value, cl_uint num_events, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(mem_object)) { + return CL_INVALID_MEM_OBJECT; + } + + amd::Buffer* buffer = as_amd(mem_object)->asBuffer(); + if (buffer == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + if (!(buffer->getMemFlags() & CL_MEM_BUS_ADDRESSABLE_AMD)) { + return CL_INVALID_MEM_OBJECT; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != buffer->getContext()) { + return CL_INVALID_CONTEXT; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = + amd::clSetEventWaitList(eventWaitList, hostQueue, num_events, event_wait_list); + + if (err != CL_SUCCESS) { + return err; + } + + amd::SignalCommand* command = + new amd::SignalCommand(hostQueue, CL_COMMAND_WAIT_SIGNAL_AMD, eventWaitList, *buffer, value); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_OUT_OF_RESOURCES; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + + +RUNTIME_ENTRY(cl_int, clEnqueueWriteSignalAMD, + (cl_command_queue command_queue, cl_mem mem_object, cl_uint value, cl_ulong offset, + cl_uint num_events, const cl_event* event_wait_list, cl_event* event)) + +{ + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (!is_valid(mem_object)) { + return CL_INVALID_MEM_OBJECT; + } + + amd::Buffer* buffer = as_amd(mem_object)->asBuffer(); + if (buffer == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + if (!(buffer->getMemFlags() & CL_MEM_EXTERNAL_PHYSICAL_AMD)) { + return CL_INVALID_MEM_OBJECT; + } + + if ((offset + sizeof(value)) > (buffer->getSize() + amd::Os::pageSize())) { + return CL_INVALID_BUFFER_SIZE; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (hostQueue.context() != buffer->getContext()) { + return CL_INVALID_CONTEXT; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = + amd::clSetEventWaitList(eventWaitList, hostQueue, num_events, event_wait_list); + + if (err != CL_SUCCESS) { + return err; + } + + amd::SignalCommand* command = new amd::SignalCommand(hostQueue, CL_COMMAND_WRITE_SIGNAL_AMD, + eventWaitList, *buffer, value, offset); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_OUT_OF_RESOURCES; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + + +RUNTIME_ENTRY(cl_int, clEnqueueMakeBuffersResidentAMD, + (cl_command_queue command_queue, cl_uint num_mem_objs, cl_mem* mem_objects, + cl_bool blocking_make_resident, cl_bus_address_amd* bus_addresses, + cl_uint num_events, const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (mem_objects == 0) { + return CL_INVALID_MEM_OBJECT; + } + + if (bus_addresses == 0 || num_mem_objs == 0) { + return CL_INVALID_VALUE; + } + + memset(bus_addresses, 0, sizeof(cl_bus_address_amd) * num_mem_objs); + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + std::vector memObjects; + for (unsigned int i = 0; i < num_mem_objs; ++i) { + if (!is_valid(mem_objects[i])) { + return CL_INVALID_MEM_OBJECT; + } + + amd::Buffer* buffer = as_amd(mem_objects[i])->asBuffer(); + if (buffer == NULL) { + return CL_INVALID_MEM_OBJECT; + } + + if (!(buffer->getMemFlags() & CL_MEM_BUS_ADDRESSABLE_AMD)) { + return CL_INVALID_MEM_OBJECT; + } + + if (hostQueue.context() != buffer->getContext()) { + return CL_INVALID_CONTEXT; + } + + memObjects.push_back(buffer); + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = + amd::clSetEventWaitList(eventWaitList, hostQueue, num_events, event_wait_list); + + if (err != CL_SUCCESS) { + return err; + } + + amd::MakeBuffersResidentCommand* command = new amd::MakeBuffersResidentCommand( + hostQueue, CL_COMMAND_MAKE_BUFFERS_RESIDENT_AMD, eventWaitList, memObjects, bus_addresses); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_OUT_OF_RESOURCES; + } + + command->enqueue(); + + if (blocking_make_resident) { + command->awaitCompletion(); + } + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT diff --git a/opencl/amdocl/cl_sdi_amd.h b/opencl/amdocl/cl_sdi_amd.h new file mode 100644 index 0000000000..97fd2b2ab8 --- /dev/null +++ b/opencl/amdocl/cl_sdi_amd.h @@ -0,0 +1,51 @@ +/* Copyright (c) 2012 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef __CL_SDI_AMD_H +#define __CL_SDI_AMD_H + +#include "CL/cl_ext.h" + +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus*/ + + +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueWaitSignalAMD( + cl_command_queue command_queue, cl_mem mem_object, cl_uint value, cl_uint num_events, + const cl_event* event_wait_list, cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; + + +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueWriteSignalAMD( + cl_command_queue command_queue, cl_mem mem_object, cl_uint value, cl_ulong offset, + cl_uint num_events, const cl_event* event_list, cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; + + +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueMakeBuffersResidentAMD( + cl_command_queue command_queue, cl_uint num_mem_objs, cl_mem* mem_objects, + cl_bool blocking_make_resident, cl_bus_address_amd* bus_addresses, cl_uint num_events, + const cl_event* event_list, cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; + + +#ifdef __cplusplus +} /*extern "C"*/ +#endif /*__cplusplus*/ + +#endif diff --git a/opencl/amdocl/cl_semaphore_amd.h b/opencl/amdocl/cl_semaphore_amd.h new file mode 100644 index 0000000000..52dd812832 --- /dev/null +++ b/opencl/amdocl/cl_semaphore_amd.h @@ -0,0 +1,47 @@ +/* Copyright (c) 2012 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef __CL_SEMAPHORE_AMD_H +#define __CL_SEMAPHORE_AMD_H +/******************************************* + * AMD Extension cl_amd_semaphore + *******************************************/ +#define cl_amd_semaphore 1 + +#if cl_amd_semaphore + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* cl_device_info */ +#define CL_DEVICE_MAX_SEMAPHORES_AMD 0xF050 +#define CL_DEVICE_MAX_SEMAPHORE_SIZE_AMD 0xF051 + +/* cl_kernel_work_group_info */ +#define CL_KERNEL_MAX_SEMAPHORE_SIZE_AMD 0xF052 + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* cl_amd_semaphore */ + +#endif /* __CL_SEMAPHORE_AMD_H */ diff --git a/opencl/amdocl/cl_svm.cpp b/opencl/amdocl/cl_svm.cpp new file mode 100644 index 0000000000..7404d69857 --- /dev/null +++ b/opencl/amdocl/cl_svm.cpp @@ -0,0 +1,1217 @@ +/* Copyright (c) 2009 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include "platform/command.hpp" +#include "platform/kernel.hpp" +#include "platform/program.hpp" + +/*! \brief Helper function to validate SVM allocation flags + * + * \return true if flags are valid, otherwise - false + */ +static bool validateSvmFlags(cl_svm_mem_flags flags) { + if (!flags) { + // coarse-grained allocation + return true; + } + const cl_svm_mem_flags rwFlags = CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY; + const cl_svm_mem_flags setFlags = + flags & (rwFlags | CL_MEM_SVM_ATOMICS | CL_MEM_SVM_FINE_GRAIN_BUFFER); + if (flags != setFlags) { + // invalid flags value + return false; + } + + if (amd::countBitsSet(flags & rwFlags) > 1) { + // contradictory R/W flags + return false; + } + + if ((flags & CL_MEM_SVM_ATOMICS) && !(flags & CL_MEM_SVM_FINE_GRAIN_BUFFER)) { + return false; + } + + return true; +} + +/*! \brief Helper function to validate cl_map_flags + * + * \return true if flags are valid, otherwise - false + */ +static bool validateMapFlags(cl_map_flags flags) { + const cl_map_flags maxFlag = CL_MAP_WRITE_INVALIDATE_REGION; + if (flags >= (maxFlag << 1)) { + // at least one flag is out-of-range + return false; + } else if ((flags & CL_MAP_WRITE_INVALIDATE_REGION) && (flags & (CL_MAP_READ | CL_MAP_WRITE))) { + // CL_MAP_READ or CL_MAP_WRITE and CL_MAP_WRITE_INVALIDATE_REGION are + // mutually exclusive. + return false; + } + return true; +} + +/*! \addtogroup API + * @{ + * + * \addtogroup SVM + * @{ + * + */ + +/*! \brief Allocate a shared virtual memory buffer that can be shared by the + * host and all devices in an OpenCL context. + * + * \param context is a valid OpenCL context used to create the SVM buffer. + * + * \param flags is a bit-field that is used to specify allocation and usage + * information. If CL_MEM_SVM_FINE_GRAIN_BUFFER is not specified, the + * buffer is created as a coarse grained SVM allocation. Similarly, if + * CL_MEM_SVM_ATOMICS is not specified, the buffer is created without + * support for SVM atomic operations. + * + * \param size is the size in bytes of the SVM buffer to be allocated. + * + * \param alignment is the minimum alignment in bytes that is required for the + * newly created buffer?s memory region. It must be a power of two up to the + * largest data type supported by the OpenCL device. For the full profile, the + * largest data type is long16. For the embedded profile, it is long16 if the + * device supports 64-bit integers; otherwise it is int16. If alignment is 0, a + * default alignment will be used that is equal to the size of largest data + * type supported by the OpenCL implementation. + * + * \return A valid non-NULL shared virtual memory address if the SVM buffer + * is successfully allocated. Otherwise, like malloc, it returns a NULL pointer + * value. clSVMAlloc will fail if + * - \a context is not a valid context. + * - \a flags does not contain CL_MEM_SVM_FINE_GRAIN_BUFFER but does + * contain CL_MEM_SVM_ATOMICS. + * - Values specified in \a flags do not follow rules for that particular type. + * - CL_MEM_SVM_FINE_GRAIN_BUFFER or CL_MEM_SVM_ATOMICS is specified + * in \a flags and these are not supported by at least one device in + * \a context. + * - The values specified in \a flags are not valid. + * - \a size is 0 or > CL_DEVICE_MAX_MEM_ALLOC_SIZE value for any device in + * \a context. + * - \a alignment is not a power of two or the OpenCL implementation cannot + * support the specified alignment for at least one device in \a context. + * - There was a failure to allocate resources. + * + * \version 2.0r15 + */ +RUNTIME_ENTRY_RET_NOERRCODE(void*, clSVMAlloc, (cl_context context, cl_svm_mem_flags flags, + size_t size, unsigned int alignment)) { + if (!is_valid(context)) { + LogWarning("invalid parameter \"context\""); + return NULL; + } + + if (size == 0) { + LogWarning("invalid parameter \"size = 0\""); + return NULL; + } + + if (!validateSvmFlags(flags)) { + LogWarning("invalid parameter \"flags\""); + return NULL; + } + + if (!amd::isPowerOfTwo(alignment)) { + LogWarning("invalid parameter \"alignment\""); + return NULL; + } + + const std::vector& devices = as_amd(context)->svmDevices(); + bool sizePass = false; + cl_device_svm_capabilities combinedSvmCapabilities = 0; + const cl_uint hostAddressBits = LP64_SWITCH(32, 64); + cl_uint minContextAlignment = std::numeric_limits::max(); + for (const auto& it : devices) { + cl_device_svm_capabilities svmCapabilities = it->info().svmCapabilities_; + if (svmCapabilities == 0) { + continue; + } + combinedSvmCapabilities |= svmCapabilities; + + if (it->info().maxMemAllocSize_ >= size) { + sizePass = true; + } + + if (it->info().addressBits_ < hostAddressBits) { + LogWarning("address mode mismatch between host and device"); + return NULL; + } + + // maximum alignment for a device is given in bits. + cl_uint baseAlignment = it->info().memBaseAddrAlign_ >> 3; + if (alignment > baseAlignment) { + LogWarning("invalid parameter \"alignment\""); + return NULL; + } + + minContextAlignment = std::min(minContextAlignment, baseAlignment); + } + if ((flags & CL_MEM_SVM_FINE_GRAIN_BUFFER) && + !(combinedSvmCapabilities & CL_DEVICE_SVM_FINE_GRAIN_BUFFER)) { + LogWarning("No device in context supports SVM fine grained buffers"); + return NULL; + } + if ((flags & CL_MEM_SVM_ATOMICS) && !(combinedSvmCapabilities & CL_DEVICE_SVM_ATOMICS)) { + LogWarning("No device in context supports SVM atomics"); + return NULL; + } + if (!sizePass) { + LogWarning("invalid parameter \"size\""); + return NULL; + } + + // if alignment not specified, use largest data type alignment supported + if (alignment == 0) { + alignment = minContextAlignment; + ClPrint(amd::LOG_INFO, amd::LOG_API, "Assumed alignment %d\n", alignment); + } + + amd::Context& amdContext = *as_amd(context); + return amd::SvmBuffer::malloc(amdContext, flags, size, alignment); +} +RUNTIME_EXIT + +/*! \brief Free a shared virtual memory buffer allocated using clSVMAlloc. + * + * \param context is a valid OpenCL context used to create the SVM buffer. + * + * \param svm_pointer must be the value returned by a call to clSVMAlloc. If a + * NULL pointer is passed in \a svm_pointer, no action occurs. + * + * \version 2.0r15 + */ +RUNTIME_ENTRY_VOID(void, clSVMFree, (cl_context context, void* svm_pointer)) { + if (!is_valid(context)) { + LogWarning("invalid parameter \"context\""); + return; + } + + if (svm_pointer == NULL) { + return; + } + + amd::Context& amdContext = *as_amd(context); + amd::SvmBuffer::free(amdContext, svm_pointer); +} +RUNTIME_EXIT + +/*! \brief enqueues a command to free shared virtual memory allocated using + * clSVMAlloc or a shared system memory pointer. + * + * \param command_queue is a valid host command-queue. + * + * \param num_svm_pointers specifies the number of elements in \a svm_pointers. + * + * \param svm_pointers is a list of shared virtual memory pointers to + * be freed. Each pointer in \a svm_pointers that was allocated using SVMAlloc + * must have been allocated from the same context from which \a command_queue + * was created. The memory associated with \a svm_pointers can be reused or + * freed after the function returns. + * + * \param pfn_free_func specifies the callback function to be called to free + * the SVM pointers. \a pfn_free_func takes four arguments: \a queue which is + * the command queue in which clEnqueueSVMFree was enqueued, the count and list + * of SVM pointers to free and \a user_data which is a pointer to user + * specified data. If \a pfn_free_func is NULL, all the pointers specified in + * \a svm_pointers array must be allocated using clSVMAlloc. \a pfn_free_func + * must however be a valid callback function if any SVM pointer to be freed is + * a shared system memory pointer i.e. not allocated using clSVMAlloc. + * + * \param user_data will be passed as the user_data argument when + * \a pfn_free_func is called. \a user_data can be NULL. + * + * \param even_wait_list specifies the events that need to complete before + * this particular command can be executed. If \a event_wait_list is NULL, then + * this particular command does not wait on any event to complete. If + * \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. If + * \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. The context associated with events in + * \a event_wait_list and \a command_queue must be the same. The memory + * associated with \a event_wait_list can be reused or freed after the function + * returns. + * + * \param num_events_in_wait_list specifies the number of elements in + * \a even_wait_list + * + * \param event returns an event object that identifies this particular command + * and can be used to query or queue a wait for this particular command to + * complete. \a event can be NULL in which case it will not be possible for the + * application to query the status of this command or queue a wait for this + * command to complete. If the \a event_wait_list and the \a event arguments + * are not NULL, the \a event argument should not refer to an element of the + * \a event_wait_list array. + * + * \return One of the following values: + * - CL_SUCCESS if the function was executed successfully + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid host + * command-queue + * - CL_INVALID_VALUE if \a num_svm_pointers is 0 or if \a svm_pointers is + * NULL or if any of the pointers specified in \a svm_pointers array is NULL + * - CL_INVALID_CONTEXT if context associated with \a command_queue and + * events in \a event_wait_list are not the same + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 2.0r15 + */ +RUNTIME_ENTRY(cl_int, clEnqueueSVMFree, + (cl_command_queue command_queue, cl_uint num_svm_pointers, void* svm_pointers[], + void(CL_CALLBACK* pfn_free_func)(cl_command_queue queue, cl_uint num_svm_pointers, + void* svm_pointers[], void* user_data), + void* user_data, cl_uint num_events_in_wait_list, const cl_event* event_wait_list, + cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (num_svm_pointers == 0) { + LogWarning("invalid parameter \"num_svm_pointers = 0\""); + return CL_INVALID_VALUE; + } + + if (svm_pointers == NULL) { + LogWarning("invalid parameter \"svm_pointers = NULL\""); + return CL_INVALID_VALUE; + } + + //!@todo why are NULL pointers disallowed here but not in clSVMFree? + for (cl_uint i = 0; i < num_svm_pointers; i++) { + if (svm_pointers[i] == NULL) { + LogWarning("Null pointers are not allowed"); + return CL_INVALID_VALUE; + } + } + + //!@todo what if the callback is NULL but \a user_data is not? + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::Command* command = new amd::SvmFreeMemoryCommand(hostQueue, eventWaitList, num_svm_pointers, + svm_pointers, pfn_free_func, user_data); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief enqueues a command to do a memcpy operation. + * + * \param command_queue refers to the host command-queue in which the read/ + * write commands will be queued. + * + * \param blocking_copy indicates if the copy operation is blocking or + * non-blocking. If \a blocking_copy is CL_TRUE i.e. the copy command is + * blocking, clEnqueueSVMMemcpy does not return until the buffer data has been + * copied into memory pointed to by \a dst_ptr. If \a blocking_copy is CL_FALSE + * i.e. the copy command is non-blocking, clEnqueueSVMMemcpy queues a + * non-blocking copy command and returns. The contents of the buffer that + * \a dst_ptr point to cannot be used until the copy command has completed. + * The \a event argument returns an event object which can be used to query the + * execution status of the read command. When the copy command has completed, + * the contents of the buffer that \a dst_ptr points to can be used by the + * application. + * + * \param dst_ptr is the pointer to a memory region where data is copied to. + * + * \param src_ptr is the pointer to a memory region where data is copied from. + * If \a dst_ptr and/or \a src_ptr are allocated using clSVMAlloc then they + * must be allocated from the same context from which \a command_queue was + * created. Otherwise the behavior is undefined. + * + * \param size is the size in bytes of data being copied. + * + * \param even_wait_list specifies the events that need to complete before + * this particular command can be executed. If \a event_wait_list is NULL, then + * this particular command does not wait on any event to complete. If + * \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. If + * \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. The context associated with events in + * \a event_wait_list and \a command_queue must be the same. The memory + * associated with \a event_wait_list can be reused or freed after the function + * returns. + * + * \param num_events_in_wait_list specifies the number of elements in + * \a even_wait_list + * + * \param event returns an event object that identifies this particular command + * and can be used to query or queue a wait for this particular command to + * complete. \a event can be NULL in which case it will not be possible for the + * application to query the status of this command or queue a wait for this + * command to complete. If the \a event_wait_list and the \a event arguments + * are not NULL, the \a event argument should not refer to an element of the + * \a event_wait_list array. + * + * \return One of the following values: + * - CL_SUCCESS if the function was executed successfully + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid host + * command-queue + * - CL_INVALID_CONTEXT if the context associated with \a command_queue and + * events in \a event_wait_list are not the same + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST if the operation is + * blocking and the execution status of any of the events in + * \a event_wait_list is a negative integer value. + * - CL_INVALID_VALUE if \a dst_ptr or \a src_ptr are NULL. + * - CL_INVALID_VALUE if \a size is 0. + * - CL_MEM_COPY_OVERLAP if the values specified for \a dst_ptr, \a src_ptr + * and \a size result in an overlapping copy. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 2.0r15 + */ +RUNTIME_ENTRY(cl_int, clEnqueueSVMMemcpy, + (cl_command_queue command_queue, cl_bool blocking_copy, void* dst_ptr, + const void* src_ptr, size_t size, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (dst_ptr == NULL || src_ptr == NULL) { + return CL_INVALID_VALUE; + } + + if (size == 0) { + return CL_INVALID_VALUE; + } + + char* dst = reinterpret_cast(dst_ptr); + const char* src = reinterpret_cast(src_ptr); + if ((dst > src - size) && (dst < src + size)) { + return CL_MEM_COPY_OVERLAP; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::Command* command = + new amd::SvmCopyMemoryCommand(hostQueue, eventWaitList, dst_ptr, src_ptr, size); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + command->enqueue(); + + if (blocking_copy) { + command->awaitCompletion(); + } + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief enqueues a command to fill a region in memory with a pattern of a + * given pattern size. + * + * \param command_queue refers to the host command-queue in which the fill + * command will be queued. The OpenCL context associated with \a command_queue + * and SVM pointer referred to by \a svm_ptr must be the same.. + * + * \param svm_ptr is a pointer to a memory region that will be filled with + * \a pattern. It must be aligned to \a pattern_size bytes. If \a svm_ptr is + * allocated using clSVMAlloc then it must be allocated from the same context + * from which \a command_queue was created. Otherwise the behavior is + * undefined. + * + * \a pattern is a pointer to the data pattern of size \a pattern_size in + * bytes. \a pattern will be used to fill a region in buffer starting at + * \a svm_ptr and is \a size bytes in size. The data pattern must be a scalar + * or vector integer or floating-point data type supported by OpenCL. For + * example, if region pointed to by \a svm_ptr is to be filled with a pattern + * of float4 values, then \a pattern will be a pointer to a cl_float4 value + * and \a pattern_size will be sizeof(cl_float4). The maximum value of + * \a pattern_size is the size of the largest integer or floating-point vector + * data type supported by the OpenCL device. The memory associated with + * \a pattern can be reused or freed after the function returns. + * + * \param size is the size in bytes of region being filled starting with + * \a svm_ptr and must be a multiple of \a pattern_size. + * + * \param even_wait_list specifies the events that need to complete before + * this particular command can be executed. If \a event_wait_list is NULL, then + * this particular command does not wait on any event to complete. If + * \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. If + * \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. The context associated with events in + * \a event_wait_list and \a command_queue must be the same. The memory + * associated with \a event_wait_list can be reused or freed after the function + * returns. + * + * \param num_events_in_wait_list specifies the number of elements in + * \a even_wait_list + * + * \param event returns an event object that identifies this particular command + * and can be used to query or queue a wait for this particular command to + * complete. \a event can be NULL in which case it will not be possible for the + * application to query the status of this command or queue a wait for this + * command to complete. clEnqueueBarrierWithWaitList can be used instead. If + * the \a event_wait_list and the \a event arguments are not NULL, the \a event + * argument should not refer to an element of the \a event_wait_list array. + * + * \return One of the following values: + * - CL_SUCCESS if the function was executed successfully + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid host + * command-queue + * - CL_INVALID_CONTEXT if context associated with \a command_queue and + * events in \a event_wait_list are not the same + * - CL_INVALID_VALUE if \a svm_ptr is NULL. + * - CL_INVALID_VALUE if \a svm_ptr is not aligned to \a pattern_size bytes. + * - CL_INVALID_VALUE if \a pattern is NULL or if \a pattern_size is 0 or if + * \a pattern_size is not one of {1, 2, 4, 8, 16, 32, 64, 128}. + * - CL_INVALID_VALUE if \a size is 0 or is not a multiple of \a pattern_size. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 2.0r15 + */ +RUNTIME_ENTRY(cl_int, clEnqueueSVMMemFill, + (cl_command_queue command_queue, void* svm_ptr, const void* pattern, + size_t pattern_size, size_t size, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (svm_ptr == NULL) { + return CL_INVALID_VALUE; + } + + char* dst = reinterpret_cast(svm_ptr); + if (!amd::isMultipleOf(dst, pattern_size)) { + return CL_INVALID_VALUE; + } + + if (pattern == NULL) { + return CL_INVALID_VALUE; + } + + if (!amd::isPowerOfTwo(pattern_size) || pattern_size == 0 || + pattern_size > amd::FillMemoryCommand::MaxFillPatterSize) { + return CL_INVALID_VALUE; + } + + if (size == 0 || !amd::isMultipleOf(size, pattern_size)) { + return CL_INVALID_VALUE; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::Command* command = + new amd::SvmFillMemoryCommand(hostQueue, eventWaitList, svm_ptr, pattern, pattern_size, size); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief enqueues a command that will allow the host to update a region of a + * SVM buffer + * + * \param command_queue is a valid host command-queue. + * + * \param blocking_map indicates if the map operation is blocking or + * non-blocking. If \a blocking_map is CL_TRUE, clEnqueueSVMMap does not return + * until the application can access the contents of the SVM region specified by + * \a svm_ptr and \a size on the host. If blocking_map is CL_FALSE i.e. map + * operation is non-blocking, the region specified by \a svm_ptr and \a size + * cannot be used until the map command has completed. The \a event argument + * returns an event object which can be used to query the execution status of + * the map command. When the map command is completed, the application can + * access the contents of the region specified by \a svm_ptr and \a size. + * + * \param maps_flag is a valid cl_map_flags flag. + * + * \param svm_ptr is a pointer to a memory region that will be updated by the + * host. If \a svm_ptr is allocated using clSVMAlloc then it must be allocated + * from the same context from which \a command_queue was created. Otherwise + * the behavior is undefined. + * + * \param size is the size in bytes of the memory region that will be updated + * by the host. + * + * \param even_wait_list specifies the events that need to complete before + * this particular command can be executed. If \a event_wait_list is NULL, then + * this particular command does not wait on any event to complete. If + * \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. If + * \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. The context associated with events in + * \a event_wait_list and \a command_queue must be the same. The memory + * associated with \a event_wait_list can be reused or freed after the function + * returns. + * + * \param num_events_in_wait_list specifies the number of elements in + * \a even_wait_list + * + * \param event returns an event object that identifies this particular command + * and can be used to query or queue a wait for this particular command to + * complete. \a event can be NULL in which case it will not be possible for the + * application to query the status of this command or queue a wait for this + * command to complete. clEnqueueBarrierWithWaitList can be used instead. If + * the \a event_wait_list and the \a event arguments are not NULL, the \a event + * argument should not refer to an element of the \a event_wait_list array. + * + * \return One of the following values: + * - CL_SUCCESS if the function was executed successfully + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid host + * command-queue + * - CL_INVALID_CONTEXT if context associated with \a command_queue and + * events in \a event_wait_list are not the same + * - CL_INVALID_VALUE if \a svm_ptr is NULL. + * - CL_INVALID_VALUE if \a size is 0 or if values specified in \a map_flags + * are not valid. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST if the operation is + * blocking and the execution status of any of the events in + * \a event_wait_list is a negative integer value. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 2.0r15 + */ +RUNTIME_ENTRY(cl_int, clEnqueueSVMMap, + (cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags map_flags, + void* svm_ptr, size_t size, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (svm_ptr == NULL) { + return CL_INVALID_VALUE; + } + + if (size == 0) { + return CL_INVALID_VALUE; + } + + if (!validateMapFlags(map_flags)) { + return CL_INVALID_VALUE; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + size_t offset = 0; + amd::Memory* svmMem = NULL; + if ((queue->device()).isFineGrainedSystem()) { + // leave blank on purpose for FGS no op + } else { + svmMem = amd::MemObjMap::FindMemObj(svm_ptr); + if (NULL != svmMem) { + // make sure the context is the same as the context of creation of svm space + if (hostQueue.context() != svmMem->getContext()) { + LogWarning("different contexts"); + return CL_INVALID_CONTEXT; + } + + offset = static_cast
(svm_ptr) - static_cast
(svmMem->getSvmPtr()); + if (offset < 0 || offset + size > svmMem->getSize()) { + LogWarning("wrong svm address "); + return CL_INVALID_VALUE; + } + amd::Buffer* srcBuffer = svmMem->asBuffer(); + + amd::Coord3D srcSize(size); + amd::Coord3D srcOffset(offset); + if (NULL != srcBuffer) { + if (!srcBuffer->validateRegion(srcOffset, srcSize)) { + return CL_INVALID_VALUE; + } + } + + // Make sure we have memory for the command execution + device::Memory* mem = svmMem->getDeviceMemory(queue->device()); + if (NULL == mem) { + LogPrintfError("Can't allocate memory size - 0x%08X bytes!", svmMem->getSize()); + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + // Attempt to allocate the map target now (whether blocking or non-blocking) + void* mapPtr = mem->allocMapTarget(srcOffset, srcSize, map_flags); + if (NULL == mapPtr || mapPtr != svm_ptr) { + return CL_OUT_OF_RESOURCES; + } + } + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::Command* command = new amd::SvmMapMemoryCommand(hostQueue, eventWaitList, svmMem, size, + offset, map_flags, svm_ptr); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + command->enqueue(); + + if (blocking_map) { + command->awaitCompletion(); + } + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief enqueues a command to indicate that the host has completed updating + * a memory region which was specified in a previous call to clEnqueueSVMUnmap. + * + * \param command_queue is a valid host command-queue. + * + * \param svm_ptr is a pointer that was specified in a previous call to + * clEnqueueSVMMap. If \a svm_ptr is allocated using clSVMAlloc then it must be + * allocated from the same context from which \a command_queue was created. + * Otherwise the behavior is undefined. + * + * \param even_wait_list specifies the events that need to complete before + * this particular command can be executed. If \a event_wait_list is NULL, then + * this particular command does not wait on any event to complete. If + * \a event_wait_list is NULL, \a num_events_in_wait_list must be 0. If + * \a event_wait_list is not NULL, the list of events pointed to by + * \a event_wait_list must be valid and \a num_events_in_wait_list must be + * greater than 0. The events specified in \a event_wait_list act as + * synchronization points. The context associated with events in + * \a event_wait_list and \a command_queue must be the same. The memory + * associated with \a event_wait_list can be reused or freed after the function + * returns. + * + * \param num_events_in_wait_list specifies the number of elements in + * \a even_wait_list + * + * \param event returns an event object that identifies this particular command + * and can be used to query or queue a wait for this particular command to + * complete. \a event can be NULL in which case it will not be possible for the + * application to query the status of this command or queue a wait for this + * command to complete. clEnqueueBarrierWithWaitList can be used instead. If + * the \a event_wait_list and the \a event arguments are not NULL, the \a event + * argument should not refer to an element of the \a event_wait_list array. + * + * \return One of the following values: + * - CL_SUCCESS if the function was executed successfully + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid host + * command-queue + * - CL_INVALID_CONTEXT if context associated with \a command_queue and + * events in \a event_wait_list are not the same + * - CL_INVALID_VALUE if \a svm_ptr is NULL. + * - CL_INVALID_EVENT_WAIT_LIST if \a event_wait_list is NULL and + * \a num_events_in_wait_list > 0, or \a event_wait_list is not NULL and + * \a num_events_in_wait_list is 0, or if event objects in \a event_wait_list + * are not valid events. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 2.0r15 + */ +RUNTIME_ENTRY(cl_int, clEnqueueSVMUnmap, + (cl_command_queue command_queue, void* svm_ptr, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + if (svm_ptr == NULL) { + return CL_INVALID_VALUE; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + amd::Memory* svmMem = NULL; + if (!(queue->device()).isFineGrainedSystem()) { + // check if the ptr is in the svm space + svmMem = amd::MemObjMap::FindMemObj(svm_ptr); + // Make sure we have memory for the command execution + if (NULL != svmMem) { + // Make sure we have memory for the command execution + device::Memory* mem = svmMem->getDeviceMemory(queue->device()); + if (NULL == mem) { + LogPrintfError("Can't allocate memory size - 0x%08X bytes!", svmMem->getSize()); + return CL_INVALID_VALUE; + } + } + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::Command* command = new amd::SvmUnmapMemoryCommand(hostQueue, eventWaitList, svmMem, svm_ptr); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Set the argument value for a specific argument of a kernel to be + * a SVM pointer. + * + * \param kernel is a valid kernel object. + * + * \param arg_index is the argument index. Arguments to the kernel are referred + * by indices that go from 0 for the leftmost argument to n - 1, where n is the + * total number of arguments declared by a kernel. + * + * \param arg_value is the SVM pointer that should be used as the argument + * value for argument specified by \a arg_index. The SVM pointer pointed to by + * \a arg_value is copied and the \a arg_value pointer can therefore be reused + * by the application after clSetKernelArgSVMPointer returns. The SVM pointer + * specified is the value used by all API calls that enqueue kernel + * (clEnqueueNDRangeKernel) until the argument value is changed by a call to + * clSetKernelArgSVMPointer for \a kernel. The SVM pointer can only be used for + * arguments that are declared to be a pointer to global or constant memory. + * The SVM pointer value must be aligned according to the argument?s type. For + * example, if the argument is declared to be global float4 *p, the SVM pointer + * value passed for p must be at a minimum aligned to a float4. The SVM pointer + * value specified as the argument value can be the pointer returned by + * clSVMAlloc or can be a pointer + offset into the SVM region. + * + * \return One of the following values: + * - CL_SUCCESS if the function was executed successfully + * - CL_INVALID_KERNEL if \a kernel is not a valid kernel object + * - CL_INVALID_ARG_INDEX if \a arg_index is not a valid argument index + * - CL_INVALID_ARG_VALUE if \a arg_value is not a valid value + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 2.0r15 + */ +RUNTIME_ENTRY(cl_int, clSetKernelArgSVMPointer, + (cl_kernel kernel, cl_uint arg_index, const void* arg_value)) { + if (!is_valid(kernel)) { + return CL_INVALID_KERNEL; + } + + const amd::KernelSignature& signature = as_amd(kernel)->signature(); + if (arg_index >= signature.numParameters()) { + return CL_INVALID_ARG_INDEX; + } + + const amd::KernelParameterDescriptor& desc = signature.at(arg_index); + if (desc.type_ != T_POINTER || + !(desc.addressQualifier_ & (CL_KERNEL_ARG_ADDRESS_GLOBAL | CL_KERNEL_ARG_ADDRESS_CONSTANT))) { + as_amd(kernel)->parameters().reset(static_cast(arg_index)); + return CL_INVALID_ARG_VALUE; + } + + //! @todo We need to check that the alignment of \a arg_value. For instance, + // if the argument is of type 'global float4*', then \a arg_value must be + // aligned to sizeof(float4*). Note that desc.size_ contains the size of the + // pointer type itself and the size of the pointed type. + + + // We do not perform additional pointer validations: + // -verifying pointers returned by SVMAlloc would imply keeping track + // of every allocation range and then matching the pointer against that + // range. Note that even if the pointer would look correct, nothing + // prevents the user from using an offset within the kernel that would + // result on an invalid access. + // -verifying system pointers (if supported) requires matching the pointer + // against the address space of the current process. + + as_amd(kernel)->parameters().set(static_cast(arg_index), sizeof(arg_value), &arg_value, + true); + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Pass additional information other than argument values to a kernel. + * + * \param kernel is a valid kernel object. + * + * \param param_name specifies the information to be passed to \a kernel. It + * must be a cl_kernel_exec_info value. + * + * \param param_value_size specifies the size in bytes of the memory pointed to + * by \a param_value. + * + * \param param_value is a pointer to memory where the appropiate values + * determined by \a param_name are specified. + * + * \return One of the following values: + * - CL_SUCCESS if the function was executed successfully + * - CL_INVALID_KERNEL if \a kernel is not a valid kernel object. + * - CL_INVALID_VALUE if \a param_name is not valid, if \a param_value is + * NULL or if the size specified by \a param_value_size is not valid + * - CL_INVALID_OPERATION if \a param_name is + * CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM and \a param_value = CL_TRUE + * but no devices in context associated with \a kernel support fine-grained + * system SVM allocations + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 2.0r15 + */ +RUNTIME_ENTRY(cl_int, clSetKernelExecInfo, (cl_kernel kernel, cl_kernel_exec_info param_name, + size_t param_value_size, const void* param_value)) { + if (!is_valid(kernel)) { + return CL_INVALID_KERNEL; + } + + if (param_value == NULL) { + return CL_INVALID_VALUE; + } + + const amd::Kernel* amdKernel = as_amd(kernel); + + switch (param_name) { + case CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM: + if (param_value_size != sizeof(cl_bool)) { + return CL_INVALID_VALUE; + } else { + const bool flag = *(static_cast(param_value)); + const amd::Context* amdContext = &amdKernel->program().context(); + bool foundFineGrainedSystemDevice = false; + const std::vector& devices = amdContext->devices(); + for (const auto it : devices) { + if (it->info().svmCapabilities_ & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM) { + foundFineGrainedSystemDevice = true; + break; + } + } + if (flag && !foundFineGrainedSystemDevice) { + return CL_INVALID_OPERATION; + } + amdKernel->parameters().setSvmSystemPointersSupport(flag ? FGS_YES : FGS_NO); + } + break; + case CL_KERNEL_EXEC_INFO_SVM_PTRS: + if (param_value_size == 0 || !amd::isMultipleOf(param_value_size, sizeof(void*))) { + return CL_INVALID_VALUE; + } else { + size_t count = param_value_size / sizeof(void*); + void* const* execInfoArray = reinterpret_cast(param_value); + for (size_t i = 0; i < count; i++) { + if (NULL == execInfoArray[i]) { + return CL_INVALID_VALUE; + } + } + amdKernel->parameters().addSvmPtr(execInfoArray, count); + } + break; + case CL_KERNEL_EXEC_INFO_NEW_VCOP_AMD: + if (param_value_size != sizeof(cl_bool)) { + return CL_INVALID_VALUE; + } else { + const bool newVcopFlag = (*(reinterpret_cast(param_value))) ? true : false; + amdKernel->parameters().setExecNewVcop(newVcopFlag); + } + break; + case CL_KERNEL_EXEC_INFO_PFPA_VCOP_AMD: + if (param_value_size != sizeof(cl_bool)) { + return CL_INVALID_VALUE; + } else { + const bool pfpaVcopFlag = (*(reinterpret_cast(param_value))) ? true : false; + amdKernel->parameters().setExecPfpaVcop(pfpaVcopFlag); + } + break; + default: + return CL_INVALID_VALUE; + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Enqueues a command to indicate which device a set of ranges of SVM + * allocations should be associated with. Once the event returned by + * \a clEnqueueSVMMigrateMem has become CL_COMPLETE, the ranges specified by + * svm pointers and sizes have been successfully migrated to the device + * associated with command queue. + * The user is responsible for managing the event dependencies associated with + * this command in order to avoid overlapping access to SVM allocations. + * Improperly specified event dependencies passed to clEnqueueSVMMigrateMem + * could result in undefined results + * + * \param command_queue is a valid host command queue. The specified set of + * allocation ranges will be migrated to the OpenCL device associated with + * command_queue. + * + * \param num_svm_pointers is the number of pointers in the specified + * svm_pointers array, and the number of sizes in the sizes array, if sizes + * is not NULL. + * + * \param svm_pointers is a pointer to an array of pointers. Each pointer in + * this array must be within an allocation produced by a call to clSVMAlloc. + * + * \param sizes is an array of sizes. The pair svm_pointers[i] and sizes[i] + * together define the starting address and number of bytes in a range to be + * migrated. sizes may be NULL indicating that every allocation containing + * any svm_pointer[i] is to be migrated. Also, if sizes[i] is zero, then the + * entire allocation containing svm_pointer[i] is migrated. + * + * \param flags is a bit-field that is used to specify migration options. + * Table 5.12 describes the possible values for flags. + * + * \param num_events_in_wait_list specifies the number of event objects in + * \a event_wait_list. + * + * \param event_wait_list specifies events that need to complete before this + * particular command can be executed. If event_wait_list is NULL, then this + * particular command does not wait on any event to complete. If + * event_wait_list is NULL, num_events_in_wait_list must be 0. If + * event_wait_list is not NULL, the list of events pointed to by + * event_wait_list must be valid and num_events_in_wait_list must be greater + * than 0. The events specified in event_wait_list act as synchronization + * points. The context associated with events in event_wait_list and + * command_queue must be the same. The memory associated with + * event_wait_list can be reused or freed after the function returns. + * + * \param event an returned event object that identifies this particular write + * command and can be used to query or queue a wait for this particular + * command to complete. event can be NULL in which case it will not be + * possible for the application to query the status of this command or queue + * another command that waits for this command to complete. If the + * event_wait_list and the event arguments are not NULL, the event argument + * should not refer to an element of the event_wait_list array. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully + * - CL_INVALID_COMMAND_QUEUE if \a command_queue is not a valid command-queue + * - CL_INVALID_VALUE if num_svm_pointers is zero or svm_pointers is NULL + * - CL_INVALID_VALUE if sizes[i] is non-zero range [svm_pointers[i], + * svm_pointers[i]+sizes[i]) is not contained within an existing clSVMAlloc + * allocation + * - CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and + * num_events_in_wait_list > 0, or event_wait_list is not NULL and + * num_events_in_wait_list is 0, or if event objects in event_wait_list are + * not valid events + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required + * by the OpenCL implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required + * by the OpenCL implementation on the host. + * + * \version 2.1r00 + */ +RUNTIME_ENTRY(cl_int, clEnqueueSVMMigrateMem, + (cl_command_queue command_queue, cl_uint num_svm_pointers, const void **svm_pointers, + const size_t *size, cl_mem_migration_flags flags, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + amd::HostQueue* queue = as_amd(command_queue)->asHostQueue(); + if (NULL == queue) { + return CL_INVALID_COMMAND_QUEUE; + } + amd::HostQueue& hostQueue = *queue; + + if (num_svm_pointers == 0) { + LogWarning("invalid parameter \"num_svm_pointers = 0\""); + return CL_INVALID_VALUE; + } + + if (svm_pointers == NULL) { + LogWarning("invalid parameter \"svm_pointers = NULL\""); + return CL_INVALID_VALUE; + } + + for (cl_uint i = 0; i < num_svm_pointers; i++) { + if (svm_pointers[i] == NULL) { + LogWarning("Null pointers are not allowed"); + return CL_INVALID_VALUE; + } + } + + if (flags & ~(CL_MIGRATE_MEM_OBJECT_HOST | CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED)) { + LogWarning("Invalid flag is specified"); + return CL_INVALID_VALUE; + } + + std::vector memObjects; + for (cl_uint i = 0; i < num_svm_pointers; i++) { + const void* svm_ptr = svm_pointers[i]; + + amd::Memory* svmMem = amd::MemObjMap::FindMemObj(svm_ptr); + if (NULL != svmMem) { + // make sure the context is the same as the context of creation of svm space + if (hostQueue.context() != svmMem->getContext()) { + LogWarning("different contexts"); + return CL_INVALID_CONTEXT; + } + + // Make sure the specified size[i] is within a valid range + // TODO: handle the size parameter properly + size_t svm_size = (size == NULL) ? 0 : size[i]; + size_t offset = reinterpret_cast(svm_ptr) - reinterpret_cast
(svmMem->getSvmPtr()); + if ((offset + svm_size) > svmMem->getSize()) { + LogWarning("wrong svm address "); + return CL_INVALID_VALUE; + } + + memObjects.push_back(svmMem); + } + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amd::MigrateMemObjectsCommand* command = new amd::MigrateMemObjectsCommand( + hostQueue, CL_COMMAND_MIGRATE_MEM_OBJECTS, eventWaitList, memObjects, flags); + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_MEM_OBJECT_ALLOCATION_FAILURE; + } + + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT +/*! @} + * @} + */ diff --git a/opencl/amdocl/cl_thread_trace_amd.cpp b/opencl/amdocl/cl_thread_trace_amd.cpp new file mode 100644 index 0000000000..6dd8189e90 --- /dev/null +++ b/opencl/amdocl/cl_thread_trace_amd.cpp @@ -0,0 +1,534 @@ +/* Copyright (c) 2009 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "cl_common.hpp" +#include "cl_thread_trace_amd.h" +#include "platform/context.hpp" +#include "platform/command.hpp" +#include "platform/threadtrace.hpp" +#include +#include +#include + +/*! \addtogroup API + * @{ + * + * \addtogroup AMD_Extensions + * @{ + * + */ + +/*! \brief Creates a new HW threadTrace + * + * \param device must be a valid OpenCL device. + * + * \param threadTrace the created cl_threadtrace_amd object + * + * \param errcode_ret A non zero value if OpenCL failed to create cl_threadtrace_amd + * - CL_SUCCESS if the function is executed successfully. + * - CL_INVALID_DEVICE if the specified context is invalid. + * - CL_INVALID_OPERATION if we couldn't create the object + * + * \return Created cl_threadtrace_amd object + */ +RUNTIME_ENTRY_RET(cl_threadtrace_amd, clCreateThreadTraceAMD, + (cl_device_id device, cl_int* errcode_ret)) { + // Make sure we have a valid device object + if (!is_valid(device)) { + *not_null(errcode_ret) = CL_INVALID_DEVICE; + return NULL; + } + + // Create the device thread trace object + amd::ThreadTrace* threadTrace = new amd::ThreadTrace(*as_amd(device)); + + if (threadTrace == NULL) { + *not_null(errcode_ret) = CL_INVALID_OPERATION; + return NULL; + } + + *not_null(errcode_ret) = CL_SUCCESS; + return as_cl(threadTrace); +} +RUNTIME_EXIT + +///*! \brief Destroy a threadTrace object. +// * +// * \param threadTrace the cl_threadtrace_amd object for release +// * +// * \return A non zero value if OpenCL failed to release cl_threadtrace_amd +// * - CL_SUCCESS if the function is executed successfully. +// * - CL_INVALID_OPERATION if we failed to release the object +// */ +RUNTIME_ENTRY(cl_int, clReleaseThreadTraceAMD, (cl_threadtrace_amd threadTrace)) { + if (!is_valid(threadTrace)) { + return CL_INVALID_OPERATION; + } + as_amd(threadTrace)->release(); + return CL_SUCCESS; +} +RUNTIME_EXIT +// +// *! \brief Increments the cl_threadtrace_amd object reference count. +// * +// * \param threadTrace the cl_threadtrace_amd object for retain +// * +// * \return A non zero value if OpenCL failed to retain cl_threadtrace_amd +// * - CL_SUCCESS if the function is executed successfully. +// * - CL_INVALID_OPERATION if we failed to release the object +// */ +RUNTIME_ENTRY(cl_int, clRetainThreadTraceAMD, (cl_threadtrace_amd threadTrace)) { + if (!is_valid(threadTrace)) { + return CL_INVALID_OPERATION; + } + as_amd(threadTrace)->retain(); + return CL_SUCCESS; +} +RUNTIME_EXIT + +// +// *! \brief Sets the cl_threadtrace_amd object configuration parameter. +// * +// * \param thread_trace the cl_threadtrace_amd object to set configuration parameter +// * +// * \param config_param the cl_thread_trace_param +// * +// * \param param_value corresponding to configParam +// * +// * \return A non zero value if OpenCL failed to set threadTrace buffer parameter +// * - CL_INVALID_VALUE if the thread_trace is invalid thread trace object. +// * - CL_INVALID_VALUE if the invalid config_param or param_value enum values , are used. +// * - CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and num_events_in_wait_list > 0, or +// event_wait_list is not NULL and num_events_in_wait_list is 0, +// * - or if event objects in event_wait_list are not valid events. +// * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL +// implementation on the device. +// * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the +// OpenCL implementation on the host. +// */ +RUNTIME_ENTRY(cl_int, clSetThreadTraceParamAMD, + (cl_threadtrace_amd thread_trace, cl_thread_trace_param config_param, + cl_uint param_value)) { + if (!is_valid(thread_trace)) { + return CL_INVALID_OPERATION; + } + switch (config_param) { + case CL_THREAD_TRACE_PARAM_TOKEN_MASK: + if (param_value > CL_THREAD_TRACE_TOKEN_MASK_ALL_SI) { + return CL_INVALID_VALUE; + } + as_amd(thread_trace)->setTokenMask(param_value); + break; + case CL_THREAD_TRACE_PARAM_REG_MASK: + if (param_value > CL_THREAD_TRACE_REG_MASK_ALL_SI) { + return CL_INVALID_VALUE; + } + as_amd(thread_trace)->setRegMask(param_value); + break; + case CL_THREAD_TRACE_PARAM_VM_ID_MASK: + if (param_value > CL_THREAD_TRACE_VM_ID_MASK_SINGLE_DETAIL) { + return CL_INVALID_VALUE; + } + as_amd(thread_trace)->setVmIdMask(param_value); + break; + case CL_THREAD_TRACE_PARAM_INSTRUCTION_MASK: + if (param_value > CL_THREAD_TRACE_INST_MASK_IMMEDIATE_CI) { + return CL_INVALID_VALUE; + } + as_amd(thread_trace)->setInstMask(param_value); + break; + case CL_THREAD_TRACE_PARAM_COMPUTE_UNIT_TARGET: + as_amd(thread_trace)->setCU(param_value); + break; + case CL_THREAD_TRACE_PARAM_SHADER_ARRAY_TARGET: + as_amd(thread_trace)->setSH(param_value); + break; + case CL_THREAD_TRACE_PARAM_SIMD_MASK: + as_amd(thread_trace)->setSIMD(param_value); + break; + case CL_THREAD_TRACE_PARAM_USER_DATA: + as_amd(thread_trace)->setUserData(param_value); + break; + case CL_THREAD_TRACE_PARAM_CAPTURE_MODE: + if (param_value > CL_THREAD_TRACE_CAPTURE_SELECT_DETAIL) { + return CL_INVALID_VALUE; + } + as_amd(thread_trace)->setCaptureMode(param_value); + break; + case CL_THREAD_TRACE_PARAM_IS_WRAPPED: + as_amd(thread_trace)->setIsWrapped(true); + break; + case CL_THREAD_TRACE_PARAM_RANDOM_SEED: + as_amd(thread_trace)->setRandomSeed(param_value); + break; + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! \brief Get specific information about the OpenCL Thread Trace. + * + * \param threadTrace_info_param is an enum that identifies the Thread Trace information being + * queried. + * + * \param param_value is a pointer to memory location where appropriate values + * for a given \a threadTrace_info_param will be returned. If \a param_value is NULL, + * it is ignored. + * + * \param param_value_size specifies the size in bytes of memory pointed to by + * \a param_value. This size in bytes must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data being + * queried by param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * \return One of the following values: + * CL_INVALID_OPERATION if cl_threadtrace_amd object is not valid + * - CL_INVALID_VALUE if \a param_name is not one of the supported + * values or if size in bytes specified by \a param_value_size is < size of + * return type and \a param_value is not a NULL value. + * - CL_SUCCESS if the function is executed successfully. + * + */ +RUNTIME_ENTRY(cl_int, clGetThreadTraceInfoAMD, + (cl_threadtrace_amd thread_trace /* threadTrace */, + cl_threadtrace_info thread_trace_info_param, size_t param_value_size, + void* param_value, size_t* param_value_size_ret)) { + if (!is_valid(thread_trace)) { + return CL_INVALID_OPERATION; + } + + // Find the thread trace object, associated with the specified device + const device::ThreadTrace* devThreadTrace = as_amd(thread_trace)->getDeviceThreadTrace(); + + const size_t seNum = as_amd(thread_trace)->deviceSeNumThreadTrace(); + switch (thread_trace_info_param) { + case CL_THREAD_TRACE_SE: { + return amd::clGetInfo(seNum, param_value_size, param_value, param_value_size_ret); + } + case CL_THREAD_TRACE_BUFFERS_SIZE: { + // Make sure we found a valid thread trace object + if (devThreadTrace == NULL) { + return CL_INVALID_OPERATION; + } + + std::unique_ptr bufSize2Se(new uint[seNum]); + + if (bufSize2Se.get() == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + if (!devThreadTrace->info(thread_trace_info_param, bufSize2Se.get(), seNum)) { + return CL_INVALID_VALUE; + } + + const size_t valueSize = seNum * sizeof(unsigned int); + + if (param_value != NULL && param_value_size < valueSize) { + return CL_INVALID_VALUE; + } + + *not_null(param_value_size_ret) = valueSize; + + if (param_value != NULL) { + ::memcpy(param_value, bufSize2Se.get(), valueSize); + if (param_value_size > valueSize) { + ::memset(static_cast
(param_value) + valueSize, '\0', + param_value_size - valueSize); + } + } + + return CL_SUCCESS; + } + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +/* \brief Enqueues the command for the specified thread trace object. + * + * \param command_queue must be a valid OpenCL command queue. + * + * \param thread_trace specifies the cl_threadtrace_amd object. + * + * \param event_wait_list specify [is a pointer to] events that need to + * complete before this particular command can be executed. + * If \a event_wait_list is NULL, then this particular command does not wait + * on any event to complete. If \a event_wait_list is NULL, + * \a num_events_in_wait_list must be 0. If \a event_wait_list is not NULL, + * the list of events pointed to by \a event_wait_list must be valid and + * \a num_events_in_wait_list must be greater than 0. The events specified in + * \a event_wait_list act as synchronization points. + * + * \param num_events_in_wait_list specify the number of events in + * \a event_wait_list. It must be 0 if \a event_wait_list is NULL. It must be + * greater than 0 if \a event_wait_list is not NULL. + * + * \param event returns an event object that identifies this particular + * command and can be used to query or queue a wait for this particular + * command to complete. \a event can be NULL in which case it will not be + * possible for the application to query the status of this command or queue a + * wait for this command to complete. + * \return A non zero value if OpenCL failed to release threadTrace + * - CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with command_queue and events in event_wait_list + * are not the same. + * - CL_INVALID_VALUE if the thread_trace is invalid thread trace object . + * - CL_INVALID_VALUE if the invalid command name enum value , not described in the + * cl_threadtrace_command_name_amd, is used. + * - CL_INVALID_OPERATION if the command enqueue failed. It can happen in the following cases: + * o BEGIN_COMMAND is queued for thread trace object for which memory object/s was/were not + * bound.. + * o END_COMMAND is queued for thread trace object, for which BEGIN_COMMAND was not queued. + * o PAUSE_COMMAND is queued for thread trace object, for which BEGIN_COMMAND was not + * queued. + * o RESUME_COMMAND is queued for thread trace object, for which PAUSE_COMMAND was not + * queued. + * - CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and num_events_in_wait_list > 0, or + * event_wait_list is not NULL and num_events_in_wait_list is 0, or if event objects in + * event_wait_list are not valid events. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL + * implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL + * implementation on the host. + */ + +RUNTIME_ENTRY(cl_int, clEnqueueThreadTraceCommandAMD, + (cl_command_queue command_queue, cl_threadtrace_amd thread_trace, + cl_threadtrace_command_name_amd command_name, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + // Check if command queue is valid + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + // Check if thread trace is valid + if (!is_valid(thread_trace)) { + return CL_INVALID_OPERATION; + } + + amd::ThreadTrace* amdThreadTrace = as_amd(thread_trace); + amd::HostQueue* hostQueue = as_amd(command_queue)->asHostQueue(); + if (NULL == hostQueue) { + return CL_INVALID_COMMAND_QUEUE; + } + + // Check that device associated with the command queue is the same as with thread trace + if (&hostQueue->device() != &amdThreadTrace->device()) { + return CL_INVALID_DEVICE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, *hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + // Create a new command for the threadTraces + amd::ThreadTraceCommand* command = NULL; + switch (command_name) { + case CL_THREAD_TRACE_BEGIN_COMMAND: + if ((amdThreadTrace->getState() != amd::ThreadTrace::MemoryBound) && + (amdThreadTrace->getState() != amd::ThreadTrace::End)) { + return CL_INVALID_OPERATION; + } + amdThreadTrace->setState(amd::ThreadTrace::Begin); + command = new amd::ThreadTraceCommand( + *hostQueue, eventWaitList, static_cast(&amdThreadTrace->threadTraceConfig()), + *amdThreadTrace, amd::ThreadTraceCommand::Begin, CL_COMMAND_THREAD_TRACE); + break; + case CL_THREAD_TRACE_END_COMMAND: + if ((amdThreadTrace->getState() != amd::ThreadTrace::Begin) && + (amdThreadTrace->getState() != amd::ThreadTrace::Pause)) { + return CL_INVALID_OPERATION; + } + amdThreadTrace->setState(amd::ThreadTrace::End); + command = new amd::ThreadTraceCommand(*hostQueue, eventWaitList, + &amdThreadTrace->threadTraceConfig(), *amdThreadTrace, + amd::ThreadTraceCommand::End, CL_COMMAND_THREAD_TRACE); + break; + case CL_THREAD_TRACE_PAUSE_COMMAND: + if (amdThreadTrace->getState() != amd::ThreadTrace::Begin) { + return CL_INVALID_OPERATION; + } + amdThreadTrace->setState(amd::ThreadTrace::Pause); + command = new amd::ThreadTraceCommand( + *hostQueue, eventWaitList, &amdThreadTrace->threadTraceConfig(), *amdThreadTrace, + amd::ThreadTraceCommand::Pause, CL_COMMAND_THREAD_TRACE); + break; + case CL_THREAD_TRACE_RESUME_COMMAND: + if (amdThreadTrace->getState() != amd::ThreadTrace::Pause) { + return CL_INVALID_OPERATION; + } + amdThreadTrace->setState(amd::ThreadTrace::Begin); + command = new amd::ThreadTraceCommand( + *hostQueue, eventWaitList, &amdThreadTrace->threadTraceConfig(), *amdThreadTrace, + amd::ThreadTraceCommand::Resume, CL_COMMAND_THREAD_TRACE); + break; + } + + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Submit the command to the device + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + + return CL_SUCCESS; +} +RUNTIME_EXIT + +// +///*! \brief Enqueues the binding command to bind cl_threadtrace_amd to cl_mem object for trace +///recording.. +// * +// * \param command_queue must be a valid OpenCL command queue. +// * +// * \param thread_trace specifies the cl_threadtrace_amd object. +// * +// * \param mem_objects the cl_mem objects for trace recording +// * +// * \param mem_objects_num the number of cl_mem objects in the mem_objects +// * +// * \param buffer_size the size of each cl_mem object from mem_objects +// * +// * \param event_wait_list specify [is a pointer to] events that need to +// * complete before this particular command can be executed. +// * If \a event_wait_list is NULL, then this particular command does not wait +// * on any event to complete. If \a event_wait_list is NULL, +// * \a num_events_in_wait_list must be 0. If \a event_wait_list is not NULL, +// * the list of events pointed to by \a event_wait_list must be valid and +// * \a num_events_in_wait_list must be greater than 0. The events specified in +// * \a event_wait_list act as synchronization points. +// * +// * \param num_events_in_wait_list specify the number of events in +// * \a event_wait_list. It must be 0 if \a event_wait_list is NULL. It must be +// * greater than 0 if \a event_wait_list is not NULL. +// * +// * \param event returns an event object that identifies this particular +// * command and can be used to query or queue a wait for this particular +// * command to complete. \a event can be NULL in which case it will not be +// * possible for the application to query the status of this command or queue a +// * wait for this command to complete. +// * \return A non zero value if OpenCL failed to set threadTrace buffer parameter +// * - CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue. +// * - CL_INVALID_CONTEXT if the context associated with command_queue and events in +// event_wait_list are not the same. +// * - CL_INVALID_VALUE if the thread_trace is invalid thread trace object. +// * - CL_INVALID_VALUE if the buffer_size is negative or zero. +// * - CL_INVALID_VALUE if the sub_buffers_num I less than 1. +// * - CL_INVALID_OPERATION if the mem_objects_num is not equal to the number of Shader Engines of +// the [GPU] device. +// * - CL_INVALID_MEM_OBJECT if one on memory objects in the mem_objects array is not a valid +// memory object or memory_objects is NULL. +// * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory for the data store +// associated from the memory objects of the mem_objects array. +// * - CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and num_events_in_wait_list > 0, or +// event_wait_list is not NULL and num_events_in_wait_list is 0, or if event objects in +// event_wait_list are not valid events. +// * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL +// implementation on the device. +// * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the +// * OpenCL implementation on the host. +// */ +RUNTIME_ENTRY(cl_int, clEnqueueBindThreadTraceBufferAMD, + (cl_command_queue command_queue, cl_threadtrace_amd thread_trace, cl_mem* mem_objects, + cl_uint mem_objects_num, cl_uint buffer_size, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event)) { + // Check if command queue is valid + if (!is_valid(command_queue)) { + return CL_INVALID_COMMAND_QUEUE; + } + + // Check if thread trace is valid + if (!is_valid(thread_trace)) { + return CL_INVALID_OPERATION; + } + + // Check if input values are valid + if ((mem_objects == NULL) || (buffer_size <= 0)) { + return CL_INVALID_VALUE; + } + + amd::ThreadTrace* amdThreadTrace = as_amd(thread_trace); + + // Check if the number of bound memory objects is the same as the number of SEs + if (amdThreadTrace->deviceSeNumThreadTrace() != mem_objects_num) { + return CL_INVALID_OPERATION; + } + // Check if memory objects ,bound the thread trace,are valid + for (size_t i = 0; i < mem_objects_num; ++i) { + cl_mem obj = mem_objects[i]; + if (!is_valid(obj)) { + return CL_INVALID_MEM_OBJECT; + } + } + + amd::HostQueue* hostQueue = as_amd(command_queue)->asHostQueue(); + if (NULL == hostQueue) { + return CL_INVALID_COMMAND_QUEUE; + } + + // Check that device associated with the command queue is the same as with thread trace + if (&hostQueue->device() != &amdThreadTrace->device()) { + return CL_INVALID_DEVICE; + } + + amd::Command::EventWaitList eventWaitList; + cl_int err = amd::clSetEventWaitList(eventWaitList, *hostQueue, num_events_in_wait_list, + event_wait_list); + if (err != CL_SUCCESS) { + return err; + } + + amdThreadTrace->setState(amd::ThreadTrace::MemoryBound); + // Create a new ThreadTraceMemObjectsCommand command + amd::ThreadTraceMemObjectsCommand* command = new amd::ThreadTraceMemObjectsCommand( + *hostQueue, eventWaitList, mem_objects_num, mem_objects, buffer_size, *amdThreadTrace, + CL_COMMAND_THREAD_TRACE_MEM); + if (command == NULL) { + return CL_OUT_OF_HOST_MEMORY; + } + + // Make sure we have memory for the command execution + if (!command->validateMemory()) { + delete command; + return CL_OUT_OF_RESOURCES; + } + // Submit the command to the device + command->enqueue(); + + *not_null(event) = as_cl(&command->event()); + if (event == NULL) { + command->release(); + } + return CL_SUCCESS; +} +RUNTIME_EXIT + +/*! @} + * @} + */ diff --git a/opencl/amdocl/cl_thread_trace_amd.h b/opencl/amdocl/cl_thread_trace_amd.h new file mode 100644 index 0000000000..976f8ae75b --- /dev/null +++ b/opencl/amdocl/cl_thread_trace_amd.h @@ -0,0 +1,363 @@ +/* Copyright (c) 2012 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef __CL_THREAD_TRACE_AMD_H +#define __CL_THREAD_TRACE_AMD_H + +#include "CL/cl_platform.h" + +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus*/ + +typedef struct _cl_threadtrace_amd* cl_threadtrace_amd; +typedef cl_uint cl_thread_trace_param; +typedef cl_uint cl_threadtrace_info; + +/* cl_command_type */ +#define CL_COMMAND_THREAD_TRACE_MEM 0x4500 +#define CL_COMMAND_THREAD_TRACE 0x4501 + +/* cl_threadtrace_command_name_amd enumeration */ +typedef enum _cl_threadtrace_command_name_amd { + CL_THREAD_TRACE_BEGIN_COMMAND, + CL_THREAD_TRACE_END_COMMAND, + CL_THREAD_TRACE_PAUSE_COMMAND, + CL_THREAD_TRACE_RESUME_COMMAND +} cl_threadtrace_command_name_amd; + +// Thread trace parameters +enum ThreadTraceParameter { + CL_THREAD_TRACE_PARAM_TOKEN_MASK, + CL_THREAD_TRACE_PARAM_REG_MASK, + CL_THREAD_TRACE_PARAM_COMPUTE_UNIT_TARGET, + CL_THREAD_TRACE_PARAM_SHADER_ARRAY_TARGET, + CL_THREAD_TRACE_PARAM_SIMD_MASK, + CL_THREAD_TRACE_PARAM_VM_ID_MASK, + CL_THREAD_TRACE_PARAM_RANDOM_SEED, + CL_THREAD_TRACE_PARAM_CAPTURE_MODE, + CL_THREAD_TRACE_PARAM_INSTRUCTION_MASK, + CL_THREAD_TRACE_PARAM_USER_DATA, + CL_THREAD_TRACE_PARAM_IS_WRAPPED +}; + +// CL_THREAD_TRACE_PARAM_TOKEN_MASK data selects for SI +enum CL_THREAD_TRACE_TOKEN_MASK { + // Time passed + CL_THREAD_TRACE_TOKEN_MASK_TIME_SI = 0x00000001, + // Resync the timestamp + CL_THREAD_TRACE_TOKEN_MASK_TIMESTAMP_SI = 0x00000002, + // A register write has occurred + CL_THREAD_TRACE_TOKEN_MASK_REG_SI = 0x00000004, + // A wavefront has started + CL_THREAD_TRACE_TOKEN_MASK_WAVE_START_SI = 0x00000008, + // Output space has been allocated for color/Z [Should be used for cl-gl] + CL_THREAD_TRACE_TOKEN_MASK_WAVE_PS_ALLOC_SI = 0x00000010, + // Output space has been allocated for vertex position [Should be used for cl-gl] + CL_THREAD_TRACE_TOKEN_MASK_WAVE_VS_ALLOC_SI = 0x00000020, + // Wavefront completion + CL_THREAD_TRACE_TOKEN_MASK_WAVE_END_SI = 0x00000040, + // An event has reached the top of a shader stage. In-order with WAVE_START + CL_THREAD_TRACE_TOKEN_MASK_EVENT_SI = 0x00000080, + // An event has reached the top of a compute shader stage. In-order with WAVE_START + CL_THREAD_TRACE_TOKEN_MASK_EVENT_CS_SI = 0x00000100, + // An event has reached the top of a shader stage for the second GFX pipe. In-order with + // WAVE_START. + //[Should be used for cl-gl] + CL_THREAD_TRACE_TOKEN_MASK_EVENT_GFX_SI = 0x00000200, + // The kernel has executed an instruction + CL_THREAD_TRACE_TOKEN_MASK_INST_SI = 0x00000400, + // The kernel has explicitly written the PC value + CL_THREAD_TRACE_TOKEN_MASK_INST_PC_SI = 0x00000800, + // The kernel has written user data into the thread trace buffer + CL_THREAD_TRACE_TOKEN_MASK_INST_USERDATA_SI = 0x00001000, + // Provides information about instruction scheduling + CL_THREAD_TRACE_TOKEN_MASK_ISSUE_SI = 0x00002000, + // The performance counter delta has been updated + CL_THREAD_TRACE_TOKEN_MASK_PERF_SI = 0x00004000, + // A miscellaneous event has been sent + CL_THREAD_TRACE_TOKEN_MASK_MISC_SI = 0x00008000, + // All possible tokens + CL_THREAD_TRACE_TOKEN_MASK_ALL_SI = 0x0000ffff, +}; + +// CL_THREAD_TRACE_PARAM_REG_MASK data selects +enum CL_THREAD_TRACE_REG_MASK { + // Event initiator + CL_THREAD_TRACE_REG_MASK_EVENT_SI = 0x00000001, + // Draw initiator [Should be used for cl-gl] + CL_THREAD_TRACE_REG_MASK_DRAW_SI = 0x00000002, + // Dispatch initiator + CL_THREAD_TRACE_REG_MASK_DISPATCH_SI = 0x00000004, + // User data from host + CL_THREAD_TRACE_REG_MASK_USERDATA_SI = 0x00000008, + // GFXDEC register (8-state) [Should be used for cl-gl] + CL_THREAD_TRACE_REG_MASK_GFXDEC_SI = 0x00000020, + // SHDEC register (many state) + CL_THREAD_TRACE_REG_MASK_SHDEC_SI = 0x00000040, + // Other registers + CL_THREAD_TRACE_REG_MASK_OTHER_SI = 0x00000080, + // All possible registers types + CL_THREAD_TRACE_REG_MASK_ALL_SI = 0x000000ff, +}; + +// CL_THREAD_TRACE_PARAM_VM_ID_MASK data selects +enum CL_THREAD_TRACE_VM_ID_MASK { + // Capture only data from the VM_ID used to write {SQTT}_BASE + CL_THREAD_TRACE_VM_ID_MASK_SINGLE = 0, + // Capture all data from all VM_IDs + CL_THREAD_TRACE_VM_ID_MASK_ALL = 1, + // Capture all data but only get target (a.k.a. detail) data from VM_ID used to write {SQTT}_BASE + CL_THREAD_TRACE_VM_ID_MASK_SINGLE_DETAIL = 2 +}; + +// CL_THREAD_TRACE_PARAM_CAPTURE_MODE data +enum CL_THREAD_TRACE_CAPTURE_MODE { + // Capture all data in the thread trace buffer + CL_THREAD_TRACE_CAPTURE_ALL = 0, + // Capture only data between THREAD_TRACE_START and THREAD_TRACE_STOP events + CL_THREAD_TRACE_CAPTURE_SELECT = 1, + // Capture data between THREAD_TRACE_START and THREAD_TRACE_/STOP events, + // and global/reference data at all times + CL_THREAD_TRACE_CAPTURE_SELECT_DETAIL = 2 +}; + +// CL_THREAD_TRACE_PARAM_INSTRUCTION_MASK data selects +enum CL_THREAD_TRACE_INSTRUCTION_MASK { + // Generate {SQTT}_TOKEN_INST tokens for all instructions + CL_THREAD_TRACE_INST_MASK_ALL, + // Generate {SQTT}_TOKEN_INST tokens for stalled instructions only + CL_THREAD_TRACE_INST_MASK_STALLED, + // Generate {SQTT}_TOKEN_INST messages for stalled and other (no op/wait/set prio/etc) + // instructions + CL_THREAD_TRACE_INST_MASK_STALLED_AND_IMMEDIATE, + // Generate {SQTT}_TOKEN_INST messages for immediate instructions only only [ Should be used only + // for CI] + CL_THREAD_TRACE_INST_MASK_IMMEDIATE_CI, +}; + +enum ThreadTraceInfo { + CL_THREAD_TRACE_SE, + CL_THREAD_TRACE_BUFFERS_FILLED, + CL_THREAD_TRACE_BUFFERS_SIZE +}; + + +/*! \brief Creates a new cl_threadtrace_amd object + * + * \param device must be a valid OpenCL device. + * + * \param errcode_ret A non zero value if OpenCL failed to create threadTrace + * -CL_INVALID_DEVICE if devices contains an invalid device. + * -CL_DEVICE_NOT_AVAILABLE if a device is currently not available even + * though the device was returned by clGetDeviceIDs. + * -CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the + * OpenCL implementation on the device. + * -CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the + OpenCL implementation on the host. + * + * \return the created threadTrace object + */ +extern CL_API_ENTRY cl_threadtrace_amd CL_API_CALL clCreateThreadTraceAMD( + cl_device_id /* device */, cl_int* /* errcode_ret */ + ) CL_API_SUFFIX__VERSION_1_0; + +/*! \brief Destroys a cl_threadtrace_amd object. + * + * \param threadTrace the cl_threadtrace_amd object for release + * + * \return A non zero value if OpenCL failed to release threadTrace + * -CL_INVALID_VALUE if the thread_trace is not a valid OpenCL thread trace object + (cl_threadtrace_amd) . + * -CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the + * OpenCL implementation on the device. + * -CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the + OpenCL implementation on the host. + */ +extern CL_API_ENTRY cl_int CL_API_CALL clReleaseThreadTraceAMD(cl_threadtrace_amd /* threadTrace */ + ) CL_API_SUFFIX__VERSION_1_0; + +/*! \brief Increments the cl_threadtrace_amd object reference count. + * + * \param threadTrace the cl_threadtrace_amd object for retain + * + * \return A non zero value if OpenCL failed to retain threadTrace + * -CL_INVALID_VALUE if the thread_trace is not a valid thread trace object (cl_threadtrace_amd) . + * -CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the + OpenCL implementation on the device. + * -CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the + OpenCL implementation on the host. + */ +extern CL_API_ENTRY cl_int CL_API_CALL clRetainThreadTraceAMD(cl_threadtrace_amd /* threadTrace */ + ) CL_API_SUFFIX__VERSION_1_0; + +/*! \brief Sets the cl_threadtrace_amd object configuration parameter. + * + * \param thread_trace the cl_threadtrace_amd object to set configuration parameter + * + * \param config_param the cl_thread_trace_param + * + * \param param_value corresponding to configParam + * + * \return A non zero value if OpenCL failed to set threadTrace buffer parameter + * - CL_INVALID_VALUE if the thread_trace is invalid thread trace object. + * - CL_INVALID_VALUE if the invalid config_param or param_value enum values , are used. + * - CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and num_events_in_wait_list > 0, or + event_wait_list is not NULL and num_events_in_wait_list is 0, + * - or if event objects in event_wait_list are not valid events. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL + implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the + OpenCL implementation on the host. + */ + +extern CL_API_ENTRY cl_int CL_API_CALL clSetThreadTraceParamAMD( + cl_threadtrace_amd /*thread_trace*/, cl_thread_trace_param /*config_param*/, + cl_uint /*param_value*/ + ) CL_API_SUFFIX__VERSION_1_0; + +/* \brief Enqueues the binding command to bind cl_threadtrace_amd to cl_mem object for trace + * recording.. + * + * \param command_queue must be a valid OpenCL command queue. + * + * \param thread_trace specifies the cl_threadtrace_amd object. + * + * \param mem_objects the cl_mem objects for trace recording + * + * \param mem_objects_num the number of cl_mem objects in the mem_objects + * + * \param buffer_size the size of each cl_mem object from mem_objects + * + * \param event_wait_list specify [is a pointer to] events that need to + * complete before this particular command can be executed. + * If \a event_wait_list is NULL, then this particular command does not wait + * on any event to complete. If \a event_wait_list is NULL, + * \a num_events_in_wait_list must be 0. If \a event_wait_list is not NULL, + * the list of events pointed to by \a event_wait_list must be valid and + * \a num_events_in_wait_list must be greater than 0. The events specified in + * \a event_wait_list act as synchronization points. + * + * \param num_events_in_wait_list specify the number of events in + * \a event_wait_list. It must be 0 if \a event_wait_list is NULL. It must be + * greater than 0 if \a event_wait_list is not NULL. + * + * \param event returns an event object that identifies this particular + * command and can be used to query or queue a wait for this particular + * command to complete. \a event can be NULL in which case it will not be + * possible for the application to query the status of this command or queue a + * wait for this command to complete. + * \return A non zero value if OpenCL failed to set threadTrace buffer parameter + * - CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with command_queue and events in event_wait_list + * are not the same. + * - CL_INVALID_VALUE if the thread_trace is invalid thread trace object. + * - CL_INVALID_VALUE if the buffer_size is negative or zero. + * - CL_INVALID_VALUE if the sub_buffers_num I less than 1. + * - CL_INVALID_OPERATION if the mem_objects_num is not equal to the number of Shader Engines of + * the [GPU] device. + * - CL_INVALID_MEM_OBJECT if one on memory objects in the mem_objects array is not a valid memory + * object or memory_objects is NULL. + * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory for the data store + * associated from the memory objects of the mem_objects array. + * - CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and num_events_in_wait_list > 0, or + * event_wait_list is not NULL and num_events_in_wait_list is 0, or if event objects in + * event_wait_list are not valid events. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL + * implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the + * OpenCL implementation on the host. + */ +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueBindThreadTraceBufferAMD( + cl_command_queue command_queue, cl_threadtrace_amd /*thread_trace*/, cl_mem* /*mem_objects*/, + cl_uint /*mem_objects_num*/, cl_uint /*buffer_size*/, cl_uint /*num_events_in_wait_list*/, + const cl_event* /*event_wait_list*/, cl_event* /*event*/ + ) CL_API_SUFFIX__VERSION_1_0; + +/*! \brief Get specific information about the OpenCL Thread Trace. + * + * \param thread_trace_info_param is an enum that identifies the Thread Trace information being + * queried. + * + * \param param_value is a pointer to memory location where appropriate values + * for a given \a threadTrace_info_param will be returned. If \a param_value is NULL, + * it is ignored. + * + * \param param_value_size specifies the size in bytes of memory pointed to by + * \a param_value. This size in bytes must be >= size of return type. + * + * \param param_value_size_ret returns the actual size in bytes of data being + * queried by param_value. If \a param_value_size_ret is NULL, it is ignored. + * + * \return One of the following values: + * CL_INVALID_OPERATION if cl_threadtrace_amd object is not valid + * - CL_INVALID_VALUE if \a param_name is not one of the supported + * values or if size in bytes specified by \a param_value_size is < size of + * return type and \a param_value is not a NULL value. + * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the + * OpenCL implementation on the host. + * CL_SUCCESS if the function is executed successfully. + */ +extern CL_API_ENTRY cl_int CL_API_CALL clGetThreadTraceInfoAMD( + cl_threadtrace_amd /* thread_trace */, cl_threadtrace_info /*thread_trace_info_param*/, + size_t /*param_value_size*/, void* /*param_value*/, size_t* /*param_value_size_ret*/ + ) CL_API_SUFFIX__VERSION_1_0; + +/*! \brief Enqueues the thread trace command for the specified thread trace object. + * + * \param command_queue must be a valid OpenCL command queue. + * + * \param threadTraces specifies an array of cl_threadtrace_amd objects. + * + * \return A non zero value if OpenCL failed to release threadTrace + * - CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue. + * - CL_INVALID_CONTEXT if the context associated with command_queue and events in event_wait_list + * are not the same. + * - CL_INVALID_VALUE if the thread_trace is invalid thread trace object . + * - CL_INVALID_VALUE if the invalid command name enum value , not described in the + * cl_threadtrace_command_name_amd, is used. + * - CL_INVALID_OPERATION if the command enqueue failed. It can happen in the following cases: + * o BEGIN_COMMAND is queued for thread trace object for which memory object/s was/were not + * bound.. + * o END_COMMAND is queued for thread trace object, for which BEGIN_COMMAND was not queued. + * o PAUSE_COMMAND is queued for thread trace object, for which BEGIN_COMMAND was not + * queued. + * o RESUME_COMMAND is queued for thread trace object, for which PAUSE_COMMAND was not + * queued. + * - CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and num_events_in_wait_list > 0, or + * event_wait_list is not NULL and num_events_in_wait_list is 0, or if event objects in + * event_wait_list are not valid events. + * - CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL + * implementation on the device. + * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL + * implementation on the host. + */ +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueThreadTraceCommandAMD( + cl_command_queue /*command_queue*/, cl_threadtrace_amd /*thread_trace*/, + cl_threadtrace_command_name_amd /*command_name*/, cl_uint /*num_events_in_wait_list*/, + const cl_event* /*event_wait_list*/, cl_event* /*event*/ + ) CL_API_SUFFIX__VERSION_1_0; + + +#ifdef __cplusplus +} /*extern "C"*/ +#endif /*__cplusplus*/ + +#endif /*__CL_THREAD_TRACE_AMD_H*/ diff --git a/opencl/amdocl/cl_vk_amd.hpp b/opencl/amdocl/cl_vk_amd.hpp new file mode 100644 index 0000000000..2883f8a216 --- /dev/null +++ b/opencl/amdocl/cl_vk_amd.hpp @@ -0,0 +1,119 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#pragma once + +#include "platform/context.hpp" +#include "platform/memory.hpp" + +namespace amd +{ + class VkObject : public InteropObject + { + protected: + amd::Os::FileDesc handleVk_; + + public: + //! GLObject constructor initializes member variables + VkObject( + amd::Os::FileDesc handle + ) // Initialization of member variables + + { + handleVk_ = handle; + } + + virtual ~VkObject() {} + VkObject* asVkObject() { return this; } + amd::Os::FileDesc getVkSharedHandle() const { return handleVk_; } + + + }; + + class BufferVk : public Buffer, public VkObject + { + protected: + //! Initializes the device memory array which is nested + // after'BufferVk' object in memory layout. + void initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(BufferVk)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); + } + public: + //! BufferVk constructor just calls constructors of base classes + //! to pass down the parameters + BufferVk( + Context& amdContext, + size_t uiSizeInBytes, + amd::Os::FileDesc handle) + : // Call base classes constructors + Buffer( + amdContext, + 0, + uiSizeInBytes + ), + VkObject( + handle + ) + { + setInteropObj(this); + } + virtual ~BufferVk() {} + + BufferVk* asBufferVk() { return this; } + }; + + // to be modified once image requirments are known, for now, implement like buffer + + class ImageVk : public Buffer, public VkObject + { + protected: + //! Initializes the device memory array which is nested + // after'ImageVk' object in memory layout. + void initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(ImageVk)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); + } + public: + //! ImageVk constructor just calls constructors of base classes + //! to pass down the parameters + ImageVk( + Context& amdContext, + size_t uiSizeInBytes, + amd::Os::FileDesc handle) + : // Call base classes constructors + Buffer( + amdContext, + 0, + uiSizeInBytes + ), + VkObject( + handle + ) + { + setInteropObj(this); + } + virtual ~ImageVk() {} + + ImageVk* asImageVk() { return this; } + }; +} diff --git a/opencl/amdocl/cmake/FindROCclr.cmake b/opencl/amdocl/cmake/FindROCclr.cmake new file mode 100644 index 0000000000..b9ff2b1c78 --- /dev/null +++ b/opencl/amdocl/cmake/FindROCclr.cmake @@ -0,0 +1,51 @@ +# Copyright (c) 2020 - 2021 Advanced Micro Devices, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +if(ROCCLR_FOUND) + return() +endif() + +find_path(ROCCLR_INCLUDE_DIR top.hpp + HINTS + ${ROCCLR_PATH} + PATHS + # gerrit repo name + ${CMAKE_SOURCE_DIR}/vdi + ${CMAKE_SOURCE_DIR}/../vdi + ${CMAKE_SOURCE_DIR}/../../vdi + # github repo name + ${CMAKE_SOURCE_DIR}/ROCclr + ${CMAKE_SOURCE_DIR}/../ROCclr + ${CMAKE_SOURCE_DIR}/../../ROCclr + # jenkins repo name + ${CMAKE_SOURCE_DIR}/rocclr + ${CMAKE_SOURCE_DIR}/../rocclr + ${CMAKE_SOURCE_DIR}/../../rocclr + PATH_SUFFIXES + include) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ROCclr + "\nROCclr not found" + ROCCLR_INCLUDE_DIR) +mark_as_advanced(ROCCLR_INCLUDE_DIR) + +list(APPEND CMAKE_MODULE_PATH "${ROCCLR_INCLUDE_DIR}/../cmake") +include(ROCclr) diff --git a/opencl/amdocl/gl_functions.hpp b/opencl/amdocl/gl_functions.hpp new file mode 100644 index 0000000000..7994e87667 --- /dev/null +++ b/opencl/amdocl/gl_functions.hpp @@ -0,0 +1,64 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +GLPREFIX(GLubyte*, glGetString, (GLenum name)) + +GLPREFIX(void, glBindBuffer, (GLenum target, GLuint buffer)) +//GLPREFIX(void, glBindFramebufferEXT, (GLenum target, GLuint framebuffer)) +GLPREFIX(void, glBindRenderbuffer, (GLenum target, GLuint renderbuffer)) +GLPREFIX(void, glBindTexture, (GLenum target, GLuint texture)) +GLPREFIX(void, glBufferData, (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)) + +GLPREFIX(GLenum, glCheckFramebufferStatusEXT, (GLenum target)) + +GLPREFIX(void, glDeleteBuffers, (GLsizei n, const GLuint* buffers)) +GLPREFIX(void, glDrawPixels, (GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)) + +//GLPREFIX(void, glFramebufferRenderbufferEXT, (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)) + +GLPREFIX(void, glGenBuffers, (GLsizei n, GLuint* buffers)) +//GLPREFIX(void, glGenFramebuffersEXT, (GLsizei n, GLuint* framebuffers)) +//10 +GLPREFIX(void, glGetBufferParameteriv, (GLenum target, GLenum pname, GLint* params)) +GLPREFIX(GLenum, glGetError, (void)) +GLPREFIX(void, glFinish, (void)) +GLPREFIX(void, glFlush, (void)) +GLPREFIX(GLenum, glClientWaitSync, (GLsync sync, GLbitfield flags, GLuint64 timeout)) +GLPREFIX(void, glGetIntegerv, (GLenum pname, GLint *params)) +GLPREFIX(void, glGetRenderbufferParameterivEXT, (GLenum target, GLenum pname, GLint* params)) +//GLPREFIX(GLubyte*, glGetString, (GLenum name)) +GLPREFIX(void, glGetTexImage, (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels)) +GLPREFIX(void, glGetTexLevelParameteriv, (GLenum target, GLint level, GLenum pname, GLint *params)) +GLPREFIX(void, glGetTexParameteriv, (GLenum target, GLenum pname, GLint *params)) + +GLPREFIX(GLboolean, glIsBuffer, (GLuint buffer)) +GLPREFIX(GLboolean, glIsRenderbufferEXT, (GLuint renderbuffer)) +GLPREFIX(GLboolean, glIsTexture, (GLuint texture)) +//20 +GLPREFIX(GLvoid*, glMapBuffer, (GLenum target, GLenum access)) + +GLPREFIX(void, glReadPixels, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels)) + +GLPREFIX(void, glTexImage2D, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)) +GLPREFIX(void, glTexImage3D, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)) + +GLPREFIX(GLboolean, glUnmapBuffer, (GLenum target)) + +#undef GLPREFIX diff --git a/opencl/amdocl/glibc_functions.cpp b/opencl/amdocl/glibc_functions.cpp new file mode 100644 index 0000000000..04822436c2 --- /dev/null +++ b/opencl/amdocl/glibc_functions.cpp @@ -0,0 +1,41 @@ +/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#if defined(__linux__) + +#include + +#if defined(__cplusplus) +extern "C" { +#endif // __cplusplus + +#if defined(_LP64) +asm (".symver memcpy, memcpy@GLIBC_2.2.5"); +void *__wrap_memcpy(void *dest, const void *src, size_t n) +{ + return memcpy(dest, src, n); +} +#endif // _LP64 + +#if defined(__cplusplus) +} +#endif // __cplusplus) + +#endif // __linux__ diff --git a/opencl/config/amdocl32.icd b/opencl/config/amdocl32.icd new file mode 100644 index 0000000000..53fb988802 --- /dev/null +++ b/opencl/config/amdocl32.icd @@ -0,0 +1 @@ +libamdocl32.so diff --git a/opencl/config/amdocl64.icd b/opencl/config/amdocl64.icd new file mode 100644 index 0000000000..ec1be031ec --- /dev/null +++ b/opencl/config/amdocl64.icd @@ -0,0 +1 @@ +libamdocl64.so diff --git a/opencl/configure b/opencl/configure new file mode 100644 index 0000000000..e69de29bb2 diff --git a/opencl/khronos/headers/EGL/egl.h b/opencl/khronos/headers/EGL/egl.h new file mode 100644 index 0000000000..99ea342a47 --- /dev/null +++ b/opencl/khronos/headers/EGL/egl.h @@ -0,0 +1,329 @@ +/* -*- mode: c; tab-width: 8; -*- */ +/* vi: set sw=4 ts=8: */ +/* Reference version of egl.h for EGL 1.4. + * $Revision: 9356 $ on $Date: 2009-10-21 02:52:25 -0700 (Wed, 21 Oct 2009) $ + */ + +/* +** Copyright (c) 2007-2009 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +#ifndef __egl_h_ +#define __egl_h_ + +/* All platform-dependent types and macro boilerplate (such as EGLAPI + * and EGLAPIENTRY) should go in eglplatform.h. + */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* EGL Types */ +/* EGLint is defined in eglplatform.h */ +typedef unsigned int EGLBoolean; +typedef unsigned int EGLenum; +typedef void *EGLConfig; +typedef void *EGLContext; +typedef void *EGLDisplay; +typedef void *EGLSurface; +typedef void *EGLClientBuffer; + +/* EGL Versioning */ +#define EGL_VERSION_1_0 1 +#define EGL_VERSION_1_1 1 +#define EGL_VERSION_1_2 1 +#define EGL_VERSION_1_3 1 +#define EGL_VERSION_1_4 1 + +/* EGL Enumerants. Bitmasks and other exceptional cases aside, most + * enums are assigned unique values starting at 0x3000. + */ + +/* EGL aliases */ +#define EGL_FALSE 0 +#define EGL_TRUE 1 + +/* Out-of-band handle values */ +#define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0) +#define EGL_NO_CONTEXT ((EGLContext)0) +#define EGL_NO_DISPLAY ((EGLDisplay)0) +#define EGL_NO_SURFACE ((EGLSurface)0) + +/* Out-of-band attribute value */ +#define EGL_DONT_CARE ((EGLint)-1) + +/* Errors / GetError return values */ +#define EGL_SUCCESS 0x3000 +#define EGL_NOT_INITIALIZED 0x3001 +#define EGL_BAD_ACCESS 0x3002 +#define EGL_BAD_ALLOC 0x3003 +#define EGL_BAD_ATTRIBUTE 0x3004 +#define EGL_BAD_CONFIG 0x3005 +#define EGL_BAD_CONTEXT 0x3006 +#define EGL_BAD_CURRENT_SURFACE 0x3007 +#define EGL_BAD_DISPLAY 0x3008 +#define EGL_BAD_MATCH 0x3009 +#define EGL_BAD_NATIVE_PIXMAP 0x300A +#define EGL_BAD_NATIVE_WINDOW 0x300B +#define EGL_BAD_PARAMETER 0x300C +#define EGL_BAD_SURFACE 0x300D +#define EGL_CONTEXT_LOST 0x300E /* EGL 1.1 - IMG_power_management */ + +/* Reserved 0x300F-0x301F for additional errors */ + +/* Config attributes */ +#define EGL_BUFFER_SIZE 0x3020 +#define EGL_ALPHA_SIZE 0x3021 +#define EGL_BLUE_SIZE 0x3022 +#define EGL_GREEN_SIZE 0x3023 +#define EGL_RED_SIZE 0x3024 +#define EGL_DEPTH_SIZE 0x3025 +#define EGL_STENCIL_SIZE 0x3026 +#define EGL_CONFIG_CAVEAT 0x3027 +#define EGL_CONFIG_ID 0x3028 +#define EGL_LEVEL 0x3029 +#define EGL_MAX_PBUFFER_HEIGHT 0x302A +#define EGL_MAX_PBUFFER_PIXELS 0x302B +#define EGL_MAX_PBUFFER_WIDTH 0x302C +#define EGL_NATIVE_RENDERABLE 0x302D +#define EGL_NATIVE_VISUAL_ID 0x302E +#define EGL_NATIVE_VISUAL_TYPE 0x302F +#define EGL_SAMPLES 0x3031 +#define EGL_SAMPLE_BUFFERS 0x3032 +#define EGL_SURFACE_TYPE 0x3033 +#define EGL_TRANSPARENT_TYPE 0x3034 +#define EGL_TRANSPARENT_BLUE_VALUE 0x3035 +#define EGL_TRANSPARENT_GREEN_VALUE 0x3036 +#define EGL_TRANSPARENT_RED_VALUE 0x3037 +#define EGL_NONE 0x3038 /* Attrib list terminator */ +#define EGL_BIND_TO_TEXTURE_RGB 0x3039 +#define EGL_BIND_TO_TEXTURE_RGBA 0x303A +#define EGL_MIN_SWAP_INTERVAL 0x303B +#define EGL_MAX_SWAP_INTERVAL 0x303C +#define EGL_LUMINANCE_SIZE 0x303D +#define EGL_ALPHA_MASK_SIZE 0x303E +#define EGL_COLOR_BUFFER_TYPE 0x303F +#define EGL_RENDERABLE_TYPE 0x3040 +#define EGL_MATCH_NATIVE_PIXMAP 0x3041 /* Pseudo-attribute (not queryable) */ +#define EGL_CONFORMANT 0x3042 + +/* Reserved 0x3041-0x304F for additional config attributes */ + +/* Config attribute values */ +#define EGL_SLOW_CONFIG 0x3050 /* EGL_CONFIG_CAVEAT value */ +#define EGL_NON_CONFORMANT_CONFIG 0x3051 /* EGL_CONFIG_CAVEAT value */ +#define EGL_TRANSPARENT_RGB 0x3052 /* EGL_TRANSPARENT_TYPE value */ +#define EGL_RGB_BUFFER 0x308E /* EGL_COLOR_BUFFER_TYPE value */ +#define EGL_LUMINANCE_BUFFER 0x308F /* EGL_COLOR_BUFFER_TYPE value */ + +/* More config attribute values, for EGL_TEXTURE_FORMAT */ +#define EGL_NO_TEXTURE 0x305C +#define EGL_TEXTURE_RGB 0x305D +#define EGL_TEXTURE_RGBA 0x305E +#define EGL_TEXTURE_2D 0x305F + +/* Config attribute mask bits */ +#define EGL_PBUFFER_BIT 0x0001 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_PIXMAP_BIT 0x0002 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_WINDOW_BIT 0x0004 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_VG_COLORSPACE_LINEAR_BIT 0x0020 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_VG_ALPHA_FORMAT_PRE_BIT 0x0040 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_MULTISAMPLE_RESOLVE_BOX_BIT 0x0200 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_SWAP_BEHAVIOR_PRESERVED_BIT 0x0400 /* EGL_SURFACE_TYPE mask bits */ + +#define EGL_OPENGL_ES_BIT 0x0001 /* EGL_RENDERABLE_TYPE mask bits */ +#define EGL_OPENVG_BIT 0x0002 /* EGL_RENDERABLE_TYPE mask bits */ +#define EGL_OPENGL_ES2_BIT 0x0004 /* EGL_RENDERABLE_TYPE mask bits */ +#define EGL_OPENGL_BIT 0x0008 /* EGL_RENDERABLE_TYPE mask bits */ + +/* QueryString targets */ +#define EGL_VENDOR 0x3053 +#define EGL_VERSION 0x3054 +#define EGL_EXTENSIONS 0x3055 +#define EGL_CLIENT_APIS 0x308D + +/* QuerySurface / SurfaceAttrib / CreatePbufferSurface targets */ +#define EGL_HEIGHT 0x3056 +#define EGL_WIDTH 0x3057 +#define EGL_LARGEST_PBUFFER 0x3058 +#define EGL_TEXTURE_FORMAT 0x3080 +#define EGL_TEXTURE_TARGET 0x3081 +#define EGL_MIPMAP_TEXTURE 0x3082 +#define EGL_MIPMAP_LEVEL 0x3083 +#define EGL_RENDER_BUFFER 0x3086 +#define EGL_VG_COLORSPACE 0x3087 +#define EGL_VG_ALPHA_FORMAT 0x3088 +#define EGL_HORIZONTAL_RESOLUTION 0x3090 +#define EGL_VERTICAL_RESOLUTION 0x3091 +#define EGL_PIXEL_ASPECT_RATIO 0x3092 +#define EGL_SWAP_BEHAVIOR 0x3093 +#define EGL_MULTISAMPLE_RESOLVE 0x3099 + +/* EGL_RENDER_BUFFER values / BindTexImage / ReleaseTexImage buffer targets */ +#define EGL_BACK_BUFFER 0x3084 +#define EGL_SINGLE_BUFFER 0x3085 + +/* OpenVG color spaces */ +#define EGL_VG_COLORSPACE_sRGB 0x3089 /* EGL_VG_COLORSPACE value */ +#define EGL_VG_COLORSPACE_LINEAR 0x308A /* EGL_VG_COLORSPACE value */ + +/* OpenVG alpha formats */ +#define EGL_VG_ALPHA_FORMAT_NONPRE 0x308B /* EGL_ALPHA_FORMAT value */ +#define EGL_VG_ALPHA_FORMAT_PRE 0x308C /* EGL_ALPHA_FORMAT value */ + +/* Constant scale factor by which fractional display resolutions & + * aspect ratio are scaled when queried as integer values. + */ +#define EGL_DISPLAY_SCALING 10000 + +/* Unknown display resolution/aspect ratio */ +#define EGL_UNKNOWN ((EGLint)-1) + +/* Back buffer swap behaviors */ +#define EGL_BUFFER_PRESERVED 0x3094 /* EGL_SWAP_BEHAVIOR value */ +#define EGL_BUFFER_DESTROYED 0x3095 /* EGL_SWAP_BEHAVIOR value */ + +/* CreatePbufferFromClientBuffer buffer types */ +#define EGL_OPENVG_IMAGE 0x3096 + +/* QueryContext targets */ +#define EGL_CONTEXT_CLIENT_TYPE 0x3097 + +/* CreateContext attributes */ +#define EGL_CONTEXT_CLIENT_VERSION 0x3098 + +/* Multisample resolution behaviors */ +#define EGL_MULTISAMPLE_RESOLVE_DEFAULT 0x309A /* EGL_MULTISAMPLE_RESOLVE value */ +#define EGL_MULTISAMPLE_RESOLVE_BOX 0x309B /* EGL_MULTISAMPLE_RESOLVE value */ + +/* BindAPI/QueryAPI targets */ +#define EGL_OPENGL_ES_API 0x30A0 +#define EGL_OPENVG_API 0x30A1 +#define EGL_OPENGL_API 0x30A2 + +/* GetCurrentSurface targets */ +#define EGL_DRAW 0x3059 +#define EGL_READ 0x305A + +/* WaitNative engines */ +#define EGL_CORE_NATIVE_ENGINE 0x305B + +/* EGL 1.2 tokens renamed for consistency in EGL 1.3 */ +#define EGL_COLORSPACE EGL_VG_COLORSPACE +#define EGL_ALPHA_FORMAT EGL_VG_ALPHA_FORMAT +#define EGL_COLORSPACE_sRGB EGL_VG_COLORSPACE_sRGB +#define EGL_COLORSPACE_LINEAR EGL_VG_COLORSPACE_LINEAR +#define EGL_ALPHA_FORMAT_NONPRE EGL_VG_ALPHA_FORMAT_NONPRE +#define EGL_ALPHA_FORMAT_PRE EGL_VG_ALPHA_FORMAT_PRE + +/* EGL extensions must request enum blocks from the Khronos + * API Registrar, who maintains the enumerant registry. Submit + * a bug in Khronos Bugzilla against task "Registry". + */ + + + +/* EGL Functions */ + +EGLAPI EGLint EGLAPIENTRY eglGetError(void); + +EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id); +EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor); +EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy); + +EGLAPI const char * EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name); + +EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, + EGLint config_size, EGLint *num_config); +EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, + EGLConfig *configs, EGLint config_size, + EGLint *num_config); +EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, + EGLint attribute, EGLint *value); + +EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, + EGLNativeWindowType win, + const EGLint *attrib_list); +EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list); +EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, + EGLNativePixmapType pixmap, + const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface); +EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, EGLSurface surface, + EGLint attribute, EGLint *value); + +EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api); +EGLAPI EGLenum EGLAPIENTRY eglQueryAPI(void); + +EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient(void); + +EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void); + +EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferFromClientBuffer( + EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, + EGLConfig config, const EGLint *attrib_list); + +EGLAPI EGLBoolean EGLAPIENTRY eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, + EGLint attribute, EGLint value); +EGLAPI EGLBoolean EGLAPIENTRY eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer); +EGLAPI EGLBoolean EGLAPIENTRY eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer); + + +EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval); + + +EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, + EGLContext share_context, + const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx); +EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, + EGLSurface read, EGLContext ctx); + +EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void); +EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw); +EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext(EGLDisplay dpy, EGLContext ctx, + EGLint attribute, EGLint *value); + +EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL(void); +EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine); +EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface); +EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, + EGLNativePixmapType target); + +/* This is a generic function pointer type, whose name indicates it must + * be cast to the proper type *and calling convention* before use. + */ +typedef void (*__eglMustCastToProperFunctionPointerType)(void); + +/* Now, define eglGetProcAddress using the generic function ptr. type */ +EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY + eglGetProcAddress(const char *procname); + +#ifdef __cplusplus +} +#endif + +#endif /* __egl_h_ */ diff --git a/opencl/khronos/headers/EGL/eglext.h b/opencl/khronos/headers/EGL/eglext.h new file mode 100644 index 0000000000..2317b0cf45 --- /dev/null +++ b/opencl/khronos/headers/EGL/eglext.h @@ -0,0 +1,645 @@ +#ifndef __eglext_h_ +#define __eglext_h_ 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2013 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ +/* +** This header is generated from the Khronos OpenGL / OpenGL ES XML +** API Registry. The current version of the Registry, generator scripts +** used to make the header, and the header can be found at +** http://www.opengl.org/registry/ +** +** Khronos $Revision: 24350 $ on $Date: 2013-12-04 12:46:23 -0800 (Wed, 04 Dec 2013) $ +*/ + +#include + +#define EGL_EGLEXT_VERSION 20131204 + +/* Generated C header for: + * API: egl + * Versions considered: .* + * Versions emitted: _nomatch_^ + * Default extensions included: egl + * Additional extensions included: _nomatch_^ + * Extensions removed: _nomatch_^ + */ + +#ifndef EGL_KHR_cl_event +#define EGL_KHR_cl_event 1 +#define EGL_CL_EVENT_HANDLE_KHR 0x309C +#define EGL_SYNC_CL_EVENT_KHR 0x30FE +#define EGL_SYNC_CL_EVENT_COMPLETE_KHR 0x30FF +#endif /* EGL_KHR_cl_event */ + +#ifndef EGL_KHR_cl_event2 +#define EGL_KHR_cl_event2 1 +typedef void *EGLSyncKHR; +typedef intptr_t EGLAttribKHR; +typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNC64KHRPROC) (EGLDisplay dpy, EGLenum type, const EGLAttribKHR *attrib_list); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSync64KHR (EGLDisplay dpy, EGLenum type, const EGLAttribKHR *attrib_list); +#endif +#endif /* EGL_KHR_cl_event2 */ + +#ifndef EGL_KHR_client_get_all_proc_addresses +#define EGL_KHR_client_get_all_proc_addresses 1 +#endif /* EGL_KHR_client_get_all_proc_addresses */ + +#ifndef EGL_KHR_config_attribs +#define EGL_KHR_config_attribs 1 +#define EGL_CONFORMANT_KHR 0x3042 +#define EGL_VG_COLORSPACE_LINEAR_BIT_KHR 0x0020 +#define EGL_VG_ALPHA_FORMAT_PRE_BIT_KHR 0x0040 +#endif /* EGL_KHR_config_attribs */ + +#ifndef EGL_KHR_create_context +#define EGL_KHR_create_context 1 +#define EGL_CONTEXT_MAJOR_VERSION_KHR 0x3098 +#define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB +#define EGL_CONTEXT_FLAGS_KHR 0x30FC +#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30FD +#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR 0x31BD +#define EGL_NO_RESET_NOTIFICATION_KHR 0x31BE +#define EGL_LOSE_CONTEXT_ON_RESET_KHR 0x31BF +#define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001 +#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR 0x00000002 +#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR 0x00000004 +#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR 0x00000001 +#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR 0x00000002 +#define EGL_OPENGL_ES3_BIT_KHR 0x00000040 +#endif /* EGL_KHR_create_context */ + +#ifndef EGL_KHR_fence_sync +#define EGL_KHR_fence_sync 1 +#ifdef KHRONOS_SUPPORT_INT64 +#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR 0x30F0 +#define EGL_SYNC_CONDITION_KHR 0x30F8 +#define EGL_SYNC_FENCE_KHR 0x30F9 +#endif /* KHRONOS_SUPPORT_INT64 */ +#endif /* EGL_KHR_fence_sync */ + +#ifndef EGL_KHR_get_all_proc_addresses +#define EGL_KHR_get_all_proc_addresses 1 +#endif /* EGL_KHR_get_all_proc_addresses */ + +#ifndef EGL_KHR_gl_renderbuffer_image +#define EGL_KHR_gl_renderbuffer_image 1 +#define EGL_GL_RENDERBUFFER_KHR 0x30B9 +#endif /* EGL_KHR_gl_renderbuffer_image */ + +#ifndef EGL_KHR_gl_texture_2D_image +#define EGL_KHR_gl_texture_2D_image 1 +#define EGL_GL_TEXTURE_2D_KHR 0x30B1 +#define EGL_GL_TEXTURE_LEVEL_KHR 0x30BC +#endif /* EGL_KHR_gl_texture_2D_image */ + +#ifndef EGL_KHR_gl_texture_3D_image +#define EGL_KHR_gl_texture_3D_image 1 +#define EGL_GL_TEXTURE_3D_KHR 0x30B2 +#define EGL_GL_TEXTURE_ZOFFSET_KHR 0x30BD +#endif /* EGL_KHR_gl_texture_3D_image */ + +#ifndef EGL_KHR_gl_texture_cubemap_image +#define EGL_KHR_gl_texture_cubemap_image 1 +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR 0x30B3 +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR 0x30B4 +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR 0x30B5 +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR 0x30B6 +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR 0x30B7 +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR 0x30B8 +#endif /* EGL_KHR_gl_texture_cubemap_image */ + +#ifndef EGL_KHR_image +#define EGL_KHR_image 1 +typedef void *EGLImageKHR; +#define EGL_NATIVE_PIXMAP_KHR 0x30B0 +#define EGL_NO_IMAGE_KHR ((EGLImageKHR)0) +typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImageKHR (EGLDisplay dpy, EGLImageKHR image); +#endif +#endif /* EGL_KHR_image */ + +#ifndef EGL_KHR_image_base +#define EGL_KHR_image_base 1 +#define EGL_IMAGE_PRESERVED_KHR 0x30D2 +#endif /* EGL_KHR_image_base */ + +#ifndef EGL_KHR_image_pixmap +#define EGL_KHR_image_pixmap 1 +#endif /* EGL_KHR_image_pixmap */ + +#ifndef EGL_KHR_lock_surface +#define EGL_KHR_lock_surface 1 +#define EGL_READ_SURFACE_BIT_KHR 0x0001 +#define EGL_WRITE_SURFACE_BIT_KHR 0x0002 +#define EGL_LOCK_SURFACE_BIT_KHR 0x0080 +#define EGL_OPTIMAL_FORMAT_BIT_KHR 0x0100 +#define EGL_MATCH_FORMAT_KHR 0x3043 +#define EGL_FORMAT_RGB_565_EXACT_KHR 0x30C0 +#define EGL_FORMAT_RGB_565_KHR 0x30C1 +#define EGL_FORMAT_RGBA_8888_EXACT_KHR 0x30C2 +#define EGL_FORMAT_RGBA_8888_KHR 0x30C3 +#define EGL_MAP_PRESERVE_PIXELS_KHR 0x30C4 +#define EGL_LOCK_USAGE_HINT_KHR 0x30C5 +#define EGL_BITMAP_POINTER_KHR 0x30C6 +#define EGL_BITMAP_PITCH_KHR 0x30C7 +#define EGL_BITMAP_ORIGIN_KHR 0x30C8 +#define EGL_BITMAP_PIXEL_RED_OFFSET_KHR 0x30C9 +#define EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR 0x30CA +#define EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR 0x30CB +#define EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR 0x30CC +#define EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR 0x30CD +#define EGL_LOWER_LEFT_KHR 0x30CE +#define EGL_UPPER_LEFT_KHR 0x30CF +typedef EGLBoolean (EGLAPIENTRYP PFNEGLLOCKSURFACEKHRPROC) (EGLDisplay dpy, EGLSurface surface, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNLOCKSURFACEKHRPROC) (EGLDisplay dpy, EGLSurface surface); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglLockSurfaceKHR (EGLDisplay dpy, EGLSurface surface, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglUnlockSurfaceKHR (EGLDisplay dpy, EGLSurface surface); +#endif +#endif /* EGL_KHR_lock_surface */ + +#ifndef EGL_KHR_lock_surface2 +#define EGL_KHR_lock_surface2 1 +#define EGL_BITMAP_PIXEL_SIZE_KHR 0x3110 +#endif /* EGL_KHR_lock_surface2 */ + +#ifndef EGL_KHR_lock_surface3 +#define EGL_KHR_lock_surface3 1 +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSURFACE64KHRPROC) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLAttribKHR *value); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface64KHR (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLAttribKHR *value); +#endif +#endif /* EGL_KHR_lock_surface3 */ + +#ifndef EGL_KHR_reusable_sync +#define EGL_KHR_reusable_sync 1 +typedef khronos_utime_nanoseconds_t EGLTimeKHR; +#ifdef KHRONOS_SUPPORT_INT64 +#define EGL_SYNC_STATUS_KHR 0x30F1 +#define EGL_SIGNALED_KHR 0x30F2 +#define EGL_UNSIGNALED_KHR 0x30F3 +#define EGL_TIMEOUT_EXPIRED_KHR 0x30F5 +#define EGL_CONDITION_SATISFIED_KHR 0x30F6 +#define EGL_SYNC_TYPE_KHR 0x30F7 +#define EGL_SYNC_REUSABLE_KHR 0x30FA +#define EGL_SYNC_FLUSH_COMMANDS_BIT_KHR 0x0001 +#define EGL_FOREVER_KHR 0xFFFFFFFFFFFFFFFFull +#define EGL_NO_SYNC_KHR ((EGLSyncKHR)0) +typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNCKHRPROC) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync); +typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSyncKHR (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncKHR (EGLDisplay dpy, EGLSyncKHR sync); +EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout); +EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); +EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value); +#endif +#endif /* KHRONOS_SUPPORT_INT64 */ +#endif /* EGL_KHR_reusable_sync */ + +#ifndef EGL_KHR_stream +#define EGL_KHR_stream 1 +typedef void *EGLStreamKHR; +typedef khronos_uint64_t EGLuint64KHR; +#ifdef KHRONOS_SUPPORT_INT64 +#define EGL_NO_STREAM_KHR ((EGLStreamKHR)0) +#define EGL_CONSUMER_LATENCY_USEC_KHR 0x3210 +#define EGL_PRODUCER_FRAME_KHR 0x3212 +#define EGL_CONSUMER_FRAME_KHR 0x3213 +#define EGL_STREAM_STATE_KHR 0x3214 +#define EGL_STREAM_STATE_CREATED_KHR 0x3215 +#define EGL_STREAM_STATE_CONNECTING_KHR 0x3216 +#define EGL_STREAM_STATE_EMPTY_KHR 0x3217 +#define EGL_STREAM_STATE_NEW_FRAME_AVAILABLE_KHR 0x3218 +#define EGL_STREAM_STATE_OLD_FRAME_AVAILABLE_KHR 0x3219 +#define EGL_STREAM_STATE_DISCONNECTED_KHR 0x321A +#define EGL_BAD_STREAM_KHR 0x321B +#define EGL_BAD_STATE_KHR 0x321C +typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMKHRPROC) (EGLDisplay dpy, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSTREAMKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMATTRIBKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMU64KHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamKHR (EGLDisplay dpy, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroyStreamKHR (EGLDisplay dpy, EGLStreamKHR stream); +EGLAPI EGLBoolean EGLAPIENTRY eglStreamAttribKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamu64KHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value); +#endif +#endif /* KHRONOS_SUPPORT_INT64 */ +#endif /* EGL_KHR_stream */ + +#ifndef EGL_KHR_stream_consumer_gltexture +#define EGL_KHR_stream_consumer_gltexture 1 +#ifdef EGL_KHR_stream +#define EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR 0x321E +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERGLTEXTUREEXTERNALKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerGLTextureExternalKHR (EGLDisplay dpy, EGLStreamKHR stream); +EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerAcquireKHR (EGLDisplay dpy, EGLStreamKHR stream); +EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerReleaseKHR (EGLDisplay dpy, EGLStreamKHR stream); +#endif +#endif /* EGL_KHR_stream */ +#endif /* EGL_KHR_stream_consumer_gltexture */ + +#ifndef EGL_KHR_stream_cross_process_fd +#define EGL_KHR_stream_cross_process_fd 1 +typedef int EGLNativeFileDescriptorKHR; +#ifdef EGL_KHR_stream +#define EGL_NO_FILE_DESCRIPTOR_KHR ((EGLNativeFileDescriptorKHR)(-1)) +typedef EGLNativeFileDescriptorKHR (EGLAPIENTRYP PFNEGLGETSTREAMFILEDESCRIPTORKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMFROMFILEDESCRIPTORKHRPROC) (EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLNativeFileDescriptorKHR EGLAPIENTRY eglGetStreamFileDescriptorKHR (EGLDisplay dpy, EGLStreamKHR stream); +EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamFromFileDescriptorKHR (EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor); +#endif +#endif /* EGL_KHR_stream */ +#endif /* EGL_KHR_stream_cross_process_fd */ + +#ifndef EGL_KHR_stream_fifo +#define EGL_KHR_stream_fifo 1 +#ifdef EGL_KHR_stream +#define EGL_STREAM_FIFO_LENGTH_KHR 0x31FC +#define EGL_STREAM_TIME_NOW_KHR 0x31FD +#define EGL_STREAM_TIME_CONSUMER_KHR 0x31FE +#define EGL_STREAM_TIME_PRODUCER_KHR 0x31FF +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMTIMEKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamTimeKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value); +#endif +#endif /* EGL_KHR_stream */ +#endif /* EGL_KHR_stream_fifo */ + +#ifndef EGL_KHR_stream_producer_aldatalocator +#define EGL_KHR_stream_producer_aldatalocator 1 +#ifdef EGL_KHR_stream +#endif /* EGL_KHR_stream */ +#endif /* EGL_KHR_stream_producer_aldatalocator */ + +#ifndef EGL_KHR_stream_producer_eglsurface +#define EGL_KHR_stream_producer_eglsurface 1 +#ifdef EGL_KHR_stream +#define EGL_STREAM_BIT_KHR 0x0800 +typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC) (EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSurface EGLAPIENTRY eglCreateStreamProducerSurfaceKHR (EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list); +#endif +#endif /* EGL_KHR_stream */ +#endif /* EGL_KHR_stream_producer_eglsurface */ + +#ifndef EGL_KHR_surfaceless_context +#define EGL_KHR_surfaceless_context 1 +#endif /* EGL_KHR_surfaceless_context */ + +#ifndef EGL_KHR_vg_parent_image +#define EGL_KHR_vg_parent_image 1 +#define EGL_VG_PARENT_IMAGE_KHR 0x30BA +#endif /* EGL_KHR_vg_parent_image */ + +#ifndef EGL_KHR_wait_sync +#define EGL_KHR_wait_sync 1 +typedef EGLint (EGLAPIENTRYP PFNEGLWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLint EGLAPIENTRY eglWaitSyncKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags); +#endif +#endif /* EGL_KHR_wait_sync */ + +#ifndef EGL_ANDROID_blob_cache +#define EGL_ANDROID_blob_cache 1 +typedef khronos_ssize_t EGLsizeiANDROID; +typedef void (*EGLSetBlobFuncANDROID) (const void *key, EGLsizeiANDROID keySize, const void *value, EGLsizeiANDROID valueSize); +typedef EGLsizeiANDROID (*EGLGetBlobFuncANDROID) (const void *key, EGLsizeiANDROID keySize, void *value, EGLsizeiANDROID valueSize); +typedef void (EGLAPIENTRYP PFNEGLSETBLOBCACHEFUNCSANDROIDPROC) (EGLDisplay dpy, EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI void EGLAPIENTRY eglSetBlobCacheFuncsANDROID (EGLDisplay dpy, EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get); +#endif +#endif /* EGL_ANDROID_blob_cache */ + +#ifndef EGL_ANDROID_framebuffer_target +#define EGL_ANDROID_framebuffer_target 1 +#define EGL_FRAMEBUFFER_TARGET_ANDROID 0x3147 +#endif /* EGL_ANDROID_framebuffer_target */ + +#ifndef EGL_ANDROID_image_native_buffer +#define EGL_ANDROID_image_native_buffer 1 +#define EGL_NATIVE_BUFFER_ANDROID 0x3140 +#endif /* EGL_ANDROID_image_native_buffer */ + +#ifndef EGL_ANDROID_native_fence_sync +#define EGL_ANDROID_native_fence_sync 1 +#define EGL_SYNC_NATIVE_FENCE_ANDROID 0x3144 +#define EGL_SYNC_NATIVE_FENCE_FD_ANDROID 0x3145 +#define EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID 0x3146 +#define EGL_NO_NATIVE_FENCE_FD_ANDROID -1 +typedef EGLint (EGLAPIENTRYP PFNEGLDUPNATIVEFENCEFDANDROIDPROC) (EGLDisplay dpy, EGLSyncKHR sync); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLint EGLAPIENTRY eglDupNativeFenceFDANDROID (EGLDisplay dpy, EGLSyncKHR sync); +#endif +#endif /* EGL_ANDROID_native_fence_sync */ + +#ifndef EGL_ANDROID_recordable +#define EGL_ANDROID_recordable 1 +#define EGL_RECORDABLE_ANDROID 0x3142 +#endif /* EGL_ANDROID_recordable */ + +#ifndef EGL_ANGLE_d3d_share_handle_client_buffer +#define EGL_ANGLE_d3d_share_handle_client_buffer 1 +#define EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE 0x3200 +#endif /* EGL_ANGLE_d3d_share_handle_client_buffer */ + +#ifndef EGL_ANGLE_query_surface_pointer +#define EGL_ANGLE_query_surface_pointer 1 +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSURFACEPOINTERANGLEPROC) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurfacePointerANGLE (EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value); +#endif +#endif /* EGL_ANGLE_query_surface_pointer */ + +#ifndef EGL_ANGLE_surface_d3d_texture_2d_share_handle +#define EGL_ANGLE_surface_d3d_texture_2d_share_handle 1 +#endif /* EGL_ANGLE_surface_d3d_texture_2d_share_handle */ + +#ifndef EGL_ARM_pixmap_multisample_discard +#define EGL_ARM_pixmap_multisample_discard 1 +#define EGL_DISCARD_SAMPLES_ARM 0x3286 +#endif /* EGL_ARM_pixmap_multisample_discard */ + +#ifndef EGL_EXT_buffer_age +#define EGL_EXT_buffer_age 1 +#define EGL_BUFFER_AGE_EXT 0x313D +#endif /* EGL_EXT_buffer_age */ + +#ifndef EGL_EXT_client_extensions +#define EGL_EXT_client_extensions 1 +#endif /* EGL_EXT_client_extensions */ + +#ifndef EGL_EXT_create_context_robustness +#define EGL_EXT_create_context_robustness 1 +#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT 0x30BF +#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT 0x3138 +#define EGL_NO_RESET_NOTIFICATION_EXT 0x31BE +#define EGL_LOSE_CONTEXT_ON_RESET_EXT 0x31BF +#endif /* EGL_EXT_create_context_robustness */ + +#ifndef EGL_EXT_image_dma_buf_import +#define EGL_EXT_image_dma_buf_import 1 +#define EGL_LINUX_DMA_BUF_EXT 0x3270 +#define EGL_LINUX_DRM_FOURCC_EXT 0x3271 +#define EGL_DMA_BUF_PLANE0_FD_EXT 0x3272 +#define EGL_DMA_BUF_PLANE0_OFFSET_EXT 0x3273 +#define EGL_DMA_BUF_PLANE0_PITCH_EXT 0x3274 +#define EGL_DMA_BUF_PLANE1_FD_EXT 0x3275 +#define EGL_DMA_BUF_PLANE1_OFFSET_EXT 0x3276 +#define EGL_DMA_BUF_PLANE1_PITCH_EXT 0x3277 +#define EGL_DMA_BUF_PLANE2_FD_EXT 0x3278 +#define EGL_DMA_BUF_PLANE2_OFFSET_EXT 0x3279 +#define EGL_DMA_BUF_PLANE2_PITCH_EXT 0x327A +#define EGL_YUV_COLOR_SPACE_HINT_EXT 0x327B +#define EGL_SAMPLE_RANGE_HINT_EXT 0x327C +#define EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT 0x327D +#define EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT 0x327E +#define EGL_ITU_REC601_EXT 0x327F +#define EGL_ITU_REC709_EXT 0x3280 +#define EGL_ITU_REC2020_EXT 0x3281 +#define EGL_YUV_FULL_RANGE_EXT 0x3282 +#define EGL_YUV_NARROW_RANGE_EXT 0x3283 +#define EGL_YUV_CHROMA_SITING_0_EXT 0x3284 +#define EGL_YUV_CHROMA_SITING_0_5_EXT 0x3285 +#endif /* EGL_EXT_image_dma_buf_import */ + +#ifndef EGL_EXT_multiview_window +#define EGL_EXT_multiview_window 1 +#define EGL_MULTIVIEW_VIEW_COUNT_EXT 0x3134 +#endif /* EGL_EXT_multiview_window */ + +#ifndef EGL_EXT_platform_base +#define EGL_EXT_platform_base 1 +typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform, void *native_display, const EGLint *attrib_list); +typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list); +typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMPIXMAPSURFACEEXTPROC) (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplayEXT (EGLenum platform, void *native_display, const EGLint *attrib_list); +EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurfaceEXT (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list); +EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurfaceEXT (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list); +#endif +#endif /* EGL_EXT_platform_base */ + +#ifndef EGL_EXT_platform_wayland +#define EGL_EXT_platform_wayland 1 +#define EGL_PLATFORM_WAYLAND_EXT 0x31D8 +#endif /* EGL_EXT_platform_wayland */ + +#ifndef EGL_EXT_platform_x11 +#define EGL_EXT_platform_x11 1 +#define EGL_PLATFORM_X11_EXT 0x31D5 +#define EGL_PLATFORM_X11_SCREEN_EXT 0x31D6 +#endif /* EGL_EXT_platform_x11 */ + +#ifndef EGL_EXT_swap_buffers_with_damage +#define EGL_EXT_swap_buffers_with_damage 1 +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC) (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersWithDamageEXT (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects); +#endif +#endif /* EGL_EXT_swap_buffers_with_damage */ + +#ifndef EGL_HI_clientpixmap +#define EGL_HI_clientpixmap 1 +struct EGLClientPixmapHI { + void *pData; + EGLint iWidth; + EGLint iHeight; + EGLint iStride; +}; +#define EGL_CLIENT_PIXMAP_POINTER_HI 0x8F74 +typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPIXMAPSURFACEHIPROC) (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI *pixmap); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurfaceHI (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI *pixmap); +#endif +#endif /* EGL_HI_clientpixmap */ + +#ifndef EGL_HI_colorformats +#define EGL_HI_colorformats 1 +#define EGL_COLOR_FORMAT_HI 0x8F70 +#define EGL_COLOR_RGB_HI 0x8F71 +#define EGL_COLOR_RGBA_HI 0x8F72 +#define EGL_COLOR_ARGB_HI 0x8F73 +#endif /* EGL_HI_colorformats */ + +#ifndef EGL_IMG_context_priority +#define EGL_IMG_context_priority 1 +#define EGL_CONTEXT_PRIORITY_LEVEL_IMG 0x3100 +#define EGL_CONTEXT_PRIORITY_HIGH_IMG 0x3101 +#define EGL_CONTEXT_PRIORITY_MEDIUM_IMG 0x3102 +#define EGL_CONTEXT_PRIORITY_LOW_IMG 0x3103 +#endif /* EGL_IMG_context_priority */ + +#ifndef EGL_MESA_drm_image +#define EGL_MESA_drm_image 1 +#define EGL_DRM_BUFFER_FORMAT_MESA 0x31D0 +#define EGL_DRM_BUFFER_USE_MESA 0x31D1 +#define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA 0x31D2 +#define EGL_DRM_BUFFER_MESA 0x31D3 +#define EGL_DRM_BUFFER_STRIDE_MESA 0x31D4 +#define EGL_DRM_BUFFER_USE_SCANOUT_MESA 0x00000001 +#define EGL_DRM_BUFFER_USE_SHARE_MESA 0x00000002 +typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEDRMIMAGEMESAPROC) (EGLDisplay dpy, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLImageKHR EGLAPIENTRY eglCreateDRMImageMESA (EGLDisplay dpy, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglExportDRMImageMESA (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride); +#endif +#endif /* EGL_MESA_drm_image */ + +#ifndef EGL_MESA_platform_gbm +#define EGL_MESA_platform_gbm 1 +#define EGL_PLATFORM_GBM_MESA 0x31D7 +#endif /* EGL_MESA_platform_gbm */ + +#ifndef EGL_NV_3dvision_surface +#define EGL_NV_3dvision_surface 1 +#define EGL_AUTO_STEREO_NV 0x3136 +#endif /* EGL_NV_3dvision_surface */ + +#ifndef EGL_NV_coverage_sample +#define EGL_NV_coverage_sample 1 +#define EGL_COVERAGE_BUFFERS_NV 0x30E0 +#define EGL_COVERAGE_SAMPLES_NV 0x30E1 +#endif /* EGL_NV_coverage_sample */ + +#ifndef EGL_NV_coverage_sample_resolve +#define EGL_NV_coverage_sample_resolve 1 +#define EGL_COVERAGE_SAMPLE_RESOLVE_NV 0x3131 +#define EGL_COVERAGE_SAMPLE_RESOLVE_DEFAULT_NV 0x3132 +#define EGL_COVERAGE_SAMPLE_RESOLVE_NONE_NV 0x3133 +#endif /* EGL_NV_coverage_sample_resolve */ + +#ifndef EGL_NV_depth_nonlinear +#define EGL_NV_depth_nonlinear 1 +#define EGL_DEPTH_ENCODING_NV 0x30E2 +#define EGL_DEPTH_ENCODING_NONE_NV 0 +#define EGL_DEPTH_ENCODING_NONLINEAR_NV 0x30E3 +#endif /* EGL_NV_depth_nonlinear */ + +#ifndef EGL_NV_native_query +#define EGL_NV_native_query 1 +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEDISPLAYNVPROC) (EGLDisplay dpy, EGLNativeDisplayType *display_id); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEWINDOWNVPROC) (EGLDisplay dpy, EGLSurface surf, EGLNativeWindowType *window); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEPIXMAPNVPROC) (EGLDisplay dpy, EGLSurface surf, EGLNativePixmapType *pixmap); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativeDisplayNV (EGLDisplay dpy, EGLNativeDisplayType *display_id); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativeWindowNV (EGLDisplay dpy, EGLSurface surf, EGLNativeWindowType *window); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativePixmapNV (EGLDisplay dpy, EGLSurface surf, EGLNativePixmapType *pixmap); +#endif +#endif /* EGL_NV_native_query */ + +#ifndef EGL_NV_post_convert_rounding +#define EGL_NV_post_convert_rounding 1 +#endif /* EGL_NV_post_convert_rounding */ + +#ifndef EGL_NV_post_sub_buffer +#define EGL_NV_post_sub_buffer 1 +#define EGL_POST_SUB_BUFFER_SUPPORTED_NV 0x30BE +typedef EGLBoolean (EGLAPIENTRYP PFNEGLPOSTSUBBUFFERNVPROC) (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglPostSubBufferNV (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height); +#endif +#endif /* EGL_NV_post_sub_buffer */ + +#ifndef EGL_NV_stream_sync +#define EGL_NV_stream_sync 1 +#define EGL_SYNC_NEW_FRAME_NV 0x321F +typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESTREAMSYNCNVPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum type, const EGLint *attrib_list); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateStreamSyncNV (EGLDisplay dpy, EGLStreamKHR stream, EGLenum type, const EGLint *attrib_list); +#endif +#endif /* EGL_NV_stream_sync */ + +#ifndef EGL_NV_sync +#define EGL_NV_sync 1 +typedef void *EGLSyncNV; +typedef khronos_utime_nanoseconds_t EGLTimeNV; +#ifdef KHRONOS_SUPPORT_INT64 +#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_NV 0x30E6 +#define EGL_SYNC_STATUS_NV 0x30E7 +#define EGL_SIGNALED_NV 0x30E8 +#define EGL_UNSIGNALED_NV 0x30E9 +#define EGL_SYNC_FLUSH_COMMANDS_BIT_NV 0x0001 +#define EGL_FOREVER_NV 0xFFFFFFFFFFFFFFFFull +#define EGL_ALREADY_SIGNALED_NV 0x30EA +#define EGL_TIMEOUT_EXPIRED_NV 0x30EB +#define EGL_CONDITION_SATISFIED_NV 0x30EC +#define EGL_SYNC_TYPE_NV 0x30ED +#define EGL_SYNC_CONDITION_NV 0x30EE +#define EGL_SYNC_FENCE_NV 0x30EF +#define EGL_NO_SYNC_NV ((EGLSyncNV)0) +typedef EGLSyncNV (EGLAPIENTRYP PFNEGLCREATEFENCESYNCNVPROC) (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCNVPROC) (EGLSyncNV sync); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLFENCENVPROC) (EGLSyncNV sync); +typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCNVPROC) (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCNVPROC) (EGLSyncNV sync, EGLenum mode); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBNVPROC) (EGLSyncNV sync, EGLint attribute, EGLint *value); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSyncNV EGLAPIENTRY eglCreateFenceSyncNV (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncNV (EGLSyncNV sync); +EGLAPI EGLBoolean EGLAPIENTRY eglFenceNV (EGLSyncNV sync); +EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncNV (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout); +EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncNV (EGLSyncNV sync, EGLenum mode); +EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribNV (EGLSyncNV sync, EGLint attribute, EGLint *value); +#endif +#endif /* KHRONOS_SUPPORT_INT64 */ +#endif /* EGL_NV_sync */ + +#ifndef EGL_NV_system_time +#define EGL_NV_system_time 1 +typedef khronos_utime_nanoseconds_t EGLuint64NV; +#ifdef KHRONOS_SUPPORT_INT64 +typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC) (void); +typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMENVPROC) (void); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeFrequencyNV (void); +EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeNV (void); +#endif +#endif /* KHRONOS_SUPPORT_INT64 */ +#endif /* EGL_NV_system_time */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencl/khronos/headers/EGL/eglplatform.h b/opencl/khronos/headers/EGL/eglplatform.h new file mode 100644 index 0000000000..3ab8844f09 --- /dev/null +++ b/opencl/khronos/headers/EGL/eglplatform.h @@ -0,0 +1,125 @@ +#ifndef __eglplatform_h_ +#define __eglplatform_h_ + +/* +** Copyright (c) 2007-2013 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Platform-specific types and definitions for egl.h + * $Revision: 23432 $ on $Date: 2013-10-09 00:57:24 -0700 (Wed, 09 Oct 2013) $ + * + * Adopters may modify khrplatform.h and this file to suit their platform. + * You are encouraged to submit all modifications to the Khronos group so that + * they can be included in future versions of this file. Please submit changes + * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) + * by filing a bug against product "EGL" component "Registry". + */ + +#include + +/* Macros used in EGL function prototype declarations. + * + * EGL functions should be prototyped as: + * + * EGLAPI return-type EGLAPIENTRY eglFunction(arguments); + * typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments); + * + * KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h + */ + +#ifndef EGLAPI +#define EGLAPI KHRONOS_APICALL +#endif + +#ifndef EGLAPIENTRY +#define EGLAPIENTRY KHRONOS_APIENTRY +#endif +#define EGLAPIENTRYP EGLAPIENTRY* + +/* The types NativeDisplayType, NativeWindowType, and NativePixmapType + * are aliases of window-system-dependent types, such as X Display * or + * Windows Device Context. They must be defined in platform-specific + * code below. The EGL-prefixed versions of Native*Type are the same + * types, renamed in EGL 1.3 so all types in the API start with "EGL". + * + * Khronos STRONGLY RECOMMENDS that you use the default definitions + * provided below, since these changes affect both binary and source + * portability of applications using EGL running on different EGL + * implementations. + */ + +#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */ +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#include + +typedef HDC EGLNativeDisplayType; +typedef HBITMAP EGLNativePixmapType; +typedef HWND EGLNativeWindowType; + +#elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */ + +typedef int EGLNativeDisplayType; +typedef void *EGLNativeWindowType; +typedef void *EGLNativePixmapType; + +#elif defined(__ANDROID__) || defined(ANDROID) + +#include + +struct egl_native_pixmap_t; + +typedef struct ANativeWindow* EGLNativeWindowType; +typedef struct egl_native_pixmap_t* EGLNativePixmapType; +typedef void* EGLNativeDisplayType; + +#elif defined(__unix__) + +/* X11 (tentative) */ +#include +#include + +typedef Display *EGLNativeDisplayType; +typedef Pixmap EGLNativePixmapType; +typedef Window EGLNativeWindowType; + +#else +#error "Platform not recognized" +#endif + +/* EGL 1.2 types, renamed for consistency in EGL 1.3 */ +typedef EGLNativeDisplayType NativeDisplayType; +typedef EGLNativePixmapType NativePixmapType; +typedef EGLNativeWindowType NativeWindowType; + + +/* Define EGLint. This must be a signed integral type large enough to contain + * all legal attribute names and values passed into and out of EGL, whether + * their type is boolean, bitmask, enumerant (symbolic constant), integer, + * handle, or other. While in general a 32-bit integer will suffice, if + * handles are 64 bit types, then EGLint should be defined as a signed 64-bit + * integer type. + */ +typedef khronos_int32_t EGLint; + +#endif /* __eglplatform_h */ diff --git a/opencl/khronos/headers/GL/glext.h b/opencl/khronos/headers/GL/glext.h new file mode 100644 index 0000000000..c09e23b29b --- /dev/null +++ b/opencl/khronos/headers/GL/glext.h @@ -0,0 +1,9253 @@ +#ifndef __glext_h_ +#define __glext_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2009 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Header file version number, required by OpenGL ABI for Linux */ +/* glext.h last updated $Date: 2009-08-03 02:13:51 -0700 (Mon, 03 Aug 2009) $ */ +/* Current version at http://www.opengl.org/registry/ */ +#define GL_GLEXT_VERSION 54 + +/* Function declaration macros - to move into glplatform.h */ + +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI +#define GLAPI extern +#endif + +/*************************************************************/ + +#ifndef GL_VERSION_1_2 +#define GL_UNSIGNED_BYTE_3_3_2 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GL_TEXTURE_BINDING_3D 0x806A +#define GL_PACK_SKIP_IMAGES 0x806B +#define GL_PACK_IMAGE_HEIGHT 0x806C +#define GL_UNPACK_SKIP_IMAGES 0x806D +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_TEXTURE_3D 0x806F +#define GL_PROXY_TEXTURE_3D 0x8070 +#define GL_TEXTURE_DEPTH 0x8071 +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE 0x8073 +#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_BGR 0x80E0 +#define GL_BGRA 0x80E1 +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_BASE_LEVEL 0x813C +#define GL_TEXTURE_MAX_LEVEL 0x813D +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#endif + +#ifndef GL_VERSION_1_2_DEPRECATED +#define GL_RESCALE_NORMAL 0x803A +#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 +#define GL_SINGLE_COLOR 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR 0x81FA +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#endif + +#ifndef GL_ARB_imaging +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_BLEND_COLOR 0x8005 +#define GL_FUNC_ADD 0x8006 +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +#define GL_BLEND_EQUATION 0x8009 +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B +#endif + +#ifndef GL_ARB_imaging_DEPRECATED +#define GL_CONVOLUTION_1D 0x8010 +#define GL_CONVOLUTION_2D 0x8011 +#define GL_SEPARABLE_2D 0x8012 +#define GL_CONVOLUTION_BORDER_MODE 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS 0x8015 +#define GL_REDUCE 0x8016 +#define GL_CONVOLUTION_FORMAT 0x8017 +#define GL_CONVOLUTION_WIDTH 0x8018 +#define GL_CONVOLUTION_HEIGHT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023 +#define GL_HISTOGRAM 0x8024 +#define GL_PROXY_HISTOGRAM 0x8025 +#define GL_HISTOGRAM_WIDTH 0x8026 +#define GL_HISTOGRAM_FORMAT 0x8027 +#define GL_HISTOGRAM_RED_SIZE 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C +#define GL_HISTOGRAM_SINK 0x802D +#define GL_MINMAX 0x802E +#define GL_MINMAX_FORMAT 0x802F +#define GL_MINMAX_SINK 0x8030 +#define GL_TABLE_TOO_LARGE 0x8031 +#define GL_COLOR_MATRIX 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB +#define GL_COLOR_TABLE 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2 +#define GL_PROXY_COLOR_TABLE 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5 +#define GL_COLOR_TABLE_SCALE 0x80D6 +#define GL_COLOR_TABLE_BIAS 0x80D7 +#define GL_COLOR_TABLE_FORMAT 0x80D8 +#define GL_COLOR_TABLE_WIDTH 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF +#define GL_CONSTANT_BORDER 0x8151 +#define GL_REPLICATE_BORDER 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR 0x8154 +#endif + +#ifndef GL_VERSION_1_3 +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C +#define GL_COMPRESSED_RGB 0x84ED +#define GL_COMPRESSED_RGBA 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 +#define GL_TEXTURE_COMPRESSED 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 +#define GL_CLAMP_TO_BORDER 0x812D +#endif + +#ifndef GL_VERSION_1_3_DEPRECATED +#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 +#define GL_MAX_TEXTURE_UNITS 0x84E2 +#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6 +#define GL_MULTISAMPLE_BIT 0x20000000 +#define GL_NORMAL_MAP 0x8511 +#define GL_REFLECTION_MAP 0x8512 +#define GL_COMPRESSED_ALPHA 0x84E9 +#define GL_COMPRESSED_LUMINANCE 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB +#define GL_COMPRESSED_INTENSITY 0x84EC +#define GL_COMBINE 0x8570 +#define GL_COMBINE_RGB 0x8571 +#define GL_COMBINE_ALPHA 0x8572 +#define GL_SOURCE0_RGB 0x8580 +#define GL_SOURCE1_RGB 0x8581 +#define GL_SOURCE2_RGB 0x8582 +#define GL_SOURCE0_ALPHA 0x8588 +#define GL_SOURCE1_ALPHA 0x8589 +#define GL_SOURCE2_ALPHA 0x858A +#define GL_OPERAND0_RGB 0x8590 +#define GL_OPERAND1_RGB 0x8591 +#define GL_OPERAND2_RGB 0x8592 +#define GL_OPERAND0_ALPHA 0x8598 +#define GL_OPERAND1_ALPHA 0x8599 +#define GL_OPERAND2_ALPHA 0x859A +#define GL_RGB_SCALE 0x8573 +#define GL_ADD_SIGNED 0x8574 +#define GL_INTERPOLATE 0x8575 +#define GL_SUBTRACT 0x84E7 +#define GL_CONSTANT 0x8576 +#define GL_PRIMARY_COLOR 0x8577 +#define GL_PREVIOUS 0x8578 +#define GL_DOT3_RGB 0x86AE +#define GL_DOT3_RGBA 0x86AF +#endif + +#ifndef GL_VERSION_1_4 +#define GL_BLEND_DST_RGB 0x80C8 +#define GL_BLEND_SRC_RGB 0x80C9 +#define GL_BLEND_DST_ALPHA 0x80CA +#define GL_BLEND_SRC_ALPHA 0x80CB +#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 +#define GL_DEPTH_COMPONENT16 0x81A5 +#define GL_DEPTH_COMPONENT24 0x81A6 +#define GL_DEPTH_COMPONENT32 0x81A7 +#define GL_MIRRORED_REPEAT 0x8370 +#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD +#define GL_TEXTURE_LOD_BIAS 0x8501 +#define GL_INCR_WRAP 0x8507 +#define GL_DECR_WRAP 0x8508 +#define GL_TEXTURE_DEPTH_SIZE 0x884A +#define GL_TEXTURE_COMPARE_MODE 0x884C +#define GL_TEXTURE_COMPARE_FUNC 0x884D +#endif + +#ifndef GL_VERSION_1_4_DEPRECATED +#define GL_POINT_SIZE_MIN 0x8126 +#define GL_POINT_SIZE_MAX 0x8127 +#define GL_POINT_DISTANCE_ATTENUATION 0x8129 +#define GL_GENERATE_MIPMAP 0x8191 +#define GL_GENERATE_MIPMAP_HINT 0x8192 +#define GL_FOG_COORDINATE_SOURCE 0x8450 +#define GL_FOG_COORDINATE 0x8451 +#define GL_FRAGMENT_DEPTH 0x8452 +#define GL_CURRENT_FOG_COORDINATE 0x8453 +#define GL_FOG_COORDINATE_ARRAY_TYPE 0x8454 +#define GL_FOG_COORDINATE_ARRAY_STRIDE 0x8455 +#define GL_FOG_COORDINATE_ARRAY_POINTER 0x8456 +#define GL_FOG_COORDINATE_ARRAY 0x8457 +#define GL_COLOR_SUM 0x8458 +#define GL_CURRENT_SECONDARY_COLOR 0x8459 +#define GL_SECONDARY_COLOR_ARRAY_SIZE 0x845A +#define GL_SECONDARY_COLOR_ARRAY_TYPE 0x845B +#define GL_SECONDARY_COLOR_ARRAY_STRIDE 0x845C +#define GL_SECONDARY_COLOR_ARRAY_POINTER 0x845D +#define GL_SECONDARY_COLOR_ARRAY 0x845E +#define GL_TEXTURE_FILTER_CONTROL 0x8500 +#define GL_DEPTH_TEXTURE_MODE 0x884B +#define GL_COMPARE_R_TO_TEXTURE 0x884E +#endif + +#ifndef GL_VERSION_1_5 +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 +#define GL_QUERY_COUNTER_BITS 0x8864 +#define GL_CURRENT_QUERY 0x8865 +#define GL_QUERY_RESULT 0x8866 +#define GL_QUERY_RESULT_AVAILABLE 0x8867 +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F +#define GL_READ_ONLY 0x88B8 +#define GL_WRITE_ONLY 0x88B9 +#define GL_READ_WRITE 0x88BA +#define GL_BUFFER_ACCESS 0x88BB +#define GL_BUFFER_MAPPED 0x88BC +#define GL_BUFFER_MAP_POINTER 0x88BD +#define GL_STREAM_DRAW 0x88E0 +#define GL_STREAM_READ 0x88E1 +#define GL_STREAM_COPY 0x88E2 +#define GL_STATIC_DRAW 0x88E4 +#define GL_STATIC_READ 0x88E5 +#define GL_STATIC_COPY 0x88E6 +#define GL_DYNAMIC_DRAW 0x88E8 +#define GL_DYNAMIC_READ 0x88E9 +#define GL_DYNAMIC_COPY 0x88EA +#define GL_SAMPLES_PASSED 0x8914 +#endif + +#ifndef GL_VERSION_1_5_DEPRECATED +#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E +#define GL_FOG_COORD_SRC 0x8450 +#define GL_FOG_COORD 0x8451 +#define GL_CURRENT_FOG_COORD 0x8453 +#define GL_FOG_COORD_ARRAY_TYPE 0x8454 +#define GL_FOG_COORD_ARRAY_STRIDE 0x8455 +#define GL_FOG_COORD_ARRAY_POINTER 0x8456 +#define GL_FOG_COORD_ARRAY 0x8457 +#define GL_FOG_COORD_ARRAY_BUFFER_BINDING 0x889D +#define GL_SRC0_RGB 0x8580 +#define GL_SRC1_RGB 0x8581 +#define GL_SRC2_RGB 0x8582 +#define GL_SRC0_ALPHA 0x8588 +#define GL_SRC1_ALPHA 0x8589 +#define GL_SRC2_ALPHA 0x858A +#endif + +#ifndef GL_VERSION_2_0 +#define GL_BLEND_EQUATION_RGB 0x8009 +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_CURRENT_VERTEX_ATTRIB 0x8626 +#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 +#define GL_STENCIL_BACK_FUNC 0x8800 +#define GL_STENCIL_BACK_FAIL 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 +#define GL_MAX_DRAW_BUFFERS 0x8824 +#define GL_DRAW_BUFFER0 0x8825 +#define GL_DRAW_BUFFER1 0x8826 +#define GL_DRAW_BUFFER2 0x8827 +#define GL_DRAW_BUFFER3 0x8828 +#define GL_DRAW_BUFFER4 0x8829 +#define GL_DRAW_BUFFER5 0x882A +#define GL_DRAW_BUFFER6 0x882B +#define GL_DRAW_BUFFER7 0x882C +#define GL_DRAW_BUFFER8 0x882D +#define GL_DRAW_BUFFER9 0x882E +#define GL_DRAW_BUFFER10 0x882F +#define GL_DRAW_BUFFER11 0x8830 +#define GL_DRAW_BUFFER12 0x8831 +#define GL_DRAW_BUFFER13 0x8832 +#define GL_DRAW_BUFFER14 0x8833 +#define GL_DRAW_BUFFER15 0x8834 +#define GL_BLEND_EQUATION_ALPHA 0x883D +#define GL_MAX_VERTEX_ATTRIBS 0x8869 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A +#define GL_MAX_VARYING_FLOATS 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#define GL_SHADER_TYPE 0x8B4F +#define GL_FLOAT_VEC2 0x8B50 +#define GL_FLOAT_VEC3 0x8B51 +#define GL_FLOAT_VEC4 0x8B52 +#define GL_INT_VEC2 0x8B53 +#define GL_INT_VEC3 0x8B54 +#define GL_INT_VEC4 0x8B55 +#define GL_BOOL 0x8B56 +#define GL_BOOL_VEC2 0x8B57 +#define GL_BOOL_VEC3 0x8B58 +#define GL_BOOL_VEC4 0x8B59 +#define GL_FLOAT_MAT2 0x8B5A +#define GL_FLOAT_MAT3 0x8B5B +#define GL_FLOAT_MAT4 0x8B5C +#define GL_SAMPLER_1D 0x8B5D +#define GL_SAMPLER_2D 0x8B5E +#define GL_SAMPLER_3D 0x8B5F +#define GL_SAMPLER_CUBE 0x8B60 +#define GL_SAMPLER_1D_SHADOW 0x8B61 +#define GL_SAMPLER_2D_SHADOW 0x8B62 +#define GL_DELETE_STATUS 0x8B80 +#define GL_COMPILE_STATUS 0x8B81 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_ACTIVE_ATTRIBUTES 0x8B89 +#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_CURRENT_PROGRAM 0x8B8D +#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0 +#define GL_LOWER_LEFT 0x8CA1 +#define GL_UPPER_LEFT 0x8CA2 +#define GL_STENCIL_BACK_REF 0x8CA3 +#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 +#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 +#endif + +#ifndef GL_VERSION_2_0_DEPRECATED +#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643 +#define GL_POINT_SPRITE 0x8861 +#define GL_COORD_REPLACE 0x8862 +#define GL_MAX_TEXTURE_COORDS 0x8871 +#endif + +#ifndef GL_VERSION_2_1 +#define GL_PIXEL_PACK_BUFFER 0x88EB +#define GL_PIXEL_UNPACK_BUFFER 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF +#define GL_FLOAT_MAT2x3 0x8B65 +#define GL_FLOAT_MAT2x4 0x8B66 +#define GL_FLOAT_MAT3x2 0x8B67 +#define GL_FLOAT_MAT3x4 0x8B68 +#define GL_FLOAT_MAT4x2 0x8B69 +#define GL_FLOAT_MAT4x3 0x8B6A +#define GL_SRGB 0x8C40 +#define GL_SRGB8 0x8C41 +#define GL_SRGB_ALPHA 0x8C42 +#define GL_SRGB8_ALPHA8 0x8C43 +#define GL_COMPRESSED_SRGB 0x8C48 +#define GL_COMPRESSED_SRGB_ALPHA 0x8C49 +#endif + +#ifndef GL_VERSION_2_1_DEPRECATED +#define GL_CURRENT_RASTER_SECONDARY_COLOR 0x845F +#define GL_SLUMINANCE_ALPHA 0x8C44 +#define GL_SLUMINANCE8_ALPHA8 0x8C45 +#define GL_SLUMINANCE 0x8C46 +#define GL_SLUMINANCE8 0x8C47 +#define GL_COMPRESSED_SLUMINANCE 0x8C4A +#define GL_COMPRESSED_SLUMINANCE_ALPHA 0x8C4B +#endif + +#ifndef GL_VERSION_3_0 +#define GL_COMPARE_REF_TO_TEXTURE 0x884E +#define GL_CLIP_DISTANCE0 0x3000 +#define GL_CLIP_DISTANCE1 0x3001 +#define GL_CLIP_DISTANCE2 0x3002 +#define GL_CLIP_DISTANCE3 0x3003 +#define GL_CLIP_DISTANCE4 0x3004 +#define GL_CLIP_DISTANCE5 0x3005 +#define GL_CLIP_DISTANCE6 0x3006 +#define GL_CLIP_DISTANCE7 0x3007 +#define GL_MAX_CLIP_DISTANCES 0x0D32 +#define GL_MAJOR_VERSION 0x821B +#define GL_MINOR_VERSION 0x821C +#define GL_NUM_EXTENSIONS 0x821D +#define GL_CONTEXT_FLAGS 0x821E +#define GL_DEPTH_BUFFER 0x8223 +#define GL_STENCIL_BUFFER 0x8224 +#define GL_COMPRESSED_RED 0x8225 +#define GL_COMPRESSED_RG 0x8226 +#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x0001 +#define GL_RGBA32F 0x8814 +#define GL_RGB32F 0x8815 +#define GL_RGBA16F 0x881A +#define GL_RGB16F 0x881B +#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD +#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF +#define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904 +#define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905 +#define GL_CLAMP_READ_COLOR 0x891C +#define GL_FIXED_ONLY 0x891D +#define GL_MAX_VARYING_COMPONENTS 0x8B4B +#define GL_TEXTURE_1D_ARRAY 0x8C18 +#define GL_PROXY_TEXTURE_1D_ARRAY 0x8C19 +#define GL_TEXTURE_2D_ARRAY 0x8C1A +#define GL_PROXY_TEXTURE_2D_ARRAY 0x8C1B +#define GL_TEXTURE_BINDING_1D_ARRAY 0x8C1C +#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D +#define GL_R11F_G11F_B10F 0x8C3A +#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B +#define GL_RGB9_E5 0x8C3D +#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E +#define GL_TEXTURE_SHARED_SIZE 0x8C3F +#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76 +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80 +#define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85 +#define GL_PRIMITIVES_GENERATED 0x8C87 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88 +#define GL_RASTERIZER_DISCARD 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B +#define GL_INTERLEAVED_ATTRIBS 0x8C8C +#define GL_SEPARATE_ATTRIBS 0x8C8D +#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F +#define GL_RGBA32UI 0x8D70 +#define GL_RGB32UI 0x8D71 +#define GL_RGBA16UI 0x8D76 +#define GL_RGB16UI 0x8D77 +#define GL_RGBA8UI 0x8D7C +#define GL_RGB8UI 0x8D7D +#define GL_RGBA32I 0x8D82 +#define GL_RGB32I 0x8D83 +#define GL_RGBA16I 0x8D88 +#define GL_RGB16I 0x8D89 +#define GL_RGBA8I 0x8D8E +#define GL_RGB8I 0x8D8F +#define GL_RED_INTEGER 0x8D94 +#define GL_GREEN_INTEGER 0x8D95 +#define GL_BLUE_INTEGER 0x8D96 +#define GL_RGB_INTEGER 0x8D98 +#define GL_RGBA_INTEGER 0x8D99 +#define GL_BGR_INTEGER 0x8D9A +#define GL_BGRA_INTEGER 0x8D9B +#define GL_SAMPLER_1D_ARRAY 0x8DC0 +#define GL_SAMPLER_2D_ARRAY 0x8DC1 +#define GL_SAMPLER_1D_ARRAY_SHADOW 0x8DC3 +#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4 +#define GL_SAMPLER_CUBE_SHADOW 0x8DC5 +#define GL_UNSIGNED_INT_VEC2 0x8DC6 +#define GL_UNSIGNED_INT_VEC3 0x8DC7 +#define GL_UNSIGNED_INT_VEC4 0x8DC8 +#define GL_INT_SAMPLER_1D 0x8DC9 +#define GL_INT_SAMPLER_2D 0x8DCA +#define GL_INT_SAMPLER_3D 0x8DCB +#define GL_INT_SAMPLER_CUBE 0x8DCC +#define GL_INT_SAMPLER_1D_ARRAY 0x8DCE +#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF +#define GL_UNSIGNED_INT_SAMPLER_1D 0x8DD1 +#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2 +#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3 +#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4 +#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY 0x8DD6 +#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7 +#define GL_QUERY_WAIT 0x8E13 +#define GL_QUERY_NO_WAIT 0x8E14 +#define GL_QUERY_BY_REGION_WAIT 0x8E15 +#define GL_QUERY_BY_REGION_NO_WAIT 0x8E16 +#define GL_BUFFER_ACCESS_FLAGS 0x911F +#define GL_BUFFER_MAP_LENGTH 0x9120 +#define GL_BUFFER_MAP_OFFSET 0x9121 +/* Reuse tokens from ARB_depth_buffer_float */ +/* reuse GL_DEPTH_COMPONENT32F */ +/* reuse GL_DEPTH32F_STENCIL8 */ +/* reuse GL_FLOAT_32_UNSIGNED_INT_24_8_REV */ +/* Reuse tokens from ARB_framebuffer_object */ +/* reuse GL_INVALID_FRAMEBUFFER_OPERATION */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE */ +/* reuse GL_FRAMEBUFFER_DEFAULT */ +/* reuse GL_FRAMEBUFFER_UNDEFINED */ +/* reuse GL_DEPTH_STENCIL_ATTACHMENT */ +/* reuse GL_INDEX */ +/* reuse GL_MAX_RENDERBUFFER_SIZE */ +/* reuse GL_DEPTH_STENCIL */ +/* reuse GL_UNSIGNED_INT_24_8 */ +/* reuse GL_DEPTH24_STENCIL8 */ +/* reuse GL_TEXTURE_STENCIL_SIZE */ +/* reuse GL_TEXTURE_RED_TYPE */ +/* reuse GL_TEXTURE_GREEN_TYPE */ +/* reuse GL_TEXTURE_BLUE_TYPE */ +/* reuse GL_TEXTURE_ALPHA_TYPE */ +/* reuse GL_TEXTURE_DEPTH_TYPE */ +/* reuse GL_UNSIGNED_NORMALIZED */ +/* reuse GL_FRAMEBUFFER_BINDING */ +/* reuse GL_DRAW_FRAMEBUFFER_BINDING */ +/* reuse GL_RENDERBUFFER_BINDING */ +/* reuse GL_READ_FRAMEBUFFER */ +/* reuse GL_DRAW_FRAMEBUFFER */ +/* reuse GL_READ_FRAMEBUFFER_BINDING */ +/* reuse GL_RENDERBUFFER_SAMPLES */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ +/* reuse GL_FRAMEBUFFER_COMPLETE */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER */ +/* reuse GL_FRAMEBUFFER_UNSUPPORTED */ +/* reuse GL_MAX_COLOR_ATTACHMENTS */ +/* reuse GL_COLOR_ATTACHMENT0 */ +/* reuse GL_COLOR_ATTACHMENT1 */ +/* reuse GL_COLOR_ATTACHMENT2 */ +/* reuse GL_COLOR_ATTACHMENT3 */ +/* reuse GL_COLOR_ATTACHMENT4 */ +/* reuse GL_COLOR_ATTACHMENT5 */ +/* reuse GL_COLOR_ATTACHMENT6 */ +/* reuse GL_COLOR_ATTACHMENT7 */ +/* reuse GL_COLOR_ATTACHMENT8 */ +/* reuse GL_COLOR_ATTACHMENT9 */ +/* reuse GL_COLOR_ATTACHMENT10 */ +/* reuse GL_COLOR_ATTACHMENT11 */ +/* reuse GL_COLOR_ATTACHMENT12 */ +/* reuse GL_COLOR_ATTACHMENT13 */ +/* reuse GL_COLOR_ATTACHMENT14 */ +/* reuse GL_COLOR_ATTACHMENT15 */ +/* reuse GL_DEPTH_ATTACHMENT */ +/* reuse GL_STENCIL_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER */ +/* reuse GL_RENDERBUFFER */ +/* reuse GL_RENDERBUFFER_WIDTH */ +/* reuse GL_RENDERBUFFER_HEIGHT */ +/* reuse GL_RENDERBUFFER_INTERNAL_FORMAT */ +/* reuse GL_STENCIL_INDEX1 */ +/* reuse GL_STENCIL_INDEX4 */ +/* reuse GL_STENCIL_INDEX8 */ +/* reuse GL_STENCIL_INDEX16 */ +/* reuse GL_RENDERBUFFER_RED_SIZE */ +/* reuse GL_RENDERBUFFER_GREEN_SIZE */ +/* reuse GL_RENDERBUFFER_BLUE_SIZE */ +/* reuse GL_RENDERBUFFER_ALPHA_SIZE */ +/* reuse GL_RENDERBUFFER_DEPTH_SIZE */ +/* reuse GL_RENDERBUFFER_STENCIL_SIZE */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE */ +/* reuse GL_MAX_SAMPLES */ +/* Reuse tokens from ARB_framebuffer_sRGB */ +/* reuse GL_FRAMEBUFFER_SRGB */ +/* Reuse tokens from ARB_half_float_vertex */ +/* reuse GL_HALF_FLOAT */ +/* Reuse tokens from ARB_map_buffer_range */ +/* reuse GL_MAP_READ_BIT */ +/* reuse GL_MAP_WRITE_BIT */ +/* reuse GL_MAP_INVALIDATE_RANGE_BIT */ +/* reuse GL_MAP_INVALIDATE_BUFFER_BIT */ +/* reuse GL_MAP_FLUSH_EXPLICIT_BIT */ +/* reuse GL_MAP_UNSYNCHRONIZED_BIT */ +/* Reuse tokens from ARB_texture_compression_rgtc */ +/* reuse GL_COMPRESSED_RED_RGTC1 */ +/* reuse GL_COMPRESSED_SIGNED_RED_RGTC1 */ +/* reuse GL_COMPRESSED_RG_RGTC2 */ +/* reuse GL_COMPRESSED_SIGNED_RG_RGTC2 */ +/* Reuse tokens from ARB_texture_rg */ +/* reuse GL_RG */ +/* reuse GL_RG_INTEGER */ +/* reuse GL_R8 */ +/* reuse GL_R16 */ +/* reuse GL_RG8 */ +/* reuse GL_RG16 */ +/* reuse GL_R16F */ +/* reuse GL_R32F */ +/* reuse GL_RG16F */ +/* reuse GL_RG32F */ +/* reuse GL_R8I */ +/* reuse GL_R8UI */ +/* reuse GL_R16I */ +/* reuse GL_R16UI */ +/* reuse GL_R32I */ +/* reuse GL_R32UI */ +/* reuse GL_RG8I */ +/* reuse GL_RG8UI */ +/* reuse GL_RG16I */ +/* reuse GL_RG16UI */ +/* reuse GL_RG32I */ +/* reuse GL_RG32UI */ +/* Reuse tokens from ARB_vertex_array_object */ +/* reuse GL_VERTEX_ARRAY_BINDING */ +#endif + +#ifndef GL_VERSION_3_0_DEPRECATED +#define GL_CLAMP_VERTEX_COLOR 0x891A +#define GL_CLAMP_FRAGMENT_COLOR 0x891B +#define GL_ALPHA_INTEGER 0x8D97 +/* Reuse tokens from ARB_framebuffer_object */ +/* reuse GL_TEXTURE_LUMINANCE_TYPE */ +/* reuse GL_TEXTURE_INTENSITY_TYPE */ +#endif + +#ifndef GL_VERSION_3_1 +#define GL_SAMPLER_2D_RECT 0x8B63 +#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64 +#define GL_SAMPLER_BUFFER 0x8DC2 +#define GL_INT_SAMPLER_2D_RECT 0x8DCD +#define GL_INT_SAMPLER_BUFFER 0x8DD0 +#define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8 +#define GL_TEXTURE_BUFFER 0x8C2A +#define GL_MAX_TEXTURE_BUFFER_SIZE 0x8C2B +#define GL_TEXTURE_BINDING_BUFFER 0x8C2C +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING 0x8C2D +#define GL_TEXTURE_BUFFER_FORMAT 0x8C2E +#define GL_TEXTURE_RECTANGLE 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE 0x84F8 +#define GL_RED_SNORM 0x8F90 +#define GL_RG_SNORM 0x8F91 +#define GL_RGB_SNORM 0x8F92 +#define GL_RGBA_SNORM 0x8F93 +#define GL_R8_SNORM 0x8F94 +#define GL_RG8_SNORM 0x8F95 +#define GL_RGB8_SNORM 0x8F96 +#define GL_RGBA8_SNORM 0x8F97 +#define GL_R16_SNORM 0x8F98 +#define GL_RG16_SNORM 0x8F99 +#define GL_RGB16_SNORM 0x8F9A +#define GL_RGBA16_SNORM 0x8F9B +#define GL_SIGNED_NORMALIZED 0x8F9C +#define GL_PRIMITIVE_RESTART 0x8F9D +#define GL_PRIMITIVE_RESTART_INDEX 0x8F9E +/* Reuse tokens from ARB_copy_buffer */ +/* reuse GL_COPY_READ_BUFFER */ +/* reuse GL_COPY_WRITE_BUFFER */ +/* Would reuse tokens from ARB_draw_instanced, but it has none */ +/* Reuse tokens from ARB_uniform_buffer_object */ +/* reuse GL_UNIFORM_BUFFER */ +/* reuse GL_UNIFORM_BUFFER_BINDING */ +/* reuse GL_UNIFORM_BUFFER_START */ +/* reuse GL_UNIFORM_BUFFER_SIZE */ +/* reuse GL_MAX_VERTEX_UNIFORM_BLOCKS */ +/* reuse GL_MAX_FRAGMENT_UNIFORM_BLOCKS */ +/* reuse GL_MAX_COMBINED_UNIFORM_BLOCKS */ +/* reuse GL_MAX_UNIFORM_BUFFER_BINDINGS */ +/* reuse GL_MAX_UNIFORM_BLOCK_SIZE */ +/* reuse GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS */ +/* reuse GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT */ +/* reuse GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH */ +/* reuse GL_ACTIVE_UNIFORM_BLOCKS */ +/* reuse GL_UNIFORM_TYPE */ +/* reuse GL_UNIFORM_SIZE */ +/* reuse GL_UNIFORM_NAME_LENGTH */ +/* reuse GL_UNIFORM_BLOCK_INDEX */ +/* reuse GL_UNIFORM_OFFSET */ +/* reuse GL_UNIFORM_ARRAY_STRIDE */ +/* reuse GL_UNIFORM_MATRIX_STRIDE */ +/* reuse GL_UNIFORM_IS_ROW_MAJOR */ +/* reuse GL_UNIFORM_BLOCK_BINDING */ +/* reuse GL_UNIFORM_BLOCK_DATA_SIZE */ +/* reuse GL_UNIFORM_BLOCK_NAME_LENGTH */ +/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS */ +/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER */ +/* reuse GL_INVALID_INDEX */ +#endif + +#ifndef GL_VERSION_3_2 +#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001 +#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 +#define GL_LINES_ADJACENCY 0x000A +#define GL_LINE_STRIP_ADJACENCY 0x000B +#define GL_TRIANGLES_ADJACENCY 0x000C +#define GL_TRIANGLE_STRIP_ADJACENCY 0x000D +#define GL_PROGRAM_POINT_SIZE 0x8642 +#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS 0x8C29 +#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED 0x8DA7 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS 0x8DA8 +#define GL_GEOMETRY_SHADER 0x8DD9 +#define GL_GEOMETRY_VERTICES_OUT 0x8916 +#define GL_GEOMETRY_INPUT_TYPE 0x8917 +#define GL_GEOMETRY_OUTPUT_TYPE 0x8918 +#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS 0x8DDF +#define GL_MAX_GEOMETRY_OUTPUT_VERTICES 0x8DE0 +#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS 0x8DE1 +#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122 +#define GL_MAX_GEOMETRY_INPUT_COMPONENTS 0x9123 +#define GL_MAX_GEOMETRY_OUTPUT_COMPONENTS 0x9124 +#define GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125 +#define GL_CONTEXT_PROFILE_MASK 0x9126 +/* reuse GL_MAX_VARYING_COMPONENTS */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ +/* Reuse tokens from ARB_depth_clamp */ +/* reuse GL_DEPTH_CLAMP */ +/* Would reuse tokens from ARB_draw_elements_base_vertex, but it has none */ +/* Would reuse tokens from ARB_fragment_coord_conventions, but it has none */ +/* Reuse tokens from ARB_provoking_vertex */ +/* reuse GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION */ +/* reuse GL_FIRST_VERTEX_CONVENTION */ +/* reuse GL_LAST_VERTEX_CONVENTION */ +/* reuse GL_PROVOKING_VERTEX */ +/* Reuse tokens from ARB_seamless_cube_map */ +/* reuse GL_TEXTURE_CUBE_MAP_SEAMLESS */ +/* Reuse tokens from ARB_sync */ +/* reuse GL_MAX_SERVER_WAIT_TIMEOUT */ +/* reuse GL_OBJECT_TYPE */ +/* reuse GL_SYNC_CONDITION */ +/* reuse GL_SYNC_STATUS */ +/* reuse GL_SYNC_FLAGS */ +/* reuse GL_SYNC_FENCE */ +/* reuse GL_SYNC_GPU_COMMANDS_COMPLETE */ +/* reuse GL_UNSIGNALED */ +/* reuse GL_SIGNALED */ +/* reuse GL_ALREADY_SIGNALED */ +/* reuse GL_TIMEOUT_EXPIRED */ +/* reuse GL_CONDITION_SATISFIED */ +/* reuse GL_WAIT_FAILED */ +/* reuse GL_TIMEOUT_IGNORED */ +/* reuse GL_SYNC_FLUSH_COMMANDS_BIT */ +/* reuse GL_TIMEOUT_IGNORED */ +/* Reuse tokens from ARB_texture_multisample */ +/* reuse GL_SAMPLE_POSITION */ +/* reuse GL_SAMPLE_MASK */ +/* reuse GL_SAMPLE_MASK_VALUE */ +/* reuse GL_MAX_SAMPLE_MASK_WORDS */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_SAMPLES */ +/* reuse GL_TEXTURE_FIXED_SAMPLE_LOCATIONS */ +/* reuse GL_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_MAX_COLOR_TEXTURE_SAMPLES */ +/* reuse GL_MAX_DEPTH_TEXTURE_SAMPLES */ +/* reuse GL_MAX_INTEGER_SAMPLES */ +/* Don't need to reuse tokens from ARB_vertex_array_bgra since they're already in 1.2 core */ +#endif + +#ifndef GL_ARB_multitexture +#define GL_TEXTURE0_ARB 0x84C0 +#define GL_TEXTURE1_ARB 0x84C1 +#define GL_TEXTURE2_ARB 0x84C2 +#define GL_TEXTURE3_ARB 0x84C3 +#define GL_TEXTURE4_ARB 0x84C4 +#define GL_TEXTURE5_ARB 0x84C5 +#define GL_TEXTURE6_ARB 0x84C6 +#define GL_TEXTURE7_ARB 0x84C7 +#define GL_TEXTURE8_ARB 0x84C8 +#define GL_TEXTURE9_ARB 0x84C9 +#define GL_TEXTURE10_ARB 0x84CA +#define GL_TEXTURE11_ARB 0x84CB +#define GL_TEXTURE12_ARB 0x84CC +#define GL_TEXTURE13_ARB 0x84CD +#define GL_TEXTURE14_ARB 0x84CE +#define GL_TEXTURE15_ARB 0x84CF +#define GL_TEXTURE16_ARB 0x84D0 +#define GL_TEXTURE17_ARB 0x84D1 +#define GL_TEXTURE18_ARB 0x84D2 +#define GL_TEXTURE19_ARB 0x84D3 +#define GL_TEXTURE20_ARB 0x84D4 +#define GL_TEXTURE21_ARB 0x84D5 +#define GL_TEXTURE22_ARB 0x84D6 +#define GL_TEXTURE23_ARB 0x84D7 +#define GL_TEXTURE24_ARB 0x84D8 +#define GL_TEXTURE25_ARB 0x84D9 +#define GL_TEXTURE26_ARB 0x84DA +#define GL_TEXTURE27_ARB 0x84DB +#define GL_TEXTURE28_ARB 0x84DC +#define GL_TEXTURE29_ARB 0x84DD +#define GL_TEXTURE30_ARB 0x84DE +#define GL_TEXTURE31_ARB 0x84DF +#define GL_ACTIVE_TEXTURE_ARB 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1 +#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 +#endif + +#ifndef GL_ARB_transpose_matrix +#define GL_TRANSPOSE_MODELVIEW_MATRIX_ARB 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX_ARB 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX_ARB 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX_ARB 0x84E6 +#endif + +#ifndef GL_ARB_multisample +#define GL_MULTISAMPLE_ARB 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F +#define GL_SAMPLE_COVERAGE_ARB 0x80A0 +#define GL_SAMPLE_BUFFERS_ARB 0x80A8 +#define GL_SAMPLES_ARB 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB +#define GL_MULTISAMPLE_BIT_ARB 0x20000000 +#endif + +#ifndef GL_ARB_texture_env_add +#endif + +#ifndef GL_ARB_texture_cube_map +#define GL_NORMAL_MAP_ARB 0x8511 +#define GL_REFLECTION_MAP_ARB 0x8512 +#define GL_TEXTURE_CUBE_MAP_ARB 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C +#endif + +#ifndef GL_ARB_texture_compression +#define GL_COMPRESSED_ALPHA_ARB 0x84E9 +#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB +#define GL_COMPRESSED_INTENSITY_ARB 0x84EC +#define GL_COMPRESSED_RGB_ARB 0x84ED +#define GL_COMPRESSED_RGBA_ARB 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0 +#define GL_TEXTURE_COMPRESSED_ARB 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3 +#endif + +#ifndef GL_ARB_texture_border_clamp +#define GL_CLAMP_TO_BORDER_ARB 0x812D +#endif + +#ifndef GL_ARB_point_parameters +#define GL_POINT_SIZE_MIN_ARB 0x8126 +#define GL_POINT_SIZE_MAX_ARB 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_ARB 0x8128 +#define GL_POINT_DISTANCE_ATTENUATION_ARB 0x8129 +#endif + +#ifndef GL_ARB_vertex_blend +#define GL_MAX_VERTEX_UNITS_ARB 0x86A4 +#define GL_ACTIVE_VERTEX_UNITS_ARB 0x86A5 +#define GL_WEIGHT_SUM_UNITY_ARB 0x86A6 +#define GL_VERTEX_BLEND_ARB 0x86A7 +#define GL_CURRENT_WEIGHT_ARB 0x86A8 +#define GL_WEIGHT_ARRAY_TYPE_ARB 0x86A9 +#define GL_WEIGHT_ARRAY_STRIDE_ARB 0x86AA +#define GL_WEIGHT_ARRAY_SIZE_ARB 0x86AB +#define GL_WEIGHT_ARRAY_POINTER_ARB 0x86AC +#define GL_WEIGHT_ARRAY_ARB 0x86AD +#define GL_MODELVIEW0_ARB 0x1700 +#define GL_MODELVIEW1_ARB 0x850A +#define GL_MODELVIEW2_ARB 0x8722 +#define GL_MODELVIEW3_ARB 0x8723 +#define GL_MODELVIEW4_ARB 0x8724 +#define GL_MODELVIEW5_ARB 0x8725 +#define GL_MODELVIEW6_ARB 0x8726 +#define GL_MODELVIEW7_ARB 0x8727 +#define GL_MODELVIEW8_ARB 0x8728 +#define GL_MODELVIEW9_ARB 0x8729 +#define GL_MODELVIEW10_ARB 0x872A +#define GL_MODELVIEW11_ARB 0x872B +#define GL_MODELVIEW12_ARB 0x872C +#define GL_MODELVIEW13_ARB 0x872D +#define GL_MODELVIEW14_ARB 0x872E +#define GL_MODELVIEW15_ARB 0x872F +#define GL_MODELVIEW16_ARB 0x8730 +#define GL_MODELVIEW17_ARB 0x8731 +#define GL_MODELVIEW18_ARB 0x8732 +#define GL_MODELVIEW19_ARB 0x8733 +#define GL_MODELVIEW20_ARB 0x8734 +#define GL_MODELVIEW21_ARB 0x8735 +#define GL_MODELVIEW22_ARB 0x8736 +#define GL_MODELVIEW23_ARB 0x8737 +#define GL_MODELVIEW24_ARB 0x8738 +#define GL_MODELVIEW25_ARB 0x8739 +#define GL_MODELVIEW26_ARB 0x873A +#define GL_MODELVIEW27_ARB 0x873B +#define GL_MODELVIEW28_ARB 0x873C +#define GL_MODELVIEW29_ARB 0x873D +#define GL_MODELVIEW30_ARB 0x873E +#define GL_MODELVIEW31_ARB 0x873F +#endif + +#ifndef GL_ARB_matrix_palette +#define GL_MATRIX_PALETTE_ARB 0x8840 +#define GL_MAX_MATRIX_PALETTE_STACK_DEPTH_ARB 0x8841 +#define GL_MAX_PALETTE_MATRICES_ARB 0x8842 +#define GL_CURRENT_PALETTE_MATRIX_ARB 0x8843 +#define GL_MATRIX_INDEX_ARRAY_ARB 0x8844 +#define GL_CURRENT_MATRIX_INDEX_ARB 0x8845 +#define GL_MATRIX_INDEX_ARRAY_SIZE_ARB 0x8846 +#define GL_MATRIX_INDEX_ARRAY_TYPE_ARB 0x8847 +#define GL_MATRIX_INDEX_ARRAY_STRIDE_ARB 0x8848 +#define GL_MATRIX_INDEX_ARRAY_POINTER_ARB 0x8849 +#endif + +#ifndef GL_ARB_texture_env_combine +#define GL_COMBINE_ARB 0x8570 +#define GL_COMBINE_RGB_ARB 0x8571 +#define GL_COMBINE_ALPHA_ARB 0x8572 +#define GL_SOURCE0_RGB_ARB 0x8580 +#define GL_SOURCE1_RGB_ARB 0x8581 +#define GL_SOURCE2_RGB_ARB 0x8582 +#define GL_SOURCE0_ALPHA_ARB 0x8588 +#define GL_SOURCE1_ALPHA_ARB 0x8589 +#define GL_SOURCE2_ALPHA_ARB 0x858A +#define GL_OPERAND0_RGB_ARB 0x8590 +#define GL_OPERAND1_RGB_ARB 0x8591 +#define GL_OPERAND2_RGB_ARB 0x8592 +#define GL_OPERAND0_ALPHA_ARB 0x8598 +#define GL_OPERAND1_ALPHA_ARB 0x8599 +#define GL_OPERAND2_ALPHA_ARB 0x859A +#define GL_RGB_SCALE_ARB 0x8573 +#define GL_ADD_SIGNED_ARB 0x8574 +#define GL_INTERPOLATE_ARB 0x8575 +#define GL_SUBTRACT_ARB 0x84E7 +#define GL_CONSTANT_ARB 0x8576 +#define GL_PRIMARY_COLOR_ARB 0x8577 +#define GL_PREVIOUS_ARB 0x8578 +#endif + +#ifndef GL_ARB_texture_env_crossbar +#endif + +#ifndef GL_ARB_texture_env_dot3 +#define GL_DOT3_RGB_ARB 0x86AE +#define GL_DOT3_RGBA_ARB 0x86AF +#endif + +#ifndef GL_ARB_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_ARB 0x8370 +#endif + +#ifndef GL_ARB_depth_texture +#define GL_DEPTH_COMPONENT16_ARB 0x81A5 +#define GL_DEPTH_COMPONENT24_ARB 0x81A6 +#define GL_DEPTH_COMPONENT32_ARB 0x81A7 +#define GL_TEXTURE_DEPTH_SIZE_ARB 0x884A +#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B +#endif + +#ifndef GL_ARB_shadow +#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C +#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D +#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E +#endif + +#ifndef GL_ARB_shadow_ambient +#define GL_TEXTURE_COMPARE_FAIL_VALUE_ARB 0x80BF +#endif + +#ifndef GL_ARB_window_pos +#endif + +#ifndef GL_ARB_vertex_program +#define GL_COLOR_SUM_ARB 0x8458 +#define GL_VERTEX_PROGRAM_ARB 0x8620 +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625 +#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626 +#define GL_PROGRAM_LENGTH_ARB 0x8627 +#define GL_PROGRAM_STRING_ARB 0x8628 +#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E +#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F +#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640 +#define GL_CURRENT_MATRIX_ARB 0x8641 +#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645 +#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B +#define GL_PROGRAM_BINDING_ARB 0x8677 +#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A +#define GL_PROGRAM_ERROR_STRING_ARB 0x8874 +#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875 +#define GL_PROGRAM_FORMAT_ARB 0x8876 +#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0 +#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1 +#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2 +#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3 +#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4 +#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5 +#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6 +#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7 +#define GL_PROGRAM_PARAMETERS_ARB 0x88A8 +#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9 +#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA +#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB +#define GL_PROGRAM_ATTRIBS_ARB 0x88AC +#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD +#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE +#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF +#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0 +#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1 +#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2 +#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3 +#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4 +#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5 +#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6 +#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7 +#define GL_MATRIX0_ARB 0x88C0 +#define GL_MATRIX1_ARB 0x88C1 +#define GL_MATRIX2_ARB 0x88C2 +#define GL_MATRIX3_ARB 0x88C3 +#define GL_MATRIX4_ARB 0x88C4 +#define GL_MATRIX5_ARB 0x88C5 +#define GL_MATRIX6_ARB 0x88C6 +#define GL_MATRIX7_ARB 0x88C7 +#define GL_MATRIX8_ARB 0x88C8 +#define GL_MATRIX9_ARB 0x88C9 +#define GL_MATRIX10_ARB 0x88CA +#define GL_MATRIX11_ARB 0x88CB +#define GL_MATRIX12_ARB 0x88CC +#define GL_MATRIX13_ARB 0x88CD +#define GL_MATRIX14_ARB 0x88CE +#define GL_MATRIX15_ARB 0x88CF +#define GL_MATRIX16_ARB 0x88D0 +#define GL_MATRIX17_ARB 0x88D1 +#define GL_MATRIX18_ARB 0x88D2 +#define GL_MATRIX19_ARB 0x88D3 +#define GL_MATRIX20_ARB 0x88D4 +#define GL_MATRIX21_ARB 0x88D5 +#define GL_MATRIX22_ARB 0x88D6 +#define GL_MATRIX23_ARB 0x88D7 +#define GL_MATRIX24_ARB 0x88D8 +#define GL_MATRIX25_ARB 0x88D9 +#define GL_MATRIX26_ARB 0x88DA +#define GL_MATRIX27_ARB 0x88DB +#define GL_MATRIX28_ARB 0x88DC +#define GL_MATRIX29_ARB 0x88DD +#define GL_MATRIX30_ARB 0x88DE +#define GL_MATRIX31_ARB 0x88DF +#endif + +#ifndef GL_ARB_fragment_program +#define GL_FRAGMENT_PROGRAM_ARB 0x8804 +#define GL_PROGRAM_ALU_INSTRUCTIONS_ARB 0x8805 +#define GL_PROGRAM_TEX_INSTRUCTIONS_ARB 0x8806 +#define GL_PROGRAM_TEX_INDIRECTIONS_ARB 0x8807 +#define GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x8808 +#define GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x8809 +#define GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x880A +#define GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB 0x880B +#define GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB 0x880C +#define GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB 0x880D +#define GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x880E +#define GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x880F +#define GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x8810 +#define GL_MAX_TEXTURE_COORDS_ARB 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872 +#endif + +#ifndef GL_ARB_vertex_buffer_object +#define GL_BUFFER_SIZE_ARB 0x8764 +#define GL_BUFFER_USAGE_ARB 0x8765 +#define GL_ARRAY_BUFFER_ARB 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893 +#define GL_ARRAY_BUFFER_BINDING_ARB 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB 0x8895 +#define GL_VERTEX_ARRAY_BUFFER_BINDING_ARB 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING_ARB 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING_ARB 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING_ARB 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB 0x889E +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB 0x889F +#define GL_READ_ONLY_ARB 0x88B8 +#define GL_WRITE_ONLY_ARB 0x88B9 +#define GL_READ_WRITE_ARB 0x88BA +#define GL_BUFFER_ACCESS_ARB 0x88BB +#define GL_BUFFER_MAPPED_ARB 0x88BC +#define GL_BUFFER_MAP_POINTER_ARB 0x88BD +#define GL_STREAM_DRAW_ARB 0x88E0 +#define GL_STREAM_READ_ARB 0x88E1 +#define GL_STREAM_COPY_ARB 0x88E2 +#define GL_STATIC_DRAW_ARB 0x88E4 +#define GL_STATIC_READ_ARB 0x88E5 +#define GL_STATIC_COPY_ARB 0x88E6 +#define GL_DYNAMIC_DRAW_ARB 0x88E8 +#define GL_DYNAMIC_READ_ARB 0x88E9 +#define GL_DYNAMIC_COPY_ARB 0x88EA +#endif + +#ifndef GL_ARB_occlusion_query +#define GL_QUERY_COUNTER_BITS_ARB 0x8864 +#define GL_CURRENT_QUERY_ARB 0x8865 +#define GL_QUERY_RESULT_ARB 0x8866 +#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867 +#define GL_SAMPLES_PASSED_ARB 0x8914 +#endif + +#ifndef GL_ARB_shader_objects +#define GL_PROGRAM_OBJECT_ARB 0x8B40 +#define GL_SHADER_OBJECT_ARB 0x8B48 +#define GL_OBJECT_TYPE_ARB 0x8B4E +#define GL_OBJECT_SUBTYPE_ARB 0x8B4F +#define GL_FLOAT_VEC2_ARB 0x8B50 +#define GL_FLOAT_VEC3_ARB 0x8B51 +#define GL_FLOAT_VEC4_ARB 0x8B52 +#define GL_INT_VEC2_ARB 0x8B53 +#define GL_INT_VEC3_ARB 0x8B54 +#define GL_INT_VEC4_ARB 0x8B55 +#define GL_BOOL_ARB 0x8B56 +#define GL_BOOL_VEC2_ARB 0x8B57 +#define GL_BOOL_VEC3_ARB 0x8B58 +#define GL_BOOL_VEC4_ARB 0x8B59 +#define GL_FLOAT_MAT2_ARB 0x8B5A +#define GL_FLOAT_MAT3_ARB 0x8B5B +#define GL_FLOAT_MAT4_ARB 0x8B5C +#define GL_SAMPLER_1D_ARB 0x8B5D +#define GL_SAMPLER_2D_ARB 0x8B5E +#define GL_SAMPLER_3D_ARB 0x8B5F +#define GL_SAMPLER_CUBE_ARB 0x8B60 +#define GL_SAMPLER_1D_SHADOW_ARB 0x8B61 +#define GL_SAMPLER_2D_SHADOW_ARB 0x8B62 +#define GL_SAMPLER_2D_RECT_ARB 0x8B63 +#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64 +#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80 +#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81 +#define GL_OBJECT_LINK_STATUS_ARB 0x8B82 +#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83 +#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84 +#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85 +#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86 +#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87 +#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88 +#endif + +#ifndef GL_ARB_vertex_shader +#define GL_VERTEX_SHADER_ARB 0x8B31 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A +#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D +#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89 +#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A +#endif + +#ifndef GL_ARB_fragment_shader +#define GL_FRAGMENT_SHADER_ARB 0x8B30 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49 +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB 0x8B8B +#endif + +#ifndef GL_ARB_shading_language_100 +#define GL_SHADING_LANGUAGE_VERSION_ARB 0x8B8C +#endif + +#ifndef GL_ARB_texture_non_power_of_two +#endif + +#ifndef GL_ARB_point_sprite +#define GL_POINT_SPRITE_ARB 0x8861 +#define GL_COORD_REPLACE_ARB 0x8862 +#endif + +#ifndef GL_ARB_fragment_program_shadow +#endif + +#ifndef GL_ARB_draw_buffers +#define GL_MAX_DRAW_BUFFERS_ARB 0x8824 +#define GL_DRAW_BUFFER0_ARB 0x8825 +#define GL_DRAW_BUFFER1_ARB 0x8826 +#define GL_DRAW_BUFFER2_ARB 0x8827 +#define GL_DRAW_BUFFER3_ARB 0x8828 +#define GL_DRAW_BUFFER4_ARB 0x8829 +#define GL_DRAW_BUFFER5_ARB 0x882A +#define GL_DRAW_BUFFER6_ARB 0x882B +#define GL_DRAW_BUFFER7_ARB 0x882C +#define GL_DRAW_BUFFER8_ARB 0x882D +#define GL_DRAW_BUFFER9_ARB 0x882E +#define GL_DRAW_BUFFER10_ARB 0x882F +#define GL_DRAW_BUFFER11_ARB 0x8830 +#define GL_DRAW_BUFFER12_ARB 0x8831 +#define GL_DRAW_BUFFER13_ARB 0x8832 +#define GL_DRAW_BUFFER14_ARB 0x8833 +#define GL_DRAW_BUFFER15_ARB 0x8834 +#endif + +#ifndef GL_ARB_texture_rectangle +#define GL_TEXTURE_RECTANGLE_ARB 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE_ARB 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE_ARB 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 +#endif + +#ifndef GL_ARB_color_buffer_float +#define GL_RGBA_FLOAT_MODE_ARB 0x8820 +#define GL_CLAMP_VERTEX_COLOR_ARB 0x891A +#define GL_CLAMP_FRAGMENT_COLOR_ARB 0x891B +#define GL_CLAMP_READ_COLOR_ARB 0x891C +#define GL_FIXED_ONLY_ARB 0x891D +#endif + +#ifndef GL_ARB_half_float_pixel +#define GL_HALF_FLOAT_ARB 0x140B +#endif + +#ifndef GL_ARB_texture_float +#define GL_TEXTURE_RED_TYPE_ARB 0x8C10 +#define GL_TEXTURE_GREEN_TYPE_ARB 0x8C11 +#define GL_TEXTURE_BLUE_TYPE_ARB 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE_ARB 0x8C13 +#define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x8C14 +#define GL_TEXTURE_INTENSITY_TYPE_ARB 0x8C15 +#define GL_TEXTURE_DEPTH_TYPE_ARB 0x8C16 +#define GL_UNSIGNED_NORMALIZED_ARB 0x8C17 +#define GL_RGBA32F_ARB 0x8814 +#define GL_RGB32F_ARB 0x8815 +#define GL_ALPHA32F_ARB 0x8816 +#define GL_INTENSITY32F_ARB 0x8817 +#define GL_LUMINANCE32F_ARB 0x8818 +#define GL_LUMINANCE_ALPHA32F_ARB 0x8819 +#define GL_RGBA16F_ARB 0x881A +#define GL_RGB16F_ARB 0x881B +#define GL_ALPHA16F_ARB 0x881C +#define GL_INTENSITY16F_ARB 0x881D +#define GL_LUMINANCE16F_ARB 0x881E +#define GL_LUMINANCE_ALPHA16F_ARB 0x881F +#endif + +#ifndef GL_ARB_pixel_buffer_object +#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB +#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF +#endif + +#ifndef GL_ARB_depth_buffer_float +#define GL_DEPTH_COMPONENT32F 0x8CAC +#define GL_DEPTH32F_STENCIL8 0x8CAD +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD +#endif + +#ifndef GL_ARB_draw_instanced +#endif + +#ifndef GL_ARB_framebuffer_object +#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 +#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 +#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 +#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 +#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 +#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 +#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 +#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 +#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 +#define GL_FRAMEBUFFER_DEFAULT 0x8218 +#define GL_FRAMEBUFFER_UNDEFINED 0x8219 +#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A +#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 +#define GL_DEPTH_STENCIL 0x84F9 +#define GL_UNSIGNED_INT_24_8 0x84FA +#define GL_DEPTH24_STENCIL8 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE 0x88F1 +#define GL_TEXTURE_RED_TYPE 0x8C10 +#define GL_TEXTURE_GREEN_TYPE 0x8C11 +#define GL_TEXTURE_BLUE_TYPE 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE 0x8C13 +#define GL_TEXTURE_DEPTH_TYPE 0x8C16 +#define GL_UNSIGNED_NORMALIZED 0x8C17 +#define GL_FRAMEBUFFER_BINDING 0x8CA6 +#define GL_DRAW_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING +#define GL_RENDERBUFFER_BINDING 0x8CA7 +#define GL_READ_FRAMEBUFFER 0x8CA8 +#define GL_DRAW_FRAMEBUFFER 0x8CA9 +#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA +#define GL_RENDERBUFFER_SAMPLES 0x8CAB +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 +#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC +#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD +#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_COLOR_ATTACHMENT1 0x8CE1 +#define GL_COLOR_ATTACHMENT2 0x8CE2 +#define GL_COLOR_ATTACHMENT3 0x8CE3 +#define GL_COLOR_ATTACHMENT4 0x8CE4 +#define GL_COLOR_ATTACHMENT5 0x8CE5 +#define GL_COLOR_ATTACHMENT6 0x8CE6 +#define GL_COLOR_ATTACHMENT7 0x8CE7 +#define GL_COLOR_ATTACHMENT8 0x8CE8 +#define GL_COLOR_ATTACHMENT9 0x8CE9 +#define GL_COLOR_ATTACHMENT10 0x8CEA +#define GL_COLOR_ATTACHMENT11 0x8CEB +#define GL_COLOR_ATTACHMENT12 0x8CEC +#define GL_COLOR_ATTACHMENT13 0x8CED +#define GL_COLOR_ATTACHMENT14 0x8CEE +#define GL_COLOR_ATTACHMENT15 0x8CEF +#define GL_DEPTH_ATTACHMENT 0x8D00 +#define GL_STENCIL_ATTACHMENT 0x8D20 +#define GL_FRAMEBUFFER 0x8D40 +#define GL_RENDERBUFFER 0x8D41 +#define GL_RENDERBUFFER_WIDTH 0x8D42 +#define GL_RENDERBUFFER_HEIGHT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 +#define GL_STENCIL_INDEX1 0x8D46 +#define GL_STENCIL_INDEX4 0x8D47 +#define GL_STENCIL_INDEX8 0x8D48 +#define GL_STENCIL_INDEX16 0x8D49 +#define GL_RENDERBUFFER_RED_SIZE 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 +#define GL_MAX_SAMPLES 0x8D57 +#endif + +#ifndef GL_ARB_framebuffer_object_DEPRECATED +#define GL_INDEX 0x8222 +#define GL_TEXTURE_LUMINANCE_TYPE 0x8C14 +#define GL_TEXTURE_INTENSITY_TYPE 0x8C15 +#endif + +#ifndef GL_ARB_framebuffer_sRGB +#define GL_FRAMEBUFFER_SRGB 0x8DB9 +#endif + +#ifndef GL_ARB_geometry_shader4 +#define GL_LINES_ADJACENCY_ARB 0x000A +#define GL_LINE_STRIP_ADJACENCY_ARB 0x000B +#define GL_TRIANGLES_ADJACENCY_ARB 0x000C +#define GL_TRIANGLE_STRIP_ADJACENCY_ARB 0x000D +#define GL_PROGRAM_POINT_SIZE_ARB 0x8642 +#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_ARB 0x8C29 +#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_ARB 0x8DA7 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB 0x8DA8 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB 0x8DA9 +#define GL_GEOMETRY_SHADER_ARB 0x8DD9 +#define GL_GEOMETRY_VERTICES_OUT_ARB 0x8DDA +#define GL_GEOMETRY_INPUT_TYPE_ARB 0x8DDB +#define GL_GEOMETRY_OUTPUT_TYPE_ARB 0x8DDC +#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_ARB 0x8DDD +#define GL_MAX_VERTEX_VARYING_COMPONENTS_ARB 0x8DDE +#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_ARB 0x8DDF +#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_ARB 0x8DE0 +#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB 0x8DE1 +/* reuse GL_MAX_VARYING_COMPONENTS */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ +#endif + +#ifndef GL_ARB_half_float_vertex +#define GL_HALF_FLOAT 0x140B +#endif + +#ifndef GL_ARB_instanced_arrays +#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB 0x88FE +#endif + +#ifndef GL_ARB_map_buffer_range +#define GL_MAP_READ_BIT 0x0001 +#define GL_MAP_WRITE_BIT 0x0002 +#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004 +#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 +#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 +#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 +#endif + +#ifndef GL_ARB_texture_buffer_object +#define GL_TEXTURE_BUFFER_ARB 0x8C2A +#define GL_MAX_TEXTURE_BUFFER_SIZE_ARB 0x8C2B +#define GL_TEXTURE_BINDING_BUFFER_ARB 0x8C2C +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB 0x8C2D +#define GL_TEXTURE_BUFFER_FORMAT_ARB 0x8C2E +#endif + +#ifndef GL_ARB_texture_compression_rgtc +#define GL_COMPRESSED_RED_RGTC1 0x8DBB +#define GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC +#define GL_COMPRESSED_RG_RGTC2 0x8DBD +#define GL_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE +#endif + +#ifndef GL_ARB_texture_rg +#define GL_RG 0x8227 +#define GL_RG_INTEGER 0x8228 +#define GL_R8 0x8229 +#define GL_R16 0x822A +#define GL_RG8 0x822B +#define GL_RG16 0x822C +#define GL_R16F 0x822D +#define GL_R32F 0x822E +#define GL_RG16F 0x822F +#define GL_RG32F 0x8230 +#define GL_R8I 0x8231 +#define GL_R8UI 0x8232 +#define GL_R16I 0x8233 +#define GL_R16UI 0x8234 +#define GL_R32I 0x8235 +#define GL_R32UI 0x8236 +#define GL_RG8I 0x8237 +#define GL_RG8UI 0x8238 +#define GL_RG16I 0x8239 +#define GL_RG16UI 0x823A +#define GL_RG32I 0x823B +#define GL_RG32UI 0x823C +#endif + +#ifndef GL_ARB_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING 0x85B5 +#endif + +#ifndef GL_ARB_uniform_buffer_object +#define GL_UNIFORM_BUFFER 0x8A11 +#define GL_UNIFORM_BUFFER_BINDING 0x8A28 +#define GL_UNIFORM_BUFFER_START 0x8A29 +#define GL_UNIFORM_BUFFER_SIZE 0x8A2A +#define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B +#define GL_MAX_GEOMETRY_UNIFORM_BLOCKS 0x8A2C +#define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D +#define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E +#define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F +#define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30 +#define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31 +#define GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS 0x8A32 +#define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33 +#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34 +#define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35 +#define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 +#define GL_UNIFORM_TYPE 0x8A37 +#define GL_UNIFORM_SIZE 0x8A38 +#define GL_UNIFORM_NAME_LENGTH 0x8A39 +#define GL_UNIFORM_BLOCK_INDEX 0x8A3A +#define GL_UNIFORM_OFFSET 0x8A3B +#define GL_UNIFORM_ARRAY_STRIDE 0x8A3C +#define GL_UNIFORM_MATRIX_STRIDE 0x8A3D +#define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E +#define GL_UNIFORM_BLOCK_BINDING 0x8A3F +#define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 +#define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER 0x8A45 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46 +#define GL_INVALID_INDEX 0xFFFFFFFFu +#endif + +#ifndef GL_ARB_compatibility +/* ARB_compatibility just defines tokens from core 3.0 */ +#endif + +#ifndef GL_ARB_copy_buffer +#define GL_COPY_READ_BUFFER 0x8F36 +#define GL_COPY_WRITE_BUFFER 0x8F37 +#endif + +#ifndef GL_ARB_shader_texture_lod +#endif + +#ifndef GL_ARB_depth_clamp +#define GL_DEPTH_CLAMP 0x864F +#endif + +#ifndef GL_ARB_draw_elements_base_vertex +#endif + +#ifndef GL_ARB_fragment_coord_conventions +#endif + +#ifndef GL_ARB_provoking_vertex +#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION 0x8E4C +#define GL_FIRST_VERTEX_CONVENTION 0x8E4D +#define GL_LAST_VERTEX_CONVENTION 0x8E4E +#define GL_PROVOKING_VERTEX 0x8E4F +#endif + +#ifndef GL_ARB_seamless_cube_map +#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F +#endif + +#ifndef GL_ARB_sync +#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 +#define GL_OBJECT_TYPE 0x9112 +#define GL_SYNC_CONDITION 0x9113 +#define GL_SYNC_STATUS 0x9114 +#define GL_SYNC_FLAGS 0x9115 +#define GL_SYNC_FENCE 0x9116 +#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 +#define GL_UNSIGNALED 0x9118 +#define GL_SIGNALED 0x9119 +#define GL_ALREADY_SIGNALED 0x911A +#define GL_TIMEOUT_EXPIRED 0x911B +#define GL_CONDITION_SATISFIED 0x911C +#define GL_WAIT_FAILED 0x911D +#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 +#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull +#endif + +#ifndef GL_ARB_texture_multisample +#define GL_SAMPLE_POSITION 0x8E50 +#define GL_SAMPLE_MASK 0x8E51 +#define GL_SAMPLE_MASK_VALUE 0x8E52 +#define GL_MAX_SAMPLE_MASK_WORDS 0x8E59 +#define GL_TEXTURE_2D_MULTISAMPLE 0x9100 +#define GL_PROXY_TEXTURE_2D_MULTISAMPLE 0x9101 +#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102 +#define GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9103 +#define GL_TEXTURE_BINDING_2D_MULTISAMPLE 0x9104 +#define GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY 0x9105 +#define GL_TEXTURE_SAMPLES 0x9106 +#define GL_TEXTURE_FIXED_SAMPLE_LOCATIONS 0x9107 +#define GL_SAMPLER_2D_MULTISAMPLE 0x9108 +#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109 +#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A +#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B +#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C +#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D +#define GL_MAX_COLOR_TEXTURE_SAMPLES 0x910E +#define GL_MAX_DEPTH_TEXTURE_SAMPLES 0x910F +#define GL_MAX_INTEGER_SAMPLES 0x9110 +#endif + +#ifndef GL_ARB_vertex_array_bgra +/* reuse GL_BGRA */ +#endif + +#ifndef GL_ARB_draw_buffers_blend +#endif + +#ifndef GL_ARB_sample_shading +#define GL_SAMPLE_SHADING 0x8C36 +#define GL_MIN_SAMPLE_SHADING_VALUE 0x8C37 +#endif + +#ifndef GL_ARB_texture_cube_map_array +#define GL_TEXTURE_CUBE_MAP_ARRAY 0x9009 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY 0x900A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY 0x900B +#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C +#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D +#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E +#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F +#endif + +#ifndef GL_ARB_texture_gather +#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5E +#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5F +#define GL_MAX_PROGRAM_TEXTURE_GATHER_COMPONENTS 0x8F9F +#endif + +#ifndef GL_ARB_texture_query_lod +#endif + +#ifndef GL_EXT_abgr +#define GL_ABGR_EXT 0x8000 +#endif + +#ifndef GL_EXT_blend_color +#define GL_CONSTANT_COLOR_EXT 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR_EXT 0x8002 +#define GL_CONSTANT_ALPHA_EXT 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA_EXT 0x8004 +#define GL_BLEND_COLOR_EXT 0x8005 +#endif + +#ifndef GL_EXT_polygon_offset +#define GL_POLYGON_OFFSET_EXT 0x8037 +#define GL_POLYGON_OFFSET_FACTOR_EXT 0x8038 +#define GL_POLYGON_OFFSET_BIAS_EXT 0x8039 +#endif + +#ifndef GL_EXT_texture +#define GL_ALPHA4_EXT 0x803B +#define GL_ALPHA8_EXT 0x803C +#define GL_ALPHA12_EXT 0x803D +#define GL_ALPHA16_EXT 0x803E +#define GL_LUMINANCE4_EXT 0x803F +#define GL_LUMINANCE8_EXT 0x8040 +#define GL_LUMINANCE12_EXT 0x8041 +#define GL_LUMINANCE16_EXT 0x8042 +#define GL_LUMINANCE4_ALPHA4_EXT 0x8043 +#define GL_LUMINANCE6_ALPHA2_EXT 0x8044 +#define GL_LUMINANCE8_ALPHA8_EXT 0x8045 +#define GL_LUMINANCE12_ALPHA4_EXT 0x8046 +#define GL_LUMINANCE12_ALPHA12_EXT 0x8047 +#define GL_LUMINANCE16_ALPHA16_EXT 0x8048 +#define GL_INTENSITY_EXT 0x8049 +#define GL_INTENSITY4_EXT 0x804A +#define GL_INTENSITY8_EXT 0x804B +#define GL_INTENSITY12_EXT 0x804C +#define GL_INTENSITY16_EXT 0x804D +#define GL_RGB2_EXT 0x804E +#define GL_RGB4_EXT 0x804F +#define GL_RGB5_EXT 0x8050 +#define GL_RGB8_EXT 0x8051 +#define GL_RGB10_EXT 0x8052 +#define GL_RGB12_EXT 0x8053 +#define GL_RGB16_EXT 0x8054 +#define GL_RGBA2_EXT 0x8055 +#define GL_RGBA4_EXT 0x8056 +#define GL_RGB5_A1_EXT 0x8057 +#define GL_RGBA8_EXT 0x8058 +#define GL_RGB10_A2_EXT 0x8059 +#define GL_RGBA12_EXT 0x805A +#define GL_RGBA16_EXT 0x805B +#define GL_TEXTURE_RED_SIZE_EXT 0x805C +#define GL_TEXTURE_GREEN_SIZE_EXT 0x805D +#define GL_TEXTURE_BLUE_SIZE_EXT 0x805E +#define GL_TEXTURE_ALPHA_SIZE_EXT 0x805F +#define GL_TEXTURE_LUMINANCE_SIZE_EXT 0x8060 +#define GL_TEXTURE_INTENSITY_SIZE_EXT 0x8061 +#define GL_REPLACE_EXT 0x8062 +#define GL_PROXY_TEXTURE_1D_EXT 0x8063 +#define GL_PROXY_TEXTURE_2D_EXT 0x8064 +#define GL_TEXTURE_TOO_LARGE_EXT 0x8065 +#endif + +#ifndef GL_EXT_texture3D +#define GL_PACK_SKIP_IMAGES_EXT 0x806B +#define GL_PACK_IMAGE_HEIGHT_EXT 0x806C +#define GL_UNPACK_SKIP_IMAGES_EXT 0x806D +#define GL_UNPACK_IMAGE_HEIGHT_EXT 0x806E +#define GL_TEXTURE_3D_EXT 0x806F +#define GL_PROXY_TEXTURE_3D_EXT 0x8070 +#define GL_TEXTURE_DEPTH_EXT 0x8071 +#define GL_TEXTURE_WRAP_R_EXT 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE_EXT 0x8073 +#endif + +#ifndef GL_SGIS_texture_filter4 +#define GL_FILTER4_SGIS 0x8146 +#define GL_TEXTURE_FILTER4_SIZE_SGIS 0x8147 +#endif + +#ifndef GL_EXT_subtexture +#endif + +#ifndef GL_EXT_copy_texture +#endif + +#ifndef GL_EXT_histogram +#define GL_HISTOGRAM_EXT 0x8024 +#define GL_PROXY_HISTOGRAM_EXT 0x8025 +#define GL_HISTOGRAM_WIDTH_EXT 0x8026 +#define GL_HISTOGRAM_FORMAT_EXT 0x8027 +#define GL_HISTOGRAM_RED_SIZE_EXT 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE_EXT 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE_EXT 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE_EXT 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE_EXT 0x802C +#define GL_HISTOGRAM_SINK_EXT 0x802D +#define GL_MINMAX_EXT 0x802E +#define GL_MINMAX_FORMAT_EXT 0x802F +#define GL_MINMAX_SINK_EXT 0x8030 +#define GL_TABLE_TOO_LARGE_EXT 0x8031 +#endif + +#ifndef GL_EXT_convolution +#define GL_CONVOLUTION_1D_EXT 0x8010 +#define GL_CONVOLUTION_2D_EXT 0x8011 +#define GL_SEPARABLE_2D_EXT 0x8012 +#define GL_CONVOLUTION_BORDER_MODE_EXT 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE_EXT 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS_EXT 0x8015 +#define GL_REDUCE_EXT 0x8016 +#define GL_CONVOLUTION_FORMAT_EXT 0x8017 +#define GL_CONVOLUTION_WIDTH_EXT 0x8018 +#define GL_CONVOLUTION_HEIGHT_EXT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH_EXT 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT_EXT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE_EXT 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE_EXT 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE_EXT 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE_EXT 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS_EXT 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS_EXT 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS_EXT 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS_EXT 0x8023 +#endif + +#ifndef GL_SGI_color_matrix +#define GL_COLOR_MATRIX_SGI 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE_SGI 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE_SGI 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE_SGI 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE_SGI 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS_SGI 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS_SGI 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS_SGI 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS_SGI 0x80BB +#endif + +#ifndef GL_SGI_color_table +#define GL_COLOR_TABLE_SGI 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D2 +#define GL_PROXY_COLOR_TABLE_SGI 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D5 +#define GL_COLOR_TABLE_SCALE_SGI 0x80D6 +#define GL_COLOR_TABLE_BIAS_SGI 0x80D7 +#define GL_COLOR_TABLE_FORMAT_SGI 0x80D8 +#define GL_COLOR_TABLE_WIDTH_SGI 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE_SGI 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE_SGI 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE_SGI 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE_SGI 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE_SGI 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE_SGI 0x80DF +#endif + +#ifndef GL_SGIS_pixel_texture +#define GL_PIXEL_TEXTURE_SGIS 0x8353 +#define GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS 0x8354 +#define GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS 0x8355 +#define GL_PIXEL_GROUP_COLOR_SGIS 0x8356 +#endif + +#ifndef GL_SGIX_pixel_texture +#define GL_PIXEL_TEX_GEN_SGIX 0x8139 +#define GL_PIXEL_TEX_GEN_MODE_SGIX 0x832B +#endif + +#ifndef GL_SGIS_texture4D +#define GL_PACK_SKIP_VOLUMES_SGIS 0x8130 +#define GL_PACK_IMAGE_DEPTH_SGIS 0x8131 +#define GL_UNPACK_SKIP_VOLUMES_SGIS 0x8132 +#define GL_UNPACK_IMAGE_DEPTH_SGIS 0x8133 +#define GL_TEXTURE_4D_SGIS 0x8134 +#define GL_PROXY_TEXTURE_4D_SGIS 0x8135 +#define GL_TEXTURE_4DSIZE_SGIS 0x8136 +#define GL_TEXTURE_WRAP_Q_SGIS 0x8137 +#define GL_MAX_4D_TEXTURE_SIZE_SGIS 0x8138 +#define GL_TEXTURE_4D_BINDING_SGIS 0x814F +#endif + +#ifndef GL_SGI_texture_color_table +#define GL_TEXTURE_COLOR_TABLE_SGI 0x80BC +#define GL_PROXY_TEXTURE_COLOR_TABLE_SGI 0x80BD +#endif + +#ifndef GL_EXT_cmyka +#define GL_CMYK_EXT 0x800C +#define GL_CMYKA_EXT 0x800D +#define GL_PACK_CMYK_HINT_EXT 0x800E +#define GL_UNPACK_CMYK_HINT_EXT 0x800F +#endif + +#ifndef GL_EXT_texture_object +#define GL_TEXTURE_PRIORITY_EXT 0x8066 +#define GL_TEXTURE_RESIDENT_EXT 0x8067 +#define GL_TEXTURE_1D_BINDING_EXT 0x8068 +#define GL_TEXTURE_2D_BINDING_EXT 0x8069 +#define GL_TEXTURE_3D_BINDING_EXT 0x806A +#endif + +#ifndef GL_SGIS_detail_texture +#define GL_DETAIL_TEXTURE_2D_SGIS 0x8095 +#define GL_DETAIL_TEXTURE_2D_BINDING_SGIS 0x8096 +#define GL_LINEAR_DETAIL_SGIS 0x8097 +#define GL_LINEAR_DETAIL_ALPHA_SGIS 0x8098 +#define GL_LINEAR_DETAIL_COLOR_SGIS 0x8099 +#define GL_DETAIL_TEXTURE_LEVEL_SGIS 0x809A +#define GL_DETAIL_TEXTURE_MODE_SGIS 0x809B +#define GL_DETAIL_TEXTURE_FUNC_POINTS_SGIS 0x809C +#endif + +#ifndef GL_SGIS_sharpen_texture +#define GL_LINEAR_SHARPEN_SGIS 0x80AD +#define GL_LINEAR_SHARPEN_ALPHA_SGIS 0x80AE +#define GL_LINEAR_SHARPEN_COLOR_SGIS 0x80AF +#define GL_SHARPEN_TEXTURE_FUNC_POINTS_SGIS 0x80B0 +#endif + +#ifndef GL_EXT_packed_pixels +#define GL_UNSIGNED_BYTE_3_3_2_EXT 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4_EXT 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1_EXT 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8_EXT 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2_EXT 0x8036 +#endif + +#ifndef GL_SGIS_texture_lod +#define GL_TEXTURE_MIN_LOD_SGIS 0x813A +#define GL_TEXTURE_MAX_LOD_SGIS 0x813B +#define GL_TEXTURE_BASE_LEVEL_SGIS 0x813C +#define GL_TEXTURE_MAX_LEVEL_SGIS 0x813D +#endif + +#ifndef GL_SGIS_multisample +#define GL_MULTISAMPLE_SGIS 0x809D +#define GL_SAMPLE_ALPHA_TO_MASK_SGIS 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_SGIS 0x809F +#define GL_SAMPLE_MASK_SGIS 0x80A0 +#define GL_1PASS_SGIS 0x80A1 +#define GL_2PASS_0_SGIS 0x80A2 +#define GL_2PASS_1_SGIS 0x80A3 +#define GL_4PASS_0_SGIS 0x80A4 +#define GL_4PASS_1_SGIS 0x80A5 +#define GL_4PASS_2_SGIS 0x80A6 +#define GL_4PASS_3_SGIS 0x80A7 +#define GL_SAMPLE_BUFFERS_SGIS 0x80A8 +#define GL_SAMPLES_SGIS 0x80A9 +#define GL_SAMPLE_MASK_VALUE_SGIS 0x80AA +#define GL_SAMPLE_MASK_INVERT_SGIS 0x80AB +#define GL_SAMPLE_PATTERN_SGIS 0x80AC +#endif + +#ifndef GL_EXT_rescale_normal +#define GL_RESCALE_NORMAL_EXT 0x803A +#endif + +#ifndef GL_EXT_vertex_array +#define GL_VERTEX_ARRAY_EXT 0x8074 +#define GL_NORMAL_ARRAY_EXT 0x8075 +#define GL_COLOR_ARRAY_EXT 0x8076 +#define GL_INDEX_ARRAY_EXT 0x8077 +#define GL_TEXTURE_COORD_ARRAY_EXT 0x8078 +#define GL_EDGE_FLAG_ARRAY_EXT 0x8079 +#define GL_VERTEX_ARRAY_SIZE_EXT 0x807A +#define GL_VERTEX_ARRAY_TYPE_EXT 0x807B +#define GL_VERTEX_ARRAY_STRIDE_EXT 0x807C +#define GL_VERTEX_ARRAY_COUNT_EXT 0x807D +#define GL_NORMAL_ARRAY_TYPE_EXT 0x807E +#define GL_NORMAL_ARRAY_STRIDE_EXT 0x807F +#define GL_NORMAL_ARRAY_COUNT_EXT 0x8080 +#define GL_COLOR_ARRAY_SIZE_EXT 0x8081 +#define GL_COLOR_ARRAY_TYPE_EXT 0x8082 +#define GL_COLOR_ARRAY_STRIDE_EXT 0x8083 +#define GL_COLOR_ARRAY_COUNT_EXT 0x8084 +#define GL_INDEX_ARRAY_TYPE_EXT 0x8085 +#define GL_INDEX_ARRAY_STRIDE_EXT 0x8086 +#define GL_INDEX_ARRAY_COUNT_EXT 0x8087 +#define GL_TEXTURE_COORD_ARRAY_SIZE_EXT 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE_EXT 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE_EXT 0x808A +#define GL_TEXTURE_COORD_ARRAY_COUNT_EXT 0x808B +#define GL_EDGE_FLAG_ARRAY_STRIDE_EXT 0x808C +#define GL_EDGE_FLAG_ARRAY_COUNT_EXT 0x808D +#define GL_VERTEX_ARRAY_POINTER_EXT 0x808E +#define GL_NORMAL_ARRAY_POINTER_EXT 0x808F +#define GL_COLOR_ARRAY_POINTER_EXT 0x8090 +#define GL_INDEX_ARRAY_POINTER_EXT 0x8091 +#define GL_TEXTURE_COORD_ARRAY_POINTER_EXT 0x8092 +#define GL_EDGE_FLAG_ARRAY_POINTER_EXT 0x8093 +#endif + +#ifndef GL_EXT_misc_attribute +#endif + +#ifndef GL_SGIS_generate_mipmap +#define GL_GENERATE_MIPMAP_SGIS 0x8191 +#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 +#endif + +#ifndef GL_SGIX_clipmap +#define GL_LINEAR_CLIPMAP_LINEAR_SGIX 0x8170 +#define GL_TEXTURE_CLIPMAP_CENTER_SGIX 0x8171 +#define GL_TEXTURE_CLIPMAP_FRAME_SGIX 0x8172 +#define GL_TEXTURE_CLIPMAP_OFFSET_SGIX 0x8173 +#define GL_TEXTURE_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8174 +#define GL_TEXTURE_CLIPMAP_LOD_OFFSET_SGIX 0x8175 +#define GL_TEXTURE_CLIPMAP_DEPTH_SGIX 0x8176 +#define GL_MAX_CLIPMAP_DEPTH_SGIX 0x8177 +#define GL_MAX_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8178 +#define GL_NEAREST_CLIPMAP_NEAREST_SGIX 0x844D +#define GL_NEAREST_CLIPMAP_LINEAR_SGIX 0x844E +#define GL_LINEAR_CLIPMAP_NEAREST_SGIX 0x844F +#endif + +#ifndef GL_SGIX_shadow +#define GL_TEXTURE_COMPARE_SGIX 0x819A +#define GL_TEXTURE_COMPARE_OPERATOR_SGIX 0x819B +#define GL_TEXTURE_LEQUAL_R_SGIX 0x819C +#define GL_TEXTURE_GEQUAL_R_SGIX 0x819D +#endif + +#ifndef GL_SGIS_texture_edge_clamp +#define GL_CLAMP_TO_EDGE_SGIS 0x812F +#endif + +#ifndef GL_SGIS_texture_border_clamp +#define GL_CLAMP_TO_BORDER_SGIS 0x812D +#endif + +#ifndef GL_EXT_blend_minmax +#define GL_FUNC_ADD_EXT 0x8006 +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#define GL_BLEND_EQUATION_EXT 0x8009 +#endif + +#ifndef GL_EXT_blend_subtract +#define GL_FUNC_SUBTRACT_EXT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT_EXT 0x800B +#endif + +#ifndef GL_EXT_blend_logic_op +#endif + +#ifndef GL_SGIX_interlace +#define GL_INTERLACE_SGIX 0x8094 +#endif + +#ifndef GL_SGIX_pixel_tiles +#define GL_PIXEL_TILE_BEST_ALIGNMENT_SGIX 0x813E +#define GL_PIXEL_TILE_CACHE_INCREMENT_SGIX 0x813F +#define GL_PIXEL_TILE_WIDTH_SGIX 0x8140 +#define GL_PIXEL_TILE_HEIGHT_SGIX 0x8141 +#define GL_PIXEL_TILE_GRID_WIDTH_SGIX 0x8142 +#define GL_PIXEL_TILE_GRID_HEIGHT_SGIX 0x8143 +#define GL_PIXEL_TILE_GRID_DEPTH_SGIX 0x8144 +#define GL_PIXEL_TILE_CACHE_SIZE_SGIX 0x8145 +#endif + +#ifndef GL_SGIS_texture_select +#define GL_DUAL_ALPHA4_SGIS 0x8110 +#define GL_DUAL_ALPHA8_SGIS 0x8111 +#define GL_DUAL_ALPHA12_SGIS 0x8112 +#define GL_DUAL_ALPHA16_SGIS 0x8113 +#define GL_DUAL_LUMINANCE4_SGIS 0x8114 +#define GL_DUAL_LUMINANCE8_SGIS 0x8115 +#define GL_DUAL_LUMINANCE12_SGIS 0x8116 +#define GL_DUAL_LUMINANCE16_SGIS 0x8117 +#define GL_DUAL_INTENSITY4_SGIS 0x8118 +#define GL_DUAL_INTENSITY8_SGIS 0x8119 +#define GL_DUAL_INTENSITY12_SGIS 0x811A +#define GL_DUAL_INTENSITY16_SGIS 0x811B +#define GL_DUAL_LUMINANCE_ALPHA4_SGIS 0x811C +#define GL_DUAL_LUMINANCE_ALPHA8_SGIS 0x811D +#define GL_QUAD_ALPHA4_SGIS 0x811E +#define GL_QUAD_ALPHA8_SGIS 0x811F +#define GL_QUAD_LUMINANCE4_SGIS 0x8120 +#define GL_QUAD_LUMINANCE8_SGIS 0x8121 +#define GL_QUAD_INTENSITY4_SGIS 0x8122 +#define GL_QUAD_INTENSITY8_SGIS 0x8123 +#define GL_DUAL_TEXTURE_SELECT_SGIS 0x8124 +#define GL_QUAD_TEXTURE_SELECT_SGIS 0x8125 +#endif + +#ifndef GL_SGIX_sprite +#define GL_SPRITE_SGIX 0x8148 +#define GL_SPRITE_MODE_SGIX 0x8149 +#define GL_SPRITE_AXIS_SGIX 0x814A +#define GL_SPRITE_TRANSLATION_SGIX 0x814B +#define GL_SPRITE_AXIAL_SGIX 0x814C +#define GL_SPRITE_OBJECT_ALIGNED_SGIX 0x814D +#define GL_SPRITE_EYE_ALIGNED_SGIX 0x814E +#endif + +#ifndef GL_SGIX_texture_multi_buffer +#define GL_TEXTURE_MULTI_BUFFER_HINT_SGIX 0x812E +#endif + +#ifndef GL_EXT_point_parameters +#define GL_POINT_SIZE_MIN_EXT 0x8126 +#define GL_POINT_SIZE_MAX_EXT 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128 +#define GL_DISTANCE_ATTENUATION_EXT 0x8129 +#endif + +#ifndef GL_SGIS_point_parameters +#define GL_POINT_SIZE_MIN_SGIS 0x8126 +#define GL_POINT_SIZE_MAX_SGIS 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_SGIS 0x8128 +#define GL_DISTANCE_ATTENUATION_SGIS 0x8129 +#endif + +#ifndef GL_SGIX_instruments +#define GL_INSTRUMENT_BUFFER_POINTER_SGIX 0x8180 +#define GL_INSTRUMENT_MEASUREMENTS_SGIX 0x8181 +#endif + +#ifndef GL_SGIX_texture_scale_bias +#define GL_POST_TEXTURE_FILTER_BIAS_SGIX 0x8179 +#define GL_POST_TEXTURE_FILTER_SCALE_SGIX 0x817A +#define GL_POST_TEXTURE_FILTER_BIAS_RANGE_SGIX 0x817B +#define GL_POST_TEXTURE_FILTER_SCALE_RANGE_SGIX 0x817C +#endif + +#ifndef GL_SGIX_framezoom +#define GL_FRAMEZOOM_SGIX 0x818B +#define GL_FRAMEZOOM_FACTOR_SGIX 0x818C +#define GL_MAX_FRAMEZOOM_FACTOR_SGIX 0x818D +#endif + +#ifndef GL_SGIX_tag_sample_buffer +#endif + +#ifndef GL_FfdMaskSGIX +#define GL_TEXTURE_DEFORMATION_BIT_SGIX 0x00000001 +#define GL_GEOMETRY_DEFORMATION_BIT_SGIX 0x00000002 +#endif + +#ifndef GL_SGIX_polynomial_ffd +#define GL_GEOMETRY_DEFORMATION_SGIX 0x8194 +#define GL_TEXTURE_DEFORMATION_SGIX 0x8195 +#define GL_DEFORMATIONS_MASK_SGIX 0x8196 +#define GL_MAX_DEFORMATION_ORDER_SGIX 0x8197 +#endif + +#ifndef GL_SGIX_reference_plane +#define GL_REFERENCE_PLANE_SGIX 0x817D +#define GL_REFERENCE_PLANE_EQUATION_SGIX 0x817E +#endif + +#ifndef GL_SGIX_flush_raster +#endif + +#ifndef GL_SGIX_depth_texture +#define GL_DEPTH_COMPONENT16_SGIX 0x81A5 +#define GL_DEPTH_COMPONENT24_SGIX 0x81A6 +#define GL_DEPTH_COMPONENT32_SGIX 0x81A7 +#endif + +#ifndef GL_SGIS_fog_function +#define GL_FOG_FUNC_SGIS 0x812A +#define GL_FOG_FUNC_POINTS_SGIS 0x812B +#define GL_MAX_FOG_FUNC_POINTS_SGIS 0x812C +#endif + +#ifndef GL_SGIX_fog_offset +#define GL_FOG_OFFSET_SGIX 0x8198 +#define GL_FOG_OFFSET_VALUE_SGIX 0x8199 +#endif + +#ifndef GL_HP_image_transform +#define GL_IMAGE_SCALE_X_HP 0x8155 +#define GL_IMAGE_SCALE_Y_HP 0x8156 +#define GL_IMAGE_TRANSLATE_X_HP 0x8157 +#define GL_IMAGE_TRANSLATE_Y_HP 0x8158 +#define GL_IMAGE_ROTATE_ANGLE_HP 0x8159 +#define GL_IMAGE_ROTATE_ORIGIN_X_HP 0x815A +#define GL_IMAGE_ROTATE_ORIGIN_Y_HP 0x815B +#define GL_IMAGE_MAG_FILTER_HP 0x815C +#define GL_IMAGE_MIN_FILTER_HP 0x815D +#define GL_IMAGE_CUBIC_WEIGHT_HP 0x815E +#define GL_CUBIC_HP 0x815F +#define GL_AVERAGE_HP 0x8160 +#define GL_IMAGE_TRANSFORM_2D_HP 0x8161 +#define GL_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8162 +#define GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8163 +#endif + +#ifndef GL_HP_convolution_border_modes +#define GL_IGNORE_BORDER_HP 0x8150 +#define GL_CONSTANT_BORDER_HP 0x8151 +#define GL_REPLICATE_BORDER_HP 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR_HP 0x8154 +#endif + +#ifndef GL_INGR_palette_buffer +#endif + +#ifndef GL_SGIX_texture_add_env +#define GL_TEXTURE_ENV_BIAS_SGIX 0x80BE +#endif + +#ifndef GL_EXT_color_subtable +#endif + +#ifndef GL_PGI_vertex_hints +#define GL_VERTEX_DATA_HINT_PGI 0x1A22A +#define GL_VERTEX_CONSISTENT_HINT_PGI 0x1A22B +#define GL_MATERIAL_SIDE_HINT_PGI 0x1A22C +#define GL_MAX_VERTEX_HINT_PGI 0x1A22D +#define GL_COLOR3_BIT_PGI 0x00010000 +#define GL_COLOR4_BIT_PGI 0x00020000 +#define GL_EDGEFLAG_BIT_PGI 0x00040000 +#define GL_INDEX_BIT_PGI 0x00080000 +#define GL_MAT_AMBIENT_BIT_PGI 0x00100000 +#define GL_MAT_AMBIENT_AND_DIFFUSE_BIT_PGI 0x00200000 +#define GL_MAT_DIFFUSE_BIT_PGI 0x00400000 +#define GL_MAT_EMISSION_BIT_PGI 0x00800000 +#define GL_MAT_COLOR_INDEXES_BIT_PGI 0x01000000 +#define GL_MAT_SHININESS_BIT_PGI 0x02000000 +#define GL_MAT_SPECULAR_BIT_PGI 0x04000000 +#define GL_NORMAL_BIT_PGI 0x08000000 +#define GL_TEXCOORD1_BIT_PGI 0x10000000 +#define GL_TEXCOORD2_BIT_PGI 0x20000000 +#define GL_TEXCOORD3_BIT_PGI 0x40000000 +#define GL_TEXCOORD4_BIT_PGI 0x80000000 +#define GL_VERTEX23_BIT_PGI 0x00000004 +#define GL_VERTEX4_BIT_PGI 0x00000008 +#endif + +#ifndef GL_PGI_misc_hints +#define GL_PREFER_DOUBLEBUFFER_HINT_PGI 0x1A1F8 +#define GL_CONSERVE_MEMORY_HINT_PGI 0x1A1FD +#define GL_RECLAIM_MEMORY_HINT_PGI 0x1A1FE +#define GL_NATIVE_GRAPHICS_HANDLE_PGI 0x1A202 +#define GL_NATIVE_GRAPHICS_BEGIN_HINT_PGI 0x1A203 +#define GL_NATIVE_GRAPHICS_END_HINT_PGI 0x1A204 +#define GL_ALWAYS_FAST_HINT_PGI 0x1A20C +#define GL_ALWAYS_SOFT_HINT_PGI 0x1A20D +#define GL_ALLOW_DRAW_OBJ_HINT_PGI 0x1A20E +#define GL_ALLOW_DRAW_WIN_HINT_PGI 0x1A20F +#define GL_ALLOW_DRAW_FRG_HINT_PGI 0x1A210 +#define GL_ALLOW_DRAW_MEM_HINT_PGI 0x1A211 +#define GL_STRICT_DEPTHFUNC_HINT_PGI 0x1A216 +#define GL_STRICT_LIGHTING_HINT_PGI 0x1A217 +#define GL_STRICT_SCISSOR_HINT_PGI 0x1A218 +#define GL_FULL_STIPPLE_HINT_PGI 0x1A219 +#define GL_CLIP_NEAR_HINT_PGI 0x1A220 +#define GL_CLIP_FAR_HINT_PGI 0x1A221 +#define GL_WIDE_LINE_HINT_PGI 0x1A222 +#define GL_BACK_NORMALS_HINT_PGI 0x1A223 +#endif + +#ifndef GL_EXT_paletted_texture +#define GL_COLOR_INDEX1_EXT 0x80E2 +#define GL_COLOR_INDEX2_EXT 0x80E3 +#define GL_COLOR_INDEX4_EXT 0x80E4 +#define GL_COLOR_INDEX8_EXT 0x80E5 +#define GL_COLOR_INDEX12_EXT 0x80E6 +#define GL_COLOR_INDEX16_EXT 0x80E7 +#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED +#endif + +#ifndef GL_EXT_clip_volume_hint +#define GL_CLIP_VOLUME_CLIPPING_HINT_EXT 0x80F0 +#endif + +#ifndef GL_SGIX_list_priority +#define GL_LIST_PRIORITY_SGIX 0x8182 +#endif + +#ifndef GL_SGIX_ir_instrument1 +#define GL_IR_INSTRUMENT1_SGIX 0x817F +#endif + +#ifndef GL_SGIX_calligraphic_fragment +#define GL_CALLIGRAPHIC_FRAGMENT_SGIX 0x8183 +#endif + +#ifndef GL_SGIX_texture_lod_bias +#define GL_TEXTURE_LOD_BIAS_S_SGIX 0x818E +#define GL_TEXTURE_LOD_BIAS_T_SGIX 0x818F +#define GL_TEXTURE_LOD_BIAS_R_SGIX 0x8190 +#endif + +#ifndef GL_SGIX_shadow_ambient +#define GL_SHADOW_AMBIENT_SGIX 0x80BF +#endif + +#ifndef GL_EXT_index_texture +#endif + +#ifndef GL_EXT_index_material +#define GL_INDEX_MATERIAL_EXT 0x81B8 +#define GL_INDEX_MATERIAL_PARAMETER_EXT 0x81B9 +#define GL_INDEX_MATERIAL_FACE_EXT 0x81BA +#endif + +#ifndef GL_EXT_index_func +#define GL_INDEX_TEST_EXT 0x81B5 +#define GL_INDEX_TEST_FUNC_EXT 0x81B6 +#define GL_INDEX_TEST_REF_EXT 0x81B7 +#endif + +#ifndef GL_EXT_index_array_formats +#define GL_IUI_V2F_EXT 0x81AD +#define GL_IUI_V3F_EXT 0x81AE +#define GL_IUI_N3F_V2F_EXT 0x81AF +#define GL_IUI_N3F_V3F_EXT 0x81B0 +#define GL_T2F_IUI_V2F_EXT 0x81B1 +#define GL_T2F_IUI_V3F_EXT 0x81B2 +#define GL_T2F_IUI_N3F_V2F_EXT 0x81B3 +#define GL_T2F_IUI_N3F_V3F_EXT 0x81B4 +#endif + +#ifndef GL_EXT_compiled_vertex_array +#define GL_ARRAY_ELEMENT_LOCK_FIRST_EXT 0x81A8 +#define GL_ARRAY_ELEMENT_LOCK_COUNT_EXT 0x81A9 +#endif + +#ifndef GL_EXT_cull_vertex +#define GL_CULL_VERTEX_EXT 0x81AA +#define GL_CULL_VERTEX_EYE_POSITION_EXT 0x81AB +#define GL_CULL_VERTEX_OBJECT_POSITION_EXT 0x81AC +#endif + +#ifndef GL_SGIX_ycrcb +#define GL_YCRCB_422_SGIX 0x81BB +#define GL_YCRCB_444_SGIX 0x81BC +#endif + +#ifndef GL_SGIX_fragment_lighting +#define GL_FRAGMENT_LIGHTING_SGIX 0x8400 +#define GL_FRAGMENT_COLOR_MATERIAL_SGIX 0x8401 +#define GL_FRAGMENT_COLOR_MATERIAL_FACE_SGIX 0x8402 +#define GL_FRAGMENT_COLOR_MATERIAL_PARAMETER_SGIX 0x8403 +#define GL_MAX_FRAGMENT_LIGHTS_SGIX 0x8404 +#define GL_MAX_ACTIVE_LIGHTS_SGIX 0x8405 +#define GL_CURRENT_RASTER_NORMAL_SGIX 0x8406 +#define GL_LIGHT_ENV_MODE_SGIX 0x8407 +#define GL_FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX 0x8408 +#define GL_FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX 0x8409 +#define GL_FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX 0x840A +#define GL_FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX 0x840B +#define GL_FRAGMENT_LIGHT0_SGIX 0x840C +#define GL_FRAGMENT_LIGHT1_SGIX 0x840D +#define GL_FRAGMENT_LIGHT2_SGIX 0x840E +#define GL_FRAGMENT_LIGHT3_SGIX 0x840F +#define GL_FRAGMENT_LIGHT4_SGIX 0x8410 +#define GL_FRAGMENT_LIGHT5_SGIX 0x8411 +#define GL_FRAGMENT_LIGHT6_SGIX 0x8412 +#define GL_FRAGMENT_LIGHT7_SGIX 0x8413 +#endif + +#ifndef GL_IBM_rasterpos_clip +#define GL_RASTER_POSITION_UNCLIPPED_IBM 0x19262 +#endif + +#ifndef GL_HP_texture_lighting +#define GL_TEXTURE_LIGHTING_MODE_HP 0x8167 +#define GL_TEXTURE_POST_SPECULAR_HP 0x8168 +#define GL_TEXTURE_PRE_SPECULAR_HP 0x8169 +#endif + +#ifndef GL_EXT_draw_range_elements +#define GL_MAX_ELEMENTS_VERTICES_EXT 0x80E8 +#define GL_MAX_ELEMENTS_INDICES_EXT 0x80E9 +#endif + +#ifndef GL_WIN_phong_shading +#define GL_PHONG_WIN 0x80EA +#define GL_PHONG_HINT_WIN 0x80EB +#endif + +#ifndef GL_WIN_specular_fog +#define GL_FOG_SPECULAR_TEXTURE_WIN 0x80EC +#endif + +#ifndef GL_EXT_light_texture +#define GL_FRAGMENT_MATERIAL_EXT 0x8349 +#define GL_FRAGMENT_NORMAL_EXT 0x834A +#define GL_FRAGMENT_COLOR_EXT 0x834C +#define GL_ATTENUATION_EXT 0x834D +#define GL_SHADOW_ATTENUATION_EXT 0x834E +#define GL_TEXTURE_APPLICATION_MODE_EXT 0x834F +#define GL_TEXTURE_LIGHT_EXT 0x8350 +#define GL_TEXTURE_MATERIAL_FACE_EXT 0x8351 +#define GL_TEXTURE_MATERIAL_PARAMETER_EXT 0x8352 +/* reuse GL_FRAGMENT_DEPTH_EXT */ +#endif + +#ifndef GL_SGIX_blend_alpha_minmax +#define GL_ALPHA_MIN_SGIX 0x8320 +#define GL_ALPHA_MAX_SGIX 0x8321 +#endif + +#ifndef GL_SGIX_impact_pixel_texture +#define GL_PIXEL_TEX_GEN_Q_CEILING_SGIX 0x8184 +#define GL_PIXEL_TEX_GEN_Q_ROUND_SGIX 0x8185 +#define GL_PIXEL_TEX_GEN_Q_FLOOR_SGIX 0x8186 +#define GL_PIXEL_TEX_GEN_ALPHA_REPLACE_SGIX 0x8187 +#define GL_PIXEL_TEX_GEN_ALPHA_NO_REPLACE_SGIX 0x8188 +#define GL_PIXEL_TEX_GEN_ALPHA_LS_SGIX 0x8189 +#define GL_PIXEL_TEX_GEN_ALPHA_MS_SGIX 0x818A +#endif + +#ifndef GL_EXT_bgra +#define GL_BGR_EXT 0x80E0 +#define GL_BGRA_EXT 0x80E1 +#endif + +#ifndef GL_SGIX_async +#define GL_ASYNC_MARKER_SGIX 0x8329 +#endif + +#ifndef GL_SGIX_async_pixel +#define GL_ASYNC_TEX_IMAGE_SGIX 0x835C +#define GL_ASYNC_DRAW_PIXELS_SGIX 0x835D +#define GL_ASYNC_READ_PIXELS_SGIX 0x835E +#define GL_MAX_ASYNC_TEX_IMAGE_SGIX 0x835F +#define GL_MAX_ASYNC_DRAW_PIXELS_SGIX 0x8360 +#define GL_MAX_ASYNC_READ_PIXELS_SGIX 0x8361 +#endif + +#ifndef GL_SGIX_async_histogram +#define GL_ASYNC_HISTOGRAM_SGIX 0x832C +#define GL_MAX_ASYNC_HISTOGRAM_SGIX 0x832D +#endif + +#ifndef GL_INTEL_texture_scissor +#endif + +#ifndef GL_INTEL_parallel_arrays +#define GL_PARALLEL_ARRAYS_INTEL 0x83F4 +#define GL_VERTEX_ARRAY_PARALLEL_POINTERS_INTEL 0x83F5 +#define GL_NORMAL_ARRAY_PARALLEL_POINTERS_INTEL 0x83F6 +#define GL_COLOR_ARRAY_PARALLEL_POINTERS_INTEL 0x83F7 +#define GL_TEXTURE_COORD_ARRAY_PARALLEL_POINTERS_INTEL 0x83F8 +#endif + +#ifndef GL_HP_occlusion_test +#define GL_OCCLUSION_TEST_HP 0x8165 +#define GL_OCCLUSION_TEST_RESULT_HP 0x8166 +#endif + +#ifndef GL_EXT_pixel_transform +#define GL_PIXEL_TRANSFORM_2D_EXT 0x8330 +#define GL_PIXEL_MAG_FILTER_EXT 0x8331 +#define GL_PIXEL_MIN_FILTER_EXT 0x8332 +#define GL_PIXEL_CUBIC_WEIGHT_EXT 0x8333 +#define GL_CUBIC_EXT 0x8334 +#define GL_AVERAGE_EXT 0x8335 +#define GL_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8336 +#define GL_MAX_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8337 +#define GL_PIXEL_TRANSFORM_2D_MATRIX_EXT 0x8338 +#endif + +#ifndef GL_EXT_pixel_transform_color_table +#endif + +#ifndef GL_EXT_shared_texture_palette +#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB +#endif + +#ifndef GL_EXT_separate_specular_color +#define GL_LIGHT_MODEL_COLOR_CONTROL_EXT 0x81F8 +#define GL_SINGLE_COLOR_EXT 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR_EXT 0x81FA +#endif + +#ifndef GL_EXT_secondary_color +#define GL_COLOR_SUM_EXT 0x8458 +#define GL_CURRENT_SECONDARY_COLOR_EXT 0x8459 +#define GL_SECONDARY_COLOR_ARRAY_SIZE_EXT 0x845A +#define GL_SECONDARY_COLOR_ARRAY_TYPE_EXT 0x845B +#define GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT 0x845C +#define GL_SECONDARY_COLOR_ARRAY_POINTER_EXT 0x845D +#define GL_SECONDARY_COLOR_ARRAY_EXT 0x845E +#endif + +#ifndef GL_EXT_texture_perturb_normal +#define GL_PERTURB_EXT 0x85AE +#define GL_TEXTURE_NORMAL_EXT 0x85AF +#endif + +#ifndef GL_EXT_multi_draw_arrays +#endif + +#ifndef GL_EXT_fog_coord +#define GL_FOG_COORDINATE_SOURCE_EXT 0x8450 +#define GL_FOG_COORDINATE_EXT 0x8451 +#define GL_FRAGMENT_DEPTH_EXT 0x8452 +#define GL_CURRENT_FOG_COORDINATE_EXT 0x8453 +#define GL_FOG_COORDINATE_ARRAY_TYPE_EXT 0x8454 +#define GL_FOG_COORDINATE_ARRAY_STRIDE_EXT 0x8455 +#define GL_FOG_COORDINATE_ARRAY_POINTER_EXT 0x8456 +#define GL_FOG_COORDINATE_ARRAY_EXT 0x8457 +#endif + +#ifndef GL_REND_screen_coordinates +#define GL_SCREEN_COORDINATES_REND 0x8490 +#define GL_INVERTED_SCREEN_W_REND 0x8491 +#endif + +#ifndef GL_EXT_coordinate_frame +#define GL_TANGENT_ARRAY_EXT 0x8439 +#define GL_BINORMAL_ARRAY_EXT 0x843A +#define GL_CURRENT_TANGENT_EXT 0x843B +#define GL_CURRENT_BINORMAL_EXT 0x843C +#define GL_TANGENT_ARRAY_TYPE_EXT 0x843E +#define GL_TANGENT_ARRAY_STRIDE_EXT 0x843F +#define GL_BINORMAL_ARRAY_TYPE_EXT 0x8440 +#define GL_BINORMAL_ARRAY_STRIDE_EXT 0x8441 +#define GL_TANGENT_ARRAY_POINTER_EXT 0x8442 +#define GL_BINORMAL_ARRAY_POINTER_EXT 0x8443 +#define GL_MAP1_TANGENT_EXT 0x8444 +#define GL_MAP2_TANGENT_EXT 0x8445 +#define GL_MAP1_BINORMAL_EXT 0x8446 +#define GL_MAP2_BINORMAL_EXT 0x8447 +#endif + +#ifndef GL_EXT_texture_env_combine +#define GL_COMBINE_EXT 0x8570 +#define GL_COMBINE_RGB_EXT 0x8571 +#define GL_COMBINE_ALPHA_EXT 0x8572 +#define GL_RGB_SCALE_EXT 0x8573 +#define GL_ADD_SIGNED_EXT 0x8574 +#define GL_INTERPOLATE_EXT 0x8575 +#define GL_CONSTANT_EXT 0x8576 +#define GL_PRIMARY_COLOR_EXT 0x8577 +#define GL_PREVIOUS_EXT 0x8578 +#define GL_SOURCE0_RGB_EXT 0x8580 +#define GL_SOURCE1_RGB_EXT 0x8581 +#define GL_SOURCE2_RGB_EXT 0x8582 +#define GL_SOURCE0_ALPHA_EXT 0x8588 +#define GL_SOURCE1_ALPHA_EXT 0x8589 +#define GL_SOURCE2_ALPHA_EXT 0x858A +#define GL_OPERAND0_RGB_EXT 0x8590 +#define GL_OPERAND1_RGB_EXT 0x8591 +#define GL_OPERAND2_RGB_EXT 0x8592 +#define GL_OPERAND0_ALPHA_EXT 0x8598 +#define GL_OPERAND1_ALPHA_EXT 0x8599 +#define GL_OPERAND2_ALPHA_EXT 0x859A +#endif + +#ifndef GL_APPLE_specular_vector +#define GL_LIGHT_MODEL_SPECULAR_VECTOR_APPLE 0x85B0 +#endif + +#ifndef GL_APPLE_transform_hint +#define GL_TRANSFORM_HINT_APPLE 0x85B1 +#endif + +#ifndef GL_SGIX_fog_scale +#define GL_FOG_SCALE_SGIX 0x81FC +#define GL_FOG_SCALE_VALUE_SGIX 0x81FD +#endif + +#ifndef GL_SUNX_constant_data +#define GL_UNPACK_CONSTANT_DATA_SUNX 0x81D5 +#define GL_TEXTURE_CONSTANT_DATA_SUNX 0x81D6 +#endif + +#ifndef GL_SUN_global_alpha +#define GL_GLOBAL_ALPHA_SUN 0x81D9 +#define GL_GLOBAL_ALPHA_FACTOR_SUN 0x81DA +#endif + +#ifndef GL_SUN_triangle_list +#define GL_RESTART_SUN 0x0001 +#define GL_REPLACE_MIDDLE_SUN 0x0002 +#define GL_REPLACE_OLDEST_SUN 0x0003 +#define GL_TRIANGLE_LIST_SUN 0x81D7 +#define GL_REPLACEMENT_CODE_SUN 0x81D8 +#define GL_REPLACEMENT_CODE_ARRAY_SUN 0x85C0 +#define GL_REPLACEMENT_CODE_ARRAY_TYPE_SUN 0x85C1 +#define GL_REPLACEMENT_CODE_ARRAY_STRIDE_SUN 0x85C2 +#define GL_REPLACEMENT_CODE_ARRAY_POINTER_SUN 0x85C3 +#define GL_R1UI_V3F_SUN 0x85C4 +#define GL_R1UI_C4UB_V3F_SUN 0x85C5 +#define GL_R1UI_C3F_V3F_SUN 0x85C6 +#define GL_R1UI_N3F_V3F_SUN 0x85C7 +#define GL_R1UI_C4F_N3F_V3F_SUN 0x85C8 +#define GL_R1UI_T2F_V3F_SUN 0x85C9 +#define GL_R1UI_T2F_N3F_V3F_SUN 0x85CA +#define GL_R1UI_T2F_C4F_N3F_V3F_SUN 0x85CB +#endif + +#ifndef GL_SUN_vertex +#endif + +#ifndef GL_EXT_blend_func_separate +#define GL_BLEND_DST_RGB_EXT 0x80C8 +#define GL_BLEND_SRC_RGB_EXT 0x80C9 +#define GL_BLEND_DST_ALPHA_EXT 0x80CA +#define GL_BLEND_SRC_ALPHA_EXT 0x80CB +#endif + +#ifndef GL_INGR_color_clamp +#define GL_RED_MIN_CLAMP_INGR 0x8560 +#define GL_GREEN_MIN_CLAMP_INGR 0x8561 +#define GL_BLUE_MIN_CLAMP_INGR 0x8562 +#define GL_ALPHA_MIN_CLAMP_INGR 0x8563 +#define GL_RED_MAX_CLAMP_INGR 0x8564 +#define GL_GREEN_MAX_CLAMP_INGR 0x8565 +#define GL_BLUE_MAX_CLAMP_INGR 0x8566 +#define GL_ALPHA_MAX_CLAMP_INGR 0x8567 +#endif + +#ifndef GL_INGR_interlace_read +#define GL_INTERLACE_READ_INGR 0x8568 +#endif + +#ifndef GL_EXT_stencil_wrap +#define GL_INCR_WRAP_EXT 0x8507 +#define GL_DECR_WRAP_EXT 0x8508 +#endif + +#ifndef GL_EXT_422_pixels +#define GL_422_EXT 0x80CC +#define GL_422_REV_EXT 0x80CD +#define GL_422_AVERAGE_EXT 0x80CE +#define GL_422_REV_AVERAGE_EXT 0x80CF +#endif + +#ifndef GL_NV_texgen_reflection +#define GL_NORMAL_MAP_NV 0x8511 +#define GL_REFLECTION_MAP_NV 0x8512 +#endif + +#ifndef GL_EXT_texture_cube_map +#define GL_NORMAL_MAP_EXT 0x8511 +#define GL_REFLECTION_MAP_EXT 0x8512 +#define GL_TEXTURE_CUBE_MAP_EXT 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_EXT 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP_EXT 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_EXT 0x851C +#endif + +#ifndef GL_SUN_convolution_border_modes +#define GL_WRAP_BORDER_SUN 0x81D4 +#endif + +#ifndef GL_EXT_texture_env_add +#endif + +#ifndef GL_EXT_texture_lod_bias +#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD +#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500 +#define GL_TEXTURE_LOD_BIAS_EXT 0x8501 +#endif + +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif + +#ifndef GL_EXT_vertex_weighting +#define GL_MODELVIEW0_STACK_DEPTH_EXT GL_MODELVIEW_STACK_DEPTH +#define GL_MODELVIEW1_STACK_DEPTH_EXT 0x8502 +#define GL_MODELVIEW0_MATRIX_EXT GL_MODELVIEW_MATRIX +#define GL_MODELVIEW1_MATRIX_EXT 0x8506 +#define GL_VERTEX_WEIGHTING_EXT 0x8509 +#define GL_MODELVIEW0_EXT GL_MODELVIEW +#define GL_MODELVIEW1_EXT 0x850A +#define GL_CURRENT_VERTEX_WEIGHT_EXT 0x850B +#define GL_VERTEX_WEIGHT_ARRAY_EXT 0x850C +#define GL_VERTEX_WEIGHT_ARRAY_SIZE_EXT 0x850D +#define GL_VERTEX_WEIGHT_ARRAY_TYPE_EXT 0x850E +#define GL_VERTEX_WEIGHT_ARRAY_STRIDE_EXT 0x850F +#define GL_VERTEX_WEIGHT_ARRAY_POINTER_EXT 0x8510 +#endif + +#ifndef GL_NV_light_max_exponent +#define GL_MAX_SHININESS_NV 0x8504 +#define GL_MAX_SPOT_EXPONENT_NV 0x8505 +#endif + +#ifndef GL_NV_vertex_array_range +#define GL_VERTEX_ARRAY_RANGE_NV 0x851D +#define GL_VERTEX_ARRAY_RANGE_LENGTH_NV 0x851E +#define GL_VERTEX_ARRAY_RANGE_VALID_NV 0x851F +#define GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_NV 0x8520 +#define GL_VERTEX_ARRAY_RANGE_POINTER_NV 0x8521 +#endif + +#ifndef GL_NV_register_combiners +#define GL_REGISTER_COMBINERS_NV 0x8522 +#define GL_VARIABLE_A_NV 0x8523 +#define GL_VARIABLE_B_NV 0x8524 +#define GL_VARIABLE_C_NV 0x8525 +#define GL_VARIABLE_D_NV 0x8526 +#define GL_VARIABLE_E_NV 0x8527 +#define GL_VARIABLE_F_NV 0x8528 +#define GL_VARIABLE_G_NV 0x8529 +#define GL_CONSTANT_COLOR0_NV 0x852A +#define GL_CONSTANT_COLOR1_NV 0x852B +#define GL_PRIMARY_COLOR_NV 0x852C +#define GL_SECONDARY_COLOR_NV 0x852D +#define GL_SPARE0_NV 0x852E +#define GL_SPARE1_NV 0x852F +#define GL_DISCARD_NV 0x8530 +#define GL_E_TIMES_F_NV 0x8531 +#define GL_SPARE0_PLUS_SECONDARY_COLOR_NV 0x8532 +#define GL_UNSIGNED_IDENTITY_NV 0x8536 +#define GL_UNSIGNED_INVERT_NV 0x8537 +#define GL_EXPAND_NORMAL_NV 0x8538 +#define GL_EXPAND_NEGATE_NV 0x8539 +#define GL_HALF_BIAS_NORMAL_NV 0x853A +#define GL_HALF_BIAS_NEGATE_NV 0x853B +#define GL_SIGNED_IDENTITY_NV 0x853C +#define GL_SIGNED_NEGATE_NV 0x853D +#define GL_SCALE_BY_TWO_NV 0x853E +#define GL_SCALE_BY_FOUR_NV 0x853F +#define GL_SCALE_BY_ONE_HALF_NV 0x8540 +#define GL_BIAS_BY_NEGATIVE_ONE_HALF_NV 0x8541 +#define GL_COMBINER_INPUT_NV 0x8542 +#define GL_COMBINER_MAPPING_NV 0x8543 +#define GL_COMBINER_COMPONENT_USAGE_NV 0x8544 +#define GL_COMBINER_AB_DOT_PRODUCT_NV 0x8545 +#define GL_COMBINER_CD_DOT_PRODUCT_NV 0x8546 +#define GL_COMBINER_MUX_SUM_NV 0x8547 +#define GL_COMBINER_SCALE_NV 0x8548 +#define GL_COMBINER_BIAS_NV 0x8549 +#define GL_COMBINER_AB_OUTPUT_NV 0x854A +#define GL_COMBINER_CD_OUTPUT_NV 0x854B +#define GL_COMBINER_SUM_OUTPUT_NV 0x854C +#define GL_MAX_GENERAL_COMBINERS_NV 0x854D +#define GL_NUM_GENERAL_COMBINERS_NV 0x854E +#define GL_COLOR_SUM_CLAMP_NV 0x854F +#define GL_COMBINER0_NV 0x8550 +#define GL_COMBINER1_NV 0x8551 +#define GL_COMBINER2_NV 0x8552 +#define GL_COMBINER3_NV 0x8553 +#define GL_COMBINER4_NV 0x8554 +#define GL_COMBINER5_NV 0x8555 +#define GL_COMBINER6_NV 0x8556 +#define GL_COMBINER7_NV 0x8557 +/* reuse GL_TEXTURE0_ARB */ +/* reuse GL_TEXTURE1_ARB */ +/* reuse GL_ZERO */ +/* reuse GL_NONE */ +/* reuse GL_FOG */ +#endif + +#ifndef GL_NV_fog_distance +#define GL_FOG_DISTANCE_MODE_NV 0x855A +#define GL_EYE_RADIAL_NV 0x855B +#define GL_EYE_PLANE_ABSOLUTE_NV 0x855C +/* reuse GL_EYE_PLANE */ +#endif + +#ifndef GL_NV_texgen_emboss +#define GL_EMBOSS_LIGHT_NV 0x855D +#define GL_EMBOSS_CONSTANT_NV 0x855E +#define GL_EMBOSS_MAP_NV 0x855F +#endif + +#ifndef GL_NV_blend_square +#endif + +#ifndef GL_NV_texture_env_combine4 +#define GL_COMBINE4_NV 0x8503 +#define GL_SOURCE3_RGB_NV 0x8583 +#define GL_SOURCE3_ALPHA_NV 0x858B +#define GL_OPERAND3_RGB_NV 0x8593 +#define GL_OPERAND3_ALPHA_NV 0x859B +#endif + +#ifndef GL_MESA_resize_buffers +#endif + +#ifndef GL_MESA_window_pos +#endif + +#ifndef GL_EXT_texture_compression_s3tc +#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 +#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 +#endif + +#ifndef GL_IBM_cull_vertex +#define GL_CULL_VERTEX_IBM 103050 +#endif + +#ifndef GL_IBM_multimode_draw_arrays +#endif + +#ifndef GL_IBM_vertex_array_lists +#define GL_VERTEX_ARRAY_LIST_IBM 103070 +#define GL_NORMAL_ARRAY_LIST_IBM 103071 +#define GL_COLOR_ARRAY_LIST_IBM 103072 +#define GL_INDEX_ARRAY_LIST_IBM 103073 +#define GL_TEXTURE_COORD_ARRAY_LIST_IBM 103074 +#define GL_EDGE_FLAG_ARRAY_LIST_IBM 103075 +#define GL_FOG_COORDINATE_ARRAY_LIST_IBM 103076 +#define GL_SECONDARY_COLOR_ARRAY_LIST_IBM 103077 +#define GL_VERTEX_ARRAY_LIST_STRIDE_IBM 103080 +#define GL_NORMAL_ARRAY_LIST_STRIDE_IBM 103081 +#define GL_COLOR_ARRAY_LIST_STRIDE_IBM 103082 +#define GL_INDEX_ARRAY_LIST_STRIDE_IBM 103083 +#define GL_TEXTURE_COORD_ARRAY_LIST_STRIDE_IBM 103084 +#define GL_EDGE_FLAG_ARRAY_LIST_STRIDE_IBM 103085 +#define GL_FOG_COORDINATE_ARRAY_LIST_STRIDE_IBM 103086 +#define GL_SECONDARY_COLOR_ARRAY_LIST_STRIDE_IBM 103087 +#endif + +#ifndef GL_SGIX_subsample +#define GL_PACK_SUBSAMPLE_RATE_SGIX 0x85A0 +#define GL_UNPACK_SUBSAMPLE_RATE_SGIX 0x85A1 +#define GL_PIXEL_SUBSAMPLE_4444_SGIX 0x85A2 +#define GL_PIXEL_SUBSAMPLE_2424_SGIX 0x85A3 +#define GL_PIXEL_SUBSAMPLE_4242_SGIX 0x85A4 +#endif + +#ifndef GL_SGIX_ycrcb_subsample +#endif + +#ifndef GL_SGIX_ycrcba +#define GL_YCRCB_SGIX 0x8318 +#define GL_YCRCBA_SGIX 0x8319 +#endif + +#ifndef GL_SGI_depth_pass_instrument +#define GL_DEPTH_PASS_INSTRUMENT_SGIX 0x8310 +#define GL_DEPTH_PASS_INSTRUMENT_COUNTERS_SGIX 0x8311 +#define GL_DEPTH_PASS_INSTRUMENT_MAX_SGIX 0x8312 +#endif + +#ifndef GL_3DFX_texture_compression_FXT1 +#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0 +#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1 +#endif + +#ifndef GL_3DFX_multisample +#define GL_MULTISAMPLE_3DFX 0x86B2 +#define GL_SAMPLE_BUFFERS_3DFX 0x86B3 +#define GL_SAMPLES_3DFX 0x86B4 +#define GL_MULTISAMPLE_BIT_3DFX 0x20000000 +#endif + +#ifndef GL_3DFX_tbuffer +#endif + +#ifndef GL_EXT_multisample +#define GL_MULTISAMPLE_EXT 0x809D +#define GL_SAMPLE_ALPHA_TO_MASK_EXT 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_EXT 0x809F +#define GL_SAMPLE_MASK_EXT 0x80A0 +#define GL_1PASS_EXT 0x80A1 +#define GL_2PASS_0_EXT 0x80A2 +#define GL_2PASS_1_EXT 0x80A3 +#define GL_4PASS_0_EXT 0x80A4 +#define GL_4PASS_1_EXT 0x80A5 +#define GL_4PASS_2_EXT 0x80A6 +#define GL_4PASS_3_EXT 0x80A7 +#define GL_SAMPLE_BUFFERS_EXT 0x80A8 +#define GL_SAMPLES_EXT 0x80A9 +#define GL_SAMPLE_MASK_VALUE_EXT 0x80AA +#define GL_SAMPLE_MASK_INVERT_EXT 0x80AB +#define GL_SAMPLE_PATTERN_EXT 0x80AC +#define GL_MULTISAMPLE_BIT_EXT 0x20000000 +#endif + +#ifndef GL_SGIX_vertex_preclip +#define GL_VERTEX_PRECLIP_SGIX 0x83EE +#define GL_VERTEX_PRECLIP_HINT_SGIX 0x83EF +#endif + +#ifndef GL_SGIX_convolution_accuracy +#define GL_CONVOLUTION_HINT_SGIX 0x8316 +#endif + +#ifndef GL_SGIX_resample +#define GL_PACK_RESAMPLE_SGIX 0x842C +#define GL_UNPACK_RESAMPLE_SGIX 0x842D +#define GL_RESAMPLE_REPLICATE_SGIX 0x842E +#define GL_RESAMPLE_ZERO_FILL_SGIX 0x842F +#define GL_RESAMPLE_DECIMATE_SGIX 0x8430 +#endif + +#ifndef GL_SGIS_point_line_texgen +#define GL_EYE_DISTANCE_TO_POINT_SGIS 0x81F0 +#define GL_OBJECT_DISTANCE_TO_POINT_SGIS 0x81F1 +#define GL_EYE_DISTANCE_TO_LINE_SGIS 0x81F2 +#define GL_OBJECT_DISTANCE_TO_LINE_SGIS 0x81F3 +#define GL_EYE_POINT_SGIS 0x81F4 +#define GL_OBJECT_POINT_SGIS 0x81F5 +#define GL_EYE_LINE_SGIS 0x81F6 +#define GL_OBJECT_LINE_SGIS 0x81F7 +#endif + +#ifndef GL_SGIS_texture_color_mask +#define GL_TEXTURE_COLOR_WRITEMASK_SGIS 0x81EF +#endif + +#ifndef GL_EXT_texture_env_dot3 +#define GL_DOT3_RGB_EXT 0x8740 +#define GL_DOT3_RGBA_EXT 0x8741 +#endif + +#ifndef GL_ATI_texture_mirror_once +#define GL_MIRROR_CLAMP_ATI 0x8742 +#define GL_MIRROR_CLAMP_TO_EDGE_ATI 0x8743 +#endif + +#ifndef GL_NV_fence +#define GL_ALL_COMPLETED_NV 0x84F2 +#define GL_FENCE_STATUS_NV 0x84F3 +#define GL_FENCE_CONDITION_NV 0x84F4 +#endif + +#ifndef GL_IBM_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_IBM 0x8370 +#endif + +#ifndef GL_NV_evaluators +#define GL_EVAL_2D_NV 0x86C0 +#define GL_EVAL_TRIANGULAR_2D_NV 0x86C1 +#define GL_MAP_TESSELLATION_NV 0x86C2 +#define GL_MAP_ATTRIB_U_ORDER_NV 0x86C3 +#define GL_MAP_ATTRIB_V_ORDER_NV 0x86C4 +#define GL_EVAL_FRACTIONAL_TESSELLATION_NV 0x86C5 +#define GL_EVAL_VERTEX_ATTRIB0_NV 0x86C6 +#define GL_EVAL_VERTEX_ATTRIB1_NV 0x86C7 +#define GL_EVAL_VERTEX_ATTRIB2_NV 0x86C8 +#define GL_EVAL_VERTEX_ATTRIB3_NV 0x86C9 +#define GL_EVAL_VERTEX_ATTRIB4_NV 0x86CA +#define GL_EVAL_VERTEX_ATTRIB5_NV 0x86CB +#define GL_EVAL_VERTEX_ATTRIB6_NV 0x86CC +#define GL_EVAL_VERTEX_ATTRIB7_NV 0x86CD +#define GL_EVAL_VERTEX_ATTRIB8_NV 0x86CE +#define GL_EVAL_VERTEX_ATTRIB9_NV 0x86CF +#define GL_EVAL_VERTEX_ATTRIB10_NV 0x86D0 +#define GL_EVAL_VERTEX_ATTRIB11_NV 0x86D1 +#define GL_EVAL_VERTEX_ATTRIB12_NV 0x86D2 +#define GL_EVAL_VERTEX_ATTRIB13_NV 0x86D3 +#define GL_EVAL_VERTEX_ATTRIB14_NV 0x86D4 +#define GL_EVAL_VERTEX_ATTRIB15_NV 0x86D5 +#define GL_MAX_MAP_TESSELLATION_NV 0x86D6 +#define GL_MAX_RATIONAL_EVAL_ORDER_NV 0x86D7 +#endif + +#ifndef GL_NV_packed_depth_stencil +#define GL_DEPTH_STENCIL_NV 0x84F9 +#define GL_UNSIGNED_INT_24_8_NV 0x84FA +#endif + +#ifndef GL_NV_register_combiners2 +#define GL_PER_STAGE_CONSTANTS_NV 0x8535 +#endif + +#ifndef GL_NV_texture_compression_vtc +#endif + +#ifndef GL_NV_texture_rectangle +#define GL_TEXTURE_RECTANGLE_NV 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8 +#endif + +#ifndef GL_NV_texture_shader +#define GL_OFFSET_TEXTURE_RECTANGLE_NV 0x864C +#define GL_OFFSET_TEXTURE_RECTANGLE_SCALE_NV 0x864D +#define GL_DOT_PRODUCT_TEXTURE_RECTANGLE_NV 0x864E +#define GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV 0x86D9 +#define GL_UNSIGNED_INT_S8_S8_8_8_NV 0x86DA +#define GL_UNSIGNED_INT_8_8_S8_S8_REV_NV 0x86DB +#define GL_DSDT_MAG_INTENSITY_NV 0x86DC +#define GL_SHADER_CONSISTENT_NV 0x86DD +#define GL_TEXTURE_SHADER_NV 0x86DE +#define GL_SHADER_OPERATION_NV 0x86DF +#define GL_CULL_MODES_NV 0x86E0 +#define GL_OFFSET_TEXTURE_MATRIX_NV 0x86E1 +#define GL_OFFSET_TEXTURE_SCALE_NV 0x86E2 +#define GL_OFFSET_TEXTURE_BIAS_NV 0x86E3 +#define GL_OFFSET_TEXTURE_2D_MATRIX_NV GL_OFFSET_TEXTURE_MATRIX_NV +#define GL_OFFSET_TEXTURE_2D_SCALE_NV GL_OFFSET_TEXTURE_SCALE_NV +#define GL_OFFSET_TEXTURE_2D_BIAS_NV GL_OFFSET_TEXTURE_BIAS_NV +#define GL_PREVIOUS_TEXTURE_INPUT_NV 0x86E4 +#define GL_CONST_EYE_NV 0x86E5 +#define GL_PASS_THROUGH_NV 0x86E6 +#define GL_CULL_FRAGMENT_NV 0x86E7 +#define GL_OFFSET_TEXTURE_2D_NV 0x86E8 +#define GL_DEPENDENT_AR_TEXTURE_2D_NV 0x86E9 +#define GL_DEPENDENT_GB_TEXTURE_2D_NV 0x86EA +#define GL_DOT_PRODUCT_NV 0x86EC +#define GL_DOT_PRODUCT_DEPTH_REPLACE_NV 0x86ED +#define GL_DOT_PRODUCT_TEXTURE_2D_NV 0x86EE +#define GL_DOT_PRODUCT_TEXTURE_CUBE_MAP_NV 0x86F0 +#define GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV 0x86F1 +#define GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV 0x86F2 +#define GL_DOT_PRODUCT_CONST_EYE_REFLECT_CUBE_MAP_NV 0x86F3 +#define GL_HILO_NV 0x86F4 +#define GL_DSDT_NV 0x86F5 +#define GL_DSDT_MAG_NV 0x86F6 +#define GL_DSDT_MAG_VIB_NV 0x86F7 +#define GL_HILO16_NV 0x86F8 +#define GL_SIGNED_HILO_NV 0x86F9 +#define GL_SIGNED_HILO16_NV 0x86FA +#define GL_SIGNED_RGBA_NV 0x86FB +#define GL_SIGNED_RGBA8_NV 0x86FC +#define GL_SIGNED_RGB_NV 0x86FE +#define GL_SIGNED_RGB8_NV 0x86FF +#define GL_SIGNED_LUMINANCE_NV 0x8701 +#define GL_SIGNED_LUMINANCE8_NV 0x8702 +#define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703 +#define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704 +#define GL_SIGNED_ALPHA_NV 0x8705 +#define GL_SIGNED_ALPHA8_NV 0x8706 +#define GL_SIGNED_INTENSITY_NV 0x8707 +#define GL_SIGNED_INTENSITY8_NV 0x8708 +#define GL_DSDT8_NV 0x8709 +#define GL_DSDT8_MAG8_NV 0x870A +#define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B +#define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C +#define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D +#define GL_HI_SCALE_NV 0x870E +#define GL_LO_SCALE_NV 0x870F +#define GL_DS_SCALE_NV 0x8710 +#define GL_DT_SCALE_NV 0x8711 +#define GL_MAGNITUDE_SCALE_NV 0x8712 +#define GL_VIBRANCE_SCALE_NV 0x8713 +#define GL_HI_BIAS_NV 0x8714 +#define GL_LO_BIAS_NV 0x8715 +#define GL_DS_BIAS_NV 0x8716 +#define GL_DT_BIAS_NV 0x8717 +#define GL_MAGNITUDE_BIAS_NV 0x8718 +#define GL_VIBRANCE_BIAS_NV 0x8719 +#define GL_TEXTURE_BORDER_VALUES_NV 0x871A +#define GL_TEXTURE_HI_SIZE_NV 0x871B +#define GL_TEXTURE_LO_SIZE_NV 0x871C +#define GL_TEXTURE_DS_SIZE_NV 0x871D +#define GL_TEXTURE_DT_SIZE_NV 0x871E +#define GL_TEXTURE_MAG_SIZE_NV 0x871F +#endif + +#ifndef GL_NV_texture_shader2 +#define GL_DOT_PRODUCT_TEXTURE_3D_NV 0x86EF +#endif + +#ifndef GL_NV_vertex_array_range2 +#define GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV 0x8533 +#endif + +#ifndef GL_NV_vertex_program +#define GL_VERTEX_PROGRAM_NV 0x8620 +#define GL_VERTEX_STATE_PROGRAM_NV 0x8621 +#define GL_ATTRIB_ARRAY_SIZE_NV 0x8623 +#define GL_ATTRIB_ARRAY_STRIDE_NV 0x8624 +#define GL_ATTRIB_ARRAY_TYPE_NV 0x8625 +#define GL_CURRENT_ATTRIB_NV 0x8626 +#define GL_PROGRAM_LENGTH_NV 0x8627 +#define GL_PROGRAM_STRING_NV 0x8628 +#define GL_MODELVIEW_PROJECTION_NV 0x8629 +#define GL_IDENTITY_NV 0x862A +#define GL_INVERSE_NV 0x862B +#define GL_TRANSPOSE_NV 0x862C +#define GL_INVERSE_TRANSPOSE_NV 0x862D +#define GL_MAX_TRACK_MATRIX_STACK_DEPTH_NV 0x862E +#define GL_MAX_TRACK_MATRICES_NV 0x862F +#define GL_MATRIX0_NV 0x8630 +#define GL_MATRIX1_NV 0x8631 +#define GL_MATRIX2_NV 0x8632 +#define GL_MATRIX3_NV 0x8633 +#define GL_MATRIX4_NV 0x8634 +#define GL_MATRIX5_NV 0x8635 +#define GL_MATRIX6_NV 0x8636 +#define GL_MATRIX7_NV 0x8637 +#define GL_CURRENT_MATRIX_STACK_DEPTH_NV 0x8640 +#define GL_CURRENT_MATRIX_NV 0x8641 +#define GL_VERTEX_PROGRAM_POINT_SIZE_NV 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE_NV 0x8643 +#define GL_PROGRAM_PARAMETER_NV 0x8644 +#define GL_ATTRIB_ARRAY_POINTER_NV 0x8645 +#define GL_PROGRAM_TARGET_NV 0x8646 +#define GL_PROGRAM_RESIDENT_NV 0x8647 +#define GL_TRACK_MATRIX_NV 0x8648 +#define GL_TRACK_MATRIX_TRANSFORM_NV 0x8649 +#define GL_VERTEX_PROGRAM_BINDING_NV 0x864A +#define GL_PROGRAM_ERROR_POSITION_NV 0x864B +#define GL_VERTEX_ATTRIB_ARRAY0_NV 0x8650 +#define GL_VERTEX_ATTRIB_ARRAY1_NV 0x8651 +#define GL_VERTEX_ATTRIB_ARRAY2_NV 0x8652 +#define GL_VERTEX_ATTRIB_ARRAY3_NV 0x8653 +#define GL_VERTEX_ATTRIB_ARRAY4_NV 0x8654 +#define GL_VERTEX_ATTRIB_ARRAY5_NV 0x8655 +#define GL_VERTEX_ATTRIB_ARRAY6_NV 0x8656 +#define GL_VERTEX_ATTRIB_ARRAY7_NV 0x8657 +#define GL_VERTEX_ATTRIB_ARRAY8_NV 0x8658 +#define GL_VERTEX_ATTRIB_ARRAY9_NV 0x8659 +#define GL_VERTEX_ATTRIB_ARRAY10_NV 0x865A +#define GL_VERTEX_ATTRIB_ARRAY11_NV 0x865B +#define GL_VERTEX_ATTRIB_ARRAY12_NV 0x865C +#define GL_VERTEX_ATTRIB_ARRAY13_NV 0x865D +#define GL_VERTEX_ATTRIB_ARRAY14_NV 0x865E +#define GL_VERTEX_ATTRIB_ARRAY15_NV 0x865F +#define GL_MAP1_VERTEX_ATTRIB0_4_NV 0x8660 +#define GL_MAP1_VERTEX_ATTRIB1_4_NV 0x8661 +#define GL_MAP1_VERTEX_ATTRIB2_4_NV 0x8662 +#define GL_MAP1_VERTEX_ATTRIB3_4_NV 0x8663 +#define GL_MAP1_VERTEX_ATTRIB4_4_NV 0x8664 +#define GL_MAP1_VERTEX_ATTRIB5_4_NV 0x8665 +#define GL_MAP1_VERTEX_ATTRIB6_4_NV 0x8666 +#define GL_MAP1_VERTEX_ATTRIB7_4_NV 0x8667 +#define GL_MAP1_VERTEX_ATTRIB8_4_NV 0x8668 +#define GL_MAP1_VERTEX_ATTRIB9_4_NV 0x8669 +#define GL_MAP1_VERTEX_ATTRIB10_4_NV 0x866A +#define GL_MAP1_VERTEX_ATTRIB11_4_NV 0x866B +#define GL_MAP1_VERTEX_ATTRIB12_4_NV 0x866C +#define GL_MAP1_VERTEX_ATTRIB13_4_NV 0x866D +#define GL_MAP1_VERTEX_ATTRIB14_4_NV 0x866E +#define GL_MAP1_VERTEX_ATTRIB15_4_NV 0x866F +#define GL_MAP2_VERTEX_ATTRIB0_4_NV 0x8670 +#define GL_MAP2_VERTEX_ATTRIB1_4_NV 0x8671 +#define GL_MAP2_VERTEX_ATTRIB2_4_NV 0x8672 +#define GL_MAP2_VERTEX_ATTRIB3_4_NV 0x8673 +#define GL_MAP2_VERTEX_ATTRIB4_4_NV 0x8674 +#define GL_MAP2_VERTEX_ATTRIB5_4_NV 0x8675 +#define GL_MAP2_VERTEX_ATTRIB6_4_NV 0x8676 +#define GL_MAP2_VERTEX_ATTRIB7_4_NV 0x8677 +#define GL_MAP2_VERTEX_ATTRIB8_4_NV 0x8678 +#define GL_MAP2_VERTEX_ATTRIB9_4_NV 0x8679 +#define GL_MAP2_VERTEX_ATTRIB10_4_NV 0x867A +#define GL_MAP2_VERTEX_ATTRIB11_4_NV 0x867B +#define GL_MAP2_VERTEX_ATTRIB12_4_NV 0x867C +#define GL_MAP2_VERTEX_ATTRIB13_4_NV 0x867D +#define GL_MAP2_VERTEX_ATTRIB14_4_NV 0x867E +#define GL_MAP2_VERTEX_ATTRIB15_4_NV 0x867F +#endif + +#ifndef GL_SGIX_texture_coordinate_clamp +#define GL_TEXTURE_MAX_CLAMP_S_SGIX 0x8369 +#define GL_TEXTURE_MAX_CLAMP_T_SGIX 0x836A +#define GL_TEXTURE_MAX_CLAMP_R_SGIX 0x836B +#endif + +#ifndef GL_SGIX_scalebias_hint +#define GL_SCALEBIAS_HINT_SGIX 0x8322 +#endif + +#ifndef GL_OML_interlace +#define GL_INTERLACE_OML 0x8980 +#define GL_INTERLACE_READ_OML 0x8981 +#endif + +#ifndef GL_OML_subsample +#define GL_FORMAT_SUBSAMPLE_24_24_OML 0x8982 +#define GL_FORMAT_SUBSAMPLE_244_244_OML 0x8983 +#endif + +#ifndef GL_OML_resample +#define GL_PACK_RESAMPLE_OML 0x8984 +#define GL_UNPACK_RESAMPLE_OML 0x8985 +#define GL_RESAMPLE_REPLICATE_OML 0x8986 +#define GL_RESAMPLE_ZERO_FILL_OML 0x8987 +#define GL_RESAMPLE_AVERAGE_OML 0x8988 +#define GL_RESAMPLE_DECIMATE_OML 0x8989 +#endif + +#ifndef GL_NV_copy_depth_to_color +#define GL_DEPTH_STENCIL_TO_RGBA_NV 0x886E +#define GL_DEPTH_STENCIL_TO_BGRA_NV 0x886F +#endif + +#ifndef GL_ATI_envmap_bumpmap +#define GL_BUMP_ROT_MATRIX_ATI 0x8775 +#define GL_BUMP_ROT_MATRIX_SIZE_ATI 0x8776 +#define GL_BUMP_NUM_TEX_UNITS_ATI 0x8777 +#define GL_BUMP_TEX_UNITS_ATI 0x8778 +#define GL_DUDV_ATI 0x8779 +#define GL_DU8DV8_ATI 0x877A +#define GL_BUMP_ENVMAP_ATI 0x877B +#define GL_BUMP_TARGET_ATI 0x877C +#endif + +#ifndef GL_ATI_fragment_shader +#define GL_FRAGMENT_SHADER_ATI 0x8920 +#define GL_REG_0_ATI 0x8921 +#define GL_REG_1_ATI 0x8922 +#define GL_REG_2_ATI 0x8923 +#define GL_REG_3_ATI 0x8924 +#define GL_REG_4_ATI 0x8925 +#define GL_REG_5_ATI 0x8926 +#define GL_REG_6_ATI 0x8927 +#define GL_REG_7_ATI 0x8928 +#define GL_REG_8_ATI 0x8929 +#define GL_REG_9_ATI 0x892A +#define GL_REG_10_ATI 0x892B +#define GL_REG_11_ATI 0x892C +#define GL_REG_12_ATI 0x892D +#define GL_REG_13_ATI 0x892E +#define GL_REG_14_ATI 0x892F +#define GL_REG_15_ATI 0x8930 +#define GL_REG_16_ATI 0x8931 +#define GL_REG_17_ATI 0x8932 +#define GL_REG_18_ATI 0x8933 +#define GL_REG_19_ATI 0x8934 +#define GL_REG_20_ATI 0x8935 +#define GL_REG_21_ATI 0x8936 +#define GL_REG_22_ATI 0x8937 +#define GL_REG_23_ATI 0x8938 +#define GL_REG_24_ATI 0x8939 +#define GL_REG_25_ATI 0x893A +#define GL_REG_26_ATI 0x893B +#define GL_REG_27_ATI 0x893C +#define GL_REG_28_ATI 0x893D +#define GL_REG_29_ATI 0x893E +#define GL_REG_30_ATI 0x893F +#define GL_REG_31_ATI 0x8940 +#define GL_CON_0_ATI 0x8941 +#define GL_CON_1_ATI 0x8942 +#define GL_CON_2_ATI 0x8943 +#define GL_CON_3_ATI 0x8944 +#define GL_CON_4_ATI 0x8945 +#define GL_CON_5_ATI 0x8946 +#define GL_CON_6_ATI 0x8947 +#define GL_CON_7_ATI 0x8948 +#define GL_CON_8_ATI 0x8949 +#define GL_CON_9_ATI 0x894A +#define GL_CON_10_ATI 0x894B +#define GL_CON_11_ATI 0x894C +#define GL_CON_12_ATI 0x894D +#define GL_CON_13_ATI 0x894E +#define GL_CON_14_ATI 0x894F +#define GL_CON_15_ATI 0x8950 +#define GL_CON_16_ATI 0x8951 +#define GL_CON_17_ATI 0x8952 +#define GL_CON_18_ATI 0x8953 +#define GL_CON_19_ATI 0x8954 +#define GL_CON_20_ATI 0x8955 +#define GL_CON_21_ATI 0x8956 +#define GL_CON_22_ATI 0x8957 +#define GL_CON_23_ATI 0x8958 +#define GL_CON_24_ATI 0x8959 +#define GL_CON_25_ATI 0x895A +#define GL_CON_26_ATI 0x895B +#define GL_CON_27_ATI 0x895C +#define GL_CON_28_ATI 0x895D +#define GL_CON_29_ATI 0x895E +#define GL_CON_30_ATI 0x895F +#define GL_CON_31_ATI 0x8960 +#define GL_MOV_ATI 0x8961 +#define GL_ADD_ATI 0x8963 +#define GL_MUL_ATI 0x8964 +#define GL_SUB_ATI 0x8965 +#define GL_DOT3_ATI 0x8966 +#define GL_DOT4_ATI 0x8967 +#define GL_MAD_ATI 0x8968 +#define GL_LERP_ATI 0x8969 +#define GL_CND_ATI 0x896A +#define GL_CND0_ATI 0x896B +#define GL_DOT2_ADD_ATI 0x896C +#define GL_SECONDARY_INTERPOLATOR_ATI 0x896D +#define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E +#define GL_NUM_FRAGMENT_CONSTANTS_ATI 0x896F +#define GL_NUM_PASSES_ATI 0x8970 +#define GL_NUM_INSTRUCTIONS_PER_PASS_ATI 0x8971 +#define GL_NUM_INSTRUCTIONS_TOTAL_ATI 0x8972 +#define GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI 0x8973 +#define GL_NUM_LOOPBACK_COMPONENTS_ATI 0x8974 +#define GL_COLOR_ALPHA_PAIRING_ATI 0x8975 +#define GL_SWIZZLE_STR_ATI 0x8976 +#define GL_SWIZZLE_STQ_ATI 0x8977 +#define GL_SWIZZLE_STR_DR_ATI 0x8978 +#define GL_SWIZZLE_STQ_DQ_ATI 0x8979 +#define GL_SWIZZLE_STRQ_ATI 0x897A +#define GL_SWIZZLE_STRQ_DQ_ATI 0x897B +#define GL_RED_BIT_ATI 0x00000001 +#define GL_GREEN_BIT_ATI 0x00000002 +#define GL_BLUE_BIT_ATI 0x00000004 +#define GL_2X_BIT_ATI 0x00000001 +#define GL_4X_BIT_ATI 0x00000002 +#define GL_8X_BIT_ATI 0x00000004 +#define GL_HALF_BIT_ATI 0x00000008 +#define GL_QUARTER_BIT_ATI 0x00000010 +#define GL_EIGHTH_BIT_ATI 0x00000020 +#define GL_SATURATE_BIT_ATI 0x00000040 +#define GL_COMP_BIT_ATI 0x00000002 +#define GL_NEGATE_BIT_ATI 0x00000004 +#define GL_BIAS_BIT_ATI 0x00000008 +#endif + +#ifndef GL_ATI_pn_triangles +#define GL_PN_TRIANGLES_ATI 0x87F0 +#define GL_MAX_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F1 +#define GL_PN_TRIANGLES_POINT_MODE_ATI 0x87F2 +#define GL_PN_TRIANGLES_NORMAL_MODE_ATI 0x87F3 +#define GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F4 +#define GL_PN_TRIANGLES_POINT_MODE_LINEAR_ATI 0x87F5 +#define GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATI 0x87F6 +#define GL_PN_TRIANGLES_NORMAL_MODE_LINEAR_ATI 0x87F7 +#define GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATI 0x87F8 +#endif + +#ifndef GL_ATI_vertex_array_object +#define GL_STATIC_ATI 0x8760 +#define GL_DYNAMIC_ATI 0x8761 +#define GL_PRESERVE_ATI 0x8762 +#define GL_DISCARD_ATI 0x8763 +#define GL_OBJECT_BUFFER_SIZE_ATI 0x8764 +#define GL_OBJECT_BUFFER_USAGE_ATI 0x8765 +#define GL_ARRAY_OBJECT_BUFFER_ATI 0x8766 +#define GL_ARRAY_OBJECT_OFFSET_ATI 0x8767 +#endif + +#ifndef GL_EXT_vertex_shader +#define GL_VERTEX_SHADER_EXT 0x8780 +#define GL_VERTEX_SHADER_BINDING_EXT 0x8781 +#define GL_OP_INDEX_EXT 0x8782 +#define GL_OP_NEGATE_EXT 0x8783 +#define GL_OP_DOT3_EXT 0x8784 +#define GL_OP_DOT4_EXT 0x8785 +#define GL_OP_MUL_EXT 0x8786 +#define GL_OP_ADD_EXT 0x8787 +#define GL_OP_MADD_EXT 0x8788 +#define GL_OP_FRAC_EXT 0x8789 +#define GL_OP_MAX_EXT 0x878A +#define GL_OP_MIN_EXT 0x878B +#define GL_OP_SET_GE_EXT 0x878C +#define GL_OP_SET_LT_EXT 0x878D +#define GL_OP_CLAMP_EXT 0x878E +#define GL_OP_FLOOR_EXT 0x878F +#define GL_OP_ROUND_EXT 0x8790 +#define GL_OP_EXP_BASE_2_EXT 0x8791 +#define GL_OP_LOG_BASE_2_EXT 0x8792 +#define GL_OP_POWER_EXT 0x8793 +#define GL_OP_RECIP_EXT 0x8794 +#define GL_OP_RECIP_SQRT_EXT 0x8795 +#define GL_OP_SUB_EXT 0x8796 +#define GL_OP_CROSS_PRODUCT_EXT 0x8797 +#define GL_OP_MULTIPLY_MATRIX_EXT 0x8798 +#define GL_OP_MOV_EXT 0x8799 +#define GL_OUTPUT_VERTEX_EXT 0x879A +#define GL_OUTPUT_COLOR0_EXT 0x879B +#define GL_OUTPUT_COLOR1_EXT 0x879C +#define GL_OUTPUT_TEXTURE_COORD0_EXT 0x879D +#define GL_OUTPUT_TEXTURE_COORD1_EXT 0x879E +#define GL_OUTPUT_TEXTURE_COORD2_EXT 0x879F +#define GL_OUTPUT_TEXTURE_COORD3_EXT 0x87A0 +#define GL_OUTPUT_TEXTURE_COORD4_EXT 0x87A1 +#define GL_OUTPUT_TEXTURE_COORD5_EXT 0x87A2 +#define GL_OUTPUT_TEXTURE_COORD6_EXT 0x87A3 +#define GL_OUTPUT_TEXTURE_COORD7_EXT 0x87A4 +#define GL_OUTPUT_TEXTURE_COORD8_EXT 0x87A5 +#define GL_OUTPUT_TEXTURE_COORD9_EXT 0x87A6 +#define GL_OUTPUT_TEXTURE_COORD10_EXT 0x87A7 +#define GL_OUTPUT_TEXTURE_COORD11_EXT 0x87A8 +#define GL_OUTPUT_TEXTURE_COORD12_EXT 0x87A9 +#define GL_OUTPUT_TEXTURE_COORD13_EXT 0x87AA +#define GL_OUTPUT_TEXTURE_COORD14_EXT 0x87AB +#define GL_OUTPUT_TEXTURE_COORD15_EXT 0x87AC +#define GL_OUTPUT_TEXTURE_COORD16_EXT 0x87AD +#define GL_OUTPUT_TEXTURE_COORD17_EXT 0x87AE +#define GL_OUTPUT_TEXTURE_COORD18_EXT 0x87AF +#define GL_OUTPUT_TEXTURE_COORD19_EXT 0x87B0 +#define GL_OUTPUT_TEXTURE_COORD20_EXT 0x87B1 +#define GL_OUTPUT_TEXTURE_COORD21_EXT 0x87B2 +#define GL_OUTPUT_TEXTURE_COORD22_EXT 0x87B3 +#define GL_OUTPUT_TEXTURE_COORD23_EXT 0x87B4 +#define GL_OUTPUT_TEXTURE_COORD24_EXT 0x87B5 +#define GL_OUTPUT_TEXTURE_COORD25_EXT 0x87B6 +#define GL_OUTPUT_TEXTURE_COORD26_EXT 0x87B7 +#define GL_OUTPUT_TEXTURE_COORD27_EXT 0x87B8 +#define GL_OUTPUT_TEXTURE_COORD28_EXT 0x87B9 +#define GL_OUTPUT_TEXTURE_COORD29_EXT 0x87BA +#define GL_OUTPUT_TEXTURE_COORD30_EXT 0x87BB +#define GL_OUTPUT_TEXTURE_COORD31_EXT 0x87BC +#define GL_OUTPUT_FOG_EXT 0x87BD +#define GL_SCALAR_EXT 0x87BE +#define GL_VECTOR_EXT 0x87BF +#define GL_MATRIX_EXT 0x87C0 +#define GL_VARIANT_EXT 0x87C1 +#define GL_INVARIANT_EXT 0x87C2 +#define GL_LOCAL_CONSTANT_EXT 0x87C3 +#define GL_LOCAL_EXT 0x87C4 +#define GL_MAX_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87C5 +#define GL_MAX_VERTEX_SHADER_VARIANTS_EXT 0x87C6 +#define GL_MAX_VERTEX_SHADER_INVARIANTS_EXT 0x87C7 +#define GL_MAX_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87C8 +#define GL_MAX_VERTEX_SHADER_LOCALS_EXT 0x87C9 +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CA +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_VARIANTS_EXT 0x87CB +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87CC +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INVARIANTS_EXT 0x87CD +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCALS_EXT 0x87CE +#define GL_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CF +#define GL_VERTEX_SHADER_VARIANTS_EXT 0x87D0 +#define GL_VERTEX_SHADER_INVARIANTS_EXT 0x87D1 +#define GL_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87D2 +#define GL_VERTEX_SHADER_LOCALS_EXT 0x87D3 +#define GL_VERTEX_SHADER_OPTIMIZED_EXT 0x87D4 +#define GL_X_EXT 0x87D5 +#define GL_Y_EXT 0x87D6 +#define GL_Z_EXT 0x87D7 +#define GL_W_EXT 0x87D8 +#define GL_NEGATIVE_X_EXT 0x87D9 +#define GL_NEGATIVE_Y_EXT 0x87DA +#define GL_NEGATIVE_Z_EXT 0x87DB +#define GL_NEGATIVE_W_EXT 0x87DC +#define GL_ZERO_EXT 0x87DD +#define GL_ONE_EXT 0x87DE +#define GL_NEGATIVE_ONE_EXT 0x87DF +#define GL_NORMALIZED_RANGE_EXT 0x87E0 +#define GL_FULL_RANGE_EXT 0x87E1 +#define GL_CURRENT_VERTEX_EXT 0x87E2 +#define GL_MVP_MATRIX_EXT 0x87E3 +#define GL_VARIANT_VALUE_EXT 0x87E4 +#define GL_VARIANT_DATATYPE_EXT 0x87E5 +#define GL_VARIANT_ARRAY_STRIDE_EXT 0x87E6 +#define GL_VARIANT_ARRAY_TYPE_EXT 0x87E7 +#define GL_VARIANT_ARRAY_EXT 0x87E8 +#define GL_VARIANT_ARRAY_POINTER_EXT 0x87E9 +#define GL_INVARIANT_VALUE_EXT 0x87EA +#define GL_INVARIANT_DATATYPE_EXT 0x87EB +#define GL_LOCAL_CONSTANT_VALUE_EXT 0x87EC +#define GL_LOCAL_CONSTANT_DATATYPE_EXT 0x87ED +#endif + +#ifndef GL_ATI_vertex_streams +#define GL_MAX_VERTEX_STREAMS_ATI 0x876B +#define GL_VERTEX_STREAM0_ATI 0x876C +#define GL_VERTEX_STREAM1_ATI 0x876D +#define GL_VERTEX_STREAM2_ATI 0x876E +#define GL_VERTEX_STREAM3_ATI 0x876F +#define GL_VERTEX_STREAM4_ATI 0x8770 +#define GL_VERTEX_STREAM5_ATI 0x8771 +#define GL_VERTEX_STREAM6_ATI 0x8772 +#define GL_VERTEX_STREAM7_ATI 0x8773 +#define GL_VERTEX_SOURCE_ATI 0x8774 +#endif + +#ifndef GL_ATI_element_array +#define GL_ELEMENT_ARRAY_ATI 0x8768 +#define GL_ELEMENT_ARRAY_TYPE_ATI 0x8769 +#define GL_ELEMENT_ARRAY_POINTER_ATI 0x876A +#endif + +#ifndef GL_SUN_mesh_array +#define GL_QUAD_MESH_SUN 0x8614 +#define GL_TRIANGLE_MESH_SUN 0x8615 +#endif + +#ifndef GL_SUN_slice_accum +#define GL_SLICE_ACCUM_SUN 0x85CC +#endif + +#ifndef GL_NV_multisample_filter_hint +#define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534 +#endif + +#ifndef GL_NV_depth_clamp +#define GL_DEPTH_CLAMP_NV 0x864F +#endif + +#ifndef GL_NV_occlusion_query +#define GL_PIXEL_COUNTER_BITS_NV 0x8864 +#define GL_CURRENT_OCCLUSION_QUERY_ID_NV 0x8865 +#define GL_PIXEL_COUNT_NV 0x8866 +#define GL_PIXEL_COUNT_AVAILABLE_NV 0x8867 +#endif + +#ifndef GL_NV_point_sprite +#define GL_POINT_SPRITE_NV 0x8861 +#define GL_COORD_REPLACE_NV 0x8862 +#define GL_POINT_SPRITE_R_MODE_NV 0x8863 +#endif + +#ifndef GL_NV_texture_shader3 +#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_NV 0x8850 +#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_SCALE_NV 0x8851 +#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8852 +#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_SCALE_NV 0x8853 +#define GL_OFFSET_HILO_TEXTURE_2D_NV 0x8854 +#define GL_OFFSET_HILO_TEXTURE_RECTANGLE_NV 0x8855 +#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_2D_NV 0x8856 +#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8857 +#define GL_DEPENDENT_HILO_TEXTURE_2D_NV 0x8858 +#define GL_DEPENDENT_RGB_TEXTURE_3D_NV 0x8859 +#define GL_DEPENDENT_RGB_TEXTURE_CUBE_MAP_NV 0x885A +#define GL_DOT_PRODUCT_PASS_THROUGH_NV 0x885B +#define GL_DOT_PRODUCT_TEXTURE_1D_NV 0x885C +#define GL_DOT_PRODUCT_AFFINE_DEPTH_REPLACE_NV 0x885D +#define GL_HILO8_NV 0x885E +#define GL_SIGNED_HILO8_NV 0x885F +#define GL_FORCE_BLUE_TO_ONE_NV 0x8860 +#endif + +#ifndef GL_NV_vertex_program1_1 +#endif + +#ifndef GL_EXT_shadow_funcs +#endif + +#ifndef GL_EXT_stencil_two_side +#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910 +#define GL_ACTIVE_STENCIL_FACE_EXT 0x8911 +#endif + +#ifndef GL_ATI_text_fragment_shader +#define GL_TEXT_FRAGMENT_SHADER_ATI 0x8200 +#endif + +#ifndef GL_APPLE_client_storage +#define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2 +#endif + +#ifndef GL_APPLE_element_array +#define GL_ELEMENT_ARRAY_APPLE 0x8768 +#define GL_ELEMENT_ARRAY_TYPE_APPLE 0x8769 +#define GL_ELEMENT_ARRAY_POINTER_APPLE 0x876A +#endif + +#ifndef GL_APPLE_fence +#define GL_DRAW_PIXELS_APPLE 0x8A0A +#define GL_FENCE_APPLE 0x8A0B +#endif + +#ifndef GL_APPLE_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING_APPLE 0x85B5 +#endif + +#ifndef GL_APPLE_vertex_array_range +#define GL_VERTEX_ARRAY_RANGE_APPLE 0x851D +#define GL_VERTEX_ARRAY_RANGE_LENGTH_APPLE 0x851E +#define GL_VERTEX_ARRAY_STORAGE_HINT_APPLE 0x851F +#define GL_VERTEX_ARRAY_RANGE_POINTER_APPLE 0x8521 +#define GL_STORAGE_CACHED_APPLE 0x85BE +#define GL_STORAGE_SHARED_APPLE 0x85BF +#endif + +#ifndef GL_APPLE_ycbcr_422 +#define GL_YCBCR_422_APPLE 0x85B9 +#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB +#endif + +#ifndef GL_S3_s3tc +#define GL_RGB_S3TC 0x83A0 +#define GL_RGB4_S3TC 0x83A1 +#define GL_RGBA_S3TC 0x83A2 +#define GL_RGBA4_S3TC 0x83A3 +#endif + +#ifndef GL_ATI_draw_buffers +#define GL_MAX_DRAW_BUFFERS_ATI 0x8824 +#define GL_DRAW_BUFFER0_ATI 0x8825 +#define GL_DRAW_BUFFER1_ATI 0x8826 +#define GL_DRAW_BUFFER2_ATI 0x8827 +#define GL_DRAW_BUFFER3_ATI 0x8828 +#define GL_DRAW_BUFFER4_ATI 0x8829 +#define GL_DRAW_BUFFER5_ATI 0x882A +#define GL_DRAW_BUFFER6_ATI 0x882B +#define GL_DRAW_BUFFER7_ATI 0x882C +#define GL_DRAW_BUFFER8_ATI 0x882D +#define GL_DRAW_BUFFER9_ATI 0x882E +#define GL_DRAW_BUFFER10_ATI 0x882F +#define GL_DRAW_BUFFER11_ATI 0x8830 +#define GL_DRAW_BUFFER12_ATI 0x8831 +#define GL_DRAW_BUFFER13_ATI 0x8832 +#define GL_DRAW_BUFFER14_ATI 0x8833 +#define GL_DRAW_BUFFER15_ATI 0x8834 +#endif + +#ifndef GL_ATI_pixel_format_float +#define GL_TYPE_RGBA_FLOAT_ATI 0x8820 +#define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835 +#endif + +#ifndef GL_ATI_texture_env_combine3 +#define GL_MODULATE_ADD_ATI 0x8744 +#define GL_MODULATE_SIGNED_ADD_ATI 0x8745 +#define GL_MODULATE_SUBTRACT_ATI 0x8746 +#endif + +#ifndef GL_ATI_texture_float +#define GL_RGBA_FLOAT32_ATI 0x8814 +#define GL_RGB_FLOAT32_ATI 0x8815 +#define GL_ALPHA_FLOAT32_ATI 0x8816 +#define GL_INTENSITY_FLOAT32_ATI 0x8817 +#define GL_LUMINANCE_FLOAT32_ATI 0x8818 +#define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819 +#define GL_RGBA_FLOAT16_ATI 0x881A +#define GL_RGB_FLOAT16_ATI 0x881B +#define GL_ALPHA_FLOAT16_ATI 0x881C +#define GL_INTENSITY_FLOAT16_ATI 0x881D +#define GL_LUMINANCE_FLOAT16_ATI 0x881E +#define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F +#endif + +#ifndef GL_NV_float_buffer +#define GL_FLOAT_R_NV 0x8880 +#define GL_FLOAT_RG_NV 0x8881 +#define GL_FLOAT_RGB_NV 0x8882 +#define GL_FLOAT_RGBA_NV 0x8883 +#define GL_FLOAT_R16_NV 0x8884 +#define GL_FLOAT_R32_NV 0x8885 +#define GL_FLOAT_RG16_NV 0x8886 +#define GL_FLOAT_RG32_NV 0x8887 +#define GL_FLOAT_RGB16_NV 0x8888 +#define GL_FLOAT_RGB32_NV 0x8889 +#define GL_FLOAT_RGBA16_NV 0x888A +#define GL_FLOAT_RGBA32_NV 0x888B +#define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C +#define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D +#define GL_FLOAT_RGBA_MODE_NV 0x888E +#endif + +#ifndef GL_NV_fragment_program +#define GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV 0x8868 +#define GL_FRAGMENT_PROGRAM_NV 0x8870 +#define GL_MAX_TEXTURE_COORDS_NV 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS_NV 0x8872 +#define GL_FRAGMENT_PROGRAM_BINDING_NV 0x8873 +#define GL_PROGRAM_ERROR_STRING_NV 0x8874 +#endif + +#ifndef GL_NV_half_float +#define GL_HALF_FLOAT_NV 0x140B +#endif + +#ifndef GL_NV_pixel_data_range +#define GL_WRITE_PIXEL_DATA_RANGE_NV 0x8878 +#define GL_READ_PIXEL_DATA_RANGE_NV 0x8879 +#define GL_WRITE_PIXEL_DATA_RANGE_LENGTH_NV 0x887A +#define GL_READ_PIXEL_DATA_RANGE_LENGTH_NV 0x887B +#define GL_WRITE_PIXEL_DATA_RANGE_POINTER_NV 0x887C +#define GL_READ_PIXEL_DATA_RANGE_POINTER_NV 0x887D +#endif + +#ifndef GL_NV_primitive_restart +#define GL_PRIMITIVE_RESTART_NV 0x8558 +#define GL_PRIMITIVE_RESTART_INDEX_NV 0x8559 +#endif + +#ifndef GL_NV_texture_expand_normal +#define GL_TEXTURE_UNSIGNED_REMAP_MODE_NV 0x888F +#endif + +#ifndef GL_NV_vertex_program2 +#endif + +#ifndef GL_ATI_map_object_buffer +#endif + +#ifndef GL_ATI_separate_stencil +#define GL_STENCIL_BACK_FUNC_ATI 0x8800 +#define GL_STENCIL_BACK_FAIL_ATI 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL_ATI 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS_ATI 0x8803 +#endif + +#ifndef GL_ATI_vertex_attrib_array_object +#endif + +#ifndef GL_OES_read_format +#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B +#endif + +#ifndef GL_EXT_depth_bounds_test +#define GL_DEPTH_BOUNDS_TEST_EXT 0x8890 +#define GL_DEPTH_BOUNDS_EXT 0x8891 +#endif + +#ifndef GL_EXT_texture_mirror_clamp +#define GL_MIRROR_CLAMP_EXT 0x8742 +#define GL_MIRROR_CLAMP_TO_EDGE_EXT 0x8743 +#define GL_MIRROR_CLAMP_TO_BORDER_EXT 0x8912 +#endif + +#ifndef GL_EXT_blend_equation_separate +#define GL_BLEND_EQUATION_RGB_EXT 0x8009 +#define GL_BLEND_EQUATION_ALPHA_EXT 0x883D +#endif + +#ifndef GL_MESA_pack_invert +#define GL_PACK_INVERT_MESA 0x8758 +#endif + +#ifndef GL_MESA_ycbcr_texture +#define GL_UNSIGNED_SHORT_8_8_MESA 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_MESA 0x85BB +#define GL_YCBCR_MESA 0x8757 +#endif + +#ifndef GL_EXT_pixel_buffer_object +#define GL_PIXEL_PACK_BUFFER_EXT 0x88EB +#define GL_PIXEL_UNPACK_BUFFER_EXT 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING_EXT 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING_EXT 0x88EF +#endif + +#ifndef GL_NV_fragment_program_option +#endif + +#ifndef GL_NV_fragment_program2 +#define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV 0x88F4 +#define GL_MAX_PROGRAM_CALL_DEPTH_NV 0x88F5 +#define GL_MAX_PROGRAM_IF_DEPTH_NV 0x88F6 +#define GL_MAX_PROGRAM_LOOP_DEPTH_NV 0x88F7 +#define GL_MAX_PROGRAM_LOOP_COUNT_NV 0x88F8 +#endif + +#ifndef GL_NV_vertex_program2_option +/* reuse GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV */ +/* reuse GL_MAX_PROGRAM_CALL_DEPTH_NV */ +#endif + +#ifndef GL_NV_vertex_program3 +/* reuse GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB */ +#endif + +#ifndef GL_EXT_framebuffer_object +#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506 +#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8 +#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6 +#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4 +#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9 +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC +#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD +#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF +#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0 +#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1 +#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2 +#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3 +#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4 +#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5 +#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6 +#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7 +#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8 +#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9 +#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA +#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB +#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC +#define GL_COLOR_ATTACHMENT13_EXT 0x8CED +#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE +#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF +#define GL_DEPTH_ATTACHMENT_EXT 0x8D00 +#define GL_STENCIL_ATTACHMENT_EXT 0x8D20 +#define GL_FRAMEBUFFER_EXT 0x8D40 +#define GL_RENDERBUFFER_EXT 0x8D41 +#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42 +#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44 +#define GL_STENCIL_INDEX1_EXT 0x8D46 +#define GL_STENCIL_INDEX4_EXT 0x8D47 +#define GL_STENCIL_INDEX8_EXT 0x8D48 +#define GL_STENCIL_INDEX16_EXT 0x8D49 +#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55 +#endif + +#ifndef GL_GREMEDY_string_marker +#endif + +#ifndef GL_EXT_packed_depth_stencil +#define GL_DEPTH_STENCIL_EXT 0x84F9 +#define GL_UNSIGNED_INT_24_8_EXT 0x84FA +#define GL_DEPTH24_STENCIL8_EXT 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1 +#endif + +#ifndef GL_EXT_stencil_clear_tag +#define GL_STENCIL_TAG_BITS_EXT 0x88F2 +#define GL_STENCIL_CLEAR_TAG_VALUE_EXT 0x88F3 +#endif + +#ifndef GL_EXT_texture_sRGB +#define GL_SRGB_EXT 0x8C40 +#define GL_SRGB8_EXT 0x8C41 +#define GL_SRGB_ALPHA_EXT 0x8C42 +#define GL_SRGB8_ALPHA8_EXT 0x8C43 +#define GL_SLUMINANCE_ALPHA_EXT 0x8C44 +#define GL_SLUMINANCE8_ALPHA8_EXT 0x8C45 +#define GL_SLUMINANCE_EXT 0x8C46 +#define GL_SLUMINANCE8_EXT 0x8C47 +#define GL_COMPRESSED_SRGB_EXT 0x8C48 +#define GL_COMPRESSED_SRGB_ALPHA_EXT 0x8C49 +#define GL_COMPRESSED_SLUMINANCE_EXT 0x8C4A +#define GL_COMPRESSED_SLUMINANCE_ALPHA_EXT 0x8C4B +#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F +#endif + +#ifndef GL_EXT_framebuffer_blit +#define GL_READ_FRAMEBUFFER_EXT 0x8CA8 +#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9 +#define GL_DRAW_FRAMEBUFFER_BINDING_EXT GL_FRAMEBUFFER_BINDING_EXT +#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA +#endif + +#ifndef GL_EXT_framebuffer_multisample +#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56 +#define GL_MAX_SAMPLES_EXT 0x8D57 +#endif + +#ifndef GL_MESAX_texture_stack +#define GL_TEXTURE_1D_STACK_MESAX 0x8759 +#define GL_TEXTURE_2D_STACK_MESAX 0x875A +#define GL_PROXY_TEXTURE_1D_STACK_MESAX 0x875B +#define GL_PROXY_TEXTURE_2D_STACK_MESAX 0x875C +#define GL_TEXTURE_1D_STACK_BINDING_MESAX 0x875D +#define GL_TEXTURE_2D_STACK_BINDING_MESAX 0x875E +#endif + +#ifndef GL_EXT_timer_query +#define GL_TIME_ELAPSED_EXT 0x88BF +#endif + +#ifndef GL_EXT_gpu_program_parameters +#endif + +#ifndef GL_APPLE_flush_buffer_range +#define GL_BUFFER_SERIALIZED_MODIFY_APPLE 0x8A12 +#define GL_BUFFER_FLUSHING_UNMAP_APPLE 0x8A13 +#endif + +#ifndef GL_NV_gpu_program4 +#define GL_MIN_PROGRAM_TEXEL_OFFSET_NV 0x8904 +#define GL_MAX_PROGRAM_TEXEL_OFFSET_NV 0x8905 +#define GL_PROGRAM_ATTRIB_COMPONENTS_NV 0x8906 +#define GL_PROGRAM_RESULT_COMPONENTS_NV 0x8907 +#define GL_MAX_PROGRAM_ATTRIB_COMPONENTS_NV 0x8908 +#define GL_MAX_PROGRAM_RESULT_COMPONENTS_NV 0x8909 +#define GL_MAX_PROGRAM_GENERIC_ATTRIBS_NV 0x8DA5 +#define GL_MAX_PROGRAM_GENERIC_RESULTS_NV 0x8DA6 +#endif + +#ifndef GL_NV_geometry_program4 +#define GL_LINES_ADJACENCY_EXT 0x000A +#define GL_LINE_STRIP_ADJACENCY_EXT 0x000B +#define GL_TRIANGLES_ADJACENCY_EXT 0x000C +#define GL_TRIANGLE_STRIP_ADJACENCY_EXT 0x000D +#define GL_GEOMETRY_PROGRAM_NV 0x8C26 +#define GL_MAX_PROGRAM_OUTPUT_VERTICES_NV 0x8C27 +#define GL_MAX_PROGRAM_TOTAL_OUTPUT_COMPONENTS_NV 0x8C28 +#define GL_GEOMETRY_VERTICES_OUT_EXT 0x8DDA +#define GL_GEOMETRY_INPUT_TYPE_EXT 0x8DDB +#define GL_GEOMETRY_OUTPUT_TYPE_EXT 0x8DDC +#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT 0x8C29 +#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT 0x8DA7 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT 0x8DA8 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT 0x8DA9 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4 +#define GL_PROGRAM_POINT_SIZE_EXT 0x8642 +#endif + +#ifndef GL_EXT_geometry_shader4 +#define GL_GEOMETRY_SHADER_EXT 0x8DD9 +/* reuse GL_GEOMETRY_VERTICES_OUT_EXT */ +/* reuse GL_GEOMETRY_INPUT_TYPE_EXT */ +/* reuse GL_GEOMETRY_OUTPUT_TYPE_EXT */ +/* reuse GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT */ +#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_EXT 0x8DDD +#define GL_MAX_VERTEX_VARYING_COMPONENTS_EXT 0x8DDE +#define GL_MAX_VARYING_COMPONENTS_EXT 0x8B4B +#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT 0x8DDF +#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT 0x8DE0 +#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT 0x8DE1 +/* reuse GL_LINES_ADJACENCY_EXT */ +/* reuse GL_LINE_STRIP_ADJACENCY_EXT */ +/* reuse GL_TRIANGLES_ADJACENCY_EXT */ +/* reuse GL_TRIANGLE_STRIP_ADJACENCY_EXT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT */ +/* reuse GL_PROGRAM_POINT_SIZE_EXT */ +#endif + +#ifndef GL_NV_vertex_program4 +#define GL_VERTEX_ATTRIB_ARRAY_INTEGER_NV 0x88FD +#endif + +#ifndef GL_EXT_gpu_shader4 +#define GL_SAMPLER_1D_ARRAY_EXT 0x8DC0 +#define GL_SAMPLER_2D_ARRAY_EXT 0x8DC1 +#define GL_SAMPLER_BUFFER_EXT 0x8DC2 +#define GL_SAMPLER_1D_ARRAY_SHADOW_EXT 0x8DC3 +#define GL_SAMPLER_2D_ARRAY_SHADOW_EXT 0x8DC4 +#define GL_SAMPLER_CUBE_SHADOW_EXT 0x8DC5 +#define GL_UNSIGNED_INT_VEC2_EXT 0x8DC6 +#define GL_UNSIGNED_INT_VEC3_EXT 0x8DC7 +#define GL_UNSIGNED_INT_VEC4_EXT 0x8DC8 +#define GL_INT_SAMPLER_1D_EXT 0x8DC9 +#define GL_INT_SAMPLER_2D_EXT 0x8DCA +#define GL_INT_SAMPLER_3D_EXT 0x8DCB +#define GL_INT_SAMPLER_CUBE_EXT 0x8DCC +#define GL_INT_SAMPLER_2D_RECT_EXT 0x8DCD +#define GL_INT_SAMPLER_1D_ARRAY_EXT 0x8DCE +#define GL_INT_SAMPLER_2D_ARRAY_EXT 0x8DCF +#define GL_INT_SAMPLER_BUFFER_EXT 0x8DD0 +#define GL_UNSIGNED_INT_SAMPLER_1D_EXT 0x8DD1 +#define GL_UNSIGNED_INT_SAMPLER_2D_EXT 0x8DD2 +#define GL_UNSIGNED_INT_SAMPLER_3D_EXT 0x8DD3 +#define GL_UNSIGNED_INT_SAMPLER_CUBE_EXT 0x8DD4 +#define GL_UNSIGNED_INT_SAMPLER_2D_RECT_EXT 0x8DD5 +#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY_EXT 0x8DD6 +#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY_EXT 0x8DD7 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT 0x8DD8 +#endif + +#ifndef GL_EXT_draw_instanced +#endif + +#ifndef GL_EXT_packed_float +#define GL_R11F_G11F_B10F_EXT 0x8C3A +#define GL_UNSIGNED_INT_10F_11F_11F_REV_EXT 0x8C3B +#define GL_RGBA_SIGNED_COMPONENTS_EXT 0x8C3C +#endif + +#ifndef GL_EXT_texture_array +#define GL_TEXTURE_1D_ARRAY_EXT 0x8C18 +#define GL_PROXY_TEXTURE_1D_ARRAY_EXT 0x8C19 +#define GL_TEXTURE_2D_ARRAY_EXT 0x8C1A +#define GL_PROXY_TEXTURE_2D_ARRAY_EXT 0x8C1B +#define GL_TEXTURE_BINDING_1D_ARRAY_EXT 0x8C1C +#define GL_TEXTURE_BINDING_2D_ARRAY_EXT 0x8C1D +#define GL_MAX_ARRAY_TEXTURE_LAYERS_EXT 0x88FF +#define GL_COMPARE_REF_DEPTH_TO_TEXTURE_EXT 0x884E +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT */ +#endif + +#ifndef GL_EXT_texture_buffer_object +#define GL_TEXTURE_BUFFER_EXT 0x8C2A +#define GL_MAX_TEXTURE_BUFFER_SIZE_EXT 0x8C2B +#define GL_TEXTURE_BINDING_BUFFER_EXT 0x8C2C +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT 0x8C2D +#define GL_TEXTURE_BUFFER_FORMAT_EXT 0x8C2E +#endif + +#ifndef GL_EXT_texture_compression_latc +#define GL_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70 +#define GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT 0x8C71 +#define GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72 +#define GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT 0x8C73 +#endif + +#ifndef GL_EXT_texture_compression_rgtc +#define GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB +#define GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC +#define GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD +#define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE +#endif + +#ifndef GL_EXT_texture_shared_exponent +#define GL_RGB9_E5_EXT 0x8C3D +#define GL_UNSIGNED_INT_5_9_9_9_REV_EXT 0x8C3E +#define GL_TEXTURE_SHARED_SIZE_EXT 0x8C3F +#endif + +#ifndef GL_NV_depth_buffer_float +#define GL_DEPTH_COMPONENT32F_NV 0x8DAB +#define GL_DEPTH32F_STENCIL8_NV 0x8DAC +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV_NV 0x8DAD +#define GL_DEPTH_BUFFER_FLOAT_MODE_NV 0x8DAF +#endif + +#ifndef GL_NV_fragment_program4 +#endif + +#ifndef GL_NV_framebuffer_multisample_coverage +#define GL_RENDERBUFFER_COVERAGE_SAMPLES_NV 0x8CAB +#define GL_RENDERBUFFER_COLOR_SAMPLES_NV 0x8E10 +#define GL_MAX_MULTISAMPLE_COVERAGE_MODES_NV 0x8E11 +#define GL_MULTISAMPLE_COVERAGE_MODES_NV 0x8E12 +#endif + +#ifndef GL_EXT_framebuffer_sRGB +#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9 +#define GL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x8DBA +#endif + +#ifndef GL_NV_geometry_shader4 +#endif + +#ifndef GL_NV_parameter_buffer_object +#define GL_MAX_PROGRAM_PARAMETER_BUFFER_BINDINGS_NV 0x8DA0 +#define GL_MAX_PROGRAM_PARAMETER_BUFFER_SIZE_NV 0x8DA1 +#define GL_VERTEX_PROGRAM_PARAMETER_BUFFER_NV 0x8DA2 +#define GL_GEOMETRY_PROGRAM_PARAMETER_BUFFER_NV 0x8DA3 +#define GL_FRAGMENT_PROGRAM_PARAMETER_BUFFER_NV 0x8DA4 +#endif + +#ifndef GL_EXT_draw_buffers2 +#endif + +#ifndef GL_NV_transform_feedback +#define GL_BACK_PRIMARY_COLOR_NV 0x8C77 +#define GL_BACK_SECONDARY_COLOR_NV 0x8C78 +#define GL_TEXTURE_COORD_NV 0x8C79 +#define GL_CLIP_DISTANCE_NV 0x8C7A +#define GL_VERTEX_ID_NV 0x8C7B +#define GL_PRIMITIVE_ID_NV 0x8C7C +#define GL_GENERIC_ATTRIB_NV 0x8C7D +#define GL_TRANSFORM_FEEDBACK_ATTRIBS_NV 0x8C7E +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_NV 0x8C7F +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_NV 0x8C80 +#define GL_ACTIVE_VARYINGS_NV 0x8C81 +#define GL_ACTIVE_VARYING_MAX_LENGTH_NV 0x8C82 +#define GL_TRANSFORM_FEEDBACK_VARYINGS_NV 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_START_NV 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_NV 0x8C85 +#define GL_TRANSFORM_FEEDBACK_RECORD_NV 0x8C86 +#define GL_PRIMITIVES_GENERATED_NV 0x8C87 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_NV 0x8C88 +#define GL_RASTERIZER_DISCARD_NV 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_ATTRIBS_NV 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_NV 0x8C8B +#define GL_INTERLEAVED_ATTRIBS_NV 0x8C8C +#define GL_SEPARATE_ATTRIBS_NV 0x8C8D +#define GL_TRANSFORM_FEEDBACK_BUFFER_NV 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_NV 0x8C8F +#endif + +#ifndef GL_EXT_bindable_uniform +#define GL_MAX_VERTEX_BINDABLE_UNIFORMS_EXT 0x8DE2 +#define GL_MAX_FRAGMENT_BINDABLE_UNIFORMS_EXT 0x8DE3 +#define GL_MAX_GEOMETRY_BINDABLE_UNIFORMS_EXT 0x8DE4 +#define GL_MAX_BINDABLE_UNIFORM_SIZE_EXT 0x8DED +#define GL_UNIFORM_BUFFER_EXT 0x8DEE +#define GL_UNIFORM_BUFFER_BINDING_EXT 0x8DEF +#endif + +#ifndef GL_EXT_texture_integer +#define GL_RGBA32UI_EXT 0x8D70 +#define GL_RGB32UI_EXT 0x8D71 +#define GL_ALPHA32UI_EXT 0x8D72 +#define GL_INTENSITY32UI_EXT 0x8D73 +#define GL_LUMINANCE32UI_EXT 0x8D74 +#define GL_LUMINANCE_ALPHA32UI_EXT 0x8D75 +#define GL_RGBA16UI_EXT 0x8D76 +#define GL_RGB16UI_EXT 0x8D77 +#define GL_ALPHA16UI_EXT 0x8D78 +#define GL_INTENSITY16UI_EXT 0x8D79 +#define GL_LUMINANCE16UI_EXT 0x8D7A +#define GL_LUMINANCE_ALPHA16UI_EXT 0x8D7B +#define GL_RGBA8UI_EXT 0x8D7C +#define GL_RGB8UI_EXT 0x8D7D +#define GL_ALPHA8UI_EXT 0x8D7E +#define GL_INTENSITY8UI_EXT 0x8D7F +#define GL_LUMINANCE8UI_EXT 0x8D80 +#define GL_LUMINANCE_ALPHA8UI_EXT 0x8D81 +#define GL_RGBA32I_EXT 0x8D82 +#define GL_RGB32I_EXT 0x8D83 +#define GL_ALPHA32I_EXT 0x8D84 +#define GL_INTENSITY32I_EXT 0x8D85 +#define GL_LUMINANCE32I_EXT 0x8D86 +#define GL_LUMINANCE_ALPHA32I_EXT 0x8D87 +#define GL_RGBA16I_EXT 0x8D88 +#define GL_RGB16I_EXT 0x8D89 +#define GL_ALPHA16I_EXT 0x8D8A +#define GL_INTENSITY16I_EXT 0x8D8B +#define GL_LUMINANCE16I_EXT 0x8D8C +#define GL_LUMINANCE_ALPHA16I_EXT 0x8D8D +#define GL_RGBA8I_EXT 0x8D8E +#define GL_RGB8I_EXT 0x8D8F +#define GL_ALPHA8I_EXT 0x8D90 +#define GL_INTENSITY8I_EXT 0x8D91 +#define GL_LUMINANCE8I_EXT 0x8D92 +#define GL_LUMINANCE_ALPHA8I_EXT 0x8D93 +#define GL_RED_INTEGER_EXT 0x8D94 +#define GL_GREEN_INTEGER_EXT 0x8D95 +#define GL_BLUE_INTEGER_EXT 0x8D96 +#define GL_ALPHA_INTEGER_EXT 0x8D97 +#define GL_RGB_INTEGER_EXT 0x8D98 +#define GL_RGBA_INTEGER_EXT 0x8D99 +#define GL_BGR_INTEGER_EXT 0x8D9A +#define GL_BGRA_INTEGER_EXT 0x8D9B +#define GL_LUMINANCE_INTEGER_EXT 0x8D9C +#define GL_LUMINANCE_ALPHA_INTEGER_EXT 0x8D9D +#define GL_RGBA_INTEGER_MODE_EXT 0x8D9E +#endif + +#ifndef GL_GREMEDY_frame_terminator +#endif + +#ifndef GL_NV_conditional_render +#define GL_QUERY_WAIT_NV 0x8E13 +#define GL_QUERY_NO_WAIT_NV 0x8E14 +#define GL_QUERY_BY_REGION_WAIT_NV 0x8E15 +#define GL_QUERY_BY_REGION_NO_WAIT_NV 0x8E16 +#endif + +#ifndef GL_NV_present_video +#define GL_FRAME_NV 0x8E26 +#define GL_FIELDS_NV 0x8E27 +#define GL_CURRENT_TIME_NV 0x8E28 +#define GL_NUM_FILL_STREAMS_NV 0x8E29 +#define GL_PRESENT_TIME_NV 0x8E2A +#define GL_PRESENT_DURATION_NV 0x8E2B +#endif + +#ifndef GL_EXT_transform_feedback +#define GL_TRANSFORM_FEEDBACK_BUFFER_EXT 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_START_EXT 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_EXT 0x8C85 +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_EXT 0x8C8F +#define GL_INTERLEAVED_ATTRIBS_EXT 0x8C8C +#define GL_SEPARATE_ATTRIBS_EXT 0x8C8D +#define GL_PRIMITIVES_GENERATED_EXT 0x8C87 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_EXT 0x8C88 +#define GL_RASTERIZER_DISCARD_EXT 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_EXT 0x8C8B +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT 0x8C80 +#define GL_TRANSFORM_FEEDBACK_VARYINGS_EXT 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_EXT 0x8C7F +#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH_EXT 0x8C76 +#endif + +#ifndef GL_EXT_direct_state_access +#define GL_PROGRAM_MATRIX_EXT 0x8E2D +#define GL_TRANSPOSE_PROGRAM_MATRIX_EXT 0x8E2E +#define GL_PROGRAM_MATRIX_STACK_DEPTH_EXT 0x8E2F +#endif + +#ifndef GL_EXT_vertex_array_bgra +/* reuse GL_BGRA */ +#endif + +#ifndef GL_EXT_texture_swizzle +#define GL_TEXTURE_SWIZZLE_R_EXT 0x8E42 +#define GL_TEXTURE_SWIZZLE_G_EXT 0x8E43 +#define GL_TEXTURE_SWIZZLE_B_EXT 0x8E44 +#define GL_TEXTURE_SWIZZLE_A_EXT 0x8E45 +#define GL_TEXTURE_SWIZZLE_RGBA_EXT 0x8E46 +#endif + +#ifndef GL_NV_explicit_multisample +#define GL_SAMPLE_POSITION_NV 0x8E50 +#define GL_SAMPLE_MASK_NV 0x8E51 +#define GL_SAMPLE_MASK_VALUE_NV 0x8E52 +#define GL_TEXTURE_BINDING_RENDERBUFFER_NV 0x8E53 +#define GL_TEXTURE_RENDERBUFFER_DATA_STORE_BINDING_NV 0x8E54 +#define GL_TEXTURE_RENDERBUFFER_NV 0x8E55 +#define GL_SAMPLER_RENDERBUFFER_NV 0x8E56 +#define GL_INT_SAMPLER_RENDERBUFFER_NV 0x8E57 +#define GL_UNSIGNED_INT_SAMPLER_RENDERBUFFER_NV 0x8E58 +#define GL_MAX_SAMPLE_MASK_WORDS_NV 0x8E59 +#endif + +#ifndef GL_NV_transform_feedback2 +#define GL_TRANSFORM_FEEDBACK_NV 0x8E22 +#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED_NV 0x8E23 +#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE_NV 0x8E24 +#define GL_TRANSFORM_FEEDBACK_BINDING_NV 0x8E25 +#endif + +#ifndef GL_ATI_meminfo +#define GL_VBO_FREE_MEMORY_ATI 0x87FB +#define GL_TEXTURE_FREE_MEMORY_ATI 0x87FC +#define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD +#endif + +#ifndef GL_AMD_performance_monitor +#define GL_COUNTER_TYPE_AMD 0x8BC0 +#define GL_COUNTER_RANGE_AMD 0x8BC1 +#define GL_UNSIGNED_INT64_AMD 0x8BC2 +#define GL_PERCENTAGE_AMD 0x8BC3 +#define GL_PERFMON_RESULT_AVAILABLE_AMD 0x8BC4 +#define GL_PERFMON_RESULT_SIZE_AMD 0x8BC5 +#define GL_PERFMON_RESULT_AMD 0x8BC6 +#endif + +#ifndef GL_AMD_texture_texture4 +#endif + +#ifndef GL_AMD_vertex_shader_tesselator +#define GL_SAMPLER_BUFFER_AMD 0x9001 +#define GL_INT_SAMPLER_BUFFER_AMD 0x9002 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER_AMD 0x9003 +#define GL_TESSELLATION_MODE_AMD 0x9004 +#define GL_TESSELLATION_FACTOR_AMD 0x9005 +#define GL_DISCRETE_AMD 0x9006 +#define GL_CONTINUOUS_AMD 0x9007 +#endif + +#ifndef GL_EXT_provoking_vertex +#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT 0x8E4C +#define GL_FIRST_VERTEX_CONVENTION_EXT 0x8E4D +#define GL_LAST_VERTEX_CONVENTION_EXT 0x8E4E +#define GL_PROVOKING_VERTEX_EXT 0x8E4F +#endif + +#ifndef GL_EXT_texture_snorm +#define GL_ALPHA_SNORM 0x9010 +#define GL_LUMINANCE_SNORM 0x9011 +#define GL_LUMINANCE_ALPHA_SNORM 0x9012 +#define GL_INTENSITY_SNORM 0x9013 +#define GL_ALPHA8_SNORM 0x9014 +#define GL_LUMINANCE8_SNORM 0x9015 +#define GL_LUMINANCE8_ALPHA8_SNORM 0x9016 +#define GL_INTENSITY8_SNORM 0x9017 +#define GL_ALPHA16_SNORM 0x9018 +#define GL_LUMINANCE16_SNORM 0x9019 +#define GL_LUMINANCE16_ALPHA16_SNORM 0x901A +#define GL_INTENSITY16_SNORM 0x901B +/* reuse GL_R_SNORM */ +/* reuse GL_RG_SNORM */ +/* reuse GL_RGB_SNORM */ +/* reuse GL_RGBA_SNORM */ +/* reuse GL_R8_SNORM */ +/* reuse GL_RG8_SNORM */ +/* reuse GL_RGB8_SNORM */ +/* reuse GL_RGBA8_SNORM */ +/* reuse GL_R16_SNORM */ +/* reuse GL_RG16_SNORM */ +/* reuse GL_RGB16_SNORM */ +/* reuse GL_RGBA16_SNORM */ +/* reuse GL_SIGNED_NORMALIZED */ +#endif + +#ifndef GL_AMD_draw_buffers_blend +#endif + +#ifndef GL_APPLE_texture_range +#define GL_TEXTURE_RANGE_LENGTH_APPLE 0x85B7 +#define GL_TEXTURE_RANGE_POINTER_APPLE 0x85B8 +#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC +#define GL_STORAGE_PRIVATE_APPLE 0x85BD +/* reuse GL_STORAGE_CACHED_APPLE */ +/* reuse GL_STORAGE_SHARED_APPLE */ +#endif + +#ifndef GL_APPLE_float_pixels +#define GL_HALF_APPLE 0x140B +#define GL_RGBA_FLOAT32_APPLE 0x8814 +#define GL_RGB_FLOAT32_APPLE 0x8815 +#define GL_ALPHA_FLOAT32_APPLE 0x8816 +#define GL_INTENSITY_FLOAT32_APPLE 0x8817 +#define GL_LUMINANCE_FLOAT32_APPLE 0x8818 +#define GL_LUMINANCE_ALPHA_FLOAT32_APPLE 0x8819 +#define GL_RGBA_FLOAT16_APPLE 0x881A +#define GL_RGB_FLOAT16_APPLE 0x881B +#define GL_ALPHA_FLOAT16_APPLE 0x881C +#define GL_INTENSITY_FLOAT16_APPLE 0x881D +#define GL_LUMINANCE_FLOAT16_APPLE 0x881E +#define GL_LUMINANCE_ALPHA_FLOAT16_APPLE 0x881F +#define GL_COLOR_FLOAT_APPLE 0x8A0F +#endif + +#ifndef GL_APPLE_vertex_program_evaluators +#define GL_VERTEX_ATTRIB_MAP1_APPLE 0x8A00 +#define GL_VERTEX_ATTRIB_MAP2_APPLE 0x8A01 +#define GL_VERTEX_ATTRIB_MAP1_SIZE_APPLE 0x8A02 +#define GL_VERTEX_ATTRIB_MAP1_COEFF_APPLE 0x8A03 +#define GL_VERTEX_ATTRIB_MAP1_ORDER_APPLE 0x8A04 +#define GL_VERTEX_ATTRIB_MAP1_DOMAIN_APPLE 0x8A05 +#define GL_VERTEX_ATTRIB_MAP2_SIZE_APPLE 0x8A06 +#define GL_VERTEX_ATTRIB_MAP2_COEFF_APPLE 0x8A07 +#define GL_VERTEX_ATTRIB_MAP2_ORDER_APPLE 0x8A08 +#define GL_VERTEX_ATTRIB_MAP2_DOMAIN_APPLE 0x8A09 +#endif + +#ifndef GL_APPLE_aux_depth_stencil +#define GL_AUX_DEPTH_STENCIL_APPLE 0x8A14 +#endif + +#ifndef GL_APPLE_object_purgeable +#define GL_BUFFER_OBJECT_APPLE 0x85B3 +#define GL_RELEASED_APPLE 0x8A19 +#define GL_VOLATILE_APPLE 0x8A1A +#define GL_RETAINED_APPLE 0x8A1B +#define GL_UNDEFINED_APPLE 0x8A1C +#define GL_PURGEABLE_APPLE 0x8A1D +#endif + +#ifndef GL_APPLE_row_bytes +#define GL_PACK_ROW_BYTES_APPLE 0x8A15 +#define GL_UNPACK_ROW_BYTES_APPLE 0x8A16 +#endif + + +/*************************************************************/ + +#include +#ifndef GL_VERSION_2_0 +/* GL type for program/shader text */ +typedef char GLchar; +#endif + +#ifndef GL_VERSION_1_5 +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptr; +typedef ptrdiff_t GLsizeiptr; +#endif + +#ifndef GL_ARB_vertex_buffer_object +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptrARB; +typedef ptrdiff_t GLsizeiptrARB; +#endif + +#ifndef GL_ARB_shader_objects +/* GL types for program/shader text and shader object handles */ +typedef char GLcharARB; +typedef unsigned int GLhandleARB; +#endif + +/* GL type for "half" precision (s10e5) float data in host memory */ +#ifndef GL_ARB_half_float_pixel +typedef unsigned short GLhalfARB; +#endif + +#ifndef GL_NV_half_float +typedef unsigned short GLhalfNV; +#endif + +#ifndef GLEXT_64_TYPES_DEFINED +/* This code block is duplicated in glxext.h, so must be protected */ +#define GLEXT_64_TYPES_DEFINED +/* Define int32_t, int64_t, and uint64_t types for UST/MSC */ +/* (as used in the GL_EXT_timer_query extension). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#include +#elif defined(__sun__) || defined(__digital__) +#include +#if defined(__STDC__) +#if defined(__arch64__) || defined(_LP64) +typedef long int int64_t; +typedef unsigned long int uint64_t; +#else +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#endif /* __arch64__ */ +#endif /* __STDC__ */ +#elif defined( __VMS ) || defined(__sgi) +#include +#elif defined(__SCO__) || defined(__USLC__) +#include +#elif defined(__UNIXOS2__) || defined(__SOL64__) +typedef long int int32_t; +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#elif defined(_WIN32) && defined(__GNUC__) +#include +#elif defined(_WIN32) +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#else +/* Fallback if nothing above works */ +#include +#endif +#endif + +#ifndef GL_EXT_timer_query +typedef int64_t GLint64EXT; +typedef uint64_t GLuint64EXT; +#endif + +#ifndef ARB_sync +typedef int64_t GLint64; +typedef uint64_t GLuint64; +typedef struct __GLsync *GLsync; +#endif + +#ifndef GL_VERSION_1_2 +#define GL_VERSION_1_2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendColor (GLclampf, GLclampf, GLclampf, GLclampf); +GLAPI void APIENTRY glBlendEquation (GLenum); +GLAPI void APIENTRY glDrawRangeElements (GLenum, GLuint, GLuint, GLsizei, GLenum, const GLvoid *); +GLAPI void APIENTRY glTexImage3D (GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glCopyTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_VERSION_1_2_DEPRECATED +#define GL_VERSION_1_2_DEPRECATED 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTable (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glColorTableParameterfv (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glColorTableParameteriv (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glCopyColorTable (GLenum, GLenum, GLint, GLint, GLsizei); +GLAPI void APIENTRY glGetColorTable (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetColorTableParameterfv (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetColorTableParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glColorSubTable (GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glCopyColorSubTable (GLenum, GLsizei, GLint, GLint, GLsizei); +GLAPI void APIENTRY glConvolutionFilter1D (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glConvolutionFilter2D (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glConvolutionParameterf (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glConvolutionParameterfv (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glConvolutionParameteri (GLenum, GLenum, GLint); +GLAPI void APIENTRY glConvolutionParameteriv (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glCopyConvolutionFilter1D (GLenum, GLenum, GLint, GLint, GLsizei); +GLAPI void APIENTRY glCopyConvolutionFilter2D (GLenum, GLenum, GLint, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glGetConvolutionFilter (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetConvolutionParameterfv (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetConvolutionParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetSeparableFilter (GLenum, GLenum, GLenum, GLvoid *, GLvoid *, GLvoid *); +GLAPI void APIENTRY glSeparableFilter2D (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *, const GLvoid *); +GLAPI void APIENTRY glGetHistogram (GLenum, GLboolean, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetHistogramParameterfv (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetHistogramParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetMinmax (GLenum, GLboolean, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetMinmaxParameterfv (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetMinmaxParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glHistogram (GLenum, GLsizei, GLenum, GLboolean); +GLAPI void APIENTRY glMinmax (GLenum, GLenum, GLboolean); +GLAPI void APIENTRY glResetHistogram (GLenum); +GLAPI void APIENTRY glResetMinmax (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIPROC) (GLenum target, GLenum pname, GLint params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSEPARABLEFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMINMAXPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLHISTOGRAMPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLMINMAXPROC) (GLenum target, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLRESETHISTOGRAMPROC) (GLenum target); +typedef void (APIENTRYP PFNGLRESETMINMAXPROC) (GLenum target); +#endif + +#ifndef GL_VERSION_1_3 +#define GL_VERSION_1_3 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveTexture (GLenum); +GLAPI void APIENTRY glSampleCoverage (GLclampf, GLboolean); +GLAPI void APIENTRY glCompressedTexImage3D (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexImage2D (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexImage1D (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glGetCompressedTexImage (GLenum, GLint, GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); +#endif + +#ifndef GL_VERSION_1_3_DEPRECATED +#define GL_VERSION_1_3_DEPRECATED 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClientActiveTexture (GLenum); +GLAPI void APIENTRY glMultiTexCoord1d (GLenum, GLdouble); +GLAPI void APIENTRY glMultiTexCoord1dv (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord1f (GLenum, GLfloat); +GLAPI void APIENTRY glMultiTexCoord1fv (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord1i (GLenum, GLint); +GLAPI void APIENTRY glMultiTexCoord1iv (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord1s (GLenum, GLshort); +GLAPI void APIENTRY glMultiTexCoord1sv (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord2d (GLenum, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord2dv (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord2f (GLenum, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord2fv (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord2i (GLenum, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord2iv (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord2s (GLenum, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord2sv (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord3d (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord3dv (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord3f (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord3fv (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord3i (GLenum, GLint, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord3iv (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord3s (GLenum, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord3sv (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord4d (GLenum, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord4dv (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord4f (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord4fv (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord4i (GLenum, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord4iv (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord4s (GLenum, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord4sv (GLenum, const GLshort *); +GLAPI void APIENTRY glLoadTransposeMatrixf (const GLfloat *); +GLAPI void APIENTRY glLoadTransposeMatrixd (const GLdouble *); +GLAPI void APIENTRY glMultTransposeMatrixf (const GLfloat *); +GLAPI void APIENTRY glMultTransposeMatrixd (const GLdouble *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDPROC) (const GLdouble *m); +#endif + +#ifndef GL_VERSION_1_4 +#define GL_VERSION_1_4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparate (GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glMultiDrawArrays (GLenum, GLint *, GLsizei *, GLsizei); +GLAPI void APIENTRY glMultiDrawElements (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); +GLAPI void APIENTRY glPointParameterf (GLenum, GLfloat); +GLAPI void APIENTRY glPointParameterfv (GLenum, const GLfloat *); +GLAPI void APIENTRY glPointParameteri (GLenum, GLint); +GLAPI void APIENTRY glPointParameteriv (GLenum, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_VERSION_1_4_DEPRECATED +#define GL_VERSION_1_4_DEPRECATED 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogCoordf (GLfloat); +GLAPI void APIENTRY glFogCoordfv (const GLfloat *); +GLAPI void APIENTRY glFogCoordd (GLdouble); +GLAPI void APIENTRY glFogCoorddv (const GLdouble *); +GLAPI void APIENTRY glFogCoordPointer (GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glSecondaryColor3b (GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glSecondaryColor3bv (const GLbyte *); +GLAPI void APIENTRY glSecondaryColor3d (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glSecondaryColor3dv (const GLdouble *); +GLAPI void APIENTRY glSecondaryColor3f (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glSecondaryColor3fv (const GLfloat *); +GLAPI void APIENTRY glSecondaryColor3i (GLint, GLint, GLint); +GLAPI void APIENTRY glSecondaryColor3iv (const GLint *); +GLAPI void APIENTRY glSecondaryColor3s (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glSecondaryColor3sv (const GLshort *); +GLAPI void APIENTRY glSecondaryColor3ub (GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glSecondaryColor3ubv (const GLubyte *); +GLAPI void APIENTRY glSecondaryColor3ui (GLuint, GLuint, GLuint); +GLAPI void APIENTRY glSecondaryColor3uiv (const GLuint *); +GLAPI void APIENTRY glSecondaryColor3us (GLushort, GLushort, GLushort); +GLAPI void APIENTRY glSecondaryColor3usv (const GLushort *); +GLAPI void APIENTRY glSecondaryColorPointer (GLint, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glWindowPos2d (GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos2dv (const GLdouble *); +GLAPI void APIENTRY glWindowPos2f (GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos2fv (const GLfloat *); +GLAPI void APIENTRY glWindowPos2i (GLint, GLint); +GLAPI void APIENTRY glWindowPos2iv (const GLint *); +GLAPI void APIENTRY glWindowPos2s (GLshort, GLshort); +GLAPI void APIENTRY glWindowPos2sv (const GLshort *); +GLAPI void APIENTRY glWindowPos3d (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos3dv (const GLdouble *); +GLAPI void APIENTRY glWindowPos3f (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos3fv (const GLfloat *); +GLAPI void APIENTRY glWindowPos3i (GLint, GLint, GLint); +GLAPI void APIENTRY glWindowPos3iv (const GLint *); +GLAPI void APIENTRY glWindowPos3s (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glWindowPos3sv (const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFOGCOORDFPROC) (GLfloat coord); +typedef void (APIENTRYP PFNGLFOGCOORDFVPROC) (const GLfloat *coord); +typedef void (APIENTRYP PFNGLFOGCOORDDPROC) (GLdouble coord); +typedef void (APIENTRYP PFNGLFOGCOORDDVPROC) (const GLdouble *coord); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BPROC) (GLbyte red, GLbyte green, GLbyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DPROC) (GLdouble red, GLdouble green, GLdouble blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FPROC) (GLfloat red, GLfloat green, GLfloat blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IPROC) (GLint red, GLint green, GLint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SPROC) (GLshort red, GLshort green, GLshort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBPROC) (GLubyte red, GLubyte green, GLubyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVPROC) (const GLubyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIPROC) (GLuint red, GLuint green, GLuint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVPROC) (const GLuint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USPROC) (GLushort red, GLushort green, GLushort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVPROC) (const GLushort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLWINDOWPOS2DPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVPROC) (const GLshort *v); +#endif + +#ifndef GL_VERSION_1_5 +#define GL_VERSION_1_5 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenQueries (GLsizei, GLuint *); +GLAPI void APIENTRY glDeleteQueries (GLsizei, const GLuint *); +GLAPI GLboolean APIENTRY glIsQuery (GLuint); +GLAPI void APIENTRY glBeginQuery (GLenum, GLuint); +GLAPI void APIENTRY glEndQuery (GLenum); +GLAPI void APIENTRY glGetQueryiv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetQueryObjectiv (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetQueryObjectuiv (GLuint, GLenum, GLuint *); +GLAPI void APIENTRY glBindBuffer (GLenum, GLuint); +GLAPI void APIENTRY glDeleteBuffers (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenBuffers (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsBuffer (GLuint); +GLAPI void APIENTRY glBufferData (GLenum, GLsizeiptr, const GLvoid *, GLenum); +GLAPI void APIENTRY glBufferSubData (GLenum, GLintptr, GLsizeiptr, const GLvoid *); +GLAPI void APIENTRY glGetBufferSubData (GLenum, GLintptr, GLsizeiptr, GLvoid *); +GLAPI GLvoid* APIENTRY glMapBuffer (GLenum, GLenum); +GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum); +GLAPI void APIENTRY glGetBufferParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetBufferPointerv (GLenum, GLenum, GLvoid* *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_VERSION_2_0 +#define GL_VERSION_2_0 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparate (GLenum, GLenum); +GLAPI void APIENTRY glDrawBuffers (GLsizei, const GLenum *); +GLAPI void APIENTRY glStencilOpSeparate (GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glStencilFuncSeparate (GLenum, GLenum, GLint, GLuint); +GLAPI void APIENTRY glStencilMaskSeparate (GLenum, GLuint); +GLAPI void APIENTRY glAttachShader (GLuint, GLuint); +GLAPI void APIENTRY glBindAttribLocation (GLuint, GLuint, const GLchar *); +GLAPI void APIENTRY glCompileShader (GLuint); +GLAPI GLuint APIENTRY glCreateProgram (void); +GLAPI GLuint APIENTRY glCreateShader (GLenum); +GLAPI void APIENTRY glDeleteProgram (GLuint); +GLAPI void APIENTRY glDeleteShader (GLuint); +GLAPI void APIENTRY glDetachShader (GLuint, GLuint); +GLAPI void APIENTRY glDisableVertexAttribArray (GLuint); +GLAPI void APIENTRY glEnableVertexAttribArray (GLuint); +GLAPI void APIENTRY glGetActiveAttrib (GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *); +GLAPI void APIENTRY glGetActiveUniform (GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *); +GLAPI void APIENTRY glGetAttachedShaders (GLuint, GLsizei, GLsizei *, GLuint *); +GLAPI GLint APIENTRY glGetAttribLocation (GLuint, const GLchar *); +GLAPI void APIENTRY glGetProgramiv (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetProgramInfoLog (GLuint, GLsizei, GLsizei *, GLchar *); +GLAPI void APIENTRY glGetShaderiv (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetShaderInfoLog (GLuint, GLsizei, GLsizei *, GLchar *); +GLAPI void APIENTRY glGetShaderSource (GLuint, GLsizei, GLsizei *, GLchar *); +GLAPI GLint APIENTRY glGetUniformLocation (GLuint, const GLchar *); +GLAPI void APIENTRY glGetUniformfv (GLuint, GLint, GLfloat *); +GLAPI void APIENTRY glGetUniformiv (GLuint, GLint, GLint *); +GLAPI void APIENTRY glGetVertexAttribdv (GLuint, GLenum, GLdouble *); +GLAPI void APIENTRY glGetVertexAttribfv (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVertexAttribiv (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint, GLenum, GLvoid* *); +GLAPI GLboolean APIENTRY glIsProgram (GLuint); +GLAPI GLboolean APIENTRY glIsShader (GLuint); +GLAPI void APIENTRY glLinkProgram (GLuint); +GLAPI void APIENTRY glShaderSource (GLuint, GLsizei, const GLchar* *, const GLint *); +GLAPI void APIENTRY glUseProgram (GLuint); +GLAPI void APIENTRY glUniform1f (GLint, GLfloat); +GLAPI void APIENTRY glUniform2f (GLint, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform3f (GLint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform4f (GLint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform1i (GLint, GLint); +GLAPI void APIENTRY glUniform2i (GLint, GLint, GLint); +GLAPI void APIENTRY glUniform3i (GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glUniform4i (GLint, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glUniform1fv (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform2fv (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform3fv (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform4fv (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform1iv (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform2iv (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform3iv (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform4iv (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniformMatrix2fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix3fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix4fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glValidateProgram (GLuint); +GLAPI void APIENTRY glVertexAttrib1d (GLuint, GLdouble); +GLAPI void APIENTRY glVertexAttrib1dv (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib1f (GLuint, GLfloat); +GLAPI void APIENTRY glVertexAttrib1fv (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib1s (GLuint, GLshort); +GLAPI void APIENTRY glVertexAttrib1sv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib2d (GLuint, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib2dv (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib2f (GLuint, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib2fv (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib2s (GLuint, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib2sv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib3d (GLuint, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib3dv (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib3f (GLuint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib3fv (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib3s (GLuint, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib3sv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttrib4Niv (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4Nub (GLuint, GLubyte, GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint, const GLushort *); +GLAPI void APIENTRY glVertexAttrib4bv (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttrib4d (GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib4dv (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib4f (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib4fv (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib4iv (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttrib4s (GLuint, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib4sv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4ubv (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttrib4uiv (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttrib4usv (GLuint, const GLushort *); +GLAPI void APIENTRY glVertexAttribPointer (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs); +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); +typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask); +typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name); +typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); +typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); +typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); +typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* *string, const GLint *length); +typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_VERSION_2_1 +#define GL_VERSION_2_1 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniformMatrix2x3fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix3x2fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix2x4fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix4x2fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix3x4fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix4x3fv (GLint, GLsizei, GLboolean, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +#endif + +#ifndef GL_VERSION_3_0 +#define GL_VERSION_3_0 1 +/* OpenGL 3.0 also reuses entry points from these extensions: */ +/* ARB_framebuffer_object */ +/* ARB_map_buffer_range */ +/* ARB_vertex_array_object */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorMaski (GLuint, GLboolean, GLboolean, GLboolean, GLboolean); +GLAPI void APIENTRY glGetBooleani_v (GLenum, GLuint, GLboolean *); +GLAPI void APIENTRY glGetIntegeri_v (GLenum, GLuint, GLint *); +GLAPI void APIENTRY glEnablei (GLenum, GLuint); +GLAPI void APIENTRY glDisablei (GLenum, GLuint); +GLAPI GLboolean APIENTRY glIsEnabledi (GLenum, GLuint); +GLAPI void APIENTRY glBeginTransformFeedback (GLenum); +GLAPI void APIENTRY glEndTransformFeedback (void); +GLAPI void APIENTRY glBindBufferRange (GLenum, GLuint, GLuint, GLintptr, GLsizeiptr); +GLAPI void APIENTRY glBindBufferBase (GLenum, GLuint, GLuint); +GLAPI void APIENTRY glTransformFeedbackVaryings (GLuint, GLsizei, const GLchar* *, GLenum); +GLAPI void APIENTRY glGetTransformFeedbackVarying (GLuint, GLuint, GLsizei, GLsizei *, GLsizei *, GLenum *, GLchar *); +GLAPI void APIENTRY glClampColor (GLenum, GLenum); +GLAPI void APIENTRY glBeginConditionalRender (GLuint, GLenum); +GLAPI void APIENTRY glEndConditionalRender (void); +GLAPI void APIENTRY glVertexAttribIPointer (GLuint, GLint, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glGetVertexAttribIiv (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribIuiv (GLuint, GLenum, GLuint *); +GLAPI void APIENTRY glVertexAttribI1i (GLuint, GLint); +GLAPI void APIENTRY glVertexAttribI2i (GLuint, GLint, GLint); +GLAPI void APIENTRY glVertexAttribI3i (GLuint, GLint, GLint, GLint); +GLAPI void APIENTRY glVertexAttribI4i (GLuint, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glVertexAttribI1ui (GLuint, GLuint); +GLAPI void APIENTRY glVertexAttribI2ui (GLuint, GLuint, GLuint); +GLAPI void APIENTRY glVertexAttribI3ui (GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glVertexAttribI4ui (GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glVertexAttribI1iv (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttribI2iv (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttribI3iv (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttribI4iv (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttribI1uiv (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttribI2uiv (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttribI3uiv (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttribI4uiv (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttribI4bv (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttribI4sv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttribI4ubv (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttribI4usv (GLuint, const GLushort *); +GLAPI void APIENTRY glGetUniformuiv (GLuint, GLint, GLuint *); +GLAPI void APIENTRY glBindFragDataLocation (GLuint, GLuint, const GLchar *); +GLAPI GLint APIENTRY glGetFragDataLocation (GLuint, const GLchar *); +GLAPI void APIENTRY glUniform1ui (GLint, GLuint); +GLAPI void APIENTRY glUniform2ui (GLint, GLuint, GLuint); +GLAPI void APIENTRY glUniform3ui (GLint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glUniform4ui (GLint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glUniform1uiv (GLint, GLsizei, const GLuint *); +GLAPI void APIENTRY glUniform2uiv (GLint, GLsizei, const GLuint *); +GLAPI void APIENTRY glUniform3uiv (GLint, GLsizei, const GLuint *); +GLAPI void APIENTRY glUniform4uiv (GLint, GLsizei, const GLuint *); +GLAPI void APIENTRY glTexParameterIiv (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glTexParameterIuiv (GLenum, GLenum, const GLuint *); +GLAPI void APIENTRY glGetTexParameterIiv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetTexParameterIuiv (GLenum, GLenum, GLuint *); +GLAPI void APIENTRY glClearBufferiv (GLenum, GLint, const GLint *); +GLAPI void APIENTRY glClearBufferuiv (GLenum, GLint, const GLuint *); +GLAPI void APIENTRY glClearBufferfv (GLenum, GLint, const GLfloat *); +GLAPI void APIENTRY glClearBufferfi (GLenum, GLint, GLfloat, GLint); +GLAPI const GLubyte * APIENTRY glGetStringi (GLenum, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORMASKIPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data); +typedef void (APIENTRYP PFNGLENABLEIPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLDISABLEIPROC) (GLenum target, GLuint index); +typedef GLboolean (APIENTRYP PFNGLISENABLEDIPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGEPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFERBASEPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSPROC) (GLuint program, GLsizei count, const GLchar* *varyings, GLenum bufferMode); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLCLAMPCOLORPROC) (GLenum target, GLenum clamp); +typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERPROC) (GLuint id, GLenum mode); +typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERPROC) (void); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVPROC) (GLuint index, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IPROC) (GLuint index, GLint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IPROC) (GLuint index, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IPROC) (GLuint index, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIPROC) (GLuint index, GLuint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIPROC) (GLuint index, GLuint x, GLuint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLGETUNIFORMUIVPROC) (GLuint program, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONPROC) (GLuint program, GLuint color, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORM1UIPROC) (GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLUNIFORM2UIPROC) (GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLUNIFORM3UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLUNIFORM4UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLUNIFORM1UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM2UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM3UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM4UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLCLEARBUFFERIVPROC) (GLenum buffer, GLint drawbuffer, const GLint *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERUIVPROC) (GLenum buffer, GLint drawbuffer, const GLuint *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERFVPROC) (GLenum buffer, GLint drawbuffer, const GLfloat *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERFIPROC) (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index); +#endif + +#ifndef GL_VERSION_3_1 +#define GL_VERSION_3_1 1 +/* OpenGL 3.1 also reuses entry points from these extensions: */ +/* ARB_copy_buffer */ +/* ARB_uniform_buffer_object */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstanced (GLenum, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glDrawElementsInstanced (GLenum, GLsizei, GLenum, const GLvoid *, GLsizei); +GLAPI void APIENTRY glTexBuffer (GLenum, GLenum, GLuint); +GLAPI void APIENTRY glPrimitiveRestartIndex (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +typedef void (APIENTRYP PFNGLTEXBUFFERPROC) (GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC) (GLuint index); +#endif + +#ifndef GL_VERSION_3_2 +#define GL_VERSION_3_2 1 +/* OpenGL 3.2 also reuses entry points from these extensions: */ +/* ARB_draw_elements_base_vertex */ +/* ARB_provoking_vertex */ +/* ARB_sync */ +/* ARB_texture_multisample */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetInteger64i_v (GLenum, GLuint, GLint64 *); +GLAPI void APIENTRY glGetBufferParameteri64v (GLenum, GLenum, GLint64 *); +GLAPI void APIENTRY glProgramParameteri (GLuint, GLenum, GLint); +GLAPI void APIENTRY glFramebufferTexture (GLenum, GLenum, GLuint, GLint); +GLAPI void APIENTRY glFramebufferTextureFace (GLenum, GLenum, GLuint, GLint, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERI64VPROC) (GLenum target, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC) (GLuint program, GLenum pname, GLint value); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#endif + +#ifndef GL_ARB_multitexture +#define GL_ARB_multitexture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveTextureARB (GLenum); +GLAPI void APIENTRY glClientActiveTextureARB (GLenum); +GLAPI void APIENTRY glMultiTexCoord1dARB (GLenum, GLdouble); +GLAPI void APIENTRY glMultiTexCoord1dvARB (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord1fARB (GLenum, GLfloat); +GLAPI void APIENTRY glMultiTexCoord1fvARB (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord1iARB (GLenum, GLint); +GLAPI void APIENTRY glMultiTexCoord1ivARB (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord1sARB (GLenum, GLshort); +GLAPI void APIENTRY glMultiTexCoord1svARB (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord2dARB (GLenum, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord2dvARB (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord2fARB (GLenum, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord2fvARB (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord2iARB (GLenum, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord2ivARB (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord2sARB (GLenum, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord2svARB (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord3dARB (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord3dvARB (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord3fARB (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord3fvARB (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord3iARB (GLenum, GLint, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord3ivARB (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord3sARB (GLenum, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord3svARB (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord4dARB (GLenum, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord4dvARB (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord4fARB (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord4fvARB (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord4iARB (GLenum, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord4ivARB (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord4sARB (GLenum, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord4svARB (GLenum, const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v); +#endif + +#ifndef GL_ARB_transpose_matrix +#define GL_ARB_transpose_matrix 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLoadTransposeMatrixfARB (const GLfloat *); +GLAPI void APIENTRY glLoadTransposeMatrixdARB (const GLdouble *); +GLAPI void APIENTRY glMultTransposeMatrixfARB (const GLfloat *); +GLAPI void APIENTRY glMultTransposeMatrixdARB (const GLdouble *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); +#endif + +#ifndef GL_ARB_multisample +#define GL_ARB_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleCoverageARB (GLclampf, GLboolean); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEARBPROC) (GLclampf value, GLboolean invert); +#endif + +#ifndef GL_ARB_texture_env_add +#define GL_ARB_texture_env_add 1 +#endif + +#ifndef GL_ARB_texture_cube_map +#define GL_ARB_texture_cube_map 1 +#endif + +#ifndef GL_ARB_texture_compression +#define GL_ARB_texture_compression 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCompressedTexImage3DARB (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexImage2DARB (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexImage1DARB (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage3DARB (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage2DARB (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage1DARB (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glGetCompressedTexImageARB (GLenum, GLint, GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint level, GLvoid *img); +#endif + +#ifndef GL_ARB_texture_border_clamp +#define GL_ARB_texture_border_clamp 1 +#endif + +#ifndef GL_ARB_point_parameters +#define GL_ARB_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfARB (GLenum, GLfloat); +GLAPI void APIENTRY glPointParameterfvARB (GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFARBPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVARBPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_ARB_vertex_blend +#define GL_ARB_vertex_blend 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWeightbvARB (GLint, const GLbyte *); +GLAPI void APIENTRY glWeightsvARB (GLint, const GLshort *); +GLAPI void APIENTRY glWeightivARB (GLint, const GLint *); +GLAPI void APIENTRY glWeightfvARB (GLint, const GLfloat *); +GLAPI void APIENTRY glWeightdvARB (GLint, const GLdouble *); +GLAPI void APIENTRY glWeightubvARB (GLint, const GLubyte *); +GLAPI void APIENTRY glWeightusvARB (GLint, const GLushort *); +GLAPI void APIENTRY glWeightuivARB (GLint, const GLuint *); +GLAPI void APIENTRY glWeightPointerARB (GLint, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glVertexBlendARB (GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWEIGHTBVARBPROC) (GLint size, const GLbyte *weights); +typedef void (APIENTRYP PFNGLWEIGHTSVARBPROC) (GLint size, const GLshort *weights); +typedef void (APIENTRYP PFNGLWEIGHTIVARBPROC) (GLint size, const GLint *weights); +typedef void (APIENTRYP PFNGLWEIGHTFVARBPROC) (GLint size, const GLfloat *weights); +typedef void (APIENTRYP PFNGLWEIGHTDVARBPROC) (GLint size, const GLdouble *weights); +typedef void (APIENTRYP PFNGLWEIGHTUBVARBPROC) (GLint size, const GLubyte *weights); +typedef void (APIENTRYP PFNGLWEIGHTUSVARBPROC) (GLint size, const GLushort *weights); +typedef void (APIENTRYP PFNGLWEIGHTUIVARBPROC) (GLint size, const GLuint *weights); +typedef void (APIENTRYP PFNGLWEIGHTPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXBLENDARBPROC) (GLint count); +#endif + +#ifndef GL_ARB_matrix_palette +#define GL_ARB_matrix_palette 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCurrentPaletteMatrixARB (GLint); +GLAPI void APIENTRY glMatrixIndexubvARB (GLint, const GLubyte *); +GLAPI void APIENTRY glMatrixIndexusvARB (GLint, const GLushort *); +GLAPI void APIENTRY glMatrixIndexuivARB (GLint, const GLuint *); +GLAPI void APIENTRY glMatrixIndexPointerARB (GLint, GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCURRENTPALETTEMATRIXARBPROC) (GLint index); +typedef void (APIENTRYP PFNGLMATRIXINDEXUBVARBPROC) (GLint size, const GLubyte *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXUSVARBPROC) (GLint size, const GLushort *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXUIVARBPROC) (GLint size, const GLuint *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_ARB_texture_env_combine +#define GL_ARB_texture_env_combine 1 +#endif + +#ifndef GL_ARB_texture_env_crossbar +#define GL_ARB_texture_env_crossbar 1 +#endif + +#ifndef GL_ARB_texture_env_dot3 +#define GL_ARB_texture_env_dot3 1 +#endif + +#ifndef GL_ARB_texture_mirrored_repeat +#define GL_ARB_texture_mirrored_repeat 1 +#endif + +#ifndef GL_ARB_depth_texture +#define GL_ARB_depth_texture 1 +#endif + +#ifndef GL_ARB_shadow +#define GL_ARB_shadow 1 +#endif + +#ifndef GL_ARB_shadow_ambient +#define GL_ARB_shadow_ambient 1 +#endif + +#ifndef GL_ARB_window_pos +#define GL_ARB_window_pos 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWindowPos2dARB (GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos2dvARB (const GLdouble *); +GLAPI void APIENTRY glWindowPos2fARB (GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos2fvARB (const GLfloat *); +GLAPI void APIENTRY glWindowPos2iARB (GLint, GLint); +GLAPI void APIENTRY glWindowPos2ivARB (const GLint *); +GLAPI void APIENTRY glWindowPos2sARB (GLshort, GLshort); +GLAPI void APIENTRY glWindowPos2svARB (const GLshort *); +GLAPI void APIENTRY glWindowPos3dARB (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos3dvARB (const GLdouble *); +GLAPI void APIENTRY glWindowPos3fARB (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos3fvARB (const GLfloat *); +GLAPI void APIENTRY glWindowPos3iARB (GLint, GLint, GLint); +GLAPI void APIENTRY glWindowPos3ivARB (const GLint *); +GLAPI void APIENTRY glWindowPos3sARB (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glWindowPos3svARB (const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWINDOWPOS2DARBPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVARBPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FARBPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVARBPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IARBPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVARBPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SARBPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVARBPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DARBPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVARBPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FARBPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVARBPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IARBPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVARBPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SARBPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVARBPROC) (const GLshort *v); +#endif + +#ifndef GL_ARB_vertex_program +#define GL_ARB_vertex_program 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttrib1dARB (GLuint, GLdouble); +GLAPI void APIENTRY glVertexAttrib1dvARB (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib1fARB (GLuint, GLfloat); +GLAPI void APIENTRY glVertexAttrib1fvARB (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib1sARB (GLuint, GLshort); +GLAPI void APIENTRY glVertexAttrib1svARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib2dARB (GLuint, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib2dvARB (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib2fARB (GLuint, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib2fvARB (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib2sARB (GLuint, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib2svARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib3dARB (GLuint, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib3dvARB (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib3fARB (GLuint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib3fvARB (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib3sARB (GLuint, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib3svARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4NbvARB (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttrib4NivARB (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttrib4NsvARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4NubARB (GLuint, GLubyte, GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glVertexAttrib4NubvARB (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttrib4NuivARB (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttrib4NusvARB (GLuint, const GLushort *); +GLAPI void APIENTRY glVertexAttrib4bvARB (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttrib4dARB (GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib4dvARB (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib4fARB (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib4fvARB (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib4ivARB (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttrib4sARB (GLuint, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib4svARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4ubvARB (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttrib4uivARB (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttrib4usvARB (GLuint, const GLushort *); +GLAPI void APIENTRY glVertexAttribPointerARB (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid *); +GLAPI void APIENTRY glEnableVertexAttribArrayARB (GLuint); +GLAPI void APIENTRY glDisableVertexAttribArrayARB (GLuint); +GLAPI void APIENTRY glProgramStringARB (GLenum, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glBindProgramARB (GLenum, GLuint); +GLAPI void APIENTRY glDeleteProgramsARB (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenProgramsARB (GLsizei, GLuint *); +GLAPI void APIENTRY glProgramEnvParameter4dARB (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glProgramEnvParameter4dvARB (GLenum, GLuint, const GLdouble *); +GLAPI void APIENTRY glProgramEnvParameter4fARB (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramEnvParameter4fvARB (GLenum, GLuint, const GLfloat *); +GLAPI void APIENTRY glProgramLocalParameter4dARB (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glProgramLocalParameter4dvARB (GLenum, GLuint, const GLdouble *); +GLAPI void APIENTRY glProgramLocalParameter4fARB (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramLocalParameter4fvARB (GLenum, GLuint, const GLfloat *); +GLAPI void APIENTRY glGetProgramEnvParameterdvARB (GLenum, GLuint, GLdouble *); +GLAPI void APIENTRY glGetProgramEnvParameterfvARB (GLenum, GLuint, GLfloat *); +GLAPI void APIENTRY glGetProgramLocalParameterdvARB (GLenum, GLuint, GLdouble *); +GLAPI void APIENTRY glGetProgramLocalParameterfvARB (GLenum, GLuint, GLfloat *); +GLAPI void APIENTRY glGetProgramivARB (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetProgramStringARB (GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetVertexAttribdvARB (GLuint, GLenum, GLdouble *); +GLAPI void APIENTRY glGetVertexAttribfvARB (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVertexAttribivARB (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribPointervARB (GLuint, GLenum, GLvoid* *); +GLAPI GLboolean APIENTRY glIsProgramARB (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DARBPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FARBPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SARBPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DARBPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FARBPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SARBPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVARBPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVARBPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBARBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVARBPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVARBPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVARBPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVARBPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVARBPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVARBPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVARBPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVARBPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); +typedef void (APIENTRYP PFNGLPROGRAMSTRINGARBPROC) (GLenum target, GLenum format, GLsizei len, const GLvoid *string); +typedef void (APIENTRYP PFNGLBINDPROGRAMARBPROC) (GLenum target, GLuint program); +typedef void (APIENTRYP PFNGLDELETEPROGRAMSARBPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLGENPROGRAMSARBPROC) (GLsizei n, GLuint *programs); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGARBPROC) (GLenum target, GLenum pname, GLvoid *string); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVARBPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVARBPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVARBPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVARBPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMARBPROC) (GLuint program); +#endif + +#ifndef GL_ARB_fragment_program +#define GL_ARB_fragment_program 1 +/* All ARB_fragment_program entry points are shared with ARB_vertex_program. */ +#endif + +#ifndef GL_ARB_vertex_buffer_object +#define GL_ARB_vertex_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindBufferARB (GLenum, GLuint); +GLAPI void APIENTRY glDeleteBuffersARB (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenBuffersARB (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsBufferARB (GLuint); +GLAPI void APIENTRY glBufferDataARB (GLenum, GLsizeiptrARB, const GLvoid *, GLenum); +GLAPI void APIENTRY glBufferSubDataARB (GLenum, GLintptrARB, GLsizeiptrARB, const GLvoid *); +GLAPI void APIENTRY glGetBufferSubDataARB (GLenum, GLintptrARB, GLsizeiptrARB, GLvoid *); +GLAPI GLvoid* APIENTRY glMapBufferARB (GLenum, GLenum); +GLAPI GLboolean APIENTRY glUnmapBufferARB (GLenum); +GLAPI void APIENTRY glGetBufferParameterivARB (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetBufferPointervARB (GLenum, GLenum, GLvoid* *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERARBPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERARBPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERARBPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVARBPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_ARB_occlusion_query +#define GL_ARB_occlusion_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenQueriesARB (GLsizei, GLuint *); +GLAPI void APIENTRY glDeleteQueriesARB (GLsizei, const GLuint *); +GLAPI GLboolean APIENTRY glIsQueryARB (GLuint); +GLAPI void APIENTRY glBeginQueryARB (GLenum, GLuint); +GLAPI void APIENTRY glEndQueryARB (GLenum); +GLAPI void APIENTRY glGetQueryivARB (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetQueryObjectivARB (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetQueryObjectuivARB (GLuint, GLenum, GLuint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENQUERIESARBPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESARBPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYARBPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYARBPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYARBPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVARBPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVARBPROC) (GLuint id, GLenum pname, GLuint *params); +#endif + +#ifndef GL_ARB_shader_objects +#define GL_ARB_shader_objects 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeleteObjectARB (GLhandleARB); +GLAPI GLhandleARB APIENTRY glGetHandleARB (GLenum); +GLAPI void APIENTRY glDetachObjectARB (GLhandleARB, GLhandleARB); +GLAPI GLhandleARB APIENTRY glCreateShaderObjectARB (GLenum); +GLAPI void APIENTRY glShaderSourceARB (GLhandleARB, GLsizei, const GLcharARB* *, const GLint *); +GLAPI void APIENTRY glCompileShaderARB (GLhandleARB); +GLAPI GLhandleARB APIENTRY glCreateProgramObjectARB (void); +GLAPI void APIENTRY glAttachObjectARB (GLhandleARB, GLhandleARB); +GLAPI void APIENTRY glLinkProgramARB (GLhandleARB); +GLAPI void APIENTRY glUseProgramObjectARB (GLhandleARB); +GLAPI void APIENTRY glValidateProgramARB (GLhandleARB); +GLAPI void APIENTRY glUniform1fARB (GLint, GLfloat); +GLAPI void APIENTRY glUniform2fARB (GLint, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform3fARB (GLint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform4fARB (GLint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform1iARB (GLint, GLint); +GLAPI void APIENTRY glUniform2iARB (GLint, GLint, GLint); +GLAPI void APIENTRY glUniform3iARB (GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glUniform4iARB (GLint, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glUniform1fvARB (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform2fvARB (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform3fvARB (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform4fvARB (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform1ivARB (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform2ivARB (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform3ivARB (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform4ivARB (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniformMatrix2fvARB (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix3fvARB (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix4fvARB (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glGetObjectParameterfvARB (GLhandleARB, GLenum, GLfloat *); +GLAPI void APIENTRY glGetObjectParameterivARB (GLhandleARB, GLenum, GLint *); +GLAPI void APIENTRY glGetInfoLogARB (GLhandleARB, GLsizei, GLsizei *, GLcharARB *); +GLAPI void APIENTRY glGetAttachedObjectsARB (GLhandleARB, GLsizei, GLsizei *, GLhandleARB *); +GLAPI GLint APIENTRY glGetUniformLocationARB (GLhandleARB, const GLcharARB *); +GLAPI void APIENTRY glGetActiveUniformARB (GLhandleARB, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLcharARB *); +GLAPI void APIENTRY glGetUniformfvARB (GLhandleARB, GLint, GLfloat *); +GLAPI void APIENTRY glGetUniformivARB (GLhandleARB, GLint, GLint *); +GLAPI void APIENTRY glGetShaderSourceARB (GLhandleARB, GLsizei, GLsizei *, GLcharARB *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj); +typedef GLhandleARB (APIENTRYP PFNGLGETHANDLEARBPROC) (GLenum pname); +typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB attachedObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); +typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); +typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); +typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); +typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUNIFORM1FARBPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FARBPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IARBPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERFVARBPROC) (GLhandleARB obj, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB obj, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +typedef void (APIENTRYP PFNGLGETATTACHEDOBJECTSARBPROC) (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVARBPROC) (GLhandleARB programObj, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVARBPROC) (GLhandleARB programObj, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); +#endif + +#ifndef GL_ARB_vertex_shader +#define GL_ARB_vertex_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindAttribLocationARB (GLhandleARB, GLuint, const GLcharARB *); +GLAPI void APIENTRY glGetActiveAttribARB (GLhandleARB, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLcharARB *); +GLAPI GLint APIENTRY glGetAttribLocationARB (GLhandleARB, const GLcharARB *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONARBPROC) (GLhandleARB programObj, GLuint index, const GLcharARB *name); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +#endif + +#ifndef GL_ARB_fragment_shader +#define GL_ARB_fragment_shader 1 +#endif + +#ifndef GL_ARB_shading_language_100 +#define GL_ARB_shading_language_100 1 +#endif + +#ifndef GL_ARB_texture_non_power_of_two +#define GL_ARB_texture_non_power_of_two 1 +#endif + +#ifndef GL_ARB_point_sprite +#define GL_ARB_point_sprite 1 +#endif + +#ifndef GL_ARB_fragment_program_shadow +#define GL_ARB_fragment_program_shadow 1 +#endif + +#ifndef GL_ARB_draw_buffers +#define GL_ARB_draw_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawBuffersARB (GLsizei, const GLenum *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWBUFFERSARBPROC) (GLsizei n, const GLenum *bufs); +#endif + +#ifndef GL_ARB_texture_rectangle +#define GL_ARB_texture_rectangle 1 +#endif + +#ifndef GL_ARB_color_buffer_float +#define GL_ARB_color_buffer_float 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClampColorARB (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLAMPCOLORARBPROC) (GLenum target, GLenum clamp); +#endif + +#ifndef GL_ARB_half_float_pixel +#define GL_ARB_half_float_pixel 1 +#endif + +#ifndef GL_ARB_texture_float +#define GL_ARB_texture_float 1 +#endif + +#ifndef GL_ARB_pixel_buffer_object +#define GL_ARB_pixel_buffer_object 1 +#endif + +#ifndef GL_ARB_depth_buffer_float +#define GL_ARB_depth_buffer_float 1 +#endif + +#ifndef GL_ARB_draw_instanced +#define GL_ARB_draw_instanced 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstancedARB (GLenum, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glDrawElementsInstancedARB (GLenum, GLsizei, GLenum, const GLvoid *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDARBPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDARBPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +#endif + +#ifndef GL_ARB_framebuffer_object +#define GL_ARB_framebuffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glIsRenderbuffer (GLuint); +GLAPI void APIENTRY glBindRenderbuffer (GLenum, GLuint); +GLAPI void APIENTRY glDeleteRenderbuffers (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenRenderbuffers (GLsizei, GLuint *); +GLAPI void APIENTRY glRenderbufferStorage (GLenum, GLenum, GLsizei, GLsizei); +GLAPI void APIENTRY glGetRenderbufferParameteriv (GLenum, GLenum, GLint *); +GLAPI GLboolean APIENTRY glIsFramebuffer (GLuint); +GLAPI void APIENTRY glBindFramebuffer (GLenum, GLuint); +GLAPI void APIENTRY glDeleteFramebuffers (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenFramebuffers (GLsizei, GLuint *); +GLAPI GLenum APIENTRY glCheckFramebufferStatus (GLenum); +GLAPI void APIENTRY glFramebufferTexture1D (GLenum, GLenum, GLenum, GLuint, GLint); +GLAPI void APIENTRY glFramebufferTexture2D (GLenum, GLenum, GLenum, GLuint, GLint); +GLAPI void APIENTRY glFramebufferTexture3D (GLenum, GLenum, GLenum, GLuint, GLint, GLint); +GLAPI void APIENTRY glFramebufferRenderbuffer (GLenum, GLenum, GLenum, GLuint); +GLAPI void APIENTRY glGetFramebufferAttachmentParameteriv (GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGenerateMipmap (GLenum); +GLAPI void APIENTRY glBlitFramebuffer (GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum); +GLAPI void APIENTRY glRenderbufferStorageMultisample (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +GLAPI void APIENTRY glFramebufferTextureLayer (GLenum, GLenum, GLuint, GLint, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFERPROC) (GLuint renderbuffer); +typedef void (APIENTRYP PFNGLBINDRENDERBUFFERPROC) (GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSPROC) (GLsizei n, const GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLGENRENDERBUFFERSPROC) (GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFERPROC) (GLuint framebuffer); +typedef void (APIENTRYP PFNGLBINDFRAMEBUFFERPROC) (GLenum target, GLuint framebuffer); +typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSPROC) (GLsizei n, const GLuint *framebuffers); +typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSPROC) (GLsizei n, GLuint *framebuffers); +typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC) (GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target); +typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif + +#ifndef GL_ARB_framebuffer_sRGB +#define GL_ARB_framebuffer_sRGB 1 +#endif + +#ifndef GL_ARB_geometry_shader4 +#define GL_ARB_geometry_shader4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramParameteriARB (GLuint, GLenum, GLint); +GLAPI void APIENTRY glFramebufferTextureARB (GLenum, GLenum, GLuint, GLint); +GLAPI void APIENTRY glFramebufferTextureLayerARB (GLenum, GLenum, GLuint, GLint, GLint); +GLAPI void APIENTRY glFramebufferTextureFaceARB (GLenum, GLenum, GLuint, GLint, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIARBPROC) (GLuint program, GLenum pname, GLint value); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#endif + +#ifndef GL_ARB_half_float_vertex +#define GL_ARB_half_float_vertex 1 +#endif + +#ifndef GL_ARB_instanced_arrays +#define GL_ARB_instanced_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribDivisorARB (GLuint, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORARBPROC) (GLuint index, GLuint divisor); +#endif + +#ifndef GL_ARB_map_buffer_range +#define GL_ARB_map_buffer_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLvoid* APIENTRY glMapBufferRange (GLenum, GLintptr, GLsizeiptr, GLbitfield); +GLAPI void APIENTRY glFlushMappedBufferRange (GLenum, GLintptr, GLsizeiptr); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length); +#endif + +#ifndef GL_ARB_texture_buffer_object +#define GL_ARB_texture_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBufferARB (GLenum, GLenum, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUFFERARBPROC) (GLenum target, GLenum internalformat, GLuint buffer); +#endif + +#ifndef GL_ARB_texture_compression_rgtc +#define GL_ARB_texture_compression_rgtc 1 +#endif + +#ifndef GL_ARB_texture_rg +#define GL_ARB_texture_rg 1 +#endif + +#ifndef GL_ARB_vertex_array_object +#define GL_ARB_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindVertexArray (GLuint); +GLAPI void APIENTRY glDeleteVertexArrays (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenVertexArrays (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsVertexArray (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array); +typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays); +typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYPROC) (GLuint array); +#endif + +#ifndef GL_ARB_uniform_buffer_object +#define GL_ARB_uniform_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetUniformIndices (GLuint, GLsizei, const GLchar* *, GLuint *); +GLAPI void APIENTRY glGetActiveUniformsiv (GLuint, GLsizei, const GLuint *, GLenum, GLint *); +GLAPI void APIENTRY glGetActiveUniformName (GLuint, GLuint, GLsizei, GLsizei *, GLchar *); +GLAPI GLuint APIENTRY glGetUniformBlockIndex (GLuint, const GLchar *); +GLAPI void APIENTRY glGetActiveUniformBlockiv (GLuint, GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetActiveUniformBlockName (GLuint, GLuint, GLsizei, GLsizei *, GLchar *); +GLAPI void APIENTRY glUniformBlockBinding (GLuint, GLuint, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETUNIFORMINDICESPROC) (GLuint program, GLsizei uniformCount, const GLchar* *uniformNames, GLuint *uniformIndices); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMSIVPROC) (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMNAMEPROC) (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); +typedef GLuint (APIENTRYP PFNGLGETUNIFORMBLOCKINDEXPROC) (GLuint program, const GLchar *uniformBlockName); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKIVPROC) (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); +typedef void (APIENTRYP PFNGLUNIFORMBLOCKBINDINGPROC) (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); +#endif + +#ifndef GL_ARB_compatibility +#define GL_ARB_compatibility 1 +#endif + +#ifndef GL_ARB_copy_buffer +#define GL_ARB_copy_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCopyBufferSubData (GLenum, GLenum, GLintptr, GLintptr, GLsizeiptr); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +#endif + +#ifndef GL_ARB_shader_texture_lod +#define GL_ARB_shader_texture_lod 1 +#endif + +#ifndef GL_ARB_depth_clamp +#define GL_ARB_depth_clamp 1 +#endif + +#ifndef GL_ARB_draw_elements_base_vertex +#define GL_ARB_draw_elements_base_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum, GLsizei, GLenum, const GLvoid *, GLint); +GLAPI void APIENTRY glDrawRangeElementsBaseVertex (GLenum, GLuint, GLuint, GLsizei, GLenum, const GLvoid *, GLint); +GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum, GLsizei, GLenum, const GLvoid *, GLsizei, GLint); +GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount, GLint basevertex); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount, const GLint *basevertex); +#endif + +#ifndef GL_ARB_fragment_coord_conventions +#define GL_ARB_fragment_coord_conventions 1 +#endif + +#ifndef GL_ARB_provoking_vertex +#define GL_ARB_provoking_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProvokingVertex (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC) (GLenum mode); +#endif + +#ifndef GL_ARB_seamless_cube_map +#define GL_ARB_seamless_cube_map 1 +#endif + +#ifndef GL_ARB_sync +#define GL_ARB_sync 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLsync APIENTRY glFenceSync (GLenum, GLbitfield); +GLAPI GLboolean APIENTRY glIsSync (GLsync); +GLAPI void APIENTRY glDeleteSync (GLsync); +GLAPI GLenum APIENTRY glClientWaitSync (GLsync, GLbitfield, GLuint64); +GLAPI void APIENTRY glWaitSync (GLsync, GLbitfield, GLuint64); +GLAPI void APIENTRY glGetInteger64v (GLenum, GLint64 *); +GLAPI void APIENTRY glGetSynciv (GLsync, GLenum, GLsizei, GLsizei *, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags); +typedef GLboolean (APIENTRYP PFNGLISSYNCPROC) (GLsync sync); +typedef void (APIENTRYP PFNGLDELETESYNCPROC) (GLsync sync); +typedef GLenum (APIENTRYP PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLGETINTEGER64VPROC) (GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif + +#ifndef GL_ARB_texture_multisample +#define GL_ARB_texture_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage2DMultisample (GLenum, GLsizei, GLint, GLsizei, GLsizei, GLboolean); +GLAPI void APIENTRY glTexImage3DMultisample (GLenum, GLsizei, GLint, GLsizei, GLsizei, GLsizei, GLboolean); +GLAPI void APIENTRY glGetMultisamplefv (GLenum, GLuint, GLfloat *); +GLAPI void APIENTRY glSampleMaski (GLuint, GLbitfield); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVPROC) (GLenum pname, GLuint index, GLfloat *val); +typedef void (APIENTRYP PFNGLSAMPLEMASKIPROC) (GLuint index, GLbitfield mask); +#endif + +#ifndef GL_ARB_vertex_array_bgra +#define GL_ARB_vertex_array_bgra 1 +#endif + +#ifndef GL_ARB_draw_buffers_blend +#define GL_ARB_draw_buffers_blend 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationi (GLuint, GLenum); +GLAPI void APIENTRY glBlendEquationSeparatei (GLuint, GLenum, GLenum); +GLAPI void APIENTRY glBlendFunci (GLuint, GLenum, GLenum); +GLAPI void APIENTRY glBlendFuncSeparatei (GLuint, GLenum, GLenum, GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONIPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLBLENDFUNCIPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif + +#ifndef GL_ARB_sample_shading +#define GL_ARB_sample_shading 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMinSampleShading (GLclampf); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMINSAMPLESHADINGPROC) (GLclampf value); +#endif + +#ifndef GL_ARB_texture_cube_map_array +#define GL_ARB_texture_cube_map_array 1 +#endif + +#ifndef GL_ARB_texture_gather +#define GL_ARB_texture_gather 1 +#endif + +#ifndef GL_ARB_texture_query_lod +#define GL_ARB_texture_query_lod 1 +#endif + +#ifndef GL_EXT_abgr +#define GL_EXT_abgr 1 +#endif + +#ifndef GL_EXT_blend_color +#define GL_EXT_blend_color 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendColorEXT (GLclampf, GLclampf, GLclampf, GLclampf); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDCOLOREXTPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +#endif + +#ifndef GL_EXT_polygon_offset +#define GL_EXT_polygon_offset 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPolygonOffsetEXT (GLfloat, GLfloat); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOLYGONOFFSETEXTPROC) (GLfloat factor, GLfloat bias); +#endif + +#ifndef GL_EXT_texture +#define GL_EXT_texture 1 +#endif + +#ifndef GL_EXT_texture3D +#define GL_EXT_texture3D 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage3DEXT (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTexSubImage3DEXT (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE3DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_SGIS_texture_filter4 +#define GL_SGIS_texture_filter4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetTexFilterFuncSGIS (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glTexFilterFuncSGIS (GLenum, GLenum, GLsizei, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLfloat *weights); +typedef void (APIENTRYP PFNGLTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights); +#endif + +#ifndef GL_EXT_subtexture +#define GL_EXT_subtexture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexSubImage1DEXT (GLenum, GLint, GLint, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTexSubImage2DEXT (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_EXT_copy_texture +#define GL_EXT_copy_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCopyTexImage1DEXT (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLint); +GLAPI void APIENTRY glCopyTexImage2DEXT (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint); +GLAPI void APIENTRY glCopyTexSubImage1DEXT (GLenum, GLint, GLint, GLint, GLint, GLsizei); +GLAPI void APIENTRY glCopyTexSubImage2DEXT (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glCopyTexSubImage3DEXT (GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_EXT_histogram +#define GL_EXT_histogram 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetHistogramEXT (GLenum, GLboolean, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetHistogramParameterfvEXT (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetHistogramParameterivEXT (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetMinmaxEXT (GLenum, GLboolean, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetMinmaxParameterfvEXT (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetMinmaxParameterivEXT (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glHistogramEXT (GLenum, GLsizei, GLenum, GLboolean); +GLAPI void APIENTRY glMinmaxEXT (GLenum, GLenum, GLboolean); +GLAPI void APIENTRY glResetHistogramEXT (GLenum); +GLAPI void APIENTRY glResetMinmaxEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETHISTOGRAMEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMINMAXEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLHISTOGRAMEXTPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLMINMAXEXTPROC) (GLenum target, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLRESETHISTOGRAMEXTPROC) (GLenum target); +typedef void (APIENTRYP PFNGLRESETMINMAXEXTPROC) (GLenum target); +#endif + +#ifndef GL_EXT_convolution +#define GL_EXT_convolution 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glConvolutionFilter1DEXT (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glConvolutionFilter2DEXT (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glConvolutionParameterfEXT (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glConvolutionParameterfvEXT (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glConvolutionParameteriEXT (GLenum, GLenum, GLint); +GLAPI void APIENTRY glConvolutionParameterivEXT (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glCopyConvolutionFilter1DEXT (GLenum, GLenum, GLint, GLint, GLsizei); +GLAPI void APIENTRY glCopyConvolutionFilter2DEXT (GLenum, GLenum, GLint, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glGetConvolutionFilterEXT (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetConvolutionParameterfvEXT (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetConvolutionParameterivEXT (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetSeparableFilterEXT (GLenum, GLenum, GLenum, GLvoid *, GLvoid *, GLvoid *); +GLAPI void APIENTRY glSeparableFilter2DEXT (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSEPARABLEFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +#endif + +#ifndef GL_SGI_color_matrix +#define GL_SGI_color_matrix 1 +#endif + +#ifndef GL_SGI_color_table +#define GL_SGI_color_table 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTableSGI (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glColorTableParameterfvSGI (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glColorTableParameterivSGI (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glCopyColorTableSGI (GLenum, GLenum, GLint, GLint, GLsizei); +GLAPI void APIENTRY glGetColorTableSGI (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetColorTableParameterfvSGI (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetColorTableParameterivSGI (GLenum, GLenum, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLGETCOLORTABLESGIPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, GLint *params); +#endif + +#ifndef GL_SGIX_pixel_texture +#define GL_SGIX_pixel_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTexGenSGIX (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTEXGENSGIXPROC) (GLenum mode); +#endif + +#ifndef GL_SGIS_pixel_texture +#define GL_SGIS_pixel_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTexGenParameteriSGIS (GLenum, GLint); +GLAPI void APIENTRY glPixelTexGenParameterivSGIS (GLenum, const GLint *); +GLAPI void APIENTRY glPixelTexGenParameterfSGIS (GLenum, GLfloat); +GLAPI void APIENTRY glPixelTexGenParameterfvSGIS (GLenum, const GLfloat *); +GLAPI void APIENTRY glGetPixelTexGenParameterivSGIS (GLenum, GLint *); +GLAPI void APIENTRY glGetPixelTexGenParameterfvSGIS (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERISGISPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFSGISPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, GLfloat *params); +#endif + +#ifndef GL_SGIS_texture4D +#define GL_SGIS_texture4D 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage4DSGIS (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTexSubImage4DSGIS (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE4DSGISPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE4DSGISPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_SGI_texture_color_table +#define GL_SGI_texture_color_table 1 +#endif + +#ifndef GL_EXT_cmyka +#define GL_EXT_cmyka 1 +#endif + +#ifndef GL_EXT_texture_object +#define GL_EXT_texture_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glAreTexturesResidentEXT (GLsizei, const GLuint *, GLboolean *); +GLAPI void APIENTRY glBindTextureEXT (GLenum, GLuint); +GLAPI void APIENTRY glDeleteTexturesEXT (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenTexturesEXT (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsTextureEXT (GLuint); +GLAPI void APIENTRY glPrioritizeTexturesEXT (GLsizei, const GLuint *, const GLclampf *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLARETEXTURESRESIDENTEXTPROC) (GLsizei n, const GLuint *textures, GLboolean *residences); +typedef void (APIENTRYP PFNGLBINDTEXTUREEXTPROC) (GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLDELETETEXTURESEXTPROC) (GLsizei n, const GLuint *textures); +typedef void (APIENTRYP PFNGLGENTEXTURESEXTPROC) (GLsizei n, GLuint *textures); +typedef GLboolean (APIENTRYP PFNGLISTEXTUREEXTPROC) (GLuint texture); +typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESEXTPROC) (GLsizei n, const GLuint *textures, const GLclampf *priorities); +#endif + +#ifndef GL_SGIS_detail_texture +#define GL_SGIS_detail_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDetailTexFuncSGIS (GLenum, GLsizei, const GLfloat *); +GLAPI void APIENTRY glGetDetailTexFuncSGIS (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDETAILTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETDETAILTEXFUNCSGISPROC) (GLenum target, GLfloat *points); +#endif + +#ifndef GL_SGIS_sharpen_texture +#define GL_SGIS_sharpen_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSharpenTexFuncSGIS (GLenum, GLsizei, const GLfloat *); +GLAPI void APIENTRY glGetSharpenTexFuncSGIS (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSHARPENTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETSHARPENTEXFUNCSGISPROC) (GLenum target, GLfloat *points); +#endif + +#ifndef GL_EXT_packed_pixels +#define GL_EXT_packed_pixels 1 +#endif + +#ifndef GL_SGIS_texture_lod +#define GL_SGIS_texture_lod 1 +#endif + +#ifndef GL_SGIS_multisample +#define GL_SGIS_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleMaskSGIS (GLclampf, GLboolean); +GLAPI void APIENTRY glSamplePatternSGIS (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLEMASKSGISPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLSAMPLEPATTERNSGISPROC) (GLenum pattern); +#endif + +#ifndef GL_EXT_rescale_normal +#define GL_EXT_rescale_normal 1 +#endif + +#ifndef GL_EXT_vertex_array +#define GL_EXT_vertex_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glArrayElementEXT (GLint); +GLAPI void APIENTRY glColorPointerEXT (GLint, GLenum, GLsizei, GLsizei, const GLvoid *); +GLAPI void APIENTRY glDrawArraysEXT (GLenum, GLint, GLsizei); +GLAPI void APIENTRY glEdgeFlagPointerEXT (GLsizei, GLsizei, const GLboolean *); +GLAPI void APIENTRY glGetPointervEXT (GLenum, GLvoid* *); +GLAPI void APIENTRY glIndexPointerEXT (GLenum, GLsizei, GLsizei, const GLvoid *); +GLAPI void APIENTRY glNormalPointerEXT (GLenum, GLsizei, GLsizei, const GLvoid *); +GLAPI void APIENTRY glTexCoordPointerEXT (GLint, GLenum, GLsizei, GLsizei, const GLvoid *); +GLAPI void APIENTRY glVertexPointerEXT (GLint, GLenum, GLsizei, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLARRAYELEMENTEXTPROC) (GLint i); +typedef void (APIENTRYP PFNGLCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWARRAYSEXTPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLEDGEFLAGPOINTEREXTPROC) (GLsizei stride, GLsizei count, const GLboolean *pointer); +typedef void (APIENTRYP PFNGLGETPOINTERVEXTPROC) (GLenum pname, GLvoid* *params); +typedef void (APIENTRYP PFNGLINDEXPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLNORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_misc_attribute +#define GL_EXT_misc_attribute 1 +#endif + +#ifndef GL_SGIS_generate_mipmap +#define GL_SGIS_generate_mipmap 1 +#endif + +#ifndef GL_SGIX_clipmap +#define GL_SGIX_clipmap 1 +#endif + +#ifndef GL_SGIX_shadow +#define GL_SGIX_shadow 1 +#endif + +#ifndef GL_SGIS_texture_edge_clamp +#define GL_SGIS_texture_edge_clamp 1 +#endif + +#ifndef GL_SGIS_texture_border_clamp +#define GL_SGIS_texture_border_clamp 1 +#endif + +#ifndef GL_EXT_blend_minmax +#define GL_EXT_blend_minmax 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONEXTPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_blend_subtract +#define GL_EXT_blend_subtract 1 +#endif + +#ifndef GL_EXT_blend_logic_op +#define GL_EXT_blend_logic_op 1 +#endif + +#ifndef GL_SGIX_interlace +#define GL_SGIX_interlace 1 +#endif + +#ifndef GL_SGIX_pixel_tiles +#define GL_SGIX_pixel_tiles 1 +#endif + +#ifndef GL_SGIX_texture_select +#define GL_SGIX_texture_select 1 +#endif + +#ifndef GL_SGIX_sprite +#define GL_SGIX_sprite 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSpriteParameterfSGIX (GLenum, GLfloat); +GLAPI void APIENTRY glSpriteParameterfvSGIX (GLenum, const GLfloat *); +GLAPI void APIENTRY glSpriteParameteriSGIX (GLenum, GLint); +GLAPI void APIENTRY glSpriteParameterivSGIX (GLenum, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSPRITEPARAMETERFSGIXPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERFVSGIXPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERISGIXPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERIVSGIXPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_SGIX_texture_multi_buffer +#define GL_SGIX_texture_multi_buffer 1 +#endif + +#ifndef GL_EXT_point_parameters +#define GL_EXT_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfEXT (GLenum, GLfloat); +GLAPI void APIENTRY glPointParameterfvEXT (GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_SGIS_point_parameters +#define GL_SGIS_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfSGIS (GLenum, GLfloat); +GLAPI void APIENTRY glPointParameterfvSGIS (GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFSGISPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_SGIX_instruments +#define GL_SGIX_instruments 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLint APIENTRY glGetInstrumentsSGIX (void); +GLAPI void APIENTRY glInstrumentsBufferSGIX (GLsizei, GLint *); +GLAPI GLint APIENTRY glPollInstrumentsSGIX (GLint *); +GLAPI void APIENTRY glReadInstrumentsSGIX (GLint); +GLAPI void APIENTRY glStartInstrumentsSGIX (void); +GLAPI void APIENTRY glStopInstrumentsSGIX (GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLint (APIENTRYP PFNGLGETINSTRUMENTSSGIXPROC) (void); +typedef void (APIENTRYP PFNGLINSTRUMENTSBUFFERSGIXPROC) (GLsizei size, GLint *buffer); +typedef GLint (APIENTRYP PFNGLPOLLINSTRUMENTSSGIXPROC) (GLint *marker_p); +typedef void (APIENTRYP PFNGLREADINSTRUMENTSSGIXPROC) (GLint marker); +typedef void (APIENTRYP PFNGLSTARTINSTRUMENTSSGIXPROC) (void); +typedef void (APIENTRYP PFNGLSTOPINSTRUMENTSSGIXPROC) (GLint marker); +#endif + +#ifndef GL_SGIX_texture_scale_bias +#define GL_SGIX_texture_scale_bias 1 +#endif + +#ifndef GL_SGIX_framezoom +#define GL_SGIX_framezoom 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFrameZoomSGIX (GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAMEZOOMSGIXPROC) (GLint factor); +#endif + +#ifndef GL_SGIX_tag_sample_buffer +#define GL_SGIX_tag_sample_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTagSampleBufferSGIX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTAGSAMPLEBUFFERSGIXPROC) (void); +#endif + +#ifndef GL_SGIX_polynomial_ffd +#define GL_SGIX_polynomial_ffd 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeformationMap3dSGIX (GLenum, GLdouble, GLdouble, GLint, GLint, GLdouble, GLdouble, GLint, GLint, GLdouble, GLdouble, GLint, GLint, const GLdouble *); +GLAPI void APIENTRY glDeformationMap3fSGIX (GLenum, GLfloat, GLfloat, GLint, GLint, GLfloat, GLfloat, GLint, GLint, GLfloat, GLfloat, GLint, GLint, const GLfloat *); +GLAPI void APIENTRY glDeformSGIX (GLbitfield); +GLAPI void APIENTRY glLoadIdentityDeformationMapSGIX (GLbitfield); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEFORMATIONMAP3DSGIXPROC) (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points); +typedef void (APIENTRYP PFNGLDEFORMATIONMAP3FSGIXPROC) (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points); +typedef void (APIENTRYP PFNGLDEFORMSGIXPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLLOADIDENTITYDEFORMATIONMAPSGIXPROC) (GLbitfield mask); +#endif + +#ifndef GL_SGIX_reference_plane +#define GL_SGIX_reference_plane 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReferencePlaneSGIX (const GLdouble *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLREFERENCEPLANESGIXPROC) (const GLdouble *equation); +#endif + +#ifndef GL_SGIX_flush_raster +#define GL_SGIX_flush_raster 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFlushRasterSGIX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFLUSHRASTERSGIXPROC) (void); +#endif + +#ifndef GL_SGIX_depth_texture +#define GL_SGIX_depth_texture 1 +#endif + +#ifndef GL_SGIS_fog_function +#define GL_SGIS_fog_function 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogFuncSGIS (GLsizei, const GLfloat *); +GLAPI void APIENTRY glGetFogFuncSGIS (GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFOGFUNCSGISPROC) (GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETFOGFUNCSGISPROC) (GLfloat *points); +#endif + +#ifndef GL_SGIX_fog_offset +#define GL_SGIX_fog_offset 1 +#endif + +#ifndef GL_HP_image_transform +#define GL_HP_image_transform 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glImageTransformParameteriHP (GLenum, GLenum, GLint); +GLAPI void APIENTRY glImageTransformParameterfHP (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glImageTransformParameterivHP (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glImageTransformParameterfvHP (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glGetImageTransformParameterivHP (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetImageTransformParameterfvHP (GLenum, GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIHPPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFHPPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_HP_convolution_border_modes +#define GL_HP_convolution_border_modes 1 +#endif + +#ifndef GL_SGIX_texture_add_env +#define GL_SGIX_texture_add_env 1 +#endif + +#ifndef GL_EXT_color_subtable +#define GL_EXT_color_subtable 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorSubTableEXT (GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glCopyColorSubTableEXT (GLenum, GLsizei, GLint, GLint, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +//typedef void (APIENTRYP PFNGLCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +#endif + +#ifndef GL_PGI_vertex_hints +#define GL_PGI_vertex_hints 1 +#endif + +#ifndef GL_PGI_misc_hints +#define GL_PGI_misc_hints 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glHintPGI (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLHINTPGIPROC) (GLenum target, GLint mode); +#endif + +#ifndef GL_EXT_paletted_texture +#define GL_EXT_paletted_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTableEXT (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glGetColorTableEXT (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetColorTableParameterivEXT (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetColorTableParameterfvEXT (GLenum, GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORTABLEEXTPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEEXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_EXT_clip_volume_hint +#define GL_EXT_clip_volume_hint 1 +#endif + +#ifndef GL_SGIX_list_priority +#define GL_SGIX_list_priority 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetListParameterfvSGIX (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetListParameterivSGIX (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glListParameterfSGIX (GLuint, GLenum, GLfloat); +GLAPI void APIENTRY glListParameterfvSGIX (GLuint, GLenum, const GLfloat *); +GLAPI void APIENTRY glListParameteriSGIX (GLuint, GLenum, GLint); +GLAPI void APIENTRY glListParameterivSGIX (GLuint, GLenum, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLLISTPARAMETERFSGIXPROC) (GLuint list, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLLISTPARAMETERISGIXPROC) (GLuint list, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, const GLint *params); +#endif + +#ifndef GL_SGIX_ir_instrument1 +#define GL_SGIX_ir_instrument1 1 +#endif + +#ifndef GL_SGIX_calligraphic_fragment +#define GL_SGIX_calligraphic_fragment 1 +#endif + +#ifndef GL_SGIX_texture_lod_bias +#define GL_SGIX_texture_lod_bias 1 +#endif + +#ifndef GL_SGIX_shadow_ambient +#define GL_SGIX_shadow_ambient 1 +#endif + +#ifndef GL_EXT_index_texture +#define GL_EXT_index_texture 1 +#endif + +#ifndef GL_EXT_index_material +#define GL_EXT_index_material 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIndexMaterialEXT (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINDEXMATERIALEXTPROC) (GLenum face, GLenum mode); +#endif + +#ifndef GL_EXT_index_func +#define GL_EXT_index_func 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIndexFuncEXT (GLenum, GLclampf); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINDEXFUNCEXTPROC) (GLenum func, GLclampf ref); +#endif + +#ifndef GL_EXT_index_array_formats +#define GL_EXT_index_array_formats 1 +#endif + +#ifndef GL_EXT_compiled_vertex_array +#define GL_EXT_compiled_vertex_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLockArraysEXT (GLint, GLsizei); +GLAPI void APIENTRY glUnlockArraysEXT (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLUNLOCKARRAYSEXTPROC) (void); +#endif + +#ifndef GL_EXT_cull_vertex +#define GL_EXT_cull_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCullParameterdvEXT (GLenum, GLdouble *); +GLAPI void APIENTRY glCullParameterfvEXT (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCULLPARAMETERDVEXTPROC) (GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLCULLPARAMETERFVEXTPROC) (GLenum pname, GLfloat *params); +#endif + +#ifndef GL_SGIX_ycrcb +#define GL_SGIX_ycrcb 1 +#endif + +#ifndef GL_SGIX_fragment_lighting +#define GL_SGIX_fragment_lighting 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFragmentColorMaterialSGIX (GLenum, GLenum); +GLAPI void APIENTRY glFragmentLightfSGIX (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glFragmentLightfvSGIX (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glFragmentLightiSGIX (GLenum, GLenum, GLint); +GLAPI void APIENTRY glFragmentLightivSGIX (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glFragmentLightModelfSGIX (GLenum, GLfloat); +GLAPI void APIENTRY glFragmentLightModelfvSGIX (GLenum, const GLfloat *); +GLAPI void APIENTRY glFragmentLightModeliSGIX (GLenum, GLint); +GLAPI void APIENTRY glFragmentLightModelivSGIX (GLenum, const GLint *); +GLAPI void APIENTRY glFragmentMaterialfSGIX (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glFragmentMaterialfvSGIX (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glFragmentMaterialiSGIX (GLenum, GLenum, GLint); +GLAPI void APIENTRY glFragmentMaterialivSGIX (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glGetFragmentLightfvSGIX (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetFragmentLightivSGIX (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetFragmentMaterialfvSGIX (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetFragmentMaterialivSGIX (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glLightEnviSGIX (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAGMENTCOLORMATERIALSGIXPROC) (GLenum face, GLenum mode); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFSGIXPROC) (GLenum light, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTISGIXPROC) (GLenum light, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFSGIXPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELISGIXPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFSGIXPROC) (GLenum face, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALISGIXPROC) (GLenum face, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLLIGHTENVISGIXPROC) (GLenum pname, GLint param); +#endif + +#ifndef GL_IBM_rasterpos_clip +#define GL_IBM_rasterpos_clip 1 +#endif + +#ifndef GL_HP_texture_lighting +#define GL_HP_texture_lighting 1 +#endif + +#ifndef GL_EXT_draw_range_elements +#define GL_EXT_draw_range_elements 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawRangeElementsEXT (GLenum, GLuint, GLuint, GLsizei, GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +#endif + +#ifndef GL_WIN_phong_shading +#define GL_WIN_phong_shading 1 +#endif + +#ifndef GL_WIN_specular_fog +#define GL_WIN_specular_fog 1 +#endif + +#ifndef GL_EXT_light_texture +#define GL_EXT_light_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glApplyTextureEXT (GLenum); +GLAPI void APIENTRY glTextureLightEXT (GLenum); +GLAPI void APIENTRY glTextureMaterialEXT (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLAPPLYTEXTUREEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLTEXTURELIGHTEXTPROC) (GLenum pname); +typedef void (APIENTRYP PFNGLTEXTUREMATERIALEXTPROC) (GLenum face, GLenum mode); +#endif + +#ifndef GL_SGIX_blend_alpha_minmax +#define GL_SGIX_blend_alpha_minmax 1 +#endif + +#ifndef GL_EXT_bgra +#define GL_EXT_bgra 1 +#endif + +#ifndef GL_SGIX_async +#define GL_SGIX_async 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glAsyncMarkerSGIX (GLuint); +GLAPI GLint APIENTRY glFinishAsyncSGIX (GLuint *); +GLAPI GLint APIENTRY glPollAsyncSGIX (GLuint *); +GLAPI GLuint APIENTRY glGenAsyncMarkersSGIX (GLsizei); +GLAPI void APIENTRY glDeleteAsyncMarkersSGIX (GLuint, GLsizei); +GLAPI GLboolean APIENTRY glIsAsyncMarkerSGIX (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLASYNCMARKERSGIXPROC) (GLuint marker); +typedef GLint (APIENTRYP PFNGLFINISHASYNCSGIXPROC) (GLuint *markerp); +typedef GLint (APIENTRYP PFNGLPOLLASYNCSGIXPROC) (GLuint *markerp); +typedef GLuint (APIENTRYP PFNGLGENASYNCMARKERSSGIXPROC) (GLsizei range); +typedef void (APIENTRYP PFNGLDELETEASYNCMARKERSSGIXPROC) (GLuint marker, GLsizei range); +typedef GLboolean (APIENTRYP PFNGLISASYNCMARKERSGIXPROC) (GLuint marker); +#endif + +#ifndef GL_SGIX_async_pixel +#define GL_SGIX_async_pixel 1 +#endif + +#ifndef GL_SGIX_async_histogram +#define GL_SGIX_async_histogram 1 +#endif + +#ifndef GL_INTEL_parallel_arrays +#define GL_INTEL_parallel_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexPointervINTEL (GLint, GLenum, const GLvoid* *); +GLAPI void APIENTRY glNormalPointervINTEL (GLenum, const GLvoid* *); +GLAPI void APIENTRY glColorPointervINTEL (GLint, GLenum, const GLvoid* *); +GLAPI void APIENTRY glTexCoordPointervINTEL (GLint, GLenum, const GLvoid* *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLNORMALPOINTERVINTELPROC) (GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLCOLORPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +#endif + +#ifndef GL_HP_occlusion_test +#define GL_HP_occlusion_test 1 +#endif + +#ifndef GL_EXT_pixel_transform +#define GL_EXT_pixel_transform 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTransformParameteriEXT (GLenum, GLenum, GLint); +GLAPI void APIENTRY glPixelTransformParameterfEXT (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glPixelTransformParameterivEXT (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glPixelTransformParameterfvEXT (GLenum, GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_EXT_pixel_transform_color_table +#define GL_EXT_pixel_transform_color_table 1 +#endif + +#ifndef GL_EXT_shared_texture_palette +#define GL_EXT_shared_texture_palette 1 +#endif + +#ifndef GL_EXT_separate_specular_color +#define GL_EXT_separate_specular_color 1 +#endif + +#ifndef GL_EXT_secondary_color +#define GL_EXT_secondary_color 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSecondaryColor3bEXT (GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glSecondaryColor3bvEXT (const GLbyte *); +GLAPI void APIENTRY glSecondaryColor3dEXT (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glSecondaryColor3dvEXT (const GLdouble *); +GLAPI void APIENTRY glSecondaryColor3fEXT (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glSecondaryColor3fvEXT (const GLfloat *); +GLAPI void APIENTRY glSecondaryColor3iEXT (GLint, GLint, GLint); +GLAPI void APIENTRY glSecondaryColor3ivEXT (const GLint *); +GLAPI void APIENTRY glSecondaryColor3sEXT (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glSecondaryColor3svEXT (const GLshort *); +GLAPI void APIENTRY glSecondaryColor3ubEXT (GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glSecondaryColor3ubvEXT (const GLubyte *); +GLAPI void APIENTRY glSecondaryColor3uiEXT (GLuint, GLuint, GLuint); +GLAPI void APIENTRY glSecondaryColor3uivEXT (const GLuint *); +GLAPI void APIENTRY glSecondaryColor3usEXT (GLushort, GLushort, GLushort); +GLAPI void APIENTRY glSecondaryColor3usvEXT (const GLushort *); +GLAPI void APIENTRY glSecondaryColorPointerEXT (GLint, GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BEXTPROC) (GLbyte red, GLbyte green, GLbyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DEXTPROC) (GLdouble red, GLdouble green, GLdouble blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FEXTPROC) (GLfloat red, GLfloat green, GLfloat blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IEXTPROC) (GLint red, GLint green, GLint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SEXTPROC) (GLshort red, GLshort green, GLshort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBEXTPROC) (GLubyte red, GLubyte green, GLubyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVEXTPROC) (const GLubyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIEXTPROC) (GLuint red, GLuint green, GLuint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVEXTPROC) (const GLuint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USEXTPROC) (GLushort red, GLushort green, GLushort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVEXTPROC) (const GLushort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_texture_perturb_normal +#define GL_EXT_texture_perturb_normal 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureNormalEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTURENORMALEXTPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_multi_draw_arrays +#define GL_EXT_multi_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysEXT (GLenum, GLint *, GLsizei *, GLsizei); +GLAPI void APIENTRY glMultiDrawElementsEXT (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +#endif + +#ifndef GL_EXT_fog_coord +#define GL_EXT_fog_coord 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogCoordfEXT (GLfloat); +GLAPI void APIENTRY glFogCoordfvEXT (const GLfloat *); +GLAPI void APIENTRY glFogCoorddEXT (GLdouble); +GLAPI void APIENTRY glFogCoorddvEXT (const GLdouble *); +GLAPI void APIENTRY glFogCoordPointerEXT (GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFOGCOORDFEXTPROC) (GLfloat coord); +typedef void (APIENTRYP PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord); +typedef void (APIENTRYP PFNGLFOGCOORDDEXTPROC) (GLdouble coord); +typedef void (APIENTRYP PFNGLFOGCOORDDVEXTPROC) (const GLdouble *coord); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_REND_screen_coordinates +#define GL_REND_screen_coordinates 1 +#endif + +#ifndef GL_EXT_coordinate_frame +#define GL_EXT_coordinate_frame 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTangent3bEXT (GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glTangent3bvEXT (const GLbyte *); +GLAPI void APIENTRY glTangent3dEXT (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glTangent3dvEXT (const GLdouble *); +GLAPI void APIENTRY glTangent3fEXT (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTangent3fvEXT (const GLfloat *); +GLAPI void APIENTRY glTangent3iEXT (GLint, GLint, GLint); +GLAPI void APIENTRY glTangent3ivEXT (const GLint *); +GLAPI void APIENTRY glTangent3sEXT (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glTangent3svEXT (const GLshort *); +GLAPI void APIENTRY glBinormal3bEXT (GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glBinormal3bvEXT (const GLbyte *); +GLAPI void APIENTRY glBinormal3dEXT (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glBinormal3dvEXT (const GLdouble *); +GLAPI void APIENTRY glBinormal3fEXT (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glBinormal3fvEXT (const GLfloat *); +GLAPI void APIENTRY glBinormal3iEXT (GLint, GLint, GLint); +GLAPI void APIENTRY glBinormal3ivEXT (const GLint *); +GLAPI void APIENTRY glBinormal3sEXT (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glBinormal3svEXT (const GLshort *); +GLAPI void APIENTRY glTangentPointerEXT (GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glBinormalPointerEXT (GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTANGENT3BEXTPROC) (GLbyte tx, GLbyte ty, GLbyte tz); +typedef void (APIENTRYP PFNGLTANGENT3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLTANGENT3DEXTPROC) (GLdouble tx, GLdouble ty, GLdouble tz); +typedef void (APIENTRYP PFNGLTANGENT3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLTANGENT3FEXTPROC) (GLfloat tx, GLfloat ty, GLfloat tz); +typedef void (APIENTRYP PFNGLTANGENT3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLTANGENT3IEXTPROC) (GLint tx, GLint ty, GLint tz); +typedef void (APIENTRYP PFNGLTANGENT3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLTANGENT3SEXTPROC) (GLshort tx, GLshort ty, GLshort tz); +typedef void (APIENTRYP PFNGLTANGENT3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLBINORMAL3BEXTPROC) (GLbyte bx, GLbyte by, GLbyte bz); +typedef void (APIENTRYP PFNGLBINORMAL3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLBINORMAL3DEXTPROC) (GLdouble bx, GLdouble by, GLdouble bz); +typedef void (APIENTRYP PFNGLBINORMAL3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLBINORMAL3FEXTPROC) (GLfloat bx, GLfloat by, GLfloat bz); +typedef void (APIENTRYP PFNGLBINORMAL3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLBINORMAL3IEXTPROC) (GLint bx, GLint by, GLint bz); +typedef void (APIENTRYP PFNGLBINORMAL3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLBINORMAL3SEXTPROC) (GLshort bx, GLshort by, GLshort bz); +typedef void (APIENTRYP PFNGLBINORMAL3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLTANGENTPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLBINORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_texture_env_combine +#define GL_EXT_texture_env_combine 1 +#endif + +#ifndef GL_APPLE_specular_vector +#define GL_APPLE_specular_vector 1 +#endif + +#ifndef GL_APPLE_transform_hint +#define GL_APPLE_transform_hint 1 +#endif + +#ifndef GL_SGIX_fog_scale +#define GL_SGIX_fog_scale 1 +#endif + +#ifndef GL_SUNX_constant_data +#define GL_SUNX_constant_data 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFinishTextureSUNX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFINISHTEXTURESUNXPROC) (void); +#endif + +#ifndef GL_SUN_global_alpha +#define GL_SUN_global_alpha 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGlobalAlphaFactorbSUN (GLbyte); +GLAPI void APIENTRY glGlobalAlphaFactorsSUN (GLshort); +GLAPI void APIENTRY glGlobalAlphaFactoriSUN (GLint); +GLAPI void APIENTRY glGlobalAlphaFactorfSUN (GLfloat); +GLAPI void APIENTRY glGlobalAlphaFactordSUN (GLdouble); +GLAPI void APIENTRY glGlobalAlphaFactorubSUN (GLubyte); +GLAPI void APIENTRY glGlobalAlphaFactorusSUN (GLushort); +GLAPI void APIENTRY glGlobalAlphaFactoruiSUN (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORBSUNPROC) (GLbyte factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORSSUNPROC) (GLshort factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORISUNPROC) (GLint factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORFSUNPROC) (GLfloat factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORDSUNPROC) (GLdouble factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUBSUNPROC) (GLubyte factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUSSUNPROC) (GLushort factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUISUNPROC) (GLuint factor); +#endif + +#ifndef GL_SUN_triangle_list +#define GL_SUN_triangle_list 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReplacementCodeuiSUN (GLuint); +GLAPI void APIENTRY glReplacementCodeusSUN (GLushort); +GLAPI void APIENTRY glReplacementCodeubSUN (GLubyte); +GLAPI void APIENTRY glReplacementCodeuivSUN (const GLuint *); +GLAPI void APIENTRY glReplacementCodeusvSUN (const GLushort *); +GLAPI void APIENTRY glReplacementCodeubvSUN (const GLubyte *); +GLAPI void APIENTRY glReplacementCodePointerSUN (GLenum, GLsizei, const GLvoid* *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUISUNPROC) (GLuint code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSSUNPROC) (GLushort code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBSUNPROC) (GLubyte code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVSUNPROC) (const GLuint *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSVSUNPROC) (const GLushort *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBVSUNPROC) (const GLubyte *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEPOINTERSUNPROC) (GLenum type, GLsizei stride, const GLvoid* *pointer); +#endif + +#ifndef GL_SUN_vertex +#define GL_SUN_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColor4ubVertex2fSUN (GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat); +GLAPI void APIENTRY glColor4ubVertex2fvSUN (const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glColor4ubVertex3fSUN (GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glColor4ubVertex3fvSUN (const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glColor3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glColor3fVertex3fvSUN (const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glColor4fNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glColor4fNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fVertex3fvSUN (const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord4fVertex4fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord4fVertex4fvSUN (const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fSUN (GLfloat, GLfloat, GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fvSUN (const GLfloat *, const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fColor3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fColor3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fvSUN (const GLfloat *, const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiVertex3fvSUN (const GLuint *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fSUN (GLuint, GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fvSUN (const GLuint *, const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *, const GLfloat *, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FVSUNPROC) (const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FVSUNPROC) (const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FSUNPROC) (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FVSUNPROC) (const GLfloat *tc, const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FSUNPROC) (GLuint rc, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FSUNPROC) (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FVSUNPROC) (const GLuint *rc, const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +#endif + +#ifndef GL_EXT_blend_func_separate +#define GL_EXT_blend_func_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparateEXT (GLenum, GLenum, GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEEXTPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif + +#ifndef GL_INGR_blend_func_separate +#define GL_INGR_blend_func_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparateINGR (GLenum, GLenum, GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINGRPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif + +#ifndef GL_INGR_color_clamp +#define GL_INGR_color_clamp 1 +#endif + +#ifndef GL_INGR_interlace_read +#define GL_INGR_interlace_read 1 +#endif + +#ifndef GL_EXT_stencil_wrap +#define GL_EXT_stencil_wrap 1 +#endif + +#ifndef GL_EXT_422_pixels +#define GL_EXT_422_pixels 1 +#endif + +#ifndef GL_NV_texgen_reflection +#define GL_NV_texgen_reflection 1 +#endif + +#ifndef GL_SUN_convolution_border_modes +#define GL_SUN_convolution_border_modes 1 +#endif + +#ifndef GL_EXT_texture_env_add +#define GL_EXT_texture_env_add 1 +#endif + +#ifndef GL_EXT_texture_lod_bias +#define GL_EXT_texture_lod_bias 1 +#endif + +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_EXT_texture_filter_anisotropic 1 +#endif + +#ifndef GL_EXT_vertex_weighting +#define GL_EXT_vertex_weighting 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexWeightfEXT (GLfloat); +GLAPI void APIENTRY glVertexWeightfvEXT (const GLfloat *); +GLAPI void APIENTRY glVertexWeightPointerEXT (GLsizei, GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXWEIGHTFEXTPROC) (GLfloat weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat *weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTPOINTEREXTPROC) (GLsizei size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_NV_light_max_exponent +#define GL_NV_light_max_exponent 1 +#endif + +#ifndef GL_NV_vertex_array_range +#define GL_NV_vertex_array_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFlushVertexArrayRangeNV (void); +GLAPI void APIENTRY glVertexArrayRangeNV (GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGENVPROC) (void); +typedef void (APIENTRYP PFNGLVERTEXARRAYRANGENVPROC) (GLsizei length, const GLvoid *pointer); +#endif + +#ifndef GL_NV_register_combiners +#define GL_NV_register_combiners 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCombinerParameterfvNV (GLenum, const GLfloat *); +GLAPI void APIENTRY glCombinerParameterfNV (GLenum, GLfloat); +GLAPI void APIENTRY glCombinerParameterivNV (GLenum, const GLint *); +GLAPI void APIENTRY glCombinerParameteriNV (GLenum, GLint); +GLAPI void APIENTRY glCombinerInputNV (GLenum, GLenum, GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glCombinerOutputNV (GLenum, GLenum, GLenum, GLenum, GLenum, GLenum, GLenum, GLboolean, GLboolean, GLboolean); +GLAPI void APIENTRY glFinalCombinerInputNV (GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glGetCombinerInputParameterfvNV (GLenum, GLenum, GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetCombinerInputParameterivNV (GLenum, GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetCombinerOutputParameterfvNV (GLenum, GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetCombinerOutputParameterivNV (GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetFinalCombinerInputParameterfvNV (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetFinalCombinerInputParameterivNV (GLenum, GLenum, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFVNVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFNVPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERIVNVPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERINVPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLCOMBINERINPUTNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +typedef void (APIENTRYP PFNGLCOMBINEROUTPUTNVPROC) (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum); +typedef void (APIENTRYP PFNGLFINALCOMBINERINPUTNVPROC) (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC) (GLenum variable, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC) (GLenum variable, GLenum pname, GLint *params); +#endif + +#ifndef GL_NV_fog_distance +#define GL_NV_fog_distance 1 +#endif + +#ifndef GL_NV_texgen_emboss +#define GL_NV_texgen_emboss 1 +#endif + +#ifndef GL_NV_blend_square +#define GL_NV_blend_square 1 +#endif + +#ifndef GL_NV_texture_env_combine4 +#define GL_NV_texture_env_combine4 1 +#endif + +#ifndef GL_MESA_resize_buffers +#define GL_MESA_resize_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glResizeBuffersMESA (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRESIZEBUFFERSMESAPROC) (void); +#endif + +#ifndef GL_MESA_window_pos +#define GL_MESA_window_pos 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWindowPos2dMESA (GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos2dvMESA (const GLdouble *); +GLAPI void APIENTRY glWindowPos2fMESA (GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos2fvMESA (const GLfloat *); +GLAPI void APIENTRY glWindowPos2iMESA (GLint, GLint); +GLAPI void APIENTRY glWindowPos2ivMESA (const GLint *); +GLAPI void APIENTRY glWindowPos2sMESA (GLshort, GLshort); +GLAPI void APIENTRY glWindowPos2svMESA (const GLshort *); +GLAPI void APIENTRY glWindowPos3dMESA (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos3dvMESA (const GLdouble *); +GLAPI void APIENTRY glWindowPos3fMESA (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos3fvMESA (const GLfloat *); +GLAPI void APIENTRY glWindowPos3iMESA (GLint, GLint, GLint); +GLAPI void APIENTRY glWindowPos3ivMESA (const GLint *); +GLAPI void APIENTRY glWindowPos3sMESA (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glWindowPos3svMESA (const GLshort *); +GLAPI void APIENTRY glWindowPos4dMESA (GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos4dvMESA (const GLdouble *); +GLAPI void APIENTRY glWindowPos4fMESA (GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos4fvMESA (const GLfloat *); +GLAPI void APIENTRY glWindowPos4iMESA (GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glWindowPos4ivMESA (const GLint *); +GLAPI void APIENTRY glWindowPos4sMESA (GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glWindowPos4svMESA (const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWINDOWPOS2DMESAPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FMESAPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IMESAPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SMESAPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVMESAPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DMESAPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FMESAPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IMESAPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SMESAPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVMESAPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4DMESAPROC) (GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLWINDOWPOS4DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4FMESAPROC) (GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLWINDOWPOS4FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4IMESAPROC) (GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLWINDOWPOS4IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4SMESAPROC) (GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLWINDOWPOS4SVMESAPROC) (const GLshort *v); +#endif + +#ifndef GL_IBM_cull_vertex +#define GL_IBM_cull_vertex 1 +#endif + +#ifndef GL_IBM_multimode_draw_arrays +#define GL_IBM_multimode_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiModeDrawArraysIBM (const GLenum *, const GLint *, const GLsizei *, GLsizei, GLint); +GLAPI void APIENTRY glMultiModeDrawElementsIBM (const GLenum *, const GLsizei *, GLenum, const GLvoid* const *, GLsizei, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIMODEDRAWARRAYSIBMPROC) (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride); +typedef void (APIENTRYP PFNGLMULTIMODEDRAWELEMENTSIBMPROC) (const GLenum *mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, GLint modestride); +#endif + +#ifndef GL_IBM_vertex_array_lists +#define GL_IBM_vertex_array_lists 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glSecondaryColorPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glEdgeFlagPointerListIBM (GLint, const GLboolean* *, GLint); +GLAPI void APIENTRY glFogCoordPointerListIBM (GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glIndexPointerListIBM (GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glNormalPointerListIBM (GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glTexCoordPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glVertexPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLEDGEFLAGPOINTERLISTIBMPROC) (GLint stride, const GLboolean* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLINDEXPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLNORMALPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLVERTEXPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +#endif + +#ifndef GL_SGIX_subsample +#define GL_SGIX_subsample 1 +#endif + +#ifndef GL_SGIX_ycrcba +#define GL_SGIX_ycrcba 1 +#endif + +#ifndef GL_SGIX_ycrcb_subsample +#define GL_SGIX_ycrcb_subsample 1 +#endif + +#ifndef GL_SGIX_depth_pass_instrument +#define GL_SGIX_depth_pass_instrument 1 +#endif + +#ifndef GL_3DFX_texture_compression_FXT1 +#define GL_3DFX_texture_compression_FXT1 1 +#endif + +#ifndef GL_3DFX_multisample +#define GL_3DFX_multisample 1 +#endif + +#ifndef GL_3DFX_tbuffer +#define GL_3DFX_tbuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTbufferMask3DFX (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTBUFFERMASK3DFXPROC) (GLuint mask); +#endif + +#ifndef GL_EXT_multisample +#define GL_EXT_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleMaskEXT (GLclampf, GLboolean); +GLAPI void APIENTRY glSamplePatternEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLEMASKEXTPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLSAMPLEPATTERNEXTPROC) (GLenum pattern); +#endif + +#ifndef GL_SGIX_vertex_preclip +#define GL_SGIX_vertex_preclip 1 +#endif + +#ifndef GL_SGIX_convolution_accuracy +#define GL_SGIX_convolution_accuracy 1 +#endif + +#ifndef GL_SGIX_resample +#define GL_SGIX_resample 1 +#endif + +#ifndef GL_SGIS_point_line_texgen +#define GL_SGIS_point_line_texgen 1 +#endif + +#ifndef GL_SGIS_texture_color_mask +#define GL_SGIS_texture_color_mask 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureColorMaskSGIS (GLboolean, GLboolean, GLboolean, GLboolean); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTURECOLORMASKSGISPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +#endif + +#ifndef GL_SGIX_igloo_interface +#define GL_SGIX_igloo_interface 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIglooInterfaceSGIX (GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLIGLOOINTERFACESGIXPROC) (GLenum pname, const GLvoid *params); +#endif + +#ifndef GL_EXT_texture_env_dot3 +#define GL_EXT_texture_env_dot3 1 +#endif + +#ifndef GL_ATI_texture_mirror_once +#define GL_ATI_texture_mirror_once 1 +#endif + +#ifndef GL_NV_fence +#define GL_NV_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeleteFencesNV (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenFencesNV (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsFenceNV (GLuint); +GLAPI GLboolean APIENTRY glTestFenceNV (GLuint); +GLAPI void APIENTRY glGetFenceivNV (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glFinishFenceNV (GLuint); +GLAPI void APIENTRY glSetFenceNV (GLuint, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); +typedef void (APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); +typedef GLboolean (APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); +#endif + +#ifndef GL_NV_evaluators +#define GL_NV_evaluators 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMapControlPointsNV (GLenum, GLuint, GLenum, GLsizei, GLsizei, GLint, GLint, GLboolean, const GLvoid *); +GLAPI void APIENTRY glMapParameterivNV (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glMapParameterfvNV (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glGetMapControlPointsNV (GLenum, GLuint, GLenum, GLsizei, GLsizei, GLboolean, GLvoid *); +GLAPI void APIENTRY glGetMapParameterivNV (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetMapParameterfvNV (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetMapAttribParameterivNV (GLenum, GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetMapAttribParameterfvNV (GLenum, GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glEvalMapsNV (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const GLvoid *points); +typedef void (APIENTRYP PFNGLMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, GLvoid *points); +typedef void (APIENTRYP PFNGLGETMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERIVNVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLEVALMAPSNVPROC) (GLenum target, GLenum mode); +#endif + +#ifndef GL_NV_packed_depth_stencil +#define GL_NV_packed_depth_stencil 1 +#endif + +#ifndef GL_NV_register_combiners2 +#define GL_NV_register_combiners2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCombinerStageParameterfvNV (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glGetCombinerStageParameterfvNV (GLenum, GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_NV_texture_compression_vtc +#define GL_NV_texture_compression_vtc 1 +#endif + +#ifndef GL_NV_texture_rectangle +#define GL_NV_texture_rectangle 1 +#endif + +#ifndef GL_NV_texture_shader +#define GL_NV_texture_shader 1 +#endif + +#ifndef GL_NV_texture_shader2 +#define GL_NV_texture_shader2 1 +#endif + +#ifndef GL_NV_vertex_array_range2 +#define GL_NV_vertex_array_range2 1 +#endif + +#ifndef GL_NV_vertex_program +#define GL_NV_vertex_program 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glAreProgramsResidentNV (GLsizei, const GLuint *, GLboolean *); +GLAPI void APIENTRY glBindProgramNV (GLenum, GLuint); +GLAPI void APIENTRY glDeleteProgramsNV (GLsizei, const GLuint *); +GLAPI void APIENTRY glExecuteProgramNV (GLenum, GLuint, const GLfloat *); +GLAPI void APIENTRY glGenProgramsNV (GLsizei, GLuint *); +GLAPI void APIENTRY glGetProgramParameterdvNV (GLenum, GLuint, GLenum, GLdouble *); +GLAPI void APIENTRY glGetProgramParameterfvNV (GLenum, GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetProgramivNV (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetProgramStringNV (GLuint, GLenum, GLubyte *); +GLAPI void APIENTRY glGetTrackMatrixivNV (GLenum, GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribdvNV (GLuint, GLenum, GLdouble *); +GLAPI void APIENTRY glGetVertexAttribfvNV (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVertexAttribivNV (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribPointervNV (GLuint, GLenum, GLvoid* *); +GLAPI GLboolean APIENTRY glIsProgramNV (GLuint); +GLAPI void APIENTRY glLoadProgramNV (GLenum, GLuint, GLsizei, const GLubyte *); +GLAPI void APIENTRY glProgramParameter4dNV (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glProgramParameter4dvNV (GLenum, GLuint, const GLdouble *); +GLAPI void APIENTRY glProgramParameter4fNV (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramParameter4fvNV (GLenum, GLuint, const GLfloat *); +GLAPI void APIENTRY glProgramParameters4dvNV (GLenum, GLuint, GLuint, const GLdouble *); +GLAPI void APIENTRY glProgramParameters4fvNV (GLenum, GLuint, GLuint, const GLfloat *); +GLAPI void APIENTRY glRequestResidentProgramsNV (GLsizei, const GLuint *); +GLAPI void APIENTRY glTrackMatrixNV (GLenum, GLuint, GLenum, GLenum); +GLAPI void APIENTRY glVertexAttribPointerNV (GLuint, GLint, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glVertexAttrib1dNV (GLuint, GLdouble); +GLAPI void APIENTRY glVertexAttrib1dvNV (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib1fNV (GLuint, GLfloat); +GLAPI void APIENTRY glVertexAttrib1fvNV (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib1sNV (GLuint, GLshort); +GLAPI void APIENTRY glVertexAttrib1svNV (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib2dNV (GLuint, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib2dvNV (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib2fNV (GLuint, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib2fvNV (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib2sNV (GLuint, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib2svNV (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib3dNV (GLuint, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib3dvNV (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib3fNV (GLuint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib3fvNV (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib3sNV (GLuint, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib3svNV (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4dNV (GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib4dvNV (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib4fNV (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib4fvNV (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib4sNV (GLuint, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib4svNV (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4ubNV (GLuint, GLubyte, GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glVertexAttrib4ubvNV (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttribs1dvNV (GLuint, GLsizei, const GLdouble *); +GLAPI void APIENTRY glVertexAttribs1fvNV (GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glVertexAttribs1svNV (GLuint, GLsizei, const GLshort *); +GLAPI void APIENTRY glVertexAttribs2dvNV (GLuint, GLsizei, const GLdouble *); +GLAPI void APIENTRY glVertexAttribs2fvNV (GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glVertexAttribs2svNV (GLuint, GLsizei, const GLshort *); +GLAPI void APIENTRY glVertexAttribs3dvNV (GLuint, GLsizei, const GLdouble *); +GLAPI void APIENTRY glVertexAttribs3fvNV (GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glVertexAttribs3svNV (GLuint, GLsizei, const GLshort *); +GLAPI void APIENTRY glVertexAttribs4dvNV (GLuint, GLsizei, const GLdouble *); +GLAPI void APIENTRY glVertexAttribs4fvNV (GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glVertexAttribs4svNV (GLuint, GLsizei, const GLshort *); +GLAPI void APIENTRY glVertexAttribs4ubvNV (GLuint, GLsizei, const GLubyte *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLAREPROGRAMSRESIDENTNVPROC) (GLsizei n, const GLuint *programs, GLboolean *residences); +typedef void (APIENTRYP PFNGLBINDPROGRAMNVPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETEPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLEXECUTEPROGRAMNVPROC) (GLenum target, GLuint id, const GLfloat *params); +typedef void (APIENTRYP PFNGLGENPROGRAMSNVPROC) (GLsizei n, GLuint *programs); +typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERDVNVPROC) (GLenum target, GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMIVNVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGNVPROC) (GLuint id, GLenum pname, GLubyte *program); +typedef void (APIENTRYP PFNGLGETTRACKMATRIXIVNVPROC) (GLenum target, GLuint address, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVNVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVNVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVNVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVNVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLLOADPROGRAMNVPROC) (GLenum target, GLuint id, GLsizei len, const GLubyte *program); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DNVPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DVNVPROC) (GLenum target, GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FNVPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FVNVPROC) (GLenum target, GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4DVNVPROC) (GLenum target, GLuint index, GLuint count, const GLdouble *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4FVNVPROC) (GLenum target, GLuint index, GLuint count, const GLfloat *v); +typedef void (APIENTRYP PFNGLREQUESTRESIDENTPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLTRACKMATRIXNVPROC) (GLenum target, GLuint address, GLenum matrix, GLenum transform); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERNVPROC) (GLuint index, GLint fsize, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DNVPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FNVPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SNVPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DNVPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FNVPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SNVPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBNVPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVNVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4UBVNVPROC) (GLuint index, GLsizei count, const GLubyte *v); +#endif + +#ifndef GL_SGIX_texture_coordinate_clamp +#define GL_SGIX_texture_coordinate_clamp 1 +#endif + +#ifndef GL_SGIX_scalebias_hint +#define GL_SGIX_scalebias_hint 1 +#endif + +#ifndef GL_OML_interlace +#define GL_OML_interlace 1 +#endif + +#ifndef GL_OML_subsample +#define GL_OML_subsample 1 +#endif + +#ifndef GL_OML_resample +#define GL_OML_resample 1 +#endif + +#ifndef GL_NV_copy_depth_to_color +#define GL_NV_copy_depth_to_color 1 +#endif + +#ifndef GL_ATI_envmap_bumpmap +#define GL_ATI_envmap_bumpmap 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBumpParameterivATI (GLenum, const GLint *); +GLAPI void APIENTRY glTexBumpParameterfvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glGetTexBumpParameterivATI (GLenum, GLint *); +GLAPI void APIENTRY glGetTexBumpParameterfvATI (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERIVATIPROC) (GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERFVATIPROC) (GLenum pname, const GLfloat *param); +typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERIVATIPROC) (GLenum pname, GLint *param); +typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERFVATIPROC) (GLenum pname, GLfloat *param); +#endif + +#ifndef GL_ATI_fragment_shader +#define GL_ATI_fragment_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glGenFragmentShadersATI (GLuint); +GLAPI void APIENTRY glBindFragmentShaderATI (GLuint); +GLAPI void APIENTRY glDeleteFragmentShaderATI (GLuint); +GLAPI void APIENTRY glBeginFragmentShaderATI (void); +GLAPI void APIENTRY glEndFragmentShaderATI (void); +GLAPI void APIENTRY glPassTexCoordATI (GLuint, GLuint, GLenum); +GLAPI void APIENTRY glSampleMapATI (GLuint, GLuint, GLenum); +GLAPI void APIENTRY glColorFragmentOp1ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glColorFragmentOp2ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glColorFragmentOp3ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glAlphaFragmentOp1ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glAlphaFragmentOp2ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glAlphaFragmentOp3ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glSetFragmentShaderConstantATI (GLuint, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLuint (APIENTRYP PFNGLGENFRAGMENTSHADERSATIPROC) (GLuint range); +typedef void (APIENTRYP PFNGLBINDFRAGMENTSHADERATIPROC) (GLuint id); +typedef void (APIENTRYP PFNGLDELETEFRAGMENTSHADERATIPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINFRAGMENTSHADERATIPROC) (void); +typedef void (APIENTRYP PFNGLENDFRAGMENTSHADERATIPROC) (void); +typedef void (APIENTRYP PFNGLPASSTEXCOORDATIPROC) (GLuint dst, GLuint coord, GLenum swizzle); +typedef void (APIENTRYP PFNGLSAMPLEMAPATIPROC) (GLuint dst, GLuint interp, GLenum swizzle); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +typedef void (APIENTRYP PFNGLSETFRAGMENTSHADERCONSTANTATIPROC) (GLuint dst, const GLfloat *value); +#endif + +#ifndef GL_ATI_pn_triangles +#define GL_ATI_pn_triangles 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPNTrianglesiATI (GLenum, GLint); +GLAPI void APIENTRY glPNTrianglesfATI (GLenum, GLfloat); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPNTRIANGLESIATIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPNTRIANGLESFATIPROC) (GLenum pname, GLfloat param); +#endif + +#ifndef GL_ATI_vertex_array_object +#define GL_ATI_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glNewObjectBufferATI (GLsizei, const GLvoid *, GLenum); +GLAPI GLboolean APIENTRY glIsObjectBufferATI (GLuint); +GLAPI void APIENTRY glUpdateObjectBufferATI (GLuint, GLuint, GLsizei, const GLvoid *, GLenum); +GLAPI void APIENTRY glGetObjectBufferfvATI (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetObjectBufferivATI (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glFreeObjectBufferATI (GLuint); +GLAPI void APIENTRY glArrayObjectATI (GLenum, GLint, GLenum, GLsizei, GLuint, GLuint); +GLAPI void APIENTRY glGetArrayObjectfvATI (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetArrayObjectivATI (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glVariantArrayObjectATI (GLuint, GLenum, GLsizei, GLuint, GLuint); +GLAPI void APIENTRY glGetVariantArrayObjectfvATI (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVariantArrayObjectivATI (GLuint, GLenum, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLuint (APIENTRYP PFNGLNEWOBJECTBUFFERATIPROC) (GLsizei size, const GLvoid *pointer, GLenum usage); +typedef GLboolean (APIENTRYP PFNGLISOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLUPDATEOBJECTBUFFERATIPROC) (GLuint buffer, GLuint offset, GLsizei size, const GLvoid *pointer, GLenum preserve); +typedef void (APIENTRYP PFNGLGETOBJECTBUFFERFVATIPROC) (GLuint buffer, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETOBJECTBUFFERIVATIPROC) (GLuint buffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLFREEOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLARRAYOBJECTATIPROC) (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETARRAYOBJECTFVATIPROC) (GLenum array, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETARRAYOBJECTIVATIPROC) (GLenum array, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLVARIANTARRAYOBJECTATIPROC) (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTFVATIPROC) (GLuint id, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTIVATIPROC) (GLuint id, GLenum pname, GLint *params); +#endif + +#ifndef GL_EXT_vertex_shader +#define GL_EXT_vertex_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginVertexShaderEXT (void); +GLAPI void APIENTRY glEndVertexShaderEXT (void); +GLAPI void APIENTRY glBindVertexShaderEXT (GLuint); +GLAPI GLuint APIENTRY glGenVertexShadersEXT (GLuint); +GLAPI void APIENTRY glDeleteVertexShaderEXT (GLuint); +GLAPI void APIENTRY glShaderOp1EXT (GLenum, GLuint, GLuint); +GLAPI void APIENTRY glShaderOp2EXT (GLenum, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glShaderOp3EXT (GLenum, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glSwizzleEXT (GLuint, GLuint, GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glWriteMaskEXT (GLuint, GLuint, GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glInsertComponentEXT (GLuint, GLuint, GLuint); +GLAPI void APIENTRY glExtractComponentEXT (GLuint, GLuint, GLuint); +GLAPI GLuint APIENTRY glGenSymbolsEXT (GLenum, GLenum, GLenum, GLuint); +GLAPI void APIENTRY glSetInvariantEXT (GLuint, GLenum, const GLvoid *); +GLAPI void APIENTRY glSetLocalConstantEXT (GLuint, GLenum, const GLvoid *); +GLAPI void APIENTRY glVariantbvEXT (GLuint, const GLbyte *); +GLAPI void APIENTRY glVariantsvEXT (GLuint, const GLshort *); +GLAPI void APIENTRY glVariantivEXT (GLuint, const GLint *); +GLAPI void APIENTRY glVariantfvEXT (GLuint, const GLfloat *); +GLAPI void APIENTRY glVariantdvEXT (GLuint, const GLdouble *); +GLAPI void APIENTRY glVariantubvEXT (GLuint, const GLubyte *); +GLAPI void APIENTRY glVariantusvEXT (GLuint, const GLushort *); +GLAPI void APIENTRY glVariantuivEXT (GLuint, const GLuint *); +GLAPI void APIENTRY glVariantPointerEXT (GLuint, GLenum, GLuint, const GLvoid *); +GLAPI void APIENTRY glEnableVariantClientStateEXT (GLuint); +GLAPI void APIENTRY glDisableVariantClientStateEXT (GLuint); +GLAPI GLuint APIENTRY glBindLightParameterEXT (GLenum, GLenum); +GLAPI GLuint APIENTRY glBindMaterialParameterEXT (GLenum, GLenum); +GLAPI GLuint APIENTRY glBindTexGenParameterEXT (GLenum, GLenum, GLenum); +GLAPI GLuint APIENTRY glBindTextureUnitParameterEXT (GLenum, GLenum); +GLAPI GLuint APIENTRY glBindParameterEXT (GLenum); +GLAPI GLboolean APIENTRY glIsVariantEnabledEXT (GLuint, GLenum); +GLAPI void APIENTRY glGetVariantBooleanvEXT (GLuint, GLenum, GLboolean *); +GLAPI void APIENTRY glGetVariantIntegervEXT (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVariantFloatvEXT (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVariantPointervEXT (GLuint, GLenum, GLvoid* *); +GLAPI void APIENTRY glGetInvariantBooleanvEXT (GLuint, GLenum, GLboolean *); +GLAPI void APIENTRY glGetInvariantIntegervEXT (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetInvariantFloatvEXT (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetLocalConstantBooleanvEXT (GLuint, GLenum, GLboolean *); +GLAPI void APIENTRY glGetLocalConstantIntegervEXT (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetLocalConstantFloatvEXT (GLuint, GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINVERTEXSHADEREXTPROC) (void); +typedef void (APIENTRYP PFNGLENDVERTEXSHADEREXTPROC) (void); +typedef void (APIENTRYP PFNGLBINDVERTEXSHADEREXTPROC) (GLuint id); +typedef GLuint (APIENTRYP PFNGLGENVERTEXSHADERSEXTPROC) (GLuint range); +typedef void (APIENTRYP PFNGLDELETEVERTEXSHADEREXTPROC) (GLuint id); +typedef void (APIENTRYP PFNGLSHADEROP1EXTPROC) (GLenum op, GLuint res, GLuint arg1); +typedef void (APIENTRYP PFNGLSHADEROP2EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2); +typedef void (APIENTRYP PFNGLSHADEROP3EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3); +typedef void (APIENTRYP PFNGLSWIZZLEEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +typedef void (APIENTRYP PFNGLWRITEMASKEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +typedef void (APIENTRYP PFNGLINSERTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); +typedef void (APIENTRYP PFNGLEXTRACTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); +typedef GLuint (APIENTRYP PFNGLGENSYMBOLSEXTPROC) (GLenum datatype, GLenum storagetype, GLenum range, GLuint components); +typedef void (APIENTRYP PFNGLSETINVARIANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); +typedef void (APIENTRYP PFNGLSETLOCALCONSTANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); +typedef void (APIENTRYP PFNGLVARIANTBVEXTPROC) (GLuint id, const GLbyte *addr); +typedef void (APIENTRYP PFNGLVARIANTSVEXTPROC) (GLuint id, const GLshort *addr); +typedef void (APIENTRYP PFNGLVARIANTIVEXTPROC) (GLuint id, const GLint *addr); +typedef void (APIENTRYP PFNGLVARIANTFVEXTPROC) (GLuint id, const GLfloat *addr); +typedef void (APIENTRYP PFNGLVARIANTDVEXTPROC) (GLuint id, const GLdouble *addr); +typedef void (APIENTRYP PFNGLVARIANTUBVEXTPROC) (GLuint id, const GLubyte *addr); +typedef void (APIENTRYP PFNGLVARIANTUSVEXTPROC) (GLuint id, const GLushort *addr); +typedef void (APIENTRYP PFNGLVARIANTUIVEXTPROC) (GLuint id, const GLuint *addr); +typedef void (APIENTRYP PFNGLVARIANTPOINTEREXTPROC) (GLuint id, GLenum type, GLuint stride, const GLvoid *addr); +typedef void (APIENTRYP PFNGLENABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); +typedef void (APIENTRYP PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); +typedef GLuint (APIENTRYP PFNGLBINDLIGHTPARAMETEREXTPROC) (GLenum light, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDMATERIALPARAMETEREXTPROC) (GLenum face, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDTEXGENPARAMETEREXTPROC) (GLenum unit, GLenum coord, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDTEXTUREUNITPARAMETEREXTPROC) (GLenum unit, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDPARAMETEREXTPROC) (GLenum value); +typedef GLboolean (APIENTRYP PFNGLISVARIANTENABLEDEXTPROC) (GLuint id, GLenum cap); +typedef void (APIENTRYP PFNGLGETVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +typedef void (APIENTRYP PFNGLGETVARIANTPOINTERVEXTPROC) (GLuint id, GLenum value, GLvoid* *data); +typedef void (APIENTRYP PFNGLGETINVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETINVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +#endif + +#ifndef GL_ATI_vertex_streams +#define GL_ATI_vertex_streams 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexStream1sATI (GLenum, GLshort); +GLAPI void APIENTRY glVertexStream1svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glVertexStream1iATI (GLenum, GLint); +GLAPI void APIENTRY glVertexStream1ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glVertexStream1fATI (GLenum, GLfloat); +GLAPI void APIENTRY glVertexStream1fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glVertexStream1dATI (GLenum, GLdouble); +GLAPI void APIENTRY glVertexStream1dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glVertexStream2sATI (GLenum, GLshort, GLshort); +GLAPI void APIENTRY glVertexStream2svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glVertexStream2iATI (GLenum, GLint, GLint); +GLAPI void APIENTRY glVertexStream2ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glVertexStream2fATI (GLenum, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexStream2fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glVertexStream2dATI (GLenum, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexStream2dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glVertexStream3sATI (GLenum, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexStream3svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glVertexStream3iATI (GLenum, GLint, GLint, GLint); +GLAPI void APIENTRY glVertexStream3ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glVertexStream3fATI (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexStream3fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glVertexStream3dATI (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexStream3dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glVertexStream4sATI (GLenum, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexStream4svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glVertexStream4iATI (GLenum, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glVertexStream4ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glVertexStream4fATI (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexStream4fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glVertexStream4dATI (GLenum, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexStream4dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glNormalStream3bATI (GLenum, GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glNormalStream3bvATI (GLenum, const GLbyte *); +GLAPI void APIENTRY glNormalStream3sATI (GLenum, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glNormalStream3svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glNormalStream3iATI (GLenum, GLint, GLint, GLint); +GLAPI void APIENTRY glNormalStream3ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glNormalStream3fATI (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glNormalStream3fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glNormalStream3dATI (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glNormalStream3dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glClientActiveVertexStreamATI (GLenum); +GLAPI void APIENTRY glVertexBlendEnviATI (GLenum, GLint); +GLAPI void APIENTRY glVertexBlendEnvfATI (GLenum, GLfloat); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXSTREAM1SATIPROC) (GLenum stream, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1IATIPROC) (GLenum stream, GLint x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1FATIPROC) (GLenum stream, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1DATIPROC) (GLenum stream, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2SATIPROC) (GLenum stream, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2IATIPROC) (GLenum stream, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2FATIPROC) (GLenum stream, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2DATIPROC) (GLenum stream, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3IATIPROC) (GLenum stream, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4IATIPROC) (GLenum stream, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3BATIPROC) (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3BVATIPROC) (GLenum stream, const GLbyte *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3SATIPROC) (GLenum stream, GLshort nx, GLshort ny, GLshort nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3IATIPROC) (GLenum stream, GLint nx, GLint ny, GLint nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3FATIPROC) (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3DATIPROC) (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLCLIENTACTIVEVERTEXSTREAMATIPROC) (GLenum stream); +typedef void (APIENTRYP PFNGLVERTEXBLENDENVIATIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLVERTEXBLENDENVFATIPROC) (GLenum pname, GLfloat param); +#endif + +#ifndef GL_ATI_element_array +#define GL_ATI_element_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glElementPointerATI (GLenum, const GLvoid *); +GLAPI void APIENTRY glDrawElementArrayATI (GLenum, GLsizei); +GLAPI void APIENTRY glDrawRangeElementArrayATI (GLenum, GLuint, GLuint, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLELEMENTPOINTERATIPROC) (GLenum type, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYATIPROC) (GLenum mode, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYATIPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count); +#endif + +#ifndef GL_SUN_mesh_array +#define GL_SUN_mesh_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawMeshArraysSUN (GLenum, GLint, GLsizei, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWMESHARRAYSSUNPROC) (GLenum mode, GLint first, GLsizei count, GLsizei width); +#endif + +#ifndef GL_SUN_slice_accum +#define GL_SUN_slice_accum 1 +#endif + +#ifndef GL_NV_multisample_filter_hint +#define GL_NV_multisample_filter_hint 1 +#endif + +#ifndef GL_NV_depth_clamp +#define GL_NV_depth_clamp 1 +#endif + +#ifndef GL_NV_occlusion_query +#define GL_NV_occlusion_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenOcclusionQueriesNV (GLsizei, GLuint *); +GLAPI void APIENTRY glDeleteOcclusionQueriesNV (GLsizei, const GLuint *); +GLAPI GLboolean APIENTRY glIsOcclusionQueryNV (GLuint); +GLAPI void APIENTRY glBeginOcclusionQueryNV (GLuint); +GLAPI void APIENTRY glEndOcclusionQueryNV (void); +GLAPI void APIENTRY glGetOcclusionQueryivNV (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetOcclusionQueryuivNV (GLuint, GLenum, GLuint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENOCCLUSIONQUERIESNVPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEOCCLUSIONQUERIESNVPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISOCCLUSIONQUERYNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINOCCLUSIONQUERYNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLENDOCCLUSIONQUERYNVPROC) (void); +typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYIVNVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYUIVNVPROC) (GLuint id, GLenum pname, GLuint *params); +#endif + +#ifndef GL_NV_point_sprite +#define GL_NV_point_sprite 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameteriNV (GLenum, GLint); +GLAPI void APIENTRY glPointParameterivNV (GLenum, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERINVPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVNVPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_NV_texture_shader3 +#define GL_NV_texture_shader3 1 +#endif + +#ifndef GL_NV_vertex_program1_1 +#define GL_NV_vertex_program1_1 1 +#endif + +#ifndef GL_EXT_shadow_funcs +#define GL_EXT_shadow_funcs 1 +#endif + +#ifndef GL_EXT_stencil_two_side +#define GL_EXT_stencil_two_side 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveStencilFaceEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVESTENCILFACEEXTPROC) (GLenum face); +#endif + +#ifndef GL_ATI_text_fragment_shader +#define GL_ATI_text_fragment_shader 1 +#endif + +#ifndef GL_APPLE_client_storage +#define GL_APPLE_client_storage 1 +#endif + +#ifndef GL_APPLE_element_array +#define GL_APPLE_element_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glElementPointerAPPLE (GLenum, const GLvoid *); +GLAPI void APIENTRY glDrawElementArrayAPPLE (GLenum, GLint, GLsizei); +GLAPI void APIENTRY glDrawRangeElementArrayAPPLE (GLenum, GLuint, GLuint, GLint, GLsizei); +GLAPI void APIENTRY glMultiDrawElementArrayAPPLE (GLenum, const GLint *, const GLsizei *, GLsizei); +GLAPI void APIENTRY glMultiDrawRangeElementArrayAPPLE (GLenum, GLuint, GLuint, const GLint *, const GLsizei *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLELEMENTPOINTERAPPLEPROC) (GLenum type, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount); +#endif + +#ifndef GL_APPLE_fence +#define GL_APPLE_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenFencesAPPLE (GLsizei, GLuint *); +GLAPI void APIENTRY glDeleteFencesAPPLE (GLsizei, const GLuint *); +GLAPI void APIENTRY glSetFenceAPPLE (GLuint); +GLAPI GLboolean APIENTRY glIsFenceAPPLE (GLuint); +GLAPI GLboolean APIENTRY glTestFenceAPPLE (GLuint); +GLAPI void APIENTRY glFinishFenceAPPLE (GLuint); +GLAPI GLboolean APIENTRY glTestObjectAPPLE (GLenum, GLuint); +GLAPI void APIENTRY glFinishObjectAPPLE (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENFENCESAPPLEPROC) (GLsizei n, GLuint *fences); +typedef void (APIENTRYP PFNGLDELETEFENCESAPPLEPROC) (GLsizei n, const GLuint *fences); +typedef void (APIENTRYP PFNGLSETFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLISFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTFENCEAPPLEPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLFINISHFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTOBJECTAPPLEPROC) (GLenum object, GLuint name); +typedef void (APIENTRYP PFNGLFINISHOBJECTAPPLEPROC) (GLenum object, GLint name); +#endif + +#ifndef GL_APPLE_vertex_array_object +#define GL_APPLE_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindVertexArrayAPPLE (GLuint); +GLAPI void APIENTRY glDeleteVertexArraysAPPLE (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenVertexArraysAPPLE (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsVertexArrayAPPLE (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXARRAYAPPLEPROC) (GLuint array); +typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); +typedef void (APIENTRYP PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array); +#endif + +#ifndef GL_APPLE_vertex_array_range +#define GL_APPLE_vertex_array_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexArrayRangeAPPLE (GLsizei, GLvoid *); +GLAPI void APIENTRY glFlushVertexArrayRangeAPPLE (GLsizei, GLvoid *); +GLAPI void APIENTRY glVertexArrayParameteriAPPLE (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXARRAYPARAMETERIAPPLEPROC) (GLenum pname, GLint param); +#endif + +#ifndef GL_APPLE_ycbcr_422 +#define GL_APPLE_ycbcr_422 1 +#endif + +#ifndef GL_S3_s3tc +#define GL_S3_s3tc 1 +#endif + +#ifndef GL_ATI_draw_buffers +#define GL_ATI_draw_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawBuffersATI (GLsizei, const GLenum *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWBUFFERSATIPROC) (GLsizei n, const GLenum *bufs); +#endif + +#ifndef GL_ATI_pixel_format_float +#define GL_ATI_pixel_format_float 1 +/* This is really a WGL extension, but defines some associated GL enums. + * ATI does not export "GL_ATI_pixel_format_float" in the GL_EXTENSIONS string. + */ +#endif + +#ifndef GL_ATI_texture_env_combine3 +#define GL_ATI_texture_env_combine3 1 +#endif + +#ifndef GL_ATI_texture_float +#define GL_ATI_texture_float 1 +#endif + +#ifndef GL_NV_float_buffer +#define GL_NV_float_buffer 1 +#endif + +#ifndef GL_NV_fragment_program +#define GL_NV_fragment_program 1 +/* Some NV_fragment_program entry points are shared with ARB_vertex_program. */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramNamedParameter4fNV (GLuint, GLsizei, const GLubyte *, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramNamedParameter4dNV (GLuint, GLsizei, const GLubyte *, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glProgramNamedParameter4fvNV (GLuint, GLsizei, const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glProgramNamedParameter4dvNV (GLuint, GLsizei, const GLubyte *, const GLdouble *); +GLAPI void APIENTRY glGetProgramNamedParameterfvNV (GLuint, GLsizei, const GLubyte *, GLfloat *); +GLAPI void APIENTRY glGetProgramNamedParameterdvNV (GLuint, GLsizei, const GLubyte *, GLdouble *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v); +typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERFVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERDVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params); +#endif + +#ifndef GL_NV_half_float +#define GL_NV_half_float 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertex2hNV (GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertex2hvNV (const GLhalfNV *); +GLAPI void APIENTRY glVertex3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertex3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glVertex4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertex4hvNV (const GLhalfNV *); +GLAPI void APIENTRY glNormal3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glNormal3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glColor3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glColor3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glColor4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glColor4hvNV (const GLhalfNV *); +GLAPI void APIENTRY glTexCoord1hNV (GLhalfNV); +GLAPI void APIENTRY glTexCoord1hvNV (const GLhalfNV *); +GLAPI void APIENTRY glTexCoord2hNV (GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glTexCoord2hvNV (const GLhalfNV *); +GLAPI void APIENTRY glTexCoord3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glTexCoord3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glTexCoord4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glTexCoord4hvNV (const GLhalfNV *); +GLAPI void APIENTRY glMultiTexCoord1hNV (GLenum, GLhalfNV); +GLAPI void APIENTRY glMultiTexCoord1hvNV (GLenum, const GLhalfNV *); +GLAPI void APIENTRY glMultiTexCoord2hNV (GLenum, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glMultiTexCoord2hvNV (GLenum, const GLhalfNV *); +GLAPI void APIENTRY glMultiTexCoord3hNV (GLenum, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glMultiTexCoord3hvNV (GLenum, const GLhalfNV *); +GLAPI void APIENTRY glMultiTexCoord4hNV (GLenum, GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glMultiTexCoord4hvNV (GLenum, const GLhalfNV *); +GLAPI void APIENTRY glFogCoordhNV (GLhalfNV); +GLAPI void APIENTRY glFogCoordhvNV (const GLhalfNV *); +GLAPI void APIENTRY glSecondaryColor3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glSecondaryColor3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glVertexWeighthNV (GLhalfNV); +GLAPI void APIENTRY glVertexWeighthvNV (const GLhalfNV *); +GLAPI void APIENTRY glVertexAttrib1hNV (GLuint, GLhalfNV); +GLAPI void APIENTRY glVertexAttrib1hvNV (GLuint, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttrib2hNV (GLuint, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertexAttrib2hvNV (GLuint, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttrib3hNV (GLuint, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertexAttrib3hvNV (GLuint, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttrib4hNV (GLuint, GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertexAttrib4hvNV (GLuint, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttribs1hvNV (GLuint, GLsizei, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttribs2hvNV (GLuint, GLsizei, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttribs3hvNV (GLuint, GLsizei, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttribs4hvNV (GLuint, GLsizei, const GLhalfNV *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEX2HNVPROC) (GLhalfNV x, GLhalfNV y); +typedef void (APIENTRYP PFNGLVERTEX2HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEX3HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z); +typedef void (APIENTRYP PFNGLVERTEX3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEX4HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +typedef void (APIENTRYP PFNGLVERTEX4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLNORMAL3HNVPROC) (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz); +typedef void (APIENTRYP PFNGLNORMAL3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +typedef void (APIENTRYP PFNGLCOLOR3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLCOLOR4HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha); +typedef void (APIENTRYP PFNGLCOLOR4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD1HNVPROC) (GLhalfNV s); +typedef void (APIENTRYP PFNGLTEXCOORD1HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD2HNVPROC) (GLhalfNV s, GLhalfNV t); +typedef void (APIENTRYP PFNGLTEXCOORD2HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD3HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r); +typedef void (APIENTRYP PFNGLTEXCOORD3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD4HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +typedef void (APIENTRYP PFNGLTEXCOORD4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1HNVPROC) (GLenum target, GLhalfNV s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLFOGCOORDHNVPROC) (GLhalfNV fog); +typedef void (APIENTRYP PFNGLFOGCOORDHVNVPROC) (const GLhalfNV *fog); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTHNVPROC) (GLhalfNV weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTHVNVPROC) (const GLhalfNV *weight); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1HNVPROC) (GLuint index, GLhalfNV x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +#endif + +#ifndef GL_NV_pixel_data_range +#define GL_NV_pixel_data_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelDataRangeNV (GLenum, GLsizei, GLvoid *); +GLAPI void APIENTRY glFlushPixelDataRangeNV (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELDATARANGENVPROC) (GLenum target, GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLFLUSHPIXELDATARANGENVPROC) (GLenum target); +#endif + +#ifndef GL_NV_primitive_restart +#define GL_NV_primitive_restart 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPrimitiveRestartNV (void); +GLAPI void APIENTRY glPrimitiveRestartIndexNV (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTNVPROC) (void); +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXNVPROC) (GLuint index); +#endif + +#ifndef GL_NV_texture_expand_normal +#define GL_NV_texture_expand_normal 1 +#endif + +#ifndef GL_NV_vertex_program2 +#define GL_NV_vertex_program2 1 +#endif + +#ifndef GL_ATI_map_object_buffer +#define GL_ATI_map_object_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLvoid* APIENTRY glMapObjectBufferATI (GLuint); +GLAPI void APIENTRY glUnmapObjectBufferATI (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLvoid* (APIENTRYP PFNGLMAPOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLUNMAPOBJECTBUFFERATIPROC) (GLuint buffer); +#endif + +#ifndef GL_ATI_separate_stencil +#define GL_ATI_separate_stencil 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStencilOpSeparateATI (GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glStencilFuncSeparateATI (GLenum, GLenum, GLint, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEATIPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEATIPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); +#endif + +#ifndef GL_ATI_vertex_attrib_array_object +#define GL_ATI_vertex_attrib_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribArrayObjectATI (GLuint, GLint, GLenum, GLboolean, GLsizei, GLuint, GLuint); +GLAPI void APIENTRY glGetVertexAttribArrayObjectfvATI (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVertexAttribArrayObjectivATI (GLuint, GLenum, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBARRAYOBJECTATIPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTFVATIPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTIVATIPROC) (GLuint index, GLenum pname, GLint *params); +#endif + +#ifndef GL_OES_read_format +#define GL_OES_read_format 1 +#endif + +#ifndef GL_EXT_depth_bounds_test +#define GL_EXT_depth_bounds_test 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDepthBoundsEXT (GLclampd, GLclampd); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEPTHBOUNDSEXTPROC) (GLclampd zmin, GLclampd zmax); +#endif + +#ifndef GL_EXT_texture_mirror_clamp +#define GL_EXT_texture_mirror_clamp 1 +#endif + +#ifndef GL_EXT_blend_equation_separate +#define GL_EXT_blend_equation_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparateEXT (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEEXTPROC) (GLenum modeRGB, GLenum modeAlpha); +#endif + +#ifndef GL_MESA_pack_invert +#define GL_MESA_pack_invert 1 +#endif + +#ifndef GL_MESA_ycbcr_texture +#define GL_MESA_ycbcr_texture 1 +#endif + +#ifndef GL_EXT_pixel_buffer_object +#define GL_EXT_pixel_buffer_object 1 +#endif + +#ifndef GL_NV_fragment_program_option +#define GL_NV_fragment_program_option 1 +#endif + +#ifndef GL_NV_fragment_program2 +#define GL_NV_fragment_program2 1 +#endif + +#ifndef GL_NV_vertex_program2_option +#define GL_NV_vertex_program2_option 1 +#endif + +#ifndef GL_NV_vertex_program3 +#define GL_NV_vertex_program3 1 +#endif + +#ifndef GL_EXT_framebuffer_object +#define GL_EXT_framebuffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glIsRenderbufferEXT (GLuint); +GLAPI void APIENTRY glBindRenderbufferEXT (GLenum, GLuint); +GLAPI void APIENTRY glDeleteRenderbuffersEXT (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenRenderbuffersEXT (GLsizei, GLuint *); +GLAPI void APIENTRY glRenderbufferStorageEXT (GLenum, GLenum, GLsizei, GLsizei); +GLAPI void APIENTRY glGetRenderbufferParameterivEXT (GLenum, GLenum, GLint *); +GLAPI GLboolean APIENTRY glIsFramebufferEXT (GLuint); +GLAPI void APIENTRY glBindFramebufferEXT (GLenum, GLuint); +GLAPI void APIENTRY glDeleteFramebuffersEXT (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenFramebuffersEXT (GLsizei, GLuint *); +GLAPI GLenum APIENTRY glCheckFramebufferStatusEXT (GLenum); +GLAPI void APIENTRY glFramebufferTexture1DEXT (GLenum, GLenum, GLenum, GLuint, GLint); +GLAPI void APIENTRY glFramebufferTexture2DEXT (GLenum, GLenum, GLenum, GLuint, GLint); +GLAPI void APIENTRY glFramebufferTexture3DEXT (GLenum, GLenum, GLenum, GLuint, GLint, GLint); +GLAPI void APIENTRY glFramebufferRenderbufferEXT (GLenum, GLenum, GLenum, GLuint); +GLAPI void APIENTRY glGetFramebufferAttachmentParameterivEXT (GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGenerateMipmapEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFEREXTPROC) (GLuint renderbuffer); +typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFEREXTPROC) (GLuint framebuffer); +typedef void (APIENTRYP PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum target, GLuint framebuffer); +typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei n, const GLuint *framebuffers); +typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei n, GLuint *framebuffers); +typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATEMIPMAPEXTPROC) (GLenum target); +#endif + +#ifndef GL_GREMEDY_string_marker +#define GL_GREMEDY_string_marker 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStringMarkerGREMEDY (GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const GLvoid *string); +#endif + +#ifndef GL_EXT_packed_depth_stencil +#define GL_EXT_packed_depth_stencil 1 +#endif + +#ifndef GL_EXT_stencil_clear_tag +#define GL_EXT_stencil_clear_tag 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStencilClearTagEXT (GLsizei, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSTENCILCLEARTAGEXTPROC) (GLsizei stencilTagBits, GLuint stencilClearTag); +#endif + +#ifndef GL_EXT_texture_sRGB +#define GL_EXT_texture_sRGB 1 +#endif + +#ifndef GL_EXT_framebuffer_blit +#define GL_EXT_framebuffer_blit 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlitFramebufferEXT (GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLITFRAMEBUFFEREXTPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif + +#ifndef GL_EXT_framebuffer_multisample +#define GL_EXT_framebuffer_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glRenderbufferStorageMultisampleEXT (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +#endif + +#ifndef GL_MESAX_texture_stack +#define GL_MESAX_texture_stack 1 +#endif + +#ifndef GL_EXT_timer_query +#define GL_EXT_timer_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetQueryObjecti64vEXT (GLuint, GLenum, GLint64EXT *); +GLAPI void APIENTRY glGetQueryObjectui64vEXT (GLuint, GLenum, GLuint64EXT *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VEXTPROC) (GLuint id, GLenum pname, GLint64EXT *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VEXTPROC) (GLuint id, GLenum pname, GLuint64EXT *params); +#endif + +#ifndef GL_EXT_gpu_program_parameters +#define GL_EXT_gpu_program_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramEnvParameters4fvEXT (GLenum, GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glProgramLocalParameters4fvEXT (GLenum, GLuint, GLsizei, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +#endif + +#ifndef GL_APPLE_flush_buffer_range +#define GL_APPLE_flush_buffer_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBufferParameteriAPPLE (GLenum, GLenum, GLint); +GLAPI void APIENTRY glFlushMappedBufferRangeAPPLE (GLenum, GLintptr, GLsizeiptr); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBUFFERPARAMETERIAPPLEPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEAPPLEPROC) (GLenum target, GLintptr offset, GLsizeiptr size); +#endif + +#ifndef GL_NV_gpu_program4 +#define GL_NV_gpu_program4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramLocalParameterI4iNV (GLenum, GLuint, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glProgramLocalParameterI4ivNV (GLenum, GLuint, const GLint *); +GLAPI void APIENTRY glProgramLocalParametersI4ivNV (GLenum, GLuint, GLsizei, const GLint *); +GLAPI void APIENTRY glProgramLocalParameterI4uiNV (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glProgramLocalParameterI4uivNV (GLenum, GLuint, const GLuint *); +GLAPI void APIENTRY glProgramLocalParametersI4uivNV (GLenum, GLuint, GLsizei, const GLuint *); +GLAPI void APIENTRY glProgramEnvParameterI4iNV (GLenum, GLuint, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glProgramEnvParameterI4ivNV (GLenum, GLuint, const GLint *); +GLAPI void APIENTRY glProgramEnvParametersI4ivNV (GLenum, GLuint, GLsizei, const GLint *); +GLAPI void APIENTRY glProgramEnvParameterI4uiNV (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glProgramEnvParameterI4uivNV (GLenum, GLuint, const GLuint *); +GLAPI void APIENTRY glProgramEnvParametersI4uivNV (GLenum, GLuint, GLsizei, const GLuint *); +GLAPI void APIENTRY glGetProgramLocalParameterIivNV (GLenum, GLuint, GLint *); +GLAPI void APIENTRY glGetProgramLocalParameterIuivNV (GLenum, GLuint, GLuint *); +GLAPI void APIENTRY glGetProgramEnvParameterIivNV (GLenum, GLuint, GLint *); +GLAPI void APIENTRY glGetProgramEnvParameterIuivNV (GLenum, GLuint, GLuint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params); +#endif + +#ifndef GL_NV_geometry_program4 +#define GL_NV_geometry_program4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramVertexLimitNV (GLenum, GLint); +GLAPI void APIENTRY glFramebufferTextureEXT (GLenum, GLenum, GLuint, GLint); +GLAPI void APIENTRY glFramebufferTextureLayerEXT (GLenum, GLenum, GLuint, GLint, GLint); +GLAPI void APIENTRY glFramebufferTextureFaceEXT (GLenum, GLenum, GLuint, GLint, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMVERTEXLIMITNVPROC) (GLenum target, GLint limit); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYEREXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#endif + +#ifndef GL_EXT_geometry_shader4 +#define GL_EXT_geometry_shader4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramParameteriEXT (GLuint, GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIEXTPROC) (GLuint program, GLenum pname, GLint value); +#endif + +#ifndef GL_NV_vertex_program4 +#define GL_NV_vertex_program4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribI1iEXT (GLuint, GLint); +GLAPI void APIENTRY glVertexAttribI2iEXT (GLuint, GLint, GLint); +GLAPI void APIENTRY glVertexAttribI3iEXT (GLuint, GLint, GLint, GLint); +GLAPI void APIENTRY glVertexAttribI4iEXT (GLuint, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glVertexAttribI1uiEXT (GLuint, GLuint); +GLAPI void APIENTRY glVertexAttribI2uiEXT (GLuint, GLuint, GLuint); +GLAPI void APIENTRY glVertexAttribI3uiEXT (GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glVertexAttribI4uiEXT (GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glVertexAttribI1ivEXT (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttribI2ivEXT (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttribI3ivEXT (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttribI4ivEXT (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttribI1uivEXT (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttribI2uivEXT (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttribI3uivEXT (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttribI4uivEXT (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttribI4bvEXT (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttribI4svEXT (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttribI4ubvEXT (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttribI4usvEXT (GLuint, const GLushort *); +GLAPI void APIENTRY glVertexAttribIPointerEXT (GLuint, GLint, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glGetVertexAttribIivEXT (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribIuivEXT (GLuint, GLenum, GLuint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IEXTPROC) (GLuint index, GLint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IEXTPROC) (GLuint index, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IEXTPROC) (GLuint index, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IEXTPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIEXTPROC) (GLuint index, GLuint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIEXTPROC) (GLuint index, GLuint x, GLuint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVEXTPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVEXTPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVEXTPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVEXTPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTEREXTPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVEXTPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVEXTPROC) (GLuint index, GLenum pname, GLuint *params); +#endif + +#ifndef GL_EXT_gpu_shader4 +#define GL_EXT_gpu_shader4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetUniformuivEXT (GLuint, GLint, GLuint *); +GLAPI void APIENTRY glBindFragDataLocationEXT (GLuint, GLuint, const GLchar *); +GLAPI GLint APIENTRY glGetFragDataLocationEXT (GLuint, const GLchar *); +GLAPI void APIENTRY glUniform1uiEXT (GLint, GLuint); +GLAPI void APIENTRY glUniform2uiEXT (GLint, GLuint, GLuint); +GLAPI void APIENTRY glUniform3uiEXT (GLint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glUniform4uiEXT (GLint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glUniform1uivEXT (GLint, GLsizei, const GLuint *); +GLAPI void APIENTRY glUniform2uivEXT (GLint, GLsizei, const GLuint *); +GLAPI void APIENTRY glUniform3uivEXT (GLint, GLsizei, const GLuint *); +GLAPI void APIENTRY glUniform4uivEXT (GLint, GLsizei, const GLuint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETUNIFORMUIVEXTPROC) (GLuint program, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONEXTPROC) (GLuint program, GLuint color, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONEXTPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORM1UIEXTPROC) (GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLUNIFORM2UIEXTPROC) (GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLUNIFORM3UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLUNIFORM4UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLUNIFORM1UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM2UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM3UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM4UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +#endif + +#ifndef GL_EXT_draw_instanced +#define GL_EXT_draw_instanced 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstancedEXT (GLenum, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glDrawElementsInstancedEXT (GLenum, GLsizei, GLenum, const GLvoid *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDEXTPROC) (GLenum mode, GLint start, GLsizei count, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDEXTPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +#endif + +#ifndef GL_EXT_packed_float +#define GL_EXT_packed_float 1 +#endif + +#ifndef GL_EXT_texture_array +#define GL_EXT_texture_array 1 +#endif + +#ifndef GL_EXT_texture_buffer_object +#define GL_EXT_texture_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBufferEXT (GLenum, GLenum, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUFFEREXTPROC) (GLenum target, GLenum internalformat, GLuint buffer); +#endif + +#ifndef GL_EXT_texture_compression_latc +#define GL_EXT_texture_compression_latc 1 +#endif + +#ifndef GL_EXT_texture_compression_rgtc +#define GL_EXT_texture_compression_rgtc 1 +#endif + +#ifndef GL_EXT_texture_shared_exponent +#define GL_EXT_texture_shared_exponent 1 +#endif + +#ifndef GL_NV_depth_buffer_float +#define GL_NV_depth_buffer_float 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDepthRangedNV (GLdouble, GLdouble); +GLAPI void APIENTRY glClearDepthdNV (GLdouble); +GLAPI void APIENTRY glDepthBoundsdNV (GLdouble, GLdouble); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEPTHRANGEDNVPROC) (GLdouble zNear, GLdouble zFar); +typedef void (APIENTRYP PFNGLCLEARDEPTHDNVPROC) (GLdouble depth); +typedef void (APIENTRYP PFNGLDEPTHBOUNDSDNVPROC) (GLdouble zmin, GLdouble zmax); +#endif + +#ifndef GL_NV_fragment_program4 +#define GL_NV_fragment_program4 1 +#endif + +#ifndef GL_NV_framebuffer_multisample_coverage +#define GL_NV_framebuffer_multisample_coverage 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glRenderbufferStorageMultisampleCoverageNV (GLenum, GLsizei, GLsizei, GLenum, GLsizei, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +#endif + +#ifndef GL_EXT_framebuffer_sRGB +#define GL_EXT_framebuffer_sRGB 1 +#endif + +#ifndef GL_NV_geometry_shader4 +#define GL_NV_geometry_shader4 1 +#endif + +#ifndef GL_NV_parameter_buffer_object +#define GL_NV_parameter_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramBufferParametersfvNV (GLenum, GLuint, GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glProgramBufferParametersIivNV (GLenum, GLuint, GLuint, GLsizei, const GLint *); +GLAPI void APIENTRY glProgramBufferParametersIuivNV (GLenum, GLuint, GLuint, GLsizei, const GLuint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSFVNVPROC) (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIIVNVPROC) (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIUIVNVPROC) (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLuint *params); +#endif + +#ifndef GL_EXT_draw_buffers2 +#define GL_EXT_draw_buffers2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorMaskIndexedEXT (GLuint, GLboolean, GLboolean, GLboolean, GLboolean); +GLAPI void APIENTRY glGetBooleanIndexedvEXT (GLenum, GLuint, GLboolean *); +GLAPI void APIENTRY glGetIntegerIndexedvEXT (GLenum, GLuint, GLint *); +GLAPI void APIENTRY glEnableIndexedEXT (GLenum, GLuint); +GLAPI void APIENTRY glDisableIndexedEXT (GLenum, GLuint); +GLAPI GLboolean APIENTRY glIsEnabledIndexedEXT (GLenum, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORMASKINDEXEDEXTPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +typedef void (APIENTRYP PFNGLGETBOOLEANINDEXEDVEXTPROC) (GLenum target, GLuint index, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINTEGERINDEXEDVEXTPROC) (GLenum target, GLuint index, GLint *data); +typedef void (APIENTRYP PFNGLENABLEINDEXEDEXTPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLDISABLEINDEXEDEXTPROC) (GLenum target, GLuint index); +typedef GLboolean (APIENTRYP PFNGLISENABLEDINDEXEDEXTPROC) (GLenum target, GLuint index); +#endif + +#ifndef GL_NV_transform_feedback +#define GL_NV_transform_feedback 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginTransformFeedbackNV (GLenum); +GLAPI void APIENTRY glEndTransformFeedbackNV (void); +GLAPI void APIENTRY glTransformFeedbackAttribsNV (GLuint, const GLint *, GLenum); +GLAPI void APIENTRY glBindBufferRangeNV (GLenum, GLuint, GLuint, GLintptr, GLsizeiptr); +GLAPI void APIENTRY glBindBufferOffsetNV (GLenum, GLuint, GLuint, GLintptr); +GLAPI void APIENTRY glBindBufferBaseNV (GLenum, GLuint, GLuint); +GLAPI void APIENTRY glTransformFeedbackVaryingsNV (GLuint, GLsizei, const GLchar* *, GLenum); +GLAPI void APIENTRY glActiveVaryingNV (GLuint, const GLchar *); +GLAPI GLint APIENTRY glGetVaryingLocationNV (GLuint, const GLchar *); +GLAPI void APIENTRY glGetActiveVaryingNV (GLuint, GLuint, GLsizei, GLsizei *, GLsizei *, GLenum *, GLchar *); +GLAPI void APIENTRY glGetTransformFeedbackVaryingNV (GLuint, GLuint, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKNVPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKNVPROC) (void); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKATTRIBSNVPROC) (GLuint count, const GLint *attribs, GLenum bufferMode); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGENVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETNVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +typedef void (APIENTRYP PFNGLBINDBUFFERBASENVPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSNVPROC) (GLuint program, GLsizei count, const GLchar* *varyings, GLenum bufferMode); +typedef void (APIENTRYP PFNGLACTIVEVARYINGNVPROC) (GLuint program, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETVARYINGLOCATIONNVPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVEVARYINGNVPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGNVPROC) (GLuint program, GLuint index, GLint *location); +#endif + +#ifndef GL_EXT_bindable_uniform +#define GL_EXT_bindable_uniform 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniformBufferEXT (GLuint, GLint, GLuint); +GLAPI GLint APIENTRY glGetUniformBufferSizeEXT (GLuint, GLint); +GLAPI GLintptr APIENTRY glGetUniformOffsetEXT (GLuint, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORMBUFFEREXTPROC) (GLuint program, GLint location, GLuint buffer); +typedef GLint (APIENTRYP PFNGLGETUNIFORMBUFFERSIZEEXTPROC) (GLuint program, GLint location); +typedef GLintptr (APIENTRYP PFNGLGETUNIFORMOFFSETEXTPROC) (GLuint program, GLint location); +#endif + +#ifndef GL_EXT_texture_integer +#define GL_EXT_texture_integer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexParameterIivEXT (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glTexParameterIuivEXT (GLenum, GLenum, const GLuint *); +GLAPI void APIENTRY glGetTexParameterIivEXT (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetTexParameterIuivEXT (GLenum, GLenum, GLuint *); +GLAPI void APIENTRY glClearColorIiEXT (GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glClearColorIuiEXT (GLuint, GLuint, GLuint, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLCLEARCOLORIIEXTPROC) (GLint red, GLint green, GLint blue, GLint alpha); +typedef void (APIENTRYP PFNGLCLEARCOLORIUIEXTPROC) (GLuint red, GLuint green, GLuint blue, GLuint alpha); +#endif + +#ifndef GL_GREMEDY_frame_terminator +#define GL_GREMEDY_frame_terminator 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFrameTerminatorGREMEDY (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAMETERMINATORGREMEDYPROC) (void); +#endif + +#ifndef GL_NV_conditional_render +#define GL_NV_conditional_render 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginConditionalRenderNV (GLuint, GLenum); +GLAPI void APIENTRY glEndConditionalRenderNV (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERNVPROC) (GLuint id, GLenum mode); +typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERNVPROC) (void); +#endif + +#ifndef GL_NV_present_video +#define GL_NV_present_video 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPresentFrameKeyedNV (GLuint, GLuint64EXT, GLuint, GLuint, GLenum, GLenum, GLuint, GLuint, GLenum, GLuint, GLuint); +GLAPI void APIENTRY glPresentFrameDualFillNV (GLuint, GLuint64EXT, GLuint, GLuint, GLenum, GLenum, GLuint, GLenum, GLuint, GLenum, GLuint, GLenum, GLuint); +GLAPI void APIENTRY glGetVideoivNV (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVideouivNV (GLuint, GLenum, GLuint *); +GLAPI void APIENTRY glGetVideoi64vNV (GLuint, GLenum, GLint64EXT *); +GLAPI void APIENTRY glGetVideoui64vNV (GLuint, GLenum, GLuint64EXT *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPRESENTFRAMEKEYEDNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1); +typedef void (APIENTRYP PFNGLPRESENTFRAMEDUALFILLNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum target3, GLuint fill3); +typedef void (APIENTRYP PFNGLGETVIDEOIVNVPROC) (GLuint video_slot, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVIDEOUIVNVPROC) (GLuint video_slot, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLGETVIDEOI64VNVPROC) (GLuint video_slot, GLenum pname, GLint64EXT *params); +typedef void (APIENTRYP PFNGLGETVIDEOUI64VNVPROC) (GLuint video_slot, GLenum pname, GLuint64EXT *params); +#endif + +#ifndef GL_EXT_transform_feedback +#define GL_EXT_transform_feedback 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginTransformFeedbackEXT (GLenum); +GLAPI void APIENTRY glEndTransformFeedbackEXT (void); +GLAPI void APIENTRY glBindBufferRangeEXT (GLenum, GLuint, GLuint, GLintptr, GLsizeiptr); +GLAPI void APIENTRY glBindBufferOffsetEXT (GLenum, GLuint, GLuint, GLintptr); +GLAPI void APIENTRY glBindBufferBaseEXT (GLenum, GLuint, GLuint); +GLAPI void APIENTRY glTransformFeedbackVaryingsEXT (GLuint, GLsizei, const GLchar* *, GLenum); +GLAPI void APIENTRY glGetTransformFeedbackVaryingEXT (GLuint, GLuint, GLsizei, GLsizei *, GLsizei *, GLenum *, GLchar *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKEXTPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKEXTPROC) (void); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGEEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +typedef void (APIENTRYP PFNGLBINDBUFFERBASEEXTPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSEXTPROC) (GLuint program, GLsizei count, const GLchar* *varyings, GLenum bufferMode); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGEXTPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +#endif + +#ifndef GL_EXT_direct_state_access +#define GL_EXT_direct_state_access 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClientAttribDefaultEXT (GLbitfield); +GLAPI void APIENTRY glPushClientAttribDefaultEXT (GLbitfield); +GLAPI void APIENTRY glMatrixLoadfEXT (GLenum, const GLfloat *); +GLAPI void APIENTRY glMatrixLoaddEXT (GLenum, const GLdouble *); +GLAPI void APIENTRY glMatrixMultfEXT (GLenum, const GLfloat *); +GLAPI void APIENTRY glMatrixMultdEXT (GLenum, const GLdouble *); +GLAPI void APIENTRY glMatrixLoadIdentityEXT (GLenum); +GLAPI void APIENTRY glMatrixRotatefEXT (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMatrixRotatedEXT (GLenum, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMatrixScalefEXT (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMatrixScaledEXT (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMatrixTranslatefEXT (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMatrixTranslatedEXT (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMatrixFrustumEXT (GLenum, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMatrixOrthoEXT (GLenum, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMatrixPopEXT (GLenum); +GLAPI void APIENTRY glMatrixPushEXT (GLenum); +GLAPI void APIENTRY glMatrixLoadTransposefEXT (GLenum, const GLfloat *); +GLAPI void APIENTRY glMatrixLoadTransposedEXT (GLenum, const GLdouble *); +GLAPI void APIENTRY glMatrixMultTransposefEXT (GLenum, const GLfloat *); +GLAPI void APIENTRY glMatrixMultTransposedEXT (GLenum, const GLdouble *); +GLAPI void APIENTRY glTextureParameterfEXT (GLuint, GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glTextureParameterfvEXT (GLuint, GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glTextureParameteriEXT (GLuint, GLenum, GLenum, GLint); +GLAPI void APIENTRY glTextureParameterivEXT (GLuint, GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glTextureImage1DEXT (GLuint, GLenum, GLint, GLenum, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTextureImage2DEXT (GLuint, GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTextureSubImage1DEXT (GLuint, GLenum, GLint, GLint, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTextureSubImage2DEXT (GLuint, GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glCopyTextureImage1DEXT (GLuint, GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLint); +GLAPI void APIENTRY glCopyTextureImage2DEXT (GLuint, GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint); +GLAPI void APIENTRY glCopyTextureSubImage1DEXT (GLuint, GLenum, GLint, GLint, GLint, GLint, GLsizei); +GLAPI void APIENTRY glCopyTextureSubImage2DEXT (GLuint, GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glGetTextureImageEXT (GLuint, GLenum, GLint, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetTextureParameterfvEXT (GLuint, GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetTextureParameterivEXT (GLuint, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetTextureLevelParameterfvEXT (GLuint, GLenum, GLint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetTextureLevelParameterivEXT (GLuint, GLenum, GLint, GLenum, GLint *); +GLAPI void APIENTRY glTextureImage3DEXT (GLuint, GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTextureSubImage3DEXT (GLuint, GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glCopyTextureSubImage3DEXT (GLuint, GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glMultiTexParameterfEXT (GLenum, GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glMultiTexParameterfvEXT (GLenum, GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexParameteriEXT (GLenum, GLenum, GLenum, GLint); +GLAPI void APIENTRY glMultiTexParameterivEXT (GLenum, GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexImage1DEXT (GLenum, GLenum, GLint, GLenum, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glMultiTexImage2DEXT (GLenum, GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glMultiTexSubImage1DEXT (GLenum, GLenum, GLint, GLint, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glMultiTexSubImage2DEXT (GLenum, GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glCopyMultiTexImage1DEXT (GLenum, GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLint); +GLAPI void APIENTRY glCopyMultiTexImage2DEXT (GLenum, GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint); +GLAPI void APIENTRY glCopyMultiTexSubImage1DEXT (GLenum, GLenum, GLint, GLint, GLint, GLint, GLsizei); +GLAPI void APIENTRY glCopyMultiTexSubImage2DEXT (GLenum, GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glGetMultiTexImageEXT (GLenum, GLenum, GLint, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetMultiTexParameterfvEXT (GLenum, GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetMultiTexParameterivEXT (GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetMultiTexLevelParameterfvEXT (GLenum, GLenum, GLint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetMultiTexLevelParameterivEXT (GLenum, GLenum, GLint, GLenum, GLint *); +GLAPI void APIENTRY glMultiTexImage3DEXT (GLenum, GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glMultiTexSubImage3DEXT (GLenum, GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glCopyMultiTexSubImage3DEXT (GLenum, GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glBindMultiTextureEXT (GLenum, GLenum, GLuint); +GLAPI void APIENTRY glEnableClientStateIndexedEXT (GLenum, GLuint); +GLAPI void APIENTRY glDisableClientStateIndexedEXT (GLenum, GLuint); +GLAPI void APIENTRY glMultiTexCoordPointerEXT (GLenum, GLint, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glMultiTexEnvfEXT (GLenum, GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glMultiTexEnvfvEXT (GLenum, GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexEnviEXT (GLenum, GLenum, GLenum, GLint); +GLAPI void APIENTRY glMultiTexEnvivEXT (GLenum, GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexGendEXT (GLenum, GLenum, GLenum, GLdouble); +GLAPI void APIENTRY glMultiTexGendvEXT (GLenum, GLenum, GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexGenfEXT (GLenum, GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glMultiTexGenfvEXT (GLenum, GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexGeniEXT (GLenum, GLenum, GLenum, GLint); +GLAPI void APIENTRY glMultiTexGenivEXT (GLenum, GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glGetMultiTexEnvfvEXT (GLenum, GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetMultiTexEnvivEXT (GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetMultiTexGendvEXT (GLenum, GLenum, GLenum, GLdouble *); +GLAPI void APIENTRY glGetMultiTexGenfvEXT (GLenum, GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetMultiTexGenivEXT (GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetFloatIndexedvEXT (GLenum, GLuint, GLfloat *); +GLAPI void APIENTRY glGetDoubleIndexedvEXT (GLenum, GLuint, GLdouble *); +GLAPI void APIENTRY glGetPointerIndexedvEXT (GLenum, GLuint, GLvoid* *); +GLAPI void APIENTRY glCompressedTextureImage3DEXT (GLuint, GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTextureImage2DEXT (GLuint, GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTextureImage1DEXT (GLuint, GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTextureSubImage3DEXT (GLuint, GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTextureSubImage2DEXT (GLuint, GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTextureSubImage1DEXT (GLuint, GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glGetCompressedTextureImageEXT (GLuint, GLenum, GLint, GLvoid *); +GLAPI void APIENTRY glCompressedMultiTexImage3DEXT (GLenum, GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedMultiTexImage2DEXT (GLenum, GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedMultiTexImage1DEXT (GLenum, GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedMultiTexSubImage3DEXT (GLenum, GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedMultiTexSubImage2DEXT (GLenum, GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedMultiTexSubImage1DEXT (GLenum, GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glGetCompressedMultiTexImageEXT (GLenum, GLenum, GLint, GLvoid *); +GLAPI void APIENTRY glNamedProgramStringEXT (GLuint, GLenum, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glNamedProgramLocalParameter4dEXT (GLuint, GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glNamedProgramLocalParameter4dvEXT (GLuint, GLenum, GLuint, const GLdouble *); +GLAPI void APIENTRY glNamedProgramLocalParameter4fEXT (GLuint, GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glNamedProgramLocalParameter4fvEXT (GLuint, GLenum, GLuint, const GLfloat *); +GLAPI void APIENTRY glGetNamedProgramLocalParameterdvEXT (GLuint, GLenum, GLuint, GLdouble *); +GLAPI void APIENTRY glGetNamedProgramLocalParameterfvEXT (GLuint, GLenum, GLuint, GLfloat *); +GLAPI void APIENTRY glGetNamedProgramivEXT (GLuint, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetNamedProgramStringEXT (GLuint, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glNamedProgramLocalParameters4fvEXT (GLuint, GLenum, GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glNamedProgramLocalParameterI4iEXT (GLuint, GLenum, GLuint, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glNamedProgramLocalParameterI4ivEXT (GLuint, GLenum, GLuint, const GLint *); +GLAPI void APIENTRY glNamedProgramLocalParametersI4ivEXT (GLuint, GLenum, GLuint, GLsizei, const GLint *); +GLAPI void APIENTRY glNamedProgramLocalParameterI4uiEXT (GLuint, GLenum, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glNamedProgramLocalParameterI4uivEXT (GLuint, GLenum, GLuint, const GLuint *); +GLAPI void APIENTRY glNamedProgramLocalParametersI4uivEXT (GLuint, GLenum, GLuint, GLsizei, const GLuint *); +GLAPI void APIENTRY glGetNamedProgramLocalParameterIivEXT (GLuint, GLenum, GLuint, GLint *); +GLAPI void APIENTRY glGetNamedProgramLocalParameterIuivEXT (GLuint, GLenum, GLuint, GLuint *); +GLAPI void APIENTRY glTextureParameterIivEXT (GLuint, GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glTextureParameterIuivEXT (GLuint, GLenum, GLenum, const GLuint *); +GLAPI void APIENTRY glGetTextureParameterIivEXT (GLuint, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetTextureParameterIuivEXT (GLuint, GLenum, GLenum, GLuint *); +GLAPI void APIENTRY glMultiTexParameterIivEXT (GLenum, GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexParameterIuivEXT (GLenum, GLenum, GLenum, const GLuint *); +GLAPI void APIENTRY glGetMultiTexParameterIivEXT (GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetMultiTexParameterIuivEXT (GLenum, GLenum, GLenum, GLuint *); +GLAPI void APIENTRY glProgramUniform1fEXT (GLuint, GLint, GLfloat); +GLAPI void APIENTRY glProgramUniform2fEXT (GLuint, GLint, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramUniform3fEXT (GLuint, GLint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramUniform4fEXT (GLuint, GLint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramUniform1iEXT (GLuint, GLint, GLint); +GLAPI void APIENTRY glProgramUniform2iEXT (GLuint, GLint, GLint, GLint); +GLAPI void APIENTRY glProgramUniform3iEXT (GLuint, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glProgramUniform4iEXT (GLuint, GLint, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glProgramUniform1fvEXT (GLuint, GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glProgramUniform2fvEXT (GLuint, GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glProgramUniform3fvEXT (GLuint, GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glProgramUniform4fvEXT (GLuint, GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glProgramUniform1ivEXT (GLuint, GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glProgramUniform2ivEXT (GLuint, GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glProgramUniform3ivEXT (GLuint, GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glProgramUniform4ivEXT (GLuint, GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glProgramUniformMatrix2fvEXT (GLuint, GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glProgramUniformMatrix3fvEXT (GLuint, GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glProgramUniformMatrix4fvEXT (GLuint, GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glProgramUniformMatrix2x3fvEXT (GLuint, GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glProgramUniformMatrix3x2fvEXT (GLuint, GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glProgramUniformMatrix2x4fvEXT (GLuint, GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glProgramUniformMatrix4x2fvEXT (GLuint, GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glProgramUniformMatrix3x4fvEXT (GLuint, GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glProgramUniformMatrix4x3fvEXT (GLuint, GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glProgramUniform1uiEXT (GLuint, GLint, GLuint); +GLAPI void APIENTRY glProgramUniform2uiEXT (GLuint, GLint, GLuint, GLuint); +GLAPI void APIENTRY glProgramUniform3uiEXT (GLuint, GLint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glProgramUniform4uiEXT (GLuint, GLint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glProgramUniform1uivEXT (GLuint, GLint, GLsizei, const GLuint *); +GLAPI void APIENTRY glProgramUniform2uivEXT (GLuint, GLint, GLsizei, const GLuint *); +GLAPI void APIENTRY glProgramUniform3uivEXT (GLuint, GLint, GLsizei, const GLuint *); +GLAPI void APIENTRY glProgramUniform4uivEXT (GLuint, GLint, GLsizei, const GLuint *); +GLAPI void APIENTRY glNamedBufferDataEXT (GLuint, GLsizeiptr, const GLvoid *, GLenum); +GLAPI void APIENTRY glNamedBufferSubDataEXT (GLuint, GLintptr, GLsizeiptr, const GLvoid *); +GLAPI GLvoid* APIENTRY glMapNamedBufferEXT (GLuint, GLenum); +GLAPI GLboolean APIENTRY glUnmapNamedBufferEXT (GLuint); +GLAPI void APIENTRY glGetNamedBufferParameterivEXT (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetNamedBufferPointervEXT (GLuint, GLenum, GLvoid* *); +GLAPI void APIENTRY glGetNamedBufferSubDataEXT (GLuint, GLintptr, GLsizeiptr, GLvoid *); +GLAPI void APIENTRY glTextureBufferEXT (GLuint, GLenum, GLenum, GLuint); +GLAPI void APIENTRY glMultiTexBufferEXT (GLenum, GLenum, GLenum, GLuint); +GLAPI void APIENTRY glNamedRenderbufferStorageEXT (GLuint, GLenum, GLsizei, GLsizei); +GLAPI void APIENTRY glGetNamedRenderbufferParameterivEXT (GLuint, GLenum, GLint *); +GLAPI GLenum APIENTRY glCheckNamedFramebufferStatusEXT (GLuint, GLenum); +GLAPI void APIENTRY glNamedFramebufferTexture1DEXT (GLuint, GLenum, GLenum, GLuint, GLint); +GLAPI void APIENTRY glNamedFramebufferTexture2DEXT (GLuint, GLenum, GLenum, GLuint, GLint); +GLAPI void APIENTRY glNamedFramebufferTexture3DEXT (GLuint, GLenum, GLenum, GLuint, GLint, GLint); +GLAPI void APIENTRY glNamedFramebufferRenderbufferEXT (GLuint, GLenum, GLenum, GLuint); +GLAPI void APIENTRY glGetNamedFramebufferAttachmentParameterivEXT (GLuint, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGenerateTextureMipmapEXT (GLuint, GLenum); +GLAPI void APIENTRY glGenerateMultiTexMipmapEXT (GLenum, GLenum); +GLAPI void APIENTRY glFramebufferDrawBufferEXT (GLuint, GLenum); +GLAPI void APIENTRY glFramebufferDrawBuffersEXT (GLuint, GLsizei, const GLenum *); +GLAPI void APIENTRY glFramebufferReadBufferEXT (GLuint, GLenum); +GLAPI void APIENTRY glGetFramebufferParameterivEXT (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleEXT (GLuint, GLsizei, GLenum, GLsizei, GLsizei); +GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleCoverageEXT (GLuint, GLsizei, GLsizei, GLenum, GLsizei, GLsizei); +GLAPI void APIENTRY glNamedFramebufferTextureEXT (GLuint, GLenum, GLuint, GLint); +GLAPI void APIENTRY glNamedFramebufferTextureLayerEXT (GLuint, GLenum, GLuint, GLint, GLint); +GLAPI void APIENTRY glNamedFramebufferTextureFaceEXT (GLuint, GLenum, GLuint, GLint, GLenum); +GLAPI void APIENTRY glTextureRenderbufferEXT (GLuint, GLenum, GLuint); +GLAPI void APIENTRY glMultiTexRenderbufferEXT (GLenum, GLenum, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLPUSHCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLMATRIXLOADFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXLOADDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLMATRIXMULTFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXMULTDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLMATRIXLOADIDENTITYEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLMATRIXROTATEFEXTPROC) (GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLMATRIXROTATEDEXTPROC) (GLenum mode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLMATRIXSCALEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLMATRIXSCALEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLMATRIXTRANSLATEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLMATRIXTRANSLATEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLMATRIXFRUSTUMEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +typedef void (APIENTRYP PFNGLMATRIXORTHOEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +typedef void (APIENTRYP PFNGLMATRIXPOPEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLMATRIXPUSHEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLBINDMULTITEXTUREEXTPROC) (GLenum texunit, GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLENABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index); +typedef void (APIENTRYP PFNGLDISABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index); +typedef void (APIENTRYP PFNGLMULTITEXCOORDPOINTEREXTPROC) (GLenum texunit, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLMULTITEXENVFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLMULTITEXENVIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXGENDEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble param); +typedef void (APIENTRYP PFNGLMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params); +typedef void (APIENTRYP PFNGLMULTITEXGENFEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLMULTITEXGENIEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFLOATINDEXEDVEXTPROC) (GLenum target, GLuint index, GLfloat *data); +typedef void (APIENTRYP PFNGLGETDOUBLEINDEXEDVEXTPROC) (GLenum target, GLuint index, GLdouble *data); +typedef void (APIENTRYP PFNGLGETPOINTERINDEXEDVEXTPROC) (GLenum target, GLuint index, GLvoid* *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint lod, GLvoid *img); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint lod, GLvoid *img); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum format, GLsizei len, const GLvoid *string); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERDVEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERFVEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMIVEXTPROC) (GLuint program, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum pname, GLvoid *string); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IEXTPROC) (GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLint *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLuint *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLint *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIUIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint *params); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FEXTPROC) (GLuint program, GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IEXTPROC) (GLuint program, GLint location, GLint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIEXTPROC) (GLuint program, GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLsizeiptr size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, const GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPNAMEDBUFFEREXTPROC) (GLuint buffer, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPNAMEDBUFFEREXTPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERIVEXTPROC) (GLuint buffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPOINTERVEXTPROC) (GLuint buffer, GLenum pname, GLvoid* *params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, GLvoid *data); +typedef void (APIENTRYP PFNGLTEXTUREBUFFEREXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLMULTITEXBUFFEREXTPROC) (GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEEXTPROC) (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETNAMEDRENDERBUFFERPARAMETERIVEXTPROC) (GLuint renderbuffer, GLenum pname, GLint *params); +typedef GLenum (APIENTRYP PFNGLCHECKNAMEDFRAMEBUFFERSTATUSEXTPROC) (GLuint framebuffer, GLenum target); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE1DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE2DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE3DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERRENDERBUFFEREXTPROC) (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATETEXTUREMIPMAPEXTPROC) (GLuint texture, GLenum target); +typedef void (APIENTRYP PFNGLGENERATEMULTITEXMIPMAPEXTPROC) (GLenum texunit, GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFEREXTPROC) (GLuint framebuffer, GLenum mode); +typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFERSEXTPROC) (GLuint framebuffer, GLsizei n, const GLenum *bufs); +typedef void (APIENTRYP PFNGLFRAMEBUFFERREADBUFFEREXTPROC) (GLuint framebuffer, GLenum mode); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLECOVERAGEEXTPROC) (GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURELAYEREXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREFACEEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face); +typedef void (APIENTRYP PFNGLTEXTURERENDERBUFFEREXTPROC) (GLuint texture, GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLMULTITEXRENDERBUFFEREXTPROC) (GLenum texunit, GLenum target, GLuint renderbuffer); +#endif + +#ifndef GL_EXT_vertex_array_bgra +#define GL_EXT_vertex_array_bgra 1 +#endif + +#ifndef GL_EXT_texture_swizzle +#define GL_EXT_texture_swizzle 1 +#endif + +#ifndef GL_NV_explicit_multisample +#define GL_NV_explicit_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetMultisamplefvNV (GLenum, GLuint, GLfloat *); +GLAPI void APIENTRY glSampleMaskIndexedNV (GLuint, GLbitfield); +GLAPI void APIENTRY glTexRenderbufferNV (GLenum, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVNVPROC) (GLenum pname, GLuint index, GLfloat *val); +typedef void (APIENTRYP PFNGLSAMPLEMASKINDEXEDNVPROC) (GLuint index, GLbitfield mask); +typedef void (APIENTRYP PFNGLTEXRENDERBUFFERNVPROC) (GLenum target, GLuint renderbuffer); +#endif + +#ifndef GL_NV_transform_feedback2 +#define GL_NV_transform_feedback2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindTransformFeedbackNV (GLenum, GLuint); +GLAPI void APIENTRY glDeleteTransformFeedbacksNV (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenTransformFeedbacksNV (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsTransformFeedbackNV (GLuint); +GLAPI void APIENTRY glPauseTransformFeedbackNV (void); +GLAPI void APIENTRY glResumeTransformFeedbackNV (void); +GLAPI void APIENTRY glDrawTransformFeedbackNV (GLenum, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKNVPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSNVPROC) (GLsizei n, const GLuint *ids); +typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSNVPROC) (GLsizei n, GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKNVPROC) (void); +typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKNVPROC) (void); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKNVPROC) (GLenum mode, GLuint id); +#endif + +#ifndef GL_ATI_meminfo +#define GL_ATI_meminfo 1 +#endif + +#ifndef GL_AMD_performance_monitor +#define GL_AMD_performance_monitor 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetPerfMonitorGroupsAMD (GLint *, GLsizei, GLuint *); +GLAPI void APIENTRY glGetPerfMonitorCountersAMD (GLuint, GLint *, GLint *, GLsizei, GLuint *); +GLAPI void APIENTRY glGetPerfMonitorGroupStringAMD (GLuint, GLsizei, GLsizei *, GLchar *); +GLAPI void APIENTRY glGetPerfMonitorCounterStringAMD (GLuint, GLuint, GLsizei, GLsizei *, GLchar *); +GLAPI void APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint, GLuint, GLenum, void *); +GLAPI void APIENTRY glGenPerfMonitorsAMD (GLsizei, GLuint *); +GLAPI void APIENTRY glDeletePerfMonitorsAMD (GLsizei, GLuint *); +GLAPI void APIENTRY glSelectPerfMonitorCountersAMD (GLuint, GLboolean, GLuint, GLint, GLuint *); +GLAPI void APIENTRY glBeginPerfMonitorAMD (GLuint); +GLAPI void APIENTRY glEndPerfMonitorAMD (GLuint); +GLAPI void APIENTRY glGetPerfMonitorCounterDataAMD (GLuint, GLenum, GLsizei, GLuint *, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSAMDPROC) (GLint *numGroups, GLsizei groupsSize, GLuint *groups); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSAMDPROC) (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); +typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSTRINGAMDPROC) (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERINFOAMDPROC) (GLuint group, GLuint counter, GLenum pname, void *data); +typedef void (APIENTRYP PFNGLGENPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (APIENTRYP PFNGLDELETEPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (APIENTRYP PFNGLSELECTPERFMONITORCOUNTERSAMDPROC) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList); +typedef void (APIENTRYP PFNGLBEGINPERFMONITORAMDPROC) (GLuint monitor); +typedef void (APIENTRYP PFNGLENDPERFMONITORAMDPROC) (GLuint monitor); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERDATAAMDPROC) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); +#endif + +#ifndef GL_AMD_texture_texture4 +#define GL_AMD_texture_texture4 1 +#endif + +#ifndef GL_AMD_vertex_shader_tesselator +#define GL_AMD_vertex_shader_tesselator 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTessellationFactorAMD (GLfloat); +GLAPI void APIENTRY glTessellationModeAMD (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTESSELLATIONFACTORAMDPROC) (GLfloat factor); +typedef void (APIENTRYP PFNGLTESSELLATIONMODEAMDPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_provoking_vertex +#define GL_EXT_provoking_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProvokingVertexEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROVOKINGVERTEXEXTPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_texture_snorm +#define GL_EXT_texture_snorm 1 +#endif + +#ifndef GL_AMD_draw_buffers_blend +#define GL_AMD_draw_buffers_blend 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncIndexedAMD (GLuint, GLenum, GLenum); +GLAPI void APIENTRY glBlendFuncSeparateIndexedAMD (GLuint, GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glBlendEquationIndexedAMD (GLuint, GLenum); +GLAPI void APIENTRY glBlendEquationSeparateIndexedAMD (GLuint, GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCINDEXEDAMDPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONINDEXEDAMDPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +#endif + +#ifndef GL_APPLE_texture_range +#define GL_APPLE_texture_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureRangeAPPLE (GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glGetTexParameterPointervAPPLE (GLenum, GLenum, GLvoid* *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTURERANGEAPPLEPROC) (GLenum target, GLsizei length, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERPOINTERVAPPLEPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_APPLE_float_pixels +#define GL_APPLE_float_pixels 1 +#endif + +#ifndef GL_APPLE_vertex_program_evaluators +#define GL_APPLE_vertex_program_evaluators 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glEnableVertexAttribAPPLE (GLuint, GLenum); +GLAPI void APIENTRY glDisableVertexAttribAPPLE (GLuint, GLenum); +GLAPI GLboolean APIENTRY glIsVertexAttribEnabledAPPLE (GLuint, GLenum); +GLAPI void APIENTRY glMapVertexAttrib1dAPPLE (GLuint, GLuint, GLdouble, GLdouble, GLint, GLint, const GLdouble *); +GLAPI void APIENTRY glMapVertexAttrib1fAPPLE (GLuint, GLuint, GLfloat, GLfloat, GLint, GLint, const GLfloat *); +GLAPI void APIENTRY glMapVertexAttrib2dAPPLE (GLuint, GLuint, GLdouble, GLdouble, GLint, GLint, GLdouble, GLdouble, GLint, GLint, const GLdouble *); +GLAPI void APIENTRY glMapVertexAttrib2fAPPLE (GLuint, GLuint, GLfloat, GLfloat, GLint, GLint, GLfloat, GLfloat, GLint, GLint, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname); +typedef GLboolean (APIENTRYP PFNGLISVERTEXATTRIBENABLEDAPPLEPROC) (GLuint index, GLenum pname); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); +#endif + +#ifndef GL_APPLE_aux_depth_stencil +#define GL_APPLE_aux_depth_stencil 1 +#endif + +#ifndef GL_APPLE_object_purgeable +#define GL_APPLE_object_purgeable 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLenum APIENTRY glObjectPurgeableAPPLE (GLenum, GLuint, GLenum); +GLAPI GLenum APIENTRY glObjectUnpurgeableAPPLE (GLenum, GLuint, GLenum); +GLAPI void APIENTRY glGetObjectParameterivAPPLE (GLenum, GLuint, GLenum, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLenum (APIENTRYP PFNGLOBJECTPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option); +typedef GLenum (APIENTRYP PFNGLOBJECTUNPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVAPPLEPROC) (GLenum objectType, GLuint name, GLenum pname, GLint *params); +#endif + +#ifndef GL_APPLE_row_bytes +#define GL_APPLE_row_bytes 1 +#endif + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/opencl/khronos/headers/KHR/khrplatform.h b/opencl/khronos/headers/KHR/khrplatform.h new file mode 100644 index 0000000000..c9e6f17d34 --- /dev/null +++ b/opencl/khronos/headers/KHR/khrplatform.h @@ -0,0 +1,282 @@ +#ifndef __khrplatform_h_ +#define __khrplatform_h_ + +/* +** Copyright (c) 2008-2009 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Khronos platform-specific types and definitions. + * + * $Revision: 23298 $ on $Date: 2013-09-30 17:07:13 -0700 (Mon, 30 Sep 2013) $ + * + * Adopters may modify this file to suit their platform. Adopters are + * encouraged to submit platform specific modifications to the Khronos + * group so that they can be included in future versions of this file. + * Please submit changes by sending them to the public Khronos Bugzilla + * (http://khronos.org/bugzilla) by filing a bug against product + * "Khronos (general)" component "Registry". + * + * A predefined template which fills in some of the bug fields can be + * reached using http://tinyurl.com/khrplatform-h-bugreport, but you + * must create a Bugzilla login first. + * + * + * See the Implementer's Guidelines for information about where this file + * should be located on your system and for more details of its use: + * http://www.khronos.org/registry/implementers_guide.pdf + * + * This file should be included as + * #include + * by Khronos client API header files that use its types and defines. + * + * The types in khrplatform.h should only be used to define API-specific types. + * + * Types defined in khrplatform.h: + * khronos_int8_t signed 8 bit + * khronos_uint8_t unsigned 8 bit + * khronos_int16_t signed 16 bit + * khronos_uint16_t unsigned 16 bit + * khronos_int32_t signed 32 bit + * khronos_uint32_t unsigned 32 bit + * khronos_int64_t signed 64 bit + * khronos_uint64_t unsigned 64 bit + * khronos_intptr_t signed same number of bits as a pointer + * khronos_uintptr_t unsigned same number of bits as a pointer + * khronos_ssize_t signed size + * khronos_usize_t unsigned size + * khronos_float_t signed 32 bit floating point + * khronos_time_ns_t unsigned 64 bit time in nanoseconds + * khronos_utime_nanoseconds_t unsigned time interval or absolute time in + * nanoseconds + * khronos_stime_nanoseconds_t signed time interval in nanoseconds + * khronos_boolean_enum_t enumerated boolean type. This should + * only be used as a base type when a client API's boolean type is + * an enum. Client APIs which use an integer or other type for + * booleans cannot use this as the base type for their boolean. + * + * Tokens defined in khrplatform.h: + * + * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. + * + * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. + * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. + * + * Calling convention macros defined in this file: + * KHRONOS_APICALL + * KHRONOS_APIENTRY + * KHRONOS_APIATTRIBUTES + * + * These may be used in function prototypes as: + * + * KHRONOS_APICALL void KHRONOS_APIENTRY funcname( + * int arg1, + * int arg2) KHRONOS_APIATTRIBUTES; + */ + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APICALL + *------------------------------------------------------------------------- + * This precedes the return type of the function in the function prototype. + */ +#if defined(_WIN32) && !defined(__SCITECH_SNAP__) +# define KHRONOS_APICALL __declspec(dllimport) +#elif defined (__SYMBIAN32__) +# define KHRONOS_APICALL IMPORT_C +#else +# define KHRONOS_APICALL +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APIENTRY + *------------------------------------------------------------------------- + * This follows the return type of the function and precedes the function + * name in the function prototype. + */ +#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) + /* Win32 but not WinCE */ +# define KHRONOS_APIENTRY __stdcall +#else +# define KHRONOS_APIENTRY +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APIATTRIBUTES + *------------------------------------------------------------------------- + * This follows the closing parenthesis of the function prototype arguments. + */ +#if defined (__ARMCC_2__) +#define KHRONOS_APIATTRIBUTES __softfp +#else +#define KHRONOS_APIATTRIBUTES +#endif + +/*------------------------------------------------------------------------- + * basic type definitions + *-----------------------------------------------------------------------*/ +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__) + + +/* + * Using + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(__VMS ) || defined(__sgi) + +/* + * Using + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(_WIN32) && !defined(__SCITECH_SNAP__) + +/* + * Win32 + */ +typedef __int32 khronos_int32_t; +typedef unsigned __int32 khronos_uint32_t; +typedef __int64 khronos_int64_t; +typedef unsigned __int64 khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(__sun__) || defined(__digital__) + +/* + * Sun or Digital + */ +typedef int khronos_int32_t; +typedef unsigned int khronos_uint32_t; +#if defined(__arch64__) || defined(_LP64) +typedef long int khronos_int64_t; +typedef unsigned long int khronos_uint64_t; +#else +typedef long long int khronos_int64_t; +typedef unsigned long long int khronos_uint64_t; +#endif /* __arch64__ */ +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif 0 + +/* + * Hypothetical platform with no float or int64 support + */ +typedef int khronos_int32_t; +typedef unsigned int khronos_uint32_t; +#define KHRONOS_SUPPORT_INT64 0 +#define KHRONOS_SUPPORT_FLOAT 0 + +#else + +/* + * Generic fallback + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#endif + + +/* + * Types that are (so far) the same on all platforms + */ +typedef signed char khronos_int8_t; +typedef unsigned char khronos_uint8_t; +typedef signed short int khronos_int16_t; +typedef unsigned short int khronos_uint16_t; + +/* + * Types that differ between LLP64 and LP64 architectures - in LLP64, + * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears + * to be the only LLP64 architecture in current use. + */ +#ifdef _WIN64 +typedef signed long long int khronos_intptr_t; +typedef unsigned long long int khronos_uintptr_t; +typedef signed long long int khronos_ssize_t; +typedef unsigned long long int khronos_usize_t; +#else +typedef signed long int khronos_intptr_t; +typedef unsigned long int khronos_uintptr_t; +typedef signed long int khronos_ssize_t; +typedef unsigned long int khronos_usize_t; +#endif + +#if KHRONOS_SUPPORT_FLOAT +/* + * Float type + */ +typedef float khronos_float_t; +#endif + +#if KHRONOS_SUPPORT_INT64 +/* Time types + * + * These types can be used to represent a time interval in nanoseconds or + * an absolute Unadjusted System Time. Unadjusted System Time is the number + * of nanoseconds since some arbitrary system event (e.g. since the last + * time the system booted). The Unadjusted System Time is an unsigned + * 64 bit value that wraps back to 0 every 584 years. Time intervals + * may be either signed or unsigned. + */ +typedef khronos_uint64_t khronos_utime_nanoseconds_t; +typedef khronos_int64_t khronos_stime_nanoseconds_t; +#endif + +/* + * Dummy value used to pad enum types to 32 bits. + */ +#ifndef KHRONOS_MAX_ENUM +#define KHRONOS_MAX_ENUM 0x7FFFFFFF +#endif + +/* + * Enumerated boolean type + * + * Values other than zero should be considered to be true. Therefore + * comparisons should not be made against KHRONOS_TRUE. + */ +typedef enum { + KHRONOS_FALSE = 0, + KHRONOS_TRUE = 1, + KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM +} khronos_boolean_enum_t; + +#endif /* __khrplatform_h_ */ diff --git a/opencl/khronos/headers/opencl1.2/CL/cl.h b/opencl/khronos/headers/opencl1.2/CL/cl.h new file mode 100644 index 0000000000..9b082480ac --- /dev/null +++ b/opencl/khronos/headers/opencl1.2/CL/cl.h @@ -0,0 +1,1219 @@ +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +#ifndef __OPENCL_CL_H +#define __OPENCL_CL_H + +#ifdef __APPLE__ +#include +#else +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/******************************************************************************/ + +typedef struct _cl_platform_id * cl_platform_id; +typedef struct _cl_device_id * cl_device_id; +typedef struct _cl_context * cl_context; +typedef struct _cl_command_queue * cl_command_queue; +typedef struct _cl_mem * cl_mem; +typedef struct _cl_program * cl_program; +typedef struct _cl_kernel * cl_kernel; +typedef struct _cl_event * cl_event; +typedef struct _cl_sampler * cl_sampler; + +typedef cl_uint cl_bool; /* WARNING! Unlike cl_ types in cl_platform.h, cl_bool is not guaranteed to be the same size as the bool in kernels. */ +typedef cl_ulong cl_bitfield; +typedef cl_bitfield cl_device_type; +typedef cl_uint cl_platform_info; +typedef cl_uint cl_device_info; +typedef cl_bitfield cl_device_fp_config; +typedef cl_uint cl_device_mem_cache_type; +typedef cl_uint cl_device_local_mem_type; +typedef cl_bitfield cl_device_exec_capabilities; +typedef cl_bitfield cl_command_queue_properties; +typedef intptr_t cl_device_partition_property; +typedef cl_bitfield cl_device_affinity_domain; + +typedef intptr_t cl_context_properties; +typedef cl_uint cl_context_info; +typedef cl_uint cl_command_queue_info; +typedef cl_uint cl_channel_order; +typedef cl_uint cl_channel_type; +typedef cl_bitfield cl_mem_flags; +typedef cl_uint cl_mem_object_type; +typedef cl_uint cl_mem_info; +typedef cl_bitfield cl_mem_migration_flags; +typedef cl_uint cl_image_info; +typedef cl_uint cl_buffer_create_type; +typedef cl_uint cl_addressing_mode; +typedef cl_uint cl_filter_mode; +typedef cl_uint cl_sampler_info; +typedef cl_bitfield cl_map_flags; +typedef cl_uint cl_program_info; +typedef cl_uint cl_program_build_info; +typedef cl_uint cl_program_binary_type; +typedef cl_int cl_build_status; +typedef cl_uint cl_kernel_info; +typedef cl_uint cl_kernel_arg_info; +typedef cl_uint cl_kernel_arg_address_qualifier; +typedef cl_uint cl_kernel_arg_access_qualifier; +typedef cl_bitfield cl_kernel_arg_type_qualifier; +typedef cl_uint cl_kernel_work_group_info; +typedef cl_uint cl_event_info; +typedef cl_uint cl_command_type; +typedef cl_uint cl_profiling_info; + + +typedef struct _cl_image_format { + cl_channel_order image_channel_order; + cl_channel_type image_channel_data_type; +} cl_image_format; + +typedef struct _cl_image_desc { + cl_mem_object_type image_type; + size_t image_width; + size_t image_height; + size_t image_depth; + size_t image_array_size; + size_t image_row_pitch; + size_t image_slice_pitch; + cl_uint num_mip_levels; + cl_uint num_samples; + cl_mem buffer; +} cl_image_desc; + +typedef struct _cl_buffer_region { + size_t origin; + size_t size; +} cl_buffer_region; + + +/******************************************************************************/ + +/* Error Codes */ +#define CL_SUCCESS 0 +#define CL_DEVICE_NOT_FOUND -1 +#define CL_DEVICE_NOT_AVAILABLE -2 +#define CL_COMPILER_NOT_AVAILABLE -3 +#define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 +#define CL_OUT_OF_RESOURCES -5 +#define CL_OUT_OF_HOST_MEMORY -6 +#define CL_PROFILING_INFO_NOT_AVAILABLE -7 +#define CL_MEM_COPY_OVERLAP -8 +#define CL_IMAGE_FORMAT_MISMATCH -9 +#define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 +#define CL_BUILD_PROGRAM_FAILURE -11 +#define CL_MAP_FAILURE -12 +#define CL_MISALIGNED_SUB_BUFFER_OFFSET -13 +#define CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST -14 +#define CL_COMPILE_PROGRAM_FAILURE -15 +#define CL_LINKER_NOT_AVAILABLE -16 +#define CL_LINK_PROGRAM_FAILURE -17 +#define CL_DEVICE_PARTITION_FAILED -18 +#define CL_KERNEL_ARG_INFO_NOT_AVAILABLE -19 + +#define CL_INVALID_VALUE -30 +#define CL_INVALID_DEVICE_TYPE -31 +#define CL_INVALID_PLATFORM -32 +#define CL_INVALID_DEVICE -33 +#define CL_INVALID_CONTEXT -34 +#define CL_INVALID_QUEUE_PROPERTIES -35 +#define CL_INVALID_COMMAND_QUEUE -36 +#define CL_INVALID_HOST_PTR -37 +#define CL_INVALID_MEM_OBJECT -38 +#define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 +#define CL_INVALID_IMAGE_SIZE -40 +#define CL_INVALID_SAMPLER -41 +#define CL_INVALID_BINARY -42 +#define CL_INVALID_BUILD_OPTIONS -43 +#define CL_INVALID_PROGRAM -44 +#define CL_INVALID_PROGRAM_EXECUTABLE -45 +#define CL_INVALID_KERNEL_NAME -46 +#define CL_INVALID_KERNEL_DEFINITION -47 +#define CL_INVALID_KERNEL -48 +#define CL_INVALID_ARG_INDEX -49 +#define CL_INVALID_ARG_VALUE -50 +#define CL_INVALID_ARG_SIZE -51 +#define CL_INVALID_KERNEL_ARGS -52 +#define CL_INVALID_WORK_DIMENSION -53 +#define CL_INVALID_WORK_GROUP_SIZE -54 +#define CL_INVALID_WORK_ITEM_SIZE -55 +#define CL_INVALID_GLOBAL_OFFSET -56 +#define CL_INVALID_EVENT_WAIT_LIST -57 +#define CL_INVALID_EVENT -58 +#define CL_INVALID_OPERATION -59 +#define CL_INVALID_GL_OBJECT -60 +#define CL_INVALID_BUFFER_SIZE -61 +#define CL_INVALID_MIP_LEVEL -62 +#define CL_INVALID_GLOBAL_WORK_SIZE -63 +#define CL_INVALID_PROPERTY -64 +#define CL_INVALID_IMAGE_DESCRIPTOR -65 +#define CL_INVALID_COMPILER_OPTIONS -66 +#define CL_INVALID_LINKER_OPTIONS -67 +#define CL_INVALID_DEVICE_PARTITION_COUNT -68 + +/* OpenCL Version */ +#define CL_VERSION_1_0 1 +#define CL_VERSION_1_1 1 +#define CL_VERSION_1_2 1 + +/* cl_bool */ +#define CL_FALSE 0 +#define CL_TRUE 1 +#define CL_BLOCKING CL_TRUE +#define CL_NON_BLOCKING CL_FALSE + +/* cl_platform_info */ +#define CL_PLATFORM_PROFILE 0x0900 +#define CL_PLATFORM_VERSION 0x0901 +#define CL_PLATFORM_NAME 0x0902 +#define CL_PLATFORM_VENDOR 0x0903 +#define CL_PLATFORM_EXTENSIONS 0x0904 + +/* cl_device_type - bitfield */ +#define CL_DEVICE_TYPE_DEFAULT (1 << 0) +#define CL_DEVICE_TYPE_CPU (1 << 1) +#define CL_DEVICE_TYPE_GPU (1 << 2) +#define CL_DEVICE_TYPE_ACCELERATOR (1 << 3) +#define CL_DEVICE_TYPE_CUSTOM (1 << 4) +#define CL_DEVICE_TYPE_ALL 0xFFFFFFFF + +/* cl_device_info */ +#define CL_DEVICE_TYPE 0x1000 +#define CL_DEVICE_VENDOR_ID 0x1001 +#define CL_DEVICE_MAX_COMPUTE_UNITS 0x1002 +#define CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS 0x1003 +#define CL_DEVICE_MAX_WORK_GROUP_SIZE 0x1004 +#define CL_DEVICE_MAX_WORK_ITEM_SIZES 0x1005 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR 0x1006 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT 0x1007 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT 0x1008 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG 0x1009 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT 0x100A +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE 0x100B +#define CL_DEVICE_MAX_CLOCK_FREQUENCY 0x100C +#define CL_DEVICE_ADDRESS_BITS 0x100D +#define CL_DEVICE_MAX_READ_IMAGE_ARGS 0x100E +#define CL_DEVICE_MAX_WRITE_IMAGE_ARGS 0x100F +#define CL_DEVICE_MAX_MEM_ALLOC_SIZE 0x1010 +#define CL_DEVICE_IMAGE2D_MAX_WIDTH 0x1011 +#define CL_DEVICE_IMAGE2D_MAX_HEIGHT 0x1012 +#define CL_DEVICE_IMAGE3D_MAX_WIDTH 0x1013 +#define CL_DEVICE_IMAGE3D_MAX_HEIGHT 0x1014 +#define CL_DEVICE_IMAGE3D_MAX_DEPTH 0x1015 +#define CL_DEVICE_IMAGE_SUPPORT 0x1016 +#define CL_DEVICE_MAX_PARAMETER_SIZE 0x1017 +#define CL_DEVICE_MAX_SAMPLERS 0x1018 +#define CL_DEVICE_MEM_BASE_ADDR_ALIGN 0x1019 +#define CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE 0x101A +#define CL_DEVICE_SINGLE_FP_CONFIG 0x101B +#define CL_DEVICE_GLOBAL_MEM_CACHE_TYPE 0x101C +#define CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE 0x101D +#define CL_DEVICE_GLOBAL_MEM_CACHE_SIZE 0x101E +#define CL_DEVICE_GLOBAL_MEM_SIZE 0x101F +#define CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE 0x1020 +#define CL_DEVICE_MAX_CONSTANT_ARGS 0x1021 +#define CL_DEVICE_LOCAL_MEM_TYPE 0x1022 +#define CL_DEVICE_LOCAL_MEM_SIZE 0x1023 +#define CL_DEVICE_ERROR_CORRECTION_SUPPORT 0x1024 +#define CL_DEVICE_PROFILING_TIMER_RESOLUTION 0x1025 +#define CL_DEVICE_ENDIAN_LITTLE 0x1026 +#define CL_DEVICE_AVAILABLE 0x1027 +#define CL_DEVICE_COMPILER_AVAILABLE 0x1028 +#define CL_DEVICE_EXECUTION_CAPABILITIES 0x1029 +#define CL_DEVICE_QUEUE_PROPERTIES 0x102A +#define CL_DEVICE_NAME 0x102B +#define CL_DEVICE_VENDOR 0x102C +#define CL_DRIVER_VERSION 0x102D +#define CL_DEVICE_PROFILE 0x102E +#define CL_DEVICE_VERSION 0x102F +#define CL_DEVICE_EXTENSIONS 0x1030 +#define CL_DEVICE_PLATFORM 0x1031 +#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 +#define CL_DEVICE_HALF_FP_CONFIG 0x1033 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF 0x1034 +#define CL_DEVICE_HOST_UNIFIED_MEMORY 0x1035 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR 0x1036 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT 0x1037 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 0x1038 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 0x1039 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 0x103A +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 0x103B +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 0x103C +#define CL_DEVICE_OPENCL_C_VERSION 0x103D +#define CL_DEVICE_LINKER_AVAILABLE 0x103E +#define CL_DEVICE_BUILT_IN_KERNELS 0x103F +#define CL_DEVICE_IMAGE_MAX_BUFFER_SIZE 0x1040 +#define CL_DEVICE_IMAGE_MAX_ARRAY_SIZE 0x1041 +#define CL_DEVICE_PARENT_DEVICE 0x1042 +#define CL_DEVICE_PARTITION_MAX_SUB_DEVICES 0x1043 +#define CL_DEVICE_PARTITION_PROPERTIES 0x1044 +#define CL_DEVICE_PARTITION_AFFINITY_DOMAIN 0x1045 +#define CL_DEVICE_PARTITION_TYPE 0x1046 +#define CL_DEVICE_REFERENCE_COUNT 0x1047 +#define CL_DEVICE_PREFERRED_INTEROP_USER_SYNC 0x1048 +#define CL_DEVICE_PRINTF_BUFFER_SIZE 0x1049 +#define CL_DEVICE_IMAGE_PITCH_ALIGNMENT 0x104A +#define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT 0x104B + +/* cl_device_fp_config - bitfield */ +#define CL_FP_DENORM (1 << 0) +#define CL_FP_INF_NAN (1 << 1) +#define CL_FP_ROUND_TO_NEAREST (1 << 2) +#define CL_FP_ROUND_TO_ZERO (1 << 3) +#define CL_FP_ROUND_TO_INF (1 << 4) +#define CL_FP_FMA (1 << 5) +#define CL_FP_SOFT_FLOAT (1 << 6) +#define CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT (1 << 7) + +/* cl_device_mem_cache_type */ +#define CL_NONE 0x0 +#define CL_READ_ONLY_CACHE 0x1 +#define CL_READ_WRITE_CACHE 0x2 + +/* cl_device_local_mem_type */ +#define CL_LOCAL 0x1 +#define CL_GLOBAL 0x2 + +/* cl_device_exec_capabilities - bitfield */ +#define CL_EXEC_KERNEL (1 << 0) +#define CL_EXEC_NATIVE_KERNEL (1 << 1) + +/* cl_command_queue_properties - bitfield */ +#define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE (1 << 0) +#define CL_QUEUE_PROFILING_ENABLE (1 << 1) + +/* cl_context_info */ +#define CL_CONTEXT_REFERENCE_COUNT 0x1080 +#define CL_CONTEXT_DEVICES 0x1081 +#define CL_CONTEXT_PROPERTIES 0x1082 +#define CL_CONTEXT_NUM_DEVICES 0x1083 + +/* cl_context_properties */ +#define CL_CONTEXT_PLATFORM 0x1084 +#define CL_CONTEXT_INTEROP_USER_SYNC 0x1085 + +/* cl_device_partition_property */ +#define CL_DEVICE_PARTITION_EQUALLY 0x1086 +#define CL_DEVICE_PARTITION_BY_COUNTS 0x1087 +#define CL_DEVICE_PARTITION_BY_COUNTS_LIST_END 0x0 +#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN 0x1088 + +/* cl_device_affinity_domain */ +#define CL_DEVICE_AFFINITY_DOMAIN_NUMA (1 << 0) +#define CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE (1 << 1) +#define CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE (1 << 2) +#define CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE (1 << 3) +#define CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE (1 << 4) +#define CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE (1 << 5) + +/* cl_command_queue_info */ +#define CL_QUEUE_CONTEXT 0x1090 +#define CL_QUEUE_DEVICE 0x1091 +#define CL_QUEUE_REFERENCE_COUNT 0x1092 +#define CL_QUEUE_PROPERTIES 0x1093 + +/* cl_mem_flags - bitfield */ +#define CL_MEM_READ_WRITE (1 << 0) +#define CL_MEM_WRITE_ONLY (1 << 1) +#define CL_MEM_READ_ONLY (1 << 2) +#define CL_MEM_USE_HOST_PTR (1 << 3) +#define CL_MEM_ALLOC_HOST_PTR (1 << 4) +#define CL_MEM_COPY_HOST_PTR (1 << 5) +/* reserved (1 << 6) */ +#define CL_MEM_HOST_WRITE_ONLY (1 << 7) +#define CL_MEM_HOST_READ_ONLY (1 << 8) +#define CL_MEM_HOST_NO_ACCESS (1 << 9) + +/* cl_mem_migration_flags - bitfield */ +#define CL_MIGRATE_MEM_OBJECT_HOST (1 << 0) +#define CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED (1 << 1) + +/* cl_channel_order */ +#define CL_R 0x10B0 +#define CL_A 0x10B1 +#define CL_RG 0x10B2 +#define CL_RA 0x10B3 +#define CL_RGB 0x10B4 +#define CL_RGBA 0x10B5 +#define CL_BGRA 0x10B6 +#define CL_ARGB 0x10B7 +#define CL_INTENSITY 0x10B8 +#define CL_LUMINANCE 0x10B9 +#define CL_Rx 0x10BA +#define CL_RGx 0x10BB +#define CL_RGBx 0x10BC +#define CL_DEPTH 0x10BD +#define CL_DEPTH_STENCIL 0x10BE + +/* cl_channel_type */ +#define CL_SNORM_INT8 0x10D0 +#define CL_SNORM_INT16 0x10D1 +#define CL_UNORM_INT8 0x10D2 +#define CL_UNORM_INT16 0x10D3 +#define CL_UNORM_SHORT_565 0x10D4 +#define CL_UNORM_SHORT_555 0x10D5 +#define CL_UNORM_INT_101010 0x10D6 +#define CL_SIGNED_INT8 0x10D7 +#define CL_SIGNED_INT16 0x10D8 +#define CL_SIGNED_INT32 0x10D9 +#define CL_UNSIGNED_INT8 0x10DA +#define CL_UNSIGNED_INT16 0x10DB +#define CL_UNSIGNED_INT32 0x10DC +#define CL_HALF_FLOAT 0x10DD +#define CL_FLOAT 0x10DE +#define CL_UNORM_INT24 0x10DF + +/* cl_mem_object_type */ +#define CL_MEM_OBJECT_BUFFER 0x10F0 +#define CL_MEM_OBJECT_IMAGE2D 0x10F1 +#define CL_MEM_OBJECT_IMAGE3D 0x10F2 +#define CL_MEM_OBJECT_IMAGE2D_ARRAY 0x10F3 +#define CL_MEM_OBJECT_IMAGE1D 0x10F4 +#define CL_MEM_OBJECT_IMAGE1D_ARRAY 0x10F5 +#define CL_MEM_OBJECT_IMAGE1D_BUFFER 0x10F6 + +/* cl_mem_info */ +#define CL_MEM_TYPE 0x1100 +#define CL_MEM_FLAGS 0x1101 +#define CL_MEM_SIZE 0x1102 +#define CL_MEM_HOST_PTR 0x1103 +#define CL_MEM_MAP_COUNT 0x1104 +#define CL_MEM_REFERENCE_COUNT 0x1105 +#define CL_MEM_CONTEXT 0x1106 +#define CL_MEM_ASSOCIATED_MEMOBJECT 0x1107 +#define CL_MEM_OFFSET 0x1108 + +/* cl_image_info */ +#define CL_IMAGE_FORMAT 0x1110 +#define CL_IMAGE_ELEMENT_SIZE 0x1111 +#define CL_IMAGE_ROW_PITCH 0x1112 +#define CL_IMAGE_SLICE_PITCH 0x1113 +#define CL_IMAGE_WIDTH 0x1114 +#define CL_IMAGE_HEIGHT 0x1115 +#define CL_IMAGE_DEPTH 0x1116 +#define CL_IMAGE_ARRAY_SIZE 0x1117 +#define CL_IMAGE_BUFFER 0x1118 +#define CL_IMAGE_NUM_MIP_LEVELS 0x1119 +#define CL_IMAGE_NUM_SAMPLES 0x111A + +/* cl_addressing_mode */ +#define CL_ADDRESS_NONE 0x1130 +#define CL_ADDRESS_CLAMP_TO_EDGE 0x1131 +#define CL_ADDRESS_CLAMP 0x1132 +#define CL_ADDRESS_REPEAT 0x1133 +#define CL_ADDRESS_MIRRORED_REPEAT 0x1134 + +/* cl_filter_mode */ +#define CL_FILTER_NEAREST 0x1140 +#define CL_FILTER_LINEAR 0x1141 + +/* cl_sampler_info */ +#define CL_SAMPLER_REFERENCE_COUNT 0x1150 +#define CL_SAMPLER_CONTEXT 0x1151 +#define CL_SAMPLER_NORMALIZED_COORDS 0x1152 +#define CL_SAMPLER_ADDRESSING_MODE 0x1153 +#define CL_SAMPLER_FILTER_MODE 0x1154 + +/* cl_map_flags - bitfield */ +#define CL_MAP_READ (1 << 0) +#define CL_MAP_WRITE (1 << 1) +#define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2) + +/* cl_program_info */ +#define CL_PROGRAM_REFERENCE_COUNT 0x1160 +#define CL_PROGRAM_CONTEXT 0x1161 +#define CL_PROGRAM_NUM_DEVICES 0x1162 +#define CL_PROGRAM_DEVICES 0x1163 +#define CL_PROGRAM_SOURCE 0x1164 +#define CL_PROGRAM_BINARY_SIZES 0x1165 +#define CL_PROGRAM_BINARIES 0x1166 +#define CL_PROGRAM_NUM_KERNELS 0x1167 +#define CL_PROGRAM_KERNEL_NAMES 0x1168 + +/* cl_program_build_info */ +#define CL_PROGRAM_BUILD_STATUS 0x1181 +#define CL_PROGRAM_BUILD_OPTIONS 0x1182 +#define CL_PROGRAM_BUILD_LOG 0x1183 +#define CL_PROGRAM_BINARY_TYPE 0x1184 + +/* cl_program_binary_type */ +#define CL_PROGRAM_BINARY_TYPE_NONE 0x0 +#define CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT 0x1 +#define CL_PROGRAM_BINARY_TYPE_LIBRARY 0x2 +#define CL_PROGRAM_BINARY_TYPE_EXECUTABLE 0x4 + +/* cl_build_status */ +#define CL_BUILD_SUCCESS 0 +#define CL_BUILD_NONE -1 +#define CL_BUILD_ERROR -2 +#define CL_BUILD_IN_PROGRESS -3 + +/* cl_kernel_info */ +#define CL_KERNEL_FUNCTION_NAME 0x1190 +#define CL_KERNEL_NUM_ARGS 0x1191 +#define CL_KERNEL_REFERENCE_COUNT 0x1192 +#define CL_KERNEL_CONTEXT 0x1193 +#define CL_KERNEL_PROGRAM 0x1194 +#define CL_KERNEL_ATTRIBUTES 0x1195 + +/* cl_kernel_arg_info */ +#define CL_KERNEL_ARG_ADDRESS_QUALIFIER 0x1196 +#define CL_KERNEL_ARG_ACCESS_QUALIFIER 0x1197 +#define CL_KERNEL_ARG_TYPE_NAME 0x1198 +#define CL_KERNEL_ARG_TYPE_QUALIFIER 0x1199 +#define CL_KERNEL_ARG_NAME 0x119A + +/* cl_kernel_arg_address_qualifier */ +#define CL_KERNEL_ARG_ADDRESS_GLOBAL 0x119B +#define CL_KERNEL_ARG_ADDRESS_LOCAL 0x119C +#define CL_KERNEL_ARG_ADDRESS_CONSTANT 0x119D +#define CL_KERNEL_ARG_ADDRESS_PRIVATE 0x119E + +/* cl_kernel_arg_access_qualifier */ +#define CL_KERNEL_ARG_ACCESS_READ_ONLY 0x11A0 +#define CL_KERNEL_ARG_ACCESS_WRITE_ONLY 0x11A1 +#define CL_KERNEL_ARG_ACCESS_READ_WRITE 0x11A2 +#define CL_KERNEL_ARG_ACCESS_NONE 0x11A3 + +/* cl_kernel_arg_type_qualifier */ +#define CL_KERNEL_ARG_TYPE_NONE 0 +#define CL_KERNEL_ARG_TYPE_CONST (1 << 0) +#define CL_KERNEL_ARG_TYPE_RESTRICT (1 << 1) +#define CL_KERNEL_ARG_TYPE_VOLATILE (1 << 2) + +/* cl_kernel_work_group_info */ +#define CL_KERNEL_WORK_GROUP_SIZE 0x11B0 +#define CL_KERNEL_COMPILE_WORK_GROUP_SIZE 0x11B1 +#define CL_KERNEL_LOCAL_MEM_SIZE 0x11B2 +#define CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE 0x11B3 +#define CL_KERNEL_PRIVATE_MEM_SIZE 0x11B4 +#define CL_KERNEL_GLOBAL_WORK_SIZE 0x11B5 + +/* cl_event_info */ +#define CL_EVENT_COMMAND_QUEUE 0x11D0 +#define CL_EVENT_COMMAND_TYPE 0x11D1 +#define CL_EVENT_REFERENCE_COUNT 0x11D2 +#define CL_EVENT_COMMAND_EXECUTION_STATUS 0x11D3 +#define CL_EVENT_CONTEXT 0x11D4 + +/* cl_command_type */ +#define CL_COMMAND_NDRANGE_KERNEL 0x11F0 +#define CL_COMMAND_TASK 0x11F1 +#define CL_COMMAND_NATIVE_KERNEL 0x11F2 +#define CL_COMMAND_READ_BUFFER 0x11F3 +#define CL_COMMAND_WRITE_BUFFER 0x11F4 +#define CL_COMMAND_COPY_BUFFER 0x11F5 +#define CL_COMMAND_READ_IMAGE 0x11F6 +#define CL_COMMAND_WRITE_IMAGE 0x11F7 +#define CL_COMMAND_COPY_IMAGE 0x11F8 +#define CL_COMMAND_COPY_IMAGE_TO_BUFFER 0x11F9 +#define CL_COMMAND_COPY_BUFFER_TO_IMAGE 0x11FA +#define CL_COMMAND_MAP_BUFFER 0x11FB +#define CL_COMMAND_MAP_IMAGE 0x11FC +#define CL_COMMAND_UNMAP_MEM_OBJECT 0x11FD +#define CL_COMMAND_MARKER 0x11FE +#define CL_COMMAND_ACQUIRE_GL_OBJECTS 0x11FF +#define CL_COMMAND_RELEASE_GL_OBJECTS 0x1200 +#define CL_COMMAND_READ_BUFFER_RECT 0x1201 +#define CL_COMMAND_WRITE_BUFFER_RECT 0x1202 +#define CL_COMMAND_COPY_BUFFER_RECT 0x1203 +#define CL_COMMAND_USER 0x1204 +#define CL_COMMAND_BARRIER 0x1205 +#define CL_COMMAND_MIGRATE_MEM_OBJECTS 0x1206 +#define CL_COMMAND_FILL_BUFFER 0x1207 +#define CL_COMMAND_FILL_IMAGE 0x1208 + +/* command execution status */ +#define CL_COMPLETE 0x0 +#define CL_RUNNING 0x1 +#define CL_SUBMITTED 0x2 +#define CL_QUEUED 0x3 + +/* cl_buffer_create_type */ +#define CL_BUFFER_CREATE_TYPE_REGION 0x1220 + +/* cl_profiling_info */ +#define CL_PROFILING_COMMAND_QUEUED 0x1280 +#define CL_PROFILING_COMMAND_SUBMIT 0x1281 +#define CL_PROFILING_COMMAND_START 0x1282 +#define CL_PROFILING_COMMAND_END 0x1283 + +/********************************************************************************************************/ + +/* Platform API */ +extern CL_API_ENTRY cl_int CL_API_CALL +clGetPlatformIDs(cl_uint /* num_entries */, + cl_platform_id * /* platforms */, + cl_uint * /* num_platforms */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetPlatformInfo(cl_platform_id /* platform */, + cl_platform_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Device APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceIDs(cl_platform_id /* platform */, + cl_device_type /* device_type */, + cl_uint /* num_entries */, + cl_device_id * /* devices */, + cl_uint * /* num_devices */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceInfo(cl_device_id /* device */, + cl_device_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clCreateSubDevices(cl_device_id /* in_device */, + const cl_device_partition_property * /* properties */, + cl_uint /* num_devices */, + cl_device_id * /* out_devices */, + cl_uint * /* num_devices_ret */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; + +/* Context APIs */ +extern CL_API_ENTRY cl_context CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_context CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetContextInfo(cl_context /* context */, + cl_context_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Command Queue APIs */ +extern CL_API_ENTRY cl_command_queue CL_API_CALL +clCreateCommandQueue(cl_context /* context */, + cl_device_id /* device */, + cl_command_queue_properties /* properties */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetCommandQueueInfo(cl_command_queue /* command_queue */, + cl_command_queue_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Memory Object APIs */ +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateBuffer(cl_context /* context */, + cl_mem_flags /* flags */, + size_t /* size */, + void * /* host_ptr */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateSubBuffer(cl_mem /* buffer */, + cl_mem_flags /* flags */, + cl_buffer_create_type /* buffer_create_type */, + const void * /* buffer_create_info */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_mem CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetMemObjectInfo(cl_mem /* memobj */, + cl_mem_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetImageInfo(cl_mem /* image */, + cl_image_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetMemObjectDestructorCallback( cl_mem /* memobj */, + void (CL_CALLBACK * /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), + void * /*user_data */ ) CL_API_SUFFIX__VERSION_1_1; + +/* Sampler APIs */ +extern CL_API_ENTRY cl_sampler CL_API_CALL +clCreateSampler(cl_context /* context */, + cl_bool /* normalized_coords */, + cl_addressing_mode /* addressing_mode */, + cl_filter_mode /* filter_mode */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetSamplerInfo(cl_sampler /* sampler */, + cl_sampler_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Program Object APIs */ +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithSource(cl_context /* context */, + cl_uint /* count */, + const char ** /* strings */, + const size_t * /* lengths */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_program CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithBuiltInKernels(cl_context /* context */, + cl_uint /* num_devices */, + const cl_device_id * /* device_list */, + const char * /* kernel_names */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clCompileProgram(cl_program /* program */, + cl_uint /* num_devices */, + const cl_device_id * /* device_list */, + const char * /* options */, + cl_uint /* num_input_headers */, + const cl_program * /* input_headers */, + const char ** /* header_include_names */, + void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), + void * /* user_data */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_program CL_API_CALL +clLinkProgram(cl_context /* context */, + cl_uint /* num_devices */, + const cl_device_id * /* device_list */, + const char * /* options */, + cl_uint /* num_input_programs */, + const cl_program * /* input_programs */, + void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), + void * /* user_data */, + cl_int * /* errcode_ret */ ) CL_API_SUFFIX__VERSION_1_2; + + +extern CL_API_ENTRY cl_int CL_API_CALL +clUnloadPlatformCompiler(cl_platform_id /* platform */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetProgramInfo(cl_program /* program */, + cl_program_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +/* Kernel Object APIs */ +extern CL_API_ENTRY cl_kernel CL_API_CALL +clCreateKernel(cl_program /* program */, + const char * /* kernel_name */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clCreateKernelsInProgram(cl_program /* program */, + cl_uint /* num_kernels */, + cl_kernel * /* kernels */, + cl_uint * /* num_kernels_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainKernel(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseKernel(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArg(cl_kernel /* kernel */, + cl_uint /* arg_index */, + size_t /* arg_size */, + const void * /* arg_value */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetKernelInfo(cl_kernel /* kernel */, + cl_kernel_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetKernelArgInfo(cl_kernel /* kernel */, + cl_uint /* arg_indx */, + cl_kernel_arg_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +/* Event Object APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clWaitForEvents(cl_uint /* num_events */, + const cl_event * /* event_list */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetEventInfo(cl_event /* event */, + cl_event_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_event CL_API_CALL +clCreateUserEvent(cl_context /* context */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetUserEventStatus(cl_event /* event */, + cl_int /* execution_status */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetEventCallback( cl_event /* event */, + cl_int /* command_exec_callback_type */, + void (CL_CALLBACK * /* pfn_notify */)(cl_event, cl_int, void *), + void * /* user_data */) CL_API_SUFFIX__VERSION_1_1; + +/* Profiling APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clGetEventProfilingInfo(cl_event /* event */, + cl_profiling_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Flush and Finish APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clFlush(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clFinish(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; + +/* Enqueued Commands APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadBufferRect(cl_command_queue /* command_queue */, + cl_mem /* buffer */, + cl_bool /* blocking_read */, + const size_t * /* buffer_offset */, + const size_t * /* host_offset */, + const size_t * /* region */, + size_t /* buffer_row_pitch */, + size_t /* buffer_slice_pitch */, + size_t /* host_row_pitch */, + size_t /* host_slice_pitch */, + void * /* ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteBufferRect(cl_command_queue /* command_queue */, + cl_mem /* buffer */, + cl_bool /* blocking_write */, + const size_t * /* buffer_offset */, + const size_t * /* host_offset */, + const size_t * /* region */, + size_t /* buffer_row_pitch */, + size_t /* buffer_slice_pitch */, + size_t /* host_row_pitch */, + size_t /* host_slice_pitch */, + const void * /* ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBuffer(cl_command_queue /* command_queue */, + cl_mem /* src_buffer */, + cl_mem /* dst_buffer */, + size_t /* src_offset */, + size_t /* dst_offset */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBufferRect(cl_command_queue /* command_queue */, + cl_mem /* src_buffer */, + cl_mem /* dst_buffer */, + const size_t * /* src_origin */, + const size_t * /* dst_origin */, + const size_t * /* region */, + size_t /* src_row_pitch */, + size_t /* src_slice_pitch */, + size_t /* dst_row_pitch */, + size_t /* dst_slice_pitch */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadImage(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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteImage(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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueFillImage(cl_command_queue /* command_queue */, + cl_mem /* image */, + const void * /* fill_color */, + const size_t * /* origin[3] */, + const size_t * /* region[3] */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyImage(cl_command_queue /* command_queue */, + cl_mem /* src_image */, + cl_mem /* dst_image */, + const size_t * /* src_origin[3] */, + const size_t * /* dst_origin[3] */, + const size_t * /* region[3] */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyImageToBuffer(cl_command_queue /* command_queue */, + cl_mem /* src_image */, + cl_mem /* dst_buffer */, + const size_t * /* src_origin[3] */, + const size_t * /* region[3] */, + size_t /* dst_offset */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBufferToImage(cl_command_queue /* command_queue */, + cl_mem /* src_buffer */, + cl_mem /* dst_image */, + size_t /* src_offset */, + const size_t * /* dst_origin[3] */, + const size_t * /* region[3] */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY void * CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY void * CL_API_CALL +clEnqueueMapImage(cl_command_queue /* command_queue */, + cl_mem /* image */, + cl_bool /* blocking_map */, + cl_map_flags /* map_flags */, + const size_t * /* origin[3] */, + const size_t * /* region[3] */, + 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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMigrateMemObjects(cl_command_queue /* command_queue */, + cl_uint /* num_mem_objects */, + const cl_mem * /* mem_objects */, + cl_mem_migration_flags /* flags */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueTask(cl_command_queue /* command_queue */, + cl_kernel /* kernel */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueNativeKernel(cl_command_queue /* command_queue */, + void (CL_CALLBACK * /*user_func*/)(void *), + void * /* args */, + size_t /* cb_args */, + cl_uint /* num_mem_objects */, + const cl_mem * /* mem_list */, + const void ** /* args_mem_loc */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMarkerWithWaitList(cl_command_queue /* command_queue */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueBarrierWithWaitList(cl_command_queue /* command_queue */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; + + +/* Extension function access + * + * Returns the extension function address for the given function name, + * or NULL if a valid function can not be found. The client must + * check to make sure the address is not NULL, before using or + * calling the returned function address. + */ +extern CL_API_ENTRY void * CL_API_CALL +clGetExtensionFunctionAddressForPlatform(cl_platform_id /* platform */, + const char * /* func_name */) CL_API_SUFFIX__VERSION_1_2; + + +/* Deprecated OpenCL 1.1 APIs */ +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateImage2D(cl_context /* context */, + cl_mem_flags /* flags */, + const cl_image_format * /* image_format */, + size_t /* image_width */, + size_t /* image_height */, + size_t /* image_row_pitch */, + void * /* host_ptr */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateImage3D(cl_context /* context */, + cl_mem_flags /* flags */, + const cl_image_format * /* image_format */, + size_t /* image_width */, + size_t /* image_height */, + size_t /* image_depth */, + size_t /* image_row_pitch */, + size_t /* image_slice_pitch */, + void * /* host_ptr */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clEnqueueMarker(cl_command_queue /* command_queue */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clEnqueueWaitForEvents(cl_command_queue /* command_queue */, + cl_uint /* num_events */, + const cl_event * /* event_list */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clEnqueueBarrier(cl_command_queue /* command_queue */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clUnloadCompiler(void) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED void * CL_API_CALL +clGetExtensionFunctionAddress(const char * /* func_name */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_H */ + diff --git a/opencl/khronos/headers/opencl1.2/CL/cl.hpp b/opencl/khronos/headers/opencl1.2/CL/cl.hpp new file mode 100644 index 0000000000..3ea724593b --- /dev/null +++ b/opencl/khronos/headers/opencl1.2/CL/cl.hpp @@ -0,0 +1,12960 @@ +/* Modifications Copyright(C)[2021-2022] Advanced Micro Devices, Inc. + * All rights reserved. + * */ + +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +/*! \file + * + * \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33) and + * OpenCL 1.2 (rev 15) + * \author Benedict R. Gaster, Laurent Morichetti and Lee Howes + * + * Additions and fixes from: + * Brian Cole, March 3rd 2010 and April 2012 + * Matt Gruenke, April 2012. + * Bruce Merry, February 2013. + * Tom Deakin and Simon McIntosh-Smith, July 2013 + * + * \version 1.2.9 + * \date December 2015 + * + * Optional extension support + * + * cl + * cl_ext_device_fission + * #define USE_CL_DEVICE_FISSION + */ + +/*! \mainpage + * \section intro Introduction + * For many large applications C++ is the language of choice and so it seems + * reasonable to define C++ bindings for OpenCL. + * + * + * The interface is contained with a single C++ header file \em cl.hpp and all + * definitions are contained within the namespace \em cl. There is no additional + * requirement to include \em cl.h and to use either the C++ or original C + * bindings it is enough to simply include \em cl.hpp. + * + * The bindings themselves are lightweight and correspond closely to the + * underlying C API. Using the C++ bindings introduces no additional execution + * overhead. + * + * For detail documentation on the bindings see: + * + * The OpenCL C++ Wrapper API 1.2 (revision 09) + * http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.2.pdf + * + * \section example Example + * + * The following example shows a general use case for the C++ + * bindings, including support for the optional exception feature and + * also the supplied vector and string classes, see following sections for + * decriptions of these features. + * + * \code + * #define __CL_ENABLE_EXCEPTIONS + * + * #if defined(__APPLE__) || defined(__MACOSX) + * #include + * #else + * #include + * #endif + * #include + * #include + * #include + * + * const char * helloStr = "__kernel void " + * "hello(void) " + * "{ " + * " " + * "} "; + * + * int + * main(void) + * { + * cl_int err = CL_SUCCESS; + * try { + * + * std::vector platforms; + * cl::Platform::get(&platforms); + * if (platforms.size() == 0) { + * std::cout << "Platform size 0\n"; + * return -1; + * } + * + * cl_context_properties properties[] = + * { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0}; + * cl::Context context(CL_DEVICE_TYPE_CPU, properties); + * + * std::vector devices = context.getInfo(); + * + * cl::Program::Sources source(1, + * std::make_pair(helloStr,strlen(helloStr))); + * cl::Program program_ = cl::Program(context, source); + * program_.build(devices); + * + * cl::Kernel kernel(program_, "hello", &err); + * + * cl::Event event; + * cl::CommandQueue queue(context, devices[0], 0, &err); + * queue.enqueueNDRangeKernel( + * kernel, + * cl::NullRange, + * cl::NDRange(4,4), + * cl::NullRange, + * NULL, + * &event); + * + * event.wait(); + * } + * catch (cl::Error err) { + * std::cerr + * << "ERROR: " + * << err.what() + * << "(" + * << err.err() + * << ")" + * << std::endl; + * } + * + * return EXIT_SUCCESS; + * } + * + * \endcode + * + */ +#ifndef CL_HPP_ +#define CL_HPP_ + +#ifdef _WIN32 + +#include + +#if defined(USE_DX_INTEROP) +#include +#include +#endif +#endif // _WIN32 + +#if defined(_MSC_VER) +#include +#endif // _MSC_VER + +// +#if defined(USE_CL_DEVICE_FISSION) +#include +#endif + +#if defined(__APPLE__) || defined(__MACOSX) +#include +#else +#include +#endif // !__APPLE__ + +#if (_MSC_VER >= 1700) || (__cplusplus >= 201103L) +#define CL_HPP_RVALUE_REFERENCES_SUPPORTED +#define CL_HPP_CPP11_ATOMICS_SUPPORTED +#include +#endif + +#if (__cplusplus >= 201103L) +#define CL_HPP_NOEXCEPT noexcept +#else +#define CL_HPP_NOEXCEPT +#endif + + +// To avoid accidentally taking ownership of core OpenCL types +// such as cl_kernel constructors are made explicit +// under OpenCL 1.2 +#if defined(CL_VERSION_1_2) && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +#define __CL_EXPLICIT_CONSTRUCTORS explicit +#else // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +#define __CL_EXPLICIT_CONSTRUCTORS +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +// Define deprecated prefixes and suffixes to ensure compilation +// in case they are not pre-defined +#if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) + +#if !defined(CL_CALLBACK) +#define CL_CALLBACK +#endif //CL_CALLBACK + +#include +#include +#include + +#if defined(__CL_ENABLE_EXCEPTIONS) +#include +#endif // #if defined(__CL_ENABLE_EXCEPTIONS) + +#if !defined(__NO_STD_VECTOR) +#include +#endif + +#if !defined(__NO_STD_STRING) +#include +#endif + +#if defined(__ANDROID__) || defined(linux) || defined(__APPLE__) || defined(__MACOSX) +#include +#endif // linux + +#include + + +/*! \namespace cl + * + * \brief The OpenCL C++ bindings are defined within this namespace. + * + */ +namespace cl { + +class Memory; + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) +#define __INIT_CL_EXT_FCN_PTR(name) \ + if(!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddress(#name); \ + if(!pfn_##name) { \ + } \ + } +#endif // #if defined(CL_VERSION_1_1) + +#if defined(CL_VERSION_1_2) +#define __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, name) \ + if(!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddressForPlatform(platform, #name); \ + if(!pfn_##name) { \ + } \ + } +#endif // #if defined(CL_VERSION_1_1) + +class Program; +class Device; +class Context; +class CommandQueue; +class Memory; +class Buffer; + +#if defined(__CL_ENABLE_EXCEPTIONS) +/*! \brief Exception class + * + * This may be thrown by API functions when __CL_ENABLE_EXCEPTIONS is defined. + */ +class Error : public std::exception +{ +private: + cl_int err_; + const char * errStr_; +public: + /*! \brief Create a new CL error exception for a given error code + * and corresponding message. + * + * \param err error code value. + * + * \param errStr a descriptive string that must remain in scope until + * handling of the exception has concluded. If set, it + * will be returned by what(). + */ + Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr) + {} + + ~Error() throw() {} + + /*! \brief Get error string associated with exception + * + * \return A memory pointer to the error message string. + */ + virtual const char * what() const throw () + { + if (errStr_ == NULL) { + return "empty"; + } + else { + return errStr_; + } + } + + /*! \brief Get error code associated with exception + * + * \return The error code. + */ + cl_int err(void) const { return err_; } +}; + +#define __ERR_STR(x) #x +#else +#define __ERR_STR(x) NULL +#endif // __CL_ENABLE_EXCEPTIONS + + +namespace detail +{ +#if defined(__CL_ENABLE_EXCEPTIONS) +static inline cl_int errHandler ( + cl_int err, + const char * errStr = NULL) +{ + if (err != CL_SUCCESS) { + throw Error(err, errStr); + } + return err; +} +#else +static inline cl_int errHandler (cl_int err, const char * errStr = NULL) +{ + (void) errStr; // suppress unused variable warning + return err; +} +#endif // __CL_ENABLE_EXCEPTIONS +} + + + +//! \cond DOXYGEN_DETAIL +#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS) +#define __GET_DEVICE_INFO_ERR __ERR_STR(clGetDeviceInfo) +#define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo) +#define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs) +#define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs) +#define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo) +#define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo) +#define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo) +#define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo) +#define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo) +#define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo) +#define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo) +#if defined(CL_VERSION_1_2) +#define __GET_KERNEL_ARG_INFO_ERR __ERR_STR(clGetKernelArgInfo) +#endif // #if defined(CL_VERSION_1_2) +#define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo) +#define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo) +#define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo) +#define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo) + +#define __CREATE_CONTEXT_ERR __ERR_STR(clCreateContext) +#define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType) +#define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats) + +#define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer) +#define __COPY_ERR __ERR_STR(cl::copy) +#define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer) +#define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer) +#define __CREATE_GL_RENDER_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer) +#define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo) +#if defined(CL_VERSION_1_2) +#define __CREATE_IMAGE_ERR __ERR_STR(clCreateImage) +#define __CREATE_GL_TEXTURE_ERR __ERR_STR(clCreateFromGLTexture) +#define __IMAGE_DIMENSION_ERR __ERR_STR(Incorrect image dimensions) +#endif // #if defined(CL_VERSION_1_2) +#define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler) +#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback) + +#define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent) +#define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus) +#define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback) +#define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents) + +#define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel) +#define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg) +#define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource) +#define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary) +#if defined(CL_VERSION_1_2) +#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR __ERR_STR(clCreateProgramWithBuiltInKernels) +#endif // #if defined(CL_VERSION_1_2) +#define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram) +#if defined(CL_VERSION_1_2) +#define __COMPILE_PROGRAM_ERR __ERR_STR(clCompileProgram) +#define __LINK_PROGRAM_ERR __ERR_STR(clLinkProgram) +#endif // #if defined(CL_VERSION_1_2) +#define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram) + +#define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue) +#define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty) +#define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer) +#define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect) +#define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer) +#define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect) +#define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer) +#define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect) +#define __ENQUEUE_FILL_BUFFER_ERR __ERR_STR(clEnqueueFillBuffer) +#define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage) +#define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage) +#define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage) +#define __ENQUEUE_FILL_IMAGE_ERR __ERR_STR(clEnqueueFillImage) +#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer) +#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage) +#define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer) +#define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage) +#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject) +#define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel) +#define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask) +#define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel) +#if defined(CL_VERSION_1_2) +#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR __ERR_STR(clEnqueueMigrateMemObjects) +#endif // #if defined(CL_VERSION_1_2) + +#define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects) +#define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects) + + +#define __RETAIN_ERR __ERR_STR(Retain Object) +#define __RELEASE_ERR __ERR_STR(Release Object) +#define __FLUSH_ERR __ERR_STR(clFlush) +#define __FINISH_ERR __ERR_STR(clFinish) +#define __VECTOR_CAPACITY_ERR __ERR_STR(Vector capacity error) + +/** + * CL 1.2 version that uses device fission. + */ +#if defined(CL_VERSION_1_2) +#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevices) +#else +#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT) +#endif // #if defined(CL_VERSION_1_2) + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) +#define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker) +#define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents) +#define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier) +#define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler) +#define __CREATE_GL_TEXTURE_2D_ERR __ERR_STR(clCreateFromGLTexture2D) +#define __CREATE_GL_TEXTURE_3D_ERR __ERR_STR(clCreateFromGLTexture3D) +#define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D) +#define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D) +#endif // #if defined(CL_VERSION_1_1) + +#endif // __CL_USER_OVERRIDE_ERROR_STRINGS +//! \endcond + +/** + * CL 1.2 marker and barrier commands + */ +#if defined(CL_VERSION_1_2) +#define __ENQUEUE_MARKER_WAIT_LIST_ERR __ERR_STR(clEnqueueMarkerWithWaitList) +#define __ENQUEUE_BARRIER_WAIT_LIST_ERR __ERR_STR(clEnqueueBarrierWithWaitList) +#endif // #if defined(CL_VERSION_1_2) + +#if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING) +typedef std::string STRING_CLASS; +#elif !defined(__USE_DEV_STRING) + +/*! \class string + * \brief Simple string class, that provides a limited subset of std::string + * functionality but avoids many of the issues that come with that class. + + * \note Deprecated. Please use std::string as default or + * re-define the string class to match the std::string + * interface by defining STRING_CLASS + */ +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED string +{ +private: + ::size_t size_; + char * str_; +public: + //! \brief Constructs an empty string, allocating no memory. + string(void) : size_(0), str_(NULL) + { + } + + /*! \brief Constructs a string populated from an arbitrary value of + * specified size. + * + * An extra '\0' is added, in case none was contained in str. + * + * \param str the initial value of the string instance. Note that '\0' + * characters receive no special treatment. If NULL, + * the string is left empty, with a size of 0. + * + * \param size the number of characters to copy from str. + */ + string(const char * str, ::size_t size) : + size_(size), + str_(NULL) + { + if( size > 0 ) { + str_ = new char[size_+1]; + if (str_ != NULL) { + memcpy(str_, str, size_ * sizeof(char)); + str_[size_] = '\0'; + } + else { + size_ = 0; + } + } + } + + /*! \brief Constructs a string populated from a null-terminated value. + * + * \param str the null-terminated initial value of the string instance. + * If NULL, the string is left empty, with a size of 0. + */ + string(const char * str) : + size_(0), + str_(NULL) + { + if( str ) { + size_= ::strlen(str); + } + if( size_ > 0 ) { + str_ = new char[size_ + 1]; + if (str_ != NULL) { + memcpy(str_, str, (size_ + 1) * sizeof(char)); + } + } + } + + void resize( ::size_t n ) + { + if( size_ == n ) { + return; + } + if (n == 0) { + if( str_ ) { + delete [] str_; + } + str_ = NULL; + size_ = 0; + } + else { + char *newString = new char[n + 1]; + ::size_t copySize = n; + if( size_ < n ) { + copySize = size_; + } + size_ = n; + + if(str_) { + memcpy(newString, str_, (copySize + 1) * sizeof(char)); + } + if( copySize < size_ ) { + memset(newString + copySize, 0, size_ - copySize); + } + newString[size_] = '\0'; + + delete [] str_; + str_ = newString; + } + } + + const char& operator[] ( ::size_t pos ) const + { + return str_[pos]; + } + + char& operator[] ( ::size_t pos ) + { + return str_[pos]; + } + + /*! \brief Copies the value of another string to this one. + * + * \param rhs the string to copy. + * + * \returns a reference to the modified instance. + */ + string& operator=(const string& rhs) + { + if (this == &rhs) { + return *this; + } + + if( str_ != NULL ) { + delete [] str_; + str_ = NULL; + size_ = 0; + } + + if (rhs.size_ == 0 || rhs.str_ == NULL) { + str_ = NULL; + size_ = 0; + } + else { + str_ = new char[rhs.size_ + 1]; + size_ = rhs.size_; + + if (str_ != NULL) { + memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char)); + } + else { + size_ = 0; + } + } + + return *this; + } + + /*! \brief Constructs a string by copying the value of another instance. + * + * \param rhs the string to copy. + */ + string(const string& rhs) : + size_(0), + str_(NULL) + { + *this = rhs; + } + + //! \brief Destructor - frees memory used to hold the current value. + ~string() + { + delete[] str_; + str_ = NULL; + } + + //! \brief Queries the length of the string, excluding any added '\0's. + ::size_t size(void) const { return size_; } + + //! \brief Queries the length of the string, excluding any added '\0's. + ::size_t length(void) const { return size(); } + + /*! \brief Returns a pointer to the private copy held by this instance, + * or "" if empty/unset. + */ + const char * c_str(void) const { return (str_) ? str_ : "";} +} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +typedef cl::string STRING_CLASS; +#endif // #elif !defined(__USE_DEV_STRING) + +#if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR) +#define VECTOR_CLASS std::vector +#elif !defined(__USE_DEV_VECTOR) +#define VECTOR_CLASS cl::vector + +#if !defined(__MAX_DEFAULT_VECTOR_SIZE) +#define __MAX_DEFAULT_VECTOR_SIZE 10 +#endif + +/*! \class vector + * \brief Fixed sized vector implementation that mirroring + * + * \note Deprecated. Please use std::vector as default or + * re-define the vector class to match the std::vector + * interface by defining VECTOR_CLASS + + * \note Not recommended for use with custom objects as + * current implementation will construct N elements + * + * std::vector functionality. + * \brief Fixed sized vector compatible with std::vector. + * + * \note + * This differs from std::vector<> not just in memory allocation, + * but also in terms of when members are constructed, destroyed, + * and assigned instead of being copy constructed. + * + * \param T type of element contained in the vector. + * + * \param N maximum size of the vector. + */ +template +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED vector +{ +private: + T data_[N]; + unsigned int size_; + +public: + //! \brief Constructs an empty vector with no memory allocated. + vector() : + size_(static_cast(0)) + {} + + //! \brief Deallocates the vector's memory and destroys all of its elements. + ~vector() + { + clear(); + } + + //! \brief Returns the number of elements currently contained. + unsigned int size(void) const + { + return size_; + } + + /*! \brief Empties the vector of all elements. + * \note + * This does not deallocate memory but will invoke destructors + * on contained elements. + */ + void clear() + { + while(!empty()) { + pop_back(); + } + } + + /*! \brief Appends an element after the last valid element. + * Calling this on a vector that has reached capacity will throw an + * exception if exceptions are enabled. + */ + void push_back (const T& x) + { + if (size() < N) { + new (&data_[size_]) T(x); + size_++; + } else { + detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); + } + } + + /*! \brief Removes the last valid element from the vector. + * Calling this on an empty vector will throw an exception + * if exceptions are enabled. + */ + void pop_back(void) + { + if (size_ != 0) { + --size_; + data_[size_].~T(); + } else { + detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); + } + } + + /*! \brief Constructs with a value copied from another. + * + * \param vec the vector to copy. + */ + vector(const vector& vec) : + size_(vec.size_) + { + if (size_ != 0) { + assign(vec.begin(), vec.end()); + } + } + + /*! \brief Constructs with a specified number of initial elements. + * + * \param size number of initial elements. + * + * \param val value of initial elements. + */ + vector(unsigned int size, const T& val = T()) : + size_(0) + { + for (unsigned int i = 0; i < size; i++) { + push_back(val); + } + } + + /*! \brief Overwrites the current content with that copied from another + * instance. + * + * \param rhs vector to copy. + * + * \returns a reference to this. + */ + vector& operator=(const vector& rhs) + { + if (this == &rhs) { + return *this; + } + + if (rhs.size_ != 0) { + assign(rhs.begin(), rhs.end()); + } else { + clear(); + } + + return *this; + } + + /*! \brief Tests equality against another instance. + * + * \param vec the vector against which to compare. + */ + bool operator==(vector &vec) + { + if (size() != vec.size()) { + return false; + } + + for( unsigned int i = 0; i < size(); ++i ) { + if( operator[](i) != vec[i] ) { + return false; + } + } + return true; + } + + //! \brief Conversion operator to T*. + operator T* () { return data_; } + + //! \brief Conversion operator to const T*. + operator const T* () const { return data_; } + + //! \brief Tests whether this instance has any elements. + bool empty (void) const + { + return size_==0; + } + + //! \brief Returns the maximum number of elements this instance can hold. + unsigned int max_size (void) const + { + return N; + } + + //! \brief Returns the maximum number of elements this instance can hold. + unsigned int capacity () const + { + return N; + } + + //! \brief Resizes the vector to the given size + void resize(unsigned int newSize, T fill = T()) + { + if (newSize > N) + { + detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); + } + else + { + while (size_ < newSize) + { + new (&data_[size_]) T(fill); + size_++; + } + while (size_ > newSize) + { + --size_; + data_[size_].~T(); + } + } + } + + /*! \brief Returns a reference to a given element. + * + * \param index which element to access. * + * \note + * The caller is responsible for ensuring index is >= 0 and < size(). + */ + T& operator[](int index) + { + return data_[index]; + } + + /*! \brief Returns a const reference to a given element. + * + * \param index which element to access. + * + * \note + * The caller is responsible for ensuring index is >= 0 and < size(). + */ + const T& operator[](int index) const + { + return data_[index]; + } + + /*! \brief Assigns elements of the vector based on a source iterator range. + * + * \param start Beginning iterator of source range + * \param end Enditerator of source range + * + * \note + * Will throw an exception if exceptions are enabled and size exceeded. + */ + template + void assign(I start, I end) + { + clear(); + while(start != end) { + push_back(*start); + start++; + } + } + + /*! \class iterator + * \brief Const iterator class for vectors + */ + class iterator + { + private: + const vector *vec_; + int index_; + + /** + * Internal iterator constructor to capture reference + * to the vector it iterates over rather than taking + * the vector by copy. + */ + iterator (const vector &vec, int index) : + vec_(&vec) + { + if( !vec.empty() ) { + index_ = index; + } else { + index_ = -1; + } + } + + public: + iterator(void) : + index_(-1), + vec_(NULL) + { + } + + iterator(const iterator& rhs) : + vec_(rhs.vec_), + index_(rhs.index_) + { + } + + ~iterator(void) {} + + static iterator begin(const cl::vector &vec) + { + iterator i(vec, 0); + + return i; + } + + static iterator end(const cl::vector &vec) + { + iterator i(vec, vec.size()); + + return i; + } + + bool operator==(iterator i) + { + return ((vec_ == i.vec_) && + (index_ == i.index_)); + } + + bool operator!=(iterator i) + { + return (!(*this==i)); + } + + iterator& operator++() + { + ++index_; + return *this; + } + + iterator operator++(int) + { + iterator retVal(*this); + ++index_; + return retVal; + } + + iterator& operator--() + { + --index_; + return *this; + } + + iterator operator--(int) + { + iterator retVal(*this); + --index_; + return retVal; + } + + const T& operator *() const + { + return (*vec_)[index_]; + } + }; + + iterator begin(void) + { + return iterator::begin(*this); + } + + iterator begin(void) const + { + return iterator::begin(*this); + } + + iterator end(void) + { + return iterator::end(*this); + } + + iterator end(void) const + { + return iterator::end(*this); + } + + T& front(void) + { + return data_[0]; + } + + T& back(void) + { + return data_[size_]; + } + + const T& front(void) const + { + return data_[0]; + } + + const T& back(void) const + { + return data_[size_-1]; + } +} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +#endif // #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR) + + + + + +namespace detail { +#define __DEFAULT_NOT_INITIALIZED 1 +#define __DEFAULT_BEING_INITIALIZED 2 +#define __DEFAULT_INITIALIZED 4 + + /* + * Compare and exchange primitives are needed for handling of defaults + */ + +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + inline int compare_exchange(std::atomic * dest, int exchange, int comparand) +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED + inline int compare_exchange(volatile int * dest, int exchange, int comparand) +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + { +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + std::atomic_compare_exchange_strong(dest, &comparand, exchange); + return comparand; +#elif _MSC_VER + return (int)(_InterlockedCompareExchange( + (volatile long*)dest, + (long)exchange, + (long)comparand)); +#else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED + return (__sync_val_compare_and_swap( + dest, + comparand, + exchange)); +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + } + + inline void fence() { +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + std::atomic_thread_fence(std::memory_order_seq_cst); +#elif _MSC_VER // !CL_HPP_CPP11_ATOMICS_SUPPORTED + _ReadWriteBarrier(); +#else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED + __sync_synchronize(); +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + } +} // namespace detail + + +/*! \brief class used to interface between C++ and + * OpenCL C calls that require arrays of size_t values, whose + * size is known statically. + */ +template +class size_t +{ +private: + ::size_t data_[N]; + +public: + //! \brief Initialize size_t to all 0s + size_t() + { + for( int i = 0; i < N; ++i ) { + data_[i] = 0; + } + } + + ::size_t& operator[](int index) + { + return data_[index]; + } + + const ::size_t& operator[](int index) const + { + return data_[index]; + } + + //! \brief Conversion operator to T*. + operator ::size_t* () { return data_; } + + //! \brief Conversion operator to const T*. + operator const ::size_t* () const { return data_; } +}; + +namespace detail { + +// Generic getInfoHelper. The final parameter is used to guide overload +// resolution: the actual parameter passed is an int, which makes this +// a worse conversion sequence than a specialization that declares the +// parameter as an int. +template +inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long) +{ + return f(name, sizeof(T), param, NULL); +} + +// Specialized getInfoHelper for VECTOR_CLASS params +template +inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, long) +{ + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + T* value = (T*) alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + param->assign(&value[0], &value[required/sizeof(T)]); + return CL_SUCCESS; +} + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, int, typename T::cl_type = 0) +{ + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + typename T::cl_type * value = (typename T::cl_type *) alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + ::size_t elements = required / sizeof(typename T::cl_type); + param->assign(&value[0], &value[elements]); + for (::size_t i = 0; i < elements; i++) + { + if (value[i] != NULL) + { + err = (*param)[i].retain(); + if (err != CL_SUCCESS) { + return err; + } + } + } + return CL_SUCCESS; +} + +// Specialized for getInfo +template +inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, int) +{ + cl_int err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL); + + if (err != CL_SUCCESS) { + return err; + } + + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for STRING_CLASS params +template +inline cl_int getInfoHelper(Func f, cl_uint name, STRING_CLASS* param, long) +{ +#if defined(__NO_STD_VECTOR) || defined(__NO_STD_STRING) + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + char* value = (char*)alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + *param = value; + return CL_SUCCESS; +#else + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + // std::string has a constant data member + // a char vector does not + VECTOR_CLASS value(required); + err = f(name, required, value.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + if (param) { + param->assign(value.begin(), value.end()); + } +#endif + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for cl::size_t params +template +inline cl_int getInfoHelper(Func f, cl_uint name, size_t* param, long) +{ + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + ::size_t* value = (::size_t*) alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + for(int i = 0; i < N; ++i) { + (*param)[i] = value[i]; + } + + return CL_SUCCESS; +} + +template struct ReferenceHandler; + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0) +{ + typename T::cl_type value; + cl_int err = f(name, sizeof(value), &value, NULL); + if (err != CL_SUCCESS) { + return err; + } + *param = value; + if (value != NULL) + { + err = param->retain(); + if (err != CL_SUCCESS) { + return err; + } + } + return CL_SUCCESS; +} + +#define __PARAM_NAME_INFO_1_0(F) \ + F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \ + \ + F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \ + F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \ + F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \ + F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \ + F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \ + F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \ + F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \ + F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \ + F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \ + F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \ + \ + F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \ + F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS) \ + F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS) \ + \ + F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \ + F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \ + F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \ + F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \ + \ + F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \ + \ + F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \ + F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \ + F(cl_mem_info, CL_MEM_SIZE, ::size_t) \ + F(cl_mem_info, CL_MEM_HOST_PTR, void*) \ + F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \ + \ + F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \ + F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \ + F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \ + F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \ + F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \ + F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \ + F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \ + \ + F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \ + F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \ + F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \ + F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \ + F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \ + \ + F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \ + F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \ + F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \ + F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS) \ + F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \ + F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \ + F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS) \ + \ + F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \ + \ + F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \ + F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \ + F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \ + F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \ + F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \ + \ + F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \ + F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \ + F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \ + F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties) + +#if defined(CL_VERSION_1_1) +#define __PARAM_NAME_INFO_1_1(F) \ + F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \ + F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, STRING_CLASS) \ + \ + F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \ + F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \ + F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \ + \ + F(cl_event_info, CL_EVENT_CONTEXT, cl::Context) +#endif // CL_VERSION_1_1 + + +#if defined(CL_VERSION_1_2) +#define __PARAM_NAME_INFO_1_2(F) \ + F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer) \ + \ + F(cl_program_info, CL_PROGRAM_NUM_KERNELS, ::size_t) \ + F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, STRING_CLASS) \ + \ + F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \ + \ + F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, STRING_CLASS) \ + \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, STRING_CLASS) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, STRING_CLASS) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \ + \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl_device_id) \ + F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPE, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, ::size_t) \ + F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \ + F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, STRING_CLASS) +#endif // #if defined(CL_VERSION_1_2) + +#if defined(USE_CL_DEVICE_FISSION) +#define __PARAM_NAME_DEVICE_FISSION(F) \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \ + F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS) +#endif // USE_CL_DEVICE_FISSION + +template +struct param_traits {}; + +#define __CL_DECLARE_PARAM_TRAITS(token, param_name, T) \ +struct token; \ +template<> \ +struct param_traits \ +{ \ + enum { value = param_name }; \ + typedef T param_type; \ +}; + +__PARAM_NAME_INFO_1_0(__CL_DECLARE_PARAM_TRAITS) +#if defined(CL_VERSION_1_1) +__PARAM_NAME_INFO_1_1(__CL_DECLARE_PARAM_TRAITS) +#endif // CL_VERSION_1_1 +#if defined(CL_VERSION_1_2) +__PARAM_NAME_INFO_1_2(__CL_DECLARE_PARAM_TRAITS) +#endif // CL_VERSION_1_1 + +#if defined(USE_CL_DEVICE_FISSION) +__PARAM_NAME_DEVICE_FISSION(__CL_DECLARE_PARAM_TRAITS); +#endif // USE_CL_DEVICE_FISSION + +#ifdef CL_PLATFORM_ICD_SUFFIX_KHR +__CL_DECLARE_PARAM_TRAITS(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, STRING_CLASS) +#endif + +#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong) +#endif + +#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, VECTOR_CLASS< ::size_t>) +#endif +#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD, ::size_t) +#endif +#ifdef CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD, ::size_t) +#endif +#ifdef CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD, ::size_t) +#endif + +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint) +#endif +#ifdef CL_DEVICE_WARP_SIZE_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint) +#endif +#ifdef CL_DEVICE_GPU_OVERLAP_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool) +#endif +#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool) +#endif +#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool) +#endif + +// Convenience functions + +template +inline cl_int +getInfo(Func f, cl_uint name, T* param) +{ + return getInfoHelper(f, name, param, 0); +} + +template +struct GetInfoFunctor0 +{ + Func f_; const Arg0& arg0_; + cl_int operator ()( + cl_uint param, ::size_t size, void* value, ::size_t* size_ret) + { return f_(arg0_, param, size, value, size_ret); } +}; + +template +struct GetInfoFunctor1 +{ + Func f_; const Arg0& arg0_; const Arg1& arg1_; + cl_int operator ()( + cl_uint param, ::size_t size, void* value, ::size_t* size_ret) + { return f_(arg0_, arg1_, param, size, value, size_ret); } +}; + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, cl_uint name, T* param) +{ + GetInfoFunctor0 f0 = { f, arg0 }; + return getInfoHelper(f0, name, param, 0); +} + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param) +{ + GetInfoFunctor1 f0 = { f, arg0, arg1 }; + return getInfoHelper(f0, name, param, 0); +} + +template +struct ReferenceHandler +{ }; + +#if defined(CL_VERSION_1_2) +/** + * OpenCL 1.2 devices do have retain/release. + */ +template <> +struct ReferenceHandler +{ + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int retain(cl_device_id device) + { return ::clRetainDevice(device); } + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int release(cl_device_id device) + { return ::clReleaseDevice(device); } +}; +#else // #if defined(CL_VERSION_1_2) +/** + * OpenCL 1.1 devices do not have retain/release. + */ +template <> +struct ReferenceHandler +{ + // cl_device_id does not have retain(). + static cl_int retain(cl_device_id) + { return CL_SUCCESS; } + // cl_device_id does not have release(). + static cl_int release(cl_device_id) + { return CL_SUCCESS; } +}; +#endif // #if defined(CL_VERSION_1_2) + +template <> +struct ReferenceHandler +{ + // cl_platform_id does not have retain(). + static cl_int retain(cl_platform_id) + { return CL_SUCCESS; } + // cl_platform_id does not have release(). + static cl_int release(cl_platform_id) + { return CL_SUCCESS; } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_context context) + { return ::clRetainContext(context); } + static cl_int release(cl_context context) + { return ::clReleaseContext(context); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_command_queue queue) + { return ::clRetainCommandQueue(queue); } + static cl_int release(cl_command_queue queue) + { return ::clReleaseCommandQueue(queue); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_mem memory) + { return ::clRetainMemObject(memory); } + static cl_int release(cl_mem memory) + { return ::clReleaseMemObject(memory); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_sampler sampler) + { return ::clRetainSampler(sampler); } + static cl_int release(cl_sampler sampler) + { return ::clReleaseSampler(sampler); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_program program) + { return ::clRetainProgram(program); } + static cl_int release(cl_program program) + { return ::clReleaseProgram(program); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_kernel kernel) + { return ::clRetainKernel(kernel); } + static cl_int release(cl_kernel kernel) + { return ::clReleaseKernel(kernel); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_event event) + { return ::clRetainEvent(event); } + static cl_int release(cl_event event) + { return ::clReleaseEvent(event); } +}; + + +// Extracts version number with major in the upper 16 bits, minor in the lower 16 +static cl_uint getVersion(const char *versionInfo) +{ + int highVersion = 0; + int lowVersion = 0; + int index = 7; + while(versionInfo[index] != '.' ) { + highVersion *= 10; + highVersion += versionInfo[index]-'0'; + ++index; + } + ++index; + while(versionInfo[index] != ' ' && versionInfo[index] != '\0') { + lowVersion *= 10; + lowVersion += versionInfo[index]-'0'; + ++index; + } + return (highVersion << 16) | lowVersion; +} + +static cl_uint getPlatformVersion(cl_platform_id platform) +{ + ::size_t size = 0; + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size); + char *versionInfo = (char *) alloca(size); + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, &versionInfo[0], &size); + return getVersion(versionInfo); +} + +static cl_uint getDevicePlatformVersion(cl_device_id device) +{ + cl_platform_id platform; + clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL); + return getPlatformVersion(platform); +} + +#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +static cl_uint getContextPlatformVersion(cl_context context) +{ + // The platform cannot be queried directly, so we first have to grab a + // device and obtain its context + ::size_t size = 0; + clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size); + if (size == 0) + return 0; + cl_device_id *devices = (cl_device_id *) alloca(size); + clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices, NULL); + return getDevicePlatformVersion(devices[0]); +} +#endif // #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +template +class Wrapper +{ +public: + typedef T cl_type; + +protected: + cl_type object_; + +public: + Wrapper() : object_(NULL) { } + + Wrapper(const cl_type &obj) : object_(obj) { } + + ~Wrapper() + { + if (object_ != NULL) { release(); } + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT + { + object_ = rhs.object_; + rhs.object_ = NULL; + } +#endif + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + rhs.object_ = NULL; + } + return *this; + } +#endif + + Wrapper& operator = (const cl_type &rhs) + { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs; + return *this; + } + + cl_type operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + cl_int retain() const + { + return ReferenceHandler::retain(object_); + } + + cl_int release() const + { + return ReferenceHandler::release(object_); + } +}; + +template <> +class Wrapper +{ +public: + typedef cl_device_id cl_type; + +protected: + cl_type object_; + bool referenceCountable_; + + static bool isReferenceCountable(cl_device_id device) + { + bool retVal = false; + if (device != NULL) { + int version = getDevicePlatformVersion(device); + if(version > ((1 << 16) + 1)) { + retVal = true; + } + } + return retVal; + } + +public: + Wrapper() : object_(NULL), referenceCountable_(false) + { + } + + Wrapper(const cl_type &obj) : object_(obj), referenceCountable_(false) + { + referenceCountable_ = isReferenceCountable(obj); + } + + ~Wrapper() + { + if (object_ != NULL) { release(); } + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + referenceCountable_ = isReferenceCountable(object_); + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT + { + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } +#endif + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } + return *this; + } +#endif + + Wrapper& operator = (const cl_type &rhs) + { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs; + referenceCountable_ = isReferenceCountable(object_); + return *this; + } + + cl_type operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + template + friend inline cl_int getInfoHelper(Func, cl_uint, VECTOR_CLASS*, int, typename U::cl_type); + + cl_int retain() const + { + if( referenceCountable_ ) { + return ReferenceHandler::retain(object_); + } + else { + return CL_SUCCESS; + } + } + + cl_int release() const + { + if( referenceCountable_ ) { + return ReferenceHandler::release(object_); + } + else { + return CL_SUCCESS; + } + } +}; + +} // namespace detail +//! \endcond + +/*! \stuct ImageFormat + * \brief Adds constructors and member functions for cl_image_format. + * + * \see cl_image_format + */ +struct ImageFormat : public cl_image_format +{ + //! \brief Default constructor - performs no initialization. + ImageFormat(){} + + //! \brief Initializing constructor. + ImageFormat(cl_channel_order order, cl_channel_type type) + { + image_channel_order = order; + image_channel_data_type = type; + } + + //! \brief Assignment operator. + ImageFormat& operator = (const ImageFormat& rhs) + { + if (this != &rhs) { + this->image_channel_data_type = rhs.image_channel_data_type; + this->image_channel_order = rhs.image_channel_order; + } + return *this; + } +}; + +/*! \brief Class interface for cl_device_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_device_id + */ +class Device : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Device() : detail::Wrapper() { } + + /*! \brief Constructor from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + __CL_EXPLICIT_CONSTRUCTORS Device(const cl_device_id &device) : detail::Wrapper(device) { } + + /*! \brief Returns the first device on the default context. + * + * \see Context::getDefault() + */ + static Device getDefault(cl_int * err = NULL); + + /*! \brief Assignment operator from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + Device& operator = (const cl_device_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device(const Device& dev) : detail::Wrapper(dev) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (const Device &dev) + { + detail::Wrapper::operator=(dev); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Device(Device&& dev) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(dev)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (Device &&dev) + { + detail::Wrapper::operator=(std::move(dev)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetDeviceInfo(). + template + cl_int getInfo(cl_device_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetDeviceInfo, object_, name, param), + __GET_DEVICE_INFO_ERR); + } + + //! \brief Wrapper for clGetDeviceInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_device_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /** + * CL 1.2 version + */ +#if defined(CL_VERSION_1_2) + //! \brief Wrapper for clCreateSubDevicesEXT(). + cl_int createSubDevices( + const cl_device_partition_property * properties, + VECTOR_CLASS* devices) + { + cl_uint n = 0; + cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = clCreateSubDevices(object_, properties, n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } +#endif // #if defined(CL_VERSION_1_2) + +/** + * CL 1.1 version that uses device fission. + */ +#if defined(CL_VERSION_1_1) +#if defined(USE_CL_DEVICE_FISSION) + cl_int createSubDevices( + const cl_device_partition_property_ext * properties, + VECTOR_CLASS* devices) + { + typedef CL_API_ENTRY cl_int + ( CL_API_CALL * PFN_clCreateSubDevicesEXT)( + cl_device_id /*in_device*/, + const cl_device_partition_property_ext * /* properties */, + cl_uint /*num_entries*/, + cl_device_id * /*out_devices*/, + cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL; + __INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT); + + cl_uint n = 0; + cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } +#endif // #if defined(USE_CL_DEVICE_FISSION) +#endif // #if defined(CL_VERSION_1_1) +}; + +/*! \brief Class interface for cl_platform_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_platform_id + */ +class Platform : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Platform() : detail::Wrapper() { } + + /*! \brief Constructor from cl_platform_id. + * + * This simply copies the platform ID value, which is an inexpensive operation. + */ + __CL_EXPLICIT_CONSTRUCTORS Platform(const cl_platform_id &platform) : detail::Wrapper(platform) { } + + /*! \brief Assignment operator from cl_platform_id. + * + * This simply copies the platform ID value, which is an inexpensive operation. + */ + Platform& operator = (const cl_platform_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetPlatformInfo(). + cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetPlatformInfo, object_, name, param), + __GET_PLATFORM_INFO_ERR); + } + + //! \brief Wrapper for clGetPlatformInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_platform_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of devices for this platform. + * + * Wraps clGetDeviceIDs(). + */ + cl_int getDevices( + cl_device_type type, + VECTOR_CLASS* devices) const + { + cl_uint n = 0; + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = ::clGetDeviceIDs(object_, type, n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } + +#if defined(USE_DX_INTEROP) + /*! \brief Get the list of available D3D10 devices. + * + * \param d3d_device_source. + * + * \param d3d_object. + * + * \param d3d_device_set. + * + * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device + * values returned in devices can be used to identify a specific OpenCL + * device. If \a devices argument is NULL, this argument is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * + * The application can query specific capabilities of the OpenCL device(s) + * returned by cl::getDevices. This can be used by the application to + * determine which device(s) to use. + * + * \note In the case that exceptions are enabled and a return value + * other than CL_SUCCESS is generated, then cl::Error exception is + * generated. + */ + cl_int getDevices( + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + VECTOR_CLASS* devices) const + { + typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)( + cl_platform_id platform, + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint* num_devices); + + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + + static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL; + __INIT_CL_EXT_FCN_PTR_PLATFORM(object_, clGetDeviceIDsFromD3D10KHR); + + cl_uint n = 0; + cl_int err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + 0, + NULL, + &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + n, + ids, + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } +#endif + + /*! \brief Gets a list of available platforms. + * + * Wraps clGetPlatformIDs(). + */ + static cl_int get( + VECTOR_CLASS* platforms) + { + cl_uint n = 0; + + if( platforms == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); + } + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + cl_platform_id* ids = (cl_platform_id*) alloca( + n * sizeof(cl_platform_id)); + err = ::clGetPlatformIDs(n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + platforms->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } + + /*! \brief Gets the first available platform. + * + * Wraps clGetPlatformIDs(), returning the first result. + */ + static cl_int get( + Platform * platform) + { + cl_uint n = 0; + + if( platform == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); + } + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + cl_platform_id* ids = (cl_platform_id*) alloca( + n * sizeof(cl_platform_id)); + err = ::clGetPlatformIDs(n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + *platform = ids[0]; + return CL_SUCCESS; + } + + /*! \brief Gets the first available platform, returning it by value. + * + * Wraps clGetPlatformIDs(), returning the first result. + */ + static Platform get( + cl_int * errResult = NULL) + { + Platform platform; + cl_uint n = 0; + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + if (errResult != NULL) { + *errResult = err; + } + return Platform(); + } + + cl_platform_id* ids = (cl_platform_id*) alloca( + n * sizeof(cl_platform_id)); + err = ::clGetPlatformIDs(n, ids, NULL); + + if (err != CL_SUCCESS) { + detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + if (errResult != NULL) { + *errResult = err; + } + return Platform(); + } + + + return Platform(ids[0]); + } + + static Platform getDefault( + cl_int *errResult = NULL ) + { + return get(errResult); + } + + +#if defined(CL_VERSION_1_2) + //! \brief Wrapper for clUnloadCompiler(). + cl_int + unloadCompiler() + { + return ::clUnloadPlatformCompiler(object_); + } +#endif // #if defined(CL_VERSION_1_2) +}; // class Platform + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) +/** + * Unload the OpenCL compiler. + * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead. + */ +inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int +UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +inline cl_int +UnloadCompiler() +{ + return ::clUnloadCompiler(); +} +#endif // #if defined(CL_VERSION_1_1) + +/*! \brief Class interface for cl_context. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_context as the original. For details, see + * clRetainContext() and clReleaseContext(). + * + * \see cl_context + */ +class Context + : public detail::Wrapper +{ +private: + +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + static std::atomic default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static volatile int default_initialized_; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static Context default_; + static volatile cl_int default_error_; +public: + /*! \brief Constructs a context including a list of specified devices. + * + * Wraps clCreateContext(). + */ + Context( + const VECTOR_CLASS& devices, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + ::size_t, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + ::size_t numDevices = devices.size(); + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateContext( + properties, (cl_uint) numDevices, + deviceIDs, + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + Context( + const Device& device, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + ::size_t, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + cl_device_id deviceID = device(); + + object_ = ::clCreateContext( + properties, 1, + &deviceID, + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a context including all or a subset of devices of a specified type. + * + * Wraps clCreateContextFromType(). + */ + Context( + cl_device_type type, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + ::size_t, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + +#if !defined(__APPLE__) && !defined(__MACOS) + cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 }; + + if (properties == NULL) { + // Get a valid platform ID as we cannot send in a blank one + VECTOR_CLASS platforms; + error = Platform::get(&platforms); + if (error != CL_SUCCESS) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + // Check the platforms we found for a device of our specified type + cl_context_properties platform_id = 0; + for (unsigned int i = 0; i < platforms.size(); i++) { + + VECTOR_CLASS devices; + +#if defined(__CL_ENABLE_EXCEPTIONS) + try { +#endif + + error = platforms[i].getDevices(type, &devices); + +#if defined(__CL_ENABLE_EXCEPTIONS) + } catch (Error) {} + // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type + // We do error checking next anyway, and can throw there if needed +#endif + + // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND + if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + if (devices.size() > 0) { + platform_id = (cl_context_properties)platforms[i](); + break; + } + } + + if (platform_id == 0) { + detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = CL_DEVICE_NOT_FOUND; + } + return; + } + + prop[1] = platform_id; + properties = &prop[0]; + } +#endif + object_ = ::clCreateContextFromType( + properties, type, notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context(const Context& ctx) : detail::Wrapper(ctx) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (const Context &ctx) + { + detail::Wrapper::operator=(ctx); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Context(Context&& ctx) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(ctx)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (Context &&ctx) + { + detail::Wrapper::operator=(std::move(ctx)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT. + * + * \note All calls to this function return the same cl_context as the first. + */ + static Context getDefault(cl_int * err = NULL) + { + int state = detail::compare_exchange( + &default_initialized_, + __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED); + + if (state & __DEFAULT_INITIALIZED) { + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + if (state & __DEFAULT_BEING_INITIALIZED) { + // Assume writes will propagate eventually... + while(default_initialized_ != __DEFAULT_INITIALIZED) { + detail::fence(); + } + + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + cl_int error; + default_ = Context( + CL_DEVICE_TYPE_DEFAULT, + NULL, + NULL, + NULL, + &error); + + detail::fence(); + + default_error_ = error; + // Assume writes will propagate eventually... + default_initialized_ = __DEFAULT_INITIALIZED; + + detail::fence(); + + if (err != NULL) { + *err = default_error_; + } + return default_; + + } + + //! \brief Default constructor - initializes to NULL. + Context() : detail::Wrapper() { } + + /*! \brief Constructor from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_context + * into the new Context object. + */ + __CL_EXPLICIT_CONSTRUCTORS Context(const cl_context& context) : detail::Wrapper(context) { } + + /*! \brief Assignment operator from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseContext() on the value previously held by this instance. + */ + Context& operator = (const cl_context& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetContextInfo(). + template + cl_int getInfo(cl_context_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetContextInfo, object_, name, param), + __GET_CONTEXT_INFO_ERR); + } + + //! \brief Wrapper for clGetContextInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_context_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of supported image formats. + * + * Wraps clGetSupportedImageFormats(). + */ + cl_int getSupportedImageFormats( + cl_mem_flags flags, + cl_mem_object_type type, + VECTOR_CLASS* formats) const + { + cl_uint numEntries; + + if (!formats) { + return CL_SUCCESS; + } + + cl_int err = ::clGetSupportedImageFormats( + object_, + flags, + type, + 0, + NULL, + &numEntries); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + if (numEntries > 0) { + ImageFormat* value = (ImageFormat*) + alloca(numEntries * sizeof(ImageFormat)); + err = ::clGetSupportedImageFormats( + object_, + flags, + type, + numEntries, + (cl_image_format*)value, + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + formats->assign(&value[0], &value[numEntries]); + } + else { + formats->clear(); + } + return CL_SUCCESS; + } +}; + +inline Device Device::getDefault(cl_int * err) +{ + cl_int error; + Device device; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + device = context.getInfo()[0]; + if (err != NULL) { + *err = CL_SUCCESS; + } + } + + return device; +} + + +#ifdef _WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) std::atomic Context::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) Context Context::default_; +__declspec(selectany) volatile cl_int Context::default_error_ = CL_SUCCESS; +#else // !_WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) std::atomic Context::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) Context Context::default_; +__attribute__((weak)) volatile cl_int Context::default_error_ = CL_SUCCESS; +#endif // !_WIN32 + +/*! \brief Class interface for cl_event. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_event as the original. For details, see + * clRetainEvent() and clReleaseEvent(). + * + * \see cl_event + */ +class Event : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Event() : detail::Wrapper() { } + + /*! \brief Constructor from cl_event - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_event + * into the new Event object. + */ + __CL_EXPLICIT_CONSTRUCTORS Event(const cl_event& event) : detail::Wrapper(event) { } + + /*! \brief Assignment operator from cl_event - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseEvent() on the value previously held by this instance. + */ + Event& operator = (const cl_event& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetEventInfo(). + template + cl_int getInfo(cl_event_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetEventInfo, object_, name, param), + __GET_EVENT_INFO_ERR); + } + + //! \brief Wrapper for clGetEventInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_event_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + //! \brief Wrapper for clGetEventProfilingInfo(). + template + cl_int getProfilingInfo(cl_profiling_info name, T* param) const + { + return detail::errHandler(detail::getInfo( + &::clGetEventProfilingInfo, object_, name, param), + __GET_EVENT_PROFILE_INFO_ERR); + } + + //! \brief Wrapper for clGetEventProfilingInfo() that returns by value. + template typename + detail::param_traits::param_type + getProfilingInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_profiling_info, name>::param_type param; + cl_int result = getProfilingInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Blocks the calling thread until this event completes. + * + * Wraps clWaitForEvents(). + */ + cl_int wait() const + { + return detail::errHandler( + ::clWaitForEvents(1, &object_), + __WAIT_FOR_EVENTS_ERR); + } + +#if defined(CL_VERSION_1_1) + /*! \brief Registers a user callback function for a specific command execution status. + * + * Wraps clSetEventCallback(). + */ + cl_int setCallback( + cl_int type, + void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetEventCallback( + object_, + type, + pfn_notify, + user_data), + __SET_EVENT_CALLBACK_ERR); + } +#endif + + /*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ + static cl_int + waitForEvents(const VECTOR_CLASS& events) + { + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); + } +}; + +#if defined(CL_VERSION_1_1) +/*! \brief Class interface for user events (a subset of cl_event's). + * + * See Event for details about copy semantics, etc. + */ +class UserEvent : public Event +{ +public: + /*! \brief Constructs a user event on a given context. + * + * Wraps clCreateUserEvent(). + */ + UserEvent( + const Context& context, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateUserEvent( + context(), + &error); + + detail::errHandler(error, __CREATE_USER_EVENT_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + UserEvent() : Event() { } + + /*! \brief Sets the execution status of a user event object. + * + * Wraps clSetUserEventStatus(). + */ + cl_int setStatus(cl_int status) + { + return detail::errHandler( + ::clSetUserEventStatus(object_,status), + __SET_USER_EVENT_STATUS_ERR); + } +}; +#endif + +/*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ +inline static cl_int +WaitForEvents(const VECTOR_CLASS& events) +{ + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); +} + +/*! \brief Class interface for cl_mem. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_mem as the original. For details, see + * clRetainMemObject() and clReleaseMemObject(). + * + * \see cl_mem + */ +class Memory : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Memory() : detail::Wrapper() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_mem + * into the new Memory object. + */ + __CL_EXPLICIT_CONSTRUCTORS Memory(const cl_mem& memory) : detail::Wrapper(memory) { } + + /*! \brief Assignment operator from cl_mem - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseMemObject() on the value previously held by this instance. + */ + Memory& operator = (const cl_mem& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory(const Memory& mem) : detail::Wrapper(mem) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (const Memory &mem) + { + detail::Wrapper::operator=(mem); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory(Memory&& mem) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(mem)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (Memory &&mem) + { + detail::Wrapper::operator=(std::move(mem)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetMemObjectInfo(). + template + cl_int getInfo(cl_mem_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetMemObjectInfo, object_, name, param), + __GET_MEM_OBJECT_INFO_ERR); + } + + //! \brief Wrapper for clGetMemObjectInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_mem_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if defined(CL_VERSION_1_1) + /*! \brief Registers a callback function to be called when the memory object + * is no longer needed. + * + * Wraps clSetMemObjectDestructorCallback(). + * + * Repeated calls to this function, for a given cl_mem value, will append + * to the list of functions called (in reverse order) when memory object's + * resources are freed and the memory object is deleted. + * + * \note + * The registered callbacks are associated with the underlying cl_mem + * value - not the Memory class instance. + */ + cl_int setDestructorCallback( + void (CL_CALLBACK * pfn_notify)(cl_mem, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetMemObjectDestructorCallback( + object_, + pfn_notify, + user_data), + __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR); + } +#endif + +}; + +// Pre-declare copy functions +class Buffer; +template< typename IteratorType > +cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); + + +/*! \brief Class interface for Buffer Memory Objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Buffer : public Memory +{ +public: + + /*! \brief Constructs a Buffer in a specified context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + */ + Buffer( + const Context& context, + cl_mem_flags flags, + ::size_t size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a Buffer in the default context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + * + * \see Context::getDefault() + */ + Buffer( + cl_mem_flags flags, + ::size_t size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(err); + + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer( + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr = false, + cl_int* err = NULL) + { + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + ::size_t size = sizeof(DataType)*(endIterator - startIterator); + + Context context = Context::getDefault(err); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + error = cl::copy(startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified context. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified queue. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Buffer() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Buffer(const cl_mem& buffer) : Memory(buffer) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Buffer& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer(const Buffer& buf) : Memory(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (const Buffer &buf) + { + Memory::operator=(buf); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer(Buffer&& buf) CL_HPP_NOEXCEPT : Memory(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (Buffer &&buf) + { + Memory::operator=(std::move(buf)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + +#if defined(CL_VERSION_1_1) + /*! \brief Creates a new buffer object from this. + * + * Wraps clCreateSubBuffer(). + */ + Buffer createSubBuffer( + cl_mem_flags flags, + cl_buffer_create_type buffer_create_type, + const void * buffer_create_info, + cl_int * err = NULL) + { + Buffer result; + cl_int error; + result.object_ = ::clCreateSubBuffer( + object_, + flags, + buffer_create_type, + buffer_create_info, + &error); + + detail::errHandler(error, __CREATE_SUBBUFFER_ERR); + if (err != NULL) { + *err = error; + } + + return result; + } +#endif +}; + +#if defined (USE_DX_INTEROP) +/*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's. + * + * This is provided to facilitate interoperability with Direct3D. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferD3D10 : public Buffer +{ +public: + typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)( + cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer, + cl_int* errcode_ret); + + /*! \brief Constructs a BufferD3D10, in a specified context, from a + * given ID3D10Buffer. + * + * Wraps clCreateFromD3D10BufferKHR(). + */ + BufferD3D10( + const Context& context, + cl_mem_flags flags, + ID3D10Buffer* bufobj, + cl_int * err = NULL) + { + static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL; + +#if defined(CL_VERSION_1_2) + vector props = context.getInfo(); + cl_platform platform = -1; + for( int i = 0; i < props.size(); ++i ) { + if( props[i] == CL_CONTEXT_PLATFORM ) { + platform = props[i+1]; + } + } + __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clCreateFromD3D10BufferKHR); +#endif +#if defined(CL_VERSION_1_1) + __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR); +#endif + + cl_int error; + object_ = pfn_clCreateFromD3D10BufferKHR( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferD3D10() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS BufferD3D10(const cl_mem& buffer) : Buffer(buffer) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferD3D10& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(const BufferD3D10& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (const BufferD3D10 &buf) + { + Buffer::operator=(buf); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (BufferD3D10 &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif + +/*! \brief Class interface for GL Buffer Memory Objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferGL : public Buffer +{ +public: + /*! \brief Constructs a BufferGL in a specified context, from a given + * GL buffer. + * + * Wraps clCreateFromGLBuffer(). + */ + BufferGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLBuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferGL() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS BufferGL(const cl_mem& buffer) : Buffer(buffer) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferGL& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL(const BufferGL& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (const BufferGL &buf) + { + Buffer::operator=(buf); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (BufferGL &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_,type,gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief C++ base class for Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image : public Memory +{ +protected: + //! \brief Default constructor - initializes to NULL. + Image() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image(const cl_mem& image) : Memory(image) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image(const Image& img) : Memory(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (const Image &img) + { + Memory::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image(Image&& img) CL_HPP_NOEXCEPT : Memory(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (Image &&img) + { + Memory::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + +public: + //! \brief Wrapper for clGetImageInfo(). + template + cl_int getImageInfo(cl_image_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetImageInfo, object_, name, param), + __GET_IMAGE_INFO_ERR); + } + + //! \brief Wrapper for clGetImageInfo() that returns by value. + template typename + detail::param_traits::param_type + getImageInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_image_info, name>::param_type param; + cl_int result = getImageInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +#if defined(CL_VERSION_1_2) +/*! \brief Class interface for 1D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image1D : public Image +{ +public: + /*! \brief Constructs a 1D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image1D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D, + width, + 0, 0, 0, 0, 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image1D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image1D(const cl_mem& image1D) : Image(image1D) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image1D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D(const Image1D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (const Image1D &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D(Image1D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (Image1D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + +/*! \class Image1DBuffer + * \brief Image interface for 1D buffer images. + */ +class Image1DBuffer : public Image +{ +public: + Image1DBuffer( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + const Buffer &buffer, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_BUFFER, + width, + 0, 0, 0, 0, 0, 0, 0, + buffer() + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + NULL, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DBuffer() { } + + __CL_EXPLICIT_CONSTRUCTORS Image1DBuffer(const cl_mem& image1D) : Image(image1D) { } + + Image1DBuffer& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(const Image1DBuffer& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (const Image1DBuffer &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (Image1DBuffer &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + +/*! \class Image1DArray + * \brief Image interface for arrays of 1D images. + */ +class Image1DArray : public Image +{ +public: + Image1DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t arraySize, + ::size_t width, + ::size_t rowPitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_ARRAY, + width, + 0, 0, // height, depth (unused) + arraySize, + rowPitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DArray() { } + + __CL_EXPLICIT_CONSTRUCTORS Image1DArray(const cl_mem& imageArray) : Image(imageArray) { } + + Image1DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(const Image1DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (const Image1DArray &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (Image1DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if defined(CL_VERSION_1_2) + + +/*! \brief Class interface for 2D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image2D : public Image +{ +public: + /*! \brief Constructs a 1D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image2D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + ::size_t height, + ::size_t row_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif defined(CL_VERSION_1_2) + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if defined(CL_VERSION_1_2) + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D, + width, + height, + 0, 0, // depth, array size (unused) + row_pitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if defined(CL_VERSION_1_2) +#if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + if (!useCreateImage) + { + object_ = ::clCreateImage2D( + context(), flags,&format, width, height, row_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE2D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + } + + //! \brief Default constructor - initializes to NULL. + Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image2D(const cl_mem& image2D) : Image(image2D) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image2D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D(const Image2D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (const Image2D &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D(Image2D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (Image2D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + + +#if !defined(CL_VERSION_1_2) +/*! \brief Class interface for GL 2D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + * \note Deprecated for OpenCL 1.2. Please use ImageGL instead. + */ +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED : public Image2D +{ +public: + /*! \brief Constructs an Image2DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture2D(). + */ + Image2DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture2D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR); + if (err != NULL) { + *err = error; + } + + } + + //! \brief Default constructor - initializes to NULL. + Image2DGL() : Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image2DGL(const cl_mem& image) : Image2D(image) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image2DGL& operator = (const cl_mem& rhs) + { + Image2D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(const Image2DGL& img) : Image2D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (const Image2DGL &img) + { + Image2D::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT : Image2D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (Image2DGL &&img) + { + Image2D::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if !defined(CL_VERSION_1_2) + +#if defined(CL_VERSION_1_2) +/*! \class Image2DArray + * \brief Image interface for arrays of 2D images. + */ +class Image2DArray : public Image +{ +public: + Image2DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t arraySize, + ::size_t width, + ::size_t height, + ::size_t rowPitch, + ::size_t slicePitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D_ARRAY, + width, + height, + 0, // depth (unused) + arraySize, + rowPitch, + slicePitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image2DArray() { } + + __CL_EXPLICIT_CONSTRUCTORS Image2DArray(const cl_mem& imageArray) : Image(imageArray) { } + + Image2DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(const Image2DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (const Image2DArray &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (Image2DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if defined(CL_VERSION_1_2) + +/*! \brief Class interface for 3D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3D : public Image +{ +public: + /*! \brief Constructs a 3D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image3D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + ::size_t height, + ::size_t depth, + ::size_t row_pitch = 0, + ::size_t slice_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif defined(CL_VERSION_1_2) + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if defined(CL_VERSION_1_2) + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE3D, + width, + height, + depth, + 0, // array size (unused) + row_pitch, + slice_pitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if defined(CL_VERSION_1_2) +#if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + if (!useCreateImage) + { + object_ = ::clCreateImage3D( + context(), flags, &format, width, height, depth, row_pitch, + slice_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE3D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + } + + //! \brief Default constructor - initializes to NULL. + Image3D() : Image() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image3D(const cl_mem& image3D) : Image(image3D) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D(const Image3D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (const Image3D &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D(Image3D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (Image3D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + +#if !defined(CL_VERSION_1_2) +/*! \brief Class interface for GL 3D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3DGL : public Image3D +{ +public: + /*! \brief Constructs an Image3DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture3D(). + */ + Image3DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture3D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image3DGL() : Image3D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image3DGL(const cl_mem& image) : Image3D(image) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3DGL& operator = (const cl_mem& rhs) + { + Image3D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(const Image3DGL& img) : Image3D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (const Image3DGL &img) + { + Image3D::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT : Image3D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (Image3DGL &&img) + { + Image3D::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if !defined(CL_VERSION_1_2) + +#if defined(CL_VERSION_1_2) +/*! \class ImageGL + * \brief general image interface for GL interop. + * We abstract the 2D and 3D GL images into a single instance here + * that wraps all GL sourced images on the grounds that setup information + * was performed by OpenCL anyway. + */ +class ImageGL : public Image +{ +public: + ImageGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_ERR); + if (err != NULL) { + *err = error; + } + } + + ImageGL() : Image() { } + + __CL_EXPLICIT_CONSTRUCTORS ImageGL(const cl_mem& image) : Image(image) { } + + ImageGL& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL(const ImageGL& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (const ImageGL &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (ImageGL &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if defined(CL_VERSION_1_2) + +/*! \brief Class interface for GL Render Buffer Memory Objects. +* +* This is provided to facilitate interoperability with OpenGL. +* +* See Memory for details about copy semantics, etc. +* +* \see Memory +*/ +class BufferRenderGL : +#if defined(CL_VERSION_1_2) + public ImageGL +#else // #if defined(CL_VERSION_1_2) + public Image2DGL +#endif //#if defined(CL_VERSION_1_2) +{ +public: + /*! \brief Constructs a BufferRenderGL in a specified context, from a given + * GL Renderbuffer. + * + * Wraps clCreateFromGLRenderbuffer(). + */ + BufferRenderGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLRenderbuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. +#if defined(CL_VERSION_1_2) + BufferRenderGL() : ImageGL() {}; +#else // #if defined(CL_VERSION_1_2) + BufferRenderGL() : Image2DGL() {}; +#endif //#if defined(CL_VERSION_1_2) + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ +#if defined(CL_VERSION_1_2) + __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : ImageGL(buffer) { } +#else // #if defined(CL_VERSION_1_2) + __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : Image2DGL(buffer) { } +#endif //#if defined(CL_VERSION_1_2) + + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferRenderGL& operator = (const cl_mem& rhs) + { +#if defined(CL_VERSION_1_2) + ImageGL::operator=(rhs); +#else // #if defined(CL_VERSION_1_2) + Image2DGL::operator=(rhs); +#endif //#if defined(CL_VERSION_1_2) + + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ +#if defined(CL_VERSION_1_2) + BufferRenderGL(const BufferRenderGL& buf) : ImageGL(buf) {} +#else // #if defined(CL_VERSION_1_2) + BufferRenderGL(const BufferRenderGL& buf) : Image2DGL(buf) {} +#endif //#if defined(CL_VERSION_1_2) + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (const BufferRenderGL &rhs) + { +#if defined(CL_VERSION_1_2) + ImageGL::operator=(rhs); +#else // #if defined(CL_VERSION_1_2) + Image2DGL::operator=(rhs); +#endif //#if defined(CL_VERSION_1_2) + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ +#if defined(CL_VERSION_1_2) + BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : ImageGL(std::move(buf)) {} +#else // #if defined(CL_VERSION_1_2) + BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : Image2DGL(std::move(buf)) {} +#endif //#if defined(CL_VERSION_1_2) + + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (BufferRenderGL &&buf) + { +#if defined(CL_VERSION_1_2) + ImageGL::operator=(std::move(buf)); +#else // #if defined(CL_VERSION_1_2) + Image2DGL::operator=(std::move(buf)); +#endif //#if defined(CL_VERSION_1_2) + + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_, type, gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief Class interface for cl_sampler. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_sampler as the original. For details, see + * clRetainSampler() and clReleaseSampler(). + * + * \see cl_sampler + */ +class Sampler : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Sampler() { } + + /*! \brief Constructs a Sampler in a specified context. + * + * Wraps clCreateSampler(). + */ + Sampler( + const Context& context, + cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateSampler( + context(), + normalized_coords, + addressing_mode, + filter_mode, + &error); + + detail::errHandler(error, __CREATE_SAMPLER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructor from cl_sampler - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_sampler + * into the new Sampler object. + */ + __CL_EXPLICIT_CONSTRUCTORS Sampler(const cl_sampler& sampler) : detail::Wrapper(sampler) { } + + /*! \brief Assignment operator from cl_sampler - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseSampler() on the value previously held by this instance. + */ + Sampler& operator = (const cl_sampler& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler(const Sampler& sam) : detail::Wrapper(sam) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (const Sampler &sam) + { + detail::Wrapper::operator=(sam); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler(Sampler&& sam) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(sam)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (Sampler &&sam) + { + detail::Wrapper::operator=(std::move(sam)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetSamplerInfo(). + template + cl_int getInfo(cl_sampler_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetSamplerInfo, object_, name, param), + __GET_SAMPLER_INFO_ERR); + } + + //! \brief Wrapper for clGetSamplerInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_sampler_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +class Program; +class CommandQueue; +class Kernel; + +//! \brief Class interface for specifying NDRange values. +class NDRange +{ +private: + size_t<3> sizes_; + cl_uint dimensions_; + +public: + //! \brief Default constructor - resulting range has zero dimensions. + NDRange() + : dimensions_(0) + { } + + //! \brief Constructs one-dimensional range. + NDRange(::size_t size0) + : dimensions_(1) + { + sizes_[0] = size0; + } + + //! \brief Constructs two-dimensional range. + NDRange(::size_t size0, ::size_t size1) + : dimensions_(2) + { + sizes_[0] = size0; + sizes_[1] = size1; + } + + //! \brief Constructs three-dimensional range. + NDRange(::size_t size0, ::size_t size1, ::size_t size2) + : dimensions_(3) + { + sizes_[0] = size0; + sizes_[1] = size1; + sizes_[2] = size2; + } + + /*! \brief Conversion operator to const ::size_t *. + * + * \returns a pointer to the size of the first dimension. + */ + operator const ::size_t*() const { + return (const ::size_t*) sizes_; + } + + //! \brief Queries the number of dimensions in the range. + ::size_t dimensions() const { return dimensions_; } +}; + +//! \brief A zero-dimensional range. +static const NDRange NullRange; + +//! \brief Local address wrapper for use with Kernel::setArg +struct LocalSpaceArg +{ + ::size_t size_; +}; + +namespace detail { + +template +struct KernelArgumentHandler +{ + static ::size_t size(const T&) { return sizeof(T); } + static const T* ptr(const T& value) { return &value; } +}; + +template <> +struct KernelArgumentHandler +{ + static ::size_t size(const LocalSpaceArg& value) { return value.size_; } + static const void* ptr(const LocalSpaceArg&) { return NULL; } +}; + +} +//! \endcond + +/*! __local + * \brief Helper function for generating LocalSpaceArg objects. + * Deprecated. Replaced with Local. + */ +inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED LocalSpaceArg +__local(::size_t size) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +inline LocalSpaceArg +__local(::size_t size) +{ + LocalSpaceArg ret = { size }; + return ret; +} + +/*! Local + * \brief Helper function for generating LocalSpaceArg objects. + */ +inline LocalSpaceArg +Local(::size_t size) +{ + LocalSpaceArg ret = { size }; + return ret; +} + +//class KernelFunctor; + +/*! \brief Class interface for cl_kernel. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_kernel as the original. For details, see + * clRetainKernel() and clReleaseKernel(). + * + * \see cl_kernel + */ +class Kernel : public detail::Wrapper +{ +public: + inline Kernel(const Program& program, const char* name, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Kernel() { } + + /*! \brief Constructor from cl_kernel - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_kernel + * into the new Kernel object. + */ + __CL_EXPLICIT_CONSTRUCTORS Kernel(const cl_kernel& kernel) : detail::Wrapper(kernel) { } + + /*! \brief Assignment operator from cl_kernel - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseKernel() on the value previously held by this instance. + */ + Kernel& operator = (const cl_kernel& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel(const Kernel& kernel) : detail::Wrapper(kernel) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (const Kernel &kernel) + { + detail::Wrapper::operator=(kernel); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(kernel)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (Kernel &&kernel) + { + detail::Wrapper::operator=(std::move(kernel)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + template + cl_int getInfo(cl_kernel_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelInfo, object_, name, param), + __GET_KERNEL_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if defined(CL_VERSION_1_2) + template + cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param), + __GET_KERNEL_ARG_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getArgInfo(cl_uint argIndex, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_arg_info, name>::param_type param; + cl_int result = getArgInfo(argIndex, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +#endif // #if defined(CL_VERSION_1_2) + + template + cl_int getWorkGroupInfo( + const Device& device, cl_kernel_work_group_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetKernelWorkGroupInfo, object_, device(), name, param), + __GET_KERNEL_WORK_GROUP_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getWorkGroupInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_work_group_info, name>::param_type param; + cl_int result = getWorkGroupInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + template + cl_int setArg(cl_uint index, const T &value) + { + return detail::errHandler( + ::clSetKernelArg( + object_, + index, + detail::KernelArgumentHandler::size(value), + detail::KernelArgumentHandler::ptr(value)), + __SET_KERNEL_ARGS_ERR); + } + + cl_int setArg(cl_uint index, ::size_t size, const void* argPtr) + { + return detail::errHandler( + ::clSetKernelArg(object_, index, size, argPtr), + __SET_KERNEL_ARGS_ERR); + } +}; + +/*! \class Program + * \brief Program interface that implements cl_program. + */ +class Program : public detail::Wrapper +{ +public: + typedef VECTOR_CLASS > Binaries; + typedef VECTOR_CLASS > Sources; + + Program( + const STRING_CLASS& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const ::size_t length = source.size(); + + Context context = Context::getDefault(err); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + + error = ::clBuildProgram( + object_, + 0, + NULL, + "", + NULL, + NULL); + + detail::errHandler(error, __BUILD_PROGRAM_ERR); + } + + if (err != NULL) { + *err = error; + } + } + + Program( + const Context& context, + const STRING_CLASS& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const ::size_t length = source.size(); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + + error = ::clBuildProgram( + object_, + 0, + NULL, + "", + NULL, + NULL); + + detail::errHandler(error, __BUILD_PROGRAM_ERR); + } + + if (err != NULL) { + *err = error; + } + } + + Program( + const Context& context, + const Sources& sources, + cl_int* err = NULL) + { + cl_int error; + + const ::size_t n = (::size_t)sources.size(); + ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t)); + const char** strings = (const char**) alloca(n * sizeof(const char*)); + + for (::size_t i = 0; i < n; ++i) { + strings[i] = sources[(int)i].first; + lengths[i] = sources[(int)i].second; + } + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)n, strings, lengths, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + if (err != NULL) { + *err = error; + } + } + + /** + * Construct a program object from a list of devices and a per-device list of binaries. + * \param context A valid OpenCL context in which to construct the program. + * \param devices A vector of OpenCL device objects for which the program will be created. + * \param binaries A vector of pairs of a pointer to a binary object and its length. + * \param binaryStatus An optional vector that on completion will be resized to + * match the size of binaries and filled with values to specify if each binary + * was successfully loaded. + * Set to CL_SUCCESS if the binary was successfully loaded. + * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL. + * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device. + * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors: + * CL_INVALID_CONTEXT if context is not a valid context. + * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices; + * or if any entry in binaries is NULL or has length 0. + * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context. + * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device. + * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host. + */ + Program( + const Context& context, + const VECTOR_CLASS& devices, + const Binaries& binaries, + VECTOR_CLASS* binaryStatus = NULL, + cl_int* err = NULL) + { + cl_int error; + + const ::size_t numDevices = devices.size(); + + // Catch size mismatch early and return + if(binaries.size() != numDevices) { + error = CL_INVALID_VALUE; + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + ::size_t* lengths = (::size_t*) alloca(numDevices * sizeof(::size_t)); + const unsigned char** images = (const unsigned char**) alloca(numDevices * sizeof(const unsigned char**)); + + for (::size_t i = 0; i < numDevices; ++i) { + images[i] = (const unsigned char*)binaries[i].first; + lengths[i] = binaries[(int)i].second; + } + + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + if(binaryStatus) { + binaryStatus->resize(numDevices); + } + + object_ = ::clCreateProgramWithBinary( + context(), (cl_uint) devices.size(), + deviceIDs, + lengths, images, (binaryStatus != NULL && numDevices > 0) + ? &binaryStatus->front() + : NULL, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + } + + +#if defined(CL_VERSION_1_2) + /** + * Create program using builtin kernels. + * \param kernelNames Semi-colon separated list of builtin kernel names + */ + Program( + const Context& context, + const VECTOR_CLASS& devices, + const STRING_CLASS& kernelNames, + cl_int* err = NULL) + { + cl_int error; + + + ::size_t numDevices = devices.size(); + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateProgramWithBuiltInKernels( + context(), + (cl_uint) devices.size(), + deviceIDs, + kernelNames.c_str(), + &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if defined(CL_VERSION_1_2) + + Program() { } + + __CL_EXPLICIT_CONSTRUCTORS Program(const cl_program& program) : detail::Wrapper(program) { } + + Program& operator = (const cl_program& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program(const Program& program) : detail::Wrapper(program) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (const Program &program) + { + detail::Wrapper::operator=(program); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Program(Program&& program) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(program)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (Program &&program) + { + detail::Wrapper::operator=(std::move(program)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + cl_int build( + const VECTOR_CLASS& devices, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + ::size_t numDevices = devices.size(); + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + return detail::errHandler( + ::clBuildProgram( + object_, + (cl_uint) + devices.size(), + deviceIDs, + options, + notifyFptr, + data), + __BUILD_PROGRAM_ERR); + } + + cl_int build( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + return detail::errHandler( + ::clBuildProgram( + object_, + 0, + NULL, + options, + notifyFptr, + data), + __BUILD_PROGRAM_ERR); + } + +#if defined(CL_VERSION_1_2) + cl_int compile( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + return detail::errHandler( + ::clCompileProgram( + object_, + 0, + NULL, + options, + 0, + NULL, + NULL, + notifyFptr, + data), + __COMPILE_PROGRAM_ERR); + } +#endif + + template + cl_int getInfo(cl_program_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetProgramInfo, object_, name, param), + __GET_PROGRAM_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + template + cl_int getBuildInfo( + const Device& device, cl_program_build_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetProgramBuildInfo, object_, device(), name, param), + __GET_PROGRAM_BUILD_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getBuildInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_build_info, name>::param_type param; + cl_int result = getBuildInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + cl_int createKernels(VECTOR_CLASS* kernels) + { + cl_uint numKernels; + cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel)); + err = ::clCreateKernelsInProgram( + object_, numKernels, (cl_kernel*) value, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + kernels->assign(&value[0], &value[numKernels]); + return CL_SUCCESS; + } +}; + +#if defined(CL_VERSION_1_2) +inline Program linkProgram( + Program input1, + Program input2, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + cl_program programs[2] = { input1(), input2() }; + + Context ctx = input1.getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + 2, + programs, + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog); +} + +inline Program linkProgram( + VECTOR_CLASS inputPrograms, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + cl_program * programs = (cl_program*) alloca(inputPrograms.size() * sizeof(cl_program)); + + if (programs != NULL) { + for (unsigned int i = 0; i < inputPrograms.size(); i++) { + programs[i] = inputPrograms[i](); + } + } + + Context ctx; + if(inputPrograms.size() > 0) { + ctx = inputPrograms[0].getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + } + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + (cl_uint)inputPrograms.size(), + programs, + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog); +} +#endif + +template<> +inline VECTOR_CLASS cl::Program::getInfo(cl_int* err) const +{ + VECTOR_CLASS< ::size_t> sizes = getInfo(); + VECTOR_CLASS binaries; + for (VECTOR_CLASS< ::size_t>::iterator s = sizes.begin(); s != sizes.end(); ++s) + { + char *ptr = NULL; + if (*s != 0) + ptr = new char[*s]; + binaries.push_back(ptr); + } + + cl_int result = getInfo(CL_PROGRAM_BINARIES, &binaries); + if (err != NULL) { + *err = result; + } + return binaries; +} + +inline Kernel::Kernel(const Program& program, const char* name, cl_int* err) +{ + cl_int error; + + object_ = ::clCreateKernel(program(), name, &error); + detail::errHandler(error, __CREATE_KERNEL_ERR); + + if (err != NULL) { + *err = error; + } + +} + +/*! \class CommandQueue + * \brief CommandQueue interface for cl_command_queue. + */ +class CommandQueue : public detail::Wrapper +{ +private: +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + static std::atomic default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static volatile int default_initialized_; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static CommandQueue default_; + static volatile cl_int default_error_; +public: + CommandQueue( + cl_command_queue_properties properties, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } + } + } + /*! + * \brief Constructs a CommandQueue for an implementation defined device in the given context + */ + explicit CommandQueue( + const Context& context, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + VECTOR_CLASS devices; + error = context.getInfo(CL_CONTEXT_DEVICES, &devices); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) + { + if (err != NULL) { + *err = error; + } + return; + } + + object_ = ::clCreateCommandQueue(context(), devices[0](), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + + if (err != NULL) { + *err = error; + } + + } + + CommandQueue( + const Context& context, + const Device& device, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(const CommandQueue& queue) : detail::Wrapper(queue) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (const CommandQueue &queue) + { + detail::Wrapper::operator=(queue); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(queue)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (CommandQueue &&queue) + { + detail::Wrapper::operator=(std::move(queue)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + static CommandQueue getDefault(cl_int * err = NULL) + { + int state = detail::compare_exchange( + &default_initialized_, + __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED); + + if (state & __DEFAULT_INITIALIZED) { + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + if (state & __DEFAULT_BEING_INITIALIZED) { + // Assume writes will propagate eventually... + while(default_initialized_ != __DEFAULT_INITIALIZED) { + detail::fence(); + } + + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + + default_ = CommandQueue(context, device, 0, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } + } + + detail::fence(); + + default_error_ = error; + // Assume writes will propagate eventually... + default_initialized_ = __DEFAULT_INITIALIZED; + + detail::fence(); + + if (err != NULL) { + *err = default_error_; + } + return default_; + + } + + CommandQueue() { } + + __CL_EXPLICIT_CONSTRUCTORS CommandQueue(const cl_command_queue& commandQueue) : detail::Wrapper(commandQueue) { } + + CommandQueue& operator = (const cl_command_queue& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + template + cl_int getInfo(cl_command_queue_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetCommandQueueInfo, object_, name, param), + __GET_COMMAND_QUEUE_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_command_queue_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + ::size_t src_offset, + ::size_t dst_offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBuffer( + object_, src(), dst(), src_offset, dst_offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBufferRect( + object_, + buffer(), + blocking, + (const ::size_t *)buffer_offset, + (const ::size_t *)host_offset, + (const ::size_t *)region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + const void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBufferRect( + object_, + buffer(), + blocking, + (const ::size_t *)buffer_offset, + (const ::size_t *)host_offset, + (const ::size_t *)region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + ::size_t src_row_pitch, + ::size_t src_slice_pitch, + ::size_t dst_row_pitch, + ::size_t dst_slice_pitch, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferRect( + object_, + src(), + dst(), + (const ::size_t *)src_origin, + (const ::size_t *)dst_origin, + (const ::size_t *)region, + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_VERSION_1_2) + /** + * Enqueue a command to fill a buffer object with a pattern + * of a given size. The pattern is specified a as vector. + * \tparam PatternType The datatype of the pattern field. + * The pattern type must be an accepted OpenCL data type. + */ + template + cl_int enqueueFillBuffer( + const Buffer& buffer, + PatternType pattern, + ::size_t offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillBuffer( + object_, + buffer(), + static_cast(&pattern), + sizeof(PatternType), + offset, + size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_VERSION_1_2) + + cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadImage( + object_, image(), blocking, (const ::size_t *) origin, + (const ::size_t *) region, row_pitch, slice_pitch, ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteImage( + object_, image(), blocking, (const ::size_t *) origin, + (const ::size_t *) region, row_pitch, slice_pitch, ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImage( + object_, src(), dst(), (const ::size_t *) src_origin, + (const ::size_t *)dst_origin, (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_VERSION_1_2) + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA floating-point color value if + * the image channel data type is not an unnormalized signed or + * unsigned data type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_float4 fillColor, + const size_t<3>& origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + (const ::size_t *) origin, + (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA signed integer color value if + * the image channel data type is an unnormalized signed integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_int4 fillColor, + const size_t<3>& origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + (const ::size_t *) origin, + (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA unsigned integer color value if + * the image channel data type is an unnormalized unsigned integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_uint4 fillColor, + const size_t<3>& origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + (const ::size_t *) origin, + (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_VERSION_1_2) + + cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& region, + ::size_t dst_offset, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImageToBuffer( + object_, src(), dst(), (const ::size_t *) src_origin, + (const ::size_t *) region, dst_offset, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + ::size_t src_offset, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferToImage( + object_, src(), dst(), src_offset, + (const ::size_t *) dst_origin, (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + ::size_t offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapBuffer( + object_, buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + + return result; + } + + void* enqueueMapImage( + const Image& buffer, + cl_bool blocking, + cl_map_flags flags, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t * row_pitch, + ::size_t * slice_pitch, + const VECTOR_CLASS* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapImage( + object_, buffer(), blocking, flags, + (const ::size_t *) origin, (const ::size_t *) region, + row_pitch, slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + return result; + } + + cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + object_, memory(), mapped_ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_VERSION_1_2) + /** + * Enqueues a marker command which waits for either a list of events to complete, + * or all previously enqueued commands to complete. + * + * Enqueues a marker command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command returns an event which can be waited on, + * i.e. this event can be waited on to insure that all events either in the event_wait_list + * or all previously enqueued commands, queued before this command to command_queue, + * have completed. + */ + cl_int enqueueMarkerWithWaitList( + const VECTOR_CLASS *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarkerWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * A synchronization point that enqueues a barrier operation. + * + * Enqueues a barrier command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command blocks command execution, that is, any + * following commands enqueued after it do not execute until it completes. This command + * returns an event which can be waited on, i.e. this event can be waited on to insure that + * all events either in the event_wait_list or all previously enqueued commands, queued + * before this command to command_queue, have completed. + */ + cl_int enqueueBarrierWithWaitList( + const VECTOR_CLASS *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueBarrierWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_BARRIER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command to indicate with which device a set of memory objects + * should be associated. + */ + cl_int enqueueMigrateMemObjects( + const VECTOR_CLASS &memObjects, + cl_mem_migration_flags flags, + const VECTOR_CLASS* events = NULL, + Event* event = NULL + ) const + { + cl_event tmp; + + cl_mem* localMemObjects = static_cast(alloca(memObjects.size() * sizeof(cl_mem))); + for( int i = 0; i < (int)memObjects.size(); ++i ) { + localMemObjects[i] = memObjects[i](); + } + + + cl_int err = detail::errHandler( + ::clEnqueueMigrateMemObjects( + object_, + (cl_uint)memObjects.size(), + static_cast(localMemObjects), + flags, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_VERSION_1_2) + + cl_int enqueueNDRangeKernel( + const Kernel& kernel, + const NDRange& offset, + const NDRange& global, + const NDRange& local = NullRange, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNDRangeKernel( + object_, kernel(), (cl_uint) global.dimensions(), + offset.dimensions() != 0 ? (const ::size_t*) offset : NULL, + (const ::size_t*) global, + local.dimensions() != 0 ? (const ::size_t*) local : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NDRANGE_KERNEL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueTask( + const Kernel& kernel, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueTask( + object_, kernel(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_TASK_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueNativeKernel( + void (CL_CALLBACK *userFptr)(void *), + std::pair args, + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* mem_locs = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_mem * mems = (mem_objects != NULL && mem_objects->size() > 0) + ? (cl_mem*) alloca(mem_objects->size() * sizeof(cl_mem)) + : NULL; + + if (mems != NULL) { + for (unsigned int i = 0; i < mem_objects->size(); i++) { + mems[i] = ((*mem_objects)[i])(); + } + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNativeKernel( + object_, userFptr, args.first, args.second, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + mems, + (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NATIVE_KERNEL); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarker( + object_, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueWaitForEvents(const VECTOR_CLASS& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueWaitForEvents( + object_, + (cl_uint) events.size(), + events.size() > 0 ? (const cl_event*) &events.front() : NULL), + __ENQUEUE_WAIT_FOR_EVENTS_ERR); + } +#endif // #if defined(CL_VERSION_1_1) + + cl_int enqueueAcquireGLObjects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueAcquireGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseGLObjects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReleaseGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined (USE_DX_INTEROP) +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); + + cl_int enqueueAcquireD3D10Objects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL; +#if defined(CL_VERSION_1_2) + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueAcquireD3D10ObjectsKHR); +#endif +#if defined(CL_VERSION_1_1) + __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR); +#endif + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueAcquireD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseD3D10Objects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL; +#if defined(CL_VERSION_1_2) + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueReleaseD3D10ObjectsKHR); +#endif // #if defined(CL_VERSION_1_2) +#if defined(CL_VERSION_1_1) + __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR); +#endif // #if defined(CL_VERSION_1_1) + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueReleaseD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueBarrier(object_), + __ENQUEUE_BARRIER_ERR); + } +#endif // #if defined(CL_VERSION_1_1) + + cl_int flush() const + { + return detail::errHandler(::clFlush(object_), __FLUSH_ERR); + } + + cl_int finish() const + { + return detail::errHandler(::clFinish(object_), __FINISH_ERR); + } +}; + +#ifdef _WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) std::atomic CommandQueue::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) CommandQueue CommandQueue::default_; +__declspec(selectany) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS; +#else // !_WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) std::atomic CommandQueue::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) CommandQueue CommandQueue::default_; +__attribute__((weak)) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS; +#endif // !_WIN32 + +template< typename IteratorType > +Buffer::Buffer( + const Context &context, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + ::size_t size = sizeof(DataType)*(endIterator - startIterator); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + CommandQueue queue(context, 0, &error); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +template< typename IteratorType > +Buffer::Buffer( + const CommandQueue &queue, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if (readOnly) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + } + + ::size_t size = sizeof(DataType)*(endIterator - startIterator); + + Context context = queue.getInfo(); + + if (useHostPtr) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } + else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if (!useHostPtr) { + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +inline cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + ::size_t offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL, + cl_int* err = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + void * result = ::clEnqueueMapBuffer( + queue(), buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (cl_event*) event, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + return result; +} + +inline cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (error != CL_SUCCESS) { + return error; + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + queue(), memory(), mapped_ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; +} + +inline cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + ::size_t src_offset, + ::size_t dst_offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, startIterator, endIterator, buffer); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, buffer, startIterator, endIterator); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + ::size_t length = endIterator-startIterator; + ::size_t byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } +#if defined(_MSC_VER) + std::copy( + startIterator, + endIterator, + stdext::checked_array_iterator( + pointer, length)); +#else + std::copy(startIterator, endIterator, pointer); +#endif + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + ::size_t length = endIterator-startIterator; + ::size_t byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } + std::copy(pointer, pointer + length, startIterator); + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + +#if defined(CL_VERSION_1_1) +inline cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + const void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + ::size_t src_row_pitch, + ::size_t src_slice_pitch, + ::size_t dst_row_pitch, + ::size_t dst_slice_pitch, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferRect( + src, + dst, + src_origin, + dst_origin, + region, + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + events, + event); +} +#endif + +inline cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImage( + src, + dst, + src_origin, + dst_origin, + region, + events, + event); +} + +inline cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& region, + ::size_t dst_offset, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImageToBuffer( + src, + dst, + src_origin, + region, + dst_offset, + events, + event); +} + +inline cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + ::size_t src_offset, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferToImage( + src, + dst, + src_offset, + dst_origin, + region, + events, + event); +} + + +inline cl_int flush(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.flush(); +} + +inline cl_int finish(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + + return queue.finish(); +} + +// Kernel Functor support +// New interface as of September 2011 +// Requires the C++11 std::tr1::function (note do not support TR1) +// Visual Studio 2010 and GCC 4.2 + +struct EnqueueArgs +{ + CommandQueue queue_; + const NDRange offset_; + const NDRange global_; + const NDRange local_; + VECTOR_CLASS events_; + + EnqueueArgs(NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(Event e, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(const VECTOR_CLASS &events, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(const VECTOR_CLASS &events, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(const VECTOR_CLASS &events, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } +}; + +namespace detail { + +class NullType {}; + +template +struct SetArg +{ + static void set (Kernel kernel, T0 arg) + { + kernel.setArg(index, arg); + } +}; + +template +struct SetArg +{ + static void set (Kernel, NullType) + { + } +}; + +template < + typename T0, typename T1, typename T2, typename T3, + typename T4, typename T5, typename T6, typename T7, + typename T8, typename T9, typename T10, typename T11, + typename T12, typename T13, typename T14, typename T15, + typename T16, typename T17, typename T18, typename T19, + typename T20, typename T21, typename T22, typename T23, + typename T24, typename T25, typename T26, typename T27, + typename T28, typename T29, typename T30, typename T31 + +> +class KernelFunctorGlobal +{ +private: + Kernel kernel_; + +public: + KernelFunctorGlobal( + Kernel kernel) : + kernel_(kernel) + {} + + KernelFunctorGlobal( + const Program& program, + const STRING_CLASS name, + cl_int * err = NULL) : + kernel_(program, name.c_str(), err) + {} + + Event operator() ( + const EnqueueArgs& args, + T0 t0, + T1 t1 = NullType(), + T2 t2 = NullType(), + T3 t3 = NullType(), + T4 t4 = NullType(), + T5 t5 = NullType(), + T6 t6 = NullType(), + T7 t7 = NullType(), + T8 t8 = NullType(), + T9 t9 = NullType(), + T10 t10 = NullType(), + T11 t11 = NullType(), + T12 t12 = NullType(), + T13 t13 = NullType(), + T14 t14 = NullType(), + T15 t15 = NullType(), + T16 t16 = NullType(), + T17 t17 = NullType(), + T18 t18 = NullType(), + T19 t19 = NullType(), + T20 t20 = NullType(), + T21 t21 = NullType(), + T22 t22 = NullType(), + T23 t23 = NullType(), + T24 t24 = NullType(), + T25 t25 = NullType(), + T26 t26 = NullType(), + T27 t27 = NullType(), + T28 t28 = NullType(), + T29 t29 = NullType(), + T30 t30 = NullType(), + T31 t31 = NullType() + + ) + { + Event event; + SetArg<0, T0>::set(kernel_, t0); + SetArg<1, T1>::set(kernel_, t1); + SetArg<2, T2>::set(kernel_, t2); + SetArg<3, T3>::set(kernel_, t3); + SetArg<4, T4>::set(kernel_, t4); + SetArg<5, T5>::set(kernel_, t5); + SetArg<6, T6>::set(kernel_, t6); + SetArg<7, T7>::set(kernel_, t7); + SetArg<8, T8>::set(kernel_, t8); + SetArg<9, T9>::set(kernel_, t9); + SetArg<10, T10>::set(kernel_, t10); + SetArg<11, T11>::set(kernel_, t11); + SetArg<12, T12>::set(kernel_, t12); + SetArg<13, T13>::set(kernel_, t13); + SetArg<14, T14>::set(kernel_, t14); + SetArg<15, T15>::set(kernel_, t15); + SetArg<16, T16>::set(kernel_, t16); + SetArg<17, T17>::set(kernel_, t17); + SetArg<18, T18>::set(kernel_, t18); + SetArg<19, T19>::set(kernel_, t19); + SetArg<20, T20>::set(kernel_, t20); + SetArg<21, T21>::set(kernel_, t21); + SetArg<22, T22>::set(kernel_, t22); + SetArg<23, T23>::set(kernel_, t23); + SetArg<24, T24>::set(kernel_, t24); + SetArg<25, T25>::set(kernel_, t25); + SetArg<26, T26>::set(kernel_, t26); + SetArg<27, T27>::set(kernel_, t27); + SetArg<28, T28>::set(kernel_, t28); + SetArg<29, T29>::set(kernel_, t29); + SetArg<30, T30>::set(kernel_, t30); + SetArg<31, T31>::set(kernel_, t31); + + + args.queue_.enqueueNDRangeKernel( + kernel_, + args.offset_, + args.global_, + args.local_, + &args.events_, + &event); + + return event; + } + +}; + +//------------------------------------------------------------------------------------------------------ + + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28, + typename T29, + typename T30, + typename T31> +struct functionImplementation_ +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + T31> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 32)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + T31); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28, + T29 arg29, + T30 arg30, + T31 arg31) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28, + arg29, + arg30, + arg31); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28, + typename T29, + typename T30> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 31)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28, + T29 arg29, + T30 arg30) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28, + arg29, + arg30); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28, + typename T29> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 30)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28, + T29 arg29) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28, + arg29); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 29)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 28)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 27)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 26)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 25)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 24)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 23)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 22)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 21)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 20)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 19)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 18)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 17)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 16)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 15)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 14)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 13)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 12)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 11)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 10)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 9)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 8)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 7)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 6)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 5)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 4)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3); + } + + +}; + +template< + typename T0, + typename T1, + typename T2> +struct functionImplementation_ +< T0, + T1, + T2, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 3)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2); + } + + +}; + +template< + typename T0, + typename T1> +struct functionImplementation_ +< T0, + T1, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 2)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1) + { + return functor_( + enqueueArgs, + arg0, + arg1); + } + + +}; + +template< + typename T0> +struct functionImplementation_ +< T0, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 1)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0) + { + return functor_( + enqueueArgs, + arg0); + } + + +}; + + + + + +} // namespace detail + +//---------------------------------------------------------------------------------------------- + +template < + typename T0, typename T1 = detail::NullType, typename T2 = detail::NullType, + typename T3 = detail::NullType, typename T4 = detail::NullType, + typename T5 = detail::NullType, typename T6 = detail::NullType, + typename T7 = detail::NullType, typename T8 = detail::NullType, + typename T9 = detail::NullType, typename T10 = detail::NullType, + typename T11 = detail::NullType, typename T12 = detail::NullType, + typename T13 = detail::NullType, typename T14 = detail::NullType, + typename T15 = detail::NullType, typename T16 = detail::NullType, + typename T17 = detail::NullType, typename T18 = detail::NullType, + typename T19 = detail::NullType, typename T20 = detail::NullType, + typename T21 = detail::NullType, typename T22 = detail::NullType, + typename T23 = detail::NullType, typename T24 = detail::NullType, + typename T25 = detail::NullType, typename T26 = detail::NullType, + typename T27 = detail::NullType, typename T28 = detail::NullType, + typename T29 = detail::NullType, typename T30 = detail::NullType, + typename T31 = detail::NullType + +> +struct make_kernel : + public detail::functionImplementation_< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + > +{ +public: + typedef detail::KernelFunctorGlobal< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + > FunctorType; + + make_kernel( + const Program& program, + const STRING_CLASS name, + cl_int * err = NULL) : + detail::functionImplementation_< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + >( + FunctorType(program, name, err)) + {} + + make_kernel( + const Kernel kernel) : + detail::functionImplementation_< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + >( + FunctorType(kernel)) + {} +}; + + +//---------------------------------------------------------------------------------------------------------------------- + +#undef __ERR_STR +#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS) +#undef __GET_DEVICE_INFO_ERR +#undef __GET_PLATFORM_INFO_ERR +#undef __GET_DEVICE_IDS_ERR +#undef __GET_CONTEXT_INFO_ERR +#undef __GET_EVENT_INFO_ERR +#undef __GET_EVENT_PROFILE_INFO_ERR +#undef __GET_MEM_OBJECT_INFO_ERR +#undef __GET_IMAGE_INFO_ERR +#undef __GET_SAMPLER_INFO_ERR +#undef __GET_KERNEL_INFO_ERR +#undef __GET_KERNEL_ARG_INFO_ERR +#undef __GET_KERNEL_WORK_GROUP_INFO_ERR +#undef __GET_PROGRAM_INFO_ERR +#undef __GET_PROGRAM_BUILD_INFO_ERR +#undef __GET_COMMAND_QUEUE_INFO_ERR + +#undef __CREATE_CONTEXT_ERR +#undef __CREATE_CONTEXT_FROM_TYPE_ERR +#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR + +#undef __CREATE_BUFFER_ERR +#undef __CREATE_SUBBUFFER_ERR +#undef __CREATE_IMAGE2D_ERR +#undef __CREATE_IMAGE3D_ERR +#undef __CREATE_SAMPLER_ERR +#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR + +#undef __CREATE_USER_EVENT_ERR +#undef __SET_USER_EVENT_STATUS_ERR +#undef __SET_EVENT_CALLBACK_ERR +#undef __SET_PRINTF_CALLBACK_ERR + +#undef __WAIT_FOR_EVENTS_ERR + +#undef __CREATE_KERNEL_ERR +#undef __SET_KERNEL_ARGS_ERR +#undef __CREATE_PROGRAM_WITH_SOURCE_ERR +#undef __CREATE_PROGRAM_WITH_BINARY_ERR +#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR +#undef __BUILD_PROGRAM_ERR +#undef __CREATE_KERNELS_IN_PROGRAM_ERR + +#undef __CREATE_COMMAND_QUEUE_ERR +#undef __SET_COMMAND_QUEUE_PROPERTY_ERR +#undef __ENQUEUE_READ_BUFFER_ERR +#undef __ENQUEUE_WRITE_BUFFER_ERR +#undef __ENQUEUE_READ_BUFFER_RECT_ERR +#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR +#undef __ENQEUE_COPY_BUFFER_ERR +#undef __ENQEUE_COPY_BUFFER_RECT_ERR +#undef __ENQUEUE_READ_IMAGE_ERR +#undef __ENQUEUE_WRITE_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR +#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR +#undef __ENQUEUE_MAP_BUFFER_ERR +#undef __ENQUEUE_MAP_IMAGE_ERR +#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR +#undef __ENQUEUE_NDRANGE_KERNEL_ERR +#undef __ENQUEUE_TASK_ERR +#undef __ENQUEUE_NATIVE_KERNEL + +#undef __CL_EXPLICIT_CONSTRUCTORS + +#undef __UNLOAD_COMPILER_ERR +#endif //__CL_USER_OVERRIDE_ERROR_STRINGS + +#undef __CL_FUNCTION_TYPE + +// Extensions +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_VERSION_1_1) +#undef __INIT_CL_EXT_FCN_PTR +#endif // #if defined(CL_VERSION_1_1) +#undef __CREATE_SUB_DEVICES + +#if defined(USE_CL_DEVICE_FISSION) +#undef __PARAM_NAME_DEVICE_FISSION +#endif // USE_CL_DEVICE_FISSION + +#undef __DEFAULT_NOT_INITIALIZED +#undef __DEFAULT_BEING_INITIALIZED +#undef __DEFAULT_INITIALIZED + +#undef CL_HPP_RVALUE_REFERENCES_SUPPORTED +#undef CL_HPP_NOEXCEPT + +} // namespace cl + +#endif // CL_HPP_ diff --git a/opencl/khronos/headers/opencl1.2/CL/cl_d3d10.h b/opencl/khronos/headers/opencl1.2/CL/cl_d3d10.h new file mode 100644 index 0000000000..d5960a43f7 --- /dev/null +++ b/opencl/khronos/headers/opencl1.2/CL/cl_d3d10.h @@ -0,0 +1,131 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_CL_D3D10_H +#define __OPENCL_CL_D3D10_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * cl_khr_d3d10_sharing */ +#define cl_khr_d3d10_sharing 1 + +typedef cl_uint cl_d3d10_device_source_khr; +typedef cl_uint cl_d3d10_device_set_khr; + +/******************************************************************************/ + +/* Error Codes */ +#define CL_INVALID_D3D10_DEVICE_KHR -1002 +#define CL_INVALID_D3D10_RESOURCE_KHR -1003 +#define CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR -1004 +#define CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR -1005 + +/* cl_d3d10_device_source_nv */ +#define CL_D3D10_DEVICE_KHR 0x4010 +#define CL_D3D10_DXGI_ADAPTER_KHR 0x4011 + +/* cl_d3d10_device_set_nv */ +#define CL_PREFERRED_DEVICES_FOR_D3D10_KHR 0x4012 +#define CL_ALL_DEVICES_FOR_D3D10_KHR 0x4013 + +/* cl_context_info */ +#define CL_CONTEXT_D3D10_DEVICE_KHR 0x4014 +#define CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR 0x402C + +/* cl_mem_info */ +#define CL_MEM_D3D10_RESOURCE_KHR 0x4015 + +/* cl_image_info */ +#define CL_IMAGE_D3D10_SUBRESOURCE_KHR 0x4016 + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR 0x4017 +#define CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR 0x4018 + +/******************************************************************************/ + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D10KHR_fn)( + cl_platform_id platform, + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10BufferKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D10Buffer * resource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture2DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D10Texture2D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture3DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D10Texture3D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D10ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_D3D10_H */ + diff --git a/opencl/khronos/headers/opencl1.2/CL/cl_d3d11.h b/opencl/khronos/headers/opencl1.2/CL/cl_d3d11.h new file mode 100644 index 0000000000..39f9072398 --- /dev/null +++ b/opencl/khronos/headers/opencl1.2/CL/cl_d3d11.h @@ -0,0 +1,131 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_CL_D3D11_H +#define __OPENCL_CL_D3D11_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * cl_khr_d3d11_sharing */ +#define cl_khr_d3d11_sharing 1 + +typedef cl_uint cl_d3d11_device_source_khr; +typedef cl_uint cl_d3d11_device_set_khr; + +/******************************************************************************/ + +/* Error Codes */ +#define CL_INVALID_D3D11_DEVICE_KHR -1006 +#define CL_INVALID_D3D11_RESOURCE_KHR -1007 +#define CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR -1008 +#define CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR -1009 + +/* cl_d3d11_device_source */ +#define CL_D3D11_DEVICE_KHR 0x4019 +#define CL_D3D11_DXGI_ADAPTER_KHR 0x401A + +/* cl_d3d11_device_set */ +#define CL_PREFERRED_DEVICES_FOR_D3D11_KHR 0x401B +#define CL_ALL_DEVICES_FOR_D3D11_KHR 0x401C + +/* cl_context_info */ +#define CL_CONTEXT_D3D11_DEVICE_KHR 0x401D +#define CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR 0x402D + +/* cl_mem_info */ +#define CL_MEM_D3D11_RESOURCE_KHR 0x401E + +/* cl_image_info */ +#define CL_IMAGE_D3D11_SUBRESOURCE_KHR 0x401F + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR 0x4020 +#define CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR 0x4021 + +/******************************************************************************/ + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D11KHR_fn)( + cl_platform_id platform, + cl_d3d11_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d11_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11BufferKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D11Buffer * resource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture2DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D11Texture2D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture3DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D11Texture3D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D11ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_D3D11_H */ + diff --git a/opencl/khronos/headers/opencl1.2/CL/cl_dx9_media_sharing.h b/opencl/khronos/headers/opencl1.2/CL/cl_dx9_media_sharing.h new file mode 100644 index 0000000000..7c217b880a --- /dev/null +++ b/opencl/khronos/headers/opencl1.2/CL/cl_dx9_media_sharing.h @@ -0,0 +1,132 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_CL_DX9_MEDIA_SHARING_H +#define __OPENCL_CL_DX9_MEDIA_SHARING_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** +/* cl_khr_dx9_media_sharing */ +#define cl_khr_dx9_media_sharing 1 + +typedef cl_uint cl_dx9_media_adapter_type_khr; +typedef cl_uint cl_dx9_media_adapter_set_khr; + +#if defined(_WIN32) +#include +typedef struct _cl_dx9_surface_info_khr +{ + IDirect3DSurface9 *resource; + HANDLE shared_handle; +} cl_dx9_surface_info_khr; +#endif + + +/******************************************************************************/ + +/* Error Codes */ +#define CL_INVALID_DX9_MEDIA_ADAPTER_KHR -1010 +#define CL_INVALID_DX9_MEDIA_SURFACE_KHR -1011 +#define CL_DX9_MEDIA_SURFACE_ALREADY_ACQUIRED_KHR -1012 +#define CL_DX9_MEDIA_SURFACE_NOT_ACQUIRED_KHR -1013 + +/* cl_media_adapter_type_khr */ +#define CL_ADAPTER_D3D9_KHR 0x2020 +#define CL_ADAPTER_D3D9EX_KHR 0x2021 +#define CL_ADAPTER_DXVA_KHR 0x2022 + +/* cl_media_adapter_set_khr */ +#define CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2023 +#define CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2024 + +/* cl_context_info */ +#define CL_CONTEXT_ADAPTER_D3D9_KHR 0x2025 +#define CL_CONTEXT_ADAPTER_D3D9EX_KHR 0x2026 +#define CL_CONTEXT_ADAPTER_DXVA_KHR 0x2027 + +/* cl_mem_info */ +#define CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR 0x2028 +#define CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR 0x2029 + +/* cl_image_info */ +#define CL_IMAGE_DX9_MEDIA_PLANE_KHR 0x202A + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR 0x202B +#define CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR 0x202C + +/******************************************************************************/ + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromDX9MediaAdapterKHR_fn)( + cl_platform_id platform, + cl_uint num_media_adapters, + cl_dx9_media_adapter_type_khr * media_adapter_type, + void * media_adapters, + cl_dx9_media_adapter_set_khr media_adapter_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)( + cl_context context, + cl_mem_flags flags, + cl_dx9_media_adapter_type_khr adapter_type, + void * surface_info, + cl_uint plane, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9MediaSurfacesKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_DX9_MEDIA_SHARING_H */ + diff --git a/opencl/khronos/headers/opencl1.2/CL/cl_ext.h b/opencl/khronos/headers/opencl1.2/CL/cl_ext.h new file mode 100644 index 0000000000..08d00129de --- /dev/null +++ b/opencl/khronos/headers/opencl1.2/CL/cl_ext.h @@ -0,0 +1,661 @@ +/* Modifications Copyright (C) 2010-2021 Advanced Micro Devices, Inc. */ +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +/* $Revision: 11928 $ on $Date: 2010-07-13 09:04:56 -0700 (Tue, 13 Jul 2010) $ */ + +/* cl_ext.h contains OpenCL extensions which don't have external */ +/* (OpenGL, D3D) dependencies. */ + +#ifndef __CL_EXT_H +#define __CL_EXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __APPLE__ + #include + #include +#else + #include +#endif + +/* cl_khr_fp16 extension - no extension #define since it has no functions */ +#define CL_DEVICE_HALF_FP_CONFIG 0x1033 + +/* Memory object destruction + * + * Apple extension for use to manage externally allocated buffers used with cl_mem objects with CL_MEM_USE_HOST_PTR + * + * Registers a user callback function that will be called when the memory object is deleted and its resources + * freed. Each call to clSetMemObjectCallbackFn registers the specified user callback function on a callback + * stack associated with memobj. The registered user callback functions are called in the reverse order in + * which they were registered. The user callback functions are called and then the memory object is deleted + * and its resources freed. This provides a mechanism for the application (and libraries) using memobj to be + * notified when the memory referenced by host_ptr, specified when the memory object is created and used as + * the storage bits for the memory object, can be reused or freed. + * + * The application may not call CL api's with the cl_mem object passed to the pfn_notify. + * + * Please check for the "cl_APPLE_SetMemObjectDestructor" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) + * before using. + */ +#define cl_APPLE_SetMemObjectDestructor 1 +cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE( cl_mem /* memobj */, + void (* /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), + void * /*user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; + + +/* Context Logging Functions + * + * The next three convenience functions are intended to be used as the pfn_notify parameter to clCreateContext(). + * Please check for the "cl_APPLE_ContextLoggingFunctions" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) + * before using. + * + * clLogMessagesToSystemLog fowards on all log messages to the Apple System Logger + */ +#define cl_APPLE_ContextLoggingFunctions 1 +extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE( const char * /* errstr */, + const void * /* private_info */, + size_t /* cb */, + void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; + +/* clLogMessagesToStdout sends all log messages to the file descriptor stdout */ +extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE( const char * /* errstr */, + const void * /* private_info */, + size_t /* cb */, + void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; + +/* clLogMessagesToStderr sends all log messages to the file descriptor stderr */ +extern void CL_API_ENTRY clLogMessagesToStderrAPPLE( const char * /* errstr */, + const void * /* private_info */, + size_t /* cb */, + void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; + + +/************************ +* cl_khr_icd extension * +************************/ +#define cl_khr_icd 1 + +/* cl_platform_info */ +#define CL_PLATFORM_ICD_SUFFIX_KHR 0x0920 + +/* Additional Error Codes */ +#define CL_PLATFORM_NOT_FOUND_KHR -1001 + +extern CL_API_ENTRY cl_int CL_API_CALL +clIcdGetPlatformIDsKHR(cl_uint /* num_entries */, + cl_platform_id * /* platforms */, + cl_uint * /* num_platforms */); + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clIcdGetPlatformIDsKHR_fn)( + cl_uint /* num_entries */, + cl_platform_id * /* platforms */, + cl_uint * /* num_platforms */); + + +/* Extension: cl_khr_image2D_buffer + * + * This extension allows a 2D image to be created from a cl_mem buffer without a copy. + * The type associated with a 2D image created from a buffer in an OpenCL program is image2d_t. + * Both the sampler and sampler-less read_image built-in functions are supported for 2D images + * and 2D images created from a buffer. Similarly, the write_image built-ins are also supported + * for 2D images created from a buffer. + * + * When the 2D image from buffer is created, the client must specify the width, + * height, image format (i.e. channel order and channel data type) and optionally the row pitch + * + * The pitch specified must be a multiple of CL_DEVICE_IMAGE_PITCH_ALIGNMENT pixels. + * The base address of the buffer must be aligned to CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT pixels. + */ + +/************************************* + * cl_khr_initalize_memory extension * + *************************************/ + +#define CL_CONTEXT_MEMORY_INITIALIZE_KHR 0x200E + + +/************************************** + * cl_khr_terminate_context extension * + **************************************/ + +#define CL_DEVICE_TERMINATE_CAPABILITY_KHR 0x200F +#define CL_CONTEXT_TERMINATE_KHR 0x2010 + +#define cl_khr_terminate_context 1 +extern CL_API_ENTRY cl_int CL_API_CALL clTerminateContextKHR(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clTerminateContextKHR_fn)(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; + + +/* + * Extension: cl_khr_spir + * + * This extension adds support to create an OpenCL program object from a + * Standard Portable Intermediate Representation (SPIR) instance + */ + +#define CL_DEVICE_SPIR_VERSIONS 0x40E0 +#define CL_PROGRAM_BINARY_TYPE_INTERMEDIATE 0x40E1 + + +/****************************************** +* cl_nv_device_attribute_query extension * +******************************************/ +/* cl_nv_device_attribute_query extension - no extension #define since it has no functions */ +#define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 +#define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 +#define CL_DEVICE_REGISTERS_PER_BLOCK_NV 0x4002 +#define CL_DEVICE_WARP_SIZE_NV 0x4003 +#define CL_DEVICE_GPU_OVERLAP_NV 0x4004 +#define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 +#define CL_DEVICE_INTEGRATED_MEMORY_NV 0x4006 + +/********************************* +* cl_amd_device_memory_flags * +*********************************/ +#define cl_amd_device_memory_flags 1 +#define CL_MEM_USE_PERSISTENT_MEM_AMD (1 << 6) // Alloc from GPU's CPU visible heap + +/* cl_device_info */ +#define CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT 0x4032 + +/********************************* +* cl_amd_device_attribute_query * +*********************************/ +#define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 0x4036 +#define CL_DEVICE_TOPOLOGY_AMD 0x4037 +#define CL_DEVICE_BOARD_NAME_AMD 0x4038 +#define CL_DEVICE_GLOBAL_FREE_MEMORY_AMD 0x4039 +#define CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD 0x4040 +#define CL_DEVICE_SIMD_WIDTH_AMD 0x4041 +#define CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD 0x4042 +#define CL_DEVICE_WAVEFRONT_WIDTH_AMD 0x4043 +#define CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD 0x4044 +#define CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD 0x4045 +#define CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD 0x4046 +#define CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD 0x4047 +#define CL_DEVICE_LOCAL_MEM_BANKS_AMD 0x4048 +#define CL_DEVICE_THREAD_TRACE_SUPPORTED_AMD 0x4049 +#define CL_DEVICE_GFXIP_MAJOR_AMD 0x404A +#define CL_DEVICE_GFXIP_MINOR_AMD 0x404B +#define CL_DEVICE_AVAILABLE_ASYNC_QUEUES_AMD 0x404C +#define CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD 0x4030 +#define CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD 0x4031 +#define CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD 0x4033 +#define CL_DEVICE_PCIE_ID_AMD 0x4034 + +typedef union +{ + struct { cl_uint type; cl_uint data[5]; } raw; + struct { cl_uint type; cl_uchar unused[17]; cl_uchar bus; cl_uchar device; cl_uchar function; } pcie; +} cl_device_topology_amd; + +#define CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD 1 + +/************************** +* cl_amd_offline_devices * +**************************/ +#define CL_CONTEXT_OFFLINE_DEVICES_AMD 0x403F + +/******************************** +* cl_amd_bus_addressable_memory * +********************************/ + +/* cl_mem flag - bitfield */ +#define CL_MEM_BUS_ADDRESSABLE_AMD (1<<30) +#define CL_MEM_EXTERNAL_PHYSICAL_AMD (1<<31) + +#define CL_COMMAND_WAIT_SIGNAL_AMD 0x4080 +#define CL_COMMAND_WRITE_SIGNAL_AMD 0x4081 +#define CL_COMMAND_MAKE_BUFFERS_RESIDENT_AMD 0x4082 + +typedef struct _cl_bus_address_amd +{ + cl_ulong surface_bus_address; + cl_ulong marker_bus_address; +} cl_bus_address_amd; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueWaitSignalAMD_fn)( cl_command_queue /*command_queue*/, + cl_mem /*mem_object*/, + cl_uint /*value*/, + cl_uint /*num_events*/, + const cl_event * /*event_wait_list*/, + cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueWriteSignalAMD_fn)( cl_command_queue /*command_queue*/, + cl_mem /*mem_object*/, + cl_uint /*value*/, + cl_ulong /*offset*/, + cl_uint /*num_events*/, + const cl_event * /*event_list*/, + cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueMakeBuffersResidentAMD_fn)( cl_command_queue /*command_queue*/, + cl_uint /*num_mem_objs*/, + cl_mem * /*mem_objects*/, + cl_bool /*blocking_make_resident*/, + cl_bus_address_amd * /*bus_addresses*/, + cl_uint /*num_events*/, + const cl_event * /*event_list*/, + cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +/************************* +* cl_amd_copy_buffer_p2p * +**************************/ +#define CL_DEVICE_NUM_P2P_DEVICES_AMD 0x4088 +#define CL_DEVICE_P2P_DEVICES_AMD 0x4089 + +#define cl_amd_copy_buffer_p2p 1 + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueCopyBufferP2PAMD_fn)(cl_command_queue /*command_queue*/, + cl_mem /*src_buffer*/, + cl_mem /*dst_buffer*/, + size_t /*src_offset*/, + size_t /*dst_offset*/, + size_t /*cb*/, + cl_uint /*num_events_in_wait_list*/, + const cl_event* /*event_wait_list*/, + cl_event* /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +/*********************************** +* cl_amd_assembly_program extension * +***********************************/ +#define cl_amd_assembly_program 1 + +typedef CL_API_ENTRY cl_program (CL_API_CALL * clCreateProgramWithAssemblyAMD_fn) ( + cl_context /* context */, + cl_uint /* count */, + const char** /* strings */, + const size_t* /* lengths */, + cl_int* /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2; + + +// +/************************** +* cl_amd_command_queue_info * +**************************/ +#define CL_QUEUE_THREAD_HANDLE_AMD 0x403E + +/* cl_kernel_exec_info for DVR DOPP texture support */ +#define CL_KERNEL_EXEC_INFO_NEW_VCOP_AMD 0x4120 +#define CL_KERNEL_EXEC_INFO_PFPA_VCOP_AMD 0x4121 +// + +/********************************* +* cl_arm_printf extension +*********************************/ +#define CL_PRINTF_CALLBACK_ARM 0x40B0 +#define CL_PRINTF_BUFFERSIZE_ARM 0x40B1 + +#ifdef CL_VERSION_1_1 + /*********************************** + * cl_ext_device_fission extension * + ***********************************/ + #define cl_ext_device_fission 1 + + extern CL_API_ENTRY cl_int CL_API_CALL + clReleaseDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + typedef CL_API_ENTRY cl_int + (CL_API_CALL *clReleaseDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + extern CL_API_ENTRY cl_int CL_API_CALL + clRetainDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + typedef CL_API_ENTRY cl_int + (CL_API_CALL *clRetainDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + typedef cl_ulong cl_device_partition_property_ext; + extern CL_API_ENTRY cl_int CL_API_CALL + clCreateSubDevicesEXT( cl_device_id /*in_device*/, + const cl_device_partition_property_ext * /* properties */, + cl_uint /*num_entries*/, + cl_device_id * /*out_devices*/, + cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + typedef CL_API_ENTRY cl_int + ( CL_API_CALL * clCreateSubDevicesEXT_fn)( cl_device_id /*in_device*/, + const cl_device_partition_property_ext * /* properties */, + cl_uint /*num_entries*/, + cl_device_id * /*out_devices*/, + cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + /* cl_device_partition_property_ext */ + #define CL_DEVICE_PARTITION_EQUALLY_EXT 0x4050 + #define CL_DEVICE_PARTITION_BY_COUNTS_EXT 0x4051 + #define CL_DEVICE_PARTITION_BY_NAMES_EXT 0x4052 + #define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT 0x4053 + + /* clDeviceGetInfo selectors */ + #define CL_DEVICE_PARENT_DEVICE_EXT 0x4054 + #define CL_DEVICE_PARTITION_TYPES_EXT 0x4055 + #define CL_DEVICE_AFFINITY_DOMAINS_EXT 0x4056 + #define CL_DEVICE_REFERENCE_COUNT_EXT 0x4057 + #define CL_DEVICE_PARTITION_STYLE_EXT 0x4058 + + /* clGetImageInfo enum */ + #define CL_IMAGE_BYTE_PITCH_AMD 0x4059 + + /* error codes */ + #define CL_DEVICE_PARTITION_FAILED_EXT -1057 + #define CL_INVALID_PARTITION_COUNT_EXT -1058 + #define CL_INVALID_PARTITION_NAME_EXT -1059 + + /* CL_AFFINITY_DOMAINs */ + #define CL_AFFINITY_DOMAIN_L1_CACHE_EXT 0x1 + #define CL_AFFINITY_DOMAIN_L2_CACHE_EXT 0x2 + #define CL_AFFINITY_DOMAIN_L3_CACHE_EXT 0x3 + #define CL_AFFINITY_DOMAIN_L4_CACHE_EXT 0x4 + #define CL_AFFINITY_DOMAIN_NUMA_EXT 0x10 + #define CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT 0x100 + + /* cl_device_partition_property_ext list terminators */ + #define CL_PROPERTIES_LIST_END_EXT ((cl_device_partition_property_ext) 0) + #define CL_PARTITION_BY_COUNTS_LIST_END_EXT ((cl_device_partition_property_ext) 0) + #define CL_PARTITION_BY_NAMES_LIST_END_EXT ((cl_device_partition_property_ext) 0 - 1) + +/********************************* +* cl_qcom_ext_host_ptr extension +*********************************/ + +#define CL_MEM_EXT_HOST_PTR_QCOM (1 << 29) + +#define CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM 0x40A0 +#define CL_DEVICE_PAGE_SIZE_QCOM 0x40A1 +#define CL_IMAGE_ROW_ALIGNMENT_QCOM 0x40A2 +#define CL_IMAGE_SLICE_ALIGNMENT_QCOM 0x40A3 +#define CL_MEM_HOST_UNCACHED_QCOM 0x40A4 +#define CL_MEM_HOST_WRITEBACK_QCOM 0x40A5 +#define CL_MEM_HOST_WRITETHROUGH_QCOM 0x40A6 +#define CL_MEM_HOST_WRITE_COMBINING_QCOM 0x40A7 + +typedef cl_uint cl_image_pitch_info_qcom; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceImageInfoQCOM(cl_device_id device, + size_t image_width, + size_t image_height, + const cl_image_format *image_format, + cl_image_pitch_info_qcom param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret); + +typedef struct _cl_mem_ext_host_ptr +{ + /* Type of external memory allocation. */ + /* Legal values will be defined in layered extensions. */ + cl_uint allocation_type; + + /* Host cache policy for this external memory allocation. */ + cl_uint host_cache_policy; + +} cl_mem_ext_host_ptr; + +/********************************* +* cl_qcom_ion_host_ptr extension +*********************************/ + +#define CL_MEM_ION_HOST_PTR_QCOM 0x40A8 + +typedef struct _cl_mem_ion_host_ptr +{ + /* Type of external memory allocation. */ + /* Must be CL_MEM_ION_HOST_PTR_QCOM for ION allocations. */ + cl_mem_ext_host_ptr ext_host_ptr; + + /* ION file descriptor */ + int ion_filedesc; + + /* Host pointer to the ION allocated memory */ + void* ion_hostptr; + +} cl_mem_ion_host_ptr; + +#endif /* CL_VERSION_1_1 */ + +#if defined(CL_VERSION_1_2) + +/****************************************** + * cl_img_yuv_image extension * + ******************************************/ + +/* Image formats used in clCreateImage */ +#define CL_NV21_IMG 0x40D0 +#define CL_YV12_IMG 0x40D1 + +/****************************************** + * cl_img_cached_allocations extension * + ******************************************/ + +/* Flag values used by clCreteBuffer */ +#define CL_MEM_USE_UNCACHED_CPU_MEMORY_IMG (1 << 26) +#define CL_MEM_USE_CACHED_CPU_MEMORY_IMG (1 << 27) + +/****************************************** + * cl_img_use_gralloc_ptr extension * + ******************************************/ + +/* Flag values used by clCreteBuffer */ +#define CL_MEM_USE_GRALLOC_PTR_IMG (1 << 28) + +/* To be used by clGetEventInfo: */ +#define CL_COMMAND_ACQUIRE_GRALLOC_OBJECTS_IMG 0x40D2 +#define CL_COMMAND_RELEASE_GRALLOC_OBJECTS_IMG 0x40D3 + +/* Error code from clEnqueueReleaseGrallocObjectsIMG */ +#define CL_GRALLOC_RESOURCE_NOT_ACQUIRED_IMG 0x40D4 + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireGrallocObjectsIMG(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseGrallocObjectsIMG(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +#endif /* CL_VERSION_1_2 */ + +/********************************** + * cl_arm_import_memory extension * + **********************************/ + +#ifdef CL_VERSION_1_0 + +typedef intptr_t cl_import_properties_arm; + +/* Default and valid proporties name for cl_arm_import_memory */ +#define CL_IMPORT_TYPE_ARM 0x40B2 + +/* Host process memory type default value for CL_IMPORT_TYPE_ARM property */ +#define CL_IMPORT_TYPE_HOST_ARM 0x40B3 + +/* DMA BUF memory type value for CL_IMPORT_TYPE_ARM property */ +#define CL_IMPORT_TYPE_DMA_BUF_ARM 0x40B4 + +/* Secure DMA BUF memory type value for CL_IMPORT_TYPE_ARM property */ +#define CL_IMPORT_TYPE_SECURE_ARM 0x40B5 + +/* This extension adds a new function that allows for direct memory import into + * OpenCL via the clImportMemoryARM function. + * + * Memory imported through this interface will be mapped into the device's page + * tables directly, providing zero copy access. It will never fall back to copy + * operations and aliased buffers. + * + * Types of memory supported for import are specified as additional extension + * strings. + * + * This extension produces cl_mem allocations which are compatible with all other + * users of cl_mem in the standard API. + * + * This extension maps pages with the same properties as the normal buffer creation + * function clCreateBuffer. + */ +extern CL_API_ENTRY cl_mem CL_API_CALL +clImportMemoryARM( cl_context context, + cl_mem_flags flags, + const cl_import_properties_arm *properties, + void *memory, + size_t size, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_0; + + +#endif /* CL_VERSION_1_0 */ + +/****************************************** + * cl_arm_shared_virtual_memory extension * + ******************************************/ + +#ifdef CL_VERSION_1_2 + +/* Used by clGetDeviceInfo */ +#define CL_DEVICE_SVM_CAPABILITIES_ARM 0x40B6 + +/* Used by clGetMemObjectInfo */ +#define CL_MEM_USES_SVM_POINTER_ARM 0x40B7 + +/* Used by clSetKernelExecInfoARM: */ +#define CL_KERNEL_EXEC_INFO_SVM_PTRS_ARM 0x40B8 +#define CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM_ARM 0x40B9 + +/* To be used by clGetEventInfo: */ +#define CL_COMMAND_SVM_FREE_ARM 0x40BA +#define CL_COMMAND_SVM_MEMCPY_ARM 0x40BB +#define CL_COMMAND_SVM_MEMFILL_ARM 0x40BC +#define CL_COMMAND_SVM_MAP_ARM 0x40BD +#define CL_COMMAND_SVM_UNMAP_ARM 0x40BE + +/* Flag values returned by clGetDeviceInfo with CL_DEVICE_SVM_CAPABILITIES_ARM as the param_name. */ +#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER_ARM (1 << 0) +#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER_ARM (1 << 1) +#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM_ARM (1 << 2) +#define CL_DEVICE_SVM_ATOMICS_ARM (1 << 3) + +/* Flag values used by clSVMAllocARM: */ +#define CL_MEM_SVM_FINE_GRAIN_BUFFER_ARM (1 << 10) +#define CL_MEM_SVM_ATOMICS_ARM (1 << 11) + +typedef cl_bitfield cl_svm_mem_flags_arm; +typedef cl_uint cl_kernel_exec_info_arm; +typedef cl_bitfield cl_device_svm_capabilities_arm; + +extern CL_API_ENTRY void * CL_API_CALL +clSVMAllocARM(cl_context /* context */, + cl_svm_mem_flags_arm /* flags */, + size_t /* size */, + cl_uint /* alignment */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY void CL_API_CALL +clSVMFreeARM(cl_context /* context */, + void * /* svm_pointer */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMFreeARM(cl_command_queue /* command_queue */, + cl_uint /* num_svm_pointers */, + void *[] /* svm_pointers[] */, + void (CL_CALLBACK * /*pfn_free_func*/)(cl_command_queue /* queue */, + cl_uint /* num_svm_pointers */, + void *[] /* svm_pointers[] */, + void * /* user_data */), + void * /* user_data */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemcpyARM(cl_command_queue /* command_queue */, + cl_bool /* blocking_copy */, + void * /* dst_ptr */, + const void * /* src_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemFillARM(cl_command_queue /* command_queue */, + void * /* svm_ptr */, + const void * /* pattern */, + size_t /* pattern_size */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMapARM(cl_command_queue /* command_queue */, + cl_bool /* blocking_map */, + cl_map_flags /* flags */, + void * /* svm_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMUnmapARM(cl_command_queue /* command_queue */, + void * /* svm_ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArgSVMPointerARM(cl_kernel /* kernel */, + cl_uint /* arg_index */, + const void * /* arg_value */) CL_EXT_SUFFIX__VERSION_1_2; +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelExecInfoARM(cl_kernel /* kernel */, + cl_kernel_exec_info_arm /* param_name */, + size_t /* param_value_size */, + const void * /* param_value */) CL_EXT_SUFFIX__VERSION_1_2; + +#endif /* CL_VERSION_1_2 */ + +#ifdef __cplusplus +} +#endif + + +#endif /* __CL_EXT_H */ diff --git a/opencl/khronos/headers/opencl1.2/CL/cl_gl.h b/opencl/khronos/headers/opencl1.2/CL/cl_gl.h new file mode 100644 index 0000000000..945daa83d7 --- /dev/null +++ b/opencl/khronos/headers/opencl1.2/CL/cl_gl.h @@ -0,0 +1,167 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +#ifndef __OPENCL_CL_GL_H +#define __OPENCL_CL_GL_H + +#ifdef __APPLE__ +#include +#else +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef cl_uint cl_gl_object_type; +typedef cl_uint cl_gl_texture_info; +typedef cl_uint cl_gl_platform_info; +typedef struct __GLsync *cl_GLsync; + +/* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken */ +#define CL_GL_OBJECT_BUFFER 0x2000 +#define CL_GL_OBJECT_TEXTURE2D 0x2001 +#define CL_GL_OBJECT_TEXTURE3D 0x2002 +#define CL_GL_OBJECT_RENDERBUFFER 0x2003 +#define CL_GL_OBJECT_TEXTURE2D_ARRAY 0x200E +#define CL_GL_OBJECT_TEXTURE1D 0x200F +#define CL_GL_OBJECT_TEXTURE1D_ARRAY 0x2010 +#define CL_GL_OBJECT_TEXTURE_BUFFER 0x2011 + +/* cl_gl_texture_info */ +#define CL_GL_TEXTURE_TARGET 0x2004 +#define CL_GL_MIPMAP_LEVEL 0x2005 +#define CL_GL_NUM_SAMPLES 0x2012 + + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLBuffer(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLuint /* bufobj */, + int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLTexture(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLenum /* target */, + cl_GLint /* miplevel */, + cl_GLuint /* texture */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLRenderbuffer(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLuint /* renderbuffer */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetGLObjectInfo(cl_mem /* memobj */, + cl_gl_object_type * /* gl_object_type */, + cl_GLuint * /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetGLTextureInfo(cl_mem /* memobj */, + cl_gl_texture_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireGLObjects(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseGLObjects(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + + +/* Deprecated OpenCL 1.1 APIs */ +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateFromGLTexture2D(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLenum /* target */, + cl_GLint /* miplevel */, + cl_GLuint /* texture */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateFromGLTexture3D(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLenum /* target */, + cl_GLint /* miplevel */, + cl_GLuint /* texture */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +/* cl_khr_gl_sharing extension */ + +#define cl_khr_gl_sharing 1 + +typedef cl_uint cl_gl_context_info; + +/* Additional Error Codes */ +#define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000 + +/* cl_gl_context_info */ +#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 +#define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007 + +/* Additional cl_context_properties */ +#define CL_GL_CONTEXT_KHR 0x2008 +#define CL_EGL_DISPLAY_KHR 0x2009 +#define CL_GLX_DISPLAY_KHR 0x200A +#define CL_WGL_HDC_KHR 0x200B +#define CL_CGL_SHAREGROUP_KHR 0x200C + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetGLContextInfoKHR(const cl_context_properties * /* properties */, + cl_gl_context_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( + const cl_context_properties * properties, + cl_gl_context_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret); + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_GL_H */ diff --git a/opencl/khronos/headers/opencl1.2/CL/cl_gl_ext.h b/opencl/khronos/headers/opencl1.2/CL/cl_gl_ext.h new file mode 100644 index 0000000000..e3c14c6408 --- /dev/null +++ b/opencl/khronos/headers/opencl1.2/CL/cl_gl_ext.h @@ -0,0 +1,74 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +/* cl_gl_ext.h contains vendor (non-KHR) OpenCL extensions which have */ +/* OpenGL dependencies. */ + +#ifndef __OPENCL_CL_GL_EXT_H +#define __OPENCL_CL_GL_EXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __APPLE__ + #include +#else + #include +#endif + +/* + * For each extension, follow this template + * cl_VEN_extname extension */ +/* #define cl_VEN_extname 1 + * ... define new types, if any + * ... define new tokens, if any + * ... define new APIs, if any + * + * If you need GLtypes here, mirror them with a cl_GLtype, rather than including a GL header + * This allows us to avoid having to decide whether to include GL headers or GLES here. + */ + +/* + * cl_khr_gl_event extension + * See section 9.9 in the OpenCL 1.1 spec for more information + */ +#define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D + +extern CL_API_ENTRY cl_event CL_API_CALL +clCreateEventFromGLsyncKHR(cl_context /* context */, + cl_GLsync /* cl_GLsync */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_GL_EXT_H */ diff --git a/opencl/khronos/headers/opencl1.2/CL/cl_platform.h b/opencl/khronos/headers/opencl1.2/CL/cl_platform.h new file mode 100644 index 0000000000..19c54340c6 --- /dev/null +++ b/opencl/khronos/headers/opencl1.2/CL/cl_platform.h @@ -0,0 +1,1387 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11803 $ on $Date: 2010-06-25 10:02:12 -0700 (Fri, 25 Jun 2010) $ */ + +#ifndef __CL_PLATFORM_H +#define __CL_PLATFORM_H + +#ifdef __APPLE__ + /* Contains #defines for AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER below */ + #include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_WIN32) + #define CL_API_ENTRY + #define CL_API_CALL __stdcall + #define CL_CALLBACK __stdcall +#else + #define CL_API_ENTRY + #define CL_API_CALL + #define CL_CALLBACK +#endif + +#ifdef __APPLE__ + #define CL_EXTENSION_WEAK_LINK __attribute__((weak_import)) + #define CL_API_SUFFIX__VERSION_1_0 AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_0 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER + #define CL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define GCL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_1 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_7 + + #ifdef AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_8 + #else + #warning This path should never happen outside of internal operating system development. AvailabilityMacros do not function correctly here! + #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #endif +#else + #define CL_EXTENSION_WEAK_LINK + #define CL_API_SUFFIX__VERSION_1_0 + #define CL_EXT_SUFFIX__VERSION_1_0 + #define CL_API_SUFFIX__VERSION_1_1 + #define CL_EXT_SUFFIX__VERSION_1_1 + #define CL_API_SUFFIX__VERSION_1_2 + #define CL_EXT_SUFFIX__VERSION_1_2 + + #ifdef __GNUC__ + #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED __attribute__((deprecated)) + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED + #endif + + #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED __attribute__((deprecated)) + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + #endif + #elif defined(_WIN32) + #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED __declspec(deprecated) + #endif + + #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED __declspec(deprecated) + #endif + #else + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED + + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + #endif +#endif + +#if (defined (_WIN32) && defined(_MSC_VER)) + +/* scalar types */ +typedef signed __int8 cl_char; +typedef unsigned __int8 cl_uchar; +typedef signed __int16 cl_short; +typedef unsigned __int16 cl_ushort; +typedef signed __int32 cl_int; +typedef unsigned __int32 cl_uint; +typedef signed __int64 cl_long; +typedef unsigned __int64 cl_ulong; + +typedef unsigned __int16 cl_half; +typedef float cl_float; +typedef double cl_double; + +/* Macro names and corresponding values defined by OpenCL */ +#define CL_CHAR_BIT 8 +#define CL_SCHAR_MAX 127 +#define CL_SCHAR_MIN (-127-1) +#define CL_CHAR_MAX CL_SCHAR_MAX +#define CL_CHAR_MIN CL_SCHAR_MIN +#define CL_UCHAR_MAX 255 +#define CL_SHRT_MAX 32767 +#define CL_SHRT_MIN (-32767-1) +#define CL_USHRT_MAX 65535 +#define CL_INT_MAX 2147483647 +#define CL_INT_MIN (-2147483647-1) +#define CL_UINT_MAX 0xffffffffU +#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) +#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) +#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) + +#define CL_FLT_DIG 6 +#define CL_FLT_MANT_DIG 24 +#define CL_FLT_MAX_10_EXP +38 +#define CL_FLT_MAX_EXP +128 +#define CL_FLT_MIN_10_EXP -37 +#define CL_FLT_MIN_EXP -125 +#define CL_FLT_RADIX 2 +#define CL_FLT_MAX 340282346638528859811704183484516925440.0f +#define CL_FLT_MIN 1.175494350822287507969e-38f +#define CL_FLT_EPSILON 1.1920928955078125e-7f + +#define CL_HALF_DIG 3 +#define CL_HALF_MANT_DIG 11 +#define CL_HALF_MAX_10_EXP +4 +#define CL_HALF_MAX_EXP +16 +#define CL_HALF_MIN_10_EXP -4 +#define CL_HALF_MIN_EXP -13 +#define CL_HALF_RADIX 2 +#define CL_HALF_MAX 65504.0f +#define CL_HALF_MIN 6.103515625e-05f +#define CL_HALF_EPSILON 9.765625e-04f + +#define CL_DBL_DIG 15 +#define CL_DBL_MANT_DIG 53 +#define CL_DBL_MAX_10_EXP +308 +#define CL_DBL_MAX_EXP +1024 +#define CL_DBL_MIN_10_EXP -307 +#define CL_DBL_MIN_EXP -1021 +#define CL_DBL_RADIX 2 +#define CL_DBL_MAX 1.7976931348623158e+308 +#define CL_DBL_MIN 2.225073858507201383090e-308 +#define CL_DBL_EPSILON 2.220446049250313080847e-16 + +#define CL_M_E 2.7182818284590452354 +#define CL_M_LOG2E 1.4426950408889634074 +#define CL_M_LOG10E 0.43429448190325182765 +#define CL_M_LN2 0.69314718055994530942 +#define CL_M_LN10 2.30258509299404568402 +#define CL_M_PI 3.14159265358979323846 +#define CL_M_PI_2 1.57079632679489661923 +#define CL_M_PI_4 0.78539816339744830962 +#define CL_M_1_PI 0.31830988618379067154 +#define CL_M_2_PI 0.63661977236758134308 +#define CL_M_2_SQRTPI 1.12837916709551257390 +#define CL_M_SQRT2 1.41421356237309504880 +#define CL_M_SQRT1_2 0.70710678118654752440 + +#define CL_M_E_F 2.718281828f +#define CL_M_LOG2E_F 1.442695041f +#define CL_M_LOG10E_F 0.434294482f +#define CL_M_LN2_F 0.693147181f +#define CL_M_LN10_F 2.302585093f +#define CL_M_PI_F 3.141592654f +#define CL_M_PI_2_F 1.570796327f +#define CL_M_PI_4_F 0.785398163f +#define CL_M_1_PI_F 0.318309886f +#define CL_M_2_PI_F 0.636619772f +#define CL_M_2_SQRTPI_F 1.128379167f +#define CL_M_SQRT2_F 1.414213562f +#define CL_M_SQRT1_2_F 0.707106781f + +#define CL_NAN (CL_INFINITY - CL_INFINITY) +#define CL_HUGE_VALF ((cl_float) 1e50) +#define CL_HUGE_VAL ((cl_double) 1e500) +#define CL_MAXFLOAT CL_FLT_MAX +#define CL_INFINITY CL_HUGE_VALF + +#else + +#include + +/* scalar types */ +typedef int8_t cl_char; +typedef uint8_t cl_uchar; +typedef int16_t cl_short __attribute__((aligned(2))); +typedef uint16_t cl_ushort __attribute__((aligned(2))); +typedef int32_t cl_int __attribute__((aligned(4))); +typedef uint32_t cl_uint __attribute__((aligned(4))); +typedef int64_t cl_long __attribute__((aligned(8))); +typedef uint64_t cl_ulong __attribute__((aligned(8))); + +typedef uint16_t cl_half __attribute__((aligned(2))); +typedef float cl_float __attribute__((aligned(4))); +typedef double cl_double __attribute__((aligned(8))); + +/* Macro names and corresponding values defined by OpenCL */ +#define CL_CHAR_BIT 8 +#define CL_SCHAR_MAX 127 +#define CL_SCHAR_MIN (-127-1) +#define CL_CHAR_MAX CL_SCHAR_MAX +#define CL_CHAR_MIN CL_SCHAR_MIN +#define CL_UCHAR_MAX 255 +#define CL_SHRT_MAX 32767 +#define CL_SHRT_MIN (-32767-1) +#define CL_USHRT_MAX 65535 +#define CL_INT_MAX 2147483647 +#define CL_INT_MIN (-2147483647-1) +#define CL_UINT_MAX 0xffffffffU +#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) +#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) +#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) + +#define CL_FLT_DIG 6 +#define CL_FLT_MANT_DIG 24 +#define CL_FLT_MAX_10_EXP +38 +#define CL_FLT_MAX_EXP +128 +#define CL_FLT_MIN_10_EXP -37 +#define CL_FLT_MIN_EXP -125 +#define CL_FLT_RADIX 2 +#define CL_FLT_MAX 340282346638528859811704183484516925440.0f +#define CL_FLT_MIN 1.175494350822287507969e-38f +#define CL_FLT_EPSILON 1.1920928955078125e-7f + +#define CL_HALF_DIG 3 +#define CL_HALF_MANT_DIG 11 +#define CL_HALF_MAX_10_EXP +4 +#define CL_HALF_MAX_EXP +16 +#define CL_HALF_MIN_10_EXP -4 +#define CL_HALF_MIN_EXP -13 +#define CL_HALF_RADIX 2 +#define CL_HALF_MAX 65504.0f +#define CL_HALF_MIN 6.103515625e-05f +#define CL_HALF_EPSILON 9.765625e-04f + +#define CL_DBL_DIG 15 +#define CL_DBL_MANT_DIG 53 +#define CL_DBL_MAX_10_EXP +308 +#define CL_DBL_MAX_EXP +1024 +#define CL_DBL_MIN_10_EXP -307 +#define CL_DBL_MIN_EXP -1021 +#define CL_DBL_RADIX 2 +#define CL_DBL_MAX 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0 +#define CL_DBL_MIN 2.225073858507201383090e-308 +#define CL_DBL_EPSILON 2.220446049250313080847e-16 + +#define CL_M_E 2.7182818284590452354 +#define CL_M_LOG2E 1.4426950408889634074 +#define CL_M_LOG10E 0.43429448190325182765 +#define CL_M_LN2 0.69314718055994530942 +#define CL_M_LN10 2.30258509299404568402 +#define CL_M_PI 3.14159265358979323846 +#define CL_M_PI_2 1.57079632679489661923 +#define CL_M_PI_4 0.78539816339744830962 +#define CL_M_1_PI 0.31830988618379067154 +#define CL_M_2_PI 0.63661977236758134308 +#define CL_M_2_SQRTPI 1.12837916709551257390 +#define CL_M_SQRT2 1.41421356237309504880 +#define CL_M_SQRT1_2 0.70710678118654752440 + +#define CL_M_E_F 2.718281828f +#define CL_M_LOG2E_F 1.442695041f +#define CL_M_LOG10E_F 0.434294482f +#define CL_M_LN2_F 0.693147181f +#define CL_M_LN10_F 2.302585093f +#define CL_M_PI_F 3.141592654f +#define CL_M_PI_2_F 1.570796327f +#define CL_M_PI_4_F 0.785398163f +#define CL_M_1_PI_F 0.318309886f +#define CL_M_2_PI_F 0.636619772f +#define CL_M_2_SQRTPI_F 1.128379167f +#define CL_M_SQRT2_F 1.414213562f +#define CL_M_SQRT1_2_F 0.707106781f + +#if defined( __GNUC__ ) + #define CL_HUGE_VALF __builtin_huge_valf() + #define CL_HUGE_VAL __builtin_huge_val() + #define CL_NAN __builtin_nanf( "" ) +#else + #define CL_HUGE_VALF ((cl_float) 1e50) + #define CL_HUGE_VAL ((cl_double) 1e500) + float nanf( const char * ); + #define CL_NAN nanf( "" ) +#endif +#define CL_MAXFLOAT CL_FLT_MAX +#define CL_INFINITY CL_HUGE_VALF + +#endif + +#include + +/* Mirror types to GL types. Mirror types allow us to avoid deciding which 87s to load based on whether we are using GL or GLES here. */ +typedef unsigned int cl_GLuint; +typedef int cl_GLint; +typedef unsigned int cl_GLenum; + +/* + * Vector types + * + * Note: OpenCL requires that all types be naturally aligned. + * This means that vector types must be naturally aligned. + * For example, a vector of four floats must be aligned to + * a 16 byte boundary (calculated as 4 * the natural 4-byte + * alignment of the float). The alignment qualifiers here + * will only function properly if your compiler supports them + * and if you don't actively work to defeat them. For example, + * in order for a cl_float4 to be 16 byte aligned in a struct, + * the start of the struct must itself be 16-byte aligned. + * + * Maintaining proper alignment is the user's responsibility. + */ + +/* Define basic vector types */ +#if defined( __VEC__ ) + #include /* may be omitted depending on compiler. AltiVec spec provides no way to detect whether the header is required. */ + typedef vector unsigned char __cl_uchar16; + typedef vector signed char __cl_char16; + typedef vector unsigned short __cl_ushort8; + typedef vector signed short __cl_short8; + typedef vector unsigned int __cl_uint4; + typedef vector signed int __cl_int4; + typedef vector float __cl_float4; + #define __CL_UCHAR16__ 1 + #define __CL_CHAR16__ 1 + #define __CL_USHORT8__ 1 + #define __CL_SHORT8__ 1 + #define __CL_UINT4__ 1 + #define __CL_INT4__ 1 + #define __CL_FLOAT4__ 1 +#endif + +#if defined( __SSE__ ) + #if defined( __MINGW64__ ) + #include + #else + #include + #endif + #if defined( __GNUC__ ) + typedef float __cl_float4 __attribute__((vector_size(16))); + #else + typedef __m128 __cl_float4; + #endif + #define __CL_FLOAT4__ 1 +#endif + +#if defined( __SSE2__ ) + #if defined( __MINGW64__ ) + #include + #else + #include + #endif + #if defined( __GNUC__ ) + typedef cl_uchar __cl_uchar16 __attribute__((vector_size(16))); + typedef cl_char __cl_char16 __attribute__((vector_size(16))); + typedef cl_ushort __cl_ushort8 __attribute__((vector_size(16))); + typedef cl_short __cl_short8 __attribute__((vector_size(16))); + typedef cl_uint __cl_uint4 __attribute__((vector_size(16))); + typedef cl_int __cl_int4 __attribute__((vector_size(16))); + typedef cl_ulong __cl_ulong2 __attribute__((vector_size(16))); + typedef cl_long __cl_long2 __attribute__((vector_size(16))); + typedef cl_double __cl_double2 __attribute__((vector_size(16))); + #else + typedef __m128i __cl_uchar16; + typedef __m128i __cl_char16; + typedef __m128i __cl_ushort8; + typedef __m128i __cl_short8; + typedef __m128i __cl_uint4; + typedef __m128i __cl_int4; + typedef __m128i __cl_ulong2; + typedef __m128i __cl_long2; + typedef __m128d __cl_double2; + #endif + #define __CL_UCHAR16__ 1 + #define __CL_CHAR16__ 1 + #define __CL_USHORT8__ 1 + #define __CL_SHORT8__ 1 + #define __CL_INT4__ 1 + #define __CL_UINT4__ 1 + #define __CL_ULONG2__ 1 + #define __CL_LONG2__ 1 + #define __CL_DOUBLE2__ 1 +#endif + +#if defined( __MMX__ ) + #include + #if defined( __GNUC__ ) + typedef cl_uchar __cl_uchar8 __attribute__((vector_size(8))); + typedef cl_char __cl_char8 __attribute__((vector_size(8))); + typedef cl_ushort __cl_ushort4 __attribute__((vector_size(8))); + typedef cl_short __cl_short4 __attribute__((vector_size(8))); + typedef cl_uint __cl_uint2 __attribute__((vector_size(8))); + typedef cl_int __cl_int2 __attribute__((vector_size(8))); + typedef cl_ulong __cl_ulong1 __attribute__((vector_size(8))); + typedef cl_long __cl_long1 __attribute__((vector_size(8))); + typedef cl_float __cl_float2 __attribute__((vector_size(8))); + #else + typedef __m64 __cl_uchar8; + typedef __m64 __cl_char8; + typedef __m64 __cl_ushort4; + typedef __m64 __cl_short4; + typedef __m64 __cl_uint2; + typedef __m64 __cl_int2; + typedef __m64 __cl_ulong1; + typedef __m64 __cl_long1; + typedef __m64 __cl_float2; + #endif + #define __CL_UCHAR8__ 1 + #define __CL_CHAR8__ 1 + #define __CL_USHORT4__ 1 + #define __CL_SHORT4__ 1 + #define __CL_INT2__ 1 + #define __CL_UINT2__ 1 + #define __CL_ULONG1__ 1 + #define __CL_LONG1__ 1 + #define __CL_FLOAT2__ 1 +#endif + +#if defined( __AVX__ ) + #if defined( __MINGW64__ ) + #include + #else + #include + #endif + #if defined( __GNUC__ ) + typedef cl_float __cl_float8 __attribute__((vector_size(32))); + typedef cl_double __cl_double4 __attribute__((vector_size(32))); + #else + typedef __m256 __cl_float8; + typedef __m256d __cl_double4; + #endif + #define __CL_FLOAT8__ 1 + #define __CL_DOUBLE4__ 1 +#endif + +/* Define capabilities for anonymous struct members. */ +#if !defined(__cplusplus) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#define __CL_HAS_ANON_STRUCT__ 1 +#define __CL_ANON_STRUCT__ +#elif defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) +#define __CL_HAS_ANON_STRUCT__ 1 +#define __CL_ANON_STRUCT__ __extension__ +#elif defined( _WIN32) && defined(_MSC_VER) + #if _MSC_VER >= 1500 + /* Microsoft Developer Studio 2008 supports anonymous structs, but + * complains by default. */ + #define __CL_HAS_ANON_STRUCT__ 1 + #define __CL_ANON_STRUCT__ + /* Disable warning C4201: nonstandard extension used : nameless + * struct/union */ + #pragma warning( push ) + #pragma warning( disable : 4201 ) + #endif +#else +#define __CL_HAS_ANON_STRUCT__ 0 +#define __CL_ANON_STRUCT__ +#endif + +/* Define alignment keys */ +#if defined( __GNUC__ ) + #define CL_ALIGNED(_x) __attribute__ ((aligned(_x))) +#elif defined( _WIN32) && (_MSC_VER) + /* Alignment keys neutered on windows because MSVC can't swallow function arguments with alignment requirements */ + /* http://msdn.microsoft.com/en-us/library/373ak2y1%28VS.71%29.aspx */ + /* #include */ + /* #define CL_ALIGNED(_x) _CRT_ALIGN(_x) */ + #define CL_ALIGNED(_x) +#else + #warning Need to implement some method to align data here + #define CL_ALIGNED(_x) +#endif + +/* Indicate whether .xyzw, .s0123 and .hi.lo are supported */ +#if __CL_HAS_ANON_STRUCT__ + /* .xyzw and .s0123...{f|F} are supported */ + #define CL_HAS_NAMED_VECTOR_FIELDS 1 + /* .hi and .lo are supported */ + #define CL_HAS_HI_LO_VECTOR_FIELDS 1 +#endif + +/* Define cl_vector types */ + +/* ---- cl_charn ---- */ +typedef union +{ + cl_char CL_ALIGNED(2) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_char lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2; +#endif +}cl_char2; + +typedef union +{ + cl_char CL_ALIGNED(4) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_char2 lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2[2]; +#endif +#if defined( __CL_CHAR4__) + __cl_char4 v4; +#endif +}cl_char4; + +/* cl_char3 is identical in size, alignment and behavior to cl_char4. See section 6.1.5. */ +typedef cl_char4 cl_char3; + +typedef union +{ + cl_char CL_ALIGNED(8) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_char4 lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2[4]; +#endif +#if defined( __CL_CHAR4__) + __cl_char4 v4[2]; +#endif +#if defined( __CL_CHAR8__ ) + __cl_char8 v8; +#endif +}cl_char8; + +typedef union +{ + cl_char CL_ALIGNED(16) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_char8 lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2[8]; +#endif +#if defined( __CL_CHAR4__) + __cl_char4 v4[4]; +#endif +#if defined( __CL_CHAR8__ ) + __cl_char8 v8[2]; +#endif +#if defined( __CL_CHAR16__ ) + __cl_char16 v16; +#endif +}cl_char16; + + +/* ---- cl_ucharn ---- */ +typedef union +{ + cl_uchar CL_ALIGNED(2) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_uchar lo, hi; }; +#endif +#if defined( __cl_uchar2__) + __cl_uchar2 v2; +#endif +}cl_uchar2; + +typedef union +{ + cl_uchar CL_ALIGNED(4) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_uchar2 lo, hi; }; +#endif +#if defined( __CL_UCHAR2__) + __cl_uchar2 v2[2]; +#endif +#if defined( __CL_UCHAR4__) + __cl_uchar4 v4; +#endif +}cl_uchar4; + +/* cl_uchar3 is identical in size, alignment and behavior to cl_uchar4. See section 6.1.5. */ +typedef cl_uchar4 cl_uchar3; + +typedef union +{ + cl_uchar CL_ALIGNED(8) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_uchar4 lo, hi; }; +#endif +#if defined( __CL_UCHAR2__) + __cl_uchar2 v2[4]; +#endif +#if defined( __CL_UCHAR4__) + __cl_uchar4 v4[2]; +#endif +#if defined( __CL_UCHAR8__ ) + __cl_uchar8 v8; +#endif +}cl_uchar8; + +typedef union +{ + cl_uchar CL_ALIGNED(16) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_uchar8 lo, hi; }; +#endif +#if defined( __CL_UCHAR2__) + __cl_uchar2 v2[8]; +#endif +#if defined( __CL_UCHAR4__) + __cl_uchar4 v4[4]; +#endif +#if defined( __CL_UCHAR8__ ) + __cl_uchar8 v8[2]; +#endif +#if defined( __CL_UCHAR16__ ) + __cl_uchar16 v16; +#endif +}cl_uchar16; + + +/* ---- cl_shortn ---- */ +typedef union +{ + cl_short CL_ALIGNED(4) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_short lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2; +#endif +}cl_short2; + +typedef union +{ + cl_short CL_ALIGNED(8) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_short2 lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2[2]; +#endif +#if defined( __CL_SHORT4__) + __cl_short4 v4; +#endif +}cl_short4; + +/* cl_short3 is identical in size, alignment and behavior to cl_short4. See section 6.1.5. */ +typedef cl_short4 cl_short3; + +typedef union +{ + cl_short CL_ALIGNED(16) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_short4 lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2[4]; +#endif +#if defined( __CL_SHORT4__) + __cl_short4 v4[2]; +#endif +#if defined( __CL_SHORT8__ ) + __cl_short8 v8; +#endif +}cl_short8; + +typedef union +{ + cl_short CL_ALIGNED(32) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_short8 lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2[8]; +#endif +#if defined( __CL_SHORT4__) + __cl_short4 v4[4]; +#endif +#if defined( __CL_SHORT8__ ) + __cl_short8 v8[2]; +#endif +#if defined( __CL_SHORT16__ ) + __cl_short16 v16; +#endif +}cl_short16; + + +/* ---- cl_ushortn ---- */ +typedef union +{ + cl_ushort CL_ALIGNED(4) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_ushort lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2; +#endif +}cl_ushort2; + +typedef union +{ + cl_ushort CL_ALIGNED(8) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_ushort2 lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2[2]; +#endif +#if defined( __CL_USHORT4__) + __cl_ushort4 v4; +#endif +}cl_ushort4; + +/* cl_ushort3 is identical in size, alignment and behavior to cl_ushort4. See section 6.1.5. */ +typedef cl_ushort4 cl_ushort3; + +typedef union +{ + cl_ushort CL_ALIGNED(16) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_ushort4 lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2[4]; +#endif +#if defined( __CL_USHORT4__) + __cl_ushort4 v4[2]; +#endif +#if defined( __CL_USHORT8__ ) + __cl_ushort8 v8; +#endif +}cl_ushort8; + +typedef union +{ + cl_ushort CL_ALIGNED(32) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_ushort8 lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2[8]; +#endif +#if defined( __CL_USHORT4__) + __cl_ushort4 v4[4]; +#endif +#if defined( __CL_USHORT8__ ) + __cl_ushort8 v8[2]; +#endif +#if defined( __CL_USHORT16__ ) + __cl_ushort16 v16; +#endif +}cl_ushort16; + + +/* ---- cl_halfn ---- */ +typedef union +{ + cl_half CL_ALIGNED(4) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_half lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2; +#endif +}cl_half2; + +typedef union +{ + cl_half CL_ALIGNED(8) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_half2 lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2[2]; +#endif +#if defined( __CL_HALF4__) + __cl_half4 v4; +#endif +}cl_half4; + +/* cl_half3 is identical in size, alignment and behavior to cl_half4. See section 6.1.5. */ +typedef cl_half4 cl_half3; + +typedef union +{ + cl_half CL_ALIGNED(16) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_half4 lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2[4]; +#endif +#if defined( __CL_HALF4__) + __cl_half4 v4[2]; +#endif +#if defined( __CL_HALF8__ ) + __cl_half8 v8; +#endif +}cl_half8; + +typedef union +{ + cl_half CL_ALIGNED(32) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_half8 lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2[8]; +#endif +#if defined( __CL_HALF4__) + __cl_half4 v4[4]; +#endif +#if defined( __CL_HALF8__ ) + __cl_half8 v8[2]; +#endif +#if defined( __CL_HALF16__ ) + __cl_half16 v16; +#endif +}cl_half16; + +/* ---- cl_intn ---- */ +typedef union +{ + cl_int CL_ALIGNED(8) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_int lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2; +#endif +}cl_int2; + +typedef union +{ + cl_int CL_ALIGNED(16) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_int2 lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2[2]; +#endif +#if defined( __CL_INT4__) + __cl_int4 v4; +#endif +}cl_int4; + +/* cl_int3 is identical in size, alignment and behavior to cl_int4. See section 6.1.5. */ +typedef cl_int4 cl_int3; + +typedef union +{ + cl_int CL_ALIGNED(32) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_int4 lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2[4]; +#endif +#if defined( __CL_INT4__) + __cl_int4 v4[2]; +#endif +#if defined( __CL_INT8__ ) + __cl_int8 v8; +#endif +}cl_int8; + +typedef union +{ + cl_int CL_ALIGNED(64) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_int8 lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2[8]; +#endif +#if defined( __CL_INT4__) + __cl_int4 v4[4]; +#endif +#if defined( __CL_INT8__ ) + __cl_int8 v8[2]; +#endif +#if defined( __CL_INT16__ ) + __cl_int16 v16; +#endif +}cl_int16; + + +/* ---- cl_uintn ---- */ +typedef union +{ + cl_uint CL_ALIGNED(8) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_uint lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2; +#endif +}cl_uint2; + +typedef union +{ + cl_uint CL_ALIGNED(16) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_uint2 lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2[2]; +#endif +#if defined( __CL_UINT4__) + __cl_uint4 v4; +#endif +}cl_uint4; + +/* cl_uint3 is identical in size, alignment and behavior to cl_uint4. See section 6.1.5. */ +typedef cl_uint4 cl_uint3; + +typedef union +{ + cl_uint CL_ALIGNED(32) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_uint4 lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2[4]; +#endif +#if defined( __CL_UINT4__) + __cl_uint4 v4[2]; +#endif +#if defined( __CL_UINT8__ ) + __cl_uint8 v8; +#endif +}cl_uint8; + +typedef union +{ + cl_uint CL_ALIGNED(64) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_uint8 lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2[8]; +#endif +#if defined( __CL_UINT4__) + __cl_uint4 v4[4]; +#endif +#if defined( __CL_UINT8__ ) + __cl_uint8 v8[2]; +#endif +#if defined( __CL_UINT16__ ) + __cl_uint16 v16; +#endif +}cl_uint16; + +/* ---- cl_longn ---- */ +typedef union +{ + cl_long CL_ALIGNED(16) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_long lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2; +#endif +}cl_long2; + +typedef union +{ + cl_long CL_ALIGNED(32) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_long2 lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2[2]; +#endif +#if defined( __CL_LONG4__) + __cl_long4 v4; +#endif +}cl_long4; + +/* cl_long3 is identical in size, alignment and behavior to cl_long4. See section 6.1.5. */ +typedef cl_long4 cl_long3; + +typedef union +{ + cl_long CL_ALIGNED(64) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_long4 lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2[4]; +#endif +#if defined( __CL_LONG4__) + __cl_long4 v4[2]; +#endif +#if defined( __CL_LONG8__ ) + __cl_long8 v8; +#endif +}cl_long8; + +typedef union +{ + cl_long CL_ALIGNED(128) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_long8 lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2[8]; +#endif +#if defined( __CL_LONG4__) + __cl_long4 v4[4]; +#endif +#if defined( __CL_LONG8__ ) + __cl_long8 v8[2]; +#endif +#if defined( __CL_LONG16__ ) + __cl_long16 v16; +#endif +}cl_long16; + + +/* ---- cl_ulongn ---- */ +typedef union +{ + cl_ulong CL_ALIGNED(16) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_ulong lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2; +#endif +}cl_ulong2; + +typedef union +{ + cl_ulong CL_ALIGNED(32) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_ulong2 lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2[2]; +#endif +#if defined( __CL_ULONG4__) + __cl_ulong4 v4; +#endif +}cl_ulong4; + +/* cl_ulong3 is identical in size, alignment and behavior to cl_ulong4. See section 6.1.5. */ +typedef cl_ulong4 cl_ulong3; + +typedef union +{ + cl_ulong CL_ALIGNED(64) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_ulong4 lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2[4]; +#endif +#if defined( __CL_ULONG4__) + __cl_ulong4 v4[2]; +#endif +#if defined( __CL_ULONG8__ ) + __cl_ulong8 v8; +#endif +}cl_ulong8; + +typedef union +{ + cl_ulong CL_ALIGNED(128) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_ulong8 lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2[8]; +#endif +#if defined( __CL_ULONG4__) + __cl_ulong4 v4[4]; +#endif +#if defined( __CL_ULONG8__ ) + __cl_ulong8 v8[2]; +#endif +#if defined( __CL_ULONG16__ ) + __cl_ulong16 v16; +#endif +}cl_ulong16; + + +/* --- cl_floatn ---- */ + +typedef union +{ + cl_float CL_ALIGNED(8) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_float lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2; +#endif +}cl_float2; + +typedef union +{ + cl_float CL_ALIGNED(16) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_float2 lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2[2]; +#endif +#if defined( __CL_FLOAT4__) + __cl_float4 v4; +#endif +}cl_float4; + +/* cl_float3 is identical in size, alignment and behavior to cl_float4. See section 6.1.5. */ +typedef cl_float4 cl_float3; + +typedef union +{ + cl_float CL_ALIGNED(32) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_float4 lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2[4]; +#endif +#if defined( __CL_FLOAT4__) + __cl_float4 v4[2]; +#endif +#if defined( __CL_FLOAT8__ ) + __cl_float8 v8; +#endif +}cl_float8; + +typedef union +{ + cl_float CL_ALIGNED(64) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_float8 lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2[8]; +#endif +#if defined( __CL_FLOAT4__) + __cl_float4 v4[4]; +#endif +#if defined( __CL_FLOAT8__ ) + __cl_float8 v8[2]; +#endif +#if defined( __CL_FLOAT16__ ) + __cl_float16 v16; +#endif +}cl_float16; + +/* --- cl_doublen ---- */ + +typedef union +{ + cl_double CL_ALIGNED(16) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_double lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2; +#endif +}cl_double2; + +typedef union +{ + cl_double CL_ALIGNED(32) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_double2 lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2[2]; +#endif +#if defined( __CL_DOUBLE4__) + __cl_double4 v4; +#endif +}cl_double4; + +/* cl_double3 is identical in size, alignment and behavior to cl_double4. See section 6.1.5. */ +typedef cl_double4 cl_double3; + +typedef union +{ + cl_double CL_ALIGNED(64) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_double4 lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2[4]; +#endif +#if defined( __CL_DOUBLE4__) + __cl_double4 v4[2]; +#endif +#if defined( __CL_DOUBLE8__ ) + __cl_double8 v8; +#endif +}cl_double8; + +typedef union +{ + cl_double CL_ALIGNED(128) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_double8 lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2[8]; +#endif +#if defined( __CL_DOUBLE4__) + __cl_double4 v4[4]; +#endif +#if defined( __CL_DOUBLE8__ ) + __cl_double8 v8[2]; +#endif +#if defined( __CL_DOUBLE16__ ) + __cl_double16 v16; +#endif +}cl_double16; + +/* Macro to facilitate debugging + * Usage: + * Place CL_PROGRAM_STRING_DEBUG_INFO on the line before the first line of your source. + * The first line ends with: CL_PROGRAM_STRING_DEBUG_INFO \" + * Each line thereafter of OpenCL C source must end with: \n\ + * The last line ends in "; + * + * Example: + * + * const char *my_program = CL_PROGRAM_STRING_DEBUG_INFO "\ + * kernel void foo( int a, float * b ) \n\ + * { \n\ + * // my comment \n\ + * *b[ get_global_id(0)] = a; \n\ + * } \n\ + * "; + * + * This should correctly set up the line, (column) and file information for your source + * string so you can do source level debugging. + */ +#define __CL_STRINGIFY( _x ) # _x +#define _CL_STRINGIFY( _x ) __CL_STRINGIFY( _x ) +#define CL_PROGRAM_STRING_DEBUG_INFO "#line " _CL_STRINGIFY(__LINE__) " \"" __FILE__ "\" \n\n" + +#ifdef __cplusplus +} +#endif + +#undef __CL_HAS_ANON_STRUCT__ +#undef __CL_ANON_STRUCT__ +#if defined( _WIN32) && defined(_MSC_VER) + #if _MSC_VER >=1500 + #pragma warning( pop ) + #endif +#endif + +#endif /* __CL_PLATFORM_H */ diff --git a/opencl/khronos/headers/opencl1.2/CL/opencl.h b/opencl/khronos/headers/opencl1.2/CL/opencl.h new file mode 100644 index 0000000000..9855cd75e7 --- /dev/null +++ b/opencl/khronos/headers/opencl1.2/CL/opencl.h @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_H +#define __OPENCL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __APPLE__ + +#include +#include +#include +#include + +#else + +#include +#include +#include +#include + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_H */ + diff --git a/opencl/khronos/headers/opencl2.0/CL/cl.h b/opencl/khronos/headers/opencl2.0/CL/cl.h new file mode 100644 index 0000000000..509dbd90b8 --- /dev/null +++ b/opencl/khronos/headers/opencl2.0/CL/cl.h @@ -0,0 +1,1389 @@ +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +#ifndef __OPENCL_CL_H +#define __OPENCL_CL_H + +#ifdef __APPLE__ +#include +#else +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/******************************************************************************/ + +typedef struct _cl_platform_id * cl_platform_id; +typedef struct _cl_device_id * cl_device_id; +typedef struct _cl_context * cl_context; +typedef struct _cl_command_queue * cl_command_queue; +typedef struct _cl_mem * cl_mem; +typedef struct _cl_program * cl_program; +typedef struct _cl_kernel * cl_kernel; +typedef struct _cl_event * cl_event; +typedef struct _cl_sampler * cl_sampler; + +typedef cl_uint cl_bool; /* WARNING! Unlike cl_ types in cl_platform.h, cl_bool is not guaranteed to be the same size as the bool in kernels. */ +typedef cl_ulong cl_bitfield; +typedef cl_bitfield cl_device_type; +typedef cl_uint cl_platform_info; +typedef cl_uint cl_device_info; +typedef cl_bitfield cl_device_fp_config; +typedef cl_uint cl_device_mem_cache_type; +typedef cl_uint cl_device_local_mem_type; +typedef cl_bitfield cl_device_exec_capabilities; +typedef cl_bitfield cl_device_svm_capabilities; +typedef cl_bitfield cl_command_queue_properties; +typedef intptr_t cl_device_partition_property; +typedef cl_bitfield cl_device_affinity_domain; + +typedef intptr_t cl_context_properties; +typedef cl_uint cl_context_info; +typedef cl_bitfield cl_queue_properties; +typedef cl_uint cl_command_queue_info; +typedef cl_uint cl_channel_order; +typedef cl_uint cl_channel_type; +typedef cl_bitfield cl_mem_flags; +typedef cl_bitfield cl_svm_mem_flags; +typedef cl_uint cl_mem_object_type; +typedef cl_uint cl_mem_info; +typedef cl_bitfield cl_mem_migration_flags; +typedef cl_uint cl_image_info; +typedef cl_uint cl_buffer_create_type; +typedef cl_uint cl_addressing_mode; +typedef cl_uint cl_filter_mode; +typedef cl_uint cl_sampler_info; +typedef cl_bitfield cl_map_flags; +typedef intptr_t cl_pipe_properties; +typedef cl_uint cl_pipe_info; +typedef cl_uint cl_program_info; +typedef cl_uint cl_program_build_info; +typedef cl_uint cl_program_binary_type; +typedef cl_int cl_build_status; +typedef cl_uint cl_kernel_info; +typedef cl_uint cl_kernel_arg_info; +typedef cl_uint cl_kernel_arg_address_qualifier; +typedef cl_uint cl_kernel_arg_access_qualifier; +typedef cl_bitfield cl_kernel_arg_type_qualifier; +typedef cl_uint cl_kernel_work_group_info; +typedef cl_uint cl_event_info; +typedef cl_uint cl_command_type; +typedef cl_uint cl_profiling_info; +typedef cl_bitfield cl_sampler_properties; +typedef cl_uint cl_kernel_exec_info; + +typedef struct _cl_image_format { + cl_channel_order image_channel_order; + cl_channel_type image_channel_data_type; +} cl_image_format; + +typedef struct _cl_image_desc { + cl_mem_object_type image_type; + size_t image_width; + size_t image_height; + size_t image_depth; + size_t image_array_size; + size_t image_row_pitch; + size_t image_slice_pitch; + cl_uint num_mip_levels; + cl_uint num_samples; +#ifdef __GNUC__ + __extension__ /* Prevents warnings about anonymous union in -pedantic builds */ +#endif + union { + cl_mem buffer; + cl_mem mem_object; + }; +} cl_image_desc; + +typedef struct _cl_buffer_region { + size_t origin; + size_t size; +} cl_buffer_region; + + +/******************************************************************************/ + +/* Error Codes */ +#define CL_SUCCESS 0 +#define CL_DEVICE_NOT_FOUND -1 +#define CL_DEVICE_NOT_AVAILABLE -2 +#define CL_COMPILER_NOT_AVAILABLE -3 +#define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 +#define CL_OUT_OF_RESOURCES -5 +#define CL_OUT_OF_HOST_MEMORY -6 +#define CL_PROFILING_INFO_NOT_AVAILABLE -7 +#define CL_MEM_COPY_OVERLAP -8 +#define CL_IMAGE_FORMAT_MISMATCH -9 +#define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 +#define CL_BUILD_PROGRAM_FAILURE -11 +#define CL_MAP_FAILURE -12 +#define CL_MISALIGNED_SUB_BUFFER_OFFSET -13 +#define CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST -14 +#define CL_COMPILE_PROGRAM_FAILURE -15 +#define CL_LINKER_NOT_AVAILABLE -16 +#define CL_LINK_PROGRAM_FAILURE -17 +#define CL_DEVICE_PARTITION_FAILED -18 +#define CL_KERNEL_ARG_INFO_NOT_AVAILABLE -19 + +#define CL_INVALID_VALUE -30 +#define CL_INVALID_DEVICE_TYPE -31 +#define CL_INVALID_PLATFORM -32 +#define CL_INVALID_DEVICE -33 +#define CL_INVALID_CONTEXT -34 +#define CL_INVALID_QUEUE_PROPERTIES -35 +#define CL_INVALID_COMMAND_QUEUE -36 +#define CL_INVALID_HOST_PTR -37 +#define CL_INVALID_MEM_OBJECT -38 +#define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 +#define CL_INVALID_IMAGE_SIZE -40 +#define CL_INVALID_SAMPLER -41 +#define CL_INVALID_BINARY -42 +#define CL_INVALID_BUILD_OPTIONS -43 +#define CL_INVALID_PROGRAM -44 +#define CL_INVALID_PROGRAM_EXECUTABLE -45 +#define CL_INVALID_KERNEL_NAME -46 +#define CL_INVALID_KERNEL_DEFINITION -47 +#define CL_INVALID_KERNEL -48 +#define CL_INVALID_ARG_INDEX -49 +#define CL_INVALID_ARG_VALUE -50 +#define CL_INVALID_ARG_SIZE -51 +#define CL_INVALID_KERNEL_ARGS -52 +#define CL_INVALID_WORK_DIMENSION -53 +#define CL_INVALID_WORK_GROUP_SIZE -54 +#define CL_INVALID_WORK_ITEM_SIZE -55 +#define CL_INVALID_GLOBAL_OFFSET -56 +#define CL_INVALID_EVENT_WAIT_LIST -57 +#define CL_INVALID_EVENT -58 +#define CL_INVALID_OPERATION -59 +#define CL_INVALID_GL_OBJECT -60 +#define CL_INVALID_BUFFER_SIZE -61 +#define CL_INVALID_MIP_LEVEL -62 +#define CL_INVALID_GLOBAL_WORK_SIZE -63 +#define CL_INVALID_PROPERTY -64 +#define CL_INVALID_IMAGE_DESCRIPTOR -65 +#define CL_INVALID_COMPILER_OPTIONS -66 +#define CL_INVALID_LINKER_OPTIONS -67 +#define CL_INVALID_DEVICE_PARTITION_COUNT -68 +#define CL_INVALID_PIPE_SIZE -69 +#define CL_INVALID_DEVICE_QUEUE -70 + +/* OpenCL Version */ +#define CL_VERSION_1_0 1 +#define CL_VERSION_1_1 1 +#define CL_VERSION_1_2 1 +#define CL_VERSION_2_0 1 + +/* cl_bool */ +#define CL_FALSE 0 +#define CL_TRUE 1 +#define CL_BLOCKING CL_TRUE +#define CL_NON_BLOCKING CL_FALSE + +/* cl_platform_info */ +#define CL_PLATFORM_PROFILE 0x0900 +#define CL_PLATFORM_VERSION 0x0901 +#define CL_PLATFORM_NAME 0x0902 +#define CL_PLATFORM_VENDOR 0x0903 +#define CL_PLATFORM_EXTENSIONS 0x0904 + +/* cl_device_type - bitfield */ +#define CL_DEVICE_TYPE_DEFAULT (1 << 0) +#define CL_DEVICE_TYPE_CPU (1 << 1) +#define CL_DEVICE_TYPE_GPU (1 << 2) +#define CL_DEVICE_TYPE_ACCELERATOR (1 << 3) +#define CL_DEVICE_TYPE_CUSTOM (1 << 4) +#define CL_DEVICE_TYPE_ALL 0xFFFFFFFF + +/* cl_device_info */ +#define CL_DEVICE_TYPE 0x1000 +#define CL_DEVICE_VENDOR_ID 0x1001 +#define CL_DEVICE_MAX_COMPUTE_UNITS 0x1002 +#define CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS 0x1003 +#define CL_DEVICE_MAX_WORK_GROUP_SIZE 0x1004 +#define CL_DEVICE_MAX_WORK_ITEM_SIZES 0x1005 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR 0x1006 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT 0x1007 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT 0x1008 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG 0x1009 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT 0x100A +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE 0x100B +#define CL_DEVICE_MAX_CLOCK_FREQUENCY 0x100C +#define CL_DEVICE_ADDRESS_BITS 0x100D +#define CL_DEVICE_MAX_READ_IMAGE_ARGS 0x100E +#define CL_DEVICE_MAX_WRITE_IMAGE_ARGS 0x100F +#define CL_DEVICE_MAX_MEM_ALLOC_SIZE 0x1010 +#define CL_DEVICE_IMAGE2D_MAX_WIDTH 0x1011 +#define CL_DEVICE_IMAGE2D_MAX_HEIGHT 0x1012 +#define CL_DEVICE_IMAGE3D_MAX_WIDTH 0x1013 +#define CL_DEVICE_IMAGE3D_MAX_HEIGHT 0x1014 +#define CL_DEVICE_IMAGE3D_MAX_DEPTH 0x1015 +#define CL_DEVICE_IMAGE_SUPPORT 0x1016 +#define CL_DEVICE_MAX_PARAMETER_SIZE 0x1017 +#define CL_DEVICE_MAX_SAMPLERS 0x1018 +#define CL_DEVICE_MEM_BASE_ADDR_ALIGN 0x1019 +#define CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE 0x101A +#define CL_DEVICE_SINGLE_FP_CONFIG 0x101B +#define CL_DEVICE_GLOBAL_MEM_CACHE_TYPE 0x101C +#define CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE 0x101D +#define CL_DEVICE_GLOBAL_MEM_CACHE_SIZE 0x101E +#define CL_DEVICE_GLOBAL_MEM_SIZE 0x101F +#define CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE 0x1020 +#define CL_DEVICE_MAX_CONSTANT_ARGS 0x1021 +#define CL_DEVICE_LOCAL_MEM_TYPE 0x1022 +#define CL_DEVICE_LOCAL_MEM_SIZE 0x1023 +#define CL_DEVICE_ERROR_CORRECTION_SUPPORT 0x1024 +#define CL_DEVICE_PROFILING_TIMER_RESOLUTION 0x1025 +#define CL_DEVICE_ENDIAN_LITTLE 0x1026 +#define CL_DEVICE_AVAILABLE 0x1027 +#define CL_DEVICE_COMPILER_AVAILABLE 0x1028 +#define CL_DEVICE_EXECUTION_CAPABILITIES 0x1029 +#define CL_DEVICE_QUEUE_PROPERTIES 0x102A /* deprecated */ +#define CL_DEVICE_QUEUE_ON_HOST_PROPERTIES 0x102A +#define CL_DEVICE_NAME 0x102B +#define CL_DEVICE_VENDOR 0x102C +#define CL_DRIVER_VERSION 0x102D +#define CL_DEVICE_PROFILE 0x102E +#define CL_DEVICE_VERSION 0x102F +#define CL_DEVICE_EXTENSIONS 0x1030 +#define CL_DEVICE_PLATFORM 0x1031 +#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 +#define CL_DEVICE_HALF_FP_CONFIG 0x1033 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF 0x1034 +#define CL_DEVICE_HOST_UNIFIED_MEMORY 0x1035 /* deprecated */ +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR 0x1036 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT 0x1037 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 0x1038 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 0x1039 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 0x103A +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 0x103B +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 0x103C +#define CL_DEVICE_OPENCL_C_VERSION 0x103D +#define CL_DEVICE_LINKER_AVAILABLE 0x103E +#define CL_DEVICE_BUILT_IN_KERNELS 0x103F +#define CL_DEVICE_IMAGE_MAX_BUFFER_SIZE 0x1040 +#define CL_DEVICE_IMAGE_MAX_ARRAY_SIZE 0x1041 +#define CL_DEVICE_PARENT_DEVICE 0x1042 +#define CL_DEVICE_PARTITION_MAX_SUB_DEVICES 0x1043 +#define CL_DEVICE_PARTITION_PROPERTIES 0x1044 +#define CL_DEVICE_PARTITION_AFFINITY_DOMAIN 0x1045 +#define CL_DEVICE_PARTITION_TYPE 0x1046 +#define CL_DEVICE_REFERENCE_COUNT 0x1047 +#define CL_DEVICE_PREFERRED_INTEROP_USER_SYNC 0x1048 +#define CL_DEVICE_PRINTF_BUFFER_SIZE 0x1049 +#define CL_DEVICE_IMAGE_PITCH_ALIGNMENT 0x104A +#define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT 0x104B +#define CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS 0x104C +#define CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE 0x104D +#define CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES 0x104E +#define CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE 0x104F +#define CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE 0x1050 +#define CL_DEVICE_MAX_ON_DEVICE_QUEUES 0x1051 +#define CL_DEVICE_MAX_ON_DEVICE_EVENTS 0x1052 +#define CL_DEVICE_SVM_CAPABILITIES 0x1053 +#define CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE 0x1054 +#define CL_DEVICE_MAX_PIPE_ARGS 0x1055 +#define CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS 0x1056 +#define CL_DEVICE_PIPE_MAX_PACKET_SIZE 0x1057 +#define CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT 0x1058 +#define CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT 0x1059 +#define CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT 0x105A + +/* cl_device_fp_config - bitfield */ +#define CL_FP_DENORM (1 << 0) +#define CL_FP_INF_NAN (1 << 1) +#define CL_FP_ROUND_TO_NEAREST (1 << 2) +#define CL_FP_ROUND_TO_ZERO (1 << 3) +#define CL_FP_ROUND_TO_INF (1 << 4) +#define CL_FP_FMA (1 << 5) +#define CL_FP_SOFT_FLOAT (1 << 6) +#define CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT (1 << 7) + +/* cl_device_mem_cache_type */ +#define CL_NONE 0x0 +#define CL_READ_ONLY_CACHE 0x1 +#define CL_READ_WRITE_CACHE 0x2 + +/* cl_device_local_mem_type */ +#define CL_LOCAL 0x1 +#define CL_GLOBAL 0x2 + +/* cl_device_exec_capabilities - bitfield */ +#define CL_EXEC_KERNEL (1 << 0) +#define CL_EXEC_NATIVE_KERNEL (1 << 1) + +/* cl_command_queue_properties - bitfield */ +#define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE (1 << 0) +#define CL_QUEUE_PROFILING_ENABLE (1 << 1) +#define CL_QUEUE_ON_DEVICE (1 << 2) +#define CL_QUEUE_ON_DEVICE_DEFAULT (1 << 3) + +/* cl_context_info */ +#define CL_CONTEXT_REFERENCE_COUNT 0x1080 +#define CL_CONTEXT_DEVICES 0x1081 +#define CL_CONTEXT_PROPERTIES 0x1082 +#define CL_CONTEXT_NUM_DEVICES 0x1083 + +/* cl_context_properties */ +#define CL_CONTEXT_PLATFORM 0x1084 +#define CL_CONTEXT_INTEROP_USER_SYNC 0x1085 + +/* cl_device_partition_property */ +#define CL_DEVICE_PARTITION_EQUALLY 0x1086 +#define CL_DEVICE_PARTITION_BY_COUNTS 0x1087 +#define CL_DEVICE_PARTITION_BY_COUNTS_LIST_END 0x0 +#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN 0x1088 + +/* cl_device_affinity_domain */ +#define CL_DEVICE_AFFINITY_DOMAIN_NUMA (1 << 0) +#define CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE (1 << 1) +#define CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE (1 << 2) +#define CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE (1 << 3) +#define CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE (1 << 4) +#define CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE (1 << 5) + +/* cl_device_svm_capabilities */ +#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER (1 << 0) +#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER (1 << 1) +#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM (1 << 2) +#define CL_DEVICE_SVM_ATOMICS (1 << 3) + +/* cl_command_queue_info */ +#define CL_QUEUE_CONTEXT 0x1090 +#define CL_QUEUE_DEVICE 0x1091 +#define CL_QUEUE_REFERENCE_COUNT 0x1092 +#define CL_QUEUE_PROPERTIES 0x1093 +#define CL_QUEUE_SIZE 0x1094 + +/* cl_mem_flags and cl_svm_mem_flags - bitfield */ +#define CL_MEM_READ_WRITE (1 << 0) +#define CL_MEM_WRITE_ONLY (1 << 1) +#define CL_MEM_READ_ONLY (1 << 2) +#define CL_MEM_USE_HOST_PTR (1 << 3) +#define CL_MEM_ALLOC_HOST_PTR (1 << 4) +#define CL_MEM_COPY_HOST_PTR (1 << 5) +/* reserved (1 << 6) */ +#define CL_MEM_HOST_WRITE_ONLY (1 << 7) +#define CL_MEM_HOST_READ_ONLY (1 << 8) +#define CL_MEM_HOST_NO_ACCESS (1 << 9) +#define CL_MEM_SVM_FINE_GRAIN_BUFFER (1 << 10) /* used by cl_svm_mem_flags only */ +#define CL_MEM_SVM_ATOMICS (1 << 11) /* used by cl_svm_mem_flags only */ +#define CL_MEM_KERNEL_READ_AND_WRITE (1 << 12) + +/* cl_mem_migration_flags - bitfield */ +#define CL_MIGRATE_MEM_OBJECT_HOST (1 << 0) +#define CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED (1 << 1) + +/* cl_channel_order */ +#define CL_R 0x10B0 +#define CL_A 0x10B1 +#define CL_RG 0x10B2 +#define CL_RA 0x10B3 +#define CL_RGB 0x10B4 +#define CL_RGBA 0x10B5 +#define CL_BGRA 0x10B6 +#define CL_ARGB 0x10B7 +#define CL_INTENSITY 0x10B8 +#define CL_LUMINANCE 0x10B9 +#define CL_Rx 0x10BA +#define CL_RGx 0x10BB +#define CL_RGBx 0x10BC +#define CL_DEPTH 0x10BD +#define CL_DEPTH_STENCIL 0x10BE +#define CL_sRGB 0x10BF +#define CL_sRGBx 0x10C0 +#define CL_sRGBA 0x10C1 +#define CL_sBGRA 0x10C2 +#define CL_ABGR 0x10C3 + +/* cl_channel_type */ +#define CL_SNORM_INT8 0x10D0 +#define CL_SNORM_INT16 0x10D1 +#define CL_UNORM_INT8 0x10D2 +#define CL_UNORM_INT16 0x10D3 +#define CL_UNORM_SHORT_565 0x10D4 +#define CL_UNORM_SHORT_555 0x10D5 +#define CL_UNORM_INT_101010 0x10D6 +#define CL_SIGNED_INT8 0x10D7 +#define CL_SIGNED_INT16 0x10D8 +#define CL_SIGNED_INT32 0x10D9 +#define CL_UNSIGNED_INT8 0x10DA +#define CL_UNSIGNED_INT16 0x10DB +#define CL_UNSIGNED_INT32 0x10DC +#define CL_HALF_FLOAT 0x10DD +#define CL_FLOAT 0x10DE +#define CL_UNORM_INT24 0x10DF + +/* cl_mem_object_type */ +#define CL_MEM_OBJECT_BUFFER 0x10F0 +#define CL_MEM_OBJECT_IMAGE2D 0x10F1 +#define CL_MEM_OBJECT_IMAGE3D 0x10F2 +#define CL_MEM_OBJECT_IMAGE2D_ARRAY 0x10F3 +#define CL_MEM_OBJECT_IMAGE1D 0x10F4 +#define CL_MEM_OBJECT_IMAGE1D_ARRAY 0x10F5 +#define CL_MEM_OBJECT_IMAGE1D_BUFFER 0x10F6 +#define CL_MEM_OBJECT_PIPE 0x10F7 + +/* cl_mem_info */ +#define CL_MEM_TYPE 0x1100 +#define CL_MEM_FLAGS 0x1101 +#define CL_MEM_SIZE 0x1102 +#define CL_MEM_HOST_PTR 0x1103 +#define CL_MEM_MAP_COUNT 0x1104 +#define CL_MEM_REFERENCE_COUNT 0x1105 +#define CL_MEM_CONTEXT 0x1106 +#define CL_MEM_ASSOCIATED_MEMOBJECT 0x1107 +#define CL_MEM_OFFSET 0x1108 +#define CL_MEM_USES_SVM_POINTER 0x1109 + +/* cl_image_info */ +#define CL_IMAGE_FORMAT 0x1110 +#define CL_IMAGE_ELEMENT_SIZE 0x1111 +#define CL_IMAGE_ROW_PITCH 0x1112 +#define CL_IMAGE_SLICE_PITCH 0x1113 +#define CL_IMAGE_WIDTH 0x1114 +#define CL_IMAGE_HEIGHT 0x1115 +#define CL_IMAGE_DEPTH 0x1116 +#define CL_IMAGE_ARRAY_SIZE 0x1117 +#define CL_IMAGE_BUFFER 0x1118 +#define CL_IMAGE_NUM_MIP_LEVELS 0x1119 +#define CL_IMAGE_NUM_SAMPLES 0x111A + +/* cl_pipe_info */ +#define CL_PIPE_PACKET_SIZE 0x1120 +#define CL_PIPE_MAX_PACKETS 0x1121 + +/* cl_addressing_mode */ +#define CL_ADDRESS_NONE 0x1130 +#define CL_ADDRESS_CLAMP_TO_EDGE 0x1131 +#define CL_ADDRESS_CLAMP 0x1132 +#define CL_ADDRESS_REPEAT 0x1133 +#define CL_ADDRESS_MIRRORED_REPEAT 0x1134 + +/* cl_filter_mode */ +#define CL_FILTER_NEAREST 0x1140 +#define CL_FILTER_LINEAR 0x1141 + +/* cl_sampler_info */ +#define CL_SAMPLER_REFERENCE_COUNT 0x1150 +#define CL_SAMPLER_CONTEXT 0x1151 +#define CL_SAMPLER_NORMALIZED_COORDS 0x1152 +#define CL_SAMPLER_ADDRESSING_MODE 0x1153 +#define CL_SAMPLER_FILTER_MODE 0x1154 +#define CL_SAMPLER_MIP_FILTER_MODE 0x1155 +#define CL_SAMPLER_LOD_MIN 0x1156 +#define CL_SAMPLER_LOD_MAX 0x1157 + +/* cl_map_flags - bitfield */ +#define CL_MAP_READ (1 << 0) +#define CL_MAP_WRITE (1 << 1) +#define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2) + +/* cl_program_info */ +#define CL_PROGRAM_REFERENCE_COUNT 0x1160 +#define CL_PROGRAM_CONTEXT 0x1161 +#define CL_PROGRAM_NUM_DEVICES 0x1162 +#define CL_PROGRAM_DEVICES 0x1163 +#define CL_PROGRAM_SOURCE 0x1164 +#define CL_PROGRAM_BINARY_SIZES 0x1165 +#define CL_PROGRAM_BINARIES 0x1166 +#define CL_PROGRAM_NUM_KERNELS 0x1167 +#define CL_PROGRAM_KERNEL_NAMES 0x1168 + +/* cl_program_build_info */ +#define CL_PROGRAM_BUILD_STATUS 0x1181 +#define CL_PROGRAM_BUILD_OPTIONS 0x1182 +#define CL_PROGRAM_BUILD_LOG 0x1183 +#define CL_PROGRAM_BINARY_TYPE 0x1184 +#define CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE 0x1185 + +/* cl_program_binary_type */ +#define CL_PROGRAM_BINARY_TYPE_NONE 0x0 +#define CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT 0x1 +#define CL_PROGRAM_BINARY_TYPE_LIBRARY 0x2 +#define CL_PROGRAM_BINARY_TYPE_EXECUTABLE 0x4 + +/* cl_build_status */ +#define CL_BUILD_SUCCESS 0 +#define CL_BUILD_NONE -1 +#define CL_BUILD_ERROR -2 +#define CL_BUILD_IN_PROGRESS -3 + +/* cl_kernel_info */ +#define CL_KERNEL_FUNCTION_NAME 0x1190 +#define CL_KERNEL_NUM_ARGS 0x1191 +#define CL_KERNEL_REFERENCE_COUNT 0x1192 +#define CL_KERNEL_CONTEXT 0x1193 +#define CL_KERNEL_PROGRAM 0x1194 +#define CL_KERNEL_ATTRIBUTES 0x1195 + +/* cl_kernel_arg_info */ +#define CL_KERNEL_ARG_ADDRESS_QUALIFIER 0x1196 +#define CL_KERNEL_ARG_ACCESS_QUALIFIER 0x1197 +#define CL_KERNEL_ARG_TYPE_NAME 0x1198 +#define CL_KERNEL_ARG_TYPE_QUALIFIER 0x1199 +#define CL_KERNEL_ARG_NAME 0x119A + +/* cl_kernel_arg_address_qualifier */ +#define CL_KERNEL_ARG_ADDRESS_GLOBAL 0x119B +#define CL_KERNEL_ARG_ADDRESS_LOCAL 0x119C +#define CL_KERNEL_ARG_ADDRESS_CONSTANT 0x119D +#define CL_KERNEL_ARG_ADDRESS_PRIVATE 0x119E + +/* cl_kernel_arg_access_qualifier */ +#define CL_KERNEL_ARG_ACCESS_READ_ONLY 0x11A0 +#define CL_KERNEL_ARG_ACCESS_WRITE_ONLY 0x11A1 +#define CL_KERNEL_ARG_ACCESS_READ_WRITE 0x11A2 +#define CL_KERNEL_ARG_ACCESS_NONE 0x11A3 + +/* cl_kernel_arg_type_qualifier */ +#define CL_KERNEL_ARG_TYPE_NONE 0 +#define CL_KERNEL_ARG_TYPE_CONST (1 << 0) +#define CL_KERNEL_ARG_TYPE_RESTRICT (1 << 1) +#define CL_KERNEL_ARG_TYPE_VOLATILE (1 << 2) +#define CL_KERNEL_ARG_TYPE_PIPE (1 << 3) + +/* cl_kernel_work_group_info */ +#define CL_KERNEL_WORK_GROUP_SIZE 0x11B0 +#define CL_KERNEL_COMPILE_WORK_GROUP_SIZE 0x11B1 +#define CL_KERNEL_LOCAL_MEM_SIZE 0x11B2 +#define CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE 0x11B3 +#define CL_KERNEL_PRIVATE_MEM_SIZE 0x11B4 +#define CL_KERNEL_GLOBAL_WORK_SIZE 0x11B5 + +/* cl_kernel_exec_info */ +#define CL_KERNEL_EXEC_INFO_SVM_PTRS 0x11B6 +#define CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM 0x11B7 + +/* cl_event_info */ +#define CL_EVENT_COMMAND_QUEUE 0x11D0 +#define CL_EVENT_COMMAND_TYPE 0x11D1 +#define CL_EVENT_REFERENCE_COUNT 0x11D2 +#define CL_EVENT_COMMAND_EXECUTION_STATUS 0x11D3 +#define CL_EVENT_CONTEXT 0x11D4 + +/* cl_command_type */ +#define CL_COMMAND_NDRANGE_KERNEL 0x11F0 +#define CL_COMMAND_TASK 0x11F1 +#define CL_COMMAND_NATIVE_KERNEL 0x11F2 +#define CL_COMMAND_READ_BUFFER 0x11F3 +#define CL_COMMAND_WRITE_BUFFER 0x11F4 +#define CL_COMMAND_COPY_BUFFER 0x11F5 +#define CL_COMMAND_READ_IMAGE 0x11F6 +#define CL_COMMAND_WRITE_IMAGE 0x11F7 +#define CL_COMMAND_COPY_IMAGE 0x11F8 +#define CL_COMMAND_COPY_IMAGE_TO_BUFFER 0x11F9 +#define CL_COMMAND_COPY_BUFFER_TO_IMAGE 0x11FA +#define CL_COMMAND_MAP_BUFFER 0x11FB +#define CL_COMMAND_MAP_IMAGE 0x11FC +#define CL_COMMAND_UNMAP_MEM_OBJECT 0x11FD +#define CL_COMMAND_MARKER 0x11FE +#define CL_COMMAND_ACQUIRE_GL_OBJECTS 0x11FF +#define CL_COMMAND_RELEASE_GL_OBJECTS 0x1200 +#define CL_COMMAND_READ_BUFFER_RECT 0x1201 +#define CL_COMMAND_WRITE_BUFFER_RECT 0x1202 +#define CL_COMMAND_COPY_BUFFER_RECT 0x1203 +#define CL_COMMAND_USER 0x1204 +#define CL_COMMAND_BARRIER 0x1205 +#define CL_COMMAND_MIGRATE_MEM_OBJECTS 0x1206 +#define CL_COMMAND_FILL_BUFFER 0x1207 +#define CL_COMMAND_FILL_IMAGE 0x1208 +#define CL_COMMAND_SVM_FREE 0x1209 +#define CL_COMMAND_SVM_MEMCPY 0x120A +#define CL_COMMAND_SVM_MEMFILL 0x120B +#define CL_COMMAND_SVM_MAP 0x120C +#define CL_COMMAND_SVM_UNMAP 0x120D + +/* command execution status */ +#define CL_COMPLETE 0x0 +#define CL_RUNNING 0x1 +#define CL_SUBMITTED 0x2 +#define CL_QUEUED 0x3 + +/* cl_buffer_create_type */ +#define CL_BUFFER_CREATE_TYPE_REGION 0x1220 + +/* cl_profiling_info */ +#define CL_PROFILING_COMMAND_QUEUED 0x1280 +#define CL_PROFILING_COMMAND_SUBMIT 0x1281 +#define CL_PROFILING_COMMAND_START 0x1282 +#define CL_PROFILING_COMMAND_END 0x1283 +#define CL_PROFILING_COMMAND_COMPLETE 0x1284 + +/********************************************************************************************************/ + +/* Platform API */ +extern CL_API_ENTRY cl_int CL_API_CALL +clGetPlatformIDs(cl_uint /* num_entries */, + cl_platform_id * /* platforms */, + cl_uint * /* num_platforms */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetPlatformInfo(cl_platform_id /* platform */, + cl_platform_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Device APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceIDs(cl_platform_id /* platform */, + cl_device_type /* device_type */, + cl_uint /* num_entries */, + cl_device_id * /* devices */, + cl_uint * /* num_devices */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceInfo(cl_device_id /* device */, + cl_device_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clCreateSubDevices(cl_device_id /* in_device */, + const cl_device_partition_property * /* properties */, + cl_uint /* num_devices */, + cl_device_id * /* out_devices */, + cl_uint * /* num_devices_ret */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; + +/* Context APIs */ +extern CL_API_ENTRY cl_context CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_context CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetContextInfo(cl_context /* context */, + cl_context_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Command Queue APIs */ +extern CL_API_ENTRY cl_command_queue CL_API_CALL +clCreateCommandQueueWithProperties(cl_context /* context */, + cl_device_id /* device */, + const cl_queue_properties * /* properties */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetCommandQueueInfo(cl_command_queue /* command_queue */, + cl_command_queue_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Memory Object APIs */ +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateBuffer(cl_context /* context */, + cl_mem_flags /* flags */, + size_t /* size */, + void * /* host_ptr */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateSubBuffer(cl_mem /* buffer */, + cl_mem_flags /* flags */, + cl_buffer_create_type /* buffer_create_type */, + const void * /* buffer_create_info */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_mem CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreatePipe(cl_context /* context */, + cl_mem_flags /* flags */, + cl_uint /* pipe_packet_size */, + cl_uint /* pipe_max_packets */, + const cl_pipe_properties * /* properties */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetMemObjectInfo(cl_mem /* memobj */, + cl_mem_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetImageInfo(cl_mem /* image */, + cl_image_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetPipeInfo(cl_mem /* pipe */, + cl_pipe_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_2_0; + + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetMemObjectDestructorCallback(cl_mem /* memobj */, + void (CL_CALLBACK * /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), + void * /*user_data */ ) CL_API_SUFFIX__VERSION_1_1; + +/* SVM Allocation APIs */ +extern CL_API_ENTRY void * CL_API_CALL +clSVMAlloc(cl_context /* context */, + cl_svm_mem_flags /* flags */, + size_t /* size */, + cl_uint /* alignment */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY void CL_API_CALL +clSVMFree(cl_context /* context */, + void * /* svm_pointer */) CL_API_SUFFIX__VERSION_2_0; + +/* Sampler APIs */ +extern CL_API_ENTRY cl_sampler CL_API_CALL +clCreateSamplerWithProperties(cl_context /* context */, + const cl_sampler_properties * /* normalized_coords */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetSamplerInfo(cl_sampler /* sampler */, + cl_sampler_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Program Object APIs */ +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithSource(cl_context /* context */, + cl_uint /* count */, + const char ** /* strings */, + const size_t * /* lengths */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_program CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithBuiltInKernels(cl_context /* context */, + cl_uint /* num_devices */, + const cl_device_id * /* device_list */, + const char * /* kernel_names */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clCompileProgram(cl_program /* program */, + cl_uint /* num_devices */, + const cl_device_id * /* device_list */, + const char * /* options */, + cl_uint /* num_input_headers */, + const cl_program * /* input_headers */, + const char ** /* header_include_names */, + void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), + void * /* user_data */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_program CL_API_CALL +clLinkProgram(cl_context /* context */, + cl_uint /* num_devices */, + const cl_device_id * /* device_list */, + const char * /* options */, + cl_uint /* num_input_programs */, + const cl_program * /* input_programs */, + void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), + void * /* user_data */, + cl_int * /* errcode_ret */ ) CL_API_SUFFIX__VERSION_1_2; + + +extern CL_API_ENTRY cl_int CL_API_CALL +clUnloadPlatformCompiler(cl_platform_id /* platform */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetProgramInfo(cl_program /* program */, + cl_program_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +/* Kernel Object APIs */ +extern CL_API_ENTRY cl_kernel CL_API_CALL +clCreateKernel(cl_program /* program */, + const char * /* kernel_name */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clCreateKernelsInProgram(cl_program /* program */, + cl_uint /* num_kernels */, + cl_kernel * /* kernels */, + cl_uint * /* num_kernels_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainKernel(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseKernel(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArg(cl_kernel /* kernel */, + cl_uint /* arg_index */, + size_t /* arg_size */, + const void * /* arg_value */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArgSVMPointer(cl_kernel /* kernel */, + cl_uint /* arg_index */, + const void * /* arg_value */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelExecInfo(cl_kernel /* kernel */, + cl_kernel_exec_info /* param_name */, + size_t /* param_value_size */, + const void * /* param_value */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetKernelInfo(cl_kernel /* kernel */, + cl_kernel_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetKernelArgInfo(cl_kernel /* kernel */, + cl_uint /* arg_indx */, + cl_kernel_arg_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +/* Event Object APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clWaitForEvents(cl_uint /* num_events */, + const cl_event * /* event_list */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetEventInfo(cl_event /* event */, + cl_event_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_event CL_API_CALL +clCreateUserEvent(cl_context /* context */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetUserEventStatus(cl_event /* event */, + cl_int /* execution_status */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetEventCallback( cl_event /* event */, + cl_int /* command_exec_callback_type */, + void (CL_CALLBACK * /* pfn_notify */)(cl_event, cl_int, void *), + void * /* user_data */) CL_API_SUFFIX__VERSION_1_1; + +/* Profiling APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clGetEventProfilingInfo(cl_event /* event */, + cl_profiling_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Flush and Finish APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clFlush(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clFinish(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; + +/* Enqueued Commands APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadBufferRect(cl_command_queue /* command_queue */, + cl_mem /* buffer */, + cl_bool /* blocking_read */, + const size_t * /* buffer_offset */, + const size_t * /* host_offset */, + const size_t * /* region */, + size_t /* buffer_row_pitch */, + size_t /* buffer_slice_pitch */, + size_t /* host_row_pitch */, + size_t /* host_slice_pitch */, + void * /* ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteBufferRect(cl_command_queue /* command_queue */, + cl_mem /* buffer */, + cl_bool /* blocking_write */, + const size_t * /* buffer_offset */, + const size_t * /* host_offset */, + const size_t * /* region */, + size_t /* buffer_row_pitch */, + size_t /* buffer_slice_pitch */, + size_t /* host_row_pitch */, + size_t /* host_slice_pitch */, + const void * /* ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBuffer(cl_command_queue /* command_queue */, + cl_mem /* src_buffer */, + cl_mem /* dst_buffer */, + size_t /* src_offset */, + size_t /* dst_offset */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBufferRect(cl_command_queue /* command_queue */, + cl_mem /* src_buffer */, + cl_mem /* dst_buffer */, + const size_t * /* src_origin */, + const size_t * /* dst_origin */, + const size_t * /* region */, + size_t /* src_row_pitch */, + size_t /* src_slice_pitch */, + size_t /* dst_row_pitch */, + size_t /* dst_slice_pitch */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadImage(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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteImage(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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueFillImage(cl_command_queue /* command_queue */, + cl_mem /* image */, + const void * /* fill_color */, + const size_t * /* origin[3] */, + const size_t * /* region[3] */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyImage(cl_command_queue /* command_queue */, + cl_mem /* src_image */, + cl_mem /* dst_image */, + const size_t * /* src_origin[3] */, + const size_t * /* dst_origin[3] */, + const size_t * /* region[3] */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyImageToBuffer(cl_command_queue /* command_queue */, + cl_mem /* src_image */, + cl_mem /* dst_buffer */, + const size_t * /* src_origin[3] */, + const size_t * /* region[3] */, + size_t /* dst_offset */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBufferToImage(cl_command_queue /* command_queue */, + cl_mem /* src_buffer */, + cl_mem /* dst_image */, + size_t /* src_offset */, + const size_t * /* dst_origin[3] */, + const size_t * /* region[3] */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY void * CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY void * CL_API_CALL +clEnqueueMapImage(cl_command_queue /* command_queue */, + cl_mem /* image */, + cl_bool /* blocking_map */, + cl_map_flags /* map_flags */, + const size_t * /* origin[3] */, + const size_t * /* region[3] */, + 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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMigrateMemObjects(cl_command_queue /* command_queue */, + cl_uint /* num_mem_objects */, + const cl_mem * /* mem_objects */, + cl_mem_migration_flags /* flags */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueNativeKernel(cl_command_queue /* command_queue */, + void (CL_CALLBACK * /*user_func*/)(void *), + void * /* args */, + size_t /* cb_args */, + cl_uint /* num_mem_objects */, + const cl_mem * /* mem_list */, + const void ** /* args_mem_loc */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMarkerWithWaitList(cl_command_queue /* command_queue */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueBarrierWithWaitList(cl_command_queue /* command_queue */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMFree(cl_command_queue /* command_queue */, + cl_uint /* num_svm_pointers */, + void *[] /* svm_pointers[] */, + void (CL_CALLBACK * /*pfn_free_func*/)(cl_command_queue /* queue */, + cl_uint /* num_svm_pointers */, + void *[] /* svm_pointers[] */, + void * /* user_data */), + void * /* user_data */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemcpy(cl_command_queue /* command_queue */, + cl_bool /* blocking_copy */, + void * /* dst_ptr */, + const void * /* src_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemFill(cl_command_queue /* command_queue */, + void * /* svm_ptr */, + const void * /* pattern */, + size_t /* pattern_size */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMap(cl_command_queue /* command_queue */, + cl_bool /* blocking_map */, + cl_map_flags /* flags */, + void * /* svm_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMUnmap(cl_command_queue /* command_queue */, + void * /* svm_ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + + +/* Extension function access + * + * Returns the extension function address for the given function name, + * or NULL if a valid function can not be found. The client must + * check to make sure the address is not NULL, before using or + * calling the returned function address. + */ +extern CL_API_ENTRY void * CL_API_CALL +clGetExtensionFunctionAddressForPlatform(cl_platform_id /* platform */, + const char * /* func_name */) CL_API_SUFFIX__VERSION_1_2; + + +/* Deprecated OpenCL 1.1 APIs */ +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateImage2D(cl_context /* context */, + cl_mem_flags /* flags */, + const cl_image_format * /* image_format */, + size_t /* image_width */, + size_t /* image_height */, + size_t /* image_row_pitch */, + void * /* host_ptr */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateImage3D(cl_context /* context */, + cl_mem_flags /* flags */, + const cl_image_format * /* image_format */, + size_t /* image_width */, + size_t /* image_height */, + size_t /* image_depth */, + size_t /* image_row_pitch */, + size_t /* image_slice_pitch */, + void * /* host_ptr */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clEnqueueMarker(cl_command_queue /* command_queue */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clEnqueueWaitForEvents(cl_command_queue /* command_queue */, + cl_uint /* num_events */, + const cl_event * /* event_list */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clEnqueueBarrier(cl_command_queue /* command_queue */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clUnloadCompiler(void) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED void * CL_API_CALL +clGetExtensionFunctionAddress(const char * /* func_name */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +/* Deprecated OpenCL 2.0 APIs */ +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_command_queue CL_API_CALL +clCreateCommandQueue(cl_context /* context */, + cl_device_id /* device */, + cl_command_queue_properties /* properties */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; + + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_sampler CL_API_CALL +clCreateSampler(cl_context /* context */, + cl_bool /* normalized_coords */, + cl_addressing_mode /* addressing_mode */, + cl_filter_mode /* filter_mode */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int CL_API_CALL +clEnqueueTask(cl_command_queue /* command_queue */, + cl_kernel /* kernel */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_H */ + diff --git a/opencl/khronos/headers/opencl2.0/CL/cl.hpp b/opencl/khronos/headers/opencl2.0/CL/cl.hpp new file mode 100644 index 0000000000..3ea724593b --- /dev/null +++ b/opencl/khronos/headers/opencl2.0/CL/cl.hpp @@ -0,0 +1,12960 @@ +/* Modifications Copyright(C)[2021-2022] Advanced Micro Devices, Inc. + * All rights reserved. + * */ + +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +/*! \file + * + * \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33) and + * OpenCL 1.2 (rev 15) + * \author Benedict R. Gaster, Laurent Morichetti and Lee Howes + * + * Additions and fixes from: + * Brian Cole, March 3rd 2010 and April 2012 + * Matt Gruenke, April 2012. + * Bruce Merry, February 2013. + * Tom Deakin and Simon McIntosh-Smith, July 2013 + * + * \version 1.2.9 + * \date December 2015 + * + * Optional extension support + * + * cl + * cl_ext_device_fission + * #define USE_CL_DEVICE_FISSION + */ + +/*! \mainpage + * \section intro Introduction + * For many large applications C++ is the language of choice and so it seems + * reasonable to define C++ bindings for OpenCL. + * + * + * The interface is contained with a single C++ header file \em cl.hpp and all + * definitions are contained within the namespace \em cl. There is no additional + * requirement to include \em cl.h and to use either the C++ or original C + * bindings it is enough to simply include \em cl.hpp. + * + * The bindings themselves are lightweight and correspond closely to the + * underlying C API. Using the C++ bindings introduces no additional execution + * overhead. + * + * For detail documentation on the bindings see: + * + * The OpenCL C++ Wrapper API 1.2 (revision 09) + * http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.2.pdf + * + * \section example Example + * + * The following example shows a general use case for the C++ + * bindings, including support for the optional exception feature and + * also the supplied vector and string classes, see following sections for + * decriptions of these features. + * + * \code + * #define __CL_ENABLE_EXCEPTIONS + * + * #if defined(__APPLE__) || defined(__MACOSX) + * #include + * #else + * #include + * #endif + * #include + * #include + * #include + * + * const char * helloStr = "__kernel void " + * "hello(void) " + * "{ " + * " " + * "} "; + * + * int + * main(void) + * { + * cl_int err = CL_SUCCESS; + * try { + * + * std::vector platforms; + * cl::Platform::get(&platforms); + * if (platforms.size() == 0) { + * std::cout << "Platform size 0\n"; + * return -1; + * } + * + * cl_context_properties properties[] = + * { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0}; + * cl::Context context(CL_DEVICE_TYPE_CPU, properties); + * + * std::vector devices = context.getInfo(); + * + * cl::Program::Sources source(1, + * std::make_pair(helloStr,strlen(helloStr))); + * cl::Program program_ = cl::Program(context, source); + * program_.build(devices); + * + * cl::Kernel kernel(program_, "hello", &err); + * + * cl::Event event; + * cl::CommandQueue queue(context, devices[0], 0, &err); + * queue.enqueueNDRangeKernel( + * kernel, + * cl::NullRange, + * cl::NDRange(4,4), + * cl::NullRange, + * NULL, + * &event); + * + * event.wait(); + * } + * catch (cl::Error err) { + * std::cerr + * << "ERROR: " + * << err.what() + * << "(" + * << err.err() + * << ")" + * << std::endl; + * } + * + * return EXIT_SUCCESS; + * } + * + * \endcode + * + */ +#ifndef CL_HPP_ +#define CL_HPP_ + +#ifdef _WIN32 + +#include + +#if defined(USE_DX_INTEROP) +#include +#include +#endif +#endif // _WIN32 + +#if defined(_MSC_VER) +#include +#endif // _MSC_VER + +// +#if defined(USE_CL_DEVICE_FISSION) +#include +#endif + +#if defined(__APPLE__) || defined(__MACOSX) +#include +#else +#include +#endif // !__APPLE__ + +#if (_MSC_VER >= 1700) || (__cplusplus >= 201103L) +#define CL_HPP_RVALUE_REFERENCES_SUPPORTED +#define CL_HPP_CPP11_ATOMICS_SUPPORTED +#include +#endif + +#if (__cplusplus >= 201103L) +#define CL_HPP_NOEXCEPT noexcept +#else +#define CL_HPP_NOEXCEPT +#endif + + +// To avoid accidentally taking ownership of core OpenCL types +// such as cl_kernel constructors are made explicit +// under OpenCL 1.2 +#if defined(CL_VERSION_1_2) && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +#define __CL_EXPLICIT_CONSTRUCTORS explicit +#else // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +#define __CL_EXPLICIT_CONSTRUCTORS +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +// Define deprecated prefixes and suffixes to ensure compilation +// in case they are not pre-defined +#if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) + +#if !defined(CL_CALLBACK) +#define CL_CALLBACK +#endif //CL_CALLBACK + +#include +#include +#include + +#if defined(__CL_ENABLE_EXCEPTIONS) +#include +#endif // #if defined(__CL_ENABLE_EXCEPTIONS) + +#if !defined(__NO_STD_VECTOR) +#include +#endif + +#if !defined(__NO_STD_STRING) +#include +#endif + +#if defined(__ANDROID__) || defined(linux) || defined(__APPLE__) || defined(__MACOSX) +#include +#endif // linux + +#include + + +/*! \namespace cl + * + * \brief The OpenCL C++ bindings are defined within this namespace. + * + */ +namespace cl { + +class Memory; + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) +#define __INIT_CL_EXT_FCN_PTR(name) \ + if(!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddress(#name); \ + if(!pfn_##name) { \ + } \ + } +#endif // #if defined(CL_VERSION_1_1) + +#if defined(CL_VERSION_1_2) +#define __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, name) \ + if(!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddressForPlatform(platform, #name); \ + if(!pfn_##name) { \ + } \ + } +#endif // #if defined(CL_VERSION_1_1) + +class Program; +class Device; +class Context; +class CommandQueue; +class Memory; +class Buffer; + +#if defined(__CL_ENABLE_EXCEPTIONS) +/*! \brief Exception class + * + * This may be thrown by API functions when __CL_ENABLE_EXCEPTIONS is defined. + */ +class Error : public std::exception +{ +private: + cl_int err_; + const char * errStr_; +public: + /*! \brief Create a new CL error exception for a given error code + * and corresponding message. + * + * \param err error code value. + * + * \param errStr a descriptive string that must remain in scope until + * handling of the exception has concluded. If set, it + * will be returned by what(). + */ + Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr) + {} + + ~Error() throw() {} + + /*! \brief Get error string associated with exception + * + * \return A memory pointer to the error message string. + */ + virtual const char * what() const throw () + { + if (errStr_ == NULL) { + return "empty"; + } + else { + return errStr_; + } + } + + /*! \brief Get error code associated with exception + * + * \return The error code. + */ + cl_int err(void) const { return err_; } +}; + +#define __ERR_STR(x) #x +#else +#define __ERR_STR(x) NULL +#endif // __CL_ENABLE_EXCEPTIONS + + +namespace detail +{ +#if defined(__CL_ENABLE_EXCEPTIONS) +static inline cl_int errHandler ( + cl_int err, + const char * errStr = NULL) +{ + if (err != CL_SUCCESS) { + throw Error(err, errStr); + } + return err; +} +#else +static inline cl_int errHandler (cl_int err, const char * errStr = NULL) +{ + (void) errStr; // suppress unused variable warning + return err; +} +#endif // __CL_ENABLE_EXCEPTIONS +} + + + +//! \cond DOXYGEN_DETAIL +#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS) +#define __GET_DEVICE_INFO_ERR __ERR_STR(clGetDeviceInfo) +#define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo) +#define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs) +#define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs) +#define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo) +#define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo) +#define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo) +#define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo) +#define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo) +#define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo) +#define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo) +#if defined(CL_VERSION_1_2) +#define __GET_KERNEL_ARG_INFO_ERR __ERR_STR(clGetKernelArgInfo) +#endif // #if defined(CL_VERSION_1_2) +#define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo) +#define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo) +#define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo) +#define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo) + +#define __CREATE_CONTEXT_ERR __ERR_STR(clCreateContext) +#define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType) +#define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats) + +#define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer) +#define __COPY_ERR __ERR_STR(cl::copy) +#define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer) +#define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer) +#define __CREATE_GL_RENDER_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer) +#define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo) +#if defined(CL_VERSION_1_2) +#define __CREATE_IMAGE_ERR __ERR_STR(clCreateImage) +#define __CREATE_GL_TEXTURE_ERR __ERR_STR(clCreateFromGLTexture) +#define __IMAGE_DIMENSION_ERR __ERR_STR(Incorrect image dimensions) +#endif // #if defined(CL_VERSION_1_2) +#define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler) +#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback) + +#define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent) +#define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus) +#define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback) +#define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents) + +#define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel) +#define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg) +#define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource) +#define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary) +#if defined(CL_VERSION_1_2) +#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR __ERR_STR(clCreateProgramWithBuiltInKernels) +#endif // #if defined(CL_VERSION_1_2) +#define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram) +#if defined(CL_VERSION_1_2) +#define __COMPILE_PROGRAM_ERR __ERR_STR(clCompileProgram) +#define __LINK_PROGRAM_ERR __ERR_STR(clLinkProgram) +#endif // #if defined(CL_VERSION_1_2) +#define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram) + +#define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue) +#define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty) +#define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer) +#define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect) +#define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer) +#define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect) +#define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer) +#define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect) +#define __ENQUEUE_FILL_BUFFER_ERR __ERR_STR(clEnqueueFillBuffer) +#define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage) +#define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage) +#define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage) +#define __ENQUEUE_FILL_IMAGE_ERR __ERR_STR(clEnqueueFillImage) +#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer) +#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage) +#define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer) +#define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage) +#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject) +#define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel) +#define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask) +#define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel) +#if defined(CL_VERSION_1_2) +#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR __ERR_STR(clEnqueueMigrateMemObjects) +#endif // #if defined(CL_VERSION_1_2) + +#define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects) +#define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects) + + +#define __RETAIN_ERR __ERR_STR(Retain Object) +#define __RELEASE_ERR __ERR_STR(Release Object) +#define __FLUSH_ERR __ERR_STR(clFlush) +#define __FINISH_ERR __ERR_STR(clFinish) +#define __VECTOR_CAPACITY_ERR __ERR_STR(Vector capacity error) + +/** + * CL 1.2 version that uses device fission. + */ +#if defined(CL_VERSION_1_2) +#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevices) +#else +#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT) +#endif // #if defined(CL_VERSION_1_2) + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) +#define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker) +#define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents) +#define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier) +#define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler) +#define __CREATE_GL_TEXTURE_2D_ERR __ERR_STR(clCreateFromGLTexture2D) +#define __CREATE_GL_TEXTURE_3D_ERR __ERR_STR(clCreateFromGLTexture3D) +#define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D) +#define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D) +#endif // #if defined(CL_VERSION_1_1) + +#endif // __CL_USER_OVERRIDE_ERROR_STRINGS +//! \endcond + +/** + * CL 1.2 marker and barrier commands + */ +#if defined(CL_VERSION_1_2) +#define __ENQUEUE_MARKER_WAIT_LIST_ERR __ERR_STR(clEnqueueMarkerWithWaitList) +#define __ENQUEUE_BARRIER_WAIT_LIST_ERR __ERR_STR(clEnqueueBarrierWithWaitList) +#endif // #if defined(CL_VERSION_1_2) + +#if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING) +typedef std::string STRING_CLASS; +#elif !defined(__USE_DEV_STRING) + +/*! \class string + * \brief Simple string class, that provides a limited subset of std::string + * functionality but avoids many of the issues that come with that class. + + * \note Deprecated. Please use std::string as default or + * re-define the string class to match the std::string + * interface by defining STRING_CLASS + */ +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED string +{ +private: + ::size_t size_; + char * str_; +public: + //! \brief Constructs an empty string, allocating no memory. + string(void) : size_(0), str_(NULL) + { + } + + /*! \brief Constructs a string populated from an arbitrary value of + * specified size. + * + * An extra '\0' is added, in case none was contained in str. + * + * \param str the initial value of the string instance. Note that '\0' + * characters receive no special treatment. If NULL, + * the string is left empty, with a size of 0. + * + * \param size the number of characters to copy from str. + */ + string(const char * str, ::size_t size) : + size_(size), + str_(NULL) + { + if( size > 0 ) { + str_ = new char[size_+1]; + if (str_ != NULL) { + memcpy(str_, str, size_ * sizeof(char)); + str_[size_] = '\0'; + } + else { + size_ = 0; + } + } + } + + /*! \brief Constructs a string populated from a null-terminated value. + * + * \param str the null-terminated initial value of the string instance. + * If NULL, the string is left empty, with a size of 0. + */ + string(const char * str) : + size_(0), + str_(NULL) + { + if( str ) { + size_= ::strlen(str); + } + if( size_ > 0 ) { + str_ = new char[size_ + 1]; + if (str_ != NULL) { + memcpy(str_, str, (size_ + 1) * sizeof(char)); + } + } + } + + void resize( ::size_t n ) + { + if( size_ == n ) { + return; + } + if (n == 0) { + if( str_ ) { + delete [] str_; + } + str_ = NULL; + size_ = 0; + } + else { + char *newString = new char[n + 1]; + ::size_t copySize = n; + if( size_ < n ) { + copySize = size_; + } + size_ = n; + + if(str_) { + memcpy(newString, str_, (copySize + 1) * sizeof(char)); + } + if( copySize < size_ ) { + memset(newString + copySize, 0, size_ - copySize); + } + newString[size_] = '\0'; + + delete [] str_; + str_ = newString; + } + } + + const char& operator[] ( ::size_t pos ) const + { + return str_[pos]; + } + + char& operator[] ( ::size_t pos ) + { + return str_[pos]; + } + + /*! \brief Copies the value of another string to this one. + * + * \param rhs the string to copy. + * + * \returns a reference to the modified instance. + */ + string& operator=(const string& rhs) + { + if (this == &rhs) { + return *this; + } + + if( str_ != NULL ) { + delete [] str_; + str_ = NULL; + size_ = 0; + } + + if (rhs.size_ == 0 || rhs.str_ == NULL) { + str_ = NULL; + size_ = 0; + } + else { + str_ = new char[rhs.size_ + 1]; + size_ = rhs.size_; + + if (str_ != NULL) { + memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char)); + } + else { + size_ = 0; + } + } + + return *this; + } + + /*! \brief Constructs a string by copying the value of another instance. + * + * \param rhs the string to copy. + */ + string(const string& rhs) : + size_(0), + str_(NULL) + { + *this = rhs; + } + + //! \brief Destructor - frees memory used to hold the current value. + ~string() + { + delete[] str_; + str_ = NULL; + } + + //! \brief Queries the length of the string, excluding any added '\0's. + ::size_t size(void) const { return size_; } + + //! \brief Queries the length of the string, excluding any added '\0's. + ::size_t length(void) const { return size(); } + + /*! \brief Returns a pointer to the private copy held by this instance, + * or "" if empty/unset. + */ + const char * c_str(void) const { return (str_) ? str_ : "";} +} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +typedef cl::string STRING_CLASS; +#endif // #elif !defined(__USE_DEV_STRING) + +#if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR) +#define VECTOR_CLASS std::vector +#elif !defined(__USE_DEV_VECTOR) +#define VECTOR_CLASS cl::vector + +#if !defined(__MAX_DEFAULT_VECTOR_SIZE) +#define __MAX_DEFAULT_VECTOR_SIZE 10 +#endif + +/*! \class vector + * \brief Fixed sized vector implementation that mirroring + * + * \note Deprecated. Please use std::vector as default or + * re-define the vector class to match the std::vector + * interface by defining VECTOR_CLASS + + * \note Not recommended for use with custom objects as + * current implementation will construct N elements + * + * std::vector functionality. + * \brief Fixed sized vector compatible with std::vector. + * + * \note + * This differs from std::vector<> not just in memory allocation, + * but also in terms of when members are constructed, destroyed, + * and assigned instead of being copy constructed. + * + * \param T type of element contained in the vector. + * + * \param N maximum size of the vector. + */ +template +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED vector +{ +private: + T data_[N]; + unsigned int size_; + +public: + //! \brief Constructs an empty vector with no memory allocated. + vector() : + size_(static_cast(0)) + {} + + //! \brief Deallocates the vector's memory and destroys all of its elements. + ~vector() + { + clear(); + } + + //! \brief Returns the number of elements currently contained. + unsigned int size(void) const + { + return size_; + } + + /*! \brief Empties the vector of all elements. + * \note + * This does not deallocate memory but will invoke destructors + * on contained elements. + */ + void clear() + { + while(!empty()) { + pop_back(); + } + } + + /*! \brief Appends an element after the last valid element. + * Calling this on a vector that has reached capacity will throw an + * exception if exceptions are enabled. + */ + void push_back (const T& x) + { + if (size() < N) { + new (&data_[size_]) T(x); + size_++; + } else { + detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); + } + } + + /*! \brief Removes the last valid element from the vector. + * Calling this on an empty vector will throw an exception + * if exceptions are enabled. + */ + void pop_back(void) + { + if (size_ != 0) { + --size_; + data_[size_].~T(); + } else { + detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); + } + } + + /*! \brief Constructs with a value copied from another. + * + * \param vec the vector to copy. + */ + vector(const vector& vec) : + size_(vec.size_) + { + if (size_ != 0) { + assign(vec.begin(), vec.end()); + } + } + + /*! \brief Constructs with a specified number of initial elements. + * + * \param size number of initial elements. + * + * \param val value of initial elements. + */ + vector(unsigned int size, const T& val = T()) : + size_(0) + { + for (unsigned int i = 0; i < size; i++) { + push_back(val); + } + } + + /*! \brief Overwrites the current content with that copied from another + * instance. + * + * \param rhs vector to copy. + * + * \returns a reference to this. + */ + vector& operator=(const vector& rhs) + { + if (this == &rhs) { + return *this; + } + + if (rhs.size_ != 0) { + assign(rhs.begin(), rhs.end()); + } else { + clear(); + } + + return *this; + } + + /*! \brief Tests equality against another instance. + * + * \param vec the vector against which to compare. + */ + bool operator==(vector &vec) + { + if (size() != vec.size()) { + return false; + } + + for( unsigned int i = 0; i < size(); ++i ) { + if( operator[](i) != vec[i] ) { + return false; + } + } + return true; + } + + //! \brief Conversion operator to T*. + operator T* () { return data_; } + + //! \brief Conversion operator to const T*. + operator const T* () const { return data_; } + + //! \brief Tests whether this instance has any elements. + bool empty (void) const + { + return size_==0; + } + + //! \brief Returns the maximum number of elements this instance can hold. + unsigned int max_size (void) const + { + return N; + } + + //! \brief Returns the maximum number of elements this instance can hold. + unsigned int capacity () const + { + return N; + } + + //! \brief Resizes the vector to the given size + void resize(unsigned int newSize, T fill = T()) + { + if (newSize > N) + { + detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); + } + else + { + while (size_ < newSize) + { + new (&data_[size_]) T(fill); + size_++; + } + while (size_ > newSize) + { + --size_; + data_[size_].~T(); + } + } + } + + /*! \brief Returns a reference to a given element. + * + * \param index which element to access. * + * \note + * The caller is responsible for ensuring index is >= 0 and < size(). + */ + T& operator[](int index) + { + return data_[index]; + } + + /*! \brief Returns a const reference to a given element. + * + * \param index which element to access. + * + * \note + * The caller is responsible for ensuring index is >= 0 and < size(). + */ + const T& operator[](int index) const + { + return data_[index]; + } + + /*! \brief Assigns elements of the vector based on a source iterator range. + * + * \param start Beginning iterator of source range + * \param end Enditerator of source range + * + * \note + * Will throw an exception if exceptions are enabled and size exceeded. + */ + template + void assign(I start, I end) + { + clear(); + while(start != end) { + push_back(*start); + start++; + } + } + + /*! \class iterator + * \brief Const iterator class for vectors + */ + class iterator + { + private: + const vector *vec_; + int index_; + + /** + * Internal iterator constructor to capture reference + * to the vector it iterates over rather than taking + * the vector by copy. + */ + iterator (const vector &vec, int index) : + vec_(&vec) + { + if( !vec.empty() ) { + index_ = index; + } else { + index_ = -1; + } + } + + public: + iterator(void) : + index_(-1), + vec_(NULL) + { + } + + iterator(const iterator& rhs) : + vec_(rhs.vec_), + index_(rhs.index_) + { + } + + ~iterator(void) {} + + static iterator begin(const cl::vector &vec) + { + iterator i(vec, 0); + + return i; + } + + static iterator end(const cl::vector &vec) + { + iterator i(vec, vec.size()); + + return i; + } + + bool operator==(iterator i) + { + return ((vec_ == i.vec_) && + (index_ == i.index_)); + } + + bool operator!=(iterator i) + { + return (!(*this==i)); + } + + iterator& operator++() + { + ++index_; + return *this; + } + + iterator operator++(int) + { + iterator retVal(*this); + ++index_; + return retVal; + } + + iterator& operator--() + { + --index_; + return *this; + } + + iterator operator--(int) + { + iterator retVal(*this); + --index_; + return retVal; + } + + const T& operator *() const + { + return (*vec_)[index_]; + } + }; + + iterator begin(void) + { + return iterator::begin(*this); + } + + iterator begin(void) const + { + return iterator::begin(*this); + } + + iterator end(void) + { + return iterator::end(*this); + } + + iterator end(void) const + { + return iterator::end(*this); + } + + T& front(void) + { + return data_[0]; + } + + T& back(void) + { + return data_[size_]; + } + + const T& front(void) const + { + return data_[0]; + } + + const T& back(void) const + { + return data_[size_-1]; + } +} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +#endif // #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR) + + + + + +namespace detail { +#define __DEFAULT_NOT_INITIALIZED 1 +#define __DEFAULT_BEING_INITIALIZED 2 +#define __DEFAULT_INITIALIZED 4 + + /* + * Compare and exchange primitives are needed for handling of defaults + */ + +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + inline int compare_exchange(std::atomic * dest, int exchange, int comparand) +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED + inline int compare_exchange(volatile int * dest, int exchange, int comparand) +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + { +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + std::atomic_compare_exchange_strong(dest, &comparand, exchange); + return comparand; +#elif _MSC_VER + return (int)(_InterlockedCompareExchange( + (volatile long*)dest, + (long)exchange, + (long)comparand)); +#else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED + return (__sync_val_compare_and_swap( + dest, + comparand, + exchange)); +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + } + + inline void fence() { +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + std::atomic_thread_fence(std::memory_order_seq_cst); +#elif _MSC_VER // !CL_HPP_CPP11_ATOMICS_SUPPORTED + _ReadWriteBarrier(); +#else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED + __sync_synchronize(); +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + } +} // namespace detail + + +/*! \brief class used to interface between C++ and + * OpenCL C calls that require arrays of size_t values, whose + * size is known statically. + */ +template +class size_t +{ +private: + ::size_t data_[N]; + +public: + //! \brief Initialize size_t to all 0s + size_t() + { + for( int i = 0; i < N; ++i ) { + data_[i] = 0; + } + } + + ::size_t& operator[](int index) + { + return data_[index]; + } + + const ::size_t& operator[](int index) const + { + return data_[index]; + } + + //! \brief Conversion operator to T*. + operator ::size_t* () { return data_; } + + //! \brief Conversion operator to const T*. + operator const ::size_t* () const { return data_; } +}; + +namespace detail { + +// Generic getInfoHelper. The final parameter is used to guide overload +// resolution: the actual parameter passed is an int, which makes this +// a worse conversion sequence than a specialization that declares the +// parameter as an int. +template +inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long) +{ + return f(name, sizeof(T), param, NULL); +} + +// Specialized getInfoHelper for VECTOR_CLASS params +template +inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, long) +{ + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + T* value = (T*) alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + param->assign(&value[0], &value[required/sizeof(T)]); + return CL_SUCCESS; +} + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, int, typename T::cl_type = 0) +{ + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + typename T::cl_type * value = (typename T::cl_type *) alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + ::size_t elements = required / sizeof(typename T::cl_type); + param->assign(&value[0], &value[elements]); + for (::size_t i = 0; i < elements; i++) + { + if (value[i] != NULL) + { + err = (*param)[i].retain(); + if (err != CL_SUCCESS) { + return err; + } + } + } + return CL_SUCCESS; +} + +// Specialized for getInfo +template +inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, int) +{ + cl_int err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL); + + if (err != CL_SUCCESS) { + return err; + } + + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for STRING_CLASS params +template +inline cl_int getInfoHelper(Func f, cl_uint name, STRING_CLASS* param, long) +{ +#if defined(__NO_STD_VECTOR) || defined(__NO_STD_STRING) + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + char* value = (char*)alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + *param = value; + return CL_SUCCESS; +#else + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + // std::string has a constant data member + // a char vector does not + VECTOR_CLASS value(required); + err = f(name, required, value.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + if (param) { + param->assign(value.begin(), value.end()); + } +#endif + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for cl::size_t params +template +inline cl_int getInfoHelper(Func f, cl_uint name, size_t* param, long) +{ + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + ::size_t* value = (::size_t*) alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + for(int i = 0; i < N; ++i) { + (*param)[i] = value[i]; + } + + return CL_SUCCESS; +} + +template struct ReferenceHandler; + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0) +{ + typename T::cl_type value; + cl_int err = f(name, sizeof(value), &value, NULL); + if (err != CL_SUCCESS) { + return err; + } + *param = value; + if (value != NULL) + { + err = param->retain(); + if (err != CL_SUCCESS) { + return err; + } + } + return CL_SUCCESS; +} + +#define __PARAM_NAME_INFO_1_0(F) \ + F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \ + \ + F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \ + F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \ + F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \ + F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \ + F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \ + F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \ + F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \ + F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \ + F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \ + F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \ + \ + F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \ + F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS) \ + F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS) \ + \ + F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \ + F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \ + F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \ + F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \ + \ + F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \ + \ + F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \ + F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \ + F(cl_mem_info, CL_MEM_SIZE, ::size_t) \ + F(cl_mem_info, CL_MEM_HOST_PTR, void*) \ + F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \ + \ + F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \ + F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \ + F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \ + F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \ + F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \ + F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \ + F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \ + \ + F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \ + F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \ + F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \ + F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \ + F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \ + \ + F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \ + F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \ + F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \ + F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS) \ + F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \ + F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \ + F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS) \ + \ + F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \ + \ + F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \ + F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \ + F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \ + F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \ + F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \ + \ + F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \ + F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \ + F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \ + F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties) + +#if defined(CL_VERSION_1_1) +#define __PARAM_NAME_INFO_1_1(F) \ + F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \ + F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, STRING_CLASS) \ + \ + F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \ + F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \ + F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \ + \ + F(cl_event_info, CL_EVENT_CONTEXT, cl::Context) +#endif // CL_VERSION_1_1 + + +#if defined(CL_VERSION_1_2) +#define __PARAM_NAME_INFO_1_2(F) \ + F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer) \ + \ + F(cl_program_info, CL_PROGRAM_NUM_KERNELS, ::size_t) \ + F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, STRING_CLASS) \ + \ + F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \ + \ + F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, STRING_CLASS) \ + \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, STRING_CLASS) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, STRING_CLASS) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \ + \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl_device_id) \ + F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPE, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, ::size_t) \ + F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \ + F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, STRING_CLASS) +#endif // #if defined(CL_VERSION_1_2) + +#if defined(USE_CL_DEVICE_FISSION) +#define __PARAM_NAME_DEVICE_FISSION(F) \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \ + F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS) +#endif // USE_CL_DEVICE_FISSION + +template +struct param_traits {}; + +#define __CL_DECLARE_PARAM_TRAITS(token, param_name, T) \ +struct token; \ +template<> \ +struct param_traits \ +{ \ + enum { value = param_name }; \ + typedef T param_type; \ +}; + +__PARAM_NAME_INFO_1_0(__CL_DECLARE_PARAM_TRAITS) +#if defined(CL_VERSION_1_1) +__PARAM_NAME_INFO_1_1(__CL_DECLARE_PARAM_TRAITS) +#endif // CL_VERSION_1_1 +#if defined(CL_VERSION_1_2) +__PARAM_NAME_INFO_1_2(__CL_DECLARE_PARAM_TRAITS) +#endif // CL_VERSION_1_1 + +#if defined(USE_CL_DEVICE_FISSION) +__PARAM_NAME_DEVICE_FISSION(__CL_DECLARE_PARAM_TRAITS); +#endif // USE_CL_DEVICE_FISSION + +#ifdef CL_PLATFORM_ICD_SUFFIX_KHR +__CL_DECLARE_PARAM_TRAITS(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, STRING_CLASS) +#endif + +#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong) +#endif + +#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, VECTOR_CLASS< ::size_t>) +#endif +#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD, ::size_t) +#endif +#ifdef CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD, ::size_t) +#endif +#ifdef CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD, ::size_t) +#endif + +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint) +#endif +#ifdef CL_DEVICE_WARP_SIZE_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint) +#endif +#ifdef CL_DEVICE_GPU_OVERLAP_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool) +#endif +#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool) +#endif +#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool) +#endif + +// Convenience functions + +template +inline cl_int +getInfo(Func f, cl_uint name, T* param) +{ + return getInfoHelper(f, name, param, 0); +} + +template +struct GetInfoFunctor0 +{ + Func f_; const Arg0& arg0_; + cl_int operator ()( + cl_uint param, ::size_t size, void* value, ::size_t* size_ret) + { return f_(arg0_, param, size, value, size_ret); } +}; + +template +struct GetInfoFunctor1 +{ + Func f_; const Arg0& arg0_; const Arg1& arg1_; + cl_int operator ()( + cl_uint param, ::size_t size, void* value, ::size_t* size_ret) + { return f_(arg0_, arg1_, param, size, value, size_ret); } +}; + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, cl_uint name, T* param) +{ + GetInfoFunctor0 f0 = { f, arg0 }; + return getInfoHelper(f0, name, param, 0); +} + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param) +{ + GetInfoFunctor1 f0 = { f, arg0, arg1 }; + return getInfoHelper(f0, name, param, 0); +} + +template +struct ReferenceHandler +{ }; + +#if defined(CL_VERSION_1_2) +/** + * OpenCL 1.2 devices do have retain/release. + */ +template <> +struct ReferenceHandler +{ + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int retain(cl_device_id device) + { return ::clRetainDevice(device); } + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int release(cl_device_id device) + { return ::clReleaseDevice(device); } +}; +#else // #if defined(CL_VERSION_1_2) +/** + * OpenCL 1.1 devices do not have retain/release. + */ +template <> +struct ReferenceHandler +{ + // cl_device_id does not have retain(). + static cl_int retain(cl_device_id) + { return CL_SUCCESS; } + // cl_device_id does not have release(). + static cl_int release(cl_device_id) + { return CL_SUCCESS; } +}; +#endif // #if defined(CL_VERSION_1_2) + +template <> +struct ReferenceHandler +{ + // cl_platform_id does not have retain(). + static cl_int retain(cl_platform_id) + { return CL_SUCCESS; } + // cl_platform_id does not have release(). + static cl_int release(cl_platform_id) + { return CL_SUCCESS; } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_context context) + { return ::clRetainContext(context); } + static cl_int release(cl_context context) + { return ::clReleaseContext(context); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_command_queue queue) + { return ::clRetainCommandQueue(queue); } + static cl_int release(cl_command_queue queue) + { return ::clReleaseCommandQueue(queue); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_mem memory) + { return ::clRetainMemObject(memory); } + static cl_int release(cl_mem memory) + { return ::clReleaseMemObject(memory); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_sampler sampler) + { return ::clRetainSampler(sampler); } + static cl_int release(cl_sampler sampler) + { return ::clReleaseSampler(sampler); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_program program) + { return ::clRetainProgram(program); } + static cl_int release(cl_program program) + { return ::clReleaseProgram(program); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_kernel kernel) + { return ::clRetainKernel(kernel); } + static cl_int release(cl_kernel kernel) + { return ::clReleaseKernel(kernel); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_event event) + { return ::clRetainEvent(event); } + static cl_int release(cl_event event) + { return ::clReleaseEvent(event); } +}; + + +// Extracts version number with major in the upper 16 bits, minor in the lower 16 +static cl_uint getVersion(const char *versionInfo) +{ + int highVersion = 0; + int lowVersion = 0; + int index = 7; + while(versionInfo[index] != '.' ) { + highVersion *= 10; + highVersion += versionInfo[index]-'0'; + ++index; + } + ++index; + while(versionInfo[index] != ' ' && versionInfo[index] != '\0') { + lowVersion *= 10; + lowVersion += versionInfo[index]-'0'; + ++index; + } + return (highVersion << 16) | lowVersion; +} + +static cl_uint getPlatformVersion(cl_platform_id platform) +{ + ::size_t size = 0; + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size); + char *versionInfo = (char *) alloca(size); + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, &versionInfo[0], &size); + return getVersion(versionInfo); +} + +static cl_uint getDevicePlatformVersion(cl_device_id device) +{ + cl_platform_id platform; + clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL); + return getPlatformVersion(platform); +} + +#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +static cl_uint getContextPlatformVersion(cl_context context) +{ + // The platform cannot be queried directly, so we first have to grab a + // device and obtain its context + ::size_t size = 0; + clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size); + if (size == 0) + return 0; + cl_device_id *devices = (cl_device_id *) alloca(size); + clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices, NULL); + return getDevicePlatformVersion(devices[0]); +} +#endif // #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +template +class Wrapper +{ +public: + typedef T cl_type; + +protected: + cl_type object_; + +public: + Wrapper() : object_(NULL) { } + + Wrapper(const cl_type &obj) : object_(obj) { } + + ~Wrapper() + { + if (object_ != NULL) { release(); } + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT + { + object_ = rhs.object_; + rhs.object_ = NULL; + } +#endif + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + rhs.object_ = NULL; + } + return *this; + } +#endif + + Wrapper& operator = (const cl_type &rhs) + { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs; + return *this; + } + + cl_type operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + cl_int retain() const + { + return ReferenceHandler::retain(object_); + } + + cl_int release() const + { + return ReferenceHandler::release(object_); + } +}; + +template <> +class Wrapper +{ +public: + typedef cl_device_id cl_type; + +protected: + cl_type object_; + bool referenceCountable_; + + static bool isReferenceCountable(cl_device_id device) + { + bool retVal = false; + if (device != NULL) { + int version = getDevicePlatformVersion(device); + if(version > ((1 << 16) + 1)) { + retVal = true; + } + } + return retVal; + } + +public: + Wrapper() : object_(NULL), referenceCountable_(false) + { + } + + Wrapper(const cl_type &obj) : object_(obj), referenceCountable_(false) + { + referenceCountable_ = isReferenceCountable(obj); + } + + ~Wrapper() + { + if (object_ != NULL) { release(); } + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + referenceCountable_ = isReferenceCountable(object_); + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT + { + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } +#endif + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } + return *this; + } +#endif + + Wrapper& operator = (const cl_type &rhs) + { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs; + referenceCountable_ = isReferenceCountable(object_); + return *this; + } + + cl_type operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + template + friend inline cl_int getInfoHelper(Func, cl_uint, VECTOR_CLASS*, int, typename U::cl_type); + + cl_int retain() const + { + if( referenceCountable_ ) { + return ReferenceHandler::retain(object_); + } + else { + return CL_SUCCESS; + } + } + + cl_int release() const + { + if( referenceCountable_ ) { + return ReferenceHandler::release(object_); + } + else { + return CL_SUCCESS; + } + } +}; + +} // namespace detail +//! \endcond + +/*! \stuct ImageFormat + * \brief Adds constructors and member functions for cl_image_format. + * + * \see cl_image_format + */ +struct ImageFormat : public cl_image_format +{ + //! \brief Default constructor - performs no initialization. + ImageFormat(){} + + //! \brief Initializing constructor. + ImageFormat(cl_channel_order order, cl_channel_type type) + { + image_channel_order = order; + image_channel_data_type = type; + } + + //! \brief Assignment operator. + ImageFormat& operator = (const ImageFormat& rhs) + { + if (this != &rhs) { + this->image_channel_data_type = rhs.image_channel_data_type; + this->image_channel_order = rhs.image_channel_order; + } + return *this; + } +}; + +/*! \brief Class interface for cl_device_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_device_id + */ +class Device : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Device() : detail::Wrapper() { } + + /*! \brief Constructor from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + __CL_EXPLICIT_CONSTRUCTORS Device(const cl_device_id &device) : detail::Wrapper(device) { } + + /*! \brief Returns the first device on the default context. + * + * \see Context::getDefault() + */ + static Device getDefault(cl_int * err = NULL); + + /*! \brief Assignment operator from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + Device& operator = (const cl_device_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device(const Device& dev) : detail::Wrapper(dev) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (const Device &dev) + { + detail::Wrapper::operator=(dev); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Device(Device&& dev) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(dev)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (Device &&dev) + { + detail::Wrapper::operator=(std::move(dev)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetDeviceInfo(). + template + cl_int getInfo(cl_device_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetDeviceInfo, object_, name, param), + __GET_DEVICE_INFO_ERR); + } + + //! \brief Wrapper for clGetDeviceInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_device_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /** + * CL 1.2 version + */ +#if defined(CL_VERSION_1_2) + //! \brief Wrapper for clCreateSubDevicesEXT(). + cl_int createSubDevices( + const cl_device_partition_property * properties, + VECTOR_CLASS* devices) + { + cl_uint n = 0; + cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = clCreateSubDevices(object_, properties, n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } +#endif // #if defined(CL_VERSION_1_2) + +/** + * CL 1.1 version that uses device fission. + */ +#if defined(CL_VERSION_1_1) +#if defined(USE_CL_DEVICE_FISSION) + cl_int createSubDevices( + const cl_device_partition_property_ext * properties, + VECTOR_CLASS* devices) + { + typedef CL_API_ENTRY cl_int + ( CL_API_CALL * PFN_clCreateSubDevicesEXT)( + cl_device_id /*in_device*/, + const cl_device_partition_property_ext * /* properties */, + cl_uint /*num_entries*/, + cl_device_id * /*out_devices*/, + cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL; + __INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT); + + cl_uint n = 0; + cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } +#endif // #if defined(USE_CL_DEVICE_FISSION) +#endif // #if defined(CL_VERSION_1_1) +}; + +/*! \brief Class interface for cl_platform_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_platform_id + */ +class Platform : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Platform() : detail::Wrapper() { } + + /*! \brief Constructor from cl_platform_id. + * + * This simply copies the platform ID value, which is an inexpensive operation. + */ + __CL_EXPLICIT_CONSTRUCTORS Platform(const cl_platform_id &platform) : detail::Wrapper(platform) { } + + /*! \brief Assignment operator from cl_platform_id. + * + * This simply copies the platform ID value, which is an inexpensive operation. + */ + Platform& operator = (const cl_platform_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetPlatformInfo(). + cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetPlatformInfo, object_, name, param), + __GET_PLATFORM_INFO_ERR); + } + + //! \brief Wrapper for clGetPlatformInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_platform_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of devices for this platform. + * + * Wraps clGetDeviceIDs(). + */ + cl_int getDevices( + cl_device_type type, + VECTOR_CLASS* devices) const + { + cl_uint n = 0; + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = ::clGetDeviceIDs(object_, type, n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } + +#if defined(USE_DX_INTEROP) + /*! \brief Get the list of available D3D10 devices. + * + * \param d3d_device_source. + * + * \param d3d_object. + * + * \param d3d_device_set. + * + * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device + * values returned in devices can be used to identify a specific OpenCL + * device. If \a devices argument is NULL, this argument is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * + * The application can query specific capabilities of the OpenCL device(s) + * returned by cl::getDevices. This can be used by the application to + * determine which device(s) to use. + * + * \note In the case that exceptions are enabled and a return value + * other than CL_SUCCESS is generated, then cl::Error exception is + * generated. + */ + cl_int getDevices( + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + VECTOR_CLASS* devices) const + { + typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)( + cl_platform_id platform, + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint* num_devices); + + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + + static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL; + __INIT_CL_EXT_FCN_PTR_PLATFORM(object_, clGetDeviceIDsFromD3D10KHR); + + cl_uint n = 0; + cl_int err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + 0, + NULL, + &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + n, + ids, + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } +#endif + + /*! \brief Gets a list of available platforms. + * + * Wraps clGetPlatformIDs(). + */ + static cl_int get( + VECTOR_CLASS* platforms) + { + cl_uint n = 0; + + if( platforms == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); + } + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + cl_platform_id* ids = (cl_platform_id*) alloca( + n * sizeof(cl_platform_id)); + err = ::clGetPlatformIDs(n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + platforms->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } + + /*! \brief Gets the first available platform. + * + * Wraps clGetPlatformIDs(), returning the first result. + */ + static cl_int get( + Platform * platform) + { + cl_uint n = 0; + + if( platform == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); + } + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + cl_platform_id* ids = (cl_platform_id*) alloca( + n * sizeof(cl_platform_id)); + err = ::clGetPlatformIDs(n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + *platform = ids[0]; + return CL_SUCCESS; + } + + /*! \brief Gets the first available platform, returning it by value. + * + * Wraps clGetPlatformIDs(), returning the first result. + */ + static Platform get( + cl_int * errResult = NULL) + { + Platform platform; + cl_uint n = 0; + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + if (errResult != NULL) { + *errResult = err; + } + return Platform(); + } + + cl_platform_id* ids = (cl_platform_id*) alloca( + n * sizeof(cl_platform_id)); + err = ::clGetPlatformIDs(n, ids, NULL); + + if (err != CL_SUCCESS) { + detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + if (errResult != NULL) { + *errResult = err; + } + return Platform(); + } + + + return Platform(ids[0]); + } + + static Platform getDefault( + cl_int *errResult = NULL ) + { + return get(errResult); + } + + +#if defined(CL_VERSION_1_2) + //! \brief Wrapper for clUnloadCompiler(). + cl_int + unloadCompiler() + { + return ::clUnloadPlatformCompiler(object_); + } +#endif // #if defined(CL_VERSION_1_2) +}; // class Platform + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) +/** + * Unload the OpenCL compiler. + * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead. + */ +inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int +UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +inline cl_int +UnloadCompiler() +{ + return ::clUnloadCompiler(); +} +#endif // #if defined(CL_VERSION_1_1) + +/*! \brief Class interface for cl_context. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_context as the original. For details, see + * clRetainContext() and clReleaseContext(). + * + * \see cl_context + */ +class Context + : public detail::Wrapper +{ +private: + +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + static std::atomic default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static volatile int default_initialized_; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static Context default_; + static volatile cl_int default_error_; +public: + /*! \brief Constructs a context including a list of specified devices. + * + * Wraps clCreateContext(). + */ + Context( + const VECTOR_CLASS& devices, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + ::size_t, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + ::size_t numDevices = devices.size(); + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateContext( + properties, (cl_uint) numDevices, + deviceIDs, + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + Context( + const Device& device, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + ::size_t, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + cl_device_id deviceID = device(); + + object_ = ::clCreateContext( + properties, 1, + &deviceID, + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a context including all or a subset of devices of a specified type. + * + * Wraps clCreateContextFromType(). + */ + Context( + cl_device_type type, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + ::size_t, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + +#if !defined(__APPLE__) && !defined(__MACOS) + cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 }; + + if (properties == NULL) { + // Get a valid platform ID as we cannot send in a blank one + VECTOR_CLASS platforms; + error = Platform::get(&platforms); + if (error != CL_SUCCESS) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + // Check the platforms we found for a device of our specified type + cl_context_properties platform_id = 0; + for (unsigned int i = 0; i < platforms.size(); i++) { + + VECTOR_CLASS devices; + +#if defined(__CL_ENABLE_EXCEPTIONS) + try { +#endif + + error = platforms[i].getDevices(type, &devices); + +#if defined(__CL_ENABLE_EXCEPTIONS) + } catch (Error) {} + // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type + // We do error checking next anyway, and can throw there if needed +#endif + + // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND + if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + if (devices.size() > 0) { + platform_id = (cl_context_properties)platforms[i](); + break; + } + } + + if (platform_id == 0) { + detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = CL_DEVICE_NOT_FOUND; + } + return; + } + + prop[1] = platform_id; + properties = &prop[0]; + } +#endif + object_ = ::clCreateContextFromType( + properties, type, notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context(const Context& ctx) : detail::Wrapper(ctx) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (const Context &ctx) + { + detail::Wrapper::operator=(ctx); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Context(Context&& ctx) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(ctx)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (Context &&ctx) + { + detail::Wrapper::operator=(std::move(ctx)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT. + * + * \note All calls to this function return the same cl_context as the first. + */ + static Context getDefault(cl_int * err = NULL) + { + int state = detail::compare_exchange( + &default_initialized_, + __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED); + + if (state & __DEFAULT_INITIALIZED) { + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + if (state & __DEFAULT_BEING_INITIALIZED) { + // Assume writes will propagate eventually... + while(default_initialized_ != __DEFAULT_INITIALIZED) { + detail::fence(); + } + + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + cl_int error; + default_ = Context( + CL_DEVICE_TYPE_DEFAULT, + NULL, + NULL, + NULL, + &error); + + detail::fence(); + + default_error_ = error; + // Assume writes will propagate eventually... + default_initialized_ = __DEFAULT_INITIALIZED; + + detail::fence(); + + if (err != NULL) { + *err = default_error_; + } + return default_; + + } + + //! \brief Default constructor - initializes to NULL. + Context() : detail::Wrapper() { } + + /*! \brief Constructor from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_context + * into the new Context object. + */ + __CL_EXPLICIT_CONSTRUCTORS Context(const cl_context& context) : detail::Wrapper(context) { } + + /*! \brief Assignment operator from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseContext() on the value previously held by this instance. + */ + Context& operator = (const cl_context& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetContextInfo(). + template + cl_int getInfo(cl_context_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetContextInfo, object_, name, param), + __GET_CONTEXT_INFO_ERR); + } + + //! \brief Wrapper for clGetContextInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_context_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of supported image formats. + * + * Wraps clGetSupportedImageFormats(). + */ + cl_int getSupportedImageFormats( + cl_mem_flags flags, + cl_mem_object_type type, + VECTOR_CLASS* formats) const + { + cl_uint numEntries; + + if (!formats) { + return CL_SUCCESS; + } + + cl_int err = ::clGetSupportedImageFormats( + object_, + flags, + type, + 0, + NULL, + &numEntries); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + if (numEntries > 0) { + ImageFormat* value = (ImageFormat*) + alloca(numEntries * sizeof(ImageFormat)); + err = ::clGetSupportedImageFormats( + object_, + flags, + type, + numEntries, + (cl_image_format*)value, + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + formats->assign(&value[0], &value[numEntries]); + } + else { + formats->clear(); + } + return CL_SUCCESS; + } +}; + +inline Device Device::getDefault(cl_int * err) +{ + cl_int error; + Device device; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + device = context.getInfo()[0]; + if (err != NULL) { + *err = CL_SUCCESS; + } + } + + return device; +} + + +#ifdef _WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) std::atomic Context::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) Context Context::default_; +__declspec(selectany) volatile cl_int Context::default_error_ = CL_SUCCESS; +#else // !_WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) std::atomic Context::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) Context Context::default_; +__attribute__((weak)) volatile cl_int Context::default_error_ = CL_SUCCESS; +#endif // !_WIN32 + +/*! \brief Class interface for cl_event. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_event as the original. For details, see + * clRetainEvent() and clReleaseEvent(). + * + * \see cl_event + */ +class Event : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Event() : detail::Wrapper() { } + + /*! \brief Constructor from cl_event - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_event + * into the new Event object. + */ + __CL_EXPLICIT_CONSTRUCTORS Event(const cl_event& event) : detail::Wrapper(event) { } + + /*! \brief Assignment operator from cl_event - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseEvent() on the value previously held by this instance. + */ + Event& operator = (const cl_event& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetEventInfo(). + template + cl_int getInfo(cl_event_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetEventInfo, object_, name, param), + __GET_EVENT_INFO_ERR); + } + + //! \brief Wrapper for clGetEventInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_event_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + //! \brief Wrapper for clGetEventProfilingInfo(). + template + cl_int getProfilingInfo(cl_profiling_info name, T* param) const + { + return detail::errHandler(detail::getInfo( + &::clGetEventProfilingInfo, object_, name, param), + __GET_EVENT_PROFILE_INFO_ERR); + } + + //! \brief Wrapper for clGetEventProfilingInfo() that returns by value. + template typename + detail::param_traits::param_type + getProfilingInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_profiling_info, name>::param_type param; + cl_int result = getProfilingInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Blocks the calling thread until this event completes. + * + * Wraps clWaitForEvents(). + */ + cl_int wait() const + { + return detail::errHandler( + ::clWaitForEvents(1, &object_), + __WAIT_FOR_EVENTS_ERR); + } + +#if defined(CL_VERSION_1_1) + /*! \brief Registers a user callback function for a specific command execution status. + * + * Wraps clSetEventCallback(). + */ + cl_int setCallback( + cl_int type, + void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetEventCallback( + object_, + type, + pfn_notify, + user_data), + __SET_EVENT_CALLBACK_ERR); + } +#endif + + /*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ + static cl_int + waitForEvents(const VECTOR_CLASS& events) + { + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); + } +}; + +#if defined(CL_VERSION_1_1) +/*! \brief Class interface for user events (a subset of cl_event's). + * + * See Event for details about copy semantics, etc. + */ +class UserEvent : public Event +{ +public: + /*! \brief Constructs a user event on a given context. + * + * Wraps clCreateUserEvent(). + */ + UserEvent( + const Context& context, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateUserEvent( + context(), + &error); + + detail::errHandler(error, __CREATE_USER_EVENT_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + UserEvent() : Event() { } + + /*! \brief Sets the execution status of a user event object. + * + * Wraps clSetUserEventStatus(). + */ + cl_int setStatus(cl_int status) + { + return detail::errHandler( + ::clSetUserEventStatus(object_,status), + __SET_USER_EVENT_STATUS_ERR); + } +}; +#endif + +/*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ +inline static cl_int +WaitForEvents(const VECTOR_CLASS& events) +{ + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); +} + +/*! \brief Class interface for cl_mem. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_mem as the original. For details, see + * clRetainMemObject() and clReleaseMemObject(). + * + * \see cl_mem + */ +class Memory : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Memory() : detail::Wrapper() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_mem + * into the new Memory object. + */ + __CL_EXPLICIT_CONSTRUCTORS Memory(const cl_mem& memory) : detail::Wrapper(memory) { } + + /*! \brief Assignment operator from cl_mem - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseMemObject() on the value previously held by this instance. + */ + Memory& operator = (const cl_mem& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory(const Memory& mem) : detail::Wrapper(mem) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (const Memory &mem) + { + detail::Wrapper::operator=(mem); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory(Memory&& mem) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(mem)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (Memory &&mem) + { + detail::Wrapper::operator=(std::move(mem)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetMemObjectInfo(). + template + cl_int getInfo(cl_mem_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetMemObjectInfo, object_, name, param), + __GET_MEM_OBJECT_INFO_ERR); + } + + //! \brief Wrapper for clGetMemObjectInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_mem_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if defined(CL_VERSION_1_1) + /*! \brief Registers a callback function to be called when the memory object + * is no longer needed. + * + * Wraps clSetMemObjectDestructorCallback(). + * + * Repeated calls to this function, for a given cl_mem value, will append + * to the list of functions called (in reverse order) when memory object's + * resources are freed and the memory object is deleted. + * + * \note + * The registered callbacks are associated with the underlying cl_mem + * value - not the Memory class instance. + */ + cl_int setDestructorCallback( + void (CL_CALLBACK * pfn_notify)(cl_mem, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetMemObjectDestructorCallback( + object_, + pfn_notify, + user_data), + __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR); + } +#endif + +}; + +// Pre-declare copy functions +class Buffer; +template< typename IteratorType > +cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); + + +/*! \brief Class interface for Buffer Memory Objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Buffer : public Memory +{ +public: + + /*! \brief Constructs a Buffer in a specified context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + */ + Buffer( + const Context& context, + cl_mem_flags flags, + ::size_t size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a Buffer in the default context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + * + * \see Context::getDefault() + */ + Buffer( + cl_mem_flags flags, + ::size_t size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(err); + + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer( + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr = false, + cl_int* err = NULL) + { + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + ::size_t size = sizeof(DataType)*(endIterator - startIterator); + + Context context = Context::getDefault(err); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + error = cl::copy(startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified context. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified queue. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Buffer() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Buffer(const cl_mem& buffer) : Memory(buffer) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Buffer& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer(const Buffer& buf) : Memory(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (const Buffer &buf) + { + Memory::operator=(buf); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer(Buffer&& buf) CL_HPP_NOEXCEPT : Memory(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (Buffer &&buf) + { + Memory::operator=(std::move(buf)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + +#if defined(CL_VERSION_1_1) + /*! \brief Creates a new buffer object from this. + * + * Wraps clCreateSubBuffer(). + */ + Buffer createSubBuffer( + cl_mem_flags flags, + cl_buffer_create_type buffer_create_type, + const void * buffer_create_info, + cl_int * err = NULL) + { + Buffer result; + cl_int error; + result.object_ = ::clCreateSubBuffer( + object_, + flags, + buffer_create_type, + buffer_create_info, + &error); + + detail::errHandler(error, __CREATE_SUBBUFFER_ERR); + if (err != NULL) { + *err = error; + } + + return result; + } +#endif +}; + +#if defined (USE_DX_INTEROP) +/*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's. + * + * This is provided to facilitate interoperability with Direct3D. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferD3D10 : public Buffer +{ +public: + typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)( + cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer, + cl_int* errcode_ret); + + /*! \brief Constructs a BufferD3D10, in a specified context, from a + * given ID3D10Buffer. + * + * Wraps clCreateFromD3D10BufferKHR(). + */ + BufferD3D10( + const Context& context, + cl_mem_flags flags, + ID3D10Buffer* bufobj, + cl_int * err = NULL) + { + static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL; + +#if defined(CL_VERSION_1_2) + vector props = context.getInfo(); + cl_platform platform = -1; + for( int i = 0; i < props.size(); ++i ) { + if( props[i] == CL_CONTEXT_PLATFORM ) { + platform = props[i+1]; + } + } + __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clCreateFromD3D10BufferKHR); +#endif +#if defined(CL_VERSION_1_1) + __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR); +#endif + + cl_int error; + object_ = pfn_clCreateFromD3D10BufferKHR( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferD3D10() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS BufferD3D10(const cl_mem& buffer) : Buffer(buffer) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferD3D10& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(const BufferD3D10& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (const BufferD3D10 &buf) + { + Buffer::operator=(buf); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (BufferD3D10 &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif + +/*! \brief Class interface for GL Buffer Memory Objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferGL : public Buffer +{ +public: + /*! \brief Constructs a BufferGL in a specified context, from a given + * GL buffer. + * + * Wraps clCreateFromGLBuffer(). + */ + BufferGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLBuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferGL() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS BufferGL(const cl_mem& buffer) : Buffer(buffer) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferGL& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL(const BufferGL& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (const BufferGL &buf) + { + Buffer::operator=(buf); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (BufferGL &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_,type,gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief C++ base class for Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image : public Memory +{ +protected: + //! \brief Default constructor - initializes to NULL. + Image() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image(const cl_mem& image) : Memory(image) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image(const Image& img) : Memory(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (const Image &img) + { + Memory::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image(Image&& img) CL_HPP_NOEXCEPT : Memory(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (Image &&img) + { + Memory::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + +public: + //! \brief Wrapper for clGetImageInfo(). + template + cl_int getImageInfo(cl_image_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetImageInfo, object_, name, param), + __GET_IMAGE_INFO_ERR); + } + + //! \brief Wrapper for clGetImageInfo() that returns by value. + template typename + detail::param_traits::param_type + getImageInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_image_info, name>::param_type param; + cl_int result = getImageInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +#if defined(CL_VERSION_1_2) +/*! \brief Class interface for 1D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image1D : public Image +{ +public: + /*! \brief Constructs a 1D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image1D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D, + width, + 0, 0, 0, 0, 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image1D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image1D(const cl_mem& image1D) : Image(image1D) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image1D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D(const Image1D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (const Image1D &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D(Image1D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (Image1D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + +/*! \class Image1DBuffer + * \brief Image interface for 1D buffer images. + */ +class Image1DBuffer : public Image +{ +public: + Image1DBuffer( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + const Buffer &buffer, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_BUFFER, + width, + 0, 0, 0, 0, 0, 0, 0, + buffer() + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + NULL, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DBuffer() { } + + __CL_EXPLICIT_CONSTRUCTORS Image1DBuffer(const cl_mem& image1D) : Image(image1D) { } + + Image1DBuffer& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(const Image1DBuffer& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (const Image1DBuffer &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (Image1DBuffer &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + +/*! \class Image1DArray + * \brief Image interface for arrays of 1D images. + */ +class Image1DArray : public Image +{ +public: + Image1DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t arraySize, + ::size_t width, + ::size_t rowPitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_ARRAY, + width, + 0, 0, // height, depth (unused) + arraySize, + rowPitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DArray() { } + + __CL_EXPLICIT_CONSTRUCTORS Image1DArray(const cl_mem& imageArray) : Image(imageArray) { } + + Image1DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(const Image1DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (const Image1DArray &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (Image1DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if defined(CL_VERSION_1_2) + + +/*! \brief Class interface for 2D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image2D : public Image +{ +public: + /*! \brief Constructs a 1D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image2D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + ::size_t height, + ::size_t row_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif defined(CL_VERSION_1_2) + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if defined(CL_VERSION_1_2) + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D, + width, + height, + 0, 0, // depth, array size (unused) + row_pitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if defined(CL_VERSION_1_2) +#if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + if (!useCreateImage) + { + object_ = ::clCreateImage2D( + context(), flags,&format, width, height, row_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE2D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + } + + //! \brief Default constructor - initializes to NULL. + Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image2D(const cl_mem& image2D) : Image(image2D) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image2D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D(const Image2D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (const Image2D &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D(Image2D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (Image2D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + + +#if !defined(CL_VERSION_1_2) +/*! \brief Class interface for GL 2D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + * \note Deprecated for OpenCL 1.2. Please use ImageGL instead. + */ +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED : public Image2D +{ +public: + /*! \brief Constructs an Image2DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture2D(). + */ + Image2DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture2D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR); + if (err != NULL) { + *err = error; + } + + } + + //! \brief Default constructor - initializes to NULL. + Image2DGL() : Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image2DGL(const cl_mem& image) : Image2D(image) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image2DGL& operator = (const cl_mem& rhs) + { + Image2D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(const Image2DGL& img) : Image2D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (const Image2DGL &img) + { + Image2D::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT : Image2D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (Image2DGL &&img) + { + Image2D::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if !defined(CL_VERSION_1_2) + +#if defined(CL_VERSION_1_2) +/*! \class Image2DArray + * \brief Image interface for arrays of 2D images. + */ +class Image2DArray : public Image +{ +public: + Image2DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t arraySize, + ::size_t width, + ::size_t height, + ::size_t rowPitch, + ::size_t slicePitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D_ARRAY, + width, + height, + 0, // depth (unused) + arraySize, + rowPitch, + slicePitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image2DArray() { } + + __CL_EXPLICIT_CONSTRUCTORS Image2DArray(const cl_mem& imageArray) : Image(imageArray) { } + + Image2DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(const Image2DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (const Image2DArray &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (Image2DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if defined(CL_VERSION_1_2) + +/*! \brief Class interface for 3D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3D : public Image +{ +public: + /*! \brief Constructs a 3D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image3D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + ::size_t height, + ::size_t depth, + ::size_t row_pitch = 0, + ::size_t slice_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif defined(CL_VERSION_1_2) + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if defined(CL_VERSION_1_2) + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE3D, + width, + height, + depth, + 0, // array size (unused) + row_pitch, + slice_pitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if defined(CL_VERSION_1_2) +#if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + if (!useCreateImage) + { + object_ = ::clCreateImage3D( + context(), flags, &format, width, height, depth, row_pitch, + slice_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE3D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + } + + //! \brief Default constructor - initializes to NULL. + Image3D() : Image() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image3D(const cl_mem& image3D) : Image(image3D) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D(const Image3D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (const Image3D &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D(Image3D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (Image3D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + +#if !defined(CL_VERSION_1_2) +/*! \brief Class interface for GL 3D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3DGL : public Image3D +{ +public: + /*! \brief Constructs an Image3DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture3D(). + */ + Image3DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture3D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image3DGL() : Image3D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image3DGL(const cl_mem& image) : Image3D(image) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3DGL& operator = (const cl_mem& rhs) + { + Image3D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(const Image3DGL& img) : Image3D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (const Image3DGL &img) + { + Image3D::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT : Image3D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (Image3DGL &&img) + { + Image3D::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if !defined(CL_VERSION_1_2) + +#if defined(CL_VERSION_1_2) +/*! \class ImageGL + * \brief general image interface for GL interop. + * We abstract the 2D and 3D GL images into a single instance here + * that wraps all GL sourced images on the grounds that setup information + * was performed by OpenCL anyway. + */ +class ImageGL : public Image +{ +public: + ImageGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_ERR); + if (err != NULL) { + *err = error; + } + } + + ImageGL() : Image() { } + + __CL_EXPLICIT_CONSTRUCTORS ImageGL(const cl_mem& image) : Image(image) { } + + ImageGL& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL(const ImageGL& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (const ImageGL &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (ImageGL &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if defined(CL_VERSION_1_2) + +/*! \brief Class interface for GL Render Buffer Memory Objects. +* +* This is provided to facilitate interoperability with OpenGL. +* +* See Memory for details about copy semantics, etc. +* +* \see Memory +*/ +class BufferRenderGL : +#if defined(CL_VERSION_1_2) + public ImageGL +#else // #if defined(CL_VERSION_1_2) + public Image2DGL +#endif //#if defined(CL_VERSION_1_2) +{ +public: + /*! \brief Constructs a BufferRenderGL in a specified context, from a given + * GL Renderbuffer. + * + * Wraps clCreateFromGLRenderbuffer(). + */ + BufferRenderGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLRenderbuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. +#if defined(CL_VERSION_1_2) + BufferRenderGL() : ImageGL() {}; +#else // #if defined(CL_VERSION_1_2) + BufferRenderGL() : Image2DGL() {}; +#endif //#if defined(CL_VERSION_1_2) + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ +#if defined(CL_VERSION_1_2) + __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : ImageGL(buffer) { } +#else // #if defined(CL_VERSION_1_2) + __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : Image2DGL(buffer) { } +#endif //#if defined(CL_VERSION_1_2) + + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferRenderGL& operator = (const cl_mem& rhs) + { +#if defined(CL_VERSION_1_2) + ImageGL::operator=(rhs); +#else // #if defined(CL_VERSION_1_2) + Image2DGL::operator=(rhs); +#endif //#if defined(CL_VERSION_1_2) + + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ +#if defined(CL_VERSION_1_2) + BufferRenderGL(const BufferRenderGL& buf) : ImageGL(buf) {} +#else // #if defined(CL_VERSION_1_2) + BufferRenderGL(const BufferRenderGL& buf) : Image2DGL(buf) {} +#endif //#if defined(CL_VERSION_1_2) + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (const BufferRenderGL &rhs) + { +#if defined(CL_VERSION_1_2) + ImageGL::operator=(rhs); +#else // #if defined(CL_VERSION_1_2) + Image2DGL::operator=(rhs); +#endif //#if defined(CL_VERSION_1_2) + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ +#if defined(CL_VERSION_1_2) + BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : ImageGL(std::move(buf)) {} +#else // #if defined(CL_VERSION_1_2) + BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : Image2DGL(std::move(buf)) {} +#endif //#if defined(CL_VERSION_1_2) + + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (BufferRenderGL &&buf) + { +#if defined(CL_VERSION_1_2) + ImageGL::operator=(std::move(buf)); +#else // #if defined(CL_VERSION_1_2) + Image2DGL::operator=(std::move(buf)); +#endif //#if defined(CL_VERSION_1_2) + + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_, type, gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief Class interface for cl_sampler. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_sampler as the original. For details, see + * clRetainSampler() and clReleaseSampler(). + * + * \see cl_sampler + */ +class Sampler : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Sampler() { } + + /*! \brief Constructs a Sampler in a specified context. + * + * Wraps clCreateSampler(). + */ + Sampler( + const Context& context, + cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateSampler( + context(), + normalized_coords, + addressing_mode, + filter_mode, + &error); + + detail::errHandler(error, __CREATE_SAMPLER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructor from cl_sampler - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_sampler + * into the new Sampler object. + */ + __CL_EXPLICIT_CONSTRUCTORS Sampler(const cl_sampler& sampler) : detail::Wrapper(sampler) { } + + /*! \brief Assignment operator from cl_sampler - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseSampler() on the value previously held by this instance. + */ + Sampler& operator = (const cl_sampler& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler(const Sampler& sam) : detail::Wrapper(sam) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (const Sampler &sam) + { + detail::Wrapper::operator=(sam); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler(Sampler&& sam) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(sam)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (Sampler &&sam) + { + detail::Wrapper::operator=(std::move(sam)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetSamplerInfo(). + template + cl_int getInfo(cl_sampler_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetSamplerInfo, object_, name, param), + __GET_SAMPLER_INFO_ERR); + } + + //! \brief Wrapper for clGetSamplerInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_sampler_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +class Program; +class CommandQueue; +class Kernel; + +//! \brief Class interface for specifying NDRange values. +class NDRange +{ +private: + size_t<3> sizes_; + cl_uint dimensions_; + +public: + //! \brief Default constructor - resulting range has zero dimensions. + NDRange() + : dimensions_(0) + { } + + //! \brief Constructs one-dimensional range. + NDRange(::size_t size0) + : dimensions_(1) + { + sizes_[0] = size0; + } + + //! \brief Constructs two-dimensional range. + NDRange(::size_t size0, ::size_t size1) + : dimensions_(2) + { + sizes_[0] = size0; + sizes_[1] = size1; + } + + //! \brief Constructs three-dimensional range. + NDRange(::size_t size0, ::size_t size1, ::size_t size2) + : dimensions_(3) + { + sizes_[0] = size0; + sizes_[1] = size1; + sizes_[2] = size2; + } + + /*! \brief Conversion operator to const ::size_t *. + * + * \returns a pointer to the size of the first dimension. + */ + operator const ::size_t*() const { + return (const ::size_t*) sizes_; + } + + //! \brief Queries the number of dimensions in the range. + ::size_t dimensions() const { return dimensions_; } +}; + +//! \brief A zero-dimensional range. +static const NDRange NullRange; + +//! \brief Local address wrapper for use with Kernel::setArg +struct LocalSpaceArg +{ + ::size_t size_; +}; + +namespace detail { + +template +struct KernelArgumentHandler +{ + static ::size_t size(const T&) { return sizeof(T); } + static const T* ptr(const T& value) { return &value; } +}; + +template <> +struct KernelArgumentHandler +{ + static ::size_t size(const LocalSpaceArg& value) { return value.size_; } + static const void* ptr(const LocalSpaceArg&) { return NULL; } +}; + +} +//! \endcond + +/*! __local + * \brief Helper function for generating LocalSpaceArg objects. + * Deprecated. Replaced with Local. + */ +inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED LocalSpaceArg +__local(::size_t size) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +inline LocalSpaceArg +__local(::size_t size) +{ + LocalSpaceArg ret = { size }; + return ret; +} + +/*! Local + * \brief Helper function for generating LocalSpaceArg objects. + */ +inline LocalSpaceArg +Local(::size_t size) +{ + LocalSpaceArg ret = { size }; + return ret; +} + +//class KernelFunctor; + +/*! \brief Class interface for cl_kernel. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_kernel as the original. For details, see + * clRetainKernel() and clReleaseKernel(). + * + * \see cl_kernel + */ +class Kernel : public detail::Wrapper +{ +public: + inline Kernel(const Program& program, const char* name, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Kernel() { } + + /*! \brief Constructor from cl_kernel - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_kernel + * into the new Kernel object. + */ + __CL_EXPLICIT_CONSTRUCTORS Kernel(const cl_kernel& kernel) : detail::Wrapper(kernel) { } + + /*! \brief Assignment operator from cl_kernel - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseKernel() on the value previously held by this instance. + */ + Kernel& operator = (const cl_kernel& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel(const Kernel& kernel) : detail::Wrapper(kernel) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (const Kernel &kernel) + { + detail::Wrapper::operator=(kernel); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(kernel)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (Kernel &&kernel) + { + detail::Wrapper::operator=(std::move(kernel)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + template + cl_int getInfo(cl_kernel_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelInfo, object_, name, param), + __GET_KERNEL_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if defined(CL_VERSION_1_2) + template + cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param), + __GET_KERNEL_ARG_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getArgInfo(cl_uint argIndex, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_arg_info, name>::param_type param; + cl_int result = getArgInfo(argIndex, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +#endif // #if defined(CL_VERSION_1_2) + + template + cl_int getWorkGroupInfo( + const Device& device, cl_kernel_work_group_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetKernelWorkGroupInfo, object_, device(), name, param), + __GET_KERNEL_WORK_GROUP_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getWorkGroupInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_work_group_info, name>::param_type param; + cl_int result = getWorkGroupInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + template + cl_int setArg(cl_uint index, const T &value) + { + return detail::errHandler( + ::clSetKernelArg( + object_, + index, + detail::KernelArgumentHandler::size(value), + detail::KernelArgumentHandler::ptr(value)), + __SET_KERNEL_ARGS_ERR); + } + + cl_int setArg(cl_uint index, ::size_t size, const void* argPtr) + { + return detail::errHandler( + ::clSetKernelArg(object_, index, size, argPtr), + __SET_KERNEL_ARGS_ERR); + } +}; + +/*! \class Program + * \brief Program interface that implements cl_program. + */ +class Program : public detail::Wrapper +{ +public: + typedef VECTOR_CLASS > Binaries; + typedef VECTOR_CLASS > Sources; + + Program( + const STRING_CLASS& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const ::size_t length = source.size(); + + Context context = Context::getDefault(err); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + + error = ::clBuildProgram( + object_, + 0, + NULL, + "", + NULL, + NULL); + + detail::errHandler(error, __BUILD_PROGRAM_ERR); + } + + if (err != NULL) { + *err = error; + } + } + + Program( + const Context& context, + const STRING_CLASS& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const ::size_t length = source.size(); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + + error = ::clBuildProgram( + object_, + 0, + NULL, + "", + NULL, + NULL); + + detail::errHandler(error, __BUILD_PROGRAM_ERR); + } + + if (err != NULL) { + *err = error; + } + } + + Program( + const Context& context, + const Sources& sources, + cl_int* err = NULL) + { + cl_int error; + + const ::size_t n = (::size_t)sources.size(); + ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t)); + const char** strings = (const char**) alloca(n * sizeof(const char*)); + + for (::size_t i = 0; i < n; ++i) { + strings[i] = sources[(int)i].first; + lengths[i] = sources[(int)i].second; + } + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)n, strings, lengths, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + if (err != NULL) { + *err = error; + } + } + + /** + * Construct a program object from a list of devices and a per-device list of binaries. + * \param context A valid OpenCL context in which to construct the program. + * \param devices A vector of OpenCL device objects for which the program will be created. + * \param binaries A vector of pairs of a pointer to a binary object and its length. + * \param binaryStatus An optional vector that on completion will be resized to + * match the size of binaries and filled with values to specify if each binary + * was successfully loaded. + * Set to CL_SUCCESS if the binary was successfully loaded. + * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL. + * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device. + * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors: + * CL_INVALID_CONTEXT if context is not a valid context. + * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices; + * or if any entry in binaries is NULL or has length 0. + * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context. + * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device. + * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host. + */ + Program( + const Context& context, + const VECTOR_CLASS& devices, + const Binaries& binaries, + VECTOR_CLASS* binaryStatus = NULL, + cl_int* err = NULL) + { + cl_int error; + + const ::size_t numDevices = devices.size(); + + // Catch size mismatch early and return + if(binaries.size() != numDevices) { + error = CL_INVALID_VALUE; + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + ::size_t* lengths = (::size_t*) alloca(numDevices * sizeof(::size_t)); + const unsigned char** images = (const unsigned char**) alloca(numDevices * sizeof(const unsigned char**)); + + for (::size_t i = 0; i < numDevices; ++i) { + images[i] = (const unsigned char*)binaries[i].first; + lengths[i] = binaries[(int)i].second; + } + + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + if(binaryStatus) { + binaryStatus->resize(numDevices); + } + + object_ = ::clCreateProgramWithBinary( + context(), (cl_uint) devices.size(), + deviceIDs, + lengths, images, (binaryStatus != NULL && numDevices > 0) + ? &binaryStatus->front() + : NULL, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + } + + +#if defined(CL_VERSION_1_2) + /** + * Create program using builtin kernels. + * \param kernelNames Semi-colon separated list of builtin kernel names + */ + Program( + const Context& context, + const VECTOR_CLASS& devices, + const STRING_CLASS& kernelNames, + cl_int* err = NULL) + { + cl_int error; + + + ::size_t numDevices = devices.size(); + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateProgramWithBuiltInKernels( + context(), + (cl_uint) devices.size(), + deviceIDs, + kernelNames.c_str(), + &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if defined(CL_VERSION_1_2) + + Program() { } + + __CL_EXPLICIT_CONSTRUCTORS Program(const cl_program& program) : detail::Wrapper(program) { } + + Program& operator = (const cl_program& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program(const Program& program) : detail::Wrapper(program) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (const Program &program) + { + detail::Wrapper::operator=(program); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Program(Program&& program) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(program)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (Program &&program) + { + detail::Wrapper::operator=(std::move(program)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + cl_int build( + const VECTOR_CLASS& devices, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + ::size_t numDevices = devices.size(); + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + return detail::errHandler( + ::clBuildProgram( + object_, + (cl_uint) + devices.size(), + deviceIDs, + options, + notifyFptr, + data), + __BUILD_PROGRAM_ERR); + } + + cl_int build( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + return detail::errHandler( + ::clBuildProgram( + object_, + 0, + NULL, + options, + notifyFptr, + data), + __BUILD_PROGRAM_ERR); + } + +#if defined(CL_VERSION_1_2) + cl_int compile( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + return detail::errHandler( + ::clCompileProgram( + object_, + 0, + NULL, + options, + 0, + NULL, + NULL, + notifyFptr, + data), + __COMPILE_PROGRAM_ERR); + } +#endif + + template + cl_int getInfo(cl_program_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetProgramInfo, object_, name, param), + __GET_PROGRAM_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + template + cl_int getBuildInfo( + const Device& device, cl_program_build_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetProgramBuildInfo, object_, device(), name, param), + __GET_PROGRAM_BUILD_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getBuildInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_build_info, name>::param_type param; + cl_int result = getBuildInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + cl_int createKernels(VECTOR_CLASS* kernels) + { + cl_uint numKernels; + cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel)); + err = ::clCreateKernelsInProgram( + object_, numKernels, (cl_kernel*) value, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + kernels->assign(&value[0], &value[numKernels]); + return CL_SUCCESS; + } +}; + +#if defined(CL_VERSION_1_2) +inline Program linkProgram( + Program input1, + Program input2, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + cl_program programs[2] = { input1(), input2() }; + + Context ctx = input1.getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + 2, + programs, + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog); +} + +inline Program linkProgram( + VECTOR_CLASS inputPrograms, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + cl_program * programs = (cl_program*) alloca(inputPrograms.size() * sizeof(cl_program)); + + if (programs != NULL) { + for (unsigned int i = 0; i < inputPrograms.size(); i++) { + programs[i] = inputPrograms[i](); + } + } + + Context ctx; + if(inputPrograms.size() > 0) { + ctx = inputPrograms[0].getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + } + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + (cl_uint)inputPrograms.size(), + programs, + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog); +} +#endif + +template<> +inline VECTOR_CLASS cl::Program::getInfo(cl_int* err) const +{ + VECTOR_CLASS< ::size_t> sizes = getInfo(); + VECTOR_CLASS binaries; + for (VECTOR_CLASS< ::size_t>::iterator s = sizes.begin(); s != sizes.end(); ++s) + { + char *ptr = NULL; + if (*s != 0) + ptr = new char[*s]; + binaries.push_back(ptr); + } + + cl_int result = getInfo(CL_PROGRAM_BINARIES, &binaries); + if (err != NULL) { + *err = result; + } + return binaries; +} + +inline Kernel::Kernel(const Program& program, const char* name, cl_int* err) +{ + cl_int error; + + object_ = ::clCreateKernel(program(), name, &error); + detail::errHandler(error, __CREATE_KERNEL_ERR); + + if (err != NULL) { + *err = error; + } + +} + +/*! \class CommandQueue + * \brief CommandQueue interface for cl_command_queue. + */ +class CommandQueue : public detail::Wrapper +{ +private: +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + static std::atomic default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static volatile int default_initialized_; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static CommandQueue default_; + static volatile cl_int default_error_; +public: + CommandQueue( + cl_command_queue_properties properties, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } + } + } + /*! + * \brief Constructs a CommandQueue for an implementation defined device in the given context + */ + explicit CommandQueue( + const Context& context, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + VECTOR_CLASS devices; + error = context.getInfo(CL_CONTEXT_DEVICES, &devices); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) + { + if (err != NULL) { + *err = error; + } + return; + } + + object_ = ::clCreateCommandQueue(context(), devices[0](), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + + if (err != NULL) { + *err = error; + } + + } + + CommandQueue( + const Context& context, + const Device& device, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(const CommandQueue& queue) : detail::Wrapper(queue) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (const CommandQueue &queue) + { + detail::Wrapper::operator=(queue); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(queue)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (CommandQueue &&queue) + { + detail::Wrapper::operator=(std::move(queue)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + static CommandQueue getDefault(cl_int * err = NULL) + { + int state = detail::compare_exchange( + &default_initialized_, + __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED); + + if (state & __DEFAULT_INITIALIZED) { + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + if (state & __DEFAULT_BEING_INITIALIZED) { + // Assume writes will propagate eventually... + while(default_initialized_ != __DEFAULT_INITIALIZED) { + detail::fence(); + } + + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + + default_ = CommandQueue(context, device, 0, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } + } + + detail::fence(); + + default_error_ = error; + // Assume writes will propagate eventually... + default_initialized_ = __DEFAULT_INITIALIZED; + + detail::fence(); + + if (err != NULL) { + *err = default_error_; + } + return default_; + + } + + CommandQueue() { } + + __CL_EXPLICIT_CONSTRUCTORS CommandQueue(const cl_command_queue& commandQueue) : detail::Wrapper(commandQueue) { } + + CommandQueue& operator = (const cl_command_queue& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + template + cl_int getInfo(cl_command_queue_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetCommandQueueInfo, object_, name, param), + __GET_COMMAND_QUEUE_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_command_queue_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + ::size_t src_offset, + ::size_t dst_offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBuffer( + object_, src(), dst(), src_offset, dst_offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBufferRect( + object_, + buffer(), + blocking, + (const ::size_t *)buffer_offset, + (const ::size_t *)host_offset, + (const ::size_t *)region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + const void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBufferRect( + object_, + buffer(), + blocking, + (const ::size_t *)buffer_offset, + (const ::size_t *)host_offset, + (const ::size_t *)region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + ::size_t src_row_pitch, + ::size_t src_slice_pitch, + ::size_t dst_row_pitch, + ::size_t dst_slice_pitch, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferRect( + object_, + src(), + dst(), + (const ::size_t *)src_origin, + (const ::size_t *)dst_origin, + (const ::size_t *)region, + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_VERSION_1_2) + /** + * Enqueue a command to fill a buffer object with a pattern + * of a given size. The pattern is specified a as vector. + * \tparam PatternType The datatype of the pattern field. + * The pattern type must be an accepted OpenCL data type. + */ + template + cl_int enqueueFillBuffer( + const Buffer& buffer, + PatternType pattern, + ::size_t offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillBuffer( + object_, + buffer(), + static_cast(&pattern), + sizeof(PatternType), + offset, + size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_VERSION_1_2) + + cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadImage( + object_, image(), blocking, (const ::size_t *) origin, + (const ::size_t *) region, row_pitch, slice_pitch, ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteImage( + object_, image(), blocking, (const ::size_t *) origin, + (const ::size_t *) region, row_pitch, slice_pitch, ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImage( + object_, src(), dst(), (const ::size_t *) src_origin, + (const ::size_t *)dst_origin, (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_VERSION_1_2) + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA floating-point color value if + * the image channel data type is not an unnormalized signed or + * unsigned data type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_float4 fillColor, + const size_t<3>& origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + (const ::size_t *) origin, + (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA signed integer color value if + * the image channel data type is an unnormalized signed integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_int4 fillColor, + const size_t<3>& origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + (const ::size_t *) origin, + (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA unsigned integer color value if + * the image channel data type is an unnormalized unsigned integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_uint4 fillColor, + const size_t<3>& origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + (const ::size_t *) origin, + (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_VERSION_1_2) + + cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& region, + ::size_t dst_offset, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImageToBuffer( + object_, src(), dst(), (const ::size_t *) src_origin, + (const ::size_t *) region, dst_offset, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + ::size_t src_offset, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferToImage( + object_, src(), dst(), src_offset, + (const ::size_t *) dst_origin, (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + ::size_t offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapBuffer( + object_, buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + + return result; + } + + void* enqueueMapImage( + const Image& buffer, + cl_bool blocking, + cl_map_flags flags, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t * row_pitch, + ::size_t * slice_pitch, + const VECTOR_CLASS* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapImage( + object_, buffer(), blocking, flags, + (const ::size_t *) origin, (const ::size_t *) region, + row_pitch, slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + return result; + } + + cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + object_, memory(), mapped_ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_VERSION_1_2) + /** + * Enqueues a marker command which waits for either a list of events to complete, + * or all previously enqueued commands to complete. + * + * Enqueues a marker command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command returns an event which can be waited on, + * i.e. this event can be waited on to insure that all events either in the event_wait_list + * or all previously enqueued commands, queued before this command to command_queue, + * have completed. + */ + cl_int enqueueMarkerWithWaitList( + const VECTOR_CLASS *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarkerWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * A synchronization point that enqueues a barrier operation. + * + * Enqueues a barrier command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command blocks command execution, that is, any + * following commands enqueued after it do not execute until it completes. This command + * returns an event which can be waited on, i.e. this event can be waited on to insure that + * all events either in the event_wait_list or all previously enqueued commands, queued + * before this command to command_queue, have completed. + */ + cl_int enqueueBarrierWithWaitList( + const VECTOR_CLASS *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueBarrierWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_BARRIER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command to indicate with which device a set of memory objects + * should be associated. + */ + cl_int enqueueMigrateMemObjects( + const VECTOR_CLASS &memObjects, + cl_mem_migration_flags flags, + const VECTOR_CLASS* events = NULL, + Event* event = NULL + ) const + { + cl_event tmp; + + cl_mem* localMemObjects = static_cast(alloca(memObjects.size() * sizeof(cl_mem))); + for( int i = 0; i < (int)memObjects.size(); ++i ) { + localMemObjects[i] = memObjects[i](); + } + + + cl_int err = detail::errHandler( + ::clEnqueueMigrateMemObjects( + object_, + (cl_uint)memObjects.size(), + static_cast(localMemObjects), + flags, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_VERSION_1_2) + + cl_int enqueueNDRangeKernel( + const Kernel& kernel, + const NDRange& offset, + const NDRange& global, + const NDRange& local = NullRange, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNDRangeKernel( + object_, kernel(), (cl_uint) global.dimensions(), + offset.dimensions() != 0 ? (const ::size_t*) offset : NULL, + (const ::size_t*) global, + local.dimensions() != 0 ? (const ::size_t*) local : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NDRANGE_KERNEL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueTask( + const Kernel& kernel, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueTask( + object_, kernel(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_TASK_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueNativeKernel( + void (CL_CALLBACK *userFptr)(void *), + std::pair args, + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* mem_locs = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_mem * mems = (mem_objects != NULL && mem_objects->size() > 0) + ? (cl_mem*) alloca(mem_objects->size() * sizeof(cl_mem)) + : NULL; + + if (mems != NULL) { + for (unsigned int i = 0; i < mem_objects->size(); i++) { + mems[i] = ((*mem_objects)[i])(); + } + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNativeKernel( + object_, userFptr, args.first, args.second, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + mems, + (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NATIVE_KERNEL); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarker( + object_, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueWaitForEvents(const VECTOR_CLASS& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueWaitForEvents( + object_, + (cl_uint) events.size(), + events.size() > 0 ? (const cl_event*) &events.front() : NULL), + __ENQUEUE_WAIT_FOR_EVENTS_ERR); + } +#endif // #if defined(CL_VERSION_1_1) + + cl_int enqueueAcquireGLObjects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueAcquireGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseGLObjects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReleaseGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined (USE_DX_INTEROP) +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); + + cl_int enqueueAcquireD3D10Objects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL; +#if defined(CL_VERSION_1_2) + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueAcquireD3D10ObjectsKHR); +#endif +#if defined(CL_VERSION_1_1) + __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR); +#endif + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueAcquireD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseD3D10Objects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL; +#if defined(CL_VERSION_1_2) + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueReleaseD3D10ObjectsKHR); +#endif // #if defined(CL_VERSION_1_2) +#if defined(CL_VERSION_1_1) + __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR); +#endif // #if defined(CL_VERSION_1_1) + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueReleaseD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueBarrier(object_), + __ENQUEUE_BARRIER_ERR); + } +#endif // #if defined(CL_VERSION_1_1) + + cl_int flush() const + { + return detail::errHandler(::clFlush(object_), __FLUSH_ERR); + } + + cl_int finish() const + { + return detail::errHandler(::clFinish(object_), __FINISH_ERR); + } +}; + +#ifdef _WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) std::atomic CommandQueue::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) CommandQueue CommandQueue::default_; +__declspec(selectany) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS; +#else // !_WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) std::atomic CommandQueue::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) CommandQueue CommandQueue::default_; +__attribute__((weak)) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS; +#endif // !_WIN32 + +template< typename IteratorType > +Buffer::Buffer( + const Context &context, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + ::size_t size = sizeof(DataType)*(endIterator - startIterator); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + CommandQueue queue(context, 0, &error); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +template< typename IteratorType > +Buffer::Buffer( + const CommandQueue &queue, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if (readOnly) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + } + + ::size_t size = sizeof(DataType)*(endIterator - startIterator); + + Context context = queue.getInfo(); + + if (useHostPtr) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } + else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if (!useHostPtr) { + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +inline cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + ::size_t offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL, + cl_int* err = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + void * result = ::clEnqueueMapBuffer( + queue(), buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (cl_event*) event, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + return result; +} + +inline cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (error != CL_SUCCESS) { + return error; + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + queue(), memory(), mapped_ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; +} + +inline cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + ::size_t src_offset, + ::size_t dst_offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, startIterator, endIterator, buffer); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, buffer, startIterator, endIterator); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + ::size_t length = endIterator-startIterator; + ::size_t byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } +#if defined(_MSC_VER) + std::copy( + startIterator, + endIterator, + stdext::checked_array_iterator( + pointer, length)); +#else + std::copy(startIterator, endIterator, pointer); +#endif + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + ::size_t length = endIterator-startIterator; + ::size_t byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } + std::copy(pointer, pointer + length, startIterator); + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + +#if defined(CL_VERSION_1_1) +inline cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + const void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + ::size_t src_row_pitch, + ::size_t src_slice_pitch, + ::size_t dst_row_pitch, + ::size_t dst_slice_pitch, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferRect( + src, + dst, + src_origin, + dst_origin, + region, + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + events, + event); +} +#endif + +inline cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImage( + src, + dst, + src_origin, + dst_origin, + region, + events, + event); +} + +inline cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& region, + ::size_t dst_offset, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImageToBuffer( + src, + dst, + src_origin, + region, + dst_offset, + events, + event); +} + +inline cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + ::size_t src_offset, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferToImage( + src, + dst, + src_offset, + dst_origin, + region, + events, + event); +} + + +inline cl_int flush(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.flush(); +} + +inline cl_int finish(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + + return queue.finish(); +} + +// Kernel Functor support +// New interface as of September 2011 +// Requires the C++11 std::tr1::function (note do not support TR1) +// Visual Studio 2010 and GCC 4.2 + +struct EnqueueArgs +{ + CommandQueue queue_; + const NDRange offset_; + const NDRange global_; + const NDRange local_; + VECTOR_CLASS events_; + + EnqueueArgs(NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(Event e, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(const VECTOR_CLASS &events, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(const VECTOR_CLASS &events, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(const VECTOR_CLASS &events, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } +}; + +namespace detail { + +class NullType {}; + +template +struct SetArg +{ + static void set (Kernel kernel, T0 arg) + { + kernel.setArg(index, arg); + } +}; + +template +struct SetArg +{ + static void set (Kernel, NullType) + { + } +}; + +template < + typename T0, typename T1, typename T2, typename T3, + typename T4, typename T5, typename T6, typename T7, + typename T8, typename T9, typename T10, typename T11, + typename T12, typename T13, typename T14, typename T15, + typename T16, typename T17, typename T18, typename T19, + typename T20, typename T21, typename T22, typename T23, + typename T24, typename T25, typename T26, typename T27, + typename T28, typename T29, typename T30, typename T31 + +> +class KernelFunctorGlobal +{ +private: + Kernel kernel_; + +public: + KernelFunctorGlobal( + Kernel kernel) : + kernel_(kernel) + {} + + KernelFunctorGlobal( + const Program& program, + const STRING_CLASS name, + cl_int * err = NULL) : + kernel_(program, name.c_str(), err) + {} + + Event operator() ( + const EnqueueArgs& args, + T0 t0, + T1 t1 = NullType(), + T2 t2 = NullType(), + T3 t3 = NullType(), + T4 t4 = NullType(), + T5 t5 = NullType(), + T6 t6 = NullType(), + T7 t7 = NullType(), + T8 t8 = NullType(), + T9 t9 = NullType(), + T10 t10 = NullType(), + T11 t11 = NullType(), + T12 t12 = NullType(), + T13 t13 = NullType(), + T14 t14 = NullType(), + T15 t15 = NullType(), + T16 t16 = NullType(), + T17 t17 = NullType(), + T18 t18 = NullType(), + T19 t19 = NullType(), + T20 t20 = NullType(), + T21 t21 = NullType(), + T22 t22 = NullType(), + T23 t23 = NullType(), + T24 t24 = NullType(), + T25 t25 = NullType(), + T26 t26 = NullType(), + T27 t27 = NullType(), + T28 t28 = NullType(), + T29 t29 = NullType(), + T30 t30 = NullType(), + T31 t31 = NullType() + + ) + { + Event event; + SetArg<0, T0>::set(kernel_, t0); + SetArg<1, T1>::set(kernel_, t1); + SetArg<2, T2>::set(kernel_, t2); + SetArg<3, T3>::set(kernel_, t3); + SetArg<4, T4>::set(kernel_, t4); + SetArg<5, T5>::set(kernel_, t5); + SetArg<6, T6>::set(kernel_, t6); + SetArg<7, T7>::set(kernel_, t7); + SetArg<8, T8>::set(kernel_, t8); + SetArg<9, T9>::set(kernel_, t9); + SetArg<10, T10>::set(kernel_, t10); + SetArg<11, T11>::set(kernel_, t11); + SetArg<12, T12>::set(kernel_, t12); + SetArg<13, T13>::set(kernel_, t13); + SetArg<14, T14>::set(kernel_, t14); + SetArg<15, T15>::set(kernel_, t15); + SetArg<16, T16>::set(kernel_, t16); + SetArg<17, T17>::set(kernel_, t17); + SetArg<18, T18>::set(kernel_, t18); + SetArg<19, T19>::set(kernel_, t19); + SetArg<20, T20>::set(kernel_, t20); + SetArg<21, T21>::set(kernel_, t21); + SetArg<22, T22>::set(kernel_, t22); + SetArg<23, T23>::set(kernel_, t23); + SetArg<24, T24>::set(kernel_, t24); + SetArg<25, T25>::set(kernel_, t25); + SetArg<26, T26>::set(kernel_, t26); + SetArg<27, T27>::set(kernel_, t27); + SetArg<28, T28>::set(kernel_, t28); + SetArg<29, T29>::set(kernel_, t29); + SetArg<30, T30>::set(kernel_, t30); + SetArg<31, T31>::set(kernel_, t31); + + + args.queue_.enqueueNDRangeKernel( + kernel_, + args.offset_, + args.global_, + args.local_, + &args.events_, + &event); + + return event; + } + +}; + +//------------------------------------------------------------------------------------------------------ + + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28, + typename T29, + typename T30, + typename T31> +struct functionImplementation_ +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + T31> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 32)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + T31); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28, + T29 arg29, + T30 arg30, + T31 arg31) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28, + arg29, + arg30, + arg31); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28, + typename T29, + typename T30> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 31)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28, + T29 arg29, + T30 arg30) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28, + arg29, + arg30); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28, + typename T29> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 30)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28, + T29 arg29) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28, + arg29); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 29)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 28)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 27)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 26)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 25)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 24)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 23)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 22)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 21)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 20)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 19)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 18)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 17)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 16)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 15)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 14)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 13)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 12)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 11)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 10)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 9)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 8)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 7)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 6)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 5)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 4)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3); + } + + +}; + +template< + typename T0, + typename T1, + typename T2> +struct functionImplementation_ +< T0, + T1, + T2, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 3)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2); + } + + +}; + +template< + typename T0, + typename T1> +struct functionImplementation_ +< T0, + T1, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 2)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1) + { + return functor_( + enqueueArgs, + arg0, + arg1); + } + + +}; + +template< + typename T0> +struct functionImplementation_ +< T0, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 1)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0) + { + return functor_( + enqueueArgs, + arg0); + } + + +}; + + + + + +} // namespace detail + +//---------------------------------------------------------------------------------------------- + +template < + typename T0, typename T1 = detail::NullType, typename T2 = detail::NullType, + typename T3 = detail::NullType, typename T4 = detail::NullType, + typename T5 = detail::NullType, typename T6 = detail::NullType, + typename T7 = detail::NullType, typename T8 = detail::NullType, + typename T9 = detail::NullType, typename T10 = detail::NullType, + typename T11 = detail::NullType, typename T12 = detail::NullType, + typename T13 = detail::NullType, typename T14 = detail::NullType, + typename T15 = detail::NullType, typename T16 = detail::NullType, + typename T17 = detail::NullType, typename T18 = detail::NullType, + typename T19 = detail::NullType, typename T20 = detail::NullType, + typename T21 = detail::NullType, typename T22 = detail::NullType, + typename T23 = detail::NullType, typename T24 = detail::NullType, + typename T25 = detail::NullType, typename T26 = detail::NullType, + typename T27 = detail::NullType, typename T28 = detail::NullType, + typename T29 = detail::NullType, typename T30 = detail::NullType, + typename T31 = detail::NullType + +> +struct make_kernel : + public detail::functionImplementation_< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + > +{ +public: + typedef detail::KernelFunctorGlobal< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + > FunctorType; + + make_kernel( + const Program& program, + const STRING_CLASS name, + cl_int * err = NULL) : + detail::functionImplementation_< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + >( + FunctorType(program, name, err)) + {} + + make_kernel( + const Kernel kernel) : + detail::functionImplementation_< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + >( + FunctorType(kernel)) + {} +}; + + +//---------------------------------------------------------------------------------------------------------------------- + +#undef __ERR_STR +#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS) +#undef __GET_DEVICE_INFO_ERR +#undef __GET_PLATFORM_INFO_ERR +#undef __GET_DEVICE_IDS_ERR +#undef __GET_CONTEXT_INFO_ERR +#undef __GET_EVENT_INFO_ERR +#undef __GET_EVENT_PROFILE_INFO_ERR +#undef __GET_MEM_OBJECT_INFO_ERR +#undef __GET_IMAGE_INFO_ERR +#undef __GET_SAMPLER_INFO_ERR +#undef __GET_KERNEL_INFO_ERR +#undef __GET_KERNEL_ARG_INFO_ERR +#undef __GET_KERNEL_WORK_GROUP_INFO_ERR +#undef __GET_PROGRAM_INFO_ERR +#undef __GET_PROGRAM_BUILD_INFO_ERR +#undef __GET_COMMAND_QUEUE_INFO_ERR + +#undef __CREATE_CONTEXT_ERR +#undef __CREATE_CONTEXT_FROM_TYPE_ERR +#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR + +#undef __CREATE_BUFFER_ERR +#undef __CREATE_SUBBUFFER_ERR +#undef __CREATE_IMAGE2D_ERR +#undef __CREATE_IMAGE3D_ERR +#undef __CREATE_SAMPLER_ERR +#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR + +#undef __CREATE_USER_EVENT_ERR +#undef __SET_USER_EVENT_STATUS_ERR +#undef __SET_EVENT_CALLBACK_ERR +#undef __SET_PRINTF_CALLBACK_ERR + +#undef __WAIT_FOR_EVENTS_ERR + +#undef __CREATE_KERNEL_ERR +#undef __SET_KERNEL_ARGS_ERR +#undef __CREATE_PROGRAM_WITH_SOURCE_ERR +#undef __CREATE_PROGRAM_WITH_BINARY_ERR +#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR +#undef __BUILD_PROGRAM_ERR +#undef __CREATE_KERNELS_IN_PROGRAM_ERR + +#undef __CREATE_COMMAND_QUEUE_ERR +#undef __SET_COMMAND_QUEUE_PROPERTY_ERR +#undef __ENQUEUE_READ_BUFFER_ERR +#undef __ENQUEUE_WRITE_BUFFER_ERR +#undef __ENQUEUE_READ_BUFFER_RECT_ERR +#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR +#undef __ENQEUE_COPY_BUFFER_ERR +#undef __ENQEUE_COPY_BUFFER_RECT_ERR +#undef __ENQUEUE_READ_IMAGE_ERR +#undef __ENQUEUE_WRITE_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR +#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR +#undef __ENQUEUE_MAP_BUFFER_ERR +#undef __ENQUEUE_MAP_IMAGE_ERR +#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR +#undef __ENQUEUE_NDRANGE_KERNEL_ERR +#undef __ENQUEUE_TASK_ERR +#undef __ENQUEUE_NATIVE_KERNEL + +#undef __CL_EXPLICIT_CONSTRUCTORS + +#undef __UNLOAD_COMPILER_ERR +#endif //__CL_USER_OVERRIDE_ERROR_STRINGS + +#undef __CL_FUNCTION_TYPE + +// Extensions +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_VERSION_1_1) +#undef __INIT_CL_EXT_FCN_PTR +#endif // #if defined(CL_VERSION_1_1) +#undef __CREATE_SUB_DEVICES + +#if defined(USE_CL_DEVICE_FISSION) +#undef __PARAM_NAME_DEVICE_FISSION +#endif // USE_CL_DEVICE_FISSION + +#undef __DEFAULT_NOT_INITIALIZED +#undef __DEFAULT_BEING_INITIALIZED +#undef __DEFAULT_INITIALIZED + +#undef CL_HPP_RVALUE_REFERENCES_SUPPORTED +#undef CL_HPP_NOEXCEPT + +} // namespace cl + +#endif // CL_HPP_ diff --git a/opencl/khronos/headers/opencl2.0/CL/cl2.hpp b/opencl/khronos/headers/opencl2.0/CL/cl2.hpp new file mode 100644 index 0000000000..4d9ca2363a --- /dev/null +++ b/opencl/khronos/headers/opencl2.0/CL/cl2.hpp @@ -0,0 +1,9579 @@ +/* Modifications Copyright(C)[2021-2022] Advanced Micro Devices, Inc. + * All rights reserved. + * */ + +/******************************************************************************* + * Copyright (c) 2008-2016 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +/*! \file + * + * \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33), + * OpenCL 1.2 (rev 15) and OpenCL 2.0 (rev 29) + * \author Lee Howes and Bruce Merry + * + * Derived from the OpenCL 1.x C++ bindings written by + * Benedict R. Gaster, Laurent Morichetti and Lee Howes + * With additions and fixes from: + * Brian Cole, March 3rd 2010 and April 2012 + * Matt Gruenke, April 2012. + * Bruce Merry, February 2013. + * Tom Deakin and Simon McIntosh-Smith, July 2013 + * James Price, 2015- + * + * \version 2.0.10 + * \date 2016-07-20 + * + * Optional extension support + * + * cl_ext_device_fission + * #define CL_HPP_USE_CL_DEVICE_FISSION + * cl_khr_d3d10_sharing + * #define CL_HPP_USE_DX_INTEROP + * cl_khr_sub_groups + * #define CL_HPP_USE_CL_SUB_GROUPS_KHR + * cl_khr_image2d_from_buffer + * #define CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR + * + * Doxygen documentation for this header is available here: + * + * http://khronosgroup.github.io/OpenCL-CLHPP/ + * + * The latest version of this header can be found on the GitHub releases page: + * + * https://github.com/KhronosGroup/OpenCL-CLHPP/releases + * + * Bugs and patches can be submitted to the GitHub repository: + * + * https://github.com/KhronosGroup/OpenCL-CLHPP + */ + +/*! \mainpage + * \section intro Introduction + * For many large applications C++ is the language of choice and so it seems + * reasonable to define C++ bindings for OpenCL. + * + * The interface is contained with a single C++ header file \em cl2.hpp and all + * definitions are contained within the namespace \em cl. There is no additional + * requirement to include \em cl.h and to use either the C++ or original C + * bindings; it is enough to simply include \em cl2.hpp. + * + * The bindings themselves are lightweight and correspond closely to the + * underlying C API. Using the C++ bindings introduces no additional execution + * overhead. + * + * There are numerous compatibility, portability and memory management + * fixes in the new header as well as additional OpenCL 2.0 features. + * As a result the header is not directly backward compatible and for this + * reason we release it as cl2.hpp rather than a new version of cl.hpp. + * + * + * \section compatibility Compatibility + * Due to the evolution of the underlying OpenCL API the 2.0 C++ bindings + * include an updated approach to defining supported feature versions + * and the range of valid underlying OpenCL runtime versions supported. + * + * The combination of preprocessor macros CL_HPP_TARGET_OPENCL_VERSION and + * CL_HPP_MINIMUM_OPENCL_VERSION control this range. These are three digit + * decimal values representing OpenCL runime versions. The default for + * the target is 200, representing OpenCL 2.0 and the minimum is also + * defined as 200. These settings would use 2.0 API calls only. + * If backward compatibility with a 1.2 runtime is required, the minimum + * version may be set to 120. + * + * Note that this is a compile-time setting, and so affects linking against + * a particular SDK version rather than the versioning of the loaded runtime. + * + * The earlier versions of the header included basic vector and string + * classes based loosely on STL versions. These were difficult to + * maintain and very rarely used. For the 2.0 header we now assume + * the presence of the standard library unless requested otherwise. + * We use std::array, std::vector, std::shared_ptr and std::string + * throughout to safely manage memory and reduce the chance of a + * recurrance of earlier memory management bugs. + * + * These classes are used through typedefs in the cl namespace: + * cl::array, cl::vector, cl::pointer and cl::string. + * In addition cl::allocate_pointer forwards to std::allocate_shared + * by default. + * In all cases these standard library classes can be replaced with + * custom interface-compatible versions using the CL_HPP_NO_STD_ARRAY, + * CL_HPP_NO_STD_VECTOR, CL_HPP_NO_STD_UNIQUE_PTR and + * CL_HPP_NO_STD_STRING macros. + * + * The OpenCL 1.x versions of the C++ bindings included a size_t wrapper + * class to interface with kernel enqueue. This caused unpleasant interactions + * with the standard size_t declaration and led to namespacing bugs. + * In the 2.0 version we have replaced this with a std::array-based interface. + * However, the old behaviour can be regained for backward compatibility + * using the CL_HPP_ENABLE_SIZE_T_COMPATIBILITY macro. + * + * Finally, the program construction interface used a clumsy vector-of-pairs + * design in the earlier versions. We have replaced that with a cleaner + * vector-of-vectors and vector-of-strings design. However, for backward + * compatibility old behaviour can be regained with the + * CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY macro. + * + * In OpenCL 2.0 OpenCL C is not entirely backward compatibility with + * earlier versions. As a result a flag must be passed to the OpenCL C + * compiled to request OpenCL 2.0 compilation of kernels with 1.2 as + * the default in the absence of the flag. + * In some cases the C++ bindings automatically compile code for ease. + * For those cases the compilation defaults to OpenCL C 2.0. + * If this is not wanted, the CL_HPP_CL_1_2_DEFAULT_BUILD macro may + * be specified to assume 1.2 compilation. + * If more fine-grained decisions on a per-kernel bases are required + * then explicit build operations that take the flag should be used. + * + * + * \section parameterization Parameters + * This header may be parameterized by a set of preprocessor macros. + * + * - CL_HPP_TARGET_OPENCL_VERSION + * + * Defines the target OpenCL runtime version to build the header + * against. Defaults to 200, representing OpenCL 2.0. + * + * - CL_HPP_NO_STD_STRING + * + * Do not use the standard library string class. cl::string is not + * defined and may be defined by the user before cl2.hpp is + * included. + * + * - CL_HPP_NO_STD_VECTOR + * + * Do not use the standard library vector class. cl::vector is not + * defined and may be defined by the user before cl2.hpp is + * included. + * + * - CL_HPP_NO_STD_ARRAY + * + * Do not use the standard library array class. cl::array is not + * defined and may be defined by the user before cl2.hpp is + * included. + * + * - CL_HPP_NO_STD_UNIQUE_PTR + * + * Do not use the standard library unique_ptr class. cl::pointer and + * the cl::allocate_pointer functions are not defined and may be + * defined by the user before cl2.hpp is included. + * + * - CL_HPP_ENABLE_DEVICE_FISSION + * + * Enables device fission for OpenCL 1.2 platforms. + * + * - CL_HPP_ENABLE_EXCEPTIONS + * + * Enable exceptions for use in the C++ bindings header. This is the + * preferred error handling mechanism but is not required. + * + * - CL_HPP_ENABLE_SIZE_T_COMPATIBILITY + * + * Backward compatibility option to support cl.hpp-style size_t + * class. Replaces the updated std::array derived version and + * removal of size_t from the namespace. Note that in this case the + * new size_t class is placed in the cl::compatibility namespace and + * thus requires an additional using declaration for direct backward + * compatibility. + * + * - CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY + * + * Enable older vector of pairs interface for construction of + * programs. + * + * - CL_HPP_CL_1_2_DEFAULT_BUILD + * + * Default to OpenCL C 1.2 compilation rather than OpenCL C 2.0 + * applies to use of cl::Program construction and other program + * build variants. + * + * + * \section example Example + * + * The following example shows a general use case for the C++ + * bindings, including support for the optional exception feature and + * also the supplied vector and string classes, see following sections for + * decriptions of these features. + * + * \code + #define CL_HPP_ENABLE_EXCEPTIONS + #define CL_HPP_TARGET_OPENCL_VERSION 200 + + #include + #include + #include + #include + #include + + const int numElements = 32; + + int main(void) + { + // Filter for a 2.0 platform and set it as the default + std::vector platforms; + cl::Platform::get(&platforms); + cl::Platform plat; + for (auto &p : platforms) { + std::string platver = p.getInfo(); + if (platver.find("OpenCL 2.") != std::string::npos) { + plat = p; + } + } + if (plat() == 0) { + std::cout << "No OpenCL 2.0 platform found."; + return -1; + } + + cl::Platform newP = cl::Platform::setDefault(plat); + if (newP != plat) { + std::cout << "Error setting default platform."; + return -1; + } + + // Use C++11 raw string literals for kernel source code + std::string kernel1{R"CLC( + global int globalA; + kernel void updateGlobal() + { + globalA = 75; + } + )CLC"}; + std::string kernel2{R"CLC( + typedef struct { global int *bar; } Foo; + kernel void vectorAdd(global const Foo* aNum, global const int *inputA, global const int *inputB, + global int *output, int val, write_only pipe int outPipe, queue_t childQueue) + { + output[get_global_id(0)] = inputA[get_global_id(0)] + inputB[get_global_id(0)] + val + *(aNum->bar); + write_pipe(outPipe, &val); + queue_t default_queue = get_default_queue(); + ndrange_t ndrange = ndrange_1D(get_global_size(0)/2, get_global_size(0)/2); + + // Have a child kernel write into third quarter of output + enqueue_kernel(default_queue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, + ^{ + output[get_global_size(0)*2 + get_global_id(0)] = + inputA[get_global_size(0)*2 + get_global_id(0)] + inputB[get_global_size(0)*2 + get_global_id(0)] + globalA; + }); + + // Have a child kernel write into last quarter of output + enqueue_kernel(childQueue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, + ^{ + output[get_global_size(0)*3 + get_global_id(0)] = + inputA[get_global_size(0)*3 + get_global_id(0)] + inputB[get_global_size(0)*3 + get_global_id(0)] + globalA + 2; + }); + } + )CLC"}; + + // New simpler string interface style + std::vector programStrings {kernel1, kernel2}; + + cl::Program vectorAddProgram(programStrings); + try { + vectorAddProgram.build("-cl-std=CL2.0"); + } + catch (...) { + // Print build info for all devices + cl_int buildErr = CL_SUCCESS; + auto buildInfo = vectorAddProgram.getBuildInfo(&buildErr); + for (auto &pair : buildInfo) { + std::cerr << pair.second << std::endl << std::endl; + } + + return 1; + } + + typedef struct { int *bar; } Foo; + + // Get and run kernel that initializes the program-scope global + // A test for kernels that take no arguments + auto program2Kernel = + cl::KernelFunctor<>(vectorAddProgram, "updateGlobal"); + program2Kernel( + cl::EnqueueArgs( + cl::NDRange(1))); + + ////////////////// + // SVM allocations + + auto anSVMInt = cl::allocate_svm>(); + *anSVMInt = 5; + cl::SVMAllocator>> svmAllocReadOnly; + auto fooPointer = cl::allocate_pointer(svmAllocReadOnly); + fooPointer->bar = anSVMInt.get(); + cl::SVMAllocator> svmAlloc; + std::vector>> inputA(numElements, 1, svmAlloc); + cl::coarse_svm_vector inputB(numElements, 2, svmAlloc); + + // + ////////////// + + // Traditional cl_mem allocations + std::vector output(numElements, 0xdeadbeef); + cl::Buffer outputBuffer(begin(output), end(output), false); + cl::Pipe aPipe(sizeof(cl_int), numElements / 2); + + // Default command queue, also passed in as a parameter + cl::DeviceCommandQueue defaultDeviceQueue = cl::DeviceCommandQueue::makeDefault( + cl::Context::getDefault(), cl::Device::getDefault()); + + auto vectorAddKernel = + cl::KernelFunctor< + decltype(fooPointer)&, + int*, + cl::coarse_svm_vector&, + cl::Buffer, + int, + cl::Pipe&, + cl::DeviceCommandQueue + >(vectorAddProgram, "vectorAdd"); + + // Ensure that the additional SVM pointer is available to the kernel + // This one was not passed as a parameter + vectorAddKernel.setSVMPointers(anSVMInt); + + // Hand control of coarse allocations to runtime + cl::enqueueUnmapSVM(anSVMInt); + cl::enqueueUnmapSVM(fooPointer); + cl::unmapSVM(inputB); + cl::unmapSVM(output2); + + cl_int error; + vectorAddKernel( + cl::EnqueueArgs( + cl::NDRange(numElements/2), + cl::NDRange(numElements/2)), + fooPointer, + inputA.data(), + inputB, + outputBuffer, + 3, + aPipe, + defaultDeviceQueue, + error + ); + + cl::copy(outputBuffer, begin(output), end(output)); + // Grab the SVM output vector using a map + cl::mapSVM(output2); + + cl::Device d = cl::Device::getDefault(); + + std::cout << "Output:\n"; + for (int i = 1; i < numElements; ++i) { + std::cout << "\t" << output[i] << "\n"; + } + std::cout << "\n\n"; + + return 0; + } + * + * \endcode + * + */ +#ifndef CL_HPP_ +#define CL_HPP_ + +/* Handle deprecated preprocessor definitions. In each case, we only check for + * the old name if the new name is not defined, so that user code can define + * both and hence work with either version of the bindings. + */ +#if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP) +# pragma message("cl2.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead") +# define CL_HPP_USE_DX_INTEROP +#endif +#if !defined(CL_HPP_USE_CL_DEVICE_FISSION) && defined(USE_CL_DEVICE_FISSION) +# pragma message("cl2.hpp: USE_CL_DEVICE_FISSION is deprecated. Define CL_HPP_USE_CL_DEVICE_FISSION instead") +# define CL_HPP_USE_CL_DEVICE_FISSION +#endif +#if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS) +# pragma message("cl2.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead") +# define CL_HPP_ENABLE_EXCEPTIONS +#endif +#if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR) +# pragma message("cl2.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead") +# define CL_HPP_NO_STD_VECTOR +#endif +#if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING) +# pragma message("cl2.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead") +# define CL_HPP_NO_STD_STRING +#endif +#if defined(VECTOR_CLASS) +# pragma message("cl2.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead") +#endif +#if defined(STRING_CLASS) +# pragma message("cl2.hpp: STRING_CLASS is deprecated. Alias cl::string instead.") +#endif +#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS) +# pragma message("cl2.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead") +# define CL_HPP_USER_OVERRIDE_ERROR_STRINGS +#endif + +/* Warn about features that are no longer supported + */ +#if defined(__USE_DEV_VECTOR) +# pragma message("cl2.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors") +#endif +#if defined(__USE_DEV_STRING) +# pragma message("cl2.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors") +#endif + +/* Detect which version to target */ +#if !defined(CL_HPP_TARGET_OPENCL_VERSION) +# pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 200 (OpenCL 2.0)") +# define CL_HPP_TARGET_OPENCL_VERSION 200 +#endif +#if CL_HPP_TARGET_OPENCL_VERSION != 100 && CL_HPP_TARGET_OPENCL_VERSION != 110 && CL_HPP_TARGET_OPENCL_VERSION != 120 && CL_HPP_TARGET_OPENCL_VERSION != 200 +# pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120 or 200). It will be set to 200") +# undef CL_HPP_TARGET_OPENCL_VERSION +# define CL_HPP_TARGET_OPENCL_VERSION 200 +#endif + +#if !defined(CL_HPP_MINIMUM_OPENCL_VERSION) +# define CL_HPP_MINIMUM_OPENCL_VERSION 200 +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && CL_HPP_MINIMUM_OPENCL_VERSION != 110 && CL_HPP_MINIMUM_OPENCL_VERSION != 120 && CL_HPP_MINIMUM_OPENCL_VERSION != 200 +# pragma message("cl2.hpp: CL_HPP_MINIMUM_OPENCL_VERSION is not a valid value (100, 110, 120 or 200). It will be set to 100") +# undef CL_HPP_MINIMUM_OPENCL_VERSION +# define CL_HPP_MINIMUM_OPENCL_VERSION 100 +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION +# error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION" +#endif + +#if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS) +# define CL_USE_DEPRECATED_OPENCL_1_0_APIS +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +# define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) +# define CL_USE_DEPRECATED_OPENCL_1_2_APIS +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS) +# define CL_USE_DEPRECATED_OPENCL_2_0_APIS +#endif + +#ifdef _WIN32 + +#include + +#if defined(CL_HPP_USE_DX_INTEROP) +#include +#include +#endif +#endif // _WIN32 + +#if defined(_MSC_VER) +#include +#endif // _MSC_VER + + // Check for a valid C++ version + +// Need to do both tests here because for some reason __cplusplus is not +// updated in visual studio +#if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700) +#error Visual studio 2013 or another C++11-supporting compiler required +#endif + +// +#if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) +#include +#endif + +#if defined(__APPLE__) || defined(__MACOSX) +#include +#else +#include +#endif // !__APPLE__ + +#if (__cplusplus >= 201103L) +#define CL_HPP_NOEXCEPT_ noexcept +#else +#define CL_HPP_NOEXCEPT_ +#endif + +#if defined(_MSC_VER) +# define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany) +#else +# define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak)) +#endif // !_MSC_VER + +// Define deprecated prefixes and suffixes to ensure compilation +// in case they are not pre-defined +#if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) + +#if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED) +#define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED) +#if !defined(CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED) +#define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED) + +#if !defined(CL_CALLBACK) +#define CL_CALLBACK +#endif //CL_CALLBACK + +#include +#include +#include +#include +#include +#include + + +// Define a size_type to represent a correctly resolved size_t +#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) +namespace cl { + using size_type = ::size_t; +} // namespace cl +#else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) +namespace cl { + using size_type = size_t; +} // namespace cl +#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) + + +#if defined(CL_HPP_ENABLE_EXCEPTIONS) +#include +#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS) + +#if !defined(CL_HPP_NO_STD_VECTOR) +#include +namespace cl { + template < class T, class Alloc = std::allocator > + using vector = std::vector; +} // namespace cl +#endif // #if !defined(CL_HPP_NO_STD_VECTOR) + +#if !defined(CL_HPP_NO_STD_STRING) +#include +namespace cl { + using string = std::string; +} // namespace cl +#endif // #if !defined(CL_HPP_NO_STD_STRING) + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +#if !defined(CL_HPP_NO_STD_UNIQUE_PTR) +#include +namespace cl { + // Replace unique_ptr and allocate_pointer for internal use + // to allow user to replace them + template + using pointer = std::unique_ptr; +} // namespace cl +#endif +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 +#if !defined(CL_HPP_NO_STD_ARRAY) +#include +namespace cl { + template < class T, size_type N > + using array = std::array; +} // namespace cl +#endif // #if !defined(CL_HPP_NO_STD_ARRAY) + +// Define size_type appropriately to allow backward-compatibility +// use of the old size_t interface class +#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) +namespace cl { + namespace compatibility { + /*! \brief class used to interface between C++ and + * OpenCL C calls that require arrays of size_t values, whose + * size is known statically. + */ + template + class size_t + { + private: + size_type data_[N]; + + public: + //! \brief Initialize size_t to all 0s + size_t() + { + for (int i = 0; i < N; ++i) { + data_[i] = 0; + } + } + + size_t(const array &rhs) + { + for (int i = 0; i < N; ++i) { + data_[i] = rhs[i]; + } + } + + size_type& operator[](int index) + { + return data_[index]; + } + + const size_type& operator[](int index) const + { + return data_[index]; + } + + //! \brief Conversion operator to T*. + operator size_type* () { return data_; } + + //! \brief Conversion operator to const T*. + operator const size_type* () const { return data_; } + + operator array() const + { + array ret; + + for (int i = 0; i < N; ++i) { + ret[i] = data_[i]; + } + return ret; + } + }; + } // namespace compatibility + + template + using size_t = compatibility::size_t; +} // namespace cl +#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) + +// Helper alias to avoid confusing the macros +namespace cl { + namespace detail { + using size_t_array = array; + } // namespace detail +} // namespace cl + + +/*! \namespace cl + * + * \brief The OpenCL C++ bindings are defined within this namespace. + * + */ +namespace cl { + class Memory; + +#define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \ + if (!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddress(#name); \ + if (!pfn_##name) { \ + } \ + } + +#define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \ + if (!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddressForPlatform(platform, #name); \ + if (!pfn_##name) { \ + } \ + } + + class Program; + class Device; + class Context; + class CommandQueue; + class DeviceCommandQueue; + class Memory; + class Buffer; + class Pipe; + +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + /*! \brief Exception class + * + * This may be thrown by API functions when CL_HPP_ENABLE_EXCEPTIONS is defined. + */ + class Error : public std::exception + { + private: + cl_int err_; + const char * errStr_; + public: + /*! \brief Create a new CL error exception for a given error code + * and corresponding message. + * + * \param err error code value. + * + * \param errStr a descriptive string that must remain in scope until + * handling of the exception has concluded. If set, it + * will be returned by what(). + */ + Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr) + {} + + ~Error() throw() {} + + /*! \brief Get error string associated with exception + * + * \return A memory pointer to the error message string. + */ + virtual const char * what() const throw () + { + if (errStr_ == NULL) { + return "empty"; + } + else { + return errStr_; + } + } + + /*! \brief Get error code associated with exception + * + * \return The error code. + */ + cl_int err(void) const { return err_; } + }; +#define CL_HPP_ERR_STR_(x) #x +#else +#define CL_HPP_ERR_STR_(x) NULL +#endif // CL_HPP_ENABLE_EXCEPTIONS + + +namespace detail +{ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) +static inline cl_int errHandler ( + cl_int err, + const char * errStr = NULL) +{ + if (err != CL_SUCCESS) { + throw Error(err, errStr); + } + return err; +} +#else +static inline cl_int errHandler (cl_int err, const char * errStr = NULL) +{ + (void) errStr; // suppress unused variable warning + return err; +} +#endif // CL_HPP_ENABLE_EXCEPTIONS +} + + + +//! \cond DOXYGEN_DETAIL +#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) +#define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo) +#define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo) +#define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs) +#define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs) +#define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo) +#define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo) +#define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo) +#define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo) +#define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo) +#define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo) +#define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo) +#define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo) +#define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo) +#define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo) + +#define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext) +#define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType) +#define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats) + +#define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer) +#define __COPY_ERR CL_HPP_ERR_STR_(cl::copy) +#define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer) +#define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer) +#define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer) +#define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage) +#define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture) +#define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback) + +#define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent) +#define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus) +#define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback) +#define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents) + +#define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel) +#define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg) +#define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource) +#define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram) +#define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram) + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +#define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties) +#define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200 +#define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty) +#define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer) +#define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect) +#define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer) +#define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect) +#define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer) +#define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect) +#define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer) +#define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage) +#define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage) +#define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage) +#define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage) +#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer) +#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage) +#define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer) +#define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage) +#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject) +#define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel) +#define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + +#define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects) +#define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects) + +#define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe) +#define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo) + + +#define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object) +#define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object) +#define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush) +#define __FINISH_ERR CL_HPP_ERR_STR_(clFinish) +#define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error) + +/** + * CL 1.2 version that uses device fission. + */ +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices) +#else +#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +#define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker) +#define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents) +#define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier) +#define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler) +#define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D) +#define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D) +#define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D) +#define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D) +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +/** + * Deprecated APIs for 2.0 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) +#define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue) +#define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask) +#define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler) +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +/** + * CL 1.2 marker and barrier commands + */ +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList) +#define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + +#endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS +//! \endcond + + +namespace detail { + +// Generic getInfoHelper. The final parameter is used to guide overload +// resolution: the actual parameter passed is an int, which makes this +// a worse conversion sequence than a specialization that declares the +// parameter as an int. +template +inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long) +{ + return f(name, sizeof(T), param, NULL); +} + +// Specialized for getInfo +// Assumes that the output vector was correctly resized on the way in +template +inline cl_int getInfoHelper(Func f, cl_uint name, vector>* param, int) +{ + if (name != CL_PROGRAM_BINARIES) { + return CL_INVALID_VALUE; + } + if (param) { + // Create array of pointers, calculate total size and pass pointer array in + size_type numBinaries = param->size(); + vector binariesPointers(numBinaries); + + for (size_type i = 0; i < numBinaries; ++i) + { + binariesPointers[i] = (*param)[i].data(); + } + + cl_int err = f(name, numBinaries * sizeof(unsigned char*), binariesPointers.data(), NULL); + + if (err != CL_SUCCESS) { + return err; + } + } + + + return CL_SUCCESS; +} + +// Specialized getInfoHelper for vector params +template +inline cl_int getInfoHelper(Func f, cl_uint name, vector* param, long) +{ + size_type required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + const size_type elements = required / sizeof(T); + + // Temporary to avoid changing param on an error + vector localData(elements); + err = f(name, required, localData.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + if (param) { + *param = std::move(localData); + } + + return CL_SUCCESS; +} + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper( + Func f, cl_uint name, vector* param, int, typename T::cl_type = 0) +{ + size_type required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + const size_type elements = required / sizeof(typename T::cl_type); + + vector value(elements); + err = f(name, required, value.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + + if (param) { + // Assign to convert CL type to T for each element + param->resize(elements); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < elements; i++) { + (*param)[i] = T(value[i], true); + } + } + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for string params +template +inline cl_int getInfoHelper(Func f, cl_uint name, string* param, long) +{ + size_type required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + // std::string has a constant data member + // a char vector does not + if (required > 0) { + vector value(required); + err = f(name, required, value.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + if (param) { + param->assign(begin(value), prev(end(value))); + } + } + else if (param) { + param->assign(""); + } + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for clsize_t params +template +inline cl_int getInfoHelper(Func f, cl_uint name, array* param, long) +{ + size_type required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + size_type elements = required / sizeof(size_type); + vector value(elements, 0); + + err = f(name, required, value.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + + // Bound the copy with N to prevent overruns + // if passed N > than the amount copied + if (elements > N) { + elements = N; + } + for (size_type i = 0; i < elements; ++i) { + (*param)[i] = value[i]; + } + + return CL_SUCCESS; +} + +template struct ReferenceHandler; + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0) +{ + typename T::cl_type value; + cl_int err = f(name, sizeof(value), &value, NULL); + if (err != CL_SUCCESS) { + return err; + } + *param = value; + if (value != NULL) + { + err = param->retain(); + if (err != CL_SUCCESS) { + return err; + } + } + return CL_SUCCESS; +} + +#define CL_HPP_PARAM_NAME_INFO_1_0_(F) \ + F(cl_platform_info, CL_PLATFORM_PROFILE, string) \ + F(cl_platform_info, CL_PLATFORM_VERSION, string) \ + F(cl_platform_info, CL_PLATFORM_NAME, string) \ + F(cl_platform_info, CL_PLATFORM_VENDOR, string) \ + F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \ + \ + F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \ + F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \ + F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \ + F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \ + F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \ + F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \ + F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \ + F(cl_device_info, CL_DEVICE_NAME, string) \ + F(cl_device_info, CL_DEVICE_VENDOR, string) \ + F(cl_device_info, CL_DRIVER_VERSION, string) \ + F(cl_device_info, CL_DEVICE_PROFILE, string) \ + F(cl_device_info, CL_DEVICE_VERSION, string) \ + F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \ + \ + F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \ + F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector) \ + F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector) \ + \ + F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \ + F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \ + F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \ + F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \ + \ + F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \ + \ + F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \ + F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \ + F(cl_mem_info, CL_MEM_SIZE, size_type) \ + F(cl_mem_info, CL_MEM_HOST_PTR, void*) \ + F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \ + \ + F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \ + F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \ + F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \ + F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \ + F(cl_image_info, CL_IMAGE_WIDTH, size_type) \ + F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \ + F(cl_image_info, CL_IMAGE_DEPTH, size_type) \ + \ + F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \ + F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \ + F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \ + F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \ + F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \ + \ + F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \ + F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \ + F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \ + F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector) \ + F(cl_program_info, CL_PROGRAM_SOURCE, string) \ + F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector) \ + F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector>) \ + \ + F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \ + \ + F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \ + F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \ + F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \ + F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \ + F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \ + \ + F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \ + F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \ + F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \ + F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties) + + +#define CL_HPP_PARAM_NAME_INFO_1_1_(F) \ + F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \ + \ + F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \ + F(cl_mem_info, CL_MEM_OFFSET, size_type) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \ + F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \ + \ + F(cl_event_info, CL_EVENT_CONTEXT, cl::Context) + +#define CL_HPP_PARAM_NAME_INFO_1_2_(F) \ + F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \ + F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \ + \ + F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \ + \ + F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \ + \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \ + \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \ + F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, size_type) \ + F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \ + F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \ + \ + F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \ + F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \ + F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint) + +#define CL_HPP_PARAM_NAME_INFO_2_0_(F) \ + F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \ + F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \ + F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \ + F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \ + F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE, size_type) \ + F(cl_device_info, CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE, size_type) \ + F(cl_device_info, CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS, cl_uint) \ + F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \ + F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \ + F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \ + F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint) + +#define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector) \ + F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \ + F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector) + +template +struct param_traits {}; + +#define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \ +struct token; \ +template<> \ +struct param_traits \ +{ \ + enum { value = param_name }; \ + typedef T param_type; \ +}; + +CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 +CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + + +// Flags deprecated in OpenCL 2.0 +#define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \ + F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) + +#define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \ + F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) + +#define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \ + F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer) + +// Include deprecated query flags based on versions +// Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash +#if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200 +CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110 +#if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 +CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120 +#if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 +CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200 + +#if defined(CL_HPP_USE_CL_DEVICE_FISSION) +CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_); +#endif // CL_HPP_USE_CL_DEVICE_FISSION + +#ifdef CL_PLATFORM_ICD_SUFFIX_KHR +CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string) +#endif + +#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong) +#endif + +#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector) +#endif +#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_WIDTH_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint) +#endif + +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint) +#endif +#ifdef CL_DEVICE_WARP_SIZE_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint) +#endif +#ifdef CL_DEVICE_GPU_OVERLAP_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool) +#endif +#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool) +#endif +#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool) +#endif + +// Convenience functions + +template +inline cl_int +getInfo(Func f, cl_uint name, T* param) +{ + return getInfoHelper(f, name, param, 0); +} + +template +struct GetInfoFunctor0 +{ + Func f_; const Arg0& arg0_; + cl_int operator ()( + cl_uint param, size_type size, void* value, size_type* size_ret) + { return f_(arg0_, param, size, value, size_ret); } +}; + +template +struct GetInfoFunctor1 +{ + Func f_; const Arg0& arg0_; const Arg1& arg1_; + cl_int operator ()( + cl_uint param, size_type size, void* value, size_type* size_ret) + { return f_(arg0_, arg1_, param, size, value, size_ret); } +}; + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, cl_uint name, T* param) +{ + GetInfoFunctor0 f0 = { f, arg0 }; + return getInfoHelper(f0, name, param, 0); +} + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param) +{ + GetInfoFunctor1 f0 = { f, arg0, arg1 }; + return getInfoHelper(f0, name, param, 0); +} + + +template +struct ReferenceHandler +{ }; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +/** + * OpenCL 1.2 devices do have retain/release. + */ +template <> +struct ReferenceHandler +{ + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int retain(cl_device_id device) + { return ::clRetainDevice(device); } + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int release(cl_device_id device) + { return ::clReleaseDevice(device); } +}; +#else // CL_HPP_TARGET_OPENCL_VERSION >= 120 +/** + * OpenCL 1.1 devices do not have retain/release. + */ +template <> +struct ReferenceHandler +{ + // cl_device_id does not have retain(). + static cl_int retain(cl_device_id) + { return CL_SUCCESS; } + // cl_device_id does not have release(). + static cl_int release(cl_device_id) + { return CL_SUCCESS; } +}; +#endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120) + +template <> +struct ReferenceHandler +{ + // cl_platform_id does not have retain(). + static cl_int retain(cl_platform_id) + { return CL_SUCCESS; } + // cl_platform_id does not have release(). + static cl_int release(cl_platform_id) + { return CL_SUCCESS; } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_context context) + { return ::clRetainContext(context); } + static cl_int release(cl_context context) + { return ::clReleaseContext(context); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_command_queue queue) + { return ::clRetainCommandQueue(queue); } + static cl_int release(cl_command_queue queue) + { return ::clReleaseCommandQueue(queue); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_mem memory) + { return ::clRetainMemObject(memory); } + static cl_int release(cl_mem memory) + { return ::clReleaseMemObject(memory); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_sampler sampler) + { return ::clRetainSampler(sampler); } + static cl_int release(cl_sampler sampler) + { return ::clReleaseSampler(sampler); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_program program) + { return ::clRetainProgram(program); } + static cl_int release(cl_program program) + { return ::clReleaseProgram(program); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_kernel kernel) + { return ::clRetainKernel(kernel); } + static cl_int release(cl_kernel kernel) + { return ::clReleaseKernel(kernel); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_event event) + { return ::clRetainEvent(event); } + static cl_int release(cl_event event) + { return ::clReleaseEvent(event); } +}; + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120 +// Extracts version number with major in the upper 16 bits, minor in the lower 16 +static cl_uint getVersion(const vector &versionInfo) +{ + int highVersion = 0; + int lowVersion = 0; + int index = 7; + while(versionInfo[index] != '.' ) { + highVersion *= 10; + highVersion += versionInfo[index]-'0'; + ++index; + } + ++index; + while(versionInfo[index] != ' ' && versionInfo[index] != '\0') { + lowVersion *= 10; + lowVersion += versionInfo[index]-'0'; + ++index; + } + return (highVersion << 16) | lowVersion; +} + +static cl_uint getPlatformVersion(cl_platform_id platform) +{ + size_type size = 0; + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size); + + vector versionInfo(size); + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size); + return getVersion(versionInfo); +} + +static cl_uint getDevicePlatformVersion(cl_device_id device) +{ + cl_platform_id platform; + clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL); + return getPlatformVersion(platform); +} + +static cl_uint getContextPlatformVersion(cl_context context) +{ + // The platform cannot be queried directly, so we first have to grab a + // device and obtain its context + size_type size = 0; + clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size); + if (size == 0) + return 0; + vector devices(size/sizeof(cl_device_id)); + clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL); + return getDevicePlatformVersion(devices[0]); +} +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120 + +template +class Wrapper +{ +public: + typedef T cl_type; + +protected: + cl_type object_; + +public: + Wrapper() : object_(NULL) { } + + Wrapper(const cl_type &obj, bool retainObject) : object_(obj) + { + if (retainObject) { + detail::errHandler(retain(), __RETAIN_ERR); + } + } + + ~Wrapper() + { + if (object_ != NULL) { release(); } + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + detail::errHandler(retain(), __RETAIN_ERR); + } + + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT_ + { + object_ = rhs.object_; + rhs.object_ = NULL; + } + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs.object_; + detail::errHandler(retain(), __RETAIN_ERR); + } + return *this; + } + + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs.object_; + rhs.object_ = NULL; + } + return *this; + } + + Wrapper& operator = (const cl_type &rhs) + { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs; + return *this; + } + + const cl_type& operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + + const cl_type get() const { return object_; } + + cl_type get() { return object_; } + + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + cl_int retain() const + { + if (object_ != nullptr) { + return ReferenceHandler::retain(object_); + } + else { + return CL_SUCCESS; + } + } + + cl_int release() const + { + if (object_ != nullptr) { + return ReferenceHandler::release(object_); + } + else { + return CL_SUCCESS; + } + } +}; + +template <> +class Wrapper +{ +public: + typedef cl_device_id cl_type; + +protected: + cl_type object_; + bool referenceCountable_; + + static bool isReferenceCountable(cl_device_id device) + { + bool retVal = false; +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#if CL_HPP_MINIMUM_OPENCL_VERSION < 120 + if (device != NULL) { + int version = getDevicePlatformVersion(device); + if(version > ((1 << 16) + 1)) { + retVal = true; + } + } +#else // CL_HPP_MINIMUM_OPENCL_VERSION < 120 + retVal = true; +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120 +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + return retVal; + } + +public: + Wrapper() : object_(NULL), referenceCountable_(false) + { + } + + Wrapper(const cl_type &obj, bool retainObject) : + object_(obj), + referenceCountable_(false) + { + referenceCountable_ = isReferenceCountable(obj); + + if (retainObject) { + detail::errHandler(retain(), __RETAIN_ERR); + } + } + + ~Wrapper() + { + release(); + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + referenceCountable_ = isReferenceCountable(object_); + detail::errHandler(retain(), __RETAIN_ERR); + } + + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT_ + { + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + detail::errHandler(retain(), __RETAIN_ERR); + } + return *this; + } + + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } + return *this; + } + + Wrapper& operator = (const cl_type &rhs) + { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs; + referenceCountable_ = isReferenceCountable(object_); + return *this; + } + + const cl_type& operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + + const cl_type get() const { return object_; } + + cl_type get() { return object_; } + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + template + friend inline cl_int getInfoHelper(Func, cl_uint, vector*, int, typename U::cl_type); + + cl_int retain() const + { + if( object_ != nullptr && referenceCountable_ ) { + return ReferenceHandler::retain(object_); + } + else { + return CL_SUCCESS; + } + } + + cl_int release() const + { + if (object_ != nullptr && referenceCountable_) { + return ReferenceHandler::release(object_); + } + else { + return CL_SUCCESS; + } + } +}; + +template +inline bool operator==(const Wrapper &lhs, const Wrapper &rhs) +{ + return lhs() == rhs(); +} + +template +inline bool operator!=(const Wrapper &lhs, const Wrapper &rhs) +{ + return !operator==(lhs, rhs); +} + +} // namespace detail +//! \endcond + + +using BuildLogType = vector::param_type>>; +#if defined(CL_HPP_ENABLE_EXCEPTIONS) +/** +* Exception class for build errors to carry build info +*/ +class BuildError : public Error +{ +private: + BuildLogType buildLogs; +public: + BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec) + { + } + + BuildLogType getBuildLog() const + { + return buildLogs; + } +}; +namespace detail { + static inline cl_int buildErrHandler( + cl_int err, + const char * errStr, + const BuildLogType &buildLogs) + { + if (err != CL_SUCCESS) { + throw BuildError(err, errStr, buildLogs); + } + return err; + } +} // namespace detail + +#else +namespace detail { + static inline cl_int buildErrHandler( + cl_int err, + const char * errStr, + const BuildLogType &buildLogs) + { + (void)buildLogs; // suppress unused variable warning + (void)errStr; + return err; + } +} // namespace detail +#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS) + + +/*! \stuct ImageFormat + * \brief Adds constructors and member functions for cl_image_format. + * + * \see cl_image_format + */ +struct ImageFormat : public cl_image_format +{ + //! \brief Default constructor - performs no initialization. + ImageFormat(){} + + //! \brief Initializing constructor. + ImageFormat(cl_channel_order order, cl_channel_type type) + { + image_channel_order = order; + image_channel_data_type = type; + } + + //! \brief Assignment operator. + ImageFormat& operator = (const ImageFormat& rhs) + { + if (this != &rhs) { + this->image_channel_data_type = rhs.image_channel_data_type; + this->image_channel_order = rhs.image_channel_order; + } + return *this; + } +}; + +/*! \brief Class interface for cl_device_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_device_id + */ +class Device : public detail::Wrapper +{ +private: + static std::once_flag default_initialized_; + static Device default_; + static cl_int default_error_; + + /*! \brief Create the default context. + * + * This sets @c default_ and @c default_error_. It does not throw + * @c cl::Error. + */ + static void makeDefault(); + + /*! \brief Create the default platform from a provided platform. + * + * This sets @c default_. It does not throw + * @c cl::Error. + */ + static void makeDefaultProvided(const Device &p) { + default_ = p; + } + +public: +#ifdef CL_HPP_UNIT_TEST_ENABLE + /*! \brief Reset the default. + * + * This sets @c default_ to an empty value to support cleanup in + * the unit test framework. + * This function is not thread safe. + */ + static void unitTestClearDefault() { + default_ = Device(); + } +#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE + + //! \brief Default constructor - initializes to NULL. + Device() : detail::Wrapper() { } + + /*! \brief Constructor from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + explicit Device(const cl_device_id &device, bool retainObject = false) : + detail::Wrapper(device, retainObject) { } + + /*! \brief Returns the first device on the default context. + * + * \see Context::getDefault() + */ + static Device getDefault( + cl_int *errResult = NULL) + { + std::call_once(default_initialized_, makeDefault); + detail::errHandler(default_error_); + if (errResult != NULL) { + *errResult = default_error_; + } + return default_; + } + + /** + * Modify the default device to be used by + * subsequent operations. + * Will only set the default if no default was previously created. + * @return updated default device. + * Should be compared to the passed value to ensure that it was updated. + */ + static Device setDefault(const Device &default_device) + { + std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device)); + detail::errHandler(default_error_); + return default_; + } + + /*! \brief Assignment operator from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + Device& operator = (const cl_device_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device(const Device& dev) : detail::Wrapper(dev) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (const Device &dev) + { + detail::Wrapper::operator=(dev); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Device(Device&& dev) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(dev)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (Device &&dev) + { + detail::Wrapper::operator=(std::move(dev)); + return *this; + } + + //! \brief Wrapper for clGetDeviceInfo(). + template + cl_int getInfo(cl_device_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetDeviceInfo, object_, name, param), + __GET_DEVICE_INFO_ERR); + } + + //! \brief Wrapper for clGetDeviceInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_device_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /** + * CL 1.2 version + */ +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + //! \brief Wrapper for clCreateSubDevices(). + cl_int createSubDevices( + const cl_device_partition_property * properties, + vector* devices) + { + cl_uint n = 0; + cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR); + } + + vector ids(n); + err = clCreateSubDevices(object_, properties, n, ids.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR); + } + + // Cannot trivially assign because we need to capture intermediates + // with safe construction + if (devices) { + devices->resize(ids.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < ids.size(); i++) { + // We do not need to retain because this device is being created + // by the runtime + (*devices)[i] = Device(ids[i], false); + } + } + + return CL_SUCCESS; + } +#elif defined(CL_HPP_USE_CL_DEVICE_FISSION) + +/** + * CL 1.1 version that uses device fission extension. + */ + cl_int createSubDevices( + const cl_device_partition_property_ext * properties, + vector* devices) + { + typedef CL_API_ENTRY cl_int + ( CL_API_CALL * PFN_clCreateSubDevicesEXT)( + cl_device_id /*in_device*/, + const cl_device_partition_property_ext * /* properties */, + cl_uint /*num_entries*/, + cl_device_id * /*out_devices*/, + cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL; + CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT); + + cl_uint n = 0; + cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR); + } + + vector ids(n); + err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR); + } + // Cannot trivially assign because we need to capture intermediates + // with safe construction + if (devices) { + devices->resize(ids.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < ids.size(); i++) { + // We do not need to retain because this device is being created + // by the runtime + (*devices)[i] = Device(ids[i], false); + } + } + return CL_SUCCESS; + } +#endif // defined(CL_HPP_USE_CL_DEVICE_FISSION) +}; + +CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_; +CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_; +CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS; + +/*! \brief Class interface for cl_platform_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_platform_id + */ +class Platform : public detail::Wrapper +{ +private: + static std::once_flag default_initialized_; + static Platform default_; + static cl_int default_error_; + + /*! \brief Create the default context. + * + * This sets @c default_ and @c default_error_. It does not throw + * @c cl::Error. + */ + static void makeDefault() { + /* Throwing an exception from a call_once invocation does not do + * what we wish, so we catch it and save the error. + */ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try +#endif + { + // If default wasn't passed ,generate one + // Otherwise set it + cl_uint n = 0; + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + default_error_ = err; + return; + } + if (n == 0) { + default_error_ = CL_INVALID_PLATFORM; + return; + } + + vector ids(n); + err = ::clGetPlatformIDs(n, ids.data(), NULL); + if (err != CL_SUCCESS) { + default_error_ = err; + return; + } + + default_ = Platform(ids[0]); + } +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + catch (cl::Error &e) { + default_error_ = e.err(); + } +#endif + } + + /*! \brief Create the default platform from a provided platform. + * + * This sets @c default_. It does not throw + * @c cl::Error. + */ + static void makeDefaultProvided(const Platform &p) { + default_ = p; + } + +public: +#ifdef CL_HPP_UNIT_TEST_ENABLE + /*! \brief Reset the default. + * + * This sets @c default_ to an empty value to support cleanup in + * the unit test framework. + * This function is not thread safe. + */ + static void unitTestClearDefault() { + default_ = Platform(); + } +#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE + + //! \brief Default constructor - initializes to NULL. + Platform() : detail::Wrapper() { } + + /*! \brief Constructor from cl_platform_id. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * This simply copies the platform ID value, which is an inexpensive operation. + */ + explicit Platform(const cl_platform_id &platform, bool retainObject = false) : + detail::Wrapper(platform, retainObject) { } + + /*! \brief Assignment operator from cl_platform_id. + * + * This simply copies the platform ID value, which is an inexpensive operation. + */ + Platform& operator = (const cl_platform_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + static Platform getDefault( + cl_int *errResult = NULL) + { + std::call_once(default_initialized_, makeDefault); + detail::errHandler(default_error_); + if (errResult != NULL) { + *errResult = default_error_; + } + return default_; + } + + /** + * Modify the default platform to be used by + * subsequent operations. + * Will only set the default if no default was previously created. + * @return updated default platform. + * Should be compared to the passed value to ensure that it was updated. + */ + static Platform setDefault(const Platform &default_platform) + { + std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform)); + detail::errHandler(default_error_); + return default_; + } + + //! \brief Wrapper for clGetPlatformInfo(). + cl_int getInfo(cl_platform_info name, string* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetPlatformInfo, object_, name, param), + __GET_PLATFORM_INFO_ERR); + } + + //! \brief Wrapper for clGetPlatformInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_platform_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of devices for this platform. + * + * Wraps clGetDeviceIDs(). + */ + cl_int getDevices( + cl_device_type type, + vector* devices) const + { + cl_uint n = 0; + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + vector ids(n); + err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + // Cannot trivially assign because we need to capture intermediates + // with safe construction + // We must retain things we obtain from the API to avoid releasing + // API-owned objects. + if (devices) { + devices->resize(ids.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < ids.size(); i++) { + (*devices)[i] = Device(ids[i], true); + } + } + return CL_SUCCESS; + } + +#if defined(CL_HPP_USE_DX_INTEROP) + /*! \brief Get the list of available D3D10 devices. + * + * \param d3d_device_source. + * + * \param d3d_object. + * + * \param d3d_device_set. + * + * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device + * values returned in devices can be used to identify a specific OpenCL + * device. If \a devices argument is NULL, this argument is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * + * The application can query specific capabilities of the OpenCL device(s) + * returned by cl::getDevices. This can be used by the application to + * determine which device(s) to use. + * + * \note In the case that exceptions are enabled and a return value + * other than CL_SUCCESS is generated, then cl::Error exception is + * generated. + */ + cl_int getDevices( + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + vector* devices) const + { + typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)( + cl_platform_id platform, + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint* num_devices); + + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + + static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL; + CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR); + + cl_uint n = 0; + cl_int err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + 0, + NULL, + &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + vector ids(n); + err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + n, + ids.data(), + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + // Cannot trivially assign because we need to capture intermediates + // with safe construction + // We must retain things we obtain from the API to avoid releasing + // API-owned objects. + if (devices) { + devices->resize(ids.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < ids.size(); i++) { + (*devices)[i] = Device(ids[i], true); + } + } + return CL_SUCCESS; + } +#endif + + /*! \brief Gets a list of available platforms. + * + * Wraps clGetPlatformIDs(). + */ + static cl_int get( + vector* platforms) + { + cl_uint n = 0; + + if( platforms == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); + } + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + vector ids(n); + err = ::clGetPlatformIDs(n, ids.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + if (platforms) { + platforms->resize(ids.size()); + + // Platforms don't reference count + for (size_type i = 0; i < ids.size(); i++) { + (*platforms)[i] = Platform(ids[i]); + } + } + return CL_SUCCESS; + } + + /*! \brief Gets the first available platform. + * + * Wraps clGetPlatformIDs(), returning the first result. + */ + static cl_int get( + Platform * platform) + { + cl_int err; + Platform default_platform = Platform::getDefault(&err); + if (platform) { + *platform = default_platform; + } + return err; + } + + /*! \brief Gets the first available platform, returning it by value. + * + * \return Returns a valid platform if one is available. + * If no platform is available will return a null platform. + * Throws an exception if no platforms are available + * or an error condition occurs. + * Wraps clGetPlatformIDs(), returning the first result. + */ + static Platform get( + cl_int * errResult = NULL) + { + cl_int err; + Platform default_platform = Platform::getDefault(&err); + if (errResult) { + *errResult = err; + } + return default_platform; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + //! \brief Wrapper for clUnloadCompiler(). + cl_int + unloadCompiler() + { + return ::clUnloadPlatformCompiler(object_); + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +}; // class Platform + +CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_; +CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_; +CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS; + + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +/** + * Unload the OpenCL compiler. + * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead. + */ +inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int +UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +inline cl_int +UnloadCompiler() +{ + return ::clUnloadCompiler(); +} +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +/*! \brief Class interface for cl_context. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_context as the original. For details, see + * clRetainContext() and clReleaseContext(). + * + * \see cl_context + */ +class Context + : public detail::Wrapper +{ +private: + static std::once_flag default_initialized_; + static Context default_; + static cl_int default_error_; + + /*! \brief Create the default context from the default device type in the default platform. + * + * This sets @c default_ and @c default_error_. It does not throw + * @c cl::Error. + */ + static void makeDefault() { + /* Throwing an exception from a call_once invocation does not do + * what we wish, so we catch it and save the error. + */ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try +#endif + { +#if !defined(__APPLE__) && !defined(__MACOS) + const Platform &p = Platform::getDefault(); + cl_platform_id defaultPlatform = p(); + cl_context_properties properties[3] = { + CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0 + }; +#else // #if !defined(__APPLE__) && !defined(__MACOS) + cl_context_properties *properties = nullptr; +#endif // #if !defined(__APPLE__) && !defined(__MACOS) + + default_ = Context( + CL_DEVICE_TYPE_DEFAULT, + properties, + NULL, + NULL, + &default_error_); + } +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + catch (cl::Error &e) { + default_error_ = e.err(); + } +#endif + } + + + /*! \brief Create the default context from a provided Context. + * + * This sets @c default_. It does not throw + * @c cl::Error. + */ + static void makeDefaultProvided(const Context &c) { + default_ = c; + } + +public: +#ifdef CL_HPP_UNIT_TEST_ENABLE + /*! \brief Reset the default. + * + * This sets @c default_ to an empty value to support cleanup in + * the unit test framework. + * This function is not thread safe. + */ + static void unitTestClearDefault() { + default_ = Context(); + } +#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE + + /*! \brief Constructs a context including a list of specified devices. + * + * Wraps clCreateContext(). + */ + Context( + const vector& devices, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + size_type, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + size_type numDevices = devices.size(); + vector deviceIDs(numDevices); + + for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateContext( + properties, (cl_uint) numDevices, + deviceIDs.data(), + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + Context( + const Device& device, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + size_type, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + cl_device_id deviceID = device(); + + object_ = ::clCreateContext( + properties, 1, + &deviceID, + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a context including all or a subset of devices of a specified type. + * + * Wraps clCreateContextFromType(). + */ + Context( + cl_device_type type, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + size_type, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + +#if !defined(__APPLE__) && !defined(__MACOS) + cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 }; + + if (properties == NULL) { + // Get a valid platform ID as we cannot send in a blank one + vector platforms; + error = Platform::get(&platforms); + if (error != CL_SUCCESS) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + // Check the platforms we found for a device of our specified type + cl_context_properties platform_id = 0; + for (unsigned int i = 0; i < platforms.size(); i++) { + + vector devices; + +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try { +#endif + + error = platforms[i].getDevices(type, &devices); + +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + } catch (Error) {} + // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type + // We do error checking next anyway, and can throw there if needed +#endif + + // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND + if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + if (devices.size() > 0) { + platform_id = (cl_context_properties)platforms[i](); + break; + } + } + + if (platform_id == 0) { + detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = CL_DEVICE_NOT_FOUND; + } + return; + } + + prop[1] = platform_id; + properties = &prop[0]; + } +#endif + object_ = ::clCreateContextFromType( + properties, type, notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context(const Context& ctx) : detail::Wrapper(ctx) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (const Context &ctx) + { + detail::Wrapper::operator=(ctx); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Context(Context&& ctx) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(ctx)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (Context &&ctx) + { + detail::Wrapper::operator=(std::move(ctx)); + return *this; + } + + + /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT. + * + * \note All calls to this function return the same cl_context as the first. + */ + static Context getDefault(cl_int * err = NULL) + { + std::call_once(default_initialized_, makeDefault); + detail::errHandler(default_error_); + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + /** + * Modify the default context to be used by + * subsequent operations. + * Will only set the default if no default was previously created. + * @return updated default context. + * Should be compared to the passed value to ensure that it was updated. + */ + static Context setDefault(const Context &default_context) + { + std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context)); + detail::errHandler(default_error_); + return default_; + } + + //! \brief Default constructor - initializes to NULL. + Context() : detail::Wrapper() { } + + /*! \brief Constructor from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_context + * into the new Context object. + */ + explicit Context(const cl_context& context, bool retainObject = false) : + detail::Wrapper(context, retainObject) { } + + /*! \brief Assignment operator from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseContext() on the value previously held by this instance. + */ + Context& operator = (const cl_context& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetContextInfo(). + template + cl_int getInfo(cl_context_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetContextInfo, object_, name, param), + __GET_CONTEXT_INFO_ERR); + } + + //! \brief Wrapper for clGetContextInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_context_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of supported image formats. + * + * Wraps clGetSupportedImageFormats(). + */ + cl_int getSupportedImageFormats( + cl_mem_flags flags, + cl_mem_object_type type, + vector* formats) const + { + cl_uint numEntries; + + if (!formats) { + return CL_SUCCESS; + } + + cl_int err = ::clGetSupportedImageFormats( + object_, + flags, + type, + 0, + NULL, + &numEntries); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + if (numEntries > 0) { + vector value(numEntries); + err = ::clGetSupportedImageFormats( + object_, + flags, + type, + numEntries, + (cl_image_format*)value.data(), + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + formats->assign(begin(value), end(value)); + } + else { + // If no values are being returned, ensure an empty vector comes back + formats->clear(); + } + + return CL_SUCCESS; + } +}; + +inline void Device::makeDefault() +{ + /* Throwing an exception from a call_once invocation does not do + * what we wish, so we catch it and save the error. + */ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try +#endif + { + cl_int error = 0; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + default_error_ = error; + } + else { + default_ = context.getInfo()[0]; + default_error_ = CL_SUCCESS; + } + } +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + catch (cl::Error &e) { + default_error_ = e.err(); + } +#endif +} + +CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_; +CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_; +CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS; + +/*! \brief Class interface for cl_event. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_event as the original. For details, see + * clRetainEvent() and clReleaseEvent(). + * + * \see cl_event + */ +class Event : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Event() : detail::Wrapper() { } + + /*! \brief Constructor from cl_event - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * This effectively transfers ownership of a refcount on the cl_event + * into the new Event object. + */ + explicit Event(const cl_event& event, bool retainObject = false) : + detail::Wrapper(event, retainObject) { } + + /*! \brief Assignment operator from cl_event - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseEvent() on the value previously held by this instance. + */ + Event& operator = (const cl_event& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetEventInfo(). + template + cl_int getInfo(cl_event_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetEventInfo, object_, name, param), + __GET_EVENT_INFO_ERR); + } + + //! \brief Wrapper for clGetEventInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_event_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + //! \brief Wrapper for clGetEventProfilingInfo(). + template + cl_int getProfilingInfo(cl_profiling_info name, T* param) const + { + return detail::errHandler(detail::getInfo( + &::clGetEventProfilingInfo, object_, name, param), + __GET_EVENT_PROFILE_INFO_ERR); + } + + //! \brief Wrapper for clGetEventProfilingInfo() that returns by value. + template typename + detail::param_traits::param_type + getProfilingInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_profiling_info, name>::param_type param; + cl_int result = getProfilingInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Blocks the calling thread until this event completes. + * + * Wraps clWaitForEvents(). + */ + cl_int wait() const + { + return detail::errHandler( + ::clWaitForEvents(1, &object_), + __WAIT_FOR_EVENTS_ERR); + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + /*! \brief Registers a user callback function for a specific command execution status. + * + * Wraps clSetEventCallback(). + */ + cl_int setCallback( + cl_int type, + void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetEventCallback( + object_, + type, + pfn_notify, + user_data), + __SET_EVENT_CALLBACK_ERR); + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + + /*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ + static cl_int + waitForEvents(const vector& events) + { + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); + } +}; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 +/*! \brief Class interface for user events (a subset of cl_event's). + * + * See Event for details about copy semantics, etc. + */ +class UserEvent : public Event +{ +public: + /*! \brief Constructs a user event on a given context. + * + * Wraps clCreateUserEvent(). + */ + UserEvent( + const Context& context, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateUserEvent( + context(), + &error); + + detail::errHandler(error, __CREATE_USER_EVENT_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + UserEvent() : Event() { } + + /*! \brief Sets the execution status of a user event object. + * + * Wraps clSetUserEventStatus(). + */ + cl_int setStatus(cl_int status) + { + return detail::errHandler( + ::clSetUserEventStatus(object_,status), + __SET_USER_EVENT_STATUS_ERR); + } +}; +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + +/*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ +inline static cl_int +WaitForEvents(const vector& events) +{ + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); +} + +/*! \brief Class interface for cl_mem. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_mem as the original. For details, see + * clRetainMemObject() and clReleaseMemObject(). + * + * \see cl_mem + */ +class Memory : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Memory() : detail::Wrapper() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * Optionally transfer ownership of a refcount on the cl_mem + * into the new Memory object. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * + * See Memory for further details. + */ + explicit Memory(const cl_mem& memory, bool retainObject) : + detail::Wrapper(memory, retainObject) { } + + /*! \brief Assignment operator from cl_mem - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseMemObject() on the value previously held by this instance. + */ + Memory& operator = (const cl_mem& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory(const Memory& mem) : detail::Wrapper(mem) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (const Memory &mem) + { + detail::Wrapper::operator=(mem); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory(Memory&& mem) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(mem)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (Memory &&mem) + { + detail::Wrapper::operator=(std::move(mem)); + return *this; + } + + + //! \brief Wrapper for clGetMemObjectInfo(). + template + cl_int getInfo(cl_mem_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetMemObjectInfo, object_, name, param), + __GET_MEM_OBJECT_INFO_ERR); + } + + //! \brief Wrapper for clGetMemObjectInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_mem_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + /*! \brief Registers a callback function to be called when the memory object + * is no longer needed. + * + * Wraps clSetMemObjectDestructorCallback(). + * + * Repeated calls to this function, for a given cl_mem value, will append + * to the list of functions called (in reverse order) when memory object's + * resources are freed and the memory object is deleted. + * + * \note + * The registered callbacks are associated with the underlying cl_mem + * value - not the Memory class instance. + */ + cl_int setDestructorCallback( + void (CL_CALLBACK * pfn_notify)(cl_mem, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetMemObjectDestructorCallback( + object_, + pfn_notify, + user_data), + __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR); + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + +}; + +// Pre-declare copy functions +class Buffer; +template< typename IteratorType > +cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +namespace detail +{ + class SVMTraitNull + { + public: + static cl_svm_mem_flags getSVMMemFlags() + { + return 0; + } + }; +} // namespace detail + +template +class SVMTraitReadWrite +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return CL_MEM_READ_WRITE | + Trait::getSVMMemFlags(); + } +}; + +template +class SVMTraitReadOnly +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return CL_MEM_READ_ONLY | + Trait::getSVMMemFlags(); + } +}; + +template +class SVMTraitWriteOnly +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return CL_MEM_WRITE_ONLY | + Trait::getSVMMemFlags(); + } +}; + +template> +class SVMTraitCoarse +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return Trait::getSVMMemFlags(); + } +}; + +template> +class SVMTraitFine +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return CL_MEM_SVM_FINE_GRAIN_BUFFER | + Trait::getSVMMemFlags(); + } +}; + +template> +class SVMTraitAtomic +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return + CL_MEM_SVM_FINE_GRAIN_BUFFER | + CL_MEM_SVM_ATOMICS | + Trait::getSVMMemFlags(); + } +}; + +// Pre-declare SVM map function +template +inline cl_int enqueueMapSVM( + T* ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events = NULL, + Event* event = NULL); + +/** + * STL-like allocator class for managing SVM objects provided for convenience. + * + * Note that while this behaves like an allocator for the purposes of constructing vectors and similar objects, + * care must be taken when using with smart pointers. + * The allocator should not be used to construct a unique_ptr if we are using coarse-grained SVM mode because + * the coarse-grained management behaviour would behave incorrectly with respect to reference counting. + * + * Instead the allocator embeds a Deleter which may be used with unique_ptr and is used + * with the allocate_shared and allocate_ptr supplied operations. + */ +template +class SVMAllocator { +private: + Context context_; + +public: + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + template + struct rebind + { + typedef SVMAllocator other; + }; + + template + friend class SVMAllocator; + + SVMAllocator() : + context_(Context::getDefault()) + { + } + + explicit SVMAllocator(cl::Context context) : + context_(context) + { + } + + + SVMAllocator(const SVMAllocator &other) : + context_(other.context_) + { + } + + template + SVMAllocator(const SVMAllocator &other) : + context_(other.context_) + { + } + + ~SVMAllocator() + { + } + + pointer address(reference r) CL_HPP_NOEXCEPT_ + { + return std::addressof(r); + } + + const_pointer address(const_reference r) CL_HPP_NOEXCEPT_ + { + return std::addressof(r); + } + + /** + * Allocate an SVM pointer. + * + * If the allocator is coarse-grained, this will take ownership to allow + * containers to correctly construct data in place. + */ + pointer allocate( + size_type size, + typename cl::SVMAllocator::const_pointer = 0) + { + // Allocate memory with default alignment matching the size of the type + void* voidPointer = + clSVMAlloc( + context_(), + SVMTrait::getSVMMemFlags(), + size*sizeof(T), + 0); + pointer retValue = reinterpret_cast( + voidPointer); +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + if (!retValue) { + std::bad_alloc excep; + throw excep; + } +#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS) + + // If allocation was coarse-grained then map it + if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) { + cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T)); + if (err != CL_SUCCESS) { + std::bad_alloc excep; + throw excep; + } + } + + // If exceptions disabled, return null pointer from allocator + return retValue; + } + + void deallocate(pointer p, size_type) + { + clSVMFree(context_(), p); + } + + /** + * Return the maximum possible allocation size. + * This is the minimum of the maximum sizes of all devices in the context. + */ + size_type max_size() const CL_HPP_NOEXCEPT_ + { + size_type maxSize = std::numeric_limits::max() / sizeof(T); + + for (const Device &d : context_.getInfo()) { + maxSize = std::min( + maxSize, + static_cast(d.getInfo())); + } + + return maxSize; + } + + template< class U, class... Args > + void construct(U* p, Args&&... args) + { + new(p)T(args...); + } + + template< class U > + void destroy(U* p) + { + p->~U(); + } + + /** + * Returns true if the contexts match. + */ + inline bool operator==(SVMAllocator const& rhs) + { + return (context_==rhs.context_); + } + + inline bool operator!=(SVMAllocator const& a) + { + return !operator==(a); + } +}; // class SVMAllocator return cl::pointer(tmp, detail::Deleter{alloc, copies}); + + +template +class SVMAllocator { +public: + typedef void value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + + template + struct rebind + { + typedef SVMAllocator other; + }; + + template + friend class SVMAllocator; +}; + +#if !defined(CL_HPP_NO_STD_UNIQUE_PTR) +namespace detail +{ + template + class Deleter { + private: + Alloc alloc_; + size_type copies_; + + public: + typedef typename std::allocator_traits::pointer pointer; + + Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies } + { + } + + void operator()(pointer ptr) const { + Alloc tmpAlloc{ alloc_ }; + std::allocator_traits::destroy(tmpAlloc, std::addressof(*ptr)); + std::allocator_traits::deallocate(tmpAlloc, ptr, copies_); + } + }; +} // namespace detail + +/** + * Allocation operation compatible with std::allocate_ptr. + * Creates a unique_ptr by default. + * This requirement is to ensure that the control block is not + * allocated in memory inaccessible to the host. + */ +template +cl::pointer> allocate_pointer(const Alloc &alloc_, Args&&... args) +{ + Alloc alloc(alloc_); + static const size_type copies = 1; + + // Ensure that creation of the management block and the + // object are dealt with separately such that we only provide a deleter + + T* tmp = std::allocator_traits::allocate(alloc, copies); + if (!tmp) { + std::bad_alloc excep; + throw excep; + } + try { + std::allocator_traits::construct( + alloc, + std::addressof(*tmp), + std::forward(args)...); + + return cl::pointer>(tmp, detail::Deleter{alloc, copies}); + } + catch (std::bad_alloc b) + { + std::allocator_traits::deallocate(alloc, tmp, copies); + throw; + } +} + +template< class T, class SVMTrait, class... Args > +cl::pointer>> allocate_svm(Args... args) +{ + SVMAllocator alloc; + return cl::allocate_pointer(alloc, args...); +} + +template< class T, class SVMTrait, class... Args > +cl::pointer>> allocate_svm(const cl::Context &c, Args... args) +{ + SVMAllocator alloc(c); + return cl::allocate_pointer(alloc, args...); +} +#endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR) + +/*! \brief Vector alias to simplify contruction of coarse-grained SVM containers. + * + */ +template < class T > +using coarse_svm_vector = vector>>; + +/*! \brief Vector alias to simplify contruction of fine-grained SVM containers. +* +*/ +template < class T > +using fine_svm_vector = vector>>; + +/*! \brief Vector alias to simplify contruction of fine-grained SVM containers that support platform atomics. +* +*/ +template < class T > +using atomic_svm_vector = vector>>; + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + +/*! \brief Class interface for Buffer Memory Objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Buffer : public Memory +{ +public: + + /*! \brief Constructs a Buffer in a specified context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + */ + Buffer( + const Context& context, + cl_mem_flags flags, + size_type size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a Buffer in the default context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + * + * \see Context::getDefault() + */ + Buffer( + cl_mem_flags flags, + size_type size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(err); + + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer( + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr = false, + cl_int* err = NULL) + { + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + size_type size = sizeof(DataType)*(endIterator - startIterator); + + Context context = Context::getDefault(err); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + error = cl::copy(startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified context. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified queue. + * If useHostPtr is specified iterators must be random access. + */ + template< typename IteratorType > + Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Buffer() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with earlier versions. + * + * See Memory for further details. + */ + explicit Buffer(const cl_mem& buffer, bool retainObject = false) : + Memory(buffer, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Buffer& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer(const Buffer& buf) : Memory(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (const Buffer &buf) + { + Memory::operator=(buf); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer(Buffer&& buf) CL_HPP_NOEXCEPT_ : Memory(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (Buffer &&buf) + { + Memory::operator=(std::move(buf)); + return *this; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + /*! \brief Creates a new buffer object from this. + * + * Wraps clCreateSubBuffer(). + */ + Buffer createSubBuffer( + cl_mem_flags flags, + cl_buffer_create_type buffer_create_type, + const void * buffer_create_info, + cl_int * err = NULL) + { + Buffer result; + cl_int error; + result.object_ = ::clCreateSubBuffer( + object_, + flags, + buffer_create_type, + buffer_create_info, + &error); + + detail::errHandler(error, __CREATE_SUBBUFFER_ERR); + if (err != NULL) { + *err = error; + } + + return result; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 +}; + +#if defined (CL_HPP_USE_DX_INTEROP) +/*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's. + * + * This is provided to facilitate interoperability with Direct3D. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferD3D10 : public Buffer +{ +public: + + + /*! \brief Constructs a BufferD3D10, in a specified context, from a + * given ID3D10Buffer. + * + * Wraps clCreateFromD3D10BufferKHR(). + */ + BufferD3D10( + const Context& context, + cl_mem_flags flags, + ID3D10Buffer* bufobj, + cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr) + { + typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)( + cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer, + cl_int* errcode_ret); + PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR; +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + vector props = context.getInfo(); + cl_platform platform = -1; + for( int i = 0; i < props.size(); ++i ) { + if( props[i] == CL_CONTEXT_PLATFORM ) { + platform = props[i+1]; + } + } + CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR); +#elif CL_HPP_TARGET_OPENCL_VERSION >= 110 + CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR); +#endif + + cl_int error; + object_ = pfn_clCreateFromD3D10BufferKHR( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferD3D10() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) : + Buffer(buffer, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferD3D10& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(const BufferD3D10& buf) : + Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (const BufferD3D10 &buf) + { + Buffer::operator=(buf); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (BufferD3D10 &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } +}; +#endif + +/*! \brief Class interface for GL Buffer Memory Objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferGL : public Buffer +{ +public: + /*! \brief Constructs a BufferGL in a specified context, from a given + * GL buffer. + * + * Wraps clCreateFromGLBuffer(). + */ + BufferGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLBuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferGL() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit BufferGL(const cl_mem& buffer, bool retainObject = false) : + Buffer(buffer, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferGL& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL(const BufferGL& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (const BufferGL &buf) + { + Buffer::operator=(buf); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (BufferGL &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_,type,gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief Class interface for GL Render Buffer Memory Objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferRenderGL : public Buffer +{ +public: + /*! \brief Constructs a BufferRenderGL in a specified context, from a given + * GL Renderbuffer. + * + * Wraps clCreateFromGLRenderbuffer(). + */ + BufferRenderGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLRenderbuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferRenderGL() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) : + Buffer(buffer, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferRenderGL& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL(const BufferRenderGL& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (const BufferRenderGL &buf) + { + Buffer::operator=(buf); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (BufferRenderGL &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_,type,gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief C++ base class for Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image : public Memory +{ +protected: + //! \brief Default constructor - initializes to NULL. + Image() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image(const cl_mem& image, bool retainObject = false) : + Memory(image, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image(const Image& img) : Memory(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (const Image &img) + { + Memory::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image(Image&& img) CL_HPP_NOEXCEPT_ : Memory(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (Image &&img) + { + Memory::operator=(std::move(img)); + return *this; + } + + +public: + //! \brief Wrapper for clGetImageInfo(). + template + cl_int getImageInfo(cl_image_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetImageInfo, object_, name, param), + __GET_IMAGE_INFO_ERR); + } + + //! \brief Wrapper for clGetImageInfo() that returns by value. + template typename + detail::param_traits::param_type + getImageInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_image_info, name>::param_type param; + cl_int result = getImageInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +/*! \brief Class interface for 1D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image1D : public Image +{ +public: + /*! \brief Constructs a 1D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image1D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type width, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D, + width, + 0, 0, 0, 0, 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image1D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image1D(const cl_mem& image1D, bool retainObject = false) : + Image(image1D, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image1D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D(const Image1D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (const Image1D &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D(Image1D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (Image1D &&img) + { + Image::operator=(std::move(img)); + return *this; + } + +}; + +/*! \class Image1DBuffer + * \brief Image interface for 1D buffer images. + */ +class Image1DBuffer : public Image +{ +public: + Image1DBuffer( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type width, + const Buffer &buffer, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_BUFFER, + width, + 0, 0, 0, 0, 0, 0, 0, + buffer() + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + NULL, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DBuffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) : + Image(image1D, retainObject) { } + + Image1DBuffer& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(const Image1DBuffer& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (const Image1DBuffer &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (Image1DBuffer &&img) + { + Image::operator=(std::move(img)); + return *this; + } + +}; + +/*! \class Image1DArray + * \brief Image interface for arrays of 1D images. + */ +class Image1DArray : public Image +{ +public: + Image1DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type arraySize, + size_type width, + size_type rowPitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_ARRAY, + width, + 0, 0, // height, depth (unused) + arraySize, + rowPitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DArray() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) : + Image(imageArray, retainObject) { } + + + Image1DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(const Image1DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (const Image1DArray &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (Image1DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } + +}; +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120 + + +/*! \brief Class interface for 2D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image2D : public Image +{ +public: + /*! \brief Constructs a 2D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image2D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type width, + size_type height, + size_type row_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120 + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif CL_HPP_TARGET_OPENCL_VERSION >= 120 + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D, + width, + height, + 0, 0, // depth, array size (unused) + row_pitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#if CL_HPP_MINIMUM_OPENCL_VERSION < 120 + if (!useCreateImage) + { + object_ = ::clCreateImage2D( + context(), flags,&format, width, height, row_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE2D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120 + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR) + /*! \brief Constructs a 2D Image from a buffer. + * \note This will share storage with the underlying buffer. + * + * Wraps clCreateImage(). + */ + Image2D( + const Context& context, + ImageFormat format, + const Buffer &sourceBuffer, + size_type width, + size_type height, + size_type row_pitch = 0, + cl_int* err = nullptr) + { + cl_int error; + + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D, + width, + height, + 0, 0, // depth, array size (unused) + row_pitch, + 0, 0, 0, + // Use buffer as input to image + sourceBuffer() + }; + object_ = ::clCreateImage( + context(), + 0, // flags inherited from buffer + &format, + &desc, + nullptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != nullptr) { + *err = error; + } + } +#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR) + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /*! \brief Constructs a 2D Image from an image. + * \note This will share storage with the underlying image but may + * reinterpret the channel order and type. + * + * The image will be created matching with a descriptor matching the source. + * + * \param order is the channel order to reinterpret the image data as. + * The channel order may differ as described in the OpenCL + * 2.0 API specification. + * + * Wraps clCreateImage(). + */ + Image2D( + const Context& context, + cl_channel_order order, + const Image &sourceImage, + cl_int* err = nullptr) + { + cl_int error; + + // Descriptor fields have to match source image + size_type sourceWidth = + sourceImage.getImageInfo(); + size_type sourceHeight = + sourceImage.getImageInfo(); + size_type sourceRowPitch = + sourceImage.getImageInfo(); + cl_uint sourceNumMIPLevels = + sourceImage.getImageInfo(); + cl_uint sourceNumSamples = + sourceImage.getImageInfo(); + cl_image_format sourceFormat = + sourceImage.getImageInfo(); + + // Update only the channel order. + // Channel format inherited from source. + sourceFormat.image_channel_order = order; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D, + sourceWidth, + sourceHeight, + 0, 0, // depth (unused), array size (unused) + sourceRowPitch, + 0, // slice pitch (unused) + sourceNumMIPLevels, + sourceNumSamples, + // Use buffer as input to image + sourceImage() + }; + object_ = ::clCreateImage( + context(), + 0, // flags should be inherited from mem_object + &sourceFormat, + &desc, + nullptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != nullptr) { + *err = error; + } + } +#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + //! \brief Default constructor - initializes to NULL. + Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image2D(const cl_mem& image2D, bool retainObject = false) : + Image(image2D, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image2D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D(const Image2D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (const Image2D &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D(Image2D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (Image2D &&img) + { + Image::operator=(std::move(img)); + return *this; + } + +}; + + +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +/*! \brief Class interface for GL 2D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + * \note Deprecated for OpenCL 1.2. Please use ImageGL instead. + */ +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D +{ +public: + /*! \brief Constructs an Image2DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture2D(). + */ + Image2DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture2D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR); + if (err != NULL) { + *err = error; + } + + } + + //! \brief Default constructor - initializes to NULL. + Image2DGL() : Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image2DGL(const cl_mem& image, bool retainObject = false) : + Image2D(image, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + *c + * See Memory for further details. + */ + Image2DGL& operator = (const cl_mem& rhs) + { + Image2D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(const Image2DGL& img) : Image2D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (const Image2DGL &img) + { + Image2D::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT_ : Image2D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (Image2DGL &&img) + { + Image2D::operator=(std::move(img)); + return *this; + } + +} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +/*! \class Image2DArray + * \brief Image interface for arrays of 2D images. + */ +class Image2DArray : public Image +{ +public: + Image2DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type arraySize, + size_type width, + size_type height, + size_type rowPitch, + size_type slicePitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D_ARRAY, + width, + height, + 0, // depth (unused) + arraySize, + rowPitch, + slicePitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image2DArray() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { } + + Image2DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(const Image2DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (const Image2DArray &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (Image2DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } +}; +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120 + +/*! \brief Class interface for 3D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3D : public Image +{ +public: + /*! \brief Constructs a 3D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image3D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type width, + size_type height, + size_type depth, + size_type row_pitch = 0, + size_type slice_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120 + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif CL_HPP_TARGET_OPENCL_VERSION >= 120 + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE3D, + width, + height, + depth, + 0, // array size (unused) + row_pitch, + slice_pitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#if CL_HPP_MINIMUM_OPENCL_VERSION < 120 + if (!useCreateImage) + { + object_ = ::clCreateImage3D( + context(), flags, &format, width, height, depth, row_pitch, + slice_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE3D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120 + } + + //! \brief Default constructor - initializes to NULL. + Image3D() : Image() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image3D(const cl_mem& image3D, bool retainObject = false) : + Image(image3D, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D(const Image3D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (const Image3D &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D(Image3D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (Image3D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +}; + +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +/*! \brief Class interface for GL 3D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3DGL : public Image3D +{ +public: + /*! \brief Constructs an Image3DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture3D(). + */ + Image3DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture3D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image3DGL() : Image3D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image3DGL(const cl_mem& image, bool retainObject = false) : + Image3D(image, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3DGL& operator = (const cl_mem& rhs) + { + Image3D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(const Image3DGL& img) : Image3D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (const Image3DGL &img) + { + Image3D::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT_ : Image3D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (Image3DGL &&img) + { + Image3D::operator=(std::move(img)); + return *this; + } +}; +#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +/*! \class ImageGL + * \brief general image interface for GL interop. + * We abstract the 2D and 3D GL images into a single instance here + * that wraps all GL sourced images on the grounds that setup information + * was performed by OpenCL anyway. + */ +class ImageGL : public Image +{ +public: + ImageGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_ERR); + if (err != NULL) { + *err = error; + } + } + + ImageGL() : Image() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit ImageGL(const cl_mem& image, bool retainObject = false) : + Image(image, retainObject) { } + + ImageGL& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL(const ImageGL& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (const ImageGL &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (ImageGL &&img) + { + Image::operator=(std::move(img)); + return *this; + } +}; +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +/*! \brief Class interface for Pipe Memory Objects. +* +* See Memory for details about copy semantics, etc. +* +* \see Memory +*/ +class Pipe : public Memory +{ +public: + + /*! \brief Constructs a Pipe in a specified context. + * + * Wraps clCreatePipe(). + * @param context Context in which to create the pipe. + * @param flags Bitfield. Only CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS are valid. + * @param packet_size Size in bytes of a single packet of the pipe. + * @param max_packets Number of packets that may be stored in the pipe. + * + */ + Pipe( + const Context& context, + cl_uint packet_size, + cl_uint max_packets, + cl_int* err = NULL) + { + cl_int error; + + cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS; + object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error); + + detail::errHandler(error, __CREATE_PIPE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a Pipe in a the default context. + * + * Wraps clCreatePipe(). + * @param flags Bitfield. Only CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS are valid. + * @param packet_size Size in bytes of a single packet of the pipe. + * @param max_packets Number of packets that may be stored in the pipe. + * + */ + Pipe( + cl_uint packet_size, + cl_uint max_packets, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(err); + + cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS; + object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error); + + detail::errHandler(error, __CREATE_PIPE_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Pipe() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with earlier versions. + * + * See Memory for further details. + */ + explicit Pipe(const cl_mem& pipe, bool retainObject = false) : + Memory(pipe, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Pipe& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Pipe(const Pipe& pipe) : Memory(pipe) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Pipe& operator = (const Pipe &pipe) + { + Memory::operator=(pipe); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Pipe(Pipe&& pipe) CL_HPP_NOEXCEPT_ : Memory(std::move(pipe)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Pipe& operator = (Pipe &&pipe) + { + Memory::operator=(std::move(pipe)); + return *this; + } + + //! \brief Wrapper for clGetMemObjectInfo(). + template + cl_int getInfo(cl_pipe_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetPipeInfo, object_, name, param), + __GET_PIPE_INFO_ERR); + } + + //! \brief Wrapper for clGetMemObjectInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_pipe_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; // class Pipe +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200 + + +/*! \brief Class interface for cl_sampler. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_sampler as the original. For details, see + * clRetainSampler() and clReleaseSampler(). + * + * \see cl_sampler + */ +class Sampler : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Sampler() { } + + /*! \brief Constructs a Sampler in a specified context. + * + * Wraps clCreateSampler(). + */ + Sampler( + const Context& context, + cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, + cl_int* err = NULL) + { + cl_int error; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_sampler_properties sampler_properties[] = { + CL_SAMPLER_NORMALIZED_COORDS, normalized_coords, + CL_SAMPLER_ADDRESSING_MODE, addressing_mode, + CL_SAMPLER_FILTER_MODE, filter_mode, + 0 }; + object_ = ::clCreateSamplerWithProperties( + context(), + sampler_properties, + &error); + + detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateSampler( + context(), + normalized_coords, + addressing_mode, + filter_mode, + &error); + + detail::errHandler(error, __CREATE_SAMPLER_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + + /*! \brief Constructor from cl_sampler - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * This effectively transfers ownership of a refcount on the cl_sampler + * into the new Sampler object. + */ + explicit Sampler(const cl_sampler& sampler, bool retainObject = false) : + detail::Wrapper(sampler, retainObject) { } + + /*! \brief Assignment operator from cl_sampler - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseSampler() on the value previously held by this instance. + */ + Sampler& operator = (const cl_sampler& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler(const Sampler& sam) : detail::Wrapper(sam) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (const Sampler &sam) + { + detail::Wrapper::operator=(sam); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler(Sampler&& sam) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(sam)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (Sampler &&sam) + { + detail::Wrapper::operator=(std::move(sam)); + return *this; + } + + //! \brief Wrapper for clGetSamplerInfo(). + template + cl_int getInfo(cl_sampler_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetSamplerInfo, object_, name, param), + __GET_SAMPLER_INFO_ERR); + } + + //! \brief Wrapper for clGetSamplerInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_sampler_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +class Program; +class CommandQueue; +class DeviceCommandQueue; +class Kernel; + +//! \brief Class interface for specifying NDRange values. +class NDRange +{ +private: + size_type sizes_[3]; + cl_uint dimensions_; + +public: + //! \brief Default constructor - resulting range has zero dimensions. + NDRange() + : dimensions_(0) + { + sizes_[0] = 0; + sizes_[1] = 0; + sizes_[2] = 0; + } + + //! \brief Constructs one-dimensional range. + NDRange(size_type size0) + : dimensions_(1) + { + sizes_[0] = size0; + sizes_[1] = 1; + sizes_[2] = 1; + } + + //! \brief Constructs two-dimensional range. + NDRange(size_type size0, size_type size1) + : dimensions_(2) + { + sizes_[0] = size0; + sizes_[1] = size1; + sizes_[2] = 1; + } + + //! \brief Constructs three-dimensional range. + NDRange(size_type size0, size_type size1, size_type size2) + : dimensions_(3) + { + sizes_[0] = size0; + sizes_[1] = size1; + sizes_[2] = size2; + } + + /*! \brief Conversion operator to const size_type *. + * + * \returns a pointer to the size of the first dimension. + */ + operator const size_type*() const { + return sizes_; + } + + //! \brief Queries the number of dimensions in the range. + size_type dimensions() const + { + return dimensions_; + } + + //! \brief Returns the size of the object in bytes based on the + // runtime number of dimensions + size_type size() const + { + return dimensions_*sizeof(size_type); + } + + size_type* get() + { + return sizes_; + } + + const size_type* get() const + { + return sizes_; + } +}; + +//! \brief A zero-dimensional range. +static const NDRange NullRange; + +//! \brief Local address wrapper for use with Kernel::setArg +struct LocalSpaceArg +{ + size_type size_; +}; + +namespace detail { + +template +struct KernelArgumentHandler; + +// Enable for objects that are not subclasses of memory +// Pointers, constants etc +template +struct KernelArgumentHandler::value>::type> +{ + static size_type size(const T&) { return sizeof(T); } + static const T* ptr(const T& value) { return &value; } +}; + +// Enable for subclasses of memory where we want to get a reference to the cl_mem out +// and pass that in for safety +template +struct KernelArgumentHandler::value>::type> +{ + static size_type size(const T&) { return sizeof(cl_mem); } + static const cl_mem* ptr(const T& value) { return &(value()); } +}; + +// Specialization for DeviceCommandQueue defined later + +template <> +struct KernelArgumentHandler +{ + static size_type size(const LocalSpaceArg& value) { return value.size_; } + static const void* ptr(const LocalSpaceArg&) { return NULL; } +}; + +} +//! \endcond + +/*! Local + * \brief Helper function for generating LocalSpaceArg objects. + */ +inline LocalSpaceArg +Local(size_type size) +{ + LocalSpaceArg ret = { size }; + return ret; +} + +/*! \brief Class interface for cl_kernel. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_kernel as the original. For details, see + * clRetainKernel() and clReleaseKernel(). + * + * \see cl_kernel + */ +class Kernel : public detail::Wrapper +{ +public: + inline Kernel(const Program& program, const char* name, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Kernel() { } + + /*! \brief Constructor from cl_kernel - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * This effectively transfers ownership of a refcount on the cl_kernel + * into the new Kernel object. + */ + explicit Kernel(const cl_kernel& kernel, bool retainObject = false) : + detail::Wrapper(kernel, retainObject) { } + + /*! \brief Assignment operator from cl_kernel - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseKernel() on the value previously held by this instance. + */ + Kernel& operator = (const cl_kernel& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel(const Kernel& kernel) : detail::Wrapper(kernel) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (const Kernel &kernel) + { + detail::Wrapper::operator=(kernel); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(kernel)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (Kernel &&kernel) + { + detail::Wrapper::operator=(std::move(kernel)); + return *this; + } + + template + cl_int getInfo(cl_kernel_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelInfo, object_, name, param), + __GET_KERNEL_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + template + cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param), + __GET_KERNEL_ARG_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getArgInfo(cl_uint argIndex, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_arg_info, name>::param_type param; + cl_int result = getArgInfo(argIndex, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + template + cl_int getWorkGroupInfo( + const Device& device, cl_kernel_work_group_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetKernelWorkGroupInfo, object_, device(), name, param), + __GET_KERNEL_WORK_GROUP_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getWorkGroupInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_work_group_info, name>::param_type param; + cl_int result = getWorkGroupInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +#if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) + cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const + { + typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR; + static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL; + CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR); + + return detail::errHandler( + pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr), + __GET_KERNEL_ARG_INFO_ERR); + } + + template + size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = NULL) const + { + size_type param; + cl_int result = getSubGroupInfo(dev, name, range, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +#endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /*! \brief setArg overload taking a shared_ptr type + */ + template + cl_int setArg(cl_uint index, const cl::pointer &argPtr) + { + return detail::errHandler( + ::clSetKernelArgSVMPointer(object_, index, argPtr.get()), + __SET_KERNEL_ARGS_ERR); + } + + /*! \brief setArg overload taking a vector type. + */ + template + cl_int setArg(cl_uint index, const cl::vector &argPtr) + { + return detail::errHandler( + ::clSetKernelArgSVMPointer(object_, index, argPtr.data()), + __SET_KERNEL_ARGS_ERR); + } + + /*! \brief setArg overload taking a pointer type + */ + template + typename std::enable_if::value, cl_int>::type + setArg(cl_uint index, const T argPtr) + { + return detail::errHandler( + ::clSetKernelArgSVMPointer(object_, index, argPtr), + __SET_KERNEL_ARGS_ERR); + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + /*! \brief setArg overload taking a POD type + */ + template + typename std::enable_if::value, cl_int>::type + setArg(cl_uint index, const T &value) + { + return detail::errHandler( + ::clSetKernelArg( + object_, + index, + detail::KernelArgumentHandler::size(value), + detail::KernelArgumentHandler::ptr(value)), + __SET_KERNEL_ARGS_ERR); + } + + cl_int setArg(cl_uint index, size_type size, const void* argPtr) + { + return detail::errHandler( + ::clSetKernelArg(object_, index, size, argPtr), + __SET_KERNEL_ARGS_ERR); + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /*! + * Specify a vector of SVM pointers that the kernel may access in + * addition to its arguments. + */ + cl_int setSVMPointers(const vector &pointerList) + { + return detail::errHandler( + ::clSetKernelExecInfo( + object_, + CL_KERNEL_EXEC_INFO_SVM_PTRS, + sizeof(void*)*pointerList.size(), + pointerList.data())); + } + + /*! + * Specify a std::array of SVM pointers that the kernel may access in + * addition to its arguments. + */ + template + cl_int setSVMPointers(const std::array &pointerList) + { + return detail::errHandler( + ::clSetKernelExecInfo( + object_, + CL_KERNEL_EXEC_INFO_SVM_PTRS, + sizeof(void*)*pointerList.size(), + pointerList.data())); + } + + /*! \brief Enable fine-grained system SVM. + * + * \note It is only possible to enable fine-grained system SVM if all devices + * in the context associated with kernel support it. + * + * \param svmEnabled True if fine-grained system SVM is requested. False otherwise. + * \return CL_SUCCESS if the function was executed succesfully. CL_INVALID_OPERATION + * if no devices in the context support fine-grained system SVM. + * + * \see clSetKernelExecInfo + */ + cl_int enableFineGrainedSystemSVM(bool svmEnabled) + { + cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE; + return detail::errHandler( + ::clSetKernelExecInfo( + object_, + CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, + sizeof(cl_bool), + &svmEnabled_ + ) + ); + } + + template + void setSVMPointersHelper(std::array &pointerList, const pointer &t0, Ts... ts) + { + pointerList[index] = static_cast(t0.get()); + setSVMPointersHelper(ts...); + } + + template + typename std::enable_if::value, void>::type + setSVMPointersHelper(std::array &pointerList, T0 t0, Ts... ts) + { + pointerList[index] = static_cast(t0); + setSVMPointersHelper(ts...); + } + + template + void setSVMPointersHelper(std::array &pointerList, const pointer &t0) + { + pointerList[index] = static_cast(t0.get()); + } + + template + typename std::enable_if::value, void>::type + setSVMPointersHelper(std::array &pointerList, T0 t0) + { + pointerList[index] = static_cast(t0); + } + + template + cl_int setSVMPointers(const T0 &t0, Ts... ts) + { + std::array pointerList; + + setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...); + return detail::errHandler( + ::clSetKernelExecInfo( + object_, + CL_KERNEL_EXEC_INFO_SVM_PTRS, + sizeof(void*)*(1 + sizeof...(Ts)), + pointerList.data())); + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 +}; + +/*! \class Program + * \brief Program interface that implements cl_program. + */ +class Program : public detail::Wrapper +{ +public: +#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + typedef vector> Binaries; + typedef vector Sources; +#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + typedef vector > Binaries; + typedef vector > Sources; +#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + + Program( + const string& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const size_type length = source.size(); + + Context context = Context::getDefault(err); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + + error = ::clBuildProgram( + object_, + 0, + NULL, +#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD) + "-cl-std=CL2.0", +#else + "", +#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD) + NULL, + NULL); + + detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo()); + } + + if (err != NULL) { + *err = error; + } + } + + Program( + const Context& context, + const string& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const size_type length = source.size(); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + error = ::clBuildProgram( + object_, + 0, + NULL, +#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD) + "-cl-std=CL2.0", +#else + "", +#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD) + NULL, + NULL); + + detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo()); + } + + if (err != NULL) { + *err = error; + } + } + + /** + * Create a program from a vector of source strings and the default context. + * Does not compile or link the program. + */ + Program( + const Sources& sources, + cl_int* err = NULL) + { + cl_int error; + Context context = Context::getDefault(err); + + const size_type n = (size_type)sources.size(); + + vector lengths(n); + vector strings(n); + + for (size_type i = 0; i < n; ++i) { +#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + strings[i] = sources[(int)i].data(); + lengths[i] = sources[(int)i].length(); +#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + strings[i] = sources[(int)i].first; + lengths[i] = sources[(int)i].second; +#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + } + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)n, strings.data(), lengths.data(), &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + if (err != NULL) { + *err = error; + } + } + + /** + * Create a program from a vector of source strings and a provided context. + * Does not compile or link the program. + */ + Program( + const Context& context, + const Sources& sources, + cl_int* err = NULL) + { + cl_int error; + + const size_type n = (size_type)sources.size(); + + vector lengths(n); + vector strings(n); + + for (size_type i = 0; i < n; ++i) { +#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + strings[i] = sources[(int)i].data(); + lengths[i] = sources[(int)i].length(); +#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + strings[i] = sources[(int)i].first; + lengths[i] = sources[(int)i].second; +#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + } + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)n, strings.data(), lengths.data(), &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + if (err != NULL) { + *err = error; + } + } + + /** + * Construct a program object from a list of devices and a per-device list of binaries. + * \param context A valid OpenCL context in which to construct the program. + * \param devices A vector of OpenCL device objects for which the program will be created. + * \param binaries A vector of pairs of a pointer to a binary object and its length. + * \param binaryStatus An optional vector that on completion will be resized to + * match the size of binaries and filled with values to specify if each binary + * was successfully loaded. + * Set to CL_SUCCESS if the binary was successfully loaded. + * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL. + * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device. + * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors: + * CL_INVALID_CONTEXT if context is not a valid context. + * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices; + * or if any entry in binaries is NULL or has length 0. + * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context. + * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device. + * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host. + */ + Program( + const Context& context, + const vector& devices, + const Binaries& binaries, + vector* binaryStatus = NULL, + cl_int* err = NULL) + { + cl_int error; + + const size_type numDevices = devices.size(); + + // Catch size mismatch early and return + if(binaries.size() != numDevices) { + error = CL_INVALID_VALUE; + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + + vector lengths(numDevices); + vector images(numDevices); +#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + for (size_type i = 0; i < numDevices; ++i) { + images[i] = binaries[i].data(); + lengths[i] = binaries[(int)i].size(); + } +#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + for (size_type i = 0; i < numDevices; ++i) { + images[i] = (const unsigned char*)binaries[i].first; + lengths[i] = binaries[(int)i].second; + } +#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + + vector deviceIDs(numDevices); + for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + if(binaryStatus) { + binaryStatus->resize(numDevices); + } + + object_ = ::clCreateProgramWithBinary( + context(), (cl_uint) devices.size(), + deviceIDs.data(), + lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0) + ? &binaryStatus->front() + : NULL, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + } + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + /** + * Create program using builtin kernels. + * \param kernelNames Semi-colon separated list of builtin kernel names + */ + Program( + const Context& context, + const vector& devices, + const string& kernelNames, + cl_int* err = NULL) + { + cl_int error; + + + size_type numDevices = devices.size(); + vector deviceIDs(numDevices); + for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateProgramWithBuiltInKernels( + context(), + (cl_uint) devices.size(), + deviceIDs.data(), + kernelNames.c_str(), + &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + Program() { } + + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + */ + explicit Program(const cl_program& program, bool retainObject = false) : + detail::Wrapper(program, retainObject) { } + + Program& operator = (const cl_program& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program(const Program& program) : detail::Wrapper(program) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (const Program &program) + { + detail::Wrapper::operator=(program); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Program(Program&& program) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(program)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (Program &&program) + { + detail::Wrapper::operator=(std::move(program)); + return *this; + } + + cl_int build( + const vector& devices, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + size_type numDevices = devices.size(); + vector deviceIDs(numDevices); + + for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + cl_int buildError = ::clBuildProgram( + object_, + (cl_uint) + devices.size(), + deviceIDs.data(), + options, + notifyFptr, + data); + + return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo()); + } + + cl_int build( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + cl_int buildError = ::clBuildProgram( + object_, + 0, + NULL, + options, + notifyFptr, + data); + + + return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo()); + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + cl_int compile( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + cl_int error = ::clCompileProgram( + object_, + 0, + NULL, + options, + 0, + NULL, + NULL, + notifyFptr, + data); + return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo()); + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + template + cl_int getInfo(cl_program_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetProgramInfo, object_, name, param), + __GET_PROGRAM_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + template + cl_int getBuildInfo( + const Device& device, cl_program_build_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetProgramBuildInfo, object_, device(), name, param), + __GET_PROGRAM_BUILD_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getBuildInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_build_info, name>::param_type param; + cl_int result = getBuildInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /** + * Build info function that returns a vector of device/info pairs for the specified + * info type and for all devices in the program. + * On an error reading the info for any device, an empty vector of info will be returned. + */ + template + vector::param_type>> + getBuildInfo(cl_int *err = NULL) const + { + cl_int result = CL_SUCCESS; + + auto devs = getInfo(&result); + vector::param_type>> + devInfo; + + // If there was an initial error from getInfo return the error + if (result != CL_SUCCESS) { + if (err != NULL) { + *err = result; + } + return devInfo; + } + + for (const cl::Device &d : devs) { + typename detail::param_traits< + detail::cl_program_build_info, name>::param_type param; + result = getBuildInfo(d, name, ¶m); + devInfo.push_back( + std::pair::param_type> + (d, param)); + if (result != CL_SUCCESS) { + // On error, leave the loop and return the error code + break; + } + } + if (err != NULL) { + *err = result; + } + if (result != CL_SUCCESS) { + devInfo.clear(); + } + return devInfo; + } + + cl_int createKernels(vector* kernels) + { + cl_uint numKernels; + cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + vector value(numKernels); + + err = ::clCreateKernelsInProgram( + object_, numKernels, value.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + if (kernels) { + kernels->resize(value.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < value.size(); i++) { + // We do not need to retain because this kernel is being created + // by the runtime + (*kernels)[i] = Kernel(value[i], false); + } + } + return CL_SUCCESS; + } +}; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +inline Program linkProgram( + Program input1, + Program input2, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + cl_program programs[2] = { input1(), input2() }; + + Context ctx = input1.getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + 2, + programs, + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog); +} + +inline Program linkProgram( + vector inputPrograms, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + vector programs(inputPrograms.size()); + + for (unsigned int i = 0; i < inputPrograms.size(); i++) { + programs[i] = inputPrograms[i](); + } + + Context ctx; + if(inputPrograms.size() > 0) { + ctx = inputPrograms[0].getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + } + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + (cl_uint)inputPrograms.size(), + programs.data(), + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog, false); +} +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + +// Template specialization for CL_PROGRAM_BINARIES +template <> +inline cl_int cl::Program::getInfo(cl_program_info name, vector>* param) const +{ + if (name != CL_PROGRAM_BINARIES) { + return CL_INVALID_VALUE; + } + if (param) { + // Resize the parameter array appropriately for each allocation + // and pass down to the helper + + vector sizes = getInfo(); + size_type numBinaries = sizes.size(); + + // Resize the parameter array and constituent arrays + param->resize(numBinaries); + for (size_type i = 0; i < numBinaries; ++i) { + (*param)[i].resize(sizes[i]); + } + + return detail::errHandler( + detail::getInfo(&::clGetProgramInfo, object_, name, param), + __GET_PROGRAM_INFO_ERR); + } + + return CL_SUCCESS; +} + +template<> +inline vector> cl::Program::getInfo(cl_int* err) const +{ + vector> binariesVectors; + + cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors); + if (err != NULL) { + *err = result; + } + return binariesVectors; +} + +inline Kernel::Kernel(const Program& program, const char* name, cl_int* err) +{ + cl_int error; + + object_ = ::clCreateKernel(program(), name, &error); + detail::errHandler(error, __CREATE_KERNEL_ERR); + + if (err != NULL) { + *err = error; + } + +} + +enum class QueueProperties : cl_command_queue_properties +{ + None = 0, + Profiling = CL_QUEUE_PROFILING_ENABLE, + OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, +}; + +inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs) +{ + return static_cast(static_cast(lhs) | static_cast(rhs)); +} + +/*! \class CommandQueue + * \brief CommandQueue interface for cl_command_queue. + */ +class CommandQueue : public detail::Wrapper +{ +private: + static std::once_flag default_initialized_; + static CommandQueue default_; + static cl_int default_error_; + + /*! \brief Create the default command queue returned by @ref getDefault. + * + * It sets default_error_ to indicate success or failure. It does not throw + * @c cl::Error. + */ + static void makeDefault() + { + /* We don't want to throw an error from this function, so we have to + * catch and set the error flag. + */ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try +#endif + { + int error; + Context context = Context::getDefault(&error); + + if (error != CL_SUCCESS) { + default_error_ = error; + } + else { + Device device = Device::getDefault(); + default_ = CommandQueue(context, device, 0, &default_error_); + } + } +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + catch (cl::Error &e) { + default_error_ = e.err(); + } +#endif + } + + /*! \brief Create the default command queue. + * + * This sets @c default_. It does not throw + * @c cl::Error. + */ + static void makeDefaultProvided(const CommandQueue &c) { + default_ = c; + } + +public: +#ifdef CL_HPP_UNIT_TEST_ENABLE + /*! \brief Reset the default. + * + * This sets @c default_ to an empty value to support cleanup in + * the unit test framework. + * This function is not thread safe. + */ + static void unitTestClearDefault() { + default_ = CommandQueue(); + } +#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE + + + /*! + * \brief Constructs a CommandQueue based on passed properties. + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + CommandQueue( + cl_command_queue_properties properties, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, 0 }; + if ((properties & CL_QUEUE_ON_DEVICE) == 0) { + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + } + else { + error = CL_INVALID_QUEUE_PROPERTIES; + } + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + } + + /*! + * \brief Constructs a CommandQueue based on passed properties. + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + CommandQueue( + QueueProperties properties, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, static_cast(properties), 0 }; + + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), device(), static_cast(properties), &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + } + + /*! + * \brief Constructs a CommandQueue for an implementation defined device in the given context + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + explicit CommandQueue( + const Context& context, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + vector devices; + error = context.getInfo(CL_CONTEXT_DEVICES, &devices); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) + { + if (err != NULL) { + *err = error; + } + return; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, 0 }; + if ((properties & CL_QUEUE_ON_DEVICE) == 0) { + object_ = ::clCreateCommandQueueWithProperties( + context(), devices[0](), queue_properties, &error); + } + else { + error = CL_INVALID_QUEUE_PROPERTIES; + } + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), devices[0](), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + + } + + /*! + * \brief Constructs a CommandQueue for an implementation defined device in the given context + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + explicit CommandQueue( + const Context& context, + QueueProperties properties, + cl_int* err = NULL) + { + cl_int error; + vector devices; + error = context.getInfo(CL_CONTEXT_DEVICES, &devices); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) + { + if (err != NULL) { + *err = error; + } + return; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, static_cast(properties), 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), devices[0](), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), devices[0](), static_cast(properties), &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + + } + + /*! + * \brief Constructs a CommandQueue for a passed device and context + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + CommandQueue( + const Context& context, + const Device& device, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + + /*! + * \brief Constructs a CommandQueue for a passed device and context + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + CommandQueue( + const Context& context, + const Device& device, + QueueProperties properties, + cl_int* err = NULL) + { + cl_int error; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, static_cast(properties), 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), device(), static_cast(properties), &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + + static CommandQueue getDefault(cl_int * err = NULL) + { + std::call_once(default_initialized_, makeDefault); +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); +#else // CL_HPP_TARGET_OPENCL_VERSION >= 200 + detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR); +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200 + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + /** + * Modify the default command queue to be used by + * subsequent operations. + * Will only set the default if no default was previously created. + * @return updated default command queue. + * Should be compared to the passed value to ensure that it was updated. + */ + static CommandQueue setDefault(const CommandQueue &default_queue) + { + std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue)); + detail::errHandler(default_error_); + return default_; + } + + CommandQueue() { } + + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + */ + explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) : + detail::Wrapper(commandQueue, retainObject) { } + + CommandQueue& operator = (const cl_command_queue& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(const CommandQueue& queue) : detail::Wrapper(queue) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (const CommandQueue &queue) + { + detail::Wrapper::operator=(queue); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(queue)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (CommandQueue &&queue) + { + detail::Wrapper::operator=(std::move(queue)); + return *this; + } + + template + cl_int getInfo(cl_command_queue_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetCommandQueueInfo, object_, name, param), + __GET_COMMAND_QUEUE_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_command_queue_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + size_type offset, + size_type size, + void* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + size_type offset, + size_type size, + const void* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + size_type src_offset, + size_type dst_offset, + size_type size, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBuffer( + object_, src(), dst(), src_offset, dst_offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const array& buffer_offset, + const array& host_offset, + const array& region, + size_type buffer_row_pitch, + size_type buffer_slice_pitch, + size_type host_row_pitch, + size_type host_slice_pitch, + void *ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBufferRect( + object_, + buffer(), + blocking, + buffer_offset.data(), + host_offset.data(), + region.data(), + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const array& buffer_offset, + const array& host_offset, + const array& region, + size_type buffer_row_pitch, + size_type buffer_slice_pitch, + size_type host_row_pitch, + size_type host_slice_pitch, + const void *ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBufferRect( + object_, + buffer(), + blocking, + buffer_offset.data(), + host_offset.data(), + region.data(), + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const array& src_origin, + const array& dst_origin, + const array& region, + size_type src_row_pitch, + size_type src_slice_pitch, + size_type dst_row_pitch, + size_type dst_slice_pitch, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferRect( + object_, + src(), + dst(), + src_origin.data(), + dst_origin.data(), + region.data(), + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + /** + * Enqueue a command to fill a buffer object with a pattern + * of a given size. The pattern is specified as a vector type. + * \tparam PatternType The datatype of the pattern field. + * The pattern type must be an accepted OpenCL data type. + * \tparam offset Is the offset in bytes into the buffer at + * which to start filling. This must be a multiple of + * the pattern size. + * \tparam size Is the size in bytes of the region to fill. + * This must be a multiple of the pattern size. + */ + template + cl_int enqueueFillBuffer( + const Buffer& buffer, + PatternType pattern, + size_type offset, + size_type size, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillBuffer( + object_, + buffer(), + static_cast(&pattern), + sizeof(PatternType), + offset, + size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const array& origin, + const array& region, + size_type row_pitch, + size_type slice_pitch, + void* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadImage( + object_, + image(), + blocking, + origin.data(), + region.data(), + row_pitch, + slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const array& origin, + const array& region, + size_type row_pitch, + size_type slice_pitch, + const void* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteImage( + object_, + image(), + blocking, + origin.data(), + region.data(), + row_pitch, + slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const array& src_origin, + const array& dst_origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImage( + object_, + src(), + dst(), + src_origin.data(), + dst_origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA floating-point color value if + * the image channel data type is not an unnormalized signed or + * unsigned data type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_float4 fillColor, + const array& origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA signed integer color value if + * the image channel data type is an unnormalized signed integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_int4 fillColor, + const array& origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA unsigned integer color value if + * the image channel data type is an unnormalized unsigned integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_uint4 fillColor, + const array& origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const array& src_origin, + const array& region, + size_type dst_offset, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImageToBuffer( + object_, + src(), + dst(), + src_origin.data(), + region.data(), + dst_offset, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + size_type src_offset, + const array& dst_origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferToImage( + object_, + src(), + dst(), + src_offset, + dst_origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + size_type offset, + size_type size, + const vector* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapBuffer( + object_, buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + + return result; + } + + void* enqueueMapImage( + const Image& buffer, + cl_bool blocking, + cl_map_flags flags, + const array& origin, + const array& region, + size_type * row_pitch, + size_type * slice_pitch, + const vector* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapImage( + object_, buffer(), blocking, flags, + origin.data(), + region.data(), + row_pitch, slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + return result; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /** + * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer. + * This variant takes a raw SVM pointer. + */ + template + cl_int enqueueMapSVM( + T* ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler(::clEnqueueSVMMap( + object_, blocking, flags, static_cast(ptr), size, + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MAP_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + + /** + * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer. + * This variant takes a cl::pointer instance. + */ + template + cl_int enqueueMapSVM( + cl::pointer &ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler(::clEnqueueSVMMap( + object_, blocking, flags, static_cast(ptr.get()), size, + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MAP_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer. + * This variant takes a cl::vector instance. + */ + template + cl_int enqueueMapSVM( + cl::vector &container, + cl_bool blocking, + cl_map_flags flags, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler(::clEnqueueSVMMap( + object_, blocking, flags, static_cast(container.data()), container.size(), + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MAP_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + object_, memory(), mapped_ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /** + * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime. + * This variant takes a raw SVM pointer. + */ + template + cl_int enqueueUnmapSVM( + T* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueSVMUnmap( + object_, static_cast(ptr), + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime. + * This variant takes a cl::pointer instance. + */ + template + cl_int enqueueUnmapSVM( + cl::pointer &ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueSVMUnmap( + object_, static_cast(ptr.get()), + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime. + * This variant takes a cl::vector instance. + */ + template + cl_int enqueueUnmapSVM( + cl::vector &container, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueSVMUnmap( + object_, static_cast(container.data()), + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + /** + * Enqueues a marker command which waits for either a list of events to complete, + * or all previously enqueued commands to complete. + * + * Enqueues a marker command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command returns an event which can be waited on, + * i.e. this event can be waited on to insure that all events either in the event_wait_list + * or all previously enqueued commands, queued before this command to command_queue, + * have completed. + */ + cl_int enqueueMarkerWithWaitList( + const vector *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarkerWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * A synchronization point that enqueues a barrier operation. + * + * Enqueues a barrier command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command blocks command execution, that is, any + * following commands enqueued after it do not execute until it completes. This command + * returns an event which can be waited on, i.e. this event can be waited on to insure that + * all events either in the event_wait_list or all previously enqueued commands, queued + * before this command to command_queue, have completed. + */ + cl_int enqueueBarrierWithWaitList( + const vector *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueBarrierWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_BARRIER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command to indicate with which device a set of memory objects + * should be associated. + */ + cl_int enqueueMigrateMemObjects( + const vector &memObjects, + cl_mem_migration_flags flags, + const vector* events = NULL, + Event* event = NULL + ) const + { + cl_event tmp; + + vector localMemObjects(memObjects.size()); + + for( int i = 0; i < (int)memObjects.size(); ++i ) { + localMemObjects[i] = memObjects[i](); + } + + + cl_int err = detail::errHandler( + ::clEnqueueMigrateMemObjects( + object_, + (cl_uint)memObjects.size(), + localMemObjects.data(), + flags, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + cl_int enqueueNDRangeKernel( + const Kernel& kernel, + const NDRange& offset, + const NDRange& global, + const NDRange& local = NullRange, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNDRangeKernel( + object_, kernel(), (cl_uint) global.dimensions(), + offset.dimensions() != 0 ? (const size_type*) offset : NULL, + (const size_type*) global, + local.dimensions() != 0 ? (const size_type*) local : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NDRANGE_KERNEL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) + CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask( + const Kernel& kernel, + const vector* events = NULL, + Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueTask( + object_, kernel(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_TASK_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) + + cl_int enqueueNativeKernel( + void (CL_CALLBACK *userFptr)(void *), + std::pair args, + const vector* mem_objects = NULL, + const vector* mem_locs = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + size_type elements = 0; + if (mem_objects != NULL) { + elements = mem_objects->size(); + } + vector mems(elements); + for (unsigned int i = 0; i < elements; i++) { + mems[i] = ((*mem_objects)[i])(); + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNativeKernel( + object_, userFptr, args.first, args.second, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + mems.data(), + (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NATIVE_KERNEL); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarker( + object_, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueWaitForEvents(const vector& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueWaitForEvents( + object_, + (cl_uint) events.size(), + events.size() > 0 ? (const cl_event*) &events.front() : NULL), + __ENQUEUE_WAIT_FOR_EVENTS_ERR); + } +#endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + + cl_int enqueueAcquireGLObjects( + const vector* mem_objects = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueAcquireGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseGLObjects( + const vector* mem_objects = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReleaseGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined (CL_HPP_USE_DX_INTEROP) +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); + + cl_int enqueueAcquireD3D10Objects( + const vector* mem_objects = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL; +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR); +#endif +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR); +#endif + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueAcquireD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseD3D10Objects( + const vector* mem_objects = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL; +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR); +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR); +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueReleaseD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueBarrier(object_), + __ENQUEUE_BARRIER_ERR); + } +#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS + + cl_int flush() const + { + return detail::errHandler(::clFlush(object_), __FLUSH_ERR); + } + + cl_int finish() const + { + return detail::errHandler(::clFinish(object_), __FINISH_ERR); + } +}; // CommandQueue + +CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_; +CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_; +CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS; + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +enum class DeviceQueueProperties : cl_command_queue_properties +{ + None = 0, + Profiling = CL_QUEUE_PROFILING_ENABLE, +}; + +inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs) +{ + return static_cast(static_cast(lhs) | static_cast(rhs)); +} + +/*! \class DeviceCommandQueue + * \brief DeviceCommandQueue interface for device cl_command_queues. + */ +class DeviceCommandQueue : public detail::Wrapper +{ +public: + + /*! + * Trivial empty constructor to create a null queue. + */ + DeviceCommandQueue() { } + + /*! + * Default construct device command queue on default context and device + */ + DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = NULL) + { + cl_int error; + cl::Context context = cl::Context::getDefault(); + cl::Device device = cl::Device::getDefault(); + + cl_command_queue_properties mergedProperties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast(properties); + + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, mergedProperties, 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! + * Create a device command queue for a specified device in the passed context. + */ + DeviceCommandQueue( + const Context& context, + const Device& device, + DeviceQueueProperties properties = DeviceQueueProperties::None, + cl_int* err = NULL) + { + cl_int error; + + cl_command_queue_properties mergedProperties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast(properties); + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, mergedProperties, 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! + * Create a device command queue for a specified device in the passed context. + */ + DeviceCommandQueue( + const Context& context, + const Device& device, + cl_uint queueSize, + DeviceQueueProperties properties = DeviceQueueProperties::None, + cl_int* err = NULL) + { + cl_int error; + + cl_command_queue_properties mergedProperties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast(properties); + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, mergedProperties, + CL_QUEUE_SIZE, queueSize, + 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructor from cl_command_queue - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + */ + explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) : + detail::Wrapper(commandQueue, retainObject) { } + + DeviceCommandQueue& operator = (const cl_command_queue& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + DeviceCommandQueue(const DeviceCommandQueue& queue) : detail::Wrapper(queue) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + DeviceCommandQueue& operator = (const DeviceCommandQueue &queue) + { + detail::Wrapper::operator=(queue); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + DeviceCommandQueue(DeviceCommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(queue)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + DeviceCommandQueue& operator = (DeviceCommandQueue &&queue) + { + detail::Wrapper::operator=(std::move(queue)); + return *this; + } + + template + cl_int getInfo(cl_command_queue_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetCommandQueueInfo, object_, name, param), + __GET_COMMAND_QUEUE_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_command_queue_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! + * Create a new default device command queue for the default device, + * in the default context and of the default size. + * If there is already a default queue for the specified device this + * function will return the pre-existing queue. + */ + static DeviceCommandQueue makeDefault( + cl_int *err = nullptr) + { + cl_int error; + cl::Context context = cl::Context::getDefault(); + cl::Device device = cl::Device::getDefault(); + + cl_command_queue_properties properties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT; + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, + 0 }; + DeviceCommandQueue deviceQueue( + ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error)); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + + return deviceQueue; + } + + /*! + * Create a new default device command queue for the specified device + * and of the default size. + * If there is already a default queue for the specified device this + * function will return the pre-existing queue. + */ + static DeviceCommandQueue makeDefault( + const Context &context, const Device &device, cl_int *err = nullptr) + { + cl_int error; + + cl_command_queue_properties properties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT; + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, + 0 }; + DeviceCommandQueue deviceQueue( + ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error)); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + + return deviceQueue; + } + + /*! + * Create a new default device command queue for the specified device + * and of the requested size in bytes. + * If there is already a default queue for the specified device this + * function will return the pre-existing queue. + */ + static DeviceCommandQueue makeDefault( + const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr) + { + cl_int error; + + cl_command_queue_properties properties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT; + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, + CL_QUEUE_SIZE, queueSize, + 0 }; + DeviceCommandQueue deviceQueue( + ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error)); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + + return deviceQueue; + } +}; // DeviceCommandQueue + +namespace detail +{ + // Specialization for device command queue + template <> + struct KernelArgumentHandler + { + static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); } + static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); } + }; +} // namespace detail + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + +template< typename IteratorType > +Buffer::Buffer( + const Context &context, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + size_type size = sizeof(DataType)*(endIterator - startIterator); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + CommandQueue queue(context, 0, &error); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +template< typename IteratorType > +Buffer::Buffer( + const CommandQueue &queue, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if (readOnly) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + } + + size_type size = sizeof(DataType)*(endIterator - startIterator); + + Context context = queue.getInfo(); + + if (useHostPtr) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } + else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if (!useHostPtr) { + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +inline cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + size_type offset, + size_type size, + void* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + size_type offset, + size_type size, + const void* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + size_type offset, + size_type size, + const vector* events = NULL, + Event* event = NULL, + cl_int* err = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + void * result = ::clEnqueueMapBuffer( + queue(), buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (cl_event*) event, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + return result; +} + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +/** + * Enqueues to the default queue a command that will allow the host to + * update a region of a coarse-grained SVM buffer. + * This variant takes a raw SVM pointer. + */ +template +inline cl_int enqueueMapSVM( + T* ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events, + Event* event) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + } + + return queue.enqueueMapSVM( + ptr, blocking, flags, size, events, event); +} + +/** + * Enqueues to the default queue a command that will allow the host to + * update a region of a coarse-grained SVM buffer. + * This variant takes a cl::pointer instance. + */ +template +inline cl_int enqueueMapSVM( + cl::pointer ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + } + + return queue.enqueueMapSVM( + ptr, blocking, flags, size, events, event); +} + +/** + * Enqueues to the default queue a command that will allow the host to + * update a region of a coarse-grained SVM buffer. + * This variant takes a cl::vector instance. + */ +template +inline cl_int enqueueMapSVM( + cl::vector container, + cl_bool blocking, + cl_map_flags flags, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + } + + return queue.enqueueMapSVM( + container, blocking, flags, events, event); +} + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +inline cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (error != CL_SUCCESS) { + return error; + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + queue(), memory(), mapped_ptr, + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; +} + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +/** + * Enqueues to the default queue a command that will release a coarse-grained + * SVM buffer back to the OpenCL runtime. + * This variant takes a raw SVM pointer. + */ +template +inline cl_int enqueueUnmapSVM( + T* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + } + + return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + +} + +/** + * Enqueues to the default queue a command that will release a coarse-grained + * SVM buffer back to the OpenCL runtime. + * This variant takes a cl::pointer instance. + */ +template +inline cl_int enqueueUnmapSVM( + cl::pointer &ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + } + + return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); +} + +/** + * Enqueues to the default queue a command that will release a coarse-grained + * SVM buffer back to the OpenCL runtime. + * This variant takes a cl::vector instance. + */ +template +inline cl_int enqueueUnmapSVM( + cl::vector &container, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + } + + return detail::errHandler(queue.enqueueUnmapSVM(container, events, event), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); +} + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +inline cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + size_type src_offset, + size_type dst_offset, + size_type size, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, startIterator, endIterator, buffer); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, buffer, startIterator, endIterator); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + size_type length = endIterator-startIterator; + size_type byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } +#if defined(_MSC_VER) + std::copy( + startIterator, + endIterator, + stdext::checked_array_iterator( + pointer, length)); +#else + std::copy(startIterator, endIterator, pointer); +#endif + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + size_type length = endIterator-startIterator; + size_type byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } + std::copy(pointer, pointer + length, startIterator); + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +/** + * Blocking SVM map operation - performs a blocking map underneath. + */ +template +inline cl_int mapSVM(cl::vector &container) +{ + return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE); +} + +/** +* Blocking SVM map operation - performs a blocking map underneath. +*/ +template +inline cl_int unmapSVM(cl::vector &container) +{ + return enqueueUnmapSVM(container); +} + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 +inline cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const array& buffer_offset, + const array& host_offset, + const array& region, + size_type buffer_row_pitch, + size_type buffer_slice_pitch, + size_type host_row_pitch, + size_type host_slice_pitch, + void *ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const array& buffer_offset, + const array& host_offset, + const array& region, + size_type buffer_row_pitch, + size_type buffer_slice_pitch, + size_type host_row_pitch, + size_type host_slice_pitch, + const void *ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const array& src_origin, + const array& dst_origin, + const array& region, + size_type src_row_pitch, + size_type src_slice_pitch, + size_type dst_row_pitch, + size_type dst_slice_pitch, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferRect( + src, + dst, + src_origin, + dst_origin, + region, + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + events, + event); +} +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + +inline cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const array& origin, + const array& region, + size_type row_pitch, + size_type slice_pitch, + void* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const array& origin, + const array& region, + size_type row_pitch, + size_type slice_pitch, + const void* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const array& src_origin, + const array& dst_origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImage( + src, + dst, + src_origin, + dst_origin, + region, + events, + event); +} + +inline cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const array& src_origin, + const array& region, + size_type dst_offset, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImageToBuffer( + src, + dst, + src_origin, + region, + dst_offset, + events, + event); +} + +inline cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + size_type src_offset, + const array& dst_origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferToImage( + src, + dst, + src_offset, + dst_origin, + region, + events, + event); +} + + +inline cl_int flush(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.flush(); +} + +inline cl_int finish(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + + return queue.finish(); +} + +class EnqueueArgs +{ +private: + CommandQueue queue_; + const NDRange offset_; + const NDRange global_; + const NDRange local_; + vector events_; + + template + friend class KernelFunctor; + +public: + EnqueueArgs(NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(Event e, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(const vector &events, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(const vector &events, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(const vector &events, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, const vector &events, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const vector &events, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const vector &events, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } +}; + + +//---------------------------------------------------------------------------------------------- + + +/** + * Type safe kernel functor. + * + */ +template +class KernelFunctor +{ +private: + Kernel kernel_; + + template + void setArgs(T0&& t0, T1s&&... t1s) + { + kernel_.setArg(index, t0); + setArgs(std::forward(t1s)...); + } + + template + void setArgs(T0&& t0) + { + kernel_.setArg(index, t0); + } + + template + void setArgs() + { + } + + +public: + KernelFunctor(Kernel kernel) : kernel_(kernel) + {} + + KernelFunctor( + const Program& program, + const string name, + cl_int * err = NULL) : + kernel_(program, name.c_str(), err) + {} + + //! \brief Return type of the functor + typedef Event result_type; + + /** + * Enqueue kernel. + * @param args Launch parameters of the kernel. + * @param t0... List of kernel arguments based on the template type of the functor. + */ + Event operator() ( + const EnqueueArgs& args, + Ts... ts) + { + Event event; + setArgs<0>(std::forward(ts)...); + + args.queue_.enqueueNDRangeKernel( + kernel_, + args.offset_, + args.global_, + args.local_, + &args.events_, + &event); + + return event; + } + + /** + * Enqueue kernel with support for error code. + * @param args Launch parameters of the kernel. + * @param t0... List of kernel arguments based on the template type of the functor. + * @param error Out parameter returning the error code from the execution. + */ + Event operator() ( + const EnqueueArgs& args, + Ts... ts, + cl_int &error) + { + Event event; + setArgs<0>(std::forward(ts)...); + + error = args.queue_.enqueueNDRangeKernel( + kernel_, + args.offset_, + args.global_, + args.local_, + &args.events_, + &event); + + return event; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_int setSVMPointers(const vector &pointerList) + { + return kernel_.setSVMPointers(pointerList); + } + + template + cl_int setSVMPointers(const T0 &t0, T1s... ts) + { + return kernel_.setSVMPointers(t0, ts...); + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + Kernel getKernel() + { + return kernel_; + } +}; + +namespace compatibility { + /** + * Backward compatibility class to ensure that cl.hpp code works with cl2.hpp. + * Please use KernelFunctor directly. + */ + template + struct make_kernel + { + typedef KernelFunctor FunctorType; + + FunctorType functor_; + + make_kernel( + const Program& program, + const string name, + cl_int * err = NULL) : + functor_(FunctorType(program, name, err)) + {} + + make_kernel( + const Kernel kernel) : + functor_(FunctorType(kernel)) + {} + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + Ts...); + + Event operator()( + const EnqueueArgs& enqueueArgs, + Ts... args) + { + return functor_( + enqueueArgs, args...); + } + }; +} // namespace compatibility + + +//---------------------------------------------------------------------------------------------------------------------- + +#undef CL_HPP_ERR_STR_ +#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) +#undef __GET_DEVICE_INFO_ERR +#undef __GET_PLATFORM_INFO_ERR +#undef __GET_DEVICE_IDS_ERR +#undef __GET_CONTEXT_INFO_ERR +#undef __GET_EVENT_INFO_ERR +#undef __GET_EVENT_PROFILE_INFO_ERR +#undef __GET_MEM_OBJECT_INFO_ERR +#undef __GET_IMAGE_INFO_ERR +#undef __GET_SAMPLER_INFO_ERR +#undef __GET_KERNEL_INFO_ERR +#undef __GET_KERNEL_ARG_INFO_ERR +#undef __GET_KERNEL_WORK_GROUP_INFO_ERR +#undef __GET_PROGRAM_INFO_ERR +#undef __GET_PROGRAM_BUILD_INFO_ERR +#undef __GET_COMMAND_QUEUE_INFO_ERR + +#undef __CREATE_CONTEXT_ERR +#undef __CREATE_CONTEXT_FROM_TYPE_ERR +#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR + +#undef __CREATE_BUFFER_ERR +#undef __CREATE_SUBBUFFER_ERR +#undef __CREATE_IMAGE2D_ERR +#undef __CREATE_IMAGE3D_ERR +#undef __CREATE_SAMPLER_ERR +#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR + +#undef __CREATE_USER_EVENT_ERR +#undef __SET_USER_EVENT_STATUS_ERR +#undef __SET_EVENT_CALLBACK_ERR +#undef __SET_PRINTF_CALLBACK_ERR + +#undef __WAIT_FOR_EVENTS_ERR + +#undef __CREATE_KERNEL_ERR +#undef __SET_KERNEL_ARGS_ERR +#undef __CREATE_PROGRAM_WITH_SOURCE_ERR +#undef __CREATE_PROGRAM_WITH_BINARY_ERR +#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR +#undef __BUILD_PROGRAM_ERR +#undef __CREATE_KERNELS_IN_PROGRAM_ERR + +#undef __CREATE_COMMAND_QUEUE_ERR +#undef __SET_COMMAND_QUEUE_PROPERTY_ERR +#undef __ENQUEUE_READ_BUFFER_ERR +#undef __ENQUEUE_WRITE_BUFFER_ERR +#undef __ENQUEUE_READ_BUFFER_RECT_ERR +#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR +#undef __ENQEUE_COPY_BUFFER_ERR +#undef __ENQEUE_COPY_BUFFER_RECT_ERR +#undef __ENQUEUE_READ_IMAGE_ERR +#undef __ENQUEUE_WRITE_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR +#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR +#undef __ENQUEUE_MAP_BUFFER_ERR +#undef __ENQUEUE_MAP_IMAGE_ERR +#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR +#undef __ENQUEUE_NDRANGE_KERNEL_ERR +#undef __ENQUEUE_TASK_ERR +#undef __ENQUEUE_NATIVE_KERNEL + +#undef __UNLOAD_COMPILER_ERR +#undef __CREATE_SUB_DEVICES_ERR + +#undef __CREATE_PIPE_ERR +#undef __GET_PIPE_INFO_ERR + +#endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS + +// Extensions +#undef CL_HPP_INIT_CL_EXT_FCN_PTR_ +#undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_ + +#if defined(CL_HPP_USE_CL_DEVICE_FISSION) +#undef CL_HPP_PARAM_NAME_DEVICE_FISSION_ +#endif // CL_HPP_USE_CL_DEVICE_FISSION + +#undef CL_HPP_NOEXCEPT_ +#undef CL_HPP_DEFINE_STATIC_MEMBER_ + +} // namespace cl + +#endif // CL_HPP_ diff --git a/opencl/khronos/headers/opencl2.0/CL/cl_d3d10.h b/opencl/khronos/headers/opencl2.0/CL/cl_d3d10.h new file mode 100644 index 0000000000..d5960a43f7 --- /dev/null +++ b/opencl/khronos/headers/opencl2.0/CL/cl_d3d10.h @@ -0,0 +1,131 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_CL_D3D10_H +#define __OPENCL_CL_D3D10_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * cl_khr_d3d10_sharing */ +#define cl_khr_d3d10_sharing 1 + +typedef cl_uint cl_d3d10_device_source_khr; +typedef cl_uint cl_d3d10_device_set_khr; + +/******************************************************************************/ + +/* Error Codes */ +#define CL_INVALID_D3D10_DEVICE_KHR -1002 +#define CL_INVALID_D3D10_RESOURCE_KHR -1003 +#define CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR -1004 +#define CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR -1005 + +/* cl_d3d10_device_source_nv */ +#define CL_D3D10_DEVICE_KHR 0x4010 +#define CL_D3D10_DXGI_ADAPTER_KHR 0x4011 + +/* cl_d3d10_device_set_nv */ +#define CL_PREFERRED_DEVICES_FOR_D3D10_KHR 0x4012 +#define CL_ALL_DEVICES_FOR_D3D10_KHR 0x4013 + +/* cl_context_info */ +#define CL_CONTEXT_D3D10_DEVICE_KHR 0x4014 +#define CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR 0x402C + +/* cl_mem_info */ +#define CL_MEM_D3D10_RESOURCE_KHR 0x4015 + +/* cl_image_info */ +#define CL_IMAGE_D3D10_SUBRESOURCE_KHR 0x4016 + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR 0x4017 +#define CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR 0x4018 + +/******************************************************************************/ + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D10KHR_fn)( + cl_platform_id platform, + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10BufferKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D10Buffer * resource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture2DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D10Texture2D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture3DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D10Texture3D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D10ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_D3D10_H */ + diff --git a/opencl/khronos/headers/opencl2.0/CL/cl_d3d11.h b/opencl/khronos/headers/opencl2.0/CL/cl_d3d11.h new file mode 100644 index 0000000000..39f9072398 --- /dev/null +++ b/opencl/khronos/headers/opencl2.0/CL/cl_d3d11.h @@ -0,0 +1,131 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_CL_D3D11_H +#define __OPENCL_CL_D3D11_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * cl_khr_d3d11_sharing */ +#define cl_khr_d3d11_sharing 1 + +typedef cl_uint cl_d3d11_device_source_khr; +typedef cl_uint cl_d3d11_device_set_khr; + +/******************************************************************************/ + +/* Error Codes */ +#define CL_INVALID_D3D11_DEVICE_KHR -1006 +#define CL_INVALID_D3D11_RESOURCE_KHR -1007 +#define CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR -1008 +#define CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR -1009 + +/* cl_d3d11_device_source */ +#define CL_D3D11_DEVICE_KHR 0x4019 +#define CL_D3D11_DXGI_ADAPTER_KHR 0x401A + +/* cl_d3d11_device_set */ +#define CL_PREFERRED_DEVICES_FOR_D3D11_KHR 0x401B +#define CL_ALL_DEVICES_FOR_D3D11_KHR 0x401C + +/* cl_context_info */ +#define CL_CONTEXT_D3D11_DEVICE_KHR 0x401D +#define CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR 0x402D + +/* cl_mem_info */ +#define CL_MEM_D3D11_RESOURCE_KHR 0x401E + +/* cl_image_info */ +#define CL_IMAGE_D3D11_SUBRESOURCE_KHR 0x401F + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR 0x4020 +#define CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR 0x4021 + +/******************************************************************************/ + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D11KHR_fn)( + cl_platform_id platform, + cl_d3d11_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d11_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11BufferKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D11Buffer * resource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture2DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D11Texture2D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture3DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D11Texture3D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D11ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_D3D11_H */ + diff --git a/opencl/khronos/headers/opencl2.0/CL/cl_dx9_media_sharing.h b/opencl/khronos/headers/opencl2.0/CL/cl_dx9_media_sharing.h new file mode 100644 index 0000000000..2729e8b9e8 --- /dev/null +++ b/opencl/khronos/headers/opencl2.0/CL/cl_dx9_media_sharing.h @@ -0,0 +1,132 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_CL_DX9_MEDIA_SHARING_H +#define __OPENCL_CL_DX9_MEDIA_SHARING_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/******************************************************************************/ +/* cl_khr_dx9_media_sharing */ +#define cl_khr_dx9_media_sharing 1 + +typedef cl_uint cl_dx9_media_adapter_type_khr; +typedef cl_uint cl_dx9_media_adapter_set_khr; + +#if defined(_WIN32) +#include +typedef struct _cl_dx9_surface_info_khr +{ + IDirect3DSurface9 *resource; + HANDLE shared_handle; +} cl_dx9_surface_info_khr; +#endif + + +/******************************************************************************/ + +/* Error Codes */ +#define CL_INVALID_DX9_MEDIA_ADAPTER_KHR -1010 +#define CL_INVALID_DX9_MEDIA_SURFACE_KHR -1011 +#define CL_DX9_MEDIA_SURFACE_ALREADY_ACQUIRED_KHR -1012 +#define CL_DX9_MEDIA_SURFACE_NOT_ACQUIRED_KHR -1013 + +/* cl_media_adapter_type_khr */ +#define CL_ADAPTER_D3D9_KHR 0x2020 +#define CL_ADAPTER_D3D9EX_KHR 0x2021 +#define CL_ADAPTER_DXVA_KHR 0x2022 + +/* cl_media_adapter_set_khr */ +#define CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2023 +#define CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2024 + +/* cl_context_info */ +#define CL_CONTEXT_ADAPTER_D3D9_KHR 0x2025 +#define CL_CONTEXT_ADAPTER_D3D9EX_KHR 0x2026 +#define CL_CONTEXT_ADAPTER_DXVA_KHR 0x2027 + +/* cl_mem_info */ +#define CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR 0x2028 +#define CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR 0x2029 + +/* cl_image_info */ +#define CL_IMAGE_DX9_MEDIA_PLANE_KHR 0x202A + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR 0x202B +#define CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR 0x202C + +/******************************************************************************/ + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromDX9MediaAdapterKHR_fn)( + cl_platform_id platform, + cl_uint num_media_adapters, + cl_dx9_media_adapter_type_khr * media_adapter_type, + void * media_adapters, + cl_dx9_media_adapter_set_khr media_adapter_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)( + cl_context context, + cl_mem_flags flags, + cl_dx9_media_adapter_type_khr adapter_type, + void * surface_info, + cl_uint plane, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9MediaSurfacesKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_DX9_MEDIA_SHARING_H */ + diff --git a/opencl/khronos/headers/opencl2.0/CL/cl_egl.h b/opencl/khronos/headers/opencl2.0/CL/cl_egl.h new file mode 100644 index 0000000000..a765bd5266 --- /dev/null +++ b/opencl/khronos/headers/opencl2.0/CL/cl_egl.h @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +#ifndef __OPENCL_CL_EGL_H +#define __OPENCL_CL_EGL_H + +#ifdef __APPLE__ + +#else +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Command type for events created with clEnqueueAcquireEGLObjectsKHR */ +#define CL_COMMAND_EGL_FENCE_SYNC_OBJECT_KHR 0x202F +#define CL_COMMAND_ACQUIRE_EGL_OBJECTS_KHR 0x202D +#define CL_COMMAND_RELEASE_EGL_OBJECTS_KHR 0x202E + +/* Error type for clCreateFromEGLImageKHR */ +#define CL_INVALID_EGL_OBJECT_KHR -1093 +#define CL_EGL_RESOURCE_NOT_ACQUIRED_KHR -1092 + +/* CLeglImageKHR is an opaque handle to an EGLImage */ +typedef void* CLeglImageKHR; + +/* CLeglDisplayKHR is an opaque handle to an EGLDisplay */ +typedef void* CLeglDisplayKHR; + +/* CLeglSyncKHR is an opaque handle to an EGLSync object */ +typedef void* CLeglSyncKHR; + +/* properties passed to clCreateFromEGLImageKHR */ +typedef intptr_t cl_egl_image_properties_khr; + + +#define cl_khr_egl_image 1 + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromEGLImageKHR(cl_context /* context */, + CLeglDisplayKHR /* egldisplay */, + CLeglImageKHR /* eglimage */, + cl_mem_flags /* flags */, + const cl_egl_image_properties_khr * /* properties */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromEGLImageKHR_fn)( + cl_context context, + CLeglDisplayKHR egldisplay, + CLeglImageKHR eglimage, + cl_mem_flags flags, + const cl_egl_image_properties_khr * properties, + cl_int * errcode_ret); + + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireEGLObjectsKHR(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireEGLObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event); + + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseEGLObjectsKHR(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseEGLObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event); + + +#define cl_khr_egl_event 1 + +extern CL_API_ENTRY cl_event CL_API_CALL +clCreateEventFromEGLSyncKHR(cl_context /* context */, + CLeglSyncKHR /* sync */, + CLeglDisplayKHR /* display */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_event (CL_API_CALL *clCreateEventFromEGLSyncKHR_fn)( + cl_context context, + CLeglSyncKHR sync, + CLeglDisplayKHR display, + cl_int * errcode_ret); + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_EGL_H */ diff --git a/opencl/khronos/headers/opencl2.0/CL/cl_ext.h b/opencl/khronos/headers/opencl2.0/CL/cl_ext.h new file mode 100644 index 0000000000..1d2bcfabad --- /dev/null +++ b/opencl/khronos/headers/opencl2.0/CL/cl_ext.h @@ -0,0 +1,729 @@ +/* Modifications Copyright (C) 2010-2021 Advanced Micro Devices, Inc. */ +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +/* $Revision: 11928 $ on $Date: 2010-07-13 09:04:56 -0700 (Tue, 13 Jul 2010) $ */ + +/* cl_ext.h contains OpenCL extensions which don't have external */ +/* (OpenGL, D3D) dependencies. */ + +#ifndef __CL_EXT_H +#define __CL_EXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __APPLE__ + #include + #include +#else + #include +#endif + +/* cl_khr_fp16 extension - no extension #define since it has no functions */ +#define CL_DEVICE_HALF_FP_CONFIG 0x1033 + +/* Memory object destruction + * + * Apple extension for use to manage externally allocated buffers used with cl_mem objects with CL_MEM_USE_HOST_PTR + * + * Registers a user callback function that will be called when the memory object is deleted and its resources + * freed. Each call to clSetMemObjectCallbackFn registers the specified user callback function on a callback + * stack associated with memobj. The registered user callback functions are called in the reverse order in + * which they were registered. The user callback functions are called and then the memory object is deleted + * and its resources freed. This provides a mechanism for the application (and libraries) using memobj to be + * notified when the memory referenced by host_ptr, specified when the memory object is created and used as + * the storage bits for the memory object, can be reused or freed. + * + * The application may not call CL api's with the cl_mem object passed to the pfn_notify. + * + * Please check for the "cl_APPLE_SetMemObjectDestructor" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) + * before using. + */ +#define cl_APPLE_SetMemObjectDestructor 1 +cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE( cl_mem /* memobj */, + void (* /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), + void * /*user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; + + +/* Context Logging Functions + * + * The next three convenience functions are intended to be used as the pfn_notify parameter to clCreateContext(). + * Please check for the "cl_APPLE_ContextLoggingFunctions" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) + * before using. + * + * clLogMessagesToSystemLog fowards on all log messages to the Apple System Logger + */ +#define cl_APPLE_ContextLoggingFunctions 1 +extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE( const char * /* errstr */, + const void * /* private_info */, + size_t /* cb */, + void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; + +/* clLogMessagesToStdout sends all log messages to the file descriptor stdout */ +extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE( const char * /* errstr */, + const void * /* private_info */, + size_t /* cb */, + void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; + +/* clLogMessagesToStderr sends all log messages to the file descriptor stderr */ +extern void CL_API_ENTRY clLogMessagesToStderrAPPLE( const char * /* errstr */, + const void * /* private_info */, + size_t /* cb */, + void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; + + +/************************ +* cl_khr_icd extension * +************************/ +#define cl_khr_icd 1 + +/* cl_platform_info */ +#define CL_PLATFORM_ICD_SUFFIX_KHR 0x0920 + +/* Additional Error Codes */ +#define CL_PLATFORM_NOT_FOUND_KHR -1001 + +extern CL_API_ENTRY cl_int CL_API_CALL +clIcdGetPlatformIDsKHR(cl_uint /* num_entries */, + cl_platform_id * /* platforms */, + cl_uint * /* num_platforms */); + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clIcdGetPlatformIDsKHR_fn)( + cl_uint /* num_entries */, + cl_platform_id * /* platforms */, + cl_uint * /* num_platforms */); + + +/* Extension: cl_khr_image2D_buffer + * + * This extension allows a 2D image to be created from a cl_mem buffer without a copy. + * The type associated with a 2D image created from a buffer in an OpenCL program is image2d_t. + * Both the sampler and sampler-less read_image built-in functions are supported for 2D images + * and 2D images created from a buffer. Similarly, the write_image built-ins are also supported + * for 2D images created from a buffer. + * + * When the 2D image from buffer is created, the client must specify the width, + * height, image format (i.e. channel order and channel data type) and optionally the row pitch + * + * The pitch specified must be a multiple of CL_DEVICE_IMAGE_PITCH_ALIGNMENT pixels. + * The base address of the buffer must be aligned to CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT pixels. + */ + +/************************************* + * cl_khr_initalize_memory extension * + *************************************/ + +#define CL_CONTEXT_MEMORY_INITIALIZE_KHR 0x2030 + + +/************************************** + * cl_khr_terminate_context extension * + **************************************/ + +#define CL_DEVICE_TERMINATE_CAPABILITY_KHR 0x2031 +#define CL_CONTEXT_TERMINATE_KHR 0x2032 + +#define cl_khr_terminate_context 1 +extern CL_API_ENTRY cl_int CL_API_CALL clTerminateContextKHR(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clTerminateContextKHR_fn)(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; + + +/* + * Extension: cl_khr_spir + * + * This extension adds support to create an OpenCL program object from a + * Standard Portable Intermediate Representation (SPIR) instance + */ + +#define CL_DEVICE_SPIR_VERSIONS 0x40E0 +#define CL_PROGRAM_BINARY_TYPE_INTERMEDIATE 0x40E1 + +#ifdef CL_VERSION_2_0 +/********************************* +* cl_khr_il_program extension +*********************************/ +#define cl_khr_il_program 1 + +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithILKHR(cl_context /* context */, + const void * /* strings */, + size_t /* lengths */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_2_0; + +typedef CL_API_ENTRY cl_program + ( CL_API_CALL * clCreateProgramWithILKHR_fn)(cl_context /* context */, + const void * /* strings */, + size_t /* lengths */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_2_0; + +#endif /* CL_VERSION_2_0 */ + +/****************************************** +* cl_nv_device_attribute_query extension * +******************************************/ +/* cl_nv_device_attribute_query extension - no extension #define since it has no functions */ +#define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 +#define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 +#define CL_DEVICE_REGISTERS_PER_BLOCK_NV 0x4002 +#define CL_DEVICE_WARP_SIZE_NV 0x4003 +#define CL_DEVICE_GPU_OVERLAP_NV 0x4004 +#define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 +#define CL_DEVICE_INTEGRATED_MEMORY_NV 0x4006 + +/********************************* +* cl_amd_device_memory_flags * +*********************************/ +#define cl_amd_device_memory_flags 1 +#define CL_MEM_USE_PERSISTENT_MEM_AMD (1 << 6) // Alloc from GPU's CPU visible heap + +/* cl_device_info */ +#define CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT 0x4032 + +/********************************* +* cl_amd_device_attribute_query * +*********************************/ +#define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 0x4036 +#define CL_DEVICE_TOPOLOGY_AMD 0x4037 +#define CL_DEVICE_BOARD_NAME_AMD 0x4038 +#define CL_DEVICE_GLOBAL_FREE_MEMORY_AMD 0x4039 +#define CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD 0x4040 +#define CL_DEVICE_SIMD_WIDTH_AMD 0x4041 +#define CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD 0x4042 +#define CL_DEVICE_WAVEFRONT_WIDTH_AMD 0x4043 +#define CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD 0x4044 +#define CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD 0x4045 +#define CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD 0x4046 +#define CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD 0x4047 +#define CL_DEVICE_LOCAL_MEM_BANKS_AMD 0x4048 +#define CL_DEVICE_THREAD_TRACE_SUPPORTED_AMD 0x4049 +#define CL_DEVICE_GFXIP_MAJOR_AMD 0x404A +#define CL_DEVICE_GFXIP_MINOR_AMD 0x404B +#define CL_DEVICE_AVAILABLE_ASYNC_QUEUES_AMD 0x404C +#define CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD 0x4030 +#define CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD 0x4031 +#define CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD 0x4033 +#define CL_DEVICE_PCIE_ID_AMD 0x4034 + +typedef union +{ + struct { cl_uint type; cl_uint data[5]; } raw; + struct { cl_uint type; cl_uchar unused[17]; cl_uchar bus; cl_uchar device; cl_uchar function; } pcie; +} cl_device_topology_amd; + +#define CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD 1 + +/************************** +* cl_amd_offline_devices * +**************************/ +#define CL_CONTEXT_OFFLINE_DEVICES_AMD 0x403F + +/******************************** +* cl_amd_bus_addressable_memory * +********************************/ + +/* cl_mem flag - bitfield */ +#define CL_MEM_BUS_ADDRESSABLE_AMD (1<<30) +#define CL_MEM_EXTERNAL_PHYSICAL_AMD (1<<31) + +#define CL_COMMAND_WAIT_SIGNAL_AMD 0x4080 +#define CL_COMMAND_WRITE_SIGNAL_AMD 0x4081 +#define CL_COMMAND_MAKE_BUFFERS_RESIDENT_AMD 0x4082 + +typedef struct _cl_bus_address_amd +{ + cl_ulong surface_bus_address; + cl_ulong marker_bus_address; +} cl_bus_address_amd; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueWaitSignalAMD_fn)( cl_command_queue /*command_queue*/, + cl_mem /*mem_object*/, + cl_uint /*value*/, + cl_uint /*num_events*/, + const cl_event * /*event_wait_list*/, + cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueWriteSignalAMD_fn)( cl_command_queue /*command_queue*/, + cl_mem /*mem_object*/, + cl_uint /*value*/, + cl_ulong /*offset*/, + cl_uint /*num_events*/, + const cl_event * /*event_list*/, + cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueMakeBuffersResidentAMD_fn)( cl_command_queue /*command_queue*/, + cl_uint /*num_mem_objs*/, + cl_mem * /*mem_objects*/, + cl_bool /*blocking_make_resident*/, + cl_bus_address_amd * /*bus_addresses*/, + cl_uint /*num_events*/, + const cl_event * /*event_list*/, + cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +/************************* +* cl_amd_copy_buffer_p2p * +**************************/ +#define CL_DEVICE_NUM_P2P_DEVICES_AMD 0x4088 +#define CL_DEVICE_P2P_DEVICES_AMD 0x4089 + +#define cl_amd_copy_buffer_p2p 1 + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueCopyBufferP2PAMD_fn)(cl_command_queue /*command_queue*/, + cl_mem /*src_buffer*/, + cl_mem /*dst_buffer*/, + size_t /*src_offset*/, + size_t /*dst_offset*/, + size_t /*cb*/, + cl_uint /*num_events_in_wait_list*/, + const cl_event* /*event_wait_list*/, + cl_event* /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +/*********************************** +* cl_amd_assembly_program extension * +***********************************/ +#define cl_amd_assembly_program 1 + +typedef CL_API_ENTRY cl_program (CL_API_CALL * clCreateProgramWithAssemblyAMD_fn) ( + cl_context /* context */, + cl_uint /* count */, + const char** /* strings */, + const size_t* /* lengths */, + cl_int* /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2; + +#ifdef CL_VERSION_2_0 +/******************************** +* cl_amd_planar_yuv * +********************************/ + +/* cl_mem flag - bitfield */ +#define CL_YUV_IMAGE_Y_PLANE_AMD 0x0 +#define CL_YUV_IMAGE_UV_PLANE_AMD 0x1 + +typedef CL_API_ENTRY cl_mem +(CL_API_CALL * clGetPlaneFromImageAMD_fn)(cl_context /*context*/, + cl_mem /*mem*/, + cl_uint /*plane*/, + cl_int * /*errcode_ret*/) CL_EXT_SUFFIX__VERSION_2_0; +#endif + +// +/************************** +* cl_amd_command_queue_info * +**************************/ +#define CL_QUEUE_THREAD_HANDLE_AMD 0x403E + +/* cl_kernel_exec_info for DVR DOPP texture support */ +#define CL_KERNEL_EXEC_INFO_NEW_VCOP_AMD 0x4120 +#define CL_KERNEL_EXEC_INFO_PFPA_VCOP_AMD 0x4121 +// + +/********************************* +* cl_arm_printf extension +*********************************/ +#define CL_PRINTF_CALLBACK_ARM 0x40B0 +#define CL_PRINTF_BUFFERSIZE_ARM 0x40B1 + +#ifdef CL_VERSION_1_1 + /*********************************** + * cl_ext_device_fission extension * + ***********************************/ + #define cl_ext_device_fission 1 + + extern CL_API_ENTRY cl_int CL_API_CALL + clReleaseDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + typedef CL_API_ENTRY cl_int + (CL_API_CALL *clReleaseDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + extern CL_API_ENTRY cl_int CL_API_CALL + clRetainDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + typedef CL_API_ENTRY cl_int + (CL_API_CALL *clRetainDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + typedef cl_ulong cl_device_partition_property_ext; + extern CL_API_ENTRY cl_int CL_API_CALL + clCreateSubDevicesEXT( cl_device_id /*in_device*/, + const cl_device_partition_property_ext * /* properties */, + cl_uint /*num_entries*/, + cl_device_id * /*out_devices*/, + cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + typedef CL_API_ENTRY cl_int + ( CL_API_CALL * clCreateSubDevicesEXT_fn)( cl_device_id /*in_device*/, + const cl_device_partition_property_ext * /* properties */, + cl_uint /*num_entries*/, + cl_device_id * /*out_devices*/, + cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + /* cl_device_partition_property_ext */ + #define CL_DEVICE_PARTITION_EQUALLY_EXT 0x4050 + #define CL_DEVICE_PARTITION_BY_COUNTS_EXT 0x4051 + #define CL_DEVICE_PARTITION_BY_NAMES_EXT 0x4052 + #define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT 0x4053 + + /* clDeviceGetInfo selectors */ + #define CL_DEVICE_PARENT_DEVICE_EXT 0x4054 + #define CL_DEVICE_PARTITION_TYPES_EXT 0x4055 + #define CL_DEVICE_AFFINITY_DOMAINS_EXT 0x4056 + #define CL_DEVICE_REFERENCE_COUNT_EXT 0x4057 + #define CL_DEVICE_PARTITION_STYLE_EXT 0x4058 + + /* clGetImageInfo enum */ + #define CL_IMAGE_BYTE_PITCH_AMD 0x4059 + + /* error codes */ + #define CL_DEVICE_PARTITION_FAILED_EXT -1057 + #define CL_INVALID_PARTITION_COUNT_EXT -1058 + #define CL_INVALID_PARTITION_NAME_EXT -1059 + + /* CL_AFFINITY_DOMAINs */ + #define CL_AFFINITY_DOMAIN_L1_CACHE_EXT 0x1 + #define CL_AFFINITY_DOMAIN_L2_CACHE_EXT 0x2 + #define CL_AFFINITY_DOMAIN_L3_CACHE_EXT 0x3 + #define CL_AFFINITY_DOMAIN_L4_CACHE_EXT 0x4 + #define CL_AFFINITY_DOMAIN_NUMA_EXT 0x10 + #define CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT 0x100 + + /* cl_device_partition_property_ext list terminators */ + #define CL_PROPERTIES_LIST_END_EXT ((cl_device_partition_property_ext) 0) + #define CL_PARTITION_BY_COUNTS_LIST_END_EXT ((cl_device_partition_property_ext) 0) + #define CL_PARTITION_BY_NAMES_LIST_END_EXT ((cl_device_partition_property_ext) 0 - 1) + +/********************************* +* cl_qcom_ext_host_ptr extension +*********************************/ + +#define CL_MEM_EXT_HOST_PTR_QCOM (1 << 29) + +#define CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM 0x40A0 +#define CL_DEVICE_PAGE_SIZE_QCOM 0x40A1 +#define CL_IMAGE_ROW_ALIGNMENT_QCOM 0x40A2 +#define CL_IMAGE_SLICE_ALIGNMENT_QCOM 0x40A3 +#define CL_MEM_HOST_UNCACHED_QCOM 0x40A4 +#define CL_MEM_HOST_WRITEBACK_QCOM 0x40A5 +#define CL_MEM_HOST_WRITETHROUGH_QCOM 0x40A6 +#define CL_MEM_HOST_WRITE_COMBINING_QCOM 0x40A7 + +typedef cl_uint cl_image_pitch_info_qcom; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceImageInfoQCOM(cl_device_id device, + size_t image_width, + size_t image_height, + const cl_image_format *image_format, + cl_image_pitch_info_qcom param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret); + +typedef struct _cl_mem_ext_host_ptr +{ + /* Type of external memory allocation. */ + /* Legal values will be defined in layered extensions. */ + cl_uint allocation_type; + + /* Host cache policy for this external memory allocation. */ + cl_uint host_cache_policy; + +} cl_mem_ext_host_ptr; + +/********************************* +* cl_qcom_ion_host_ptr extension +*********************************/ + +#define CL_MEM_ION_HOST_PTR_QCOM 0x40A8 + +typedef struct _cl_mem_ion_host_ptr +{ + /* Type of external memory allocation. */ + /* Must be CL_MEM_ION_HOST_PTR_QCOM for ION allocations. */ + cl_mem_ext_host_ptr ext_host_ptr; + + /* ION file descriptor */ + int ion_filedesc; + + /* Host pointer to the ION allocated memory */ + void* ion_hostptr; + +} cl_mem_ion_host_ptr; + +#endif /* CL_VERSION_1_1 */ + +#if defined(CL_VERSION_1_2) + +/****************************************** + * cl_img_yuv_image extension * + ******************************************/ + +/* Image formats used in clCreateImage */ +#define CL_NV21_IMG 0x40D0 +#define CL_YV12_IMG 0x40D1 + +/****************************************** + * cl_img_cached_allocations extension * + ******************************************/ + +/* Flag values used by clCreteBuffer */ +#define CL_MEM_USE_UNCACHED_CPU_MEMORY_IMG (1 << 26) +#define CL_MEM_USE_CACHED_CPU_MEMORY_IMG (1 << 27) + +/****************************************** + * cl_img_use_gralloc_ptr extension * + ******************************************/ + +/* Flag values used by clCreteBuffer */ +#define CL_MEM_USE_GRALLOC_PTR_IMG (1 << 28) + +/* To be used by clGetEventInfo: */ +#define CL_COMMAND_ACQUIRE_GRALLOC_OBJECTS_IMG 0x40D2 +#define CL_COMMAND_RELEASE_GRALLOC_OBJECTS_IMG 0x40D3 + +/* Error code from clEnqueueReleaseGrallocObjectsIMG */ +#define CL_GRALLOC_RESOURCE_NOT_ACQUIRED_IMG 0x40D4 + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireGrallocObjectsIMG(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseGrallocObjectsIMG(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +#endif /* CL_VERSION_1_2 */ + +#ifdef CL_VERSION_2_0 +/********************************* +* cl_khr_subgroups extension +*********************************/ +#define cl_khr_subgroups 1 + +typedef cl_uint cl_kernel_sub_group_info; + +/* cl_kernel_sub_group_info */ +#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR 0x2033 +#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR 0x2034 + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetKernelSubGroupInfoKHR(cl_kernel /* in_kernel */, + cl_device_id /*in_device*/, + cl_kernel_sub_group_info /* param_name */, + size_t /*input_value_size*/, + const void * /*input_value*/, + size_t /*param_value_size*/, + void* /*param_value*/, + size_t* /*param_value_size_ret*/ ) CL_EXT_SUFFIX__VERSION_2_0; + +typedef CL_API_ENTRY cl_int + ( CL_API_CALL * clGetKernelSubGroupInfoKHR_fn)(cl_kernel /* in_kernel */, + cl_device_id /*in_device*/, + cl_kernel_sub_group_info /* param_name */, + size_t /*input_value_size*/, + const void * /*input_value*/, + size_t /*param_value_size*/, + void* /*param_value*/, + size_t* /*param_value_size_ret*/ ) CL_EXT_SUFFIX__VERSION_2_0; +#endif /* CL_VERSION_2_0 */ + + +/****************************************** + * cl_arm_shared_virtual_memory extension * + ******************************************/ + +#ifdef CL_VERSION_1_2 + +/* Used by clGetDeviceInfo */ +#define CL_DEVICE_SVM_CAPABILITIES_ARM 0x40B6 + +/* Used by clGetMemObjectInfo */ +#define CL_MEM_USES_SVM_POINTER_ARM 0x40B7 + +/* Used by clSetKernelExecInfoARM: */ +#define CL_KERNEL_EXEC_INFO_SVM_PTRS_ARM 0x40B8 +#define CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM_ARM 0x40B9 + +/* To be used by clGetEventInfo: */ +#define CL_COMMAND_SVM_FREE_ARM 0x40BA +#define CL_COMMAND_SVM_MEMCPY_ARM 0x40BB +#define CL_COMMAND_SVM_MEMFILL_ARM 0x40BC +#define CL_COMMAND_SVM_MAP_ARM 0x40BD +#define CL_COMMAND_SVM_UNMAP_ARM 0x40BE + +/* Flag values returned by clGetDeviceInfo with CL_DEVICE_SVM_CAPABILITIES_ARM as the param_name. */ +#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER_ARM (1 << 0) +#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER_ARM (1 << 1) +#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM_ARM (1 << 2) +#define CL_DEVICE_SVM_ATOMICS_ARM (1 << 3) + +/* Flag values used by clSVMAllocARM: */ +#define CL_MEM_SVM_FINE_GRAIN_BUFFER_ARM (1 << 10) +#define CL_MEM_SVM_ATOMICS_ARM (1 << 11) + +typedef cl_bitfield cl_svm_mem_flags_arm; +typedef cl_uint cl_kernel_exec_info_arm; +typedef cl_bitfield cl_device_svm_capabilities_arm; + +extern CL_API_ENTRY void * CL_API_CALL +clSVMAllocARM(cl_context /* context */, + cl_svm_mem_flags_arm /* flags */, + size_t /* size */, + cl_uint /* alignment */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY void CL_API_CALL +clSVMFreeARM(cl_context /* context */, + void * /* svm_pointer */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMFreeARM(cl_command_queue /* command_queue */, + cl_uint /* num_svm_pointers */, + void *[] /* svm_pointers[] */, + void (CL_CALLBACK * /*pfn_free_func*/)(cl_command_queue /* queue */, + cl_uint /* num_svm_pointers */, + void *[] /* svm_pointers[] */, + void * /* user_data */), + void * /* user_data */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemcpyARM(cl_command_queue /* command_queue */, + cl_bool /* blocking_copy */, + void * /* dst_ptr */, + const void * /* src_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemFillARM(cl_command_queue /* command_queue */, + void * /* svm_ptr */, + const void * /* pattern */, + size_t /* pattern_size */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMapARM(cl_command_queue /* command_queue */, + cl_bool /* blocking_map */, + cl_map_flags /* flags */, + void * /* svm_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMUnmapARM(cl_command_queue /* command_queue */, + void * /* svm_ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArgSVMPointerARM(cl_kernel /* kernel */, + cl_uint /* arg_index */, + const void * /* arg_value */) CL_EXT_SUFFIX__VERSION_1_2; +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelExecInfoARM(cl_kernel /* kernel */, + cl_kernel_exec_info_arm /* param_name */, + size_t /* param_value_size */, + const void * /* param_value */) CL_EXT_SUFFIX__VERSION_1_2; + +#endif /* CL_VERSION_1_2 */ + +/********************************** + * cl_arm_import_memory extension * + **********************************/ + +#ifdef CL_VERSION_1_0 + +typedef intptr_t cl_import_properties_arm; + +/* Default and valid proporties name for cl_arm_import_memory */ +#define CL_IMPORT_TYPE_ARM 0x40B2 + +/* Host process memory type default value for CL_IMPORT_TYPE_ARM property */ +#define CL_IMPORT_TYPE_HOST_ARM 0x40B3 + +/* DMA BUF memory type value for CL_IMPORT_TYPE_ARM property */ +#define CL_IMPORT_TYPE_DMA_BUF_ARM 0x40B4 + +/* Secure DMA BUF memory type value for CL_IMPORT_TYPE_ARM property */ +#define CL_IMPORT_TYPE_SECURE_ARM 0x40B5 + +/* This extension adds a new function that allows for direct memory import into + * OpenCL via the clImportMemoryARM function. + * + * Memory imported through this interface will be mapped into the device's page + * tables directly, providing zero copy access. It will never fall back to copy + * operations and aliased buffers. + * + * Types of memory supported for import are specified as additional extension + * strings. + * + * This extension produces cl_mem allocations which are compatible with all other + * users of cl_mem in the standard API. + * + * This extension maps pages with the same properties as the normal buffer creation + * function clCreateBuffer. + */ +extern CL_API_ENTRY cl_mem CL_API_CALL +clImportMemoryARM( cl_context context, + cl_mem_flags flags, + const cl_import_properties_arm *properties, + void *memory, + size_t size, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_0; + + +#endif /* CL_VERSION_1_0 */ + +#ifdef __cplusplus +} +#endif + + +#endif /* __CL_EXT_H */ diff --git a/opencl/khronos/headers/opencl2.0/CL/cl_gl.h b/opencl/khronos/headers/opencl2.0/CL/cl_gl.h new file mode 100644 index 0000000000..945daa83d7 --- /dev/null +++ b/opencl/khronos/headers/opencl2.0/CL/cl_gl.h @@ -0,0 +1,167 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +#ifndef __OPENCL_CL_GL_H +#define __OPENCL_CL_GL_H + +#ifdef __APPLE__ +#include +#else +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef cl_uint cl_gl_object_type; +typedef cl_uint cl_gl_texture_info; +typedef cl_uint cl_gl_platform_info; +typedef struct __GLsync *cl_GLsync; + +/* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken */ +#define CL_GL_OBJECT_BUFFER 0x2000 +#define CL_GL_OBJECT_TEXTURE2D 0x2001 +#define CL_GL_OBJECT_TEXTURE3D 0x2002 +#define CL_GL_OBJECT_RENDERBUFFER 0x2003 +#define CL_GL_OBJECT_TEXTURE2D_ARRAY 0x200E +#define CL_GL_OBJECT_TEXTURE1D 0x200F +#define CL_GL_OBJECT_TEXTURE1D_ARRAY 0x2010 +#define CL_GL_OBJECT_TEXTURE_BUFFER 0x2011 + +/* cl_gl_texture_info */ +#define CL_GL_TEXTURE_TARGET 0x2004 +#define CL_GL_MIPMAP_LEVEL 0x2005 +#define CL_GL_NUM_SAMPLES 0x2012 + + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLBuffer(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLuint /* bufobj */, + int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLTexture(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLenum /* target */, + cl_GLint /* miplevel */, + cl_GLuint /* texture */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLRenderbuffer(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLuint /* renderbuffer */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetGLObjectInfo(cl_mem /* memobj */, + cl_gl_object_type * /* gl_object_type */, + cl_GLuint * /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetGLTextureInfo(cl_mem /* memobj */, + cl_gl_texture_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireGLObjects(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseGLObjects(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + + +/* Deprecated OpenCL 1.1 APIs */ +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateFromGLTexture2D(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLenum /* target */, + cl_GLint /* miplevel */, + cl_GLuint /* texture */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateFromGLTexture3D(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLenum /* target */, + cl_GLint /* miplevel */, + cl_GLuint /* texture */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +/* cl_khr_gl_sharing extension */ + +#define cl_khr_gl_sharing 1 + +typedef cl_uint cl_gl_context_info; + +/* Additional Error Codes */ +#define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000 + +/* cl_gl_context_info */ +#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 +#define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007 + +/* Additional cl_context_properties */ +#define CL_GL_CONTEXT_KHR 0x2008 +#define CL_EGL_DISPLAY_KHR 0x2009 +#define CL_GLX_DISPLAY_KHR 0x200A +#define CL_WGL_HDC_KHR 0x200B +#define CL_CGL_SHAREGROUP_KHR 0x200C + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetGLContextInfoKHR(const cl_context_properties * /* properties */, + cl_gl_context_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( + const cl_context_properties * properties, + cl_gl_context_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret); + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_GL_H */ diff --git a/opencl/khronos/headers/opencl2.0/CL/cl_gl_ext.h b/opencl/khronos/headers/opencl2.0/CL/cl_gl_ext.h new file mode 100644 index 0000000000..e3c14c6408 --- /dev/null +++ b/opencl/khronos/headers/opencl2.0/CL/cl_gl_ext.h @@ -0,0 +1,74 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +/* cl_gl_ext.h contains vendor (non-KHR) OpenCL extensions which have */ +/* OpenGL dependencies. */ + +#ifndef __OPENCL_CL_GL_EXT_H +#define __OPENCL_CL_GL_EXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __APPLE__ + #include +#else + #include +#endif + +/* + * For each extension, follow this template + * cl_VEN_extname extension */ +/* #define cl_VEN_extname 1 + * ... define new types, if any + * ... define new tokens, if any + * ... define new APIs, if any + * + * If you need GLtypes here, mirror them with a cl_GLtype, rather than including a GL header + * This allows us to avoid having to decide whether to include GL headers or GLES here. + */ + +/* + * cl_khr_gl_event extension + * See section 9.9 in the OpenCL 1.1 spec for more information + */ +#define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D + +extern CL_API_ENTRY cl_event CL_API_CALL +clCreateEventFromGLsyncKHR(cl_context /* context */, + cl_GLsync /* cl_GLsync */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_GL_EXT_H */ diff --git a/opencl/khronos/headers/opencl2.0/CL/cl_platform.h b/opencl/khronos/headers/opencl2.0/CL/cl_platform.h new file mode 100644 index 0000000000..e204e61b86 --- /dev/null +++ b/opencl/khronos/headers/opencl2.0/CL/cl_platform.h @@ -0,0 +1,1416 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11803 $ on $Date: 2010-06-25 10:02:12 -0700 (Fri, 25 Jun 2010) $ */ + +#ifndef __CL_PLATFORM_H +#define __CL_PLATFORM_H + +#ifdef __APPLE__ + /* Contains #defines for AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER below */ + #include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_WIN32) + #define CL_API_ENTRY + #define CL_API_CALL __stdcall + #define CL_CALLBACK __stdcall +#else + #define CL_API_ENTRY + #define CL_API_CALL + #define CL_CALLBACK +#endif + +/* + * Deprecation flags refer to the last version of the header in which the + * feature was not deprecated. + * + * E.g. VERSION_1_1_DEPRECATED means the feature is present in 1.1 without + * deprecation but is deprecated in versions later than 1.1. + */ + +#ifdef __APPLE__ + #define CL_EXTENSION_WEAK_LINK __attribute__((weak_import)) + #define CL_API_SUFFIX__VERSION_1_0 AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_0 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER + #define CL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define GCL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_1 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_7 + + #ifdef AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_8 + #else + #warning This path should never happen outside of internal operating system development. AvailabilityMacros do not function correctly here! + #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #endif +#else + #define CL_EXTENSION_WEAK_LINK + #define CL_API_SUFFIX__VERSION_1_0 + #define CL_EXT_SUFFIX__VERSION_1_0 + #define CL_API_SUFFIX__VERSION_1_1 + #define CL_EXT_SUFFIX__VERSION_1_1 + #define CL_API_SUFFIX__VERSION_1_2 + #define CL_EXT_SUFFIX__VERSION_1_2 + #define CL_API_SUFFIX__VERSION_2_0 + #define CL_EXT_SUFFIX__VERSION_2_0 + + #ifdef __GNUC__ + #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED __attribute__((deprecated)) + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED + #endif + + #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED __attribute__((deprecated)) + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + #endif + + #ifdef CL_USE_DEPRECATED_OPENCL_1_2_APIS + #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED __attribute__((deprecated)) + #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED + #endif + #elif defined(_WIN32) + #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED __declspec(deprecated) + #endif + + #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED __declspec(deprecated) + #endif + + #ifdef CL_USE_DEPRECATED_OPENCL_1_2_APIS + #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED __declspec(deprecated) + #endif + #else + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED + + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + + #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED + #endif +#endif + +#if (defined (_WIN32) && defined(_MSC_VER)) + +/* scalar types */ +typedef signed __int8 cl_char; +typedef unsigned __int8 cl_uchar; +typedef signed __int16 cl_short; +typedef unsigned __int16 cl_ushort; +typedef signed __int32 cl_int; +typedef unsigned __int32 cl_uint; +typedef signed __int64 cl_long; +typedef unsigned __int64 cl_ulong; + +typedef unsigned __int16 cl_half; +typedef float cl_float; +typedef double cl_double; + +/* Macro names and corresponding values defined by OpenCL */ +#define CL_CHAR_BIT 8 +#define CL_SCHAR_MAX 127 +#define CL_SCHAR_MIN (-127-1) +#define CL_CHAR_MAX CL_SCHAR_MAX +#define CL_CHAR_MIN CL_SCHAR_MIN +#define CL_UCHAR_MAX 255 +#define CL_SHRT_MAX 32767 +#define CL_SHRT_MIN (-32767-1) +#define CL_USHRT_MAX 65535 +#define CL_INT_MAX 2147483647 +#define CL_INT_MIN (-2147483647-1) +#define CL_UINT_MAX 0xffffffffU +#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) +#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) +#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) + +#define CL_FLT_DIG 6 +#define CL_FLT_MANT_DIG 24 +#define CL_FLT_MAX_10_EXP +38 +#define CL_FLT_MAX_EXP +128 +#define CL_FLT_MIN_10_EXP -37 +#define CL_FLT_MIN_EXP -125 +#define CL_FLT_RADIX 2 +#define CL_FLT_MAX 340282346638528859811704183484516925440.0f +#define CL_FLT_MIN 1.175494350822287507969e-38f +#define CL_FLT_EPSILON 1.1920928955078125e-7f + +#define CL_HALF_DIG 3 +#define CL_HALF_MANT_DIG 11 +#define CL_HALF_MAX_10_EXP +4 +#define CL_HALF_MAX_EXP +16 +#define CL_HALF_MIN_10_EXP -4 +#define CL_HALF_MIN_EXP -13 +#define CL_HALF_RADIX 2 +#define CL_HALF_MAX 65504.0f +#define CL_HALF_MIN 6.103515625e-05f +#define CL_HALF_EPSILON 9.765625e-04f + +#define CL_DBL_DIG 15 +#define CL_DBL_MANT_DIG 53 +#define CL_DBL_MAX_10_EXP +308 +#define CL_DBL_MAX_EXP +1024 +#define CL_DBL_MIN_10_EXP -307 +#define CL_DBL_MIN_EXP -1021 +#define CL_DBL_RADIX 2 +#define CL_DBL_MAX 1.7976931348623158e+308 +#define CL_DBL_MIN 2.225073858507201383090e-308 +#define CL_DBL_EPSILON 2.220446049250313080847e-16 + +#define CL_M_E 2.7182818284590452354 +#define CL_M_LOG2E 1.4426950408889634074 +#define CL_M_LOG10E 0.43429448190325182765 +#define CL_M_LN2 0.69314718055994530942 +#define CL_M_LN10 2.30258509299404568402 +#define CL_M_PI 3.14159265358979323846 +#define CL_M_PI_2 1.57079632679489661923 +#define CL_M_PI_4 0.78539816339744830962 +#define CL_M_1_PI 0.31830988618379067154 +#define CL_M_2_PI 0.63661977236758134308 +#define CL_M_2_SQRTPI 1.12837916709551257390 +#define CL_M_SQRT2 1.41421356237309504880 +#define CL_M_SQRT1_2 0.70710678118654752440 + +#define CL_M_E_F 2.718281828f +#define CL_M_LOG2E_F 1.442695041f +#define CL_M_LOG10E_F 0.434294482f +#define CL_M_LN2_F 0.693147181f +#define CL_M_LN10_F 2.302585093f +#define CL_M_PI_F 3.141592654f +#define CL_M_PI_2_F 1.570796327f +#define CL_M_PI_4_F 0.785398163f +#define CL_M_1_PI_F 0.318309886f +#define CL_M_2_PI_F 0.636619772f +#define CL_M_2_SQRTPI_F 1.128379167f +#define CL_M_SQRT2_F 1.414213562f +#define CL_M_SQRT1_2_F 0.707106781f + +#define CL_NAN (CL_INFINITY - CL_INFINITY) +#define CL_HUGE_VALF ((cl_float) 1e50) +#define CL_HUGE_VAL ((cl_double) 1e500) +#define CL_MAXFLOAT CL_FLT_MAX +#define CL_INFINITY CL_HUGE_VALF + +#else + +#include + +/* scalar types */ +typedef int8_t cl_char; +typedef uint8_t cl_uchar; +typedef int16_t cl_short __attribute__((aligned(2))); +typedef uint16_t cl_ushort __attribute__((aligned(2))); +typedef int32_t cl_int __attribute__((aligned(4))); +typedef uint32_t cl_uint __attribute__((aligned(4))); +typedef int64_t cl_long __attribute__((aligned(8))); +typedef uint64_t cl_ulong __attribute__((aligned(8))); + +typedef uint16_t cl_half __attribute__((aligned(2))); +typedef float cl_float __attribute__((aligned(4))); +typedef double cl_double __attribute__((aligned(8))); + +/* Macro names and corresponding values defined by OpenCL */ +#define CL_CHAR_BIT 8 +#define CL_SCHAR_MAX 127 +#define CL_SCHAR_MIN (-127-1) +#define CL_CHAR_MAX CL_SCHAR_MAX +#define CL_CHAR_MIN CL_SCHAR_MIN +#define CL_UCHAR_MAX 255 +#define CL_SHRT_MAX 32767 +#define CL_SHRT_MIN (-32767-1) +#define CL_USHRT_MAX 65535 +#define CL_INT_MAX 2147483647 +#define CL_INT_MIN (-2147483647-1) +#define CL_UINT_MAX 0xffffffffU +#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) +#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) +#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) + +#define CL_FLT_DIG 6 +#define CL_FLT_MANT_DIG 24 +#define CL_FLT_MAX_10_EXP +38 +#define CL_FLT_MAX_EXP +128 +#define CL_FLT_MIN_10_EXP -37 +#define CL_FLT_MIN_EXP -125 +#define CL_FLT_RADIX 2 +#define CL_FLT_MAX 340282346638528859811704183484516925440.0f +#define CL_FLT_MIN 1.175494350822287507969e-38f +#define CL_FLT_EPSILON 1.1920928955078125e-7f + +#define CL_HALF_DIG 3 +#define CL_HALF_MANT_DIG 11 +#define CL_HALF_MAX_10_EXP +4 +#define CL_HALF_MAX_EXP +16 +#define CL_HALF_MIN_10_EXP -4 +#define CL_HALF_MIN_EXP -13 +#define CL_HALF_RADIX 2 +#define CL_HALF_MAX 65504.0f +#define CL_HALF_MIN 6.103515625e-05f +#define CL_HALF_EPSILON 9.765625e-04f + +#define CL_DBL_DIG 15 +#define CL_DBL_MANT_DIG 53 +#define CL_DBL_MAX_10_EXP +308 +#define CL_DBL_MAX_EXP +1024 +#define CL_DBL_MIN_10_EXP -307 +#define CL_DBL_MIN_EXP -1021 +#define CL_DBL_RADIX 2 +#define CL_DBL_MAX 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0 +#define CL_DBL_MIN 2.225073858507201383090e-308 +#define CL_DBL_EPSILON 2.220446049250313080847e-16 + +#define CL_M_E 2.7182818284590452354 +#define CL_M_LOG2E 1.4426950408889634074 +#define CL_M_LOG10E 0.43429448190325182765 +#define CL_M_LN2 0.69314718055994530942 +#define CL_M_LN10 2.30258509299404568402 +#define CL_M_PI 3.14159265358979323846 +#define CL_M_PI_2 1.57079632679489661923 +#define CL_M_PI_4 0.78539816339744830962 +#define CL_M_1_PI 0.31830988618379067154 +#define CL_M_2_PI 0.63661977236758134308 +#define CL_M_2_SQRTPI 1.12837916709551257390 +#define CL_M_SQRT2 1.41421356237309504880 +#define CL_M_SQRT1_2 0.70710678118654752440 + +#define CL_M_E_F 2.718281828f +#define CL_M_LOG2E_F 1.442695041f +#define CL_M_LOG10E_F 0.434294482f +#define CL_M_LN2_F 0.693147181f +#define CL_M_LN10_F 2.302585093f +#define CL_M_PI_F 3.141592654f +#define CL_M_PI_2_F 1.570796327f +#define CL_M_PI_4_F 0.785398163f +#define CL_M_1_PI_F 0.318309886f +#define CL_M_2_PI_F 0.636619772f +#define CL_M_2_SQRTPI_F 1.128379167f +#define CL_M_SQRT2_F 1.414213562f +#define CL_M_SQRT1_2_F 0.707106781f + +#if defined( __GNUC__ ) + #define CL_HUGE_VALF __builtin_huge_valf() + #define CL_HUGE_VAL __builtin_huge_val() + #define CL_NAN __builtin_nanf( "" ) +#else + #define CL_HUGE_VALF ((cl_float) 1e50) + #define CL_HUGE_VAL ((cl_double) 1e500) + float nanf( const char * ); + #define CL_NAN nanf( "" ) +#endif +#define CL_MAXFLOAT CL_FLT_MAX +#define CL_INFINITY CL_HUGE_VALF + +#endif + +#include + +/* Mirror types to GL types. Mirror types allow us to avoid deciding which 87s to load based on whether we are using GL or GLES here. */ +typedef unsigned int cl_GLuint; +typedef int cl_GLint; +typedef unsigned int cl_GLenum; + +/* + * Vector types + * + * Note: OpenCL requires that all types be naturally aligned. + * This means that vector types must be naturally aligned. + * For example, a vector of four floats must be aligned to + * a 16 byte boundary (calculated as 4 * the natural 4-byte + * alignment of the float). The alignment qualifiers here + * will only function properly if your compiler supports them + * and if you don't actively work to defeat them. For example, + * in order for a cl_float4 to be 16 byte aligned in a struct, + * the start of the struct must itself be 16-byte aligned. + * + * Maintaining proper alignment is the user's responsibility. + */ + +/* Define basic vector types */ +#if defined( __VEC__ ) + #include /* may be omitted depending on compiler. AltiVec spec provides no way to detect whether the header is required. */ + typedef vector unsigned char __cl_uchar16; + typedef vector signed char __cl_char16; + typedef vector unsigned short __cl_ushort8; + typedef vector signed short __cl_short8; + typedef vector unsigned int __cl_uint4; + typedef vector signed int __cl_int4; + typedef vector float __cl_float4; + #define __CL_UCHAR16__ 1 + #define __CL_CHAR16__ 1 + #define __CL_USHORT8__ 1 + #define __CL_SHORT8__ 1 + #define __CL_UINT4__ 1 + #define __CL_INT4__ 1 + #define __CL_FLOAT4__ 1 +#endif + +#if defined( __SSE__ ) + #if defined( __MINGW64__ ) + #include + #else + #include + #endif + #if defined( __GNUC__ ) + typedef float __cl_float4 __attribute__((vector_size(16))); + #else + typedef __m128 __cl_float4; + #endif + #define __CL_FLOAT4__ 1 +#endif + +#if defined( __SSE2__ ) + #if defined( __MINGW64__ ) + #include + #else + #include + #endif + #if defined( __GNUC__ ) + typedef cl_uchar __cl_uchar16 __attribute__((vector_size(16))); + typedef cl_char __cl_char16 __attribute__((vector_size(16))); + typedef cl_ushort __cl_ushort8 __attribute__((vector_size(16))); + typedef cl_short __cl_short8 __attribute__((vector_size(16))); + typedef cl_uint __cl_uint4 __attribute__((vector_size(16))); + typedef cl_int __cl_int4 __attribute__((vector_size(16))); + typedef cl_ulong __cl_ulong2 __attribute__((vector_size(16))); + typedef cl_long __cl_long2 __attribute__((vector_size(16))); + typedef cl_double __cl_double2 __attribute__((vector_size(16))); + #else + typedef __m128i __cl_uchar16; + typedef __m128i __cl_char16; + typedef __m128i __cl_ushort8; + typedef __m128i __cl_short8; + typedef __m128i __cl_uint4; + typedef __m128i __cl_int4; + typedef __m128i __cl_ulong2; + typedef __m128i __cl_long2; + typedef __m128d __cl_double2; + #endif + #define __CL_UCHAR16__ 1 + #define __CL_CHAR16__ 1 + #define __CL_USHORT8__ 1 + #define __CL_SHORT8__ 1 + #define __CL_INT4__ 1 + #define __CL_UINT4__ 1 + #define __CL_ULONG2__ 1 + #define __CL_LONG2__ 1 + #define __CL_DOUBLE2__ 1 +#endif + +#if defined( __MMX__ ) + #include + #if defined( __GNUC__ ) + typedef cl_uchar __cl_uchar8 __attribute__((vector_size(8))); + typedef cl_char __cl_char8 __attribute__((vector_size(8))); + typedef cl_ushort __cl_ushort4 __attribute__((vector_size(8))); + typedef cl_short __cl_short4 __attribute__((vector_size(8))); + typedef cl_uint __cl_uint2 __attribute__((vector_size(8))); + typedef cl_int __cl_int2 __attribute__((vector_size(8))); + typedef cl_ulong __cl_ulong1 __attribute__((vector_size(8))); + typedef cl_long __cl_long1 __attribute__((vector_size(8))); + typedef cl_float __cl_float2 __attribute__((vector_size(8))); + #else + typedef __m64 __cl_uchar8; + typedef __m64 __cl_char8; + typedef __m64 __cl_ushort4; + typedef __m64 __cl_short4; + typedef __m64 __cl_uint2; + typedef __m64 __cl_int2; + typedef __m64 __cl_ulong1; + typedef __m64 __cl_long1; + typedef __m64 __cl_float2; + #endif + #define __CL_UCHAR8__ 1 + #define __CL_CHAR8__ 1 + #define __CL_USHORT4__ 1 + #define __CL_SHORT4__ 1 + #define __CL_INT2__ 1 + #define __CL_UINT2__ 1 + #define __CL_ULONG1__ 1 + #define __CL_LONG1__ 1 + #define __CL_FLOAT2__ 1 +#endif + +#if defined( __AVX__ ) + #if defined( __MINGW64__ ) + #include + #else + #include + #endif + #if defined( __GNUC__ ) + typedef cl_float __cl_float8 __attribute__((vector_size(32))); + typedef cl_double __cl_double4 __attribute__((vector_size(32))); + #else + typedef __m256 __cl_float8; + typedef __m256d __cl_double4; + #endif + #define __CL_FLOAT8__ 1 + #define __CL_DOUBLE4__ 1 +#endif + +/* Define capabilities for anonymous struct members. */ +#if !defined(__cplusplus) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#define __CL_HAS_ANON_STRUCT__ 1 +#define __CL_ANON_STRUCT__ +#elif defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) +#define __CL_HAS_ANON_STRUCT__ 1 +#define __CL_ANON_STRUCT__ __extension__ +#elif defined( _WIN32) && defined(_MSC_VER) + #if _MSC_VER >= 1500 + /* Microsoft Developer Studio 2008 supports anonymous structs, but + * complains by default. */ + #define __CL_HAS_ANON_STRUCT__ 1 + #define __CL_ANON_STRUCT__ + /* Disable warning C4201: nonstandard extension used : nameless + * struct/union */ + #pragma warning( push ) + #pragma warning( disable : 4201 ) + #endif +#else +#define __CL_HAS_ANON_STRUCT__ 0 +#define __CL_ANON_STRUCT__ +#endif + +/* Define alignment keys */ +#if defined( __GNUC__ ) + #define CL_ALIGNED(_x) __attribute__ ((aligned(_x))) +#elif defined( _WIN32) && (_MSC_VER) + /* Alignment keys neutered on windows because MSVC can't swallow function arguments with alignment requirements */ + /* http://msdn.microsoft.com/en-us/library/373ak2y1%28VS.71%29.aspx */ + /* #include */ + /* #define CL_ALIGNED(_x) _CRT_ALIGN(_x) */ + #define CL_ALIGNED(_x) +#else + #warning Need to implement some method to align data here + #define CL_ALIGNED(_x) +#endif + +/* Indicate whether .xyzw, .s0123 and .hi.lo are supported */ +#if __CL_HAS_ANON_STRUCT__ + /* .xyzw and .s0123...{f|F} are supported */ + #define CL_HAS_NAMED_VECTOR_FIELDS 1 + /* .hi and .lo are supported */ + #define CL_HAS_HI_LO_VECTOR_FIELDS 1 +#endif + +/* Define cl_vector types */ + +/* ---- cl_charn ---- */ +typedef union +{ + cl_char CL_ALIGNED(2) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_char lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2; +#endif +}cl_char2; + +typedef union +{ + cl_char CL_ALIGNED(4) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_char2 lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2[2]; +#endif +#if defined( __CL_CHAR4__) + __cl_char4 v4; +#endif +}cl_char4; + +/* cl_char3 is identical in size, alignment and behavior to cl_char4. See section 6.1.5. */ +typedef cl_char4 cl_char3; + +typedef union +{ + cl_char CL_ALIGNED(8) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_char4 lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2[4]; +#endif +#if defined( __CL_CHAR4__) + __cl_char4 v4[2]; +#endif +#if defined( __CL_CHAR8__ ) + __cl_char8 v8; +#endif +}cl_char8; + +typedef union +{ + cl_char CL_ALIGNED(16) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_char8 lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2[8]; +#endif +#if defined( __CL_CHAR4__) + __cl_char4 v4[4]; +#endif +#if defined( __CL_CHAR8__ ) + __cl_char8 v8[2]; +#endif +#if defined( __CL_CHAR16__ ) + __cl_char16 v16; +#endif +}cl_char16; + + +/* ---- cl_ucharn ---- */ +typedef union +{ + cl_uchar CL_ALIGNED(2) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_uchar lo, hi; }; +#endif +#if defined( __cl_uchar2__) + __cl_uchar2 v2; +#endif +}cl_uchar2; + +typedef union +{ + cl_uchar CL_ALIGNED(4) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_uchar2 lo, hi; }; +#endif +#if defined( __CL_UCHAR2__) + __cl_uchar2 v2[2]; +#endif +#if defined( __CL_UCHAR4__) + __cl_uchar4 v4; +#endif +}cl_uchar4; + +/* cl_uchar3 is identical in size, alignment and behavior to cl_uchar4. See section 6.1.5. */ +typedef cl_uchar4 cl_uchar3; + +typedef union +{ + cl_uchar CL_ALIGNED(8) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_uchar4 lo, hi; }; +#endif +#if defined( __CL_UCHAR2__) + __cl_uchar2 v2[4]; +#endif +#if defined( __CL_UCHAR4__) + __cl_uchar4 v4[2]; +#endif +#if defined( __CL_UCHAR8__ ) + __cl_uchar8 v8; +#endif +}cl_uchar8; + +typedef union +{ + cl_uchar CL_ALIGNED(16) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_uchar8 lo, hi; }; +#endif +#if defined( __CL_UCHAR2__) + __cl_uchar2 v2[8]; +#endif +#if defined( __CL_UCHAR4__) + __cl_uchar4 v4[4]; +#endif +#if defined( __CL_UCHAR8__ ) + __cl_uchar8 v8[2]; +#endif +#if defined( __CL_UCHAR16__ ) + __cl_uchar16 v16; +#endif +}cl_uchar16; + + +/* ---- cl_shortn ---- */ +typedef union +{ + cl_short CL_ALIGNED(4) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_short lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2; +#endif +}cl_short2; + +typedef union +{ + cl_short CL_ALIGNED(8) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_short2 lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2[2]; +#endif +#if defined( __CL_SHORT4__) + __cl_short4 v4; +#endif +}cl_short4; + +/* cl_short3 is identical in size, alignment and behavior to cl_short4. See section 6.1.5. */ +typedef cl_short4 cl_short3; + +typedef union +{ + cl_short CL_ALIGNED(16) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_short4 lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2[4]; +#endif +#if defined( __CL_SHORT4__) + __cl_short4 v4[2]; +#endif +#if defined( __CL_SHORT8__ ) + __cl_short8 v8; +#endif +}cl_short8; + +typedef union +{ + cl_short CL_ALIGNED(32) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_short8 lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2[8]; +#endif +#if defined( __CL_SHORT4__) + __cl_short4 v4[4]; +#endif +#if defined( __CL_SHORT8__ ) + __cl_short8 v8[2]; +#endif +#if defined( __CL_SHORT16__ ) + __cl_short16 v16; +#endif +}cl_short16; + + +/* ---- cl_ushortn ---- */ +typedef union +{ + cl_ushort CL_ALIGNED(4) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_ushort lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2; +#endif +}cl_ushort2; + +typedef union +{ + cl_ushort CL_ALIGNED(8) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_ushort2 lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2[2]; +#endif +#if defined( __CL_USHORT4__) + __cl_ushort4 v4; +#endif +}cl_ushort4; + +/* cl_ushort3 is identical in size, alignment and behavior to cl_ushort4. See section 6.1.5. */ +typedef cl_ushort4 cl_ushort3; + +typedef union +{ + cl_ushort CL_ALIGNED(16) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_ushort4 lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2[4]; +#endif +#if defined( __CL_USHORT4__) + __cl_ushort4 v4[2]; +#endif +#if defined( __CL_USHORT8__ ) + __cl_ushort8 v8; +#endif +}cl_ushort8; + +typedef union +{ + cl_ushort CL_ALIGNED(32) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_ushort8 lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2[8]; +#endif +#if defined( __CL_USHORT4__) + __cl_ushort4 v4[4]; +#endif +#if defined( __CL_USHORT8__ ) + __cl_ushort8 v8[2]; +#endif +#if defined( __CL_USHORT16__ ) + __cl_ushort16 v16; +#endif +}cl_ushort16; + + +/* ---- cl_halfn ---- */ +typedef union +{ + cl_half CL_ALIGNED(4) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_half lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2; +#endif +}cl_half2; + +typedef union +{ + cl_half CL_ALIGNED(8) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_half2 lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2[2]; +#endif +#if defined( __CL_HALF4__) + __cl_half4 v4; +#endif +}cl_half4; + +/* cl_half3 is identical in size, alignment and behavior to cl_half4. See section 6.1.5. */ +typedef cl_half4 cl_half3; + +typedef union +{ + cl_half CL_ALIGNED(16) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_half4 lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2[4]; +#endif +#if defined( __CL_HALF4__) + __cl_half4 v4[2]; +#endif +#if defined( __CL_HALF8__ ) + __cl_half8 v8; +#endif +}cl_half8; + +typedef union +{ + cl_half CL_ALIGNED(32) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_half8 lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2[8]; +#endif +#if defined( __CL_HALF4__) + __cl_half4 v4[4]; +#endif +#if defined( __CL_HALF8__ ) + __cl_half8 v8[2]; +#endif +#if defined( __CL_HALF16__ ) + __cl_half16 v16; +#endif +}cl_half16; + +/* ---- cl_intn ---- */ +typedef union +{ + cl_int CL_ALIGNED(8) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_int lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2; +#endif +}cl_int2; + +typedef union +{ + cl_int CL_ALIGNED(16) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_int2 lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2[2]; +#endif +#if defined( __CL_INT4__) + __cl_int4 v4; +#endif +}cl_int4; + +/* cl_int3 is identical in size, alignment and behavior to cl_int4. See section 6.1.5. */ +typedef cl_int4 cl_int3; + +typedef union +{ + cl_int CL_ALIGNED(32) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_int4 lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2[4]; +#endif +#if defined( __CL_INT4__) + __cl_int4 v4[2]; +#endif +#if defined( __CL_INT8__ ) + __cl_int8 v8; +#endif +}cl_int8; + +typedef union +{ + cl_int CL_ALIGNED(64) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_int8 lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2[8]; +#endif +#if defined( __CL_INT4__) + __cl_int4 v4[4]; +#endif +#if defined( __CL_INT8__ ) + __cl_int8 v8[2]; +#endif +#if defined( __CL_INT16__ ) + __cl_int16 v16; +#endif +}cl_int16; + + +/* ---- cl_uintn ---- */ +typedef union +{ + cl_uint CL_ALIGNED(8) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_uint lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2; +#endif +}cl_uint2; + +typedef union +{ + cl_uint CL_ALIGNED(16) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_uint2 lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2[2]; +#endif +#if defined( __CL_UINT4__) + __cl_uint4 v4; +#endif +}cl_uint4; + +/* cl_uint3 is identical in size, alignment and behavior to cl_uint4. See section 6.1.5. */ +typedef cl_uint4 cl_uint3; + +typedef union +{ + cl_uint CL_ALIGNED(32) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_uint4 lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2[4]; +#endif +#if defined( __CL_UINT4__) + __cl_uint4 v4[2]; +#endif +#if defined( __CL_UINT8__ ) + __cl_uint8 v8; +#endif +}cl_uint8; + +typedef union +{ + cl_uint CL_ALIGNED(64) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_uint8 lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2[8]; +#endif +#if defined( __CL_UINT4__) + __cl_uint4 v4[4]; +#endif +#if defined( __CL_UINT8__ ) + __cl_uint8 v8[2]; +#endif +#if defined( __CL_UINT16__ ) + __cl_uint16 v16; +#endif +}cl_uint16; + +/* ---- cl_longn ---- */ +typedef union +{ + cl_long CL_ALIGNED(16) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_long lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2; +#endif +}cl_long2; + +typedef union +{ + cl_long CL_ALIGNED(32) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_long2 lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2[2]; +#endif +#if defined( __CL_LONG4__) + __cl_long4 v4; +#endif +}cl_long4; + +/* cl_long3 is identical in size, alignment and behavior to cl_long4. See section 6.1.5. */ +typedef cl_long4 cl_long3; + +typedef union +{ + cl_long CL_ALIGNED(64) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_long4 lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2[4]; +#endif +#if defined( __CL_LONG4__) + __cl_long4 v4[2]; +#endif +#if defined( __CL_LONG8__ ) + __cl_long8 v8; +#endif +}cl_long8; + +typedef union +{ + cl_long CL_ALIGNED(128) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_long8 lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2[8]; +#endif +#if defined( __CL_LONG4__) + __cl_long4 v4[4]; +#endif +#if defined( __CL_LONG8__ ) + __cl_long8 v8[2]; +#endif +#if defined( __CL_LONG16__ ) + __cl_long16 v16; +#endif +}cl_long16; + + +/* ---- cl_ulongn ---- */ +typedef union +{ + cl_ulong CL_ALIGNED(16) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_ulong lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2; +#endif +}cl_ulong2; + +typedef union +{ + cl_ulong CL_ALIGNED(32) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_ulong2 lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2[2]; +#endif +#if defined( __CL_ULONG4__) + __cl_ulong4 v4; +#endif +}cl_ulong4; + +/* cl_ulong3 is identical in size, alignment and behavior to cl_ulong4. See section 6.1.5. */ +typedef cl_ulong4 cl_ulong3; + +typedef union +{ + cl_ulong CL_ALIGNED(64) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_ulong4 lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2[4]; +#endif +#if defined( __CL_ULONG4__) + __cl_ulong4 v4[2]; +#endif +#if defined( __CL_ULONG8__ ) + __cl_ulong8 v8; +#endif +}cl_ulong8; + +typedef union +{ + cl_ulong CL_ALIGNED(128) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_ulong8 lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2[8]; +#endif +#if defined( __CL_ULONG4__) + __cl_ulong4 v4[4]; +#endif +#if defined( __CL_ULONG8__ ) + __cl_ulong8 v8[2]; +#endif +#if defined( __CL_ULONG16__ ) + __cl_ulong16 v16; +#endif +}cl_ulong16; + + +/* --- cl_floatn ---- */ + +typedef union +{ + cl_float CL_ALIGNED(8) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_float lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2; +#endif +}cl_float2; + +typedef union +{ + cl_float CL_ALIGNED(16) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_float2 lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2[2]; +#endif +#if defined( __CL_FLOAT4__) + __cl_float4 v4; +#endif +}cl_float4; + +/* cl_float3 is identical in size, alignment and behavior to cl_float4. See section 6.1.5. */ +typedef cl_float4 cl_float3; + +typedef union +{ + cl_float CL_ALIGNED(32) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_float4 lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2[4]; +#endif +#if defined( __CL_FLOAT4__) + __cl_float4 v4[2]; +#endif +#if defined( __CL_FLOAT8__ ) + __cl_float8 v8; +#endif +}cl_float8; + +typedef union +{ + cl_float CL_ALIGNED(64) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_float8 lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2[8]; +#endif +#if defined( __CL_FLOAT4__) + __cl_float4 v4[4]; +#endif +#if defined( __CL_FLOAT8__ ) + __cl_float8 v8[2]; +#endif +#if defined( __CL_FLOAT16__ ) + __cl_float16 v16; +#endif +}cl_float16; + +/* --- cl_doublen ---- */ + +typedef union +{ + cl_double CL_ALIGNED(16) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_double lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2; +#endif +}cl_double2; + +typedef union +{ + cl_double CL_ALIGNED(32) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_double2 lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2[2]; +#endif +#if defined( __CL_DOUBLE4__) + __cl_double4 v4; +#endif +}cl_double4; + +/* cl_double3 is identical in size, alignment and behavior to cl_double4. See section 6.1.5. */ +typedef cl_double4 cl_double3; + +typedef union +{ + cl_double CL_ALIGNED(64) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_double4 lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2[4]; +#endif +#if defined( __CL_DOUBLE4__) + __cl_double4 v4[2]; +#endif +#if defined( __CL_DOUBLE8__ ) + __cl_double8 v8; +#endif +}cl_double8; + +typedef union +{ + cl_double CL_ALIGNED(128) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_double8 lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2[8]; +#endif +#if defined( __CL_DOUBLE4__) + __cl_double4 v4[4]; +#endif +#if defined( __CL_DOUBLE8__ ) + __cl_double8 v8[2]; +#endif +#if defined( __CL_DOUBLE16__ ) + __cl_double16 v16; +#endif +}cl_double16; + +/* Macro to facilitate debugging + * Usage: + * Place CL_PROGRAM_STRING_DEBUG_INFO on the line before the first line of your source. + * The first line ends with: CL_PROGRAM_STRING_DEBUG_INFO \" + * Each line thereafter of OpenCL C source must end with: \n\ + * The last line ends in "; + * + * Example: + * + * const char *my_program = CL_PROGRAM_STRING_DEBUG_INFO "\ + * kernel void foo( int a, float * b ) \n\ + * { \n\ + * // my comment \n\ + * *b[ get_global_id(0)] = a; \n\ + * } \n\ + * "; + * + * This should correctly set up the line, (column) and file information for your source + * string so you can do source level debugging. + */ +#define __CL_STRINGIFY( _x ) # _x +#define _CL_STRINGIFY( _x ) __CL_STRINGIFY( _x ) +#define CL_PROGRAM_STRING_DEBUG_INFO "#line " _CL_STRINGIFY(__LINE__) " \"" __FILE__ "\" \n\n" + +#ifdef __cplusplus +} +#endif + +#undef __CL_HAS_ANON_STRUCT__ +#undef __CL_ANON_STRUCT__ +#if defined( _WIN32) && defined(_MSC_VER) + #if _MSC_VER >=1500 + #pragma warning( pop ) + #endif +#endif + +#endif /* __CL_PLATFORM_H */ diff --git a/opencl/khronos/headers/opencl2.0/CL/opencl.h b/opencl/khronos/headers/opencl2.0/CL/opencl.h new file mode 100644 index 0000000000..9855cd75e7 --- /dev/null +++ b/opencl/khronos/headers/opencl2.0/CL/opencl.h @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_H +#define __OPENCL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __APPLE__ + +#include +#include +#include +#include + +#else + +#include +#include +#include +#include + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_H */ + diff --git a/opencl/khronos/headers/opencl2.1/CL/cl.h b/opencl/khronos/headers/opencl2.1/CL/cl.h new file mode 100644 index 0000000000..706e944545 --- /dev/null +++ b/opencl/khronos/headers/opencl2.1/CL/cl.h @@ -0,0 +1,1453 @@ +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +#ifndef __OPENCL_CL_H +#define __OPENCL_CL_H + +#ifdef __APPLE__ +#include +#else +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/******************************************************************************/ + +typedef struct _cl_platform_id * cl_platform_id; +typedef struct _cl_device_id * cl_device_id; +typedef struct _cl_context * cl_context; +typedef struct _cl_command_queue * cl_command_queue; +typedef struct _cl_mem * cl_mem; +typedef struct _cl_program * cl_program; +typedef struct _cl_kernel * cl_kernel; +typedef struct _cl_event * cl_event; +typedef struct _cl_sampler * cl_sampler; + +typedef cl_uint cl_bool; /* WARNING! Unlike cl_ types in cl_platform.h, cl_bool is not guaranteed to be the same size as the bool in kernels. */ +typedef cl_ulong cl_bitfield; +typedef cl_bitfield cl_device_type; +typedef cl_uint cl_platform_info; +typedef cl_uint cl_device_info; +typedef cl_bitfield cl_device_fp_config; +typedef cl_uint cl_device_mem_cache_type; +typedef cl_uint cl_device_local_mem_type; +typedef cl_bitfield cl_device_exec_capabilities; +typedef cl_bitfield cl_device_svm_capabilities; +typedef cl_bitfield cl_command_queue_properties; +typedef intptr_t cl_device_partition_property; +typedef cl_bitfield cl_device_affinity_domain; + +typedef intptr_t cl_context_properties; +typedef cl_uint cl_context_info; +typedef cl_bitfield cl_queue_properties; +typedef cl_uint cl_command_queue_info; +typedef cl_uint cl_channel_order; +typedef cl_uint cl_channel_type; +typedef cl_bitfield cl_mem_flags; +typedef cl_bitfield cl_svm_mem_flags; +typedef cl_uint cl_mem_object_type; +typedef cl_uint cl_mem_info; +typedef cl_bitfield cl_mem_migration_flags; +typedef cl_uint cl_image_info; +typedef cl_uint cl_buffer_create_type; +typedef cl_uint cl_addressing_mode; +typedef cl_uint cl_filter_mode; +typedef cl_uint cl_sampler_info; +typedef cl_bitfield cl_map_flags; +typedef intptr_t cl_pipe_properties; +typedef cl_uint cl_pipe_info; +typedef cl_uint cl_program_info; +typedef cl_uint cl_program_build_info; +typedef cl_uint cl_program_binary_type; +typedef cl_int cl_build_status; +typedef cl_uint cl_kernel_info; +typedef cl_uint cl_kernel_arg_info; +typedef cl_uint cl_kernel_arg_address_qualifier; +typedef cl_uint cl_kernel_arg_access_qualifier; +typedef cl_bitfield cl_kernel_arg_type_qualifier; +typedef cl_uint cl_kernel_work_group_info; +typedef cl_uint cl_kernel_sub_group_info; +typedef cl_uint cl_event_info; +typedef cl_uint cl_command_type; +typedef cl_uint cl_profiling_info; +typedef cl_bitfield cl_sampler_properties; +typedef cl_uint cl_kernel_exec_info; + +typedef struct _cl_image_format { + cl_channel_order image_channel_order; + cl_channel_type image_channel_data_type; +} cl_image_format; + +typedef struct _cl_image_desc { + cl_mem_object_type image_type; + size_t image_width; + size_t image_height; + size_t image_depth; + size_t image_array_size; + size_t image_row_pitch; + size_t image_slice_pitch; + cl_uint num_mip_levels; + cl_uint num_samples; +#ifdef __GNUC__ + __extension__ /* Prevents warnings about anonymous union in -pedantic builds */ +#endif + union { + cl_mem buffer; + cl_mem mem_object; + }; +} cl_image_desc; + +typedef struct _cl_buffer_region { + size_t origin; + size_t size; +} cl_buffer_region; + + +/******************************************************************************/ + +/* Error Codes */ +#define CL_SUCCESS 0 +#define CL_DEVICE_NOT_FOUND -1 +#define CL_DEVICE_NOT_AVAILABLE -2 +#define CL_COMPILER_NOT_AVAILABLE -3 +#define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 +#define CL_OUT_OF_RESOURCES -5 +#define CL_OUT_OF_HOST_MEMORY -6 +#define CL_PROFILING_INFO_NOT_AVAILABLE -7 +#define CL_MEM_COPY_OVERLAP -8 +#define CL_IMAGE_FORMAT_MISMATCH -9 +#define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 +#define CL_BUILD_PROGRAM_FAILURE -11 +#define CL_MAP_FAILURE -12 +#define CL_MISALIGNED_SUB_BUFFER_OFFSET -13 +#define CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST -14 +#define CL_COMPILE_PROGRAM_FAILURE -15 +#define CL_LINKER_NOT_AVAILABLE -16 +#define CL_LINK_PROGRAM_FAILURE -17 +#define CL_DEVICE_PARTITION_FAILED -18 +#define CL_KERNEL_ARG_INFO_NOT_AVAILABLE -19 + +#define CL_INVALID_VALUE -30 +#define CL_INVALID_DEVICE_TYPE -31 +#define CL_INVALID_PLATFORM -32 +#define CL_INVALID_DEVICE -33 +#define CL_INVALID_CONTEXT -34 +#define CL_INVALID_QUEUE_PROPERTIES -35 +#define CL_INVALID_COMMAND_QUEUE -36 +#define CL_INVALID_HOST_PTR -37 +#define CL_INVALID_MEM_OBJECT -38 +#define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 +#define CL_INVALID_IMAGE_SIZE -40 +#define CL_INVALID_SAMPLER -41 +#define CL_INVALID_BINARY -42 +#define CL_INVALID_BUILD_OPTIONS -43 +#define CL_INVALID_PROGRAM -44 +#define CL_INVALID_PROGRAM_EXECUTABLE -45 +#define CL_INVALID_KERNEL_NAME -46 +#define CL_INVALID_KERNEL_DEFINITION -47 +#define CL_INVALID_KERNEL -48 +#define CL_INVALID_ARG_INDEX -49 +#define CL_INVALID_ARG_VALUE -50 +#define CL_INVALID_ARG_SIZE -51 +#define CL_INVALID_KERNEL_ARGS -52 +#define CL_INVALID_WORK_DIMENSION -53 +#define CL_INVALID_WORK_GROUP_SIZE -54 +#define CL_INVALID_WORK_ITEM_SIZE -55 +#define CL_INVALID_GLOBAL_OFFSET -56 +#define CL_INVALID_EVENT_WAIT_LIST -57 +#define CL_INVALID_EVENT -58 +#define CL_INVALID_OPERATION -59 +#define CL_INVALID_GL_OBJECT -60 +#define CL_INVALID_BUFFER_SIZE -61 +#define CL_INVALID_MIP_LEVEL -62 +#define CL_INVALID_GLOBAL_WORK_SIZE -63 +#define CL_INVALID_PROPERTY -64 +#define CL_INVALID_IMAGE_DESCRIPTOR -65 +#define CL_INVALID_COMPILER_OPTIONS -66 +#define CL_INVALID_LINKER_OPTIONS -67 +#define CL_INVALID_DEVICE_PARTITION_COUNT -68 +#define CL_INVALID_PIPE_SIZE -69 +#define CL_INVALID_DEVICE_QUEUE -70 + +/* OpenCL Version */ +#define CL_VERSION_1_0 1 +#define CL_VERSION_1_1 1 +#define CL_VERSION_1_2 1 +#define CL_VERSION_2_0 1 +#define CL_VERSION_2_1 1 + +/* cl_bool */ +#define CL_FALSE 0 +#define CL_TRUE 1 +#define CL_BLOCKING CL_TRUE +#define CL_NON_BLOCKING CL_FALSE + +/* cl_platform_info */ +#define CL_PLATFORM_PROFILE 0x0900 +#define CL_PLATFORM_VERSION 0x0901 +#define CL_PLATFORM_NAME 0x0902 +#define CL_PLATFORM_VENDOR 0x0903 +#define CL_PLATFORM_EXTENSIONS 0x0904 +#define CL_PLATFORM_HOST_TIMER_RESOLUTION 0x0905 + +/* cl_device_type - bitfield */ +#define CL_DEVICE_TYPE_DEFAULT (1 << 0) +#define CL_DEVICE_TYPE_CPU (1 << 1) +#define CL_DEVICE_TYPE_GPU (1 << 2) +#define CL_DEVICE_TYPE_ACCELERATOR (1 << 3) +#define CL_DEVICE_TYPE_CUSTOM (1 << 4) +#define CL_DEVICE_TYPE_ALL 0xFFFFFFFF + +/* cl_device_info */ +#define CL_DEVICE_TYPE 0x1000 +#define CL_DEVICE_VENDOR_ID 0x1001 +#define CL_DEVICE_MAX_COMPUTE_UNITS 0x1002 +#define CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS 0x1003 +#define CL_DEVICE_MAX_WORK_GROUP_SIZE 0x1004 +#define CL_DEVICE_MAX_WORK_ITEM_SIZES 0x1005 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR 0x1006 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT 0x1007 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT 0x1008 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG 0x1009 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT 0x100A +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE 0x100B +#define CL_DEVICE_MAX_CLOCK_FREQUENCY 0x100C +#define CL_DEVICE_ADDRESS_BITS 0x100D +#define CL_DEVICE_MAX_READ_IMAGE_ARGS 0x100E +#define CL_DEVICE_MAX_WRITE_IMAGE_ARGS 0x100F +#define CL_DEVICE_MAX_MEM_ALLOC_SIZE 0x1010 +#define CL_DEVICE_IMAGE2D_MAX_WIDTH 0x1011 +#define CL_DEVICE_IMAGE2D_MAX_HEIGHT 0x1012 +#define CL_DEVICE_IMAGE3D_MAX_WIDTH 0x1013 +#define CL_DEVICE_IMAGE3D_MAX_HEIGHT 0x1014 +#define CL_DEVICE_IMAGE3D_MAX_DEPTH 0x1015 +#define CL_DEVICE_IMAGE_SUPPORT 0x1016 +#define CL_DEVICE_MAX_PARAMETER_SIZE 0x1017 +#define CL_DEVICE_MAX_SAMPLERS 0x1018 +#define CL_DEVICE_MEM_BASE_ADDR_ALIGN 0x1019 +#define CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE 0x101A +#define CL_DEVICE_SINGLE_FP_CONFIG 0x101B +#define CL_DEVICE_GLOBAL_MEM_CACHE_TYPE 0x101C +#define CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE 0x101D +#define CL_DEVICE_GLOBAL_MEM_CACHE_SIZE 0x101E +#define CL_DEVICE_GLOBAL_MEM_SIZE 0x101F +#define CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE 0x1020 +#define CL_DEVICE_MAX_CONSTANT_ARGS 0x1021 +#define CL_DEVICE_LOCAL_MEM_TYPE 0x1022 +#define CL_DEVICE_LOCAL_MEM_SIZE 0x1023 +#define CL_DEVICE_ERROR_CORRECTION_SUPPORT 0x1024 +#define CL_DEVICE_PROFILING_TIMER_RESOLUTION 0x1025 +#define CL_DEVICE_ENDIAN_LITTLE 0x1026 +#define CL_DEVICE_AVAILABLE 0x1027 +#define CL_DEVICE_COMPILER_AVAILABLE 0x1028 +#define CL_DEVICE_EXECUTION_CAPABILITIES 0x1029 +#define CL_DEVICE_QUEUE_PROPERTIES 0x102A /* deprecated */ +#define CL_DEVICE_QUEUE_ON_HOST_PROPERTIES 0x102A +#define CL_DEVICE_NAME 0x102B +#define CL_DEVICE_VENDOR 0x102C +#define CL_DRIVER_VERSION 0x102D +#define CL_DEVICE_PROFILE 0x102E +#define CL_DEVICE_VERSION 0x102F +#define CL_DEVICE_EXTENSIONS 0x1030 +#define CL_DEVICE_PLATFORM 0x1031 +#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 +#define CL_DEVICE_HALF_FP_CONFIG 0x1033 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF 0x1034 +#define CL_DEVICE_HOST_UNIFIED_MEMORY 0x1035 /* deprecated */ +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR 0x1036 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT 0x1037 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 0x1038 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 0x1039 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 0x103A +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 0x103B +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 0x103C +#define CL_DEVICE_OPENCL_C_VERSION 0x103D +#define CL_DEVICE_LINKER_AVAILABLE 0x103E +#define CL_DEVICE_BUILT_IN_KERNELS 0x103F +#define CL_DEVICE_IMAGE_MAX_BUFFER_SIZE 0x1040 +#define CL_DEVICE_IMAGE_MAX_ARRAY_SIZE 0x1041 +#define CL_DEVICE_PARENT_DEVICE 0x1042 +#define CL_DEVICE_PARTITION_MAX_SUB_DEVICES 0x1043 +#define CL_DEVICE_PARTITION_PROPERTIES 0x1044 +#define CL_DEVICE_PARTITION_AFFINITY_DOMAIN 0x1045 +#define CL_DEVICE_PARTITION_TYPE 0x1046 +#define CL_DEVICE_REFERENCE_COUNT 0x1047 +#define CL_DEVICE_PREFERRED_INTEROP_USER_SYNC 0x1048 +#define CL_DEVICE_PRINTF_BUFFER_SIZE 0x1049 +#define CL_DEVICE_IMAGE_PITCH_ALIGNMENT 0x104A +#define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT 0x104B +#define CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS 0x104C +#define CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE 0x104D +#define CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES 0x104E +#define CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE 0x104F +#define CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE 0x1050 +#define CL_DEVICE_MAX_ON_DEVICE_QUEUES 0x1051 +#define CL_DEVICE_MAX_ON_DEVICE_EVENTS 0x1052 +#define CL_DEVICE_SVM_CAPABILITIES 0x1053 +#define CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE 0x1054 +#define CL_DEVICE_MAX_PIPE_ARGS 0x1055 +#define CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS 0x1056 +#define CL_DEVICE_PIPE_MAX_PACKET_SIZE 0x1057 +#define CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT 0x1058 +#define CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT 0x1059 +#define CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT 0x105A +#define CL_DEVICE_IL_VERSION 0x105B +#define CL_DEVICE_MAX_NUM_SUB_GROUPS 0x105C +#define CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS 0x105D + +/* cl_device_fp_config - bitfield */ +#define CL_FP_DENORM (1 << 0) +#define CL_FP_INF_NAN (1 << 1) +#define CL_FP_ROUND_TO_NEAREST (1 << 2) +#define CL_FP_ROUND_TO_ZERO (1 << 3) +#define CL_FP_ROUND_TO_INF (1 << 4) +#define CL_FP_FMA (1 << 5) +#define CL_FP_SOFT_FLOAT (1 << 6) +#define CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT (1 << 7) + +/* cl_device_mem_cache_type */ +#define CL_NONE 0x0 +#define CL_READ_ONLY_CACHE 0x1 +#define CL_READ_WRITE_CACHE 0x2 + +/* cl_device_local_mem_type */ +#define CL_LOCAL 0x1 +#define CL_GLOBAL 0x2 + +/* cl_device_exec_capabilities - bitfield */ +#define CL_EXEC_KERNEL (1 << 0) +#define CL_EXEC_NATIVE_KERNEL (1 << 1) + +/* cl_command_queue_properties - bitfield */ +#define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE (1 << 0) +#define CL_QUEUE_PROFILING_ENABLE (1 << 1) +#define CL_QUEUE_ON_DEVICE (1 << 2) +#define CL_QUEUE_ON_DEVICE_DEFAULT (1 << 3) + +/* cl_context_info */ +#define CL_CONTEXT_REFERENCE_COUNT 0x1080 +#define CL_CONTEXT_DEVICES 0x1081 +#define CL_CONTEXT_PROPERTIES 0x1082 +#define CL_CONTEXT_NUM_DEVICES 0x1083 + +/* cl_context_properties */ +#define CL_CONTEXT_PLATFORM 0x1084 +#define CL_CONTEXT_INTEROP_USER_SYNC 0x1085 + +/* cl_device_partition_property */ +#define CL_DEVICE_PARTITION_EQUALLY 0x1086 +#define CL_DEVICE_PARTITION_BY_COUNTS 0x1087 +#define CL_DEVICE_PARTITION_BY_COUNTS_LIST_END 0x0 +#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN 0x1088 + +/* cl_device_affinity_domain */ +#define CL_DEVICE_AFFINITY_DOMAIN_NUMA (1 << 0) +#define CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE (1 << 1) +#define CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE (1 << 2) +#define CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE (1 << 3) +#define CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE (1 << 4) +#define CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE (1 << 5) + +/* cl_device_svm_capabilities */ +#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER (1 << 0) +#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER (1 << 1) +#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM (1 << 2) +#define CL_DEVICE_SVM_ATOMICS (1 << 3) + +/* cl_command_queue_info */ +#define CL_QUEUE_CONTEXT 0x1090 +#define CL_QUEUE_DEVICE 0x1091 +#define CL_QUEUE_REFERENCE_COUNT 0x1092 +#define CL_QUEUE_PROPERTIES 0x1093 +#define CL_QUEUE_SIZE 0x1094 +#define CL_QUEUE_DEVICE_DEFAULT 0x1095 + +/* cl_mem_flags and cl_svm_mem_flags - bitfield */ +#define CL_MEM_READ_WRITE (1 << 0) +#define CL_MEM_WRITE_ONLY (1 << 1) +#define CL_MEM_READ_ONLY (1 << 2) +#define CL_MEM_USE_HOST_PTR (1 << 3) +#define CL_MEM_ALLOC_HOST_PTR (1 << 4) +#define CL_MEM_COPY_HOST_PTR (1 << 5) +/* reserved (1 << 6) */ +#define CL_MEM_HOST_WRITE_ONLY (1 << 7) +#define CL_MEM_HOST_READ_ONLY (1 << 8) +#define CL_MEM_HOST_NO_ACCESS (1 << 9) +#define CL_MEM_SVM_FINE_GRAIN_BUFFER (1 << 10) /* used by cl_svm_mem_flags only */ +#define CL_MEM_SVM_ATOMICS (1 << 11) /* used by cl_svm_mem_flags only */ +#define CL_MEM_KERNEL_READ_AND_WRITE (1 << 12) + +/* cl_mem_migration_flags - bitfield */ +#define CL_MIGRATE_MEM_OBJECT_HOST (1 << 0) +#define CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED (1 << 1) + +/* cl_channel_order */ +#define CL_R 0x10B0 +#define CL_A 0x10B1 +#define CL_RG 0x10B2 +#define CL_RA 0x10B3 +#define CL_RGB 0x10B4 +#define CL_RGBA 0x10B5 +#define CL_BGRA 0x10B6 +#define CL_ARGB 0x10B7 +#define CL_INTENSITY 0x10B8 +#define CL_LUMINANCE 0x10B9 +#define CL_Rx 0x10BA +#define CL_RGx 0x10BB +#define CL_RGBx 0x10BC +#define CL_DEPTH 0x10BD +#define CL_DEPTH_STENCIL 0x10BE +#define CL_sRGB 0x10BF +#define CL_sRGBx 0x10C0 +#define CL_sRGBA 0x10C1 +#define CL_sBGRA 0x10C2 +#define CL_ABGR 0x10C3 + +/* cl_channel_type */ +#define CL_SNORM_INT8 0x10D0 +#define CL_SNORM_INT16 0x10D1 +#define CL_UNORM_INT8 0x10D2 +#define CL_UNORM_INT16 0x10D3 +#define CL_UNORM_SHORT_565 0x10D4 +#define CL_UNORM_SHORT_555 0x10D5 +#define CL_UNORM_INT_101010 0x10D6 +#define CL_SIGNED_INT8 0x10D7 +#define CL_SIGNED_INT16 0x10D8 +#define CL_SIGNED_INT32 0x10D9 +#define CL_UNSIGNED_INT8 0x10DA +#define CL_UNSIGNED_INT16 0x10DB +#define CL_UNSIGNED_INT32 0x10DC +#define CL_HALF_FLOAT 0x10DD +#define CL_FLOAT 0x10DE +#define CL_UNORM_INT24 0x10DF +#define CL_UNORM_INT_101010_2 0x10E0 + +/* cl_mem_object_type */ +#define CL_MEM_OBJECT_BUFFER 0x10F0 +#define CL_MEM_OBJECT_IMAGE2D 0x10F1 +#define CL_MEM_OBJECT_IMAGE3D 0x10F2 +#define CL_MEM_OBJECT_IMAGE2D_ARRAY 0x10F3 +#define CL_MEM_OBJECT_IMAGE1D 0x10F4 +#define CL_MEM_OBJECT_IMAGE1D_ARRAY 0x10F5 +#define CL_MEM_OBJECT_IMAGE1D_BUFFER 0x10F6 +#define CL_MEM_OBJECT_PIPE 0x10F7 + +/* cl_mem_info */ +#define CL_MEM_TYPE 0x1100 +#define CL_MEM_FLAGS 0x1101 +#define CL_MEM_SIZE 0x1102 +#define CL_MEM_HOST_PTR 0x1103 +#define CL_MEM_MAP_COUNT 0x1104 +#define CL_MEM_REFERENCE_COUNT 0x1105 +#define CL_MEM_CONTEXT 0x1106 +#define CL_MEM_ASSOCIATED_MEMOBJECT 0x1107 +#define CL_MEM_OFFSET 0x1108 +#define CL_MEM_USES_SVM_POINTER 0x1109 + +/* cl_image_info */ +#define CL_IMAGE_FORMAT 0x1110 +#define CL_IMAGE_ELEMENT_SIZE 0x1111 +#define CL_IMAGE_ROW_PITCH 0x1112 +#define CL_IMAGE_SLICE_PITCH 0x1113 +#define CL_IMAGE_WIDTH 0x1114 +#define CL_IMAGE_HEIGHT 0x1115 +#define CL_IMAGE_DEPTH 0x1116 +#define CL_IMAGE_ARRAY_SIZE 0x1117 +#define CL_IMAGE_BUFFER 0x1118 +#define CL_IMAGE_NUM_MIP_LEVELS 0x1119 +#define CL_IMAGE_NUM_SAMPLES 0x111A + +/* cl_pipe_info */ +#define CL_PIPE_PACKET_SIZE 0x1120 +#define CL_PIPE_MAX_PACKETS 0x1121 + +/* cl_addressing_mode */ +#define CL_ADDRESS_NONE 0x1130 +#define CL_ADDRESS_CLAMP_TO_EDGE 0x1131 +#define CL_ADDRESS_CLAMP 0x1132 +#define CL_ADDRESS_REPEAT 0x1133 +#define CL_ADDRESS_MIRRORED_REPEAT 0x1134 + +/* cl_filter_mode */ +#define CL_FILTER_NEAREST 0x1140 +#define CL_FILTER_LINEAR 0x1141 + +/* cl_sampler_info */ +#define CL_SAMPLER_REFERENCE_COUNT 0x1150 +#define CL_SAMPLER_CONTEXT 0x1151 +#define CL_SAMPLER_NORMALIZED_COORDS 0x1152 +#define CL_SAMPLER_ADDRESSING_MODE 0x1153 +#define CL_SAMPLER_FILTER_MODE 0x1154 +#define CL_SAMPLER_MIP_FILTER_MODE 0x1155 +#define CL_SAMPLER_LOD_MIN 0x1156 +#define CL_SAMPLER_LOD_MAX 0x1157 + +/* cl_map_flags - bitfield */ +#define CL_MAP_READ (1 << 0) +#define CL_MAP_WRITE (1 << 1) +#define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2) + +/* cl_program_info */ +#define CL_PROGRAM_REFERENCE_COUNT 0x1160 +#define CL_PROGRAM_CONTEXT 0x1161 +#define CL_PROGRAM_NUM_DEVICES 0x1162 +#define CL_PROGRAM_DEVICES 0x1163 +#define CL_PROGRAM_SOURCE 0x1164 +#define CL_PROGRAM_BINARY_SIZES 0x1165 +#define CL_PROGRAM_BINARIES 0x1166 +#define CL_PROGRAM_NUM_KERNELS 0x1167 +#define CL_PROGRAM_KERNEL_NAMES 0x1168 +#define CL_PROGRAM_IL 0x1169 + +/* cl_program_build_info */ +#define CL_PROGRAM_BUILD_STATUS 0x1181 +#define CL_PROGRAM_BUILD_OPTIONS 0x1182 +#define CL_PROGRAM_BUILD_LOG 0x1183 +#define CL_PROGRAM_BINARY_TYPE 0x1184 +#define CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE 0x1185 + +/* cl_program_binary_type */ +#define CL_PROGRAM_BINARY_TYPE_NONE 0x0 +#define CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT 0x1 +#define CL_PROGRAM_BINARY_TYPE_LIBRARY 0x2 +#define CL_PROGRAM_BINARY_TYPE_EXECUTABLE 0x4 + +/* cl_build_status */ +#define CL_BUILD_SUCCESS 0 +#define CL_BUILD_NONE -1 +#define CL_BUILD_ERROR -2 +#define CL_BUILD_IN_PROGRESS -3 + +/* cl_kernel_info */ +#define CL_KERNEL_FUNCTION_NAME 0x1190 +#define CL_KERNEL_NUM_ARGS 0x1191 +#define CL_KERNEL_REFERENCE_COUNT 0x1192 +#define CL_KERNEL_CONTEXT 0x1193 +#define CL_KERNEL_PROGRAM 0x1194 +#define CL_KERNEL_ATTRIBUTES 0x1195 +#define CL_KERNEL_MAX_NUM_SUB_GROUPS 0x11B9 +#define CL_KERNEL_COMPILE_NUM_SUB_GROUPS 0x11BA + +/* cl_kernel_arg_info */ +#define CL_KERNEL_ARG_ADDRESS_QUALIFIER 0x1196 +#define CL_KERNEL_ARG_ACCESS_QUALIFIER 0x1197 +#define CL_KERNEL_ARG_TYPE_NAME 0x1198 +#define CL_KERNEL_ARG_TYPE_QUALIFIER 0x1199 +#define CL_KERNEL_ARG_NAME 0x119A + +/* cl_kernel_arg_address_qualifier */ +#define CL_KERNEL_ARG_ADDRESS_GLOBAL 0x119B +#define CL_KERNEL_ARG_ADDRESS_LOCAL 0x119C +#define CL_KERNEL_ARG_ADDRESS_CONSTANT 0x119D +#define CL_KERNEL_ARG_ADDRESS_PRIVATE 0x119E + +/* cl_kernel_arg_access_qualifier */ +#define CL_KERNEL_ARG_ACCESS_READ_ONLY 0x11A0 +#define CL_KERNEL_ARG_ACCESS_WRITE_ONLY 0x11A1 +#define CL_KERNEL_ARG_ACCESS_READ_WRITE 0x11A2 +#define CL_KERNEL_ARG_ACCESS_NONE 0x11A3 + +/* cl_kernel_arg_type_qualifier */ +#define CL_KERNEL_ARG_TYPE_NONE 0 +#define CL_KERNEL_ARG_TYPE_CONST (1 << 0) +#define CL_KERNEL_ARG_TYPE_RESTRICT (1 << 1) +#define CL_KERNEL_ARG_TYPE_VOLATILE (1 << 2) +#define CL_KERNEL_ARG_TYPE_PIPE (1 << 3) + +/* cl_kernel_work_group_info */ +#define CL_KERNEL_WORK_GROUP_SIZE 0x11B0 +#define CL_KERNEL_COMPILE_WORK_GROUP_SIZE 0x11B1 +#define CL_KERNEL_LOCAL_MEM_SIZE 0x11B2 +#define CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE 0x11B3 +#define CL_KERNEL_PRIVATE_MEM_SIZE 0x11B4 +#define CL_KERNEL_GLOBAL_WORK_SIZE 0x11B5 + +/* cl_kernel_sub_group_info */ +#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE 0x2033 +#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE 0x2034 +#define CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT 0x11B8 + +/* cl_kernel_exec_info */ +#define CL_KERNEL_EXEC_INFO_SVM_PTRS 0x11B6 +#define CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM 0x11B7 + +/* cl_event_info */ +#define CL_EVENT_COMMAND_QUEUE 0x11D0 +#define CL_EVENT_COMMAND_TYPE 0x11D1 +#define CL_EVENT_REFERENCE_COUNT 0x11D2 +#define CL_EVENT_COMMAND_EXECUTION_STATUS 0x11D3 +#define CL_EVENT_CONTEXT 0x11D4 + +/* cl_command_type */ +#define CL_COMMAND_NDRANGE_KERNEL 0x11F0 +#define CL_COMMAND_TASK 0x11F1 +#define CL_COMMAND_NATIVE_KERNEL 0x11F2 +#define CL_COMMAND_READ_BUFFER 0x11F3 +#define CL_COMMAND_WRITE_BUFFER 0x11F4 +#define CL_COMMAND_COPY_BUFFER 0x11F5 +#define CL_COMMAND_READ_IMAGE 0x11F6 +#define CL_COMMAND_WRITE_IMAGE 0x11F7 +#define CL_COMMAND_COPY_IMAGE 0x11F8 +#define CL_COMMAND_COPY_IMAGE_TO_BUFFER 0x11F9 +#define CL_COMMAND_COPY_BUFFER_TO_IMAGE 0x11FA +#define CL_COMMAND_MAP_BUFFER 0x11FB +#define CL_COMMAND_MAP_IMAGE 0x11FC +#define CL_COMMAND_UNMAP_MEM_OBJECT 0x11FD +#define CL_COMMAND_MARKER 0x11FE +#define CL_COMMAND_ACQUIRE_GL_OBJECTS 0x11FF +#define CL_COMMAND_RELEASE_GL_OBJECTS 0x1200 +#define CL_COMMAND_READ_BUFFER_RECT 0x1201 +#define CL_COMMAND_WRITE_BUFFER_RECT 0x1202 +#define CL_COMMAND_COPY_BUFFER_RECT 0x1203 +#define CL_COMMAND_USER 0x1204 +#define CL_COMMAND_BARRIER 0x1205 +#define CL_COMMAND_MIGRATE_MEM_OBJECTS 0x1206 +#define CL_COMMAND_FILL_BUFFER 0x1207 +#define CL_COMMAND_FILL_IMAGE 0x1208 +#define CL_COMMAND_SVM_FREE 0x1209 +#define CL_COMMAND_SVM_MEMCPY 0x120A +#define CL_COMMAND_SVM_MEMFILL 0x120B +#define CL_COMMAND_SVM_MAP 0x120C +#define CL_COMMAND_SVM_UNMAP 0x120D +#define CL_COMMAND_SVM_MIGRATE_MEM 0x120E + +/* command execution status */ +#define CL_COMPLETE 0x0 +#define CL_RUNNING 0x1 +#define CL_SUBMITTED 0x2 +#define CL_QUEUED 0x3 + +/* cl_buffer_create_type */ +#define CL_BUFFER_CREATE_TYPE_REGION 0x1220 + +/* cl_profiling_info */ +#define CL_PROFILING_COMMAND_QUEUED 0x1280 +#define CL_PROFILING_COMMAND_SUBMIT 0x1281 +#define CL_PROFILING_COMMAND_START 0x1282 +#define CL_PROFILING_COMMAND_END 0x1283 +#define CL_PROFILING_COMMAND_COMPLETE 0x1284 + +/********************************************************************************************************/ + +/* Platform API */ +extern CL_API_ENTRY cl_int CL_API_CALL +clGetPlatformIDs(cl_uint /* num_entries */, + cl_platform_id * /* platforms */, + cl_uint * /* num_platforms */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetPlatformInfo(cl_platform_id /* platform */, + cl_platform_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Device APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceIDs(cl_platform_id /* platform */, + cl_device_type /* device_type */, + cl_uint /* num_entries */, + cl_device_id * /* devices */, + cl_uint * /* num_devices */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceInfo(cl_device_id /* device */, + cl_device_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clCreateSubDevices(cl_device_id /* in_device */, + const cl_device_partition_property * /* properties */, + cl_uint /* num_devices */, + cl_device_id * /* out_devices */, + cl_uint * /* num_devices_ret */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetDefaultDeviceCommandQueue(cl_context /* context */, + cl_device_id /* device */, + cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_2_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceAndHostTimer(cl_device_id /* device */, + cl_ulong* /* device_timestamp */, + cl_ulong* /* host_timestamp */) CL_API_SUFFIX__VERSION_2_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetHostTimer(cl_device_id /* device */, + cl_ulong * /* host_timestamp */) CL_API_SUFFIX__VERSION_2_1; + + +/* Context APIs */ +extern CL_API_ENTRY cl_context CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_context CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetContextInfo(cl_context /* context */, + cl_context_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Command Queue APIs */ +extern CL_API_ENTRY cl_command_queue CL_API_CALL +clCreateCommandQueueWithProperties(cl_context /* context */, + cl_device_id /* device */, + const cl_queue_properties * /* properties */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetCommandQueueInfo(cl_command_queue /* command_queue */, + cl_command_queue_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Memory Object APIs */ +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateBuffer(cl_context /* context */, + cl_mem_flags /* flags */, + size_t /* size */, + void * /* host_ptr */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateSubBuffer(cl_mem /* buffer */, + cl_mem_flags /* flags */, + cl_buffer_create_type /* buffer_create_type */, + const void * /* buffer_create_info */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_mem CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreatePipe(cl_context /* context */, + cl_mem_flags /* flags */, + cl_uint /* pipe_packet_size */, + cl_uint /* pipe_max_packets */, + const cl_pipe_properties * /* properties */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetMemObjectInfo(cl_mem /* memobj */, + cl_mem_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetImageInfo(cl_mem /* image */, + cl_image_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetPipeInfo(cl_mem /* pipe */, + cl_pipe_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_2_0; + + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetMemObjectDestructorCallback(cl_mem /* memobj */, + void (CL_CALLBACK * /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), + void * /*user_data */ ) CL_API_SUFFIX__VERSION_1_1; + +/* SVM Allocation APIs */ +extern CL_API_ENTRY void * CL_API_CALL +clSVMAlloc(cl_context /* context */, + cl_svm_mem_flags /* flags */, + size_t /* size */, + cl_uint /* alignment */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY void CL_API_CALL +clSVMFree(cl_context /* context */, + void * /* svm_pointer */) CL_API_SUFFIX__VERSION_2_0; + +/* Sampler APIs */ +extern CL_API_ENTRY cl_sampler CL_API_CALL +clCreateSamplerWithProperties(cl_context /* context */, + const cl_sampler_properties * /* normalized_coords */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetSamplerInfo(cl_sampler /* sampler */, + cl_sampler_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Program Object APIs */ +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithSource(cl_context /* context */, + cl_uint /* count */, + const char ** /* strings */, + const size_t * /* lengths */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_program CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithBuiltInKernels(cl_context /* context */, + cl_uint /* num_devices */, + const cl_device_id * /* device_list */, + const char * /* kernel_names */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithIL(cl_context /* context */, + const void* /* il */, + size_t /* length */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_2_1; + + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clCompileProgram(cl_program /* program */, + cl_uint /* num_devices */, + const cl_device_id * /* device_list */, + const char * /* options */, + cl_uint /* num_input_headers */, + const cl_program * /* input_headers */, + const char ** /* header_include_names */, + void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), + void * /* user_data */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_program CL_API_CALL +clLinkProgram(cl_context /* context */, + cl_uint /* num_devices */, + const cl_device_id * /* device_list */, + const char * /* options */, + cl_uint /* num_input_programs */, + const cl_program * /* input_programs */, + void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), + void * /* user_data */, + cl_int * /* errcode_ret */ ) CL_API_SUFFIX__VERSION_1_2; + + +extern CL_API_ENTRY cl_int CL_API_CALL +clUnloadPlatformCompiler(cl_platform_id /* platform */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetProgramInfo(cl_program /* program */, + cl_program_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +/* Kernel Object APIs */ +extern CL_API_ENTRY cl_kernel CL_API_CALL +clCreateKernel(cl_program /* program */, + const char * /* kernel_name */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clCreateKernelsInProgram(cl_program /* program */, + cl_uint /* num_kernels */, + cl_kernel * /* kernels */, + cl_uint * /* num_kernels_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_kernel CL_API_CALL +clCloneKernel(cl_kernel /* source_kernel */, + cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_2_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainKernel(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseKernel(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArg(cl_kernel /* kernel */, + cl_uint /* arg_index */, + size_t /* arg_size */, + const void * /* arg_value */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArgSVMPointer(cl_kernel /* kernel */, + cl_uint /* arg_index */, + const void * /* arg_value */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelExecInfo(cl_kernel /* kernel */, + cl_kernel_exec_info /* param_name */, + size_t /* param_value_size */, + const void * /* param_value */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetKernelInfo(cl_kernel /* kernel */, + cl_kernel_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetKernelArgInfo(cl_kernel /* kernel */, + cl_uint /* arg_indx */, + cl_kernel_arg_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetKernelSubGroupInfo(cl_kernel /* kernel */, + cl_device_id /* device */, + cl_kernel_sub_group_info /* param_name */, + size_t /* input_value_size */, + const void* /*input_value */, + size_t /* param_value_size */, + void* /* param_value */, + size_t* /* param_value_size_ret */ ) CL_API_SUFFIX__VERSION_2_1; + + +/* Event Object APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clWaitForEvents(cl_uint /* num_events */, + const cl_event * /* event_list */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetEventInfo(cl_event /* event */, + cl_event_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_event CL_API_CALL +clCreateUserEvent(cl_context /* context */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetUserEventStatus(cl_event /* event */, + cl_int /* execution_status */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetEventCallback( cl_event /* event */, + cl_int /* command_exec_callback_type */, + void (CL_CALLBACK * /* pfn_notify */)(cl_event, cl_int, void *), + void * /* user_data */) CL_API_SUFFIX__VERSION_1_1; + +/* Profiling APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clGetEventProfilingInfo(cl_event /* event */, + cl_profiling_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +/* Flush and Finish APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clFlush(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clFinish(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; + +/* Enqueued Commands APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadBufferRect(cl_command_queue /* command_queue */, + cl_mem /* buffer */, + cl_bool /* blocking_read */, + const size_t * /* buffer_offset */, + const size_t * /* host_offset */, + const size_t * /* region */, + size_t /* buffer_row_pitch */, + size_t /* buffer_slice_pitch */, + size_t /* host_row_pitch */, + size_t /* host_slice_pitch */, + void * /* ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteBufferRect(cl_command_queue /* command_queue */, + cl_mem /* buffer */, + cl_bool /* blocking_write */, + const size_t * /* buffer_offset */, + const size_t * /* host_offset */, + const size_t * /* region */, + size_t /* buffer_row_pitch */, + size_t /* buffer_slice_pitch */, + size_t /* host_row_pitch */, + size_t /* host_slice_pitch */, + const void * /* ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBuffer(cl_command_queue /* command_queue */, + cl_mem /* src_buffer */, + cl_mem /* dst_buffer */, + size_t /* src_offset */, + size_t /* dst_offset */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBufferRect(cl_command_queue /* command_queue */, + cl_mem /* src_buffer */, + cl_mem /* dst_buffer */, + const size_t * /* src_origin */, + const size_t * /* dst_origin */, + const size_t * /* region */, + size_t /* src_row_pitch */, + size_t /* src_slice_pitch */, + size_t /* dst_row_pitch */, + size_t /* dst_slice_pitch */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadImage(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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteImage(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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueFillImage(cl_command_queue /* command_queue */, + cl_mem /* image */, + const void * /* fill_color */, + const size_t * /* origin[3] */, + const size_t * /* region[3] */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyImage(cl_command_queue /* command_queue */, + cl_mem /* src_image */, + cl_mem /* dst_image */, + const size_t * /* src_origin[3] */, + const size_t * /* dst_origin[3] */, + const size_t * /* region[3] */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyImageToBuffer(cl_command_queue /* command_queue */, + cl_mem /* src_image */, + cl_mem /* dst_buffer */, + const size_t * /* src_origin[3] */, + const size_t * /* region[3] */, + size_t /* dst_offset */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBufferToImage(cl_command_queue /* command_queue */, + cl_mem /* src_buffer */, + cl_mem /* dst_image */, + size_t /* src_offset */, + const size_t * /* dst_origin[3] */, + const size_t * /* region[3] */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY void * CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY void * CL_API_CALL +clEnqueueMapImage(cl_command_queue /* command_queue */, + cl_mem /* image */, + cl_bool /* blocking_map */, + cl_map_flags /* map_flags */, + const size_t * /* origin[3] */, + const size_t * /* region[3] */, + 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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMigrateMemObjects(cl_command_queue /* command_queue */, + cl_uint /* num_mem_objects */, + const cl_mem * /* mem_objects */, + cl_mem_migration_flags /* flags */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +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 */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueNativeKernel(cl_command_queue /* command_queue */, + void (CL_CALLBACK * /*user_func*/)(void *), + void * /* args */, + size_t /* cb_args */, + cl_uint /* num_mem_objects */, + const cl_mem * /* mem_list */, + const void ** /* args_mem_loc */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMarkerWithWaitList(cl_command_queue /* command_queue */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueBarrierWithWaitList(cl_command_queue /* command_queue */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMFree(cl_command_queue /* command_queue */, + cl_uint /* num_svm_pointers */, + void *[] /* svm_pointers[] */, + void (CL_CALLBACK * /*pfn_free_func*/)(cl_command_queue /* queue */, + cl_uint /* num_svm_pointers */, + void *[] /* svm_pointers[] */, + void * /* user_data */), + void * /* user_data */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemcpy(cl_command_queue /* command_queue */, + cl_bool /* blocking_copy */, + void * /* dst_ptr */, + const void * /* src_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemFill(cl_command_queue /* command_queue */, + void * /* svm_ptr */, + const void * /* pattern */, + size_t /* pattern_size */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMap(cl_command_queue /* command_queue */, + cl_bool /* blocking_map */, + cl_map_flags /* flags */, + void * /* svm_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMUnmap(cl_command_queue /* command_queue */, + void * /* svm_ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMigrateMem(cl_command_queue /* command_queue */, + cl_uint /* num_svm_pointers */, + const void ** /* svm_pointers */, + const size_t * /* sizes */, + cl_mem_migration_flags /* flags */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_1; + + +/* Extension function access + * + * Returns the extension function address for the given function name, + * or NULL if a valid function can not be found. The client must + * check to make sure the address is not NULL, before using or + * calling the returned function address. + */ +extern CL_API_ENTRY void * CL_API_CALL +clGetExtensionFunctionAddressForPlatform(cl_platform_id /* platform */, + const char * /* func_name */) CL_API_SUFFIX__VERSION_1_2; + + +/* Deprecated OpenCL 1.1 APIs */ +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateImage2D(cl_context /* context */, + cl_mem_flags /* flags */, + const cl_image_format * /* image_format */, + size_t /* image_width */, + size_t /* image_height */, + size_t /* image_row_pitch */, + void * /* host_ptr */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateImage3D(cl_context /* context */, + cl_mem_flags /* flags */, + const cl_image_format * /* image_format */, + size_t /* image_width */, + size_t /* image_height */, + size_t /* image_depth */, + size_t /* image_row_pitch */, + size_t /* image_slice_pitch */, + void * /* host_ptr */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clEnqueueMarker(cl_command_queue /* command_queue */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clEnqueueWaitForEvents(cl_command_queue /* command_queue */, + cl_uint /* num_events */, + const cl_event * /* event_list */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clEnqueueBarrier(cl_command_queue /* command_queue */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clUnloadCompiler(void) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED void * CL_API_CALL +clGetExtensionFunctionAddress(const char * /* func_name */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +/* Deprecated OpenCL 2.0 APIs */ +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_command_queue CL_API_CALL +clCreateCommandQueue(cl_context /* context */, + cl_device_id /* device */, + cl_command_queue_properties /* properties */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; + + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_sampler CL_API_CALL +clCreateSampler(cl_context /* context */, + cl_bool /* normalized_coords */, + cl_addressing_mode /* addressing_mode */, + cl_filter_mode /* filter_mode */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int CL_API_CALL +clEnqueueTask(cl_command_queue /* command_queue */, + cl_kernel /* kernel */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_H */ + diff --git a/opencl/khronos/headers/opencl2.1/CL/cl.hpp b/opencl/khronos/headers/opencl2.1/CL/cl.hpp new file mode 100644 index 0000000000..3ea724593b --- /dev/null +++ b/opencl/khronos/headers/opencl2.1/CL/cl.hpp @@ -0,0 +1,12960 @@ +/* Modifications Copyright(C)[2021-2022] Advanced Micro Devices, Inc. + * All rights reserved. + * */ + +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +/*! \file + * + * \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33) and + * OpenCL 1.2 (rev 15) + * \author Benedict R. Gaster, Laurent Morichetti and Lee Howes + * + * Additions and fixes from: + * Brian Cole, March 3rd 2010 and April 2012 + * Matt Gruenke, April 2012. + * Bruce Merry, February 2013. + * Tom Deakin and Simon McIntosh-Smith, July 2013 + * + * \version 1.2.9 + * \date December 2015 + * + * Optional extension support + * + * cl + * cl_ext_device_fission + * #define USE_CL_DEVICE_FISSION + */ + +/*! \mainpage + * \section intro Introduction + * For many large applications C++ is the language of choice and so it seems + * reasonable to define C++ bindings for OpenCL. + * + * + * The interface is contained with a single C++ header file \em cl.hpp and all + * definitions are contained within the namespace \em cl. There is no additional + * requirement to include \em cl.h and to use either the C++ or original C + * bindings it is enough to simply include \em cl.hpp. + * + * The bindings themselves are lightweight and correspond closely to the + * underlying C API. Using the C++ bindings introduces no additional execution + * overhead. + * + * For detail documentation on the bindings see: + * + * The OpenCL C++ Wrapper API 1.2 (revision 09) + * http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.2.pdf + * + * \section example Example + * + * The following example shows a general use case for the C++ + * bindings, including support for the optional exception feature and + * also the supplied vector and string classes, see following sections for + * decriptions of these features. + * + * \code + * #define __CL_ENABLE_EXCEPTIONS + * + * #if defined(__APPLE__) || defined(__MACOSX) + * #include + * #else + * #include + * #endif + * #include + * #include + * #include + * + * const char * helloStr = "__kernel void " + * "hello(void) " + * "{ " + * " " + * "} "; + * + * int + * main(void) + * { + * cl_int err = CL_SUCCESS; + * try { + * + * std::vector platforms; + * cl::Platform::get(&platforms); + * if (platforms.size() == 0) { + * std::cout << "Platform size 0\n"; + * return -1; + * } + * + * cl_context_properties properties[] = + * { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0}; + * cl::Context context(CL_DEVICE_TYPE_CPU, properties); + * + * std::vector devices = context.getInfo(); + * + * cl::Program::Sources source(1, + * std::make_pair(helloStr,strlen(helloStr))); + * cl::Program program_ = cl::Program(context, source); + * program_.build(devices); + * + * cl::Kernel kernel(program_, "hello", &err); + * + * cl::Event event; + * cl::CommandQueue queue(context, devices[0], 0, &err); + * queue.enqueueNDRangeKernel( + * kernel, + * cl::NullRange, + * cl::NDRange(4,4), + * cl::NullRange, + * NULL, + * &event); + * + * event.wait(); + * } + * catch (cl::Error err) { + * std::cerr + * << "ERROR: " + * << err.what() + * << "(" + * << err.err() + * << ")" + * << std::endl; + * } + * + * return EXIT_SUCCESS; + * } + * + * \endcode + * + */ +#ifndef CL_HPP_ +#define CL_HPP_ + +#ifdef _WIN32 + +#include + +#if defined(USE_DX_INTEROP) +#include +#include +#endif +#endif // _WIN32 + +#if defined(_MSC_VER) +#include +#endif // _MSC_VER + +// +#if defined(USE_CL_DEVICE_FISSION) +#include +#endif + +#if defined(__APPLE__) || defined(__MACOSX) +#include +#else +#include +#endif // !__APPLE__ + +#if (_MSC_VER >= 1700) || (__cplusplus >= 201103L) +#define CL_HPP_RVALUE_REFERENCES_SUPPORTED +#define CL_HPP_CPP11_ATOMICS_SUPPORTED +#include +#endif + +#if (__cplusplus >= 201103L) +#define CL_HPP_NOEXCEPT noexcept +#else +#define CL_HPP_NOEXCEPT +#endif + + +// To avoid accidentally taking ownership of core OpenCL types +// such as cl_kernel constructors are made explicit +// under OpenCL 1.2 +#if defined(CL_VERSION_1_2) && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +#define __CL_EXPLICIT_CONSTRUCTORS explicit +#else // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +#define __CL_EXPLICIT_CONSTRUCTORS +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +// Define deprecated prefixes and suffixes to ensure compilation +// in case they are not pre-defined +#if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) + +#if !defined(CL_CALLBACK) +#define CL_CALLBACK +#endif //CL_CALLBACK + +#include +#include +#include + +#if defined(__CL_ENABLE_EXCEPTIONS) +#include +#endif // #if defined(__CL_ENABLE_EXCEPTIONS) + +#if !defined(__NO_STD_VECTOR) +#include +#endif + +#if !defined(__NO_STD_STRING) +#include +#endif + +#if defined(__ANDROID__) || defined(linux) || defined(__APPLE__) || defined(__MACOSX) +#include +#endif // linux + +#include + + +/*! \namespace cl + * + * \brief The OpenCL C++ bindings are defined within this namespace. + * + */ +namespace cl { + +class Memory; + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) +#define __INIT_CL_EXT_FCN_PTR(name) \ + if(!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddress(#name); \ + if(!pfn_##name) { \ + } \ + } +#endif // #if defined(CL_VERSION_1_1) + +#if defined(CL_VERSION_1_2) +#define __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, name) \ + if(!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddressForPlatform(platform, #name); \ + if(!pfn_##name) { \ + } \ + } +#endif // #if defined(CL_VERSION_1_1) + +class Program; +class Device; +class Context; +class CommandQueue; +class Memory; +class Buffer; + +#if defined(__CL_ENABLE_EXCEPTIONS) +/*! \brief Exception class + * + * This may be thrown by API functions when __CL_ENABLE_EXCEPTIONS is defined. + */ +class Error : public std::exception +{ +private: + cl_int err_; + const char * errStr_; +public: + /*! \brief Create a new CL error exception for a given error code + * and corresponding message. + * + * \param err error code value. + * + * \param errStr a descriptive string that must remain in scope until + * handling of the exception has concluded. If set, it + * will be returned by what(). + */ + Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr) + {} + + ~Error() throw() {} + + /*! \brief Get error string associated with exception + * + * \return A memory pointer to the error message string. + */ + virtual const char * what() const throw () + { + if (errStr_ == NULL) { + return "empty"; + } + else { + return errStr_; + } + } + + /*! \brief Get error code associated with exception + * + * \return The error code. + */ + cl_int err(void) const { return err_; } +}; + +#define __ERR_STR(x) #x +#else +#define __ERR_STR(x) NULL +#endif // __CL_ENABLE_EXCEPTIONS + + +namespace detail +{ +#if defined(__CL_ENABLE_EXCEPTIONS) +static inline cl_int errHandler ( + cl_int err, + const char * errStr = NULL) +{ + if (err != CL_SUCCESS) { + throw Error(err, errStr); + } + return err; +} +#else +static inline cl_int errHandler (cl_int err, const char * errStr = NULL) +{ + (void) errStr; // suppress unused variable warning + return err; +} +#endif // __CL_ENABLE_EXCEPTIONS +} + + + +//! \cond DOXYGEN_DETAIL +#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS) +#define __GET_DEVICE_INFO_ERR __ERR_STR(clGetDeviceInfo) +#define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo) +#define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs) +#define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs) +#define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo) +#define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo) +#define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo) +#define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo) +#define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo) +#define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo) +#define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo) +#if defined(CL_VERSION_1_2) +#define __GET_KERNEL_ARG_INFO_ERR __ERR_STR(clGetKernelArgInfo) +#endif // #if defined(CL_VERSION_1_2) +#define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo) +#define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo) +#define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo) +#define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo) + +#define __CREATE_CONTEXT_ERR __ERR_STR(clCreateContext) +#define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType) +#define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats) + +#define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer) +#define __COPY_ERR __ERR_STR(cl::copy) +#define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer) +#define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer) +#define __CREATE_GL_RENDER_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer) +#define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo) +#if defined(CL_VERSION_1_2) +#define __CREATE_IMAGE_ERR __ERR_STR(clCreateImage) +#define __CREATE_GL_TEXTURE_ERR __ERR_STR(clCreateFromGLTexture) +#define __IMAGE_DIMENSION_ERR __ERR_STR(Incorrect image dimensions) +#endif // #if defined(CL_VERSION_1_2) +#define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler) +#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback) + +#define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent) +#define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus) +#define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback) +#define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents) + +#define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel) +#define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg) +#define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource) +#define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary) +#if defined(CL_VERSION_1_2) +#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR __ERR_STR(clCreateProgramWithBuiltInKernels) +#endif // #if defined(CL_VERSION_1_2) +#define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram) +#if defined(CL_VERSION_1_2) +#define __COMPILE_PROGRAM_ERR __ERR_STR(clCompileProgram) +#define __LINK_PROGRAM_ERR __ERR_STR(clLinkProgram) +#endif // #if defined(CL_VERSION_1_2) +#define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram) + +#define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue) +#define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty) +#define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer) +#define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect) +#define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer) +#define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect) +#define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer) +#define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect) +#define __ENQUEUE_FILL_BUFFER_ERR __ERR_STR(clEnqueueFillBuffer) +#define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage) +#define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage) +#define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage) +#define __ENQUEUE_FILL_IMAGE_ERR __ERR_STR(clEnqueueFillImage) +#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer) +#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage) +#define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer) +#define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage) +#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject) +#define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel) +#define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask) +#define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel) +#if defined(CL_VERSION_1_2) +#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR __ERR_STR(clEnqueueMigrateMemObjects) +#endif // #if defined(CL_VERSION_1_2) + +#define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects) +#define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects) + + +#define __RETAIN_ERR __ERR_STR(Retain Object) +#define __RELEASE_ERR __ERR_STR(Release Object) +#define __FLUSH_ERR __ERR_STR(clFlush) +#define __FINISH_ERR __ERR_STR(clFinish) +#define __VECTOR_CAPACITY_ERR __ERR_STR(Vector capacity error) + +/** + * CL 1.2 version that uses device fission. + */ +#if defined(CL_VERSION_1_2) +#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevices) +#else +#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT) +#endif // #if defined(CL_VERSION_1_2) + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) +#define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker) +#define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents) +#define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier) +#define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler) +#define __CREATE_GL_TEXTURE_2D_ERR __ERR_STR(clCreateFromGLTexture2D) +#define __CREATE_GL_TEXTURE_3D_ERR __ERR_STR(clCreateFromGLTexture3D) +#define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D) +#define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D) +#endif // #if defined(CL_VERSION_1_1) + +#endif // __CL_USER_OVERRIDE_ERROR_STRINGS +//! \endcond + +/** + * CL 1.2 marker and barrier commands + */ +#if defined(CL_VERSION_1_2) +#define __ENQUEUE_MARKER_WAIT_LIST_ERR __ERR_STR(clEnqueueMarkerWithWaitList) +#define __ENQUEUE_BARRIER_WAIT_LIST_ERR __ERR_STR(clEnqueueBarrierWithWaitList) +#endif // #if defined(CL_VERSION_1_2) + +#if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING) +typedef std::string STRING_CLASS; +#elif !defined(__USE_DEV_STRING) + +/*! \class string + * \brief Simple string class, that provides a limited subset of std::string + * functionality but avoids many of the issues that come with that class. + + * \note Deprecated. Please use std::string as default or + * re-define the string class to match the std::string + * interface by defining STRING_CLASS + */ +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED string +{ +private: + ::size_t size_; + char * str_; +public: + //! \brief Constructs an empty string, allocating no memory. + string(void) : size_(0), str_(NULL) + { + } + + /*! \brief Constructs a string populated from an arbitrary value of + * specified size. + * + * An extra '\0' is added, in case none was contained in str. + * + * \param str the initial value of the string instance. Note that '\0' + * characters receive no special treatment. If NULL, + * the string is left empty, with a size of 0. + * + * \param size the number of characters to copy from str. + */ + string(const char * str, ::size_t size) : + size_(size), + str_(NULL) + { + if( size > 0 ) { + str_ = new char[size_+1]; + if (str_ != NULL) { + memcpy(str_, str, size_ * sizeof(char)); + str_[size_] = '\0'; + } + else { + size_ = 0; + } + } + } + + /*! \brief Constructs a string populated from a null-terminated value. + * + * \param str the null-terminated initial value of the string instance. + * If NULL, the string is left empty, with a size of 0. + */ + string(const char * str) : + size_(0), + str_(NULL) + { + if( str ) { + size_= ::strlen(str); + } + if( size_ > 0 ) { + str_ = new char[size_ + 1]; + if (str_ != NULL) { + memcpy(str_, str, (size_ + 1) * sizeof(char)); + } + } + } + + void resize( ::size_t n ) + { + if( size_ == n ) { + return; + } + if (n == 0) { + if( str_ ) { + delete [] str_; + } + str_ = NULL; + size_ = 0; + } + else { + char *newString = new char[n + 1]; + ::size_t copySize = n; + if( size_ < n ) { + copySize = size_; + } + size_ = n; + + if(str_) { + memcpy(newString, str_, (copySize + 1) * sizeof(char)); + } + if( copySize < size_ ) { + memset(newString + copySize, 0, size_ - copySize); + } + newString[size_] = '\0'; + + delete [] str_; + str_ = newString; + } + } + + const char& operator[] ( ::size_t pos ) const + { + return str_[pos]; + } + + char& operator[] ( ::size_t pos ) + { + return str_[pos]; + } + + /*! \brief Copies the value of another string to this one. + * + * \param rhs the string to copy. + * + * \returns a reference to the modified instance. + */ + string& operator=(const string& rhs) + { + if (this == &rhs) { + return *this; + } + + if( str_ != NULL ) { + delete [] str_; + str_ = NULL; + size_ = 0; + } + + if (rhs.size_ == 0 || rhs.str_ == NULL) { + str_ = NULL; + size_ = 0; + } + else { + str_ = new char[rhs.size_ + 1]; + size_ = rhs.size_; + + if (str_ != NULL) { + memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char)); + } + else { + size_ = 0; + } + } + + return *this; + } + + /*! \brief Constructs a string by copying the value of another instance. + * + * \param rhs the string to copy. + */ + string(const string& rhs) : + size_(0), + str_(NULL) + { + *this = rhs; + } + + //! \brief Destructor - frees memory used to hold the current value. + ~string() + { + delete[] str_; + str_ = NULL; + } + + //! \brief Queries the length of the string, excluding any added '\0's. + ::size_t size(void) const { return size_; } + + //! \brief Queries the length of the string, excluding any added '\0's. + ::size_t length(void) const { return size(); } + + /*! \brief Returns a pointer to the private copy held by this instance, + * or "" if empty/unset. + */ + const char * c_str(void) const { return (str_) ? str_ : "";} +} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +typedef cl::string STRING_CLASS; +#endif // #elif !defined(__USE_DEV_STRING) + +#if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR) +#define VECTOR_CLASS std::vector +#elif !defined(__USE_DEV_VECTOR) +#define VECTOR_CLASS cl::vector + +#if !defined(__MAX_DEFAULT_VECTOR_SIZE) +#define __MAX_DEFAULT_VECTOR_SIZE 10 +#endif + +/*! \class vector + * \brief Fixed sized vector implementation that mirroring + * + * \note Deprecated. Please use std::vector as default or + * re-define the vector class to match the std::vector + * interface by defining VECTOR_CLASS + + * \note Not recommended for use with custom objects as + * current implementation will construct N elements + * + * std::vector functionality. + * \brief Fixed sized vector compatible with std::vector. + * + * \note + * This differs from std::vector<> not just in memory allocation, + * but also in terms of when members are constructed, destroyed, + * and assigned instead of being copy constructed. + * + * \param T type of element contained in the vector. + * + * \param N maximum size of the vector. + */ +template +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED vector +{ +private: + T data_[N]; + unsigned int size_; + +public: + //! \brief Constructs an empty vector with no memory allocated. + vector() : + size_(static_cast(0)) + {} + + //! \brief Deallocates the vector's memory and destroys all of its elements. + ~vector() + { + clear(); + } + + //! \brief Returns the number of elements currently contained. + unsigned int size(void) const + { + return size_; + } + + /*! \brief Empties the vector of all elements. + * \note + * This does not deallocate memory but will invoke destructors + * on contained elements. + */ + void clear() + { + while(!empty()) { + pop_back(); + } + } + + /*! \brief Appends an element after the last valid element. + * Calling this on a vector that has reached capacity will throw an + * exception if exceptions are enabled. + */ + void push_back (const T& x) + { + if (size() < N) { + new (&data_[size_]) T(x); + size_++; + } else { + detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); + } + } + + /*! \brief Removes the last valid element from the vector. + * Calling this on an empty vector will throw an exception + * if exceptions are enabled. + */ + void pop_back(void) + { + if (size_ != 0) { + --size_; + data_[size_].~T(); + } else { + detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); + } + } + + /*! \brief Constructs with a value copied from another. + * + * \param vec the vector to copy. + */ + vector(const vector& vec) : + size_(vec.size_) + { + if (size_ != 0) { + assign(vec.begin(), vec.end()); + } + } + + /*! \brief Constructs with a specified number of initial elements. + * + * \param size number of initial elements. + * + * \param val value of initial elements. + */ + vector(unsigned int size, const T& val = T()) : + size_(0) + { + for (unsigned int i = 0; i < size; i++) { + push_back(val); + } + } + + /*! \brief Overwrites the current content with that copied from another + * instance. + * + * \param rhs vector to copy. + * + * \returns a reference to this. + */ + vector& operator=(const vector& rhs) + { + if (this == &rhs) { + return *this; + } + + if (rhs.size_ != 0) { + assign(rhs.begin(), rhs.end()); + } else { + clear(); + } + + return *this; + } + + /*! \brief Tests equality against another instance. + * + * \param vec the vector against which to compare. + */ + bool operator==(vector &vec) + { + if (size() != vec.size()) { + return false; + } + + for( unsigned int i = 0; i < size(); ++i ) { + if( operator[](i) != vec[i] ) { + return false; + } + } + return true; + } + + //! \brief Conversion operator to T*. + operator T* () { return data_; } + + //! \brief Conversion operator to const T*. + operator const T* () const { return data_; } + + //! \brief Tests whether this instance has any elements. + bool empty (void) const + { + return size_==0; + } + + //! \brief Returns the maximum number of elements this instance can hold. + unsigned int max_size (void) const + { + return N; + } + + //! \brief Returns the maximum number of elements this instance can hold. + unsigned int capacity () const + { + return N; + } + + //! \brief Resizes the vector to the given size + void resize(unsigned int newSize, T fill = T()) + { + if (newSize > N) + { + detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); + } + else + { + while (size_ < newSize) + { + new (&data_[size_]) T(fill); + size_++; + } + while (size_ > newSize) + { + --size_; + data_[size_].~T(); + } + } + } + + /*! \brief Returns a reference to a given element. + * + * \param index which element to access. * + * \note + * The caller is responsible for ensuring index is >= 0 and < size(). + */ + T& operator[](int index) + { + return data_[index]; + } + + /*! \brief Returns a const reference to a given element. + * + * \param index which element to access. + * + * \note + * The caller is responsible for ensuring index is >= 0 and < size(). + */ + const T& operator[](int index) const + { + return data_[index]; + } + + /*! \brief Assigns elements of the vector based on a source iterator range. + * + * \param start Beginning iterator of source range + * \param end Enditerator of source range + * + * \note + * Will throw an exception if exceptions are enabled and size exceeded. + */ + template + void assign(I start, I end) + { + clear(); + while(start != end) { + push_back(*start); + start++; + } + } + + /*! \class iterator + * \brief Const iterator class for vectors + */ + class iterator + { + private: + const vector *vec_; + int index_; + + /** + * Internal iterator constructor to capture reference + * to the vector it iterates over rather than taking + * the vector by copy. + */ + iterator (const vector &vec, int index) : + vec_(&vec) + { + if( !vec.empty() ) { + index_ = index; + } else { + index_ = -1; + } + } + + public: + iterator(void) : + index_(-1), + vec_(NULL) + { + } + + iterator(const iterator& rhs) : + vec_(rhs.vec_), + index_(rhs.index_) + { + } + + ~iterator(void) {} + + static iterator begin(const cl::vector &vec) + { + iterator i(vec, 0); + + return i; + } + + static iterator end(const cl::vector &vec) + { + iterator i(vec, vec.size()); + + return i; + } + + bool operator==(iterator i) + { + return ((vec_ == i.vec_) && + (index_ == i.index_)); + } + + bool operator!=(iterator i) + { + return (!(*this==i)); + } + + iterator& operator++() + { + ++index_; + return *this; + } + + iterator operator++(int) + { + iterator retVal(*this); + ++index_; + return retVal; + } + + iterator& operator--() + { + --index_; + return *this; + } + + iterator operator--(int) + { + iterator retVal(*this); + --index_; + return retVal; + } + + const T& operator *() const + { + return (*vec_)[index_]; + } + }; + + iterator begin(void) + { + return iterator::begin(*this); + } + + iterator begin(void) const + { + return iterator::begin(*this); + } + + iterator end(void) + { + return iterator::end(*this); + } + + iterator end(void) const + { + return iterator::end(*this); + } + + T& front(void) + { + return data_[0]; + } + + T& back(void) + { + return data_[size_]; + } + + const T& front(void) const + { + return data_[0]; + } + + const T& back(void) const + { + return data_[size_-1]; + } +} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +#endif // #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR) + + + + + +namespace detail { +#define __DEFAULT_NOT_INITIALIZED 1 +#define __DEFAULT_BEING_INITIALIZED 2 +#define __DEFAULT_INITIALIZED 4 + + /* + * Compare and exchange primitives are needed for handling of defaults + */ + +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + inline int compare_exchange(std::atomic * dest, int exchange, int comparand) +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED + inline int compare_exchange(volatile int * dest, int exchange, int comparand) +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + { +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + std::atomic_compare_exchange_strong(dest, &comparand, exchange); + return comparand; +#elif _MSC_VER + return (int)(_InterlockedCompareExchange( + (volatile long*)dest, + (long)exchange, + (long)comparand)); +#else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED + return (__sync_val_compare_and_swap( + dest, + comparand, + exchange)); +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + } + + inline void fence() { +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + std::atomic_thread_fence(std::memory_order_seq_cst); +#elif _MSC_VER // !CL_HPP_CPP11_ATOMICS_SUPPORTED + _ReadWriteBarrier(); +#else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED + __sync_synchronize(); +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + } +} // namespace detail + + +/*! \brief class used to interface between C++ and + * OpenCL C calls that require arrays of size_t values, whose + * size is known statically. + */ +template +class size_t +{ +private: + ::size_t data_[N]; + +public: + //! \brief Initialize size_t to all 0s + size_t() + { + for( int i = 0; i < N; ++i ) { + data_[i] = 0; + } + } + + ::size_t& operator[](int index) + { + return data_[index]; + } + + const ::size_t& operator[](int index) const + { + return data_[index]; + } + + //! \brief Conversion operator to T*. + operator ::size_t* () { return data_; } + + //! \brief Conversion operator to const T*. + operator const ::size_t* () const { return data_; } +}; + +namespace detail { + +// Generic getInfoHelper. The final parameter is used to guide overload +// resolution: the actual parameter passed is an int, which makes this +// a worse conversion sequence than a specialization that declares the +// parameter as an int. +template +inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long) +{ + return f(name, sizeof(T), param, NULL); +} + +// Specialized getInfoHelper for VECTOR_CLASS params +template +inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, long) +{ + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + T* value = (T*) alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + param->assign(&value[0], &value[required/sizeof(T)]); + return CL_SUCCESS; +} + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, int, typename T::cl_type = 0) +{ + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + typename T::cl_type * value = (typename T::cl_type *) alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + ::size_t elements = required / sizeof(typename T::cl_type); + param->assign(&value[0], &value[elements]); + for (::size_t i = 0; i < elements; i++) + { + if (value[i] != NULL) + { + err = (*param)[i].retain(); + if (err != CL_SUCCESS) { + return err; + } + } + } + return CL_SUCCESS; +} + +// Specialized for getInfo +template +inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, int) +{ + cl_int err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL); + + if (err != CL_SUCCESS) { + return err; + } + + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for STRING_CLASS params +template +inline cl_int getInfoHelper(Func f, cl_uint name, STRING_CLASS* param, long) +{ +#if defined(__NO_STD_VECTOR) || defined(__NO_STD_STRING) + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + char* value = (char*)alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + *param = value; + return CL_SUCCESS; +#else + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + // std::string has a constant data member + // a char vector does not + VECTOR_CLASS value(required); + err = f(name, required, value.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + if (param) { + param->assign(value.begin(), value.end()); + } +#endif + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for cl::size_t params +template +inline cl_int getInfoHelper(Func f, cl_uint name, size_t* param, long) +{ + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + ::size_t* value = (::size_t*) alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + for(int i = 0; i < N; ++i) { + (*param)[i] = value[i]; + } + + return CL_SUCCESS; +} + +template struct ReferenceHandler; + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0) +{ + typename T::cl_type value; + cl_int err = f(name, sizeof(value), &value, NULL); + if (err != CL_SUCCESS) { + return err; + } + *param = value; + if (value != NULL) + { + err = param->retain(); + if (err != CL_SUCCESS) { + return err; + } + } + return CL_SUCCESS; +} + +#define __PARAM_NAME_INFO_1_0(F) \ + F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \ + \ + F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \ + F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \ + F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \ + F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \ + F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \ + F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \ + F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \ + F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \ + F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \ + F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \ + \ + F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \ + F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS) \ + F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS) \ + \ + F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \ + F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \ + F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \ + F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \ + \ + F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \ + \ + F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \ + F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \ + F(cl_mem_info, CL_MEM_SIZE, ::size_t) \ + F(cl_mem_info, CL_MEM_HOST_PTR, void*) \ + F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \ + \ + F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \ + F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \ + F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \ + F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \ + F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \ + F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \ + F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \ + \ + F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \ + F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \ + F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \ + F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \ + F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \ + \ + F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \ + F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \ + F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \ + F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS) \ + F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \ + F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \ + F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS) \ + \ + F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \ + \ + F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \ + F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \ + F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \ + F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \ + F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \ + \ + F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \ + F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \ + F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \ + F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties) + +#if defined(CL_VERSION_1_1) +#define __PARAM_NAME_INFO_1_1(F) \ + F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \ + F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, STRING_CLASS) \ + \ + F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \ + F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \ + F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \ + \ + F(cl_event_info, CL_EVENT_CONTEXT, cl::Context) +#endif // CL_VERSION_1_1 + + +#if defined(CL_VERSION_1_2) +#define __PARAM_NAME_INFO_1_2(F) \ + F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer) \ + \ + F(cl_program_info, CL_PROGRAM_NUM_KERNELS, ::size_t) \ + F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, STRING_CLASS) \ + \ + F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \ + \ + F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, STRING_CLASS) \ + \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, STRING_CLASS) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, STRING_CLASS) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \ + \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl_device_id) \ + F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPE, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, ::size_t) \ + F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \ + F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, STRING_CLASS) +#endif // #if defined(CL_VERSION_1_2) + +#if defined(USE_CL_DEVICE_FISSION) +#define __PARAM_NAME_DEVICE_FISSION(F) \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \ + F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS) +#endif // USE_CL_DEVICE_FISSION + +template +struct param_traits {}; + +#define __CL_DECLARE_PARAM_TRAITS(token, param_name, T) \ +struct token; \ +template<> \ +struct param_traits \ +{ \ + enum { value = param_name }; \ + typedef T param_type; \ +}; + +__PARAM_NAME_INFO_1_0(__CL_DECLARE_PARAM_TRAITS) +#if defined(CL_VERSION_1_1) +__PARAM_NAME_INFO_1_1(__CL_DECLARE_PARAM_TRAITS) +#endif // CL_VERSION_1_1 +#if defined(CL_VERSION_1_2) +__PARAM_NAME_INFO_1_2(__CL_DECLARE_PARAM_TRAITS) +#endif // CL_VERSION_1_1 + +#if defined(USE_CL_DEVICE_FISSION) +__PARAM_NAME_DEVICE_FISSION(__CL_DECLARE_PARAM_TRAITS); +#endif // USE_CL_DEVICE_FISSION + +#ifdef CL_PLATFORM_ICD_SUFFIX_KHR +__CL_DECLARE_PARAM_TRAITS(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, STRING_CLASS) +#endif + +#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong) +#endif + +#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, VECTOR_CLASS< ::size_t>) +#endif +#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD, ::size_t) +#endif +#ifdef CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD, ::size_t) +#endif +#ifdef CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD, ::size_t) +#endif + +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint) +#endif +#ifdef CL_DEVICE_WARP_SIZE_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint) +#endif +#ifdef CL_DEVICE_GPU_OVERLAP_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool) +#endif +#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool) +#endif +#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool) +#endif + +// Convenience functions + +template +inline cl_int +getInfo(Func f, cl_uint name, T* param) +{ + return getInfoHelper(f, name, param, 0); +} + +template +struct GetInfoFunctor0 +{ + Func f_; const Arg0& arg0_; + cl_int operator ()( + cl_uint param, ::size_t size, void* value, ::size_t* size_ret) + { return f_(arg0_, param, size, value, size_ret); } +}; + +template +struct GetInfoFunctor1 +{ + Func f_; const Arg0& arg0_; const Arg1& arg1_; + cl_int operator ()( + cl_uint param, ::size_t size, void* value, ::size_t* size_ret) + { return f_(arg0_, arg1_, param, size, value, size_ret); } +}; + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, cl_uint name, T* param) +{ + GetInfoFunctor0 f0 = { f, arg0 }; + return getInfoHelper(f0, name, param, 0); +} + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param) +{ + GetInfoFunctor1 f0 = { f, arg0, arg1 }; + return getInfoHelper(f0, name, param, 0); +} + +template +struct ReferenceHandler +{ }; + +#if defined(CL_VERSION_1_2) +/** + * OpenCL 1.2 devices do have retain/release. + */ +template <> +struct ReferenceHandler +{ + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int retain(cl_device_id device) + { return ::clRetainDevice(device); } + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int release(cl_device_id device) + { return ::clReleaseDevice(device); } +}; +#else // #if defined(CL_VERSION_1_2) +/** + * OpenCL 1.1 devices do not have retain/release. + */ +template <> +struct ReferenceHandler +{ + // cl_device_id does not have retain(). + static cl_int retain(cl_device_id) + { return CL_SUCCESS; } + // cl_device_id does not have release(). + static cl_int release(cl_device_id) + { return CL_SUCCESS; } +}; +#endif // #if defined(CL_VERSION_1_2) + +template <> +struct ReferenceHandler +{ + // cl_platform_id does not have retain(). + static cl_int retain(cl_platform_id) + { return CL_SUCCESS; } + // cl_platform_id does not have release(). + static cl_int release(cl_platform_id) + { return CL_SUCCESS; } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_context context) + { return ::clRetainContext(context); } + static cl_int release(cl_context context) + { return ::clReleaseContext(context); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_command_queue queue) + { return ::clRetainCommandQueue(queue); } + static cl_int release(cl_command_queue queue) + { return ::clReleaseCommandQueue(queue); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_mem memory) + { return ::clRetainMemObject(memory); } + static cl_int release(cl_mem memory) + { return ::clReleaseMemObject(memory); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_sampler sampler) + { return ::clRetainSampler(sampler); } + static cl_int release(cl_sampler sampler) + { return ::clReleaseSampler(sampler); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_program program) + { return ::clRetainProgram(program); } + static cl_int release(cl_program program) + { return ::clReleaseProgram(program); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_kernel kernel) + { return ::clRetainKernel(kernel); } + static cl_int release(cl_kernel kernel) + { return ::clReleaseKernel(kernel); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_event event) + { return ::clRetainEvent(event); } + static cl_int release(cl_event event) + { return ::clReleaseEvent(event); } +}; + + +// Extracts version number with major in the upper 16 bits, minor in the lower 16 +static cl_uint getVersion(const char *versionInfo) +{ + int highVersion = 0; + int lowVersion = 0; + int index = 7; + while(versionInfo[index] != '.' ) { + highVersion *= 10; + highVersion += versionInfo[index]-'0'; + ++index; + } + ++index; + while(versionInfo[index] != ' ' && versionInfo[index] != '\0') { + lowVersion *= 10; + lowVersion += versionInfo[index]-'0'; + ++index; + } + return (highVersion << 16) | lowVersion; +} + +static cl_uint getPlatformVersion(cl_platform_id platform) +{ + ::size_t size = 0; + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size); + char *versionInfo = (char *) alloca(size); + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, &versionInfo[0], &size); + return getVersion(versionInfo); +} + +static cl_uint getDevicePlatformVersion(cl_device_id device) +{ + cl_platform_id platform; + clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL); + return getPlatformVersion(platform); +} + +#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +static cl_uint getContextPlatformVersion(cl_context context) +{ + // The platform cannot be queried directly, so we first have to grab a + // device and obtain its context + ::size_t size = 0; + clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size); + if (size == 0) + return 0; + cl_device_id *devices = (cl_device_id *) alloca(size); + clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices, NULL); + return getDevicePlatformVersion(devices[0]); +} +#endif // #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +template +class Wrapper +{ +public: + typedef T cl_type; + +protected: + cl_type object_; + +public: + Wrapper() : object_(NULL) { } + + Wrapper(const cl_type &obj) : object_(obj) { } + + ~Wrapper() + { + if (object_ != NULL) { release(); } + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT + { + object_ = rhs.object_; + rhs.object_ = NULL; + } +#endif + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + rhs.object_ = NULL; + } + return *this; + } +#endif + + Wrapper& operator = (const cl_type &rhs) + { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs; + return *this; + } + + cl_type operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + cl_int retain() const + { + return ReferenceHandler::retain(object_); + } + + cl_int release() const + { + return ReferenceHandler::release(object_); + } +}; + +template <> +class Wrapper +{ +public: + typedef cl_device_id cl_type; + +protected: + cl_type object_; + bool referenceCountable_; + + static bool isReferenceCountable(cl_device_id device) + { + bool retVal = false; + if (device != NULL) { + int version = getDevicePlatformVersion(device); + if(version > ((1 << 16) + 1)) { + retVal = true; + } + } + return retVal; + } + +public: + Wrapper() : object_(NULL), referenceCountable_(false) + { + } + + Wrapper(const cl_type &obj) : object_(obj), referenceCountable_(false) + { + referenceCountable_ = isReferenceCountable(obj); + } + + ~Wrapper() + { + if (object_ != NULL) { release(); } + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + referenceCountable_ = isReferenceCountable(object_); + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT + { + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } +#endif + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } + return *this; + } +#endif + + Wrapper& operator = (const cl_type &rhs) + { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs; + referenceCountable_ = isReferenceCountable(object_); + return *this; + } + + cl_type operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + template + friend inline cl_int getInfoHelper(Func, cl_uint, VECTOR_CLASS*, int, typename U::cl_type); + + cl_int retain() const + { + if( referenceCountable_ ) { + return ReferenceHandler::retain(object_); + } + else { + return CL_SUCCESS; + } + } + + cl_int release() const + { + if( referenceCountable_ ) { + return ReferenceHandler::release(object_); + } + else { + return CL_SUCCESS; + } + } +}; + +} // namespace detail +//! \endcond + +/*! \stuct ImageFormat + * \brief Adds constructors and member functions for cl_image_format. + * + * \see cl_image_format + */ +struct ImageFormat : public cl_image_format +{ + //! \brief Default constructor - performs no initialization. + ImageFormat(){} + + //! \brief Initializing constructor. + ImageFormat(cl_channel_order order, cl_channel_type type) + { + image_channel_order = order; + image_channel_data_type = type; + } + + //! \brief Assignment operator. + ImageFormat& operator = (const ImageFormat& rhs) + { + if (this != &rhs) { + this->image_channel_data_type = rhs.image_channel_data_type; + this->image_channel_order = rhs.image_channel_order; + } + return *this; + } +}; + +/*! \brief Class interface for cl_device_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_device_id + */ +class Device : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Device() : detail::Wrapper() { } + + /*! \brief Constructor from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + __CL_EXPLICIT_CONSTRUCTORS Device(const cl_device_id &device) : detail::Wrapper(device) { } + + /*! \brief Returns the first device on the default context. + * + * \see Context::getDefault() + */ + static Device getDefault(cl_int * err = NULL); + + /*! \brief Assignment operator from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + Device& operator = (const cl_device_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device(const Device& dev) : detail::Wrapper(dev) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (const Device &dev) + { + detail::Wrapper::operator=(dev); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Device(Device&& dev) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(dev)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (Device &&dev) + { + detail::Wrapper::operator=(std::move(dev)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetDeviceInfo(). + template + cl_int getInfo(cl_device_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetDeviceInfo, object_, name, param), + __GET_DEVICE_INFO_ERR); + } + + //! \brief Wrapper for clGetDeviceInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_device_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /** + * CL 1.2 version + */ +#if defined(CL_VERSION_1_2) + //! \brief Wrapper for clCreateSubDevicesEXT(). + cl_int createSubDevices( + const cl_device_partition_property * properties, + VECTOR_CLASS* devices) + { + cl_uint n = 0; + cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = clCreateSubDevices(object_, properties, n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } +#endif // #if defined(CL_VERSION_1_2) + +/** + * CL 1.1 version that uses device fission. + */ +#if defined(CL_VERSION_1_1) +#if defined(USE_CL_DEVICE_FISSION) + cl_int createSubDevices( + const cl_device_partition_property_ext * properties, + VECTOR_CLASS* devices) + { + typedef CL_API_ENTRY cl_int + ( CL_API_CALL * PFN_clCreateSubDevicesEXT)( + cl_device_id /*in_device*/, + const cl_device_partition_property_ext * /* properties */, + cl_uint /*num_entries*/, + cl_device_id * /*out_devices*/, + cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL; + __INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT); + + cl_uint n = 0; + cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } +#endif // #if defined(USE_CL_DEVICE_FISSION) +#endif // #if defined(CL_VERSION_1_1) +}; + +/*! \brief Class interface for cl_platform_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_platform_id + */ +class Platform : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Platform() : detail::Wrapper() { } + + /*! \brief Constructor from cl_platform_id. + * + * This simply copies the platform ID value, which is an inexpensive operation. + */ + __CL_EXPLICIT_CONSTRUCTORS Platform(const cl_platform_id &platform) : detail::Wrapper(platform) { } + + /*! \brief Assignment operator from cl_platform_id. + * + * This simply copies the platform ID value, which is an inexpensive operation. + */ + Platform& operator = (const cl_platform_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetPlatformInfo(). + cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetPlatformInfo, object_, name, param), + __GET_PLATFORM_INFO_ERR); + } + + //! \brief Wrapper for clGetPlatformInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_platform_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of devices for this platform. + * + * Wraps clGetDeviceIDs(). + */ + cl_int getDevices( + cl_device_type type, + VECTOR_CLASS* devices) const + { + cl_uint n = 0; + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = ::clGetDeviceIDs(object_, type, n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } + +#if defined(USE_DX_INTEROP) + /*! \brief Get the list of available D3D10 devices. + * + * \param d3d_device_source. + * + * \param d3d_object. + * + * \param d3d_device_set. + * + * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device + * values returned in devices can be used to identify a specific OpenCL + * device. If \a devices argument is NULL, this argument is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * + * The application can query specific capabilities of the OpenCL device(s) + * returned by cl::getDevices. This can be used by the application to + * determine which device(s) to use. + * + * \note In the case that exceptions are enabled and a return value + * other than CL_SUCCESS is generated, then cl::Error exception is + * generated. + */ + cl_int getDevices( + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + VECTOR_CLASS* devices) const + { + typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)( + cl_platform_id platform, + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint* num_devices); + + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + + static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL; + __INIT_CL_EXT_FCN_PTR_PLATFORM(object_, clGetDeviceIDsFromD3D10KHR); + + cl_uint n = 0; + cl_int err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + 0, + NULL, + &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + n, + ids, + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } +#endif + + /*! \brief Gets a list of available platforms. + * + * Wraps clGetPlatformIDs(). + */ + static cl_int get( + VECTOR_CLASS* platforms) + { + cl_uint n = 0; + + if( platforms == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); + } + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + cl_platform_id* ids = (cl_platform_id*) alloca( + n * sizeof(cl_platform_id)); + err = ::clGetPlatformIDs(n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + platforms->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } + + /*! \brief Gets the first available platform. + * + * Wraps clGetPlatformIDs(), returning the first result. + */ + static cl_int get( + Platform * platform) + { + cl_uint n = 0; + + if( platform == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); + } + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + cl_platform_id* ids = (cl_platform_id*) alloca( + n * sizeof(cl_platform_id)); + err = ::clGetPlatformIDs(n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + *platform = ids[0]; + return CL_SUCCESS; + } + + /*! \brief Gets the first available platform, returning it by value. + * + * Wraps clGetPlatformIDs(), returning the first result. + */ + static Platform get( + cl_int * errResult = NULL) + { + Platform platform; + cl_uint n = 0; + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + if (errResult != NULL) { + *errResult = err; + } + return Platform(); + } + + cl_platform_id* ids = (cl_platform_id*) alloca( + n * sizeof(cl_platform_id)); + err = ::clGetPlatformIDs(n, ids, NULL); + + if (err != CL_SUCCESS) { + detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + if (errResult != NULL) { + *errResult = err; + } + return Platform(); + } + + + return Platform(ids[0]); + } + + static Platform getDefault( + cl_int *errResult = NULL ) + { + return get(errResult); + } + + +#if defined(CL_VERSION_1_2) + //! \brief Wrapper for clUnloadCompiler(). + cl_int + unloadCompiler() + { + return ::clUnloadPlatformCompiler(object_); + } +#endif // #if defined(CL_VERSION_1_2) +}; // class Platform + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) +/** + * Unload the OpenCL compiler. + * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead. + */ +inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int +UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +inline cl_int +UnloadCompiler() +{ + return ::clUnloadCompiler(); +} +#endif // #if defined(CL_VERSION_1_1) + +/*! \brief Class interface for cl_context. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_context as the original. For details, see + * clRetainContext() and clReleaseContext(). + * + * \see cl_context + */ +class Context + : public detail::Wrapper +{ +private: + +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + static std::atomic default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static volatile int default_initialized_; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static Context default_; + static volatile cl_int default_error_; +public: + /*! \brief Constructs a context including a list of specified devices. + * + * Wraps clCreateContext(). + */ + Context( + const VECTOR_CLASS& devices, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + ::size_t, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + ::size_t numDevices = devices.size(); + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateContext( + properties, (cl_uint) numDevices, + deviceIDs, + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + Context( + const Device& device, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + ::size_t, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + cl_device_id deviceID = device(); + + object_ = ::clCreateContext( + properties, 1, + &deviceID, + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a context including all or a subset of devices of a specified type. + * + * Wraps clCreateContextFromType(). + */ + Context( + cl_device_type type, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + ::size_t, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + +#if !defined(__APPLE__) && !defined(__MACOS) + cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 }; + + if (properties == NULL) { + // Get a valid platform ID as we cannot send in a blank one + VECTOR_CLASS platforms; + error = Platform::get(&platforms); + if (error != CL_SUCCESS) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + // Check the platforms we found for a device of our specified type + cl_context_properties platform_id = 0; + for (unsigned int i = 0; i < platforms.size(); i++) { + + VECTOR_CLASS devices; + +#if defined(__CL_ENABLE_EXCEPTIONS) + try { +#endif + + error = platforms[i].getDevices(type, &devices); + +#if defined(__CL_ENABLE_EXCEPTIONS) + } catch (Error) {} + // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type + // We do error checking next anyway, and can throw there if needed +#endif + + // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND + if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + if (devices.size() > 0) { + platform_id = (cl_context_properties)platforms[i](); + break; + } + } + + if (platform_id == 0) { + detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = CL_DEVICE_NOT_FOUND; + } + return; + } + + prop[1] = platform_id; + properties = &prop[0]; + } +#endif + object_ = ::clCreateContextFromType( + properties, type, notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context(const Context& ctx) : detail::Wrapper(ctx) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (const Context &ctx) + { + detail::Wrapper::operator=(ctx); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Context(Context&& ctx) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(ctx)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (Context &&ctx) + { + detail::Wrapper::operator=(std::move(ctx)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT. + * + * \note All calls to this function return the same cl_context as the first. + */ + static Context getDefault(cl_int * err = NULL) + { + int state = detail::compare_exchange( + &default_initialized_, + __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED); + + if (state & __DEFAULT_INITIALIZED) { + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + if (state & __DEFAULT_BEING_INITIALIZED) { + // Assume writes will propagate eventually... + while(default_initialized_ != __DEFAULT_INITIALIZED) { + detail::fence(); + } + + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + cl_int error; + default_ = Context( + CL_DEVICE_TYPE_DEFAULT, + NULL, + NULL, + NULL, + &error); + + detail::fence(); + + default_error_ = error; + // Assume writes will propagate eventually... + default_initialized_ = __DEFAULT_INITIALIZED; + + detail::fence(); + + if (err != NULL) { + *err = default_error_; + } + return default_; + + } + + //! \brief Default constructor - initializes to NULL. + Context() : detail::Wrapper() { } + + /*! \brief Constructor from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_context + * into the new Context object. + */ + __CL_EXPLICIT_CONSTRUCTORS Context(const cl_context& context) : detail::Wrapper(context) { } + + /*! \brief Assignment operator from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseContext() on the value previously held by this instance. + */ + Context& operator = (const cl_context& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetContextInfo(). + template + cl_int getInfo(cl_context_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetContextInfo, object_, name, param), + __GET_CONTEXT_INFO_ERR); + } + + //! \brief Wrapper for clGetContextInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_context_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of supported image formats. + * + * Wraps clGetSupportedImageFormats(). + */ + cl_int getSupportedImageFormats( + cl_mem_flags flags, + cl_mem_object_type type, + VECTOR_CLASS* formats) const + { + cl_uint numEntries; + + if (!formats) { + return CL_SUCCESS; + } + + cl_int err = ::clGetSupportedImageFormats( + object_, + flags, + type, + 0, + NULL, + &numEntries); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + if (numEntries > 0) { + ImageFormat* value = (ImageFormat*) + alloca(numEntries * sizeof(ImageFormat)); + err = ::clGetSupportedImageFormats( + object_, + flags, + type, + numEntries, + (cl_image_format*)value, + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + formats->assign(&value[0], &value[numEntries]); + } + else { + formats->clear(); + } + return CL_SUCCESS; + } +}; + +inline Device Device::getDefault(cl_int * err) +{ + cl_int error; + Device device; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + device = context.getInfo()[0]; + if (err != NULL) { + *err = CL_SUCCESS; + } + } + + return device; +} + + +#ifdef _WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) std::atomic Context::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) Context Context::default_; +__declspec(selectany) volatile cl_int Context::default_error_ = CL_SUCCESS; +#else // !_WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) std::atomic Context::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) Context Context::default_; +__attribute__((weak)) volatile cl_int Context::default_error_ = CL_SUCCESS; +#endif // !_WIN32 + +/*! \brief Class interface for cl_event. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_event as the original. For details, see + * clRetainEvent() and clReleaseEvent(). + * + * \see cl_event + */ +class Event : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Event() : detail::Wrapper() { } + + /*! \brief Constructor from cl_event - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_event + * into the new Event object. + */ + __CL_EXPLICIT_CONSTRUCTORS Event(const cl_event& event) : detail::Wrapper(event) { } + + /*! \brief Assignment operator from cl_event - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseEvent() on the value previously held by this instance. + */ + Event& operator = (const cl_event& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetEventInfo(). + template + cl_int getInfo(cl_event_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetEventInfo, object_, name, param), + __GET_EVENT_INFO_ERR); + } + + //! \brief Wrapper for clGetEventInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_event_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + //! \brief Wrapper for clGetEventProfilingInfo(). + template + cl_int getProfilingInfo(cl_profiling_info name, T* param) const + { + return detail::errHandler(detail::getInfo( + &::clGetEventProfilingInfo, object_, name, param), + __GET_EVENT_PROFILE_INFO_ERR); + } + + //! \brief Wrapper for clGetEventProfilingInfo() that returns by value. + template typename + detail::param_traits::param_type + getProfilingInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_profiling_info, name>::param_type param; + cl_int result = getProfilingInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Blocks the calling thread until this event completes. + * + * Wraps clWaitForEvents(). + */ + cl_int wait() const + { + return detail::errHandler( + ::clWaitForEvents(1, &object_), + __WAIT_FOR_EVENTS_ERR); + } + +#if defined(CL_VERSION_1_1) + /*! \brief Registers a user callback function for a specific command execution status. + * + * Wraps clSetEventCallback(). + */ + cl_int setCallback( + cl_int type, + void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetEventCallback( + object_, + type, + pfn_notify, + user_data), + __SET_EVENT_CALLBACK_ERR); + } +#endif + + /*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ + static cl_int + waitForEvents(const VECTOR_CLASS& events) + { + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); + } +}; + +#if defined(CL_VERSION_1_1) +/*! \brief Class interface for user events (a subset of cl_event's). + * + * See Event for details about copy semantics, etc. + */ +class UserEvent : public Event +{ +public: + /*! \brief Constructs a user event on a given context. + * + * Wraps clCreateUserEvent(). + */ + UserEvent( + const Context& context, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateUserEvent( + context(), + &error); + + detail::errHandler(error, __CREATE_USER_EVENT_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + UserEvent() : Event() { } + + /*! \brief Sets the execution status of a user event object. + * + * Wraps clSetUserEventStatus(). + */ + cl_int setStatus(cl_int status) + { + return detail::errHandler( + ::clSetUserEventStatus(object_,status), + __SET_USER_EVENT_STATUS_ERR); + } +}; +#endif + +/*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ +inline static cl_int +WaitForEvents(const VECTOR_CLASS& events) +{ + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); +} + +/*! \brief Class interface for cl_mem. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_mem as the original. For details, see + * clRetainMemObject() and clReleaseMemObject(). + * + * \see cl_mem + */ +class Memory : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Memory() : detail::Wrapper() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_mem + * into the new Memory object. + */ + __CL_EXPLICIT_CONSTRUCTORS Memory(const cl_mem& memory) : detail::Wrapper(memory) { } + + /*! \brief Assignment operator from cl_mem - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseMemObject() on the value previously held by this instance. + */ + Memory& operator = (const cl_mem& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory(const Memory& mem) : detail::Wrapper(mem) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (const Memory &mem) + { + detail::Wrapper::operator=(mem); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory(Memory&& mem) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(mem)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (Memory &&mem) + { + detail::Wrapper::operator=(std::move(mem)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetMemObjectInfo(). + template + cl_int getInfo(cl_mem_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetMemObjectInfo, object_, name, param), + __GET_MEM_OBJECT_INFO_ERR); + } + + //! \brief Wrapper for clGetMemObjectInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_mem_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if defined(CL_VERSION_1_1) + /*! \brief Registers a callback function to be called when the memory object + * is no longer needed. + * + * Wraps clSetMemObjectDestructorCallback(). + * + * Repeated calls to this function, for a given cl_mem value, will append + * to the list of functions called (in reverse order) when memory object's + * resources are freed and the memory object is deleted. + * + * \note + * The registered callbacks are associated with the underlying cl_mem + * value - not the Memory class instance. + */ + cl_int setDestructorCallback( + void (CL_CALLBACK * pfn_notify)(cl_mem, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetMemObjectDestructorCallback( + object_, + pfn_notify, + user_data), + __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR); + } +#endif + +}; + +// Pre-declare copy functions +class Buffer; +template< typename IteratorType > +cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); + + +/*! \brief Class interface for Buffer Memory Objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Buffer : public Memory +{ +public: + + /*! \brief Constructs a Buffer in a specified context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + */ + Buffer( + const Context& context, + cl_mem_flags flags, + ::size_t size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a Buffer in the default context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + * + * \see Context::getDefault() + */ + Buffer( + cl_mem_flags flags, + ::size_t size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(err); + + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer( + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr = false, + cl_int* err = NULL) + { + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + ::size_t size = sizeof(DataType)*(endIterator - startIterator); + + Context context = Context::getDefault(err); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + error = cl::copy(startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified context. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified queue. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Buffer() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Buffer(const cl_mem& buffer) : Memory(buffer) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Buffer& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer(const Buffer& buf) : Memory(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (const Buffer &buf) + { + Memory::operator=(buf); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer(Buffer&& buf) CL_HPP_NOEXCEPT : Memory(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (Buffer &&buf) + { + Memory::operator=(std::move(buf)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + +#if defined(CL_VERSION_1_1) + /*! \brief Creates a new buffer object from this. + * + * Wraps clCreateSubBuffer(). + */ + Buffer createSubBuffer( + cl_mem_flags flags, + cl_buffer_create_type buffer_create_type, + const void * buffer_create_info, + cl_int * err = NULL) + { + Buffer result; + cl_int error; + result.object_ = ::clCreateSubBuffer( + object_, + flags, + buffer_create_type, + buffer_create_info, + &error); + + detail::errHandler(error, __CREATE_SUBBUFFER_ERR); + if (err != NULL) { + *err = error; + } + + return result; + } +#endif +}; + +#if defined (USE_DX_INTEROP) +/*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's. + * + * This is provided to facilitate interoperability with Direct3D. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferD3D10 : public Buffer +{ +public: + typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)( + cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer, + cl_int* errcode_ret); + + /*! \brief Constructs a BufferD3D10, in a specified context, from a + * given ID3D10Buffer. + * + * Wraps clCreateFromD3D10BufferKHR(). + */ + BufferD3D10( + const Context& context, + cl_mem_flags flags, + ID3D10Buffer* bufobj, + cl_int * err = NULL) + { + static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL; + +#if defined(CL_VERSION_1_2) + vector props = context.getInfo(); + cl_platform platform = -1; + for( int i = 0; i < props.size(); ++i ) { + if( props[i] == CL_CONTEXT_PLATFORM ) { + platform = props[i+1]; + } + } + __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clCreateFromD3D10BufferKHR); +#endif +#if defined(CL_VERSION_1_1) + __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR); +#endif + + cl_int error; + object_ = pfn_clCreateFromD3D10BufferKHR( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferD3D10() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS BufferD3D10(const cl_mem& buffer) : Buffer(buffer) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferD3D10& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(const BufferD3D10& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (const BufferD3D10 &buf) + { + Buffer::operator=(buf); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (BufferD3D10 &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif + +/*! \brief Class interface for GL Buffer Memory Objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferGL : public Buffer +{ +public: + /*! \brief Constructs a BufferGL in a specified context, from a given + * GL buffer. + * + * Wraps clCreateFromGLBuffer(). + */ + BufferGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLBuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferGL() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS BufferGL(const cl_mem& buffer) : Buffer(buffer) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferGL& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL(const BufferGL& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (const BufferGL &buf) + { + Buffer::operator=(buf); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (BufferGL &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_,type,gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief C++ base class for Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image : public Memory +{ +protected: + //! \brief Default constructor - initializes to NULL. + Image() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image(const cl_mem& image) : Memory(image) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image(const Image& img) : Memory(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (const Image &img) + { + Memory::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image(Image&& img) CL_HPP_NOEXCEPT : Memory(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (Image &&img) + { + Memory::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + +public: + //! \brief Wrapper for clGetImageInfo(). + template + cl_int getImageInfo(cl_image_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetImageInfo, object_, name, param), + __GET_IMAGE_INFO_ERR); + } + + //! \brief Wrapper for clGetImageInfo() that returns by value. + template typename + detail::param_traits::param_type + getImageInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_image_info, name>::param_type param; + cl_int result = getImageInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +#if defined(CL_VERSION_1_2) +/*! \brief Class interface for 1D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image1D : public Image +{ +public: + /*! \brief Constructs a 1D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image1D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D, + width, + 0, 0, 0, 0, 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image1D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image1D(const cl_mem& image1D) : Image(image1D) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image1D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D(const Image1D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (const Image1D &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D(Image1D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (Image1D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + +/*! \class Image1DBuffer + * \brief Image interface for 1D buffer images. + */ +class Image1DBuffer : public Image +{ +public: + Image1DBuffer( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + const Buffer &buffer, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_BUFFER, + width, + 0, 0, 0, 0, 0, 0, 0, + buffer() + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + NULL, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DBuffer() { } + + __CL_EXPLICIT_CONSTRUCTORS Image1DBuffer(const cl_mem& image1D) : Image(image1D) { } + + Image1DBuffer& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(const Image1DBuffer& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (const Image1DBuffer &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (Image1DBuffer &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + +/*! \class Image1DArray + * \brief Image interface for arrays of 1D images. + */ +class Image1DArray : public Image +{ +public: + Image1DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t arraySize, + ::size_t width, + ::size_t rowPitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_ARRAY, + width, + 0, 0, // height, depth (unused) + arraySize, + rowPitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DArray() { } + + __CL_EXPLICIT_CONSTRUCTORS Image1DArray(const cl_mem& imageArray) : Image(imageArray) { } + + Image1DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(const Image1DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (const Image1DArray &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (Image1DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if defined(CL_VERSION_1_2) + + +/*! \brief Class interface for 2D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image2D : public Image +{ +public: + /*! \brief Constructs a 1D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image2D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + ::size_t height, + ::size_t row_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif defined(CL_VERSION_1_2) + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if defined(CL_VERSION_1_2) + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D, + width, + height, + 0, 0, // depth, array size (unused) + row_pitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if defined(CL_VERSION_1_2) +#if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + if (!useCreateImage) + { + object_ = ::clCreateImage2D( + context(), flags,&format, width, height, row_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE2D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + } + + //! \brief Default constructor - initializes to NULL. + Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image2D(const cl_mem& image2D) : Image(image2D) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image2D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D(const Image2D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (const Image2D &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D(Image2D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (Image2D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + + +#if !defined(CL_VERSION_1_2) +/*! \brief Class interface for GL 2D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + * \note Deprecated for OpenCL 1.2. Please use ImageGL instead. + */ +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED : public Image2D +{ +public: + /*! \brief Constructs an Image2DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture2D(). + */ + Image2DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture2D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR); + if (err != NULL) { + *err = error; + } + + } + + //! \brief Default constructor - initializes to NULL. + Image2DGL() : Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image2DGL(const cl_mem& image) : Image2D(image) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image2DGL& operator = (const cl_mem& rhs) + { + Image2D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(const Image2DGL& img) : Image2D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (const Image2DGL &img) + { + Image2D::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT : Image2D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (Image2DGL &&img) + { + Image2D::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if !defined(CL_VERSION_1_2) + +#if defined(CL_VERSION_1_2) +/*! \class Image2DArray + * \brief Image interface for arrays of 2D images. + */ +class Image2DArray : public Image +{ +public: + Image2DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t arraySize, + ::size_t width, + ::size_t height, + ::size_t rowPitch, + ::size_t slicePitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D_ARRAY, + width, + height, + 0, // depth (unused) + arraySize, + rowPitch, + slicePitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image2DArray() { } + + __CL_EXPLICIT_CONSTRUCTORS Image2DArray(const cl_mem& imageArray) : Image(imageArray) { } + + Image2DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(const Image2DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (const Image2DArray &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (Image2DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if defined(CL_VERSION_1_2) + +/*! \brief Class interface for 3D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3D : public Image +{ +public: + /*! \brief Constructs a 3D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image3D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + ::size_t height, + ::size_t depth, + ::size_t row_pitch = 0, + ::size_t slice_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif defined(CL_VERSION_1_2) + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if defined(CL_VERSION_1_2) + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE3D, + width, + height, + depth, + 0, // array size (unused) + row_pitch, + slice_pitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if defined(CL_VERSION_1_2) +#if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + if (!useCreateImage) + { + object_ = ::clCreateImage3D( + context(), flags, &format, width, height, depth, row_pitch, + slice_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE3D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + } + + //! \brief Default constructor - initializes to NULL. + Image3D() : Image() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image3D(const cl_mem& image3D) : Image(image3D) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D(const Image3D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (const Image3D &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D(Image3D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (Image3D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + +#if !defined(CL_VERSION_1_2) +/*! \brief Class interface for GL 3D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3DGL : public Image3D +{ +public: + /*! \brief Constructs an Image3DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture3D(). + */ + Image3DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture3D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image3DGL() : Image3D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image3DGL(const cl_mem& image) : Image3D(image) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3DGL& operator = (const cl_mem& rhs) + { + Image3D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(const Image3DGL& img) : Image3D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (const Image3DGL &img) + { + Image3D::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT : Image3D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (Image3DGL &&img) + { + Image3D::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if !defined(CL_VERSION_1_2) + +#if defined(CL_VERSION_1_2) +/*! \class ImageGL + * \brief general image interface for GL interop. + * We abstract the 2D and 3D GL images into a single instance here + * that wraps all GL sourced images on the grounds that setup information + * was performed by OpenCL anyway. + */ +class ImageGL : public Image +{ +public: + ImageGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_ERR); + if (err != NULL) { + *err = error; + } + } + + ImageGL() : Image() { } + + __CL_EXPLICIT_CONSTRUCTORS ImageGL(const cl_mem& image) : Image(image) { } + + ImageGL& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL(const ImageGL& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (const ImageGL &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (ImageGL &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if defined(CL_VERSION_1_2) + +/*! \brief Class interface for GL Render Buffer Memory Objects. +* +* This is provided to facilitate interoperability with OpenGL. +* +* See Memory for details about copy semantics, etc. +* +* \see Memory +*/ +class BufferRenderGL : +#if defined(CL_VERSION_1_2) + public ImageGL +#else // #if defined(CL_VERSION_1_2) + public Image2DGL +#endif //#if defined(CL_VERSION_1_2) +{ +public: + /*! \brief Constructs a BufferRenderGL in a specified context, from a given + * GL Renderbuffer. + * + * Wraps clCreateFromGLRenderbuffer(). + */ + BufferRenderGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLRenderbuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. +#if defined(CL_VERSION_1_2) + BufferRenderGL() : ImageGL() {}; +#else // #if defined(CL_VERSION_1_2) + BufferRenderGL() : Image2DGL() {}; +#endif //#if defined(CL_VERSION_1_2) + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ +#if defined(CL_VERSION_1_2) + __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : ImageGL(buffer) { } +#else // #if defined(CL_VERSION_1_2) + __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : Image2DGL(buffer) { } +#endif //#if defined(CL_VERSION_1_2) + + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferRenderGL& operator = (const cl_mem& rhs) + { +#if defined(CL_VERSION_1_2) + ImageGL::operator=(rhs); +#else // #if defined(CL_VERSION_1_2) + Image2DGL::operator=(rhs); +#endif //#if defined(CL_VERSION_1_2) + + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ +#if defined(CL_VERSION_1_2) + BufferRenderGL(const BufferRenderGL& buf) : ImageGL(buf) {} +#else // #if defined(CL_VERSION_1_2) + BufferRenderGL(const BufferRenderGL& buf) : Image2DGL(buf) {} +#endif //#if defined(CL_VERSION_1_2) + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (const BufferRenderGL &rhs) + { +#if defined(CL_VERSION_1_2) + ImageGL::operator=(rhs); +#else // #if defined(CL_VERSION_1_2) + Image2DGL::operator=(rhs); +#endif //#if defined(CL_VERSION_1_2) + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ +#if defined(CL_VERSION_1_2) + BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : ImageGL(std::move(buf)) {} +#else // #if defined(CL_VERSION_1_2) + BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : Image2DGL(std::move(buf)) {} +#endif //#if defined(CL_VERSION_1_2) + + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (BufferRenderGL &&buf) + { +#if defined(CL_VERSION_1_2) + ImageGL::operator=(std::move(buf)); +#else // #if defined(CL_VERSION_1_2) + Image2DGL::operator=(std::move(buf)); +#endif //#if defined(CL_VERSION_1_2) + + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_, type, gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief Class interface for cl_sampler. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_sampler as the original. For details, see + * clRetainSampler() and clReleaseSampler(). + * + * \see cl_sampler + */ +class Sampler : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Sampler() { } + + /*! \brief Constructs a Sampler in a specified context. + * + * Wraps clCreateSampler(). + */ + Sampler( + const Context& context, + cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateSampler( + context(), + normalized_coords, + addressing_mode, + filter_mode, + &error); + + detail::errHandler(error, __CREATE_SAMPLER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructor from cl_sampler - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_sampler + * into the new Sampler object. + */ + __CL_EXPLICIT_CONSTRUCTORS Sampler(const cl_sampler& sampler) : detail::Wrapper(sampler) { } + + /*! \brief Assignment operator from cl_sampler - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseSampler() on the value previously held by this instance. + */ + Sampler& operator = (const cl_sampler& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler(const Sampler& sam) : detail::Wrapper(sam) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (const Sampler &sam) + { + detail::Wrapper::operator=(sam); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler(Sampler&& sam) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(sam)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (Sampler &&sam) + { + detail::Wrapper::operator=(std::move(sam)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetSamplerInfo(). + template + cl_int getInfo(cl_sampler_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetSamplerInfo, object_, name, param), + __GET_SAMPLER_INFO_ERR); + } + + //! \brief Wrapper for clGetSamplerInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_sampler_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +class Program; +class CommandQueue; +class Kernel; + +//! \brief Class interface for specifying NDRange values. +class NDRange +{ +private: + size_t<3> sizes_; + cl_uint dimensions_; + +public: + //! \brief Default constructor - resulting range has zero dimensions. + NDRange() + : dimensions_(0) + { } + + //! \brief Constructs one-dimensional range. + NDRange(::size_t size0) + : dimensions_(1) + { + sizes_[0] = size0; + } + + //! \brief Constructs two-dimensional range. + NDRange(::size_t size0, ::size_t size1) + : dimensions_(2) + { + sizes_[0] = size0; + sizes_[1] = size1; + } + + //! \brief Constructs three-dimensional range. + NDRange(::size_t size0, ::size_t size1, ::size_t size2) + : dimensions_(3) + { + sizes_[0] = size0; + sizes_[1] = size1; + sizes_[2] = size2; + } + + /*! \brief Conversion operator to const ::size_t *. + * + * \returns a pointer to the size of the first dimension. + */ + operator const ::size_t*() const { + return (const ::size_t*) sizes_; + } + + //! \brief Queries the number of dimensions in the range. + ::size_t dimensions() const { return dimensions_; } +}; + +//! \brief A zero-dimensional range. +static const NDRange NullRange; + +//! \brief Local address wrapper for use with Kernel::setArg +struct LocalSpaceArg +{ + ::size_t size_; +}; + +namespace detail { + +template +struct KernelArgumentHandler +{ + static ::size_t size(const T&) { return sizeof(T); } + static const T* ptr(const T& value) { return &value; } +}; + +template <> +struct KernelArgumentHandler +{ + static ::size_t size(const LocalSpaceArg& value) { return value.size_; } + static const void* ptr(const LocalSpaceArg&) { return NULL; } +}; + +} +//! \endcond + +/*! __local + * \brief Helper function for generating LocalSpaceArg objects. + * Deprecated. Replaced with Local. + */ +inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED LocalSpaceArg +__local(::size_t size) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +inline LocalSpaceArg +__local(::size_t size) +{ + LocalSpaceArg ret = { size }; + return ret; +} + +/*! Local + * \brief Helper function for generating LocalSpaceArg objects. + */ +inline LocalSpaceArg +Local(::size_t size) +{ + LocalSpaceArg ret = { size }; + return ret; +} + +//class KernelFunctor; + +/*! \brief Class interface for cl_kernel. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_kernel as the original. For details, see + * clRetainKernel() and clReleaseKernel(). + * + * \see cl_kernel + */ +class Kernel : public detail::Wrapper +{ +public: + inline Kernel(const Program& program, const char* name, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Kernel() { } + + /*! \brief Constructor from cl_kernel - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_kernel + * into the new Kernel object. + */ + __CL_EXPLICIT_CONSTRUCTORS Kernel(const cl_kernel& kernel) : detail::Wrapper(kernel) { } + + /*! \brief Assignment operator from cl_kernel - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseKernel() on the value previously held by this instance. + */ + Kernel& operator = (const cl_kernel& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel(const Kernel& kernel) : detail::Wrapper(kernel) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (const Kernel &kernel) + { + detail::Wrapper::operator=(kernel); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(kernel)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (Kernel &&kernel) + { + detail::Wrapper::operator=(std::move(kernel)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + template + cl_int getInfo(cl_kernel_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelInfo, object_, name, param), + __GET_KERNEL_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if defined(CL_VERSION_1_2) + template + cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param), + __GET_KERNEL_ARG_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getArgInfo(cl_uint argIndex, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_arg_info, name>::param_type param; + cl_int result = getArgInfo(argIndex, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +#endif // #if defined(CL_VERSION_1_2) + + template + cl_int getWorkGroupInfo( + const Device& device, cl_kernel_work_group_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetKernelWorkGroupInfo, object_, device(), name, param), + __GET_KERNEL_WORK_GROUP_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getWorkGroupInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_work_group_info, name>::param_type param; + cl_int result = getWorkGroupInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + template + cl_int setArg(cl_uint index, const T &value) + { + return detail::errHandler( + ::clSetKernelArg( + object_, + index, + detail::KernelArgumentHandler::size(value), + detail::KernelArgumentHandler::ptr(value)), + __SET_KERNEL_ARGS_ERR); + } + + cl_int setArg(cl_uint index, ::size_t size, const void* argPtr) + { + return detail::errHandler( + ::clSetKernelArg(object_, index, size, argPtr), + __SET_KERNEL_ARGS_ERR); + } +}; + +/*! \class Program + * \brief Program interface that implements cl_program. + */ +class Program : public detail::Wrapper +{ +public: + typedef VECTOR_CLASS > Binaries; + typedef VECTOR_CLASS > Sources; + + Program( + const STRING_CLASS& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const ::size_t length = source.size(); + + Context context = Context::getDefault(err); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + + error = ::clBuildProgram( + object_, + 0, + NULL, + "", + NULL, + NULL); + + detail::errHandler(error, __BUILD_PROGRAM_ERR); + } + + if (err != NULL) { + *err = error; + } + } + + Program( + const Context& context, + const STRING_CLASS& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const ::size_t length = source.size(); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + + error = ::clBuildProgram( + object_, + 0, + NULL, + "", + NULL, + NULL); + + detail::errHandler(error, __BUILD_PROGRAM_ERR); + } + + if (err != NULL) { + *err = error; + } + } + + Program( + const Context& context, + const Sources& sources, + cl_int* err = NULL) + { + cl_int error; + + const ::size_t n = (::size_t)sources.size(); + ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t)); + const char** strings = (const char**) alloca(n * sizeof(const char*)); + + for (::size_t i = 0; i < n; ++i) { + strings[i] = sources[(int)i].first; + lengths[i] = sources[(int)i].second; + } + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)n, strings, lengths, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + if (err != NULL) { + *err = error; + } + } + + /** + * Construct a program object from a list of devices and a per-device list of binaries. + * \param context A valid OpenCL context in which to construct the program. + * \param devices A vector of OpenCL device objects for which the program will be created. + * \param binaries A vector of pairs of a pointer to a binary object and its length. + * \param binaryStatus An optional vector that on completion will be resized to + * match the size of binaries and filled with values to specify if each binary + * was successfully loaded. + * Set to CL_SUCCESS if the binary was successfully loaded. + * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL. + * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device. + * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors: + * CL_INVALID_CONTEXT if context is not a valid context. + * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices; + * or if any entry in binaries is NULL or has length 0. + * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context. + * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device. + * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host. + */ + Program( + const Context& context, + const VECTOR_CLASS& devices, + const Binaries& binaries, + VECTOR_CLASS* binaryStatus = NULL, + cl_int* err = NULL) + { + cl_int error; + + const ::size_t numDevices = devices.size(); + + // Catch size mismatch early and return + if(binaries.size() != numDevices) { + error = CL_INVALID_VALUE; + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + ::size_t* lengths = (::size_t*) alloca(numDevices * sizeof(::size_t)); + const unsigned char** images = (const unsigned char**) alloca(numDevices * sizeof(const unsigned char**)); + + for (::size_t i = 0; i < numDevices; ++i) { + images[i] = (const unsigned char*)binaries[i].first; + lengths[i] = binaries[(int)i].second; + } + + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + if(binaryStatus) { + binaryStatus->resize(numDevices); + } + + object_ = ::clCreateProgramWithBinary( + context(), (cl_uint) devices.size(), + deviceIDs, + lengths, images, (binaryStatus != NULL && numDevices > 0) + ? &binaryStatus->front() + : NULL, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + } + + +#if defined(CL_VERSION_1_2) + /** + * Create program using builtin kernels. + * \param kernelNames Semi-colon separated list of builtin kernel names + */ + Program( + const Context& context, + const VECTOR_CLASS& devices, + const STRING_CLASS& kernelNames, + cl_int* err = NULL) + { + cl_int error; + + + ::size_t numDevices = devices.size(); + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateProgramWithBuiltInKernels( + context(), + (cl_uint) devices.size(), + deviceIDs, + kernelNames.c_str(), + &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if defined(CL_VERSION_1_2) + + Program() { } + + __CL_EXPLICIT_CONSTRUCTORS Program(const cl_program& program) : detail::Wrapper(program) { } + + Program& operator = (const cl_program& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program(const Program& program) : detail::Wrapper(program) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (const Program &program) + { + detail::Wrapper::operator=(program); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Program(Program&& program) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(program)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (Program &&program) + { + detail::Wrapper::operator=(std::move(program)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + cl_int build( + const VECTOR_CLASS& devices, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + ::size_t numDevices = devices.size(); + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + return detail::errHandler( + ::clBuildProgram( + object_, + (cl_uint) + devices.size(), + deviceIDs, + options, + notifyFptr, + data), + __BUILD_PROGRAM_ERR); + } + + cl_int build( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + return detail::errHandler( + ::clBuildProgram( + object_, + 0, + NULL, + options, + notifyFptr, + data), + __BUILD_PROGRAM_ERR); + } + +#if defined(CL_VERSION_1_2) + cl_int compile( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + return detail::errHandler( + ::clCompileProgram( + object_, + 0, + NULL, + options, + 0, + NULL, + NULL, + notifyFptr, + data), + __COMPILE_PROGRAM_ERR); + } +#endif + + template + cl_int getInfo(cl_program_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetProgramInfo, object_, name, param), + __GET_PROGRAM_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + template + cl_int getBuildInfo( + const Device& device, cl_program_build_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetProgramBuildInfo, object_, device(), name, param), + __GET_PROGRAM_BUILD_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getBuildInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_build_info, name>::param_type param; + cl_int result = getBuildInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + cl_int createKernels(VECTOR_CLASS* kernels) + { + cl_uint numKernels; + cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel)); + err = ::clCreateKernelsInProgram( + object_, numKernels, (cl_kernel*) value, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + kernels->assign(&value[0], &value[numKernels]); + return CL_SUCCESS; + } +}; + +#if defined(CL_VERSION_1_2) +inline Program linkProgram( + Program input1, + Program input2, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + cl_program programs[2] = { input1(), input2() }; + + Context ctx = input1.getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + 2, + programs, + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog); +} + +inline Program linkProgram( + VECTOR_CLASS inputPrograms, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + cl_program * programs = (cl_program*) alloca(inputPrograms.size() * sizeof(cl_program)); + + if (programs != NULL) { + for (unsigned int i = 0; i < inputPrograms.size(); i++) { + programs[i] = inputPrograms[i](); + } + } + + Context ctx; + if(inputPrograms.size() > 0) { + ctx = inputPrograms[0].getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + } + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + (cl_uint)inputPrograms.size(), + programs, + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog); +} +#endif + +template<> +inline VECTOR_CLASS cl::Program::getInfo(cl_int* err) const +{ + VECTOR_CLASS< ::size_t> sizes = getInfo(); + VECTOR_CLASS binaries; + for (VECTOR_CLASS< ::size_t>::iterator s = sizes.begin(); s != sizes.end(); ++s) + { + char *ptr = NULL; + if (*s != 0) + ptr = new char[*s]; + binaries.push_back(ptr); + } + + cl_int result = getInfo(CL_PROGRAM_BINARIES, &binaries); + if (err != NULL) { + *err = result; + } + return binaries; +} + +inline Kernel::Kernel(const Program& program, const char* name, cl_int* err) +{ + cl_int error; + + object_ = ::clCreateKernel(program(), name, &error); + detail::errHandler(error, __CREATE_KERNEL_ERR); + + if (err != NULL) { + *err = error; + } + +} + +/*! \class CommandQueue + * \brief CommandQueue interface for cl_command_queue. + */ +class CommandQueue : public detail::Wrapper +{ +private: +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + static std::atomic default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static volatile int default_initialized_; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static CommandQueue default_; + static volatile cl_int default_error_; +public: + CommandQueue( + cl_command_queue_properties properties, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } + } + } + /*! + * \brief Constructs a CommandQueue for an implementation defined device in the given context + */ + explicit CommandQueue( + const Context& context, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + VECTOR_CLASS devices; + error = context.getInfo(CL_CONTEXT_DEVICES, &devices); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) + { + if (err != NULL) { + *err = error; + } + return; + } + + object_ = ::clCreateCommandQueue(context(), devices[0](), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + + if (err != NULL) { + *err = error; + } + + } + + CommandQueue( + const Context& context, + const Device& device, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(const CommandQueue& queue) : detail::Wrapper(queue) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (const CommandQueue &queue) + { + detail::Wrapper::operator=(queue); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(queue)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (CommandQueue &&queue) + { + detail::Wrapper::operator=(std::move(queue)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + static CommandQueue getDefault(cl_int * err = NULL) + { + int state = detail::compare_exchange( + &default_initialized_, + __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED); + + if (state & __DEFAULT_INITIALIZED) { + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + if (state & __DEFAULT_BEING_INITIALIZED) { + // Assume writes will propagate eventually... + while(default_initialized_ != __DEFAULT_INITIALIZED) { + detail::fence(); + } + + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + + default_ = CommandQueue(context, device, 0, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } + } + + detail::fence(); + + default_error_ = error; + // Assume writes will propagate eventually... + default_initialized_ = __DEFAULT_INITIALIZED; + + detail::fence(); + + if (err != NULL) { + *err = default_error_; + } + return default_; + + } + + CommandQueue() { } + + __CL_EXPLICIT_CONSTRUCTORS CommandQueue(const cl_command_queue& commandQueue) : detail::Wrapper(commandQueue) { } + + CommandQueue& operator = (const cl_command_queue& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + template + cl_int getInfo(cl_command_queue_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetCommandQueueInfo, object_, name, param), + __GET_COMMAND_QUEUE_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_command_queue_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + ::size_t src_offset, + ::size_t dst_offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBuffer( + object_, src(), dst(), src_offset, dst_offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBufferRect( + object_, + buffer(), + blocking, + (const ::size_t *)buffer_offset, + (const ::size_t *)host_offset, + (const ::size_t *)region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + const void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBufferRect( + object_, + buffer(), + blocking, + (const ::size_t *)buffer_offset, + (const ::size_t *)host_offset, + (const ::size_t *)region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + ::size_t src_row_pitch, + ::size_t src_slice_pitch, + ::size_t dst_row_pitch, + ::size_t dst_slice_pitch, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferRect( + object_, + src(), + dst(), + (const ::size_t *)src_origin, + (const ::size_t *)dst_origin, + (const ::size_t *)region, + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_VERSION_1_2) + /** + * Enqueue a command to fill a buffer object with a pattern + * of a given size. The pattern is specified a as vector. + * \tparam PatternType The datatype of the pattern field. + * The pattern type must be an accepted OpenCL data type. + */ + template + cl_int enqueueFillBuffer( + const Buffer& buffer, + PatternType pattern, + ::size_t offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillBuffer( + object_, + buffer(), + static_cast(&pattern), + sizeof(PatternType), + offset, + size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_VERSION_1_2) + + cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadImage( + object_, image(), blocking, (const ::size_t *) origin, + (const ::size_t *) region, row_pitch, slice_pitch, ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteImage( + object_, image(), blocking, (const ::size_t *) origin, + (const ::size_t *) region, row_pitch, slice_pitch, ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImage( + object_, src(), dst(), (const ::size_t *) src_origin, + (const ::size_t *)dst_origin, (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_VERSION_1_2) + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA floating-point color value if + * the image channel data type is not an unnormalized signed or + * unsigned data type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_float4 fillColor, + const size_t<3>& origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + (const ::size_t *) origin, + (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA signed integer color value if + * the image channel data type is an unnormalized signed integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_int4 fillColor, + const size_t<3>& origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + (const ::size_t *) origin, + (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA unsigned integer color value if + * the image channel data type is an unnormalized unsigned integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_uint4 fillColor, + const size_t<3>& origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + (const ::size_t *) origin, + (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_VERSION_1_2) + + cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& region, + ::size_t dst_offset, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImageToBuffer( + object_, src(), dst(), (const ::size_t *) src_origin, + (const ::size_t *) region, dst_offset, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + ::size_t src_offset, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferToImage( + object_, src(), dst(), src_offset, + (const ::size_t *) dst_origin, (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + ::size_t offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapBuffer( + object_, buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + + return result; + } + + void* enqueueMapImage( + const Image& buffer, + cl_bool blocking, + cl_map_flags flags, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t * row_pitch, + ::size_t * slice_pitch, + const VECTOR_CLASS* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapImage( + object_, buffer(), blocking, flags, + (const ::size_t *) origin, (const ::size_t *) region, + row_pitch, slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + return result; + } + + cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + object_, memory(), mapped_ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_VERSION_1_2) + /** + * Enqueues a marker command which waits for either a list of events to complete, + * or all previously enqueued commands to complete. + * + * Enqueues a marker command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command returns an event which can be waited on, + * i.e. this event can be waited on to insure that all events either in the event_wait_list + * or all previously enqueued commands, queued before this command to command_queue, + * have completed. + */ + cl_int enqueueMarkerWithWaitList( + const VECTOR_CLASS *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarkerWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * A synchronization point that enqueues a barrier operation. + * + * Enqueues a barrier command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command blocks command execution, that is, any + * following commands enqueued after it do not execute until it completes. This command + * returns an event which can be waited on, i.e. this event can be waited on to insure that + * all events either in the event_wait_list or all previously enqueued commands, queued + * before this command to command_queue, have completed. + */ + cl_int enqueueBarrierWithWaitList( + const VECTOR_CLASS *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueBarrierWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_BARRIER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command to indicate with which device a set of memory objects + * should be associated. + */ + cl_int enqueueMigrateMemObjects( + const VECTOR_CLASS &memObjects, + cl_mem_migration_flags flags, + const VECTOR_CLASS* events = NULL, + Event* event = NULL + ) const + { + cl_event tmp; + + cl_mem* localMemObjects = static_cast(alloca(memObjects.size() * sizeof(cl_mem))); + for( int i = 0; i < (int)memObjects.size(); ++i ) { + localMemObjects[i] = memObjects[i](); + } + + + cl_int err = detail::errHandler( + ::clEnqueueMigrateMemObjects( + object_, + (cl_uint)memObjects.size(), + static_cast(localMemObjects), + flags, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_VERSION_1_2) + + cl_int enqueueNDRangeKernel( + const Kernel& kernel, + const NDRange& offset, + const NDRange& global, + const NDRange& local = NullRange, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNDRangeKernel( + object_, kernel(), (cl_uint) global.dimensions(), + offset.dimensions() != 0 ? (const ::size_t*) offset : NULL, + (const ::size_t*) global, + local.dimensions() != 0 ? (const ::size_t*) local : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NDRANGE_KERNEL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueTask( + const Kernel& kernel, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueTask( + object_, kernel(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_TASK_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueNativeKernel( + void (CL_CALLBACK *userFptr)(void *), + std::pair args, + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* mem_locs = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_mem * mems = (mem_objects != NULL && mem_objects->size() > 0) + ? (cl_mem*) alloca(mem_objects->size() * sizeof(cl_mem)) + : NULL; + + if (mems != NULL) { + for (unsigned int i = 0; i < mem_objects->size(); i++) { + mems[i] = ((*mem_objects)[i])(); + } + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNativeKernel( + object_, userFptr, args.first, args.second, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + mems, + (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NATIVE_KERNEL); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarker( + object_, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueWaitForEvents(const VECTOR_CLASS& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueWaitForEvents( + object_, + (cl_uint) events.size(), + events.size() > 0 ? (const cl_event*) &events.front() : NULL), + __ENQUEUE_WAIT_FOR_EVENTS_ERR); + } +#endif // #if defined(CL_VERSION_1_1) + + cl_int enqueueAcquireGLObjects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueAcquireGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseGLObjects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReleaseGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined (USE_DX_INTEROP) +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); + + cl_int enqueueAcquireD3D10Objects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL; +#if defined(CL_VERSION_1_2) + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueAcquireD3D10ObjectsKHR); +#endif +#if defined(CL_VERSION_1_1) + __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR); +#endif + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueAcquireD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseD3D10Objects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL; +#if defined(CL_VERSION_1_2) + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueReleaseD3D10ObjectsKHR); +#endif // #if defined(CL_VERSION_1_2) +#if defined(CL_VERSION_1_1) + __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR); +#endif // #if defined(CL_VERSION_1_1) + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueReleaseD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueBarrier(object_), + __ENQUEUE_BARRIER_ERR); + } +#endif // #if defined(CL_VERSION_1_1) + + cl_int flush() const + { + return detail::errHandler(::clFlush(object_), __FLUSH_ERR); + } + + cl_int finish() const + { + return detail::errHandler(::clFinish(object_), __FINISH_ERR); + } +}; + +#ifdef _WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) std::atomic CommandQueue::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) CommandQueue CommandQueue::default_; +__declspec(selectany) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS; +#else // !_WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) std::atomic CommandQueue::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) CommandQueue CommandQueue::default_; +__attribute__((weak)) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS; +#endif // !_WIN32 + +template< typename IteratorType > +Buffer::Buffer( + const Context &context, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + ::size_t size = sizeof(DataType)*(endIterator - startIterator); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + CommandQueue queue(context, 0, &error); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +template< typename IteratorType > +Buffer::Buffer( + const CommandQueue &queue, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if (readOnly) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + } + + ::size_t size = sizeof(DataType)*(endIterator - startIterator); + + Context context = queue.getInfo(); + + if (useHostPtr) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } + else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if (!useHostPtr) { + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +inline cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + ::size_t offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL, + cl_int* err = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + void * result = ::clEnqueueMapBuffer( + queue(), buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (cl_event*) event, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + return result; +} + +inline cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (error != CL_SUCCESS) { + return error; + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + queue(), memory(), mapped_ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; +} + +inline cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + ::size_t src_offset, + ::size_t dst_offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, startIterator, endIterator, buffer); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, buffer, startIterator, endIterator); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + ::size_t length = endIterator-startIterator; + ::size_t byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } +#if defined(_MSC_VER) + std::copy( + startIterator, + endIterator, + stdext::checked_array_iterator( + pointer, length)); +#else + std::copy(startIterator, endIterator, pointer); +#endif + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + ::size_t length = endIterator-startIterator; + ::size_t byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } + std::copy(pointer, pointer + length, startIterator); + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + +#if defined(CL_VERSION_1_1) +inline cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + const void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + ::size_t src_row_pitch, + ::size_t src_slice_pitch, + ::size_t dst_row_pitch, + ::size_t dst_slice_pitch, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferRect( + src, + dst, + src_origin, + dst_origin, + region, + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + events, + event); +} +#endif + +inline cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImage( + src, + dst, + src_origin, + dst_origin, + region, + events, + event); +} + +inline cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& region, + ::size_t dst_offset, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImageToBuffer( + src, + dst, + src_origin, + region, + dst_offset, + events, + event); +} + +inline cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + ::size_t src_offset, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferToImage( + src, + dst, + src_offset, + dst_origin, + region, + events, + event); +} + + +inline cl_int flush(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.flush(); +} + +inline cl_int finish(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + + return queue.finish(); +} + +// Kernel Functor support +// New interface as of September 2011 +// Requires the C++11 std::tr1::function (note do not support TR1) +// Visual Studio 2010 and GCC 4.2 + +struct EnqueueArgs +{ + CommandQueue queue_; + const NDRange offset_; + const NDRange global_; + const NDRange local_; + VECTOR_CLASS events_; + + EnqueueArgs(NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(Event e, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(const VECTOR_CLASS &events, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(const VECTOR_CLASS &events, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(const VECTOR_CLASS &events, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } +}; + +namespace detail { + +class NullType {}; + +template +struct SetArg +{ + static void set (Kernel kernel, T0 arg) + { + kernel.setArg(index, arg); + } +}; + +template +struct SetArg +{ + static void set (Kernel, NullType) + { + } +}; + +template < + typename T0, typename T1, typename T2, typename T3, + typename T4, typename T5, typename T6, typename T7, + typename T8, typename T9, typename T10, typename T11, + typename T12, typename T13, typename T14, typename T15, + typename T16, typename T17, typename T18, typename T19, + typename T20, typename T21, typename T22, typename T23, + typename T24, typename T25, typename T26, typename T27, + typename T28, typename T29, typename T30, typename T31 + +> +class KernelFunctorGlobal +{ +private: + Kernel kernel_; + +public: + KernelFunctorGlobal( + Kernel kernel) : + kernel_(kernel) + {} + + KernelFunctorGlobal( + const Program& program, + const STRING_CLASS name, + cl_int * err = NULL) : + kernel_(program, name.c_str(), err) + {} + + Event operator() ( + const EnqueueArgs& args, + T0 t0, + T1 t1 = NullType(), + T2 t2 = NullType(), + T3 t3 = NullType(), + T4 t4 = NullType(), + T5 t5 = NullType(), + T6 t6 = NullType(), + T7 t7 = NullType(), + T8 t8 = NullType(), + T9 t9 = NullType(), + T10 t10 = NullType(), + T11 t11 = NullType(), + T12 t12 = NullType(), + T13 t13 = NullType(), + T14 t14 = NullType(), + T15 t15 = NullType(), + T16 t16 = NullType(), + T17 t17 = NullType(), + T18 t18 = NullType(), + T19 t19 = NullType(), + T20 t20 = NullType(), + T21 t21 = NullType(), + T22 t22 = NullType(), + T23 t23 = NullType(), + T24 t24 = NullType(), + T25 t25 = NullType(), + T26 t26 = NullType(), + T27 t27 = NullType(), + T28 t28 = NullType(), + T29 t29 = NullType(), + T30 t30 = NullType(), + T31 t31 = NullType() + + ) + { + Event event; + SetArg<0, T0>::set(kernel_, t0); + SetArg<1, T1>::set(kernel_, t1); + SetArg<2, T2>::set(kernel_, t2); + SetArg<3, T3>::set(kernel_, t3); + SetArg<4, T4>::set(kernel_, t4); + SetArg<5, T5>::set(kernel_, t5); + SetArg<6, T6>::set(kernel_, t6); + SetArg<7, T7>::set(kernel_, t7); + SetArg<8, T8>::set(kernel_, t8); + SetArg<9, T9>::set(kernel_, t9); + SetArg<10, T10>::set(kernel_, t10); + SetArg<11, T11>::set(kernel_, t11); + SetArg<12, T12>::set(kernel_, t12); + SetArg<13, T13>::set(kernel_, t13); + SetArg<14, T14>::set(kernel_, t14); + SetArg<15, T15>::set(kernel_, t15); + SetArg<16, T16>::set(kernel_, t16); + SetArg<17, T17>::set(kernel_, t17); + SetArg<18, T18>::set(kernel_, t18); + SetArg<19, T19>::set(kernel_, t19); + SetArg<20, T20>::set(kernel_, t20); + SetArg<21, T21>::set(kernel_, t21); + SetArg<22, T22>::set(kernel_, t22); + SetArg<23, T23>::set(kernel_, t23); + SetArg<24, T24>::set(kernel_, t24); + SetArg<25, T25>::set(kernel_, t25); + SetArg<26, T26>::set(kernel_, t26); + SetArg<27, T27>::set(kernel_, t27); + SetArg<28, T28>::set(kernel_, t28); + SetArg<29, T29>::set(kernel_, t29); + SetArg<30, T30>::set(kernel_, t30); + SetArg<31, T31>::set(kernel_, t31); + + + args.queue_.enqueueNDRangeKernel( + kernel_, + args.offset_, + args.global_, + args.local_, + &args.events_, + &event); + + return event; + } + +}; + +//------------------------------------------------------------------------------------------------------ + + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28, + typename T29, + typename T30, + typename T31> +struct functionImplementation_ +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + T31> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 32)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + T31); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28, + T29 arg29, + T30 arg30, + T31 arg31) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28, + arg29, + arg30, + arg31); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28, + typename T29, + typename T30> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 31)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28, + T29 arg29, + T30 arg30) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28, + arg29, + arg30); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28, + typename T29> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 30)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28, + T29 arg29) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28, + arg29); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 29)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 28)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 27)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 26)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 25)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 24)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 23)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 22)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 21)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 20)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 19)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 18)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 17)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 16)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 15)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 14)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 13)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 12)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 11)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 10)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 9)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 8)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 7)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 6)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 5)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 4)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3); + } + + +}; + +template< + typename T0, + typename T1, + typename T2> +struct functionImplementation_ +< T0, + T1, + T2, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 3)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2); + } + + +}; + +template< + typename T0, + typename T1> +struct functionImplementation_ +< T0, + T1, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 2)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1) + { + return functor_( + enqueueArgs, + arg0, + arg1); + } + + +}; + +template< + typename T0> +struct functionImplementation_ +< T0, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 1)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0) + { + return functor_( + enqueueArgs, + arg0); + } + + +}; + + + + + +} // namespace detail + +//---------------------------------------------------------------------------------------------- + +template < + typename T0, typename T1 = detail::NullType, typename T2 = detail::NullType, + typename T3 = detail::NullType, typename T4 = detail::NullType, + typename T5 = detail::NullType, typename T6 = detail::NullType, + typename T7 = detail::NullType, typename T8 = detail::NullType, + typename T9 = detail::NullType, typename T10 = detail::NullType, + typename T11 = detail::NullType, typename T12 = detail::NullType, + typename T13 = detail::NullType, typename T14 = detail::NullType, + typename T15 = detail::NullType, typename T16 = detail::NullType, + typename T17 = detail::NullType, typename T18 = detail::NullType, + typename T19 = detail::NullType, typename T20 = detail::NullType, + typename T21 = detail::NullType, typename T22 = detail::NullType, + typename T23 = detail::NullType, typename T24 = detail::NullType, + typename T25 = detail::NullType, typename T26 = detail::NullType, + typename T27 = detail::NullType, typename T28 = detail::NullType, + typename T29 = detail::NullType, typename T30 = detail::NullType, + typename T31 = detail::NullType + +> +struct make_kernel : + public detail::functionImplementation_< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + > +{ +public: + typedef detail::KernelFunctorGlobal< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + > FunctorType; + + make_kernel( + const Program& program, + const STRING_CLASS name, + cl_int * err = NULL) : + detail::functionImplementation_< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + >( + FunctorType(program, name, err)) + {} + + make_kernel( + const Kernel kernel) : + detail::functionImplementation_< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + >( + FunctorType(kernel)) + {} +}; + + +//---------------------------------------------------------------------------------------------------------------------- + +#undef __ERR_STR +#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS) +#undef __GET_DEVICE_INFO_ERR +#undef __GET_PLATFORM_INFO_ERR +#undef __GET_DEVICE_IDS_ERR +#undef __GET_CONTEXT_INFO_ERR +#undef __GET_EVENT_INFO_ERR +#undef __GET_EVENT_PROFILE_INFO_ERR +#undef __GET_MEM_OBJECT_INFO_ERR +#undef __GET_IMAGE_INFO_ERR +#undef __GET_SAMPLER_INFO_ERR +#undef __GET_KERNEL_INFO_ERR +#undef __GET_KERNEL_ARG_INFO_ERR +#undef __GET_KERNEL_WORK_GROUP_INFO_ERR +#undef __GET_PROGRAM_INFO_ERR +#undef __GET_PROGRAM_BUILD_INFO_ERR +#undef __GET_COMMAND_QUEUE_INFO_ERR + +#undef __CREATE_CONTEXT_ERR +#undef __CREATE_CONTEXT_FROM_TYPE_ERR +#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR + +#undef __CREATE_BUFFER_ERR +#undef __CREATE_SUBBUFFER_ERR +#undef __CREATE_IMAGE2D_ERR +#undef __CREATE_IMAGE3D_ERR +#undef __CREATE_SAMPLER_ERR +#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR + +#undef __CREATE_USER_EVENT_ERR +#undef __SET_USER_EVENT_STATUS_ERR +#undef __SET_EVENT_CALLBACK_ERR +#undef __SET_PRINTF_CALLBACK_ERR + +#undef __WAIT_FOR_EVENTS_ERR + +#undef __CREATE_KERNEL_ERR +#undef __SET_KERNEL_ARGS_ERR +#undef __CREATE_PROGRAM_WITH_SOURCE_ERR +#undef __CREATE_PROGRAM_WITH_BINARY_ERR +#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR +#undef __BUILD_PROGRAM_ERR +#undef __CREATE_KERNELS_IN_PROGRAM_ERR + +#undef __CREATE_COMMAND_QUEUE_ERR +#undef __SET_COMMAND_QUEUE_PROPERTY_ERR +#undef __ENQUEUE_READ_BUFFER_ERR +#undef __ENQUEUE_WRITE_BUFFER_ERR +#undef __ENQUEUE_READ_BUFFER_RECT_ERR +#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR +#undef __ENQEUE_COPY_BUFFER_ERR +#undef __ENQEUE_COPY_BUFFER_RECT_ERR +#undef __ENQUEUE_READ_IMAGE_ERR +#undef __ENQUEUE_WRITE_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR +#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR +#undef __ENQUEUE_MAP_BUFFER_ERR +#undef __ENQUEUE_MAP_IMAGE_ERR +#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR +#undef __ENQUEUE_NDRANGE_KERNEL_ERR +#undef __ENQUEUE_TASK_ERR +#undef __ENQUEUE_NATIVE_KERNEL + +#undef __CL_EXPLICIT_CONSTRUCTORS + +#undef __UNLOAD_COMPILER_ERR +#endif //__CL_USER_OVERRIDE_ERROR_STRINGS + +#undef __CL_FUNCTION_TYPE + +// Extensions +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_VERSION_1_1) +#undef __INIT_CL_EXT_FCN_PTR +#endif // #if defined(CL_VERSION_1_1) +#undef __CREATE_SUB_DEVICES + +#if defined(USE_CL_DEVICE_FISSION) +#undef __PARAM_NAME_DEVICE_FISSION +#endif // USE_CL_DEVICE_FISSION + +#undef __DEFAULT_NOT_INITIALIZED +#undef __DEFAULT_BEING_INITIALIZED +#undef __DEFAULT_INITIALIZED + +#undef CL_HPP_RVALUE_REFERENCES_SUPPORTED +#undef CL_HPP_NOEXCEPT + +} // namespace cl + +#endif // CL_HPP_ diff --git a/opencl/khronos/headers/opencl2.1/CL/cl2.hpp b/opencl/khronos/headers/opencl2.1/CL/cl2.hpp new file mode 100644 index 0000000000..4d9ca2363a --- /dev/null +++ b/opencl/khronos/headers/opencl2.1/CL/cl2.hpp @@ -0,0 +1,9579 @@ +/* Modifications Copyright(C)[2021-2022] Advanced Micro Devices, Inc. + * All rights reserved. + * */ + +/******************************************************************************* + * Copyright (c) 2008-2016 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +/*! \file + * + * \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33), + * OpenCL 1.2 (rev 15) and OpenCL 2.0 (rev 29) + * \author Lee Howes and Bruce Merry + * + * Derived from the OpenCL 1.x C++ bindings written by + * Benedict R. Gaster, Laurent Morichetti and Lee Howes + * With additions and fixes from: + * Brian Cole, March 3rd 2010 and April 2012 + * Matt Gruenke, April 2012. + * Bruce Merry, February 2013. + * Tom Deakin and Simon McIntosh-Smith, July 2013 + * James Price, 2015- + * + * \version 2.0.10 + * \date 2016-07-20 + * + * Optional extension support + * + * cl_ext_device_fission + * #define CL_HPP_USE_CL_DEVICE_FISSION + * cl_khr_d3d10_sharing + * #define CL_HPP_USE_DX_INTEROP + * cl_khr_sub_groups + * #define CL_HPP_USE_CL_SUB_GROUPS_KHR + * cl_khr_image2d_from_buffer + * #define CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR + * + * Doxygen documentation for this header is available here: + * + * http://khronosgroup.github.io/OpenCL-CLHPP/ + * + * The latest version of this header can be found on the GitHub releases page: + * + * https://github.com/KhronosGroup/OpenCL-CLHPP/releases + * + * Bugs and patches can be submitted to the GitHub repository: + * + * https://github.com/KhronosGroup/OpenCL-CLHPP + */ + +/*! \mainpage + * \section intro Introduction + * For many large applications C++ is the language of choice and so it seems + * reasonable to define C++ bindings for OpenCL. + * + * The interface is contained with a single C++ header file \em cl2.hpp and all + * definitions are contained within the namespace \em cl. There is no additional + * requirement to include \em cl.h and to use either the C++ or original C + * bindings; it is enough to simply include \em cl2.hpp. + * + * The bindings themselves are lightweight and correspond closely to the + * underlying C API. Using the C++ bindings introduces no additional execution + * overhead. + * + * There are numerous compatibility, portability and memory management + * fixes in the new header as well as additional OpenCL 2.0 features. + * As a result the header is not directly backward compatible and for this + * reason we release it as cl2.hpp rather than a new version of cl.hpp. + * + * + * \section compatibility Compatibility + * Due to the evolution of the underlying OpenCL API the 2.0 C++ bindings + * include an updated approach to defining supported feature versions + * and the range of valid underlying OpenCL runtime versions supported. + * + * The combination of preprocessor macros CL_HPP_TARGET_OPENCL_VERSION and + * CL_HPP_MINIMUM_OPENCL_VERSION control this range. These are three digit + * decimal values representing OpenCL runime versions. The default for + * the target is 200, representing OpenCL 2.0 and the minimum is also + * defined as 200. These settings would use 2.0 API calls only. + * If backward compatibility with a 1.2 runtime is required, the minimum + * version may be set to 120. + * + * Note that this is a compile-time setting, and so affects linking against + * a particular SDK version rather than the versioning of the loaded runtime. + * + * The earlier versions of the header included basic vector and string + * classes based loosely on STL versions. These were difficult to + * maintain and very rarely used. For the 2.0 header we now assume + * the presence of the standard library unless requested otherwise. + * We use std::array, std::vector, std::shared_ptr and std::string + * throughout to safely manage memory and reduce the chance of a + * recurrance of earlier memory management bugs. + * + * These classes are used through typedefs in the cl namespace: + * cl::array, cl::vector, cl::pointer and cl::string. + * In addition cl::allocate_pointer forwards to std::allocate_shared + * by default. + * In all cases these standard library classes can be replaced with + * custom interface-compatible versions using the CL_HPP_NO_STD_ARRAY, + * CL_HPP_NO_STD_VECTOR, CL_HPP_NO_STD_UNIQUE_PTR and + * CL_HPP_NO_STD_STRING macros. + * + * The OpenCL 1.x versions of the C++ bindings included a size_t wrapper + * class to interface with kernel enqueue. This caused unpleasant interactions + * with the standard size_t declaration and led to namespacing bugs. + * In the 2.0 version we have replaced this with a std::array-based interface. + * However, the old behaviour can be regained for backward compatibility + * using the CL_HPP_ENABLE_SIZE_T_COMPATIBILITY macro. + * + * Finally, the program construction interface used a clumsy vector-of-pairs + * design in the earlier versions. We have replaced that with a cleaner + * vector-of-vectors and vector-of-strings design. However, for backward + * compatibility old behaviour can be regained with the + * CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY macro. + * + * In OpenCL 2.0 OpenCL C is not entirely backward compatibility with + * earlier versions. As a result a flag must be passed to the OpenCL C + * compiled to request OpenCL 2.0 compilation of kernels with 1.2 as + * the default in the absence of the flag. + * In some cases the C++ bindings automatically compile code for ease. + * For those cases the compilation defaults to OpenCL C 2.0. + * If this is not wanted, the CL_HPP_CL_1_2_DEFAULT_BUILD macro may + * be specified to assume 1.2 compilation. + * If more fine-grained decisions on a per-kernel bases are required + * then explicit build operations that take the flag should be used. + * + * + * \section parameterization Parameters + * This header may be parameterized by a set of preprocessor macros. + * + * - CL_HPP_TARGET_OPENCL_VERSION + * + * Defines the target OpenCL runtime version to build the header + * against. Defaults to 200, representing OpenCL 2.0. + * + * - CL_HPP_NO_STD_STRING + * + * Do not use the standard library string class. cl::string is not + * defined and may be defined by the user before cl2.hpp is + * included. + * + * - CL_HPP_NO_STD_VECTOR + * + * Do not use the standard library vector class. cl::vector is not + * defined and may be defined by the user before cl2.hpp is + * included. + * + * - CL_HPP_NO_STD_ARRAY + * + * Do not use the standard library array class. cl::array is not + * defined and may be defined by the user before cl2.hpp is + * included. + * + * - CL_HPP_NO_STD_UNIQUE_PTR + * + * Do not use the standard library unique_ptr class. cl::pointer and + * the cl::allocate_pointer functions are not defined and may be + * defined by the user before cl2.hpp is included. + * + * - CL_HPP_ENABLE_DEVICE_FISSION + * + * Enables device fission for OpenCL 1.2 platforms. + * + * - CL_HPP_ENABLE_EXCEPTIONS + * + * Enable exceptions for use in the C++ bindings header. This is the + * preferred error handling mechanism but is not required. + * + * - CL_HPP_ENABLE_SIZE_T_COMPATIBILITY + * + * Backward compatibility option to support cl.hpp-style size_t + * class. Replaces the updated std::array derived version and + * removal of size_t from the namespace. Note that in this case the + * new size_t class is placed in the cl::compatibility namespace and + * thus requires an additional using declaration for direct backward + * compatibility. + * + * - CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY + * + * Enable older vector of pairs interface for construction of + * programs. + * + * - CL_HPP_CL_1_2_DEFAULT_BUILD + * + * Default to OpenCL C 1.2 compilation rather than OpenCL C 2.0 + * applies to use of cl::Program construction and other program + * build variants. + * + * + * \section example Example + * + * The following example shows a general use case for the C++ + * bindings, including support for the optional exception feature and + * also the supplied vector and string classes, see following sections for + * decriptions of these features. + * + * \code + #define CL_HPP_ENABLE_EXCEPTIONS + #define CL_HPP_TARGET_OPENCL_VERSION 200 + + #include + #include + #include + #include + #include + + const int numElements = 32; + + int main(void) + { + // Filter for a 2.0 platform and set it as the default + std::vector platforms; + cl::Platform::get(&platforms); + cl::Platform plat; + for (auto &p : platforms) { + std::string platver = p.getInfo(); + if (platver.find("OpenCL 2.") != std::string::npos) { + plat = p; + } + } + if (plat() == 0) { + std::cout << "No OpenCL 2.0 platform found."; + return -1; + } + + cl::Platform newP = cl::Platform::setDefault(plat); + if (newP != plat) { + std::cout << "Error setting default platform."; + return -1; + } + + // Use C++11 raw string literals for kernel source code + std::string kernel1{R"CLC( + global int globalA; + kernel void updateGlobal() + { + globalA = 75; + } + )CLC"}; + std::string kernel2{R"CLC( + typedef struct { global int *bar; } Foo; + kernel void vectorAdd(global const Foo* aNum, global const int *inputA, global const int *inputB, + global int *output, int val, write_only pipe int outPipe, queue_t childQueue) + { + output[get_global_id(0)] = inputA[get_global_id(0)] + inputB[get_global_id(0)] + val + *(aNum->bar); + write_pipe(outPipe, &val); + queue_t default_queue = get_default_queue(); + ndrange_t ndrange = ndrange_1D(get_global_size(0)/2, get_global_size(0)/2); + + // Have a child kernel write into third quarter of output + enqueue_kernel(default_queue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, + ^{ + output[get_global_size(0)*2 + get_global_id(0)] = + inputA[get_global_size(0)*2 + get_global_id(0)] + inputB[get_global_size(0)*2 + get_global_id(0)] + globalA; + }); + + // Have a child kernel write into last quarter of output + enqueue_kernel(childQueue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, + ^{ + output[get_global_size(0)*3 + get_global_id(0)] = + inputA[get_global_size(0)*3 + get_global_id(0)] + inputB[get_global_size(0)*3 + get_global_id(0)] + globalA + 2; + }); + } + )CLC"}; + + // New simpler string interface style + std::vector programStrings {kernel1, kernel2}; + + cl::Program vectorAddProgram(programStrings); + try { + vectorAddProgram.build("-cl-std=CL2.0"); + } + catch (...) { + // Print build info for all devices + cl_int buildErr = CL_SUCCESS; + auto buildInfo = vectorAddProgram.getBuildInfo(&buildErr); + for (auto &pair : buildInfo) { + std::cerr << pair.second << std::endl << std::endl; + } + + return 1; + } + + typedef struct { int *bar; } Foo; + + // Get and run kernel that initializes the program-scope global + // A test for kernels that take no arguments + auto program2Kernel = + cl::KernelFunctor<>(vectorAddProgram, "updateGlobal"); + program2Kernel( + cl::EnqueueArgs( + cl::NDRange(1))); + + ////////////////// + // SVM allocations + + auto anSVMInt = cl::allocate_svm>(); + *anSVMInt = 5; + cl::SVMAllocator>> svmAllocReadOnly; + auto fooPointer = cl::allocate_pointer(svmAllocReadOnly); + fooPointer->bar = anSVMInt.get(); + cl::SVMAllocator> svmAlloc; + std::vector>> inputA(numElements, 1, svmAlloc); + cl::coarse_svm_vector inputB(numElements, 2, svmAlloc); + + // + ////////////// + + // Traditional cl_mem allocations + std::vector output(numElements, 0xdeadbeef); + cl::Buffer outputBuffer(begin(output), end(output), false); + cl::Pipe aPipe(sizeof(cl_int), numElements / 2); + + // Default command queue, also passed in as a parameter + cl::DeviceCommandQueue defaultDeviceQueue = cl::DeviceCommandQueue::makeDefault( + cl::Context::getDefault(), cl::Device::getDefault()); + + auto vectorAddKernel = + cl::KernelFunctor< + decltype(fooPointer)&, + int*, + cl::coarse_svm_vector&, + cl::Buffer, + int, + cl::Pipe&, + cl::DeviceCommandQueue + >(vectorAddProgram, "vectorAdd"); + + // Ensure that the additional SVM pointer is available to the kernel + // This one was not passed as a parameter + vectorAddKernel.setSVMPointers(anSVMInt); + + // Hand control of coarse allocations to runtime + cl::enqueueUnmapSVM(anSVMInt); + cl::enqueueUnmapSVM(fooPointer); + cl::unmapSVM(inputB); + cl::unmapSVM(output2); + + cl_int error; + vectorAddKernel( + cl::EnqueueArgs( + cl::NDRange(numElements/2), + cl::NDRange(numElements/2)), + fooPointer, + inputA.data(), + inputB, + outputBuffer, + 3, + aPipe, + defaultDeviceQueue, + error + ); + + cl::copy(outputBuffer, begin(output), end(output)); + // Grab the SVM output vector using a map + cl::mapSVM(output2); + + cl::Device d = cl::Device::getDefault(); + + std::cout << "Output:\n"; + for (int i = 1; i < numElements; ++i) { + std::cout << "\t" << output[i] << "\n"; + } + std::cout << "\n\n"; + + return 0; + } + * + * \endcode + * + */ +#ifndef CL_HPP_ +#define CL_HPP_ + +/* Handle deprecated preprocessor definitions. In each case, we only check for + * the old name if the new name is not defined, so that user code can define + * both and hence work with either version of the bindings. + */ +#if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP) +# pragma message("cl2.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead") +# define CL_HPP_USE_DX_INTEROP +#endif +#if !defined(CL_HPP_USE_CL_DEVICE_FISSION) && defined(USE_CL_DEVICE_FISSION) +# pragma message("cl2.hpp: USE_CL_DEVICE_FISSION is deprecated. Define CL_HPP_USE_CL_DEVICE_FISSION instead") +# define CL_HPP_USE_CL_DEVICE_FISSION +#endif +#if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS) +# pragma message("cl2.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead") +# define CL_HPP_ENABLE_EXCEPTIONS +#endif +#if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR) +# pragma message("cl2.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead") +# define CL_HPP_NO_STD_VECTOR +#endif +#if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING) +# pragma message("cl2.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead") +# define CL_HPP_NO_STD_STRING +#endif +#if defined(VECTOR_CLASS) +# pragma message("cl2.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead") +#endif +#if defined(STRING_CLASS) +# pragma message("cl2.hpp: STRING_CLASS is deprecated. Alias cl::string instead.") +#endif +#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS) +# pragma message("cl2.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead") +# define CL_HPP_USER_OVERRIDE_ERROR_STRINGS +#endif + +/* Warn about features that are no longer supported + */ +#if defined(__USE_DEV_VECTOR) +# pragma message("cl2.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors") +#endif +#if defined(__USE_DEV_STRING) +# pragma message("cl2.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors") +#endif + +/* Detect which version to target */ +#if !defined(CL_HPP_TARGET_OPENCL_VERSION) +# pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 200 (OpenCL 2.0)") +# define CL_HPP_TARGET_OPENCL_VERSION 200 +#endif +#if CL_HPP_TARGET_OPENCL_VERSION != 100 && CL_HPP_TARGET_OPENCL_VERSION != 110 && CL_HPP_TARGET_OPENCL_VERSION != 120 && CL_HPP_TARGET_OPENCL_VERSION != 200 +# pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120 or 200). It will be set to 200") +# undef CL_HPP_TARGET_OPENCL_VERSION +# define CL_HPP_TARGET_OPENCL_VERSION 200 +#endif + +#if !defined(CL_HPP_MINIMUM_OPENCL_VERSION) +# define CL_HPP_MINIMUM_OPENCL_VERSION 200 +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && CL_HPP_MINIMUM_OPENCL_VERSION != 110 && CL_HPP_MINIMUM_OPENCL_VERSION != 120 && CL_HPP_MINIMUM_OPENCL_VERSION != 200 +# pragma message("cl2.hpp: CL_HPP_MINIMUM_OPENCL_VERSION is not a valid value (100, 110, 120 or 200). It will be set to 100") +# undef CL_HPP_MINIMUM_OPENCL_VERSION +# define CL_HPP_MINIMUM_OPENCL_VERSION 100 +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION +# error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION" +#endif + +#if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS) +# define CL_USE_DEPRECATED_OPENCL_1_0_APIS +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +# define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) +# define CL_USE_DEPRECATED_OPENCL_1_2_APIS +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS) +# define CL_USE_DEPRECATED_OPENCL_2_0_APIS +#endif + +#ifdef _WIN32 + +#include + +#if defined(CL_HPP_USE_DX_INTEROP) +#include +#include +#endif +#endif // _WIN32 + +#if defined(_MSC_VER) +#include +#endif // _MSC_VER + + // Check for a valid C++ version + +// Need to do both tests here because for some reason __cplusplus is not +// updated in visual studio +#if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700) +#error Visual studio 2013 or another C++11-supporting compiler required +#endif + +// +#if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) +#include +#endif + +#if defined(__APPLE__) || defined(__MACOSX) +#include +#else +#include +#endif // !__APPLE__ + +#if (__cplusplus >= 201103L) +#define CL_HPP_NOEXCEPT_ noexcept +#else +#define CL_HPP_NOEXCEPT_ +#endif + +#if defined(_MSC_VER) +# define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany) +#else +# define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak)) +#endif // !_MSC_VER + +// Define deprecated prefixes and suffixes to ensure compilation +// in case they are not pre-defined +#if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) + +#if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED) +#define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED) +#if !defined(CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED) +#define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED) + +#if !defined(CL_CALLBACK) +#define CL_CALLBACK +#endif //CL_CALLBACK + +#include +#include +#include +#include +#include +#include + + +// Define a size_type to represent a correctly resolved size_t +#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) +namespace cl { + using size_type = ::size_t; +} // namespace cl +#else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) +namespace cl { + using size_type = size_t; +} // namespace cl +#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) + + +#if defined(CL_HPP_ENABLE_EXCEPTIONS) +#include +#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS) + +#if !defined(CL_HPP_NO_STD_VECTOR) +#include +namespace cl { + template < class T, class Alloc = std::allocator > + using vector = std::vector; +} // namespace cl +#endif // #if !defined(CL_HPP_NO_STD_VECTOR) + +#if !defined(CL_HPP_NO_STD_STRING) +#include +namespace cl { + using string = std::string; +} // namespace cl +#endif // #if !defined(CL_HPP_NO_STD_STRING) + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +#if !defined(CL_HPP_NO_STD_UNIQUE_PTR) +#include +namespace cl { + // Replace unique_ptr and allocate_pointer for internal use + // to allow user to replace them + template + using pointer = std::unique_ptr; +} // namespace cl +#endif +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 +#if !defined(CL_HPP_NO_STD_ARRAY) +#include +namespace cl { + template < class T, size_type N > + using array = std::array; +} // namespace cl +#endif // #if !defined(CL_HPP_NO_STD_ARRAY) + +// Define size_type appropriately to allow backward-compatibility +// use of the old size_t interface class +#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) +namespace cl { + namespace compatibility { + /*! \brief class used to interface between C++ and + * OpenCL C calls that require arrays of size_t values, whose + * size is known statically. + */ + template + class size_t + { + private: + size_type data_[N]; + + public: + //! \brief Initialize size_t to all 0s + size_t() + { + for (int i = 0; i < N; ++i) { + data_[i] = 0; + } + } + + size_t(const array &rhs) + { + for (int i = 0; i < N; ++i) { + data_[i] = rhs[i]; + } + } + + size_type& operator[](int index) + { + return data_[index]; + } + + const size_type& operator[](int index) const + { + return data_[index]; + } + + //! \brief Conversion operator to T*. + operator size_type* () { return data_; } + + //! \brief Conversion operator to const T*. + operator const size_type* () const { return data_; } + + operator array() const + { + array ret; + + for (int i = 0; i < N; ++i) { + ret[i] = data_[i]; + } + return ret; + } + }; + } // namespace compatibility + + template + using size_t = compatibility::size_t; +} // namespace cl +#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) + +// Helper alias to avoid confusing the macros +namespace cl { + namespace detail { + using size_t_array = array; + } // namespace detail +} // namespace cl + + +/*! \namespace cl + * + * \brief The OpenCL C++ bindings are defined within this namespace. + * + */ +namespace cl { + class Memory; + +#define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \ + if (!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddress(#name); \ + if (!pfn_##name) { \ + } \ + } + +#define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \ + if (!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddressForPlatform(platform, #name); \ + if (!pfn_##name) { \ + } \ + } + + class Program; + class Device; + class Context; + class CommandQueue; + class DeviceCommandQueue; + class Memory; + class Buffer; + class Pipe; + +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + /*! \brief Exception class + * + * This may be thrown by API functions when CL_HPP_ENABLE_EXCEPTIONS is defined. + */ + class Error : public std::exception + { + private: + cl_int err_; + const char * errStr_; + public: + /*! \brief Create a new CL error exception for a given error code + * and corresponding message. + * + * \param err error code value. + * + * \param errStr a descriptive string that must remain in scope until + * handling of the exception has concluded. If set, it + * will be returned by what(). + */ + Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr) + {} + + ~Error() throw() {} + + /*! \brief Get error string associated with exception + * + * \return A memory pointer to the error message string. + */ + virtual const char * what() const throw () + { + if (errStr_ == NULL) { + return "empty"; + } + else { + return errStr_; + } + } + + /*! \brief Get error code associated with exception + * + * \return The error code. + */ + cl_int err(void) const { return err_; } + }; +#define CL_HPP_ERR_STR_(x) #x +#else +#define CL_HPP_ERR_STR_(x) NULL +#endif // CL_HPP_ENABLE_EXCEPTIONS + + +namespace detail +{ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) +static inline cl_int errHandler ( + cl_int err, + const char * errStr = NULL) +{ + if (err != CL_SUCCESS) { + throw Error(err, errStr); + } + return err; +} +#else +static inline cl_int errHandler (cl_int err, const char * errStr = NULL) +{ + (void) errStr; // suppress unused variable warning + return err; +} +#endif // CL_HPP_ENABLE_EXCEPTIONS +} + + + +//! \cond DOXYGEN_DETAIL +#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) +#define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo) +#define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo) +#define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs) +#define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs) +#define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo) +#define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo) +#define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo) +#define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo) +#define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo) +#define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo) +#define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo) +#define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo) +#define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo) +#define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo) + +#define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext) +#define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType) +#define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats) + +#define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer) +#define __COPY_ERR CL_HPP_ERR_STR_(cl::copy) +#define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer) +#define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer) +#define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer) +#define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage) +#define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture) +#define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback) + +#define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent) +#define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus) +#define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback) +#define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents) + +#define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel) +#define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg) +#define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource) +#define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram) +#define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram) + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +#define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties) +#define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200 +#define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty) +#define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer) +#define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect) +#define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer) +#define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect) +#define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer) +#define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect) +#define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer) +#define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage) +#define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage) +#define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage) +#define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage) +#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer) +#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage) +#define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer) +#define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage) +#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject) +#define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel) +#define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + +#define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects) +#define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects) + +#define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe) +#define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo) + + +#define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object) +#define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object) +#define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush) +#define __FINISH_ERR CL_HPP_ERR_STR_(clFinish) +#define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error) + +/** + * CL 1.2 version that uses device fission. + */ +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices) +#else +#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +#define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker) +#define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents) +#define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier) +#define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler) +#define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D) +#define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D) +#define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D) +#define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D) +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +/** + * Deprecated APIs for 2.0 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) +#define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue) +#define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask) +#define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler) +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +/** + * CL 1.2 marker and barrier commands + */ +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList) +#define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + +#endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS +//! \endcond + + +namespace detail { + +// Generic getInfoHelper. The final parameter is used to guide overload +// resolution: the actual parameter passed is an int, which makes this +// a worse conversion sequence than a specialization that declares the +// parameter as an int. +template +inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long) +{ + return f(name, sizeof(T), param, NULL); +} + +// Specialized for getInfo +// Assumes that the output vector was correctly resized on the way in +template +inline cl_int getInfoHelper(Func f, cl_uint name, vector>* param, int) +{ + if (name != CL_PROGRAM_BINARIES) { + return CL_INVALID_VALUE; + } + if (param) { + // Create array of pointers, calculate total size and pass pointer array in + size_type numBinaries = param->size(); + vector binariesPointers(numBinaries); + + for (size_type i = 0; i < numBinaries; ++i) + { + binariesPointers[i] = (*param)[i].data(); + } + + cl_int err = f(name, numBinaries * sizeof(unsigned char*), binariesPointers.data(), NULL); + + if (err != CL_SUCCESS) { + return err; + } + } + + + return CL_SUCCESS; +} + +// Specialized getInfoHelper for vector params +template +inline cl_int getInfoHelper(Func f, cl_uint name, vector* param, long) +{ + size_type required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + const size_type elements = required / sizeof(T); + + // Temporary to avoid changing param on an error + vector localData(elements); + err = f(name, required, localData.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + if (param) { + *param = std::move(localData); + } + + return CL_SUCCESS; +} + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper( + Func f, cl_uint name, vector* param, int, typename T::cl_type = 0) +{ + size_type required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + const size_type elements = required / sizeof(typename T::cl_type); + + vector value(elements); + err = f(name, required, value.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + + if (param) { + // Assign to convert CL type to T for each element + param->resize(elements); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < elements; i++) { + (*param)[i] = T(value[i], true); + } + } + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for string params +template +inline cl_int getInfoHelper(Func f, cl_uint name, string* param, long) +{ + size_type required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + // std::string has a constant data member + // a char vector does not + if (required > 0) { + vector value(required); + err = f(name, required, value.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + if (param) { + param->assign(begin(value), prev(end(value))); + } + } + else if (param) { + param->assign(""); + } + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for clsize_t params +template +inline cl_int getInfoHelper(Func f, cl_uint name, array* param, long) +{ + size_type required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + size_type elements = required / sizeof(size_type); + vector value(elements, 0); + + err = f(name, required, value.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + + // Bound the copy with N to prevent overruns + // if passed N > than the amount copied + if (elements > N) { + elements = N; + } + for (size_type i = 0; i < elements; ++i) { + (*param)[i] = value[i]; + } + + return CL_SUCCESS; +} + +template struct ReferenceHandler; + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0) +{ + typename T::cl_type value; + cl_int err = f(name, sizeof(value), &value, NULL); + if (err != CL_SUCCESS) { + return err; + } + *param = value; + if (value != NULL) + { + err = param->retain(); + if (err != CL_SUCCESS) { + return err; + } + } + return CL_SUCCESS; +} + +#define CL_HPP_PARAM_NAME_INFO_1_0_(F) \ + F(cl_platform_info, CL_PLATFORM_PROFILE, string) \ + F(cl_platform_info, CL_PLATFORM_VERSION, string) \ + F(cl_platform_info, CL_PLATFORM_NAME, string) \ + F(cl_platform_info, CL_PLATFORM_VENDOR, string) \ + F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \ + \ + F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \ + F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \ + F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \ + F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \ + F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \ + F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \ + F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \ + F(cl_device_info, CL_DEVICE_NAME, string) \ + F(cl_device_info, CL_DEVICE_VENDOR, string) \ + F(cl_device_info, CL_DRIVER_VERSION, string) \ + F(cl_device_info, CL_DEVICE_PROFILE, string) \ + F(cl_device_info, CL_DEVICE_VERSION, string) \ + F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \ + \ + F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \ + F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector) \ + F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector) \ + \ + F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \ + F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \ + F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \ + F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \ + \ + F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \ + \ + F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \ + F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \ + F(cl_mem_info, CL_MEM_SIZE, size_type) \ + F(cl_mem_info, CL_MEM_HOST_PTR, void*) \ + F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \ + \ + F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \ + F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \ + F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \ + F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \ + F(cl_image_info, CL_IMAGE_WIDTH, size_type) \ + F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \ + F(cl_image_info, CL_IMAGE_DEPTH, size_type) \ + \ + F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \ + F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \ + F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \ + F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \ + F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \ + \ + F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \ + F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \ + F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \ + F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector) \ + F(cl_program_info, CL_PROGRAM_SOURCE, string) \ + F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector) \ + F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector>) \ + \ + F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \ + \ + F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \ + F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \ + F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \ + F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \ + F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \ + \ + F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \ + F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \ + F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \ + F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties) + + +#define CL_HPP_PARAM_NAME_INFO_1_1_(F) \ + F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \ + \ + F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \ + F(cl_mem_info, CL_MEM_OFFSET, size_type) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \ + F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \ + \ + F(cl_event_info, CL_EVENT_CONTEXT, cl::Context) + +#define CL_HPP_PARAM_NAME_INFO_1_2_(F) \ + F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \ + F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \ + \ + F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \ + \ + F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \ + \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \ + \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \ + F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, size_type) \ + F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \ + F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \ + \ + F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \ + F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \ + F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint) + +#define CL_HPP_PARAM_NAME_INFO_2_0_(F) \ + F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \ + F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \ + F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \ + F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \ + F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE, size_type) \ + F(cl_device_info, CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE, size_type) \ + F(cl_device_info, CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS, cl_uint) \ + F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \ + F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \ + F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \ + F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint) + +#define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector) \ + F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \ + F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector) + +template +struct param_traits {}; + +#define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \ +struct token; \ +template<> \ +struct param_traits \ +{ \ + enum { value = param_name }; \ + typedef T param_type; \ +}; + +CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 +CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + + +// Flags deprecated in OpenCL 2.0 +#define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \ + F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) + +#define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \ + F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) + +#define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \ + F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer) + +// Include deprecated query flags based on versions +// Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash +#if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200 +CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110 +#if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 +CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120 +#if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 +CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200 + +#if defined(CL_HPP_USE_CL_DEVICE_FISSION) +CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_); +#endif // CL_HPP_USE_CL_DEVICE_FISSION + +#ifdef CL_PLATFORM_ICD_SUFFIX_KHR +CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string) +#endif + +#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong) +#endif + +#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector) +#endif +#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_WIDTH_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint) +#endif + +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint) +#endif +#ifdef CL_DEVICE_WARP_SIZE_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint) +#endif +#ifdef CL_DEVICE_GPU_OVERLAP_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool) +#endif +#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool) +#endif +#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool) +#endif + +// Convenience functions + +template +inline cl_int +getInfo(Func f, cl_uint name, T* param) +{ + return getInfoHelper(f, name, param, 0); +} + +template +struct GetInfoFunctor0 +{ + Func f_; const Arg0& arg0_; + cl_int operator ()( + cl_uint param, size_type size, void* value, size_type* size_ret) + { return f_(arg0_, param, size, value, size_ret); } +}; + +template +struct GetInfoFunctor1 +{ + Func f_; const Arg0& arg0_; const Arg1& arg1_; + cl_int operator ()( + cl_uint param, size_type size, void* value, size_type* size_ret) + { return f_(arg0_, arg1_, param, size, value, size_ret); } +}; + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, cl_uint name, T* param) +{ + GetInfoFunctor0 f0 = { f, arg0 }; + return getInfoHelper(f0, name, param, 0); +} + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param) +{ + GetInfoFunctor1 f0 = { f, arg0, arg1 }; + return getInfoHelper(f0, name, param, 0); +} + + +template +struct ReferenceHandler +{ }; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +/** + * OpenCL 1.2 devices do have retain/release. + */ +template <> +struct ReferenceHandler +{ + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int retain(cl_device_id device) + { return ::clRetainDevice(device); } + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int release(cl_device_id device) + { return ::clReleaseDevice(device); } +}; +#else // CL_HPP_TARGET_OPENCL_VERSION >= 120 +/** + * OpenCL 1.1 devices do not have retain/release. + */ +template <> +struct ReferenceHandler +{ + // cl_device_id does not have retain(). + static cl_int retain(cl_device_id) + { return CL_SUCCESS; } + // cl_device_id does not have release(). + static cl_int release(cl_device_id) + { return CL_SUCCESS; } +}; +#endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120) + +template <> +struct ReferenceHandler +{ + // cl_platform_id does not have retain(). + static cl_int retain(cl_platform_id) + { return CL_SUCCESS; } + // cl_platform_id does not have release(). + static cl_int release(cl_platform_id) + { return CL_SUCCESS; } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_context context) + { return ::clRetainContext(context); } + static cl_int release(cl_context context) + { return ::clReleaseContext(context); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_command_queue queue) + { return ::clRetainCommandQueue(queue); } + static cl_int release(cl_command_queue queue) + { return ::clReleaseCommandQueue(queue); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_mem memory) + { return ::clRetainMemObject(memory); } + static cl_int release(cl_mem memory) + { return ::clReleaseMemObject(memory); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_sampler sampler) + { return ::clRetainSampler(sampler); } + static cl_int release(cl_sampler sampler) + { return ::clReleaseSampler(sampler); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_program program) + { return ::clRetainProgram(program); } + static cl_int release(cl_program program) + { return ::clReleaseProgram(program); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_kernel kernel) + { return ::clRetainKernel(kernel); } + static cl_int release(cl_kernel kernel) + { return ::clReleaseKernel(kernel); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_event event) + { return ::clRetainEvent(event); } + static cl_int release(cl_event event) + { return ::clReleaseEvent(event); } +}; + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120 +// Extracts version number with major in the upper 16 bits, minor in the lower 16 +static cl_uint getVersion(const vector &versionInfo) +{ + int highVersion = 0; + int lowVersion = 0; + int index = 7; + while(versionInfo[index] != '.' ) { + highVersion *= 10; + highVersion += versionInfo[index]-'0'; + ++index; + } + ++index; + while(versionInfo[index] != ' ' && versionInfo[index] != '\0') { + lowVersion *= 10; + lowVersion += versionInfo[index]-'0'; + ++index; + } + return (highVersion << 16) | lowVersion; +} + +static cl_uint getPlatformVersion(cl_platform_id platform) +{ + size_type size = 0; + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size); + + vector versionInfo(size); + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size); + return getVersion(versionInfo); +} + +static cl_uint getDevicePlatformVersion(cl_device_id device) +{ + cl_platform_id platform; + clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL); + return getPlatformVersion(platform); +} + +static cl_uint getContextPlatformVersion(cl_context context) +{ + // The platform cannot be queried directly, so we first have to grab a + // device and obtain its context + size_type size = 0; + clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size); + if (size == 0) + return 0; + vector devices(size/sizeof(cl_device_id)); + clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL); + return getDevicePlatformVersion(devices[0]); +} +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120 + +template +class Wrapper +{ +public: + typedef T cl_type; + +protected: + cl_type object_; + +public: + Wrapper() : object_(NULL) { } + + Wrapper(const cl_type &obj, bool retainObject) : object_(obj) + { + if (retainObject) { + detail::errHandler(retain(), __RETAIN_ERR); + } + } + + ~Wrapper() + { + if (object_ != NULL) { release(); } + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + detail::errHandler(retain(), __RETAIN_ERR); + } + + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT_ + { + object_ = rhs.object_; + rhs.object_ = NULL; + } + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs.object_; + detail::errHandler(retain(), __RETAIN_ERR); + } + return *this; + } + + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs.object_; + rhs.object_ = NULL; + } + return *this; + } + + Wrapper& operator = (const cl_type &rhs) + { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs; + return *this; + } + + const cl_type& operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + + const cl_type get() const { return object_; } + + cl_type get() { return object_; } + + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + cl_int retain() const + { + if (object_ != nullptr) { + return ReferenceHandler::retain(object_); + } + else { + return CL_SUCCESS; + } + } + + cl_int release() const + { + if (object_ != nullptr) { + return ReferenceHandler::release(object_); + } + else { + return CL_SUCCESS; + } + } +}; + +template <> +class Wrapper +{ +public: + typedef cl_device_id cl_type; + +protected: + cl_type object_; + bool referenceCountable_; + + static bool isReferenceCountable(cl_device_id device) + { + bool retVal = false; +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#if CL_HPP_MINIMUM_OPENCL_VERSION < 120 + if (device != NULL) { + int version = getDevicePlatformVersion(device); + if(version > ((1 << 16) + 1)) { + retVal = true; + } + } +#else // CL_HPP_MINIMUM_OPENCL_VERSION < 120 + retVal = true; +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120 +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + return retVal; + } + +public: + Wrapper() : object_(NULL), referenceCountable_(false) + { + } + + Wrapper(const cl_type &obj, bool retainObject) : + object_(obj), + referenceCountable_(false) + { + referenceCountable_ = isReferenceCountable(obj); + + if (retainObject) { + detail::errHandler(retain(), __RETAIN_ERR); + } + } + + ~Wrapper() + { + release(); + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + referenceCountable_ = isReferenceCountable(object_); + detail::errHandler(retain(), __RETAIN_ERR); + } + + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT_ + { + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + detail::errHandler(retain(), __RETAIN_ERR); + } + return *this; + } + + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } + return *this; + } + + Wrapper& operator = (const cl_type &rhs) + { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs; + referenceCountable_ = isReferenceCountable(object_); + return *this; + } + + const cl_type& operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + + const cl_type get() const { return object_; } + + cl_type get() { return object_; } + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + template + friend inline cl_int getInfoHelper(Func, cl_uint, vector*, int, typename U::cl_type); + + cl_int retain() const + { + if( object_ != nullptr && referenceCountable_ ) { + return ReferenceHandler::retain(object_); + } + else { + return CL_SUCCESS; + } + } + + cl_int release() const + { + if (object_ != nullptr && referenceCountable_) { + return ReferenceHandler::release(object_); + } + else { + return CL_SUCCESS; + } + } +}; + +template +inline bool operator==(const Wrapper &lhs, const Wrapper &rhs) +{ + return lhs() == rhs(); +} + +template +inline bool operator!=(const Wrapper &lhs, const Wrapper &rhs) +{ + return !operator==(lhs, rhs); +} + +} // namespace detail +//! \endcond + + +using BuildLogType = vector::param_type>>; +#if defined(CL_HPP_ENABLE_EXCEPTIONS) +/** +* Exception class for build errors to carry build info +*/ +class BuildError : public Error +{ +private: + BuildLogType buildLogs; +public: + BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec) + { + } + + BuildLogType getBuildLog() const + { + return buildLogs; + } +}; +namespace detail { + static inline cl_int buildErrHandler( + cl_int err, + const char * errStr, + const BuildLogType &buildLogs) + { + if (err != CL_SUCCESS) { + throw BuildError(err, errStr, buildLogs); + } + return err; + } +} // namespace detail + +#else +namespace detail { + static inline cl_int buildErrHandler( + cl_int err, + const char * errStr, + const BuildLogType &buildLogs) + { + (void)buildLogs; // suppress unused variable warning + (void)errStr; + return err; + } +} // namespace detail +#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS) + + +/*! \stuct ImageFormat + * \brief Adds constructors and member functions for cl_image_format. + * + * \see cl_image_format + */ +struct ImageFormat : public cl_image_format +{ + //! \brief Default constructor - performs no initialization. + ImageFormat(){} + + //! \brief Initializing constructor. + ImageFormat(cl_channel_order order, cl_channel_type type) + { + image_channel_order = order; + image_channel_data_type = type; + } + + //! \brief Assignment operator. + ImageFormat& operator = (const ImageFormat& rhs) + { + if (this != &rhs) { + this->image_channel_data_type = rhs.image_channel_data_type; + this->image_channel_order = rhs.image_channel_order; + } + return *this; + } +}; + +/*! \brief Class interface for cl_device_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_device_id + */ +class Device : public detail::Wrapper +{ +private: + static std::once_flag default_initialized_; + static Device default_; + static cl_int default_error_; + + /*! \brief Create the default context. + * + * This sets @c default_ and @c default_error_. It does not throw + * @c cl::Error. + */ + static void makeDefault(); + + /*! \brief Create the default platform from a provided platform. + * + * This sets @c default_. It does not throw + * @c cl::Error. + */ + static void makeDefaultProvided(const Device &p) { + default_ = p; + } + +public: +#ifdef CL_HPP_UNIT_TEST_ENABLE + /*! \brief Reset the default. + * + * This sets @c default_ to an empty value to support cleanup in + * the unit test framework. + * This function is not thread safe. + */ + static void unitTestClearDefault() { + default_ = Device(); + } +#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE + + //! \brief Default constructor - initializes to NULL. + Device() : detail::Wrapper() { } + + /*! \brief Constructor from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + explicit Device(const cl_device_id &device, bool retainObject = false) : + detail::Wrapper(device, retainObject) { } + + /*! \brief Returns the first device on the default context. + * + * \see Context::getDefault() + */ + static Device getDefault( + cl_int *errResult = NULL) + { + std::call_once(default_initialized_, makeDefault); + detail::errHandler(default_error_); + if (errResult != NULL) { + *errResult = default_error_; + } + return default_; + } + + /** + * Modify the default device to be used by + * subsequent operations. + * Will only set the default if no default was previously created. + * @return updated default device. + * Should be compared to the passed value to ensure that it was updated. + */ + static Device setDefault(const Device &default_device) + { + std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device)); + detail::errHandler(default_error_); + return default_; + } + + /*! \brief Assignment operator from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + Device& operator = (const cl_device_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device(const Device& dev) : detail::Wrapper(dev) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (const Device &dev) + { + detail::Wrapper::operator=(dev); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Device(Device&& dev) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(dev)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (Device &&dev) + { + detail::Wrapper::operator=(std::move(dev)); + return *this; + } + + //! \brief Wrapper for clGetDeviceInfo(). + template + cl_int getInfo(cl_device_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetDeviceInfo, object_, name, param), + __GET_DEVICE_INFO_ERR); + } + + //! \brief Wrapper for clGetDeviceInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_device_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /** + * CL 1.2 version + */ +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + //! \brief Wrapper for clCreateSubDevices(). + cl_int createSubDevices( + const cl_device_partition_property * properties, + vector* devices) + { + cl_uint n = 0; + cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR); + } + + vector ids(n); + err = clCreateSubDevices(object_, properties, n, ids.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR); + } + + // Cannot trivially assign because we need to capture intermediates + // with safe construction + if (devices) { + devices->resize(ids.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < ids.size(); i++) { + // We do not need to retain because this device is being created + // by the runtime + (*devices)[i] = Device(ids[i], false); + } + } + + return CL_SUCCESS; + } +#elif defined(CL_HPP_USE_CL_DEVICE_FISSION) + +/** + * CL 1.1 version that uses device fission extension. + */ + cl_int createSubDevices( + const cl_device_partition_property_ext * properties, + vector* devices) + { + typedef CL_API_ENTRY cl_int + ( CL_API_CALL * PFN_clCreateSubDevicesEXT)( + cl_device_id /*in_device*/, + const cl_device_partition_property_ext * /* properties */, + cl_uint /*num_entries*/, + cl_device_id * /*out_devices*/, + cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL; + CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT); + + cl_uint n = 0; + cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR); + } + + vector ids(n); + err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR); + } + // Cannot trivially assign because we need to capture intermediates + // with safe construction + if (devices) { + devices->resize(ids.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < ids.size(); i++) { + // We do not need to retain because this device is being created + // by the runtime + (*devices)[i] = Device(ids[i], false); + } + } + return CL_SUCCESS; + } +#endif // defined(CL_HPP_USE_CL_DEVICE_FISSION) +}; + +CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_; +CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_; +CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS; + +/*! \brief Class interface for cl_platform_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_platform_id + */ +class Platform : public detail::Wrapper +{ +private: + static std::once_flag default_initialized_; + static Platform default_; + static cl_int default_error_; + + /*! \brief Create the default context. + * + * This sets @c default_ and @c default_error_. It does not throw + * @c cl::Error. + */ + static void makeDefault() { + /* Throwing an exception from a call_once invocation does not do + * what we wish, so we catch it and save the error. + */ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try +#endif + { + // If default wasn't passed ,generate one + // Otherwise set it + cl_uint n = 0; + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + default_error_ = err; + return; + } + if (n == 0) { + default_error_ = CL_INVALID_PLATFORM; + return; + } + + vector ids(n); + err = ::clGetPlatformIDs(n, ids.data(), NULL); + if (err != CL_SUCCESS) { + default_error_ = err; + return; + } + + default_ = Platform(ids[0]); + } +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + catch (cl::Error &e) { + default_error_ = e.err(); + } +#endif + } + + /*! \brief Create the default platform from a provided platform. + * + * This sets @c default_. It does not throw + * @c cl::Error. + */ + static void makeDefaultProvided(const Platform &p) { + default_ = p; + } + +public: +#ifdef CL_HPP_UNIT_TEST_ENABLE + /*! \brief Reset the default. + * + * This sets @c default_ to an empty value to support cleanup in + * the unit test framework. + * This function is not thread safe. + */ + static void unitTestClearDefault() { + default_ = Platform(); + } +#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE + + //! \brief Default constructor - initializes to NULL. + Platform() : detail::Wrapper() { } + + /*! \brief Constructor from cl_platform_id. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * This simply copies the platform ID value, which is an inexpensive operation. + */ + explicit Platform(const cl_platform_id &platform, bool retainObject = false) : + detail::Wrapper(platform, retainObject) { } + + /*! \brief Assignment operator from cl_platform_id. + * + * This simply copies the platform ID value, which is an inexpensive operation. + */ + Platform& operator = (const cl_platform_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + static Platform getDefault( + cl_int *errResult = NULL) + { + std::call_once(default_initialized_, makeDefault); + detail::errHandler(default_error_); + if (errResult != NULL) { + *errResult = default_error_; + } + return default_; + } + + /** + * Modify the default platform to be used by + * subsequent operations. + * Will only set the default if no default was previously created. + * @return updated default platform. + * Should be compared to the passed value to ensure that it was updated. + */ + static Platform setDefault(const Platform &default_platform) + { + std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform)); + detail::errHandler(default_error_); + return default_; + } + + //! \brief Wrapper for clGetPlatformInfo(). + cl_int getInfo(cl_platform_info name, string* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetPlatformInfo, object_, name, param), + __GET_PLATFORM_INFO_ERR); + } + + //! \brief Wrapper for clGetPlatformInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_platform_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of devices for this platform. + * + * Wraps clGetDeviceIDs(). + */ + cl_int getDevices( + cl_device_type type, + vector* devices) const + { + cl_uint n = 0; + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + vector ids(n); + err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + // Cannot trivially assign because we need to capture intermediates + // with safe construction + // We must retain things we obtain from the API to avoid releasing + // API-owned objects. + if (devices) { + devices->resize(ids.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < ids.size(); i++) { + (*devices)[i] = Device(ids[i], true); + } + } + return CL_SUCCESS; + } + +#if defined(CL_HPP_USE_DX_INTEROP) + /*! \brief Get the list of available D3D10 devices. + * + * \param d3d_device_source. + * + * \param d3d_object. + * + * \param d3d_device_set. + * + * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device + * values returned in devices can be used to identify a specific OpenCL + * device. If \a devices argument is NULL, this argument is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * + * The application can query specific capabilities of the OpenCL device(s) + * returned by cl::getDevices. This can be used by the application to + * determine which device(s) to use. + * + * \note In the case that exceptions are enabled and a return value + * other than CL_SUCCESS is generated, then cl::Error exception is + * generated. + */ + cl_int getDevices( + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + vector* devices) const + { + typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)( + cl_platform_id platform, + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint* num_devices); + + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + + static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL; + CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR); + + cl_uint n = 0; + cl_int err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + 0, + NULL, + &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + vector ids(n); + err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + n, + ids.data(), + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + // Cannot trivially assign because we need to capture intermediates + // with safe construction + // We must retain things we obtain from the API to avoid releasing + // API-owned objects. + if (devices) { + devices->resize(ids.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < ids.size(); i++) { + (*devices)[i] = Device(ids[i], true); + } + } + return CL_SUCCESS; + } +#endif + + /*! \brief Gets a list of available platforms. + * + * Wraps clGetPlatformIDs(). + */ + static cl_int get( + vector* platforms) + { + cl_uint n = 0; + + if( platforms == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); + } + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + vector ids(n); + err = ::clGetPlatformIDs(n, ids.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + if (platforms) { + platforms->resize(ids.size()); + + // Platforms don't reference count + for (size_type i = 0; i < ids.size(); i++) { + (*platforms)[i] = Platform(ids[i]); + } + } + return CL_SUCCESS; + } + + /*! \brief Gets the first available platform. + * + * Wraps clGetPlatformIDs(), returning the first result. + */ + static cl_int get( + Platform * platform) + { + cl_int err; + Platform default_platform = Platform::getDefault(&err); + if (platform) { + *platform = default_platform; + } + return err; + } + + /*! \brief Gets the first available platform, returning it by value. + * + * \return Returns a valid platform if one is available. + * If no platform is available will return a null platform. + * Throws an exception if no platforms are available + * or an error condition occurs. + * Wraps clGetPlatformIDs(), returning the first result. + */ + static Platform get( + cl_int * errResult = NULL) + { + cl_int err; + Platform default_platform = Platform::getDefault(&err); + if (errResult) { + *errResult = err; + } + return default_platform; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + //! \brief Wrapper for clUnloadCompiler(). + cl_int + unloadCompiler() + { + return ::clUnloadPlatformCompiler(object_); + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +}; // class Platform + +CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_; +CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_; +CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS; + + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +/** + * Unload the OpenCL compiler. + * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead. + */ +inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int +UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +inline cl_int +UnloadCompiler() +{ + return ::clUnloadCompiler(); +} +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +/*! \brief Class interface for cl_context. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_context as the original. For details, see + * clRetainContext() and clReleaseContext(). + * + * \see cl_context + */ +class Context + : public detail::Wrapper +{ +private: + static std::once_flag default_initialized_; + static Context default_; + static cl_int default_error_; + + /*! \brief Create the default context from the default device type in the default platform. + * + * This sets @c default_ and @c default_error_. It does not throw + * @c cl::Error. + */ + static void makeDefault() { + /* Throwing an exception from a call_once invocation does not do + * what we wish, so we catch it and save the error. + */ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try +#endif + { +#if !defined(__APPLE__) && !defined(__MACOS) + const Platform &p = Platform::getDefault(); + cl_platform_id defaultPlatform = p(); + cl_context_properties properties[3] = { + CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0 + }; +#else // #if !defined(__APPLE__) && !defined(__MACOS) + cl_context_properties *properties = nullptr; +#endif // #if !defined(__APPLE__) && !defined(__MACOS) + + default_ = Context( + CL_DEVICE_TYPE_DEFAULT, + properties, + NULL, + NULL, + &default_error_); + } +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + catch (cl::Error &e) { + default_error_ = e.err(); + } +#endif + } + + + /*! \brief Create the default context from a provided Context. + * + * This sets @c default_. It does not throw + * @c cl::Error. + */ + static void makeDefaultProvided(const Context &c) { + default_ = c; + } + +public: +#ifdef CL_HPP_UNIT_TEST_ENABLE + /*! \brief Reset the default. + * + * This sets @c default_ to an empty value to support cleanup in + * the unit test framework. + * This function is not thread safe. + */ + static void unitTestClearDefault() { + default_ = Context(); + } +#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE + + /*! \brief Constructs a context including a list of specified devices. + * + * Wraps clCreateContext(). + */ + Context( + const vector& devices, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + size_type, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + size_type numDevices = devices.size(); + vector deviceIDs(numDevices); + + for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateContext( + properties, (cl_uint) numDevices, + deviceIDs.data(), + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + Context( + const Device& device, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + size_type, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + cl_device_id deviceID = device(); + + object_ = ::clCreateContext( + properties, 1, + &deviceID, + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a context including all or a subset of devices of a specified type. + * + * Wraps clCreateContextFromType(). + */ + Context( + cl_device_type type, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + size_type, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + +#if !defined(__APPLE__) && !defined(__MACOS) + cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 }; + + if (properties == NULL) { + // Get a valid platform ID as we cannot send in a blank one + vector platforms; + error = Platform::get(&platforms); + if (error != CL_SUCCESS) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + // Check the platforms we found for a device of our specified type + cl_context_properties platform_id = 0; + for (unsigned int i = 0; i < platforms.size(); i++) { + + vector devices; + +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try { +#endif + + error = platforms[i].getDevices(type, &devices); + +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + } catch (Error) {} + // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type + // We do error checking next anyway, and can throw there if needed +#endif + + // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND + if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + if (devices.size() > 0) { + platform_id = (cl_context_properties)platforms[i](); + break; + } + } + + if (platform_id == 0) { + detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = CL_DEVICE_NOT_FOUND; + } + return; + } + + prop[1] = platform_id; + properties = &prop[0]; + } +#endif + object_ = ::clCreateContextFromType( + properties, type, notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context(const Context& ctx) : detail::Wrapper(ctx) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (const Context &ctx) + { + detail::Wrapper::operator=(ctx); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Context(Context&& ctx) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(ctx)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (Context &&ctx) + { + detail::Wrapper::operator=(std::move(ctx)); + return *this; + } + + + /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT. + * + * \note All calls to this function return the same cl_context as the first. + */ + static Context getDefault(cl_int * err = NULL) + { + std::call_once(default_initialized_, makeDefault); + detail::errHandler(default_error_); + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + /** + * Modify the default context to be used by + * subsequent operations. + * Will only set the default if no default was previously created. + * @return updated default context. + * Should be compared to the passed value to ensure that it was updated. + */ + static Context setDefault(const Context &default_context) + { + std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context)); + detail::errHandler(default_error_); + return default_; + } + + //! \brief Default constructor - initializes to NULL. + Context() : detail::Wrapper() { } + + /*! \brief Constructor from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_context + * into the new Context object. + */ + explicit Context(const cl_context& context, bool retainObject = false) : + detail::Wrapper(context, retainObject) { } + + /*! \brief Assignment operator from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseContext() on the value previously held by this instance. + */ + Context& operator = (const cl_context& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetContextInfo(). + template + cl_int getInfo(cl_context_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetContextInfo, object_, name, param), + __GET_CONTEXT_INFO_ERR); + } + + //! \brief Wrapper for clGetContextInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_context_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of supported image formats. + * + * Wraps clGetSupportedImageFormats(). + */ + cl_int getSupportedImageFormats( + cl_mem_flags flags, + cl_mem_object_type type, + vector* formats) const + { + cl_uint numEntries; + + if (!formats) { + return CL_SUCCESS; + } + + cl_int err = ::clGetSupportedImageFormats( + object_, + flags, + type, + 0, + NULL, + &numEntries); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + if (numEntries > 0) { + vector value(numEntries); + err = ::clGetSupportedImageFormats( + object_, + flags, + type, + numEntries, + (cl_image_format*)value.data(), + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + formats->assign(begin(value), end(value)); + } + else { + // If no values are being returned, ensure an empty vector comes back + formats->clear(); + } + + return CL_SUCCESS; + } +}; + +inline void Device::makeDefault() +{ + /* Throwing an exception from a call_once invocation does not do + * what we wish, so we catch it and save the error. + */ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try +#endif + { + cl_int error = 0; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + default_error_ = error; + } + else { + default_ = context.getInfo()[0]; + default_error_ = CL_SUCCESS; + } + } +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + catch (cl::Error &e) { + default_error_ = e.err(); + } +#endif +} + +CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_; +CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_; +CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS; + +/*! \brief Class interface for cl_event. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_event as the original. For details, see + * clRetainEvent() and clReleaseEvent(). + * + * \see cl_event + */ +class Event : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Event() : detail::Wrapper() { } + + /*! \brief Constructor from cl_event - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * This effectively transfers ownership of a refcount on the cl_event + * into the new Event object. + */ + explicit Event(const cl_event& event, bool retainObject = false) : + detail::Wrapper(event, retainObject) { } + + /*! \brief Assignment operator from cl_event - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseEvent() on the value previously held by this instance. + */ + Event& operator = (const cl_event& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetEventInfo(). + template + cl_int getInfo(cl_event_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetEventInfo, object_, name, param), + __GET_EVENT_INFO_ERR); + } + + //! \brief Wrapper for clGetEventInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_event_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + //! \brief Wrapper for clGetEventProfilingInfo(). + template + cl_int getProfilingInfo(cl_profiling_info name, T* param) const + { + return detail::errHandler(detail::getInfo( + &::clGetEventProfilingInfo, object_, name, param), + __GET_EVENT_PROFILE_INFO_ERR); + } + + //! \brief Wrapper for clGetEventProfilingInfo() that returns by value. + template typename + detail::param_traits::param_type + getProfilingInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_profiling_info, name>::param_type param; + cl_int result = getProfilingInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Blocks the calling thread until this event completes. + * + * Wraps clWaitForEvents(). + */ + cl_int wait() const + { + return detail::errHandler( + ::clWaitForEvents(1, &object_), + __WAIT_FOR_EVENTS_ERR); + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + /*! \brief Registers a user callback function for a specific command execution status. + * + * Wraps clSetEventCallback(). + */ + cl_int setCallback( + cl_int type, + void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetEventCallback( + object_, + type, + pfn_notify, + user_data), + __SET_EVENT_CALLBACK_ERR); + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + + /*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ + static cl_int + waitForEvents(const vector& events) + { + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); + } +}; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 +/*! \brief Class interface for user events (a subset of cl_event's). + * + * See Event for details about copy semantics, etc. + */ +class UserEvent : public Event +{ +public: + /*! \brief Constructs a user event on a given context. + * + * Wraps clCreateUserEvent(). + */ + UserEvent( + const Context& context, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateUserEvent( + context(), + &error); + + detail::errHandler(error, __CREATE_USER_EVENT_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + UserEvent() : Event() { } + + /*! \brief Sets the execution status of a user event object. + * + * Wraps clSetUserEventStatus(). + */ + cl_int setStatus(cl_int status) + { + return detail::errHandler( + ::clSetUserEventStatus(object_,status), + __SET_USER_EVENT_STATUS_ERR); + } +}; +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + +/*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ +inline static cl_int +WaitForEvents(const vector& events) +{ + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); +} + +/*! \brief Class interface for cl_mem. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_mem as the original. For details, see + * clRetainMemObject() and clReleaseMemObject(). + * + * \see cl_mem + */ +class Memory : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Memory() : detail::Wrapper() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * Optionally transfer ownership of a refcount on the cl_mem + * into the new Memory object. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * + * See Memory for further details. + */ + explicit Memory(const cl_mem& memory, bool retainObject) : + detail::Wrapper(memory, retainObject) { } + + /*! \brief Assignment operator from cl_mem - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseMemObject() on the value previously held by this instance. + */ + Memory& operator = (const cl_mem& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory(const Memory& mem) : detail::Wrapper(mem) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (const Memory &mem) + { + detail::Wrapper::operator=(mem); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory(Memory&& mem) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(mem)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (Memory &&mem) + { + detail::Wrapper::operator=(std::move(mem)); + return *this; + } + + + //! \brief Wrapper for clGetMemObjectInfo(). + template + cl_int getInfo(cl_mem_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetMemObjectInfo, object_, name, param), + __GET_MEM_OBJECT_INFO_ERR); + } + + //! \brief Wrapper for clGetMemObjectInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_mem_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + /*! \brief Registers a callback function to be called when the memory object + * is no longer needed. + * + * Wraps clSetMemObjectDestructorCallback(). + * + * Repeated calls to this function, for a given cl_mem value, will append + * to the list of functions called (in reverse order) when memory object's + * resources are freed and the memory object is deleted. + * + * \note + * The registered callbacks are associated with the underlying cl_mem + * value - not the Memory class instance. + */ + cl_int setDestructorCallback( + void (CL_CALLBACK * pfn_notify)(cl_mem, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetMemObjectDestructorCallback( + object_, + pfn_notify, + user_data), + __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR); + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + +}; + +// Pre-declare copy functions +class Buffer; +template< typename IteratorType > +cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +namespace detail +{ + class SVMTraitNull + { + public: + static cl_svm_mem_flags getSVMMemFlags() + { + return 0; + } + }; +} // namespace detail + +template +class SVMTraitReadWrite +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return CL_MEM_READ_WRITE | + Trait::getSVMMemFlags(); + } +}; + +template +class SVMTraitReadOnly +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return CL_MEM_READ_ONLY | + Trait::getSVMMemFlags(); + } +}; + +template +class SVMTraitWriteOnly +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return CL_MEM_WRITE_ONLY | + Trait::getSVMMemFlags(); + } +}; + +template> +class SVMTraitCoarse +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return Trait::getSVMMemFlags(); + } +}; + +template> +class SVMTraitFine +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return CL_MEM_SVM_FINE_GRAIN_BUFFER | + Trait::getSVMMemFlags(); + } +}; + +template> +class SVMTraitAtomic +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return + CL_MEM_SVM_FINE_GRAIN_BUFFER | + CL_MEM_SVM_ATOMICS | + Trait::getSVMMemFlags(); + } +}; + +// Pre-declare SVM map function +template +inline cl_int enqueueMapSVM( + T* ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events = NULL, + Event* event = NULL); + +/** + * STL-like allocator class for managing SVM objects provided for convenience. + * + * Note that while this behaves like an allocator for the purposes of constructing vectors and similar objects, + * care must be taken when using with smart pointers. + * The allocator should not be used to construct a unique_ptr if we are using coarse-grained SVM mode because + * the coarse-grained management behaviour would behave incorrectly with respect to reference counting. + * + * Instead the allocator embeds a Deleter which may be used with unique_ptr and is used + * with the allocate_shared and allocate_ptr supplied operations. + */ +template +class SVMAllocator { +private: + Context context_; + +public: + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + template + struct rebind + { + typedef SVMAllocator other; + }; + + template + friend class SVMAllocator; + + SVMAllocator() : + context_(Context::getDefault()) + { + } + + explicit SVMAllocator(cl::Context context) : + context_(context) + { + } + + + SVMAllocator(const SVMAllocator &other) : + context_(other.context_) + { + } + + template + SVMAllocator(const SVMAllocator &other) : + context_(other.context_) + { + } + + ~SVMAllocator() + { + } + + pointer address(reference r) CL_HPP_NOEXCEPT_ + { + return std::addressof(r); + } + + const_pointer address(const_reference r) CL_HPP_NOEXCEPT_ + { + return std::addressof(r); + } + + /** + * Allocate an SVM pointer. + * + * If the allocator is coarse-grained, this will take ownership to allow + * containers to correctly construct data in place. + */ + pointer allocate( + size_type size, + typename cl::SVMAllocator::const_pointer = 0) + { + // Allocate memory with default alignment matching the size of the type + void* voidPointer = + clSVMAlloc( + context_(), + SVMTrait::getSVMMemFlags(), + size*sizeof(T), + 0); + pointer retValue = reinterpret_cast( + voidPointer); +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + if (!retValue) { + std::bad_alloc excep; + throw excep; + } +#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS) + + // If allocation was coarse-grained then map it + if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) { + cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T)); + if (err != CL_SUCCESS) { + std::bad_alloc excep; + throw excep; + } + } + + // If exceptions disabled, return null pointer from allocator + return retValue; + } + + void deallocate(pointer p, size_type) + { + clSVMFree(context_(), p); + } + + /** + * Return the maximum possible allocation size. + * This is the minimum of the maximum sizes of all devices in the context. + */ + size_type max_size() const CL_HPP_NOEXCEPT_ + { + size_type maxSize = std::numeric_limits::max() / sizeof(T); + + for (const Device &d : context_.getInfo()) { + maxSize = std::min( + maxSize, + static_cast(d.getInfo())); + } + + return maxSize; + } + + template< class U, class... Args > + void construct(U* p, Args&&... args) + { + new(p)T(args...); + } + + template< class U > + void destroy(U* p) + { + p->~U(); + } + + /** + * Returns true if the contexts match. + */ + inline bool operator==(SVMAllocator const& rhs) + { + return (context_==rhs.context_); + } + + inline bool operator!=(SVMAllocator const& a) + { + return !operator==(a); + } +}; // class SVMAllocator return cl::pointer(tmp, detail::Deleter{alloc, copies}); + + +template +class SVMAllocator { +public: + typedef void value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + + template + struct rebind + { + typedef SVMAllocator other; + }; + + template + friend class SVMAllocator; +}; + +#if !defined(CL_HPP_NO_STD_UNIQUE_PTR) +namespace detail +{ + template + class Deleter { + private: + Alloc alloc_; + size_type copies_; + + public: + typedef typename std::allocator_traits::pointer pointer; + + Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies } + { + } + + void operator()(pointer ptr) const { + Alloc tmpAlloc{ alloc_ }; + std::allocator_traits::destroy(tmpAlloc, std::addressof(*ptr)); + std::allocator_traits::deallocate(tmpAlloc, ptr, copies_); + } + }; +} // namespace detail + +/** + * Allocation operation compatible with std::allocate_ptr. + * Creates a unique_ptr by default. + * This requirement is to ensure that the control block is not + * allocated in memory inaccessible to the host. + */ +template +cl::pointer> allocate_pointer(const Alloc &alloc_, Args&&... args) +{ + Alloc alloc(alloc_); + static const size_type copies = 1; + + // Ensure that creation of the management block and the + // object are dealt with separately such that we only provide a deleter + + T* tmp = std::allocator_traits::allocate(alloc, copies); + if (!tmp) { + std::bad_alloc excep; + throw excep; + } + try { + std::allocator_traits::construct( + alloc, + std::addressof(*tmp), + std::forward(args)...); + + return cl::pointer>(tmp, detail::Deleter{alloc, copies}); + } + catch (std::bad_alloc b) + { + std::allocator_traits::deallocate(alloc, tmp, copies); + throw; + } +} + +template< class T, class SVMTrait, class... Args > +cl::pointer>> allocate_svm(Args... args) +{ + SVMAllocator alloc; + return cl::allocate_pointer(alloc, args...); +} + +template< class T, class SVMTrait, class... Args > +cl::pointer>> allocate_svm(const cl::Context &c, Args... args) +{ + SVMAllocator alloc(c); + return cl::allocate_pointer(alloc, args...); +} +#endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR) + +/*! \brief Vector alias to simplify contruction of coarse-grained SVM containers. + * + */ +template < class T > +using coarse_svm_vector = vector>>; + +/*! \brief Vector alias to simplify contruction of fine-grained SVM containers. +* +*/ +template < class T > +using fine_svm_vector = vector>>; + +/*! \brief Vector alias to simplify contruction of fine-grained SVM containers that support platform atomics. +* +*/ +template < class T > +using atomic_svm_vector = vector>>; + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + +/*! \brief Class interface for Buffer Memory Objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Buffer : public Memory +{ +public: + + /*! \brief Constructs a Buffer in a specified context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + */ + Buffer( + const Context& context, + cl_mem_flags flags, + size_type size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a Buffer in the default context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + * + * \see Context::getDefault() + */ + Buffer( + cl_mem_flags flags, + size_type size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(err); + + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer( + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr = false, + cl_int* err = NULL) + { + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + size_type size = sizeof(DataType)*(endIterator - startIterator); + + Context context = Context::getDefault(err); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + error = cl::copy(startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified context. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified queue. + * If useHostPtr is specified iterators must be random access. + */ + template< typename IteratorType > + Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Buffer() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with earlier versions. + * + * See Memory for further details. + */ + explicit Buffer(const cl_mem& buffer, bool retainObject = false) : + Memory(buffer, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Buffer& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer(const Buffer& buf) : Memory(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (const Buffer &buf) + { + Memory::operator=(buf); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer(Buffer&& buf) CL_HPP_NOEXCEPT_ : Memory(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (Buffer &&buf) + { + Memory::operator=(std::move(buf)); + return *this; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + /*! \brief Creates a new buffer object from this. + * + * Wraps clCreateSubBuffer(). + */ + Buffer createSubBuffer( + cl_mem_flags flags, + cl_buffer_create_type buffer_create_type, + const void * buffer_create_info, + cl_int * err = NULL) + { + Buffer result; + cl_int error; + result.object_ = ::clCreateSubBuffer( + object_, + flags, + buffer_create_type, + buffer_create_info, + &error); + + detail::errHandler(error, __CREATE_SUBBUFFER_ERR); + if (err != NULL) { + *err = error; + } + + return result; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 +}; + +#if defined (CL_HPP_USE_DX_INTEROP) +/*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's. + * + * This is provided to facilitate interoperability with Direct3D. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferD3D10 : public Buffer +{ +public: + + + /*! \brief Constructs a BufferD3D10, in a specified context, from a + * given ID3D10Buffer. + * + * Wraps clCreateFromD3D10BufferKHR(). + */ + BufferD3D10( + const Context& context, + cl_mem_flags flags, + ID3D10Buffer* bufobj, + cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr) + { + typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)( + cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer, + cl_int* errcode_ret); + PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR; +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + vector props = context.getInfo(); + cl_platform platform = -1; + for( int i = 0; i < props.size(); ++i ) { + if( props[i] == CL_CONTEXT_PLATFORM ) { + platform = props[i+1]; + } + } + CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR); +#elif CL_HPP_TARGET_OPENCL_VERSION >= 110 + CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR); +#endif + + cl_int error; + object_ = pfn_clCreateFromD3D10BufferKHR( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferD3D10() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) : + Buffer(buffer, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferD3D10& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(const BufferD3D10& buf) : + Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (const BufferD3D10 &buf) + { + Buffer::operator=(buf); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (BufferD3D10 &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } +}; +#endif + +/*! \brief Class interface for GL Buffer Memory Objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferGL : public Buffer +{ +public: + /*! \brief Constructs a BufferGL in a specified context, from a given + * GL buffer. + * + * Wraps clCreateFromGLBuffer(). + */ + BufferGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLBuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferGL() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit BufferGL(const cl_mem& buffer, bool retainObject = false) : + Buffer(buffer, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferGL& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL(const BufferGL& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (const BufferGL &buf) + { + Buffer::operator=(buf); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (BufferGL &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_,type,gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief Class interface for GL Render Buffer Memory Objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferRenderGL : public Buffer +{ +public: + /*! \brief Constructs a BufferRenderGL in a specified context, from a given + * GL Renderbuffer. + * + * Wraps clCreateFromGLRenderbuffer(). + */ + BufferRenderGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLRenderbuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferRenderGL() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) : + Buffer(buffer, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferRenderGL& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL(const BufferRenderGL& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (const BufferRenderGL &buf) + { + Buffer::operator=(buf); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (BufferRenderGL &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_,type,gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief C++ base class for Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image : public Memory +{ +protected: + //! \brief Default constructor - initializes to NULL. + Image() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image(const cl_mem& image, bool retainObject = false) : + Memory(image, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image(const Image& img) : Memory(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (const Image &img) + { + Memory::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image(Image&& img) CL_HPP_NOEXCEPT_ : Memory(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (Image &&img) + { + Memory::operator=(std::move(img)); + return *this; + } + + +public: + //! \brief Wrapper for clGetImageInfo(). + template + cl_int getImageInfo(cl_image_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetImageInfo, object_, name, param), + __GET_IMAGE_INFO_ERR); + } + + //! \brief Wrapper for clGetImageInfo() that returns by value. + template typename + detail::param_traits::param_type + getImageInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_image_info, name>::param_type param; + cl_int result = getImageInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +/*! \brief Class interface for 1D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image1D : public Image +{ +public: + /*! \brief Constructs a 1D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image1D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type width, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D, + width, + 0, 0, 0, 0, 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image1D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image1D(const cl_mem& image1D, bool retainObject = false) : + Image(image1D, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image1D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D(const Image1D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (const Image1D &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D(Image1D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (Image1D &&img) + { + Image::operator=(std::move(img)); + return *this; + } + +}; + +/*! \class Image1DBuffer + * \brief Image interface for 1D buffer images. + */ +class Image1DBuffer : public Image +{ +public: + Image1DBuffer( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type width, + const Buffer &buffer, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_BUFFER, + width, + 0, 0, 0, 0, 0, 0, 0, + buffer() + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + NULL, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DBuffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) : + Image(image1D, retainObject) { } + + Image1DBuffer& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(const Image1DBuffer& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (const Image1DBuffer &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (Image1DBuffer &&img) + { + Image::operator=(std::move(img)); + return *this; + } + +}; + +/*! \class Image1DArray + * \brief Image interface for arrays of 1D images. + */ +class Image1DArray : public Image +{ +public: + Image1DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type arraySize, + size_type width, + size_type rowPitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_ARRAY, + width, + 0, 0, // height, depth (unused) + arraySize, + rowPitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DArray() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) : + Image(imageArray, retainObject) { } + + + Image1DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(const Image1DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (const Image1DArray &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (Image1DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } + +}; +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120 + + +/*! \brief Class interface for 2D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image2D : public Image +{ +public: + /*! \brief Constructs a 2D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image2D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type width, + size_type height, + size_type row_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120 + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif CL_HPP_TARGET_OPENCL_VERSION >= 120 + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D, + width, + height, + 0, 0, // depth, array size (unused) + row_pitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#if CL_HPP_MINIMUM_OPENCL_VERSION < 120 + if (!useCreateImage) + { + object_ = ::clCreateImage2D( + context(), flags,&format, width, height, row_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE2D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120 + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR) + /*! \brief Constructs a 2D Image from a buffer. + * \note This will share storage with the underlying buffer. + * + * Wraps clCreateImage(). + */ + Image2D( + const Context& context, + ImageFormat format, + const Buffer &sourceBuffer, + size_type width, + size_type height, + size_type row_pitch = 0, + cl_int* err = nullptr) + { + cl_int error; + + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D, + width, + height, + 0, 0, // depth, array size (unused) + row_pitch, + 0, 0, 0, + // Use buffer as input to image + sourceBuffer() + }; + object_ = ::clCreateImage( + context(), + 0, // flags inherited from buffer + &format, + &desc, + nullptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != nullptr) { + *err = error; + } + } +#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR) + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /*! \brief Constructs a 2D Image from an image. + * \note This will share storage with the underlying image but may + * reinterpret the channel order and type. + * + * The image will be created matching with a descriptor matching the source. + * + * \param order is the channel order to reinterpret the image data as. + * The channel order may differ as described in the OpenCL + * 2.0 API specification. + * + * Wraps clCreateImage(). + */ + Image2D( + const Context& context, + cl_channel_order order, + const Image &sourceImage, + cl_int* err = nullptr) + { + cl_int error; + + // Descriptor fields have to match source image + size_type sourceWidth = + sourceImage.getImageInfo(); + size_type sourceHeight = + sourceImage.getImageInfo(); + size_type sourceRowPitch = + sourceImage.getImageInfo(); + cl_uint sourceNumMIPLevels = + sourceImage.getImageInfo(); + cl_uint sourceNumSamples = + sourceImage.getImageInfo(); + cl_image_format sourceFormat = + sourceImage.getImageInfo(); + + // Update only the channel order. + // Channel format inherited from source. + sourceFormat.image_channel_order = order; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D, + sourceWidth, + sourceHeight, + 0, 0, // depth (unused), array size (unused) + sourceRowPitch, + 0, // slice pitch (unused) + sourceNumMIPLevels, + sourceNumSamples, + // Use buffer as input to image + sourceImage() + }; + object_ = ::clCreateImage( + context(), + 0, // flags should be inherited from mem_object + &sourceFormat, + &desc, + nullptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != nullptr) { + *err = error; + } + } +#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + //! \brief Default constructor - initializes to NULL. + Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image2D(const cl_mem& image2D, bool retainObject = false) : + Image(image2D, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image2D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D(const Image2D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (const Image2D &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D(Image2D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (Image2D &&img) + { + Image::operator=(std::move(img)); + return *this; + } + +}; + + +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +/*! \brief Class interface for GL 2D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + * \note Deprecated for OpenCL 1.2. Please use ImageGL instead. + */ +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D +{ +public: + /*! \brief Constructs an Image2DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture2D(). + */ + Image2DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture2D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR); + if (err != NULL) { + *err = error; + } + + } + + //! \brief Default constructor - initializes to NULL. + Image2DGL() : Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image2DGL(const cl_mem& image, bool retainObject = false) : + Image2D(image, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + *c + * See Memory for further details. + */ + Image2DGL& operator = (const cl_mem& rhs) + { + Image2D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(const Image2DGL& img) : Image2D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (const Image2DGL &img) + { + Image2D::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT_ : Image2D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (Image2DGL &&img) + { + Image2D::operator=(std::move(img)); + return *this; + } + +} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +/*! \class Image2DArray + * \brief Image interface for arrays of 2D images. + */ +class Image2DArray : public Image +{ +public: + Image2DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type arraySize, + size_type width, + size_type height, + size_type rowPitch, + size_type slicePitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D_ARRAY, + width, + height, + 0, // depth (unused) + arraySize, + rowPitch, + slicePitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image2DArray() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { } + + Image2DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(const Image2DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (const Image2DArray &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (Image2DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } +}; +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120 + +/*! \brief Class interface for 3D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3D : public Image +{ +public: + /*! \brief Constructs a 3D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image3D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type width, + size_type height, + size_type depth, + size_type row_pitch = 0, + size_type slice_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120 + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif CL_HPP_TARGET_OPENCL_VERSION >= 120 + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE3D, + width, + height, + depth, + 0, // array size (unused) + row_pitch, + slice_pitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#if CL_HPP_MINIMUM_OPENCL_VERSION < 120 + if (!useCreateImage) + { + object_ = ::clCreateImage3D( + context(), flags, &format, width, height, depth, row_pitch, + slice_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE3D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120 + } + + //! \brief Default constructor - initializes to NULL. + Image3D() : Image() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image3D(const cl_mem& image3D, bool retainObject = false) : + Image(image3D, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D(const Image3D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (const Image3D &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D(Image3D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (Image3D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +}; + +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +/*! \brief Class interface for GL 3D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3DGL : public Image3D +{ +public: + /*! \brief Constructs an Image3DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture3D(). + */ + Image3DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture3D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image3DGL() : Image3D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image3DGL(const cl_mem& image, bool retainObject = false) : + Image3D(image, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3DGL& operator = (const cl_mem& rhs) + { + Image3D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(const Image3DGL& img) : Image3D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (const Image3DGL &img) + { + Image3D::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT_ : Image3D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (Image3DGL &&img) + { + Image3D::operator=(std::move(img)); + return *this; + } +}; +#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +/*! \class ImageGL + * \brief general image interface for GL interop. + * We abstract the 2D and 3D GL images into a single instance here + * that wraps all GL sourced images on the grounds that setup information + * was performed by OpenCL anyway. + */ +class ImageGL : public Image +{ +public: + ImageGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_ERR); + if (err != NULL) { + *err = error; + } + } + + ImageGL() : Image() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit ImageGL(const cl_mem& image, bool retainObject = false) : + Image(image, retainObject) { } + + ImageGL& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL(const ImageGL& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (const ImageGL &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (ImageGL &&img) + { + Image::operator=(std::move(img)); + return *this; + } +}; +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +/*! \brief Class interface for Pipe Memory Objects. +* +* See Memory for details about copy semantics, etc. +* +* \see Memory +*/ +class Pipe : public Memory +{ +public: + + /*! \brief Constructs a Pipe in a specified context. + * + * Wraps clCreatePipe(). + * @param context Context in which to create the pipe. + * @param flags Bitfield. Only CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS are valid. + * @param packet_size Size in bytes of a single packet of the pipe. + * @param max_packets Number of packets that may be stored in the pipe. + * + */ + Pipe( + const Context& context, + cl_uint packet_size, + cl_uint max_packets, + cl_int* err = NULL) + { + cl_int error; + + cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS; + object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error); + + detail::errHandler(error, __CREATE_PIPE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a Pipe in a the default context. + * + * Wraps clCreatePipe(). + * @param flags Bitfield. Only CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS are valid. + * @param packet_size Size in bytes of a single packet of the pipe. + * @param max_packets Number of packets that may be stored in the pipe. + * + */ + Pipe( + cl_uint packet_size, + cl_uint max_packets, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(err); + + cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS; + object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error); + + detail::errHandler(error, __CREATE_PIPE_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Pipe() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with earlier versions. + * + * See Memory for further details. + */ + explicit Pipe(const cl_mem& pipe, bool retainObject = false) : + Memory(pipe, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Pipe& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Pipe(const Pipe& pipe) : Memory(pipe) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Pipe& operator = (const Pipe &pipe) + { + Memory::operator=(pipe); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Pipe(Pipe&& pipe) CL_HPP_NOEXCEPT_ : Memory(std::move(pipe)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Pipe& operator = (Pipe &&pipe) + { + Memory::operator=(std::move(pipe)); + return *this; + } + + //! \brief Wrapper for clGetMemObjectInfo(). + template + cl_int getInfo(cl_pipe_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetPipeInfo, object_, name, param), + __GET_PIPE_INFO_ERR); + } + + //! \brief Wrapper for clGetMemObjectInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_pipe_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; // class Pipe +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200 + + +/*! \brief Class interface for cl_sampler. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_sampler as the original. For details, see + * clRetainSampler() and clReleaseSampler(). + * + * \see cl_sampler + */ +class Sampler : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Sampler() { } + + /*! \brief Constructs a Sampler in a specified context. + * + * Wraps clCreateSampler(). + */ + Sampler( + const Context& context, + cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, + cl_int* err = NULL) + { + cl_int error; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_sampler_properties sampler_properties[] = { + CL_SAMPLER_NORMALIZED_COORDS, normalized_coords, + CL_SAMPLER_ADDRESSING_MODE, addressing_mode, + CL_SAMPLER_FILTER_MODE, filter_mode, + 0 }; + object_ = ::clCreateSamplerWithProperties( + context(), + sampler_properties, + &error); + + detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateSampler( + context(), + normalized_coords, + addressing_mode, + filter_mode, + &error); + + detail::errHandler(error, __CREATE_SAMPLER_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + + /*! \brief Constructor from cl_sampler - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * This effectively transfers ownership of a refcount on the cl_sampler + * into the new Sampler object. + */ + explicit Sampler(const cl_sampler& sampler, bool retainObject = false) : + detail::Wrapper(sampler, retainObject) { } + + /*! \brief Assignment operator from cl_sampler - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseSampler() on the value previously held by this instance. + */ + Sampler& operator = (const cl_sampler& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler(const Sampler& sam) : detail::Wrapper(sam) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (const Sampler &sam) + { + detail::Wrapper::operator=(sam); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler(Sampler&& sam) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(sam)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (Sampler &&sam) + { + detail::Wrapper::operator=(std::move(sam)); + return *this; + } + + //! \brief Wrapper for clGetSamplerInfo(). + template + cl_int getInfo(cl_sampler_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetSamplerInfo, object_, name, param), + __GET_SAMPLER_INFO_ERR); + } + + //! \brief Wrapper for clGetSamplerInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_sampler_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +class Program; +class CommandQueue; +class DeviceCommandQueue; +class Kernel; + +//! \brief Class interface for specifying NDRange values. +class NDRange +{ +private: + size_type sizes_[3]; + cl_uint dimensions_; + +public: + //! \brief Default constructor - resulting range has zero dimensions. + NDRange() + : dimensions_(0) + { + sizes_[0] = 0; + sizes_[1] = 0; + sizes_[2] = 0; + } + + //! \brief Constructs one-dimensional range. + NDRange(size_type size0) + : dimensions_(1) + { + sizes_[0] = size0; + sizes_[1] = 1; + sizes_[2] = 1; + } + + //! \brief Constructs two-dimensional range. + NDRange(size_type size0, size_type size1) + : dimensions_(2) + { + sizes_[0] = size0; + sizes_[1] = size1; + sizes_[2] = 1; + } + + //! \brief Constructs three-dimensional range. + NDRange(size_type size0, size_type size1, size_type size2) + : dimensions_(3) + { + sizes_[0] = size0; + sizes_[1] = size1; + sizes_[2] = size2; + } + + /*! \brief Conversion operator to const size_type *. + * + * \returns a pointer to the size of the first dimension. + */ + operator const size_type*() const { + return sizes_; + } + + //! \brief Queries the number of dimensions in the range. + size_type dimensions() const + { + return dimensions_; + } + + //! \brief Returns the size of the object in bytes based on the + // runtime number of dimensions + size_type size() const + { + return dimensions_*sizeof(size_type); + } + + size_type* get() + { + return sizes_; + } + + const size_type* get() const + { + return sizes_; + } +}; + +//! \brief A zero-dimensional range. +static const NDRange NullRange; + +//! \brief Local address wrapper for use with Kernel::setArg +struct LocalSpaceArg +{ + size_type size_; +}; + +namespace detail { + +template +struct KernelArgumentHandler; + +// Enable for objects that are not subclasses of memory +// Pointers, constants etc +template +struct KernelArgumentHandler::value>::type> +{ + static size_type size(const T&) { return sizeof(T); } + static const T* ptr(const T& value) { return &value; } +}; + +// Enable for subclasses of memory where we want to get a reference to the cl_mem out +// and pass that in for safety +template +struct KernelArgumentHandler::value>::type> +{ + static size_type size(const T&) { return sizeof(cl_mem); } + static const cl_mem* ptr(const T& value) { return &(value()); } +}; + +// Specialization for DeviceCommandQueue defined later + +template <> +struct KernelArgumentHandler +{ + static size_type size(const LocalSpaceArg& value) { return value.size_; } + static const void* ptr(const LocalSpaceArg&) { return NULL; } +}; + +} +//! \endcond + +/*! Local + * \brief Helper function for generating LocalSpaceArg objects. + */ +inline LocalSpaceArg +Local(size_type size) +{ + LocalSpaceArg ret = { size }; + return ret; +} + +/*! \brief Class interface for cl_kernel. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_kernel as the original. For details, see + * clRetainKernel() and clReleaseKernel(). + * + * \see cl_kernel + */ +class Kernel : public detail::Wrapper +{ +public: + inline Kernel(const Program& program, const char* name, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Kernel() { } + + /*! \brief Constructor from cl_kernel - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * This effectively transfers ownership of a refcount on the cl_kernel + * into the new Kernel object. + */ + explicit Kernel(const cl_kernel& kernel, bool retainObject = false) : + detail::Wrapper(kernel, retainObject) { } + + /*! \brief Assignment operator from cl_kernel - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseKernel() on the value previously held by this instance. + */ + Kernel& operator = (const cl_kernel& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel(const Kernel& kernel) : detail::Wrapper(kernel) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (const Kernel &kernel) + { + detail::Wrapper::operator=(kernel); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(kernel)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (Kernel &&kernel) + { + detail::Wrapper::operator=(std::move(kernel)); + return *this; + } + + template + cl_int getInfo(cl_kernel_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelInfo, object_, name, param), + __GET_KERNEL_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + template + cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param), + __GET_KERNEL_ARG_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getArgInfo(cl_uint argIndex, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_arg_info, name>::param_type param; + cl_int result = getArgInfo(argIndex, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + template + cl_int getWorkGroupInfo( + const Device& device, cl_kernel_work_group_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetKernelWorkGroupInfo, object_, device(), name, param), + __GET_KERNEL_WORK_GROUP_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getWorkGroupInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_work_group_info, name>::param_type param; + cl_int result = getWorkGroupInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +#if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) + cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const + { + typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR; + static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL; + CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR); + + return detail::errHandler( + pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr), + __GET_KERNEL_ARG_INFO_ERR); + } + + template + size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = NULL) const + { + size_type param; + cl_int result = getSubGroupInfo(dev, name, range, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +#endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /*! \brief setArg overload taking a shared_ptr type + */ + template + cl_int setArg(cl_uint index, const cl::pointer &argPtr) + { + return detail::errHandler( + ::clSetKernelArgSVMPointer(object_, index, argPtr.get()), + __SET_KERNEL_ARGS_ERR); + } + + /*! \brief setArg overload taking a vector type. + */ + template + cl_int setArg(cl_uint index, const cl::vector &argPtr) + { + return detail::errHandler( + ::clSetKernelArgSVMPointer(object_, index, argPtr.data()), + __SET_KERNEL_ARGS_ERR); + } + + /*! \brief setArg overload taking a pointer type + */ + template + typename std::enable_if::value, cl_int>::type + setArg(cl_uint index, const T argPtr) + { + return detail::errHandler( + ::clSetKernelArgSVMPointer(object_, index, argPtr), + __SET_KERNEL_ARGS_ERR); + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + /*! \brief setArg overload taking a POD type + */ + template + typename std::enable_if::value, cl_int>::type + setArg(cl_uint index, const T &value) + { + return detail::errHandler( + ::clSetKernelArg( + object_, + index, + detail::KernelArgumentHandler::size(value), + detail::KernelArgumentHandler::ptr(value)), + __SET_KERNEL_ARGS_ERR); + } + + cl_int setArg(cl_uint index, size_type size, const void* argPtr) + { + return detail::errHandler( + ::clSetKernelArg(object_, index, size, argPtr), + __SET_KERNEL_ARGS_ERR); + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /*! + * Specify a vector of SVM pointers that the kernel may access in + * addition to its arguments. + */ + cl_int setSVMPointers(const vector &pointerList) + { + return detail::errHandler( + ::clSetKernelExecInfo( + object_, + CL_KERNEL_EXEC_INFO_SVM_PTRS, + sizeof(void*)*pointerList.size(), + pointerList.data())); + } + + /*! + * Specify a std::array of SVM pointers that the kernel may access in + * addition to its arguments. + */ + template + cl_int setSVMPointers(const std::array &pointerList) + { + return detail::errHandler( + ::clSetKernelExecInfo( + object_, + CL_KERNEL_EXEC_INFO_SVM_PTRS, + sizeof(void*)*pointerList.size(), + pointerList.data())); + } + + /*! \brief Enable fine-grained system SVM. + * + * \note It is only possible to enable fine-grained system SVM if all devices + * in the context associated with kernel support it. + * + * \param svmEnabled True if fine-grained system SVM is requested. False otherwise. + * \return CL_SUCCESS if the function was executed succesfully. CL_INVALID_OPERATION + * if no devices in the context support fine-grained system SVM. + * + * \see clSetKernelExecInfo + */ + cl_int enableFineGrainedSystemSVM(bool svmEnabled) + { + cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE; + return detail::errHandler( + ::clSetKernelExecInfo( + object_, + CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, + sizeof(cl_bool), + &svmEnabled_ + ) + ); + } + + template + void setSVMPointersHelper(std::array &pointerList, const pointer &t0, Ts... ts) + { + pointerList[index] = static_cast(t0.get()); + setSVMPointersHelper(ts...); + } + + template + typename std::enable_if::value, void>::type + setSVMPointersHelper(std::array &pointerList, T0 t0, Ts... ts) + { + pointerList[index] = static_cast(t0); + setSVMPointersHelper(ts...); + } + + template + void setSVMPointersHelper(std::array &pointerList, const pointer &t0) + { + pointerList[index] = static_cast(t0.get()); + } + + template + typename std::enable_if::value, void>::type + setSVMPointersHelper(std::array &pointerList, T0 t0) + { + pointerList[index] = static_cast(t0); + } + + template + cl_int setSVMPointers(const T0 &t0, Ts... ts) + { + std::array pointerList; + + setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...); + return detail::errHandler( + ::clSetKernelExecInfo( + object_, + CL_KERNEL_EXEC_INFO_SVM_PTRS, + sizeof(void*)*(1 + sizeof...(Ts)), + pointerList.data())); + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 +}; + +/*! \class Program + * \brief Program interface that implements cl_program. + */ +class Program : public detail::Wrapper +{ +public: +#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + typedef vector> Binaries; + typedef vector Sources; +#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + typedef vector > Binaries; + typedef vector > Sources; +#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + + Program( + const string& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const size_type length = source.size(); + + Context context = Context::getDefault(err); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + + error = ::clBuildProgram( + object_, + 0, + NULL, +#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD) + "-cl-std=CL2.0", +#else + "", +#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD) + NULL, + NULL); + + detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo()); + } + + if (err != NULL) { + *err = error; + } + } + + Program( + const Context& context, + const string& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const size_type length = source.size(); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + error = ::clBuildProgram( + object_, + 0, + NULL, +#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD) + "-cl-std=CL2.0", +#else + "", +#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD) + NULL, + NULL); + + detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo()); + } + + if (err != NULL) { + *err = error; + } + } + + /** + * Create a program from a vector of source strings and the default context. + * Does not compile or link the program. + */ + Program( + const Sources& sources, + cl_int* err = NULL) + { + cl_int error; + Context context = Context::getDefault(err); + + const size_type n = (size_type)sources.size(); + + vector lengths(n); + vector strings(n); + + for (size_type i = 0; i < n; ++i) { +#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + strings[i] = sources[(int)i].data(); + lengths[i] = sources[(int)i].length(); +#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + strings[i] = sources[(int)i].first; + lengths[i] = sources[(int)i].second; +#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + } + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)n, strings.data(), lengths.data(), &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + if (err != NULL) { + *err = error; + } + } + + /** + * Create a program from a vector of source strings and a provided context. + * Does not compile or link the program. + */ + Program( + const Context& context, + const Sources& sources, + cl_int* err = NULL) + { + cl_int error; + + const size_type n = (size_type)sources.size(); + + vector lengths(n); + vector strings(n); + + for (size_type i = 0; i < n; ++i) { +#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + strings[i] = sources[(int)i].data(); + lengths[i] = sources[(int)i].length(); +#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + strings[i] = sources[(int)i].first; + lengths[i] = sources[(int)i].second; +#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + } + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)n, strings.data(), lengths.data(), &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + if (err != NULL) { + *err = error; + } + } + + /** + * Construct a program object from a list of devices and a per-device list of binaries. + * \param context A valid OpenCL context in which to construct the program. + * \param devices A vector of OpenCL device objects for which the program will be created. + * \param binaries A vector of pairs of a pointer to a binary object and its length. + * \param binaryStatus An optional vector that on completion will be resized to + * match the size of binaries and filled with values to specify if each binary + * was successfully loaded. + * Set to CL_SUCCESS if the binary was successfully loaded. + * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL. + * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device. + * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors: + * CL_INVALID_CONTEXT if context is not a valid context. + * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices; + * or if any entry in binaries is NULL or has length 0. + * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context. + * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device. + * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host. + */ + Program( + const Context& context, + const vector& devices, + const Binaries& binaries, + vector* binaryStatus = NULL, + cl_int* err = NULL) + { + cl_int error; + + const size_type numDevices = devices.size(); + + // Catch size mismatch early and return + if(binaries.size() != numDevices) { + error = CL_INVALID_VALUE; + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + + vector lengths(numDevices); + vector images(numDevices); +#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + for (size_type i = 0; i < numDevices; ++i) { + images[i] = binaries[i].data(); + lengths[i] = binaries[(int)i].size(); + } +#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + for (size_type i = 0; i < numDevices; ++i) { + images[i] = (const unsigned char*)binaries[i].first; + lengths[i] = binaries[(int)i].second; + } +#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + + vector deviceIDs(numDevices); + for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + if(binaryStatus) { + binaryStatus->resize(numDevices); + } + + object_ = ::clCreateProgramWithBinary( + context(), (cl_uint) devices.size(), + deviceIDs.data(), + lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0) + ? &binaryStatus->front() + : NULL, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + } + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + /** + * Create program using builtin kernels. + * \param kernelNames Semi-colon separated list of builtin kernel names + */ + Program( + const Context& context, + const vector& devices, + const string& kernelNames, + cl_int* err = NULL) + { + cl_int error; + + + size_type numDevices = devices.size(); + vector deviceIDs(numDevices); + for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateProgramWithBuiltInKernels( + context(), + (cl_uint) devices.size(), + deviceIDs.data(), + kernelNames.c_str(), + &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + Program() { } + + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + */ + explicit Program(const cl_program& program, bool retainObject = false) : + detail::Wrapper(program, retainObject) { } + + Program& operator = (const cl_program& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program(const Program& program) : detail::Wrapper(program) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (const Program &program) + { + detail::Wrapper::operator=(program); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Program(Program&& program) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(program)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (Program &&program) + { + detail::Wrapper::operator=(std::move(program)); + return *this; + } + + cl_int build( + const vector& devices, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + size_type numDevices = devices.size(); + vector deviceIDs(numDevices); + + for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + cl_int buildError = ::clBuildProgram( + object_, + (cl_uint) + devices.size(), + deviceIDs.data(), + options, + notifyFptr, + data); + + return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo()); + } + + cl_int build( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + cl_int buildError = ::clBuildProgram( + object_, + 0, + NULL, + options, + notifyFptr, + data); + + + return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo()); + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + cl_int compile( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + cl_int error = ::clCompileProgram( + object_, + 0, + NULL, + options, + 0, + NULL, + NULL, + notifyFptr, + data); + return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo()); + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + template + cl_int getInfo(cl_program_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetProgramInfo, object_, name, param), + __GET_PROGRAM_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + template + cl_int getBuildInfo( + const Device& device, cl_program_build_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetProgramBuildInfo, object_, device(), name, param), + __GET_PROGRAM_BUILD_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getBuildInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_build_info, name>::param_type param; + cl_int result = getBuildInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /** + * Build info function that returns a vector of device/info pairs for the specified + * info type and for all devices in the program. + * On an error reading the info for any device, an empty vector of info will be returned. + */ + template + vector::param_type>> + getBuildInfo(cl_int *err = NULL) const + { + cl_int result = CL_SUCCESS; + + auto devs = getInfo(&result); + vector::param_type>> + devInfo; + + // If there was an initial error from getInfo return the error + if (result != CL_SUCCESS) { + if (err != NULL) { + *err = result; + } + return devInfo; + } + + for (const cl::Device &d : devs) { + typename detail::param_traits< + detail::cl_program_build_info, name>::param_type param; + result = getBuildInfo(d, name, ¶m); + devInfo.push_back( + std::pair::param_type> + (d, param)); + if (result != CL_SUCCESS) { + // On error, leave the loop and return the error code + break; + } + } + if (err != NULL) { + *err = result; + } + if (result != CL_SUCCESS) { + devInfo.clear(); + } + return devInfo; + } + + cl_int createKernels(vector* kernels) + { + cl_uint numKernels; + cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + vector value(numKernels); + + err = ::clCreateKernelsInProgram( + object_, numKernels, value.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + if (kernels) { + kernels->resize(value.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < value.size(); i++) { + // We do not need to retain because this kernel is being created + // by the runtime + (*kernels)[i] = Kernel(value[i], false); + } + } + return CL_SUCCESS; + } +}; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +inline Program linkProgram( + Program input1, + Program input2, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + cl_program programs[2] = { input1(), input2() }; + + Context ctx = input1.getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + 2, + programs, + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog); +} + +inline Program linkProgram( + vector inputPrograms, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + vector programs(inputPrograms.size()); + + for (unsigned int i = 0; i < inputPrograms.size(); i++) { + programs[i] = inputPrograms[i](); + } + + Context ctx; + if(inputPrograms.size() > 0) { + ctx = inputPrograms[0].getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + } + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + (cl_uint)inputPrograms.size(), + programs.data(), + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog, false); +} +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + +// Template specialization for CL_PROGRAM_BINARIES +template <> +inline cl_int cl::Program::getInfo(cl_program_info name, vector>* param) const +{ + if (name != CL_PROGRAM_BINARIES) { + return CL_INVALID_VALUE; + } + if (param) { + // Resize the parameter array appropriately for each allocation + // and pass down to the helper + + vector sizes = getInfo(); + size_type numBinaries = sizes.size(); + + // Resize the parameter array and constituent arrays + param->resize(numBinaries); + for (size_type i = 0; i < numBinaries; ++i) { + (*param)[i].resize(sizes[i]); + } + + return detail::errHandler( + detail::getInfo(&::clGetProgramInfo, object_, name, param), + __GET_PROGRAM_INFO_ERR); + } + + return CL_SUCCESS; +} + +template<> +inline vector> cl::Program::getInfo(cl_int* err) const +{ + vector> binariesVectors; + + cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors); + if (err != NULL) { + *err = result; + } + return binariesVectors; +} + +inline Kernel::Kernel(const Program& program, const char* name, cl_int* err) +{ + cl_int error; + + object_ = ::clCreateKernel(program(), name, &error); + detail::errHandler(error, __CREATE_KERNEL_ERR); + + if (err != NULL) { + *err = error; + } + +} + +enum class QueueProperties : cl_command_queue_properties +{ + None = 0, + Profiling = CL_QUEUE_PROFILING_ENABLE, + OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, +}; + +inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs) +{ + return static_cast(static_cast(lhs) | static_cast(rhs)); +} + +/*! \class CommandQueue + * \brief CommandQueue interface for cl_command_queue. + */ +class CommandQueue : public detail::Wrapper +{ +private: + static std::once_flag default_initialized_; + static CommandQueue default_; + static cl_int default_error_; + + /*! \brief Create the default command queue returned by @ref getDefault. + * + * It sets default_error_ to indicate success or failure. It does not throw + * @c cl::Error. + */ + static void makeDefault() + { + /* We don't want to throw an error from this function, so we have to + * catch and set the error flag. + */ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try +#endif + { + int error; + Context context = Context::getDefault(&error); + + if (error != CL_SUCCESS) { + default_error_ = error; + } + else { + Device device = Device::getDefault(); + default_ = CommandQueue(context, device, 0, &default_error_); + } + } +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + catch (cl::Error &e) { + default_error_ = e.err(); + } +#endif + } + + /*! \brief Create the default command queue. + * + * This sets @c default_. It does not throw + * @c cl::Error. + */ + static void makeDefaultProvided(const CommandQueue &c) { + default_ = c; + } + +public: +#ifdef CL_HPP_UNIT_TEST_ENABLE + /*! \brief Reset the default. + * + * This sets @c default_ to an empty value to support cleanup in + * the unit test framework. + * This function is not thread safe. + */ + static void unitTestClearDefault() { + default_ = CommandQueue(); + } +#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE + + + /*! + * \brief Constructs a CommandQueue based on passed properties. + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + CommandQueue( + cl_command_queue_properties properties, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, 0 }; + if ((properties & CL_QUEUE_ON_DEVICE) == 0) { + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + } + else { + error = CL_INVALID_QUEUE_PROPERTIES; + } + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + } + + /*! + * \brief Constructs a CommandQueue based on passed properties. + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + CommandQueue( + QueueProperties properties, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, static_cast(properties), 0 }; + + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), device(), static_cast(properties), &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + } + + /*! + * \brief Constructs a CommandQueue for an implementation defined device in the given context + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + explicit CommandQueue( + const Context& context, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + vector devices; + error = context.getInfo(CL_CONTEXT_DEVICES, &devices); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) + { + if (err != NULL) { + *err = error; + } + return; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, 0 }; + if ((properties & CL_QUEUE_ON_DEVICE) == 0) { + object_ = ::clCreateCommandQueueWithProperties( + context(), devices[0](), queue_properties, &error); + } + else { + error = CL_INVALID_QUEUE_PROPERTIES; + } + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), devices[0](), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + + } + + /*! + * \brief Constructs a CommandQueue for an implementation defined device in the given context + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + explicit CommandQueue( + const Context& context, + QueueProperties properties, + cl_int* err = NULL) + { + cl_int error; + vector devices; + error = context.getInfo(CL_CONTEXT_DEVICES, &devices); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) + { + if (err != NULL) { + *err = error; + } + return; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, static_cast(properties), 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), devices[0](), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), devices[0](), static_cast(properties), &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + + } + + /*! + * \brief Constructs a CommandQueue for a passed device and context + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + CommandQueue( + const Context& context, + const Device& device, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + + /*! + * \brief Constructs a CommandQueue for a passed device and context + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + CommandQueue( + const Context& context, + const Device& device, + QueueProperties properties, + cl_int* err = NULL) + { + cl_int error; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, static_cast(properties), 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), device(), static_cast(properties), &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + + static CommandQueue getDefault(cl_int * err = NULL) + { + std::call_once(default_initialized_, makeDefault); +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); +#else // CL_HPP_TARGET_OPENCL_VERSION >= 200 + detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR); +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200 + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + /** + * Modify the default command queue to be used by + * subsequent operations. + * Will only set the default if no default was previously created. + * @return updated default command queue. + * Should be compared to the passed value to ensure that it was updated. + */ + static CommandQueue setDefault(const CommandQueue &default_queue) + { + std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue)); + detail::errHandler(default_error_); + return default_; + } + + CommandQueue() { } + + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + */ + explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) : + detail::Wrapper(commandQueue, retainObject) { } + + CommandQueue& operator = (const cl_command_queue& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(const CommandQueue& queue) : detail::Wrapper(queue) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (const CommandQueue &queue) + { + detail::Wrapper::operator=(queue); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(queue)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (CommandQueue &&queue) + { + detail::Wrapper::operator=(std::move(queue)); + return *this; + } + + template + cl_int getInfo(cl_command_queue_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetCommandQueueInfo, object_, name, param), + __GET_COMMAND_QUEUE_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_command_queue_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + size_type offset, + size_type size, + void* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + size_type offset, + size_type size, + const void* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + size_type src_offset, + size_type dst_offset, + size_type size, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBuffer( + object_, src(), dst(), src_offset, dst_offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const array& buffer_offset, + const array& host_offset, + const array& region, + size_type buffer_row_pitch, + size_type buffer_slice_pitch, + size_type host_row_pitch, + size_type host_slice_pitch, + void *ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBufferRect( + object_, + buffer(), + blocking, + buffer_offset.data(), + host_offset.data(), + region.data(), + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const array& buffer_offset, + const array& host_offset, + const array& region, + size_type buffer_row_pitch, + size_type buffer_slice_pitch, + size_type host_row_pitch, + size_type host_slice_pitch, + const void *ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBufferRect( + object_, + buffer(), + blocking, + buffer_offset.data(), + host_offset.data(), + region.data(), + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const array& src_origin, + const array& dst_origin, + const array& region, + size_type src_row_pitch, + size_type src_slice_pitch, + size_type dst_row_pitch, + size_type dst_slice_pitch, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferRect( + object_, + src(), + dst(), + src_origin.data(), + dst_origin.data(), + region.data(), + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + /** + * Enqueue a command to fill a buffer object with a pattern + * of a given size. The pattern is specified as a vector type. + * \tparam PatternType The datatype of the pattern field. + * The pattern type must be an accepted OpenCL data type. + * \tparam offset Is the offset in bytes into the buffer at + * which to start filling. This must be a multiple of + * the pattern size. + * \tparam size Is the size in bytes of the region to fill. + * This must be a multiple of the pattern size. + */ + template + cl_int enqueueFillBuffer( + const Buffer& buffer, + PatternType pattern, + size_type offset, + size_type size, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillBuffer( + object_, + buffer(), + static_cast(&pattern), + sizeof(PatternType), + offset, + size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const array& origin, + const array& region, + size_type row_pitch, + size_type slice_pitch, + void* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadImage( + object_, + image(), + blocking, + origin.data(), + region.data(), + row_pitch, + slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const array& origin, + const array& region, + size_type row_pitch, + size_type slice_pitch, + const void* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteImage( + object_, + image(), + blocking, + origin.data(), + region.data(), + row_pitch, + slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const array& src_origin, + const array& dst_origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImage( + object_, + src(), + dst(), + src_origin.data(), + dst_origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA floating-point color value if + * the image channel data type is not an unnormalized signed or + * unsigned data type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_float4 fillColor, + const array& origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA signed integer color value if + * the image channel data type is an unnormalized signed integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_int4 fillColor, + const array& origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA unsigned integer color value if + * the image channel data type is an unnormalized unsigned integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_uint4 fillColor, + const array& origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const array& src_origin, + const array& region, + size_type dst_offset, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImageToBuffer( + object_, + src(), + dst(), + src_origin.data(), + region.data(), + dst_offset, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + size_type src_offset, + const array& dst_origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferToImage( + object_, + src(), + dst(), + src_offset, + dst_origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + size_type offset, + size_type size, + const vector* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapBuffer( + object_, buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + + return result; + } + + void* enqueueMapImage( + const Image& buffer, + cl_bool blocking, + cl_map_flags flags, + const array& origin, + const array& region, + size_type * row_pitch, + size_type * slice_pitch, + const vector* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapImage( + object_, buffer(), blocking, flags, + origin.data(), + region.data(), + row_pitch, slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + return result; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /** + * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer. + * This variant takes a raw SVM pointer. + */ + template + cl_int enqueueMapSVM( + T* ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler(::clEnqueueSVMMap( + object_, blocking, flags, static_cast(ptr), size, + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MAP_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + + /** + * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer. + * This variant takes a cl::pointer instance. + */ + template + cl_int enqueueMapSVM( + cl::pointer &ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler(::clEnqueueSVMMap( + object_, blocking, flags, static_cast(ptr.get()), size, + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MAP_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer. + * This variant takes a cl::vector instance. + */ + template + cl_int enqueueMapSVM( + cl::vector &container, + cl_bool blocking, + cl_map_flags flags, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler(::clEnqueueSVMMap( + object_, blocking, flags, static_cast(container.data()), container.size(), + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MAP_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + object_, memory(), mapped_ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /** + * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime. + * This variant takes a raw SVM pointer. + */ + template + cl_int enqueueUnmapSVM( + T* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueSVMUnmap( + object_, static_cast(ptr), + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime. + * This variant takes a cl::pointer instance. + */ + template + cl_int enqueueUnmapSVM( + cl::pointer &ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueSVMUnmap( + object_, static_cast(ptr.get()), + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime. + * This variant takes a cl::vector instance. + */ + template + cl_int enqueueUnmapSVM( + cl::vector &container, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueSVMUnmap( + object_, static_cast(container.data()), + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + /** + * Enqueues a marker command which waits for either a list of events to complete, + * or all previously enqueued commands to complete. + * + * Enqueues a marker command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command returns an event which can be waited on, + * i.e. this event can be waited on to insure that all events either in the event_wait_list + * or all previously enqueued commands, queued before this command to command_queue, + * have completed. + */ + cl_int enqueueMarkerWithWaitList( + const vector *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarkerWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * A synchronization point that enqueues a barrier operation. + * + * Enqueues a barrier command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command blocks command execution, that is, any + * following commands enqueued after it do not execute until it completes. This command + * returns an event which can be waited on, i.e. this event can be waited on to insure that + * all events either in the event_wait_list or all previously enqueued commands, queued + * before this command to command_queue, have completed. + */ + cl_int enqueueBarrierWithWaitList( + const vector *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueBarrierWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_BARRIER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command to indicate with which device a set of memory objects + * should be associated. + */ + cl_int enqueueMigrateMemObjects( + const vector &memObjects, + cl_mem_migration_flags flags, + const vector* events = NULL, + Event* event = NULL + ) const + { + cl_event tmp; + + vector localMemObjects(memObjects.size()); + + for( int i = 0; i < (int)memObjects.size(); ++i ) { + localMemObjects[i] = memObjects[i](); + } + + + cl_int err = detail::errHandler( + ::clEnqueueMigrateMemObjects( + object_, + (cl_uint)memObjects.size(), + localMemObjects.data(), + flags, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + cl_int enqueueNDRangeKernel( + const Kernel& kernel, + const NDRange& offset, + const NDRange& global, + const NDRange& local = NullRange, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNDRangeKernel( + object_, kernel(), (cl_uint) global.dimensions(), + offset.dimensions() != 0 ? (const size_type*) offset : NULL, + (const size_type*) global, + local.dimensions() != 0 ? (const size_type*) local : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NDRANGE_KERNEL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) + CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask( + const Kernel& kernel, + const vector* events = NULL, + Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueTask( + object_, kernel(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_TASK_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) + + cl_int enqueueNativeKernel( + void (CL_CALLBACK *userFptr)(void *), + std::pair args, + const vector* mem_objects = NULL, + const vector* mem_locs = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + size_type elements = 0; + if (mem_objects != NULL) { + elements = mem_objects->size(); + } + vector mems(elements); + for (unsigned int i = 0; i < elements; i++) { + mems[i] = ((*mem_objects)[i])(); + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNativeKernel( + object_, userFptr, args.first, args.second, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + mems.data(), + (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NATIVE_KERNEL); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarker( + object_, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueWaitForEvents(const vector& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueWaitForEvents( + object_, + (cl_uint) events.size(), + events.size() > 0 ? (const cl_event*) &events.front() : NULL), + __ENQUEUE_WAIT_FOR_EVENTS_ERR); + } +#endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + + cl_int enqueueAcquireGLObjects( + const vector* mem_objects = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueAcquireGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseGLObjects( + const vector* mem_objects = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReleaseGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined (CL_HPP_USE_DX_INTEROP) +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); + + cl_int enqueueAcquireD3D10Objects( + const vector* mem_objects = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL; +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR); +#endif +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR); +#endif + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueAcquireD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseD3D10Objects( + const vector* mem_objects = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL; +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR); +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR); +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueReleaseD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueBarrier(object_), + __ENQUEUE_BARRIER_ERR); + } +#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS + + cl_int flush() const + { + return detail::errHandler(::clFlush(object_), __FLUSH_ERR); + } + + cl_int finish() const + { + return detail::errHandler(::clFinish(object_), __FINISH_ERR); + } +}; // CommandQueue + +CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_; +CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_; +CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS; + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +enum class DeviceQueueProperties : cl_command_queue_properties +{ + None = 0, + Profiling = CL_QUEUE_PROFILING_ENABLE, +}; + +inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs) +{ + return static_cast(static_cast(lhs) | static_cast(rhs)); +} + +/*! \class DeviceCommandQueue + * \brief DeviceCommandQueue interface for device cl_command_queues. + */ +class DeviceCommandQueue : public detail::Wrapper +{ +public: + + /*! + * Trivial empty constructor to create a null queue. + */ + DeviceCommandQueue() { } + + /*! + * Default construct device command queue on default context and device + */ + DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = NULL) + { + cl_int error; + cl::Context context = cl::Context::getDefault(); + cl::Device device = cl::Device::getDefault(); + + cl_command_queue_properties mergedProperties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast(properties); + + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, mergedProperties, 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! + * Create a device command queue for a specified device in the passed context. + */ + DeviceCommandQueue( + const Context& context, + const Device& device, + DeviceQueueProperties properties = DeviceQueueProperties::None, + cl_int* err = NULL) + { + cl_int error; + + cl_command_queue_properties mergedProperties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast(properties); + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, mergedProperties, 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! + * Create a device command queue for a specified device in the passed context. + */ + DeviceCommandQueue( + const Context& context, + const Device& device, + cl_uint queueSize, + DeviceQueueProperties properties = DeviceQueueProperties::None, + cl_int* err = NULL) + { + cl_int error; + + cl_command_queue_properties mergedProperties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast(properties); + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, mergedProperties, + CL_QUEUE_SIZE, queueSize, + 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructor from cl_command_queue - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + */ + explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) : + detail::Wrapper(commandQueue, retainObject) { } + + DeviceCommandQueue& operator = (const cl_command_queue& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + DeviceCommandQueue(const DeviceCommandQueue& queue) : detail::Wrapper(queue) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + DeviceCommandQueue& operator = (const DeviceCommandQueue &queue) + { + detail::Wrapper::operator=(queue); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + DeviceCommandQueue(DeviceCommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(queue)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + DeviceCommandQueue& operator = (DeviceCommandQueue &&queue) + { + detail::Wrapper::operator=(std::move(queue)); + return *this; + } + + template + cl_int getInfo(cl_command_queue_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetCommandQueueInfo, object_, name, param), + __GET_COMMAND_QUEUE_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_command_queue_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! + * Create a new default device command queue for the default device, + * in the default context and of the default size. + * If there is already a default queue for the specified device this + * function will return the pre-existing queue. + */ + static DeviceCommandQueue makeDefault( + cl_int *err = nullptr) + { + cl_int error; + cl::Context context = cl::Context::getDefault(); + cl::Device device = cl::Device::getDefault(); + + cl_command_queue_properties properties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT; + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, + 0 }; + DeviceCommandQueue deviceQueue( + ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error)); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + + return deviceQueue; + } + + /*! + * Create a new default device command queue for the specified device + * and of the default size. + * If there is already a default queue for the specified device this + * function will return the pre-existing queue. + */ + static DeviceCommandQueue makeDefault( + const Context &context, const Device &device, cl_int *err = nullptr) + { + cl_int error; + + cl_command_queue_properties properties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT; + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, + 0 }; + DeviceCommandQueue deviceQueue( + ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error)); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + + return deviceQueue; + } + + /*! + * Create a new default device command queue for the specified device + * and of the requested size in bytes. + * If there is already a default queue for the specified device this + * function will return the pre-existing queue. + */ + static DeviceCommandQueue makeDefault( + const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr) + { + cl_int error; + + cl_command_queue_properties properties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT; + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, + CL_QUEUE_SIZE, queueSize, + 0 }; + DeviceCommandQueue deviceQueue( + ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error)); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + + return deviceQueue; + } +}; // DeviceCommandQueue + +namespace detail +{ + // Specialization for device command queue + template <> + struct KernelArgumentHandler + { + static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); } + static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); } + }; +} // namespace detail + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + +template< typename IteratorType > +Buffer::Buffer( + const Context &context, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + size_type size = sizeof(DataType)*(endIterator - startIterator); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + CommandQueue queue(context, 0, &error); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +template< typename IteratorType > +Buffer::Buffer( + const CommandQueue &queue, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if (readOnly) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + } + + size_type size = sizeof(DataType)*(endIterator - startIterator); + + Context context = queue.getInfo(); + + if (useHostPtr) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } + else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if (!useHostPtr) { + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +inline cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + size_type offset, + size_type size, + void* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + size_type offset, + size_type size, + const void* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + size_type offset, + size_type size, + const vector* events = NULL, + Event* event = NULL, + cl_int* err = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + void * result = ::clEnqueueMapBuffer( + queue(), buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (cl_event*) event, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + return result; +} + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +/** + * Enqueues to the default queue a command that will allow the host to + * update a region of a coarse-grained SVM buffer. + * This variant takes a raw SVM pointer. + */ +template +inline cl_int enqueueMapSVM( + T* ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events, + Event* event) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + } + + return queue.enqueueMapSVM( + ptr, blocking, flags, size, events, event); +} + +/** + * Enqueues to the default queue a command that will allow the host to + * update a region of a coarse-grained SVM buffer. + * This variant takes a cl::pointer instance. + */ +template +inline cl_int enqueueMapSVM( + cl::pointer ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + } + + return queue.enqueueMapSVM( + ptr, blocking, flags, size, events, event); +} + +/** + * Enqueues to the default queue a command that will allow the host to + * update a region of a coarse-grained SVM buffer. + * This variant takes a cl::vector instance. + */ +template +inline cl_int enqueueMapSVM( + cl::vector container, + cl_bool blocking, + cl_map_flags flags, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + } + + return queue.enqueueMapSVM( + container, blocking, flags, events, event); +} + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +inline cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (error != CL_SUCCESS) { + return error; + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + queue(), memory(), mapped_ptr, + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; +} + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +/** + * Enqueues to the default queue a command that will release a coarse-grained + * SVM buffer back to the OpenCL runtime. + * This variant takes a raw SVM pointer. + */ +template +inline cl_int enqueueUnmapSVM( + T* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + } + + return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + +} + +/** + * Enqueues to the default queue a command that will release a coarse-grained + * SVM buffer back to the OpenCL runtime. + * This variant takes a cl::pointer instance. + */ +template +inline cl_int enqueueUnmapSVM( + cl::pointer &ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + } + + return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); +} + +/** + * Enqueues to the default queue a command that will release a coarse-grained + * SVM buffer back to the OpenCL runtime. + * This variant takes a cl::vector instance. + */ +template +inline cl_int enqueueUnmapSVM( + cl::vector &container, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + } + + return detail::errHandler(queue.enqueueUnmapSVM(container, events, event), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); +} + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +inline cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + size_type src_offset, + size_type dst_offset, + size_type size, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, startIterator, endIterator, buffer); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, buffer, startIterator, endIterator); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + size_type length = endIterator-startIterator; + size_type byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } +#if defined(_MSC_VER) + std::copy( + startIterator, + endIterator, + stdext::checked_array_iterator( + pointer, length)); +#else + std::copy(startIterator, endIterator, pointer); +#endif + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + size_type length = endIterator-startIterator; + size_type byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } + std::copy(pointer, pointer + length, startIterator); + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +/** + * Blocking SVM map operation - performs a blocking map underneath. + */ +template +inline cl_int mapSVM(cl::vector &container) +{ + return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE); +} + +/** +* Blocking SVM map operation - performs a blocking map underneath. +*/ +template +inline cl_int unmapSVM(cl::vector &container) +{ + return enqueueUnmapSVM(container); +} + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 +inline cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const array& buffer_offset, + const array& host_offset, + const array& region, + size_type buffer_row_pitch, + size_type buffer_slice_pitch, + size_type host_row_pitch, + size_type host_slice_pitch, + void *ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const array& buffer_offset, + const array& host_offset, + const array& region, + size_type buffer_row_pitch, + size_type buffer_slice_pitch, + size_type host_row_pitch, + size_type host_slice_pitch, + const void *ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const array& src_origin, + const array& dst_origin, + const array& region, + size_type src_row_pitch, + size_type src_slice_pitch, + size_type dst_row_pitch, + size_type dst_slice_pitch, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferRect( + src, + dst, + src_origin, + dst_origin, + region, + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + events, + event); +} +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + +inline cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const array& origin, + const array& region, + size_type row_pitch, + size_type slice_pitch, + void* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const array& origin, + const array& region, + size_type row_pitch, + size_type slice_pitch, + const void* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const array& src_origin, + const array& dst_origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImage( + src, + dst, + src_origin, + dst_origin, + region, + events, + event); +} + +inline cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const array& src_origin, + const array& region, + size_type dst_offset, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImageToBuffer( + src, + dst, + src_origin, + region, + dst_offset, + events, + event); +} + +inline cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + size_type src_offset, + const array& dst_origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferToImage( + src, + dst, + src_offset, + dst_origin, + region, + events, + event); +} + + +inline cl_int flush(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.flush(); +} + +inline cl_int finish(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + + return queue.finish(); +} + +class EnqueueArgs +{ +private: + CommandQueue queue_; + const NDRange offset_; + const NDRange global_; + const NDRange local_; + vector events_; + + template + friend class KernelFunctor; + +public: + EnqueueArgs(NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(Event e, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(const vector &events, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(const vector &events, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(const vector &events, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, const vector &events, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const vector &events, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const vector &events, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } +}; + + +//---------------------------------------------------------------------------------------------- + + +/** + * Type safe kernel functor. + * + */ +template +class KernelFunctor +{ +private: + Kernel kernel_; + + template + void setArgs(T0&& t0, T1s&&... t1s) + { + kernel_.setArg(index, t0); + setArgs(std::forward(t1s)...); + } + + template + void setArgs(T0&& t0) + { + kernel_.setArg(index, t0); + } + + template + void setArgs() + { + } + + +public: + KernelFunctor(Kernel kernel) : kernel_(kernel) + {} + + KernelFunctor( + const Program& program, + const string name, + cl_int * err = NULL) : + kernel_(program, name.c_str(), err) + {} + + //! \brief Return type of the functor + typedef Event result_type; + + /** + * Enqueue kernel. + * @param args Launch parameters of the kernel. + * @param t0... List of kernel arguments based on the template type of the functor. + */ + Event operator() ( + const EnqueueArgs& args, + Ts... ts) + { + Event event; + setArgs<0>(std::forward(ts)...); + + args.queue_.enqueueNDRangeKernel( + kernel_, + args.offset_, + args.global_, + args.local_, + &args.events_, + &event); + + return event; + } + + /** + * Enqueue kernel with support for error code. + * @param args Launch parameters of the kernel. + * @param t0... List of kernel arguments based on the template type of the functor. + * @param error Out parameter returning the error code from the execution. + */ + Event operator() ( + const EnqueueArgs& args, + Ts... ts, + cl_int &error) + { + Event event; + setArgs<0>(std::forward(ts)...); + + error = args.queue_.enqueueNDRangeKernel( + kernel_, + args.offset_, + args.global_, + args.local_, + &args.events_, + &event); + + return event; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_int setSVMPointers(const vector &pointerList) + { + return kernel_.setSVMPointers(pointerList); + } + + template + cl_int setSVMPointers(const T0 &t0, T1s... ts) + { + return kernel_.setSVMPointers(t0, ts...); + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + Kernel getKernel() + { + return kernel_; + } +}; + +namespace compatibility { + /** + * Backward compatibility class to ensure that cl.hpp code works with cl2.hpp. + * Please use KernelFunctor directly. + */ + template + struct make_kernel + { + typedef KernelFunctor FunctorType; + + FunctorType functor_; + + make_kernel( + const Program& program, + const string name, + cl_int * err = NULL) : + functor_(FunctorType(program, name, err)) + {} + + make_kernel( + const Kernel kernel) : + functor_(FunctorType(kernel)) + {} + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + Ts...); + + Event operator()( + const EnqueueArgs& enqueueArgs, + Ts... args) + { + return functor_( + enqueueArgs, args...); + } + }; +} // namespace compatibility + + +//---------------------------------------------------------------------------------------------------------------------- + +#undef CL_HPP_ERR_STR_ +#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) +#undef __GET_DEVICE_INFO_ERR +#undef __GET_PLATFORM_INFO_ERR +#undef __GET_DEVICE_IDS_ERR +#undef __GET_CONTEXT_INFO_ERR +#undef __GET_EVENT_INFO_ERR +#undef __GET_EVENT_PROFILE_INFO_ERR +#undef __GET_MEM_OBJECT_INFO_ERR +#undef __GET_IMAGE_INFO_ERR +#undef __GET_SAMPLER_INFO_ERR +#undef __GET_KERNEL_INFO_ERR +#undef __GET_KERNEL_ARG_INFO_ERR +#undef __GET_KERNEL_WORK_GROUP_INFO_ERR +#undef __GET_PROGRAM_INFO_ERR +#undef __GET_PROGRAM_BUILD_INFO_ERR +#undef __GET_COMMAND_QUEUE_INFO_ERR + +#undef __CREATE_CONTEXT_ERR +#undef __CREATE_CONTEXT_FROM_TYPE_ERR +#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR + +#undef __CREATE_BUFFER_ERR +#undef __CREATE_SUBBUFFER_ERR +#undef __CREATE_IMAGE2D_ERR +#undef __CREATE_IMAGE3D_ERR +#undef __CREATE_SAMPLER_ERR +#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR + +#undef __CREATE_USER_EVENT_ERR +#undef __SET_USER_EVENT_STATUS_ERR +#undef __SET_EVENT_CALLBACK_ERR +#undef __SET_PRINTF_CALLBACK_ERR + +#undef __WAIT_FOR_EVENTS_ERR + +#undef __CREATE_KERNEL_ERR +#undef __SET_KERNEL_ARGS_ERR +#undef __CREATE_PROGRAM_WITH_SOURCE_ERR +#undef __CREATE_PROGRAM_WITH_BINARY_ERR +#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR +#undef __BUILD_PROGRAM_ERR +#undef __CREATE_KERNELS_IN_PROGRAM_ERR + +#undef __CREATE_COMMAND_QUEUE_ERR +#undef __SET_COMMAND_QUEUE_PROPERTY_ERR +#undef __ENQUEUE_READ_BUFFER_ERR +#undef __ENQUEUE_WRITE_BUFFER_ERR +#undef __ENQUEUE_READ_BUFFER_RECT_ERR +#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR +#undef __ENQEUE_COPY_BUFFER_ERR +#undef __ENQEUE_COPY_BUFFER_RECT_ERR +#undef __ENQUEUE_READ_IMAGE_ERR +#undef __ENQUEUE_WRITE_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR +#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR +#undef __ENQUEUE_MAP_BUFFER_ERR +#undef __ENQUEUE_MAP_IMAGE_ERR +#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR +#undef __ENQUEUE_NDRANGE_KERNEL_ERR +#undef __ENQUEUE_TASK_ERR +#undef __ENQUEUE_NATIVE_KERNEL + +#undef __UNLOAD_COMPILER_ERR +#undef __CREATE_SUB_DEVICES_ERR + +#undef __CREATE_PIPE_ERR +#undef __GET_PIPE_INFO_ERR + +#endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS + +// Extensions +#undef CL_HPP_INIT_CL_EXT_FCN_PTR_ +#undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_ + +#if defined(CL_HPP_USE_CL_DEVICE_FISSION) +#undef CL_HPP_PARAM_NAME_DEVICE_FISSION_ +#endif // CL_HPP_USE_CL_DEVICE_FISSION + +#undef CL_HPP_NOEXCEPT_ +#undef CL_HPP_DEFINE_STATIC_MEMBER_ + +} // namespace cl + +#endif // CL_HPP_ diff --git a/opencl/khronos/headers/opencl2.1/CL/cl_d3d10.h b/opencl/khronos/headers/opencl2.1/CL/cl_d3d10.h new file mode 100644 index 0000000000..d5960a43f7 --- /dev/null +++ b/opencl/khronos/headers/opencl2.1/CL/cl_d3d10.h @@ -0,0 +1,131 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_CL_D3D10_H +#define __OPENCL_CL_D3D10_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * cl_khr_d3d10_sharing */ +#define cl_khr_d3d10_sharing 1 + +typedef cl_uint cl_d3d10_device_source_khr; +typedef cl_uint cl_d3d10_device_set_khr; + +/******************************************************************************/ + +/* Error Codes */ +#define CL_INVALID_D3D10_DEVICE_KHR -1002 +#define CL_INVALID_D3D10_RESOURCE_KHR -1003 +#define CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR -1004 +#define CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR -1005 + +/* cl_d3d10_device_source_nv */ +#define CL_D3D10_DEVICE_KHR 0x4010 +#define CL_D3D10_DXGI_ADAPTER_KHR 0x4011 + +/* cl_d3d10_device_set_nv */ +#define CL_PREFERRED_DEVICES_FOR_D3D10_KHR 0x4012 +#define CL_ALL_DEVICES_FOR_D3D10_KHR 0x4013 + +/* cl_context_info */ +#define CL_CONTEXT_D3D10_DEVICE_KHR 0x4014 +#define CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR 0x402C + +/* cl_mem_info */ +#define CL_MEM_D3D10_RESOURCE_KHR 0x4015 + +/* cl_image_info */ +#define CL_IMAGE_D3D10_SUBRESOURCE_KHR 0x4016 + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR 0x4017 +#define CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR 0x4018 + +/******************************************************************************/ + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D10KHR_fn)( + cl_platform_id platform, + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10BufferKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D10Buffer * resource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture2DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D10Texture2D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture3DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D10Texture3D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D10ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_D3D10_H */ + diff --git a/opencl/khronos/headers/opencl2.1/CL/cl_d3d11.h b/opencl/khronos/headers/opencl2.1/CL/cl_d3d11.h new file mode 100644 index 0000000000..39f9072398 --- /dev/null +++ b/opencl/khronos/headers/opencl2.1/CL/cl_d3d11.h @@ -0,0 +1,131 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_CL_D3D11_H +#define __OPENCL_CL_D3D11_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * cl_khr_d3d11_sharing */ +#define cl_khr_d3d11_sharing 1 + +typedef cl_uint cl_d3d11_device_source_khr; +typedef cl_uint cl_d3d11_device_set_khr; + +/******************************************************************************/ + +/* Error Codes */ +#define CL_INVALID_D3D11_DEVICE_KHR -1006 +#define CL_INVALID_D3D11_RESOURCE_KHR -1007 +#define CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR -1008 +#define CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR -1009 + +/* cl_d3d11_device_source */ +#define CL_D3D11_DEVICE_KHR 0x4019 +#define CL_D3D11_DXGI_ADAPTER_KHR 0x401A + +/* cl_d3d11_device_set */ +#define CL_PREFERRED_DEVICES_FOR_D3D11_KHR 0x401B +#define CL_ALL_DEVICES_FOR_D3D11_KHR 0x401C + +/* cl_context_info */ +#define CL_CONTEXT_D3D11_DEVICE_KHR 0x401D +#define CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR 0x402D + +/* cl_mem_info */ +#define CL_MEM_D3D11_RESOURCE_KHR 0x401E + +/* cl_image_info */ +#define CL_IMAGE_D3D11_SUBRESOURCE_KHR 0x401F + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR 0x4020 +#define CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR 0x4021 + +/******************************************************************************/ + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D11KHR_fn)( + cl_platform_id platform, + cl_d3d11_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d11_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11BufferKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D11Buffer * resource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture2DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D11Texture2D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture3DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D11Texture3D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D11ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_D3D11_H */ + diff --git a/opencl/khronos/headers/opencl2.1/CL/cl_dx9_media_sharing.h b/opencl/khronos/headers/opencl2.1/CL/cl_dx9_media_sharing.h new file mode 100644 index 0000000000..2729e8b9e8 --- /dev/null +++ b/opencl/khronos/headers/opencl2.1/CL/cl_dx9_media_sharing.h @@ -0,0 +1,132 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_CL_DX9_MEDIA_SHARING_H +#define __OPENCL_CL_DX9_MEDIA_SHARING_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/******************************************************************************/ +/* cl_khr_dx9_media_sharing */ +#define cl_khr_dx9_media_sharing 1 + +typedef cl_uint cl_dx9_media_adapter_type_khr; +typedef cl_uint cl_dx9_media_adapter_set_khr; + +#if defined(_WIN32) +#include +typedef struct _cl_dx9_surface_info_khr +{ + IDirect3DSurface9 *resource; + HANDLE shared_handle; +} cl_dx9_surface_info_khr; +#endif + + +/******************************************************************************/ + +/* Error Codes */ +#define CL_INVALID_DX9_MEDIA_ADAPTER_KHR -1010 +#define CL_INVALID_DX9_MEDIA_SURFACE_KHR -1011 +#define CL_DX9_MEDIA_SURFACE_ALREADY_ACQUIRED_KHR -1012 +#define CL_DX9_MEDIA_SURFACE_NOT_ACQUIRED_KHR -1013 + +/* cl_media_adapter_type_khr */ +#define CL_ADAPTER_D3D9_KHR 0x2020 +#define CL_ADAPTER_D3D9EX_KHR 0x2021 +#define CL_ADAPTER_DXVA_KHR 0x2022 + +/* cl_media_adapter_set_khr */ +#define CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2023 +#define CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2024 + +/* cl_context_info */ +#define CL_CONTEXT_ADAPTER_D3D9_KHR 0x2025 +#define CL_CONTEXT_ADAPTER_D3D9EX_KHR 0x2026 +#define CL_CONTEXT_ADAPTER_DXVA_KHR 0x2027 + +/* cl_mem_info */ +#define CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR 0x2028 +#define CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR 0x2029 + +/* cl_image_info */ +#define CL_IMAGE_DX9_MEDIA_PLANE_KHR 0x202A + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR 0x202B +#define CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR 0x202C + +/******************************************************************************/ + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromDX9MediaAdapterKHR_fn)( + cl_platform_id platform, + cl_uint num_media_adapters, + cl_dx9_media_adapter_type_khr * media_adapter_type, + void * media_adapters, + cl_dx9_media_adapter_set_khr media_adapter_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)( + cl_context context, + cl_mem_flags flags, + cl_dx9_media_adapter_type_khr adapter_type, + void * surface_info, + cl_uint plane, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9MediaSurfacesKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_DX9_MEDIA_SHARING_H */ + diff --git a/opencl/khronos/headers/opencl2.1/CL/cl_egl.h b/opencl/khronos/headers/opencl2.1/CL/cl_egl.h new file mode 100644 index 0000000000..a765bd5266 --- /dev/null +++ b/opencl/khronos/headers/opencl2.1/CL/cl_egl.h @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +#ifndef __OPENCL_CL_EGL_H +#define __OPENCL_CL_EGL_H + +#ifdef __APPLE__ + +#else +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Command type for events created with clEnqueueAcquireEGLObjectsKHR */ +#define CL_COMMAND_EGL_FENCE_SYNC_OBJECT_KHR 0x202F +#define CL_COMMAND_ACQUIRE_EGL_OBJECTS_KHR 0x202D +#define CL_COMMAND_RELEASE_EGL_OBJECTS_KHR 0x202E + +/* Error type for clCreateFromEGLImageKHR */ +#define CL_INVALID_EGL_OBJECT_KHR -1093 +#define CL_EGL_RESOURCE_NOT_ACQUIRED_KHR -1092 + +/* CLeglImageKHR is an opaque handle to an EGLImage */ +typedef void* CLeglImageKHR; + +/* CLeglDisplayKHR is an opaque handle to an EGLDisplay */ +typedef void* CLeglDisplayKHR; + +/* CLeglSyncKHR is an opaque handle to an EGLSync object */ +typedef void* CLeglSyncKHR; + +/* properties passed to clCreateFromEGLImageKHR */ +typedef intptr_t cl_egl_image_properties_khr; + + +#define cl_khr_egl_image 1 + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromEGLImageKHR(cl_context /* context */, + CLeglDisplayKHR /* egldisplay */, + CLeglImageKHR /* eglimage */, + cl_mem_flags /* flags */, + const cl_egl_image_properties_khr * /* properties */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromEGLImageKHR_fn)( + cl_context context, + CLeglDisplayKHR egldisplay, + CLeglImageKHR eglimage, + cl_mem_flags flags, + const cl_egl_image_properties_khr * properties, + cl_int * errcode_ret); + + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireEGLObjectsKHR(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireEGLObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event); + + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseEGLObjectsKHR(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseEGLObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event); + + +#define cl_khr_egl_event 1 + +extern CL_API_ENTRY cl_event CL_API_CALL +clCreateEventFromEGLSyncKHR(cl_context /* context */, + CLeglSyncKHR /* sync */, + CLeglDisplayKHR /* display */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_event (CL_API_CALL *clCreateEventFromEGLSyncKHR_fn)( + cl_context context, + CLeglSyncKHR sync, + CLeglDisplayKHR display, + cl_int * errcode_ret); + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_EGL_H */ diff --git a/opencl/khronos/headers/opencl2.1/CL/cl_ext.h b/opencl/khronos/headers/opencl2.1/CL/cl_ext.h new file mode 100644 index 0000000000..a1ca5a234b --- /dev/null +++ b/opencl/khronos/headers/opencl2.1/CL/cl_ext.h @@ -0,0 +1,745 @@ +/* Modifications Copyright (C) 2010-2021 Advanced Micro Devices, Inc. */ +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +/* $Revision: 11928 $ on $Date: 2010-07-13 09:04:56 -0700 (Tue, 13 Jul 2010) $ */ + +/* cl_ext.h contains OpenCL extensions which don't have external */ +/* (OpenGL, D3D) dependencies. */ + +#ifndef __CL_EXT_H +#define __CL_EXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __APPLE__ + #include + #include +#else + #include +#endif + +/* cl_khr_fp16 extension - no extension #define since it has no functions */ +#define CL_DEVICE_HALF_FP_CONFIG 0x1033 + +/* Memory object destruction + * + * Apple extension for use to manage externally allocated buffers used with cl_mem objects with CL_MEM_USE_HOST_PTR + * + * Registers a user callback function that will be called when the memory object is deleted and its resources + * freed. Each call to clSetMemObjectCallbackFn registers the specified user callback function on a callback + * stack associated with memobj. The registered user callback functions are called in the reverse order in + * which they were registered. The user callback functions are called and then the memory object is deleted + * and its resources freed. This provides a mechanism for the application (and libraries) using memobj to be + * notified when the memory referenced by host_ptr, specified when the memory object is created and used as + * the storage bits for the memory object, can be reused or freed. + * + * The application may not call CL api's with the cl_mem object passed to the pfn_notify. + * + * Please check for the "cl_APPLE_SetMemObjectDestructor" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) + * before using. + */ +#define cl_APPLE_SetMemObjectDestructor 1 +cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE( cl_mem /* memobj */, + void (* /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), + void * /*user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; + + +/* Context Logging Functions + * + * The next three convenience functions are intended to be used as the pfn_notify parameter to clCreateContext(). + * Please check for the "cl_APPLE_ContextLoggingFunctions" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) + * before using. + * + * clLogMessagesToSystemLog fowards on all log messages to the Apple System Logger + */ +#define cl_APPLE_ContextLoggingFunctions 1 +extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE( const char * /* errstr */, + const void * /* private_info */, + size_t /* cb */, + void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; + +/* clLogMessagesToStdout sends all log messages to the file descriptor stdout */ +extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE( const char * /* errstr */, + const void * /* private_info */, + size_t /* cb */, + void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; + +/* clLogMessagesToStderr sends all log messages to the file descriptor stderr */ +extern void CL_API_ENTRY clLogMessagesToStderrAPPLE( const char * /* errstr */, + const void * /* private_info */, + size_t /* cb */, + void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; + + +/************************ +* cl_khr_icd extension * +************************/ +#define cl_khr_icd 1 + +/* cl_platform_info */ +#define CL_PLATFORM_ICD_SUFFIX_KHR 0x0920 + +/* Additional Error Codes */ +#define CL_PLATFORM_NOT_FOUND_KHR -1001 + +extern CL_API_ENTRY cl_int CL_API_CALL +clIcdGetPlatformIDsKHR(cl_uint /* num_entries */, + cl_platform_id * /* platforms */, + cl_uint * /* num_platforms */); + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clIcdGetPlatformIDsKHR_fn)( + cl_uint /* num_entries */, + cl_platform_id * /* platforms */, + cl_uint * /* num_platforms */); + + +/* Extension: cl_khr_image2D_buffer + * + * This extension allows a 2D image to be created from a cl_mem buffer without a copy. + * The type associated with a 2D image created from a buffer in an OpenCL program is image2d_t. + * Both the sampler and sampler-less read_image built-in functions are supported for 2D images + * and 2D images created from a buffer. Similarly, the write_image built-ins are also supported + * for 2D images created from a buffer. + * + * When the 2D image from buffer is created, the client must specify the width, + * height, image format (i.e. channel order and channel data type) and optionally the row pitch + * + * The pitch specified must be a multiple of CL_DEVICE_IMAGE_PITCH_ALIGNMENT pixels. + * The base address of the buffer must be aligned to CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT pixels. + */ + +/************************************* + * cl_khr_initalize_memory extension * + *************************************/ + +#define CL_CONTEXT_MEMORY_INITIALIZE_KHR 0x2030 + + +/************************************** + * cl_khr_terminate_context extension * + **************************************/ + +#define CL_DEVICE_TERMINATE_CAPABILITY_KHR 0x2031 +#define CL_CONTEXT_TERMINATE_KHR 0x2032 + +#define cl_khr_terminate_context 1 +extern CL_API_ENTRY cl_int CL_API_CALL clTerminateContextKHR(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clTerminateContextKHR_fn)(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; + + +/* + * Extension: cl_khr_spir + * + * This extension adds support to create an OpenCL program object from a + * Standard Portable Intermediate Representation (SPIR) instance + */ + +#define CL_DEVICE_SPIR_VERSIONS 0x40E0 +#define CL_PROGRAM_BINARY_TYPE_INTERMEDIATE 0x40E1 + + +/****************************************** +* cl_nv_device_attribute_query extension * +******************************************/ +/* cl_nv_device_attribute_query extension - no extension #define since it has no functions */ +#define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 +#define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 +#define CL_DEVICE_REGISTERS_PER_BLOCK_NV 0x4002 +#define CL_DEVICE_WARP_SIZE_NV 0x4003 +#define CL_DEVICE_GPU_OVERLAP_NV 0x4004 +#define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 +#define CL_DEVICE_INTEGRATED_MEMORY_NV 0x4006 + +/********************************* +* cl_amd_device_memory_flags * +*********************************/ +#define cl_amd_device_memory_flags 1 +#define CL_MEM_USE_PERSISTENT_MEM_AMD (1 << 6) // Alloc from GPU's CPU visible heap + +/* cl_device_info */ +#define CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT 0x4032 + +/********************************* +* cl_amd_device_attribute_query * +*********************************/ +#define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 0x4036 +#define CL_DEVICE_TOPOLOGY_AMD 0x4037 +#define CL_DEVICE_BOARD_NAME_AMD 0x4038 +#define CL_DEVICE_GLOBAL_FREE_MEMORY_AMD 0x4039 +#define CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD 0x4040 +#define CL_DEVICE_SIMD_WIDTH_AMD 0x4041 +#define CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD 0x4042 +#define CL_DEVICE_WAVEFRONT_WIDTH_AMD 0x4043 +#define CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD 0x4044 +#define CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD 0x4045 +#define CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD 0x4046 +#define CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD 0x4047 +#define CL_DEVICE_LOCAL_MEM_BANKS_AMD 0x4048 +#define CL_DEVICE_THREAD_TRACE_SUPPORTED_AMD 0x4049 +#define CL_DEVICE_GFXIP_MAJOR_AMD 0x404A +#define CL_DEVICE_GFXIP_MINOR_AMD 0x404B +#define CL_DEVICE_AVAILABLE_ASYNC_QUEUES_AMD 0x404C +#define CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD 0x4030 +#define CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD 0x4031 +#define CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD 0x4033 +#define CL_DEVICE_PCIE_ID_AMD 0x4034 + +typedef union +{ + struct { cl_uint type; cl_uint data[5]; } raw; + struct { cl_uint type; cl_uchar unused[17]; cl_uchar bus; cl_uchar device; cl_uchar function; } pcie; +} cl_device_topology_amd; + +#define CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD 1 + +/************************** +* cl_amd_offline_devices * +**************************/ +#define CL_CONTEXT_OFFLINE_DEVICES_AMD 0x403F + +/******************************** +* cl_amd_bus_addressable_memory * +********************************/ + +/* cl_mem flag - bitfield */ +#define CL_MEM_BUS_ADDRESSABLE_AMD (1<<30) +#define CL_MEM_EXTERNAL_PHYSICAL_AMD (1<<31) + +#define CL_COMMAND_WAIT_SIGNAL_AMD 0x4080 +#define CL_COMMAND_WRITE_SIGNAL_AMD 0x4081 +#define CL_COMMAND_MAKE_BUFFERS_RESIDENT_AMD 0x4082 + +typedef struct _cl_bus_address_amd +{ + cl_ulong surface_bus_address; + cl_ulong marker_bus_address; +} cl_bus_address_amd; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueWaitSignalAMD_fn)( cl_command_queue /*command_queue*/, + cl_mem /*mem_object*/, + cl_uint /*value*/, + cl_uint /*num_events*/, + const cl_event * /*event_wait_list*/, + cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueWriteSignalAMD_fn)( cl_command_queue /*command_queue*/, + cl_mem /*mem_object*/, + cl_uint /*value*/, + cl_ulong /*offset*/, + cl_uint /*num_events*/, + const cl_event * /*event_list*/, + cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueMakeBuffersResidentAMD_fn)( cl_command_queue /*command_queue*/, + cl_uint /*num_mem_objs*/, + cl_mem * /*mem_objects*/, + cl_bool /*blocking_make_resident*/, + cl_bus_address_amd * /*bus_addresses*/, + cl_uint /*num_events*/, + const cl_event * /*event_list*/, + cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +/************************* +* cl_amd_copy_buffer_p2p * +**************************/ +#define CL_DEVICE_NUM_P2P_DEVICES_AMD 0x4088 +#define CL_DEVICE_P2P_DEVICES_AMD 0x4089 + +#define cl_amd_copy_buffer_p2p 1 + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueCopyBufferP2PAMD_fn)(cl_command_queue /*command_queue*/, + cl_mem /*src_buffer*/, + cl_mem /*dst_buffer*/, + size_t /*src_offset*/, + size_t /*dst_offset*/, + size_t /*cb*/, + cl_uint /*num_events_in_wait_list*/, + const cl_event* /*event_wait_list*/, + cl_event* /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +/*********************************** +* cl_amd_assembly_program extension * +***********************************/ +#define cl_amd_assembly_program 1 + +typedef CL_API_ENTRY cl_program (CL_API_CALL * clCreateProgramWithAssemblyAMD_fn) ( + cl_context /* context */, + cl_uint /* count */, + const char** /* strings */, + const size_t* /* lengths */, + cl_int* /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2; + +#ifdef CL_VERSION_2_0 +/******************************** +* cl_amd_planar_yuv * +********************************/ + +/* cl_mem flag - bitfield */ +#define CL_YUV_IMAGE_Y_PLANE_AMD 0x0 +#define CL_YUV_IMAGE_UV_PLANE_AMD 0x1 + +typedef CL_API_ENTRY cl_mem +(CL_API_CALL * clGetPlaneFromImageAMD_fn)(cl_context /*context*/, + cl_mem /*mem*/, + cl_uint /*plane*/, + cl_int * /*errcode_ret*/) CL_EXT_SUFFIX__VERSION_2_0; +#endif + +// +/************************** +* cl_amd_command_queue_info * +**************************/ +#define CL_QUEUE_THREAD_HANDLE_AMD 0x403E + +/* cl_kernel_exec_info for DVR DOPP texture support */ +#define CL_KERNEL_EXEC_INFO_NEW_VCOP_AMD 0x4120 +#define CL_KERNEL_EXEC_INFO_PFPA_VCOP_AMD 0x4121 +// + +/********************************* +* cl_arm_printf extension +*********************************/ +#define CL_PRINTF_CALLBACK_ARM 0x40B0 +#define CL_PRINTF_BUFFERSIZE_ARM 0x40B1 + +#ifdef CL_VERSION_1_1 + /*********************************** + * cl_ext_device_fission extension * + ***********************************/ + #define cl_ext_device_fission 1 + + extern CL_API_ENTRY cl_int CL_API_CALL + clReleaseDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + typedef CL_API_ENTRY cl_int + (CL_API_CALL *clReleaseDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + extern CL_API_ENTRY cl_int CL_API_CALL + clRetainDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + typedef CL_API_ENTRY cl_int + (CL_API_CALL *clRetainDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + typedef cl_ulong cl_device_partition_property_ext; + extern CL_API_ENTRY cl_int CL_API_CALL + clCreateSubDevicesEXT( cl_device_id /*in_device*/, + const cl_device_partition_property_ext * /* properties */, + cl_uint /*num_entries*/, + cl_device_id * /*out_devices*/, + cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + typedef CL_API_ENTRY cl_int + ( CL_API_CALL * clCreateSubDevicesEXT_fn)( cl_device_id /*in_device*/, + const cl_device_partition_property_ext * /* properties */, + cl_uint /*num_entries*/, + cl_device_id * /*out_devices*/, + cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + /* cl_device_partition_property_ext */ + #define CL_DEVICE_PARTITION_EQUALLY_EXT 0x4050 + #define CL_DEVICE_PARTITION_BY_COUNTS_EXT 0x4051 + #define CL_DEVICE_PARTITION_BY_NAMES_EXT 0x4052 + #define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT 0x4053 + + /* clDeviceGetInfo selectors */ + #define CL_DEVICE_PARENT_DEVICE_EXT 0x4054 + #define CL_DEVICE_PARTITION_TYPES_EXT 0x4055 + #define CL_DEVICE_AFFINITY_DOMAINS_EXT 0x4056 + #define CL_DEVICE_REFERENCE_COUNT_EXT 0x4057 + #define CL_DEVICE_PARTITION_STYLE_EXT 0x4058 + + /* clGetImageInfo enum */ + #define CL_IMAGE_BYTE_PITCH_AMD 0x4059 + + /* error codes */ + #define CL_DEVICE_PARTITION_FAILED_EXT -1057 + #define CL_INVALID_PARTITION_COUNT_EXT -1058 + #define CL_INVALID_PARTITION_NAME_EXT -1059 + + /* CL_AFFINITY_DOMAINs */ + #define CL_AFFINITY_DOMAIN_L1_CACHE_EXT 0x1 + #define CL_AFFINITY_DOMAIN_L2_CACHE_EXT 0x2 + #define CL_AFFINITY_DOMAIN_L3_CACHE_EXT 0x3 + #define CL_AFFINITY_DOMAIN_L4_CACHE_EXT 0x4 + #define CL_AFFINITY_DOMAIN_NUMA_EXT 0x10 + #define CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT 0x100 + + /* cl_device_partition_property_ext list terminators */ + #define CL_PROPERTIES_LIST_END_EXT ((cl_device_partition_property_ext) 0) + #define CL_PARTITION_BY_COUNTS_LIST_END_EXT ((cl_device_partition_property_ext) 0) + #define CL_PARTITION_BY_NAMES_LIST_END_EXT ((cl_device_partition_property_ext) 0 - 1) + +/********************************* +* cl_qcom_ext_host_ptr extension +*********************************/ + +#define CL_MEM_EXT_HOST_PTR_QCOM (1 << 29) + +#define CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM 0x40A0 +#define CL_DEVICE_PAGE_SIZE_QCOM 0x40A1 +#define CL_IMAGE_ROW_ALIGNMENT_QCOM 0x40A2 +#define CL_IMAGE_SLICE_ALIGNMENT_QCOM 0x40A3 +#define CL_MEM_HOST_UNCACHED_QCOM 0x40A4 +#define CL_MEM_HOST_WRITEBACK_QCOM 0x40A5 +#define CL_MEM_HOST_WRITETHROUGH_QCOM 0x40A6 +#define CL_MEM_HOST_WRITE_COMBINING_QCOM 0x40A7 + +typedef cl_uint cl_image_pitch_info_qcom; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceImageInfoQCOM(cl_device_id device, + size_t image_width, + size_t image_height, + const cl_image_format *image_format, + cl_image_pitch_info_qcom param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret); + +typedef struct _cl_mem_ext_host_ptr +{ + /* Type of external memory allocation. */ + /* Legal values will be defined in layered extensions. */ + cl_uint allocation_type; + + /* Host cache policy for this external memory allocation. */ + cl_uint host_cache_policy; + +} cl_mem_ext_host_ptr; + +/********************************* +* cl_qcom_ion_host_ptr extension +*********************************/ + +#define CL_MEM_ION_HOST_PTR_QCOM 0x40A8 + +typedef struct _cl_mem_ion_host_ptr +{ + /* Type of external memory allocation. */ + /* Must be CL_MEM_ION_HOST_PTR_QCOM for ION allocations. */ + cl_mem_ext_host_ptr ext_host_ptr; + + /* ION file descriptor */ + int ion_filedesc; + + /* Host pointer to the ION allocated memory */ + void* ion_hostptr; + +} cl_mem_ion_host_ptr; + +#endif /* CL_VERSION_1_1 */ + +#if defined(CL_VERSION_1_2) + +/****************************************** + * cl_img_yuv_image extension * + ******************************************/ + +/* Image formats used in clCreateImage */ +#define CL_NV21_IMG 0x40D0 +#define CL_YV12_IMG 0x40D1 + +/****************************************** + * cl_img_cached_allocations extension * + ******************************************/ + +/* Flag values used by clCreteBuffer */ +#define CL_MEM_USE_UNCACHED_CPU_MEMORY_IMG (1 << 26) +#define CL_MEM_USE_CACHED_CPU_MEMORY_IMG (1 << 27) + +/****************************************** + * cl_img_use_gralloc_ptr extension * + ******************************************/ + +/* Flag values used by clCreteBuffer */ +#define CL_MEM_USE_GRALLOC_PTR_IMG (1 << 28) + +/* To be used by clGetEventInfo: */ +#define CL_COMMAND_ACQUIRE_GRALLOC_OBJECTS_IMG 0x40D2 +#define CL_COMMAND_RELEASE_GRALLOC_OBJECTS_IMG 0x40D3 + +/* Error code from clEnqueueReleaseGrallocObjectsIMG */ +#define CL_GRALLOC_RESOURCE_NOT_ACQUIRED_IMG 0x40D4 + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireGrallocObjectsIMG(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseGrallocObjectsIMG(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +#endif /* CL_VERSION_1_2 */ + +#ifdef CL_VERSION_2_0 +/********************************* +* cl_khr_subgroups extension +*********************************/ +#define cl_khr_subgroups 1 + +/* cl_kernel_sub_group_info is declared in CL.h. */ + +/* cl_kernel_sub_group_info */ +#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR 0x2033 +#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR 0x2034 + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetKernelSubGroupInfoKHR(cl_kernel /* in_kernel */, + cl_device_id /*in_device*/, + cl_kernel_sub_group_info /* param_name */, + size_t /*input_value_size*/, + const void * /*input_value*/, + size_t /*param_value_size*/, + void* /*param_value*/, + size_t* /*param_value_size_ret*/ ) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; + +typedef CL_API_ENTRY cl_int + ( CL_API_CALL * clGetKernelSubGroupInfoKHR_fn)(cl_kernel /* in_kernel */, + cl_device_id /*in_device*/, + cl_kernel_sub_group_info /* param_name */, + size_t /*input_value_size*/, + const void * /*input_value*/, + size_t /*param_value_size*/, + void* /*param_value*/, + size_t* /*param_value_size_ret*/ ) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; +#endif /* CL_VERSION_2_0 */ + +#ifdef CL_VERSION_2_1 +/********************************* +* cl_khr_priority_hints extension +*********************************/ +#define cl_khr_priority_hints 1 + +typedef cl_uint cl_queue_priority_khr; + +/* cl_command_queue_properties */ +#define CL_QUEUE_PRIORITY_KHR 0x1096 + +/* cl_queue_priority_khr */ +#define CL_QUEUE_PRIORITY_HIGH_KHR (1<<0) +#define CL_QUEUE_PRIORITY_MED_KHR (1<<1) +#define CL_QUEUE_PRIORITY_LOW_KHR (1<<2) + +#endif /* CL_VERSION_2_1 */ + +#ifdef CL_VERSION_2_1 +/********************************* +* cl_khr_throttle_hints extension +*********************************/ +#define cl_khr_throttle_hints 1 + +typedef cl_uint cl_queue_throttle_khr; + +/* cl_command_queue_properties */ +#define CL_QUEUE_THROTTLE_KHR 0x1097 + +/* cl_queue_throttle_khr */ +#define CL_QUEUE_THROTTLE_HIGH_KHR (1<<0) +#define CL_QUEUE_THROTTLE_MED_KHR (1<<1) +#define CL_QUEUE_THROTTLE_LOW_KHR (1<<2) + +#endif /* CL_VERSION_2_1 */ + +/********************************** + * cl_arm_import_memory extension * + **********************************/ + +#ifdef CL_VERSION_1_0 + +typedef intptr_t cl_import_properties_arm; + +/* Default and valid proporties name for cl_arm_import_memory */ +#define CL_IMPORT_TYPE_ARM 0x40B2 + +/* Host process memory type default value for CL_IMPORT_TYPE_ARM property */ +#define CL_IMPORT_TYPE_HOST_ARM 0x40B3 + +/* DMA BUF memory type value for CL_IMPORT_TYPE_ARM property */ +#define CL_IMPORT_TYPE_DMA_BUF_ARM 0x40B4 + +/* Secure DMA BUF memory type value for CL_IMPORT_TYPE_ARM property */ +#define CL_IMPORT_TYPE_SECURE_ARM 0x40B5 + +/* This extension adds a new function that allows for direct memory import into + * OpenCL via the clImportMemoryARM function. + * + * Memory imported through this interface will be mapped into the device's page + * tables directly, providing zero copy access. It will never fall back to copy + * operations and aliased buffers. + * + * Types of memory supported for import are specified as additional extension + * strings. + * + * This extension produces cl_mem allocations which are compatible with all other + * users of cl_mem in the standard API. + * + * This extension maps pages with the same properties as the normal buffer creation + * function clCreateBuffer. + */ +extern CL_API_ENTRY cl_mem CL_API_CALL +clImportMemoryARM( cl_context context, + cl_mem_flags flags, + const cl_import_properties_arm *properties, + void *memory, + size_t size, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_0; + + +#endif /* CL_VERSION_1_0 */ + +/****************************************** + * cl_arm_shared_virtual_memory extension * + ******************************************/ + +#ifdef CL_VERSION_1_2 + +/* Used by clGetDeviceInfo */ +#define CL_DEVICE_SVM_CAPABILITIES_ARM 0x40B6 + +/* Used by clGetMemObjectInfo */ +#define CL_MEM_USES_SVM_POINTER_ARM 0x40B7 + +/* Used by clSetKernelExecInfoARM: */ +#define CL_KERNEL_EXEC_INFO_SVM_PTRS_ARM 0x40B8 +#define CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM_ARM 0x40B9 + +/* To be used by clGetEventInfo: */ +#define CL_COMMAND_SVM_FREE_ARM 0x40BA +#define CL_COMMAND_SVM_MEMCPY_ARM 0x40BB +#define CL_COMMAND_SVM_MEMFILL_ARM 0x40BC +#define CL_COMMAND_SVM_MAP_ARM 0x40BD +#define CL_COMMAND_SVM_UNMAP_ARM 0x40BE + +/* Flag values returned by clGetDeviceInfo with CL_DEVICE_SVM_CAPABILITIES_ARM as the param_name. */ +#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER_ARM (1 << 0) +#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER_ARM (1 << 1) +#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM_ARM (1 << 2) +#define CL_DEVICE_SVM_ATOMICS_ARM (1 << 3) + +/* Flag values used by clSVMAllocARM: */ +#define CL_MEM_SVM_FINE_GRAIN_BUFFER_ARM (1 << 10) +#define CL_MEM_SVM_ATOMICS_ARM (1 << 11) + +typedef cl_bitfield cl_svm_mem_flags_arm; +typedef cl_uint cl_kernel_exec_info_arm; +typedef cl_bitfield cl_device_svm_capabilities_arm; + +extern CL_API_ENTRY void * CL_API_CALL +clSVMAllocARM(cl_context /* context */, + cl_svm_mem_flags_arm /* flags */, + size_t /* size */, + cl_uint /* alignment */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY void CL_API_CALL +clSVMFreeARM(cl_context /* context */, + void * /* svm_pointer */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMFreeARM(cl_command_queue /* command_queue */, + cl_uint /* num_svm_pointers */, + void *[] /* svm_pointers[] */, + void (CL_CALLBACK * /*pfn_free_func*/)(cl_command_queue /* queue */, + cl_uint /* num_svm_pointers */, + void *[] /* svm_pointers[] */, + void * /* user_data */), + void * /* user_data */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemcpyARM(cl_command_queue /* command_queue */, + cl_bool /* blocking_copy */, + void * /* dst_ptr */, + const void * /* src_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemFillARM(cl_command_queue /* command_queue */, + void * /* svm_ptr */, + const void * /* pattern */, + size_t /* pattern_size */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMapARM(cl_command_queue /* command_queue */, + cl_bool /* blocking_map */, + cl_map_flags /* flags */, + void * /* svm_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMUnmapARM(cl_command_queue /* command_queue */, + void * /* svm_ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArgSVMPointerARM(cl_kernel /* kernel */, + cl_uint /* arg_index */, + const void * /* arg_value */) CL_EXT_SUFFIX__VERSION_1_2; +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelExecInfoARM(cl_kernel /* kernel */, + cl_kernel_exec_info_arm /* param_name */, + size_t /* param_value_size */, + const void * /* param_value */) CL_EXT_SUFFIX__VERSION_1_2; + +#endif /* CL_VERSION_1_2 */ + +#ifdef __cplusplus +} +#endif + + +#endif /* __CL_EXT_H */ diff --git a/opencl/khronos/headers/opencl2.1/CL/cl_gl.h b/opencl/khronos/headers/opencl2.1/CL/cl_gl.h new file mode 100644 index 0000000000..945daa83d7 --- /dev/null +++ b/opencl/khronos/headers/opencl2.1/CL/cl_gl.h @@ -0,0 +1,167 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +#ifndef __OPENCL_CL_GL_H +#define __OPENCL_CL_GL_H + +#ifdef __APPLE__ +#include +#else +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef cl_uint cl_gl_object_type; +typedef cl_uint cl_gl_texture_info; +typedef cl_uint cl_gl_platform_info; +typedef struct __GLsync *cl_GLsync; + +/* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken */ +#define CL_GL_OBJECT_BUFFER 0x2000 +#define CL_GL_OBJECT_TEXTURE2D 0x2001 +#define CL_GL_OBJECT_TEXTURE3D 0x2002 +#define CL_GL_OBJECT_RENDERBUFFER 0x2003 +#define CL_GL_OBJECT_TEXTURE2D_ARRAY 0x200E +#define CL_GL_OBJECT_TEXTURE1D 0x200F +#define CL_GL_OBJECT_TEXTURE1D_ARRAY 0x2010 +#define CL_GL_OBJECT_TEXTURE_BUFFER 0x2011 + +/* cl_gl_texture_info */ +#define CL_GL_TEXTURE_TARGET 0x2004 +#define CL_GL_MIPMAP_LEVEL 0x2005 +#define CL_GL_NUM_SAMPLES 0x2012 + + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLBuffer(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLuint /* bufobj */, + int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLTexture(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLenum /* target */, + cl_GLint /* miplevel */, + cl_GLuint /* texture */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLRenderbuffer(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLuint /* renderbuffer */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetGLObjectInfo(cl_mem /* memobj */, + cl_gl_object_type * /* gl_object_type */, + cl_GLuint * /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetGLTextureInfo(cl_mem /* memobj */, + cl_gl_texture_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireGLObjects(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseGLObjects(cl_command_queue /* command_queue */, + cl_uint /* num_objects */, + const cl_mem * /* mem_objects */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; + + +/* Deprecated OpenCL 1.1 APIs */ +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateFromGLTexture2D(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLenum /* target */, + cl_GLint /* miplevel */, + cl_GLuint /* texture */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateFromGLTexture3D(cl_context /* context */, + cl_mem_flags /* flags */, + cl_GLenum /* target */, + cl_GLint /* miplevel */, + cl_GLuint /* texture */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +/* cl_khr_gl_sharing extension */ + +#define cl_khr_gl_sharing 1 + +typedef cl_uint cl_gl_context_info; + +/* Additional Error Codes */ +#define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000 + +/* cl_gl_context_info */ +#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 +#define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007 + +/* Additional cl_context_properties */ +#define CL_GL_CONTEXT_KHR 0x2008 +#define CL_EGL_DISPLAY_KHR 0x2009 +#define CL_GLX_DISPLAY_KHR 0x200A +#define CL_WGL_HDC_KHR 0x200B +#define CL_CGL_SHAREGROUP_KHR 0x200C + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetGLContextInfoKHR(const cl_context_properties * /* properties */, + cl_gl_context_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( + const cl_context_properties * properties, + cl_gl_context_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret); + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_GL_H */ diff --git a/opencl/khronos/headers/opencl2.1/CL/cl_gl_ext.h b/opencl/khronos/headers/opencl2.1/CL/cl_gl_ext.h new file mode 100644 index 0000000000..e3c14c6408 --- /dev/null +++ b/opencl/khronos/headers/opencl2.1/CL/cl_gl_ext.h @@ -0,0 +1,74 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +/* cl_gl_ext.h contains vendor (non-KHR) OpenCL extensions which have */ +/* OpenGL dependencies. */ + +#ifndef __OPENCL_CL_GL_EXT_H +#define __OPENCL_CL_GL_EXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __APPLE__ + #include +#else + #include +#endif + +/* + * For each extension, follow this template + * cl_VEN_extname extension */ +/* #define cl_VEN_extname 1 + * ... define new types, if any + * ... define new tokens, if any + * ... define new APIs, if any + * + * If you need GLtypes here, mirror them with a cl_GLtype, rather than including a GL header + * This allows us to avoid having to decide whether to include GL headers or GLES here. + */ + +/* + * cl_khr_gl_event extension + * See section 9.9 in the OpenCL 1.1 spec for more information + */ +#define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D + +extern CL_API_ENTRY cl_event CL_API_CALL +clCreateEventFromGLsyncKHR(cl_context /* context */, + cl_GLsync /* cl_GLsync */, + cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_GL_EXT_H */ diff --git a/opencl/khronos/headers/opencl2.1/CL/cl_platform.h b/opencl/khronos/headers/opencl2.1/CL/cl_platform.h new file mode 100644 index 0000000000..dc17e52d85 --- /dev/null +++ b/opencl/khronos/headers/opencl2.1/CL/cl_platform.h @@ -0,0 +1,1437 @@ +/********************************************************************************** + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + **********************************************************************************/ + +/* $Revision: 11803 $ on $Date: 2010-06-25 10:02:12 -0700 (Fri, 25 Jun 2010) $ */ + +#ifndef __CL_PLATFORM_H +#define __CL_PLATFORM_H + +#ifdef __APPLE__ + /* Contains #defines for AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER below */ + #include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_WIN32) + #define CL_API_ENTRY + #define CL_API_CALL __stdcall + #define CL_CALLBACK __stdcall +#else + #define CL_API_ENTRY + #define CL_API_CALL + #define CL_CALLBACK +#endif + +/* + * Deprecation flags refer to the last version of the header in which the + * feature was not deprecated. + * + * E.g. VERSION_1_1_DEPRECATED means the feature is present in 1.1 without + * deprecation but is deprecated in versions later than 1.1. + */ + +#ifdef __APPLE__ + #define CL_EXTENSION_WEAK_LINK __attribute__((weak_import)) + #define CL_API_SUFFIX__VERSION_1_0 AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_0 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER + #define CL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define GCL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_1 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_7 + + #ifdef AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_8 + #else + #warning This path should never happen outside of internal operating system development. AvailabilityMacros do not function correctly here! + #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER + #endif +#else + #define CL_EXTENSION_WEAK_LINK + #define CL_API_SUFFIX__VERSION_1_0 + #define CL_EXT_SUFFIX__VERSION_1_0 + #define CL_API_SUFFIX__VERSION_1_1 + #define CL_EXT_SUFFIX__VERSION_1_1 + #define CL_API_SUFFIX__VERSION_1_2 + #define CL_EXT_SUFFIX__VERSION_1_2 + #define CL_API_SUFFIX__VERSION_2_0 + #define CL_EXT_SUFFIX__VERSION_2_0 + #define CL_API_SUFFIX__VERSION_2_1 + #define CL_EXT_SUFFIX__VERSION_2_1 + + #ifdef __GNUC__ + #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED __attribute__((deprecated)) + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED + #endif + + #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED __attribute__((deprecated)) + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + #endif + + #ifdef CL_USE_DEPRECATED_OPENCL_1_2_APIS + #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED __attribute__((deprecated)) + #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED + #endif + + #ifdef CL_USE_DEPRECATED_OPENCL_2_0_APIS + #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED __attribute__((deprecated)) + #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED + #endif + #elif defined(_WIN32) + #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED __declspec(deprecated) + #endif + + #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED __declspec(deprecated) + #endif + + #ifdef CL_USE_DEPRECATED_OPENCL_1_2_APIS + #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED __declspec(deprecated) + #endif + + #ifdef CL_USE_DEPRECATED_OPENCL_2_0_APIS + #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED + #else + #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED __declspec(deprecated) + #endif + #else + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED + + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + + #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED + + #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED + #endif +#endif + +#if (defined (_WIN32) && defined(_MSC_VER)) + +/* scalar types */ +typedef signed __int8 cl_char; +typedef unsigned __int8 cl_uchar; +typedef signed __int16 cl_short; +typedef unsigned __int16 cl_ushort; +typedef signed __int32 cl_int; +typedef unsigned __int32 cl_uint; +typedef signed __int64 cl_long; +typedef unsigned __int64 cl_ulong; + +typedef unsigned __int16 cl_half; +typedef float cl_float; +typedef double cl_double; + +/* Macro names and corresponding values defined by OpenCL */ +#define CL_CHAR_BIT 8 +#define CL_SCHAR_MAX 127 +#define CL_SCHAR_MIN (-127-1) +#define CL_CHAR_MAX CL_SCHAR_MAX +#define CL_CHAR_MIN CL_SCHAR_MIN +#define CL_UCHAR_MAX 255 +#define CL_SHRT_MAX 32767 +#define CL_SHRT_MIN (-32767-1) +#define CL_USHRT_MAX 65535 +#define CL_INT_MAX 2147483647 +#define CL_INT_MIN (-2147483647-1) +#define CL_UINT_MAX 0xffffffffU +#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) +#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) +#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) + +#define CL_FLT_DIG 6 +#define CL_FLT_MANT_DIG 24 +#define CL_FLT_MAX_10_EXP +38 +#define CL_FLT_MAX_EXP +128 +#define CL_FLT_MIN_10_EXP -37 +#define CL_FLT_MIN_EXP -125 +#define CL_FLT_RADIX 2 +#define CL_FLT_MAX 340282346638528859811704183484516925440.0f +#define CL_FLT_MIN 1.175494350822287507969e-38f +#define CL_FLT_EPSILON 1.1920928955078125e-7f + +#define CL_HALF_DIG 3 +#define CL_HALF_MANT_DIG 11 +#define CL_HALF_MAX_10_EXP +4 +#define CL_HALF_MAX_EXP +16 +#define CL_HALF_MIN_10_EXP -4 +#define CL_HALF_MIN_EXP -13 +#define CL_HALF_RADIX 2 +#define CL_HALF_MAX 65504.0f +#define CL_HALF_MIN 6.103515625e-05f +#define CL_HALF_EPSILON 9.765625e-04f + +#define CL_DBL_DIG 15 +#define CL_DBL_MANT_DIG 53 +#define CL_DBL_MAX_10_EXP +308 +#define CL_DBL_MAX_EXP +1024 +#define CL_DBL_MIN_10_EXP -307 +#define CL_DBL_MIN_EXP -1021 +#define CL_DBL_RADIX 2 +#define CL_DBL_MAX 1.7976931348623158e+308 +#define CL_DBL_MIN 2.225073858507201383090e-308 +#define CL_DBL_EPSILON 2.220446049250313080847e-16 + +#define CL_M_E 2.7182818284590452354 +#define CL_M_LOG2E 1.4426950408889634074 +#define CL_M_LOG10E 0.43429448190325182765 +#define CL_M_LN2 0.69314718055994530942 +#define CL_M_LN10 2.30258509299404568402 +#define CL_M_PI 3.14159265358979323846 +#define CL_M_PI_2 1.57079632679489661923 +#define CL_M_PI_4 0.78539816339744830962 +#define CL_M_1_PI 0.31830988618379067154 +#define CL_M_2_PI 0.63661977236758134308 +#define CL_M_2_SQRTPI 1.12837916709551257390 +#define CL_M_SQRT2 1.41421356237309504880 +#define CL_M_SQRT1_2 0.70710678118654752440 + +#define CL_M_E_F 2.718281828f +#define CL_M_LOG2E_F 1.442695041f +#define CL_M_LOG10E_F 0.434294482f +#define CL_M_LN2_F 0.693147181f +#define CL_M_LN10_F 2.302585093f +#define CL_M_PI_F 3.141592654f +#define CL_M_PI_2_F 1.570796327f +#define CL_M_PI_4_F 0.785398163f +#define CL_M_1_PI_F 0.318309886f +#define CL_M_2_PI_F 0.636619772f +#define CL_M_2_SQRTPI_F 1.128379167f +#define CL_M_SQRT2_F 1.414213562f +#define CL_M_SQRT1_2_F 0.707106781f + +#define CL_NAN (CL_INFINITY - CL_INFINITY) +#define CL_HUGE_VALF ((cl_float) 1e50) +#define CL_HUGE_VAL ((cl_double) 1e500) +#define CL_MAXFLOAT CL_FLT_MAX +#define CL_INFINITY CL_HUGE_VALF + +#else + +#include + +/* scalar types */ +typedef int8_t cl_char; +typedef uint8_t cl_uchar; +typedef int16_t cl_short __attribute__((aligned(2))); +typedef uint16_t cl_ushort __attribute__((aligned(2))); +typedef int32_t cl_int __attribute__((aligned(4))); +typedef uint32_t cl_uint __attribute__((aligned(4))); +typedef int64_t cl_long __attribute__((aligned(8))); +typedef uint64_t cl_ulong __attribute__((aligned(8))); + +typedef uint16_t cl_half __attribute__((aligned(2))); +typedef float cl_float __attribute__((aligned(4))); +typedef double cl_double __attribute__((aligned(8))); + +/* Macro names and corresponding values defined by OpenCL */ +#define CL_CHAR_BIT 8 +#define CL_SCHAR_MAX 127 +#define CL_SCHAR_MIN (-127-1) +#define CL_CHAR_MAX CL_SCHAR_MAX +#define CL_CHAR_MIN CL_SCHAR_MIN +#define CL_UCHAR_MAX 255 +#define CL_SHRT_MAX 32767 +#define CL_SHRT_MIN (-32767-1) +#define CL_USHRT_MAX 65535 +#define CL_INT_MAX 2147483647 +#define CL_INT_MIN (-2147483647-1) +#define CL_UINT_MAX 0xffffffffU +#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) +#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) +#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) + +#define CL_FLT_DIG 6 +#define CL_FLT_MANT_DIG 24 +#define CL_FLT_MAX_10_EXP +38 +#define CL_FLT_MAX_EXP +128 +#define CL_FLT_MIN_10_EXP -37 +#define CL_FLT_MIN_EXP -125 +#define CL_FLT_RADIX 2 +#define CL_FLT_MAX 340282346638528859811704183484516925440.0f +#define CL_FLT_MIN 1.175494350822287507969e-38f +#define CL_FLT_EPSILON 1.1920928955078125e-7f + +#define CL_HALF_DIG 3 +#define CL_HALF_MANT_DIG 11 +#define CL_HALF_MAX_10_EXP +4 +#define CL_HALF_MAX_EXP +16 +#define CL_HALF_MIN_10_EXP -4 +#define CL_HALF_MIN_EXP -13 +#define CL_HALF_RADIX 2 +#define CL_HALF_MAX 65504.0f +#define CL_HALF_MIN 6.103515625e-05f +#define CL_HALF_EPSILON 9.765625e-04f + +#define CL_DBL_DIG 15 +#define CL_DBL_MANT_DIG 53 +#define CL_DBL_MAX_10_EXP +308 +#define CL_DBL_MAX_EXP +1024 +#define CL_DBL_MIN_10_EXP -307 +#define CL_DBL_MIN_EXP -1021 +#define CL_DBL_RADIX 2 +#define CL_DBL_MAX 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0 +#define CL_DBL_MIN 2.225073858507201383090e-308 +#define CL_DBL_EPSILON 2.220446049250313080847e-16 + +#define CL_M_E 2.7182818284590452354 +#define CL_M_LOG2E 1.4426950408889634074 +#define CL_M_LOG10E 0.43429448190325182765 +#define CL_M_LN2 0.69314718055994530942 +#define CL_M_LN10 2.30258509299404568402 +#define CL_M_PI 3.14159265358979323846 +#define CL_M_PI_2 1.57079632679489661923 +#define CL_M_PI_4 0.78539816339744830962 +#define CL_M_1_PI 0.31830988618379067154 +#define CL_M_2_PI 0.63661977236758134308 +#define CL_M_2_SQRTPI 1.12837916709551257390 +#define CL_M_SQRT2 1.41421356237309504880 +#define CL_M_SQRT1_2 0.70710678118654752440 + +#define CL_M_E_F 2.718281828f +#define CL_M_LOG2E_F 1.442695041f +#define CL_M_LOG10E_F 0.434294482f +#define CL_M_LN2_F 0.693147181f +#define CL_M_LN10_F 2.302585093f +#define CL_M_PI_F 3.141592654f +#define CL_M_PI_2_F 1.570796327f +#define CL_M_PI_4_F 0.785398163f +#define CL_M_1_PI_F 0.318309886f +#define CL_M_2_PI_F 0.636619772f +#define CL_M_2_SQRTPI_F 1.128379167f +#define CL_M_SQRT2_F 1.414213562f +#define CL_M_SQRT1_2_F 0.707106781f + +#if defined( __GNUC__ ) + #define CL_HUGE_VALF __builtin_huge_valf() + #define CL_HUGE_VAL __builtin_huge_val() + #define CL_NAN __builtin_nanf( "" ) +#else + #define CL_HUGE_VALF ((cl_float) 1e50) + #define CL_HUGE_VAL ((cl_double) 1e500) + float nanf( const char * ); + #define CL_NAN nanf( "" ) +#endif +#define CL_MAXFLOAT CL_FLT_MAX +#define CL_INFINITY CL_HUGE_VALF + +#endif + +#include + +/* Mirror types to GL types. Mirror types allow us to avoid deciding which 87s to load based on whether we are using GL or GLES here. */ +typedef unsigned int cl_GLuint; +typedef int cl_GLint; +typedef unsigned int cl_GLenum; + +/* + * Vector types + * + * Note: OpenCL requires that all types be naturally aligned. + * This means that vector types must be naturally aligned. + * For example, a vector of four floats must be aligned to + * a 16 byte boundary (calculated as 4 * the natural 4-byte + * alignment of the float). The alignment qualifiers here + * will only function properly if your compiler supports them + * and if you don't actively work to defeat them. For example, + * in order for a cl_float4 to be 16 byte aligned in a struct, + * the start of the struct must itself be 16-byte aligned. + * + * Maintaining proper alignment is the user's responsibility. + */ + +/* Define basic vector types */ +#if defined( __VEC__ ) + #include /* may be omitted depending on compiler. AltiVec spec provides no way to detect whether the header is required. */ + typedef vector unsigned char __cl_uchar16; + typedef vector signed char __cl_char16; + typedef vector unsigned short __cl_ushort8; + typedef vector signed short __cl_short8; + typedef vector unsigned int __cl_uint4; + typedef vector signed int __cl_int4; + typedef vector float __cl_float4; + #define __CL_UCHAR16__ 1 + #define __CL_CHAR16__ 1 + #define __CL_USHORT8__ 1 + #define __CL_SHORT8__ 1 + #define __CL_UINT4__ 1 + #define __CL_INT4__ 1 + #define __CL_FLOAT4__ 1 +#endif + +#if defined( __SSE__ ) + #if defined( __MINGW64__ ) + #include + #else + #include + #endif + #if defined( __GNUC__ ) + typedef float __cl_float4 __attribute__((vector_size(16))); + #else + typedef __m128 __cl_float4; + #endif + #define __CL_FLOAT4__ 1 +#endif + +#if defined( __SSE2__ ) + #if defined( __MINGW64__ ) + #include + #else + #include + #endif + #if defined( __GNUC__ ) + typedef cl_uchar __cl_uchar16 __attribute__((vector_size(16))); + typedef cl_char __cl_char16 __attribute__((vector_size(16))); + typedef cl_ushort __cl_ushort8 __attribute__((vector_size(16))); + typedef cl_short __cl_short8 __attribute__((vector_size(16))); + typedef cl_uint __cl_uint4 __attribute__((vector_size(16))); + typedef cl_int __cl_int4 __attribute__((vector_size(16))); + typedef cl_ulong __cl_ulong2 __attribute__((vector_size(16))); + typedef cl_long __cl_long2 __attribute__((vector_size(16))); + typedef cl_double __cl_double2 __attribute__((vector_size(16))); + #else + typedef __m128i __cl_uchar16; + typedef __m128i __cl_char16; + typedef __m128i __cl_ushort8; + typedef __m128i __cl_short8; + typedef __m128i __cl_uint4; + typedef __m128i __cl_int4; + typedef __m128i __cl_ulong2; + typedef __m128i __cl_long2; + typedef __m128d __cl_double2; + #endif + #define __CL_UCHAR16__ 1 + #define __CL_CHAR16__ 1 + #define __CL_USHORT8__ 1 + #define __CL_SHORT8__ 1 + #define __CL_INT4__ 1 + #define __CL_UINT4__ 1 + #define __CL_ULONG2__ 1 + #define __CL_LONG2__ 1 + #define __CL_DOUBLE2__ 1 +#endif + +#if defined( __MMX__ ) + #include + #if defined( __GNUC__ ) + typedef cl_uchar __cl_uchar8 __attribute__((vector_size(8))); + typedef cl_char __cl_char8 __attribute__((vector_size(8))); + typedef cl_ushort __cl_ushort4 __attribute__((vector_size(8))); + typedef cl_short __cl_short4 __attribute__((vector_size(8))); + typedef cl_uint __cl_uint2 __attribute__((vector_size(8))); + typedef cl_int __cl_int2 __attribute__((vector_size(8))); + typedef cl_ulong __cl_ulong1 __attribute__((vector_size(8))); + typedef cl_long __cl_long1 __attribute__((vector_size(8))); + typedef cl_float __cl_float2 __attribute__((vector_size(8))); + #else + typedef __m64 __cl_uchar8; + typedef __m64 __cl_char8; + typedef __m64 __cl_ushort4; + typedef __m64 __cl_short4; + typedef __m64 __cl_uint2; + typedef __m64 __cl_int2; + typedef __m64 __cl_ulong1; + typedef __m64 __cl_long1; + typedef __m64 __cl_float2; + #endif + #define __CL_UCHAR8__ 1 + #define __CL_CHAR8__ 1 + #define __CL_USHORT4__ 1 + #define __CL_SHORT4__ 1 + #define __CL_INT2__ 1 + #define __CL_UINT2__ 1 + #define __CL_ULONG1__ 1 + #define __CL_LONG1__ 1 + #define __CL_FLOAT2__ 1 +#endif + +#if defined( __AVX__ ) + #if defined( __MINGW64__ ) + #include + #else + #include + #endif + #if defined( __GNUC__ ) + typedef cl_float __cl_float8 __attribute__((vector_size(32))); + typedef cl_double __cl_double4 __attribute__((vector_size(32))); + #else + typedef __m256 __cl_float8; + typedef __m256d __cl_double4; + #endif + #define __CL_FLOAT8__ 1 + #define __CL_DOUBLE4__ 1 +#endif + +/* Define capabilities for anonymous struct members. */ +#if !defined(__cplusplus) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#define __CL_HAS_ANON_STRUCT__ 1 +#define __CL_ANON_STRUCT__ +#elif defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) +#define __CL_HAS_ANON_STRUCT__ 1 +#define __CL_ANON_STRUCT__ __extension__ +#elif defined( _WIN32) && defined(_MSC_VER) + #if _MSC_VER >= 1500 + /* Microsoft Developer Studio 2008 supports anonymous structs, but + * complains by default. */ + #define __CL_HAS_ANON_STRUCT__ 1 + #define __CL_ANON_STRUCT__ + /* Disable warning C4201: nonstandard extension used : nameless + * struct/union */ + #pragma warning( push ) + #pragma warning( disable : 4201 ) + #endif +#else +#define __CL_HAS_ANON_STRUCT__ 0 +#define __CL_ANON_STRUCT__ +#endif + +/* Define alignment keys */ +#if defined( __GNUC__ ) + #define CL_ALIGNED(_x) __attribute__ ((aligned(_x))) +#elif defined( _WIN32) && (_MSC_VER) + /* Alignment keys neutered on windows because MSVC can't swallow function arguments with alignment requirements */ + /* http://msdn.microsoft.com/en-us/library/373ak2y1%28VS.71%29.aspx */ + /* #include */ + /* #define CL_ALIGNED(_x) _CRT_ALIGN(_x) */ + #define CL_ALIGNED(_x) +#else + #warning Need to implement some method to align data here + #define CL_ALIGNED(_x) +#endif + +/* Indicate whether .xyzw, .s0123 and .hi.lo are supported */ +#if __CL_HAS_ANON_STRUCT__ + /* .xyzw and .s0123...{f|F} are supported */ + #define CL_HAS_NAMED_VECTOR_FIELDS 1 + /* .hi and .lo are supported */ + #define CL_HAS_HI_LO_VECTOR_FIELDS 1 +#endif + +/* Define cl_vector types */ + +/* ---- cl_charn ---- */ +typedef union +{ + cl_char CL_ALIGNED(2) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_char lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2; +#endif +}cl_char2; + +typedef union +{ + cl_char CL_ALIGNED(4) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_char2 lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2[2]; +#endif +#if defined( __CL_CHAR4__) + __cl_char4 v4; +#endif +}cl_char4; + +/* cl_char3 is identical in size, alignment and behavior to cl_char4. See section 6.1.5. */ +typedef cl_char4 cl_char3; + +typedef union +{ + cl_char CL_ALIGNED(8) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_char4 lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2[4]; +#endif +#if defined( __CL_CHAR4__) + __cl_char4 v4[2]; +#endif +#if defined( __CL_CHAR8__ ) + __cl_char8 v8; +#endif +}cl_char8; + +typedef union +{ + cl_char CL_ALIGNED(16) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_char8 lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2[8]; +#endif +#if defined( __CL_CHAR4__) + __cl_char4 v4[4]; +#endif +#if defined( __CL_CHAR8__ ) + __cl_char8 v8[2]; +#endif +#if defined( __CL_CHAR16__ ) + __cl_char16 v16; +#endif +}cl_char16; + + +/* ---- cl_ucharn ---- */ +typedef union +{ + cl_uchar CL_ALIGNED(2) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_uchar lo, hi; }; +#endif +#if defined( __cl_uchar2__) + __cl_uchar2 v2; +#endif +}cl_uchar2; + +typedef union +{ + cl_uchar CL_ALIGNED(4) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_uchar2 lo, hi; }; +#endif +#if defined( __CL_UCHAR2__) + __cl_uchar2 v2[2]; +#endif +#if defined( __CL_UCHAR4__) + __cl_uchar4 v4; +#endif +}cl_uchar4; + +/* cl_uchar3 is identical in size, alignment and behavior to cl_uchar4. See section 6.1.5. */ +typedef cl_uchar4 cl_uchar3; + +typedef union +{ + cl_uchar CL_ALIGNED(8) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_uchar4 lo, hi; }; +#endif +#if defined( __CL_UCHAR2__) + __cl_uchar2 v2[4]; +#endif +#if defined( __CL_UCHAR4__) + __cl_uchar4 v4[2]; +#endif +#if defined( __CL_UCHAR8__ ) + __cl_uchar8 v8; +#endif +}cl_uchar8; + +typedef union +{ + cl_uchar CL_ALIGNED(16) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_uchar8 lo, hi; }; +#endif +#if defined( __CL_UCHAR2__) + __cl_uchar2 v2[8]; +#endif +#if defined( __CL_UCHAR4__) + __cl_uchar4 v4[4]; +#endif +#if defined( __CL_UCHAR8__ ) + __cl_uchar8 v8[2]; +#endif +#if defined( __CL_UCHAR16__ ) + __cl_uchar16 v16; +#endif +}cl_uchar16; + + +/* ---- cl_shortn ---- */ +typedef union +{ + cl_short CL_ALIGNED(4) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_short lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2; +#endif +}cl_short2; + +typedef union +{ + cl_short CL_ALIGNED(8) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_short2 lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2[2]; +#endif +#if defined( __CL_SHORT4__) + __cl_short4 v4; +#endif +}cl_short4; + +/* cl_short3 is identical in size, alignment and behavior to cl_short4. See section 6.1.5. */ +typedef cl_short4 cl_short3; + +typedef union +{ + cl_short CL_ALIGNED(16) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_short4 lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2[4]; +#endif +#if defined( __CL_SHORT4__) + __cl_short4 v4[2]; +#endif +#if defined( __CL_SHORT8__ ) + __cl_short8 v8; +#endif +}cl_short8; + +typedef union +{ + cl_short CL_ALIGNED(32) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_short8 lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2[8]; +#endif +#if defined( __CL_SHORT4__) + __cl_short4 v4[4]; +#endif +#if defined( __CL_SHORT8__ ) + __cl_short8 v8[2]; +#endif +#if defined( __CL_SHORT16__ ) + __cl_short16 v16; +#endif +}cl_short16; + + +/* ---- cl_ushortn ---- */ +typedef union +{ + cl_ushort CL_ALIGNED(4) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_ushort lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2; +#endif +}cl_ushort2; + +typedef union +{ + cl_ushort CL_ALIGNED(8) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_ushort2 lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2[2]; +#endif +#if defined( __CL_USHORT4__) + __cl_ushort4 v4; +#endif +}cl_ushort4; + +/* cl_ushort3 is identical in size, alignment and behavior to cl_ushort4. See section 6.1.5. */ +typedef cl_ushort4 cl_ushort3; + +typedef union +{ + cl_ushort CL_ALIGNED(16) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_ushort4 lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2[4]; +#endif +#if defined( __CL_USHORT4__) + __cl_ushort4 v4[2]; +#endif +#if defined( __CL_USHORT8__ ) + __cl_ushort8 v8; +#endif +}cl_ushort8; + +typedef union +{ + cl_ushort CL_ALIGNED(32) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_ushort8 lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2[8]; +#endif +#if defined( __CL_USHORT4__) + __cl_ushort4 v4[4]; +#endif +#if defined( __CL_USHORT8__ ) + __cl_ushort8 v8[2]; +#endif +#if defined( __CL_USHORT16__ ) + __cl_ushort16 v16; +#endif +}cl_ushort16; + + +/* ---- cl_halfn ---- */ +typedef union +{ + cl_half CL_ALIGNED(4) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_half lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2; +#endif +}cl_half2; + +typedef union +{ + cl_half CL_ALIGNED(8) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_half2 lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2[2]; +#endif +#if defined( __CL_HALF4__) + __cl_half4 v4; +#endif +}cl_half4; + +/* cl_half3 is identical in size, alignment and behavior to cl_half4. See section 6.1.5. */ +typedef cl_half4 cl_half3; + +typedef union +{ + cl_half CL_ALIGNED(16) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_half4 lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2[4]; +#endif +#if defined( __CL_HALF4__) + __cl_half4 v4[2]; +#endif +#if defined( __CL_HALF8__ ) + __cl_half8 v8; +#endif +}cl_half8; + +typedef union +{ + cl_half CL_ALIGNED(32) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_half8 lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2[8]; +#endif +#if defined( __CL_HALF4__) + __cl_half4 v4[4]; +#endif +#if defined( __CL_HALF8__ ) + __cl_half8 v8[2]; +#endif +#if defined( __CL_HALF16__ ) + __cl_half16 v16; +#endif +}cl_half16; + +/* ---- cl_intn ---- */ +typedef union +{ + cl_int CL_ALIGNED(8) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_int lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2; +#endif +}cl_int2; + +typedef union +{ + cl_int CL_ALIGNED(16) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_int2 lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2[2]; +#endif +#if defined( __CL_INT4__) + __cl_int4 v4; +#endif +}cl_int4; + +/* cl_int3 is identical in size, alignment and behavior to cl_int4. See section 6.1.5. */ +typedef cl_int4 cl_int3; + +typedef union +{ + cl_int CL_ALIGNED(32) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_int4 lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2[4]; +#endif +#if defined( __CL_INT4__) + __cl_int4 v4[2]; +#endif +#if defined( __CL_INT8__ ) + __cl_int8 v8; +#endif +}cl_int8; + +typedef union +{ + cl_int CL_ALIGNED(64) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_int8 lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2[8]; +#endif +#if defined( __CL_INT4__) + __cl_int4 v4[4]; +#endif +#if defined( __CL_INT8__ ) + __cl_int8 v8[2]; +#endif +#if defined( __CL_INT16__ ) + __cl_int16 v16; +#endif +}cl_int16; + + +/* ---- cl_uintn ---- */ +typedef union +{ + cl_uint CL_ALIGNED(8) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_uint lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2; +#endif +}cl_uint2; + +typedef union +{ + cl_uint CL_ALIGNED(16) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_uint2 lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2[2]; +#endif +#if defined( __CL_UINT4__) + __cl_uint4 v4; +#endif +}cl_uint4; + +/* cl_uint3 is identical in size, alignment and behavior to cl_uint4. See section 6.1.5. */ +typedef cl_uint4 cl_uint3; + +typedef union +{ + cl_uint CL_ALIGNED(32) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_uint4 lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2[4]; +#endif +#if defined( __CL_UINT4__) + __cl_uint4 v4[2]; +#endif +#if defined( __CL_UINT8__ ) + __cl_uint8 v8; +#endif +}cl_uint8; + +typedef union +{ + cl_uint CL_ALIGNED(64) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_uint8 lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2[8]; +#endif +#if defined( __CL_UINT4__) + __cl_uint4 v4[4]; +#endif +#if defined( __CL_UINT8__ ) + __cl_uint8 v8[2]; +#endif +#if defined( __CL_UINT16__ ) + __cl_uint16 v16; +#endif +}cl_uint16; + +/* ---- cl_longn ---- */ +typedef union +{ + cl_long CL_ALIGNED(16) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_long lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2; +#endif +}cl_long2; + +typedef union +{ + cl_long CL_ALIGNED(32) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_long2 lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2[2]; +#endif +#if defined( __CL_LONG4__) + __cl_long4 v4; +#endif +}cl_long4; + +/* cl_long3 is identical in size, alignment and behavior to cl_long4. See section 6.1.5. */ +typedef cl_long4 cl_long3; + +typedef union +{ + cl_long CL_ALIGNED(64) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_long4 lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2[4]; +#endif +#if defined( __CL_LONG4__) + __cl_long4 v4[2]; +#endif +#if defined( __CL_LONG8__ ) + __cl_long8 v8; +#endif +}cl_long8; + +typedef union +{ + cl_long CL_ALIGNED(128) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_long8 lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2[8]; +#endif +#if defined( __CL_LONG4__) + __cl_long4 v4[4]; +#endif +#if defined( __CL_LONG8__ ) + __cl_long8 v8[2]; +#endif +#if defined( __CL_LONG16__ ) + __cl_long16 v16; +#endif +}cl_long16; + + +/* ---- cl_ulongn ---- */ +typedef union +{ + cl_ulong CL_ALIGNED(16) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_ulong lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2; +#endif +}cl_ulong2; + +typedef union +{ + cl_ulong CL_ALIGNED(32) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_ulong2 lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2[2]; +#endif +#if defined( __CL_ULONG4__) + __cl_ulong4 v4; +#endif +}cl_ulong4; + +/* cl_ulong3 is identical in size, alignment and behavior to cl_ulong4. See section 6.1.5. */ +typedef cl_ulong4 cl_ulong3; + +typedef union +{ + cl_ulong CL_ALIGNED(64) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_ulong4 lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2[4]; +#endif +#if defined( __CL_ULONG4__) + __cl_ulong4 v4[2]; +#endif +#if defined( __CL_ULONG8__ ) + __cl_ulong8 v8; +#endif +}cl_ulong8; + +typedef union +{ + cl_ulong CL_ALIGNED(128) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_ulong8 lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2[8]; +#endif +#if defined( __CL_ULONG4__) + __cl_ulong4 v4[4]; +#endif +#if defined( __CL_ULONG8__ ) + __cl_ulong8 v8[2]; +#endif +#if defined( __CL_ULONG16__ ) + __cl_ulong16 v16; +#endif +}cl_ulong16; + + +/* --- cl_floatn ---- */ + +typedef union +{ + cl_float CL_ALIGNED(8) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_float lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2; +#endif +}cl_float2; + +typedef union +{ + cl_float CL_ALIGNED(16) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_float2 lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2[2]; +#endif +#if defined( __CL_FLOAT4__) + __cl_float4 v4; +#endif +}cl_float4; + +/* cl_float3 is identical in size, alignment and behavior to cl_float4. See section 6.1.5. */ +typedef cl_float4 cl_float3; + +typedef union +{ + cl_float CL_ALIGNED(32) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_float4 lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2[4]; +#endif +#if defined( __CL_FLOAT4__) + __cl_float4 v4[2]; +#endif +#if defined( __CL_FLOAT8__ ) + __cl_float8 v8; +#endif +}cl_float8; + +typedef union +{ + cl_float CL_ALIGNED(64) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_float8 lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2[8]; +#endif +#if defined( __CL_FLOAT4__) + __cl_float4 v4[4]; +#endif +#if defined( __CL_FLOAT8__ ) + __cl_float8 v8[2]; +#endif +#if defined( __CL_FLOAT16__ ) + __cl_float16 v16; +#endif +}cl_float16; + +/* --- cl_doublen ---- */ + +typedef union +{ + cl_double CL_ALIGNED(16) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_double lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2; +#endif +}cl_double2; + +typedef union +{ + cl_double CL_ALIGNED(32) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_double2 lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2[2]; +#endif +#if defined( __CL_DOUBLE4__) + __cl_double4 v4; +#endif +}cl_double4; + +/* cl_double3 is identical in size, alignment and behavior to cl_double4. See section 6.1.5. */ +typedef cl_double4 cl_double3; + +typedef union +{ + cl_double CL_ALIGNED(64) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_double4 lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2[4]; +#endif +#if defined( __CL_DOUBLE4__) + __cl_double4 v4[2]; +#endif +#if defined( __CL_DOUBLE8__ ) + __cl_double8 v8; +#endif +}cl_double8; + +typedef union +{ + cl_double CL_ALIGNED(128) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_double8 lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2[8]; +#endif +#if defined( __CL_DOUBLE4__) + __cl_double4 v4[4]; +#endif +#if defined( __CL_DOUBLE8__ ) + __cl_double8 v8[2]; +#endif +#if defined( __CL_DOUBLE16__ ) + __cl_double16 v16; +#endif +}cl_double16; + +/* Macro to facilitate debugging + * Usage: + * Place CL_PROGRAM_STRING_DEBUG_INFO on the line before the first line of your source. + * The first line ends with: CL_PROGRAM_STRING_DEBUG_INFO \" + * Each line thereafter of OpenCL C source must end with: \n\ + * The last line ends in "; + * + * Example: + * + * const char *my_program = CL_PROGRAM_STRING_DEBUG_INFO "\ + * kernel void foo( int a, float * b ) \n\ + * { \n\ + * // my comment \n\ + * *b[ get_global_id(0)] = a; \n\ + * } \n\ + * "; + * + * This should correctly set up the line, (column) and file information for your source + * string so you can do source level debugging. + */ +#define __CL_STRINGIFY( _x ) # _x +#define _CL_STRINGIFY( _x ) __CL_STRINGIFY( _x ) +#define CL_PROGRAM_STRING_DEBUG_INFO "#line " _CL_STRINGIFY(__LINE__) " \"" __FILE__ "\" \n\n" + +#ifdef __cplusplus +} +#endif + +#undef __CL_HAS_ANON_STRUCT__ +#undef __CL_ANON_STRUCT__ +#if defined( _WIN32) && defined(_MSC_VER) + #if _MSC_VER >=1500 + #pragma warning( pop ) + #endif +#endif + +#endif /* __CL_PLATFORM_H */ diff --git a/opencl/khronos/headers/opencl2.1/CL/opencl.h b/opencl/khronos/headers/opencl2.1/CL/opencl.h new file mode 100644 index 0000000000..9855cd75e7 --- /dev/null +++ b/opencl/khronos/headers/opencl2.1/CL/opencl.h @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2008-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS + * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS + * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + * https://www.khronos.org/registry/ + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_H +#define __OPENCL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __APPLE__ + +#include +#include +#include +#include + +#else + +#include +#include +#include +#include + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_H */ + diff --git a/opencl/khronos/headers/opencl2.2/CL/cl.h b/opencl/khronos/headers/opencl2.2/CL/cl.h new file mode 100644 index 0000000000..59d6bdfcf2 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl.h @@ -0,0 +1,1824 @@ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#ifndef __OPENCL_CL_H +#define __OPENCL_CL_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/******************************************************************************/ + +typedef struct _cl_platform_id * cl_platform_id; +typedef struct _cl_device_id * cl_device_id; +typedef struct _cl_context * cl_context; +typedef struct _cl_command_queue * cl_command_queue; +typedef struct _cl_mem * cl_mem; +typedef struct _cl_program * cl_program; +typedef struct _cl_kernel * cl_kernel; +typedef struct _cl_event * cl_event; +typedef struct _cl_sampler * cl_sampler; + +typedef cl_uint cl_bool; /* WARNING! Unlike cl_ types in cl_platform.h, cl_bool is not guaranteed to be the same size as the bool in kernels. */ +typedef cl_ulong cl_bitfield; +typedef cl_bitfield cl_device_type; +typedef cl_uint cl_platform_info; +typedef cl_uint cl_device_info; +typedef cl_bitfield cl_device_fp_config; +typedef cl_uint cl_device_mem_cache_type; +typedef cl_uint cl_device_local_mem_type; +typedef cl_bitfield cl_device_exec_capabilities; +#ifdef CL_VERSION_2_0 +typedef cl_bitfield cl_device_svm_capabilities; +#endif +typedef cl_bitfield cl_command_queue_properties; +#ifdef CL_VERSION_1_2 +typedef intptr_t cl_device_partition_property; +typedef cl_bitfield cl_device_affinity_domain; +#endif + +typedef intptr_t cl_context_properties; +typedef cl_uint cl_context_info; +#ifdef CL_VERSION_2_0 +typedef cl_bitfield cl_queue_properties; +#endif +typedef cl_uint cl_command_queue_info; +typedef cl_uint cl_channel_order; +typedef cl_uint cl_channel_type; +typedef cl_bitfield cl_mem_flags; +#ifdef CL_VERSION_2_0 +typedef cl_bitfield cl_svm_mem_flags; +#endif +typedef cl_uint cl_mem_object_type; +typedef cl_uint cl_mem_info; +#ifdef CL_VERSION_1_2 +typedef cl_bitfield cl_mem_migration_flags; +#endif +typedef cl_uint cl_image_info; +#ifdef CL_VERSION_1_1 +typedef cl_uint cl_buffer_create_type; +#endif +typedef cl_uint cl_addressing_mode; +typedef cl_uint cl_filter_mode; +typedef cl_uint cl_sampler_info; +typedef cl_bitfield cl_map_flags; +#ifdef CL_VERSION_2_0 +typedef intptr_t cl_pipe_properties; +typedef cl_uint cl_pipe_info; +#endif +typedef cl_uint cl_program_info; +typedef cl_uint cl_program_build_info; +#ifdef CL_VERSION_1_2 +typedef cl_uint cl_program_binary_type; +#endif +typedef cl_int cl_build_status; +typedef cl_uint cl_kernel_info; +#ifdef CL_VERSION_1_2 +typedef cl_uint cl_kernel_arg_info; +typedef cl_uint cl_kernel_arg_address_qualifier; +typedef cl_uint cl_kernel_arg_access_qualifier; +typedef cl_bitfield cl_kernel_arg_type_qualifier; +#endif +typedef cl_uint cl_kernel_work_group_info; +#ifdef CL_VERSION_2_1 +typedef cl_uint cl_kernel_sub_group_info; +#endif +typedef cl_uint cl_event_info; +typedef cl_uint cl_command_type; +typedef cl_uint cl_profiling_info; +#ifdef CL_VERSION_2_0 +typedef cl_bitfield cl_sampler_properties; +typedef cl_uint cl_kernel_exec_info; +#endif +#ifdef CL_EXPERIMENTAL +typedef cl_bitfield cl_device_atomic_capabilities; +typedef cl_uint cl_khronos_vendor_id; +#endif + +typedef struct _cl_image_format { + cl_channel_order image_channel_order; + cl_channel_type image_channel_data_type; +} cl_image_format; + +#ifdef CL_VERSION_1_2 + +typedef struct _cl_image_desc { + cl_mem_object_type image_type; + size_t image_width; + size_t image_height; + size_t image_depth; + size_t image_array_size; + size_t image_row_pitch; + size_t image_slice_pitch; + cl_uint num_mip_levels; + cl_uint num_samples; +#ifdef CL_VERSION_2_0 +#ifdef __GNUC__ + __extension__ /* Prevents warnings about anonymous union in -pedantic builds */ +#endif +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable : 4201 ) /* Prevents warning about nameless struct/union in /W4 /Za builds */ +#endif + union { +#endif + cl_mem buffer; +#ifdef CL_VERSION_2_0 + cl_mem mem_object; + }; +#ifdef _MSC_VER +#pragma warning( pop ) +#endif +#endif +} cl_image_desc; + +#endif + +#ifdef CL_VERSION_1_1 + +typedef struct _cl_buffer_region { + size_t origin; + size_t size; +} cl_buffer_region; + +#endif + +/******************************************************************************/ + +/* Error Codes */ +#define CL_SUCCESS 0 +#define CL_DEVICE_NOT_FOUND -1 +#define CL_DEVICE_NOT_AVAILABLE -2 +#define CL_COMPILER_NOT_AVAILABLE -3 +#define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 +#define CL_OUT_OF_RESOURCES -5 +#define CL_OUT_OF_HOST_MEMORY -6 +#define CL_PROFILING_INFO_NOT_AVAILABLE -7 +#define CL_MEM_COPY_OVERLAP -8 +#define CL_IMAGE_FORMAT_MISMATCH -9 +#define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 +#define CL_BUILD_PROGRAM_FAILURE -11 +#define CL_MAP_FAILURE -12 +#ifdef CL_VERSION_1_1 +#define CL_MISALIGNED_SUB_BUFFER_OFFSET -13 +#define CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST -14 +#endif +#ifdef CL_VERSION_1_2 +#define CL_COMPILE_PROGRAM_FAILURE -15 +#define CL_LINKER_NOT_AVAILABLE -16 +#define CL_LINK_PROGRAM_FAILURE -17 +#define CL_DEVICE_PARTITION_FAILED -18 +#define CL_KERNEL_ARG_INFO_NOT_AVAILABLE -19 +#endif + +#define CL_INVALID_VALUE -30 +#define CL_INVALID_DEVICE_TYPE -31 +#define CL_INVALID_PLATFORM -32 +#define CL_INVALID_DEVICE -33 +#define CL_INVALID_CONTEXT -34 +#define CL_INVALID_QUEUE_PROPERTIES -35 +#define CL_INVALID_COMMAND_QUEUE -36 +#define CL_INVALID_HOST_PTR -37 +#define CL_INVALID_MEM_OBJECT -38 +#define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 +#define CL_INVALID_IMAGE_SIZE -40 +#define CL_INVALID_SAMPLER -41 +#define CL_INVALID_BINARY -42 +#define CL_INVALID_BUILD_OPTIONS -43 +#define CL_INVALID_PROGRAM -44 +#define CL_INVALID_PROGRAM_EXECUTABLE -45 +#define CL_INVALID_KERNEL_NAME -46 +#define CL_INVALID_KERNEL_DEFINITION -47 +#define CL_INVALID_KERNEL -48 +#define CL_INVALID_ARG_INDEX -49 +#define CL_INVALID_ARG_VALUE -50 +#define CL_INVALID_ARG_SIZE -51 +#define CL_INVALID_KERNEL_ARGS -52 +#define CL_INVALID_WORK_DIMENSION -53 +#define CL_INVALID_WORK_GROUP_SIZE -54 +#define CL_INVALID_WORK_ITEM_SIZE -55 +#define CL_INVALID_GLOBAL_OFFSET -56 +#define CL_INVALID_EVENT_WAIT_LIST -57 +#define CL_INVALID_EVENT -58 +#define CL_INVALID_OPERATION -59 +#define CL_INVALID_GL_OBJECT -60 +#define CL_INVALID_BUFFER_SIZE -61 +#define CL_INVALID_MIP_LEVEL -62 +#define CL_INVALID_GLOBAL_WORK_SIZE -63 +#ifdef CL_VERSION_1_1 +#define CL_INVALID_PROPERTY -64 +#endif +#ifdef CL_VERSION_1_2 +#define CL_INVALID_IMAGE_DESCRIPTOR -65 +#define CL_INVALID_COMPILER_OPTIONS -66 +#define CL_INVALID_LINKER_OPTIONS -67 +#define CL_INVALID_DEVICE_PARTITION_COUNT -68 +#endif +#ifdef CL_VERSION_2_0 +#define CL_INVALID_PIPE_SIZE -69 +#define CL_INVALID_DEVICE_QUEUE -70 +#endif +#ifdef CL_VERSION_2_2 +#define CL_INVALID_SPEC_ID -71 +#define CL_MAX_SIZE_RESTRICTION_EXCEEDED -72 +#endif + + +/* cl_bool */ +#define CL_FALSE 0 +#define CL_TRUE 1 +#ifdef CL_VERSION_1_2 +#define CL_BLOCKING CL_TRUE +#define CL_NON_BLOCKING CL_FALSE +#endif + +/* cl_platform_info */ +#define CL_PLATFORM_PROFILE 0x0900 +#define CL_PLATFORM_VERSION 0x0901 +#define CL_PLATFORM_NAME 0x0902 +#define CL_PLATFORM_VENDOR 0x0903 +#define CL_PLATFORM_EXTENSIONS 0x0904 +#ifdef CL_VERSION_2_1 +#define CL_PLATFORM_HOST_TIMER_RESOLUTION 0x0905 +#endif + +/* cl_device_type - bitfield */ +#define CL_DEVICE_TYPE_DEFAULT (1 << 0) +#define CL_DEVICE_TYPE_CPU (1 << 1) +#define CL_DEVICE_TYPE_GPU (1 << 2) +#define CL_DEVICE_TYPE_ACCELERATOR (1 << 3) +#ifdef CL_VERSION_1_2 +#define CL_DEVICE_TYPE_CUSTOM (1 << 4) +#endif +#define CL_DEVICE_TYPE_ALL 0xFFFFFFFF + +/* cl_device_info */ +#define CL_DEVICE_TYPE 0x1000 +#define CL_DEVICE_VENDOR_ID 0x1001 +#define CL_DEVICE_MAX_COMPUTE_UNITS 0x1002 +#define CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS 0x1003 +#define CL_DEVICE_MAX_WORK_GROUP_SIZE 0x1004 +#define CL_DEVICE_MAX_WORK_ITEM_SIZES 0x1005 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR 0x1006 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT 0x1007 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT 0x1008 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG 0x1009 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT 0x100A +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE 0x100B +#define CL_DEVICE_MAX_CLOCK_FREQUENCY 0x100C +#define CL_DEVICE_ADDRESS_BITS 0x100D +#define CL_DEVICE_MAX_READ_IMAGE_ARGS 0x100E +#define CL_DEVICE_MAX_WRITE_IMAGE_ARGS 0x100F +#define CL_DEVICE_MAX_MEM_ALLOC_SIZE 0x1010 +#define CL_DEVICE_IMAGE2D_MAX_WIDTH 0x1011 +#define CL_DEVICE_IMAGE2D_MAX_HEIGHT 0x1012 +#define CL_DEVICE_IMAGE3D_MAX_WIDTH 0x1013 +#define CL_DEVICE_IMAGE3D_MAX_HEIGHT 0x1014 +#define CL_DEVICE_IMAGE3D_MAX_DEPTH 0x1015 +#define CL_DEVICE_IMAGE_SUPPORT 0x1016 +#define CL_DEVICE_MAX_PARAMETER_SIZE 0x1017 +#define CL_DEVICE_MAX_SAMPLERS 0x1018 +#define CL_DEVICE_MEM_BASE_ADDR_ALIGN 0x1019 +#define CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE 0x101A +#define CL_DEVICE_SINGLE_FP_CONFIG 0x101B +#define CL_DEVICE_GLOBAL_MEM_CACHE_TYPE 0x101C +#define CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE 0x101D +#define CL_DEVICE_GLOBAL_MEM_CACHE_SIZE 0x101E +#define CL_DEVICE_GLOBAL_MEM_SIZE 0x101F +#define CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE 0x1020 +#define CL_DEVICE_MAX_CONSTANT_ARGS 0x1021 +#define CL_DEVICE_LOCAL_MEM_TYPE 0x1022 +#define CL_DEVICE_LOCAL_MEM_SIZE 0x1023 +#define CL_DEVICE_ERROR_CORRECTION_SUPPORT 0x1024 +#define CL_DEVICE_PROFILING_TIMER_RESOLUTION 0x1025 +#define CL_DEVICE_ENDIAN_LITTLE 0x1026 +#define CL_DEVICE_AVAILABLE 0x1027 +#define CL_DEVICE_COMPILER_AVAILABLE 0x1028 +#define CL_DEVICE_EXECUTION_CAPABILITIES 0x1029 +#define CL_DEVICE_QUEUE_PROPERTIES 0x102A /* deprecated */ +#ifdef CL_VERSION_2_0 +#define CL_DEVICE_QUEUE_ON_HOST_PROPERTIES 0x102A +#endif +#define CL_DEVICE_NAME 0x102B +#define CL_DEVICE_VENDOR 0x102C +#define CL_DRIVER_VERSION 0x102D +#define CL_DEVICE_PROFILE 0x102E +#define CL_DEVICE_VERSION 0x102F +#define CL_DEVICE_EXTENSIONS 0x1030 +#define CL_DEVICE_PLATFORM 0x1031 +#ifdef CL_VERSION_1_2 +#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 +#endif +/* 0x1033 reserved for CL_DEVICE_HALF_FP_CONFIG which is already defined in "cl_ext.h" */ +#ifdef CL_VERSION_1_1 +#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF 0x1034 +#define CL_DEVICE_HOST_UNIFIED_MEMORY 0x1035 /* deprecated */ +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR 0x1036 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT 0x1037 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 0x1038 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 0x1039 +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 0x103A +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 0x103B +#define CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 0x103C +#define CL_DEVICE_OPENCL_C_VERSION 0x103D +#endif +#ifdef CL_VERSION_1_2 +#define CL_DEVICE_LINKER_AVAILABLE 0x103E +#define CL_DEVICE_BUILT_IN_KERNELS 0x103F +#define CL_DEVICE_IMAGE_MAX_BUFFER_SIZE 0x1040 +#define CL_DEVICE_IMAGE_MAX_ARRAY_SIZE 0x1041 +#define CL_DEVICE_PARENT_DEVICE 0x1042 +#define CL_DEVICE_PARTITION_MAX_SUB_DEVICES 0x1043 +#define CL_DEVICE_PARTITION_PROPERTIES 0x1044 +#define CL_DEVICE_PARTITION_AFFINITY_DOMAIN 0x1045 +#define CL_DEVICE_PARTITION_TYPE 0x1046 +#define CL_DEVICE_REFERENCE_COUNT 0x1047 +#define CL_DEVICE_PREFERRED_INTEROP_USER_SYNC 0x1048 +#define CL_DEVICE_PRINTF_BUFFER_SIZE 0x1049 +#endif +#ifdef CL_VERSION_2_0 +#define CL_DEVICE_IMAGE_PITCH_ALIGNMENT 0x104A +#define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT 0x104B +#define CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS 0x104C +#define CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE 0x104D +#define CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES 0x104E +#define CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE 0x104F +#define CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE 0x1050 +#define CL_DEVICE_MAX_ON_DEVICE_QUEUES 0x1051 +#define CL_DEVICE_MAX_ON_DEVICE_EVENTS 0x1052 +#define CL_DEVICE_SVM_CAPABILITIES 0x1053 +#define CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE 0x1054 +#define CL_DEVICE_MAX_PIPE_ARGS 0x1055 +#define CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS 0x1056 +#define CL_DEVICE_PIPE_MAX_PACKET_SIZE 0x1057 +#define CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT 0x1058 +#define CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT 0x1059 +#define CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT 0x105A +#endif +#ifdef CL_VERSION_2_1 +#define CL_DEVICE_IL_VERSION 0x105B +#define CL_DEVICE_MAX_NUM_SUB_GROUPS 0x105C +#define CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS 0x105D +#endif + +/* cl_device_fp_config - bitfield */ +#define CL_FP_DENORM (1 << 0) +#define CL_FP_INF_NAN (1 << 1) +#define CL_FP_ROUND_TO_NEAREST (1 << 2) +#define CL_FP_ROUND_TO_ZERO (1 << 3) +#define CL_FP_ROUND_TO_INF (1 << 4) +#define CL_FP_FMA (1 << 5) +#ifdef CL_VERSION_1_1 +#define CL_FP_SOFT_FLOAT (1 << 6) +#endif +#ifdef CL_VERSION_1_2 +#define CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT (1 << 7) +#endif + +/* cl_device_mem_cache_type */ +#define CL_NONE 0x0 +#define CL_READ_ONLY_CACHE 0x1 +#define CL_READ_WRITE_CACHE 0x2 + +/* cl_device_local_mem_type */ +#define CL_LOCAL 0x1 +#define CL_GLOBAL 0x2 + +/* cl_device_exec_capabilities - bitfield */ +#define CL_EXEC_KERNEL (1 << 0) +#define CL_EXEC_NATIVE_KERNEL (1 << 1) + +/* cl_command_queue_properties - bitfield */ +#define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE (1 << 0) +#define CL_QUEUE_PROFILING_ENABLE (1 << 1) +#ifdef CL_VERSION_2_0 +#define CL_QUEUE_ON_DEVICE (1 << 2) +#define CL_QUEUE_ON_DEVICE_DEFAULT (1 << 3) +#endif + +/* cl_context_info */ +#define CL_CONTEXT_REFERENCE_COUNT 0x1080 +#define CL_CONTEXT_DEVICES 0x1081 +#define CL_CONTEXT_PROPERTIES 0x1082 +#ifdef CL_VERSION_1_1 +#define CL_CONTEXT_NUM_DEVICES 0x1083 +#endif + +/* cl_context_properties */ +#define CL_CONTEXT_PLATFORM 0x1084 +#ifdef CL_VERSION_1_2 +#define CL_CONTEXT_INTEROP_USER_SYNC 0x1085 +#endif + +#ifdef CL_VERSION_1_2 + +/* cl_device_partition_property */ +#define CL_DEVICE_PARTITION_EQUALLY 0x1086 +#define CL_DEVICE_PARTITION_BY_COUNTS 0x1087 +#define CL_DEVICE_PARTITION_BY_COUNTS_LIST_END 0x0 +#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN 0x1088 + +#endif + +#ifdef CL_VERSION_1_2 + +/* cl_device_affinity_domain */ +#define CL_DEVICE_AFFINITY_DOMAIN_NUMA (1 << 0) +#define CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE (1 << 1) +#define CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE (1 << 2) +#define CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE (1 << 3) +#define CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE (1 << 4) +#define CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE (1 << 5) + +#endif + +#ifdef CL_VERSION_2_0 + +/* cl_device_svm_capabilities */ +#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER (1 << 0) +#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER (1 << 1) +#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM (1 << 2) +#define CL_DEVICE_SVM_ATOMICS (1 << 3) + +#endif + +/* cl_command_queue_info */ +#define CL_QUEUE_CONTEXT 0x1090 +#define CL_QUEUE_DEVICE 0x1091 +#define CL_QUEUE_REFERENCE_COUNT 0x1092 +#define CL_QUEUE_PROPERTIES 0x1093 +#ifdef CL_VERSION_2_0 +#define CL_QUEUE_SIZE 0x1094 +#endif +#ifdef CL_VERSION_2_1 +#define CL_QUEUE_DEVICE_DEFAULT 0x1095 +#endif + +/* cl_mem_flags and cl_svm_mem_flags - bitfield */ +#define CL_MEM_READ_WRITE (1 << 0) +#define CL_MEM_WRITE_ONLY (1 << 1) +#define CL_MEM_READ_ONLY (1 << 2) +#define CL_MEM_USE_HOST_PTR (1 << 3) +#define CL_MEM_ALLOC_HOST_PTR (1 << 4) +#define CL_MEM_COPY_HOST_PTR (1 << 5) +/* reserved (1 << 6) */ +#ifdef CL_VERSION_1_2 +#define CL_MEM_HOST_WRITE_ONLY (1 << 7) +#define CL_MEM_HOST_READ_ONLY (1 << 8) +#define CL_MEM_HOST_NO_ACCESS (1 << 9) +#endif +#ifdef CL_VERSION_2_0 +#define CL_MEM_SVM_FINE_GRAIN_BUFFER (1 << 10) /* used by cl_svm_mem_flags only */ +#define CL_MEM_SVM_ATOMICS (1 << 11) /* used by cl_svm_mem_flags only */ +#define CL_MEM_KERNEL_READ_AND_WRITE (1 << 12) +#endif + +#ifdef CL_VERSION_1_2 + +/* cl_mem_migration_flags - bitfield */ +#define CL_MIGRATE_MEM_OBJECT_HOST (1 << 0) +#define CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED (1 << 1) + +#endif + +/* cl_channel_order */ +#define CL_R 0x10B0 +#define CL_A 0x10B1 +#define CL_RG 0x10B2 +#define CL_RA 0x10B3 +#define CL_RGB 0x10B4 +#define CL_RGBA 0x10B5 +#define CL_BGRA 0x10B6 +#define CL_ARGB 0x10B7 +#define CL_INTENSITY 0x10B8 +#define CL_LUMINANCE 0x10B9 +#ifdef CL_VERSION_1_1 +#define CL_Rx 0x10BA +#define CL_RGx 0x10BB +#define CL_RGBx 0x10BC +#endif +#ifdef CL_VERSION_1_2 +#define CL_DEPTH 0x10BD +#define CL_DEPTH_STENCIL 0x10BE +#endif +#ifdef CL_VERSION_2_0 +#define CL_sRGB 0x10BF +#define CL_sRGBx 0x10C0 +#define CL_sRGBA 0x10C1 +#define CL_sBGRA 0x10C2 +#define CL_ABGR 0x10C3 +#endif + +/* cl_channel_type */ +#define CL_SNORM_INT8 0x10D0 +#define CL_SNORM_INT16 0x10D1 +#define CL_UNORM_INT8 0x10D2 +#define CL_UNORM_INT16 0x10D3 +#define CL_UNORM_SHORT_565 0x10D4 +#define CL_UNORM_SHORT_555 0x10D5 +#define CL_UNORM_INT_101010 0x10D6 +#define CL_SIGNED_INT8 0x10D7 +#define CL_SIGNED_INT16 0x10D8 +#define CL_SIGNED_INT32 0x10D9 +#define CL_UNSIGNED_INT8 0x10DA +#define CL_UNSIGNED_INT16 0x10DB +#define CL_UNSIGNED_INT32 0x10DC +#define CL_HALF_FLOAT 0x10DD +#define CL_FLOAT 0x10DE +#ifdef CL_VERSION_1_2 +#define CL_UNORM_INT24 0x10DF +#endif +#ifdef CL_VERSION_2_1 +#define CL_UNORM_INT_101010_2 0x10E0 +#endif + +/* cl_mem_object_type */ +#define CL_MEM_OBJECT_BUFFER 0x10F0 +#define CL_MEM_OBJECT_IMAGE2D 0x10F1 +#define CL_MEM_OBJECT_IMAGE3D 0x10F2 +#ifdef CL_VERSION_1_2 +#define CL_MEM_OBJECT_IMAGE2D_ARRAY 0x10F3 +#define CL_MEM_OBJECT_IMAGE1D 0x10F4 +#define CL_MEM_OBJECT_IMAGE1D_ARRAY 0x10F5 +#define CL_MEM_OBJECT_IMAGE1D_BUFFER 0x10F6 +#endif +#ifdef CL_VERSION_2_0 +#define CL_MEM_OBJECT_PIPE 0x10F7 +#endif + +/* cl_mem_info */ +#define CL_MEM_TYPE 0x1100 +#define CL_MEM_FLAGS 0x1101 +#define CL_MEM_SIZE 0x1102 +#define CL_MEM_HOST_PTR 0x1103 +#define CL_MEM_MAP_COUNT 0x1104 +#define CL_MEM_REFERENCE_COUNT 0x1105 +#define CL_MEM_CONTEXT 0x1106 +#ifdef CL_VERSION_1_1 +#define CL_MEM_ASSOCIATED_MEMOBJECT 0x1107 +#define CL_MEM_OFFSET 0x1108 +#endif +#ifdef CL_VERSION_2_0 +#define CL_MEM_USES_SVM_POINTER 0x1109 +#endif + +/* cl_image_info */ +#define CL_IMAGE_FORMAT 0x1110 +#define CL_IMAGE_ELEMENT_SIZE 0x1111 +#define CL_IMAGE_ROW_PITCH 0x1112 +#define CL_IMAGE_SLICE_PITCH 0x1113 +#define CL_IMAGE_WIDTH 0x1114 +#define CL_IMAGE_HEIGHT 0x1115 +#define CL_IMAGE_DEPTH 0x1116 +#ifdef CL_VERSION_1_2 +#define CL_IMAGE_ARRAY_SIZE 0x1117 +#define CL_IMAGE_BUFFER 0x1118 +#define CL_IMAGE_NUM_MIP_LEVELS 0x1119 +#define CL_IMAGE_NUM_SAMPLES 0x111A +#endif + +#ifdef CL_VERSION_2_0 + +/* cl_pipe_info */ +#define CL_PIPE_PACKET_SIZE 0x1120 +#define CL_PIPE_MAX_PACKETS 0x1121 + +#endif + +/* cl_addressing_mode */ +#define CL_ADDRESS_NONE 0x1130 +#define CL_ADDRESS_CLAMP_TO_EDGE 0x1131 +#define CL_ADDRESS_CLAMP 0x1132 +#define CL_ADDRESS_REPEAT 0x1133 +#ifdef CL_VERSION_1_1 +#define CL_ADDRESS_MIRRORED_REPEAT 0x1134 +#endif + +/* cl_filter_mode */ +#define CL_FILTER_NEAREST 0x1140 +#define CL_FILTER_LINEAR 0x1141 + +/* cl_sampler_info */ +#define CL_SAMPLER_REFERENCE_COUNT 0x1150 +#define CL_SAMPLER_CONTEXT 0x1151 +#define CL_SAMPLER_NORMALIZED_COORDS 0x1152 +#define CL_SAMPLER_ADDRESSING_MODE 0x1153 +#define CL_SAMPLER_FILTER_MODE 0x1154 +#ifdef CL_VERSION_2_0 +/* These enumerants are for the cl_khr_mipmap_image extension. + They have since been added to cl_ext.h with an appropriate + KHR suffix, but are left here for backwards compatibility. */ +#define CL_SAMPLER_MIP_FILTER_MODE 0x1155 +#define CL_SAMPLER_LOD_MIN 0x1156 +#define CL_SAMPLER_LOD_MAX 0x1157 +#endif + +/* cl_map_flags - bitfield */ +#define CL_MAP_READ (1 << 0) +#define CL_MAP_WRITE (1 << 1) +#ifdef CL_VERSION_1_2 +#define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2) +#endif + +/* cl_program_info */ +#define CL_PROGRAM_REFERENCE_COUNT 0x1160 +#define CL_PROGRAM_CONTEXT 0x1161 +#define CL_PROGRAM_NUM_DEVICES 0x1162 +#define CL_PROGRAM_DEVICES 0x1163 +#define CL_PROGRAM_SOURCE 0x1164 +#define CL_PROGRAM_BINARY_SIZES 0x1165 +#define CL_PROGRAM_BINARIES 0x1166 +#ifdef CL_VERSION_1_2 +#define CL_PROGRAM_NUM_KERNELS 0x1167 +#define CL_PROGRAM_KERNEL_NAMES 0x1168 +#endif +#ifdef CL_VERSION_2_1 +#define CL_PROGRAM_IL 0x1169 +#endif +#ifdef CL_VERSION_2_2 +#define CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT 0x116A +#define CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT 0x116B +#endif + +/* cl_program_build_info */ +#define CL_PROGRAM_BUILD_STATUS 0x1181 +#define CL_PROGRAM_BUILD_OPTIONS 0x1182 +#define CL_PROGRAM_BUILD_LOG 0x1183 +#ifdef CL_VERSION_1_2 +#define CL_PROGRAM_BINARY_TYPE 0x1184 +#endif +#ifdef CL_VERSION_2_0 +#define CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE 0x1185 +#endif + +#ifdef CL_VERSION_1_2 + +/* cl_program_binary_type */ +#define CL_PROGRAM_BINARY_TYPE_NONE 0x0 +#define CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT 0x1 +#define CL_PROGRAM_BINARY_TYPE_LIBRARY 0x2 +#define CL_PROGRAM_BINARY_TYPE_EXECUTABLE 0x4 + +#endif + +/* cl_build_status */ +#define CL_BUILD_SUCCESS 0 +#define CL_BUILD_NONE -1 +#define CL_BUILD_ERROR -2 +#define CL_BUILD_IN_PROGRESS -3 + +/* cl_kernel_info */ +#define CL_KERNEL_FUNCTION_NAME 0x1190 +#define CL_KERNEL_NUM_ARGS 0x1191 +#define CL_KERNEL_REFERENCE_COUNT 0x1192 +#define CL_KERNEL_CONTEXT 0x1193 +#define CL_KERNEL_PROGRAM 0x1194 +#ifdef CL_VERSION_1_2 +#define CL_KERNEL_ATTRIBUTES 0x1195 +#endif + +#ifdef CL_VERSION_1_2 + +/* cl_kernel_arg_info */ +#define CL_KERNEL_ARG_ADDRESS_QUALIFIER 0x1196 +#define CL_KERNEL_ARG_ACCESS_QUALIFIER 0x1197 +#define CL_KERNEL_ARG_TYPE_NAME 0x1198 +#define CL_KERNEL_ARG_TYPE_QUALIFIER 0x1199 +#define CL_KERNEL_ARG_NAME 0x119A + +#endif + +#ifdef CL_VERSION_1_2 + +/* cl_kernel_arg_address_qualifier */ +#define CL_KERNEL_ARG_ADDRESS_GLOBAL 0x119B +#define CL_KERNEL_ARG_ADDRESS_LOCAL 0x119C +#define CL_KERNEL_ARG_ADDRESS_CONSTANT 0x119D +#define CL_KERNEL_ARG_ADDRESS_PRIVATE 0x119E + +#endif + +#ifdef CL_VERSION_1_2 + +/* cl_kernel_arg_access_qualifier */ +#define CL_KERNEL_ARG_ACCESS_READ_ONLY 0x11A0 +#define CL_KERNEL_ARG_ACCESS_WRITE_ONLY 0x11A1 +#define CL_KERNEL_ARG_ACCESS_READ_WRITE 0x11A2 +#define CL_KERNEL_ARG_ACCESS_NONE 0x11A3 + +#endif + +#ifdef CL_VERSION_1_2 + +/* cl_kernel_arg_type_qualifier */ +#define CL_KERNEL_ARG_TYPE_NONE 0 +#define CL_KERNEL_ARG_TYPE_CONST (1 << 0) +#define CL_KERNEL_ARG_TYPE_RESTRICT (1 << 1) +#define CL_KERNEL_ARG_TYPE_VOLATILE (1 << 2) +#ifdef CL_VERSION_2_0 +#define CL_KERNEL_ARG_TYPE_PIPE (1 << 3) +#endif + +#endif + +/* cl_kernel_work_group_info */ +#define CL_KERNEL_WORK_GROUP_SIZE 0x11B0 +#define CL_KERNEL_COMPILE_WORK_GROUP_SIZE 0x11B1 +#define CL_KERNEL_LOCAL_MEM_SIZE 0x11B2 +#define CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE 0x11B3 +#define CL_KERNEL_PRIVATE_MEM_SIZE 0x11B4 +#ifdef CL_VERSION_1_2 +#define CL_KERNEL_GLOBAL_WORK_SIZE 0x11B5 +#endif + +#ifdef CL_VERSION_2_1 + +/* cl_kernel_sub_group_info */ +#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE 0x2033 +#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE 0x2034 +#define CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT 0x11B8 +#define CL_KERNEL_MAX_NUM_SUB_GROUPS 0x11B9 +#define CL_KERNEL_COMPILE_NUM_SUB_GROUPS 0x11BA + +#endif + +#ifdef CL_VERSION_2_0 + +/* cl_kernel_exec_info */ +#define CL_KERNEL_EXEC_INFO_SVM_PTRS 0x11B6 +#define CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM 0x11B7 + +#endif + +/* cl_event_info */ +#define CL_EVENT_COMMAND_QUEUE 0x11D0 +#define CL_EVENT_COMMAND_TYPE 0x11D1 +#define CL_EVENT_REFERENCE_COUNT 0x11D2 +#define CL_EVENT_COMMAND_EXECUTION_STATUS 0x11D3 +#ifdef CL_VERSION_1_1 +#define CL_EVENT_CONTEXT 0x11D4 +#endif + +/* cl_command_type */ +#define CL_COMMAND_NDRANGE_KERNEL 0x11F0 +#define CL_COMMAND_TASK 0x11F1 +#define CL_COMMAND_NATIVE_KERNEL 0x11F2 +#define CL_COMMAND_READ_BUFFER 0x11F3 +#define CL_COMMAND_WRITE_BUFFER 0x11F4 +#define CL_COMMAND_COPY_BUFFER 0x11F5 +#define CL_COMMAND_READ_IMAGE 0x11F6 +#define CL_COMMAND_WRITE_IMAGE 0x11F7 +#define CL_COMMAND_COPY_IMAGE 0x11F8 +#define CL_COMMAND_COPY_IMAGE_TO_BUFFER 0x11F9 +#define CL_COMMAND_COPY_BUFFER_TO_IMAGE 0x11FA +#define CL_COMMAND_MAP_BUFFER 0x11FB +#define CL_COMMAND_MAP_IMAGE 0x11FC +#define CL_COMMAND_UNMAP_MEM_OBJECT 0x11FD +#define CL_COMMAND_MARKER 0x11FE +#define CL_COMMAND_ACQUIRE_GL_OBJECTS 0x11FF +#define CL_COMMAND_RELEASE_GL_OBJECTS 0x1200 +#ifdef CL_VERSION_1_1 +#define CL_COMMAND_READ_BUFFER_RECT 0x1201 +#define CL_COMMAND_WRITE_BUFFER_RECT 0x1202 +#define CL_COMMAND_COPY_BUFFER_RECT 0x1203 +#define CL_COMMAND_USER 0x1204 +#endif +#ifdef CL_VERSION_1_2 +#define CL_COMMAND_BARRIER 0x1205 +#define CL_COMMAND_MIGRATE_MEM_OBJECTS 0x1206 +#define CL_COMMAND_FILL_BUFFER 0x1207 +#define CL_COMMAND_FILL_IMAGE 0x1208 +#endif +#ifdef CL_VERSION_2_0 +#define CL_COMMAND_SVM_FREE 0x1209 +#define CL_COMMAND_SVM_MEMCPY 0x120A +#define CL_COMMAND_SVM_MEMFILL 0x120B +#define CL_COMMAND_SVM_MAP 0x120C +#define CL_COMMAND_SVM_UNMAP 0x120D +#endif + +/* command execution status */ +#define CL_COMPLETE 0x0 +#define CL_RUNNING 0x1 +#define CL_SUBMITTED 0x2 +#define CL_QUEUED 0x3 + +#ifdef CL_VERSION_1_1 + +/* cl_buffer_create_type */ +#define CL_BUFFER_CREATE_TYPE_REGION 0x1220 + +#endif + +/* cl_profiling_info */ +#define CL_PROFILING_COMMAND_QUEUED 0x1280 +#define CL_PROFILING_COMMAND_SUBMIT 0x1281 +#define CL_PROFILING_COMMAND_START 0x1282 +#define CL_PROFILING_COMMAND_END 0x1283 +#ifdef CL_VERSION_2_0 +#define CL_PROFILING_COMMAND_COMPLETE 0x1284 +#endif + +#ifdef CL_EXPERIMENTAL + +/* cl_device_atomic_capabilities - bitfield */ +#define CL_DEVICE_ATOMIC_ORDER_RELAXED (1 << 0) +#define CL_DEVICE_ATOMIC_ORDER_ACQ_REL (1 << 1) +#define CL_DEVICE_ATOMIC_ORDER_SEQ_CST (1 << 2) +#define CL_DEVICE_ATOMIC_SCOPE_WORK_ITEM (1 << 3) +#define CL_DEVICE_ATOMIC_SCOPE_WORK_GROUP (1 << 4) +#define CL_DEVICE_ATOMIC_SCOPE_DEVICE (1 << 5) +#define CL_DEVICE_ATOMIC_SCOPE_ALL_SVM_DEVICES (1 << 6) + +/* cl_device_info */ +#define CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES 0x1063 +#define CL_DEVICE_ATOMIC_FENCE_CAPABILITIES 0x1064 +#define CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT 0x1065 +#define CL_DEVICE_OPENCL_C_VERSIONS 0x1066 +#define CL_DEVICE_MAX_WRITE_IMAGE3D_ARGS 0x1067 +#define CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT 0x1068 +#define CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT 0x1069 +/* 0x106A to 0x106E - Reserved for upcoming KHR extension */ +#define CL_DEVICE_OPENCL_C_FEATURES 0x106F + +/* cl_command_type */ +#define CL_COMMAND_SVM_MIGRATE_MEM 0x120E + +#endif + +/* cl_khronos_vendor_id */ +#define CL_KHRONOS_VENDOR_ID_CODEPLAY 0x10004 + +/********************************************************************************************************/ + +/* Platform API */ +extern CL_API_ENTRY cl_int CL_API_CALL +clGetPlatformIDs(cl_uint num_entries, + cl_platform_id * platforms, + cl_uint * num_platforms) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetPlatformInfo(cl_platform_id platform, + cl_platform_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +/* Device APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceIDs(cl_platform_id platform, + cl_device_type device_type, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceInfo(cl_device_id device, + cl_device_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +extern CL_API_ENTRY cl_int CL_API_CALL +clCreateSubDevices(cl_device_id in_device, + const cl_device_partition_property * properties, + cl_uint num_devices, + cl_device_id * out_devices, + cl_uint * num_devices_ret) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainDevice(cl_device_id device) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseDevice(cl_device_id device) CL_API_SUFFIX__VERSION_1_2; + +#endif + +#ifdef CL_VERSION_2_1 + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetDefaultDeviceCommandQueue(cl_context context, + cl_device_id device, + cl_command_queue command_queue) CL_API_SUFFIX__VERSION_2_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceAndHostTimer(cl_device_id device, + cl_ulong* device_timestamp, + cl_ulong* host_timestamp) CL_API_SUFFIX__VERSION_2_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetHostTimer(cl_device_id device, + cl_ulong * host_timestamp) CL_API_SUFFIX__VERSION_2_1; + +#endif + +/* Context APIs */ +extern CL_API_ENTRY cl_context CL_API_CALL +clCreateContext(const cl_context_properties * properties, + cl_uint num_devices, + const cl_device_id * devices, + void (CL_CALLBACK * pfn_notify)(const char * errinfo, + const void * private_info, + size_t cb, + void * user_data), + void * user_data, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_context CL_API_CALL +clCreateContextFromType(const cl_context_properties * properties, + cl_device_type device_type, + void (CL_CALLBACK * pfn_notify)(const char * errinfo, + const void * private_info, + size_t cb, + void * user_data), + void * user_data, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainContext(cl_context context) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseContext(cl_context context) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetContextInfo(cl_context context, + cl_context_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +/* Command Queue APIs */ + +#ifdef CL_VERSION_2_0 + +extern CL_API_ENTRY cl_command_queue CL_API_CALL +clCreateCommandQueueWithProperties(cl_context context, + cl_device_id device, + const cl_queue_properties * properties, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_0; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainCommandQueue(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseCommandQueue(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetCommandQueueInfo(cl_command_queue command_queue, + cl_command_queue_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +/* Memory Object APIs */ +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateBuffer(cl_context context, + cl_mem_flags flags, + size_t size, + void * host_ptr, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_1 + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateSubBuffer(cl_mem buffer, + cl_mem_flags flags, + cl_buffer_create_type buffer_create_type, + const void * buffer_create_info, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1; + +#endif + +#ifdef CL_VERSION_1_2 + +extern CL_API_ENTRY cl_mem CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_2; + +#endif + +#ifdef CL_VERSION_2_0 + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreatePipe(cl_context context, + cl_mem_flags flags, + cl_uint pipe_packet_size, + cl_uint pipe_max_packets, + const cl_pipe_properties * properties, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_0; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainMemObject(cl_mem memobj) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseMemObject(cl_mem memobj) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetMemObjectInfo(cl_mem memobj, + cl_mem_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetImageInfo(cl_mem image, + cl_image_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_2_0 + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetPipeInfo(cl_mem pipe, + cl_pipe_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_2_0; + +#endif + +#ifdef CL_VERSION_1_1 + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetMemObjectDestructorCallback(cl_mem memobj, + void (CL_CALLBACK * pfn_notify)(cl_mem memobj, + void * user_data), + void * user_data) CL_API_SUFFIX__VERSION_1_1; + +#endif + +/* SVM Allocation APIs */ + +#ifdef CL_VERSION_2_0 + +extern CL_API_ENTRY void * CL_API_CALL +clSVMAlloc(cl_context context, + cl_svm_mem_flags flags, + size_t size, + cl_uint alignment) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY void CL_API_CALL +clSVMFree(cl_context context, + void * svm_pointer) CL_API_SUFFIX__VERSION_2_0; + +#endif + +/* Sampler APIs */ + +#ifdef CL_VERSION_2_0 + +extern CL_API_ENTRY cl_sampler CL_API_CALL +clCreateSamplerWithProperties(cl_context context, + const cl_sampler_properties * sampler_properties, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_0; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainSampler(cl_sampler sampler) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseSampler(cl_sampler sampler) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetSamplerInfo(cl_sampler sampler, + cl_sampler_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +/* Program Object APIs */ +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithSource(cl_context context, + cl_uint count, + const char ** strings, + const size_t * lengths, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_program CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithBuiltInKernels(cl_context context, + cl_uint num_devices, + const cl_device_id * device_list, + const char * kernel_names, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +#endif + +#ifdef CL_VERSION_2_1 + +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithIL(cl_context context, + const void* il, + size_t length, + cl_int* errcode_ret) CL_API_SUFFIX__VERSION_2_1; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainProgram(cl_program program) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseProgram(cl_program program) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +extern CL_API_ENTRY cl_int CL_API_CALL +clCompileProgram(cl_program program, + cl_uint num_devices, + const cl_device_id * device_list, + const char * options, + cl_uint num_input_headers, + const cl_program * input_headers, + const char ** header_include_names, + void (CL_CALLBACK * pfn_notify)(cl_program program, + void * user_data), + void * user_data) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_program CL_API_CALL +clLinkProgram(cl_context context, + cl_uint num_devices, + const cl_device_id * device_list, + const char * options, + cl_uint num_input_programs, + const cl_program * input_programs, + void (CL_CALLBACK * pfn_notify)(cl_program program, + void * user_data), + void * user_data, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +#endif + +#ifdef CL_VERSION_2_2 + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetProgramReleaseCallback(cl_program program, + void (CL_CALLBACK * pfn_notify)(cl_program program, + void * user_data), + void * user_data) CL_API_SUFFIX__VERSION_2_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetProgramSpecializationConstant(cl_program program, + cl_uint spec_id, + size_t spec_size, + const void* spec_value) CL_API_SUFFIX__VERSION_2_2; + +#endif + +#ifdef CL_VERSION_1_2 + +extern CL_API_ENTRY cl_int CL_API_CALL +clUnloadPlatformCompiler(cl_platform_id platform) CL_API_SUFFIX__VERSION_1_2; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetProgramInfo(cl_program program, + cl_program_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0; + +/* Kernel Object APIs */ +extern CL_API_ENTRY cl_kernel CL_API_CALL +clCreateKernel(cl_program program, + const char * kernel_name, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clCreateKernelsInProgram(cl_program program, + cl_uint num_kernels, + cl_kernel * kernels, + cl_uint * num_kernels_ret) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_2_1 + +extern CL_API_ENTRY cl_kernel CL_API_CALL +clCloneKernel(cl_kernel source_kernel, + cl_int* errcode_ret) CL_API_SUFFIX__VERSION_2_1; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainKernel(cl_kernel kernel) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseKernel(cl_kernel kernel) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArg(cl_kernel kernel, + cl_uint arg_index, + size_t arg_size, + const void * arg_value) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_2_0 + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArgSVMPointer(cl_kernel kernel, + cl_uint arg_index, + const void * arg_value) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelExecInfo(cl_kernel kernel, + cl_kernel_exec_info param_name, + size_t param_value_size, + const void * param_value) CL_API_SUFFIX__VERSION_2_0; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetKernelInfo(cl_kernel kernel, + cl_kernel_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetKernelArgInfo(cl_kernel kernel, + cl_uint arg_indx, + cl_kernel_arg_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_2; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_2_1 + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetKernelSubGroupInfo(cl_kernel kernel, + cl_device_id device, + cl_kernel_sub_group_info param_name, + size_t input_value_size, + const void* input_value, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret) CL_API_SUFFIX__VERSION_2_1; + +#endif + +/* Event Object APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clWaitForEvents(cl_uint num_events, + const cl_event * event_list) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetEventInfo(cl_event event, + cl_event_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_1 + +extern CL_API_ENTRY cl_event CL_API_CALL +clCreateUserEvent(cl_context context, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainEvent(cl_event event) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseEvent(cl_event event) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_1 + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetUserEventStatus(cl_event event, + cl_int execution_status) CL_API_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetEventCallback(cl_event event, + cl_int command_exec_callback_type, + void (CL_CALLBACK * pfn_notify)(cl_event event, + cl_int event_command_status, + void * user_data), + void * user_data) CL_API_SUFFIX__VERSION_1_1; + +#endif + +/* Profiling APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clGetEventProfilingInfo(cl_event event, + cl_profiling_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +/* Flush and Finish APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +clFlush(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clFinish(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0; + +/* Enqueued Commands APIs */ +extern CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_1 + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadBufferRect(cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_read, + const size_t * buffer_offset, + const size_t * host_offset, + const size_t * region, + size_t buffer_row_pitch, + size_t buffer_slice_pitch, + size_t host_row_pitch, + size_t host_slice_pitch, + void * ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_1; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_1 + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteBufferRect(cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_write, + const size_t * buffer_offset, + const size_t * host_offset, + const size_t * region, + size_t buffer_row_pitch, + size_t buffer_slice_pitch, + size_t host_row_pitch, + size_t host_slice_pitch, + const void * ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_1; + +#endif + +#ifdef CL_VERSION_1_2 + +extern CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_2; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBuffer(cl_command_queue command_queue, + cl_mem src_buffer, + cl_mem dst_buffer, + size_t src_offset, + size_t dst_offset, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_1 + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBufferRect(cl_command_queue command_queue, + cl_mem src_buffer, + cl_mem dst_buffer, + const size_t * src_origin, + const size_t * dst_origin, + const size_t * region, + size_t src_row_pitch, + size_t src_slice_pitch, + size_t dst_row_pitch, + size_t dst_slice_pitch, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_1; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadImage(cl_command_queue command_queue, + cl_mem image, + cl_bool blocking_read, + const size_t * origin, + const size_t * region, + 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) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteImage(cl_command_queue command_queue, + cl_mem image, + cl_bool blocking_write, + const size_t * origin, + const size_t * region, + 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) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueFillImage(cl_command_queue command_queue, + cl_mem image, + const void * fill_color, + const size_t * origin, + const size_t * region, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyImage(cl_command_queue command_queue, + cl_mem src_image, + cl_mem dst_image, + const size_t * src_origin, + const size_t * dst_origin, + const size_t * region, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyImageToBuffer(cl_command_queue command_queue, + cl_mem src_image, + cl_mem dst_buffer, + const size_t * src_origin, + const size_t * region, + size_t dst_offset, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBufferToImage(cl_command_queue command_queue, + cl_mem src_buffer, + cl_mem dst_image, + size_t src_offset, + const size_t * dst_origin, + const size_t * region, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY void * CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY void * CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMigrateMemObjects(cl_command_queue command_queue, + cl_uint num_mem_objects, + const cl_mem * mem_objects, + cl_mem_migration_flags flags, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +#endif + +extern CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueNativeKernel(cl_command_queue command_queue, + void (CL_CALLBACK * user_func)(void *), + void * args, + size_t cb_args, + cl_uint num_mem_objects, + const cl_mem * mem_list, + const void ** args_mem_loc, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMarkerWithWaitList(cl_command_queue command_queue, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueBarrierWithWaitList(cl_command_queue command_queue, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +#endif + +#ifdef CL_VERSION_2_0 + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMFree(cl_command_queue command_queue, + cl_uint num_svm_pointers, + void * svm_pointers[], + void (CL_CALLBACK * pfn_free_func)(cl_command_queue queue, + cl_uint num_svm_pointers, + void * svm_pointers[], + void * user_data), + void * user_data, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemcpy(cl_command_queue command_queue, + cl_bool blocking_copy, + void * dst_ptr, + const void * src_ptr, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemFill(cl_command_queue command_queue, + void * svm_ptr, + const void * pattern, + size_t pattern_size, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMap(cl_command_queue command_queue, + cl_bool blocking_map, + cl_map_flags flags, + void * svm_ptr, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_2_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMUnmap(cl_command_queue command_queue, + void * svm_ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_2_0; + +#endif + +#ifdef CL_VERSION_2_1 + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMigrateMem(cl_command_queue command_queue, + cl_uint num_svm_pointers, + const void ** svm_pointers, + const size_t * sizes, + cl_mem_migration_flags flags, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_2_1; + +#endif + +#ifdef CL_VERSION_1_2 + +/* Extension function access + * + * Returns the extension function address for the given function name, + * or NULL if a valid function can not be found. The client must + * check to make sure the address is not NULL, before using or + * calling the returned function address. + */ +extern CL_API_ENTRY void * CL_API_CALL +clGetExtensionFunctionAddressForPlatform(cl_platform_id platform, + const char * func_name) CL_API_SUFFIX__VERSION_1_2; + +#endif + +#ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS + /* + * WARNING: + * This API introduces mutable state into the OpenCL implementation. It has been REMOVED + * to better facilitate thread safety. The 1.0 API is not thread safe. It is not tested by the + * OpenCL 1.1 conformance test, and consequently may not work or may not work dependably. + * It is likely to be non-performant. Use of this API is not advised. Use at your own risk. + * + * Software developers previously relying on this API are instructed to set the command queue + * properties when creating the queue, instead. + */ + extern CL_API_ENTRY cl_int CL_API_CALL + clSetCommandQueueProperty(cl_command_queue command_queue, + cl_command_queue_properties properties, + cl_bool enable, + cl_command_queue_properties * old_properties) CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED; +#endif /* CL_USE_DEPRECATED_OPENCL_1_0_APIS */ + +/* Deprecated OpenCL 1.1 APIs */ +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateImage2D(cl_context context, + cl_mem_flags flags, + const cl_image_format * image_format, + size_t image_width, + size_t image_height, + size_t image_row_pitch, + void * host_ptr, + cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateImage3D(cl_context context, + cl_mem_flags flags, + const cl_image_format * image_format, + size_t image_width, + size_t image_height, + size_t image_depth, + size_t image_row_pitch, + size_t image_slice_pitch, + void * host_ptr, + cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clEnqueueMarker(cl_command_queue command_queue, + cl_event * event) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clEnqueueWaitForEvents(cl_command_queue command_queue, + cl_uint num_events, + const cl_event * event_list) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clEnqueueBarrier(cl_command_queue command_queue) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL +clUnloadCompiler(void) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED void * CL_API_CALL +clGetExtensionFunctionAddress(const char * func_name) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +/* Deprecated OpenCL 2.0 APIs */ +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_command_queue CL_API_CALL +clCreateCommandQueue(cl_context context, + cl_device_id device, + cl_command_queue_properties properties, + cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_sampler CL_API_CALL +clCreateSampler(cl_context context, + cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, + cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int CL_API_CALL +clEnqueueTask(cl_command_queue command_queue, + cl_kernel kernel, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_H */ diff --git a/opencl/khronos/headers/opencl2.2/CL/cl.hpp b/opencl/khronos/headers/opencl2.2/CL/cl.hpp new file mode 100644 index 0000000000..d5f2c0008d --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl.hpp @@ -0,0 +1,12953 @@ +/* Modifications Copyright(C)[2021-2022] Advanced Micro Devices, Inc. + * All rights reserved. + * */ + +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +/*! \file + * + * \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33) and + * OpenCL 1.2 (rev 15) + * \author Benedict R. Gaster, Laurent Morichetti and Lee Howes + * + * Additions and fixes from: + * Brian Cole, March 3rd 2010 and April 2012 + * Matt Gruenke, April 2012. + * Bruce Merry, February 2013. + * Tom Deakin and Simon McIntosh-Smith, July 2013 + * + * \version 1.2.9 + * \date December 2015 + * + * Optional extension support + * + * cl + * cl_ext_device_fission + * #define USE_CL_DEVICE_FISSION + */ + +/*! \mainpage + * \section intro Introduction + * For many large applications C++ is the language of choice and so it seems + * reasonable to define C++ bindings for OpenCL. + * + * + * The interface is contained with a single C++ header file \em cl.hpp and all + * definitions are contained within the namespace \em cl. There is no additional + * requirement to include \em cl.h and to use either the C++ or original C + * bindings it is enough to simply include \em cl.hpp. + * + * The bindings themselves are lightweight and correspond closely to the + * underlying C API. Using the C++ bindings introduces no additional execution + * overhead. + * + * For detail documentation on the bindings see: + * + * The OpenCL C++ Wrapper API 1.2 (revision 09) + * http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.2.pdf + * + * \section example Example + * + * The following example shows a general use case for the C++ + * bindings, including support for the optional exception feature and + * also the supplied vector and string classes, see following sections for + * decriptions of these features. + * + * \code + * #define __CL_ENABLE_EXCEPTIONS + * + * #if defined(__APPLE__) || defined(__MACOSX) + * #include + * #else + * #include + * #endif + * #include + * #include + * #include + * + * const char * helloStr = "__kernel void " + * "hello(void) " + * "{ " + * " " + * "} "; + * + * int + * main(void) + * { + * cl_int err = CL_SUCCESS; + * try { + * + * std::vector platforms; + * cl::Platform::get(&platforms); + * if (platforms.size() == 0) { + * std::cout << "Platform size 0\n"; + * return -1; + * } + * + * cl_context_properties properties[] = + * { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0}; + * cl::Context context(CL_DEVICE_TYPE_CPU, properties); + * + * std::vector devices = context.getInfo(); + * + * cl::Program::Sources source(1, + * std::make_pair(helloStr,strlen(helloStr))); + * cl::Program program_ = cl::Program(context, source); + * program_.build(devices); + * + * cl::Kernel kernel(program_, "hello", &err); + * + * cl::Event event; + * cl::CommandQueue queue(context, devices[0], 0, &err); + * queue.enqueueNDRangeKernel( + * kernel, + * cl::NullRange, + * cl::NDRange(4,4), + * cl::NullRange, + * NULL, + * &event); + * + * event.wait(); + * } + * catch (cl::Error err) { + * std::cerr + * << "ERROR: " + * << err.what() + * << "(" + * << err.err() + * << ")" + * << std::endl; + * } + * + * return EXIT_SUCCESS; + * } + * + * \endcode + * + */ +#ifndef CL_HPP_ +#define CL_HPP_ + +#ifdef _WIN32 + +#include + +#if defined(USE_DX_INTEROP) +#include +#include +#endif +#endif // _WIN32 + +#if defined(_MSC_VER) +#include +#endif // _MSC_VER + +// +#if defined(USE_CL_DEVICE_FISSION) +#include +#endif + +#if defined(__APPLE__) || defined(__MACOSX) +#include +#else +#include +#endif // !__APPLE__ + +#if (_MSC_VER >= 1700) || (__cplusplus >= 201103L) +#define CL_HPP_RVALUE_REFERENCES_SUPPORTED +#define CL_HPP_CPP11_ATOMICS_SUPPORTED +#include +#endif + +#if (__cplusplus >= 201103L) +#define CL_HPP_NOEXCEPT noexcept +#else +#define CL_HPP_NOEXCEPT +#endif + + +// To avoid accidentally taking ownership of core OpenCL types +// such as cl_kernel constructors are made explicit +// under OpenCL 1.2 +#if defined(CL_VERSION_1_2) && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +#define __CL_EXPLICIT_CONSTRUCTORS explicit +#else // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +#define __CL_EXPLICIT_CONSTRUCTORS +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +// Define deprecated prefixes and suffixes to ensure compilation +// in case they are not pre-defined +#if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) + +#if !defined(CL_CALLBACK) +#define CL_CALLBACK +#endif //CL_CALLBACK + +#include +#include +#include + +#if defined(__CL_ENABLE_EXCEPTIONS) +#include +#endif // #if defined(__CL_ENABLE_EXCEPTIONS) + +#if !defined(__NO_STD_VECTOR) +#include +#endif + +#if !defined(__NO_STD_STRING) +#include +#endif + +#if defined(__ANDROID__) || defined(linux) || defined(__APPLE__) || defined(__MACOSX) +#include +#endif // linux + +#include + + +/*! \namespace cl + * + * \brief The OpenCL C++ bindings are defined within this namespace. + * + */ +namespace cl { + +class Memory; + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) +#define __INIT_CL_EXT_FCN_PTR(name) \ + if(!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddress(#name); \ + if(!pfn_##name) { \ + } \ + } +#endif // #if defined(CL_VERSION_1_1) + +#if defined(CL_VERSION_1_2) +#define __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, name) \ + if(!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddressForPlatform(platform, #name); \ + if(!pfn_##name) { \ + } \ + } +#endif // #if defined(CL_VERSION_1_1) + +class Program; +class Device; +class Context; +class CommandQueue; +class Memory; +class Buffer; + +#if defined(__CL_ENABLE_EXCEPTIONS) +/*! \brief Exception class + * + * This may be thrown by API functions when __CL_ENABLE_EXCEPTIONS is defined. + */ +class Error : public std::exception +{ +private: + cl_int err_; + const char * errStr_; +public: + /*! \brief Create a new CL error exception for a given error code + * and corresponding message. + * + * \param err error code value. + * + * \param errStr a descriptive string that must remain in scope until + * handling of the exception has concluded. If set, it + * will be returned by what(). + */ + Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr) + {} + + ~Error() throw() {} + + /*! \brief Get error string associated with exception + * + * \return A memory pointer to the error message string. + */ + virtual const char * what() const throw () + { + if (errStr_ == NULL) { + return "empty"; + } + else { + return errStr_; + } + } + + /*! \brief Get error code associated with exception + * + * \return The error code. + */ + cl_int err(void) const { return err_; } +}; + +#define __ERR_STR(x) #x +#else +#define __ERR_STR(x) NULL +#endif // __CL_ENABLE_EXCEPTIONS + + +namespace detail +{ +#if defined(__CL_ENABLE_EXCEPTIONS) +static inline cl_int errHandler ( + cl_int err, + const char * errStr = NULL) +{ + if (err != CL_SUCCESS) { + throw Error(err, errStr); + } + return err; +} +#else +static inline cl_int errHandler (cl_int err, const char * errStr = NULL) +{ + (void) errStr; // suppress unused variable warning + return err; +} +#endif // __CL_ENABLE_EXCEPTIONS +} + + + +//! \cond DOXYGEN_DETAIL +#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS) +#define __GET_DEVICE_INFO_ERR __ERR_STR(clGetDeviceInfo) +#define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo) +#define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs) +#define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs) +#define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo) +#define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo) +#define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo) +#define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo) +#define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo) +#define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo) +#define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo) +#if defined(CL_VERSION_1_2) +#define __GET_KERNEL_ARG_INFO_ERR __ERR_STR(clGetKernelArgInfo) +#endif // #if defined(CL_VERSION_1_2) +#define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo) +#define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo) +#define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo) +#define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo) + +#define __CREATE_CONTEXT_ERR __ERR_STR(clCreateContext) +#define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType) +#define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats) + +#define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer) +#define __COPY_ERR __ERR_STR(cl::copy) +#define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer) +#define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer) +#define __CREATE_GL_RENDER_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer) +#define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo) +#if defined(CL_VERSION_1_2) +#define __CREATE_IMAGE_ERR __ERR_STR(clCreateImage) +#define __CREATE_GL_TEXTURE_ERR __ERR_STR(clCreateFromGLTexture) +#define __IMAGE_DIMENSION_ERR __ERR_STR(Incorrect image dimensions) +#endif // #if defined(CL_VERSION_1_2) +#define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler) +#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback) + +#define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent) +#define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus) +#define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback) +#define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents) + +#define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel) +#define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg) +#define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource) +#define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary) +#if defined(CL_VERSION_1_2) +#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR __ERR_STR(clCreateProgramWithBuiltInKernels) +#endif // #if defined(CL_VERSION_1_2) +#define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram) +#if defined(CL_VERSION_1_2) +#define __COMPILE_PROGRAM_ERR __ERR_STR(clCompileProgram) +#define __LINK_PROGRAM_ERR __ERR_STR(clLinkProgram) +#endif // #if defined(CL_VERSION_1_2) +#define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram) + +#define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue) +#define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty) +#define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer) +#define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect) +#define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer) +#define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect) +#define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer) +#define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect) +#define __ENQUEUE_FILL_BUFFER_ERR __ERR_STR(clEnqueueFillBuffer) +#define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage) +#define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage) +#define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage) +#define __ENQUEUE_FILL_IMAGE_ERR __ERR_STR(clEnqueueFillImage) +#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer) +#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage) +#define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer) +#define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage) +#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject) +#define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel) +#define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask) +#define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel) +#if defined(CL_VERSION_1_2) +#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR __ERR_STR(clEnqueueMigrateMemObjects) +#endif // #if defined(CL_VERSION_1_2) + +#define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects) +#define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects) + + +#define __RETAIN_ERR __ERR_STR(Retain Object) +#define __RELEASE_ERR __ERR_STR(Release Object) +#define __FLUSH_ERR __ERR_STR(clFlush) +#define __FINISH_ERR __ERR_STR(clFinish) +#define __VECTOR_CAPACITY_ERR __ERR_STR(Vector capacity error) + +/** + * CL 1.2 version that uses device fission. + */ +#if defined(CL_VERSION_1_2) +#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevices) +#else +#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT) +#endif // #if defined(CL_VERSION_1_2) + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) +#define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker) +#define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents) +#define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier) +#define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler) +#define __CREATE_GL_TEXTURE_2D_ERR __ERR_STR(clCreateFromGLTexture2D) +#define __CREATE_GL_TEXTURE_3D_ERR __ERR_STR(clCreateFromGLTexture3D) +#define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D) +#define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D) +#endif // #if defined(CL_VERSION_1_1) + +#endif // __CL_USER_OVERRIDE_ERROR_STRINGS +//! \endcond + +/** + * CL 1.2 marker and barrier commands + */ +#if defined(CL_VERSION_1_2) +#define __ENQUEUE_MARKER_WAIT_LIST_ERR __ERR_STR(clEnqueueMarkerWithWaitList) +#define __ENQUEUE_BARRIER_WAIT_LIST_ERR __ERR_STR(clEnqueueBarrierWithWaitList) +#endif // #if defined(CL_VERSION_1_2) + +#if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING) +typedef std::string STRING_CLASS; +#elif !defined(__USE_DEV_STRING) + +/*! \class string + * \brief Simple string class, that provides a limited subset of std::string + * functionality but avoids many of the issues that come with that class. + + * \note Deprecated. Please use std::string as default or + * re-define the string class to match the std::string + * interface by defining STRING_CLASS + */ +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED string +{ +private: + ::size_t size_; + char * str_; +public: + //! \brief Constructs an empty string, allocating no memory. + string(void) : size_(0), str_(NULL) + { + } + + /*! \brief Constructs a string populated from an arbitrary value of + * specified size. + * + * An extra '\0' is added, in case none was contained in str. + * + * \param str the initial value of the string instance. Note that '\0' + * characters receive no special treatment. If NULL, + * the string is left empty, with a size of 0. + * + * \param size the number of characters to copy from str. + */ + string(const char * str, ::size_t size) : + size_(size), + str_(NULL) + { + if( size > 0 ) { + str_ = new char[size_+1]; + if (str_ != NULL) { + memcpy(str_, str, size_ * sizeof(char)); + str_[size_] = '\0'; + } + else { + size_ = 0; + } + } + } + + /*! \brief Constructs a string populated from a null-terminated value. + * + * \param str the null-terminated initial value of the string instance. + * If NULL, the string is left empty, with a size of 0. + */ + string(const char * str) : + size_(0), + str_(NULL) + { + if( str ) { + size_= ::strlen(str); + } + if( size_ > 0 ) { + str_ = new char[size_ + 1]; + if (str_ != NULL) { + memcpy(str_, str, (size_ + 1) * sizeof(char)); + } + } + } + + void resize( ::size_t n ) + { + if( size_ == n ) { + return; + } + if (n == 0) { + if( str_ ) { + delete [] str_; + } + str_ = NULL; + size_ = 0; + } + else { + char *newString = new char[n + 1]; + ::size_t copySize = n; + if( size_ < n ) { + copySize = size_; + } + size_ = n; + + if(str_) { + memcpy(newString, str_, (copySize + 1) * sizeof(char)); + } + if( copySize < size_ ) { + memset(newString + copySize, 0, size_ - copySize); + } + newString[size_] = '\0'; + + delete [] str_; + str_ = newString; + } + } + + const char& operator[] ( ::size_t pos ) const + { + return str_[pos]; + } + + char& operator[] ( ::size_t pos ) + { + return str_[pos]; + } + + /*! \brief Copies the value of another string to this one. + * + * \param rhs the string to copy. + * + * \returns a reference to the modified instance. + */ + string& operator=(const string& rhs) + { + if (this == &rhs) { + return *this; + } + + if( str_ != NULL ) { + delete [] str_; + str_ = NULL; + size_ = 0; + } + + if (rhs.size_ == 0 || rhs.str_ == NULL) { + str_ = NULL; + size_ = 0; + } + else { + str_ = new char[rhs.size_ + 1]; + size_ = rhs.size_; + + if (str_ != NULL) { + memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char)); + } + else { + size_ = 0; + } + } + + return *this; + } + + /*! \brief Constructs a string by copying the value of another instance. + * + * \param rhs the string to copy. + */ + string(const string& rhs) : + size_(0), + str_(NULL) + { + *this = rhs; + } + + //! \brief Destructor - frees memory used to hold the current value. + ~string() + { + delete[] str_; + str_ = NULL; + } + + //! \brief Queries the length of the string, excluding any added '\0's. + ::size_t size(void) const { return size_; } + + //! \brief Queries the length of the string, excluding any added '\0's. + ::size_t length(void) const { return size(); } + + /*! \brief Returns a pointer to the private copy held by this instance, + * or "" if empty/unset. + */ + const char * c_str(void) const { return (str_) ? str_ : "";} +} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +typedef cl::string STRING_CLASS; +#endif // #elif !defined(__USE_DEV_STRING) + +#if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR) +#define VECTOR_CLASS std::vector +#elif !defined(__USE_DEV_VECTOR) +#define VECTOR_CLASS cl::vector + +#if !defined(__MAX_DEFAULT_VECTOR_SIZE) +#define __MAX_DEFAULT_VECTOR_SIZE 10 +#endif + +/*! \class vector + * \brief Fixed sized vector implementation that mirroring + * + * \note Deprecated. Please use std::vector as default or + * re-define the vector class to match the std::vector + * interface by defining VECTOR_CLASS + + * \note Not recommended for use with custom objects as + * current implementation will construct N elements + * + * std::vector functionality. + * \brief Fixed sized vector compatible with std::vector. + * + * \note + * This differs from std::vector<> not just in memory allocation, + * but also in terms of when members are constructed, destroyed, + * and assigned instead of being copy constructed. + * + * \param T type of element contained in the vector. + * + * \param N maximum size of the vector. + */ +template +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED vector +{ +private: + T data_[N]; + unsigned int size_; + +public: + //! \brief Constructs an empty vector with no memory allocated. + vector() : + size_(static_cast(0)) + {} + + //! \brief Deallocates the vector's memory and destroys all of its elements. + ~vector() + { + clear(); + } + + //! \brief Returns the number of elements currently contained. + unsigned int size(void) const + { + return size_; + } + + /*! \brief Empties the vector of all elements. + * \note + * This does not deallocate memory but will invoke destructors + * on contained elements. + */ + void clear() + { + while(!empty()) { + pop_back(); + } + } + + /*! \brief Appends an element after the last valid element. + * Calling this on a vector that has reached capacity will throw an + * exception if exceptions are enabled. + */ + void push_back (const T& x) + { + if (size() < N) { + new (&data_[size_]) T(x); + size_++; + } else { + detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); + } + } + + /*! \brief Removes the last valid element from the vector. + * Calling this on an empty vector will throw an exception + * if exceptions are enabled. + */ + void pop_back(void) + { + if (size_ != 0) { + --size_; + data_[size_].~T(); + } else { + detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); + } + } + + /*! \brief Constructs with a value copied from another. + * + * \param vec the vector to copy. + */ + vector(const vector& vec) : + size_(vec.size_) + { + if (size_ != 0) { + assign(vec.begin(), vec.end()); + } + } + + /*! \brief Constructs with a specified number of initial elements. + * + * \param size number of initial elements. + * + * \param val value of initial elements. + */ + vector(unsigned int size, const T& val = T()) : + size_(0) + { + for (unsigned int i = 0; i < size; i++) { + push_back(val); + } + } + + /*! \brief Overwrites the current content with that copied from another + * instance. + * + * \param rhs vector to copy. + * + * \returns a reference to this. + */ + vector& operator=(const vector& rhs) + { + if (this == &rhs) { + return *this; + } + + if (rhs.size_ != 0) { + assign(rhs.begin(), rhs.end()); + } else { + clear(); + } + + return *this; + } + + /*! \brief Tests equality against another instance. + * + * \param vec the vector against which to compare. + */ + bool operator==(vector &vec) + { + if (size() != vec.size()) { + return false; + } + + for( unsigned int i = 0; i < size(); ++i ) { + if( operator[](i) != vec[i] ) { + return false; + } + } + return true; + } + + //! \brief Conversion operator to T*. + operator T* () { return data_; } + + //! \brief Conversion operator to const T*. + operator const T* () const { return data_; } + + //! \brief Tests whether this instance has any elements. + bool empty (void) const + { + return size_==0; + } + + //! \brief Returns the maximum number of elements this instance can hold. + unsigned int max_size (void) const + { + return N; + } + + //! \brief Returns the maximum number of elements this instance can hold. + unsigned int capacity () const + { + return N; + } + + //! \brief Resizes the vector to the given size + void resize(unsigned int newSize, T fill = T()) + { + if (newSize > N) + { + detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); + } + else + { + while (size_ < newSize) + { + new (&data_[size_]) T(fill); + size_++; + } + while (size_ > newSize) + { + --size_; + data_[size_].~T(); + } + } + } + + /*! \brief Returns a reference to a given element. + * + * \param index which element to access. * + * \note + * The caller is responsible for ensuring index is >= 0 and < size(). + */ + T& operator[](int index) + { + return data_[index]; + } + + /*! \brief Returns a const reference to a given element. + * + * \param index which element to access. + * + * \note + * The caller is responsible for ensuring index is >= 0 and < size(). + */ + const T& operator[](int index) const + { + return data_[index]; + } + + /*! \brief Assigns elements of the vector based on a source iterator range. + * + * \param start Beginning iterator of source range + * \param end Enditerator of source range + * + * \note + * Will throw an exception if exceptions are enabled and size exceeded. + */ + template + void assign(I start, I end) + { + clear(); + while(start != end) { + push_back(*start); + start++; + } + } + + /*! \class iterator + * \brief Const iterator class for vectors + */ + class iterator + { + private: + const vector *vec_; + int index_; + + /** + * Internal iterator constructor to capture reference + * to the vector it iterates over rather than taking + * the vector by copy. + */ + iterator (const vector &vec, int index) : + vec_(&vec) + { + if( !vec.empty() ) { + index_ = index; + } else { + index_ = -1; + } + } + + public: + iterator(void) : + index_(-1), + vec_(NULL) + { + } + + iterator(const iterator& rhs) : + vec_(rhs.vec_), + index_(rhs.index_) + { + } + + ~iterator(void) {} + + static iterator begin(const cl::vector &vec) + { + iterator i(vec, 0); + + return i; + } + + static iterator end(const cl::vector &vec) + { + iterator i(vec, vec.size()); + + return i; + } + + bool operator==(iterator i) + { + return ((vec_ == i.vec_) && + (index_ == i.index_)); + } + + bool operator!=(iterator i) + { + return (!(*this==i)); + } + + iterator& operator++() + { + ++index_; + return *this; + } + + iterator operator++(int) + { + iterator retVal(*this); + ++index_; + return retVal; + } + + iterator& operator--() + { + --index_; + return *this; + } + + iterator operator--(int) + { + iterator retVal(*this); + --index_; + return retVal; + } + + const T& operator *() const + { + return (*vec_)[index_]; + } + }; + + iterator begin(void) + { + return iterator::begin(*this); + } + + iterator begin(void) const + { + return iterator::begin(*this); + } + + iterator end(void) + { + return iterator::end(*this); + } + + iterator end(void) const + { + return iterator::end(*this); + } + + T& front(void) + { + return data_[0]; + } + + T& back(void) + { + return data_[size_]; + } + + const T& front(void) const + { + return data_[0]; + } + + const T& back(void) const + { + return data_[size_-1]; + } +} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +#endif // #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR) + + + + + +namespace detail { +#define __DEFAULT_NOT_INITIALIZED 1 +#define __DEFAULT_BEING_INITIALIZED 2 +#define __DEFAULT_INITIALIZED 4 + + /* + * Compare and exchange primitives are needed for handling of defaults + */ + +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + inline int compare_exchange(std::atomic * dest, int exchange, int comparand) +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED + inline int compare_exchange(volatile int * dest, int exchange, int comparand) +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + { +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + std::atomic_compare_exchange_strong(dest, &comparand, exchange); + return comparand; +#elif _MSC_VER + return (int)(_InterlockedCompareExchange( + (volatile long*)dest, + (long)exchange, + (long)comparand)); +#else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED + return (__sync_val_compare_and_swap( + dest, + comparand, + exchange)); +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + } + + inline void fence() { +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + std::atomic_thread_fence(std::memory_order_seq_cst); +#elif _MSC_VER // !CL_HPP_CPP11_ATOMICS_SUPPORTED + _ReadWriteBarrier(); +#else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED + __sync_synchronize(); +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + } +} // namespace detail + + +/*! \brief class used to interface between C++ and + * OpenCL C calls that require arrays of size_t values, whose + * size is known statically. + */ +template +class size_t +{ +private: + ::size_t data_[N]; + +public: + //! \brief Initialize size_t to all 0s + size_t() + { + for( int i = 0; i < N; ++i ) { + data_[i] = 0; + } + } + + ::size_t& operator[](int index) + { + return data_[index]; + } + + const ::size_t& operator[](int index) const + { + return data_[index]; + } + + //! \brief Conversion operator to T*. + operator ::size_t* () { return data_; } + + //! \brief Conversion operator to const T*. + operator const ::size_t* () const { return data_; } +}; + +namespace detail { + +// Generic getInfoHelper. The final parameter is used to guide overload +// resolution: the actual parameter passed is an int, which makes this +// a worse conversion sequence than a specialization that declares the +// parameter as an int. +template +inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long) +{ + return f(name, sizeof(T), param, NULL); +} + +// Specialized getInfoHelper for VECTOR_CLASS params +template +inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, long) +{ + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + T* value = (T*) alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + param->assign(&value[0], &value[required/sizeof(T)]); + return CL_SUCCESS; +} + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, int, typename T::cl_type = 0) +{ + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + typename T::cl_type * value = (typename T::cl_type *) alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + ::size_t elements = required / sizeof(typename T::cl_type); + param->assign(&value[0], &value[elements]); + for (::size_t i = 0; i < elements; i++) + { + if (value[i] != NULL) + { + err = (*param)[i].retain(); + if (err != CL_SUCCESS) { + return err; + } + } + } + return CL_SUCCESS; +} + +// Specialized for getInfo +template +inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, int) +{ + cl_int err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL); + + if (err != CL_SUCCESS) { + return err; + } + + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for STRING_CLASS params +template +inline cl_int getInfoHelper(Func f, cl_uint name, STRING_CLASS* param, long) +{ +#if defined(__NO_STD_VECTOR) || defined(__NO_STD_STRING) + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + char* value = (char*)alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + *param = value; + return CL_SUCCESS; +#else + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + // std::string has a constant data member + // a char vector does not + VECTOR_CLASS value(required); + err = f(name, required, value.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + if (param) { + param->assign(value.begin(), value.end()); + } +#endif + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for cl::size_t params +template +inline cl_int getInfoHelper(Func f, cl_uint name, size_t* param, long) +{ + ::size_t required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + ::size_t* value = (::size_t*) alloca(required); + err = f(name, required, value, NULL); + if (err != CL_SUCCESS) { + return err; + } + + for(int i = 0; i < N; ++i) { + (*param)[i] = value[i]; + } + + return CL_SUCCESS; +} + +template struct ReferenceHandler; + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0) +{ + typename T::cl_type value; + cl_int err = f(name, sizeof(value), &value, NULL); + if (err != CL_SUCCESS) { + return err; + } + *param = value; + if (value != NULL) + { + err = param->retain(); + if (err != CL_SUCCESS) { + return err; + } + } + return CL_SUCCESS; +} + +#define __PARAM_NAME_INFO_1_0(F) \ + F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \ + F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \ + \ + F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \ + F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \ + F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \ + F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \ + F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \ + F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \ + F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \ + F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \ + F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \ + F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \ + F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \ + F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \ + \ + F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \ + F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS) \ + F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS) \ + \ + F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \ + F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \ + F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \ + F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \ + \ + F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \ + \ + F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \ + F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \ + F(cl_mem_info, CL_MEM_SIZE, ::size_t) \ + F(cl_mem_info, CL_MEM_HOST_PTR, void*) \ + F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \ + \ + F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \ + F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \ + F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \ + F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \ + F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \ + F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \ + F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \ + \ + F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \ + F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \ + F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \ + F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \ + F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \ + \ + F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \ + F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \ + F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \ + F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS) \ + F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \ + F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \ + F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS) \ + \ + F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \ + \ + F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \ + F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \ + F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \ + F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \ + F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \ + \ + F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \ + F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \ + F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \ + F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties) + +#if defined(CL_VERSION_1_1) +#define __PARAM_NAME_INFO_1_1(F) \ + F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \ + F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, STRING_CLASS) \ + \ + F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \ + F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \ + F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \ + \ + F(cl_event_info, CL_EVENT_CONTEXT, cl::Context) +#endif // CL_VERSION_1_1 + + +#if defined(CL_VERSION_1_2) +#define __PARAM_NAME_INFO_1_2(F) \ + F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer) \ + \ + F(cl_program_info, CL_PROGRAM_NUM_KERNELS, ::size_t) \ + F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, STRING_CLASS) \ + \ + F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \ + \ + F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, STRING_CLASS) \ + \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, STRING_CLASS) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, STRING_CLASS) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \ + \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl_device_id) \ + F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPE, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, ::size_t) \ + F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \ + F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, STRING_CLASS) +#endif // #if defined(CL_VERSION_1_2) + +#if defined(USE_CL_DEVICE_FISSION) +#define __PARAM_NAME_DEVICE_FISSION(F) \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \ + F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS) +#endif // USE_CL_DEVICE_FISSION + +template +struct param_traits {}; + +#define __CL_DECLARE_PARAM_TRAITS(token, param_name, T) \ +struct token; \ +template<> \ +struct param_traits \ +{ \ + enum { value = param_name }; \ + typedef T param_type; \ +}; + +__PARAM_NAME_INFO_1_0(__CL_DECLARE_PARAM_TRAITS) +#if defined(CL_VERSION_1_1) +__PARAM_NAME_INFO_1_1(__CL_DECLARE_PARAM_TRAITS) +#endif // CL_VERSION_1_1 +#if defined(CL_VERSION_1_2) +__PARAM_NAME_INFO_1_2(__CL_DECLARE_PARAM_TRAITS) +#endif // CL_VERSION_1_1 + +#if defined(USE_CL_DEVICE_FISSION) +__PARAM_NAME_DEVICE_FISSION(__CL_DECLARE_PARAM_TRAITS); +#endif // USE_CL_DEVICE_FISSION + +#ifdef CL_PLATFORM_ICD_SUFFIX_KHR +__CL_DECLARE_PARAM_TRAITS(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, STRING_CLASS) +#endif + +#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong) +#endif + +#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, VECTOR_CLASS< ::size_t>) +#endif +#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD, ::size_t) +#endif +#ifdef CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD, ::size_t) +#endif +#ifdef CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD, ::size_t) +#endif + +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint) +#endif +#ifdef CL_DEVICE_WARP_SIZE_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint) +#endif +#ifdef CL_DEVICE_GPU_OVERLAP_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool) +#endif +#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool) +#endif +#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV +__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool) +#endif + +// Convenience functions + +template +inline cl_int +getInfo(Func f, cl_uint name, T* param) +{ + return getInfoHelper(f, name, param, 0); +} + +template +struct GetInfoFunctor0 +{ + Func f_; const Arg0& arg0_; + cl_int operator ()( + cl_uint param, ::size_t size, void* value, ::size_t* size_ret) + { return f_(arg0_, param, size, value, size_ret); } +}; + +template +struct GetInfoFunctor1 +{ + Func f_; const Arg0& arg0_; const Arg1& arg1_; + cl_int operator ()( + cl_uint param, ::size_t size, void* value, ::size_t* size_ret) + { return f_(arg0_, arg1_, param, size, value, size_ret); } +}; + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, cl_uint name, T* param) +{ + GetInfoFunctor0 f0 = { f, arg0 }; + return getInfoHelper(f0, name, param, 0); +} + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param) +{ + GetInfoFunctor1 f0 = { f, arg0, arg1 }; + return getInfoHelper(f0, name, param, 0); +} + +template +struct ReferenceHandler +{ }; + +#if defined(CL_VERSION_1_2) +/** + * OpenCL 1.2 devices do have retain/release. + */ +template <> +struct ReferenceHandler +{ + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int retain(cl_device_id device) + { return ::clRetainDevice(device); } + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int release(cl_device_id device) + { return ::clReleaseDevice(device); } +}; +#else // #if defined(CL_VERSION_1_2) +/** + * OpenCL 1.1 devices do not have retain/release. + */ +template <> +struct ReferenceHandler +{ + // cl_device_id does not have retain(). + static cl_int retain(cl_device_id) + { return CL_SUCCESS; } + // cl_device_id does not have release(). + static cl_int release(cl_device_id) + { return CL_SUCCESS; } +}; +#endif // #if defined(CL_VERSION_1_2) + +template <> +struct ReferenceHandler +{ + // cl_platform_id does not have retain(). + static cl_int retain(cl_platform_id) + { return CL_SUCCESS; } + // cl_platform_id does not have release(). + static cl_int release(cl_platform_id) + { return CL_SUCCESS; } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_context context) + { return ::clRetainContext(context); } + static cl_int release(cl_context context) + { return ::clReleaseContext(context); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_command_queue queue) + { return ::clRetainCommandQueue(queue); } + static cl_int release(cl_command_queue queue) + { return ::clReleaseCommandQueue(queue); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_mem memory) + { return ::clRetainMemObject(memory); } + static cl_int release(cl_mem memory) + { return ::clReleaseMemObject(memory); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_sampler sampler) + { return ::clRetainSampler(sampler); } + static cl_int release(cl_sampler sampler) + { return ::clReleaseSampler(sampler); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_program program) + { return ::clRetainProgram(program); } + static cl_int release(cl_program program) + { return ::clReleaseProgram(program); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_kernel kernel) + { return ::clRetainKernel(kernel); } + static cl_int release(cl_kernel kernel) + { return ::clReleaseKernel(kernel); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_event event) + { return ::clRetainEvent(event); } + static cl_int release(cl_event event) + { return ::clReleaseEvent(event); } +}; + + +// Extracts version number with major in the upper 16 bits, minor in the lower 16 +static cl_uint getVersion(const char *versionInfo) +{ + int highVersion = 0; + int lowVersion = 0; + int index = 7; + while(versionInfo[index] != '.' ) { + highVersion *= 10; + highVersion += versionInfo[index]-'0'; + ++index; + } + ++index; + while(versionInfo[index] != ' ' && versionInfo[index] != '\0') { + lowVersion *= 10; + lowVersion += versionInfo[index]-'0'; + ++index; + } + return (highVersion << 16) | lowVersion; +} + +static cl_uint getPlatformVersion(cl_platform_id platform) +{ + ::size_t size = 0; + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size); + char *versionInfo = (char *) alloca(size); + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, &versionInfo[0], &size); + return getVersion(versionInfo); +} + +static cl_uint getDevicePlatformVersion(cl_device_id device) +{ + cl_platform_id platform; + clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL); + return getPlatformVersion(platform); +} + +#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +static cl_uint getContextPlatformVersion(cl_context context) +{ + // The platform cannot be queried directly, so we first have to grab a + // device and obtain its context + ::size_t size = 0; + clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size); + if (size == 0) + return 0; + cl_device_id *devices = (cl_device_id *) alloca(size); + clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices, NULL); + return getDevicePlatformVersion(devices[0]); +} +#endif // #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +template +class Wrapper +{ +public: + typedef T cl_type; + +protected: + cl_type object_; + +public: + Wrapper() : object_(NULL) { } + + Wrapper(const cl_type &obj) : object_(obj) { } + + ~Wrapper() + { + if (object_ != NULL) { release(); } + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT + { + object_ = rhs.object_; + rhs.object_ = NULL; + } +#endif + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + rhs.object_ = NULL; + } + return *this; + } +#endif + + Wrapper& operator = (const cl_type &rhs) + { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs; + return *this; + } + + cl_type operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + cl_int retain() const + { + return ReferenceHandler::retain(object_); + } + + cl_int release() const + { + return ReferenceHandler::release(object_); + } +}; + +template <> +class Wrapper +{ +public: + typedef cl_device_id cl_type; + +protected: + cl_type object_; + bool referenceCountable_; + + static bool isReferenceCountable(cl_device_id device) + { + bool retVal = false; + if (device != NULL) { + int version = getDevicePlatformVersion(device); + if(version > ((1 << 16) + 1)) { + retVal = true; + } + } + return retVal; + } + +public: + Wrapper() : object_(NULL), referenceCountable_(false) + { + } + + Wrapper(const cl_type &obj) : object_(obj), referenceCountable_(false) + { + referenceCountable_ = isReferenceCountable(obj); + } + + ~Wrapper() + { + if (object_ != NULL) { release(); } + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + referenceCountable_ = isReferenceCountable(object_); + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT + { + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } +#endif + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } + } + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } + return *this; + } +#endif + + Wrapper& operator = (const cl_type &rhs) + { + if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } + object_ = rhs; + referenceCountable_ = isReferenceCountable(object_); + return *this; + } + + cl_type operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + template + friend inline cl_int getInfoHelper(Func, cl_uint, VECTOR_CLASS*, int, typename U::cl_type); + + cl_int retain() const + { + if( referenceCountable_ ) { + return ReferenceHandler::retain(object_); + } + else { + return CL_SUCCESS; + } + } + + cl_int release() const + { + if( referenceCountable_ ) { + return ReferenceHandler::release(object_); + } + else { + return CL_SUCCESS; + } + } +}; + +} // namespace detail +//! \endcond + +/*! \stuct ImageFormat + * \brief Adds constructors and member functions for cl_image_format. + * + * \see cl_image_format + */ +struct ImageFormat : public cl_image_format +{ + //! \brief Default constructor - performs no initialization. + ImageFormat(){} + + //! \brief Initializing constructor. + ImageFormat(cl_channel_order order, cl_channel_type type) + { + image_channel_order = order; + image_channel_data_type = type; + } + + //! \brief Assignment operator. + ImageFormat& operator = (const ImageFormat& rhs) + { + if (this != &rhs) { + this->image_channel_data_type = rhs.image_channel_data_type; + this->image_channel_order = rhs.image_channel_order; + } + return *this; + } +}; + +/*! \brief Class interface for cl_device_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_device_id + */ +class Device : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Device() : detail::Wrapper() { } + + /*! \brief Constructor from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + __CL_EXPLICIT_CONSTRUCTORS Device(const cl_device_id &device) : detail::Wrapper(device) { } + + /*! \brief Returns the first device on the default context. + * + * \see Context::getDefault() + */ + static Device getDefault(cl_int * err = NULL); + + /*! \brief Assignment operator from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + Device& operator = (const cl_device_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device(const Device& dev) : detail::Wrapper(dev) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (const Device &dev) + { + detail::Wrapper::operator=(dev); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Device(Device&& dev) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(dev)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (Device &&dev) + { + detail::Wrapper::operator=(std::move(dev)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetDeviceInfo(). + template + cl_int getInfo(cl_device_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetDeviceInfo, object_, name, param), + __GET_DEVICE_INFO_ERR); + } + + //! \brief Wrapper for clGetDeviceInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_device_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /** + * CL 1.2 version + */ +#if defined(CL_VERSION_1_2) + //! \brief Wrapper for clCreateSubDevicesEXT(). + cl_int createSubDevices( + const cl_device_partition_property * properties, + VECTOR_CLASS* devices) + { + cl_uint n = 0; + cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = clCreateSubDevices(object_, properties, n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } +#endif // #if defined(CL_VERSION_1_2) + +/** + * CL 1.1 version that uses device fission. + */ +#if defined(CL_VERSION_1_1) +#if defined(USE_CL_DEVICE_FISSION) + cl_int createSubDevices( + const cl_device_partition_property_ext * properties, + VECTOR_CLASS* devices) + { + typedef CL_API_ENTRY cl_int + ( CL_API_CALL * PFN_clCreateSubDevicesEXT)( + cl_device_id /*in_device*/, + const cl_device_partition_property_ext * /* properties */, + cl_uint /*num_entries*/, + cl_device_id * /*out_devices*/, + cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL; + __INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT); + + cl_uint n = 0; + cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } +#endif // #if defined(USE_CL_DEVICE_FISSION) +#endif // #if defined(CL_VERSION_1_1) +}; + +/*! \brief Class interface for cl_platform_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_platform_id + */ +class Platform : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Platform() : detail::Wrapper() { } + + /*! \brief Constructor from cl_platform_id. + * + * This simply copies the platform ID value, which is an inexpensive operation. + */ + __CL_EXPLICIT_CONSTRUCTORS Platform(const cl_platform_id &platform) : detail::Wrapper(platform) { } + + /*! \brief Assignment operator from cl_platform_id. + * + * This simply copies the platform ID value, which is an inexpensive operation. + */ + Platform& operator = (const cl_platform_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetPlatformInfo(). + cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetPlatformInfo, object_, name, param), + __GET_PLATFORM_INFO_ERR); + } + + //! \brief Wrapper for clGetPlatformInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_platform_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of devices for this platform. + * + * Wraps clGetDeviceIDs(). + */ + cl_int getDevices( + cl_device_type type, + VECTOR_CLASS* devices) const + { + cl_uint n = 0; + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n); + if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + if (n > 0) { + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = ::clGetDeviceIDs(object_, type, n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + devices->assign(&ids[0], &ids[n]); + } else { + devices->clear(); + } + + return CL_SUCCESS; + } + +#if defined(USE_DX_INTEROP) + /*! \brief Get the list of available D3D10 devices. + * + * \param d3d_device_source. + * + * \param d3d_object. + * + * \param d3d_device_set. + * + * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device + * values returned in devices can be used to identify a specific OpenCL + * device. If \a devices argument is NULL, this argument is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * + * The application can query specific capabilities of the OpenCL device(s) + * returned by cl::getDevices. This can be used by the application to + * determine which device(s) to use. + * + * \note In the case that exceptions are enabled and a return value + * other than CL_SUCCESS is generated, then cl::Error exception is + * generated. + */ + cl_int getDevices( + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + VECTOR_CLASS* devices) const + { + typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)( + cl_platform_id platform, + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint* num_devices); + + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + + static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL; + __INIT_CL_EXT_FCN_PTR_PLATFORM(object_, clGetDeviceIDsFromD3D10KHR); + + cl_uint n = 0; + cl_int err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + 0, + NULL, + &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + n, + ids, + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + devices->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } +#endif + + /*! \brief Gets a list of available platforms. + * + * Wraps clGetPlatformIDs(). + */ + static cl_int get( + VECTOR_CLASS* platforms) + { + cl_uint n = 0; + + if( platforms == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); + } + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + cl_platform_id* ids = (cl_platform_id*) alloca( + n * sizeof(cl_platform_id)); + err = ::clGetPlatformIDs(n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + platforms->assign(&ids[0], &ids[n]); + return CL_SUCCESS; + } + + /*! \brief Gets the first available platform. + * + * Wraps clGetPlatformIDs(), returning the first result. + */ + static cl_int get( + Platform * platform) + { + cl_uint n = 0; + + if( platform == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); + } + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + cl_platform_id* ids = (cl_platform_id*) alloca( + n * sizeof(cl_platform_id)); + err = ::clGetPlatformIDs(n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + *platform = ids[0]; + return CL_SUCCESS; + } + + /*! \brief Gets the first available platform, returning it by value. + * + * Wraps clGetPlatformIDs(), returning the first result. + */ + static Platform get( + cl_int * errResult = NULL) + { + Platform platform; + cl_uint n = 0; + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + if (errResult != NULL) { + *errResult = err; + } + return Platform(); + } + + cl_platform_id* ids = (cl_platform_id*) alloca( + n * sizeof(cl_platform_id)); + err = ::clGetPlatformIDs(n, ids, NULL); + + if (err != CL_SUCCESS) { + detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + if (errResult != NULL) { + *errResult = err; + } + return Platform(); + } + + + return Platform(ids[0]); + } + + static Platform getDefault( + cl_int *errResult = NULL ) + { + return get(errResult); + } + + +#if defined(CL_VERSION_1_2) + //! \brief Wrapper for clUnloadCompiler(). + cl_int + unloadCompiler() + { + return ::clUnloadPlatformCompiler(object_); + } +#endif // #if defined(CL_VERSION_1_2) +}; // class Platform + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) +/** + * Unload the OpenCL compiler. + * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead. + */ +inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int +UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +inline cl_int +UnloadCompiler() +{ + return ::clUnloadCompiler(); +} +#endif // #if defined(CL_VERSION_1_1) + +/*! \brief Class interface for cl_context. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_context as the original. For details, see + * clRetainContext() and clReleaseContext(). + * + * \see cl_context + */ +class Context + : public detail::Wrapper +{ +private: + +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + static std::atomic default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static volatile int default_initialized_; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static Context default_; + static volatile cl_int default_error_; +public: + /*! \brief Constructs a context including a list of specified devices. + * + * Wraps clCreateContext(). + */ + Context( + const VECTOR_CLASS& devices, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + ::size_t, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + ::size_t numDevices = devices.size(); + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateContext( + properties, (cl_uint) numDevices, + deviceIDs, + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + Context( + const Device& device, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + ::size_t, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + cl_device_id deviceID = device(); + + object_ = ::clCreateContext( + properties, 1, + &deviceID, + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a context including all or a subset of devices of a specified type. + * + * Wraps clCreateContextFromType(). + */ + Context( + cl_device_type type, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + ::size_t, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + +#if !defined(__APPLE__) && !defined(__MACOS) + cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 }; + + if (properties == NULL) { + // Get a valid platform ID as we cannot send in a blank one + VECTOR_CLASS platforms; + error = Platform::get(&platforms); + if (error != CL_SUCCESS) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + // Check the platforms we found for a device of our specified type + cl_context_properties platform_id = 0; + for (unsigned int i = 0; i < platforms.size(); i++) { + + VECTOR_CLASS devices; + +#if defined(__CL_ENABLE_EXCEPTIONS) + try { +#endif + + error = platforms[i].getDevices(type, &devices); + +#if defined(__CL_ENABLE_EXCEPTIONS) + } catch (Error) {} + // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type + // We do error checking next anyway, and can throw there if needed +#endif + + // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND + if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + if (devices.size() > 0) { + platform_id = (cl_context_properties)platforms[i](); + break; + } + } + + if (platform_id == 0) { + detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = CL_DEVICE_NOT_FOUND; + } + return; + } + + prop[1] = platform_id; + properties = &prop[0]; + } +#endif + object_ = ::clCreateContextFromType( + properties, type, notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context(const Context& ctx) : detail::Wrapper(ctx) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (const Context &ctx) + { + detail::Wrapper::operator=(ctx); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Context(Context&& ctx) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(ctx)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (Context &&ctx) + { + detail::Wrapper::operator=(std::move(ctx)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT. + * + * \note All calls to this function return the same cl_context as the first. + */ + static Context getDefault(cl_int * err = NULL) + { + int state = detail::compare_exchange( + &default_initialized_, + __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED); + + if (state & __DEFAULT_INITIALIZED) { + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + if (state & __DEFAULT_BEING_INITIALIZED) { + // Assume writes will propagate eventually... + while(default_initialized_ != __DEFAULT_INITIALIZED) { + detail::fence(); + } + + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + cl_int error; + default_ = Context( + CL_DEVICE_TYPE_DEFAULT, + NULL, + NULL, + NULL, + &error); + + detail::fence(); + + default_error_ = error; + // Assume writes will propagate eventually... + default_initialized_ = __DEFAULT_INITIALIZED; + + detail::fence(); + + if (err != NULL) { + *err = default_error_; + } + return default_; + + } + + //! \brief Default constructor - initializes to NULL. + Context() : detail::Wrapper() { } + + /*! \brief Constructor from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_context + * into the new Context object. + */ + __CL_EXPLICIT_CONSTRUCTORS Context(const cl_context& context) : detail::Wrapper(context) { } + + /*! \brief Assignment operator from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseContext() on the value previously held by this instance. + */ + Context& operator = (const cl_context& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetContextInfo(). + template + cl_int getInfo(cl_context_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetContextInfo, object_, name, param), + __GET_CONTEXT_INFO_ERR); + } + + //! \brief Wrapper for clGetContextInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_context_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of supported image formats. + * + * Wraps clGetSupportedImageFormats(). + */ + cl_int getSupportedImageFormats( + cl_mem_flags flags, + cl_mem_object_type type, + VECTOR_CLASS* formats) const + { + cl_uint numEntries; + + if (!formats) { + return CL_SUCCESS; + } + + cl_int err = ::clGetSupportedImageFormats( + object_, + flags, + type, + 0, + NULL, + &numEntries); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + if (numEntries > 0) { + ImageFormat* value = (ImageFormat*) + alloca(numEntries * sizeof(ImageFormat)); + err = ::clGetSupportedImageFormats( + object_, + flags, + type, + numEntries, + (cl_image_format*)value, + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + formats->assign(&value[0], &value[numEntries]); + } + else { + formats->clear(); + } + return CL_SUCCESS; + } +}; + +inline Device Device::getDefault(cl_int * err) +{ + cl_int error; + Device device; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + device = context.getInfo()[0]; + if (err != NULL) { + *err = CL_SUCCESS; + } + } + + return device; +} + + +#ifdef _WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) std::atomic Context::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) Context Context::default_; +__declspec(selectany) volatile cl_int Context::default_error_ = CL_SUCCESS; +#else // !_WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) std::atomic Context::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) Context Context::default_; +__attribute__((weak)) volatile cl_int Context::default_error_ = CL_SUCCESS; +#endif // !_WIN32 + +/*! \brief Class interface for cl_event. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_event as the original. For details, see + * clRetainEvent() and clReleaseEvent(). + * + * \see cl_event + */ +class Event : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Event() : detail::Wrapper() { } + + /*! \brief Constructor from cl_event - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_event + * into the new Event object. + */ + __CL_EXPLICIT_CONSTRUCTORS Event(const cl_event& event) : detail::Wrapper(event) { } + + /*! \brief Assignment operator from cl_event - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseEvent() on the value previously held by this instance. + */ + Event& operator = (const cl_event& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetEventInfo(). + template + cl_int getInfo(cl_event_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetEventInfo, object_, name, param), + __GET_EVENT_INFO_ERR); + } + + //! \brief Wrapper for clGetEventInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_event_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + //! \brief Wrapper for clGetEventProfilingInfo(). + template + cl_int getProfilingInfo(cl_profiling_info name, T* param) const + { + return detail::errHandler(detail::getInfo( + &::clGetEventProfilingInfo, object_, name, param), + __GET_EVENT_PROFILE_INFO_ERR); + } + + //! \brief Wrapper for clGetEventProfilingInfo() that returns by value. + template typename + detail::param_traits::param_type + getProfilingInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_profiling_info, name>::param_type param; + cl_int result = getProfilingInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Blocks the calling thread until this event completes. + * + * Wraps clWaitForEvents(). + */ + cl_int wait() const + { + return detail::errHandler( + ::clWaitForEvents(1, &object_), + __WAIT_FOR_EVENTS_ERR); + } + +#if defined(CL_VERSION_1_1) + /*! \brief Registers a user callback function for a specific command execution status. + * + * Wraps clSetEventCallback(). + */ + cl_int setCallback( + cl_int type, + void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetEventCallback( + object_, + type, + pfn_notify, + user_data), + __SET_EVENT_CALLBACK_ERR); + } +#endif + + /*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ + static cl_int + waitForEvents(const VECTOR_CLASS& events) + { + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); + } +}; + +#if defined(CL_VERSION_1_1) +/*! \brief Class interface for user events (a subset of cl_event's). + * + * See Event for details about copy semantics, etc. + */ +class UserEvent : public Event +{ +public: + /*! \brief Constructs a user event on a given context. + * + * Wraps clCreateUserEvent(). + */ + UserEvent( + const Context& context, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateUserEvent( + context(), + &error); + + detail::errHandler(error, __CREATE_USER_EVENT_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + UserEvent() : Event() { } + + /*! \brief Sets the execution status of a user event object. + * + * Wraps clSetUserEventStatus(). + */ + cl_int setStatus(cl_int status) + { + return detail::errHandler( + ::clSetUserEventStatus(object_,status), + __SET_USER_EVENT_STATUS_ERR); + } +}; +#endif + +/*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ +inline static cl_int +WaitForEvents(const VECTOR_CLASS& events) +{ + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); +} + +/*! \brief Class interface for cl_mem. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_mem as the original. For details, see + * clRetainMemObject() and clReleaseMemObject(). + * + * \see cl_mem + */ +class Memory : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Memory() : detail::Wrapper() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_mem + * into the new Memory object. + */ + __CL_EXPLICIT_CONSTRUCTORS Memory(const cl_mem& memory) : detail::Wrapper(memory) { } + + /*! \brief Assignment operator from cl_mem - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseMemObject() on the value previously held by this instance. + */ + Memory& operator = (const cl_mem& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory(const Memory& mem) : detail::Wrapper(mem) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (const Memory &mem) + { + detail::Wrapper::operator=(mem); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory(Memory&& mem) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(mem)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (Memory &&mem) + { + detail::Wrapper::operator=(std::move(mem)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetMemObjectInfo(). + template + cl_int getInfo(cl_mem_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetMemObjectInfo, object_, name, param), + __GET_MEM_OBJECT_INFO_ERR); + } + + //! \brief Wrapper for clGetMemObjectInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_mem_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if defined(CL_VERSION_1_1) + /*! \brief Registers a callback function to be called when the memory object + * is no longer needed. + * + * Wraps clSetMemObjectDestructorCallback(). + * + * Repeated calls to this function, for a given cl_mem value, will append + * to the list of functions called (in reverse order) when memory object's + * resources are freed and the memory object is deleted. + * + * \note + * The registered callbacks are associated with the underlying cl_mem + * value - not the Memory class instance. + */ + cl_int setDestructorCallback( + void (CL_CALLBACK * pfn_notify)(cl_mem, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetMemObjectDestructorCallback( + object_, + pfn_notify, + user_data), + __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR); + } +#endif + +}; + +// Pre-declare copy functions +class Buffer; +template< typename IteratorType > +cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); + + +/*! \brief Class interface for Buffer Memory Objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Buffer : public Memory +{ +public: + + /*! \brief Constructs a Buffer in a specified context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + */ + Buffer( + const Context& context, + cl_mem_flags flags, + ::size_t size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a Buffer in the default context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + * + * \see Context::getDefault() + */ + Buffer( + cl_mem_flags flags, + ::size_t size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(err); + + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer( + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr = false, + cl_int* err = NULL) + { + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + ::size_t size = sizeof(DataType)*(endIterator - startIterator); + + Context context = Context::getDefault(err); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + error = cl::copy(startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified context. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified queue. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Buffer() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Buffer(const cl_mem& buffer) : Memory(buffer) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Buffer& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer(const Buffer& buf) : Memory(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (const Buffer &buf) + { + Memory::operator=(buf); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer(Buffer&& buf) CL_HPP_NOEXCEPT : Memory(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (Buffer &&buf) + { + Memory::operator=(std::move(buf)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + +#if defined(CL_VERSION_1_1) + /*! \brief Creates a new buffer object from this. + * + * Wraps clCreateSubBuffer(). + */ + Buffer createSubBuffer( + cl_mem_flags flags, + cl_buffer_create_type buffer_create_type, + const void * buffer_create_info, + cl_int * err = NULL) + { + Buffer result; + cl_int error; + result.object_ = ::clCreateSubBuffer( + object_, + flags, + buffer_create_type, + buffer_create_info, + &error); + + detail::errHandler(error, __CREATE_SUBBUFFER_ERR); + if (err != NULL) { + *err = error; + } + + return result; + } +#endif +}; + +#if defined (USE_DX_INTEROP) +/*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's. + * + * This is provided to facilitate interoperability with Direct3D. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferD3D10 : public Buffer +{ +public: + typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)( + cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer, + cl_int* errcode_ret); + + /*! \brief Constructs a BufferD3D10, in a specified context, from a + * given ID3D10Buffer. + * + * Wraps clCreateFromD3D10BufferKHR(). + */ + BufferD3D10( + const Context& context, + cl_mem_flags flags, + ID3D10Buffer* bufobj, + cl_int * err = NULL) + { + static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL; + +#if defined(CL_VERSION_1_2) + vector props = context.getInfo(); + cl_platform platform = -1; + for( int i = 0; i < props.size(); ++i ) { + if( props[i] == CL_CONTEXT_PLATFORM ) { + platform = props[i+1]; + } + } + __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clCreateFromD3D10BufferKHR); +#endif +#if defined(CL_VERSION_1_1) + __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR); +#endif + + cl_int error; + object_ = pfn_clCreateFromD3D10BufferKHR( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferD3D10() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS BufferD3D10(const cl_mem& buffer) : Buffer(buffer) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferD3D10& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(const BufferD3D10& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (const BufferD3D10 &buf) + { + Buffer::operator=(buf); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (BufferD3D10 &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif + +/*! \brief Class interface for GL Buffer Memory Objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferGL : public Buffer +{ +public: + /*! \brief Constructs a BufferGL in a specified context, from a given + * GL buffer. + * + * Wraps clCreateFromGLBuffer(). + */ + BufferGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLBuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferGL() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS BufferGL(const cl_mem& buffer) : Buffer(buffer) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferGL& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL(const BufferGL& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (const BufferGL &buf) + { + Buffer::operator=(buf); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (BufferGL &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_,type,gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief C++ base class for Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image : public Memory +{ +protected: + //! \brief Default constructor - initializes to NULL. + Image() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image(const cl_mem& image) : Memory(image) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image(const Image& img) : Memory(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (const Image &img) + { + Memory::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image(Image&& img) CL_HPP_NOEXCEPT : Memory(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (Image &&img) + { + Memory::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + +public: + //! \brief Wrapper for clGetImageInfo(). + template + cl_int getImageInfo(cl_image_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetImageInfo, object_, name, param), + __GET_IMAGE_INFO_ERR); + } + + //! \brief Wrapper for clGetImageInfo() that returns by value. + template typename + detail::param_traits::param_type + getImageInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_image_info, name>::param_type param; + cl_int result = getImageInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +#if defined(CL_VERSION_1_2) +/*! \brief Class interface for 1D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image1D : public Image +{ +public: + /*! \brief Constructs a 1D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image1D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D, + width, + 0, 0, 0, 0, 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image1D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image1D(const cl_mem& image1D) : Image(image1D) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image1D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D(const Image1D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (const Image1D &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D(Image1D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (Image1D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + +/*! \class Image1DBuffer + * \brief Image interface for 1D buffer images. + */ +class Image1DBuffer : public Image +{ +public: + Image1DBuffer( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + const Buffer &buffer, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_BUFFER, + width, + 0, 0, 0, 0, 0, 0, 0, + buffer() + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + NULL, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DBuffer() { } + + __CL_EXPLICIT_CONSTRUCTORS Image1DBuffer(const cl_mem& image1D) : Image(image1D) { } + + Image1DBuffer& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(const Image1DBuffer& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (const Image1DBuffer &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (Image1DBuffer &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + +/*! \class Image1DArray + * \brief Image interface for arrays of 1D images. + */ +class Image1DArray : public Image +{ +public: + Image1DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t arraySize, + ::size_t width, + ::size_t rowPitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_ARRAY, + width, + 0, 0, // height, depth (unused) + arraySize, + rowPitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DArray() { } + + __CL_EXPLICIT_CONSTRUCTORS Image1DArray(const cl_mem& imageArray) : Image(imageArray) { } + + Image1DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(const Image1DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (const Image1DArray &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (Image1DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if defined(CL_VERSION_1_2) + + +/*! \brief Class interface for 2D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image2D : public Image +{ +public: + /*! \brief Constructs a 1D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image2D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + ::size_t height, + ::size_t row_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif defined(CL_VERSION_1_2) + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if defined(CL_VERSION_1_2) + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D, + width, + height, + 0, 0, // depth, array size (unused) + row_pitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if defined(CL_VERSION_1_2) +#if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + if (!useCreateImage) + { + object_ = ::clCreateImage2D( + context(), flags,&format, width, height, row_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE2D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + } + + //! \brief Default constructor - initializes to NULL. + Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image2D(const cl_mem& image2D) : Image(image2D) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image2D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D(const Image2D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (const Image2D &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D(Image2D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (Image2D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + + +#if !defined(CL_VERSION_1_2) +/*! \brief Class interface for GL 2D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + * \note Deprecated for OpenCL 1.2. Please use ImageGL instead. + */ +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED : public Image2D +{ +public: + /*! \brief Constructs an Image2DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture2D(). + */ + Image2DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture2D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR); + if (err != NULL) { + *err = error; + } + + } + + //! \brief Default constructor - initializes to NULL. + Image2DGL() : Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image2DGL(const cl_mem& image) : Image2D(image) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image2DGL& operator = (const cl_mem& rhs) + { + Image2D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(const Image2DGL& img) : Image2D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (const Image2DGL &img) + { + Image2D::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT : Image2D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (Image2DGL &&img) + { + Image2D::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if !defined(CL_VERSION_1_2) + +#if defined(CL_VERSION_1_2) +/*! \class Image2DArray + * \brief Image interface for arrays of 2D images. + */ +class Image2DArray : public Image +{ +public: + Image2DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t arraySize, + ::size_t width, + ::size_t height, + ::size_t rowPitch, + ::size_t slicePitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D_ARRAY, + width, + height, + 0, // depth (unused) + arraySize, + rowPitch, + slicePitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image2DArray() { } + + __CL_EXPLICIT_CONSTRUCTORS Image2DArray(const cl_mem& imageArray) : Image(imageArray) { } + + Image2DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(const Image2DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (const Image2DArray &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (Image2DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if defined(CL_VERSION_1_2) + +/*! \brief Class interface for 3D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3D : public Image +{ +public: + /*! \brief Constructs a 3D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image3D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + ::size_t width, + ::size_t height, + ::size_t depth, + ::size_t row_pitch = 0, + ::size_t slice_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif defined(CL_VERSION_1_2) + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if defined(CL_VERSION_1_2) + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE3D, + width, + height, + depth, + 0, // array size (unused) + row_pitch, + slice_pitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if defined(CL_VERSION_1_2) +#if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + if (!useCreateImage) + { + object_ = ::clCreateImage3D( + context(), flags, &format, width, height, depth, row_pitch, + slice_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE3D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + } + + //! \brief Default constructor - initializes to NULL. + Image3D() : Image() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image3D(const cl_mem& image3D) : Image(image3D) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D(const Image3D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (const Image3D &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D(Image3D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (Image3D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; + +#if !defined(CL_VERSION_1_2) +/*! \brief Class interface for GL 3D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3DGL : public Image3D +{ +public: + /*! \brief Constructs an Image3DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture3D(). + */ + Image3DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture3D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image3DGL() : Image3D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ + __CL_EXPLICIT_CONSTRUCTORS Image3DGL(const cl_mem& image) : Image3D(image) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3DGL& operator = (const cl_mem& rhs) + { + Image3D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(const Image3DGL& img) : Image3D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (const Image3DGL &img) + { + Image3D::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT : Image3D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (Image3DGL &&img) + { + Image3D::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if !defined(CL_VERSION_1_2) + +#if defined(CL_VERSION_1_2) +/*! \class ImageGL + * \brief general image interface for GL interop. + * We abstract the 2D and 3D GL images into a single instance here + * that wraps all GL sourced images on the grounds that setup information + * was performed by OpenCL anyway. + */ +class ImageGL : public Image +{ +public: + ImageGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_ERR); + if (err != NULL) { + *err = error; + } + } + + ImageGL() : Image() { } + + __CL_EXPLICIT_CONSTRUCTORS ImageGL(const cl_mem& image) : Image(image) { } + + ImageGL& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL(const ImageGL& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (const ImageGL &img) + { + Image::operator=(img); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (ImageGL &&img) + { + Image::operator=(std::move(img)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) +}; +#endif // #if defined(CL_VERSION_1_2) + +/*! \brief Class interface for GL Render Buffer Memory Objects. +* +* This is provided to facilitate interoperability with OpenGL. +* +* See Memory for details about copy semantics, etc. +* +* \see Memory +*/ +class BufferRenderGL : +#if defined(CL_VERSION_1_2) + public ImageGL +#else // #if defined(CL_VERSION_1_2) + public Image2DGL +#endif //#if defined(CL_VERSION_1_2) +{ +public: + /*! \brief Constructs a BufferRenderGL in a specified context, from a given + * GL Renderbuffer. + * + * Wraps clCreateFromGLRenderbuffer(). + */ + BufferRenderGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLRenderbuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. +#if defined(CL_VERSION_1_2) + BufferRenderGL() : ImageGL() {}; +#else // #if defined(CL_VERSION_1_2) + BufferRenderGL() : Image2DGL() {}; +#endif //#if defined(CL_VERSION_1_2) + + /*! \brief Constructor from cl_mem - takes ownership. + * + * See Memory for further details. + */ +#if defined(CL_VERSION_1_2) + __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : ImageGL(buffer) { } +#else // #if defined(CL_VERSION_1_2) + __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : Image2DGL(buffer) { } +#endif //#if defined(CL_VERSION_1_2) + + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferRenderGL& operator = (const cl_mem& rhs) + { +#if defined(CL_VERSION_1_2) + ImageGL::operator=(rhs); +#else // #if defined(CL_VERSION_1_2) + Image2DGL::operator=(rhs); +#endif //#if defined(CL_VERSION_1_2) + + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ +#if defined(CL_VERSION_1_2) + BufferRenderGL(const BufferRenderGL& buf) : ImageGL(buf) {} +#else // #if defined(CL_VERSION_1_2) + BufferRenderGL(const BufferRenderGL& buf) : Image2DGL(buf) {} +#endif //#if defined(CL_VERSION_1_2) + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (const BufferRenderGL &rhs) + { +#if defined(CL_VERSION_1_2) + ImageGL::operator=(rhs); +#else // #if defined(CL_VERSION_1_2) + Image2DGL::operator=(rhs); +#endif //#if defined(CL_VERSION_1_2) + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ +#if defined(CL_VERSION_1_2) + BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : ImageGL(std::move(buf)) {} +#else // #if defined(CL_VERSION_1_2) + BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : Image2DGL(std::move(buf)) {} +#endif //#if defined(CL_VERSION_1_2) + + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (BufferRenderGL &&buf) + { +#if defined(CL_VERSION_1_2) + ImageGL::operator=(std::move(buf)); +#else // #if defined(CL_VERSION_1_2) + Image2DGL::operator=(std::move(buf)); +#endif //#if defined(CL_VERSION_1_2) + + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_, type, gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief Class interface for cl_sampler. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_sampler as the original. For details, see + * clRetainSampler() and clReleaseSampler(). + * + * \see cl_sampler + */ +class Sampler : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Sampler() { } + + /*! \brief Constructs a Sampler in a specified context. + * + * Wraps clCreateSampler(). + */ + Sampler( + const Context& context, + cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateSampler( + context(), + normalized_coords, + addressing_mode, + filter_mode, + &error); + + detail::errHandler(error, __CREATE_SAMPLER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructor from cl_sampler - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_sampler + * into the new Sampler object. + */ + __CL_EXPLICIT_CONSTRUCTORS Sampler(const cl_sampler& sampler) : detail::Wrapper(sampler) { } + + /*! \brief Assignment operator from cl_sampler - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseSampler() on the value previously held by this instance. + */ + Sampler& operator = (const cl_sampler& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler(const Sampler& sam) : detail::Wrapper(sam) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (const Sampler &sam) + { + detail::Wrapper::operator=(sam); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler(Sampler&& sam) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(sam)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (Sampler &&sam) + { + detail::Wrapper::operator=(std::move(sam)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + //! \brief Wrapper for clGetSamplerInfo(). + template + cl_int getInfo(cl_sampler_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetSamplerInfo, object_, name, param), + __GET_SAMPLER_INFO_ERR); + } + + //! \brief Wrapper for clGetSamplerInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_sampler_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +class Program; +class CommandQueue; +class Kernel; + +//! \brief Class interface for specifying NDRange values. +class NDRange +{ +private: + size_t<3> sizes_; + cl_uint dimensions_; + +public: + //! \brief Default constructor - resulting range has zero dimensions. + NDRange() + : dimensions_(0) + { } + + //! \brief Constructs one-dimensional range. + NDRange(::size_t size0) + : dimensions_(1) + { + sizes_[0] = size0; + } + + //! \brief Constructs two-dimensional range. + NDRange(::size_t size0, ::size_t size1) + : dimensions_(2) + { + sizes_[0] = size0; + sizes_[1] = size1; + } + + //! \brief Constructs three-dimensional range. + NDRange(::size_t size0, ::size_t size1, ::size_t size2) + : dimensions_(3) + { + sizes_[0] = size0; + sizes_[1] = size1; + sizes_[2] = size2; + } + + /*! \brief Conversion operator to const ::size_t *. + * + * \returns a pointer to the size of the first dimension. + */ + operator const ::size_t*() const { + return (const ::size_t*) sizes_; + } + + //! \brief Queries the number of dimensions in the range. + ::size_t dimensions() const { return dimensions_; } +}; + +//! \brief A zero-dimensional range. +static const NDRange NullRange; + +//! \brief Local address wrapper for use with Kernel::setArg +struct LocalSpaceArg +{ + ::size_t size_; +}; + +namespace detail { + +template +struct KernelArgumentHandler +{ + static ::size_t size(const T&) { return sizeof(T); } + static const T* ptr(const T& value) { return &value; } +}; + +template <> +struct KernelArgumentHandler +{ + static ::size_t size(const LocalSpaceArg& value) { return value.size_; } + static const void* ptr(const LocalSpaceArg&) { return NULL; } +}; + +} +//! \endcond + +/*! __local + * \brief Helper function for generating LocalSpaceArg objects. + * Deprecated. Replaced with Local. + */ +inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED LocalSpaceArg +__local(::size_t size) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +inline LocalSpaceArg +__local(::size_t size) +{ + LocalSpaceArg ret = { size }; + return ret; +} + +/*! Local + * \brief Helper function for generating LocalSpaceArg objects. + */ +inline LocalSpaceArg +Local(::size_t size) +{ + LocalSpaceArg ret = { size }; + return ret; +} + +//class KernelFunctor; + +/*! \brief Class interface for cl_kernel. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_kernel as the original. For details, see + * clRetainKernel() and clReleaseKernel(). + * + * \see cl_kernel + */ +class Kernel : public detail::Wrapper +{ +public: + inline Kernel(const Program& program, const char* name, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Kernel() { } + + /*! \brief Constructor from cl_kernel - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_kernel + * into the new Kernel object. + */ + __CL_EXPLICIT_CONSTRUCTORS Kernel(const cl_kernel& kernel) : detail::Wrapper(kernel) { } + + /*! \brief Assignment operator from cl_kernel - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseKernel() on the value previously held by this instance. + */ + Kernel& operator = (const cl_kernel& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel(const Kernel& kernel) : detail::Wrapper(kernel) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (const Kernel &kernel) + { + detail::Wrapper::operator=(kernel); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(kernel)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (Kernel &&kernel) + { + detail::Wrapper::operator=(std::move(kernel)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + template + cl_int getInfo(cl_kernel_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelInfo, object_, name, param), + __GET_KERNEL_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if defined(CL_VERSION_1_2) + template + cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param), + __GET_KERNEL_ARG_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getArgInfo(cl_uint argIndex, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_arg_info, name>::param_type param; + cl_int result = getArgInfo(argIndex, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +#endif // #if defined(CL_VERSION_1_2) + + template + cl_int getWorkGroupInfo( + const Device& device, cl_kernel_work_group_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetKernelWorkGroupInfo, object_, device(), name, param), + __GET_KERNEL_WORK_GROUP_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getWorkGroupInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_work_group_info, name>::param_type param; + cl_int result = getWorkGroupInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + template + cl_int setArg(cl_uint index, const T &value) + { + return detail::errHandler( + ::clSetKernelArg( + object_, + index, + detail::KernelArgumentHandler::size(value), + detail::KernelArgumentHandler::ptr(value)), + __SET_KERNEL_ARGS_ERR); + } + + cl_int setArg(cl_uint index, ::size_t size, const void* argPtr) + { + return detail::errHandler( + ::clSetKernelArg(object_, index, size, argPtr), + __SET_KERNEL_ARGS_ERR); + } +}; + +/*! \class Program + * \brief Program interface that implements cl_program. + */ +class Program : public detail::Wrapper +{ +public: + typedef VECTOR_CLASS > Binaries; + typedef VECTOR_CLASS > Sources; + + Program( + const STRING_CLASS& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const ::size_t length = source.size(); + + Context context = Context::getDefault(err); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + + error = ::clBuildProgram( + object_, + 0, + NULL, + "", + NULL, + NULL); + + detail::errHandler(error, __BUILD_PROGRAM_ERR); + } + + if (err != NULL) { + *err = error; + } + } + + Program( + const Context& context, + const STRING_CLASS& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const ::size_t length = source.size(); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + + error = ::clBuildProgram( + object_, + 0, + NULL, + "", + NULL, + NULL); + + detail::errHandler(error, __BUILD_PROGRAM_ERR); + } + + if (err != NULL) { + *err = error; + } + } + + Program( + const Context& context, + const Sources& sources, + cl_int* err = NULL) + { + cl_int error; + + const ::size_t n = (::size_t)sources.size(); + ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t)); + const char** strings = (const char**) alloca(n * sizeof(const char*)); + + for (::size_t i = 0; i < n; ++i) { + strings[i] = sources[(int)i].first; + lengths[i] = sources[(int)i].second; + } + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)n, strings, lengths, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + if (err != NULL) { + *err = error; + } + } + + /** + * Construct a program object from a list of devices and a per-device list of binaries. + * \param context A valid OpenCL context in which to construct the program. + * \param devices A vector of OpenCL device objects for which the program will be created. + * \param binaries A vector of pairs of a pointer to a binary object and its length. + * \param binaryStatus An optional vector that on completion will be resized to + * match the size of binaries and filled with values to specify if each binary + * was successfully loaded. + * Set to CL_SUCCESS if the binary was successfully loaded. + * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL. + * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device. + * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors: + * CL_INVALID_CONTEXT if context is not a valid context. + * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices; + * or if any entry in binaries is NULL or has length 0. + * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context. + * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device. + * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host. + */ + Program( + const Context& context, + const VECTOR_CLASS& devices, + const Binaries& binaries, + VECTOR_CLASS* binaryStatus = NULL, + cl_int* err = NULL) + { + cl_int error; + + const ::size_t numDevices = devices.size(); + + // Catch size mismatch early and return + if(binaries.size() != numDevices) { + error = CL_INVALID_VALUE; + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + ::size_t* lengths = (::size_t*) alloca(numDevices * sizeof(::size_t)); + const unsigned char** images = (const unsigned char**) alloca(numDevices * sizeof(const unsigned char**)); + + for (::size_t i = 0; i < numDevices; ++i) { + images[i] = (const unsigned char*)binaries[i].first; + lengths[i] = binaries[(int)i].second; + } + + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + if(binaryStatus) { + binaryStatus->resize(numDevices); + } + + object_ = ::clCreateProgramWithBinary( + context(), (cl_uint) devices.size(), + deviceIDs, + lengths, images, (binaryStatus != NULL && numDevices > 0) + ? &binaryStatus->front() + : NULL, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + } + + +#if defined(CL_VERSION_1_2) + /** + * Create program using builtin kernels. + * \param kernelNames Semi-colon separated list of builtin kernel names + */ + Program( + const Context& context, + const VECTOR_CLASS& devices, + const STRING_CLASS& kernelNames, + cl_int* err = NULL) + { + cl_int error; + + + ::size_t numDevices = devices.size(); + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateProgramWithBuiltInKernels( + context(), + (cl_uint) devices.size(), + deviceIDs, + kernelNames.c_str(), + &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // #if defined(CL_VERSION_1_2) + + Program() { } + + __CL_EXPLICIT_CONSTRUCTORS Program(const cl_program& program) : detail::Wrapper(program) { } + + Program& operator = (const cl_program& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program(const Program& program) : detail::Wrapper(program) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (const Program &program) + { + detail::Wrapper::operator=(program); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Program(Program&& program) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(program)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (Program &&program) + { + detail::Wrapper::operator=(std::move(program)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + cl_int build( + const VECTOR_CLASS& devices, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + ::size_t numDevices = devices.size(); + cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); + for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + return detail::errHandler( + ::clBuildProgram( + object_, + (cl_uint) + devices.size(), + deviceIDs, + options, + notifyFptr, + data), + __BUILD_PROGRAM_ERR); + } + + cl_int build( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + return detail::errHandler( + ::clBuildProgram( + object_, + 0, + NULL, + options, + notifyFptr, + data), + __BUILD_PROGRAM_ERR); + } + +#if defined(CL_VERSION_1_2) + cl_int compile( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + return detail::errHandler( + ::clCompileProgram( + object_, + 0, + NULL, + options, + 0, + NULL, + NULL, + notifyFptr, + data), + __COMPILE_PROGRAM_ERR); + } +#endif + + template + cl_int getInfo(cl_program_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetProgramInfo, object_, name, param), + __GET_PROGRAM_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + template + cl_int getBuildInfo( + const Device& device, cl_program_build_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetProgramBuildInfo, object_, device(), name, param), + __GET_PROGRAM_BUILD_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getBuildInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_build_info, name>::param_type param; + cl_int result = getBuildInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + cl_int createKernels(VECTOR_CLASS* kernels) + { + cl_uint numKernels; + cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel)); + err = ::clCreateKernelsInProgram( + object_, numKernels, (cl_kernel*) value, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + kernels->assign(&value[0], &value[numKernels]); + return CL_SUCCESS; + } +}; + +#if defined(CL_VERSION_1_2) +inline Program linkProgram( + Program input1, + Program input2, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + cl_program programs[2] = { input1(), input2() }; + + Context ctx = input1.getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + 2, + programs, + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog); +} + +inline Program linkProgram( + VECTOR_CLASS inputPrograms, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + cl_program * programs = (cl_program*) alloca(inputPrograms.size() * sizeof(cl_program)); + + if (programs != NULL) { + for (unsigned int i = 0; i < inputPrograms.size(); i++) { + programs[i] = inputPrograms[i](); + } + } + + Context ctx; + if(inputPrograms.size() > 0) { + ctx = inputPrograms[0].getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + } + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + (cl_uint)inputPrograms.size(), + programs, + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog); +} +#endif + +template<> +inline VECTOR_CLASS cl::Program::getInfo(cl_int* err) const +{ + VECTOR_CLASS< ::size_t> sizes = getInfo(); + VECTOR_CLASS binaries; + for (VECTOR_CLASS< ::size_t>::iterator s = sizes.begin(); s != sizes.end(); ++s) + { + char *ptr = NULL; + if (*s != 0) + ptr = new char[*s]; + binaries.push_back(ptr); + } + + cl_int result = getInfo(CL_PROGRAM_BINARIES, &binaries); + if (err != NULL) { + *err = result; + } + return binaries; +} + +inline Kernel::Kernel(const Program& program, const char* name, cl_int* err) +{ + cl_int error; + + object_ = ::clCreateKernel(program(), name, &error); + detail::errHandler(error, __CREATE_KERNEL_ERR); + + if (err != NULL) { + *err = error; + } + +} + +/*! \class CommandQueue + * \brief CommandQueue interface for cl_command_queue. + */ +class CommandQueue : public detail::Wrapper +{ +private: +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED + static std::atomic default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static volatile int default_initialized_; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED + static CommandQueue default_; + static volatile cl_int default_error_; +public: + CommandQueue( + cl_command_queue_properties properties, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } + } + } + /*! + * \brief Constructs a CommandQueue for an implementation defined device in the given context + */ + explicit CommandQueue( + const Context& context, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + VECTOR_CLASS devices; + error = context.getInfo(CL_CONTEXT_DEVICES, &devices); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) + { + if (err != NULL) { + *err = error; + } + return; + } + + object_ = ::clCreateCommandQueue(context(), devices[0](), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + + if (err != NULL) { + *err = error; + } + + } + + CommandQueue( + const Context& context, + const Device& device, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(const CommandQueue& queue) : detail::Wrapper(queue) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (const CommandQueue &queue) + { + detail::Wrapper::operator=(queue); + return *this; + } + +#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(queue)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (CommandQueue &&queue) + { + detail::Wrapper::operator=(std::move(queue)); + return *this; + } +#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) + + static CommandQueue getDefault(cl_int * err = NULL) + { + int state = detail::compare_exchange( + &default_initialized_, + __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED); + + if (state & __DEFAULT_INITIALIZED) { + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + if (state & __DEFAULT_BEING_INITIALIZED) { + // Assume writes will propagate eventually... + while(default_initialized_ != __DEFAULT_INITIALIZED) { + detail::fence(); + } + + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + + default_ = CommandQueue(context, device, 0, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } + } + + detail::fence(); + + default_error_ = error; + // Assume writes will propagate eventually... + default_initialized_ = __DEFAULT_INITIALIZED; + + detail::fence(); + + if (err != NULL) { + *err = default_error_; + } + return default_; + + } + + CommandQueue() { } + + __CL_EXPLICIT_CONSTRUCTORS CommandQueue(const cl_command_queue& commandQueue) : detail::Wrapper(commandQueue) { } + + CommandQueue& operator = (const cl_command_queue& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + template + cl_int getInfo(cl_command_queue_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetCommandQueueInfo, object_, name, param), + __GET_COMMAND_QUEUE_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_command_queue_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + ::size_t src_offset, + ::size_t dst_offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBuffer( + object_, src(), dst(), src_offset, dst_offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBufferRect( + object_, + buffer(), + blocking, + (const ::size_t *)buffer_offset, + (const ::size_t *)host_offset, + (const ::size_t *)region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + const void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBufferRect( + object_, + buffer(), + blocking, + (const ::size_t *)buffer_offset, + (const ::size_t *)host_offset, + (const ::size_t *)region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + ::size_t src_row_pitch, + ::size_t src_slice_pitch, + ::size_t dst_row_pitch, + ::size_t dst_slice_pitch, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferRect( + object_, + src(), + dst(), + (const ::size_t *)src_origin, + (const ::size_t *)dst_origin, + (const ::size_t *)region, + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_VERSION_1_2) + /** + * Enqueue a command to fill a buffer object with a pattern + * of a given size. The pattern is specified a as vector. + * \tparam PatternType The datatype of the pattern field. + * The pattern type must be an accepted OpenCL data type. + */ + template + cl_int enqueueFillBuffer( + const Buffer& buffer, + PatternType pattern, + ::size_t offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillBuffer( + object_, + buffer(), + static_cast(&pattern), + sizeof(PatternType), + offset, + size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_VERSION_1_2) + + cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadImage( + object_, image(), blocking, (const ::size_t *) origin, + (const ::size_t *) region, row_pitch, slice_pitch, ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteImage( + object_, image(), blocking, (const ::size_t *) origin, + (const ::size_t *) region, row_pitch, slice_pitch, ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImage( + object_, src(), dst(), (const ::size_t *) src_origin, + (const ::size_t *)dst_origin, (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_VERSION_1_2) + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA floating-point color value if + * the image channel data type is not an unnormalized signed or + * unsigned data type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_float4 fillColor, + const size_t<3>& origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + (const ::size_t *) origin, + (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA signed integer color value if + * the image channel data type is an unnormalized signed integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_int4 fillColor, + const size_t<3>& origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + (const ::size_t *) origin, + (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA unsigned integer color value if + * the image channel data type is an unnormalized unsigned integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_uint4 fillColor, + const size_t<3>& origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + (const ::size_t *) origin, + (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_VERSION_1_2) + + cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& region, + ::size_t dst_offset, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImageToBuffer( + object_, src(), dst(), (const ::size_t *) src_origin, + (const ::size_t *) region, dst_offset, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + ::size_t src_offset, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferToImage( + object_, src(), dst(), src_offset, + (const ::size_t *) dst_origin, (const ::size_t *) region, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + ::size_t offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapBuffer( + object_, buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + + return result; + } + + void* enqueueMapImage( + const Image& buffer, + cl_bool blocking, + cl_map_flags flags, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t * row_pitch, + ::size_t * slice_pitch, + const VECTOR_CLASS* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapImage( + object_, buffer(), blocking, flags, + (const ::size_t *) origin, (const ::size_t *) region, + row_pitch, slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + return result; + } + + cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + object_, memory(), mapped_ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_VERSION_1_2) + /** + * Enqueues a marker command which waits for either a list of events to complete, + * or all previously enqueued commands to complete. + * + * Enqueues a marker command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command returns an event which can be waited on, + * i.e. this event can be waited on to insure that all events either in the event_wait_list + * or all previously enqueued commands, queued before this command to command_queue, + * have completed. + */ + cl_int enqueueMarkerWithWaitList( + const VECTOR_CLASS *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarkerWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * A synchronization point that enqueues a barrier operation. + * + * Enqueues a barrier command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command blocks command execution, that is, any + * following commands enqueued after it do not execute until it completes. This command + * returns an event which can be waited on, i.e. this event can be waited on to insure that + * all events either in the event_wait_list or all previously enqueued commands, queued + * before this command to command_queue, have completed. + */ + cl_int enqueueBarrierWithWaitList( + const VECTOR_CLASS *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueBarrierWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_BARRIER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command to indicate with which device a set of memory objects + * should be associated. + */ + cl_int enqueueMigrateMemObjects( + const VECTOR_CLASS &memObjects, + cl_mem_migration_flags flags, + const VECTOR_CLASS* events = NULL, + Event* event = NULL + ) const + { + cl_event tmp; + + cl_mem* localMemObjects = static_cast(alloca(memObjects.size() * sizeof(cl_mem))); + for( int i = 0; i < (int)memObjects.size(); ++i ) { + localMemObjects[i] = memObjects[i](); + } + + + cl_int err = detail::errHandler( + ::clEnqueueMigrateMemObjects( + object_, + (cl_uint)memObjects.size(), + static_cast(localMemObjects), + flags, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_VERSION_1_2) + + cl_int enqueueNDRangeKernel( + const Kernel& kernel, + const NDRange& offset, + const NDRange& global, + const NDRange& local = NullRange, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNDRangeKernel( + object_, kernel(), (cl_uint) global.dimensions(), + offset.dimensions() != 0 ? (const ::size_t*) offset : NULL, + (const ::size_t*) global, + local.dimensions() != 0 ? (const ::size_t*) local : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NDRANGE_KERNEL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueTask( + const Kernel& kernel, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueTask( + object_, kernel(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_TASK_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueNativeKernel( + void (CL_CALLBACK *userFptr)(void *), + std::pair args, + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* mem_locs = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_mem * mems = (mem_objects != NULL && mem_objects->size() > 0) + ? (cl_mem*) alloca(mem_objects->size() * sizeof(cl_mem)) + : NULL; + + if (mems != NULL) { + for (unsigned int i = 0; i < mem_objects->size(); i++) { + mems[i] = ((*mem_objects)[i])(); + } + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNativeKernel( + object_, userFptr, args.first, args.second, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + mems, + (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NATIVE_KERNEL); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarker( + object_, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueWaitForEvents(const VECTOR_CLASS& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueWaitForEvents( + object_, + (cl_uint) events.size(), + events.size() > 0 ? (const cl_event*) &events.front() : NULL), + __ENQUEUE_WAIT_FOR_EVENTS_ERR); + } +#endif // #if defined(CL_VERSION_1_1) + + cl_int enqueueAcquireGLObjects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueAcquireGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseGLObjects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReleaseGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined (USE_DX_INTEROP) +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); + + cl_int enqueueAcquireD3D10Objects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL; +#if defined(CL_VERSION_1_2) + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueAcquireD3D10ObjectsKHR); +#endif +#if defined(CL_VERSION_1_1) + __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR); +#endif + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueAcquireD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseD3D10Objects( + const VECTOR_CLASS* mem_objects = NULL, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL; +#if defined(CL_VERSION_1_2) + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueReleaseD3D10ObjectsKHR); +#endif // #if defined(CL_VERSION_1_2) +#if defined(CL_VERSION_1_1) + __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR); +#endif // #if defined(CL_VERSION_1_1) + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueReleaseD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueBarrier(object_), + __ENQUEUE_BARRIER_ERR); + } +#endif // #if defined(CL_VERSION_1_1) + + cl_int flush() const + { + return detail::errHandler(::clFlush(object_), __FLUSH_ERR); + } + + cl_int finish() const + { + return detail::errHandler(::clFinish(object_), __FINISH_ERR); + } +}; + +#ifdef _WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) std::atomic CommandQueue::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__declspec(selectany) CommandQueue CommandQueue::default_; +__declspec(selectany) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS; +#else // !_WIN32 +#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) std::atomic CommandQueue::default_initialized_; +#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED; +#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED +__attribute__((weak)) CommandQueue CommandQueue::default_; +__attribute__((weak)) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS; +#endif // !_WIN32 + +template< typename IteratorType > +Buffer::Buffer( + const Context &context, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + ::size_t size = sizeof(DataType)*(endIterator - startIterator); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + CommandQueue queue(context, 0, &error); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +template< typename IteratorType > +Buffer::Buffer( + const CommandQueue &queue, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if (readOnly) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + } + + ::size_t size = sizeof(DataType)*(endIterator - startIterator); + + Context context = queue.getInfo(); + + if (useHostPtr) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } + else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if (!useHostPtr) { + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +inline cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + ::size_t offset, + ::size_t size, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + ::size_t offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL, + cl_int* err = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + void * result = ::clEnqueueMapBuffer( + queue(), buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (cl_event*) event, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + return result; +} + +inline cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (error != CL_SUCCESS) { + return error; + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + queue(), memory(), mapped_ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; +} + +inline cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + ::size_t src_offset, + ::size_t dst_offset, + ::size_t size, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, startIterator, endIterator, buffer); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, buffer, startIterator, endIterator); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + ::size_t length = endIterator-startIterator; + ::size_t byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } +#if defined(_MSC_VER) + std::copy( + startIterator, + endIterator, + stdext::checked_array_iterator( + pointer, length)); +#else + std::copy(startIterator, endIterator, pointer); +#endif + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + ::size_t length = endIterator-startIterator; + ::size_t byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } + std::copy(pointer, pointer + length, startIterator); + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + +#if defined(CL_VERSION_1_1) +inline cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const size_t<3>& buffer_offset, + const size_t<3>& host_offset, + const size_t<3>& region, + ::size_t buffer_row_pitch, + ::size_t buffer_slice_pitch, + ::size_t host_row_pitch, + ::size_t host_slice_pitch, + const void *ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + ::size_t src_row_pitch, + ::size_t src_slice_pitch, + ::size_t dst_row_pitch, + ::size_t dst_slice_pitch, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferRect( + src, + dst, + src_origin, + dst_origin, + region, + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + events, + event); +} +#endif + +inline cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const size_t<3>& origin, + const size_t<3>& region, + ::size_t row_pitch, + ::size_t slice_pitch, + const void* ptr, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const size_t<3>& src_origin, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImage( + src, + dst, + src_origin, + dst_origin, + region, + events, + event); +} + +inline cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const size_t<3>& src_origin, + const size_t<3>& region, + ::size_t dst_offset, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImageToBuffer( + src, + dst, + src_origin, + region, + dst_offset, + events, + event); +} + +inline cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + ::size_t src_offset, + const size_t<3>& dst_origin, + const size_t<3>& region, + const VECTOR_CLASS* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferToImage( + src, + dst, + src_offset, + dst_origin, + region, + events, + event); +} + + +inline cl_int flush(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.flush(); +} + +inline cl_int finish(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + + return queue.finish(); +} + +// Kernel Functor support +// New interface as of September 2011 +// Requires the C++11 std::tr1::function (note do not support TR1) +// Visual Studio 2010 and GCC 4.2 + +struct EnqueueArgs +{ + CommandQueue queue_; + const NDRange offset_; + const NDRange global_; + const NDRange local_; + VECTOR_CLASS events_; + + EnqueueArgs(NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(Event e, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(const VECTOR_CLASS &events, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(const VECTOR_CLASS &events, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(const VECTOR_CLASS &events, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } +}; + +namespace detail { + +class NullType {}; + +template +struct SetArg +{ + static void set (Kernel kernel, T0 arg) + { + kernel.setArg(index, arg); + } +}; + +template +struct SetArg +{ + static void set (Kernel, NullType) + { + } +}; + +template < + typename T0, typename T1, typename T2, typename T3, + typename T4, typename T5, typename T6, typename T7, + typename T8, typename T9, typename T10, typename T11, + typename T12, typename T13, typename T14, typename T15, + typename T16, typename T17, typename T18, typename T19, + typename T20, typename T21, typename T22, typename T23, + typename T24, typename T25, typename T26, typename T27, + typename T28, typename T29, typename T30, typename T31 + +> +class KernelFunctorGlobal +{ +private: + Kernel kernel_; + +public: + KernelFunctorGlobal( + Kernel kernel) : + kernel_(kernel) + {} + + KernelFunctorGlobal( + const Program& program, + const STRING_CLASS name, + cl_int * err = NULL) : + kernel_(program, name.c_str(), err) + {} + + Event operator() ( + const EnqueueArgs& args, + T0 t0, + T1 t1 = NullType(), + T2 t2 = NullType(), + T3 t3 = NullType(), + T4 t4 = NullType(), + T5 t5 = NullType(), + T6 t6 = NullType(), + T7 t7 = NullType(), + T8 t8 = NullType(), + T9 t9 = NullType(), + T10 t10 = NullType(), + T11 t11 = NullType(), + T12 t12 = NullType(), + T13 t13 = NullType(), + T14 t14 = NullType(), + T15 t15 = NullType(), + T16 t16 = NullType(), + T17 t17 = NullType(), + T18 t18 = NullType(), + T19 t19 = NullType(), + T20 t20 = NullType(), + T21 t21 = NullType(), + T22 t22 = NullType(), + T23 t23 = NullType(), + T24 t24 = NullType(), + T25 t25 = NullType(), + T26 t26 = NullType(), + T27 t27 = NullType(), + T28 t28 = NullType(), + T29 t29 = NullType(), + T30 t30 = NullType(), + T31 t31 = NullType() + + ) + { + Event event; + SetArg<0, T0>::set(kernel_, t0); + SetArg<1, T1>::set(kernel_, t1); + SetArg<2, T2>::set(kernel_, t2); + SetArg<3, T3>::set(kernel_, t3); + SetArg<4, T4>::set(kernel_, t4); + SetArg<5, T5>::set(kernel_, t5); + SetArg<6, T6>::set(kernel_, t6); + SetArg<7, T7>::set(kernel_, t7); + SetArg<8, T8>::set(kernel_, t8); + SetArg<9, T9>::set(kernel_, t9); + SetArg<10, T10>::set(kernel_, t10); + SetArg<11, T11>::set(kernel_, t11); + SetArg<12, T12>::set(kernel_, t12); + SetArg<13, T13>::set(kernel_, t13); + SetArg<14, T14>::set(kernel_, t14); + SetArg<15, T15>::set(kernel_, t15); + SetArg<16, T16>::set(kernel_, t16); + SetArg<17, T17>::set(kernel_, t17); + SetArg<18, T18>::set(kernel_, t18); + SetArg<19, T19>::set(kernel_, t19); + SetArg<20, T20>::set(kernel_, t20); + SetArg<21, T21>::set(kernel_, t21); + SetArg<22, T22>::set(kernel_, t22); + SetArg<23, T23>::set(kernel_, t23); + SetArg<24, T24>::set(kernel_, t24); + SetArg<25, T25>::set(kernel_, t25); + SetArg<26, T26>::set(kernel_, t26); + SetArg<27, T27>::set(kernel_, t27); + SetArg<28, T28>::set(kernel_, t28); + SetArg<29, T29>::set(kernel_, t29); + SetArg<30, T30>::set(kernel_, t30); + SetArg<31, T31>::set(kernel_, t31); + + + args.queue_.enqueueNDRangeKernel( + kernel_, + args.offset_, + args.global_, + args.local_, + &args.events_, + &event); + + return event; + } + +}; + +//------------------------------------------------------------------------------------------------------ + + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28, + typename T29, + typename T30, + typename T31> +struct functionImplementation_ +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + T31> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 32)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + T31); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28, + T29 arg29, + T30 arg30, + T31 arg31) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28, + arg29, + arg30, + arg31); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28, + typename T29, + typename T30> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 31)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28, + T29 arg29, + T30 arg30) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28, + arg29, + arg30); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28, + typename T29> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 30)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28, + T29 arg29) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28, + arg29); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27, + typename T28> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 29)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27, + T28 arg28) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26, + typename T27> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 28)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26, + T27 arg27) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25, + typename T26> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 27)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25, + T26 arg26) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24, + typename T25> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 26)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24, + T25 arg25) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23, + typename T24> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 25)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23, + T24 arg24) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22, + typename T23> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 24)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22, + T23 arg23) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21, + typename T22> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 23)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21, + T22 arg22) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20, + typename T21> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 22)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20, + T21 arg21) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19, + typename T20> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 21)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19, + T20 arg20) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18, + typename T19> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 20)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18, + T19 arg19) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18, + arg19); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17, + typename T18> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 19)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17, + T18 arg18) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17, + arg18); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16, + typename T17> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 18)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16, + T17 arg17) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16, + arg17); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15, + typename T16> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 17)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15, + T16 arg16) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + arg16); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14, + typename T15> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 16)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14, + T15 arg15) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13, + typename T14> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 15)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13, + T14 arg14) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12, + typename T13> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 14)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12, + T13 arg13) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11, + typename T12> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 13)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11, + T12 arg12) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10, + typename T11> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 12)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10, + T11 arg11) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9, + typename T10> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 11)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9, + T10 arg10) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 10)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8, + T9 arg9) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 9)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7, + T8 arg8) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 8)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6, + T7 arg7) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + T6, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + T6, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 7)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5, + T6); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5, + T6 arg6) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + T5, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + T5, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 6)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4, + T5); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4, + T5 arg5) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4, + arg5); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + T4, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + T4, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 5)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3, + T4); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3, + T4 arg4) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3, + arg4); + } + + +}; + +template< + typename T0, + typename T1, + typename T2, + typename T3> +struct functionImplementation_ +< T0, + T1, + T2, + T3, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + T3, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 4)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2, + T3); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2, + T3 arg3) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2, + arg3); + } + + +}; + +template< + typename T0, + typename T1, + typename T2> +struct functionImplementation_ +< T0, + T1, + T2, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + T2, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 3)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1, + T2); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1, + T2 arg2) + { + return functor_( + enqueueArgs, + arg0, + arg1, + arg2); + } + + +}; + +template< + typename T0, + typename T1> +struct functionImplementation_ +< T0, + T1, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + T1, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 2)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0, + T1); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0, + T1 arg1) + { + return functor_( + enqueueArgs, + arg0, + arg1); + } + + +}; + +template< + typename T0> +struct functionImplementation_ +< T0, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> +{ + typedef detail::KernelFunctorGlobal< + T0, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType, + NullType> FunctorType; + + FunctorType functor_; + + functionImplementation_(const FunctorType &functor) : + functor_(functor) + { + + #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 1)) + // Fail variadic expansion for dev11 + static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); + #endif + + } + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + T0); + + Event operator()( + const EnqueueArgs& enqueueArgs, + T0 arg0) + { + return functor_( + enqueueArgs, + arg0); + } + + +}; + + + + + +} // namespace detail + +//---------------------------------------------------------------------------------------------- + +template < + typename T0, typename T1 = detail::NullType, typename T2 = detail::NullType, + typename T3 = detail::NullType, typename T4 = detail::NullType, + typename T5 = detail::NullType, typename T6 = detail::NullType, + typename T7 = detail::NullType, typename T8 = detail::NullType, + typename T9 = detail::NullType, typename T10 = detail::NullType, + typename T11 = detail::NullType, typename T12 = detail::NullType, + typename T13 = detail::NullType, typename T14 = detail::NullType, + typename T15 = detail::NullType, typename T16 = detail::NullType, + typename T17 = detail::NullType, typename T18 = detail::NullType, + typename T19 = detail::NullType, typename T20 = detail::NullType, + typename T21 = detail::NullType, typename T22 = detail::NullType, + typename T23 = detail::NullType, typename T24 = detail::NullType, + typename T25 = detail::NullType, typename T26 = detail::NullType, + typename T27 = detail::NullType, typename T28 = detail::NullType, + typename T29 = detail::NullType, typename T30 = detail::NullType, + typename T31 = detail::NullType + +> +struct make_kernel : + public detail::functionImplementation_< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + > +{ +public: + typedef detail::KernelFunctorGlobal< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + > FunctorType; + + make_kernel( + const Program& program, + const STRING_CLASS name, + cl_int * err = NULL) : + detail::functionImplementation_< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + >( + FunctorType(program, name, err)) + {} + + make_kernel( + const Kernel kernel) : + detail::functionImplementation_< + T0, T1, T2, T3, + T4, T5, T6, T7, + T8, T9, T10, T11, + T12, T13, T14, T15, + T16, T17, T18, T19, + T20, T21, T22, T23, + T24, T25, T26, T27, + T28, T29, T30, T31 + + >( + FunctorType(kernel)) + {} +}; + + +//---------------------------------------------------------------------------------------------------------------------- + +#undef __ERR_STR +#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS) +#undef __GET_DEVICE_INFO_ERR +#undef __GET_PLATFORM_INFO_ERR +#undef __GET_DEVICE_IDS_ERR +#undef __GET_CONTEXT_INFO_ERR +#undef __GET_EVENT_INFO_ERR +#undef __GET_EVENT_PROFILE_INFO_ERR +#undef __GET_MEM_OBJECT_INFO_ERR +#undef __GET_IMAGE_INFO_ERR +#undef __GET_SAMPLER_INFO_ERR +#undef __GET_KERNEL_INFO_ERR +#undef __GET_KERNEL_ARG_INFO_ERR +#undef __GET_KERNEL_WORK_GROUP_INFO_ERR +#undef __GET_PROGRAM_INFO_ERR +#undef __GET_PROGRAM_BUILD_INFO_ERR +#undef __GET_COMMAND_QUEUE_INFO_ERR + +#undef __CREATE_CONTEXT_ERR +#undef __CREATE_CONTEXT_FROM_TYPE_ERR +#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR + +#undef __CREATE_BUFFER_ERR +#undef __CREATE_SUBBUFFER_ERR +#undef __CREATE_IMAGE2D_ERR +#undef __CREATE_IMAGE3D_ERR +#undef __CREATE_SAMPLER_ERR +#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR + +#undef __CREATE_USER_EVENT_ERR +#undef __SET_USER_EVENT_STATUS_ERR +#undef __SET_EVENT_CALLBACK_ERR +#undef __SET_PRINTF_CALLBACK_ERR + +#undef __WAIT_FOR_EVENTS_ERR + +#undef __CREATE_KERNEL_ERR +#undef __SET_KERNEL_ARGS_ERR +#undef __CREATE_PROGRAM_WITH_SOURCE_ERR +#undef __CREATE_PROGRAM_WITH_BINARY_ERR +#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR +#undef __BUILD_PROGRAM_ERR +#undef __CREATE_KERNELS_IN_PROGRAM_ERR + +#undef __CREATE_COMMAND_QUEUE_ERR +#undef __SET_COMMAND_QUEUE_PROPERTY_ERR +#undef __ENQUEUE_READ_BUFFER_ERR +#undef __ENQUEUE_WRITE_BUFFER_ERR +#undef __ENQUEUE_READ_BUFFER_RECT_ERR +#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR +#undef __ENQEUE_COPY_BUFFER_ERR +#undef __ENQEUE_COPY_BUFFER_RECT_ERR +#undef __ENQUEUE_READ_IMAGE_ERR +#undef __ENQUEUE_WRITE_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR +#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR +#undef __ENQUEUE_MAP_BUFFER_ERR +#undef __ENQUEUE_MAP_IMAGE_ERR +#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR +#undef __ENQUEUE_NDRANGE_KERNEL_ERR +#undef __ENQUEUE_TASK_ERR +#undef __ENQUEUE_NATIVE_KERNEL + +#undef __CL_EXPLICIT_CONSTRUCTORS + +#undef __UNLOAD_COMPILER_ERR +#endif //__CL_USER_OVERRIDE_ERROR_STRINGS + +#undef __CL_FUNCTION_TYPE + +// Extensions +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_VERSION_1_1) +#undef __INIT_CL_EXT_FCN_PTR +#endif // #if defined(CL_VERSION_1_1) +#undef __CREATE_SUB_DEVICES + +#if defined(USE_CL_DEVICE_FISSION) +#undef __PARAM_NAME_DEVICE_FISSION +#endif // USE_CL_DEVICE_FISSION + +#undef __DEFAULT_NOT_INITIALIZED +#undef __DEFAULT_BEING_INITIALIZED +#undef __DEFAULT_INITIALIZED + +#undef CL_HPP_RVALUE_REFERENCES_SUPPORTED +#undef CL_HPP_NOEXCEPT + +} // namespace cl + +#endif // CL_HPP_ diff --git a/opencl/khronos/headers/opencl2.2/CL/cl2.hpp b/opencl/khronos/headers/opencl2.2/CL/cl2.hpp new file mode 100644 index 0000000000..c89668b788 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl2.hpp @@ -0,0 +1,9569 @@ +/* Modifications Copyright(C)[2021-2022] Advanced Micro Devices, Inc. + * All rights reserved. + * */ + +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +/*! \file + * + * \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33), + * OpenCL 1.2 (rev 15) and OpenCL 2.0 (rev 29) + * \author Lee Howes and Bruce Merry + * + * Derived from the OpenCL 1.x C++ bindings written by + * Benedict R. Gaster, Laurent Morichetti and Lee Howes + * With additions and fixes from: + * Brian Cole, March 3rd 2010 and April 2012 + * Matt Gruenke, April 2012. + * Bruce Merry, February 2013. + * Tom Deakin and Simon McIntosh-Smith, July 2013 + * James Price, 2015- + * + * \version 2.0.10 + * \date 2016-07-20 + * + * Optional extension support + * + * cl_ext_device_fission + * #define CL_HPP_USE_CL_DEVICE_FISSION + * cl_khr_d3d10_sharing + * #define CL_HPP_USE_DX_INTEROP + * cl_khr_sub_groups + * #define CL_HPP_USE_CL_SUB_GROUPS_KHR + * cl_khr_image2d_from_buffer + * #define CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR + * + * Doxygen documentation for this header is available here: + * + * http://khronosgroup.github.io/OpenCL-CLHPP/ + * + * The latest version of this header can be found on the GitHub releases page: + * + * https://github.com/KhronosGroup/OpenCL-CLHPP/releases + * + * Bugs and patches can be submitted to the GitHub repository: + * + * https://github.com/KhronosGroup/OpenCL-CLHPP + */ + +/*! \mainpage + * \section intro Introduction + * For many large applications C++ is the language of choice and so it seems + * reasonable to define C++ bindings for OpenCL. + * + * The interface is contained with a single C++ header file \em cl2.hpp and all + * definitions are contained within the namespace \em cl. There is no additional + * requirement to include \em cl.h and to use either the C++ or original C + * bindings; it is enough to simply include \em cl2.hpp. + * + * The bindings themselves are lightweight and correspond closely to the + * underlying C API. Using the C++ bindings introduces no additional execution + * overhead. + * + * There are numerous compatibility, portability and memory management + * fixes in the new header as well as additional OpenCL 2.0 features. + * As a result the header is not directly backward compatible and for this + * reason we release it as cl2.hpp rather than a new version of cl.hpp. + * + * + * \section compatibility Compatibility + * Due to the evolution of the underlying OpenCL API the 2.0 C++ bindings + * include an updated approach to defining supported feature versions + * and the range of valid underlying OpenCL runtime versions supported. + * + * The combination of preprocessor macros CL_HPP_TARGET_OPENCL_VERSION and + * CL_HPP_MINIMUM_OPENCL_VERSION control this range. These are three digit + * decimal values representing OpenCL runime versions. The default for + * the target is 200, representing OpenCL 2.0 and the minimum is also + * defined as 200. These settings would use 2.0 API calls only. + * If backward compatibility with a 1.2 runtime is required, the minimum + * version may be set to 120. + * + * Note that this is a compile-time setting, and so affects linking against + * a particular SDK version rather than the versioning of the loaded runtime. + * + * The earlier versions of the header included basic vector and string + * classes based loosely on STL versions. These were difficult to + * maintain and very rarely used. For the 2.0 header we now assume + * the presence of the standard library unless requested otherwise. + * We use std::array, std::vector, std::shared_ptr and std::string + * throughout to safely manage memory and reduce the chance of a + * recurrance of earlier memory management bugs. + * + * These classes are used through typedefs in the cl namespace: + * cl::array, cl::vector, cl::pointer and cl::string. + * In addition cl::allocate_pointer forwards to std::allocate_shared + * by default. + * In all cases these standard library classes can be replaced with + * custom interface-compatible versions using the CL_HPP_NO_STD_ARRAY, + * CL_HPP_NO_STD_VECTOR, CL_HPP_NO_STD_UNIQUE_PTR and + * CL_HPP_NO_STD_STRING macros. + * + * The OpenCL 1.x versions of the C++ bindings included a size_t wrapper + * class to interface with kernel enqueue. This caused unpleasant interactions + * with the standard size_t declaration and led to namespacing bugs. + * In the 2.0 version we have replaced this with a std::array-based interface. + * However, the old behaviour can be regained for backward compatibility + * using the CL_HPP_ENABLE_SIZE_T_COMPATIBILITY macro. + * + * Finally, the program construction interface used a clumsy vector-of-pairs + * design in the earlier versions. We have replaced that with a cleaner + * vector-of-vectors and vector-of-strings design. However, for backward + * compatibility old behaviour can be regained with the + * CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY macro. + * + * In OpenCL 2.0 OpenCL C is not entirely backward compatibility with + * earlier versions. As a result a flag must be passed to the OpenCL C + * compiled to request OpenCL 2.0 compilation of kernels with 1.2 as + * the default in the absence of the flag. + * In some cases the C++ bindings automatically compile code for ease. + * For those cases the compilation defaults to OpenCL C 2.0. + * If this is not wanted, the CL_HPP_CL_1_2_DEFAULT_BUILD macro may + * be specified to assume 1.2 compilation. + * If more fine-grained decisions on a per-kernel bases are required + * then explicit build operations that take the flag should be used. + * + * + * \section parameterization Parameters + * This header may be parameterized by a set of preprocessor macros. + * + * - CL_HPP_TARGET_OPENCL_VERSION + * + * Defines the target OpenCL runtime version to build the header + * against. Defaults to 200, representing OpenCL 2.0. + * + * - CL_HPP_NO_STD_STRING + * + * Do not use the standard library string class. cl::string is not + * defined and may be defined by the user before cl2.hpp is + * included. + * + * - CL_HPP_NO_STD_VECTOR + * + * Do not use the standard library vector class. cl::vector is not + * defined and may be defined by the user before cl2.hpp is + * included. + * + * - CL_HPP_NO_STD_ARRAY + * + * Do not use the standard library array class. cl::array is not + * defined and may be defined by the user before cl2.hpp is + * included. + * + * - CL_HPP_NO_STD_UNIQUE_PTR + * + * Do not use the standard library unique_ptr class. cl::pointer and + * the cl::allocate_pointer functions are not defined and may be + * defined by the user before cl2.hpp is included. + * + * - CL_HPP_ENABLE_DEVICE_FISSION + * + * Enables device fission for OpenCL 1.2 platforms. + * + * - CL_HPP_ENABLE_EXCEPTIONS + * + * Enable exceptions for use in the C++ bindings header. This is the + * preferred error handling mechanism but is not required. + * + * - CL_HPP_ENABLE_SIZE_T_COMPATIBILITY + * + * Backward compatibility option to support cl.hpp-style size_t + * class. Replaces the updated std::array derived version and + * removal of size_t from the namespace. Note that in this case the + * new size_t class is placed in the cl::compatibility namespace and + * thus requires an additional using declaration for direct backward + * compatibility. + * + * - CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY + * + * Enable older vector of pairs interface for construction of + * programs. + * + * - CL_HPP_CL_1_2_DEFAULT_BUILD + * + * Default to OpenCL C 1.2 compilation rather than OpenCL C 2.0 + * applies to use of cl::Program construction and other program + * build variants. + * + * + * \section example Example + * + * The following example shows a general use case for the C++ + * bindings, including support for the optional exception feature and + * also the supplied vector and string classes, see following sections for + * decriptions of these features. + * + * \code + #define CL_HPP_ENABLE_EXCEPTIONS + #define CL_HPP_TARGET_OPENCL_VERSION 200 + + #include + #include + #include + #include + #include + + const int numElements = 32; + + int main(void) + { + // Filter for a 2.0 platform and set it as the default + std::vector platforms; + cl::Platform::get(&platforms); + cl::Platform plat; + for (auto &p : platforms) { + std::string platver = p.getInfo(); + if (platver.find("OpenCL 2.") != std::string::npos) { + plat = p; + } + } + if (plat() == 0) { + std::cout << "No OpenCL 2.0 platform found."; + return -1; + } + + cl::Platform newP = cl::Platform::setDefault(plat); + if (newP != plat) { + std::cout << "Error setting default platform."; + return -1; + } + + // Use C++11 raw string literals for kernel source code + std::string kernel1{R"CLC( + global int globalA; + kernel void updateGlobal() + { + globalA = 75; + } + )CLC"}; + std::string kernel2{R"CLC( + typedef struct { global int *bar; } Foo; + kernel void vectorAdd(global const Foo* aNum, global const int *inputA, global const int *inputB, + global int *output, int val, write_only pipe int outPipe, queue_t childQueue) + { + output[get_global_id(0)] = inputA[get_global_id(0)] + inputB[get_global_id(0)] + val + *(aNum->bar); + write_pipe(outPipe, &val); + queue_t default_queue = get_default_queue(); + ndrange_t ndrange = ndrange_1D(get_global_size(0)/2, get_global_size(0)/2); + + // Have a child kernel write into third quarter of output + enqueue_kernel(default_queue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, + ^{ + output[get_global_size(0)*2 + get_global_id(0)] = + inputA[get_global_size(0)*2 + get_global_id(0)] + inputB[get_global_size(0)*2 + get_global_id(0)] + globalA; + }); + + // Have a child kernel write into last quarter of output + enqueue_kernel(childQueue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, + ^{ + output[get_global_size(0)*3 + get_global_id(0)] = + inputA[get_global_size(0)*3 + get_global_id(0)] + inputB[get_global_size(0)*3 + get_global_id(0)] + globalA + 2; + }); + } + )CLC"}; + + // New simpler string interface style + std::vector programStrings {kernel1, kernel2}; + + cl::Program vectorAddProgram(programStrings); + try { + vectorAddProgram.build("-cl-std=CL2.0"); + } + catch (...) { + // Print build info for all devices + cl_int buildErr = CL_SUCCESS; + auto buildInfo = vectorAddProgram.getBuildInfo(&buildErr); + for (auto &pair : buildInfo) { + std::cerr << pair.second << std::endl << std::endl; + } + + return 1; + } + + typedef struct { int *bar; } Foo; + + // Get and run kernel that initializes the program-scope global + // A test for kernels that take no arguments + auto program2Kernel = + cl::KernelFunctor<>(vectorAddProgram, "updateGlobal"); + program2Kernel( + cl::EnqueueArgs( + cl::NDRange(1))); + + ////////////////// + // SVM allocations + + auto anSVMInt = cl::allocate_svm>(); + *anSVMInt = 5; + cl::SVMAllocator>> svmAllocReadOnly; + auto fooPointer = cl::allocate_pointer(svmAllocReadOnly); + fooPointer->bar = anSVMInt.get(); + cl::SVMAllocator> svmAlloc; + std::vector>> inputA(numElements, 1, svmAlloc); + cl::coarse_svm_vector inputB(numElements, 2, svmAlloc); + + // + ////////////// + + // Traditional cl_mem allocations + std::vector output(numElements, 0xdeadbeef); + cl::Buffer outputBuffer(begin(output), end(output), false); + cl::Pipe aPipe(sizeof(cl_int), numElements / 2); + + // Default command queue, also passed in as a parameter + cl::DeviceCommandQueue defaultDeviceQueue = cl::DeviceCommandQueue::makeDefault( + cl::Context::getDefault(), cl::Device::getDefault()); + + auto vectorAddKernel = + cl::KernelFunctor< + decltype(fooPointer)&, + int*, + cl::coarse_svm_vector&, + cl::Buffer, + int, + cl::Pipe&, + cl::DeviceCommandQueue + >(vectorAddProgram, "vectorAdd"); + + // Ensure that the additional SVM pointer is available to the kernel + // This one was not passed as a parameter + vectorAddKernel.setSVMPointers(anSVMInt); + + // Hand control of coarse allocations to runtime + cl::enqueueUnmapSVM(anSVMInt); + cl::enqueueUnmapSVM(fooPointer); + cl::unmapSVM(inputB); + cl::unmapSVM(output2); + + cl_int error; + vectorAddKernel( + cl::EnqueueArgs( + cl::NDRange(numElements/2), + cl::NDRange(numElements/2)), + fooPointer, + inputA.data(), + inputB, + outputBuffer, + 3, + aPipe, + defaultDeviceQueue, + error + ); + + cl::copy(outputBuffer, begin(output), end(output)); + // Grab the SVM output vector using a map + cl::mapSVM(output2); + + cl::Device d = cl::Device::getDefault(); + + std::cout << "Output:\n"; + for (int i = 1; i < numElements; ++i) { + std::cout << "\t" << output[i] << "\n"; + } + std::cout << "\n\n"; + + return 0; + } + * + * \endcode + * + */ +#ifndef CL_HPP_ +#define CL_HPP_ + +/* Handle deprecated preprocessor definitions. In each case, we only check for + * the old name if the new name is not defined, so that user code can define + * both and hence work with either version of the bindings. + */ +#if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP) +# pragma message("cl2.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead") +# define CL_HPP_USE_DX_INTEROP +#endif +#if !defined(CL_HPP_USE_CL_DEVICE_FISSION) && defined(USE_CL_DEVICE_FISSION) +# pragma message("cl2.hpp: USE_CL_DEVICE_FISSION is deprecated. Define CL_HPP_USE_CL_DEVICE_FISSION instead") +# define CL_HPP_USE_CL_DEVICE_FISSION +#endif +#if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS) +# pragma message("cl2.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead") +# define CL_HPP_ENABLE_EXCEPTIONS +#endif +#if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR) +# pragma message("cl2.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead") +# define CL_HPP_NO_STD_VECTOR +#endif +#if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING) +# pragma message("cl2.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead") +# define CL_HPP_NO_STD_STRING +#endif +#if defined(VECTOR_CLASS) +# pragma message("cl2.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead") +#endif +#if defined(STRING_CLASS) +# pragma message("cl2.hpp: STRING_CLASS is deprecated. Alias cl::string instead.") +#endif +#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS) +# pragma message("cl2.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead") +# define CL_HPP_USER_OVERRIDE_ERROR_STRINGS +#endif + +/* Warn about features that are no longer supported + */ +#if defined(__USE_DEV_VECTOR) +# pragma message("cl2.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors") +#endif +#if defined(__USE_DEV_STRING) +# pragma message("cl2.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors") +#endif + +/* Detect which version to target */ +#if !defined(CL_HPP_TARGET_OPENCL_VERSION) +# pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 200 (OpenCL 2.0)") +# define CL_HPP_TARGET_OPENCL_VERSION 200 +#endif +#if CL_HPP_TARGET_OPENCL_VERSION != 100 && CL_HPP_TARGET_OPENCL_VERSION != 110 && CL_HPP_TARGET_OPENCL_VERSION != 120 && CL_HPP_TARGET_OPENCL_VERSION != 200 +# pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120 or 200). It will be set to 200") +# undef CL_HPP_TARGET_OPENCL_VERSION +# define CL_HPP_TARGET_OPENCL_VERSION 200 +#endif + +#if !defined(CL_HPP_MINIMUM_OPENCL_VERSION) +# define CL_HPP_MINIMUM_OPENCL_VERSION 200 +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && CL_HPP_MINIMUM_OPENCL_VERSION != 110 && CL_HPP_MINIMUM_OPENCL_VERSION != 120 && CL_HPP_MINIMUM_OPENCL_VERSION != 200 +# pragma message("cl2.hpp: CL_HPP_MINIMUM_OPENCL_VERSION is not a valid value (100, 110, 120 or 200). It will be set to 100") +# undef CL_HPP_MINIMUM_OPENCL_VERSION +# define CL_HPP_MINIMUM_OPENCL_VERSION 100 +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION +# error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION" +#endif + +#if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS) +# define CL_USE_DEPRECATED_OPENCL_1_0_APIS +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +# define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) +# define CL_USE_DEPRECATED_OPENCL_1_2_APIS +#endif +#if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS) +# define CL_USE_DEPRECATED_OPENCL_2_0_APIS +#endif + +#ifdef _WIN32 + +#include + +#if defined(CL_HPP_USE_DX_INTEROP) +#include +#include +#endif +#endif // _WIN32 + +#if defined(_MSC_VER) +#include +#endif // _MSC_VER + + // Check for a valid C++ version + +// Need to do both tests here because for some reason __cplusplus is not +// updated in visual studio +#if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700) +#error Visual studio 2013 or another C++11-supporting compiler required +#endif + +// +#if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) +#include +#endif + +#if defined(__APPLE__) || defined(__MACOSX) +#include +#else +#include +#endif // !__APPLE__ + +#if (__cplusplus >= 201103L) +#define CL_HPP_NOEXCEPT_ noexcept +#else +#define CL_HPP_NOEXCEPT_ +#endif + +#if defined(_MSC_VER) +# define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany) +#else +# define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak)) +#endif // !_MSC_VER + +// Define deprecated prefixes and suffixes to ensure compilation +// in case they are not pre-defined +#if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) +#if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED) +#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) + +#if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED) +#define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED) +#if !defined(CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED) +#define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED +#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED) + +#if !defined(CL_CALLBACK) +#define CL_CALLBACK +#endif //CL_CALLBACK + +#include +#include +#include +#include +#include +#include + + +// Define a size_type to represent a correctly resolved size_t +#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) +namespace cl { + using size_type = ::size_t; +} // namespace cl +#else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) +namespace cl { + using size_type = size_t; +} // namespace cl +#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) + + +#if defined(CL_HPP_ENABLE_EXCEPTIONS) +#include +#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS) + +#if !defined(CL_HPP_NO_STD_VECTOR) +#include +namespace cl { + template < class T, class Alloc = std::allocator > + using vector = std::vector; +} // namespace cl +#endif // #if !defined(CL_HPP_NO_STD_VECTOR) + +#if !defined(CL_HPP_NO_STD_STRING) +#include +namespace cl { + using string = std::string; +} // namespace cl +#endif // #if !defined(CL_HPP_NO_STD_STRING) + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +#if !defined(CL_HPP_NO_STD_UNIQUE_PTR) +#include +namespace cl { + // Replace unique_ptr and allocate_pointer for internal use + // to allow user to replace them + template + using pointer = std::unique_ptr; +} // namespace cl +#endif +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 +#if !defined(CL_HPP_NO_STD_ARRAY) +#include +namespace cl { + template < class T, size_type N > + using array = std::array; +} // namespace cl +#endif // #if !defined(CL_HPP_NO_STD_ARRAY) + +// Define size_type appropriately to allow backward-compatibility +// use of the old size_t interface class +#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) +namespace cl { + namespace compatibility { + /*! \brief class used to interface between C++ and + * OpenCL C calls that require arrays of size_t values, whose + * size is known statically. + */ + template + class size_t + { + private: + size_type data_[N]; + + public: + //! \brief Initialize size_t to all 0s + size_t() + { + for (int i = 0; i < N; ++i) { + data_[i] = 0; + } + } + + size_t(const array &rhs) + { + for (int i = 0; i < N; ++i) { + data_[i] = rhs[i]; + } + } + + size_type& operator[](int index) + { + return data_[index]; + } + + const size_type& operator[](int index) const + { + return data_[index]; + } + + //! \brief Conversion operator to T*. + operator size_type* () { return data_; } + + //! \brief Conversion operator to const T*. + operator const size_type* () const { return data_; } + + operator array() const + { + array ret; + + for (int i = 0; i < N; ++i) { + ret[i] = data_[i]; + } + return ret; + } + }; + } // namespace compatibility + + template + using size_t = compatibility::size_t; +} // namespace cl +#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY) + +// Helper alias to avoid confusing the macros +namespace cl { + namespace detail { + using size_t_array = array; + } // namespace detail +} // namespace cl + + +/*! \namespace cl + * + * \brief The OpenCL C++ bindings are defined within this namespace. + * + */ +namespace cl { + class Memory; + +#define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \ + if (!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddress(#name); \ + if (!pfn_##name) { \ + } \ + } + +#define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \ + if (!pfn_##name) { \ + pfn_##name = (PFN_##name) \ + clGetExtensionFunctionAddressForPlatform(platform, #name); \ + if (!pfn_##name) { \ + } \ + } + + class Program; + class Device; + class Context; + class CommandQueue; + class DeviceCommandQueue; + class Memory; + class Buffer; + class Pipe; + +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + /*! \brief Exception class + * + * This may be thrown by API functions when CL_HPP_ENABLE_EXCEPTIONS is defined. + */ + class Error : public std::exception + { + private: + cl_int err_; + const char * errStr_; + public: + /*! \brief Create a new CL error exception for a given error code + * and corresponding message. + * + * \param err error code value. + * + * \param errStr a descriptive string that must remain in scope until + * handling of the exception has concluded. If set, it + * will be returned by what(). + */ + Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr) + {} + + ~Error() throw() {} + + /*! \brief Get error string associated with exception + * + * \return A memory pointer to the error message string. + */ + virtual const char * what() const throw () + { + if (errStr_ == NULL) { + return "empty"; + } + else { + return errStr_; + } + } + + /*! \brief Get error code associated with exception + * + * \return The error code. + */ + cl_int err(void) const { return err_; } + }; +#define CL_HPP_ERR_STR_(x) #x +#else +#define CL_HPP_ERR_STR_(x) NULL +#endif // CL_HPP_ENABLE_EXCEPTIONS + + +namespace detail +{ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) +static inline cl_int errHandler ( + cl_int err, + const char * errStr = NULL) +{ + if (err != CL_SUCCESS) { + throw Error(err, errStr); + } + return err; +} +#else +static inline cl_int errHandler (cl_int err, const char * errStr = NULL) +{ + (void) errStr; // suppress unused variable warning + return err; +} +#endif // CL_HPP_ENABLE_EXCEPTIONS +} + + + +//! \cond DOXYGEN_DETAIL +#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) +#define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo) +#define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo) +#define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs) +#define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs) +#define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo) +#define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo) +#define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo) +#define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo) +#define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo) +#define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo) +#define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo) +#define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo) +#define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo) +#define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo) + +#define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext) +#define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType) +#define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats) + +#define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer) +#define __COPY_ERR CL_HPP_ERR_STR_(cl::copy) +#define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer) +#define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer) +#define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer) +#define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage) +#define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture) +#define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback) + +#define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent) +#define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus) +#define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback) +#define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents) + +#define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel) +#define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg) +#define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource) +#define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram) +#define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram) + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +#define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties) +#define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200 +#define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty) +#define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer) +#define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect) +#define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer) +#define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect) +#define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer) +#define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect) +#define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer) +#define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage) +#define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage) +#define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage) +#define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage) +#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer) +#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage) +#define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer) +#define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage) +#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject) +#define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel) +#define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel) +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + +#define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects) +#define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects) + +#define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe) +#define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo) + + +#define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object) +#define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object) +#define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush) +#define __FINISH_ERR CL_HPP_ERR_STR_(clFinish) +#define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error) + +/** + * CL 1.2 version that uses device fission. + */ +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices) +#else +#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +#define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker) +#define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents) +#define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier) +#define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler) +#define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D) +#define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D) +#define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D) +#define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D) +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +/** + * Deprecated APIs for 2.0 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) +#define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue) +#define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask) +#define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler) +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +/** + * CL 1.2 marker and barrier commands + */ +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList) +#define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + +#endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS +//! \endcond + + +namespace detail { + +// Generic getInfoHelper. The final parameter is used to guide overload +// resolution: the actual parameter passed is an int, which makes this +// a worse conversion sequence than a specialization that declares the +// parameter as an int. +template +inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long) +{ + return f(name, sizeof(T), param, NULL); +} + +// Specialized for getInfo +// Assumes that the output vector was correctly resized on the way in +template +inline cl_int getInfoHelper(Func f, cl_uint name, vector>* param, int) +{ + if (name != CL_PROGRAM_BINARIES) { + return CL_INVALID_VALUE; + } + if (param) { + // Create array of pointers, calculate total size and pass pointer array in + size_type numBinaries = param->size(); + vector binariesPointers(numBinaries); + + for (size_type i = 0; i < numBinaries; ++i) + { + binariesPointers[i] = (*param)[i].data(); + } + + cl_int err = f(name, numBinaries * sizeof(unsigned char*), binariesPointers.data(), NULL); + + if (err != CL_SUCCESS) { + return err; + } + } + + + return CL_SUCCESS; +} + +// Specialized getInfoHelper for vector params +template +inline cl_int getInfoHelper(Func f, cl_uint name, vector* param, long) +{ + size_type required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + const size_type elements = required / sizeof(T); + + // Temporary to avoid changing param on an error + vector localData(elements); + err = f(name, required, localData.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + if (param) { + *param = std::move(localData); + } + + return CL_SUCCESS; +} + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper( + Func f, cl_uint name, vector* param, int, typename T::cl_type = 0) +{ + size_type required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + const size_type elements = required / sizeof(typename T::cl_type); + + vector value(elements); + err = f(name, required, value.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + + if (param) { + // Assign to convert CL type to T for each element + param->resize(elements); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < elements; i++) { + (*param)[i] = T(value[i], true); + } + } + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for string params +template +inline cl_int getInfoHelper(Func f, cl_uint name, string* param, long) +{ + size_type required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + // std::string has a constant data member + // a char vector does not + if (required > 0) { + vector value(required); + err = f(name, required, value.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + if (param) { + param->assign(begin(value), prev(end(value))); + } + } + else if (param) { + param->assign(""); + } + return CL_SUCCESS; +} + +// Specialized GetInfoHelper for clsize_t params +template +inline cl_int getInfoHelper(Func f, cl_uint name, array* param, long) +{ + size_type required; + cl_int err = f(name, 0, NULL, &required); + if (err != CL_SUCCESS) { + return err; + } + + size_type elements = required / sizeof(size_type); + vector value(elements, 0); + + err = f(name, required, value.data(), NULL); + if (err != CL_SUCCESS) { + return err; + } + + // Bound the copy with N to prevent overruns + // if passed N > than the amount copied + if (elements > N) { + elements = N; + } + for (size_type i = 0; i < elements; ++i) { + (*param)[i] = value[i]; + } + + return CL_SUCCESS; +} + +template struct ReferenceHandler; + +/* Specialization for reference-counted types. This depends on the + * existence of Wrapper::cl_type, and none of the other types having the + * cl_type member. Note that simplify specifying the parameter as Wrapper + * does not work, because when using a derived type (e.g. Context) the generic + * template will provide a better match. + */ +template +inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0) +{ + typename T::cl_type value; + cl_int err = f(name, sizeof(value), &value, NULL); + if (err != CL_SUCCESS) { + return err; + } + *param = value; + if (value != NULL) + { + err = param->retain(); + if (err != CL_SUCCESS) { + return err; + } + } + return CL_SUCCESS; +} + +#define CL_HPP_PARAM_NAME_INFO_1_0_(F) \ + F(cl_platform_info, CL_PLATFORM_PROFILE, string) \ + F(cl_platform_info, CL_PLATFORM_VERSION, string) \ + F(cl_platform_info, CL_PLATFORM_NAME, string) \ + F(cl_platform_info, CL_PLATFORM_VENDOR, string) \ + F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \ + \ + F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \ + F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \ + F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \ + F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \ + F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \ + F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \ + F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \ + F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \ + F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \ + F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \ + F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \ + F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \ + F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \ + F(cl_device_info, CL_DEVICE_NAME, string) \ + F(cl_device_info, CL_DEVICE_VENDOR, string) \ + F(cl_device_info, CL_DRIVER_VERSION, string) \ + F(cl_device_info, CL_DEVICE_PROFILE, string) \ + F(cl_device_info, CL_DEVICE_VERSION, string) \ + F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \ + \ + F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \ + F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector) \ + F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector) \ + \ + F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \ + F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \ + F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \ + F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \ + \ + F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \ + F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \ + \ + F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \ + F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \ + F(cl_mem_info, CL_MEM_SIZE, size_type) \ + F(cl_mem_info, CL_MEM_HOST_PTR, void*) \ + F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \ + F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \ + \ + F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \ + F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \ + F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \ + F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \ + F(cl_image_info, CL_IMAGE_WIDTH, size_type) \ + F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \ + F(cl_image_info, CL_IMAGE_DEPTH, size_type) \ + \ + F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \ + F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \ + F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \ + F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \ + F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \ + \ + F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \ + F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \ + F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \ + F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector) \ + F(cl_program_info, CL_PROGRAM_SOURCE, string) \ + F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector) \ + F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector>) \ + \ + F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \ + \ + F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \ + F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \ + F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \ + F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \ + F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \ + F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \ + \ + F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \ + F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \ + F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \ + F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties) + + +#define CL_HPP_PARAM_NAME_INFO_1_1_(F) \ + F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\ + F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \ + F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \ + F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \ + F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \ + \ + F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \ + F(cl_mem_info, CL_MEM_OFFSET, size_type) \ + \ + F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \ + F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \ + \ + F(cl_event_info, CL_EVENT_CONTEXT, cl::Context) + +#define CL_HPP_PARAM_NAME_INFO_1_2_(F) \ + F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \ + F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \ + \ + F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \ + \ + F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \ + \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \ + F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \ + \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \ + F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, size_type) \ + F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \ + F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \ + \ + F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \ + F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \ + F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint) + +#define CL_HPP_PARAM_NAME_INFO_2_0_(F) \ + F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \ + F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \ + F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \ + F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \ + F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \ + F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \ + F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \ + F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \ + F(cl_device_info, CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE, size_type) \ + F(cl_device_info, CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE, size_type) \ + F(cl_device_info, CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS, cl_uint) \ + F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \ + F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \ + F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \ + F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \ + F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint) + +#define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \ + F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \ + F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector) \ + F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector) \ + F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \ + F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector) + +template +struct param_traits {}; + +#define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \ +struct token; \ +template<> \ +struct param_traits \ +{ \ + enum { value = param_name }; \ + typedef T param_type; \ +}; + +CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 +CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + + +// Flags deprecated in OpenCL 2.0 +#define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \ + F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) + +#define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \ + F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) + +#define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \ + F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer) + +// Include deprecated query flags based on versions +// Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash +#if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200 +CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110 +#if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 +CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120 +#if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 +CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_) +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200 + +#if defined(CL_HPP_USE_CL_DEVICE_FISSION) +CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_); +#endif // CL_HPP_USE_CL_DEVICE_FISSION + +#ifdef CL_PLATFORM_ICD_SUFFIX_KHR +CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string) +#endif + +#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong) +#endif + +#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector) +#endif +#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_WIDTH_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint) +#endif +#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint) +#endif + +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint) +#endif +#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint) +#endif +#ifdef CL_DEVICE_WARP_SIZE_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint) +#endif +#ifdef CL_DEVICE_GPU_OVERLAP_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool) +#endif +#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool) +#endif +#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool) +#endif + +// Convenience functions + +template +inline cl_int +getInfo(Func f, cl_uint name, T* param) +{ + return getInfoHelper(f, name, param, 0); +} + +template +struct GetInfoFunctor0 +{ + Func f_; const Arg0& arg0_; + cl_int operator ()( + cl_uint param, size_type size, void* value, size_type* size_ret) + { return f_(arg0_, param, size, value, size_ret); } +}; + +template +struct GetInfoFunctor1 +{ + Func f_; const Arg0& arg0_; const Arg1& arg1_; + cl_int operator ()( + cl_uint param, size_type size, void* value, size_type* size_ret) + { return f_(arg0_, arg1_, param, size, value, size_ret); } +}; + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, cl_uint name, T* param) +{ + GetInfoFunctor0 f0 = { f, arg0 }; + return getInfoHelper(f0, name, param, 0); +} + +template +inline cl_int +getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param) +{ + GetInfoFunctor1 f0 = { f, arg0, arg1 }; + return getInfoHelper(f0, name, param, 0); +} + + +template +struct ReferenceHandler +{ }; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +/** + * OpenCL 1.2 devices do have retain/release. + */ +template <> +struct ReferenceHandler +{ + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int retain(cl_device_id device) + { return ::clRetainDevice(device); } + /** + * Retain the device. + * \param device A valid device created using createSubDevices + * \return + * CL_SUCCESS if the function executed successfully. + * CL_INVALID_DEVICE if device was not a valid subdevice + * CL_OUT_OF_RESOURCES + * CL_OUT_OF_HOST_MEMORY + */ + static cl_int release(cl_device_id device) + { return ::clReleaseDevice(device); } +}; +#else // CL_HPP_TARGET_OPENCL_VERSION >= 120 +/** + * OpenCL 1.1 devices do not have retain/release. + */ +template <> +struct ReferenceHandler +{ + // cl_device_id does not have retain(). + static cl_int retain(cl_device_id) + { return CL_SUCCESS; } + // cl_device_id does not have release(). + static cl_int release(cl_device_id) + { return CL_SUCCESS; } +}; +#endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120) + +template <> +struct ReferenceHandler +{ + // cl_platform_id does not have retain(). + static cl_int retain(cl_platform_id) + { return CL_SUCCESS; } + // cl_platform_id does not have release(). + static cl_int release(cl_platform_id) + { return CL_SUCCESS; } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_context context) + { return ::clRetainContext(context); } + static cl_int release(cl_context context) + { return ::clReleaseContext(context); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_command_queue queue) + { return ::clRetainCommandQueue(queue); } + static cl_int release(cl_command_queue queue) + { return ::clReleaseCommandQueue(queue); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_mem memory) + { return ::clRetainMemObject(memory); } + static cl_int release(cl_mem memory) + { return ::clReleaseMemObject(memory); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_sampler sampler) + { return ::clRetainSampler(sampler); } + static cl_int release(cl_sampler sampler) + { return ::clReleaseSampler(sampler); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_program program) + { return ::clRetainProgram(program); } + static cl_int release(cl_program program) + { return ::clReleaseProgram(program); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_kernel kernel) + { return ::clRetainKernel(kernel); } + static cl_int release(cl_kernel kernel) + { return ::clReleaseKernel(kernel); } +}; + +template <> +struct ReferenceHandler +{ + static cl_int retain(cl_event event) + { return ::clRetainEvent(event); } + static cl_int release(cl_event event) + { return ::clReleaseEvent(event); } +}; + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120 +// Extracts version number with major in the upper 16 bits, minor in the lower 16 +static cl_uint getVersion(const vector &versionInfo) +{ + int highVersion = 0; + int lowVersion = 0; + int index = 7; + while(versionInfo[index] != '.' ) { + highVersion *= 10; + highVersion += versionInfo[index]-'0'; + ++index; + } + ++index; + while(versionInfo[index] != ' ' && versionInfo[index] != '\0') { + lowVersion *= 10; + lowVersion += versionInfo[index]-'0'; + ++index; + } + return (highVersion << 16) | lowVersion; +} + +static cl_uint getPlatformVersion(cl_platform_id platform) +{ + size_type size = 0; + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size); + + vector versionInfo(size); + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size); + return getVersion(versionInfo); +} + +static cl_uint getDevicePlatformVersion(cl_device_id device) +{ + cl_platform_id platform; + clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL); + return getPlatformVersion(platform); +} + +static cl_uint getContextPlatformVersion(cl_context context) +{ + // The platform cannot be queried directly, so we first have to grab a + // device and obtain its context + size_type size = 0; + clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size); + if (size == 0) + return 0; + vector devices(size/sizeof(cl_device_id)); + clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL); + return getDevicePlatformVersion(devices[0]); +} +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120 + +template +class Wrapper +{ +public: + typedef T cl_type; + +protected: + cl_type object_; + +public: + Wrapper() : object_(NULL) { } + + Wrapper(const cl_type &obj, bool retainObject) : object_(obj) + { + if (retainObject) { + detail::errHandler(retain(), __RETAIN_ERR); + } + } + + ~Wrapper() + { + if (object_ != NULL) { release(); } + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + detail::errHandler(retain(), __RETAIN_ERR); + } + + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT_ + { + object_ = rhs.object_; + rhs.object_ = NULL; + } + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs.object_; + detail::errHandler(retain(), __RETAIN_ERR); + } + return *this; + } + + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs.object_; + rhs.object_ = NULL; + } + return *this; + } + + Wrapper& operator = (const cl_type &rhs) + { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs; + return *this; + } + + const cl_type& operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + + const cl_type get() const { return object_; } + + cl_type get() { return object_; } + + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + cl_int retain() const + { + if (object_ != nullptr) { + return ReferenceHandler::retain(object_); + } + else { + return CL_SUCCESS; + } + } + + cl_int release() const + { + if (object_ != nullptr) { + return ReferenceHandler::release(object_); + } + else { + return CL_SUCCESS; + } + } +}; + +template <> +class Wrapper +{ +public: + typedef cl_device_id cl_type; + +protected: + cl_type object_; + bool referenceCountable_; + + static bool isReferenceCountable(cl_device_id device) + { + bool retVal = false; +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +#if CL_HPP_MINIMUM_OPENCL_VERSION < 120 + if (device != NULL) { + int version = getDevicePlatformVersion(device); + if(version > ((1 << 16) + 1)) { + retVal = true; + } + } +#else // CL_HPP_MINIMUM_OPENCL_VERSION < 120 + retVal = true; +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120 +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + return retVal; + } + +public: + Wrapper() : object_(NULL), referenceCountable_(false) + { + } + + Wrapper(const cl_type &obj, bool retainObject) : + object_(obj), + referenceCountable_(false) + { + referenceCountable_ = isReferenceCountable(obj); + + if (retainObject) { + detail::errHandler(retain(), __RETAIN_ERR); + } + } + + ~Wrapper() + { + release(); + } + + Wrapper(const Wrapper& rhs) + { + object_ = rhs.object_; + referenceCountable_ = isReferenceCountable(object_); + detail::errHandler(retain(), __RETAIN_ERR); + } + + Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT_ + { + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } + + Wrapper& operator = (const Wrapper& rhs) + { + if (this != &rhs) { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + detail::errHandler(retain(), __RETAIN_ERR); + } + return *this; + } + + Wrapper& operator = (Wrapper&& rhs) + { + if (this != &rhs) { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs.object_; + referenceCountable_ = rhs.referenceCountable_; + rhs.object_ = NULL; + rhs.referenceCountable_ = false; + } + return *this; + } + + Wrapper& operator = (const cl_type &rhs) + { + detail::errHandler(release(), __RELEASE_ERR); + object_ = rhs; + referenceCountable_ = isReferenceCountable(object_); + return *this; + } + + const cl_type& operator ()() const { return object_; } + + cl_type& operator ()() { return object_; } + + const cl_type get() const { return object_; } + + cl_type get() { return object_; } + +protected: + template + friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); + + template + friend inline cl_int getInfoHelper(Func, cl_uint, vector*, int, typename U::cl_type); + + cl_int retain() const + { + if( object_ != nullptr && referenceCountable_ ) { + return ReferenceHandler::retain(object_); + } + else { + return CL_SUCCESS; + } + } + + cl_int release() const + { + if (object_ != nullptr && referenceCountable_) { + return ReferenceHandler::release(object_); + } + else { + return CL_SUCCESS; + } + } +}; + +template +inline bool operator==(const Wrapper &lhs, const Wrapper &rhs) +{ + return lhs() == rhs(); +} + +template +inline bool operator!=(const Wrapper &lhs, const Wrapper &rhs) +{ + return !operator==(lhs, rhs); +} + +} // namespace detail +//! \endcond + + +using BuildLogType = vector::param_type>>; +#if defined(CL_HPP_ENABLE_EXCEPTIONS) +/** +* Exception class for build errors to carry build info +*/ +class BuildError : public Error +{ +private: + BuildLogType buildLogs; +public: + BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec) + { + } + + BuildLogType getBuildLog() const + { + return buildLogs; + } +}; +namespace detail { + static inline cl_int buildErrHandler( + cl_int err, + const char * errStr, + const BuildLogType &buildLogs) + { + if (err != CL_SUCCESS) { + throw BuildError(err, errStr, buildLogs); + } + return err; + } +} // namespace detail + +#else +namespace detail { + static inline cl_int buildErrHandler( + cl_int err, + const char * errStr, + const BuildLogType &buildLogs) + { + (void)buildLogs; // suppress unused variable warning + (void)errStr; + return err; + } +} // namespace detail +#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS) + + +/*! \stuct ImageFormat + * \brief Adds constructors and member functions for cl_image_format. + * + * \see cl_image_format + */ +struct ImageFormat : public cl_image_format +{ + //! \brief Default constructor - performs no initialization. + ImageFormat(){} + + //! \brief Initializing constructor. + ImageFormat(cl_channel_order order, cl_channel_type type) + { + image_channel_order = order; + image_channel_data_type = type; + } + + //! \brief Assignment operator. + ImageFormat& operator = (const ImageFormat& rhs) + { + if (this != &rhs) { + this->image_channel_data_type = rhs.image_channel_data_type; + this->image_channel_order = rhs.image_channel_order; + } + return *this; + } +}; + +/*! \brief Class interface for cl_device_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_device_id + */ +class Device : public detail::Wrapper +{ +private: + static std::once_flag default_initialized_; + static Device default_; + static cl_int default_error_; + + /*! \brief Create the default context. + * + * This sets @c default_ and @c default_error_. It does not throw + * @c cl::Error. + */ + static void makeDefault(); + + /*! \brief Create the default platform from a provided platform. + * + * This sets @c default_. It does not throw + * @c cl::Error. + */ + static void makeDefaultProvided(const Device &p) { + default_ = p; + } + +public: +#ifdef CL_HPP_UNIT_TEST_ENABLE + /*! \brief Reset the default. + * + * This sets @c default_ to an empty value to support cleanup in + * the unit test framework. + * This function is not thread safe. + */ + static void unitTestClearDefault() { + default_ = Device(); + } +#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE + + //! \brief Default constructor - initializes to NULL. + Device() : detail::Wrapper() { } + + /*! \brief Constructor from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + explicit Device(const cl_device_id &device, bool retainObject = false) : + detail::Wrapper(device, retainObject) { } + + /*! \brief Returns the first device on the default context. + * + * \see Context::getDefault() + */ + static Device getDefault( + cl_int *errResult = NULL) + { + std::call_once(default_initialized_, makeDefault); + detail::errHandler(default_error_); + if (errResult != NULL) { + *errResult = default_error_; + } + return default_; + } + + /** + * Modify the default device to be used by + * subsequent operations. + * Will only set the default if no default was previously created. + * @return updated default device. + * Should be compared to the passed value to ensure that it was updated. + */ + static Device setDefault(const Device &default_device) + { + std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device)); + detail::errHandler(default_error_); + return default_; + } + + /*! \brief Assignment operator from cl_device_id. + * + * This simply copies the device ID value, which is an inexpensive operation. + */ + Device& operator = (const cl_device_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device(const Device& dev) : detail::Wrapper(dev) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (const Device &dev) + { + detail::Wrapper::operator=(dev); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Device(Device&& dev) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(dev)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Device& operator = (Device &&dev) + { + detail::Wrapper::operator=(std::move(dev)); + return *this; + } + + //! \brief Wrapper for clGetDeviceInfo(). + template + cl_int getInfo(cl_device_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetDeviceInfo, object_, name, param), + __GET_DEVICE_INFO_ERR); + } + + //! \brief Wrapper for clGetDeviceInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_device_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /** + * CL 1.2 version + */ +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + //! \brief Wrapper for clCreateSubDevices(). + cl_int createSubDevices( + const cl_device_partition_property * properties, + vector* devices) + { + cl_uint n = 0; + cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR); + } + + vector ids(n); + err = clCreateSubDevices(object_, properties, n, ids.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR); + } + + // Cannot trivially assign because we need to capture intermediates + // with safe construction + if (devices) { + devices->resize(ids.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < ids.size(); i++) { + // We do not need to retain because this device is being created + // by the runtime + (*devices)[i] = Device(ids[i], false); + } + } + + return CL_SUCCESS; + } +#elif defined(CL_HPP_USE_CL_DEVICE_FISSION) + +/** + * CL 1.1 version that uses device fission extension. + */ + cl_int createSubDevices( + const cl_device_partition_property_ext * properties, + vector* devices) + { + typedef CL_API_ENTRY cl_int + ( CL_API_CALL * PFN_clCreateSubDevicesEXT)( + cl_device_id /*in_device*/, + const cl_device_partition_property_ext * /* properties */, + cl_uint /*num_entries*/, + cl_device_id * /*out_devices*/, + cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; + + static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL; + CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT); + + cl_uint n = 0; + cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR); + } + + vector ids(n); + err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR); + } + // Cannot trivially assign because we need to capture intermediates + // with safe construction + if (devices) { + devices->resize(ids.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < ids.size(); i++) { + // We do not need to retain because this device is being created + // by the runtime + (*devices)[i] = Device(ids[i], false); + } + } + return CL_SUCCESS; + } +#endif // defined(CL_HPP_USE_CL_DEVICE_FISSION) +}; + +CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_; +CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_; +CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS; + +/*! \brief Class interface for cl_platform_id. + * + * \note Copies of these objects are inexpensive, since they don't 'own' + * any underlying resources or data structures. + * + * \see cl_platform_id + */ +class Platform : public detail::Wrapper +{ +private: + static std::once_flag default_initialized_; + static Platform default_; + static cl_int default_error_; + + /*! \brief Create the default context. + * + * This sets @c default_ and @c default_error_. It does not throw + * @c cl::Error. + */ + static void makeDefault() { + /* Throwing an exception from a call_once invocation does not do + * what we wish, so we catch it and save the error. + */ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try +#endif + { + // If default wasn't passed ,generate one + // Otherwise set it + cl_uint n = 0; + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + default_error_ = err; + return; + } + if (n == 0) { + default_error_ = CL_INVALID_PLATFORM; + return; + } + + vector ids(n); + err = ::clGetPlatformIDs(n, ids.data(), NULL); + if (err != CL_SUCCESS) { + default_error_ = err; + return; + } + + default_ = Platform(ids[0]); + } +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + catch (cl::Error &e) { + default_error_ = e.err(); + } +#endif + } + + /*! \brief Create the default platform from a provided platform. + * + * This sets @c default_. It does not throw + * @c cl::Error. + */ + static void makeDefaultProvided(const Platform &p) { + default_ = p; + } + +public: +#ifdef CL_HPP_UNIT_TEST_ENABLE + /*! \brief Reset the default. + * + * This sets @c default_ to an empty value to support cleanup in + * the unit test framework. + * This function is not thread safe. + */ + static void unitTestClearDefault() { + default_ = Platform(); + } +#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE + + //! \brief Default constructor - initializes to NULL. + Platform() : detail::Wrapper() { } + + /*! \brief Constructor from cl_platform_id. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * This simply copies the platform ID value, which is an inexpensive operation. + */ + explicit Platform(const cl_platform_id &platform, bool retainObject = false) : + detail::Wrapper(platform, retainObject) { } + + /*! \brief Assignment operator from cl_platform_id. + * + * This simply copies the platform ID value, which is an inexpensive operation. + */ + Platform& operator = (const cl_platform_id& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + static Platform getDefault( + cl_int *errResult = NULL) + { + std::call_once(default_initialized_, makeDefault); + detail::errHandler(default_error_); + if (errResult != NULL) { + *errResult = default_error_; + } + return default_; + } + + /** + * Modify the default platform to be used by + * subsequent operations. + * Will only set the default if no default was previously created. + * @return updated default platform. + * Should be compared to the passed value to ensure that it was updated. + */ + static Platform setDefault(const Platform &default_platform) + { + std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform)); + detail::errHandler(default_error_); + return default_; + } + + //! \brief Wrapper for clGetPlatformInfo(). + cl_int getInfo(cl_platform_info name, string* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetPlatformInfo, object_, name, param), + __GET_PLATFORM_INFO_ERR); + } + + //! \brief Wrapper for clGetPlatformInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_platform_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of devices for this platform. + * + * Wraps clGetDeviceIDs(). + */ + cl_int getDevices( + cl_device_type type, + vector* devices) const + { + cl_uint n = 0; + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n); + if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + vector ids(n); + if (n>0) { + err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + } + + // Cannot trivially assign because we need to capture intermediates + // with safe construction + // We must retain things we obtain from the API to avoid releasing + // API-owned objects. + if (devices) { + devices->resize(ids.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < ids.size(); i++) { + (*devices)[i] = Device(ids[i], true); + } + } + return CL_SUCCESS; + } + +#if defined(CL_HPP_USE_DX_INTEROP) + /*! \brief Get the list of available D3D10 devices. + * + * \param d3d_device_source. + * + * \param d3d_object. + * + * \param d3d_device_set. + * + * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device + * values returned in devices can be used to identify a specific OpenCL + * device. If \a devices argument is NULL, this argument is ignored. + * + * \return One of the following values: + * - CL_SUCCESS if the function is executed successfully. + * + * The application can query specific capabilities of the OpenCL device(s) + * returned by cl::getDevices. This can be used by the application to + * determine which device(s) to use. + * + * \note In the case that exceptions are enabled and a return value + * other than CL_SUCCESS is generated, then cl::Error exception is + * generated. + */ + cl_int getDevices( + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + vector* devices) const + { + typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)( + cl_platform_id platform, + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint* num_devices); + + if( devices == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); + } + + static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL; + CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR); + + cl_uint n = 0; + cl_int err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + 0, + NULL, + &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + vector ids(n); + err = pfn_clGetDeviceIDsFromD3D10KHR( + object_, + d3d_device_source, + d3d_object, + d3d_device_set, + n, + ids.data(), + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + // Cannot trivially assign because we need to capture intermediates + // with safe construction + // We must retain things we obtain from the API to avoid releasing + // API-owned objects. + if (devices) { + devices->resize(ids.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < ids.size(); i++) { + (*devices)[i] = Device(ids[i], true); + } + } + return CL_SUCCESS; + } +#endif + + /*! \brief Gets a list of available platforms. + * + * Wraps clGetPlatformIDs(). + */ + static cl_int get( + vector* platforms) + { + cl_uint n = 0; + + if( platforms == NULL ) { + return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); + } + + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + vector ids(n); + err = ::clGetPlatformIDs(n, ids.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); + } + + if (platforms) { + platforms->resize(ids.size()); + + // Platforms don't reference count + for (size_type i = 0; i < ids.size(); i++) { + (*platforms)[i] = Platform(ids[i]); + } + } + return CL_SUCCESS; + } + + /*! \brief Gets the first available platform. + * + * Wraps clGetPlatformIDs(), returning the first result. + */ + static cl_int get( + Platform * platform) + { + cl_int err; + Platform default_platform = Platform::getDefault(&err); + if (platform) { + *platform = default_platform; + } + return err; + } + + /*! \brief Gets the first available platform, returning it by value. + * + * \return Returns a valid platform if one is available. + * If no platform is available will return a null platform. + * Throws an exception if no platforms are available + * or an error condition occurs. + * Wraps clGetPlatformIDs(), returning the first result. + */ + static Platform get( + cl_int * errResult = NULL) + { + cl_int err; + Platform default_platform = Platform::getDefault(&err); + if (errResult) { + *errResult = err; + } + return default_platform; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + //! \brief Wrapper for clUnloadCompiler(). + cl_int + unloadCompiler() + { + return ::clUnloadPlatformCompiler(object_); + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +}; // class Platform + +CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_; +CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_; +CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS; + + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +/** + * Unload the OpenCL compiler. + * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead. + */ +inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int +UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +inline cl_int +UnloadCompiler() +{ + return ::clUnloadCompiler(); +} +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + +/*! \brief Class interface for cl_context. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_context as the original. For details, see + * clRetainContext() and clReleaseContext(). + * + * \see cl_context + */ +class Context + : public detail::Wrapper +{ +private: + static std::once_flag default_initialized_; + static Context default_; + static cl_int default_error_; + + /*! \brief Create the default context from the default device type in the default platform. + * + * This sets @c default_ and @c default_error_. It does not throw + * @c cl::Error. + */ + static void makeDefault() { + /* Throwing an exception from a call_once invocation does not do + * what we wish, so we catch it and save the error. + */ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try +#endif + { +#if !defined(__APPLE__) && !defined(__MACOS) + const Platform &p = Platform::getDefault(); + cl_platform_id defaultPlatform = p(); + cl_context_properties properties[3] = { + CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0 + }; +#else // #if !defined(__APPLE__) && !defined(__MACOS) + cl_context_properties *properties = nullptr; +#endif // #if !defined(__APPLE__) && !defined(__MACOS) + + default_ = Context( + CL_DEVICE_TYPE_DEFAULT, + properties, + NULL, + NULL, + &default_error_); + } +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + catch (cl::Error &e) { + default_error_ = e.err(); + } +#endif + } + + + /*! \brief Create the default context from a provided Context. + * + * This sets @c default_. It does not throw + * @c cl::Error. + */ + static void makeDefaultProvided(const Context &c) { + default_ = c; + } + +public: +#ifdef CL_HPP_UNIT_TEST_ENABLE + /*! \brief Reset the default. + * + * This sets @c default_ to an empty value to support cleanup in + * the unit test framework. + * This function is not thread safe. + */ + static void unitTestClearDefault() { + default_ = Context(); + } +#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE + + /*! \brief Constructs a context including a list of specified devices. + * + * Wraps clCreateContext(). + */ + Context( + const vector& devices, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + size_type, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + size_type numDevices = devices.size(); + vector deviceIDs(numDevices); + + for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateContext( + properties, (cl_uint) numDevices, + deviceIDs.data(), + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + Context( + const Device& device, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + size_type, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + + cl_device_id deviceID = device(); + + object_ = ::clCreateContext( + properties, 1, + &deviceID, + notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a context including all or a subset of devices of a specified type. + * + * Wraps clCreateContextFromType(). + */ + Context( + cl_device_type type, + cl_context_properties* properties = NULL, + void (CL_CALLBACK * notifyFptr)( + const char *, + const void *, + size_type, + void *) = NULL, + void* data = NULL, + cl_int* err = NULL) + { + cl_int error; + +#if !defined(__APPLE__) && !defined(__MACOS) + cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 }; + + if (properties == NULL) { + // Get a valid platform ID as we cannot send in a blank one + vector platforms; + error = Platform::get(&platforms); + if (error != CL_SUCCESS) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + // Check the platforms we found for a device of our specified type + cl_context_properties platform_id = 0; + for (unsigned int i = 0; i < platforms.size(); i++) { + + vector devices; + +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try { +#endif + + error = platforms[i].getDevices(type, &devices); + +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + } catch (Error) {} + // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type + // We do error checking next anyway, and can throw there if needed +#endif + + // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND + if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) { + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + if (devices.size() > 0) { + platform_id = (cl_context_properties)platforms[i](); + break; + } + } + + if (platform_id == 0) { + detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = CL_DEVICE_NOT_FOUND; + } + return; + } + + prop[1] = platform_id; + properties = &prop[0]; + } +#endif + object_ = ::clCreateContextFromType( + properties, type, notifyFptr, data, &error); + + detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context(const Context& ctx) : detail::Wrapper(ctx) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (const Context &ctx) + { + detail::Wrapper::operator=(ctx); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Context(Context&& ctx) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(ctx)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Context& operator = (Context &&ctx) + { + detail::Wrapper::operator=(std::move(ctx)); + return *this; + } + + + /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT. + * + * \note All calls to this function return the same cl_context as the first. + */ + static Context getDefault(cl_int * err = NULL) + { + std::call_once(default_initialized_, makeDefault); + detail::errHandler(default_error_); + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + /** + * Modify the default context to be used by + * subsequent operations. + * Will only set the default if no default was previously created. + * @return updated default context. + * Should be compared to the passed value to ensure that it was updated. + */ + static Context setDefault(const Context &default_context) + { + std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context)); + detail::errHandler(default_error_); + return default_; + } + + //! \brief Default constructor - initializes to NULL. + Context() : detail::Wrapper() { } + + /*! \brief Constructor from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the cl_context + * into the new Context object. + */ + explicit Context(const cl_context& context, bool retainObject = false) : + detail::Wrapper(context, retainObject) { } + + /*! \brief Assignment operator from cl_context - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseContext() on the value previously held by this instance. + */ + Context& operator = (const cl_context& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetContextInfo(). + template + cl_int getInfo(cl_context_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetContextInfo, object_, name, param), + __GET_CONTEXT_INFO_ERR); + } + + //! \brief Wrapper for clGetContextInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_context_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Gets a list of supported image formats. + * + * Wraps clGetSupportedImageFormats(). + */ + cl_int getSupportedImageFormats( + cl_mem_flags flags, + cl_mem_object_type type, + vector* formats) const + { + cl_uint numEntries; + + if (!formats) { + return CL_SUCCESS; + } + + cl_int err = ::clGetSupportedImageFormats( + object_, + flags, + type, + 0, + NULL, + &numEntries); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + if (numEntries > 0) { + vector value(numEntries); + err = ::clGetSupportedImageFormats( + object_, + flags, + type, + numEntries, + (cl_image_format*)value.data(), + NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); + } + + formats->assign(begin(value), end(value)); + } + else { + // If no values are being returned, ensure an empty vector comes back + formats->clear(); + } + + return CL_SUCCESS; + } +}; + +inline void Device::makeDefault() +{ + /* Throwing an exception from a call_once invocation does not do + * what we wish, so we catch it and save the error. + */ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try +#endif + { + cl_int error = 0; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + default_error_ = error; + } + else { + default_ = context.getInfo()[0]; + default_error_ = CL_SUCCESS; + } + } +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + catch (cl::Error &e) { + default_error_ = e.err(); + } +#endif +} + +CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_; +CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_; +CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS; + +/*! \brief Class interface for cl_event. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_event as the original. For details, see + * clRetainEvent() and clReleaseEvent(). + * + * \see cl_event + */ +class Event : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Event() : detail::Wrapper() { } + + /*! \brief Constructor from cl_event - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * This effectively transfers ownership of a refcount on the cl_event + * into the new Event object. + */ + explicit Event(const cl_event& event, bool retainObject = false) : + detail::Wrapper(event, retainObject) { } + + /*! \brief Assignment operator from cl_event - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseEvent() on the value previously held by this instance. + */ + Event& operator = (const cl_event& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + //! \brief Wrapper for clGetEventInfo(). + template + cl_int getInfo(cl_event_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetEventInfo, object_, name, param), + __GET_EVENT_INFO_ERR); + } + + //! \brief Wrapper for clGetEventInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_event_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + //! \brief Wrapper for clGetEventProfilingInfo(). + template + cl_int getProfilingInfo(cl_profiling_info name, T* param) const + { + return detail::errHandler(detail::getInfo( + &::clGetEventProfilingInfo, object_, name, param), + __GET_EVENT_PROFILE_INFO_ERR); + } + + //! \brief Wrapper for clGetEventProfilingInfo() that returns by value. + template typename + detail::param_traits::param_type + getProfilingInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_profiling_info, name>::param_type param; + cl_int result = getProfilingInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! \brief Blocks the calling thread until this event completes. + * + * Wraps clWaitForEvents(). + */ + cl_int wait() const + { + return detail::errHandler( + ::clWaitForEvents(1, &object_), + __WAIT_FOR_EVENTS_ERR); + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + /*! \brief Registers a user callback function for a specific command execution status. + * + * Wraps clSetEventCallback(). + */ + cl_int setCallback( + cl_int type, + void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetEventCallback( + object_, + type, + pfn_notify, + user_data), + __SET_EVENT_CALLBACK_ERR); + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + + /*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ + static cl_int + waitForEvents(const vector& events) + { + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); + } +}; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 +/*! \brief Class interface for user events (a subset of cl_event's). + * + * See Event for details about copy semantics, etc. + */ +class UserEvent : public Event +{ +public: + /*! \brief Constructs a user event on a given context. + * + * Wraps clCreateUserEvent(). + */ + UserEvent( + const Context& context, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateUserEvent( + context(), + &error); + + detail::errHandler(error, __CREATE_USER_EVENT_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + UserEvent() : Event() { } + + /*! \brief Sets the execution status of a user event object. + * + * Wraps clSetUserEventStatus(). + */ + cl_int setStatus(cl_int status) + { + return detail::errHandler( + ::clSetUserEventStatus(object_,status), + __SET_USER_EVENT_STATUS_ERR); + } +}; +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + +/*! \brief Blocks the calling thread until every event specified is complete. + * + * Wraps clWaitForEvents(). + */ +inline static cl_int +WaitForEvents(const vector& events) +{ + return detail::errHandler( + ::clWaitForEvents( + (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), + __WAIT_FOR_EVENTS_ERR); +} + +/*! \brief Class interface for cl_mem. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_mem as the original. For details, see + * clRetainMemObject() and clReleaseMemObject(). + * + * \see cl_mem + */ +class Memory : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Memory() : detail::Wrapper() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * Optionally transfer ownership of a refcount on the cl_mem + * into the new Memory object. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * + * See Memory for further details. + */ + explicit Memory(const cl_mem& memory, bool retainObject) : + detail::Wrapper(memory, retainObject) { } + + /*! \brief Assignment operator from cl_mem - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseMemObject() on the value previously held by this instance. + */ + Memory& operator = (const cl_mem& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory(const Memory& mem) : detail::Wrapper(mem) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (const Memory &mem) + { + detail::Wrapper::operator=(mem); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory(Memory&& mem) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(mem)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Memory& operator = (Memory &&mem) + { + detail::Wrapper::operator=(std::move(mem)); + return *this; + } + + + //! \brief Wrapper for clGetMemObjectInfo(). + template + cl_int getInfo(cl_mem_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetMemObjectInfo, object_, name, param), + __GET_MEM_OBJECT_INFO_ERR); + } + + //! \brief Wrapper for clGetMemObjectInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_mem_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + /*! \brief Registers a callback function to be called when the memory object + * is no longer needed. + * + * Wraps clSetMemObjectDestructorCallback(). + * + * Repeated calls to this function, for a given cl_mem value, will append + * to the list of functions called (in reverse order) when memory object's + * resources are freed and the memory object is deleted. + * + * \note + * The registered callbacks are associated with the underlying cl_mem + * value - not the Memory class instance. + */ + cl_int setDestructorCallback( + void (CL_CALLBACK * pfn_notify)(cl_mem, void *), + void * user_data = NULL) + { + return detail::errHandler( + ::clSetMemObjectDestructorCallback( + object_, + pfn_notify, + user_data), + __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR); + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + +}; + +// Pre-declare copy functions +class Buffer; +template< typename IteratorType > +cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); +template< typename IteratorType > +cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +namespace detail +{ + class SVMTraitNull + { + public: + static cl_svm_mem_flags getSVMMemFlags() + { + return 0; + } + }; +} // namespace detail + +template +class SVMTraitReadWrite +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return CL_MEM_READ_WRITE | + Trait::getSVMMemFlags(); + } +}; + +template +class SVMTraitReadOnly +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return CL_MEM_READ_ONLY | + Trait::getSVMMemFlags(); + } +}; + +template +class SVMTraitWriteOnly +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return CL_MEM_WRITE_ONLY | + Trait::getSVMMemFlags(); + } +}; + +template> +class SVMTraitCoarse +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return Trait::getSVMMemFlags(); + } +}; + +template> +class SVMTraitFine +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return CL_MEM_SVM_FINE_GRAIN_BUFFER | + Trait::getSVMMemFlags(); + } +}; + +template> +class SVMTraitAtomic +{ +public: + static cl_svm_mem_flags getSVMMemFlags() + { + return + CL_MEM_SVM_FINE_GRAIN_BUFFER | + CL_MEM_SVM_ATOMICS | + Trait::getSVMMemFlags(); + } +}; + +// Pre-declare SVM map function +template +inline cl_int enqueueMapSVM( + T* ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events = NULL, + Event* event = NULL); + +/** + * STL-like allocator class for managing SVM objects provided for convenience. + * + * Note that while this behaves like an allocator for the purposes of constructing vectors and similar objects, + * care must be taken when using with smart pointers. + * The allocator should not be used to construct a unique_ptr if we are using coarse-grained SVM mode because + * the coarse-grained management behaviour would behave incorrectly with respect to reference counting. + * + * Instead the allocator embeds a Deleter which may be used with unique_ptr and is used + * with the allocate_shared and allocate_ptr supplied operations. + */ +template +class SVMAllocator { +private: + Context context_; + +public: + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + template + struct rebind + { + typedef SVMAllocator other; + }; + + template + friend class SVMAllocator; + + SVMAllocator() : + context_(Context::getDefault()) + { + } + + explicit SVMAllocator(cl::Context context) : + context_(context) + { + } + + + SVMAllocator(const SVMAllocator &other) : + context_(other.context_) + { + } + + template + SVMAllocator(const SVMAllocator &other) : + context_(other.context_) + { + } + + ~SVMAllocator() + { + } + + pointer address(reference r) CL_HPP_NOEXCEPT_ + { + return std::addressof(r); + } + + const_pointer address(const_reference r) CL_HPP_NOEXCEPT_ + { + return std::addressof(r); + } + + /** + * Allocate an SVM pointer. + * + * If the allocator is coarse-grained, this will take ownership to allow + * containers to correctly construct data in place. + */ + pointer allocate( + size_type size, + typename cl::SVMAllocator::const_pointer = 0) + { + // Allocate memory with default alignment matching the size of the type + void* voidPointer = + clSVMAlloc( + context_(), + SVMTrait::getSVMMemFlags(), + size*sizeof(T), + 0); + pointer retValue = reinterpret_cast( + voidPointer); +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + if (!retValue) { + std::bad_alloc excep; + throw excep; + } +#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS) + + // If allocation was coarse-grained then map it + if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) { + cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T)); + if (err != CL_SUCCESS) { + std::bad_alloc excep; + throw excep; + } + } + + // If exceptions disabled, return null pointer from allocator + return retValue; + } + + void deallocate(pointer p, size_type) + { + clSVMFree(context_(), p); + } + + /** + * Return the maximum possible allocation size. + * This is the minimum of the maximum sizes of all devices in the context. + */ + size_type max_size() const CL_HPP_NOEXCEPT_ + { + size_type maxSize = std::numeric_limits::max() / sizeof(T); + + for (const Device &d : context_.getInfo()) { + maxSize = std::min( + maxSize, + static_cast(d.getInfo())); + } + + return maxSize; + } + + template< class U, class... Args > + void construct(U* p, Args&&... args) + { + new(p)T(args...); + } + + template< class U > + void destroy(U* p) + { + p->~U(); + } + + /** + * Returns true if the contexts match. + */ + inline bool operator==(SVMAllocator const& rhs) + { + return (context_==rhs.context_); + } + + inline bool operator!=(SVMAllocator const& a) + { + return !operator==(a); + } +}; // class SVMAllocator return cl::pointer(tmp, detail::Deleter{alloc, copies}); + + +template +class SVMAllocator { +public: + typedef void value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + + template + struct rebind + { + typedef SVMAllocator other; + }; + + template + friend class SVMAllocator; +}; + +#if !defined(CL_HPP_NO_STD_UNIQUE_PTR) +namespace detail +{ + template + class Deleter { + private: + Alloc alloc_; + size_type copies_; + + public: + typedef typename std::allocator_traits::pointer pointer; + + Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies } + { + } + + void operator()(pointer ptr) const { + Alloc tmpAlloc{ alloc_ }; + std::allocator_traits::destroy(tmpAlloc, std::addressof(*ptr)); + std::allocator_traits::deallocate(tmpAlloc, ptr, copies_); + } + }; +} // namespace detail + +/** + * Allocation operation compatible with std::allocate_ptr. + * Creates a unique_ptr by default. + * This requirement is to ensure that the control block is not + * allocated in memory inaccessible to the host. + */ +template +cl::pointer> allocate_pointer(const Alloc &alloc_, Args&&... args) +{ + Alloc alloc(alloc_); + static const size_type copies = 1; + + // Ensure that creation of the management block and the + // object are dealt with separately such that we only provide a deleter + + T* tmp = std::allocator_traits::allocate(alloc, copies); + if (!tmp) { + std::bad_alloc excep; + throw excep; + } + try { + std::allocator_traits::construct( + alloc, + std::addressof(*tmp), + std::forward(args)...); + + return cl::pointer>(tmp, detail::Deleter{alloc, copies}); + } + catch (std::bad_alloc b) + { + std::allocator_traits::deallocate(alloc, tmp, copies); + throw; + } +} + +template< class T, class SVMTrait, class... Args > +cl::pointer>> allocate_svm(Args... args) +{ + SVMAllocator alloc; + return cl::allocate_pointer(alloc, args...); +} + +template< class T, class SVMTrait, class... Args > +cl::pointer>> allocate_svm(const cl::Context &c, Args... args) +{ + SVMAllocator alloc(c); + return cl::allocate_pointer(alloc, args...); +} +#endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR) + +/*! \brief Vector alias to simplify contruction of coarse-grained SVM containers. + * + */ +template < class T > +using coarse_svm_vector = vector>>; + +/*! \brief Vector alias to simplify contruction of fine-grained SVM containers. +* +*/ +template < class T > +using fine_svm_vector = vector>>; + +/*! \brief Vector alias to simplify contruction of fine-grained SVM containers that support platform atomics. +* +*/ +template < class T > +using atomic_svm_vector = vector>>; + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + +/*! \brief Class interface for Buffer Memory Objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Buffer : public Memory +{ +public: + + /*! \brief Constructs a Buffer in a specified context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + */ + Buffer( + const Context& context, + cl_mem_flags flags, + size_type size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a Buffer in the default context. + * + * Wraps clCreateBuffer(). + * + * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was + * specified. Note alignment & exclusivity requirements. + * + * \see Context::getDefault() + */ + Buffer( + cl_mem_flags flags, + size_type size, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(err); + + object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer( + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr = false, + cl_int* err = NULL) + { + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + size_type size = sizeof(DataType)*(endIterator - startIterator); + + Context context = Context::getDefault(err); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + error = cl::copy(startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + } + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified context. + * IteratorType must be random access. + * If useHostPtr is specified iterators must represent contiguous data. + */ + template< typename IteratorType > + Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + /*! + * \brief Construct a Buffer from a host container via iterators using a specified queue. + * If useHostPtr is specified iterators must be random access. + */ + template< typename IteratorType > + Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, + bool readOnly, bool useHostPtr = false, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Buffer() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with earlier versions. + * + * See Memory for further details. + */ + explicit Buffer(const cl_mem& buffer, bool retainObject = false) : + Memory(buffer, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Buffer& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer(const Buffer& buf) : Memory(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (const Buffer &buf) + { + Memory::operator=(buf); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer(Buffer&& buf) CL_HPP_NOEXCEPT_ : Memory(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Buffer& operator = (Buffer &&buf) + { + Memory::operator=(std::move(buf)); + return *this; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + /*! \brief Creates a new buffer object from this. + * + * Wraps clCreateSubBuffer(). + */ + Buffer createSubBuffer( + cl_mem_flags flags, + cl_buffer_create_type buffer_create_type, + const void * buffer_create_info, + cl_int * err = NULL) + { + Buffer result; + cl_int error; + result.object_ = ::clCreateSubBuffer( + object_, + flags, + buffer_create_type, + buffer_create_info, + &error); + + detail::errHandler(error, __CREATE_SUBBUFFER_ERR); + if (err != NULL) { + *err = error; + } + + return result; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 +}; + +#if defined (CL_HPP_USE_DX_INTEROP) +/*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's. + * + * This is provided to facilitate interoperability with Direct3D. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferD3D10 : public Buffer +{ +public: + + + /*! \brief Constructs a BufferD3D10, in a specified context, from a + * given ID3D10Buffer. + * + * Wraps clCreateFromD3D10BufferKHR(). + */ + BufferD3D10( + const Context& context, + cl_mem_flags flags, + ID3D10Buffer* bufobj, + cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr) + { + typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)( + cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer, + cl_int* errcode_ret); + PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR; +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + vector props = context.getInfo(); + cl_platform platform = -1; + for( int i = 0; i < props.size(); ++i ) { + if( props[i] == CL_CONTEXT_PLATFORM ) { + platform = props[i+1]; + } + } + CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR); +#elif CL_HPP_TARGET_OPENCL_VERSION >= 110 + CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR); +#endif + + cl_int error; + object_ = pfn_clCreateFromD3D10BufferKHR( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferD3D10() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) : + Buffer(buffer, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferD3D10& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(const BufferD3D10& buf) : + Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (const BufferD3D10 &buf) + { + Buffer::operator=(buf); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferD3D10& operator = (BufferD3D10 &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } +}; +#endif + +/*! \brief Class interface for GL Buffer Memory Objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferGL : public Buffer +{ +public: + /*! \brief Constructs a BufferGL in a specified context, from a given + * GL buffer. + * + * Wraps clCreateFromGLBuffer(). + */ + BufferGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLBuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferGL() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit BufferGL(const cl_mem& buffer, bool retainObject = false) : + Buffer(buffer, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferGL& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL(const BufferGL& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (const BufferGL &buf) + { + Buffer::operator=(buf); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferGL& operator = (BufferGL &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_,type,gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief Class interface for GL Render Buffer Memory Objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class BufferRenderGL : public Buffer +{ +public: + /*! \brief Constructs a BufferRenderGL in a specified context, from a given + * GL Renderbuffer. + * + * Wraps clCreateFromGLRenderbuffer(). + */ + BufferRenderGL( + const Context& context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLRenderbuffer( + context(), + flags, + bufobj, + &error); + + detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + BufferRenderGL() : Buffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) : + Buffer(buffer, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + BufferRenderGL& operator = (const cl_mem& rhs) + { + Buffer::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL(const BufferRenderGL& buf) : Buffer(buf) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (const BufferRenderGL &buf) + { + Buffer::operator=(buf); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + BufferRenderGL& operator = (BufferRenderGL &&buf) + { + Buffer::operator=(std::move(buf)); + return *this; + } + + //! \brief Wrapper for clGetGLObjectInfo(). + cl_int getObjectInfo( + cl_gl_object_type *type, + cl_GLuint * gl_object_name) + { + return detail::errHandler( + ::clGetGLObjectInfo(object_,type,gl_object_name), + __GET_GL_OBJECT_INFO_ERR); + } +}; + +/*! \brief C++ base class for Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image : public Memory +{ +protected: + //! \brief Default constructor - initializes to NULL. + Image() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image(const cl_mem& image, bool retainObject = false) : + Memory(image, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image(const Image& img) : Memory(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (const Image &img) + { + Memory::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image(Image&& img) CL_HPP_NOEXCEPT_ : Memory(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image& operator = (Image &&img) + { + Memory::operator=(std::move(img)); + return *this; + } + + +public: + //! \brief Wrapper for clGetImageInfo(). + template + cl_int getImageInfo(cl_image_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetImageInfo, object_, name, param), + __GET_IMAGE_INFO_ERR); + } + + //! \brief Wrapper for clGetImageInfo() that returns by value. + template typename + detail::param_traits::param_type + getImageInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_image_info, name>::param_type param; + cl_int result = getImageInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +/*! \brief Class interface for 1D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image1D : public Image +{ +public: + /*! \brief Constructs a 1D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image1D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type width, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D, + width, + 0, 0, 0, 0, 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image1D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image1D(const cl_mem& image1D, bool retainObject = false) : + Image(image1D, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image1D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D(const Image1D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (const Image1D &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D(Image1D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1D& operator = (Image1D &&img) + { + Image::operator=(std::move(img)); + return *this; + } + +}; + +/*! \class Image1DBuffer + * \brief Image interface for 1D buffer images. + */ +class Image1DBuffer : public Image +{ +public: + Image1DBuffer( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type width, + const Buffer &buffer, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_BUFFER, + width, + 0, 0, 0, 0, 0, 0, 0, + buffer() + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + NULL, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DBuffer() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) : + Image(image1D, retainObject) { } + + Image1DBuffer& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(const Image1DBuffer& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (const Image1DBuffer &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DBuffer& operator = (Image1DBuffer &&img) + { + Image::operator=(std::move(img)); + return *this; + } + +}; + +/*! \class Image1DArray + * \brief Image interface for arrays of 1D images. + */ +class Image1DArray : public Image +{ +public: + Image1DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type arraySize, + size_type width, + size_type rowPitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE1D_ARRAY, + width, + 0, 0, // height, depth (unused) + arraySize, + rowPitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image1DArray() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) : + Image(imageArray, retainObject) { } + + + Image1DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(const Image1DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (const Image1DArray &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image1DArray& operator = (Image1DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } + +}; +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120 + + +/*! \brief Class interface for 2D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image2D : public Image +{ +public: + /*! \brief Constructs a 2D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image2D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type width, + size_type height, + size_type row_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120 + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif CL_HPP_TARGET_OPENCL_VERSION >= 120 + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D, + width, + height, + 0, 0, // depth, array size (unused) + row_pitch, + 0, 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#if CL_HPP_MINIMUM_OPENCL_VERSION < 120 + if (!useCreateImage) + { + object_ = ::clCreateImage2D( + context(), flags,&format, width, height, row_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE2D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120 + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR) + /*! \brief Constructs a 2D Image from a buffer. + * \note This will share storage with the underlying buffer. + * + * Wraps clCreateImage(). + */ + Image2D( + const Context& context, + ImageFormat format, + const Buffer &sourceBuffer, + size_type width, + size_type height, + size_type row_pitch = 0, + cl_int* err = nullptr) + { + cl_int error; + + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D, + width, + height, + 0, 0, // depth, array size (unused) + row_pitch, + 0, 0, 0, + // Use buffer as input to image + sourceBuffer() + }; + object_ = ::clCreateImage( + context(), + 0, // flags inherited from buffer + &format, + &desc, + nullptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != nullptr) { + *err = error; + } + } +#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR) + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /*! \brief Constructs a 2D Image from an image. + * \note This will share storage with the underlying image but may + * reinterpret the channel order and type. + * + * The image will be created matching with a descriptor matching the source. + * + * \param order is the channel order to reinterpret the image data as. + * The channel order may differ as described in the OpenCL + * 2.0 API specification. + * + * Wraps clCreateImage(). + */ + Image2D( + const Context& context, + cl_channel_order order, + const Image &sourceImage, + cl_int* err = nullptr) + { + cl_int error; + + // Descriptor fields have to match source image + size_type sourceWidth = + sourceImage.getImageInfo(); + size_type sourceHeight = + sourceImage.getImageInfo(); + size_type sourceRowPitch = + sourceImage.getImageInfo(); + cl_uint sourceNumMIPLevels = + sourceImage.getImageInfo(); + cl_uint sourceNumSamples = + sourceImage.getImageInfo(); + cl_image_format sourceFormat = + sourceImage.getImageInfo(); + + // Update only the channel order. + // Channel format inherited from source. + sourceFormat.image_channel_order = order; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D, + sourceWidth, + sourceHeight, + 0, 0, // depth (unused), array size (unused) + sourceRowPitch, + 0, // slice pitch (unused) + sourceNumMIPLevels, + sourceNumSamples, + // Use buffer as input to image + sourceImage() + }; + object_ = ::clCreateImage( + context(), + 0, // flags should be inherited from mem_object + &sourceFormat, + &desc, + nullptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != nullptr) { + *err = error; + } + } +#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + //! \brief Default constructor - initializes to NULL. + Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image2D(const cl_mem& image2D, bool retainObject = false) : + Image(image2D, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image2D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D(const Image2D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (const Image2D &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D(Image2D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2D& operator = (Image2D &&img) + { + Image::operator=(std::move(img)); + return *this; + } + +}; + + +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +/*! \brief Class interface for GL 2D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + * \note Deprecated for OpenCL 1.2. Please use ImageGL instead. + */ +class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D +{ +public: + /*! \brief Constructs an Image2DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture2D(). + */ + Image2DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture2D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR); + if (err != NULL) { + *err = error; + } + + } + + //! \brief Default constructor - initializes to NULL. + Image2DGL() : Image2D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image2DGL(const cl_mem& image, bool retainObject = false) : + Image2D(image, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + *c + * See Memory for further details. + */ + Image2DGL& operator = (const cl_mem& rhs) + { + Image2D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(const Image2DGL& img) : Image2D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (const Image2DGL &img) + { + Image2D::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT_ : Image2D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DGL& operator = (Image2DGL &&img) + { + Image2D::operator=(std::move(img)); + return *this; + } + +} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +/*! \class Image2DArray + * \brief Image interface for arrays of 2D images. + */ +class Image2DArray : public Image +{ +public: + Image2DArray( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type arraySize, + size_type width, + size_type height, + size_type rowPitch, + size_type slicePitch, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE2D_ARRAY, + width, + height, + 0, // depth (unused) + arraySize, + rowPitch, + slicePitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } + + Image2DArray() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { } + + Image2DArray& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(const Image2DArray& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (const Image2DArray &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image2DArray& operator = (Image2DArray &&img) + { + Image::operator=(std::move(img)); + return *this; + } +}; +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120 + +/*! \brief Class interface for 3D Image Memory objects. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3D : public Image +{ +public: + /*! \brief Constructs a 3D Image in a specified context. + * + * Wraps clCreateImage(). + */ + Image3D( + const Context& context, + cl_mem_flags flags, + ImageFormat format, + size_type width, + size_type height, + size_type depth, + size_type row_pitch = 0, + size_type slice_pitch = 0, + void* host_ptr = NULL, + cl_int* err = NULL) + { + cl_int error; + bool useCreateImage; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120 + // Run-time decision based on the actual platform + { + cl_uint version = detail::getContextPlatformVersion(context()); + useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above + } +#elif CL_HPP_TARGET_OPENCL_VERSION >= 120 + useCreateImage = true; +#else + useCreateImage = false; +#endif + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + if (useCreateImage) + { + cl_image_desc desc = + { + CL_MEM_OBJECT_IMAGE3D, + width, + height, + depth, + 0, // array size (unused) + row_pitch, + slice_pitch, + 0, 0, 0 + }; + object_ = ::clCreateImage( + context(), + flags, + &format, + &desc, + host_ptr, + &error); + + detail::errHandler(error, __CREATE_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#if CL_HPP_MINIMUM_OPENCL_VERSION < 120 + if (!useCreateImage) + { + object_ = ::clCreateImage3D( + context(), flags, &format, width, height, depth, row_pitch, + slice_pitch, host_ptr, &error); + + detail::errHandler(error, __CREATE_IMAGE3D_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120 + } + + //! \brief Default constructor - initializes to NULL. + Image3D() : Image() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image3D(const cl_mem& image3D, bool retainObject = false) : + Image(image3D, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3D& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D(const Image3D& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (const Image3D &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D(Image3D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3D& operator = (Image3D &&img) + { + Image::operator=(std::move(img)); + return *this; + } +}; + +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +/*! \brief Class interface for GL 3D Image Memory objects. + * + * This is provided to facilitate interoperability with OpenGL. + * + * See Memory for details about copy semantics, etc. + * + * \see Memory + */ +class Image3DGL : public Image3D +{ +public: + /*! \brief Constructs an Image3DGL in a specified context, from a given + * GL Texture. + * + * Wraps clCreateFromGLTexture3D(). + */ + Image3DGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture3D( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Image3DGL() : Image3D() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit Image3DGL(const cl_mem& image, bool retainObject = false) : + Image3D(image, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Image3DGL& operator = (const cl_mem& rhs) + { + Image3D::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(const Image3DGL& img) : Image3D(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (const Image3DGL &img) + { + Image3D::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT_ : Image3D(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Image3DGL& operator = (Image3DGL &&img) + { + Image3D::operator=(std::move(img)); + return *this; + } +}; +#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +/*! \class ImageGL + * \brief general image interface for GL interop. + * We abstract the 2D and 3D GL images into a single instance here + * that wraps all GL sourced images on the grounds that setup information + * was performed by OpenCL anyway. + */ +class ImageGL : public Image +{ +public: + ImageGL( + const Context& context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texobj, + cl_int * err = NULL) + { + cl_int error; + object_ = ::clCreateFromGLTexture( + context(), + flags, + target, + miplevel, + texobj, + &error); + + detail::errHandler(error, __CREATE_GL_TEXTURE_ERR); + if (err != NULL) { + *err = error; + } + } + + ImageGL() : Image() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * See Memory for further details. + */ + explicit ImageGL(const cl_mem& image, bool retainObject = false) : + Image(image, retainObject) { } + + ImageGL& operator = (const cl_mem& rhs) + { + Image::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL(const ImageGL& img) : Image(img) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (const ImageGL &img) + { + Image::operator=(img); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + ImageGL& operator = (ImageGL &&img) + { + Image::operator=(std::move(img)); + return *this; + } +}; +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +/*! \brief Class interface for Pipe Memory Objects. +* +* See Memory for details about copy semantics, etc. +* +* \see Memory +*/ +class Pipe : public Memory +{ +public: + + /*! \brief Constructs a Pipe in a specified context. + * + * Wraps clCreatePipe(). + * @param context Context in which to create the pipe. + * @param flags Bitfield. Only CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS are valid. + * @param packet_size Size in bytes of a single packet of the pipe. + * @param max_packets Number of packets that may be stored in the pipe. + * + */ + Pipe( + const Context& context, + cl_uint packet_size, + cl_uint max_packets, + cl_int* err = NULL) + { + cl_int error; + + cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS; + object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error); + + detail::errHandler(error, __CREATE_PIPE_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructs a Pipe in a the default context. + * + * Wraps clCreatePipe(). + * @param flags Bitfield. Only CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS are valid. + * @param packet_size Size in bytes of a single packet of the pipe. + * @param max_packets Number of packets that may be stored in the pipe. + * + */ + Pipe( + cl_uint packet_size, + cl_uint max_packets, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(err); + + cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS; + object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error); + + detail::errHandler(error, __CREATE_PIPE_ERR); + if (err != NULL) { + *err = error; + } + } + + //! \brief Default constructor - initializes to NULL. + Pipe() : Memory() { } + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with earlier versions. + * + * See Memory for further details. + */ + explicit Pipe(const cl_mem& pipe, bool retainObject = false) : + Memory(pipe, retainObject) { } + + /*! \brief Assignment from cl_mem - performs shallow copy. + * + * See Memory for further details. + */ + Pipe& operator = (const cl_mem& rhs) + { + Memory::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Pipe(const Pipe& pipe) : Memory(pipe) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Pipe& operator = (const Pipe &pipe) + { + Memory::operator=(pipe); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Pipe(Pipe&& pipe) CL_HPP_NOEXCEPT_ : Memory(std::move(pipe)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Pipe& operator = (Pipe &&pipe) + { + Memory::operator=(std::move(pipe)); + return *this; + } + + //! \brief Wrapper for clGetMemObjectInfo(). + template + cl_int getInfo(cl_pipe_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetPipeInfo, object_, name, param), + __GET_PIPE_INFO_ERR); + } + + //! \brief Wrapper for clGetMemObjectInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_pipe_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; // class Pipe +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200 + + +/*! \brief Class interface for cl_sampler. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_sampler as the original. For details, see + * clRetainSampler() and clReleaseSampler(). + * + * \see cl_sampler + */ +class Sampler : public detail::Wrapper +{ +public: + //! \brief Default constructor - initializes to NULL. + Sampler() { } + + /*! \brief Constructs a Sampler in a specified context. + * + * Wraps clCreateSampler(). + */ + Sampler( + const Context& context, + cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, + cl_int* err = NULL) + { + cl_int error; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_sampler_properties sampler_properties[] = { + CL_SAMPLER_NORMALIZED_COORDS, normalized_coords, + CL_SAMPLER_ADDRESSING_MODE, addressing_mode, + CL_SAMPLER_FILTER_MODE, filter_mode, + 0 }; + object_ = ::clCreateSamplerWithProperties( + context(), + sampler_properties, + &error); + + detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateSampler( + context(), + normalized_coords, + addressing_mode, + filter_mode, + &error); + + detail::errHandler(error, __CREATE_SAMPLER_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + + /*! \brief Constructor from cl_sampler - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * This effectively transfers ownership of a refcount on the cl_sampler + * into the new Sampler object. + */ + explicit Sampler(const cl_sampler& sampler, bool retainObject = false) : + detail::Wrapper(sampler, retainObject) { } + + /*! \brief Assignment operator from cl_sampler - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseSampler() on the value previously held by this instance. + */ + Sampler& operator = (const cl_sampler& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler(const Sampler& sam) : detail::Wrapper(sam) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (const Sampler &sam) + { + detail::Wrapper::operator=(sam); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler(Sampler&& sam) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(sam)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Sampler& operator = (Sampler &&sam) + { + detail::Wrapper::operator=(std::move(sam)); + return *this; + } + + //! \brief Wrapper for clGetSamplerInfo(). + template + cl_int getInfo(cl_sampler_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetSamplerInfo, object_, name, param), + __GET_SAMPLER_INFO_ERR); + } + + //! \brief Wrapper for clGetSamplerInfo() that returns by value. + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_sampler_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +}; + +class Program; +class CommandQueue; +class DeviceCommandQueue; +class Kernel; + +//! \brief Class interface for specifying NDRange values. +class NDRange +{ +private: + size_type sizes_[3]; + cl_uint dimensions_; + +public: + //! \brief Default constructor - resulting range has zero dimensions. + NDRange() + : dimensions_(0) + { + sizes_[0] = 0; + sizes_[1] = 0; + sizes_[2] = 0; + } + + //! \brief Constructs one-dimensional range. + NDRange(size_type size0) + : dimensions_(1) + { + sizes_[0] = size0; + sizes_[1] = 1; + sizes_[2] = 1; + } + + //! \brief Constructs two-dimensional range. + NDRange(size_type size0, size_type size1) + : dimensions_(2) + { + sizes_[0] = size0; + sizes_[1] = size1; + sizes_[2] = 1; + } + + //! \brief Constructs three-dimensional range. + NDRange(size_type size0, size_type size1, size_type size2) + : dimensions_(3) + { + sizes_[0] = size0; + sizes_[1] = size1; + sizes_[2] = size2; + } + + /*! \brief Conversion operator to const size_type *. + * + * \returns a pointer to the size of the first dimension. + */ + operator const size_type*() const { + return sizes_; + } + + //! \brief Queries the number of dimensions in the range. + size_type dimensions() const + { + return dimensions_; + } + + //! \brief Returns the size of the object in bytes based on the + // runtime number of dimensions + size_type size() const + { + return dimensions_*sizeof(size_type); + } + + size_type* get() + { + return sizes_; + } + + const size_type* get() const + { + return sizes_; + } +}; + +//! \brief A zero-dimensional range. +static const NDRange NullRange; + +//! \brief Local address wrapper for use with Kernel::setArg +struct LocalSpaceArg +{ + size_type size_; +}; + +namespace detail { + +template +struct KernelArgumentHandler; + +// Enable for objects that are not subclasses of memory +// Pointers, constants etc +template +struct KernelArgumentHandler::value>::type> +{ + static size_type size(const T&) { return sizeof(T); } + static const T* ptr(const T& value) { return &value; } +}; + +// Enable for subclasses of memory where we want to get a reference to the cl_mem out +// and pass that in for safety +template +struct KernelArgumentHandler::value>::type> +{ + static size_type size(const T&) { return sizeof(cl_mem); } + static const cl_mem* ptr(const T& value) { return &(value()); } +}; + +// Specialization for DeviceCommandQueue defined later + +template <> +struct KernelArgumentHandler +{ + static size_type size(const LocalSpaceArg& value) { return value.size_; } + static const void* ptr(const LocalSpaceArg&) { return NULL; } +}; + +} +//! \endcond + +/*! Local + * \brief Helper function for generating LocalSpaceArg objects. + */ +inline LocalSpaceArg +Local(size_type size) +{ + LocalSpaceArg ret = { size }; + return ret; +} + +/*! \brief Class interface for cl_kernel. + * + * \note Copies of these objects are shallow, meaning that the copy will refer + * to the same underlying cl_kernel as the original. For details, see + * clRetainKernel() and clReleaseKernel(). + * + * \see cl_kernel + */ +class Kernel : public detail::Wrapper +{ +public: + inline Kernel(const Program& program, const char* name, cl_int* err = NULL); + + //! \brief Default constructor - initializes to NULL. + Kernel() { } + + /*! \brief Constructor from cl_kernel - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + * This effectively transfers ownership of a refcount on the cl_kernel + * into the new Kernel object. + */ + explicit Kernel(const cl_kernel& kernel, bool retainObject = false) : + detail::Wrapper(kernel, retainObject) { } + + /*! \brief Assignment operator from cl_kernel - takes ownership. + * + * This effectively transfers ownership of a refcount on the rhs and calls + * clReleaseKernel() on the value previously held by this instance. + */ + Kernel& operator = (const cl_kernel& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel(const Kernel& kernel) : detail::Wrapper(kernel) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (const Kernel &kernel) + { + detail::Wrapper::operator=(kernel); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(kernel)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Kernel& operator = (Kernel &&kernel) + { + detail::Wrapper::operator=(std::move(kernel)); + return *this; + } + + template + cl_int getInfo(cl_kernel_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelInfo, object_, name, param), + __GET_KERNEL_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + template + cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param), + __GET_KERNEL_ARG_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getArgInfo(cl_uint argIndex, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_arg_info, name>::param_type param; + cl_int result = getArgInfo(argIndex, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + template + cl_int getWorkGroupInfo( + const Device& device, cl_kernel_work_group_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetKernelWorkGroupInfo, object_, device(), name, param), + __GET_KERNEL_WORK_GROUP_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getWorkGroupInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_kernel_work_group_info, name>::param_type param; + cl_int result = getWorkGroupInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +#if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) + cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const + { + typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR; + static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL; + CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR); + + return detail::errHandler( + pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr), + __GET_KERNEL_ARG_INFO_ERR); + } + + template + size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = NULL) const + { + size_type param; + cl_int result = getSubGroupInfo(dev, name, range, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } +#endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /*! \brief setArg overload taking a shared_ptr type + */ + template + cl_int setArg(cl_uint index, const cl::pointer &argPtr) + { + return detail::errHandler( + ::clSetKernelArgSVMPointer(object_, index, argPtr.get()), + __SET_KERNEL_ARGS_ERR); + } + + /*! \brief setArg overload taking a vector type. + */ + template + cl_int setArg(cl_uint index, const cl::vector &argPtr) + { + return detail::errHandler( + ::clSetKernelArgSVMPointer(object_, index, argPtr.data()), + __SET_KERNEL_ARGS_ERR); + } + + /*! \brief setArg overload taking a pointer type + */ + template + typename std::enable_if::value, cl_int>::type + setArg(cl_uint index, const T argPtr) + { + return detail::errHandler( + ::clSetKernelArgSVMPointer(object_, index, argPtr), + __SET_KERNEL_ARGS_ERR); + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + /*! \brief setArg overload taking a POD type + */ + template + typename std::enable_if::value, cl_int>::type + setArg(cl_uint index, const T &value) + { + return detail::errHandler( + ::clSetKernelArg( + object_, + index, + detail::KernelArgumentHandler::size(value), + detail::KernelArgumentHandler::ptr(value)), + __SET_KERNEL_ARGS_ERR); + } + + cl_int setArg(cl_uint index, size_type size, const void* argPtr) + { + return detail::errHandler( + ::clSetKernelArg(object_, index, size, argPtr), + __SET_KERNEL_ARGS_ERR); + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /*! + * Specify a vector of SVM pointers that the kernel may access in + * addition to its arguments. + */ + cl_int setSVMPointers(const vector &pointerList) + { + return detail::errHandler( + ::clSetKernelExecInfo( + object_, + CL_KERNEL_EXEC_INFO_SVM_PTRS, + sizeof(void*)*pointerList.size(), + pointerList.data())); + } + + /*! + * Specify a std::array of SVM pointers that the kernel may access in + * addition to its arguments. + */ + template + cl_int setSVMPointers(const std::array &pointerList) + { + return detail::errHandler( + ::clSetKernelExecInfo( + object_, + CL_KERNEL_EXEC_INFO_SVM_PTRS, + sizeof(void*)*pointerList.size(), + pointerList.data())); + } + + /*! \brief Enable fine-grained system SVM. + * + * \note It is only possible to enable fine-grained system SVM if all devices + * in the context associated with kernel support it. + * + * \param svmEnabled True if fine-grained system SVM is requested. False otherwise. + * \return CL_SUCCESS if the function was executed succesfully. CL_INVALID_OPERATION + * if no devices in the context support fine-grained system SVM. + * + * \see clSetKernelExecInfo + */ + cl_int enableFineGrainedSystemSVM(bool svmEnabled) + { + cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE; + return detail::errHandler( + ::clSetKernelExecInfo( + object_, + CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, + sizeof(cl_bool), + &svmEnabled_ + ) + ); + } + + template + void setSVMPointersHelper(std::array &pointerList, const pointer &t0, Ts... ts) + { + pointerList[index] = static_cast(t0.get()); + setSVMPointersHelper(ts...); + } + + template + typename std::enable_if::value, void>::type + setSVMPointersHelper(std::array &pointerList, T0 t0, Ts... ts) + { + pointerList[index] = static_cast(t0); + setSVMPointersHelper(ts...); + } + + template + void setSVMPointersHelper(std::array &pointerList, const pointer &t0) + { + pointerList[index] = static_cast(t0.get()); + } + + template + typename std::enable_if::value, void>::type + setSVMPointersHelper(std::array &pointerList, T0 t0) + { + pointerList[index] = static_cast(t0); + } + + template + cl_int setSVMPointers(const T0 &t0, Ts... ts) + { + std::array pointerList; + + setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...); + return detail::errHandler( + ::clSetKernelExecInfo( + object_, + CL_KERNEL_EXEC_INFO_SVM_PTRS, + sizeof(void*)*(1 + sizeof...(Ts)), + pointerList.data())); + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 +}; + +/*! \class Program + * \brief Program interface that implements cl_program. + */ +class Program : public detail::Wrapper +{ +public: +#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + typedef vector> Binaries; + typedef vector Sources; +#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + typedef vector > Binaries; + typedef vector > Sources; +#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + + Program( + const string& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const size_type length = source.size(); + + Context context = Context::getDefault(err); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + + error = ::clBuildProgram( + object_, + 0, + NULL, +#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD) + "-cl-std=CL2.0", +#else + "", +#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD) + NULL, + NULL); + + detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo()); + } + + if (err != NULL) { + *err = error; + } + } + + Program( + const Context& context, + const string& source, + bool build = false, + cl_int* err = NULL) + { + cl_int error; + + const char * strings = source.c_str(); + const size_type length = source.size(); + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)1, &strings, &length, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + + if (error == CL_SUCCESS && build) { + error = ::clBuildProgram( + object_, + 0, + NULL, +#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD) + "-cl-std=CL2.0", +#else + "", +#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD) + NULL, + NULL); + + detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo()); + } + + if (err != NULL) { + *err = error; + } + } + + /** + * Create a program from a vector of source strings and the default context. + * Does not compile or link the program. + */ + Program( + const Sources& sources, + cl_int* err = NULL) + { + cl_int error; + Context context = Context::getDefault(err); + + const size_type n = (size_type)sources.size(); + + vector lengths(n); + vector strings(n); + + for (size_type i = 0; i < n; ++i) { +#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + strings[i] = sources[(int)i].data(); + lengths[i] = sources[(int)i].length(); +#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + strings[i] = sources[(int)i].first; + lengths[i] = sources[(int)i].second; +#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + } + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)n, strings.data(), lengths.data(), &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + if (err != NULL) { + *err = error; + } + } + + /** + * Create a program from a vector of source strings and a provided context. + * Does not compile or link the program. + */ + Program( + const Context& context, + const Sources& sources, + cl_int* err = NULL) + { + cl_int error; + + const size_type n = (size_type)sources.size(); + + vector lengths(n); + vector strings(n); + + for (size_type i = 0; i < n; ++i) { +#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + strings[i] = sources[(int)i].data(); + lengths[i] = sources[(int)i].length(); +#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + strings[i] = sources[(int)i].first; + lengths[i] = sources[(int)i].second; +#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + } + + object_ = ::clCreateProgramWithSource( + context(), (cl_uint)n, strings.data(), lengths.data(), &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); + if (err != NULL) { + *err = error; + } + } + + /** + * Construct a program object from a list of devices and a per-device list of binaries. + * \param context A valid OpenCL context in which to construct the program. + * \param devices A vector of OpenCL device objects for which the program will be created. + * \param binaries A vector of pairs of a pointer to a binary object and its length. + * \param binaryStatus An optional vector that on completion will be resized to + * match the size of binaries and filled with values to specify if each binary + * was successfully loaded. + * Set to CL_SUCCESS if the binary was successfully loaded. + * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL. + * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device. + * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors: + * CL_INVALID_CONTEXT if context is not a valid context. + * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices; + * or if any entry in binaries is NULL or has length 0. + * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context. + * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device. + * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host. + */ + Program( + const Context& context, + const vector& devices, + const Binaries& binaries, + vector* binaryStatus = NULL, + cl_int* err = NULL) + { + cl_int error; + + const size_type numDevices = devices.size(); + + // Catch size mismatch early and return + if(binaries.size() != numDevices) { + error = CL_INVALID_VALUE; + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + return; + } + + + vector lengths(numDevices); + vector images(numDevices); +#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + for (size_type i = 0; i < numDevices; ++i) { + images[i] = binaries[i].data(); + lengths[i] = binaries[(int)i].size(); + } +#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + for (size_type i = 0; i < numDevices; ++i) { + images[i] = (const unsigned char*)binaries[i].first; + lengths[i] = binaries[(int)i].second; + } +#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY) + + vector deviceIDs(numDevices); + for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + if(binaryStatus) { + binaryStatus->resize(numDevices); + } + + object_ = ::clCreateProgramWithBinary( + context(), (cl_uint) devices.size(), + deviceIDs.data(), + lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0) + ? &binaryStatus->front() + : NULL, &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); + if (err != NULL) { + *err = error; + } + } + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + /** + * Create program using builtin kernels. + * \param kernelNames Semi-colon separated list of builtin kernel names + */ + Program( + const Context& context, + const vector& devices, + const string& kernelNames, + cl_int* err = NULL) + { + cl_int error; + + + size_type numDevices = devices.size(); + vector deviceIDs(numDevices); + for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + object_ = ::clCreateProgramWithBuiltInKernels( + context(), + (cl_uint) devices.size(), + deviceIDs.data(), + kernelNames.c_str(), + &error); + + detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR); + if (err != NULL) { + *err = error; + } + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + Program() { } + + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + */ + explicit Program(const cl_program& program, bool retainObject = false) : + detail::Wrapper(program, retainObject) { } + + Program& operator = (const cl_program& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program(const Program& program) : detail::Wrapper(program) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (const Program &program) + { + detail::Wrapper::operator=(program); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + Program(Program&& program) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(program)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + Program& operator = (Program &&program) + { + detail::Wrapper::operator=(std::move(program)); + return *this; + } + + cl_int build( + const vector& devices, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + size_type numDevices = devices.size(); + vector deviceIDs(numDevices); + + for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { + deviceIDs[deviceIndex] = (devices[deviceIndex])(); + } + + cl_int buildError = ::clBuildProgram( + object_, + (cl_uint) + devices.size(), + deviceIDs.data(), + options, + notifyFptr, + data); + + return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo()); + } + + cl_int build( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + cl_int buildError = ::clBuildProgram( + object_, + 0, + NULL, + options, + notifyFptr, + data); + + + return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo()); + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + cl_int compile( + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL) const + { + cl_int error = ::clCompileProgram( + object_, + 0, + NULL, + options, + 0, + NULL, + NULL, + notifyFptr, + data); + return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo()); + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + template + cl_int getInfo(cl_program_info name, T* param) const + { + return detail::errHandler( + detail::getInfo(&::clGetProgramInfo, object_, name, param), + __GET_PROGRAM_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + template + cl_int getBuildInfo( + const Device& device, cl_program_build_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetProgramBuildInfo, object_, device(), name, param), + __GET_PROGRAM_BUILD_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getBuildInfo(const Device& device, cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_program_build_info, name>::param_type param; + cl_int result = getBuildInfo(device, name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /** + * Build info function that returns a vector of device/info pairs for the specified + * info type and for all devices in the program. + * On an error reading the info for any device, an empty vector of info will be returned. + */ + template + vector::param_type>> + getBuildInfo(cl_int *err = NULL) const + { + cl_int result = CL_SUCCESS; + + auto devs = getInfo(&result); + vector::param_type>> + devInfo; + + // If there was an initial error from getInfo return the error + if (result != CL_SUCCESS) { + if (err != NULL) { + *err = result; + } + return devInfo; + } + + for (const cl::Device &d : devs) { + typename detail::param_traits< + detail::cl_program_build_info, name>::param_type param; + result = getBuildInfo(d, name, ¶m); + devInfo.push_back( + std::pair::param_type> + (d, param)); + if (result != CL_SUCCESS) { + // On error, leave the loop and return the error code + break; + } + } + if (err != NULL) { + *err = result; + } + if (result != CL_SUCCESS) { + devInfo.clear(); + } + return devInfo; + } + + cl_int createKernels(vector* kernels) + { + cl_uint numKernels; + cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + vector value(numKernels); + + err = ::clCreateKernelsInProgram( + object_, numKernels, value.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); + } + + if (kernels) { + kernels->resize(value.size()); + + // Assign to param, constructing with retain behaviour + // to correctly capture each underlying CL object + for (size_type i = 0; i < value.size(); i++) { + // We do not need to retain because this kernel is being created + // by the runtime + (*kernels)[i] = Kernel(value[i], false); + } + } + return CL_SUCCESS; + } +}; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 +inline Program linkProgram( + Program input1, + Program input2, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + cl_program programs[2] = { input1(), input2() }; + + Context ctx = input1.getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + 2, + programs, + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog); +} + +inline Program linkProgram( + vector inputPrograms, + const char* options = NULL, + void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, + void* data = NULL, + cl_int* err = NULL) +{ + cl_int error_local = CL_SUCCESS; + + vector programs(inputPrograms.size()); + + for (unsigned int i = 0; i < inputPrograms.size(); i++) { + programs[i] = inputPrograms[i](); + } + + Context ctx; + if(inputPrograms.size() > 0) { + ctx = inputPrograms[0].getInfo(&error_local); + if(error_local!=CL_SUCCESS) { + detail::errHandler(error_local, __LINK_PROGRAM_ERR); + } + } + cl_program prog = ::clLinkProgram( + ctx(), + 0, + NULL, + options, + (cl_uint)inputPrograms.size(), + programs.data(), + notifyFptr, + data, + &error_local); + + detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); + if (err != NULL) { + *err = error_local; + } + + return Program(prog, false); +} +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + +// Template specialization for CL_PROGRAM_BINARIES +template <> +inline cl_int cl::Program::getInfo(cl_program_info name, vector>* param) const +{ + if (name != CL_PROGRAM_BINARIES) { + return CL_INVALID_VALUE; + } + if (param) { + // Resize the parameter array appropriately for each allocation + // and pass down to the helper + + vector sizes = getInfo(); + size_type numBinaries = sizes.size(); + + // Resize the parameter array and constituent arrays + param->resize(numBinaries); + for (size_type i = 0; i < numBinaries; ++i) { + (*param)[i].resize(sizes[i]); + } + + return detail::errHandler( + detail::getInfo(&::clGetProgramInfo, object_, name, param), + __GET_PROGRAM_INFO_ERR); + } + + return CL_SUCCESS; +} + +template<> +inline vector> cl::Program::getInfo(cl_int* err) const +{ + vector> binariesVectors; + + cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors); + if (err != NULL) { + *err = result; + } + return binariesVectors; +} + +inline Kernel::Kernel(const Program& program, const char* name, cl_int* err) +{ + cl_int error; + + object_ = ::clCreateKernel(program(), name, &error); + detail::errHandler(error, __CREATE_KERNEL_ERR); + + if (err != NULL) { + *err = error; + } + +} + +enum class QueueProperties : cl_command_queue_properties +{ + None = 0, + Profiling = CL_QUEUE_PROFILING_ENABLE, + OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, +}; + +inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs) +{ + return static_cast(static_cast(lhs) | static_cast(rhs)); +} + +/*! \class CommandQueue + * \brief CommandQueue interface for cl_command_queue. + */ +class CommandQueue : public detail::Wrapper +{ +private: + static std::once_flag default_initialized_; + static CommandQueue default_; + static cl_int default_error_; + + /*! \brief Create the default command queue returned by @ref getDefault. + * + * It sets default_error_ to indicate success or failure. It does not throw + * @c cl::Error. + */ + static void makeDefault() + { + /* We don't want to throw an error from this function, so we have to + * catch and set the error flag. + */ +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + try +#endif + { + int error; + Context context = Context::getDefault(&error); + + if (error != CL_SUCCESS) { + default_error_ = error; + } + else { + Device device = Device::getDefault(); + default_ = CommandQueue(context, device, 0, &default_error_); + } + } +#if defined(CL_HPP_ENABLE_EXCEPTIONS) + catch (cl::Error &e) { + default_error_ = e.err(); + } +#endif + } + + /*! \brief Create the default command queue. + * + * This sets @c default_. It does not throw + * @c cl::Error. + */ + static void makeDefaultProvided(const CommandQueue &c) { + default_ = c; + } + +public: +#ifdef CL_HPP_UNIT_TEST_ENABLE + /*! \brief Reset the default. + * + * This sets @c default_ to an empty value to support cleanup in + * the unit test framework. + * This function is not thread safe. + */ + static void unitTestClearDefault() { + default_ = CommandQueue(); + } +#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE + + + /*! + * \brief Constructs a CommandQueue based on passed properties. + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + CommandQueue( + cl_command_queue_properties properties, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, 0 }; + if ((properties & CL_QUEUE_ON_DEVICE) == 0) { + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + } + else { + error = CL_INVALID_QUEUE_PROPERTIES; + } + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + } + + /*! + * \brief Constructs a CommandQueue based on passed properties. + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + CommandQueue( + QueueProperties properties, + cl_int* err = NULL) + { + cl_int error; + + Context context = Context::getDefault(&error); + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) { + if (err != NULL) { + *err = error; + } + } + else { + Device device = context.getInfo()[0]; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, static_cast(properties), 0 }; + + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), device(), static_cast(properties), &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + } + + /*! + * \brief Constructs a CommandQueue for an implementation defined device in the given context + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + explicit CommandQueue( + const Context& context, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + vector devices; + error = context.getInfo(CL_CONTEXT_DEVICES, &devices); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) + { + if (err != NULL) { + *err = error; + } + return; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, 0 }; + if ((properties & CL_QUEUE_ON_DEVICE) == 0) { + object_ = ::clCreateCommandQueueWithProperties( + context(), devices[0](), queue_properties, &error); + } + else { + error = CL_INVALID_QUEUE_PROPERTIES; + } + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), devices[0](), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + + } + + /*! + * \brief Constructs a CommandQueue for an implementation defined device in the given context + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + explicit CommandQueue( + const Context& context, + QueueProperties properties, + cl_int* err = NULL) + { + cl_int error; + vector devices; + error = context.getInfo(CL_CONTEXT_DEVICES, &devices); + + detail::errHandler(error, __CREATE_CONTEXT_ERR); + + if (error != CL_SUCCESS) + { + if (err != NULL) { + *err = error; + } + return; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, static_cast(properties), 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), devices[0](), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), devices[0](), static_cast(properties), &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + + } + + /*! + * \brief Constructs a CommandQueue for a passed device and context + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + CommandQueue( + const Context& context, + const Device& device, + cl_command_queue_properties properties = 0, + cl_int* err = NULL) + { + cl_int error; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), device(), properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + + /*! + * \brief Constructs a CommandQueue for a passed device and context + * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified. + */ + CommandQueue( + const Context& context, + const Device& device, + QueueProperties properties, + cl_int* err = NULL) + { + cl_int error; + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, static_cast(properties), 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } +#else + object_ = ::clCreateCommandQueue( + context(), device(), static_cast(properties), &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); + if (err != NULL) { + *err = error; + } +#endif + } + + static CommandQueue getDefault(cl_int * err = NULL) + { + std::call_once(default_initialized_, makeDefault); +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); +#else // CL_HPP_TARGET_OPENCL_VERSION >= 200 + detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR); +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200 + if (err != NULL) { + *err = default_error_; + } + return default_; + } + + /** + * Modify the default command queue to be used by + * subsequent operations. + * Will only set the default if no default was previously created. + * @return updated default command queue. + * Should be compared to the passed value to ensure that it was updated. + */ + static CommandQueue setDefault(const CommandQueue &default_queue) + { + std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue)); + detail::errHandler(default_error_); + return default_; + } + + CommandQueue() { } + + + /*! \brief Constructor from cl_mem - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + */ + explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) : + detail::Wrapper(commandQueue, retainObject) { } + + CommandQueue& operator = (const cl_command_queue& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(const CommandQueue& queue) : detail::Wrapper(queue) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (const CommandQueue &queue) + { + detail::Wrapper::operator=(queue); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(queue)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + CommandQueue& operator = (CommandQueue &&queue) + { + detail::Wrapper::operator=(std::move(queue)); + return *this; + } + + template + cl_int getInfo(cl_command_queue_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetCommandQueueInfo, object_, name, param), + __GET_COMMAND_QUEUE_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_command_queue_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + size_type offset, + size_type size, + void* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + size_type offset, + size_type size, + const void* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBuffer( + object_, buffer(), blocking, offset, size, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + size_type src_offset, + size_type dst_offset, + size_type size, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBuffer( + object_, src(), dst(), src_offset, dst_offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const array& buffer_offset, + const array& host_offset, + const array& region, + size_type buffer_row_pitch, + size_type buffer_slice_pitch, + size_type host_row_pitch, + size_type host_slice_pitch, + void *ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadBufferRect( + object_, + buffer(), + blocking, + buffer_offset.data(), + host_offset.data(), + region.data(), + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const array& buffer_offset, + const array& host_offset, + const array& region, + size_type buffer_row_pitch, + size_type buffer_slice_pitch, + size_type host_row_pitch, + size_type host_slice_pitch, + const void *ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteBufferRect( + object_, + buffer(), + blocking, + buffer_offset.data(), + host_offset.data(), + region.data(), + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const array& src_origin, + const array& dst_origin, + const array& region, + size_type src_row_pitch, + size_type src_slice_pitch, + size_type dst_row_pitch, + size_type dst_slice_pitch, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferRect( + object_, + src(), + dst(), + src_origin.data(), + dst_origin.data(), + region.data(), + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQEUE_COPY_BUFFER_RECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + /** + * Enqueue a command to fill a buffer object with a pattern + * of a given size. The pattern is specified as a vector type. + * \tparam PatternType The datatype of the pattern field. + * The pattern type must be an accepted OpenCL data type. + * \tparam offset Is the offset in bytes into the buffer at + * which to start filling. This must be a multiple of + * the pattern size. + * \tparam size Is the size in bytes of the region to fill. + * This must be a multiple of the pattern size. + */ + template + cl_int enqueueFillBuffer( + const Buffer& buffer, + PatternType pattern, + size_type offset, + size_type size, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillBuffer( + object_, + buffer(), + static_cast(&pattern), + sizeof(PatternType), + offset, + size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const array& origin, + const array& region, + size_type row_pitch, + size_type slice_pitch, + void* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReadImage( + object_, + image(), + blocking, + origin.data(), + region.data(), + row_pitch, + slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_READ_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const array& origin, + const array& region, + size_type row_pitch, + size_type slice_pitch, + const void* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueWriteImage( + object_, + image(), + blocking, + origin.data(), + region.data(), + row_pitch, + slice_pitch, + ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_WRITE_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const array& src_origin, + const array& dst_origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImage( + object_, + src(), + dst(), + src_origin.data(), + dst_origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA floating-point color value if + * the image channel data type is not an unnormalized signed or + * unsigned data type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_float4 fillColor, + const array& origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA signed integer color value if + * the image channel data type is an unnormalized signed integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_int4 fillColor, + const array& origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueue a command to fill an image object with a specified color. + * \param fillColor is the color to use to fill the image. + * This is a four component RGBA unsigned integer color value if + * the image channel data type is an unnormalized unsigned integer + * type. + */ + cl_int enqueueFillImage( + const Image& image, + cl_uint4 fillColor, + const array& origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueFillImage( + object_, + image(), + static_cast(&fillColor), + origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_FILL_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const array& src_origin, + const array& region, + size_type dst_offset, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyImageToBuffer( + object_, + src(), + dst(), + src_origin.data(), + region.data(), + dst_offset, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + size_type src_offset, + const array& dst_origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueCopyBufferToImage( + object_, + src(), + dst(), + src_offset, + dst_origin.data(), + region.data(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + size_type offset, + size_type size, + const vector* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapBuffer( + object_, buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + + return result; + } + + void* enqueueMapImage( + const Image& buffer, + cl_bool blocking, + cl_map_flags flags, + const array& origin, + const array& region, + size_type * row_pitch, + size_type * slice_pitch, + const vector* events = NULL, + Event* event = NULL, + cl_int* err = NULL) const + { + cl_event tmp; + cl_int error; + void * result = ::clEnqueueMapImage( + object_, buffer(), blocking, flags, + origin.data(), + region.data(), + row_pitch, slice_pitch, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR); + if (err != NULL) { + *err = error; + } + if (event != NULL && error == CL_SUCCESS) + *event = tmp; + return result; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /** + * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer. + * This variant takes a raw SVM pointer. + */ + template + cl_int enqueueMapSVM( + T* ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler(::clEnqueueSVMMap( + object_, blocking, flags, static_cast(ptr), size, + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MAP_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + + /** + * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer. + * This variant takes a cl::pointer instance. + */ + template + cl_int enqueueMapSVM( + cl::pointer &ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler(::clEnqueueSVMMap( + object_, blocking, flags, static_cast(ptr.get()), size, + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MAP_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer. + * This variant takes a cl::vector instance. + */ + template + cl_int enqueueMapSVM( + cl::vector &container, + cl_bool blocking, + cl_map_flags flags, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler(::clEnqueueSVMMap( + object_, blocking, flags, static_cast(container.data()), container.size(), + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MAP_BUFFER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + object_, memory(), mapped_ptr, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + /** + * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime. + * This variant takes a raw SVM pointer. + */ + template + cl_int enqueueUnmapSVM( + T* ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueSVMUnmap( + object_, static_cast(ptr), + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime. + * This variant takes a cl::pointer instance. + */ + template + cl_int enqueueUnmapSVM( + cl::pointer &ptr, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueSVMUnmap( + object_, static_cast(ptr.get()), + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime. + * This variant takes a cl::vector instance. + */ + template + cl_int enqueueUnmapSVM( + cl::vector &container, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueSVMUnmap( + object_, static_cast(container.data()), + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + /** + * Enqueues a marker command which waits for either a list of events to complete, + * or all previously enqueued commands to complete. + * + * Enqueues a marker command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command returns an event which can be waited on, + * i.e. this event can be waited on to insure that all events either in the event_wait_list + * or all previously enqueued commands, queued before this command to command_queue, + * have completed. + */ + cl_int enqueueMarkerWithWaitList( + const vector *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarkerWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * A synchronization point that enqueues a barrier operation. + * + * Enqueues a barrier command which waits for either a list of events to complete, + * or if the list is empty it waits for all commands previously enqueued in command_queue + * to complete before it completes. This command blocks command execution, that is, any + * following commands enqueued after it do not execute until it completes. This command + * returns an event which can be waited on, i.e. this event can be waited on to insure that + * all events either in the event_wait_list or all previously enqueued commands, queued + * before this command to command_queue, have completed. + */ + cl_int enqueueBarrierWithWaitList( + const vector *events = 0, + Event *event = 0) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueBarrierWithWaitList( + object_, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_BARRIER_WAIT_LIST_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + /** + * Enqueues a command to indicate with which device a set of memory objects + * should be associated. + */ + cl_int enqueueMigrateMemObjects( + const vector &memObjects, + cl_mem_migration_flags flags, + const vector* events = NULL, + Event* event = NULL + ) const + { + cl_event tmp; + + vector localMemObjects(memObjects.size()); + + for( int i = 0; i < (int)memObjects.size(); ++i ) { + localMemObjects[i] = memObjects[i](); + } + + + cl_int err = detail::errHandler( + ::clEnqueueMigrateMemObjects( + object_, + (cl_uint)memObjects.size(), + localMemObjects.data(), + flags, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 + + cl_int enqueueNDRangeKernel( + const Kernel& kernel, + const NDRange& offset, + const NDRange& global, + const NDRange& local = NullRange, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNDRangeKernel( + object_, kernel(), (cl_uint) global.dimensions(), + offset.dimensions() != 0 ? (const size_type*) offset : NULL, + (const size_type*) global, + local.dimensions() != 0 ? (const size_type*) local : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NDRANGE_KERNEL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) + CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask( + const Kernel& kernel, + const vector* events = NULL, + Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueTask( + object_, kernel(), + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_TASK_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) + + cl_int enqueueNativeKernel( + void (CL_CALLBACK *userFptr)(void *), + std::pair args, + const vector* mem_objects = NULL, + const vector* mem_locs = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + size_type elements = 0; + if (mem_objects != NULL) { + elements = mem_objects->size(); + } + vector mems(elements); + for (unsigned int i = 0; i < elements; i++) { + mems[i] = ((*mem_objects)[i])(); + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueNativeKernel( + object_, userFptr, args.first, args.second, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + mems.data(), + (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_NATIVE_KERNEL); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueMarker( + object_, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_MARKER_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueWaitForEvents(const vector& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueWaitForEvents( + object_, + (cl_uint) events.size(), + events.size() > 0 ? (const cl_event*) &events.front() : NULL), + __ENQUEUE_WAIT_FOR_EVENTS_ERR); + } +#endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + + cl_int enqueueAcquireGLObjects( + const vector* mem_objects = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueAcquireGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseGLObjects( + const vector* mem_objects = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueReleaseGLObjects( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + +#if defined (CL_HPP_USE_DX_INTEROP) +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); +typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem* mem_objects, cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, cl_event* event); + + cl_int enqueueAcquireD3D10Objects( + const vector* mem_objects = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL; +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR); +#endif +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR); +#endif + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueAcquireD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_ACQUIRE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } + + cl_int enqueueReleaseD3D10Objects( + const vector* mem_objects = NULL, + const vector* events = NULL, + Event* event = NULL) const + { + static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL; +#if CL_HPP_TARGET_OPENCL_VERSION >= 120 + cl_context context = getInfo(); + cl::Device device(getInfo()); + cl_platform_id platform = device.getInfo(); + CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR); +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 + CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR); +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + + cl_event tmp; + cl_int err = detail::errHandler( + pfn_clEnqueueReleaseD3D10ObjectsKHR( + object_, + (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, + (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_RELEASE_GL_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; + } +#endif + +/** + * Deprecated APIs for 1.2 + */ +#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) + CL_EXT_PREFIX__VERSION_1_1_DEPRECATED + cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + { + return detail::errHandler( + ::clEnqueueBarrier(object_), + __ENQUEUE_BARRIER_ERR); + } +#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS + + cl_int flush() const + { + return detail::errHandler(::clFlush(object_), __FLUSH_ERR); + } + + cl_int finish() const + { + return detail::errHandler(::clFinish(object_), __FINISH_ERR); + } +}; // CommandQueue + +CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_; +CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_; +CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS; + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +enum class DeviceQueueProperties : cl_command_queue_properties +{ + None = 0, + Profiling = CL_QUEUE_PROFILING_ENABLE, +}; + +inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs) +{ + return static_cast(static_cast(lhs) | static_cast(rhs)); +} + +/*! \class DeviceCommandQueue + * \brief DeviceCommandQueue interface for device cl_command_queues. + */ +class DeviceCommandQueue : public detail::Wrapper +{ +public: + + /*! + * Trivial empty constructor to create a null queue. + */ + DeviceCommandQueue() { } + + /*! + * Default construct device command queue on default context and device + */ + DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = NULL) + { + cl_int error; + cl::Context context = cl::Context::getDefault(); + cl::Device device = cl::Device::getDefault(); + + cl_command_queue_properties mergedProperties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast(properties); + + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, mergedProperties, 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! + * Create a device command queue for a specified device in the passed context. + */ + DeviceCommandQueue( + const Context& context, + const Device& device, + DeviceQueueProperties properties = DeviceQueueProperties::None, + cl_int* err = NULL) + { + cl_int error; + + cl_command_queue_properties mergedProperties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast(properties); + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, mergedProperties, 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! + * Create a device command queue for a specified device in the passed context. + */ + DeviceCommandQueue( + const Context& context, + const Device& device, + cl_uint queueSize, + DeviceQueueProperties properties = DeviceQueueProperties::None, + cl_int* err = NULL) + { + cl_int error; + + cl_command_queue_properties mergedProperties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast(properties); + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, mergedProperties, + CL_QUEUE_SIZE, queueSize, + 0 }; + object_ = ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + } + + /*! \brief Constructor from cl_command_queue - takes ownership. + * + * \param retainObject will cause the constructor to retain its cl object. + * Defaults to false to maintain compatibility with + * earlier versions. + */ + explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) : + detail::Wrapper(commandQueue, retainObject) { } + + DeviceCommandQueue& operator = (const cl_command_queue& rhs) + { + detail::Wrapper::operator=(rhs); + return *this; + } + + /*! \brief Copy constructor to forward copy to the superclass correctly. + * Required for MSVC. + */ + DeviceCommandQueue(const DeviceCommandQueue& queue) : detail::Wrapper(queue) {} + + /*! \brief Copy assignment to forward copy to the superclass correctly. + * Required for MSVC. + */ + DeviceCommandQueue& operator = (const DeviceCommandQueue &queue) + { + detail::Wrapper::operator=(queue); + return *this; + } + + /*! \brief Move constructor to forward move to the superclass correctly. + * Required for MSVC. + */ + DeviceCommandQueue(DeviceCommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper(std::move(queue)) {} + + /*! \brief Move assignment to forward move to the superclass correctly. + * Required for MSVC. + */ + DeviceCommandQueue& operator = (DeviceCommandQueue &&queue) + { + detail::Wrapper::operator=(std::move(queue)); + return *this; + } + + template + cl_int getInfo(cl_command_queue_info name, T* param) const + { + return detail::errHandler( + detail::getInfo( + &::clGetCommandQueueInfo, object_, name, param), + __GET_COMMAND_QUEUE_INFO_ERR); + } + + template typename + detail::param_traits::param_type + getInfo(cl_int* err = NULL) const + { + typename detail::param_traits< + detail::cl_command_queue_info, name>::param_type param; + cl_int result = getInfo(name, ¶m); + if (err != NULL) { + *err = result; + } + return param; + } + + /*! + * Create a new default device command queue for the default device, + * in the default context and of the default size. + * If there is already a default queue for the specified device this + * function will return the pre-existing queue. + */ + static DeviceCommandQueue makeDefault( + cl_int *err = nullptr) + { + cl_int error; + cl::Context context = cl::Context::getDefault(); + cl::Device device = cl::Device::getDefault(); + + cl_command_queue_properties properties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT; + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, + 0 }; + DeviceCommandQueue deviceQueue( + ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error)); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + + return deviceQueue; + } + + /*! + * Create a new default device command queue for the specified device + * and of the default size. + * If there is already a default queue for the specified device this + * function will return the pre-existing queue. + */ + static DeviceCommandQueue makeDefault( + const Context &context, const Device &device, cl_int *err = nullptr) + { + cl_int error; + + cl_command_queue_properties properties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT; + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, + 0 }; + DeviceCommandQueue deviceQueue( + ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error)); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + + return deviceQueue; + } + + /*! + * Create a new default device command queue for the specified device + * and of the requested size in bytes. + * If there is already a default queue for the specified device this + * function will return the pre-existing queue. + */ + static DeviceCommandQueue makeDefault( + const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr) + { + cl_int error; + + cl_command_queue_properties properties = + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT; + cl_queue_properties queue_properties[] = { + CL_QUEUE_PROPERTIES, properties, + CL_QUEUE_SIZE, queueSize, + 0 }; + DeviceCommandQueue deviceQueue( + ::clCreateCommandQueueWithProperties( + context(), device(), queue_properties, &error)); + + detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR); + if (err != NULL) { + *err = error; + } + + return deviceQueue; + } +}; // DeviceCommandQueue + +namespace detail +{ + // Specialization for device command queue + template <> + struct KernelArgumentHandler + { + static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); } + static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); } + }; +} // namespace detail + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + +template< typename IteratorType > +Buffer::Buffer( + const Context &context, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if( readOnly ) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if( useHostPtr ) { + flags |= CL_MEM_USE_HOST_PTR; + } + + size_type size = sizeof(DataType)*(endIterator - startIterator); + + if( useHostPtr ) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if( !useHostPtr ) { + CommandQueue queue(context, 0, &error); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +template< typename IteratorType > +Buffer::Buffer( + const CommandQueue &queue, + IteratorType startIterator, + IteratorType endIterator, + bool readOnly, + bool useHostPtr, + cl_int* err) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + cl_mem_flags flags = 0; + if (readOnly) { + flags |= CL_MEM_READ_ONLY; + } + else { + flags |= CL_MEM_READ_WRITE; + } + if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + } + + size_type size = sizeof(DataType)*(endIterator - startIterator); + + Context context = queue.getInfo(); + + if (useHostPtr) { + object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); + } + else { + object_ = ::clCreateBuffer(context(), flags, size, 0, &error); + } + + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + if (!useHostPtr) { + error = cl::copy(queue, startIterator, endIterator, *this); + detail::errHandler(error, __CREATE_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + } +} + +inline cl_int enqueueReadBuffer( + const Buffer& buffer, + cl_bool blocking, + size_type offset, + size_type size, + void* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline cl_int enqueueWriteBuffer( + const Buffer& buffer, + cl_bool blocking, + size_type offset, + size_type size, + const void* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event); +} + +inline void* enqueueMapBuffer( + const Buffer& buffer, + cl_bool blocking, + cl_map_flags flags, + size_type offset, + size_type size, + const vector* events = NULL, + Event* event = NULL, + cl_int* err = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + + void * result = ::clEnqueueMapBuffer( + queue(), buffer(), blocking, flags, offset, size, + (events != NULL) ? (cl_uint) events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, + (cl_event*) event, + &error); + + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (err != NULL) { + *err = error; + } + return result; +} + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +/** + * Enqueues to the default queue a command that will allow the host to + * update a region of a coarse-grained SVM buffer. + * This variant takes a raw SVM pointer. + */ +template +inline cl_int enqueueMapSVM( + T* ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events, + Event* event) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + } + + return queue.enqueueMapSVM( + ptr, blocking, flags, size, events, event); +} + +/** + * Enqueues to the default queue a command that will allow the host to + * update a region of a coarse-grained SVM buffer. + * This variant takes a cl::pointer instance. + */ +template +inline cl_int enqueueMapSVM( + cl::pointer ptr, + cl_bool blocking, + cl_map_flags flags, + size_type size, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + } + + return queue.enqueueMapSVM( + ptr, blocking, flags, size, events, event); +} + +/** + * Enqueues to the default queue a command that will allow the host to + * update a region of a coarse-grained SVM buffer. + * This variant takes a cl::vector instance. + */ +template +inline cl_int enqueueMapSVM( + cl::vector container, + cl_bool blocking, + cl_map_flags flags, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + } + + return queue.enqueueMapSVM( + container, blocking, flags, events, event); +} + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +inline cl_int enqueueUnmapMemObject( + const Memory& memory, + void* mapped_ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); + if (error != CL_SUCCESS) { + return error; + } + + cl_event tmp; + cl_int err = detail::errHandler( + ::clEnqueueUnmapMemObject( + queue(), memory(), mapped_ptr, + (events != NULL) ? (cl_uint)events->size() : 0, + (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL, + (event != NULL) ? &tmp : NULL), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + + if (event != NULL && err == CL_SUCCESS) + *event = tmp; + + return err; +} + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +/** + * Enqueues to the default queue a command that will release a coarse-grained + * SVM buffer back to the OpenCL runtime. + * This variant takes a raw SVM pointer. + */ +template +inline cl_int enqueueUnmapSVM( + T* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + } + + return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + +} + +/** + * Enqueues to the default queue a command that will release a coarse-grained + * SVM buffer back to the OpenCL runtime. + * This variant takes a cl::pointer instance. + */ +template +inline cl_int enqueueUnmapSVM( + cl::pointer &ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + } + + return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); +} + +/** + * Enqueues to the default queue a command that will release a coarse-grained + * SVM buffer back to the OpenCL runtime. + * This variant takes a cl::vector instance. + */ +template +inline cl_int enqueueUnmapSVM( + cl::vector &container, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) { + return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR); + } + + return detail::errHandler(queue.enqueueUnmapSVM(container, events, event), + __ENQUEUE_UNMAP_MEM_OBJECT_ERR); +} + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +inline cl_int enqueueCopyBuffer( + const Buffer& src, + const Buffer& dst, + size_type src_offset, + size_type dst_offset, + size_type size, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, startIterator, endIterator, buffer); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses default command queue. + */ +template< typename IteratorType > +inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + if (error != CL_SUCCESS) + return error; + + return cl::copy(queue, buffer, startIterator, endIterator); +} + +/** + * Blocking copy operation between iterators and a buffer. + * Host to Device. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + size_type length = endIterator-startIterator; + size_type byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } +#if defined(_MSC_VER) + std::copy( + startIterator, + endIterator, + stdext::checked_array_iterator( + pointer, length)); +#else + std::copy(startIterator, endIterator, pointer); +#endif + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + +/** + * Blocking copy operation between iterators and a buffer. + * Device to Host. + * Uses specified queue. + */ +template< typename IteratorType > +inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) +{ + typedef typename std::iterator_traits::value_type DataType; + cl_int error; + + size_type length = endIterator-startIterator; + size_type byteLength = length*sizeof(DataType); + + DataType *pointer = + static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error)); + // if exceptions enabled, enqueueMapBuffer will throw + if( error != CL_SUCCESS ) { + return error; + } + std::copy(pointer, pointer + length, startIterator); + Event endEvent; + error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); + // if exceptions enabled, enqueueUnmapMemObject will throw + if( error != CL_SUCCESS ) { + return error; + } + endEvent.wait(); + return CL_SUCCESS; +} + + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 +/** + * Blocking SVM map operation - performs a blocking map underneath. + */ +template +inline cl_int mapSVM(cl::vector &container) +{ + return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE); +} + +/** +* Blocking SVM map operation - performs a blocking map underneath. +*/ +template +inline cl_int unmapSVM(cl::vector &container) +{ + return enqueueUnmapSVM(container); +} + +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + +#if CL_HPP_TARGET_OPENCL_VERSION >= 110 +inline cl_int enqueueReadBufferRect( + const Buffer& buffer, + cl_bool blocking, + const array& buffer_offset, + const array& host_offset, + const array& region, + size_type buffer_row_pitch, + size_type buffer_slice_pitch, + size_type host_row_pitch, + size_type host_slice_pitch, + void *ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteBufferRect( + const Buffer& buffer, + cl_bool blocking, + const array& buffer_offset, + const array& host_offset, + const array& region, + size_type buffer_row_pitch, + size_type buffer_slice_pitch, + size_type host_row_pitch, + size_type host_slice_pitch, + const void *ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteBufferRect( + buffer, + blocking, + buffer_offset, + host_offset, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyBufferRect( + const Buffer& src, + const Buffer& dst, + const array& src_origin, + const array& dst_origin, + const array& region, + size_type src_row_pitch, + size_type src_slice_pitch, + size_type dst_row_pitch, + size_type dst_slice_pitch, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferRect( + src, + dst, + src_origin, + dst_origin, + region, + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + events, + event); +} +#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110 + +inline cl_int enqueueReadImage( + const Image& image, + cl_bool blocking, + const array& origin, + const array& region, + size_type row_pitch, + size_type slice_pitch, + void* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueReadImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueWriteImage( + const Image& image, + cl_bool blocking, + const array& origin, + const array& region, + size_type row_pitch, + size_type slice_pitch, + const void* ptr, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueWriteImage( + image, + blocking, + origin, + region, + row_pitch, + slice_pitch, + ptr, + events, + event); +} + +inline cl_int enqueueCopyImage( + const Image& src, + const Image& dst, + const array& src_origin, + const array& dst_origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImage( + src, + dst, + src_origin, + dst_origin, + region, + events, + event); +} + +inline cl_int enqueueCopyImageToBuffer( + const Image& src, + const Buffer& dst, + const array& src_origin, + const array& region, + size_type dst_offset, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyImageToBuffer( + src, + dst, + src_origin, + region, + dst_offset, + events, + event); +} + +inline cl_int enqueueCopyBufferToImage( + const Buffer& src, + const Image& dst, + size_type src_offset, + const array& dst_origin, + const array& region, + const vector* events = NULL, + Event* event = NULL) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.enqueueCopyBufferToImage( + src, + dst, + src_offset, + dst_origin, + region, + events, + event); +} + + +inline cl_int flush(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + return queue.flush(); +} + +inline cl_int finish(void) +{ + cl_int error; + CommandQueue queue = CommandQueue::getDefault(&error); + + if (error != CL_SUCCESS) { + return error; + } + + + return queue.finish(); +} + +class EnqueueArgs +{ +private: + CommandQueue queue_; + const NDRange offset_; + const NDRange global_; + const NDRange local_; + vector events_; + + template + friend class KernelFunctor; + +public: + EnqueueArgs(NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(Event e, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(const vector &events, NDRange global) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(const vector &events, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(const vector &events, NDRange offset, NDRange global, NDRange local) : + queue_(CommandQueue::getDefault()), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local) + { + events_.push_back(e); + } + + EnqueueArgs(CommandQueue &queue, const vector &events, NDRange global) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(NullRange), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const vector &events, NDRange global, NDRange local) : + queue_(queue), + offset_(NullRange), + global_(global), + local_(local), + events_(events) + { + + } + + EnqueueArgs(CommandQueue &queue, const vector &events, NDRange offset, NDRange global, NDRange local) : + queue_(queue), + offset_(offset), + global_(global), + local_(local), + events_(events) + { + + } +}; + + +//---------------------------------------------------------------------------------------------- + + +/** + * Type safe kernel functor. + * + */ +template +class KernelFunctor +{ +private: + Kernel kernel_; + + template + void setArgs(T0&& t0, T1s&&... t1s) + { + kernel_.setArg(index, t0); + setArgs(std::forward(t1s)...); + } + + template + void setArgs(T0&& t0) + { + kernel_.setArg(index, t0); + } + + template + void setArgs() + { + } + + +public: + KernelFunctor(Kernel kernel) : kernel_(kernel) + {} + + KernelFunctor( + const Program& program, + const string name, + cl_int * err = NULL) : + kernel_(program, name.c_str(), err) + {} + + //! \brief Return type of the functor + typedef Event result_type; + + /** + * Enqueue kernel. + * @param args Launch parameters of the kernel. + * @param t0... List of kernel arguments based on the template type of the functor. + */ + Event operator() ( + const EnqueueArgs& args, + Ts... ts) + { + Event event; + setArgs<0>(std::forward(ts)...); + + args.queue_.enqueueNDRangeKernel( + kernel_, + args.offset_, + args.global_, + args.local_, + &args.events_, + &event); + + return event; + } + + /** + * Enqueue kernel with support for error code. + * @param args Launch parameters of the kernel. + * @param t0... List of kernel arguments based on the template type of the functor. + * @param error Out parameter returning the error code from the execution. + */ + Event operator() ( + const EnqueueArgs& args, + Ts... ts, + cl_int &error) + { + Event event; + setArgs<0>(std::forward(ts)...); + + error = args.queue_.enqueueNDRangeKernel( + kernel_, + args.offset_, + args.global_, + args.local_, + &args.events_, + &event); + + return event; + } + +#if CL_HPP_TARGET_OPENCL_VERSION >= 200 + cl_int setSVMPointers(const vector &pointerList) + { + return kernel_.setSVMPointers(pointerList); + } + + template + cl_int setSVMPointers(const T0 &t0, T1s... ts) + { + return kernel_.setSVMPointers(t0, ts...); + } +#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200 + + Kernel getKernel() + { + return kernel_; + } +}; + +namespace compatibility { + /** + * Backward compatibility class to ensure that cl.hpp code works with cl2.hpp. + * Please use KernelFunctor directly. + */ + template + struct make_kernel + { + typedef KernelFunctor FunctorType; + + FunctorType functor_; + + make_kernel( + const Program& program, + const string name, + cl_int * err = NULL) : + functor_(FunctorType(program, name, err)) + {} + + make_kernel( + const Kernel kernel) : + functor_(FunctorType(kernel)) + {} + + //! \brief Return type of the functor + typedef Event result_type; + + //! \brief Function signature of kernel functor with no event dependency. + typedef Event type_( + const EnqueueArgs&, + Ts...); + + Event operator()( + const EnqueueArgs& enqueueArgs, + Ts... args) + { + return functor_( + enqueueArgs, args...); + } + }; +} // namespace compatibility + + +//---------------------------------------------------------------------------------------------------------------------- + +#undef CL_HPP_ERR_STR_ +#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) +#undef __GET_DEVICE_INFO_ERR +#undef __GET_PLATFORM_INFO_ERR +#undef __GET_DEVICE_IDS_ERR +#undef __GET_CONTEXT_INFO_ERR +#undef __GET_EVENT_INFO_ERR +#undef __GET_EVENT_PROFILE_INFO_ERR +#undef __GET_MEM_OBJECT_INFO_ERR +#undef __GET_IMAGE_INFO_ERR +#undef __GET_SAMPLER_INFO_ERR +#undef __GET_KERNEL_INFO_ERR +#undef __GET_KERNEL_ARG_INFO_ERR +#undef __GET_KERNEL_WORK_GROUP_INFO_ERR +#undef __GET_PROGRAM_INFO_ERR +#undef __GET_PROGRAM_BUILD_INFO_ERR +#undef __GET_COMMAND_QUEUE_INFO_ERR + +#undef __CREATE_CONTEXT_ERR +#undef __CREATE_CONTEXT_FROM_TYPE_ERR +#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR + +#undef __CREATE_BUFFER_ERR +#undef __CREATE_SUBBUFFER_ERR +#undef __CREATE_IMAGE2D_ERR +#undef __CREATE_IMAGE3D_ERR +#undef __CREATE_SAMPLER_ERR +#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR + +#undef __CREATE_USER_EVENT_ERR +#undef __SET_USER_EVENT_STATUS_ERR +#undef __SET_EVENT_CALLBACK_ERR +#undef __SET_PRINTF_CALLBACK_ERR + +#undef __WAIT_FOR_EVENTS_ERR + +#undef __CREATE_KERNEL_ERR +#undef __SET_KERNEL_ARGS_ERR +#undef __CREATE_PROGRAM_WITH_SOURCE_ERR +#undef __CREATE_PROGRAM_WITH_BINARY_ERR +#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR +#undef __BUILD_PROGRAM_ERR +#undef __CREATE_KERNELS_IN_PROGRAM_ERR + +#undef __CREATE_COMMAND_QUEUE_ERR +#undef __SET_COMMAND_QUEUE_PROPERTY_ERR +#undef __ENQUEUE_READ_BUFFER_ERR +#undef __ENQUEUE_WRITE_BUFFER_ERR +#undef __ENQUEUE_READ_BUFFER_RECT_ERR +#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR +#undef __ENQEUE_COPY_BUFFER_ERR +#undef __ENQEUE_COPY_BUFFER_RECT_ERR +#undef __ENQUEUE_READ_IMAGE_ERR +#undef __ENQUEUE_WRITE_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_ERR +#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR +#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR +#undef __ENQUEUE_MAP_BUFFER_ERR +#undef __ENQUEUE_MAP_IMAGE_ERR +#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR +#undef __ENQUEUE_NDRANGE_KERNEL_ERR +#undef __ENQUEUE_TASK_ERR +#undef __ENQUEUE_NATIVE_KERNEL + +#undef __UNLOAD_COMPILER_ERR +#undef __CREATE_SUB_DEVICES_ERR + +#undef __CREATE_PIPE_ERR +#undef __GET_PIPE_INFO_ERR + +#endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS + +// Extensions +#undef CL_HPP_INIT_CL_EXT_FCN_PTR_ +#undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_ + +#if defined(CL_HPP_USE_CL_DEVICE_FISSION) +#undef CL_HPP_PARAM_NAME_DEVICE_FISSION_ +#endif // CL_HPP_USE_CL_DEVICE_FISSION + +#undef CL_HPP_NOEXCEPT_ +#undef CL_HPP_DEFINE_STATIC_MEMBER_ + +} // namespace cl + +#endif // CL_HPP_ diff --git a/opencl/khronos/headers/opencl2.2/CL/cl_d3d10.h b/opencl/khronos/headers/opencl2.2/CL/cl_d3d10.h new file mode 100644 index 0000000000..2f68dbfd1f --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl_d3d10.h @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_CL_D3D10_H +#define __OPENCL_CL_D3D10_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * cl_khr_d3d10_sharing */ +#define cl_khr_d3d10_sharing 1 + +typedef cl_uint cl_d3d10_device_source_khr; +typedef cl_uint cl_d3d10_device_set_khr; + +/******************************************************************************/ + +/* Error Codes */ +#define CL_INVALID_D3D10_DEVICE_KHR -1002 +#define CL_INVALID_D3D10_RESOURCE_KHR -1003 +#define CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR -1004 +#define CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR -1005 + +/* cl_d3d10_device_source_nv */ +#define CL_D3D10_DEVICE_KHR 0x4010 +#define CL_D3D10_DXGI_ADAPTER_KHR 0x4011 + +/* cl_d3d10_device_set_nv */ +#define CL_PREFERRED_DEVICES_FOR_D3D10_KHR 0x4012 +#define CL_ALL_DEVICES_FOR_D3D10_KHR 0x4013 + +/* cl_context_info */ +#define CL_CONTEXT_D3D10_DEVICE_KHR 0x4014 +#define CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR 0x402C + +/* cl_mem_info */ +#define CL_MEM_D3D10_RESOURCE_KHR 0x4015 + +/* cl_image_info */ +#define CL_IMAGE_D3D10_SUBRESOURCE_KHR 0x4016 + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR 0x4017 +#define CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR 0x4018 + +/******************************************************************************/ + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D10KHR_fn)( + cl_platform_id platform, + cl_d3d10_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10BufferKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D10Buffer * resource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture2DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D10Texture2D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture3DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D10Texture3D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D10ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_D3D10_H */ + diff --git a/opencl/khronos/headers/opencl2.2/CL/cl_d3d11.h b/opencl/khronos/headers/opencl2.2/CL/cl_d3d11.h new file mode 100644 index 0000000000..44b8b1e4bc --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl_d3d11.h @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_CL_D3D11_H +#define __OPENCL_CL_D3D11_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * cl_khr_d3d11_sharing */ +#define cl_khr_d3d11_sharing 1 + +typedef cl_uint cl_d3d11_device_source_khr; +typedef cl_uint cl_d3d11_device_set_khr; + +/******************************************************************************/ + +/* Error Codes */ +#define CL_INVALID_D3D11_DEVICE_KHR -1006 +#define CL_INVALID_D3D11_RESOURCE_KHR -1007 +#define CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR -1008 +#define CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR -1009 + +/* cl_d3d11_device_source */ +#define CL_D3D11_DEVICE_KHR 0x4019 +#define CL_D3D11_DXGI_ADAPTER_KHR 0x401A + +/* cl_d3d11_device_set */ +#define CL_PREFERRED_DEVICES_FOR_D3D11_KHR 0x401B +#define CL_ALL_DEVICES_FOR_D3D11_KHR 0x401C + +/* cl_context_info */ +#define CL_CONTEXT_D3D11_DEVICE_KHR 0x401D +#define CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR 0x402D + +/* cl_mem_info */ +#define CL_MEM_D3D11_RESOURCE_KHR 0x401E + +/* cl_image_info */ +#define CL_IMAGE_D3D11_SUBRESOURCE_KHR 0x401F + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR 0x4020 +#define CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR 0x4021 + +/******************************************************************************/ + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D11KHR_fn)( + cl_platform_id platform, + cl_d3d11_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d11_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11BufferKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D11Buffer * resource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture2DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D11Texture2D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture3DKHR_fn)( + cl_context context, + cl_mem_flags flags, + ID3D11Texture3D * resource, + UINT subresource, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D11ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_D3D11_H */ + diff --git a/opencl/khronos/headers/opencl2.2/CL/cl_dx9_media_sharing.h b/opencl/khronos/headers/opencl2.2/CL/cl_dx9_media_sharing.h new file mode 100644 index 0000000000..e0f99b640d --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl_dx9_media_sharing.h @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_CL_DX9_MEDIA_SHARING_H +#define __OPENCL_CL_DX9_MEDIA_SHARING_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/******************************************************************************/ +/* cl_khr_dx9_media_sharing */ +#define cl_khr_dx9_media_sharing 1 + +typedef cl_uint cl_dx9_media_adapter_type_khr; +typedef cl_uint cl_dx9_media_adapter_set_khr; + +#if defined(_WIN32) +#include +typedef struct _cl_dx9_surface_info_khr +{ + IDirect3DSurface9 *resource; + HANDLE shared_handle; +} cl_dx9_surface_info_khr; +#endif + + +/******************************************************************************/ + +/* Error Codes */ +#define CL_INVALID_DX9_MEDIA_ADAPTER_KHR -1010 +#define CL_INVALID_DX9_MEDIA_SURFACE_KHR -1011 +#define CL_DX9_MEDIA_SURFACE_ALREADY_ACQUIRED_KHR -1012 +#define CL_DX9_MEDIA_SURFACE_NOT_ACQUIRED_KHR -1013 + +/* cl_media_adapter_type_khr */ +#define CL_ADAPTER_D3D9_KHR 0x2020 +#define CL_ADAPTER_D3D9EX_KHR 0x2021 +#define CL_ADAPTER_DXVA_KHR 0x2022 + +/* cl_media_adapter_set_khr */ +#define CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2023 +#define CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2024 + +/* cl_context_info */ +#define CL_CONTEXT_ADAPTER_D3D9_KHR 0x2025 +#define CL_CONTEXT_ADAPTER_D3D9EX_KHR 0x2026 +#define CL_CONTEXT_ADAPTER_DXVA_KHR 0x2027 + +/* cl_mem_info */ +#define CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR 0x2028 +#define CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR 0x2029 + +/* cl_image_info */ +#define CL_IMAGE_DX9_MEDIA_PLANE_KHR 0x202A + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR 0x202B +#define CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR 0x202C + +/******************************************************************************/ + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromDX9MediaAdapterKHR_fn)( + cl_platform_id platform, + cl_uint num_media_adapters, + cl_dx9_media_adapter_type_khr * media_adapter_type, + void * media_adapters, + cl_dx9_media_adapter_set_khr media_adapter_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)( + cl_context context, + cl_mem_flags flags, + cl_dx9_media_adapter_type_khr adapter_type, + void * surface_info, + cl_uint plane, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9MediaSurfacesKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_DX9_MEDIA_SHARING_H */ + diff --git a/opencl/khronos/headers/opencl2.2/CL/cl_dx9_media_sharing_intel.h b/opencl/khronos/headers/opencl2.2/CL/cl_dx9_media_sharing_intel.h new file mode 100644 index 0000000000..4525a175e6 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl_dx9_media_sharing_intel.h @@ -0,0 +1,170 @@ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +/*****************************************************************************\ + +Copyright (c) 2013-2019 Intel Corporation All Rights Reserved. + +THESE MATERIALS ARE PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THESE +MATERIALS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +File Name: cl_dx9_media_sharing_intel.h + +Abstract: + +Notes: + +\*****************************************************************************/ + +#ifndef __OPENCL_CL_DX9_MEDIA_SHARING_INTEL_H +#define __OPENCL_CL_DX9_MEDIA_SHARING_INTEL_H + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*************************************** +* cl_intel_dx9_media_sharing extension * +****************************************/ + +#define cl_intel_dx9_media_sharing 1 + +typedef cl_uint cl_dx9_device_source_intel; +typedef cl_uint cl_dx9_device_set_intel; + +/* error codes */ +#define CL_INVALID_DX9_DEVICE_INTEL -1010 +#define CL_INVALID_DX9_RESOURCE_INTEL -1011 +#define CL_DX9_RESOURCE_ALREADY_ACQUIRED_INTEL -1012 +#define CL_DX9_RESOURCE_NOT_ACQUIRED_INTEL -1013 + +/* cl_dx9_device_source_intel */ +#define CL_D3D9_DEVICE_INTEL 0x4022 +#define CL_D3D9EX_DEVICE_INTEL 0x4070 +#define CL_DXVA_DEVICE_INTEL 0x4071 + +/* cl_dx9_device_set_intel */ +#define CL_PREFERRED_DEVICES_FOR_DX9_INTEL 0x4024 +#define CL_ALL_DEVICES_FOR_DX9_INTEL 0x4025 + +/* cl_context_info */ +#define CL_CONTEXT_D3D9_DEVICE_INTEL 0x4026 +#define CL_CONTEXT_D3D9EX_DEVICE_INTEL 0x4072 +#define CL_CONTEXT_DXVA_DEVICE_INTEL 0x4073 + +/* cl_mem_info */ +#define CL_MEM_DX9_RESOURCE_INTEL 0x4027 +#define CL_MEM_DX9_SHARED_HANDLE_INTEL 0x4074 + +/* cl_image_info */ +#define CL_IMAGE_DX9_PLANE_INTEL 0x4075 + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_DX9_OBJECTS_INTEL 0x402A +#define CL_COMMAND_RELEASE_DX9_OBJECTS_INTEL 0x402B +/******************************************************************************/ + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceIDsFromDX9INTEL( + cl_platform_id platform, + cl_dx9_device_source_intel dx9_device_source, + void* dx9_object, + cl_dx9_device_set_intel dx9_device_set, + cl_uint num_entries, + cl_device_id* devices, + cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_1; + +typedef CL_API_ENTRY cl_int (CL_API_CALL* clGetDeviceIDsFromDX9INTEL_fn)( + cl_platform_id platform, + cl_dx9_device_source_intel dx9_device_source, + void* dx9_object, + cl_dx9_device_set_intel dx9_device_set, + cl_uint num_entries, + cl_device_id* devices, + cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromDX9MediaSurfaceINTEL( + cl_context context, + cl_mem_flags flags, + IDirect3DSurface9* resource, + HANDLE sharedHandle, + UINT plane, + cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_1; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceINTEL_fn)( + cl_context context, + cl_mem_flags flags, + IDirect3DSurface9* resource, + HANDLE sharedHandle, + UINT plane, + cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireDX9ObjectsINTEL( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event) CL_EXT_SUFFIX__VERSION_1_1; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9ObjectsINTEL_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event) CL_EXT_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseDX9ObjectsINTEL( + cl_command_queue command_queue, + cl_uint num_objects, + cl_mem* mem_objects, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event) CL_EXT_SUFFIX__VERSION_1_1; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9ObjectsINTEL_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + cl_mem* mem_objects, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event) CL_EXT_SUFFIX__VERSION_1_1; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_DX9_MEDIA_SHARING_INTEL_H */ + diff --git a/opencl/khronos/headers/opencl2.2/CL/cl_egl.h b/opencl/khronos/headers/opencl2.2/CL/cl_egl.h new file mode 100644 index 0000000000..c8bde80e15 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl_egl.h @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#ifndef __OPENCL_CL_EGL_H +#define __OPENCL_CL_EGL_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Command type for events created with clEnqueueAcquireEGLObjectsKHR */ +#define CL_COMMAND_EGL_FENCE_SYNC_OBJECT_KHR 0x202F +#define CL_COMMAND_ACQUIRE_EGL_OBJECTS_KHR 0x202D +#define CL_COMMAND_RELEASE_EGL_OBJECTS_KHR 0x202E + +/* Error type for clCreateFromEGLImageKHR */ +#define CL_INVALID_EGL_OBJECT_KHR -1093 +#define CL_EGL_RESOURCE_NOT_ACQUIRED_KHR -1092 + +/* CLeglImageKHR is an opaque handle to an EGLImage */ +typedef void* CLeglImageKHR; + +/* CLeglDisplayKHR is an opaque handle to an EGLDisplay */ +typedef void* CLeglDisplayKHR; + +/* CLeglSyncKHR is an opaque handle to an EGLSync object */ +typedef void* CLeglSyncKHR; + +/* properties passed to clCreateFromEGLImageKHR */ +typedef intptr_t cl_egl_image_properties_khr; + + +#define cl_khr_egl_image 1 + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromEGLImageKHR(cl_context context, + CLeglDisplayKHR egldisplay, + CLeglImageKHR eglimage, + cl_mem_flags flags, + const cl_egl_image_properties_khr * properties, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromEGLImageKHR_fn)( + cl_context context, + CLeglDisplayKHR egldisplay, + CLeglImageKHR eglimage, + cl_mem_flags flags, + const cl_egl_image_properties_khr * properties, + cl_int * errcode_ret); + + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireEGLObjectsKHR(cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireEGLObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event); + + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseEGLObjectsKHR(cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseEGLObjectsKHR_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event); + + +#define cl_khr_egl_event 1 + +extern CL_API_ENTRY cl_event CL_API_CALL +clCreateEventFromEGLSyncKHR(cl_context context, + CLeglSyncKHR sync, + CLeglDisplayKHR display, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_event (CL_API_CALL *clCreateEventFromEGLSyncKHR_fn)( + cl_context context, + CLeglSyncKHR sync, + CLeglDisplayKHR display, + cl_int * errcode_ret); + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_EGL_H */ diff --git a/opencl/khronos/headers/opencl2.2/CL/cl_ext.h b/opencl/khronos/headers/opencl2.2/CL/cl_ext.h new file mode 100644 index 0000000000..8f42403a8f --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl_ext.h @@ -0,0 +1,976 @@ +/* Modifications Copyright (C) 2010-2021 Advanced Micro Devices, Inc. */ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +/* cl_ext.h contains OpenCL extensions which don't have external */ +/* (OpenGL, D3D) dependencies. */ + +#ifndef __CL_EXT_H +#define __CL_EXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* cl_khr_fp64 extension - no extension #define since it has no functions */ +/* CL_DEVICE_DOUBLE_FP_CONFIG is defined in CL.h for OpenCL >= 120 */ + +#if CL_TARGET_OPENCL_VERSION <= 110 +#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 +#endif + +/* cl_khr_fp16 extension - no extension #define since it has no functions */ +#define CL_DEVICE_HALF_FP_CONFIG 0x1033 + +/* Memory object destruction + * + * Apple extension for use to manage externally allocated buffers used with cl_mem objects with CL_MEM_USE_HOST_PTR + * + * Registers a user callback function that will be called when the memory object is deleted and its resources + * freed. Each call to clSetMemObjectCallbackFn registers the specified user callback function on a callback + * stack associated with memobj. The registered user callback functions are called in the reverse order in + * which they were registered. The user callback functions are called and then the memory object is deleted + * and its resources freed. This provides a mechanism for the application (and libraries) using memobj to be + * notified when the memory referenced by host_ptr, specified when the memory object is created and used as + * the storage bits for the memory object, can be reused or freed. + * + * The application may not call CL api's with the cl_mem object passed to the pfn_notify. + * + * Please check for the "cl_APPLE_SetMemObjectDestructor" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) + * before using. + */ +#define cl_APPLE_SetMemObjectDestructor 1 +cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE( cl_mem memobj, + void (* pfn_notify)(cl_mem memobj, void * user_data), + void * user_data) CL_EXT_SUFFIX__VERSION_1_0; + + +/* Context Logging Functions + * + * The next three convenience functions are intended to be used as the pfn_notify parameter to clCreateContext(). + * Please check for the "cl_APPLE_ContextLoggingFunctions" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) + * before using. + * + * clLogMessagesToSystemLog forwards on all log messages to the Apple System Logger + */ +#define cl_APPLE_ContextLoggingFunctions 1 +extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE( const char * errstr, + const void * private_info, + size_t cb, + void * user_data) CL_EXT_SUFFIX__VERSION_1_0; + +/* clLogMessagesToStdout sends all log messages to the file descriptor stdout */ +extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE( const char * errstr, + const void * private_info, + size_t cb, + void * user_data) CL_EXT_SUFFIX__VERSION_1_0; + +/* clLogMessagesToStderr sends all log messages to the file descriptor stderr */ +extern void CL_API_ENTRY clLogMessagesToStderrAPPLE( const char * errstr, + const void * private_info, + size_t cb, + void * user_data) CL_EXT_SUFFIX__VERSION_1_0; + + +/************************ +* cl_khr_icd extension * +************************/ +#define cl_khr_icd 1 + +/* cl_platform_info */ +#define CL_PLATFORM_ICD_SUFFIX_KHR 0x0920 + +/* Additional Error Codes */ +#define CL_PLATFORM_NOT_FOUND_KHR -1001 + +extern CL_API_ENTRY cl_int CL_API_CALL +clIcdGetPlatformIDsKHR(cl_uint num_entries, + cl_platform_id * platforms, + cl_uint * num_platforms); + +typedef CL_API_ENTRY cl_int +(CL_API_CALL *clIcdGetPlatformIDsKHR_fn)(cl_uint num_entries, + cl_platform_id * platforms, + cl_uint * num_platforms); + + +/******************************* + * cl_khr_il_program extension * + *******************************/ +#define cl_khr_il_program 1 + +/* New property to clGetDeviceInfo for retrieving supported intermediate + * languages + */ +#define CL_DEVICE_IL_VERSION_KHR 0x105B + +/* New property to clGetProgramInfo for retrieving for retrieving the IL of a + * program + */ +#define CL_PROGRAM_IL_KHR 0x1169 + +extern CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithILKHR(cl_context context, + const void * il, + size_t length, + cl_int * errcode_ret); + +typedef CL_API_ENTRY cl_program +(CL_API_CALL *clCreateProgramWithILKHR_fn)(cl_context context, + const void * il, + size_t length, + cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + +/* Extension: cl_khr_image2d_from_buffer + * + * This extension allows a 2D image to be created from a cl_mem buffer without + * a copy. The type associated with a 2D image created from a buffer in an + * OpenCL program is image2d_t. Both the sampler and sampler-less read_image + * built-in functions are supported for 2D images and 2D images created from + * a buffer. Similarly, the write_image built-ins are also supported for 2D + * images created from a buffer. + * + * When the 2D image from buffer is created, the client must specify the + * width, height, image format (i.e. channel order and channel data type) + * and optionally the row pitch. + * + * The pitch specified must be a multiple of + * CL_DEVICE_IMAGE_PITCH_ALIGNMENT_KHR pixels. + * The base address of the buffer must be aligned to + * CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT_KHR pixels. + */ + +#define CL_DEVICE_IMAGE_PITCH_ALIGNMENT_KHR 0x104A +#define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT_KHR 0x104B + + +/************************************** + * cl_khr_initialize_memory extension * + **************************************/ + +#define CL_CONTEXT_MEMORY_INITIALIZE_KHR 0x2030 + + +/************************************** + * cl_khr_terminate_context extension * + **************************************/ + +#define CL_DEVICE_TERMINATE_CAPABILITY_KHR 0x2031 +#define CL_CONTEXT_TERMINATE_KHR 0x2032 + +#define cl_khr_terminate_context 1 +extern CL_API_ENTRY cl_int CL_API_CALL +clTerminateContextKHR(cl_context context) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL *clTerminateContextKHR_fn)(cl_context context) CL_EXT_SUFFIX__VERSION_1_2; + + +/* + * Extension: cl_khr_spir + * + * This extension adds support to create an OpenCL program object from a + * Standard Portable Intermediate Representation (SPIR) instance + */ + +#define CL_DEVICE_SPIR_VERSIONS 0x40E0 +#define CL_PROGRAM_BINARY_TYPE_INTERMEDIATE 0x40E1 + + +/***************************************** + * cl_khr_create_command_queue extension * + *****************************************/ +#define cl_khr_create_command_queue 1 + +typedef cl_bitfield cl_queue_properties_khr; + +extern CL_API_ENTRY cl_command_queue CL_API_CALL +clCreateCommandQueueWithPropertiesKHR(cl_context context, + cl_device_id device, + const cl_queue_properties_khr* properties, + cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_command_queue +(CL_API_CALL *clCreateCommandQueueWithPropertiesKHR_fn)(cl_context context, + cl_device_id device, + const cl_queue_properties_khr* properties, + cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + + +/****************************************** +* cl_nv_device_attribute_query extension * +******************************************/ + +/* cl_nv_device_attribute_query extension - no extension #define since it has no functions */ +#define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 +#define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 +#define CL_DEVICE_REGISTERS_PER_BLOCK_NV 0x4002 +#define CL_DEVICE_WARP_SIZE_NV 0x4003 +#define CL_DEVICE_GPU_OVERLAP_NV 0x4004 +#define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 +#define CL_DEVICE_INTEGRATED_MEMORY_NV 0x4006 + +/********************************* +* cl_amd_device_memory_flags * +*********************************/ +#define cl_amd_device_memory_flags 1 +#define CL_MEM_USE_PERSISTENT_MEM_AMD (1 << 6) // Alloc from GPU's CPU visible heap + +/* cl_device_info */ +#define CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT 0x4032 + +/********************************* +* cl_amd_device_attribute_query * +*********************************/ + +#define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 0x4036 +#define CL_DEVICE_TOPOLOGY_AMD 0x4037 +#define CL_DEVICE_BOARD_NAME_AMD 0x4038 +#define CL_DEVICE_GLOBAL_FREE_MEMORY_AMD 0x4039 +#define CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD 0x4040 +#define CL_DEVICE_SIMD_WIDTH_AMD 0x4041 +#define CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD 0x4042 +#define CL_DEVICE_WAVEFRONT_WIDTH_AMD 0x4043 +#define CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD 0x4044 +#define CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD 0x4045 +#define CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD 0x4046 +#define CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD 0x4047 +#define CL_DEVICE_LOCAL_MEM_BANKS_AMD 0x4048 +#define CL_DEVICE_THREAD_TRACE_SUPPORTED_AMD 0x4049 +#define CL_DEVICE_GFXIP_MAJOR_AMD 0x404A +#define CL_DEVICE_GFXIP_MINOR_AMD 0x404B +#define CL_DEVICE_AVAILABLE_ASYNC_QUEUES_AMD 0x404C +#define CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD 0x4030 +#define CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD 0x4031 +#define CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD 0x4033 +#define CL_DEVICE_PCIE_ID_AMD 0x4034 + +typedef union +{ + struct { cl_uint type; cl_uint data[5]; } raw; + struct { cl_uint type; cl_uchar unused[17]; cl_uchar bus; cl_uchar device; cl_uchar function; } pcie; +} cl_device_topology_amd; + +#define CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD 1 + +/************************** +* cl_amd_offline_devices * +**************************/ +#define CL_CONTEXT_OFFLINE_DEVICES_AMD 0x403F + +/******************************** +* cl_amd_bus_addressable_memory * +********************************/ + +/* cl_mem flag - bitfield */ +#define CL_MEM_BUS_ADDRESSABLE_AMD (1<<30) +#define CL_MEM_EXTERNAL_PHYSICAL_AMD (1<<31) + +#define CL_COMMAND_WAIT_SIGNAL_AMD 0x4080 +#define CL_COMMAND_WRITE_SIGNAL_AMD 0x4081 +#define CL_COMMAND_MAKE_BUFFERS_RESIDENT_AMD 0x4082 + +typedef struct _cl_bus_address_amd +{ + cl_ulong surface_bus_address; + cl_ulong marker_bus_address; +} cl_bus_address_amd; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueWaitSignalAMD_fn)( cl_command_queue /*command_queue*/, + cl_mem /*mem_object*/, + cl_uint /*value*/, + cl_uint /*num_events*/, + const cl_event * /*event_wait_list*/, + cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueWriteSignalAMD_fn)( cl_command_queue /*command_queue*/, + cl_mem /*mem_object*/, + cl_uint /*value*/, + cl_ulong /*offset*/, + cl_uint /*num_events*/, + const cl_event * /*event_list*/, + cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueMakeBuffersResidentAMD_fn)( cl_command_queue /*command_queue*/, + cl_uint /*num_mem_objs*/, + cl_mem * /*mem_objects*/, + cl_bool /*blocking_make_resident*/, + cl_bus_address_amd * /*bus_addresses*/, + cl_uint /*num_events*/, + const cl_event * /*event_list*/, + cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +/************************* +* cl_amd_copy_buffer_p2p * +**************************/ +#define CL_DEVICE_NUM_P2P_DEVICES_AMD 0x4088 +#define CL_DEVICE_P2P_DEVICES_AMD 0x4089 + +#define cl_amd_copy_buffer_p2p 1 + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueCopyBufferP2PAMD_fn)(cl_command_queue /*command_queue*/, + cl_mem /*src_buffer*/, + cl_mem /*dst_buffer*/, + size_t /*src_offset*/, + size_t /*dst_offset*/, + size_t /*cb*/, + cl_uint /*num_events_in_wait_list*/, + const cl_event* /*event_wait_list*/, + cl_event* /*event*/) CL_EXT_SUFFIX__VERSION_1_2; + +/*********************************** +* cl_amd_assembly_program extension * +***********************************/ +#define cl_amd_assembly_program 1 + +typedef CL_API_ENTRY cl_program (CL_API_CALL * clCreateProgramWithAssemblyAMD_fn) ( + cl_context /* context */, + cl_uint /* count */, + const char** /* strings */, + const size_t* /* lengths */, + cl_int* /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2; + +#ifdef CL_VERSION_2_0 +/******************************** +* cl_amd_planar_yuv * +********************************/ + +/* cl_mem flag - bitfield */ +#define CL_YUV_IMAGE_Y_PLANE_AMD 0x0 +#define CL_YUV_IMAGE_UV_PLANE_AMD 0x1 + +typedef CL_API_ENTRY cl_mem +(CL_API_CALL * clGetPlaneFromImageAMD_fn)(cl_context /*context*/, + cl_mem /*mem*/, + cl_uint /*plane*/, + cl_int * /*errcode_ret*/) CL_EXT_SUFFIX__VERSION_2_0; +#endif + +// +/************************** +* cl_amd_command_queue_info * +**************************/ +#define CL_QUEUE_THREAD_HANDLE_AMD 0x403E + +/* cl_kernel_exec_info for DVR DOPP texture support */ +#define CL_KERNEL_EXEC_INFO_NEW_VCOP_AMD 0x4120 +#define CL_KERNEL_EXEC_INFO_PFPA_VCOP_AMD 0x4121 + +/************************* +* cl_amd_object_metadata * +**************************/ +#define cl_amd_object_metadata 1 + +typedef size_t cl_key_amd; + +#define CL_INVALID_OBJECT_AMD 0x403A +#define CL_INVALID_KEY_AMD 0x403B +#define CL_PLATFORM_MAX_KEYS_AMD 0x403C + +typedef CL_API_ENTRY cl_key_amd (CL_API_CALL * clCreateKeyAMD_fn)( + cl_platform_id /* platform */, + void (CL_CALLBACK * /* destructor */)( void* /* old_value */), + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; + +typedef CL_API_ENTRY cl_int (CL_API_CALL * clObjectGetValueForKeyAMD_fn)( + void * /* object */, + cl_key_amd /* key */, + void ** /* ret_val */) CL_API_SUFFIX__VERSION_1_1; + +typedef CL_API_ENTRY cl_int (CL_API_CALL * clObjectSetValueForKeyAMD_fn)( + void * /* object */, + cl_key_amd /* key */, + void * /* value */) CL_API_SUFFIX__VERSION_1_1; +// + + +/********************************* +* cl_arm_printf extension +*********************************/ + +#define CL_PRINTF_CALLBACK_ARM 0x40B0 +#define CL_PRINTF_BUFFERSIZE_ARM 0x40B1 + + +/*********************************** +* cl_ext_device_fission extension +***********************************/ +#define cl_ext_device_fission 1 + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseDeviceEXT(cl_device_id device) CL_EXT_SUFFIX__VERSION_1_1; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL *clReleaseDeviceEXT_fn)(cl_device_id device) CL_EXT_SUFFIX__VERSION_1_1; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainDeviceEXT(cl_device_id device) CL_EXT_SUFFIX__VERSION_1_1; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL *clRetainDeviceEXT_fn)(cl_device_id device) CL_EXT_SUFFIX__VERSION_1_1; + +typedef cl_ulong cl_device_partition_property_ext; +extern CL_API_ENTRY cl_int CL_API_CALL +clCreateSubDevicesEXT(cl_device_id in_device, + const cl_device_partition_property_ext * properties, + cl_uint num_entries, + cl_device_id * out_devices, + cl_uint * num_devices) CL_EXT_SUFFIX__VERSION_1_1; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clCreateSubDevicesEXT_fn)(cl_device_id in_device, + const cl_device_partition_property_ext * properties, + cl_uint num_entries, + cl_device_id * out_devices, + cl_uint * num_devices) CL_EXT_SUFFIX__VERSION_1_1; + +/* cl_device_partition_property_ext */ +#define CL_DEVICE_PARTITION_EQUALLY_EXT 0x4050 +#define CL_DEVICE_PARTITION_BY_COUNTS_EXT 0x4051 +#define CL_DEVICE_PARTITION_BY_NAMES_EXT 0x4052 +#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT 0x4053 + +/* clDeviceGetInfo selectors */ +#define CL_DEVICE_PARENT_DEVICE_EXT 0x4054 +#define CL_DEVICE_PARTITION_TYPES_EXT 0x4055 +#define CL_DEVICE_AFFINITY_DOMAINS_EXT 0x4056 +#define CL_DEVICE_REFERENCE_COUNT_EXT 0x4057 +#define CL_DEVICE_PARTITION_STYLE_EXT 0x4058 + +/* clGetImageInfo enum */ +#define CL_IMAGE_BYTE_PITCH_AMD 0x4059 + +/* error codes */ +#define CL_DEVICE_PARTITION_FAILED_EXT -1057 +#define CL_INVALID_PARTITION_COUNT_EXT -1058 +#define CL_INVALID_PARTITION_NAME_EXT -1059 + +/* CL_AFFINITY_DOMAINs */ +#define CL_AFFINITY_DOMAIN_L1_CACHE_EXT 0x1 +#define CL_AFFINITY_DOMAIN_L2_CACHE_EXT 0x2 +#define CL_AFFINITY_DOMAIN_L3_CACHE_EXT 0x3 +#define CL_AFFINITY_DOMAIN_L4_CACHE_EXT 0x4 +#define CL_AFFINITY_DOMAIN_NUMA_EXT 0x10 +#define CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT 0x100 + +/* cl_device_partition_property_ext list terminators */ +#define CL_PROPERTIES_LIST_END_EXT ((cl_device_partition_property_ext) 0) +#define CL_PARTITION_BY_COUNTS_LIST_END_EXT ((cl_device_partition_property_ext) 0) +#define CL_PARTITION_BY_NAMES_LIST_END_EXT ((cl_device_partition_property_ext) 0 - 1) + + +/*********************************** + * cl_ext_migrate_memobject extension definitions + ***********************************/ +#define cl_ext_migrate_memobject 1 + +typedef cl_bitfield cl_mem_migration_flags_ext; + +#define CL_MIGRATE_MEM_OBJECT_HOST_EXT 0x1 + +#define CL_COMMAND_MIGRATE_MEM_OBJECT_EXT 0x4040 + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMigrateMemObjectEXT(cl_command_queue command_queue, + cl_uint num_mem_objects, + const cl_mem * mem_objects, + cl_mem_migration_flags_ext flags, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event); + +typedef CL_API_ENTRY cl_int +(CL_API_CALL *clEnqueueMigrateMemObjectEXT_fn)(cl_command_queue command_queue, + cl_uint num_mem_objects, + const cl_mem * mem_objects, + cl_mem_migration_flags_ext flags, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event); + + +/********************************* +* cl_qcom_ext_host_ptr extension +*********************************/ +#define cl_qcom_ext_host_ptr 1 + +#define CL_MEM_EXT_HOST_PTR_QCOM (1 << 29) + +#define CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM 0x40A0 +#define CL_DEVICE_PAGE_SIZE_QCOM 0x40A1 +#define CL_IMAGE_ROW_ALIGNMENT_QCOM 0x40A2 +#define CL_IMAGE_SLICE_ALIGNMENT_QCOM 0x40A3 +#define CL_MEM_HOST_UNCACHED_QCOM 0x40A4 +#define CL_MEM_HOST_WRITEBACK_QCOM 0x40A5 +#define CL_MEM_HOST_WRITETHROUGH_QCOM 0x40A6 +#define CL_MEM_HOST_WRITE_COMBINING_QCOM 0x40A7 + +typedef cl_uint cl_image_pitch_info_qcom; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceImageInfoQCOM(cl_device_id device, + size_t image_width, + size_t image_height, + const cl_image_format *image_format, + cl_image_pitch_info_qcom param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret); + +typedef struct _cl_mem_ext_host_ptr +{ + /* Type of external memory allocation. */ + /* Legal values will be defined in layered extensions. */ + cl_uint allocation_type; + + /* Host cache policy for this external memory allocation. */ + cl_uint host_cache_policy; + +} cl_mem_ext_host_ptr; + + +/******************************************* +* cl_qcom_ext_host_ptr_iocoherent extension +********************************************/ + +/* Cache policy specifying io-coherence */ +#define CL_MEM_HOST_IOCOHERENT_QCOM 0x40A9 + + +/********************************* +* cl_qcom_ion_host_ptr extension +*********************************/ + +#define CL_MEM_ION_HOST_PTR_QCOM 0x40A8 + +typedef struct _cl_mem_ion_host_ptr +{ + /* Type of external memory allocation. */ + /* Must be CL_MEM_ION_HOST_PTR_QCOM for ION allocations. */ + cl_mem_ext_host_ptr ext_host_ptr; + + /* ION file descriptor */ + int ion_filedesc; + + /* Host pointer to the ION allocated memory */ + void* ion_hostptr; + +} cl_mem_ion_host_ptr; + + +/********************************* +* cl_qcom_android_native_buffer_host_ptr extension +*********************************/ + +#define CL_MEM_ANDROID_NATIVE_BUFFER_HOST_PTR_QCOM 0x40C6 + +typedef struct _cl_mem_android_native_buffer_host_ptr +{ + /* Type of external memory allocation. */ + /* Must be CL_MEM_ANDROID_NATIVE_BUFFER_HOST_PTR_QCOM for Android native buffers. */ + cl_mem_ext_host_ptr ext_host_ptr; + + /* Virtual pointer to the android native buffer */ + void* anb_ptr; + +} cl_mem_android_native_buffer_host_ptr; + + +/****************************************** + * cl_img_yuv_image extension * + ******************************************/ + +/* Image formats used in clCreateImage */ +#define CL_NV21_IMG 0x40D0 +#define CL_YV12_IMG 0x40D1 + + +/****************************************** + * cl_img_cached_allocations extension * + ******************************************/ + +/* Flag values used by clCreateBuffer */ +#define CL_MEM_USE_UNCACHED_CPU_MEMORY_IMG (1 << 26) +#define CL_MEM_USE_CACHED_CPU_MEMORY_IMG (1 << 27) + + +/****************************************** + * cl_img_use_gralloc_ptr extension * + ******************************************/ +#define cl_img_use_gralloc_ptr 1 + +/* Flag values used by clCreateBuffer */ +#define CL_MEM_USE_GRALLOC_PTR_IMG (1 << 28) + +/* To be used by clGetEventInfo: */ +#define CL_COMMAND_ACQUIRE_GRALLOC_OBJECTS_IMG 0x40D2 +#define CL_COMMAND_RELEASE_GRALLOC_OBJECTS_IMG 0x40D3 + +/* Error code from clEnqueueReleaseGrallocObjectsIMG */ +#define CL_GRALLOC_RESOURCE_NOT_ACQUIRED_IMG 0x40D4 + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireGrallocObjectsIMG(cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseGrallocObjectsIMG(cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + + +/********************************* +* cl_khr_subgroups extension +*********************************/ +#define cl_khr_subgroups 1 + +#if !defined(CL_VERSION_2_1) +/* For OpenCL 2.1 and newer, cl_kernel_sub_group_info is declared in CL.h. + In hindsight, there should have been a khr suffix on this type for + the extension, but keeping it un-suffixed to maintain backwards + compatibility. */ +typedef cl_uint cl_kernel_sub_group_info; +#endif + +/* cl_kernel_sub_group_info */ +#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR 0x2033 +#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR 0x2034 + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetKernelSubGroupInfoKHR(cl_kernel in_kernel, + cl_device_id in_device, + cl_kernel_sub_group_info param_name, + size_t input_value_size, + const void * input_value, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clGetKernelSubGroupInfoKHR_fn)(cl_kernel in_kernel, + cl_device_id in_device, + cl_kernel_sub_group_info param_name, + size_t input_value_size, + const void * input_value, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; + + +/********************************* +* cl_khr_mipmap_image extension +*********************************/ + +/* cl_sampler_properties */ +#define CL_SAMPLER_MIP_FILTER_MODE_KHR 0x1155 +#define CL_SAMPLER_LOD_MIN_KHR 0x1156 +#define CL_SAMPLER_LOD_MAX_KHR 0x1157 + + +/********************************* +* cl_khr_priority_hints extension +*********************************/ +/* This extension define is for backwards compatibility. + It shouldn't be required since this extension has no new functions. */ +#define cl_khr_priority_hints 1 + +typedef cl_uint cl_queue_priority_khr; + +/* cl_command_queue_properties */ +#define CL_QUEUE_PRIORITY_KHR 0x1096 + +/* cl_queue_priority_khr */ +#define CL_QUEUE_PRIORITY_HIGH_KHR (1<<0) +#define CL_QUEUE_PRIORITY_MED_KHR (1<<1) +#define CL_QUEUE_PRIORITY_LOW_KHR (1<<2) + + +/********************************* +* cl_khr_throttle_hints extension +*********************************/ +/* This extension define is for backwards compatibility. + It shouldn't be required since this extension has no new functions. */ +#define cl_khr_throttle_hints 1 + +typedef cl_uint cl_queue_throttle_khr; + +/* cl_command_queue_properties */ +#define CL_QUEUE_THROTTLE_KHR 0x1097 + +/* cl_queue_throttle_khr */ +#define CL_QUEUE_THROTTLE_HIGH_KHR (1<<0) +#define CL_QUEUE_THROTTLE_MED_KHR (1<<1) +#define CL_QUEUE_THROTTLE_LOW_KHR (1<<2) + + +/********************************* +* cl_khr_subgroup_named_barrier +*********************************/ +/* This extension define is for backwards compatibility. + It shouldn't be required since this extension has no new functions. */ +#define cl_khr_subgroup_named_barrier 1 + +/* cl_device_info */ +#define CL_DEVICE_MAX_NAMED_BARRIER_COUNT_KHR 0x2035 + + +/********************************* +* cl_khr_extended_versioning +*********************************/ + +#define CL_VERSION_MAJOR_BITS_KHR (10) +#define CL_VERSION_MINOR_BITS_KHR (10) +#define CL_VERSION_PATCH_BITS_KHR (12) + +#define CL_VERSION_MAJOR_MASK_KHR ((1 << CL_VERSION_MAJOR_BITS_KHR) - 1) +#define CL_VERSION_MINOR_MASK_KHR ((1 << CL_VERSION_MINOR_BITS_KHR) - 1) +#define CL_VERSION_PATCH_MASK_KHR ((1 << CL_VERSION_PATCH_BITS_KHR) - 1) + +#define CL_VERSION_MAJOR_KHR(version) ((version) >> (CL_VERSION_MINOR_BITS_KHR + CL_VERSION_PATCH_BITS_KHR)) +#define CL_VERSION_MINOR_KHR(version) (((version) >> CL_VERSION_PATCH_BITS_KHR) & CL_VERSION_MINOR_MASK_KHR) +#define CL_VERSION_PATCH_KHR(version) ((version) & CL_VERSION_PATCH_MASK_KHR) + +#define CL_MAKE_VERSION_KHR(major, minor, patch) \ + ((((major) & CL_VERSION_MAJOR_MASK_KHR) << (CL_VERSION_MINOR_BITS_KHR + CL_VERSION_PATCH_BITS_KHR)) | \ + (((minor) & CL_VERSION_MINOR_MASK_KHR) << CL_VERSION_PATCH_BITS_KHR) | \ + ((patch) & CL_VERSION_PATCH_MASK_KHR)) + +typedef cl_uint cl_version_khr; + +#define CL_NAME_VERSION_MAX_NAME_SIZE_KHR 64 + +typedef struct _cl_name_version_khr +{ + cl_version_khr version; + char name[CL_NAME_VERSION_MAX_NAME_SIZE_KHR]; +} cl_name_version_khr; + +/* cl_platform_info */ +#define CL_PLATFORM_NUMERIC_VERSION_KHR 0x0906 +#define CL_PLATFORM_EXTENSIONS_WITH_VERSION_KHR 0x0907 + +/* cl_device_info */ +#define CL_DEVICE_NUMERIC_VERSION_KHR 0x105E +#define CL_DEVICE_OPENCL_C_NUMERIC_VERSION_KHR 0x105F +#define CL_DEVICE_EXTENSIONS_WITH_VERSION_KHR 0x1060 +#define CL_DEVICE_ILS_WITH_VERSION_KHR 0x1061 +#define CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION_KHR 0x1062 + + +/********************************** + * cl_arm_import_memory extension * + **********************************/ +#define cl_arm_import_memory 1 + +typedef intptr_t cl_import_properties_arm; + +/* Default and valid proporties name for cl_arm_import_memory */ +#define CL_IMPORT_TYPE_ARM 0x40B2 + +/* Host process memory type default value for CL_IMPORT_TYPE_ARM property */ +#define CL_IMPORT_TYPE_HOST_ARM 0x40B3 + +/* DMA BUF memory type value for CL_IMPORT_TYPE_ARM property */ +#define CL_IMPORT_TYPE_DMA_BUF_ARM 0x40B4 + +/* Protected memory property */ +#define CL_IMPORT_TYPE_PROTECTED_ARM 0x40B5 + +/* Android hardware buffer type value for CL_IMPORT_TYPE_ARM property */ +#define CL_IMPORT_TYPE_ANDROID_HARDWARE_BUFFER_ARM 0x41E2 + +/* Data consistency with host property */ +#define CL_IMPORT_DMA_BUF_DATA_CONSISTENCY_WITH_HOST_ARM 0x41E3 + +/* Import memory size value to indicate a size for the whole buffer */ +#define CL_IMPORT_MEMORY_WHOLE_ALLOCATION_ARM SIZE_MAX + +/* This extension adds a new function that allows for direct memory import into + * OpenCL via the clImportMemoryARM function. + * + * Memory imported through this interface will be mapped into the device's page + * tables directly, providing zero copy access. It will never fall back to copy + * operations and aliased buffers. + * + * Types of memory supported for import are specified as additional extension + * strings. + * + * This extension produces cl_mem allocations which are compatible with all other + * users of cl_mem in the standard API. + * + * This extension maps pages with the same properties as the normal buffer creation + * function clCreateBuffer. + */ +extern CL_API_ENTRY cl_mem CL_API_CALL +clImportMemoryARM( cl_context context, + cl_mem_flags flags, + const cl_import_properties_arm *properties, + void *memory, + size_t size, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_0; + + +/****************************************** + * cl_arm_shared_virtual_memory extension * + ******************************************/ +#define cl_arm_shared_virtual_memory 1 + +/* Used by clGetDeviceInfo */ +#define CL_DEVICE_SVM_CAPABILITIES_ARM 0x40B6 + +/* Used by clGetMemObjectInfo */ +#define CL_MEM_USES_SVM_POINTER_ARM 0x40B7 + +/* Used by clSetKernelExecInfoARM: */ +#define CL_KERNEL_EXEC_INFO_SVM_PTRS_ARM 0x40B8 +#define CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM_ARM 0x40B9 + +/* To be used by clGetEventInfo: */ +#define CL_COMMAND_SVM_FREE_ARM 0x40BA +#define CL_COMMAND_SVM_MEMCPY_ARM 0x40BB +#define CL_COMMAND_SVM_MEMFILL_ARM 0x40BC +#define CL_COMMAND_SVM_MAP_ARM 0x40BD +#define CL_COMMAND_SVM_UNMAP_ARM 0x40BE + +/* Flag values returned by clGetDeviceInfo with CL_DEVICE_SVM_CAPABILITIES_ARM as the param_name. */ +#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER_ARM (1 << 0) +#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER_ARM (1 << 1) +#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM_ARM (1 << 2) +#define CL_DEVICE_SVM_ATOMICS_ARM (1 << 3) + +/* Flag values used by clSVMAllocARM: */ +#define CL_MEM_SVM_FINE_GRAIN_BUFFER_ARM (1 << 10) +#define CL_MEM_SVM_ATOMICS_ARM (1 << 11) + +typedef cl_bitfield cl_svm_mem_flags_arm; +typedef cl_uint cl_kernel_exec_info_arm; +typedef cl_bitfield cl_device_svm_capabilities_arm; + +extern CL_API_ENTRY void * CL_API_CALL +clSVMAllocARM(cl_context context, + cl_svm_mem_flags_arm flags, + size_t size, + cl_uint alignment) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY void CL_API_CALL +clSVMFreeARM(cl_context context, + void * svm_pointer) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMFreeARM(cl_command_queue command_queue, + cl_uint num_svm_pointers, + void * svm_pointers[], + void (CL_CALLBACK * pfn_free_func)(cl_command_queue queue, + cl_uint num_svm_pointers, + void * svm_pointers[], + void * user_data), + void * user_data, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemcpyARM(cl_command_queue command_queue, + cl_bool blocking_copy, + void * dst_ptr, + const void * src_ptr, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemFillARM(cl_command_queue command_queue, + void * svm_ptr, + const void * pattern, + size_t pattern_size, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMapARM(cl_command_queue command_queue, + cl_bool blocking_map, + cl_map_flags flags, + void * svm_ptr, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMUnmapARM(cl_command_queue command_queue, + void * svm_ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArgSVMPointerARM(cl_kernel kernel, + cl_uint arg_index, + const void * arg_value) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetKernelExecInfoARM(cl_kernel kernel, + cl_kernel_exec_info_arm param_name, + size_t param_value_size, + const void * param_value) CL_EXT_SUFFIX__VERSION_1_2; + +/******************************** + * cl_arm_get_core_id extension * + ********************************/ + +#ifdef CL_VERSION_1_2 + +#define cl_arm_get_core_id 1 + +/* Device info property for bitfield of cores present */ +#define CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM 0x40BF + +#endif /* CL_VERSION_1_2 */ + +/********************************* +* cl_arm_job_slot_selection +*********************************/ + +#define cl_arm_job_slot_selection 1 + +/* cl_device_info */ +#define CL_DEVICE_JOB_SLOTS_ARM 0x41E0 + +/* cl_command_queue_properties */ +#define CL_QUEUE_JOB_SLOT_ARM 0x41E1 + +#ifdef __cplusplus +} +#endif + + +#endif /* __CL_EXT_H */ diff --git a/opencl/khronos/headers/opencl2.2/CL/cl_ext_intel.h b/opencl/khronos/headers/opencl2.2/CL/cl_ext_intel.h new file mode 100644 index 0000000000..cb903ffc3b --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl_ext_intel.h @@ -0,0 +1,411 @@ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +/*****************************************************************************\ + +Copyright (c) 2013-2019 Intel Corporation All Rights Reserved. + +THESE MATERIALS ARE PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THESE +MATERIALS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +File Name: cl_ext_intel.h + +Abstract: + +Notes: + +\*****************************************************************************/ + +#ifndef __CL_EXT_INTEL_H +#define __CL_EXT_INTEL_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*************************************** +* cl_intel_thread_local_exec extension * +****************************************/ + +#define cl_intel_thread_local_exec 1 + +#define CL_QUEUE_THREAD_LOCAL_EXEC_ENABLE_INTEL (((cl_bitfield)1) << 31) + +/*********************************************** +* cl_intel_device_partition_by_names extension * +************************************************/ + +#define cl_intel_device_partition_by_names 1 + +#define CL_DEVICE_PARTITION_BY_NAMES_INTEL 0x4052 +#define CL_PARTITION_BY_NAMES_LIST_END_INTEL -1 + +/************************************************ +* cl_intel_accelerator extension * +* cl_intel_motion_estimation extension * +* cl_intel_advanced_motion_estimation extension * +*************************************************/ + +#define cl_intel_accelerator 1 +#define cl_intel_motion_estimation 1 +#define cl_intel_advanced_motion_estimation 1 + +typedef struct _cl_accelerator_intel* cl_accelerator_intel; +typedef cl_uint cl_accelerator_type_intel; +typedef cl_uint cl_accelerator_info_intel; + +typedef struct _cl_motion_estimation_desc_intel { + cl_uint mb_block_type; + cl_uint subpixel_mode; + cl_uint sad_adjust_mode; + cl_uint search_path_type; +} cl_motion_estimation_desc_intel; + +/* error codes */ +#define CL_INVALID_ACCELERATOR_INTEL -1094 +#define CL_INVALID_ACCELERATOR_TYPE_INTEL -1095 +#define CL_INVALID_ACCELERATOR_DESCRIPTOR_INTEL -1096 +#define CL_ACCELERATOR_TYPE_NOT_SUPPORTED_INTEL -1097 + +/* cl_accelerator_type_intel */ +#define CL_ACCELERATOR_TYPE_MOTION_ESTIMATION_INTEL 0x0 + +/* cl_accelerator_info_intel */ +#define CL_ACCELERATOR_DESCRIPTOR_INTEL 0x4090 +#define CL_ACCELERATOR_REFERENCE_COUNT_INTEL 0x4091 +#define CL_ACCELERATOR_CONTEXT_INTEL 0x4092 +#define CL_ACCELERATOR_TYPE_INTEL 0x4093 + +/* cl_motion_detect_desc_intel flags */ +#define CL_ME_MB_TYPE_16x16_INTEL 0x0 +#define CL_ME_MB_TYPE_8x8_INTEL 0x1 +#define CL_ME_MB_TYPE_4x4_INTEL 0x2 + +#define CL_ME_SUBPIXEL_MODE_INTEGER_INTEL 0x0 +#define CL_ME_SUBPIXEL_MODE_HPEL_INTEL 0x1 +#define CL_ME_SUBPIXEL_MODE_QPEL_INTEL 0x2 + +#define CL_ME_SAD_ADJUST_MODE_NONE_INTEL 0x0 +#define CL_ME_SAD_ADJUST_MODE_HAAR_INTEL 0x1 + +#define CL_ME_SEARCH_PATH_RADIUS_2_2_INTEL 0x0 +#define CL_ME_SEARCH_PATH_RADIUS_4_4_INTEL 0x1 +#define CL_ME_SEARCH_PATH_RADIUS_16_12_INTEL 0x5 + +#define CL_ME_SKIP_BLOCK_TYPE_16x16_INTEL 0x0 +#define CL_ME_CHROMA_INTRA_PREDICT_ENABLED_INTEL 0x1 +#define CL_ME_LUMA_INTRA_PREDICT_ENABLED_INTEL 0x2 +#define CL_ME_SKIP_BLOCK_TYPE_8x8_INTEL 0x4 + +#define CL_ME_FORWARD_INPUT_MODE_INTEL 0x1 +#define CL_ME_BACKWARD_INPUT_MODE_INTEL 0x2 +#define CL_ME_BIDIRECTION_INPUT_MODE_INTEL 0x3 + +#define CL_ME_BIDIR_WEIGHT_QUARTER_INTEL 16 +#define CL_ME_BIDIR_WEIGHT_THIRD_INTEL 21 +#define CL_ME_BIDIR_WEIGHT_HALF_INTEL 32 +#define CL_ME_BIDIR_WEIGHT_TWO_THIRD_INTEL 43 +#define CL_ME_BIDIR_WEIGHT_THREE_QUARTER_INTEL 48 + +#define CL_ME_COST_PENALTY_NONE_INTEL 0x0 +#define CL_ME_COST_PENALTY_LOW_INTEL 0x1 +#define CL_ME_COST_PENALTY_NORMAL_INTEL 0x2 +#define CL_ME_COST_PENALTY_HIGH_INTEL 0x3 + +#define CL_ME_COST_PRECISION_QPEL_INTEL 0x0 +#define CL_ME_COST_PRECISION_HPEL_INTEL 0x1 +#define CL_ME_COST_PRECISION_PEL_INTEL 0x2 +#define CL_ME_COST_PRECISION_DPEL_INTEL 0x3 + +#define CL_ME_LUMA_PREDICTOR_MODE_VERTICAL_INTEL 0x0 +#define CL_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_INTEL 0x1 +#define CL_ME_LUMA_PREDICTOR_MODE_DC_INTEL 0x2 +#define CL_ME_LUMA_PREDICTOR_MODE_DIAGONAL_DOWN_LEFT_INTEL 0x3 + +#define CL_ME_LUMA_PREDICTOR_MODE_DIAGONAL_DOWN_RIGHT_INTEL 0x4 +#define CL_ME_LUMA_PREDICTOR_MODE_PLANE_INTEL 0x4 +#define CL_ME_LUMA_PREDICTOR_MODE_VERTICAL_RIGHT_INTEL 0x5 +#define CL_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_DOWN_INTEL 0x6 +#define CL_ME_LUMA_PREDICTOR_MODE_VERTICAL_LEFT_INTEL 0x7 +#define CL_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_UP_INTEL 0x8 + +#define CL_ME_CHROMA_PREDICTOR_MODE_DC_INTEL 0x0 +#define CL_ME_CHROMA_PREDICTOR_MODE_HORIZONTAL_INTEL 0x1 +#define CL_ME_CHROMA_PREDICTOR_MODE_VERTICAL_INTEL 0x2 +#define CL_ME_CHROMA_PREDICTOR_MODE_PLANE_INTEL 0x3 + +/* cl_device_info */ +#define CL_DEVICE_ME_VERSION_INTEL 0x407E + +#define CL_ME_VERSION_LEGACY_INTEL 0x0 +#define CL_ME_VERSION_ADVANCED_VER_1_INTEL 0x1 +#define CL_ME_VERSION_ADVANCED_VER_2_INTEL 0x2 + +extern CL_API_ENTRY cl_accelerator_intel CL_API_CALL +clCreateAcceleratorINTEL( + cl_context context, + cl_accelerator_type_intel accelerator_type, + size_t descriptor_size, + const void* descriptor, + cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_accelerator_intel (CL_API_CALL *clCreateAcceleratorINTEL_fn)( + cl_context context, + cl_accelerator_type_intel accelerator_type, + size_t descriptor_size, + const void* descriptor, + cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetAcceleratorInfoINTEL( + cl_accelerator_intel accelerator, + cl_accelerator_info_intel param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetAcceleratorInfoINTEL_fn)( + cl_accelerator_intel accelerator, + cl_accelerator_info_intel param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clRetainAcceleratorINTEL( + cl_accelerator_intel accelerator) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clRetainAcceleratorINTEL_fn)( + cl_accelerator_intel accelerator) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clReleaseAcceleratorINTEL( + cl_accelerator_intel accelerator) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clReleaseAcceleratorINTEL_fn)( + cl_accelerator_intel accelerator) CL_EXT_SUFFIX__VERSION_1_2; + +/****************************************** +* cl_intel_simultaneous_sharing extension * +*******************************************/ + +#define cl_intel_simultaneous_sharing 1 + +#define CL_DEVICE_SIMULTANEOUS_INTEROPS_INTEL 0x4104 +#define CL_DEVICE_NUM_SIMULTANEOUS_INTEROPS_INTEL 0x4105 + +/*********************************** +* cl_intel_egl_image_yuv extension * +************************************/ + +#define cl_intel_egl_image_yuv 1 + +#define CL_EGL_YUV_PLANE_INTEL 0x4107 + +/******************************** +* cl_intel_packed_yuv extension * +*********************************/ + +#define cl_intel_packed_yuv 1 + +#define CL_YUYV_INTEL 0x4076 +#define CL_UYVY_INTEL 0x4077 +#define CL_YVYU_INTEL 0x4078 +#define CL_VYUY_INTEL 0x4079 + +/******************************************** +* cl_intel_required_subgroup_size extension * +*********************************************/ + +#define cl_intel_required_subgroup_size 1 + +#define CL_DEVICE_SUB_GROUP_SIZES_INTEL 0x4108 +#define CL_KERNEL_SPILL_MEM_SIZE_INTEL 0x4109 +#define CL_KERNEL_COMPILE_SUB_GROUP_SIZE_INTEL 0x410A + +/**************************************** +* cl_intel_driver_diagnostics extension * +*****************************************/ + +#define cl_intel_driver_diagnostics 1 + +typedef cl_uint cl_diagnostics_verbose_level; + +#define CL_CONTEXT_SHOW_DIAGNOSTICS_INTEL 0x4106 + +#define CL_CONTEXT_DIAGNOSTICS_LEVEL_ALL_INTEL ( 0xff ) +#define CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL ( 1 ) +#define CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL ( 1 << 1 ) +#define CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL ( 1 << 2 ) + +/******************************** +* cl_intel_planar_yuv extension * +*********************************/ + +#define CL_NV12_INTEL 0x410E + +#define CL_MEM_NO_ACCESS_INTEL ( 1 << 24 ) +#define CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL ( 1 << 25 ) + +#define CL_DEVICE_PLANAR_YUV_MAX_WIDTH_INTEL 0x417E +#define CL_DEVICE_PLANAR_YUV_MAX_HEIGHT_INTEL 0x417F + +/******************************************************* +* cl_intel_device_side_avc_motion_estimation extension * +********************************************************/ + +#define CL_DEVICE_AVC_ME_VERSION_INTEL 0x410B +#define CL_DEVICE_AVC_ME_SUPPORTS_TEXTURE_SAMPLER_USE_INTEL 0x410C +#define CL_DEVICE_AVC_ME_SUPPORTS_PREEMPTION_INTEL 0x410D + +#define CL_AVC_ME_VERSION_0_INTEL 0x0; // No support. +#define CL_AVC_ME_VERSION_1_INTEL 0x1; // First supported version. + +#define CL_AVC_ME_MAJOR_16x16_INTEL 0x0 +#define CL_AVC_ME_MAJOR_16x8_INTEL 0x1 +#define CL_AVC_ME_MAJOR_8x16_INTEL 0x2 +#define CL_AVC_ME_MAJOR_8x8_INTEL 0x3 + +#define CL_AVC_ME_MINOR_8x8_INTEL 0x0 +#define CL_AVC_ME_MINOR_8x4_INTEL 0x1 +#define CL_AVC_ME_MINOR_4x8_INTEL 0x2 +#define CL_AVC_ME_MINOR_4x4_INTEL 0x3 + +#define CL_AVC_ME_MAJOR_FORWARD_INTEL 0x0 +#define CL_AVC_ME_MAJOR_BACKWARD_INTEL 0x1 +#define CL_AVC_ME_MAJOR_BIDIRECTIONAL_INTEL 0x2 + +#define CL_AVC_ME_PARTITION_MASK_ALL_INTEL 0x0 +#define CL_AVC_ME_PARTITION_MASK_16x16_INTEL 0x7E +#define CL_AVC_ME_PARTITION_MASK_16x8_INTEL 0x7D +#define CL_AVC_ME_PARTITION_MASK_8x16_INTEL 0x7B +#define CL_AVC_ME_PARTITION_MASK_8x8_INTEL 0x77 +#define CL_AVC_ME_PARTITION_MASK_8x4_INTEL 0x6F +#define CL_AVC_ME_PARTITION_MASK_4x8_INTEL 0x5F +#define CL_AVC_ME_PARTITION_MASK_4x4_INTEL 0x3F + +#define CL_AVC_ME_SEARCH_WINDOW_EXHAUSTIVE_INTEL 0x0 +#define CL_AVC_ME_SEARCH_WINDOW_SMALL_INTEL 0x1 +#define CL_AVC_ME_SEARCH_WINDOW_TINY_INTEL 0x2 +#define CL_AVC_ME_SEARCH_WINDOW_EXTRA_TINY_INTEL 0x3 +#define CL_AVC_ME_SEARCH_WINDOW_DIAMOND_INTEL 0x4 +#define CL_AVC_ME_SEARCH_WINDOW_LARGE_DIAMOND_INTEL 0x5 +#define CL_AVC_ME_SEARCH_WINDOW_RESERVED0_INTEL 0x6 +#define CL_AVC_ME_SEARCH_WINDOW_RESERVED1_INTEL 0x7 +#define CL_AVC_ME_SEARCH_WINDOW_CUSTOM_INTEL 0x8 +#define CL_AVC_ME_SEARCH_WINDOW_16x12_RADIUS_INTEL 0x9 +#define CL_AVC_ME_SEARCH_WINDOW_4x4_RADIUS_INTEL 0x2 +#define CL_AVC_ME_SEARCH_WINDOW_2x2_RADIUS_INTEL 0xa + +#define CL_AVC_ME_SAD_ADJUST_MODE_NONE_INTEL 0x0 +#define CL_AVC_ME_SAD_ADJUST_MODE_HAAR_INTEL 0x2 + +#define CL_AVC_ME_SUBPIXEL_MODE_INTEGER_INTEL 0x0 +#define CL_AVC_ME_SUBPIXEL_MODE_HPEL_INTEL 0x1 +#define CL_AVC_ME_SUBPIXEL_MODE_QPEL_INTEL 0x3 + +#define CL_AVC_ME_COST_PRECISION_QPEL_INTEL 0x0 +#define CL_AVC_ME_COST_PRECISION_HPEL_INTEL 0x1 +#define CL_AVC_ME_COST_PRECISION_PEL_INTEL 0x2 +#define CL_AVC_ME_COST_PRECISION_DPEL_INTEL 0x3 + +#define CL_AVC_ME_BIDIR_WEIGHT_QUARTER_INTEL 0x10 +#define CL_AVC_ME_BIDIR_WEIGHT_THIRD_INTEL 0x15 +#define CL_AVC_ME_BIDIR_WEIGHT_HALF_INTEL 0x20 +#define CL_AVC_ME_BIDIR_WEIGHT_TWO_THIRD_INTEL 0x2B +#define CL_AVC_ME_BIDIR_WEIGHT_THREE_QUARTER_INTEL 0x30 + +#define CL_AVC_ME_BORDER_REACHED_LEFT_INTEL 0x0 +#define CL_AVC_ME_BORDER_REACHED_RIGHT_INTEL 0x2 +#define CL_AVC_ME_BORDER_REACHED_TOP_INTEL 0x4 +#define CL_AVC_ME_BORDER_REACHED_BOTTOM_INTEL 0x8 + +#define CL_AVC_ME_SKIP_BLOCK_PARTITION_16x16_INTEL 0x0 +#define CL_AVC_ME_SKIP_BLOCK_PARTITION_8x8_INTEL 0x4000 + +#define CL_AVC_ME_SKIP_BLOCK_16x16_FORWARD_ENABLE_INTEL ( 0x1 << 24 ) +#define CL_AVC_ME_SKIP_BLOCK_16x16_BACKWARD_ENABLE_INTEL ( 0x2 << 24 ) +#define CL_AVC_ME_SKIP_BLOCK_16x16_DUAL_ENABLE_INTEL ( 0x3 << 24 ) +#define CL_AVC_ME_SKIP_BLOCK_8x8_FORWARD_ENABLE_INTEL ( 0x55 << 24 ) +#define CL_AVC_ME_SKIP_BLOCK_8x8_BACKWARD_ENABLE_INTEL ( 0xAA << 24 ) +#define CL_AVC_ME_SKIP_BLOCK_8x8_DUAL_ENABLE_INTEL ( 0xFF << 24 ) +#define CL_AVC_ME_SKIP_BLOCK_8x8_0_FORWARD_ENABLE_INTEL ( 0x1 << 24 ) +#define CL_AVC_ME_SKIP_BLOCK_8x8_0_BACKWARD_ENABLE_INTEL ( 0x2 << 24 ) +#define CL_AVC_ME_SKIP_BLOCK_8x8_1_FORWARD_ENABLE_INTEL ( 0x1 << 26 ) +#define CL_AVC_ME_SKIP_BLOCK_8x8_1_BACKWARD_ENABLE_INTEL ( 0x2 << 26 ) +#define CL_AVC_ME_SKIP_BLOCK_8x8_2_FORWARD_ENABLE_INTEL ( 0x1 << 28 ) +#define CL_AVC_ME_SKIP_BLOCK_8x8_2_BACKWARD_ENABLE_INTEL ( 0x2 << 28 ) +#define CL_AVC_ME_SKIP_BLOCK_8x8_3_FORWARD_ENABLE_INTEL ( 0x1 << 30 ) +#define CL_AVC_ME_SKIP_BLOCK_8x8_3_BACKWARD_ENABLE_INTEL ( 0x2 << 30 ) + +#define CL_AVC_ME_BLOCK_BASED_SKIP_4x4_INTEL 0x00 +#define CL_AVC_ME_BLOCK_BASED_SKIP_8x8_INTEL 0x80 + +#define CL_AVC_ME_INTRA_16x16_INTEL 0x0 +#define CL_AVC_ME_INTRA_8x8_INTEL 0x1 +#define CL_AVC_ME_INTRA_4x4_INTEL 0x2 + +#define CL_AVC_ME_INTRA_LUMA_PARTITION_MASK_16x16_INTEL 0x6 +#define CL_AVC_ME_INTRA_LUMA_PARTITION_MASK_8x8_INTEL 0x5 +#define CL_AVC_ME_INTRA_LUMA_PARTITION_MASK_4x4_INTEL 0x3 + +#define CL_AVC_ME_INTRA_NEIGHBOR_LEFT_MASK_ENABLE_INTEL 0x60 +#define CL_AVC_ME_INTRA_NEIGHBOR_UPPER_MASK_ENABLE_INTEL 0x10 +#define CL_AVC_ME_INTRA_NEIGHBOR_UPPER_RIGHT_MASK_ENABLE_INTEL 0x8 +#define CL_AVC_ME_INTRA_NEIGHBOR_UPPER_LEFT_MASK_ENABLE_INTEL 0x4 + +#define CL_AVC_ME_LUMA_PREDICTOR_MODE_VERTICAL_INTEL 0x0 +#define CL_AVC_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_INTEL 0x1 +#define CL_AVC_ME_LUMA_PREDICTOR_MODE_DC_INTEL 0x2 +#define CL_AVC_ME_LUMA_PREDICTOR_MODE_DIAGONAL_DOWN_LEFT_INTEL 0x3 +#define CL_AVC_ME_LUMA_PREDICTOR_MODE_DIAGONAL_DOWN_RIGHT_INTEL 0x4 +#define CL_AVC_ME_LUMA_PREDICTOR_MODE_PLANE_INTEL 0x4 +#define CL_AVC_ME_LUMA_PREDICTOR_MODE_VERTICAL_RIGHT_INTEL 0x5 +#define CL_AVC_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_DOWN_INTEL 0x6 +#define CL_AVC_ME_LUMA_PREDICTOR_MODE_VERTICAL_LEFT_INTEL 0x7 +#define CL_AVC_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_UP_INTEL 0x8 +#define CL_AVC_ME_CHROMA_PREDICTOR_MODE_DC_INTEL 0x0 +#define CL_AVC_ME_CHROMA_PREDICTOR_MODE_HORIZONTAL_INTEL 0x1 +#define CL_AVC_ME_CHROMA_PREDICTOR_MODE_VERTICAL_INTEL 0x2 +#define CL_AVC_ME_CHROMA_PREDICTOR_MODE_PLANE_INTEL 0x3 + +#define CL_AVC_ME_FRAME_FORWARD_INTEL 0x1 +#define CL_AVC_ME_FRAME_BACKWARD_INTEL 0x2 +#define CL_AVC_ME_FRAME_DUAL_INTEL 0x3 + +#define CL_AVC_ME_SLICE_TYPE_PRED_INTEL 0x0 +#define CL_AVC_ME_SLICE_TYPE_BPRED_INTEL 0x1 +#define CL_AVC_ME_SLICE_TYPE_INTRA_INTEL 0x2 + +#define CL_AVC_ME_INTERLACED_SCAN_TOP_FIELD_INTEL 0x0 +#define CL_AVC_ME_INTERLACED_SCAN_BOTTOM_FIELD_INTEL 0x1 + +#ifdef __cplusplus +} +#endif + +#endif /* __CL_EXT_INTEL_H */ diff --git a/opencl/khronos/headers/opencl2.2/CL/cl_gl.h b/opencl/khronos/headers/opencl2.2/CL/cl_gl.h new file mode 100644 index 0000000000..b587f02a98 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl_gl.h @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#ifndef __OPENCL_CL_GL_H +#define __OPENCL_CL_GL_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef cl_uint cl_gl_object_type; +typedef cl_uint cl_gl_texture_info; +typedef cl_uint cl_gl_platform_info; +typedef struct __GLsync *cl_GLsync; + +/* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken */ +#define CL_GL_OBJECT_BUFFER 0x2000 +#define CL_GL_OBJECT_TEXTURE2D 0x2001 +#define CL_GL_OBJECT_TEXTURE3D 0x2002 +#define CL_GL_OBJECT_RENDERBUFFER 0x2003 +#ifdef CL_VERSION_1_2 +#define CL_GL_OBJECT_TEXTURE2D_ARRAY 0x200E +#define CL_GL_OBJECT_TEXTURE1D 0x200F +#define CL_GL_OBJECT_TEXTURE1D_ARRAY 0x2010 +#define CL_GL_OBJECT_TEXTURE_BUFFER 0x2011 +#endif + +/* cl_gl_texture_info */ +#define CL_GL_TEXTURE_TARGET 0x2004 +#define CL_GL_MIPMAP_LEVEL 0x2005 +#ifdef CL_VERSION_1_2 +#define CL_GL_NUM_SAMPLES 0x2012 +#endif + + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLBuffer(cl_context context, + cl_mem_flags flags, + cl_GLuint bufobj, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLTexture(cl_context context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texture, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +#endif + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLRenderbuffer(cl_context context, + cl_mem_flags flags, + cl_GLuint renderbuffer, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetGLObjectInfo(cl_mem memobj, + cl_gl_object_type * gl_object_type, + cl_GLuint * gl_object_name) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetGLTextureInfo(cl_mem memobj, + cl_gl_texture_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireGLObjects(cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseGLObjects(cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0; + + +/* Deprecated OpenCL 1.1 APIs */ +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateFromGLTexture2D(cl_context context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texture, + cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL +clCreateFromGLTexture3D(cl_context context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texture, + cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +/* cl_khr_gl_sharing extension */ + +#define cl_khr_gl_sharing 1 + +typedef cl_uint cl_gl_context_info; + +/* Additional Error Codes */ +#define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000 + +/* cl_gl_context_info */ +#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 +#define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007 + +/* Additional cl_context_properties */ +#define CL_GL_CONTEXT_KHR 0x2008 +#define CL_EGL_DISPLAY_KHR 0x2009 +#define CL_GLX_DISPLAY_KHR 0x200A +#define CL_WGL_HDC_KHR 0x200B +#define CL_CGL_SHAREGROUP_KHR 0x200C + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetGLContextInfoKHR(const cl_context_properties * properties, + cl_gl_context_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( + const cl_context_properties * properties, + cl_gl_context_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret); + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_GL_H */ diff --git a/opencl/khronos/headers/opencl2.2/CL/cl_gl_ext.h b/opencl/khronos/headers/opencl2.2/CL/cl_gl_ext.h new file mode 100644 index 0000000000..9bb75405bc --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl_gl_ext.h @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#ifndef __OPENCL_CL_GL_EXT_H +#define __OPENCL_CL_GL_EXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* + * cl_khr_gl_event extension + */ +#define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D + +extern CL_API_ENTRY cl_event CL_API_CALL +clCreateEventFromGLsyncKHR(cl_context context, + cl_GLsync cl_GLsync, + cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_GL_EXT_H */ diff --git a/opencl/khronos/headers/opencl2.2/CL/cl_icd.h b/opencl/khronos/headers/opencl2.2/CL/cl_icd.h new file mode 100644 index 0000000000..746d8a4af2 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl_icd.h @@ -0,0 +1,1257 @@ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#ifndef OPENCL_CL_ICD_H +#define OPENCL_CL_ICD_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This file contains pointer type definitions for each of the CL API calls as + * well as a type definition for the dispatch table used by the Khronos ICD + * loader (see cl_khr_icd extension specification for background). + */ + +/* API function pointer definitions */ + +// Platform APIs +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetPlatformIDs)( + cl_uint num_entries, cl_platform_id *platforms, + cl_uint *num_platforms) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetPlatformInfo)( + cl_platform_id platform, cl_platform_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +// Device APIs +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetDeviceIDs)( + cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, + cl_device_id *devices, cl_uint *num_devices) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetDeviceInfo)( + cl_device_id device, cl_device_info param_name, size_t param_value_size, + void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clCreateSubDevices)( + cl_device_id in_device, + const cl_device_partition_property *partition_properties, + cl_uint num_entries, cl_device_id *out_devices, cl_uint *num_devices); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clRetainDevice)( + cl_device_id device) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clReleaseDevice)( + cl_device_id device) CL_API_SUFFIX__VERSION_1_2; + +#else + +typedef void *cl_api_clCreateSubDevices; +typedef void *cl_api_clRetainDevice; +typedef void *cl_api_clReleaseDevice; + +#endif + +// Context APIs +typedef CL_API_ENTRY cl_context(CL_API_CALL *cl_api_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) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_context(CL_API_CALL *cl_api_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) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clRetainContext)( + cl_context context) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clReleaseContext)( + cl_context context) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetContextInfo)( + cl_context context, cl_context_info param_name, size_t param_value_size, + void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +// Command Queue APIs +typedef CL_API_ENTRY cl_command_queue(CL_API_CALL *cl_api_clCreateCommandQueue)( + cl_context context, cl_device_id device, + cl_command_queue_properties properties, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_2_0 + +typedef CL_API_ENTRY +cl_command_queue(CL_API_CALL *cl_api_clCreateCommandQueueWithProperties)( + cl_context /* context */, cl_device_id /* device */, + const cl_queue_properties * /* properties */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; + +#else + +typedef void *cl_api_clCreateCommandQueueWithProperties; + +#endif + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clRetainCommandQueue)( + cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clReleaseCommandQueue)( + cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetCommandQueueInfo)( + cl_command_queue command_queue, cl_command_queue_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +// Memory Object APIs +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateBuffer)( + cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_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) CL_API_SUFFIX__VERSION_1_2; + +#else + +typedef void *cl_api_clCreateImage; + +#endif + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clRetainMemObject)( + cl_mem memobj) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clReleaseMemObject)( + cl_mem memobj) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_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) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetMemObjectInfo)( + cl_mem memobj, cl_mem_info param_name, size_t param_value_size, + void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetImageInfo)( + cl_mem image, cl_image_info param_name, size_t param_value_size, + void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_2_0 + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreatePipe)( + cl_context /* context */, cl_mem_flags /* flags */, + cl_uint /* pipe_packet_size */, cl_uint /* pipe_max_packets */, + const cl_pipe_properties * /* properties */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetPipeInfo)( + cl_mem /* pipe */, cl_pipe_info /* param_name */, + size_t /* param_value_size */, void * /* param_value */, + size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_2_0; + +typedef CL_API_ENTRY void *(CL_API_CALL *cl_api_clSVMAlloc)( + cl_context /* context */, cl_svm_mem_flags /* flags */, size_t /* size */, + unsigned int /* alignment */)CL_API_SUFFIX__VERSION_2_0; + +typedef CL_API_ENTRY void(CL_API_CALL *cl_api_clSVMFree)( + cl_context /* context */, + void * /* svm_pointer */) CL_API_SUFFIX__VERSION_2_0; + +#else + +typedef void *cl_api_clCreatePipe; +typedef void *cl_api_clGetPipeInfo; +typedef void *cl_api_clSVMAlloc; +typedef void *cl_api_clSVMFree; + +#endif + +// Sampler APIs +typedef CL_API_ENTRY cl_sampler(CL_API_CALL *cl_api_clCreateSampler)( + cl_context context, cl_bool normalized_coords, + cl_addressing_mode addressing_mode, cl_filter_mode filter_mode, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clRetainSampler)( + cl_sampler sampler) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clReleaseSampler)( + cl_sampler sampler) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetSamplerInfo)( + cl_sampler sampler, cl_sampler_info param_name, size_t param_value_size, + void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_2_0 + +typedef CL_API_ENTRY +cl_sampler(CL_API_CALL *cl_api_clCreateSamplerWithProperties)( + cl_context /* context */, + const cl_sampler_properties * /* sampler_properties */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; + +#else + +typedef void *cl_api_clCreateSamplerWithProperties; + +#endif + +// Program Object APIs +typedef CL_API_ENTRY cl_program(CL_API_CALL *cl_api_clCreateProgramWithSource)( + cl_context context, cl_uint count, const char **strings, + const size_t *lengths, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_program(CL_API_CALL *cl_api_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) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +typedef CL_API_ENTRY +cl_program(CL_API_CALL *cl_api_clCreateProgramWithBuiltInKernels)( + cl_context context, cl_uint num_devices, const cl_device_id *device_list, + const char *kernel_names, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +#else + +typedef void *cl_api_clCreateProgramWithBuiltInKernels; + +#endif + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clRetainProgram)( + cl_program program) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clReleaseProgram)( + cl_program program) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_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) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clCompileProgram)( + cl_program program, cl_uint num_devices, const cl_device_id *device_list, + const char *options, cl_uint num_input_headers, + const cl_program *input_headers, const char **header_include_names, + void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), + void *user_data) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_program(CL_API_CALL *cl_api_clLinkProgram)( + cl_context context, cl_uint num_devices, const cl_device_id *device_list, + const char *options, cl_uint num_input_programs, + const cl_program *input_programs, + void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), + void *user_data, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +#else + +typedef void *cl_api_clCompileProgram; +typedef void *cl_api_clLinkProgram; + +#endif + +#ifdef CL_VERSION_2_2 + +typedef CL_API_ENTRY +cl_int(CL_API_CALL *cl_api_clSetProgramSpecializationConstant)( + cl_program program, cl_uint spec_id, size_t spec_size, + const void *spec_value) CL_API_SUFFIX__VERSION_2_2; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clSetProgramReleaseCallback)( + cl_program program, + void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), + void *user_data) CL_API_SUFFIX__VERSION_2_2; + +#else + +typedef void *cl_api_clSetProgramSpecializationConstant; +typedef void *cl_api_clSetProgramReleaseCallback; + +#endif + +#ifdef CL_VERSION_1_2 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clUnloadPlatformCompiler)( + cl_platform_id platform) CL_API_SUFFIX__VERSION_1_2; + +#else + +typedef void *cl_api_clUnloadPlatformCompiler; + +#endif + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetProgramInfo)( + cl_program program, cl_program_info param_name, size_t param_value_size, + void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_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) CL_API_SUFFIX__VERSION_1_0; + +// Kernel Object APIs +typedef CL_API_ENTRY cl_kernel(CL_API_CALL *cl_api_clCreateKernel)( + cl_program program, const char *kernel_name, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clCreateKernelsInProgram)( + cl_program program, cl_uint num_kernels, cl_kernel *kernels, + cl_uint *num_kernels_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clRetainKernel)( + cl_kernel kernel) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clReleaseKernel)( + cl_kernel kernel) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clSetKernelArg)( + cl_kernel kernel, cl_uint arg_index, size_t arg_size, + const void *arg_value) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetKernelInfo)( + cl_kernel kernel, cl_kernel_info param_name, size_t param_value_size, + void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetKernelArgInfo)( + cl_kernel kernel, cl_uint arg_indx, cl_kernel_arg_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_2; + +#else + +typedef void *cl_api_clGetKernelArgInfo; + +#endif + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_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) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_2_0 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clSetKernelArgSVMPointer)( + cl_kernel /* kernel */, cl_uint /* arg_index */, + const void * /* arg_value */) CL_API_SUFFIX__VERSION_2_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clSetKernelExecInfo)( + cl_kernel /* kernel */, cl_kernel_exec_info /* param_name */, + size_t /* param_value_size */, + const void * /* param_value */) CL_API_SUFFIX__VERSION_2_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetKernelSubGroupInfoKHR)( + cl_kernel /* in_kernel */, cl_device_id /*in_device*/, + cl_kernel_sub_group_info /* param_name */, size_t /*input_value_size*/, + const void * /*input_value*/, size_t /*param_value_size*/, + void * /*param_value*/, + size_t * /*param_value_size_ret*/) CL_EXT_SUFFIX__VERSION_2_0; + +#else + +typedef void *cl_api_clSetKernelArgSVMPointer; +typedef void *cl_api_clSetKernelExecInfo; +typedef void *cl_api_clGetKernelSubGroupInfoKHR; + +#endif + +// Event Object APIs +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clWaitForEvents)( + cl_uint num_events, const cl_event *event_list) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetEventInfo)( + cl_event event, cl_event_info param_name, size_t param_value_size, + void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clRetainEvent)(cl_event event) + CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clReleaseEvent)(cl_event event) + CL_API_SUFFIX__VERSION_1_0; + +// Profiling APIs +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetEventProfilingInfo)( + cl_event event, cl_profiling_info param_name, size_t param_value_size, + void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +// Flush and Finish APIs +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clFlush)( + cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clFinish)( + cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0; + +// Enqueued Commands APIs +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueReadBuffer)( + cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, + size_t offset, size_t cb, void *ptr, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_1 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueReadBufferRect)( + cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, + const size_t *buffer_origin, const size_t *host_origin, + const size_t *region, size_t buffer_row_pitch, size_t buffer_slice_pitch, + size_t host_row_pitch, size_t host_slice_pitch, void *ptr, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_1; + +#else + +typedef void *cl_api_clEnqueueReadBufferRect; + +#endif + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueWriteBuffer)( + cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, + size_t offset, size_t cb, const void *ptr, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_1 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueWriteBufferRect)( + cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, + const size_t *buffer_origin, const size_t *host_origin, + const size_t *region, size_t buffer_row_pitch, size_t buffer_slice_pitch, + size_t host_row_pitch, size_t host_slice_pitch, const void *ptr, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_1; + +#else + +typedef void *cl_api_clEnqueueWriteBufferRect; + +#endif + +#ifdef CL_VERSION_1_2 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueFillBuffer)( + cl_command_queue command_queue, cl_mem buffer, const void *pattern, + size_t pattern_size, size_t offset, size_t cb, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; + +#else + +typedef void *cl_api_clEnqueueFillBuffer; + +#endif + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueCopyBuffer)( + cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, + size_t src_offset, size_t dst_offset, size_t cb, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_1 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueCopyBufferRect)( + cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, + const size_t *src_origin, const size_t *dst_origin, const size_t *region, + size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, + size_t dst_slice_pitch, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_1; + +#else + +typedef void *cl_api_clEnqueueCopyBufferRect; + +#endif + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueReadImage)( + cl_command_queue command_queue, cl_mem image, cl_bool blocking_read, + const size_t *origin, const size_t *region, 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) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueWriteImage)( + cl_command_queue command_queue, cl_mem image, cl_bool blocking_write, + const size_t *origin, const size_t *region, 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) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueFillImage)( + cl_command_queue command_queue, cl_mem image, const void *fill_color, + const size_t origin[3], const size_t region[3], + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; + +#else + +typedef void *cl_api_clEnqueueFillImage; + +#endif + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueCopyImage)( + cl_command_queue command_queue, cl_mem src_image, cl_mem dst_image, + const size_t *src_origin, const size_t *dst_origin, const size_t *region, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueCopyImageToBuffer)( + cl_command_queue command_queue, cl_mem src_image, cl_mem dst_buffer, + const size_t *src_origin, const size_t *region, size_t dst_offset, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueCopyBufferToImage)( + cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_image, + size_t src_offset, const size_t *dst_origin, const size_t *region, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY void *(CL_API_CALL *cl_api_clEnqueueMapBuffer)( + cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_map, + cl_map_flags map_flags, size_t offset, size_t cb, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *event, cl_int *errcode_ret)CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY void *(CL_API_CALL *cl_api_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)CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_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) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueMigrateMemObjects)( + cl_command_queue command_queue, cl_uint num_mem_objects, + const cl_mem *mem_objects, cl_mem_migration_flags flags, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; + +#else + +typedef void *cl_api_clEnqueueMigrateMemObjects; + +#endif + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_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) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueTask)( + cl_command_queue command_queue, cl_kernel kernel, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueNativeKernel)( + cl_command_queue command_queue, void(CL_CALLBACK *user_func)(void *), + void *args, size_t cb_args, cl_uint num_mem_objects, const cl_mem *mem_list, + const void **args_mem_loc, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; + +#ifdef CL_VERSION_1_2 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueMarkerWithWaitList)( + cl_command_queue command_queue, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueBarrierWithWaitList)( + cl_command_queue command_queue, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY void *( + CL_API_CALL *cl_api_clGetExtensionFunctionAddressForPlatform)( + cl_platform_id platform, + const char *function_name)CL_API_SUFFIX__VERSION_1_2; + +#else + +typedef void *cl_api_clEnqueueMarkerWithWaitList; +typedef void *cl_api_clEnqueueBarrierWithWaitList; +typedef void *cl_api_clGetExtensionFunctionAddressForPlatform; + +#endif + +// Shared Virtual Memory APIs + +#ifdef CL_VERSION_2_0 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueSVMFree)( + cl_command_queue /* command_queue */, cl_uint /* num_svm_pointers */, + void ** /* svm_pointers */, + void(CL_CALLBACK *pfn_free_func)(cl_command_queue /* queue */, + cl_uint /* num_svm_pointers */, + void ** /* svm_pointers[] */, + void * /* user_data */), + void * /* user_data */, cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueSVMMemcpy)( + cl_command_queue /* command_queue */, cl_bool /* blocking_copy */, + void * /* dst_ptr */, const void * /* src_ptr */, size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueSVMMemFill)( + cl_command_queue /* command_queue */, void * /* svm_ptr */, + const void * /* pattern */, size_t /* pattern_size */, size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueSVMMap)( + cl_command_queue /* command_queue */, cl_bool /* blocking_map */, + cl_map_flags /* map_flags */, void * /* svm_ptr */, size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueSVMUnmap)( + cl_command_queue /* command_queue */, void * /* svm_ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event * /* event_wait_list */, + cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; + +#else + +typedef void *cl_api_clEnqueueSVMFree; +typedef void *cl_api_clEnqueueSVMMemcpy; +typedef void *cl_api_clEnqueueSVMMemFill; +typedef void *cl_api_clEnqueueSVMMap; +typedef void *cl_api_clEnqueueSVMUnmap; + +#endif + +// Deprecated APIs +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clSetCommandQueueProperty)( + cl_command_queue command_queue, cl_command_queue_properties properties, + cl_bool enable, cl_command_queue_properties *old_properties) + CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateImage2D)( + cl_context context, cl_mem_flags flags, const cl_image_format *image_format, + size_t image_width, size_t image_height, size_t image_row_pitch, + void *host_ptr, cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateImage3D)( + cl_context context, cl_mem_flags flags, const cl_image_format *image_format, + size_t image_width, size_t image_height, size_t image_depth, + size_t image_row_pitch, size_t image_slice_pitch, void *host_ptr, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clUnloadCompiler)(void) + CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueMarker)( + cl_command_queue command_queue, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueWaitForEvents)( + cl_command_queue command_queue, cl_uint num_events, + const cl_event *event_list) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueBarrier)( + cl_command_queue command_queue) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +typedef CL_API_ENTRY void *(CL_API_CALL *cl_api_clGetExtensionFunctionAddress)( + const char *function_name)CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + +// GL and other APIs +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateFromGLBuffer)( + cl_context context, cl_mem_flags flags, cl_GLuint bufobj, + int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateFromGLTexture)( + cl_context context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, + cl_GLuint texture, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateFromGLTexture2D)( + cl_context context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, + cl_GLuint texture, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateFromGLTexture3D)( + cl_context context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, + cl_GLuint texture, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateFromGLRenderbuffer)( + cl_context context, cl_mem_flags flags, cl_GLuint renderbuffer, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetGLObjectInfo)( + cl_mem memobj, cl_gl_object_type *gl_object_type, + cl_GLuint *gl_object_name) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetGLTextureInfo)( + cl_mem memobj, cl_gl_texture_info param_name, size_t param_value_size, + void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueAcquireGLObjects)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueReleaseGLObjects)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; + +/* cl_khr_gl_sharing */ +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetGLContextInfoKHR)( + const cl_context_properties *properties, cl_gl_context_info param_name, + size_t param_value_size, void *param_value, size_t *param_value_size_ret); + +/* cl_khr_gl_event */ +typedef CL_API_ENTRY cl_event(CL_API_CALL *cl_api_clCreateEventFromGLsyncKHR)( + cl_context context, cl_GLsync sync, cl_int *errcode_ret); + +#if defined(_WIN32) + +/* cl_khr_d3d10_sharing */ + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetDeviceIDsFromD3D10KHR)( + cl_platform_id platform, cl_d3d10_device_source_khr d3d_device_source, + void *d3d_object, cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, cl_device_id *devices, + cl_uint *num_devices) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateFromD3D10BufferKHR)( + cl_context context, cl_mem_flags flags, ID3D10Buffer *resource, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateFromD3D10Texture2DKHR)( + cl_context context, cl_mem_flags flags, ID3D10Texture2D *resource, + UINT subresource, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateFromD3D10Texture3DKHR)( + cl_context context, cl_mem_flags flags, ID3D10Texture3D *resource, + UINT subresource, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY +cl_int(CL_API_CALL *cl_api_clEnqueueAcquireD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY +cl_int(CL_API_CALL *cl_api_clEnqueueReleaseD3D10ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; + +extern CL_API_ENTRY cl_int CL_API_CALL clGetDeviceIDsFromD3D10KHR( + cl_platform_id platform, cl_d3d10_device_source_khr d3d_device_source, + void *d3d_object, cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, cl_device_id *devices, cl_uint *num_devices); + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromD3D10BufferKHR(cl_context context, cl_mem_flags flags, + ID3D10Buffer *resource, cl_int *errcode_ret); + +extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromD3D10Texture2DKHR( + cl_context context, cl_mem_flags flags, ID3D10Texture2D *resource, + UINT subresource, cl_int *errcode_ret); + +extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromD3D10Texture3DKHR( + cl_context context, cl_mem_flags flags, ID3D10Texture3D *resource, + UINT subresource, cl_int *errcode_ret); + +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueAcquireD3D10ObjectsKHR( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueReleaseD3D10ObjectsKHR( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + +/* cl_khr_d3d11_sharing */ +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetDeviceIDsFromD3D11KHR)( + cl_platform_id platform, cl_d3d11_device_source_khr d3d_device_source, + void *d3d_object, cl_d3d11_device_set_khr d3d_device_set, + cl_uint num_entries, cl_device_id *devices, + cl_uint *num_devices) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateFromD3D11BufferKHR)( + cl_context context, cl_mem_flags flags, ID3D11Buffer *resource, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateFromD3D11Texture2DKHR)( + cl_context context, cl_mem_flags flags, ID3D11Texture2D *resource, + UINT subresource, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateFromD3D11Texture3DKHR)( + cl_context context, cl_mem_flags flags, ID3D11Texture3D *resource, + UINT subresource, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY +cl_int(CL_API_CALL *cl_api_clEnqueueAcquireD3D11ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY +cl_int(CL_API_CALL *cl_api_clEnqueueReleaseD3D11ObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; + +/* cl_khr_dx9_media_sharing */ +typedef CL_API_ENTRY +cl_int(CL_API_CALL *cl_api_clGetDeviceIDsFromDX9MediaAdapterKHR)( + cl_platform_id platform, cl_uint num_media_adapters, + cl_dx9_media_adapter_type_khr *media_adapters_type, void *media_adapters, + cl_dx9_media_adapter_set_khr media_adapter_set, cl_uint num_entries, + cl_device_id *devices, cl_uint *num_devices) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateFromDX9MediaSurfaceKHR)( + cl_context context, cl_mem_flags flags, + cl_dx9_media_adapter_type_khr adapter_type, void *surface_info, + cl_uint plane, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY +cl_int(CL_API_CALL *cl_api_clEnqueueAcquireDX9MediaSurfacesKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY +cl_int(CL_API_CALL *cl_api_clEnqueueReleaseDX9MediaSurfacesKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; + +/* cl_khr_d3d11_sharing */ +extern CL_API_ENTRY cl_int CL_API_CALL clGetDeviceIDsFromD3D11KHR( + cl_platform_id platform, cl_d3d11_device_source_khr d3d_device_source, + void *d3d_object, cl_d3d11_device_set_khr d3d_device_set, + cl_uint num_entries, cl_device_id *devices, cl_uint *num_devices); + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromD3D11BufferKHR(cl_context context, cl_mem_flags flags, + ID3D11Buffer *resource, cl_int *errcode_ret); + +extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromD3D11Texture2DKHR( + cl_context context, cl_mem_flags flags, ID3D11Texture2D *resource, + UINT subresource, cl_int *errcode_ret); + +extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromD3D11Texture3DKHR( + cl_context context, cl_mem_flags flags, ID3D11Texture3D *resource, + UINT subresource, cl_int *errcode_ret); + +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueAcquireD3D11ObjectsKHR( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueReleaseD3D11ObjectsKHR( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + +/* cl_khr_dx9_media_sharing */ +extern CL_API_ENTRY cl_int CL_API_CALL clGetDeviceIDsFromDX9MediaAdapterKHR( + cl_platform_id platform, cl_uint num_media_adapters, + cl_dx9_media_adapter_type_khr *media_adapter_type, void *media_adapters, + cl_dx9_media_adapter_set_khr media_adapter_set, cl_uint num_entries, + cl_device_id *devices, cl_uint *num_devices); + +extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromDX9MediaSurfaceKHR( + cl_context context, cl_mem_flags flags, + cl_dx9_media_adapter_type_khr adapter_type, void *surface_info, + cl_uint plane, cl_int *errcode_ret); + +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueAcquireDX9MediaSurfacesKHR( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + +extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueReleaseDX9MediaSurfacesKHR( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + +#else + +/* cl_khr_d3d10_sharing */ +typedef void *cl_api_clGetDeviceIDsFromD3D10KHR; +typedef void *cl_api_clCreateFromD3D10BufferKHR; +typedef void *cl_api_clCreateFromD3D10Texture2DKHR; +typedef void *cl_api_clCreateFromD3D10Texture3DKHR; +typedef void *cl_api_clEnqueueAcquireD3D10ObjectsKHR; +typedef void *cl_api_clEnqueueReleaseD3D10ObjectsKHR; + +/* cl_khr_d3d11_sharing */ +typedef void *cl_api_clGetDeviceIDsFromD3D11KHR; +typedef void *cl_api_clCreateFromD3D11BufferKHR; +typedef void *cl_api_clCreateFromD3D11Texture2DKHR; +typedef void *cl_api_clCreateFromD3D11Texture3DKHR; +typedef void *cl_api_clEnqueueAcquireD3D11ObjectsKHR; +typedef void *cl_api_clEnqueueReleaseD3D11ObjectsKHR; + +/* cl_khr_dx9_media_sharing */ +typedef void *cl_api_clCreateFromDX9MediaSurfaceKHR; +typedef void *cl_api_clEnqueueAcquireDX9MediaSurfacesKHR; +typedef void *cl_api_clEnqueueReleaseDX9MediaSurfacesKHR; +typedef void *cl_api_clGetDeviceIDsFromDX9MediaAdapterKHR; + +#endif + +/* OpenCL 1.1 */ + +#ifdef CL_VERSION_1_1 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clSetEventCallback)( + cl_event /* event */, cl_int /* command_exec_callback_type */, + void(CL_CALLBACK * /* pfn_notify */)(cl_event, cl_int, void *), + void * /* user_data */) CL_API_SUFFIX__VERSION_1_1; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateSubBuffer)( + cl_mem /* buffer */, cl_mem_flags /* flags */, + cl_buffer_create_type /* buffer_create_type */, + const void * /* buffer_create_info */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; + +typedef CL_API_ENTRY +cl_int(CL_API_CALL *cl_api_clSetMemObjectDestructorCallback)( + cl_mem /* memobj */, + void(CL_CALLBACK * /*pfn_notify*/)(cl_mem /* memobj */, + void * /*user_data*/), + void * /*user_data */) CL_API_SUFFIX__VERSION_1_1; + +typedef CL_API_ENTRY cl_event(CL_API_CALL *cl_api_clCreateUserEvent)( + cl_context /* context */, + cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clSetUserEventStatus)( + cl_event /* event */, + cl_int /* execution_status */) CL_API_SUFFIX__VERSION_1_1; + +#else + +typedef void *cl_api_clSetEventCallback; +typedef void *cl_api_clCreateSubBuffer; +typedef void *cl_api_clSetMemObjectDestructorCallback; +typedef void *cl_api_clCreateUserEvent; +typedef void *cl_api_clSetUserEventStatus; + +#endif + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clCreateSubDevicesEXT)( + cl_device_id in_device, + const cl_device_partition_property_ext *partition_properties, + cl_uint num_entries, cl_device_id *out_devices, cl_uint *num_devices); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clRetainDeviceEXT)( + cl_device_id device) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clReleaseDeviceEXT)( + cl_device_id device) CL_API_SUFFIX__VERSION_1_0; + +/* cl_khr_egl_image */ +typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateFromEGLImageKHR)( + cl_context context, CLeglDisplayKHR display, CLeglImageKHR image, + cl_mem_flags flags, const cl_egl_image_properties_khr *properties, + cl_int *errcode_ret); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueAcquireEGLObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueReleaseEGLObjectsKHR)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + +/* cl_khr_egl_event */ +typedef CL_API_ENTRY cl_event(CL_API_CALL *cl_api_clCreateEventFromEGLSyncKHR)( + cl_context context, CLeglSyncKHR sync, CLeglDisplayKHR display, + cl_int *errcode_ret); + +#ifdef CL_VERSION_2_1 + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clSetDefaultDeviceCommandQueue)( + cl_context context, cl_device_id device, + cl_command_queue command_queue) CL_API_SUFFIX__VERSION_2_1; + +typedef CL_API_ENTRY cl_program(CL_API_CALL *cl_api_clCreateProgramWithIL)( + cl_context context, const void *il, size_t length, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_2_1; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetKernelSubGroupInfo)( + cl_kernel kernel, cl_device_id device, cl_kernel_sub_group_info param_name, + size_t input_value_size, const void *input_value, size_t param_value_size, + void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_2_1; + +typedef CL_API_ENTRY cl_kernel(CL_API_CALL *cl_api_clCloneKernel)( + cl_kernel source_kernel, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_2_1; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueSVMMigrateMem)( + cl_command_queue command_queue, cl_uint num_svm_pointers, + const void **svm_pointers, const size_t *sizes, + cl_mem_migration_flags flags, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_2_1; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetDeviceAndHostTimer)( + cl_device_id device, cl_ulong *device_timestamp, + cl_ulong *host_timestamp) CL_API_SUFFIX__VERSION_2_1; + +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetHostTimer)( + cl_device_id device, cl_ulong *host_timestamp) CL_API_SUFFIX__VERSION_2_1; + +#else + +typedef void *cl_api_clSetDefaultDeviceCommandQueue; +typedef void *cl_api_clCreateProgramWithIL; +typedef void *cl_api_clGetKernelSubGroupInfo; +typedef void *cl_api_clCloneKernel; +typedef void *cl_api_clEnqueueSVMMigrateMem; +typedef void *cl_api_clGetDeviceAndHostTimer; +typedef void *cl_api_clGetHostTimer; + +#endif + +/* Vendor dispatch table struture */ + +typedef struct _cl_icd_dispatch { + /* OpenCL 1.0 */ + cl_api_clGetPlatformIDs clGetPlatformIDs; + cl_api_clGetPlatformInfo clGetPlatformInfo; + cl_api_clGetDeviceIDs clGetDeviceIDs; + cl_api_clGetDeviceInfo clGetDeviceInfo; + cl_api_clCreateContext clCreateContext; + cl_api_clCreateContextFromType clCreateContextFromType; + cl_api_clRetainContext clRetainContext; + cl_api_clReleaseContext clReleaseContext; + cl_api_clGetContextInfo clGetContextInfo; + cl_api_clCreateCommandQueue clCreateCommandQueue; + cl_api_clRetainCommandQueue clRetainCommandQueue; + cl_api_clReleaseCommandQueue clReleaseCommandQueue; + cl_api_clGetCommandQueueInfo clGetCommandQueueInfo; + cl_api_clSetCommandQueueProperty clSetCommandQueueProperty; + cl_api_clCreateBuffer clCreateBuffer; + cl_api_clCreateImage2D clCreateImage2D; + cl_api_clCreateImage3D clCreateImage3D; + cl_api_clRetainMemObject clRetainMemObject; + cl_api_clReleaseMemObject clReleaseMemObject; + cl_api_clGetSupportedImageFormats clGetSupportedImageFormats; + cl_api_clGetMemObjectInfo clGetMemObjectInfo; + cl_api_clGetImageInfo clGetImageInfo; + cl_api_clCreateSampler clCreateSampler; + cl_api_clRetainSampler clRetainSampler; + cl_api_clReleaseSampler clReleaseSampler; + cl_api_clGetSamplerInfo clGetSamplerInfo; + cl_api_clCreateProgramWithSource clCreateProgramWithSource; + cl_api_clCreateProgramWithBinary clCreateProgramWithBinary; + cl_api_clRetainProgram clRetainProgram; + cl_api_clReleaseProgram clReleaseProgram; + cl_api_clBuildProgram clBuildProgram; + cl_api_clUnloadCompiler clUnloadCompiler; + cl_api_clGetProgramInfo clGetProgramInfo; + cl_api_clGetProgramBuildInfo clGetProgramBuildInfo; + cl_api_clCreateKernel clCreateKernel; + cl_api_clCreateKernelsInProgram clCreateKernelsInProgram; + cl_api_clRetainKernel clRetainKernel; + cl_api_clReleaseKernel clReleaseKernel; + cl_api_clSetKernelArg clSetKernelArg; + cl_api_clGetKernelInfo clGetKernelInfo; + cl_api_clGetKernelWorkGroupInfo clGetKernelWorkGroupInfo; + cl_api_clWaitForEvents clWaitForEvents; + cl_api_clGetEventInfo clGetEventInfo; + cl_api_clRetainEvent clRetainEvent; + cl_api_clReleaseEvent clReleaseEvent; + cl_api_clGetEventProfilingInfo clGetEventProfilingInfo; + cl_api_clFlush clFlush; + cl_api_clFinish clFinish; + cl_api_clEnqueueReadBuffer clEnqueueReadBuffer; + cl_api_clEnqueueWriteBuffer clEnqueueWriteBuffer; + cl_api_clEnqueueCopyBuffer clEnqueueCopyBuffer; + cl_api_clEnqueueReadImage clEnqueueReadImage; + cl_api_clEnqueueWriteImage clEnqueueWriteImage; + cl_api_clEnqueueCopyImage clEnqueueCopyImage; + cl_api_clEnqueueCopyImageToBuffer clEnqueueCopyImageToBuffer; + cl_api_clEnqueueCopyBufferToImage clEnqueueCopyBufferToImage; + cl_api_clEnqueueMapBuffer clEnqueueMapBuffer; + cl_api_clEnqueueMapImage clEnqueueMapImage; + cl_api_clEnqueueUnmapMemObject clEnqueueUnmapMemObject; + cl_api_clEnqueueNDRangeKernel clEnqueueNDRangeKernel; + cl_api_clEnqueueTask clEnqueueTask; + cl_api_clEnqueueNativeKernel clEnqueueNativeKernel; + cl_api_clEnqueueMarker clEnqueueMarker; + cl_api_clEnqueueWaitForEvents clEnqueueWaitForEvents; + cl_api_clEnqueueBarrier clEnqueueBarrier; + cl_api_clGetExtensionFunctionAddress clGetExtensionFunctionAddress; + cl_api_clCreateFromGLBuffer clCreateFromGLBuffer; + cl_api_clCreateFromGLTexture2D clCreateFromGLTexture2D; + cl_api_clCreateFromGLTexture3D clCreateFromGLTexture3D; + cl_api_clCreateFromGLRenderbuffer clCreateFromGLRenderbuffer; + cl_api_clGetGLObjectInfo clGetGLObjectInfo; + cl_api_clGetGLTextureInfo clGetGLTextureInfo; + cl_api_clEnqueueAcquireGLObjects clEnqueueAcquireGLObjects; + cl_api_clEnqueueReleaseGLObjects clEnqueueReleaseGLObjects; + cl_api_clGetGLContextInfoKHR clGetGLContextInfoKHR; + + /* cl_khr_d3d10_sharing */ + cl_api_clGetDeviceIDsFromD3D10KHR clGetDeviceIDsFromD3D10KHR; + cl_api_clCreateFromD3D10BufferKHR clCreateFromD3D10BufferKHR; + cl_api_clCreateFromD3D10Texture2DKHR clCreateFromD3D10Texture2DKHR; + cl_api_clCreateFromD3D10Texture3DKHR clCreateFromD3D10Texture3DKHR; + cl_api_clEnqueueAcquireD3D10ObjectsKHR clEnqueueAcquireD3D10ObjectsKHR; + cl_api_clEnqueueReleaseD3D10ObjectsKHR clEnqueueReleaseD3D10ObjectsKHR; + + /* OpenCL 1.1 */ + cl_api_clSetEventCallback clSetEventCallback; + cl_api_clCreateSubBuffer clCreateSubBuffer; + cl_api_clSetMemObjectDestructorCallback clSetMemObjectDestructorCallback; + cl_api_clCreateUserEvent clCreateUserEvent; + cl_api_clSetUserEventStatus clSetUserEventStatus; + cl_api_clEnqueueReadBufferRect clEnqueueReadBufferRect; + cl_api_clEnqueueWriteBufferRect clEnqueueWriteBufferRect; + cl_api_clEnqueueCopyBufferRect clEnqueueCopyBufferRect; + + /* cl_ext_device_fission */ + cl_api_clCreateSubDevicesEXT clCreateSubDevicesEXT; + cl_api_clRetainDeviceEXT clRetainDeviceEXT; + cl_api_clReleaseDeviceEXT clReleaseDeviceEXT; + + /* cl_khr_gl_event */ + cl_api_clCreateEventFromGLsyncKHR clCreateEventFromGLsyncKHR; + + /* OpenCL 1.2 */ + cl_api_clCreateSubDevices clCreateSubDevices; + cl_api_clRetainDevice clRetainDevice; + cl_api_clReleaseDevice clReleaseDevice; + cl_api_clCreateImage clCreateImage; + cl_api_clCreateProgramWithBuiltInKernels clCreateProgramWithBuiltInKernels; + cl_api_clCompileProgram clCompileProgram; + cl_api_clLinkProgram clLinkProgram; + cl_api_clUnloadPlatformCompiler clUnloadPlatformCompiler; + cl_api_clGetKernelArgInfo clGetKernelArgInfo; + cl_api_clEnqueueFillBuffer clEnqueueFillBuffer; + cl_api_clEnqueueFillImage clEnqueueFillImage; + cl_api_clEnqueueMigrateMemObjects clEnqueueMigrateMemObjects; + cl_api_clEnqueueMarkerWithWaitList clEnqueueMarkerWithWaitList; + cl_api_clEnqueueBarrierWithWaitList clEnqueueBarrierWithWaitList; + cl_api_clGetExtensionFunctionAddressForPlatform + clGetExtensionFunctionAddressForPlatform; + cl_api_clCreateFromGLTexture clCreateFromGLTexture; + + /* cl_khr_d3d11_sharing */ + cl_api_clGetDeviceIDsFromD3D11KHR clGetDeviceIDsFromD3D11KHR; + cl_api_clCreateFromD3D11BufferKHR clCreateFromD3D11BufferKHR; + cl_api_clCreateFromD3D11Texture2DKHR clCreateFromD3D11Texture2DKHR; + cl_api_clCreateFromD3D11Texture3DKHR clCreateFromD3D11Texture3DKHR; + cl_api_clCreateFromDX9MediaSurfaceKHR clCreateFromDX9MediaSurfaceKHR; + cl_api_clEnqueueAcquireD3D11ObjectsKHR clEnqueueAcquireD3D11ObjectsKHR; + cl_api_clEnqueueReleaseD3D11ObjectsKHR clEnqueueReleaseD3D11ObjectsKHR; + + /* cl_khr_dx9_media_sharing */ + cl_api_clGetDeviceIDsFromDX9MediaAdapterKHR + clGetDeviceIDsFromDX9MediaAdapterKHR; + cl_api_clEnqueueAcquireDX9MediaSurfacesKHR + clEnqueueAcquireDX9MediaSurfacesKHR; + cl_api_clEnqueueReleaseDX9MediaSurfacesKHR + clEnqueueReleaseDX9MediaSurfacesKHR; + + /* cl_khr_egl_image */ + cl_api_clCreateFromEGLImageKHR clCreateFromEGLImageKHR; + cl_api_clEnqueueAcquireEGLObjectsKHR clEnqueueAcquireEGLObjectsKHR; + cl_api_clEnqueueReleaseEGLObjectsKHR clEnqueueReleaseEGLObjectsKHR; + + /* cl_khr_egl_event */ + cl_api_clCreateEventFromEGLSyncKHR clCreateEventFromEGLSyncKHR; + + /* OpenCL 2.0 */ + cl_api_clCreateCommandQueueWithProperties clCreateCommandQueueWithProperties; + cl_api_clCreatePipe clCreatePipe; + cl_api_clGetPipeInfo clGetPipeInfo; + cl_api_clSVMAlloc clSVMAlloc; + cl_api_clSVMFree clSVMFree; + cl_api_clEnqueueSVMFree clEnqueueSVMFree; + cl_api_clEnqueueSVMMemcpy clEnqueueSVMMemcpy; + cl_api_clEnqueueSVMMemFill clEnqueueSVMMemFill; + cl_api_clEnqueueSVMMap clEnqueueSVMMap; + cl_api_clEnqueueSVMUnmap clEnqueueSVMUnmap; + cl_api_clCreateSamplerWithProperties clCreateSamplerWithProperties; + cl_api_clSetKernelArgSVMPointer clSetKernelArgSVMPointer; + cl_api_clSetKernelExecInfo clSetKernelExecInfo; + + /* cl_khr_sub_groups */ + cl_api_clGetKernelSubGroupInfoKHR clGetKernelSubGroupInfoKHR; + + /* OpenCL 2.1 */ + cl_api_clCloneKernel clCloneKernel; + cl_api_clCreateProgramWithIL clCreateProgramWithIL; + cl_api_clEnqueueSVMMigrateMem clEnqueueSVMMigrateMem; + cl_api_clGetDeviceAndHostTimer clGetDeviceAndHostTimer; + cl_api_clGetHostTimer clGetHostTimer; + cl_api_clGetKernelSubGroupInfo clGetKernelSubGroupInfo; + cl_api_clSetDefaultDeviceCommandQueue clSetDefaultDeviceCommandQueue; + + /* OpenCL 2.2 */ + cl_api_clSetProgramReleaseCallback clSetProgramReleaseCallback; + cl_api_clSetProgramSpecializationConstant clSetProgramSpecializationConstant; +} cl_icd_dispatch; + +#ifdef __cplusplus +} +#endif + +#endif /* #ifndef OPENCL_CL_ICD_H */ diff --git a/opencl/khronos/headers/opencl2.2/CL/cl_platform.h b/opencl/khronos/headers/opencl2.2/CL/cl_platform.h new file mode 100644 index 0000000000..0462601c4e --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl_platform.h @@ -0,0 +1,1372 @@ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#ifndef __CL_PLATFORM_H +#define __CL_PLATFORM_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_WIN32) + #define CL_API_ENTRY + #define CL_API_CALL __stdcall + #define CL_CALLBACK __stdcall +#else + #define CL_API_ENTRY + #define CL_API_CALL + #define CL_CALLBACK +#endif + +/* + * Deprecation flags refer to the last version of the header in which the + * feature was not deprecated. + * + * E.g. VERSION_1_1_DEPRECATED means the feature is present in 1.1 without + * deprecation but is deprecated in versions later than 1.1. + */ + +#define CL_EXTENSION_WEAK_LINK +#define CL_API_SUFFIX__VERSION_1_0 +#define CL_EXT_SUFFIX__VERSION_1_0 +#define CL_API_SUFFIX__VERSION_1_1 +#define CL_EXT_SUFFIX__VERSION_1_1 +#define CL_API_SUFFIX__VERSION_1_2 +#define CL_EXT_SUFFIX__VERSION_1_2 +#define CL_API_SUFFIX__VERSION_2_0 +#define CL_EXT_SUFFIX__VERSION_2_0 +#define CL_API_SUFFIX__VERSION_2_1 +#define CL_EXT_SUFFIX__VERSION_2_1 +#define CL_API_SUFFIX__VERSION_2_2 +#define CL_EXT_SUFFIX__VERSION_2_2 + + +#ifdef __GNUC__ + #define CL_EXT_SUFFIX_DEPRECATED __attribute__((deprecated)) + #define CL_EXT_PREFIX_DEPRECATED +#elif defined(_WIN32) + #define CL_EXT_SUFFIX_DEPRECATED + #define CL_EXT_PREFIX_DEPRECATED __declspec(deprecated) +#else + #define CL_EXT_SUFFIX_DEPRECATED + #define CL_EXT_PREFIX_DEPRECATED +#endif + +#ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED +#else + #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED CL_EXT_SUFFIX_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED CL_EXT_PREFIX_DEPRECATED +#endif + +#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED +#else + #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXT_SUFFIX_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED CL_EXT_PREFIX_DEPRECATED +#endif + +#ifdef CL_USE_DEPRECATED_OPENCL_1_2_APIS + #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED +#else + #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED CL_EXT_SUFFIX_DEPRECATED + #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED CL_EXT_PREFIX_DEPRECATED + #endif + +#ifdef CL_USE_DEPRECATED_OPENCL_2_0_APIS + #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED + #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED +#else + #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED CL_EXT_SUFFIX_DEPRECATED + #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED CL_EXT_PREFIX_DEPRECATED +#endif + +#ifdef CL_USE_DEPRECATED_OPENCL_2_1_APIS + #define CL_EXT_SUFFIX__VERSION_2_1_DEPRECATED + #define CL_EXT_PREFIX__VERSION_2_1_DEPRECATED +#else + #define CL_EXT_SUFFIX__VERSION_2_1_DEPRECATED CL_EXT_SUFFIX_DEPRECATED + #define CL_EXT_PREFIX__VERSION_2_1_DEPRECATED CL_EXT_PREFIX_DEPRECATED +#endif + +#if (defined (_WIN32) && defined(_MSC_VER)) + +/* scalar types */ +typedef signed __int8 cl_char; +typedef unsigned __int8 cl_uchar; +typedef signed __int16 cl_short; +typedef unsigned __int16 cl_ushort; +typedef signed __int32 cl_int; +typedef unsigned __int32 cl_uint; +typedef signed __int64 cl_long; +typedef unsigned __int64 cl_ulong; + +typedef unsigned __int16 cl_half; +typedef float cl_float; +typedef double cl_double; + +/* Macro names and corresponding values defined by OpenCL */ +#define CL_CHAR_BIT 8 +#define CL_SCHAR_MAX 127 +#define CL_SCHAR_MIN (-127-1) +#define CL_CHAR_MAX CL_SCHAR_MAX +#define CL_CHAR_MIN CL_SCHAR_MIN +#define CL_UCHAR_MAX 255 +#define CL_SHRT_MAX 32767 +#define CL_SHRT_MIN (-32767-1) +#define CL_USHRT_MAX 65535 +#define CL_INT_MAX 2147483647 +#define CL_INT_MIN (-2147483647-1) +#define CL_UINT_MAX 0xffffffffU +#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) +#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) +#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) + +#define CL_FLT_DIG 6 +#define CL_FLT_MANT_DIG 24 +#define CL_FLT_MAX_10_EXP +38 +#define CL_FLT_MAX_EXP +128 +#define CL_FLT_MIN_10_EXP -37 +#define CL_FLT_MIN_EXP -125 +#define CL_FLT_RADIX 2 +#define CL_FLT_MAX 340282346638528859811704183484516925440.0f +#define CL_FLT_MIN 1.175494350822287507969e-38f +#define CL_FLT_EPSILON 1.1920928955078125e-7f + +#define CL_HALF_DIG 3 +#define CL_HALF_MANT_DIG 11 +#define CL_HALF_MAX_10_EXP +4 +#define CL_HALF_MAX_EXP +16 +#define CL_HALF_MIN_10_EXP -4 +#define CL_HALF_MIN_EXP -13 +#define CL_HALF_RADIX 2 +#define CL_HALF_MAX 65504.0f +#define CL_HALF_MIN 6.103515625e-05f +#define CL_HALF_EPSILON 9.765625e-04f + +#define CL_DBL_DIG 15 +#define CL_DBL_MANT_DIG 53 +#define CL_DBL_MAX_10_EXP +308 +#define CL_DBL_MAX_EXP +1024 +#define CL_DBL_MIN_10_EXP -307 +#define CL_DBL_MIN_EXP -1021 +#define CL_DBL_RADIX 2 +#define CL_DBL_MAX 1.7976931348623158e+308 +#define CL_DBL_MIN 2.225073858507201383090e-308 +#define CL_DBL_EPSILON 2.220446049250313080847e-16 + +#define CL_M_E 2.7182818284590452354 +#define CL_M_LOG2E 1.4426950408889634074 +#define CL_M_LOG10E 0.43429448190325182765 +#define CL_M_LN2 0.69314718055994530942 +#define CL_M_LN10 2.30258509299404568402 +#define CL_M_PI 3.14159265358979323846 +#define CL_M_PI_2 1.57079632679489661923 +#define CL_M_PI_4 0.78539816339744830962 +#define CL_M_1_PI 0.31830988618379067154 +#define CL_M_2_PI 0.63661977236758134308 +#define CL_M_2_SQRTPI 1.12837916709551257390 +#define CL_M_SQRT2 1.41421356237309504880 +#define CL_M_SQRT1_2 0.70710678118654752440 + +#define CL_M_E_F 2.718281828f +#define CL_M_LOG2E_F 1.442695041f +#define CL_M_LOG10E_F 0.434294482f +#define CL_M_LN2_F 0.693147181f +#define CL_M_LN10_F 2.302585093f +#define CL_M_PI_F 3.141592654f +#define CL_M_PI_2_F 1.570796327f +#define CL_M_PI_4_F 0.785398163f +#define CL_M_1_PI_F 0.318309886f +#define CL_M_2_PI_F 0.636619772f +#define CL_M_2_SQRTPI_F 1.128379167f +#define CL_M_SQRT2_F 1.414213562f +#define CL_M_SQRT1_2_F 0.707106781f + +#define CL_NAN (CL_INFINITY - CL_INFINITY) +#define CL_HUGE_VALF ((cl_float) 1e50) +#define CL_HUGE_VAL ((cl_double) 1e500) +#define CL_MAXFLOAT CL_FLT_MAX +#define CL_INFINITY CL_HUGE_VALF + +#else + +#include + +/* scalar types */ +typedef int8_t cl_char; +typedef uint8_t cl_uchar; +typedef int16_t cl_short; +typedef uint16_t cl_ushort; +typedef int32_t cl_int; +typedef uint32_t cl_uint; +typedef int64_t cl_long; +typedef uint64_t cl_ulong; + +typedef uint16_t cl_half; +typedef float cl_float; +typedef double cl_double; + +/* Macro names and corresponding values defined by OpenCL */ +#define CL_CHAR_BIT 8 +#define CL_SCHAR_MAX 127 +#define CL_SCHAR_MIN (-127-1) +#define CL_CHAR_MAX CL_SCHAR_MAX +#define CL_CHAR_MIN CL_SCHAR_MIN +#define CL_UCHAR_MAX 255 +#define CL_SHRT_MAX 32767 +#define CL_SHRT_MIN (-32767-1) +#define CL_USHRT_MAX 65535 +#define CL_INT_MAX 2147483647 +#define CL_INT_MIN (-2147483647-1) +#define CL_UINT_MAX 0xffffffffU +#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) +#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) +#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) + +#define CL_FLT_DIG 6 +#define CL_FLT_MANT_DIG 24 +#define CL_FLT_MAX_10_EXP +38 +#define CL_FLT_MAX_EXP +128 +#define CL_FLT_MIN_10_EXP -37 +#define CL_FLT_MIN_EXP -125 +#define CL_FLT_RADIX 2 +#define CL_FLT_MAX 340282346638528859811704183484516925440.0f +#define CL_FLT_MIN 1.175494350822287507969e-38f +#define CL_FLT_EPSILON 1.1920928955078125e-7f + +#define CL_HALF_DIG 3 +#define CL_HALF_MANT_DIG 11 +#define CL_HALF_MAX_10_EXP +4 +#define CL_HALF_MAX_EXP +16 +#define CL_HALF_MIN_10_EXP -4 +#define CL_HALF_MIN_EXP -13 +#define CL_HALF_RADIX 2 +#define CL_HALF_MAX 65504.0f +#define CL_HALF_MIN 6.103515625e-05f +#define CL_HALF_EPSILON 9.765625e-04f + +#define CL_DBL_DIG 15 +#define CL_DBL_MANT_DIG 53 +#define CL_DBL_MAX_10_EXP +308 +#define CL_DBL_MAX_EXP +1024 +#define CL_DBL_MIN_10_EXP -307 +#define CL_DBL_MIN_EXP -1021 +#define CL_DBL_RADIX 2 +#define CL_DBL_MAX 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0 +#define CL_DBL_MIN 2.225073858507201383090e-308 +#define CL_DBL_EPSILON 2.220446049250313080847e-16 + +#define CL_M_E 2.7182818284590452354 +#define CL_M_LOG2E 1.4426950408889634074 +#define CL_M_LOG10E 0.43429448190325182765 +#define CL_M_LN2 0.69314718055994530942 +#define CL_M_LN10 2.30258509299404568402 +#define CL_M_PI 3.14159265358979323846 +#define CL_M_PI_2 1.57079632679489661923 +#define CL_M_PI_4 0.78539816339744830962 +#define CL_M_1_PI 0.31830988618379067154 +#define CL_M_2_PI 0.63661977236758134308 +#define CL_M_2_SQRTPI 1.12837916709551257390 +#define CL_M_SQRT2 1.41421356237309504880 +#define CL_M_SQRT1_2 0.70710678118654752440 + +#define CL_M_E_F 2.718281828f +#define CL_M_LOG2E_F 1.442695041f +#define CL_M_LOG10E_F 0.434294482f +#define CL_M_LN2_F 0.693147181f +#define CL_M_LN10_F 2.302585093f +#define CL_M_PI_F 3.141592654f +#define CL_M_PI_2_F 1.570796327f +#define CL_M_PI_4_F 0.785398163f +#define CL_M_1_PI_F 0.318309886f +#define CL_M_2_PI_F 0.636619772f +#define CL_M_2_SQRTPI_F 1.128379167f +#define CL_M_SQRT2_F 1.414213562f +#define CL_M_SQRT1_2_F 0.707106781f + +#if defined( __GNUC__ ) + #define CL_HUGE_VALF __builtin_huge_valf() + #define CL_HUGE_VAL __builtin_huge_val() + #define CL_NAN __builtin_nanf( "" ) +#else + #define CL_HUGE_VALF ((cl_float) 1e50) + #define CL_HUGE_VAL ((cl_double) 1e500) + float nanf( const char * ); + #define CL_NAN nanf( "" ) +#endif +#define CL_MAXFLOAT CL_FLT_MAX +#define CL_INFINITY CL_HUGE_VALF + +#endif + +#include + +/* Mirror types to GL types. Mirror types allow us to avoid deciding which 87s to load based on whether we are using GL or GLES here. */ +typedef unsigned int cl_GLuint; +typedef int cl_GLint; +typedef unsigned int cl_GLenum; + +/* + * Vector types + * + * Note: OpenCL requires that all types be naturally aligned. + * This means that vector types must be naturally aligned. + * For example, a vector of four floats must be aligned to + * a 16 byte boundary (calculated as 4 * the natural 4-byte + * alignment of the float). The alignment qualifiers here + * will only function properly if your compiler supports them + * and if you don't actively work to defeat them. For example, + * in order for a cl_float4 to be 16 byte aligned in a struct, + * the start of the struct must itself be 16-byte aligned. + * + * Maintaining proper alignment is the user's responsibility. + */ + +/* Define basic vector types */ +#if defined( __VEC__ ) + #include /* may be omitted depending on compiler. AltiVec spec provides no way to detect whether the header is required. */ + typedef __vector unsigned char __cl_uchar16; + typedef __vector signed char __cl_char16; + typedef __vector unsigned short __cl_ushort8; + typedef __vector signed short __cl_short8; + typedef __vector unsigned int __cl_uint4; + typedef __vector signed int __cl_int4; + typedef __vector float __cl_float4; + #define __CL_UCHAR16__ 1 + #define __CL_CHAR16__ 1 + #define __CL_USHORT8__ 1 + #define __CL_SHORT8__ 1 + #define __CL_UINT4__ 1 + #define __CL_INT4__ 1 + #define __CL_FLOAT4__ 1 +#endif + +#if defined( __SSE__ ) + #if defined( __MINGW64__ ) + #include + #else + #include + #endif + #if defined( __GNUC__ ) + typedef float __cl_float4 __attribute__((vector_size(16))); + #else + typedef __m128 __cl_float4; + #endif + #define __CL_FLOAT4__ 1 +#endif + +#if defined( __SSE2__ ) + #if defined( __MINGW64__ ) + #include + #else + #include + #endif + #if defined( __GNUC__ ) + typedef cl_uchar __cl_uchar16 __attribute__((vector_size(16))); + typedef cl_char __cl_char16 __attribute__((vector_size(16))); + typedef cl_ushort __cl_ushort8 __attribute__((vector_size(16))); + typedef cl_short __cl_short8 __attribute__((vector_size(16))); + typedef cl_uint __cl_uint4 __attribute__((vector_size(16))); + typedef cl_int __cl_int4 __attribute__((vector_size(16))); + typedef cl_ulong __cl_ulong2 __attribute__((vector_size(16))); + typedef cl_long __cl_long2 __attribute__((vector_size(16))); + typedef cl_double __cl_double2 __attribute__((vector_size(16))); + #else + typedef __m128i __cl_uchar16; + typedef __m128i __cl_char16; + typedef __m128i __cl_ushort8; + typedef __m128i __cl_short8; + typedef __m128i __cl_uint4; + typedef __m128i __cl_int4; + typedef __m128i __cl_ulong2; + typedef __m128i __cl_long2; + typedef __m128d __cl_double2; + #endif + #define __CL_UCHAR16__ 1 + #define __CL_CHAR16__ 1 + #define __CL_USHORT8__ 1 + #define __CL_SHORT8__ 1 + #define __CL_INT4__ 1 + #define __CL_UINT4__ 1 + #define __CL_ULONG2__ 1 + #define __CL_LONG2__ 1 + #define __CL_DOUBLE2__ 1 +#endif + +#if defined( __MMX__ ) + #include + #if defined( __GNUC__ ) + typedef cl_uchar __cl_uchar8 __attribute__((vector_size(8))); + typedef cl_char __cl_char8 __attribute__((vector_size(8))); + typedef cl_ushort __cl_ushort4 __attribute__((vector_size(8))); + typedef cl_short __cl_short4 __attribute__((vector_size(8))); + typedef cl_uint __cl_uint2 __attribute__((vector_size(8))); + typedef cl_int __cl_int2 __attribute__((vector_size(8))); + typedef cl_ulong __cl_ulong1 __attribute__((vector_size(8))); + typedef cl_long __cl_long1 __attribute__((vector_size(8))); + typedef cl_float __cl_float2 __attribute__((vector_size(8))); + #else + typedef __m64 __cl_uchar8; + typedef __m64 __cl_char8; + typedef __m64 __cl_ushort4; + typedef __m64 __cl_short4; + typedef __m64 __cl_uint2; + typedef __m64 __cl_int2; + typedef __m64 __cl_ulong1; + typedef __m64 __cl_long1; + typedef __m64 __cl_float2; + #endif + #define __CL_UCHAR8__ 1 + #define __CL_CHAR8__ 1 + #define __CL_USHORT4__ 1 + #define __CL_SHORT4__ 1 + #define __CL_INT2__ 1 + #define __CL_UINT2__ 1 + #define __CL_ULONG1__ 1 + #define __CL_LONG1__ 1 + #define __CL_FLOAT2__ 1 +#endif + +#if defined( __AVX__ ) + #if defined( __MINGW64__ ) + #include + #else + #include + #endif + #if defined( __GNUC__ ) + typedef cl_float __cl_float8 __attribute__((vector_size(32))); + typedef cl_double __cl_double4 __attribute__((vector_size(32))); + #else + typedef __m256 __cl_float8; + typedef __m256d __cl_double4; + #endif + #define __CL_FLOAT8__ 1 + #define __CL_DOUBLE4__ 1 +#endif + +/* Define capabilities for anonymous struct members. */ +#if !defined(__cplusplus) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#define __CL_HAS_ANON_STRUCT__ 1 +#define __CL_ANON_STRUCT__ +#elif defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) +#define __CL_HAS_ANON_STRUCT__ 1 +#define __CL_ANON_STRUCT__ __extension__ +#elif defined( _WIN32) && defined(_MSC_VER) + #if _MSC_VER >= 1500 + /* Microsoft Developer Studio 2008 supports anonymous structs, but + * complains by default. */ + #define __CL_HAS_ANON_STRUCT__ 1 + #define __CL_ANON_STRUCT__ + /* Disable warning C4201: nonstandard extension used : nameless + * struct/union */ + #pragma warning( push ) + #pragma warning( disable : 4201 ) + #endif +#else +#define __CL_HAS_ANON_STRUCT__ 0 +#define __CL_ANON_STRUCT__ +#endif + +/* Define alignment keys */ +#if defined( __GNUC__ ) + #define CL_ALIGNED(_x) __attribute__ ((aligned(_x))) +#elif defined( _WIN32) && (_MSC_VER) + /* Alignment keys neutered on windows because MSVC can't swallow function arguments with alignment requirements */ + /* http://msdn.microsoft.com/en-us/library/373ak2y1%28VS.71%29.aspx */ + /* #include */ + /* #define CL_ALIGNED(_x) _CRT_ALIGN(_x) */ + #define CL_ALIGNED(_x) +#else + #warning Need to implement some method to align data here + #define CL_ALIGNED(_x) +#endif + +/* Indicate whether .xyzw, .s0123 and .hi.lo are supported */ +#if __CL_HAS_ANON_STRUCT__ + /* .xyzw and .s0123...{f|F} are supported */ + #define CL_HAS_NAMED_VECTOR_FIELDS 1 + /* .hi and .lo are supported */ + #define CL_HAS_HI_LO_VECTOR_FIELDS 1 +#endif + +/* Define cl_vector types */ + +/* ---- cl_charn ---- */ +typedef union +{ + cl_char CL_ALIGNED(2) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_char lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2; +#endif +}cl_char2; + +typedef union +{ + cl_char CL_ALIGNED(4) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_char2 lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2[2]; +#endif +#if defined( __CL_CHAR4__) + __cl_char4 v4; +#endif +}cl_char4; + +/* cl_char3 is identical in size, alignment and behavior to cl_char4. See section 6.1.5. */ +typedef cl_char4 cl_char3; + +typedef union +{ + cl_char CL_ALIGNED(8) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_char4 lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2[4]; +#endif +#if defined( __CL_CHAR4__) + __cl_char4 v4[2]; +#endif +#if defined( __CL_CHAR8__ ) + __cl_char8 v8; +#endif +}cl_char8; + +typedef union +{ + cl_char CL_ALIGNED(16) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_char8 lo, hi; }; +#endif +#if defined( __CL_CHAR2__) + __cl_char2 v2[8]; +#endif +#if defined( __CL_CHAR4__) + __cl_char4 v4[4]; +#endif +#if defined( __CL_CHAR8__ ) + __cl_char8 v8[2]; +#endif +#if defined( __CL_CHAR16__ ) + __cl_char16 v16; +#endif +}cl_char16; + + +/* ---- cl_ucharn ---- */ +typedef union +{ + cl_uchar CL_ALIGNED(2) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_uchar lo, hi; }; +#endif +#if defined( __cl_uchar2__) + __cl_uchar2 v2; +#endif +}cl_uchar2; + +typedef union +{ + cl_uchar CL_ALIGNED(4) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_uchar2 lo, hi; }; +#endif +#if defined( __CL_UCHAR2__) + __cl_uchar2 v2[2]; +#endif +#if defined( __CL_UCHAR4__) + __cl_uchar4 v4; +#endif +}cl_uchar4; + +/* cl_uchar3 is identical in size, alignment and behavior to cl_uchar4. See section 6.1.5. */ +typedef cl_uchar4 cl_uchar3; + +typedef union +{ + cl_uchar CL_ALIGNED(8) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_uchar4 lo, hi; }; +#endif +#if defined( __CL_UCHAR2__) + __cl_uchar2 v2[4]; +#endif +#if defined( __CL_UCHAR4__) + __cl_uchar4 v4[2]; +#endif +#if defined( __CL_UCHAR8__ ) + __cl_uchar8 v8; +#endif +}cl_uchar8; + +typedef union +{ + cl_uchar CL_ALIGNED(16) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_uchar8 lo, hi; }; +#endif +#if defined( __CL_UCHAR2__) + __cl_uchar2 v2[8]; +#endif +#if defined( __CL_UCHAR4__) + __cl_uchar4 v4[4]; +#endif +#if defined( __CL_UCHAR8__ ) + __cl_uchar8 v8[2]; +#endif +#if defined( __CL_UCHAR16__ ) + __cl_uchar16 v16; +#endif +}cl_uchar16; + + +/* ---- cl_shortn ---- */ +typedef union +{ + cl_short CL_ALIGNED(4) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_short lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2; +#endif +}cl_short2; + +typedef union +{ + cl_short CL_ALIGNED(8) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_short2 lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2[2]; +#endif +#if defined( __CL_SHORT4__) + __cl_short4 v4; +#endif +}cl_short4; + +/* cl_short3 is identical in size, alignment and behavior to cl_short4. See section 6.1.5. */ +typedef cl_short4 cl_short3; + +typedef union +{ + cl_short CL_ALIGNED(16) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_short4 lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2[4]; +#endif +#if defined( __CL_SHORT4__) + __cl_short4 v4[2]; +#endif +#if defined( __CL_SHORT8__ ) + __cl_short8 v8; +#endif +}cl_short8; + +typedef union +{ + cl_short CL_ALIGNED(32) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_short8 lo, hi; }; +#endif +#if defined( __CL_SHORT2__) + __cl_short2 v2[8]; +#endif +#if defined( __CL_SHORT4__) + __cl_short4 v4[4]; +#endif +#if defined( __CL_SHORT8__ ) + __cl_short8 v8[2]; +#endif +#if defined( __CL_SHORT16__ ) + __cl_short16 v16; +#endif +}cl_short16; + + +/* ---- cl_ushortn ---- */ +typedef union +{ + cl_ushort CL_ALIGNED(4) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_ushort lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2; +#endif +}cl_ushort2; + +typedef union +{ + cl_ushort CL_ALIGNED(8) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_ushort2 lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2[2]; +#endif +#if defined( __CL_USHORT4__) + __cl_ushort4 v4; +#endif +}cl_ushort4; + +/* cl_ushort3 is identical in size, alignment and behavior to cl_ushort4. See section 6.1.5. */ +typedef cl_ushort4 cl_ushort3; + +typedef union +{ + cl_ushort CL_ALIGNED(16) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_ushort4 lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2[4]; +#endif +#if defined( __CL_USHORT4__) + __cl_ushort4 v4[2]; +#endif +#if defined( __CL_USHORT8__ ) + __cl_ushort8 v8; +#endif +}cl_ushort8; + +typedef union +{ + cl_ushort CL_ALIGNED(32) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_ushort8 lo, hi; }; +#endif +#if defined( __CL_USHORT2__) + __cl_ushort2 v2[8]; +#endif +#if defined( __CL_USHORT4__) + __cl_ushort4 v4[4]; +#endif +#if defined( __CL_USHORT8__ ) + __cl_ushort8 v8[2]; +#endif +#if defined( __CL_USHORT16__ ) + __cl_ushort16 v16; +#endif +}cl_ushort16; + + +/* ---- cl_halfn ---- */ +typedef union +{ + cl_half CL_ALIGNED(4) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_half lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2; +#endif +}cl_half2; + +typedef union +{ + cl_half CL_ALIGNED(8) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_half2 lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2[2]; +#endif +#if defined( __CL_HALF4__) + __cl_half4 v4; +#endif +}cl_half4; + +/* cl_half3 is identical in size, alignment and behavior to cl_half4. See section 6.1.5. */ +typedef cl_half4 cl_half3; + +typedef union +{ + cl_half CL_ALIGNED(16) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_half4 lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2[4]; +#endif +#if defined( __CL_HALF4__) + __cl_half4 v4[2]; +#endif +#if defined( __CL_HALF8__ ) + __cl_half8 v8; +#endif +}cl_half8; + +typedef union +{ + cl_half CL_ALIGNED(32) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_half8 lo, hi; }; +#endif +#if defined( __CL_HALF2__) + __cl_half2 v2[8]; +#endif +#if defined( __CL_HALF4__) + __cl_half4 v4[4]; +#endif +#if defined( __CL_HALF8__ ) + __cl_half8 v8[2]; +#endif +#if defined( __CL_HALF16__ ) + __cl_half16 v16; +#endif +}cl_half16; + +/* ---- cl_intn ---- */ +typedef union +{ + cl_int CL_ALIGNED(8) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_int lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2; +#endif +}cl_int2; + +typedef union +{ + cl_int CL_ALIGNED(16) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_int2 lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2[2]; +#endif +#if defined( __CL_INT4__) + __cl_int4 v4; +#endif +}cl_int4; + +/* cl_int3 is identical in size, alignment and behavior to cl_int4. See section 6.1.5. */ +typedef cl_int4 cl_int3; + +typedef union +{ + cl_int CL_ALIGNED(32) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_int4 lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2[4]; +#endif +#if defined( __CL_INT4__) + __cl_int4 v4[2]; +#endif +#if defined( __CL_INT8__ ) + __cl_int8 v8; +#endif +}cl_int8; + +typedef union +{ + cl_int CL_ALIGNED(64) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_int8 lo, hi; }; +#endif +#if defined( __CL_INT2__) + __cl_int2 v2[8]; +#endif +#if defined( __CL_INT4__) + __cl_int4 v4[4]; +#endif +#if defined( __CL_INT8__ ) + __cl_int8 v8[2]; +#endif +#if defined( __CL_INT16__ ) + __cl_int16 v16; +#endif +}cl_int16; + + +/* ---- cl_uintn ---- */ +typedef union +{ + cl_uint CL_ALIGNED(8) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_uint lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2; +#endif +}cl_uint2; + +typedef union +{ + cl_uint CL_ALIGNED(16) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_uint2 lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2[2]; +#endif +#if defined( __CL_UINT4__) + __cl_uint4 v4; +#endif +}cl_uint4; + +/* cl_uint3 is identical in size, alignment and behavior to cl_uint4. See section 6.1.5. */ +typedef cl_uint4 cl_uint3; + +typedef union +{ + cl_uint CL_ALIGNED(32) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_uint4 lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2[4]; +#endif +#if defined( __CL_UINT4__) + __cl_uint4 v4[2]; +#endif +#if defined( __CL_UINT8__ ) + __cl_uint8 v8; +#endif +}cl_uint8; + +typedef union +{ + cl_uint CL_ALIGNED(64) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_uint8 lo, hi; }; +#endif +#if defined( __CL_UINT2__) + __cl_uint2 v2[8]; +#endif +#if defined( __CL_UINT4__) + __cl_uint4 v4[4]; +#endif +#if defined( __CL_UINT8__ ) + __cl_uint8 v8[2]; +#endif +#if defined( __CL_UINT16__ ) + __cl_uint16 v16; +#endif +}cl_uint16; + +/* ---- cl_longn ---- */ +typedef union +{ + cl_long CL_ALIGNED(16) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_long lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2; +#endif +}cl_long2; + +typedef union +{ + cl_long CL_ALIGNED(32) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_long2 lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2[2]; +#endif +#if defined( __CL_LONG4__) + __cl_long4 v4; +#endif +}cl_long4; + +/* cl_long3 is identical in size, alignment and behavior to cl_long4. See section 6.1.5. */ +typedef cl_long4 cl_long3; + +typedef union +{ + cl_long CL_ALIGNED(64) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_long4 lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2[4]; +#endif +#if defined( __CL_LONG4__) + __cl_long4 v4[2]; +#endif +#if defined( __CL_LONG8__ ) + __cl_long8 v8; +#endif +}cl_long8; + +typedef union +{ + cl_long CL_ALIGNED(128) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_long8 lo, hi; }; +#endif +#if defined( __CL_LONG2__) + __cl_long2 v2[8]; +#endif +#if defined( __CL_LONG4__) + __cl_long4 v4[4]; +#endif +#if defined( __CL_LONG8__ ) + __cl_long8 v8[2]; +#endif +#if defined( __CL_LONG16__ ) + __cl_long16 v16; +#endif +}cl_long16; + + +/* ---- cl_ulongn ---- */ +typedef union +{ + cl_ulong CL_ALIGNED(16) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_ulong lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2; +#endif +}cl_ulong2; + +typedef union +{ + cl_ulong CL_ALIGNED(32) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_ulong2 lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2[2]; +#endif +#if defined( __CL_ULONG4__) + __cl_ulong4 v4; +#endif +}cl_ulong4; + +/* cl_ulong3 is identical in size, alignment and behavior to cl_ulong4. See section 6.1.5. */ +typedef cl_ulong4 cl_ulong3; + +typedef union +{ + cl_ulong CL_ALIGNED(64) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_ulong4 lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2[4]; +#endif +#if defined( __CL_ULONG4__) + __cl_ulong4 v4[2]; +#endif +#if defined( __CL_ULONG8__ ) + __cl_ulong8 v8; +#endif +}cl_ulong8; + +typedef union +{ + cl_ulong CL_ALIGNED(128) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_ulong8 lo, hi; }; +#endif +#if defined( __CL_ULONG2__) + __cl_ulong2 v2[8]; +#endif +#if defined( __CL_ULONG4__) + __cl_ulong4 v4[4]; +#endif +#if defined( __CL_ULONG8__ ) + __cl_ulong8 v8[2]; +#endif +#if defined( __CL_ULONG16__ ) + __cl_ulong16 v16; +#endif +}cl_ulong16; + + +/* --- cl_floatn ---- */ + +typedef union +{ + cl_float CL_ALIGNED(8) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_float lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2; +#endif +}cl_float2; + +typedef union +{ + cl_float CL_ALIGNED(16) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_float2 lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2[2]; +#endif +#if defined( __CL_FLOAT4__) + __cl_float4 v4; +#endif +}cl_float4; + +/* cl_float3 is identical in size, alignment and behavior to cl_float4. See section 6.1.5. */ +typedef cl_float4 cl_float3; + +typedef union +{ + cl_float CL_ALIGNED(32) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_float4 lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2[4]; +#endif +#if defined( __CL_FLOAT4__) + __cl_float4 v4[2]; +#endif +#if defined( __CL_FLOAT8__ ) + __cl_float8 v8; +#endif +}cl_float8; + +typedef union +{ + cl_float CL_ALIGNED(64) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_float8 lo, hi; }; +#endif +#if defined( __CL_FLOAT2__) + __cl_float2 v2[8]; +#endif +#if defined( __CL_FLOAT4__) + __cl_float4 v4[4]; +#endif +#if defined( __CL_FLOAT8__ ) + __cl_float8 v8[2]; +#endif +#if defined( __CL_FLOAT16__ ) + __cl_float16 v16; +#endif +}cl_float16; + +/* --- cl_doublen ---- */ + +typedef union +{ + cl_double CL_ALIGNED(16) s[2]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1; }; + __CL_ANON_STRUCT__ struct{ cl_double lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2; +#endif +}cl_double2; + +typedef union +{ + cl_double CL_ALIGNED(32) s[4]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct{ cl_double2 lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2[2]; +#endif +#if defined( __CL_DOUBLE4__) + __cl_double4 v4; +#endif +}cl_double4; + +/* cl_double3 is identical in size, alignment and behavior to cl_double4. See section 6.1.5. */ +typedef cl_double4 cl_double3; + +typedef union +{ + cl_double CL_ALIGNED(64) s[8]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct{ cl_double4 lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2[4]; +#endif +#if defined( __CL_DOUBLE4__) + __cl_double4 v4[2]; +#endif +#if defined( __CL_DOUBLE8__ ) + __cl_double8 v8; +#endif +}cl_double8; + +typedef union +{ + cl_double CL_ALIGNED(128) s[16]; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct{ cl_double8 lo, hi; }; +#endif +#if defined( __CL_DOUBLE2__) + __cl_double2 v2[8]; +#endif +#if defined( __CL_DOUBLE4__) + __cl_double4 v4[4]; +#endif +#if defined( __CL_DOUBLE8__ ) + __cl_double8 v8[2]; +#endif +#if defined( __CL_DOUBLE16__ ) + __cl_double16 v16; +#endif +}cl_double16; + +/* Macro to facilitate debugging + * Usage: + * Place CL_PROGRAM_STRING_DEBUG_INFO on the line before the first line of your source. + * The first line ends with: CL_PROGRAM_STRING_DEBUG_INFO \" + * Each line thereafter of OpenCL C source must end with: \n\ + * The last line ends in "; + * + * Example: + * + * const char *my_program = CL_PROGRAM_STRING_DEBUG_INFO "\ + * kernel void foo( int a, float * b ) \n\ + * { \n\ + * // my comment \n\ + * *b[ get_global_id(0)] = a; \n\ + * } \n\ + * "; + * + * This should correctly set up the line, (column) and file information for your source + * string so you can do source level debugging. + */ +#define __CL_STRINGIFY( _x ) # _x +#define _CL_STRINGIFY( _x ) __CL_STRINGIFY( _x ) +#define CL_PROGRAM_STRING_DEBUG_INFO "#line " _CL_STRINGIFY(__LINE__) " \"" __FILE__ "\" \n\n" + +#ifdef __cplusplus +} +#endif + +#undef __CL_HAS_ANON_STRUCT__ +#undef __CL_ANON_STRUCT__ +#if defined( _WIN32) && defined(_MSC_VER) + #if _MSC_VER >=1500 + #pragma warning( pop ) + #endif +#endif + +#endif /* __CL_PLATFORM_H */ diff --git a/opencl/khronos/headers/opencl2.2/CL/cl_va_api_media_sharing_intel.h b/opencl/khronos/headers/opencl2.2/CL/cl_va_api_media_sharing_intel.h new file mode 100644 index 0000000000..0e7cd4d6f8 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl_va_api_media_sharing_intel.h @@ -0,0 +1,160 @@ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +/*****************************************************************************\ + +Copyright (c) 2013-2019 Intel Corporation All Rights Reserved. + +THESE MATERIALS ARE PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THESE +MATERIALS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +File Name: cl_va_api_media_sharing_intel.h + +Abstract: + +Notes: + +\*****************************************************************************/ + + +#ifndef __OPENCL_CL_VA_API_MEDIA_SHARING_INTEL_H +#define __OPENCL_CL_VA_API_MEDIA_SHARING_INTEL_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************** +* cl_intel_va_api_media_sharing extension * +*******************************************/ + +#define cl_intel_va_api_media_sharing 1 + +/* error codes */ +#define CL_INVALID_VA_API_MEDIA_ADAPTER_INTEL -1098 +#define CL_INVALID_VA_API_MEDIA_SURFACE_INTEL -1099 +#define CL_VA_API_MEDIA_SURFACE_ALREADY_ACQUIRED_INTEL -1100 +#define CL_VA_API_MEDIA_SURFACE_NOT_ACQUIRED_INTEL -1101 + +/* cl_va_api_device_source_intel */ +#define CL_VA_API_DISPLAY_INTEL 0x4094 + +/* cl_va_api_device_set_intel */ +#define CL_PREFERRED_DEVICES_FOR_VA_API_INTEL 0x4095 +#define CL_ALL_DEVICES_FOR_VA_API_INTEL 0x4096 + +/* cl_context_info */ +#define CL_CONTEXT_VA_API_DISPLAY_INTEL 0x4097 + +/* cl_mem_info */ +#define CL_MEM_VA_API_MEDIA_SURFACE_INTEL 0x4098 + +/* cl_image_info */ +#define CL_IMAGE_VA_API_PLANE_INTEL 0x4099 + +/* cl_command_type */ +#define CL_COMMAND_ACQUIRE_VA_API_MEDIA_SURFACES_INTEL 0x409A +#define CL_COMMAND_RELEASE_VA_API_MEDIA_SURFACES_INTEL 0x409B + +typedef cl_uint cl_va_api_device_source_intel; +typedef cl_uint cl_va_api_device_set_intel; + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceIDsFromVA_APIMediaAdapterINTEL( + cl_platform_id platform, + cl_va_api_device_source_intel media_adapter_type, + void* media_adapter, + cl_va_api_device_set_intel media_adapter_set, + cl_uint num_entries, + cl_device_id* devices, + cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL * clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn)( + cl_platform_id platform, + cl_va_api_device_source_intel media_adapter_type, + void* media_adapter, + cl_va_api_device_set_intel media_adapter_set, + cl_uint num_entries, + cl_device_id* devices, + cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromVA_APIMediaSurfaceINTEL( + cl_context context, + cl_mem_flags flags, + VASurfaceID* surface, + cl_uint plane, + cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_mem (CL_API_CALL * clCreateFromVA_APIMediaSurfaceINTEL_fn)( + cl_context context, + cl_mem_flags flags, + VASurfaceID* surface, + cl_uint plane, + cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireVA_APIMediaSurfacesINTEL( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireVA_APIMediaSurfacesINTEL_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseVA_APIMediaSurfacesINTEL( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn)( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem* mem_objects, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_CL_VA_API_MEDIA_SHARING_INTEL_H */ + diff --git a/opencl/khronos/headers/opencl2.2/CL/cl_version.h b/opencl/khronos/headers/opencl2.2/CL/cl_version.h new file mode 100644 index 0000000000..c3576f6767 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/cl_version.h @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2008-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#ifndef __CL_VERSION_H +#define __CL_VERSION_H + +/* Detect which version to target */ +#if !defined(CL_TARGET_OPENCL_VERSION) +#pragma message("cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 220 (OpenCL 2.2)") +#define CL_TARGET_OPENCL_VERSION 220 +#endif +#if CL_TARGET_OPENCL_VERSION != 100 && \ + CL_TARGET_OPENCL_VERSION != 110 && \ + CL_TARGET_OPENCL_VERSION != 120 && \ + CL_TARGET_OPENCL_VERSION != 200 && \ + CL_TARGET_OPENCL_VERSION != 210 && \ + CL_TARGET_OPENCL_VERSION != 220 +#pragma message("cl_version: CL_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220). Defaulting to 220 (OpenCL 2.2)") +#undef CL_TARGET_OPENCL_VERSION +#define CL_TARGET_OPENCL_VERSION 220 +#endif + + +/* OpenCL Version */ +#if CL_TARGET_OPENCL_VERSION >= 220 && !defined(CL_VERSION_2_2) +#define CL_VERSION_2_2 1 +#endif +#if CL_TARGET_OPENCL_VERSION >= 210 && !defined(CL_VERSION_2_1) +#define CL_VERSION_2_1 1 +#endif +#if CL_TARGET_OPENCL_VERSION >= 200 && !defined(CL_VERSION_2_0) +#define CL_VERSION_2_0 1 +#endif +#if CL_TARGET_OPENCL_VERSION >= 120 && !defined(CL_VERSION_1_2) +#define CL_VERSION_1_2 1 +#endif +#if CL_TARGET_OPENCL_VERSION >= 110 && !defined(CL_VERSION_1_1) +#define CL_VERSION_1_1 1 +#endif +#if CL_TARGET_OPENCL_VERSION >= 100 && !defined(CL_VERSION_1_0) +#define CL_VERSION_1_0 1 +#endif + +/* Allow deprecated APIs for older OpenCL versions. */ +#if CL_TARGET_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS) +#define CL_USE_DEPRECATED_OPENCL_2_1_APIS +#endif +#if CL_TARGET_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS) +#define CL_USE_DEPRECATED_OPENCL_2_0_APIS +#endif +#if CL_TARGET_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) +#define CL_USE_DEPRECATED_OPENCL_1_2_APIS +#endif +#if CL_TARGET_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) +#define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#endif +#if CL_TARGET_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS) +#define CL_USE_DEPRECATED_OPENCL_1_0_APIS +#endif + +#endif /* __CL_VERSION_H */ diff --git a/opencl/khronos/headers/opencl2.2/CL/opencl.h b/opencl/khronos/headers/opencl2.2/CL/opencl.h new file mode 100644 index 0000000000..abff9161f4 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CL/opencl.h @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2008-2021 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ + +#ifndef __OPENCL_H +#define __OPENCL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +#ifdef __cplusplus +} +#endif + +#endif /* __OPENCL_H */ diff --git a/opencl/khronos/headers/opencl2.2/CODE_OF_CONDUCT.md b/opencl/khronos/headers/opencl2.2/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000..a11610bd30 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/CODE_OF_CONDUCT.md @@ -0,0 +1 @@ +A reminder that this issue tracker is managed by the Khronos Group. Interactions here should follow the Khronos Code of Conduct (https://www.khronos.org/developers/code-of-conduct), which prohibits aggressive or derogatory language. Please keep the discussion friendly and civil. diff --git a/opencl/khronos/headers/opencl2.2/LICENSE b/opencl/khronos/headers/opencl2.2/LICENSE new file mode 100644 index 0000000000..020ce65fca --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) 2008-2015 The Khronos Group Inc. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and/or associated documentation files (the +"Materials"), to deal in the Materials without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Materials, and to +permit persons to whom the Materials are furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Materials. + +MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS +KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS +SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT + https://www.khronos.org/registry/ + +THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. diff --git a/opencl/khronos/headers/opencl2.2/LICENSE.txt b/opencl/khronos/headers/opencl2.2/LICENSE.txt new file mode 100644 index 0000000000..7afedf6cf9 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/LICENSE.txt @@ -0,0 +1,35 @@ +Copyright (c) 2016 The Khronos Group Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software source and associated documentation files (the "Materials"), +to deal in the Materials without restriction, including without limitation +the rights to use, copy, modify, compile, merge, publish, distribute, +sublicense, and/or sell copies of the Materials, and to permit persons to +whom the Materials are furnished to do so, subject the following terms and +conditions: + +All modifications to the Materials used to create a binary that is +distributed to third parties shall be provided to Khronos with an +unrestricted license to use for the purposes of implementing bug fixes and +enhancements to the Materials; + +If the binary is used as part of an OpenCL(TM) implementation, whether binary +is distributed together with or separately to that implementation, then +recipient must become an OpenCL Adopter and follow the published OpenCL +conformance process for that implementation, details at: +http://www.khronos.org/conformance/; + +The above copyright notice, the OpenCL trademark license, and this permission +notice shall be included in all copies or substantial portions of the +Materials. + +THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN +THE MATERIALS. + +OpenCL is a trademark of Apple Inc. used under license by Khronos. + diff --git a/opencl/khronos/headers/opencl2.2/README.md b/opencl/khronos/headers/opencl2.2/README.md new file mode 100644 index 0000000000..757e56e152 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/README.md @@ -0,0 +1,50 @@ +# OpenCLTM API Headers + +This repository contains C language headers for the OpenCL API. + +The authoritative public repository for these headers is located at: + +https://github.com/KhronosGroup/OpenCL-Headers + +Issues, proposed fixes for issues, and other suggested changes should be +created using Github. + +## Branch Structure + +The OpenCL API headers in this repository are Unified headers and are designed +to work with all released OpenCL versions. This differs from previous OpenCL +API headers, where version-specific API headers either existed in separate +branches, or in separate folders in a branch. + +## Compiling for a Specific OpenCL Version + +By default, the OpenCL API headers in this repository are for the latest +OpenCL version (currently OpenCL 2.2). To use these API headers to target +a different OpenCL version, an application may `#define` the preprocessor +value `CL_TARGET_OPENCL_VERSION` before including the OpenCL API headers. +The `CL_TARGET_OPENCL_VERSION` is a three digit decimal value representing +the OpenCL API version. + +For example, to enforce usage of no more than the OpenCL 1.2 APIs, you may +include the OpenCL API headers as follows: + +``` +#define CL_TARGET_OPENCL_VERSION 120 +#include +``` + +## Directory Structure + +``` +README.md This file +LICENSE Source license for the OpenCL API headers +CL/ Unified OpenCL API headers tree +``` + +## License + +See [LICENSE](LICENSE). + +--- + +OpenCL and the OpenCL logo are trademarks of Apple Inc. used by permission by Khronos. diff --git a/opencl/khronos/headers/opencl2.2/tests/CMakeLists.txt b/opencl/khronos/headers/opencl2.2/tests/CMakeLists.txt new file mode 100644 index 0000000000..351008cf87 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/tests/CMakeLists.txt @@ -0,0 +1,43 @@ +cmake_minimum_required (VERSION 2.8.11) + +project(OpenCL_Headers_Tests) + +enable_testing() + +include_directories(${PROJECT_SOURCE_DIR}/..) + +# Make sure headers do not produce warnings +add_compile_options(-Wall -Wextra -Werror -pedantic -Wno-format) + +# Add a test for a given source file for each version of OpenCL +function(add_header_test NAME SOURCE) + foreach(VERSION 100 110 120 200 210 220) + set(TEST_EXE ${NAME}_${VERSION}) + add_executable(${TEST_EXE} ${SOURCE}) + target_compile_definitions(${TEST_EXE} + PUBLIC -DCL_TARGET_OPENCL_VERSION=${VERSION} + ) + add_test(NAME ${TEST_EXE} COMMAND ${TEST_EXE}) + if(${VERSION} EQUAL 220) + set(TEST_EXE ${NAME}_${VERSION}_EXPERIMENTAL) + add_executable(${TEST_EXE} ${SOURCE}) + target_compile_definitions(${TEST_EXE} + PUBLIC -DCL_TARGET_OPENCL_VERSION=${VERSION} -DCL_EXPERIMENTAL + ) + add_test(NAME ${TEST_EXE} COMMAND ${TEST_EXE}) + endif() + endforeach(VERSION) +endfunction(add_header_test) + +# Tests +add_header_test(cl_h test_cl.h.c) +add_header_test(cl_egl_h test_cl_egl.h.c) +add_header_test(cl_ext_h test_cl_ext.h.c) +add_header_test(cl_ext_intel_h test_cl_ext_intel.h.c) +add_header_test(cl_gl_h test_cl_gl.h.c) +add_header_test(cl_gl_ext_h test_cl_gl_ext.h.c) +add_header_test(cl_icd_h test_cl_icd.h.c) +add_header_test(cl_platform_h test_cl_platform.h.c) +add_header_test(cl_opencl_h test_opencl.h.c) +add_header_test(cl_version_h test_cl_version.h.c) +add_header_test(headers test_headers.c) diff --git a/opencl/khronos/headers/opencl2.2/tests/README.md b/opencl/khronos/headers/opencl2.2/tests/README.md new file mode 100644 index 0000000000..1f16fb88f1 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/tests/README.md @@ -0,0 +1,22 @@ +OpenCL-Headers/tests README +=========================== + +The test_headers.c test is designed to make sure that the various cl_typen types +work and conform to expectation for recent versions of cl_platform.h. Conforming +to these expectations make use of these types practical for developers writing +portable code. + +The various tests ending in .h.c are there to verify that the various OpenCL +headers can compile stand alone. That is to ensure that they may be used a la +carte. This provides developers a lifeline in the case that some unneeded part +of OpenCL (e.g. cl/gl sharing) brings in a pile of symbols (e.g. all of OpenGL) +that collides with other headers needed by the application. It is also poor form +to require headers to be included in a particular order, especially if multiple +systems require they be included in mutually incompatible order. So, here we +require that each header can be used standalone so that the order is irrelevant. + +We also check to make sure that the headers don't cause spurious warnings. These +tests are intended to be compiled using the most stringent compiler flags +available for the platform, within reason. All warnings should be errors and +extra warnings that it is expected developers are likely to use should be turned +on. diff --git a/opencl/khronos/headers/opencl2.2/tests/test_cl.h.c b/opencl/khronos/headers/opencl2.2/tests/test_cl.h.c new file mode 100644 index 0000000000..e8a7808913 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/tests/test_cl.h.c @@ -0,0 +1,25 @@ +// +// Copyright (c) 2020 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include "CL/cl.h" + +int main( void ) +{ + printf("cl.h standalone test PASSED.\n"); + return 0; +} diff --git a/opencl/khronos/headers/opencl2.2/tests/test_cl_egl.h.c b/opencl/khronos/headers/opencl2.2/tests/test_cl_egl.h.c new file mode 100644 index 0000000000..f9bf541ee8 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/tests/test_cl_egl.h.c @@ -0,0 +1,25 @@ +// +// Copyright (c) 2020 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include "CL/cl_egl.h" + +int main( void ) +{ + printf("cl_egl.h standalone test PASSED.\n"); + return 0; +} diff --git a/opencl/khronos/headers/opencl2.2/tests/test_cl_ext.h.c b/opencl/khronos/headers/opencl2.2/tests/test_cl_ext.h.c new file mode 100644 index 0000000000..5d430aa72a --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/tests/test_cl_ext.h.c @@ -0,0 +1,25 @@ +// +// Copyright (c) 2020 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include "CL/cl_ext.h" + +int main( void ) +{ + printf("cl_ext.h standalone test PASSED.\n"); + return 0; +} diff --git a/opencl/khronos/headers/opencl2.2/tests/test_cl_ext_intel.h.c b/opencl/khronos/headers/opencl2.2/tests/test_cl_ext_intel.h.c new file mode 100644 index 0000000000..72a0a8c463 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/tests/test_cl_ext_intel.h.c @@ -0,0 +1,25 @@ +// +// Copyright (c) 2020 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include "CL/cl_ext_intel.h" + +int main( void ) +{ + printf("cl_ext_intel.h standalone test PASSED.\n"); + return 0; +} diff --git a/opencl/khronos/headers/opencl2.2/tests/test_cl_gl.h.c b/opencl/khronos/headers/opencl2.2/tests/test_cl_gl.h.c new file mode 100644 index 0000000000..8c3c4ea140 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/tests/test_cl_gl.h.c @@ -0,0 +1,25 @@ +// +// Copyright (c) 2020 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include "CL/cl_gl.h" + +int main( void ) +{ + printf("cl_gl.h standalone test PASSED.\n"); + return 0; +} diff --git a/opencl/khronos/headers/opencl2.2/tests/test_cl_gl_ext.h.c b/opencl/khronos/headers/opencl2.2/tests/test_cl_gl_ext.h.c new file mode 100644 index 0000000000..5d675029fc --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/tests/test_cl_gl_ext.h.c @@ -0,0 +1,25 @@ +// +// Copyright (c) 2020 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include "CL/cl_gl_ext.h" + +int main( void ) +{ + printf("cl_gl_ext.h standalone test PASSED.\n"); + return 0; +} diff --git a/opencl/khronos/headers/opencl2.2/tests/test_cl_icd.h.c b/opencl/khronos/headers/opencl2.2/tests/test_cl_icd.h.c new file mode 100644 index 0000000000..9de0cf5503 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/tests/test_cl_icd.h.c @@ -0,0 +1,31 @@ +// +// Copyright (c) 2020 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#define CL_USE_DEPRECATED_OPENCL_1_0_APIS +#define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#define CL_USE_DEPRECATED_OPENCL_1_2_APIS +#define CL_USE_DEPRECATED_OPENCL_2_0_APIS +#define CL_USE_DEPRECATED_OPENCL_2_1_APIS +#define CL_USE_DEPRECATED_OPENCL_2_2_APIS +#include "CL/cl_icd.h" + +int main( void ) +{ + printf("cl_icd.h standalone test PASSED.\n"); + return 0; +} diff --git a/opencl/khronos/headers/opencl2.2/tests/test_cl_platform.h.c b/opencl/khronos/headers/opencl2.2/tests/test_cl_platform.h.c new file mode 100644 index 0000000000..4d21178751 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/tests/test_cl_platform.h.c @@ -0,0 +1,25 @@ +// +// Copyright (c) 2020 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include "CL/cl_platform.h" + +int main( void ) +{ + printf("cl_platform.h standalone test PASSED.\n"); + return 0; +} diff --git a/opencl/khronos/headers/opencl2.2/tests/test_cl_version.h.c b/opencl/khronos/headers/opencl2.2/tests/test_cl_version.h.c new file mode 100644 index 0000000000..7dfc48636b --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/tests/test_cl_version.h.c @@ -0,0 +1,25 @@ +// +// Copyright (c) 2020 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include "CL/cl_version.h" + +int main( void ) +{ + printf("cl_version.h standalone test PASSED.\n"); + return 0; +} diff --git a/opencl/khronos/headers/opencl2.2/tests/test_headers.c b/opencl/khronos/headers/opencl2.2/tests/test_headers.c new file mode 100644 index 0000000000..c870900db0 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/tests/test_headers.c @@ -0,0 +1,637 @@ +// +// Copyright (c) 2020 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include "CL/cl.h" + +int test_char() +{ +/* char */ + /* Constructor */ + cl_char a = 0; + cl_char2 a2 = {{ 0, 1 }}; + cl_char4 a4 = {{ 0, 1, 2, 3 }}; + cl_char8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }}; + cl_char16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }}; + + /* assignment */ + cl_char b = a; + cl_char2 b2 = a2; + cl_char4 b4 = a4; + cl_char8 b8 = a8; + cl_char16 b16 = a16; + + printf("\nVerifying assignment:\n" ); + printf("b: %d\n", b ); + printf("b2: %d %d \n", b2.s[0], b2.s[1] ); + printf("b4: %d %d %d %d\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] ); + printf("b8: %d %d %d %d %d %d %d %d\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] ); + printf("b16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7], + b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]); + + /* vector access */ + printf("\nVerifying vector access:\n" ); +#if defined( __CL_CHAR2__ ) + __cl_char2 v2 = b2.v2; + printf("__cl_char2: %d %d \n", ((cl_char*)&v2)[0], ((cl_char*)&v2)[1] ); +#else + printf( "__cl_char2 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_CHAR4__ ) + __cl_char4 v4 = b4.v4; + printf("__cl_char4: %d %d %d %d \n", ((cl_char*)&v4)[0], ((cl_char*)&v4)[1], ((cl_char*)&v4)[2], ((cl_char*)&v4)[3] ); +#else + printf( "__cl_char4 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_CHAR8__ ) + __cl_char8 v8 = b8.v8; + printf("__cl_char8: %d %d %d %d %d %d %d %d \n", ((cl_char*)&v8)[0], ((cl_char*)&v8)[1], ((cl_char*)&v8)[2], ((cl_char*)&v8)[3], ((cl_char*)&v8)[4], ((cl_char*)&v8)[5], ((cl_char*)&v8)[6], ((cl_char*)&v8)[7] ); +#else + printf( "__cl_char8 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_CHAR16__ ) + __cl_char16 v16 = b16.v16; + printf("__cl_char16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", ((cl_char*)&v16)[0], ((cl_char*)&v16)[1], ((cl_char*)&v16)[2], ((cl_char*)&v16)[3], ((cl_char*)&v16)[4], ((cl_char*)&v16)[5], ((cl_char*)&v16)[6], ((cl_char*)&v16)[7], + ((cl_char*)&v16)[8], ((cl_char*)&v16)[9], ((cl_char*)&v16)[10], ((cl_char*)&v16)[11], ((cl_char*)&v16)[12], ((cl_char*)&v16)[13], ((cl_char*)&v16)[14], ((cl_char*)&v16)[15]); +#else + printf( "__cl_char16 SIMD vectors not supported on this architecture.\n" ); +#endif + + printf( "\n" ); + return 0; +} + +int test_uchar() +{ +/* uchar */ + /* Constructor */ + cl_uchar a = 0; + cl_uchar2 a2 = {{ 0, 1 }}; + cl_uchar4 a4 = {{ 0, 1, 2, 3 }}; + cl_uchar8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }}; + cl_uchar16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }}; + + /* assignment */ + cl_uchar b = a; + cl_uchar2 b2 = a2; + cl_uchar4 b4 = a4; + cl_uchar8 b8 = a8; + cl_uchar16 b16 = a16; + + printf("\nVerifying assignment:\n" ); + printf("b: %d\n", b ); + printf("b2: %d %d \n", b2.s[0], b2.s[1] ); + printf("b4: %d %d %d %d\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] ); + printf("b8: %d %d %d %d %d %d %d %d\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] ); + printf("b16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7], + b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]); + + /* vector access */ + printf("\nVerifying vector access:\n" ); +#if defined( __CL_UCHAR2__ ) + __cl_uchar2 v2 = b2.v2; + printf("__cl_uchar2: %d %d \n", ((uchar*)&v2)[0], ((cl_uchar*)&v2)[1] ); +#else + printf( "__cl_uchar2 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_UCHAR4__ ) + __cl_uchar4 v4 = b4.v4; + printf("__cl_uchar4: %d %d %d %d \n", ((uchar*)&v4)[0], ((cl_uchar*)&v4)[1], ((cl_uchar*)&v4)[2], ((cl_uchar*)&v4)[3] ); +#else + printf( "__cl_uchar4 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_UCHAR8__ ) + __cl_uchar8 v8 = b8.v8; + printf("__cl_uchar8: %d %d %d %d %d %d %d %d \n", ((cl_uchar*)&v8)[0], ((cl_uchar*)&v8)[1], ((cl_uchar*)&v8)[2], ((cl_uchar*)&v8)[3], ((cl_uchar*)&v8)[4], ((cl_uchar*)&v8)[5], ((cl_uchar*)&v8)[6], ((cl_uchar*)&v8)[7] ); +#else + printf( "__cl_uchar8 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_UCHAR16__ ) + __cl_uchar16 v16 = b16.v16; + printf("__cl_uchar16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", ((cl_uchar*)&v16)[0], ((cl_uchar*)&v16)[1], ((cl_uchar*)&v16)[2], ((cl_uchar*)&v16)[3], ((cl_uchar*)&v16)[4], ((cl_uchar*)&v16)[5], ((cl_uchar*)&v16)[6], ((cl_uchar*)&v16)[7], + ((cl_uchar*)&v16)[8], ((cl_uchar*)&v16)[9], ((cl_uchar*)&v16)[10], ((cl_uchar*)&v16)[11], ((cl_uchar*)&v16)[12], ((cl_uchar*)&v16)[13], ((cl_uchar*)&v16)[14], ((cl_uchar*)&v16)[15]); +#else + printf( "__cl_uchar16 SIMD vectors not supported on this architecture.\n" ); +#endif + + printf( "\n" ); + return 0; +} + +int test_short() +{ +/* short */ + /* Constructor */ + cl_short a = 0; + cl_short2 a2 = {{ 0, 1 }}; + cl_short4 a4 = {{ 0, 1, 2, 3 }}; + cl_short8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }}; + cl_short16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }}; + + /* assignment */ + cl_short b = a; + cl_short2 b2 = a2; + cl_short4 b4 = a4; + cl_short8 b8 = a8; + cl_short16 b16 = a16; + + printf("\nVerifying assignment:\n" ); + printf("b: %d\n", b ); + printf("b2: %d %d \n", b2.s[0], b2.s[1] ); + printf("b4: %d %d %d %d\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] ); + printf("b8: %d %d %d %d %d %d %d %d\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] ); + printf("b16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7], + b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]); + + /* vector access */ + printf("\nVerifying vector access:\n" ); +#if defined( __CL_SHORT2__ ) + __cl_short2 v2 = b2.v2; + printf("__cl_short2: %d %d \n", ((cl_short*)&v2)[0], ((cl_short*)&v2)[1] ); +#else + printf( "__cl_short2 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_SHORT4__ ) + __cl_short4 v4 = b4.v4; + printf("__cl_short4: %d %d %d %d \n", ((cl_short*)&v4)[0], ((cl_short*)&v4)[1], ((cl_short*)&v4)[2], ((cl_short*)&v4)[3] ); +#else + printf( "__cl_short4 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_SHORT8__ ) + __cl_short8 v8 = b8.v8; + printf("__cl_short8: %d %d %d %d %d %d %d %d \n", ((cl_short*)&v8)[0], ((cl_short*)&v8)[1], ((cl_short*)&v8)[2], ((cl_short*)&v8)[3], ((cl_short*)&v8)[4], ((cl_short*)&v8)[5], ((cl_short*)&v8)[6], ((cl_short*)&v8)[7] ); +#else + printf( "__cl_short8 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_SHORT16__ ) + __cl_short16 v16 = b16.v16; + printf("__cl_short16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", ((cl_short*)&v16)[0], ((cl_short*)&v16)[1], ((cl_short*)&v16)[2], ((cl_short*)&v16)[3], ((cl_short*)&v16)[4], ((cl_short*)&v16)[5], ((cl_short*)&v16)[6], ((cl_short*)&v16)[7], + ((cl_short*)&v16)[8], ((cl_short*)&v16)[9], ((cl_short*)&v16)[10], ((cl_short*)&v16)[11], ((cl_short*)&v16)[12], ((cl_short*)&v16)[13], ((cl_short*)&v16)[14], ((cl_short*)&v16)[15]); +#else + printf( "__cl_short16 SIMD vectors not supported on this architecture.\n" ); +#endif + + printf( "\n" ); + return 0; +} + +int test_ushort() +{ +/* ushort */ + /* Constructor */ + cl_ushort a = 0; + cl_ushort2 a2 = {{ 0, 1 }}; + cl_ushort4 a4 = {{ 0, 1, 2, 3 }}; + cl_ushort8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }}; + cl_ushort16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }}; + + /* assignment */ + cl_ushort b = a; + cl_ushort2 b2 = a2; + cl_ushort4 b4 = a4; + cl_ushort8 b8 = a8; + cl_ushort16 b16 = a16; + + printf("\nVerifying assignment:\n" ); + printf("b: %d\n", b ); + printf("b2: %d %d \n", b2.s[0], b2.s[1] ); + printf("b4: %d %d %d %d\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] ); + printf("b8: %d %d %d %d %d %d %d %d\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] ); + printf("b16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7], + b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]); + + /* vector access */ + printf("\nVerifying vector access:\n" ); +#if defined( __CL_USHORT2__ ) + __cl_ushort2 v2 = b2.v2; + printf("__cl_ushort2: %d %d \n", ((unsigned short*)&v2)[0], ((unsigned short*)&v2)[1] ); +#else + printf( "__cl_ushort2 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_USHORT4__ ) + __cl_ushort4 v4 = b4.v4; + printf("__cl_ushort4: %d %d %d %d \n", ((unsigned short*)&v4)[0], ((unsigned short*)&v4)[1], ((unsigned short*)&v4)[2], ((unsigned short*)&v4)[3] ); +#else + printf( "__cl_ushort4 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_USHORT8__ ) + __cl_ushort8 v8 = b8.v8; + printf("__cl_ushort8: %d %d %d %d %d %d %d %d \n", ((unsigned short*)&v8)[0], ((unsigned short*)&v8)[1], ((unsigned short*)&v8)[2], ((unsigned short*)&v8)[3], ((unsigned short*)&v8)[4], ((unsigned short*)&v8)[5], ((unsigned short*)&v8)[6], ((unsigned short*)&v8)[7] ); +#else + printf( "__cl_ushort8 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_USHORT16__ ) + __cl_ushort16 v16 = b16.v16; + printf("__cl_ushort16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", ((unsigned short*)&v16)[0], ((unsigned short*)&v16)[1], ((unsigned short*)&v16)[2], ((unsigned short*)&v16)[3], ((unsigned short*)&v16)[4], ((unsigned short*)&v16)[5], ((unsigned short*)&v16)[6], ((unsigned short*)&v16)[7], + ((unsigned short*)&v16)[8], ((unsigned short*)&v16)[9], ((unsigned short*)&v16)[10], ((unsigned short*)&v16)[11], ((unsigned short*)&v16)[12], ((unsigned short*)&v16)[13], ((unsigned short*)&v16)[14], ((unsigned short*)&v16)[15]); +#else + printf( "__cl_ushort16 SIMD vectors not supported on this architecture.\n" ); +#endif + + printf( "\n" ); + return 0; +} + +int test_int() +{ +/* int */ + /* Constructor */ + cl_int a = 0; + cl_int2 a2 = {{ 0, 1 }}; + cl_int4 a4 = {{ 0, 1, 2, 3 }}; + cl_int8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }}; + cl_int16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }}; + + /* assignment */ + cl_int b = a; + cl_int2 b2 = a2; + cl_int4 b4 = a4; + cl_int8 b8 = a8; + cl_int16 b16 = a16; + + printf("\nVerifying assignment:\n" ); + printf("b: %d\n", b ); + printf("b2: %d %d \n", b2.s[0], b2.s[1] ); + printf("b4: %d %d %d %d\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] ); + printf("b8: %d %d %d %d %d %d %d %d\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] ); + printf("b16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7], + b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]); + + /* vector access */ + printf("\nVerifying vector access:\n" ); +#if defined( __CL_INT2__ ) + __cl_int2 v2 = b2.v2; + printf("__cl_int2: %d %d \n", ((cl_int*)&v2)[0], ((cl_int*)&v2)[1] ); +#else + printf( "__cl_int2 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_INT4__ ) + __cl_int4 v4 = b4.v4; + printf("__cl_int4: %d %d %d %d \n", ((cl_int*)&v4)[0], ((cl_int*)&v4)[1], ((cl_int*)&v4)[2], ((cl_int*)&v4)[3] ); +#else + printf( "__cl_int4 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_INT8__ ) + __cl_int8 v8 = b8.v8; + printf("__cl_int8: %d %d %d %d %d %d %d %d \n", ((cl_int*)&v8)[0], ((cl_int*)&v8)[1], ((cl_int*)&v8)[2], ((cl_int*)&v8)[3], ((cl_int*)&v8)[4], ((cl_int*)&v8)[5], ((cl_int*)&v8)[6], ((cl_int*)&v8)[7] ); +#else + printf( "__cl_int8 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_INT16__ ) + __cl_int16 v16 = b16.v16; + printf("__cl_int16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", ((cl_int*)&v16)[0], ((cl_int*)&v16)[1], ((cl_int*)&v16)[2], ((cl_int*)&v16)[3], ((cl_int*)&v16)[4], ((cl_int*)&v16)[5], ((cl_int*)&v16)[6], ((cl_int*)&v16)[7], + ((cl_int*)&v16)[8], ((cl_int*)&v16)[9], ((cl_int*)&v16)[10], ((cl_int*)&v16)[11], ((cl_int*)&v16)[12], ((cl_int*)&v16)[13], ((cl_int*)&v16)[14], ((cl_int*)&v16)[15]); +#else + printf( "__cl_int16 SIMD vectors not supported on this architecture.\n" ); +#endif + + printf( "\n" ); + return 0; +} + +int test_uint() +{ +/* uint */ + /* Constructor */ + cl_uint a = 0; + cl_uint2 a2 = {{ 0, 1 }}; + cl_uint4 a4 = {{ 0, 1, 2, 3 }}; + cl_uint8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }}; + cl_uint16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }}; + + /* assignment */ + cl_uint b = a; + cl_uint2 b2 = a2; + cl_uint4 b4 = a4; + cl_uint8 b8 = a8; + cl_uint16 b16 = a16; + + printf("\nVerifying assignment:\n" ); + printf("b: %d\n", b ); + printf("b2: %d %d \n", b2.s[0], b2.s[1] ); + printf("b4: %d %d %d %d\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] ); + printf("b8: %d %d %d %d %d %d %d %d\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] ); + printf("b16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7], + b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]); + + /* vector access */ + printf("\nVerifying vector access:\n" ); +#if defined( __CL_UINT2__ ) + __cl_uint2 v2 = b2.v2; + printf("__cl_uint2: %d %d \n", ((cl_uint*)&v2)[0], ((cl_uint*)&v2)[1] ); +#else + printf( "__cl_uint2 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_UINT4__ ) + __cl_uint4 v4 = b4.v4; + printf("__cl_uint4: %d %d %d %d \n", ((cl_uint*)&v4)[0], ((cl_uint*)&v4)[1], ((cl_uint*)&v4)[2], ((cl_uint*)&v4)[3] ); +#else + printf( "__cl_uint4 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_UINT8__ ) + __cl_uint8 v8 = b8.v8; + printf("__cl_uint8: %d %d %d %d %d %d %d %d \n", ((cl_uint*)&v8)[0], ((cl_uint*)&v8)[1], ((cl_uint*)&v8)[2], ((cl_uint*)&v8)[3], ((cl_uint*)&v8)[4], ((cl_uint*)&v8)[5], ((cl_uint*)&v8)[6], ((cl_uint*)&v8)[7] ); +#else + printf( "__cl_uint8 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_UINT16__ ) + __cl_uint16 v16 = b16.v16; + printf("__cl_uint16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", ((cl_uint*)&v16)[0], ((cl_uint*)&v16)[1], ((cl_uint*)&v16)[2], ((cl_uint*)&v16)[3], ((cl_uint*)&v16)[4], ((cl_uint*)&v16)[5], ((cl_uint*)&v16)[6], ((cl_uint*)&v16)[7], + ((cl_uint*)&v16)[8], ((cl_uint*)&v16)[9], ((cl_uint*)&v16)[10], ((cl_uint*)&v16)[11], ((cl_uint*)&v16)[12], ((cl_uint*)&v16)[13], ((cl_uint*)&v16)[14], ((cl_uint*)&v16)[15]); +#else + printf( "__cl_uint16 SIMD vectors not supported on this architecture.\n" ); +#endif + + printf( "\n" ); + return 0; +} + +int test_long() +{ +/* long */ + /* Constructor */ + cl_long a = 0; + cl_long2 a2 = {{ 0, 1 }}; + cl_long4 a4 = {{ 0, 1, 2, 3 }}; + cl_long8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }}; + cl_long16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }}; + + /* assignment */ + cl_long b = a; + cl_long2 b2 = a2; + cl_long4 b4 = a4; + cl_long8 b8 = a8; + cl_long16 b16 = a16; + + printf("\nVerifying assignment:\n" ); + printf("b: %lld\n", b ); + printf("b2: %lld %lld \n", b2.s[0], b2.s[1] ); + printf("b4: %lld %lld %lld %lld\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] ); + printf("b8: %lld %lld %lld %lld %lld %lld %lld %lld\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] ); + printf("b16: %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7], + b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]); + + /* vector access */ + printf("\nVerifying vector access:\n" ); +#if defined( __CL_LONG2__ ) + __cl_long2 v2 = b2.v2; + printf("__cl_long2: %lld %lld \n", ((cl_long*)&v2)[0], ((cl_long*)&v2)[1] ); +#else + printf( "__cl_long2 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_LONG4__ ) + __cl_long4 v4 = b4.v4; + printf("__cl_long4: %lld %lld %lld %lld \n", ((cl_long*)&v4)[0], ((cl_long*)&v4)[1], ((cl_long*)&v4)[2], ((cl_long*)&v4)[3] ); +#else + printf( "__cl_long4 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_LONG8__ ) + __cl_long8 v8 = b8.v8; + printf("__cl_long8: %lld %lld %lld %lld %lld %lld %lld %lld \n", ((cl_long*)&v8)[0], ((cl_long*)&v8)[1], ((cl_long*)&v8)[2], ((cl_long*)&v8)[3], ((cl_long*)&v8)[4], ((cl_long*)&v8)[5], ((cl_long*)&v8)[6], ((cl_long*)&v8)[7] ); +#else + printf( "__cl_long8 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_LONG16__ ) + __cl_long16 v16 = b16.v16; + printf("__cl_long16: %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld \n", ((cl_long*)&v16)[0], ((cl_long*)&v16)[1], ((cl_long*)&v16)[2], ((cl_long*)&v16)[3], ((cl_long*)&v16)[4], ((cl_long*)&v16)[5], ((cl_long*)&v16)[6], ((cl_long*)&v16)[7], + ((cl_long*)&v16)[8], ((cl_long*)&v16)[9], ((cl_long*)&v16)[10], ((cl_long*)&v16)[11], ((cl_long*)&v16)[12], ((cl_long*)&v16)[13], ((cl_long*)&v16)[14], ((cl_long*)&v16)[15]); +#else + printf( "__cl_long16 SIMD vectors not supported on this architecture.\n" ); +#endif + + printf( "\n" ); + return 0; +} + +int test_ulong() +{ +/* ulong */ + /* Constructor */ + cl_ulong a = 0; + cl_ulong2 a2 = {{ 0, 1 }}; + cl_ulong4 a4 = {{ 0, 1, 2, 3 }}; + cl_ulong8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }}; + cl_ulong16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }}; + + /* assignment */ + cl_ulong b = a; + cl_ulong2 b2 = a2; + cl_ulong4 b4 = a4; + cl_ulong8 b8 = a8; + cl_ulong16 b16 = a16; + + printf("\nVerifying assignment:\n" ); + printf("b: %lld\n", b ); + printf("b2: %lld %lld \n", b2.s[0], b2.s[1] ); + printf("b4: %lld %lld %lld %lld\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] ); + printf("b8: %lld %lld %lld %lld %lld %lld %lld %lld\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] ); + printf("b16: %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7], + b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]); + + /* vector access */ + printf("\nVerifying vector access:\n" ); +#if defined( __CL_ULONG2__ ) + __cl_ulong2 v2 = b2.v2; + printf("__cl_ulong2: %lld %lld \n", ((cl_ulong*)&v2)[0], ((cl_ulong*)&v2)[1] ); +#else + printf( "__cl_ulong2 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_ULONG4__ ) + __cl_ulong4 v4 = b4.v4; + printf("__cl_ulong4: %lld %lld %lld %lld \n", ((cl_ulong*)&v4)[0], ((cl_ulong*)&v4)[1], ((cl_ulong*)&v4)[2], ((cl_ulong*)&v4)[3] ); +#else + printf( "__cl_ulong4 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_ULONG8__ ) + __cl_ulong8 v8 = b8.v8; + printf("__cl_ulong8: %lld %lld %lld %lld %lld %lld %lld %lld \n", ((cl_ulong*)&v8)[0], ((cl_ulong*)&v8)[1], ((cl_ulong*)&v8)[2], ((cl_ulong*)&v8)[3], ((cl_ulong*)&v8)[4], ((cl_ulong*)&v8)[5], ((cl_ulong*)&v8)[6], ((cl_ulong*)&v8)[7] ); +#else + printf( "__cl_ulong8 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_ULONG16__ ) + __cl_ulong16 v16 = b16.v16; + printf("__cl_ulong16: %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld \n", ((cl_ulong*)&v16)[0], ((cl_ulong*)&v16)[1], ((cl_ulong*)&v16)[2], ((cl_ulong*)&v16)[3], ((cl_ulong*)&v16)[4], ((cl_ulong*)&v16)[5], ((cl_ulong*)&v16)[6], ((cl_ulong*)&v16)[7], + ((cl_ulong*)&v16)[8], ((cl_ulong*)&v16)[9], ((cl_ulong*)&v16)[10], ((cl_ulong*)&v16)[11], ((cl_ulong*)&v16)[12], ((cl_ulong*)&v16)[13], ((cl_ulong*)&v16)[14], ((cl_ulong*)&v16)[15]); +#else + printf( "__cl_ulong16 SIMD vectors not supported on this architecture.\n" ); +#endif + + printf( "\n" ); + return 0; +} + +int test_float() +{ +/* float */ + /* Constructor */ + cl_float a = 0.0f; + cl_float2 a2 = {{ 0.0f, 1.0f }}; + cl_float4 a4 = {{ 0.0f, 1.0f, 2.0f, 3.0f }}; + cl_float8 a8 = {{ 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f }}; + cl_float16 a16 = {{ 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f }}; + + /* assignment */ + cl_float b = a; + cl_float2 b2 = a2; + cl_float4 b4 = a4; + cl_float8 b8 = a8; + cl_float16 b16 = a16; + + printf("\nVerifying assignment:\n" ); + printf("b: %f\n", b ); + printf("b2: %f %f \n", b2.s[0], b2.s[1] ); + printf("b4: %f %f %f %f\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] ); + printf("b8: %f %f %f %f %f %f %f %f\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] ); + printf("b16: %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7], + b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]); + + /* vector access */ + printf("\nVerifying vector access:\n" ); +#if defined( __CL_FLOAT2__ ) + __cl_float2 v2 = b2.v2; + printf("__cl_float2: %f %f \n", ((cl_float*)&v2)[0], ((cl_float*)&v2)[1] ); +#else + printf( "__cl_float2 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_FLOAT4__ ) + { + __cl_float4 v4 = b4.v4; + printf("__cl_float4: %f %f %f %f \n", ((cl_float*)&v4)[0], ((cl_float*)&v4)[1], ((cl_float*)&v4)[2], ((cl_float*)&v4)[3] ); + } +#else + printf( "__cl_float4 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_FLOAT8__ ) + __cl_float8 v8 = b8.v8; + printf("__cl_float8: %f %f %f %f %f %f %f %f \n", ((cl_float*)&v8)[0], ((cl_float*)&v8)[1], ((cl_float*)&v8)[2], ((cl_float*)&v8)[3], ((cl_float*)&v8)[4], ((cl_float*)&v8)[5], ((cl_float*)&v8)[6], ((cl_float*)&v8)[7] ); +#else + printf( "__cl_float8 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_FLOAT16__ ) + __cl_float16 v16 = b16.v16; + printf("__cl_float16: %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f \n", ((cl_float*)&v16)[0], ((cl_float*)&v16)[1], ((cl_float*)&v16)[2], ((cl_float*)&v16)[3], ((cl_float*)&v16)[4], ((cl_float*)&v16)[5], ((cl_float*)&v16)[6], ((cl_float*)&v16)[7], + ((cl_float*)&v16)[8], ((cl_float*)&v16)[9], ((cl_float*)&v16)[10], ((cl_float*)&v16)[11], ((cl_float*)&v16)[12], ((cl_float*)&v16)[13], ((cl_float*)&v16)[14], ((cl_float*)&v16)[15]); +#else + printf( "__cl_float16 SIMD vectors not supported on this architecture.\n" ); +#endif + + printf( "\n" ); + return 0; +} + +int test_double() +{ +/* double */ + /* Constructor */ + cl_double a = 0.0f; + cl_double2 a2 = {{ 0.0f, 1.0f }}; + cl_double4 a4 = {{ 0.0f, 1.0f, 2.0f, 3.0f }}; + cl_double8 a8 = {{ 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f }}; + cl_double16 a16 = {{ 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f }}; + + /* assignment */ + cl_double b = a; + cl_double2 b2 = a2; + cl_double4 b4 = a4; + cl_double8 b8 = a8; + cl_double16 b16 = a16; + + printf("\nVerifying assignment:\n" ); + printf("b: %f\n", b ); + printf("b2: %f %f \n", b2.s[0], b2.s[1] ); + printf("b4: %f %f %f %f\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] ); + printf("b8: %f %f %f %f %f %f %f %f\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] ); + printf("b16: %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7], + b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]); + + /* vector access */ + printf("\nVerifying vector access:\n" ); +#if defined( __CL_DOUBLE2__ ) + __cl_double2 v2 = b2.v2; + printf("__cl_double2: %f %f \n", ((cl_double*)&v2)[0], ((cl_double*)&v2)[1] ); +#else + printf( "__cl_double2 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_DOUBLE4__ ) + __cl_double4 v4 = b4.v4; + printf("__cl_double4: %f %f %f %f \n", ((cl_double*)&v4)[0], ((cl_double*)&v4)[1], ((cl_double*)&v4)[2], ((cl_double*)&v4)[3] ); +#else + printf( "__cl_double4 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_DOUBLE8__ ) + __cl_double8 v8 = b8.v8; + printf("__cl_double8: %f %f %f %f %f %f %f %f \n", ((cl_double*)&v8)[0], ((cl_double*)&v8)[1], ((cl_double*)&v8)[2], ((cl_double*)&v8)[3], ((cl_double*)&v8)[4], ((cl_double*)&v8)[5], ((cl_double*)&v8)[6], ((cl_double*)&v8)[7] ); +#else + printf( "__cl_double8 SIMD vectors not supported on this architecture.\n" ); +#endif + +#if defined( __CL_DOUBLE16__ ) + __cl_double16 v16 = b16.v16; + printf("__cl_double16: %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f \n", ((cl_double*)&v16)[0], ((cl_double*)&v16)[1], ((cl_double*)&v16)[2], ((cl_double*)&v16)[3], ((cl_double*)&v16)[4], ((cl_double*)&v16)[5], ((cl_double*)&v16)[6], ((cl_double*)&v16)[7], + ((cl_double*)&v16)[8], ((cl_double*)&v16)[9], ((cl_double*)&v16)[10], ((cl_double*)&v16)[11], ((cl_double*)&v16)[12], ((cl_double*)&v16)[13], ((cl_double*)&v16)[14], ((cl_double*)&v16)[15]); +#else + printf( "__cl_double16 SIMD vectors not supported on this architecture.\n" ); +#endif + + printf( "\n" ); + return 0; +} + +int main(void) +{ + printf( "\nChecking operations on cl_types.\nNumbers, where presented, should walk upward from 0, with step of 1:\n" ); + + test_char(); + test_uchar(); + test_short(); + test_ushort(); + test_long(); + test_ulong(); + test_float(); + test_double(); + + return 0; +} diff --git a/opencl/khronos/headers/opencl2.2/tests/test_opencl.h.c b/opencl/khronos/headers/opencl2.2/tests/test_opencl.h.c new file mode 100644 index 0000000000..d8bbf34eb7 --- /dev/null +++ b/opencl/khronos/headers/opencl2.2/tests/test_opencl.h.c @@ -0,0 +1,25 @@ +// +// Copyright (c) 2020 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include "CL/opencl.h" + +int main( void ) +{ + printf("opencl.h standalone test PASSED.\n"); + return 0; +} diff --git a/opencl/khronos/icd/.gitignore b/opencl/khronos/icd/.gitignore new file mode 100644 index 0000000000..9bb7c139d7 --- /dev/null +++ b/opencl/khronos/icd/.gitignore @@ -0,0 +1,4 @@ +inc/CL/ +inc/EGL/ +inc/KHR/ +build/ diff --git a/opencl/khronos/icd/CMakeLists.txt b/opencl/khronos/icd/CMakeLists.txt new file mode 100644 index 0000000000..4bafa862e2 --- /dev/null +++ b/opencl/khronos/icd/CMakeLists.txt @@ -0,0 +1,138 @@ +cmake_minimum_required (VERSION 2.8.11) + +project (OPENCL_ICD_LOADER) +include (GNUInstallDirs) +find_package (Threads REQUIRED) + +# The option below allows building the ICD Loader library as a shared library +# (ON, default) or a static library (OFF). +# +# Khronos OpenCL Working Group strongly recommends building and using the ICD +# loader as a shared library due to the following benefits: +# +# 1. The shared library can be updated independent of the application. This +# allows releasing new fixes and features in the ICD loader without updating +# the application. +# +# In rare cases when there are backward-incompatible changes to the ICD +# loader (due to platform requirements, for instance), using a shared +# library allows updating the library to make the transition seamless to +# installed applications. +# +# 2. On platforms that require the ICD mechanism there are multiple vendors +# shipping their OpenCL implementations. The vendor installers collaborate +# to make sure that the installed ICD shared library version is suitable for +# working with all vendor implementations installed on the system. +# +# If applications statically link to ICD Loader then that version of the ICD +# loader may not work with one or more installed vendor implementations. +# +# Using the OpenCL ICD loader as a static library is NOT recommended for +# end-user installations in general. However in some controlled environments it +# may be useful to simplify the build and distribution of the application. E.g. +# in test farms, or in cases where the end-user system configs are known in +# advance. Use it with discretion. +option (BUILD_SHARED_LIBS "Build shared libs" ON) + +include(CheckFunctionExists) +check_function_exists(secure_getenv HAVE_SECURE_GETENV) +check_function_exists(__secure_getenv HAVE___SECURE_GETENV) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/loader/icd_cmake_config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/icd_cmake_config.h) + +set (OPENCL_ICD_LOADER_SOURCES + loader/icd.c + loader/icd.h + loader/icd_dispatch.c + loader/icd_dispatch.h + loader/icd_envvars.h + loader/icd_platform.h) + +if (WIN32) + list (APPEND OPENCL_ICD_LOADER_SOURCES + loader/windows/icd_windows.c + loader/windows/icd_windows.h + loader/windows/icd_windows_dxgk.c + loader/windows/icd_windows_dxgk.h + loader/windows/icd_windows_envvars.c + loader/windows/icd_windows_hkr.c + loader/windows/icd_windows_hkr.h + loader/windows/OpenCL.def + loader/windows/OpenCL.rc) + # Only add the DXSDK include directory if the environment variable is + # defined. Since the DXSDK has merged into the Windows SDK, this is + # only required in rare cases. + if (DEFINED ENV{DXSDK_DIR} AND NOT (MINGW OR MSYS OR CYGWIN)) + include_directories ($ENV{DXSDK_DIR}/Include) + endif () +else () + list (APPEND OPENCL_ICD_LOADER_SOURCES + loader/linux/icd_linux.c + loader/linux/icd_linux_envvars.c + loader/linux/icd_exports.map) +endif () + +set (OPENCL_ICD_LOADER_HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/inc CACHE PATH "Path to OpenCL Headers") + +add_library (OpenCL ${OPENCL_ICD_LOADER_SOURCES}) +set_target_properties (OpenCL PROPERTIES VERSION "1.2" SOVERSION "1") + +if (WIN32) + target_link_libraries (OpenCL cfgmgr32.lib) + + option (OPENCL_ICD_LOADER_REQUIRE_WDK "Build with D3DKMT support, which requires the Windows WDK." ON) + if (OPENCL_ICD_LOADER_REQUIRE_WDK) + if(DEFINED ENV{WDKContentRoot}) + file(GLOB D3DKMT_HEADER "$ENV{WDKContentRoot}/Include/*/km/d3dkmthk.h") + else() + file(GLOB D3DKMT_HEADER "$ENV{HOMEDRIVE}/Program Files */Windows Kits/10/Include/*/km/d3dkmthk.h") + endif() + + if(D3DKMT_HEADER) + list(GET D3DKMT_HEADER -1 LATEST_D3DKMT_HEADER) + get_filename_component(WDK_DIRECTORY ${LATEST_D3DKMT_HEADER} DIRECTORY) + get_filename_component(WDK_DIRECTORY ${WDK_DIRECTORY} DIRECTORY) + message(STATUS "Found the Windows WDK in: ${WDK_DIRECTORY}") + target_compile_definitions(OpenCL PRIVATE OPENCL_ICD_LOADER_REQUIRE_WDK) + target_include_directories(OpenCL PRIVATE ${WDK_DIRECTORY}/um) + target_include_directories(OpenCL PRIVATE ${WDK_DIRECTORY}/km) + target_include_directories(OpenCL PRIVATE ${WDK_DIRECTORY}/shared) + else() + message(FATAL_ERROR "The Windows WDK was not found. Consider disabling OPENCL_ICD_LOADER_REQUIRE_WDK. Aborting.") + endif() + endif() + + if(NOT USE_DYNAMIC_VCXX_RUNTIME) + string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}") + string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}") + string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}") + string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") + string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + endif() +else() + if (APPLE) + target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT}) + else () + set_target_properties (OpenCL PROPERTIES LINK_FLAGS "-Wl,--version-script -Wl,${CMAKE_CURRENT_SOURCE_DIR}/loader/linux/icd_exports.map") + target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT}) + endif () +endif () + +include_directories (${OPENCL_ICD_LOADER_HEADERS_DIR}) +add_definitions (-DCL_TARGET_OPENCL_VERSION=220) + +target_include_directories (OpenCL PRIVATE ${CMAKE_CURRENT_BINARY_DIR} loader) +target_link_libraries (OpenCL ${CMAKE_DL_LIBS}) + +include (CTest) +if (BUILD_TESTING) + add_subdirectory (test) +endif() + +install (TARGETS OpenCL + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/opencl/khronos/icd/CODE_OF_CONDUCT.md b/opencl/khronos/icd/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000..a11610bd30 --- /dev/null +++ b/opencl/khronos/icd/CODE_OF_CONDUCT.md @@ -0,0 +1 @@ +A reminder that this issue tracker is managed by the Khronos Group. Interactions here should follow the Khronos Code of Conduct (https://www.khronos.org/developers/code-of-conduct), which prohibits aggressive or derogatory language. Please keep the discussion friendly and civil. diff --git a/opencl/khronos/icd/LICENSE b/opencl/khronos/icd/LICENSE new file mode 100644 index 0000000000..261eeb9e9f --- /dev/null +++ b/opencl/khronos/icd/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/opencl/khronos/icd/LICENSE.txt b/opencl/khronos/icd/LICENSE.txt new file mode 100644 index 0000000000..7afedf6cf9 --- /dev/null +++ b/opencl/khronos/icd/LICENSE.txt @@ -0,0 +1,35 @@ +Copyright (c) 2016 The Khronos Group Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software source and associated documentation files (the "Materials"), +to deal in the Materials without restriction, including without limitation +the rights to use, copy, modify, compile, merge, publish, distribute, +sublicense, and/or sell copies of the Materials, and to permit persons to +whom the Materials are furnished to do so, subject the following terms and +conditions: + +All modifications to the Materials used to create a binary that is +distributed to third parties shall be provided to Khronos with an +unrestricted license to use for the purposes of implementing bug fixes and +enhancements to the Materials; + +If the binary is used as part of an OpenCL(TM) implementation, whether binary +is distributed together with or separately to that implementation, then +recipient must become an OpenCL Adopter and follow the published OpenCL +conformance process for that implementation, details at: +http://www.khronos.org/conformance/; + +The above copyright notice, the OpenCL trademark license, and this permission +notice shall be included in all copies or substantial portions of the +Materials. + +THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN +THE MATERIALS. + +OpenCL is a trademark of Apple Inc. used under license by Khronos. + diff --git a/opencl/khronos/icd/README.md b/opencl/khronos/icd/README.md new file mode 100644 index 0000000000..852591c11d --- /dev/null +++ b/opencl/khronos/icd/README.md @@ -0,0 +1,132 @@ +# OpenCL ICD Loader + +This repo contains the source code and tests for the Khronos official OpenCL ICD Loader. + +## CI Build Status + +[![Windows Build Status](https://ci.appveyor.com/api/projects/status/47uhjgp5h4de2f63/branch/master?svg=true)](https://ci.appveyor.com/project/Khronoswebmaster/opencl-icd-loader/branch/master) [![Linux OSX Build Status](https://travis-ci.com/KhronosGroup/opencl-icd-loader.svg?branch=master)](https://travis-ci.com/KhronosGroup/opencl-icd-loader) + +## Introduction + +OpenCL defines an *Installable Client Driver* (ICD) mechanism to allow developers to build applications against an *Installable Client Driver* loader (ICD loader) rather than linking their applications against a specific OpenCL implementation. +The ICD Loader is responsible for: + +* Exporting OpenCL API entry points +* Enumerating OpenCL implementations +* Forwarding OpenCL API calls to the correct implementation + +This repo contains the source code and tests for the Khronos official OpenCL ICD Loader. + +Note that this repo does not contain an OpenCL implementation (ICD). +You will need to obtain and install an OpenCL implementation for your OpenCL device that supports the OpenCL ICD extension `cl_khr_icd` to run an application using the OpenCL ICD Loader. + +The OpenCL *Installable Client Driver* extension (`cl_khr_icd`) is described in the OpenCL extensions specification, which may be found on the [Khronos OpenCL Registry](https://www.khronos.org/registry/OpenCL/). + +## Build Instructions + +### Dependencies + +The OpenCL ICD Loader requires OpenCL Headers. +To use system OpenCL Headers, please specify the OpenCL Header location using the CMake variable `OPENCL_ICD_LOADER_HEADERS_DIR`. +By default, the OpenCL ICD Loader will look for OpenCL Headers in the `inc` directory. + +By default, the OpenCL ICD Loader on Windows requires the Windows Driver Kit (WDK). +To build OpenCL ICD Loader with WDK support - +* Install recent Windows WDK currently at https://docs.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk + +* Establish environment variable WDK to include directory. Ex: set WDK=C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0 + +An OpenCL ICD Loader may be built without the Windows Driver Kit using the CMake variable `OPENCL_ICD_LOADER_REQUIRE_WDK`, however this option should be used with caution since it may prevent the OpenCL ICD Loader from enumerating some OpenCL implementations. +This dependency may be removed in the future. + +The OpenCL ICD Loader uses CMake for its build system. +If CMake is not provided by your build system or OS package manager, please consult the [CMake website](https://cmake.org). + +### Build and Install Directories + +A common convention is to place the `build` directory in the top directory of the repository and to place the `install` directory as a child of the `build` directory. +The remainder of these instructions follow this convention, although you may place these directories in any location. + +### Example Usage + +For most Windows and Linux usages, the following steps are sufficient to build the OpenCL ICD Loader: + +1. Clone this repo: + + git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader + +1. Obtain the OpenCL Headers, if you are not planning to use system OpenCL headers. +Headers may be obtained from the [Khronos OpenCL Headers](https://github.com/KhronosGroup/OpenCL-Headers) repository. + +1. Create a `build` directory: + + cd OpenCL-ICD-Loader + mkdir build + cd build + +1. Invoke `cmake` to generate solution files, Makefiles, or files for other build systems. + + cmake .. + +1. Build using the CMake-generated files. + +Notes: + +* For 64-bit Windows builds, you may need to specify a 64-bit generator manually, for example: + + cmake.exe -G "Visual Studio 14 2015 Win64" .. + +* Some users may prefer to use a CMake GUI frontend, such as `cmake-gui` or `ccmake`, vs. the command-line CMake. + +## OpenCL ICD Loader Tests + +OpenCL ICD Loader Tests can be run using `ctest`, which is a companion to CMake. +The OpenCL ICD Loader Tests can also be run directly by executing icd_loader_test(.exe) executable from the bin folder. + +### Test Setup + +The OpenCL ICD Loader Tests use a "stub" ICD, which must be set up manually. +The OpenCL ICD Loader Tests will "fail" if the "stub" ICD is not set up correctly. +The method to install the "stub" ICD is operating system dependent. + +On Linux, install the "stub" ICD by creating a file with the full path to the "stub" ICD in `/etc/OpenCL/vendors`: + + echo full/path/to/libOpenCLDriverStub.so > /etc/OpenCL/vendors/test.icd + +On Windows, add the "stub" ICD by adding a `REG_DWORD` value to the registry keys: + + // For 32-bit operating systems, or 64-bit tests on a 64-bit operating system: + HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors + + // For 32-bit tests on a 64-bit operating system: + HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Khronos\OpenCL\Vendors + + // The name of the REG_DWORD value should be the full path to the "stub" ICD + // OpenCLDriverStub.dll, and the data for this value should be 0. + +### Running Tests + +To run the tests, invoke `ctest` from the `build` directory. +The CMake-generated build files may be able to invoke the OpenCL ICD Loader tests as well. + +### Test Cleanup + +Manually remove the file or registry keys added during Test Setup. + +## Support + +Please create a GitHub issue to report an issue or ask questions. + +## Contributing + +Contributions to the OpenCL ICD Loader are welcomed and encouraged. +You will be prompted with a one-time "click-through" CLA dialog as part of submitting your pull request or other contribution to GitHub. + +## Table of Debug Environment Variables + +The following debug environment variables are available for use with the OpenCL ICD loader: + +| Environment Variable | Behavior | Example Format | +|:---------------------------------:|---------------------|----------------------| +| OCL_ICD_FILENAMES | Specifies a list of additional ICDs to load. The ICDs will be enumerated first, before any ICDs discovered via default mechanisms. | `export OCL_ICD_FILENAMES=libVendorA.so:libVendorB.so`

`set OCL_ICD_FILENAMES=vendor_a.dll;vendor_b.dll` | +| OCL_ICD_VENDORS | On Linux and Android, specifies a directory to scan for ICDs to enumerate in place of the default `/etc/OpenCL/vendors'. | `export OCL_ICD_VENDORS=/my/local/icd/search/path` | diff --git a/opencl/khronos/icd/inc/README.txt b/opencl/khronos/icd/inc/README.txt new file mode 100644 index 0000000000..9209d44d1c --- /dev/null +++ b/opencl/khronos/icd/inc/README.txt @@ -0,0 +1,14 @@ +Copy or symlink OpenCL headers here, inside a CL directory, so that +the structure of the inc directory looks something like this: + +inc/CL/cl_d3d10.h +inc/CL/cl_d3d11.h +inc/CL/cl_dx9_media_sharing.h +inc/CL/cl_egl.h +inc/CL/cl_ext.h +inc/CL/cl_gl_ext.h +inc/CL/cl_gl.h +inc/CL/cl.h +inc/CL/cl.hpp +inc/CL/cl_platform.h +inc/CL/opencl.h diff --git a/opencl/khronos/icd/loader/icd.c b/opencl/khronos/icd/loader/icd.c new file mode 100644 index 0000000000..ccd5231c44 --- /dev/null +++ b/opencl/khronos/icd/loader/icd.c @@ -0,0 +1,273 @@ +/* Modifications Copyright(C) 2022 Advanced Micro Devices, Inc. + * All rights reserved. + */ + +/* + * Copyright (c) 2016-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#include "icd.h" +#include "icd_dispatch.h" +#include "icd_envvars.h" +#include +#include + +KHRicdVendor *khrIcdVendors = NULL; + +// entrypoint to initialize the ICD and add all vendors +void khrIcdInitialize(void) +{ + // enumerate vendors present on the system + khrIcdOsVendorsEnumerateOnce(); +} + +void khrIcdVendorAdd(const char *libraryName) +{ + void *library = NULL; + cl_int result = CL_SUCCESS; + pfn_clGetExtensionFunctionAddress p_clGetExtensionFunctionAddress = NULL; + pfn_clIcdGetPlatformIDs p_clIcdGetPlatformIDs = NULL; + cl_uint i = 0; + cl_uint platformCount = 0; + cl_platform_id *platforms = NULL; + KHRicdVendor *vendorIterator = NULL; + + // require that the library name be valid + if (!libraryName) + { + goto Done; + } + KHR_ICD_TRACE("attempting to add vendor %s...\n", libraryName); + + // load its library and query its function pointers + library = khrIcdOsLibraryLoad(libraryName); + if (!library) + { + KHR_ICD_TRACE("failed to load library %s\n", libraryName); + goto Done; + } + + // get the library's file name + const char *libName = libraryName; + const char *c; + for (c = libraryName; *c; ++c) + { + if ((*c == '\\') || (*c == '/')) + { + libName = c + 1; + } + } + + // ensure that we haven't already loaded this vendor + for (vendorIterator = khrIcdVendors; vendorIterator; vendorIterator = vendorIterator->next) + { + if (vendorIterator->library == library) + { + KHR_ICD_TRACE("already loaded vendor %s, nothing to do here\n", libraryName); + goto Done; + } + if (!strcmp(vendorIterator->libName, libName)) + { + KHR_ICD_TRACE("already loaded library %s, nothing to do here\n", libName); + goto Done; + } + } + + // get the library's clGetExtensionFunctionAddress pointer + p_clGetExtensionFunctionAddress = (pfn_clGetExtensionFunctionAddress)(size_t)khrIcdOsLibraryGetFunctionAddress(library, "clGetExtensionFunctionAddress"); + if (!p_clGetExtensionFunctionAddress) + { + KHR_ICD_TRACE("failed to get function address clGetExtensionFunctionAddress\n"); + goto Done; + } + + // use that function to get the clIcdGetPlatformIDsKHR function pointer + p_clIcdGetPlatformIDs = (pfn_clIcdGetPlatformIDs)(size_t)p_clGetExtensionFunctionAddress("clIcdGetPlatformIDsKHR"); + if (!p_clIcdGetPlatformIDs) + { + KHR_ICD_TRACE("failed to get extension function address clIcdGetPlatformIDsKHR\n"); + goto Done; + } + + // query the number of platforms available and allocate space to store them + result = p_clIcdGetPlatformIDs(0, NULL, &platformCount); + if (CL_SUCCESS != result) + { + KHR_ICD_TRACE("failed clIcdGetPlatformIDs\n"); + goto Done; + } + platforms = (cl_platform_id *)malloc(platformCount * sizeof(cl_platform_id) ); + if (!platforms) + { + KHR_ICD_TRACE("failed to allocate memory\n"); + goto Done; + } + memset(platforms, 0, platformCount * sizeof(cl_platform_id) ); + result = p_clIcdGetPlatformIDs(platformCount, platforms, NULL); + if (CL_SUCCESS != result) + { + KHR_ICD_TRACE("failed clIcdGetPlatformIDs\n"); + goto Done; + } + + // for each platform, add it + for (i = 0; i < platformCount; ++i) + { + KHRicdVendor* vendor = NULL; + char *suffix; + size_t suffixSize; + + // call clGetPlatformInfo on the returned platform to get the suffix + if (!platforms[i]) + { + continue; + } + result = platforms[i]->dispatch->clGetPlatformInfo( + platforms[i], + CL_PLATFORM_ICD_SUFFIX_KHR, + 0, + NULL, + &suffixSize); + if (CL_SUCCESS != result) + { + continue; + } + suffix = (char *)malloc(suffixSize); + if (!suffix) + { + continue; + } + result = platforms[i]->dispatch->clGetPlatformInfo( + platforms[i], + CL_PLATFORM_ICD_SUFFIX_KHR, + suffixSize, + suffix, + NULL); + if (CL_SUCCESS != result) + { + free(suffix); + continue; + } + + // allocate a structure for the vendor + vendor = (KHRicdVendor*)malloc(sizeof(*vendor) ); + if (!vendor) + { + free(suffix); + KHR_ICD_TRACE("failed to allocate memory\n"); + continue; + } + memset(vendor, 0, sizeof(*vendor) ); + + // populate vendor data + vendor->library = khrIcdOsLibraryLoad(libraryName); + if (!vendor->library) + { + free(suffix); + free(vendor); + KHR_ICD_TRACE("failed get platform handle to library\n"); + continue; + } + vendor->libName = (char *)malloc(strlen(libName) + 1); + strcpy(vendor->libName, libName); + vendor->clGetExtensionFunctionAddress = p_clGetExtensionFunctionAddress; + vendor->platform = platforms[i]; + vendor->suffix = suffix; + + // add this vendor to the list of vendors at the tail + { + KHRicdVendor **prevNextPointer = NULL; + for (prevNextPointer = &khrIcdVendors; *prevNextPointer; prevNextPointer = &( (*prevNextPointer)->next) ); + *prevNextPointer = vendor; + } + + KHR_ICD_TRACE("successfully added vendor %s with suffix %s\n", libraryName, suffix); + + } + +Done: + + if (library) + { + khrIcdOsLibraryUnload(library); + } + if (platforms) + { + free(platforms); + } +} + +// Get next file or dirname given a string list or registry key path. +// Note: the input string may be modified! +static char *loader_get_next_path(char *path) { + size_t len; + char *next; + + if (path == NULL) return NULL; + next = strchr(path, PATH_SEPARATOR); + if (next == NULL) { + len = strlen(path); + next = path + len; + } else { + *next = '\0'; + next++; + } + + return next; +} + +void khrIcdVendorsEnumerateEnv(void) +{ + char* icdFilenames = khrIcd_secure_getenv("OCL_ICD_FILENAMES"); + char* cur_file = NULL; + char* next_file = NULL; + if (icdFilenames) + { + KHR_ICD_TRACE("Found OCL_ICD_FILENAMES environment variable.\n"); + + next_file = icdFilenames; + while (NULL != next_file && *next_file != '\0') { + cur_file = next_file; + next_file = loader_get_next_path(cur_file); + + khrIcdVendorAdd(cur_file); + } + + khrIcd_free_getenv(icdFilenames); + } +} + +void khrIcdContextPropertiesGetPlatform(const cl_context_properties *properties, cl_platform_id *outPlatform) +{ + if (properties == NULL && khrIcdVendors != NULL) + { + *outPlatform = khrIcdVendors[0].platform; + } + else + { + const cl_context_properties *property = (cl_context_properties *)NULL; + *outPlatform = NULL; + for (property = properties; property && property[0]; property += 2) + { + if ((cl_context_properties)CL_CONTEXT_PLATFORM == property[0]) + { + *outPlatform = (cl_platform_id)property[1]; + } + } + } +} + diff --git a/opencl/khronos/icd/loader/icd.h b/opencl/khronos/icd/loader/icd.h new file mode 100644 index 0000000000..a99010c3b8 --- /dev/null +++ b/opencl/khronos/icd/loader/icd.h @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2016-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#ifndef _ICD_H_ +#define _ICD_H_ + +#include "icd_platform.h" + +#ifndef CL_USE_DEPRECATED_OPENCL_1_0_APIS +#define CL_USE_DEPRECATED_OPENCL_1_0_APIS +#endif + +#ifndef CL_USE_DEPRECATED_OPENCL_1_1_APIS +#define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#endif + +#ifndef CL_USE_DEPRECATED_OPENCL_1_2_APIS +#define CL_USE_DEPRECATED_OPENCL_1_2_APIS +#endif + +#include +#include + +/* + * type definitions + */ + +typedef CL_API_ENTRY cl_int (CL_API_CALL *pfn_clIcdGetPlatformIDs)( + cl_uint num_entries, + cl_platform_id *platforms, + cl_uint *num_platforms) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY cl_int (CL_API_CALL *pfn_clGetPlatformInfo)( + cl_platform_id platform, + cl_platform_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + +typedef CL_API_ENTRY void *(CL_API_CALL *pfn_clGetExtensionFunctionAddress)( + const char *function_name) CL_API_SUFFIX__VERSION_1_0; + +typedef struct KHRicdVendorRec KHRicdVendor; + +/* + * KHRicdVendor + * + * Data for a single ICD vendor platform. + */ +struct KHRicdVendorRec +{ + // the loaded library object (true type varies on Linux versus Windows) + void *library; + + // the file name of the library + char *libName; + + // the extension suffix for this platform + char *suffix; + + // function pointer to the ICD platform IDs extracted from the library + pfn_clGetExtensionFunctionAddress clGetExtensionFunctionAddress; + + // the platform retrieved from clGetIcdPlatformIDsKHR + cl_platform_id platform; + + // next vendor in the list vendors + KHRicdVendor *next; +}; + +// the global state +extern KHRicdVendor * khrIcdVendors; + +/* + * khrIcd interface + */ + +// read vendors from system configuration and store the data +// loaded into khrIcdState. this will call the OS-specific +// function khrIcdEnumerateVendors. this is called at every +// dispatch function which may be a valid first call into the +// API (e.g, getPlatformIDs, etc). +void khrIcdInitialize(void); + +// go through the list of vendors (in /etc/OpenCL.conf or through +// the registry) and call khrIcdVendorAdd for each vendor encountered +// n.b, this call is OS-specific +void khrIcdOsVendorsEnumerateOnce(void); + +// read vendors from environment variables +void khrIcdVendorsEnumerateEnv(void); + +// add a vendor's implementation to the list of libraries +void khrIcdVendorAdd(const char *libraryName); + +// dynamically load a library. returns NULL on failure +// n.b, this call is OS-specific +void *khrIcdOsLibraryLoad(const char *libraryName); + +// get a function pointer from a loaded library. returns NULL on failure. +// n.b, this call is OS-specific +void *khrIcdOsLibraryGetFunctionAddress(void *library, const char *functionName); + +// unload a library. +// n.b, this call is OS-specific +void khrIcdOsLibraryUnload(void *library); + +// parse properties and determine the platform to use from them +void khrIcdContextPropertiesGetPlatform( + const cl_context_properties *properties, + cl_platform_id *outPlatform); + +// internal tracing macros +#if 0 + #include + #define KHR_ICD_TRACE(...) \ + do \ + { \ + fprintf(stderr, "KHR ICD trace at %s:%d: ", __FILE__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); \ + } while (0) +#ifdef _WIN32 +#define KHR_ICD_WIDE_TRACE(...) \ + do \ + { \ + fwprintf(stderr, L"KHR ICD trace at %hs:%d: ", __FILE__, __LINE__); \ + fwprintf(stderr, __VA_ARGS__); \ + } while (0) +#else +#define KHR_ICD_WIDE_TRACE(...) +#endif + #define KHR_ICD_ASSERT(x) \ + do \ + { \ + if (!(x)) \ + { \ + fprintf(stderr, "KHR ICD assert at %s:%d: %s failed", __FILE__, __LINE__, #x); \ + } \ + } while (0) +#else + #define KHR_ICD_TRACE(...) + #define KHR_ICD_WIDE_TRACE(...) + #define KHR_ICD_ASSERT(x) +#endif + +// if handle is NULL then return invalid_handle_error_code +#define KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(handle,invalid_handle_error_code) \ + do \ + { \ + if (!handle) \ + { \ + return invalid_handle_error_code; \ + } \ + } while (0) + +// if handle is NULL then set errcode_ret to invalid_handle_error and return NULL +// (NULL being an invalid handle) +#define KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(handle,invalid_handle_error) \ + do \ + { \ + if (!handle) \ + { \ + if (errcode_ret) \ + { \ + *errcode_ret = invalid_handle_error; \ + } \ + return NULL; \ + } \ + } while (0) + + +#endif + diff --git a/opencl/khronos/icd/loader/icd_cmake_config.h.in b/opencl/khronos/icd/loader/icd_cmake_config.h.in new file mode 100644 index 0000000000..3bbc46127a --- /dev/null +++ b/opencl/khronos/icd/loader/icd_cmake_config.h.in @@ -0,0 +1,2 @@ +#cmakedefine HAVE_SECURE_GETENV +#cmakedefine HAVE___SECURE_GETENV diff --git a/opencl/khronos/icd/loader/icd_dispatch.c b/opencl/khronos/icd/loader/icd_dispatch.c new file mode 100644 index 0000000000..d07777fd99 --- /dev/null +++ b/opencl/khronos/icd/loader/icd_dispatch.c @@ -0,0 +1,2678 @@ +/* Modifications Copyright(C) 2022 Advanced Micro Devices, Inc. + * All rights reserved. + */ + +/* + * Copyright (c) 2012-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#include "icd_dispatch.h" +#include "icd.h" +#include +#include + +// Platform APIs +CL_API_ENTRY cl_int CL_API_CALL +clGetPlatformIDs(cl_uint num_entries, + cl_platform_id * platforms, + cl_uint * num_platforms) CL_API_SUFFIX__VERSION_1_0 +{ + KHRicdVendor* vendor = NULL; + cl_uint i; + + // initialize the platforms (in case they have not been already) + khrIcdInitialize(); + + if (!num_entries && platforms) + { + return CL_INVALID_VALUE; + } + if (!platforms && !num_platforms) + { + return CL_INVALID_VALUE; + } + // set num_platforms to 0 and set all platform pointers to NULL + if (num_platforms) + { + *num_platforms = 0; + } + for (i = 0; i < num_entries && platforms; ++i) + { + platforms[i] = NULL; + } + // return error if we have no platforms + if (!khrIcdVendors) + { + return CL_PLATFORM_NOT_FOUND_KHR; + } + // otherwise enumerate all platforms + for (vendor = khrIcdVendors; vendor; vendor = vendor->next) + { + if (num_entries && platforms) + { + *(platforms++) = vendor->platform; + --num_entries; + } + if (num_platforms) + { + ++(*num_platforms); + } + } + return CL_SUCCESS; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetPlatformInfo(cl_platform_id platform, + cl_platform_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + // initialize the platforms (in case they have not been already) + khrIcdInitialize(); + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(platform, CL_INVALID_PLATFORM); + return platform->dispatch->clGetPlatformInfo( + platform, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +// Device APIs +CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceIDs(cl_platform_id platform, + cl_device_type device_type, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0 +{ + // initialize the platforms (in case they have not been already) + khrIcdInitialize(); + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(platform, CL_INVALID_PLATFORM); + return platform->dispatch->clGetDeviceIDs( + platform, + device_type, + num_entries, + devices, + num_devices); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceInfo( + cl_device_id device, + cl_device_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(device, CL_INVALID_DEVICE); + return device->dispatch->clGetDeviceInfo( + device, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clCreateSubDevices(cl_device_id in_device, + const cl_device_partition_property * properties, + cl_uint num_entries, + cl_device_id * out_devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(in_device, CL_INVALID_DEVICE); + return in_device->dispatch->clCreateSubDevices( + in_device, + properties, + num_entries, + out_devices, + num_devices); +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainDevice(cl_device_id device) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(device, CL_INVALID_DEVICE); + return device->dispatch->clRetainDevice(device); +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseDevice(cl_device_id device) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(device, CL_INVALID_DEVICE); + return device->dispatch->clReleaseDevice(device); +} + +// Context APIs +CL_API_ENTRY cl_context CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + // initialize the platforms (in case they have not been already) + khrIcdInitialize(); + if (!num_devices || !devices) + { + if (errcode_ret) + { + *errcode_ret = CL_INVALID_VALUE; + } + return NULL; + } + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(devices[0], CL_INVALID_DEVICE); + return devices[0]->dispatch->clCreateContext( + properties, + num_devices, + devices, + pfn_notify, + user_data, + errcode_ret); +} + +CL_API_ENTRY cl_context CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + cl_platform_id platform = NULL; + + // initialize the platforms (in case they have not been already) + khrIcdInitialize(); + + // determine the platform to use from the properties specified + khrIcdContextPropertiesGetPlatform(properties, &platform); + + // validate the platform handle and dispatch + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(platform, CL_INVALID_PLATFORM); + return platform->dispatch->clCreateContextFromType( + properties, + device_type, + pfn_notify, + user_data, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainContext(cl_context context) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(context, CL_INVALID_CONTEXT); + return context->dispatch->clRetainContext(context); +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseContext(cl_context context) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(context, CL_INVALID_CONTEXT); + return context->dispatch->clReleaseContext(context); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetContextInfo(cl_context context, + cl_context_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(context, CL_INVALID_CONTEXT); + return context->dispatch->clGetContextInfo( + context, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +// Command Queue APIs +CL_API_ENTRY cl_command_queue CL_API_CALL +clCreateCommandQueue(cl_context context, + cl_device_id device, + cl_command_queue_properties properties, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateCommandQueue( + context, + device, + properties, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainCommandQueue(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clRetainCommandQueue(command_queue); +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseCommandQueue(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clReleaseCommandQueue(command_queue); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetCommandQueueInfo(cl_command_queue command_queue, + cl_command_queue_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clGetCommandQueueInfo( + command_queue, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +// Memory Object APIs +CL_API_ENTRY cl_mem CL_API_CALL +clCreateBuffer(cl_context context, + cl_mem_flags flags, + size_t size, + void * host_ptr, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateBuffer( + context, + flags, + size, + host_ptr, + errcode_ret); +} + +CL_API_ENTRY cl_mem CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateImage( + context, + flags, + image_format, + image_desc, + host_ptr, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainMemObject(cl_mem memobj) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(memobj, CL_INVALID_MEM_OBJECT); + return memobj->dispatch->clRetainMemObject(memobj); +} + + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseMemObject(cl_mem memobj) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(memobj, CL_INVALID_MEM_OBJECT); + return memobj->dispatch->clReleaseMemObject(memobj); +} + +CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(context, CL_INVALID_CONTEXT); + return context->dispatch->clGetSupportedImageFormats( + context, + flags, + image_type, + num_entries, + image_formats, + num_image_formats); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetMemObjectInfo(cl_mem memobj, + cl_mem_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(memobj, CL_INVALID_MEM_OBJECT); + return memobj->dispatch->clGetMemObjectInfo( + memobj, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetImageInfo(cl_mem image, + cl_image_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(image, CL_INVALID_MEM_OBJECT); + return image->dispatch->clGetImageInfo( + image, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +// Sampler APIs +CL_API_ENTRY cl_sampler CL_API_CALL +clCreateSampler(cl_context context, + cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateSampler( + context, + normalized_coords, + addressing_mode, + filter_mode, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainSampler(cl_sampler sampler) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(sampler, CL_INVALID_SAMPLER); + return sampler->dispatch->clRetainSampler(sampler); +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseSampler(cl_sampler sampler) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(sampler, CL_INVALID_SAMPLER); + return sampler->dispatch->clReleaseSampler(sampler); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetSamplerInfo(cl_sampler sampler, + cl_sampler_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(sampler, CL_INVALID_SAMPLER); + return sampler->dispatch->clGetSamplerInfo( + sampler, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +// Program Object APIs +CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithSource(cl_context context, + cl_uint count, + const char ** strings, + const size_t * lengths, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateProgramWithSource( + context, + count, + strings, + lengths, + errcode_ret); +} + +CL_API_ENTRY cl_program CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateProgramWithBinary( + context, + num_devices, + device_list, + lengths, + binaries, + binary_status, + errcode_ret); +} + +CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithBuiltInKernels(cl_context context, + cl_uint num_devices, + const cl_device_id * device_list, + const char * kernel_names, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateProgramWithBuiltInKernels( + context, + num_devices, + device_list, + kernel_names, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainProgram(cl_program program) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(program, CL_INVALID_PROGRAM); + return program->dispatch->clRetainProgram(program); +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseProgram(cl_program program) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(program, CL_INVALID_PROGRAM); + return program->dispatch->clReleaseProgram(program); +} + +CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(program, CL_INVALID_PROGRAM); + return program->dispatch->clBuildProgram( + program, + num_devices, + device_list, + options, + pfn_notify, + user_data); +} + +CL_API_ENTRY cl_int CL_API_CALL +clCompileProgram(cl_program program, + cl_uint num_devices, + const cl_device_id * device_list, + const char * options, + cl_uint num_input_headers, + const cl_program * input_headers, + const char ** header_include_names, + void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data), + void * user_data) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(program, CL_INVALID_PROGRAM); + return program->dispatch->clCompileProgram( + program, + num_devices, + device_list, + options, + num_input_headers, + input_headers, + header_include_names, + pfn_notify, + user_data); +} + +CL_API_ENTRY cl_program CL_API_CALL +clLinkProgram(cl_context context, + cl_uint num_devices, + const cl_device_id * device_list, + const char * options, + cl_uint num_input_programs, + const cl_program * input_programs, + void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data), + void * user_data, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clLinkProgram( + context, + num_devices, + device_list, + options, + num_input_programs, + input_programs, + pfn_notify, + user_data, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clSetProgramSpecializationConstant(cl_program program, + cl_uint spec_id, + size_t spec_size, + const void* spec_value) CL_API_SUFFIX__VERSION_2_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(program, CL_INVALID_PROGRAM); + return program->dispatch->clSetProgramSpecializationConstant( + program, + spec_id, + spec_size, + spec_value); +} + +CL_API_ENTRY cl_int CL_API_CALL +clSetProgramReleaseCallback(cl_program program, + void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data), + void * user_data) CL_API_SUFFIX__VERSION_2_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(program, CL_INVALID_PROGRAM); + return program->dispatch->clSetProgramReleaseCallback( + program, + pfn_notify, + user_data); +} + +CL_API_ENTRY cl_int CL_API_CALL +clUnloadPlatformCompiler(cl_platform_id platform) CL_API_SUFFIX__VERSION_1_2 +{ + // initialize the platforms (in case they have not been already) + khrIcdInitialize(); + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(platform, CL_INVALID_PLATFORM); + return platform->dispatch->clUnloadPlatformCompiler(platform); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetProgramInfo(cl_program program, + cl_program_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(program, CL_INVALID_PROGRAM); + return program->dispatch->clGetProgramInfo( + program, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(program, CL_INVALID_PROGRAM); + return program->dispatch->clGetProgramBuildInfo( + program, + device, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +// Kernel Object APIs +CL_API_ENTRY cl_kernel CL_API_CALL +clCreateKernel(cl_program program, + const char * kernel_name, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(program, CL_INVALID_PROGRAM); + return program->dispatch->clCreateKernel( + program, + kernel_name, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clCreateKernelsInProgram(cl_program program, + cl_uint num_kernels, + cl_kernel * kernels, + cl_uint * num_kernels_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(program, CL_INVALID_PROGRAM); + return program->dispatch->clCreateKernelsInProgram( + program, + num_kernels, + kernels, + num_kernels_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainKernel(cl_kernel kernel) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(kernel, CL_INVALID_KERNEL); + return kernel->dispatch->clRetainKernel(kernel); +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseKernel(cl_kernel kernel) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(kernel, CL_INVALID_KERNEL); + return kernel->dispatch->clReleaseKernel(kernel); +} + +CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArg(cl_kernel kernel, + cl_uint arg_index, + size_t arg_size, + const void * arg_value) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(kernel, CL_INVALID_KERNEL); + return kernel->dispatch->clSetKernelArg( + kernel, + arg_index, + arg_size, + arg_value); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetKernelInfo(cl_kernel kernel, + cl_kernel_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(kernel, CL_INVALID_KERNEL); + return kernel->dispatch->clGetKernelInfo( + kernel, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetKernelArgInfo(cl_kernel kernel, + cl_uint arg_indx, + cl_kernel_arg_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(kernel, CL_INVALID_KERNEL); + return kernel->dispatch->clGetKernelArgInfo( + kernel, + arg_indx, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(kernel, CL_INVALID_KERNEL); + return kernel->dispatch->clGetKernelWorkGroupInfo( + kernel, + device, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +// Event Object APIs +CL_API_ENTRY cl_int CL_API_CALL +clWaitForEvents(cl_uint num_events, + const cl_event * event_list) CL_API_SUFFIX__VERSION_1_0 +{ + if (!num_events || !event_list) + { + return CL_INVALID_VALUE; + } + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(event_list[0], CL_INVALID_EVENT); + return event_list[0]->dispatch->clWaitForEvents( + num_events, + event_list); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetEventInfo(cl_event event, + cl_event_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(event, CL_INVALID_EVENT); + return event->dispatch->clGetEventInfo( + event, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainEvent(cl_event event) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(event, CL_INVALID_EVENT); + return event->dispatch->clRetainEvent(event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseEvent(cl_event event) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(event, CL_INVALID_EVENT); + return event->dispatch->clReleaseEvent(event); +} + +// Profiling APIs +CL_API_ENTRY cl_int CL_API_CALL +clGetEventProfilingInfo(cl_event event, + cl_profiling_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(event, CL_INVALID_EVENT); + return event->dispatch->clGetEventProfilingInfo( + event, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +// Flush and Finish APIs +CL_API_ENTRY cl_int CL_API_CALL +clFlush(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clFlush(command_queue); +} + +CL_API_ENTRY cl_int CL_API_CALL +clFinish(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clFinish(command_queue); +} + +// Enqueued Commands APIs +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadBuffer(cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_read, + size_t offset, + size_t cb, + void * ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueReadBuffer( + command_queue, + buffer, + blocking_read, + offset, + cb, + ptr, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadBufferRect( + cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_read, + const size_t * buffer_origin, + const size_t * host_origin, + const size_t * region, + size_t buffer_row_pitch, + size_t buffer_slice_pitch, + size_t host_row_pitch, + size_t host_slice_pitch, + void * ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueReadBufferRect( + command_queue, + buffer, + blocking_read, + buffer_origin, + host_origin, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteBuffer(cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_write, + size_t offset, + size_t cb, + const void * ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueWriteBuffer( + command_queue, + buffer, + blocking_write, + offset, + cb, + ptr, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteBufferRect( + cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_read, + const size_t * buffer_origin, + const size_t * host_origin, + const size_t * region, + size_t buffer_row_pitch, + size_t buffer_slice_pitch, + size_t host_row_pitch, + size_t host_slice_pitch, + const void * ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueWriteBufferRect( + command_queue, + buffer, + blocking_read, + buffer_origin, + host_origin, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueFillBuffer(cl_command_queue command_queue, + cl_mem buffer, + const void * pattern, + size_t pattern_size, + size_t offset, + size_t cb, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueFillBuffer( + command_queue, + buffer, + pattern, + pattern_size, + offset, + cb, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBuffer(cl_command_queue command_queue, + cl_mem src_buffer, + cl_mem dst_buffer, + size_t src_offset, + size_t dst_offset, + size_t cb, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueCopyBuffer( + command_queue, + src_buffer, + dst_buffer, + src_offset, + dst_offset, + cb, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBufferRect( + cl_command_queue command_queue, + cl_mem src_buffer, + cl_mem dst_buffer, + const size_t * src_origin, + const size_t * dst_origin, + const size_t * region, + size_t src_row_pitch, + size_t src_slice_pitch, + size_t dst_row_pitch, + size_t dst_slice_pitch, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueCopyBufferRect( + command_queue, + src_buffer, + dst_buffer, + src_origin, + dst_origin, + region, + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadImage(cl_command_queue command_queue, + cl_mem image, + cl_bool blocking_read, + const size_t * origin, + const size_t * region, + 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) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueReadImage( + command_queue, + image, + blocking_read, + origin, + region, + row_pitch, + slice_pitch, + ptr, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteImage(cl_command_queue command_queue, + cl_mem image, + cl_bool blocking_write, + const size_t * origin, + const size_t * region, + 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) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueWriteImage( + command_queue, + image, + blocking_write, + origin, + region, + input_row_pitch, + input_slice_pitch, + ptr, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueFillImage(cl_command_queue command_queue, + cl_mem image, + const void * fill_color, + const size_t origin[3], + const size_t region[3], + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueFillImage( + command_queue, + image, + fill_color, + origin, + region, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyImage(cl_command_queue command_queue, + cl_mem src_image, + cl_mem dst_image, + const size_t * src_origin, + const size_t * dst_origin, + const size_t * region, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueCopyImage( + command_queue, + src_image, + dst_image, + src_origin, + dst_origin, + region, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyImageToBuffer(cl_command_queue command_queue, + cl_mem src_image, + cl_mem dst_buffer, + const size_t * src_origin, + const size_t * region, + size_t dst_offset, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueCopyImageToBuffer( + command_queue, + src_image, + dst_buffer, + src_origin, + region, + dst_offset, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBufferToImage(cl_command_queue command_queue, + cl_mem src_buffer, + cl_mem dst_image, + size_t src_offset, + const size_t * dst_origin, + const size_t * region, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueCopyBufferToImage( + command_queue, + src_buffer, + dst_image, + src_offset, + dst_origin, + region, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY void * CL_API_CALL +clEnqueueMapBuffer(cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_map, + cl_map_flags map_flags, + size_t offset, + size_t cb, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueMapBuffer( + command_queue, + buffer, + blocking_map, + map_flags, + offset, + cb, + num_events_in_wait_list, + event_wait_list, + event, + errcode_ret); +} + +CL_API_ENTRY void * CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueMapImage( + 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); +} + +CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueUnmapMemObject( + command_queue, + memobj, + mapped_ptr, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMigrateMemObjects(cl_command_queue command_queue, + cl_uint num_mem_objects, + const cl_mem * mem_objects, + cl_mem_migration_flags flags, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueMigrateMemObjects( + command_queue, + num_mem_objects, + mem_objects, + flags, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueNDRangeKernel( + command_queue, + kernel, + work_dim, + global_work_offset, + global_work_size, + local_work_size, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueTask(cl_command_queue command_queue, + cl_kernel kernel, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueTask( + command_queue, + kernel, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueNativeKernel(cl_command_queue command_queue, + void (CL_CALLBACK * user_func)(void *), + void * args, + size_t cb_args, + cl_uint num_mem_objects, + const cl_mem * mem_list, + const void ** args_mem_loc, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueNativeKernel( + command_queue, + user_func, + args, + cb_args, + num_mem_objects, + mem_list, + args_mem_loc, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMarkerWithWaitList(cl_command_queue command_queue, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueMarkerWithWaitList( + command_queue, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueBarrierWithWaitList(cl_command_queue command_queue, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueBarrierWithWaitList( + command_queue, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY void * CL_API_CALL +clGetExtensionFunctionAddressForPlatform(cl_platform_id platform, + const char * function_name) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(function_name, NULL); + + // make sure the ICD is initialized + khrIcdInitialize(); + + // return any ICD-aware extensions + + // Most extensions, including multi-vendor KHR and EXT extensions, + // do not need to be ICD-aware and do not require any ICD loader + // modifications. The KHR and EXT extensions below were added for + // backwards compatibility only. + #define CL_COMMON_EXTENSION_ENTRYPOINT_ADD(name) if (!strcmp(function_name, #name) ) return (void *)(size_t)&name + + // Functions supporting the creation of OpenCL Memory Objects + // from OpenGL Objects (cl_apple_gl_sharing, cl_khr_gl_sharing) + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromGLBuffer); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromGLTexture); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromGLTexture2D); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromGLTexture3D); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromGLRenderbuffer); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetGLObjectInfo); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetGLTextureInfo); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueAcquireGLObjects); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueReleaseGLObjects); + + // cl_khr_gl_sharing + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetGLContextInfoKHR); + + // cl_khr_gl_event + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateEventFromGLsyncKHR); + +#if defined(_WIN32) + // cl_khr_d3d10_sharing + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetDeviceIDsFromD3D10KHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromD3D10BufferKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromD3D10Texture2DKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromD3D10Texture3DKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueAcquireD3D10ObjectsKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueReleaseD3D10ObjectsKHR); + // cl_khr_d3d11_sharing + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetDeviceIDsFromD3D11KHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromD3D11BufferKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromD3D11Texture2DKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromD3D11Texture3DKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueAcquireD3D11ObjectsKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueReleaseD3D11ObjectsKHR); + // cl_khr_dx9_media_sharing + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetDeviceIDsFromDX9MediaAdapterKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromDX9MediaSurfaceKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueAcquireDX9MediaSurfacesKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueReleaseDX9MediaSurfacesKHR); +#endif + + // cl_ext_device_fission + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateSubDevicesEXT); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clRetainDeviceEXT); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clReleaseDeviceEXT); + + /* cl_khr_egl_image */ + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromEGLImageKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueAcquireEGLObjectsKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueReleaseEGLObjectsKHR); + + /* cl_khr_egl_event */ + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateEventFromEGLSyncKHR); + + /* cl_khr_sub_groups */ + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetKernelSubGroupInfoKHR); + + #undef CL_COMMON_EXTENSION_ENTRYPOINT_ADD + + // This is not an ICD-aware extension, so call into the implementation + // to get the extension function address. + + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(platform, NULL); + return platform->dispatch->clGetExtensionFunctionAddressForPlatform( + platform, + function_name); +} + +// Deprecated APIs +CL_API_ENTRY cl_int CL_API_CALL +clSetCommandQueueProperty(cl_command_queue command_queue, + cl_command_queue_properties properties, + cl_bool enable, + cl_command_queue_properties * old_properties) CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clSetCommandQueueProperty( + command_queue, + properties, + enable, + old_properties); +} + +CL_API_ENTRY cl_int CL_API_CALL +clCreateSubDevicesEXT( + cl_device_id in_device, + const cl_device_partition_property_ext * partition_properties, + cl_uint num_entries, + cl_device_id * out_devices, + cl_uint * num_devices) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(in_device, CL_INVALID_DEVICE); + return in_device->dispatch->clCreateSubDevicesEXT( + in_device, + partition_properties, + num_entries, + out_devices, + num_devices); +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainDeviceEXT(cl_device_id device) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(device, CL_INVALID_DEVICE); + return device->dispatch->clRetainDeviceEXT(device); +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseDeviceEXT(cl_device_id device) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(device, CL_INVALID_DEVICE); + return device->dispatch->clReleaseDeviceEXT(device); +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateImage2D(cl_context context, + cl_mem_flags flags, + const cl_image_format * image_format, + size_t image_width, + size_t image_height, + size_t image_row_pitch, + void * host_ptr, + cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateImage2D( + context, + flags, + image_format, + image_width, + image_height, + image_row_pitch, + host_ptr, + errcode_ret); +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateImage3D(cl_context context, + cl_mem_flags flags, + const cl_image_format * image_format, + size_t image_width, + size_t image_height, + size_t image_depth, + size_t image_row_pitch, + size_t image_slice_pitch, + void * host_ptr, + cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateImage3D( + context, + flags, + image_format, + image_width, + image_height, + image_depth, + image_row_pitch, + image_slice_pitch, + host_ptr, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clUnloadCompiler(void) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +{ + return CL_SUCCESS; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMarker(cl_command_queue command_queue, + cl_event * event) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueMarker( + command_queue, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWaitForEvents(cl_command_queue command_queue, + cl_uint num_events, + const cl_event * event_list) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueWaitForEvents( + command_queue, + num_events, + event_list); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueBarrier(cl_command_queue command_queue) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueBarrier(command_queue); +} + +CL_API_ENTRY void * CL_API_CALL +clGetExtensionFunctionAddress(const char *function_name) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +{ + size_t function_name_length = 0; + KHRicdVendor* vendor = NULL; + + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(function_name, NULL); + + // make sure the ICD is initialized + khrIcdInitialize(); + function_name_length = strlen(function_name); + + // return any ICD-aware extensions + + // Most extensions, including multi-vendor KHR and EXT extensions, + // do not need to be ICD-aware and do not require any ICD loader + // modifications. The KHR and EXT extensions below were added for + // backwards compatibility only. + #define CL_COMMON_EXTENSION_ENTRYPOINT_ADD(name) if (!strcmp(function_name, #name) ) return (void *)(size_t)&name + + // Functions supporting the creation of OpenCL Memory Objects + // from OpenGL Objects (cl_apple_gl_sharing, cl_khr_gl_sharing) + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromGLBuffer); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromGLTexture); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromGLTexture2D); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromGLTexture3D); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromGLRenderbuffer); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetGLObjectInfo); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetGLTextureInfo); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueAcquireGLObjects); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueReleaseGLObjects); + + // cl_khr_gl_sharing + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetGLContextInfoKHR); + + // cl_khr_gl_event + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateEventFromGLsyncKHR); + +#if defined(_WIN32) + // cl_khr_d3d10_sharing + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetDeviceIDsFromD3D10KHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromD3D10BufferKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromD3D10Texture2DKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromD3D10Texture3DKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueAcquireD3D10ObjectsKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueReleaseD3D10ObjectsKHR); + // cl_khr_d3d11_sharing + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetDeviceIDsFromD3D11KHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromD3D11BufferKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromD3D11Texture2DKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromD3D11Texture3DKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueAcquireD3D11ObjectsKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueReleaseD3D11ObjectsKHR); + // cl_khr_dx9_media_sharing + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetDeviceIDsFromDX9MediaAdapterKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromDX9MediaSurfaceKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueAcquireDX9MediaSurfacesKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueReleaseDX9MediaSurfacesKHR); +#endif + + // cl_ext_device_fission + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateSubDevicesEXT); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clRetainDeviceEXT); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clReleaseDeviceEXT); + + /* cl_khr_egl_image */ + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateFromEGLImageKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueAcquireEGLObjectsKHR); + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clEnqueueReleaseEGLObjectsKHR); + + /* cl_khr_egl_event */ + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clCreateEventFromEGLSyncKHR); + + /* cl_khr_sub_groups */ + CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetKernelSubGroupInfoKHR); + + #undef CL_COMMON_EXTENSION_ENTRYPOINT_ADD + + // fall back to vendor extension detection + for (vendor = khrIcdVendors; vendor; vendor = vendor->next) + { + size_t vendor_suffix_length = strlen(vendor->suffix); + if (vendor_suffix_length <= function_name_length && vendor_suffix_length > 0) + { + const char *function_suffix = function_name+function_name_length-vendor_suffix_length; + if (!strcmp(function_suffix, vendor->suffix) ) + { + return vendor->clGetExtensionFunctionAddress(function_name); + } + } + } + return NULL; +} + +// GL and other APIs +CL_API_ENTRY cl_mem CL_API_CALL clCreateFromGLBuffer( + cl_context context, + cl_mem_flags flags, + cl_GLuint bufobj, + int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateFromGLBuffer( + context, + flags, + bufobj, + errcode_ret); +} + +CL_API_ENTRY cl_mem CL_API_CALL clCreateFromGLTexture( + cl_context context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texture, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateFromGLTexture( + context, + flags, + target, + miplevel, + texture, + errcode_ret); +} + +CL_API_ENTRY cl_mem CL_API_CALL clCreateFromGLTexture2D( + cl_context context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texture, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateFromGLTexture2D( + context, + flags, + target, + miplevel, + texture, + errcode_ret); +} + +CL_API_ENTRY cl_mem CL_API_CALL clCreateFromGLTexture3D( + cl_context context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texture, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateFromGLTexture3D( + context, + flags, + target, + miplevel, + texture, + errcode_ret); +} + +CL_API_ENTRY cl_mem CL_API_CALL clCreateFromGLRenderbuffer( + cl_context context, + cl_mem_flags flags, + cl_GLuint renderbuffer, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateFromGLRenderbuffer( + context, + flags, + renderbuffer, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL clGetGLObjectInfo( + cl_mem memobj, + cl_gl_object_type * gl_object_type, + cl_GLuint * gl_object_name) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(memobj, CL_INVALID_MEM_OBJECT); + return memobj->dispatch->clGetGLObjectInfo( + memobj, + gl_object_type, + gl_object_name); +} + +CL_API_ENTRY cl_int CL_API_CALL clGetGLTextureInfo( + cl_mem memobj, + cl_gl_texture_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(memobj, CL_INVALID_MEM_OBJECT); + return memobj->dispatch->clGetGLTextureInfo( + memobj, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL clEnqueueAcquireGLObjects( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueAcquireGLObjects( + command_queue, + num_objects, + mem_objects, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL clEnqueueReleaseGLObjects( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueReleaseGLObjects( + command_queue, + num_objects, + mem_objects, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL clGetGLContextInfoKHR( + const cl_context_properties *properties, + cl_gl_context_info param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_platform_id platform = NULL; + + // initialize the platforms (in case they have not been already) + khrIcdInitialize(); + + // determine the platform to use from the properties specified + khrIcdContextPropertiesGetPlatform(properties, &platform); + + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(platform, CL_INVALID_PLATFORM); + return platform->dispatch->clGetGLContextInfoKHR( + properties, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +CL_API_ENTRY cl_event CL_API_CALL clCreateEventFromGLsyncKHR( + cl_context context, + cl_GLsync sync, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateEventFromGLsyncKHR( + context, + sync, + errcode_ret); +} + +#if defined(_WIN32) +/* + * + * cl_d3d10_sharing_khr + * + */ + +CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceIDsFromD3D10KHR( + cl_platform_id platform, + cl_d3d10_device_source_khr d3d_device_source, + void *d3d_object, + cl_d3d10_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id *devices, + cl_uint *num_devices) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(platform, CL_INVALID_PLATFORM); + return platform->dispatch->clGetDeviceIDsFromD3D10KHR( + platform, + d3d_device_source, + d3d_object, + d3d_device_set, + num_entries, + devices, + num_devices); +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromD3D10BufferKHR( + cl_context context, + cl_mem_flags flags, + ID3D10Buffer *resource, + cl_int *errcode_ret) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateFromD3D10BufferKHR( + context, + flags, + resource, + errcode_ret); +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromD3D10Texture2DKHR( + cl_context context, + cl_mem_flags flags, + ID3D10Texture2D * resource, + UINT subresource, + cl_int * errcode_ret) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateFromD3D10Texture2DKHR( + context, + flags, + resource, + subresource, + errcode_ret); +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromD3D10Texture3DKHR( + cl_context context, + cl_mem_flags flags, + ID3D10Texture3D *resource, + UINT subresource, + cl_int *errcode_ret) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateFromD3D10Texture3DKHR( + context, + flags, + resource, + subresource, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireD3D10ObjectsKHR( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem *mem_objects, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueAcquireD3D10ObjectsKHR( + command_queue, + num_objects, + mem_objects, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseD3D10ObjectsKHR( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem *mem_objects, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueReleaseD3D10ObjectsKHR( + command_queue, + num_objects, + mem_objects, + num_events_in_wait_list, + event_wait_list, + event); +} + +/* + * + * cl_d3d11_sharing_khr + * + */ + +CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceIDsFromD3D11KHR( + cl_platform_id platform, + cl_d3d11_device_source_khr d3d_device_source, + void * d3d_object, + cl_d3d11_device_set_khr d3d_device_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(platform, CL_INVALID_PLATFORM); + return platform->dispatch->clGetDeviceIDsFromD3D11KHR( + platform, + d3d_device_source, + d3d_object, + d3d_device_set, + num_entries, + devices, + num_devices); +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromD3D11BufferKHR( + cl_context context, + cl_mem_flags flags, + ID3D11Buffer * resource, + cl_int * errcode_ret) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateFromD3D11BufferKHR( + context, + flags, + resource, + errcode_ret); +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromD3D11Texture2DKHR( + cl_context context, + cl_mem_flags flags, + ID3D11Texture2D * resource, + UINT subresource, + cl_int * errcode_ret) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateFromD3D11Texture2DKHR( + context, + flags, + resource, + subresource, + errcode_ret); +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromD3D11Texture3DKHR( + cl_context context, + cl_mem_flags flags, + ID3D11Texture3D * resource, + UINT subresource, + cl_int * errcode_ret) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateFromD3D11Texture3DKHR( + context, + flags, + resource, + subresource, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireD3D11ObjectsKHR( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueAcquireD3D11ObjectsKHR( + command_queue, + num_objects, + mem_objects, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseD3D11ObjectsKHR( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueReleaseD3D11ObjectsKHR( + command_queue, + num_objects, + mem_objects, + num_events_in_wait_list, + event_wait_list, + event); +} + +/* + * + * cl_khr_dx9_media_sharing + * + */ + +CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceIDsFromDX9MediaAdapterKHR( + cl_platform_id platform, + cl_uint num_media_adapters, + cl_dx9_media_adapter_type_khr * media_adapters_type, + void * media_adapters, + cl_dx9_media_adapter_set_khr media_adapter_set, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(platform, CL_INVALID_PLATFORM); + return platform->dispatch->clGetDeviceIDsFromDX9MediaAdapterKHR( + platform, + num_media_adapters, + media_adapters_type, + media_adapters, + media_adapter_set, + num_entries, + devices, + num_devices); +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromDX9MediaSurfaceKHR( + cl_context context, + cl_mem_flags flags, + cl_dx9_media_adapter_type_khr adapter_type, + void * surface_info, + cl_uint plane, + cl_int * errcode_ret) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateFromDX9MediaSurfaceKHR( + context, + flags, + adapter_type, + surface_info, + plane, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireDX9MediaSurfacesKHR( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueAcquireDX9MediaSurfacesKHR( + command_queue, + num_objects, + mem_objects, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseDX9MediaSurfacesKHR( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueReleaseDX9MediaSurfacesKHR( + command_queue, + num_objects, + mem_objects, + num_events_in_wait_list, + event_wait_list, + event); +} + +#endif + +CL_API_ENTRY cl_int CL_API_CALL +clSetEventCallback( + cl_event event, + cl_int command_exec_callback_type, + void (CL_CALLBACK *pfn_notify)(cl_event, cl_int, void *), + void *user_data) CL_API_SUFFIX__VERSION_1_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(event, CL_INVALID_EVENT); + return event->dispatch->clSetEventCallback( + event, + command_exec_callback_type, + pfn_notify, + user_data); +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateSubBuffer( + cl_mem buffer, + cl_mem_flags flags, + cl_buffer_create_type buffer_create_type, + const void * buffer_create_info, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(buffer, CL_INVALID_MEM_OBJECT); + return buffer->dispatch->clCreateSubBuffer( + buffer, + flags, + buffer_create_type, + buffer_create_info, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clSetMemObjectDestructorCallback( + cl_mem memobj, + void (CL_CALLBACK * pfn_notify)( cl_mem, void*), + void * user_data ) CL_API_SUFFIX__VERSION_1_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(memobj, CL_INVALID_MEM_OBJECT); + return memobj->dispatch->clSetMemObjectDestructorCallback( + memobj, + pfn_notify, + user_data); +} + +CL_API_ENTRY cl_event CL_API_CALL +clCreateUserEvent( + cl_context context, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateUserEvent( + context, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clSetUserEventStatus( + cl_event event, + cl_int execution_status) CL_API_SUFFIX__VERSION_1_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(event, CL_INVALID_EVENT); + return event->dispatch->clSetUserEventStatus( + event, + execution_status); +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromEGLImageKHR( + cl_context context, + CLeglDisplayKHR display, + CLeglImageKHR image, + cl_mem_flags flags, + const cl_egl_image_properties_khr *properties, + cl_int *errcode_ret) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateFromEGLImageKHR( + context, + display, + image, + flags, + properties, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireEGLObjectsKHR( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem *mem_objects, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueAcquireEGLObjectsKHR( + command_queue, + num_objects, + mem_objects, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseEGLObjectsKHR( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem *mem_objects, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueReleaseEGLObjectsKHR( + command_queue, + num_objects, + mem_objects, + num_events_in_wait_list, + event_wait_list, + event); +} + +/* cl_khr_egl_event */ +CL_API_ENTRY cl_event CL_API_CALL +clCreateEventFromEGLSyncKHR( + cl_context context, + CLeglSyncKHR sync, + CLeglDisplayKHR display, + cl_int *errcode_ret) +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateEventFromEGLSyncKHR( + context, + sync, + display, + errcode_ret); +} + +CL_API_ENTRY cl_command_queue CL_API_CALL +clCreateCommandQueueWithProperties( + cl_context context, + cl_device_id device, + const cl_queue_properties * properties, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateCommandQueueWithProperties( + context, + device, + properties, + errcode_ret); +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreatePipe( + cl_context context, + cl_mem_flags flags, + cl_uint pipe_packet_size, + cl_uint pipe_max_packets, + const cl_pipe_properties * properties, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreatePipe( + context, + flags, + pipe_packet_size, + pipe_max_packets, + properties, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetPipeInfo( + cl_mem pipe, + cl_pipe_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_2_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(pipe, CL_INVALID_MEM_OBJECT); + return pipe->dispatch->clGetPipeInfo( + pipe, + param_name, + param_value_size, + param_value, + param_value_size_ret); +} + +CL_API_ENTRY void * CL_API_CALL +clSVMAlloc( + cl_context context, + cl_svm_mem_flags flags, + size_t size, + cl_uint alignment) CL_API_SUFFIX__VERSION_2_0 +{ + if (!context) { + return NULL; + } + return context->dispatch->clSVMAlloc( + context, + flags, + size, + alignment); +} + +CL_API_ENTRY void CL_API_CALL +clSVMFree( + cl_context context, + void * svm_pointer) CL_API_SUFFIX__VERSION_2_0 +{ + if (!context || !svm_pointer) { + return; + } + context->dispatch->clSVMFree( + context, + svm_pointer); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMFree( + cl_command_queue command_queue, + cl_uint num_svm_pointers, + void* svm_pointers[], + void (CL_CALLBACK* pfn_free_func)( + cl_command_queue queue, + cl_uint num_svm_pointers, + void* svm_pointers[], + void* user_data), + void* user_data, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event) CL_API_SUFFIX__VERSION_2_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueSVMFree( + command_queue, + num_svm_pointers, + svm_pointers, + pfn_free_func, + user_data, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemcpy( + cl_command_queue command_queue, + cl_bool blocking_copy, + void * dst_ptr, + const void * src_ptr, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_2_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueSVMMemcpy( + command_queue, + blocking_copy, + dst_ptr, + src_ptr, + size, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMemFill( + cl_command_queue command_queue, + void * svm_ptr, + const void * pattern, + size_t pattern_size, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_2_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueSVMMemFill( + command_queue, + svm_ptr, + pattern, + pattern_size, + size, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMap( + cl_command_queue command_queue, + cl_bool blocking_map, + cl_map_flags flags, + void * svm_ptr, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_2_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueSVMMap( + command_queue, + blocking_map, + flags, + svm_ptr, + size, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMUnmap( + cl_command_queue command_queue, + void * svm_ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_2_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueSVMUnmap( + command_queue, + svm_ptr, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_sampler CL_API_CALL +clCreateSamplerWithProperties( + cl_context context, + const cl_sampler_properties * sampler_properties, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateSamplerWithProperties( + context, + sampler_properties, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArgSVMPointer( + cl_kernel kernel, + cl_uint arg_index, + const void * arg_value) CL_API_SUFFIX__VERSION_2_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(kernel, CL_INVALID_KERNEL); + return kernel->dispatch->clSetKernelArgSVMPointer( + kernel, + arg_index, + arg_value); +} + +CL_API_ENTRY cl_int CL_API_CALL +clSetKernelExecInfo( + cl_kernel kernel, + cl_kernel_exec_info param_name, + size_t param_value_size, + const void * param_value) CL_API_SUFFIX__VERSION_2_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(kernel, CL_INVALID_KERNEL); + return kernel->dispatch->clSetKernelExecInfo( + kernel, + param_name, + param_value_size, + param_value); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetKernelSubGroupInfoKHR( + cl_kernel in_kernel, + cl_device_id in_device, + cl_kernel_sub_group_info param_name, + size_t input_value_size, + const void * input_value, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_EXT_SUFFIX__VERSION_2_0 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(in_kernel, CL_INVALID_KERNEL); + return in_kernel->dispatch->clGetKernelSubGroupInfoKHR( + in_kernel, + in_device, + param_name, + input_value_size, + input_value, + param_value_size, + param_value, + param_value_size_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clSetDefaultDeviceCommandQueue( + cl_context context, + cl_device_id device, + cl_command_queue command_queue) CL_API_SUFFIX__VERSION_2_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(context, CL_INVALID_CONTEXT); + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(device, CL_INVALID_DEVICE); + return context->dispatch->clSetDefaultDeviceCommandQueue( + context, + device, + command_queue); +} + +CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithIL( + cl_context context, + const void * il, + size_t length, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(context, CL_INVALID_CONTEXT); + return context->dispatch->clCreateProgramWithIL( + context, + il, + length, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetKernelSubGroupInfo( + cl_kernel kernel, + cl_device_id device, + cl_kernel_sub_group_info param_name, + size_t input_value_size, + const void * input_value, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_2_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(kernel, CL_INVALID_KERNEL); + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(device, CL_INVALID_DEVICE); + return kernel->dispatch->clGetKernelSubGroupInfo( + kernel, + device, + param_name, + input_value_size, + input_value, + param_value_size, + param_value, + param_value_size_ret); +} + +CL_API_ENTRY cl_kernel CL_API_CALL +clCloneKernel( + cl_kernel source_kernel, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(source_kernel, CL_INVALID_KERNEL); + return source_kernel->dispatch->clCloneKernel( + source_kernel, + errcode_ret); +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueSVMMigrateMem( + cl_command_queue command_queue, + cl_uint num_svm_pointers, + const void ** svm_pointers, + const size_t * sizes, + cl_mem_migration_flags flags, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_2_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(command_queue, CL_INVALID_COMMAND_QUEUE); + return command_queue->dispatch->clEnqueueSVMMigrateMem( + command_queue, + num_svm_pointers, + svm_pointers, + sizes, + flags, + num_events_in_wait_list, + event_wait_list, + event); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceAndHostTimer( + cl_device_id device, + cl_ulong * device_timestamp, + cl_ulong * host_timestamp) CL_API_SUFFIX__VERSION_2_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(device, CL_INVALID_DEVICE); + return device->dispatch->clGetDeviceAndHostTimer( + device, + device_timestamp, + host_timestamp); +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetHostTimer( + cl_device_id device, + cl_ulong * host_timestamp) CL_API_SUFFIX__VERSION_2_1 +{ + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(device, CL_INVALID_DEVICE); + return device->dispatch->clGetHostTimer( + device, + host_timestamp); +} + + diff --git a/opencl/khronos/icd/loader/icd_dispatch.h b/opencl/khronos/icd/loader/icd_dispatch.h new file mode 100644 index 0000000000..84a3e305a7 --- /dev/null +++ b/opencl/khronos/icd/loader/icd_dispatch.h @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2016-2019 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#ifndef _ICD_DISPATCH_H_ +#define _ICD_DISPATCH_H_ + +#ifndef CL_USE_DEPRECATED_OPENCL_1_0_APIS +#define CL_USE_DEPRECATED_OPENCL_1_0_APIS +#endif + +#ifndef CL_USE_DEPRECATED_OPENCL_1_1_APIS +#define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#endif + +#ifndef CL_USE_DEPRECATED_OPENCL_1_2_APIS +#define CL_USE_DEPRECATED_OPENCL_1_2_APIS +#endif + +#ifndef CL_USE_DEPRECATED_OPENCL_2_0_APIS +#define CL_USE_DEPRECATED_OPENCL_2_0_APIS +#endif + +// cl.h +#include + +// cl_gl.h and required files +#ifdef _WIN32 +#include +#include +#include +#include +#include +#include +#endif +#include +#include +#include +#include +#include + +/* + * + * vendor dispatch table structure + * + */ + +struct _cl_platform_id +{ + cl_icd_dispatch *dispatch; +}; + +struct _cl_device_id +{ + cl_icd_dispatch *dispatch; +}; + +struct _cl_context +{ + cl_icd_dispatch *dispatch; +}; + +struct _cl_command_queue +{ + cl_icd_dispatch *dispatch; +}; + +struct _cl_mem +{ + cl_icd_dispatch *dispatch; +}; + +struct _cl_program +{ + cl_icd_dispatch *dispatch; +}; + +struct _cl_kernel +{ + cl_icd_dispatch *dispatch; +}; + +struct _cl_event +{ + cl_icd_dispatch *dispatch; +}; + +struct _cl_sampler +{ + cl_icd_dispatch *dispatch; +}; + +#endif // _ICD_DISPATCH_H_ + diff --git a/opencl/khronos/icd/loader/icd_envvars.h b/opencl/khronos/icd/loader/icd_envvars.h new file mode 100644 index 0000000000..0d34d3d60c --- /dev/null +++ b/opencl/khronos/icd/loader/icd_envvars.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2016-2019 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#ifndef _ICD_ENVVARS_H_ +#define _ICD_ENVVARS_H_ + +char *khrIcd_getenv(const char *name); +char *khrIcd_secure_getenv(const char *name); +void khrIcd_free_getenv(char *val); + +#endif diff --git a/opencl/khronos/icd/loader/icd_platform.h b/opencl/khronos/icd/loader/icd_platform.h new file mode 100644 index 0000000000..b16d0dbe22 --- /dev/null +++ b/opencl/khronos/icd/loader/icd_platform.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016-2019 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#ifndef _ICD_PLATFORM_H_ +#define _ICD_PLATFORM_H_ + +#if defined(__linux__) || defined(__APPLE__) + +#define PATH_SEPARATOR ':' +#define DIRECTORY_SYMBOL '/' +#ifdef __ANDROID__ +#define ICD_VENDOR_PATH "/system/vendor/Khronos/OpenCL/vendors/"; +#else +#define ICD_VENDOR_PATH "/etc/OpenCL/vendors/"; +#endif // ANDROID + +#elif defined(_WIN32) + +#define PATH_SEPARATOR ';' +#define DIRECTORY_SYMBOL '\\' + +#endif + +#endif diff --git a/opencl/khronos/icd/loader/linux/icd_exports.map b/opencl/khronos/icd/loader/linux/icd_exports.map new file mode 100644 index 0000000000..c716a39248 --- /dev/null +++ b/opencl/khronos/icd/loader/linux/icd_exports.map @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2016-2019 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +OPENCL_1.0 { + global: + clBuildProgram; + clCreateBuffer; + clCreateCommandQueue; + clCreateContext; + clCreateContextFromType; + clCreateFromGLBuffer; + clCreateFromGLRenderbuffer; + clCreateFromGLTexture2D; + clCreateFromGLTexture3D; + clCreateImage2D; + clCreateImage3D; + clCreateKernel; + clCreateKernelsInProgram; + clCreateProgramWithBinary; + clCreateProgramWithSource; + clCreateSampler; + clEnqueueAcquireGLObjects; + clEnqueueBarrier; + clEnqueueCopyBuffer; + clEnqueueCopyBufferToImage; + clEnqueueCopyImage; + clEnqueueCopyImageToBuffer; + clEnqueueMapBuffer; + clEnqueueMapImage; + clEnqueueMarker; + clEnqueueNDRangeKernel; + clEnqueueNativeKernel; + clEnqueueReadBuffer; + clEnqueueReadImage; + clEnqueueReleaseGLObjects; + clEnqueueTask; + clEnqueueUnmapMemObject; + clEnqueueWaitForEvents; + clEnqueueWriteBuffer; + clEnqueueWriteImage; + clFinish; + clFlush; + clGetCommandQueueInfo; + clGetContextInfo; + clGetDeviceIDs; + clGetDeviceInfo; + clGetEventInfo; + clGetEventProfilingInfo; + clGetExtensionFunctionAddress; + clGetGLObjectInfo; + clGetGLTextureInfo; + clGetImageInfo; + clGetKernelInfo; + clGetKernelWorkGroupInfo; + clGetMemObjectInfo; + clGetPlatformIDs; + clGetPlatformInfo; + clGetProgramBuildInfo; + clGetProgramInfo; + clGetSamplerInfo; + clGetSupportedImageFormats; + clReleaseCommandQueue; + clReleaseContext; + clReleaseEvent; + clReleaseKernel; + clReleaseMemObject; + clReleaseProgram; + clReleaseSampler; + clRetainCommandQueue; + clRetainContext; + clRetainEvent; + clRetainKernel; + clRetainMemObject; + clRetainProgram; + clRetainSampler; + clSetCommandQueueProperty; + clSetKernelArg; + clUnloadCompiler; + clWaitForEvents; + + local: + /* Everything else is local to ICD. */ + *; +}; + +OPENCL_1.1 { + global: + clCreateSubBuffer; + clCreateUserEvent; + clEnqueueCopyBufferRect; + clEnqueueReadBufferRect; + clEnqueueWriteBufferRect; + clSetEventCallback; + clSetMemObjectDestructorCallback; + clSetUserEventStatus; +} OPENCL_1.0; + +OPENCL_1.2 { + global: + clCompileProgram; + clCreateFromGLTexture; + clCreateImage; + clCreateProgramWithBuiltInKernels; + clCreateSubDevices; + clEnqueueBarrierWithWaitList; + clEnqueueFillBuffer; + clEnqueueFillImage; + clEnqueueMarkerWithWaitList; + clEnqueueMigrateMemObjects; + clGetExtensionFunctionAddressForPlatform; + clGetKernelArgInfo; + clLinkProgram; + clReleaseDevice; + clRetainDevice; + clUnloadPlatformCompiler; +} OPENCL_1.1; + +OPENCL_2.0 { + global: + clCreateCommandQueueWithProperties; + clCreatePipe; + clGetPipeInfo; + clSVMAlloc; + clSVMFree; + clEnqueueSVMFree; + clEnqueueSVMMemcpy; + clEnqueueSVMMemFill; + clEnqueueSVMMap; + clEnqueueSVMUnmap; + clCreateSamplerWithProperties; + clSetKernelArgSVMPointer; + clSetKernelExecInfo; +} OPENCL_1.2; + +OPENCL_2.1 { + global: + clCloneKernel; + clCreateProgramWithIL; + clEnqueueSVMMigrateMem; + clGetDeviceAndHostTimer; + clGetHostTimer; + clGetKernelSubGroupInfo; + clSetDefaultDeviceCommandQueue; +} OPENCL_2.0; + +OPENCL_2.2 { + global: + clSetProgramReleaseCallback; + clSetProgramSpecializationConstant; +} OPENCL_2.1; diff --git a/opencl/khronos/icd/loader/linux/icd_linux.c b/opencl/khronos/icd/loader/linux/icd_linux.c new file mode 100644 index 0000000000..11693ecfd0 --- /dev/null +++ b/opencl/khronos/icd/loader/linux/icd_linux.c @@ -0,0 +1,194 @@ +/* Modifications Copyright(C) 2022 Advanced Micro Devices, Inc. + * All rights reserved. + */ + +/* + * Copyright (c) 2016-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#include "icd.h" +#include "icd_envvars.h" + +#include +#include +#include +#include +#include +#include +#include + +static pthread_once_t initialized = PTHREAD_ONCE_INIT; + +/* + * + * Vendor enumeration functions + * + */ + +// go through the list of vendors in the two configuration files +void khrIcdOsVendorsEnumerate(void) +{ + DIR *dir = NULL; + struct dirent *dirEntry = NULL; + char* vendorPath = ICD_VENDOR_PATH; + char* envPath = NULL; + + khrIcdVendorsEnumerateEnv(); + + envPath = khrIcd_secure_getenv("OCL_ICD_VENDORS"); + if (NULL != envPath) + { + vendorPath = envPath; + } + + dir = opendir(vendorPath); + if (NULL == dir) + { + KHR_ICD_TRACE("Failed to open path %s, continuing\n", vendorPath); + } + else + { + // attempt to load all files in the directory + for (dirEntry = readdir(dir); dirEntry; dirEntry = readdir(dir) ) + { + switch(dirEntry->d_type) + { + case DT_UNKNOWN: + case DT_REG: + case DT_LNK: + { + const char* extension = ".icd"; + FILE *fin = NULL; + char* fileName = NULL; + char* buffer = NULL; + long bufferSize = 0; + + // make sure the file name ends in .icd + if (strlen(extension) > strlen(dirEntry->d_name) ) + { + break; + } + if (strcmp(dirEntry->d_name + strlen(dirEntry->d_name) - strlen(extension), extension) ) + { + break; + } + + // allocate space for the full path of the vendor library name + fileName = malloc(strlen(dirEntry->d_name) + strlen(vendorPath) + 1); + if (!fileName) + { + KHR_ICD_TRACE("Failed allocate space for ICD file path\n"); + break; + } + sprintf(fileName, "%s%s", vendorPath, dirEntry->d_name); + + // open the file and read its contents + fin = fopen(fileName, "r"); + if (!fin) + { + free(fileName); + break; + } + fseek(fin, 0, SEEK_END); + bufferSize = ftell(fin); + + buffer = malloc(bufferSize+1); + if (!buffer) + { + free(fileName); + fclose(fin); + break; + } + memset(buffer, 0, bufferSize+1); + fseek(fin, 0, SEEK_SET); + if (bufferSize != (long)fread(buffer, 1, bufferSize, fin) ) + { + free(fileName); + free(buffer); + fclose(fin); + break; + } + // ignore a newline at the end of the file + if (buffer[bufferSize-1] == '\n') buffer[bufferSize-1] = '\0'; + + // load the string read from the file + khrIcdVendorAdd(buffer); + + free(fileName); + free(buffer); + fclose(fin); + } + break; + default: + break; + } + } + + closedir(dir); + + KHRicdVendor *vendorIterator; + for (vendorIterator = khrIcdVendors; vendorIterator; vendorIterator = vendorIterator->next) + { + if (vendorIterator->libName != NULL) + { + free(vendorIterator->libName); + vendorIterator->libName = NULL; + } + } + } + + if (NULL != envPath) + { + khrIcd_free_getenv(envPath); + } +} + +// go through the list of vendors only once +void khrIcdOsVendorsEnumerateOnce(void) +{ + pthread_once(&initialized, khrIcdOsVendorsEnumerate); +} + +/* + * + * Dynamic library loading functions + * + */ + +// dynamically load a library. returns NULL on failure +void *khrIcdOsLibraryLoad(const char *libraryName) +{ + void *retVal = dlopen (libraryName, RTLD_NOW); + + if (NULL == retVal) { + printf("dlerror: %s\n", dlerror()); + } + + return retVal; +} + +// get a function pointer from a loaded library. returns NULL on failure. +void *khrIcdOsLibraryGetFunctionAddress(void *library, const char *functionName) +{ + return dlsym(library, functionName); +} + +// unload a library +void khrIcdOsLibraryUnload(void *library) +{ + dlclose(library); +} diff --git a/opencl/khronos/icd/loader/linux/icd_linux_envvars.c b/opencl/khronos/icd/loader/linux/icd_linux_envvars.c new file mode 100644 index 0000000000..4af5a082d8 --- /dev/null +++ b/opencl/khronos/icd/loader/linux/icd_linux_envvars.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016-2019 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +// for secure_getenv(): +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include "icd_cmake_config.h" + +#include + +char *khrIcd_getenv(const char *name) { + // No allocation of memory necessary for Linux. + return getenv(name); +} + +char *khrIcd_secure_getenv(const char *name) { +#if defined(__APPLE__) + // Apple does not appear to have a secure getenv implementation. + // The main difference between secure getenv and getenv is that secure getenv + // returns NULL if the process is being run with elevated privileges by a normal user. + // The idea is to prevent the reading of malicious environment variables by a process + // that can do damage. + // This algorithm is derived from glibc code that sets an internal + // variable (__libc_enable_secure) if the process is running under setuid or setgid. + return geteuid() != getuid() || getegid() != getgid() ? NULL : khrIcd_getenv(name); +#else +// Linux +#ifdef HAVE_SECURE_GETENV + return secure_getenv(name); +#elif defined(HAVE___SECURE_GETENV) + return __secure_getenv(name); +#else +#pragma message( \ + "Warning: Falling back to non-secure getenv for environmental lookups! Consider" \ + " updating to a different libc.") + return khrIcd_getenv(name); +#endif +#endif +} + +void khrIcd_free_getenv(char *val) { + // No freeing of memory necessary for Linux, but we should at least touch + // val to get rid of compiler warnings. + (void)val; +} diff --git a/opencl/khronos/icd/loader/windows/OpenCL.def b/opencl/khronos/icd/loader/windows/OpenCL.def new file mode 100644 index 0000000000..98abc9b127 --- /dev/null +++ b/opencl/khronos/icd/loader/windows/OpenCL.def @@ -0,0 +1,162 @@ +; +; Copyright (c) 2016-2019 The Khronos Group Inc. +; +; Licensed under the Apache License, Version 2.0 (the "License"); +; you may not use this file except in compliance with the License. +; You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, +; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; See the License for the specific language governing permissions and +; limitations under the License. +; +; OpenCL is a trademark of Apple Inc. used under license by Khronos. + +EXPORTS + +; +; Note: +; +; 1. Functions are grouped into blocks according to the OpenCL API version they +; were introduced in. +; +; 2. Function blocks are sorted in ascending order of the API version. +; +; 3. Functions within a block are sorted alphabetically. +; + +; OpenCL 1.0 API +clBuildProgram +clCreateBuffer +clCreateCommandQueue +clCreateContext +clCreateContextFromType +clCreateFromGLBuffer +clCreateFromGLRenderbuffer +clCreateFromGLTexture2D +clCreateFromGLTexture3D +clCreateImage2D +clCreateImage3D +clCreateKernel +clCreateKernelsInProgram +clCreateProgramWithBinary +clCreateProgramWithSource +clCreateSampler +clEnqueueAcquireGLObjects +clEnqueueBarrier +clEnqueueCopyBuffer +clEnqueueCopyBufferToImage +clEnqueueCopyImage +clEnqueueCopyImageToBuffer +clEnqueueMapBuffer +clEnqueueMapImage +clEnqueueMarker +clEnqueueNDRangeKernel +clEnqueueNativeKernel +clEnqueueReadBuffer +clEnqueueReadImage +clEnqueueReleaseGLObjects +clEnqueueTask +clEnqueueUnmapMemObject +clEnqueueWaitForEvents +clEnqueueWriteBuffer +clEnqueueWriteImage +clFinish +clFlush +clGetCommandQueueInfo +clGetContextInfo +clGetDeviceIDs +clGetDeviceInfo +clGetEventInfo +clGetEventProfilingInfo +clGetExtensionFunctionAddress +clGetGLObjectInfo +clGetGLTextureInfo +clGetImageInfo +clGetKernelInfo +clGetKernelWorkGroupInfo +clGetMemObjectInfo +clGetPlatformIDs +clGetPlatformInfo +clGetProgramBuildInfo +clGetProgramInfo +clGetSamplerInfo +clGetSupportedImageFormats +clReleaseCommandQueue +clReleaseContext +clReleaseEvent +clReleaseKernel +clReleaseMemObject +clReleaseProgram +clReleaseSampler +clRetainCommandQueue +clRetainContext +clRetainEvent +clRetainKernel +clRetainMemObject +clRetainProgram +clRetainSampler +clSetCommandQueueProperty +clSetKernelArg +clUnloadCompiler +clWaitForEvents + +; OpenCL 1.1 API +clCreateSubBuffer +clCreateUserEvent +clEnqueueCopyBufferRect +clEnqueueReadBufferRect +clEnqueueWriteBufferRect +clSetEventCallback +clSetMemObjectDestructorCallback +clSetUserEventStatus + +; OpenCL 1.2 API +clCompileProgram +clCreateFromGLTexture +clCreateImage +clCreateProgramWithBuiltInKernels +clCreateSubDevices +clEnqueueBarrierWithWaitList +clEnqueueFillBuffer +clEnqueueFillImage +clEnqueueMarkerWithWaitList +clEnqueueMigrateMemObjects +clGetExtensionFunctionAddressForPlatform +clGetKernelArgInfo +clLinkProgram +clReleaseDevice +clRetainDevice +clUnloadPlatformCompiler + +; OpenCL 2.0 API +clCreateCommandQueueWithProperties +clCreatePipe +clCreateSamplerWithProperties +clEnqueueSVMFree +clEnqueueSVMMap +clEnqueueSVMMemcpy +clEnqueueSVMMemFill +clEnqueueSVMUnmap +clGetPipeInfo +clSetKernelArgSVMPointer +clSetKernelExecInfo +clSVMAlloc +clSVMFree + +; OpenCL 2.1 API +clCloneKernel +clCreateProgramWithIL +clEnqueueSVMMigrateMem +clGetDeviceAndHostTimer +clGetHostTimer +clGetKernelSubGroupInfo +clSetDefaultDeviceCommandQueue + +; OpenCL 2.2 API +clSetProgramReleaseCallback +clSetProgramSpecializationConstant + diff --git a/opencl/khronos/icd/loader/windows/OpenCL.rc b/opencl/khronos/icd/loader/windows/OpenCL.rc new file mode 100644 index 0000000000..c096161445 --- /dev/null +++ b/opencl/khronos/icd/loader/windows/OpenCL.rc @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#include + +#define OPENCL_ICD_LOADER_VERSION_MAJOR 2 +#define OPENCL_ICD_LOADER_VERSION_MINOR 2 +#define OPENCL_ICD_LOADER_VERSION_REV 6 + +#ifdef RC_INVOKED + +#define OPENCL_ICD_LOADER_VAL(_v) #_v +#define OPENCL_ICD_LOADER_TOSTRING(_d) OPENCL_ICD_LOADER_VAL(_d) +#define OPENCL_ICD_LOADER_VERSION_STRING \ + OPENCL_ICD_LOADER_TOSTRING(OPENCL_ICD_LOADER_VERSION_MAJOR) "." \ + OPENCL_ICD_LOADER_TOSTRING(OPENCL_ICD_LOADER_VERSION_MINOR) "." \ + OPENCL_ICD_LOADER_TOSTRING(OPENCL_ICD_LOADER_VERSION_REV) + +VS_VERSION_INFO VERSIONINFO +FILEVERSION OPENCL_ICD_LOADER_VERSION_MAJOR,OPENCL_ICD_LOADER_VERSION_MINOR,OPENCL_ICD_LOADER_VERSION_REV,0 +PRODUCTVERSION OPENCL_ICD_LOADER_VERSION_MAJOR,OPENCL_ICD_LOADER_VERSION_MINOR,OPENCL_ICD_LOADER_VERSION_REV,0 +FILETYPE VFT_DLL + +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + VALUE "FileDescription" ,"OpenCL Client DLL" + VALUE "ProductName" ,"Khronos OpenCL ICD Loader" + VALUE "LegalCopyright" ,"Copyright \251 The Khronos Group Inc 2016-2019" + VALUE "FileVersion" ,OPENCL_ICD_LOADER_VERSION_STRING ".0" + VALUE "CompanyName" ,"Khronos Group" + VALUE "InternalName" ,"OpenCL" + VALUE "OriginalFilename","OpenCL.dll" + END + END + + BLOCK "VarFileInfo" + BEGIN + // extend this line for localized versions + VALUE "Translation", 0x0409, 0x04E4 + END +END + +#endif + diff --git a/opencl/khronos/icd/loader/windows/icd_windows.c b/opencl/khronos/icd/loader/windows/icd_windows.c new file mode 100644 index 0000000000..6f04a1df0a --- /dev/null +++ b/opencl/khronos/icd/loader/windows/icd_windows.c @@ -0,0 +1,288 @@ +/* Modifications Copyright(C) 2022 Advanced Micro Devices, Inc. + * All rights reserved. + */ + +/* + * Copyright (c) 2016-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#include "icd.h" +#include "icd_windows.h" +#include "icd_windows_hkr.h" +#include "icd_windows_dxgk.h" +#include +#include +#include + +#include +#include +typedef HRESULT (WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID, void **); + +static INIT_ONCE initialized = INIT_ONCE_STATIC_INIT; + +typedef struct WinAdapter +{ + char * szName; + LUID luid; +} WinAdapter; + +const LUID ZeroLuid = { 0, 0 }; + +static WinAdapter* pWinAdapterBegin = NULL; +static WinAdapter* pWinAdapterEnd = NULL; +static WinAdapter* pWinAdapterCapacity = NULL; + +BOOL adapterAdd(const char* szName, LUID luid) +{ + BOOL result = TRUE; + if (pWinAdapterEnd == pWinAdapterCapacity) + { + size_t oldCapacity = pWinAdapterCapacity - pWinAdapterBegin; + size_t newCapacity = oldCapacity; + if (0 == newCapacity) + { + newCapacity = 1; + } + else if(newCapacity < UINT_MAX/2) + { + newCapacity *= 2; + } + + WinAdapter* pNewBegin = malloc(newCapacity * sizeof(*pWinAdapterBegin)); + if (!pNewBegin) + result = FALSE; + else + { + if (pWinAdapterBegin) + { + memcpy(pNewBegin, pWinAdapterBegin, oldCapacity * sizeof(*pWinAdapterBegin)); + free(pWinAdapterBegin); + } + pWinAdapterCapacity = pNewBegin + newCapacity; + pWinAdapterEnd = pNewBegin + oldCapacity; + pWinAdapterBegin = pNewBegin; + } + } + if (pWinAdapterEnd != pWinAdapterCapacity) + { + size_t nameLen = (strlen(szName) + 1)*sizeof(szName[0]); + pWinAdapterEnd->szName = malloc(nameLen); + if (!pWinAdapterEnd->szName) + result = FALSE; + else + { + memcpy(pWinAdapterEnd->szName, szName, nameLen); + pWinAdapterEnd->luid = luid; + ++pWinAdapterEnd; + } + } + return result; +} + +void adapterFree(WinAdapter *pWinAdapter) +{ + free(pWinAdapter->szName); + pWinAdapter->szName = NULL; +} + +/* + * + * Vendor enumeration functions + * + */ + +// go through the list of vendors in the registry and call khrIcdVendorAdd +// for each vendor encountered +BOOL CALLBACK khrIcdOsVendorsEnumerate(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *lpContext) +{ + LONG result; + BOOL status = FALSE; + const char* platformsName = "SOFTWARE\\Khronos\\OpenCL\\Vendors"; + HKEY platformsKey = NULL; + DWORD dwIndex; + + khrIcdVendorsEnumerateEnv(); + + status |= khrIcdOsVendorsEnumerateDXGK(); + if (!status) + { + KHR_ICD_TRACE("Failed to load via DXGK interface on RS4, continuing\n"); + status |= khrIcdOsVendorsEnumerateHKR(); + if (!status) + { + KHR_ICD_TRACE("Failed to enumerate HKR entries, continuing\n"); + } + } + + KHR_ICD_TRACE("Opening key HKLM\\%s...\n", platformsName); + result = RegOpenKeyExA( + HKEY_LOCAL_MACHINE, + platformsName, + 0, + KEY_READ, + &platformsKey); + if (ERROR_SUCCESS != result) + { + KHR_ICD_TRACE("Failed to open platforms key %s, continuing\n", platformsName); + } + else + { + // for each value + for (dwIndex = 0;; ++dwIndex) + { + char cszLibraryName[1024] = {0}; + DWORD dwLibraryNameSize = sizeof(cszLibraryName); + DWORD dwLibraryNameType = 0; + DWORD dwValue = 0; + DWORD dwValueSize = sizeof(dwValue); + + // read the value name + KHR_ICD_TRACE("Reading value %d...\n", dwIndex); + result = RegEnumValueA( + platformsKey, + dwIndex, + cszLibraryName, + &dwLibraryNameSize, + NULL, + &dwLibraryNameType, + (LPBYTE)&dwValue, + &dwValueSize); + // if RegEnumKeyEx fails, we are done with the enumeration + if (ERROR_SUCCESS != result) + { + KHR_ICD_TRACE("Failed to read value %d, done reading key.\n", dwIndex); + break; + } + KHR_ICD_TRACE("Value %s found...\n", cszLibraryName); + + // Require that the value be a DWORD and equal zero + if (REG_DWORD != dwLibraryNameType) + { + KHR_ICD_TRACE("Value not a DWORD, skipping\n"); + continue; + } + if (dwValue) + { + KHR_ICD_TRACE("Value not zero, skipping\n"); + continue; + } + // add the library + status |= adapterAdd(cszLibraryName, ZeroLuid); + } + } + + // Add adapters according to DXGI's preference order + HMODULE hDXGI = LoadLibrary("dxgi.dll"); + if (hDXGI) + { + IDXGIFactory* pFactory = NULL; + PFN_CREATE_DXGI_FACTORY pCreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY)GetProcAddress(hDXGI, "CreateDXGIFactory"); + if (pCreateDXGIFactory) + { + HRESULT hr = pCreateDXGIFactory(&IID_IDXGIFactory, &pFactory); + if (SUCCEEDED(hr)) + { + UINT i = 0; + IDXGIAdapter* pAdapter = NULL; + while (SUCCEEDED(pFactory->lpVtbl->EnumAdapters(pFactory, i++, &pAdapter))) + { + DXGI_ADAPTER_DESC AdapterDesc; + if (SUCCEEDED(pAdapter->lpVtbl->GetDesc(pAdapter, &AdapterDesc))) + { + for (WinAdapter* iterAdapter = pWinAdapterBegin; iterAdapter != pWinAdapterEnd; ++iterAdapter) + { + if (iterAdapter->luid.LowPart == AdapterDesc.AdapterLuid.LowPart + && iterAdapter->luid.HighPart == AdapterDesc.AdapterLuid.HighPart) + { + khrIcdVendorAdd(iterAdapter->szName); + break; + } + } + } + + pAdapter->lpVtbl->Release(pAdapter); + } + pFactory->lpVtbl->Release(pFactory); + } + FreeLibrary(hDXGI); + } + } + + // Go through the list again, putting any remaining adapters at the end of the list in an undefined order + for (WinAdapter* iterAdapter = pWinAdapterBegin; iterAdapter != pWinAdapterEnd; ++iterAdapter) + { + khrIcdVendorAdd(iterAdapter->szName); + adapterFree(iterAdapter); + } + + free(pWinAdapterBegin); + pWinAdapterBegin = NULL; + pWinAdapterEnd = NULL; + pWinAdapterCapacity = NULL; + + result = RegCloseKey(platformsKey); + if (ERROR_SUCCESS != result) + { + KHR_ICD_TRACE("Failed to close platforms key %s, ignoring\n", platformsName); + } + + KHRicdVendor *vendorIterator; + for (vendorIterator = khrIcdVendors; vendorIterator; vendorIterator = vendorIterator->next) + { + if (vendorIterator->libName != NULL) + { + free(vendorIterator->libName); + vendorIterator->libName = NULL; + } + } + + return status; +} + +// go through the list of vendors only once +void khrIcdOsVendorsEnumerateOnce() +{ + InitOnceExecuteOnce(&initialized, khrIcdOsVendorsEnumerate, NULL, NULL); +} + +/* + * + * Dynamic library loading functions + * + */ + +// dynamically load a library. returns NULL on failure +void *khrIcdOsLibraryLoad(const char *libraryName) +{ + return (void *)LoadLibraryA(libraryName); +} + +// get a function pointer from a loaded library. returns NULL on failure. +void *khrIcdOsLibraryGetFunctionAddress(void *library, const char *functionName) +{ + if (!library || !functionName) + { + return NULL; + } + return GetProcAddress( (HMODULE)library, functionName); +} + +// unload a library. +void khrIcdOsLibraryUnload(void *library) +{ + FreeLibrary( (HMODULE)library); +} diff --git a/opencl/khronos/icd/loader/windows/icd_windows.h b/opencl/khronos/icd/loader/windows/icd_windows.h new file mode 100644 index 0000000000..48bbf137d8 --- /dev/null +++ b/opencl/khronos/icd/loader/windows/icd_windows.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017-2019 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#include +#include + +extern const LUID ZeroLuid; + +BOOL adapterAdd(const char* szName, LUID luid); + +// Do not free the memory returned by this function. +const char* getOpenCLRegKeyName(void); diff --git a/opencl/khronos/icd/loader/windows/icd_windows_dxgk.c b/opencl/khronos/icd/loader/windows/icd_windows_dxgk.c new file mode 100644 index 0000000000..0fec344069 --- /dev/null +++ b/opencl/khronos/icd/loader/windows/icd_windows_dxgk.c @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2017-2020 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#include "icd.h" +#include "icd_windows_dxgk.h" + +#if defined(OPENCL_ICD_LOADER_REQUIRE_WDK) +#include + +#ifndef NTSTATUS +typedef LONG NTSTATUS; +#define STATUS_SUCCESS ((NTSTATUS)0x00000000L) +#define STATUS_BUFFER_TOO_SMALL ((NTSTATUS)0xC0000023) +#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0) +#endif + +#include +#endif + +bool khrIcdOsVendorsEnumerateDXGK(void) +{ + bool ret = false; + int result = 0; +#if defined(OPENCL_ICD_LOADER_REQUIRE_WDK) +#if defined(DXGKDDI_INTERFACE_VERSION_WDDM2_4) && (DXGKDDI_INTERFACE_VERSION >= DXGKDDI_INTERFACE_VERSION_WDDM2_4) + // Get handle to GDI Runtime + HMODULE h = LoadLibrary("gdi32.dll"); + if (h == NULL) + return ret; + + if(GetProcAddress((HMODULE)h, "D3DKMTSubmitPresentBltToHwQueue")) // OS Version check + { + D3DKMT_ADAPTERINFO* pAdapterInfo = NULL; + D3DKMT_ENUMADAPTERS2 EnumAdapters; + NTSTATUS Status = STATUS_SUCCESS; + + char cszLibraryName[MAX_PATH] = { 0 }; + EnumAdapters.NumAdapters = 0; + EnumAdapters.pAdapters = NULL; + PFND3DKMT_ENUMADAPTERS2 pEnumAdapters2 = (PFND3DKMT_ENUMADAPTERS2)GetProcAddress((HMODULE)h, "D3DKMTEnumAdapters2"); + if (!pEnumAdapters2) + { + KHR_ICD_TRACE("GetProcAddress failed for D3DKMT_ENUMADAPTERS2\n"); + goto out; + } + while (1) + { + EnumAdapters.NumAdapters = 0; + EnumAdapters.pAdapters = NULL; + Status = pEnumAdapters2(&EnumAdapters); + if (Status == STATUS_BUFFER_TOO_SMALL) + { + // Number of Adapters increased between calls, retry; + continue; + } + else if (!NT_SUCCESS(Status)) + { + KHR_ICD_TRACE("D3DKMT_ENUMADAPTERS2 status != SUCCESS\n"); + goto out; + } + break; + } + pAdapterInfo = (D3DKMT_ADAPTERINFO*)malloc(sizeof(D3DKMT_ADAPTERINFO)*(EnumAdapters.NumAdapters)); + if (pAdapterInfo == NULL) + { + KHR_ICD_TRACE("Allocation failure for AdapterInfo buffer\n"); + goto out; + } + EnumAdapters.pAdapters = pAdapterInfo; + Status = pEnumAdapters2(&EnumAdapters); + if (!NT_SUCCESS(Status)) + { + KHR_ICD_TRACE("D3DKMT_ENUMADAPTERS2 status != SUCCESS\n"); + goto out; + } + const char* cszOpenCLRegKeyName = getOpenCLRegKeyName(); + const int szOpenCLRegKeyName = (int)(strlen(cszOpenCLRegKeyName) + 1)*sizeof(cszOpenCLRegKeyName[0]); + for (UINT AdapterIndex = 0; AdapterIndex < EnumAdapters.NumAdapters; AdapterIndex++) + { + D3DDDI_QUERYREGISTRY_INFO queryArgs = {0}; + D3DDDI_QUERYREGISTRY_INFO* pQueryArgs = &queryArgs; + D3DDDI_QUERYREGISTRY_INFO* pQueryBuffer = NULL; + queryArgs.QueryType = D3DDDI_QUERYREGISTRY_ADAPTERKEY; + queryArgs.QueryFlags.TranslatePath = TRUE; + queryArgs.ValueType = REG_SZ; + result = MultiByteToWideChar( + CP_ACP, + 0, + cszOpenCLRegKeyName, + szOpenCLRegKeyName, + queryArgs.ValueName, + ARRAYSIZE(queryArgs.ValueName)); + if (!result) + { + KHR_ICD_TRACE("MultiByteToWideChar status != SUCCESS\n"); + continue; + } + D3DKMT_QUERYADAPTERINFO queryAdapterInfo = {0}; + queryAdapterInfo.hAdapter = pAdapterInfo[AdapterIndex].hAdapter; + queryAdapterInfo.Type = KMTQAITYPE_QUERYREGISTRY; + queryAdapterInfo.pPrivateDriverData = &queryArgs; + queryAdapterInfo.PrivateDriverDataSize = sizeof(queryArgs); + Status = D3DKMTQueryAdapterInfo(&queryAdapterInfo); + if (!NT_SUCCESS(Status)) + { + // Try a different value type. Some vendors write the key as a multi-string type. + queryArgs.ValueType = REG_MULTI_SZ; + Status = D3DKMTQueryAdapterInfo(&queryAdapterInfo); + if (NT_SUCCESS(Status)) + { + KHR_ICD_TRACE("Accepting multi-string registry key type\n"); + } + else + { + // Continue trying to get as much info on each adapter as possible. + // It's too late to return FALSE and claim WDDM2_4 enumeration is not available here. + continue; + } + } + if (NT_SUCCESS(Status) && pQueryArgs->Status == D3DDDI_QUERYREGISTRY_STATUS_BUFFER_OVERFLOW) + { + ULONG queryBufferSize = sizeof(D3DDDI_QUERYREGISTRY_INFO) + queryArgs.OutputValueSize; + pQueryBuffer = (D3DDDI_QUERYREGISTRY_INFO*)malloc(queryBufferSize); + if (pQueryBuffer == NULL) + continue; + memcpy(pQueryBuffer, &queryArgs, sizeof(D3DDDI_QUERYREGISTRY_INFO)); + queryAdapterInfo.pPrivateDriverData = pQueryBuffer; + queryAdapterInfo.PrivateDriverDataSize = queryBufferSize; + Status = D3DKMTQueryAdapterInfo(&queryAdapterInfo); + pQueryArgs = pQueryBuffer; + } + if (NT_SUCCESS(Status) && pQueryArgs->Status == D3DDDI_QUERYREGISTRY_STATUS_SUCCESS) + { + wchar_t* pWchar = pQueryArgs->OutputString; + memset(cszLibraryName, 0, sizeof(cszLibraryName)); + { + size_t len = wcstombs(cszLibraryName, pWchar, sizeof(cszLibraryName)); + KHR_ICD_ASSERT(len == (sizeof(cszLibraryName) - 1)); + ret |= adapterAdd(cszLibraryName, pAdapterInfo[AdapterIndex].AdapterLuid); + } + } + else if (Status == STATUS_INVALID_PARAMETER && pQueryArgs->Status == D3DDDI_QUERYREGISTRY_STATUS_FAIL) + { + free(pQueryBuffer); + goto out; + } + free(pQueryBuffer); + } +out: + free(pAdapterInfo); + } + + FreeLibrary(h); + +#endif +#endif + return ret; +} diff --git a/opencl/khronos/icd/loader/windows/icd_windows_dxgk.h b/opencl/khronos/icd/loader/windows/icd_windows_dxgk.h new file mode 100644 index 0000000000..34bad64af4 --- /dev/null +++ b/opencl/khronos/icd/loader/windows/icd_windows_dxgk.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2017-2019 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#include +#include "icd_windows.h" + +bool khrIcdOsVendorsEnumerateDXGK(void); diff --git a/opencl/khronos/icd/loader/windows/icd_windows_envvars.c b/opencl/khronos/icd/loader/windows/icd_windows_envvars.c new file mode 100644 index 0000000000..3c17519991 --- /dev/null +++ b/opencl/khronos/icd/loader/windows/icd_windows_envvars.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2016-2019 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#include +#include +#include + +char *khrIcd_getenv(const char *name) { + char *retVal; + DWORD valSize; + + valSize = GetEnvironmentVariableA(name, NULL, 0); + + // valSize DOES include the null terminator, so for any set variable + // will always be at least 1. If it's 0, the variable wasn't set. + if (valSize == 0) return NULL; + + // Allocate the space necessary for the registry entry + retVal = (char *)malloc(valSize); + + if (NULL != retVal) { + GetEnvironmentVariableA(name, retVal, valSize); + } + + return retVal; +} + +static bool khrIcd_IsHighIntegrityLevel() +{ + bool isHighIntegrityLevel = false; + + HANDLE processToken; + if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_QUERY_SOURCE, &processToken)) { + // Maximum possible size of SID_AND_ATTRIBUTES is maximum size of a SID + size of attributes DWORD. + char mandatoryLabelBuffer[SECURITY_MAX_SID_SIZE + sizeof(DWORD)] = {0}; + DWORD bufferSize; + if (GetTokenInformation(processToken, TokenIntegrityLevel, mandatoryLabelBuffer, sizeof(mandatoryLabelBuffer), + &bufferSize) != 0) { + const TOKEN_MANDATORY_LABEL* mandatoryLabel = (const TOKEN_MANDATORY_LABEL*)(mandatoryLabelBuffer); + const DWORD subAuthorityCount = *GetSidSubAuthorityCount(mandatoryLabel->Label.Sid); + const DWORD integrityLevel = *GetSidSubAuthority(mandatoryLabel->Label.Sid, subAuthorityCount - 1); + + isHighIntegrityLevel = integrityLevel > SECURITY_MANDATORY_MEDIUM_RID; + } + + CloseHandle(processToken); + } + + return isHighIntegrityLevel; +} + +char *khrIcd_secure_getenv(const char *name) { + if (khrIcd_IsHighIntegrityLevel()) { + KHR_ICD_TRACE("Running at a high integrity level, so secure_getenv is returning NULL\n"); + return NULL; + } + + return khrIcd_getenv(name); +} + +void khrIcd_free_getenv(char *val) { + free((void *)val); +} diff --git a/opencl/khronos/icd/loader/windows/icd_windows_hkr.c b/opencl/khronos/icd/loader/windows/icd_windows_hkr.c new file mode 100644 index 0000000000..58d5c0c518 --- /dev/null +++ b/opencl/khronos/icd/loader/windows/icd_windows_hkr.c @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2017-2019 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#include "icd.h" +#include "icd_windows_hkr.h" +#include +#include "icd_windows_dxgk.h" +#include +#include +#include +#include +#include +#include + + // This GUID was only added to devguid.h on Windows SDK v10.0.16232 which + // corresponds to Windows 10 Redstone 3 (Windows 10 Fall Creators Update). +DEFINE_GUID(OCL_GUID_DEVCLASS_SOFTWARECOMPONENT, 0x5c4c3332, 0x344d, 0x483c, 0x87, 0x39, 0x25, 0x9e, 0x93, 0x4c, 0x9c, 0xc8); + +typedef enum +{ + ProbeFailure, + PendingReboot, + Valid +} DeviceProbeResult; + +#define KHR_SAFE_RELEASE(mem) \ + do \ + { \ + free(mem); \ + mem = NULL; \ + } while (0) + +static const char OPENCL_REG_SUB_KEY[] = "OpenCLDriverName"; + +#ifndef _WIN64 +static const char OPENCL_REG_SUB_KEY_WOW[] = "OpenCLDriverNameWow"; +#endif + +// Do not free the memory returned by this function. +const char* getOpenCLRegKeyName(void) +{ +#ifdef _WIN64 + return OPENCL_REG_SUB_KEY; +#else + // The suffix/substring "WoW" is meaningful only when a 32-bit + // application is running on a 64-bit Windows OS. A 32-bit application + // running on a 32-bit OS uses non-WoW names. + BOOL is_wow64; + if (IsWow64Process(GetCurrentProcess(), &is_wow64) && is_wow64) + { + return OPENCL_REG_SUB_KEY_WOW; + } + + return OPENCL_REG_SUB_KEY; +#endif +} + +static bool ReadOpenCLKey(DEVINST dnDevNode) +{ + HKEY hkey = 0; + CONFIGRET ret; + bool bRet = false; + DWORD dwLibraryNameType = 0; + char *cszOclPath = NULL; + DWORD dwOclPathSize = 0; + LSTATUS result; + + ret = CM_Open_DevNode_Key( + dnDevNode, + KEY_QUERY_VALUE, + 0, + RegDisposition_OpenExisting, + &hkey, + CM_REGISTRY_SOFTWARE); + + if (CR_SUCCESS != ret) + { + KHR_ICD_TRACE("Failed with ret 0x%x\n", ret); + goto out; + } + else + { + result = RegQueryValueExA( + hkey, + getOpenCLRegKeyName(), + NULL, + &dwLibraryNameType, + NULL, + &dwOclPathSize); + + if (ERROR_SUCCESS != result) + { + KHR_ICD_TRACE("Failed to open sub key 0x%x\n", result); + goto out; + } + + cszOclPath = malloc(dwOclPathSize); + if (NULL == cszOclPath) + { + KHR_ICD_TRACE("Failed to allocate %u bytes for registry value\n", dwOclPathSize); + goto out; + } + + result = RegQueryValueExA( + hkey, + getOpenCLRegKeyName(), + NULL, + &dwLibraryNameType, + (LPBYTE)cszOclPath, + &dwOclPathSize); + if (ERROR_SUCCESS != result) + { + KHR_ICD_TRACE("Failed to open sub key 0x%x\n", result); + goto out; + } + + if (REG_SZ != dwLibraryNameType) + { + if (REG_MULTI_SZ == dwLibraryNameType) + { + KHR_ICD_TRACE("Accepting multi-string registry key type\n"); + } + else + { + KHR_ICD_TRACE("Unexpected registry entry 0x%x! continuing\n", dwLibraryNameType); + goto out; + } + } + + KHR_ICD_TRACE(" Path: %s\n", cszOclPath); + + bRet |= adapterAdd(cszOclPath, ZeroLuid); + } + +out: + free(cszOclPath); + + if (hkey) + { + result = RegCloseKey(hkey); + if (ERROR_SUCCESS != result) + { + KHR_ICD_TRACE("WARNING: failed to close hkey 0x%x\n", result); + } + } + + return bRet; +} + +static DeviceProbeResult ProbeDevice(DEVINST devnode) +{ + CONFIGRET ret; + ULONG ulStatus; + ULONG ulProblem; + + ret = CM_Get_DevNode_Status( + &ulStatus, + &ulProblem, + devnode, + 0); + + if (CR_SUCCESS != ret) + { + KHR_ICD_TRACE(" WARNING: failed to probe the status of the device 0x%x\n", ret); + return ProbeFailure; + } + + // + // Careful here, we need to check 2 scenarios: + // 1. DN_NEED_RESTART + // status flag indicates that a reboot is needed when an _already started_ + // device cannot be stopped. This covers devices that are still started with their + // old KMD (because they couldn't be stopped/restarted) while the UMD is updated + // and possibly out of sync. + // + // 2. Status & DN_HAS_PROBLEM && Problem == CM_PROB_NEED_RESTART + // indicates that a reboot is needed when a _stopped device_ cannot be (re)started. + // + if (((ulStatus & DN_HAS_PROBLEM) && ulProblem == CM_PROB_NEED_RESTART) || + ulStatus & DN_NEED_RESTART) + { + KHR_ICD_TRACE(" WARNING: device is pending reboot (0x%x), skipping...\n", ulStatus); + return PendingReboot; + } + + return Valid; +} + +// Tries to look for the OpenCL key under the display devices and +// if not found, falls back to software component devices. +bool khrIcdOsVendorsEnumerateHKR(void) +{ + CONFIGRET ret; + int iret; + bool foundOpenCLKey = false; + DEVINST devinst = 0; + DEVINST devchild = 0; + wchar_t *deviceIdList = NULL; + ULONG szBuffer = 0; + + OLECHAR display_adapter_guid_str[MAX_GUID_STRING_LEN]; + ULONG ulFlags = CM_GETIDLIST_FILTER_CLASS | + CM_GETIDLIST_FILTER_PRESENT; + + iret = StringFromGUID2( + &GUID_DEVCLASS_DISPLAY, + display_adapter_guid_str, + MAX_GUID_STRING_LEN); + + if (MAX_GUID_STRING_LEN != iret) + { + KHR_ICD_TRACE("StringFromGUID2 failed with %d\n", iret); + goto out; + } + + // Paranoia: we might have a new device added to the list between the call + // to CM_Get_Device_ID_List_Size() and the call to CM_Get_Device_ID_List(). + do + { + ret = CM_Get_Device_ID_List_SizeW( + &szBuffer, + display_adapter_guid_str, + ulFlags); + + if (CR_SUCCESS != ret) + { + KHR_ICD_TRACE("CM_Get_Device_ID_List_size failed with 0x%x\n", ret); + break; + } + + // "pulLen [out] Receives a value representing the required buffer + // size, in characters." + // So we need to allocate the right size in bytes but we still need + // to keep szBuffer as it was returned from CM_Get_Device_ID_List_Size so + // the call to CM_Get_Device_ID_List will receive the correct size. + deviceIdList = malloc(szBuffer * sizeof(wchar_t)); + if (NULL == deviceIdList) + { + KHR_ICD_TRACE("Failed to allocate %u bytes for device ID strings\n", szBuffer); + break; + } + + ret = CM_Get_Device_ID_ListW( + display_adapter_guid_str, + deviceIdList, + szBuffer, + ulFlags); + + if (CR_SUCCESS != ret) + { + KHR_ICD_TRACE("CM_Get_Device_ID_List failed with 0x%x\n", ret); + KHR_SAFE_RELEASE(deviceIdList); + } + } while (CR_BUFFER_SMALL == ret); + + if (NULL == deviceIdList) + { + goto out; + } + + for (PWSTR deviceId = deviceIdList; *deviceId; deviceId += wcslen(deviceId) + 1) + { + DEVPROPTYPE devpropType; + + KHR_ICD_WIDE_TRACE(L"Device ID: %ls\n", deviceId); + + ret = CM_Locate_DevNodeW(&devinst, deviceId, 0); + if (CR_SUCCESS == ret) + { + KHR_ICD_TRACE(" devinst: %d\n", devinst); + } + else + { + KHR_ICD_TRACE("CM_Locate_DevNode failed with 0x%x\n", ret); + continue; + } + + if (ProbeDevice(devinst) != Valid) + { + continue; + } + + KHR_ICD_TRACE(" Trying to look for the key in the display adapter HKR...\n"); + if (ReadOpenCLKey(devinst)) + { + foundOpenCLKey = true; + continue; + } + + KHR_ICD_TRACE(" Could not find the key, proceeding to children software components...\n"); + + ret = CM_Get_Child( + &devchild, + devinst, + 0); + + if (CR_SUCCESS != ret) + { + KHR_ICD_TRACE(" CM_Get_Child returned 0x%x, skipping children...\n", ret); + } + else + { + do + { + wchar_t deviceInstanceID[MAX_DEVICE_ID_LEN] = { 0 }; + GUID guid; + ULONG szGuid = sizeof(guid); + + KHR_ICD_TRACE(" devchild: %d\n", devchild); + ret = CM_Get_Device_IDW( + devchild, + deviceInstanceID, + sizeof(deviceInstanceID), + 0); + + if (CR_SUCCESS != ret) + { + KHR_ICD_TRACE(" CM_Get_Device_ID returned 0x%x, skipping device...\n", ret); + continue; + } + else + { + KHR_ICD_WIDE_TRACE(L" deviceInstanceID: %ls\n", deviceInstanceID); + } + + ret = CM_Get_DevNode_PropertyW( + devchild, + &DEVPKEY_Device_ClassGuid, + &devpropType, + (PBYTE)&guid, + &szGuid, + 0); + + if (CR_SUCCESS != ret || + !IsEqualGUID(&OCL_GUID_DEVCLASS_SOFTWARECOMPONENT, &guid)) + { + continue; + } + + if (ProbeDevice(devchild) != Valid) + { + continue; + } + + if (ReadOpenCLKey(devchild)) + { + foundOpenCLKey = true; + break; + } + } while (CM_Get_Sibling(&devchild, devchild, 0) == CR_SUCCESS); + } + } + +out: + free(deviceIdList); + return foundOpenCLKey; +} diff --git a/opencl/khronos/icd/loader/windows/icd_windows_hkr.h b/opencl/khronos/icd/loader/windows/icd_windows_hkr.h new file mode 100644 index 0000000000..e0db713bb7 --- /dev/null +++ b/opencl/khronos/icd/loader/windows/icd_windows_hkr.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2017-2019 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#include +#include "icd_windows.h" + +bool khrIcdOsVendorsEnumerateHKR(void); diff --git a/opencl/khronos/icd/test/CMakeLists.txt b/opencl/khronos/icd/test/CMakeLists.txt new file mode 100644 index 0000000000..a158995888 --- /dev/null +++ b/opencl/khronos/icd/test/CMakeLists.txt @@ -0,0 +1,7 @@ +include_directories (./inc) + +add_subdirectory (log) +add_subdirectory (driver_stub) +add_subdirectory (loader_test) + +add_test (NAME opencl_icd_loader_test COMMAND icd_loader_test) diff --git a/opencl/khronos/icd/test/driver_stub/CMakeLists.txt b/opencl/khronos/icd/test/driver_stub/CMakeLists.txt new file mode 100644 index 0000000000..47b3bd273e --- /dev/null +++ b/opencl/khronos/icd/test/driver_stub/CMakeLists.txt @@ -0,0 +1,10 @@ + +set (OPENCL_DRIVER_STUB_SOURCES cl.c cl_ext.c cl_gl.c icd.c) + +if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + list (APPEND OPENCL_DRIVER_STUB_SOURCES driver_stub.def) +endif () + +add_library (OpenCLDriverStub ${OPENCL_DRIVER_STUB_SOURCES}) + +target_link_libraries (OpenCLDriverStub IcdLog) diff --git a/opencl/khronos/icd/test/driver_stub/cl.c b/opencl/khronos/icd/test/driver_stub/cl.c new file mode 100644 index 0000000000..b280d04d7e --- /dev/null +++ b/opencl/khronos/icd/test/driver_stub/cl.c @@ -0,0 +1,1923 @@ +/* Modifications Copyright(C) 2022 Advanced Micro Devices, Inc. + * All rights reserved. + */ + +#include +#include +#include + +#ifndef CL_USE_DEPRECATED_OPENCL_1_0_APIS +#define CL_USE_DEPRECATED_OPENCL_1_0_APIS +#endif + +#ifndef CL_USE_DEPRECATED_OPENCL_1_1_APIS +#define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#endif + +// Need to rename all CL API functions to prevent ICD loader functions calling +// themselves via the dispatch table. Include this before cl headers. +#include "rename_api.h" + +#include +#include +#include "icd_structs.h" + +#define CL_PLATFORM_ICD_SUFFIX_KHR 0x0920 +CL_API_ENTRY cl_int CL_API_CALL +clIcdGetPlatformIDsKHR(cl_uint, cl_platform_id *, cl_uint *); + +struct _cl_platform_id +{ + CLIicdDispatchTable* dispatch; + const char *profile; + const char *version; + const char *name; + const char *vendor; + const char *extensions; + const char *suffix; +}; + +struct _cl_device_id +{ + CLIicdDispatchTable* dispatch; +}; + +struct _cl_context +{ + CLIicdDispatchTable* dispatch; +}; + +struct _cl_command_queue +{ + CLIicdDispatchTable* dispatch; +}; + +struct _cl_mem +{ + CLIicdDispatchTable* dispatch; +}; + +struct _cl_program +{ + CLIicdDispatchTable* dispatch; +}; + +struct _cl_kernel +{ + CLIicdDispatchTable* dispatch; +}; + +struct _cl_event +{ + CLIicdDispatchTable* dispatch; +}; + +struct _cl_sampler +{ + CLIicdDispatchTable* dispatch; +}; + +static CLIicdDispatchTable* dispatchTable = NULL; +static cl_platform_id platform = NULL; +static cl_bool initialized = CL_FALSE; + +CL_API_ENTRY cl_int CL_API_CALL +clGetPlatformIDs(cl_uint num_entries , + cl_platform_id * platforms , + cl_uint * num_platforms) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetPlatformIDs(%u, %p, %p)\n", + num_entries, + platforms, + num_platforms); + return_value = clIcdGetPlatformIDsKHR(num_entries, platforms, num_platforms); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetPlatformInfo(cl_platform_id platform, + cl_platform_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int ret = CL_SUCCESS; + const char *returnString = NULL; + size_t returnStringLength = 0; + /*test_icd_stub_log("clGetPlatformInfo(%p, %u, %u, %p, %p)\n", + platform, + param_name, + param_value_size, + param_value, + param_value_size_ret);*/ + + // validate the arguments + if (param_value_size == 0 && param_value != NULL) { + ret = CL_INVALID_VALUE; + goto done; + } + // select the string to return + switch(param_name) { + case CL_PLATFORM_PROFILE: + returnString = platform->profile; + break; + case CL_PLATFORM_VERSION: + returnString = platform->version; + break; + case CL_PLATFORM_NAME: + returnString = platform->name; + break; + case CL_PLATFORM_VENDOR: + returnString = platform->vendor; + break; + case CL_PLATFORM_EXTENSIONS: + returnString = platform->extensions; + break; + case CL_PLATFORM_ICD_SUFFIX_KHR: + returnString = platform->suffix; + break; + default: + ret = CL_INVALID_VALUE; + goto done; + } + + // make sure the buffer passed in is big enough for the result + returnStringLength = strlen(returnString)+1; + if (param_value_size && param_value_size < returnStringLength) { + ret = CL_INVALID_VALUE; + goto done; + } + + // pass the data back to the user + if (param_value) { + memcpy(param_value, returnString, returnStringLength); + } + if (param_value_size_ret) { + *param_value_size_ret = returnStringLength; + } + +done: + /*test_icd_stub_log("Value returned: %d\n", + return_value);*/ + return ret; +} + + +/* Device APIs */ +CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceIDs(cl_platform_id platform, + cl_device_type device_type, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int ret = CL_SUCCESS; + + if ((num_entries > 1 || num_entries < 0) && devices != NULL) { + ret = CL_INVALID_VALUE; + goto done; + } + + if (devices != NULL) { + cl_device_id obj = (cl_device_id) malloc(sizeof(*obj)); + obj->dispatch = dispatchTable; + devices[0] = obj; + } + if (num_devices) { + *num_devices = 1; + } + +done: + test_icd_stub_log("clGetDeviceIDs(%p, %x, %u, %p, %p)\n", + platform, + device_type, + num_entries, + devices, + num_devices); + test_icd_stub_log("Value returned: %d\n", ret); + return ret; +} + + + +CL_API_ENTRY cl_int CL_API_CALL +clGetDeviceInfo(cl_device_id device, + cl_device_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetDeviceInfo(%p, %u, %u, %p, %p)\n", + device, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clCreateSubDevices(cl_device_id in_device, + const cl_device_partition_property *properties, + cl_uint num_entries, + cl_device_id *out_devices, + cl_uint *num_devices) CL_API_SUFFIX__VERSION_1_2 +{ + + cl_int return_value = CL_OUT_OF_RESOURCES; + + test_icd_stub_log("clCreateSubDevices(%p, %p, %u, %p, %p)\n", + in_device, + properties, + num_entries, + out_devices, + num_devices); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + + +CL_API_ENTRY cl_int CL_API_CALL +clRetainDevice(cl_device_id device) CL_API_SUFFIX__VERSION_1_2 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clRetainDevice(%p)\n", device); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseDevice(cl_device_id device) CL_API_SUFFIX__VERSION_1_2 + +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clReleaseDevice(%p)\n", device); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + + +/* Context APIs */ +CL_API_ENTRY cl_context CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + cl_context obj = (cl_context) malloc(sizeof(struct _cl_context)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateContext(%p, %u, %p, %p, %p, %p)\n", + properties, + num_devices, + devices, + pfn_notify, + user_data, + errcode_ret); + pfn_notify(NULL, NULL, 0, NULL); + test_icd_stub_log("createcontext_callback(%p, %p, %u, %p)\n", + NULL, + NULL, + 0, + NULL); + + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + + +CL_API_ENTRY cl_context CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + cl_context obj = (cl_context) malloc(sizeof(struct _cl_context)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateContextFromType(%p, %x, %p, %p, %p)\n", + properties, + device_type, + pfn_notify, + user_data, + errcode_ret); + pfn_notify(NULL, NULL, 0, NULL); + + test_icd_stub_log ("createcontext_callback(%p, %p, %u, %p)\n", + NULL, + NULL, + 0, + NULL); + + test_icd_stub_log("Value returned: %p\n", + obj); + return obj; +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainContext(cl_context context) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clRetainContext(%p)\n", context); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseContext(cl_context context) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clReleaseContext(%p)\n", context); + free(context); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetContextInfo(cl_context context, + cl_context_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetContextInfo(%p, %u, %u, %p, %p)\n", + context, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +/* Command Queue APIs */ +CL_API_ENTRY cl_command_queue CL_API_CALL +clCreateCommandQueue(cl_context context, + cl_device_id device, + cl_command_queue_properties properties, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_command_queue obj = (cl_command_queue) malloc(sizeof(struct _cl_command_queue)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateCommandQueue(%p, %p, %x, %p)\n", + context, + device, + properties, + errcode_ret); + + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + +CL_API_ENTRY cl_int CL_API_CALL +clSetCommandQueueProperty(cl_command_queue command_queue , + cl_command_queue_properties properties , + cl_bool enable , + cl_command_queue_properties * old_properties) CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clSetCommandQueueProperty(%p, %p, %u, %p)\n", + command_queue, + properties, + enable, + old_properties); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainCommandQueue(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clRetainCommandQueue(%p)\n", command_queue); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseCommandQueue(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clReleaseCommandQueue(%p)\n", command_queue); + free(command_queue); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetCommandQueueInfo(cl_command_queue command_queue , + cl_command_queue_info param_name , + size_t param_value_size , + void * param_value , + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetCommandQueueInfo(%p, %u, %u, %p, %p)\n", + command_queue, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + + + +/* Memory Object APIs */ +CL_API_ENTRY cl_mem CL_API_CALL +clCreateBuffer(cl_context context , + cl_mem_flags flags , + size_t size , + void * host_ptr , + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_mem obj = (cl_mem) malloc(sizeof(struct _cl_mem)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateBuffer(%p, %x, %u, %p, %p)\n", + context, + flags, + size, + host_ptr, + errcode_ret); + + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateSubBuffer(cl_mem buffer , + cl_mem_flags flags , + cl_buffer_create_type buffer_create_type , + const void * buffer_create_info , + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1 +{ + cl_mem obj = (cl_mem) malloc(sizeof(struct _cl_mem)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateSubBuffer(%p, %x, %u, %p, %p)\n", + buffer, + flags, + buffer_create_type, + buffer_create_info, + errcode_ret); + + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + +CL_API_ENTRY cl_mem CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_2 +{ + cl_mem obj = (cl_mem) malloc(sizeof(struct _cl_mem)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateImage(%p, %x, %p, %p, %p, %p)\n", + context, + flags, + image_format, + image_desc, + host_ptr, + errcode_ret); + + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateImage2D(cl_context context , + cl_mem_flags flags , + const cl_image_format * image_format , + size_t image_width , + size_t image_height , + size_t image_row_pitch , + void * host_ptr , + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_mem obj = (cl_mem) malloc(sizeof(struct _cl_mem)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateImage2D(%p, %x, %p, %u, %u, %u, %p, %p)\n", + context, + flags, + image_format, + image_width, + image_height, + image_row_pitch, + host_ptr, + errcode_ret); + + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateImage3D(cl_context context, + cl_mem_flags flags, + const cl_image_format * image_format, + size_t image_width, + size_t image_height , + size_t image_depth , + size_t image_row_pitch , + size_t image_slice_pitch , + void * host_ptr , + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_mem obj = (cl_mem) malloc(sizeof(struct _cl_mem)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateImage3D(%p, %x, %p, %u, %u, %u, %u, %u, %p, %p)\n", + context, + flags, + image_format, + image_width, + image_height, + image_depth, + image_row_pitch, + image_slice_pitch, + host_ptr, + errcode_ret); + + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainMemObject(cl_mem memobj) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clRetainMemObject(%p)\n", memobj); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseMemObject(cl_mem memobj) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clReleaseMemObject(%p)\n", memobj); + free(memobj); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetSupportedImageFormats(%p, %x, %u, %u, %p, %p)\n", + context, + flags, + image_type, + num_entries, + image_formats, + num_image_formats); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetMemObjectInfo(cl_mem memobj , + cl_mem_info param_name , + size_t param_value_size , + void * param_value , + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetMemObjectInfo(%p, %u, %u, %p, %p)\n", + memobj, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetImageInfo(cl_mem image , + cl_image_info param_name , + size_t param_value_size , + void * param_value , + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetImageInfo(%p, %u, %u, %p, %p)\n", + image, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clSetMemObjectDestructorCallback(cl_mem memobj , + void (CL_CALLBACK * pfn_notify)(cl_mem memobj , void* user_data), + void * user_data) CL_API_SUFFIX__VERSION_1_1 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clSetMemObjectDestructorCallback(%p, %p, %p)\n", + memobj, + pfn_notify, + user_data); + pfn_notify(memobj, NULL); + test_icd_stub_log("setmemobjectdestructor_callback(%p, %p)\n", + memobj, + NULL); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +/* Sampler APIs */ +CL_API_ENTRY cl_sampler CL_API_CALL +clCreateSampler(cl_context context , + cl_bool normalized_coords , + cl_addressing_mode addressing_mode , + cl_filter_mode filter_mode , + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_sampler obj = (cl_sampler) malloc(sizeof(struct _cl_sampler)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateSampler(%p, %u, %u, %u, %p)\n", + context, + normalized_coords, + addressing_mode, + filter_mode, + errcode_ret); + + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainSampler(cl_sampler sampler) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clRetainSampler(%p)\n", sampler); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseSampler(cl_sampler sampler) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clReleaseSampler(%p)\n", sampler); + free(sampler); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetSamplerInfo(cl_sampler sampler , + cl_sampler_info param_name , + size_t param_value_size , + void * param_value , + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetSamplerInfo(%p, %u, %u, %p, %p)\n", + sampler, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +/* Program Object APIs */ +CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithSource(cl_context context , + cl_uint count , + const char ** strings , + const size_t * lengths , + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_program obj = (cl_program) malloc(sizeof(struct _cl_program)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateProgramWithSource(%p, %u, %p, %p, %p)\n", + context, + count, + strings, + lengths, + errcode_ret); + + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + +CL_API_ENTRY cl_program CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + cl_program obj = (cl_program) malloc(sizeof(struct _cl_program)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateProgramWithBinary(%p, %u, %p, %p, %p, %p, %p)\n", + context, + num_devices, + device_list, + lengths, + binaries, + binary_status, + errcode_ret); + + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + +CL_API_ENTRY cl_program CL_API_CALL +clCreateProgramWithBuiltInKernels(cl_context context , + cl_uint num_devices , + const cl_device_id * device_list , + const char * kernel_names , + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2 +{ + cl_program obj = (cl_program) malloc(sizeof(struct _cl_program)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateProgramWithBuiltInKernels(%p, %u, %p, %p, %p)\n", + context, + num_devices, + device_list, + kernel_names, + errcode_ret); + + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + + +CL_API_ENTRY cl_int CL_API_CALL +clRetainProgram(cl_program program) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clRetainProgram(%p)\n", + program); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseProgram(cl_program program) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clReleaseProgram(%p)\n", program); + free(program); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clBuildProgram(%p, %u, %p, %p, %p, %p)\n", + program, + num_devices, + device_list, + options, + pfn_notify, + user_data); + pfn_notify(program, NULL); + test_icd_stub_log("program_callback(%p, %p)\n", program, NULL); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clUnloadCompiler(void) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clUnloadCompiler()\n"); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clCompileProgram(cl_program program , + cl_uint num_devices , + const cl_device_id * device_list , + const char * options , + cl_uint num_input_headers , + const cl_program * input_headers, + const char ** header_include_names , + void (CL_CALLBACK * pfn_notify)(cl_program program , void * user_data), + void * user_data) CL_API_SUFFIX__VERSION_1_2 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clCompileProgram(%p, %u, %p, %p, %u, %p, %p, %p)\n", + program, + num_devices, + device_list, + options, + num_input_headers, + header_include_names, + pfn_notify, + user_data); + pfn_notify(program, NULL); + test_icd_stub_log("program_callback(%p, %p)\n", program, NULL); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_program CL_API_CALL +clLinkProgram(cl_context context , + cl_uint num_devices , + const cl_device_id * device_list , + const char * options , + cl_uint num_input_programs , + const cl_program * input_programs , + void (CL_CALLBACK * pfn_notify)(cl_program program , void * user_data), + void * user_data , + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2 +{ + cl_program obj = (cl_program) malloc(sizeof(cl_program)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clLinkProgram(%p, %u, %p, %p, %u, %p, %p, %p, %p)\n", + context, + num_devices, + device_list, + options, + num_input_programs, + input_programs, + pfn_notify, + user_data, + errcode_ret); + pfn_notify(obj, NULL); + test_icd_stub_log("program_callback(%p, %p)\n", obj, NULL); + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + + +CL_API_ENTRY cl_int CL_API_CALL +clUnloadPlatformCompiler(cl_platform_id platform) CL_API_SUFFIX__VERSION_1_2 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clUnloadPlatformCompiler(%p)\n", platform); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetProgramInfo(cl_program program , + cl_program_info param_name , + size_t param_value_size , + void * param_value , + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetProgramInfo(%p, %u, %u, %p, %p)\n", + program, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetProgramBuildInfo(%p, %p, %u, %u, %p, %p)\n", + program, + device, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +/* Kernel Object APIs */ +CL_API_ENTRY cl_kernel CL_API_CALL +clCreateKernel(cl_program program , + const char * kernel_name , + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_kernel obj = (cl_kernel) malloc(sizeof(struct _cl_kernel)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateKernel(%p, %p, %p)\n", + program, + kernel_name, + errcode_ret); + + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + +CL_API_ENTRY cl_int CL_API_CALL +clCreateKernelsInProgram(cl_program program , + cl_uint num_kernels , + cl_kernel * kernels , + cl_uint * num_kernels_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clCreateKernelsInProgram(%p, %u, %p, %p)\n", + program, + num_kernels, + kernels, + num_kernels_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainKernel(cl_kernel kernel) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clRetainKernel(%p)\n", kernel); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseKernel(cl_kernel kernel) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clReleaseKernel(%p)\n", kernel); + free(kernel); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clSetKernelArg(cl_kernel kernel , + cl_uint arg_index , + size_t arg_size , + const void * arg_value) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clSetKernelArg(%p, %u, %u, %p)\n", + kernel, + arg_index, + arg_size, + arg_value); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetKernelInfo(cl_kernel kernel , + cl_kernel_info param_name , + size_t param_value_size , + void * param_value , + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetKernelInfo(%p, %u, %u, %p, %p)\n", + kernel, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetKernelArgInfo(cl_kernel kernel , + cl_uint arg_indx , + cl_kernel_arg_info param_name , + size_t param_value_size , + void * param_value , + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_2 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetKernelArgInfo(%p, %u, %u, %u, %p, %p)\n", + kernel, + arg_indx, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetKernelWorkGroupInfo(%p, %p, %u, %u, %p, %p)\n", + kernel, + device, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +/* Event Object APIs */ +CL_API_ENTRY cl_int CL_API_CALL +clWaitForEvents(cl_uint num_events , + const cl_event * event_list) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clWaitForEvents(%u, %p)\n", + num_events, + event_list); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetEventInfo(cl_event event , + cl_event_info param_name , + size_t param_value_size , + void * param_value , + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetEventInfo(%p, %u, %u, %p, %p)\n", + event, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_event CL_API_CALL +clCreateUserEvent(cl_context context , + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1 +{ + cl_event obj = (cl_event) malloc(sizeof(struct _cl_event)); + obj->dispatch = dispatchTable; + test_icd_stub_log("clCreateUserEvent(%p, %p)\n", context, errcode_ret); + test_icd_stub_log("Value returned: %p\n", obj); + return obj; +} + +CL_API_ENTRY cl_int CL_API_CALL +clRetainEvent(cl_event event) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clRetainEvent(%p)\n", event); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clReleaseEvent(cl_event event) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clReleaseEvent(%p)\n", event); + free(event); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clSetUserEventStatus(cl_event event , + cl_int execution_status) CL_API_SUFFIX__VERSION_1_1 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clSetUserEventStatus(%p, %d)\n", + event, + execution_status); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clSetEventCallback(cl_event event , + cl_int command_exec_callback_type , + void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *), + void * user_data) CL_API_SUFFIX__VERSION_1_1 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clSetEventCallback(%p, %d, %p, %p)\n", + event, + command_exec_callback_type, + pfn_notify, + user_data); + pfn_notify(event, command_exec_callback_type, NULL); + test_icd_stub_log("setevent_callback(%p, %d, %p)\n", + event, + command_exec_callback_type, + NULL); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +/* Profiling APIs */ +CL_API_ENTRY cl_int CL_API_CALL +clGetEventProfilingInfo(cl_event event , + cl_profiling_info param_name , + size_t param_value_size , + void * param_value , + size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clGetEventProfilingInfo(%p, %u, %u, %p, %p)\n", + event, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +/* Flush and Finish APIs */ +CL_API_ENTRY cl_int CL_API_CALL +clFlush(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clFlush(%p)\n", command_queue); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clFinish(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clFinish(%p)\n", command_queue); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +/* Enqueued Commands APIs */ +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadBuffer(cl_command_queue command_queue , + cl_mem buffer , + cl_bool blocking_read , + size_t offset , + size_t cb , + void * ptr , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueReadBuffer(%p, %p, %u, %u, %u, %p, %u, %p, %p)\n", + command_queue, + buffer, + blocking_read, + offset, + cb, + ptr, + num_events_in_wait_list, + event_wait_list, event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadBufferRect(cl_command_queue command_queue , + cl_mem buffer , + cl_bool blocking_read , + const size_t * buffer_origin , + const size_t * host_origin , + const size_t * region , + size_t buffer_row_pitch , + size_t buffer_slice_pitch , + size_t host_row_pitch , + size_t host_slice_pitch , + void * ptr , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_1 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueReadBufferRect(%p, %p, %u, %p, %p, %p, %u, %u, %u, %u, %p, %u, %p, %p)\n", + command_queue, + buffer, + blocking_read, + buffer_origin, + host_origin, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteBuffer(cl_command_queue command_queue , + cl_mem buffer , + cl_bool blocking_write , + size_t offset , + size_t cb , + const void * ptr , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueWriteBuffer(%p, %p, %u, %u, %u, %p, %u, %p, %p)\n", + command_queue, + buffer, + blocking_write, + offset, + cb, + ptr, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteBufferRect(cl_command_queue command_queue , + cl_mem buffer , + cl_bool blocking_write , + const size_t * buffer_origin , + const size_t * host_origin , + const size_t * region , + size_t buffer_row_pitch , + size_t buffer_slice_pitch , + size_t host_row_pitch , + size_t host_slice_pitch , + const void * ptr , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_1 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueWriteBufferRect(%p, %p, %u, %p, %p, %p, %u, %u, %u, %u, %p, %u, %p, %p)\n", + command_queue, + buffer, + blocking_write, + buffer_origin, + host_origin, + region, + buffer_row_pitch, + buffer_slice_pitch, + host_row_pitch, + host_slice_pitch, + ptr, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBuffer(cl_command_queue command_queue , + cl_mem src_buffer , + cl_mem dst_buffer , + size_t src_offset , + size_t dst_offset , + size_t cb , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueCopyBuffer(%p, %p, %p, %u, %u, %u, %u, %p, %p)\n", + command_queue, + src_buffer, + dst_buffer, + src_offset, + dst_offset, + cb, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBufferRect(cl_command_queue command_queue , + cl_mem src_buffer , + cl_mem dst_buffer , + const size_t * src_origin , + const size_t * dst_origin , + const size_t * region , + size_t src_row_pitch , + size_t src_slice_pitch , + size_t dst_row_pitch , + size_t dst_slice_pitch , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_1 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueCopyBufferRect(%p, %p, %p, %p, %p, %p, %u, %u, %u, %u, %u, %p, %p)\n", + command_queue, + src_buffer, + dst_buffer, + src_origin, + dst_origin, + region, + src_row_pitch, + src_slice_pitch, + dst_row_pitch, + dst_slice_pitch, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueFillBuffer(cl_command_queue command_queue , + cl_mem buffer , + const void * pattern , + size_t pattern_size , + size_t offset , + size_t cb , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_2 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueFillBuffer(%p, %p, %p, %u, %u, %u, %u, %p, %p)\n", + command_queue, + buffer, + pattern, + pattern_size, + offset, + cb, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueFillImage(cl_command_queue command_queue , + cl_mem image , + const void * fill_color , + const size_t * origin , + const size_t * region , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_2 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueFillImage(%p, %p, %p, %p, %p, %u, %p, %p)\n", + command_queue, + image, + fill_color, + origin, + region, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReadImage(cl_command_queue command_queue , + cl_mem image , + cl_bool blocking_read , + const size_t * origin , + const size_t * region , + 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) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueReadImage(%p, %p, %u, %p, %p, %u, %u, %p, %u, %p, %p)\n", + command_queue, + image, + blocking_read, + origin, + region, + row_pitch, + slice_pitch, + ptr, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWriteImage(cl_command_queue command_queue , + cl_mem image , + cl_bool blocking_write , + const size_t * origin , + const size_t * region , + 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) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueWriteImage(%p, %p, %u, %p, %p, %u, %u, %p, %u, %p, %p)\n", + command_queue, + image, + blocking_write, + origin, + region, + input_row_pitch, + input_slice_pitch, + ptr, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyImage(cl_command_queue command_queue , + cl_mem src_image , + cl_mem dst_image , + const size_t * src_origin , + const size_t * dst_origin , + const size_t * region , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueCopyImage(%p, %p, %p, %p, %p, %p, %u, %p, %p)\n", + command_queue, + src_image, + dst_image, + src_origin, + dst_origin, + region, + num_events_in_wait_list, + event_wait_list , + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyImageToBuffer(cl_command_queue command_queue , + cl_mem src_image , + cl_mem dst_buffer , + const size_t * src_origin , + const size_t * region , + size_t dst_offset , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueCopyImageToBuffer(%p, %p, %p, %p, %p, %u, %u, %p, %p)\n", + command_queue, + src_image, + dst_buffer, + src_origin, + region, + dst_offset, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueCopyBufferToImage(cl_command_queue command_queue , + cl_mem src_buffer , + cl_mem dst_image , + size_t src_offset , + const size_t * dst_origin , + const size_t * region , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueCopyBufferToImage(%p, %p, %p, %u, %p, %p, %u, %p, %p)\n", + command_queue, + src_buffer, + dst_image, + src_offset, + dst_origin, + region, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY void * CL_API_CALL +clEnqueueMapBuffer(cl_command_queue command_queue , + cl_mem buffer , + cl_bool blocking_map , + cl_map_flags map_flags , + size_t offset , + size_t cb , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event , + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + void *return_value = (void *) malloc(sizeof(void *)); + test_icd_stub_log("clEnqueueMapBuffer(%p, %p, %u, %x, %u, %u, %u, %p, %p, %p)\n", + command_queue, + buffer, + blocking_map, + map_flags, + offset, + cb, + num_events_in_wait_list, + event_wait_list, + event, + errcode_ret); + + test_icd_stub_log("Value returned: %p\n", return_value); + return return_value; +} + +CL_API_ENTRY void * CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + void *return_value = (void *) malloc(sizeof(void *)); + test_icd_stub_log("clEnqueueMapImage(%p, %p, %u, %x, %p, %p, %p, %p, %u, %p, %p, %p)\n", + 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); + + test_icd_stub_log("Value returned: %p\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueUnmapMemObject(%p, %p, %p, %u, %p, %p)\n", + command_queue, + memobj, + mapped_ptr, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMigrateMemObjects(cl_command_queue command_queue , + cl_uint num_mem_objects , + const cl_mem * mem_objects , + cl_mem_migration_flags flags , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_2 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueMigrateMemObjects(%p, %u, %p, %x, %u, %p, %p)\n", + command_queue, + num_mem_objects, + mem_objects, + flags, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + + +CL_API_ENTRY cl_int CL_API_CALL +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) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueNDRangeKernel(%p, %p, %u, %p, %p, %p, %u, %p, %p)\n", + command_queue, + kernel, + work_dim, + global_work_offset, + global_work_size, + local_work_size, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueTask(cl_command_queue command_queue , + cl_kernel kernel , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueTask(%p, %p, %u, %p, %p)\n", + command_queue, + kernel, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueNativeKernel(cl_command_queue command_queue , + void (CL_CALLBACK *user_func)(void *), + void * args , + size_t cb_args , + cl_uint num_mem_objects , + const cl_mem * mem_list , + const void ** args_mem_loc , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueNativeKernel(%p, %p, %p, %u, %u, %p, %p, %u, %p, %p)\n", + command_queue, + user_func, + args, + cb_args, + num_mem_objects, + mem_list, + args_mem_loc, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY void * CL_API_CALL +clGetExtensionFunctionAddressForPlatform(cl_platform_id platform , + const char * func_name) CL_API_SUFFIX__VERSION_1_2 +{ + void *return_value = (void *) malloc(sizeof(void *)); + test_icd_stub_log("clGetExtensionFunctionAddressForPlatform(%p, %p)\n", + platform, + func_name); + + test_icd_stub_log("Value returned: %p\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMarkerWithWaitList(cl_command_queue command_queue , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_2 + +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueMarkerWithWaitList(%p, %u, %p, %p)\n", + command_queue, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +extern CL_API_ENTRY cl_int CL_API_CALL +clEnqueueBarrierWithWaitList(cl_command_queue command_queue , + cl_uint num_events_in_wait_list , + const cl_event * event_wait_list , + cl_event * event) CL_API_SUFFIX__VERSION_1_2 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueBarrierWithWaitList(%p, %u, %p, %p)\n", + command_queue, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +extern CL_API_ENTRY cl_int CL_API_CALL +clSetPrintfCallback(cl_context context , + void (CL_CALLBACK * pfn_notify)(cl_context program , + cl_uint printf_data_len , + char * printf_data_ptr , + void * user_data), + void * user_data) CL_API_SUFFIX__VERSION_1_2 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clSetPrintfCallback(%p, %p, %p)\n", + context, + pfn_notify, + user_data); + pfn_notify(context, 0, NULL, NULL); + test_icd_stub_log("setprintf_callback(%p, %u, %p, %p)\n", + context, + 0, + NULL, + NULL); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueMarker(cl_command_queue command_queue , + cl_event * event) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueMarker(%p, %p)\n", command_queue, event); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueWaitForEvents(cl_command_queue command_queue , + cl_uint num_events , + const cl_event * event_list) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueWaitForEvents(%p, %u, %p)\n", + command_queue, + num_events, + event_list); + + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueBarrier(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int return_value = CL_OUT_OF_RESOURCES; + test_icd_stub_log("clEnqueueBarrier(%p)\n", command_queue); + test_icd_stub_log("Value returned: %d\n", return_value); + return return_value; +} + +extern cl_int cliIcdDispatchTableCreate(CLIicdDispatchTable **outDispatchTable); + +CL_API_ENTRY cl_int CL_API_CALL +clIcdGetPlatformIDsKHR(cl_uint num_entries, + cl_platform_id * platforms, + cl_uint * num_platforms) +{ + cl_int result = CL_SUCCESS; + if (!initialized) { + result = cliIcdDispatchTableCreate(&dispatchTable); + platform = (cl_platform_id) malloc(sizeof(struct _cl_platform_id)); + memset(platform, 0, sizeof(struct _cl_platform_id)); + + platform->dispatch = dispatchTable; + platform->version = "OpenCL 1.2 Stub"; + platform->vendor = "stubvendorxxx"; + platform->profile = "stubprofilexxx"; + platform->name = "ICD_LOADER_TEST_OPENCL_STUB"; + platform->extensions = "cl_khr_icd cl_khr_gl cl_khr_d3d10"; + platform->suffix = "ilts"; + platform->dispatch = dispatchTable; + initialized = CL_TRUE; + } + + if ((platforms && num_entries >1) || + (platforms && num_entries <= 0) || + (!platforms && num_entries >= 1)) { + result = CL_INVALID_VALUE; + goto Done; + } + + if (platforms && num_entries == 1) { + platforms[0] = platform; + } + +Done: + if (num_platforms) { + *num_platforms = 1; + } + + return result; +} + diff --git a/opencl/khronos/icd/test/driver_stub/cl_ext.c b/opencl/khronos/icd/test/driver_stub/cl_ext.c new file mode 100644 index 0000000000..1363c469fc --- /dev/null +++ b/opencl/khronos/icd/test/driver_stub/cl_ext.c @@ -0,0 +1,39 @@ +/* Modifications Copyright(C) 2022 Advanced Micro Devices, Inc. + * All rights reserved. + */ + +#include + +#define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#include "CL/cl.h" +#include "CL/cl_ext.h" + +struct driverStubextFunc_st +{ + const char *name; + void *func; +}; + +#define EXT_FUNC(name) { #name, (void*)(name) } + +static struct driverStubextFunc_st clExtensions[] = +{ + EXT_FUNC(clIcdGetPlatformIDsKHR), +}; + +static const int clExtensionCount = sizeof(clExtensions) / sizeof(clExtensions[0]); + +CL_API_ENTRY void * CL_API_CALL +clGetExtensionFunctionAddress(const char *name) +{ + int ii; + + for (ii = 0; ii < clExtensionCount; ii++) { + if (!strcmp(name, clExtensions[ii].name)) { + return clExtensions[ii].func; + } + } + + return NULL; +} + diff --git a/opencl/khronos/icd/test/driver_stub/cl_gl.c b/opencl/khronos/icd/test/driver_stub/cl_gl.c new file mode 100644 index 0000000000..c69b015645 --- /dev/null +++ b/opencl/khronos/icd/test/driver_stub/cl_gl.c @@ -0,0 +1,225 @@ +/* Modifications Copyright(C) 2022 Advanced Micro Devices, Inc. + * All rights reserved. + */ + +#include +#include +#include + +// Need to rename all CL API functions to prevent ICD loader functions calling +// themselves via the dispatch table. Include this before cl headers. +#include "rename_api.h" + +#define SIZE_T_MAX (size_t) 0xFFFFFFFFFFFFFFFFULL + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLBuffer(cl_context context , + cl_mem_flags flags , + cl_GLuint bufret_mem , + int * errcode_ret ) CL_API_SUFFIX__VERSION_1_0 +{ + cl_mem ret_mem = (cl_mem)(SIZE_T_MAX); + test_icd_stub_log("clCreateFromGLBuffer(%p, %x, %u, %p)\n", + context, + flags, + bufret_mem, + errcode_ret); + test_icd_stub_log("Value returned: %p\n", + ret_mem); + return ret_mem; +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLTexture(cl_context context , + cl_mem_flags flags , + cl_GLenum target , + cl_GLint miplevel , + cl_GLuint texture , + cl_int * errcode_ret ) CL_API_SUFFIX__VERSION_1_2 +{ + cl_mem ret_mem = (cl_mem)(SIZE_T_MAX); + test_icd_stub_log("clCreateFromGLTexture(%p, %x, %d, %d, %u, %p)\n", + context , + flags , + target , + miplevel , + texture , + errcode_ret ); + test_icd_stub_log("Value returned: %p\n", + ret_mem); + return ret_mem; +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLTexture2D(cl_context context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texture, + cl_int * errcode_ret ) CL_API_SUFFIX__VERSION_1_0 +{ + cl_mem ret_mem = (cl_mem)(SIZE_T_MAX); + test_icd_stub_log("clCreateFromGLTexture2D(%p, %x, %d, %d, %u, %p)\n", + context, + flags, + target, + miplevel, + texture, + errcode_ret ); + test_icd_stub_log("Value returned: %p\n", + ret_mem); + return ret_mem; +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLTexture3D(cl_context context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texture, + cl_int * errcode_ret ) CL_API_SUFFIX__VERSION_1_0 + +{ + cl_mem ret_mem = (cl_mem)(SIZE_T_MAX); + test_icd_stub_log("clCreateFromGLTexture3D(%p, %x, %d, %d, %u, %p)\n", + context, + flags, + target, + miplevel, + texture, + errcode_ret ); + test_icd_stub_log("Value returned: %p\n", + ret_mem); + return ret_mem; +} + +CL_API_ENTRY cl_mem CL_API_CALL +clCreateFromGLRenderbuffer(cl_context context, + cl_mem_flags flags, + cl_GLuint renderbuffer, + cl_int * errcode_ret ) CL_API_SUFFIX__VERSION_1_0 +{ + cl_mem ret_mem = (cl_mem)(SIZE_T_MAX); + test_icd_stub_log("clCreateFromGLRenderbuffer(%p, %x, %d, %p)\n", + context, + flags, + renderbuffer, + errcode_ret); + test_icd_stub_log("Value returned: %p\n", + ret_mem); + return ret_mem; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetGLObjectInfo(cl_mem memobj, + cl_gl_object_type * gl_object_type, + cl_GLuint * gl_object_name ) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int ret_val = -5; + test_icd_stub_log("clGetGLObjectInfo(%p, %p, %p)\n", + memobj, + gl_object_type, + gl_object_name); + test_icd_stub_log("Value returned: %p\n", + ret_val); + return ret_val; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetGLTextureInfo(cl_mem memobj, + cl_gl_texture_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret ) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int ret_val = -5; + test_icd_stub_log("clGetGLTextureInfo(%p, %u, %u, %p, %p)\n", + memobj, + param_name, + param_value_size, + param_value, + param_value_size_ret ); + test_icd_stub_log("Value returned: %p\n", + ret_val); + return ret_val; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueAcquireGLObjects(cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event ) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int ret_val = -5; + test_icd_stub_log("clEnqueueAcquireGLObjects(%p, %u, %p, %u, %p, %p)\n", + command_queue, + num_objects, + mem_objects, + num_events_in_wait_list, + event_wait_list, + event); + + test_icd_stub_log("Value returned: %p\n", + ret_val); + return ret_val; +} + +CL_API_ENTRY cl_int CL_API_CALL +clEnqueueReleaseGLObjects(cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event ) CL_API_SUFFIX__VERSION_1_0 + +{ + cl_int ret_val = -5; + test_icd_stub_log("clEnqueueReleaseGLObjects(%p, %u, %p, %u, %p, %p)\n", + command_queue, + num_objects, + mem_objects, + num_events_in_wait_list, + event_wait_list, + event); + test_icd_stub_log("Value returned: %p\n", + ret_val); + return ret_val; +} + +CL_API_ENTRY cl_int CL_API_CALL +clGetGLContextInfoKHR(const cl_context_properties * properties, + cl_gl_context_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret ) CL_API_SUFFIX__VERSION_1_0 +{ + cl_int ret_val = -5; + test_icd_stub_log("clGetGLContextInfoKHR(%p, %u, %u, %p, %p)\n", + properties, + param_name, + param_value_size, + param_value, + param_value_size_ret); + + test_icd_stub_log("Value returned: %p\n", + ret_val); + return ret_val; +} + +CL_API_ENTRY cl_event CL_API_CALL +clCreateEventFromGLsyncKHR(cl_context context , + cl_GLsync cl_GLsync , + cl_int * errcode_ret ) CL_EXT_SUFFIX__VERSION_1_1 + +{ + cl_event ret_event = (cl_event)(SIZE_T_MAX); + test_icd_stub_log("clCreateEventFromGLsyncKHR(%p, %p, %p)\n", + context, + cl_GLsync, + errcode_ret); + test_icd_stub_log("Value returned: %p\n", + ret_event); + return ret_event; +} diff --git a/opencl/khronos/icd/test/driver_stub/driver_stub.def b/opencl/khronos/icd/test/driver_stub/driver_stub.def new file mode 100644 index 0000000000..1ec276011a --- /dev/null +++ b/opencl/khronos/icd/test/driver_stub/driver_stub.def @@ -0,0 +1,2 @@ +EXPORTS +clGetExtensionFunctionAddress diff --git a/opencl/khronos/icd/test/driver_stub/icd.c b/opencl/khronos/icd/test/driver_stub/icd.c new file mode 100644 index 0000000000..faa5b46ca1 --- /dev/null +++ b/opencl/khronos/icd/test/driver_stub/icd.c @@ -0,0 +1,190 @@ +/* Modifications Copyright(C) 2022 Advanced Micro Devices, Inc. + * All rights reserved. + */ + +#include +#include +#include +#include +#include "icd_structs.h" + +#define CL_USE_DEPRECATED_OPENCL_1_0_APIS +#define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#define CL_USE_DEPRECATED_OPENCL_1_2_APIS + +// Need to rename all CL API functions to prevent ICD loader functions calling +// themselves via the dispatch table. Include this before cl headers. +#include "rename_api.h" + +#include "CL/cl.h" +#include "CL/cl_gl.h" +#include "CL/cl_gl_ext.h" + +/* + * Prototypes for deprecated functions no longer present in cl.h + */ +extern CL_API_ENTRY cl_int CL_API_CALL +clSetCommandQueueProperty(cl_command_queue /* command_queue */, + cl_command_queue_properties /* properties */, + cl_bool /* enable */, + cl_command_queue_properties * /* old_properties */); + +#define ICD_DISPATCH_TABLE_ENTRY(fn) \ + assert(dispatchTable->entryCount < 256); \ + dispatchTable->entries[dispatchTable->entryCount++] = (void*)(fn) + +cl_int cliIcdDispatchTableCreate(CLIicdDispatchTable **outDispatchTable) +{ + CLIicdDispatchTable *dispatchTable = NULL; + cl_int result = CL_SUCCESS; + + // allocate the public handle + dispatchTable = (CLIicdDispatchTable *) malloc(sizeof(*dispatchTable)); + if (!dispatchTable) { + result = CL_OUT_OF_HOST_MEMORY; + goto Error; + } + memset(dispatchTable, 0, sizeof(*dispatchTable)); + + // OpenCL 1.0 + ICD_DISPATCH_TABLE_ENTRY ( clGetPlatformIDs ); + ICD_DISPATCH_TABLE_ENTRY ( clGetPlatformInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clGetDeviceIDs ); + ICD_DISPATCH_TABLE_ENTRY ( clGetDeviceInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateContext ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateContextFromType ); + ICD_DISPATCH_TABLE_ENTRY ( clRetainContext ); + ICD_DISPATCH_TABLE_ENTRY ( clReleaseContext ); + ICD_DISPATCH_TABLE_ENTRY ( clGetContextInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateCommandQueue ); + ICD_DISPATCH_TABLE_ENTRY ( clRetainCommandQueue ); + ICD_DISPATCH_TABLE_ENTRY ( clReleaseCommandQueue ); + ICD_DISPATCH_TABLE_ENTRY ( clGetCommandQueueInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clSetCommandQueueProperty ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateBuffer ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateImage2D ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateImage3D ); + ICD_DISPATCH_TABLE_ENTRY ( clRetainMemObject ); + ICD_DISPATCH_TABLE_ENTRY ( clReleaseMemObject ); + ICD_DISPATCH_TABLE_ENTRY ( clGetSupportedImageFormats ); + ICD_DISPATCH_TABLE_ENTRY ( clGetMemObjectInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clGetImageInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateSampler ); + ICD_DISPATCH_TABLE_ENTRY ( clRetainSampler ); + ICD_DISPATCH_TABLE_ENTRY ( clReleaseSampler ); + ICD_DISPATCH_TABLE_ENTRY ( clGetSamplerInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateProgramWithSource ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateProgramWithBinary ); + ICD_DISPATCH_TABLE_ENTRY ( clRetainProgram ); + ICD_DISPATCH_TABLE_ENTRY ( clReleaseProgram ); + ICD_DISPATCH_TABLE_ENTRY ( clBuildProgram ); + ICD_DISPATCH_TABLE_ENTRY ( clUnloadCompiler ); + ICD_DISPATCH_TABLE_ENTRY ( clGetProgramInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clGetProgramBuildInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateKernel ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateKernelsInProgram ); + ICD_DISPATCH_TABLE_ENTRY ( clRetainKernel ); + ICD_DISPATCH_TABLE_ENTRY ( clReleaseKernel ); + ICD_DISPATCH_TABLE_ENTRY ( clSetKernelArg ); + ICD_DISPATCH_TABLE_ENTRY ( clGetKernelInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clGetKernelWorkGroupInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clWaitForEvents ); + ICD_DISPATCH_TABLE_ENTRY ( clGetEventInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clRetainEvent ); + ICD_DISPATCH_TABLE_ENTRY ( clReleaseEvent ); + ICD_DISPATCH_TABLE_ENTRY ( clGetEventProfilingInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clFlush ); + ICD_DISPATCH_TABLE_ENTRY ( clFinish ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueReadBuffer ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueWriteBuffer ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueCopyBuffer ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueReadImage ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueWriteImage ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueCopyImage ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueCopyImageToBuffer ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueCopyBufferToImage ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueMapBuffer ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueMapImage ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueUnmapMemObject ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueNDRangeKernel ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueTask ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueNativeKernel ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueMarker ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueWaitForEvents ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueBarrier ); + ICD_DISPATCH_TABLE_ENTRY ( clGetExtensionFunctionAddress ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateFromGLBuffer ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateFromGLTexture2D ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateFromGLTexture3D ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateFromGLRenderbuffer ); + ICD_DISPATCH_TABLE_ENTRY ( clGetGLObjectInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clGetGLTextureInfo ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueAcquireGLObjects ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueReleaseGLObjects ); + + // cl_khr_gl_sharing + ICD_DISPATCH_TABLE_ENTRY ( clGetGLContextInfoKHR ); + + // cl_khr_d3d10_sharing (windows-only) +#if 0 && defined(_WIN32) + ICD_DISPATCH_TABLE_ENTRY ( clGetDeviceIDsFromD3D10KHR ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateFromD3D10BufferKHR ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateFromD3D10Texture2DKHR ); + ICD_DISPATCH_TABLE_ENTRY ( clCreateFromD3D10Texture3DKHR ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueAcquireD3D10ObjectsKHR ); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueReleaseD3D10ObjectsKHR ); +#else + ICD_DISPATCH_TABLE_ENTRY( NULL ); + ICD_DISPATCH_TABLE_ENTRY( NULL ); + ICD_DISPATCH_TABLE_ENTRY( NULL ); + ICD_DISPATCH_TABLE_ENTRY( NULL ); + ICD_DISPATCH_TABLE_ENTRY( NULL ); + ICD_DISPATCH_TABLE_ENTRY( NULL ); +#endif + + // OpenCL 1.1 + ICD_DISPATCH_TABLE_ENTRY ( clSetEventCallback); + ICD_DISPATCH_TABLE_ENTRY ( clCreateSubBuffer); + ICD_DISPATCH_TABLE_ENTRY ( clSetMemObjectDestructorCallback); + ICD_DISPATCH_TABLE_ENTRY ( clCreateUserEvent); + ICD_DISPATCH_TABLE_ENTRY ( clSetUserEventStatus); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueReadBufferRect); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueWriteBufferRect); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueCopyBufferRect); + + ICD_DISPATCH_TABLE_ENTRY ( /*clCreateSubDevicesEXT*/NULL); + ICD_DISPATCH_TABLE_ENTRY ( /*clRetainDeviceEXT*/ NULL); + ICD_DISPATCH_TABLE_ENTRY ( /*clReleaseDevice*/NULL); + + ICD_DISPATCH_TABLE_ENTRY ( clCreateEventFromGLsyncKHR); + + ICD_DISPATCH_TABLE_ENTRY ( clCreateSubDevices); + ICD_DISPATCH_TABLE_ENTRY ( clRetainDevice); + ICD_DISPATCH_TABLE_ENTRY ( clReleaseDevice); + ICD_DISPATCH_TABLE_ENTRY ( clCreateImage); + ICD_DISPATCH_TABLE_ENTRY ( clCreateProgramWithBuiltInKernels); + ICD_DISPATCH_TABLE_ENTRY ( clCompileProgram); + ICD_DISPATCH_TABLE_ENTRY ( clLinkProgram); + ICD_DISPATCH_TABLE_ENTRY ( clUnloadPlatformCompiler); + ICD_DISPATCH_TABLE_ENTRY ( clGetKernelArgInfo); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueFillBuffer); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueFillImage); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueMigrateMemObjects); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueMarkerWithWaitList); + ICD_DISPATCH_TABLE_ENTRY ( clEnqueueBarrierWithWaitList); + ICD_DISPATCH_TABLE_ENTRY ( clGetExtensionFunctionAddressForPlatform); + ICD_DISPATCH_TABLE_ENTRY ( clCreateFromGLTexture); + + // return success + *outDispatchTable = dispatchTable; + return CL_SUCCESS; + +Error: + return result; +} + +void +cliIcdDispatchTableDestroy(CLIicdDispatchTable *dispatchTable) +{ + free(dispatchTable); +} diff --git a/opencl/khronos/icd/test/driver_stub/icd_driver_exports.map b/opencl/khronos/icd/test/driver_stub/icd_driver_exports.map new file mode 100644 index 0000000000..c6386a26ea --- /dev/null +++ b/opencl/khronos/icd/test/driver_stub/icd_driver_exports.map @@ -0,0 +1,8 @@ +{ + global: +clGetExtensionFunctionAddress; +clGetPlatformInfo; + + local: + *; +}; diff --git a/opencl/khronos/icd/test/driver_stub/icd_structs.h b/opencl/khronos/icd/test/driver_stub/icd_structs.h new file mode 100644 index 0000000000..4b7e68b118 --- /dev/null +++ b/opencl/khronos/icd/test/driver_stub/icd_structs.h @@ -0,0 +1,18 @@ +#ifndef _ICD_STRUCTS_H_ +#define _ICD_STRUCTS_H_ + +typedef struct CLIicdDispatchTable_st CLIicdDispatchTable; +typedef struct CLIplatform_st CLIplatform; + +struct CLIicdDispatchTable_st +{ + void *entries[256]; + int entryCount; +}; + +struct CLIplatform_st +{ + CLIicdDispatchTable* dispatch; +}; + +#endif /* _ICD_STRUCTS_H_ */ diff --git a/opencl/khronos/icd/test/driver_stub/rename_api.h b/opencl/khronos/icd/test/driver_stub/rename_api.h new file mode 100644 index 0000000000..7d5130cec3 --- /dev/null +++ b/opencl/khronos/icd/test/driver_stub/rename_api.h @@ -0,0 +1,106 @@ +#ifndef _RENAME_API_H_ +#define _RENAME_API_H_ + +#define clGetPlatformIDs ___clGetPlatformIDs +#define clGetPlatformInfo ___clGetPlatformInfo +#define clGetDeviceIDs ___clGetDeviceIDs +#define clGetDeviceInfo ___clGetDeviceInfo +#define clCreateSubDevices ___clCreateSubDevices +#define clRetainDevice ___clRetainDevice +#define clReleaseDevice ___clReleaseDevice +#define clCreateContext ___clCreateContext +#define clCreateContextFromType ___clCreateContextFromType +#define clRetainContext ___clRetainContext +#define clReleaseContext ___clReleaseContext +#define clGetContextInfo ___clGetContextInfo +#define clCreateCommandQueue ___clCreateCommandQueue +#define clSetCommandQueueProperty ___clSetCommandQueueProperty +#define clRetainCommandQueue ___clRetainCommandQueue +#define clReleaseCommandQueue ___clReleaseCommandQueue +#define clGetCommandQueueInfo ___clGetCommandQueueInfo +#define clCreateBuffer ___clCreateBuffer +#define clCreateSubBuffer ___clCreateSubBuffer +#define clCreateImage ___clCreateImage +#define clCreateImage2D ___clCreateImage2D +#define clCreateImage3D ___clCreateImage3D +#define clRetainMemObject ___clRetainMemObject +#define clReleaseMemObject ___clReleaseMemObject +#define clGetSupportedImageFormats ___clGetSupportedImageFormats +#define clGetMemObjectInfo ___clGetMemObjectInfo +#define clGetImageInfo ___clGetImageInfo +#define clSetMemObjectDestructorCallback ___clSetMemObjectDestructorCallback +#define clCreateSampler ___clCreateSampler +#define clRetainSampler ___clRetainSampler +#define clReleaseSampler ___clReleaseSampler +#define clGetSamplerInfo ___clGetSamplerInfo +#define clCreateProgramWithSource ___clCreateProgramWithSource +#define clCreateProgramWithBinary ___clCreateProgramWithBinary +#define clCreateProgramWithBuiltInKernels ___clCreateProgramWithBuiltInKernels +#define clRetainProgram ___clRetainProgram +#define clReleaseProgram ___clReleaseProgram +#define clBuildProgram ___clBuildProgram +#define clUnloadCompiler ___clUnloadCompiler +#define clCompileProgram ___clCompileProgram +#define clLinkProgram ___clLinkProgram +#define clUnloadPlatformCompiler ___clUnloadPlatformCompiler +#define clGetProgramInfo ___clGetProgramInfo +#define clGetProgramBuildInfo ___clGetProgramBuildInfo +#define clCreateKernel ___clCreateKernel +#define clCreateKernelsInProgram ___clCreateKernelsInProgram +#define clRetainKernel ___clRetainKernel +#define clReleaseKernel ___clReleaseKernel +#define clSetKernelArg ___clSetKernelArg +#define clGetKernelInfo ___clGetKernelInfo +#define clGetKernelArgInfo ___clGetKernelArgInfo +#define clGetKernelWorkGroupInfo ___clGetKernelWorkGroupInfo +#define clWaitForEvents ___clWaitForEvents +#define clGetEventInfo ___clGetEventInfo +#define clCreateUserEvent ___clCreateUserEvent +#define clRetainEvent ___clRetainEvent +#define clReleaseEvent ___clReleaseEvent +#define clSetUserEventStatus ___clSetUserEventStatus +#define clSetEventCallback ___clSetEventCallback +#define clGetEventProfilingInfo ___clGetEventProfilingInfo +#define clFlush ___clFlush +#define clFinish ___clFinish +#define clEnqueueReadBuffer ___clEnqueueReadBuffer +#define clEnqueueReadBufferRect ___clEnqueueReadBufferRect +#define clEnqueueWriteBuffer ___clEnqueueWriteBuffer +#define clEnqueueWriteBufferRect ___clEnqueueWriteBufferRect +#define clEnqueueCopyBuffer ___clEnqueueCopyBuffer +#define clEnqueueCopyBufferRect ___clEnqueueCopyBufferRect +#define clEnqueueFillBuffer ___clEnqueueFillBuffer +#define clEnqueueFillImage ___clEnqueueFillImage +#define clEnqueueReadImage ___clEnqueueReadImage +#define clEnqueueWriteImage ___clEnqueueWriteImage +#define clEnqueueCopyImage ___clEnqueueCopyImage +#define clEnqueueCopyImageToBuffer ___clEnqueueCopyImageToBuffer +#define clEnqueueCopyBufferToImage ___clEnqueueCopyBufferToImage +#define clEnqueueMapBuffer ___clEnqueueMapBuffer +#define clEnqueueMapImage ___clEnqueueMapImage +#define clEnqueueUnmapMemObject ___clEnqueueUnmapMemObject +#define clEnqueueMigrateMemObjects ___clEnqueueMigrateMemObjects +#define clEnqueueNDRangeKernel ___clEnqueueNDRangeKernel +#define clEnqueueTask ___clEnqueueTask +#define clEnqueueNativeKernel ___clEnqueueNativeKernel +#define clGetExtensionFunctionAddressForPlatform ___clGetExtensionFunctionAddressForPlatform +#define clEnqueueMarkerWithWaitList ___clEnqueueMarkerWithWaitList +#define clEnqueueBarrierWithWaitList ___clEnqueueBarrierWithWaitList +#define clSetPrintfCallback ___clSetPrintfCallback +#define clEnqueueMarker ___clEnqueueMarker +#define clEnqueueWaitForEvents ___clEnqueueWaitForEvents +#define clEnqueueBarrier ___clEnqueueBarrier + +#define clCreateFromGLBuffer ___clCreateFromGLBuffer +#define clCreateFromGLTexture ___clCreateFromGLTexture +#define clCreateFromGLTexture2D ___clCreateFromGLTexture2D +#define clCreateFromGLTexture3D ___clCreateFromGLTexture3D +#define clCreateFromGLRenderbuffer ___clCreateFromGLRenderbuffer +#define clGetGLObjectInfo ___clGetGLObjectInfo +#define clGetGLTextureInfo ___clGetGLTextureInfo +#define clEnqueueAcquireGLObjects ___clEnqueueAcquireGLObjects +#define clEnqueueReleaseGLObjects ___clEnqueueReleaseGLObjects +#define clGetGLContextInfoKHR ___clGetGLContextInfoKHR +#define clCreateEventFromGLsyncKHR ___clCreateEventFromGLsyncKHR + +#endif /* __RENAME_API_H__ */ diff --git a/opencl/khronos/icd/test/inc/platform/icd_test_log.h b/opencl/khronos/icd/test/inc/platform/icd_test_log.h new file mode 100644 index 0000000000..6db0bfe6ab --- /dev/null +++ b/opencl/khronos/icd/test/inc/platform/icd_test_log.h @@ -0,0 +1,20 @@ +#ifndef _ICD_TEST_LOG_H_ +#define _ICD_TEST_LOG_H_ + +#if defined (_WIN32) +#define DllExport __declspec( dllexport ) +#else +#define DllExport +#endif + +DllExport int test_icd_initialize_app_log(void); +DllExport void test_icd_app_log(const char *format, ...); +DllExport void test_icd_close_app_log(void); +DllExport char *test_icd_get_stub_log(void); + +DllExport int test_icd_initialize_stub_log(void); +DllExport void test_icd_stub_log(const char *format, ...); +DllExport void test_icd_close_stub_log(void); +DllExport char *test_icd_get_app_log(void); + +#endif /* _ICD_TEST_LOG_H_ */ diff --git a/opencl/khronos/icd/test/loader_test/CMakeLists.txt b/opencl/khronos/icd/test/loader_test/CMakeLists.txt new file mode 100644 index 0000000000..ddc675b422 --- /dev/null +++ b/opencl/khronos/icd/test/loader_test/CMakeLists.txt @@ -0,0 +1,15 @@ +add_executable (icd_loader_test + test_kernel.c + main.c + test_platforms.c + icd_test_match.c + test_program_objects.c + test_sampler_objects.c + test_buffer_object.c + test_cl_runtime.c + callbacks.c + test_create_calls.c + test_clgl.c + test_image_objects.c ) + +target_link_libraries (icd_loader_test OpenCL IcdLog) diff --git a/opencl/khronos/icd/test/loader_test/callbacks.c b/opencl/khronos/icd/test/loader_test/callbacks.c new file mode 100644 index 0000000000..edbedf4d42 --- /dev/null +++ b/opencl/khronos/icd/test/loader_test/callbacks.c @@ -0,0 +1,43 @@ +#include +#include +#include + +void CL_CALLBACK createcontext_callback(const char* _a, const void* _b, size_t _c, void* _d) +{ + test_icd_app_log("createcontext_callback(%p, %p, %u, %p)\n", + _a, + _b, + _c, + _d); +} + +void CL_CALLBACK setmemobjectdestructor_callback(cl_mem _a, void* _b) +{ + test_icd_app_log("setmemobjectdestructor_callback(%p, %p)\n", + _a, + _b); +} + +void CL_CALLBACK program_callback(cl_program _a, void* _b) +{ + test_icd_app_log("program_callback(%p, %p)\n", + _a, + _b); +} + +void CL_CALLBACK setevent_callback(cl_event _a, cl_int _b, void* _c) +{ + test_icd_app_log("setevent_callback(%p, %d, %p)\n", + _a, + _b, + _c); +} + +void CL_CALLBACK setprintf_callback(cl_context _a, cl_uint _b, char* _c, void* _d ) +{ + test_icd_app_log("setprintf_callback(%p, %u, %p, %p)\n", + _a, + _b, + _c, + _d); +} diff --git a/opencl/khronos/icd/test/loader_test/icd_test_match.c b/opencl/khronos/icd/test/loader_test/icd_test_match.c new file mode 100644 index 0000000000..a8330b4a26 --- /dev/null +++ b/opencl/khronos/icd/test/loader_test/icd_test_match.c @@ -0,0 +1,38 @@ +#include +#include +#ifndef __APPLE__ +#include +#endif +#include + +int test_icd_match() +{ + int error = 0; + char *app_log = NULL, *stub_log = NULL; + + app_log = test_icd_get_app_log(); + if (!app_log) { + printf("ERROR: Could not retrieve app log\n"); + error = 1; + goto End; + } + + stub_log = test_icd_get_stub_log(); + if (!stub_log) { + printf("ERROR: Could not retrieve stub log\n"); + error = 1; + goto End; + } + + if (strcmp(app_log, stub_log)) { + printf("ERROR: App log and stub log differ.\n"); + error = 1; + goto End; + } + +End: + free(app_log); + free(stub_log); + return error; +} + diff --git a/opencl/khronos/icd/test/loader_test/main.c b/opencl/khronos/icd/test/loader_test/main.c new file mode 100644 index 0000000000..70f65151b8 --- /dev/null +++ b/opencl/khronos/icd/test/loader_test/main.c @@ -0,0 +1,49 @@ +/* Modifications Copyright(C) 2022 Advanced Micro Devices, Inc. + * All rights reserved. + */ + +#include +#include +#include +#include "param_struct.h" + +extern int test_create_calls(); +extern int test_platforms(); +extern int test_cl_runtime(); +extern int test_kernel(); +extern int test_buffer_object(); +extern int test_program_objects(); +extern int test_image_objects(); +extern int test_sampler_objects(); +extern int test_OpenGL_share(); +extern int test_release_calls(); + +extern int test_icd_match(); + +int main(int argc, char **argv) +{ + test_icd_initialize_app_log(); + test_icd_initialize_stub_log(); + + test_create_calls(); + test_platforms(); + test_cl_runtime(); + test_kernel(); + test_buffer_object(); + test_program_objects(); + test_image_objects(); + test_sampler_objects(); + test_OpenGL_share(); + test_release_calls(); + + test_icd_close_app_log(); + test_icd_close_stub_log(); + + if (test_icd_match()) { + printf("ICD Loader Test FAILED\n"); + return 1; + } else { + printf("ICD Loader Test PASSED\n"); + return 0; + } +} diff --git a/opencl/khronos/icd/test/loader_test/param_struct.h b/opencl/khronos/icd/test/loader_test/param_struct.h new file mode 100644 index 0000000000..06a1f2bf80 --- /dev/null +++ b/opencl/khronos/icd/test/loader_test/param_struct.h @@ -0,0 +1,1110 @@ +#ifndef _PARAM_STRUCT_H_ +#define _PARAM_STRUCT_H_ + +#include +#include +#include + +struct clCreateCommandQueue_st +{ + cl_context context; + cl_device_id device; + cl_command_queue_properties properties; + cl_int *errcode_ret; +}; + +struct clSetCommandQueueProperty_st +{ + cl_command_queue command_queue; + cl_command_queue_properties properties; + cl_bool enable; + cl_command_queue_properties *old_properties; +}; + +struct clGetCommandQueueInfo_st +{ + cl_command_queue command_queue; + cl_command_queue_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +struct clCreateContext_st +{ + const cl_context_properties *properties; + cl_uint num_devices; + const cl_device_id *devices; + void (CL_CALLBACK*pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data); + void *user_data; + cl_int *errcode_ret; +}; + +struct clCreateContextFromType_st +{ + const cl_context_properties *properties; + cl_device_type device_type; + void (CL_CALLBACK *pfn_notify)(const char *errinfo, const void *private_info, size_t cb,void *user_data); + void *user_data; + cl_int *errcode_ret; +}; + +struct clRetainContext_st +{ + cl_context context; +}; + +struct clReleaseContext_st +{ + cl_context context; +}; + +struct clGetContextInfo_st +{ + cl_context context; + cl_context_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +struct clGetPlatformIDs_st +{ + cl_uint num_entries; + cl_platform_id *platforms; + cl_uint *num_platforms; +}; + +struct clGetPlatformInfo_st +{ + cl_platform_id platform; + cl_platform_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +struct clGetDeviceIDs_st +{ + cl_platform_id platform; + cl_device_type device_type; + cl_uint num_entries; + cl_device_id *devices; + cl_uint *num_devices; +}; + +struct clRetainCommandQueue_st +{ + cl_command_queue command_queue; +}; + +struct clReleaseCommandQueue_st +{ + cl_command_queue command_queue; +}; + +#define NUM_ITEMS_clCreateCommandQueue 1 +#define NUM_ITEMS_clRetainCommandQueue 1 +#define NUM_ITEMS_clReleaseCommandQueue 1 +#define NUM_ITEMS_clGetCommandQueueInfo 1 +#define NUM_ITEMS_clSetCommandQueueProperty 1 +#define NUM_ITEMS_clCreateContext 1 +#define NUM_ITEMS_clCreateContextFromType 1 +#define NUM_ITEMS_clRetainContext 1 +#define NUM_ITEMS_clReleaseContext 1 +#define NUM_ITEMS_clGetContextInfo 1 +#define NUM_ITEMS_clGetPlatformIDs 1 +#define NUM_ITEMS_clGetPlatformInfo 1 +#define NUM_ITEMS_clGetDeviceIDs 1 +#define NUM_ITEMS_clGetDeviceInfo 1 +#define NUM_ITEMS_clCreateSubDevices 1 +#define NUM_ITEMS_clRetainDevice 1 +#define NUM_ITEMS_clReleaseDevice 1 + +struct clGetDeviceInfo_st +{ + cl_device_id device; + cl_device_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +struct clCreateSubDevices_st +{ + cl_device_id in_device; + cl_device_partition_property *properties; + cl_uint num_entries; + cl_device_id *out_devices; + cl_uint *num_devices; +}; + +struct clRetainDevice_st +{ + cl_device_id device; +}; + +struct clReleaseDevice_st +{ + cl_device_id device; +}; + + +#define NUM_ITEMS_clCreateBuffer 1 +#define NUM_ITEMS_clCreateSubBuffer 1 +#define NUM_ITEMS_clEnqueueReadBuffer 1 +#define NUM_ITEMS_clEnqueueWriteBuffer 1 +#define NUM_ITEMS_clEnqueueReadBufferRect 1 +#define NUM_ITEMS_clEnqueueWriteBufferRect 1 +#define NUM_ITEMS_clEnqueueFillBuffer 1 +#define NUM_ITEMS_clEnqueueCopyBuffer 1 +#define NUM_ITEMS_clEnqueueCopyBufferRect 1 +#define NUM_ITEMS_clEnqueueMapBuffer 1 +#define NUM_ITEMS_clRetainMemObject 1 +#define NUM_ITEMS_clReleaseMemObject 1 +#define NUM_ITEMS_clSetMemObjectDestructorCallback 1 +#define NUM_ITEMS_clEnqueueUnmapMemObject 1 +#define NUM_ITEMS_clGetMemObjectInfo 1 + +struct clCreateBuffer_st +{ + cl_context context; + cl_mem_flags flags; + size_t size; + void *host_ptr; + cl_int *errcode_ret; +}; +struct clCreateSubBuffer_st +{ + cl_mem buffer; + cl_mem_flags flags; + cl_buffer_create_type buffer_create_type; + const void *buffer_create_info; + cl_int *errcode_ret; +}; + +struct clEnqueueReadBuffer_st +{ + cl_command_queue command_queue; + cl_mem buffer; + cl_bool blocking_read; + size_t offset; + size_t cb; + void *ptr; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueWriteBuffer_st +{ + cl_command_queue command_queue; + cl_mem buffer; + cl_bool blocking_write; + size_t offset; + size_t cb; + const void *ptr; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueReadBufferRect_st +{ + cl_command_queue command_queue; + cl_mem buffer; + cl_bool blocking_read; + const size_t * buffer_offset; + const size_t * host_offset; + const size_t * region; + size_t buffer_row_pitch; + size_t buffer_slice_pitch; + size_t host_row_pitch; + size_t host_slice_pitch; + void *ptr; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueWriteBufferRect_st +{ + cl_command_queue command_queue; + cl_mem buffer; + cl_bool blocking_write; + const size_t *buffer_offset; + const size_t *host_offset; + const size_t *region; + size_t buffer_row_pitch; + size_t buffer_slice_pitch; + size_t host_row_pitch; + size_t host_slice_pitch; + void *ptr; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueFillBuffer_st +{ + cl_command_queue command_queue; + cl_mem buffer; + const void *pattern; + size_t pattern_size; + size_t offset; + size_t cb; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueCopyBuffer_st +{ + cl_command_queue command_queue; + cl_mem src_buffer; + cl_mem dst_buffer; + size_t src_offset; + size_t dst_offset; + size_t cb; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueCopyBufferRect_st +{ + cl_command_queue command_queue; + cl_mem src_buffer; + cl_mem dst_buffer; + const size_t *src_origin; + const size_t *dst_origin; + const size_t *region; + size_t src_row_pitch; + size_t src_slice_pitch; + size_t dst_row_pitch; + size_t dst_slice_pitch; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueMapBuffer_st +{ + cl_command_queue command_queue; + cl_mem buffer; + cl_bool blocking_map; + cl_map_flags map_flags; + size_t offset; + size_t cb; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; + cl_int *errcode_ret; +}; + +struct clRetainMemObject_st +{ + cl_mem memobj; +}; + +struct clReleaseMemObject_st +{ + cl_mem memobj; +}; + +struct clSetMemObjectDestructorCallback_st +{ + cl_mem memobj; + void (CL_CALLBACK *pfn_notify)(cl_mem memobj, void *user_data); + void *user_data; +}; + +struct clEnqueueUnmapMemObject_st +{ + 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; +}; + +struct clGetMemObjectInfo_st +{ + cl_mem memobj; + cl_mem_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +#define NUM_ITEMS_clCreateProgramWithSource 1 +#define NUM_ITEMS_clCreateProgramWithBinary 1 +#define NUM_ITEMS_clCreateProgramWithBuiltInKernels 1 +#define NUM_ITEMS_clRetainProgram 1 +#define NUM_ITEMS_clReleaseProgram 1 +#define NUM_ITEMS_clBuildProgram 1 +#define NUM_ITEMS_clCompileProgram 1 +#define NUM_ITEMS_clLinkProgram 1 +#define NUM_ITEMS_clUnloadPlatformCompiler 1 +#define NUM_ITEMS_clGetProgramInfo 1 +#define NUM_ITEMS_clGetProgramBuildInfo 1 +#define NUM_ITEMS_clUnloadCompiler 1 +#define NUM_ITEMS_clGetExtensionFunctionAddress 1 +#define NUM_ITEMS_clGetExtensionFunctionAddressForPlatform 1 + +struct clCreateProgramWithSource_st +{ + cl_context context; + cl_uint count; + const char **strings; + const size_t *lengths; + cl_int *errcode_ret; +}; + +struct clCreateProgramWithBinary_st +{ + 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; +}; + +struct clCreateProgramWithBuiltInKernels_st +{ + cl_context context; + cl_uint num_devices; + const cl_device_id *device_list; + const char *kernel_names; + cl_int *errcode_ret; +}; + +struct clRetainProgram_st +{ + cl_program program; +}; + +struct clReleaseProgram_st +{ + cl_program program; +}; + +struct clBuildProgram_st +{ + 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; +}; + +struct clCompileProgram_st +{ + cl_program program; + cl_uint num_devices; + const cl_device_id *device_list; + const char *options; + cl_uint num_input_headers; + const cl_program *headers; + const char **header_include_names; + void (CL_CALLBACK *pfn_notify)(cl_program program, void * user_data); + void *user_data; +}; + +struct clLinkProgram_st +{ + cl_context context; + cl_uint num_devices; + const cl_device_id *device_list; + const char *options; + cl_uint num_input_programs; + const cl_program *input_programs; + void (CL_CALLBACK *pfn_notify)(cl_program program, void *user_data); + void *user_data; + cl_int *errcode_ret; +}; + +struct clUnloadPlatformCompiler_st +{ + cl_platform_id platform; +}; + +#if 0 +struct clUnloadCompiler_st +{ + void ; +}; +#endif + +struct clGetExtensionFunctionAddress_st +{ + const char *func_name; +}; + +struct clGetExtensionFunctionAddressForPlatform_st +{ + cl_platform_id platform; + const char *func_name; +}; + +struct clGetProgramInfo_st +{ + cl_program program; + cl_program_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +struct clGetProgramBuildInfo_st +{ + 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; +}; + +#define NUM_ITEMS_clCreateImage2D 1 +#define NUM_ITEMS_clCreateImage3D 1 +#define NUM_ITEMS_clCreateImage 1 +#define NUM_ITEMS_clGetSupportedImageFormats 1 +#define NUM_ITEMS_clEnqueueCopyImageToBuffer 1 +#define NUM_ITEMS_clEnqueueCopyBufferToImage 1 +#define NUM_ITEMS_clEnqueueMapImage 1 +#define NUM_ITEMS_clEnqueueReadImage 1 +#define NUM_ITEMS_clEnqueueWriteImage 1 +#define NUM_ITEMS_clEnqueueFillImage 1 +#define NUM_ITEMS_clEnqueueCopyImage 1 +#define NUM_ITEMS_clGetMemObjectInfo 1 +#define NUM_ITEMS_clGetImageInfo 1 + +struct clCreateImage_st +{ + 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; +}; + +struct clCreateImage2D_st +{ + cl_context context; + cl_mem_flags flags; + const cl_image_format *image_format; + size_t image_width; + size_t image_height; + size_t image_row_pitch; + void *host_ptr; + cl_int *errcode_ret; +}; + +struct clCreateImage3D_st +{ + cl_context context; + cl_mem_flags flags; + const cl_image_format *image_format; + size_t image_width; + size_t image_height; + size_t image_depth; + size_t image_row_pitch; + size_t image_slice_pitch; + void *host_ptr; + cl_int *errcode_ret; +}; + +struct clGetSupportedImageFormats_st +{ + 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; +}; + +struct clEnqueueCopyImageToBuffer_st +{ + cl_command_queue command_queue; + cl_mem src_image; + cl_mem dst_buffer; + const size_t *src_origin; + const size_t *region; + size_t dst_offset; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueCopyBufferToImage_st +{ + cl_command_queue command_queue; + cl_mem src_buffer; + cl_mem dst_image; + size_t src_offset; + const size_t *dst_origin; + const size_t *region; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueMapImage_st +{ + 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; +}; + +struct clEnqueueReadImage_st +{ + cl_command_queue command_queue; + cl_mem image; + cl_bool blocking_read; + const size_t *origin; + const size_t *region; + 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; +}; + +struct clEnqueueWriteImage_st +{ + cl_command_queue command_queue; + cl_mem image; + cl_bool blocking_write; + const size_t *origin; + const size_t *region; + 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; +}; + +struct clEnqueueFillImage_st +{ + cl_command_queue command_queue; + cl_mem image; + const void *fill_color; + const size_t *origin; + const size_t *region; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueCopyImage_st +{ + cl_command_queue command_queue; + cl_mem src_image; + cl_mem dst_image; + const size_t *src_origin; + const size_t *dst_origin; + const size_t *region; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +#if 0 +struct clGetMemObjectInfo_st +{ + cl_mem memobj; + cl_mem_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; +#endif + +struct clGetImageInfo_st +{ + cl_mem image; + cl_image_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +#define NUM_ITEMS_clCreateSampler 1 +#define NUM_ITEMS_clRetainSampler 1 +#define NUM_ITEMS_clReleaseSampler 1 +#define NUM_ITEMS_clGetSamplerInfo 1 + +struct clCreateSampler_st +{ + cl_context context; + cl_bool normalized_coords; + cl_addressing_mode addressing_mode; + cl_filter_mode filter_mode; + cl_int *errcode_ret; +}; + +struct clRetainSampler_st +{ + cl_sampler sampler; +}; + +struct clReleaseSampler_st +{ + cl_sampler sampler; +}; + +struct clGetSamplerInfo_st +{ + cl_sampler sampler; + cl_sampler_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +#define NUM_ITEMS_clCreateKernel 1 +#define NUM_ITEMS_clCreateKernelsInProgram 1 +#define NUM_ITEMS_clRetainKernel 1 +#define NUM_ITEMS_clReleaseKernel 1 + +struct clCreateKernel_st +{ + cl_program program; + const char *kernel_name; + cl_int *errcode_ret; +}; + +struct clCreateKernelsInProgram_st +{ + cl_program program; + cl_uint num_kernels; + cl_kernel *kernels; + cl_uint *num_kernels_ret; +}; + +struct clRetainKernel_st +{ + cl_kernel kernel; +}; + +struct clReleaseKernel_st +{ + cl_kernel kernel; +}; + +#define NUM_ITEMS_clSetKernelArg 1 +#define NUM_ITEMS_clGetKernelInfo 1 +#define NUM_ITEMS_clGetKernelArgInfo 1 +#define NUM_ITEMS_clGetKernelWorkGroupInfo 1 + +struct clSetKernelArg_st +{ + cl_kernel kernel; + cl_uint arg_index; + size_t arg_size; + const void *arg_value; +}; + +struct clGetKernelInfo_st +{ + cl_kernel kernel; + cl_kernel_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +struct clGetKernelArgInfo_st +{ + cl_kernel kernel; + cl_uint arg_indx; + cl_kernel_arg_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +struct clGetKernelWorkGroupInfo_st +{ + 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; +}; + +#define NUM_ITEMS_clEnqueueMigrateMemObjects 1 +#define NUM_ITEMS_clEnqueueNDRangeKernel 1 +#define NUM_ITEMS_clEnqueueTask 1 +#define NUM_ITEMS_clEnqueueNativeKernel 1 + +struct clEnqueueMigrateMemObjects_st +{ + cl_command_queue command_queue; + cl_uint num_mem_objects; + const cl_mem *mem_objects; + cl_mem_migration_flags flags; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueNDRangeKernel_st +{ + 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; +}; + +struct clEnqueueTask_st +{ + cl_command_queue command_queue; + cl_kernel kernel; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueNativeKernel_st +{ + cl_command_queue command_queue; + void (CL_CALLBACK *user_func)(void *); + void *args; + size_t cb_args; + cl_uint num_mem_objects; + const cl_mem *mem_list; + const void **args_mem_loc; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +#define NUM_ITEMS_clCreateUserEvent 1 +#define NUM_ITEMS_clSetUserEventStatus 1 +#define NUM_ITEMS_clWaitForEvents 1 +#define NUM_ITEMS_clGetEventInfo 1 +#define NUM_ITEMS_clSetEventCallback 1 +#define NUM_ITEMS_clRetainEvent 1 +#define NUM_ITEMS_clReleaseEvent 1 + +struct clCreateUserEvent_st +{ + cl_context context; + cl_int *errcode_ret; +}; + +struct clSetUserEventStatus_st +{ + cl_event event; + cl_int execution_status; +}; + +struct clWaitForEvents_st +{ + cl_uint num_events; + const cl_event *event_list; +}; + +struct clGetEventInfo_st +{ + cl_event event; + cl_event_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +struct clSetEventCallback_st +{ + cl_event event; + cl_int command_exec_callback_type; + void (CL_CALLBACK *pfn_event_notify)(cl_event event, cl_int event_command_exec_status,void *user_data); + void *user_data; +}; + +struct clRetainEvent_st +{ + cl_event event; +}; + +struct clReleaseEvent_st +{ + cl_event event; +}; + +#define NUM_ITEMS_clEnqueueMarker 1 +#define NUM_ITEMS_clEnqueueWaitForEvents 1 +#define NUM_ITEMS_clEnqueueBarrier 1 +#define NUM_ITEMS_clEnqueueMarkerWithWaitList 1 +#define NUM_ITEMS_clEnqueueBarrierWithWaitList 1 + +struct clEnqueueMarker_st +{ + cl_command_queue command_queue; + cl_event *event; +}; + +struct clEnqueueWaitForEvents_st +{ + cl_command_queue command_queue; + cl_uint num_events; + const cl_event *event_list; +}; + +struct clEnqueueBarrier_st +{ + cl_command_queue command_queue; +}; + +struct clEnqueueMarkerWithWaitList_st +{ + cl_command_queue command_queue; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueBarrierWithWaitList_st +{ + cl_command_queue command_queue; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +#define NUM_ITEMS_clGetEventProfilingInfo 1 + +struct clGetEventProfilingInfo_st +{ + cl_event event; + cl_profiling_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +#define NUM_ITEMS_clFlush 1 +#define NUM_ITEMS_clFinish 1 + +struct clFlush_st +{ + cl_command_queue command_queue; +}; + +struct clFinish_st +{ + cl_command_queue command_queue; +}; + +#define NUM_ITEMS_clCreateFromGLBuffer 1 +struct clCreateFromGLBuffer_st +{ + cl_context context; + cl_mem_flags flags; + cl_GLuint bufobj; + int *errcode_ret; +}; + +#define NUM_ITEMS_clCreateFromGLTexture 1 +#define NUM_ITEMS_clCreateFromGLTexture2D 1 +#define NUM_ITEMS_clCreateFromGLTexture3D 1 + +struct clCreateFromGLTexture_st +{ + cl_context context; + cl_mem_flags flags; + cl_GLenum texture_target; + cl_GLint miplevel; + cl_GLuint texture; + cl_int *errcode_ret; +}; + +struct clCreateFromGLTexture2D_st +{ + cl_context context; + cl_mem_flags flags; + cl_GLenum texture_target; + cl_GLint miplevel; + cl_GLuint texture; + cl_int *errcode_ret; +}; + +struct clCreateFromGLTexture3D_st +{ + cl_context context; + cl_mem_flags flags; + cl_GLenum texture_target; + cl_GLint miplevel; + cl_GLuint texture; + cl_int *errcode_ret; +}; + +#define NUM_ITEMS_clCreateFromGLRenderbuffer 1 + +struct clCreateFromGLRenderbuffer_st +{ + cl_context context; + cl_mem_flags flags; + cl_GLuint renderbuffer; + cl_int *errcode_ret; +}; + + + // Query Information [9.8.5] +#define NUM_ITEMS_clGetGLObjectInfo 1 +#define NUM_ITEMS_clGetGLTextureInfo 1 + +struct clGetGLObjectInfo_st +{ + cl_mem memobj; + cl_gl_object_type *gl_object_type; + cl_GLuint *gl_object_name; +}; + +struct clGetGLTextureInfo_st +{ + cl_mem memobj; + cl_gl_texture_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +// Share Objects [9.8.6] + +#define NUM_ITEMS_clEnqueueAcquireGLObjects 1 +#define NUM_ITEMS_clEnqueueReleaseGLObjects 1 + +struct clEnqueueAcquireGLObjects_st +{ + cl_command_queue command_queue; + cl_uint num_objects; + const cl_mem *mem_objects; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +struct clEnqueueReleaseGLObjects_st +{ + cl_command_queue command_queue; + cl_uint num_objects; + const cl_mem *mem_objects; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; + +// CL Event Objects > GL Sync Objects [9.9] +#define NUM_ITEMS_clCreateEventFromGLsyncKHR 1 + +struct clCreateEventFromGLsyncKHR_st +{ + cl_context context; + cl_GLsync sync; + cl_int *errcode_ret; +}; + +// CL Context > GL Context; Sharegroup [9.7] +#define NUM_ITEMS_clGetGLContextInfoKHR 1 + +struct clGetGLContextInfoKHR_st +{ + const cl_context_properties *properties; + cl_gl_context_info param_name; + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; + +#if 0 +// OpenCL/Direct3D 10 Sharing APIs [9.10] + +#define NUM_ITEMS_clGetDeviceIDsFromD3D10KHR 1 +#define NUM_ITEMS_clCreateFromD3D10BufferKHR 1 +#define NUM_ITEMS_clCreateFromD3D10Texture2DKHR 1 +#define NUM_ITEMS_clCreateFromD3D10Texture3DKHR 1 +#define NUM_ITEMS_clEnqueueAcquireD3D10ObjectsKHR 1 +#define NUM_ITEMS_clEnqueueReleaseD3D10ObjectsKHR 1 + +struct clGetDeviceIDsFromD3D10KHR_st +{ + cl_platform_id platform; + cl_d3d10_device_source_khr d3d_device_source; + void *d3d_object; + cl_d3d10_device_set_khr d3d_device_set; + cl_uint num_entries; + cl_device_id *devices; cl_uint *num_devices; +}; + +struct clCreateFromD3D10BufferKHR_st +{ + cl_context context; + cl_mem_flags flags; + ID3D10Buffer *resource; + cl_int *errcode_ret; +}; + +struct clCreateFromD3D10Texture2DKHR_st +{ + cl_context context; + cl_mem_flags flags; + ID3D10Texture2D *resource; + UINT subresource; + cl_int *errcode_ret; +}; + +struct clCreateFromD3D10Texture3DKHR_st +{ + cl_context context; + cl_mem_flags flags; + ID3D10Texture3D *resource; + UINT subresource; + cl_int *errcode_ret; +}; + +struct clEnqueueAcquireD3D10ObjectsKHR_st +{ + cl_command_queue command_queue; + cl_uint num_objects; + const cl_mem *mem_objects; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event;}; + +struct clEnqueueReleaseD3D10ObjectsKHR_st +{ + cl_command_queue command_queue; + cl_uint num_objects; + const cl_mem *mem_objects; + cl_uint num_events_in_wait_list; + const cl_event *event_wait_list; + cl_event *event; +}; +#endif + +#endif /* _PARAM_STRUCT_H_ */ diff --git a/opencl/khronos/icd/test/loader_test/test_buffer_object.c b/opencl/khronos/icd/test/loader_test/test_buffer_object.c new file mode 100644 index 0000000000..1710e88006 --- /dev/null +++ b/opencl/khronos/icd/test/loader_test/test_buffer_object.c @@ -0,0 +1,463 @@ +#include + +#include +#include "param_struct.h" +#include + +extern cl_mem buffer; +extern cl_command_queue command_queue; +extern cl_event event; + +static int ret_val; + +extern void CL_CALLBACK setmemobjectdestructor_callback(cl_mem _a, void* _b); + +const struct clEnqueueReadBuffer_st clEnqueueReadBufferData[NUM_ITEMS_clEnqueueReadBuffer] = +{ + {NULL, NULL, 0, 0, 0, NULL, 0, NULL, NULL} +}; + +const struct clEnqueueWriteBuffer_st clEnqueueWriteBufferData[NUM_ITEMS_clEnqueueWriteBuffer] = +{ + {NULL, NULL, 0, 0, 0, NULL, 0, NULL, NULL} +}; + +const struct clEnqueueReadBufferRect_st clEnqueueReadBufferRectData[NUM_ITEMS_clEnqueueReadBufferRect] = +{ + {NULL, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, NULL, 0, NULL, NULL} +}; + +const struct clEnqueueWriteBufferRect_st clEnqueueWriteBufferRectData[NUM_ITEMS_clEnqueueWriteBufferRect] = +{ + {NULL, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, NULL, 0, NULL, NULL} +}; + +const struct clEnqueueFillBuffer_st clEnqueueFillBufferData[NUM_ITEMS_clEnqueueFillBuffer] = +{ + {NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL} +}; + +const struct clEnqueueCopyBuffer_st clEnqueueCopyBufferData[NUM_ITEMS_clEnqueueCopyBuffer] = +{ + {NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL} +}; + +const struct clEnqueueCopyBufferRect_st clEnqueueCopyBufferRectData[NUM_ITEMS_clEnqueueCopyBufferRect] = +{ + {NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL} +}; + +const struct clEnqueueMapBuffer_st clEnqueueMapBufferData[NUM_ITEMS_clEnqueueMapBuffer] = +{ + {NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL} +}; + +const struct clRetainMemObject_st clRetainMemObjectData[NUM_ITEMS_clRetainMemObject] = +{ + {NULL} +}; + +const struct clSetMemObjectDestructorCallback_st clSetMemObjectDestructorCallbackData[NUM_ITEMS_clSetMemObjectDestructorCallback] = +{ + {NULL, setmemobjectdestructor_callback, NULL} +}; + +const struct clEnqueueUnmapMemObject_st clEnqueueUnmapMemObjectData[NUM_ITEMS_clEnqueueUnmapMemObject] = +{ + {NULL, NULL, NULL, 0, NULL, NULL} +}; + +const struct clGetMemObjectInfo_st clGetMemObjectInfoData[NUM_ITEMS_clGetMemObjectInfo] = +{ + {NULL, 0, 0, NULL, NULL} +}; + +int test_clEnqueueReadBuffer(const struct clEnqueueReadBuffer_st *data) +{ + test_icd_app_log("clEnqueueReadBuffer(%p, %p, %u, %u, %u, %p, %u, %p, %p)\n", + command_queue, + buffer, + data->blocking_read, + data->offset, + data->cb, + data->ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueReadBuffer(command_queue, + buffer, + data->blocking_read, + data->offset, + data->cb, + data->ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +int test_clEnqueueWriteBuffer(const struct clEnqueueWriteBuffer_st *data) +{ + test_icd_app_log("clEnqueueWriteBuffer(%p, %p, %u, %u, %u, %p, %u, %p, %p)\n", + command_queue, + buffer, + data->blocking_write, + data->offset, + data->cb, + data->ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueWriteBuffer(command_queue, + buffer, + data->blocking_write, + data->offset, + data->cb, + data->ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +int test_clEnqueueReadBufferRect(const struct clEnqueueReadBufferRect_st *data) +{ + test_icd_app_log("clEnqueueReadBufferRect(%p, %p, %u, %p, %p, %p, %u, %u, %u, %u, %p, %u, %p, %p)\n", + command_queue, + buffer, + data->blocking_read, + data->buffer_offset, + data->host_offset, + data->region, + data->buffer_row_pitch, + data->buffer_slice_pitch, + data->host_row_pitch, + data->host_slice_pitch, + data->ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueReadBufferRect(command_queue, + buffer, + data->blocking_read, + data->buffer_offset, + data->host_offset, + data->region, + data->buffer_row_pitch, + data->buffer_slice_pitch, + data->host_row_pitch, + data->host_slice_pitch, + data->ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clEnqueueWriteBufferRect(const struct clEnqueueWriteBufferRect_st *data) +{ + test_icd_app_log("clEnqueueWriteBufferRect(%p, %p, %u, %p, %p, %p, %u, %u, %u, %u, %p, %u, %p, %p)\n", + command_queue, + buffer, + data->blocking_write, + data->buffer_offset, + data->host_offset, + data->region, + data->buffer_row_pitch, + data->buffer_slice_pitch, + data->host_row_pitch, + data->host_slice_pitch, + data->ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueWriteBufferRect(command_queue, + buffer, + data->blocking_write, + data->buffer_offset, + data->host_offset, + data->region, + data->buffer_row_pitch, + data->buffer_slice_pitch, + data->host_row_pitch, + data->host_slice_pitch, + data->ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +int test_clEnqueueFillBuffer(const struct clEnqueueFillBuffer_st *data) +{ + test_icd_app_log("clEnqueueFillBuffer(%p, %p, %p, %u, %u, %u, %u, %p, %p)\n", + command_queue, + buffer, + data->pattern, + data->pattern_size, + data->offset, + data->cb, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueFillBuffer(command_queue, + buffer, + data->pattern, + data->pattern_size, + data->offset, + data->cb, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clEnqueueCopyBuffer(const struct clEnqueueCopyBuffer_st *data) +{ + test_icd_app_log("clEnqueueCopyBuffer(%p, %p, %p, %u, %u, %u, %u, %p, %p)\n", + command_queue, + data->src_buffer, + buffer, + data->src_offset, + data->dst_offset, + data->cb, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueCopyBuffer(command_queue, + data->src_buffer, + buffer, + data->src_offset, + data->dst_offset, + data->cb, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clEnqueueCopyBufferRect(const struct clEnqueueCopyBufferRect_st *data) +{ + test_icd_app_log("clEnqueueCopyBufferRect(%p, %p, %p, %p, %p, %p, %u, %u, %u, %u, %u, %p, %p)\n", + command_queue, + buffer, + buffer, + data->src_origin, + data->dst_origin, + data->region, + data->src_row_pitch, + data->src_slice_pitch, + data->dst_row_pitch, + data->dst_slice_pitch, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueCopyBufferRect(command_queue, + buffer, + buffer, + data->src_origin, + data->dst_origin, + data->region, + data->src_row_pitch, + data->src_slice_pitch, + data->dst_row_pitch, + data->dst_slice_pitch, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clEnqueueMapBuffer(const struct clEnqueueMapBuffer_st *data) +{ + void * return_value; + test_icd_app_log("clEnqueueMapBuffer(%p, %p, %u, %x, %u, %u, %u, %p, %p, %p)\n", + command_queue, + buffer, + data->blocking_map, + data->map_flags, + data->offset, + data->cb, + data->num_events_in_wait_list, + data->event_wait_list, + &event, + data->errcode_ret); + + return_value=clEnqueueMapBuffer(command_queue, + buffer, + data->blocking_map, + data->map_flags, + data->offset, + data->cb, + data->num_events_in_wait_list, + data->event_wait_list, + &event, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", return_value); + + free(return_value); + + return 0; + +} + +int test_clRetainMemObject(const struct clRetainMemObject_st *data) +{ + test_icd_app_log("clRetainMemObject(%p)\n", buffer); + + ret_val=clRetainMemObject(buffer); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clSetMemObjectDestructorCallback(const struct clSetMemObjectDestructorCallback_st *data) +{ + test_icd_app_log("clSetMemObjectDestructorCallback(%p, %p, %p)\n", + buffer, + data->pfn_notify, + data->user_data); + + ret_val=clSetMemObjectDestructorCallback(buffer, + data->pfn_notify, + data->user_data); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clEnqueueUnmapMemObject(const struct clEnqueueUnmapMemObject_st *data) +{ + test_icd_app_log("clEnqueueUnmapMemObject(%p, %p, %p, %u, %p, %p)\n", + command_queue, + buffer, + data->mapped_ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueUnmapMemObject(command_queue, + buffer, + data->mapped_ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + + +int test_clGetMemObjectInfo (const struct clGetMemObjectInfo_st *data) +{ + test_icd_app_log("clGetMemObjectInfo(%p, %u, %u, %p, %p)\n", + buffer, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val=clGetMemObjectInfo(buffer, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n",ret_val); + + return 0; +} + +int test_buffer_object() +{ + int i; + for (i=0; i +#include "param_struct.h" +#include + +extern cl_command_queue command_queue; + +static cl_int ret_val; + +const struct clRetainCommandQueue_st clRetainCommandQueueData[NUM_ITEMS_clRetainCommandQueue] = { + {NULL} +}; + +const struct clGetCommandQueueInfo_st clGetCommandQueueInfoData[NUM_ITEMS_clGetCommandQueueInfo] = { + {NULL, 0, 0, NULL, NULL} +}; + +int test_clRetainCommandQueue(const struct clRetainCommandQueue_st *data) +{ + test_icd_app_log("clRetainCommandQueue(%p)\n", command_queue); + + ret_val = clRetainCommandQueue(command_queue); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clGetCommandQueueInfo(const struct clGetCommandQueueInfo_st *data) +{ + test_icd_app_log("clGetCommandQueueInfo(%p, %u, %u, %p, %p)\n", + command_queue, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val = clGetCommandQueueInfo(command_queue, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_cl_runtime() +{ + int i; + + for (i=0; i +#include +#include +#include "param_struct.h" +#include + +extern cl_context context; +extern cl_mem buffer; +extern cl_command_queue command_queue; +extern cl_event event; +extern cl_context_properties context_properties[3]; +static cl_int ret_val; +cl_mem ret_mem; + +struct clCreateFromGLBuffer_st clCreateFromGLBufferData[NUM_ITEMS_clCreateFromGLBuffer] = { + {NULL, 0x0, 0, NULL} +}; + +int test_clCreateFromGLBuffer(const struct clCreateFromGLBuffer_st* data) +{ + + test_icd_app_log("clCreateFromGLBuffer(%p, %x, %u, %p)\n", + context, + data->flags, + data->bufobj, + data->errcode_ret); + + ret_mem = clCreateFromGLBuffer(context, + data->flags, + data->bufobj, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", ret_mem); + + return 0; +} + +struct clCreateFromGLTexture_st clCreateFromGLTextureData[NUM_ITEMS_clCreateFromGLTexture] = { + {NULL, 0x0, 0, 0, 0, NULL} +}; + +int test_clCreateFromGLTexture(const struct clCreateFromGLTexture_st* data) +{ + test_icd_app_log("clCreateFromGLTexture(%p, %x, %d, %d, %u, %p)\n", + context, + data->flags, + data->texture_target, + data->miplevel, + data->texture, + data->errcode_ret); + + ret_mem = clCreateFromGLTexture(context, + data->flags, + data->texture_target, + data->miplevel, + data->texture, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", ret_mem); + + return 0; +} + +struct clCreateFromGLTexture2D_st clCreateFromGLTexture2DData[NUM_ITEMS_clCreateFromGLTexture2D] = { + {NULL, 0x0, 0, 0, 0, NULL} +}; + +int test_clCreateFromGLTexture2D(const struct clCreateFromGLTexture2D_st* data) +{ + test_icd_app_log("clCreateFromGLTexture2D(%p, %x, %d, %d, %u, %p)\n", + context, + data->flags, + data->texture_target, + data->miplevel, + data->texture, + data->errcode_ret); + + ret_mem = clCreateFromGLTexture2D(context, + data->flags, + data->texture_target, + data->miplevel, + data->texture, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", ret_mem); + + return 0; +} + +struct clCreateFromGLTexture3D_st clCreateFromGLTexture3DData[NUM_ITEMS_clCreateFromGLTexture3D] = { + {NULL, 0, 0, 0, 0, NULL} +}; + +int test_clCreateFromGLTexture3D(const struct clCreateFromGLTexture3D_st* data) +{ + test_icd_app_log("clCreateFromGLTexture3D(%p, %x, %d, %d, %u, %p)\n", + context, + data->flags, + data->texture_target, + data->miplevel, + data->texture, + data->errcode_ret); + + ret_mem = clCreateFromGLTexture3D(context, + data->flags, + data->texture_target, + data->miplevel, + data->texture, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", ret_mem); + + return 0; +} + +struct clCreateFromGLRenderbuffer_st clCreateFromGLRenderbufferData[NUM_ITEMS_clCreateFromGLRenderbuffer] = { + {NULL, 0x0, 0, NULL} +}; + +int test_clCreateFromGLRenderbuffer(const struct clCreateFromGLRenderbuffer_st* data) +{ + test_icd_app_log("clCreateFromGLRenderbuffer(%p, %x, %d, %p)\n", + context, + data->flags, + data->renderbuffer, + data->errcode_ret); + + ret_mem = clCreateFromGLRenderbuffer(context, + data->flags, + data->renderbuffer, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", ret_mem); + + return 0; +} + +struct clGetGLObjectInfo_st clGetGLObjectInfoData[NUM_ITEMS_clGetGLObjectInfo] = { + {NULL, NULL, NULL} +}; + +int test_clGetGLObjectInfo(const struct clGetGLObjectInfo_st* data) +{ + test_icd_app_log("clGetGLObjectInfo(%p, %p, %p)\n", + buffer, + data->gl_object_type, + data->gl_object_name); + + ret_val = clGetGLObjectInfo(buffer, + data->gl_object_type, + data->gl_object_name); + + test_icd_app_log("Value returned: %p\n", ret_val); + + return ret_val; + +} + +struct clGetGLTextureInfo_st clGetGLTextureInfoData[NUM_ITEMS_clGetGLTextureInfo] = { + {NULL, 0, 0, NULL, NULL} +}; + +int test_clGetGLTextureInfo(const struct clGetGLTextureInfo_st* data) +{ + test_icd_app_log("clGetGLTextureInfo(%p, %u, %u, %p, %p)\n", + buffer, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val = clGetGLTextureInfo (buffer, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %p\n", ret_val); + + return 0; +} + +struct clEnqueueAcquireGLObjects_st clEnqueueAcquireGLObjectsData[NUM_ITEMS_clEnqueueAcquireGLObjects] = { + {NULL, 0, NULL, 0, NULL, NULL} +}; + +int test_clEnqueueAcquireGLObjects(const struct clEnqueueAcquireGLObjects_st* data) +{ + test_icd_app_log("clEnqueueAcquireGLObjects(%p, %u, %p, %u, %p, %p)\n", + command_queue, + data->num_objects, + data->mem_objects, + data->num_events_in_wait_list, + &event, + &event); + + ret_val = clEnqueueAcquireGLObjects (command_queue, + data->num_objects, + data->mem_objects, + data->num_events_in_wait_list, + &event, + &event); + + test_icd_app_log("Value returned: %p\n", ret_val); + + return 0; +} + +struct clEnqueueReleaseGLObjects_st clEnqueueReleaseGLObjectsData[NUM_ITEMS_clEnqueueReleaseGLObjects] = { + {NULL, 0, NULL, 0, NULL, NULL} +}; + +int test_clEnqueueReleaseGLObjects(const struct clEnqueueReleaseGLObjects_st* data) +{ + test_icd_app_log("clEnqueueReleaseGLObjects(%p, %u, %p, %u, %p, %p)\n", + command_queue, + data->num_objects, + data->mem_objects, + data->num_events_in_wait_list, + &event, + &event); + + ret_val = clEnqueueReleaseGLObjects (command_queue, + data->num_objects, + data->mem_objects, + data->num_events_in_wait_list, + &event, + &event); + + + test_icd_app_log("Value returned: %p\n", ret_val); + + return 0; +} + +struct clCreateEventFromGLsyncKHR_st clCreateEventFromGLsyncKHRData[NUM_ITEMS_clCreateEventFromGLsyncKHR] = { + {NULL, NULL, NULL} +}; + +typedef CL_API_ENTRY cl_event +(CL_API_CALL *PFN_clCreateEventFromGLsyncKHR)(cl_context /* context */, + cl_GLsync /* cl_GLsync */, + cl_int * /* errcode_ret */); + +int test_clCreateEventFromGLsyncKHR(const struct clCreateEventFromGLsyncKHR_st* data) +{ cl_event ret_event; + PFN_clCreateEventFromGLsyncKHR pfn_clCreateEventFromGLsyncKHR = NULL; + + test_icd_app_log("clCreateEventFromGLsyncKHR(%p, %p, %p)\n", + context, + data->sync, + data->errcode_ret); + + pfn_clCreateEventFromGLsyncKHR = clGetExtensionFunctionAddress("clCreateEventFromGLsyncKHR"); + if (!pfn_clCreateEventFromGLsyncKHR) { + test_icd_app_log("clGetExtensionFunctionAddress failed!\n"); + return 1; + } + + ret_event = pfn_clCreateEventFromGLsyncKHR (context, + data->sync, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", ret_event); + return 0; +} + +struct clGetGLContextInfoKHR_st clGetGLContextInfoKHRData[NUM_ITEMS_clGetGLContextInfoKHR] = { + {NULL, 0, 0, NULL, NULL} +}; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL *PFN_clGetGLContextInfoKHR)(const cl_context_properties * /* properties */, + cl_gl_context_info /* param_name */, + size_t /* param_value_size */, + void * /* param_value */, + size_t * /* param_value_size_ret */); + +int test_clGetGLContextInfoKHR(const struct clGetGLContextInfoKHR_st* data) +{ + PFN_clGetGLContextInfoKHR pfn_clGetGLContextInfoKHR = NULL; + test_icd_app_log("clGetGLContextInfoKHR(%p, %u, %u, %p, %p)\n", + context_properties, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + pfn_clGetGLContextInfoKHR = clGetExtensionFunctionAddress("clGetGLContextInfoKHR"); + if (!pfn_clGetGLContextInfoKHR) { + test_icd_app_log("clGetExtensionFunctionAddress failed!\n"); + return 1; + } + + ret_val = pfn_clGetGLContextInfoKHR(context_properties, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %p\n", ret_val); + return 0; + +} + +int test_OpenGL_share() +{ + int i; + + for(i=0;i +#include + +#define CL_USE_DEPRECATED_OPENCL_1_0_APIS +#define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#define CL_USE_DEPRECATED_OPENCL_1_2_APIS + +#include +#include "param_struct.h" +#include + +extern void CL_CALLBACK createcontext_callback(const char* a, const void* b, size_t c, void* d); + +cl_platform_id* all_platforms; +cl_platform_id platform; +cl_uint num_platforms; +cl_context context; +cl_command_queue command_queue; +cl_mem buffer; +cl_mem subBuffer; +cl_mem image; +cl_sampler sampler; +cl_program program; +cl_kernel kernel; +cl_event event; +cl_device_id devices; +cl_context_properties context_properties[3] = { + (cl_context_properties)CL_CONTEXT_PLATFORM, + 0, + 0, +}; + +const struct clGetDeviceIDs_st clGetDeviceIDsData[NUM_ITEMS_clGetDeviceIDs] = +{ + {NULL, 0, 1, NULL, NULL} +}; + +const struct clCreateSampler_st clCreateSamplerData[NUM_ITEMS_clCreateSampler] = +{ + {NULL, 0x0, 0, 0, NULL}, +}; + +const struct clCreateCommandQueue_st clCreateCommandQueueData[NUM_ITEMS_clCreateCommandQueue] = +{ + {NULL, NULL, 0, NULL} +}; + +const struct clCreateContext_st clCreateContextData[NUM_ITEMS_clCreateContext] = +{ + {NULL, 1, NULL, NULL, NULL, NULL} +}; + +const struct clCreateContextFromType_st clCreateContextFromTypeData[NUM_ITEMS_clCreateContextFromType] = +{ + {NULL, 0, createcontext_callback, NULL, NULL} +}; + +const struct clCreateBuffer_st clCreateBufferData[NUM_ITEMS_clCreateBuffer] = +{ + {NULL, 0, 0, NULL, NULL} +}; + +const struct clCreateSubBuffer_st clCreateSubBufferData[NUM_ITEMS_clCreateSubBuffer] = +{ + {NULL, 0, 0, NULL, NULL} +}; + +const struct clCreateImage_st clCreateImageData[NUM_ITEMS_clCreateImage] = +{ + { NULL, 0x0, NULL, NULL, NULL, NULL} +}; + +const struct clCreateImage2D_st clCreateImage2DData[NUM_ITEMS_clCreateImage2D] = +{ + { NULL, 0x0, NULL, 0, 0, 0, NULL, NULL} +}; + +const struct clCreateImage3D_st clCreateImage3DData[NUM_ITEMS_clCreateImage3D] = +{ + { NULL, 0x0, NULL, 0, 0, 0, 0, 0, NULL, NULL } +}; + + +struct clReleaseMemObject_st clReleaseMemObjectData[NUM_ITEMS_clReleaseMemObject] = +{ + {NULL} +}; + +struct clReleaseMemObject_st clReleaseMemObjectDataImage[NUM_ITEMS_clReleaseMemObject] = +{ + {NULL} +};const struct clCreateProgramWithSource_st clCreateProgramWithSourceData[NUM_ITEMS_clCreateProgramWithSource] = +{ + {NULL, 0, NULL, NULL, NULL} +}; + +const struct clCreateProgramWithBinary_st clCreateProgramWithBinaryData[NUM_ITEMS_clCreateProgramWithBinary] = +{ + {NULL, 0, NULL, NULL, NULL, NULL, NULL} +}; + +const struct clCreateProgramWithBuiltInKernels_st clCreateProgramWithBuiltInKernelsData[NUM_ITEMS_clCreateProgramWithBuiltInKernels] = +{ + {NULL, 0, NULL, NULL, NULL} +}; + +const struct clCreateKernel_st clCreateKernelData[NUM_ITEMS_clCreateKernel] = +{ + {NULL, NULL, NULL} +}; + +const struct clCreateKernelsInProgram_st clCreateKernelsInProgramData[NUM_ITEMS_clCreateKernelsInProgram] = +{ + {NULL, 0, NULL, NULL} +}; + +const struct clCreateUserEvent_st clCreateUserEventData[NUM_ITEMS_clCreateUserEvent] = +{ + {NULL, NULL} +}; + +const struct clGetPlatformIDs_st clGetPlatformIDsData[NUM_ITEMS_clGetPlatformIDs] = +{ + {0, NULL, 0} +}; + +/* + * Some log messages cause log mismatches when ICD loader calls a driver + * function while initializing platforms. The functions clGetPlatform* are most + * likely to be called at that time. But nothing stops an ICD loader from + * calling a ICD driver function anytime. + * + * FIXME: Figure out a good way to handle this. + */ +#define ENABLE_MISMATCHING_PRINTS 0 + +int test_clGetPlatformIDs(const struct clGetPlatformIDs_st* data) +{ + cl_int ret_val; + size_t param_val_ret_size; + #define PLATFORM_NAME_SIZE 40 + char platform_name[PLATFORM_NAME_SIZE]; + cl_uint i; + +#if ENABLE_MISMATCHING_PRINTS + test_icd_app_log("clGetPlatformIDs(%u, %p, %p)\n", + data->num_entries, + &platforms, + &num_platforms); +#endif + + ret_val = clGetPlatformIDs(0, + NULL, + &num_platforms); + + if (ret_val != CL_SUCCESS){ + return -1; + } + + all_platforms = (cl_platform_id *) malloc (num_platforms * sizeof(cl_platform_id)); + + ret_val = clGetPlatformIDs(num_platforms, + all_platforms, + NULL); + + if (ret_val != CL_SUCCESS){ + return -1; + } + + for (i = 0; i < num_platforms; i++) { + ret_val = clGetPlatformInfo(all_platforms[i], + CL_PLATFORM_NAME, + PLATFORM_NAME_SIZE, + (void*)platform_name, + ¶m_val_ret_size ); + + if (ret_val == CL_SUCCESS ){ + if(!strcmp(platform_name, "ICD_LOADER_TEST_OPENCL_STUB")) { + platform = all_platforms[i]; + } + } + } + +#if ENABLE_MISMATCHING_PRINTS + test_icd_app_log("Value returned: %d\n", ret_val); +#endif + + return 0; + +} + +int test_clGetDeviceIDs(const struct clGetDeviceIDs_st* data) +{ + int ret_val; + + test_icd_app_log("clGetDeviceIDs(%p, %x, %u, %p, %p)\n", + platform, + data->device_type, + data->num_entries, + &devices, + data->num_devices); + + ret_val = clGetDeviceIDs(platform, + data->device_type, + data->num_entries, + &devices, + data->num_devices); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clCreateContext(const struct clCreateContext_st* data) +{ + test_icd_app_log("clCreateContext(%p, %u, %p, %p, %p, %p)\n", + data->properties, + data->num_devices, + &devices, + &createcontext_callback, + data->user_data, + data->errcode_ret); + + context = clCreateContext(data->properties, + data->num_devices, + &devices, + &createcontext_callback, + data->user_data, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", context); + + return 0; + +} + +int test_clCreateContextFromType(const struct clCreateContextFromType_st* data) +{ + test_icd_app_log("clCreateContextFromType(%p, %x, %p, %p, %p)\n", + context_properties, + data->device_type, + data->pfn_notify, + data->user_data, + data->errcode_ret); + + + context = clCreateContextFromType(context_properties, + data->device_type, + data->pfn_notify, + data->user_data, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", context); + + return 0; + +} + +int test_clCreateCommandQueue(const struct clCreateCommandQueue_st *data) +{ + test_icd_app_log("clCreateCommandQueue(%p, %p, %x, %p)\n", + context, + devices, + data->properties, + data->errcode_ret); + + command_queue = clCreateCommandQueue(context, + devices, + data->properties, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", command_queue); + + return 0; + +} + +int test_clCreateBuffer(const struct clCreateBuffer_st *data) +{ + test_icd_app_log("clCreateBuffer(%p, %x, %u, %p, %p)\n", + context, + data->flags, + data->size, + data->host_ptr, + data->errcode_ret); + + buffer = clCreateBuffer(context, + data->flags, + data->size, + data->host_ptr, + data->errcode_ret); + + clReleaseMemObjectData->memobj = buffer; + + test_icd_app_log("Value returned: %p\n", buffer); + + return 0; + +} + +int test_clCreateSubBuffer(const struct clCreateSubBuffer_st *data) +{ + test_icd_app_log("clCreateSubBuffer(%p, %x, %u, %p, %p)\n", + buffer, + data->flags, + data->buffer_create_type, + data->buffer_create_info, + data->errcode_ret); + + subBuffer = clCreateSubBuffer(buffer, + data->flags, + data->buffer_create_type, + data->buffer_create_info, + data->errcode_ret); + + clReleaseMemObjectData->memobj = buffer; + + test_icd_app_log("Value returned: %p\n", subBuffer); + + return 0; + +} + +int test_clCreateImage(const struct clCreateImage_st *data) +{ + test_icd_app_log("clCreateImage(%p, %x, %p, %p, %p, %p)\n", + context, + data->flags, + data->image_format, + data->image_desc, + data->host_ptr, + data->errcode_ret); + + image = clCreateImage(context, + data->flags, + data->image_format, + data->image_desc, + data->host_ptr, + data->errcode_ret); + + clReleaseMemObjectDataImage[0].memobj = image; + test_icd_app_log("Value returned: %p\n", image); + + return 0; + +} + +int test_clCreateImage2D(const struct clCreateImage2D_st *data) +{ + test_icd_app_log("clCreateImage2D(%p, %x, %p, %u, %u, %u, %p, %p)\n", + context, + data->flags, + data->image_format, + data->image_width, + data->image_height, + data->image_row_pitch, + data->host_ptr, + data->errcode_ret); + + image = clCreateImage2D(context, + data->flags, + data->image_format, + data->image_width, + data->image_height, + data->image_row_pitch, + data->host_ptr, + data->errcode_ret); + + clReleaseMemObjectDataImage[0].memobj = image; + test_icd_app_log("Value returned: %p\n", image); + + return 0; + +} + +int test_clCreateImage3D(const struct clCreateImage3D_st *data) +{ + test_icd_app_log("clCreateImage3D(%p, %x, %p, %u, %u, %u, %u, %u, %p, %p)\n", + context, + data->flags, + data->image_format, + data->image_width, + data->image_height, + data->image_depth, + data->image_row_pitch, + data->image_slice_pitch, + data->host_ptr, + data->errcode_ret); + + image = clCreateImage3D(context, + data->flags, + data->image_format, + data->image_width, + data->image_height, + data->image_depth, + data->image_row_pitch, + data->image_slice_pitch, + data->host_ptr, + data->errcode_ret); + + clReleaseMemObjectDataImage[0].memobj = image; + test_icd_app_log("Value returned: %p\n", image); + + return 0; + +} + +int test_clCreateSampler(const struct clCreateSampler_st *data) +{ + test_icd_app_log("clCreateSampler(%p, %u, %u, %u, %p)\n", + context, + data->normalized_coords, + data->addressing_mode, + data->filter_mode, + data->errcode_ret); + + sampler = clCreateSampler(context, + data->normalized_coords, + data->addressing_mode, + data->filter_mode, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", sampler); + + return 0; + +} + +int test_clCreateProgramWithSource(const struct clCreateProgramWithSource_st *data) +{ + test_icd_app_log("clCreateProgramWithSource(%p, %u, %p, %p, %p)\n", + context, + data->count, + data->strings, + data->lengths, + data->errcode_ret); + + program = clCreateProgramWithSource(context, + data->count, + data->strings, + data->lengths, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", program); + + return 0; + +} + +int test_clCreateProgramWithBinary(const struct clCreateProgramWithBinary_st *data) +{ + test_icd_app_log("clCreateProgramWithBinary(%p, %u, %p, %p, %p, %p, %p)\n", + context, + data->num_devices, + &devices, + data->lengths, + data->binaries, + data->binary_status, + data->errcode_ret); + + program = clCreateProgramWithBinary(context, + data->num_devices, + &devices, + data->lengths, + data->binaries, + data->binary_status, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", program); + + return 0; + +} + +int test_clCreateProgramWithBuiltInKernels(const struct clCreateProgramWithBuiltInKernels_st *data) +{ + test_icd_app_log("clCreateProgramWithBuiltInKernels(%p, %u, %p, %p, %p)\n", + context, + data->num_devices, + &devices, + data->kernel_names, + data->errcode_ret); + + program = clCreateProgramWithBuiltInKernels(context, + data->num_devices, + &devices, + data->kernel_names, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", program); + + return 0; + +} + +int test_clCreateKernel(const struct clCreateKernel_st* data) +{ + test_icd_app_log("clCreateKernel(%p, %p, %p)\n", + program, + data->kernel_name, + data->errcode_ret); + + kernel = clCreateKernel(program, + data->kernel_name, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", kernel); + + return 0; + +} + +int test_clCreateKernelsInProgram(const struct clCreateKernelsInProgram_st* data) +{ + int ret_val; + test_icd_app_log("clCreateKernelsInProgram(%p, %u, %p, %p)\n", + program, + data->num_kernels, + &kernel, + data->num_kernels_ret); + + ret_val = clCreateKernelsInProgram(program, + data->num_kernels, + &kernel, + data->num_kernels_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clCreateUserEvent(const struct clCreateUserEvent_st* data) +{ + test_icd_app_log("clCreateUserEvent(%p, %p)\n", + context, + data->errcode_ret); + + event = clCreateUserEvent(context, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", event); + + return 0; + +} + +const struct clReleaseSampler_st clReleaseSamplerData[NUM_ITEMS_clReleaseSampler] = +{ + { NULL } +}; + +int test_clReleaseSampler(const struct clReleaseSampler_st *data) +{ + int ret_val = CL_OUT_OF_RESOURCES; + + test_icd_app_log("clReleaseSampler(%p)\n", sampler); + + ret_val = clReleaseSampler(sampler); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + + +int test_clReleaseMemObject(const struct clReleaseMemObject_st *data) +{ + int ret_val = -15; + test_icd_app_log("clReleaseMemObject(%p)\n", data->memobj); + + ret_val = clReleaseMemObject(data->memobj); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +const struct clReleaseEvent_st clReleaseEventData[NUM_ITEMS_clReleaseEvent] = +{ + {NULL} +}; + +int test_clReleaseEvent(const struct clReleaseEvent_st* data) +{ + int ret_val = CL_OUT_OF_RESOURCES; + + test_icd_app_log("clReleaseEvent(%p)\n", event); + + ret_val = clReleaseEvent(event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +const struct clReleaseKernel_st clReleaseKernelData[NUM_ITEMS_clReleaseKernel] = +{ + {NULL} +}; + +int test_clReleaseKernel(const struct clReleaseKernel_st* data) +{ + int ret_val = CL_OUT_OF_RESOURCES; + + test_icd_app_log("clReleaseKernel(%p)\n", kernel); + + ret_val = clReleaseKernel(kernel); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +const struct clReleaseProgram_st clReleaseProgramData[NUM_ITEMS_clReleaseProgram] = +{ + {NULL} +}; + +int test_clReleaseProgram(const struct clReleaseProgram_st *data) +{ + int ret_val = CL_OUT_OF_RESOURCES; + + test_icd_app_log("clReleaseProgram(%p)\n", program); + + ret_val = clReleaseProgram(program); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +const struct clReleaseCommandQueue_st clReleaseCommandQueueData[NUM_ITEMS_clReleaseCommandQueue] = +{ + {NULL} +}; + +int test_clReleaseCommandQueue(const struct clReleaseCommandQueue_st *data) +{ + int ret_val = CL_OUT_OF_RESOURCES; + + test_icd_app_log("clReleaseCommandQueue(%p)\n", command_queue); + + ret_val = clReleaseCommandQueue(command_queue); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +const struct clReleaseContext_st clReleaseContextData[NUM_ITEMS_clReleaseContext] = +{ + {NULL} +}; + +int test_clReleaseContext(const struct clReleaseContext_st* data) +{ + int ret_val = CL_OUT_OF_RESOURCES; + + test_icd_app_log("clReleaseContext(%p)\n", context); + + ret_val = clReleaseContext(context); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +const struct clReleaseDevice_st clReleaseDeviceData[NUM_ITEMS_clReleaseDevice] = +{ + {NULL} +}; + +int test_clReleaseDevice(const struct clReleaseDevice_st* data) +{ + int ret_val = CL_OUT_OF_RESOURCES; + + test_icd_app_log("clReleaseDevice(%p)\n", devices); + + ret_val = clReleaseDevice(devices); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_create_calls() +{ + test_clGetPlatformIDs(clGetPlatformIDsData); + + context_properties[1] = (cl_context_properties) platform; + + test_clGetDeviceIDs(clGetDeviceIDsData); + + test_clCreateContext(clCreateContextData); + + test_clReleaseContext(clReleaseContextData); + + test_clCreateContextFromType(clCreateContextFromTypeData); + + test_clCreateCommandQueue(clCreateCommandQueueData); + + test_clCreateBuffer(clCreateBufferData); + + test_clCreateSubBuffer(clCreateSubBufferData); + + test_clCreateImage(clCreateImageData); + + test_clReleaseMemObject(clReleaseMemObjectDataImage); + + test_clCreateImage2D(clCreateImage2DData); + + test_clReleaseMemObject(clReleaseMemObjectDataImage); + + test_clCreateImage3D(clCreateImage3DData); + + test_clCreateSampler(clCreateSamplerData); + + test_clCreateProgramWithSource(clCreateProgramWithSourceData); + + test_clReleaseProgram(clReleaseProgramData); + + test_clCreateProgramWithBinary(clCreateProgramWithBinaryData); + + test_clReleaseProgram(clReleaseProgramData); + + test_clCreateProgramWithBuiltInKernels(clCreateProgramWithBuiltInKernelsData); + + test_clCreateKernel(clCreateKernelData); + + test_clCreateKernelsInProgram(clCreateKernelsInProgramData); + + test_clCreateUserEvent(clCreateUserEventData); + + return 0; + +} + +int test_release_calls() +{ + test_clReleaseSampler(clReleaseSamplerData); + + test_clReleaseMemObject(clReleaseMemObjectData); + + test_clReleaseMemObject(clReleaseMemObjectDataImage); + + test_clReleaseEvent(clReleaseEventData); + + test_clReleaseKernel(clReleaseKernelData); + + test_clReleaseProgram(clReleaseProgramData); + + test_clReleaseCommandQueue(clReleaseCommandQueueData); + + test_clReleaseContext(clReleaseContextData); + + test_clReleaseDevice(clReleaseDeviceData); + + return 0; +} + diff --git a/opencl/khronos/icd/test/loader_test/test_image_objects.c b/opencl/khronos/icd/test/loader_test/test_image_objects.c new file mode 100644 index 0000000000..a4d427b2e2 --- /dev/null +++ b/opencl/khronos/icd/test/loader_test/test_image_objects.c @@ -0,0 +1,368 @@ +/* Modifications Copyright(C) 2022 Advanced Micro Devices, Inc. + * All rights reserved. + */ + +#include + +#include +#include "param_struct.h" +#include + +extern cl_mem image; +extern cl_context context; +extern cl_command_queue command_queue; +extern cl_event event; +extern cl_mem buffer; + +static int ret_val; + +const struct clGetSupportedImageFormats_st clGetSupportedImageFormatsData[NUM_ITEMS_clGetSupportedImageFormats] = +{ + { NULL, 0x0, 0, 0, NULL, NULL } +}; + +const struct clEnqueueCopyImageToBuffer_st clEnqueueCopyImageToBufferData[NUM_ITEMS_clEnqueueCopyImageToBuffer] = +{ + { NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL } +}; + +const struct clEnqueueCopyBufferToImage_st clEnqueueCopyBufferToImageData[NUM_ITEMS_clEnqueueCopyBufferToImage] = +{ + { NULL, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL } +}; + +const struct clEnqueueMapImage_st clEnqueueMapImageData[NUM_ITEMS_clEnqueueMapImage] = +{ + { NULL, NULL, 0, 0x0, NULL, NULL, NULL, NULL,0, NULL, NULL} +}; + +const struct clEnqueueReadImage_st clEnqueueReadImageData[NUM_ITEMS_clEnqueueReadImage] = +{ + { NULL, NULL, 0, NULL, NULL, 0, 0, NULL, 0, NULL, NULL } +}; + +const struct clEnqueueWriteImage_st clEnqueueWriteImageData[NUM_ITEMS_clEnqueueWriteImage] = +{ + { NULL, NULL, 0, NULL, NULL, 0, 0, NULL, 0, NULL, NULL } +}; + +const struct clEnqueueFillImage_st clEnqueueFillImageData[NUM_ITEMS_clEnqueueFillImage] = +{ + { NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL } +}; + +const struct clEnqueueCopyImage_st clEnqueueCopyImageData[NUM_ITEMS_clEnqueueCopyImage] = +{ + { NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL } +}; + +const struct clGetImageInfo_st clGetImageInfoData[NUM_ITEMS_clGetImageInfo] = +{ + { NULL, 0, 0, NULL, NULL} +}; + +int test_clGetSupportedImageFormats(const struct clGetSupportedImageFormats_st *data) +{ + test_icd_app_log("clGetSupportedImageFormats(%p, %x, %u, %u, %p, %p)\n", + context, + data->flags, + data->image_type, + data->num_entries, + data->image_formats, + data->num_image_formats); + + ret_val = clGetSupportedImageFormats(context, + data->flags, + data->image_type, + data->num_entries, + data->image_formats, + data->num_image_formats); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clEnqueueCopyImageToBuffer(const struct clEnqueueCopyImageToBuffer_st *data) +{ + test_icd_app_log("clEnqueueCopyImageToBuffer(%p, %p, %p, %p, %p, %u, %u, %p, %p)\n", + command_queue, + image, + buffer, + data->src_origin, + data->region, + data->dst_offset, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val = clEnqueueCopyImageToBuffer(command_queue, + image, + buffer, + data->src_origin, + data->region, + data->dst_offset, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clEnqueueCopyBufferToImage(const struct clEnqueueCopyBufferToImage_st *data) +{ + test_icd_app_log("clEnqueueCopyBufferToImage(%p, %p, %p, %u, %p, %p, %u, %p, %p)\n", + command_queue, + buffer, + image, + data->src_offset, + data->dst_origin, + data->region, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val = clEnqueueCopyBufferToImage(command_queue, + buffer, + image, + data->src_offset, + data->dst_origin, + data->region, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clEnqueueMapImage(const struct clEnqueueMapImage_st *data) +{ + void *return_value; + test_icd_app_log("clEnqueueMapImage(%p, %p, %u, %x, %p, %p, %p, %p, %u, %p, %p, %p)\n", + command_queue, + image, + data->blocking_map, + data->map_flags, + data->origin, + data->region, + data->image_row_pitch, + data->image_slice_pitch, + data->num_events_in_wait_list, + data->event_wait_list, + &event, + data->errcode_ret); + + return_value = clEnqueueMapImage(command_queue, + image, + data->blocking_map, + data->map_flags, + data->origin, + data->region, + data->image_row_pitch, + data->image_slice_pitch, + data->num_events_in_wait_list, + data->event_wait_list, + &event, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", return_value); + + free(return_value); + + return 0; + +} + +int test_clEnqueueReadImage(const struct clEnqueueReadImage_st *data) +{ + test_icd_app_log("clEnqueueReadImage(%p, %p, %u, %p, %p, %u, %u, %p, %u, %p, %p)\n", + command_queue, + image, + data->blocking_read, + data->origin, + data->region, + data->row_pitch, + data->slice_pitch, + data->ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val = clEnqueueReadImage(command_queue, + image, + data->blocking_read, + data->origin, + data->region, + data->row_pitch, + data->slice_pitch, + data->ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clEnqueueWriteImage(const struct clEnqueueWriteImage_st *data) +{ + test_icd_app_log("clEnqueueWriteImage(%p, %p, %u, %p, %p, %u, %u, %p, %u, %p, %p)\n", + command_queue, + image, + data->blocking_write, + data->origin, + data->region, + data->input_row_pitch, + data->input_slice_pitch, + data->ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val = clEnqueueWriteImage(command_queue, + image, + data->blocking_write, + data->origin, + data->region, + data->input_row_pitch, + data->input_slice_pitch, + data->ptr, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clEnqueueFillImage(const struct clEnqueueFillImage_st *data) +{ + test_icd_app_log("clEnqueueFillImage(%p, %p, %p, %p, %p, %u, %p, %p)\n", + command_queue, + image, + data->fill_color, + data->origin, + data->region, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val = clEnqueueFillImage(command_queue, + image, + data->fill_color, + data->origin, + data->region, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} +int test_clEnqueueCopyImage(const struct clEnqueueCopyImage_st *data) +{ + test_icd_app_log("clEnqueueCopyImage(%p, %p, %p, %p, %p, %p, %u, %p, %p)\n", + command_queue, + image, + image, + data->src_origin, + data->dst_origin, + data->region, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val = clEnqueueCopyImage(command_queue, + image, + image, + data->src_origin, + data->dst_origin, + data->region, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + + +int test_clGetImageInfo(const struct clGetImageInfo_st *data) +{ + test_icd_app_log("clGetImageInfo(%p, %u, %u, %p, %p)\n", + image, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val = clGetImageInfo(image, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_image_objects() +{ + int i; + + for (i = 0; i +#include "param_struct.h" +#include + +extern cl_kernel kernel; +extern cl_event event; +extern cl_context context; +extern cl_command_queue command_queue; +extern cl_device_id devices; +static int ret_val; +extern void CL_CALLBACK setevent_callback(cl_event _a, cl_int _b, void* _c); +extern void CL_CALLBACK setprintf_callback(cl_context _a, cl_uint _b, char* _c, void* _d ); + +struct clRetainKernel_st clRetainKernelData[NUM_ITEMS_clRetainKernel] = +{ + {NULL} +}; + +int test_clRetainKernel(const struct clRetainKernel_st* data) +{ + test_icd_app_log("clRetainKernel(%p)\n", kernel); + + ret_val=clRetainKernel(kernel); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clSetKernelArg_st clSetKernelArgData[NUM_ITEMS_clSetKernelArg] = +{ + {NULL, 0, 0, NULL} +}; + +int test_clSetKernelArg(const struct clSetKernelArg_st* data) +{ + test_icd_app_log("clSetKernelArg(%p, %u, %u, %p)\n", + kernel, + data->arg_index, + data->arg_size, + data->arg_value); + + ret_val=clSetKernelArg(kernel, + data->arg_index, + data->arg_size, + data->arg_value); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clGetKernelInfo_st clGetKernelInfoData[NUM_ITEMS_clGetKernelInfo] = +{ + {NULL, 0, 0, NULL, NULL} +}; + +int test_clGetKernelInfo(const struct clGetKernelInfo_st* data) +{ + test_icd_app_log("clGetKernelInfo(%p, %u, %u, %p, %p)\n", + kernel, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val=clGetKernelInfo(kernel, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clGetKernelArgInfo_st clGetKernelArgInfoData[NUM_ITEMS_clGetKernelArgInfo] = +{ + {NULL, 0, 0, 0, NULL, NULL} +}; + +int test_clGetKernelArgInfo(const struct clGetKernelArgInfo_st* data) +{ + test_icd_app_log("clGetKernelArgInfo(%p, %u, %u, %u, %p, %p)\n", + kernel, + data->arg_indx, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val=clGetKernelArgInfo(kernel, + data->arg_indx, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clGetKernelWorkGroupInfo_st clGetKernelWorkGroupInfoData[NUM_ITEMS_clGetKernelWorkGroupInfo] = +{ + {NULL, NULL, 0, 0, NULL, NULL} +}; + +int test_clGetKernelWorkGroupInfo(const struct clGetKernelWorkGroupInfo_st* data) +{ + test_icd_app_log("clGetKernelWorkGroupInfo(%p, %p, %u, %u, %p, %p)\n", + kernel, + devices, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val=clGetKernelWorkGroupInfo(kernel, + devices, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clEnqueueMigrateMemObjects_st clEnqueueMigrateMemObjectsData[NUM_ITEMS_clEnqueueMigrateMemObjects] = +{ + {NULL, 0, NULL, 0x0, 0, NULL, NULL} +}; + +int test_clEnqueueMigrateMemObjects(const struct clEnqueueMigrateMemObjects_st* data) +{ + test_icd_app_log("clEnqueueMigrateMemObjects(%p, %u, %p, %x, %u, %p, %p)\n", + command_queue, + data->num_mem_objects, + data->mem_objects, + data->flags, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueMigrateMemObjects(command_queue, + data->num_mem_objects, + data->mem_objects, + data->flags, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clEnqueueNDRangeKernel_st clEnqueueNDRangeKernelData[NUM_ITEMS_clEnqueueNDRangeKernel] = +{ + {NULL, NULL, 0, NULL, NULL, NULL, 0, NULL} +}; + +int test_clEnqueueNDRangeKernel(const struct clEnqueueNDRangeKernel_st* data) +{ + test_icd_app_log("clEnqueueNDRangeKernel(%p, %p, %u, %p, %p, %p, %u, %p, %p)\n", + command_queue, + kernel, + data->work_dim, + data->global_work_offset, + data->global_work_size, + data->local_work_size, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueNDRangeKernel(command_queue, + kernel, + data->work_dim, + data->global_work_offset, + data->global_work_size, + data->local_work_size, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clEnqueueTask_st clEnqueueTaskData[NUM_ITEMS_clEnqueueTask] = +{ + {NULL, NULL, 0, NULL, NULL} +}; + +int test_clEnqueueTask(const struct clEnqueueTask_st* data) +{ + test_icd_app_log("clEnqueueTask(%p, %p, %u, %p, %p)\n", + command_queue, + kernel, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueTask(command_queue, + kernel, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} +struct clEnqueueNativeKernel_st clEnqueueNativeKernelData[NUM_ITEMS_clEnqueueNativeKernel] = +{ + {NULL, NULL, NULL, 0, 0, NULL, NULL, 0, NULL, NULL} +}; + +int test_clEnqueueNativeKernel(const struct clEnqueueNativeKernel_st* data) { + test_icd_app_log("clEnqueueNativeKernel(%p, %p, %p, %u, %u, %p, %p, %u, %p, %p)\n", + command_queue, + data->user_func, + data->args, + data->cb_args, + data->num_mem_objects, + data->mem_list, + data->args_mem_loc, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueNativeKernel(command_queue, + data->user_func, + data->args, + data->cb_args, + data->num_mem_objects, + data->mem_list, + data->args_mem_loc, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + return 0; +} + +struct clSetUserEventStatus_st clSetUserEventStatusData[NUM_ITEMS_clSetUserEventStatus] = +{ + {NULL, 0} +}; + +int test_clSetUserEventStatus(const struct clSetUserEventStatus_st* data) +{ + test_icd_app_log("clSetUserEventStatus(%p, %d)\n", + event, + data->execution_status); + + ret_val=clSetUserEventStatus(event, + data->execution_status); + + test_icd_app_log("Value returned: %d\n", ret_val); + return 0; +} + +struct clWaitForEvents_st clWaitForEventsData[NUM_ITEMS_clWaitForEvents] = +{ + {1, NULL} +}; + +int test_clWaitForEvents(const struct clWaitForEvents_st* data) +{ + test_icd_app_log("clWaitForEvents(%u, %p)\n", + data->num_events, + &event); + + ret_val=clWaitForEvents(data->num_events, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + return 0; +} + +struct clGetEventInfo_st clGetEventInfoData[NUM_ITEMS_clGetEventInfo] = +{ + {NULL, 0, 0, NULL, NULL} +}; + +int test_clGetEventInfo(const struct clGetEventInfo_st* data){ + test_icd_app_log("clGetEventInfo(%p, %u, %u, %p, %p)\n", + event, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val=clGetEventInfo(event, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clSetEventCallback_st clSetEventCallbackData[NUM_ITEMS_clSetEventCallback] = +{ + {NULL, 0, setevent_callback, NULL} +}; + +int test_clSetEventCallback(const struct clSetEventCallback_st* data) +{ + test_icd_app_log("clSetEventCallback(%p, %d, %p, %p)\n", + event, + data->command_exec_callback_type, + data->pfn_event_notify, + data->user_data); + + ret_val=clSetEventCallback(event, + data->command_exec_callback_type, + data->pfn_event_notify, + data->user_data); + + test_icd_app_log("Value returned: %d\n", ret_val); + return 0; +} + +struct clRetainEvent_st clRetainEventData[NUM_ITEMS_clRetainEvent] = +{ + {NULL} +}; + +int test_clRetainEvent(const struct clRetainEvent_st* data) +{ + test_icd_app_log("clRetainEvent(%p)\n", event); + + ret_val=clRetainEvent(event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clEnqueueMarker_st clEnqueueMarkerData[NUM_ITEMS_clEnqueueMarker] = +{ + {NULL, NULL} +}; + +int test_clEnqueueMarker(const struct clEnqueueMarker_st* data) +{ + test_icd_app_log("clEnqueueMarker(%p, %p)\n", command_queue, &event); + + ret_val = clEnqueueMarker(command_queue, &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clEnqueueMarkerWithWaitList_st clEnqueueMarkerWithWaitListData[NUM_ITEMS_clEnqueueMarkerWithWaitList] = +{ + {NULL, 0, NULL, NULL} +}; + +int test_clEnqueueMarkerWithWaitList(const struct clEnqueueMarkerWithWaitList_st* data) +{ + test_icd_app_log("clEnqueueMarkerWithWaitList(%p, %u, %p, %p)\n", + command_queue, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueMarkerWithWaitList(command_queue, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clEnqueueBarrierWithWaitList_st clEnqueueBarrierWithWaitListData[NUM_ITEMS_clEnqueueBarrierWithWaitList] = +{ + {NULL, 0, NULL, NULL} +}; +int test_clEnqueueBarrierWithWaitList(const struct clEnqueueBarrierWithWaitList_st* data) +{ + test_icd_app_log("clEnqueueBarrierWithWaitList(%p, %u, %p, %p)\n", + command_queue, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + ret_val=clEnqueueBarrierWithWaitList(command_queue, + data->num_events_in_wait_list, + data->event_wait_list, + &event); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clEnqueueWaitForEvents_st clEnqueueWaitForEventsData[NUM_ITEMS_clEnqueueWaitForEvents] = +{ + {NULL, 0, NULL} +}; + +int test_clEnqueueWaitForEvents(const struct clEnqueueWaitForEvents_st* data) +{ + test_icd_app_log("clEnqueueWaitForEvents(%p, %u, %p)\n", + command_queue, + data->num_events, + data->event_list); + + ret_val = clEnqueueWaitForEvents(command_queue, + data->num_events, + data->event_list); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clEnqueueBarrier_st clEnqueueBarrierData[NUM_ITEMS_clEnqueueBarrier] = +{ + {NULL} +}; + +int test_clEnqueueBarrier(const struct clEnqueueBarrier_st* data) +{ + test_icd_app_log("clEnqueueBarrier(%p)\n", command_queue); + + ret_val = clEnqueueBarrier(command_queue); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} +struct clGetEventProfilingInfo_st clGetEventProfilingInfoData[NUM_ITEMS_clGetEventProfilingInfo] = +{ + {NULL, 0, 0, NULL, NULL} +}; + +int test_clGetEventProfilingInfo(const struct clGetEventProfilingInfo_st* data) +{ + test_icd_app_log("clGetEventProfilingInfo(%p, %u, %u, %p, %p)\n", + event, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val=clGetEventProfilingInfo(event, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clFlush_st clFlushData[NUM_ITEMS_clFlush] = +{ + {NULL} +}; + +int test_clFlush(const struct clFlush_st* data) +{ + test_icd_app_log("clFlush(%p)\n", command_queue); + + ret_val=clFlush(command_queue); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +struct clFinish_st clFinishData[NUM_ITEMS_clFinish] = +{ + {NULL} +}; + +int test_clFinish(const struct clFinish_st* data) +{ + test_icd_app_log("clFinish(%p)\n", command_queue); + + ret_val=clFinish(command_queue); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +int test_kernel() +{ + int i; + + for (i=0; i +#include "param_struct.h" +#include + +extern cl_context context; + +extern cl_platform_id platform; + +extern cl_device_id devices; + +static int ret_val; + +struct clRetainContext_st clRetainContextData[NUM_ITEMS_clRetainContext] = +{ + {NULL} +}; + +struct clGetContextInfo_st clGetContextInfoData[NUM_ITEMS_clGetContextInfo] = +{ + {NULL, 0, 0, NULL, NULL} +}; + + +struct clGetPlatformInfo_st clGetPlatformInfoData[NUM_ITEMS_clGetPlatformInfo] = +{ + {NULL, 0, 0, NULL, NULL} +}; + +struct clGetDeviceInfo_st clGetDeviceInfoData[NUM_ITEMS_clGetDeviceInfo] = +{ + {NULL, 0, 0, NULL, NULL} +}; + +struct clCreateSubDevices_st clCreateSubDevicesData[NUM_ITEMS_clCreateSubDevices] = +{ + {NULL, NULL, 0, NULL, NULL} +}; + + +struct clRetainDevice_st clRetainDeviceData[NUM_ITEMS_clRetainDevice] = +{ + {NULL} +}; + + +int test_clRetainContext(const struct clRetainContext_st* data) +{ + test_icd_app_log("clRetainContext(%p)\n", context); + + ret_val = clRetainContext(context); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + + + +int test_clGetContextInfo(const struct clGetContextInfo_st* data) +{ + test_icd_app_log("clGetContextInfo(%p, %u, %u, %p, %p)\n", + context, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + + ret_val = clGetContextInfo(context, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +int test_clGetPlatformInfo(const struct clGetPlatformInfo_st* data) +{ + test_icd_app_log("clGetPlatformInfo(%p, %u, %u, %p, %p)\n", + platform, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val = clGetPlatformInfo(platform, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clGetDeviceInfo(const struct clGetDeviceInfo_st* data) +{ + test_icd_app_log("clGetDeviceInfo(%p, %u, %u, %p, %p)\n", + devices, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val = clGetDeviceInfo(devices, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +int test_clCreateSubDevices(const struct clCreateSubDevices_st* data) +{ + test_icd_app_log("clCreateSubDevices(%p, %p, %u, %p, %p)\n", + devices, + data->properties, + data->num_entries, + &devices, + data->num_devices); + + ret_val = clCreateSubDevices(devices, + data->properties, + data->num_entries, + &devices, + data->num_devices); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +int test_clRetainDevice(const struct clRetainDevice_st* data) +{ + test_icd_app_log("clRetainDevice(%p)\n", devices); + + ret_val = clRetainDevice(devices); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +int test_platforms() +{ + int i; + + for (i = 0;i +#include "param_struct.h" +#include + +extern cl_context context; +extern cl_program program; +extern cl_platform_id platform; +extern cl_device_id devices; + +static int ret_val; + +extern void CL_CALLBACK program_callback(cl_program _a, void* _b); + +const struct clRetainProgram_st clRetainProgramData[NUM_ITEMS_clRetainProgram]= +{ + {NULL} +}; + +const struct clBuildProgram_st clBuildProgramData[NUM_ITEMS_clBuildProgram]= +{ + {NULL,0,NULL,NULL,program_callback,NULL} +}; + +const struct clCompileProgram_st clCompileProgramData[NUM_ITEMS_clCompileProgram]= +{ + {NULL,0,NULL,NULL,0,NULL,NULL,program_callback,NULL} +}; + +const struct clLinkProgram_st clLinkProgramData[NUM_ITEMS_clLinkProgram]= +{ + {NULL,0,NULL,NULL,0,NULL,program_callback,NULL,NULL} +}; + +const struct clUnloadPlatformCompiler_st clUnloadPlatformCompilerData[NUM_ITEMS_clUnloadPlatformCompiler]= +{ + {NULL} +}; + +const struct clGetExtensionFunctionAddressForPlatform_st clGetExtensionFunctionAddressForPlatformData[NUM_ITEMS_clGetExtensionFunctionAddressForPlatform]= +{ + {NULL, ""} +}; + +const struct clGetProgramInfo_st clGetProgramInfoData[NUM_ITEMS_clGetProgramInfo]= +{ + {NULL,0,0,NULL,NULL} +}; + +const struct clGetProgramBuildInfo_st clGetProgramBuildInfoData[NUM_ITEMS_clGetProgramBuildInfo]= +{ + {NULL,NULL,0,0,NULL,NULL} +}; + +int test_clRetainProgram(const struct clRetainProgram_st *data) +{ + test_icd_app_log("clRetainProgram(%p)\n", + program); + + ret_val=clRetainProgram(program); + + test_icd_app_log("Value returned: %d\n", + ret_val); + + return 0; + +} + +int test_clBuildProgram(const struct clBuildProgram_st *data) +{ + test_icd_app_log("clBuildProgram(%p, %u, %p, %p, %p, %p)\n", + program, + data->num_devices, + &devices, + data->options, + data->pfn_notify, + data->user_data); + + ret_val=clBuildProgram(program, + data->num_devices, + &devices, + data->options, + data->pfn_notify, + data->user_data); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clCompileProgram(const struct clCompileProgram_st *data) +{ + test_icd_app_log("clCompileProgram(%p, %u, %p, %p, %u, %p, %p, %p)\n", + program, + data->num_devices, + &devices, + data->options, + data->num_input_headers, + data->header_include_names, + data->pfn_notify, + data->user_data); + + ret_val=clCompileProgram(program, + data->num_devices, + &devices, + data->options, + data->num_input_headers, + data->headers, + data->header_include_names, + data->pfn_notify, + data->user_data); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clLinkProgram(const struct clLinkProgram_st *data) +{ + cl_program program; + test_icd_app_log("clLinkProgram(%p, %u, %p, %p, %u, %p, %p, %p, %p)\n", + context, + data->num_devices, + data->device_list, + data->options, + data->num_input_programs, + data->input_programs, + data->pfn_notify, + data->user_data, + data->errcode_ret); + + program=clLinkProgram(context, + data->num_devices, + data->device_list, + data->options, + data->num_input_programs, + data->input_programs, + data->pfn_notify, + data->user_data, + data->errcode_ret); + + test_icd_app_log("Value returned: %p\n", program); + + return 0; + +} + +int test_clUnloadPlatformCompiler(const struct clUnloadPlatformCompiler_st *data) +{ + test_icd_app_log("clUnloadPlatformCompiler(%p)\n", platform); + + ret_val=clUnloadPlatformCompiler(platform); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clGetExtensionFunctionAddressForPlatform(const struct clGetExtensionFunctionAddressForPlatform_st *data) +{ + void *return_value; + test_icd_app_log("clGetExtensionFunctionAddressForPlatform(%p, %p)\n", + platform, + data->func_name); + + return_value=clGetExtensionFunctionAddressForPlatform(platform, + data->func_name); + + test_icd_app_log("Value returned: %p\n", return_value); + + return 0; + +} + +int test_clGetProgramInfo(const struct clGetProgramInfo_st *data) +{ + test_icd_app_log("clGetProgramInfo(%p, %u, %u, %p, %p)\n", + program, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val=clGetProgramInfo(program, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_clGetProgramBuildInfo(const struct clGetProgramBuildInfo_st *data) +{ + test_icd_app_log("clGetProgramBuildInfo(%p, %p, %u, %u, %p, %p)\n", + program, + data->device, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val=clGetProgramBuildInfo(program, + data->device, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; + +} + +int test_program_objects() +{ + int i; + + for (i=0;i +#include "param_struct.h" +#include + +extern cl_sampler sampler; +static int ret_val; + +const struct clRetainSampler_st clRetainSamplerData[NUM_ITEMS_clRetainSampler]= +{ + { NULL } +}; + +const struct clGetSamplerInfo_st clGetSamplerInfoData[NUM_ITEMS_clGetSamplerInfo]= +{ + { NULL, 0, 0, NULL, NULL } +}; + + +int test_clRetainSampler(const struct clRetainSampler_st *data) +{ + test_icd_app_log("clRetainSampler(%p)\n", sampler); + + ret_val=clRetainSampler(sampler); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +int test_clGetSamplerInfo(const struct clGetSamplerInfo_st *data) +{ + test_icd_app_log("clGetSamplerInfo(%p, %u, %u, %p, %p)\n", + sampler, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + ret_val=clGetSamplerInfo(sampler, + data->param_name, + data->param_value_size, + data->param_value, + data->param_value_size_ret); + + test_icd_app_log("Value returned: %d\n", ret_val); + + return 0; +} + +int test_sampler_objects() +{ + int i; + + for (i=0;i +#include +#include +#include +#include +#include + +#define APP_LOG_FILE "icd_test_app_log.txt" +#define STUB_LOG_FILE "icd_test_stub_log.txt" + +static FILE *app_log_file; +static FILE *stub_log_file; + +int test_icd_initialize_app_log(void) +{ + app_log_file = fopen(APP_LOG_FILE, "w"); + if (!app_log_file) { + printf("Unable to open file %s\n", APP_LOG_FILE); + return -1; + } + + return 0; +} + +void test_icd_close_app_log(void) +{ + fclose(app_log_file); +} + +void test_icd_app_log(const char *format, ...) +{ + va_list args; + va_start(args, format); + vfprintf(app_log_file, format, args); + va_end(args); +} + +int test_icd_initialize_stub_log(void) +{ + stub_log_file = fopen(STUB_LOG_FILE, "w"); + if (!stub_log_file) { + printf("Unable to open file %s\n", STUB_LOG_FILE); + return -1; + } + + return 0; + +} + +void test_icd_close_stub_log(void) +{ + fclose(stub_log_file); +} + +void test_icd_stub_log(const char *format, ...) +{ + va_list args; + va_start(args, format); + vfprintf(stub_log_file, format, args); + va_end(args); +} + +static char *test_icd_get_log(const char *filename) +{ + struct stat statbuf; + FILE *fp; + char *source = NULL; + + fp = fopen(filename, "rb"); + + if (fp) { + size_t fsize = 0; + stat(filename, &statbuf); + fsize = statbuf.st_size; + source = (char *)malloc(fsize+1); // +1 for NULL terminator + if (source) { + if (fsize) { + if (fread(source, fsize, 1, fp) != 1) { + free(source); + source = NULL; + } else { + source[fsize] = '\0'; + } + } else { + // Don't fail when fsize = 0, just return empty string + source[fsize] = '\0'; + } + } + fclose(fp); + } + + return source; +} + +char *test_icd_get_app_log(void) +{ + return test_icd_get_log(APP_LOG_FILE); +} + +char *test_icd_get_stub_log(void) +{ + return test_icd_get_log(STUB_LOG_FILE); +} diff --git a/opencl/opencl-backward-compat.cmake b/opencl/opencl-backward-compat.cmake new file mode 100644 index 0000000000..92e08898ca --- /dev/null +++ b/opencl/opencl-backward-compat.cmake @@ -0,0 +1,149 @@ +# Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved. +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +cmake_minimum_required(VERSION 3.16.8) + +set(OPENCL ${PROJECT_NAME}) +set(OPENCL_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set(OPENCL_WRAPPER_DIR ${OPENCL_BUILD_DIR}/wrapper_dir) +set(OPENCL_WRAPPER_INC_DIR ${OPENCL_WRAPPER_DIR}/include/CL) +set(OPENCL_WRAPPER_BIN_DIR ${OPENCL_WRAPPER_DIR}/bin) +set(OPENCL_WRAPPER_LIB_DIR ${OPENCL_WRAPPER_DIR}/lib) + +#Function to generate header template file +function(create_header_template) + file(WRITE ${OPENCL_WRAPPER_DIR}/header.hpp.in "/* + Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the \"Software\"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +#ifndef @include_guard@ +#define @include_guard@ + +#if defined(_MSC_VER) +#pragma message(\"This file is deprecated. Use file from include path /opt/rocm-ver/include/ and prefix with CL\") +#elif defined(__GNUC__) +#warning \"This file is deprecated. Use file from include path /opt/rocm-ver/include/ and prefix with CL\" +#endif + +@include_statements@ + +#endif") +endfunction() + + +#use header template file and generate wrapper header files +function(generate_wrapper_header) + file(MAKE_DIRECTORY ${OPENCL_WRAPPER_INC_DIR}) + set(HEADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/khronos/headers/opencl2.2/CL ) + #find all header files from CL folder + file(GLOB include_files ${CMAKE_CURRENT_SOURCE_DIR}/khronos/headers/opencl2.2/CL/*) + #remove files that are not required in package + list(REMOVE_ITEM include_files ${HEADER_DIR}/cl_egl.h ${HEADER_DIR}/cl_dx9_media_sharing.h ${HEADER_DIR}/cl_d3d11.h ${HEADER_DIR}/cl_d3d10.h) + #Generate wrapper header files + foreach(header_file ${include_files}) + # set include guard + get_filename_component(INC_GAURD_NAME ${header_file} NAME_WE) + string(TOUPPER ${INC_GAURD_NAME} INC_GAURD_NAME) + set(include_guard "${include_guard}OPENCL_WRAPPER_INCLUDE_${INC_GAURD_NAME}_H") + #set #include statement + get_filename_component(file_name ${header_file} NAME) + set(include_statements "${include_statements}#include \"../../../${CMAKE_INSTALL_INCLUDEDIR}/CL/${file_name}\"\n") + configure_file(${OPENCL_WRAPPER_DIR}/header.hpp.in ${OPENCL_WRAPPER_INC_DIR}/${file_name}) + unset(include_guard) + unset(include_statements) + endforeach() + +endfunction() + +#function to create symlink to binaries +function(create_binary_symlink) + file(MAKE_DIRECTORY ${OPENCL_WRAPPER_BIN_DIR}) + set(file_name "clinfo") + add_custom_target(link_${file_name} ALL + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E create_symlink + ../../${CMAKE_INSTALL_BINDIR}/${file_name} ${OPENCL_WRAPPER_BIN_DIR}/${file_name}) +endfunction() + +#function to create symlink to libraries +function(create_library_symlink) + if(BUILD_ICD) + file(MAKE_DIRECTORY ${OPENCL_WRAPPER_LIB_DIR}) + set(LIB_OPENCL "libOpenCL.so") + set(MAJ_VERSION "${OPENCL_LIB_VERSION_MAJOR}") + set(SO_VERSION "${OPENCL_LIB_VERSION_STRING}") + set(library_files "${LIB_OPENCL}" "${LIB_OPENCL}.${MAJ_VERSION}" "${LIB_OPENCL}.${SO_VERSION}") + + foreach(file_name ${library_files}) + add_custom_target(link_${file_name} ALL + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E create_symlink + ../../${CMAKE_INSTALL_LIBDIR}/${file_name} ${OPENCL_WRAPPER_LIB_DIR}/${file_name}) + endforeach() + endif() + if(BUILD_SHARED_LIBS) + set(LIB_AMDDOC "libamdocl64.so") + else() + set(LIB_AMDDOC "libamdocl64.a") + endif() + set(file_name "${LIB_AMDDOC}") + add_custom_target(link_${file_name} ALL + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E create_symlink + ../../${CMAKE_INSTALL_LIBDIR}/${file_name} ${OPENCL_WRAPPER_DIR}/${file_name}) +endfunction() + +#Creater a template for header file +create_header_template() +#Use template header file and generater wrapper header files +generate_wrapper_header() +install(DIRECTORY ${OPENCL_WRAPPER_INC_DIR} DESTINATION ${OPENCL}/include COMPONENT dev) +# Create symlink to binaries +create_binary_symlink() +install(DIRECTORY ${OPENCL_WRAPPER_BIN_DIR} DESTINATION ${OPENCL} COMPONENT binary) + +option(BUILD_SHARED_LIBS "Build the shared library" ON) +# Create symlink to libraries +create_library_symlink() +if(BUILD_ICD) + install(DIRECTORY ${OPENCL_WRAPPER_LIB_DIR} DESTINATION ${OPENCL} COMPONENT icd) +endif() +if(BUILD_SHARED_LIBS) + install(FILES ${OPENCL_WRAPPER_DIR}/libamdocl64.so DESTINATION ${OPENCL}/lib COMPONENT binary) +else() + install(FILES ${OPENCL_WRAPPER_DIR}/libamdocl64.a DESTINATION ${OPENCL}/lib COMPONENT binary) +endif() diff --git a/opencl/packaging/CMakeLists.txt b/opencl/packaging/CMakeLists.txt new file mode 100644 index 0000000000..a703f58a15 --- /dev/null +++ b/opencl/packaging/CMakeLists.txt @@ -0,0 +1,146 @@ +cmake_minimum_required(VERSION 3.5.1) +project(rocm-opencl) + +set(CPACK_COMPONENTS_ALL binary dev) +if(BUILD_ICD) +set(CPACK_COMPONENTS_ALL "${CPACK_COMPONENTS_ALL}" icd) +endif() +if(BUILD_TESTS) +set(CPACK_COMPONENTS_ALL "${CPACK_COMPONENTS_ALL}" ocltst) +endif() + +set(CPACK_DEB_COMPONENT_INSTALL ON) +set(CPACK_RPM_COMPONENT_INSTALL ON) + +install(TARGETS clinfo DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT binary) +install(TARGETS amdocl DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT binary) +install(FILES ${CMAKE_SOURCE_DIR}/LICENSE.txt DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT binary) + +install(DIRECTORY ${CMAKE_SOURCE_DIR}/khronos/headers/opencl2.2/CL + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT dev + USE_SOURCE_PERMISSIONS + PATTERN cl_d3d10.h EXCLUDE + PATTERN cl_d3d11.h EXCLUDE + PATTERN cl_dx9_media_sharing.h EXCLUDE ) + +if(BUILD_ICD) + install(TARGETS OpenCL DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT icd ) + install(FILES ${CMAKE_SOURCE_DIR}/khronos/icd/LICENSE DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/rocm-ocl-icd COMPONENT icd) +endif() + + +# Generic CPACK variables +set(CPACK_GENERATOR "DEB;RPM" CACHE STRING "Package types to build") +set(CPACK_PACKAGE_CONTACT "ROCm OpenCL Support ") +set(CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc.") +set(CPACK_PACKAGE_DESCRIPTION "OpenCL: Open Computing Language on ROCclr") + + + + +#########Binary-Package############### +set(CPACK_DEBIAN_BINARY_PACKAGE_NAME "rocm-opencl") +set(CPACK_RPM_BINARY_PACKAGE_NAME "rocm-opencl") + +# Debian CPACK variables +set(CPACK_BINARY_DEB "ON") +if(DEFINED ENV{CPACK_DEBIAN_PACKAGE_RELEASE}) + set(CPACK_DEBIAN_PACKAGE_RELEASE $ENV{CPACK_DEBIAN_PACKAGE_RELEASE}) +else() + set(CPACK_DEBIAN_PACKAGE_RELEASE "local") +endif() +message("Using CPACK_DEBIAN_PACKAGE_RELEASE ${CPACK_DEBIAN_PACKAGE_RELEASE}") + +set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT") +if(BUILD_ICD) + set(CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS "rocm-ocl-icd, libelf-dev, comgr, hsa-rocr, rocm-core") +else() + set(CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS "ocl-icd-libopencl1, libelf-dev, comgr, hsa-rocr, rocm-core") +endif() + +# RPM CPACK variables +set(CPACK_BINARY_RPM "ON") +if(BUILD_ICD) + set(CPACK_RPM_BINARY_PACKAGE_REQUIRES "rocm-ocl-icd, comgr, hsa-rocr, rocm-core") +else() + set(CPACK_RPM_BINARY_PACKAGE_REQUIRES "ocl-icd, comgr, hsa-rocr, rocm-core") +endif() + +#Unable to set CPACK_RPM_BIANRY_PACKAGE_LICENSE to control individual pacakge license +#Hence combining the license for BINARY,DEV,ICD to one +set(CPACK_RPM_PACKAGE_LICENSE "MIT and ASL 2.0") + +#########Dev-Package############### + +# DEBIAN CPACK variables +set(CPACK_DEBIAN_DEV_PACKAGE_NAME "rocm-opencl-dev") +set(CPACK_DEBIAN_DEV_PACKAGE_DEPENDS "mesa-common-dev, rocm-opencl, hsa-rocr-dev, rocm-core") +# RPM CPACK variables +set(CPACK_RPM_DEV_PACKAGE_NAME "rocm-opencl-devel") +set(CPACK_RPM_DEV_PACKAGE_REQUIRES "rocm-opencl, hsa-rocr-devel, rocm-core") + + +############################# +# ICD Loader +############################# + +# Debian CPACK variables +if(BUILD_ICD) + set(CPACK_ICD_DEB "ON") + set(CPACK_DEBIAN_ICD_PACKAGE_NAME "rocm-ocl-icd") + + set(CPACK_DEBIAN_ICD_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/packages/rocm-ocl-icd/postinst;${CMAKE_BINARY_DIR}/packages/rocm-ocl-icd/prerm") + set(CPACK_DEBIAN_ICD_PACKAGE_DEPENDS "rocm-core") + +# RPM CPACK variables + set(CPACK_ICD_RPM "ON") + set(CPACK_RPM_ICD_PACKAGE_NAME "rocm-ocl-icd") + + + + set(CPACK_RPM_ICD_POST_INSTALL_SCRIPT_FILE "${CMAKE_BINARY_DIR}/packages/rocm-ocl-icd/rpm_post") + set(CPACK_RPM_ICD_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_BINARY_DIR}/packages/rocm-ocl-icd/rpm_postun") + set(CPACK_RPM_ICD_PACKAGE_REQUIRES "rocm-core") +endif() + +if(BUILD_TESTS) + set(CPACK_OCLTST_DEB "ON") + set(CPACK_DEBIAN_OCLTST_PACKAGE_NAME "rocm-ocltst") + set(CPACK_OCLTST_RPM "ON") + set(CPACK_RPM_OCLTST_PACKAGE_NAME "rocm-ocltst") +endif() + +if(DEFINED ENV{CPACK_RPM_PACKAGE_RELEASE}) + set(CPACK_RPM_PACKAGE_RELEASE $ENV{CPACK_RPM_PACKAGE_RELEASE}) +else() + set(CPACK_RPM_PACKAGE_RELEASE "local") +endif() +message("Using CPACK_RPM_PACKAGE_RELEASE ${CPACK_RPM_PACKAGE_RELEASE}") + + +set(CPACK_RPM_FILE_NAME "RPM-DEFAULT") +set(CPACK_RPM_PACKAGE_AUTOREQPROV " no") + +## 'dist' breaks manual builds on debian systems due to empty Provides +execute_process(COMMAND rpm --eval %{?dist} + RESULT_VARIABLE PROC_RESULT + OUTPUT_VARIABLE EVAL_RESULT + OUTPUT_STRIP_TRAILING_WHITESPACE) +message("RESULT_VARIABLE ${PROC_RESULT} OUTPUT_VARIABLE: ${EVAL_RESULT}") + +if(PROC_RESULT EQUAL "0" AND NOT EVAL_RESULT STREQUAL "") + string(APPEND CPACK_RPM_PACKAGE_RELEASE "%{?dist}") +endif() +# Remove dependency on rocm-core if -DROCM_DEP_ROCMCORE=ON not given to cmake +if(NOT ROCM_DEP_ROCMCORE) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_BINARY_PACKAGE_REQUIRES ${CPACK_RPM_BINARY_PACKAGE_REQUIRES}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS ${CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_DEV_PACKAGE_REQUIRES ${CPACK_RPM_DEV_PACKAGE_REQUIRES}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_DEV_PACKAGE_DEPENDS ${CPACK_DEBIAN_DEV_PACKAGE_DEPENDS}) + if(BUILD_ICD) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_ICD_PACKAGE_REQUIRES ${CPACK_RPM_ICD_PACKAGE_REQUIRES}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_ICD_PACKAGE_DEPENDS ${CPACK_DEBIAN_ICD_PACKAGE_DEPENDS}) + endif() +endif() + +include(CPack) diff --git a/opencl/packaging/rocm-ocl-icd.postinst b/opencl/packaging/rocm-ocl-icd.postinst new file mode 100644 index 0000000000..e22be0df9c --- /dev/null +++ b/opencl/packaging/rocm-ocl-icd.postinst @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +INSTALL_PATH=@CPACK_PACKAGING_INSTALL_PREFIX@ + +do_ldconfig() { + echo ${INSTALL_PATH}/@CMAKE_INSTALL_LIBDIR@ > /@CMAKE_INSTALL_SYSCONFDIR@/ld.so.conf.d/10-rocm-opencl.conf && ldconfig + mkdir -p /@CMAKE_INSTALL_SYSCONFDIR@/OpenCL/vendors && (echo libamdocl64.so > /@CMAKE_INSTALL_SYSCONFDIR@/OpenCL/vendors/@OPENCL_AMD_ICD_FILE@) +} + +case "$1" in + abort-deconfigure|abort-remove|abort-upgrade) + echo "$1" + ;; + configure) + do_ldconfig + ;; + *) + exit 0 + ;; +esac diff --git a/opencl/packaging/rocm-ocl-icd.prerm b/opencl/packaging/rocm-ocl-icd.prerm new file mode 100644 index 0000000000..4843048571 --- /dev/null +++ b/opencl/packaging/rocm-ocl-icd.prerm @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +rm_ldconfig() { + rm -f /@CMAKE_INSTALL_SYSCONFDIR@/ld.so.conf.d/10-rocm-opencl.conf && ldconfig + rm -f /@CMAKE_INSTALL_SYSCONFDIR@/OpenCL/vendors/@OPENCL_AMD_ICD_FILE@ +} + +case "$1" in + purge) + ;; + remove | upgrade ) + rm_ldconfig + ;; + *) + exit 0 + ;; +esac diff --git a/opencl/packaging/rocm-ocl-icd.rpm_post b/opencl/packaging/rocm-ocl-icd.rpm_post new file mode 100644 index 0000000000..b467f63ba8 --- /dev/null +++ b/opencl/packaging/rocm-ocl-icd.rpm_post @@ -0,0 +1,4 @@ +INSTALL_PATH=@CPACK_PACKAGING_INSTALL_PREFIX@ + +echo ${INSTALL_PATH}/@CMAKE_INSTALL_LIBDIR@ > /@CMAKE_INSTALL_SYSCONFDIR@/ld.so.conf.d/10-rocm-opencl.conf && ldconfig +mkdir -p /@CMAKE_INSTALL_SYSCONFDIR@/OpenCL/vendors && (echo libamdocl64.so > /@CMAKE_INSTALL_SYSCONFDIR@/OpenCL/vendors/@OPENCL_AMD_ICD_FILE@) diff --git a/opencl/packaging/rocm-ocl-icd.rpm_postun b/opencl/packaging/rocm-ocl-icd.rpm_postun new file mode 100644 index 0000000000..f3655dfe90 --- /dev/null +++ b/opencl/packaging/rocm-ocl-icd.rpm_postun @@ -0,0 +1,8 @@ +if [ $1 -eq 0 ]; then + # Remove rocm-opencl.conf during remove/uninstall operation + rm -f /@CMAKE_INSTALL_SYSCONFDIR@/ld.so.conf.d/10-rocm-opencl.conf && ldconfig +fi +# Remove icd file for uninstall and upgrade operation +rm -f /@CMAKE_INSTALL_SYSCONFDIR@/OpenCL/vendors/@OPENCL_AMD_ICD_FILE@ + + diff --git a/opencl/tests/ocltst/CMakeLists.txt b/opencl/tests/ocltst/CMakeLists.txt new file mode 100644 index 0000000000..2938820e1e --- /dev/null +++ b/opencl/tests/ocltst/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.5.1) + +set(OCLTST_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + +if (WIN32) + set(OCLTST_INSTALL_DIR "tests/ocltst") +else() + set(OCLTST_INSTALL_DIR "share/ocltst") +endif() + +find_package(OpenGL) +find_package(GLEW) + +add_subdirectory(module/common) +add_subdirectory(env) +if(OPENGL_FOUND AND GLEW_FOUND) + add_subdirectory(module/gl) +endif() +add_subdirectory(module/perf) +add_subdirectory(module/runtime) diff --git a/opencl/tests/ocltst/env/CMakeLists.txt b/opencl/tests/ocltst/env/CMakeLists.txt new file mode 100644 index 0000000000..308acc7d6c --- /dev/null +++ b/opencl/tests/ocltst/env/CMakeLists.txt @@ -0,0 +1,45 @@ +add_executable(ocltst) + +target_sources(ocltst PRIVATE + ${OCLTST_DIR}/env/oclTestLog.cpp + ${OCLTST_DIR}/env/oclsysinfo.cpp + ${OCLTST_DIR}/env/ocltst.cpp + ${OCLTST_DIR}/env/pfm.cpp + ${OCLTST_DIR}/env/Timer.cpp + ${OCLTST_DIR}/module/common/BaseTestImp.cpp + ${OCLTST_DIR}/module/common/OCLTestImp.cpp + ${OCLTST_DIR}/module/common/OCLThread.cpp + ${OCLTST_DIR}/module/common/OCLWrapper.cpp) + +# Windows compatibilty logic +if (WIN32) + target_sources(ocltst PRIVATE + ${OCLTST_DIR}/env/getopt.cpp + ${OCLTST_DIR}/env/ServiceCode.cpp + ${OCLTST_DIR}/env/window.cpp) +endif() + + +set_target_properties(ocltst PROPERTIES + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests/ocltst) + +target_compile_definitions(ocltst + PRIVATE + $) + +target_include_directories(ocltst + PRIVATE + $) + +target_link_libraries(ocltst + PRIVATE + OpenCL + ) + +set_target_properties(ocltst PROPERTIES INSTALL_RPATH "$ORIGIN") + +INSTALL(TARGETS ocltst DESTINATION ${OCLTST_INSTALL_DIR} COMPONENT ocltst) + diff --git a/opencl/tests/ocltst/env/Module.h b/opencl/tests/ocltst/env/Module.h new file mode 100644 index 0000000000..85853eee40 --- /dev/null +++ b/opencl/tests/ocltst/env/Module.h @@ -0,0 +1,54 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef OCL_TEST_MODULE_H +#define OCL_TEST_MODULE_H + +#include + +#include "OCLTest.h" +#include "OCLTestList.h" + +struct Module { + std::string name; + ModuleHandle hmodule; + TestCountFuncPtr get_count; + TestNameFuncPtr get_name; + CreateTestFuncPtr create_test; + DestroyTestFuncPtr destroy_test; + TestVersionFuncPtr get_version; + TestLibNameFuncPtr get_libname; + OCLTest** cached_test; + + Module() + : name(""), + hmodule(0), + get_count(0), + get_name(0), + create_test(0), + destroy_test(0), + get_version(0), + get_libname(0), + cached_test(0) { + // EMPTY! + } +}; + +#endif // OCL_TEST_MODULE_H diff --git a/opencl/tests/ocltst/env/ResultStruct.h b/opencl/tests/ocltst/env/ResultStruct.h new file mode 100644 index 0000000000..03671cf9ae --- /dev/null +++ b/opencl/tests/ocltst/env/ResultStruct.h @@ -0,0 +1,71 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _RESULT_STRUCT_H_ + +struct IndicesRange { + int startIndex; + int endIndex; +}; + +#define INDEX_ALL_TESTS -1 +#define EXTREMELY_SMALL_VALUE -10000.0f +#define EXTREMELY_LARGE_VALUE 10000.0f + +class TestResult { + public: + float value; + std::string resultString; + bool passed; + + TestResult(float val) : resultString("\n"), passed(true) { value = val; } + + void reset(float val) { + value = val; + passed = true; + resultString.assign("\n"); + } +}; + +class Report { + public: + TestResult *max; + TestResult *min; + bool success; + int numFailedTests; + + Report() : success(true), numFailedTests(0) { + max = new TestResult(EXTREMELY_SMALL_VALUE); + min = new TestResult(EXTREMELY_LARGE_VALUE); + } + + void reset() { + max->reset(EXTREMELY_SMALL_VALUE); + min->reset(EXTREMELY_LARGE_VALUE); + success = true; + numFailedTests = 0; + } + ~Report() { + delete max; + delete min; + } +}; + +#endif // _RESULT_STRUCT_H_ diff --git a/opencl/tests/ocltst/env/ServiceCode.cpp b/opencl/tests/ocltst/env/ServiceCode.cpp new file mode 100644 index 0000000000..f83137819c --- /dev/null +++ b/opencl/tests/ocltst/env/ServiceCode.cpp @@ -0,0 +1,330 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include +#define CL_USE_DEPRECATED_OPENCL_2_0_APIS 1 +#include "CL/cl.hpp" + +SERVICE_STATUS serviceStatus = {0}; +SERVICE_STATUS_HANDLE serviceStatusHandle = 0; + +const wchar_t* CrossProcessEventName = L"Global\\OpenCL_Test_serviceEvent"; +const wchar_t* successMessage = L"OpenCL Service Test Success\n"; +const wchar_t* serviceName = L"OpenCL Test service"; +// this event is set whenever the service thread is finished executing +// all it's tasks +HANDLE RetireServiceEvent = 0; + +DWORD WINAPI ThreadProc(LPVOID lpdwThreadParam); + +////////////////////////// +// log relate functions // +////////////////////////// +void getLogFileName(wchar_t fileName[MAX_PATH]) { + DWORD dwSize = GetModuleFileNameW(NULL, fileName, MAX_PATH); + wchar_t* p = fileName + dwSize; + while (*p != '\\' && p > fileName) p--; + p++; + wcscpy(p, L"result.txt"); +} + +VOID WriteLog(const wchar_t* pMsg) { + static wchar_t fileName[MAX_PATH] = {0}; + if (fileName[0] == 0) getLogFileName(fileName); + + FILE* pLog = _wfopen(fileName, L"w"); + if (NULL != pLog) { + fwprintf(pLog, pMsg); + fclose(pLog); + } +} + +VOID AppendLog(const wchar_t* pMsg) { + static wchar_t fileName[MAX_PATH] = {0}; + if (fileName[0] == 0) getLogFileName(fileName); + FILE* pLog = _wfopen(fileName, L"a"); + if (NULL != pLog) { + fwprintf(pLog, pMsg); + fclose(pLog); + } +} + +VOID AppendLog(const char* pMsg) { + static wchar_t fileName[MAX_PATH] = {0}; + if (fileName[0] == 0) getLogFileName(fileName); + FILE* pLog = _wfopen(fileName, L"a"); + if (NULL != pLog) { + fprintf(pLog, pMsg); + fclose(pLog); + } +} +/////////////////////////////// +// service related functions // +/////////////////////////////// +void WINAPI ServiceControlHandler(DWORD controlCode) { + switch (controlCode) { + case SERVICE_CONTROL_INTERROGATE: + break; + + case SERVICE_CONTROL_SHUTDOWN: + case SERVICE_CONTROL_STOP: + serviceStatus.dwCurrentState = SERVICE_STOP_PENDING; + if (!SetServiceStatus(serviceStatusHandle, &serviceStatus)) + AppendLog(L"SetServiceStatus SERVICE_STOP_PENDING failed\n"); + + if (RetireServiceEvent) SetEvent(RetireServiceEvent); + return; + + case SERVICE_CONTROL_PAUSE: + break; + + case SERVICE_CONTROL_CONTINUE: + break; + + default: + if (controlCode >= 128 && controlCode <= 255) + // user defined control code + break; + else + // unrecognised control code + break; + } + + if (!SetServiceStatus(serviceStatusHandle, &serviceStatus)) + AppendLog(L"SetServiceStatus SERVICE_STOP_PENDING failed\n"); +} + +void WINAPI ServiceMain(DWORD /*argc*/, wchar_t* /*argv*/[]) { + // initialise service status + serviceStatus.dwServiceType = SERVICE_WIN32; + serviceStatus.dwCurrentState = SERVICE_START_PENDING; + serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_SHUTDOWN; + serviceStatus.dwWin32ExitCode = NO_ERROR; + serviceStatus.dwServiceSpecificExitCode = NO_ERROR; + serviceStatus.dwCheckPoint = 0; + serviceStatus.dwWaitHint = 0; + + serviceStatusHandle = + RegisterServiceCtrlHandlerW(serviceName, ServiceControlHandler); + + if (serviceStatusHandle) { + // service is starting + serviceStatus.dwCurrentState = SERVICE_START_PENDING; + if (!SetServiceStatus(serviceStatusHandle, &serviceStatus)) + AppendLog(L"SetServiceStatus SERVICE_START_PENDING failed\n"); + + // do initialisation here + RetireServiceEvent = CreateEvent(0, FALSE, FALSE, 0); + + // running + serviceStatus.dwControlsAccepted |= + (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN); + serviceStatus.dwCurrentState = SERVICE_RUNNING; + if (!SetServiceStatus(serviceStatusHandle, &serviceStatus)) + AppendLog(L"SetServiceStatus SERVICE_RUNNING failed\n"); + + // Create the thread that actually does the CL testing + CreateThread(NULL, 0, ThreadProc, NULL, 0, NULL); + // wait for the thread to finish + WaitForSingleObject(RetireServiceEvent, 60000); + + HANDLE crossProcessEvent = + OpenEventW(EVENT_ALL_ACCESS, FALSE, CrossProcessEventName); + if (NULL != crossProcessEvent) { + SetEvent(crossProcessEvent); + } else { + AppendLog(L"cross process Event could not be openned\n"); + } + + // service was stopped + serviceStatus.dwCurrentState = SERVICE_STOP_PENDING; + if (!SetServiceStatus(serviceStatusHandle, &serviceStatus)) + AppendLog(L"SetServiceStatus SERVICE_STOP_PENDING failed\n"); + + // do cleanup here + CloseHandle(crossProcessEvent); + CloseHandle(RetireServiceEvent); + RetireServiceEvent = 0; + + // service is now stopped + serviceStatus.dwControlsAccepted &= + ~(SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN); + serviceStatus.dwCurrentState = SERVICE_STOPPED; + if (!SetServiceStatus(serviceStatusHandle, &serviceStatus)) + AppendLog(L"SetServiceStatus SERVICE_STOPPED failed\n"); + } +} + +// This function services ocltst as a service when launched +// by the OS. It registers the service routines. +void serviceStubCall() { + wchar_t serviceName[MAX_PATH]; + wcscpy(serviceName, ::serviceName); + SERVICE_TABLE_ENTRYW serviceTable[] = {{serviceName, ServiceMain}, {0, 0}}; + DWORD session_id; + BOOL retVal = ProcessIdToSessionId(GetCurrentProcessId(), &session_id); + if (0 == session_id) { + StartServiceCtrlDispatcherW(serviceTable); + } +} +///////////////////// +// CL related code // +///////////////////// +const char c_kernelCode[] = + " __kernel void hello(__global char * theArray)" + "{" + " size_t i = get_global_id(0);" + "if ( i < get_global_size(0))" + "theArray[i] = 78;" + "}"; + +const unsigned int c_bufferSize = 1024; + +DWORD WINAPI ThreadProc(LPVOID lpdwThreadParam) { + cl_int err; + // Platform info + std::vector platforms; + + err = cl::Platform::get(&platforms); + if (err != CL_SUCCESS) { + AppendLog(L"Platform::get() failed\n"); + return -1; + } + + std::vector::iterator i; + if (platforms.size() > 0) { + for (i = platforms.begin(); i != platforms.end(); ++i) { + if (!strcmp((*i).getInfo(&err).c_str(), + "Advanced Micro Devices, Inc.")) { + break; + } + } + } + if (err != CL_SUCCESS) { + AppendLog(L"Platform::getInfo() failed \n"); + return -1; + } + + cl_context_properties cps[3] = {CL_CONTEXT_PLATFORM, + (cl_context_properties)(*i)(), 0}; + + cl::Context context(CL_DEVICE_TYPE_GPU, cps, NULL, NULL, &err); + if (err != CL_SUCCESS) { + AppendLog(L"Context::Context() failed \n"); + return -1; + } + + std::vector devices = context.getInfo(); + if (err != CL_SUCCESS) { + AppendLog(L"Context::getInfo() failed \n"); + return -1; + } + if (devices.size() == 0) { + AppendLog(L"No device available\n"); + return -1; + } + + cl::Program::Sources sources( + 1, std::make_pair(c_kernelCode, sizeof(c_kernelCode))); + + cl::Program program = cl::Program(context, sources, &err); + if (err != CL_SUCCESS) { + AppendLog(L"Program::Program() failed\n"); + } + + err = program.build(devices); + if (err != CL_SUCCESS) { + if (err == CL_BUILD_PROGRAM_FAILURE) { + std::string str( + (char*)program.getBuildInfo(devices[0]) + .c_str()); + + AppendLog(L" \n\t\t\tBUILD LOG\n\n"); + AppendLog(L" ************************************************\n"); + AppendLog(str.c_str()); + AppendLog(L" ************************************************\n"); + } + + AppendLog(L"Program::build() failed\n"); + return -1; + } + + cl::Kernel kernel(program, "hello", &err); + if (err != CL_SUCCESS) { + AppendLog(L"Kernel::Kernel() failed\n"); + return -1; + } + + cl::Buffer buffer = + cl::Buffer(context, CL_MEM_READ_WRITE, c_bufferSize, 0, &err); + if (err != CL_SUCCESS) { + AppendLog(L"Kernel::setArg() failed \n"); + } + + cl::CommandQueue queue(context, devices[0], 0, &err); + if (err != CL_SUCCESS) { + AppendLog(L"CommandQueue::CommandQueue() failed \n"); + return -1; + } + + err = kernel.setArg(0, buffer); + if (err != CL_SUCCESS) { + AppendLog(L"Kernel::setArg() failed \n"); + return -1; + } + + err = queue.enqueueNDRangeKernel(kernel, cl::NullRange, + cl::NDRange(c_bufferSize), cl::NullRange); + + if (err != CL_SUCCESS) { + AppendLog(L"CommandQueue::enqueueNDRangeKernel()\n"); + return -1; + } + + err = queue.finish(); + if (err != CL_SUCCESS) { + AppendLog(L"Event::wait() failed \n"); + } + char* ptr = (char*)malloc(c_bufferSize); + err = queue.enqueueReadBuffer(buffer, CL_TRUE, 0, c_bufferSize, ptr, NULL, + NULL); + if (err != CL_SUCCESS) { + AppendLog(L"CommandQueue::enqueueReadBuffer()\n"); + return -1; + } + + bool validateSuccess = true; + // validate the results + for (int i = 0; i < c_bufferSize; i++) { + if (ptr[i] != 78) validateSuccess = false; + } + + free(ptr); + if (validateSuccess) { + WriteLog(successMessage); + AppendLog(L"validate success"); + } else { + AppendLog(L"Validate fail"); + return -1; + } + + SetEvent(RetireServiceEvent); + return 0; +} diff --git a/opencl/tests/ocltst/env/Timer.cpp b/opencl/tests/ocltst/env/Timer.cpp new file mode 100644 index 0000000000..2bda27f8f6 --- /dev/null +++ b/opencl/tests/ocltst/env/Timer.cpp @@ -0,0 +1,111 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "Timer.h" + +#ifdef _WIN32 +#include +#endif + +#ifdef __linux__ +#include +#endif + +CPerfCounter::CPerfCounter() : _clocks(0), _start(0) { +#ifdef _WIN32 + + QueryPerformanceFrequency((LARGE_INTEGER *)&_freq); + +#endif + +#ifdef __linux__ + _freq = 1000; +#endif +} + +CPerfCounter::~CPerfCounter() { + // EMPTY! +} + +void CPerfCounter::Start(void) { +#ifdef _WIN32 + + if (_start) { + MessageBox(NULL, "Bad Perf Counter Start", "Error", MB_OK); + exit(0); + } + QueryPerformanceCounter((LARGE_INTEGER *)&_start); + +#endif +#ifdef __linux__ + + struct timeval s; + gettimeofday(&s, 0); + _start = (i64)s.tv_sec * 1000 + (i64)s.tv_usec / 1000; + +#endif +} + +void CPerfCounter::Stop(void) { + i64 n; + +#ifdef _WIN32 + + if (!_start) { + MessageBox(NULL, "Bad Perf Counter Stop", "Error", MB_OK); + exit(0); + } + + QueryPerformanceCounter((LARGE_INTEGER *)&n); + +#endif +#ifdef __linux__ + + struct timeval s; + gettimeofday(&s, 0); + n = (i64)s.tv_sec * 1000 + (i64)s.tv_usec / 1000; + +#endif + + n -= _start; + _start = 0; + _clocks += n; +} + +void CPerfCounter::Reset(void) { +#ifdef _WIN32 + if (_start) { + MessageBox(NULL, "Bad Perf Counter Reset", "Error", MB_OK); + exit(0); + } +#endif + _clocks = 0; +} + +double CPerfCounter::GetElapsedTime(void) { +#ifdef _WIN32 + if (_start) { + MessageBox(NULL, "Trying to get time while still running.", "Error", MB_OK); + exit(0); + } +#endif + + return (double)_clocks / (double)_freq; +} diff --git a/opencl/tests/ocltst/env/Timer.h b/opencl/tests/ocltst/env/Timer.h new file mode 100644 index 0000000000..e5d331ccff --- /dev/null +++ b/opencl/tests/ocltst/env/Timer.h @@ -0,0 +1,46 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _TIMER_H_ +#define _TIMER_H_ + +#ifdef _WIN32 +typedef __int64 i64; +#endif +#ifdef __linux__ +typedef long long i64; +#endif + +class CPerfCounter { + public: + CPerfCounter(); + ~CPerfCounter(); + void Start(void); + void Stop(void); + void Reset(void); + double GetElapsedTime(void); + + private: + i64 _freq; + i64 _clocks; + i64 _start; +}; + +#endif // _TIMER_H_ diff --git a/opencl/tests/ocltst/env/Worker.h b/opencl/tests/ocltst/env/Worker.h new file mode 100644 index 0000000000..e5cc66d653 --- /dev/null +++ b/opencl/tests/ocltst/env/Worker.h @@ -0,0 +1,180 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef OCL_TEST_WORKER_H +#define OCL_TEST_WORKER_H + +///////////////////////////////////////////////////////////////////////////// + +#include +#include + +#include +#include +#include +#include + +#include "Module.h" +#include "OCLTest.h" +#include "OCLTestList.h" +#include "ResultStruct.h" +#include "Timer.h" +#include "getopt.h" +#include "pfm.h" + +///////////////////////////////////////////////////////////////////////////// + +typedef void* (*TestMethod)(void* param); + +///////////////////////////////////////////////////////////////////////////// + +class Worker { + public: + Worker() + : m_wrapper(0), + m_module(0), + m_run(0), + m_id(0), + m_subtest(0), + m_testindex(0), + m_dump(false), + m_display(false), + m_useCPU(false), + m_window(0), + m_width(0), + m_height(0), + m_buffer(0), + m_perflab(false), + m_deviceId(0), + m_platform(0) { + // EMPTY! + } + + Worker(OCLWrapper* wrapper, Module* module, TestMethod run, unsigned int id, + unsigned int subtest, unsigned int testindex, bool dump, bool view, + bool useCPU, void* window, unsigned int x, unsigned int y, + bool perflab, unsigned int deviceId = 0, unsigned int platform = 0) + : m_wrapper(wrapper), + m_module(module), + m_run(run), + m_id(id), + m_subtest(subtest), + m_testindex(testindex), + m_dump(dump), + m_display(view), + m_useCPU(useCPU), + m_window(window), + m_width(x), + m_height(y), + m_buffer(0), + m_perflab(perflab), + m_deviceId(deviceId), + m_platform(platform) { + if (m_dump == true || m_display == true) { + m_buffer = new float[4 * m_width * m_height]; + if (m_buffer != 0) { + memset(m_buffer, 0, 4 * m_width * m_height * sizeof(float)); + } else { + m_dump = false; + m_display = false; + } + } + m_result = new TestResult(0.0f); + } + + Worker(const Worker& w) { + if (this == &w) return; + + if (m_buffer) delete[] m_buffer; + m_buffer = 0; + + m_wrapper = w.m_wrapper; + m_module = w.m_module; + m_run = w.m_run; + m_id = w.m_id; + m_subtest = w.m_subtest; + m_testindex = w.m_testindex; + m_dump = w.m_dump; + m_display = w.m_display; + m_useCPU = w.m_useCPU; + m_window = w.m_window; + m_width = w.m_width; + m_height = w.m_height; + m_perflab = w.m_perflab; + m_deviceId = w.m_deviceId; + m_result = w.m_result; + m_platform = w.m_platform; + + if (w.m_buffer) { + m_buffer = new float[4 * m_width * m_height]; + if (m_buffer != 0) { + memcpy(m_buffer, w.m_buffer, 4 * m_width * m_height * sizeof(float)); + } + } + } + + ~Worker() { + if (m_buffer) delete[] m_buffer; + m_buffer = 0; + delete m_result; + m_result = 0; + } + + OCLWrapper* getOCLWrapper() { return m_wrapper; } + Module* getModule() { return m_module; } + TestMethod getTestMethod() { return m_run; } + unsigned int getId() { return m_id; } + unsigned int getSubTest() { return m_subtest; } + unsigned int getTestIndex() { return m_testindex; } + bool isDumpEnabled() { return m_dump; } + bool isDisplayEnabled() { return m_display; } + bool isCPUEnabled() { return m_useCPU; } + void* getWindow() { return m_window; } + unsigned int getWidth() { return m_width; } + unsigned int getHeight() { return m_height; } + float* getBuffer() { return m_buffer; } + bool getPerflab() { return m_perflab; } + unsigned int getDeviceId() { return m_deviceId; } + TestResult* getResult() { return m_result; } + unsigned int getPlatformID() { return m_platform; } + + private: + OCLWrapper* m_wrapper; + Module* m_module; + TestMethod m_run; + unsigned int m_id; + unsigned int m_subtest; + unsigned int m_testindex; + bool m_dump; + bool m_display; + bool m_useCPU; + void* m_window; + unsigned int m_width; + unsigned int m_height; + float* m_buffer; + bool m_perflab; + unsigned int m_deviceId; + unsigned int m_platform; + TestResult* m_result; +}; + +///////////////////////////////////////////////////////////////////////////// + +#endif // OCL_TEST_WORKER_H diff --git a/opencl/tests/ocltst/env/getopt.cpp b/opencl/tests/ocltst/env/getopt.cpp new file mode 100644 index 0000000000..72ff9c8adb --- /dev/null +++ b/opencl/tests/ocltst/env/getopt.cpp @@ -0,0 +1,49 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "getopt.h" + +#include + +char *optarg = nullptr; +int optind = 1; + +int getopt(int argc, char *const argv[], const char *optstring) { + if ((optind >= argc) || (argv[optind][0] != '-') || (argv[optind][0] == 0)) { + return -1; + } + + int opt = argv[optind][1]; + const char *p = strchr(optstring, opt); + + if (p == nullptr) { + return '?'; + } + if (p[1] == ':') { + optind++; + if (optind >= argc) { + return '?'; + } + optarg = argv[optind]; + } + + optind++; + return opt; +} diff --git a/opencl/tests/ocltst/env/getopt.h b/opencl/tests/ocltst/env/getopt.h new file mode 100644 index 0000000000..18ef649b60 --- /dev/null +++ b/opencl/tests/ocltst/env/getopt.h @@ -0,0 +1,26 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#pragma once + +extern char *optarg; +extern int optind; + +extern "C" int getopt(int argc, char *const argv[], const char *optstring); diff --git a/opencl/tests/ocltst/env/oclTestLog.cpp b/opencl/tests/ocltst/env/oclTestLog.cpp new file mode 100644 index 0000000000..232b04d741 --- /dev/null +++ b/opencl/tests/ocltst/env/oclTestLog.cpp @@ -0,0 +1,104 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "oclTestLog.h" + +#include +#include + +#include "OCLLog.h" + +oclLog::oclLog() + : m_stdout_fp(stdout), m_filename(""), m_writeToFileIsEnabled(false) {} + +oclLog::~oclLog() { disable_write_to_file(); } + +void oclLog::enable_write_to_file(std::string filename) { + m_writeToFileIsEnabled = true; + m_filename = filename; + FILE* fp = fopen(m_filename.c_str(), "w"); + if (fp == NULL) { + oclTestLog(OCLTEST_LOG_ALWAYS, + "ERROR: Cannot open file %s. Disabling logging to file.\n", + filename.c_str()); + m_writeToFileIsEnabled = false; + } else { + fclose(fp); + } +} + +void oclLog::disable_write_to_file() { m_writeToFileIsEnabled = false; } + +void oclLog::vprint(char const* fmt, va_list args) { + // hack for fixing the lnx64bit segfault and + // garbage printing in file. XXX 2048 a magic number + char buffer[4096]; + + memset(buffer, 0, sizeof(buffer)); + int rc = vsnprintf(buffer, sizeof(buffer), fmt, args); + assert(rc >= 0 && rc != sizeof(buffer)); + + fputs(buffer, m_stdout_fp); + if (m_writeToFileIsEnabled) { + FILE* fp = fopen(m_filename.c_str(), "a"); + if (fp == NULL) { + oclTestLog(OCLTEST_LOG_ALWAYS, + "ERROR: Cannot open file %s. Disabling logging to file.\n", + m_filename.c_str()); + m_writeToFileIsEnabled = false; + } + fputs(buffer, fp); + fclose(fp); + } +} + +void oclLog::flush() { fflush(m_stdout_fp); } + +static oclLog& theLog() { + static oclLog Log; + return Log; +} + +static oclLoggingLevel currentLevel = OCLTEST_LOG_ALWAYS; +static float logcount = 0.0f; + +void oclTestLog(oclLoggingLevel logLevel, const char* fmt, ...) { + logcount += 1.0f; + + if (logLevel <= currentLevel) { + va_list args; + va_start(args, fmt); + + theLog().vprint(fmt, args); + theLog().flush(); + + va_end(args); + } +} + +void oclTestEnableLogToFile(const char* filename) { + theLog().enable_write_to_file(filename); +} + +void oclTestSetLogLevel(int level) { + if (level >= 0) { + currentLevel = static_cast(level); + } +} diff --git a/opencl/tests/ocltst/env/oclTestLog.h b/opencl/tests/ocltst/env/oclTestLog.h new file mode 100644 index 0000000000..bbdb8b6b73 --- /dev/null +++ b/opencl/tests/ocltst/env/oclTestLog.h @@ -0,0 +1,44 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef CALTESTLOG_H_ +#define CALTESTLOG_H_ + +#include +#include + +#include + +class oclLog { + public: + oclLog(); + virtual ~oclLog(); + virtual void vprint(char const* fmt, va_list args); + virtual void flush(); + virtual void enable_write_to_file(std::string filename); + virtual void disable_write_to_file(); + + private: + FILE* m_stdout_fp; + std::string m_filename; + bool m_writeToFileIsEnabled; +}; + +#endif // CALTESTLOG_H_ diff --git a/opencl/tests/ocltst/env/oclsysinfo.cpp b/opencl/tests/ocltst/env/oclsysinfo.cpp new file mode 100644 index 0000000000..a0ca56bc82 --- /dev/null +++ b/opencl/tests/ocltst/env/oclsysinfo.cpp @@ -0,0 +1,162 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "oclsysinfo.h" + +#include +#include + +#include + +#ifndef MAX_DEVICES +#define MAX_DEVICES 16 +#endif // MAX_DEVICES + +int oclSysInfo(std::string &info_string, bool use_cpu, unsigned dev_id, + unsigned int platformIndex) { + /* + * Have a look at the available platforms and pick the one + * in the platforms vector in index "platformIndex". + */ + + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + + int error = clGetPlatformIDs(0, NULL, &numPlatforms); + if (CL_SUCCESS != error) { + fprintf(stderr, "clGetPlatformIDs() failed"); + return 0; + } + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error = clGetPlatformIDs(numPlatforms, platforms, NULL); + if (CL_SUCCESS != error) { + fprintf(stderr, "clGetPlatformIDs() failed"); + return 0; + } +#if 0 + for (unsigned i = 0; i < numPlatforms; ++i) { + /* Get the number of requested devices */ + error = clGetDeviceIDs(platforms[i], (use_cpu) ? CL_DEVICE_TYPE_CPU : CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices ); +#if 0 + /* clGetDeviceIDs fails when no GPU devices are present */ + if (error) { + fprintf(stderr, "clGetDeviceIDs failed: %d\n", error ); + return 0; + } +#endif +#if 0 + char pbuf[100]; + + error = clGetPlatformInfo( + platforms[i], + CL_PLATFORM_VENDOR, + sizeof(pbuf), + pbuf, + NULL); + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + platform = platforms[i]; + break; + } +#else + /* Select platform with GPU devices present */ + if (num_devices > 0) { + platform = platforms[i]; + break; + } +#endif + } +#endif + error = clGetDeviceIDs(platforms[platformIndex], + (use_cpu) ? CL_DEVICE_TYPE_CPU : CL_DEVICE_TYPE_GPU, + 0, NULL, &num_devices); + if (error) { + fprintf(stderr, "clGetDeviceIDs failed: %d\n", error); + return 0; + } + platform = platforms[platformIndex]; + delete[] platforms; + } + if (dev_id >= num_devices) { + fprintf(stderr, "Device selected does not exist.\n"); + return 0; + } + if (NULL == platform) { + fprintf(stderr, + "Couldn't find platform with GPU devices, cannot proceed.\n"); + return 0; + } + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + if (!devices) { + fprintf(stderr, "no devices\n"); + return 0; + } + + /* Get the requested device */ + error = clGetDeviceIDs(platform, + (use_cpu) ? CL_DEVICE_TYPE_CPU : CL_DEVICE_TYPE_GPU, + num_devices, devices, NULL); + if (error) { + fprintf(stderr, "clGetDeviceIDs failed: %d\n", error); + return 0; + } + + device = devices[dev_id]; + + char c[1024]; + char tmpString[256]; + static const char *no_yes[] = {"NO", "YES"}; + sprintf(tmpString, "\nCompute Device info:\n"); + info_string.append(tmpString); + clGetPlatformInfo(platform, CL_PLATFORM_VERSION, sizeof(c), &c, NULL); + sprintf(tmpString, "\tPlatform Version: %s\n", c); + info_string.append(tmpString); + clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(c), &c, NULL); + sprintf(tmpString, "\tDevice Name: %s\n", c); + info_string.append(tmpString); + clGetDeviceInfo(device, CL_DEVICE_VENDOR, sizeof(c), &c, NULL); + sprintf(tmpString, "\tVendor: %s\n", c); + info_string.append(tmpString); + clGetDeviceInfo(device, CL_DEVICE_VERSION, sizeof(c), &c, NULL); + sprintf(tmpString, "\tDevice Version: %s\n", c); + info_string.append(tmpString); + clGetDeviceInfo(device, CL_DRIVER_VERSION, sizeof(c), &c, NULL); + sprintf(tmpString, "\tDriver Version: %s\n", c); + info_string.append(tmpString); + clGetDeviceInfo(device, CL_DEVICE_BOARD_NAME_AMD, sizeof(c), &c, NULL); + sprintf(tmpString, "\tBoard Name: %s\n", c); + info_string.append(tmpString); +#if defined(__linux__) + cl_device_topology_amd topology; + clGetDeviceInfo(device, CL_DEVICE_TOPOLOGY_AMD, sizeof(topology), &topology, + NULL); + if (topology.raw.type == CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD) { + sprintf(tmpString, "\tDevice Topology: PCI[ B#%d, D#%d, F#%d]\n", + topology.pcie.bus, topology.pcie.device, topology.pcie.function); + info_string.append(tmpString); + } +#endif + free(devices); + return 1; +} diff --git a/opencl/tests/ocltst/env/oclsysinfo.h b/opencl/tests/ocltst/env/oclsysinfo.h new file mode 100644 index 0000000000..6a540aaa11 --- /dev/null +++ b/opencl/tests/ocltst/env/oclsysinfo.h @@ -0,0 +1,28 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCLSYSINFO_H_ +#define _OCLSYSINFO_H_ +#include + +int oclSysInfo(std::string& info_string, bool useCPU, unsigned dev_id, + unsigned int platformIndex = 0); + +#endif //_OCLSYSINFO_H_ diff --git a/opencl/tests/ocltst/env/ocltst.cpp b/opencl/tests/ocltst/env/ocltst.cpp new file mode 100644 index 0000000000..84d8cdf3cd --- /dev/null +++ b/opencl/tests/ocltst/env/ocltst.cpp @@ -0,0 +1,1622 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +///////////////////////////////////////////////////////////////////////////// + +#include + +#ifdef _WIN32 +#include + +#include "Window.h" +typedef HMODULE ModuleHandle; +#endif + +///////////////////////////////////////////////////////////////////////////// + +#ifdef __linux__ +#include +typedef void* ModuleHandle; +#endif + +///////////////////////////////////////////////////////////////////////////// + +#include "BaseTestImp.h" +#include "Module.h" +#include "OCLLog.h" +#include "OCLTest.h" +#include "OCLTestImp.h" +#include "OCLTestList.h" +#include "OCLWrapper.h" +#include "Timer.h" +#include "Worker.h" +#include "getopt.h" +#include "oclsysinfo.h" +#include "pfm.h" + +//! Including OCLutilities Thread utility +#include "OCL/Thread.h" + +//! Lock that needs to be obtained to access the global +//! module variable +static OCLutil::Lock moduleLock; + +#include +#include + +#include +#include +#include +#include + +///////////////////////////////////////////////////////////////////////////// + +#ifdef _WIN32 +static LONG WINAPI xFilter(LPEXCEPTION_POINTERS xEP); +void serviceStubCall(); +#endif + +#define MAX_DEVICES 16 +#undef CHECK_RESULT +#define CHECK_RESULT(test, msg) \ + if ((test)) { \ + printf("\n%s\n", msg); \ + exit(1); \ + } + +//! Declaration of a function that find devices of a specific type for the +//! chosen platform +int findAdapters(unsigned int platformIdx, bool useCPU, cl_platform_id*); + +//! class App that is used to run the tests on the system +class App { + public: + static bool m_reRunFailed; + static const char* m_svcMsg; + //! Constructor for App + App(unsigned int platform) + : m_list(false), + m_console(true), + m_useCPU(false), + m_dump(false), + m_perflab(false), + m_noSysInfoPrint(false), + m_numItr(1), + mp_testOrder(NULL), + m_rndOrder(false), + m_spawned(0), + m_threads(1), + m_runthread(0), + m_width(512), + m_height(512), + m_window(0), + m_platform(platform) { + // initialize OCLWrapper reference + m_wrapper = new OCLWrapper(); + + // m_workers = Set of worker objects that are used to run a subtest from a + // module + for (unsigned int i = 0; i < 256; i++) m_workers[i] = 0; + + // Setting the number of devices + /* + * Force caltst to use 1 thread at a time in Windows + * only contextual calls are thread safe currently + */ + m_numDevices = findAdapters(m_platform, m_useCPU, NULL); + // m_numDevices = 1; + + // Report structure used to store the results of the tests +#if 0 + testReport = (Report **)malloc(sizeof(Report *) * m_numDevices); + for(unsigned int i = 0; i < m_numDevices; i++) + { + testReport[i] = new Report; + } +#else + testReport = (Report**)malloc(sizeof(Report*)); + testReport[0] = new Report; +#endif + } + + //! Destructor for App + ~App() { + // Deleting the Worker objects + for (unsigned int i = 0; i < 256; i++) { + if (m_workers[i]) { + delete m_workers[i]; + m_workers[i] = 0; + } + } + + // Deleting the report structures + // for(unsigned int i = 0; i < m_numDevices; i++) + for (unsigned int i = 0; i < 1; i++) { + delete testReport[i]; + } + free(testReport); + m_wrapper->clUnloadPlatformAMD(mpform_id); + + delete m_wrapper; + } + + //! Function used to create a worker object corresponding to a subtest in a + //! module + void SetWorker(unsigned int index, OCLWrapper* wrapper, Module* module, + TestMethod run, unsigned int id, unsigned int subtest, + unsigned int test, bool dump, bool view, bool useCPU, + void* window, unsigned int x, unsigned int y, bool perflab, + unsigned int deviceId, unsigned int platform) { + if (index >= 256) return; + + if (m_workers[index]) delete m_workers[index]; + + m_workers[index] = + new Worker(wrapper, module, run, id, subtest, test, dump, view, useCPU, + window, x, y, perflab, deviceId, platform); + + assert(m_workers[index] != 0); + // oclTestLog(OCLTEST_LOG_ALWAYS, "Worker Device Id = %d\n", + // m_workers[index]->getDeviceId()); + } + + //! Function to return the 'index'th m_workers + Worker* GetWorker(unsigned int index) { + if (index >= 256) return 0; + + return m_workers[index]; + } + + //! Create a thread to run the subtest + void AddThread(unsigned int workerindex, unsigned int usage) { + Worker* worker = GetWorker(workerindex); + if (worker == 0) { + return; + } + + // usage = Whether to use threads or not + if (usage != 0) { + // Creating a thread + // getTestMethod = runSubTest here + // which takes a Worker object as an argument + m_pool[workerindex].create(worker->getTestMethod(), (void*)(worker)); + m_spawned++; + } else { + // Same as above without using threads + TestMethod run = worker->getTestMethod(); + if (run) { + run(worker); + UpdateTestReport(workerindex, worker->getResult()); + } + } + return; + } + + //! Function which waits for all threads to execute and also updates the + //! report + void WaitAllThreads() { + for (unsigned int w = 0; w < m_spawned; w++) { + m_pool[w].join(); + UpdateTestReport(w, m_workers[w]->getResult()); + } + m_spawned = 0; + } + + //! Function to add a worker thread so as to run a subtest of a module + //! @param run = runSubtest function + //! @param index = index of the module in m_modules + //! @param subtest = the subtest number to run + //! @param usage = whether to use threads or not + //! @param test = The test in the module to be executed + void AddWorkerThread(unsigned int index, unsigned int subtest, + unsigned int test, unsigned int usage, TestMethod run) { + if (m_spawned > m_threads) { + WaitAllThreads(); + } + + // Creating a worker thread for each device +#if 0 + for(unsigned int i = 0; i < m_numDevices; i++) + { + SetWorker(i, + m_wrapper, + &m_modules[index], + run, + m_spawned, + subtest, + test, + m_dump, + !m_console, + m_useCPU, + m_window, + m_width, + m_height, + m_perflab, + i, + m_platform); + } +#else + for (unsigned int i = 0; i < 1; i++) { + SetWorker(i, m_wrapper, &m_modules[index], run, m_spawned, subtest, test, + m_dump, !m_console, m_useCPU, m_window, m_width, m_height, + m_perflab, m_deviceId, m_platform); + } +#endif + + // Creating and executing a thread for each device + // for(unsigned int i = 0; i < m_numDevices; i++) + for (unsigned int i = 0; i < 1; i++) { + AddThread(i, usage); + } + } + + void printOCLinfo(void); + + //! Function to process the commandline arguments + void CommandLine(unsigned int argc, char** argv); + + //! Function to scan for the different tests in the module + void ScanForTests(); + + //! Function to run all the specified tests + void RunAllTests(); + + //! Free memory + void CleanUp(); + + //! Function to set the order in which test are executed. + void SetTestRunOrder(int); + + //! Function to print the test order + void PrintTestOrder(int); + + //! Function to get the number of iterations. + int GetNumItr(void) { return m_numItr; } + + private: + typedef std::vector TestIndexList; + typedef std::vector StringList; + + void AddToList(StringList& strlist, const char* str); + void LoadList(StringList& strlist, const char* filename); + + bool TestInList(StringList& strlist, const char* testname); + + //! Array storing the report for each device + Report** testReport; + + //! Function to update the result of each device + void UpdateTestReport(int index, TestResult* result) { + if (result != NULL) { + if (result->passed) { + if (testReport[index]->max->value < result->value) { + testReport[index]->max->value = result->value; + testReport[index]->max->resultString = result->resultString; + } + if (testReport[index]->min->value > result->value) { + testReport[index]->min->value = result->value; + testReport[index]->min->resultString = result->resultString; + } + } else { + testReport[index]->numFailedTests++; + testReport[index]->success = false; + } + } else { + testReport[index]->numFailedTests++; + testReport[index]->success = false; + } + } + + //! Functions used to find the range of the tests to be run + void GetTestIndexList(TestIndexList& testIndices, StringList& testList, + const char* szModuleTestname, int maxIndex); + void PruneTestIndexList(TestIndexList& testIndices, + TestIndexList& avoidIndices, + TestIndexList& erasedIndices); + + StringList m_paths; + StringList m_tests; + StringList m_avoid; + std::vector m_modules; + bool m_list; + bool m_console; + bool m_useCPU; + bool m_dump; + bool m_perflab; + bool m_noSysInfoPrint; + int m_numItr; + int* mp_testOrder; + bool m_rndOrder; + + //! m_pool = Various threads created to execute tests on multiple devices + OCLutil::Thread m_pool[256]; + + Worker* m_workers[256]; + + //! Number of threads spawned + unsigned int m_spawned; + + //! Upper limit on the number of threads that can be spawned + unsigned int m_threads; + unsigned int m_runthread; + unsigned int m_width; + unsigned int m_height; + void* m_window; + + //! which index/platform id from the platforms vector returned by + //! cl::Platform::get we should run on + unsigned int m_platform; + cl_platform_id mpform_id; + + //! Number of devices on the system + unsigned int m_numDevices; + // + //! Device ID to use on the system + unsigned int m_deviceId; + + // OCLWrapper reference + OCLWrapper* m_wrapper; +}; + +void App::printOCLinfo(void) { + std::string calinfo; + if (!m_noSysInfoPrint) { + oclSysInfo(calinfo, m_useCPU, m_deviceId, m_platform); + oclTestLog(OCLTEST_LOG_ALWAYS, calinfo.c_str()); + } +} + +/*----------------------------------------------------- +Function to randomize the order in which tests are executed +-------------------------------------------------------*/ +#ifdef _WIN32 +#include +#endif +// void App::SetTestRunOrder(int test_count) +void App::SetTestRunOrder(int mod_index) { + assert(mp_testOrder != NULL); + unsigned int test_count = m_modules[mod_index].get_count(); + + StringList uniqueTests; + for (unsigned int i = 0; i < m_tests.size(); ++i) { + // see if the tests are being run using indices + size_t nFirstBracket = m_tests[i].find("["); + // set the test name + std::string szTestName = m_tests[i]; + + // order of execution is set based on base name so get the base name + if (nFirstBracket != std::string::npos) + szTestName = szTestName.substr(0, nFirstBracket); + + bool bTestExists = false; + for (unsigned int j = 0; j < uniqueTests.size(); ++j) { + if (strcmp(szTestName.c_str(), uniqueTests[j].c_str()) == 0) { + bTestExists = true; + break; + } + } + + if (!bTestExists) { + AddToList(uniqueTests, szTestName.c_str()); + } + } + + for (unsigned int i = 0; i < test_count && i < uniqueTests.size(); i++) { + for (unsigned int j = 0; j < test_count; j++) { + unsigned int index = i; + // add all the prev test indices + for (int k = 0; k < mod_index; k++) index += m_modules[k].get_count(); + + std::string szTestName = uniqueTests[index]; + + if (strcmp(szTestName.c_str(), m_modules[mod_index].get_name(j)) == 0) { + mp_testOrder[i] = j; + break; + } + } + } + + if (m_rndOrder) { + srand((unsigned int)time(NULL)); + for (unsigned int i = 0; i < test_count; i++) { + // find two random indices + int index1 = (int)((float)test_count * (rand() / (RAND_MAX + 1.0))); + int index2 = (int)((float)test_count * (rand() / (RAND_MAX + 1.0))); + // swap the data + int tmp = mp_testOrder[index1]; + mp_testOrder[index1] = mp_testOrder[index2]; + mp_testOrder[index2] = tmp; + } + } +} + +///////////////////////////////////////////////////////////////////////////// + +// Process device string. Returns true if there is a primary ATI Radeon device +// adapter, false otherwise +static bool procDevString(const char* devString) { + // Search for the string "Radeon" inside the device string + if (strstr(devString, "Radeon") || strstr(devString, "R600") || + strstr(devString, "RV630") || strstr(devString, "RV670") || + (strstr(devString, "Stream") && strstr(devString, "Processor"))) { + // Ignore if the device is a secondary device, i.e., not an adapter + if (strstr(devString, "Secondary")) { + return false; + } + } else { + return false; + } + + return true; +} + +//! +//! Function to find the total number of adapters on the system +//! +int findAdapters(unsigned int platformIdx, bool useCPU, + cl_platform_id* mpform) { + unsigned int numOfAdapters = 0; + cl_int error = 0; + cl_uint numPlatforms = 0; + + error = clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT((error != CL_SUCCESS), "clGetPlatformIDs failed"); + + CHECK_RESULT((platformIdx >= numPlatforms), "Invalid platform"); + + cl_platform_id* platforms = new cl_platform_id[numPlatforms]; + error = clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error != CL_SUCCESS, "clGetPlatformIDs failed"); + + cl_platform_id platform = 0; + + platform = platforms[platformIdx]; + + delete[] platforms; + + cl_device_type devType = CL_DEVICE_TYPE_GPU; + if (useCPU) devType = CL_DEVICE_TYPE_CPU; + error = clGetDeviceIDs(platform, devType, 0, 0, &numOfAdapters); + CHECK_RESULT((error != CL_SUCCESS), "clGetDeviceIDs failed"); + if (mpform) { + (*mpform) = platform; + } + + return (int)numOfAdapters; +} + +int calibrate(OCLTest* test) { + int n = 1; + +#if 0 + while (1) + { + double timer = run(test, n); + if (timer > 2.) + { + break; + } + n *= 2; + } +#endif + + return n; +} + +void* dummyThread(void* argv) { + unsigned int counter = 0; + while (counter < 1000000) counter++; + + return argv; +} + +//! Function used to run the test specified +//! It would look something like OCLPerfInputspeed[0] +double run(OCLTest* test, int passes) { + CPerfCounter counter; + + counter.Reset(); + counter.Start(); + int i; + for (i = 0; i < passes; i++) { + test->run(); + } + counter.Stop(); + double timer = counter.GetElapsedTime(); + counter.Reset(); + + return timer; +} + +//! Function to display the result after a test is finished +//! It also stores the result in a TestResult object +void report(Worker* w, const char* testname, int testnum, unsigned int crc, + const char* errorMsg, float timer, TestResult* tr, + const char* testDesc) { + unsigned int thread = w->getId(); + bool perflab = w->getPerflab(); + unsigned int deviceId = w->getDeviceId(); + + char tmpUnits[256]; + if (perflab) { + oclTestLog(OCLTEST_LOG_ALWAYS, "%10.3f\n", timer); + } else { + const char* passedOrFailed[] = {"FAILED", "PASSED"}; + + // char teststring[256]; + // sprintf(teststring, "%s[%d]", testname, testnum); + // sprintf(tmpUnits, "Device[%d]:\t%-32s:\t%s\n", deviceId, teststring, + // ((tr->passed) ? passedOrFailed[1] : passedOrFailed[0])); + // If crc is not 0 or errorMsg is not empty, print the full stats + if ((crc != 0) || (errorMsg && (errorMsg[0] != '\0'))) { + sprintf(tmpUnits, + "%s %s: %s[%d] T[%1d] [%3d], %10.3f %-20s (chksum 0x%08x)\n", + testDesc, ((tr->passed) ? passedOrFailed[1] : passedOrFailed[0]), + w->isCPUEnabled() ? "CPU" : "GPU", deviceId, thread, testnum, + timer, errorMsg, crc); + } else { + sprintf(tmpUnits, "%s %s: %s[%d] T[%1d] [%3d], %10.3f\n", testDesc, + ((tr->passed) ? passedOrFailed[1] : passedOrFailed[0]), + w->isCPUEnabled() ? "CPU" : "GPU", deviceId, thread, testnum, + timer); + } + + oclTestLog(OCLTEST_LOG_ALWAYS, tmpUnits); + + tr->value = timer; + tr->resultString.assign(tmpUnits); + + if (App::m_svcMsg && !tr->passed) { + char escaped[2 * sizeof(tmpUnits)]; + + char* ptr = escaped; + for (int i = 0; tmpUnits[i] != '\0'; ++i) { + switch (tmpUnits[i]) { + case '\n': + *ptr++ = '|'; + *ptr++ = 'n'; + break; + case '\r': + *ptr++ = '|'; + *ptr++ = 'r'; + break; + case '\'': + case '|': + case ']': + case '[': + *ptr++ = '|'; + default: + *ptr++ = tmpUnits[i]; + } + } + *ptr = '\0'; + + oclTestLog(OCLTEST_LOG_ALWAYS, + "##%s[testFailed name='%s.%s.%d' message='FAILED' " + "details='%s']\n", App::m_svcMsg, + w->getModule()->get_libname(), testname, testnum, escaped); + } + } +} + +//! Thread Entry point +void* runSubtest(void* worker) { + char units[256]; + double conversion; + unsigned int crc = 0; + bool second_run = false; + + // Getting the worker object that is running in this thread + Worker* w = (Worker*)worker; + + if (w == 0) return NULL; + + unsigned int test = w->getTestIndex(); + unsigned int subtest = w->getSubTest(); + unsigned int deviceId = w->getDeviceId(); + unsigned int platformIndex = w->getPlatformID(); + TestResult* result = w->getResult(); + +RERUN_TEST: + // Acquiring lock on the 'module' object common to all threads + moduleLock.lock(); + Module* m = w->getModule(); + if (m == 0 || m->create_test == 0) return NULL; + // If we can, used the cached version, + // otherwise create the test. + OCLTest* pt = (m->cached_test ? m->cached_test[subtest] : NULL); + if (!pt) { + pt = m->create_test(subtest); + if (pt->cache_test() && m->cached_test) { + m->cached_test[subtest] = pt; + } + } + pt->clearError(); + OCLTestImp* tmp = pt->toOCLTestImp(); + if (tmp) { + tmp->setOCLWrapper(w->getOCLWrapper()); + } + std::string subtestName = m->get_name(subtest); + moduleLock.unlock(); + + if (pt == 0) return NULL; + + pt->resetDescString(); + if (App::m_svcMsg) { + oclTestLog(OCLTEST_LOG_ALWAYS, + "##%s[testStarted name='%s.%s.%d' " + "captureStandardOutput='true']\n", App::m_svcMsg, + m->get_libname(), subtestName.c_str(), test); + } + // setting the type to CPU. + if (w->isCPUEnabled()) { + pt->useCPU(); + } + // Setting the device according to the worker thread + pt->setDeviceId(w->getDeviceId()); + pt->setPlatformIndex(w->getPlatformID()); + // Opening the 'test'th subtest of 'pt' + pt->open(test, units, conversion, deviceId); + pt->clearPerfInfo(); + + char buffer[256]; + sprintf(buffer, "%s[%3d]", subtestName.c_str(), test); + oclTestLog(OCLTEST_LOG_ALWAYS, "%-32s", buffer); + + if (pt->hasErrorOccured()) { + result->passed = false; + report(w, subtestName.c_str(), test, crc, pt->getErrorMsg(), + pt->getPerfInfo(), result, pt->testDescString.c_str()); + } else { + unsigned int n = calibrate(pt); + double timer = run(pt, n); + crc = pt->close(); + + if (pt->hasErrorOccured()) { + // run second time if the test fails the first time. + if (!second_run && App::m_reRunFailed && !App::m_svcMsg) { + second_run = true; + + // Destroying a test object + moduleLock.lock(); + if (!pt->cache_test()) { + m->destroy_test(pt); + } + moduleLock.unlock(); + + pt->clearError(); + goto RERUN_TEST; + } + } + result->passed = !pt->hasErrorOccured(); + /// print conditional pass if it is passes the second time. + if (second_run && result->passed) { + report(w, subtestName.c_str(), test, crc, "Conditional PASS", + pt->getPerfInfo(), result, pt->testDescString.c_str()); + } else { + report(w, subtestName.c_str(), test, crc, pt->getErrorMsg(), + pt->getPerfInfo(), result, pt->testDescString.c_str()); + } + } + if (App::m_svcMsg) { + oclTestLog(OCLTEST_LOG_ALWAYS, "##%s[testFinished name='%s.%s.%d']\n", App::m_svcMsg, + m->get_libname(), subtestName.c_str(), test); + } + + // Make sure we clear the error after we report that there was an error. + pt->clearError(); + + // Destroying a test object + moduleLock.lock(); + if (!pt->cache_test()) { + m->destroy_test(pt); + } + moduleLock.unlock(); + return NULL; +} + +void App::PrintTestOrder(int mod_index) { + oclTestLog(OCLTEST_LOG_ALWAYS, "Module: %s (%d tests)\n", + m_modules[mod_index].name.c_str(), + m_modules[mod_index].get_count()); + + for (unsigned int j = 0; j < m_modules[mod_index].get_count(); j++) { + oclTestLog(OCLTEST_LOG_ALWAYS, "%s\n", + m_modules[mod_index].get_name(mp_testOrder[j])); + } +} + +//! Function that runs all the tests specified in the command-line +void App::RunAllTests() { +#ifdef _WIN32 + + if (!m_console) m_window = new Window("Test", 100, 100, m_width, m_height, 0); +#endif + + // + // Add all tests to run list if none specified + // + if (m_tests.size() < 1) { + for (unsigned int i = 0; i < m_modules.size(); i++) { + for (unsigned int j = 0; j < m_modules[i].get_count(); j++) { + AddToList(m_tests, m_modules[i].get_name(j)); + } + } + } + + unsigned int num_passes = 0; + unsigned int num_failures = 0; + + + // + // Run each test + // + for (unsigned int i = 0; i < m_modules.size(); i++) { + oclTestLog(OCLTEST_LOG_ALWAYS, + "\n-------------------------------------------------\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + "The OpenCL Testing Module %s Version = %d \n", + m_modules[i].get_libname(), m_modules[i].get_version()); + oclTestLog(OCLTEST_LOG_ALWAYS, "-------------------------------------------------\n"); + + if (App::m_svcMsg) { + oclTestLog(OCLTEST_LOG_ALWAYS, "##%s[testSuiteStarted name='ocltst %s']\n", + App::m_svcMsg, m_modules[i].get_libname()); + } + + // array to keep track of order of test execution. + int test_count = m_modules[i].get_count(); + mp_testOrder = new int[test_count]; + memset((void*)mp_testOrder, 0, sizeof(*mp_testOrder) * test_count); + SetTestRunOrder(i); + + // + // List all tests first if the option was turned on + // + if (m_list) { + PrintTestOrder(i); + delete[] mp_testOrder; + continue; + // return; + } + + for (unsigned int itr_var = 0; itr_var < m_modules[i].get_count(); + itr_var++) { + // done for random order generation + unsigned int subtest = mp_testOrder[itr_var]; + + const char* name = m_modules[i].get_name(subtest); + if (itr_var < m_tests.size() && TestInList(m_tests, name)) { + OCLTest* pt = NULL; + if (m_modules[i].cached_test) { + pt = m_modules[i].cached_test[subtest]; + } + // Try to use the cached version first! + if (!pt) { + pt = m_modules[i].create_test(subtest); + if (pt->cache_test() && m_modules[i].cached_test) { + m_modules[i].cached_test[subtest] = pt; + } + } + + int numSubTests = pt->getNumSubTests(); + assert(numSubTests > 0); + + TestIndexList testIndices; + GetTestIndexList(testIndices, m_tests, name, numSubTests - 1); + + TestIndexList avoidIndices; + GetTestIndexList(avoidIndices, m_avoid, name, numSubTests - 1); + + TestIndexList erasedIndices; + PruneTestIndexList(testIndices, avoidIndices, erasedIndices); + + int numTestsRun = 0; + for (unsigned int j = 0; j < testIndices.size(); j++) { + unsigned int test = testIndices[j]; + + WaitAllThreads(); + AddWorkerThread(i, subtest, test, pt->getThreadUsage(), runSubtest); + + for (unsigned int thread = 1; + (thread < m_threads) && (thread < m_modules.size()); thread++) { + AddWorkerThread(thread, subtest, test, pt->getThreadUsage(), + dummyThread); + } + + numTestsRun++; + } + + WaitAllThreads(); + // Printing the test report + // First checking whether the number of subtests is greater than 1. + // No point printing report for a one subtest test + + if (numTestsRun > 0) { + if (testReport[0]->success) { + num_passes++; + } else { + num_failures++; + } + } + if (App::m_svcMsg) { + for (unsigned int j = 0; j < erasedIndices.size(); j++) { + oclTestLog(OCLTEST_LOG_ALWAYS, + "##%s[testIgnored name='%s.%s.%d']\n", App::m_svcMsg, + m_modules[i].get_libname(), name, erasedIndices[j]); + } + } + + // Resetting the values of the test reports + // for(unsigned int j = 0; j < m_numDevices; j++) + for (unsigned int j = 0; j < 1; j++) { + testReport[j]->reset(); + } + m_modules[i].destroy_test(pt); + if (m_modules[i].cached_test) { + m_modules[i].cached_test[subtest] = NULL; + } + } + } + + if (App::m_svcMsg) { + oclTestLog(OCLTEST_LOG_ALWAYS, "##%s[testSuiteFinished name='ocltst %s']\n", + App::m_svcMsg, m_modules[i].get_libname()); + } + + // print the order in which the test are executed if they are + // randomized. + if (m_rndOrder) { + PrintTestOrder(i); + } + // deleting the test order + delete[] mp_testOrder; + } + +#ifdef _WIN32 + if (!m_console && m_window) { + ((Window*)m_window)->ConsumeEvents(); + } +#endif + float total_tests = (float)(num_passes + num_failures); + + float percent_passed = 0.0f; + float percent_failed = 0.0f; + float percent_total = 0.0f; + if (total_tests > 0) { + percent_passed = 100.0f * ((float)num_passes / total_tests); + percent_failed = 100.0f * ((float)num_failures / total_tests); + percent_total = 100.0f * ((float)total_tests / total_tests); + } + + oclTestLog(OCLTEST_LOG_ALWAYS, "\n\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, "----------------------------------------\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, "Total Passed Tests: %8d (%6.2f%s)\n", + num_passes, percent_passed, "%"); + oclTestLog(OCLTEST_LOG_ALWAYS, "Total Failed Tests: %8d (%6.2f%s)\n", + num_failures, percent_failed, "%"); + oclTestLog(OCLTEST_LOG_ALWAYS, "----------------------------------------\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, "Total Run Tests: %8d (%6.2f%s)\n", + (int)total_tests, percent_total, "%"); + oclTestLog(OCLTEST_LOG_ALWAYS, "\n\n"); +} + +///////////////////////////////////////////////////////////////////////////// + +void App::AddToList(StringList& strlist, const char* str) { + std::string s(str); + + strlist.push_back(s); +} + +void App::LoadList(StringList& strlist, const char* filename) { + char buffer[1024]; + + FILE* fp = fopen(filename, "r"); + + if (fp == NULL) return; + + while (fgets(buffer, 1000, fp) != NULL) { + size_t length = strlen(buffer); + if (length > 0) { + if (buffer[length - 1] != '\n') { + length++; + } + buffer[length - 1] = 0; + AddToList(strlist, buffer); + } + } + + fclose(fp); +} + +static void Help(const char* name) { + oclTestLog(OCLTEST_LOG_ALWAYS, + "%s (-w | -V | -m | -M | -l | -t | -T | -p | -d | -x | -y | -g| " + "-o | -n )\n", + name); + oclTestLog(OCLTEST_LOG_ALWAYS, " -w : enable window mode\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, " -V : enable TeamCity service messages\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, " -J : enable Jenkins service messages\n"); + oclTestLog( + OCLTEST_LOG_ALWAYS, + " -d : dump test output to portable float map (pfm)\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -m : specify a DLL module with tests\n"); + oclTestLog( + OCLTEST_LOG_ALWAYS, + " -M : specify a text file with one DLL module per line\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -l : list test names in DLL modules and exit\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -s : number of threads to spawn\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, " -t : run test\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -T : specify a text file with one test per line\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -a : specify a test to avoid\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -A : specify a text file of tests to avoid with " + "one test per line\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -p : specify a platform to run on, 'amd','nvidia' " + "or 'intel'\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, " -h : this help text\n"); + oclTestLog( + OCLTEST_LOG_ALWAYS, + " -x : x dimension for debug output image (and window)\n"); + oclTestLog( + OCLTEST_LOG_ALWAYS, + " -y : y dimension for debug output image (and window)\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -P : Perflab mode (just print the result without " + "any supplementary information)\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -n #number : run the tests specified with -m, -M, -t or -T " + "options multiple times\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -r : Option to Randomize the order in which the " + "tests are executed.\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -R : Option to ReRun failed tests for conditional " + "pass.\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -i : Don't print system information\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -g : GPUid to run the tests on\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -o : dump the output to a specified file\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " -c : Run the test on the CPU device.\n"); + oclTestLog(OCLTEST_LOG_ALWAYS, " : \n"); + oclTestLog(OCLTEST_LOG_ALWAYS, + " : To run only one subtest of a test, append the " + "subtest to\n"); + oclTestLog( + OCLTEST_LOG_ALWAYS, + " : the end of the test name in brackets. i.e. test[1]"); + oclTestLog(OCLTEST_LOG_ALWAYS, "\n"); + + exit(0); +} + +unsigned int getPlatformID(const char* str) { + std::string strOfCLVendor(str); + std::string strOfCLPlatformName; + unsigned int platform = 0; + + // currently, the only input values amd,nvidia and intel are supported + if (strOfCLVendor == "amd") { + strOfCLPlatformName = "Advanced Micro Devices, Inc."; + } else if (strOfCLVendor == "intel") { + strOfCLPlatformName = "Intel(R) Corporation"; + } else if (strOfCLVendor == "nvidia") { + strOfCLPlatformName = "NVIDIA Corporation"; + } else { + // fall-back on platform index 0 + return platform; + } + + cl_int status; + cl_uint numPlatforms = 0; + + status = clGetPlatformIDs(0, NULL, &numPlatforms); + if (status != CL_SUCCESS) { + return platform; + } + + cl_platform_id* platforms = new cl_platform_id[numPlatforms]; + status = clGetPlatformIDs(numPlatforms, platforms, NULL); + + if (status == CL_SUCCESS) { + unsigned int i; + for (i = 0; i < numPlatforms; ++i) { + char buff[200]; + status = clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, sizeof(buff), + buff, NULL); + if (status != CL_SUCCESS) { + break; + } + if (strcmp(buff, strOfCLPlatformName.c_str()) == 0) { + platform = i; + break; + } + } + } + + delete[] platforms; + return platform; +} + +static const char* supported_options = "dg:lm:M:o:Ps:t:T:a:A:p:v:wxy:in:rcRVJ"; + +unsigned int parseCommandLineForPlatform(unsigned int argc, char** argv) { + int c; + unsigned int platform = 0; + + while ((c = getopt(argc, argv, supported_options)) != + -1) { + switch (c) { + case 'p': + platform = getPlatformID(optarg); + break; + default: + break; + } + } + return platform; +} + +void App::CommandLine(unsigned int argc, char** argv) { + unsigned int i = 1; + int c; + bool hasOption = false; + unsigned int tmpNumDevices = 0; + unsigned int tmpDeviceId = 0; + m_deviceId = 0; + int tmp; + + while ((c = getopt(argc, argv, supported_options)) != + -1) { + switch (c) { + case 'c': + m_useCPU = true; + break; + + case 'p': + break; + + case 'w': + m_console = false; + hasOption = true; + break; + + case 'V': + m_svcMsg = "teamcity"; + break; + + case 'J': + m_svcMsg = "jenkins"; + break; + + case 'd': + m_dump = true; + hasOption = true; + break; + + case 'm': + AddToList(m_paths, optarg); + hasOption = true; + break; + + case 'M': + LoadList(m_paths, optarg); + hasOption = true; + break; + + case 'a': + AddToList(m_avoid, optarg); + hasOption = true; + break; + + case 'A': + LoadList(m_avoid, optarg); + hasOption = true; + break; + + case 'l': + m_list = true; + hasOption = true; + break; + + // command line switch to loop execution of any specified test or tests n + // number of times + case 'n': + m_numItr = atoi(optarg); + break; + + // command line switch to randomize the order of test execution in OCLTest + case 'r': + m_rndOrder = true; + break; + + // command line switch to rerun the failed tests to see if they pass on + // second run + case 'R': { + m_reRunFailed = true; + break; + } + case 't': + AddToList(m_tests, optarg); + hasOption = true; + break; + + case 'T': + LoadList(m_tests, optarg); + hasOption = true; + break; + + case 's': + m_threads = atoi(optarg); + hasOption = true; + break; + + case 'h': + Help(argv[0]); + break; + + case 'x': + m_width = atoi(optarg); + hasOption = true; + break; + + case 'y': + m_height = atoi(optarg); + hasOption = true; + break; + + case 'P': + m_perflab = true; + hasOption = true; + break; + case 'g': +#if 0 + tmpNumDevices = (unsigned int)atoi(optarg); + if(m_numDevices < tmpNumDevices) + { + oclTestLog(OCLTEST_LOG_ALWAYS, "Number of Devices(%d) less than specified by the user(%d). Using %d devices.\n", m_numDevices, tmpNumDevices, m_numDevices); + } + else + { + m_numDevices = tmpNumDevices; + } +#else + tmpDeviceId = (unsigned int)atoi(optarg); +#endif + break; + case 'v': + tmp = atoi(optarg); + if (tmp >= 0 && tmp < 100) { + oclTestSetLogLevel(atoi(optarg)); + } else { + oclTestLog(OCLTEST_LOG_ALWAYS, "Invalid verbose level\n"); + } + break; + case 'o': { + hasOption = true; + oclTestEnableLogToFile(optarg); + } break; + case 'i': + m_noSysInfoPrint = true; + break; + default: + Help(argv[0]); + break; + } + } + + // Reset devices in case user overrode defaults + m_numDevices = findAdapters(m_platform, m_useCPU, &mpform_id); + if (m_numDevices < (tmpDeviceId + 1)) { + m_deviceId = 0; + oclTestLog(OCLTEST_LOG_ALWAYS, + "User specified deviceId(%d) exceedes the number of " + "Devices(%d). Using device %d.\n", + tmpDeviceId, m_numDevices, m_deviceId); + } else { + m_deviceId = tmpDeviceId; + } + + if (!hasOption) { + Help(argv[0]); + } +} + +bool App::TestInList(StringList& strlist, const char* szModuleTestname) { + if (szModuleTestname == NULL) { + return false; + } + for (unsigned int i = 0; i < strlist.size(); i++) { + // check to see if an index is specified for this test name + int nIndex = -1; + std::string szTestName = strlist[i]; + if (szTestName.find("[") != std::string::npos) { + size_t nFirstBracket = szTestName.find("["); + size_t nLastBracket = szTestName.find("]"); + if ((nFirstBracket != std::string::npos) && + (nLastBracket != std::string::npos) && + (nLastBracket > nFirstBracket)) { + szTestName = szTestName.substr(0, nFirstBracket); + } + } + if (strcmp(szModuleTestname, szTestName.c_str()) == 0) { + return true; + } + } + + return false; +} + +void App::GetTestIndexList(TestIndexList& testIndices, StringList& testList, + const char* szModuleTestname, int maxIndex) { + for (unsigned int i = 0; i < testList.size(); i++) { + IndicesRange nIndex = {0, maxIndex}; + + // If the test name string ends with [...] parse the text + // between the brackets to determine the index range. + std::string szTestName = testList[i]; + if (szTestName.find("[") != std::string::npos) { + size_t nFirstBracket = szTestName.find("["); + size_t nLastBracket = szTestName.find("]"); + if ((nFirstBracket != std::string::npos) && + (nLastBracket != std::string::npos) && + (nLastBracket > nFirstBracket)) { + // Getting the string between the brackets '[' and ']' + // The values can be one of the following:- + // [a-b] - Run tests from a to b + // [a-] - Run tests from subtest a to subtest total_tests + // [-b] - Run tests from subtest 0 to subtest b + // a and b are indices of the tests to run + + std::string nIndexString = szTestName.substr( + nFirstBracket + 1, nLastBracket - nFirstBracket - 1); + size_t nIntermediateHyphen = szTestName.find("-"); + if ((nIntermediateHyphen != std::string::npos) && + (nIntermediateHyphen < nLastBracket) && + (nIntermediateHyphen > nFirstBracket)) { + // Getting the start index + if ((nIntermediateHyphen - 1) == nFirstBracket) { + nIndex.startIndex = 0; + } else { + nIndex.startIndex = + atoi(szTestName + .substr(nFirstBracket + 1, + nIntermediateHyphen - nFirstBracket - 1) + .c_str()); + } + + // Getting the end index + if ((nIntermediateHyphen + 1) == nLastBracket) { + nIndex.endIndex = maxIndex; + } else { + nIndex.endIndex = + atoi(szTestName + .substr(nIntermediateHyphen + 1, + nLastBracket - nIntermediateHyphen - 1) + .c_str()); + } + } else { + nIndex.startIndex = atoi( + szTestName + .substr(nFirstBracket + 1, nLastBracket - nFirstBracket - 1) + .c_str()); + nIndex.endIndex = nIndex.startIndex; + } + } + + szTestName = szTestName.substr(0, nFirstBracket); + } + + if (strcmp(szModuleTestname, szTestName.c_str()) == 0) { + // If the values are out of order, swap them. + if (nIndex.startIndex > nIndex.endIndex) { + int tmp = nIndex.startIndex; + nIndex.startIndex = nIndex.endIndex; + nIndex.endIndex = tmp; + } + + // Add the indices in the specified range to the list. + for (int i = nIndex.startIndex; i <= nIndex.endIndex; ++i) { + if (i <= maxIndex) { + testIndices.push_back(i); + } else { + oclTestLog(OCLTEST_LOG_ALWAYS, + "Error: Invalid test index for subtest: %s!\n", + szModuleTestname); + } + } + + // Now sort and prune duplicates. + std::sort(testIndices.begin(), testIndices.end()); + std::unique(testIndices.begin(), testIndices.end()); + } + } +} + +void App::PruneTestIndexList(TestIndexList& testIndices, + TestIndexList& avoidIndices, + TestIndexList& erasedIndices) { + for (TestIndexList::iterator it = testIndices.begin(); + it != testIndices.end();) { + unsigned int index = *it; + TestIndexList::iterator result = + std::find(avoidIndices.begin(), avoidIndices.end(), index); + if (result != avoidIndices.end()) { + it = testIndices.erase(it); + erasedIndices.push_back(index); + } else { + ++it; + } + } +} + +void App::ScanForTests() { + for (unsigned int i = 0; i < m_paths.size(); i++) { + Module mod; + +#ifdef _WIN32 + std::string::iterator myIter; + myIter = m_paths[i].end(); + myIter--; + if (*myIter == 0x0a) m_paths[i].erase(myIter); + + mod.hmodule = LoadLibrary(m_paths[i].c_str()); +#endif +#ifdef __linux__ + mod.hmodule = dlopen(m_paths[i].c_str(), RTLD_NOW); +#endif + + if (mod.hmodule == NULL) { + fprintf(stderr, "Could not load module: %s\n", m_paths[i].c_str()); +#ifdef __linux__ + fprintf(stderr, "Error : %s\n", dlerror()); +#else +#endif + } else { + mod.name = m_paths[i]; + +#ifdef _WIN32 + mod.get_count = (TestCountFuncPtr)GetProcAddress(mod.hmodule, + "OCLTestList_TestCount"); + mod.get_name = + (TestNameFuncPtr)GetProcAddress(mod.hmodule, "OCLTestList_TestName"); + mod.create_test = (CreateTestFuncPtr)GetProcAddress( + mod.hmodule, "OCLTestList_CreateTest"); + mod.destroy_test = (DestroyTestFuncPtr)GetProcAddress( + mod.hmodule, "OCLTestList_DestroyTest"); + mod.get_version = (TestVersionFuncPtr)GetProcAddress( + mod.hmodule, "OCLTestList_TestLibVersion"); + mod.get_libname = (TestLibNameFuncPtr)GetProcAddress( + mod.hmodule, "OCLTestList_TestLibName"); +#endif +#ifdef __linux__ + mod.get_count = + (TestCountFuncPtr)dlsym(mod.hmodule, "OCLTestList_TestCount"); + mod.get_name = + (TestNameFuncPtr)dlsym(mod.hmodule, "OCLTestList_TestName"); + mod.create_test = + (CreateTestFuncPtr)dlsym(mod.hmodule, "OCLTestList_CreateTest"); + mod.destroy_test = + (DestroyTestFuncPtr)dlsym(mod.hmodule, "OCLTestList_DestroyTest"); + mod.get_version = + (TestVersionFuncPtr)dlsym(mod.hmodule, "OCLTestList_TestLibVersion"); + mod.get_libname = + (TestLibNameFuncPtr)dlsym(mod.hmodule, "OCLTestList_TestLibName"); +#endif + mod.cached_test = new OCLTest*[mod.get_count()]; + for (int x = 0, y = mod.get_count(); x < y; ++x) { + mod.cached_test[x] = NULL; + } + m_modules.push_back(mod); + } + } +} + +void App::CleanUp() { + for (unsigned int i = 0; i < m_modules.size(); i++) { + if (m_modules[i].cached_test) { + delete[] m_modules[i].cached_test; + } +#ifdef _WIN32 + FreeLibrary(m_modules[i].hmodule); +#endif +#ifdef __linux__ + dlclose(m_modules[i].hmodule); +#endif + } + +#ifdef _WIN32 + if (m_window) delete m_window; + m_window = 0; +#endif +} + +extern int optind; +///////////////////////////////////////////////////////////////////////////// +bool App::m_reRunFailed = false; +const char* App::m_svcMsg = nullptr; + +int main(int argc, char** argv) { +#if EMU_ENV + printf("Built for Emulation Environment\n"); +#endif // EMU_ENV + unsigned int platform = 0; + platform = parseCommandLineForPlatform(argc, argv); + // reset optind as we really didn't parse the full command line + optind = 1; + App app(platform); +#ifdef _WIN32 + // this function is registers windows service routine when ocltst is launched + // by the OS on service initialization. On other scenarios, this function does + // nothing. + serviceStubCall(); + // SetErrorMode(SEM_NOGPFAULTERRORBOX); + // const LPTOP_LEVEL_EXCEPTION_FILTER oldFilter = + // SetUnhandledExceptionFilter(xFilter); +#endif // _WIN32 +#ifdef AUTO_REGRESS + try { +#endif /* AUTO_REGRESS */ + app.CommandLine(argc, argv); + app.printOCLinfo(); + app.ScanForTests(); + for (int i = 0; i < app.GetNumItr(); i++) { + app.RunAllTests(); + } + app.CleanUp(); +#ifdef AUTO_REGRESS + } catch (...) { + oclTestLog(OCLTEST_LOG_ALWAYS, "Exiting due to unhandled exception!\n"); + return (-1); + } +#endif /* AUTO_REGRESS */ + + return 0; +} + +#ifdef _WIN32 + +#include + +typedef unsigned int uint32; +typedef size_t uintp; + +struct StackEntry { + uintp addr; + uint32 line; + uint32 disp; + char symbol[128]; + char file[128]; +}; + +static const unsigned int MAX_DEPTH_PER_NODE = 24; +struct Info { + bool operator==(const Info& b) const { return key == b.key; } + + uintp key; // pointer, handle, whatever + StackEntry stack[MAX_DEPTH_PER_NODE]; +}; + +static void dumpTraceBack(CONTEXT& context) { + Info info; + + oclTestLog(OCLTEST_LOG_ALWAYS, "Exception: exiting!\n"); + HANDLE process = GetCurrentProcess(); + + STACKFRAME64 stackframe; + memset(&stackframe, 0, sizeof(STACKFRAME64)); + +#if defined(_WIN64) + stackframe.AddrPC.Offset = context.Rip; + stackframe.AddrPC.Mode = AddrModeFlat; + stackframe.AddrStack.Offset = context.Rsp; + stackframe.AddrStack.Mode = AddrModeFlat; + stackframe.AddrFrame.Offset = context.Rbp; + stackframe.AddrFrame.Mode = AddrModeFlat; +#else + stackframe.AddrPC.Offset = context.Eip; + stackframe.AddrPC.Mode = AddrModeFlat; + stackframe.AddrStack.Offset = context.Esp; + stackframe.AddrStack.Mode = AddrModeFlat; + stackframe.AddrFrame.Offset = context.Ebp; + stackframe.AddrFrame.Mode = AddrModeFlat; +#endif + unsigned int depth = 0; + + if (SymInitialize(process, NULL, true)) { + while ((depth < MAX_DEPTH_PER_NODE) && + StackWalk64(IMAGE_FILE_MACHINE_I386, process, GetCurrentThread(), + &stackframe, &context, NULL, SymFunctionTableAccess64, + SymGetModuleBase64, NULL)) { + if (stackframe.AddrPC.Offset != 0) { + // + // we don't want to evaluate the names/lines yet + // so just record the address + // + info.stack[depth].addr = (uintp)stackframe.AddrPC.Offset; + + DWORD64 disp64; + DWORD disp; + IMAGEHLP_SYMBOL64* symInfo; + IMAGEHLP_LINE64 lineInfo; + uintp addr = (uintp)stackframe.AddrPC.Offset; + char buffer[128]; + + symInfo = (IMAGEHLP_SYMBOL64*)&buffer[0]; + symInfo->SizeOfStruct = sizeof(symInfo); + symInfo->MaxNameLength = (sizeof(buffer) - sizeof(IMAGEHLP_SYMBOL64)); + + lineInfo.SizeOfStruct = sizeof(lineInfo); + + if (SymGetSymFromAddr64(process, addr, &disp64, symInfo)) { + sprintf(info.stack[depth].symbol, "%s", symInfo->Name); + info.stack[depth].disp = (uint32)disp64; + } else { + sprintf(info.stack[depth].symbol, ""); + } + + if (SymGetLineFromAddr64(process, addr, &disp, &lineInfo)) { + sprintf(info.stack[depth].file, "%s", lineInfo.FileName); + info.stack[depth].line = lineInfo.LineNumber; + } else { + info.stack[depth].file[0] = '\0'; + } + depth++; + } + } + } + + SymCleanup(process); + + int j = 0; + while (j < MAX_DEPTH_PER_NODE && info.stack[j].addr != 0) { + oclTestLog(OCLTEST_LOG_ALWAYS, " %s()+%d (0x%.8x) %s:%d\n", + info.stack[j].symbol, info.stack[j].disp, info.stack[j].addr, + info.stack[j].file, info.stack[j].line); + + j++; + } +} + +static LONG WINAPI xFilter(LPEXCEPTION_POINTERS xEP) { + CONTEXT context; + CONTEXT* xCtx = &context; + memset(xCtx, 0, sizeof(CONTEXT)); + context.ContextFlags = CONTEXT_FULL; + memcpy(xCtx, xEP->ContextRecord, sizeof(CONTEXT)); + + dumpTraceBack(context); + + return (EXCEPTION_EXECUTE_HANDLER); +} +#undef CHECK_RESULT +#endif // WIN_OS + +///////////////////////////////////////////////////////////////////////////// diff --git a/opencl/tests/ocltst/env/pfm.cpp b/opencl/tests/ocltst/env/pfm.cpp new file mode 100644 index 0000000000..80c0153403 --- /dev/null +++ b/opencl/tests/ocltst/env/pfm.cpp @@ -0,0 +1,79 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "pfm.h" + +#ifdef _WIN32 +#include +#endif + +#include +#include +#include +#include +#include + +unsigned int SavePFM(const char* filename, const float* buffer, + unsigned int width, unsigned int height, + unsigned int components) { + unsigned int error = 0; + + // + // open the image file for writing + // + FILE* fh; + if ((fh = fopen(filename, "wb")) == NULL) { + return 1; + } + + // + // write the PFM header + // +#define PFMEOL "\x0a" + fprintf(fh, "PF" PFMEOL "%d %d" PFMEOL "-1" PFMEOL, width, height); + fflush(fh); + + // + // write each scanline + // + const unsigned int lineSize = width * 3; + float line[3 * 4096]; + for (unsigned int y = height; y > 0; y--) { + const float* v = buffer + components * width * (y - 1); + for (unsigned int x = 0; x < width; x++) { + line[x * 3 + 0] = v[x * components + 0]; + line[x * 3 + 1] = + (components > 1) ? v[x * components + 1] : v[x * components + 0]; + line[x * 3 + 2] = + (components > 2) ? v[x * components + 2] : v[x * components + 0]; + } + unsigned int written = + (unsigned int)fwrite(line, (unsigned int)sizeof(float), lineSize, fh); + if (written != lineSize) { + error = 1; + break; + } + fflush(fh); + } + fflush(fh); + fclose(fh); + + return error; +} diff --git a/opencl/tests/ocltst/env/pfm.h b/opencl/tests/ocltst/env/pfm.h new file mode 100644 index 0000000000..ae3dcadff2 --- /dev/null +++ b/opencl/tests/ocltst/env/pfm.h @@ -0,0 +1,28 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _PFM_H_ +#define _PFM_H_ + +extern unsigned int SavePFM(const char* filename, const float* buffer, + unsigned int width, unsigned int height, + unsigned int components); + +#endif // _PFM_H_ diff --git a/opencl/tests/ocltst/env/window.cpp b/opencl/tests/ocltst/env/window.cpp new file mode 100644 index 0000000000..094aee10e9 --- /dev/null +++ b/opencl/tests/ocltst/env/window.cpp @@ -0,0 +1,175 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifdef _WIN32 + +#include +#include +#include + +#include "Window.h" + +HWND Window::_hWnd; +unsigned char* Window::_data; +unsigned int Window::_w; +unsigned int Window::_h; + +void Window::OnPaint(void) { + PAINTSTRUCT ps; + HDC hDC = BeginPaint(_hWnd, &ps); + + if (_w && _h && _data) { + BITMAPINFO bm; + bm.bmiColors[0].rgbBlue = 0; + bm.bmiColors[0].rgbGreen = 0; + bm.bmiColors[0].rgbRed = 0; + bm.bmiColors[0].rgbReserved = 0; + + bm.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bm.bmiHeader.biWidth = _w; + bm.bmiHeader.biHeight = _h; + bm.bmiHeader.biPlanes = 1; + bm.bmiHeader.biBitCount = 32; + bm.bmiHeader.biCompression = BI_RGB; + bm.bmiHeader.biSizeImage = 0; + bm.bmiHeader.biXPelsPerMeter = 0; + bm.bmiHeader.biYPelsPerMeter = 0; + bm.bmiHeader.biClrUsed = 0; + bm.bmiHeader.biClrImportant = 0; + + int ret = SetDIBitsToDevice(hDC, 0, 0, _w, _h, 0, 0, 0, _h, _data, &bm, + DIB_RGB_COLORS); + assert(ret); + } + + EndPaint(_hWnd, &ps); +} + +/***************************************************************************** + *****************************************************************************/ +LRESULT WINAPI Window::DefWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, + LPARAM lParam) { + switch (uMsg) { + case WM_CHAR: + switch (wParam) { + case 27: // ESC + exit(0); + break; + } + return 0; + case WM_PAINT: + OnPaint(); + return 0; + } + return ::DefWindowProc(hWnd, uMsg, wParam, lParam); +} + +Window::Window(const char* title, int x, int y, int width, int height, + unsigned int uiStyle) { + _data = NULL; + _w = 0; + _h = 0; + + WNDCLASS wc = {0, + (WNDPROC)Window::DefWindowProc, + 0, + 0, + GetModuleHandle(0), + LoadIcon(NULL, IDI_WINLOGO), + LoadCursor(NULL, IDC_ARROW), + NULL, + NULL, + "TST"}; + if (!RegisterClass(&wc)) { + MessageBox(NULL, "RegisterClass() failed", "Error", MB_OK); + exit(0); + } + + if (uiStyle == 0) { + uiStyle = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; + } + + RECT r = {x, y, x + width, y + height}; + AdjustWindowRect(&r, uiStyle, 0); + + _hWnd = CreateWindow("TST", title, uiStyle, r.left, r.top, r.right - r.left, + r.bottom - r.top, NULL, NULL, GetModuleHandle(0), this); + if (_hWnd == NULL) { + MessageBox(NULL, "CreateWindow() failed.", "Error", MB_OK); + exit(0); + } + + ShowWindow(_hWnd, SW_SHOW); + UpdateWindow(_hWnd); +} + +Window::~Window(void) { + DestroyWindow(_hWnd); + + if (_data) { + delete[] _data; + } + + UnregisterClass("TST", GetModuleHandle(NULL)); +} + +void Window::ConsumeEvents(void) { + while (1) { + MSG msg; + while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { + GetMessage(&msg, NULL, 0, 0); + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } +} + +void Window::ShowImage(unsigned int width, unsigned int height, float* data) { + if (_data) { + delete[] _data; + } + + _data = new unsigned char[4 * width * height]; + _w = width; + _h = height; + + unsigned char* pb = _data; + float* p = data; + unsigned int i; + for (i = 0; i < (unsigned int)(width * height); i++) { + // + // argb + // + float v = p[2] > 1.f ? 1.f : (p[2] < 0.f ? 0.f : p[2]); + *pb++ = (unsigned char)(255.f * v); + v = p[1] > 1.f ? 1.f : (p[1] < 0.f ? 0.f : p[1]); + *pb++ = (unsigned char)(255.f * v); + v = p[0] > 1.f ? 1.f : (p[0] < 0.f ? 0.f : p[0]); + *pb++ = (unsigned char)(255.f * v); + v = p[3] > 1.f ? 1.f : (p[3] < 0.f ? 0.f : p[3]); + *pb++ = (unsigned char)(255.f * v); + p += 4; + } + + RedrawWindow(_hWnd, NULL, NULL, RDW_INVALIDATE); + OnPaint(); +} + +#endif // _WIN32 diff --git a/opencl/tests/ocltst/env/window.h b/opencl/tests/ocltst/env/window.h new file mode 100644 index 0000000000..ee6474f792 --- /dev/null +++ b/opencl/tests/ocltst/env/window.h @@ -0,0 +1,55 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _WINDOW_H_ +#define _WINDOW_H_ + +#ifdef _WIN32 + +#include +#include + +class Window { + public: + typedef LRESULT (*WindowProc)(HWND hW, UINT uMsg, WPARAM wP, LPARAM lP); + + public: + Window(const char* title, int x, int y, int width, int height, + unsigned int uiStyle); + ~Window(); + + void ConsumeEvents(void); + void ShowImage(unsigned int width, unsigned int height, float* data); + + private: + static LRESULT WINAPI DefWindowProc(HWND hW, UINT uMsg, WPARAM wP, LPARAM lP); + + static void OnPaint(void); + + public: + static HWND _hWnd; + static unsigned char* _data; + static unsigned int _w; + static unsigned int _h; +}; + +#endif // _WIN32 + +#endif // _WINDOW_H_ diff --git a/opencl/tests/ocltst/include/OCL/Thread.h b/opencl/tests/ocltst/include/OCL/Thread.h new file mode 100644 index 0000000000..0f0ac38a8f --- /dev/null +++ b/opencl/tests/ocltst/include/OCL/Thread.h @@ -0,0 +1,148 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef OCL_THREAD_H +#define OCL_THREAD_H + +//! +//! \file Thread.h +//! + +#ifdef _WIN32 +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0501 +#endif + +#include "windows.h" +#else +#include "pthread.h" +#endif + +//! Entry point for the thread +//! prototype of the entry point in windows +typedef void *(*oclThreadFunc)(void *); + +namespace OCLutil { +//! \class Lock +//! \brief Provides a wrapper for locking primitives used to +//! synchronize _CPU_ threads. +//! +//! Common usage would be: +//! +//! OCL::Lock lock; +//! +//! .... +//! +//! // Critical section begins +//! +//! lock.lock(); +//! +//! ..... +//! +//! // Critical section ends +//! +//! lock.unlock(); +//! + +class Lock { + public: + //! Constructor for OCLLock + Lock(); + + //! Destructor for OCLLock + ~Lock(); + + //! Try to acquire the lock, if available continue, else wait on the lock + void lock(); + + //! Try to acquire the lock, if available, hold it, else continue doing + //! something else + bool tryLock(); + + //! Unlock the lock and return + void unlock(); + + private: + ///////////////////////////////////////////////////////////// + //! + //! Private data members and methods + //! + + //! System specific synchronization primitive +#ifdef _WIN32 + CRITICAL_SECTION _cs; +#else + pthread_mutex_t _lock; +#endif +}; + +////////////////////////////////////////////////////////////// +//! +//! \class Thread +//! \brief Provides a wrapper for creating a _CPU_ thread. +//! +//! This class provides a simple wrapper to a CPU thread/ +//! The class name might be a bit confusing, esp considering +//! the GPU has it's own threads as well. +//! +class Thread { + public: + //! Thread constructor and destructor. Note that the thread is + //! NOT created in the constructor. The thread creation takes + //! place in the create method + Thread(); + + ~Thread(); + + //! Wrapper for pthread_create. Pass the thread's entry + //! point and data to be passed to the routine + bool create(oclThreadFunc func, void *arg); + + //! Wrapper for pthread_join. The calling thread + //! will wait until _this_ thread exits + bool join(); + + //! Get the thread data passed by the application + void *getData() { return _data; } + + //! Get the thread ID + static unsigned int getID(); + + private: + ///////////////////////////////////////////////////////////// + //! + //! Private data members and methods + //! + +#ifdef _WIN32 + //! store the handle + HANDLE _tid; + + unsigned int _ID; +#else + pthread_t _tid; + + pthread_attr_t _attr; +#endif + + void *_data; +}; +}; // namespace OCLutil +#endif diff --git a/opencl/tests/ocltst/include/OCLLog.h b/opencl/tests/ocltst/include/OCLLog.h new file mode 100644 index 0000000000..20671a8633 --- /dev/null +++ b/opencl/tests/ocltst/include/OCLLog.h @@ -0,0 +1,47 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef OCLLOG_H_ +#define OCLLOG_H_ + +#ifdef _WIN32 + +#ifdef OCLTST_LOG_BUILD +#define DLLIMPORT __declspec(dllexport) +#else +#define DLLIMPORT __declspec(dllimport) +#endif // OCLTST_ENV_BUILD + +#else +#define DLLIMPORT + +#endif // _WIN32 + +enum oclLoggingLevel { + OCLTEST_LOG_ALWAYS, + OCLTEST_LOG_VERBOSE, +}; + +extern DLLIMPORT void oclTestLog(oclLoggingLevel logLevel, const char* fmt, + ...); +extern DLLIMPORT void oclTestSetLogLevel(int level); +extern DLLIMPORT void oclTestEnableLogToFile(const char* filename); + +#endif // OCLLOG_H_ diff --git a/opencl/tests/ocltst/include/OCLTest.h b/opencl/tests/ocltst/include/OCLTest.h new file mode 100644 index 0000000000..3547b0e336 --- /dev/null +++ b/opencl/tests/ocltst/include/OCLTest.h @@ -0,0 +1,73 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCLTEST_H_ +#define _OCLTEST_H_ + +#include + +#include "OCLWrapper.h" + +class BaseTestImp; +class OCLTestImp; +class OCLTest { + public: + virtual unsigned int getThreadUsage(void) = 0; + virtual int getNumSubTests(void) = 0; + virtual void open() = 0; + virtual void open(unsigned int test, const char* deviceName, + unsigned int architecture) = 0; + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId, unsigned int platformIndex) = 0; + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) = 0; + + virtual void run(void) = 0; + virtual unsigned int close(void) = 0; + virtual void setErrorMsg(const char* error) = 0; + virtual const char* getErrorMsg(void) = 0; + virtual bool hasErrorOccured(void) = 0; + virtual void clearError() = 0; + virtual void setDeviceId(unsigned int deviceId) = 0; + virtual void setPlatformIndex(unsigned int platformIndex) = 0; + virtual OCLTestImp* toOCLTestImp() = 0; + virtual BaseTestImp* toBaseTestImp() = 0; + virtual float getPerfInfo() = 0; + virtual void clearPerfInfo(void) = 0; + + virtual void setIterationCount(int cnt) = 0; + virtual void useCPU() = 0; + // Having this return true will allow the creation of the + // test to be cached in between runs and will only be + // deleted after all the tests are finished running. + // This defaults to false as not many tests are modified + // to use it. + // FIXME: Switch all tests to support caching. + virtual bool cache_test() { return true; } + + std::string testDescString; + void resetDescString(void) { testDescString.clear(); } + + virtual ~OCLTest(){}; +}; + +#endif // _OCLTEST_H_ diff --git a/opencl/tests/ocltst/include/OCLTestList.h b/opencl/tests/ocltst/include/OCLTestList.h new file mode 100644 index 0000000000..1189d6310d --- /dev/null +++ b/opencl/tests/ocltst/include/OCLTestList.h @@ -0,0 +1,43 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCLMODULE_H_ +#define _OCLMODULE_H_ + +#ifdef _WIN32 +#define OCLLCONV __cdecl +#endif +#ifdef __linux__ +#define OCLLCONV +#endif + +class OCLTest; + +// +// exported function pointer typedefs +// +typedef unsigned int(OCLLCONV *TestCountFuncPtr)(void); +typedef const char *(OCLLCONV *TestNameFuncPtr)(unsigned int); +typedef OCLTest *(OCLLCONV *CreateTestFuncPtr)(unsigned int); +typedef void(OCLLCONV *DestroyTestFuncPtr)(OCLTest *); +typedef unsigned int(OCLLCONV *TestVersionFuncPtr)(void); +typedef const char *(OCLLCONV *TestLibNameFuncPtr)(void); + +#endif // _OCLMODULE_H_ diff --git a/opencl/tests/ocltst/include/OCLTestUtils.h b/opencl/tests/ocltst/include/OCLTestUtils.h new file mode 100644 index 0000000000..2add76863a --- /dev/null +++ b/opencl/tests/ocltst/include/OCLTestUtils.h @@ -0,0 +1,31 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef OCLTESTUTILS_H_ +#define OCLTESTUTILS_H_ +#include + +// @param FN Name of the file to be loaded +// @param S String to store the loaded file +// @brief Load file to a string +// @return true on success +bool loadFile(const char* FN, std::string& S); + +#endif /* OCLTESTUTILS_H_ */ diff --git a/opencl/tests/ocltst/include/OCLWrapper.h b/opencl/tests/ocltst/include/OCLWrapper.h new file mode 100644 index 0000000000..521a5fc50f --- /dev/null +++ b/opencl/tests/ocltst/include/OCLWrapper.h @@ -0,0 +1,614 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef __OCLWrapper_H +#define __OCLWrapper_H + +#define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#define CL_USE_DEPRECATED_OPENCL_2_0_APIS +#include "CL/cl.h" +#include "CL/cl_ext.h" +#include "CL/cl_gl.h" +#include "cl_profile_amd.h" + +typedef CL_API_ENTRY cl_int(CL_API_CALL *clUnloadPlatformAMD_fn)( + cl_platform_id id); + +// Function Pointer Declarations for cl_khr_gl_sharing extension (missing in +// cl_gl.h) +typedef CL_API_ENTRY cl_int(CL_API_CALL *clGetGLContextInfoKHR_fn)( + const cl_context_properties *properties, cl_gl_context_info param_name, + size_t param_value_size, void *param_value, size_t *param_value_size_ret); + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromGLBuffer_fn)( + cl_context context, cl_mem_flags flags, unsigned int bufobj, + int *errcode_ret); + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromGLTexture_fn)( + cl_context context, cl_mem_flags flags, unsigned int texture_target, + int miplevel, unsigned int texture, cl_int *errcode_ret); + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromGLTexture2D_fn)( + cl_context context, cl_mem_flags flags, unsigned int texture_target, + int miplevel, unsigned int texture, cl_int *errcode_ret); + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromGLRenderbuffer_fn)( + cl_context context, cl_mem_flags flags, unsigned int renderbuffer, + cl_int *errcode_ret); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *clGetGLObjectInfo_fn)( + cl_mem memobj, cl_gl_object_type *gl_object_type, + unsigned int *gl_object_name); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *clGetGLTextureInfo_fn)( + cl_mem memobj, cl_gl_texture_info param_name, size_t param_value_size, + void *param_value, size_t *param_value_size_ret); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueAcquireGLObjects_fn)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueReleaseGLObjects_fn)( + cl_command_queue command_queue, cl_uint num_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + +// Function Pointer Declarations for performance counters +typedef CL_API_ENTRY cl_perfcounter_amd(CL_API_CALL *clCreatePerfCounterAMD_fn)( + cl_device_id device, cl_perfcounter_property *properties, + cl_int *errcode_ret); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueBeginPerfCounterAMD_fn)( + cl_command_queue command_queue, cl_uint num_perf_counters, + cl_perfcounter_amd *perf_counters, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueEndPerfCounterAMD_fn)( + cl_command_queue command_queue, cl_uint num_perf_counters, + cl_perfcounter_amd *perf_counters, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *clGetPerfCounterInfoAMD_fn)( + cl_perfcounter_amd perf_counter, cl_perfcounter_info param_name, + size_t param_value_size, void *param_value, size_t *param_value_size_ret); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *clReleasePerfCounterAMD_fn)( + cl_perfcounter_amd perf_counter); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *clRetainPerfCounterAMD_fn)( + cl_perfcounter_amd perf_counter); + +typedef CL_API_ENTRY cl_int(CL_API_CALL *clSetDeviceClockModeAMD_fn)( + cl_device_id device, + cl_set_device_clock_mode_input_amd set_clock_mode_input, + cl_set_device_clock_mode_output_amd *set_clock_mode_Output); + +class OCLWrapper { + public: + OCLWrapper(); + + ~OCLWrapper() {} + + // All OCL APIs are declared in the order they appear in cl.h + + cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, + cl_uint *num_platforms); + + 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); + + cl_int clGetDeviceIDs(cl_platform_id platform, cl_device_type device_type, + cl_uint num_entries, cl_device_id *devices, + cl_uint *num_devices); + + 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); + + cl_context clCreateContext(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); + + cl_context clCreateContextFromType( + 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); + + cl_int clRetainContext(cl_context context); + + cl_int clReleaseContext(cl_context context); + + 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); + + cl_command_queue clCreateCommandQueue(cl_context context, cl_device_id device, + cl_command_queue_properties properties, + cl_int *errcode_ret); + + cl_int clRetainCommandQueue(cl_command_queue command_queue); + + cl_int clReleaseCommandQueue(cl_command_queue command_queue); + + cl_int clGetCommandQueueInfo(cl_command_queue command_queue, + cl_command_queue_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret); + + cl_mem clCreateBuffer(cl_context context, cl_mem_flags flags, size_t size, + void *host_ptr, cl_int *errcode_ret); + + cl_mem clCreateImage2D(cl_context context, cl_mem_flags flags, + const cl_image_format *image_format, + size_t image_width, size_t image_height, + size_t image_row_pitch, void *host_ptr, + cl_int *errcode_ret); + + cl_mem clCreateImage3D(cl_context context, cl_mem_flags flags, + const cl_image_format *image_format, + size_t image_width, size_t image_height, + size_t image_depth, size_t image_row_pitch, + size_t image_slice_pitch, void *host_ptr, + cl_int *errcode_ret); + + cl_int clRetainMemObject(cl_mem memobj); + + cl_int clReleaseMemObject(cl_mem memobj); + + 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); + + cl_int clGetMemObjectInfo(cl_mem memobj, cl_mem_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret); + + cl_int clGetImageInfo(cl_mem image, cl_image_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret); + + cl_sampler clCreateSampler(cl_context context, cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, cl_int *errcode_ret); + + cl_int clRetainSampler(cl_sampler sampler); + + cl_int clReleaseSampler(cl_sampler sampler); + + cl_int clGetSamplerInfo(cl_sampler sampler, cl_sampler_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret); + + cl_program clCreateProgramWithSource(cl_context context, cl_uint count, + const char **strings, + const size_t *lengths, + cl_int *errcode_ret); + + 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); + + cl_int clRetainProgram(cl_program program); + + cl_int clReleaseProgram(cl_program program); + + 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); + + cl_int clCompileProgram( + cl_program program, cl_uint num_devices, const cl_device_id *device_list, + const char *options, cl_uint num_input_headers, + const cl_program *input_headers, const char **header_include_names, + void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), + void *user_data); + + cl_program clLinkProgram(cl_context context, cl_uint num_devices, + const cl_device_id *device_list, const char *options, + cl_uint num_input_programs, + const cl_program *input_programs, + void(CL_CALLBACK *pfn_notify)(cl_program program, + void *user_data), + void *user_data, cl_int *errcode_ret); + + cl_int clUnloadCompiler(void); + + cl_int clUnloadPlatform(cl_platform_id); + + 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); + + 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); + + cl_kernel clCreateKernel(cl_program program, const char *kernel_name, + cl_int *errcode_ret); + + cl_int clCreateKernelsInProgram(cl_program program, cl_uint num_kernels, + cl_kernel *kernels, cl_uint *num_kernels_ret); + + cl_int clRetainKernel(cl_kernel kernel); + + cl_int clReleaseKernel(cl_kernel kernel); + + cl_int clSetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, + const void *arg_value); + + cl_int clGetKernelInfo(cl_kernel kernel, cl_kernel_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret); + + 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); + + cl_int clWaitForEvents(cl_uint num_events, const cl_event *event_list); + + cl_int clGetEventInfo(cl_event evnt, cl_event_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret); + + cl_int clRetainEvent(cl_event evnt); + + cl_int clReleaseEvent(cl_event evnt); + + cl_int clGetEventProfilingInfo(cl_event evnt, cl_profiling_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret); + + cl_int clFlush(cl_command_queue command_queue); + + cl_int clFinish(cl_command_queue command_queue); + + cl_int clEnqueueReadBuffer(cl_command_queue command_queue, cl_mem buffer, + cl_bool blocking_read, size_t offset, size_t cb, + void *ptr, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *evnt); + + cl_int clEnqueueWriteBuffer(cl_command_queue command_queue, cl_mem buffer, + cl_bool blocking_write, size_t offset, size_t cb, + const void *ptr, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *evnt); + + cl_int clEnqueueCopyBuffer(cl_command_queue command_queue, cl_mem src_buffer, + cl_mem dst_buffer, size_t src_offset, + size_t dst_offset, size_t cb, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *evnt); + + cl_int clEnqueueReadImage(cl_command_queue command_queue, cl_mem image, + cl_bool blocking_read, const size_t *origin, + const size_t *region, 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 *evnt); + + cl_int clEnqueueWriteImage(cl_command_queue command_queue, cl_mem image, + cl_bool blocking_write, const size_t *origin, + const size_t *region, 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 *evnt); + + cl_int clEnqueueCopyImage(cl_command_queue command_queue, cl_mem src_image, + cl_mem dst_image, const size_t *src_origin, + const size_t *dst_origin, const size_t *region, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *evnt); + + cl_int clEnqueueCopyImageToBuffer(cl_command_queue command_queue, + cl_mem src_image, cl_mem dst_buffer, + const size_t *src_origin, + const size_t *region, size_t dst_offset, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *evnt); + + cl_int clEnqueueCopyBufferToImage(cl_command_queue command_queue, + cl_mem src_buffer, cl_mem dst_image, + size_t src_offset, const size_t *dst_origin, + const size_t *region, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *evnt); + + void *clEnqueueMapBuffer(cl_command_queue command_queue, cl_mem buffer, + cl_bool blocking_map, cl_map_flags map_flags, + size_t offset, size_t cb, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *evnt, + cl_int *errcode_ret); + + 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 *evnt, + cl_int *errcode_ret); + + 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 *evnt); + + 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 *evnt); + + cl_int clEnqueueTask(cl_command_queue command_queue, cl_kernel kernel, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *evnt); + + cl_int clEnqueueNativeKernel(cl_command_queue command_queue, + void(CL_CALLBACK *user_func)(void *), void *args, + size_t cb_args, cl_uint num_mem_objects, + const cl_mem *mem_list, + const void **args_mem_loc, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *evnt); + + cl_int clEnqueueMarker(cl_command_queue command_queue, cl_event *evnt); + + cl_int clEnqueueMarkerWithWaitList(cl_command_queue command_queue, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *evnt); + + cl_int clEnqueueWaitForEvents(cl_command_queue command_queue, + cl_uint num_events, const cl_event *event_list); + + cl_int clEnqueueBarrier(cl_command_queue command_queue); + + void *clGetExtensionFunctionAddress(const char *func_name); + + cl_int clEnqueueReadBufferRect( + cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, + const size_t *buffer_origin, const size_t *host_origin, + const size_t *region, size_t buffer_row_pitch, size_t buffer_slice_pitch, + size_t host_row_pitch, size_t host_slice_pitch, void *ptr, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *evnt); + + cl_int clEnqueueWriteBufferRect( + cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, + const size_t *buffer_origin, const size_t *host_origin, + const size_t *region, size_t buffer_row_pitch, size_t buffer_slice_pitch, + size_t host_row_pitch, size_t host_slice_pitch, const void *ptr, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *evnt); + + cl_int clEnqueueCopyBufferRect( + cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, + const size_t *src_origin, const size_t *dst_origin, const size_t *region, + size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, + size_t dst_slice_pitch, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *evnt); + + 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); + + cl_mem clCreateSubBuffer(cl_mem mem, cl_mem_flags flags, + cl_buffer_create_type buffer_create_type, + const void *buffer_create_info, cl_int *errcode_ret); + + cl_int clSetEventCallback( + cl_event event, cl_int command_exec_callback_type, + void(CL_CALLBACK *pfn_event_notify)(cl_event event, + cl_int event_command_exec_status, + void *user_data), + void *user_data); + + cl_int clEnqueueFillImage(cl_command_queue command_queue, cl_mem image, + void *ptr, const size_t *origin, + const size_t *region, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *evnt); + + cl_int clUnloadPlatformAMD(cl_platform_id id); + + cl_int clEnqueueWaitSignalAMD(cl_command_queue command_queue, + cl_mem mem_object, cl_uint value, + cl_uint num_events, + const cl_event *event_wait_list, + cl_event *event); + + cl_int clEnqueueWriteSignalAMD(cl_command_queue command_queue, + cl_mem mem_object, cl_uint value, + cl_ulong offset, cl_uint num_events, + const cl_event *event_list, cl_event *event); + + cl_int clEnqueueMakeBuffersResidentAMD( + cl_command_queue command_queue, cl_uint num_mem_objs, cl_mem *mem_objects, + cl_bool blocking_make_resident, cl_bus_address_amd *bus_addresses, + cl_uint num_events, const cl_event *event_list, cl_event *event); + + cl_int clEnqueueMigrateMemObjects(cl_command_queue command_queue, + cl_uint num_mem_objects, + const cl_mem *mem_objects, + cl_mem_migration_flags flags, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); + + // CL-GL Extension: cl_khr_gl_sharing + cl_int clGetGLContextInfoKHR(const cl_context_properties *properties, + cl_gl_context_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret); + + cl_mem clCreateFromGLBuffer(cl_context context, cl_mem_flags flags, + unsigned int bufobj, int *errcode_ret); + + cl_mem clCreateFromGLTexture(cl_context context, cl_mem_flags flags, + unsigned int texture_target, int miplevel, + unsigned int texture, cl_int *errcode_ret); + + cl_mem clCreateFromGLTexture2D(cl_context context, cl_mem_flags flags, + unsigned int texture_target, int miplevel, + unsigned int texture, cl_int *errcode_ret); + + cl_mem clCreateFromGLRenderbuffer(cl_context context, cl_mem_flags flags, + unsigned int renderbuffer, + cl_int *errcode_ret); + + cl_int clGetGLObjectInfo(cl_mem memobj, cl_gl_object_type *gl_object_type, + unsigned int *gl_object_name); + + cl_int clGetGLTextureInfo(cl_mem memobj, cl_gl_texture_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret); + + cl_int clEnqueueAcquireGLObjects(cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem *mem_objects, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); + + cl_int clEnqueueReleaseGLObjects(cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem *mem_objects, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); + +#if defined(CL_VERSION_2_0) + cl_command_queue clCreateCommandQueueWithProperties( + cl_context context, cl_device_id device, + const cl_queue_properties *properties, cl_int *errcode_ret); + + void *clSVMAlloc(cl_context context, cl_svm_mem_flags flags, size_t size, + cl_uint alignment); + + void clSVMFree(cl_context context, void *svm_pointer); + + cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, + cl_map_flags flags, void *svm_ptr, size_t size, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + + cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + + cl_int clEnqueueSVMMemFill(cl_command_queue command_queue, void *svm_ptr, + const void *pattern, size_t pattern_size, + size_t size, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event); + + cl_int clSetKernelArgSVMPointer(cl_kernel kernel, cl_uint arg_index, + const void *arg_value); + + cl_mem clCreatePipe(cl_context context, cl_mem_flags flags, + cl_uint packet_size, cl_uint num_packets, + const cl_pipe_properties *properties, + cl_int *errcode_ret); + + cl_int clGetPipeInfo(cl_mem pipe, cl_pipe_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret); + +#endif + + cl_perfcounter_amd clCreatePerfCounterAMD(cl_device_id device, + cl_perfcounter_property *properties, + cl_int *errcode_ret); + + cl_int clEnqueueBeginPerfCounterAMD(cl_command_queue command_queue, + cl_uint num_perf_counters, + cl_perfcounter_amd *perf_counters, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); + + cl_int clEnqueueEndPerfCounterAMD(cl_command_queue command_queue, + cl_uint num_perf_counters, + cl_perfcounter_amd *perf_counters, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); + + cl_int clGetPerfCounterInfoAMD(cl_perfcounter_amd perf_counter, + cl_perfcounter_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret); + + cl_int clReleasePerfCounterAMD(cl_perfcounter_amd perf_counter); + + cl_int clRetainPerfCounterAMD(cl_perfcounter_amd perf_counter); + + cl_int clSetDeviceClockModeAMD( + cl_device_id device, + cl_set_device_clock_mode_input_amd set_clock_mode_input, + cl_set_device_clock_mode_output_amd *set_clock_mode_Output); + + private: + clEnqueueWaitSignalAMD_fn clEnqueueWaitSignalAMD_ptr; + clEnqueueWriteSignalAMD_fn clEnqueueWriteSignalAMD_ptr; + clEnqueueMakeBuffersResidentAMD_fn clEnqueueMakeBuffersResidentAMD_ptr; + + // Unload the platform + clUnloadPlatformAMD_fn clUnloadPlatformAMD_ptr; + + // CL-GL Extension: cl_khr_gl_sharing + clGetGLContextInfoKHR_fn clGetGLContextInfoKHR_ptr; + clCreateFromGLBuffer_fn clCreateFromGLBuffer_ptr; + clCreateFromGLTexture_fn clCreateFromGLTexture_ptr; + clCreateFromGLTexture2D_fn clCreateFromGLTexture2D_ptr; + clCreateFromGLRenderbuffer_fn clCreateFromGLRenderbuffer_ptr; + clGetGLObjectInfo_fn clGetGLObjectInfo_ptr; + clGetGLTextureInfo_fn clGetGLTextureInfo_ptr; + clEnqueueAcquireGLObjects_fn clEnqueueAcquireGLObjects_ptr; + clEnqueueReleaseGLObjects_fn clEnqueueReleaseGLObjects_ptr; + + // Performance counters + clCreatePerfCounterAMD_fn clCreatePerfCounterAMD_ptr; + clEnqueueBeginPerfCounterAMD_fn clEnqueueBeginPerfCounterAMD_ptr; + clEnqueueEndPerfCounterAMD_fn clEnqueueEndPerfCounterAMD_ptr; + clGetPerfCounterInfoAMD_fn clGetPerfCounterInfoAMD_ptr; + clReleasePerfCounterAMD_fn clReleasePerfCounterAMD_ptr; + clRetainPerfCounterAMD_fn clRetainPerfCounterAMD_ptr; + // Set clockMode + clSetDeviceClockModeAMD_fn clSetDeviceClockModeAMD_ptr; +}; + +#endif diff --git a/opencl/tests/ocltst/module/common/BaseTestImp.cpp b/opencl/tests/ocltst/module/common/BaseTestImp.cpp new file mode 100644 index 0000000000..c9121088ca --- /dev/null +++ b/opencl/tests/ocltst/module/common/BaseTestImp.cpp @@ -0,0 +1,185 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "BaseTestImp.h" + +#include +#include +#include + +#include + +///////////////////////////////////////////////////////////////////////////// + +static unsigned int crcinit(unsigned int crc); +static int initializeSeed(void); + +///////////////////////////////////////////////////////////////////////////// + +BaseTestImp::BaseTestImp() + : _numSubTests(0), _openTest(0), _deviceName(NULL), _architecture(0) { + _cpu = false; + unsigned int i; + for (i = 0; i < 256; i++) { + _crctab[i] = crcinit(i << 24); + } + _crcword = ~0; + _deviceId = 0; + _platformIndex = 0; + _perfInfo = 0.0f; + +#ifdef __linux__ // + _useThreads = 0; // disable threads on linux +#else + _useThreads = 1; // if available on platform +#endif + + clearError(); +} + +void BaseTestImp::checkComplib(unsigned int test, const char *deviceName, + unsigned int architecture) { + BaseTestImp::open(); + devices_ = 0; + deviceCount_ = 0; + context_ = 0; + program_ = 0; + kernel_ = 0; + type_ = CL_DEVICE_TYPE_GPU; + + cl_uint numPlatforms = 0; + error_ = clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetPlatformIDs failed"); + CHECK_RESULT((numPlatforms == 0), "No platform found"); + + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + + cl_platform_id platform = 0; +#if 0 + for(unsigned int i = 0; i < numPlatforms; ++i) + { + char buff[200]; + error_ = clGetPlatformInfo(platforms[i],CL_PLATFORM_VENDOR, sizeof(buff), buff, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + if(strcmp(buff, "Advanced Micro Devices, Inc.") == 0) + { + platform = platforms[i]; + break; + } + } +#endif + platform = platforms[_platformIndex]; + + delete[] platforms; + + CHECK_RESULT((platform == 0), "AMD Platform not found"); + + error_ = clGetDeviceIDs(platform, type_, 0, NULL, &deviceCount_); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs() failed"); + + devices_ = new cl_device_id[deviceCount_]; + error_ = clGetDeviceIDs(platform, type_, deviceCount_, devices_, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs() failed"); + + char device_string[200]; + clGetDeviceInfo(devices_[_deviceId], CL_DRIVER_VERSION, sizeof(device_string), + &device_string, NULL); + if (strstr(device_string, "LC")) { + printf("Skipping test since it does not run with LC\n"); + failed_ = true; + return; + } + return; +} + +BaseTestImp::~BaseTestImp() {} + +void BaseTestImp::open() { + _crcword = 0; + clearError(); +} +void BaseTestImp::open(unsigned int test, const char *deviceName, + unsigned int architecture) { + open(); +} + +unsigned int BaseTestImp::close() { return _crcword; } + +unsigned int BaseTestImp::getThreadUsage(void) { return _useThreads; } + +int BaseTestImp::getNumSubTests(void) { return _numSubTests; } + +void BaseTestImp::setDeviceName(const char *name) { _deviceName = name; } + +const char *BaseTestImp::getDeviceName() { return _deviceName; } + +float BaseTestImp::getPerfInfo(void) { return _perfInfo; } + +void BaseTestImp::clearPerfInfo(void) { _perfInfo = 0.0; } + +void BaseTestImp::setDeviceId(unsigned int deviceId) { _deviceId = deviceId; } + +void BaseTestImp::setIterationCount(int cnt) { _iterationCnt = cnt; } + +unsigned int BaseTestImp::getDeviceId() { return _deviceId; } + +void BaseTestImp::setPlatformIndex(unsigned int platformIndex) { + _platformIndex = platformIndex; +} + +unsigned int BaseTestImp::getPlatformIndex() { return _platformIndex; } + +void BaseTestImp::setErrorMsg(const char *error) { + _errorFlag = true; + _errorMsg.assign((const char *)error); +} + +const char *BaseTestImp::getErrorMsg() { return _errorMsg.c_str(); } + +bool BaseTestImp::hasErrorOccured() { return _errorFlag; } + +void BaseTestImp::clearError() { + _errorFlag = false; + _errorMsg.clear(); +} + +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// +// Same CRC32 as used by ogtst +// +static const unsigned int CRCMASK = 0x04c11db7; + +static unsigned int crcinit(unsigned int crc) { + int i; + unsigned int ans = crc; + + for (i = 0; i < 8; i++) { + if (ans & 0x80000000) { + ans = (ans << 1) ^ CRCMASK; + } else { + ans <<= 1; + } + } + return (ans); +} diff --git a/opencl/tests/ocltst/module/common/CMakeLists.txt b/opencl/tests/ocltst/module/common/CMakeLists.txt new file mode 100644 index 0000000000..888151b416 --- /dev/null +++ b/opencl/tests/ocltst/module/common/CMakeLists.txt @@ -0,0 +1,35 @@ +set(COMMON_SOURCES + ${OCLTST_DIR}/module/common/BaseTestImp.cpp + ${OCLTST_DIR}/module/common/OCLTestImp.cpp + ${OCLTST_DIR}/module/common/OCLTestListImp.cpp + ${OCLTST_DIR}/module/common/OCLTestUtils.cpp + ${OCLTST_DIR}/module/common/OCLThread.cpp + ${OCLTST_DIR}/module/common/OCLWrapper.cpp + ${OCLTST_DIR}/module/common/Timer.cpp) + +add_library(Common OBJECT ${COMMON_SOURCES}) + +set_target_properties(Common PROPERTIES + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + POSITION_INDEPENDENT_CODE ON) + +target_compile_definitions(Common + PUBLIC + CL_TARGET_OPENCL_VERSION=220) + +if(EMU_ENV) + target_compile_definitions(Common + PUBLIC + EMU_ENV=1) +endif() + +target_include_directories(Common + PUBLIC + ${OPENCL_ICD_LOADER_HEADERS_DIR} + ${OCLTST_DIR}/include + ${OCLTST_DIR}/module/common + ${OCLTST_DIR}/module/include + ${PROJECT_SOURCE_DIR}/amdocl) #TODO remove cl_profile_amd.h dependency + diff --git a/opencl/tests/ocltst/module/common/OCLGLCommon.cpp b/opencl/tests/ocltst/module/common/OCLGLCommon.cpp new file mode 100644 index 0000000000..affc74d711 --- /dev/null +++ b/opencl/tests/ocltst/module/common/OCLGLCommon.cpp @@ -0,0 +1,175 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGLCommon.h" + +#include +#include + +void OCLGLCommon::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + // OpenCL Initialization + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test (%d)", error_); + + char name[1024] = {0}; + size_t size = 0; + + if (deviceId >= deviceCount_) { + _errorFlag = true; + return; + } + + // Check that the device supports CL/GL interop extension + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_EXTENSIONS, 1024, + name, &size); + if (!strstr(name, "cl_khr_gl_sharing")) { + printf("KHR GL sharing extension is required for this test!\n"); + _errorFlag = true; + return; + } + + // OpenGL Initialization + bool retVal = initializeGLContext(hGL_); + CHECK_RESULT((retVal == CL_SUCCESS), "Error opening test (%d)", error_); + + createCLContextFromGLContext(hGL_); +} + +bool OCLGLCommon::IsGLEnabled(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + bool bResult = initializeGLContext(hGL_); + if (bResult) { + deleteGLContext(hGL_); + } + OCLTestImp::close(); + return bResult; +} + +void OCLGLCommon::gluPerspective(double fovy, double aspect, double zNear, + double zFar) { + double xmin, xmax, ymin, ymax; + ymax = zNear * tan(fovy * 3.149 / 360.0); + ymin = -ymax; + xmin = ymin * aspect; + xmax = ymax * aspect; + glFrustum(xmin, xmax, ymin, ymax, zNear, zFar); +} + +unsigned int OCLGLCommon::close(void) { + makeCurrent(hGL_); + unsigned int retVal = OCLTestImp::close(); + deleteGLContext(hGL_); + return retVal; +} + +void OCLGLCommon::dumpBuffer(float *pBuffer, const char fileName[], + unsigned int dimSize) { + if (pBuffer) { + FILE *f = fopen(fileName, "w"); + if (NULL != f) { + unsigned int i, j; + for (i = 0; i < dimSize; i++) { + for (j = 0; j < dimSize; j++) { + fprintf(f, "%e,\t", pBuffer[i * (dimSize) + j]); + } + fprintf(f, "\n"); + } + fclose(f); + } + } +} + +bool OCLGLCommon::createGLFragmentProgramFromSource(const char *source, + GLuint &shader, + GLuint &program) { + shader = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(shader, 1, &source, NULL); + glCompileShader(shader); + printShaderInfoLog(shader); + program = glCreateProgram(); + glAttachShader(program, shader); + glLinkProgram(program); + printProgramInfoLog(program); + + return program != 0; +} + +int OCLGLCommon::printOglError(char *file, int line) { + // + // Returns 1 if an OpenGL error occurred, 0 otherwise. + // + GLenum glErr; + int retCode = 0; + + glErr = glGetError(); + if (glErr != GL_NO_ERROR) { + printf("glError in file %s @ line %d: %d\n", file, line, glErr); + retCode = 1; + } + return retCode; +} + +// +// Print out the information log for a shader object +// +void OCLGLCommon::printShaderInfoLog(GLuint shader) { + int infologLength = 0; + int charsWritten = 0; + GLchar *infoLog; + + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infologLength); + + if (infologLength > 0) { + infoLog = (GLchar *)malloc(infologLength); + if (infoLog == NULL) { + printf("ERROR: Could not allocate InfoLog buffer\n"); + return; + } + glGetShaderInfoLog(shader, infologLength, &charsWritten, infoLog); + printf("Shader InfoLog:\n%s\n\n", infoLog); + free(infoLog); + } +} + +void OCLGLCommon::printProgramInfoLog(GLuint program) { + int infologLength = 0; + int charsWritten = 0; + GLchar *infoLog; + + // printOpenGLError(); // Check for OpenGL errors + + glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infologLength); + + // printOpenGLError(); // Check for OpenGL errors + + if (infologLength > 0) { + infoLog = (GLchar *)malloc(infologLength); + if (infoLog == NULL) { + printf("ERROR: Could not allocate InfoLog buffer\n"); + exit(1); + } + glGetProgramInfoLog(program, infologLength, &charsWritten, infoLog); + printf("Program InfoLog:\n%s\n\n", infoLog); + free(infoLog); + } + // printOpenGLError(); // Check for OpenGL errors +} diff --git a/opencl/tests/ocltst/module/common/OCLGLCommon.h b/opencl/tests/ocltst/module/common/OCLGLCommon.h new file mode 100644 index 0000000000..f9ed23069a --- /dev/null +++ b/opencl/tests/ocltst/module/common/OCLGLCommon.h @@ -0,0 +1,80 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GL_COMMON_H_ +#define _OCL_GL_COMMON_H_ + +#include +#include +#include + +#include +#include + +#include "OCLTestImp.h" + +typedef struct OCLGLHandle_* OCLGLHandle; + +#define printOpenGLError() OCLGLCommon::printOglError(__FILE__, __LINE__) + +class OCLGLCommon : public OCLTestImp { + public: + ///////////////////////////////////////// + // private initialization and clean-up // + ///////////////////////////////////////// + OCLGLCommon(); + virtual ~OCLGLCommon(); + /////////////////////// + // virtual interface // + /////////////////////// + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual unsigned int close(void); + static void gluPerspective(double fovy, double aspect, double zNear, + double zFar); + static void dumpBuffer(float* pBuffer, const char fileName[], + unsigned int dimSize); + static int printOglError(char* file, int line); + static bool createGLFragmentProgramFromSource(const char* source, + GLuint& shader, + GLuint& program); + static void printShaderInfoLog(GLuint shader); + static void printProgramInfoLog(GLuint program); + + protected: + const OCLGLHandle getGLHandle() { return hGL_; } + void makeCurrent(const OCLGLHandle hGL); + void getCLContextPropertiesFromGLContext(const OCLGLHandle hGL, + cl_context_properties properties[7]); + bool createGLContext(OCLGLHandle& hGL); + void destroyGLContext(OCLGLHandle& hGL); + bool IsGLEnabled(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + + private: + bool initializeGLContext(OCLGLHandle& hGL); + void deleteGLContext(OCLGLHandle& hGL); + bool checkAssociationDeviceWithGLContext(OCLGLHandle& hGL); + void createCLContextFromGLContext(OCLGLHandle& hGL); + + OCLGLHandle hGL_; +}; + +#endif // _OCL_GL_COMMON_H_ diff --git a/opencl/tests/ocltst/module/common/OCLGLCommonLinux.cpp b/opencl/tests/ocltst/module/common/OCLGLCommonLinux.cpp new file mode 100644 index 0000000000..07bb9b67c0 --- /dev/null +++ b/opencl/tests/ocltst/module/common/OCLGLCommonLinux.cpp @@ -0,0 +1,239 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGLCommon.h" + +struct OCLGLHandle_ { + static Display* display; + static XVisualInfo* vInfo; + static int referenceCount; + GLXContext context; + Window window; + Colormap cmap; +}; + +Display* OCLGLHandle_::display = NULL; +XVisualInfo* OCLGLHandle_::vInfo = NULL; +int OCLGLHandle_::referenceCount = 0; + +OCLGLCommon::OCLGLCommon() { + hGL_ = new OCLGLHandle_; + + hGL_->context = NULL; + hGL_->window = 0; + hGL_->cmap = 0; +} + +OCLGLCommon::~OCLGLCommon() { destroyGLContext(hGL_); } + +void OCLGLCommon::destroyGLContext(OCLGLHandle& hGL) { + deleteGLContext(hGL); + delete hGL; + hGL = NULL; +} + +void OCLGLCommon::deleteGLContext(OCLGLHandle& hGL) { + if (hGL->display != NULL) { + glXMakeCurrent(hGL->display, None, NULL); + if (hGL->cmap) { + XFreeColormap(hGL->display, hGL->cmap); + hGL->cmap = 0; + } + if (hGL->window) { + XDestroyWindow(hGL->display, hGL->window); + hGL->window = 0; + } + if (hGL->context) { + glXDestroyContext(hGL->display, hGL->context); + hGL->context = NULL; + } + + hGL->referenceCount--; + if (hGL->referenceCount == 0) { + XCloseDisplay(hGL->display); + hGL->display = NULL; + + XFree(hGL->vInfo); + hGL->vInfo = NULL; + } + } +} + +bool OCLGLCommon::createGLContext(OCLGLHandle& hGL) { + hGL = new OCLGLHandle_; + return initializeGLContext(hGL); +} + +bool OCLGLCommon::initializeGLContext(OCLGLHandle& hGL) { + if (hGL->display == NULL) { + hGL->display = XOpenDisplay(NULL); + if (hGL->display == NULL) { + printf("XOpenDisplay() failed\n"); + return false; + } + } + if (hGL->vInfo == NULL) { + int dblBuf[] = {GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, + 1, GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, + 12, GLX_DOUBLEBUFFER, None}; + + hGL->vInfo = + glXChooseVisual(hGL->display, DefaultScreen(hGL->display), dblBuf); + if (hGL->vInfo == NULL) { + printf("glXChooseVisual() failed\n"); + return false; + } + } + hGL->referenceCount++; + + hGL->context = glXCreateContext(hGL->display, hGL->vInfo, None, True); + if (hGL->context == NULL) { + printf("glXCreateContext() failed\n"); + return false; + } + + XSetWindowAttributes swa = {0}; + hGL->cmap = XCreateColormap(hGL->display, + RootWindow(hGL->display, hGL->vInfo->screen), + hGL->vInfo->visual, AllocNone); + swa.colormap = hGL->cmap; + hGL->window = XCreateWindow( + hGL->display, RootWindow(hGL->display, hGL->vInfo->screen), 0, 0, 640, + 480, 0, hGL->vInfo->depth, InputOutput, hGL->vInfo->visual, + CWBorderPixel | CWColormap | CWEventMask, &swa); + + Bool glErr = glXMakeCurrent(hGL->display, hGL->window, hGL->context); + if (False == glErr) { + return false; + } + + if (!checkAssociationDeviceWithGLContext(hGL)) { + deleteGLContext(hGL); + return false; + } + return true; +} + +bool OCLGLCommon::checkAssociationDeviceWithGLContext(OCLGLHandle& hGL) { + bool ret = false; + size_t devicesSize = 0; + cl_context_properties properties[] = {CL_CONTEXT_PLATFORM, + (cl_context_properties)platform_, + CL_GL_CONTEXT_KHR, + (cl_context_properties)hGL->context, + CL_GLX_DISPLAY_KHR, + (cl_context_properties)hGL->display, + 0}; + + error_ = _wrapper->clGetGLContextInfoKHR( + properties, CL_DEVICES_FOR_GL_CONTEXT_KHR, 0, NULL, &devicesSize); + if (error_ != CL_SUCCESS) { + printf("clGetGLContextInfoKHR failed (%d)\n", error_); + return false; + } + + cl_uint numDevices = (cl_uint)devicesSize / sizeof(cl_device_id); + cl_device_id* interopDevices = (cl_device_id*)malloc(devicesSize); + + error_ = + _wrapper->clGetGLContextInfoKHR(properties, CL_DEVICES_FOR_GL_CONTEXT_KHR, + devicesSize, interopDevices, NULL); + if (error_ != CL_SUCCESS) { + printf("clGetGLContextInfoKHR failed (%d)\n", error_); + free(interopDevices); + return false; + } + + // Check that current device can be associated with OpenGL context + for (unsigned int i = 0; i < numDevices; i++) { + if (interopDevices[i] == devices_[_deviceId]) { + ret = true; + break; + } + } + + free(interopDevices); + return ret; +} + +void OCLGLCommon::createCLContextFromGLContext(OCLGLHandle& hGL) { + cl_context_properties properties[] = {CL_CONTEXT_PLATFORM, + (cl_context_properties)platform_, + CL_GL_CONTEXT_KHR, + (cl_context_properties)hGL->context, + CL_GLX_DISPLAY_KHR, + (cl_context_properties)hGL->display, + 0}; + + // Release current command queue + if (cmdQueues_[_deviceId]) { + error_ = _wrapper->clReleaseCommandQueue(cmdQueues_[_deviceId]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseCommandQueue() failed"); + } + + // Release current context + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), "clReleaseContext() failed"); + } + + // Create new CL context from GL context + context_ = + clCreateContext(properties, 1, &devices_[_deviceId], NULL, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateContext() failed (%d)", error_); + + // Create command queue for new context + cmdQueues_[_deviceId] = + _wrapper->clCreateCommandQueue(context_, devices_[_deviceId], 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueue() failed (%d)", + error_); + + // GLEW versions 1.13.0 and earlier do not fetch all GL function pointers + // without glewExperimental set. + glewExperimental = GL_TRUE; + GLenum glErr = glewInit(); + CHECK_RESULT((glErr != GLEW_OK), "glewInit() failed: %s", + glewGetErrorString(glErr)); +} + +void OCLGLCommon::makeCurrent(OCLGLHandle hGL) { + if (hGL == NULL) { + if (hGL_ != NULL) { + glXMakeCurrent(hGL_->display, None, NULL); + } + } else { + bool ret = glXMakeCurrent(hGL->display, hGL->window, hGL->context); + assert(ret && "glXMakeCurrent failed!"); + } +} + +void OCLGLCommon::getCLContextPropertiesFromGLContext( + const OCLGLHandle hGL, cl_context_properties properties[7]) { + if (!properties) return; + + properties[0] = CL_CONTEXT_PLATFORM; + properties[1] = (cl_context_properties)platform_; + properties[2] = CL_GL_CONTEXT_KHR; + properties[3] = (cl_context_properties)hGL->context; + properties[4] = CL_GLX_DISPLAY_KHR; + properties[5] = (cl_context_properties)hGL->display; + properties[6] = 0; +} diff --git a/opencl/tests/ocltst/module/common/OCLGLCommonWindows.cpp b/opencl/tests/ocltst/module/common/OCLGLCommonWindows.cpp new file mode 100644 index 0000000000..b5869da15c --- /dev/null +++ b/opencl/tests/ocltst/module/common/OCLGLCommonWindows.cpp @@ -0,0 +1,239 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGLCommon.h" + +struct OCLGLHandle_ { + HDC hdc; + HGLRC hglrc; +}; + +OCLGLCommon::OCLGLCommon() { + hGL_ = new OCLGLHandle_; + + hGL_->hdc = NULL; + hGL_->hglrc = NULL; +} + +OCLGLCommon::~OCLGLCommon() { destroyGLContext(hGL_); } + +void OCLGLCommon::destroyGLContext(OCLGLHandle& hGL) { + deleteGLContext(hGL); + delete hGL; + hGL = NULL; +} + +void OCLGLCommon::deleteGLContext(OCLGLHandle& hGL) { + wglMakeCurrent(NULL, NULL); + if (hGL->hglrc) { + wglDeleteContext(hGL->hglrc); + hGL->hglrc = NULL; + } + if (hGL->hdc) { + DeleteDC(hGL->hdc); + hGL->hdc = NULL; + } +} + +bool OCLGLCommon::createGLContext(OCLGLHandle& hGL) { + hGL = new OCLGLHandle_; + return initializeGLContext(hGL); +} + +bool OCLGLCommon::initializeGLContext(OCLGLHandle& hGL) { + BOOL glErr = FALSE; + DISPLAY_DEVICE dispDevice; + DWORD deviceNum; + int pfmt; + PIXELFORMATDESCRIPTOR pfd; + pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); + pfd.nVersion = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.cColorBits = 24; + pfd.cRedBits = 8; + pfd.cRedShift = 0; + pfd.cGreenBits = 8; + pfd.cGreenShift = 0; + pfd.cBlueBits = 8; + pfd.cBlueShift = 0; + pfd.cAlphaBits = 8; + pfd.cAlphaShift = 0; + pfd.cAccumBits = 0; + pfd.cAccumRedBits = 0; + pfd.cAccumGreenBits = 0; + pfd.cAccumBlueBits = 0; + pfd.cAccumAlphaBits = 0; + pfd.cDepthBits = 24; + pfd.cStencilBits = 8; + pfd.cAuxBuffers = 0; + pfd.iLayerType = PFD_MAIN_PLANE; + pfd.bReserved = 0; + pfd.dwLayerMask = 0; + pfd.dwVisibleMask = 0; + pfd.dwDamageMask = 0; + + dispDevice.cb = sizeof(DISPLAY_DEVICE); + for (deviceNum = 0; EnumDisplayDevices(NULL, deviceNum, &dispDevice, 0); + deviceNum++) { + if (dispDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) { + continue; + } + + hGL->hdc = CreateDC(NULL, dispDevice.DeviceName, NULL, NULL); + if (!hGL->hdc) { + continue; + } + + pfmt = ChoosePixelFormat(hGL->hdc, &pfd); + if (pfmt == 0) { + printf("Failed choosing the requested PixelFormat.\n"); + return false; + } + + glErr = SetPixelFormat(hGL->hdc, pfmt, &pfd); + if (glErr == FALSE) { + printf("Failed to set the requested PixelFormat.\n"); + return false; + } + + hGL->hglrc = wglCreateContext(hGL->hdc); + if (NULL == hGL->hglrc) { + printf("wglCreateContext() failed\n"); + return false; + } + + glErr = wglMakeCurrent(hGL->hdc, hGL->hglrc); + if (FALSE == glErr) { + printf("wglMakeCurrent() failed\n"); + return false; + } + + if (!checkAssociationDeviceWithGLContext(hGL)) { + deleteGLContext(hGL); + return false; + } + + return true; + } // for (deviceNum = 0; EnumDisplayDevices(NULL, deviceNum, &dispDevice, + // 0); deviceNum++) { + + return false; +} + +bool OCLGLCommon::checkAssociationDeviceWithGLContext(OCLGLHandle& hGL) { + bool ret = false; + size_t devicesSize = 0; + cl_context_properties properties[] = {CL_CONTEXT_PLATFORM, + (cl_context_properties)platform_, + CL_GL_CONTEXT_KHR, + (cl_context_properties)hGL->hglrc, + CL_WGL_HDC_KHR, + (cl_context_properties)hGL->hdc, + 0}; + + error_ = _wrapper->clGetGLContextInfoKHR( + properties, CL_DEVICES_FOR_GL_CONTEXT_KHR, 0, NULL, &devicesSize); + if (error_ != CL_SUCCESS) { + printf("clGetGLContextInfoKHR failed (%d)\n", error_); + return false; + } + + cl_uint numDevices = (cl_uint)devicesSize / sizeof(cl_device_id); + cl_device_id* interopDevices = (cl_device_id*)malloc(devicesSize); + + error_ = + _wrapper->clGetGLContextInfoKHR(properties, CL_DEVICES_FOR_GL_CONTEXT_KHR, + devicesSize, interopDevices, NULL); + if (error_ != CL_SUCCESS) { + printf("clGetGLContextInfoKHR failed (%d)\n", error_); + free(interopDevices); + return false; + } + + // Check that current device can be associated with OpenGL context + for (unsigned int i = 0; i < numDevices; i++) { + if (interopDevices[i] == devices_[_deviceId]) { + ret = true; + break; + } + } + + free(interopDevices); + return ret; +} + +void OCLGLCommon::createCLContextFromGLContext(OCLGLHandle& hGL) { + cl_context_properties properties[] = {CL_CONTEXT_PLATFORM, + (cl_context_properties)platform_, + CL_GL_CONTEXT_KHR, + (cl_context_properties)hGL->hglrc, + CL_WGL_HDC_KHR, + (cl_context_properties)hGL->hdc, + 0}; + + // Release current command queue + if (cmdQueues_[_deviceId]) { + error_ = _wrapper->clReleaseCommandQueue(cmdQueues_[_deviceId]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseCommandQueue() failed"); + } + + // Release current context + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), "clReleaseContext() failed"); + } + + // Create new CL context from GL context + context_ = + clCreateContext(properties, 1, &devices_[_deviceId], NULL, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateContext() failed (%d)", error_); + + // Create command queue for new context + cmdQueues_[_deviceId] = + _wrapper->clCreateCommandQueue(context_, devices_[_deviceId], 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueue() failed (%d)", + error_); + + GLenum glErr = glewInit(); + CHECK_RESULT((glErr != GLEW_OK), "glewInit() failed"); +} + +void OCLGLCommon::makeCurrent(OCLGLHandle hGL) { + if (hGL == NULL) { + wglMakeCurrent(NULL, NULL); + } else { + wglMakeCurrent(hGL->hdc, hGL->hglrc); + } +} + +void OCLGLCommon::getCLContextPropertiesFromGLContext( + const OCLGLHandle hGL, cl_context_properties properties[7]) { + if (!properties) return; + + properties[0] = CL_CONTEXT_PLATFORM; + properties[1] = (cl_context_properties)platform_; + properties[2] = CL_GL_CONTEXT_KHR; + properties[3] = (cl_context_properties)hGL->hglrc; + properties[4] = CL_WGL_HDC_KHR; + properties[5] = (cl_context_properties)hGL->hdc; + properties[6] = 0; +} diff --git a/opencl/tests/ocltst/module/common/OCLTestImp.cpp b/opencl/tests/ocltst/module/common/OCLTestImp.cpp new file mode 100644 index 0000000000..29c51276aa --- /dev/null +++ b/opencl/tests/ocltst/module/common/OCLTestImp.cpp @@ -0,0 +1,288 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLTestImp.h" + +#include +#include +#include + +#include +#include + +///////////////////////////////////////////////////////////////////////////// + +static unsigned int crcinit(unsigned int crc); +static int initializeSeed(void); + +///////////////////////////////////////////////////////////////////////////// + +OCLutil::Lock OCLTestImp::openDeviceLock; +OCLutil::Lock OCLTestImp::compileLock; + +OCLTestImp::OCLTestImp() + : _wrapper(0), + _seed(0), + error_(0), + type_(0), + deviceCount_(0), + devices_(0), + platform_(0), + context_(0), + program_(0), + kernel_(0) { + unsigned int i; + for (i = 0; i < 256; i++) { + _crctab[i] = crcinit(i << 24); + } + _perfInfo = 0; + + _wrapper = 0; + _iterationCnt = 0; + + _seed = initializeSeed(); + + _errorMsg = ""; + _errorFlag = false; + type_ = CL_DEVICE_TYPE_GPU; +} + +OCLTestImp::~OCLTestImp() {} +void OCLTestImp::useCPU() { type_ = CL_DEVICE_TYPE_CPU; } +void OCLTestImp::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + devices_ = 0; + context_ = 0; + program_ = 0; + kernel_ = 0; + deviceCount_ = 0; + + open(test, units, conversion, deviceId, getPlatformIndex()); +} +void OCLTestImp::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId, unsigned int platformIndex) { + BaseTestImp::open(); + devices_ = 0; + deviceCount_ = 0; + context_ = 0; + program_ = 0; + kernel_ = 0; + _deviceId = deviceId; + _platformIndex = platformIndex; + + cl_uint numPlatforms = 0; + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetPlatformIDs failed"); + CHECK_RESULT((numPlatforms == 0), "No platform found"); + + cl_platform_id* platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + + cl_platform_id platform = 0; +#if 0 + for(unsigned int i = 0; i < numPlatforms; ++i) + { + char buff[200]; + error_ = _wrapper->clGetPlatformInfo(platforms[i],CL_PLATFORM_VENDOR, sizeof(buff), buff, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + if(strcmp(buff, "Advanced Micro Devices, Inc.") == 0) + { + platform = platforms[i]; + break; + } + } +#endif + platform = platforms[_platformIndex]; + + delete[] platforms; + + CHECK_RESULT((platform == 0), "AMD Platform not found"); + + error_ = _wrapper->clGetDeviceIDs(platform, type_, 0, NULL, &deviceCount_); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs() failed"); + + devices_ = new cl_device_id[deviceCount_]; + error_ = + _wrapper->clGetDeviceIDs(platform, type_, deviceCount_, devices_, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs() failed"); + + cl_context_properties props[3] = {CL_CONTEXT_PLATFORM, + (cl_context_properties)platform, 0}; + context_ = _wrapper->clCreateContext(props, deviceCount_, devices_, NULL, 0, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateContext failed"); + + cl_command_queue cmdQueue; + for (unsigned int i = 0; i < deviceCount_; ++i) { +#ifndef CL_VERSION_2_0 + cmdQueue = _wrapper->clCreateCommandQueue( + context_, devices_[i], CL_QUEUE_PROFILING_ENABLE, &error_); +#else + cl_queue_properties prop[] = {CL_QUEUE_PROPERTIES, + CL_QUEUE_PROFILING_ENABLE, 0}; + cmdQueue = _wrapper->clCreateCommandQueueWithProperties( + context_, devices_[i], prop, &error_); +#endif + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueue() failed"); + cmdQueues_.push_back(cmdQueue); + } + platform_ = platform; +} + +unsigned int OCLTestImp::close() { + for (unsigned int i = 0; i < buffers().size(); ++i) { + error_ = _wrapper->clReleaseMemObject(buffers()[i]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseMemObject() failed"); + } + buffers_.clear(); + + if (kernel_ != 0) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), "clReleaseKernel() failed"); + } + + if (program_ != 0) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), "clReleaseProgram() failed"); + } + + for (unsigned int i = 0; i < cmdQueues_.size(); ++i) { + error_ = _wrapper->clReleaseCommandQueue(cmdQueues_[i]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseCommandQueue() failed"); + } + cmdQueues_.clear(); + + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), "clReleaseContext() failed"); + } + + if (devices_) { + delete[] devices_; + } + + return BaseTestImp::close(); +} + +int OCLTestImp::genBitRand(int n) { + int rslt; + if (n <= 0 || n > 32) { + assert(0); + rslt = 0; + } else if (n < 32) { + _seed = _seed * 1103515245 + 12345; + /* + * return the most-significant n bits; they are the random ones (see + * Knuth, Vol 2) + */ + rslt = (_seed & 0x7fffffff) >> (31 - n); + } else { + rslt = (genBitRand(16) << 16) | genBitRand(16); + } + + return rslt; +} + +int OCLTestImp::genIntRand(int a, int b) { + int r; + int sign = 1; + int mySmall; + int delta; + int bits = 0; + int rslt; + if (a > b) { + mySmall = b; + delta = a - b; + } else { + mySmall = a; + delta = b - a; + } + if (delta == 0) { + rslt = a; + return (rslt); + } else if (delta < 0) { + sign = -1; + delta = -delta; + } + delta &= 0x7fffffff; + for (r = delta; r > 0; r >>= 1) { + bits++; + } + do { + r = genBitRand(bits); + } while (r > delta); + + rslt = mySmall + r * sign; + + return (rslt); +} + +void OCLTestImp::setOCLWrapper(OCLWrapper* wrapper) { _wrapper = wrapper; } + +///////////////////////////////////////////////////////////////////////////// + +#ifdef _WIN32 + +#include + +static int initializeSeed(void) { + __int64 val; + QueryPerformanceCounter((LARGE_INTEGER*)&val); + return (int)val; +} + +#endif // _WIN32 + +///////////////////////////////////////////////////////////////////////////// + +#ifdef __linux__ + +#include + +static int initializeSeed(void) { + struct timeval t; + gettimeofday(&t, 0); + return (int)t.tv_usec; +} + +#endif // __linux__ + +///////////////////////////////////////////////////////////////////////////// +// +// Same CRC32 as used by ogtst +// +static const unsigned int CRCMASK = 0x04c11db7; + +static unsigned int crcinit(unsigned int crc) { + int i; + unsigned int ans = crc; + + for (i = 0; i < 8; i++) { + if (ans & 0x80000000) { + ans = (ans << 1) ^ CRCMASK; + } else { + ans <<= 1; + } + } + return (ans); +} diff --git a/opencl/tests/ocltst/module/common/OCLTestListImp.cpp b/opencl/tests/ocltst/module/common/OCLTestListImp.cpp new file mode 100644 index 0000000000..b699e90076 --- /dev/null +++ b/opencl/tests/ocltst/module/common/OCLTestListImp.cpp @@ -0,0 +1,70 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLTestListImp.h" + +#include + +#include "OCLTest.h" + +// +// OCLTestList_TestCount - retrieve the number of tests in the testing module +// +unsigned int OCL_CALLCONV OCLTestList_TestCount(void) { return TestListCount; } + +// +// OCLTestList_TestLibVersion - retrieve the version of test lib in the testing +// module +// +unsigned int OCL_CALLCONV OCLTestList_TestLibVersion(void) { + return TestLibVersion; +} + +// +// OCLTestList_TestLibName - retrieve the name of test library +// +const char* OCL_CALLCONV OCLTestList_TestLibName(void) { return TestLibName; } + +// +// OCLTestList_TestName - retrieve the name of the indexed test in the module +// +const char* OCL_CALLCONV OCLTestList_TestName(unsigned int testNum) { + if (testNum >= OCLTestList_TestCount()) { + return NULL; + } + + return TestList[testNum].name; +} + +// +// OCLTestList_CreateTest - create a test by index +// +OCLTest* OCL_CALLCONV OCLTestList_CreateTest(unsigned int testNum) { + if (testNum >= OCLTestList_TestCount()) { + return NULL; + } + + return reinterpret_cast((*TestList[testNum].create)()); +} + +// +// OCLTestList_DestroyTest - destroy a test object +// +void OCL_CALLCONV OCLTestList_DestroyTest(OCLTest* test) { delete test; } diff --git a/opencl/tests/ocltst/module/common/OCLTestUtils.cpp b/opencl/tests/ocltst/module/common/OCLTestUtils.cpp new file mode 100644 index 0000000000..56044bdb77 --- /dev/null +++ b/opencl/tests/ocltst/module/common/OCLTestUtils.cpp @@ -0,0 +1,46 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLTestUtils.h" + +#include +#include + +bool loadFile(const char* filename, std::string& s) { + size_t size; + char* str; + std::fstream f(filename, std::fstream::in | std::fstream::binary); + + if (f.is_open()) { + size_t fileSize; + f.seekg(0, std::fstream::end); + size = fileSize = (size_t)f.tellg(); + f.seekg(0, std::fstream::beg); + str = new char[size + 1]; + f.read(str, fileSize); + f.close(); + str[size] = '\0'; + s = str; + delete[] str; + return true; + } + std::cerr << "Error: failed to open file: " << filename << '\n'; + return false; +} diff --git a/opencl/tests/ocltst/module/common/OCLThread.cpp b/opencl/tests/ocltst/module/common/OCLThread.cpp new file mode 100644 index 0000000000..4bda6a5f0a --- /dev/null +++ b/opencl/tests/ocltst/module/common/OCLThread.cpp @@ -0,0 +1,209 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +//! +//! \file OCLThread.cpp +//! + +#include +#include + +#include "OCL/Thread.h" +#ifdef _WIN32 +#include +#endif + +//! pack the function pointer and data inside this struct +typedef struct __argsToThreadFunc { + oclThreadFunc func; + void *data; + +} argsToThreadFunc; + +#ifdef _WIN32 +//! Windows thread callback - invokes the callback set by +//! the application in OCLThread constructor +unsigned _stdcall win32ThreadFunc(void *args) { + argsToThreadFunc *ptr = (argsToThreadFunc *)args; + OCLutil::Thread *obj = (OCLutil::Thread *)ptr->data; + ptr->func(obj->getData()); + delete args; + return 0; +} +#endif + +//////////////////////////////////////////////////////////////////// +//! +//! Constructor for OCLLock +//! +OCLutil::Lock::Lock() { +#ifdef _WIN32 + InitializeCriticalSection(&_cs); +#else + pthread_mutex_init(&_lock, NULL); +#endif +} + +//////////////////////////////////////////////////////////////////// +//! +//! Destructor for OCLLock +//! +OCLutil::Lock::~Lock() { +#ifdef _WIN32 + DeleteCriticalSection(&_cs); +#else + pthread_mutex_destroy(&_lock); +#endif +} + +////////////////////////////////////////////////////////////// +//! +//! Try to acquire the lock, wait for the lock if unavailable +//! else hold the lock and enter the protected area +//! +void OCLutil::Lock::lock() { +#ifdef _WIN32 + EnterCriticalSection(&_cs); +#else + pthread_mutex_lock(&_lock); +#endif +} + +////////////////////////////////////////////////////////////// +//! +//! Try to acquire the lock, if unavailable the function returns +//! false and returns true if available(enters the critical +//! section as well in this case). +//! +bool OCLutil::Lock::tryLock() { +#ifdef _WIN32 + return (TryEnterCriticalSection(&_cs) != 0); +#else + return !((bool)pthread_mutex_trylock(&_lock)); +#endif +} + +////////////////////////////////////////////////////////////// +//! +//! Unlock the lock +//! +void OCLutil::Lock::unlock() { +#ifdef _WIN32 + LeaveCriticalSection(&_cs); +#else + pthread_mutex_unlock(&_lock); +#endif +} + +//////////////////////////////////////////////////////////////////// +//! +//! Constructor for OCLThread +//! +OCLutil::Thread::Thread() : _tid(0), _data(0) { +#ifdef _WIN32 + _ID = 0; +#else +#endif +} + +//////////////////////////////////////////////////////////////////// +//! +//! Destructor for OCLLock +//! +OCLutil::Thread::~Thread() { +#ifdef _WIN32 + CloseHandle(_tid); +#else +#endif +} + +////////////////////////////////////////////////////////////// +//! +//! Create a new thread and return the status of the operation +//! +bool OCLutil::Thread::create(oclThreadFunc func, void *arg) { + // Save the data internally + _data = arg; + + unsigned int retVal; + + bool verbose = getenv("VERBOSE") != NULL; + +#ifdef _WIN32 + // Setup the callback struct for thread function and pass to the + // begin thread routine + // xxx The following struct is allocated but never freed!!!! + argsToThreadFunc *args = new argsToThreadFunc; + args->func = func; + args->data = this; + + _tid = (HANDLE)_beginthreadex(NULL, 0, win32ThreadFunc, args, 0, &retVal); + + if (verbose) { + printf("Thread handle value = %p\n", _tid); + + printf("Done creating thread. Thread id value = %u\n", retVal); + } +#else + //! Now create the thread with pointer to self as the data + retVal = pthread_create(&_tid, NULL, func, arg); + + if (verbose) + printf("Done creating thread. Ret value %d, Self = %u\n", retVal, + (unsigned int)pthread_self()); +#endif + + if (retVal != 0) return false; + + return true; +} + +////////////////////////////////////////////////////////////// +//! +//! Return the thread ID for the current OCLThread +//! +unsigned int OCLutil::Thread::getID() { +#ifdef _WIN32 + return GetCurrentThreadId(); + // Type cast the thread handle to unsigned in and send it over +#else + return (unsigned int)pthread_self(); +#endif +} + +////////////////////////////////////////////////////////////// +//! +//! Wait for this thread to join +//! +bool OCLutil::Thread::join() { +#ifdef _WIN32 + DWORD rc = WaitForSingleObject(_tid, INFINITE); + + if (rc == WAIT_FAILED) { + printf("Bad call to function(invalid handle?)\n"); + } +#else + int rc = pthread_join(_tid, NULL); +#endif + + if (rc != 0) return false; + + return true; +} diff --git a/opencl/tests/ocltst/module/common/OCLWrapper.cpp b/opencl/tests/ocltst/module/common/OCLWrapper.cpp new file mode 100644 index 0000000000..df65dedeb4 --- /dev/null +++ b/opencl/tests/ocltst/module/common/OCLWrapper.cpp @@ -0,0 +1,944 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLWrapper.h" + +OCLWrapper::OCLWrapper() { + clEnqueueWaitSignalAMD_ptr = + (clEnqueueWaitSignalAMD_fn)clGetExtensionFunctionAddress( + "clEnqueueWaitSignalAMD"); + clEnqueueWriteSignalAMD_ptr = + (clEnqueueWriteSignalAMD_fn)clGetExtensionFunctionAddress( + "clEnqueueWriteSignalAMD"); + clEnqueueMakeBuffersResidentAMD_ptr = + (clEnqueueMakeBuffersResidentAMD_fn)clGetExtensionFunctionAddress( + "clEnqueueMakeBuffersResidentAMD"); + + clUnloadPlatformAMD_ptr = + (clUnloadPlatformAMD_fn)clGetExtensionFunctionAddress( + "clUnloadPlatformAMD"); + + // CL-GL function pointers + clGetGLContextInfoKHR_ptr = + (clGetGLContextInfoKHR_fn)clGetExtensionFunctionAddress( + "clGetGLContextInfoKHR"); + clCreateFromGLBuffer_ptr = + (clCreateFromGLBuffer_fn)clGetExtensionFunctionAddress( + "clCreateFromGLBuffer"); + clCreateFromGLTexture_ptr = + (clCreateFromGLTexture_fn)clGetExtensionFunctionAddress( + "clCreateFromGLTexture"); + clCreateFromGLTexture2D_ptr = + (clCreateFromGLTexture2D_fn)clGetExtensionFunctionAddress( + "clCreateFromGLTexture2D"); + clCreateFromGLRenderbuffer_ptr = + (clCreateFromGLRenderbuffer_fn)clGetExtensionFunctionAddress( + "clCreateFromGLRenderbuffer"); + clGetGLObjectInfo_ptr = + (clGetGLObjectInfo_fn)clGetExtensionFunctionAddress("clGetGLObjectInfo"); + clGetGLTextureInfo_ptr = (clGetGLTextureInfo_fn)clGetExtensionFunctionAddress( + "clGetGLTextureInfo"); + clEnqueueAcquireGLObjects_ptr = + (clEnqueueAcquireGLObjects_fn)clGetExtensionFunctionAddress( + "clEnqueueAcquireGLObjects"); + clEnqueueReleaseGLObjects_ptr = + (clEnqueueReleaseGLObjects_fn)clGetExtensionFunctionAddress( + "clEnqueueReleaseGLObjects"); + + // Performance counter function pointers + clCreatePerfCounterAMD_ptr = + (clCreatePerfCounterAMD_fn)clGetExtensionFunctionAddress( + "clCreatePerfCounterAMD"); + clEnqueueBeginPerfCounterAMD_ptr = + (clEnqueueBeginPerfCounterAMD_fn)clGetExtensionFunctionAddress( + "clEnqueueBeginPerfCounterAMD"); + clEnqueueEndPerfCounterAMD_ptr = + (clEnqueueEndPerfCounterAMD_fn)clGetExtensionFunctionAddress( + "clEnqueueEndPerfCounterAMD"); + clGetPerfCounterInfoAMD_ptr = + (clGetPerfCounterInfoAMD_fn)clGetExtensionFunctionAddress( + "clGetPerfCounterInfoAMD"); + clReleasePerfCounterAMD_ptr = + (clReleasePerfCounterAMD_fn)clGetExtensionFunctionAddress( + "clReleasePerfCounterAMD"); + clRetainPerfCounterAMD_ptr = + (clRetainPerfCounterAMD_fn)clGetExtensionFunctionAddress( + "clRetainPerfCounterAMD"); + clSetDeviceClockModeAMD_ptr = + (clSetDeviceClockModeAMD_fn)clGetExtensionFunctionAddress( + "clSetDeviceClockModeAMD"); +} + +cl_int OCLWrapper::clGetPlatformIDs(cl_uint num_entries, + cl_platform_id *platforms, + cl_uint *num_platforms) { + return ::clGetPlatformIDs(num_entries, platforms, num_platforms); +} + +cl_int OCLWrapper::clGetPlatformInfo(cl_platform_id platform, + cl_platform_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret) { + return ::clGetPlatformInfo(platform, param_name, param_value_size, + param_value, param_value_size_ret); +} + +cl_int OCLWrapper::clGetDeviceIDs(cl_platform_id platform, + cl_device_type device_type, + cl_uint num_entries, cl_device_id *devices, + cl_uint *num_devices) { + return ::clGetDeviceIDs(platform, device_type, num_entries, devices, + num_devices); +} + +cl_int OCLWrapper::clGetDeviceInfo(cl_device_id device, + cl_device_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret) { + return ::clGetDeviceInfo(device, param_name, param_value_size, param_value, + param_value_size_ret); +} + +cl_context OCLWrapper::clCreateContext( + 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) { + return ::clCreateContext(properties, num_devices, devices, pfn_notify, + user_data, errcode_ret); +} + +cl_context OCLWrapper::clCreateContextFromType( + 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) { + return ::clCreateContextFromType(properties, device_type, pfn_notify, + user_data, errcode_ret); +} + +cl_int OCLWrapper::clRetainContext(cl_context context) { + return ::clRetainContext(context); +} + +cl_int OCLWrapper::clReleaseContext(cl_context context) { + return ::clReleaseContext(context); +} + +cl_int OCLWrapper::clGetContextInfo(cl_context context, + cl_context_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret) { + return ::clGetContextInfo(context, param_name, param_value_size, param_value, + param_value_size_ret); +} + +cl_command_queue OCLWrapper::clCreateCommandQueue( + cl_context context, cl_device_id device, + cl_command_queue_properties properties, cl_int *errcode_ret) { +#if defined(CL_VERSION_2_0) + cl_int err; + cl_platform_id pid; + bool version20 = true; + err = ::clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(cl_platform_id), + &pid, NULL); + if (err == CL_SUCCESS) { + size_t size; + char *ver; + err = ::clGetPlatformInfo(pid, CL_PLATFORM_VERSION, 0, NULL, &size); + if (err == CL_SUCCESS) { + ver = new char[size]; + if (ver) { + err = ::clGetPlatformInfo(pid, CL_PLATFORM_VERSION, size, ver, NULL); + if (err == CL_SUCCESS) { + if (ver[8] == '1') { + version20 = false; + } + } + delete[] ver; + } + } + } + if (version20) { + const cl_queue_properties cprops[] = { + CL_QUEUE_PROPERTIES, static_cast(properties), 0}; + return ::clCreateCommandQueueWithProperties( + context, device, properties ? cprops : NULL, errcode_ret); + } else { + return ::clCreateCommandQueue(context, device, properties, errcode_ret); + } +#else + return ::clCreateCommandQueue(context, device, properties, errcode_ret); +#endif +} + +cl_int OCLWrapper::clRetainCommandQueue(cl_command_queue command_queue) { + return ::clRetainCommandQueue(command_queue); +} + +cl_int OCLWrapper::clReleaseCommandQueue(cl_command_queue command_queue) { + return ::clReleaseCommandQueue(command_queue); +} + +cl_int OCLWrapper::clGetCommandQueueInfo(cl_command_queue command_queue, + cl_command_queue_info param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret) { + return ::clGetCommandQueueInfo(command_queue, param_name, param_value_size, + param_value, param_value_size_ret); +} + +cl_mem OCLWrapper::clCreateBuffer(cl_context context, cl_mem_flags flags, + size_t size, void *host_ptr, + cl_int *errcode_ret) { + return ::clCreateBuffer(context, flags, size, host_ptr, errcode_ret); +} + +cl_mem OCLWrapper::clCreateImage2D(cl_context context, cl_mem_flags flags, + const cl_image_format *image_format, + size_t image_width, size_t image_height, + size_t image_row_pitch, void *host_ptr, + cl_int *errcode_ret) { + return ::clCreateImage2D(context, flags, image_format, image_width, + image_height, image_row_pitch, host_ptr, + errcode_ret); +} + +cl_mem OCLWrapper::clCreateImage3D(cl_context context, cl_mem_flags flags, + const cl_image_format *image_format, + size_t image_width, size_t image_height, + size_t image_depth, size_t image_row_pitch, + size_t image_slice_pitch, void *host_ptr, + cl_int *errcode_ret) { + return ::clCreateImage3D(context, flags, image_format, image_width, + image_height, image_depth, image_row_pitch, + image_slice_pitch, host_ptr, errcode_ret); +} + +cl_int OCLWrapper::clRetainMemObject(cl_mem memobj) { + return ::clRetainMemObject(memobj); +} + +cl_int OCLWrapper::clReleaseMemObject(cl_mem memobj) { + return ::clReleaseMemObject(memobj); +} + +cl_int OCLWrapper::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) { + return ::clGetSupportedImageFormats(context, flags, image_type, num_entries, + image_formats, num_image_formats); +} + +cl_int OCLWrapper::clGetMemObjectInfo(cl_mem memobj, cl_mem_info param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret) { + return ::clGetMemObjectInfo(memobj, param_name, param_value_size, param_value, + param_value_size_ret); +} + +cl_int OCLWrapper::clGetImageInfo(cl_mem image, cl_image_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret) { + return ::clGetImageInfo(image, param_name, param_value_size, param_value, + param_value_size_ret); +} + +cl_sampler OCLWrapper::clCreateSampler(cl_context context, + cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, + cl_int *errcode_ret) { +#ifdef CL_VERSION_2_0 + const cl_sampler_properties sprops[] = { + CL_SAMPLER_NORMALIZED_COORDS, + static_cast(normalized_coords), + CL_SAMPLER_ADDRESSING_MODE, + static_cast(addressing_mode), + CL_SAMPLER_FILTER_MODE, + static_cast(filter_mode), + 0}; + return ::clCreateSamplerWithProperties(context, sprops, errcode_ret); +#else + return ::clCreateSampler(context, normalized_coords, addressing_mode, + filter_mode, errcode_ret); +#endif +} + +cl_int OCLWrapper::clRetainSampler(cl_sampler sampler) { + return ::clRetainSampler(sampler); +} + +cl_int OCLWrapper::clReleaseSampler(cl_sampler sampler) { + return ::clReleaseSampler(sampler); +} + +cl_int OCLWrapper::clGetSamplerInfo(cl_sampler sampler, + cl_sampler_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret) { + return ::clGetSamplerInfo(sampler, param_name, param_value_size, param_value, + param_value_size_ret); +} + +cl_program OCLWrapper::clCreateProgramWithSource(cl_context context, + cl_uint count, + const char **strings, + const size_t *lengths, + cl_int *errcode_ret) { + return ::clCreateProgramWithSource(context, count, strings, lengths, + errcode_ret); +} + +cl_program OCLWrapper::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) { + return ::clCreateProgramWithBinary(context, num_devices, device_list, lengths, + binaries, binary_status, errcode_ret); +} + +cl_int OCLWrapper::clRetainProgram(cl_program program) { + return ::clRetainProgram(program); +} + +cl_int OCLWrapper::clReleaseProgram(cl_program program) { + return ::clReleaseProgram(program); +} + +cl_int OCLWrapper::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) { + return ::clBuildProgram(program, num_devices, device_list, options, + pfn_notify, user_data); +} + +cl_int OCLWrapper::clCompileProgram( + cl_program program, cl_uint num_devices, const cl_device_id *device_list, + const char *options, cl_uint num_input_headers, + const cl_program *input_headers, const char **header_include_names, + void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), + void *user_data) { + return ::clCompileProgram(program, num_devices, device_list, options, + num_input_headers, input_headers, + header_include_names, pfn_notify, user_data); +} + +cl_program OCLWrapper::clLinkProgram( + cl_context context, cl_uint num_devices, const cl_device_id *device_list, + const char *options, cl_uint num_input_programs, + const cl_program *input_programs, + void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), + void *user_data, cl_int *errcode_ret) { + return ::clLinkProgram(context, num_devices, device_list, options, + num_input_programs, input_programs, pfn_notify, + user_data, errcode_ret); +} + +cl_int OCLWrapper::clUnloadCompiler(void) { return ::clUnloadCompiler(); } + +cl_int OCLWrapper::clGetProgramInfo(cl_program program, + cl_program_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret) { + return ::clGetProgramInfo(program, param_name, param_value_size, param_value, + param_value_size_ret); +} + +cl_int OCLWrapper::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) { + return ::clGetProgramBuildInfo(program, device, param_name, param_value_size, + param_value, param_value_size_ret); +} + +cl_kernel OCLWrapper::clCreateKernel(cl_program program, + const char *kernel_name, + cl_int *errcode_ret) { + return ::clCreateKernel(program, kernel_name, errcode_ret); +} + +cl_int OCLWrapper::clCreateKernelsInProgram(cl_program program, + cl_uint num_kernels, + cl_kernel *kernels, + cl_uint *num_kernels_ret) { + return ::clCreateKernelsInProgram(program, num_kernels, kernels, + num_kernels_ret); +} + +cl_int OCLWrapper::clRetainKernel(cl_kernel kernel) { + return ::clRetainKernel(kernel); +} + +cl_int OCLWrapper::clReleaseKernel(cl_kernel kernel) { + return ::clReleaseKernel(kernel); +} + +cl_int OCLWrapper::clSetKernelArg(cl_kernel kernel, cl_uint arg_index, + size_t arg_size, const void *arg_value) { + return ::clSetKernelArg(kernel, arg_index, arg_size, arg_value); +} + +cl_int OCLWrapper::clGetKernelInfo(cl_kernel kernel, cl_kernel_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret) { + return ::clGetKernelInfo(kernel, param_name, param_value_size, param_value, + param_value_size_ret); +} + +cl_int OCLWrapper::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) { + return ::clGetKernelWorkGroupInfo(kernel, device, param_name, + param_value_size, param_value, + param_value_size_ret); +} + +cl_int OCLWrapper::clWaitForEvents(cl_uint num_events, + const cl_event *event_list) { + return ::clWaitForEvents(num_events, event_list); +} + +cl_int OCLWrapper::clGetEventInfo(cl_event evnt, cl_event_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret) { + return ::clGetEventInfo(evnt, param_name, param_value_size, param_value, + param_value_size_ret); +} + +cl_int OCLWrapper::clRetainEvent(cl_event evnt) { + return ::clRetainEvent(evnt); +} + +cl_int OCLWrapper::clReleaseEvent(cl_event evnt) { + return ::clReleaseEvent(evnt); +} + +cl_int OCLWrapper::clGetEventProfilingInfo(cl_event evnt, + cl_profiling_info param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret) { + return ::clGetEventProfilingInfo(evnt, param_name, param_value_size, + param_value, param_value_size_ret); +} + +cl_int OCLWrapper::clFlush(cl_command_queue command_queue) { + return ::clFlush(command_queue); +} + +cl_int OCLWrapper::clFinish(cl_command_queue command_queue) { + return ::clFinish(command_queue); +} + +cl_int OCLWrapper::clEnqueueReadBuffer(cl_command_queue command_queue, + cl_mem buffer, cl_bool blocking_read, + size_t offset, size_t cb, void *ptr, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *evnt) { + return ::clEnqueueReadBuffer(command_queue, buffer, blocking_read, offset, cb, + ptr, num_events_in_wait_list, event_wait_list, + evnt); +} + +cl_int OCLWrapper::clEnqueueWriteBuffer( + cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, + size_t offset, size_t cb, const void *ptr, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *evnt) { + return ::clEnqueueWriteBuffer(command_queue, buffer, blocking_write, offset, + cb, ptr, num_events_in_wait_list, + event_wait_list, evnt); +} + +cl_int OCLWrapper::clEnqueueCopyBuffer(cl_command_queue command_queue, + cl_mem src_buffer, cl_mem dst_buffer, + size_t src_offset, size_t dst_offset, + size_t cb, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *evnt) { + return ::clEnqueueCopyBuffer(command_queue, src_buffer, dst_buffer, + src_offset, dst_offset, cb, + num_events_in_wait_list, event_wait_list, evnt); +} + +cl_int OCLWrapper::clEnqueueReadBufferRect( + cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, + const size_t *buffer_origin, const size_t *host_origin, + const size_t *region, size_t buffer_row_pitch, size_t buffer_slice_pitch, + size_t host_row_pitch, size_t host_slice_pitch, void *ptr, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *evnt) { + return ::clEnqueueReadBufferRect( + command_queue, buffer, blocking_read, buffer_origin, host_origin, region, + buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, + ptr, num_events_in_wait_list, event_wait_list, evnt); +} + +cl_int OCLWrapper::clEnqueueWriteBufferRect( + cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, + const size_t *buffer_origin, const size_t *host_origin, + const size_t *region, size_t buffer_row_pitch, size_t buffer_slice_pitch, + size_t host_row_pitch, size_t host_slice_pitch, const void *ptr, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *evnt) { + return ::clEnqueueWriteBufferRect( + command_queue, buffer, blocking_write, buffer_origin, host_origin, region, + buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, + ptr, num_events_in_wait_list, event_wait_list, evnt); +} + +cl_int OCLWrapper::clEnqueueCopyBufferRect( + cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, + const size_t *src_origin, const size_t *dst_origin, const size_t *region, + size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, + size_t dst_slice_pitch, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *evnt) { + return ::clEnqueueCopyBufferRect( + command_queue, src_buffer, dst_buffer, src_origin, dst_origin, region, + src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, + num_events_in_wait_list, event_wait_list, evnt); +} + +cl_int OCLWrapper::clEnqueueReadImage( + cl_command_queue command_queue, cl_mem image, cl_bool blocking_read, + const size_t *origin, const size_t *region, 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 *evnt) { + return ::clEnqueueReadImage(command_queue, image, blocking_read, origin, + region, row_pitch, slice_pitch, ptr, + num_events_in_wait_list, event_wait_list, evnt); +} + +cl_int OCLWrapper::clEnqueueWriteImage( + cl_command_queue command_queue, cl_mem image, cl_bool blocking_write, + const size_t *origin, const size_t *region, 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 *evnt) { + return ::clEnqueueWriteImage(command_queue, image, blocking_write, origin, + region, input_row_pitch, input_slice_pitch, ptr, + num_events_in_wait_list, event_wait_list, evnt); +} + +cl_int OCLWrapper::clEnqueueCopyImage( + cl_command_queue command_queue, cl_mem src_image, cl_mem dst_image, + const size_t *src_origin, const size_t *dst_origin, const size_t *region, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *evnt) { + return ::clEnqueueCopyImage(command_queue, src_image, dst_image, src_origin, + dst_origin, region, num_events_in_wait_list, + event_wait_list, evnt); +} + +cl_int OCLWrapper::clEnqueueCopyImageToBuffer( + cl_command_queue command_queue, cl_mem src_image, cl_mem dst_buffer, + const size_t *src_origin, const size_t *region, size_t dst_offset, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *evnt) { + return ::clEnqueueCopyImageToBuffer( + command_queue, src_image, dst_buffer, src_origin, region, dst_offset, + num_events_in_wait_list, event_wait_list, evnt); +} + +cl_int OCLWrapper::clEnqueueCopyBufferToImage( + cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_image, + size_t src_offset, const size_t *dst_origin, const size_t *region, + cl_uint num_events_in_wait_list, const cl_event *event_wait_list, + cl_event *evnt) { + return ::clEnqueueCopyBufferToImage( + command_queue, src_buffer, dst_image, src_offset, dst_origin, region, + num_events_in_wait_list, event_wait_list, evnt); +} + +void *OCLWrapper::clEnqueueMapBuffer(cl_command_queue command_queue, + cl_mem buffer, cl_bool blocking_map, + cl_map_flags map_flags, size_t offset, + size_t cb, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *evnt, cl_int *errcode_ret) { + return ::clEnqueueMapBuffer(command_queue, buffer, blocking_map, map_flags, + offset, cb, num_events_in_wait_list, + event_wait_list, evnt, errcode_ret); +} + +void *OCLWrapper::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 *evnt, cl_int *errcode_ret) { + return ::clEnqueueMapImage(command_queue, image, blocking_map, map_flags, + origin, region, image_row_pitch, image_slice_pitch, + num_events_in_wait_list, event_wait_list, evnt, + errcode_ret); +} + +cl_int OCLWrapper::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 *evnt) { + return ::clEnqueueUnmapMemObject(command_queue, memobj, mapped_ptr, + num_events_in_wait_list, event_wait_list, + evnt); +} + +cl_int OCLWrapper::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 *evnt) { + return ::clEnqueueNDRangeKernel( + command_queue, kernel, work_dim, global_work_offset, global_work_size, + local_work_size, num_events_in_wait_list, event_wait_list, evnt); +} + +cl_int OCLWrapper::clEnqueueTask(cl_command_queue command_queue, + cl_kernel kernel, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *evnt) { +#if defined(CL_VERSION_2_0) + static size_t const globalWorkSize[3] = {1, 0, 0}; + static size_t const localWorkSize[3] = {1, 0, 0}; + + return ::clEnqueueNDRangeKernel( + command_queue, kernel, 1, NULL, globalWorkSize, localWorkSize, + num_events_in_wait_list, event_wait_list, evnt); +#else + return ::clEnqueueTask(command_queue, kernel, num_events_in_wait_list, + event_wait_list, evnt); +#endif +} + +cl_int OCLWrapper::clEnqueueNativeKernel( + cl_command_queue command_queue, void(CL_CALLBACK *user_func)(void *), + void *args, size_t cb_args, cl_uint num_mem_objects, const cl_mem *mem_list, + const void **args_mem_loc, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *evnt) { + return ::clEnqueueNativeKernel( + command_queue, user_func, args, cb_args, num_mem_objects, mem_list, + args_mem_loc, num_events_in_wait_list, event_wait_list, evnt); +} + +cl_int OCLWrapper::clEnqueueMarker(cl_command_queue command_queue, + cl_event *evnt) { + return ::clEnqueueMarker(command_queue, evnt); +} + +cl_int OCLWrapper::clEnqueueMarkerWithWaitList(cl_command_queue command_queue, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *evnt) { + return ::clEnqueueMarkerWithWaitList(command_queue, num_events_in_wait_list, + event_wait_list, evnt); +} + +cl_int OCLWrapper::clEnqueueWaitForEvents(cl_command_queue command_queue, + cl_uint num_events, + const cl_event *event_list) { + return ::clEnqueueWaitForEvents(command_queue, num_events, event_list); +} + +cl_int OCLWrapper::clEnqueueBarrier(cl_command_queue command_queue) { + return ::clEnqueueBarrier(command_queue); +} + +void *OCLWrapper::clGetExtensionFunctionAddress(const char *func_name) { + return ::clGetExtensionFunctionAddress(func_name); +} + +cl_mem OCLWrapper::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) { + return ::clCreateImage(context, flags, image_format, image_desc, host_ptr, + errcode_ret); +} + +cl_mem OCLWrapper::clCreateSubBuffer(cl_mem mem, cl_mem_flags flags, + cl_buffer_create_type buffer_create_type, + const void *buffer_create_info, + cl_int *errcode_ret) { + return ::clCreateSubBuffer(mem, flags, buffer_create_type, buffer_create_info, + errcode_ret); +} + +cl_int OCLWrapper::clSetEventCallback( + cl_event event, cl_int command_exec_callback_type, + void(CL_CALLBACK *pfn_event_notify)(cl_event event, + cl_int event_command_exec_status, + void *user_data), + void *user_data) { + return ::clSetEventCallback(event, command_exec_callback_type, + pfn_event_notify, user_data); +} + +cl_int OCLWrapper::clEnqueueFillImage( + cl_command_queue command_queue, cl_mem image, void *ptr, + const size_t *origin, const size_t *region, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *evnt) { + return ::clEnqueueFillImage(command_queue, image, ptr, origin, region, + num_events_in_wait_list, event_wait_list, evnt); +} + +cl_int OCLWrapper::clUnloadPlatformAMD(cl_platform_id id) { + if (clUnloadPlatformAMD_ptr) return clUnloadPlatformAMD_ptr(id); + return CL_SUCCESS; +} +cl_int OCLWrapper::clEnqueueWaitSignalAMD(cl_command_queue command_queue, + cl_mem mem_object, cl_uint value, + cl_uint num_events, + const cl_event *event_wait_list, + cl_event *event) { + return clEnqueueWaitSignalAMD_ptr(command_queue, mem_object, value, + num_events, event_wait_list, event); +} + +cl_int OCLWrapper::clEnqueueWriteSignalAMD(cl_command_queue command_queue, + cl_mem mem_object, cl_uint value, + cl_ulong offset, cl_uint num_events, + const cl_event *event_list, + cl_event *event) { + return clEnqueueWriteSignalAMD_ptr(command_queue, mem_object, value, offset, + num_events, event_list, event); +} + +cl_int OCLWrapper::clEnqueueMakeBuffersResidentAMD( + cl_command_queue command_queue, cl_uint num_mem_objs, cl_mem *mem_objects, + cl_bool blocking_make_resident, cl_bus_address_amd *bus_addresses, + cl_uint num_events, const cl_event *event_list, cl_event *event) { + return clEnqueueMakeBuffersResidentAMD_ptr( + command_queue, num_mem_objs, mem_objects, blocking_make_resident, + bus_addresses, num_events, event_list, event); +} + +cl_int OCLWrapper::clEnqueueMigrateMemObjects(cl_command_queue command_queue, + cl_uint num_mem_objects, + const cl_mem *mem_objects, + cl_mem_migration_flags flags, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) { + return ::clEnqueueMigrateMemObjects( + command_queue, num_mem_objects, mem_objects, flags, + num_events_in_wait_list, event_wait_list, event); +} + +cl_int OCLWrapper::clGetGLContextInfoKHR( + const cl_context_properties *properties, cl_gl_context_info param_name, + size_t param_value_size, void *param_value, size_t *param_value_size_ret) { + return (*clGetGLContextInfoKHR_ptr)(properties, param_name, param_value_size, + param_value, param_value_size_ret); +} + +cl_mem OCLWrapper::clCreateFromGLBuffer(cl_context context, cl_mem_flags flags, + unsigned int bufobj, int *errcode_ret) { + return (*clCreateFromGLBuffer_ptr)(context, flags, bufobj, errcode_ret); +} + +cl_mem OCLWrapper::clCreateFromGLTexture(cl_context context, cl_mem_flags flags, + unsigned int texture_target, + int miplevel, unsigned int texture, + cl_int *errcode_ret) { + return (*clCreateFromGLTexture_ptr)(context, flags, texture_target, miplevel, + texture, errcode_ret); +} + +cl_mem OCLWrapper::clCreateFromGLTexture2D(cl_context context, + cl_mem_flags flags, + unsigned int texture_target, + int miplevel, unsigned int texture, + cl_int *errcode_ret) { + return (*clCreateFromGLTexture2D_ptr)(context, flags, texture_target, + miplevel, texture, errcode_ret); +} + +cl_mem OCLWrapper::clCreateFromGLRenderbuffer(cl_context context, + cl_mem_flags flags, + unsigned int renderbuffer, + cl_int *errcode_ret) { + return (*clCreateFromGLRenderbuffer_ptr)(context, flags, renderbuffer, + errcode_ret); +} + +cl_int OCLWrapper::clGetGLObjectInfo(cl_mem memobj, + cl_gl_object_type *gl_object_type, + unsigned int *gl_object_name) { + return (*clGetGLObjectInfo_ptr)(memobj, gl_object_type, gl_object_name); +} + +cl_int OCLWrapper::clGetGLTextureInfo(cl_mem memobj, + cl_gl_texture_info param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret) { + return (*clGetGLTextureInfo_ptr)(memobj, param_name, param_value_size, + param_value, param_value_size_ret); +} + +cl_int OCLWrapper::clEnqueueAcquireGLObjects(cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem *mem_objects, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) { + return (*clEnqueueAcquireGLObjects_ptr)(command_queue, num_objects, + mem_objects, num_events_in_wait_list, + event_wait_list, event); +} + +cl_int OCLWrapper::clEnqueueReleaseGLObjects(cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem *mem_objects, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) { + return (*clEnqueueReleaseGLObjects_ptr)(command_queue, num_objects, + mem_objects, num_events_in_wait_list, + event_wait_list, event); +} + +#if defined(CL_VERSION_2_0) +cl_command_queue OCLWrapper::clCreateCommandQueueWithProperties( + cl_context context, cl_device_id device, + const cl_queue_properties *properties, cl_int *errcode_ret) { + return ::clCreateCommandQueueWithProperties(context, device, properties, + errcode_ret); +} + +void *OCLWrapper::clSVMAlloc(cl_context context, cl_svm_mem_flags flags, + size_t size, cl_uint alignment) { + return ::clSVMAlloc(context, flags, size, alignment); +} + +void OCLWrapper::clSVMFree(cl_context context, void *svm_pointer) { + return ::clSVMFree(context, svm_pointer); +} + +cl_int OCLWrapper::clEnqueueSVMMap(cl_command_queue command_queue, + cl_bool blocking_map, cl_map_flags flags, + void *svm_ptr, size_t size, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) { + return ::clEnqueueSVMMap(command_queue, blocking_map, flags, svm_ptr, size, + num_events_in_wait_list, event_wait_list, event); +} + +cl_int OCLWrapper::clEnqueueSVMUnmap(cl_command_queue command_queue, + void *svm_ptr, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) { + return ::clEnqueueSVMUnmap(command_queue, svm_ptr, num_events_in_wait_list, + event_wait_list, event); +} +cl_int OCLWrapper::clEnqueueSVMMemFill(cl_command_queue command_queue, + void *svm_ptr, const void *pattern, + size_t pattern_size, size_t size, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) { + return ::clEnqueueSVMMemFill(command_queue, svm_ptr, pattern, pattern_size, + size, num_events_in_wait_list, event_wait_list, + event); +} + +cl_int OCLWrapper::clSetKernelArgSVMPointer(cl_kernel kernel, cl_uint arg_index, + const void *arg_value) { + return ::clSetKernelArgSVMPointer(kernel, arg_index, arg_value); +} + +cl_mem OCLWrapper::clCreatePipe(cl_context context, cl_mem_flags flags, + cl_uint packet_size, cl_uint pipe_max_packets, + const cl_pipe_properties *properties, + cl_int *errcode_ret) { + return ::clCreatePipe(context, flags, packet_size, pipe_max_packets, + properties, errcode_ret); +} + +cl_int OCLWrapper::clGetPipeInfo(cl_mem pipe, cl_pipe_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret) { + return ::clGetPipeInfo(pipe, param_name, param_value_size, param_value, + param_value_size_ret); +} + +#endif + +cl_perfcounter_amd OCLWrapper::clCreatePerfCounterAMD( + cl_device_id device, cl_perfcounter_property *properties, + cl_int *errcode_ret) { + return (*clCreatePerfCounterAMD_ptr)(device, properties, errcode_ret); +} + +cl_int OCLWrapper::clEnqueueBeginPerfCounterAMD( + cl_command_queue command_queue, cl_uint num_perf_counters, + cl_perfcounter_amd *perf_counters, cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, cl_event *event) { + return (*clEnqueueBeginPerfCounterAMD_ptr)( + command_queue, num_perf_counters, perf_counters, num_events_in_wait_list, + event_wait_list, event); +} + +cl_int OCLWrapper::clEnqueueEndPerfCounterAMD(cl_command_queue command_queue, + cl_uint num_perf_counters, + cl_perfcounter_amd *perf_counters, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) { + return (*clEnqueueEndPerfCounterAMD_ptr)( + command_queue, num_perf_counters, perf_counters, num_events_in_wait_list, + event_wait_list, event); +} + +cl_int OCLWrapper::clGetPerfCounterInfoAMD(cl_perfcounter_amd perf_counter, + cl_perfcounter_info param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret) { + return (*clGetPerfCounterInfoAMD_ptr)(perf_counter, param_name, + param_value_size, param_value, + param_value_size_ret); +} + +cl_int OCLWrapper::clReleasePerfCounterAMD(cl_perfcounter_amd perf_counter) { + return (*clReleasePerfCounterAMD_ptr)(perf_counter); +} + +cl_int OCLWrapper::clRetainPerfCounterAMD(cl_perfcounter_amd perf_counter) { + return (*clRetainPerfCounterAMD_ptr)(perf_counter); +} + +cl_int OCLWrapper::clSetDeviceClockModeAMD( + cl_device_id device, + cl_set_device_clock_mode_input_amd set_clock_mode_input, + cl_set_device_clock_mode_output_amd *set_clock_mode_output) { + return (*clSetDeviceClockModeAMD_ptr)(device, set_clock_mode_input, + set_clock_mode_output); +} diff --git a/opencl/tests/ocltst/module/common/Timer.cpp b/opencl/tests/ocltst/module/common/Timer.cpp new file mode 100644 index 0000000000..a2674ee330 --- /dev/null +++ b/opencl/tests/ocltst/module/common/Timer.cpp @@ -0,0 +1,112 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "Timer.h" + +#ifdef _WIN32 +#include +#endif + +#ifdef __linux__ +#include +#define NANOSECONDS_PER_SEC 1000000000 +#endif + +CPerfCounter::CPerfCounter() : _clocks(0), _start(0) { +#ifdef _WIN32 + + QueryPerformanceFrequency((LARGE_INTEGER *)&_freq); + +#endif + +#ifdef __linux__ + _freq = NANOSECONDS_PER_SEC; +#endif +} + +CPerfCounter::~CPerfCounter() { + // EMPTY! +} + +void CPerfCounter::Start(void) { +#ifdef _WIN32 + + if (_start) { + MessageBox(NULL, "Bad Perf Counter Start", "Error", MB_OK); + exit(0); + } + QueryPerformanceCounter((LARGE_INTEGER *)&_start); + +#endif +#ifdef __linux__ + + struct timespec s; + clock_gettime(CLOCK_MONOTONIC, &s); + _start = (i64)s.tv_sec * NANOSECONDS_PER_SEC + (i64)s.tv_nsec; + +#endif +} + +void CPerfCounter::Stop(void) { + i64 n; + +#ifdef _WIN32 + + if (!_start) { + MessageBox(NULL, "Bad Perf Counter Stop", "Error", MB_OK); + exit(0); + } + + QueryPerformanceCounter((LARGE_INTEGER *)&n); + +#endif +#ifdef __linux__ + + struct timespec s; + clock_gettime(CLOCK_MONOTONIC, &s); + n = (i64)s.tv_sec * NANOSECONDS_PER_SEC + (i64)s.tv_nsec; + +#endif + + n -= _start; + _start = 0; + _clocks += n; +} + +void CPerfCounter::Reset(void) { +#ifdef _WIN32 + if (_start) { + MessageBox(NULL, "Bad Perf Counter Reset", "Error", MB_OK); + exit(0); + } +#endif + _clocks = 0; +} + +double CPerfCounter::GetElapsedTime(void) { +#ifdef _WIN32 + if (_start) { + MessageBox(NULL, "Trying to get time while still running.", "Error", MB_OK); + exit(0); + } +#endif + + return (double)_clocks / (double)_freq; +} diff --git a/opencl/tests/ocltst/module/common/Timer.h b/opencl/tests/ocltst/module/common/Timer.h new file mode 100644 index 0000000000..e5d331ccff --- /dev/null +++ b/opencl/tests/ocltst/module/common/Timer.h @@ -0,0 +1,46 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _TIMER_H_ +#define _TIMER_H_ + +#ifdef _WIN32 +typedef __int64 i64; +#endif +#ifdef __linux__ +typedef long long i64; +#endif + +class CPerfCounter { + public: + CPerfCounter(); + ~CPerfCounter(); + void Start(void); + void Stop(void); + void Reset(void); + double GetElapsedTime(void); + + private: + i64 _freq; + i64 _clocks; + i64 _start; +}; + +#endif // _TIMER_H_ diff --git a/opencl/tests/ocltst/module/dx/OCLDX11Common.cpp b/opencl/tests/ocltst/module/dx/OCLDX11Common.cpp new file mode 100644 index 0000000000..3254b2c6cf --- /dev/null +++ b/opencl/tests/ocltst/module/dx/OCLDX11Common.cpp @@ -0,0 +1,236 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLDX11Common.h" + +#define D3D_FEATURE_LEVEL_11_1 0xb100 + +#define INITPFN(x) \ + x = (x##_fn)clGetExtensionFunctionAddressForPlatform(platform_, #x); \ + if ((x) == NULL) { \ + char* buf = (char*)malloc(4096); \ + _errorFlag = true; \ + int rc = snprintf(buf, 4096, "Failed to get function pointer for %s", #x); \ + assert(rc >= 0 && rc < (int)4096); \ + printf("%s:%d - %s\n", __FILE__, __LINE__, buf); \ + _errorMsg = std::string(buf); \ + _crcword += 1; \ + free(buf); \ + return; \ + } + +OCLDX11Common::OCLDX11Common() : OCLTestImp() { + clGetDeviceIDsFromD3D11KHR = NULL; + clCreateFromD3D11BufferKHR = NULL; + clCreateFromD3D11Texture2DKHR = NULL; + clCreateFromD3D11Texture3DKHR = NULL; + clEnqueueAcquireD3D11ObjectsKHR = NULL; + clEnqueueReleaseD3D11ObjectsKHR = NULL; + clGetPlaneFromImageAMD = NULL; +} + +OCLDX11Common::~OCLDX11Common() {} + +void OCLDX11Common::ExtensionCheck() { + cl_int result = CL_SUCCESS; + char extensions[1024]; + + result = _wrapper->clGetPlatformInfo(platform_, CL_PLATFORM_EXTENSIONS, + sizeof(extensions), extensions, NULL); + CHECK_RESULT(result != CL_SUCCESS, "Failed to list platform extensions."); + + extensionsAvailable = + strstr(extensions, "cl_khr_d3d11_sharing") ? true : false; + if (!extensionsAvailable) { + printf("cl_khr_d3d11_sharing extension is required for this test!\n"); + } + + OSVERSIONINFOEX versionInfo = {0}; + versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + versionInfo.dwMajorVersion = 6; + + DWORDLONG conditionMask = 0; + VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); + if (VerifyVersionInfo(&versionInfo, VER_MAJORVERSION, conditionMask)) { + CHECK_RESULT(!extensionsAvailable, + "Extension should be exported on Windows >= 6"); + } else { + CHECK_RESULT(extensionsAvailable, + "Extension should not be exported on Windows < 6"); + } + + result = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_EXTENSIONS, + sizeof(extensions), extensions, NULL); + CHECK_RESULT(result != CL_SUCCESS, "Failed to list device extensions."); + + extensionsAvailable = strstr(extensions, "cl_amd_planar_yuv") ? true : false; + if (!extensionsAvailable) { + printf("cl_amd_planar_yuv extension is required for this test!\n"); + } +} + +void OCLDX11Common::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + // OpenCL Initialization + // OCLTestImp::open(test, units, conversion, deviceId); + BaseTestImp::open(); + devices_ = 0; + deviceCount_ = 0; + context_ = 0; + program_ = 0; + kernel_ = 0; + _queue = 0; + _deviceId = deviceId; + + dxD3D11Context = NULL; + dxD3D11Device = NULL; + + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test (%d)", error_); + + cl_uint numPlatforms = 0; + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetPlatformIDs failed"); + CHECK_RESULT((numPlatforms == 0), "No platform found"); + + cl_platform_id* platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + + platform_ = platforms[_platformIndex]; + CHECK_RESULT((platform_ == 0), "AMD Platform not found"); + + delete[] platforms; + + error_ = _wrapper->clGetDeviceIDs(platform_, type_, 0, NULL, &deviceCount_); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs() failed"); + + devices_ = new cl_device_id[deviceCount_]; + error_ = + _wrapper->clGetDeviceIDs(platform_, type_, deviceCount_, devices_, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs() failed"); + + ExtensionCheck(); + if (!extensionsAvailable) { + return; + } + + // extract function pointers for exported functions + INITPFN(clGetDeviceIDsFromD3D11KHR); + INITPFN(clCreateFromD3D11BufferKHR); + INITPFN(clCreateFromD3D11Texture2DKHR); + INITPFN(clCreateFromD3D11Texture3DKHR); + INITPFN(clEnqueueAcquireD3D11ObjectsKHR); + INITPFN(clEnqueueReleaseD3D11ObjectsKHR); + INITPFN(clGetPlaneFromImageAMD); + + char name[1024] = {0}; + size_t size = 0; + + if (deviceId >= deviceCount_) { + _errorFlag = true; + return; + } + + HRESULT hr = S_OK; + + UINT createDeviceFlags = 0; + + D3D_FEATURE_LEVEL featureLevels[] = { + (D3D_FEATURE_LEVEL)D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0 + + }; + D3D_FEATURE_LEVEL featureLevel; + // Create only the device, not the swapchain. We can't create the swapchain + // anyways without a handle to a window we explicitly own + hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, + createDeviceFlags, featureLevels, + _countof(featureLevels), D3D11_SDK_VERSION, + &dxD3D11Device, &featureLevel, &dxD3D11Context); + + if (FAILED(hr)) { + hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, + createDeviceFlags, featureLevels + 1, + _countof(featureLevels) - 1, D3D11_SDK_VERSION, + &dxD3D11Device, &featureLevel, &dxD3D11Context); + } + if (FAILED(hr)) { + hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_SOFTWARE, NULL, + createDeviceFlags, featureLevels, + _countof(featureLevels), D3D11_SDK_VERSION, + &dxD3D11Device, &featureLevel, &dxD3D11Context); + } + + if (FAILED(hr)) { + hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_SOFTWARE, NULL, + createDeviceFlags, featureLevels + 1, + _countof(featureLevels) - 1, D3D11_SDK_VERSION, + &dxD3D11Device, &featureLevel, &dxD3D11Context); + } + + cl_int status = 0; + cl_context_properties cps[7] = { + CL_CONTEXT_D3D11_DEVICE_KHR, + (cl_context_properties)(ID3D11Device*)dxD3D11Device, + CL_CONTEXT_INTEROP_USER_SYNC, + CL_FALSE, + CL_CONTEXT_PLATFORM, + (cl_context_properties)platform_, + 0}; + cl_context_properties* cprops = (NULL == platform_) ? NULL : cps; + + cl_uint deviceListSize = 0; + clGetDeviceIDsFromD3D11KHR(platform_, CL_D3D11_DEVICE_KHR, dxD3D11Device, + CL_PREFERRED_DEVICES_FOR_D3D11_KHR, 0, NULL, + &deviceListSize); + + std::vector devices; + devices.resize(deviceListSize); + clGetDeviceIDsFromD3D11KHR(platform_, CL_D3D11_DEVICE_KHR, dxD3D11Device, + CL_PREFERRED_DEVICES_FOR_D3D11_KHR, deviceListSize, + &devices[0], NULL); + + bool ret = false; + // Check that current device can be associated with OpenGL context + for (unsigned int i = 0; i < deviceListSize; i++) { + if (devices[i] == devices_[_deviceId]) { + ret = true; + break; + } + } + if (ret) { + char buf[2000]; + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_EXTENSIONS, + sizeof(buf), buf, NULL); + + context_ = + clCreateContext(cprops, 1, &devices_[_deviceId], NULL, NULL, &status); + _queue = clCreateCommandQueue(context_, devices_[_deviceId], 0, &status); + } + CHECK_RESULT((ret != true), "Can't find D3D device!"); +} + +unsigned int OCLDX11Common::close(void) { + clReleaseCommandQueue(_queue); + unsigned int retVal = OCLTestImp::close(); + // deleteDXDevice(hDX_); + if (dxD3D11Context) dxD3D11Context->Release(); + if (dxD3D11Device) dxD3D11Device->Release(); + return retVal; +} diff --git a/opencl/tests/ocltst/module/dx/OCLDX11Common.h b/opencl/tests/ocltst/module/dx/OCLDX11Common.h new file mode 100644 index 0000000000..6e6768d15a --- /dev/null +++ b/opencl/tests/ocltst/module/dx/OCLDX11Common.h @@ -0,0 +1,68 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_DX11_COMMON_H_ +#define _OCL_DX11_COMMON_H_ + +#include +#include + +#include "OCLTestImp.h" +#include "d3d11.h" + +typedef CL_API_ENTRY cl_mem(CL_API_CALL* clGetPlaneFromImageAMD_fn)( + cl_context /* context */, cl_mem /* mem */, cl_uint /* plane */, + cl_int* /* errcode_ret */); + +class OCLDX11Common : public OCLTestImp { + public: + // S/////////////////////////////////////// + // private initialization and clean-up // + ///////////////////////////////////////// + OCLDX11Common(); + virtual ~OCLDX11Common(); + /////////////////////// + // virtual interface // + /////////////////////// + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual unsigned int close(void); + + protected: + bool extensionsAvailable; + + ID3D11Device* dxD3D11Device; + ID3D11DeviceContext* dxD3D11Context; + ID3D11Texture2D* dxDX11Texture; + cl_command_queue _queue; + + clGetDeviceIDsFromD3D11KHR_fn clGetDeviceIDsFromD3D11KHR; + clCreateFromD3D11BufferKHR_fn clCreateFromD3D11BufferKHR; + clCreateFromD3D11Texture2DKHR_fn clCreateFromD3D11Texture2DKHR; + clCreateFromD3D11Texture3DKHR_fn clCreateFromD3D11Texture3DKHR; + clEnqueueAcquireD3D11ObjectsKHR_fn clEnqueueAcquireD3D11ObjectsKHR; + clEnqueueReleaseD3D11ObjectsKHR_fn clEnqueueReleaseD3D11ObjectsKHR; + clGetPlaneFromImageAMD_fn clGetPlaneFromImageAMD; + + private: + void ExtensionCheck(); +}; + +#endif // _OCL_DX11_COMMON_H_ diff --git a/opencl/tests/ocltst/module/dx/OCLDX11YUY2.cpp b/opencl/tests/ocltst/module/dx/OCLDX11YUY2.cpp new file mode 100644 index 0000000000..ebe1a6133a --- /dev/null +++ b/opencl/tests/ocltst/module/dx/OCLDX11YUY2.cpp @@ -0,0 +1,478 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLDX11YUY2.h" + +#include +#include +#include +#include + +#define DXGI_FORMAT_NV12 103 +#define DXGI_FORMAT_P010 104 +#define GROUP_SIZE 256 + +const static char strKernel[] = + "__constant sampler_t imageSampler = CLK_NORMALIZED_COORDS_FALSE | " + "CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; \n" + "__kernel void image2imageCopy( " + " \n" + " __read_only image2d_t input, " + " \n" + " __write_only image2d_t output) " + " \n" + "{ " + " \n" + " int2 coord = (int2)(get_global_id(0), get_global_id(1)); " + " \n" + " uint4 temp = read_imageui(input, imageSampler, coord); " + " \n" + " write_imageui(output, coord, temp); " + " \n" + "} " + " \n"; + +OCLDX11YUY2::OCLDX11YUY2() : OCLDX11Common() { + _numSubTests = 4; + blockSizeX = GROUP_SIZE; + blockSizeY = 1; +} + +OCLDX11YUY2::~OCLDX11YUY2() {} + +void OCLDX11YUY2::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + dxDX11Texture = 0; + clImage2DOut = 0; + _openTest = test; + // Initialize random number seed + srand((unsigned int)time(NULL)); + + OCLDX11Common::open(test, units, conversion, deviceId); + if (_errorFlag) return; + if (!extensionsAvailable) { + return; + } + + if (_openTest < 2) { + dxFormat = (DXGI_FORMAT)DXGI_FORMAT_NV12; + extensionsAvailable = formatSupported(); + if (!extensionsAvailable) { + printf("DXGI_FORMAT_NV12 is required for this test!\n"); + return; + } + } else { + dxFormat = (DXGI_FORMAT)DXGI_FORMAT_P010; + extensionsAvailable = formatSupported(); + if (!extensionsAvailable) { + printf("DXGI_FORMAT_P010 is required for this test!\n"); + return; + } + } + + CompileKernel(); + AllocateOpenCLImage(); +} + +void OCLDX11YUY2::run(void) { + if (_errorFlag) return; + if (!extensionsAvailable) return; + + D3D11_TEXTURE2D_DESC Desc = {0}; + + Desc.ArraySize = 1; + Desc.BindFlags = 0; + Desc.Format = dxFormat; + Desc.Width = OCLDX11YUY2::WIDTH; + Desc.Height = OCLDX11YUY2::HEIGHT; + Desc.MipLevels = 1; + Desc.SampleDesc.Count = 1; + // Desc.MiscFlags=D3D11_RESOURCE_MISC_SHARED; //MM for fast GPU interop + // MM: these flags are incompatible with D3D11_RESOURCE_MISC_SHARED + // now we allocate texture without CPU access and if needed use temp texture + // (see FromSystemToDX11 and FromDX11ToSystem) + + Desc.Usage = D3D11_USAGE_STAGING; + Desc.BindFlags = 0; + Desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ; + + ID3D11Texture2D *pTextureTmp; + HRESULT hr = dxD3D11Device->CreateTexture2D(&Desc, NULL, &pTextureTmp); + + // fill memory + D3D11_MAPPED_SUBRESOURCE LockedRectD11; + if (SUCCEEDED(hr)) { + hr = + dxD3D11Context->Map(pTextureTmp, 0, D3D11_MAP_WRITE, 0, &LockedRectD11); + } + if (SUCCEEDED(hr)) { + // fill memory with something + for (int y = 0; y < OCLDX11YUY2::HEIGHT; y++) { + BYTE *pLine = (BYTE *)LockedRectD11.pData + y * LockedRectD11.RowPitch; + + BYTE *pLineUV = (BYTE *)LockedRectD11.pData + y * LockedRectD11.RowPitch + + OCLDX11YUY2::HEIGHT * LockedRectD11.RowPitch; + + for (int x = 0; x < OCLDX11YUY2::WIDTH; x++) { + *pLine++ = 0x7F; // Y + if (y < OCLDX11YUY2::HEIGHT / 2 && x < OCLDX11YUY2::WIDTH / 2) { + *pLineUV++ = 0x1F; // U + *pLineUV++ = 0x2F; // V + } + } + } + + dxD3D11Context->Unmap(pTextureTmp, 0); + } + Desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; + Desc.Usage = D3D11_USAGE_DEFAULT; + Desc.CPUAccessFlags = 0; + Desc.MiscFlags = (_openTest == 0) + ? 0 + : D3D11_RESOURCE_MISC_SHARED; // MM for fast GPU interop + + hr = dxD3D11Device->CreateTexture2D(&Desc, NULL, &dxDX11Texture); + + if (pTextureTmp != NULL) { + dxD3D11Context->CopySubresourceRegion(dxDX11Texture, 0, 0, 0, 0, + pTextureTmp, 0, NULL); + pTextureTmp->Release(); + } + testInterop(); +} + +void OCLDX11YUY2::AllocateOpenCLImage() { + cl_int status = 0; + + cl_image_format format{}; + format.image_channel_order = CL_R; + format.image_channel_data_type = + (dxFormat == DXGI_FORMAT_NV12) ? CL_UNSIGNED_INT8 : CL_UNSIGNED_INT16; + cl_image_desc descr{}; + descr.image_type = CL_MEM_OBJECT_IMAGE2D; + descr.image_width = WIDTH; + descr.image_height = HEIGHT + HEIGHT / 2; + + clImage2DOut = clCreateImage(context_, CL_MEM_WRITE_ONLY, &format, &descr, + NULL, &status); + CHECK_RESULT((status != CL_SUCCESS), "AllocateOpenCLImage() failed"); +} + +void OCLDX11YUY2::testInterop() { + // alloc + cl_int clStatus = 0; + cl_mem clImage2D = + clCreateFromD3D11Texture2DKHR(context_, 0, dxDX11Texture, 0, &clStatus); + CHECK_RESULT((clStatus != CL_SUCCESS), + "clCreateFromD3D11Texture2DKHR() failed"); + + // bring objects to the queue + cl_event clEvent = NULL; + clEnqueueAcquireD3D11ObjectsKHR(_queue, 1, &clImage2D, 0, NULL, &clEvent); + clStatus = clWaitForEvents(1, &clEvent); + clReleaseEvent(clEvent); + + CopyOpenCLImage(clImage2D); + bool ImageReadWorks = CheckCLImage(clImage2D); + bool bKernelWorks = CheckCLImage(clImage2DOut); + CHECK_RESULT_NO_RETURN((ImageReadWorks != true), + "CheckCLImage(clImage2D) failed"); + CHECK_RESULT_NO_RETURN((bKernelWorks != true), + "CheckCLImage(clImage2DOut) failed"); + + cl_mem planeY = clGetPlaneFromImageAMD(context_, clImage2D, 0, &clStatus); + CHECK_RESULT((clStatus != CL_SUCCESS), + "clGetPlaneFromImageAMD(context_,clImage2D,0,&clStatus) failed"); + + cl_mem planeUV = clGetPlaneFromImageAMD(context_, clImage2D, 1, &clStatus); + CHECK_RESULT((clStatus != CL_SUCCESS), + "clGetPlaneFromImageAMD(context_,clImage2D,1,&clStatus) failed"); + + bool ImageWorksY = CheckCLImageY(planeY); + bool ImageWorksUV = CheckCLImageUV(planeUV); + + clReleaseMemObject(planeY); + clReleaseMemObject(planeUV); + + // release + clEvent = NULL; + // release object from the queue + clStatus = + clEnqueueReleaseD3D11ObjectsKHR(_queue, 1, &clImage2D, 0, NULL, &clEvent); + clStatus = clWaitForEvents(1, &clEvent); + clReleaseEvent(clEvent); + + // release mem object + clReleaseMemObject(clImage2D); + + CHECK_RESULT_NO_RETURN((ImageWorksY != true), "CheckCLImageY() failed"); + CHECK_RESULT_NO_RETURN((ImageWorksUV != true), "CheckCLImageUV() failed"); +} + +unsigned int OCLDX11YUY2::close(void) { + if (clImage2DOut) clReleaseMemObject(clImage2DOut); + if (dxDX11Texture) dxDX11Texture->Release(); + return OCLDX11Common::close(); +} + +bool OCLDX11YUY2::CheckCLImage(cl_mem clImage) { + cl_int clStatus = 0; + + size_t pitch = 0; + clStatus = + clGetImageInfo(clImage, CL_IMAGE_ROW_PITCH, sizeof(pitch), &pitch, NULL); + pitch *= 2; + + cl_image_format format; + clStatus = + clGetImageInfo(clImage, CL_IMAGE_FORMAT, sizeof(format), &format, NULL); + + size_t height; + clStatus = + clGetImageInfo(clImage, CL_IMAGE_HEIGHT, sizeof(height), &height, NULL); + + CHECK_RESULT_NO_RETURN(height != (HEIGHT + HEIGHT / 2), + "CheckCLImage: height!=(HEIGHT+HEIGHT/2)"); + + char *pTempBuffer = new char[(HEIGHT + HEIGHT / 2) * pitch]; + + size_t origin[] = {0, 0, 0}; + size_t region[] = {WIDTH, HEIGHT + HEIGHT / 2, 1}; + clStatus = clEnqueueReadImage(_queue, clImage, 1, origin, region, pitch, 0, + pTempBuffer, 0, 0, 0); + + ::clFinish(_queue); + + // test + + bool bBreak = false; + for (int y = 0; y < HEIGHT && !bBreak; y++) { + char *pLine = (char *)pTempBuffer + y * pitch; + char *pLineUV = (char *)pTempBuffer + y * pitch + HEIGHT * pitch; + + for (int x = 0; x < WIDTH; x++) { + if (*pLine != 0x7F) // Y + { + bBreak = true; + break; + } + pLine++; + if (y < HEIGHT / 2 && x < WIDTH / 2) { + if (*pLineUV != 0x1F) // U + { + bBreak = true; + break; + } + pLineUV++; + if (*pLineUV != 0x2F) // V + { + bBreak = true; + break; + } + pLineUV++; + } + } + } + delete[] pTempBuffer; + + return !bBreak; +} + +bool OCLDX11YUY2::CheckCLImageY(cl_mem clImage) { + cl_int clStatus = 0; + + size_t pitch = 0; + clStatus = + clGetImageInfo(clImage, CL_IMAGE_ROW_PITCH, sizeof(pitch), &pitch, NULL); + pitch *= 2; + + cl_image_format format; + clStatus = + clGetImageInfo(clImage, CL_IMAGE_FORMAT, sizeof(format), &format, NULL); + + size_t height; + clStatus = + clGetImageInfo(clImage, CL_IMAGE_HEIGHT, sizeof(height), &height, NULL); + + CHECK_RESULT_NO_RETURN(height != HEIGHT, "CheckCLImageY: height!=HEIGHT"); + + char *pTempBuffer = new char[HEIGHT * pitch]; + + size_t origin[] = {0, 0, 0}; + size_t region[] = {WIDTH, HEIGHT, 1}; + clStatus = clEnqueueReadImage(_queue, clImage, 1, origin, region, pitch, 0, + pTempBuffer, 0, 0, 0); + + ::clFinish(_queue); + + // test + + bool bBreak = false; + for (int y = 0; y < HEIGHT && !bBreak; y++) { + char *pLine = (char *)pTempBuffer + y * pitch; + for (int x = 0; x < WIDTH; x++) { + if (*pLine != 0x7F) // Y + { + bBreak = true; + break; + } + pLine++; + } + } + + delete[] pTempBuffer; + + return !bBreak; +} + +bool OCLDX11YUY2::CheckCLImageUV(cl_mem clImage) { + cl_int clStatus = 0; + + size_t pitch = 0; + clStatus = + clGetImageInfo(clImage, CL_IMAGE_ROW_PITCH, sizeof(pitch), &pitch, NULL); + pitch *= 2; + size_t width = 0; + clStatus = + clGetImageInfo(clImage, CL_IMAGE_WIDTH, sizeof(width), &width, NULL); + + cl_image_format format; + clStatus = + clGetImageInfo(clImage, CL_IMAGE_FORMAT, sizeof(format), &format, NULL); + + size_t height; + clStatus = + clGetImageInfo(clImage, CL_IMAGE_HEIGHT, sizeof(height), &height, NULL); + + CHECK_RESULT_NO_RETURN(height != HEIGHT / 2, + "CheckCLImageUV: height!=HEIGHT/2"); + + char *pTempBuffer = new char[(HEIGHT / 2) * pitch]; + + size_t origin[] = {0, 0, 0}; + size_t region[] = {WIDTH / 2, HEIGHT / 2, 1}; + clStatus = clEnqueueReadImage(_queue, clImage, 1, origin, region, pitch, 0, + pTempBuffer, 0, 0, 0); + + ::clFinish(_queue); + + bool bBreak = false; + for (int y = 0; y < HEIGHT / 2 && !bBreak; y++) { + char *pLineUV = (char *)pTempBuffer + y * pitch; + for (int x = 0; x < WIDTH / 2; x++) { + if (*pLineUV != 0x1F) // U + { + bBreak = true; + break; + } + pLineUV++; + if (*pLineUV != 0x2F) // V + { + bBreak = true; + break; + } + pLineUV++; + } + } + delete[] pTempBuffer; + + return !bBreak; +} + +void OCLDX11YUY2::CopyOpenCLImage(cl_mem clImageSrc) { + cl_int status = 0; + + // Set appropriate arguments to the kernel2D + + // input buffer image + status = clSetKernelArg(kernel_, 0, sizeof(cl_mem), &clImageSrc); + CHECK_RESULT((status != CL_SUCCESS), + "CopyOpenCLImage() failed at " + "clSetKernelArg(kernel_,0,sizeof(cl_mem),&clImageSrc)"); + status = clSetKernelArg(kernel_, 1, sizeof(cl_mem), &clImage2DOut); + CHECK_RESULT((status != CL_SUCCESS), + "CopyOpenCLImage() failed at " + "clSetKernelArg(kernel_,1,sizeof(cl_mem),&clImage2DOut)"); + + // Enqueue a kernel run call. + size_t global_work_offset[] = {0, 0}; + size_t globalThreads[] = {WIDTH, HEIGHT + HEIGHT / 2}; + size_t localThreads[] = {blockSizeX, blockSizeY}; + + // status = + // clEnqueueNDRangeKernel(_queue,kernel_,2,NULL,globalThreads,localThreads,0,NULL,0); + status = clEnqueueNDRangeKernel(_queue, kernel_, 2, NULL, globalThreads, NULL, + 0, NULL, 0); + CHECK_RESULT((status != CL_SUCCESS), + "CopyOpenCLImage() failed at clEnqueueNDRangeKernel"); + + status = clFinish(_queue); + CHECK_RESULT((status != CL_SUCCESS), "CopyOpenCLImage() failed at clFinish"); +} + +void OCLDX11YUY2::CompileKernel() { + cl_int status = 0; + + size_t kernelSize = sizeof(strKernel); + const char *strs = (const char *)&strKernel[0]; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strs, + &kernelSize, &status); + + status = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], NULL, + NULL, NULL); + if (status != CL_SUCCESS) { + if (status == CL_BUILD_PROGRAM_FAILURE) { + cl_int logStatus; + size_t buildLogSize = 0; + logStatus = clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, buildLogSize, + NULL, &buildLogSize); + std::string buildLog; + buildLog.resize(buildLogSize); + + logStatus = clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, buildLogSize, + &buildLog[0], NULL); + printf("%s", buildLog.c_str()); + } + return; + } + // get a kernel object handle for a kernel with the given name + kernel_ = _wrapper->clCreateKernel(program_, "image2imageCopy", &status); + + size_t kernel2DWorkGroupSize = 0; + status = clGetKernelWorkGroupInfo(kernel_, devices_[_deviceId], + CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), + &kernel2DWorkGroupSize, 0); + + if ((blockSizeX * blockSizeY) > kernel2DWorkGroupSize) { + if (blockSizeX > kernel2DWorkGroupSize) { + blockSizeX = kernel2DWorkGroupSize; + blockSizeY = 1; + } + } +} + +bool OCLDX11YUY2::formatSupported() { + UINT supported = 0u; + dxD3D11Device->CheckFormatSupport(dxFormat, (UINT *)&supported); + return supported & D3D11_FORMAT_SUPPORT_TEXTURE2D; +} diff --git a/opencl/tests/ocltst/module/dx/OCLDX11YUY2.h b/opencl/tests/ocltst/module/dx/OCLDX11YUY2.h new file mode 100644 index 0000000000..bec8add212 --- /dev/null +++ b/opencl/tests/ocltst/module/dx/OCLDX11YUY2.h @@ -0,0 +1,56 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_DX11_YUY2_H_ +#define _OCL_DX11_YUY2_H_ + +#include "OCLDX11Common.h" + +class OCLDX11YUY2 : public OCLDX11Common { + public: + OCLDX11YUY2(); + virtual ~OCLDX11YUY2(); + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual void run(void); + virtual unsigned int close(void); + + protected: + static const unsigned int WIDTH = 1280; + static const unsigned int HEIGHT = 720; + + void testInterop(); + void AllocateOpenCLImage(); + bool CheckCLImage(cl_mem clImage); + bool CheckCLImageY(cl_mem clImage); + bool CheckCLImageUV(cl_mem clImage); + void CopyOpenCLImage(cl_mem clImageSrc); + void CompileKernel(); + bool formatSupported(); + void testFormat(); + + size_t blockSizeX; /**< Work-group size in x-direction */ + size_t blockSizeY; /**< Work-group size in y-direction */ + cl_mem clImage2DOut; + DXGI_FORMAT dxFormat; +}; + +#endif // _OCL_DX11_YUY2_H_ diff --git a/opencl/tests/ocltst/module/dx/TestList.cpp b/opencl/tests/ocltst/module/dx/TestList.cpp new file mode 100644 index 0000000000..ec3a3fc8df --- /dev/null +++ b/opencl/tests/ocltst/module/dx/TestList.cpp @@ -0,0 +1,52 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLTestListImp.h" + +// +// Includes for tests +// +#ifdef _WIN32 +#include "OCLDX11YUY2.h" +#endif + +// +// Helper macro for adding tests +// +template +static void* dictionary_CreateTestFunc(void) { + return new T(); +} + +#define TEST(name) \ + { #name, &dictionary_CreateTestFunc < name> } + +#ifdef _WIN32 + +TestEntry TestList[] = {TEST(OCLDX11YUY2)}; + +unsigned int TestListCount = sizeof(TestList) / sizeof(TestList[0]); +#else +TestEntry TestList[] = {{"void", 0}}; +unsigned int TestListCount = 0; + +#endif +unsigned int TestLibVersion = 0; +const char* TestLibName = "ocldx"; diff --git a/opencl/tests/ocltst/module/dx/ocldx.exclude b/opencl/tests/ocltst/module/dx/ocldx.exclude new file mode 100644 index 0000000000..39345e8fd7 --- /dev/null +++ b/opencl/tests/ocltst/module/dx/ocldx.exclude @@ -0,0 +1 @@ +# all clear diff --git a/opencl/tests/ocltst/module/gl/CMakeLists.txt b/opencl/tests/ocltst/module/gl/CMakeLists.txt new file mode 100644 index 0000000000..115879cf15 --- /dev/null +++ b/opencl/tests/ocltst/module/gl/CMakeLists.txt @@ -0,0 +1,84 @@ +set(TESTS + OCLGLBuffer + OCLGLBufferMultipleQueues + OCLGLDepthBuffer + OCLGLDepthTex + OCLGLFenceSync + OCLGLMsaaTexture + OCLGLMultiContext + OCLGLTexture + OCLGLPerfSepia +) + +add_library(oclgl SHARED + TestList.cpp + $) + +foreach(TEST ${TESTS}) + target_sources(oclgl + PRIVATE + ${TEST}.cpp) +endforeach() + +target_sources(oclgl + PRIVATE + ${OCLTST_DIR}/module/common/OCLGLCommon.cpp + ${OCLTST_DIR}/module/common/OCLGLCommonLinux.cpp) + +target_include_directories(oclgl + PUBLIC + ${OPENGL_INCLUDE_DIR} + ${GLEW_INCLUDE_DIRS}) + +set_target_properties(oclgl PROPERTIES + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests/ocltst + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests/ocltst) + +target_compile_definitions(oclgl + PRIVATE + $) + +target_include_directories(oclgl + PRIVATE + $) + +target_link_libraries(oclgl + PRIVATE + OpenCL + ${GLEW_LIBRARIES} + ${OPENGL_LIBRARIES}) + +add_custom_command( + TARGET oclgl POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/oclgl.exclude + ${CMAKE_BINARY_DIR}/tests/ocltst/ogl.exclude) + +add_custom_target(test.ocltst.oclgl + COMMAND + ${CMAKE_COMMAND} -E env "OCL_ICD_FILENAMES=$" + $ -p 0 -m $ -A oclgl.exclude + DEPENDS + ocltst oclgl amdocl + WORKING_DIRECTORY + ${CMAKE_BINARY_DIR}/tests/ocltst + USES_TERMINAL) + +foreach(TEST ${TESTS}) + add_custom_target(test.ocltst.oclgl.${TEST} + COMMAND + ${CMAKE_COMMAND} -E env "OCL_ICD_FILENAMES=$" + $ -p 0 -m $ -t ${TEST} + DEPENDS + ocltst oclgl amdocl + WORKING_DIRECTORY + ${CMAKE_BINARY_DIR}/tests/ocltst + USES_TERMINAL) +endforeach() + +INSTALL(TARGETS oclgl DESTINATION ${OCLTST_INSTALL_DIR} COMPONENT ocltst) +INSTALL(FILES oclgl.exclude DESTINATION ${OCLTST_INSTALL_DIR} COMPONENT ocltst) + diff --git a/opencl/tests/ocltst/module/gl/OCLGLBuffer.cpp b/opencl/tests/ocltst/module/gl/OCLGLBuffer.cpp new file mode 100644 index 0000000000..24423f543a --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLBuffer.cpp @@ -0,0 +1,220 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGLBuffer.h" + +#include +#include +#include +#include + +const static char* strKernel = + "__kernel void glbuffer_test( __global uint4 *source, __global uint4 " + "*glDest, __global uint4 *clDest) \n" + "{ " + " \n" + " int tid = get_global_id(0); " + " \n" + " clDest[ tid ] = source[ tid ] + (uint4)(1); " + " \n" + " glDest[ tid ] = source[ tid ] + (uint4)(2); " + " \n" + "} " + " \n"; + +OCLGLBuffer::OCLGLBuffer() : inGLBuffer_(0), outGLBuffer_(0) { + _numSubTests = 1; +} + +OCLGLBuffer::~OCLGLBuffer() {} + +void OCLGLBuffer::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + // Initialize random number seed + srand((unsigned int)time(NULL)); + + OCLGLCommon::open(test, units, conversion, deviceId); + if (_errorFlag) return; + + // Build the kernel + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateProgramWithSource() failed (%d)", error_); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed (%d)", error_); + + kernel_ = _wrapper->clCreateKernel(program_, "glbuffer_test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed (%d)", error_); +} + +void OCLGLBuffer::run(void) { + if (_errorFlag) { + return; + } + + cl_mem buffer; + cl_uint4 inData[c_numOfElements] = {{{0}}}; + cl_uint4 outDataCL[c_numOfElements] = {{{0}}}; + cl_uint4 outDataGL[c_numOfElements] = {{{0}}}; + + // Initialize input data with random values + for (unsigned int i = 0; i < c_numOfElements; i++) { + for (unsigned int j = 0; j < sizeof(cl_uint4) / sizeof(cl_uint); j++) { + inData[i].s[j] = (unsigned int)rand(); + } + } + + // Generate and Bind in & out OpenGL buffers + glGenBuffers(1, &inGLBuffer_); + glGenBuffers(1, &outGLBuffer_); + + glBindBuffer(GL_ARRAY_BUFFER, inGLBuffer_); + glBufferData(GL_ARRAY_BUFFER, c_numOfElements * sizeof(cl_uint4), inData, + GL_STATIC_DRAW); + + glBindBuffer(GL_ARRAY_BUFFER, outGLBuffer_); + glBufferData(GL_ARRAY_BUFFER, c_numOfElements * sizeof(cl_uint4), outDataGL, + GL_STATIC_DRAW); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glFinish(); + + // Create input buffer from GL input buffer + buffer = _wrapper->clCreateFromGLBuffer(context_, CL_MEM_READ_ONLY, + inGLBuffer_, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "Unable to create input GL buffer (%d)", + error_); + buffers_.push_back(buffer); + + // Create output buffer from GL output buffer + buffer = _wrapper->clCreateFromGLBuffer(context_, CL_MEM_WRITE_ONLY, + outGLBuffer_, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "Unable to create output GL buffer (%d)", + error_); + buffers_.push_back(buffer); + + // Create a CL output buffer + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + c_numOfElements * sizeof(cl_uint4), NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed (%d)", error_); + buffers_.push_back(buffer); + + // Assign args and execute + for (unsigned int i = 0; i < buffers_.size(); i++) { + error_ = + _wrapper->clSetKernelArg(kernel_, i, sizeof(cl_mem), &buffers()[i]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed (%d)", + error_); + } + + error_ = _wrapper->clEnqueueAcquireGLObjects(cmdQueues_[_deviceId], 2, + &buffers()[0], 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "Unable to acquire GL objects (%d)", + error_); + + size_t gws[1] = {c_numOfElements}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed (%d)", + error_); + + error_ = _wrapper->clEnqueueReleaseGLObjects(cmdQueues_[_deviceId], 2, + &buffers()[0], 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReleaseGLObjects failed (%d)", + error_); + + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + CHECK_RESULT((error_ != CL_SUCCESS), "clFinish() failed (%d)", error_); + + // Get the results from both CL and GL buffers + error_ = _wrapper->clEnqueueReadBuffer( + cmdQueues_[_deviceId], buffers()[2], CL_TRUE, 0, + c_numOfElements * sizeof(cl_uint4), outDataCL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "Unable to read output CL array! (%d)", + error_); + + glBindBuffer(GL_ARRAY_BUFFER, outGLBuffer_); + void* glMem = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY); + memcpy(outDataGL, glMem, c_numOfElements * sizeof(cl_uint4)); + glUnmapBuffer(GL_ARRAY_BUFFER); + + cl_uint4 expectedCL = {{0}}; + cl_uint4 expectedGL = {{0}}; + + // Check output + for (unsigned int i = 0; i < c_numOfElements; ++i) { + // Calculate expected value in CL output buffer (input + 1) + expectedCL = inData[i]; + expectedCL.s[0]++; + expectedCL.s[1]++; + expectedCL.s[2]++; + expectedCL.s[3]++; + + // Calculate expected value in GL output buffer (input + 2) + expectedGL = inData[i]; + expectedGL.s[0] += 2; + expectedGL.s[1] += 2; + expectedGL.s[2] += 2; + expectedGL.s[3] += 2; + + // Compare expected output with actual data received + for (unsigned int j = 0; j < sizeof(cl_uint4) / sizeof(cl_uint); j++) { + CHECK_RESULT((outDataCL[i].s[j] != expectedCL.s[j]), + "Element %d in CL output buffer is incorrect!\n\t \ + expected:{%d, %d, %d, %d} differs from actual:{%d, %d, %d, %d}", + i, expectedCL.s[0], expectedCL.s[1], expectedCL.s[2], + expectedCL.s[3], outDataCL[i].s[0], outDataCL[i].s[1], + outDataCL[i].s[2], outDataCL[i].s[3]); + CHECK_RESULT((outDataGL[i].s[j] != expectedGL.s[j]), + "Element %d in GL output buffer is incorrect!\n\t \ + expected:{%d, %d, %d, %d} differs from actual:{%d, %d, %d, %d}", + i, expectedGL.s[0], expectedGL.s[1], expectedGL.s[2], + expectedGL.s[3], outDataGL[i].s[0], outDataGL[i].s[1], + outDataGL[i].s[2], outDataGL[i].s[3]); + } + } +} + +unsigned int OCLGLBuffer::close(void) { + for (unsigned int i = 0; i < buffers().size(); ++i) { + clReleaseMemObject(buffers()[i]); + } + buffers_.clear(); + + // Delete GL in & out buffers + glBindBuffer(GL_ARRAY_BUFFER, 0); + glDeleteBuffers(1, &inGLBuffer_); + inGLBuffer_ = 0; + glDeleteBuffers(1, &outGLBuffer_); + outGLBuffer_ = 0; + + return OCLGLCommon::close(); +} diff --git a/opencl/tests/ocltst/module/gl/OCLGLBuffer.h b/opencl/tests/ocltst/module/gl/OCLGLBuffer.h new file mode 100644 index 0000000000..7fa098e064 --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLBuffer.h @@ -0,0 +1,42 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GL_BUFFER_H_ +#define _OCL_GL_BUFFER_H_ + +#include "OCLGLCommon.h" + +class OCLGLBuffer : public OCLGLCommon { + public: + OCLGLBuffer(); + virtual ~OCLGLBuffer(); + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual void run(void); + virtual unsigned int close(void); + + private: + static const unsigned int c_numOfElements = 1024; + GLuint inGLBuffer_; + GLuint outGLBuffer_; +}; + +#endif // _OCL_GL_BUFFER_H_ diff --git a/opencl/tests/ocltst/module/gl/OCLGLBufferMultipleQueues.cpp b/opencl/tests/ocltst/module/gl/OCLGLBufferMultipleQueues.cpp new file mode 100644 index 0000000000..af8601d582 --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLBufferMultipleQueues.cpp @@ -0,0 +1,303 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGLBufferMultipleQueues.h" + +#include +#include +#include +#include + +const static char* strKernel = + "__kernel void glbuffer_test( __global uint4 *source, __global uint4 " + "*glDest, __global uint4 *clDest) \n" + "{ " + " \n" + " int tid = get_global_id(0); " + " \n" + " glDest[ tid ] = source[ tid ] + (uint4)(2); " + " \n" + " clDest[ tid ] = source[ tid ] + (uint4)(1); " + " \n" + "} " + " \n"; + +OCLGLBufferMultipleQueues::OCLGLBufferMultipleQueues() { _numSubTests = 1; } + +OCLGLBufferMultipleQueues::~OCLGLBufferMultipleQueues() {} + +void OCLGLBufferMultipleQueues::open(unsigned int test, char* units, + double& conversion, + unsigned int deviceId) { + // Initialize random number seed + srand((unsigned int)time(NULL)); + + OCLGLCommon::open(test, units, conversion, deviceId); + if (_errorFlag) return; + + // Create multiple queues for the device (first add already created queue in + // OCLGLCommon::open, then add a second queue) + deviceCmdQueues_.resize(QUEUES_PER_DEVICE_COUNT); + deviceCmdQueues_[0] = cmdQueues_[deviceId]; + for (int queueIndex = 1; queueIndex < QUEUES_PER_DEVICE_COUNT; queueIndex++) { + cl_command_queue cmdQueue = _wrapper->clCreateCommandQueue( + context_, devices_[deviceId], 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueue() failed"); + deviceCmdQueues_[queueIndex] = cmdQueue; + } + + // Build the kernel + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateProgramWithSource() failed (%d)", error_); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed (%d)", error_); + + kernel_ = _wrapper->clCreateKernel(program_, "glbuffer_test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed (%d)", error_); +} + +void OCLGLBufferMultipleQueues::run(void) { + if (_errorFlag) { + return; + } + + inputGLBufferPerQueue_.resize(QUEUES_PER_DEVICE_COUNT, NULL); + outputGLBufferPerQueue_.resize(QUEUES_PER_DEVICE_COUNT, NULL); + outputCLBufferPerQueue_.resize(QUEUES_PER_DEVICE_COUNT, NULL); + + std::vector > inData( + QUEUES_PER_DEVICE_COUNT); // Input data per queue + + inGLBufferIDs_.resize(QUEUES_PER_DEVICE_COUNT, 0); + outGLBufferIDs_.resize(QUEUES_PER_DEVICE_COUNT, 0); + for (int queueIndex = 0; queueIndex < QUEUES_PER_DEVICE_COUNT; queueIndex++) { + // Initialize input data with random values + inData[queueIndex].resize(BUFFER_ELEMENTS_COUNT); + for (int i = 0; i < BUFFER_ELEMENTS_COUNT; i++) { + for (unsigned int j = 0; j < sizeof(cl_uint4) / sizeof(cl_uint); j++) { + inData[queueIndex][i].s[j] = (unsigned int)rand(); + } + } + + // Generate and Bind in & out OpenGL buffers + glGenBuffers(1, &inGLBufferIDs_[queueIndex]); + glGenBuffers(1, &outGLBufferIDs_[queueIndex]); + + glBindBuffer(GL_ARRAY_BUFFER, inGLBufferIDs_[queueIndex]); + glBufferData(GL_ARRAY_BUFFER, BUFFER_ELEMENTS_COUNT * sizeof(cl_uint4), + &inData[queueIndex][0], GL_STATIC_DRAW); + + glBindBuffer(GL_ARRAY_BUFFER, outGLBufferIDs_[queueIndex]); + glBufferData(GL_ARRAY_BUFFER, BUFFER_ELEMENTS_COUNT * sizeof(cl_uint4), + NULL, GL_STATIC_DRAW); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glFinish(); + + // Create input buffer from GL input buffer + inputGLBufferPerQueue_[queueIndex] = _wrapper->clCreateFromGLBuffer( + context_, CL_MEM_READ_ONLY, inGLBufferIDs_[queueIndex], &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "Unable to create input GL buffer (%d)", error_); + + // Create output buffer from GL output buffer + outputGLBufferPerQueue_[queueIndex] = _wrapper->clCreateFromGLBuffer( + context_, CL_MEM_WRITE_ONLY, outGLBufferIDs_[queueIndex], &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "Unable to create output GL buffer (%d)", error_); + + // Create a CL output buffer + outputCLBufferPerQueue_[queueIndex] = _wrapper->clCreateBuffer( + context_, CL_MEM_WRITE_ONLY, BUFFER_ELEMENTS_COUNT * sizeof(cl_uint4), + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed (%d)", + error_); + } + + for (int queueIndex = 0; queueIndex < QUEUES_PER_DEVICE_COUNT; queueIndex++) { + // Assign arguments to kernel according to queue index + error_ = _wrapper->clSetKernelArg( + kernel_, 0, sizeof(cl_mem), + &inputGLBufferPerQueue_[queueIndex]); // Input source + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed (%d)", + error_); + error_ = _wrapper->clSetKernelArg( + kernel_, 1, sizeof(cl_mem), + &outputGLBufferPerQueue_[queueIndex]); // Output glDest + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed (%d)", + error_); + error_ = _wrapper->clSetKernelArg( + kernel_, 2, sizeof(cl_mem), + &outputCLBufferPerQueue_[queueIndex]); // Output clDest + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed (%d)", + error_); + + // Acquire input GL buffer + error_ = _wrapper->clEnqueueAcquireGLObjects( + deviceCmdQueues_[queueIndex], 1, &inputGLBufferPerQueue_[queueIndex], 0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "Unable to acquire GL objects (%d)", + error_); + + // Acquire output GL buffer + error_ = _wrapper->clEnqueueAcquireGLObjects( + deviceCmdQueues_[queueIndex], 1, &outputGLBufferPerQueue_[queueIndex], + 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "Unable to acquire GL objects (%d)", + error_); + + // Enqueue the kernel + size_t gws[1] = {BUFFER_ELEMENTS_COUNT}; + error_ = + _wrapper->clEnqueueNDRangeKernel(deviceCmdQueues_[queueIndex], kernel_, + 1, NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed (%d)", + error_); + + // Release input GL buffer + error_ = _wrapper->clEnqueueReleaseGLObjects( + deviceCmdQueues_[queueIndex], 1, &inputGLBufferPerQueue_[queueIndex], 0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), + "clEnqueueReleaseGLObjects failed (%d)", error_); + + // Release output GL buffer + error_ = _wrapper->clEnqueueReleaseGLObjects( + deviceCmdQueues_[queueIndex], 1, &outputGLBufferPerQueue_[queueIndex], + 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), + "clEnqueueReleaseGLObjects failed (%d)", error_); + + // Flush commands in order to trigger the operations + error_ = _wrapper->clFlush(deviceCmdQueues_[queueIndex]); + CHECK_RESULT((error_ != CL_SUCCESS), "clFlush() failed (%d)", error_); + } + + for (int queueIndex = 0; queueIndex < QUEUES_PER_DEVICE_COUNT; queueIndex++) { + // Get the results from CL buffer (in a synchronous manner) + cl_uint4 outDataCL[BUFFER_ELEMENTS_COUNT]; + error_ = _wrapper->clEnqueueReadBuffer( + deviceCmdQueues_[queueIndex], outputCLBufferPerQueue_[queueIndex], + CL_TRUE, 0, BUFFER_ELEMENTS_COUNT * sizeof(cl_uint4), outDataCL, 0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "Unable to read output CL array! (%d)", + error_); + + cl_uint4 outDataGL[BUFFER_ELEMENTS_COUNT] = {{{0}}}; + glBindBuffer(GL_ARRAY_BUFFER, outGLBufferIDs_[queueIndex]); // why again + void* glMem = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY); + memcpy(outDataGL, glMem, BUFFER_ELEMENTS_COUNT * sizeof(cl_uint4)); + glUnmapBuffer(GL_ARRAY_BUFFER); + + cl_uint4 expectedCL = {{0}}; + cl_uint4 expectedGL = {{0}}; + + // Check output + for (int i = 0; i < BUFFER_ELEMENTS_COUNT; ++i) { + // Calculate expected value in CL output buffer (input + 1) + expectedCL = inData[queueIndex][i]; + expectedCL.s[0]++; + expectedCL.s[1]++; + expectedCL.s[2]++; + expectedCL.s[3]++; + + // Calculate expected value in GL output buffer (input + 2) + expectedGL = inData[queueIndex][i]; + expectedGL.s[0] += 2; + expectedGL.s[1] += 2; + expectedGL.s[2] += 2; + expectedGL.s[3] += 2; + + // Compare expected output with actual data received + for (unsigned int j = 0; j < sizeof(cl_uint4) / sizeof(cl_uint); j++) { + CHECK_RESULT((outDataCL[i].s[j] != expectedCL.s[j]), + "Element %d in CL output buffer is incorrect!\n\t \ + expected:{%d, %d, %d, %d} differs from actual:{%d, %d, %d, %d}", + i, expectedCL.s[0], expectedCL.s[1], expectedCL.s[2], + expectedCL.s[3], outDataCL[i].s[0], outDataCL[i].s[1], + outDataCL[i].s[2], outDataCL[i].s[3]); + CHECK_RESULT((outDataGL[i].s[j] != expectedGL.s[j]), + "Element %d in GL output buffer is incorrect!\n\t \ + expected:{%d, %d, %d, %d} differs from actual:{%d, %d, %d, %d}", + i, expectedGL.s[0], expectedGL.s[1], expectedGL.s[2], + expectedGL.s[3], outDataGL[i].s[0], outDataGL[i].s[1], + outDataGL[i].s[2], outDataGL[i].s[3]); + } + } + } +} + +unsigned int OCLGLBufferMultipleQueues::close(void) { + // Release cl buffers (must be done before releasing the associated GL + // buffers) + for (int bufferIndex = 0; bufferIndex < (int)inputGLBufferPerQueue_.size(); + bufferIndex++) { + error_ = _wrapper->clReleaseMemObject(inputGLBufferPerQueue_[bufferIndex]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseMemObject() failed"); + } + + for (int bufferIndex = 0; bufferIndex < (int)outputGLBufferPerQueue_.size(); + bufferIndex++) { + error_ = _wrapper->clReleaseMemObject(outputGLBufferPerQueue_[bufferIndex]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseMemObject() failed"); + } + + for (int bufferIndex = 0; bufferIndex < (int)outputCLBufferPerQueue_.size(); + bufferIndex++) { + error_ = _wrapper->clReleaseMemObject(outputCLBufferPerQueue_[bufferIndex]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseMemObject() failed"); + } + + // Delete GL in & out buffers + glBindBuffer(GL_ARRAY_BUFFER, 0); + if (!inGLBufferIDs_.empty()) { + glDeleteBuffers((int)inGLBufferIDs_.size(), &inGLBufferIDs_[0]); + } + + if (!outGLBufferIDs_.empty()) { + glDeleteBuffers((int)outGLBufferIDs_.size(), &outGLBufferIDs_[0]); + } + + // Release queues created by open method, the first queue per device is + // released by base class + for (int queueIndex = 1; queueIndex < (int)deviceCmdQueues_.size(); + queueIndex++) { + error_ = _wrapper->clReleaseCommandQueue(deviceCmdQueues_[queueIndex]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseCommandQueue() failed"); + } + deviceCmdQueues_.clear(); + + return OCLGLCommon::close(); +} diff --git a/opencl/tests/ocltst/module/gl/OCLGLBufferMultipleQueues.h b/opencl/tests/ocltst/module/gl/OCLGLBufferMultipleQueues.h new file mode 100644 index 0000000000..eabe876f09 --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLBufferMultipleQueues.h @@ -0,0 +1,48 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GL_BUFFER_MULTIPLE_QUEUES_H_ +#define _OCL_GL_BUFFER_MULTIPLE_QUEUES_H_ + +#include "OCLGLCommon.h" + +class OCLGLBufferMultipleQueues : public OCLGLCommon { + public: + OCLGLBufferMultipleQueues(); + virtual ~OCLGLBufferMultipleQueues(); + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual void run(void); + virtual unsigned int close(void); + + private: + static const int BUFFER_ELEMENTS_COUNT = 1024; + static const int QUEUES_PER_DEVICE_COUNT = 2; + std::vector + deviceCmdQueues_; // Multiple queues per device (single device) + std::vector inputGLBufferPerQueue_; // Input GL buffer per queue + std::vector outputGLBufferPerQueue_; // Output GL buffer per queue + std::vector outputCLBufferPerQueue_; // Input CL buffer per queue + std::vector inGLBufferIDs_; // Input GL buffers IDs + std::vector outGLBufferIDs_; // Output GL buffers IDs +}; + +#endif // _OCL_GL_BUFFER_MULTIPLE_QUEUES_H_ diff --git a/opencl/tests/ocltst/module/gl/OCLGLDepthBuffer.cpp b/opencl/tests/ocltst/module/gl/OCLGLDepthBuffer.cpp new file mode 100644 index 0000000000..21a6ee1a3b --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLDepthBuffer.cpp @@ -0,0 +1,270 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGLDepthBuffer.h" + +#include +#include +#include +#include + +const static char* strKernel = + "#pragma OPENCL EXTENSION cl_amd_printf : enable\n" + "__kernel void gldepths_test( __global float *output, read_only image2d_t " + "source, sampler_t sampler){ \n" + " int tidX = get_global_id(0);\n" + " int tidY = get_global_id(1);\n" + " float4 value = read_imagef( source, sampler, (int2)( tidX, tidY ) );\n" + " output[ tidY * get_image_width( source ) + tidX ] = value.z;\n" + "}\n"; + +OCLGLDepthBuffer::OCLGLDepthBuffer() + : glDepthBuffer_(0), + frameBufferOBJ_(0), + colorBuffer_(0), + clOutputBuffer_(0), + clDepth_(0), + clSampler_(0), + pGLOutput_(0), + pCLOutput_(0), + extensionSupported_(false) { + _numSubTests = 2; + _currentTest = 0; +} + +OCLGLDepthBuffer::~OCLGLDepthBuffer() {} + +void OCLGLDepthBuffer::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLGLCommon::open(test, units, conversion, deviceId); + if (_errorFlag) return; + + char* pExtensions = (char*)malloc(8192); + size_t returnSize; + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_EXTENSIONS, 8192, + pExtensions, &returnSize); + + // if extension if not supported + if (!strstr(pExtensions, "cl_khr_gl_depth_images")) { + printf("skipping test depth interop not supported\n"); + free(pExtensions); + return; + } + free(pExtensions); + extensionSupported_ = true; + + _currentTest = test; + + // Build the kernel + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateProgramWithSource() failed (%d)", error_); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed (%d)", error_); + + kernel_ = _wrapper->clCreateKernel(program_, "gldepths_test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed (%d)", error_); +} + +void OCLGLDepthBuffer::run(void) { + if (_errorFlag || !extensionSupported_) { + return; + } + bool retVal; + switch (_currentTest) { + case 0: + retVal = testDepthRead(GL_DEPTH_COMPONENT32F, GL_DEPTH_ATTACHMENT); + break; + case 1: + retVal = testDepthRead(GL_DEPTH_COMPONENT16, GL_DEPTH_ATTACHMENT); + break; + case 2: + retVal = testDepthRead(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL_ATTACHMENT); + break; + case 3: + retVal = testDepthRead(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL_ATTACHMENT); + break; + default: + CHECK_RESULT(true, "unsupported test number\n"); + } + CHECK_RESULT((retVal != true), "cl-gl depth test failed "); +} + +bool OCLGLDepthBuffer::testDepthRead(GLint internalFormat, + GLenum attachmentType) { + cl_int error; + size_t dimSizes[] = {c_dimSize, c_dimSize}; + + unsigned int bufferSize = c_dimSize * c_dimSize * 4; + bool retVal = false; + + pGLOutput_ = (float*)malloc(bufferSize); + pCLOutput_ = (float*)malloc(bufferSize); + // create Frame buffer object + glGenFramebuffers(1, &frameBufferOBJ_); + + // create textures + glGenTextures(1, &colorBuffer_); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, colorBuffer_); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, c_dimSize, c_dimSize, 0, GL_RGBA, + GL_UNSIGNED_BYTE, 0); + glBindTexture(GL_TEXTURE_2D, 0); + // create a renderbuffer for the depth/stencil buffer + glGenRenderbuffers(1, &glDepthBuffer_); + glBindRenderbuffer(GL_RENDERBUFFER, glDepthBuffer_); + glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, c_dimSize, c_dimSize); + + // + glBindFramebuffer(GL_FRAMEBUFFER, frameBufferOBJ_); + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colorBuffer_, 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachmentType, GL_RENDERBUFFER, + glDepthBuffer_); + + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (GL_FRAMEBUFFER_COMPLETE != status) { + return false; + } + // set up gl state machine + glViewport(0, 0, c_dimSize, c_dimSize); // Reset The Current Viewport + glMatrixMode(GL_PROJECTION); // Select The Projection Matrix + glLoadIdentity(); // Reset The Projection Matrix + gluPerspective(30.0f, (GLfloat)c_dimSize / (GLfloat)c_dimSize, 0.1f, 100.0f); + glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix + glLoadIdentity(); + glEnable(GL_DEPTH_TEST); + // The Type Of Depth Testing To Do + glClear(GL_COLOR_BUFFER_BIT | + GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer + glBegin(GL_QUADS); // Draw A Quad + glVertex3f(-1.0f, 1.0f, -6.0f); // Top Left + glVertex3f(1.0f, 1.0f, -6.0f); // Top Right + glVertex3f(1.0f, -1.0f, -3.0f); // Bottom Right + glVertex3f(-1.0f, -1.0f, -3.0f); // Bottom Left + glEnd(); + + glFinish(); + + clDepth_ = _wrapper->clCreateFromGLRenderbuffer(context_, CL_MEM_READ_WRITE, + glDepthBuffer_, &error); + if (CL_SUCCESS != error) { + printf("clCreateFromGLRenderbuffer failed\n"); + return false; + } + + clOutputBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, + bufferSize, NULL, &error); + if (CL_SUCCESS != error) return false; + + clSampler_ = _wrapper->clCreateSampler(context_, CL_FALSE, CL_ADDRESS_NONE, + CL_FILTER_NEAREST, &error); + if (CL_SUCCESS != error) return false; + + error = _wrapper->clEnqueueAcquireGLObjects(cmdQueues_[_deviceId], 1, + &clDepth_, 0, NULL, NULL); + + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &clOutputBuffer_); + + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), &clDepth_); + + _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_sampler), &clSampler_); + + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 2, NULL, + dimSizes, NULL, 0, NULL, NULL); + + _wrapper->clEnqueueReleaseGLObjects(cmdQueues_[_deviceId], 1, &clDepth_, 0, + NULL, NULL); + + _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], clOutputBuffer_, CL_TRUE, + 0, bufferSize, pCLOutput_, 0, NULL, NULL); + + glReadPixels(0, 0, c_dimSize, c_dimSize, GL_DEPTH_COMPONENT, GL_FLOAT, + pGLOutput_); + + // test that both resources are identical. + if (0 == memcmp(pGLOutput_, pCLOutput_, bufferSize)) { + retVal = true; // test successful + } else { + printf("expected results is different from actual results\n"); + dumpBuffer(pGLOutput_, "GLDepth.csv", c_dimSize); + dumpBuffer(pCLOutput_, "CLDepth.csv", c_dimSize); + } + + return retVal; +} + +unsigned int OCLGLDepthBuffer::close(void) { + if (pGLOutput_) { + free(pGLOutput_); + pGLOutput_ = NULL; + } + + if (pCLOutput_) { + free(pCLOutput_); + pCLOutput_ = NULL; + } + + clReleaseMemObject(clDepth_); + clReleaseMemObject(clOutputBuffer_); + clReleaseSampler(clSampler_); + // unbind the texture and frame buffer. + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 0, 0); + glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, 0, 0); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + // clean gl resources + glDeleteFramebuffers(1, &frameBufferOBJ_); + frameBufferOBJ_ = 0; + glDeleteTextures(1, &colorBuffer_); + colorBuffer_ = 0; + glDeleteTextures(1, &glDepthBuffer_); + glDepthBuffer_ = 0; + + return OCLGLCommon::close(); +} + +// helper functions +unsigned int OCLGLDepthBuffer::formatToSize(GLint internalFormat) { + switch (internalFormat) { + case GL_DEPTH_COMPONENT32F: + return 4; + break; + case GL_DEPTH_COMPONENT16: + return 2; + break; + case GL_DEPTH24_STENCIL8: + return 4; + break; + case GL_DEPTH32F_STENCIL8: + return 8; + break; + default: + return 0; + } +} diff --git a/opencl/tests/ocltst/module/gl/OCLGLDepthBuffer.h b/opencl/tests/ocltst/module/gl/OCLGLDepthBuffer.h new file mode 100644 index 0000000000..b94722d503 --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLDepthBuffer.h @@ -0,0 +1,66 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GL_DEPTH_BUFFER_H_ +#define _OCL_GL_DEPTH_BUFFER_H_ + +#include "OCLGLCommon.h" + +class OCLGLDepthBuffer : public OCLGLCommon { + public: + OCLGLDepthBuffer(); + virtual ~OCLGLDepthBuffer(); + static const unsigned int c_dimSize = 128; + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual void run(void); + virtual unsigned int close(void); + + private: + //////////////////// + // test functions // + //////////////////// + bool testDepthRead(GLint internalFormat, GLenum attachmentType); + unsigned int _currentTest; + ///////////////////// + // private members // + ///////////////////// + // GL resource identifiers + GLuint glDepthBuffer_; + GLuint frameBufferOBJ_; + GLuint colorBuffer_; + + // CL identifiers + cl_mem clOutputBuffer_; + cl_mem clDepth_; + cl_sampler clSampler_; + + // pointers to buffers + float* pGLOutput_; + float* pCLOutput_; + bool extensionSupported_; + ////////////////////////////// + // private helper functions // + ////////////////////////////// + // returns element size in bytes. + static unsigned int formatToSize(GLint internalFormat); +}; + +#endif // _OCL_GL_BUFFER_H_ diff --git a/opencl/tests/ocltst/module/gl/OCLGLDepthTex.cpp b/opencl/tests/ocltst/module/gl/OCLGLDepthTex.cpp new file mode 100644 index 0000000000..72a2cb824c --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLDepthTex.cpp @@ -0,0 +1,278 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGLDepthTex.h" + +#include +#include +#include +#include +#include + +const static char* strKernel = + "__kernel void gldepths_test( __global float *output, read_only image2d_t " + "source, sampler_t sampler){ \n" + " int tidX = get_global_id(0);\n" + " int tidY = get_global_id(1);\n" + " float4 value = read_imagef( source, sampler, (int2)( tidX, tidY ) );\n" + " output[ tidY * get_image_width( source ) + tidX ] = value.z;\n" + "}\n"; + +OCLGLDepthTex::OCLGLDepthTex() + : glDepthBuffer_(0), + frameBufferOBJ_(0), + colorBuffer_(0), + clOutputBuffer_(0), + clDepth_(0), + clSampler_(0), + pGLOutput_(0), + pCLOutput_(0), + extensionSupported_(false) { + _numSubTests = 8; + _currentTest = 0; +} + +OCLGLDepthTex::~OCLGLDepthTex() {} + +void OCLGLDepthTex::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLGLCommon::open(test, units, conversion, deviceId); + if (_errorFlag) return; + + char* pExtensions = (char*)malloc(8192); + size_t returnSize; + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_EXTENSIONS, 8192, + pExtensions, &returnSize); + + // if extension if not supported + if (!strstr(pExtensions, "cl_khr_gl_depth_images")) { + free(pExtensions); + printf("skipping test depth interop not supported\n"); + return; + } + free(pExtensions); + extensionSupported_ = true; + + static const char* OpenCL20Kernel = "-cl-std=CL2.0"; + const char* options = OpenCL20Kernel; + if (test < 4) { + options = NULL; + } + _currentTest = test % 4; + + // Build the kernel + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateProgramWithSource() failed (%d)", error_); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], options, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed (%d)", error_); + + kernel_ = _wrapper->clCreateKernel(program_, "gldepths_test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed (%d)", error_); +} + +void OCLGLDepthTex::run(void) { + if (_errorFlag || !extensionSupported_) { + return; + } + bool retVal; + switch (_currentTest) { + case 0: + retVal = testDepthRead(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, + GL_UNSIGNED_INT_24_8); + break; + case 1: + retVal = + testDepthRead(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_FLOAT); + break; + case 2: + retVal = + testDepthRead(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT); + break; + case 3: + retVal = testDepthRead(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, + GL_FLOAT_32_UNSIGNED_INT_24_8_REV); + break; + default: + CHECK_RESULT(true, "unsupported test number\n"); + } + CHECK_RESULT((retVal != true), "cl-gl depth test failed "); +} + +bool OCLGLDepthTex::testDepthRead(GLint internalFormat, GLenum format, + GLenum type) { + const unsigned int bufferSize = c_dimSize * c_dimSize * 4; + + pGLOutput_ = (float*)malloc(bufferSize); + pCLOutput_ = (float*)malloc(bufferSize); + size_t dimSizes[] = {c_dimSize, c_dimSize}; + + bool retVal = false; + // create Frame buffer object + glGenFramebuffers(1, &frameBufferOBJ_); + glBindFramebuffer(GL_FRAMEBUFFER, frameBufferOBJ_); + + // create textures + glGenTextures(1, &colorBuffer_); + glBindTexture(GL_TEXTURE_2D, colorBuffer_); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, c_dimSize, c_dimSize, 0, GL_RGBA, + GL_UNSIGNED_BYTE, 0); + + glGenTextures(1, &glDepthBuffer_); + glBindTexture(GL_TEXTURE_2D, glDepthBuffer_); + glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, c_dimSize, c_dimSize, 0, + format, type, 0); + GLint glError = glGetError(); + // + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colorBuffer_, 0); + + if (GL_DEPTH_COMPONENT == format) { + glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, glDepthBuffer_, + 0); + } else { + glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, + glDepthBuffer_, 0); + } + + glBindFramebuffer(GL_FRAMEBUFFER, frameBufferOBJ_); + + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (GL_FRAMEBUFFER_COMPLETE != status) { + printf("frame buffer incomplete!\n"); + return false; + } + // set up gl state machine + glViewport(0, 0, c_dimSize, c_dimSize); // Reset The Current Viewport + glMatrixMode(GL_PROJECTION); // Select The Projection Matrix + glLoadIdentity(); // Reset The Projection Matrix + gluPerspective(30.0f, (GLfloat)c_dimSize / (GLfloat)c_dimSize, 0.1f, 100.0f); + glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix + glLoadIdentity(); + glEnable(GL_DEPTH_TEST); + glBindFramebuffer(GL_FRAMEBUFFER, frameBufferOBJ_); + + cl_int error; + + clOutputBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, + bufferSize, NULL, &error); + if (CL_SUCCESS != error) return false; + + clSampler_ = _wrapper->clCreateSampler(context_, CL_FALSE, CL_ADDRESS_NONE, + CL_FILTER_NEAREST, &error); + if (CL_SUCCESS != error) return false; + + clDepth_ = _wrapper->clCreateFromGLTexture( + context_, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, glDepthBuffer_, &error); + if (CL_SUCCESS != error) return false; + + for (int i = 0; i < 3; ++i) { + // The Type Of Depth Testing To Do + glClear(GL_COLOR_BUFFER_BIT | + GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer + + const float zValues[3][2] = { + {-6.f, -3.f}, + {-5.f, -2.f}, + {-4.f, -1.f}, + }; + + glBegin(GL_QUADS); // Draw A Quad + glVertex3f(-1.0f, 1.0f, zValues[i][0]); // Top Left + glVertex3f(1.0f, 1.0f, zValues[i][0]); // Top Right + glVertex3f(1.0f, -1.0f, zValues[i][1]); // Bottom Right + glVertex3f(-1.0f, -1.0f, zValues[i][1]); // Bottom Left + glEnd(); + + glFinish(); + + error = _wrapper->clEnqueueAcquireGLObjects(cmdQueues_[_deviceId], 1, + &clDepth_, 0, NULL, NULL); + + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &clOutputBuffer_); + + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), &clDepth_); + + _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_sampler), &clSampler_); + + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 2, NULL, + dimSizes, NULL, 0, NULL, NULL); + + _wrapper->clEnqueueReleaseGLObjects(cmdQueues_[_deviceId], 1, &clDepth_, 0, + NULL, NULL); + + _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], clOutputBuffer_, + CL_TRUE, 0, bufferSize, pCLOutput_, 0, NULL, + NULL); + + glReadPixels(0, 0, c_dimSize, c_dimSize, GL_DEPTH_COMPONENT, GL_FLOAT, + pGLOutput_); + + // test that both resources are identical. + if (0 == memcmp(pGLOutput_, pCLOutput_, bufferSize)) { + retVal = true; // test successful + } else { + printf("expected results is different from actual results\n"); + dumpBuffer(pGLOutput_, "GLDepth.csv", c_dimSize); + dumpBuffer(pCLOutput_, "clDepth_.csv", c_dimSize); + } + } + + return retVal; +} + +unsigned int OCLGLDepthTex::close(void) { + if (pGLOutput_) { + free(pGLOutput_); + pGLOutput_ = NULL; + } + + if (pCLOutput_) { + free(pCLOutput_); + pCLOutput_ = NULL; + } + + clReleaseMemObject(clDepth_); + clReleaseMemObject(clOutputBuffer_); + clReleaseSampler(clSampler_); + // unbind the texture and frame buffer. + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 0, 0); + glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, 0, 0); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + // clean gl resources + glDeleteFramebuffers(1, &frameBufferOBJ_); + frameBufferOBJ_ = 0; + glDeleteTextures(1, &colorBuffer_); + colorBuffer_ = 0; + glDeleteTextures(1, &glDepthBuffer_); + glDepthBuffer_ = 0; + + return OCLGLCommon::close(); +} diff --git a/opencl/tests/ocltst/module/gl/OCLGLDepthTex.h b/opencl/tests/ocltst/module/gl/OCLGLDepthTex.h new file mode 100644 index 0000000000..8ac33a9f62 --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLDepthTex.h @@ -0,0 +1,62 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GL_DEPTH_TEX_H_ +#define _OCL_GL_DEPTH_TEX_H_ + +#include "OCLGLCommon.h" + +class OCLGLDepthTex : public OCLGLCommon { + public: + OCLGLDepthTex(); + virtual ~OCLGLDepthTex(); + static const unsigned int c_dimSize = 128; + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual void run(void); + virtual unsigned int close(void); + + private: + //////////////////// + // test functions // + //////////////////// + bool testDepthRead(GLint internalFormat, GLenum format, GLenum type); + unsigned int _currentTest; + + ///////////////////// + // private members // + ///////////////////// + // GL resource identifiers + GLuint glDepthBuffer_; + GLuint frameBufferOBJ_; + GLuint colorBuffer_; + + // CL identifiers + cl_mem clOutputBuffer_; + cl_mem clDepth_; + cl_sampler clSampler_; + + // pointers to buffers + float* pGLOutput_; + float* pCLOutput_; + bool extensionSupported_; +}; + +#endif // _OCL_GL_BUFFER_H_ diff --git a/opencl/tests/ocltst/module/gl/OCLGLFenceSync.cpp b/opencl/tests/ocltst/module/gl/OCLGLFenceSync.cpp new file mode 100644 index 0000000000..cb79f1799f --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLFenceSync.cpp @@ -0,0 +1,481 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGLFenceSync.h" + +#include +#include +#include +#include + +#include "Timer.h" +#ifndef WIN_OS +#include +#endif + +const static char *strKernel = + "__kernel void glmulticontext_test( __global uint4 *source, __global uint4 " + "*dest) \n" + "{ " + " \n" + " int tid = get_global_id(0); " + " \n" + " dest[ tid ] = source [ tid ] + (uint4)(1); " + " \n" + "} " + " \n"; + +OCLGLFenceSync::OCLGLFenceSync() { + memset(contextData_, 0, sizeof(contextData_)); + _numSubTests = 2; +} + +OCLGLFenceSync::~OCLGLFenceSync() {} + +#ifdef WIN_OS +typedef GLsync(__stdcall *glFenceSyncPtr)(GLenum condition, GLbitfield flags); +typedef bool(__stdcall *glIsSyncPtr)(GLsync sync); +typedef void(__stdcall *glDeleteSyncPtr)(GLsync sync); +typedef GLenum(__stdcall *glClientWaitSyncPtr)(GLsync sync, GLbitfield flags, + GLuint64 timeout); +typedef void(__stdcall *glWaitSyncPtr)(GLsync sync, GLbitfield flags, + GLuint64 timeout); +typedef void(__stdcall *glGetInteger64vPtr)(GLenum pname, GLint64 *params); +typedef void(__stdcall *glGetSyncivPtr)(GLsync sync, GLenum pname, + GLsizei bufSize, GLsizei *length, + GLint *values); +#else +typedef GLsync (*glFenceSyncPtr)(GLenum condition, GLbitfield flags); +typedef bool (*glIsSyncPtr)(GLsync sync); +typedef void (*glDeleteSyncPtr)(GLsync sync); +typedef GLenum (*glClientWaitSyncPtr)(GLsync sync, GLbitfield flags, + GLuint64 timeout); +typedef void (*glWaitSyncPtr)(GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (*glGetInteger64vPtr)(GLenum pname, GLint64 *params); +typedef void (*glGetSyncivPtr)(GLsync sync, GLenum pname, GLsizei bufSize, + GLsizei *length, GLint *values); +#endif + +typedef struct __GLsync *GLsync; + +glFenceSyncPtr glFenceSyncFunc; + +glIsSyncPtr glIsSyncFunc; + +glDeleteSyncPtr glDeleteSyncFunc; + +glClientWaitSyncPtr glClientWaitSyncFunc; + +glWaitSyncPtr glWaitSyncFunc; + +glGetInteger64vPtr glGetInteger64vFunc; + +glGetSyncivPtr glGetSyncivFunc; + +#define CHK_GL_ERR() printf("%s\n", gluErrorString(glGetError())) + +#define cl_khr_gl_event 1 + +static void InitSyncFns() { +#ifdef WIN_OS + glFenceSyncFunc = (glFenceSyncPtr)wglGetProcAddress("glFenceSync"); + glIsSyncFunc = (glIsSyncPtr)wglGetProcAddress("glIsSync"); + glDeleteSyncFunc = (glDeleteSyncPtr)wglGetProcAddress("glDeleteSync"); + glClientWaitSyncFunc = + (glClientWaitSyncPtr)wglGetProcAddress("glClientWaitSync"); + glWaitSyncFunc = (glWaitSyncPtr)wglGetProcAddress("glWaitSync"); + glGetInteger64vFunc = + (glGetInteger64vPtr)wglGetProcAddress("glGetInteger64v"); + glGetSyncivFunc = (glGetSyncivPtr)wglGetProcAddress("glGetSynciv"); +#else + glFenceSyncFunc = (glFenceSyncPtr)glXGetProcAddress((GLubyte *)"glFenceSync"); + glIsSyncFunc = (glIsSyncPtr)glXGetProcAddress((GLubyte *)"glIsSync"); + glDeleteSyncFunc = + (glDeleteSyncPtr)glXGetProcAddress((GLubyte *)"glDeleteSync"); + glClientWaitSyncFunc = + (glClientWaitSyncPtr)glXGetProcAddress((GLubyte *)"glClientWaitSync"); + glWaitSyncFunc = (glWaitSyncPtr)glXGetProcAddress((GLubyte *)"glWaitSync"); + glGetInteger64vFunc = + (glGetInteger64vPtr)glXGetProcAddress((GLubyte *)"glGetInteger64v"); + glGetSyncivFunc = (glGetSyncivPtr)glXGetProcAddress((GLubyte *)"glGetSynciv"); +#endif +} + +#define USING_ARB_sync 1 + +typedef cl_event(CL_API_CALL *clCreateEventFromGLsyncKHR_fn)( + cl_context context, GLsync sync, cl_int *errCode_ret); + +clCreateEventFromGLsyncKHR_fn clCreateEventFromGLsyncKHR_ptr; + +/* Helper to determine if an extension is supported by a device */ +int is_extension_available(cl_device_id device, const char *extensionName) { + char *extString; + size_t size = 0; + int err; + int result = -1; + + if ((err = clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 0, NULL, &size))) { + printf( + "Error: failed to determine size of device extensions string (err = " + "%d)\n", + err); + return -2; + } + + if (0 == size) return -3; + + extString = (char *)malloc(size); + if (NULL == extString) { + printf( + "Error: unable to allocate %ld byte buffer for extension string (err = " + "%d)\n", + (long)size, err); + return -40; + } + + if ((err = clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, size, extString, + NULL))) { + printf("Error: failed to obtain device extensions string (err = %d)\n", + err); + free(extString); + return -5; + } + + if (strstr(extString, extensionName)) result = 0; + + free(extString); + return result; +} + +void OCLGLFenceSync::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + _openTest = test; + + // Initialize random number seed + srand((unsigned int)time(NULL)); + + OCLGLCommon::open(test, units, conversion, deviceId); + if (_errorFlag) return; + + cl_context_properties properties[7] = {0}; + for (unsigned int i = 0; i < c_glContextCount; i++) { + error_ = is_extension_available(devices_[_deviceId], "cl_khr_gl_event"); + if (error_ != CL_SUCCESS) { + printf("Silent failure: cl_khr_gl_event extension not available (%d)\n", + error_); + extensionSupported_ = false; + return; + } + extensionSupported_ = true; + + createGLContext(contextData_[i].glContext); + getCLContextPropertiesFromGLContext(contextData_[i].glContext, properties); + + // Create new CL context from GL context + contextData_[i].clContext = _wrapper->clCreateContext( + properties, 1, &devices_[_deviceId], NULL, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateContext() failed (%d)", + error_); + + // Create command queue for new context + contextData_[i].clCmdQueue = _wrapper->clCreateCommandQueue( + contextData_[i].clContext, devices_[_deviceId], 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueue() failed (%d)", + error_); + + // Build the kernel + contextData_[i].clProgram = _wrapper->clCreateProgramWithSource( + contextData_[i].clContext, 1, &strKernel, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateProgramWithSource() failed (%d)", error_); + + error_ = _wrapper->clBuildProgram(contextData_[i].clProgram, 1, + &devices_[deviceId], NULL, NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(contextData_[i].clProgram, + devices_[deviceId], CL_PROGRAM_BUILD_LOG, + 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed (%d)", + error_); + + contextData_[i].clKernel = _wrapper->clCreateKernel( + contextData_[i].clProgram, "glmulticontext_test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed (%d)", + error_); + } +} + +void OCLGLFenceSync::run() { + if (_errorFlag || !extensionSupported_) { + return; + } + + CPerfCounter timer; + double sec; + float perf; + cl_uint4 inOutData[c_numOfElements] = {{{0}}}; + cl_uint4 expectedData[c_numOfElements] = {{{0}}}; + unsigned int m = sizeof(cl_uint4) / sizeof(cl_uint); + int count = 0; + // Initialize input data with random values + for (unsigned int i = 0; i < c_numOfElements; i++) { + for (unsigned int j = 0; j < m; j++) { + inOutData[i].s[j] = (unsigned int)i; + expectedData[i].s[j] = inOutData[i].s[j] + c_glContextCount; + } + } + + cl_event fenceEvent0 = NULL, fenceEvent = NULL; + GLsync glFence0 = NULL, glFence = NULL; + InitSyncFns(); + + clCreateEventFromGLsyncKHR_ptr = + (clCreateEventFromGLsyncKHR_fn)clGetExtensionFunctionAddress( + "clCreateEventFromGLsyncKHR"); + if (clCreateEventFromGLsyncKHR_ptr == NULL) { + printf( + "ERROR: Unable to run fence_sync test (clCreateEventFromGLsyncKHR " + "function not discovered!)\n"); + return; + } + + for (unsigned int i = 0; i < c_glContextCount; i++) { + makeCurrent(contextData_[i].glContext); + + // Generate and Bind in & out OpenGL buffers + GLuint inGLBuffer = 0, outGLBuffer = 0; + glGenBuffers(1, &inGLBuffer); + glGenBuffers(1, &outGLBuffer); + + glBindBuffer(GL_ARRAY_BUFFER, inGLBuffer); + glBufferData(GL_ARRAY_BUFFER, c_numOfElements * sizeof(cl_uint4), inOutData, + GL_STATIC_DRAW); + + glBindBuffer(GL_ARRAY_BUFFER, outGLBuffer); + glBufferData(GL_ARRAY_BUFFER, c_numOfElements * sizeof(cl_uint4), NULL, + GL_STATIC_DRAW); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + + glFinish(); + + // Checking if clWaitForEvents works + switch (_openTest) { + case 0: // Using fence sync + glFence0 = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + CHECK_RESULT((glFence0 == NULL), "Unable to create GL fence"); + + fenceEvent0 = clCreateEventFromGLsyncKHR_ptr(contextData_[i].clContext, + glFence0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "Unable to create CL event from GL fence (%d)", error_); + + error_ = clWaitForEvents(1, &fenceEvent0); + CHECK_RESULT((error_ != CL_SUCCESS), "clWaitForEvents() failed (%d)", + error_); + break; + default: + glFinish(); + break; + } + + if (fenceEvent != NULL) { + clReleaseEvent(fenceEvent0); + glDeleteSync(glFence0); + } + + cl_event acqEvent1 = 0, acqEvent2 = 0, kernelEvent = 0, relEvent1 = 0, + relEvent2 = 0; + + // Create input buffer from GL input buffer + contextData_[i].inputBuffer = _wrapper->clCreateFromGLBuffer( + contextData_[i].clContext, CL_MEM_READ_ONLY, inGLBuffer, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "Unable to create input GL buffer (%d)", error_); + + // Create output buffer from GL output buffer + contextData_[i].outputBuffer = _wrapper->clCreateFromGLBuffer( + contextData_[i].clContext, CL_MEM_WRITE_ONLY, outGLBuffer, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "Unable to create output GL buffer (%d)", error_); + + timer.Reset(); + switch (_openTest) { + case 0: // Using fence sync + timer.Start(); + glFence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + timer.Stop(); + CHECK_RESULT((glFence == NULL), "Unable to create GL fence"); + + timer.Start(); + fenceEvent = clCreateEventFromGLsyncKHR_ptr(contextData_[i].clContext, + glFence, &error_); + timer.Stop(); + CHECK_RESULT((error_ != CL_SUCCESS), + "Unable to create CL event from GL fence (%d)", error_); + break; + default: + break; + } + + error_ = + _wrapper->clSetKernelArg(contextData_[i].clKernel, 0, sizeof(cl_mem), + &(contextData_[i].inputBuffer)); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed (%d)", + error_); + + error_ = + _wrapper->clSetKernelArg(contextData_[i].clKernel, 1, sizeof(cl_mem), + &(contextData_[i].outputBuffer)); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed (%d)", + error_); + + switch (_openTest) { + case 0: // Using fence sync + timer.Start(); + error_ = _wrapper->clEnqueueAcquireGLObjects( + contextData_[i].clCmdQueue, 1, &(contextData_[i].inputBuffer), 1, + &fenceEvent, &acqEvent1); + timer.Stop(); + CHECK_RESULT((error_ != CL_SUCCESS), + "Unable to acquire GL objects (%d)", error_); + + timer.Start(); + error_ = _wrapper->clEnqueueAcquireGLObjects( + contextData_[i].clCmdQueue, 1, &(contextData_[i].outputBuffer), 1, + &fenceEvent, &acqEvent2); + timer.Stop(); + CHECK_RESULT((error_ != CL_SUCCESS), + "Unable to acquire GL objects (%d)", error_); + break; + case 1: // Using glFinish + timer.Start(); + glFinish(); + timer.Stop(); + + timer.Start(); + error_ = _wrapper->clEnqueueAcquireGLObjects( + contextData_[i].clCmdQueue, 1, &(contextData_[i].inputBuffer), 0, + NULL, &acqEvent1); + timer.Stop(); + CHECK_RESULT((error_ != CL_SUCCESS), + "Unable to acquire GL objects (%d)", error_); + + timer.Start(); + error_ = _wrapper->clEnqueueAcquireGLObjects( + contextData_[i].clCmdQueue, 1, &(contextData_[i].outputBuffer), 0, + NULL, &acqEvent2); + timer.Stop(); + CHECK_RESULT((error_ != CL_SUCCESS), + "Unable to acquire GL objects (%d)", error_); + break; + default: + break; + } + + size_t gws[1] = {c_numOfElements}; + cl_event evts[2] = {acqEvent1, acqEvent2}; + error_ = _wrapper->clEnqueueNDRangeKernel(contextData_[i].clCmdQueue, + contextData_[i].clKernel, 1, NULL, + gws, NULL, 2, evts, &kernelEvent); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed (%d)", + error_); + + error_ = _wrapper->clEnqueueReleaseGLObjects(contextData_[i].clCmdQueue, 1, + &(contextData_[i].inputBuffer), + 1, &kernelEvent, &relEvent1); + CHECK_RESULT((error_ != CL_SUCCESS), + "clEnqueueReleaseGLObjects failed (%d)", error_); + + error_ = _wrapper->clEnqueueReleaseGLObjects( + contextData_[i].clCmdQueue, 1, &(contextData_[i].outputBuffer), 1, + &kernelEvent, &relEvent2); + CHECK_RESULT((error_ != CL_SUCCESS), + "clEnqueueReleaseGLObjects failed (%d)", error_); + + evts[0] = relEvent1; + evts[1] = relEvent2; + error_ = clWaitForEvents(2, evts); + CHECK_RESULT((error_ != CL_SUCCESS), "clWaitForEvents() failed (%d)", + error_); + + glBindBuffer(GL_ARRAY_BUFFER, outGLBuffer); + void *glMem = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY); + memcpy(inOutData, glMem, c_numOfElements * sizeof(cl_uint4)); + glUnmapBuffer(GL_ARRAY_BUFFER); + + _wrapper->clReleaseMemObject(contextData_[i].inputBuffer); + _wrapper->clReleaseMemObject(contextData_[i].outputBuffer); + + // Delete GL buffers + glBindBuffer(GL_ARRAY_BUFFER, 0); + glDeleteBuffers(1, &inGLBuffer); + inGLBuffer = 0; + glDeleteBuffers(1, &outGLBuffer); + outGLBuffer = 0; + } + + sec = timer.GetElapsedTime(); + perf = (float)sec * 1000000; // in microseconds + _perfInfo = (float)perf; + + if (fenceEvent != NULL) { + clReleaseEvent(fenceEvent); + glDeleteSync(glFence); + } + + // Compare expected output with actual data received + for (unsigned int i = 0; i < c_numOfElements; i++) { + for (unsigned int j = 0; j < m; j++) { + if (inOutData[i].s[j] != expectedData[i].s[j]) { + printf( + "Element %u is incorrect!\t expected:[ %u, %u, %u, %u ] differs " + "from actual:{%u, %u, %u, %u}\n", + i, expectedData[i].s[0], expectedData[i].s[1], expectedData[i].s[2], + expectedData[i].s[3], inOutData[i].s[0], inOutData[i].s[1], + inOutData[i].s[2], inOutData[i].s[3]); + + count++; + } + } + } + if (count) printf("Number of elements wrong: %d\n", count); +} + +unsigned int OCLGLFenceSync::close() { + error_ = is_extension_available(devices_[_deviceId], "cl_khr_gl_event"); + if (error_ == CL_SUCCESS) { + for (unsigned int i = 0; i < c_glContextCount; i++) { + makeCurrent(contextData_[i].glContext); + _wrapper->clReleaseKernel(contextData_[i].clKernel); + _wrapper->clReleaseProgram(contextData_[i].clProgram); + _wrapper->clReleaseCommandQueue(contextData_[i].clCmdQueue); + _wrapper->clReleaseContext(contextData_[i].clContext); + destroyGLContext(contextData_[i].glContext); + } + } + + return OCLGLCommon::close(); +} diff --git a/opencl/tests/ocltst/module/gl/OCLGLFenceSync.h b/opencl/tests/ocltst/module/gl/OCLGLFenceSync.h new file mode 100644 index 0000000000..017f0e068a --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLFenceSync.h @@ -0,0 +1,55 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GL_FENCE_SYNC_H_ +#define _OCL_GL_FENCE_SYNC_H_ + +#include "OCLGLCommon.h" + +class OCLGLFenceSync : public OCLGLCommon { + public: + OCLGLFenceSync(); + virtual ~OCLGLFenceSync(); + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual void run(void); + virtual unsigned int close(void); + + private: + static const unsigned int c_glContextCount = 1; + static const unsigned int c_numOfElements = 8192; + + struct GLContextDataSet { + OCLGLHandle glContext; + cl_context clContext; + cl_command_queue clCmdQueue; + cl_program clProgram; + cl_kernel clKernel; + cl_mem inputBuffer; + cl_mem outputBuffer; + }; + GLContextDataSet contextData_[c_glContextCount]; + + bool failed_; + bool extensionSupported_; +}; + +#endif // _OCL_GL_FENCE_SYNC_H_ diff --git a/opencl/tests/ocltst/module/gl/OCLGLMsaaTexture.cpp b/opencl/tests/ocltst/module/gl/OCLGLMsaaTexture.cpp new file mode 100644 index 0000000000..9df9c701a9 --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLMsaaTexture.cpp @@ -0,0 +1,298 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGLMsaaTexture.h" + +#include +#include +#include +#include + +const static char* strKernel = + "__kernel void gl_msaa_test( __global uint4 *output, read_only " + "image2d_msaa_t source, unsigned int numSamples){ \n" + " int tidX = get_global_id(0);\n" + " int tidY = get_global_id(1);\n" + " for (int i = 0 ; i < numSamples ; i++) {\n" + " uint4 value = read_imageui( source, (int2)( tidX, tidY ) ,i);\n" + " int index = (tidY * get_image_width( source ) + tidX)*numSamples + " + "i;\n" + " output[ index ] = value;\n" + " }\n" + "}\n"; + +const static char* glDownSampleShader = + "uniform sampler2DMS MsaaTex;\n" + "uniform int numSamples;\n" + "uniform ivec2 resolution;\n" + "\n" + "varying vec4 gl_TexCoord[ ]; \n" + "\n" + "void main(void)\n" + "{\n" + " vec4 accum = vec4(0.0,0.0,0.0,0.0);\n" + " ivec2 coord = ivec2(resolution * gl_TexCoord[0].xy) ;\n" + " for ( int i = 0 ; i < numSamples ; i++)\n" + " {\n" + " accum += texelFetch(MsaaTex,coord,i);\n" + " }\n" + " accum /= numSamples;\n" + " \n" + " \n" + " \n" + " gl_FragColor = accum;\n" + "}"; + +OCLGLMsaaTexture::OCLGLMsaaTexture() + : msaaDepthBuffer_(0), + msaaFrameBufferOBJ_(0), + msaaColorBuffer_(0), + glShader_(0), + glprogram_(0), + clOutputBuffer_(0), + clMsaa_(0), + pGLOutput_(0), + pCLOutput_(0) { + _numSubTests = 1; + _currentTest = 0; +} + +OCLGLMsaaTexture::~OCLGLMsaaTexture() {} + +void OCLGLMsaaTexture::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLGLCommon::open(test, units, conversion, deviceId); + if (_errorFlag) return; + + _currentTest = test; + + // Build the kernel + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateProgramWithSource() failed (%d)", error_); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed (%d)", error_); + + kernel_ = _wrapper->clCreateKernel(program_, "gl_msaa_test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed (%d)", error_); +} + +void OCLGLMsaaTexture::run(void) { + if (_errorFlag) { + return; + } + bool retVal; + switch (_currentTest) { + case 0: + retVal = testMsaaRead(GL_RGBA, 2); + break; + default: + CHECK_RESULT(true, "unsupported test number\n"); + } + CHECK_RESULT((retVal != true), "cl-gl depth test failed "); +} + +unsigned int OCLGLMsaaTexture::close(void) { + if (pGLOutput_) { + free(pGLOutput_); + pGLOutput_ = NULL; + } + + if (pCLOutput_) { + free(pCLOutput_); + pCLOutput_ = NULL; + } + + clReleaseMemObject(clMsaa_); + clReleaseMemObject(clOutputBuffer_); + + glFinish(); + // unbind the texture and frame buffer. + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 0, 0); + glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, 0, 0); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); + + // clean gl resources + glDeleteFramebuffers(1, &msaaFrameBufferOBJ_); + msaaFrameBufferOBJ_ = 0; + glDeleteTextures(1, &msaaColorBuffer_); + msaaColorBuffer_ = 0; + glDeleteTextures(1, &msaaDepthBuffer_); + msaaDepthBuffer_ = 0; + + glDeleteProgram(glprogram_); + glDeleteShader(glShader_); + + return OCLGLCommon::close(); +} + +bool OCLGLMsaaTexture::testMsaaRead(GLint internalFormat, + unsigned int numSamples) { + size_t dimSizes[] = {c_dimSize, c_dimSize}; + + unsigned int bufferSize = c_dimSize * c_dimSize * 4; + bool retVal = false; + createGLFragmentProgramFromSource(glDownSampleShader, glShader_, glprogram_); + + ///////////////////// + // create msaa FBO // + ///////////////////// + glGenFramebuffers(1, &msaaFrameBufferOBJ_); + glBindFramebuffer(GL_FRAMEBUFFER, msaaFrameBufferOBJ_); + + // create textures + glGenTextures(1, &msaaColorBuffer_); + glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, msaaColorBuffer_); + glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, numSamples, GL_RGBA8, + c_dimSize, c_dimSize, GL_TRUE); + + glGenTextures(1, &msaaDepthBuffer_); + glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, msaaDepthBuffer_); + glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, numSamples, + GL_DEPTH_COMPONENT24, c_dimSize, c_dimSize, GL_TRUE); + + // + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, msaaColorBuffer_, + 0); + glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, msaaDepthBuffer_, + 0); + + // verify all resource allocations are well. + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (GL_FRAMEBUFFER_COMPLETE != status) { + return false; + } + // set up gl state machine + glViewport(0, 0, c_dimSize, c_dimSize); // Reset The Current Viewport + glMatrixMode(GL_PROJECTION); // Select The Projection Matrix + glLoadIdentity(); // Reset The Projection Matrix + gluPerspective(30.0f, (GLfloat)c_dimSize / (GLfloat)c_dimSize, 0.1f, 100.0f); + glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix + glLoadIdentity(); + glEnable(GL_DEPTH_TEST); + // The Type Of Depth Testing To Do + glClear(GL_COLOR_BUFFER_BIT | + GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer + glBegin(GL_QUADS); // Draw A Quad + glVertex3f(-1.0f, 1.0f, -6.0f); // Top Left + glVertex3f(1.0f, 1.0f, -6.0f); // Top Right + glVertex3f(1.0f, -1.0f, -3.0f); // Bottom Right + glVertex3f(-1.0f, -1.0f, -3.0f); // Bottom Left + glEnd(); + + glFinish(); + cl_int error; + clOutputBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, + bufferSize, NULL, &error); + if (CL_SUCCESS != error) return false; + + clMsaa_ = _wrapper->clCreateFromGLTexture(context_, CL_MEM_READ_WRITE, + GL_TEXTURE_2D_MULTISAMPLE, 0, + msaaColorBuffer_, &error); + if (CL_SUCCESS != error) return false; + + GLsizei samples; + error = _wrapper->clGetGLTextureInfo(clMsaa_, CL_GL_NUM_SAMPLES, + sizeof(samples), &samples, NULL); + + error = _wrapper->clEnqueueAcquireGLObjects(cmdQueues_[_deviceId], 1, + &clMsaa_, 0, NULL, NULL); + if (CL_SUCCESS != error) return false; + + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &clOutputBuffer_); + + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), &clMsaa_); + + _wrapper->clSetKernelArg(kernel_, 2, sizeof(unsigned int), &numSamples); + + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 2, NULL, + dimSizes, NULL, 0, NULL, NULL); + + _wrapper->clEnqueueReleaseGLObjects(cmdQueues_[_deviceId], 1, &clMsaa_, 0, + NULL, NULL); + + pGLOutput_ = (unsigned int*)malloc(bufferSize); + pCLOutput_ = (unsigned int*)malloc(bufferSize); + + _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], clOutputBuffer_, CL_TRUE, + 0, bufferSize, pCLOutput_, 0, NULL, NULL); + + // down sample + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, msaaColorBuffer_); + glUseProgram(glprogram_); + + glUniform1i(glGetUniformLocation(glprogram_, "numSamples"), numSamples); + glUniform2i(glGetUniformLocation(glprogram_, "resolution"), c_dimSize, + c_dimSize); + glUniform1i(glGetUniformLocation(glprogram_, "MsaaTex"), 0); + + // printOpenGLError(); + + glBegin(GL_QUADS); + glVertex2f(-1.0f, 1.0f); + glTexCoord2f(1.0f, 0.0f); + glVertex2f(1.0f, 1.0f); + glTexCoord2f(1.0f, 1.0f); + glVertex2f(1.0f, -1.0f); + glTexCoord2f(0.0f, 1.0f); + glVertex2f(-1.0f, -1.0f); + glTexCoord2f(0.0f, 0.0f); + glEnd(); + + glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); + glUseProgram(0); + + glReadPixels(0, 0, c_dimSize, c_dimSize, GL_BGRA, GL_UNSIGNED_BYTE, + pGLOutput_); + + if (absDiff(pGLOutput_, pCLOutput_, c_dimSize)) retVal = true; + + return retVal; +} + +bool OCLGLMsaaTexture::absDiff(unsigned int* pGLBuffer, unsigned int* pCLBuffer, + const unsigned int c_dimSize) { + bool retVal = true; + for (unsigned int i = 0; i < c_dimSize * c_dimSize; i++) { + char clPixel[4]; + char glPixel[4]; + char diff[4] = {0}; + memcpy(clPixel, &(pCLBuffer[i]), sizeof(clPixel)); + memcpy(glPixel, &(pGLBuffer[i]), sizeof(glPixel)); + + for (int j = 0; j < 4; j++) { + diff[j] = abs(clPixel[j] - glPixel[i]); + if (diff[j] > 10) retVal = false; + } + } + return retVal; +} diff --git a/opencl/tests/ocltst/module/gl/OCLGLMsaaTexture.h b/opencl/tests/ocltst/module/gl/OCLGLMsaaTexture.h new file mode 100644 index 0000000000..3b27ca6768 --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLMsaaTexture.h @@ -0,0 +1,68 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GL_MSAA_TEXTURE_H_ +#define _OCL_GL_MSAA_TEXTURE_H_ + +#include "OCLGLCommon.h" + +class OCLGLMsaaTexture : public OCLGLCommon { + public: + OCLGLMsaaTexture(); + virtual ~OCLGLMsaaTexture(); + static const unsigned int c_dimSize = 128; + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual void run(void); + virtual unsigned int close(void); + + private: + //////////////////// + // test functions // + //////////////////// + bool testMsaaRead(GLint internalFormat, unsigned int NumSamples); + unsigned int _currentTest; + + ////////////////////////////// + // private helper functions // + ////////////////////////////// + + // returns element size in bytes. + static bool absDiff(unsigned int* pGLBuffer, unsigned int* pCLBuffer, + const unsigned int dimSize); + + ///////////////////// + // private members // + ///////////////////// + // GL resource identifiers + GLuint msaaDepthBuffer_; + GLuint msaaFrameBufferOBJ_; + GLuint msaaColorBuffer_; + GLuint glShader_; + GLuint glprogram_; + // CL identifiers + cl_mem clOutputBuffer_; + cl_mem clMsaa_; + + unsigned int* pGLOutput_; + unsigned int* pCLOutput_; +}; + +#endif // _OCL_GL_BUFFER_H_ diff --git a/opencl/tests/ocltst/module/gl/OCLGLMultiContext.cpp b/opencl/tests/ocltst/module/gl/OCLGLMultiContext.cpp new file mode 100644 index 0000000000..c269d3594b --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLMultiContext.cpp @@ -0,0 +1,231 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGLMultiContext.h" + +#include +#include +#include +#include + +const static char* strKernel = + "__kernel void glmulticontext_test( __global uint4 *source, __global uint4 " + "*dest) \n" + "{ " + " \n" + " int tid = get_global_id(0); " + " \n" + " dest[ tid ] = source[ tid ] + (uint4)(1); " + " \n" + "} " + " \n"; + +OCLGLMultiContext::OCLGLMultiContext() { + memset(contextData_, 0, sizeof(contextData_)); + _numSubTests = 1; +} + +OCLGLMultiContext::~OCLGLMultiContext() {} + +void OCLGLMultiContext::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + // Initialize random number seed + srand((unsigned int)time(NULL)); + + OCLGLCommon::open(test, units, conversion, deviceId); + if (_errorFlag) return; + + cl_context_properties properties[7] = {0}; + for (unsigned int i = 0; i < c_glContextCount; i++) { + createGLContext(contextData_[i].glContext); + getCLContextPropertiesFromGLContext(contextData_[i].glContext, properties); + + // Create new CL context from GL context + contextData_[i].clContext = _wrapper->clCreateContext( + properties, 1, &devices_[_deviceId], NULL, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateContext() failed (%d)", + error_); + + // Create command queue for new context + contextData_[i].clCmdQueue = _wrapper->clCreateCommandQueue( + contextData_[i].clContext, devices_[_deviceId], 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueue() failed (%d)", + error_); + + // Build the kernel + contextData_[i].clProgram = _wrapper->clCreateProgramWithSource( + contextData_[i].clContext, 1, &strKernel, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateProgramWithSource() failed (%d)", error_); + + error_ = _wrapper->clBuildProgram(contextData_[i].clProgram, 1, + &devices_[deviceId], NULL, NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(contextData_[i].clProgram, + devices_[deviceId], CL_PROGRAM_BUILD_LOG, + 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed (%d)", + error_); + + contextData_[i].clKernel = _wrapper->clCreateKernel( + contextData_[i].clProgram, "glmulticontext_test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed (%d)", + error_); + } +} + +void OCLGLMultiContext::run() { + if (_errorFlag) { + return; + } + + cl_uint4 inOutData[c_numOfElements] = {{{0}}}; + cl_uint4 expectedData[c_numOfElements] = {{{0}}}; + + // Initialize input data with random values + for (unsigned int i = 0; i < c_numOfElements; i++) { + for (unsigned int j = 0; j < sizeof(cl_uint4) / sizeof(cl_uint); j++) { + inOutData[i].s[j] = (unsigned int)rand(); + expectedData[i].s[j] = inOutData[i].s[j] + c_glContextCount; + } + } + + for (unsigned int i = 0; i < c_glContextCount; i++) { + makeCurrent(contextData_[i].glContext); + + // Generate and Bind in & out OpenGL buffers + GLuint inGLBuffer = 0, outGLBuffer = 0; + glGenBuffers(1, &inGLBuffer); + glGenBuffers(1, &outGLBuffer); + + glBindBuffer(GL_ARRAY_BUFFER, inGLBuffer); + glBufferData(GL_ARRAY_BUFFER, c_numOfElements * sizeof(cl_uint4), inOutData, + GL_STATIC_DRAW); + + glBindBuffer(GL_ARRAY_BUFFER, outGLBuffer); + glBufferData(GL_ARRAY_BUFFER, c_numOfElements * sizeof(cl_uint4), NULL, + GL_STATIC_DRAW); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glFinish(); + + // Create input buffer from GL input buffer + contextData_[i].inputBuffer = _wrapper->clCreateFromGLBuffer( + contextData_[i].clContext, CL_MEM_READ_ONLY, inGLBuffer, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "Unable to create input GL buffer (%d)", error_); + + // Create output buffer from GL output buffer + contextData_[i].outputBuffer = _wrapper->clCreateFromGLBuffer( + contextData_[i].clContext, CL_MEM_WRITE_ONLY, outGLBuffer, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "Unable to create output GL buffer (%d)", error_); + + error_ = + _wrapper->clSetKernelArg(contextData_[i].clKernel, 0, sizeof(cl_mem), + &(contextData_[i].inputBuffer)); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed (%d)", + error_); + + error_ = + _wrapper->clSetKernelArg(contextData_[i].clKernel, 1, sizeof(cl_mem), + &(contextData_[i].outputBuffer)); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed (%d)", + error_); + + error_ = _wrapper->clEnqueueAcquireGLObjects(contextData_[i].clCmdQueue, 1, + &(contextData_[i].inputBuffer), + 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "Unable to acquire GL objects (%d)", + error_); + + error_ = _wrapper->clEnqueueAcquireGLObjects( + contextData_[i].clCmdQueue, 1, &(contextData_[i].outputBuffer), 0, NULL, + NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "Unable to acquire GL objects (%d)", + error_); + + size_t gws[1] = {c_numOfElements}; + error_ = _wrapper->clEnqueueNDRangeKernel(contextData_[i].clCmdQueue, + contextData_[i].clKernel, 1, NULL, + gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed (%d)", + error_); + + error_ = _wrapper->clEnqueueReleaseGLObjects(contextData_[i].clCmdQueue, 1, + &(contextData_[i].inputBuffer), + 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), + "clEnqueueReleaseGLObjects failed (%d)", error_); + + error_ = _wrapper->clEnqueueReleaseGLObjects( + contextData_[i].clCmdQueue, 1, &(contextData_[i].outputBuffer), 0, NULL, + NULL); + CHECK_RESULT((error_ != CL_SUCCESS), + "clEnqueueReleaseGLObjects failed (%d)", error_); + + error_ = _wrapper->clFinish(contextData_[i].clCmdQueue); + CHECK_RESULT((error_ != CL_SUCCESS), "clFinish() failed (%d)", error_); + + glBindBuffer(GL_ARRAY_BUFFER, outGLBuffer); + void* glMem = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY); + memcpy(inOutData, glMem, c_numOfElements * sizeof(cl_uint4)); + glUnmapBuffer(GL_ARRAY_BUFFER); + + _wrapper->clReleaseMemObject(contextData_[i].inputBuffer); + _wrapper->clReleaseMemObject(contextData_[i].outputBuffer); + + // Delete GL buffers + glBindBuffer(GL_ARRAY_BUFFER, 0); + glDeleteBuffers(1, &inGLBuffer); + inGLBuffer = 0; + glDeleteBuffers(1, &outGLBuffer); + outGLBuffer = 0; + } + + // Compare expected output with actual data received + for (unsigned int i = 0; i < c_numOfElements; i++) { + for (unsigned int j = 0; j < sizeof(cl_uint4) / sizeof(cl_uint); j++) { + CHECK_RESULT((inOutData[i].s[j] != expectedData[i].s[j]), + "Element %d is incorrect!\n\t \ + expected:{%d, %d, %d, %d} differs from actual:{%d, %d, %d, %d}", + i, expectedData[i].s[0], expectedData[i].s[1], + expectedData[i].s[2], expectedData[i].s[3], + inOutData[i].s[0], inOutData[i].s[1], inOutData[i].s[2], + inOutData[i].s[3]); + } + } +} + +unsigned int OCLGLMultiContext::close() { + for (unsigned int i = 0; i < c_glContextCount; i++) { + makeCurrent(contextData_[i].glContext); + _wrapper->clReleaseKernel(contextData_[i].clKernel); + _wrapper->clReleaseProgram(contextData_[i].clProgram); + _wrapper->clReleaseCommandQueue(contextData_[i].clCmdQueue); + _wrapper->clReleaseContext(contextData_[i].clContext); + destroyGLContext(contextData_[i].glContext); + } + return OCLGLCommon::close(); +} diff --git a/opencl/tests/ocltst/module/gl/OCLGLMultiContext.h b/opencl/tests/ocltst/module/gl/OCLGLMultiContext.h new file mode 100644 index 0000000000..0ce90030fe --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLMultiContext.h @@ -0,0 +1,54 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GL_MULTI_CONTEXT_H_ +#define _OCL_GL_MULTI_CONTEXT_H_ + +#include "OCLGLCommon.h" + +class OCLGLMultiContext : public OCLGLCommon { + public: + OCLGLMultiContext(); + virtual ~OCLGLMultiContext(); + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual void run(void); + virtual unsigned int close(void); + + private: + static const unsigned int c_glContextCount = 3; + static const unsigned int c_numOfElements = 128; + + struct GLContextDataSet { + OCLGLHandle glContext; + cl_context clContext; + cl_command_queue clCmdQueue; + cl_program clProgram; + cl_kernel clKernel; + cl_mem inputBuffer; + cl_mem outputBuffer; + }; + GLContextDataSet contextData_[c_glContextCount]; + + bool failed_; +}; + +#endif // _OCL_GL_MULTI_CONTEXT_H_ diff --git a/opencl/tests/ocltst/module/gl/OCLGLPerfSepia.cpp b/opencl/tests/ocltst/module/gl/OCLGLPerfSepia.cpp new file mode 100644 index 0000000000..a5b743a13d --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLPerfSepia.cpp @@ -0,0 +1,586 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGLPerfSepia.h" + +#include +#include +#include +#include + +#define WIDTH 1024 +#define HEIGHT 1024 + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define MAX(a, b) (a > b ? a : b) + +const char *sepiaVertexProgram = + "!!ARBvp1.0\n" + "\n" + "\n" + "OPTION ARB_position_invariant;\n" + "\n" + "PARAM p0 = program.local[2];\n" + "PARAM p1 = program.local[3];\n" + "ATTRIB a0 = vertex.texcoord[0];\n" + "OUTPUT o0 = result.texcoord[0];\n" + "OUTPUT o1 = result.texcoord[1];\n" + "TEMP r0, r1;\n" + "\n" + "MOV o0, a0;\n" + "#SWZ r1, a0, x, y, 0, 0;\n" + "#DPH r0.x, r1, p0;\n" + "#DPH r0.y, r1, p1;\n" + "#MOV o1, r0;\n" + "MOV o1, a0;\n" + "\n" + "END\n"; + +const char *sepiaFragmentProgram = + "!!ARBfp1.0\n" + "\n" + "\n" + "PARAM p0 = {1e-4, 0.085, 0.0, 0.0};\n" + "PARAM p1 = {0.2125, 0.7154, 0.0721, 0.0};\n" + "PARAM p2 = {-3605.984, 0.1323156, 0.0, -0.1991615};\n" + "PARAM p3 = {708.7939, -0.3903106, -0.05854013, 0.6621023};\n" + "PARAM p4 = {-50.93341, 0.4654831, 1.027555, -0.9069088};\n" + "PARAM p5 = {3.116672, 0.7926372, 0.03219686, 1.411847};\n" + "PARAM p6 = {8.95663e-4, -0.001104567, -6.0827e-4, 0.03277428};\n" + "PARAM p7 = program.local[0];\n" + "PARAM p8 = program.local[1];\n" + "ATTRIB a0 = fragment.texcoord[1];\n" + "OUTPUT o0 = result.color;\n" + "TEMP r0, r1, r2, r3;\n" + "\n" + "TEX r1, a0, texture[0], RECT;\n" + "#MAX r0, p0.x, r1.w;\n" + "#RCP r2, r0.x;\n" + "#DP3 r3, r1, p1;\n" + "#MUL r0, r3, r2;\n" + "#MAD r2, r0, p2, p3;\n" + "#MAD r2, r2, r0, p4;\n" + "#MAD r0, r2, r0, p5;\n" + "#MUL r2, r1.w, p6;\n" + "#MAD r2, r0, r3, r2;\n" + "#MAD r0, r1.w, p0.y, -r3;\n" + "#CMP r2.x, -r0, r2.x, r2.w;\n" + "#MAD r0, r3, r3, -r3;\n" + "#CMP r0, r0.x, r2, r3;\n" + "#MOV r0.w, r1;\n" + "#MUL r0, r0, p7;\n" + "#LRP o0, p8.x, r0, r1;\n" + "MOV o0, r1;\n" + "\n" + "END\n"; + +const static char *strKernel = + "\n" + "__kernel void program(write_only image2d_t dest, int flipped, int4 dim, " + "float2 st_origin, float4 st_delta, float4 l0, float4 l1, float4 l2, " + "float4 l3, read_only image2d_t t0, sampler_t t_sampler0)\n" + "{\n" + " const sampler_t sam = CLK_NORMALIZED_COORDS_FALSE | " + "CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;\n" + "// const float4 p0 = (float4)( 0x1.b33334p-3, 0x1.6e48e8p-1, " + "0x1.275254p-4, 0x0p+0 );\n" + "// const float4 p1 = (float4)( 0x1.a36e2ep-14, 0x1.5c28f6p-4, 0x0p+0, " + "0x0p+0 );\n" + "// const float4 p2 = (float4)( 0x1.d595dap-11, -0x1.218e3cp-10, " + "-0x1.3ee89ep-11, 0x1.0c7ca6p-5 );\n" + "// const float4 p3 = (float4)( -0x1.c2bf7cp+11, 0x1.0efb7cp-3, " + "0x0p+0, -0x1.97e1fcp-3 );\n" + "// const float4 p4 = (float4)( 0x1.62659ep+9, -0x1.8fad94p-2, " + "-0x1.df8f8cp-5, 0x1.52ff12p-1 );\n" + "// const float4 p5 = (float4)( -0x1.9777ap+5, 0x1.dca79ap-2, " + "0x1.070dd8p+0, -0x1.d0565ap-1 );\n" + "// const float4 p6 = (float4)( 0x1.8eef1cp+1, 0x1.95d48cp-1, " + "0x1.07c1b6p-5, 0x1.696ecep+0 );\n" + "// int dest_width = dim.x;\n" + "// int dest_height = dim.y;\n" + " float4 o0, r0, r1, r2, r3, r4;\n" + "// float4 false_vector = (float4) 0.0f;\n" + "// float4 true_vector = (float4) 1.0f;\n" + " int2 loc = (int2)( get_global_id(0), get_global_id(1) );\n" + "// if ((loc.x >= dim.x) || loc.y >= dim.y) return;\n" + "// float4 f0 = (float4)( st_origin.x + ((float)loc.x + 0.5f) * " + "st_delta.x + ((float)loc.y + 0.5f) * st_delta.z, st_origin.y + " + "((float)loc.x + 0.5f) * st_delta.y + ((float)loc.y + 0.5f) * st_delta.w, " + "0.0f, 0.0f );\n" + "// r2 = f0;\n" + "// r0.x = dot(r2.xy,l2.xy) + l2.w;\n" + "// r0.y = dot(r2.xy,l3.xy) + l3.w;\n" + "// r4 = r0;\n" + " r1 = read_imagef(t0, sam/*t_sampler0*/, r4.xy);\n" + "// r3 = dot(r1.xyz,p0.xyz);\n" + "// r2 = max(p1.xxxx, r1.wwww);\n" + "// r0 = native_recip(r2.xxxx);\n" + "// r4 = r3*r0;\n" + "// r2 = r1.wwww*p2;\n" + "// r0 = mad(r4,p3,p4);\n" + "// r0 = mad(r0,r4,p5);\n" + "// r0 = mad(r0,r4,p6);\n" + "// r2 = mad(r0,r3,r2);\n" + "// r0 = mad(r1.wwww,p1.yyyy,-r3);\n" + "// r2.x = select(r2.w,r2.x, isless(-r0.x, 0.0f));\n" + "// r0 = mad(r3,r3,-r3);\n" + "// r0 = select(r3,r2, isless(r0.xxxx, 0.0f));\n" + "// r0.w = r1.w;\n" + "// r0 = r0*l0;\n" + "// r0 = mix(r1,r0, l1.xxxx);\n" + "// r0.xyz = min(r0.xyz, r0.www);\n" + "// o0 = r0;\n" + " write_imagef(dest, loc /*(int2)( loc.x + dim.z , flipped ? " + "get_image_height(dest) - (loc.y + dim.w + 1) : loc.y + dim.w )*/, r1 " + "/*o0*/);\n" + "}\n"; + +OCLGLPerfSepia::OCLGLPerfSepia() { _numSubTests = 2; } + +OCLGLPerfSepia::~OCLGLPerfSepia() {} + +void OCLGLPerfSepia::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + bVerify_ = false; + silentFailure_ = false; + iterations_ = 50000; + bpr_ = 0; + data_ = 0; + result_ = 0; + width_ = 0; + height_ = 0; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + texId = 0; + format_.image_channel_order = CL_RGBA; + format_.image_channel_data_type = CL_UNORM_INT8; + + srand(0x8956); // some constant instead of time() so that we get same random + // numbers + + if (!IsGLEnabled(test, units, conversion, deviceId)) { + silentFailure_ = true; + return; + } + OCLGLCommon::open(test, units, conversion, deviceId); + if (_errorFlag) return; + if (test == 0) { + // Build the kernel + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateProgramWithSource() failed (%d)", error_); + const char *optionsGPU = "-cl-denorms-are-zero -cl-mad-enable"; + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + optionsGPU, NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, + 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed (%d)", + error_); + + kernel_ = _wrapper->clCreateKernel(program_, "program", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed (%d)", + error_); + } +} + +void OCLGLPerfSepia::populateData(void) { + width_ = WIDTH; + height_ = HEIGHT; + bpr_ = 4 * width_; + data_ = (cl_uchar *)malloc(height_ * bpr_); + for (unsigned int n = 0; n < (height_ * bpr_); n++) { + data_[n] = (n & 3) ? (rand() % 256) : 0xFF; + } +} + +void OCLGLPerfSepia::runGL(void) { + glDisable(GL_ALPHA_TEST); + glDisable(GL_DEPTH_TEST); + glDisable(GL_SCISSOR_TEST); + glDisable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_DITHER); + glDisable(GL_CULL_FACE); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glDepthMask(GL_FALSE); + glStencilMask(0); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + // let's create the textures we need + + glEnable(GL_TEXTURE_RECTANGLE_EXT); + glGenTextures(1, &texId); + glBindTexture(GL_TEXTURE_RECTANGLE_EXT, texId); + + // have GL alloc memory for us for our destination texture which we will be + // rendering into + glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, width_, height_, 0, + GL_BGRA /*RGBA*/, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + // for the source texture we will provide a data ptr and hang on to it + GLuint srcTexture; + + glGenTextures(1, &srcTexture); + glBindTexture(GL_TEXTURE_RECTANGLE_EXT, srcTexture); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, width_); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, height_); + glPixelStorei(GL_UNPACK_ALIGNMENT, 8); + + // XXX Alex -- use optimal texture upload format. + glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, width_, height_, 0, + GL_BGRA, /* GL_RGBA,*/ + format_.image_channel_order == CL_RGBA + ? GL_UNSIGNED_INT_8_8_8_8 + : GL_UNSIGNED_INT_8_8_8_8_REV, + data_); + + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, + GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, + GL_CLAMP_TO_EDGE); + glPixelStorei(GL_UNPACK_SWAP_BYTES, 0); + glPixelStorei(GL_UNPACK_LSB_FIRST, 0); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_SKIP_IMAGES, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + + GLuint vertexProgram; + GLuint fragmentProgram; + + glGenProgramsARB(1, &vertexProgram); + glGenProgramsARB(1, &fragmentProgram); + + glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vertexProgram); + glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + (GLsizei)strlen(sepiaVertexProgram), sepiaVertexProgram); + + glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fragmentProgram); + glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + (GLsizei)strlen(sepiaFragmentProgram), + sepiaFragmentProgram); + + GLfloat l0[] = {1.0f, 0.99f, 0.92f, 1.0f}; + GLfloat l1[] = {0.5, 0, 0, 0}; + GLfloat l2[] = {1, 0, 0, 0}; + GLfloat l3[] = {0, -1, 0, (GLfloat)height_}; + + glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 0, l0); + glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 1, l1); + glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 2, l2); + glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 3, l3); + + glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0, l0); + glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 1, l1); + glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 2, l2); + glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 3, l3); + + GLuint fbo; + + glGenFramebuffersEXT(1, &fbo); + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); + + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + GL_TEXTURE_RECTANGLE_ARB, texId, 0); + glViewport(0, 0, width_, height_); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, width_, 0, height_, -1, 1); + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT); + glDisable(GL_BLEND); + + glEnable(GL_VERTEX_PROGRAM_ARB); + glEnable(GL_FRAGMENT_PROGRAM_ARB); + + // warm up + for (unsigned int k = 0; k < (iterations_ / 10); k++) { + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(0, (GLfloat)height_); + glTexCoord2f((GLfloat)width_, 0); + glVertex2f((GLfloat)width_, (GLfloat)height_); + glTexCoord2f((GLfloat)width_, (GLfloat)height_); + glVertex2f((GLfloat)width_, 0); + glTexCoord2f(0, (GLfloat)height_); + glVertex2f(0, 0); + glEnd(); + glFlush(); + glFinish(); + } + + // actual test + for (unsigned int k = 0; k < iterations_; k++) { + if (k == 1) { + timer_.Reset(); + timer_.Start(); + } + + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(0, (GLfloat)height_); + glTexCoord2f((GLfloat)width_, 0); + glVertex2f((GLfloat)width_, (GLfloat)height_); + glTexCoord2f((GLfloat)width_, (GLfloat)height_); + glVertex2f((GLfloat)width_, 0); + glTexCoord2f(0, (GLfloat)height_); + glVertex2f(0, 0); + glEnd(); + } + + glFlush(); + glFinish(); + + timer_.Stop(); + + glDisable(GL_VERTEX_PROGRAM_ARB); + glDisable(GL_FRAGMENT_PROGRAM_ARB); + + // now let's read back the pixels + result_ = (cl_uchar *)malloc(width_ * height_ * 4); + + glReadPixels(0, 0, width_, height_, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, + result_); + + // bind back default frame buffer + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + + glDeleteFramebuffersEXT(1, &fbo); + glDeleteTextures(1, &srcTexture); + glDeleteProgramsARB(1, &vertexProgram); + glDeleteProgramsARB(1, &fragmentProgram); +} + +void OCLGLPerfSepia::runCL(void) { + cl_mem dst, src; + cl_sampler nearestZero; + + glEnable(GL_TEXTURE_RECTANGLE_EXT); + glGenTextures(1, &texId); + glBindTexture(GL_TEXTURE_RECTANGLE_EXT, texId); + // XXX Alex: have GL alloc memory for us ... + glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, width_, height_, 0, + GL_RGBA /*BGRA*/, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); + + dst = _wrapper->clCreateFromGLTexture2D( + context_, CL_MEM_READ_WRITE, GL_TEXTURE_RECTANGLE_EXT, 0, texId, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateFromGLTexture2D error (%d)", + error_); + nearestZero = _wrapper->clCreateSampler(context_, CL_FALSE, CL_ADDRESS_CLAMP, + CL_FILTER_NEAREST, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateSampler error (%d)", error_); + src = _wrapper->clCreateImage2D( + context_, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, &format_, width_, + height_, bpr_, data_, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateImage2D error (%d)", error_); + + int numArgs = 0; + int dim[2] = {(int)width_, (int)height_}; + int flipped[] = {1}; + int dims[] = {(int)width_, (int)height_, 0, 0}; + float st_origin[] = {0, 0}; + float st_delta[] = {1, 0, 0, 1}; + + _wrapper->clSetKernelArg(kernel_, numArgs++, sizeof(cl_mem), + &dst); // arg is a image2DGL named "dst" + _wrapper->clSetKernelArg(kernel_, numArgs++, sizeof(int), + &flipped); // arg is a int1 named "flipped" + _wrapper->clSetKernelArg(kernel_, numArgs++, 4 * sizeof(int), + &dims); // arg is a int4 named "dim" + _wrapper->clSetKernelArg(kernel_, numArgs++, 2 * sizeof(float), + &st_origin); // arg is a float2 named "st_origin" + _wrapper->clSetKernelArg(kernel_, numArgs++, 4 * sizeof(float), + &st_delta); // arg is a float4 named "st_delta" + + float l0[] = {1.0f, 0.99f, 0.92f, 1.0f}; + float l1[] = {0.5f, 0.0f, 0.0f, 0.0f}; + float l2[] = {1.0f, 0.0f, 0.0f, 0.0f}; + float l3[] = {0.0f, -1.0f, 0.0f, (float)height_}; + + _wrapper->clSetKernelArg(kernel_, numArgs++, 4 * sizeof(float), + &l0); // arg is a float4 named "l0" + _wrapper->clSetKernelArg(kernel_, numArgs++, 4 * sizeof(float), + &l1); // arg is a float4 named "l1" + _wrapper->clSetKernelArg(kernel_, numArgs++, 4 * sizeof(float), + &l2); // arg is a float4 named "l2" + _wrapper->clSetKernelArg(kernel_, numArgs++, 4 * sizeof(float), + &l3); // arg is a float4 named "l3" + _wrapper->clSetKernelArg(kernel_, numArgs++, sizeof(cl_mem), + &src); // arg is a image2D named "t0" + _wrapper->clSetKernelArg( + kernel_, numArgs++, sizeof(cl_sampler), + &nearestZero); // arg is a sampler named "t_sampler0" + + size_t execution_threads[2]; + size_t execution_local[2]; + cl_uint work_dim = 2; + error_ = _wrapper->clGetKernelWorkGroupInfo( + kernel_, devices_[_deviceId], CL_KERNEL_WORK_GROUP_SIZE, + sizeof(execution_local[0]), &execution_local[0], 0); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetKernelWorkGroupInfo error (%d)", + error_); + execution_local[1] = 1; + work_dim = 2; + GetKernelExecDimsForImage((unsigned int)execution_local[0], dim[0], dim[1], + execution_threads, execution_local); + result_ = (cl_uchar *)malloc(height_ * bpr_); + + const size_t origin[] = {0, 0, 0}; + const size_t region[] = {width_, height_, 1}; + + // warm up + for (unsigned int k = 0; k < (iterations_ / 10); k++) { + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, + work_dim, NULL, execution_threads, + execution_local, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel error (%d)", + error_); + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + CHECK_RESULT((error_ != CL_SUCCESS), "clFinish error (%d)", error_); + } + + // actual test + for (unsigned int k = 0; k < iterations_; k++) { + if (k == 1) { + timer_.Reset(); + timer_.Start(); + } + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, + work_dim, NULL, execution_threads, + execution_local, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel error (%d)", + error_); + } + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + CHECK_RESULT((error_ != CL_SUCCESS), "clFinish error (%d)", error_); + + timer_.Stop(); + + error_ = + _wrapper->clEnqueueReadImage(cmdQueues_[_deviceId], dst, true, origin, + region, bpr_, 0, result_, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadImage error (%d)", error_); + _wrapper->clFinish(cmdQueues_[_deviceId]); + + _wrapper->clReleaseMemObject(src), src = NULL; + _wrapper->clReleaseSampler(nearestZero); + _wrapper->clReleaseMemObject(dst), dst = NULL; +} + +void OCLGLPerfSepia::GetKernelExecDimsForImage(unsigned int work_group_size, + unsigned int w, unsigned int h, + size_t *global, size_t *local) { + unsigned int a, b; + static const unsigned int tile_size = 16; + + // local[0] and local[1] must be at least 1 + local[0] = tile_size < work_group_size ? tile_size : work_group_size; + local[1] = work_group_size / tile_size > tile_size + ? tile_size + : MAX(work_group_size / tile_size, 1); + + a = w; + b = (unsigned int)local[0]; + + global[0] = ((a % b) != 0) ? (a / b + 1) : (a / b); + global[0] *= local[0]; + + a = h; + b = (unsigned int)local[1]; + + global[1] = ((a % b) != 0) ? (a / b + 1) : (a / b); + global[1] *= local[1]; +} + +void OCLGLPerfSepia::run(void) { + if (_errorFlag || silentFailure_) { + return; + } + populateData(); + if (_openTest == 0) { + runCL(); + } else { + runGL(); + } + if (bVerify_) { + verifyResult(); + } + char buf[100]; + SNPRINTF(buf, sizeof(buf), "%s iterations# %d", + (_openTest == 0) ? "CL" : "GL", iterations_); + testDescString = buf; + _perfInfo = (float)timer_.GetElapsedTime(); +} + +void OCLGLPerfSepia::verifyResult(void) { + int r = 0, g = 0, b = 0, a = 0, d = 0; + for (unsigned int k = 0; k < height_ * bpr_; k += 4) { + a = a + result_[k + 0]; + r = r + result_[k + 1]; + g = g + result_[k + 2]; + b = b + result_[k + 3]; + } + d = abs(r - 152797810) + abs(g - 125868080) + abs(b - 76147833) + + abs(a - 267386880); + CHECK_RESULT(d > 20000, "wrong result"); +} +unsigned int OCLGLPerfSepia::close(void) { + if (silentFailure_) { + return 0; + } + + if (data_) { + free(data_); + } + + if (result_) { + free(result_); + } + + if (texId) { + glDeleteTextures(1, &texId); + } + + return OCLGLCommon::close(); +} diff --git a/opencl/tests/ocltst/module/gl/OCLGLPerfSepia.h b/opencl/tests/ocltst/module/gl/OCLGLPerfSepia.h new file mode 100644 index 0000000000..568cd8a93c --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLPerfSepia.h @@ -0,0 +1,58 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_SEPIA_H_ +#define _OCL_PERF_SEPIA_H_ + +#include "OCLGLCommon.h" +#include "Timer.h" + +class OCLGLPerfSepia : public OCLGLCommon { + public: + OCLGLPerfSepia(); + virtual ~OCLGLPerfSepia(); + + virtual void open(unsigned int test, char *units, double &conversion, + unsigned int deviceId); + virtual void run(void); + virtual unsigned int close(void); + + private: + void runGL(void); + void runCL(void); + void populateData(void); + void verifyResult(void); + void GetKernelExecDimsForImage(unsigned int work_group_size, unsigned int w, + unsigned int h, size_t *global, size_t *local); + + bool silentFailure_; + cl_uint iterations_; + cl_image_format format_; + cl_uchar *data_; + cl_uchar *result_; + bool bVerify_; + cl_uint width_; + cl_uint height_; + cl_uint bpr_; + GLuint texId; + CPerfCounter timer_; +}; + +#endif // _OCL_PERF_SEPIA_H_ diff --git a/opencl/tests/ocltst/module/gl/OCLGLTexture.cpp b/opencl/tests/ocltst/module/gl/OCLGLTexture.cpp new file mode 100644 index 0000000000..b44449bef0 --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLTexture.cpp @@ -0,0 +1,144 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGLTexture.h" + +#include +#include +#include +#include + +const static char* strKernelui = + "__kernel void gltexture_test(read_only image2d_t source, write_only " + "image2d_t dest) \n" + "{ " + " \n" + " int tidX = get_global_id(0); " + " \n" + " int tidY = get_global_id(1); " + " \n" + " uint4 pixel = read_imageui(source, (int2)(tidX, tidY)); " + " \n" + " write_imageui(dest, (int2)(tidX, tidY), pixel); " + " \n" + "}"; + +const static char* strKernelf = + "__kernel void gltexture_test(read_only image2d_t source, write_only " + "image2d_t dest) \n" + "{ " + " \n" + " int tidX = get_global_id(0); " + " \n" + " int tidY = get_global_id(1); " + " \n" + " float4 pixel = read_imagef(source, (int2)(tidX, tidY)); " + " \n" + " write_imagef(dest, (int2)(tidX, tidY), pixel); " + " \n" + "} " + " \n"; + +OCLGLTexture::OCLGLTexture() + : inDataGL_(NULL), outDataGL_(NULL), inGLTexture_(0), outGLTexture_(0) { + _numSubTests = 4 * 2; +} + +OCLGLTexture::~OCLGLTexture() {} + +void OCLGLTexture::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + // Initialize random number seed + srand((unsigned int)time(NULL)); + + OCLGLCommon::open(test, units, conversion, deviceId); + if (_errorFlag) return; + + currentTest_ = test % 4; + testRender_ = ((test / 4) >= 1) ? true : false; + + // Build the kernel + if (0 == currentTest_) { + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernelui, + NULL, &error_); + + } else { + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernelf, + NULL, &error_); + } + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateProgramWithSource() failed (%d)", error_); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed (%d)", error_); + + kernel_ = _wrapper->clCreateKernel(program_, "gltexture_test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed (%d)", error_); +} + +void OCLGLTexture::run(void) { + bool retVal = false; + switch (currentTest_) { + case 0: + retVal = runTextureTest(GL_RGBA32UI, GL_RGBA_INTEGER, + GL_UNSIGNED_INT); + break; + case 1: + retVal = + runTextureTest(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE); + break; + case 2: + retVal = runTextureTest(GL_RGBA16, GL_RGBA, GL_SHORT); + break; + case 3: + retVal = runTextureTest(GL_RGBA32F, GL_RGBA, GL_FLOAT); + break; + default: + CHECK_RESULT(true, "unsupported test number\n"); + } + CHECK_RESULT((retVal != true), "cl-gl texture interop test failed "); +} + +unsigned int OCLGLTexture::close(void) { + clReleaseMemObject(buffers_[0]); + clReleaseMemObject(buffers_[1]); + buffers_.clear(); + // Delete GL in & out buffers + glFinish(); + glBindTexture(GL_TEXTURE_2D, 0); + glDeleteTextures(1, &inGLTexture_); + inGLTexture_ = 0; + glDeleteTextures(1, &outGLTexture_); + outGLTexture_ = 0; + + free(inDataGL_); + inDataGL_ = NULL; + free(outDataGL_); + outDataGL_ = NULL; + return OCLGLCommon::close(); +} diff --git a/opencl/tests/ocltst/module/gl/OCLGLTexture.h b/opencl/tests/ocltst/module/gl/OCLGLTexture.h new file mode 100644 index 0000000000..f1419ca952 --- /dev/null +++ b/opencl/tests/ocltst/module/gl/OCLGLTexture.h @@ -0,0 +1,214 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GL_TEXTURE_H_ +#define _OCL_GL_TEXTURE_H_ + +#include + +#include "OCLGLCommon.h" + +class OCLGLTexture : public OCLGLCommon { + public: + static const unsigned int c_imageWidth = 512; + static const unsigned int c_imageHeight = 512; + static const unsigned int c_elementsPerPixel = 4; + + OCLGLTexture(); + virtual ~OCLGLTexture(); + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual void run(void); + virtual unsigned int close(void); + + private: + unsigned int currentTest_; + void* inDataGL_; + void* outDataGL_; + GLuint inGLTexture_; + GLuint outGLTexture_; + bool testRender_; + template + bool runTextureTest(GLint internalFormat, GLenum format, GLenum type); +}; + +template +bool OCLGLTexture::runTextureTest(GLint internalFormat, GLenum format, + GLenum type) { + cl_mem image; + inDataGL_ = + malloc(c_imageWidth * c_imageHeight * c_elementsPerPixel * sizeof(T)); + outDataGL_ = + malloc(c_imageWidth * c_imageHeight * c_elementsPerPixel * sizeof(T)); + + // Initialize input data with random values + T* inputIterator = (T*)inDataGL_; + for (unsigned int i = 0; + i < c_imageWidth * c_imageHeight * c_elementsPerPixel; i++) { + inputIterator[i] = (T)(rand() % 255); + } + // Initialize output data with zeros + memset(outDataGL_, 0, + c_imageWidth * c_imageHeight * c_elementsPerPixel * sizeof(T)); + + // Generate and Bind in & out OpenGL textures + glGenTextures(1, &inGLTexture_); + glGenTextures(1, &outGLTexture_); + + glBindTexture(GL_TEXTURE_2D, inGLTexture_); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, (GLsizei)c_imageWidth, + (GLsizei)c_imageHeight, 0, format, type, inDataGL_); + + glBindTexture(GL_TEXTURE_2D, outGLTexture_); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, (GLsizei)c_imageWidth, + (GLsizei)c_imageHeight, 0, format, type, outDataGL_); + + glFinish(); + + // Create input buffer from GL input texture + image = _wrapper->clCreateFromGLTexture( + context_, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, inGLTexture_, &error_); + if (error_ != CL_SUCCESS) { + printf("Unable to create input buffer from GL texture (%d)", error_); + return false; + } + buffers_.push_back(image); + + // Create output buffer from GL output texture + image = _wrapper->clCreateFromGLTexture( + context_, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, outGLTexture_, &error_); + if (error_ != CL_SUCCESS) { + printf("Unable to create output buffer from GL texture (%d)", error_); + return false; + } + buffers_.push_back(image); + size_t gws[2] = {c_imageWidth, c_imageHeight}; + + // Assign args + for (unsigned int i = 0; i < buffers_.size(); i++) { + error_ = + _wrapper->clSetKernelArg(kernel_, i, sizeof(cl_mem), &buffers()[i]); + if (error_ != CL_SUCCESS) { + printf("clSetKernelArg() failed (%d)", error_); + return false; + } + } + + int loop = (testRender_) ? 2 : 1; + for (int l = 0; l < loop; ++l) { + if (testRender_ && (l == 0)) { + GLuint FrameBufferName = 0; + glGenFramebuffers(1, &FrameBufferName); + glBindFramebuffer(GL_FRAMEBUFFER, FrameBufferName); + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, inGLTexture_, + 0); + glClearColor(.5f, 1.f, 1.0f, 0); + glClear(GL_COLOR_BUFFER_BIT); + glFinish(); + } + + error_ = _wrapper->clEnqueueAcquireGLObjects(cmdQueues_[_deviceId], 2, + &buffers()[0], 0, NULL, NULL); + if (error_ != CL_SUCCESS) { + printf("Unable to acquire GL objects (%d)", error_); + return false; + } + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 2, + NULL, gws, NULL, 0, NULL, NULL); + if (error_ != CL_SUCCESS) { + printf("clEnqueueNDRangeKernel() failed (%d)", error_); + return false; + } + + error_ = _wrapper->clEnqueueReleaseGLObjects(cmdQueues_[_deviceId], 2, + &buffers()[0], 0, NULL, NULL); + if (error_ != CL_SUCCESS) { + printf("clEnqueueReleaseGLObjects failed (%d)", error_); + return false; + } + + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + if (error_ != CL_SUCCESS) { + printf("clFinish() failed (%d)", error_); + return false; + } + + if (testRender_ && (l == 0)) { + glClearColor(1.f, 1.f, 1.f, 1.f); + glClear(GL_COLOR_BUFFER_BIT); + glFinish(); + } + } + + // Get the results from GL texture + glBindTexture(GL_TEXTURE_2D, outGLTexture_); + glActiveTexture(GL_TEXTURE0); + glGetTexImage(GL_TEXTURE_2D, 0, format, type, outDataGL_); + + // Check output texture data + inputIterator = (T*)inDataGL_; + T* outputIterator = (T*)outDataGL_; + T color; + switch (type) { + case GL_UNSIGNED_INT: + color = (T)0x3f800000; + break; + case GL_UNSIGNED_BYTE: + color = (T)0xff; + break; + case GL_SHORT: + color = (T)0x7fff; + break; + case GL_FLOAT: + color = (T)1.f; + break; + default: + return false; + } + for (unsigned int i = 0; + i < c_imageWidth * c_imageHeight * c_elementsPerPixel; i++) { + if (testRender_) { + if (outputIterator[i] != color) { + std::cout << "Element " << i + << " in output texture is incorrect! (internal format = " + << internalFormat << "\n\t expected:" << inputIterator[i] + << " differs from actual clear color:" << color << std::endl; + return false; + } + } else if (inputIterator[i] != outputIterator[i]) { + std::cout << "Element " << i + << " in output texture is incorrect! (internal format = " + << internalFormat << "\n\t expected:" << inputIterator[i] + << " differs from actual: " << outputIterator[i] << std::endl; + return false; + } + } + return true; +} + +#endif // _OCL_GL_TEXTURE_H_ diff --git a/opencl/tests/ocltst/module/gl/TestList.cpp b/opencl/tests/ocltst/module/gl/TestList.cpp new file mode 100644 index 0000000000..5aa378633a --- /dev/null +++ b/opencl/tests/ocltst/module/gl/TestList.cpp @@ -0,0 +1,55 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLTestListImp.h" + +// +// Includes for tests +// +#include "OCLGLBuffer.h" +#include "OCLGLBufferMultipleQueues.h" +#include "OCLGLDepthBuffer.h" +#include "OCLGLDepthTex.h" +#include "OCLGLFenceSync.h" +#include "OCLGLMsaaTexture.h" +#include "OCLGLMultiContext.h" +#include "OCLGLTexture.h" +#include "OCLGLPerfSepia.h" + +// +// Helper macro for adding tests +// +template +static void* dictionary_CreateTestFunc(void) { + return new T(); +} + +#define TEST(name) \ + { #name, &dictionary_CreateTestFunc < name> } + +TestEntry TestList[] = { + TEST(OCLGLBuffer), TEST(OCLGLBufferMultipleQueues), + TEST(OCLGLTexture), TEST(OCLGLMultiContext), + TEST(OCLGLFenceSync), TEST(OCLGLDepthTex), TEST(OCLGLPerfSepia), +}; + +unsigned int TestListCount = sizeof(TestList) / sizeof(TestList[0]); +unsigned int TestLibVersion = 0; +const char* TestLibName = "oclgl"; diff --git a/opencl/tests/ocltst/module/gl/oclgl.exclude b/opencl/tests/ocltst/module/gl/oclgl.exclude new file mode 100644 index 0000000000..39345e8fd7 --- /dev/null +++ b/opencl/tests/ocltst/module/gl/oclgl.exclude @@ -0,0 +1 @@ +# all clear diff --git a/opencl/tests/ocltst/module/include/BaseTestImp.h b/opencl/tests/ocltst/module/include/BaseTestImp.h new file mode 100644 index 0000000000..47ff996893 --- /dev/null +++ b/opencl/tests/ocltst/module/include/BaseTestImp.h @@ -0,0 +1,207 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _BaseTestImp_H_ +#define _BaseTestImp_H_ + +#include +#include +#include +#include +#include + +#include "OCLTest.h" +#include "OCLWrapper.h" + +#define EXIT_SILENT_FAILURE 2 +#define KERNEL(...) #__VA_ARGS__ + +#ifdef _MSC_VER +#define NOMINMAX +#define snprintf sprintf_s +#endif + +#define CHECK_ERROR(error, msg) \ + if (error != CL_SUCCESS) { \ + _errorFlag = true; \ + printf("\n\n%s\nError code: %d\n\n", msg, error); \ + _errorMsg = msg; \ + _crcword += 1; \ + return; \ + } + +#define CHECK_ERROR_NO_RETURN(error, msg) \ + if (error != CL_SUCCESS) { \ + _errorFlag = true; \ + printf("\n\n%s\nError code: %d\n\n", msg, error); \ + _errorMsg = msg; \ + _crcword += 1; \ + } + +#define CHECK_RESULT(test, msg, ...) \ + if ((test)) { \ + char* buf = (char*)malloc(4096); \ + _errorFlag = true; \ + int rc = snprintf(buf, 4096, msg, ##__VA_ARGS__); \ + assert(rc >= 0 && rc < (int)4096); \ + printf("%s:%d - %s\n", __FILE__, __LINE__, buf); \ + _errorMsg = std::string(buf); \ + _crcword += 1; \ + free(buf); \ + return; \ + } + +#define CHECK_RESULT_ARGS CHECK_RESULT + +#define CHECK_RESULT_NO_RETURN(test, msg, ...) \ + if ((test)) { \ + char* buf = (char*)malloc(4096); \ + _errorFlag = true; \ + int rc = snprintf(buf, 4096, msg, ##__VA_ARGS__); \ + assert(rc >= 0 && rc < (int)4096); \ + printf("%s:%d - %s\n", __FILE__, __LINE__, buf); \ + _errorMsg = std::string(msg); \ + _crcword += 1; \ + free(buf); \ + } + +#define CHECK_RESULT_NO_RETURN_ARGS CHECK_RESULT_NO_RETURN + +#define CHECK_RESULT_SHUTDOWN(test, msg) \ + if ((test)) { \ + _errorFlag = true; \ + printf("%s\n", msg); \ + _errorMsg = msg; \ + _crcword += 1; \ + close(); \ + return; \ + } + +#define CHECK_RESULT_CL(test, msg) \ + if ((test)) { \ + _errorFlag = true; \ + printf("%s\n", msg); \ + _errorMsg = msg; \ + _crcword += 1; \ + return 1; \ + } + +class BaseTestImp : public OCLTest { + public: + BaseTestImp(); + virtual ~BaseTestImp(); + + public: + virtual unsigned int getThreadUsage(void); + virtual int getNumSubTests(void); + + //! Abstract functions being defined here + virtual void open(); + virtual void open(unsigned int test, const char* deviceName, + unsigned int architecture); + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId, unsigned int platformIndex) { + return open(test, "Tahiti", platformIndex); + } + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + return open(test, "Tahiti", 0); + } + + virtual void run(void) = 0; + virtual unsigned int close(void); + + //! Functions to set class members + virtual void checkComplib(unsigned int test, const char* deviceName, + unsigned int architecture); + virtual void setDeviceName(const char*); + virtual const char* getDeviceName(); + virtual void setErrorMsg(const char* error); + virtual const char* getErrorMsg(void); + virtual bool hasErrorOccured(void); + virtual void clearError(); + BaseTestImp* toBaseTestImp() { return this; } + virtual OCLTestImp* toOCLTestImp() { return NULL; } + virtual void useCPU() { _cpu = true; } + virtual void setIterationCount(int cnt); + virtual void setDeviceId(unsigned int deviceId); + virtual unsigned int getDeviceId(); + virtual void setPlatformIndex(unsigned int platformIndex); + virtual unsigned int getPlatformIndex(); + virtual float getPerfInfo(); + virtual void clearPerfInfo(); + + protected: + unsigned int _numSubTests; + unsigned int _openTest; + unsigned int _useThreads; + int _iterationCnt; + float _perfInfo; + bool _cpu; + + unsigned int _crcword; + unsigned int _crctab[256]; + + bool _errorFlag; + std::string _errorMsg; + + const char* _deviceName; + unsigned int _architecture; + unsigned int _deviceId; + unsigned int _platformIndex; + bool failed_ = false; + cl_int error_; + cl_uint type_; + cl_uint deviceCount_; + cl_device_id* devices_; + cl_context context_; + + cl_program program_; + cl_kernel kernel_; +}; + +// enum to keep track of different memory types +enum MemType { LOOCL, REMOTE_CACHED, REMOTE_UNCACHED }; + +class DataType { + cl_image_format f; + const char* str; + unsigned int size; + + public: + DataType() {} + + DataType(cl_image_format f, const char* str, unsigned int size) { + this->f = f; + this->str = str; + this->size = size; + } + operator const char*() { return str; } + + operator unsigned int() { return size; } + operator cl_image_format() { return f; } +}; + +// useful for initialization of an array of data types for a test +#define DTYPE(x, y) DataType(x, #x, (unsigned int)y) + +#endif diff --git a/opencl/tests/ocltst/module/include/OCLTestImp.h b/opencl/tests/ocltst/module/include/OCLTestImp.h new file mode 100644 index 0000000000..69f3212fdd --- /dev/null +++ b/opencl/tests/ocltst/module/include/OCLTestImp.h @@ -0,0 +1,83 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCLTestImp_H_ +#define _OCLTestImp_H_ + +#include +#include + +#include "BaseTestImp.h" +#include "CL/cl.h" +#include "OCL/Thread.h" +#include "OCLTest.h" +#include "OCLWrapper.h" + +class OCLTestImp : public BaseTestImp { + public: + OCLTestImp(); + virtual ~OCLTestImp(); + + public: + //! Abstract functions being defined here + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId, unsigned int platformIndex); + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual void run(void) = 0; + virtual unsigned int close(void); + //! Functions to set class members + + public: + void useCPU(); + int genIntRand(int a, int b); + int genBitRand(int n); + void accumulateCRC(const void* buffer, int len); + void setOCLWrapper(OCLWrapper* wrapper); + OCLTestImp* toOCLTestImp() { return this; } + + static OCLutil::Lock openDeviceLock; + static OCLutil::Lock compileLock; + + protected: + const std::vector& buffers() const { return buffers_; } + + OCLWrapper* _wrapper; + + int _seed; + + // Common data of any CL program + cl_int error_; + cl_uint type_; + cl_uint deviceCount_; + cl_device_id* devices_; + cl_platform_id platform_; + std::vector cmdQueues_; + cl_context context_; + + cl_program program_; + cl_kernel kernel_; + std::vector buffers_; +}; + +// useful for initialization of an array of data types for a test +#define DTYPE(x, y) DataType(x, #x, (unsigned int)y) + +#endif diff --git a/opencl/tests/ocltst/module/include/OCLTestListImp.h b/opencl/tests/ocltst/module/include/OCLTestListImp.h new file mode 100644 index 0000000000..5a542a302d --- /dev/null +++ b/opencl/tests/ocltst/module/include/OCLTestListImp.h @@ -0,0 +1,86 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef __Dictionary_h__ +#define __Dictionary_h__ + +// +// Testing module (plugin) interface forward declarations +// +#ifdef _WIN32 +#define OCL_DLLEXPORT __declspec(dllexport) +#define OCL_CALLCONV __cdecl +#endif +#ifdef __linux__ +#define OCL_DLLEXPORT +#define OCL_CALLCONV +#endif + +class OCLTest; + +// +// OCLTestList_TestCount - retrieve the number of tests in the testing module +// +extern "C" OCL_DLLEXPORT unsigned int OCL_CALLCONV OCLTestList_TestCount(void); + +// +// OCLTestList_TestLibVersion - retrieve the version of test lib in the testing +// module +// +extern "C" OCL_DLLEXPORT unsigned int OCL_CALLCONV +OCLTestList_TestLibVersion(void); + +// +// OCLTestList_TestLibName - retrieve the name of test library +// +extern "C" OCL_DLLEXPORT const char* OCL_CALLCONV OCLTestList_TestLibName(void); + +// +// OCLTestList_TestName - retrieve the name of the indexed test in the module +// +extern "C" OCL_DLLEXPORT const char* OCL_CALLCONV +OCLTestList_TestName(unsigned int testNum); + +// +// OCLTestList_CreateTest - create a test by index +// +extern "C" OCL_DLLEXPORT OCLTest* OCL_CALLCONV +OCLTestList_CreateTest(unsigned int testNum); + +// +// OCLTestList_DestroyTest - destroy a test object +// +extern "C" OCL_DLLEXPORT void OCL_CALLCONV +OCLTestList_DestroyTest(OCLTest* test); + +// +// internal global data that is populated in each dll +// +typedef struct _TestEntry { + const char* name; + void* (*create)(void); +} TestEntry; + +extern TestEntry TestList[]; +extern unsigned int TestListCount; +extern unsigned int TestLibVersion; +extern const char* TestLibName; + +#endif diff --git a/opencl/tests/ocltst/module/include/OclIncludes.h b/opencl/tests/ocltst/module/include/OclIncludes.h new file mode 100644 index 0000000000..1b3dfdac51 --- /dev/null +++ b/opencl/tests/ocltst/module/include/OclIncludes.h @@ -0,0 +1,32 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_INCLUDES_H +#define _OCL_INCLUDES_H + +#ifdef _WIN32 +#define POINTER_64 __ptr64 +#include +#include "d3d9.h" +#endif + +#include "CL/cl.h" + +#endif //_OCL_INCLUDES_H diff --git a/opencl/tests/ocltst/module/perf/CMakeLists.txt b/opencl/tests/ocltst/module/perf/CMakeLists.txt new file mode 100644 index 0000000000..b9780283c6 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/CMakeLists.txt @@ -0,0 +1,132 @@ +set(TESTS + OCLPerf3DImageWriteSpeed + OCLPerfAES256 + OCLPerfAtomicSpeed20 + OCLPerfAtomicSpeed + OCLPerfBufferCopyOverhead + OCLPerfBufferCopySpeed + OCLPerfBufferReadSpeed + OCLPerfBufferWriteSpeed + OCLPerfCommandQueue + OCLPerfConcurrency + OCLPerfCPUMemSpeed + OCLPerfDeviceConcurrency + OCLPerfDeviceEnqueue + OCLPerfDeviceEnqueue2 + OCLPerfDeviceEnqueueEvent + OCLPerfDeviceEnqueueSier + OCLPerfDevMemReadSpeed + OCLPerfDevMemWriteSpeed + OCLPerfDispatchSpeed + OCLPerfDoubleDMA + OCLPerfDoubleDMASeq + OCLPerfFillBuffer + OCLPerfFillImage + OCLPerfFlush + OCLPerfGenericBandwidth + OCLPerfGenoilSiaMiner + OCLPerfImageCopyCorners + OCLPerfImageCopySpeed + OCLPerfImageCreate + OCLPerfImageMapUnmap + OCLPerfImageReadSpeed + OCLPerfImageReadsRGBA + OCLPerfImageReadWrite + OCLPerfImageSampleRate + OCLPerfImageWriteSpeed + OCLPerfKernelArguments + OCLPerfKernelThroughput + OCLPerfLDSLatency + OCLPerfLDSReadSpeed + OCLPerfMandelbrot + OCLPerfMapBufferReadSpeed + OCLPerfMapBufferWriteSpeed + OCLPerfMapImageReadSpeed + OCLPerfMapImageWriteSpeed + OCLPerfMatrixTranspose + OCLPerfMemCombine + OCLPerfMemCreate + OCLPerfMemLatency + OCLPerfPinnedBufferReadSpeed + OCLPerfPinnedBufferWriteSpeed + OCLPerfPipeCopySpeed + OCLPerfProgramGlobalRead + OCLPerfProgramGlobalWrite + OCLPerfSampleRate + OCLPerfScalarReplArrayElem + OCLPerfSdiP2PCopy + OCLPerfSHA256 + OCLPerfSVMAlloc + OCLPerfSVMKernelArguments + OCLPerfSVMMap + OCLPerfSVMMemcpy + OCLPerfSVMMemFill + OCLPerfSVMSampleRate + OCLPerfTextureMemLatency + OCLPerfUAVReadSpeed + OCLPerfUAVReadSpeedHostMem + OCLPerfUAVWriteSpeedHostMem + OCLPerfUncoalescedRead + OCLPerfVerticalFetch +) + +add_library(oclperf SHARED + TestList.cpp + $) + +foreach(TEST ${TESTS}) + target_sources(oclperf + PRIVATE + ${TEST}.cpp) +endforeach() + +set_target_properties(oclperf PROPERTIES + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests/ocltst + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests/ocltst) + +target_compile_definitions(oclperf + PRIVATE + $) + +target_include_directories(oclperf + PRIVATE + $) + +target_link_libraries(oclperf + PRIVATE + OpenCL) + +add_custom_command( + TARGET oclperf POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/oclperf.exclude + ${CMAKE_BINARY_DIR}/tests/ocltst/oclperf.exclude) + +add_custom_target(test.ocltst.oclperf + COMMAND + ${CMAKE_COMMAND} -E env "OCL_ICD_FILENAMES=$" + $ -p 0 -m $ -A oclperf.exclude + DEPENDS + ocltst oclperf amdocl + WORKING_DIRECTORY + ${CMAKE_BINARY_DIR}/tests/ocltst + USES_TERMINAL) + +foreach(TEST ${TESTS}) + add_custom_target(test.ocltst.oclperf.${TEST} + COMMAND + ${CMAKE_COMMAND} -E env "OCL_ICD_FILENAMES=$" + $ -p 0 -m $ -t ${TEST} + DEPENDS + ocltst oclperf amdocl + WORKING_DIRECTORY + ${CMAKE_BINARY_DIR}/tests/ocltst + USES_TERMINAL) +endforeach() + +INSTALL(TARGETS oclperf DESTINATION ${OCLTST_INSTALL_DIR} COMPONENT ocltst) +INSTALL(FILES oclperf.exclude DESTINATION ${OCLTST_INSTALL_DIR} COMPONENT ocltst) + diff --git a/opencl/tests/ocltst/module/perf/OCLPerf3DImageWriteSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerf3DImageWriteSpeed.cpp new file mode 100644 index 0000000000..ce42257c40 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerf3DImageWriteSpeed.cpp @@ -0,0 +1,211 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerf3DImageWriteSpeed.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define KERNEL_CODE(...) #__VA_ARGS__ + +#define NUM_SIZES 4 +static const unsigned int Sizes[NUM_SIZES] = {64, 128, 256, 512}; + +#define NUM_FORMATS 1 +static const cl_image_format formats[NUM_FORMATS] = { + {CL_RGBA, CL_UNSIGNED_INT8}}; +static const char *textFormats[NUM_FORMATS] = {"CL_RGBA , CL_UNSIGNED_INT8"}; +static const unsigned int formatSize[NUM_FORMATS] = {sizeof(CL_UNSIGNED_INT8)}; + +const static char *strKernel = {KERNEL_CODE( + \n __kernel void image_kernel(write_only image3d_t input) { + size_t x = get_global_id(0); + size_t y = get_global_id(1); + size_t z = get_global_id(2); + + int4 coords = (int4)(x, y, z, 0); + write_imageui(input, coords, (1, 1, 1, 1)); +} + \n)}; + +OCLPerf3DImageWriteSpeed::OCLPerf3DImageWriteSpeed() { + _numSubTests = NUM_SIZES * NUM_FORMATS; +} + +OCLPerf3DImageWriteSpeed::~OCLPerf3DImageWriteSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerf3DImageWriteSpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + error_ = CL_SUCCESS; + testId_ = test; + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = 0; + kernel_ = 0; + cmd_queue_ = 0; + imageBuffer_ = 0; + skip_ = false; + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_EXTENSIONS, + 1024, charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + if (!strstr(charbuf, "cl_khr_3d_image_writes")) { + skip_ = true; + testDescString = "3D Write not supported. Test Skipped."; + return; + } + + bufSize_ = Sizes[test % NUM_SIZES]; + bufnum_ = (test / NUM_SIZES) % NUM_FORMATS; + memSize_ = bufSize_ * bufSize_ * bufSize_ * formatSize[bufnum_]; + + cmd_queue_ = cmdQueues_[_deviceId]; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "image_kernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + imageBuffer_ = _wrapper->clCreateImage3D( + context_, CL_MEM_WRITE_ONLY, &formats[bufnum_], bufSize_, bufSize_, + bufSize_, 0, 0, NULL, &error_); + CHECK_RESULT(imageBuffer_ == 0, "clCreateImage(imageBuffer_) failed"); + + // set kernel arguments + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &imageBuffer_); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); +} + +void OCLPerf3DImageWriteSpeed::run(void) { + if (skip_) { + return; + } + + CPerfCounter timer; + unsigned int fmt_num = (testId_ / NUM_SIZES) % NUM_FORMATS; + + size_t gws[3] = {bufSize_, bufSize_, bufSize_}; + size_t lws[3] = {8, 8, 4}; + + // warm up + error_ = _wrapper->clEnqueueNDRangeKernel(cmd_queue_, kernel_, 3, NULL, gws, + lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(cmd_queue_); + + // checkData + char *bufptr = (char *)malloc(memSize_); + + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSize_, bufSize_, bufSize_}; + size_t image_row_pitch = bufSize_ * formatSize[bufnum_]; + size_t image_slice_pitch = image_row_pitch * bufSize_; + error_ = clEnqueueReadImage(cmd_queue_, imageBuffer_, true, origin, region, + image_row_pitch, image_slice_pitch, bufptr, 0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadImage() failed"); + + for (size_t i = 0; i < bufSize_ * bufSize_ * bufSize_ * 4; ++i) { + if (bufptr[i] != 1) { + printf("(%4dx%4dx%4d) fmt:%s(%1u) checkData() fail, image_ptr[%u] = %d\n", + bufSize_, bufSize_, bufSize_, textFormats[fmt_num], + formatSize[bufnum_], (unsigned int)i, (int)bufptr[i]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + char buf[256]; + SNPRINTF(buf, sizeof(buf), + " (%4dx%4dx%4d) fmt:%s(%1d) checkData() FAILED! ", bufSize_, + bufSize_, bufSize_, textFormats[fmt_num], formatSize[bufnum_]); + testDescString = buf; + return; + } + } + delete bufptr; + + // test begins + unsigned int numIter = 5; + + timer.Reset(); + timer.Start(); + + for (unsigned int i = 0; i < numIter; ++i) { + error_ = _wrapper->clEnqueueNDRangeKernel(cmd_queue_, kernel_, 3, NULL, gws, + lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(cmd_queue_); + } + + timer.Stop(); + + double sec = timer.GetElapsedTime(); + + // write_image speed in GB/s + double perf = ((double)memSize_ * numIter * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%3dx%3dx%3d) fmt:%s(%1u) i: %2d (GB/s) ", + bufSize_, bufSize_, bufSize_, textFormats[fmt_num], + formatSize[bufnum_], numIter); + testDescString = buf; +} + +unsigned int OCLPerf3DImageWriteSpeed::close(void) { + if (!skip_) { + if (imageBuffer_) { + error_ = _wrapper->clReleaseMemObject(imageBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(imageBuffer_) failed"); + } + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerf3DImageWriteSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerf3DImageWriteSpeed.h new file mode 100644 index 0000000000..7757606471 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerf3DImageWriteSpeed.h @@ -0,0 +1,49 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_3DImageWriteSpeed_H_ +#define _OCL_3DImageWriteSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerf3DImageWriteSpeed : public OCLTestImp { + public: + OCLPerf3DImageWriteSpeed(); + virtual ~OCLPerf3DImageWriteSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + cl_command_queue cmd_queue_; + cl_mem imageBuffer_; + + unsigned int bufSize_; + unsigned int bufnum_; + char* memptr; + unsigned int memSize_; + unsigned int testId_; + + bool skip_; +}; + +#endif // _OCL_3DImageWriteSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfAES256.cpp b/opencl/tests/ocltst/module/perf/OCLPerfAES256.cpp new file mode 100644 index 0000000000..9eca37fce8 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfAES256.cpp @@ -0,0 +1,451 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfAES256.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +static const char *aes256_kernel = + "// NOTE: THIS KERNEL WAS ADOPTED FROM SISOFT SANDRA: DO NOT " + "REDISTRIBUTE!!\n" + "inline uint Load(__global uint* pData, const uint iX, const uint iY)\n" + "{\n" + " return pData[iX | (iY << 8)];\n" + "}\n" + "\n" + "\n" + "inline uint4 Load4(__global uint* pData, const uint4 uX, const uint iY)\n" + "{\n" + " uint uExtent = iY << 8;\n" + " uint4 uNdx = uX + uExtent;\n" + " \n" + " return (uint4)(pData[uNdx.x], pData[uNdx.y], pData[uNdx.z], " + "pData[uNdx.w]);\n" + "}\n" + "\n" + "\n" + "__kernel \n" + "__attribute__((vec_type_hint(uint4))) \n" + "void CryptThread(__global uint4* pInput, __global uint4* pOutput,\n" + " __global uint* pTables,\n" + " __global uint4* pKey, const uint iRounds)\n" + "{\n" + " const uint iNdx = get_global_id(0);\n" + " \n" + " uint4 state, istate, tstate;\n" + " state = pInput[iNdx] ^ pKey[iRounds];\n" + " \n" + " for (uint i = iRounds-1; i; i--)\n" + " {\n" + " istate = state & 0xFF;\n" + " tstate = Load4(pTables, istate.xyzw, 0);\n" + "\n" + " istate = (state >> 8) & 0xFF;\n" + " tstate^= Load4(pTables, istate.wxyz, 1);\n" + "\n" + " istate = (state >> 16) & 0xFF;\n" + " tstate^= Load4(pTables, istate.zwxy, 2);\n" + "\n" + " istate = state >> 24;\n" + " tstate^= Load4(pTables, istate.yzwx, 3);\n" + "\n" + " state = tstate ^ pKey[i];\n" + " }\n" + "\n" + " istate = state & 0xFF;\n" + " tstate = Load4(pTables, istate.xyzw, 4);\n" + "\n" + " istate = (state >> 8) & 0xFF;\n" + " tstate |= Load4(pTables, istate.wxyz, 4) << 8;\n" + "\n" + " istate = (state >> 16) & 0xFF;\n" + " tstate |= Load4(pTables, istate.zwxy, 4) << 16;\n" + "\n" + " istate = state >> 24;\n" + " tstate |= Load4(pTables, istate.yzwx, 4) << 24;\n" + "\n" + " pOutput[iNdx] = tstate ^ pKey[0];\n" + "}\n"; + +static const char *aes256_kernel2 = + "// NOTE: THIS KERNEL WAS ADOPTED FROM SISOFT SANDRA: DO NOT " + "REDISTRIBUTE!!\n" + "#define AES_BLOCK_SIZE 16\n" + "#define AES_TABLE_SIZE 256\n" + "\n" + "#define AES_TABLE_MAX 5\n" + "#define AES_CONST_SIZE (AES_TABLE_SIZE*AES_TABLE_MAX)\n" + "\n" + "#define AES_ROUND_128 10\n" + "#define AES_ROUND_192 12\n" + "#define AES_ROUND_256 14\n" + "#define AES_ROUNDKEY_MAX (AES_BLOCK_SIZE/4*(AES_ROUND_256+1))\n" + "#define _IS_GPU_\n" + "\n" + "\n" + "inline uint Load(\n" + "#ifdef _IS_GPU_\n" + " __local uint* pData,\n" + "#else\n" + " __constant uint* pData,\n" + "#endif\n" + " const uint iX, const uint iY)\n" + "{\n" + " const uint uNdx = iX + iY*AES_TABLE_SIZE;\n" + " return pData[uNdx];\n" + "}\n" + "\n" + "\n" + "inline uint4 Load4(\n" + "#ifdef _IS_GPU_\n" + " __local uint* pData,\n" + "#else\n" + " __constant uint* pData,\n" + "#endif\n" + " const uint4 uX, const uint iY)\n" + "{\n" + " const uint uExtent = iY*AES_TABLE_SIZE;\n" + " const uint4 uNdx = uX + uExtent;\n" + " \n" + " return (uint4)(pData[uNdx.x], pData[uNdx.y], pData[uNdx.z], " + "pData[uNdx.w]);\n" + "}\n" + "\n" + "\n" + "__kernel \n" + "__attribute__((vec_type_hint(uint4)))\n" + "#ifdef KERNEL_MAX_THREADS\n" + "__attribute__((work_group_size_hint(KERNEL_MAX_THREADS, 1, 1)))\n" + "#endif\n" + "void CryptThread(__global const uint4* pInput, __global uint4* pOutput,\n" + " __constant uint* pTables,\n" + " __constant uint4* pKey, const uint iRounds)\n" + "{\n" + " const size_t iNdx = get_global_id(0);\n" + "\n" + "#ifdef _IS_GPU_\n" + " #define Load4T(x, y) Load4(ulTables, x, y)\n" + "\n" + " __local uint ulTables[AES_CONST_SIZE];\n" + "\n" + " const uint iLdx = get_local_id(0);\n" + " if (iLdx < AES_TABLE_SIZE) {\n" + " const uint iGrps = get_local_size(0);\n" + " const uint iLSize = min(iGrps, (uint)AES_TABLE_SIZE);\n" + " const uint iBpL = AES_CONST_SIZE/iLSize;\n" + "\n" + " const uint iStart = iLdx*iBpL;\n" + " const uint iEnd = iStart + iBpL;\n" + "\n" + " for (uint i=iStart; i> 8) & 0xFF;\n" + " tstate^= Load4T(istate.yzwx, 1);\n" + "\n" + " istate = (state >> 16) & 0xFF;\n" + " tstate^= Load4T(istate.zwxy, 2);\n" + "\n" + " istate = state >> 24;\n" + " tstate^= Load4T(istate.wxyz, 3);\n" + "\n" + " state = tstate ^ pKey[i];\n" + " }\n" + "\n" + " istate = state & 0xFF;\n" + " tstate = Load4T(istate.xyzw, 4);\n" + "\n" + " istate = (state >> 8) & 0xFF;\n" + " tstate |= Load4T(istate.yzwx, 4) << 8;\n" + "\n" + " istate = (state >> 16) & 0xFF;\n" + " tstate |= Load4T(istate.zwxy, 4) << 16;\n" + "\n" + " istate = state >> 24;\n" + " tstate |= Load4T(istate.wxyz, 4) << 24;\n" + "\n" + " pOutput[iNdx] = tstate ^ pKey[iRounds];\n" + "}\n"; + +OCLPerfAES256::OCLPerfAES256() { _numSubTests = 2; } + +OCLPerfAES256::~OCLPerfAES256() {} + +void OCLPerfAES256::setData(cl_mem buffer, unsigned int val) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, buffer, true, CL_MAP_WRITE, 0, bufSize_, 0, NULL, NULL, + &error_); + for (unsigned int i = 0; i < bufSize_ / sizeof(unsigned int); i++) + data[i] = val; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); + _wrapper->clFinish(cmd_queue_); +} + +void OCLPerfAES256::checkData(cl_mem buffer) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, buffer, true, CL_MAP_READ, 0, bufSize_, 0, NULL, NULL, + &error_); + for (unsigned int i = 0; i < bufSize_ / sizeof(unsigned int); i++) { + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); + _wrapper->clFinish(cmd_queue_); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfAES256::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + inBuffer_ = 0; + outBuffer_ = 0; + tableBuffer_ = 0; + keyBuffer_ = 0; + blockSize_ = 1024; + maxIterations = 50; + + bufSize_ = 5592320 * sizeof(cl_uint4); + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, + "Couldn't find platform with GPU devices, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + // Increase iterations for devices with many CUs + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS, + sizeof(size_t), &numCUs, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + maxIterations *= (unsigned int)(1 + 10 * numCUs / 20); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + inBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY, bufSize_, + NULL, &error_); + CHECK_RESULT(inBuffer_ == 0, "clCreateBuffer(inBuffer) failed"); + + outBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, bufSize_, + NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + tableBuffer_ = + _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY, 5120, NULL, &error_); + CHECK_RESULT(tableBuffer_ == 0, "clCreateBuffer(tableBuffer) failed"); + + keyBuffer_ = + _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY, 240, NULL, &error_); + CHECK_RESULT(keyBuffer_ == 0, "clCreateBuffer(keyBuffer) failed"); + + if (_openTest == 0) { + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&aes256_kernel, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + testDescString += "orig"; + } else { + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&aes256_kernel2, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + testDescString += " new"; + } + + const char *buildOps = NULL; + error_ = _wrapper->clBuildProgram(program_, 1, &device, buildOps, NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "CryptThread", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + cl_uint rounds = 14; + + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&inBuffer_); + error_ = + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), (void *)&outBuffer_); + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_mem), + (void *)&tableBuffer_); + error_ = + _wrapper->clSetKernelArg(kernel_, 3, sizeof(cl_mem), (void *)&keyBuffer_); + error_ = + _wrapper->clSetKernelArg(kernel_, 4, sizeof(cl_uint), (void *)&rounds); + setData(inBuffer_, 0xdeadbeef); + setData(outBuffer_, 0xdeadbeef); +} + +void OCLPerfAES256::run(void) { + int global = bufSize_ / sizeof(cl_uint4); + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < maxIterations; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + } + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // No idea what data should be in here + // checkData(outBuffer_); + // Compute GB/s + double perf = + ((double)bufSize_ * (double)maxIterations * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; +} + +unsigned int OCLPerfAES256::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (inBuffer_) { + error_ = _wrapper->clReleaseMemObject(inBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (tableBuffer_) { + error_ = _wrapper->clReleaseMemObject(tableBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(tableBuffer_) failed"); + } + if (keyBuffer_) { + error_ = _wrapper->clReleaseMemObject(keyBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(keyBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfAES256.h b/opencl/tests/ocltst/module/perf/OCLPerfAES256.h new file mode 100644 index 0000000000..7a940da17b --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfAES256.h @@ -0,0 +1,58 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_AES256_H_ +#define _OCL_AES256_H_ + +#include "OCLTestImp.h" + +class OCLPerfAES256 : public OCLTestImp { + public: + OCLPerfAES256(); + virtual ~OCLPerfAES256(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void setData(cl_mem buffer, unsigned int data); + void checkData(cl_mem buffer); + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem inBuffer_; + cl_mem outBuffer_; + cl_mem tableBuffer_; + cl_mem keyBuffer_; + cl_int error_; + + unsigned int width_; + unsigned int bufSize_; + unsigned int blockSize_; + unsigned int maxIterations; + size_t numCUs; +}; + +#endif // _OCL_AES256_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed.cpp new file mode 100644 index 0000000000..d07422e90b --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed.cpp @@ -0,0 +1,817 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfAtomicSpeed.h" + +#include +#include +#include +#include +#include + +#include "CL/cl.h" +#include "OCLPerfAtomicSpeedKernels.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +// Define the test suite tests. +testOCLPerfAtomicSpeedStruct testOCLPerfAtomicSpeedList[] = { + {LocalHistogram, 1}, + {LocalHistogram, 2}, + {LocalHistogram, 4}, + {GlobalHistogram, 1}, + {GlobalHistogram, 2}, + {GlobalHistogram, 4}, + {Global4Histogram, 1}, + {Global4Histogram, 2}, + {Global4Histogram, 4}, + {LocalReductionNoAtomics, 1}, + {LocalReductionNoAtomics, 2}, + {LocalReductionNoAtomics, 4}, + {LocalReductionAtomics, 1}, + {LocalReductionAtomics, 2}, + {LocalReductionAtomics, 4}, + {Local4ReductionNoAtomics, 1}, + {Local4ReductionNoAtomics, 2}, + {Local4ReductionNoAtomics, 4}, + /* {Local4ReductionAtomics, 1}, + {Local4ReductionAtomics, 2}, + {Local4ReductionAtomics, 4},*/ + {GlobalWGReduction, 1}, + {GlobalWGReduction, 2}, + {GlobalWGReduction, 4}, + {GlobalAllToZeroReduction, 1}, + {GlobalAllToZeroReduction, 2}, + {GlobalAllToZeroReduction, 4}, + {Global4WGReduction, 1}, + {Global4WGReduction, 2}, + {Global4WGReduction, 4}, + {Global4AllToZeroReduction, 1}, + {Global4AllToZeroReduction, 2}, + {Global4AllToZeroReduction, 4}, +}; + +/////////////////////////////////////////////////////////////////////////////// +// OCLPerfAtomicSpeed implementation. +/////////////////////////////////////////////////////////////////////////////// +OCLPerfAtomicSpeed::OCLPerfAtomicSpeed() { + _atomicsSupported = false; + _dataSizeTooBig = false; + _numSubTests = + sizeof(testOCLPerfAtomicSpeedList) / sizeof(testOCLPerfAtomicSpeedStruct); + _numLoops = 10; + _nCurrentInputScale = 1; + _maxMemoryAllocationSize = 0; + + _input = NULL; + _output = NULL; + _inputBuffer = NULL; + _outputBuffer = NULL; + _workgroupSize = 256; + _programs.clear(); + _kernels.clear(); +} + +OCLPerfAtomicSpeed::~OCLPerfAtomicSpeed() {} + +void OCLPerfAtomicSpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_int status = CL_SUCCESS; + + device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + _cpuReductionSum = 0; + _nCurrentInputScale = testOCLPerfAtomicSpeedList[_openTest].inputScale; + AtomicType atomicType = testOCLPerfAtomicSpeedList[_openTest].atomicType; + + // Setup stuff... + setupHistogram(); + calculateHostBin(); + + context_ = 0; + cmd_queue_ = 0; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + // Get last for default +#if 0 + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); +#if 0 + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + platform = platforms[i]; + break; + } +#endif + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { +#if 0 + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } +#endif + platform = platforms[_platformIndex]; + } +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, + "Couldn't find platform with GPU devices, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, NULL, NULL, &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + // Global memory size + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, + sizeof(cl_ulong), + &_maxMemoryAllocationSize, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, + "clGetDeviceIDs(CL_DEVICE_GLOBAL_MEM_SIZE) failed"); + + // Check that the test size is not too big for the current GPU. + _dataSizeTooBig = false; + cl_ulong tenMB = 1024 * 10240; + if (_inputNBytes >= (_maxMemoryAllocationSize - tenMB)) { + _dataSizeTooBig = true; + return; + } + + char *p = strstr(charbuf, "cl_khr_global_int32_base_atomics"); + char *p2 = strstr(charbuf, "cl_khr_local_int32_base_atomics"); + + _atomicsSupported = false; + if (p || p2) _atomicsSupported = true; + + // Verify atomics are supported. + if (!_atomicsSupported) return; + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + // Create buffers... + _inputBuffer = + clCreateBuffer(context_, CL_MEM_READ_ONLY, _inputNBytes, 0, &status); + CHECK_RESULT(status, "clCreateBuffer failed. (inputBuffer)"); + + // Create the programs/kernels for the current test type. + CreateKernels(atomicType); + + _nThreadsPerGroup = _workgroupSize; + _nGroups = _nThreads / _nThreadsPerGroup; + _outputNBytes = _nGroups * NBINS * sizeof(cl_uint); + if (IsReduction(atomicType)) _outputNBytes = _inputNBytes; + + _output = (cl_uint *)malloc(_outputNBytes); + if (0 == _output) { + _dataSizeTooBig = true; + return; + } + + // Create output Buffer + _outputBuffer = + clCreateBuffer(context_, CL_MEM_READ_WRITE, _outputNBytes, 0, &status); + CHECK_RESULT(status, "clCreateBuffer failed. (outputBuffer)"); +} + +// Create the programs/kernels for the current test type. +void OCLPerfAtomicSpeed::CreateKernels(const AtomicType atomicType) { + char log[16384]; + cl_kernel kernel_; + cl_program program_; + char buildOptions[1000]; + cl_int status = CL_SUCCESS; + + SNPRINTF(buildOptions, sizeof(buildOptions), + "-D NBINS=%d -D BITS_PER_PIX=%d -D NBANKS=%d", NBINS, BITS_PER_PIX, + NBANKS); + + // Create the programs. + switch (atomicType) { + case LocalHistogram: + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&local_atomics_histogram, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + _programs.push_back(program_); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&local_atomics_reduce, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + _programs.push_back(program_); + break; + case LocalReductionNoAtomics: + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&local_reduction, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + _programs.push_back(program_); + break; + case Local4ReductionNoAtomics: + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&local_vec4_reduction, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + _programs.push_back(program_); + break; + case LocalReductionAtomics: + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&local_atomics_reduction, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + _programs.push_back(program_); + break; + case Local4ReductionAtomics: + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&local_vec4_atomics_reduction, NULL, + &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + _programs.push_back(program_); + break; + case GlobalHistogram: + case Global4Histogram: + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&global_atomics_histogram, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + _programs.push_back(program_); + break; + case GlobalWGReduction: + case Global4WGReduction: + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&global_atomics_sum_reduction_workgroup, + NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + _programs.push_back(program_); + break; + case GlobalAllToZeroReduction: + case Global4AllToZeroReduction: + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&global_atomics_sum_reduction_all_to_zero, + NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + _programs.push_back(program_); + break; + default: + CHECK_RESULT(true, "Atomic type not supported (clCreateProgram)"); + } + // Build the programs. + for (size_t i = 0; i < _programs.size(); i++) { + error_ = _wrapper->clBuildProgram(_programs[i], 1, &device, buildOptions, + NULL, NULL); + if (error_ != CL_SUCCESS) { + status = _wrapper->clGetProgramBuildInfo(_programs[i], device, + CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + } + + switch (atomicType) { + case LocalHistogram: + kernel_ = _wrapper->clCreateKernel(_programs[0], + "local_atomics_histogram", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + _kernels.push_back(kernel_); + kernel_ = _wrapper->clCreateKernel(_programs[1], "local_atomics_reduce", + &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + _kernels.push_back(kernel_); + break; + case LocalReductionNoAtomics: + case Local4ReductionNoAtomics: + case LocalReductionAtomics: + case Local4ReductionAtomics: + kernel_ = + _wrapper->clCreateKernel(_programs[0], "local_reduction", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + _kernels.push_back(kernel_); + break; + case GlobalHistogram: + case Global4Histogram: + kernel_ = _wrapper->clCreateKernel(_programs[0], + "global_atomics_histogram", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + _kernels.push_back(kernel_); + break; + case GlobalWGReduction: + case Global4WGReduction: + kernel_ = _wrapper->clCreateKernel( + _programs[0], "global_atomics_sum_reduction_workgroup", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + _kernels.push_back(kernel_); + break; + case GlobalAllToZeroReduction: + case Global4AllToZeroReduction: + kernel_ = _wrapper->clCreateKernel( + _programs[0], "global_atomics_sum_reduction_all_to_zero", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + _kernels.push_back(kernel_); + break; + default: + CHECK_RESULT(true, "Atomic type not supported (clCreateKernel)"); + } +} + +// Sets the kernel arguments based on the current test type. +void OCLPerfAtomicSpeed::SetKernelArguments(const AtomicType atomicType) { + int Arg = 0; + int localSize = 0; + int itemsPerThread = 1; + cl_int status = CL_SUCCESS; + + switch (atomicType) { + case LocalHistogram: + // Set arguments for the local atomics histogram kernel + status = _wrapper->clSetKernelArg(_kernels[0], Arg++, sizeof(cl_mem), + (void *)&_inputBuffer); + CHECK_RESULT(status, "clSetKernelArg failed. (inputBuffer)"); + + status |= _wrapper->clSetKernelArg(_kernels[0], Arg++, sizeof(cl_mem), + (void *)&_outputBuffer); + CHECK_RESULT(status, "clSetKernelArg failed. (outputBuffer)"); + + status |= _wrapper->clSetKernelArg(_kernels[0], Arg++, + sizeof(_n4VectorsPerThread), + (void *)&_n4VectorsPerThread); + CHECK_RESULT(status, "clSetKernelArg failed. (n4VectorsPerThread)"); + + // Set arguments for the local atomics reduce kernel + Arg = 0; + status |= _wrapper->clSetKernelArg(_kernels[1], Arg++, sizeof(cl_mem), + (void *)&_outputBuffer); + CHECK_RESULT(status, "clSetKernelArg failed. (outputBuffer)"); + + status |= _wrapper->clSetKernelArg(_kernels[1], Arg++, sizeof(_nGroups), + (void *)&_nGroups); + CHECK_RESULT(status, "clSetKernelArg failed. (nGroups)"); + break; + case LocalReductionAtomics: + case LocalReductionNoAtomics: + case Local4ReductionNoAtomics: + case Local4ReductionAtomics: + status = _wrapper->clSetKernelArg(_kernels[0], Arg++, sizeof(cl_mem), + (void *)&_inputBuffer); + CHECK_RESULT(status, "clSetKernelArg failed. (inputBuffer)"); + + status |= _wrapper->clSetKernelArg(_kernels[0], Arg++, sizeof(cl_mem), + (void *)&_outputBuffer); + CHECK_RESULT(status, "clSetKernelArg failed. (outputBuffer)"); + + localSize = DEFAULT_WG_SIZE * sizeof(cl_uint); + if ((Local4ReductionNoAtomics == atomicType) || + (Local4ReductionAtomics == atomicType)) + localSize *= 4; + status = _wrapper->clSetKernelArg(_kernels[0], Arg++, localSize, NULL); + CHECK_RESULT(status, "clSetKernelArg failed. (local memory)"); + break; + case GlobalHistogram: + case Global4Histogram: + case GlobalWGReduction: + case Global4WGReduction: + case GlobalAllToZeroReduction: + case Global4AllToZeroReduction: + // Set arguments for the global atomics histogram kernel + if ((Global4Histogram == atomicType) || + (Global4WGReduction == atomicType) || + (Global4AllToZeroReduction == atomicType)) + itemsPerThread = 4; + + status = _wrapper->clSetKernelArg( + _kernels[0], Arg++, sizeof(itemsPerThread), (void *)&itemsPerThread); + CHECK_RESULT(status, "clSetKernelArg failed. (itemsPerThread)"); + + status = _wrapper->clSetKernelArg(_kernels[0], Arg++, sizeof(cl_mem), + (void *)&_inputBuffer); + CHECK_RESULT(status, "clSetKernelArg failed. (inputBuffer)"); + + status |= _wrapper->clSetKernelArg(_kernels[0], Arg++, sizeof(cl_mem), + (void *)&_outputBuffer); + CHECK_RESULT(status, "clSetKernelArg failed. (outputBuffer)"); + break; + default: + CHECK_RESULT(true, "Atomic type not supported (clSetKernelArg)"); + } +} + +// Since we write multiple times to the output in global atomics, need to +// reset the content every time. +void OCLPerfAtomicSpeed::ResetGlobalOutput() { + cl_int status; + + memset(_output, 0, _outputNBytes); + + status = + _wrapper->clEnqueueWriteBuffer(cmd_queue_, _outputBuffer, CL_TRUE, 0, + _outputNBytes, _output, 0, NULL, NULL); + CHECK_RESULT(status, "clEnqueueWriteBuffer failed."); + + status = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(status, "clFlush failed."); +} + +// Run the local histogram kernels. +void OCLPerfAtomicSpeed::RunLocalHistogram() { + cl_uint status; + cl_event events[2]; + size_t globalThreads[3] = {1}; + size_t localThreads[3] = {1}; + size_t globalThreadsReduce = NBINS; + size_t localThreadsReduce = _nThreadsPerGroup; + + globalThreads[0] = _nThreads; + localThreads[0] = _nThreadsPerGroup; + + status = _wrapper->clEnqueueNDRangeKernel(cmd_queue_, _kernels[0], 1, NULL, + globalThreads, localThreads, 0, + NULL, &events[0]); + CHECK_RESULT(status, "clEnqueueNDRangeKernel failed. (histogram)"); + + status = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, _kernels[1], 1, NULL, &globalThreadsReduce, + &localThreadsReduce, 1, &events[0], &events[1]); + CHECK_RESULT(status, "clEnqueueNDRangeKernel failed. (reduce)"); + + status = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(status, "clFlush failed."); + + status = _wrapper->clWaitForEvents(1, &events[0]); + status |= _wrapper->clWaitForEvents(1, &events[1]); + CHECK_RESULT(status, "clWaitForEvents failed."); +} + +// Run the local reduction kernel. +void OCLPerfAtomicSpeed::RunLocalReduction(const AtomicType atomicType) { + cl_uint status; + size_t globalThreads[3] = {1}; + size_t localThreads[3] = {1}; + + globalThreads[0] = _inputNBytes / sizeof(cl_uint) / 2; + localThreads[0] = _nThreadsPerGroup; + if ((Local4ReductionNoAtomics == atomicType) || + (Local4ReductionAtomics == atomicType)) + globalThreads[0] /= 4; + + status = _wrapper->clEnqueueNDRangeKernel(cmd_queue_, _kernels[0], 1, NULL, + globalThreads, localThreads, 0, + NULL, NULL); + CHECK_RESULT(status, "clEnqueueNDRangeKernel failed. (reduction)"); + + status = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(status, "clFlush failed."); +} + +// Run the global histogram kernel. +void OCLPerfAtomicSpeed::RunGlobalHistogram(AtomicType atomicType) { + cl_uint status; + size_t globalThreads[3] = {1}; + size_t localThreads[3] = {1}; + + globalThreads[0] = _inputNBytes / sizeof(cl_uint); + localThreads[0] = _nThreadsPerGroup; + + if ((Global4Histogram == atomicType) || (Global4WGReduction == atomicType) || + (Global4AllToZeroReduction == atomicType)) + globalThreads[0] /= 4; + + status = _wrapper->clEnqueueNDRangeKernel(cmd_queue_, _kernels[0], 1, NULL, + globalThreads, localThreads, 0, + NULL, NULL); + CHECK_RESULT(status, "clEnqueueNDRangeKernel failed."); + + status = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(status, "clFlush failed."); +} + +// Run the AtomicSpeed logic. +void OCLPerfAtomicSpeed::run() { + int Arg = 0; + cl_uint status; + AtomicType atomicType = testOCLPerfAtomicSpeedList[_openTest].atomicType; + + // Verify atomics are supported. + if ((!_atomicsSupported) || (_dataSizeTooBig)) return; + + // Write data to the GPU + status = _wrapper->clEnqueueWriteBuffer(cmd_queue_, _inputBuffer, CL_FALSE, 0, + _inputNBytes, _input, 0, NULL, NULL); + CHECK_RESULT(status, "clEnqueueWriteBuffer failed. (inputBuffer)"); + + status = _wrapper->clFlush(cmd_queue_); + CHECK_RESULT(status, "clFlush failed."); + + // Set the current arguments based on the test type. + SetKernelArguments(atomicType); + + // Run the kernels. + CPerfCounter timer; + double totalTime = 0.0f; + + for (unsigned int k = 0; k < _numLoops + 1; k++) { + // Since we run multiple times using global atomics the output + // would get accumulated therefore first clean it. + ResetGlobalOutput(); + + timer.Reset(); + timer.Start(); + switch (atomicType) { + case LocalHistogram: + RunLocalHistogram(); + break; + case LocalReductionAtomics: + case LocalReductionNoAtomics: + case Local4ReductionNoAtomics: + case Local4ReductionAtomics: + RunLocalReduction(atomicType); + break; + case GlobalHistogram: + case Global4Histogram: + case GlobalWGReduction: + case Global4WGReduction: + case GlobalAllToZeroReduction: + case Global4AllToZeroReduction: + RunGlobalHistogram(atomicType); + break; + default: + CHECK_RESULT(true, "Atomic type not supported"); + } + timer.Stop(); + // Don't count the warm-up + if (0 != k) totalTime += timer.GetElapsedTime(); + } + + // Read the results back to the CPU - Only do it for the last run + // of the test instead of for each iteration of _numLoops. + status = _wrapper->clEnqueueReadBuffer(cmd_queue_, _outputBuffer, CL_FALSE, 0, + _outputNBytes, _output, 0, NULL, NULL); + CHECK_RESULT(status, "clEnqueueReadBuffer failed."); + status = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(status, "clFlush failed."); + + // Print the results. + PrintResults(atomicType, totalTime); + + // Check the results for the current test. + _errorFlag = !(VerifyResults(atomicType)); +} + +// Compare the results and see if they match +bool OCLPerfAtomicSpeed::VerifyResults(const AtomicType atomicType) { + cl_uint i = 0; + bool flag = true; + cl_uint calculatedValue = 0; + cl_uint reductionElementCount = 0; + switch (atomicType) { + case LocalHistogram: + case GlobalHistogram: + case Global4Histogram: + for (i = 0; i < NBINS; ++i) { + if (_cpuhist[i] != _output[i]) { + flag = false; + break; + } + } + break; + case LocalReductionAtomics: + case LocalReductionNoAtomics: + case Local4ReductionNoAtomics: + case Local4ReductionAtomics: + case GlobalWGReduction: + case Global4WGReduction: + reductionElementCount = + _inputNBytes / sizeof(cl_uint) / _nThreadsPerGroup; + for (i = 0; i < reductionElementCount; i++) { + calculatedValue += _output[i]; + } + flag = (calculatedValue == _cpuReductionSum); + break; + case GlobalAllToZeroReduction: + case Global4AllToZeroReduction: + flag = (_output[0] == _cpuReductionSum); + break; + default: + CHECK_RESULT_NO_RETURN(true, "Atomic type not supported (VerifyResults)"); + return false; + } + if (!flag) printf("WRONG VALUES!!!!!"); + return flag; +} + +unsigned int OCLPerfAtomicSpeed::close() { + size_t i = 0; + for (; i < _kernels.size(); i++) { + error_ = _wrapper->clReleaseKernel(_kernels[i]); + } + for (; i < _programs.size(); i++) { + error_ = _wrapper->clReleaseProgram(_programs[i]); + } + if (_inputBuffer) { + error_ = clReleaseMemObject(_inputBuffer); + CHECK_RESULT_NO_RETURN(error_, "clReleaseMemObject failed.(inputBuffer )"); + } + if (_outputBuffer) { + error_ = clReleaseMemObject(_outputBuffer); + CHECK_RESULT_NO_RETURN(error_, "clReleaseMemObject failed.(outputBuffer)"); + } + + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + // Free host memory. + free(_input); + free(_output); + + // Reset everything. + _kernels.clear(); + _programs.clear(); + _inputBuffer = NULL; + _outputBuffer = NULL; + cmd_queue_ = NULL; + context_ = NULL; + _input = NULL; + _output = NULL; + + return _crcword; +} + +/* Helper functions */ +void OCLPerfAtomicSpeed::calculateHostBin() { + // compute CPU histogram + cl_int *p = (cl_int *)_input; + memset(_cpuhist, 0, NBINS * sizeof(cl_uint)); + _cpuReductionSum = 0; + + for (unsigned int i = 0; i < _inputNBytes / sizeof(cl_uint); i++) { + _cpuhist[(p[i] >> 24) & 0xff]++; + _cpuhist[(p[i] >> 16) & 0xff]++; + _cpuhist[(p[i] >> 8) & 0xff]++; + _cpuhist[(p[i] >> 0) & 0xff]++; + _cpuReductionSum += ((p[i] >> 24) & 0x3) + ((p[i] >> 16) & 0x3) + + ((p[i] >> 8) & 0x3) + ((p[i] >> 0) & 0x3); + } +} + +void OCLPerfAtomicSpeed::setupHistogram() { + cl_int status = 0; + + _nThreads = 64 * 1024; +#if defined(_WIN32) && !defined(_WIN64) + _n4Vectors = 1024 * 1024; +#else + _n4Vectors = 2048 * 2048; +#endif + _n4Vectors *= _nCurrentInputScale; + _n4VectorsPerThread = _n4Vectors / _nThreads; + _inputNBytes = _n4Vectors * sizeof(cl_uint4); + + _input = (cl_uint *)malloc(_inputNBytes); + if (0 == _input) { + _dataSizeTooBig = true; + return; + } + + // random initialization of input + time_t ltime; + time(<ime); + cl_uint a = (cl_uint)ltime, b = (cl_uint)ltime; + cl_uint *p = (cl_uint *)_input; + + for (unsigned int i = 0; i < _inputNBytes / sizeof(cl_uint); i++) + p[i] = (b = (a * (b & 65535)) + (b >> 16)); +} + +// Print the results of the current test. +void OCLPerfAtomicSpeed::PrintResults(const AtomicType atomicType, + double totalTime) { + char buf[500]; + char sAtomicType[100]; + double inputInGB = (double)_inputNBytes * (double)(1e-09); + // each cl_uint in _inputNBytes contributes 4 items. + double totalHistogramDataInGB = (double)inputInGB * 4; + double perf = totalTime / _numLoops; + + switch (atomicType) { + case LocalHistogram: + SNPRINTF(sAtomicType, sizeof(sAtomicType), "Local histogram"); + break; + case GlobalHistogram: + SNPRINTF(sAtomicType, sizeof(sAtomicType), "Global histogram"); + break; + case Global4Histogram: + SNPRINTF(sAtomicType, sizeof(sAtomicType), "Global vec 4 histogram"); + break; + case LocalReductionNoAtomics: + SNPRINTF(sAtomicType, sizeof(sAtomicType), "Local reduction NO atomics"); + break; + case Local4ReductionNoAtomics: + SNPRINTF(sAtomicType, sizeof(sAtomicType), + "Local vec 4 reduction NO atomics"); + break; + case LocalReductionAtomics: + SNPRINTF(sAtomicType, sizeof(sAtomicType), + "Local reduction with atomics"); + break; + case Local4ReductionAtomics: + SNPRINTF(sAtomicType, sizeof(sAtomicType), + "Local vec 4 reduction with atomics"); + break; + case GlobalWGReduction: + SNPRINTF(sAtomicType, sizeof(sAtomicType), "Global work-group reduction"); + break; + case Global4WGReduction: + SNPRINTF(sAtomicType, sizeof(sAtomicType), + "Global vec 4 work-group reduction"); + break; + case GlobalAllToZeroReduction: + SNPRINTF(sAtomicType, sizeof(sAtomicType), + "Global all to zero reduction"); + break; + case Global4AllToZeroReduction: + SNPRINTF(sAtomicType, sizeof(sAtomicType), + "Global vec 4 all to zero reduction"); + break; + default: + CHECK_RESULT(true, "Atomic type not supported (PrintResults)"); + } + + SNPRINTF(buf, sizeof(buf), "%45s: Input [%.3f GB], Time [%.3f sec]: GB/s", + sAtomicType, totalHistogramDataInGB, perf); + _perfInfo = (float)(totalHistogramDataInGB / perf); + testDescString = buf; +} + +bool OCLPerfAtomicSpeed::IsReduction(const AtomicType atomicType) { + return ((atomicType >= LocalReductionNoAtomics) && + (atomicType <= GlobalAllToZeroReduction)); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed.h new file mode 100644 index 0000000000..af4dc888db --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed.h @@ -0,0 +1,119 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_AtomicSpeed_H_ +#define _OCL_AtomicSpeed_H_ + +#include +#include +#include +#include + +#include "OCLTestImp.h" + +#define DEFAULT_WG_SIZE 256 +#define NBINS 256 +#define BITS_PER_PIX 8 +#define NBANKS 16 + +// Define the atomic type to test. +enum AtomicType { + LocalHistogram = 0, + GlobalHistogram, + Global4Histogram, + LocalReductionNoAtomics, + Local4ReductionNoAtomics, + LocalReductionAtomics, + Local4ReductionAtomics, + GlobalWGReduction, + Global4WGReduction, + GlobalAllToZeroReduction, + Global4AllToZeroReduction, +}; + +typedef struct { + AtomicType atomicType; + int inputScale; +} testOCLPerfAtomicSpeedStruct; + +// Define the OCLPerfAtomicSpeed class. +class OCLPerfAtomicSpeed : public OCLTestImp { + public: + OCLPerfAtomicSpeed(); + virtual ~OCLPerfAtomicSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + cl_context context_; + cl_command_queue cmd_queue_; + std::vector _programs; + std::vector _kernels; + cl_device_id device; + + bool _atomicsSupported; + bool _dataSizeTooBig; + cl_uint _numLoops; + + // Histogram related stuff... + private: + cl_ulong _maxMemoryAllocationSize; + cl_uint _inputNBytes; + cl_uint _outputNBytes; + + cl_uint _nCurrentInputScale; + cl_uint _workgroupSize; + // cl_uint nLoops; + cl_uint _nThreads; + cl_uint _nThreadsPerGroup; + cl_uint _nGroups; + cl_uint _n4Vectors; + cl_uint _n4VectorsPerThread; + cl_uint _nBins; + cl_uint _nBytesLDSPerGrp; + + cl_uint* _input; + cl_uint* _output; + cl_mem _inputBuffer; + cl_mem _outputBuffer; + + cl_uint _cpuhist[NBINS]; + cl_uint _cpuReductionSum; + + void calculateHostBin(); + void setupHistogram(); + bool VerifyResults(const AtomicType atomicType); + void ResetGlobalOutput(); + + // Methods that does the actual NDRange. + void RunLocalHistogram(); + void RunLocalReduction(const AtomicType atomicType); + void RunGlobalHistogram(const AtomicType atomicType); + + void CreateKernels(const AtomicType atomicType); + bool IsReduction(const AtomicType atomicType); + void SetKernelArguments(const AtomicType atomicType); + void PrintResults(const AtomicType atomicType, double totalTime); +}; + +#endif // _OCL_AtomicSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed20.cpp b/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed20.cpp new file mode 100644 index 0000000000..f6b1297900 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed20.cpp @@ -0,0 +1,509 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfAtomicSpeed20.h" + +#include +#include +#include +#include +#include + +#include "CL/cl.h" +#include "OCLPerfAtomicSpeed20Kernels.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +// Define the test suite tests. +testOCLPerfAtomicSpeed20Struct testOCLPerfAtomicSpeed20List[] = { + {GlobalWGReduction, 1}, {GlobalWGReduction, 2}, + {GlobalWGReduction, 4}, {GlobalAllToZeroReduction, 1}, + {GlobalAllToZeroReduction, 2}, {GlobalAllToZeroReduction, 4}, + {Global4WGReduction, 1}, {Global4WGReduction, 2}, + {Global4WGReduction, 4}, {Global4AllToZeroReduction, 1}, + {Global4AllToZeroReduction, 2}, {Global4AllToZeroReduction, 4}, +}; + +/////////////////////////////////////////////////////////////////////////////// +// OCLPerfAtomicSpeed20 implementation. +/////////////////////////////////////////////////////////////////////////////// +OCLPerfAtomicSpeed20::OCLPerfAtomicSpeed20() { + _atomicsSupported = false; + _dataSizeTooBig = false; + _numSubTests = sizeof(testOCLPerfAtomicSpeed20List) / + sizeof(testOCLPerfAtomicSpeed20Struct); + _numLoops = 10; + _nCurrentInputScale = 1; + _maxMemoryAllocationSize = 0; + + _input = NULL; + _output = NULL; + _inputBuffer = NULL; + _outputBuffer = NULL; + + skip_ = false; + + _workgroupSize = 256; + _programs.clear(); + _kernels.clear(); +} + +OCLPerfAtomicSpeed20::~OCLPerfAtomicSpeed20() {} + +void OCLPerfAtomicSpeed20::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + error_ = CL_SUCCESS; + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = 0; + kernel_ = 0; + +#if defined(CL_VERSION_2_0) + cl_device_id device; + cl_int status = CL_SUCCESS; + + conversion = 1.0f; + _openTest = test; + _cpuReductionSum = 0; + _nCurrentInputScale = testOCLPerfAtomicSpeed20List[_openTest].inputScale; + AtomicType atomicType = testOCLPerfAtomicSpeed20List[_openTest].atomicType; + + // Setup stuff... + setupHistogram(); + calculateHostBin(); + + device = devices_[_deviceId]; + + cmd_queue_ = cmdQueues_[_deviceId]; + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + // Global memory size + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, + sizeof(cl_ulong), + &_maxMemoryAllocationSize, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, + "clGetDeviceInfo(CL_DEVICE_MAX_MEM_ALLOC_SIZE) failed"); + + // Check that the test size is not too big for the current GPU. + _dataSizeTooBig = false; + cl_ulong tenMB = 1024 * 10240; + if (_inputNBytes >= (_maxMemoryAllocationSize - tenMB)) { + _dataSizeTooBig = true; + return; + } + + char *p = strstr(charbuf, "cl_khr_global_int32_base_atomics"); + + _atomicsSupported = false; + if (p) _atomicsSupported = true; + + // Verify atomics are supported. + if (!_atomicsSupported) return; + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + // Create buffers... + _inputBuffer = + clCreateBuffer(context_, CL_MEM_READ_ONLY, _inputNBytes, 0, &status); + CHECK_RESULT(status, "clCreateBuffer failed. (inputBuffer)"); + + // Create the programs/kernels for the current test type. + CreateKernels(atomicType); + + _nThreadsPerGroup = _workgroupSize; + _nGroups = _nThreads / _nThreadsPerGroup; + _outputNBytes = _inputNBytes; + + _output = (cl_uint *)malloc(_outputNBytes); + if (0 == _output) { + _dataSizeTooBig = true; + return; + } + + // Create output Buffer + _outputBuffer = + clCreateBuffer(context_, CL_MEM_READ_WRITE, _outputNBytes, 0, &status); + CHECK_RESULT(status, "clCreateBuffer failed. (outputBuffer)"); +#else + skip_ = true; + testDescString = "OpenCL verion < 2.0. Test Skipped."; + return; +#endif +} + +// Create the programs/kernels for the current test type. +void OCLPerfAtomicSpeed20::CreateKernels(const AtomicType atomicType) { + char log[16384]; + cl_kernel kernel_; + cl_program program_; + char buildOptions[1000]; + cl_int status = CL_SUCCESS; + cl_device_id device = devices_[_deviceId]; + + SNPRINTF(buildOptions, sizeof(buildOptions), + "-cl-std=CL2.0 -D NBINS=%d -D BITS_PER_PIX=%d -D NBANKS=%d", NBINS, + BITS_PER_PIX, NBANKS); + + // Create the programs. + switch (atomicType) { + case GlobalWGReduction: + case Global4WGReduction: + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&global_atomics_sum_reduction_workgroup, + NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + _programs.push_back(program_); + break; + case GlobalAllToZeroReduction: + case Global4AllToZeroReduction: + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&global_atomics_sum_reduction_all_to_zero, + NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + _programs.push_back(program_); + break; + default: + CHECK_RESULT(true, "Atomic type not supported (clCreateProgram)"); + } + // Build the programs. + for (size_t i = 0; i < _programs.size(); i++) { + error_ = _wrapper->clBuildProgram(_programs[i], 1, &device, buildOptions, + NULL, NULL); + if (error_ != CL_SUCCESS) { + status = _wrapper->clGetProgramBuildInfo(_programs[i], device, + CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + } + + switch (atomicType) { + case GlobalWGReduction: + case Global4WGReduction: + kernel_ = _wrapper->clCreateKernel( + _programs[0], "global_atomics_sum_reduction_workgroup", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + _kernels.push_back(kernel_); + break; + case GlobalAllToZeroReduction: + case Global4AllToZeroReduction: + kernel_ = _wrapper->clCreateKernel( + _programs[0], "global_atomics_sum_reduction_all_to_zero", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + _kernels.push_back(kernel_); + break; + default: + CHECK_RESULT(true, "Atomic type not supported (clCreateKernel)"); + } +} + +// Sets the kernel arguments based on the current test type. +void OCLPerfAtomicSpeed20::SetKernelArguments(const AtomicType atomicType) { + int Arg = 0; + int localSize = 0; + int itemsPerThread = 1; + cl_int status = CL_SUCCESS; + + switch (atomicType) { + case GlobalWGReduction: + case Global4WGReduction: + case GlobalAllToZeroReduction: + case Global4AllToZeroReduction: + // Set arguments for the global atomics histogram kernel + if ((Global4WGReduction == atomicType) || + (Global4AllToZeroReduction == atomicType)) + itemsPerThread = 4; + + status = _wrapper->clSetKernelArg( + _kernels[0], Arg++, sizeof(itemsPerThread), (void *)&itemsPerThread); + CHECK_RESULT(status, "clSetKernelArg failed. (itemsPerThread)"); + + status = _wrapper->clSetKernelArg(_kernels[0], Arg++, sizeof(cl_mem), + (void *)&_inputBuffer); + CHECK_RESULT(status, "clSetKernelArg failed. (inputBuffer)"); + + status |= _wrapper->clSetKernelArg(_kernels[0], Arg++, sizeof(cl_mem), + (void *)&_outputBuffer); + CHECK_RESULT(status, "clSetKernelArg failed. (outputBuffer)"); + break; + default: + CHECK_RESULT(true, "Atomic type not supported (clSetKernelArg)"); + } +} + +// Since we write multiple times to the output in global atomics, need to +// reset the content every time. +void OCLPerfAtomicSpeed20::ResetGlobalOutput() { + cl_int status; + + memset(_output, 0, _outputNBytes); + + status = + _wrapper->clEnqueueWriteBuffer(cmd_queue_, _outputBuffer, CL_TRUE, 0, + _outputNBytes, _output, 0, NULL, NULL); + CHECK_RESULT(status, "clEnqueueWriteBuffer failed."); + + status = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(status, "clFlush failed."); +} + +// Run the global histogram kernel. +void OCLPerfAtomicSpeed20::RunGlobalHistogram(AtomicType atomicType) { + cl_uint status; + size_t globalThreads[3] = {1}; + size_t localThreads[3] = {1}; + + globalThreads[0] = _inputNBytes / sizeof(cl_uint); + localThreads[0] = _nThreadsPerGroup; + + if ((Global4WGReduction == atomicType) || + (Global4AllToZeroReduction == atomicType)) + globalThreads[0] /= 4; + + status = _wrapper->clEnqueueNDRangeKernel(cmd_queue_, _kernels[0], 1, NULL, + globalThreads, localThreads, 0, + NULL, NULL); + CHECK_RESULT(status, "clEnqueueNDRangeKernel failed."); + + status = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(status, "clFlush failed."); +} + +// Run the AtomicSpeed logic. +void OCLPerfAtomicSpeed20::run() { + if (skip_) { + return; + } + +#if defined(CL_VERSION_2_0) + int Arg = 0; + cl_uint status; + AtomicType atomicType = testOCLPerfAtomicSpeed20List[_openTest].atomicType; + + // Verify atomics are supported. + if ((!_atomicsSupported) || (_dataSizeTooBig)) return; + + // Write data to the GPU + status = _wrapper->clEnqueueWriteBuffer(cmd_queue_, _inputBuffer, CL_FALSE, 0, + _inputNBytes, _input, 0, NULL, NULL); + CHECK_RESULT(status, "clEnqueueWriteBuffer failed. (inputBuffer)"); + + status = _wrapper->clFlush(cmd_queue_); + CHECK_RESULT(status, "clFlush failed."); + + // Set the current arguments based on the test type. + SetKernelArguments(atomicType); + + // Run the kernels. + CPerfCounter timer; + double totalTime = 0.0f; + + for (unsigned int k = 0; k < _numLoops + 1; k++) { + // Since we run multiple times using global atomics the output + // would get accumulated therefore first clean it. + ResetGlobalOutput(); + + timer.Reset(); + timer.Start(); + switch (atomicType) { + case GlobalWGReduction: + case Global4WGReduction: + case GlobalAllToZeroReduction: + case Global4AllToZeroReduction: + RunGlobalHistogram(atomicType); + break; + default: + CHECK_RESULT(true, "Atomic type not supported"); + } + timer.Stop(); + // Don't count the warm-up + if (0 != k) totalTime += timer.GetElapsedTime(); + } + + status = _wrapper->clEnqueueReadBuffer(cmd_queue_, _outputBuffer, CL_FALSE, 0, + _outputNBytes, _output, 0, NULL, NULL); + CHECK_RESULT(status, "clEnqueueReadBuffer failed."); + status = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(status, "clFlush failed."); + + // Print the results. + PrintResults(atomicType, totalTime); + + // Check the results for the current test. + _errorFlag = !(VerifyResults(atomicType)); +#endif +} + +// Compare the results and see if they match +bool OCLPerfAtomicSpeed20::VerifyResults(const AtomicType atomicType) { + cl_uint i = 0; + bool flag = true; + cl_uint calculatedValue = 0; + cl_uint reductionElementCount = 0; + switch (atomicType) { + case GlobalWGReduction: + case Global4WGReduction: + reductionElementCount = + _inputNBytes / sizeof(cl_uint) / _nThreadsPerGroup; + for (i = 0; i < reductionElementCount; i++) { + calculatedValue += _output[i]; + } + flag = (calculatedValue == _cpuReductionSum); + break; + case GlobalAllToZeroReduction: + case Global4AllToZeroReduction: + flag = (_output[0] == _cpuReductionSum); + break; + default: + CHECK_RESULT_NO_RETURN(true, "Atomic type not supported (VerifyResults)"); + return false; + } + if (!flag) printf("WRONG VALUES!!!!!"); + return flag; +} + +unsigned int OCLPerfAtomicSpeed20::close() { + size_t i = 0; + for (; i < _kernels.size(); i++) { + error_ = _wrapper->clReleaseKernel(_kernels[i]); + } + for (; i < _programs.size(); i++) { + error_ = _wrapper->clReleaseProgram(_programs[i]); + } + + if (_inputBuffer) { + error_ = clReleaseMemObject(_inputBuffer); + CHECK_RESULT_NO_RETURN(error_, "clReleaseMemObject failed.(inputBuffer )"); + } + if (_outputBuffer) { + error_ = clReleaseMemObject(_outputBuffer); + CHECK_RESULT_NO_RETURN(error_, "clReleaseMemObject failed.(outputBuffer)"); + } + + // Free host memory. + free(_input); + free(_output); + + // Reset everything. + _kernels.clear(); + _programs.clear(); + + _inputBuffer = NULL; + _outputBuffer = NULL; + + _input = NULL; + _output = NULL; + + return OCLTestImp::close(); +} + +/* Helper functions */ +void OCLPerfAtomicSpeed20::calculateHostBin() { + // compute CPU histogram + cl_int *p = (cl_int *)_input; + memset(_cpuhist, 0, NBINS * sizeof(cl_uint)); + _cpuReductionSum = 0; + + for (unsigned int i = 0; i < _inputNBytes / sizeof(cl_uint); i++) { + _cpuhist[(p[i] >> 24) & 0xff]++; + _cpuhist[(p[i] >> 16) & 0xff]++; + _cpuhist[(p[i] >> 8) & 0xff]++; + _cpuhist[(p[i] >> 0) & 0xff]++; + _cpuReductionSum += ((p[i] >> 24) & 0x3) + ((p[i] >> 16) & 0x3) + + ((p[i] >> 8) & 0x3) + ((p[i] >> 0) & 0x3); + } +} + +void OCLPerfAtomicSpeed20::setupHistogram() { + cl_int status = 0; + + _nThreads = 64 * 1024; + _n4Vectors = 2048 * 2048; + _n4Vectors *= _nCurrentInputScale; + _n4VectorsPerThread = _n4Vectors / _nThreads; + _inputNBytes = _n4Vectors * sizeof(cl_uint4); + + _input = (cl_uint *)malloc(_inputNBytes); + if (0 == _input) { + _dataSizeTooBig = true; + return; + } + + // random initialization of input + time_t ltime; + time(<ime); + cl_uint a = (cl_uint)ltime, b = (cl_uint)ltime; + cl_uint *p = (cl_uint *)_input; + + for (unsigned int i = 0; i < _inputNBytes / sizeof(cl_uint); i++) + p[i] = (b = (a * (b & 65535)) + (b >> 16)); +} + +// Print the results of the current test. +void OCLPerfAtomicSpeed20::PrintResults(const AtomicType atomicType, + double totalTime) { + char buf[500]; + char sAtomicType[100]; + double inputInGB = (double)_inputNBytes * (double)(1e-09); + // each cl_uint in _inputNBytes contributes 4 items. + double totalHistogramDataInGB = (double)inputInGB * 4; + double perf = totalTime / _numLoops; + + switch (atomicType) { + case GlobalWGReduction: + SNPRINTF(sAtomicType, sizeof(sAtomicType), "Global work-group reduction"); + break; + case Global4WGReduction: + SNPRINTF(sAtomicType, sizeof(sAtomicType), + "Global vec 4 work-group reduction"); + break; + case GlobalAllToZeroReduction: + SNPRINTF(sAtomicType, sizeof(sAtomicType), + "Global all to zero reduction"); + break; + case Global4AllToZeroReduction: + SNPRINTF(sAtomicType, sizeof(sAtomicType), + "Global vec 4 all to zero reduction"); + break; + default: + CHECK_RESULT(true, "Atomic type not supported (PrintResults)"); + } + + SNPRINTF(buf, sizeof(buf), "%45s: Input [%.3f GB], Time [%.3f sec]: GB/s", + sAtomicType, totalHistogramDataInGB, perf); + _perfInfo = (float)(totalHistogramDataInGB / perf); + testDescString = buf; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed20.h b/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed20.h new file mode 100644 index 0000000000..101f5b2c82 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed20.h @@ -0,0 +1,102 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_AtomicSpeed20_H_ +#define _OCL_AtomicSpeed20_H_ + +#include +#include +#include +#include + +#include "OCLTestImp.h" + +#define DEFAULT_WG_SIZE 256 +#define NBINS 256 +#define BITS_PER_PIX 8 +#define NBANKS 16 + +#include "OCLPerfAtomicSpeed.h" + +typedef struct { + AtomicType atomicType; + int inputScale; +} testOCLPerfAtomicSpeed20Struct; + +// Define the OCLPerfAtomicSpeed20 class. +class OCLPerfAtomicSpeed20 : public OCLTestImp { + public: + OCLPerfAtomicSpeed20(); + virtual ~OCLPerfAtomicSpeed20(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + cl_command_queue cmd_queue_; + std::vector _programs; + std::vector _kernels; + + bool _atomicsSupported; + bool _dataSizeTooBig; + cl_uint _numLoops; + + // Histogram related stuff... + private: + cl_ulong _maxMemoryAllocationSize; + cl_uint _inputNBytes; + cl_uint _outputNBytes; + + cl_uint _nCurrentInputScale; + cl_uint _workgroupSize; + // cl_uint nLoops; + cl_uint _nThreads; + cl_uint _nThreadsPerGroup; + cl_uint _nGroups; + cl_uint _n4Vectors; + cl_uint _n4VectorsPerThread; + cl_uint _nBins; + cl_uint _nBytesLDSPerGrp; + + cl_uint* _input; + cl_uint* _output; + cl_mem _inputBuffer; + cl_mem _outputBuffer; + bool skip_; + + cl_uint _cpuhist[NBINS]; + cl_uint _cpuReductionSum; + + void calculateHostBin(); + void setupHistogram(); + bool VerifyResults(const AtomicType atomicType); + void ResetGlobalOutput(); + + // Methods that does the actual NDRange. + void RunGlobalHistogram(const AtomicType atomicType); + + void CreateKernels(const AtomicType atomicType); + void SetKernelArguments(const AtomicType atomicType); + void PrintResults(const AtomicType atomicType, double totalTime); +}; + +#endif // _OCL_AtomicSpeed20_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed20Kernels.h b/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed20Kernels.h new file mode 100644 index 0000000000..b4464cf2f0 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeed20Kernels.h @@ -0,0 +1,73 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +static const char *global_atomics_sum_reduction_all_to_zero = + "#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable\n" + " __kernel void global_atomics_sum_reduction_all_to_zero(uint " + "ItemsPerThread, __global uint *Input, __global atomic_int *Output )\n" + "{\n" + " uint sum = 0;\n" + " const uint msk = (uint)3;\n" + " const uint shft = (uint)8;\n" + " \n" + " uint tid = get_global_id(0);\n" + " uint Stride = get_global_size(0);\n" + " for( int i = 0; i < ItemsPerThread; i++)\n" + " {\n" + " uint data = Input[tid];\n" + " sum += data & msk;\n" + " data = data >> shft;" + " sum += data & msk;\n" + " data = data >> shft;" + " sum += data & msk;\n" + " data = data >> shft;" + " sum += data & msk;\n" + " tid += Stride;\n" + " }\n" + " atomic_fetch_add_explicit( &(Output[0]), sum, memory_order_relaxed, " + "memory_scope_device);\n" + "}\n"; + +static const char *global_atomics_sum_reduction_workgroup = + "#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable\n" + " __kernel void global_atomics_sum_reduction_workgroup(uint " + "ItemsPerThread, __global uint *Input, __global atomic_int *Output )\n" + "{\n" + " uint sum = 0;\n" + " const uint msk = (uint)3;\n" + " const uint shft = (uint)8;\n" + " \n" + " uint tid = get_global_id(0);\n" + " uint Stride = get_global_size(0);\n" + " for( int i = 0; i < ItemsPerThread; i++)\n" + " {\n" + " uint data = Input[tid];\n" + " sum += data & msk;\n" + " data = data >> shft;" + " sum += data & msk;\n" + " data = data >> shft;" + " sum += data & msk;\n" + " data = data >> shft;" + " sum += data & msk;\n" + " tid += Stride;\n" + " }\n" + " atomic_fetch_add_explicit( &(Output[get_group_id(0)]), sum, " + "memory_order_relaxed, memory_scope_device);\n" + "}\n"; diff --git a/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeedKernels.h b/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeedKernels.h new file mode 100644 index 0000000000..95fa95c0e4 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfAtomicSpeedKernels.h @@ -0,0 +1,402 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +static const char *local_atomics_histogram = + "#pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable\n" + "#define MIN(a,b) ((a) < (b)) ? (a) : (b) \n" + "#define MAX(a,b) ((a) > (b)) ? (a) : (b) \n" + "__kernel __attribute__((reqd_work_group_size(256,1,1)))\n" + "void local_atomics_histogram(__global uint4 *Image,\n" + "__global uint *Histogram,\n" + "uint n4VectorsPerThread)\n" + "{\n" + " __local __attribute__((aligned(16))) uint subhists[NBANKS * NBINS];\n" + "\n" + " uint tid = get_global_id(0);\n" + " uint ltid = get_local_id(0);\n" + " uint Stride = get_global_size(0);\n" + "\n" + " uint i, idx;\n" + " uint4 temp, temp2;\n" + " const uint shft = (uint) BITS_PER_PIX;\n" + " const uint msk = (uint) (NBINS-1);\n" + " uint offset = (uint) ltid % (uint) (NBANKS);\n" + "\n" + " uint lmem_items = NBANKS * NBINS;\n" + " uint lmem_items_per_thread;\n" + " uint lmem_max_threads;\n" + "\n" + " // parallel LDS clear\n" + " // first, calculate threads per item, at least 1:\n" + " lmem_max_threads = MIN( 1, get_local_size(0) / lmem_items );\n" + " // but no more than we have items:\n" + " lmem_max_threads = MAX( 1, lmem_max_threads / lmem_items );\n" + " // calculate threads total:\n" + " lmem_max_threads = lmem_items / lmem_max_threads;\n" + " // but no more than LDS banks:\n" + " lmem_max_threads = MIN( get_local_size(0), lmem_max_threads );\n" + "\n" + " lmem_items_per_thread = lmem_items / lmem_max_threads;\n" + "\n" + " // now, clear LDS\n" + " __local uint4 *p = (__local uint4 *) subhists;\n" + "\n" + " if( ltid < lmem_max_threads )\n" + " {\n" + " for(i=0, idx=ltid; i> shft;\n" + " temp2 = (temp & msk) * (uint4) NBANKS + offset;\n" + "\n" + " (void) atom_inc( subhists + temp2.x );\n" + " (void) atom_inc( subhists + temp2.y );\n" + " (void) atom_inc( subhists + temp2.z );\n" + " (void) atom_inc( subhists + temp2.w );\n" + "\n" + " temp = temp >> shft;\n" + " temp2 = (temp & msk) * (uint4) NBANKS + offset;\n" + "\n" + " (void) atom_inc( subhists + temp2.x );\n" + " (void) atom_inc( subhists + temp2.y );\n" + " (void) atom_inc( subhists + temp2.z );\n" + " (void) atom_inc( subhists + temp2.w );\n" + "\n" + " temp = temp >> shft;\n" + " temp2 = (temp & msk) * (uint4) NBANKS + offset;\n" + "\n" + " (void) atom_inc( subhists + temp2.x );\n" + " (void) atom_inc( subhists + temp2.y );\n" + " (void) atom_inc( subhists + temp2.z );\n" + " (void) atom_inc( subhists + temp2.w );\n" + " }\n" + "\n" + " barrier( CLK_LOCAL_MEM_FENCE );\n" + "\n" + " // reduce __local banks to single histogram per work-group\n" + "\n" + " if( ltid < NBINS )\n" + " {\n" + " uint bin = 0;\n" + " for( i=0; i> shft;\n" + " atom_inc( &(Histogram[ (temp & msk) ]) );\n" + " temp = temp >> shft;\n" + " atom_inc( &(Histogram[ (temp & msk) ]) );\n" + " temp = temp >> shft;\n" + " atom_inc( &(Histogram[ (temp & msk) ]) );\n" + " tid += Stride;" + " }\n" + "}\n"; + +static const char *global_vec4_atomics_histogram = + "#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable\n" + "__kernel __attribute__((reqd_work_group_size(256,1,1)))\n" + "void global_atomics_histogram(uint ItemsPerThread,\n" + "__global uint4 *Input,\n" + "__global uint *Histogram)\n" + "{\n" + " uint tid = get_global_id(0);\n" + " const uint shft = (uint) BITS_PER_PIX;\n" + " const uint msk = (uint) (NBINS-1);\n" + " uint Stride = get_global_size(0);\n" + " for( int i = 0; i < ItemsPerThread; i++)\n" + " {\n" + " uint4 temp = Input[tid];\n" + " atom_inc( &(Histogram[ (temp.x & msk) ]) );\n" + " atom_inc( &(Histogram[ (temp.y & msk) ]) );\n" + " atom_inc( &(Histogram[ (temp.z & msk) ]) );\n" + " atom_inc( &(Histogram[ (temp.w & msk) ]) );\n" + " temp = temp >> shft;\n" + " atom_inc( &(Histogram[ (temp.x & msk) ]) );\n" + " atom_inc( &(Histogram[ (temp.y & msk) ]) );\n" + " atom_inc( &(Histogram[ (temp.z & msk) ]) );\n" + " atom_inc( &(Histogram[ (temp.w & msk) ]) );\n" + " temp = temp >> shft;\n" + " atom_inc( &(Histogram[ (temp.x & msk) ]) );\n" + " atom_inc( &(Histogram[ (temp.y & msk) ]) );\n" + " atom_inc( &(Histogram[ (temp.z & msk) ]) );\n" + " atom_inc( &(Histogram[ (temp.w & msk) ]) );\n" + " temp = temp >> shft;\n" + " atom_inc( &(Histogram[ (temp.x & msk) ]) );\n" + " atom_inc( &(Histogram[ (temp.y & msk) ]) );\n" + " atom_inc( &(Histogram[ (temp.z & msk) ]) );\n" + " atom_inc( &(Histogram[ (temp.w & msk) ]) );\n" + " tid += Stride;" + " }\n" + "}\n"; + +static const char *global_atomics_sum_reduction_all_to_zero = + "#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable\n" + " __kernel void global_atomics_sum_reduction_all_to_zero(uint " + "ItemsPerThread, __global uint *Input, __global int *Output )\n" + "{\n" + " uint sum = 0;\n" + " const uint msk = (uint)3;\n" + " const uint shft = (uint)8;\n" + " \n" + " uint tid = get_global_id(0);\n" + " uint Stride = get_global_size(0);\n" + " for( int i = 0; i < ItemsPerThread; i++)\n" + " {\n" + " uint data = Input[tid];\n" + " sum += data & msk;\n" + " data = data >> shft;" + " sum += data & msk;\n" + " data = data >> shft;" + " sum += data & msk;\n" + " data = data >> shft;" + " sum += data & msk;\n" + " tid += Stride;\n" + " }\n" + " atom_add( &(Output[0]), sum);\n" + "}\n"; + +static const char *global_atomics_sum_reduction_workgroup = + "#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable\n" + " __kernel void global_atomics_sum_reduction_workgroup(uint " + "ItemsPerThread, __global uint *Input, __global int *Output )\n" + "{\n" + " uint sum = 0;\n" + " const uint msk = (uint)3;\n" + " const uint shft = (uint)8;\n" + " \n" + " uint tid = get_global_id(0);\n" + " uint Stride = get_global_size(0);\n" + " for( int i = 0; i < ItemsPerThread; i++)\n" + " {\n" + " uint data = Input[tid];\n" + " sum += data & msk;\n" + " data = data >> shft;" + " sum += data & msk;\n" + " data = data >> shft;" + " sum += data & msk;\n" + " data = data >> shft;" + " sum += data & msk;\n" + " tid += Stride;\n" + " }\n" + " atom_add( &(Output[get_group_id(0)]), sum);\n" + "}\n"; + +static const char *local_reduction = + "__kernel void local_reduction(__global uint* input, __global uint* " + "output, __local uint* sdata)\n" + "{\n" + " // load shared mem\n" + " const uint msk = (uint)3;\n" + " const uint shft = (uint)8;\n" + " unsigned int tid = get_local_id(0);\n" + "\n" + " unsigned int localSize = get_local_size(0);\n" + " unsigned int stride = get_global_id(0) * 2;\n" + " unsigned int data1 = input[stride];\n" + " unsigned int data2 = input[stride + 1];\n" + " unsigned int sum = 0;\n" + " for( int i = 0; i < 4; i++)\n" + " {\n" + " sum += (data1 & msk) + (data2 & msk);\n" + " data1 = data1 >> shft;\n" + " data2 = data2 >> shft;\n" + " }\n" + " sdata[tid] = sum;" + "\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + " // do reduction in shared mem\n" + " for(unsigned int s = localSize >> 1; s > 0; s >>= 1)\n" + " {\n" + " if(tid < s) \n" + " {\n" + " sdata[tid] += sdata[tid + s];\n" + " }\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + " }\n" + "\n" + " // write result for this block to global mem\n" + " if(tid == 0) output[get_group_id(0)] = sdata[0];\n" + "}\n"; + +static const char *local_vec4_reduction = + "__kernel void local_reduction(__global uint4* input, __global uint4* " + "output, __local uint4* sdata)\n" + "{\n" + " // load shared mem\n" + " const uint msk = (uint)3;\n" + " const uint shft = (uint)8;\n" + " unsigned int tid = get_local_id(0);\n" + "\n" + " unsigned int localSize = get_local_size(0);\n" + " unsigned int stride = get_global_id(0) * 2;\n" + " uint4 data1 = input[stride];\n" + " uint4 data2 = input[stride + 1];\n" + " uint4 sum = 0;\n" + " for( int i = 0; i < 4; i++)\n" + " {\n" + " sum += (data1 & msk) + (data2 & msk);\n" + " data1 = data1 >> shft;\n" + " data2 = data2 >> shft;\n" + " }\n" + " sdata[tid] = sum;" + "\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + " // do reduction in shared mem\n" + " for(unsigned int s = localSize >> 1; s > 0; s >>= 1)\n" + " {\n" + " if(tid < s) \n" + " {\n" + " sdata[tid] += sdata[tid + s];\n" + " }\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + " }\n" + "\n" + " // write result for this block to global mem\n" + " if(tid == 0) output[get_group_id(0)] = sdata[0];\n" + "}\n"; + +static const char *local_atomics_reduction = + "#pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable\n" + "__kernel void local_reduction(__global uint* input, __global uint* " + "output, __local uint* sdata)\n" + "{\n" + " // load shared mem\n" + " const uint msk = (uint)3;\n" + " const uint shft = (uint)8;\n" + " unsigned int tid = get_local_id(0);\n" + "\n" + " unsigned int localSize = get_local_size(0);\n" + " unsigned int stride = get_global_id(0) * 2;\n" + " unsigned int data1 = input[stride];\n" + " unsigned int data2 = input[stride + 1];\n" + " unsigned int sum = 0;\n" + " for( int i = 0; i < 4; i++)\n" + " {\n" + " sum += (data1 & msk) + (data2 & msk);\n" + " data1 = data1 >> shft;\n" + " data2 = data2 >> shft;\n" + " }\n" + " sdata[tid] = sum;" + "\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + " // do reduction in shared mem\n" + " for(unsigned int s = localSize >> 1; s > 0; s >>= 1)\n" + " {\n" + " if(tid < s) \n" + " {\n" + " atom_add( &(sdata[tid]), sdata[tid + s]);\n" + " }\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + " }\n" + "\n" + " // write result for this block to global mem\n" + " if(tid == 0) output[get_group_id(0)] = sdata[0];\n" + "}\n"; + +static const char *local_vec4_atomics_reduction = + "#pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable\n" + "__kernel void local_reduction(__global uint4* input, __global uint4* " + "output, __local uint4* sdata)\n" + "{\n" + " // load shared mem\n" + " const uint msk = (uint)3;\n" + " const uint shft = (uint)8;\n" + " unsigned int tid = get_local_id(0);\n" + "\n" + " unsigned int localSize = get_local_size(0);\n" + " unsigned int stride = get_global_id(0) * 2;\n" + " uint4 data1 = input[stride];\n" + " uint4 data2 = input[stride + 1];\n" + " uint4 sum = 0;\n" + " for( int i = 0; i < 4; i++)\n" + " {\n" + " sum += (data1 & msk) + (data2 & msk);\n" + " data1 = data1 >> shft;\n" + " data2 = data2 >> shft;\n" + " }\n" + " sdata[tid] = sum;" + "\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + " // do reduction in shared mem\n" + " for(unsigned int s = localSize >> 1; s > 0; s >>= 1)\n" + " {\n" + " if(tid < s) \n" + " {\n" + " atom_add( &(sdata[tid]).x, sdata[tid + s].x);\n" + " atom_add( &(sdata[tid]).y, sdata[tid + s].y);\n" + " atom_add( &(sdata[tid]).z, sdata[tid + s].z);\n" + " atom_add( &(sdata[tid]).w, sdata[tid + s].w);\n" + " }\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + " }\n" + "\n" + " // write result for this block to global mem\n" + " if(tid == 0) output[get_group_id(0)] = sdata[0];\n" + "}\n"; diff --git a/opencl/tests/ocltst/module/perf/OCLPerfBufferCopyOverhead.cpp b/opencl/tests/ocltst/module/perf/OCLPerfBufferCopyOverhead.cpp new file mode 100644 index 0000000000..41fac39a49 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfBufferCopyOverhead.cpp @@ -0,0 +1,254 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfBufferCopyOverhead.h" + +#include +#include +#include + +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +typedef struct { + unsigned int iterations; + int flushEvery; +} testStruct; + +static testStruct testList[] = { + {1, -1}, {1, -1}, {10, 1}, {10, -1}, {100, 1}, + {100, 10}, {100, -1}, {1000, 1}, {1000, 10}, {1000, 100}, + {1000, -1}, {10000, 1}, {10000, 10}, {10000, 100}, {10000, 1000}, + {10000, -1}, {100000, 1}, {100000, 10}, {100000, 100}, {100000, 1000}, + {100000, 10000}, {100000, -1}, +}; + +OCLPerfBufferCopyOverhead::OCLPerfBufferCopyOverhead() { + _numSubTests = 2 * 2 * sizeof(testList) / sizeof(testStruct); +} + +OCLPerfBufferCopyOverhead::~OCLPerfBufferCopyOverhead() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfBufferCopyOverhead::open(unsigned int test, char *units, + double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test % (sizeof(testList) / sizeof(testStruct)); + + context_ = 0; + cmd_queue_ = 0; + srcBuffer_ = 0; + dstBuffer_ = 0; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + delete platforms; + } + + bufSize_ = 4; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_READ_ONLY; + sleep = ((test / (sizeof(testList) / sizeof(testStruct))) % 2) > 0; + if (test >= ((sizeof(testList) / sizeof(testStruct)) * 2)) { + srcHost = true; + flags |= CL_MEM_ALLOC_HOST_PTR; + } else { + srcHost = false; + } + srcBuffer_ = + _wrapper->clCreateBuffer(context_, flags, bufSize_, NULL, &error_); + CHECK_RESULT(srcBuffer_ == 0, "clCreateBuffer(srcBuffer) failed"); + + flags = CL_MEM_WRITE_ONLY; + if (!srcHost) { + flags |= CL_MEM_ALLOC_HOST_PTR; + } + dstBuffer_ = + _wrapper->clCreateBuffer(context_, flags, bufSize_, NULL, &error_); + CHECK_RESULT(dstBuffer_ == 0, "clCreateBuffer(dstBuffer) failed"); +} + +void OCLPerfBufferCopyOverhead::run(void) { + CPerfCounter timer; + cl_event event; + cl_int eventStatus; + unsigned int iter = testList[_openTest].iterations; + + // Warm up + error_ = _wrapper->clEnqueueCopyBuffer(cmd_queue_, srcBuffer_, dstBuffer_, 0, + 0, bufSize_, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueCopyBuffer failed"); + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < iter; i++) { + error_ = _wrapper->clEnqueueCopyBuffer(cmd_queue_, srcBuffer_, dstBuffer_, + 0, 0, bufSize_, 0, NULL, &event); + + CHECK_RESULT(error_, "clEnqueueCopyBuffer failed"); + if ((testList[_openTest].flushEvery > 0) && + (((i + 1) % testList[_openTest].flushEvery) == 0)) { + if (sleep) { + _wrapper->clFinish(cmd_queue_); + } else { + _wrapper->clFlush(cmd_queue_); + error_ = + _wrapper->clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(cl_int), &eventStatus, NULL); + while (eventStatus > 0) { + error_ = + _wrapper->clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(cl_int), &eventStatus, NULL); + } + } + } + if (i != (iter - 1)) { + _wrapper->clReleaseEvent(event); + } + } + if (sleep) { + _wrapper->clFinish(cmd_queue_); + } else { + _wrapper->clFlush(cmd_queue_); + error_ = _wrapper->clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(cl_int), &eventStatus, NULL); + while (eventStatus > 0) { + error_ = + _wrapper->clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(cl_int), &eventStatus, NULL); + } + } + _wrapper->clReleaseEvent(event); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Buffer copy time in us + double perf = sec * 1000. * 1000. / iter; + + const char *strSrc = NULL; + const char *strDst = NULL; + const char *strWait = NULL; + if (srcHost) { + strSrc = "host"; + strDst = "dev"; + } else { + strSrc = "dev"; + strDst = "host"; + } + if (sleep) { + strWait = "sleep"; + } else { + strWait = "spin"; + } + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " %5s, s:%4s d:%4s i:%6d (us) ", strWait, strSrc, + strDst, iter); + testDescString = buf; +} + +unsigned int OCLPerfBufferCopyOverhead::close(void) { + if (srcBuffer_) { + error_ = _wrapper->clReleaseMemObject(srcBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(srcBuffer_) failed"); + } + if (dstBuffer_) { + error_ = _wrapper->clReleaseMemObject(dstBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(dstBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfBufferCopyOverhead.h b/opencl/tests/ocltst/module/perf/OCLPerfBufferCopyOverhead.h new file mode 100644 index 0000000000..faa12697b7 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfBufferCopyOverhead.h @@ -0,0 +1,50 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_BufferCopyOverhead_H_ +#define _OCL_BufferCopyOverhead_H_ + +#include "OCLTestImp.h" + +class OCLPerfBufferCopyOverhead : public OCLTestImp { + public: + OCLPerfBufferCopyOverhead(); + virtual ~OCLPerfBufferCopyOverhead(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 1000; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem srcBuffer_; + cl_mem dstBuffer_; + cl_int error_; + + unsigned int bufSize_; + bool sleep; + bool srcHost; +}; + +#endif // _OCL_BufferCopyOverhead_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfBufferCopySpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfBufferCopySpeed.cpp new file mode 100644 index 0000000000..64aff13370 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfBufferCopySpeed.cpp @@ -0,0 +1,439 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfBufferCopySpeed.h" + +#include +#include +#include + +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 8 +// 4KB, 8KB, 64KB, 256KB, 1 MB, 4MB, 16 MB, 16MB+10 +static const unsigned int Sizes[NUM_SIZES] = { + 4096, 8192, 65536, 262144, 1048576, 4194304, 16777216, 16777216 + 10}; + +static const unsigned int Iterations[2] = {1, OCLPerfBufferCopySpeed::NUM_ITER}; + +#define BUF_TYPES 4 +// 16 ways to combine 4 different buffer types +#define NUM_SUBTESTS (BUF_TYPES * BUF_TYPES) + +OCLPerfBufferCopySpeed::OCLPerfBufferCopySpeed() { + _numSubTests = NUM_SIZES * NUM_SUBTESTS * 2; +} + +OCLPerfBufferCopySpeed::~OCLPerfBufferCopySpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfBufferCopySpeed::setData(void *ptr, unsigned int size, + unsigned int value) { + unsigned int *ptr2 = (unsigned int *)ptr; + value = 0; + for (unsigned int i = 0; i < size >> 2; i++) { + ptr2[i] = value; + value++; + } +} + +void OCLPerfBufferCopySpeed::checkData(void *ptr, unsigned int size, + unsigned int value) { + unsigned int *ptr2 = (unsigned int *)ptr; + value = 0; + for (unsigned int i = 0; i < size >> 2; i++) { + if (ptr2[i] != value) { + printf("Data validation failed at %d! Got 0x%08x 0x%08x 0x%08x 0x%08x\n", + i, ptr2[i], ptr2[i + 1], ptr2[i + 2], ptr2[i + 3]); + printf("Expected 0x%08x 0x%08x 0x%08x 0x%08x\n", value, value, value, + value); + CHECK_RESULT(true, "Data validation failed!"); + break; + } + value++; + } +} + +void OCLPerfBufferCopySpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + srcBuffer_ = 0; + dstBuffer_ = 0; + persistent[0] = false; + persistent[1] = false; + allocHostPtr[0] = false; + allocHostPtr[1] = false; + useHostPtr[0] = false; + useHostPtr[1] = false; + memptr[0] = NULL; + memptr[1] = NULL; + alignedmemptr[0] = NULL; + alignedmemptr[1] = NULL; + isAMD = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + + char getVersion[128]; + error_ = _wrapper->clGetPlatformInfo(platform, CL_PLATFORM_VERSION, + sizeof(getVersion), getVersion, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + platformVersion[0] = getVersion[7]; + platformVersion[1] = getVersion[8]; + platformVersion[2] = getVersion[9]; + platformVersion[3] = '\0'; + bufSize_ = Sizes[_openTest % NUM_SIZES]; + unsigned int srcTest = (_openTest / NUM_SIZES) % BUF_TYPES; + unsigned int dstTest = (_openTest / (NUM_SIZES * BUF_TYPES)) % BUF_TYPES; + if (srcTest == 3) { + useHostPtr[0] = true; + } else if ((srcTest == 2) && isAMD) { + persistent[0] = true; + } else if (srcTest == 1) { + allocHostPtr[0] = true; + } + if ((dstTest == 1) && isAMD) { + persistent[1] = true; + } else if (dstTest == 2) { + allocHostPtr[1] = true; + } else if (dstTest == 3) { + useHostPtr[1] = true; + } + + numIter = Iterations[_openTest / (NUM_SIZES * NUM_SUBTESTS)]; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_READ_ONLY; + if (persistent[0]) { + flags |= CL_MEM_USE_PERSISTENT_MEM_AMD; + } else if (allocHostPtr[0]) { + flags |= CL_MEM_ALLOC_HOST_PTR; + } else if (useHostPtr[0]) { + flags |= CL_MEM_USE_HOST_PTR; + memptr[0] = malloc(bufSize_ + 4096); + alignedmemptr[0] = (void *)(((size_t)memptr[0] + 4095) & ~4095); + } + srcBuffer_ = _wrapper->clCreateBuffer(context_, flags, bufSize_, + alignedmemptr[0], &error_); + CHECK_RESULT(srcBuffer_ == 0, "clCreateBuffer(srcBuffer) failed"); + void *mem; + mem = _wrapper->clEnqueueMapBuffer(cmd_queue_, srcBuffer_, CL_TRUE, + CL_MAP_WRITE, 0, bufSize_, 0, NULL, NULL, + &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + setData(mem, bufSize_, 0x600df00d); + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, srcBuffer_, mem, 0, NULL, NULL); + + flags = CL_MEM_WRITE_ONLY; + if (persistent[1]) { + flags |= CL_MEM_USE_PERSISTENT_MEM_AMD; + } else if (allocHostPtr[1]) { + flags |= CL_MEM_ALLOC_HOST_PTR; + } else if (useHostPtr[1]) { + flags |= CL_MEM_USE_HOST_PTR; + memptr[1] = malloc(bufSize_ + 4096); + alignedmemptr[1] = (void *)(((size_t)memptr[1] + 4095) & ~4095); + } + dstBuffer_ = _wrapper->clCreateBuffer(context_, flags, bufSize_, + alignedmemptr[1], &error_); + CHECK_RESULT(dstBuffer_ == 0, "clCreateBuffer(dstBuffer) failed"); + + // Force persistent memory to be on GPU + if (persistent[0]) { + cl_mem memBuffer = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(memBuffer == 0, "clCreateBuffer(memBuffer) failed"); + + _wrapper->clEnqueueCopyBuffer(cmd_queue_, memBuffer, dstBuffer_, 0, 0, + bufSize_, 0, NULL, NULL); + _wrapper->clFinish(cmd_queue_); + + _wrapper->clReleaseMemObject(memBuffer); + } + if (persistent[1]) { + cl_mem memBuffer = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(memBuffer == 0, "clCreateBuffer(memBuffer) failed"); + + _wrapper->clEnqueueCopyBuffer(cmd_queue_, srcBuffer_, memBuffer, 0, 0, + bufSize_, 0, NULL, NULL); + _wrapper->clFinish(cmd_queue_); + + _wrapper->clReleaseMemObject(memBuffer); + } +} + +void OCLPerfBufferCopySpeed::run(void) { + CPerfCounter timer; + + // Warm up + error_ = _wrapper->clEnqueueCopyBuffer(cmd_queue_, srcBuffer_, dstBuffer_, 0, + 0, bufSize_, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueCopyBuffer failed"); + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + error_ = _wrapper->clEnqueueCopyBuffer(cmd_queue_, srcBuffer_, dstBuffer_, + 0, 0, bufSize_, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueCopyBuffer failed"); + } + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Buffer copy bandwidth in GB/s + double perf = ((double)bufSize_ * numIter * (double)(1e-09)) / sec; + + void *mem; + mem = + _wrapper->clEnqueueMapBuffer(cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_READ, + 0, bufSize_, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + checkData(mem, bufSize_, 0x600df00d); + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, dstBuffer_, mem, 0, NULL, NULL); + + const char *strSrc = NULL; + const char *strDst = NULL; + if (persistent[0]) + strSrc = "per"; + else if (allocHostPtr[0]) + strSrc = "AHP"; + else if (useHostPtr[0]) + strSrc = "UHP"; + else + strSrc = "dev"; + if (persistent[1]) + strDst = "per"; + else if (allocHostPtr[1]) + strDst = "AHP"; + else if (useHostPtr[1]) + strDst = "UHP"; + else + strDst = "dev"; + // Double results when src and dst are both on device + if ((persistent[0] || (!allocHostPtr[0] && !useHostPtr[0])) && + (persistent[1] || (!allocHostPtr[1] && !useHostPtr[1]))) + perf *= 2.0; + // Double results when src and dst are both in sysmem + if ((allocHostPtr[0] || useHostPtr[0]) && (allocHostPtr[1] || useHostPtr[1])) + perf *= 2.0; + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) s:%s d:%s i:%4d (GB/s) ", bufSize_, + strSrc, strDst, numIter); + testDescString = buf; +} + +unsigned int OCLPerfBufferCopySpeed::close(void) { + if (srcBuffer_) { + error_ = _wrapper->clReleaseMemObject(srcBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(srcBuffer_) failed"); + } + if (dstBuffer_) { + error_ = _wrapper->clReleaseMemObject(dstBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(dstBuffer_) failed"); + } + if (memptr[0]) { + free(memptr[0]); + } + if (memptr[1]) { + free(memptr[1]); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} + +void OCLPerfBufferCopyRectSpeed::run(void) { + CPerfCounter timer; + size_t width = static_cast(sqrt(static_cast(bufSize_))); + size_t srcOrigin[3] = {0, 0, 0}; + size_t dstOrigin[3] = {0, 0, 0}; + size_t region[3] = {width, width, 1}; + // Clamp iteration count for non-local writes to shorten test runtime + unsigned int testNumIter = numIter; + + if (allocHostPtr[1]) { + testNumIter = (numIter < 100 ? numIter : 100); + } + + // Skip for 1.0 platforms + if ((platformVersion[0] == '1') && (platformVersion[2] == '0')) { + char buf[256]; + SNPRINTF(buf, sizeof(buf), " SKIPPED "); + testDescString = buf; + return; + } + // Warm up + error_ = _wrapper->clEnqueueCopyBufferRect(cmd_queue_, srcBuffer_, dstBuffer_, + srcOrigin, dstOrigin, region, + width, 0, width, 0, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueCopyBufferRect failed"); + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < testNumIter; i++) { + error_ = _wrapper->clEnqueueCopyBufferRect( + cmd_queue_, srcBuffer_, dstBuffer_, srcOrigin, dstOrigin, region, width, + 0, width, 0, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueCopyBufferRect failed"); + } + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Buffer copy bandwidth in GB/s + double perf = ((double)bufSize_ * testNumIter * (double)(1e-09)) / sec; + + const char *strSrc = NULL; + const char *strDst = NULL; + if (persistent[0]) + strSrc = "per"; + else if (allocHostPtr[0]) + strSrc = "AHP"; + else if (useHostPtr[0]) + strSrc = "UHP"; + else + strSrc = "dev"; + if (persistent[1]) + strDst = "per"; + else if (allocHostPtr[1]) + strDst = "AHP"; + else if (useHostPtr[1]) + strDst = "UHP"; + else + strDst = "dev"; + // Double results when src and dst are both on device + if ((persistent[0] || (!allocHostPtr[0] && !useHostPtr[0])) && + (persistent[1] || (!allocHostPtr[1] && !useHostPtr[1]))) + perf *= 2.0; + // Double results when src and dst are both in sysmem + if ((allocHostPtr[0] || useHostPtr[0]) && (allocHostPtr[1] || useHostPtr[1])) + perf *= 2.0; + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) s:%s d:%s i:%4d (GB/s) ", bufSize_, + strSrc, strDst, testNumIter); + testDescString = buf; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfBufferCopySpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfBufferCopySpeed.h new file mode 100644 index 0000000000..c5a90679f5 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfBufferCopySpeed.h @@ -0,0 +1,65 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_BufferCopySpeed_H_ +#define _OCL_BufferCopySpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfBufferCopySpeed : public OCLTestImp { + public: + OCLPerfBufferCopySpeed(); + virtual ~OCLPerfBufferCopySpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 1000; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem srcBuffer_; + cl_mem dstBuffer_; + cl_int error_; + + unsigned int bufSize_; + bool persistent[2]; + bool allocHostPtr[2]; + bool useHostPtr[2]; + unsigned int numIter; + bool isAMD; + char platformVersion[32]; + void setData(void* ptr, unsigned int size, unsigned int value); + void checkData(void* ptr, unsigned int size, unsigned int value); + void* memptr[2]; + void* alignedmemptr[2]; +}; + +class OCLPerfBufferCopyRectSpeed : public OCLPerfBufferCopySpeed { + public: + OCLPerfBufferCopyRectSpeed() : OCLPerfBufferCopySpeed() {} + + public: + virtual void run(void); +}; +#endif // _OCL_BufferCopySpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfBufferReadSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfBufferReadSpeed.cpp new file mode 100644 index 0000000000..93069e5a03 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfBufferReadSpeed.cpp @@ -0,0 +1,334 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfBufferReadSpeed.h" + +#include +#include +#include + +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 8 +// 256KB, 1 MB, 4MB, 16 MB +static const unsigned int Sizes[NUM_SIZES] = { + 1024, 32 * 1024, 64 * 1024, 128 * 1024, 262144, 1048576, 4194304, 16777216}; + +static cl_uint blockedSubtests; + +static const unsigned int Iterations[2] = {1, OCLPerfBufferReadSpeed::NUM_ITER}; +#define NUM_OFFSETS 1 +static const unsigned int offsets[NUM_OFFSETS] = {0}; +#define NUM_SUBTESTS (3 + NUM_OFFSETS) +extern const char *blkStr[2]; + +OCLPerfBufferReadSpeed::OCLPerfBufferReadSpeed() { + _numSubTests = NUM_SIZES * NUM_SUBTESTS * 2; + blockedSubtests = _numSubTests; + _numSubTests += NUM_SIZES * NUM_SUBTESTS; +} + +OCLPerfBufferReadSpeed::~OCLPerfBufferReadSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfBufferReadSpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + persistent = false; + allocHostPtr = false; + useHostPtr = false; + hostMem = NULL; + alignedMem = NULL; + alignment = 4096; + isAMD = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + char getVersion[128]; + error_ = _wrapper->clGetPlatformInfo(platform, CL_PLATFORM_VERSION, + sizeof(getVersion), getVersion, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + platformVersion[0] = getVersion[7]; + platformVersion[1] = getVersion[8]; + platformVersion[2] = getVersion[9]; + platformVersion[3] = '\0'; + bufSize_ = Sizes[_openTest % NUM_SIZES]; + + if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) > 2) { + useHostPtr = true; + offset = offsets[((_openTest / NUM_SIZES) % NUM_SUBTESTS) - 3]; + } else if ((((_openTest / NUM_SIZES) % NUM_SUBTESTS) == 2) && isAMD) { + persistent = true; + } else if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) == 1) { + allocHostPtr = true; + } + + if (_openTest < blockedSubtests) { + numIter = Iterations[_openTest / (NUM_SIZES * NUM_SUBTESTS)]; + } else { + numIter = + 4 * OCLPerfBufferReadSpeed::NUM_ITER / ((_openTest % NUM_SIZES) + 1); + } + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + if (persistent) { + flags |= CL_MEM_USE_PERSISTENT_MEM_AMD; + } else if (allocHostPtr) { + flags |= CL_MEM_ALLOC_HOST_PTR; + } else if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + hostMem = (char *)malloc(bufSize_ + alignment - 1 + offset); + CHECK_RESULT(hostMem == 0, "malloc(hostMem) failed"); + alignedMem = + (char *)((((intptr_t)hostMem + alignment - 1) & ~(alignment - 1)) + + offset); + } + outBuffer_ = + _wrapper->clCreateBuffer(context_, flags, bufSize_, alignedMem, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + // Force memory to be on GPU if possible + { + cl_mem memBuffer = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(memBuffer == 0, "clCreateBuffer(memBuffer) failed"); + + _wrapper->clEnqueueCopyBuffer(cmd_queue_, memBuffer, outBuffer_, 0, 0, + bufSize_, 0, NULL, NULL); + _wrapper->clFinish(cmd_queue_); + + _wrapper->clReleaseMemObject(memBuffer); + } +} + +void OCLPerfBufferReadSpeed::run(void) { + CPerfCounter timer; + char *mem = new char[bufSize_]; + cl_bool blocking = (_openTest < blockedSubtests) ? CL_TRUE : CL_FALSE; + + // Warm up + error_ = _wrapper->clEnqueueReadBuffer(cmd_queue_, outBuffer_, CL_TRUE, 0, + bufSize_, mem, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadBuffer failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + error_ = _wrapper->clEnqueueReadBuffer(cmd_queue_, outBuffer_, blocking, 0, + bufSize_, mem, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadBuffer failed"); + } + if (blocking != CL_TRUE) { + _wrapper->clFinish(cmd_queue_); + } + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Buffer read bandwidth in GB/s + double perf = ((double)bufSize_ * numIter * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char str[256]; + if (persistent) { + SNPRINTF(str, sizeof(str), "PERSISTENT (GB/s)"); + } else if (allocHostPtr) { + SNPRINTF(str, sizeof(str), "ALLOC_HOST_PTR (GB/s)"); + } else if (useHostPtr) { + SNPRINTF(str, sizeof(str), "off: %4d USE_HOST_PTR (GB/s)", offset); + } else { + SNPRINTF(str, sizeof(str), "(GB/s)"); + } + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) %3s i: %4d %29s ", bufSize_, + blkStr[blocking], numIter, str); + testDescString = buf; + + delete mem; +} + +unsigned int OCLPerfBufferReadSpeed::close(void) { + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + if (hostMem) { + free(hostMem); + } + + return _crcword; +} + +void OCLPerfBufferReadRectSpeed::run(void) { + CPerfCounter timer; + char *mem = new char[bufSize_]; + size_t width = static_cast(sqrt(static_cast(bufSize_))); + size_t bufOrigin[3] = {0, 0, 0}; + size_t hostOrigin[3] = {0, 0, 0}; + size_t region[3] = {width, width, 1}; + cl_bool blocking = (_openTest < blockedSubtests) ? CL_TRUE : CL_FALSE; + + // Clamp iterations to reduce run time + unsigned int testNumIter; + testNumIter = (numIter < 100 ? numIter : 100); + + // Skip for 1.0 platforms + if ((platformVersion[0] == '1') && (platformVersion[2] == '0')) { + char buf[256]; + SNPRINTF(buf, sizeof(buf), " SKIPPED "); + testDescString = buf; + return; + } + // Warm up + error_ = _wrapper->clEnqueueReadBufferRect( + cmd_queue_, outBuffer_, CL_TRUE, bufOrigin, hostOrigin, region, width, 0, + width, 0, mem, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadBufferRect failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < testNumIter; i++) { + error_ = _wrapper->clEnqueueReadBufferRect( + cmd_queue_, outBuffer_, blocking, bufOrigin, hostOrigin, region, width, + 0, width, 0, mem, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueReadBufferRect failed"); + } + if (blocking != CL_TRUE) { + _wrapper->clFinish(cmd_queue_); + } + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Buffer read bandwidth in GB/s + double perf = ((double)bufSize_ * testNumIter * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char str[256]; + if (persistent) { + SNPRINTF(str, sizeof(str), "PERSISTENT (GB/s)"); + } else if (allocHostPtr) { + SNPRINTF(str, sizeof(str), "ALLOC_HOST_PTR (GB/s)"); + } else if (useHostPtr) { + SNPRINTF(str, sizeof(str), "off: %4d USE_HOST_PTR (GB/s)", offset); + } else { + SNPRINTF(str, sizeof(str), "(GB/s)"); + } + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) %3s i: %4d %29s ", bufSize_, + blkStr[blocking], numIter, str); + testDescString = buf; + + delete mem; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfBufferReadSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfBufferReadSpeed.h new file mode 100644 index 0000000000..f222eb5917 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfBufferReadSpeed.h @@ -0,0 +1,65 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_BufferReadSpeed_H_ +#define _OCL_BufferReadSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfBufferReadSpeed : public OCLTestImp { + public: + OCLPerfBufferReadSpeed(); + virtual ~OCLPerfBufferReadSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 1000; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int bufSize_; + bool persistent; + bool allocHostPtr; + bool useHostPtr; + unsigned int numIter; + char* hostMem; + char* alignedMem; + size_t alignment; + unsigned int offset; + bool isAMD; + char platformVersion[32]; +}; + +class OCLPerfBufferReadRectSpeed : public OCLPerfBufferReadSpeed { + public: + OCLPerfBufferReadRectSpeed() : OCLPerfBufferReadSpeed() {} + + public: + virtual void run(void); +}; + +#endif // _OCL_BufferReadSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfBufferWriteSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfBufferWriteSpeed.cpp new file mode 100644 index 0000000000..10bf8e3dd8 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfBufferWriteSpeed.cpp @@ -0,0 +1,333 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfBufferWriteSpeed.h" + +#include +#include +#include + +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 8 +// 256KB, 1 MB, 4MB, 16 MB +static const unsigned int Sizes[NUM_SIZES] = { + 1024, 32 * 1024, 64 * 1024, 128 * 1024, 262144, 1048576, 4194304, 16777216}; + +static cl_uint blockedSubtests; + +static const unsigned int Iterations[2] = {1, + OCLPerfBufferWriteSpeed::NUM_ITER}; + +#define NUM_OFFSETS 1 +static const unsigned int offsets[NUM_OFFSETS] = {0}; +#define NUM_SUBTESTS (3 + NUM_OFFSETS) +extern const char *blkStr[2]; + +OCLPerfBufferWriteSpeed::OCLPerfBufferWriteSpeed() { + _numSubTests = NUM_SIZES * NUM_SUBTESTS * 2; + blockedSubtests = _numSubTests; + _numSubTests += NUM_SIZES * NUM_SUBTESTS; +} + +OCLPerfBufferWriteSpeed::~OCLPerfBufferWriteSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfBufferWriteSpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + persistent = false; + allocHostPtr = false; + useHostPtr = false; + hostMem = NULL; + alignedMem = NULL; + alignment = 4096; + isAMD = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + char getVersion[128]; + error_ = _wrapper->clGetPlatformInfo(platform, CL_PLATFORM_VERSION, + sizeof(getVersion), getVersion, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + platformVersion[0] = getVersion[7]; + platformVersion[1] = getVersion[8]; + platformVersion[2] = getVersion[9]; + platformVersion[3] = '\0'; + bufSize_ = Sizes[_openTest % NUM_SIZES]; + + if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) > 2) { + useHostPtr = true; + offset = offsets[((_openTest / NUM_SIZES) % NUM_SUBTESTS) - 3]; + } else if ((((_openTest / NUM_SIZES) % NUM_SUBTESTS) == 2) && isAMD) { + persistent = true; + } else if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) == 1) { + allocHostPtr = true; + } + + if (_openTest < blockedSubtests) { + numIter = Iterations[_openTest / (NUM_SIZES * NUM_SUBTESTS)]; + } else { + numIter = + 4 * OCLPerfBufferWriteSpeed::NUM_ITER / ((_openTest % NUM_SIZES) + 1); + } + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_READ_ONLY; + if (persistent) { + flags |= CL_MEM_USE_PERSISTENT_MEM_AMD; + } else if (allocHostPtr) { + flags |= CL_MEM_ALLOC_HOST_PTR; + } else if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + hostMem = (char *)malloc(bufSize_ + alignment - 1 + offset); + CHECK_RESULT(hostMem == 0, "malloc(hostMem) failed"); + alignedMem = + (char *)((((intptr_t)hostMem + alignment - 1) & ~(alignment - 1)) + + offset); + } + outBuffer_ = + _wrapper->clCreateBuffer(context_, flags, bufSize_, alignedMem, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + // Force memory to be on GPU if possible + { + cl_mem memBuffer = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(memBuffer == 0, "clCreateBuffer(memBuffer) failed"); + + _wrapper->clEnqueueCopyBuffer(cmd_queue_, outBuffer_, memBuffer, 0, 0, + bufSize_, 0, NULL, NULL); + _wrapper->clFinish(cmd_queue_); + + _wrapper->clReleaseMemObject(memBuffer); + } +} + +void OCLPerfBufferWriteSpeed::run(void) { + CPerfCounter timer; + char *mem = new char[bufSize_]; + cl_bool blocking = (_openTest < blockedSubtests) ? CL_TRUE : CL_FALSE; + + // Warm up + error_ = _wrapper->clEnqueueWriteBuffer(cmd_queue_, outBuffer_, CL_TRUE, 0, + bufSize_, mem, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadBuffer failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + error_ = _wrapper->clEnqueueWriteBuffer(cmd_queue_, outBuffer_, blocking, 0, + bufSize_, mem, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadBuffer failed"); + } + if (blocking != CL_TRUE) { + _wrapper->clFinish(cmd_queue_); + } + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Buffer write bandwidth in GB/s + double perf = ((double)bufSize_ * numIter * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char str[256]; + if (persistent) { + SNPRINTF(str, sizeof(str), "PERSISTENT (GB/s)"); + } else if (allocHostPtr) { + SNPRINTF(str, sizeof(str), "ALLOC_HOST_PTR (GB/s)"); + } else if (useHostPtr) { + SNPRINTF(str, sizeof(str), "off: %4d USE_HOST_PTR (GB/s)", offset); + } else { + SNPRINTF(str, sizeof(str), "(GB/s)"); + } + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) %3s i: %4d %29s ", bufSize_, + blkStr[blocking], numIter, str); + testDescString = buf; + + delete mem; +} + +unsigned int OCLPerfBufferWriteSpeed::close(void) { + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + if (hostMem) { + free(hostMem); + } + + return _crcword; +} + +void OCLPerfBufferWriteRectSpeed::run(void) { + CPerfCounter timer; + char *mem = new char[bufSize_]; + size_t width = static_cast(sqrt(static_cast(bufSize_))); + size_t bufOrigin[3] = {0, 0, 0}; + size_t hostOrigin[3] = {0, 0, 0}; + size_t region[3] = {width, width, 1}; + cl_bool blocking = (_openTest < blockedSubtests) ? CL_TRUE : CL_FALSE; + + // Skip for 1.0 platforms + if ((platformVersion[0] == '1') && (platformVersion[2] == '0')) { + char buf[256]; + SNPRINTF(buf, sizeof(buf), " SKIPPED "); + testDescString = buf; + return; + } + // Warm up + error_ = _wrapper->clEnqueueWriteBufferRect( + cmd_queue_, outBuffer_, CL_TRUE, bufOrigin, hostOrigin, region, width, 0, + width, 0, mem, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadBufferRect failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + error_ = _wrapper->clEnqueueWriteBufferRect( + cmd_queue_, outBuffer_, blocking, bufOrigin, hostOrigin, region, width, + 0, width, 0, mem, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadBufferRect failed"); + } + if (blocking != CL_TRUE) { + _wrapper->clFinish(cmd_queue_); + } + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Buffer write bandwidth in GB/s + double perf = ((double)bufSize_ * numIter * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char str[256]; + if (persistent) { + SNPRINTF(str, sizeof(str), "PERSISTENT (GB/s)"); + } else if (allocHostPtr) { + SNPRINTF(str, sizeof(str), "ALLOC_HOST_PTR (GB/s)"); + } else if (useHostPtr) { + SNPRINTF(str, sizeof(str), "off: %4d USE_HOST_PTR (GB/s)", offset); + } else { + SNPRINTF(str, sizeof(str), "(GB/s)"); + } + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) %3s i: %4d %29s ", bufSize_, + blkStr[blocking], numIter, str); + testDescString = buf; + + delete mem; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfBufferWriteSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfBufferWriteSpeed.h new file mode 100644 index 0000000000..d36da84aa4 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfBufferWriteSpeed.h @@ -0,0 +1,65 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_BufferWriteSpeed_H_ +#define _OCL_BufferWriteSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfBufferWriteSpeed : public OCLTestImp { + public: + OCLPerfBufferWriteSpeed(); + virtual ~OCLPerfBufferWriteSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 1000; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int bufSize_; + bool persistent; + bool allocHostPtr; + bool useHostPtr; + unsigned int numIter; + char* hostMem; + char* alignedMem; + size_t alignment; + unsigned int offset; + bool isAMD; + char platformVersion[32]; +}; + +class OCLPerfBufferWriteRectSpeed : public OCLPerfBufferWriteSpeed { + public: + OCLPerfBufferWriteRectSpeed() : OCLPerfBufferWriteSpeed() {} + + public: + virtual void run(void); +}; + +#endif // _OCL_BufferWriteSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfCPUMemSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfCPUMemSpeed.cpp new file mode 100644 index 0000000000..8840c7f98b --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfCPUMemSpeed.cpp @@ -0,0 +1,304 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfCPUMemSpeed.h" + +#include +#include +#include + +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 4 +// 256KB, 1 MB, 4MB, 16 MB +static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304, + 16777216}; + +#define ITER_COUNT 2 +static const unsigned int Iterations[2] = {1, OCLPerfCPUMemSpeed::NUM_ITER}; +#define NUM_OFFSETS 1 +static const unsigned int offsets[NUM_OFFSETS] = {0}; +#define NUM_SUBTESTS (3 + NUM_OFFSETS) +OCLPerfCPUMemSpeed::OCLPerfCPUMemSpeed() { + _numSubTests = NUM_SIZES * NUM_SUBTESTS * ITER_COUNT * 3; +} + +OCLPerfCPUMemSpeed::~OCLPerfCPUMemSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfCPUMemSpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + persistent = false; + allocHostPtr = false; + useHostPtr = false; + hostMem = NULL; + alignedMem = NULL; + alignment = 4096; + testMemset = false; + isAMD = false; + gpuSrc = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + CHECK_RESULT(num_devices == 0, "No devices found, cannot proceed"); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + // if (num_devices > 0) + //{ + // platform = platforms[_platformIndex]; + // break; + //} +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + bufSize_ = Sizes[_openTest % NUM_SIZES]; + if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) > 2) { + useHostPtr = true; + offset = offsets[((_openTest / NUM_SIZES) % NUM_SUBTESTS) - 3]; + } else if ((((_openTest / NUM_SIZES) % NUM_SUBTESTS) == 2) && isAMD) { + persistent = true; + } else if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) == 1) { + allocHostPtr = true; + } + + numIter = Iterations[(_openTest / (NUM_SIZES * NUM_SUBTESTS)) % 2]; + if (_openTest >= (NUM_SIZES * NUM_SUBTESTS * ITER_COUNT * 2)) + testMemset = true; + else if (_openTest >= (NUM_SIZES * NUM_SUBTESTS * ITER_COUNT)) { + gpuSrc = true; + numIter = std::min(numIter, 10u); + } + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags; + if (gpuSrc) { + flags = CL_MEM_WRITE_ONLY; + mapFlags = CL_MAP_READ; + } else { + flags = CL_MEM_READ_ONLY; + mapFlags = CL_MAP_WRITE; + } + if (persistent) { + flags |= CL_MEM_USE_PERSISTENT_MEM_AMD; + } else if (allocHostPtr) { + flags |= CL_MEM_ALLOC_HOST_PTR; + } else if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + hostMem = (char *)malloc(bufSize_ + alignment - 1 + offset); + CHECK_RESULT(hostMem == 0, "malloc(hostMem) failed"); + alignedMem = + (char *)((((intptr_t)hostMem + alignment - 1) & ~(alignment - 1)) + + offset); + } + outBuffer_ = + _wrapper->clCreateBuffer(context_, flags, bufSize_, alignedMem, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + // Force memory to be on GPU if possible + { + cl_mem memBuffer = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(memBuffer == 0, "clCreateBuffer(memBuffer) failed"); + + _wrapper->clEnqueueCopyBuffer(cmd_queue_, memBuffer, outBuffer_, 0, 0, + bufSize_, 0, NULL, NULL); + _wrapper->clFinish(cmd_queue_); + + _wrapper->clReleaseMemObject(memBuffer); + } +} + +void OCLPerfCPUMemSpeed::run(void) { + CPerfCounter timer; + + void *mem; + // Warm up + mem = _wrapper->clEnqueueMapBuffer(cmd_queue_, outBuffer_, CL_TRUE, mapFlags, + 0, bufSize_, 0, NULL, NULL, &error_); + + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, outBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapBuffer failed"); + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + mem = _wrapper->clEnqueueMapBuffer(cmd_queue_, outBuffer_, CL_TRUE, mapFlags, + 0, bufSize_, 0, NULL, NULL, &error_); + + char *cpumem = new char[bufSize_]; + + timer.Reset(); + timer.Start(); + if (testMemset) { + for (unsigned int i = 0; i < numIter; i++) { + memset(mem, 0, bufSize_); + } + } else { + if (gpuSrc) { + for (unsigned int i = 0; i < numIter; i++) { + memcpy((void *)cpumem, mem, bufSize_); + } + } else { + for (unsigned int i = 0; i < numIter; i++) { + memcpy(mem, (void *)cpumem, bufSize_); + } + } + } + + timer.Stop(); + + delete[] cpumem; + + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, outBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapBuffer failed"); + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + double sec = timer.GetElapsedTime(); + + // Map read bandwidth in GB/s + double perf = ((double)bufSize_ * numIter * (double)(1e-09)) / sec; + _perfInfo = (float)perf; + + char str[256]; + if (persistent) { + SNPRINTF(str, sizeof(str), "PERSISTENT (GB/s)"); + } else if (allocHostPtr) { + SNPRINTF(str, sizeof(str), "ALLOC_HOST_PTR (GB/s)"); + } else if (useHostPtr) { + SNPRINTF(str, sizeof(str), "off: %4d USE_HOST_PTR (GB/s)", offset); + } else { + SNPRINTF(str, sizeof(str), "(GB/s)"); + } + const char *str2 = NULL; + if (testMemset) + str2 = "memset to dev"; + else { + if (gpuSrc) + str2 = "memcpy from dev"; + else + str2 = "memcpy to dev"; + } + + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) %15s i: %4d %29s ", bufSize_, str2, + numIter, str); + testDescString = buf; +} + +unsigned int OCLPerfCPUMemSpeed::close(void) { + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + if (hostMem) { + free(hostMem); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfCPUMemSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfCPUMemSpeed.h new file mode 100644 index 0000000000..1b5328e75b --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfCPUMemSpeed.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_CPUMemSpeed_H_ +#define _OCL_CPUMemSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfCPUMemSpeed : public OCLTestImp { + public: + OCLPerfCPUMemSpeed(); + virtual ~OCLPerfCPUMemSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 100; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int bufSize_; + bool persistent; + bool allocHostPtr; + bool useHostPtr; + unsigned int numIter; + bool testMemset; + char* hostMem; + char* alignedMem; + size_t alignment; + unsigned int offset; + bool isAMD; + bool gpuSrc; + cl_map_flags mapFlags; +}; + +#endif // _OCL_CPUMemSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfCommandQueue.cpp b/opencl/tests/ocltst/module/perf/OCLPerfCommandQueue.cpp new file mode 100644 index 0000000000..ddc240e150 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfCommandQueue.cpp @@ -0,0 +1,146 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfCommandQueue.h" + +#include +#include +#include + +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +static const size_t BufSize = 0x1000; +static const size_t Iterations = 0x100; +static const size_t TotalQueues = 4; +static const size_t TotalBufs = 4; + +OCLPerfCommandQueue::OCLPerfCommandQueue() { + _numSubTests = TotalQueues * TotalBufs; + failed_ = false; +} + +OCLPerfCommandQueue::~OCLPerfCommandQueue() {} + +void OCLPerfCommandQueue::open(unsigned int test, char* units, + double& conversion, unsigned int deviceId) { + cl_mem buffer; + _deviceId = deviceId; + CPerfCounter timer; + timer.Reset(); + timer.Start(); + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + timer.Stop(); + if (test == 0) { + printf("Runtime load/init time: %0.2f ms\n", + static_cast(timer.GetElapsedTime() * 1000)); + } + test_ = test; + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + static const size_t MemObjects[] = {1, 100, 1000, 5000}; + size_t numMems = MemObjects[test_ / TotalBufs]; + size_t bufSize = BufSize * sizeof(cl_int4); + for (size_t b = 0; b < numMems; ++b) { + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, bufSize, + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + } +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLPerfCommandQueue::run(void) { + if (failed_) { + return; + } + unsigned int* values; + values = reinterpret_cast(new cl_int4[BufSize]); + CPerfCounter timer; + static const size_t Queues[] = {1, 2, 4, 8}; + size_t numQueues = Queues[test_ % TotalQueues]; + + // Clear destination buffer + memset(values, 0, BufSize * sizeof(cl_int4)); + + size_t iter = + Iterations / (numQueues * ((size_t)1 << (test_ / TotalBufs + 1))); + std::vector cmdQueues(numQueues); + + timer.Reset(); + timer.Start(); + + for (size_t i = 0; i < iter; ++i) { + for (size_t q = 0; q < numQueues; ++q) { + cl_command_queue cmdQueue = _wrapper->clCreateCommandQueue( + context_, devices_[_deviceId], 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueue() failed"); + cmdQueues[q] = cmdQueue; + } + timer.Stop(); + for (size_t q = 0; q < numQueues; ++q) { + for (size_t b = 0; b < buffers_.size(); ++b) { + error_ = _wrapper->clEnqueueWriteBuffer(cmdQueues[q], buffers_[b], + CL_TRUE, 0, sizeof(cl_int4), + values, 0, NULL, NULL); + } + } + timer.Start(); + for (size_t q = 0; q < numQueues; ++q) { + error_ = _wrapper->clReleaseCommandQueue(cmdQueues[q]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseCommandQueue() failed"); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + } + + timer.Stop(); + + std::stringstream stream; + + stream << "Create+destroy time for " << numQueues << " queues and " + << buffers_.size() << " buffers"; + stream.precision(3); + stream.width(5); + stream.setf(std::ios::fixed, std::ios::floatfield); + stream << "(ms)"; + testDescString = stream.str(); + _perfInfo = + static_cast(timer.GetElapsedTime() * 1000 / (iter * numQueues)); + delete[] values; +} + +unsigned int OCLPerfCommandQueue::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/perf/OCLPerfCommandQueue.h b/opencl/tests/ocltst/module/perf/OCLPerfCommandQueue.h new file mode 100644 index 0000000000..75e633d689 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfCommandQueue.h @@ -0,0 +1,42 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_COMMAND_QUEUE_H_ +#define _OCL_PERF_COMMAND_QUEUE_H_ + +#include "OCLTestImp.h" + +class OCLPerfCommandQueue : public OCLTestImp { + public: + OCLPerfCommandQueue(); + virtual ~OCLPerfCommandQueue(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; + unsigned int test_; +}; + +#endif // _OCL_PERF_COMMAND_QUEUE_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfConcurrency.cpp b/opencl/tests/ocltst/module/perf/OCLPerfConcurrency.cpp new file mode 100644 index 0000000000..d7156f718e --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfConcurrency.cpp @@ -0,0 +1,563 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfConcurrency.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +typedef struct { + double x; + double y; + double width; +} coordRec; + +static coordRec coords[] = { + {0.0, 0.0, 0.00001}, // All black +}; + +static unsigned int numCoords = sizeof(coords) / sizeof(coordRec); + +static const char *float_mandel_vec = + "__kernel void mandelbrot(__global uint *out, uint width, float xPos, " + "float yPos, float xStep, float yStep, uint maxIter)\n" + "{\n" + " int tid = get_global_id(0);\n" + " int i = tid % (width/4);\n" + " int j = tid / (width/4);\n" + " int4 veci = (int4)(4*i, 4*i+1, 4*i+2, 4*i+3);\n" + " int4 vecj = (int4)(j, j, j, j);\n" + " float4 x0;\n" + " x0.s0 = (float)(xPos + xStep*veci.s0);\n" + " x0.s1 = (float)(xPos + xStep*veci.s1);\n" + " x0.s2 = (float)(xPos + xStep*veci.s2);\n" + " x0.s3 = (float)(xPos + xStep*veci.s3);\n" + " float4 y0;\n" + " y0.s0 = (float)(yPos + yStep*vecj.s0);\n" + " y0.s1 = (float)(yPos + yStep*vecj.s1);\n" + " y0.s2 = (float)(yPos + yStep*vecj.s2);\n" + " y0.s3 = (float)(yPos + yStep*vecj.s3);\n" + "\n" + " float4 x = x0;\n" + " float4 y = y0;\n" + "\n" + " uint iter = 0;\n" + " float4 tmp;\n" + " int4 stay;\n" + " int4 ccount = 0;\n" + " float4 savx = x;\n" + " float4 savy = y;\n" + " stay = (x*x+y*y) <= (float4)(4.0f, 4.0f, 4.0f, 4.0f);\n" + " for (iter = 0; (stay.s0 | stay.s1 | stay.s2 | stay.s3) && (iter < " + "maxIter); iter+=16)\n" + " {\n" + " x = savx;\n" + " y = savy;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " stay = (x*x+y*y) <= (float4)(4.0f, 4.0f, 4.0f, 4.0f);\n" + " savx = (stay ? x : savx);\n" + " savy = (stay ? y : savy);\n" + " ccount -= stay*16;\n" + " }\n" + " // Handle remainder\n" + " if (!(stay.s0 & stay.s1 & stay.s2 & stay.s3))\n" + " {\n" + " iter = 16;\n" + " do\n" + " {\n" + " x = savx;\n" + " y = savy;\n" + " // More efficient to use scalar ops here: Why?\n" + " stay.s0 = ((x.s0*x.s0+y.s0*y.s0) <= 4.0f) && (ccount.s0 < " + "maxIter);\n" + " stay.s1 = ((x.s1*x.s1+y.s1*y.s1) <= 4.0f) && (ccount.s1 < " + "maxIter);\n" + " stay.s2 = ((x.s2*x.s2+y.s2*y.s2) <= 4.0f) && (ccount.s2 < " + "maxIter);\n" + " stay.s3 = ((x.s3*x.s3+y.s3*y.s3) <= 4.0f) && (ccount.s3 < " + "maxIter);\n" + " tmp = x;\n" + " x = x*x + x0 - y*y;\n" + " y = 2.0f*tmp*y + y0;\n" + " ccount += stay;\n" + " iter--;\n" + " savx.s0 = (stay.s0 ? x.s0 : savx.s0);\n" + " savx.s1 = (stay.s1 ? x.s1 : savx.s1);\n" + " savx.s2 = (stay.s2 ? x.s2 : savx.s2);\n" + " savx.s3 = (stay.s3 ? x.s3 : savx.s3);\n" + " savy.s0 = (stay.s0 ? y.s0 : savy.s0);\n" + " savy.s1 = (stay.s1 ? y.s1 : savy.s1);\n" + " savy.s2 = (stay.s2 ? y.s2 : savy.s2);\n" + " savy.s3 = (stay.s3 ? y.s3 : savy.s3);\n" + " } while ((stay.s0 | stay.s1 | stay.s2 | stay.s3) && iter);\n" + " }\n" + " __global uint4 *vecOut = (__global uint4 *)out;\n" + " vecOut[tid] = convert_uint4(ccount);\n" + "}\n"; + +OCLPerfConcurrency::OCLPerfConcurrency() { _numSubTests = 10 * numCoords; } + +OCLPerfConcurrency::~OCLPerfConcurrency() {} + +void OCLPerfConcurrency::setData(cl_mem buffer, unsigned int val) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_[0], buffer, true, CL_MAP_WRITE, 0, bufSize_, 0, NULL, NULL, + &error_); + for (unsigned int i = 0; i < width_; i++) data[i] = val; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_[0], buffer, data, 0, + NULL, NULL); + _wrapper->clFinish(cmd_queue_[0]); +} + +void OCLPerfConcurrency::checkData(cl_mem buffer) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_[0], buffer, true, CL_MAP_READ, 0, bufSize_, 0, NULL, NULL, + &error_); + totalIters = 0; + for (unsigned int i = 0; i < width_; i++) { + totalIters += data[i]; + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_[0], buffer, data, 0, + NULL, NULL); + _wrapper->clFinish(cmd_queue_[0]); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfConcurrency::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + unsigned int i; + + if (type_ != CL_DEVICE_TYPE_GPU) { + char msg[256]; + SNPRINTF(msg, sizeof(msg), "No GPU devices present. Exiting!\t"); + testDescString = msg; + return; + } + + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + + for (i = 0; i < MAX_ASYNC_QUEUES; i++) { + cmd_queue_[i] = 0; + program_[i] = 0; + kernel_[i] = 0; + outBuffer_[i] = 0; + } + + // Maximum iteration count + // NOTE: Some kernels are unrolled 16 times, so make sure maxIter is divisible + // by 16 NOTE: Can increase to get better peak performance numbers, but be + // sure not to TDR slow ASICs! NOTE:. for warmup run we use maxIter = 256 and + // then for the actual run we use maxIter = 8388608 * (engine_clock / 1000). + maxIter = 256; + + // NOTE: Width needs to be divisible by 4 because the float_mandel_vec kernel + // processes 4 pixels at once NOTE: Can increase to get better peak + // performance numbers, but be sure not to TDR slow ASICs! + width_ = 256; + + // We compute a square domain + bufSize_ = width_ * sizeof(cl_uint); + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + // if (num_devices > 0) + //{ + // platform = platforms[_platformIndex]; + // break; + //} +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + cl_uint numAsyncQueues; + error_ = _wrapper->clGetDeviceInfo( + device, CL_DEVICE_AVAILABLE_ASYNC_QUEUES_AMD, sizeof(numAsyncQueues), + &numAsyncQueues, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + CHECK_RESULT(numAsyncQueues > MAX_ASYNC_QUEUES, + "numAsyncQueues is too large for this test"); + + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS, + sizeof(size_t), &numCUs, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + switch (_openTest) { + case 0: + num_cmd_queues = num_programs = num_kernels = num_outbuffers = 1; + break; + + case 1: + num_cmd_queues = 1; + num_programs = 1; + num_kernels = 1; + num_outbuffers = 2; + break; + + case 2: + num_cmd_queues = 1; + num_programs = 2; + num_kernels = 2; + num_outbuffers = 2; + break; + + case 3: + num_cmd_queues = num_programs = num_kernels = num_outbuffers = 2; + break; + + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + num_cmd_queues = num_programs = num_kernels = num_outbuffers = + numAsyncQueues % 8; + break; + + default: + break; + } + + for (i = 0; i < num_cmd_queues; i++) { + cmd_queue_[i] = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_[i] == 0, "clCreateCommandQueue failed"); + } + + for (i = 0; i < num_outbuffers; i++) { + outBuffer_[i] = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_[i] == 0, "clCreateBuffer(outBuffer) failed"); + } + + const char *tmp; + tmp = float_mandel_vec; + + for (i = 0; i < num_programs; i++) { + program_[i] = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_[i] == 0, "clCreateProgramWithSource failed"); + + error_ = _wrapper->clBuildProgram(program_[i], 1, &device, "", NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = _wrapper->clGetProgramBuildInfo( + program_[i], device, CL_PROGRAM_BUILD_LOG, 16384 * sizeof(char), log, + NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + } + + for (i = 0; i < num_kernels; i++) { + kernel_[i] = _wrapper->clCreateKernel(program_[i], "mandelbrot", &error_); + CHECK_RESULT(kernel_[i] == 0, "clCreateKernel failed"); + } + + coordIdx = _openTest % numCoords; + float xStep = (float)(coords[coordIdx].width / (double)width_); + float yStep = (float)(-coords[coordIdx].width / (double)width_); + float xPos = (float)(coords[coordIdx].x - 0.5 * coords[coordIdx].width); + float yPos = (float)(coords[coordIdx].y + 0.5 * coords[coordIdx].width); + + for (i = 0; i < num_kernels; i++) { + error_ = _wrapper->clSetKernelArg(kernel_[i], 0, sizeof(cl_mem), + (void *)&outBuffer_[i]); + error_ = _wrapper->clSetKernelArg(kernel_[i], 1, sizeof(cl_uint), + (void *)&width_); + error_ = _wrapper->clSetKernelArg(kernel_[i], 2, sizeof(cl_float), + (void *)&xPos); + error_ = _wrapper->clSetKernelArg(kernel_[i], 3, sizeof(cl_float), + (void *)&yPos); + error_ = _wrapper->clSetKernelArg(kernel_[i], 4, sizeof(cl_float), + (void *)&xStep); + error_ = _wrapper->clSetKernelArg(kernel_[i], 5, sizeof(cl_float), + (void *)&yStep); + error_ = _wrapper->clSetKernelArg(kernel_[i], 6, sizeof(cl_uint), + (void *)&maxIter); + } + + for (i = 0; i < num_outbuffers; i++) { + setData(outBuffer_[i], 0xdeadbeef); + } + + unsigned int clkFrequency = 0; + error_ = clGetDeviceInfo(device, CL_DEVICE_MAX_CLOCK_FREQUENCY, + sizeof(clkFrequency), &clkFrequency, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + assert(clkFrequency > 0); + maxIter = + (unsigned int)(((8388608 * ((float)clkFrequency / 1000)) * numCUs) / 128); + maxIter = (maxIter + 15) & ~15; +} + +void OCLPerfConcurrency::run(void) { + // Test runs only on GPU + if (type_ != CL_DEVICE_TYPE_GPU) return; + + int global = width_ >> 2; + // We handle 4 pixels per thread + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + unsigned int i; + + // Warmup + for (i = 0; i < num_kernels; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_[i % num_cmd_queues], kernel_[i], 1, NULL, + (const size_t *)global_work_size, (const size_t *)local_work_size, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + + for (i = 0; i < num_cmd_queues; i++) { + _wrapper->clFlush(cmd_queue_[i]); + } + + for (i = 0; i < num_cmd_queues; i++) { + _wrapper->clFinish(cmd_queue_[i]); + } + + for (i = 0; i < num_kernels; i++) { + error_ = _wrapper->clSetKernelArg(kernel_[i], 6, sizeof(cl_uint), + (void *)&maxIter); + } + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + + for (i = 0; i < num_kernels; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_[i % num_cmd_queues], kernel_[i], 1, NULL, + (const size_t *)global_work_size, (const size_t *)local_work_size, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + + if (_openTest == 1) { + error_ = _wrapper->clSetKernelArg(kernel_[0], 0, sizeof(cl_mem), + (void *)&outBuffer_[1]); + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_[0], kernel_[0], 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + + for (i = 0; i < num_cmd_queues; i++) { + _wrapper->clFlush(cmd_queue_[i]); + } + + for (i = 0; i < num_cmd_queues; i++) { + _wrapper->clFinish(cmd_queue_[i]); + } + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + unsigned long long expected = + (unsigned long long)width_ * (unsigned long long)maxIter; + + for (i = 0; i < num_outbuffers; i++) { + checkData(outBuffer_[i]); + CHECK_RESULT(totalIters != expected, "Incorrect iteration count detected!"); + } + + _perfInfo = (float)sec; + if (_openTest == 0) + testDescString = "time for 1 kernel (s) "; + else if (_openTest == 1) + testDescString = "time for 2 kernels (s) (same kernel) "; + else if (_openTest == 2) + testDescString = "time for 2 kernels (s) (diff kernels)"; + else { + char buf[128]; + SNPRINTF(buf, sizeof(buf), "time for %d kernels (s) ( %d queues) ", + num_kernels, num_cmd_queues); + testDescString = buf; + } +} + +unsigned int OCLPerfConcurrency::close(void) { + unsigned int i; + + // Test runs only on GPU + if (type_ != CL_DEVICE_TYPE_GPU) return 0; + + _wrapper->clFinish(cmd_queue_[0]); + + for (i = 0; i < num_outbuffers; i++) { + error_ = _wrapper->clReleaseMemObject(outBuffer_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + + for (i = 0; i < num_kernels; i++) { + error_ = _wrapper->clReleaseKernel(kernel_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseKernel(kernel_) failed"); + } + + for (i = 0; i < num_programs; i++) { + error_ = _wrapper->clReleaseProgram(program_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseProgram(program_) failed"); + } + + for (i = 0; i < num_cmd_queues; i++) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfConcurrency.h b/opencl/tests/ocltst/module/perf/OCLPerfConcurrency.h new file mode 100644 index 0000000000..45f56f47f3 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfConcurrency.h @@ -0,0 +1,63 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_Perf_Concurrency_H_ +#define _OCL_Perf_Concurrency_H_ + +#include "OCLTestImp.h" + +class OCLPerfConcurrency : public OCLTestImp { + public: + OCLPerfConcurrency(); + virtual ~OCLPerfConcurrency(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void setData(cl_mem buffer, unsigned int data); + void checkData(cl_mem buffer); + +#define MAX_ASYNC_QUEUES 8 + + cl_context context_; + cl_command_queue cmd_queue_[MAX_ASYNC_QUEUES]; + cl_program program_[MAX_ASYNC_QUEUES]; + cl_kernel kernel_[MAX_ASYNC_QUEUES]; + cl_mem outBuffer_[MAX_ASYNC_QUEUES]; + cl_int error_; + + unsigned int num_cmd_queues; + unsigned int num_programs; + unsigned int num_kernels; + unsigned int num_outbuffers; + + unsigned int width_; + unsigned int bufSize_; + unsigned int maxIter; + unsigned int coordIdx; + unsigned long long totalIters; + size_t numCUs; +}; + +#endif // _OCL_Perf_Concurrency_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDevMemReadSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfDevMemReadSpeed.cpp new file mode 100644 index 0000000000..41f6ffc3e1 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDevMemReadSpeed.cpp @@ -0,0 +1,243 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfDevMemReadSpeed.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 1 +static const unsigned int Sizes[NUM_SIZES] = {256 * 1024 * 1024}; + +const static char *strKernel = + "__kernel void read_kernel(__global uint16 *src, ulong size1, uint " + "threads, __global uint* dst\n" + " )\n" + "{\n" + " uint16 pval;\n" + " int idx = get_global_id(0);\n" + " __global uint16 *srcEnd = src + size1;\n" + " uint tmp = 0;\n" + " src = &src[idx];" + " while (src < srcEnd) \n" + " {\n" + " pval = *src;\n" + " src += threads;\n" + " tmp += pval.s0 + pval.s1 + pval.s2 + pval.s3 + pval.s4 + pval.s5 + pval.s6 + \ + pval.s7 + pval.s8 + pval.s9 + pval.sa + pval.sb + pval.sc + pval.sd + pval.se + pval.sf;\n" + " }\n" + " atomic_add(dst, tmp);\n" + "}\n"; + +OCLPerfDevMemReadSpeed::OCLPerfDevMemReadSpeed() { _numSubTests = 1; } + +OCLPerfDevMemReadSpeed::~OCLPerfDevMemReadSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfDevMemReadSpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + error_ = CL_SUCCESS; + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = 0; + kernel_ = 0; + skip_ = false; + dstBuffer_ = 0; + nBytes = Sizes[0]; + cl_ulong loopCnt = nBytes / (16 * sizeof(cl_uint)); + cl_uint maxCUs; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_MAX_COMPUTE_UNITS, + sizeof(cl_uint), &maxCUs, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + wgs = 64; + const static cl_uint wavesPerCU = 8; + nWorkItems = maxCUs * wavesPerCU * wgs; + + inputData = 0x1; + nIter = 1000; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "read_kernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + srcBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY, nBytes, + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer(srcBuffer) failed"); + void *mem; + mem = _wrapper->clEnqueueMapBuffer(cmdQueues_[_deviceId], srcBuffer_, CL_TRUE, + CL_MAP_READ | CL_MAP_WRITE, 0, nBytes, 0, + NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + for (unsigned int i = 0; i < nBytes / sizeof(cl_uint); ++i) { + reinterpret_cast(mem)[i] = inputData; + } + + dstBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, + sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer(dstBuffer) failed"); + _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], srcBuffer_, mem, 0, + NULL, NULL); + mem = _wrapper->clEnqueueMapBuffer(cmdQueues_[_deviceId], dstBuffer_, CL_TRUE, + CL_MAP_READ | CL_MAP_WRITE, 0, + sizeof(cl_uint), 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memset(mem, 0, sizeof(cl_uint)); + _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], dstBuffer_, mem, 0, + NULL, NULL); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &srcBuffer_); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_ulong), (void *)&loopCnt); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), + (void *)&nWorkItems); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 3, sizeof(cl_mem), (void *)&dstBuffer_); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); +} + +void OCLPerfDevMemReadSpeed::run(void) { + if (skip_) { + return; + } + + CPerfCounter timer; + + size_t gws[1] = {nWorkItems}; + size_t lws[1] = {wgs}; + + // warm up + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + + cl_uint *memResult; + memResult = (cl_uint *)malloc(sizeof(cl_uint)); + if (0 == memResult) { + CHECK_RESULT_NO_RETURN(0, "malloc failed!\n"); + return; + } + + memset(memResult, 0, sizeof(cl_uint)); + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], dstBuffer_, + CL_FALSE, 0, sizeof(cl_uint), + memResult, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadBuffer dstBuffer_ failed!"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + + if (memResult[0] != (nBytes / sizeof(cl_uint))) { + CHECK_RESULT_NO_RETURN(0, "Data validation failed for warm up run!\n"); + free(memResult); + return; + } + + free(memResult); + + timer.Reset(); + timer.Start(); + double sec2 = 0; + cl_event *events = new cl_event[nIter]; + for (unsigned int i = 0; i < nIter; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmdQueues_[_deviceId], kernel_, 1, NULL, gws, lws, 0, NULL, &events[i]); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + timer.Stop(); + for (unsigned int i = 0; i < nIter; i++) { + cl_ulong startTime = 0, endTime = 0; + error_ = _wrapper->clGetEventProfilingInfo( + events[i], CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &startTime, 0); + CHECK_RESULT(error_, "clGetEventProfilingInfo failed"); + error_ = _wrapper->clGetEventProfilingInfo( + events[i], CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &endTime, 0); + CHECK_RESULT(error_, "clGetEventProfilingInfo failed"); + + _wrapper->clReleaseEvent(events[i]); + sec2 += endTime - startTime; + } + double sec = timer.GetElapsedTime(); + delete[] events; + + // read speed in GB/s + double perf = ((double)nBytes * nIter * (double)(1e-09)) / sec; + double perf2 = ((double)nBytes * nIter) / sec2; + _perfInfo = (float)perf2; + float perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) i:%4d Wall time Perf: %.2f (GB/s)", + nBytes, nIter, perfInfo); + testDescString = buf; +} + +unsigned int OCLPerfDevMemReadSpeed::close(void) { + if (!skip_) { + if (srcBuffer_) { + error_ = _wrapper->clReleaseMemObject(srcBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(srcBuffer_) failed"); + } + + if (dstBuffer_) { + error_ = _wrapper->clReleaseMemObject(dstBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(srcBuffer_) failed"); + } + } + + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDevMemReadSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfDevMemReadSpeed.h new file mode 100644 index 0000000000..4545c46470 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDevMemReadSpeed.h @@ -0,0 +1,47 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_DevMemReadSpeed_H_ +#define _OCL_DevMemReadSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfDevMemReadSpeed : public OCLTestImp { + public: + OCLPerfDevMemReadSpeed(); + virtual ~OCLPerfDevMemReadSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + cl_mem srcBuffer_; + cl_mem dstBuffer_; + unsigned int nWorkItems; // number of GPU work items + unsigned int wgs; // work group size + unsigned int nBytes; // input and output buffer size + unsigned int nIter; // overall number of timing loops + cl_uint inputData; // input data to fill the input buffer + bool skip_; +}; + +#endif // _OCL_DevMemReadSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDevMemWriteSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfDevMemWriteSpeed.cpp new file mode 100644 index 0000000000..49b3fbfed4 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDevMemWriteSpeed.cpp @@ -0,0 +1,212 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfDevMemWriteSpeed.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 1 +static const unsigned int Sizes[NUM_SIZES] = {256 * 1024 * 1024}; + +const static char *strKernel = + + "__kernel void write_kernel(__global uint16 *dst, ulong size1, uint " + "threads\n" + " )\n" + "{\n" + " uint16 pval = (uint16)(0xabababab, 0xabababab, 0xabababab, 0xabababab, 0xabababab, 0xabababab, 0xabababab, 0xabababab,\ + 0xabababab, 0xabababab, 0xabababab, 0xabababab, 0xabababab, 0xabababab, 0xabababab, 0xabababab);\n" + " int idx = get_global_id(0);\n" + " __global uint16 *dstEnd = dst + size1;\n" + " dst = &dst[idx];" + " do\n" + " {\n" + " *dst = pval;\n" + " dst += threads;\n" + " }\n" + " while (dst < dstEnd);\n" + "}\n"; + +OCLPerfDevMemWriteSpeed::OCLPerfDevMemWriteSpeed() { _numSubTests = 1; } + +OCLPerfDevMemWriteSpeed::~OCLPerfDevMemWriteSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfDevMemWriteSpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + error_ = CL_SUCCESS; + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = 0; + kernel_ = 0; + skip_ = false; + dstBuffer_ = 0; + nBytes = Sizes[0]; + cl_ulong loopCnt = nBytes / (16 * sizeof(cl_uint)); + cl_uint maxCUs; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_MAX_COMPUTE_UNITS, + sizeof(cl_uint), &maxCUs, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + wgs = 64; + const static cl_uint wavesPerCU = 8; + nWorkItems = maxCUs * wavesPerCU * wgs; + inputData = 0xabababab; + nIter = 1000; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "write_kernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + dstBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, nBytes, + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer(dstBuffer) failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &dstBuffer_); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_ulong), (void *)&loopCnt); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), + (void *)&nWorkItems); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); +} + +void OCLPerfDevMemWriteSpeed::run(void) { + if (skip_) { + return; + } + + CPerfCounter timer; + + size_t gws[1] = {nWorkItems}; + size_t lws[1] = {wgs}; + + // warm up + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + + cl_uint *memResult; + memResult = (cl_uint *)malloc(nBytes); + if (0 == memResult) { + CHECK_RESULT_NO_RETURN(0, "malloc failed!\n"); + return; + } + + memset(memResult, 0, nBytes); + error_ = + _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], dstBuffer_, CL_FALSE, + 0, nBytes, memResult, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadBuffer dstBuffer_ failed!"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + + for (unsigned int i = 0; i < nBytes / sizeof(cl_uint); i++) { + if (((cl_uint *)memResult)[i] != inputData) { + CHECK_RESULT_NO_RETURN(0, "Data validation failed for warm up run!\n"); + free(memResult); + return; + } + } + + free(memResult); + + timer.Reset(); + timer.Start(); + double sec2 = 0; + cl_event *events = new cl_event[nIter]; + for (unsigned int i = 0; i < nIter; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmdQueues_[_deviceId], kernel_, 1, NULL, gws, lws, 0, NULL, &events[i]); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + timer.Stop(); + for (unsigned int i = 0; i < nIter; i++) { + cl_ulong startTime = 0, endTime = 0; + error_ = _wrapper->clGetEventProfilingInfo( + events[i], CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &startTime, 0); + CHECK_RESULT(error_, "clGetEventProfilingInfo failed"); + error_ = _wrapper->clGetEventProfilingInfo( + events[i], CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &endTime, 0); + CHECK_RESULT(error_, "clGetEventProfilingInfo failed"); + + _wrapper->clReleaseEvent(events[i]); + sec2 += endTime - startTime; + } + double sec = timer.GetElapsedTime(); + delete[] events; + + // write speed in GB/s + double perf = ((double)nBytes * nIter * (double)(1e-09)) / sec; + double perf2 = ((double)nBytes * nIter) / sec2; + _perfInfo = (float)perf2; + float perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) i:%4d Wall time Perf: %.2f (GB/s)", + nBytes, nIter, perfInfo); + testDescString = buf; +} + +unsigned int OCLPerfDevMemWriteSpeed::close(void) { + if (!skip_) { + if (dstBuffer_) { + error_ = _wrapper->clReleaseMemObject(dstBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(srcBuffer_) failed"); + } + } + + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDevMemWriteSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfDevMemWriteSpeed.h new file mode 100644 index 0000000000..a74dd02ef2 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDevMemWriteSpeed.h @@ -0,0 +1,46 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_DevMemWriteSpeed_H_ +#define _OCL_DevMemWriteSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfDevMemWriteSpeed : public OCLTestImp { + public: + OCLPerfDevMemWriteSpeed(); + virtual ~OCLPerfDevMemWriteSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + cl_mem dstBuffer_; + unsigned int nWorkItems; // number of GPU work items + unsigned int wgs; // work group size + unsigned int nBytes; // output buffer size + unsigned int nIter; // overall number of timing loops + cl_uint inputData; // input data to fill the input buffer + bool skip_; +}; + +#endif // _OCL_DevMemWriteSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDeviceConcurrency.cpp b/opencl/tests/ocltst/module/perf/OCLPerfDeviceConcurrency.cpp new file mode 100644 index 0000000000..a3de12eef5 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDeviceConcurrency.cpp @@ -0,0 +1,480 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfDeviceConcurrency.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +typedef struct { + double x; + double y; + double width; +} coordRec; + +static coordRec coords[] = { + {0.0, 0.0, 0.00001}, // All black +}; + +static unsigned int numCoords = sizeof(coords) / sizeof(coordRec); + +static const char *float_mandel_vec = + "__kernel void mandelbrot(__global uint *out, uint width, float xPos, " + "float yPos, float xStep, float yStep, uint maxIter)\n" + "{\n" + " int tid = get_global_id(0);\n" + " int i = tid % (width/4);\n" + " int j = tid / (width/4);\n" + " int4 veci = (int4)(4*i, 4*i+1, 4*i+2, 4*i+3);\n" + " int4 vecj = (int4)(j, j, j, j);\n" + " float4 x0;\n" + " x0.s0 = (float)(xPos + xStep*veci.s0);\n" + " x0.s1 = (float)(xPos + xStep*veci.s1);\n" + " x0.s2 = (float)(xPos + xStep*veci.s2);\n" + " x0.s3 = (float)(xPos + xStep*veci.s3);\n" + " float4 y0;\n" + " y0.s0 = (float)(yPos + yStep*vecj.s0);\n" + " y0.s1 = (float)(yPos + yStep*vecj.s1);\n" + " y0.s2 = (float)(yPos + yStep*vecj.s2);\n" + " y0.s3 = (float)(yPos + yStep*vecj.s3);\n" + "\n" + " float4 x = x0;\n" + " float4 y = y0;\n" + "\n" + " uint iter = 0;\n" + " float4 tmp;\n" + " int4 stay;\n" + " int4 ccount = 0;\n" + " float4 savx = x;\n" + " float4 savy = y;\n" + " stay = (x*x+y*y) <= (float4)(4.0f, 4.0f, 4.0f, 4.0f);\n" + " for (iter = 0; (stay.s0 | stay.s1 | stay.s2 | stay.s3) && (iter < " + "maxIter); iter+=16)\n" + " {\n" + " x = savx;\n" + " y = savy;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " // Two iterations\n" + " tmp = x*x + x0 - y*y;\n" + " y = 2.0f * x * y + y0;\n" + " x = tmp*tmp + x0 - y*y;\n" + " y = 2.0f * tmp * y + y0;\n" + "\n" + " stay = (x*x+y*y) <= (float4)(4.0f, 4.0f, 4.0f, 4.0f);\n" + " savx = (stay ? x : savx);\n" + " savy = (stay ? y : savy);\n" + " ccount -= stay*16;\n" + " }\n" + " // Handle remainder\n" + " if (!(stay.s0 & stay.s1 & stay.s2 & stay.s3))\n" + " {\n" + " iter = 16;\n" + " do\n" + " {\n" + " x = savx;\n" + " y = savy;\n" + " // More efficient to use scalar ops here: Why?\n" + " stay.s0 = ((x.s0*x.s0+y.s0*y.s0) <= 4.0f) && (ccount.s0 < " + "maxIter);\n" + " stay.s1 = ((x.s1*x.s1+y.s1*y.s1) <= 4.0f) && (ccount.s1 < " + "maxIter);\n" + " stay.s2 = ((x.s2*x.s2+y.s2*y.s2) <= 4.0f) && (ccount.s2 < " + "maxIter);\n" + " stay.s3 = ((x.s3*x.s3+y.s3*y.s3) <= 4.0f) && (ccount.s3 < " + "maxIter);\n" + " tmp = x;\n" + " x = x*x + x0 - y*y;\n" + " y = 2.0f*tmp*y + y0;\n" + " ccount += stay;\n" + " iter--;\n" + " savx.s0 = (stay.s0 ? x.s0 : savx.s0);\n" + " savx.s1 = (stay.s1 ? x.s1 : savx.s1);\n" + " savx.s2 = (stay.s2 ? x.s2 : savx.s2);\n" + " savx.s3 = (stay.s3 ? x.s3 : savx.s3);\n" + " savy.s0 = (stay.s0 ? y.s0 : savy.s0);\n" + " savy.s1 = (stay.s1 ? y.s1 : savy.s1);\n" + " savy.s2 = (stay.s2 ? y.s2 : savy.s2);\n" + " savy.s3 = (stay.s3 ? y.s3 : savy.s3);\n" + " } while ((stay.s0 | stay.s1 | stay.s2 | stay.s3) && iter);\n" + " }\n" + " __global uint4 *vecOut = (__global uint4 *)out;\n" + " vecOut[tid] = convert_uint4(ccount);\n" + "}\n"; + +OCLPerfDeviceConcurrency::OCLPerfDeviceConcurrency() { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + + platform = platforms[_platformIndex]; + num_devices = 0; + /* Get the number of requested devices */ + + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + if (num_devices > MAX_DEVICES) { + num_devices = MAX_DEVICES; + } + delete platforms; + } + _numSubTests = num_devices; +} + +OCLPerfDeviceConcurrency::~OCLPerfDeviceConcurrency() {} + +void OCLPerfDeviceConcurrency::setData(cl_mem buffer, unsigned int idx, + unsigned int val) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_[idx], buffer, true, CL_MAP_WRITE, 0, bufSize_, 0, NULL, NULL, + &error_); + for (unsigned int i = 0; i < width_; i++) data[i] = val; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_[idx], buffer, data, 0, + NULL, NULL); + _wrapper->clFinish(cmd_queue_[idx]); +} + +void OCLPerfDeviceConcurrency::checkData(cl_mem buffer, unsigned int idx) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_[idx], buffer, true, CL_MAP_READ, 0, bufSize_, 0, NULL, NULL, + &error_); + totalIters = 0; + for (unsigned int i = 0; i < width_; i++) { + totalIters += data[i]; + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_[idx], buffer, data, 0, + NULL, NULL); + _wrapper->clFinish(cmd_queue_[idx]); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfDeviceConcurrency::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + num_devices = 0; + cl_device_id *devices = NULL; + unsigned int i; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + + for (i = 0; i < MAX_DEVICES; i++) { + cmd_queue_[i] = 0; + program_[i] = 0; + kernel_[i] = 0; + outBuffer_[i] = 0; + } + + // Maximum iteration count + // NOTE: Some kernels are unrolled 16 times, so make sure maxIter is divisible + // by 16 NOTE: Can increase to get better peak performance numbers, but be + // sure not to TDR slow ASICs! NOTE:. for warmup run we use maxIter = 256 and + // then for the actual run we use maxIter = 8388608 * (engine_clock / 1000). + maxIter = 256; + + // NOTE: Width needs to be divisible by 4 because the float_mandel_vec kernel + // processes 4 pixels at once NOTE: Can increase to get better peak + // performance numbers, but be sure not to TDR slow ASICs! + width_ = 256; + + // We compute a square domain + bufSize_ = width_ * sizeof(cl_uint); + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + if (num_devices > MAX_DEVICES) { + num_devices = MAX_DEVICES; + } + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested devices */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + context_ = _wrapper->clCreateContext(NULL, num_devices, devices, + notify_callback, NULL, &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cur_devices = _openTest + 1; + + for (i = 0; i < cur_devices; i++) { + cmd_queue_[i] = + _wrapper->clCreateCommandQueue(context_, devices[i], 0, NULL); + CHECK_RESULT(cmd_queue_[i] == 0, "clCreateCommandQueue failed"); + outBuffer_[i] = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_[i] == 0, "clCreateBuffer(outBuffer) failed"); + } + + const char *tmp; + tmp = float_mandel_vec; + + for (i = 0; i < cur_devices; i++) { + program_[i] = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_[i] == 0, "clCreateProgramWithSource failed"); + + error_ = + _wrapper->clBuildProgram(program_[i], 1, &devices[i], "", NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = _wrapper->clGetProgramBuildInfo( + program_[i], devices[i], CL_PROGRAM_BUILD_LOG, 16384 * sizeof(char), + log, NULL); + printf("Build error on device %d -> %s\n", i, log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + } + + for (i = 0; i < cur_devices; i++) { + kernel_[i] = _wrapper->clCreateKernel(program_[i], "mandelbrot", &error_); + CHECK_RESULT(kernel_[i] == 0, "clCreateKernel failed"); + } + + coordIdx = _openTest % numCoords; + float xStep = (float)(coords[coordIdx].width / (double)width_); + float yStep = (float)(-coords[coordIdx].width / (double)width_); + float xPos = (float)(coords[coordIdx].x - 0.5 * coords[coordIdx].width); + float yPos = (float)(coords[coordIdx].y + 0.5 * coords[coordIdx].width); + + for (i = 0; i < cur_devices; i++) { + error_ = _wrapper->clSetKernelArg(kernel_[i], 0, sizeof(cl_mem), + (void *)&outBuffer_[i]); + error_ = _wrapper->clSetKernelArg(kernel_[i], 1, sizeof(cl_uint), + (void *)&width_); + error_ = _wrapper->clSetKernelArg(kernel_[i], 2, sizeof(cl_float), + (void *)&xPos); + error_ = _wrapper->clSetKernelArg(kernel_[i], 3, sizeof(cl_float), + (void *)&yPos); + error_ = _wrapper->clSetKernelArg(kernel_[i], 4, sizeof(cl_float), + (void *)&xStep); + error_ = _wrapper->clSetKernelArg(kernel_[i], 5, sizeof(cl_float), + (void *)&yStep); + error_ = _wrapper->clSetKernelArg(kernel_[i], 6, sizeof(cl_uint), + (void *)&maxIter); + } + + for (i = 0; i < cur_devices; i++) { + setData(outBuffer_[i], i, 0xdeadbeef); + } + + cl_uint clkFrequency = 0; + error_ = clGetDeviceInfo(devices[0], CL_DEVICE_MAX_CLOCK_FREQUENCY, + sizeof(clkFrequency), &clkFrequency, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + assert(clkFrequency > 0); + maxIter = (unsigned int)(8388608 * ((float)clkFrequency / 1000)); + maxIter = (maxIter + 15) & ~15; +} + +void OCLPerfDeviceConcurrency::run(void) { + int global = width_ >> 2; + // We handle 4 pixels per thread + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + unsigned int i; + + // Warmup + for (i = 0; i < cur_devices; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_[i], kernel_[i], 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + + for (i = 0; i < cur_devices; i++) { + _wrapper->clFlush(cmd_queue_[i]); + } + + for (i = 0; i < cur_devices; i++) { + _wrapper->clFinish(cmd_queue_[i]); + } + + for (i = 0; i < cur_devices; i++) { + error_ = _wrapper->clSetKernelArg(kernel_[i], 6, sizeof(cl_uint), + (void *)&maxIter); + } + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + + for (i = 0; i < cur_devices; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_[i], kernel_[i], 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + + for (i = 0; i < cur_devices; i++) { + _wrapper->clFlush(cmd_queue_[i]); + } + + for (i = 0; i < cur_devices; i++) { + _wrapper->clFinish(cmd_queue_[i]); + } + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + unsigned long long expected = + (unsigned long long)width_ * (unsigned long long)maxIter; + + for (i = 0; i < cur_devices; i++) { + checkData(outBuffer_[i], i); + CHECK_RESULT(totalIters != expected, "Incorrect iteration count detected!"); + } + + _perfInfo = (float)sec; + char buf[128]; + SNPRINTF(buf, sizeof(buf), "time for %2d devices (s) (%2d queues) ", + cur_devices, cur_devices); + testDescString = buf; +} + +unsigned int OCLPerfDeviceConcurrency::close(void) { + unsigned int i; + + for (i = 0; i < cur_devices; i++) { + error_ = _wrapper->clReleaseMemObject(outBuffer_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + + for (i = 0; i < cur_devices; i++) { + error_ = _wrapper->clReleaseKernel(kernel_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseKernel(kernel_) failed"); + } + + for (i = 0; i < cur_devices; i++) { + error_ = _wrapper->clReleaseProgram(program_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseProgram(program_) failed"); + } + + for (i = 0; i < cur_devices; i++) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDeviceConcurrency.h b/opencl/tests/ocltst/module/perf/OCLPerfDeviceConcurrency.h new file mode 100644 index 0000000000..4cc9468c75 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDeviceConcurrency.h @@ -0,0 +1,60 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_Perf_DeviceConcurrency_H_ +#define _OCL_Perf_DeviceConcurrency_H_ + +#include "OCLTestImp.h" + +class OCLPerfDeviceConcurrency : public OCLTestImp { + public: + OCLPerfDeviceConcurrency(); + virtual ~OCLPerfDeviceConcurrency(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void setData(cl_mem buffer, unsigned int idx, unsigned int data); + void checkData(cl_mem buffer, unsigned int idx); + +#define MAX_DEVICES 16 + + cl_context context_; + cl_command_queue cmd_queue_[MAX_DEVICES]; + cl_program program_[MAX_DEVICES]; + cl_kernel kernel_[MAX_DEVICES]; + cl_mem outBuffer_[MAX_DEVICES]; + cl_int error_; + + cl_uint num_devices; + cl_uint cur_devices; + + unsigned int width_; + unsigned int bufSize_; + unsigned int maxIter; + unsigned int coordIdx; + unsigned long long totalIters; +}; + +#endif // _OCL_Perf_DeviceConcurrency_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueue.cpp b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueue.cpp new file mode 100644 index 0000000000..5f99e6989f --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueue.cpp @@ -0,0 +1,227 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfDeviceEnqueue.h" + +#include +#include +#include +#include + +#include "CL/cl.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define KERNEL_CODE(...) #__VA_ARGS__ + +typedef struct { + unsigned int threads; +} testStruct; + +static testStruct testList[] = { + {64}, {128}, {256}, {512}, {1024}, {2048}, {4096}, +}; + +const static char* strKernel = {KERNEL_CODE( + \n __kernel void childKernel(__global uint* buf) { + int idx = get_global_id(0); + if (idx < 0) { + buf[idx] = 0; + } +} + \n __kernel void parentKernel(__global uint* buf) { + queue_t def_q = get_default_queue(); + ndrange_t ndrange = ndrange_1D(64, 64); + int gid = get_global_id(0); + + int enq_res = enqueue_kernel(def_q, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, ^{ + childKernel(buf); + }); +} + \n)}; + +OCLPerfDeviceEnqueue::OCLPerfDeviceEnqueue() { + testListSize = sizeof(testList) / sizeof(testStruct); + _numSubTests = 7 * testListSize; + deviceQueue_ = NULL; + failed_ = false; + kernel2_ = NULL; +} + +OCLPerfDeviceEnqueue::~OCLPerfDeviceEnqueue() {} + +void OCLPerfDeviceEnqueue::open(unsigned int test, char* units, + double& conversion, unsigned int deviceId) { + if (type_ == CL_DEVICE_TYPE_CPU) { + return; + } + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + testID_ = test; + + threads = testList[testID_ % testListSize].threads; + size_t param_size = 0; + char* strVersion = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 0, + 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[7] < '2') { + failed_ = true; + return; + } + delete strVersion; + cl_uint maxDevQSize = 0; +#if defined(CL_VERSION_2_0) + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, + sizeof(cl_uint), &maxDevQSize, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); +#endif + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "parentKernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + kernel2_ = _wrapper->clCreateKernel(program_, "childKernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_ALLOC_HOST_PTR, 2048, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + + // Hardcoded for us + if (testID_ >= testListSize) { + queueSize = (1 << (testID_ / testListSize)) * 256 * 1024; + queueSize = std::min(queueSize, maxDevQSize); + threads *= (1 << (testID_ / testListSize - 1)); + threads = std::min(threads, queueSize / 128); + } else { + queueSize = std::max((cl_uint)threads * 128, (cl_uint)16384); + } + +#if defined(CL_VERSION_2_0) + const cl_queue_properties cprops[] = { + CL_QUEUE_PROPERTIES, + static_cast(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | + CL_QUEUE_ON_DEVICE_DEFAULT | + CL_QUEUE_ON_DEVICE), + CL_QUEUE_SIZE, queueSize, 0}; + deviceQueue_ = _wrapper->clCreateCommandQueueWithProperties( + context_, devices_[deviceId], cprops, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateCommandQueueWithProperties() failed"); +#endif +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLPerfDeviceEnqueue::run(void) { + CPerfCounter timer; + if (type_ == CL_DEVICE_TYPE_CPU) { + return; + } + + if (failed_) return; + + cl_mem buffer = buffers()[0]; + + size_t gws[1] = {threads}; + size_t lws[1] = {64}; + + if (gws[0] >= 256) { + lws[0] = 256; + } + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + + // Try to normalize the amount of work per test + unsigned int repeats = (64 / threads) * 50; + if (repeats == 0) repeats = 1; + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < repeats; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + } + timer.Stop(); + + double sec = timer.GetElapsedTime(); + + _perfInfo = (float)(threads * repeats) / (float)(sec * 1000000.); + char buf[256]; + SNPRINTF(buf, sizeof(buf), + "%7d threads spawning 64 threads, queue size %5dKB (Mdisp/s)", + threads, queueSize / 1024); + testDescString = buf; +} + +unsigned int OCLPerfDeviceEnqueue::close(void) { + // FIXME: Re-enable CPU test once bug 10143 is fixed. + if (type_ == CL_DEVICE_TYPE_CPU) { + return 0; + } + + if (NULL != deviceQueue_) { + _wrapper->clReleaseCommandQueue(deviceQueue_); + } + if (NULL != kernel2_) { + _wrapper->clReleaseKernel(kernel2_); + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueue.h b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueue.h new file mode 100644 index 0000000000..af23863fdc --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueue.h @@ -0,0 +1,47 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCLPERF_DEVICE_ENQUEUE_H_ +#define _OCLPERF_DEVICE_ENQUEUE_H_ + +#include "OCLTestImp.h" + +class OCLPerfDeviceEnqueue : public OCLTestImp { + public: + OCLPerfDeviceEnqueue(); + virtual ~OCLPerfDeviceEnqueue(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + cl_command_queue deviceQueue_; + bool failed_; + unsigned int testID_; + cl_kernel kernel2_; + unsigned int testListSize; + unsigned int threads; + cl_uint queueSize; +}; + +#endif // _OCLPERF_DEVICE_ENQUEUE_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueue2.cpp b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueue2.cpp new file mode 100644 index 0000000000..d5ebf33a5a --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueue2.cpp @@ -0,0 +1,260 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfDeviceEnqueue2.h" + +#include +#include +#include +#include + +#include "CL/cl.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define KERNEL_CODE(...) #__VA_ARGS__ + +typedef struct { + unsigned int threads; +} testStruct; + +static testStruct testList[] = { + {64}, {128}, {256}, {512}, {1024}, {2048}, {4096}, +}; + +static unsigned int qsizeList[] = { + 16, 32, 64, 128, 256, 512, +}; + +static unsigned int levelList[] = { + 1, + 2, + 4, + 8, +}; + +const static char* strKernel = {KERNEL_CODE( + \n __kernel void childKernel(__global uint* buf, uint level) { + if (level) { + queue_t def_q = get_default_queue(); + ndrange_t ndrange = ndrange_1D(64, 64); + int gid = get_global_id(0); + int lid = get_local_id(0); + if (lid == 0) { + int enq_res = + enqueue_kernel(def_q, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, ^{ + childKernel(buf, level - 1); + }); + } + } else { + int idx = get_global_id(0); + if (idx < 0) { + buf[idx] = 0; + } + } +} + \n __kernel void parentKernel(__global uint* buf, uint level) { + queue_t def_q = get_default_queue(); + ndrange_t ndrange = ndrange_1D(64, 64); + int gid = get_global_id(0); + + if (level) { + int enq_res = + enqueue_kernel(def_q, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, ^{ + childKernel(buf, level - 1); + }); + } +} + \n)}; + +OCLPerfDeviceEnqueue2::OCLPerfDeviceEnqueue2() { + subTests_level = sizeof(levelList) / sizeof(unsigned int); + subTests_qsize = (sizeof(qsizeList) / sizeof(unsigned int)); + subTests_thread = sizeof(testList) / sizeof(testStruct); + testListSize = subTests_thread; + _numSubTests = subTests_level * subTests_qsize * subTests_thread; + deviceQueue_ = NULL; + failed_ = false; + kernel2_ = NULL; + level = 2; + skip_ = false; +} + +OCLPerfDeviceEnqueue2::~OCLPerfDeviceEnqueue2() {} + +void OCLPerfDeviceEnqueue2::open(unsigned int test, char* units, + double& conversion, unsigned int deviceId) { + if (type_ == CL_DEVICE_TYPE_CPU) { + return; + } + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + testID_ = test; + + threads = testList[testID_ / (subTests_qsize * subTests_level)].threads; + queueSize = qsizeList[(testID_ / subTests_level) % subTests_qsize] * 1024; + level = levelList[testID_ % subTests_level]; + + size_t param_size = 0; + char* strVersion = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 0, + 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[7] < '2') { + failed_ = true; + return; + } + delete strVersion; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "parentKernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + kernel2_ = _wrapper->clCreateKernel(program_, "childKernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_ALLOC_HOST_PTR, 2048, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + +#if defined(CL_VERSION_2_0) + const cl_queue_properties cprops[] = { + CL_QUEUE_PROPERTIES, + static_cast(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | + CL_QUEUE_ON_DEVICE_DEFAULT | + CL_QUEUE_ON_DEVICE), + CL_QUEUE_SIZE, queueSize, 0}; + deviceQueue_ = _wrapper->clCreateCommandQueueWithProperties( + context_, devices_[deviceId], cprops, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateCommandQueueWithProperties() failed"); +#else + skip_ = true; + testDescString = + "DeviceEnqueue NOT supported for < 2.0 builds. Test Skipped."; + return; +#endif +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLPerfDeviceEnqueue2::run(void) { + CPerfCounter timer; + if (type_ == CL_DEVICE_TYPE_CPU) { + return; + } + + if (failed_) { + return; + } + + if (skip_) { + return; + } + + cl_mem buffer = buffers()[0]; + + size_t gws[1] = {threads}; + size_t lws[1] = {64}; + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(unsigned int), &level); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + + // Try to normalize the amount of work per test + // unsigned int repeats = (4096 / threads) * 100 ; + unsigned int repeats = (4096 / threads) * 10; + // unsigned int repeats = 100; + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < repeats; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + } + timer.Stop(); + + double sec = timer.GetElapsedTime(); + + _perfInfo = (float)(threads * repeats * level) / (float)(sec * 1000000.); + char buf[256]; + SNPRINTF( + buf, sizeof(buf), + "%5d threads spawning 64 threads, queue size %3dKB (Mdisp/s), level=%2d", + threads, queueSize / 1024, level); + testDescString = buf; +} + +unsigned int OCLPerfDeviceEnqueue2::close(void) { + // FIXME: Re-enable CPU test once bug 10143 is fixed. + if (type_ == CL_DEVICE_TYPE_CPU) { + return 0; + } + + if (deviceQueue_) { + error_ = _wrapper->clReleaseCommandQueue(deviceQueue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (kernel2_) { + error_ = _wrapper->clReleaseKernel(kernel2_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueue2.h b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueue2.h new file mode 100644 index 0000000000..692544c7b5 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueue2.h @@ -0,0 +1,54 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCLPERF_DEVICE_ENQUEUE2_H_ +#define _OCLPERF_DEVICE_ENQUEUE2_H_ + +#include "OCLTestImp.h" + +class OCLPerfDeviceEnqueue2 : public OCLTestImp { + public: + OCLPerfDeviceEnqueue2(); + virtual ~OCLPerfDeviceEnqueue2(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + cl_command_queue deviceQueue_; + unsigned int testID_; + cl_kernel kernel2_; + unsigned int testListSize; + unsigned int threads; + cl_uint queueSize; + unsigned int subTests_level; + unsigned int subTests_qsize; + unsigned int subTests_thread; + unsigned int level; + unsigned int lws_value; + + bool failed_; + bool skip_; +}; + +#endif // _OCLPERF_DEVICE_ENQUEUE2_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueueEvent.cpp b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueueEvent.cpp new file mode 100644 index 0000000000..41a8d98f98 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueueEvent.cpp @@ -0,0 +1,267 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfDeviceEnqueueEvent.h" + +#include +#include +#include +#include + +#include "CL/cl.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define KERNEL_CODE(...) #__VA_ARGS__ + +typedef struct { + unsigned int threads; +} testStruct; + +static testStruct testList[] = { + {64}, {128}, {256}, {512}, {1024}, {2048}, {4096}, +}; + +static unsigned int qsizeList[] = { + 16, 32, 64, 128, 256, 512, +}; + +static unsigned int levelList[] = { + 1, + 2, + 4, + 8, +}; + +const static char* strKernel = {KERNEL_CODE( + \n __kernel void childKernel(__global uint* buf, uint level, + clk_event_t wait_evt) { + int idx = get_global_id(0); + if (idx < 0) { + buf[idx] = 0; + } +} + \n __kernel void parentKernel(__global uint* buf, uint level) { + if (level) { + queue_t def_q = get_default_queue(); + ndrange_t ndrange = ndrange_1D(64, 64); + clk_event_t user_evt = create_user_event(); + clk_event_t block_evt, wait_evt; + wait_evt = user_evt; + + for (uint i = 0; i < level; i++) { + int enq_res = enqueue_kernel(def_q, CLK_ENQUEUE_FLAGS_NO_WAIT, ndrange, 0, + /*&user_evt*/ NULL, &block_evt, ^{ + childKernel(buf, level - 1, block_evt); + }); + + // wait_evt = block_evt; + } + if (is_valid_event(user_evt)) { + set_user_event_status(user_evt, CL_COMPLETE); + release_event(user_evt); + } + } else { + int idx = get_global_id(0); + if (idx < 0) { + buf[idx] = 0; + } + } +} + \n)}; + +OCLPerfDeviceEnqueueEvent::OCLPerfDeviceEnqueueEvent() { + subTests_level = sizeof(levelList) / sizeof(unsigned int); + subTests_qsize = (sizeof(qsizeList) / sizeof(unsigned int)); + subTests_thread = sizeof(testList) / sizeof(testStruct); + testListSize = subTests_thread; + //_numSubTests = 2*testListSize + subTests_level + subTests_qsize; + _numSubTests = subTests_level * subTests_qsize * subTests_thread; + deviceQueue_ = NULL; + failed_ = false; + skip_ = false; + kernel2_ = NULL; + level = 2; +} + +OCLPerfDeviceEnqueueEvent::~OCLPerfDeviceEnqueueEvent() {} + +void OCLPerfDeviceEnqueueEvent::open(unsigned int test, char* units, + double& conversion, + unsigned int deviceId) { + if (type_ == CL_DEVICE_TYPE_CPU) { + return; + } + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + testID_ = test; + + threads = testList[testID_ / (subTests_qsize * subTests_level)].threads; + queueSize = qsizeList[(testID_ / subTests_level) % subTests_qsize] * 1024; + level = levelList[testID_ % subTests_level]; + + lws_value = 64; + + size_t param_size = 0; + char* strVersion = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 0, + 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[7] < '2') { + failed_ = true; + return; + } + delete strVersion; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "parentKernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + kernel2_ = _wrapper->clCreateKernel(program_, "childKernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_ALLOC_HOST_PTR, 2048, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + +#if defined(CL_VERSION_2_0) + const cl_queue_properties cprops[] = { + CL_QUEUE_PROPERTIES, + static_cast(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | + CL_QUEUE_ON_DEVICE_DEFAULT | + CL_QUEUE_ON_DEVICE), + CL_QUEUE_SIZE, queueSize, 0}; + deviceQueue_ = _wrapper->clCreateCommandQueueWithProperties( + context_, devices_[deviceId], cprops, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateCommandQueueWithProperties() failed"); +#else + skip_ = true; + testDescString = + "DeviceEnqueue NOT supported for < 2.0 builds. Test Skipped."; + return; +#endif +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLPerfDeviceEnqueueEvent::run(void) { + CPerfCounter timer; + if (type_ == CL_DEVICE_TYPE_CPU) { + return; + } + + if (failed_) { + return; + } + + if (skip_) { + return; + } + + cl_mem buffer = buffers()[0]; + + size_t gws[1] = {threads}; + size_t lws[1] = {lws_value}; + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(unsigned int), &level); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + + // Try to normalize the amount of work per test + // unsigned int repeats = (4096 / threads) * 100 ; + unsigned int repeats = (4096 / threads) * 10; + // unsigned int repeats = 100; + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < repeats; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + } + timer.Stop(); + + double sec = timer.GetElapsedTime(); + + _perfInfo = (float)(threads * repeats * level) / (float)(sec * 1000000.); + char buf[256]; + SNPRINTF( + buf, sizeof(buf), + "%5d threads spawning %2d threads, queue size %3dKB (Mdisp/s), level=%2d", + threads, lws_value, queueSize / 1024, level); + testDescString = buf; +} + +unsigned int OCLPerfDeviceEnqueueEvent::close(void) { + // FIXME: Re-enable CPU test once bug 10143 is fixed. + if (type_ == CL_DEVICE_TYPE_CPU) { + return 0; + } + + if (deviceQueue_) { + error_ = _wrapper->clReleaseCommandQueue(deviceQueue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (kernel2_) { + error_ = _wrapper->clReleaseKernel(kernel2_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueueEvent.h b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueueEvent.h new file mode 100644 index 0000000000..688ac87335 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueueEvent.h @@ -0,0 +1,54 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCLPERF_DEVICE_ENQUEUE_EVENT_H_ +#define _OCLPERF_DEVICE_ENQUEUE_EVENT_H_ + +#include "OCLTestImp.h" + +class OCLPerfDeviceEnqueueEvent : public OCLTestImp { + public: + OCLPerfDeviceEnqueueEvent(); + virtual ~OCLPerfDeviceEnqueueEvent(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + cl_command_queue deviceQueue_; + unsigned int testID_; + cl_kernel kernel2_; + unsigned int testListSize; + unsigned int threads; + cl_uint queueSize; + unsigned int subTests_level; + unsigned int subTests_qsize; + unsigned int subTests_thread; + unsigned int level; + unsigned int lws_value; + + bool failed_; + bool skip_; +}; + +#endif // _OCLPERF_DEVICE_ENQUEUE_EVENT_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueueSier.cpp b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueueSier.cpp new file mode 100644 index 0000000000..d6927d142e --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueueSier.cpp @@ -0,0 +1,233 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfDeviceEnqueueSier.h" + +#include +#include +#include +#include +#include + +#include "CL/cl.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define KERNEL_CODE(...) #__VA_ARGS__ + +typedef struct { + unsigned int threads; +} testStruct; + +static unsigned int sizeList[] = { + 81, 243, 729, 2187, 6561, 19683, 59049, +}; + +const static char* strKernel = {KERNEL_CODE( + \n __kernel void parentKernel(__global uint* buf, int width, int offsetx, + int offsety) { + int x = get_global_id(0); + int y = get_global_id(1); + queue_t q = get_default_queue(); + + int one_third = get_global_size(0) / 3; + int two_thirds = 2 * one_third; + + if (x >= one_third && x < two_thirds && y >= one_third && y < two_thirds) { + int idx = get_global_id(0); + if (idx < 0) { + buf[idx] = 0; + } + } else { + if (one_third > 1 && x % one_third == 0 && y % one_third == 0) { + const size_t grid[2] = {one_third, one_third}; + enqueue_kernel(q, 0, ndrange_2D(grid), ^{ + parentKernel(buf, width, x + offsetx, y + offsety); + }); + } + } +} + \n)}; + +OCLPerfDeviceEnqueueSier::OCLPerfDeviceEnqueueSier() { + _numSubTests = sizeof(sizeList) / sizeof(unsigned int); + deviceQueue_ = NULL; + failed_ = false; + skip_ = false; +} + +OCLPerfDeviceEnqueueSier::~OCLPerfDeviceEnqueueSier() {} + +void OCLPerfDeviceEnqueueSier::open(unsigned int test, char* units, + double& conversion, unsigned int deviceId) { + if (type_ == CL_DEVICE_TYPE_CPU) { + return; + } + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + testID_ = test; + + size_t param_size = 0; + char* strVersion = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 0, + 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[7] < '2') { + failed_ = true; + return; + } + delete strVersion; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "parentKernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_ALLOC_HOST_PTR, 2048, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + + queueSize = 512 * 1024; + + image_size = sizeList[testID_]; + +#if defined(CL_VERSION_2_0) + const cl_queue_properties cprops[] = { + CL_QUEUE_PROPERTIES, + static_cast(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | + CL_QUEUE_ON_DEVICE_DEFAULT | + CL_QUEUE_ON_DEVICE), + CL_QUEUE_SIZE, queueSize, 0}; + deviceQueue_ = _wrapper->clCreateCommandQueueWithProperties( + context_, devices_[deviceId], cprops, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateCommandQueueWithProperties() failed"); +#else + skip_ = true; + testDescString = + "DeviceEnqueue NOT supported for < 2.0 builds. Test Skipped."; + return; +#endif +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLPerfDeviceEnqueueSier::run(void) { + CPerfCounter timer; + if (type_ == CL_DEVICE_TYPE_CPU) { + return; + } + + if (failed_) { + return; + } + + if (skip_) { + return; + } + + cl_mem buffer = buffers()[0]; + + size_t gws[1] = {1}; + size_t lws[1] = {0}; + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + int width = image_size, offsetx = 0, offsety = 0; + error_ |= _wrapper->clSetKernelArg(kernel_, 1, sizeof(int), (void*)&width); + error_ |= _wrapper->clSetKernelArg(kernel_, 2, sizeof(int), (void*)&offsetx); + error_ |= _wrapper->clSetKernelArg(kernel_, 3, sizeof(int), (void*)&offsety); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, 0, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + + size_t global_work_size[2] = {image_size, image_size}; + + // Try to normalize the amount of work per test + unsigned int repeats = 100; + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < repeats; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 2, + NULL, global_work_size, 0, 0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + } + timer.Stop(); + + double sec = timer.GetElapsedTime(); + + unsigned int numOfKernels = (int)pow(8.0, log(image_size) / log(3) - 1); + _perfInfo = (float)(numOfKernels * repeats) / (float)(sec * 1000000.); + char buf[256]; + SNPRINTF(buf, sizeof(buf), "image_size = %5d, queue size %3dKB (Mdisp/s)", + image_size, queueSize / 1024); + testDescString = buf; +} + +unsigned int OCLPerfDeviceEnqueueSier::close(void) { + // FIXME: Re-enable CPU test once bug 10143 is fixed. + if (type_ == CL_DEVICE_TYPE_CPU) { + return 0; + } + + if (deviceQueue_) { + error_ = _wrapper->clReleaseCommandQueue(deviceQueue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueueSier.h b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueueSier.h new file mode 100644 index 0000000000..ae809b2735 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDeviceEnqueueSier.h @@ -0,0 +1,49 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCLPERF_DEVICE_ENQUEUE_SIER_H_ +#define _OCLPERF_DEVICE_ENQUEUE_SIER_H_ + +#include "OCLTestImp.h" + +class OCLPerfDeviceEnqueueSier : public OCLTestImp { + public: + OCLPerfDeviceEnqueueSier(); + virtual ~OCLPerfDeviceEnqueueSier(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + cl_command_queue deviceQueue_; + unsigned int testID_; + unsigned int testListSize; + // unsigned int threads; + cl_uint queueSize; + unsigned int image_size; + + bool failed_; + bool skip_; +}; + +#endif // _OCLPERF_DEVICE_ENQUEUE_SIER_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDispatchSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfDispatchSpeed.cpp new file mode 100644 index 0000000000..86f891d4f5 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDispatchSpeed.cpp @@ -0,0 +1,391 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfDispatchSpeed.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define CHAR_BUF_SIZE 512 + +typedef struct { + unsigned int iterations; + int flushEvery; +} testStruct; + +testStruct testList[] = { + {1, -1}, {1, -1}, {10, 1}, {10, -1}, {100, 1}, + {100, 10}, {100, -1}, {1000, 1}, {1000, 10}, {1000, 100}, + {1000, -1}, {10000, 1}, {10000, 10}, {10000, 100}, {10000, 1000}, + {10000, -1}, {100000, 1}, {100000, 10}, {100000, 100}, {100000, 1000}, + {100000, 10000}, {100000, -1}, +}; + +unsigned int mapTestList[] = {1, 1, 10, 100, 1000, 10000, 100000}; + +void OCLPerfDispatchSpeed::genShader(void) { + shader_.clear(); + shader_ += + "__kernel void _dispatchSpeed(__global float *outBuf)\n" + "{\n" + " int i = (int) get_global_id(0);\n" + " if (i < 0)\n" + " outBuf[i] = 0.0f;\n" + "}\n"; +} + +OCLPerfDispatchSpeed::OCLPerfDispatchSpeed() { + testListSize = sizeof(testList) / sizeof(testStruct); + _numSubTests = 2 * 2 * testListSize; +} + +OCLPerfDispatchSpeed::~OCLPerfDispatchSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfDispatchSpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test % testListSize; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + outBuffer_ = 0; + sleep = false; + doWarmup = false; + + if ((test / testListSize) % 2) { + doWarmup = true; + } + if (test >= (testListSize * 2)) { + sleep = true; + } + + bufSize_ = 64 * sizeof(cl_float); + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + // if (num_devices > 0) + //{ + // platform = platforms[_platformIndex]; + // break; + //} +#if 0 + } +#endif + delete platforms; + } else { + CHECK_RESULT(numPlatforms == 0, "No platforms available!"); + } + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + outBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + genShader(); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &device, "", NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "_dispatchSpeed", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&outBuffer_); +} + +void OCLPerfDispatchSpeed::run(void) { + int global = bufSize_ / sizeof(cl_float); + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + CPerfCounter timer; + cl_event event; + cl_int eventStatus; + + if (doWarmup) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, &event); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue_); + } + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < testList[_openTest].iterations; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, &event); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + if ((testList[_openTest].flushEvery > 0) && + (((i + 1) % testList[_openTest].flushEvery) == 0)) { + if (sleep) { + _wrapper->clFinish(cmd_queue_); + } else { + _wrapper->clFlush(cmd_queue_); + error_ = + _wrapper->clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(cl_int), &eventStatus, NULL); + while (eventStatus > 0) { + error_ = + _wrapper->clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(cl_int), &eventStatus, NULL); + } + } + } + if (i != (testList[_openTest].iterations - 1)) { + _wrapper->clReleaseEvent(event); + } + } + if (sleep) { + _wrapper->clFinish(cmd_queue_); + } else { + _wrapper->clFlush(cmd_queue_); + error_ = _wrapper->clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(cl_int), &eventStatus, NULL); + while (eventStatus > 0) { + error_ = + _wrapper->clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(cl_int), &eventStatus, NULL); + } + } + _wrapper->clReleaseEvent(event); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // microseconds per launch + double perf = (1000000.f * sec / testList[_openTest].iterations); + const char *waitType; + const char *extraChar; + const char *n; + const char *warmup; + if (sleep) { + waitType = "sleep"; + extraChar = ""; + n = ""; + } else { + waitType = "spin"; + n = "n"; + extraChar = " "; + } + if (doWarmup) { + warmup = "warmup"; + } else { + warmup = ""; + } + + _perfInfo = (float)perf; + char buf[256]; + if (testList[_openTest].flushEvery > 0) { + SNPRINTF(buf, sizeof(buf), + " %7d dispatches %s%sing every %5d %6s (us/disp)", + testList[_openTest].iterations, waitType, n, + testList[_openTest].flushEvery, warmup); + } else { + SNPRINTF(buf, sizeof(buf), + " %7d dispatches (%s%s) %6s (us/disp)", + testList[_openTest].iterations, waitType, extraChar, warmup); + } + testDescString = buf; +} + +unsigned int OCLPerfDispatchSpeed::close(void) { + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} + +OCLPerfMapDispatchSpeed::OCLPerfMapDispatchSpeed() { + testListSize = sizeof(mapTestList) / sizeof(unsigned int); + _numSubTests = 2 * testListSize; +} + +void OCLPerfMapDispatchSpeed::run(void) { + cl_mem outBuffer; + outBuffer = _wrapper->clCreateBuffer(context_, CL_MEM_ALLOC_HOST_PTR, + bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&outBuffer); + + int global = bufSize_ / sizeof(cl_float); + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + CPerfCounter timer; + + if (doWarmup) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue_); + } + + timer.Reset(); + timer.Start(); + void *mem; + for (unsigned int i = 0; i < mapTestList[_openTest]; i++) { + mem = _wrapper->clEnqueueMapBuffer(cmd_queue_, outBuffer, CL_TRUE, + CL_MAP_WRITE_INVALIDATE_REGION, 0, + bufSize_, 0, NULL, NULL, &error_); + + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, outBuffer, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapBuffer failed"); + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // microseconds per launch + double perf = (1000000.f * sec / mapTestList[_openTest]); + const char *warmup; + if (doWarmup) { + warmup = "warmup"; + } else { + warmup = ""; + } + + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " %7d maps and dispatches %6s (us/disp)", + mapTestList[_openTest], warmup); + testDescString = buf; + + _wrapper->clReleaseMemObject(outBuffer); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDispatchSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfDispatchSpeed.h new file mode 100644 index 0000000000..004b8dd35d --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDispatchSpeed.h @@ -0,0 +1,58 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_DispatchSpeed_H_ +#define _OCL_DispatchSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfDispatchSpeed : public OCLTestImp { + public: + OCLPerfDispatchSpeed(); + virtual ~OCLPerfDispatchSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void genShader(void); + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem outBuffer_; + cl_int error_; + bool doWarmup; + + unsigned int bufSize_; + bool sleep; + unsigned int testListSize; +}; + +class OCLPerfMapDispatchSpeed : public OCLPerfDispatchSpeed { + public: + OCLPerfMapDispatchSpeed(); + virtual void run(void); +}; +#endif // _OCL_DispatchSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDoubleDMA.cpp b/opencl/tests/ocltst/module/perf/OCLPerfDoubleDMA.cpp new file mode 100644 index 0000000000..a17dabe30f --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDoubleDMA.cpp @@ -0,0 +1,442 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfDoubleDMA.h" + +#include +#include +#include + +#include +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +const size_t blockX = 256; +const size_t blockY = 256; +const size_t blockZ = 512; + +const size_t chunk = 16; +const size_t size_S = blockX * blockY * blockZ * sizeof(cl_float4); +const size_t size_s = blockX * blockY * chunk * sizeof(cl_float4); +static const int WindowWidth = 80; + +const size_t MaxQueues = 3; +bool profEnable = false; + +static const char* strKernel = + "__kernel void dummy(__global float4* out) \n" + "{ \n" + " uint id = get_global_id(0); \n" + " float4 value = (float4)(1.0f, 2.0f, 3.0f, 4.0f); \n" + " uint factorial = 1; \n" + " for (uint i = 1; i < (id / 0x400); ++i)\n" + " { \n" + " factorial *= i; \n" + " } \n" + " out[id] = value * factorial; \n" + "} \n"; + +class ProfileQueue { + public: + enum Operation { Write = 0, Execute, Read, Total }; + + static const char* OperationName[Total]; + static const char StartCommand[Total]; + static const char ExecCommand[Total]; + + ProfileQueue() {} + ~ProfileQueue() { + for (size_t op = 0; op < Total; ++op) { + for (size_t idx = 0; idx < events_[op].size(); ++idx) { + clReleaseEvent(events_[op][idx]); + } + } + } + + void addEvent(Operation op, cl_event event) { events_[op].push_back(event); } + + void findMinMax(cl_long* min, cl_long* max) { + // Find time min/max ranges for the frame scaling + for (size_t op = 0; (op < ProfileQueue::Total); ++op) { + cl_long time; + if (events_[op].size() == 0) continue; + clGetEventProfilingInfo(events_[op][0], CL_PROFILING_COMMAND_START, + sizeof(cl_long), &time, NULL); + if (0 == *min) { + *min = time; + } else { + *min = std::min(*min, time); + } + clGetEventProfilingInfo(events_[op][events_[op].size() - 1], + CL_PROFILING_COMMAND_END, sizeof(cl_long), &time, + NULL); + if (0 == *max) { + *max = time; + } else { + *max = std::max(*max, time); + } + } + } + + void display(cl_long start, cl_long finish) { + std::string graph; + graph.resize(WindowWidth + 1); + graph[WindowWidth] = '\x0'; + cl_long timeFrame = finish - start; + cl_long interval = timeFrame / WindowWidth; + + // Find time min/max ranges for the frame scaling + for (size_t op = 0; (op < Total); ++op) { + if (events_[op].size() == 0) continue; + cl_long timeStart, timeEnd; + int begin = 0, end = 0; + for (size_t idx = 0; idx < events_[op].size(); ++idx) { + bool cutStart = false; + clGetEventProfilingInfo(events_[op][idx], CL_PROFILING_COMMAND_START, + sizeof(cl_long), &timeStart, NULL); + clGetEventProfilingInfo(events_[op][idx], CL_PROFILING_COMMAND_END, + sizeof(cl_long), &timeEnd, NULL); + + // Continue if out of the frame scope + if (timeStart >= finish) continue; + if (timeEnd <= start) continue; + + if (timeStart <= start) { + timeStart = start; + cutStart = true; + } + + if (timeEnd >= finish) { + timeEnd = finish; + } + + // Readjust time to the frame + timeStart -= start; + timeEnd -= start; + timeStart = static_cast( + floor(static_cast(timeStart) / interval + 0.5f)); + timeEnd = static_cast( + floor(static_cast(timeEnd) / interval + 0.5f)); + begin = static_cast(timeStart); + // Idle from end to begin + for (int c = end; c < begin; ++c) { + graph[c] = '-'; + } + end = static_cast(timeEnd); + for (int c = begin; c < end; ++c) { + if ((c == begin) && !cutStart) { + graph[c] = StartCommand[op]; + } else { + graph[c] = ExecCommand[op]; + } + } + if ((begin == end) && (end < WindowWidth)) { + graph[begin] = '+'; + } + } + if (end < WindowWidth) { + for (int c = end; c < WindowWidth; ++c) { + graph[c] = '-'; + } + } + printf("%s\n", graph.c_str()); + } + } + + private: + // Profiling events + std::vector events_[Total]; +}; + +const char* ProfileQueue::OperationName[Total] = { + "BufferWrite", "KernelExecution", "BufferRead"}; +const char ProfileQueue::StartCommand[Total] = {'W', 'X', 'R'}; +const char ProfileQueue::ExecCommand[Total] = {'>', '#', '<'}; + +class Profile { + public: + Profile(bool profEna, int numQueues) + : profileEna_(profEna), + numQueues_(numQueues), + min_(0), + max_(0), + execTime_(0) {} + + ~Profile() {} + + void addEvent(int queue, ProfileQueue::Operation op, cl_event event) { + if (profileEna_) { + profQueue[queue].addEvent(op, event); + } + } + + cl_long findExecTime() { + if (execTime_ != 0) return execTime_; + for (int q = 0; q < numQueues_; ++q) { + profQueue[q].findMinMax(&min_, &max_); + } + execTime_ = max_ - min_; + return execTime_; + } + + void display(cl_long start, cl_long finish) { + if (!profileEna_) return; + printf("\n ----------- Time frame %.3f (us), scale 1:%.0f\n", + (float)(finish - start) / 1000, + (float)(finish - start) / (1000 * WindowWidth)); + for (size_t op = 0; (op < ProfileQueue::Total); ++op) { + printf("%s - %c%c; ", ProfileQueue::OperationName[op], + ProfileQueue::StartCommand[op], ProfileQueue::ExecCommand[op]); + } + printf("\n"); + for (int q = 0; q < numQueues_; ++q) { + printf("CommandQueue #%d\n", q); + profQueue[q].display(min_ + start, min_ + finish); + } + } + + private: + bool profileEna_; + int numQueues_; //!< Total number of queues + cl_long min_; //!< Min HW timestamp + cl_long max_; //!< Max HW timestamp + cl_long execTime_; //!< Profile time + ProfileQueue profQueue[MaxQueues]; +}; + +OCLPerfDoubleDMA::OCLPerfDoubleDMA() { + _numSubTests = 2 * MaxQueues * 2; + failed_ = false; +} + +OCLPerfDoubleDMA::~OCLPerfDoubleDMA() {} + +void OCLPerfDoubleDMA::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + _deviceId = deviceId; + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + test_ = test; + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + kernel_ = _wrapper->clCreateKernel(program_, "dummy", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + size_t bufSize = size_s; + cl_mem buffer; + if (test_ >= (2 * MaxQueues)) { + profEnable = true; + } + test_ %= 2 * MaxQueues; + size_t numBufs = (test_ % MaxQueues) + 1; + for (size_t b = 0; b < numBufs; ++b) { + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, bufSize, + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + } + + buffer = _wrapper->clCreateBuffer(context_, + CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR, + size_S, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLPerfDoubleDMA::run(void) { + if (failed_) { + return; + } + CPerfCounter timer; + const int numQueues = (test_ % MaxQueues) + 1; + const bool useKernel = ((test_ / MaxQueues) > 0); + const int numBufs = numQueues; + Profile profile(profEnable, numQueues); + + std::vector cmdQueues(numQueues); + int q; + cl_command_queue_properties qProp = + (profEnable) ? CL_QUEUE_PROFILING_ENABLE : 0; + for (q = 0; q < numQueues; ++q) { + cl_command_queue cmdQueue = _wrapper->clCreateCommandQueue( + context_, devices_[_deviceId], qProp, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueue() failed"); + cmdQueues[q] = cmdQueue; + } + + float* Data_s = (float*)_wrapper->clEnqueueMapBuffer( + cmdQueues[0], buffers_[numBufs], CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, + size_S, 0, NULL, NULL, &error_); + + size_t gws[1] = {size_s / (4 * sizeof(float))}; + size_t lws[1] = {256}; + + // Warm-up + for (q = 0; q < numQueues; ++q) { + error_ |= + _wrapper->clEnqueueWriteBuffer(cmdQueues[q], buffers_[q], CL_FALSE, 0, + size_s, (char*)Data_s, 0, NULL, NULL); + error_ |= _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void*)&buffers_[q]); + error_ |= _wrapper->clEnqueueNDRangeKernel(cmdQueues[q], kernel_, 1, NULL, + gws, lws, 0, NULL, NULL); + error_ |= + _wrapper->clEnqueueReadBuffer(cmdQueues[q], buffers_[q], CL_FALSE, 0, + size_s, (char*)Data_s, 0, NULL, NULL); + error_ |= _wrapper->clFinish(cmdQueues[q]); + } + + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), "Execution failed"); + + size_t s_done = 0; + cl_event r[MaxQueues] = {0}, w[MaxQueues] = {0}, x[MaxQueues] = {0}; + + /*---------- pass2: copy Data_s to and from GPU Buffers ----------*/ + s_done = 0; + timer.Reset(); + timer.Start(); + int idx = numBufs - 1; + // Start from the last so read/write won't go to the same DMA when kernel is + // executed + q = numQueues - 1; + size_t iter = 0; + while (1) { + if (0 == r[idx]) { + error_ |= _wrapper->clEnqueueWriteBuffer( + cmdQueues[q], buffers_[idx], CL_FALSE, 0, size_s, + (char*)Data_s + s_done, 0, NULL, &w[idx]); + } else { + error_ |= _wrapper->clEnqueueWriteBuffer( + cmdQueues[q], buffers_[idx], CL_FALSE, 0, size_s, + (char*)Data_s + s_done, 1, &r[idx], &w[idx]); + if (!profEnable) { + error_ |= _wrapper->clReleaseEvent(r[idx]); + } + } + _wrapper->clFlush(cmdQueues[q]); + profile.addEvent(q, ProfileQueue::Write, w[idx]); + + if (useKernel) { + // Change the queue + ++q %= numQueues; + // Implicit flush of DMA engine on kernel start, because memory dependency + error_ |= _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void*)&buffers_[idx]); + error_ |= _wrapper->clEnqueueNDRangeKernel(cmdQueues[q], kernel_, 1, NULL, + gws, lws, 1, &w[idx], &x[idx]); + if (!profEnable) { + error_ |= _wrapper->clReleaseEvent(w[idx]); + } + profile.addEvent(q, ProfileQueue::Execute, x[idx]); + } + _wrapper->clFlush(cmdQueues[q]); + + // Change the queue + ++q %= numQueues; + error_ |= _wrapper->clEnqueueReadBuffer( + cmdQueues[q], buffers_[idx], CL_FALSE, 0, size_s, + (char*)Data_s + s_done, 1, (useKernel) ? &x[idx] : &w[idx], &r[idx]); + if (!profEnable) { + error_ |= _wrapper->clReleaseEvent((useKernel) ? x[idx] : w[idx]); + } + profile.addEvent(q, ProfileQueue::Read, r[idx]); + _wrapper->clFlush(cmdQueues[q]); + + if ((s_done += size_s) >= size_S) { + if (!profEnable) { + error_ |= _wrapper->clReleaseEvent(r[idx]); + } + break; + } + ++iter; + ++idx %= numBufs; + ++q %= numQueues; + } + + for (q = 0; q < numQueues; ++q) { + error_ |= _wrapper->clFinish(cmdQueues[q]); + } + timer.Stop(); + + error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues[0], buffers_[numBufs], + Data_s, 0, NULL, NULL); + + error_ |= _wrapper->clFinish(cmdQueues[0]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), "Execution failed"); + + cl_long gpuTimeFrame = profile.findExecTime(); + cl_long oneIter = gpuTimeFrame / iter; + + // Display 4 iterations in the middle + cl_long startFrame = oneIter * (iter / 2 - 2); + cl_long finishFrame = oneIter * (iter / 2 + 2); + profile.display(startFrame, finishFrame); + + for (q = 0; q < numQueues; ++q) { + error_ = _wrapper->clReleaseCommandQueue(cmdQueues[q]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseCommandQueue() failed"); + } + + double GBytes = (double)(2 * size_S) / (double)(1000 * 1000 * 1000); + _perfInfo = static_cast(GBytes / timer.GetElapsedTime()); + + std::stringstream stream; + if (useKernel) { + stream << "Write/Kernel/Read operation "; + } else { + stream << "Write/Read operation "; + } + stream << numQueues << " queues; profiling " + << ((profEnable) ? "enabled" : "disabled") << " [GB/s]"; + + stream.flags(std::ios::right | std::ios::showbase); + testDescString = stream.str(); +} + +unsigned int OCLPerfDoubleDMA::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDoubleDMA.h b/opencl/tests/ocltst/module/perf/OCLPerfDoubleDMA.h new file mode 100644 index 0000000000..69a86685f1 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDoubleDMA.h @@ -0,0 +1,42 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_DOUBLE_DMA_H_ +#define _OCL_PERF_DOUBLE_DMA_H_ + +#include "OCLTestImp.h" + +class OCLPerfDoubleDMA : public OCLTestImp { + public: + OCLPerfDoubleDMA(); + virtual ~OCLPerfDoubleDMA(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; + unsigned int test_; +}; + +#endif // _OCL_PERF_DOUBLE_DMA_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDoubleDMASeq.cpp b/opencl/tests/ocltst/module/perf/OCLPerfDoubleDMASeq.cpp new file mode 100644 index 0000000000..97ed414939 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDoubleDMASeq.cpp @@ -0,0 +1,291 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfDoubleDMASeq.h" + +#include +#include +#include + +#include +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +#ifdef _WIN32 +const size_t blockX = 128; +const size_t blockY = 128; +const size_t blockZ = 256; +#else +const size_t blockX = 256; +const size_t blockY = 256; +const size_t blockZ = 512; +#endif + +const size_t chunk = 16; +const size_t size_S = blockX * blockY * blockZ * sizeof(cl_float4); +const size_t size_s = blockX * blockY * chunk * sizeof(cl_float4); +static const int WindowWidth = 80; + +const size_t MaxQueues = 3; + +static const char *strKernel = + "__kernel void dummy(__global float4* out) \n" + "{ \n" + " uint id = get_global_id(0); \n" + " float4 value = (float4)(1.0f, 2.0f, 3.0f, 4.0f); \n" + " uint factorial = 1; \n" + " for (uint i = 1; i < (id / 0x400); ++i)\n" + " { \n" + " factorial *= i; \n" + " } \n" + " out[id] = value * factorial; \n" + "} \n"; + +OCLPerfDoubleDMASeq::OCLPerfDoubleDMASeq() { + _numSubTests = MaxQueues * 2; + failed_ = false; +} + +OCLPerfDoubleDMASeq::~OCLPerfDoubleDMASeq() {} + +void OCLPerfDoubleDMASeq::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + _deviceId = deviceId; + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + test_ = test; + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + kernel_ = _wrapper->clCreateKernel(program_, "dummy", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + size_t bufSize = size_s; + cl_mem buffer; + test_ %= MaxQueues; + events_ = ((test / MaxQueues) == 0) ? false : true; + size_t numBufs = (test_ % MaxQueues) + 1; + for (size_t b = 0; b < numBufs; ++b) { + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, bufSize, + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + } + + buffer = _wrapper->clCreateBuffer(context_, + CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR, + size_S, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfDoubleDMASeq::run(void) { + if (failed_) { + return; + } + CPerfCounter timer; + const int numQueues = (test_ % MaxQueues) + 1; + const int numBufs = numQueues; + + std::vector cmdQueues(numQueues); + int q; + cl_command_queue_properties qProp = 0; + for (q = 0; q < numQueues; ++q) { + cl_command_queue cmdQueue = _wrapper->clCreateCommandQueue( + context_, devices_[_deviceId], qProp, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueue() failed"); + cmdQueues[q] = cmdQueue; + } + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), "Execution failed"); + + float *Data_s = (float *)_wrapper->clEnqueueMapBuffer( + cmdQueues[0], buffers_[numBufs], CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, + size_S, 0, NULL, NULL, &error_); + + size_t gws[1] = {size_s / (4 * sizeof(float))}; + size_t lws[1] = {256}; + + // Warm-up + for (q = 0; q < numQueues; ++q) { + error_ |= + _wrapper->clEnqueueWriteBuffer(cmdQueues[q], buffers_[q], CL_FALSE, 0, + size_s, (char *)Data_s, 0, NULL, NULL); + error_ |= _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&buffers_[q]); + error_ |= _wrapper->clEnqueueNDRangeKernel(cmdQueues[q], kernel_, 1, NULL, + gws, lws, 0, NULL, NULL); + error_ |= + _wrapper->clEnqueueReadBuffer(cmdQueues[q], buffers_[q], CL_FALSE, 0, + size_s, (char *)Data_s, 0, NULL, NULL); + error_ |= _wrapper->clFinish(cmdQueues[q]); + } + + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), "Execution failed"); + + size_t s_done = 0; + cl_event x[MaxQueues] = {0}; + + /*---------- pass2: copy Data_s to and from GPU Buffers ----------*/ + s_done = 0; + timer.Reset(); + timer.Start(); + int idx = numBufs - 1; + // Start from the last so read/write won't go to the same DMA when kernel is + // executed + q = numQueues - 1; + size_t iter = 0; + if (events_) { + while (1) { + error_ |= _wrapper->clEnqueueWriteBuffer( + cmdQueues[q], buffers_[idx], CL_FALSE, 0, size_s, + (char *)Data_s + s_done, 0, NULL, NULL); + + // Implicit flush of DMA engine on kernel start, because memory dependency + error_ |= _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&buffers_[idx]); + int prevQ; + if (q == 0) { + prevQ = numQueues - 1; + } else { + prevQ = q - 1; + } + if ((x[prevQ] != NULL) && (numQueues != 1)) { + error_ |= _wrapper->clEnqueueNDRangeKernel( + cmdQueues[q], kernel_, 1, NULL, gws, lws, 1, &x[prevQ], &x[q]); + error_ |= _wrapper->clReleaseEvent(x[prevQ]); + x[prevQ] = NULL; + } else { + error_ |= _wrapper->clEnqueueNDRangeKernel( + cmdQueues[q], kernel_, 1, NULL, gws, lws, 0, NULL, &x[q]); + if (numQueues == 1) { + error_ |= _wrapper->clReleaseEvent(x[q]); + x[q] = NULL; + } + } + error_ |= _wrapper->clFlush(cmdQueues[q]); + + // Change the queue + error_ |= _wrapper->clEnqueueReadBuffer( + cmdQueues[q], buffers_[idx], CL_FALSE, 0, size_s, + (char *)Data_s + s_done, 0, NULL, NULL); + + if ((s_done += size_s) >= size_S) { + break; + } + + error_ |= _wrapper->clFlush(cmdQueues[q]); + ++iter; + ++idx %= numBufs; + ++q %= numQueues; + } + for (q = 0; q < numQueues; ++q) { + if (x[q] != NULL) { + error_ |= _wrapper->clReleaseEvent(x[q]); + } + } + } else { + while (1) { + error_ |= _wrapper->clEnqueueWriteBuffer( + cmdQueues[q], buffers_[idx], CL_FALSE, 0, size_s, + (char *)Data_s + s_done, 0, NULL, NULL); + + // Implicit flush of DMA engine on kernel start, because memory dependency + error_ |= _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&buffers_[idx]); + error_ |= _wrapper->clEnqueueNDRangeKernel(cmdQueues[q], kernel_, 1, NULL, + gws, lws, 0, NULL, NULL); + + // Change the queue + error_ |= _wrapper->clEnqueueReadBuffer( + cmdQueues[q], buffers_[idx], CL_FALSE, 0, size_s, + (char *)Data_s + s_done, 0, NULL, NULL); + + if ((s_done += size_s) >= size_S) { + break; + } + + error_ |= _wrapper->clFlush(cmdQueues[q]); + ++iter; + ++idx %= numBufs; + ++q %= numQueues; + } + } + + for (q = 0; q < numQueues; ++q) { + error_ |= _wrapper->clFinish(cmdQueues[q]); + } + timer.Stop(); + + error_ |= _wrapper->clEnqueueUnmapMemObject(cmdQueues[0], buffers_[numBufs], + Data_s, 0, NULL, NULL); + + error_ |= _wrapper->clFinish(cmdQueues[0]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), "Execution failed"); + + for (q = 0; q < numQueues; ++q) { + error_ = _wrapper->clReleaseCommandQueue(cmdQueues[q]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseCommandQueue() failed"); + } + + double GBytes = (double)(2 * size_S) / (double)(1000 * 1000 * 1000); + _perfInfo = static_cast(GBytes / timer.GetElapsedTime()); + + std::stringstream stream; + stream << "Write/Kernel/Read operation "; + + stream << numQueues << " queues "; + if (events_) { + stream << " (use events) "; + } + stream << " [GB/s]"; + + stream.flags(std::ios::right | std::ios::showbase); + testDescString = stream.str(); +} + +unsigned int OCLPerfDoubleDMASeq::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/perf/OCLPerfDoubleDMASeq.h b/opencl/tests/ocltst/module/perf/OCLPerfDoubleDMASeq.h new file mode 100644 index 0000000000..cef6eb77b7 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfDoubleDMASeq.h @@ -0,0 +1,43 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_DOUBLE_DMA_SEQ_H_ +#define _OCL_PERF_DOUBLE_DMA_SEQ_H_ + +#include "OCLTestImp.h" + +class OCLPerfDoubleDMASeq : public OCLTestImp { + public: + OCLPerfDoubleDMASeq(); + virtual ~OCLPerfDoubleDMASeq(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; + unsigned int test_; + bool events_; +}; + +#endif // _OCL_PERF_DOUBLE_DMA_SEQ_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfFillBuffer.cpp b/opencl/tests/ocltst/module/perf/OCLPerfFillBuffer.cpp new file mode 100644 index 0000000000..aaf7465da6 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfFillBuffer.cpp @@ -0,0 +1,114 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfFillBuffer.h" + +#include +#include +#include + +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +static size_t typeSizeList[] = { + 1, // sizeof(cl_uchar) + 2, 4, 8, 16, 32, 64, + 128, // sizeof(cl_ulong16) +}; + +static unsigned int eleNumList[] = { + 0x0020000, 0x0080000, 0x0200000, 0x0800000, 0x2000000, +}; + +OCLPerfFillBuffer::OCLPerfFillBuffer() { + num_typeSize_ = sizeof(typeSizeList) / sizeof(size_t); + num_elements_ = sizeof(eleNumList) / sizeof(unsigned int); + _numSubTests = num_elements_ * num_typeSize_; + failed_ = false; + skip_ = false; +} + +OCLPerfFillBuffer::~OCLPerfFillBuffer() {} + +void OCLPerfFillBuffer::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + testTypeSize_ = typeSizeList[(test / num_elements_) % num_typeSize_]; + testNumEle_ = eleNumList[test % num_elements_]; + + bufSize_ = testNumEle_ * 4; + + buffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, bufSize_, 0, + &error_); + CHECK_RESULT(buffer_ == 0, "clCreateBuffer(buffer_) failed"); + + return; +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfFillBuffer::run(void) { + CPerfCounter timer; + size_t iter = 100; + + void *data = malloc(testTypeSize_); + + timer.Reset(); + timer.Start(); + for (size_t i = 0; i < iter; ++i) { + error_ = clEnqueueFillBuffer(cmdQueues_[_deviceId], buffer_, data, + testTypeSize_, 0, bufSize_, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueFillBuffer() failed"); + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + timer.Stop(); + + char buf[256]; + + SNPRINTF(buf, sizeof(buf), "FillBuffer (GB/s) for %6d KB, typeSize:%3d", + (int)bufSize_ / 1024, (int)testTypeSize_); + + testDescString = buf; + double sec = timer.GetElapsedTime(); + _perfInfo = static_cast((bufSize_ * iter * (double)(1e-09)) / sec); +} + +unsigned int OCLPerfFillBuffer::close(void) { + if (buffer_) { + error_ = _wrapper->clReleaseMemObject(buffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(buffer) failed"); + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfFillBuffer.h b/opencl/tests/ocltst/module/perf/OCLPerfFillBuffer.h new file mode 100644 index 0000000000..3eb99dbdf8 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfFillBuffer.h @@ -0,0 +1,48 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_FILL_BUFFER_H_ +#define _OCL_PERF_FILL_BUFFER_H_ + +#include "OCLTestImp.h" + +class OCLPerfFillBuffer : public OCLTestImp { + public: + OCLPerfFillBuffer(); + virtual ~OCLPerfFillBuffer(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + cl_mem buffer_; + unsigned int bufSize_; + unsigned int num_typeSize_; + unsigned int num_elements_; + size_t testTypeSize_; + unsigned int testNumEle_; + bool failed_; + bool skip_; +}; + +#endif // _OCL_PERF_FILL_BUFFER_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfFillImage.cpp b/opencl/tests/ocltst/module/perf/OCLPerfFillImage.cpp new file mode 100644 index 0000000000..bc43bd8318 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfFillImage.cpp @@ -0,0 +1,109 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfFillImage.h" + +#include +#include +#include + +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +static unsigned int sizeList[] = { + 256, 512, 1024, 2048, 4096, 8192, +}; + +OCLPerfFillImage::OCLPerfFillImage() { + num_sizes_ = sizeof(sizeList) / sizeof(unsigned int); + _numSubTests = num_sizes_; + failed_ = false; + skip_ = false; +} + +OCLPerfFillImage::~OCLPerfFillImage() {} + +void OCLPerfFillImage::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + bufSize_ = sizeList[test % num_sizes_]; + + cl_image_format format = {CL_RGBA, CL_UNSIGNED_INT8}; + buffer_ = _wrapper->clCreateImage2D(context_, CL_MEM_WRITE_ONLY, &format, + bufSize_, bufSize_, 0, NULL, &error_); + CHECK_RESULT(buffer_ == 0, "clCreateImage2D(imageBuffer_) failed"); + + return; +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfFillImage::run(void) { + CPerfCounter timer; + size_t iter = 100; + + cl_uint4 fillColor = {1, 1, 1, 1}; + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSize_, bufSize_, 1}; + + timer.Reset(); + timer.Start(); + for (size_t i = 0; i < iter; ++i) { + error_ = clEnqueueFillImage(cmdQueues_[_deviceId], buffer_, + (const void *)&fillColor, origin, region, 0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueFillImage() failed"); + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + timer.Stop(); + + char buf[256]; + + SNPRINTF(buf, sizeof(buf), "FillImage (GB/s) for %4dx%4d ", (int)bufSize_, + (int)bufSize_); + + testDescString = buf; + double sec = timer.GetElapsedTime(); + _perfInfo = static_cast( + (bufSize_ * bufSize_ * 4 * iter * (double)(1e-09)) / sec); +} + +unsigned int OCLPerfFillImage::close(void) { + if (buffer_) { + error_ = _wrapper->clReleaseMemObject(buffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(buffer) failed"); + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfFillImage.h b/opencl/tests/ocltst/module/perf/OCLPerfFillImage.h new file mode 100644 index 0000000000..c5a33de6fe --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfFillImage.h @@ -0,0 +1,45 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_FILL_IMAGE_H_ +#define _OCL_PERF_FILL_IMAGE_H_ + +#include "OCLTestImp.h" + +class OCLPerfFillImage : public OCLTestImp { + public: + OCLPerfFillImage(); + virtual ~OCLPerfFillImage(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + cl_mem buffer_; + unsigned int bufSize_; + unsigned int num_sizes_; + bool failed_; + bool skip_; +}; + +#endif // _OCL_PERF_FILL_IMAGE_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfFlush.cpp b/opencl/tests/ocltst/module/perf/OCLPerfFlush.cpp new file mode 100644 index 0000000000..77534838f8 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfFlush.cpp @@ -0,0 +1,165 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfFlush.h" + +#include +#include +#include + +#include +#include + +#include "CL/cl.h" + +static const cl_uint Iterations = 0x10000; +static const cl_uint IterationDivider = 2; +static const size_t MaxBuffers = IterationDivider; +static size_t BufSize = 0x1000; + +const static char* strKernel = + "__kernel void factorial(__global uint* out) \n" + "{ \n" + " uint id = get_global_id(0); \n" + " uint factorial = 1; \n" + " for (uint i = 1; i < (id / 0x10000); ++i) \n" + " { \n" + " factorial *= i; \n" + " } \n" + " out[id] = factorial; \n" + "} \n"; + +unsigned int NumTests = 3; + +OCLPerfFlush::OCLPerfFlush() { + _numSubTests = NumTests; + failed_ = false; +} + +OCLPerfFlush::~OCLPerfFlush() {} + +void OCLPerfFlush::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + test_ = test; + + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + size_t maxWorkGroupSize = 1; + cl_uint computePower = 1; + error_ = _wrapper->clGetDeviceInfo( + devices_[deviceId], CL_DEVICE_MAX_WORK_GROUP_SIZE, + sizeof(maxWorkGroupSize), &maxWorkGroupSize, NULL); + computePower *= static_cast(maxWorkGroupSize); + cl_uint maxComputeUnits = 1; + error_ = _wrapper->clGetDeviceInfo( + devices_[deviceId], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(maxComputeUnits), + &maxComputeUnits, NULL); + computePower *= 32 * maxComputeUnits; + BufSize = (BufSize < static_cast(computePower)) + ? static_cast(computePower) + : BufSize; + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + kernel_ = _wrapper->clCreateKernel(program_, "factorial", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + for (size_t i = 0; i < MaxBuffers; ++i) { + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + BufSize * sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + } +} + +void OCLPerfFlush::run(void) { + if (failed_) { + return; + } + for (size_t y = 0; y < IterationDivider; ++y) { + cl_mem buffer = buffers()[y]; + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t gws[1] = {BufSize}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + + CPerfCounter timer; + const char* descriptions[] = { + "Single batch: ", "clFlush(): ", "clFinish(): "}; + + timer.Reset(); + timer.Start(); + cl_uint x; + for (x = 0; x < Iterations / IterationDivider; x++) { + for (size_t y = 0; y < IterationDivider; ++y) { + cl_mem buffer = buffers()[y]; + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t gws[1] = {BufSize}; + error_ = _wrapper->clEnqueueNDRangeKernel( + cmdQueues_[_deviceId], kernel_, 1, NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + if (test_ == 1) { + _wrapper->clFlush(cmdQueues_[_deviceId]); + } else if (test_ == 2) { + _wrapper->clFinish(cmdQueues_[_deviceId]); + } + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + timer.Stop(); + + std::stringstream stream; + stream << "Loop[" << std::hex << Iterations << "], " << descriptions[test_]; + stream << "(sec)"; + testDescString = stream.str(); + _perfInfo = static_cast(timer.GetElapsedTime()); +} + +unsigned int OCLPerfFlush::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/perf/OCLPerfFlush.h b/opencl/tests/ocltst/module/perf/OCLPerfFlush.h new file mode 100644 index 0000000000..593663c638 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfFlush.h @@ -0,0 +1,42 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_FLUSH_H_ +#define _OCL_PERF_FLUSH_H_ + +#include "OCLTestImp.h" + +class OCLPerfFlush : public OCLTestImp { + public: + OCLPerfFlush(); + virtual ~OCLPerfFlush(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; + unsigned int test_; +}; + +#endif // _OCL_PERF_FLUSH_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfGenericBandwidth.cpp b/opencl/tests/ocltst/module/perf/OCLPerfGenericBandwidth.cpp new file mode 100644 index 0000000000..329d83e40c --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfGenericBandwidth.cpp @@ -0,0 +1,309 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfGenericBandwidth.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 4 +// 256KB, 1 MB, 4MB, 16 MB +static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304, + 16777216}; + +void OCLPerfGenericBandwidth::genShader(unsigned int idx) { + shader_.clear(); + if (idx == 0) { + shader_ += + "__kernel __attribute__((reqd_work_group_size(64,1,1))) void " + "_genericReadSpeed(global float *outBuf, global float *inBuf, local " + "float *inLocal, float c, char useLocal)\n" + "{\n" + " int gid = (int) get_global_id(0);\n" + " int lid = (int) get_local_id(0);\n" + " float val0 = 0.0f;\n" + " float val1 = 0.0f;\n" + " float *localLocal;\n" + " int hacklid = gid % 64;\n" + " if (useLocal)\n" + " localLocal = inLocal;\n" + " else\n" + " localLocal = inBuf;\n" + " for (int i = 0; i < (768/64); i++) {\n" + " localLocal[hacklid + i*64] = lid;\n" + " }\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + "#pragma nounroll\n" + " for (uint i = 0; i < 32;i++)\n" + " {\n" + " val0 += localLocal[lid+0];\n" + " val1 += localLocal[lid+64];\n" + " val0 += localLocal[lid+128];\n" + " val1 += localLocal[lid+192];\n" + " val0 += localLocal[lid+256];\n" + " val1 += localLocal[lid+320];\n" + " val0 += localLocal[lid+384];\n" + " val1 += localLocal[lid+448];\n" + " lid += 1;\n" + " }\n" + " val0 += val1;\n" + " val1 = min(val0,1.0f);\n" + " if ((lid + val1) < 0){\n" + " outBuf[gid] = val0;\n" + " }\n" + "}\n"; + dataSizeBytes_ = 768 * 4; + } else { + shader_ += + "__kernel __attribute__((reqd_work_group_size(64,1,1))) void " + "_genericReadSpeed(global float *outBuf, global float *inBuf, local " + "float *inLocal, float c, char useLocal)\n" + "{\n" + " uint gid = (uint) get_global_id(0);\n" + " int lid = (int) get_local_id(0);\n" + " float val0 = 0.0f;\n" + " float val1 = 0.0f;\n" + " float *localLocal;\n" + " uint hacklid = gid % 64;\n" + " if (useLocal)\n" + " localLocal = inLocal;\n" + " else\n" + " localLocal = inBuf;\n" + " for (int i = 0; i < (256/64); i++) {\n" + " localLocal[hacklid + i*64] = lid;\n" + " }\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + " #pragma nounroll\n" + " for (uint i = 0; i < 32;i++)\n" + " {\n" + " val0 += localLocal[8*i+0];\n" + " val1 += localLocal[8*i+1];\n" + " val0 += localLocal[8*i+2];\n" + " val1 += localLocal[8*i+3];\n" + " val0 += localLocal[8*i+4];\n" + " val1 += localLocal[8*i+5];\n" + " val0 += localLocal[8*i+6];\n" + " val1 += localLocal[8*i+7];\n" + " }\n" + " val0 += val1;\n" + " val1 = min(val0,1.0f);\n" + " if ((lid + val1) < 0){\n" + " outBuf[gid] = val0;\n" + " }\n" + "}\n"; + dataSizeBytes_ = 256 * 4; + } +} + +OCLPerfGenericBandwidth::OCLPerfGenericBandwidth() { + _numSubTests = NUM_SIZES * 4; +} + +OCLPerfGenericBandwidth::~OCLPerfGenericBandwidth() {} + +void OCLPerfGenericBandwidth::setData(cl_mem buffer, float val) { + float *data = (float *)_wrapper->clEnqueueMapBuffer( + cmdQueues_[_deviceId], buffer, true, CL_MAP_WRITE, 0, bufSize_, 0, NULL, + NULL, &error_); + for (unsigned int i = 0; i < (bufSize_ >> 2); i++) data[i] = val; + error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], buffer, + data, 0, NULL, NULL); + _wrapper->clFinish(cmdQueues_[_deviceId]); +} + +void OCLPerfGenericBandwidth::checkData(cl_mem buffer) { + float *data = (float *)_wrapper->clEnqueueMapBuffer( + cmdQueues_[_deviceId], buffer, true, CL_MAP_READ, 0, bufSize_, 0, NULL, + NULL, &error_); + for (unsigned int i = 0; i < (bufSize_ >> 2); i++) { + if (data[i] != (float)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, numReads_, + numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], buffer, + data, 0, NULL, NULL); + _wrapper->clFinish(cmdQueues_[_deviceId]); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfGenericBandwidth::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + _crcword = 0; + conversion = 1.0f; + + failed = false; + kernel_ = 0; + inBuffer_ = 0; + outBuffer_ = 0; + useLDS_ = ((test / NUM_SIZES) % 2) == 0 ? 1 : 0; + + size_t param_size = 0; + char *strVersion = 0; + error_ = _wrapper->clGetDeviceInfo( + devices_[_deviceId], CL_DEVICE_OPENCL_C_VERSION, 0, 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = + _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_OPENCL_C_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[9] < '2') { + failed = true; + return; + } + delete strVersion; + + numReads_ = 32; + width_ = Sizes[test % NUM_SIZES]; + shaderIdx_ = test / (NUM_SIZES * 2); + + bufSize_ = width_; + + inBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(inBuffer_ == 0, "clCreateBuffer(inBuffer) failed"); + + outBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + genShader(shaderIdx_); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "_genericReadSpeed", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + float foo = 0; + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&outBuffer_); + error_ = + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), (void *)&inBuffer_); + error_ = _wrapper->clSetKernelArg(kernel_, 2, 1024 * sizeof(cl_float), + (void *)NULL); + error_ = _wrapper->clSetKernelArg(kernel_, 3, sizeof(cl_float), (void *)&foo); + error_ = + _wrapper->clSetKernelArg(kernel_, 4, sizeof(cl_char), (void *)&useLDS_); + + setData(outBuffer_, 1.2345678f); +} + +void OCLPerfGenericBandwidth::run(void) { + if (failed) return; + int global = bufSize_ / sizeof(cl_float); + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < NUM_ITER; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmdQueues_[_deviceId], kernel_, 1, NULL, + (const size_t *)global_work_size, (const size_t *)local_work_size, 0, + NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + char buf[256]; + const char *buf2; + if (useLDS_) + buf2 = "LDS"; + else + buf2 = "global"; + const char *buf3; + if (shaderIdx_ == 0) { + buf3 = "reads"; + numReads_ *= 8; + } else { + buf3 = "broadcast"; + numReads_ *= 8; + } + // LDS bandwidth in GB/s + // We have one extra write per LDS location to initialize LDS + double perf = + ((double)global * (numReads_ * sizeof(cl_float) + dataSizeBytes_ / 64) * + NUM_ITER * (double)(1e-09)) / + sec; + + _perfInfo = (float)perf; + SNPRINTF(buf, sizeof(buf), " %6s %9s %8d threads, %3d reads (GB/s) ", buf2, + buf3, global, numReads_); + testDescString = buf; + // checkData(outBuffer_); +} + +unsigned int OCLPerfGenericBandwidth::close(void) { + if (inBuffer_) { + error_ = _wrapper->clReleaseMemObject(inBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfGenericBandwidth.h b/opencl/tests/ocltst/module/perf/OCLPerfGenericBandwidth.h new file mode 100644 index 0000000000..03b9f75ac1 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfGenericBandwidth.h @@ -0,0 +1,57 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GenericBandwidth_H_ +#define _OCL_GenericBandwidth_H_ + +#include "OCLTestImp.h" + +class OCLPerfGenericBandwidth : public OCLTestImp { + public: + OCLPerfGenericBandwidth(); + virtual ~OCLPerfGenericBandwidth(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void genShader(unsigned int idx); + void setData(cl_mem buffer, float data); + void checkData(cl_mem buffer); + + static const unsigned int NUM_ITER = 100; + + cl_mem inBuffer_; + cl_mem outBuffer_; + + unsigned int width_; + unsigned int bufSize_; + unsigned int vecSizeIdx_; + unsigned int numReads_; + unsigned int shaderIdx_; + unsigned int dataSizeBytes_; + cl_char useLDS_; + bool failed; +}; + +#endif // _OCL_GenericBandwidth_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfGenoilSiaMiner.cpp b/opencl/tests/ocltst/module/perf/OCLPerfGenoilSiaMiner.cpp new file mode 100644 index 0000000000..1de4719f26 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfGenoilSiaMiner.cpp @@ -0,0 +1,429 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfGenoilSiaMiner.h" + +#include +#include +#include + +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_INTENSITY 15 + +static const unsigned int intensities[NUM_INTENSITY] = { + DEFAULT_INTENSITY, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31}; + +static const char *siaKernel = + " inline static uint2 ror64(const uint2 x, const uint y) " + " \n" + " { " + " \n" + " return " + "(uint2)(((x).x>>y)^((x).y<<(32-y)),((x).y>>y)^((x).x<<(32-y))); " + " \n" + " } " + " \n" + " inline static uint2 ror64_2(const uint2 x, const uint y) " + " \n" + " { " + " \n" + " return " + "(uint2)(((x).y>>(y-32))^((x).x<<(64-y)),((x).x>>(y-32))^((x).y<<(64-y))); " + " \n" + " } " + " \n" + " __constant static const uchar blake2b_sigma[12][16] = { " + " \n" + " { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } " + ", \n" + " { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } " + ", \n" + " { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } " + ", \n" + " { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } " + ", \n" + " { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } " + ", \n" + " { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } " + ", \n" + " { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } " + ", \n" + " { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } " + ", \n" + " { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } " + ", \n" + " { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 } " + ", \n" + " { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } " + ", \n" + " { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } " + "}; \n" + " // Target is passed in via headerIn[32 - 29] " + " \n" + " __kernel void nonceGrind(__global ulong *headerIn, __global ulong " + "*nonceOut) { \n" + " ulong target = headerIn[4]; " + " \n" + " ulong m[16] = { headerIn[0], headerIn[1], " + " \n" + " headerIn[2], headerIn[3], " + " \n" + " (ulong)get_global_id(0), headerIn[5], " + " \n" + " headerIn[6], headerIn[7], " + " \n" + " headerIn[8], headerIn[9], 0, 0, 0, 0, 0, 0 }; " + " \n" + " ulong v[16] = { 0x6a09e667f2bdc928, 0xbb67ae8584caa73b, " + "0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1, \n" + " 0x510e527fade682d1, 0x9b05688c2b3e6c1f, " + "0x1f83d9abfb41bd6b, 0x5be0cd19137e2179, \n" + " 0x6a09e667f3bcc908, 0xbb67ae8584caa73b, " + "0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1, \n" + " 0x510e527fade68281, 0x9b05688c2b3e6c1f, " + "0xe07c265404be4294, 0x5be0cd19137e2179 }; \n" + " #define G(r,i,a,b,c,d) \\\n" + " a = a + b + m[ blake2b_sigma[r][2*i] ]; \\\n" + " ((uint2*)&d)[0] = ((uint2*)&d)[0].yx ^ ((uint2*)&a)[0].yx; \\\n" + " c = c + d; \\\n" + " ((uint2*)&b)[0] = ror64( ((uint2*)&b)[0] ^ ((uint2*)&c)[0], 24U); " + "\\\n" + " a = a + b + m[ blake2b_sigma[r][2*i+1] ]; \\\n" + " ((uint2*)&d)[0] = ror64( ((uint2*)&d)[0] ^ ((uint2*)&a)[0], 16U); " + "\\\n" + " c = c + d; \\\n" + " ((uint2*)&b)[0] = ror64_2( ((uint2*)&b)[0] ^ ((uint2*)&c)[0], " + "63U);\n" + " #define ROUND(r) \\\n" + " G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \\\n" + " G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \\\n" + " G(r,2,v[ 2],v[ 6],v[10],v[14]); \\\n" + " G(r,3,v[ 3],v[ 7],v[11],v[15]); \\\n" + " G(r,4,v[ 0],v[ 5],v[10],v[15]); \\\n" + " G(r,5,v[ 1],v[ 6],v[11],v[12]); \\\n" + " G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \\\n" + " G(r,7,v[ 3],v[ 4],v[ 9],v[14]); " + " \n" + " ROUND( 0 ); " + " \n" + " ROUND( 1 ); " + " \n" + " ROUND( 2 ); " + " \n" + " ROUND( 3 ); " + " \n" + " ROUND( 4 ); " + " \n" + " ROUND( 5 ); " + " \n" + " ROUND( 6 ); " + " \n" + " ROUND( 7 ); " + " \n" + " ROUND( 8 ); " + " \n" + " ROUND( 9 ); " + " \n" + " ROUND( 10 ); " + " \n" + " ROUND( 11 ); " + " \n" + " #undef G " + " \n" + " #undef ROUND " + " \n" + " if (as_ulong(as_uchar8(0x6a09e667f2bdc928 ^ v[0] ^ " + "v[8]).s76543210) < target) { \n" + " *nonceOut = m[4]; " + " \n" + " return; " + " \n" + " } " + " \n" + " }\n"; + +OCLPerfGenoilSiaMiner::OCLPerfGenoilSiaMiner() { _numSubTests = NUM_INTENSITY; } + +OCLPerfGenoilSiaMiner::~OCLPerfGenoilSiaMiner() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfGenoilSiaMiner::setHeader(uint32_t *ptr) { + ptr[0] = 0x10; + for (unsigned int i = 1; i < 9; i++) { + ptr[i] = 0; + } + ptr[9] = 0x4a5e1e4b; + ptr[10] = 0xaab89f3a; + ptr[11] = 0x32518a88; + ptr[12] = 0xc31bc87f; + ptr[13] = 0x618f7667; + ptr[14] = 0x3e2cc77a; + ptr[15] = 0xb2127b7a; + ptr[16] = 0xfdeda33b; + ptr[17] = 0x495fab29; + ptr[18] = 0x1d00ffff; + ptr[19] = 0x7c2bac1d; +} + +void OCLPerfGenoilSiaMiner::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + // Parse args. + isAMD = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + + char getVersion[128]; + error_ = _wrapper->clGetPlatformInfo(platform, CL_PLATFORM_VERSION, + sizeof(getVersion), getVersion, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + platformVersion[0] = getVersion[7]; + platformVersion[1] = getVersion[8]; + platformVersion[2] = getVersion[9]; + platformVersion[3] = '\0'; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + // Make sure the device can handle our local item size. + size_t max_group_size = 0; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_GROUP_SIZE, + sizeof(size_t), &max_group_size, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + if (local_item_size > max_group_size) { + char buf[256]; + SNPRINTF(buf, sizeof(buf), + "Selected device cannot handle work groups larger than %zu.\n", + local_item_size); + local_item_size = max_group_size; + testDescString = buf; + } + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + // Create Buffer Objects. + blockHeadermobj_ = _wrapper->clCreateBuffer( + context_, CL_MEM_READ_ONLY, 80 * sizeof(uint8_t), NULL, &error_); + CHECK_RESULT(blockHeadermobj_ == 0, "clCreateBuffer(outBuffer) failed"); + nonceOutmobj_ = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + 8 * sizeof(uint8_t), NULL, &error_); + CHECK_RESULT(nonceOutmobj_ == 0, "clCreateBuffer(outBuffer) failed"); + + // Create kernel program from source file. + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&siaKernel, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &device, NULL, NULL, NULL); + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + // Create data parallel OpenCL kernel. + kernel_ = _wrapper->clCreateKernel(program_, "nonceGrind", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + // Set OpenCL kernel arguments. + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&blockHeadermobj_); + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), + (void *)&nonceOutmobj_); +} + +void OCLPerfGenoilSiaMiner::run(void) { + CPerfCounter timer; + + uint8_t blockHeader[80]; + uint8_t target[32] = {255}; + uint8_t nonceOut[8] = {0}; + + setHeader((uint32_t *)blockHeader); + intensity = intensities[_openTest % NUM_INTENSITY]; + size_t global_item_size = 1ULL << intensity; + + timer.Reset(); + timer.Start(); + + // By doing a bunch of low intensity calls, we prevent freezing + // By splitting them up inside this function, we also avoid calling + // get_block_for_work too often. + for (unsigned int i = 0; i < cycles_per_iter; i++) { + // Offset global ids so that each loop call tries a different set of + // hashes. + size_t globalid_offset = i * global_item_size; + + // Copy input data to the memory buffer. + error_ = + clEnqueueWriteBuffer(cmd_queue_, blockHeadermobj_, CL_TRUE, 0, + 80 * sizeof(uint8_t), blockHeader, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueWriteBuffer failed"); + + error_ = clEnqueueWriteBuffer(cmd_queue_, nonceOutmobj_, CL_TRUE, 0, + 8 * sizeof(uint8_t), nonceOut, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueWriteBuffer failed"); + + // Run the kernel. + error_ = clEnqueueNDRangeKernel(cmd_queue_, kernel_, 1, &globalid_offset, + &global_item_size, &local_item_size, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + + // Copy result to host and see if a block was found. + error_ = clEnqueueReadBuffer(cmd_queue_, nonceOutmobj_, CL_TRUE, 0, + 8 * sizeof(uint8_t), nonceOut, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueReadBuffer failed"); + + // if (nonceOut[0] != 0) { + // // Copy nonce to header. + // memcpy(blockHeader + 32, nonceOut, 8); + // break; + //} + } + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Hash rate calculation MH/s + double hash_rate = cycles_per_iter * global_item_size / (sec * 1000000); + + _perfInfo = (float)hash_rate; + char buf[256]; + SNPRINTF(buf, sizeof(buf), + " (%4d cycles) Work_items:%10zu Intensity:%d (MH/s) ", + cycles_per_iter, global_item_size, intensity); + testDescString = buf; +} + +unsigned int OCLPerfGenoilSiaMiner::close(void) { + if (blockHeadermobj_) { + error_ = _wrapper->clReleaseMemObject(blockHeadermobj_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(blockHeadermobj_) failed"); + } + if (nonceOutmobj_) { + error_ = _wrapper->clReleaseMemObject(nonceOutmobj_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(nonceOutmobj_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfGenoilSiaMiner.h b/opencl/tests/ocltst/module/perf/OCLPerfGenoilSiaMiner.h new file mode 100644 index 0000000000..085b03c942 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfGenoilSiaMiner.h @@ -0,0 +1,78 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GenoilSiaMiner_H_ +#define _OCL_GenoilSiaMiner_H_ + +#include "OCLTestImp.h" + +class OCLPerfGenoilSiaMiner : public OCLTestImp { + public: + OCLPerfGenoilSiaMiner(); + virtual ~OCLPerfGenoilSiaMiner(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 1000; + // 2^intensity hashes are calculated each time the kernel is called + // Minimum of 2^8 (256) because our default local_item_size is 256 + // global_item_size (2^intensity) must be a multiple of local_item_size + // Max of 2^32 so that people can't send an hour of work to the GPU at one + // time +#define MIN_INTENSITY 8 +#define MAX_INTENSITY 32 +#define DEFAULT_INTENSITY 16 + + // Number of times the GPU kernel is called between updating the command line + // text +#define MIN_CPI 1 // Must do one call per update +#define MAX_CPI 65536 // 2^16 is a slightly arbitrary max +#define DEFAULT_CPI 30 + + // The maximum size of the .cl file we read in and compile +#define MAX_SOURCE_SIZE (0x200000) + + cl_context context_; + cl_command_queue cmd_queue_; + cl_int error_; + cl_program program_; + cl_kernel kernel_; + + // mem objects for storing our kernel parameters + cl_mem blockHeadermobj_ = NULL; + cl_mem nonceOutmobj_ = NULL; + + // More gobal variables the grindNonce needs to access + size_t local_item_size = + 256; // Size of local work groups. 256 is usually optimal + unsigned int blocks_mined = 0; + unsigned int intensity = DEFAULT_INTENSITY; + unsigned cycles_per_iter = DEFAULT_CPI; + + bool isAMD; + char platformVersion[32]; + void setHeader(uint32_t* ptr); +}; + +#endif // _OCL_GenoilSiaMiner_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageCopyCorners.cpp b/opencl/tests/ocltst/module/perf/OCLPerfImageCopyCorners.cpp new file mode 100644 index 0000000000..ce855d0a0a --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageCopyCorners.cpp @@ -0,0 +1,380 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfImageCopyCorners.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 2 +static const unsigned int Sizes0[NUM_SIZES] = {512, 16384}; +static const unsigned int Sizes1[NUM_SIZES] = {16384, 512}; + +#define NUM_FORMATS 3 +static const cl_image_format formats[NUM_FORMATS] = { + {CL_RGBA, CL_UNSIGNED_INT8}, + {CL_R, CL_UNSIGNED_INT32}, + {CL_RGBA, CL_UNSIGNED_INT32}}; +static const char *textFormats[NUM_FORMATS] = {"R8G8B8A8", "R32", + "R32G32B32A32"}; +static const unsigned int formatSize[NUM_FORMATS] = { + 4 * sizeof(cl_uchar), 1 * sizeof(cl_uint), 4 * sizeof(cl_uint)}; + +static const unsigned int Iterations[2] = {1, + OCLPerfImageCopyCorners::NUM_ITER}; + +#define NUM_SUBTESTS 3 +OCLPerfImageCopyCorners::OCLPerfImageCopyCorners() { + _numSubTests = NUM_SIZES * NUM_SUBTESTS * NUM_FORMATS * 2; +} + +OCLPerfImageCopyCorners::~OCLPerfImageCopyCorners() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfImageCopyCorners::setData(void *ptr, unsigned int pitch, + unsigned int size) { + unsigned int *ptr2 = (unsigned int *)ptr; + unsigned int value = 0; + for (unsigned int i = 0; i > 2; i++) { + ptr2[i] = value; + value++; + } +} + +void OCLPerfImageCopyCorners::checkData(void *ptr, unsigned int pitch, + unsigned int size) { + unsigned int *ptr2 = (unsigned int *)ptr; + unsigned int value = 0; + for (unsigned int i = 0; i < size >> 2; i++) { + if (ptr2[i] != value) { + printf("Data validation failed at %d! Got 0x%08x 0x%08x 0x%08x 0x%08x\n", + i, ptr2[i], ptr2[i + 1], ptr2[i + 2], ptr2[i + 3]); + printf("Expected 0x%08x 0x%08x 0x%08x 0x%08x\n", value, value, value, + value); + CHECK_RESULT(true, "Data validation failed!"); + break; + } + value++; + } +} + +void OCLPerfImageCopyCorners::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint typeOfDevice = type_; + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + size_t queryOut = 0; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + srcBuffer_ = 0; + dstBuffer_ = 0; + srcImage_ = false; + dstImage_ = false; + skip_ = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], typeOfDevice, + 0, NULL, &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + // if (num_devices > 0) + //{ + // platform = platforms[_platformIndex]; + // break; + //} +#if 0 + } +#endif + delete platforms; + } + + bufnum_ = (_openTest / (NUM_SIZES * NUM_SUBTESTS)) % NUM_FORMATS; + + if ((((_openTest / NUM_SIZES) % NUM_SUBTESTS) + 1) & 1) { + srcImage_ = true; + } + if ((((_openTest / NUM_SIZES) % NUM_SUBTESTS) + 1) & 2) { + dstImage_ = true; + } + + numIter = Iterations[_openTest / (NUM_SIZES * NUM_SUBTESTS * NUM_FORMATS)]; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = _wrapper->clGetDeviceIDs(platform, typeOfDevice, num_devices, + devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + size_t size; + bool imageSupport_ = false; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport_), &imageSupport_, &size); + if (!imageSupport_) { + printf("\n%s\n", "Image not supported, skipping this test!"); + skip_ = true; + return; + } + + if (_openTest % NUM_SIZES) { + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_WIDTH, + sizeof(size_t), &queryOut, NULL); + bufSizeW_ = (cl_uint)queryOut; + bufSizeH_ = Sizes1[_openTest % NUM_SIZES]; + } else { + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, + sizeof(size_t), &queryOut, NULL); + bufSizeW_ = Sizes0[_openTest % NUM_SIZES]; + bufSizeH_ = (cl_uint)queryOut; + } + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + void *mem; + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSizeW_, bufSizeH_, 1}; + size_t image_row_pitch; + size_t image_slice_pitch; + unsigned int memSize; + if (dstImage_) { + dstBuffer_ = + _wrapper->clCreateImage2D(context_, flags, &formats[bufnum_], bufSizeW_, + bufSizeH_, 0, NULL, &error_); + CHECK_RESULT(dstBuffer_ == 0, "clCreateImage(dstBuffer) failed"); + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_WRITE, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + memSize = (unsigned int)image_row_pitch * bufSizeH_; + } else { + dstBuffer_ = _wrapper->clCreateBuffer( + context_, flags, bufSizeW_ * bufSizeH_ * formatSize[bufnum_], NULL, + &error_); + CHECK_RESULT(dstBuffer_ == 0, "clCreateBuffer(dstBuffer) failed"); + mem = _wrapper->clEnqueueMapBuffer( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_WRITE, 0, + bufSizeW_ * bufSizeH_ * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memSize = (unsigned int)bufSizeW_ * bufSizeH_ * formatSize[bufnum_]; + image_row_pitch = 0; + } + setData(mem, (unsigned int)image_row_pitch, memSize); + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, dstBuffer_, mem, 0, NULL, NULL); + + flags = CL_MEM_READ_ONLY; + if (srcImage_) { + srcBuffer_ = + _wrapper->clCreateImage2D(context_, flags, &formats[bufnum_], bufSizeW_, + bufSizeH_, 0, NULL, &error_); + CHECK_RESULT(srcBuffer_ == 0, "clCreateImage(srcBuffer) failed"); + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, srcBuffer_, CL_TRUE, CL_MAP_WRITE, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + memSize = (unsigned int)image_row_pitch * bufSizeH_; + } else { + srcBuffer_ = _wrapper->clCreateBuffer( + context_, flags, bufSizeW_ * bufSizeH_ * formatSize[bufnum_], NULL, + &error_); + CHECK_RESULT(srcBuffer_ == 0, "clCreateBuffer(srcBuffer) failed"); + mem = _wrapper->clEnqueueMapBuffer( + cmd_queue_, srcBuffer_, CL_TRUE, CL_MAP_WRITE, 0, + bufSizeW_ * bufSizeH_ * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memSize = (unsigned int)bufSizeW_ * bufSizeH_ * formatSize[bufnum_]; + image_row_pitch = 0; + } + setData(mem, (unsigned int)image_row_pitch, memSize); + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, srcBuffer_, mem, 0, NULL, NULL); +} + +void OCLPerfImageCopyCorners::run(void) { + if (skip_) { + return; + } + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSizeW_, bufSizeH_, 1}; + + // Warm up + if (srcImage_ == false) { + error_ = _wrapper->clEnqueueCopyBufferToImage( + cmd_queue_, srcBuffer_, dstBuffer_, 0, origin, region, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyBufferToImage failed"); + } else if (dstImage_ == false) { + error_ = _wrapper->clEnqueueCopyImageToBuffer( + cmd_queue_, srcBuffer_, dstBuffer_, origin, region, 0, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyImageToBuffer failed"); + } else { + error_ = + _wrapper->clEnqueueCopyImage(cmd_queue_, srcBuffer_, dstBuffer_, origin, + origin, region, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyImage failed"); + } + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + CPerfCounter timer; + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + if (srcImage_ == false) { + error_ = _wrapper->clEnqueueCopyBufferToImage( + cmd_queue_, srcBuffer_, dstBuffer_, 0, origin, region, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyBufferToImage failed"); + } else if (dstImage_ == false) { + error_ = _wrapper->clEnqueueCopyImageToBuffer( + cmd_queue_, srcBuffer_, dstBuffer_, origin, region, 0, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyImageToBuffer failed"); + } else { + error_ = + _wrapper->clEnqueueCopyImage(cmd_queue_, srcBuffer_, dstBuffer_, + origin, origin, region, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyImage failed"); + } + } + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Image copy bandwidth in GB/s + double perf = ((double)bufSizeW_ * bufSizeH_ * formatSize[bufnum_] * 2 * + numIter * (double)(1e-09)) / + sec; + + const char *strSrc = NULL; + const char *strDst = NULL; + if (srcImage_) + strSrc = "img"; + else + strSrc = "buf"; + if (dstImage_) + strDst = "img"; + else + strDst = "buf"; + void *mem; + size_t image_row_pitch; + size_t image_slice_pitch; + unsigned int memSize; + if (dstImage_) { + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_READ, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + memSize = (unsigned int)image_row_pitch * bufSizeH_; + } else { + mem = _wrapper->clEnqueueMapBuffer( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_READ, 0, + bufSizeW_ * bufSizeH_ * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memSize = (unsigned int)bufSizeW_ * bufSizeH_ * formatSize[bufnum_]; + image_row_pitch = 0; + } + checkData(mem, (unsigned int)image_row_pitch, memSize); + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, dstBuffer_, mem, 0, NULL, NULL); + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%4dx%4d) fmt:%s src:%s dst:%s i: %4d (GB/s) ", + bufSizeW_, bufSizeH_, textFormats[bufnum_], strSrc, strDst, numIter); + testDescString = buf; +} + +unsigned int OCLPerfImageCopyCorners::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (srcBuffer_) { + error_ = _wrapper->clReleaseMemObject(srcBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(srcBuffer_) failed"); + } + if (dstBuffer_) { + error_ = _wrapper->clReleaseMemObject(dstBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(dstBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageCopyCorners.h b/opencl/tests/ocltst/module/perf/OCLPerfImageCopyCorners.h new file mode 100644 index 0000000000..f56591e3b0 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageCopyCorners.h @@ -0,0 +1,56 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ImageCopyCorners_H_ +#define _OCL_ImageCopyCorners_H_ + +#include "OCLTestImp.h" + +class OCLPerfImageCopyCorners : public OCLTestImp { + public: + OCLPerfImageCopyCorners(); + virtual ~OCLPerfImageCopyCorners(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 10; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem srcBuffer_; + cl_mem dstBuffer_; + cl_int error_; + bool skip_; + + unsigned int bufSizeW_; + unsigned int bufSizeH_; + unsigned int bufnum_; + bool srcImage_; + bool dstImage_; + unsigned int numIter; + void setData(void* ptr, unsigned int pitch, unsigned int size); + void checkData(void* ptr, unsigned int pitch, unsigned int size); +}; + +#endif // _OCL_ImageCopyCorners_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageCopySpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfImageCopySpeed.cpp new file mode 100644 index 0000000000..699142d2e3 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageCopySpeed.cpp @@ -0,0 +1,355 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfImageCopySpeed.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 4 +static const unsigned int Sizes[NUM_SIZES] = {256, 512, 1024, 2048}; + +#define NUM_FORMATS 1 +static const cl_image_format formats[NUM_FORMATS] = { + {CL_RGBA, CL_UNSIGNED_INT8}}; +static const char *textFormats[NUM_FORMATS] = {"R8G8B8A8"}; +static const unsigned int formatSize[NUM_FORMATS] = {4 * sizeof(cl_uchar)}; + +static const unsigned int Iterations[2] = {1, OCLPerfImageCopySpeed::NUM_ITER}; + +#define NUM_SUBTESTS 3 +OCLPerfImageCopySpeed::OCLPerfImageCopySpeed() { + _numSubTests = NUM_SIZES * NUM_SUBTESTS * NUM_FORMATS * 2; +} + +OCLPerfImageCopySpeed::~OCLPerfImageCopySpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfImageCopySpeed::setData(void *ptr, unsigned int pitch, + unsigned int size, unsigned int value) { + unsigned int *ptr2 = (unsigned int *)ptr; + for (unsigned int i = 0; i < size >> 2; i++) { + ptr2[i] = value; + } +} + +void OCLPerfImageCopySpeed::checkData(void *ptr, unsigned int pitch, + unsigned int size, unsigned int value) { + unsigned int *ptr2 = (unsigned int *)ptr; + for (unsigned int i = 0; i < size >> 2; i++) { + if (ptr2[i] != value) { + printf("Data validation failed at %d! Got 0x%08x 0x%08x 0x%08x 0x%08x\n", + i, ptr2[i], ptr2[i + 1], ptr2[i + 2], ptr2[i + 3]); + printf("Expected 0x%08x 0x%08x 0x%08x 0x%08x\n", value, value, value, + value); + break; + } + } +} + +void OCLPerfImageCopySpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint typeOfDevice = type_; + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + srcBuffer_ = 0; + dstBuffer_ = 0; + srcImage_ = false; + dstImage_ = false; + skip_ = false; + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], typeOfDevice, + 0, NULL, &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + // if (num_devices > 0) + //{ + // platform = platforms[_platformIndex]; + // break; + //} +#if 0 + } +#endif + delete platforms; + } + + bufSize_ = Sizes[_openTest % NUM_SIZES]; + bufnum_ = (_openTest / (NUM_SIZES * NUM_SUBTESTS)) % NUM_FORMATS; + + if ((((_openTest / NUM_SIZES) % NUM_SUBTESTS) + 1) & 1) { + srcImage_ = true; + } + if ((((_openTest / NUM_SIZES) % NUM_SUBTESTS) + 1) & 2) { + dstImage_ = true; + } + + numIter = Iterations[_openTest / (NUM_SIZES * NUM_SUBTESTS * NUM_FORMATS)]; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = _wrapper->clGetDeviceIDs(platform, typeOfDevice, num_devices, + devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + size_t size; + bool imageSupport_ = false; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport_), &imageSupport_, &size); + if (!imageSupport_) { + printf("\n%s\n", "Image not supported, skipping this test!"); + skip_ = true; + return; + } + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + void *mem; + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSize_, bufSize_, 1}; + size_t image_row_pitch; + size_t image_slice_pitch; + unsigned int memSize; + if (dstImage_) { + dstBuffer_ = + _wrapper->clCreateImage2D(context_, flags, &formats[bufnum_], bufSize_, + bufSize_, 0, NULL, &error_); + CHECK_RESULT(dstBuffer_ == 0, "clCreateImage(dstBuffer) failed"); + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_WRITE, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + memSize = (unsigned int)image_row_pitch * bufSize_; + } else { + dstBuffer_ = _wrapper->clCreateBuffer( + context_, flags, bufSize_ * bufSize_ * formatSize[bufnum_], NULL, + &error_); + CHECK_RESULT(dstBuffer_ == 0, "clCreateBuffer(dstBuffer) failed"); + mem = _wrapper->clEnqueueMapBuffer( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_WRITE, 0, + bufSize_ * bufSize_ * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memSize = (unsigned int)bufSize_ * bufSize_ * formatSize[bufnum_]; + image_row_pitch = 0; + } + setData(mem, (unsigned int)image_row_pitch, memSize, 0xdeadbeef); + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, dstBuffer_, mem, 0, NULL, NULL); + + flags = CL_MEM_READ_ONLY; + if (srcImage_) { + srcBuffer_ = + _wrapper->clCreateImage2D(context_, flags, &formats[bufnum_], bufSize_, + bufSize_, 0, NULL, &error_); + CHECK_RESULT(srcBuffer_ == 0, "clCreateImage(srcBuffer) failed"); + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, srcBuffer_, CL_TRUE, CL_MAP_WRITE, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + memSize = (unsigned int)image_row_pitch * bufSize_; + } else { + srcBuffer_ = _wrapper->clCreateBuffer( + context_, flags, bufSize_ * bufSize_ * formatSize[bufnum_], NULL, + &error_); + CHECK_RESULT(srcBuffer_ == 0, "clCreateBuffer(srcBuffer) failed"); + mem = _wrapper->clEnqueueMapBuffer( + cmd_queue_, srcBuffer_, CL_TRUE, CL_MAP_WRITE, 0, + bufSize_ * bufSize_ * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memSize = (unsigned int)bufSize_ * bufSize_ * formatSize[bufnum_]; + image_row_pitch = 0; + } + setData(mem, (unsigned int)image_row_pitch, memSize, 0x600df00d); + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, srcBuffer_, mem, 0, NULL, NULL); +} + +void OCLPerfImageCopySpeed::run(void) { + if (skip_) { + return; + } + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSize_, bufSize_, 1}; + + // Warm up + if (srcImage_ == false) { + error_ = _wrapper->clEnqueueCopyBufferToImage( + cmd_queue_, srcBuffer_, dstBuffer_, 0, origin, region, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyBufferToImage failed"); + } else if (dstImage_ == false) { + error_ = _wrapper->clEnqueueCopyImageToBuffer( + cmd_queue_, srcBuffer_, dstBuffer_, origin, region, 0, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyImageToBuffer failed"); + } else { + error_ = + _wrapper->clEnqueueCopyImage(cmd_queue_, srcBuffer_, dstBuffer_, origin, + origin, region, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyImage failed"); + } + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + CPerfCounter timer; + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + if (srcImage_ == false) { + error_ = _wrapper->clEnqueueCopyBufferToImage( + cmd_queue_, srcBuffer_, dstBuffer_, 0, origin, region, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyBufferToImage failed"); + } else if (dstImage_ == false) { + error_ = _wrapper->clEnqueueCopyImageToBuffer( + cmd_queue_, srcBuffer_, dstBuffer_, origin, region, 0, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyImageToBuffer failed"); + } else { + error_ = + _wrapper->clEnqueueCopyImage(cmd_queue_, srcBuffer_, dstBuffer_, + origin, origin, region, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyImage failed"); + } + } + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Image copy bandwidth in GB/s + double perf = ((double)bufSize_ * bufSize_ * formatSize[bufnum_] * 2 * + numIter * (double)(1e-09)) / + sec; + + const char *strSrc = NULL; + const char *strDst = NULL; + if (srcImage_) + strSrc = "img"; + else + strSrc = "buf"; + if (dstImage_) + strDst = "img"; + else + strDst = "buf"; + void *mem; + size_t image_row_pitch; + size_t image_slice_pitch; + unsigned int memSize; + if (dstImage_) { + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_READ, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + memSize = (unsigned int)image_row_pitch * bufSize_; + } else { + mem = _wrapper->clEnqueueMapBuffer( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_READ, 0, + bufSize_ * bufSize_ * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memSize = (unsigned int)bufSize_ * bufSize_ * formatSize[bufnum_]; + image_row_pitch = 0; + } + checkData(mem, (unsigned int)image_row_pitch, memSize, 0x600df00d); + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, dstBuffer_, mem, 0, NULL, NULL); + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%4dx%4d) fmt:%s src:%s dst:%s i: %4d (GB/s) ", + bufSize_, bufSize_, textFormats[bufnum_], strSrc, strDst, numIter); + testDescString = buf; +} + +unsigned int OCLPerfImageCopySpeed::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (srcBuffer_) { + error_ = _wrapper->clReleaseMemObject(srcBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(srcBuffer_) failed"); + } + if (dstBuffer_) { + error_ = _wrapper->clReleaseMemObject(dstBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(dstBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageCopySpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfImageCopySpeed.h new file mode 100644 index 0000000000..0c04bf9e0a --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageCopySpeed.h @@ -0,0 +1,56 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ImageCopySpeed_H_ +#define _OCL_ImageCopySpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfImageCopySpeed : public OCLTestImp { + public: + OCLPerfImageCopySpeed(); + virtual ~OCLPerfImageCopySpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 1000; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem srcBuffer_; + cl_mem dstBuffer_; + cl_int error_; + bool skip_; + unsigned int bufSize_; + unsigned int bufnum_; + bool srcImage_; + bool dstImage_; + unsigned int numIter; + void setData(void* ptr, unsigned int pitch, unsigned int size, + unsigned int value); + void checkData(void* ptr, unsigned int pitch, unsigned int size, + unsigned int value); +}; + +#endif // _OCL_ImageCopySpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageCreate.cpp b/opencl/tests/ocltst/module/perf/OCLPerfImageCreate.cpp new file mode 100644 index 0000000000..57d9f0ee53 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageCreate.cpp @@ -0,0 +1,202 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfImageCreate.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 4 +static const unsigned int Sizes[NUM_SIZES] = {256, 512, 1024, 2048}; + +#if defined(CL_VERSION_2_0) +#define NUM_FORMATS 3 +static const cl_image_format formats[NUM_FORMATS] = { + {CL_RGBA, CL_UNSIGNED_INT8}, + {CL_sRGBA, CL_UNORM_INT8}, + {CL_DEPTH, CL_UNORM_INT16}}; +static const char *textFormats[NUM_FORMATS] = {"CL_RGBA , CL_UNSIGNED_INT8", + "CL_sRGBA, CL_UNORM_INT8 ", + "CL_DEPTH, CL_UNORM_INT16 "}; +static const unsigned int formatSize[NUM_FORMATS] = { + sizeof(CL_UNSIGNED_INT8), sizeof(CL_UNORM_INT8), sizeof(CL_UNORM_INT16)}; +#else +#define NUM_FORMATS 1 +static const cl_image_format formats[NUM_FORMATS] = { + {CL_RGBA, CL_UNSIGNED_INT8}}; +static const char *textFormats[NUM_FORMATS] = {"CL_RGBA, CL_UNSIGNED_INT8"}; +static const unsigned int formatSize[NUM_FORMATS] = {sizeof(CL_UNSIGNED_INT8)}; +#endif + +OCLPerfImageCreate::OCLPerfImageCreate() { + _numSubTests = NUM_SIZES * NUM_FORMATS; +} + +OCLPerfImageCreate::~OCLPerfImageCreate() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfImageCreate::setData(void *ptr, unsigned int size, + unsigned int value) { + unsigned int *ptr2 = (unsigned int *)ptr; + for (unsigned int i = 0; i < size >> 2; i++) { + ptr2[i] = value; + value++; + } +} + +void OCLPerfImageCreate::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + error_ = CL_SUCCESS; + testId_ = test; + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = 0; + kernel_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + skip_ = false; + + // check device version + size_t param_size = 0; + char *strVersion = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 0, + 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[7] < '2') { + skip_ = true; + testDescString = + "sRGBA Image not supported for < 2.0 devices. Test Skipped."; + delete strVersion; + return; + } + delete strVersion; + size_t size; + bool imageSupport_ = false; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport_), &imageSupport_, &size); + if (!imageSupport_) { + printf("\n%s\n", "Image not supported, skipping this test!"); + skip_ = true; + return; + } + bufSize_ = Sizes[test % NUM_SIZES]; + bufnum_ = (test / NUM_SIZES) % NUM_FORMATS; + memSize = bufSize_ * bufSize_ * formatSize[bufnum_]; + numIter = 100; + + outBuffer_ = (cl_mem *)malloc(numIter * sizeof(cl_mem)); + memptr = new char[memSize]; + + cmd_queue_ = cmdQueues_[_deviceId]; +} + +void OCLPerfImageCreate::run(void) { + if (skip_) { + return; + } + + CPerfCounter timer; + + cl_image_desc imageInfo; + + memset(&imageInfo, 0x0, sizeof(cl_image_desc)); + + imageInfo.image_type = CL_MEM_OBJECT_IMAGE2D; + imageInfo.image_width = bufSize_; + imageInfo.image_height = bufSize_; + imageInfo.image_depth = 1; + imageInfo.image_array_size = 1; + imageInfo.image_row_pitch = bufSize_ * formatSize[bufnum_]; + imageInfo.image_slice_pitch = imageInfo.image_row_pitch * (bufSize_); + + setData(memptr, memSize, 0xdeadbeef); + + char *dstmem = new char[memSize]; + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {1, 1, 1}; + + timer.Reset(); + timer.Start(); + + for (unsigned int i = 0; i < numIter; ++i) { + outBuffer_[i] = + clCreateImage(context_, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, + &formats[bufnum_], &imageInfo, memptr, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "Error clCreateImage()"); + + error_ = + _wrapper->clEnqueueReadImage(cmd_queue_, outBuffer_[i], CL_TRUE, origin, + region, 0, 0, dstmem, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueReadImage failed"); + _wrapper->clFinish(cmd_queue_); + } + + timer.Stop(); + + delete dstmem; + + double sec = timer.GetElapsedTime(); + + // Image create in GB/s + double perf = ((double)memSize * numIter * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char buf[256]; + unsigned int fmt_num = (testId_ / NUM_SIZES) % NUM_FORMATS; + SNPRINTF(buf, sizeof(buf), " (%4dx%4d) fmt:%s(%1d) i: %4d (GB/s) ", bufSize_, + bufSize_, textFormats[fmt_num], formatSize[bufnum_], numIter); + testDescString = buf; +} + +unsigned int OCLPerfImageCreate::close(void) { + if (memptr) { + delete memptr; + } + if (outBuffer_) { + for (unsigned int i = 0; i < numIter; ++i) { + if (outBuffer_[i]) { + error_ = _wrapper->clReleaseMemObject(outBuffer_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_[i]) failed"); + } + } + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageCreate.h b/opencl/tests/ocltst/module/perf/OCLPerfImageCreate.h new file mode 100644 index 0000000000..17ba1c58e7 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageCreate.h @@ -0,0 +1,51 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ImageCreate_H_ +#define _OCL_ImageCreate_H_ + +#include "OCLTestImp.h" + +class OCLPerfImageCreate : public OCLTestImp { + public: + OCLPerfImageCreate(); + virtual ~OCLPerfImageCreate(); + + public: + virtual void open(unsigned int test, char *units, double &conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + virtual void setData(void *ptr, unsigned int size, unsigned int value); + + cl_command_queue cmd_queue_; + cl_mem *outBuffer_; + + unsigned int bufSize_; + unsigned int bufnum_; + unsigned int numIter; + char *memptr; + unsigned int memSize; + unsigned int testId_; + + bool skip_; +}; + +#endif // _OCL_ImageCreate_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageMapUnmap.cpp b/opencl/tests/ocltst/module/perf/OCLPerfImageMapUnmap.cpp new file mode 100644 index 0000000000..cc22ea7740 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageMapUnmap.cpp @@ -0,0 +1,345 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfImageMapUnmap.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 1 +static const unsigned int Sizes0[2] = {0xc0, 0x18a}; + +#define NUM_FORMATS 1 +static const cl_image_format formats[NUM_FORMATS] = {{CL_R, CL_SNORM_INT16}}; +static const char *textFormats[NUM_FORMATS] = {"R16"}; +static const unsigned int formatSize[NUM_FORMATS] = {2 * sizeof(cl_uchar)}; + +static const unsigned int Iterations[2] = {1, OCLPerfImageMapUnmap::NUM_ITER}; + +#define NUM_SUBTESTS 1 +OCLPerfImageMapUnmap::OCLPerfImageMapUnmap() { + _numSubTests = NUM_SIZES * NUM_SUBTESTS * NUM_FORMATS * 1; +} + +OCLPerfImageMapUnmap::~OCLPerfImageMapUnmap() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfImageMapUnmap::setData(void *ptr, unsigned int pitch, + unsigned int size, unsigned int value) { + unsigned int *ptr2 = (unsigned int *)ptr; + value = 0; + for (unsigned int i = 0; i < size >> 2; i++) { + ptr2[i] = value; + value++; + } +} + +void OCLPerfImageMapUnmap::checkData(void *ptr, unsigned int pitch, + unsigned int size, unsigned int value) { + unsigned int *ptr2 = (unsigned int *)ptr; + value = 0; + for (unsigned int i = 0; i < size >> 2; i++) { + if (ptr2[i] != value) { + printf("Data validation failed at %d! Got 0x%08x 0x%08x 0x%08x 0x%08x\n", + i, ptr2[i], ptr2[i + 1], ptr2[i + 2], ptr2[i + 3]); + printf("Expected 0x%08x 0x%08x 0x%08x 0x%08x\n", value, value, value, + value); + CHECK_RESULT(true, "Data validation failed!"); + break; + } + value++; + } +} + +void OCLPerfImageMapUnmap::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint typeOfDevice = type_; + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + size_t queryOut = 0; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + skip_ = false; + context_ = 0; + cmd_queue_ = 0; + srcBuffer_ = 0; + dstBuffer_ = 0; + srcImage_ = false; + dstImage_ = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], typeOfDevice, + 0, NULL, &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + // if (num_devices > 0) + //{ + // platform = platforms[_platformIndex]; + // break; + //} +#if 0 + } +#endif + delete platforms; + } + + bufnum_ = (_openTest / (NUM_SIZES * NUM_SUBTESTS)) % NUM_FORMATS; + + srcImage_ = true; + + dstImage_ = false; + + numIter = Iterations[_openTest / (NUM_SIZES * NUM_SUBTESTS * NUM_FORMATS)]; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = _wrapper->clGetDeviceIDs(platform, typeOfDevice, num_devices, + devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + size_t size; + bool imageSupport_ = false; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport_), &imageSupport_, &size); + if (!imageSupport_) { + printf("\n%s\n", "Image not supported, skipping this test!"); + skip_ = true; + return; + } + + bufSizeW_ = Sizes0[0]; + bufSizeH_ = Sizes0[1]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + cl_mem_flags flags2 = CL_MEM_WRITE_ONLY; + void *mem; + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSizeW_, bufSizeH_, 1}; + size_t image_row_pitch; + size_t image_slice_pitch; + cl_image_desc imageInfo; + + memset(&imageInfo, 0x0, sizeof(cl_image_desc)); + + imageInfo.image_type = CL_MEM_OBJECT_IMAGE2D; + imageInfo.image_width = bufSizeW_; + imageInfo.image_height = bufSizeH_; + imageInfo.image_depth = 1; + imageInfo.image_array_size = 1; + imageInfo.image_row_pitch = bufSizeW_ * formatSize[bufnum_]; + imageInfo.image_slice_pitch = imageInfo.image_row_pitch * (bufSizeH_); + + void *host_ptr = malloc(imageInfo.image_row_pitch * imageInfo.image_height); + + unsigned int memSize; + if (dstImage_) { + dstBuffer_ = + _wrapper->clCreateImage2D(context_, flags, &formats[bufnum_], bufSizeW_, + bufSizeH_, 0, host_ptr, &error_); + CHECK_RESULT(dstBuffer_ == 0, "clCreateImage(dstBuffer) failed"); + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_WRITE, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + memSize = (unsigned int)image_row_pitch * bufSizeH_; + } else { + dstBuffer_ = _wrapper->clCreateBuffer( + context_, flags2, bufSizeW_ * bufSizeH_ * formatSize[bufnum_], NULL, + &error_); + CHECK_RESULT(dstBuffer_ == 0, "clCreateBuffer(dstBuffer) failed"); + mem = _wrapper->clEnqueueMapBuffer( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_WRITE, 0, + bufSizeW_ * bufSizeH_ * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memSize = (unsigned int)bufSizeW_ * bufSizeH_ * formatSize[bufnum_]; + image_row_pitch = 0; + } + setData(mem, (unsigned int)image_row_pitch, memSize, 0xdeadbeef); + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, dstBuffer_, mem, 0, NULL, NULL); + + flags = CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR; + if (srcImage_) { + srcBuffer_ = _wrapper->clCreateImage(context_, flags, &formats[bufnum_], + &imageInfo, host_ptr, &error_); + CHECK_RESULT(srcBuffer_ == 0, "clCreateImage(srcBuffer) failed"); + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, srcBuffer_, CL_TRUE, CL_MAP_WRITE, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + memSize = (unsigned int)image_row_pitch * bufSizeH_; + error_ = _wrapper->clFinish(cmd_queue_); + } else { + srcBuffer_ = _wrapper->clCreateBuffer( + context_, flags, bufSizeW_ * bufSizeH_ * formatSize[bufnum_], NULL, + &error_); + CHECK_RESULT(srcBuffer_ == 0, "clCreateBuffer(srcBuffer) failed"); + mem = _wrapper->clEnqueueMapBuffer( + cmd_queue_, srcBuffer_, CL_TRUE, CL_MAP_WRITE, 0, + bufSizeW_ * bufSizeH_ * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memSize = (unsigned int)bufSizeW_ * bufSizeH_ * formatSize[bufnum_]; + image_row_pitch = 0; + } + setData(mem, (unsigned int)image_row_pitch, memSize, 0x600df00d); + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, srcBuffer_, mem, 0, NULL, NULL); + error_ = _wrapper->clFinish(cmd_queue_); +} + +void OCLPerfImageMapUnmap::run(void) { + if (skip_) { + return; + } + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSizeW_, bufSizeH_, 1}; + + if (srcImage_ == false) { + error_ = _wrapper->clEnqueueCopyBufferToImage( + cmd_queue_, srcBuffer_, dstBuffer_, 0, origin, region, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyBufferToImage failed"); + } else if (dstImage_ == false) { + error_ = _wrapper->clEnqueueCopyImageToBuffer( + cmd_queue_, srcBuffer_, dstBuffer_, origin, region, 0, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyImageToBuffer failed"); + } else { + error_ = + _wrapper->clEnqueueCopyImage(cmd_queue_, srcBuffer_, dstBuffer_, origin, + origin, region, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyImage failed"); + } + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + const char *strSrc = NULL; + const char *strDst = NULL; + if (srcImage_) + strSrc = "img"; + else + strSrc = "buf"; + if (dstImage_) + strDst = "img"; + else + strDst = "buf"; + void *mem; + size_t image_row_pitch; + size_t image_slice_pitch; + unsigned int memSize; + if (dstImage_) { + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_READ, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + memSize = (unsigned int)image_row_pitch * bufSizeH_; + } else { + mem = _wrapper->clEnqueueMapBuffer( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_READ, 0, + bufSizeW_ * bufSizeH_ * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memSize = (unsigned int)bufSizeW_ * bufSizeH_ * formatSize[bufnum_]; + image_row_pitch = 0; + } + checkData(mem, (unsigned int)image_row_pitch, memSize, 0x600df00d); + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, dstBuffer_, mem, 0, NULL, NULL); + _perfInfo = 0; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%4dx%4d) fmt:%s src:%s dst:%s i: %4d (GB/s) ", + bufSizeW_, bufSizeH_, textFormats[bufnum_], strSrc, strDst, numIter); + testDescString = buf; +} + +unsigned int OCLPerfImageMapUnmap::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (srcBuffer_) { + error_ = _wrapper->clReleaseMemObject(srcBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(srcBuffer_) failed"); + } + if (dstBuffer_) { + error_ = _wrapper->clReleaseMemObject(dstBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(dstBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageMapUnmap.h b/opencl/tests/ocltst/module/perf/OCLPerfImageMapUnmap.h new file mode 100644 index 0000000000..4d78c09cb1 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageMapUnmap.h @@ -0,0 +1,58 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ImageMapUnmap_H_ +#define _OCL_ImageMapUnmap_H_ + +#include "OCLTestImp.h" + +class OCLPerfImageMapUnmap : public OCLTestImp { + public: + OCLPerfImageMapUnmap(); + virtual ~OCLPerfImageMapUnmap(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 1; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem srcBuffer_; + cl_mem dstBuffer_; + cl_int error_; + bool skip_; + + unsigned int bufSizeW_; + unsigned int bufSizeH_; + unsigned int bufnum_; + bool srcImage_; + bool dstImage_; + unsigned int numIter; + void setData(void* ptr, unsigned int pitch, unsigned int size, + unsigned int value); + void checkData(void* ptr, unsigned int pitch, unsigned int size, + unsigned int value); +}; + +#endif // _OCL_ImageMapUnmap_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageReadSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfImageReadSpeed.cpp new file mode 100644 index 0000000000..2780205f6f --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageReadSpeed.cpp @@ -0,0 +1,315 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfImageReadSpeed.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 4 +static const unsigned int Sizes[NUM_SIZES] = {256, 512, 1024, 2048}; + +#define NUM_FORMATS 1 +static const cl_image_format formats[NUM_FORMATS] = { + {CL_RGBA, CL_UNSIGNED_INT8}}; +static const char *textFormats[NUM_FORMATS] = {"R8G8B8A8"}; +static const unsigned int formatSize[NUM_FORMATS] = {4}; + +static const unsigned int Iterations[2] = {1, OCLPerfImageReadSpeed::NUM_ITER}; + +OCLPerfImageReadSpeed::OCLPerfImageReadSpeed() { + _numSubTests = NUM_SIZES * NUM_FORMATS * 2; +} + +OCLPerfImageReadSpeed::~OCLPerfImageReadSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfImageReadSpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint typeOfDevice = type_; + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + skip_ = false; + context_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + memptr = NULL; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], typeOfDevice, + 0, NULL, &num_devices); + delete platforms; + } + + bufSize_ = Sizes[_openTest % NUM_SIZES]; + bufnum_ = (_openTest / NUM_SIZES) % NUM_FORMATS; + numIter = Iterations[_openTest / (NUM_SIZES * NUM_FORMATS)]; + + CHECK_RESULT(platform == 0, "Couldn't find platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = _wrapper->clGetDeviceIDs(platform, typeOfDevice, num_devices, + devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + size_t size; + bool imageSupport_ = false; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport_), &imageSupport_, &size); + if (!imageSupport_) { + printf("\n%s\n", "Image not supported, skipping this test!"); + skip_ = true; + return; + } + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + outBuffer_ = _wrapper->clCreateImage2D(context_, flags, &formats[bufnum_], + bufSize_, bufSize_, 0, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateImage(outBuffer) failed"); + memptr = new char[bufSize_ * bufSize_ * formatSize[bufnum_]]; +} + +void OCLPerfImageReadSpeed::run(void) { + if(skip_) { + return; + } + CPerfCounter timer; + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSize_, bufSize_, 1}; + // Warm up + error_ = _wrapper->clEnqueueReadImage(cmd_queue_, outBuffer_, CL_TRUE, origin, + region, 0, 0, memptr, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadImage failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + error_ = + _wrapper->clEnqueueReadImage(cmd_queue_, outBuffer_, CL_TRUE, origin, + region, 0, 0, memptr, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadImage failed"); + } + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Image read bandwidth in GB/s + double perf = ((double)bufSize_ * bufSize_ * formatSize[bufnum_] * numIter * + (double)(1e-09)) / + sec; + + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%4dx%4d) fmt:%s i: %4d (GB/s) ", bufSize_, + bufSize_, textFormats[bufnum_], numIter); + testDescString = buf; +} + +unsigned int OCLPerfImageReadSpeed::close(void) { + if (memptr) { + delete memptr; + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} + +OCLPerfPinnedImageReadSpeed::OCLPerfPinnedImageReadSpeed() { + _numSubTests = NUM_SIZES * NUM_FORMATS * 2; +} + +OCLPerfPinnedImageReadSpeed::~OCLPerfPinnedImageReadSpeed() {} + +void OCLPerfPinnedImageReadSpeed::open(unsigned int test, char *units, + double &conversion, + unsigned int deviceId) { + cl_uint typeOfDevice = type_; + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + memptr = NULL; + skip_ = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], typeOfDevice, + 0, NULL, &num_devices); + delete platforms; + } + + bufSize_ = Sizes[_openTest % NUM_SIZES]; + bufnum_ = (_openTest / NUM_SIZES) % NUM_FORMATS; + numIter = Iterations[_openTest / (NUM_SIZES * NUM_FORMATS)]; + + CHECK_RESULT(platform == 0, "Couldn't find platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = _wrapper->clGetDeviceIDs(platform, typeOfDevice, num_devices, + devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + size_t size; + bool imageSupport_ = false; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport_), &imageSupport_, &size); + if (!imageSupport_) { + printf("\n%s\n", "Image not supported, skipping this test!"); + skip_ = true; + return; + } + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR; + inBuffer_ = _wrapper->clCreateBuffer( + context_, flags, bufSize_ * bufSize_ * formatSize[bufnum_], NULL, + &error_); + CHECK_RESULT(inBuffer_ == 0, "clCreateBuffer(inBuffer) failed"); + + flags = CL_MEM_WRITE_ONLY; + outBuffer_ = _wrapper->clCreateImage2D(context_, flags, &formats[bufnum_], + bufSize_, bufSize_, 0, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateImage(outBuffer) failed"); + + memptr = (char *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, inBuffer_, CL_TRUE, CL_MAP_WRITE, 0, + bufSize_ * bufSize_ * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); +} + +unsigned int OCLPerfPinnedImageReadSpeed::close(void) { + if (memptr) { + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, inBuffer_, memptr, 0, + NULL, NULL); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clEnqueueUnmapMemObject(inBuffer_) failed"); + clFinish(cmd_queue_); + } + if (inBuffer_) { + error_ = _wrapper->clReleaseMemObject(inBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageReadSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfImageReadSpeed.h new file mode 100644 index 0000000000..d607031f68 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageReadSpeed.h @@ -0,0 +1,61 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ImageReadSpeed_H_ +#define _OCL_ImageReadSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfImageReadSpeed : public OCLTestImp { + public: + OCLPerfImageReadSpeed(); + virtual ~OCLPerfImageReadSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 100; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem outBuffer_; + cl_int error_; + bool skip_; + unsigned int bufSize_; + unsigned int bufnum_; + unsigned int numIter; + char* memptr; +}; + +class OCLPerfPinnedImageReadSpeed : public OCLPerfImageReadSpeed { + public: + OCLPerfPinnedImageReadSpeed(); + virtual ~OCLPerfPinnedImageReadSpeed(); + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual unsigned int close(void); + + cl_mem inBuffer_; +}; +#endif // _OCL_ImageReadSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageReadWrite.cpp b/opencl/tests/ocltst/module/perf/OCLPerfImageReadWrite.cpp new file mode 100644 index 0000000000..c069da6231 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageReadWrite.cpp @@ -0,0 +1,231 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfImageReadWrite.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define KERNEL_CODE(...) #__VA_ARGS__ + +#define NUM_SIZES 4 +static const unsigned int Sizes[NUM_SIZES] = {256, 512, 1024, 2048}; + +#if defined(CL_VERSION_2_0) +#define NUM_FORMATS 2 +static const cl_image_format formats[NUM_FORMATS] = { + {CL_RGBA, CL_UNSIGNED_INT8}, {CL_sRGBA, CL_UNORM_INT8}}; +static const char *textFormats[NUM_FORMATS] = {"CL_RGBA , CL_UNSIGNED_INT8", + "CL_sRGBA, CL_UNORM_INT8 "}; +static const unsigned int formatSize[NUM_FORMATS] = {sizeof(CL_UNSIGNED_INT8), + sizeof(CL_UNORM_INT8)}; +#else +#define NUM_FORMATS 1 +static const cl_image_format formats[NUM_FORMATS] = { + {CL_RGBA, CL_UNSIGNED_INT8}}; +static const char *textFormats[NUM_FORMATS] = {"CL_RGBA , CL_UNSIGNED_INT8"}; +static const unsigned int formatSize[NUM_FORMATS] = {sizeof(CL_UNSIGNED_INT8)}; +#endif + +const static char *strKernel = {KERNEL_CODE( + \n __constant sampler_t s_nearest = CLK_FILTER_NEAREST | CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE; + \n __kernel void image_kernel(read_write image2d_t image, uint zero) { + int x = get_global_id(0); + int y = get_global_id(1); + + int offset = y * get_image_width(image) + x; + + int2 coords = (int2)(x, y); + uint4 tmp = read_imageui(image, s_nearest, coords); + + write_imageui(image, coords, 1 + tmp * zero); +} + \n)}; + +OCLPerfImageReadWrite::OCLPerfImageReadWrite() { + _numSubTests = NUM_SIZES * NUM_FORMATS; +} + +OCLPerfImageReadWrite::~OCLPerfImageReadWrite() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfImageReadWrite::setData(void *ptr, unsigned int size, + unsigned int value) { + unsigned int *ptr2 = (unsigned int *)ptr; + for (unsigned int i = 0; i < size >> 2; i++) { + ptr2[i] = value; + value++; + } +} + +void OCLPerfImageReadWrite::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + error_ = CL_SUCCESS; + testId_ = test; + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = 0; + kernel_ = 0; + cmd_queue_ = 0; + imageBuffer_ = 0; + skip_ = false; + + // check device version + size_t param_size = 0; + char *strVersion = 0; + error_ = _wrapper->clGetDeviceInfo( + devices_[_deviceId], CL_DEVICE_OPENCL_C_VERSION, 0, 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = + _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_OPENCL_C_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[9] < '2') { + skip_ = true; + testDescString = + "Image read_write qualifier not supported in OpenCL C < 2.0. Test " + "Skipped."; + delete strVersion; + return; + } + delete strVersion; + size_t size; + bool imageSupport_ = false; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport_), &imageSupport_, &size); + if (!imageSupport_) { + printf("\n%s\n", "Image not supported, skipping this test!"); + skip_ = true; + return; + } + bufSize_ = Sizes[test % NUM_SIZES]; + bufnum_ = (test / NUM_SIZES) % NUM_FORMATS; + memSize = bufSize_ * bufSize_ * formatSize[bufnum_]; + numIter = 100; + + memptr = new char[memSize]; + + cmd_queue_ = cmdQueues_[_deviceId]; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "image_kernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + // create image + setData(memptr, memSize, 0x0); + imageBuffer_ = _wrapper->clCreateImage2D( + context_, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, &formats[bufnum_], + bufSize_, bufSize_, 0, memptr, &error_); + CHECK_RESULT(error_ != CL_SUCCESS, "clCreateImage2D() failed"); + + const unsigned int zero = 0; + + // set kernel arguments + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &imageBuffer_); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(unsigned int), &zero); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); +} + +void OCLPerfImageReadWrite::run(void) { + if (skip_) { + return; + } + + CPerfCounter timer; + + size_t gws[2] = {bufSize_, bufSize_}; + size_t lws[2] = {8, 8}; + + error_ = _wrapper->clEnqueueNDRangeKernel(cmd_queue_, kernel_, 2, NULL, gws, + lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(cmd_queue_); + + timer.Reset(); + timer.Start(); + + for (unsigned int i = 0; i < numIter; ++i) { + error_ = _wrapper->clEnqueueNDRangeKernel(cmd_queue_, kernel_, 2, NULL, gws, + lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(cmd_queue_); + } + + timer.Stop(); + + double sec = timer.GetElapsedTime(); + + // speed in GB/s + double perf = ((double)memSize * numIter * (double)(1e-09)) * 2 / sec; + + _perfInfo = (float)perf; + char buf[256]; + unsigned int fmt_num = (testId_ / NUM_SIZES) % NUM_FORMATS; + SNPRINTF(buf, sizeof(buf), " (%4dx%4d) fmt:%s(%1d) i: %4d (GB/s) ", bufSize_, + bufSize_, textFormats[fmt_num], formatSize[bufnum_], numIter); + testDescString = buf; +} + +unsigned int OCLPerfImageReadWrite::close(void) { + if (!skip_) { + if (memptr) { + delete memptr; + } + if (imageBuffer_) { + error_ = _wrapper->clReleaseMemObject(imageBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(imageBuffer_) failed"); + } + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageReadWrite.h b/opencl/tests/ocltst/module/perf/OCLPerfImageReadWrite.h new file mode 100644 index 0000000000..4a3f7ebaae --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageReadWrite.h @@ -0,0 +1,51 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ImageReadWrite +#define _OCL_ImageReadWrite + +#include "OCLTestImp.h" + +class OCLPerfImageReadWrite : public OCLTestImp { + public: + OCLPerfImageReadWrite(); + virtual ~OCLPerfImageReadWrite(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + virtual void setData(void* ptr, unsigned int size, unsigned int value); + + cl_command_queue cmd_queue_; + cl_mem imageBuffer_; + + unsigned int bufSize_; + unsigned int bufnum_; + unsigned int numIter; + char* memptr; + unsigned int memSize; + unsigned int testId_; + + bool skip_; +}; + +#endif // _OCL_ImageReadWrite diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageReadsRGBA.cpp b/opencl/tests/ocltst/module/perf/OCLPerfImageReadsRGBA.cpp new file mode 100644 index 0000000000..51748efa37 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageReadsRGBA.cpp @@ -0,0 +1,244 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfImageReadsRGBA.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define KERNEL_CODE(...) #__VA_ARGS__ + +#define NUM_SIZES 4 +static const unsigned int Sizes[NUM_SIZES] = {256, 512, 1024, 2048}; + +#if defined(CL_VERSION_2_0) +#define NUM_FORMATS 2 +static const cl_image_format formats[NUM_FORMATS] = { + {CL_RGBA, CL_UNSIGNED_INT8}, {CL_sRGBA, CL_UNORM_INT8}}; +static const char *textFormats[NUM_FORMATS] = {"CL_RGBA , CL_UNSIGNED_INT8", + "CL_sRGBA, CL_UNORM_INT8 "}; +static const unsigned int formatSize[NUM_FORMATS] = {sizeof(CL_UNSIGNED_INT8), + sizeof(CL_UNORM_INT8)}; +#else +#define NUM_FORMATS 1 +static const cl_image_format formats[NUM_FORMATS] = { + {CL_RGBA, CL_UNSIGNED_INT8}}; +static const char *textFormats[NUM_FORMATS] = {"CL_RGBA , CL_UNSIGNED_INT8"}; +static const unsigned int formatSize[NUM_FORMATS] = {sizeof(CL_UNSIGNED_INT8)}; +#endif + +const static char *strKernel = {KERNEL_CODE( + \n __constant sampler_t s_nearest = CLK_FILTER_NEAREST | CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE; + \n + // Read sRGBA image object (input) and convert it to linear RGB values + // (results): + __kernel void image_kernel(read_only image2d_t input, + __global float4 *results) { + int x = get_global_id(0); + int y = get_global_id(1); + + int offset = y * get_image_width(input) + x; + + int2 coords = (int2)(x, y); + float4 tmp = read_imagef(input, s_nearest, coords); + if (x < 0 && tmp.x == 0.f) { + results[offset] = tmp; + } + } + \n)}; + +OCLPerfImageReadsRGBA::OCLPerfImageReadsRGBA() { + _numSubTests = NUM_SIZES * NUM_FORMATS; +} + +OCLPerfImageReadsRGBA::~OCLPerfImageReadsRGBA() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfImageReadsRGBA::setData(void *ptr, unsigned int size, float value) { + unsigned int *ptr_i = (unsigned int *)ptr; + for (unsigned int i = 0; i < size >> 2; i++) { + ptr_i[i] = (int)value; + value++; + } +} + +void OCLPerfImageReadsRGBA::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + error_ = CL_SUCCESS; + testId_ = test; + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = 0; + kernel_ = 0; + cmd_queue_ = 0; + imageBuffer_ = 0; + valueBuffer_ = 0; + skip_ = false; + + // check device version + size_t param_size = 0; + char *strVersion = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 0, + 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[7] < '2') { + skip_ = true; + testDescString = + "sRGBA Image not supported for < 2.0 devices. Test Skipped."; + delete strVersion; + return; + } + delete strVersion; + size_t size; + bool imageSupport_ = false; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport_), &imageSupport_, &size); + if (!imageSupport_) { + printf("\n%s\n", "Image not supported, skipping this test!"); + skip_ = true; + return; + } + bufSize_ = Sizes[test % NUM_SIZES]; + bufnum_ = (test / NUM_SIZES) % NUM_FORMATS; + memSize = bufSize_ * bufSize_ * formatSize[bufnum_]; + numIter = 100; + + memptr = new char[memSize]; + + cmd_queue_ = cmdQueues_[_deviceId]; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "image_kernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + setData(memptr, memSize, 0.f); + + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSize_, bufSize_, 1}; + + // create image + imageBuffer_ = _wrapper->clCreateImage2D( + context_, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, &formats[bufnum_], + bufSize_, bufSize_, 0, memptr, &error_); + CHECK_RESULT(imageBuffer_ == 0, "clCreateImage2D(imageBuffer_) failed"); + + valueBuffer_ = clCreateBuffer( + context_, CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR, memSize, 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "Error clCreateBuffer()"); + + // set kernel arguments + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &imageBuffer_); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), &valueBuffer_); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); +} + +void OCLPerfImageReadsRGBA::run(void) { + if (skip_) { + return; + } + + CPerfCounter timer; + + size_t gws[2] = {bufSize_, bufSize_}; + size_t lws[2] = {8, 8}; + + // warm-up + error_ = _wrapper->clEnqueueNDRangeKernel(cmd_queue_, kernel_, 2, NULL, gws, + lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(cmd_queue_); + + timer.Reset(); + timer.Start(); + + for (unsigned int i = 0; i < numIter; ++i) { + error_ = _wrapper->clEnqueueNDRangeKernel(cmd_queue_, kernel_, 2, NULL, gws, + lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(cmd_queue_); + } + + timer.Stop(); + + double sec = timer.GetElapsedTime(); + + // read_imagef from sRGB to linear RGB speed in GB/s + double perf = ((double)memSize * numIter * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char buf[256]; + unsigned int fmt_num = (testId_ / NUM_SIZES) % NUM_FORMATS; + SNPRINTF(buf, sizeof(buf), " (%4dx%4d) fmt:%s(%1d) i: %4d (GB/s) ", bufSize_, + bufSize_, textFormats[fmt_num], formatSize[bufnum_], numIter); + testDescString = buf; +} + +unsigned int OCLPerfImageReadsRGBA::close(void) { + if (memptr) { + delete memptr; + } + if (imageBuffer_) { + error_ = _wrapper->clReleaseMemObject(imageBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(imageBuffer_) failed"); + } + if (valueBuffer_) { + error_ = _wrapper->clReleaseMemObject(valueBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(valueBuffer_) failed"); + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageReadsRGBA.h b/opencl/tests/ocltst/module/perf/OCLPerfImageReadsRGBA.h new file mode 100644 index 0000000000..210600b0a4 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageReadsRGBA.h @@ -0,0 +1,52 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ImageReadsRGBA_H_ +#define _OCL_ImageReadsRGBA_H_ + +#include "OCLTestImp.h" + +class OCLPerfImageReadsRGBA : public OCLTestImp { + public: + OCLPerfImageReadsRGBA(); + virtual ~OCLPerfImageReadsRGBA(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + virtual void setData(void* ptr, unsigned int size, float value); + + cl_command_queue cmd_queue_; + cl_mem imageBuffer_; + cl_mem valueBuffer_; + + unsigned int bufSize_; + unsigned int bufnum_; + unsigned int numIter; + char* memptr; + unsigned int memSize; + unsigned int testId_; + + bool skip_; +}; + +#endif // _OCL_ImageReadsRGBA_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageSampleRate.cpp b/opencl/tests/ocltst/module/perf/OCLPerfImageSampleRate.cpp new file mode 100644 index 0000000000..cb64b92597 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageSampleRate.cpp @@ -0,0 +1,335 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfImageSampleRate.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_TYPES 6 +static const cl_image_format formats[NUM_TYPES] = { + {CL_R, CL_UNSIGNED_INT8}, {CL_RG, CL_UNSIGNED_INT8}, + {CL_RGBA, CL_UNSIGNED_INT8}, {CL_R, CL_FLOAT}, + {CL_RGBA, CL_HALF_FLOAT}, {CL_RGBA, CL_FLOAT}}; +static const char *types[NUM_TYPES] = { + "R8", "R8G8", "R8G8B8A8", "R32F", "R16G16B16A16F", "R32G32B32A32F"}; +static const unsigned int typeSizes[NUM_TYPES] = {1, 2, 4, 4, 8, 16}; + +#define NUM_SIZES 12 +static const unsigned int sizes[NUM_SIZES] = {1, 2, 4, 8, 16, 32, + 64, 128, 256, 512, 1024, 2048}; + +#define NUM_BUFS 6 +#define MAX_BUFS (1 << (NUM_BUFS - 1)) + +OCLPerfImageSampleRate::OCLPerfImageSampleRate() { + _numSubTests = NUM_TYPES * NUM_SIZES * NUM_BUFS; +} + +OCLPerfImageSampleRate::~OCLPerfImageSampleRate() {} + +void OCLPerfImageSampleRate::setKernel(void) { + shader_.clear(); + shader_ += + "kernel void sampleRate(global float4* outBuffer, unsigned int " + "inBufSize, unsigned int writeIt,\n"; + char buf[256]; + for (unsigned int i = 0; i < numBufs_; i++) { + SNPRINTF(buf, sizeof(buf), "read_only image2d_t inBuffer%d", i); + shader_ += buf; + if (i < (numBufs_ - 1)) { + shader_ += ","; + } + shader_ += "\n"; + } + shader_ += ")\n"; + shader_ += + "{\n" + " uint gid = get_global_id(0);\n" + " uint inputIdx = gid % inBufSize;\n" + " const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | " + "CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;\n" + " float4 tmp = (float4)0.0f;\n"; + + for (unsigned int i = 0; i < numBufs_; i++) { + SNPRINTF(buf, sizeof(buf), + " tmp += read_imagef(inBuffer%d, sampler, (int2)( gid %% " + "inBufSize, (gid / inBufSize) %% inBufSize));\n", + i); + shader_ += buf; + } + shader_ += + " if (writeIt*(unsigned int)tmp.x) outBuffer[gid] = tmp;\n" + "}\n"; + // printf("Shader -> %s\n", shader_.c_str()); +} + +void OCLPerfImageSampleRate::setData(cl_mem buffer, unsigned int val) { + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {width_, width_, 1}; + size_t image_row_pitch; + size_t image_slice_pitch; + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapImage( + cmd_queue_, buffer, true, CL_MAP_WRITE, origin, region, &image_row_pitch, + &image_slice_pitch, 0, NULL, NULL, &error_); + for (unsigned int i = 0; i < width_ * width_; i++) data[i] = val; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +void OCLPerfImageSampleRate::checkData(cl_mem buffer) { +#if 0 + float* data = (float *)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, CL_MAP_READ, 0, outBufSize_, 0, NULL, NULL, &error_); + for (unsigned int i = 0; i < outBufSize_/sizeof(float); i++) + { + if (data[i] != (float)numBufs_) { + printf("Data validation failed at %d! Got %f, expected %f\n", i, data[i], (float)numBufs_); + break; + } + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, NULL); +#endif +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfImageSampleRate::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + skip_ = false; + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + inBuffer_ = 0; + outBuffer_ = 0; + + // We compute a square domain + width_ = sizes[test % NUM_SIZES]; + numBufs_ = (1 << ((test / NUM_SIZES) % NUM_BUFS)); + typeIdx_ = (test / (NUM_SIZES * NUM_BUFS)) % NUM_TYPES; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + platform = platforms[_platformIndex]; + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + delete platforms; + } + /* + * If we could find a platform, use it. + */ + CHECK_RESULT(platform == 0, + "Couldn't find platform with GPU devices, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + size_t size; + bool imageSupport_ = false; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport_), &imageSupport_, &size); + if (!imageSupport_) { + printf("\n%s\n", "Image not supported, skipping this test!"); + skip_ = true; + return; + } + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + inBuffer_ = (cl_mem *)malloc(sizeof(cl_mem) * numBufs_); + memset(inBuffer_, 0, sizeof(cl_mem) * numBufs_); + for (unsigned int i = 0; i < numBufs_; i++) { + inBuffer_[i] = _wrapper->clCreateImage2D(context_, CL_MEM_READ_ONLY, + &formats[typeIdx_], width_, width_, + 0, NULL, &error_); + CHECK_RESULT(inBuffer_[i] == 0, "clCreateImage2D(inBuffer) failed"); + } + + outBufSize_ = sizes[NUM_SIZES - 1] * sizes[NUM_SIZES - 1] * sizeof(cl_float4); + outBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, + outBufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + setKernel(); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + const char *buildOps = NULL; + error_ = _wrapper->clBuildProgram(program_, 1, &device, buildOps, NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "sampleRate", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&outBuffer_); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(outBuffer) failed"); + unsigned int sizeDW = width_; + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(unsigned int), + (void *)&sizeDW); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(sizeDW) failed"); + unsigned int writeIt = 0; + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(unsigned int), + (void *)&writeIt); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(writeIt) failed"); + for (unsigned int i = 0; i < numBufs_; i++) { + error_ = _wrapper->clSetKernelArg(kernel_, i + 3, sizeof(cl_mem), + (void *)&inBuffer_[i]); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(inBuffer) failed"); + // setData(inBuffer_[i], 0x3f800000); + } + // setData(outBuffer_, 0xdeadbeef); +} + +void OCLPerfImageSampleRate::run(void) { + if (skip_) { + return; + } + int global = outBufSize_ / typeSizes[typeIdx_]; + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + unsigned int maxIter = MAX_ITERATIONS * (MAX_BUFS / numBufs_); + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < maxIter; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + } + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // checkData(outBuffer_); + // Compute GB/s + double perf = + ((double)outBufSize_ * numBufs_ * (double)maxIter * (double)(1e-09)) / + sec; + char buf[256]; + SNPRINTF(buf, sizeof(buf), "Domain %dx%d, %13s, %2d images,%4dx%4d (GB/s)", + sizes[NUM_SIZES - 1], sizes[NUM_SIZES - 1], types[typeIdx_], + numBufs_, width_, width_); + + _perfInfo = (float)perf; + testDescString = buf; +} + +unsigned int OCLPerfImageSampleRate::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (inBuffer_) { + for (unsigned int i = 0; i < numBufs_; i++) { + if (inBuffer_[i]) { + error_ = _wrapper->clReleaseMemObject(inBuffer_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + } + free(inBuffer_); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageSampleRate.h b/opencl/tests/ocltst/module/perf/OCLPerfImageSampleRate.h new file mode 100644 index 0000000000..a3889ebe87 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageSampleRate.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_IMAGESAMPLERATE_H_ +#define _OCL_IMAGESAMPLERATE_H_ + +#include "OCLTestImp.h" + +class OCLPerfImageSampleRate : public OCLTestImp { + public: + OCLPerfImageSampleRate(); + virtual ~OCLPerfImageSampleRate(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void setData(cl_mem buffer, unsigned int data); + void checkData(cl_mem buffer); + void setKernel(void); + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem* inBuffer_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int width_; + unsigned int outBufWidth_; + unsigned int outBufSize_; + static const unsigned int MAX_ITERATIONS = 25; + unsigned int numBufs_; + unsigned int typeIdx_; + bool skip_; +}; + +#endif // _OCL_IMAGESAMPLERATE_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageWriteSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfImageWriteSpeed.cpp new file mode 100644 index 0000000000..1fbe02de9e --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageWriteSpeed.cpp @@ -0,0 +1,336 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfImageWriteSpeed.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 4 +static const unsigned int Sizes[NUM_SIZES] = {256, 512, 1024, 2048}; + +#define NUM_FORMATS 1 +static const cl_image_format formats[NUM_FORMATS] = { + {CL_RGBA, CL_UNSIGNED_INT8}}; +static const char *textFormats[NUM_FORMATS] = {"R8G8B8A8"}; +static const unsigned int formatSize[NUM_FORMATS] = {4}; + +static const unsigned int Iterations[2] = {1, OCLPerfImageWriteSpeed::NUM_ITER}; + +OCLPerfImageWriteSpeed::OCLPerfImageWriteSpeed() { + _numSubTests = NUM_SIZES * NUM_FORMATS * 2; +} + +OCLPerfImageWriteSpeed::~OCLPerfImageWriteSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfImageWriteSpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint typeOfDevice = type_; + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + memptr = NULL; + skip_ = false; + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], typeOfDevice, + 0, NULL, &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + // if (num_devices > 0) + //{ + // platform = platforms[_platformIndex]; + // break; + //} +#if 0 + } +#endif + delete platforms; + } + + bufSize_ = Sizes[_openTest % NUM_SIZES]; + bufnum_ = (_openTest / NUM_SIZES) % NUM_FORMATS; + numIter = Iterations[_openTest / (NUM_SIZES * NUM_FORMATS)]; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = _wrapper->clGetDeviceIDs(platform, typeOfDevice, num_devices, + devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + size_t size; + bool imageSupport_ = false; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport_), &imageSupport_, &size); + if (!imageSupport_) { + printf("\n%s\n", "Image not supported, skipping this test!"); + skip_ = true; + return; + } + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + outBuffer_ = _wrapper->clCreateImage2D(context_, flags, &formats[bufnum_], + bufSize_, bufSize_, 0, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateImage(outBuffer) failed"); + memptr = new char[bufSize_ * bufSize_ * formatSize[bufnum_]]; +} + +void OCLPerfImageWriteSpeed::run(void) { + if (skip_) { + return; + } + CPerfCounter timer; + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSize_, bufSize_, 1}; + // Warm up + error_ = + _wrapper->clEnqueueWriteImage(cmd_queue_, outBuffer_, CL_TRUE, origin, + region, 0, 0, memptr, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadImage failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + error_ = + _wrapper->clEnqueueWriteImage(cmd_queue_, outBuffer_, CL_TRUE, origin, + region, 0, 0, memptr, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadImage failed"); + } + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Image write bandwidth in GB/s + double perf = ((double)bufSize_ * bufSize_ * formatSize[bufnum_] * numIter * + (double)(1e-09)) / + sec; + + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%4dx%4d) fmt:%s i: %4d (GB/s) ", bufSize_, + bufSize_, textFormats[bufnum_], numIter); + testDescString = buf; +} + +unsigned int OCLPerfImageWriteSpeed::close(void) { + if (memptr) { + delete memptr; + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} + +OCLPerfPinnedImageWriteSpeed::OCLPerfPinnedImageWriteSpeed() { + _numSubTests = NUM_SIZES * NUM_FORMATS * 2; +} + +OCLPerfPinnedImageWriteSpeed::~OCLPerfPinnedImageWriteSpeed() {} + +void OCLPerfPinnedImageWriteSpeed::open(unsigned int test, char *units, + double &conversion, + unsigned int deviceId) { + cl_uint typeOfDevice = type_; + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + memptr = NULL; + skip_ = false; + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], typeOfDevice, + 0, NULL, &num_devices); + delete platforms; + } + + bufSize_ = Sizes[_openTest % NUM_SIZES]; + bufnum_ = (_openTest / NUM_SIZES) % NUM_FORMATS; + numIter = Iterations[_openTest / (NUM_SIZES * NUM_FORMATS)]; + + CHECK_RESULT(platform == 0, "Couldn't find platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = _wrapper->clGetDeviceIDs(platform, typeOfDevice, num_devices, + devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + size_t size; + bool imageSupport_ = false; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport_), &imageSupport_, &size); + if (!imageSupport_) { + printf("\n%s\n", "Image not supported, skipping this test!"); + skip_ = true; + return; + } + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR; + inBuffer_ = _wrapper->clCreateBuffer( + context_, flags, bufSize_ * bufSize_ * formatSize[bufnum_], NULL, + &error_); + CHECK_RESULT(inBuffer_ == 0, "clCreateBuffer(inBuffer) failed"); + + flags = CL_MEM_WRITE_ONLY; + outBuffer_ = _wrapper->clCreateImage2D(context_, flags, &formats[bufnum_], + bufSize_, bufSize_, 0, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateImage(outBuffer) failed"); + + memptr = (char *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, inBuffer_, CL_TRUE, CL_MAP_WRITE, 0, + bufSize_ * bufSize_ * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); +} + +unsigned int OCLPerfPinnedImageWriteSpeed::close(void) { + if (memptr) { + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, inBuffer_, memptr, 0, + NULL, NULL); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clEnqueueUnmapMemObject(inBuffer_) failed"); + clFinish(cmd_queue_); + } + if (inBuffer_) { + error_ = _wrapper->clReleaseMemObject(inBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfImageWriteSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfImageWriteSpeed.h new file mode 100644 index 0000000000..3f0f5702c0 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfImageWriteSpeed.h @@ -0,0 +1,63 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ImageWriteSpeed_H_ +#define _OCL_ImageWriteSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfImageWriteSpeed : public OCLTestImp { + public: + OCLPerfImageWriteSpeed(); + virtual ~OCLPerfImageWriteSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 100; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int bufSize_; + unsigned int bufnum_; + unsigned int numIter; + char* memptr; + bool skip_; +}; + +class OCLPerfPinnedImageWriteSpeed : public OCLPerfImageWriteSpeed { + public: + OCLPerfPinnedImageWriteSpeed(); + virtual ~OCLPerfPinnedImageWriteSpeed(); + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual unsigned int close(void); + + cl_mem inBuffer_; +}; + +#endif // _OCL_ImageWriteSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfKernelArguments.cpp b/opencl/tests/ocltst/module/perf/OCLPerfKernelArguments.cpp new file mode 100644 index 0000000000..0a6654f9b3 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfKernelArguments.cpp @@ -0,0 +1,239 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfKernelArguments.h" + +#include +#include +#include + +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +static const size_t BufSize = 0x1000; +static const size_t Iterations = 0x10000; +static const size_t TotalQueues = 4; +static const size_t NumBufCnts = 4; +static const size_t TotalArgs = 4; + +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +static const char* Arguments[TotalArgs] = { + "__global uint* out", + "__global uint* out, __global uint* buf0, __global uint* buf1, __global " + "uint* buf2, __global uint* buf3", + "__global uint* out, __global uint* buf0, __global uint* buf1, __global " + "uint* buf2, __global uint* buf3, \n" + "__global uint* buf4, __global uint* buf5, __global uint* buf6, __global " + "uint* buf7, __global uint* buf8", + "__global uint* out, __global uint* buf0, __global uint* buf1, __global " + "uint* buf2, __global uint* buf3,\n" + "__global uint* buf4, __global uint* buf5, __global uint* buf6, __global " + "uint* buf7, __global uint* buf8,\n" + "__global uint* buf9, __global uint* buf10, __global uint* buf11, __global " + "uint* buf12, __global uint* buf13,\n" + "__global uint* buf14, __global uint* buf15, __global uint* buf16, " + "__global uint* buf17, __global uint* buf18"}; + +static const char* strKernel = + "__kernel void dummy(%s) \n" + "{ \n" + " uint id = get_global_id(0); \n" + " uint value = 1; \n" + " out[id] = value; \n" + "} \n"; + +OCLPerfKernelArguments::OCLPerfKernelArguments() { + _numSubTests = TotalQueues * TotalArgs * NumBufCnts * 2; + failed_ = false; +} + +OCLPerfKernelArguments::~OCLPerfKernelArguments() {} + +void OCLPerfKernelArguments::open(unsigned int test, char* units, + double& conversion, unsigned int deviceId) { + cl_mem buffer; + _deviceId = deviceId; + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + test_ = test; + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + perBatch_ = test >= (TotalQueues * TotalArgs * NumBufCnts); + + size_t numArguments = (test_ / TotalQueues) % TotalArgs; + char* program = new char[4096]; + SNPRINTF(program, sizeof(char) * 4096, strKernel, Arguments[numArguments]); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char**)&program, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + kernel_ = _wrapper->clCreateKernel(program_, "dummy", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + delete[] program; + + static const size_t NumBuffs[NumBufCnts] = {0x20, 0x100, 0x800, 0x2000}; + + size_t numMems = NumBuffs[(test_ / (TotalQueues * TotalArgs)) % NumBufCnts]; + size_t bufSize = BufSize * sizeof(cl_int4); + for (size_t b = 0; b < numMems; ++b) { + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, bufSize, + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + } +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLPerfKernelArguments::run(void) { + if (failed_) { + return; + } + unsigned int* values; + values = reinterpret_cast(new cl_int4[BufSize]); + CPerfCounter timer; + static const size_t Queues[] = {1, 2, 4, 8}; + size_t numQueues = Queues[test_ % TotalQueues]; + cl_uint numArguments; + _wrapper->clGetKernelInfo(kernel_, CL_KERNEL_NUM_ARGS, sizeof(cl_uint), + &numArguments, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetKernelInfo() failed"); + + // Clear destination buffer + memset(values, 0, BufSize * sizeof(cl_int4)); + + size_t iter = Iterations / numQueues / buffers_.size(); + iter = (iter == 0) ? 1 : iter; + + std::vector cmdQueues(numQueues); + for (size_t q = 0; q < numQueues; ++q) { + cl_command_queue cmdQueue = _wrapper->clCreateCommandQueue( + context_, devices_[_deviceId], 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueue() failed"); + cmdQueues[q] = cmdQueue; + } + // Warm-up + for (size_t b = 0; b < (buffers_.size() / numArguments); ++b) { + for (size_t q = 0; q < numQueues; ++q) { + for (cl_uint a = 0; a < numArguments; ++a) { + cl_mem buffer = buffers()[(b * numArguments + a) % buffers_.size()]; + error_ = _wrapper->clSetKernelArg(kernel_, a, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + } + + size_t gws[1] = {256}; + size_t lws[1] = {256}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues[q], kernel_, 1, NULL, + gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + } + for (size_t q = 0; q < numQueues; ++q) { + _wrapper->clFinish(cmdQueues[q]); + } + + size_t disp = 0; + timer.Reset(); + timer.Start(); + + for (size_t i = 0; i < iter; ++i) { + for (size_t b = 0; b < buffers_.size(); ++b) { + for (size_t q = 0; q < numQueues; ++q) { + for (cl_uint a = 0; a < numArguments; ++a) { + cl_mem buffer = buffers()[(b * numArguments + a) % buffers_.size()]; + error_ = + _wrapper->clSetKernelArg(kernel_, a, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + } + + size_t gws[1] = {256}; + size_t lws[1] = {256}; + error_ = _wrapper->clEnqueueNDRangeKernel( + cmdQueues[q], kernel_, 1, NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + disp++; + if (perBatch_) { + _wrapper->clFlush(cmdQueues[q]); + } + } + if (perBatch_) { + for (size_t q = 0; q < numQueues; ++q) { + _wrapper->clFinish(cmdQueues[q]); + } + } + } + } + for (size_t q = 0; q < numQueues; ++q) { + _wrapper->clFinish(cmdQueues[q]); + } + timer.Stop(); + + for (size_t q = 0; q < numQueues; ++q) { + error_ = _wrapper->clReleaseCommandQueue(cmdQueues[q]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseCommandQueue() failed"); + } + + std::stringstream stream; + if (perBatch_) + stream << "Time per batch (us) for " << numQueues << " queues, "; + else + stream << "Time per dispatch (us) for " << numQueues << " queues, "; + stream.flags(std::ios::right | std::ios::showbase); + stream.width(2); + stream << numArguments; + stream << " args, "; + stream.flags(std::ios::right | std::ios::showbase); + stream.width(4); + stream << buffers_.size() << " bufs"; + testDescString = stream.str(); + _perfInfo = static_cast(timer.GetElapsedTime() * 1000000 / disp); + delete[] values; +} + +unsigned int OCLPerfKernelArguments::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/perf/OCLPerfKernelArguments.h b/opencl/tests/ocltst/module/perf/OCLPerfKernelArguments.h new file mode 100644 index 0000000000..8cf7138647 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfKernelArguments.h @@ -0,0 +1,43 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_KERNEL_ARGUMENTS_H_ +#define _OCL_PERF_KERNEL_ARGUMENTS_H_ + +#include "OCLTestImp.h" + +class OCLPerfKernelArguments : public OCLTestImp { + public: + OCLPerfKernelArguments(); + virtual ~OCLPerfKernelArguments(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; + unsigned int test_; + bool perBatch_; +}; + +#endif // _OCL_PERF_KERNEL_ARGUMENTS_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfKernelThroughput.cpp b/opencl/tests/ocltst/module/perf/OCLPerfKernelThroughput.cpp new file mode 100644 index 0000000000..cd8c33b519 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfKernelThroughput.cpp @@ -0,0 +1,1008 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfKernelThroughput.h" + +#include +#include +#include +#include + +#include + +#include "CL/cl.h" +#include "Timer.h" + +#define DO_GPU_KERNELS 1 + +#if 0 +#define ENTER(X) printf("Entering %s\n", X); +#define EXIT(X) printf("Exiting %s\n", X); +#define PKT(X) X +#else +#define ENTER(X) +#define EXIT(X) +#define PKT(X) +#endif + +// work with multiples of 128 +#define ROUND_MULT(VAL, MULT) ((VAL / MULT) * MULT) +/* +int roundUp( int numToRound, int multiple) +{ + int r = numToRound % multiple; + if (r == 0) + { + return numToRound; + } else { + return numToRound + multiple - remainder; + } +} +*/ +// quiety warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define WORK_GROUP_SIZE 256 + +/******************************************************************************* + * Enumerated Types for Tests + ******************************************************************************/ + +// memory operations +const LARGE_INT numKernelTypes = 2; +static const char *kernelType[numKernelTypes] = {"MatMul", "Madds"}; + +// source/read memory locations +const LARGE_INT numMemPaths = 2; +static const char *memPath[numMemPaths] = {"Host", "Device"}; + +// buffer size +const LARGE_INT numNumElements = 12; // 15; +static const LARGE_INT numElements[numNumElements] = { + 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, + 16777216 //, + // 67108864, + // 268435456 +}; + +// flops/byte +const LARGE_INT numWorkSizes = 5; +static const LARGE_INT workSize[numWorkSizes] = {1, 4, 16, 64, 256}; + +const float initFloat = 0.001f; +const float zeroFloat = 0.0f; + +#define WORK_GROUP_SIZE 256 + +/******************************************************************************* + * Write the Matrix Multiply Shader Kernel + ******************************************************************************/ +void OCLPerfKernelThroughput::genShaderMatrixMultiply() { + ENTER("genShaderMatrixMultiply"); + + std::stringstream ss; + ss.clear(); +#if 0 + printf("%ix%i * %ix%i = %ix%i:\n", + matrixDim1_, matrixDim2_, + matrixDim2_, matrixDim1_, + matrixDim1_, matrixDim1_ + ); +#endif + ss << "#define BLOCK_SIZE 16\n" + "#define HA " + << matrixDim1_ + << "\n" + "#define WA " + << matrixDim2_ + << "\n" + "#define HB WA\n" + "#define WB HA\n" + "#define HC HA\n" + "#define WC WB\n" + "__kernel void\n" + "__attribute__((reqd_work_group_size(16,16,1)))\n" + "kernel1(\n" + " __global float * restrict C,\n" + " __global float * restrict A,\n" + " __global float * restrict B )\n" + "{\n" + " int bx = get_group_id(0);\n" + " int by = get_group_id(1);\n" + " int tx = get_local_id(0);\n" + " int ty = get_local_id(1);\n" + " int aBegin = WA * BLOCK_SIZE * by;\n" + " int aEnd = aBegin + WA - 1;\n" + " int aStep = BLOCK_SIZE;\n" + " int bBegin = BLOCK_SIZE * bx;\n" + " int bStep = BLOCK_SIZE * WB;\n" + " __private float c = 0.f;\n" + " __local float localA[BLOCK_SIZE][BLOCK_SIZE];\n" + " __local float localB[BLOCK_SIZE][BLOCK_SIZE];\n" + " for (\n" + " int a = aBegin, b = bBegin;\n" + " a <= aEnd;\n" + " a += aStep, b += bStep)\n" + " {\n" + " localA[ty][tx] = (get_global_id(0) < WA && get_global_id(1) < " + "HA) ? A[a + WA * ty + tx] : 0;\n" + " localB[ty][tx] = (get_global_id(0) < WB && get_global_id(1) < " + "HB) ? B[b + WB * ty + tx] : 0;\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + " for (int k = 0; k < BLOCK_SIZE; ++k)\n" + " c += localA[ty][k] * localB[k][tx];\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + " }\n" + " int cIdx = WB * BLOCK_SIZE * by + BLOCK_SIZE * bx + WB * ty + tx;\n" + " if (get_global_id(0) < WC && get_global_id(1) < WC)\n" + " {\n" + " C[cIdx] = c;\n" + " }\n" + "}\n"; + + shader_ = ss.str(); + gold_ = 0.f; + for (int i = 0; i < matrixDim2_; i++) gold_ += initFloat * initFloat; + // gold_ = initFloat * initFloat * matrixDim2_; + // printf("shader:\n%s\n", shader_.c_str()); + // printf("gold_: %f\n", gold_); + EXIT("genShaderMatrixMultiply"); +} + +/******************************************************************************* + * Write the Madds Shader Kernel + ******************************************************************************/ +void OCLPerfKernelThroughput::genShaderMadds() { + ENTER("genShaderMadds"); + + int flopLoopIter = 2 * (flopsPerByte_ * 4 * 4) / 16; // bytes, flops + + std::stringstream ss; + ss.clear(); + float a, b; + + ss << // begin kernel + "__kernel void\n" + "__attribute__((reqd_work_group_size(" + << 256 + << ",1,1)))\n" + "kernel1(\n" + " __global float4 * restrict input,\n" + " __global float4 * restrict output )\n" + "{\n"; + + // begin loop + ss << " for ( uint idx = get_global_id(0);\n" + " idx < " + << numElements[numElementsIdx_] + << ";\n" + " idx += get_global_size(0) )\n" + " {\n"; + + // do load + ss << " float4 prefetch = input[ idx ];\n" + " float a0 = prefetch.x;\n" + " float a1 = prefetch.y;\n" + " float a2 = prefetch.z;\n" + " float a3 = prefetch.w;\n" + " float b0 = a0;\n" + " float b1 = a1;\n" + " float b2 = a2;\n" + " float b3 = a3;\n"; + a = initFloat; + b = a; + + // do math + for (int i = 0; i < flopLoopIter; i++) { + ss << " a0 += b3*b1;\n" + " a1 += b0*b2;\n" + " a2 += b1*b3;\n" + " a3 += b2*b0;\n" + " b0 += a3*a1;\n" + " b1 += a0*a2;\n" + " b2 += a1*a3;\n" + " b3 += a2*a0;\n"; + // printf("a += b*b; %f += %f*%f\n", a, b, b); + a += b * b; + // printf("b += a*a; %f += %f*%f\n", b, a, a); + b += a * a; + } + + // do write or accumulate + ss << " __private float4 tmp;\n" + " tmp.x = b0;\n" + " tmp.y = b1;\n" + " tmp.z = b2;\n" + " tmp.w = b3;\n" + " output[ idx ] = tmp;\n"; + gold_ = b; + // printf("GPU gold_ Tmp: %f\n", gold_); + + // end loop + ss << " } // end loop\n"; + // end kernel + ss << " } // end kernel\n\n"; + + shader_ = ss.str(); + // printf("shader:\n%s\n", shader_.c_str()); + // printf("gold_: %f\n", gold_); + EXIT("genShaderMadds"); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +/******************************************************************************* + * Constructor + ******************************************************************************/ +OCLPerfKernelThroughput::OCLPerfKernelThroughput() { + ENTER("constructor"); + _numSubTests = numKernelTypes * numMemPaths * numNumElements * numWorkSizes; + + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + context_ = 0; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + // Get last for default + platform = platforms[numPlatforms - 1]; + for (unsigned i = 0; i < numPlatforms; ++i) { + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, + sizeof(pbuf), pbuf, NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = + _wrapper->clGetDeviceIDs(platforms[i], type_, 0, NULL, &num_devices); + // Runtime returns an error when no GPU devices are present + // instead of just returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + // printf("NumDevices: %i\n", num_devices); + platform = platforms[i]; + break; + } + } + delete platforms; + } + + /* + * If we could find our platform, use it, else die. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + // get gpu speed + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_MAX_CLOCK_FREQUENCY, + sizeof(maxClockFrequency_), + &maxClockFrequency_, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS, + sizeof(maxComputeUnits_), + &maxComputeUnits_, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (maxComputeUnits_ > 8) { + // printf("%i CUs reported; assuming 8 instead.", maxComputeUnits_); + maxComputeUnits_ = 8; + } + // printf("Compute Units: %i\n", maxComputeUnits_); + + // printf("Subtests: %i\n", _numSubTests); + + // create context + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + cl_uint tmp; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS, + sizeof(tmp), &tmp, NULL); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + // printf("NumComputeUnits: %u\n", tmp); + maxComputeUnits_ = static_cast(tmp); + // printf("NumComputeUnits: %lld\n", maxComputeUnits_); + EXIT("constructor"); +} + +OCLPerfKernelThroughput::~OCLPerfKernelThroughput() {} + +/******************************************************************************* + * Open - initializes test, compile GPU kernel + ******************************************************************************/ +void OCLPerfKernelThroughput::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + ENTER("open"); + /*********************************************************** + * select subtest + **********************************************************/ + int testIdx = + test + numKernelTypes * numMemPaths * numNumElements * numWorkSizes; + memPathIdx_ = testIdx % numMemPaths; + testIdx /= numMemPaths; + numElementsIdx_ = testIdx % numNumElements; + testIdx /= numNumElements; + workSizeIdx_ = testIdx % numWorkSizes; + testIdx /= numWorkSizes; + kernelTypeIdx_ = testIdx % numKernelTypes; + testIdx /= numKernelTypes; + + // float md1; + + // kernel values + switch (kernelTypeIdx_) { + case 0: // Matrix Multiply + // md1 = sqrt(1.f*numElements[numElementsIdx_]); + // printf("MD1: sqrt(%f) = %f\n", 1.f*numElements[numElementsIdx_],md1); + matrixDim1_ = static_cast(sqrt(1.f * numElements[numElementsIdx_])); + matrixDim2_ = matrixDim1_ * (int)workSize[workSizeIdx_]; + genShaderMatrixMultiply(); + work_dim_ = 2; + global_work_size_ = new size_t[work_dim_]; + global_work_size_[0] = ((matrixDim1_ - 1) / 16 + 1) * + 16; // matrixDim1_ < 16 ? 16 : matrixDim1_; + global_work_size_[1] = global_work_size_[0]; + local_work_size_ = new size_t[work_dim_]; + local_work_size_[0] = 16; + local_work_size_[1] = local_work_size_[0]; + /* + printf("Global: %ix%i; Local: %ix%i; Matrix: %ix%i\n", + global_work_size_[0], + global_work_size_[1], + local_work_size_[0], + local_work_size_[1], + matrixDim1_, + matrixDim2_ + ); + */ + input1BufferSize_ = + static_cast(matrixDim1_ * matrixDim2_ * sizeof(float)); + input2BufferSize_ = + static_cast(matrixDim2_ * matrixDim1_ * sizeof(float)); + output1BufferSize_ = + static_cast(matrixDim1_ * matrixDim1_ * sizeof(float)); + _reqDataSize = (1.0 * matrixDim1_ * matrixDim2_ * sizeof(float)) + + (1.0 * matrixDim2_ * matrixDim1_ * sizeof(float)) + + (1.0 * matrixDim1_ * matrixDim1_ * sizeof(float)); + break; + case 1: // Flops/Byte + flopsPerByte_ = (int)workSize[workSizeIdx_]; // for kernelType == 0 + genShaderMadds(); + numWorkGroupsPerComputeUnit_ = 32; // TODO + numThreads_ = + numWorkGroupsPerComputeUnit_ * maxComputeUnits_ * WORK_GROUP_SIZE; + work_dim_ = 1; + global_work_size_ = new size_t[work_dim_]; + local_work_size_ = new size_t[work_dim_]; + global_work_size_[0] = numThreads_; + local_work_size_[0] = WORK_GROUP_SIZE; + input1BufferSize_ = + static_cast(numElements[numElementsIdx_] * sizeof(float4)); + input2BufferSize_ = 0; + output1BufferSize_ = + static_cast(numElements[numElementsIdx_] * sizeof(float4)); + _reqDataSize = 2.0 * numElements[numElementsIdx_] * sizeof(float4); + break; + } + + PKT(printf("Test Parameters:\n" + "\tkernelTypeIdx: %i\n" + "\tmemPathIdx: %i\n" + "\tnumElementsIdx: %i\n" + "\tworkSizeIdx: %i\n" + "\n\n", + kernelTypeIdx_, memPathIdx_, numElementsIdx_, workSizeIdx_);) + + /*********************************************************** + * get context and queue + **********************************************************/ + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0; + _deviceId = deviceId; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + input1Buffer_ = 0; + output1Buffer_ = 0; + _errorFlag = false; // Reset error code so a single error + // doesn't prevent other subtests from running + _errorMsg = ""; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present + // instead of just returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + delete platforms; + } + + /* + * If we could find our platform, use it, else die. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* + * Get the requested device + */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + device = devices[0]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, + CL_QUEUE_PROFILING_ENABLE, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + // Global memory size + cl_ulong _maxMemoryAllocationSize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, + sizeof(cl_ulong), + &_maxMemoryAllocationSize, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, + "clGetDeviceIDs(CL_DEVICE_GLOBAL_MEM_SIZE) failed"); +#if 0 + printf("Buffer Sizes: %i %i %i = %f\n", + input1BufferSize_, + input2BufferSize_, + output1BufferSize_, + _reqDataSize); +#endif + _dataSizeTooBig = (_reqDataSize > _maxMemoryAllocationSize); + if (_dataSizeTooBig) { + // printf("DATA TOO LARGE FOR DEVICE !!!"); + return; + } + + // create kernel + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + std::string args; + args.clear(); + error_ = + _wrapper->clBuildProgram(program_, 1, &device, args.c_str(), NULL, NULL); + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "kernel1", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + /*********************************************************** + * Allocate GPU Memory + **********************************************************/ + cl_mem_flags inputBufferFlags = 0; + cl_mem_flags outputBufferFlags = 0; + + // choose gpu source buffer type + switch (memPathIdx_) { + case 0: // host memory + // printf("Allocating Host Memories\n"); + // allocate "device" memory + inputBufferFlags = CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR; + outputBufferFlags = CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR; + input1Buffer_ = _wrapper->clCreateBuffer( + context_, inputBufferFlags, input1BufferSize_, NULL, &error_); + CHECK_RESULT(input1Buffer_ == 0, "clCreateBuffer Input failed"); + if (input1Buffer_ == 0) printf("Error: %i\n", error_); + if (input2BufferSize_) { + input2Buffer_ = _wrapper->clCreateBuffer( + context_, inputBufferFlags, input2BufferSize_, NULL, &error_); + CHECK_RESULT(input2Buffer_ == 0, "clCreateBuffer Input failed"); + } + output1Buffer_ = _wrapper->clCreateBuffer( + context_, outputBufferFlags, output1BufferSize_, NULL, &error_); + CHECK_RESULT(output1Buffer_ == 0, "clCreateBuffer Input failed"); + if (output1Buffer_ == 0) printf("Error: %i\n", error_); + + // map host memory + input1Ptr_ = (float *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, input1Buffer_, true, CL_MAP_WRITE, 0, input1BufferSize_, + 0, NULL, NULL, &error_); + if (input2BufferSize_) { + input2Ptr_ = (float *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, input2Buffer_, true, CL_MAP_WRITE, 0, input2BufferSize_, + 0, NULL, NULL, &error_); + } + output1Ptr_ = (float *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, output1Buffer_, true, CL_MAP_READ, 0, output1BufferSize_, + 0, NULL, NULL, &error_); + _wrapper->clFinish(cmd_queue_); + break; + + case 1: // device memory + // printf("Allocating Device Memories\n"); + // allocate device memory + inputBufferFlags = CL_MEM_READ_WRITE; + outputBufferFlags = CL_MEM_READ_WRITE; + input1Buffer_ = _wrapper->clCreateBuffer( + context_, inputBufferFlags, input1BufferSize_, NULL, &error_); + CHECK_RESULT(input1Buffer_ == 0, "clCreateBuffer Input failed"); + if (input2BufferSize_) { + input2Buffer_ = _wrapper->clCreateBuffer( + context_, inputBufferFlags, input2BufferSize_, NULL, &error_); + CHECK_RESULT(input2Buffer_ == 0, "clCreateBuffer Input failed"); + } + output1Buffer_ = _wrapper->clCreateBuffer( + context_, outputBufferFlags, output1BufferSize_, NULL, &error_); + CHECK_RESULT(output1Buffer_ == 0, "clCreateBuffer Input failed"); + // printf("\tDone Allocating Device Memory\n"); + + // allocate host memory + input1Ptr_ = new float[input1BufferSize_ / sizeof(float)]; + if (input2BufferSize_) { + input2Ptr_ = new float[input2BufferSize_ / sizeof(float)]; + } + output1Ptr_ = new float[output1BufferSize_ / sizeof(float)]; + // printf("\tDone Allocating Host Memory\n"); + + break; + default: + CHECK_RESULT(1, "Invalid Memory Path Idx"); + // invalid + } + for (unsigned int i = 0; i < input1BufferSize_ / sizeof(float); i++) { + input1Ptr_[i] = initFloat; + } + for (unsigned int i = 0; i < input2BufferSize_ / sizeof(float); i++) { + input2Ptr_[i] = initFloat; + } + for (unsigned int i = 0; i < output1BufferSize_ / sizeof(float); i++) { + output1Ptr_[i] = zeroFloat; + } + +#if 0 + printf("Allocating GPU: %.0fMB, %.0fMB\n", + static_cast(1.f*input1BufferSize_/1024.f/1024.f), + static_cast(1.f*output1BufferSize_/1024.f/1024.f)); + input1Buffer_ = _wrapper->clCreateBuffer( + context_, inputBufferFlags, input1BufferSize_, NULL, &error_); + CHECK_RESULT(input1Buffer_ == 0, "clCreateBuffer Input failed"); + output1Buffer_ = _wrapper->clCreateBuffer( + context_, outputBufferFlags, output1BufferSize_, NULL, &error_); + CHECK_RESULT(output1Buffer_ == 0, "clCreateBuffer Output failed"); + error_ = /*_wrapper->*/clEnqueueFillBuffer( + cmd_queue_, input1Buffer_, &initFloat, sizeof(initFloat), + 0, input1BufferSize_, 0, NULL, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueFillBuffer failed"); + error_ = /*_wrapper->*/clEnqueueFillBuffer( + cmd_queue_, output1Buffer_, &zeroFloat, sizeof(zeroFloat), + 0, output1BufferSize_, 0, NULL, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueFillBuffer failed"); + + /*********************************************************** + * Set Kernel Args + **********************************************************/ + error_ = _wrapper->clSetKernelArg( + kernel_, 0, sizeof(input1Buffer_), (void *) &input1Buffer_); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg failed"); + error_ = _wrapper->clSetKernelArg( + kernel_, 1, sizeof(output1Buffer_), (void *) &output1Buffer_); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg failed"); +#endif + + EXIT("open"); +} + +/******************************************************************************* + * Run - execute full test once and return performance + ******************************************************************************/ +void OCLPerfKernelThroughput::run(void) { + ENTER("run"); + CPerfCounter timer; + if (!_dataSizeTooBig) { + // set kernel args +#if 1 + switch (kernelTypeIdx_) { + case 0: // Matrix Multiply + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(output1Buffer_), + (void *)&output1Buffer_); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg failed"); + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(input1Buffer_), + (void *)&input1Buffer_); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg failed"); + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(input2Buffer_), + (void *)&input2Buffer_); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg failed"); + break; + case 1: // Flops/Byte + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(input1Buffer_), + (void *)&input1Buffer_); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg failed"); + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(output1Buffer_), + (void *)&output1Buffer_); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg failed"); + break; + } +#endif + launchKernel(); + timer.Reset(); + timer.Start(); + for (int i = 0; i < MAX_LOOP_ITER; i++) { + launchKernel(); + } + timer.Stop(); + } // data not too large + double totalSec = _dataSizeTooBig ? 1 : timer.GetElapsedTime(); + // printf("Total Time: %f seconds\n", totalSec); + // printf("Average Kernel Time: %f seconds\n", totalSec / MAX_LOOP_ITER); + + // analyze performance + avgKernelTime_ = (float)(totalSec / MAX_LOOP_ITER * 1000000); // microseconds + double flopCount; + switch (kernelTypeIdx_) { + case 0: // Matrix Multiply + flopCount = (2.0 * matrixDim1_ * matrixDim1_ * matrixDim2_); + // printf("FlopCount = 2*%i*%i*%i=%f\n", + // matrixDim1_,matrixDim1_,matrixDim2_,flopCount); + bandwidth_ = (float)(1.f * _reqDataSize / 1024.f / 1024.f / 1024.f) * + 1000000.f / avgKernelTime_; // GB/s + gflops_ = (float)(1000000.f * flopCount / avgKernelTime_ / 1000000000.0); + break; + case 1: // Madds + flopCount = _reqDataSize * flopsPerByte_; + bandwidth_ = (float)(1.f * _reqDataSize / 1024.f / 1024.f / 1024.f) * + 1000000.f / avgKernelTime_; // GB/s + gflops_ = bandwidth_ * flopsPerByte_; + break; + } + if (_dataSizeTooBig) { + printf("REQUESTED DATA SIZE EXCEEDS GLOBAL MEMORY !!!\n"); + bandwidth_ = 0; + gflops_ = 0; + avgKernelTime_ = 0; + } + // here print out details + char buf[512]; + int bytesWritten; + bytesWritten = SNPRINTF( + buf, sizeof(buf), + "Kernel:%7s; " + "Work:%4i; " + "Buff:%11.0f; " + "Path:%7s; " + "%10.5e GB/s; " + "%10.5e GFlop/s; ", + kernelType[kernelTypeIdx_], static_cast(workSize[workSizeIdx_]), + _reqDataSize, memPath[memPathIdx_], bandwidth_, gflops_); + testDescString = buf; + _perfInfo = avgKernelTime_; + if (!_dataSizeTooBig) checkData(); + EXIT("run"); +} + +void OCLPerfKernelThroughput::launchKernel(void) { + ENTER("launchKernel") + /*********************************************************** + * Copy Data To + **********************************************************/ + // printf("Copying Data To Device\n"); + switch (memPathIdx_) { + case 0: // zero copy + // do nothing + // void *inputPtr = _wrapper->clEnqueueMapBuffer( + // cmd_queue_, input1Buffer_, true, CL_MAP_READ, + // 0, input1BufferSize_, 0, NULL, NULL, &error_); + // void *outputPtr = _wrapper->clEnqueueMapBuffer( + // cmd_queue_, output1Buffer_, true, CL_MAP_READ, + // 0, output1BufferSize_, 0, NULL, NULL, &error_); + //_wrapper->clFinish(cmd_queue_); + break; + case 1: // explicit copy to device memory + // printf("Queue: %p\n", &cmd_queue_); + // printf("devBuffer: %i\n", input1Buffer_); + // printf("hstBuffer: %p\n", input1Ptr_); + // printf("bufSize: %i\n", input1BufferSize_); + error_ = _wrapper->clEnqueueWriteBuffer( + cmd_queue_, input1Buffer_, true, 0, input1BufferSize_, + (const void *)input1Ptr_, 0, NULL, NULL); + if (input2BufferSize_) { + error_ = _wrapper->clEnqueueWriteBuffer( + cmd_queue_, input2Buffer_, true, 0, input2BufferSize_, + (const void *)input2Ptr_, 0, NULL, NULL); + } + // printf("Error: %i\n", error_); + std::fflush(stdout); + _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_ != CL_SUCCESS, "clWriteBuffer failed"); + //_error = _wrapper->clEnqueueWriteBuffer( + // cmd_queue_, output1Buffer_, true, 0, output1BufferSize_, + // (const void *)output1Ptr_, 0, NULL, NULL ); + // CHECK_RESULT(error_ != CL_SUCCESS, "clWriteBuffer failed"); + break; + } + + /*********************************************************** + * Set Kernel Args + **********************************************************/ +#if 0 + error_ = _wrapper->clSetKernelArg( + kernel_, 0, sizeof(input1Buffer_), (void *) &input1Buffer_); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg failed"); + error_ = _wrapper->clSetKernelArg( + kernel_, 1, sizeof(output1Buffer_), (void *) &output1Buffer_); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg failed"); +#endif + + // printf("Launching Kernel: %ix%i threads\n", global_work_size_[0], + // local_work_size_[0]); + + /*********************************************************** + * Launch Kernel + **********************************************************/ + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, work_dim_, NULL, (const size_t *)global_work_size_, + (const size_t *)local_work_size_, 0, NULL, NULL); + // printf("Error: %i\n", error_); + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue_); + + /*********************************************************** + * Copy Data From + **********************************************************/ + // printf("Copying Data From Device\n"); + switch (memPathIdx_) { + case 0: // zero copy + // do nothing + // void *inputPtr = _wrapper->clEnqueueMapBuffer( + // cmd_queue_, input1Buffer_, true, CL_MAP_READ, + // 0, input1BufferSize_, 0, NULL, NULL, &error_); + // void *outputPtr = _wrapper->clEnqueueMapBuffer( + // cmd_queue_, output1Buffer_, true, CL_MAP_READ, + // 0, output1BufferSize_, 0, NULL, NULL, &error_); + //_wrapper->clFinish(cmd_queue_); + break; + case 1: // explicit copy to device memory + //_error = _wrapper->clEnqueueReadBuffer( + // cmd_queue_, input1Buffer_, true, 0, input1BufferSize_, + // (void *)input1Ptr_, 0, NULL, NULL ); + // CHECK_RESULT(error_ != CL_SUCCESS, "clWriteBuffer failed"); + // printf("VAL0 %p + error_ = _wrapper->clEnqueueReadBuffer( + cmd_queue_, output1Buffer_, true, 0, output1BufferSize_, + (void *)output1Ptr_, 0, NULL, NULL); + // printf("Error: %i\n", error_); + CHECK_RESULT(error_ != CL_SUCCESS, "clWriteBuffer failed"); + break; + } + + EXIT("launchKernel") +} + +/******************************************************************************* + * Check Data + ******************************************************************************/ +void OCLPerfKernelThroughput::checkData() { + _wrapper->clFinish(cmd_queue_); + float errorThreshhold = 0.00001f; + float eqMax = gold_ + errorThreshhold * gold_; + float eqMin = gold_ - errorThreshhold * gold_; + /* + printf("%ix%i * %ix%i = %ix%i:\n", + matrixDim1_, matrixDim2_, + matrixDim2_, matrixDim1_, + matrixDim1_, matrixDim1_ + ); + */ + for (unsigned int i = 0; i < output1BufferSize_ / sizeof(float); i++) { + float value = output1Ptr_[i]; + bool equal = (value > eqMin && value < eqMax); + if (!equal) { +#if 0 + printf("Output[%i] = %.6e; gold_ = %.6e; %s\n", + i, + value, + gold_, + equal ? "Equal" : "NOT Equal"); +#endif + // printf("FAILURE\n"); + // CHECK_RESULT_NO_RETURN(1, "Data validation failed!\n"); + _errorFlag = true; + break; + } else { + // printf("M[%i] = %.6e\n", i, output1Ptr_[i]); + } + } +} + +/******************************************************************************* + * Close - delete all data and release opencl objects + ******************************************************************************/ +unsigned int OCLPerfKernelThroughput::close(void) { + ENTER("close"); + _wrapper->clFinish(cmd_queue_); + + if (global_work_size_) { + delete[] global_work_size_; + global_work_size_ = NULL; + } + if (local_work_size_) { + delete[] local_work_size_; + local_work_size_ = NULL; + } + // switch for memory type + switch (memPathIdx_) { + case 0: // zero copy + // unmap ptr + if (input1Ptr_) { + error_ = /*_wrapper->*/ clEnqueueUnmapMemObject( + cmd_queue_, input1Buffer_, input1Ptr_, 0, NULL, NULL); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clEnqueueUnmapMemObject(input_) failed"); + _wrapper->clFinish(cmd_queue_); + error_ = _wrapper->clReleaseMemObject(input1Buffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(input1Buffer_) failed"); + input1Buffer_ = 0; + } + if (input2Ptr_) { + error_ = /*_wrapper->*/ clEnqueueUnmapMemObject( + cmd_queue_, input2Buffer_, input2Ptr_, 0, NULL, NULL); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clEnqueueUnmapMemObject(input_) failed"); + _wrapper->clFinish(cmd_queue_); + error_ = _wrapper->clReleaseMemObject(input2Buffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(input2Buffer_) failed"); + input2Buffer_ = 0; + } + if (output1Ptr_) { + error_ = /*_wrapper->*/ clEnqueueUnmapMemObject( + cmd_queue_, output1Buffer_, output1Ptr_, 0, NULL, NULL); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clEnqueueUnmapMemObject(output_) failed"); + _wrapper->clFinish(cmd_queue_); + error_ = _wrapper->clReleaseMemObject(output1Buffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(input1Buffer_) failed"); + output1Buffer_ = 0; + } + break; + case 1: // explicit copy to device memory + // release object + if (input1Buffer_) { + error_ = _wrapper->clReleaseMemObject(input1Buffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(input1Buffer_) failed"); + input1Buffer_ = 0; + } + if (input2Buffer_) { + error_ = _wrapper->clReleaseMemObject(input2Buffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(input2Buffer_) failed"); + input2Buffer_ = 0; + } + if (output1Buffer_) { + error_ = _wrapper->clReleaseMemObject(output1Buffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(input1Buffer_) failed"); + output1Buffer_ = 0; + } + if (input1Ptr_) { + delete[] input1Ptr_; + input1Ptr_ = 0; + } + if (input2Ptr_) { + delete[] input2Ptr_; + input2Ptr_ = 0; + } + if (output1Ptr_) { + delete[] output1Ptr_; + output1Ptr_ = 0; + } + break; + } + + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + kernel_ = 0; + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + program_ = 0; + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + cmd_queue_ = 0; + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + context_ = 0; + } + _wrapper->clFinish(cmd_queue_); + + EXIT("close"); + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfKernelThroughput.h b/opencl/tests/ocltst/module/perf/OCLPerfKernelThroughput.h new file mode 100644 index 0000000000..7e459eb5b6 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfKernelThroughput.h @@ -0,0 +1,118 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +/******************************************************************************* + * Kernel Throughput + * + * + * + * + * + * + ******************************************************************************/ + +#ifndef _OCL_KernelThroughput_H_ +#define _OCL_KernelThroughput_H_ + +#ifdef WIN32 +#include "xmmintrin.h" +#endif + +#include "OCLTestImp.h" +//#include +//#define WIN32_LEAN_AND_MEAN //Restricts windows.h to include only the core +//API. #include "windows.h" #undef Yield #include #include +// #include #include + +#define LARGE_INT long long +#define UNSIGNED_LARGE_INT unsigned long long +#define MAX_LOOP_ITER 10 +typedef cl_float4 float4; +typedef void (*CPUKernel)(__m128 *, __m128 *, unsigned int); + +class OCLPerfKernelThroughput : public OCLTestImp { + public: + OCLPerfKernelThroughput(); + virtual ~OCLPerfKernelThroughput(); + + public: + virtual void open(unsigned int test, char *units, double &conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void genShaderMadds(); + void genShaderMatrixMultiply(); + void checkData(); + // void allocateBuffers(); + void launchKernel(); + + // test parameters + int kernelTypeIdx_; + int memPathIdx_; + int numElementsIdx_; + int workSizeIdx_; + float gold_; + double _reqDataSize; + bool _dataSizeTooBig; + + // device attributes + cl_uint maxComputeUnits_; + cl_uint maxClockFrequency_; + + LARGE_INT numComputeUnits_; + LARGE_INT numWorkGroupsPerComputeUnit_; + LARGE_INT numThreads_; + cl_uint work_dim_; + size_t *global_work_size_; + size_t *local_work_size_; + + // opencl objects + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_int error_; + + // buffer sizes + + // kernel-specific values + int flopsPerByte_; + int matrixDim1_, matrixDim2_; + + // buffers + size_t input1BufferSize_; + size_t input2BufferSize_; + size_t output1BufferSize_; + cl_mem input1Buffer_; + cl_mem input2Buffer_; + cl_mem output1Buffer_; + float *input1Ptr_; + float *input2Ptr_; + float *output1Ptr_; + + // performance results + float bandwidth_; // GB/s + float gflops_; // GFlop/s + float avgKernelTime_; // microseconds +}; + +#endif // _OCL_KernelThroughput_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfLDSLatency.cpp b/opencl/tests/ocltst/module/perf/OCLPerfLDSLatency.cpp new file mode 100644 index 0000000000..6ffc4278f5 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfLDSLatency.cpp @@ -0,0 +1,432 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfLDSLatency.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +static const unsigned int NUM_SIZES = 5; +// 2k up to 64MB +static const unsigned int Sizes[NUM_SIZES] = {2048, 4096, 8192, 16384, 32768}; + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif +void OCLPerfLDSLatency::genShader() { + shader_.clear(); + + // DO NOT PUBLISH + // Adopted from SiSoft Sandra 2013's memory latency test + shader_ += + "__kernel\n" + //"__attribute__((work_group_size_hint(1, 1, 1)))\n" + "void MemWalker(\n" + " global uint * restrict input,\n" + " global uint * restrict output,\n" + " const uint uCount, const uint uSize,\n" + " const uint uOffset, const int bMem, const uint repeats)\n" + "{\n" + " uint o = uOffset;\n" + " uint lid = get_local_id(0);\n" + " uint x = lid*o;\n" + " local uint lclData[8192];\n" + "\n" + " {\n" + " uint i = uCount;\n" + " while (i--) {\n" + " uint oldX = x;\n" + " x = input[x];\n" + " lclData[oldX] = x;\n" + " }\n" + " }\n" + "\n" + " x = lid*uOffset;\n" + " for (uint loop = 0; loop < repeats; loop++) {\n" + " uint i = uCount;\n" + " while (i--) {\n" + " x = lclData[x] + o;\n" + " }\n" + " }\n" + "\n" + " output[0] = x;\n" + "}\n"; + + // printf("shader:\n%s\n", shader_.c_str()); + shader_ += "\n\n"; + shader_ += + "__kernel\n" + //"__attribute__((work_group_size_hint(1, 1, 1)))\n" + "void Overhead(\n" + " global uint * restrict input,\n" + " global uint * restrict output,\n" + " const uint uCount, const uint uSize,\n" + " const uint uOffset, const int bMem, const uint repeats)\n" + "{\n" + " local uint lclData[8192];\n" + "#ifdef USE_FLOAT\n" + " {\n" + " uint x = 0;\n" + " uint i = uCount;\n" + " while (i--) {\n" + " uint oldX = x;\n" + " x = input[x] /* + o*/;\n" + " lclData[oldX] = x;\n" + " }\n" + " }\n" + " float x = (float)input[0];\n" + " for (uint loop = 0; loop < repeats; loop++) {\n" + " uint i = uCount;\n" + " x = (float)uOffset*x;\n" + " while (i--) {\n" + " x += (float)i;\n" + " }\n" + " }\n" + " output[0] = (uint)x + uOffset*lclData[8191];\n" + "#else\n" + " {\n" + " uint x = 0;\n" + " uint i = uCount;\n" + " while (i--) {\n" + " uint oldX = x;\n" + " x = input[x] /* + o*/;\n" + " lclData[oldX] = x;\n" + " }\n" + " }\n" + " uint x = input[0];\n" + " for (uint loop = 0; loop < repeats; loop++) {\n" + " uint i = uCount;\n" + " x = x*uOffset;\n" + " while (i--) {\n" + " x += i;\n" + " }\n" + " }\n" + " output[0] = x + uOffset*lclData[8191];\n" + "#endif\n" + "}\n"; +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +OCLPerfLDSLatency::OCLPerfLDSLatency() { + _numSubTests = NUM_SIZES * 2; + maxSize_ = Sizes[NUM_SIZES - 1] * 2048; +} + +OCLPerfLDSLatency::~OCLPerfLDSLatency() {} + +void OCLPerfLDSLatency::setData(cl_mem buffer, unsigned int val) { + void *ptr = + _wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, CL_MAP_WRITE, 0, + width_, 0, NULL, NULL, &error_); + unsigned int *data = (unsigned int *)ptr; + for (unsigned int i = 0; i < bufSizeDW_; i++) { + data[(i * (1024 + 17)) % bufSizeDW_] = ((i + 1) * (1024 + 17)) % bufSizeDW_; + } + error_ = + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, ptr, 0, NULL, NULL); + clFinish(cmd_queue_); +} + +void OCLPerfLDSLatency::checkData(cl_mem buffer) { + void *ptr = + _wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, CL_MAP_READ, 0, + sizeof(cl_uint), 0, NULL, NULL, &error_); + + unsigned int *data = (unsigned int *)ptr; + if (data[0] != 0) { + printf("OutData= 0x%08x\n", data[0]); + CHECK_RESULT_NO_RETURN(data[0] != 0, "Data validation failed!\n"); + } + error_ = + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, ptr, 0, NULL, NULL); +} + +void OCLPerfLDSLatency::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + moreThreads = false; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + inBuffer_ = 0; + outBuffer_ = 0; + _errorFlag = false; // Reset error code so a single error doesn't prevent + // other subtests from running + _errorMsg = ""; + isAMD_ = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD_ = true; + } + } + + delete platforms; + } + + width_ = Sizes[test % NUM_SIZES]; + + bufSizeDW_ = width_ / sizeof(cl_uint); + moreThreads = ((test / NUM_SIZES) % 2) ? true : false; + + CHECK_RESULT(platform == 0, "Couldn't find OpenCL platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "Failed to allocate devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + device = devices[0]; + + free(devices); + devices = NULL; + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_uint flags; + flags = 0; + inBuffer_ = _wrapper->clCreateBuffer(context_, flags, width_, NULL, &error_); + CHECK_RESULT(inBuffer_ == 0, "clCreateBuffer(inBuffer) failed"); + + outBuffer_ = + _wrapper->clCreateBuffer(context_, 0, 1 * sizeof(cl_uint), NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + genShader(); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + std::string args; + args.clear(); + if (isAMD_) args += " -D USE_FLOAT"; + + error_ = + _wrapper->clBuildProgram(program_, 1, &device, args.c_str(), NULL, NULL); + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "MemWalker", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel(MemWalker) failed"); + + kernel2_ = _wrapper->clCreateKernel(program_, "Overhead", &error_); + CHECK_RESULT(kernel2_ == 0, "clCreateKernel(Overhead) failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&inBuffer_); + error_ = + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), (void *)&outBuffer_); + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), + (void *)&bufSizeDW_); + error_ = _wrapper->clSetKernelArg(kernel_, 3, sizeof(cl_uint), + (void *)&bufSizeDW_); + unsigned int zero = 0; + error_ = _wrapper->clSetKernelArg(kernel_, 4, sizeof(cl_uint), (void *)&zero); + int bMem = 1; + error_ = _wrapper->clSetKernelArg(kernel_, 5, sizeof(cl_int), (void *)&bMem); + // Limit the repeats, large buffers will have more samples, but the test runs + // for a long time + repeats_ = std::max((maxSize_ >> 4) / bufSizeDW_, 1u); + error_ = + _wrapper->clSetKernelArg(kernel_, 6, sizeof(cl_uint), (void *)&repeats_); + + error_ = + _wrapper->clSetKernelArg(kernel2_, 0, sizeof(cl_mem), (void *)&inBuffer_); + error_ = _wrapper->clSetKernelArg(kernel2_, 1, sizeof(cl_mem), + (void *)&outBuffer_); + error_ = _wrapper->clSetKernelArg(kernel2_, 2, sizeof(cl_uint), + (void *)&bufSizeDW_); + error_ = _wrapper->clSetKernelArg(kernel2_, 3, sizeof(cl_uint), + (void *)&bufSizeDW_); + error_ = + _wrapper->clSetKernelArg(kernel2_, 4, sizeof(cl_uint), (void *)&zero); + error_ = _wrapper->clSetKernelArg(kernel2_, 5, sizeof(cl_int), (void *)&bMem); + error_ = + _wrapper->clSetKernelArg(kernel2_, 6, sizeof(cl_uint), (void *)&repeats_); + + setData(inBuffer_, (int)1.0f); +} + +void OCLPerfLDSLatency::run(void) { + int global = 1; + int local = 1; + + if (moreThreads) { + if (isAMD_) { + global *= 64; + local *= 64; + } else { + global *= 32; + local *= 32; + } + } + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + // Warm-up + unsigned int warmup = 128; + error_ = + _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), (void *)&warmup); + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), + (void *)&bufSizeDW_); + _wrapper->clFinish(cmd_queue_); + + // Restore input buffer when finished as it may have been modified by RW test + setData(inBuffer_, (int)1.0f); + + CPerfCounter timer, timer2; + + timer.Reset(); + timer.Start(); + + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + + checkData(outBuffer_); + + timer2.Reset(); + timer2.Start(); + + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel2_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + + _wrapper->clFinish(cmd_queue_); + + timer2.Stop(); + double sec = timer.GetElapsedTime() - timer2.GetElapsedTime(); + + // Read latency in ns + double perf = sec * (double)(1e09) / ((double)bufSizeDW_ * (double)repeats_); + + _perfInfo = (float)perf; + char buf[256]; + char buf2[32]; + buf2[0] = '\0'; + SNPRINTF(buf, sizeof(buf), "%10s %2d threads, %8d reads, %5d repeats (ns)", + buf2, global, bufSizeDW_, repeats_); + testDescString = buf; +} + +unsigned int OCLPerfLDSLatency::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (inBuffer_) { + error_ = _wrapper->clReleaseMemObject(inBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (kernel2_) { + error_ = _wrapper->clReleaseKernel(kernel2_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfLDSLatency.h b/opencl/tests/ocltst/module/perf/OCLPerfLDSLatency.h new file mode 100644 index 0000000000..ebeb9c5dba --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfLDSLatency.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_LDSLATENCY_H_ +#define _OCL_LDSLATENCY_H_ + +#include "OCLTestImp.h" + +class OCLPerfLDSLatency : public OCLTestImp { + public: + OCLPerfLDSLatency(); + virtual ~OCLPerfLDSLatency(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void genShader(void); + void setData(cl_mem buffer, unsigned int data); + void checkData(cl_mem buffer); + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_kernel kernel2_; + cl_mem inBuffer_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int width_; + unsigned int bufSizeDW_; + unsigned int repeats_; + unsigned int maxSize_; + bool isAMD_; + bool moreThreads; +}; + +#endif // _OCL_LDSLATENCY_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfLDSReadSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfLDSReadSpeed.cpp new file mode 100644 index 0000000000..e8a6a5d353 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfLDSReadSpeed.cpp @@ -0,0 +1,395 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfLDSReadSpeed.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 4 +// 256KB, 1 MB, 4MB, 16 MB +static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304, + 16777216}; + +void OCLPerfLDSReadSpeed::genShader(unsigned int idx) { + shader_.clear(); + if (idx == 0) { + shader_ += + "__kernel __attribute__((reqd_work_group_size(64,1,1))) void " + "_ldsReadSpeed(__global float *outBuf, float c)\n" + "{\n" + " uint gid = (int) get_global_id(0);\n" + " uint lid = (int) get_local_id(0);\n" + " __local float localLocal[2048];\n" + " float val1 = c;\n" + " float val2 = c;\n" + " float val3 = c;\n" + " float val4 = c;\n" + " uint hacklid = gid % 64;\n" + " for (int i = 0; i < (2048/64); i++) {\n" + " localLocal[hacklid + i*64] = lid;\n" + " }\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + " val1 += localLocal[lid+0];\n" + " val2 += localLocal[lid+64];\n" + " val3 += localLocal[lid+128];\n" + " val4 += localLocal[lid+192];\n" + " val1 += localLocal[lid+256];\n" + " val2 += localLocal[lid+320];\n" + " val3 += localLocal[lid+384];\n" + " val4 += localLocal[lid+448];\n" + " val1 += localLocal[lid+512];\n" + " val2 += localLocal[lid+576];\n" + " val3 += localLocal[lid+640];\n" + " val4 += localLocal[lid+704];\n" + " val1 += localLocal[lid+768];\n" + " val2 += localLocal[lid+832];\n" + " val3 += localLocal[lid+896];\n" + " val4 += localLocal[lid+960];\n" + " val1 += localLocal[lid+1024];\n" + " val2 += localLocal[lid+1088];\n" + " val3 += localLocal[lid+1152];\n" + " val4 += localLocal[lid+1216];\n" + " val1 += localLocal[lid+1280];\n" + " val2 += localLocal[lid+1344];\n" + " val3 += localLocal[lid+1408];\n" + " val4 += localLocal[lid+1472];\n" + " val1 += localLocal[lid+1536];\n" + " val2 += localLocal[lid+1600];\n" + " val3 += localLocal[lid+1664];\n" + " val4 += localLocal[lid+1728];\n" + " val1 += localLocal[lid+1792];\n" + " val2 += localLocal[lid+1856];\n" + " val3 += localLocal[lid+1920];\n" + " val4 += localLocal[lid+1984];\n" + " outBuf[gid] = val1+val2+val3+val4;\n" + "}\n"; + ldsSizeBytes_ = 2048 * 4; + } else if (idx == 1) { + shader_ += + "__kernel __attribute__((reqd_work_group_size(64,1,1))) void " + "_ldsReadSpeed(__global float *outBuf, float c)\n" + "{\n" + " uint gid = (uint) get_global_id(0);\n" + " int lid = (int) get_local_id(0);\n" + " __local float localLocal[768];\n" + " float val0 = 0.0f;\n" + " float val1 = 0.0f;\n" + " uint hacklid = gid % 64;\n" + " for (int i = 0; i < (768/64); i++) {\n" + " localLocal[hacklid + i*64] = lid;\n" + " }\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + "#pragma nounroll\n" + "for (uint i = 0; i < 32;i++)\n" + "{\n" + " val0 += localLocal[lid+0];\n" + " val1 += localLocal[lid+64];\n" + " val0 += localLocal[lid+128];\n" + " val1 += localLocal[lid+192];\n" + " val0 += localLocal[lid+256];\n" + " val1 += localLocal[lid+320];\n" + " val0 += localLocal[lid+384];\n" + " val1 += localLocal[lid+448];\n" + " lid += 1;\n" + "}\n" + "val0 += val1;\n" + "val1 = min(val0,1.0f);\n" + "if ((lid + val1) < 0){\n" + " outBuf[gid] = val0;\n" + "}\n" + "}\n"; + ldsSizeBytes_ = 768 * 4; + } else { + shader_ += + "__kernel __attribute__((reqd_work_group_size(64,1,1))) void " + "_ldsReadSpeed(__global float *outBuf, float c)\n" + "{\n" + " uint gid = (uint) get_global_id(0);\n" + " int lid = (int) get_local_id(0);\n" + " __local float localLocal[256];\n" + " float val0 = 0.0f;\n" + " float val1 = 0.0f;\n" + " uint hacklid = gid % 64;\n" + " for (int i = 0; i < (256/64); i++) {\n" + " localLocal[hacklid + i*64] = lid;\n" + " }\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + "#pragma nounroll\n" + "for (uint i = 0; i < 32;i++)\n" + "{\n" + " val0 += localLocal[8*i+0];\n" + " val1 += localLocal[8*i+1];\n" + " val0 += localLocal[8*i+2];\n" + " val1 += localLocal[8*i+3];\n" + " val0 += localLocal[8*i+4];\n" + " val1 += localLocal[8*i+5];\n" + " val0 += localLocal[8*i+6];\n" + " val1 += localLocal[8*i+7];\n" + "}\n" + "val0 += val1;\n" + "val1 = min(val0,1.0f);\n" + "if ((lid + val1) < 0){\n" + " outBuf[gid] = val0;\n" + "}\n" + "}\n"; + ldsSizeBytes_ = 256 * 4; + } +} + +OCLPerfLDSReadSpeed::OCLPerfLDSReadSpeed() { _numSubTests = NUM_SIZES * 3; } + +OCLPerfLDSReadSpeed::~OCLPerfLDSReadSpeed() {} + +void OCLPerfLDSReadSpeed::setData(cl_mem buffer, float val) { + float *data = (float *)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, + CL_MAP_WRITE, 0, bufSize_, + 0, NULL, NULL, &error_); + for (unsigned int i = 0; i < (bufSize_ >> 2); i++) data[i] = val; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); + _wrapper->clFinish(cmd_queue_); +} + +void OCLPerfLDSReadSpeed::checkData(cl_mem buffer) { + float *data = (float *)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, + CL_MAP_READ, 0, bufSize_, + 0, NULL, NULL, &error_); + for (unsigned int i = 0; i < (bufSize_ >> 2); i++) { + if (data[i] != (float)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, numReads_, + numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); + _wrapper->clFinish(cmd_queue_); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfLDSReadSpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + outBuffer_ = 0; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + // if (num_devices > 0) + //{ + // platform = platforms[_platformIndex]; + // break; + //} +#if 0 + } +#endif + delete platforms; + } + + numReads_ = 32; + width_ = Sizes[test % NUM_SIZES]; + shaderIdx_ = test / NUM_SIZES; + + bufSize_ = width_; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + outBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + genShader(shaderIdx_); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &device, "", NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "_ldsReadSpeed", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + float foo = 0; + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&outBuffer_); + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_float), (void *)&foo); + + setData(outBuffer_, 1.2345678f); +} + +void OCLPerfLDSReadSpeed::run(void) { + int global = bufSize_ / sizeof(cl_float); + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < NUM_ITER; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + char buf[256]; + const char *buf2; + if (shaderIdx_ == 0) { + buf2 = " def kernel"; + } else if (shaderIdx_ == 1) { + buf2 = "SI friendly"; + numReads_ *= 8; + } else { + buf2 = " broadcast"; + numReads_ *= 8; + } + // LDS bandwidth in GB/s + // We have one extra write per LDS location to initialize LDS + double perf = + ((double)global * (numReads_ * sizeof(cl_float) + ldsSizeBytes_ / 64) * + NUM_ITER * (double)(1e-09)) / + sec; + + _perfInfo = (float)perf; + SNPRINTF(buf, sizeof(buf), " %s %8d threads, %3d reads (GB/s) ", buf2, global, + numReads_); + testDescString = buf; + // checkData(outBuffer_); +} + +unsigned int OCLPerfLDSReadSpeed::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfLDSReadSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfLDSReadSpeed.h new file mode 100644 index 0000000000..ed8222b5db --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfLDSReadSpeed.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_LDSReadSpeed_H_ +#define _OCL_LDSReadSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfLDSReadSpeed : public OCLTestImp { + public: + OCLPerfLDSReadSpeed(); + virtual ~OCLPerfLDSReadSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void genShader(unsigned int idx); + void setData(cl_mem buffer, float data); + void checkData(cl_mem buffer); + + static const unsigned int NUM_ITER = 100; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int width_; + unsigned int bufSize_; + unsigned int vecSizeIdx_; + unsigned int numReads_; + unsigned int shaderIdx_; + unsigned int ldsSizeBytes_; +}; + +#endif // _OCL_LDSReadSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMandelbrot.cpp b/opencl/tests/ocltst/module/perf/OCLPerfMandelbrot.cpp new file mode 100644 index 0000000000..e0cd5b37e6 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMandelbrot.cpp @@ -0,0 +1,940 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfMandelbrot.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +typedef struct { + double x; + double y; + double width; +} coordRec; + +coordRec coords[] = { + {0.0, 0.0, 4.0}, // Whole set + {0.0, 0.0, 0.00001}, // All black + {-0.0180789661868, 0.6424294066162, 0.00003824140}, // Hit detail +}; + +static unsigned int numCoords = sizeof(coords) / sizeof(coordRec); + +static const char *float_mandel = + "__kernel void mandelbrot(__global uint *out, uint width, float xPos, " + "float yPos, float xStep, float yStep, uint maxIter)\n" + "{\n" + " int tid = get_global_id(0);\n" + " int i = tid % width;\n" + " int j = tid / width;\n" + " float x0 = (float)(xPos + xStep*i);\n" + " float y0 = (float)(yPos + yStep*j);\n" + "\n" + " float x = x0;\n" + " float y = y0;\n" + "\n" + " uint iter = 0;\n" + " float tmp;\n" + " for (iter = 0; (x*x + y*y <= 4.0f) && (iter < maxIter); iter++)\n" + " {\n" + " tmp = x;\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + " }\n" + " out[tid] = iter;\n" + "}\n"; + +static const char *float_mandel_vec = + "__kernel void mandelbrot(__global uint *out, uint width, float xPos, " + "float yPos, float xStep, float yStep, uint maxIter)\n" + "{\n" + " int tid = get_global_id(0);\n" + " int i = tid % (width/4);\n" + " int j = tid / (width/4);\n" + " int4 veci = (int4)(4*i, 4*i+1, 4*i+2, 4*i+3);\n" + " int4 vecj = (int4)(j, j, j, j);\n" + " float4 x0;\n" + " x0.s0 = (float)(xPos + xStep*veci.s0);\n" + " x0.s1 = (float)(xPos + xStep*veci.s1);\n" + " x0.s2 = (float)(xPos + xStep*veci.s2);\n" + " x0.s3 = (float)(xPos + xStep*veci.s3);\n" + " float4 y0;\n" + " y0.s0 = (float)(yPos + yStep*vecj.s0);\n" + " y0.s1 = (float)(yPos + yStep*vecj.s1);\n" + " y0.s2 = (float)(yPos + yStep*vecj.s2);\n" + " y0.s3 = (float)(yPos + yStep*vecj.s3);\n" + "\n" + " float4 x = x0;\n" + " float4 y = y0;\n" + "\n" + " uint iter = 0;\n" + " float4 tmp;\n" + " int4 stay;\n" + " int4 ccount = 0;\n" + " float4 savx = x;\n" + " float4 savy = y;\n" + " stay = (x*x+y*y) <= (float4)(4.0f, 4.0f, 4.0f, 4.0f);\n" + " for (iter = 0; (stay.s0 | stay.s1 | stay.s2 | stay.s3) && (iter < " + "maxIter); iter+=16)\n" + " {\n" + " x = savx;\n" + " y = savy;\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " stay = (x*x+y*y) <= (float4)(4.0f, 4.0f, 4.0f, 4.0f);\n" + " savx = select(savx,x,stay);\n" + " savy = select(savy,y,stay);\n" + " ccount -= stay*16;\n" + " }\n" + " // Handle remainder\n" + " if (!(stay.s0 & stay.s1 & stay.s2 & stay.s3))\n" + " {\n" + " iter = 16;\n" + " do\n" + " {\n" + " x = savx;\n" + " y = savy;\n" + " // More efficient to use scalar ops here: Why?\n" + " stay.s0 = ((x.s0*x.s0+y.s0*y.s0) <= 4.0f) && (ccount.s0 < " + "maxIter);\n" + " stay.s1 = ((x.s1*x.s1+y.s1*y.s1) <= 4.0f) && (ccount.s1 < " + "maxIter);\n" + " stay.s2 = ((x.s2*x.s2+y.s2*y.s2) <= 4.0f) && (ccount.s2 < " + "maxIter);\n" + " stay.s3 = ((x.s3*x.s3+y.s3*y.s3) <= 4.0f) && (ccount.s3 < " + "maxIter);\n" + " tmp = x;\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + " ccount += stay;\n" + " iter--;\n" + " savx.s0 = (stay.s0 ? x.s0 : savx.s0);\n" + " savx.s1 = (stay.s1 ? x.s1 : savx.s1);\n" + " savx.s2 = (stay.s2 ? x.s2 : savx.s2);\n" + " savx.s3 = (stay.s3 ? x.s3 : savx.s3);\n" + " savy.s0 = (stay.s0 ? y.s0 : savy.s0);\n" + " savy.s1 = (stay.s1 ? y.s1 : savy.s1);\n" + " savy.s2 = (stay.s2 ? y.s2 : savy.s2);\n" + " savy.s3 = (stay.s3 ? y.s3 : savy.s3);\n" + " } while ((stay.s0 | stay.s1 | stay.s2 | stay.s3) && iter);\n" + " }\n" + " __global uint4 *vecOut = (__global uint4 *)out;\n" + " vecOut[tid] = convert_uint4(ccount);\n" + "}\n"; + +static const char *float_mandel_unroll = + "__kernel void mandelbrot(__global uint *out, uint width, float xPos, " + "float yPos, float xStep, float yStep, uint maxIter)\n" + "{\n" + " int tid = get_global_id(0);\n" + " int i = tid % width;\n" + " int j = tid / width;\n" + " float x0 = (float)(xPos + xStep*(float)i);\n" + " float y0 = (float)(yPos + yStep*(float)j);\n" + "\n" + " float x = x0;\n" + " float y = y0;\n" + "\n" + "#define FAST\n" + " uint iter = 0;\n" + " float tmp;\n" + " int stay;\n" + " int ccount = 0;\n" + " stay = (x*x+y*y) <= 4.0;\n" + " float savx = x;\n" + " float savy = y;\n" + "#ifdef FAST\n" + " for (iter = 0; (iter < maxIter); iter+=16)\n" + "#else\n" + " for (iter = 0; stay && (iter < maxIter); iter+=16)\n" + "#endif\n" + " {\n" + " x = savx;\n" + " y = savy;\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " stay = (x*x+y*y) <= 4.0;\n" + " savx = select(savx,x,stay);\n" + " savy = select(savy,y,stay);\n" + " ccount += stay*16;\n" + "#ifdef FAST\n" + " if (!stay)\n" + " break;\n" + "#endif\n" + " }\n" + " // Handle remainder\n" + " if (!stay)\n" + " {\n" + " iter = 16;\n" + " do\n" + " {\n" + " x = savx;\n" + " y = savy;\n" + " stay = ((x*x+y*y) <= 4.0) && (ccount < maxIter);\n" + " tmp = x;\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + " ccount += stay;\n" + " iter--;\n" + " savx = select(savx,x,stay);\n" + " savy = select(savy,y,stay);\n" + " } while (stay && iter);\n" + " }\n" + " out[tid] = (uint)ccount;\n" + "}\n"; + +static const char *double_mandel = + "#ifdef USE_CL_AMD_FP64\n" + "#pragma OPENCL EXTENSION cl_amd_fp64 : enable\n" + "#endif\n" + "#ifdef USE_CL_KHR_FP64\n" + "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n" + "#endif\n" + "__kernel void mandelbrot(__global uint *out, uint width, double xPos, " + "double yPos, double xStep, double yStep, uint maxIter)\n" + "{\n" + " int tid = get_global_id(0);\n" + " int i = tid % width;\n" + " int j = tid / width;\n" + " double x0 = (double)(xPos + xStep*i);\n" + " double y0 = (double)(yPos + yStep*j);\n" + "\n" + " double x = x0;\n" + " double y = y0;\n" + "\n" + " uint iter = 0;\n" + " double tmp;\n" + " for (iter = 0; (x*x + y*y <= 4.0) && (iter < maxIter); iter++)\n" + " {\n" + " tmp = x;\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + " }\n" + " out[tid] = iter;\n" + "}\n"; + +static const char *double_mandel_unroll = + "#ifdef USE_CL_AMD_FP64\n" + "#pragma OPENCL EXTENSION cl_amd_fp64 : enable\n" + "#endif\n" + "#ifdef USE_CL_KHR_FP64\n" + "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n" + "#endif\n" + "__kernel void mandelbrot(__global uint *out, uint width, double xPos, " + "double yPos, double xStep, double yStep, uint maxIter)\n" + "{\n" + " int tid = get_global_id(0);\n" + " int i = tid % width;\n" + " int j = tid / width;\n" + " double x0 = (double)(xPos + xStep*(double)i);\n" + " double y0 = (double)(yPos + yStep*(double)j);\n" + "\n" + " double x = x0;\n" + " double y = y0;\n" + "\n" + "#define FAST\n" + " uint iter = 0;\n" + " double tmp;\n" + " int stay;\n" + " int ccount = 0;\n" + " stay = (x*x+y*y) <= 4.0;\n" + " double savx = x;\n" + " double savy = y;\n" + "#ifdef FAST\n" + " for (iter = 0; (iter < maxIter); iter+=16)\n" + "#else\n" + " for (iter = 0; stay && (iter < maxIter); iter+=16)\n" + "#endif\n" + " {\n" + " x = savx;\n" + " y = savy;\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " // Two iterations\n" + " tmp = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*x,y,y0);\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(tmp,tmp,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + "\n" + " stay = (x*x+y*y) <= 4.0;\n" + " savx = (stay ? x : savx);//select(savx,x,stay);\n" + " savy = (stay ? y : savy);//select(savy,y,stay);\n" + " ccount += stay*16;\n" + "#ifdef FAST\n" + " if (!stay)\n" + " break;\n" + "#endif\n" + " }\n" + " // Handle remainder\n" + " if (!stay)\n" + " {\n" + " iter = 16;\n" + " do\n" + " {\n" + " x = savx;\n" + " y = savy;\n" + " stay = ((x*x+y*y) <= 4.0) && (ccount < maxIter);\n" + " tmp = x;\n" + " x = MUL_ADD_INS(-y,y,MUL_ADD_INS(x,x,x0));\n" + " y = MUL_ADD_INS(2.0f*tmp,y,y0);\n" + " ccount += stay;\n" + " iter--;\n" + " savx = (stay ? x : savx);//select(savx,x,stay);\n" + " savy = (stay ? y : savy);//select(savy,y,stay);\n" + " } while (stay && iter);\n" + " }\n" + " out[tid] = (uint)ccount;\n" + "}\n"; + +static const unsigned int FMA_EXPECTEDVALUES_INDEX = 15; + +// Expected results for each kernel run at each coord +unsigned long long expectedIters[] = { + 203277748ull, 2147483648ull, 120254651ull, 203277748ull, 2147483648ull, + 120254651ull, 203277748ull, 2147483648ull, 120254651ull, 203315114ull, + 2147483648ull, 120042599ull, 203315114ull, 2147483648ull, 120042599ull, + 203280620ull, 2147483648ull, 120485704ull, 203280620ull, 2147483648ull, + 120485704ull, 203280620ull, 2147483648ull, 120485704ull, 203315114ull, + 2147483648ull, 120042599ull, 203315114ull, 2147483648ull, 120042599ull}; + +// nvidia supports CL_KHR_FP64, so they get better results for doubles. Not +// sure why we differ in floats though +unsigned long long expectedItersNV[] = { + 203277748ull, 2147483648ull, 120254651ull, 203277748ull, + 2147483648ull, 120254651ull, 203277748ull, 2147483648ull, + 120254651ull, 203315226ull, 2147483648ull, 120091921ull, + 203315226ull, 2147483648ull, 120091921ull, // end of mad + 203280620ull, 2147483648ull, 120485704ull, 203280620ull, + 2147483648ull, 120485704ull, 203280620ull, 2147483648ull, + 120485704ull, 203315114ull, 2147483648ull, 120042599ull, + 203315114ull, 2147483648ull, 120042599ull}; + +const char *shaderStr[] = {" float_mad", " float_vector_mad", + " float_unroll_mad", " double_mad", + "double_unroll_mad", " float_fma", + " float_vector_fma", " float_unroll_fma", + " double_fma", "double_unroll_fma"}; + +OCLPerfMandelbrot::OCLPerfMandelbrot() { _numSubTests = 10 * numCoords; } + +OCLPerfMandelbrot::~OCLPerfMandelbrot() {} + +void OCLPerfMandelbrot::setData(cl_mem buffer, unsigned int val) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, buffer, true, CL_MAP_WRITE, 0, bufSize_, 0, NULL, NULL, + &error_); + for (unsigned int i = 0; i < width_ * width_; i++) data[i] = val; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +void OCLPerfMandelbrot::checkData(cl_mem buffer) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, buffer, true, CL_MAP_READ, 0, bufSize_, 0, NULL, NULL, + &error_); + for (unsigned int i = 0; i < width_ * width_; i++) { + totalIters += data[i]; + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfMandelbrot::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + skip = false; + totalIters = 0; + isAMD = false; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + outBuffer_ = 0; + + // Maximum iteration count + // NOTE: Some kernels are unrolled 16 times, so make sure maxIter is divisible + // by 16 NOTE: Can increase to get better peak performance numbers, but be + // sure not to TDR slow ASICs! + unsigned int maxIter = 32768; + + // NOTE: Width needs to be divisible by 4 because the float_mandel_vec kernel + // processes 4 pixels at once NOTE: Can increase to get better peak + // performance numbers, but be sure not to TDR slow ASICs! + width_ = 256; + + // We compute a square domain + bufSize_ = width_ * width_ * sizeof(cl_uint); + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + // Get last for default +#if 0 + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); +#if 0 + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + platform = platforms[i]; + break; + } +#endif + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + platform = platforms[_platformIndex]; + } +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, + "Couldn't find platform with GPU devices, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + doubleSupport = false; + + char *p = strstr(charbuf, "cl_amd_fp64"); + char *p2 = strstr(charbuf, "cl_khr_fp64"); + + if (p || p2) + doubleSupport = true; + else + doubleSupport = false; + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + outBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + const char *tmp; + shaderIdx = _openTest / numCoords; + if ((doubleSupport != true) && ((shaderIdx == 3) || (shaderIdx == 4) || + (shaderIdx == 8) || (shaderIdx == 9))) { + // We don't support doubles, so skip those tests + skip = true; + _perfInfo = 0.0f; + return; + } + + if (shaderIdx == 0 || shaderIdx == 5) { + tmp = float_mandel; + } else if (shaderIdx == 1 || shaderIdx == 6) { + tmp = float_mandel_vec; + } else if (shaderIdx == 2 || shaderIdx == 7) { + tmp = float_mandel_unroll; + } else if (shaderIdx == 3 || shaderIdx == 8) { + tmp = double_mandel; + } else { + tmp = double_mandel_unroll; + } + std::string curr(tmp); + std::string searchString("MUL_ADD_INS"); + std::string replaceString; + if (shaderIdx < 5) { + replaceString = "mad"; + } else { + replaceString = "fma"; + } + + std::string::size_type pos = 0; + while ((pos = curr.find(searchString, pos)) != std::string::npos) { + curr.replace(pos, searchString.size(), replaceString); + pos++; + } + + tmp = curr.c_str(); + + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + const char *buildOps = NULL; + if (p) + buildOps = "-DUSE_CL_AMD_FP64"; + else if (p2) + buildOps = "-DUSE_CL_KHR_FP64"; + error_ = _wrapper->clBuildProgram(program_, 1, &device, buildOps, NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "mandelbrot", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + coordIdx = _openTest % numCoords; + if ((shaderIdx == 0) || (shaderIdx == 1) || (shaderIdx == 2) || + (shaderIdx == 5) || (shaderIdx == 6) || (shaderIdx == 7)) { + float xStep = (float)(coords[coordIdx].width / (double)width_); + float yStep = (float)(-coords[coordIdx].width / (double)width_); + float xPos = (float)(coords[coordIdx].x - 0.5 * coords[coordIdx].width); + float yPos = (float)(coords[coordIdx].y + 0.5 * coords[coordIdx].width); + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&outBuffer_); + error_ = + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_uint), (void *)&width_); + error_ = + _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_float), (void *)&xPos); + error_ = + _wrapper->clSetKernelArg(kernel_, 3, sizeof(cl_float), (void *)&yPos); + error_ = + _wrapper->clSetKernelArg(kernel_, 4, sizeof(cl_float), (void *)&xStep); + error_ = + _wrapper->clSetKernelArg(kernel_, 5, sizeof(cl_float), (void *)&yStep); + error_ = + _wrapper->clSetKernelArg(kernel_, 6, sizeof(cl_uint), (void *)&maxIter); + } else { + double xStep = coords[coordIdx].width / (double)width_; + double yStep = -coords[coordIdx].width / (double)width_; + double xPos = coords[coordIdx].x - 0.5 * coords[coordIdx].width; + double yPos = coords[coordIdx].y + 0.5 * coords[coordIdx].width; + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&outBuffer_); + error_ = + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_uint), (void *)&width_); + error_ = + _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_double), (void *)&xPos); + error_ = + _wrapper->clSetKernelArg(kernel_, 3, sizeof(cl_double), (void *)&yPos); + error_ = + _wrapper->clSetKernelArg(kernel_, 4, sizeof(cl_double), (void *)&xStep); + error_ = + _wrapper->clSetKernelArg(kernel_, 5, sizeof(cl_double), (void *)&yStep); + error_ = + _wrapper->clSetKernelArg(kernel_, 6, sizeof(cl_uint), (void *)&maxIter); + } + setData(outBuffer_, 0xdeadbeef); +} + +void OCLPerfMandelbrot::run(void) { + if (skip) return; + int global = width_ * width_; + // We handle 4 pixels per thread + if ((shaderIdx == 1) || (shaderIdx == 6)) global >>= 2; + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + // Warm-up + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue_); + + double totalTime = 0.0; + + for (unsigned int k = 0; k < numLoops; k++) { + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + totalTime += sec; + } + + checkData(outBuffer_); + // Compute GFLOPS. There are 7 FLOPs per iteration + double perf = ((double)totalIters * 7 * (double)(1e-09)) / + (totalTime / (double)numLoops); + + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " %s (GFLOPS) ", shaderStr[shaderIdx]); + testDescString = buf; + // Dump iteration count + // printf(" totalIter = %lld\n", totalIters); + if (isAMD && (type_ == CL_DEVICE_TYPE_GPU)) { + CHECK_RESULT((totalIters != expectedIters[_openTest]) && + (totalIters != + expectedIters[(_openTest < FMA_EXPECTEDVALUES_INDEX + ? _openTest + FMA_EXPECTEDVALUES_INDEX + : _openTest)]), + "Incorrect iteration count detected!"); + } else { + CHECK_RESULT(totalIters != expectedItersNV[_openTest], + "Incorrect iteration count detected!"); + } +} + +unsigned int OCLPerfMandelbrot::close(void) { + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} + +OCLPerfAsyncMandelbrot::OCLPerfAsyncMandelbrot() {} + +OCLPerfAsyncMandelbrot::~OCLPerfAsyncMandelbrot() {} + +void OCLPerfAsyncMandelbrot::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + // Create common items first + OCLPerfMandelbrot::open(test, units, conversion, deviceId); + + // Create resources for async test + cmd_queue2_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue2_ == 0, "clCreateCommandQueue failed"); + + outBuffer2_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer2) failed"); +} + +void OCLPerfAsyncMandelbrot::run(void) { + if (skip) return; + int global = width_ * width_; + // We handle 4 pixels per thread + if ((shaderIdx == 1) || (shaderIdx == 6)) global >>= 2; + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + // Warm-up + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue_); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&outBuffer2_); + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue2_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue2_); + + double totalTime = 0.0; + + for (unsigned int k = 0; k < numLoops; k++) { + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&outBuffer_); + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&outBuffer2_); + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue2_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFlush(cmd_queue_); + _wrapper->clFlush(cmd_queue2_); + _wrapper->clFinish(cmd_queue_); + _wrapper->clFinish(cmd_queue2_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + totalTime += sec; + } + + checkData(outBuffer_); + checkData(outBuffer2_); + // Compute GFLOPS. There are 7 FLOPs per iteration + double perf = ((double)(totalIters * 7) * (double)(1e-09)) / + (totalTime / (double)numLoops); + + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " async %s (GFLOPS) ", shaderStr[shaderIdx]); + testDescString = buf; + // Dump iteration count + // printf(" totalIter = %lld\n", totalIters); + if (isAMD && (type_ == CL_DEVICE_TYPE_GPU)) { + CHECK_RESULT( + (totalIters != 2 * expectedIters[_openTest]) && + (totalIters != + 2 * expectedIters[(_openTest < FMA_EXPECTEDVALUES_INDEX + ? _openTest + FMA_EXPECTEDVALUES_INDEX + : _openTest)]), + "Incorrect iteration count detected!"); + } else { + CHECK_RESULT(totalIters != 2 * expectedItersNV[_openTest], + "Incorrect iteration count detected!"); + } +} + +unsigned int OCLPerfAsyncMandelbrot::close(void) { + _wrapper->clFinish(cmd_queue_); + _wrapper->clFinish(cmd_queue2_); + + // Clean up async test items + if (outBuffer2_) { + error_ = _wrapper->clReleaseMemObject(outBuffer2_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer2_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue2_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + // Clean up the rest + return OCLPerfMandelbrot::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMandelbrot.h b/opencl/tests/ocltst/module/perf/OCLPerfMandelbrot.h new file mode 100644 index 0000000000..7922f83a18 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMandelbrot.h @@ -0,0 +1,75 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_Mandelbrot_H_ +#define _OCL_Mandelbrot_H_ + +#include "OCLTestImp.h" + +class OCLPerfMandelbrot : public OCLTestImp { + public: + OCLPerfMandelbrot(); + virtual ~OCLPerfMandelbrot(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void setData(cl_mem buffer, unsigned int data); + void checkData(cl_mem buffer); + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem outBuffer_; + cl_int error_; + cl_device_id device; + + unsigned int width_; + unsigned int bufSize_; + bool doubleSupport; + bool skip; + unsigned int maxIter; + unsigned int shaderIdx; + unsigned int coordIdx; + unsigned long long totalIters; + bool isAMD; + static const unsigned int numLoops = 10; +}; + +class OCLPerfAsyncMandelbrot : public OCLPerfMandelbrot { + public: + OCLPerfAsyncMandelbrot(); + virtual ~OCLPerfAsyncMandelbrot(); + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + cl_command_queue cmd_queue2_; + cl_mem outBuffer2_; +}; + +#endif // _OCL_Mandelbrot_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMapBufferReadSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfMapBufferReadSpeed.cpp new file mode 100644 index 0000000000..0e655ffab1 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMapBufferReadSpeed.cpp @@ -0,0 +1,262 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfMapBufferReadSpeed.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 4 +// 256KB, 1 MB, 4MB, 16 MB +static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304, + 16777216}; + +static const unsigned int Iterations[2] = {1, + OCLPerfMapBufferReadSpeed::NUM_ITER}; +#define NUM_OFFSETS 1 +static const unsigned int offsets[NUM_OFFSETS] = {0}; +#define NUM_SUBTESTS (3 + NUM_OFFSETS) +OCLPerfMapBufferReadSpeed::OCLPerfMapBufferReadSpeed() { + _numSubTests = NUM_SIZES * NUM_SUBTESTS * 2; +} + +OCLPerfMapBufferReadSpeed::~OCLPerfMapBufferReadSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfMapBufferReadSpeed::open(unsigned int test, char *units, + double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + persistent = false; + allocHostPtr = false; + useHostPtr = false; + hostMem = NULL; + alignedMem = NULL; + alignment = 4096; + isAMD = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + bufSize_ = Sizes[_openTest % NUM_SIZES]; + if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) > 2) { + useHostPtr = true; + offset = offsets[((_openTest / NUM_SIZES) % NUM_SUBTESTS) - 3]; + } else if ((((_openTest / NUM_SIZES) % NUM_SUBTESTS) == 2) && isAMD) { + persistent = true; + } else if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) == 1) { + allocHostPtr = true; + } + + numIter = Iterations[_openTest / (NUM_SIZES * NUM_SUBTESTS)]; + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + if (persistent) { + flags |= CL_MEM_USE_PERSISTENT_MEM_AMD; + } else if (allocHostPtr) { + flags |= CL_MEM_ALLOC_HOST_PTR; + } else if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + hostMem = (char *)malloc(bufSize_ + alignment - 1 + offset); + CHECK_RESULT(hostMem == 0, "malloc(hostMem) failed"); + alignedMem = + (char *)((((intptr_t)hostMem + alignment - 1) & ~(alignment - 1)) + + offset); + } + outBuffer_ = + _wrapper->clCreateBuffer(context_, flags, bufSize_, alignedMem, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + // Force memory to be on GPU, if possible + { + cl_mem memBuffer = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(memBuffer == 0, "clCreateBuffer(memBuffer) failed"); + + _wrapper->clEnqueueCopyBuffer(cmd_queue_, memBuffer, outBuffer_, 0, 0, + bufSize_, 0, NULL, NULL); + _wrapper->clFinish(cmd_queue_); + + _wrapper->clReleaseMemObject(memBuffer); + } +} + +void OCLPerfMapBufferReadSpeed::run(void) { + CPerfCounter timer; + + void *mem; + // Warm up + mem = + _wrapper->clEnqueueMapBuffer(cmd_queue_, outBuffer_, CL_TRUE, CL_MAP_READ, + 0, bufSize_, 0, NULL, NULL, &error_); + + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, outBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapBuffer failed"); + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + mem = _wrapper->clEnqueueMapBuffer(cmd_queue_, outBuffer_, CL_TRUE, + CL_MAP_READ, 0, bufSize_, 0, NULL, NULL, + &error_); + + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, outBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapBuffer failed"); + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + } + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Map read bandwidth in GB/s + double perf = ((double)bufSize_ * numIter * (double)(1e-09)) / sec; + + if (persistent || allocHostPtr) { + _perfInfo = (float)(sec / numIter) * 1000000.0f; // Get us per map + } else { + _perfInfo = (float)perf; + } + char str[256]; + if (persistent) { + SNPRINTF(str, sizeof(str), "PERSISTENT (us)"); + } else if (allocHostPtr) { + SNPRINTF(str, sizeof(str), "ALLOC_HOST_PTR (us)"); + } else if (useHostPtr) { + SNPRINTF(str, sizeof(str), "off: %4d USE_HOST_PTR (GB/s)", offset); + } else { + SNPRINTF(str, sizeof(str), "(GB/s)"); + } + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) i: %4d %29s ", bufSize_, numIter, + str); + testDescString = buf; +} + +unsigned int OCLPerfMapBufferReadSpeed::close(void) { + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + if (hostMem) { + free(hostMem); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMapBufferReadSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfMapBufferReadSpeed.h new file mode 100644 index 0000000000..4171086f62 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMapBufferReadSpeed.h @@ -0,0 +1,56 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_MapBufferReadSpeed_H_ +#define _OCL_MapBufferReadSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfMapBufferReadSpeed : public OCLTestImp { + public: + OCLPerfMapBufferReadSpeed(); + virtual ~OCLPerfMapBufferReadSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 1000; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int bufSize_; + bool persistent; + bool allocHostPtr; + bool useHostPtr; + unsigned int numIter; + char* hostMem; + char* alignedMem; + size_t alignment; + unsigned int offset; + bool isAMD; +}; + +#endif // _OCL_MapBufferReadSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMapBufferWriteSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfMapBufferWriteSpeed.cpp new file mode 100644 index 0000000000..b22db68b22 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMapBufferWriteSpeed.cpp @@ -0,0 +1,291 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfMapBufferWriteSpeed.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 4 +// 256KB, 1 MB, 4MB, 16 MB +static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304, + 16777216}; + +static const unsigned int Iterations[2] = { + 1, OCLPerfMapBufferWriteSpeed::NUM_ITER}; +#define NUM_OFFSETS 1 +static const unsigned int offsets[NUM_OFFSETS] = {0}; +#define NUM_SUBTESTS (3 + NUM_OFFSETS) +OCLPerfMapBufferWriteSpeed::OCLPerfMapBufferWriteSpeed() { + _numSubTests = NUM_SIZES * NUM_SUBTESTS * 3; +} + +OCLPerfMapBufferWriteSpeed::~OCLPerfMapBufferWriteSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfMapBufferWriteSpeed::open(unsigned int test, char *units, + double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + persistent = false; + allocHostPtr = false; + useHostPtr = false; + hostMem = NULL; + alignedMem = NULL; + alignment = 4096; + isAMD = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + char getVersion[128]; + error_ = _wrapper->clGetPlatformInfo(platform, CL_PLATFORM_VERSION, + sizeof(getVersion), getVersion, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + platformVersion[0] = getVersion[7]; + platformVersion[1] = getVersion[8]; + platformVersion[2] = getVersion[9]; + platformVersion[3] = '\0'; + + bufSize_ = Sizes[_openTest % NUM_SIZES]; + if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) > 2) { + useHostPtr = true; + offset = offsets[((_openTest / NUM_SIZES) % NUM_SUBTESTS) - 3]; + } else if ((((_openTest / NUM_SIZES) % NUM_SUBTESTS) == 2) && isAMD) { + persistent = true; + } else if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) == 1) { + allocHostPtr = true; + } + + numIter = Iterations[std::min(_openTest / (NUM_SIZES * NUM_SUBTESTS), 1u)]; + + if (_openTest < NUM_SIZES * NUM_SUBTESTS * 2) { + mapFlags = CL_MAP_WRITE; + } else { + mapFlags = CL_MAP_WRITE_INVALIDATE_REGION; + } + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_READ_ONLY; + if (persistent) { + flags |= CL_MEM_USE_PERSISTENT_MEM_AMD; + } else if (allocHostPtr) { + flags |= CL_MEM_ALLOC_HOST_PTR; + } else if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + hostMem = (char *)malloc(bufSize_ + alignment - 1 + offset); + CHECK_RESULT(hostMem == 0, "malloc(hostMem) failed"); + alignedMem = + (char *)((((intptr_t)hostMem + alignment - 1) & ~(alignment - 1)) + + offset); + } + outBuffer_ = + _wrapper->clCreateBuffer(context_, flags, bufSize_, alignedMem, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + // Force memory to be on GPU if possible + { + cl_mem memBuffer = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(memBuffer == 0, "clCreateBuffer(memBuffer) failed"); + + _wrapper->clEnqueueCopyBuffer(cmd_queue_, outBuffer_, memBuffer, 0, 0, + bufSize_, 0, NULL, NULL); + _wrapper->clFinish(cmd_queue_); + + _wrapper->clReleaseMemObject(memBuffer); + } +} + +void OCLPerfMapBufferWriteSpeed::run(void) { + CPerfCounter timer; + + if (_openTest >= NUM_SIZES * NUM_SUBTESTS * 2) { + // Skip CL_MAP_WRITE_INVALIDATE_REGION testing for 1.0 and 1.1 platforms + if ((platformVersion[0] == '1') && + ((platformVersion[2] == '0') || (platformVersion[2] == '1'))) { + char buf[256]; + SNPRINTF(buf, sizeof(buf), " SKIPPED "); + testDescString = buf; + return; + } + } + void *mem; + // Warm up + mem = _wrapper->clEnqueueMapBuffer(cmd_queue_, outBuffer_, CL_TRUE, mapFlags, + 0, bufSize_, 0, NULL, NULL, &error_); + + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, outBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapBuffer failed"); + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + mem = + _wrapper->clEnqueueMapBuffer(cmd_queue_, outBuffer_, CL_TRUE, mapFlags, + 0, bufSize_, 0, NULL, NULL, &error_); + + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, outBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapBuffer failed"); + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + } + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Map write bandwidth in GB/s + double perf = ((double)bufSize_ * numIter * (double)(1e-09)) / sec; + + if (persistent || allocHostPtr) { + _perfInfo = (float)(sec / numIter) * 1000000.0f; // Get us per map + } else { + _perfInfo = (float)perf; + } + char str[256]; + if (persistent) { + SNPRINTF(str, sizeof(str), "PERSISTENT (us)"); + } else if (allocHostPtr) { + SNPRINTF(str, sizeof(str), "ALLOC_HOST_PTR (us)"); + } else if (useHostPtr) { + SNPRINTF(str, sizeof(str), "off: %4d USE_HOST_PTR (GB/s)", offset); + } else { + SNPRINTF(str, sizeof(str), "(GB/s)"); + } + char str2[256]; + if (mapFlags == CL_MAP_WRITE_INVALIDATE_REGION) { + SNPRINTF(str2, sizeof(str2), "INV_REG %29s", str); + } else { + SNPRINTF(str2, sizeof(str2), "%29s", str); + } + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) i: %4d %37s ", bufSize_, numIter, + str2); + testDescString = buf; +} + +unsigned int OCLPerfMapBufferWriteSpeed::close(void) { + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + if (hostMem) { + free(hostMem); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMapBufferWriteSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfMapBufferWriteSpeed.h new file mode 100644 index 0000000000..7606f193d3 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMapBufferWriteSpeed.h @@ -0,0 +1,58 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_MapBufferWriteSpeed_H_ +#define _OCL_MapBufferWriteSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfMapBufferWriteSpeed : public OCLTestImp { + public: + OCLPerfMapBufferWriteSpeed(); + virtual ~OCLPerfMapBufferWriteSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 1000; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int bufSize_; + bool persistent; + bool allocHostPtr; + bool useHostPtr; + unsigned int numIter; + char* hostMem; + char* alignedMem; + size_t alignment; + unsigned int offset; + bool isAMD; + cl_map_flags mapFlags; + char platformVersion[32]; +}; + +#endif // _OCL_MapBufferWriteSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMapImageReadSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfMapImageReadSpeed.cpp new file mode 100644 index 0000000000..239680d4f8 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMapImageReadSpeed.cpp @@ -0,0 +1,225 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfMapImageReadSpeed.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 4 +static const unsigned int Sizes[NUM_SIZES] = {256, 512, 1024, 2048}; + +#define NUM_FORMATS 1 +static const cl_image_format formats[NUM_FORMATS] = { + {CL_RGBA, CL_UNSIGNED_INT8}}; +static const char *textFormats[NUM_FORMATS] = {"R8G8B8A8"}; +static const unsigned int formatSize[NUM_FORMATS] = {4}; + +static const unsigned int Iterations[2] = {1, + OCLPerfMapImageReadSpeed::NUM_ITER}; + +OCLPerfMapImageReadSpeed::OCLPerfMapImageReadSpeed() { + _numSubTests = NUM_SIZES * NUM_FORMATS * 2; +} + +OCLPerfMapImageReadSpeed::~OCLPerfMapImageReadSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfMapImageReadSpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint typeOfDevice = type_; + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + skip_ = false; + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], typeOfDevice, + 0, NULL, &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + // if (num_devices > 0) + //{ + // platform = platforms[_platformIndex]; + // break; + //} +#if 0 + } +#endif + delete platforms; + } + + bufSize_ = Sizes[_openTest % NUM_SIZES]; + bufnum_ = (_openTest / NUM_SIZES) % NUM_FORMATS; + numIter = Iterations[_openTest / (NUM_SIZES * NUM_FORMATS)]; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = _wrapper->clGetDeviceIDs(platform, typeOfDevice, num_devices, + devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + size_t size; + bool imageSupport_ = false; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport_), &imageSupport_, &size); + if (!imageSupport_) { + printf("\n%s\n", "Image not supported, skipping this test!"); + skip_ = true; + return; + } + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + outBuffer_ = _wrapper->clCreateImage2D(context_, flags, &formats[bufnum_], + bufSize_, bufSize_, 0, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateImage(outBuffer) failed"); +} + +void OCLPerfMapImageReadSpeed::run(void) { + if(skip_) { + return; + } + CPerfCounter timer; + void *mem; + + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSize_, bufSize_, 1}; + size_t image_row_pitch; + size_t image_slice_pitch; + // Warm up + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, outBuffer_, CL_TRUE, CL_MAP_READ, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, outBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapBuffer failed"); + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, outBuffer_, CL_TRUE, CL_MAP_READ, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, outBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapBuffer failed"); + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + } + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Image map read bandwidth in GB/s + double perf = ((double)bufSize_ * bufSize_ * formatSize[bufnum_] * numIter * + (double)(1e-09)) / + sec; + + _perfInfo = (float)perf; + + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%4dx%4d) fmt:%s i: %4d (GB/s) ", bufSize_, + bufSize_, textFormats[bufnum_], numIter); + testDescString = buf; +} + +unsigned int OCLPerfMapImageReadSpeed::close(void) { + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMapImageReadSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfMapImageReadSpeed.h new file mode 100644 index 0000000000..9902bf2322 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMapImageReadSpeed.h @@ -0,0 +1,50 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_MapImageReadSpeed_H_ +#define _OCL_MapImageReadSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfMapImageReadSpeed : public OCLTestImp { + public: + OCLPerfMapImageReadSpeed(); + virtual ~OCLPerfMapImageReadSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 100; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int bufSize_; + unsigned int bufnum_; + unsigned int numIter; + bool skip_; +}; + +#endif // _OCL_MapImageReadSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMapImageWriteSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfMapImageWriteSpeed.cpp new file mode 100644 index 0000000000..e4006288e3 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMapImageWriteSpeed.cpp @@ -0,0 +1,226 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfMapImageWriteSpeed.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 4 +static const unsigned int Sizes[NUM_SIZES] = {256, 512, 1024, 2048}; + +#define NUM_FORMATS 1 +static const cl_image_format formats[NUM_FORMATS] = { + {CL_RGBA, CL_UNSIGNED_INT8}}; +static const char *textFormats[NUM_FORMATS] = {"R8G8B8A8"}; +static const unsigned int formatSize[NUM_FORMATS] = {4}; + +static const unsigned int Iterations[2] = {1, + OCLPerfMapImageWriteSpeed::NUM_ITER}; + +OCLPerfMapImageWriteSpeed::OCLPerfMapImageWriteSpeed() { + _numSubTests = NUM_SIZES * NUM_FORMATS * 2; +} + +OCLPerfMapImageWriteSpeed::~OCLPerfMapImageWriteSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfMapImageWriteSpeed::open(unsigned int test, char *units, + double &conversion, + unsigned int deviceId) { + cl_uint typeOfDevice = type_; + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + skip_ = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], typeOfDevice, + 0, NULL, &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + // if (num_devices > 0) + //{ + // platform = platforms[_platformIndex]; + // break; + //} +#if 0 + } +#endif + delete platforms; + } + + bufSize_ = Sizes[_openTest % NUM_SIZES]; + bufnum_ = (_openTest / NUM_SIZES) % NUM_FORMATS; + numIter = Iterations[_openTest / (NUM_SIZES * NUM_FORMATS)]; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = _wrapper->clGetDeviceIDs(platform, typeOfDevice, num_devices, + devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + size_t size; + bool imageSupport_ = false; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport_), &imageSupport_, &size); + if (!imageSupport_) { + printf("\n%s\n", "Image not supported, skipping this test!"); + skip_ = true; + return; + } + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_READ_ONLY; + outBuffer_ = _wrapper->clCreateImage2D(context_, flags, &formats[bufnum_], + bufSize_, bufSize_, 0, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateImage(outBuffer) failed"); +} + +void OCLPerfMapImageWriteSpeed::run(void) { + if (skip_) { + return; + } + CPerfCounter timer; + + void *mem; + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSize_, bufSize_, 1}; + size_t image_row_pitch; + size_t image_slice_pitch; + // Warm up + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, outBuffer_, CL_TRUE, CL_MAP_WRITE, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, outBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapBuffer failed"); + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, outBuffer_, CL_TRUE, CL_MAP_WRITE, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, outBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapBuffer failed"); + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + } + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Image map write bandwidth in GB/s + double perf = ((double)bufSize_ * bufSize_ * formatSize[bufnum_] * numIter * + (double)(1e-09)) / + sec; + + _perfInfo = (float)perf; + + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%4dx%4d) fmt:%s i: %4d (GB/s) ", bufSize_, + bufSize_, textFormats[bufnum_], numIter); + testDescString = buf; +} + +unsigned int OCLPerfMapImageWriteSpeed::close(void) { + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMapImageWriteSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfMapImageWriteSpeed.h new file mode 100644 index 0000000000..bfb8f0aba3 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMapImageWriteSpeed.h @@ -0,0 +1,50 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_MapImageWriteSpeed_H_ +#define _OCL_MapImageWriteSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfMapImageWriteSpeed : public OCLTestImp { + public: + OCLPerfMapImageWriteSpeed(); + virtual ~OCLPerfMapImageWriteSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 100; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int bufSize_; + unsigned int bufnum_; + unsigned int numIter; + bool skip_; +}; + +#endif // _OCL_MapImageWriteSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMatrixTranspose.cpp b/opencl/tests/ocltst/module/perf/OCLPerfMatrixTranspose.cpp new file mode 100644 index 0000000000..a25899b4bc --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMatrixTranspose.cpp @@ -0,0 +1,326 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfMatrixTranspose.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +static const unsigned int NUM_BLOCK_SIZES = 2; +static const unsigned int blockSizes[NUM_BLOCK_SIZES] = {8, 16}; +static const unsigned int NUM_MATRIX_DIMS = 2; +static const unsigned int matrixDims[NUM_MATRIX_DIMS] = {1024, 1920}; +static const char *matrixtranspose_kernel = + "kernel void matrixTranspose(global uint *restrict inBuf, global uint " + "*restrict outBuf, local uint *localBuf, uint blockSize, uint width, uint " + "height)\n" + "{\n" + " uint globalIdx = get_global_id(0);\n" + " uint globalIdy = get_global_id(1);\n" + + " uint localIdx = get_local_id(0);\n" + " uint localIdy = get_local_id(1);\n" + + " /* copy from input to local memory */\n" + " /* Note that we transpose the x and y coordinates when storing */\n" + " localBuf[localIdx*blockSize + localIdy] = inBuf[globalIdy*width + " + "globalIdx];\n" + + " /* wait until the whole block is filled */\n" + " barrier(CLK_LOCAL_MEM_FENCE);\n" + + " uint groupIdx = get_group_id(0);\n" + " uint groupIdy = get_group_id(1);\n" + + " /* calculate the corresponding target location for transpose by " + "inverting x and y values*/\n" + " /* Here we don't swap localIdx and localIdy, this is to get larger " + "bursts when threads write to memory. */\n" + " /* To make this work, we've swapped the coordinates when we write to " + "local memory. */\n" + " uint targetGlobalIdx = groupIdy*blockSize + localIdx;\n" + " uint targetGlobalIdy = groupIdx*blockSize + localIdy;\n" + + " /* calculate the corresponding raster indices of source and target " + "*/\n" + " uint targetIndex = targetGlobalIdy*height + targetGlobalIdx;\n" + " uint sourceIndex = localIdy * blockSize + localIdx;\n" + + " outBuf[targetIndex] = localBuf[sourceIndex];\n" + "}\n"; + +OCLPerfMatrixTranspose::OCLPerfMatrixTranspose() { + _numSubTests = NUM_BLOCK_SIZES * NUM_MATRIX_DIMS; +} + +OCLPerfMatrixTranspose::~OCLPerfMatrixTranspose() {} + +void OCLPerfMatrixTranspose::setData(cl_mem buffer) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, buffer, true, CL_MAP_WRITE, 0, bufSize_, 0, NULL, NULL, + &error_); + for (unsigned int i = 0; i < height_; i++) { + for (unsigned int j = 0; j < width_; j++) { + *(data + i * width_ + j) = i * width_ + j; + } + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +void OCLPerfMatrixTranspose::fillData(cl_mem buffer, unsigned int val) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, buffer, true, CL_MAP_WRITE, 0, bufSize_, 0, NULL, NULL, + &error_); + for (unsigned int i = 0; i < width_ * height_; i++) { + data[i] = val; + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +void OCLPerfMatrixTranspose::checkData(cl_mem buffer) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, buffer, true, CL_MAP_READ, 0, bufSize_, 0, NULL, NULL, + &error_); + bool err = false; + for (unsigned int i = 0; (i < width_) && !err; i++) { + for (unsigned int j = 0; (j < height_) && !err; j++) { + if (*(data + i * height_ + j) != (j * width_ + i)) { + printf("Data mismatch at (%d, %d)! Got %d, expected %d\n", j, i, + *(data + i * height_ + j), j * width_ + i); + err = true; + break; + } + } + break; + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfMatrixTranspose::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + inBuffer_ = 0; + outBuffer_ = 0; + + blockSize_ = blockSizes[_openTest % NUM_BLOCK_SIZES]; + width_ = matrixDims[_openTest / NUM_BLOCK_SIZES]; + height_ = width_; + // We compute a square domain + bufSize_ = width_ * height_ * sizeof(cl_uint); + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, + "Couldn't find platform with GPU devices, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + inBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY, bufSize_, + NULL, &error_); + CHECK_RESULT(inBuffer_ == 0, "clCreateBuffer(inBuffer) failed"); + setData(inBuffer_); + + outBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, bufSize_, + NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + fillData(outBuffer_, 0xdeadbeef); + + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&matrixtranspose_kernel, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + char *buildOps = NULL; + error_ = _wrapper->clBuildProgram(program_, 1, &device, buildOps, NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "matrixTranspose", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&inBuffer_); + error_ = + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), (void *)&outBuffer_); + error_ = _wrapper->clSetKernelArg( + kernel_, 2, sizeof(cl_uint) * blockSize_ * blockSize_, NULL); + error_ = _wrapper->clSetKernelArg(kernel_, 3, sizeof(cl_uint), + (void *)&blockSize_); + error_ = + _wrapper->clSetKernelArg(kernel_, 4, sizeof(cl_uint), (void *)&width_); + error_ = + _wrapper->clSetKernelArg(kernel_, 5, sizeof(cl_uint), (void *)&height_); +} + +void OCLPerfMatrixTranspose::run(void) { + size_t global_work_size[2] = {width_, height_}; + size_t local_work_size[2] = {blockSize_, blockSize_}; + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < MAX_ITERATIONS; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 2, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + } + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + checkData(outBuffer_); + // Compute GB/s + double perf = + ((double)bufSize_ * (double)MAX_ITERATIONS * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + testDescString = ""; + char str[64]; + sprintf(str, "(%d,%d) matrix with (%2d,%2d) block size %fms (GB/s) ", width_, + height_, blockSize_, blockSize_, + (sec / (double)MAX_ITERATIONS) * 1000.); + testDescString += str; +} + +unsigned int OCLPerfMatrixTranspose::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (inBuffer_) { + error_ = _wrapper->clReleaseMemObject(inBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMatrixTranspose.h b/opencl/tests/ocltst/module/perf/OCLPerfMatrixTranspose.h new file mode 100644 index 0000000000..ff6185485e --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMatrixTranspose.h @@ -0,0 +1,57 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_MATRIX_TRANSPOSE_H_ +#define _OCL_MATRIX_TRANSPOSE_H_ + +#include "OCLTestImp.h" + +class OCLPerfMatrixTranspose : public OCLTestImp { + public: + OCLPerfMatrixTranspose(); + virtual ~OCLPerfMatrixTranspose(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void setData(cl_mem buffer); + void fillData(cl_mem buffer, unsigned int data); + void checkData(cl_mem buffer); + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem inBuffer_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int width_; + unsigned int height_; + unsigned int bufSize_; + unsigned int blockSize_; + static const unsigned int MAX_ITERATIONS = 50; +}; + +#endif // _OCL_MATRIX_TRANSPOSE_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMemCombine.cpp b/opencl/tests/ocltst/module/perf/OCLPerfMemCombine.cpp new file mode 100644 index 0000000000..f7839dae16 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMemCombine.cpp @@ -0,0 +1,234 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfMemCombine.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +struct TestParams { + const char* type; + unsigned int numCombine; + unsigned int assignSize; +}; + +TestParams testParams[] + // char type causes shader compiler to crash. reenable once get a fix for + // the shader compiler + //= {{"char", 16}, {"short", 8}, {"int", 4}, {"long", 4}, {"float", 4}}; + //= {{"char", 16, 1}, {"short", 8, 2}, {"int", 4, 4}, {"long", 4, 8}, + = {{"short", 8, 2}, {"int", 4, 4}, {"long", 4, 8}, {"float", 4, 4}, + {"char4", 4, 4}, {"uchar16", 4, 16}, {"short2", 4, 4}, {"int2", 4, 8}, + {"uint4", 4, 16}, {"long2", 4, 16}, {"float2", 4, 8}}; + +const int numTests = sizeof(testParams) / sizeof(TestParams); + +// Generate a kernel that does array loads and stores, which should be combined +// by MemCombine +void genCombineVLoadVStores(const char* type, int loopSize, int numCombine, + char* ret) { + sprintf(ret, + "__kernel void combine_vload_vstores(__global %s" + " * restrict src, __global %s *result) {\n", + type, type); + strcat(ret, " int id = get_global_id(0);\n"); + strcat(ret, " int gsize = get_global_size(0);\n"); + char buf[256]; + sprintf(buf, " for (int i = 0; i < %d; i+=gsize) {\n", loopSize); + strcat(ret, buf); + sprintf(buf, " int j = (i+id) * %d;\n", numCombine); + strcat(ret, buf); + for (int i = 0; i < numCombine; ++i) { + sprintf(buf, " result[j+%d] = src[j+%d];\n", i, i); + strcat(ret, buf); + } + strcat(ret, " }\n}\n"); +} + +void OCLPerfMemCombine::setData(cl_mem buffer, unsigned int bufSize, + unsigned char val) { + unsigned char* data = (unsigned char*)_wrapper->clEnqueueMapBuffer( + cmdQueues_[0], buffer, true, CL_MAP_WRITE, 0, bufSize, 0, NULL, NULL, + &error_); + for (unsigned int i = 0; i < bufSize; ++i) data[i] = val; + + error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues_[0], buffer, data, 0, + NULL, NULL); + _wrapper->clFinish(cmdQueues_[0]); +} + +void print1Darray(unsigned char* buffer, unsigned int bufSize) { + for (unsigned int i = 0; i < bufSize; ++i) { + if (i % 32 == 0) printf("\n"); + printf("%d ", buffer[i]); + } + printf("\n"); +} + +void OCLPerfMemCombine::checkData(cl_mem buffer, unsigned int bufSize, + unsigned int limit, unsigned char defVal) { + unsigned char* data = (unsigned char*)_wrapper->clEnqueueMapBuffer( + cmdQueues_[0], buffer, true, CL_MAP_READ, 0, bufSize, 0, NULL, NULL, + &error_); + for (unsigned int i = 0; i < bufSize; i++) { + unsigned char expected; + if (i < limit) { + expected = 1U; + } else { + expected = defVal; + } + if (data[i] != expected) { + printf("at index %d:\n", i); + print1Darray(&data[i], 16); + CHECK_RESULT(1, "incorrect output data detected!"); + break; + } + } + + error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues_[0], buffer, data, 0, + NULL, NULL); + _wrapper->clFinish(cmdQueues_[0]); +} + +OCLPerfMemCombine::OCLPerfMemCombine() { _numSubTests = numTests; } + +OCLPerfMemCombine::~OCLPerfMemCombine() {} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLPerfMemCombine::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + _openTest = test; + + context_ = 0; + kernel_ = NULL; + program_ = NULL; + + OCLTestImp::open(test, units, conversion, deviceId); + + cl_mem inBuffer = + _wrapper->clCreateBuffer(context_, 0, inSize_, NULL, &error_); + CHECK_RESULT(inBuffer == 0, "clCreateBuffer(inBuffer) failed"); + buffers_.push_back(inBuffer); + + cl_mem outBuffer = + _wrapper->clCreateBuffer(context_, 0, outSize_, NULL, &error_); + CHECK_RESULT(outBuffer == 0, "clCreateBuffer(outBuffer) failed"); + buffers_.push_back(outBuffer); + + createKernel(testParams[test].type, testParams[test].numCombine); + setData(inBuffer, inSize_, 1U); + setData(outBuffer, outSize_, 0); + dataRange_ = loopSize_ * numCombine_ * testParams[test].assignSize; +} + +void OCLPerfMemCombine::createKernel(const char* type, int numCombine) { + dataType_ = type; + numCombine_ = numCombine; + + ///////////////////////////////////////////////////////////////// + // Load CL file, build CL program object, create CL kernel object + ///////////////////////////////////////////////////////////////// + char source[1024]; + genCombineVLoadVStores(type, loopSize_, numCombine, source); + size_t sourceSize[] = {strlen(source)}; + const char* src = &source[0]; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &src, sourceSize, + &error_); + CHECK_RESULT(error_ != CL_SUCCESS, "clCreateProgramWithSource failed"); + + /* create a cl program executable for all the devices specified */ + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + return; + } + + /* get a kernel object handle for a kernel with the given name */ + const char* kernelName = "combine_vload_vstores"; + kernel_ = _wrapper->clCreateKernel(program_, kernelName, &error_); + CHECK_RESULT(error_ != CL_SUCCESS, "clCreateProgramWithSource failed"); + + /*** Set appropriate arguments to the kernel ***/ + /* the input array to the kernel */ + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void*)&buffers()[0]); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg failed"); + + /* the output array to the kernel */ + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), + (void*)&buffers()[1]); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg failed"); +} + +void OCLPerfMemCombine::run(void) { + size_t globalThreads[1]; + size_t localThreads[1]; + + globalThreads[0] = 64; + localThreads[0] = 64; + + CPerfCounter timer; + timer.Reset(); + timer.Start(); + + for (unsigned int i = 0; i < NUM_ITER; ++i) { + /* + * Enqueue a kernel run call. + */ + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[0], kernel_, 1, NULL, + globalThreads, localThreads, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + _wrapper->clFinish(cmdQueues_[0]); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + char buf[256]; + SNPRINTF(buf, sizeof(buf), "%d %-8s (sec)", numCombine_, dataType_); + testDescString = buf; + _perfInfo = (float)sec; + + checkData(buffers()[1], outSize_, dataRange_, 0); + return; +} + +unsigned int OCLPerfMemCombine::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMemCombine.h b/opencl/tests/ocltst/module/perf/OCLPerfMemCombine.h new file mode 100644 index 0000000000..98ad42be13 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMemCombine.h @@ -0,0 +1,56 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_MemCombine_H_ +#define _OCL_MemCombine_H_ + +#include "OCLTestImp.h" + +class OCLPerfMemCombine : public OCLTestImp { + enum { inSize_ = 4096U * 1024U }; + enum { outSize_ = 4096U * 1024U }; + enum { loopSize_ = 8192 }; + + public: + OCLPerfMemCombine(); + virtual ~OCLPerfMemCombine(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 1000; + + const char* dataType_; + unsigned int numCombine_; + unsigned int dataRange_; + unsigned char input[inSize_]; + unsigned char output[outSize_]; + + private: + void createKernel(const char* type, int numCombine); + void setData(cl_mem buffer, unsigned int bufSize, unsigned char val); + void checkData(cl_mem buffer, unsigned int bufSize, unsigned int limit, + unsigned char defVal); +}; + +#endif // _OCL_MemCombine_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMemCreate.cpp b/opencl/tests/ocltst/module/perf/OCLPerfMemCreate.cpp new file mode 100644 index 0000000000..2368de568c --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMemCreate.cpp @@ -0,0 +1,176 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfMemCreate.h" + +#include +#include +#include + +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +#if defined(_WIN32) && !defined(_WIN64) +static const size_t BufSize = 0x200000; +static const size_t BufSizeC = 0x100000; +#else +static const size_t BufSize = 0x400000; +static const size_t BufSizeC = 0x200000; +#endif + +static const size_t Iterations = 0x100; +static const size_t IterationsC = 0x1000; + +static const char* strKernel = + "__kernel void dummy(__global uint* out) \n" + "{ \n" + " uint id = get_global_id(0); \n" + " uint value = 1; \n" + " if ((int)get_local_id(0) < 0) \n" + " out[id] = value; \n" + "} \n"; + +#define NUM_TESTS 5 +OCLPerfMemCreate::OCLPerfMemCreate() { + _numSubTests = NUM_TESTS * 2; + failed_ = false; +} + +OCLPerfMemCreate::~OCLPerfMemCreate() {} + +void OCLPerfMemCreate::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + _deviceId = deviceId; + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + test_ = test % NUM_TESTS; + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + useSubBuf_ = (test >= NUM_TESTS); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + kernel_ = _wrapper->clCreateKernel(program_, "dummy", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLPerfMemCreate::run(void) { + if (failed_) { + return; + } + cl_mem buffer, subBuf; + cl_mem* bufptr; + unsigned int* values; + values = reinterpret_cast(new cl_int4[BufSize]); + CPerfCounter timer; + cl_mem_flags flags = CL_MEM_READ_ONLY; + void* hostPtr = NULL; + + // Clear destination buffer + memset(values, 0, BufSize * sizeof(cl_int4)); + + size_t bufSize = ((test_ % 2) == 0) ? BufSize * sizeof(cl_int4) + : BufSizeC * sizeof(cl_int4); + size_t iter = ((test_ % 2) == 0) ? Iterations : IterationsC; + + if (test_ == 4) { + hostPtr = values; + bufSize = 0x100000; + flags = CL_MEM_USE_HOST_PTR; + } else if ((test_ / 2) > 0) { + iter = ((test_ % 2) == 0) ? Iterations / 10 : IterationsC; + flags |= CL_MEM_ALLOC_HOST_PTR; + } + timer.Reset(); + timer.Start(); + + for (size_t i = 0; i < iter; ++i) { + buffer = + _wrapper->clCreateBuffer(context_, flags, bufSize, hostPtr, &error_); + bufptr = &buffer; + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + if (useSubBuf_) { + cl_buffer_region reg; + reg.origin = 0; + reg.size = bufSize; + subBuf = _wrapper->clCreateSubBuffer( + buffer, flags, CL_BUFFER_CREATE_TYPE_REGION, ®, &error_); + bufptr = &subBuf; + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateSubBuffer() failed"); + } + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), bufptr); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t gws[1] = {64}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + if (useSubBuf_) _wrapper->clReleaseMemObject(subBuf); + _wrapper->clReleaseMemObject(buffer); + } + + timer.Stop(); + std::stringstream stream; + + static const char* Message[] = {" create+destroy time [uncached] ", + " create+destroy time [cached ] "}; + static const char* Type[] = {"DEV", "AHP", "UHP"}; + + stream << Type[test_ / 2]; + stream << Message[test_ % 2]; + stream << " per allocation (ms) "; + stream << bufSize / 1024 << " KB"; + if (useSubBuf_) stream << " subbuf "; + testDescString = stream.str(); + _perfInfo = static_cast(timer.GetElapsedTime() * 1000 / iter); + + delete[] values; +} + +unsigned int OCLPerfMemCreate::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMemCreate.h b/opencl/tests/ocltst/module/perf/OCLPerfMemCreate.h new file mode 100644 index 0000000000..df7c7ab921 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMemCreate.h @@ -0,0 +1,43 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_MEM_CREATE_H_ +#define _OCL_PERF_MEM_CREATE_H_ + +#include "OCLTestImp.h" + +class OCLPerfMemCreate : public OCLTestImp { + public: + OCLPerfMemCreate(); + virtual ~OCLPerfMemCreate(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; + unsigned int test_; + bool useSubBuf_; +}; + +#endif // _OCL_PERF_MEM_CREATE_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMemLatency.cpp b/opencl/tests/ocltst/module/perf/OCLPerfMemLatency.cpp new file mode 100644 index 0000000000..558ccf1244 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMemLatency.cpp @@ -0,0 +1,418 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfMemLatency.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +static const unsigned int NUM_SIZES = 16; +// 2k up to 64MB +static const unsigned int Sizes[NUM_SIZES] = { + 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, + 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864}; +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif +void OCLPerfMemLatency::genShader() { + shader_.clear(); + + // DO NOT PUBLISH + // Adopted from SiSoft Sandra 2013's memory latency test + shader_ += + "#ifdef MAKEVOLATILE\n" + "#define VOLATILE volatile\n" + "#else\n" + "#define VOLATILE\n" + "#endif\n" + "__kernel\n" + //"__attribute__((work_group_size_hint(1, 1, 1)))\n" + "void MemWalker(\n" + " global VOLATILE uint * restrict input,\n" + " __global uint * restrict output,\n" + " const uint uCount, const uint uSize,\n" + " const uint uOffset, const int bMem, const uint repeats)\n" + "{\n" + " uint o = uOffset;\n" + " uint lid = 0;//get_local_id(0)*o;\n" + " uint x = lid;\n" + "\n" + " for (uint loop = 0; loop < repeats; loop++) {\n" + " uint i = uCount;\n" + " while (i--) {\n" + " x = input[x] /* + o*/;\n" + " }\n" + " }\n" + "\n" + "#ifdef MAKERW\n" + " input[0] = x;\n" + "#endif\n" + " output[0] = x;\n" + "}\n"; + + // printf("shader:\n%s\n", shader_.c_str()); + shader_ += "\n\n"; + shader_ += + "__kernel\n" + //"__attribute__((work_group_size_hint(1, 1, 1)))\n" + "void Overhead(\n" + " __global uint * restrict input,\n" + " __global uint * restrict output,\n" + " const uint uCount, const uint uSize,\n" + " const uint uOffset, const int bMem, const uint repeats)\n" + "{\n" + "#ifdef USE_FLOAT\n" + " float x = (float)input[0];\n" + " for (uint loop = 0; loop < repeats; loop++) {\n" + " uint i = uCount;\n" + " x = (float)uOffset*x;\n" + " while (i--) {\n" + " x += (float)i;\n" + " }\n" + " }\n" + " output[0] = (uint)x;\n" + "#else\n" + " uint x = input[0];\n" + " for (uint loop = 0; loop < repeats; loop++) {\n" + " uint i = uCount;\n" + " x = x*uOffset;\n" + " while (i--) {\n" + " x += i;\n" + " }\n" + " }\n" + " output[0] = x;\n" + "#endif\n" + "}\n"; +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +OCLPerfMemLatency::OCLPerfMemLatency() { + _numSubTests = NUM_SIZES * 6; + maxSize_ = Sizes[NUM_SIZES - 1]; +} + +OCLPerfMemLatency::~OCLPerfMemLatency() {} + +void OCLPerfMemLatency::setData(cl_mem buffer, unsigned int val) { + void *ptr = + _wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, CL_MAP_WRITE, 0, + width_, 0, NULL, NULL, &error_); + unsigned int *data = (unsigned int *)ptr; + for (unsigned int i = 0; i < bufSizeDW_; i++) { + data[(i * (1024 + 17)) % bufSizeDW_] = ((i + 1) * (1024 + 17)) % bufSizeDW_; + } + error_ = + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, ptr, 0, NULL, NULL); + clFinish(cmd_queue_); +} + +void OCLPerfMemLatency::checkData(cl_mem buffer) { + void *ptr = + _wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, CL_MAP_READ, 0, + sizeof(cl_uint), 0, NULL, NULL, &error_); + + unsigned int *data = (unsigned int *)ptr; + if (data[0] != 0) { + printf("OutData= 0x%08x\n", data[0]); + CHECK_RESULT_NO_RETURN(data[0] != 0, "Data validation failed!\n"); + } + error_ = + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, ptr, 0, NULL, NULL); +} + +void OCLPerfMemLatency::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + moreThreads = false; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + inBuffer_ = 0; + outBuffer_ = 0; + _errorFlag = false; // Reset error code so a single error doesn't prevent + // other subtests from running + _errorMsg = ""; + isAMD_ = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD_ = true; + } + } + + delete platforms; + } + + width_ = Sizes[test % NUM_SIZES]; + + bufSizeDW_ = width_ / sizeof(cl_uint); + moreThreads = ((test / NUM_SIZES) % 2) ? true : false; + makeVolatile = (test >= 2 * NUM_SIZES) ? true : false; + makeRW = (test >= 4 * NUM_SIZES) ? true : false; + + CHECK_RESULT(platform == 0, "Couldn't find OpenCL platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "Failed to allocate devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + device = devices[0]; + + free(devices); + devices = NULL; + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + inBuffer_ = _wrapper->clCreateBuffer(context_, 0, width_, NULL, &error_); + CHECK_RESULT(inBuffer_ == 0, "clCreateBuffer(inBuffer) failed"); + + outBuffer_ = + _wrapper->clCreateBuffer(context_, 0, 1 * sizeof(cl_uint), NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + genShader(); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + std::string args; + args.clear(); + if (isAMD_) args += " -D USE_FLOAT"; + if (makeVolatile) args += " -D MAKEVOLATILE"; + if (makeRW) args += " -D MAKERW"; + + error_ = + _wrapper->clBuildProgram(program_, 1, &device, args.c_str(), NULL, NULL); + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "MemWalker", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel(MemWalker) failed"); + + kernel2_ = _wrapper->clCreateKernel(program_, "Overhead", &error_); + CHECK_RESULT(kernel2_ == 0, "clCreateKernel(Overhead) failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&inBuffer_); + error_ = + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), (void *)&outBuffer_); + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), + (void *)&bufSizeDW_); + error_ = _wrapper->clSetKernelArg(kernel_, 3, sizeof(cl_uint), + (void *)&bufSizeDW_); + unsigned int zero = 0; + error_ = _wrapper->clSetKernelArg(kernel_, 4, sizeof(cl_uint), (void *)&zero); + int bMem = 1; + error_ = _wrapper->clSetKernelArg(kernel_, 5, sizeof(cl_int), (void *)&bMem); + // Limit the repeats, large buffers will have more samples, but the test runs + // for a long time + repeats_ = std::max((maxSize_ >> 4) / bufSizeDW_, 1u); + error_ = + _wrapper->clSetKernelArg(kernel_, 6, sizeof(cl_uint), (void *)&repeats_); + + error_ = + _wrapper->clSetKernelArg(kernel2_, 0, sizeof(cl_mem), (void *)&inBuffer_); + error_ = _wrapper->clSetKernelArg(kernel2_, 1, sizeof(cl_mem), + (void *)&outBuffer_); + error_ = _wrapper->clSetKernelArg(kernel2_, 2, sizeof(cl_uint), + (void *)&bufSizeDW_); + error_ = _wrapper->clSetKernelArg(kernel2_, 3, sizeof(cl_uint), + (void *)&bufSizeDW_); + error_ = + _wrapper->clSetKernelArg(kernel2_, 4, sizeof(cl_uint), (void *)&zero); + error_ = _wrapper->clSetKernelArg(kernel2_, 5, sizeof(cl_int), (void *)&bMem); + error_ = + _wrapper->clSetKernelArg(kernel2_, 6, sizeof(cl_uint), (void *)&repeats_); + + setData(inBuffer_, (int)1.0f); +} + +void OCLPerfMemLatency::run(void) { + int global = 1; + int local = 1; + + if (moreThreads) { + if (isAMD_) { + global *= 64; + local *= 64; + } else { + global *= 32; + local *= 32; + } + } + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + // Warm-up + unsigned int warmup = 128; + error_ = + _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), (void *)&warmup); + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), + (void *)&bufSizeDW_); + _wrapper->clFinish(cmd_queue_); + + // Restore input buffer when finished as it may have been modified by RW test + setData(inBuffer_, (int)1.0f); + + CPerfCounter timer, timer2; + + timer.Reset(); + timer.Start(); + + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + + checkData(outBuffer_); + + timer2.Reset(); + timer2.Start(); + + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel2_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + + _wrapper->clFinish(cmd_queue_); + + timer2.Stop(); + double sec = timer.GetElapsedTime() - timer2.GetElapsedTime(); + + // Read latency in ns + double perf = sec * (double)(1e09) / ((double)bufSizeDW_ * (double)repeats_); + + _perfInfo = (float)perf; + char buf[256]; + char buf2[32]; + if (makeRW) + SNPRINTF(buf2, sizeof(buf), "volatileRW"); + else if (makeVolatile) + SNPRINTF(buf2, sizeof(buf), "volatile"); + else + buf2[0] = '\0'; + SNPRINTF(buf, sizeof(buf), "%10s %2d threads, %8d reads, %5d repeats (ns)", + buf2, global, bufSizeDW_, repeats_); + testDescString = buf; +} + +unsigned int OCLPerfMemLatency::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (inBuffer_) { + error_ = _wrapper->clReleaseMemObject(inBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (kernel2_) { + error_ = _wrapper->clReleaseKernel(kernel2_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfMemLatency.h b/opencl/tests/ocltst/module/perf/OCLPerfMemLatency.h new file mode 100644 index 0000000000..61919475bc --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfMemLatency.h @@ -0,0 +1,61 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_MEMLATENCY_H_ +#define _OCL_MEMLATENCY_H_ + +#include "OCLTestImp.h" + +class OCLPerfMemLatency : public OCLTestImp { + public: + OCLPerfMemLatency(); + virtual ~OCLPerfMemLatency(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void genShader(void); + void setData(cl_mem buffer, unsigned int data); + void checkData(cl_mem buffer); + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_kernel kernel2_; + cl_mem inBuffer_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int width_; + unsigned int bufSizeDW_; + unsigned int repeats_; + unsigned int maxSize_; + bool isAMD_; + bool moreThreads; + bool makeVolatile; + bool makeRW; +}; + +#endif // _OCL_MEMLATENCY_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfPinnedBufferReadSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfPinnedBufferReadSpeed.cpp new file mode 100644 index 0000000000..47f1fdbd4d --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfPinnedBufferReadSpeed.cpp @@ -0,0 +1,347 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfPinnedBufferReadSpeed.h" + +#include +#include +#include + +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 8 +// 256KB, 1 MB, 4MB, 16 MB +static const unsigned int Sizes[NUM_SIZES] = { + 1024, 4 * 1024, 8 * 1024, 16 * 1024, 262144, 1048576, 4194304, 16777216}; + +static const unsigned int Iterations[2] = { + 1, OCLPerfPinnedBufferReadSpeed::NUM_ITER}; +#define NUM_OFFSETS 2 +static const unsigned int offsets[NUM_OFFSETS] = {0, 16}; +#define NUM_SUBTESTS (1 + NUM_OFFSETS) + +static cl_uint blockedSubtests; + +OCLPerfPinnedBufferReadSpeed::OCLPerfPinnedBufferReadSpeed() { + _numSubTests = NUM_SIZES * NUM_SUBTESTS * 2; + blockedSubtests = _numSubTests; + _numSubTests += NUM_SIZES * NUM_SUBTESTS; +} + +OCLPerfPinnedBufferReadSpeed::~OCLPerfPinnedBufferReadSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +const char *blkStr[2] = {"n/b", "blk"}; + +void OCLPerfPinnedBufferReadSpeed::open(unsigned int test, char *units, + double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + inBuffer_ = 0; + outBuffer_ = 0; + persistent = false; + allocHostPtr = false; + useHostPtr = false; + hostMem = NULL; + alignedMem = NULL; + alignment = 4096; + isAMD = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + char getVersion[128]; + error_ = _wrapper->clGetPlatformInfo(platform, CL_PLATFORM_VERSION, + sizeof(getVersion), getVersion, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + platformVersion[0] = getVersion[7]; + platformVersion[1] = getVersion[8]; + platformVersion[2] = getVersion[9]; + platformVersion[3] = '\0'; + bufSize_ = Sizes[_openTest % NUM_SIZES]; + + if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) > 0) { + useHostPtr = true; + offset = offsets[((_openTest / NUM_SIZES) % NUM_SUBTESTS) - 1]; + } else if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) == 0) { + allocHostPtr = true; + } + + if (_openTest < blockedSubtests) { + numIter = Iterations[_openTest / (NUM_SIZES * NUM_SUBTESTS)]; + } else { + numIter = 4 * OCLPerfPinnedBufferReadSpeed::NUM_ITER / + ((_openTest % NUM_SIZES) + 1); + } + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + if (allocHostPtr) { + flags |= CL_MEM_ALLOC_HOST_PTR; + } else if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + hostMem = (char *)malloc(bufSize_ + alignment - 1 + offset); + CHECK_RESULT(hostMem == 0, "malloc(hostMem) failed"); + alignedMem = + (char *)((((intptr_t)hostMem + alignment - 1) & ~(alignment - 1)) + + offset); + } + inBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, 0, &error_); + CHECK_RESULT(inBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + outBuffer_ = + _wrapper->clCreateBuffer(context_, flags, bufSize_, alignedMem, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + // Force memory to be on GPU if possible + { + cl_mem memBuffer = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(memBuffer == 0, "clCreateBuffer(memBuffer) failed"); + + _wrapper->clEnqueueCopyBuffer(cmd_queue_, memBuffer, outBuffer_, 0, 0, + bufSize_, 0, NULL, NULL); + _wrapper->clFinish(cmd_queue_); + + _wrapper->clEnqueueCopyBuffer(cmd_queue_, memBuffer, inBuffer_, 0, 0, + bufSize_, 0, NULL, NULL); + _wrapper->clFinish(cmd_queue_); + + _wrapper->clReleaseMemObject(memBuffer); + } +} + +void OCLPerfPinnedBufferReadSpeed::run(void) { + CPerfCounter timer; + void *mem = + _wrapper->clEnqueueMapBuffer(cmd_queue_, outBuffer_, CL_TRUE, CL_MAP_READ, + 0, bufSize_, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + cl_bool blocking = (_openTest < blockedSubtests) ? CL_TRUE : CL_FALSE; + + // Warm up + error_ = _wrapper->clEnqueueReadBuffer(cmd_queue_, inBuffer_, CL_TRUE, 0, + bufSize_, mem, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadBuffer failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + error_ = _wrapper->clEnqueueReadBuffer(cmd_queue_, inBuffer_, blocking, 0, + bufSize_, mem, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueReadBuffer failed"); + } + + if (blocking != CL_TRUE) { + _wrapper->clFinish(cmd_queue_); + } + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Buffer read bandwidth in GB/s + double perf = ((double)bufSize_ * numIter * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char str[256]; + if (allocHostPtr) { + SNPRINTF(str, sizeof(str), "ALLOC_HOST_PTR (GB/s)"); + } else if (useHostPtr) { + SNPRINTF(str, sizeof(str), "off: %4d USE_HOST_PTR (GB/s)", offset); + } + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) %3s i: %4d %31s ", bufSize_, + blkStr[blocking], numIter, str); + testDescString = buf; + + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, outBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapMemObject failed"); +} + +unsigned int OCLPerfPinnedBufferReadSpeed::close(void) { + _wrapper->clFinish(cmd_queue_); + if (inBuffer_) { + error_ = _wrapper->clReleaseMemObject(inBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + if (hostMem) { + free(hostMem); + } + + return _crcword; +} + +void OCLPerfPinnedBufferReadRectSpeed::run(void) { + CPerfCounter timer; + void *mem = + _wrapper->clEnqueueMapBuffer(cmd_queue_, outBuffer_, CL_TRUE, CL_MAP_READ, + 0, bufSize_, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + size_t width = static_cast(sqrt(static_cast(bufSize_))); + cl_bool blocking = (_openTest < blockedSubtests) ? CL_TRUE : CL_FALSE; + size_t bufOrigin[3] = {0, 0, 0}; + size_t hostOrigin[3] = {0, 0, 0}; + size_t region[3] = {width, width, 1}; + // Clamp iteration count to reduce test run time + unsigned int testNumIter; + testNumIter = (numIter < 100 ? numIter : 100); + + // Skip for 1.0 platforms + if ((platformVersion[0] == '1') && (platformVersion[2] == '0')) { + testDescString = " SKIPPED "; + return; + } + // Warm up + error_ = _wrapper->clEnqueueReadBufferRect( + cmd_queue_, inBuffer_, CL_TRUE, bufOrigin, hostOrigin, region, width, 0, + width, 0, mem, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadBufferRect failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < testNumIter; i++) { + error_ = _wrapper->clEnqueueReadBufferRect( + cmd_queue_, inBuffer_, blocking, bufOrigin, hostOrigin, region, width, + 0, width, 0, mem, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueReadBufferRect failed"); + } + + if (blocking != CL_TRUE) { + _wrapper->clFinish(cmd_queue_); + } + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Buffer read bandwidth in GB/s + double perf = ((double)bufSize_ * testNumIter * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char str[256]; + if (allocHostPtr) { + SNPRINTF(str, sizeof(str), "ALLOC_HOST_PTR (GB/s)"); + } else if (useHostPtr) { + SNPRINTF(str, sizeof(str), "off: %4d USE_HOST_PTR (GB/s)", offset); + } + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) %3s i: %4d %31s ", bufSize_, + blkStr[blocking], testNumIter, str); + testDescString = buf; + + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, outBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapMemObject failed"); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfPinnedBufferReadSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfPinnedBufferReadSpeed.h new file mode 100644 index 0000000000..67675b9db0 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfPinnedBufferReadSpeed.h @@ -0,0 +1,66 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PinnedBufferReadSpeed_H_ +#define _OCL_PinnedBufferReadSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfPinnedBufferReadSpeed : public OCLTestImp { + public: + OCLPerfPinnedBufferReadSpeed(); + virtual ~OCLPerfPinnedBufferReadSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 1000; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem inBuffer_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int bufSize_; + bool persistent; + bool allocHostPtr; + bool useHostPtr; + unsigned int numIter; + char* hostMem; + char* alignedMem; + size_t alignment; + unsigned int offset; + bool isAMD; + char platformVersion[32]; +}; + +class OCLPerfPinnedBufferReadRectSpeed : public OCLPerfPinnedBufferReadSpeed { + public: + OCLPerfPinnedBufferReadRectSpeed() : OCLPerfPinnedBufferReadSpeed() {} + + public: + virtual void run(void); +}; + +#endif // _OCL_PinnedBufferReadSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfPinnedBufferWriteSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfPinnedBufferWriteSpeed.cpp new file mode 100644 index 0000000000..46c5d8ca7a --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfPinnedBufferWriteSpeed.cpp @@ -0,0 +1,342 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfPinnedBufferWriteSpeed.h" + +#include +#include +#include + +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 8 +// 256KB, 1 MB, 4MB, 16 MB +static const unsigned int Sizes[NUM_SIZES] = { + 1024, 4 * 1024, 8 * 1024, 16 * 1024, 262144, 1048576, 4194304, 16777216}; + +static cl_uint blockedSubtests; + +static const unsigned int Iterations[2] = { + 1, OCLPerfPinnedBufferWriteSpeed::NUM_ITER}; +#define NUM_OFFSETS 2 +static const unsigned int offsets[NUM_OFFSETS] = {0, 16}; +#define NUM_SUBTESTS (1 + NUM_OFFSETS) +OCLPerfPinnedBufferWriteSpeed::OCLPerfPinnedBufferWriteSpeed() { + _numSubTests = NUM_SIZES * NUM_SUBTESTS * 2; + blockedSubtests = _numSubTests; + _numSubTests += NUM_SIZES * NUM_SUBTESTS; +} + +OCLPerfPinnedBufferWriteSpeed::~OCLPerfPinnedBufferWriteSpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +extern const char *blkStr[2]; + +void OCLPerfPinnedBufferWriteSpeed::open(unsigned int test, char *units, + double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + persistent = false; + allocHostPtr = false; + useHostPtr = false; + hostMem = NULL; + alignedMem = NULL; + alignment = 4096; + isAMD = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + char getVersion[128]; + error_ = _wrapper->clGetPlatformInfo(platform, CL_PLATFORM_VERSION, + sizeof(getVersion), getVersion, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + platformVersion[0] = getVersion[7]; + platformVersion[1] = getVersion[8]; + platformVersion[2] = getVersion[9]; + platformVersion[3] = '\0'; + bufSize_ = Sizes[_openTest % NUM_SIZES]; + + if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) > 0) { + useHostPtr = true; + offset = offsets[((_openTest / NUM_SIZES) % NUM_SUBTESTS) - 1]; + } else if (((_openTest / NUM_SIZES) % NUM_SUBTESTS) == 0) { + allocHostPtr = true; + } + + if (_openTest < blockedSubtests) { + numIter = Iterations[_openTest / (NUM_SIZES * NUM_SUBTESTS)]; + } else { + numIter = 4 * OCLPerfPinnedBufferWriteSpeed::NUM_ITER / + ((_openTest % NUM_SIZES) + 1); + } + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_READ_ONLY; + if (allocHostPtr) { + flags |= CL_MEM_ALLOC_HOST_PTR; + } else if (useHostPtr) { + flags |= CL_MEM_USE_HOST_PTR; + hostMem = (char *)malloc(bufSize_ + alignment - 1 + offset); + CHECK_RESULT(hostMem == 0, "malloc(hostMem) failed"); + alignedMem = + (char *)((((intptr_t)hostMem + alignment - 1) & ~(alignment - 1)) + + offset); + } + inBuffer_ = + _wrapper->clCreateBuffer(context_, flags, bufSize_, alignedMem, &error_); + CHECK_RESULT(inBuffer_ == 0, "clCreateBuffer(inBuffer) failed"); + outBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, 0, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + // Force memory to be on GPU if possible + { + cl_mem memBuffer = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(memBuffer == 0, "clCreateBuffer(memBuffer) failed"); + + _wrapper->clEnqueueCopyBuffer(cmd_queue_, memBuffer, inBuffer_, 0, 0, + bufSize_, 0, NULL, NULL); + _wrapper->clFinish(cmd_queue_); + + _wrapper->clEnqueueCopyBuffer(cmd_queue_, memBuffer, outBuffer_, 0, 0, + bufSize_, 0, NULL, NULL); + _wrapper->clFinish(cmd_queue_); + + _wrapper->clReleaseMemObject(memBuffer); + } +} + +void OCLPerfPinnedBufferWriteSpeed::run(void) { + CPerfCounter timer; + void *mem = + _wrapper->clEnqueueMapBuffer(cmd_queue_, inBuffer_, CL_TRUE, CL_MAP_WRITE, + 0, bufSize_, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + cl_bool blocking = (_openTest < blockedSubtests) ? CL_TRUE : CL_FALSE; + + // Warm up + error_ = _wrapper->clEnqueueWriteBuffer(cmd_queue_, outBuffer_, CL_TRUE, 0, + bufSize_, mem, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueWriteBuffer failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + error_ = _wrapper->clEnqueueWriteBuffer(cmd_queue_, outBuffer_, blocking, 0, + bufSize_, mem, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueWriteBuffer failed"); + } + if (blocking != CL_TRUE) { + _wrapper->clFinish(cmd_queue_); + } + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Buffer read bandwidth in GB/s + double perf = ((double)bufSize_ * numIter * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char str[256]; + if (allocHostPtr) { + SNPRINTF(str, sizeof(str), "ALLOC_HOST_PTR (GB/s)"); + } else if (useHostPtr) { + SNPRINTF(str, sizeof(str), "off: %4d USE_HOST_PTR (GB/s)", offset); + } + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) %3s i: %4d %31s ", bufSize_, + blkStr[blocking], numIter, str); + testDescString = buf; + + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, inBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapMemObject failed"); +} + +unsigned int OCLPerfPinnedBufferWriteSpeed::close(void) { + _wrapper->clFinish(cmd_queue_); + if (inBuffer_) { + error_ = _wrapper->clReleaseMemObject(inBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + if (hostMem) { + free(hostMem); + } + + return _crcword; +} + +void OCLPerfPinnedBufferWriteRectSpeed::run(void) { + CPerfCounter timer; + void *mem = + _wrapper->clEnqueueMapBuffer(cmd_queue_, inBuffer_, CL_TRUE, CL_MAP_READ, + 0, bufSize_, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + size_t width = static_cast(sqrt(static_cast(bufSize_))); + size_t bufOrigin[3] = {0, 0, 0}; + size_t hostOrigin[3] = {0, 0, 0}; + size_t region[3] = {width, width, 1}; + // Clamp iteration count to reduce test run time + unsigned int testNumIter; + testNumIter = (numIter < 100 ? numIter : 100); + cl_bool blocking = (_openTest < blockedSubtests) ? CL_TRUE : CL_FALSE; + + // Skip for 1.0 platforms + if ((platformVersion[0] == '1') && (platformVersion[2] == '0')) { + testDescString = " SKIPPED "; + return; + } + // Warm up + error_ = _wrapper->clEnqueueWriteBufferRect( + cmd_queue_, outBuffer_, CL_TRUE, bufOrigin, hostOrigin, region, width, 0, + width, 0, mem, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadBufferRect failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < testNumIter; i++) { + error_ = _wrapper->clEnqueueWriteBufferRect( + cmd_queue_, outBuffer_, blocking, bufOrigin, hostOrigin, region, width, + 0, width, 0, mem, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueWriteBufferRect failed"); + } + if (blocking != CL_TRUE) { + _wrapper->clFinish(cmd_queue_); + } + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Buffer read bandwidth in GB/s + double perf = ((double)bufSize_ * testNumIter * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char str[256]; + if (allocHostPtr) { + SNPRINTF(str, sizeof(str), "ALLOC_HOST_PTR (GB/s)"); + } else if (useHostPtr) { + SNPRINTF(str, sizeof(str), "off: %4d USE_HOST_PTR (GB/s)", offset); + } + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) %3s i: %4d %31s ", bufSize_, + blkStr[blocking], testNumIter, str); + testDescString = buf; + + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, inBuffer_, mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapMemObject failed"); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfPinnedBufferWriteSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfPinnedBufferWriteSpeed.h new file mode 100644 index 0000000000..59a3f34c86 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfPinnedBufferWriteSpeed.h @@ -0,0 +1,66 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PinnedBufferWriteSpeed_H_ +#define _OCL_PinnedBufferWriteSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfPinnedBufferWriteSpeed : public OCLTestImp { + public: + OCLPerfPinnedBufferWriteSpeed(); + virtual ~OCLPerfPinnedBufferWriteSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 1000; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem inBuffer_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int bufSize_; + bool persistent; + bool allocHostPtr; + bool useHostPtr; + unsigned int numIter; + char* hostMem; + char* alignedMem; + size_t alignment; + unsigned int offset; + bool isAMD; + char platformVersion[32]; +}; + +class OCLPerfPinnedBufferWriteRectSpeed : public OCLPerfPinnedBufferWriteSpeed { + public: + OCLPerfPinnedBufferWriteRectSpeed() : OCLPerfPinnedBufferWriteSpeed() {} + + public: + virtual void run(void); +}; + +#endif // _OCL_PinnedBufferWriteSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfPipeCopySpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfPipeCopySpeed.cpp new file mode 100644 index 0000000000..7224ff8400 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfPipeCopySpeed.cpp @@ -0,0 +1,504 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfPipeCopySpeed.h" + +#include +#include +#include + +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define KERNEL_CODE(...) #__VA_ARGS__ + +const static char * strKernel = +{ + KERNEL_CODE( + \n + kernel void initPipe(global DATA_TYPE* inBuf, write_only pipe DATA_TYPE outPipe)\n + {\n + int gid = get_global_id(0);\n + write_pipe(outPipe, &inBuf[gid]);\n + }\n + \n + kernel void copyPipe(read_only pipe DATA_TYPE inPipe, write_only pipe DATA_TYPE outPipe)\n + {\n + DATA_TYPE tmp;\n + read_pipe(inPipe, &tmp);\n + write_pipe(outPipe, &tmp);\n + }\n + \n + kernel void readPipe(read_only pipe DATA_TYPE inPipe, global DATA_TYPE* outBuf)\n + {\n + int gid = get_global_id(0);\n + DATA_TYPE tmp;\n + read_pipe(inPipe, &tmp);\n + outBuf[gid] = tmp;\n + }\n + \n + kernel void initPipe_reserve(global DATA_TYPE* inBuf, write_only pipe DATA_TYPE outPipe)\n + {\n + int gid = get_global_id(0);\n + local reserve_id_t resId;\n + resId = reserve_write_pipe(outPipe, 1);\n + if (is_valid_reserve_id(resId)) {\n + write_pipe(outPipe, resId, 0, &inBuf[gid]);\n + commit_write_pipe(outPipe, resId);\n + }\n + }\n + \n + kernel void copyPipe_reserve(read_only pipe DATA_TYPE inPipe, write_only pipe DATA_TYPE outPipe)\n + {\n + local reserve_id_t resId;\n + resId = reserve_read_pipe(inPipe, 1);\n + if (is_valid_reserve_id(resId)) {\n + DATA_TYPE tmp;\n + read_pipe(inPipe, resId, 0, &tmp);\n + commit_read_pipe(inPipe, resId);\n + resId = reserve_write_pipe(outPipe, 1);\n + if (is_valid_reserve_id(resId)) {\n + write_pipe(outPipe, resId, 0, &tmp);\n + commit_write_pipe(outPipe, resId);\n + }\n + }\n + }\n + \n + kernel void readPipe_reserve(read_only pipe DATA_TYPE inPipe, global DATA_TYPE* outBuf)\n + {\n + int gid = get_global_id(0);\n + local reserve_id_t resId;\n + resId = reserve_read_pipe(inPipe, 1);\n + if (is_valid_reserve_id(resId)) {\n + DATA_TYPE tmp;\n + read_pipe(inPipe, resId, 0, &tmp);\n + commit_read_pipe(inPipe, resId);\n + outBuf[gid] = tmp;\n + }\n + }\n + \n + kernel void initPipe_wg(global DATA_TYPE* inBuf, write_only pipe DATA_TYPE outPipe)\n + {\n + int gid = get_global_id(0);\n + local reserve_id_t resId;\n + resId = work_group_reserve_write_pipe(outPipe, get_local_size(0));\n + if (is_valid_reserve_id(resId)) {\n + write_pipe(outPipe, resId, get_local_id(0), &inBuf[gid]);\n + work_group_commit_write_pipe(outPipe, resId);\n + }\n + }\n + \n + kernel void copyPipe_wg(read_only pipe DATA_TYPE inPipe, write_only pipe DATA_TYPE outPipe)\n + {\n + local reserve_id_t resId;\n + resId = work_group_reserve_read_pipe(inPipe, get_local_size(0));\n + if (is_valid_reserve_id(resId)) {\n + DATA_TYPE tmp;\n + read_pipe(inPipe, resId, get_local_id(0), &tmp);\n + work_group_commit_read_pipe(inPipe, resId);\n + resId = work_group_reserve_write_pipe(outPipe, get_local_size(0));\n + if (is_valid_reserve_id(resId)) {\n + write_pipe(outPipe, resId, get_local_id(0), &tmp);\n + work_group_commit_write_pipe(outPipe, resId);\n + }\n + }\n + }\n + \n + kernel void readPipe_wg(read_only pipe DATA_TYPE inPipe, global DATA_TYPE* outBuf)\n + {\n + int gid = get_global_id(0);\n + local reserve_id_t resId;\n + resId = work_group_reserve_read_pipe(inPipe, get_local_size(0));\n + if (is_valid_reserve_id(resId)) {\n + DATA_TYPE tmp;\n + read_pipe(inPipe, resId, get_local_id(0), &tmp);\n + work_group_commit_read_pipe(inPipe, resId);\n + outBuf[gid] = tmp;\n + }\n + }\n + \n +\x23 ifdef SUBGROUPS\n + \x23 pragma OPENCL EXTENSION cl_khr_subgroups : enable\n + kernel __attribute__((reqd_work_group_size(64,1,1))) void initPipe_sg(global DATA_TYPE* inBuf, write_only pipe DATA_TYPE outPipe)\n + {\n + int gid = get_global_id(0);\n + local reserve_id_t resId;\n + resId = sub_group_reserve_write_pipe(outPipe, get_local_size(0));\n + if (is_valid_reserve_id(resId)) {\n + write_pipe(outPipe, resId, get_local_id(0), &inBuf[gid]);\n + sub_group_commit_write_pipe(outPipe, resId);\n + }\n + }\n + \n + kernel __attribute__((reqd_work_group_size(64,1,1))) void copyPipe_sg(read_only pipe DATA_TYPE inPipe, write_only pipe DATA_TYPE outPipe)\n + {\n + local reserve_id_t resId;\n + resId = sub_group_reserve_read_pipe(inPipe, get_local_size(0));\n + if (is_valid_reserve_id(resId)) {\n + DATA_TYPE tmp;\n + read_pipe(inPipe, resId, get_local_id(0), &tmp);\n + sub_group_commit_read_pipe(inPipe, resId);\n + resId = sub_group_reserve_write_pipe(outPipe, get_local_size(0));\n + if (is_valid_reserve_id(resId)) {\n + write_pipe(outPipe, resId, get_local_id(0), &tmp);\n + sub_group_commit_write_pipe(outPipe, resId);\n + }\n + }\n + }\n + \n + kernel __attribute__((reqd_work_group_size(64,1,1))) void readPipe_sg(read_only pipe DATA_TYPE inPipe, global DATA_TYPE* outBuf)\n + {\n + int gid = get_global_id(0);\n + local reserve_id_t resId;\n + resId = sub_group_reserve_read_pipe(inPipe, get_local_size(0));\n + if (is_valid_reserve_id(resId)) {\n + DATA_TYPE tmp;\n + read_pipe(inPipe, resId, get_local_id(0), &tmp);\n + sub_group_commit_read_pipe(inPipe, resId);\n + outBuf[gid] = tmp;\n + }\n + }\n +\x23 endif\n + \n + ) +}; + +#define NUM_SIZES 6 +// 4KB, 8KB, 64KB, 256KB, 1 MB, 4MB +static const unsigned int Sizes[NUM_SIZES] = {4096, 8192, 65536, + 262144, 1048576, 4194304}; + +#define NUM_TYPES 3 +static const char *types[NUM_TYPES] = {"int", "int4", "int16"}; +static const unsigned int typeSize[NUM_TYPES] = {4, 16, 64}; + +#define NUM_TESTS 4 + +OCLPerfPipeCopySpeed::OCLPerfPipeCopySpeed() { + _numSubTests = NUM_TESTS * NUM_SIZES * NUM_TYPES; +} + +OCLPerfPipeCopySpeed::~OCLPerfPipeCopySpeed() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfPipeCopySpeed::setData(cl_mem buffer) { + int *mem; + int dwTypeSize = (int)(typeSize[typeIdx_]) >> 2; + mem = (int *)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, CL_TRUE, + CL_MAP_WRITE, 0, bufSize_, 0, NULL, + NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + for (int i = 0; i < (int)numElements; i++) { + for (int j = 0; j < dwTypeSize; j++) { + mem[i * dwTypeSize + j] = i; + } + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, (void *)mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapBuffer failed"); + clFinish(cmd_queue_); +} + +void OCLPerfPipeCopySpeed::checkData(cl_mem buffer) { + int *mem; + int dwTypeSize = (int)(typeSize[typeIdx_]) >> 2; + char *histo; + histo = (char *)malloc(numElements * sizeof(char)); + memset(histo, 0, sizeof(char) * numElements); + mem = (int *)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, CL_TRUE, + CL_MAP_READ, 0, bufSize_, 0, NULL, + NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + int errCnt = 0; + for (int i = 0; (i < (int)numElements) && (errCnt < 5); i++) { + int tmp = mem[dwTypeSize * i]; + for (int j = 1; (j < dwTypeSize) && (errCnt < 5); j++) { + if (mem[i * dwTypeSize + j] != tmp) { + // BAD DATA! + printf("BAD DATA at element %d, ref %d, got %d\n", i, tmp, + mem[i * dwTypeSize + j]); + errCnt++; + } + } + if (histo[tmp] == 1) { + printf("BAD DATA at element %d, val %d already found!\n", i, tmp); + errCnt++; + } + histo[tmp] = 1; + } + errCnt = 0; + for (int i = 0; (i < (int)numElements) && (errCnt < 5); i++) { + if (histo[i] != 1) { + printf("BAD DATA at element %d, val not found!\n", i); + errCnt++; + } + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, (void *)mem, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueUnmapBuffer failed"); + clFinish(cmd_queue_); + free(histo); +} + +void OCLPerfPipeCopySpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + _crcword = 0; + conversion = 1.0f; + + cl_device_id device = devices_[deviceId]; + cmd_queue_ = cmdQueues_[_deviceId]; + + program_ = 0; + initPipe_ = 0; + copyPipe_ = 0; + readPipe_ = 0; + srcBuffer_ = 0; + dstBuffer_ = 0; + pipe_[0] = 0; + pipe_[1] = 0; + failed_ = false; + subgroupSupport_ = false; + + bufSize_ = Sizes[test % NUM_SIZES]; + typeIdx_ = (test / NUM_SIZES) % NUM_TYPES; + testIdx_ = test / (NUM_SIZES * NUM_TYPES); + + numIter = NUM_ITER; + + char getVersion[128]; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_VERSION, + sizeof(getVersion), getVersion, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (getVersion[7] < '2') { + failed_ = true; + _errorMsg = "OpenCL 2.0 not supported"; + return; + } + + srcBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY, bufSize_, + NULL, &error_); + CHECK_RESULT(srcBuffer_ == 0, "clCreateBuffer(srcBuffer) failed"); + + numElements = bufSize_ / typeSize[typeIdx_]; + char args[100]; + +#if defined(CL_VERSION_2_0) + pipe_[0] = + _wrapper->clCreatePipe(context_, CL_MEM_HOST_NO_ACCESS, + typeSize[typeIdx_], numElements, NULL, &error_); + CHECK_RESULT(pipe_[0] == 0, "clCreatePipe(pipe_[0]) failed"); + + pipe_[1] = + _wrapper->clCreatePipe(context_, CL_MEM_HOST_NO_ACCESS, + typeSize[typeIdx_], numElements, NULL, &error_); + CHECK_RESULT(pipe_[1] == 0, "clCreatePipe(pipe_[1]) failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + char *p = strstr(charbuf, "cl_khr_subgroups"); + if (p) { + subgroupSupport_ = true; + SNPRINTF(args, sizeof(args), "-cl-std=CL2.0 -D DATA_TYPE=%s -D SUBGROUPS", + types[typeIdx_]); + } else { + if (test >= (NUM_SIZES * NUM_TYPES * 3)) { + // No support for subgroups, so skip these tests + failed_ = true; + _errorMsg = "Subgroup extension not supported"; + return; + } + SNPRINTF(args, sizeof(args), "-cl-std=CL2.0 -D DATA_TYPE=%s", + types[typeIdx_]); + } +#endif + + dstBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, bufSize_, + NULL, &error_); + CHECK_RESULT(dstBuffer_ == 0, "clCreateBuffer(dstBuffer) failed"); + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &device, args, NULL, NULL); + if (error_ != CL_SUCCESS) { + printf("\nerror: %d\n", error_); + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + if (testIdx_ == 0) { + initPipe_ = _wrapper->clCreateKernel(program_, "initPipe", &error_); + CHECK_RESULT(initPipe_ == 0, "clCreateKernel(initPipe) failed"); + copyPipe_ = _wrapper->clCreateKernel(program_, "copyPipe", &error_); + CHECK_RESULT(copyPipe_ == 0, "clCreateKernel(copyPipe) failed"); + readPipe_ = _wrapper->clCreateKernel(program_, "readPipe", &error_); + CHECK_RESULT(readPipe_ == 0, "clCreateKernel(readPipe) failed"); + testName_ = "r/w"; + } else if (testIdx_ == 1) { + initPipe_ = _wrapper->clCreateKernel(program_, "initPipe_reserve", &error_); + CHECK_RESULT(initPipe_ == 0, "clCreateKernel(initPipe) failed"); + copyPipe_ = _wrapper->clCreateKernel(program_, "copyPipe_reserve", &error_); + CHECK_RESULT(copyPipe_ == 0, "clCreateKernel(copyPipe) failed"); + readPipe_ = _wrapper->clCreateKernel(program_, "readPipe_reserve", &error_); + CHECK_RESULT(readPipe_ == 0, "clCreateKernel(readPipe) failed"); + numIter = 10; // Limit iteration count because this test is very slow + testName_ = "r/w w/ reserve"; + } else if (testIdx_ == 2) { + initPipe_ = _wrapper->clCreateKernel(program_, "initPipe_wg", &error_); + CHECK_RESULT(initPipe_ == 0, "clCreateKernel(initPipe) failed"); + copyPipe_ = _wrapper->clCreateKernel(program_, "copyPipe_wg", &error_); + CHECK_RESULT(copyPipe_ == 0, "clCreateKernel(copyPipe) failed"); + readPipe_ = _wrapper->clCreateKernel(program_, "readPipe_wg", &error_); + CHECK_RESULT(readPipe_ == 0, "clCreateKernel(readPipe) failed"); + testName_ = "wg r/w w/ reserve"; + } else if (testIdx_ == 3) { + initPipe_ = _wrapper->clCreateKernel(program_, "initPipe_sg", &error_); + CHECK_RESULT(initPipe_ == 0, "clCreateKernel(initPipe) failed"); + copyPipe_ = _wrapper->clCreateKernel(program_, "copyPipe_sg", &error_); + CHECK_RESULT(copyPipe_ == 0, "clCreateKernel(copyPipe) failed"); + readPipe_ = _wrapper->clCreateKernel(program_, "readPipe_sg", &error_); + CHECK_RESULT(readPipe_ == 0, "clCreateKernel(readPipe) failed"); + testName_ = "sg r/w w/ reserve"; + } else { + CHECK_RESULT(1, "Invalid test index!"); + } + setData(srcBuffer_); +} + +void OCLPerfPipeCopySpeed::run(void) { + if (failed_) return; + CPerfCounter timer; + size_t global_work_size[1] = {(size_t)numElements}; + size_t local_work_size[1] = {64}; + + error_ = _wrapper->clSetKernelArg(initPipe_, 0, sizeof(cl_mem), + (void *)&srcBuffer_); + error_ = + _wrapper->clSetKernelArg(initPipe_, 1, sizeof(cl_mem), (void *)&pipe_[0]); + // Warm up + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, initPipe_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + + error_ = + _wrapper->clSetKernelArg(copyPipe_, 0, sizeof(cl_mem), (void *)&pipe_[0]); + error_ = + _wrapper->clSetKernelArg(copyPipe_, 1, sizeof(cl_mem), (void *)&pipe_[1]); + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, copyPipe_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < numIter; i++) { + error_ = _wrapper->clSetKernelArg(copyPipe_, 0, sizeof(cl_mem), + (void *)&pipe_[(i + 1) % 2]); + error_ = _wrapper->clSetKernelArg(copyPipe_, 1, sizeof(cl_mem), + (void *)&pipe_[i % 2]); + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, copyPipe_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + timer.Stop(); + + // pipe[(numIter-1)%2 has the data + error_ = _wrapper->clSetKernelArg(readPipe_, 0, sizeof(cl_mem), + (void *)&pipe_[(numIter - 1) % 2]); + error_ = _wrapper->clSetKernelArg(readPipe_, 1, sizeof(cl_mem), + (void *)&dstBuffer_); + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, readPipe_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel(readPipe) failed"); + error_ = _wrapper->clFinish(cmd_queue_); + checkData(dstBuffer_); + double sec = timer.GetElapsedTime(); + + // Pipe copy total bandwidth in GB/s + double perf = 2. * ((double)bufSize_ * numIter * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " %17s (%8d bytes) block size: %2d i:%4d (GB/s) ", + testName_.c_str(), bufSize_, typeSize[typeIdx_], numIter); + testDescString = buf; +} + +unsigned int OCLPerfPipeCopySpeed::close(void) { + if (srcBuffer_) { + error_ = _wrapper->clReleaseMemObject(srcBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(srcBuffer_) failed"); + } + if (pipe_[0]) { + error_ = _wrapper->clReleaseMemObject(pipe_[0]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(pipe_[0]) failed"); + } + if (pipe_[1]) { + error_ = _wrapper->clReleaseMemObject(pipe_[1]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(pipe_[1]) failed"); + } + if (dstBuffer_) { + error_ = _wrapper->clReleaseMemObject(dstBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(dstBuffer_) failed"); + } + + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfPipeCopySpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfPipeCopySpeed.h new file mode 100644 index 0000000000..24b3098d8f --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfPipeCopySpeed.h @@ -0,0 +1,60 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PipeCopySpeed_H_ +#define _OCL_PipeCopySpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfPipeCopySpeed : public OCLTestImp { + public: + OCLPerfPipeCopySpeed(); + virtual ~OCLPerfPipeCopySpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 100; + void setData(cl_mem buffer); + void checkData(cl_mem buffer); + + cl_command_queue cmd_queue_; + cl_mem srcBuffer_; + cl_mem pipe_[2]; + cl_mem dstBuffer_; + cl_program program_; + cl_kernel initPipe_; + cl_kernel copyPipe_; + cl_kernel readPipe_; + + unsigned int bufSize_; + unsigned int typeIdx_; + unsigned int numElements; + unsigned int numIter; + unsigned int testIdx_; + std::string testName_; + bool subgroupSupport_; + bool failed_; +}; + +#endif // _OCL_PipeCopySpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfProgramGlobalRead.cpp b/opencl/tests/ocltst/module/perf/OCLPerfProgramGlobalRead.cpp new file mode 100644 index 0000000000..14b13a1a78 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfProgramGlobalRead.cpp @@ -0,0 +1,549 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfProgramGlobalRead.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +static const unsigned int NUM_SIZES = 4; +static const unsigned int NUM_READ_MODES = 6; +// Limit to 32 reads for now +static const unsigned int MAX_READ_MODES = 4; + +static const unsigned int NumReads[NUM_READ_MODES] = {1, 4, 16, 32, 64, 128}; +// 256KB, 1 MB, 4MB, 16 MB +static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304, + 16777216}; +static const unsigned int MaxTypes = 6; +static unsigned int NumTypes = MaxTypes; +static const char *types[MaxTypes] = {"char", "short", "int", + "long", "float", "double"}; +static unsigned int StartType = 0; +static const unsigned int NumVecWidths = + 3; // 5; char8 global scope does not work; bug opened +static const char *vecWidths[NumVecWidths] = {"", "2", "4"}; //, "8", "16"}; +static const unsigned int vecWidths_int[NumVecWidths] = {1, 2, 4}; //, 8, 16}; +static const unsigned int TypeSize[MaxTypes] = { + sizeof(cl_char), sizeof(cl_short), sizeof(cl_int), + sizeof(cl_long), sizeof(cl_float), sizeof(cl_double)}; +#define CHAR_BUF_SIZE 512 + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif +void OCLPerfProgramGlobalRead::genShader(unsigned int type, + unsigned int vecWidth, + unsigned int numReads, + unsigned int bufSize) { + char buf[CHAR_BUF_SIZE]; + + shader_.clear(); + shader_ += + "#ifdef USE_ARENA\n" + "#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable\n" + "#endif\n"; + shader_ += + "#ifdef USE_AMD_DOUBLES\n" + "#pragma OPENCL EXTENSION cl_amd_fp64 : enable\n" + "#endif\n"; + shader_ += + "#ifdef USE_KHR_DOUBLES\n" + "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n" + "#endif\n"; + SNPRINTF(buf, CHAR_BUF_SIZE, "__global %s%s gp[%d];\n", types[type], + vecWidths[vecWidth], bufSize); + shader_.append(buf); + SNPRINTF(buf, CHAR_BUF_SIZE, + "__kernel void __attribute__((reqd_work_group_size(64,1,1))) " + "_ReadSpeed(__global %s%s * restrict outBuf, constant uint * " + "restrict constBuf)\n", + types[type], vecWidths[vecWidth]); + shader_.append(buf); + shader_ += + "{\n" + " uint i = (uint) get_global_id(0);\n"; + if (numReads == 1) { + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + shader_ += + " const unsigned int Max = constBuf[0];\n" + " temp = *(gp + i % Max);\n"; + shader_ += + " *(outBuf + i) = temp;\n" + "}\n"; + } else { + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp0 = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp1 = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp2 = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp3 = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + shader_ += + " const unsigned int Max = constBuf[0];\n" + " unsigned int idx0 = (i % Max) + constBuf[1];\n" + " unsigned int idx1 = (i % Max) + constBuf[2];\n" + " unsigned int idx2 = (i % Max) + constBuf[3];\n" + " unsigned int idx3 = (i % Max) + constBuf[4];\n"; + + for (unsigned int i = 0; i < (numReads >> 2); i++) { + shader_ += " temp0 += *(gp + idx0);\n"; + shader_ += " temp1 += *(gp + idx1);\n"; + shader_ += " temp2 += *(gp + idx2);\n"; + shader_ += " temp3 += *(gp + idx3);\n"; + shader_ += " idx0 += constBuf[5];\n"; + shader_ += " idx1 += constBuf[5];\n"; + shader_ += " idx2 += constBuf[5];\n"; + shader_ += " idx3 += constBuf[5];\n"; + } + shader_ += + " *(outBuf + i) = temp0 + temp1 + temp2 + temp3;\n" + "}\n"; + } +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +OCLPerfProgramGlobalRead::OCLPerfProgramGlobalRead() { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + context_ = 0; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + // Get last for default + platform = platforms[numPlatforms - 1]; + for (unsigned i = 0; i < numPlatforms; ++i) { + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, + sizeof(pbuf), pbuf, NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = + _wrapper->clGetDeviceIDs(platforms[i], type_, 0, NULL, &num_devices); + // Runtime returns an error when no GPU devices are present instead of + // just returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + platform = platforms[i]; + break; + } + } + delete platforms; + } + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + char *p = strstr(charbuf, "cl_khr_byte_addressable_store"); + char *p2 = strstr(charbuf, "cl_khr_fp64"); + + NumTypes = MaxTypes; + if (!p) { + // No arena ops + NumTypes -= 2; + StartType = 2; + } + if (!p2) { + // Doubles not supported + NumTypes--; + } + _numSubTests = NumTypes * NumVecWidths * NUM_SIZES * MAX_READ_MODES; + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + skip_ = false; +} + +OCLPerfProgramGlobalRead::~OCLPerfProgramGlobalRead() {} + +// Fill with 1s of appropriate type +void OCLPerfProgramGlobalRead::setData(cl_mem buffer, float val) { + void *ptr = + _wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, CL_MAP_WRITE, 0, + bufSize_, 0, NULL, NULL, &error_); + switch (typeIdx_) { + case 0: // char + { + char *data = (char *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(char)); i++) + data[i] = (char)val; + break; + } + case 1: // short + { + short *data = (short *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(short)); i++) + data[i] = (short)val; + break; + } + case 2: // int + { + int *data = (int *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(int)); i++) + data[i] = (int)val; + break; + } + case 3: // long + { + cl_long *data = (cl_long *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(cl_long)); i++) + data[i] = (cl_long)val; + break; + } + case 4: // float + { + float *data = (float *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(float)); i++) + data[i] = val; + break; + } + case 5: // double + { + double *data = (double *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(double)); i++) + data[i] = (double)val; + break; + } + default: + // oops + break; + } + error_ = + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, ptr, 0, NULL, NULL); +} + +void OCLPerfProgramGlobalRead::checkData(cl_mem buffer) { + void *ptr = + _wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, CL_MAP_READ, 0, + bufSize_, 0, NULL, NULL, &error_); + switch (typeIdx_) { + case 0: // char + { + char *data = (char *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(char)); i++) { + if (data[i] != (char)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, + numReads_, numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + break; + } + case 1: // short + { + short *data = (short *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(short)); i++) { + if (data[i] != (short)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, + numReads_, numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + break; + } + case 2: // int + { + int *data = (int *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(int)); i++) { + if (data[i] != (int)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, + numReads_, numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + break; + } + case 3: // long + { + cl_long *data = (cl_long *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(cl_long)); i++) { + if (data[i] != (cl_long)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, + numReads_, numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + break; + } + case 4: // float + { + float *data = (float *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(float)); i++) { + if (data[i] != (float)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, + numReads_, numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + break; + } + case 5: // double + { + double *data = (double *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(double)); i++) { + if (data[i] != (double)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, + numReads_, numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + break; + } + default: + // oops + break; + } + error_ = + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, ptr, 0, NULL, NULL); +} + +void OCLPerfProgramGlobalRead::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + error_ = CL_SUCCESS; + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = 0; + kernel_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + constBuffer_ = 0; + +#if defined(CL_VERSION_2_0) + cl_device_id device; + numReads_ = NumReads[test % MAX_READ_MODES]; + width_ = Sizes[(test / MAX_READ_MODES) % NUM_SIZES]; + vecSizeIdx_ = (test / (MAX_READ_MODES * NUM_SIZES)) % NumVecWidths; + typeIdx_ = (test / (MAX_READ_MODES * NUM_SIZES * NumVecWidths)) % NumTypes + + StartType; + + bufSize_ = width_; + + cmd_queue_ = cmdQueues_[_deviceId]; + + device = devices_[_deviceId]; + + outBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + constBuffer_ = _wrapper->clCreateBuffer(context_, 0, 16 * 2, NULL, &error_); + CHECK_RESULT(constBuffer_ == 0, "clCreateBuffer(constBuffer) failed"); + + genShader(typeIdx_, vecSizeIdx_, numReads_, + bufSize_ / (TypeSize[typeIdx_] * (1 << vecSizeIdx_))); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + std::string args; + args.clear(); + if (typeIdx_ < 2) { + args += "-D USE_ARENA "; + } + args += "-cl-std=CL2.0"; + error_ = + _wrapper->clBuildProgram(program_, 1, &device, args.c_str(), NULL, NULL); + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "_ReadSpeed", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&outBuffer_); + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), + (void *)&constBuffer_); + + setData(outBuffer_, 1.2345678f); + unsigned int *cBuf = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, constBuffer_, true, CL_MAP_WRITE, 0, 16 * 2, 0, NULL, NULL, + &error_); + // Force all wavefronts to fetch the same data. We are looking for peak speed + // here. + cBuf[0] = 64; + // These values are chosen to assure there is no data reuse within a clause. + // If caching is not working, then the uncached numbers will be low. + cBuf[1] = 0; + cBuf[2] = 64; + cBuf[3] = 128; + cBuf[4] = 192; + cBuf[5] = 0; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, constBuffer_, cBuf, 0, + NULL, NULL); + _wrapper->clFinish(cmd_queue_); +#else + skip_ = true; + testDescString = + "Program scope globals not supported for < 2.0 builds. Test Skipped."; + return; +#endif +} + +void OCLPerfProgramGlobalRead::run(void) { + if (skip_) { + return; + } +#if defined(CL_VERSION_2_0) + int global = bufSize_ / (TypeSize[typeIdx_] * (1 << vecSizeIdx_)); + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < NUM_ITER; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Program scope global read bandwidth in GB/s + double perf = + ((double)bufSize_ * numReads_ * NUM_ITER * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char buf[256]; + char buf2[256]; + SNPRINTF(buf, sizeof(buf), "%s%s", types[typeIdx_], vecWidths[vecSizeIdx_]); + SNPRINTF(buf2, sizeof(buf2), " %-8s (%8d) %2d reads: (GB/s) ", buf, width_, + numReads_); + testDescString = buf2; + // checkData(outBuffer_); +#endif +} + +unsigned int OCLPerfProgramGlobalRead::close(void) { +#if defined(CL_VERSION_2_0) + if (cmd_queue_) _wrapper->clFinish(cmd_queue_); + + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (constBuffer_) { + error_ = _wrapper->clReleaseMemObject(constBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(constBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } +#endif + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfProgramGlobalRead.h b/opencl/tests/ocltst/module/perf/OCLPerfProgramGlobalRead.h new file mode 100644 index 0000000000..f17f6aeb06 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfProgramGlobalRead.h @@ -0,0 +1,60 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PROGRAMGLOBALREAD_H +#define _OCL_PROGRAMGLOBALREAD_H + +#include "OCLTestImp.h" + +class OCLPerfProgramGlobalRead : public OCLTestImp { + public: + OCLPerfProgramGlobalRead(); + virtual ~OCLPerfProgramGlobalRead(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void genShader(unsigned int type, unsigned int vecWidth, + unsigned int numReads, unsigned int bufSize); + void setData(cl_mem buffer, float data); + void checkData(cl_mem buffer); + + static const unsigned int NUM_ITER = 100; + + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem outBuffer_; + cl_mem constBuffer_; + + unsigned int width_; + unsigned int bufSize_; + unsigned int vecSizeIdx_; + unsigned int numReads_; + unsigned int typeIdx_; + + bool skip_; +}; + +#endif // _OCL_PROGRAMGLOBALREAD_H diff --git a/opencl/tests/ocltst/module/perf/OCLPerfProgramGlobalWrite.cpp b/opencl/tests/ocltst/module/perf/OCLPerfProgramGlobalWrite.cpp new file mode 100644 index 0000000000..2363fecdaa --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfProgramGlobalWrite.cpp @@ -0,0 +1,384 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfProgramGlobalWrite.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +static const unsigned int NUM_SIZES = 4; +static const unsigned int NUM_READ_MODES = 6; +// Limit to 32 reads for now +static const unsigned int MAX_READ_MODES = 4; + +static const unsigned int NumReads[NUM_READ_MODES] = {1, 4, 16, 32, 64, 128}; +// 256KB, 1 MB, 4MB, 16 MB +static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304, + 16777216}; +static const unsigned int MaxTypes = 6; +static unsigned int NumTypes = MaxTypes; +static const char *types[MaxTypes] = {"char", "short", "int", + "long", "float", "double"}; +static unsigned int StartType = 0; +static const unsigned int NumVecWidths = + 3; // 5; char8 global scope does not work; bug opened +static const char *vecWidths[NumVecWidths] = {"", "2", "4"}; //, "8", "16"}; +static const unsigned int vecWidths_int[NumVecWidths] = {1, 2, 4}; //, 8, 16}; +static const unsigned int TypeSize[MaxTypes] = { + sizeof(cl_char), sizeof(cl_short), sizeof(cl_int), + sizeof(cl_long), sizeof(cl_float), sizeof(cl_double)}; +#define CHAR_BUF_SIZE 512 + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif +void OCLPerfProgramGlobalWrite::genShader(unsigned int type, + unsigned int vecWidth, + unsigned int numReads, + unsigned int bufSize) { + char buf[CHAR_BUF_SIZE]; + + shader_.clear(); + shader_ += + "#ifdef USE_ARENA\n" + "#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable\n" + "#endif\n"; + shader_ += + "#ifdef USE_AMD_DOUBLES\n" + "#pragma OPENCL EXTENSION cl_amd_fp64 : enable\n" + "#endif\n"; + shader_ += + "#ifdef USE_KHR_DOUBLES\n" + "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n" + "#endif\n"; + SNPRINTF(buf, CHAR_BUF_SIZE, "__global %s%s gp[%d];\n", types[type], + vecWidths[vecWidth], bufSize); + shader_.append(buf); + SNPRINTF(buf, CHAR_BUF_SIZE, + "__kernel void __attribute__((reqd_work_group_size(64,1,1))) " + "_WriteSpeed(constant uint * restrict constBuf)\n"); + shader_.append(buf); + shader_ += + "{\n" + " uint i = (uint) get_global_id(0);\n"; + if (numReads == 1) { + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + shader_ += " const unsigned int Max = constBuf[0];\n"; + shader_ += + " *(gp + i % Max) = 0;\n" + "}\n"; + } else { + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp0 = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp1 = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp2 = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp3 = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + shader_ += + " const unsigned int Max = constBuf[0];\n" + " unsigned int idx0 = (i % Max) + constBuf[1];\n" + " unsigned int idx1 = (i % Max) + constBuf[2];\n" + " unsigned int idx2 = (i % Max) + constBuf[3];\n" + " unsigned int idx3 = (i % Max) + constBuf[4];\n"; + + for (unsigned int i = 0; i < (numReads >> 2); i++) { + shader_ += " *(gp + idx0) = idx0;\n"; + shader_ += " *(gp + idx1) = idx1;\n"; + shader_ += " *(gp + idx2) = idx2;\n"; + shader_ += " *(gp + idx3) = idx3;\n"; + shader_ += " idx0 += constBuf[5];\n"; + shader_ += " idx1 += constBuf[5];\n"; + shader_ += " idx2 += constBuf[5];\n"; + shader_ += " idx3 += constBuf[5];\n"; + } + shader_ += "}\n"; + } + SNPRINTF(buf, CHAR_BUF_SIZE, "__kernel void __dummyRead(global %s%s *in)\n", + types[type], vecWidths[vecWidth]); + shader_.append(buf); + shader_ += + "{\n" + " uint i = (uint) get_global_id(0);\n"; + SNPRINTF(buf, CHAR_BUF_SIZE, " in[i] = gp[i];\n"); + shader_.append(buf); + shader_ += "}\n"; +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +OCLPerfProgramGlobalWrite::OCLPerfProgramGlobalWrite() { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + context_ = 0; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + // Get last for default + platform = platforms[numPlatforms - 1]; + for (unsigned i = 0; i < numPlatforms; ++i) { + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, + sizeof(pbuf), pbuf, NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = + _wrapper->clGetDeviceIDs(platforms[i], type_, 0, NULL, &num_devices); + // Runtime returns an error when no GPU devices are present instead of + // just returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + platform = platforms[i]; + break; + } + } + delete platforms; + } + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + char *p = strstr(charbuf, "cl_khr_byte_addressable_store"); + char *p2 = strstr(charbuf, "cl_khr_fp64"); + + NumTypes = MaxTypes; + if (!p) { + // No arena ops + NumTypes -= 2; + StartType = 2; + } + if (!p2) { + // Doubles not supported + NumTypes--; + } + _numSubTests = NumTypes * NumVecWidths * NUM_SIZES * MAX_READ_MODES; + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + skip_ = false; +} + +OCLPerfProgramGlobalWrite::~OCLPerfProgramGlobalWrite() {} + +void OCLPerfProgramGlobalWrite::open(unsigned int test, char *units, + double &conversion, + unsigned int deviceId) { + error_ = CL_SUCCESS; + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = 0; + kernel_ = 0; + cmd_queue_ = 0; + outBuffer_ = 0; + constBuffer_ = 0; + +#if defined(CL_VERSION_2_0) + cl_device_id device; + numReads_ = NumReads[test % MAX_READ_MODES]; + width_ = Sizes[(test / MAX_READ_MODES) % NUM_SIZES]; + vecSizeIdx_ = (test / (MAX_READ_MODES * NUM_SIZES)) % NumVecWidths; + typeIdx_ = (test / (MAX_READ_MODES * NUM_SIZES * NumVecWidths)) % NumTypes + + StartType; + + bufSize_ = width_; + + cmd_queue_ = cmdQueues_[_deviceId]; + + device = devices_[_deviceId]; + + outBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + constBuffer_ = _wrapper->clCreateBuffer(context_, 0, 16 * 2, NULL, &error_); + CHECK_RESULT(constBuffer_ == 0, "clCreateBuffer(constBuffer) failed"); + + genShader(typeIdx_, vecSizeIdx_, numReads_, + bufSize_ / (TypeSize[typeIdx_] * (1 << vecSizeIdx_))); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + std::string args; + args.clear(); + if (typeIdx_ < 2) { + args += "-D USE_ARENA "; + } + args += "-cl-std=CL2.0"; + error_ = + _wrapper->clBuildProgram(program_, 1, &device, args.c_str(), NULL, NULL); + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "_WriteSpeed", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&constBuffer_); + + unsigned int *cBuf = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, constBuffer_, true, CL_MAP_WRITE, 0, 16 * 2, 0, NULL, NULL, + &error_); + // Force all wavefronts to fetch the same data. We are looking for peak speed + // here. + cBuf[0] = 64; + // These values are chosen to assure there is no data reuse within a clause. + // If caching is not working, then the uncached numbers will be low. + cBuf[1] = 0; + cBuf[2] = 64; + cBuf[3] = 128; + cBuf[4] = 192; + cBuf[5] = 0; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, constBuffer_, cBuf, 0, + NULL, NULL); + _wrapper->clFinish(cmd_queue_); +#else + skip_ = true; + testDescString = + "Program scope globals not supported for < 2.0 builds. Test Skipped."; + return; +#endif +} + +void OCLPerfProgramGlobalWrite::run(void) { + if (skip_) { + return; + } +#if defined(CL_VERSION_2_0) + int global = bufSize_ / (TypeSize[typeIdx_] * (1 << vecSizeIdx_)); + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < NUM_ITER; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Program scope global write bandwidth in GB/s + double perf = + ((double)bufSize_ * numReads_ * NUM_ITER * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char buf[256]; + char buf2[256]; + SNPRINTF(buf, sizeof(buf), "%s%s", types[typeIdx_], vecWidths[vecSizeIdx_]); + SNPRINTF(buf2, sizeof(buf2), " %-8s (%8d) %2d reads: (GB/s) ", buf, width_, + numReads_); + testDescString = buf2; +#endif +} + +unsigned int OCLPerfProgramGlobalWrite::close(void) { +#if defined(CL_VERSION_2_0) + if (cmd_queue_) _wrapper->clFinish(cmd_queue_); + + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (constBuffer_) { + error_ = _wrapper->clReleaseMemObject(constBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(constBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } +#endif + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfProgramGlobalWrite.h b/opencl/tests/ocltst/module/perf/OCLPerfProgramGlobalWrite.h new file mode 100644 index 0000000000..15d7407182 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfProgramGlobalWrite.h @@ -0,0 +1,58 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PROGRAMGLOBALWRITE_H_ +#define _OCL_PROGRAMGLOBALWRITE_H_ + +#include "OCLTestImp.h" + +class OCLPerfProgramGlobalWrite : public OCLTestImp { + public: + OCLPerfProgramGlobalWrite(); + virtual ~OCLPerfProgramGlobalWrite(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void genShader(unsigned int type, unsigned int vecWidth, + unsigned int numReads, unsigned int bufSize); + + static const unsigned int NUM_ITER = 100; + + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem outBuffer_; + cl_mem constBuffer_; + + unsigned int width_; + unsigned int bufSize_; + unsigned int vecSizeIdx_; + unsigned int numReads_; + unsigned int typeIdx_; + + bool skip_; +}; + +#endif // _OCL_PROGRAMGLOBALWRITE_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSHA256.cpp b/opencl/tests/ocltst/module/perf/OCLPerfSHA256.cpp new file mode 100644 index 0000000000..db3d79a4f2 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSHA256.cpp @@ -0,0 +1,841 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfSHA256.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +static const char *sha256_kernel = + "typedef uint UINT;\n" + "\n" + "#define VECTOR_LEN 1\n" + "\n" + "#ifdef LITTLE_E\n" + "\n" + "inline UINT byteswap(UINT x)\n" + "{\n" + " UINT res = 0;\n" + " \n" + " for (uint i=0; i<4; i++)\n" + " {\n" + " res <<= 8;\n" + " res |= (x & 0xff);\n" + " x >>= 8;\n" + " }\n" + " \n" + " return res;\n" + "}\n" + "\n" + "#else\n" + "\n" + "inline UINT byteswap(const UINT x)\n" + "{\n" + " return x;\n" + "}\n" + "\n" + "#endif\n" + "\n" + "\n" + "void sha256_step( const UINT data[16], UINT *state )\n" + "{\n" + " UINT W[64], temp1, temp2;\n" + " UINT A, B, C, D, E, F, G, H;\n" + "\n" + " for( int i = 0; i < 16; i++)\n" + " {\n" + " W[i] = byteswap(data[i]);\n" + " }\n" + "\n" + "#define SHR(x,n) ((x & 0xFFFFFFFF) >> n)\n" + "#define ROTR(x,n) (SHR(x,n) | (x << (32 - n)))\n" + "\n" + "#define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))\n" + "#define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))\n" + "\n" + "#define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))\n" + "#define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))\n" + "\n" + "#define F0(x,y,z) ((x & y) | (z & (x | y)))\n" + "#define F1(x,y,z) (z ^ (x & (y ^ z)))\n" + "\n" + "#define R(t) \\\n" + "( \\\n" + " W[t] = S1(W[t - 2]) + W[t - 7] + \\\n" + " S0(W[t - 15]) + W[t - 16] \\\n" + ")\n" + "\n" + "#define P(a,b,c,d,e,f,g,h,x,K) \\\n" + "{ \\\n" + " temp1 = h + S3(e) + F1(e,f,g) + K + x; \\\n" + " temp2 = S2(a) + F0(a,b,c); \\\n" + " d += temp1; h = temp1 + temp2; \\\n" + "}\n" + "\n" + " A = state[0];\n" + " B = state[1];\n" + " C = state[2];\n" + " D = state[3];\n" + " E = state[4];\n" + " F = state[5];\n" + " G = state[6];\n" + " H = state[7];\n" + "\n" + " P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98 );\n" + " P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491 );\n" + " P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF );\n" + " P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5 );\n" + " P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B );\n" + " P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1 );\n" + " P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4 );\n" + " P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5 );\n" + " P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98 );\n" + " P( H, A, B, C, D, E, F, G, W[ 9], 0x12835B01 );\n" + " P( G, H, A, B, C, D, E, F, W[10], 0x243185BE );\n" + " P( F, G, H, A, B, C, D, E, W[11], 0x550C7DC3 );\n" + " P( E, F, G, H, A, B, C, D, W[12], 0x72BE5D74 );\n" + " P( D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE );\n" + " P( C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7 );\n" + " P( B, C, D, E, F, G, H, A, W[15], 0xC19BF174 );\n" + " P( A, B, C, D, E, F, G, H, R(16), 0xE49B69C1 );\n" + " P( H, A, B, C, D, E, F, G, R(17), 0xEFBE4786 );\n" + " P( G, H, A, B, C, D, E, F, R(18), 0x0FC19DC6 );\n" + " P( F, G, H, A, B, C, D, E, R(19), 0x240CA1CC );\n" + " P( E, F, G, H, A, B, C, D, R(20), 0x2DE92C6F );\n" + " P( D, E, F, G, H, A, B, C, R(21), 0x4A7484AA );\n" + " P( C, D, E, F, G, H, A, B, R(22), 0x5CB0A9DC );\n" + " P( B, C, D, E, F, G, H, A, R(23), 0x76F988DA );\n" + " P( A, B, C, D, E, F, G, H, R(24), 0x983E5152 );\n" + " P( H, A, B, C, D, E, F, G, R(25), 0xA831C66D );\n" + " P( G, H, A, B, C, D, E, F, R(26), 0xB00327C8 );\n" + " P( F, G, H, A, B, C, D, E, R(27), 0xBF597FC7 );\n" + " P( E, F, G, H, A, B, C, D, R(28), 0xC6E00BF3 );\n" + " P( D, E, F, G, H, A, B, C, R(29), 0xD5A79147 );\n" + " P( C, D, E, F, G, H, A, B, R(30), 0x06CA6351 );\n" + " P( B, C, D, E, F, G, H, A, R(31), 0x14292967 );\n" + " P( A, B, C, D, E, F, G, H, R(32), 0x27B70A85 );\n" + " P( H, A, B, C, D, E, F, G, R(33), 0x2E1B2138 );\n" + " P( G, H, A, B, C, D, E, F, R(34), 0x4D2C6DFC );\n" + " P( F, G, H, A, B, C, D, E, R(35), 0x53380D13 );\n" + " P( E, F, G, H, A, B, C, D, R(36), 0x650A7354 );\n" + " P( D, E, F, G, H, A, B, C, R(37), 0x766A0ABB );\n" + " P( C, D, E, F, G, H, A, B, R(38), 0x81C2C92E );\n" + " P( B, C, D, E, F, G, H, A, R(39), 0x92722C85 );\n" + " P( A, B, C, D, E, F, G, H, R(40), 0xA2BFE8A1 );\n" + " P( H, A, B, C, D, E, F, G, R(41), 0xA81A664B );\n" + " P( G, H, A, B, C, D, E, F, R(42), 0xC24B8B70 );\n" + " P( F, G, H, A, B, C, D, E, R(43), 0xC76C51A3 );\n" + " P( E, F, G, H, A, B, C, D, R(44), 0xD192E819 );\n" + " P( D, E, F, G, H, A, B, C, R(45), 0xD6990624 );\n" + " P( C, D, E, F, G, H, A, B, R(46), 0xF40E3585 );\n" + " P( B, C, D, E, F, G, H, A, R(47), 0x106AA070 );\n" + " P( A, B, C, D, E, F, G, H, R(48), 0x19A4C116 );\n" + " P( H, A, B, C, D, E, F, G, R(49), 0x1E376C08 );\n" + " P( G, H, A, B, C, D, E, F, R(50), 0x2748774C );\n" + " P( F, G, H, A, B, C, D, E, R(51), 0x34B0BCB5 );\n" + " P( E, F, G, H, A, B, C, D, R(52), 0x391C0CB3 );\n" + " P( D, E, F, G, H, A, B, C, R(53), 0x4ED8AA4A );\n" + " P( C, D, E, F, G, H, A, B, R(54), 0x5B9CCA4F );\n" + " P( B, C, D, E, F, G, H, A, R(55), 0x682E6FF3 );\n" + " P( A, B, C, D, E, F, G, H, R(56), 0x748F82EE );\n" + " P( H, A, B, C, D, E, F, G, R(57), 0x78A5636F );\n" + " P( G, H, A, B, C, D, E, F, R(58), 0x84C87814 );\n" + " P( F, G, H, A, B, C, D, E, R(59), 0x8CC70208 );\n" + " P( E, F, G, H, A, B, C, D, R(60), 0x90BEFFFA );\n" + " P( D, E, F, G, H, A, B, C, R(61), 0xA4506CEB );\n" + " P( C, D, E, F, G, H, A, B, R(62), 0xBEF9A3F7 );\n" + " P( B, C, D, E, F, G, H, A, R(63), 0xC67178F2 );\n" + "\n" + " state[0] += A;\n" + " state[1] += B;\n" + " state[2] += C;\n" + " state[3] += D;\n" + " state[4] += E;\n" + " state[5] += F;\n" + " state[6] += G;\n" + " state[7] += H;\n" + "}\n" + "\n" + "\n" + "#define choose_temp(x) ((x)/16)\n" + "\n" + "#define STORE_TO_TEMP(i) tb[((i)/16)][((i)%16)]\n" + "\n" + "\n" + "__kernel void CryptThread(__global const uint *buffer, __global uint " + "*state, const uint blockLen, const uint foo)\n" + "{\n" + " const uint init[8] = {\n" + " 0x6a09e667,\n" + " 0xbb67ae85,\n" + " 0x3c6ef372,\n" + " 0xa54ff53a,\n" + " 0x510e527f,\n" + " 0x9b05688c,\n" + " 0x1f83d9ab,\n" + " 0x5be0cd19\n" + " };\n" + " \n" + " const uint id = get_global_id(0);\n" + " uint len = blockLen;\n" + " uint i, j;\n" + " const uint startPosInDWORDs = (len*id*foo)/4;\n" + " const uint msgLenInBitsl = len * 8;\n" + " const uint msgLenInBitsh = (len) >> (32-3);\n" + " UINT localState[8];\n" + "\n" + " for (j=0; j<8; j++) {\n" + " localState[j] = init[j];\n" + " }\n" + "\n" + " i = 0;\n" + " while (len >=64)\n" + " {\n" + " UINT data[16];\n" + " for (j=0; j<16; j++) {\n" + " data[j] = buffer[j + startPosInDWORDs + i];\n" + " }\n" + "\n" + " sha256_step(data, localState);\n" + " i += 16;\n" + " len -= 64;\n" + " }\n" + "\n" + " len /= 4;\n" + "\n" + " UINT tb[2][16];\n" + "\n" + " for (j=0; j>= 8;\n" + " }\n" + " \n" + " return res;\n" + "}\n" + "\n" + "#else\n" + "\n" + "inline UINT byteswap(const UINT x)\n" + "{\n" + " return x;\n" + "}\n" + "\n" + "#endif\n" + "\n" + "\n" + "void sha256_step( const UINT data[16], UINT *state )\n" + "{\n" + " UINT W[64], temp1, temp2;\n" + " UINT A, B, C, D, E, F, G, H;\n" + "\n" + " for( int i = 0; i < 16; i++)\n" + " {\n" + " W[i] = byteswap(data[i]);\n" + " }\n" + "\n" + "#define SHR(x,n) ((x & 0xFFFFFFFF) >> n)\n" + "#define ROTR(x,n) (SHR(x,n) | (x << (32 - n)))\n" + "\n" + "#define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))\n" + "#define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))\n" + "\n" + "#define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))\n" + "#define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))\n" + "\n" + "#define F0(x,y,z) ((x & y) | (z & (x | y)))\n" + "#define F1(x,y,z) (z ^ (x & (y ^ z)))\n" + "\n" + "#define R(t) \\\n" + "( \\\n" + " W[t] = S1(W[t - 2]) + W[t - 7] + \\\n" + " S0(W[t - 15]) + W[t - 16] \\\n" + ")\n" + "\n" + "#define P(a,b,c,d,e,f,g,h,x,K) \\\n" + "{ \\\n" + " temp1 = h + S3(e) + F1(e,f,g) + K + x; \\\n" + " temp2 = S2(a) + F0(a,b,c); \\\n" + " d += temp1; h = temp1 + temp2; \\\n" + "}\n" + "\n" + " A = state[0];\n" + " B = state[1];\n" + " C = state[2];\n" + " D = state[3];\n" + " E = state[4];\n" + " F = state[5];\n" + " G = state[6];\n" + " H = state[7];\n" + "\n" + " P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98 );\n" + " P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491 );\n" + " P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF );\n" + " P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5 );\n" + " P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B );\n" + " P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1 );\n" + " P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4 );\n" + " P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5 );\n" + " P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98 );\n" + " P( H, A, B, C, D, E, F, G, W[ 9], 0x12835B01 );\n" + " P( G, H, A, B, C, D, E, F, W[10], 0x243185BE );\n" + " P( F, G, H, A, B, C, D, E, W[11], 0x550C7DC3 );\n" + " P( E, F, G, H, A, B, C, D, W[12], 0x72BE5D74 );\n" + " P( D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE );\n" + " P( C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7 );\n" + " P( B, C, D, E, F, G, H, A, W[15], 0xC19BF174 );\n" + " P( A, B, C, D, E, F, G, H, R(16), 0xE49B69C1 );\n" + " P( H, A, B, C, D, E, F, G, R(17), 0xEFBE4786 );\n" + " P( G, H, A, B, C, D, E, F, R(18), 0x0FC19DC6 );\n" + " P( F, G, H, A, B, C, D, E, R(19), 0x240CA1CC );\n" + " P( E, F, G, H, A, B, C, D, R(20), 0x2DE92C6F );\n" + " P( D, E, F, G, H, A, B, C, R(21), 0x4A7484AA );\n" + " P( C, D, E, F, G, H, A, B, R(22), 0x5CB0A9DC );\n" + " P( B, C, D, E, F, G, H, A, R(23), 0x76F988DA );\n" + " P( A, B, C, D, E, F, G, H, R(24), 0x983E5152 );\n" + " P( H, A, B, C, D, E, F, G, R(25), 0xA831C66D );\n" + " P( G, H, A, B, C, D, E, F, R(26), 0xB00327C8 );\n" + " P( F, G, H, A, B, C, D, E, R(27), 0xBF597FC7 );\n" + " P( E, F, G, H, A, B, C, D, R(28), 0xC6E00BF3 );\n" + " P( D, E, F, G, H, A, B, C, R(29), 0xD5A79147 );\n" + " P( C, D, E, F, G, H, A, B, R(30), 0x06CA6351 );\n" + " P( B, C, D, E, F, G, H, A, R(31), 0x14292967 );\n" + " P( A, B, C, D, E, F, G, H, R(32), 0x27B70A85 );\n" + " P( H, A, B, C, D, E, F, G, R(33), 0x2E1B2138 );\n" + " P( G, H, A, B, C, D, E, F, R(34), 0x4D2C6DFC );\n" + " P( F, G, H, A, B, C, D, E, R(35), 0x53380D13 );\n" + " P( E, F, G, H, A, B, C, D, R(36), 0x650A7354 );\n" + " P( D, E, F, G, H, A, B, C, R(37), 0x766A0ABB );\n" + " P( C, D, E, F, G, H, A, B, R(38), 0x81C2C92E );\n" + " P( B, C, D, E, F, G, H, A, R(39), 0x92722C85 );\n" + " P( A, B, C, D, E, F, G, H, R(40), 0xA2BFE8A1 );\n" + " P( H, A, B, C, D, E, F, G, R(41), 0xA81A664B );\n" + " P( G, H, A, B, C, D, E, F, R(42), 0xC24B8B70 );\n" + " P( F, G, H, A, B, C, D, E, R(43), 0xC76C51A3 );\n" + " P( E, F, G, H, A, B, C, D, R(44), 0xD192E819 );\n" + " P( D, E, F, G, H, A, B, C, R(45), 0xD6990624 );\n" + " P( C, D, E, F, G, H, A, B, R(46), 0xF40E3585 );\n" + " P( B, C, D, E, F, G, H, A, R(47), 0x106AA070 );\n" + " P( A, B, C, D, E, F, G, H, R(48), 0x19A4C116 );\n" + " P( H, A, B, C, D, E, F, G, R(49), 0x1E376C08 );\n" + " P( G, H, A, B, C, D, E, F, R(50), 0x2748774C );\n" + " P( F, G, H, A, B, C, D, E, R(51), 0x34B0BCB5 );\n" + " P( E, F, G, H, A, B, C, D, R(52), 0x391C0CB3 );\n" + " P( D, E, F, G, H, A, B, C, R(53), 0x4ED8AA4A );\n" + " P( C, D, E, F, G, H, A, B, R(54), 0x5B9CCA4F );\n" + " P( B, C, D, E, F, G, H, A, R(55), 0x682E6FF3 );\n" + " P( A, B, C, D, E, F, G, H, R(56), 0x748F82EE );\n" + " P( H, A, B, C, D, E, F, G, R(57), 0x78A5636F );\n" + " P( G, H, A, B, C, D, E, F, R(58), 0x84C87814 );\n" + " P( F, G, H, A, B, C, D, E, R(59), 0x8CC70208 );\n" + " P( E, F, G, H, A, B, C, D, R(60), 0x90BEFFFA );\n" + " P( D, E, F, G, H, A, B, C, R(61), 0xA4506CEB );\n" + " P( C, D, E, F, G, H, A, B, R(62), 0xBEF9A3F7 );\n" + " P( B, C, D, E, F, G, H, A, R(63), 0xC67178F2 );\n" + "\n" + " state[0] += A;\n" + " state[1] += B;\n" + " state[2] += C;\n" + " state[3] += D;\n" + " state[4] += E;\n" + " state[5] += F;\n" + " state[6] += G;\n" + " state[7] += H;\n" + "}\n" + "\n" + "\n" + "#define choose_temp(x) ((x)/16)\n" + "\n" + "#define STORE_TO_TEMP(i) tb[((i)/16)][((i)%16)]\n" + "\n" + "#define WAVEFRONT_SIZE 64\n" + "\n" + "__kernel void CryptThread(__global const uint *buffer, __global uint " + "*state, const uint blockLen, const uint foo)\n" + "{\n" + " const uint init[8] = {\n" + " 0x6a09e667,\n" + " 0xbb67ae85,\n" + " 0x3c6ef372,\n" + " 0xa54ff53a,\n" + " 0x510e527f,\n" + " 0x9b05688c,\n" + " 0x1f83d9ab,\n" + " 0x5be0cd19\n" + " };\n" + " \n" + " const uint id = get_global_id(0);\n" + " const uint lid = get_local_id(0);\n" + " uint len = blockLen;\n" + " uint i, j;\n" + " const uint startPosInDWORDs = (len*id*foo)/4;\n" + "uint blockStartInDWORDs = (len*(id / WAVEFRONT_SIZE)*WAVEFRONT_SIZE)/4;\n" + " const uint msgLenInBitsl = len * 8;\n" + " const uint msgLenInBitsh = (len) >> (32-3);\n" + " UINT localState[8];\n" + "\n" + " for (j=0; j<8; j++) {\n" + " localState[j] = init[j];\n" + " }\n" + "\n" + " i = 0;\n" + " while (len >=64)\n" + " {\n" + " UINT data[16];\n" + " for (j=0; j<16; j++) {\n" + " //data[j] = buffer[j + startPosInDWORDs + i];\n" + " data[j] = buffer[j*WAVEFRONT_SIZE + blockStartInDWORDs " + "+ i*WAVEFRONT_SIZE + lid];\n" + " }\n" + "\n" + " sha256_step(data, localState);\n" + " i += 16;\n" + " len -= 64;\n" + " }\n" + "\n" + " len /= 4;\n" + "\n" + " UINT tb[2][16];\n" + "\n" + " for (j=0; jclEnqueueMapBuffer( + cmd_queue_, buffer, true, CL_MAP_WRITE, 0, bufSize_, 0, NULL, NULL, + &error_); + + if (error_ != CL_SUCCESS) { + printf("\nError code : %d\n", error_); + } else { + for (unsigned int i = 0; i < width_; i++) data[i] = val; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, + NULL, NULL); + if (error_ == CL_SUCCESS) retVal = true; + } + return retVal; +} + +void OCLPerfSHA256::checkData(cl_mem buffer) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, buffer, true, CL_MAP_READ, 0, bufSize_, 0, NULL, NULL, + &error_); + for (unsigned int i = 0; i < width_; i++) { + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfSHA256::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + inBuffer_ = 0; + outBuffer_ = 0; + num_input_buf_ = 1; + num_output_buf_ = 1; + blockSize_ = 1024; + isAMD = false; + + width_ = 22347776; + // We compute a square domain + bufSize_ = width_ * sizeof(cl_uint); + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, + "Couldn't find platform with GPU devices, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + switch (_openTest % NUM_BUF_TYPES) { + case 0: + num_input_buf_ = 1; + num_output_buf_ = 1; + break; + + case 1: + num_input_buf_ = 1; + num_output_buf_ = 4; + break; + + case 2: + num_input_buf_ = 4; + num_output_buf_ = 4; + break; + }; + + inBuffer_ = new cl_mem[num_input_buf_]; + outBuffer_ = new cl_mem[num_output_buf_]; + + for (int i = 0; i < num_input_buf_; ++i) { + inBuffer_[i] = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(inBuffer_[i] == 0, "clCreateBuffer(inBuffer) failed"); + bool result = setData(inBuffer_[i], 0xdeadbeef); + CHECK_RESULT(result != true, "clEnqueueMapBuffer buffer failed"); + } + + for (int i = 0; i < num_output_buf_; ++i) { + outBuffer_[i] = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_[i] == 0, "clCreateBuffer(outBuffer) failed"); + bool result = setData(outBuffer_[i], 0xdeadbeef); + CHECK_RESULT(result != true, "clEnqueueMapBuffer buffer failed"); + } + + if (_openTest >= NUM_BUF_TYPES) { + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&sha256_opt_kernel, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + } else { + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&sha256_kernel, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + } + + const char *buildOps = NULL; + if (isAMD) { + // Enable caching + buildOps = "-fno-alias"; + } + error_ = _wrapper->clBuildProgram(program_, 1, &device, buildOps, NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "CryptThread", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&inBuffer_[0]); + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), + (void *)&outBuffer_[0]); + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), + (void *)&blockSize_); + // Foo is not part of the original test, this can be used to see how much of + // the performance is limited by fetch. Set foo to 0 and all threads will + // fetch the same 1k block. This way they will all be in cache and hit max + // fetch speed. + unsigned int foo = 1; + error_ = _wrapper->clSetKernelArg(kernel_, 3, sizeof(cl_uint), (void *)&foo); +} + +void OCLPerfSHA256::run(void) { + int global = bufSize_ / blockSize_; + // 32 gives the best result due to memory thrashing. Need to optimize and + // give feedback to SiSoft. + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + // Warm-up + for (unsigned int i = 0; i < 10; i++) { + if (num_input_buf_ > 1) { + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&inBuffer_[i % num_input_buf_]); + } + + if (num_output_buf_ > 1) { + error_ = _wrapper->clSetKernelArg( + kernel_, 1, sizeof(cl_mem), (void *)&outBuffer_[i % num_output_buf_]); + } + + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + } + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue_); + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < MAX_ITERATIONS; i++) { + if (num_input_buf_ > 1) { + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&inBuffer_[i % num_input_buf_]); + } + + if (num_output_buf_ > 1) { + error_ = _wrapper->clSetKernelArg( + kernel_, 1, sizeof(cl_mem), (void *)&outBuffer_[i % num_output_buf_]); + } + + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + } + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // No idea what data should be in here + // checkData(outBuffer_); + // Compute GB/s + double perf = + ((double)bufSize_ * (double)MAX_ITERATIONS * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + if (_openTest >= NUM_BUF_TYPES) { + testDescString = "opt "; + } else { + testDescString = "def "; + } + + testDescString += "with "; + char str[40]; + sprintf(str, "%2d ip buff and %2d op buff ", num_input_buf_, num_output_buf_); + testDescString += str; +} + +unsigned int OCLPerfSHA256::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (inBuffer_) { + for (int i = 0; i < num_input_buf_; ++i) { + error_ = _wrapper->clReleaseMemObject(inBuffer_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + delete[] inBuffer_; + } + if (outBuffer_) { + for (int i = 0; i < num_output_buf_; ++i) { + error_ = _wrapper->clReleaseMemObject(outBuffer_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + delete[] outBuffer_; + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSHA256.h b/opencl/tests/ocltst/module/perf/OCLPerfSHA256.h new file mode 100644 index 0000000000..43e0147d08 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSHA256.h @@ -0,0 +1,58 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_SHA256_H_ +#define _OCL_SHA256_H_ + +#include "OCLTestImp.h" + +class OCLPerfSHA256 : public OCLTestImp { + public: + OCLPerfSHA256(); + virtual ~OCLPerfSHA256(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + bool setData(cl_mem buffer, unsigned int data); + void checkData(cl_mem buffer); + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem* inBuffer_; + cl_mem* outBuffer_; + cl_int num_input_buf_; + cl_int num_output_buf_; + cl_int error_; + + unsigned int width_; + unsigned int bufSize_; + unsigned int blockSize_; + static const unsigned int MAX_ITERATIONS = 100; + bool isAMD; +}; + +#endif // _OCL_SHA256_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSVMAlloc.cpp b/opencl/tests/ocltst/module/perf/OCLPerfSVMAlloc.cpp new file mode 100644 index 0000000000..bab5139f42 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSVMAlloc.cpp @@ -0,0 +1,263 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfSVMAlloc.h" + +#include +#include +#include + +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 5 +#define NUM_CG_FLAGS 3 +#define NUM_FG_FLAGS 3 + +static size_t sizeList[NUM_SIZES] = { + 0x040000, 0x080000, 0x100000, 0x200000, 0x400000, +}; + +#if defined(CL_VERSION_2_0) +static const cl_svm_mem_flags CGFlags[NUM_CG_FLAGS] = { + CL_MEM_READ_WRITE, + CL_MEM_WRITE_ONLY, + CL_MEM_READ_ONLY, +}; +static const cl_svm_mem_flags FGFlags[NUM_FG_FLAGS] = { + 0, + CL_MEM_SVM_FINE_GRAIN_BUFFER, + CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS, +}; +#endif + +static const char *strKernel = + "__kernel void dummy(__global uint* out) \n" + "{ \n" + " uint id = get_global_id(0); \n" + " uint value = 1; \n" + " if ((int)get_local_id(0) < 0) \n" + " out[id] = value; \n" + "} \n"; + +OCLPerfSVMAlloc::OCLPerfSVMAlloc() { + _numSubTests = NUM_CG_FLAGS * NUM_FG_FLAGS * NUM_SIZES + NUM_SIZES; + failed_ = false; + skip_ = false; +} + +OCLPerfSVMAlloc::~OCLPerfSVMAlloc() {} + +void OCLPerfSVMAlloc::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + +#if defined(CL_VERSION_2_0) + FGSystem_ = (test >= (NUM_CG_FLAGS * NUM_FG_FLAGS * NUM_SIZES)); + testFGFlag_ = (test / (NUM_SIZES * NUM_CG_FLAGS)) % NUM_FG_FLAGS; + testCGFlag_ = (test / NUM_SIZES) % NUM_CG_FLAGS; + testSize_ = test % NUM_SIZES; + + cl_device_svm_capabilities caps; + error_ = clGetDeviceInfo(devices_[deviceId], CL_DEVICE_SVM_CAPABILITIES, + sizeof(cl_device_svm_capabilities), &caps, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if ((caps & CL_DEVICE_SVM_COARSE_GRAIN_BUFFER) == 0) { + skip_ = true; // Should never happen as OCL 2.0 devices are required to + // support coarse grain SVM + testDescString = "Coarse Grain Buffer NOT supported. Test Skipped."; + return; + } else if (testFGFlag_ > 0 && (caps & CL_DEVICE_SVM_FINE_GRAIN_BUFFER) == 0) { + skip_ = true; // No support for fine grain buffer SVM + testDescString = "Fine Grain Buffer NOT supported. Test Skipped."; + return; + } else if (FGSystem_ && (caps & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM) == 0) { + skip_ = true; // No support for fine grain system SVM + testDescString = "Fine Grain System NOT supported. Test Skipped."; + return; + } else if (testFGFlag_ == 2 && (caps & CL_DEVICE_SVM_ATOMICS) == 0) { + skip_ = true; // No support for fine grain system SVM + testDescString = "SVM Atomic NOT supported. Test Skipped."; + return; + } + + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + kernel_ = _wrapper->clCreateKernel(program_, "dummy", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + return; +#else + skip_ = true; + testDescString = "SVM NOT supported for < 2.0 builds. Test Skipped."; + return; +#endif +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfSVMAlloc::run(void) { + if (skip_) { + return; + } + + if (failed_) { + return; + } +#if defined(CL_VERSION_2_0) + cl_uint *buffer = NULL; + CPerfCounter timer; + void *hostPtr = NULL; + + size_t bufSize = sizeList[testSize_] * sizeof(cl_int4); + size_t iter = 100; + + cl_mem_flags flags = CGFlags[testCGFlag_] | FGFlags[testFGFlag_]; + + timer.Reset(); + timer.Start(); + + size_t gws[1] = {bufSize / sizeof(cl_int4)}; + size_t lws[1] = {64}; + + for (size_t i = 0; i < iter; ++i) { + if (!FGSystem_) { + buffer = (cl_uint *)clSVMAlloc(context_, flags, bufSize, 0); + } else { + buffer = (cl_uint *)malloc(bufSize); + } + CHECK_RESULT(buffer == 0, "Allocation failed"); + + error_ = _wrapper->clSetKernelArgSVMPointer(kernel_, 0, buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + + if (!FGSystem_) { + clSVMFree(context_, (void *)buffer); + } else { + free(buffer); + } + } + + timer.Stop(); + + CPerfCounter timer2; + timer2.Reset(); + size_t numN = 100; + + if (!FGSystem_) { + buffer = (cl_uint *)clSVMAlloc(context_, flags, bufSize, 0); + } else { + buffer = (cl_uint *)malloc(bufSize); + } + CHECK_RESULT(buffer == 0, "Allocation failed"); + + timer2.Start(); + for (size_t i = 0; i < numN; ++i) { + error_ = _wrapper->clSetKernelArgSVMPointer(kernel_, 0, buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + timer2.Stop(); + + if (!FGSystem_) { + clSVMFree(context_, (void *)buffer); + } else { + free(buffer); + } + + char pFlags[5]; + pFlags[0] = + (testCGFlag_ == 0 || testCGFlag_ == 2) ? 'R' : '_'; // CL_MEM_READ_ONLY + pFlags[1] = + (testCGFlag_ == 0 || testCGFlag_ == 1) ? 'W' : '_'; // CL_MEM_WRITE_ONLY + pFlags[2] = (testFGFlag_ == 1 || testFGFlag_ == 2) + ? 'F' + : '_'; // CL_MEM_SVM_FINE_GRAIN_BUFFER + pFlags[3] = (testFGFlag_ == 2) ? 'A' : '_'; // CL_MEM_SVM_ATOMICS + + char buf[256]; + + if (!FGSystem_ && (testFGFlag_ == 0)) { + SNPRINTF(buf, sizeof(buf), + "Coarse Grain Buffer Alloc + Free (GB/s) for %6d KB, flags=%4s", + (int)bufSize / 1024, pFlags); + } else if (!FGSystem_ && (testFGFlag_ > 0)) { + SNPRINTF(buf, sizeof(buf), + "Fine Grain Buffer Alloc + Free (GB/s) for %6d KB, flags=%4s", + (int)bufSize / 1024, pFlags); + } else if (FGSystem_) { + SNPRINTF(buf, sizeof(buf), + "Fine Grain System Alloc + Free (GB/s) for %6d KB, flags=N/A ", + (int)bufSize / 1024); + } + + testDescString = buf; + double sec1 = timer.GetElapsedTime(); + double sec2 = timer2.GetElapsedTime(); + _perfInfo = static_cast((bufSize * (double)(1e-09)) / + (sec1 / iter - sec2 / numN)); +#endif +} + +unsigned int OCLPerfSVMAlloc::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSVMAlloc.h b/opencl/tests/ocltst/module/perf/OCLPerfSVMAlloc.h new file mode 100644 index 0000000000..b0dac433eb --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSVMAlloc.h @@ -0,0 +1,46 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_SVM_ALLOC_H_ +#define _OCL_PERF_SVM_ALLOC_H_ + +#include "OCLTestImp.h" + +class OCLPerfSVMAlloc : public OCLTestImp { + public: + OCLPerfSVMAlloc(); + virtual ~OCLPerfSVMAlloc(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; + unsigned int testSize_; + bool FGSystem_; + unsigned int testCGFlag_; + unsigned int testFGFlag_; + bool skip_; +}; + +#endif // _OCL_PERF_SVM_ALLOC_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSVMKernelArguments.cpp b/opencl/tests/ocltst/module/perf/OCLPerfSVMKernelArguments.cpp new file mode 100644 index 0000000000..6de282dedb --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSVMKernelArguments.cpp @@ -0,0 +1,255 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfSVMKernelArguments.h" + +#include +#include +#include + +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +static const size_t BufSize = 0x1000; +static const size_t Iterations = 0x10000; +static const size_t TotalQueues = 4; +static const size_t TotalBufs = 4; +static const size_t TotalArgs = 4; + +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +static const char *Arguments[TotalArgs] = { + "__global uint* out", + "__global uint* out, __global uint* buf0, __global uint* buf1, __global " + "uint* buf2, __global uint* buf3", + "__global uint* out, __global uint* buf0, __global uint* buf1, __global " + "uint* buf2, __global uint* buf3, \n" + "__global uint* buf4, __global uint* buf5, __global uint* buf6, __global " + "uint* buf7, __global uint* buf8", + "__global uint* out, __global uint* buf0, __global uint* buf1, __global " + "uint* buf2, __global uint* buf3,\n" + "__global uint* buf4, __global uint* buf5, __global uint* buf6, __global " + "uint* buf7, __global uint* buf8,\n" + "__global uint* buf9, __global uint* buf10, __global uint* buf11, __global " + "uint* buf12, __global uint* buf13,\n" + "__global uint* buf14, __global uint* buf15, __global uint* buf16, " + "__global uint* buf17, __global uint* buf18"}; + +static const char *strKernel = + "__kernel void dummy(%s) \n" + "{ \n" + " uint id = get_global_id(0); \n" + " uint value = 1; \n" + " out[id] = value; \n" + "} \n"; + +OCLPerfSVMKernelArguments::OCLPerfSVMKernelArguments() { + _numSubTests = TotalQueues * TotalArgs; // * TotalBufs; + failed_ = false; + skip_ = false; +} + +OCLPerfSVMKernelArguments::~OCLPerfSVMKernelArguments() {} + +void OCLPerfSVMKernelArguments::open(unsigned int test, char *units, + double &conversion, + unsigned int deviceId) { +#if defined(CL_VERSION_2_0) + // cl_mem buffer; + _deviceId = deviceId; + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + test_ = test; + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + cl_device_svm_capabilities caps; + error_ = clGetDeviceInfo(devices_[deviceId], CL_DEVICE_SVM_CAPABILITIES, + sizeof(cl_device_svm_capabilities), &caps, NULL); + // check if CL_DEVICE_SVM_COARSE_GRAIN_BUFFER is set. Skip the test if not. + if (!(caps & 0x1)) { + skip_ = true; + testDescString = "SVM NOT supported. Test Skipped."; + return; + } + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + + size_t numArguments = (test_ / TotalQueues) % TotalArgs; + char *program = new char[4096]; + SNPRINTF(program, sizeof(char) * 4096, strKernel, Arguments[numArguments]); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&program, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + kernel_ = _wrapper->clCreateKernel(program_, "dummy", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + delete[] program; + + static const size_t NumBuffs[TotalBufs] = {0x20, 0x100, 0x800, 0x2000}; + + size_t bufSize = BufSize * sizeof(cl_int); + + numBufs_ = (unsigned int)NumBuffs[test_ / (TotalQueues * TotalArgs)]; + inOutBuffer = (void **)malloc(sizeof(void *) * numBufs_); + + for (size_t b = 0; b < numBufs_; ++b) { + inOutBuffer[b] = clSVMAlloc(context_, CL_MEM_READ_WRITE, bufSize, 0); + CHECK_RESULT((error_ != CL_SUCCESS), "clSVMAlloc() failed"); + } +#else + skip_ = true; + testDescString = "SVM NOT supported for < 2.0 builds. Test Skipped."; + return; +#endif +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfSVMKernelArguments::run(void) { + if (skip_) { + return; + } + + if (failed_) { + return; + } +#if defined(CL_VERSION_2_0) + CPerfCounter timer; + static const size_t Queues[] = {1, 2, 4, 8}; + size_t numQueues = Queues[test_ % TotalQueues]; + cl_uint numArguments; + _wrapper->clGetKernelInfo(kernel_, CL_KERNEL_NUM_ARGS, sizeof(cl_uint), + &numArguments, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetKernelInfo() failed"); + + size_t iter = Iterations / numQueues / numBufs_; + iter = (iter == 0) ? 1 : iter; + + std::vector cmdQueues(numQueues); + for (size_t q = 0; q < numQueues; ++q) { + cl_command_queue cmdQueue = _wrapper->clCreateCommandQueue( + context_, devices_[_deviceId], 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueue() failed"); + cmdQueues[q] = cmdQueue; + } + // Warm-up + for (size_t b = 0; b < (numBufs_ / numArguments); ++b) { + for (size_t q = 0; q < numQueues; ++q) { + for (cl_uint a = 0; a < numArguments; ++a) { + void *buffer = inOutBuffer[(b * numArguments + a) % numBufs_]; + error_ = _wrapper->clSetKernelArgSVMPointer(kernel_, a, buffer); + CHECK_RESULT((error_ != CL_SUCCESS), + "clSetKernelArgSVMPointer() failed"); + } + + size_t gws[1] = {256}; + size_t lws[1] = {256}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues[q], kernel_, 1, NULL, + gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + } + for (size_t q = 0; q < numQueues; ++q) { + _wrapper->clFinish(cmdQueues[q]); + } + + size_t disp = 0; + timer.Reset(); + timer.Start(); + + for (size_t i = 0; i < iter; ++i) { + for (size_t b = 0; b < numBufs_; ++b) { + for (size_t q = 0; q < numQueues; ++q) { + for (cl_uint a = 0; a < numArguments; ++a) { + void *buffer = inOutBuffer[(b * numArguments + a) % numBufs_]; + error_ = _wrapper->clSetKernelArgSVMPointer(kernel_, a, buffer); + CHECK_RESULT((error_ != CL_SUCCESS), + "clSetKernelArgSVMPointer() failed"); + } + + size_t gws[1] = {256}; + size_t lws[1] = {256}; + error_ = _wrapper->clEnqueueNDRangeKernel( + cmdQueues[q], kernel_, 1, NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + disp++; + } + } + } + for (size_t q = 0; q < numQueues; ++q) { + _wrapper->clFinish(cmdQueues[q]); + } + timer.Stop(); + + for (size_t q = 0; q < numQueues; ++q) { + error_ = _wrapper->clReleaseCommandQueue(cmdQueues[q]); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseCommandQueue() failed"); + } + + std::stringstream stream; + stream << "Setup time (us) for " << numQueues << " queues, "; + stream.flags(std::ios::right | std::ios::showbase); + stream.width(2); + stream << numArguments; + stream << " arguments, "; + stream.flags(std::ios::right | std::ios::showbase); + stream.width(4); + stream << numBufs_ << " buffers"; + testDescString = stream.str(); + _perfInfo = static_cast(timer.GetElapsedTime() * 1000000 / disp); +#endif +} + +unsigned int OCLPerfSVMKernelArguments::close(void) { +#if defined(CL_VERSION_2_0) + for (size_t b = 0; b < numBufs_; ++b) { + _wrapper->clSVMFree(context_, inOutBuffer[b]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clSVMFree() failed"); + } +#endif + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSVMKernelArguments.h b/opencl/tests/ocltst/module/perf/OCLPerfSVMKernelArguments.h new file mode 100644 index 0000000000..283d6506cf --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSVMKernelArguments.h @@ -0,0 +1,47 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_SVM_KERNEL_ARGUMENTS_H_ +#define _OCL_PERF_SVM_KERNEL_ARGUMENTS_H_ + +#include + +#include "OCLTestImp.h" + +class OCLPerfSVMKernelArguments : public OCLTestImp { + public: + OCLPerfSVMKernelArguments(); + virtual ~OCLPerfSVMKernelArguments(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; + unsigned int test_; + bool skip_; + void** inOutBuffer; + unsigned int numBufs_; +}; + +#endif // _OCL_PERF_SVM_KERNEL_ARGUMENTS_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSVMMap.cpp b/opencl/tests/ocltst/module/perf/OCLPerfSVMMap.cpp new file mode 100644 index 0000000000..251a0fc1fc --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSVMMap.cpp @@ -0,0 +1,153 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfSVMMap.h" + +#include +#include +#include + +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 5 +static size_t sizeList[] = { + 0x040000, 0x080000, 0x100000, 0x200000, 0x400000, +}; + +#define NUM_FLAGS 4 +static const cl_map_flags Flags[NUM_FLAGS] = {CL_MAP_READ, CL_MAP_WRITE, + CL_MAP_READ | CL_MAP_WRITE, + CL_MAP_WRITE_INVALIDATE_REGION}; + +OCLPerfSVMMap::OCLPerfSVMMap() { + _numSubTests = NUM_SIZES * NUM_FLAGS; + failed_ = false; + skip_ = false; +} + +OCLPerfSVMMap::~OCLPerfSVMMap() {} + +void OCLPerfSVMMap::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { +#if defined(CL_VERSION_2_0) + _deviceId = deviceId; + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + testFlag_ = test / NUM_SIZES; + testSize_ = test % NUM_SIZES; + + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + cl_device_svm_capabilities caps; + error_ = clGetDeviceInfo(devices_[deviceId], CL_DEVICE_SVM_CAPABILITIES, + sizeof(cl_device_svm_capabilities), &caps, NULL); + // check if CL_DEVICE_SVM_COARSE_GRAIN_BUFFER is set. Skip the test if not. + if (!(caps & 0x1)) { + skip_ = true; + testDescString = "SVM NOT supported. Test Skipped."; + return; + } + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } +#else + skip_ = true; + testDescString = "SVM NOT supported for < 2.0 builds. Test Skipped."; + return; +#endif +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfSVMMap::run(void) { + if (skip_) { + return; + } + + if (failed_) { + return; + } +#if defined(CL_VERSION_2_0) + void *buffer; + CPerfCounter timer; + void *hostPtr = NULL; + + const size_t bufSize = sizeList[testSize_] * sizeof(cl_int4); + const cl_map_flags flag = Flags[testFlag_]; + const size_t iter = 100; + + timer.Reset(); + + buffer = clSVMAlloc(context_, CL_MEM_READ_WRITE, bufSize, 0); + CHECK_RESULT((error_ != CL_SUCCESS), "clSVMAlloc() failed"); + + for (size_t i = 0; i < iter; ++i) { + timer.Start(); + + error_ = clEnqueueSVMMap(cmdQueues_[_deviceId], CL_FALSE, flag, buffer, + bufSize, 0, 0, 0); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueSVMMap() failed"); + + error_ = clEnqueueSVMUnmap(cmdQueues_[_deviceId], buffer, 0, 0, 0); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueSVMUnmap() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + + timer.Stop(); + } + + clSVMFree(context_, (void *)buffer); + + char pFlags[4]; + pFlags[0] = (testFlag_ == 0 || testFlag_ == 2) ? 'R' : '_'; // CL_MAP_READ + pFlags[1] = (testFlag_ == 1 || testFlag_ == 2) ? 'W' : '_'; // CL_MAP_WRITE + pFlags[2] = (testFlag_ == 3) ? 'I' : '_'; // CL_MAP_WRITE_INVALIDATE_REGION + + char buf[256]; + SNPRINTF(buf, sizeof(buf), "Map + Unmap (GB/s) for %6d KB, flags=%3s", + (int)bufSize / 1024, pFlags); + + testDescString = buf; + double sec = timer.GetElapsedTime(); + _perfInfo = static_cast((bufSize * iter * (double)(1e-09)) / sec); +#endif +} + +unsigned int OCLPerfSVMMap::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSVMMap.h b/opencl/tests/ocltst/module/perf/OCLPerfSVMMap.h new file mode 100644 index 0000000000..f9722bb15d --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSVMMap.h @@ -0,0 +1,44 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_SVM_MAP_H_ +#define _OCL_PERF_SVM_MAP_H_ + +#include "OCLTestImp.h" + +class OCLPerfSVMMap : public OCLTestImp { + public: + OCLPerfSVMMap(); + virtual ~OCLPerfSVMMap(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; + unsigned int testSize_; + unsigned int testFlag_; + bool skip_; +}; + +#endif // _OCL_PERF_SVM_MAP_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSVMMemFill.cpp b/opencl/tests/ocltst/module/perf/OCLPerfSVMMemFill.cpp new file mode 100644 index 0000000000..c1dacf3fae --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSVMMemFill.cpp @@ -0,0 +1,214 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfSVMMemFill.h" + +#include +#include +#include + +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_MODES 3 +#define NUM_CG_FLAGS 2 +#define NUM_FG_FLAGS 3 + +static size_t typeSizeList[] = { + 1, // sizeof(cl_uchar) + 2, 4, 8, 16, 32, 64, + 128, // sizeof(cl_ulong16) +}; + +static unsigned int eleNumList[] = { + 0x0020000, 0x0080000, 0x0200000, 0x0800000, 0x2000000, +}; + +#if defined(CL_VERSION_2_0) +static const cl_svm_mem_flags CGFlags[NUM_CG_FLAGS] = { + CL_MEM_READ_WRITE, + CL_MEM_WRITE_ONLY, +}; +static const cl_svm_mem_flags FGFlags[NUM_FG_FLAGS] = { + 0, + CL_MEM_SVM_FINE_GRAIN_BUFFER, + CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS, +}; +#endif + +OCLPerfSVMMemFill::OCLPerfSVMMemFill() { + num_typeSize_ = sizeof(typeSizeList) / sizeof(size_t); + num_elements_ = sizeof(eleNumList) / sizeof(unsigned int); + _numSubTests = + num_elements_ * num_typeSize_ * (NUM_FG_FLAGS * NUM_CG_FLAGS + 1); + failed_ = false; + skip_ = false; +} + +OCLPerfSVMMemFill::~OCLPerfSVMMemFill() {} + +void OCLPerfSVMMemFill::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + +#if defined(CL_VERSION_2_0) + FGSystem_ = + (test >= (num_elements_ * num_typeSize_ * NUM_FG_FLAGS * NUM_CG_FLAGS)); + testFGFlag_ = + (test / (num_elements_ * num_typeSize_ * NUM_CG_FLAGS)) % NUM_FG_FLAGS; + testCGFlag_ = (test / (num_elements_ * num_typeSize_)) % NUM_CG_FLAGS; + testTypeSize_ = typeSizeList[(test / num_elements_) % num_typeSize_]; + testNumEle_ = eleNumList[test % num_elements_]; + + cl_device_svm_capabilities caps; + error_ = clGetDeviceInfo(devices_[deviceId], CL_DEVICE_SVM_CAPABILITIES, + sizeof(cl_device_svm_capabilities), &caps, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if ((caps & CL_DEVICE_SVM_COARSE_GRAIN_BUFFER) == 0) { + skip_ = true; // Should never happen as OCL 2.0 devices are required to + // support coarse grain SVM + testDescString = "Coarse Grain Buffer NOT supported. Test Skipped."; + return; + } else if (testFGFlag_ > 0 && (caps & CL_DEVICE_SVM_FINE_GRAIN_BUFFER) == 0) { + skip_ = true; // No support for fine grain buffer SVM + testDescString = "Fine Grain Buffer NOT supported. Test Skipped."; + return; + } else if (FGSystem_ && (caps & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM) == 0) { + skip_ = true; // No support for fine grain system SVM + testDescString = "Fine Grain System NOT supported. Test Skipped."; + return; + } else if (testFGFlag_ == 2 && ((caps & CL_DEVICE_SVM_ATOMICS) == 0)) { + skip_ = true; // No support for SVM Atomic + testDescString = "SVM Atomic NOT supported. Test Skipped."; + return; + } + + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + return; +#else + skip_ = true; + testDescString = "SVM NOT supported for < 2.0 builds. Test Skipped."; + return; +#endif +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfSVMMemFill::run(void) { + if (skip_) { + return; + } + + if (failed_) { + return; + } +#if defined(CL_VERSION_2_0) + cl_uint *buffer = NULL; + CPerfCounter timer; + size_t iter = 100, bufSize = testNumEle_ * 4; + + cl_mem_flags flags = CGFlags[testCGFlag_] | FGFlags[testFGFlag_]; + + void *data = malloc(bufSize); + + timer.Reset(); + + if (!FGSystem_) { + buffer = + (cl_uint *)clSVMAlloc(context_, flags, bufSize, (cl_uint)testTypeSize_); + CHECK_RESULT(buffer == 0, "Allocation failed"); + } else { // FGSystem_ = true + buffer = (cl_uint *)malloc(bufSize); + CHECK_RESULT(buffer == 0, "Allocation failed"); + } + + timer.Start(); + for (size_t i = 0; i < iter; ++i) { + error_ = clEnqueueSVMMemFill(cmdQueues_[_deviceId], buffer, data, + testTypeSize_, bufSize, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueSVMMemFill() failed"); + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + timer.Stop(); + + if (!FGSystem_) { + clSVMFree(context_, (void *)buffer); + } else { + free(buffer); + } + + char pFlags[5]; + pFlags[0] = + (testCGFlag_ == 0 || testCGFlag_ == 2) ? 'R' : '_'; // CL_MEM_READ_ONLY + pFlags[1] = + (testCGFlag_ == 0 || testCGFlag_ == 1) ? 'W' : '_'; // CL_MEM_WRITE_ONLY + pFlags[2] = (testFGFlag_ == 1 || testFGFlag_ == 2) + ? 'F' + : '_'; // CL_MEM_SVM_FINE_GRAIN_BUFFER + pFlags[3] = (testFGFlag_ == 2) ? 'A' : '_'; // CL_MEM_SVM_ATOMICS + + char buf[256]; + + if (!FGSystem_ && (testFGFlag_ == 0)) { + SNPRINTF(buf, sizeof(buf), + "Coarse Grain Buffer SVMMemFill (GB/s) for %6d KB, typeSize:%3d, " + "flags=%4s", + (int)bufSize / 1024, (int)testTypeSize_, pFlags); + } else if (!FGSystem_ && (testFGFlag_ > 0)) { + SNPRINTF(buf, sizeof(buf), + "Fine Grain Buffer SVMMemFill (GB/s) for %6d KB, typeSize:%3d, " + "flags=%4s", + (int)bufSize / 1024, (int)testTypeSize_, pFlags); + } else if (FGSystem_) { + SNPRINTF(buf, sizeof(buf), + "Fine Grain System SVMMemFill (GB/s) for %6d KB, typeSize:%3d, " + "flags=%4s", + (int)bufSize / 1024, (int)testTypeSize_, pFlags); + } + + testDescString = buf; + double sec = timer.GetElapsedTime(); + _perfInfo = static_cast((bufSize * iter * (double)(1e-09)) / sec); +#endif +} + +unsigned int OCLPerfSVMMemFill::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSVMMemFill.h b/opencl/tests/ocltst/module/perf/OCLPerfSVMMemFill.h new file mode 100644 index 0000000000..a6a807d118 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSVMMemFill.h @@ -0,0 +1,50 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_SVM_MEMFILL_H_ +#define _OCL_PERF_SVM_MEMFILL_H_ + +#include "OCLTestImp.h" + +class OCLPerfSVMMemFill : public OCLTestImp { + public: + OCLPerfSVMMemFill(); + virtual ~OCLPerfSVMMemFill(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + unsigned int num_typeSize_; + unsigned int num_elements_; + bool FGSystem_; + size_t testTypeSize_; + unsigned int testCGFlag_; + unsigned int testFGFlag_; + unsigned int testNumEle_; + bool atomic_; + bool failed_; + bool skip_; +}; + +#endif // _OCL_PERF_SVM_MEMFILL_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSVMMemcpy.cpp b/opencl/tests/ocltst/module/perf/OCLPerfSVMMemcpy.cpp new file mode 100644 index 0000000000..0310a6463c --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSVMMemcpy.cpp @@ -0,0 +1,216 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfSVMMemcpy.h" + +#include +#include +#include + +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 5 +#define NUM_SRC_FLAGS 2 +#define NUM_DST_FLAGS 2 +#define NUM_FG_FLAGS 3 + +static size_t sizeList[NUM_SIZES] = { + 0x040000, 0x080000, 0x100000, 0x200000, 0x400000, +}; + +#if defined(CL_VERSION_2_0) +static const cl_svm_mem_flags srcFlagList[NUM_SRC_FLAGS] = {CL_MEM_READ_WRITE, + CL_MEM_READ_ONLY}; +static const cl_svm_mem_flags dstFlagList[NUM_DST_FLAGS] = {CL_MEM_READ_WRITE, + CL_MEM_WRITE_ONLY}; +static const cl_svm_mem_flags FGFlags[NUM_FG_FLAGS] = { + 0, + CL_MEM_SVM_FINE_GRAIN_BUFFER, + CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS, +}; +#endif + +OCLPerfSVMMemcpy::OCLPerfSVMMemcpy() { + _numSubTests = (NUM_SRC_FLAGS * NUM_DST_FLAGS * NUM_FG_FLAGS + 1) * NUM_SIZES; + failed_ = false; + skip_ = false; +} + +OCLPerfSVMMemcpy::~OCLPerfSVMMemcpy() {} + +void OCLPerfSVMMemcpy::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + +#if defined(CL_VERSION_2_0) + FGSystem_ = + (test >= (NUM_SIZES * NUM_SRC_FLAGS * NUM_DST_FLAGS * NUM_FG_FLAGS)); + testFGFlag_ = + (test / (NUM_SIZES * NUM_DST_FLAGS * NUM_SRC_FLAGS)) % (NUM_FG_FLAGS); + testSrcFlag_ = (test / (NUM_SIZES * NUM_DST_FLAGS)) % (NUM_SRC_FLAGS); + testDstFlag_ = (test / NUM_SIZES) % (NUM_DST_FLAGS); + testSize_ = test % NUM_SIZES; + + cl_device_svm_capabilities caps; + error_ = clGetDeviceInfo(devices_[deviceId], CL_DEVICE_SVM_CAPABILITIES, + sizeof(cl_device_svm_capabilities), &caps, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if ((caps & CL_DEVICE_SVM_COARSE_GRAIN_BUFFER) == 0) { + skip_ = true; // Should never happen as OCL 2.0 devices are required to + // support coarse grain SVM + testDescString = "Coarse Grain Buffer NOT supported. Test Skipped."; + return; + } else if ((testFGFlag_ > 0) && + (caps & CL_DEVICE_SVM_FINE_GRAIN_BUFFER) == 0) { + skip_ = true; // No support for fine grain buffer SVM + testDescString = "Fine Grain Buffer NOT supported. Test Skipped."; + return; + } else if (FGSystem_ && (caps & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM) == 0) { + skip_ = true; // No support for fine grain system SVM + testDescString = "Fine Grain System NOT supported. Test Skipped."; + return; + } else if ((testFGFlag_ == 2) && ((caps & CL_DEVICE_SVM_ATOMICS) == 0)) { + skip_ = true; // No support for SVM Atomic + testDescString = "SVM Atomic NOT supported. Test Skipped."; + return; + } + + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + return; +#else + skip_ = true; + testDescString = "SVM NOT supported for < 2.0 builds. Test Skipped."; + return; +#endif +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfSVMMemcpy::run(void) { + if (skip_) { + return; + } + + if (failed_) { + return; + } +#if defined(CL_VERSION_2_0) + cl_uint *src = NULL, *dst = NULL; + CPerfCounter timer; + + size_t bufSize = sizeList[testSize_] * sizeof(cl_int4); + size_t iter = 100; + + cl_mem_flags srcFlags = srcFlagList[testSrcFlag_] | FGFlags[testFGFlag_]; + cl_mem_flags dstFlags = dstFlagList[testDstFlag_] | FGFlags[testFGFlag_]; + + size_t gws[1] = {bufSize / sizeof(cl_int4)}; + size_t lws[1] = {64}; + + if (!FGSystem_) { + src = (cl_uint *)clSVMAlloc(context_, srcFlags, bufSize, 0); + CHECK_RESULT(src == 0, "Allocation failed"); + dst = (cl_uint *)clSVMAlloc(context_, dstFlags, bufSize, 0); + CHECK_RESULT(dst == 0, "Allocation failed"); + } else { // FGSystem_ == true + src = (cl_uint *)malloc(bufSize); + dst = (cl_uint *)malloc(bufSize); + } + + timer.Reset(); + timer.Start(); + for (size_t i = 0; i < iter; ++i) { + clEnqueueSVMMemcpy(cmdQueues_[_deviceId], false, dst, src, bufSize, 0, NULL, + NULL); + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + timer.Stop(); + + if (!FGSystem_) { + clSVMFree(context_, (void *)src); + clSVMFree(context_, (void *)dst); + } else { // FGSystem_ = true + free(src); + free(dst); + } + + char pSrcFlags[5]; + pSrcFlags[0] = + (testSrcFlag_ == 0 || testSrcFlag_ == 1) ? 'R' : '_'; // CL_MEM_READ_ONLY + pSrcFlags[1] = (testSrcFlag_ == 0) ? 'W' : '_'; // CL_MEM_WRITE_ONLY + pSrcFlags[2] = (testFGFlag_ == 1 || testFGFlag_ == 2) + ? 'F' + : '_'; // CL_MEM_SVM_FINE_GRAIN_BUFFER + pSrcFlags[3] = (testFGFlag_ == 2) ? 'A' : '_'; // CL_MEM_SVM_ATOMICS + pSrcFlags[4] = '\0'; + + char pDstFlags[5]; + pDstFlags[0] = (testDstFlag_ == 0) ? 'R' : '_'; + pDstFlags[1] = (testDstFlag_ == 0 || testDstFlag_ == 1) ? 'W' : '_'; + pDstFlags[2] = (testFGFlag_ == 1 || testFGFlag_ == 2) ? 'F' : '_'; + pDstFlags[3] = (testFGFlag_ == 2) ? 'A' : '_'; + pSrcFlags[4] = '\0'; + + char buf[256]; + + if (FGSystem_) { + SNPRINTF(buf, sizeof(buf), + "Fine Grain System SVMMemcpy (GB/s) for %6d KB, from:%4s to:%4s", + (int)bufSize / 1024, pSrcFlags, pDstFlags); + } else if (testFGFlag_ == 0) { + SNPRINTF(buf, sizeof(buf), + "Coarse Grain Buffer SVMMemcpy (GB/s) for %6d KB, from:%4s to:%4s", + (int)bufSize / 1024, pSrcFlags, pDstFlags); + } else { + SNPRINTF(buf, sizeof(buf), + "Fine Grain Buffer SVMMemcpy (GB/s) for %6d KB, from:%4s to:%4s", + (int)bufSize / 1024, pSrcFlags, pDstFlags); + } + + testDescString = buf; + double sec = timer.GetElapsedTime(); + _perfInfo = static_cast((bufSize * iter * (double)(1e-09)) / sec); +#endif +} + +unsigned int OCLPerfSVMMemcpy::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSVMMemcpy.h b/opencl/tests/ocltst/module/perf/OCLPerfSVMMemcpy.h new file mode 100644 index 0000000000..b03d39637f --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSVMMemcpy.h @@ -0,0 +1,47 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERF_SVM_MEMCPY_H_ +#define _OCL_PERF_SVM_MEMCPY_H_ + +#include "OCLTestImp.h" + +class OCLPerfSVMMemcpy : public OCLTestImp { + public: + OCLPerfSVMMemcpy(); + virtual ~OCLPerfSVMMemcpy(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; + unsigned int testSize_; + unsigned int testSrcFlag_; + unsigned int testDstFlag_; + unsigned int testFGFlag_; + bool FGSystem_; + bool skip_; +}; + +#endif // _OCL_PERF_SVM_MEMCPY_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSVMSampleRate.cpp b/opencl/tests/ocltst/module/perf/OCLPerfSVMSampleRate.cpp new file mode 100644 index 0000000000..e28365378d --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSVMSampleRate.cpp @@ -0,0 +1,359 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfSVMSampleRate.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_TYPES 3 +static const char *types[NUM_TYPES] = {"float", "float2", "float4"}; +static const unsigned int typeSizes[NUM_TYPES] = {4, 8, 16}; + +#define NUM_SIZES 12 +static const unsigned int sizes[NUM_SIZES] = {1, 2, 4, 8, 16, 32, + 64, 128, 256, 512, 1024, 2048}; + +#define NUM_BUFS 6 +#define MAX_BUFS (1 << (NUM_BUFS - 1)) + +#define NUM_READS numBufs_ + +OCLPerfSVMSampleRate::OCLPerfSVMSampleRate() { + _numSubTests = NUM_TYPES * NUM_SIZES * NUM_BUFS * 3; + skip_ = false; +} + +OCLPerfSVMSampleRate::~OCLPerfSVMSampleRate() {} + +void OCLPerfSVMSampleRate::setKernel(void) { + shader_.clear(); + shader_ += + "kernel void sampleRate(global DATATYPE* outBuffer, unsigned int " + "inBufSize, unsigned int writeIt,\n"; + char buf[256]; + for (unsigned int i = 0; i < numBufs_; i++) { + SNPRINTF(buf, sizeof(buf), "global DATATYPE* inBuffer%d", i); + shader_ += buf; + if (i < (numBufs_ - 1)) { + shader_ += ","; + } + shader_ += "\n"; + } + shader_ += ")\n"; + shader_ += + "{\n" + " uint gid = get_global_id(0);\n" + " uint inputIdx = gid % inBufSize;\n" + " DATATYPE tmp = (DATATYPE)0.0f;\n"; + + for (unsigned int j = 0; j < (NUM_READS / numBufs_); j++) { + for (unsigned int i = 0; i < numBufs_; i++) { + SNPRINTF(buf, sizeof(buf), " tmp += inBuffer%d[inputIdx];\n", i); + shader_ += buf; + } + shader_ += " inputIdx += writeIt;\n"; // writeIt is 0, so we don't need + // to add a modulo + } + if (typeSizes[typeIdx_] > 4) { + shader_ += + " if (writeIt*(unsigned int)tmp.x) outBuffer[gid] = tmp;\n" + "}\n"; + } else { + shader_ += + " if (writeIt*(unsigned int)tmp) outBuffer[gid] = tmp;\n" + "}\n"; + } + // printf("Shader -> %s\n", shader_.c_str()); +} + +void OCLPerfSVMSampleRate::setData(void *buffer, unsigned int val) { +#if defined(CL_VERSION_2_0) + error_ = _wrapper->clEnqueueSVMMemFill( + cmd_queue_, buffer, &val, sizeof(unsigned int), bufSize_, 0, NULL, NULL); + if ((error_ == CL_MEM_OBJECT_ALLOCATION_FAILURE) || + (error_ == CL_OUT_OF_RESOURCES) || (error_ == CL_OUT_OF_HOST_MEMORY)) { + error_ = CL_SUCCESS; + skip_ = true; + testDescString = "Not enough memory, skipped"; + return; + } + _wrapper->clFinish(cmd_queue_); +#endif +} + +void OCLPerfSVMSampleRate::checkData(void *buffer) { +#if defined(CL_VERSION_2_0) + error_ = _wrapper->clEnqueueSVMMap(cmd_queue_, true, CL_MAP_READ, buffer, + outBufSize_, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueSVMMap failed"); + float *data = (float *)buffer; + for (unsigned int i = 0; i < outBufSize_ / sizeof(float); i++) { + if (data[i] != (float)numBufs_) { + printf("Data validation failed at %d! Got %f, expected %f\n", i, data[i], + (float)numBufs_); + break; + } + } + error_ = _wrapper->clEnqueueSVMUnmap(cmd_queue_, buffer, 0, NULL, NULL); + _wrapper->clFinish(cmd_queue_); +#endif +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfSVMSampleRate::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_device_id device; + error_ = CL_SUCCESS; + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = 0; + kernel_ = 0; + cmd_queue_ = 0; + inBuffer_ = NULL; + outBuffer_ = NULL; + coarseGrainBuffer_ = false; + fineGrainBuffer_ = false; + fineGrainSystem_ = false; + + // We compute a square domain + width_ = sizes[test % NUM_SIZES]; + typeIdx_ = (test / NUM_SIZES) % NUM_TYPES; + bufSize_ = width_ * width_ * typeSizes[typeIdx_]; + numBufs_ = (1 << ((test / (NUM_SIZES * NUM_TYPES)) % NUM_BUFS)); + svmMode_ = test / (NUM_SIZES * NUM_TYPES * NUM_BUFS); + + device = devices_[deviceId]; + +#if defined(CL_VERSION_2_0) + cl_device_svm_capabilities caps; + error_ = clGetDeviceInfo(device, CL_DEVICE_SVM_CAPABILITIES, + sizeof(cl_device_svm_capabilities), &caps, NULL); + if (svmMode_ == 0) { + if (caps & CL_DEVICE_SVM_COARSE_GRAIN_BUFFER) { + coarseGrainBuffer_ = true; + testdesc = "crs"; + } else { + skip_ = true; // Should never happen as OCL 2.0 devices are required to + // support coarse grain SVM + testDescString = "Coarse grain SVM NOT supported. Test Skipped."; + return; + } + } else if (svmMode_ == 1) { + if (caps & CL_DEVICE_SVM_FINE_GRAIN_BUFFER) { + fineGrainBuffer_ = true; + testdesc = "fgb"; + } else { + skip_ = true; // No support for fine grain buffer SVM + testDescString = "Fine grain buffer SVM NOT supported. Test Skipped."; + return; + } + } else if (svmMode_ == 2) { + if (caps & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM) { + fineGrainSystem_ = true; + testdesc = "fgs"; + } else { + skip_ = true; // No support for fine grain system SVM + testDescString = "Fine grain system SVM NOT supported. Test Skipped."; + return; + } + } + + char charbuf[1024]; + + cmd_queue_ = cmdQueues_[_deviceId]; + + outBufSize_ = + sizes[NUM_SIZES - 1] * sizes[NUM_SIZES - 1] * typeSizes[NUM_TYPES - 1]; + if ((svmMode_ == 0) || (svmMode_ == 1)) { + inBuffer_ = (void **)malloc(sizeof(void *) * numBufs_); + memset(inBuffer_, 0, sizeof(void *) * numBufs_); + cl_mem_flags flags; + flags = CL_MEM_READ_ONLY; + if (svmMode_ == 1) flags |= CL_MEM_SVM_FINE_GRAIN_BUFFER; + for (unsigned int i = 0; i < numBufs_; i++) { + inBuffer_[i] = _wrapper->clSVMAlloc(context_, flags, bufSize_, 0); + CHECK_RESULT(inBuffer_[i] == NULL, "clCreateBuffer(inBuffer) failed"); + } + + flags = CL_MEM_WRITE_ONLY; + if (svmMode_ == 1) flags |= CL_MEM_SVM_FINE_GRAIN_BUFFER; + outBuffer_ = _wrapper->clSVMAlloc(context_, flags, outBufSize_, 0); + CHECK_RESULT(outBuffer_ == NULL, "clCreateBuffer(outBuffer) failed"); + } else { + inBuffer_ = (void **)malloc(sizeof(void *) * numBufs_); + memset(inBuffer_, 0, sizeof(void *) * numBufs_); + for (unsigned int i = 0; i < numBufs_; i++) { + inBuffer_[i] = malloc(bufSize_); + CHECK_RESULT(inBuffer_[i] == NULL, "malloc(inBuffer) failed"); + } + outBuffer_ = malloc(outBufSize_); + CHECK_RESULT(outBuffer_ == NULL, "malloc(outBuffer) failed"); + } + + setKernel(); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + const char *buildOps = NULL; + // Have to force OCL 2.0 to use SVM + SNPRINTF(charbuf, sizeof(charbuf), "-cl-std=CL2.0 -D DATATYPE=%s", + types[typeIdx_]); + buildOps = charbuf; + error_ = _wrapper->clBuildProgram(program_, 1, &device, buildOps, NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "sampleRate", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + error_ = _wrapper->clSetKernelArgSVMPointer(kernel_, 0, outBuffer_); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(outBuffer) failed"); + unsigned int sizeDW = width_ * width_; + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(unsigned int), + (void *)&sizeDW); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(sizeDW) failed"); + unsigned int writeIt = 0; + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(unsigned int), + (void *)&writeIt); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(writeIt) failed"); + for (unsigned int i = 0; i < numBufs_; i++) { + error_ = _wrapper->clSetKernelArgSVMPointer(kernel_, i + 3, inBuffer_[i]); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(inBuffer) failed"); + setData(inBuffer_[i], 0x3f800000); + if (skip_) return; + } + setData(outBuffer_, 0xdeadbeef); +#else + skip_ = true; + testDescString = "SVM NOT supported for < 2.0 builds. Test Skipped."; + return; +#endif +} + +void OCLPerfSVMSampleRate::run(void) { + int global = outBufSize_ / typeSizes[typeIdx_]; + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + unsigned int maxIter = MAX_ITERATIONS * (MAX_BUFS / numBufs_); + + if (skip_) return; + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < maxIter; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + } + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Test doesn't write anything, so nothing to check + // checkData(outBuffer_); + // Compute GB/s + double perf = + ((double)outBufSize_ * NUM_READS * (double)maxIter * (double)(1e-09)) / + sec; + char buf[256]; + SNPRINTF(buf, sizeof(buf), "Domain %dx%d, %2d %s bufs, %6s, %4dx%4d (GB/s)", + sizes[NUM_SIZES - 1], sizes[NUM_SIZES - 1], numBufs_, + testdesc.c_str(), types[typeIdx_], width_, width_); + + _perfInfo = (float)perf; + testDescString = buf; +} + +unsigned int OCLPerfSVMSampleRate::close(void) { +#if defined(CL_VERSION_2_0) + if (cmd_queue_) _wrapper->clFinish(cmd_queue_); + + if ((svmMode_ == 0) || (svmMode_ == 1)) { + if (inBuffer_) { + for (unsigned int i = 0; i < numBufs_; i++) { + if (inBuffer_[i]) { + _wrapper->clSVMFree(context_, inBuffer_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clSVMFree(inBuffer_) failed"); + } + } + free(inBuffer_); + } + if (outBuffer_) { + _wrapper->clSVMFree(context_, outBuffer_); + } + } else { + if (inBuffer_) { + for (unsigned int i = 0; i < numBufs_; i++) { + if (inBuffer_[i]) { + free(inBuffer_[i]); + } + } + free(inBuffer_); + } + if (outBuffer_) { + free(outBuffer_); + } + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } +#endif + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSVMSampleRate.h b/opencl/tests/ocltst/module/perf/OCLPerfSVMSampleRate.h new file mode 100644 index 0000000000..999fb11bf7 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSVMSampleRate.h @@ -0,0 +1,63 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_SVMSAMPLERATE_H_ +#define _OCL_SVMSAMPLERATE_H_ + +#include "OCLTestImp.h" + +class OCLPerfSVMSampleRate : public OCLTestImp { + public: + OCLPerfSVMSampleRate(); + virtual ~OCLPerfSVMSampleRate(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void setData(void* buffer, unsigned int data); + void checkData(void* buffer); + void setKernel(void); + + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + void** inBuffer_; + void* outBuffer_; + + unsigned int width_; + unsigned int bufSize_; + unsigned int outBufSize_; + static const unsigned int MAX_ITERATIONS = 25; + unsigned int numBufs_; + unsigned int typeIdx_; + unsigned int svmMode_; + + bool skip_; + bool coarseGrainBuffer_; + bool fineGrainBuffer_; + bool fineGrainSystem_; + std::string testdesc; +}; + +#endif // _OCL_SVMSAMPLERATE_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSampleRate.cpp b/opencl/tests/ocltst/module/perf/OCLPerfSampleRate.cpp new file mode 100644 index 0000000000..3cba21c078 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSampleRate.cpp @@ -0,0 +1,336 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfSampleRate.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_TYPES 3 +static const char *types[NUM_TYPES] = {"float", "float2", "float4"}; +static const unsigned int typeSizes[NUM_TYPES] = {4, 8, 16}; + +#define NUM_SIZES 12 +static const unsigned int sizes[NUM_SIZES] = {1, 2, 4, 8, 16, 32, + 64, 128, 256, 512, 1024, 2048}; + +#define NUM_BUFS 6 +#define MAX_BUFS (1 << (NUM_BUFS - 1)) + +OCLPerfSampleRate::OCLPerfSampleRate() { + _numSubTests = NUM_TYPES * NUM_SIZES * NUM_BUFS; + skip_ = false; +} + +OCLPerfSampleRate::~OCLPerfSampleRate() {} + +void OCLPerfSampleRate::setKernel(void) { + shader_.clear(); + shader_ += + "kernel void sampleRate(global DATATYPE* outBuffer, unsigned int " + "inBufSize, unsigned int writeIt,\n"; + char buf[256]; + for (unsigned int i = 0; i < numBufs_; i++) { + SNPRINTF(buf, sizeof(buf), "global DATATYPE* inBuffer%d", i); + shader_ += buf; + if (i < (numBufs_ - 1)) { + shader_ += ","; + } + shader_ += "\n"; + } + shader_ += ")\n"; + shader_ += + "{\n" + " uint gid = get_global_id(0);\n" + " uint inputIdx = gid % inBufSize;\n" + " DATATYPE tmp = (DATATYPE)0.0f;\n"; + + for (unsigned int i = 0; i < numBufs_; i++) { + SNPRINTF(buf, sizeof(buf), " tmp += inBuffer%d[inputIdx];\n", i); + shader_ += buf; + } + if (typeSizes[typeIdx_] > 4) { + shader_ += + " if (writeIt*(unsigned int)tmp.x) outBuffer[gid] = tmp;\n" + "}\n"; + } else { + shader_ += + " if (writeIt*(unsigned int)tmp) outBuffer[gid] = tmp;\n" + "}\n"; + } + // printf("Shader -> %s\n", shader_.c_str()); +} + +void OCLPerfSampleRate::setData(cl_mem buffer, unsigned int val) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, buffer, true, CL_MAP_WRITE, 0, bufSize_, 0, NULL, NULL, + &error_); + if (data == NULL) { + if ((error_ == CL_MEM_OBJECT_ALLOCATION_FAILURE) || + (error_ == CL_OUT_OF_RESOURCES) || (error_ == CL_OUT_OF_HOST_MEMORY)) { + printf("WARNING: Not enough memory, skipped\n"); + error_ = CL_SUCCESS; + skip_ = true; + } else { + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueMapBuffer failed"); + } + return; + } + for (unsigned int i = 0; i < bufSize_ / sizeof(unsigned int); i++) + data[i] = val; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +void OCLPerfSampleRate::checkData(cl_mem buffer) { + float *data = (float *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, buffer, true, CL_MAP_READ, 0, outBufSize_, 0, NULL, NULL, + &error_); + for (unsigned int i = 0; i < outBufSize_ / sizeof(float); i++) { + if (data[i] != (float)numBufs_) { + printf("Data validation failed at %d! Got %f, expected %f\n", i, data[i], + (float)numBufs_); + break; + } + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfSampleRate::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + inBuffer_ = 0; + outBuffer_ = 0; + + // We compute a square domain + width_ = sizes[test % NUM_SIZES]; + typeIdx_ = (test / NUM_SIZES) % NUM_TYPES; + bufSize_ = width_ * width_ * typeSizes[typeIdx_]; + numBufs_ = (1 << (test / (NUM_SIZES * NUM_TYPES))); + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + platform = platforms[_platformIndex]; + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + delete platforms; + } + /* + * If we could find a platform, use it. + */ + CHECK_RESULT(platform == 0, + "Couldn't find platform with GPU devices, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + inBuffer_ = (cl_mem *)malloc(sizeof(cl_mem) * numBufs_); + memset(inBuffer_, 0, sizeof(cl_mem) * numBufs_); + for (unsigned int i = 0; i < numBufs_; i++) { + inBuffer_[i] = _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY, + bufSize_, NULL, &error_); + CHECK_RESULT(inBuffer_[i] == 0, "clCreateBuffer(inBuffer) failed"); + } + + outBufSize_ = + sizes[NUM_SIZES - 1] * sizes[NUM_SIZES - 1] * typeSizes[NUM_TYPES - 1]; + outBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, + outBufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + setKernel(); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + const char *buildOps = NULL; + SNPRINTF(charbuf, sizeof(charbuf), "-D DATATYPE=%s", types[typeIdx_]); + buildOps = charbuf; + error_ = _wrapper->clBuildProgram(program_, 1, &device, buildOps, NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "sampleRate", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&outBuffer_); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(outBuffer) failed"); + unsigned int sizeDW = width_ * width_; + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(unsigned int), + (void *)&sizeDW); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(sizeDW) failed"); + unsigned int writeIt = 0; + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(unsigned int), + (void *)&writeIt); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(writeIt) failed"); + for (unsigned int i = 0; i < numBufs_; i++) { + error_ = _wrapper->clSetKernelArg(kernel_, i + 3, sizeof(cl_mem), + (void *)&inBuffer_[i]); + CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(inBuffer) failed"); + setData(inBuffer_[i], 0x3f800000); + if (skip_) return; + } + setData(outBuffer_, 0xdeadbeef); +} + +void OCLPerfSampleRate::run(void) { + int global = outBufSize_ / typeSizes[typeIdx_]; + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + unsigned int maxIter = MAX_ITERATIONS * (MAX_BUFS / numBufs_); + + if (skip_) return; + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < maxIter; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + } + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // checkData(outBuffer_); + // Compute GB/s + double perf = + ((double)outBufSize_ * numBufs_ * (double)maxIter * (double)(1e-09)) / + sec; + char buf[256]; + SNPRINTF(buf, sizeof(buf), "Domain %dx%d, %2d bufs, %6s, %4dx%4d (GB/s)", + sizes[NUM_SIZES - 1], sizes[NUM_SIZES - 1], numBufs_, + types[typeIdx_], width_, width_); + + _perfInfo = (float)perf; + testDescString = buf; +} + +unsigned int OCLPerfSampleRate::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (inBuffer_) { + for (unsigned int i = 0; i < numBufs_; i++) { + if (inBuffer_[i]) { + error_ = _wrapper->clReleaseMemObject(inBuffer_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + } + free(inBuffer_); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSampleRate.h b/opencl/tests/ocltst/module/perf/OCLPerfSampleRate.h new file mode 100644 index 0000000000..ef8e9f8985 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSampleRate.h @@ -0,0 +1,60 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_SAMPLERATE_H_ +#define _OCL_SAMPLERATE_H_ + +#include "OCLTestImp.h" + +class OCLPerfSampleRate : public OCLTestImp { + public: + OCLPerfSampleRate(); + virtual ~OCLPerfSampleRate(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void setData(cl_mem buffer, unsigned int data); + void checkData(cl_mem buffer); + void setKernel(void); + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem* inBuffer_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int width_; + unsigned int bufSize_; + unsigned int outBufSize_; + static const unsigned int MAX_ITERATIONS = 25; + unsigned int numBufs_; + unsigned int typeIdx_; + + bool skip_; +}; + +#endif // _OCL_SAMPLERATE_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfScalarReplArrayElem.cpp b/opencl/tests/ocltst/module/perf/OCLPerfScalarReplArrayElem.cpp new file mode 100644 index 0000000000..6949868190 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfScalarReplArrayElem.cpp @@ -0,0 +1,325 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfScalarReplArrayElem.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 1 +static const unsigned int Sizes[NUM_SIZES] = {16777216}; // 16 + +static void genKernelSource(const char *vtypeName, unsigned arrayLen, + unsigned loopCount, char *source) { + sprintf(source, + "%s foo(uint lid, __local %s *localLocal)\n" + "{\n" + " %s val0 = 0.0f;\n" + " %s val1 = 0.0f;\n" + " for (int i = 0; i < %d; ++i) {\n" + " val0 += localLocal[lid];\n" + " lid += 16;\n" + " }\n" + " %s val = val0+val1;\n" + " return val;\n" + "}\n" + "__kernel __attribute__((reqd_work_group_size(64,1,1)))" + " void _ldsReadSpeed(__global %s *outBuf)\n" + "{\n" + " uint gid = (int) get_global_id(0);\n" + " uint lid = (int) get_local_id(0);\n" + " __local %s localLocal[%d];\n" + " outBuf[gid] = foo(lid, localLocal);\n" + "}\n", + vtypeName, vtypeName, vtypeName, vtypeName, loopCount, vtypeName, + vtypeName, vtypeName, arrayLen); +} + +typedef struct { + const char *name; + unsigned nBytes; +} ExplicitType; + +static const ExplicitType tyChar = {"char", 1}; +static const ExplicitType tyShort = {"short", 2}; +static const ExplicitType tyInt = {"int", 4}; +static const ExplicitType tyLong = {"long", 8}; +static const ExplicitType tyFloat = {"float", 4}; +static const ExplicitType tyDouble = {"double", 8}; + +typedef struct { + ExplicitType elemType; + unsigned nElems; + const char *name; + unsigned getSize() const { return elemType.nBytes * nElems; } +} VectorType; + +static const VectorType vecTypes[] = { + {tyChar, 8, "char8"}, {tyShort, 4, "short4"}, {tyInt, 2, "int2"}, + {tyFloat, 2, "float2"}, {tyLong, 1, "long"}, + + {tyChar, 16, "char16"}, {tyShort, 8, "short8"}, {tyInt, 4, "int4"}, + {tyFloat, 4, "float4"}, {tyLong, 2, "long2"}, + + {tyShort, 16, "short16"}, {tyInt, 8, "int8"}, {tyFloat, 8, "float8"}, + {tyLong, 4, "long4"}, + + {tyInt, 16, "int16"}, {tyFloat, 16, "float16"}, {tyLong, 8, "long8"}, + + {tyLong, 16, "long16"}}; +static const unsigned ldsBytes = 4 * 4096; +static const unsigned nVecTypes = sizeof(vecTypes) / sizeof(VectorType); + +void OCLPerfScalarReplArrayElem::genShader(unsigned int idx) { + VectorType vecType = vecTypes[idx]; + ExplicitType elemType = vecType.elemType; + unsigned vecSize = vecType.nElems; + unsigned arrayLen = ldsBytes / vecType.getSize(); + unsigned loopCount = arrayLen / 16; + char source[7192]; + genKernelSource(vecType.name, arrayLen, loopCount, source); + shader_ = std::string(source); + numReads_ = loopCount; + itemWidth_ = vecType.getSize(); +} + +OCLPerfScalarReplArrayElem::OCLPerfScalarReplArrayElem() { + _numSubTests = NUM_SIZES * nVecTypes; +} + +OCLPerfScalarReplArrayElem::~OCLPerfScalarReplArrayElem() {} + +void OCLPerfScalarReplArrayElem::setData(cl_mem buffer, float val) { + float *data = (float *)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, + CL_MAP_WRITE, 0, bufSize_, + 0, NULL, NULL, &error_); + for (unsigned int i = 0; i < (bufSize_ >> 2); i++) data[i] = val; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +void OCLPerfScalarReplArrayElem::checkData(cl_mem buffer) { + float *data = (float *)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, + CL_MAP_READ, 0, bufSize_, + 0, NULL, NULL, &error_); + for (unsigned int i = 0; i < (bufSize_ >> 2); i++) { + if (data[i] != (float)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, numReads_, + numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfScalarReplArrayElem::open(unsigned int test, char *units, + double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + outBuffer_ = 0; + _openTest = test; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + // if (num_devices > 0) + //{ + // platform = platforms[_platformIndex]; + // break; + //} +#if 0 + } +#endif + delete platforms; + } + + width_ = Sizes[test % NUM_SIZES]; + shaderIdx_ = test / NUM_SIZES; + bufSize_ = width_; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + outBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + genShader(shaderIdx_); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &device, "", NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "_ldsReadSpeed", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&outBuffer_); + + // setData(outBuffer_, 1.2345678f); +} + +void OCLPerfScalarReplArrayElem::run(void) { + int global = bufSize_ / itemWidth_; + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < NUM_ITER; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Constant bandwidth in GB/s + double perf = + ((double)global * numReads_ * itemWidth_ * NUM_ITER * (double)(1e-09)) / + sec; + + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " %10s %8d threads, %4d reads (GB/s)", + vecTypes[shaderIdx_].name, global, numReads_); + testDescString = buf; + // checkData(outBuffer_); +} + +unsigned int OCLPerfScalarReplArrayElem::close(void) { + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfScalarReplArrayElem.h b/opencl/tests/ocltst/module/perf/OCLPerfScalarReplArrayElem.h new file mode 100644 index 0000000000..2f29bc4363 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfScalarReplArrayElem.h @@ -0,0 +1,60 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ScalarReplArrayElem_H_ +#define _OCL_ScalarReplArrayElem_H_ + +#include "OCLTestImp.h" + +class OCLPerfScalarReplArrayElem : public OCLTestImp { + public: + OCLPerfScalarReplArrayElem(); + virtual ~OCLPerfScalarReplArrayElem(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void genShader(unsigned int idx); + void setData(cl_mem buffer, float data); + void checkData(cl_mem buffer); + + static const unsigned int NUM_ITER = 100; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int width_; + unsigned int bufSize_; + unsigned int numReads_; + unsigned int shaderIdx_; + unsigned int itemWidth_; + unsigned int vecTypeIdx_; + unsigned int vecSizeIdx_; +}; + +#endif // _OCL_ScalarReplArrayElem_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSdiP2PCopy.cpp b/opencl/tests/ocltst/module/perf/OCLPerfSdiP2PCopy.cpp new file mode 100644 index 0000000000..94f78aaefa --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSdiP2PCopy.cpp @@ -0,0 +1,261 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfSdiP2PCopy.h" + +#include + +#include "Timer.h" + +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 5 +// 64KB, 256KB, 1 MB, 4MB, 16 MB +static const unsigned int Sizes[NUM_SIZES] = {65536, 262144, 1048576, 4194304, + 16777216}; + +OCLPerfSdiP2PCopy::OCLPerfSdiP2PCopy() { + // If there are two different gpus in the system, + // we have to test each of them + _numSubTests = 2 * NUM_SIZES; +} + +OCLPerfSdiP2PCopy::~OCLPerfSdiP2PCopy() {} + +void OCLPerfSdiP2PCopy::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + cl_uint numPlatforms = 0; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + _crcword = 0; + conversion = 1.0f; + _openTest = test % NUM_SIZES; + bufSize_ = Sizes[_openTest]; + error_ = 0; + srcBuff_ = 0; + inputArr_ = 0; + outputArr_ = 0; + extPhysicalBuff_ = 0; + silentFailure = false; + busAddressableBuff_ = 0; + devices_[0] = devices_[1] = 0; + contexts_[0] = contexts_[1] = 0; + cmd_queues_[0] = cmd_queues_[1] = 0; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(numPlatforms == 0, "clGetPlatformIDs failed"); + error_ = _wrapper->clGetPlatformIDs(1, &platform, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + error_ = _wrapper->clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, + &num_devices); + if (num_devices != 2) { + printf( + "\nSilent Failure: Two GPUs are required to run OCLPerfSdiP2PCopy " + "test\n"); + silentFailure = true; + return; + } + error_ = _wrapper->clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, num_devices, + devices_, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + if (test >= NUM_SIZES) { + cl_device_id temp = devices_[0]; + devices_[0] = devices_[1]; + devices_[1] = temp; + } + size_t param_size = 0; + char* strExtensions = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[0], CL_DEVICE_EXTENSIONS, 0, 0, + ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strExtensions = (char*)malloc(param_size); + error_ = _wrapper->clGetDeviceInfo(devices_[0], CL_DEVICE_EXTENSIONS, + param_size, strExtensions, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strstr(strExtensions, "cl_amd_bus_addressable_memory") == 0) { + printf( + "\nSilent Failure: cl_amd_bus_addressable_memory extension is not " + "enabled on GPU 0\n"); + silentFailure = true; + free(strExtensions); + return; + } + free(strExtensions); + error_ = _wrapper->clGetDeviceInfo(devices_[1], CL_DEVICE_EXTENSIONS, 0, 0, + ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strExtensions = (char*)malloc(param_size); + error_ = _wrapper->clGetDeviceInfo(devices_[1], CL_DEVICE_EXTENSIONS, + param_size, strExtensions, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strstr(strExtensions, "cl_amd_bus_addressable_memory") == 0) { + printf( + "\nSilent Failure: cl_amd_bus_addressable_memory extension is not " + "enabled on GPU 1\n"); + silentFailure = true; + free(strExtensions); + return; + } + free(strExtensions); + deviceNames_ = " ["; + param_size = 0; + char* strDeviceName = 0; + error_ = + _wrapper->clGetDeviceInfo(devices_[1], CL_DEVICE_NAME, 0, 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strDeviceName = (char*)malloc(param_size); + error_ = _wrapper->clGetDeviceInfo(devices_[1], CL_DEVICE_NAME, param_size, + strDeviceName, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + deviceNames_ = deviceNames_ + strDeviceName; + free(strDeviceName); + error_ = + _wrapper->clGetDeviceInfo(devices_[0], CL_DEVICE_NAME, 0, 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strDeviceName = (char*)malloc(param_size); + error_ = _wrapper->clGetDeviceInfo(devices_[0], CL_DEVICE_NAME, param_size, + strDeviceName, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + deviceNames_ = deviceNames_ + "->"; + deviceNames_ = deviceNames_ + strDeviceName; + free(strDeviceName); + deviceNames_ = deviceNames_ + "]"; + cl_context_properties props[3] = {CL_CONTEXT_PLATFORM, + (cl_context_properties)platform, 0}; + + contexts_[0] = + _wrapper->clCreateContext(props, 1, &devices_[0], 0, 0, &error_); + CHECK_RESULT(contexts_[0] == 0, "clCreateContext failed"); + contexts_[1] = + _wrapper->clCreateContext(props, 1, &devices_[1], 0, 0, &error_); + CHECK_RESULT(contexts_[1] == 0, "clCreateContext failed"); + cmd_queues_[0] = + _wrapper->clCreateCommandQueue(contexts_[0], devices_[0], 0, NULL); + CHECK_RESULT(cmd_queues_[0] == 0, "clCreateCommandQueue failed"); + cmd_queues_[1] = + _wrapper->clCreateCommandQueue(contexts_[1], devices_[1], 0, NULL); + CHECK_RESULT(cmd_queues_[1] == 0, "clCreateCommandQueue failed"); + busAddressableBuff_ = _wrapper->clCreateBuffer( + contexts_[0], CL_MEM_BUS_ADDRESSABLE_AMD, bufSize_, 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + error_ = _wrapper->clEnqueueMakeBuffersResidentAMD( + cmd_queues_[0], 1, &busAddressableBuff_, true, &busAddr_, 0, 0, 0); + CHECK_RESULT((error_ != CL_SUCCESS), + "clEnqueueMakeBuffersResidentAMD failed"); + extPhysicalBuff_ = _wrapper->clCreateBuffer( + contexts_[1], CL_MEM_EXTERNAL_PHYSICAL_AMD, bufSize_, &busAddr_, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + srcBuff_ = _wrapper->clCreateBuffer(contexts_[1], CL_MEM_READ_WRITE, bufSize_, + 0, &error_); + CHECK_RESULT(error_ != CL_SUCCESS, "clCreateBuffer failed"); + inputArr_ = (cl_uint*)malloc(bufSize_); + outputArr_ = (cl_uint*)malloc(bufSize_); + for (unsigned int i = 0; i < (bufSize_ / sizeof(cl_uint)); ++i) { + inputArr_[i] = i + 1; + outputArr_[i] = 0; + } + error_ = _wrapper->clEnqueueWriteBuffer(cmd_queues_[1], srcBuff_, CL_TRUE, 0, + bufSize_, inputArr_, 0, 0, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWriteBuffer failed"); +} + +void OCLPerfSdiP2PCopy::run(void) { + if (silentFailure) { + return; + } + CPerfCounter timer; + // Warm up + error_ = + _wrapper->clEnqueueCopyBuffer(cmd_queues_[1], srcBuff_, extPhysicalBuff_, + 0, 0, bufSize_, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueCopyBuffer failed"); + error_ = _wrapper->clFinish(cmd_queues_[1]); + CHECK_RESULT(error_, "clFinish failed"); + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < NUM_ITER; i++) { + error_ = _wrapper->clEnqueueCopyBuffer(cmd_queues_[1], srcBuff_, + extPhysicalBuff_, 0, 0, bufSize_, 0, + NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueCopyBuffer failed"); + } + error_ = _wrapper->clFinish(cmd_queues_[1]); + CHECK_RESULT(error_, "clFinish failed"); + timer.Stop(); + double sec = timer.GetElapsedTime(); + error_ = _wrapper->clEnqueueReadBuffer(cmd_queues_[0], busAddressableBuff_, + CL_TRUE, 0, bufSize_, outputArr_, 0, 0, + NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWriteBuffer failed"); + CHECK_RESULT((memcmp(inputArr_, outputArr_, bufSize_) != 0), "copy failed"); + // Buffer copy bandwidth in GB/s + double perf = ((double)bufSize_ * NUM_ITER * (double)(1e-09)) / sec; + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%8d bytes) i:%4d (GB/s) %s", bufSize_, NUM_ITER, + deviceNames_.c_str()); + testDescString = buf; +} + +unsigned int OCLPerfSdiP2PCopy::close(void) { + if (srcBuff_) { + error_ = _wrapper->clReleaseMemObject(srcBuff_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseMemObject failed"); + } + if (extPhysicalBuff_) { + error_ = _wrapper->clReleaseMemObject(extPhysicalBuff_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseMemObject failed"); + } + if (busAddressableBuff_) { + error_ = _wrapper->clReleaseMemObject(busAddressableBuff_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseMemObject failed"); + } + if (cmd_queues_[0]) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queues_[0]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (cmd_queues_[1]) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queues_[1]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (contexts_[0]) { + error_ = _wrapper->clReleaseContext(contexts_[0]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + if (contexts_[1]) { + error_ = _wrapper->clReleaseContext(contexts_[1]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + if (inputArr_) { + free(inputArr_); + } + if (outputArr_) { + free(outputArr_); + } + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfSdiP2PCopy.h b/opencl/tests/ocltst/module/perf/OCLPerfSdiP2PCopy.h new file mode 100644 index 0000000000..eaf9e6099d --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfSdiP2PCopy.h @@ -0,0 +1,52 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_SdiP2PCopy_H_ +#define _OCL_SdiP2PCopy_H_ + +#include "OCLTestImp.h" + +class OCLPerfSdiP2PCopy : public OCLTestImp { + public: + OCLPerfSdiP2PCopy(); + virtual ~OCLPerfSdiP2PCopy(); + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + static const unsigned int NUM_ITER = 1024; + bool silentFailure; + cl_context contexts_[2]; + cl_device_id devices_[2]; + cl_command_queue cmd_queues_[2]; + cl_mem srcBuff_; + cl_mem extPhysicalBuff_; + cl_mem busAddressableBuff_; + cl_int error_; + cl_bus_address_amd busAddr_; + cl_uint* inputArr_; + cl_uint* outputArr_; + unsigned int bufSize_; + std::string deviceNames_; +}; + +#endif // _OCL_SdiP2PCopy_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfTextureMemLatency.cpp b/opencl/tests/ocltst/module/perf/OCLPerfTextureMemLatency.cpp new file mode 100644 index 0000000000..4f97c01c12 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfTextureMemLatency.cpp @@ -0,0 +1,409 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfTextureMemLatency.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +static const unsigned int NUM_SIZES = 13; +// 2k up to 64MB +static const cl_uint2 Dims[NUM_SIZES] = { + {{32, 16}}, {{32, 32}}, {{64, 32}}, {{64, 64}}, {{128, 64}}, + {{128, 128}}, {{256, 128}}, {{256, 256}}, {{512, 256}}, {{512, 512}}, + {{1024, 512}}, {{1024, 1024}}, {{2048, 1024}}}; +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif +void OCLPerfTextureMemLatency::genShader() { + shader_.clear(); + + // Adopted from SiSoft Sandra 2013's memory latency test + shader_ += + "constant sampler_t insample = CLK_NORMALIZED_COORDS_FALSE | " + "CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST;\n" + "__kernel\n" + "__attribute__((work_group_size_hint(1, 1, 1)))\n" + "void MemWalker(\n" + " read_only image2d_t input,\n" + " __global uint * restrict output,\n" + " const uint uCount, const uint uSize,\n" + " const uint4 uOffset, const int bMem, const uint repeats)\n" + "{\n" + " uint4 o = uOffset;\n" + " uint lid = get_local_id(0);\n" + " uint4 x = lid*o;\n" + "\n" + " for (uint loop = 0; (loop < repeats); loop++) {\n" + " uint i = uCount;\n" + " int2 nx = (int2)(0,0);\n" + " nx = (int2)((x.y << 8) | x.x, (x.w << 8) | x.z);\n" + " while (i--) {\n" + " x = read_imageui(input, insample, nx);\n" + " x.x += o.x;\n" + " x.z += o.z;\n" + " nx = (int2)((x.y << 8) | x.x, (x.w << 8) | x.z);\n" + " }\n" + " }\n" + "\n" + " output[0] = x.x + x.y;\n" + "}\n"; + + // printf("shader:\n%s\n", shader_.c_str()); + shader_ += "\n\n"; + shader_ += + "__kernel\n" + "__attribute__((work_group_size_hint(1, 1, 1)))\n" + "void Overhead(\n" + " read_only image2d_t input,\n" + " __global uint * restrict output,\n" + " const uint uCount, const uint uSize,\n" + " const uint4 uOffset, const int bMem, const uint repeats)\n" + "{\n" + " uint4 o = uOffset;\n" + " uint lid = get_local_id(0);\n" + " uint4 x = lid*o;\n" + " x += o;\n" + " int2 nx;\n" + " for (uint loop = 0; loop < repeats; loop++) {\n" + " uint i = uCount;\n" + " nx = (int2)(0,0);\n" + " nx = (int2)((x.y << 8) | x.x, (x.w << 8) | x.z);\n" + " while (i--) {\n" + " x.x = nx.x + o.x;\n" + " x.z = nx.y + o.y;\n" + " nx = (int2)((x.y << 8) | x.x, (x.w << 8) | x.z);\n" + " }\n" + " }\n" + " output[0] = nx.x | nx.y;\n" + "}\n"; +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +OCLPerfTextureMemLatency::OCLPerfTextureMemLatency() { + _numSubTests = NUM_SIZES; + maxSize_ = Dims[NUM_SIZES - 1].s[0] * Dims[NUM_SIZES - 1].s[1]; +} + +OCLPerfTextureMemLatency::~OCLPerfTextureMemLatency() {} + +void OCLPerfTextureMemLatency::setData(cl_mem buffer, unsigned int val) { + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {width_, height_, 1}; + + void *ptr = _wrapper->clEnqueueMapImage( + cmd_queue_, buffer, true, CL_MAP_WRITE, origin, region, &image_row_pitch, + &image_slice_pitch, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapImage failed."); + unsigned int *data = (unsigned int *)ptr; + unsigned int nextOffset = 0; + for (unsigned int i = 0; i < bufSizeDW_; i++) { + unsigned int offset = ((1024 + 17) * (i + 1)) % bufSizeDW_; + unsigned int x, y; + x = offset % width_; + y = offset / width_; + unsigned int newx, newy; + newx = nextOffset % width_; + newy = nextOffset / width_; + data[newy * image_row_pitch / sizeof(unsigned int) + newx] = + (y << 16) | (x & 0xffff); + nextOffset = offset; + } + error_ = + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, ptr, 0, NULL, NULL); + clFinish(cmd_queue_); +} + +void OCLPerfTextureMemLatency::checkData(cl_mem buffer) { + void *ptr = + _wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, CL_MAP_READ, 0, + sizeof(cl_uint), 0, NULL, NULL, &error_); + + unsigned int *data = (unsigned int *)ptr; + if (data[0] != 0) { + printf("OutData= 0x%08x\n", data[0]); + CHECK_RESULT_NO_RETURN(data[0] != 0, "Data validation failed!\n"); + } + error_ = + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, ptr, 0, NULL, NULL); + clFinish(cmd_queue_); +} + +void OCLPerfTextureMemLatency::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + inBuffer_ = 0; + outBuffer_ = 0; + _errorFlag = false; // Reset error code so a single error doesn't prevent + // other subtests from running + _errorMsg = ""; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + } + } + + delete platforms; + } + + width_ = Dims[test % NUM_SIZES].s[0]; + height_ = Dims[test % NUM_SIZES].s[1]; + + bufSizeDW_ = width_ * height_; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + device = devices[0]; + + free(devices); + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_image_format format = {CL_RGBA, CL_UNSIGNED_INT8}; + inBuffer_ = _wrapper->clCreateImage2D(context_, CL_MEM_READ_ONLY, &format, + width_, height_, 0, NULL, &error_); + CHECK_RESULT(inBuffer_ == 0, "clCreateImage(inBuffer) failed"); + + outBuffer_ = + _wrapper->clCreateBuffer(context_, 0, sizeof(cl_uint), NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + genShader(); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + std::string args; + args.clear(); + + error_ = + _wrapper->clBuildProgram(program_, 1, &device, args.c_str(), NULL, NULL); + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "MemWalker", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel(MemWalker) failed"); + + kernel2_ = _wrapper->clCreateKernel(program_, "Overhead", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel(Overhead) failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&inBuffer_); + error_ = + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), (void *)&outBuffer_); + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), + (void *)&bufSizeDW_); + error_ = _wrapper->clSetKernelArg(kernel_, 3, sizeof(cl_uint), + (void *)&bufSizeDW_); + cl_uint4 zero; + zero.s[0] = 0; + zero.s[1] = 0; + zero.s[2] = 0; + zero.s[3] = 0; + error_ = + _wrapper->clSetKernelArg(kernel_, 4, sizeof(cl_uint4), (void *)&zero); + int bMem = 1; + error_ = _wrapper->clSetKernelArg(kernel_, 5, sizeof(cl_int), (void *)&bMem); + repeats_ = std::max((maxSize_ >> 2) / bufSizeDW_, 1u); + error_ = + _wrapper->clSetKernelArg(kernel_, 6, sizeof(cl_uint), (void *)&repeats_); + + error_ = + _wrapper->clSetKernelArg(kernel2_, 0, sizeof(cl_mem), (void *)&inBuffer_); + error_ = _wrapper->clSetKernelArg(kernel2_, 1, sizeof(cl_mem), + (void *)&outBuffer_); + error_ = _wrapper->clSetKernelArg(kernel2_, 2, sizeof(cl_uint), + (void *)&bufSizeDW_); + error_ = _wrapper->clSetKernelArg(kernel2_, 3, sizeof(cl_uint), + (void *)&bufSizeDW_); + error_ = + _wrapper->clSetKernelArg(kernel2_, 4, sizeof(cl_uint4), (void *)&zero); + error_ = _wrapper->clSetKernelArg(kernel2_, 5, sizeof(cl_int), (void *)&bMem); + error_ = + _wrapper->clSetKernelArg(kernel2_, 6, sizeof(cl_uint), (void *)&repeats_); + + setData(inBuffer_, (int)1.0f); +} + +void OCLPerfTextureMemLatency::run(void) { + int global = 1; + int local = 1; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + // Warm-up + unsigned int warmup = 128; + error_ = + _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), (void *)&warmup); + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), + (void *)&bufSizeDW_); + _wrapper->clFinish(cmd_queue_); + + CPerfCounter timer, timer2; + + timer.Reset(); + timer.Start(); + + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + + checkData(outBuffer_); + + timer2.Reset(); + timer2.Start(); + + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel2_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + + _wrapper->clFinish(cmd_queue_); + + timer2.Stop(); + double sec = timer.GetElapsedTime() - timer2.GetElapsedTime(); + + // Read latency in ns + double perf = sec * (double)(1e09) / ((double)bufSizeDW_ * (double)repeats_); + + _perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), "%8d reads, %5d repeats (ns)", bufSizeDW_, + repeats_); + testDescString = buf; +} + +unsigned int OCLPerfTextureMemLatency::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (inBuffer_) { + error_ = _wrapper->clReleaseMemObject(inBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (kernel2_) { + error_ = _wrapper->clReleaseKernel(kernel2_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfTextureMemLatency.h b/opencl/tests/ocltst/module/perf/OCLPerfTextureMemLatency.h new file mode 100644 index 0000000000..acb8cbe5b9 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfTextureMemLatency.h @@ -0,0 +1,60 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_TEXTUREMEMLATENCY_H_ +#define _OCL_TEXTUREMEMLATENCY_H_ + +#include "OCLTestImp.h" + +class OCLPerfTextureMemLatency : public OCLTestImp { + public: + OCLPerfTextureMemLatency(); + virtual ~OCLPerfTextureMemLatency(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void genShader(void); + void setData(cl_mem buffer, unsigned int data); + void checkData(cl_mem buffer); + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_kernel kernel2_; + cl_mem inBuffer_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int width_; + unsigned int height_; + size_t image_row_pitch; + size_t image_slice_pitch; + unsigned int bufSizeDW_; + unsigned int repeats_; + unsigned int maxSize_; +}; + +#endif // _OCL_TEXTUREMEMLATENCY_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfUAVReadSpeed.cpp b/opencl/tests/ocltst/module/perf/OCLPerfUAVReadSpeed.cpp new file mode 100644 index 0000000000..4124fa826c --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfUAVReadSpeed.cpp @@ -0,0 +1,630 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfUAVReadSpeed.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +static const unsigned int NUM_SIZES = 4; +static const unsigned int NUM_READ_MODES = 6; +// Limit to 32 reads for now +static const unsigned int MAX_READ_MODES = 4; + +static const unsigned int NumReads[NUM_READ_MODES] = {1, 4, 16, 32, 64, 128}; +// 256KB, 1 MB, 4MB, 16 MB +static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304, + 16777216}; +static const unsigned int MaxTypes = 6; +static unsigned int NumTypes = MaxTypes; +static const char *types[MaxTypes] = {"char", "short", "int", + "long", "float", "double"}; +static unsigned int StartType = 0; +static const unsigned int NumVecWidths = 5; +static const char *vecWidths[NumVecWidths] = {"", "2", "4", "8", "16"}; +static const unsigned int TypeSize[MaxTypes] = { + sizeof(cl_char), sizeof(cl_short), sizeof(cl_int), + sizeof(cl_long), sizeof(cl_float), sizeof(cl_double)}; +#define CHAR_BUF_SIZE 512 + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif +void OCLPerfUAVReadSpeed::genShader(unsigned int type, unsigned int vecWidth, + unsigned int numReads) { + char buf[CHAR_BUF_SIZE]; + + shader_.clear(); + shader_ += + "#ifdef USE_ARENA\n" + "#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable\n" + "#endif\n"; + shader_ += + "#ifdef USE_AMD_DOUBLES\n" + "#pragma OPENCL EXTENSION cl_amd_fp64 : enable\n" + "#endif\n"; + shader_ += + "#ifdef USE_KHR_DOUBLES\n" + "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n" + "#endif\n"; + SNPRINTF(buf, CHAR_BUF_SIZE, + "__kernel void __attribute__((reqd_work_group_size(64,1,1))) " + "_uavReadSpeed(__global %s%s * restrict inBuf, __global %s%s * " + "restrict outBuf, constant uint * restrict constBuf)\n", + types[type], vecWidths[vecWidth], types[type], vecWidths[vecWidth]); + shader_.append(buf); + shader_ += + "{\n" + " uint i = (uint) get_global_id(0);\n"; + if (numReads == 1) { + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + shader_ += + " const unsigned int Max = constBuf[0];\n" + " temp = *(inBuf + i % Max);\n"; + shader_ += + " *(outBuf + i) = temp;\n" + "}\n"; + } else { + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp0 = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp1 = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp2 = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp3 = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + shader_ += + " const unsigned int Max = constBuf[0];\n" + " unsigned int idx0 = (i % Max) + constBuf[1];\n" + " unsigned int idx1 = (i % Max) + constBuf[2];\n" + " unsigned int idx2 = (i % Max) + constBuf[3];\n" + " unsigned int idx3 = (i % Max) + constBuf[4];\n"; + + for (unsigned int i = 0; i < (numReads >> 2); i++) { + shader_ += " temp0 += *(inBuf + idx0);\n"; + shader_ += " temp1 += *(inBuf + idx1);\n"; + shader_ += " temp2 += *(inBuf + idx2);\n"; + shader_ += " temp3 += *(inBuf + idx3);\n"; + shader_ += " idx0 += constBuf[5];\n"; + shader_ += " idx1 += constBuf[5];\n"; + shader_ += " idx2 += constBuf[5];\n"; + shader_ += " idx3 += constBuf[5];\n"; + } + shader_ += + " *(outBuf + i) = temp0 + temp1 + temp2 + temp3;\n" + "}\n"; + } + // printf("shader:\n%s\n", shader_.c_str()); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +OCLPerfUAVReadSpeed::OCLPerfUAVReadSpeed() { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + context_ = 0; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + // Get last for default + platform = platforms[numPlatforms - 1]; + for (unsigned i = 0; i < numPlatforms; ++i) { + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, + sizeof(pbuf), pbuf, NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = + _wrapper->clGetDeviceIDs(platforms[i], type_, 0, NULL, &num_devices); + // Runtime returns an error when no GPU devices are present instead of + // just returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + platform = platforms[i]; + break; + } + } + delete platforms; + } + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + char *p = strstr(charbuf, "cl_khr_byte_addressable_store"); + char *p2 = strstr(charbuf, "cl_khr_fp64"); + char *p3 = strstr(charbuf, "cl_amd_fp64"); + + NumTypes = MaxTypes; + if (!p) { + // No arena ops + NumTypes -= 2; + StartType = 2; + } + if (!p2 && !p3) { + // Doubles not supported + NumTypes--; + } + _numSubTests = NumTypes * NumVecWidths * NUM_SIZES * MAX_READ_MODES * 2; + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } +} + +OCLPerfUAVReadSpeed::~OCLPerfUAVReadSpeed() {} + +// Fill with 1s of appropriate type +void OCLPerfUAVReadSpeed::setData(cl_mem buffer, float val) { + void *ptr = + _wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, CL_MAP_WRITE, 0, + bufSize_, 0, NULL, NULL, &error_); + switch (typeIdx_) { + case 0: // char + { + char *data = (char *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(char)); i++) + data[i] = (char)val; + break; + } + case 1: // short + { + short *data = (short *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(short)); i++) + data[i] = (short)val; + break; + } + case 2: // int + { + int *data = (int *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(int)); i++) + data[i] = (int)val; + break; + } + case 3: // long + { + cl_long *data = (cl_long *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(cl_long)); i++) + data[i] = (cl_long)val; + break; + } + case 4: // float + { + float *data = (float *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(float)); i++) + data[i] = val; + break; + } + case 5: // double + { + double *data = (double *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(double)); i++) + data[i] = (double)val; + break; + } + default: + // oops + break; + } + error_ = + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, ptr, 0, NULL, NULL); +} + +void OCLPerfUAVReadSpeed::checkData(cl_mem buffer) { + void *ptr = + _wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, CL_MAP_READ, 0, + bufSize_, 0, NULL, NULL, &error_); + switch (typeIdx_) { + case 0: // char + { + char *data = (char *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(char)); i++) { + if (data[i] != (char)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, + numReads_, numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + break; + } + case 1: // short + { + short *data = (short *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(short)); i++) { + if (data[i] != (short)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, + numReads_, numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + break; + } + case 2: // int + { + int *data = (int *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(int)); i++) { + if (data[i] != (int)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, + numReads_, numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + break; + } + case 3: // long + { + cl_long *data = (cl_long *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(cl_long)); i++) { + if (data[i] != (cl_long)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, + numReads_, numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + break; + } + case 4: // float + { + float *data = (float *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(float)); i++) { + if (data[i] != (float)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, + numReads_, numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + break; + } + case 5: // double + { + double *data = (double *)ptr; + for (unsigned int i = 0; i < (bufSize_ / sizeof(double)); i++) { + if (data[i] != (double)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, + numReads_, numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + break; + } + default: + // oops + break; + } + error_ = + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, ptr, 0, NULL, NULL); +} + +void OCLPerfUAVReadSpeed::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + inBuffer_ = 0; + outBuffer_ = 0; + constBuffer_ = 0; + isAMD = false; + _errorFlag = false; // Reset error code so a single error doesn't prevent + // other subtests from running + _errorMsg = ""; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + + numReads_ = NumReads[test % MAX_READ_MODES]; + width_ = Sizes[(test / MAX_READ_MODES) % NUM_SIZES]; + vecSizeIdx_ = (test / (MAX_READ_MODES * NUM_SIZES)) % NumVecWidths; + typeIdx_ = (test / (MAX_READ_MODES * NUM_SIZES * NumVecWidths)) % NumTypes + + StartType; + cached_ = (test >= (MAX_READ_MODES * NUM_SIZES * NumTypes * NumVecWidths)); + + bufSize_ = width_; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + device = devices[0]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + inBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(inBuffer_ == 0, "clCreateBuffer(inBuffer) failed"); + + outBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + constBuffer_ = _wrapper->clCreateBuffer(context_, 0, 16 * 2, NULL, &error_); + CHECK_RESULT(constBuffer_ == 0, "clCreateBuffer(constBuffer) failed"); + + genShader(typeIdx_, vecSizeIdx_, numReads_); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + std::string args; + args.clear(); + if (cached_ && isAMD) { + args = "-fno-alias "; + } + if (typeIdx_ < 2) { + args += "-D USE_ARENA "; + } + + if (typeIdx_ == 5) { + if (isAMD) { + args += "-D USE_AMD_DOUBLES "; + } else { + args += "-D USE_KHR_DOUBLES "; + } + } +#if 0 + // This setting can dramatically boost the long16 perf results by avoiding spilling. + if (isAMD) + args += "-Wb,-pre-RA-sched=list-tdrr"; +#endif + + error_ = + _wrapper->clBuildProgram(program_, 1, &device, args.c_str(), NULL, NULL); + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "_uavReadSpeed", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&inBuffer_); + error_ = + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), (void *)&outBuffer_); + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_mem), + (void *)&constBuffer_); + + setData(inBuffer_, 1.0f); + setData(outBuffer_, 1.2345678f); + unsigned int *cBuf = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, constBuffer_, true, CL_MAP_WRITE, 0, 16 * 2, 0, NULL, NULL, + &error_); + // Force all wavefronts to fetch the same data. We are looking for peak speed + // here. + cBuf[0] = 64; + // These values are chosen to assure there is no data reuse within a clause. + // If caching is not working, then the uncached numbers will be low. + cBuf[1] = 0; + cBuf[2] = 64; + cBuf[3] = 128; + cBuf[4] = 192; + cBuf[5] = 0; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, constBuffer_, cBuf, 0, + NULL, NULL); + _wrapper->clFinish(cmd_queue_); +} + +void OCLPerfUAVReadSpeed::run(void) { + int global = bufSize_ / (TypeSize[typeIdx_] * (1 << vecSizeIdx_)); + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < NUM_ITER; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Constant bandwidth in GB/s + double perf = + ((double)bufSize_ * numReads_ * NUM_ITER * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char buf[256]; + char buf2[256]; + SNPRINTF(buf, sizeof(buf), "%s%s", types[typeIdx_], vecWidths[vecSizeIdx_]); + SNPRINTF(buf2, sizeof(buf2), " %-8s (%8d) %2d reads: %-8s (GB/s) ", buf, + width_, numReads_, (cached_ ? "cached" : "uncached")); + testDescString = buf2; + checkData(outBuffer_); +} + +unsigned int OCLPerfUAVReadSpeed::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (inBuffer_) { + error_ = _wrapper->clReleaseMemObject(inBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (constBuffer_) { + error_ = _wrapper->clReleaseMemObject(constBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(constBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfUAVReadSpeed.h b/opencl/tests/ocltst/module/perf/OCLPerfUAVReadSpeed.h new file mode 100644 index 0000000000..3d2c04fbca --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfUAVReadSpeed.h @@ -0,0 +1,63 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_UAVReadSpeed_H_ +#define _OCL_UAVReadSpeed_H_ + +#include "OCLTestImp.h" + +class OCLPerfUAVReadSpeed : public OCLTestImp { + public: + OCLPerfUAVReadSpeed(); + virtual ~OCLPerfUAVReadSpeed(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void genShader(unsigned int type, unsigned int vecWidth, + unsigned int numReads); + void setData(cl_mem buffer, float data); + void checkData(cl_mem buffer); + + static const unsigned int NUM_ITER = 100; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem inBuffer_; + cl_mem outBuffer_; + cl_mem constBuffer_; + cl_int error_; + + unsigned int width_; + unsigned int bufSize_; + unsigned int vecSizeIdx_; + unsigned int numReads_; + unsigned int typeIdx_; + bool cached_; + bool isAMD; +}; + +#endif // _OCL_UAVReadSpeed_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfUAVReadSpeedHostMem.cpp b/opencl/tests/ocltst/module/perf/OCLPerfUAVReadSpeedHostMem.cpp new file mode 100644 index 0000000000..cf2536de85 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfUAVReadSpeedHostMem.cpp @@ -0,0 +1,437 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfUAVReadSpeedHostMem.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +const unsigned int NUM_SIZES = 4; +const unsigned int NUM_READ_MODES = 1; +const unsigned int MAX_READ_MODES = 1; + +static const unsigned int NumReads[NUM_READ_MODES] = {1}; +// 256KB, 1 MB, 4MB, 16 MB and 64 MB +static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304, + 16777216}; +static const unsigned int MaxTypes = 2; +static unsigned int NumTypes = MaxTypes; +static const char *types[MaxTypes] = {"float", "double"}; +static const unsigned int TypeSize[MaxTypes] = {sizeof(cl_float), + sizeof(cl_double)}; +static const unsigned int NumVecWidths = 5; +static const char *vecWidths[NumVecWidths] = {"", "2", "4", "8", "16"}; +#define CHAR_BUF_SIZE 512 + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif +void OCLPerfUAVReadSpeedHostMem::genShader(unsigned int type, + unsigned int vecWidth, + unsigned int numReads) { + char buf[CHAR_BUF_SIZE]; + + shader_.clear(); + shader_ += + "#ifdef USE_AMD_DOUBLES\n" + "#pragma OPENCL EXTENSION cl_amd_fp64 : enable\n" + "#endif\n"; + shader_ += + "#ifdef USE_KHR_DOUBLES\n" + "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n" + "#endif\n"; + SNPRINTF(buf, CHAR_BUF_SIZE, + "__kernel void _uavReadSpeedHostMem(__global %s%s *inBuf, __global " + "%s%s *outBuf, constant uint *constBuf)\n", + types[type], vecWidths[vecWidth], types[type], vecWidths[vecWidth]); + shader_.append(buf); + shader_ += + "{\n" + " int i = (int) get_global_id(0);\n"; + SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp = 0;\n", types[type], + vecWidths[vecWidth]); + shader_.append(buf); + shader_ += " temp = *(inBuf + i);\n"; + if (vecWidth == 0) { + shader_ += + " if (temp < 0)\n" + " *(outBuf + i) = temp;\n" + "}\n"; + } else { + shader_ += + " if (temp.s0 < 0)\n" + " *(outBuf + i) = temp;\n" + "}\n"; + } + // printf("shader:\n%s\n", shader_.c_str()); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +OCLPerfUAVReadSpeedHostMem::OCLPerfUAVReadSpeedHostMem() { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + context_ = 0; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + // Get last for default + platform = platforms[numPlatforms - 1]; + for (unsigned i = 0; i < numPlatforms; ++i) { + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, + sizeof(pbuf), pbuf, NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = + _wrapper->clGetDeviceIDs(platforms[i], type_, 0, NULL, &num_devices); + // Runtime returns an error when no GPU devices are present instead of + // just returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + platform = platforms[i]; + break; + } + } + delete platforms; + } + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + char *p = strstr(charbuf, "cl_khr_fp64"); + char *p2 = strstr(charbuf, "cl_amd_fp64"); + + NumTypes = MaxTypes; + + if (!p && !p2) { + // Doubles not supported + NumTypes--; + } + _numSubTests = NumTypes * NumVecWidths * NUM_SIZES * MAX_READ_MODES; + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } +} + +OCLPerfUAVReadSpeedHostMem::~OCLPerfUAVReadSpeedHostMem() {} + +void OCLPerfUAVReadSpeedHostMem::setData(cl_mem buffer, float val) { + float *data = (float *)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, + CL_MAP_WRITE, 0, bufSize_, + 0, NULL, NULL, &error_); + for (unsigned int i = 0; i < (bufSize_ >> 2); i++) data[i] = val; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +void OCLPerfUAVReadSpeedHostMem::checkData(cl_mem buffer) { + float *data = (float *)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, + CL_MAP_READ, 0, bufSize_, + 0, NULL, NULL, &error_); + for (unsigned int i = 0; i < (bufSize_ >> 2); i++) { + if (data[i] != (float)numReads_) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, numReads_, + numReads_, numReads_, (unsigned int)data[i], + (unsigned int)data[i + 1], (unsigned int)data[i + 2], + (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +void OCLPerfUAVReadSpeedHostMem::open(unsigned int test, char *units, + double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + inBuffer_ = 0; + outBuffer_ = 0; + constBuffer_ = 0; + isAMD = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + + numReads_ = NumReads[test % MAX_READ_MODES]; + width_ = Sizes[(test / MAX_READ_MODES) % NUM_SIZES]; + vecSizeIdx_ = (test / (MAX_READ_MODES * NUM_SIZES)) % NumVecWidths; + typeIdx_ = (test / (MAX_READ_MODES * NUM_SIZES * NumVecWidths)) % NumTypes; + cached_ = true; + + bufSize_ = width_; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + device = devices[0]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + inBuffer_ = _wrapper->clCreateBuffer(context_, + CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR, + bufSize_, NULL, &error_); + CHECK_RESULT(inBuffer_ == 0, "clCreateBuffer(inBuffer) failed"); + + outBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + constBuffer_ = _wrapper->clCreateBuffer(context_, 0, 16 * 2, NULL, &error_); + CHECK_RESULT(constBuffer_ == 0, "clCreateBuffer(constBuffer) failed"); + + genShader(typeIdx_, vecSizeIdx_, numReads_); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + std::string args; + args.clear(); + if (cached_ && isAMD) { + args = "-fno-alias "; + } + if (typeIdx_ == 1) { + if (isAMD) { + args += "-D USE_AMD_DOUBLES "; + } else { + args += "-D USE_KHR_DOUBLES "; + } + } + error_ = + _wrapper->clBuildProgram(program_, 1, &device, args.c_str(), NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "_uavReadSpeedHostMem", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&inBuffer_); + error_ = + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), (void *)&outBuffer_); + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_mem), + (void *)&constBuffer_); + + setData(inBuffer_, 0.0f); + setData(outBuffer_, 1.2345678f); + unsigned int *cBuf = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, constBuffer_, true, CL_MAP_WRITE, 0, 16 * 2, 0, NULL, NULL, + &error_); + cBuf[0] = bufSize_ / (TypeSize[typeIdx_] * (1 << vecSizeIdx_)); + cBuf[1] = 0; + cBuf[2] = 1024; + cBuf[3] = 2048; + cBuf[4] = 3072; + cBuf[5] = 0; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, constBuffer_, cBuf, 0, + NULL, NULL); + _wrapper->clFinish(cmd_queue_); +} + +void OCLPerfUAVReadSpeedHostMem::run(void) { + int global = bufSize_ / (TypeSize[typeIdx_] * (1 << vecSizeIdx_)); + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < NUM_ITER; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Constant bandwidth in GB/s + double perf = + ((double)bufSize_ * numReads_ * NUM_ITER * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char buf[256]; + char buf2[256]; + SNPRINTF(buf, sizeof(buf), "%s%s", types[typeIdx_], vecWidths[vecSizeIdx_]); + SNPRINTF(buf2, sizeof(buf2), " %-8s (%8d) (GB/s) ", buf, width_); + testDescString = buf2; + // Test doesn't write anything + // checkData(outBuffer_); +} + +unsigned int OCLPerfUAVReadSpeedHostMem::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (inBuffer_) { + error_ = _wrapper->clReleaseMemObject(inBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (constBuffer_) { + error_ = _wrapper->clReleaseMemObject(constBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(constBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfUAVReadSpeedHostMem.h b/opencl/tests/ocltst/module/perf/OCLPerfUAVReadSpeedHostMem.h new file mode 100644 index 0000000000..5d12647f47 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfUAVReadSpeedHostMem.h @@ -0,0 +1,63 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_UAVReadSpeedHostMem_H_ +#define _OCL_UAVReadSpeedHostMem_H_ + +#include "OCLTestImp.h" + +class OCLPerfUAVReadSpeedHostMem : public OCLTestImp { + public: + OCLPerfUAVReadSpeedHostMem(); + virtual ~OCLPerfUAVReadSpeedHostMem(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void genShader(unsigned int type, unsigned int vecWidth, + unsigned int numReads); + void setData(cl_mem buffer, float data); + void checkData(cl_mem buffer); + + static const unsigned int NUM_ITER = 100; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem inBuffer_; + cl_mem outBuffer_; + cl_mem constBuffer_; + cl_int error_; + + unsigned int width_; + unsigned int bufSize_; + unsigned int vecSizeIdx_; + unsigned int numReads_; + unsigned int typeIdx_; + bool isAMD; + bool cached_; +}; + +#endif // _OCL_UAVReadSpeedHostMem_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfUAVWriteSpeedHostMem.cpp b/opencl/tests/ocltst/module/perf/OCLPerfUAVWriteSpeedHostMem.cpp new file mode 100644 index 0000000000..c677f35636 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfUAVWriteSpeedHostMem.cpp @@ -0,0 +1,380 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfUAVWriteSpeedHostMem.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +const unsigned int NUM_SIZES = 4; + +// 256KB, 1 MB, 4MB, 16 MB and 64 MB +static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304, + 16777216}; +static const unsigned int MaxTypes = 2; +static unsigned int NumTypes = 2; +static const char *types[MaxTypes] = {"float", "double"}; +static const unsigned int TypeSize[MaxTypes] = {sizeof(cl_float), + sizeof(cl_double)}; +static const unsigned int NumVecWidths = 5; +static const char *vecWidths[NumVecWidths] = {"", "2", "4", "8", "16"}; +#define CHAR_BUF_SIZE 512 + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif +void OCLPerfUAVWriteSpeedHostMem::genShader(unsigned int type, + unsigned int vecWidth) { + char buf[CHAR_BUF_SIZE]; + + shader_.clear(); + shader_ += + "#ifdef USE_AMD_DOUBLES\n" + "#pragma OPENCL EXTENSION cl_amd_fp64 : enable\n" + "#endif\n"; + shader_ += + "#ifdef USE_KHR_DOUBLES\n" + "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n" + "#endif\n"; + SNPRINTF(buf, CHAR_BUF_SIZE, + "__kernel void _uavWriteSpeedHostMem(__global %s%s *outBuf)\n", + types[type], vecWidths[vecWidth]); + shader_.append(buf); + shader_ += + "{\n" + " int i = (int) get_global_id(0);\n" + " *(outBuf + i) = 0;\n" + "}\n"; + // printf("shader:\n%s\n", shader_.c_str()); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +OCLPerfUAVWriteSpeedHostMem::OCLPerfUAVWriteSpeedHostMem() { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + context_ = 0; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + // Get last for default + platform = platforms[numPlatforms - 1]; + for (unsigned i = 0; i < numPlatforms; ++i) { + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, + sizeof(pbuf), pbuf, NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = + _wrapper->clGetDeviceIDs(platforms[i], type_, 0, NULL, &num_devices); + // Runtime returns an error when no GPU devices are present instead of + // just returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + platform = platforms[i]; + break; + } + } + delete platforms; + } + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + char *p = strstr(charbuf, "cl_khr_fp64"); + char *p2 = strstr(charbuf, "cl_amd_fp64"); + + NumTypes = MaxTypes; + + if (!p && !p2) { + // Doubles not supported + NumTypes--; + } + _numSubTests = NumTypes * NumVecWidths * NUM_SIZES; + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } +} + +OCLPerfUAVWriteSpeedHostMem::~OCLPerfUAVWriteSpeedHostMem() {} + +void OCLPerfUAVWriteSpeedHostMem::setData(cl_mem buffer, float val) { + float *data = (float *)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, + CL_MAP_WRITE, 0, bufSize_, + 0, NULL, NULL, &error_); + for (unsigned int i = 0; i < (bufSize_ >> 2); i++) data[i] = val; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); + _wrapper->clFinish(cmd_queue_); +} + +void OCLPerfUAVWriteSpeedHostMem::checkData(cl_mem buffer) { + float *data = (float *)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, + CL_MAP_READ, 0, bufSize_, + 0, NULL, NULL, &error_); + for (unsigned int i = 0; i < (bufSize_ >> 2); i++) { + if (data[i] != 0.0f) { + printf("Data validation failed at index %d!\n", i); + printf("Expected %lf %lf %lf %lf\nGot %d %d %d %d\n", 0.0f, 0.0f, 0.0f, + 0.0f, (unsigned int)data[i], (unsigned int)data[i + 1], + (unsigned int)data[i + 2], (unsigned int)data[i + 3]); + CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n"); + break; + } + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); + _wrapper->clFinish(cmd_queue_); +} + +void OCLPerfUAVWriteSpeedHostMem::open(unsigned int test, char *units, + double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + outBuffer_ = 0; + isAMD = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + + width_ = Sizes[test % NUM_SIZES]; + vecSizeIdx_ = (test / NUM_SIZES) % NumVecWidths; + typeIdx_ = (test / (NUM_SIZES * NumVecWidths)) % NumTypes; + + bufSize_ = width_; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + device = devices[0]; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + outBuffer_ = _wrapper->clCreateBuffer( + context_, CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR, bufSize_, NULL, + &error_); + CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed"); + + genShader(typeIdx_, vecSizeIdx_); + char *tmp = (char *)shader_.c_str(); + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&tmp, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + std::string args; + args.clear(); + if (typeIdx_ == 1) { + if (isAMD) { + args += "-D USE_AMD_DOUBLES "; + } else { + args += "-D USE_KHR_DOUBLES "; + } + } + error_ = + _wrapper->clBuildProgram(program_, 1, &device, args.c_str(), NULL, NULL); + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = + _wrapper->clCreateKernel(program_, "_uavWriteSpeedHostMem", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&outBuffer_); + + setData(outBuffer_, 1.2345678f); +} + +void OCLPerfUAVWriteSpeedHostMem::run(void) { + int global = bufSize_ / (TypeSize[typeIdx_] * (1 << vecSizeIdx_)); + int local = 64; + + size_t global_work_size[1] = {(size_t)global}; + size_t local_work_size[1] = {(size_t)local}; + + CPerfCounter timer; + + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < NUM_ITER; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + } + _wrapper->clFinish(cmd_queue_); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + // Constant bandwidth in GB/s + double perf = ((double)bufSize_ * NUM_ITER * (double)(1e-09)) / sec; + + _perfInfo = (float)perf; + char buf[256]; + char buf2[256]; + SNPRINTF(buf, sizeof(buf), "%s%s", types[typeIdx_], vecWidths[vecSizeIdx_]); + SNPRINTF(buf2, sizeof(buf2), " %-8s (%8d) (GB/s) ", buf, width_); + testDescString = buf2; + + // Test just writes 0s + checkData(outBuffer_); +} + +unsigned int OCLPerfUAVWriteSpeedHostMem::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (outBuffer_) { + error_ = _wrapper->clReleaseMemObject(outBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfUAVWriteSpeedHostMem.h b/opencl/tests/ocltst/module/perf/OCLPerfUAVWriteSpeedHostMem.h new file mode 100644 index 0000000000..87f54bf892 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfUAVWriteSpeedHostMem.h @@ -0,0 +1,58 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_UAVWriteSpeedHostMem_H_ +#define _OCL_UAVWriteSpeedHostMem_H_ + +#include "OCLTestImp.h" + +class OCLPerfUAVWriteSpeedHostMem : public OCLTestImp { + public: + OCLPerfUAVWriteSpeedHostMem(); + virtual ~OCLPerfUAVWriteSpeedHostMem(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + std::string shader_; + void genShader(unsigned int type, unsigned int vecWidth); + void setData(cl_mem buffer, float data); + void checkData(cl_mem buffer); + + static const unsigned int NUM_ITER = 100; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem outBuffer_; + cl_int error_; + + unsigned int width_; + unsigned int bufSize_; + unsigned int vecSizeIdx_; + unsigned int typeIdx_; + bool isAMD; +}; + +#endif // _OCL_UAVWriteSpeedHostMem_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfUncoalescedRead.cpp b/opencl/tests/ocltst/module/perf/OCLPerfUncoalescedRead.cpp new file mode 100644 index 0000000000..6db8a24be7 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfUncoalescedRead.cpp @@ -0,0 +1,270 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfUncoalescedRead.h" + +#include + +#include +#include + +#include "Timer.h" + +const char* OCLPerfUncoalescedRead::kernel_str = + "#define NUM_READS 32\n\ + __kernel void read_uncoalescing(__global float *input,__global float *output)\n\ + {\n\ + float val = (float)(0.0f);\n\ + size_t gid = get_global_id(0);\n\ + val = val + input[gid * NUM_READS + 0];\n\ + val = val + input[gid * NUM_READS + 1];\n\ + val = val + input[gid * NUM_READS + 2];\n\ + val = val + input[gid * NUM_READS + 3];\n\ + val = val + input[gid * NUM_READS + 4];\n\ + val = val + input[gid * NUM_READS + 5];\n\ + val = val + input[gid * NUM_READS + 6];\n\ + val = val + input[gid * NUM_READS + 7];\n\ + val = val + input[gid * NUM_READS + 8];\n\ + val = val + input[gid * NUM_READS + 9];\n\ + val = val + input[gid * NUM_READS + 10];\n\ + val = val + input[gid * NUM_READS + 11];\n\ + val = val + input[gid * NUM_READS + 12];\n\ + val = val + input[gid * NUM_READS + 13];\n\ + val = val + input[gid * NUM_READS + 14];\n\ + val = val + input[gid * NUM_READS + 15];\n\ + val = val + input[gid * NUM_READS + 16];\n\ + val = val + input[gid * NUM_READS + 17];\n\ + val = val + input[gid * NUM_READS + 18];\n\ + val = val + input[gid * NUM_READS + 19];\n\ + val = val + input[gid * NUM_READS + 20];\n\ + val = val + input[gid * NUM_READS + 21];\n\ + val = val + input[gid * NUM_READS + 22];\n\ + val = val + input[gid * NUM_READS + 23];\n\ + val = val + input[gid * NUM_READS + 24];\n\ + val = val + input[gid * NUM_READS + 25];\n\ + val = val + input[gid * NUM_READS + 26];\n\ + val = val + input[gid * NUM_READS + 27];\n\ + val = val + input[gid * NUM_READS + 28];\n\ + val = val + input[gid * NUM_READS + 29];\n\ + val = val + input[gid * NUM_READS + 30];\n\ + val = val + input[gid * NUM_READS + 31];\n\ + output[gid] = val;\n\ + }\n"; + +OCLPerfUncoalescedRead::OCLPerfUncoalescedRead() { _numSubTests = 3; } + +OCLPerfUncoalescedRead::~OCLPerfUncoalescedRead() {} + +void OCLPerfUncoalescedRead::open(unsigned int test, char* units, + double& conversion, unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "error_ opening test"); + silentFailure = false; + _openTest = test; + program_ = 0; + kernel_ = 0; + input_buff = NULL; + + if (test > 0) { + size_t param_size = 0; + char* strVersion = 0; + error_ = _wrapper->clGetDeviceInfo( + devices_[_deviceId], CL_DEVICE_OPENCL_C_VERSION, 0, 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + strVersion = (char*)malloc(param_size); + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_OPENCL_C_VERSION, param_size, + strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + if (strVersion[9] < '2') { + printf("\nOpenCL C 2.0 not supported\n"); + silentFailure = true; + } + free(strVersion); + if (silentFailure) return; + } + + cl_mem buffer = + _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY, + SIZE * NUM_READS * sizeof(cl_float), 0, &error_); + buffers_.push_back(buffer); + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, + SIZE * sizeof(cl_float), 0, &error_); + buffers_.push_back(buffer); + + srand(0x8956); + input_buff = (float*)malloc(SIZE * NUM_READS * sizeof(float)); + for (unsigned int i = 0; i < SIZE * NUM_READS; ++i) { + input_buff[i] = (float)rand(); + } + + error_ = _wrapper->clEnqueueWriteBuffer( + cmdQueues_[_deviceId], buffers_[0], CL_TRUE, 0, + SIZE * NUM_READS * sizeof(cl_float), input_buff, 0, 0, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed"); + + float* buff = (float*)_wrapper->clEnqueueMapBuffer( + cmdQueues_[_deviceId], buffers_[1], CL_TRUE, CL_MAP_WRITE, 0, + SIZE * sizeof(cl_float), 0, 0, 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueMapBuffer failed"); + memset(buff, 0, SIZE * sizeof(cl_float)); + error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], buffers_[1], + buff, 0, 0, 0); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueMapBuffer failed"); + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &kernel_str, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource failed"); + std::string compileOptions = ""; + if (test > 0) { + compileOptions = "-cl-std=CL2.0"; + } + if (test > 1) { + compileOptions += " -fsc-use-buffer-for-hsa-global "; + } + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], + compileOptions.c_str(), NULL, NULL); + + if (error_ != CL_SUCCESS) { + char log[400]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 400, log, 0); + printf("\n\n%s\n\n", log); + } + + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram failed"); + kernel_ = _wrapper->clCreateKernel(program_, "read_uncoalescing", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel failed"); + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + error_ = + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), (void*)&buffers_[1]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); +} + +void OCLPerfUncoalescedRead::validate(void) { + bool success = true; + float* buff = (float*)_wrapper->clEnqueueMapBuffer( + cmdQueues_[_deviceId], buffers_[1], CL_TRUE, CL_MAP_READ, 0, + SIZE * sizeof(cl_float), 0, 0, 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueMapBuffer failed"); + for (unsigned int i = 0; i < SIZE; ++i) { + volatile float val = 0; + for (int j = 0; j < NUM_READS; ++j) { + val += input_buff[i * NUM_READS + j]; + } + if (val != buff[i]) { + success = false; + std::string errorMsg = "Invalid result. Expected: "; + errorMsg += std::to_string(val); + errorMsg += " Actual result: "; + errorMsg += std::to_string(buff[i]); + CHECK_RESULT(true, errorMsg.c_str()); + break; + } + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], buffers_[1], + buff, 0, 0, 0); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueMapBuffer failed"); +} + +void OCLPerfUncoalescedRead::run(void) { + if (silentFailure) { + return; + } + CPerfCounter timer; + + // Warm up + size_t workGroupSize = SIZE; + for (int i = 0; i < 50; ++i) { + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, &workGroupSize, NULL, 0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + } + + cl_event eventArr[NUM_ITER]; + timer.Reset(); + timer.Start(); + for (unsigned int i = 0; i < NUM_ITER; i++) { + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, &workGroupSize, NULL, 0, + NULL, &eventArr[i]); + + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + } + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + CHECK_RESULT(error_, "clFinish failed"); + timer.Stop(); + double sec1 = timer.GetElapsedTime(); + double sec2 = 0; + for (unsigned int i = 0; i < NUM_ITER; ++i) { + cl_ulong startTime = 0, endTime = 0; + error_ = _wrapper->clGetEventProfilingInfo(eventArr[i], + CL_PROFILING_COMMAND_START, + sizeof(cl_ulong), &startTime, 0); + CHECK_RESULT(error_, "clGetEventProfilingInfo failed"); + error_ = _wrapper->clGetEventProfilingInfo( + eventArr[i], CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &endTime, 0); + CHECK_RESULT(error_, "clGetEventProfilingInfo failed"); + sec2 += 1e-9 * (endTime - startTime); + error_ = _wrapper->clReleaseEvent(eventArr[i]); + CHECK_RESULT(error_, "clReleaseEvent failed"); + } + + validate(); + + // Buffer copy bandwidth in GB/s + double perf1 = ((double)SIZE * NUM_READS * NUM_ITER * sizeof(cl_float) * + (double)(1e-09)) / + sec1; + double perf2 = ((double)SIZE * NUM_READS * NUM_ITER * sizeof(cl_float) * + (double)(1e-09)) / + sec2; + _perfInfo = (float)perf2; + + std::ostringstream strStream; + switch (_openTest) { + case 0: + strStream << "OCL1.2 "; + break; + case 1: + strStream << "OCL2.0 "; + break; + case 2: + strStream << "OCL2.0/flag "; + break; + } + + strStream << std::fixed << std::setprecision(2) << perf1 << " timer GB/s "; + strStream << "time: " << std::setprecision(3) << sec1 << "s (profile GB/s)"; + testDescString = strStream.str(); + ; +} + +unsigned int OCLPerfUncoalescedRead::close(void) { + if (input_buff) { + free(input_buff); + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfUncoalescedRead.h b/opencl/tests/ocltst/module/perf/OCLPerfUncoalescedRead.h new file mode 100644 index 0000000000..1f3cef0507 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfUncoalescedRead.h @@ -0,0 +1,44 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_UncoalescedRead_H_ +#define _OCL_UncoalescedRead_H_ + +#include "OCLTestImp.h" +#define NUM_READS 32 +class OCLPerfUncoalescedRead : public OCLTestImp { + public: + OCLPerfUncoalescedRead(); + virtual ~OCLPerfUncoalescedRead(); + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + static const unsigned int NUM_ITER = 1000; + static const unsigned int SIZE = 250000; + static const char* kernel_str; + bool silentFailure; + float* input_buff; + void validate(void); +}; + +#endif // _OCL_UncoalescedRead_H_ diff --git a/opencl/tests/ocltst/module/perf/OCLPerfVerticalFetch.cpp b/opencl/tests/ocltst/module/perf/OCLPerfVerticalFetch.cpp new file mode 100644 index 0000000000..e035a5d6e1 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfVerticalFetch.cpp @@ -0,0 +1,353 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfVerticalFetch.h" + +#include +#include +#include + +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 1 +#define WIDTH 4952 +#define HEIGHT 3288 +unsigned int Sizes[NUM_SIZES] = {WIDTH * HEIGHT * 4}; + +#define KERNEL_CODE(...) #__VA_ARGS__ +const static char* strKernel = KERNEL_CODE( +\n __kernel void ResizeVerticalFilter( + const __global uint* inputImage, const unsigned int inputColumns, + const unsigned int inputRows, __local uint* inputImageCache, + const int numCachedPixels, __global uint* dst) { + const unsigned int startY = get_group_id(1) * get_local_size(1); + float scale = 0.5f; + const float support = 0.5f; + const int cacheRangeStartY = + max((int)((startY + 0.5f) / 1.0f + support + 0.5f), (int)(0)); + const int cacheRangeEndY = + min((int)(cacheRangeStartY + numCachedPixels), (int)inputRows); + const unsigned int x = get_global_id(0); + event_t e = async_work_group_strided_copy( + inputImageCache, inputImage + cacheRangeStartY * inputColumns + x, + cacheRangeEndY - cacheRangeStartY, inputColumns, 0); + wait_group_events(1, &e); + + if (get_local_id(1) == 0) { + // uint sum = 0; + // for (unsigned int chunk = 0; chunk < numCachedPixels; chunk++) { + // sum += inputImageCache[chunk]; + // } + atomic_add(dst, inputImageCache[0]); + } +} +\n); + +OCLPerfVerticalFetch::OCLPerfVerticalFetch() { + ptr_ = nullptr; + _numSubTests = 6; +} + +OCLPerfVerticalFetch::~OCLPerfVerticalFetch() {} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLPerfVerticalFetch::open(unsigned int test, char* units, + double& conversion, unsigned int deviceId) { + error_ = CL_SUCCESS; + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = 0; + kernel_ = 0; + skip_ = false; + dstBuffer_ = 0; + cl_ulong loopCnt = nBytes / (16 * sizeof(cl_uint)); + cl_uint maxCUs; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_MAX_COMPUTE_UNITS, + sizeof(cl_uint), &maxCUs, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + wgs = 64; + const static cl_uint wavesPerCU = 8; + nWorkItems = maxCUs * wavesPerCU * wgs; + uint32_t memLoc = CL_MEM_USE_HOST_PTR; + + inputData = 0x1; + switch (test) { + case 0: + nIter = 1; + mem_type_ = "UHP"; + break; + case 1: + nIter = 100; + mem_type_ = "UHP"; + break; + case 2: + nIter = 1; + memLoc = CL_MEM_ALLOC_HOST_PTR; + mem_type_ = "AHP"; + break; + case 3: + nIter = 100; + memLoc = CL_MEM_ALLOC_HOST_PTR; + mem_type_ = "AHP"; + break; + case 4: + nIter = 1; + memLoc = 0; + mem_type_ = "dev"; + break; + case 5: + nIter = 1000; + memLoc = 0; + mem_type_ = "dev"; + break; + } + + std::string nameFile("dim.ini"); + std::fstream is(nameFile.c_str(), std::fstream::in | std::fstream::binary); + std::string line; + if (is.is_open()) { + size_t posStart = 0; + do { + std::getline(is, line); + } while (line.find_first_of('/', posStart) != std::string::npos); + // Find global/local + posStart = 0; + size_t posEnd = 1; + std::string dimS = line.substr(posStart, posEnd - posStart); + dim = std::stoi(dimS.c_str(), nullptr, 10); + posStart = posEnd; + posEnd = line.find_first_of('[', posStart); + for (cl_uint i = 0; i < dim; ++i) { + posStart = posEnd + 1; + posEnd = line.find_first_of(',', posStart); + std::string global = line.substr(posStart, posEnd - posStart); + gws[i] = std::stoi(global.c_str(), nullptr, 10); + } + posEnd = line.find_first_of('[', posStart); + for (cl_uint i = 0; i < dim; ++i) { + posStart = posEnd + 1; + posEnd = line.find_first_of(',', posStart); + std::string global = line.substr(posStart, posEnd - posStart); + lws[i] = std::stoi(global.c_str(), nullptr, 10); + } + posEnd = line.find_first_of('[', posStart); + posStart = posEnd + 1; + posEnd = line.find_first_of(',', posStart); + std::string global = line.substr(posStart, posEnd - posStart); + numCachedPixels_ = std::stoi(global.c_str(), nullptr, 10); + is.close(); + } else { + dim = 2; + gws[0] = WIDTH; + gws[1] = 512; + lws[0] = 1; + lws[1] = 256; + numCachedPixels_ = 1676; + } + cl_uint width = static_cast(gws[0]); + cl_uint height = numCachedPixels_ * static_cast(gws[1] / lws[1]); + if (gws[1] > 512) { + gws[1] = 512; + } + Sizes[0] = width * height * sizeof(int); + nBytes = Sizes[0]; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "ResizeVerticalFilter", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + if (memLoc == CL_MEM_USE_HOST_PTR) { + ptr_ = malloc(nBytes); + } + srcBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY | memLoc, + nBytes, ptr_, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer(srcBuffer) failed"); + void* mem; + mem = _wrapper->clEnqueueMapBuffer(cmdQueues_[_deviceId], srcBuffer_, CL_TRUE, + CL_MAP_READ | CL_MAP_WRITE, 0, nBytes, 0, + NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + for (unsigned int i = 0; i < nBytes / sizeof(cl_uint); ++i) { + reinterpret_cast(mem)[i] = inputData; + } + + dstBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, + sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer(dstBuffer) failed"); + _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], srcBuffer_, mem, 0, + NULL, NULL); + mem = _wrapper->clEnqueueMapBuffer(cmdQueues_[_deviceId], dstBuffer_, CL_TRUE, + CL_MAP_READ | CL_MAP_WRITE, 0, + sizeof(cl_uint), 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memset(mem, 0, sizeof(cl_uint)); + _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], dstBuffer_, mem, 0, + NULL, NULL); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &srcBuffer_); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_uint), (void*)&width); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), (void*)&height); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 3, + numCachedPixels_ * sizeof(cl_uint), 0); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 4, sizeof(cl_uint), + (void*)&numCachedPixels_); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = + _wrapper->clSetKernelArg(kernel_, 5, sizeof(cl_mem), (void*)&dstBuffer_); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); +} + +void OCLPerfVerticalFetch::run(void) { + if (skip_) { + return; + } + + CPerfCounter timer; + + // warm up + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, dim, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + + cl_uint* memResult; + memResult = (cl_uint*)malloc(sizeof(cl_uint)); + if (0 == memResult) { + CHECK_RESULT_NO_RETURN(0, "malloc failed!\n"); + return; + } + + memset(memResult, 0, sizeof(cl_uint)); + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], dstBuffer_, + CL_FALSE, 0, sizeof(cl_uint), + memResult, 0, NULL, NULL); + + CHECK_RESULT(error_, "clEnqueueReadBuffer dstBuffer_ failed!"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + + if (memResult[0] != ((gws[0] * gws[1]) / (lws[0] * lws[1]))) { + CHECK_RESULT_NO_RETURN(0, "Data validation failed for warm up run!\n"); + // free(memResult); + // return; + } + + free(memResult); + + timer.Reset(); + timer.Start(); + double sec2 = 0; + cl_event* events = new cl_event[nIter]; + for (unsigned int i = 0; i < nIter; i++) { + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, dim, + NULL, gws, lws, 0, NULL, &events[i]); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + timer.Stop(); + for (unsigned int i = 0; i < nIter; i++) { + cl_ulong startTime = 0, endTime = 0; + error_ = _wrapper->clGetEventProfilingInfo( + events[i], CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &startTime, 0); + CHECK_RESULT(error_, "clGetEventProfilingInfo failed"); + error_ = _wrapper->clGetEventProfilingInfo( + events[i], CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &endTime, 0); + CHECK_RESULT(error_, "clGetEventProfilingInfo failed"); + + _wrapper->clReleaseEvent(events[i]); + sec2 += endTime - startTime; + } + double sec = timer.GetElapsedTime(); + delete[] events; + + // read speed in GB/s + double perf = ((double)nBytes * nIter * (double)(1e-09)) / sec; + double perf2 = ((double)nBytes * nIter) / sec2; + _perfInfo = (float)perf2; + float perfInfo = (float)perf; + char buf[256]; + SNPRINTF(buf, sizeof(buf), + " (%8d bytes, %s) i:%4d Wall time Perf: %.2f (GB/s)", nBytes, + mem_type_, nIter, perfInfo); + testDescString = buf; +} + +unsigned int OCLPerfVerticalFetch::close(void) { + if (!skip_) { + if (srcBuffer_) { + error_ = _wrapper->clReleaseMemObject(srcBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(srcBuffer_) failed"); + } + + if (dstBuffer_) { + error_ = _wrapper->clReleaseMemObject(dstBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(srcBuffer_) failed"); + } + } + if (ptr_ != nullptr) { + free(ptr_); + ptr_ = nullptr; + } + + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/perf/OCLPerfVerticalFetch.h b/opencl/tests/ocltst/module/perf/OCLPerfVerticalFetch.h new file mode 100644 index 0000000000..c010e9227c --- /dev/null +++ b/opencl/tests/ocltst/module/perf/OCLPerfVerticalFetch.h @@ -0,0 +1,49 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#pragma once +#include "OCLTestImp.h" + +class OCLPerfVerticalFetch : public OCLTestImp { + public: + OCLPerfVerticalFetch(); + virtual ~OCLPerfVerticalFetch(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + cl_mem srcBuffer_; + cl_mem dstBuffer_; + unsigned int nWorkItems; // number of GPU work items + unsigned int wgs; // work group size + unsigned int nBytes; // input and output buffer size + unsigned int nIter; // overall number of timing loops + cl_uint inputData; // input data to fill the input buffer + bool skip_; + void* ptr_; + const char* mem_type_; + cl_uint dim; + size_t gws[3]; + size_t lws[3]; + cl_uint numCachedPixels_; +}; diff --git a/opencl/tests/ocltst/module/perf/TestList.cpp b/opencl/tests/ocltst/module/perf/TestList.cpp new file mode 100644 index 0000000000..2d6ad75749 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/TestList.cpp @@ -0,0 +1,189 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLTestListImp.h" + +// +// Includes for tests +// +#include "OCLPerfAES256.h" +#include "OCLPerfAtomicSpeed.h" +#include "OCLPerfBufferCopyOverhead.h" +#include "OCLPerfBufferCopySpeed.h" +#include "OCLPerfBufferReadSpeed.h" +#include "OCLPerfBufferWriteSpeed.h" +#include "OCLPerfCPUMemSpeed.h" +#include "OCLPerfCommandQueue.h" +#include "OCLPerfConcurrency.h" +#include "OCLPerfDevMemReadSpeed.h" +#include "OCLPerfDevMemWriteSpeed.h" +#include "OCLPerfDeviceConcurrency.h" +#include "OCLPerfDeviceEnqueue.h" +#include "OCLPerfDispatchSpeed.h" +#include "OCLPerfDoubleDMA.h" +#include "OCLPerfDoubleDMASeq.h" +#include "OCLPerfFillBuffer.h" +#include "OCLPerfFillImage.h" +#include "OCLPerfFlush.h" +#include "OCLPerfGenericBandwidth.h" +#include "OCLPerfGenoilSiaMiner.h" +#include "OCLPerfImageCopyCorners.h" +#include "OCLPerfImageCopySpeed.h" +#include "OCLPerfImageMapUnmap.h" +#include "OCLPerfImageReadSpeed.h" +#include "OCLPerfImageSampleRate.h" +#include "OCLPerfImageWriteSpeed.h" +#include "OCLPerfKernelArguments.h" +#include "OCLPerfLDSLatency.h" +#include "OCLPerfLDSReadSpeed.h" +#include "OCLPerfMandelbrot.h" +#include "OCLPerfMapBufferReadSpeed.h" +#include "OCLPerfMapBufferWriteSpeed.h" +#include "OCLPerfMapImageReadSpeed.h" +#include "OCLPerfMapImageWriteSpeed.h" +#include "OCLPerfMatrixTranspose.h" +#include "OCLPerfMemCombine.h" +#include "OCLPerfMemCreate.h" +#include "OCLPerfMemLatency.h" +#include "OCLPerfPinnedBufferReadSpeed.h" +#include "OCLPerfPinnedBufferWriteSpeed.h" +#include "OCLPerfPipeCopySpeed.h" +#include "OCLPerfSHA256.h" +#include "OCLPerfSampleRate.h" +#include "OCLPerfScalarReplArrayElem.h" +#include "OCLPerfSdiP2PCopy.h" +#include "OCLPerfTextureMemLatency.h" +#include "OCLPerfUAVReadSpeed.h" +#include "OCLPerfUAVReadSpeedHostMem.h" +#include "OCLPerfUAVWriteSpeedHostMem.h" +#include "OCLPerfVerticalFetch.h" +// 2.0 +#include "OCLPerf3DImageWriteSpeed.h" +#include "OCLPerfAtomicSpeed20.h" +#include "OCLPerfDeviceEnqueue2.h" +#include "OCLPerfDeviceEnqueueEvent.h" +#include "OCLPerfDeviceEnqueueSier.h" +#include "OCLPerfImageCreate.h" +#include "OCLPerfImageReadWrite.h" +#include "OCLPerfImageReadsRGBA.h" +#include "OCLPerfProgramGlobalRead.h" +#include "OCLPerfProgramGlobalWrite.h" +#include "OCLPerfSVMAlloc.h" +#include "OCLPerfSVMKernelArguments.h" +#include "OCLPerfSVMMap.h" +#include "OCLPerfSVMMemFill.h" +#include "OCLPerfSVMMemcpy.h" +#include "OCLPerfSVMSampleRate.h" +#include "OCLPerfUncoalescedRead.h" + +// +// Helper macro for adding tests +// +template +static void* dictionary_CreateTestFunc(void) { + return new T(); +} + +#define TEST(name) \ + { #name, &dictionary_CreateTestFunc < name> } + +TestEntry TestList[] = { + TEST(OCLPerfUAVReadSpeed), + TEST(OCLPerfUAVReadSpeedHostMem), + TEST(OCLPerfUAVWriteSpeedHostMem), + TEST(OCLPerfLDSReadSpeed), + TEST(OCLPerfDispatchSpeed), + TEST(OCLPerfMapBufferReadSpeed), + TEST(OCLPerfMapBufferWriteSpeed), + TEST(OCLPerfBufferReadSpeed), + TEST(OCLPerfBufferReadRectSpeed), + TEST(OCLPerfPinnedBufferReadSpeed), + TEST(OCLPerfPinnedBufferReadRectSpeed), + TEST(OCLPerfBufferWriteSpeed), + TEST(OCLPerfBufferWriteRectSpeed), + TEST(OCLPerfPinnedBufferWriteSpeed), + TEST(OCLPerfPinnedBufferWriteRectSpeed), + TEST(OCLPerfBufferCopySpeed), + TEST(OCLPerfBufferCopyRectSpeed), + TEST(OCLPerfMapImageReadSpeed), + TEST(OCLPerfMapImageWriteSpeed), + TEST(OCLPerfMemCombine), + TEST(OCLPerfImageReadSpeed), + TEST(OCLPerfPinnedImageReadSpeed), + TEST(OCLPerfImageWriteSpeed), + TEST(OCLPerfPinnedImageWriteSpeed), + TEST(OCLPerfImageCopySpeed), + TEST(OCLPerfCPUMemSpeed), + TEST(OCLPerfMandelbrot), + TEST(OCLPerfAsyncMandelbrot), + TEST(OCLPerfConcurrency), + TEST(OCLPerfDeviceConcurrency), + TEST(OCLPerfAES256), + TEST(OCLPerfSHA256), + TEST(OCLPerfAtomicSpeed), + TEST(OCLPerfMatrixTranspose), + TEST(OCLPerfImageCopyCorners), + TEST(OCLPerfScalarReplArrayElem), + TEST(OCLPerfSdiP2PCopy), + TEST(OCLPerfFlush), + TEST(OCLPerfMemCreate), + TEST(OCLPerfImageMapUnmap), + TEST(OCLPerfCommandQueue), + TEST(OCLPerfKernelArguments), + TEST(OCLPerfDoubleDMA), + TEST(OCLPerfDoubleDMASeq), + TEST(OCLPerfMemLatency), + TEST(OCLPerfTextureMemLatency), + TEST(OCLPerfSampleRate), + TEST(OCLPerfImageSampleRate), + TEST(OCLPerfBufferCopyOverhead), + TEST(OCLPerfMapDispatchSpeed), + TEST(OCLPerfDeviceEnqueue), + TEST(OCLPerfPipeCopySpeed), + TEST(OCLPerfGenericBandwidth), + TEST(OCLPerfLDSLatency), + TEST(OCLPerfDeviceEnqueue2), + TEST(OCLPerfSVMAlloc), + TEST(OCLPerfSVMMap), + TEST(OCLPerfDeviceEnqueueEvent), + TEST(OCLPerfSVMKernelArguments), + TEST(OCLPerfDeviceEnqueueSier), + TEST(OCLPerfProgramGlobalRead), + TEST(OCLPerfProgramGlobalWrite), + TEST(OCLPerfAtomicSpeed20), + TEST(OCLPerfSVMSampleRate), + TEST(OCLPerfImageCreate), + TEST(OCLPerfImageReadsRGBA), + TEST(OCLPerf3DImageWriteSpeed), + TEST(OCLPerfImageReadWrite), + TEST(OCLPerfSVMMemcpy), + TEST(OCLPerfSVMMemFill), + TEST(OCLPerfFillBuffer), + TEST(OCLPerfFillImage), + TEST(OCLPerfUncoalescedRead), + TEST(OCLPerfGenoilSiaMiner), + TEST(OCLPerfDevMemReadSpeed), + TEST(OCLPerfDevMemWriteSpeed), + TEST(OCLPerfVerticalFetch), +}; + +unsigned int TestListCount = sizeof(TestList) / sizeof(TestList[0]); +unsigned int TestLibVersion = 0; +const char* TestLibName = "oclperf"; diff --git a/opencl/tests/ocltst/module/perf/oclperf.exclude b/opencl/tests/ocltst/module/perf/oclperf.exclude new file mode 100644 index 0000000000..17d99c4244 --- /dev/null +++ b/opencl/tests/ocltst/module/perf/oclperf.exclude @@ -0,0 +1,28 @@ +# We don't need to run regressions on these tests, they are purely for performance testing and debugging +OCLPerfMemLatency +OCLPerfTextureMemLatency +OCLPerfSampleRate +OCLPerfImageSampleRate +OCLPerfBufferCopyOverhead +OCLPerfDeviceEnqueue +OCLPerfPipeCopySpeed +OCLPerfGenericBandwidth +OCLPerfLDSLatency +OCLPerfFillBuffer +OCLPerfDeviceEnqueue2 +OCLPerfDeviceEnqueueEvent +OCLPerfDeviceEnqueueSier +OCLPerfSVMAlloc +OCLPerfSVMMap +OCLPerfSVMKernelArguments +OCLPerfProgramGlobalRead +OCLPerfProgramGlobalWrite +OCLPerfAtomicSpeed20 +OCLPerfSVMSampleRate +OCLPerfImageCreate +OCLPerfImageReadsRGBA +OCLPerf3DImageWriteSpeed +OCLPerfImageReadWrite +OCLPerfSVMMemcpy +OCLPerfSVMMemFill +OCLPerfFillImage diff --git a/opencl/tests/ocltst/module/runtime/CMakeLists.txt b/opencl/tests/ocltst/module/runtime/CMakeLists.txt new file mode 100644 index 0000000000..0b5de94176 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/CMakeLists.txt @@ -0,0 +1,105 @@ +set(TESTS + OCLAsyncMap + OCLAsyncTransfer + OCLAtomicCounter + OCLBlitKernel + OCLBufferFromImage + OCLCPUGuardPages + OCLCreateBuffer + OCLCreateContext + OCLCreateImage + OCLDeviceAtomic + OCLDeviceQueries + OCLDynamic + OCLDynamicBLines + OCLGenericAddressSpace + OCLGetQueueThreadID + OCLGlobalOffset + OCLImage2DFromBuffer + OCLImageCopyPartial + OCLKernelBinary + OCLLDS32K + OCLLinearFilter + OCLMapCount + OCLMemDependency + OCLMemObjs + OCLMemoryInfo + OCLMultiQueue + OCLOfflineCompilation + OCLP2PBuffer + OCLPartialWrkgrp + OCLPerfCounters + OCLPersistent + OCLPinnedMemory + OCLPlatformAtomics + OCLProgramScopeVariables + OCLReadWriteImage + OCLRTQueue + OCLSDI + OCLSemaphore + OCLStablePState + OCLSVM + OCLThreadTrace + OCLUnalignedCopy +) + +add_library(oclruntime SHARED + TestList.cpp + $) + +foreach(TEST ${TESTS}) + target_sources(oclruntime + PRIVATE + ${TEST}.cpp) +endforeach() + +set_target_properties(oclruntime PROPERTIES + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests/ocltst + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests/ocltst) + +target_compile_definitions(oclruntime + PRIVATE + $) + +target_include_directories(oclruntime + PRIVATE + $) + +target_link_libraries(oclruntime + PRIVATE + OpenCL) + +add_custom_command( + TARGET oclruntime POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/oclruntime.exclude + ${CMAKE_BINARY_DIR}/tests/ocltst/oclruntime.exclude) + +add_custom_target(test.ocltst.oclruntime + COMMAND + ${CMAKE_COMMAND} -E env "OCL_ICD_FILENAMES=$" + $ -p 0 -m $ -A oclruntime.exclude + DEPENDS + ocltst oclruntime amdocl + WORKING_DIRECTORY + ${CMAKE_BINARY_DIR}/tests/ocltst + USES_TERMINAL) + +foreach(TEST ${TESTS}) + add_custom_target(test.ocltst.oclruntime.${TEST} + COMMAND + ${CMAKE_COMMAND} -E env "OCL_ICD_FILENAMES=$" + $ -p 0 -m $ -t ${TEST} + DEPENDS + ocltst oclruntime amdocl + WORKING_DIRECTORY + ${CMAKE_BINARY_DIR}/tests/ocltst + USES_TERMINAL) +endforeach() + +INSTALL(TARGETS oclruntime DESTINATION ${OCLTST_INSTALL_DIR} COMPONENT ocltst) +INSTALL(FILES oclruntime.exclude DESTINATION ${OCLTST_INSTALL_DIR} COMPONENT ocltst) + diff --git a/opencl/tests/ocltst/module/runtime/OCLAsyncMap.cpp b/opencl/tests/ocltst/module/runtime/OCLAsyncMap.cpp new file mode 100644 index 0000000000..77cb5c7b3d --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLAsyncMap.cpp @@ -0,0 +1,104 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLAsyncMap.h" + +#include +#include +#include +#include + +#include "CL/cl.h" + +#if EMU_ENV +static const size_t BufSize = 0x800; +static const size_t MapRegion = 0x100; +#else +static const size_t BufSize = 0x800000; +static const size_t MapRegion = 0x100000; +#endif // EMU_ENV + +static const unsigned int NumMaps = BufSize / MapRegion; + +OCLAsyncMap::OCLAsyncMap() { _numSubTests = 1; } + +OCLAsyncMap::~OCLAsyncMap() {} + +void OCLAsyncMap::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + cl_mem buffer; + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + BufSize * sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLAsyncMap::run(void) { + cl_uint* values[NumMaps]; + cl_mem mapBuffer = buffers()[0]; + size_t offset = 0; + size_t region = MapRegion * sizeof(cl_uint); + + for (unsigned int i = 0; i < NumMaps; ++i) { + values[i] = reinterpret_cast(_wrapper->clEnqueueMapBuffer( + cmdQueues_[_deviceId], mapBuffer, CL_TRUE, (CL_MAP_READ | CL_MAP_WRITE), + offset, region, 0, NULL, NULL, &error_)); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueMapBuffer() failed"); + offset += region; + } + + for (unsigned int i = 0; i < NumMaps; ++i) { + for (unsigned int j = 0; j < MapRegion; ++j) { + values[i][j] = i; + } + } + + for (unsigned int i = 0; i < NumMaps; ++i) { + error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], mapBuffer, + values[i], 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueMapBuffer() failed"); + } + + values[0] = reinterpret_cast(_wrapper->clEnqueueMapBuffer( + cmdQueues_[_deviceId], mapBuffer, CL_TRUE, CL_MAP_READ, 0, + BufSize * sizeof(cl_uint), 0, NULL, NULL, &error_)); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueMapBuffer() failed"); + + for (unsigned int i = 0; i < NumMaps; ++i) { + values[i] = values[0] + i * MapRegion; + for (unsigned int j = 0; j < MapRegion; ++j) { + CHECK_RESULT((values[i][j] != i), "validation failed"); + } + } + + error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], mapBuffer, + values[0], 0, NULL, NULL); + + _wrapper->clFinish(cmdQueues_[_deviceId]); +} + +unsigned int OCLAsyncMap::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLAsyncMap.h b/opencl/tests/ocltst/module/runtime/OCLAsyncMap.h new file mode 100644 index 0000000000..ca8ef994f0 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLAsyncMap.h @@ -0,0 +1,38 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ASYNC_MAP_H_ +#define _OCL_ASYNC_MAP_H_ + +#include "OCLTestImp.h" + +class OCLAsyncMap : public OCLTestImp { + public: + OCLAsyncMap(); + virtual ~OCLAsyncMap(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); +}; + +#endif // _OCL_ASYNC_MAP_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLAsyncTransfer.cpp b/opencl/tests/ocltst/module/runtime/OCLAsyncTransfer.cpp new file mode 100644 index 0000000000..4d07891939 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLAsyncTransfer.cpp @@ -0,0 +1,150 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLAsyncTransfer.h" + +#include +#include +#include +#include + +#include "CL/cl.h" + +#if EMU_ENV +static const size_t Iterations = 1; +static const size_t IterationDivider = 1; +static const size_t BufSize = 10; +#else +static const size_t Iterations = 0x100; +static const size_t IterationDivider = 2; +static const size_t BufSize = 0x800000; +#endif // EMU_ENV + +static const size_t MaxBuffers = IterationDivider; + +const static char* strKernel = + "__kernel void factorial(__global uint* out) \n" + "{ \n" + " uint id = get_global_id(0); \n" + " uint factorial = 1; \n" +#if EMU_ENV + " for (uint i = 1; i < id; ++i) \n" +#else + " for (uint i = 1; i < (id / 0x10000); ++i) \n" +#endif // EMU_ENV + " { \n" + " factorial *= i; \n" + " } \n" + " out[id] = factorial; \n" + "} \n"; + +OCLAsyncTransfer::OCLAsyncTransfer() { _numSubTests = 1; } + +OCLAsyncTransfer::~OCLAsyncTransfer() {} + +void OCLAsyncTransfer::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "factorial", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + for (size_t i = 0; i < MaxBuffers; ++i) { + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + BufSize * sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + } + + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_ALLOC_HOST_PTR, + BufSize * sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLAsyncTransfer::run(void) { + void* values; + CPerfCounter timer; + cl_mem mapBuffer = buffers()[MaxBuffers]; + + values = _wrapper->clEnqueueMapBuffer( + cmdQueues_[_deviceId], mapBuffer, true, (CL_MAP_READ | CL_MAP_WRITE), 0, + BufSize * sizeof(cl_uint), 0, NULL, NULL, &error_); + + timer.Reset(); + timer.Start(); + size_t x; + for (x = 0; x < Iterations / IterationDivider; x++) { + for (size_t y = 0; y < IterationDivider; ++y) { + cl_mem buffer = buffers()[y]; + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t gws[1] = {BufSize}; + error_ = _wrapper->clEnqueueNDRangeKernel( + cmdQueues_[_deviceId], kernel_, 1, NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + + cl_mem readBuffer = buffers()[0]; + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], readBuffer, + false, 0, BufSize * sizeof(cl_uint), + values, 0, NULL, NULL); + _wrapper->clFlush(cmdQueues_[_deviceId]); + + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + timer.Stop(); + + double sec = timer.GetElapsedTime(); + // Buffer read bandwidth in GB/s + double perf = ((double)BufSize * sizeof(cl_uint) * x * (double)(1e-09)) / sec; + + printf(" Time: %.2f sec, BW: %.2f GB/s ", sec, perf); + + error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], mapBuffer, + values, 0, NULL, NULL); + _wrapper->clFinish(cmdQueues_[_deviceId]); +} + +unsigned int OCLAsyncTransfer::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLAsyncTransfer.h b/opencl/tests/ocltst/module/runtime/OCLAsyncTransfer.h new file mode 100644 index 0000000000..5c30b55a7b --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLAsyncTransfer.h @@ -0,0 +1,38 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ASYNC_TRANSFER_H_ +#define _OCL_ASYNC_TRANSFER_H_ + +#include "OCLTestImp.h" + +class OCLAsyncTransfer : public OCLTestImp { + public: + OCLAsyncTransfer(); + virtual ~OCLAsyncTransfer(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); +}; + +#endif // _OCL_ASYNC_TRANSFER_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLAtomicCounter.cpp b/opencl/tests/ocltst/module/runtime/OCLAtomicCounter.cpp new file mode 100644 index 0000000000..8bcf99829a --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLAtomicCounter.cpp @@ -0,0 +1,168 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLAtomicCounter.h" + +#include +#include +#include + +#include "CL/cl.h" + +const static unsigned int MaxCounters = 2; +const static char* strKernel = + "#pragma OPENCL EXTENSION cl_ext_atomic_counters_32 : enable \n" + "__kernel void atomic_test( \n" + " counter32_t counter0, counter32_t counter1, global uint* out_val) \n" + "{ \n" + " if (!get_global_id(0)) { \n" + " uint val0 = atomic_inc(counter0); \n" + " uint val1 = atomic_dec(counter1); \n" + " out_val[0] = val0; \n" + " out_val[1] = val1; \n" + " } \n" + "} \n"; + +OCLAtomicCounter::OCLAtomicCounter() { + _numSubTests = 1; + failed_ = false; +} + +OCLAtomicCounter::~OCLAtomicCounter() {} + +void OCLAtomicCounter::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening"); + + char name[1024] = {0}; + size_t size = 0; + + if (deviceId >= deviceCount_) { + failed_ = true; + return; + } + + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_EXTENSIONS, 1024, + name, &size); + if (!strstr(name, "cl_ext_atomic_counter")) { + printf("Atomic counter extension is required for this test!\n"); + failed_ = true; + return; + } + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], "-legacy", + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "atomic_test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + for (unsigned int i = 0; i < MaxCounters; ++i) { + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + } + + buffer = + _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + MaxCounters * sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLAtomicCounter::run(void) { + if (failed_) { + return; + } + cl_uint initVal[2] = {5, 10}; + for (unsigned int i = 0; i < MaxCounters; ++i) { + error_ = _wrapper->clEnqueueWriteBuffer(cmdQueues_[_deviceId], buffers()[i], + true, 0, sizeof(cl_uint), + &initVal[i], 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + } + + for (unsigned int i = 0; i < MaxCounters + 1; ++i) { + cl_mem buffer = buffers()[i]; + error_ = _wrapper->clSetKernelArg(kernel_, i, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + } + + size_t gws[1] = {64}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + cl_uint outputV[MaxCounters] = {0}; + + // Find the new counter value + initVal[0]++; + initVal[1]--; + + for (unsigned int i = 0; i < MaxCounters; ++i) { + cl_mem buffer = buffers()[i]; + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers()[i], + true, 0, sizeof(cl_uint), + &outputV[i], 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + if (initVal[i] != outputV[i]) { + printf("%d != %d", initVal[i], outputV[i]); + CHECK_RESULT(true, " - Incorrect result for counter!\n"); + } + } + + // Restore the original value to check the returned result in the kernel + initVal[0]--; + initVal[1]++; + + cl_mem buffer = buffers()[MaxCounters]; + error_ = _wrapper->clEnqueueReadBuffer( + cmdQueues_[_deviceId], buffers()[MaxCounters], true, 0, + MaxCounters * sizeof(cl_uint), outputV, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + for (unsigned int i = 0; i < MaxCounters; ++i) { + if (initVal[i] != outputV[i]) { + printf("%d != %d", initVal[i], outputV[i]); + CHECK_RESULT(true, + " - Incorrect result for counter inside kernel. Returned " + "value != original.\n"); + } + } +} + +unsigned int OCLAtomicCounter::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLAtomicCounter.h b/opencl/tests/ocltst/module/runtime/OCLAtomicCounter.h new file mode 100644 index 0000000000..d44119cf95 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLAtomicCounter.h @@ -0,0 +1,41 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ATOMIC_COUNTER_H_ +#define _OCL_ATOMIC_COUNTER_H_ + +#include "OCLTestImp.h" + +class OCLAtomicCounter : public OCLTestImp { + public: + OCLAtomicCounter(); + virtual ~OCLAtomicCounter(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; +}; + +#endif // _OCL_ATOMIC_COUNTER_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLBlitKernel.cpp b/opencl/tests/ocltst/module/runtime/OCLBlitKernel.cpp new file mode 100644 index 0000000000..a76cec2d4d --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLBlitKernel.cpp @@ -0,0 +1,612 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLBlitKernel.h" + +#include +#include +#include +#include + +#include "CL/cl.h" + +const static cl_uint Stages = 4; +const static cl_uint ThreadsForCheck = 1 << Stages; + +#define KERNEL_CODE(...) #__VA_ARGS__ + +const static char* strKernel = + KERNEL_CODE( + \n + \x23 if OCL20 + \n + extern void __amd_scheduler(__global void *, __global void *, uint); + \n + \x23 endif + \n + extern void __amd_copyBufferToImage( + __global uint*, __write_only image2d_array_t, ulong4, + int4, int4, uint4, ulong4); + + extern void __amd_copyImageToBuffer( + __read_only image2d_array_t, __global uint*, __global ushort*, + __global uchar*, int4, ulong4, int4, uint4, ulong4); + + extern void __amd_copyImage( + __read_only image2d_array_t, __write_only image2d_array_t, + int4, int4, int4); + + extern void __amd_copyImage1DA( + __read_only image2d_array_t, __write_only image2d_array_t, + int4, int4, int4); + + extern void __amd_copyBufferRect( + __global uchar*, __global uchar*, + ulong4, ulong4, ulong4); + + extern void __amd_copyBufferRectAligned( + __global uint*, __global uint*, + ulong4, ulong4, ulong4); + + extern void __amd_copyBuffer( + __global uchar*, __global uchar*, + ulong, ulong, ulong, uint); + + extern void __amd_copyBufferAligned( + __global uint*, __global uint*, + ulong, ulong, ulong, uint); + + extern void __amd_fillBuffer( + __global uchar*, __global uint*, __constant uchar*, + uint, ulong, ulong); + + extern void __amd_fillImage( + __write_only image2d_array_t, + float4, int4, uint4, int4, int4, uint); + + __kernel void copyBufferToImage( + __global uint* src, + __write_only image2d_array_t dst, + ulong4 srcOrigin, + int4 dstOrigin, + int4 size, + uint4 format, + ulong4 pitch) + { + __amd_copyBufferToImage(src, dst, srcOrigin, dstOrigin, size, format, pitch); + } + + __kernel void copyImageToBuffer( + __read_only image2d_array_t src, + __global uint* dstUInt, + __global ushort* dstUShort, + __global uchar* dstUChar, + int4 srcOrigin, + ulong4 dstOrigin, + int4 size, + uint4 format, + ulong4 pitch) + { + __amd_copyImageToBuffer(src, dstUInt, dstUShort, dstUChar, + srcOrigin, dstOrigin, size, format, pitch); + } + + __kernel void copyImage( + __read_only image2d_array_t src, + __write_only image2d_array_t dst, + int4 srcOrigin, + int4 dstOrigin, + int4 size) + { + __amd_copyImage(src, dst, srcOrigin, dstOrigin, size); + } + + __kernel void copyImage1DA( + __read_only image2d_array_t src, + __write_only image2d_array_t dst, + int4 srcOrigin, + int4 dstOrigin, + int4 size) + { + __amd_copyImage1DA(src, dst, srcOrigin, dstOrigin, size); + } + + __kernel void copyBufferRect( + __global uchar* src, + __global uchar* dst, + ulong4 srcRect, + ulong4 dstRect, + ulong4 size) + { + __amd_copyBufferRect(src, dst, srcRect, dstRect, size); + } + + __kernel void copyBufferRectAligned( + __global uint* src, + __global uint* dst, + ulong4 srcRect, + ulong4 dstRect, + ulong4 size) + { + __amd_copyBufferRectAligned(src, dst, srcRect, dstRect, size); + } + + __kernel void copyBuffer( + __global uchar* srcI, + __global uchar* dstI, + ulong srcOrigin, + ulong dstOrigin, + ulong size, + uint remain) + { + __amd_copyBuffer(srcI, dstI, srcOrigin, dstOrigin, size, remain); + } + + __kernel void copyBufferAligned( + __global uint* src, + __global uint* dst, + ulong srcOrigin, + ulong dstOrigin, + ulong size, + uint alignment) + { + __amd_copyBufferAligned(src, dst, srcOrigin, dstOrigin, size, alignment); + } + + __kernel void fillBuffer( + __global uchar* bufUChar, + __global uint* bufUInt, + __constant uchar* pattern, + uint patternSize, + ulong offset, + ulong size) + { + __amd_fillBuffer(bufUChar, bufUInt, pattern, patternSize, offset, size); + } + + __kernel void fillImage( + __write_only image2d_array_t image, + float4 patternFLOAT4, + int4 patternINT4, + uint4 patternUINT4, + int4 origin, + int4 size, + uint type) + { + __amd_fillImage(image, patternFLOAT4, patternINT4, patternUINT4, + origin, size, type); + } + \n + \x23 if OCL20 + \n + typedef struct _HsaAqlDispatchPacket { + uint mix; + ushort workgroup_size[3]; + ushort reserved2; + uint grid_size[3]; + uint private_segment_size_bytes; + uint group_segment_size_bytes; + ulong kernel_object_address; + ulong kernel_arg_address; + ulong reserved3; + ulong completion_signal; + } HsaAqlDispatchPacket; + \n + // This is an OpenCLized hsa_control_directives_t + typedef struct _AmdControlDirectives { + ulong enabled_control_directives; + ushort enable_break_exceptions; + ushort enable_detect_exceptions; + uint max_dynamic_group_size; + ulong max_flat_grid_size; + uint max_flat_workgroup_size; + uchar required_dim; + uchar reserved1[3]; + ulong required_grid_size[3]; + uint required_workgroup_size[3]; + uchar reserved2[60]; + } AmdControlDirectives; + \n + // This is an OpenCLized amd_kernel_code_t + typedef struct _AmdKernelCode { + uint amd_kernel_code_version_major; + uint amd_kernel_code_version_minor; + ushort amd_machine_kind; + ushort amd_machine_version_major; + ushort amd_machine_version_minor; + ushort amd_machine_version_stepping; + long kernel_code_entry_byte_offset; + long kernel_code_prefetch_byte_offset; + ulong kernel_code_prefetch_byte_size; + ulong max_scratch_backing_memory_byte_size; + uint compute_pgm_rsrc1; + uint compute_pgm_rsrc2; + uint kernel_code_properties; + uint workitem_private_segment_byte_size; + uint workgroup_group_segment_byte_size; + uint gds_segment_byte_size; + ulong kernarg_segment_byte_size; + uint workgroup_fbarrier_count; + ushort wavefront_sgpr_count; + ushort workitem_vgpr_count; + ushort reserved_vgpr_first; + ushort reserved_vgpr_count; + ushort reserved_sgpr_first; + ushort reserved_sgpr_count; + ushort debug_wavefront_private_segment_offset_sgpr; + ushort debug_private_segment_buffer_sgpr; + uchar kernarg_segment_alignment; + uchar group_segment_alignment; + uchar private_segment_alignment; + uchar wavefront_size; + int call_convention; + uchar reserved1[12]; + ulong runtime_loader_kernel_symbol; + AmdControlDirectives control_directives; + } AmdKernelCode; + \n + typedef struct _HwDispatchHeader { + uint writeData0; // CP WRITE_DATA write to rewind for memory + uint writeData1; + uint writeData2; + uint writeData3; + uint rewind; // REWIND execution + uint startExe; // valid bit + uint condExe0; // 0xC0032200 -- TYPE 3, COND_EXEC + uint condExe1; // 0x00000204 ---- + uint condExe2; // 0x00000000 ---- + uint condExe3; // 0x00000000 ---- + uint condExe4; // 0x00000000 ---- + } HwDispatchHeader; + \n + typedef struct _HwDispatch { + uint packet0; // 0xC0067602 -- TYPE 3, SET_SH_REG, TYPE:COMPUTE (6 values) + uint offset0; // 0x00000204 ---- OFFSET + uint startX; // 0x00000000 ---- COMPUTE_START_X: START = 0x0 + uint startY; // 0x00000000 ---- COMPUTE_START_Y: START = 0x0 + uint startZ; // 0x00000000 ---- COMPUTE_START_Z: START = 0x0 + uint wrkGrpSizeX; // 0x00000000 ---- COMPUTE_NUM_THREAD_X: NUM_THREAD_FULL = 0x0, NUM_THREAD_PARTIAL = 0x0 + uint wrkGrpSizeY; // 0x00000000 ---- COMPUTE_NUM_THREAD_Y: NUM_THREAD_FULL = 0x0, NUM_THREAD_PARTIAL = 0x0 + uint wrkGrpSizeZ; // 0x00000000 ---- COMPUTE_NUM_THREAD_Z: NUM_THREAD_FULL = 0x0, NUM_THREAD_PARTIAL = 0x0 + uint packet1; // 0xC0027602 -- TYPE 3, SET_SH_REG, TYPE:COMPUTE (2 values) + uint offset1; // 0x0000020C ---- OFFSET + uint isaLo; // 0x00000000 ---- COMPUTE_PGM_LO: DATA = 0x0 + uint isaHi; // 0x00000000 ---- COMPUTE_PGM_HI: DATA = 0x0, INST_ATC__CI__VI = 0x0 + uint packet2; // 0xC0027602 -- TYPE 3, SET_SH_REG, TYPE:COMPUTE (2 values) + uint offset2; // 0x00000212 ---- OFFSET + uint resource1; // 0x00000000 ---- COMPUTE_PGM_RSRC1 + uint resource2; // 0x00000000 ---- COMPUTE_PGM_RSRC2 + uint packet3; // 0xc0017602 -- TYPE 3, SET_SH_REG, TYPE:COMPUTE (1 value) + uint offset3; // 0x00000215 ---- OFFSET + uint pad31; // 0x000003ff ---- COMPUTE_RESOURCE_LIMITS + uint packet31; // 0xC0067602 -- TYPE 3, SET_SH_REG, TYPE:COMPUTE (1 value) + uint offset31; // 0x00000218 ---- OFFSET + uint ringSize; // 0x00000000 ---- COMPUTE_TMPRING_SIZE: WAVES = 0x0, WAVESIZE = 0x0 + uint user0; // 0xC0047602 -- TYPE 3, SET_SH_REG, TYPE:COMPUTE (4 values) + uint offsUser0; // 0x00000240 ---- OFFSET + uint scratchLo; // 0x00000000 ---- COMPUTE_USER_DATA_0: DATA = 0x0 + uint scratchHi; // 0x80000000 ---- COMPUTE_USER_DATA_1: DATA = 0x80000000 + uint scratchSize; // 0x00000000 ---- COMPUTE_USER_DATA_2: DATA = 0x0 + uint padUser; // 0x00EA7FAC ---- COMPUTE_USER_DATA_3: DATA = 0xEA7FAC + uint user1; // 0xC0027602 -- TYPE 3, SET_SH_REG, TYPE:COMPUTE (2 values) + uint offsUser1; // 0x00000244 ---- OFFSET + uint aqlPtrLo; // 0x00000000 ---- COMPUTE_USER_DATA_4: DATA = 0x0 + uint aqlPtrHi; // 0x00000000 ---- COMPUTE_USER_DATA_5: DATA = 0x0 + uint user2; // 0xC0027602 -- TYPE 3, SET_SH_REG, TYPE:COMPUTE (2 values) + uint offsUser2; // 0x00000246 ---- OFFSET + uint hsaQueueLo; // 0x00000000 ---- COMPUTE_USER_DATA_6: DATA = 0x0 + uint hsaQueueHi; // 0x00000000 ---- COMPUTE_USER_DATA_7: DATA = 0x0 + uint user3; // 0xC0027602 -- TYPE 3, SET_SH_REG, TYPE:COMPUTE (2 values) + uint offsUser3; // 0x00000246 ---- OFFSET + uint argsLo; // 0x00000000 ---- COMPUTE_USER_DATA_8: DATA = 0x0 + uint argsHi; // 0x00000000 ---- COMPUTE_USER_DATA_9: DATA = 0x0 + uint copyData; // 0xC0044000 -- TYPE 3, COPY_DATA + uint copyDataFlags; // 0x00000405 ---- srcSel 0x5, destSel 0x4, countSel 0x0, wrConfirm 0x0, engineSel 0x0 + uint scratchAddrLo; // 0x000201C4 ---- srcAddressLo + uint scratchAddrHi; // 0x00000000 ---- srcAddressHi + uint shPrivateLo; // 0x00002580 ---- dstAddressLo + uint shPrivateHi; // 0x00000000 ---- dstAddressHi + uint user4; // 0xC0027602 -- TYPE 3, SET_SH_REG, TYPE:COMPUTE (2 values) + uint offsUser4; // 0x00000248 ---- OFFSET + uint scratchOffs; // 0x00000000 ---- COMPUTE_USER_DATA_10: DATA = 0x0 + uint privSize; // 0x00000030 ---- COMPUTE_USER_DATA_11: DATA = 0x30 + uint packet4; // 0xC0031502 -- TYPE 3, DISPATCH_DIRECT, TYPE:COMPUTE + uint glbSizeX; // 0x00000000 + uint glbSizeY; // 0x00000000 + uint glbSizeZ; // 0x00000000 + uint padd41; // 0x00000021 + } HwDispatch; + \n + static const uint WavefrontSize = 64; + static const uint MaxWaveSize = 0x400; + static const uint UsrRegOffset = 0x240; + static const uint Pm4Nop = 0xC0001002; + static const uint Pm4UserRegs = 0xC0007602; + static const uint Pm4CopyReg = 0xC0044000; + static const uint PrivateSegEna = 0x1; + static const uint DispatchEna = 0x2; + static const uint QueuePtrEna = 0x4; + static const uint KernelArgEna = 0x8; + static const uint FlatScratchEna = 0x20; + \n + uint GetCmdTemplateHeaderSize() { return sizeof(HwDispatchHeader); } + \n + uint GetCmdTemplateDispatchSize() { return sizeof(HwDispatch); } + \n + void EmptyCmdTemplateDispatch(ulong cmdBuf) + { + volatile __global HwDispatch* dispatch = (volatile __global HwDispatch*)cmdBuf; + dispatch->glbSizeX = 0; + dispatch->glbSizeY = 0; + dispatch->glbSizeZ = 0; + } + \n + void RunCmdTemplateDispatch( + ulong cmdBuf, + __global HsaAqlDispatchPacket* aqlPkt, + ulong scratch, + ulong hsaQueue, + uint scratchSize, + uint scratchOffset, + uint numMaxWaves, + uint useATC) + \n + { + volatile __global HwDispatch* dispatch = (volatile __global HwDispatch*)cmdBuf; + uint usrRegCnt = 0; + + // Program workgroup size + dispatch->wrkGrpSizeX = aqlPkt->workgroup_size[0]; + dispatch->wrkGrpSizeY = aqlPkt->workgroup_size[1]; + dispatch->wrkGrpSizeZ = aqlPkt->workgroup_size[2]; + + // ISA address + __global AmdKernelCode* kernelObj = (__global AmdKernelCode*)aqlPkt->kernel_object_address; + ulong isa = aqlPkt->kernel_object_address + kernelObj->kernel_code_entry_byte_offset; + + dispatch->isaLo = (uint)(isa >> 8); + dispatch->isaHi = (uint)(isa >> 40) | (useATC ? 0x100 : 0); + + // Program PGM resource registers + dispatch->resource1 = kernelObj->compute_pgm_rsrc1; + dispatch->resource2 = kernelObj->compute_pgm_rsrc2; + + uint flags = kernelObj->kernel_code_properties; + uint privateSize = kernelObj->workitem_private_segment_byte_size; + + uint ldsSize = aqlPkt->group_segment_size_bytes + + kernelObj->workgroup_group_segment_byte_size; + + // Align up the LDS blocks 128 * 4(in DWORDs) + uint ldsBlocks = (ldsSize + 511) >> 9; + + dispatch->resource2 |= (ldsBlocks << 15); + + // Private/scratch segment was enabled + if (flags & PrivateSegEna) { + uint waveSize = privateSize * WavefrontSize; + // 256 DWRODs is the minimum for SQ + waveSize = max(MaxWaveSize, waveSize); + + uint numWaves = scratchSize / waveSize; + + numWaves = min(numWaves, numMaxWaves); + + dispatch->ringSize = numWaves; + dispatch->ringSize |= (waveSize >> 10) << 12; + dispatch->user0 = Pm4UserRegs | (4 << 16); + dispatch->scratchLo = (uint)scratch; + dispatch->scratchHi = ((uint)(scratch >> 32)) | 0x80000000; // Enables swizzle + dispatch->scratchSize = scratchSize; + usrRegCnt += 4; + } + else { + dispatch->ringSize = 0; + dispatch->user0 = Pm4Nop | (4 << 16); + } + + // Pointer to the AQL dispatch packet + dispatch->user1 = (flags & DispatchEna) ? (Pm4UserRegs | (2 << 16)) : (Pm4Nop | (2 << 16)); + dispatch->offsUser1 = UsrRegOffset + usrRegCnt; + usrRegCnt += (flags & DispatchEna) ? 2 : 0; + ulong gpuAqlPtr = (ulong)aqlPkt; + dispatch->aqlPtrLo = (uint)gpuAqlPtr; + dispatch->aqlPtrHi = (uint)(gpuAqlPtr >> 32); + + // Pointer to the AQL queue header + if (flags & QueuePtrEna) { + dispatch->user2 = Pm4UserRegs | (2 << 16); + dispatch->offsUser2 = UsrRegOffset + usrRegCnt; + usrRegCnt += 2; + dispatch->hsaQueueLo = (uint)hsaQueue; + dispatch->hsaQueueHi = (uint)(hsaQueue >> 32); + } + else { + dispatch->user2 = Pm4Nop | (2 << 16); + } + + // Pointer to the AQL kernel arguments + dispatch->user3 = (flags & KernelArgEna) ? (Pm4UserRegs | (2 << 16)) : (Pm4Nop | (2 << 16)); + dispatch->offsUser3 = UsrRegOffset + usrRegCnt; + usrRegCnt += (flags & KernelArgEna) ? 2 : 0; + dispatch->argsLo = (uint)aqlPkt->kernel_arg_address; + dispatch->argsHi = (uint)(aqlPkt->kernel_arg_address >> 32); + + // Provide pointer to the private/scratch buffer for the flat address + if (flags & FlatScratchEna) { + dispatch->copyData = Pm4CopyReg; + dispatch->scratchAddrLo = (uint)((scratch - scratchOffset) >> 16); + dispatch->offsUser4 = UsrRegOffset + usrRegCnt; + dispatch->scratchOffs = scratchOffset; + dispatch->privSize = privateSize; + } + else { + dispatch->copyData = Pm4Nop | (8 << 16); + } + + // Update the global launch grid + dispatch->glbSizeX = aqlPkt->grid_size[0]; + dispatch->glbSizeY = aqlPkt->grid_size[1]; + dispatch->glbSizeZ = aqlPkt->grid_size[2]; + } + \n + __kernel void scheduler( + __global void * queue, + __global void * params, + uint paramIdx) + { + __amd_scheduler(queue, params, paramIdx); + } + \n + \x23 endif + \n + ); + +enum { + BlitCopyImage = 0, + BlitCopyImage1DA, + BlitCopyImageToBuffer, + BlitCopyBufferToImage, + BlitCopyBufferRect, + BlitCopyBufferRectAligned, + BlitCopyBuffer, + BlitCopyBufferAligned, + FillBuffer, + FillImage, + Scheduler, + BlitTotal +}; + +static const char* BlitName[BlitTotal] = { + "copyImage", "copyImage1DA", "copyImageToBuffer", + "copyBufferToImage", "copyBufferRect", "copyBufferRectAligned", + "copyBuffer", "copyBufferAligned", "fillBuffer", + "fillImage", "scheduler", +}; + +OCLBlitKernel::OCLBlitKernel() { _numSubTests = 1; } + +OCLBlitKernel::~OCLBlitKernel() {} + +void OCLBlitKernel::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + char dbuffer[1024] = {0}; + CPerfCounter timer; + int sub = 0; + std::string options = "-cl-std=CL2.0 -DOCL20=1"; + + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + testDescString = "GPU device is required for this test!\n"; + return; + } + + size_t param_size = 0; + char* strVersion = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 0, + 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[7] < '2') { + options = "-DOCL20=0"; + sub = 1; + delete strVersion; + testDescString = "Currently it works for OCL20 devices only!\n"; + return; + } + delete strVersion; + + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DRIVER_VERSION, 0, + 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DRIVER_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + std::string sch = strKernel; + static const char AmdScheduler[] = "amd_scheduler"; + static const char AmdSchedulerPal[] = "amd_scheduler_pal"; + static const char AmdSchedulerROCm[] = "amd_scheduler_rocm"; + const char* AmdSchedulerPatch = NULL; + size_t loc = 0; + + if (NULL != strstr(strVersion, "LC")) { + if (NULL != strstr(strVersion, "PAL")) { + AmdSchedulerPatch = AmdSchedulerPal; + } else if (NULL != strstr(strVersion, "HSA")) { + AmdSchedulerPatch = AmdSchedulerROCm; + } + } + delete strVersion; + + if (NULL != AmdSchedulerPatch) { + loc = sch.find(AmdScheduler); + sch.replace(loc, strlen(AmdScheduler), AmdSchedulerPatch); + loc = sch.find(AmdScheduler, (loc + strlen(AmdSchedulerPatch))); + sch.replace(loc, strlen(AmdScheduler), AmdSchedulerPatch); + } + + timer.Reset(); + timer.Start(); + + const char* strProgram = sch.c_str(); + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strProgram, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + options.c_str(), NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + cl_kernel kernels[BlitTotal]; + for (int i = 0; i < BlitTotal - sub; ++i) { + kernels[i] = _wrapper->clCreateKernel(program_, BlitName[i], &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + } + timer.Stop(); + double sec = timer.GetElapsedTime(); + + time_ = (float)sec * 1000.f; + testDescString = "Blit kernel compilaiton time (ms):"; + + for (int i = 0; i < BlitTotal - sub; ++i) { + _wrapper->clReleaseKernel(kernels[i]); + } +} + +void OCLBlitKernel::run(void) { _perfInfo = time_; } + +unsigned int OCLBlitKernel::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLBlitKernel.h b/opencl/tests/ocltst/module/runtime/OCLBlitKernel.h new file mode 100644 index 0000000000..ec6e3d80de --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLBlitKernel.h @@ -0,0 +1,41 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_BLIT_KERNEL_H_ +#define _OCL_BLIT_KERNEL_H_ + +#include "OCLTestImp.h" + +class OCLBlitKernel : public OCLTestImp { + public: + OCLBlitKernel(); + virtual ~OCLBlitKernel(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + float time_; +}; + +#endif // _OCL_BLIT_KERNEL_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLBufferFromImage.cpp b/opencl/tests/ocltst/module/runtime/OCLBufferFromImage.cpp new file mode 100644 index 0000000000..9d83583720 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLBufferFromImage.cpp @@ -0,0 +1,299 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLBufferFromImage.h" + +#include +#include +#include +#include + +#define GROUP_SIZE 256 + +const static char strKernel[] = + "__kernel void buffer2bufferCopy( " + " \n" + " __global char* input, " + " \n" + " __global char* output) " + " \n" + "{ " + " \n" + " int coord = (int)(get_global_id(0)); " + " \n" + " output[coord] = input[coord]; " + " \n" + "} " + " \n"; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateBufferFromImageAMD_fn)( + cl_context context, cl_mem image, cl_int *errcode_ret); +clCreateBufferFromImageAMD_fn clCreateBufferFromImageAMD; + +OCLBufferFromImage::OCLBufferFromImage() : OCLTestImp() { + _numSubTests = 2; + blockSizeX = GROUP_SIZE; + blockSizeY = 1; +} + +OCLBufferFromImage::~OCLBufferFromImage() {} + +void OCLBufferFromImage::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + buffer = bufferImage = clImage2D = bufferOut = NULL; + done = false; + pitchAlignment = 0; + bufferSize = 0; + + _openTest = test; + // Initialize random number seed + srand((unsigned int)time(NULL)); + + OCLTestImp::open(test, units, conversion, deviceId); + if (_errorFlag) return; + + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + testDescString = "GPU device is required for this test!\n"; + done = true; + return; + } + + cl_bool imageSupport; + size_t size; + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport), &imageSupport, &size); + if (!imageSupport) { + testDescString = "Image not supported, skipping this test! "; + done = true; + return; + } + + clCreateBufferFromImageAMD = + (clCreateBufferFromImageAMD_fn)clGetExtensionFunctionAddressForPlatform( + platform_, "clCreateBufferFromImageAMD"); + if (clCreateBufferFromImageAMD == NULL) { + testDescString = "clCreateBufferFromImageAMD not found!\n"; + done = true; + return; + } + + CompileKernel(); + AllocateOpenCLBuffer(); +} + +void OCLBufferFromImage::run(void) { + if (_errorFlag || done) { + return; + } + + if ((_openTest % 2) == 0) { + testReadBuffer(bufferImage); + } else { + testKernel(); + } +} + +void OCLBufferFromImage::AllocateOpenCLBuffer() { + cl_int status = 0; + + size_t size = 0; + pitchAlignment = 0; + status = _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_IMAGE_PITCH_ALIGNMENT, + sizeof(cl_uint), &pitchAlignment, &size); + pitchAlignment--; + + const unsigned int requiredPitch = + ((imageWidth + pitchAlignment) & ~pitchAlignment); + const unsigned int pitch = requiredPitch; + bufferSize = pitch * imageHeight; + + unsigned char *sourceData = new unsigned char[bufferSize]; + + // init data + for (unsigned int y = 0; y < bufferSize; y++) { + *(sourceData + y) = y; + } + buffer = _wrapper->clCreateBuffer(context_, + CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE, + bufferSize, sourceData, &status); + + delete[] sourceData; + + const cl_image_format format = {CL_RGBA, CL_UNSIGNED_INT8}; +#if defined(CL_VERSION_2_0) + const cl_image_desc desc = {CL_MEM_OBJECT_IMAGE2D, + imageWidth / 4, + imageHeight, + 0, + 0, + pitch, + 0, + 0, + 0, + {buffer}}; +#else + const cl_image_desc desc = {CL_MEM_OBJECT_IMAGE2D, + imageWidth / 4, + imageHeight, + 0, + 0, + pitch, + 0, + 0, + 0, + buffer}; +#endif + clImage2D = _wrapper->clCreateImage(context_, CL_MEM_READ_WRITE, &format, + &desc, NULL, &status); + CHECK_RESULT(clImage2D == NULL || status != CL_SUCCESS, + "AllocateOpenCLImage() failed"); + + bufferImage = clCreateBufferFromImageAMD(context_, clImage2D, &status); + char c[1024]; + _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DRIVER_VERSION, sizeof(c), + &c, NULL); + if (status == CL_INVALID_OPERATION) { + testDescString = + "clCreateBufferFromImageAMD not supported on this device!\n"; + done = true; + return; + } + CHECK_RESULT(bufferImage == NULL || status != CL_SUCCESS, + "clCreateBufferFromImage(bufferOut) failed"); + + bufferOut = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, bufferSize, + NULL, &status); + CHECK_RESULT(bufferOut == NULL || status != CL_SUCCESS, + "clCreateBuffer(bufferOut) failed"); +} + +void OCLBufferFromImage::testReadBuffer(cl_mem buffer) { + cl_int status = 0; + unsigned char *dstData = new unsigned char[bufferSize]; + + status = clEnqueueReadBuffer(cmdQueues_[_deviceId], buffer, 1, 0, bufferSize, + dstData, 0, 0, 0); + + ::clFinish(cmdQueues_[_deviceId]); + + for (unsigned int y = 0; y < bufferSize; y++) { + if (*(dstData + y) != (unsigned char)y) { + CHECK_RESULT_NO_RETURN(true, "CheckCLBuffer: *(dstData+y)!=y => %i != %i", + *(dstData + y), y); + goto cleanup; + } + } +cleanup: + + delete[] dstData; +} + +void OCLBufferFromImage::testKernel() { + CopyOpenCLBuffer(bufferImage); + + testReadBuffer(bufferOut); +} + +unsigned int OCLBufferFromImage::close(void) { + if (bufferImage != NULL) clReleaseMemObject(bufferImage); + if (clImage2D != NULL) clReleaseMemObject(clImage2D); + if (buffer != NULL) clReleaseMemObject(buffer); + if (bufferOut != NULL) clReleaseMemObject(bufferOut); + return OCLTestImp::close(); +} + +void OCLBufferFromImage::CopyOpenCLBuffer(cl_mem buffer) { + cl_int status = 0; + + // Set appropriate arguments to the kernel2D + + // input buffer image + status = clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((status != CL_SUCCESS), + "CopyOpenCLBuffer() failed at " + "clSetKernelArg(kernel_,0,sizeof(cl_mem),&buffer)"); + status = clSetKernelArg(kernel_, 1, sizeof(cl_mem), &bufferOut); + CHECK_RESULT((status != CL_SUCCESS), + "CopyOpenCLBuffer() failed at " + "clSetKernelArg(kernel_,1,sizeof(cl_mem),&bufferOut)"); + + // Enqueue a kernel run call. + size_t global_work_offset[] = {0}; + size_t globalThreads[] = {bufferSize}; + size_t localThreads[] = {blockSizeX}; + + status = clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, NULL, + globalThreads, NULL, 0, NULL, 0); + CHECK_RESULT((status != CL_SUCCESS), + "CopyOpenCLBuffer() failed at clEnqueueNDRangeKernel"); + + status = clFinish(cmdQueues_[_deviceId]); + CHECK_RESULT((status != CL_SUCCESS), "CopyOpenCLBuffer() failed at clFinish"); +} + +void OCLBufferFromImage::CompileKernel() { + cl_int status = 0; + + size_t kernelSize = sizeof(strKernel); + const char *strs = (const char *)&strKernel[0]; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strs, + &kernelSize, &status); + + status = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], NULL, + NULL, NULL); + if (status != CL_SUCCESS) { + if (status == CL_BUILD_PROGRAM_FAILURE) { + cl_int logStatus; + size_t buildLogSize = 0; + logStatus = clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, buildLogSize, + NULL, &buildLogSize); + std::string buildLog; + buildLog.resize(buildLogSize); + + logStatus = clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, buildLogSize, + &buildLog[0], NULL); + printf("%s", buildLog.c_str()); + } + return; + } + // get a kernel object handle for a kernel with the given name + kernel_ = _wrapper->clCreateKernel(program_, "buffer2bufferCopy", &status); + + size_t kernel2DWorkGroupSize = 0; + status = clGetKernelWorkGroupInfo(kernel_, devices_[_deviceId], + CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), + &kernel2DWorkGroupSize, 0); + + if ((blockSizeX * blockSizeY) > kernel2DWorkGroupSize) { + if (blockSizeX > kernel2DWorkGroupSize) { + blockSizeX = kernel2DWorkGroupSize; + blockSizeY = 1; + } + } +} diff --git a/opencl/tests/ocltst/module/runtime/OCLBufferFromImage.h b/opencl/tests/ocltst/module/runtime/OCLBufferFromImage.h new file mode 100644 index 0000000000..4a469596fb --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLBufferFromImage.h @@ -0,0 +1,57 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCLBufferFromImage_H_ +#define _OCLBufferFromImage_H_ + +#include "OCLTestImp.h" + +class OCLBufferFromImage : public OCLTestImp { + public: + OCLBufferFromImage(); + virtual ~OCLBufferFromImage(); + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual void run(void); + virtual unsigned int close(void); + + protected: + static const unsigned int imageWidth = 1920; + static const unsigned int imageHeight = 1080; + + void testReadBuffer(cl_mem buffer); + void testKernel(); + void AllocateOpenCLBuffer(); + void CopyOpenCLBuffer(cl_mem buffer); + void CompileKernel(); + + bool done; + size_t blockSizeX; /**< Work-group size in x-direction */ + size_t blockSizeY; /**< Work-group size in y-direction */ + size_t bufferSize; + cl_mem buffer; + cl_mem clImage2D; + cl_mem bufferImage; + cl_mem bufferOut; + cl_uint pitchAlignment; +}; + +#endif // _OCLBufferFromImage_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLCPUGuardPages.cpp b/opencl/tests/ocltst/module/runtime/OCLCPUGuardPages.cpp new file mode 100644 index 0000000000..7987af11c4 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLCPUGuardPages.cpp @@ -0,0 +1,178 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLCPUGuardPages.h" + +#include +#include +#include + +#include "CL/cl.h" +#ifdef _WIN32 +#include +#include // for EXCEPTION_ACCESS_VIOLATION + +int filter(unsigned int code, struct _EXCEPTION_POINTERS* ep) { + printf("In filter\n"); + if (code == EXCEPTION_ACCESS_VIOLATION) { + printf("caught AV as expected."); + return EXCEPTION_EXECUTE_HANDLER; + } else { + printf("didn't catch AV, unexpected."); + return EXCEPTION_CONTINUE_SEARCH; + }; +} + +#else +#include + +#include +#include +#include + +void segfault_sigaction(int signal, siginfo_t *si, void *arg) { + printf("Caught segfault at address %p\n", si->si_addr); + exit(0); +} + +#endif + +const static char* strKernel = + "__kernel void simple_in_out_test( int in_offset, \n" + " int out_offset, \n" + " __global float4* in, \n" + " __global float4* out) { \n" + "unsigned int gid = get_global_id(0);\n" + "out[gid + out_offset] = in[gid + in_offset] * -1.f;" + "}"; + +testOCLCPUGuardPagesStruct testOCLCPUGuardPagesList[] = { + {false, false, 1024, 0, 0}, {true, false, 1024, 0, 0}, + {false, false, 1024, 0, 0}, {true, true, 1024, 0, 0}, + {false, false, 1024, 0, 0}, {true, true, 1024, 0, 0}}; + +OCLCPUGuardPages::OCLCPUGuardPages() { + _numSubTests = + sizeof(testOCLCPUGuardPagesList) / sizeof(testOCLCPUGuardPagesStruct); + + /* + struct sigaction sa; + + memset(&sa, 0, sizeof(sa)); + sigemptyset(&sa.sa_mask); + sa.sa_sigaction = segfault_sigaction; + sa.sa_flags = SA_SIGINFO; + + sigaction(SIGSEGV, &sa, NULL); + */ +} + +OCLCPUGuardPages::~OCLCPUGuardPages() {} + +void OCLCPUGuardPages::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + // Initialize the current test parameters. + testValues = testOCLCPUGuardPagesList[test]; + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "simple_in_out_test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + // Create input and output buffers for the test. + cl_mem inBuffer, outBuffer; + cl_float4* dummyIn = new cl_float4[testValues.items]; + for (int i = 0; i < testValues.items; i++) { + dummyIn[i].s[0] = dummyIn[i].s[1] = dummyIn[i].s[2] = dummyIn[i].s[3] = + i * 1.f; + } + inBuffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + testValues.items * sizeof(cl_float4), + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + error_ = _wrapper->clEnqueueWriteBuffer(cmdQueues_[_deviceId], inBuffer, 1, 0, + testValues.items * sizeof(cl_float4), + dummyIn, 0, 0, 0); + buffers_.push_back(inBuffer); + + outBuffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + testValues.items * sizeof(cl_float4), + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(outBuffer); + delete[] dummyIn; +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLCPUGuardPages::run(void) { + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_int), + &testValues.in_offset); + error_ |= _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_int), + &testValues.out_offset); + error_ |= _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_mem), &buffers()[0]); + error_ |= _wrapper->clSetKernelArg(kernel_, 3, sizeof(cl_mem), &buffers()[1]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t globalThreads[1]; + globalThreads[0] = testValues.items; + size_t localThreads[1] = {256}; + +#ifdef _WIN32 + // LPTOP_LEVEL_EXCEPTION_FILTER pOriginalFilter = + // SetUnhandledExceptionFilter(MyUnhandledExceptionFilter); + // AddVectoredExceptionHandler(1,MyVectorExceptionFilter); + + try { + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, globalThreads, localThreads, + 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } catch (...) { + printf("exception caught in OCLTest...\n"); + } + +#else + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, globalThreads, localThreads, + 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); +#endif +} + +unsigned int OCLCPUGuardPages::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLCPUGuardPages.h b/opencl/tests/ocltst/module/runtime/OCLCPUGuardPages.h new file mode 100644 index 0000000000..412a582085 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLCPUGuardPages.h @@ -0,0 +1,49 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_CPU_GUARD_PAGES_H_ +#define _OCL_CPU_GUARD_PAGES_H_ + +#include "OCLTestImp.h" + +typedef struct { + bool useGuardPages; + bool shouldFail; + int items; + int in_offset; + int out_offset; +} testOCLCPUGuardPagesStruct; + +class OCLCPUGuardPages : public OCLTestImp { + public: + OCLCPUGuardPages(); + virtual ~OCLCPUGuardPages(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + testOCLCPUGuardPagesStruct testValues; +}; + +#endif // _OCL_CPU_GUARD_PAGES_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.cpp b/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.cpp new file mode 100644 index 0000000000..cd6ea46eb5 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.cpp @@ -0,0 +1,176 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLCreateBuffer.h" + +#include +#include +#include +#include + +#include +#ifdef __linux__ +#include +#endif + +#include "CL/cl.h" + +const static size_t MaxSubTests = 1; + +OCLCreateBuffer::OCLCreateBuffer() { + _numSubTests = MaxSubTests; + failed_ = false; + maxSize_ = 0; +} + +OCLCreateBuffer::~OCLCreateBuffer() {} + +void OCLCreateBuffer::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + testID_ = test; + + size_t size; + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_MAX_MEM_ALLOC_SIZE, + sizeof(cl_ulong), &maxSize_, &size); +//! Workaround out of range issue in Windows 32bit apps +#if defined(_WIN32) && !defined(_WIN64) + static const size_t MaxSizeLimit = 512 * 1024 * 1024; + if (maxSize_ > MaxSizeLimit) { + maxSize_ = MaxSizeLimit; + } +#endif +#if EMU_ENV + maxSize_ = 1000; +#endif // EMU_ENV + cl_mem buf = NULL; + buf = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, maxSize_, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + + buffers_.push_back(buf); +} + +void OCLCreateBuffer::run(void) { + CPerfCounter timer; + + cl_uchar pattern = PATTERN; + timer.Reset(); + timer.Start(); + error_ = /*_wrapper->*/ clEnqueueFillBuffer( + cmdQueues_[_deviceId], buffers_[0], &pattern, sizeof(pattern), 0, + maxSize_, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueFillBuffer() failed"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + + size_t maxSteps = maxSize_; +#ifdef __linux__ + long pages = sysconf(_SC_PHYS_PAGES); + long page_size = sysconf(_SC_PAGE_SIZE); + if (maxSteps > (size_t)(pages * page_size / 2)) { + maxSteps = (size_t)pages * page_size / 2; + } +#endif + void *resultBuf = NULL; + ; + while ((resultBuf = malloc(maxSteps)) == NULL) { + maxSteps /= 2; + continue; + } + + checkResult(maxSteps, resultBuf, pattern); + + pattern += 1; + + memset(resultBuf, pattern, maxSteps); + + writeBuffer(maxSteps, resultBuf); + + memset(resultBuf, 0x00, maxSteps); + checkResult(maxSteps, resultBuf, pattern); + + free(resultBuf); + + timer.Stop(); + double sec = timer.GetElapsedTime(); + + _perfInfo = (float)sec * 1000.f; + std::stringstream str; + str << "Max single alloc (size of "; + str << maxSize_; + str << " bytes) "; + + testDescString = str.str(); + str << "Max single read/write (size of "; + str << maxSize_; + str << " bytes) create time (ms):"; + + testDescString = str.str(); +} + +void OCLCreateBuffer::checkResult(size_t maxSteps, void *resultBuf, + cl_uchar pattern) { + size_t startPoint = 0; + while ((startPoint) < maxSize_) { + cl_event ee; + size_t readSize = maxSteps; + if ((startPoint + maxSteps) > maxSize_) { + readSize = maxSize_ - startPoint; + } + error_ = /*wrapper->*/ clEnqueueReadBuffer( + cmdQueues_[_deviceId], buffers_[0], CL_FALSE, startPoint, readSize, + resultBuf, 0, NULL, &ee); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + size_t cnt = 0; + cl_uchar *cc = (cl_uchar *)resultBuf; + for (size_t i = 0; i < readSize; i++) { + if (cc[i] != pattern) { + cnt++; + } + } + if (cnt != 0) { + error_ = -1; + CHECK_RESULT((error_ != CL_SUCCESS), "checkResult() failed"); + break; + } + startPoint += maxSteps; + } +} + +void OCLCreateBuffer::writeBuffer(size_t maxSteps, void *dataBuf) { + size_t startPoint = 0; + while ((startPoint) < maxSize_) { + cl_event ee; + size_t writeSize = maxSteps; + if ((startPoint + maxSteps) > maxSize_) { + writeSize = maxSize_ - startPoint; + } + error_ = /*wrapper->*/ clEnqueueWriteBuffer( + cmdQueues_[_deviceId], buffers_[0], CL_FALSE, startPoint, writeSize, + dataBuf, 0, NULL, &ee); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + startPoint += maxSteps; + } +} + +unsigned int OCLCreateBuffer::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.h b/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.h new file mode 100644 index 0000000000..d02117c5b8 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.h @@ -0,0 +1,47 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_CREATE_BUFFER_H_ +#define _OCL_CREATE_BUFFER_H_ + +#include "OCLTestImp.h" +#define PATTERN 0x20 + +class OCLCreateBuffer : public OCLTestImp { + public: + OCLCreateBuffer(); + virtual ~OCLCreateBuffer(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual void writeBuffer(size_t tmpMaxSize, void* dataBuf); + virtual void checkResult(size_t tmpMaxSize, void* resultBuf, + cl_uchar pattern); + virtual unsigned int close(void); + + private: + bool failed_; + unsigned int testID_; + cl_ulong maxSize_; +}; + +#endif // _OCL_CREATE_BUFFER_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLCreateContext.cpp b/opencl/tests/ocltst/module/runtime/OCLCreateContext.cpp new file mode 100644 index 0000000000..316cb6336c --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLCreateContext.cpp @@ -0,0 +1,98 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLCreateContext.h" + +#include +#include +#include + +#include "CL/cl.h" + +OCLCreateContext::OCLCreateContext() { _numSubTests = 1; } + +OCLCreateContext::~OCLCreateContext() {} + +void OCLCreateContext::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLCreateContext::run(void) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + + int error = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error != CL_SUCCESS, "clGetPlatformIDs failed"); + for (unsigned i = 0; i < numPlatforms; ++i) { + char pbuf[100]; + error = _wrapper->clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, + sizeof(pbuf), pbuf, NULL); + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + platform = platforms[i]; + break; + } + } + delete platforms; + } + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + /* Get the number of requested devices */ + error = _wrapper->clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, + &num_devices); + CHECK_RESULT(error != CL_SUCCESS, "clGetDeviceIDs failed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error = _wrapper->clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, num_devices, + devices, NULL); + CHECK_RESULT(error != CL_SUCCESS, "clGetDeviceIDs failed"); + + device = devices[0]; + + cl_context gContext = _wrapper->clCreateContext( + NULL, 1, &device, notify_callback, NULL, &error); + CHECK_RESULT(gContext == 0, "clCreateContext failed"); + + error = _wrapper->clReleaseContext(gContext); + CHECK_RESULT(error != CL_SUCCESS, "clReleaseContext failed"); +} + +unsigned int OCLCreateContext::close(void) { return _crcword; } diff --git a/opencl/tests/ocltst/module/runtime/OCLCreateContext.h b/opencl/tests/ocltst/module/runtime/OCLCreateContext.h new file mode 100644 index 0000000000..bb5fb27b2c --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLCreateContext.h @@ -0,0 +1,38 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_CreateContext_H_ +#define _OCL_CreateContext_H_ + +#include "OCLTestImp.h" + +class OCLCreateContext : public OCLTestImp { + public: + OCLCreateContext(); + virtual ~OCLCreateContext(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); +}; + +#endif // _OCL_CreateContext_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLCreateImage.cpp b/opencl/tests/ocltst/module/runtime/OCLCreateImage.cpp new file mode 100644 index 0000000000..59661e9b81 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLCreateImage.cpp @@ -0,0 +1,500 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLCreateImage.h" + +#include +#include +#include + +#include +#ifdef __linux__ +#include +#include +#endif + +#include "CL/cl.h" + +const static size_t ImageSize = 4; +const static size_t MaxSubTests = 5; + +const static char *strKernel = + "const sampler_t g_Sampler = CLK_FILTER_LINEAR | \n" + " CLK_ADDRESS_CLAMP_TO_EDGE | \n" + " CLK_NORMALIZED_COORDS_FALSE; \n" + " \n" + "__kernel void linear3D(__read_only image3d_t img3D, __global float4* " + "f4Tata) \n" + "{ \n" + " float4 f4Index = { 2.25f, 1.75f, 0.5f, 0.0f }; \n" + " // copy interpolated data in result buffer \n" + " f4Tata[0] = read_imagef(img3D, g_Sampler, f4Index); \n" + "} \n" + " \n" + "__kernel void linear2D(__read_only image2d_t img2D, __global float4* " + "f4Tata) \n" + "{ \n" + " float2 f2Index = { 2.25f, 1.75f }; \n" + " // copy interpolated data in result buffer \n" + " f4Tata[0] = read_imagef(img2D, g_Sampler, f2Index); \n" + "} \n" + " \n" + "__kernel void linear1DArray(__read_only image1d_array_t img1DA, __global " + "float4* f4Tata) \n" + "{ \n" + " float2 f2Index = { 2.25f, 0 }; \n" + " // copy interpolated data in result buffer \n" + " f4Tata[0] = read_imagef(img1DA, g_Sampler, f2Index); \n" + "} \n" + " \n" + "__kernel void linear2DArray(__read_only image2d_array_t img2DA, __global " + "float4* f4Tata) \n" + "{ \n" + " float4 f4Index = { 2.25f, 1.75f, 0.0f, 0.0f }; \n" + " // copy interpolated data in result buffer \n" + " f4Tata[0] = read_imagef(img2DA, g_Sampler, f4Index); \n" + "} \n" + " \n" + "__kernel void point1DBuffer(__read_only image1d_buffer_t img1DB, __global " + "float4* f4Tata) \n" + "{ \n" + " int index = 2; \n" + " // copy interpolated data in result buffer \n" + " f4Tata[0] = read_imagef(img1DB, index); \n" + "} \n" + " \n"; + +OCLCreateImage::OCLCreateImage() { + _numSubTests = MaxSubTests; + done_ = false; + ImageSizeX = ImageSize; + ImageSizeY = ImageSize; + ImageSizeZ = ImageSize; +} + +OCLCreateImage::~OCLCreateImage() {} + +void OCLCreateImage::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + testID_ = test; + + cl_bool imageSupport; + size_t size; + for (size_t i = 0; i < deviceCount_; ++i) { + _wrapper->clGetDeviceInfo(devices_[i], CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport), &imageSupport, &size); + if (!imageSupport) { + testDescString = "Image not supported, skipping this test! "; + done_ = true; + return; + } + } + + cl_ulong max2DWidth; + cl_ulong max2DHeight; + + cl_ulong max3DWidth; + cl_ulong max3DHeight; + cl_ulong max3DDepth; + + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_MAX_MEM_ALLOC_SIZE, + sizeof(cl_ulong), &maxSize_, &size); + + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_IMAGE2D_MAX_WIDTH, + sizeof(cl_ulong), &max2DWidth, &size); + + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_IMAGE2D_MAX_HEIGHT, + sizeof(cl_ulong), &max2DHeight, &size); + + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_IMAGE3D_MAX_WIDTH, + sizeof(cl_ulong), &max3DWidth, &size); + + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_IMAGE3D_MAX_HEIGHT, + sizeof(cl_ulong), &max3DHeight, &size); + + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_IMAGE3D_MAX_DEPTH, + sizeof(cl_ulong), &max3DDepth, &size); + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + const char *kernels[] = {"linear3D", "linear2D", "linear2DArray", + "linear1DArray", "point1DBuffer"}; + unsigned int dimensions[] = {3, 2, 3, 2, 1}; + kernel_ = _wrapper->clCreateKernel(program_, kernels[test], &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem memory; + cl_mem buf = NULL; + cl_image_desc desc; + size_t offset[3] = {0, 0, 0}; + cl_image_format imageFormat = {CL_RGBA, CL_FLOAT}; + + desc.image_type = CL_MEM_OBJECT_IMAGE3D; + desc.image_array_size = 0; + desc.image_row_pitch = 0; + desc.image_slice_pitch = 0; + desc.num_mip_levels = 0; + desc.num_samples = 0; + desc.buffer = (cl_mem)NULL; + + if (test == 0) { + desc.image_type = CL_MEM_OBJECT_IMAGE3D; + if (is64BitApp()) { + ImageSizeX = max3DWidth; + ImageSizeY = maxSize_ / (ImageSizeX * 16); + if (ImageSizeY > (max3DHeight)) { + ImageSizeY = max3DHeight; + } + ImageSizeZ = maxSize_ / (ImageSizeX * ImageSizeY * 16); +#if EMU_ENV + ImageSizeX = ImageSizeY = ImageSizeZ = 4; +#endif // EMU_ENV + } else { + ImageSizeX = 4; + ImageSizeY = 4; + ImageSizeZ = 4; + } + desc.image_width = ImageSizeX; + desc.image_height = ImageSizeY; + desc.image_depth = ImageSizeZ; + } + if (test == 1) { + desc.image_type = CL_MEM_OBJECT_IMAGE2D; + if (is64BitApp()) { + ImageSizeX = max2DWidth - 0x10; + ImageSizeY = maxSize_ / (ImageSizeX * 16 * 2); + if (ImageSizeY >= max2DHeight) { + ImageSizeY = max2DHeight - 0x1000; + } +#ifdef __linux__ + // On linux, if the size of total system memory is less than 4GB, + // then, we can allocate much smaller image. + // TODO, need to find the root cause + struct sysinfo myinfo; + unsigned long total_bytes; + + sysinfo(&myinfo); + total_bytes = myinfo.mem_unit * myinfo.totalram; + if ((total_bytes / (1024 * 1024)) <= 4096) { + ImageSizeY /= 2; + } +#endif +#if EMU_ENV + ImageSizeX = ImageSizeY = 4; +#endif // EMU_ENV + } else { + ImageSizeX = 4; + ImageSizeY = 4; + } + ImageSizeZ = 0; + desc.image_width = ImageSizeX; + desc.image_height = ImageSizeY; + desc.image_depth = 0; + } else if (test == 2) { + desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY; + ImageSizeX = ImageSize; + ImageSizeY = ImageSize; + ImageSizeZ = ImageSize; + desc.image_width = ImageSizeX; + desc.image_height = ImageSizeY; + desc.image_depth = 0; + desc.image_array_size = ImageSize; + } else if (test == 3) { + desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY; + ImageSizeX = ImageSize; + ImageSizeY = ImageSize; + ImageSizeZ = 0; + desc.image_width = ImageSize; + desc.image_height = ImageSize; + desc.image_depth = 0; + desc.image_array_size = ImageSize; + } else if (test == 4) { + ImageSizeX = ImageSize; + desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER; + buf = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + ImageSizeX * 4 * sizeof(cl_float), NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + ImageSizeY = 0; + ImageSizeZ = 0; + desc.image_width = ImageSizeX; + desc.image_height = 0; + desc.image_depth = 0; + desc.buffer = buf; + } + + memory = _wrapper->clCreateImage(context_, CL_MEM_READ_ONLY, &imageFormat, + &desc, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateImage() failed"); + + float fillColor[4] = {1.f, 1.f, 1.f, 1.f}; + + if (dimensions[test] == 1) { + float data[4][ImageSize]; + size_t region[3] = {ImageSize, 1, 1}; + + error_ = + _wrapper->clEnqueueFillImage(cmdQueues_[_deviceId], memory, fillColor, + offset, region, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueFillImage() failed"); + error_ = + _wrapper->clEnqueueReadImage(cmdQueues_[_deviceId], memory, true, + offset, region, 0, 0, data, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadImage() failed"); + + for (size_t x = 0; x < ImageSize; ++x) { + if (0 != memcmp(&data[x], fillColor, sizeof(fillColor))) { + CHECK_RESULT(true, "Fill image validation failed"); + } + data[x][0] = (float)x; + data[x][1] = data[x][2] = data[x][3] = 1.0f; + } + error_ = _wrapper->clEnqueueWriteImage(cmdQueues_[_deviceId], memory, true, + offset, region, 0, 0, data, 0, NULL, + NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteImage() failed"); + } else if (dimensions[test] == 2) { + size_t region[3] = {ImageSizeX, ImageSizeY, 1}; + + error_ = + _wrapper->clEnqueueFillImage(cmdQueues_[_deviceId], memory, fillColor, + offset, region, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueFillImage() failed"); + + float *data; + size_t ActualImageSizeY = ImageSizeY; + size_t maxImageSize = maxSize_; +#ifdef __linux__ + long pages = sysconf(_SC_PHYS_PAGES); + long page_size = sysconf(_SC_PAGE_SIZE); + if (maxImageSize > ((size_t)pages * page_size)) { + maxImageSize = ((size_t)pages * page_size); + } +#endif + while ((((ImageSizeX * ActualImageSizeY * sizeof(float) * 4) / + (1024 * 1024)) >= (size_t)4 * 1024) || + ((ImageSizeX * ActualImageSizeY * sizeof(float) * 4) >= + (maxImageSize / 2))) { + if (ActualImageSizeY == 1) { + break; + } + ActualImageSizeY /= 2; + } + while ((data = (float *)malloc(ImageSizeX * ActualImageSizeY * + sizeof(float) * 4)) == NULL) { + if (ActualImageSizeY == 1) { + break; + } + ActualImageSizeY /= 2; + } + if (data == NULL) { + CHECK_RESULT(true, "malloc() failed"); + } + + size_t remainSizeY = ImageSizeY; + while (remainSizeY > 0) { + ActualImageSizeY = + (remainSizeY > ActualImageSizeY) ? ActualImageSizeY : remainSizeY; + size_t tmpRange[3] = {ImageSizeX, ActualImageSizeY, 1}; + error_ = _wrapper->clEnqueueReadImage(cmdQueues_[_deviceId], memory, true, + offset, tmpRange, 0, 0, data, 0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadImage() failed"); + + for (size_t y = 0; y < ActualImageSizeY; ++y) { + for (size_t x = 0; x < ImageSizeX; ++x) { + size_t offsetData = (y * ImageSizeX + x) * 4; + if (0 != memcmp(&data[offsetData], fillColor, sizeof(fillColor))) { + CHECK_RESULT(true, "Fill image validation failed"); + } + data[offsetData + 0] = (float)x; + data[offsetData + 1] = (float)y; + data[offsetData + 2] = data[offsetData + 3] = 1.0f; + } + } + error_ = _wrapper->clEnqueueWriteImage(cmdQueues_[_deviceId], memory, + true, offset, tmpRange, 0, 0, data, + 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteImage() failed"); + remainSizeY -= ActualImageSizeY; + offset[1] += ActualImageSizeY; + } + free(data); + } else if (dimensions[test] == 3) { + float *data; + + float index = 0.f; + size_t region[3] = {ImageSizeX, ImageSizeY, ImageSizeZ}; + error_ = + _wrapper->clEnqueueFillImage(cmdQueues_[_deviceId], memory, fillColor, + offset, region, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueFillImage() failed"); + + size_t ActualImageSizeZ = ImageSizeZ; + size_t maxImageSize = maxSize_; +#ifdef __linux__ + long pages = sysconf(_SC_PHYS_PAGES); + long page_size = sysconf(_SC_PAGE_SIZE); + if (maxImageSize > ((size_t)pages * page_size)) { + maxImageSize = ((size_t)pages * page_size); + } +#endif + while ((((ImageSizeX * ImageSizeY * ActualImageSizeZ * sizeof(float) * 4) / + (1024 * 1024)) >= (size_t)4 * 1024) || + ((ImageSizeX * ImageSizeY * ActualImageSizeZ * sizeof(float) * 4) >= + (maxImageSize / 2))) { + if (ActualImageSizeZ == 1) { + break; + } + ActualImageSizeZ /= 2; + } + while ((data = (float *)malloc(ImageSizeX * ImageSizeY * ActualImageSizeZ * + sizeof(float) * 4)) == NULL) { + if (ActualImageSizeZ == 1) { + break; + } + ActualImageSizeZ -= 1; + } + if (data == NULL) { + CHECK_RESULT(true, "malloc() failed"); + } + + size_t remainSizeZ = ImageSizeZ; + while (remainSizeZ > 0) { + ActualImageSizeZ = + (remainSizeZ > ActualImageSizeZ) ? ActualImageSizeZ : remainSizeZ; + size_t tmpRange[3] = {ImageSizeX, ImageSizeY, ActualImageSizeZ}; + error_ = _wrapper->clEnqueueReadImage(cmdQueues_[_deviceId], memory, true, + offset, tmpRange, 0, 0, data, 0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadImage() failed"); + + for (size_t z = 0; z < ActualImageSizeZ; ++z) { + for (size_t y = 0; y < ImageSizeY; ++y) { + for (size_t x = 0; x < ImageSizeX; ++x) { + size_t offset = (((z * ImageSizeY) + y) * ImageSizeX + x) * 4; + if (0 != memcmp(&data[offset], fillColor, sizeof(fillColor))) { + CHECK_RESULT(true, "Fill image validation failed"); + } + data[offset + 0] = (float)x; + data[offset + 1] = (float)y; + data[offset + 2] = (float)z; + data[offset + 3] = 1.0f; + } + } + } + error_ = _wrapper->clEnqueueWriteImage(cmdQueues_[_deviceId], memory, + true, offset, tmpRange, 0, 0, data, + 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteImage() failed"); + remainSizeZ -= ActualImageSizeZ; + offset[2] += ActualImageSizeZ; + } + free(data); + } + + buffers_.push_back(memory); + + memory = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + 4 * sizeof(cl_float), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(memory); + if (buf != NULL) { + buffers_.push_back(buf); + } + size_t imageSizebyte = + (ImageSizeY != 0) ? ImageSizeY * ImageSizeX : ImageSizeX; + imageSizebyte *= (ImageSizeZ != 0) ? ImageSizeZ : 1; + imageSizebyte *= 16; // 16 bytes per pixel, imageFormat = {CL_RGBA,CL_FLOAT} + char strImgSize[200]; + if (imageSizebyte >= 1024 * 1024) { + sprintf(strImgSize, "%5ld MB", (long)(imageSizebyte / (1024 * 1024))); + } else { + sprintf(strImgSize, "%6ld Bytes", (long)imageSizebyte); + } + std::stringstream str; + str << " ("; + str << ImageSizeX; + str << ", "; + str << ImageSizeY; + str << ", "; + str << ImageSizeZ; + str << ") "; + str << strImgSize; + + testDescString = str.str(); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLCreateImage::run(void) { + if (done_) { + return; + } + + cl_float values[4] = {0.f, 0.f, 0.f, 0.f}; + cl_float ref[2] = {1.75f, 1.25f}; + cl_mem image = buffers()[0]; + cl_mem buffer = buffers()[1]; + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &image); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t gws[1] = {0x1}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffer, true, 0, + 4 * sizeof(cl_float), values, 0, NULL, + NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + if (testID_ == 4) { + ref[0] = 2.0f; + } + for (cl_uint i = 0; i < static_cast((testID_ >= 3) ? 1 : 2); ++i) { + if (values[i] != ref[i]) { + printf("%.2f != %.2f [ref]", values[i], ref[i]); + CHECK_RESULT(true, " - Incorrect result for linear filtering!\n"); + } + } +} + +unsigned int OCLCreateImage::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLCreateImage.h b/opencl/tests/ocltst/module/runtime/OCLCreateImage.h new file mode 100644 index 0000000000..8238bb1fda --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLCreateImage.h @@ -0,0 +1,48 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_CREATE_IMAGE_H_ +#define _OCL_CREATE_IMAGE_H_ + +#include "OCLTestImp.h" + +class OCLCreateImage : public OCLTestImp { + public: + OCLCreateImage(); + virtual ~OCLCreateImage(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool done_; + unsigned int testID_; + size_t maxSize_; + size_t ImageSizeX; + size_t ImageSizeY; + size_t ImageSizeZ; + + bool is64BitApp() { return sizeof(int*) == 8; } +}; + +#endif // _OCL_CREATE_IMAGE_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLDeviceAtomic.cpp b/opencl/tests/ocltst/module/runtime/OCLDeviceAtomic.cpp new file mode 100644 index 0000000000..62854f9862 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLDeviceAtomic.cpp @@ -0,0 +1,240 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLDeviceAtomic.h" + +#include +#include +#include + +#include "CL/cl.h" +#if EMU_ENV +static const cl_uint TotalElements = 8 * 32 * 256; +#else +static const cl_uint TotalElements = 256 * 1024 * 1024; +#endif +static const cl_uint ArraySize = 256; +static cl_uint hostArray[ArraySize]; + +#define KERNEL_CODE(...) #__VA_ARGS__ + +const static char* strKernel[] = { + KERNEL_CODE( + \n __kernel void atomic_test1(__global uint* res) { + __global atomic_uint* inc = (__global atomic_uint*)res; + atomic_fetch_add_explicit(inc, 1, memory_order_acq_rel, + memory_scope_device); + } + \n __kernel void atomic_test2(__global uint* res) { + __global atomic_uint* inc = (__global atomic_uint*)res; + atomic_fetch_add_explicit(inc, 1, memory_order_acq_rel, + memory_scope_device); + } + \n), +#if EMU_ENV + KERNEL_CODE( + \n __kernel void atomic_test1(__global uint* res) { + for (uint i = 0; i < 8 * 32; ++i) { + for (uint j = 0; j < 256; ++j) { + __global atomic_uint* inc = (__global atomic_uint*)&res[j]; + uint val = atomic_load_explicit(inc, memory_order_acquire, + memory_scope_device); + if (0 != val) { + res[1] = get_global_id(0); + res[2] = i; + return; + } + } + } + } + \n __kernel void atomic_test2(__global uint* res) { + if (get_global_id(0) == 8 * 20 * 100) { + __global atomic_uint* inc = (__global atomic_uint*)res; + // atomic_fetch_add_explicit(inc, 1, memory_order_acq_rel, + // memory_scope_device); + atomic_store_explicit(inc, get_global_id(0), memory_order_release, + memory_scope_device); + } + } + \n) +#else + KERNEL_CODE( + \n __kernel void atomic_test1(__global uint* res) { + for (uint i = 0; i < 256 * 1024; ++i) { + for (uint j = 0; j < 256; ++j) { + __global atomic_uint* inc = (__global atomic_uint*)&res[j]; + uint val = atomic_load_explicit(inc, memory_order_acquire, memory_scope_device); + if (0 != val) { + res[1] = get_global_id(0); + res[2] = i; + return; + } + } + } + } + \n __kernel void atomic_test2(__global uint* res) { + if (get_global_id(0) == 64 * 1000 * 1000) { + __global atomic_uint* inc = (__global atomic_uint*)res; + // atomic_fetch_add_explicit(inc, 1, memory_order_acq_rel, + // memory_scope_device); + atomic_store_explicit(inc, get_global_id(0), memory_order_release, memory_scope_device); + } + } + \n) +#endif +}; + +OCLDeviceAtomic::OCLDeviceAtomic() + : hostQueue_(NULL), failed_(false), kernel2_(NULL) { + _numSubTests = 2; +} + +OCLDeviceAtomic::~OCLDeviceAtomic() {} + +void OCLDeviceAtomic::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + testID_ = test; + size_t param_size = 0; + char* strVersion = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 0, + 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[7] < '2') { + failed_ = true; + return; + } + delete strVersion; + + char dbuffer[1024] = {0}; + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel[test], + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "atomic_test1", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + kernel2_ = _wrapper->clCreateKernel(program_, "atomic_test2", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + memset(hostArray, 0, sizeof(hostArray)); + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_COPY_HOST_PTR, + sizeof(hostArray), &hostArray, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + +#if defined(CL_VERSION_2_0) + const cl_queue_properties cprops[] = {CL_QUEUE_PROPERTIES, + static_cast(0), 0}; + hostQueue_ = _wrapper->clCreateCommandQueueWithProperties( + context_, devices_[deviceId], cprops, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateCommandQueueWithProperties() failed"); +#endif +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLDeviceAtomic::run(void) { + if (failed_) return; + cl_mem buffer = buffers()[0]; + + size_t gws[1] = {TotalElements}; + size_t gws2[1] = {1}; + size_t gws3[1] = {TotalElements}; + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + if (testID_ == 0) { + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } else { + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws2, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + + error_ = _wrapper->clSetKernelArg(kernel2_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + if (testID_ == 0) { + error_ = _wrapper->clEnqueueNDRangeKernel(hostQueue_, kernel2_, 1, NULL, + gws, NULL, 0, NULL, NULL); + } else { + error_ = _wrapper->clEnqueueNDRangeKernel(hostQueue_, kernel2_, 1, NULL, + gws3, NULL, 0, NULL, NULL); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFlush(cmdQueues_[_deviceId]); + _wrapper->clFlush(hostQueue_); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + _wrapper->clFinish(hostQueue_); + + error_ = _wrapper->clEnqueueReadBuffer(hostQueue_, buffer, CL_TRUE, 0, + sizeof(hostArray), hostArray, 0, NULL, + NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + + if (testID_ == 0) { + if (hostArray[0] != 2 * TotalElements) { + printf("Counter: %d, expected: %d\n", hostArray[0], 2 * TotalElements); + CHECK_RESULT(true, "Incorrect result for device atomic inc!\n"); + } + } else { + printf("Value: %d, thread: %d, iter: %d\n", hostArray[0], hostArray[1], + hostArray[2]); + if (hostArray[0] == 0) { + CHECK_RESULT(true, "Incorrect result for device atomic inc!\n"); + } + } +} + +unsigned int OCLDeviceAtomic::close(void) { + if (NULL != hostQueue_) { + _wrapper->clReleaseCommandQueue(hostQueue_); + } + if (NULL != kernel2_) { + _wrapper->clReleaseKernel(kernel2_); + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/runtime/OCLDeviceAtomic.h b/opencl/tests/ocltst/module/runtime/OCLDeviceAtomic.h new file mode 100644 index 0000000000..7dd4f377df --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLDeviceAtomic.h @@ -0,0 +1,44 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_DEVICE_ATOMIC_H_ +#define _OCL_DEVICE_ATOMIC_H_ + +#include "OCLTestImp.h" + +class OCLDeviceAtomic : public OCLTestImp { + public: + OCLDeviceAtomic(); + virtual ~OCLDeviceAtomic(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + cl_command_queue hostQueue_; + bool failed_; + cl_kernel kernel2_; + unsigned int testID_; +}; + +#endif // _OCL_DEVICE_ATOMIC_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLDeviceQueries.cpp b/opencl/tests/ocltst/module/runtime/OCLDeviceQueries.cpp new file mode 100644 index 0000000000..427b4c04a6 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLDeviceQueries.cpp @@ -0,0 +1,266 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLDeviceQueries.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +struct AMDDeviceInfo { + const char* targetName_; //!< Target name + const char* machineTarget_; //!< Machine target + cl_uint simdPerCU_; //!< Number of SIMDs per CU + cl_uint simdWidth_; //!< Number of workitems processed per SIMD + cl_uint simdInstructionWidth_; //!< Number of instructions processed per SIMD + cl_uint memChannelBankWidth_; //!< Memory channel bank width + cl_uint localMemSizePerCU_; //!< Local memory size per CU + cl_uint localMemBanks_; //!< Number of banks of local memory + cl_uint gfxipMajor_; //!< GFXIP major number + cl_uint gfxipMinor_; //!< GFXIP minor number +}; + +static const cl_uint Ki = 1024; +static const AMDDeviceInfo DeviceInfo[] = { + /* CAL_TARGET_CAYMAN */ + {"Cayman", "cayman", 1, 16, 4, 256, 32 * Ki, 32, 5, 0}, + /* CAL_TARGET_TAHITI */ + {"Tahiti", "tahiti", 4, 16, 1, 256, 64 * Ki, 32, 6, 0}, + /* CAL_TARGET_PITCAIRN */ + {"Pitcairn", "pitcairn", 4, 16, 1, 256, 64 * Ki, 32, 6, 0}, + /* CAL_TARGET_CAPEVERDE */ + {"Capeverde", "capeverde", 4, 16, 1, 256, 64 * Ki, 32, 6, 0}, + /* CAL_TARGET_DEVASTATOR */ + {"Devastator", "trinity", 1, 16, 4, 256, 32 * Ki, 32, 5, 0}, + /* CAL_TARGET_SCRAPPER */ + {"Scrapper", "trinity", 1, 16, 4, 256, 32 * Ki, 32, 5, 0}, + /* CAL_TARGET_OLAND */ {"Oland", "oland", 4, 16, 1, 256, 64 * Ki, 32, 6, 0}, + /* CAL_TARGET_BONAIRE */ + {"Bonaire", "bonaire", 4, 16, 1, 256, 64 * Ki, 32, 7, 2}, + /* CAL_TARGET_SPECTRE */ + {"Spectre", "spectre", 4, 16, 1, 256, 64 * Ki, 32, 7, 1}, + /* CAL_TARGET_SPOOKY */ + {"Spooky", "spooky", 4, 16, 1, 256, 64 * Ki, 32, 7, 1}, + /* CAL_TARGET_KALINDI */ + {"Kalindi", "kalindi", 4, 16, 1, 256, 64 * Ki, 32, 7, 2}, + /* CAL_TARGET_HAINAN */ + {"Hainan", "hainan", 4, 16, 1, 256, 64 * Ki, 32, 6, 0}, + /* CAL_TARGET_HAWAII */ + {"Hawaii", "hawaii", 4, 16, 1, 256, 64 * Ki, 32, 7, 2}, + /* CAL_TARGET_ICELAND */ + {"Iceland", "iceland", 4, 16, 1, 256, 64 * Ki, 32, 8, 0}, + /* CAL_TARGET_TONGA */ {"Tonga", "tonga", 4, 16, 1, 256, 64 * Ki, 32, 8, 0}, + /* CAL_TARGET_MULLINS */ + {"Mullins", "mullins", 4, 16, 1, 256, 64 * Ki, 32, 7, 2}, + /* CAL_TARGET_FIJI */ {"Fiji", "fiji", 4, 16, 1, 256, 64 * Ki, 32, 8, 0}, + /* CAL_TARGET_CARRIZO */ + {"Carrizo", "carrizo", 4, 16, 1, 256, 64 * Ki, 32, 8, 0}, + /* CAL_TARGET_CARRIZO */ + {"Bristol Ridge", "carrizo", 4, 16, 1, 256, 64 * Ki, 32, 8, 0}, + /* CAL_TARGET_Ellesmere */ + {"Ellesmere", "ellesmere", 4, 16, 1, 256, 64 * Ki, 32, 8, 0}, + /* CAL_TARGET_BAFFIN */ + {"Baffin", "baffin", 4, 16, 1, 256, 64 * Ki, 32, 8, 0}, + /* ROCM Kaveri */ {"gfx700", "gfx700", 4, 16, 1, 256, 64 * Ki, 32, 7, 1}, + /* ROCM Hawaii */ {"gfx701", "gfx701", 4, 16, 1, 256, 64 * Ki, 32, 7, 2}, + /* ROCM Kabini */ {"gfx703", "gfx703", 4, 16, 1, 256, 64 * Ki, 32, 7, 2}, + /* ROCM Iceland */ {"gfx800", "gfx800", 4, 16, 1, 256, 64 * Ki, 32, 8, 0}, + /* ROCM Carrizo */ {"gfx801", "gfx801", 4, 16, 1, 256, 64 * Ki, 32, 8, 0}, + /* ROCM Tonga */ {"gfx802", "gfx802", 4, 16, 1, 256, 64 * Ki, 32, 8, 0}, + /* ROCM Fiji */ {"gfx803", "gfx803", 4, 16, 1, 256, 64 * Ki, 32, 8, 0}, + /* Vega10 */ {"gfx900", "gfx900", 4, 16, 1, 256, 64 * Ki, 32, 9, 0}, + /* CAL_TARGET_STONEY */ + {"Stoney", "stoney", 4, 16, 1, 256, 64 * Ki, 32, 8, 0}, + /* CAL_TARGET_LEXA */ + {"gfx804", "gfx804", 4, 16, 1, 256, 64 * Ki, 32, 8, 0}, + /* Vega10_XNACK */ {"gfx901", "gfx901", 4, 16, 1, 256, 64 * Ki, 32, 9, 0}, + /* Raven */ {"gfx902", "gfx902", 4, 16, 1, 256, 64 * Ki, 32, 9, 0}, + /* Raven_XNACK */ {"gfx903", "gfx903", 4, 16, 1, 256, 64 * Ki, 32, 9, 0}, + /* Vega12 */ {"gfx904", "gfx904", 4, 16, 1, 256, 64 * Ki, 32, 9, 0}, + /* Vega12_XNACK */ {"gfx905", "gfx905", 4, 16, 1, 256, 64 * Ki, 32, 9, 0}, + /* Vega20 */ {"gfx906", "gfx906", 4, 16, 1, 256, 64 * Ki, 32, 9, 0}, + /* Vega20_XNACK */ {"gfx907", "gfx907", 4, 16, 1, 256, 64 * Ki, 32, 9, 0}, + /* MI100 */ {"gfx908", "gfx908", 4, 16, 1, 256, 64 * Ki, 32, 9, 0}, + /* MI200 */ {"gfx90a", "gfx90a", 4, 16, 1, 256, 64 * Ki, 32, 9, 0}, + /* Navi10 */ {"gfx1010", "gfx1010", 4, 32, 1, 256, 64 * Ki, 32, 10, 1}, + /* Navi12 */ {"gfx1011", "gfx1011", 4, 32, 1, 256, 64 * Ki, 32, 10, 1}, + /* Navi14 */ {"gfx1012", "gfx1012", 4, 32, 1, 256, 64 * Ki, 32, 10, 1}, + /* Navi21 */ { "gfx1030", "gfx1030", 4, 32, 1, 256, 64 * Ki, 32, 10, 3 }, + /* Navi22 */ { "gfx1031", "gfx1031", 4, 32, 1, 256, 64 * Ki, 32, 10, 3 }, + /* Navi23 */ { "gfx1032", "gfx1032", 4, 32, 1, 256, 64 * Ki, 32, 10, 3 }, + /* Van Gogh */ { "gfx1033", "gfx1033", 4, 32, 1, 256, 64 * Ki, 32, 10, 3 }, + /* Navi24 */ { "gfx1034", "gfx1034", 4, 32, 1, 256, 64 * Ki, 32, 10, 3 }, + /* Rembrandt */{ "gfx1035", "gfx1035", 4, 32, 1, 256, 64 * Ki, 32, 10, 3 }, + /* Raphael */ { "gfx1036", "gfx1036", 4, 32, 1, 256, 64 * Ki, 32, 10, 3 }, + /* Navi31*/ { "gfx1100", "gfx1100", 4, 32, 1, 256, 64 * Ki, 32, 11, 0 }, + /* Navi32*/ { "gfx1101", "gfx1101", 4, 32, 1, 256, 64 * Ki, 32, 11, 0 }, + /* Navi33*/ { "gfx1102", "gfx1102", 4, 32, 1, 256, 64 * Ki, 32, 11, 0 }, +}; + +const int DeviceInfoSize = sizeof(DeviceInfo) / sizeof(AMDDeviceInfo); + +OCLDeviceQueries::OCLDeviceQueries() { + _numSubTests = 1; + failed_ = false; +} + +OCLDeviceQueries::~OCLDeviceQueries() {} + +void OCLDeviceQueries::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + char name[1024] = {0}; + size_t size = 0; + + if (deviceId >= deviceCount_) { + failed_ = true; + return; + } + cl_uint value; + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_EXTENSIONS, 1024, + name, &size); + if (!strstr(name, "cl_amd_device_attribute_query")) { + printf("AMD device attribute extension is required for this test!\n"); + failed_ = true; + return; + } + + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_NAME, + sizeof(name), name, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_NAME failed"); + + std::string str = name; + int id = 0; + bool deviceFound = false; + for (int i = 0; i < DeviceInfoSize; ++i) { + if (0 == str.find(DeviceInfo[i].targetName_)) { + deviceFound = true; + id = i; + break; + } + } + CHECK_RESULT(deviceFound != true, "Device %s is not supported", name); + + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], + CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, + sizeof(cl_uint), &value, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), + "CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD failed"); + CHECK_RESULT((value != DeviceInfo[id].simdPerCU_), + "CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD failed"); + + error_ = + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_SIMD_WIDTH_AMD, + sizeof(cl_uint), &value, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_SIMD_WIDTH_AMD failed"); + CHECK_RESULT((value != DeviceInfo[id].simdWidth_), + "CL_DEVICE_SIMD_WIDTH_AMD failed"); + + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], + CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, + sizeof(cl_uint), &value, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), + "CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD failed"); + CHECK_RESULT((value != DeviceInfo[id].simdInstructionWidth_), + "CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD failed"); + + error_ = _wrapper->clGetDeviceInfo( + devices_[deviceId], CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, + sizeof(cl_uint), &value, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), + "CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD failed"); + CHECK_RESULT((value != DeviceInfo[id].memChannelBankWidth_), + "CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD failed"); + + error_ = _wrapper->clGetDeviceInfo( + devices_[deviceId], CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, + sizeof(cl_uint), &value, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), + "CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD failed"); + CHECK_RESULT((value != DeviceInfo[id].localMemSizePerCU_), + "CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD failed"); + + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], + CL_DEVICE_LOCAL_MEM_BANKS_AMD, + sizeof(cl_uint), &value, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_LOCAL_MEM_BANKS_AMD failed"); + CHECK_RESULT((value != DeviceInfo[id].localMemBanks_), + "CL_DEVICE_LOCAL_MEM_BANKS_AMD failed"); + + error_ = + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_GFXIP_MAJOR_AMD, + sizeof(cl_uint), &value, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_GFXIP_MAJOR_AMD failed"); + CHECK_RESULT((value != DeviceInfo[id].gfxipMajor_), + "CL_DEVICE_GFXIP_MAJOR_AMD failed"); + + error_ = + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_GFXIP_MINOR_AMD, + sizeof(cl_uint), &value, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_GFXIP_MINOR_AMD failed"); + + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], + CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, + sizeof(cl_uint), &value, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), + "CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD failed"); + CHECK_RESULT((value == 0), "CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD failed"); + + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], + CL_DEVICE_WAVEFRONT_WIDTH_AMD, + sizeof(cl_uint), &value, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_WAVEFRONT_WIDTH_AMD failed"); + CHECK_RESULT((value == 0), "CL_DEVICE_WAVEFRONT_WIDTH_AMD failed"); + + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], + CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, + sizeof(cl_uint), &value, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), + "CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD failed"); + CHECK_RESULT((value == 0), "CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD failed"); +} + +static void CL_CALLBACK notify_callback(cl_event event, + cl_int event_command_exec_status, + void* user_data) {} + +void OCLDeviceQueries::run(void) { + if (failed_) { + return; + } +} + +unsigned int OCLDeviceQueries::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLDeviceQueries.h b/opencl/tests/ocltst/module/runtime/OCLDeviceQueries.h new file mode 100644 index 0000000000..168169f14f --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLDeviceQueries.h @@ -0,0 +1,41 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_DEVICE_QUERIES_H_ +#define _OCL_DEVICE_QUERIES_H_ + +#include "OCLTestImp.h" + +class OCLDeviceQueries : public OCLTestImp { + public: + OCLDeviceQueries(); + virtual ~OCLDeviceQueries(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; +}; + +#endif // _OCL_DEVICE_QUERIES_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLDynamic.cpp b/opencl/tests/ocltst/module/runtime/OCLDynamic.cpp new file mode 100644 index 0000000000..98f505fc29 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLDynamic.cpp @@ -0,0 +1,235 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLDynamic.h" + +#include +#include +#include + +#include "CL/cl.h" +#if EMU_ENV +static const cl_uint TotalElements = 1; +#else +static const cl_uint TotalElements = 128; +#endif // EMU_ENV +static cl_uint hostArray[TotalElements]; + +#define KERNEL_CODE(...) #__VA_ARGS__ + +const static char* strKernel[] = { + KERNEL_CODE( + \n void block_fn(int tid, int mul, __global uint* res) { + res[tid] = mul * 7 - 21; + } + + __kernel void dynamic(__global uint* res) { + int multiplier = 3; + int tid = get_global_id(0); + + void (^kernelBlock)(void) = ^{ + block_fn(tid, multiplier, res); + }; + + res[tid] = -1; + queue_t def_q = get_default_queue(); + ndrange_t ndrange = ndrange_1D(1); + int enq_res; + do { + enq_res = enqueue_kernel(def_q, CLK_ENQUEUE_FLAGS_NO_WAIT, ndrange, + kernelBlock); + if (enq_res != 0 /*CL_SUCCESS*/) { + res[tid] = -2; + } + } while (enq_res != 0); + } + \n), + KERNEL_CODE( + \n void block_fn(int tid, int mul, __global uint* res) { + res[tid] = mul * 7 - 21; + } + + __kernel void dynamic(__global uint* res, queue_t def_q) { + int multiplier = 3; + int tid = get_global_id(0); + + void (^kernelBlock)(void) = ^{ + block_fn(tid, multiplier, res); + }; + + res[tid] = -1; + ndrange_t ndrange = ndrange_1D(1); + // if (tid == 0) { + int enq_res = enqueue_kernel(def_q, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, + ndrange, kernelBlock); + if (enq_res != 0 /*CL_SUCCESS*/) { + res[tid] = -2; + return; + } + //} + } + \n)}; + +OCLDynamic::OCLDynamic() { + _numSubTests = 2; + deviceQueue_ = NULL; + failed_ = false; +} + +OCLDynamic::~OCLDynamic() {} + +void OCLDynamic::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + // FIXME: Re-enable CPU test once bug 10143 is fixed. + if (type_ == CL_DEVICE_TYPE_CPU) { + return; + } + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + testID_ = test; + + size_t param_size = 0; + char* strVersion = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 0, + 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[7] < '2') { + failed_ = true; + return; + } + delete strVersion; + + char dbuffer[1024] = {0}; + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel[test], + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "dynamic", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + memset(hostArray, 0xee, sizeof(hostArray)); + buffer = _wrapper->clCreateBuffer( + context_, CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR, sizeof(hostArray), + &hostArray, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); +#if EMU_ENV + cl_uint queueSize = 1; +#else + cl_uint queueSize = (test == 0) ? 1 : 257 * 1024; +#endif // EMU_ENV +#if defined(CL_VERSION_2_0) + const cl_queue_properties cprops[] = { + CL_QUEUE_PROPERTIES, + static_cast(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | + CL_QUEUE_ON_DEVICE_DEFAULT | + CL_QUEUE_ON_DEVICE), + CL_QUEUE_SIZE, queueSize, 0}; + deviceQueue_ = _wrapper->clCreateCommandQueueWithProperties( + context_, devices_[deviceId], cprops, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateCommandQueueWithProperties() failed"); +#endif +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLDynamic::run(void) { + // FIXME: Re-enable CPU test once bug 10143 is fixed. + if (type_ == CL_DEVICE_TYPE_CPU) { + return; + } + + if (failed_) return; + cl_mem buffer = buffers()[0]; + + size_t gws[1] = {TotalElements}; + size_t lws[1] = {16}; + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + if (testID_ == 1) { + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_command_queue), + &deviceQueue_); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + } + + size_t offset = 0; + size_t region = TotalElements * sizeof(cl_uint); + + cl_uint* host = reinterpret_cast(_wrapper->clEnqueueMapBuffer( + cmdQueues_[_deviceId], buffer, CL_TRUE, (CL_MAP_READ | CL_MAP_WRITE), + offset, region, 0, NULL, NULL, &error_)); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueMapBuffer() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, +#if EMU_ENV + NULL, gws, NULL, 0, NULL, NULL); +#else + NULL, gws, lws, 0, NULL, NULL); +#endif // EMU_ENV + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + + for (unsigned int i = 0; i < TotalElements; ++i) { + if (host[i] != 0) { + printf("Bad value: a[%d] = %d\n", i, hostArray[i]); + CHECK_RESULT(true, "Incorrect result for dependency!\n"); + } + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], buffer, + host, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueUnmapBuffer() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); +} + +unsigned int OCLDynamic::close(void) { + // FIXME: Re-enable CPU test once bug 10143 is fixed. + if (type_ == CL_DEVICE_TYPE_CPU) { + return 0; + } + + if (NULL != deviceQueue_) { + _wrapper->clReleaseCommandQueue(deviceQueue_); + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/runtime/OCLDynamic.h b/opencl/tests/ocltst/module/runtime/OCLDynamic.h new file mode 100644 index 0000000000..e72ae18171 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLDynamic.h @@ -0,0 +1,43 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_DYNAMIC_H_ +#define _OCL_DYNAMIC_H_ + +#include "OCLTestImp.h" + +class OCLDynamic : public OCLTestImp { + public: + OCLDynamic(); + virtual ~OCLDynamic(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + cl_command_queue deviceQueue_; + bool failed_; + unsigned int testID_; +}; + +#endif // _OCL_MEM_DEPENDENCY_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLDynamicBLines.cpp b/opencl/tests/ocltst/module/runtime/OCLDynamicBLines.cpp new file mode 100644 index 0000000000..75c1124e55 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLDynamicBLines.cpp @@ -0,0 +1,357 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLDynamicBLines.h" + +#include +#include +#include +#include + +#include "CL/cl.h" + +const static cl_int nLines = 2048; +const static cl_int blockDim = 64; +#define MAX_TESSELLATION 64 + +#define KERNEL_CODE(...) #__VA_ARGS__ + +const static char* strKernel[] = +{ + KERNEL_CODE( + \n + \x23 define MAX_TESSELLATION 64 + \n + struct BezierLine + { + float2 CP[3]; + ulong vertexPos; + int nVertices; + int reserved; + }; + \n + __kernel + void computeBezierLinePositions(int lidx, __global struct BezierLine* bLines, + int nTessPoints, __global char* buf) + { + int idx = get_global_id(0); + if (idx < nTessPoints) { + float u = (float)idx / (float)(nTessPoints-1); + float omu = 1.0f - u; + + float B3u[3]; + + B3u[0] = omu * omu; + B3u[1] = 2.0f * u * omu; + B3u[2] = u * u; + + float2 position = {0, 0}; + + for (int i = 0; i < 3; i++) { + position = position + B3u[i] * bLines[lidx].CP[i]; + } + + ((__global float2*)(bLines[lidx].vertexPos))[idx] = position; + } + } + \n + __kernel + void computeBezierLines(__global struct BezierLine* bLines, int nLines, __global char* buf) + { + int lidx = get_global_id(0); + + if (lidx < nLines) { + float curvature = length(bLines[lidx].CP[1] - 0.5f * (bLines[lidx].CP[0] + bLines[lidx].CP[2])) / + length(bLines[lidx].CP[2] - bLines[lidx].CP[0]); + int nTessPoints = min(max((int)(curvature * 16.0f), 4), MAX_TESSELLATION); + + if (bLines[lidx].vertexPos == 0) { + bLines[lidx].nVertices = nTessPoints; + uint value = atomic_add((__global volatile uint*)buf, + nTessPoints * sizeof(float2)); + bLines[lidx].vertexPos = (ulong)(&buf[value]); + } + + queue_t def_q = get_default_queue(); + ndrange_t ndrange = ndrange_1D(bLines[lidx].nVertices, 64); + + int enq_res = enqueue_kernel(def_q, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, + ^{ computeBezierLinePositions(lidx, bLines, bLines[lidx].nVertices, buf); }); + } + } + \n + __kernel + void computeBezierLines2(__global struct BezierLine* bLines, int nLines, __global char* buf) + { + int lidx = get_global_id(0); + + if (lidx < nLines) { + float curvature = length(bLines[lidx].CP[1] - 0.5f * (bLines[lidx].CP[0] + bLines[lidx].CP[2])) / + length(bLines[lidx].CP[2] - bLines[lidx].CP[0]); + int nTessPoints = min(max((int)(curvature * 16.0f), 4), MAX_TESSELLATION); + + if (bLines[lidx].vertexPos == 0) { + bLines[lidx].nVertices = nTessPoints; + uint value = atomic_add((__global volatile uint*)buf, + nTessPoints * sizeof(float2)); + bLines[lidx].vertexPos = (ulong)(&buf[value]); + } + } + } + \n + ) +}; + +OCLDynamicBLines::OCLDynamicBLines() { + _numSubTests = 1; + deviceQueue_ = NULL; + failed_ = false; + bLines_ = NULL; + hostArray_ = NULL; + kernel2_ = NULL; + kernel3_ = NULL; +} + +OCLDynamicBLines::~OCLDynamicBLines() {} + +void OCLDynamicBLines::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + if (type_ == CL_DEVICE_TYPE_CPU) { + return; + } + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + testID_ = test; + + size_t param_size = 0; + char* strVersion = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 0, + 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[7] < '2') { + failed_ = true; + return; + } + delete strVersion; + + char dbuffer[1024] = {0}; + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel[test], + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "computeBezierLines", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + kernel2_ = _wrapper->clCreateKernel(program_, "computeBezierLines2", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + kernel3_ = + _wrapper->clCreateKernel(program_, "computeBezierLinePositions", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + bLines_ = new BezierLine[nLines]; + + cl_float2 last = {0, 0}; + for (int i = 0; i < nLines; i++) { + bLines_[i].CP[0] = last; + + for (int j = 1; j < 3; j++) { + bLines_[i].CP[j].s[0] = (float)rand() / (float)RAND_MAX; + bLines_[i].CP[j].s[1] = (float)rand() / (float)RAND_MAX; + } + + last = bLines_[i].CP[2]; + bLines_[i].vertexPos = 0; + bLines_[i].nVertices = 0; + bLines_[i].reserved = 0; + } + + buffer = + _wrapper->clCreateBuffer(context_, CL_MEM_USE_HOST_PTR, + sizeof(BezierLine) * nLines, bLines_, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + + hostArray_ = new cl_float2[nLines * (MAX_TESSELLATION + 1)]; + ((unsigned int*)hostArray_)[0] = sizeof(cl_float2); + buffer = _wrapper->clCreateBuffer( + context_, CL_MEM_USE_HOST_PTR, + sizeof(cl_float2) * nLines * MAX_TESSELLATION, hostArray_, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + + cl_uint queueSize = 256 * 1024; +#if defined(CL_VERSION_2_0) + const cl_queue_properties cprops[] = { + CL_QUEUE_PROPERTIES, + static_cast(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | + CL_QUEUE_ON_DEVICE_DEFAULT | + CL_QUEUE_ON_DEVICE), + CL_QUEUE_SIZE, queueSize, 0}; + deviceQueue_ = _wrapper->clCreateCommandQueueWithProperties( + context_, devices_[deviceId], cprops, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateCommandQueueWithProperties() failed"); +#endif +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLDynamicBLines::run(void) { + CPerfCounter timer; + if (type_ == CL_DEVICE_TYPE_CPU) { + return; + } + + if (failed_) return; + + cl_mem buffer = buffers()[0]; + cl_mem alloc = buffers()[1]; + + size_t gws[1] = {nLines}; + size_t lws[1] = {blockDim}; + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + error_ |= _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_int), &nLines); + error_ |= _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_mem), &alloc); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + + for (int i = 0; i < nLines; i++) { + bLines_[i].vertexPos = 0; + bLines_[i].nVertices = 0; + bLines_[i].reserved = 0; + } + ((unsigned int*)hostArray_)[0] = sizeof(cl_float2); + + timer.Reset(); + timer.Start(); + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + timer.Stop(); + double sec = timer.GetElapsedTime(); + + for (int i = 0; i < nLines; i++) { + bLines_[i].vertexPos = 0; + bLines_[i].nVertices = 0; + bLines_[i].reserved = 0; + } + unsigned int allocSize = ((unsigned int*)hostArray_)[0]; + ((unsigned int*)hostArray_)[0] = sizeof(cl_float2); + + // + // Host emulation + // + timer.Reset(); + timer.Start(); + // Step 1. Fill the jobs + error_ = _wrapper->clSetKernelArg(kernel2_, 0, sizeof(cl_mem), &buffer); + error_ |= _wrapper->clSetKernelArg(kernel2_, 1, sizeof(cl_int), &nLines); + error_ |= _wrapper->clSetKernelArg(kernel2_, 2, sizeof(cl_mem), &alloc); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel2_, 1, + NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + _wrapper->clFinish(cmdQueues_[_deviceId]); + + // Step 2. Run all jobs + for (int lidx = 0; lidx < nLines; lidx++) { + // Readback the new dimension. + error_ = _wrapper->clSetKernelArg(kernel3_, 0, sizeof(cl_int), &lidx); + error_ |= _wrapper->clSetKernelArg(kernel3_, 1, sizeof(cl_mem), &buffer); + error_ |= _wrapper->clSetKernelArg(kernel3_, 2, sizeof(cl_int), + &bLines_[lidx].nVertices); + error_ |= _wrapper->clSetKernelArg(kernel3_, 3, sizeof(cl_mem), &alloc); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t gwsL[1] = {static_cast(bLines_[lidx].nVertices)}; + size_t lwsL[1] = {blockDim}; + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel3_, + 1, NULL, gws, lws, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + + _wrapper->clFinish(cmdQueues_[_deviceId]); + timer.Stop(); + double sec2 = timer.GetElapsedTime(); + + if (memcmp(&allocSize, hostArray_, sizeof(cl_uint)) != 0) { + CHECK_RESULT(true, "Validaiton failed!"); + } + + if (sec >= sec2) { + _perfInfo = (float)(sec2 - sec); + CHECK_RESULT(true, "Device enqueue is slower than emulation (sec)"); + return; + } + + _perfInfo = (float)(((sec2 - sec) / sec) * 100); + testDescString = "Device enqueue is (%%) faster"; +} + +unsigned int OCLDynamicBLines::close(void) { + // FIXME: Re-enable CPU test once bug 10143 is fixed. + if (type_ == CL_DEVICE_TYPE_CPU) { + return 0; + } + + delete[] bLines_; + delete[] hostArray_; + + if (NULL != deviceQueue_) { + _wrapper->clReleaseCommandQueue(deviceQueue_); + } + if (NULL != kernel2_) { + _wrapper->clReleaseKernel(kernel2_); + } + if (NULL != kernel3_) { + _wrapper->clReleaseKernel(kernel3_); + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/runtime/OCLDynamicBLines.h b/opencl/tests/ocltst/module/runtime/OCLDynamicBLines.h new file mode 100644 index 0000000000..8a7c6fa2bc --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLDynamicBLines.h @@ -0,0 +1,54 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_DYNAMIC_BLINES_H_ +#define _OCL_DYNAMIC_BLINES_H_ + +#include "OCLTestImp.h" + +class OCLDynamicBLines : public OCLTestImp { + public: + OCLDynamicBLines(); + virtual ~OCLDynamicBLines(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + struct BezierLine { + cl_float2 CP[3]; + long long vertexPos; + int nVertices; + int reserved; + }; + + cl_command_queue deviceQueue_; + bool failed_; + unsigned int testID_; + BezierLine* bLines_; + cl_float2* hostArray_; + cl_kernel kernel2_; + cl_kernel kernel3_; +}; + +#endif // _OCL_DYNAMIC_BLINES__H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLGenericAddressSpace.cpp b/opencl/tests/ocltst/module/runtime/OCLGenericAddressSpace.cpp new file mode 100644 index 0000000000..dd68824ea7 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLGenericAddressSpace.cpp @@ -0,0 +1,819 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGenericAddressSpace.h" + +#include "CL/cl.h" + +#define TO_LOCAL_FAIL 0x000f0 +#define TO_GLOBAL_FAIL 0x00e00 +#define TO_PRIVATE_FAIL 0x0d000 +#define WRONG_VALUE 0xc0000 + +OCLGenericAddressSpace::OCLGenericAddressSpace() { _numSubTests = 7; } + +OCLGenericAddressSpace::~OCLGenericAddressSpace() {} + +void OCLGenericAddressSpace::open(unsigned int test, char* units, + double& conversion, unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "error_ opening test"); + silentFailure = false; + _openTest = test; + size_t param_size = 0; + program_ = 0; + kernel_ = 0; + char* strVersion = 0; +#if EMU_ENV + arrSize = 10; +#else + arrSize = 1000; +#endif // EMU_ENV + error_ = _wrapper->clGetDeviceInfo( + devices_[_deviceId], CL_DEVICE_OPENCL_C_VERSION, 0, 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + strVersion = (char*)malloc(param_size); + error_ = + _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_OPENCL_C_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + if (strVersion[9] < '2') { + printf("\nOpenCL C 2.0 not supported\n"); + silentFailure = true; + } + free(strVersion); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLGenericAddressSpace::run(void) { + if (silentFailure) return; + switch (_openTest) { + case 0: + test0(); + break; + case 1: + test1(); + break; + case 2: + test2(); + break; + case 3: + test3(); + break; + case 4: + test4(); + break; + case 5: + test5(); + break; + case 6: + test6(); + break; + } + return; +} + +void OCLGenericAddressSpace::test6(void) { + const char* kernel_str = + "\n\ + __global unsigned int gint = 1; \n\ + __kernel void test(__global ulong *results) \n\ + { \n\ + uint tid = get_global_id(0); \n\ + unsigned int *ptr; \n\ + __private unsigned int pint = tid + 2; \n\ + if ((tid % 2) == 0) { \n\ + ptr = &pint; \n\ + } \n\ + else { \n\ + ptr = &gint; \n\ + } \n\ + results[0] = *ptr;\n\ + results[1] = pint;\n\ + results[2] = (ulong)ptr;\n\ + results[3] = (ulong)to_private(ptr);\n\ + results[4] = (ulong)&pint;\n\ + } \n"; + const size_t global_work_size = 1; + const size_t arrSize = global_work_size * 5; + cl_ulong* output_arr = (cl_ulong*)malloc(arrSize * sizeof(cl_ulong)); + memset(output_arr, 0, arrSize * sizeof(cl_ulong)); + cl_mem buffer = _wrapper->clCreateBuffer( + context_, CL_MEM_READ_WRITE, arrSize * sizeof(cl_ulong), 0, &error_); + buffers_.push_back(buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &kernel_str, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char log[400]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 400, log, 0); + printf("\n\n%s\n\n", log); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram failed"); + kernel_ = _wrapper->clCreateKernel(program_, "test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel failed"); + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + cl_event evt; + + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, NULL, + &global_work_size, NULL, 0, NULL, &evt); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers_[0], + CL_TRUE, 0, sizeof(cl_ulong) * arrSize, + output_arr, 1, &evt, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed"); + if (output_arr[0] != 2) { + printf( + "\n*ptr:0x%llx, pint:0x%llx, ptr:0x%llx, to_private(ptr):0x%llx, " + "&pint:0x%llx", + (unsigned long long)output_arr[0], (unsigned long long)output_arr[1], + (unsigned long long)output_arr[2], (unsigned long long)output_arr[3], + (unsigned long long)output_arr[4]); + printf("\n\n"); + error_ = 1; + } + free(output_arr); + CHECK_RESULT((error_ != CL_SUCCESS), "Generic Address Space - test2 failed"); +} + +void OCLGenericAddressSpace::test5(void) { + const char* kernel_str = + "\n\ + __global unsigned int gint = 1; \n\ + __kernel void test(__global ulong *results) \n\ + { \n\ + uint tid = get_global_id(0); \n\ + results[tid] = 0; \n\ + unsigned int *ptr; \n\ + __local unsigned int lint; \n\ + lint = 2; \n\ + if ((tid % 2) == 0) { \n\ + ptr = &lint; \n\ + } \n\ + else { \n\ + ptr = &gint; \n\ + } \n\ + barrier(CLK_GLOBAL_MEM_FENCE); \n\ + if ((tid % 2) == 0) { \n\ + results[tid*5] = *ptr;\n\ + results[tid*5+1] = lint;\n\ + results[tid*5+2] = (ulong)ptr;\n\ + results[tid*5+3] = (ulong)to_local(ptr);\n\ + results[tid*5+4] = (ulong)&lint;\n\ + } \n\ + else { \n\ + results[tid*5] = *ptr;\n\ + results[tid*5+1] = gint;\n\ + results[tid*5+2] = (ulong)ptr;\n\ + results[tid*5+3] = (ulong)to_global(ptr);\n\ + results[tid*5+4] = (ulong)&gint;\n\ + } \n\ + } \n"; + const size_t global_work_size = 2; + const size_t arrSize = global_work_size * 5; + cl_ulong* output_arr = (cl_ulong*)malloc(arrSize * sizeof(cl_ulong)); + memset(output_arr, 0, arrSize * sizeof(cl_ulong)); + cl_mem buffer = _wrapper->clCreateBuffer( + context_, CL_MEM_READ_WRITE, arrSize * sizeof(cl_ulong), 0, &error_); + buffers_.push_back(buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &kernel_str, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char log[400]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 400, log, 0); + printf("\n\n%s\n\n", log); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram failed"); + kernel_ = _wrapper->clCreateKernel(program_, "test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel failed"); + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + cl_event evt; + + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, NULL, + &global_work_size, NULL, 0, NULL, &evt); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers_[0], + CL_TRUE, 0, sizeof(cl_ulong) * arrSize, + output_arr, 1, &evt, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed"); + int error_cnt = 0; + for (unsigned int i = 0; i < global_work_size; ++i) { + if (((i % 2 == 0) && (output_arr[i * 5] != 2)) || + ((i % 2 == 1) && (output_arr[i * 5] != 1))) { + ++error_cnt; + } + } + if (error_cnt) { + printf("\nNumber of wrong results: %d/%d\n\n", error_cnt, + (int)global_work_size); + for (unsigned int i = 0; i < global_work_size; ++i) { + if (i % 2 == 0) { + printf( + "\n*ptr:0x%llx, lint:0x%llx, ptr:0x%llx, to_local(ptr):0x%llx, " + "&lint:0x%llx", + (unsigned long long)output_arr[i * 5], + (unsigned long long)output_arr[i * 5 + 1], + (unsigned long long)output_arr[i * 5 + 2], + (unsigned long long)output_arr[i * 5 + 3], + (unsigned long long)output_arr[i * 5 + 4]); + } else { + printf( + "\n*ptr:0x%llx, gint:0x%llx, ptr:0x%llx, to_global(ptr):0x%llx, " + "&gint:0x%llx", + (unsigned long long)output_arr[i * 5], + (unsigned long long)output_arr[i * 5 + 1], + (unsigned long long)output_arr[i * 5 + 2], + (unsigned long long)output_arr[i * 5 + 3], + (unsigned long long)output_arr[i * 5 + 4]); + } + } + printf("\n\n"); + } + free(output_arr); + CHECK_RESULT((error_cnt != 0), "Generic Address Space - test2 failed"); +} + +void OCLGenericAddressSpace::test4(void) { + const char* kernel_str = + "\n\ + __global unsigned int gint = 1; \n\ + __kernel void test(__global ulong *results) \n\ + { \n\ + uint tid = get_global_id(0); \n\ + results[tid] = 0; \n\ + unsigned int *ptr; \n\ + __private unsigned int pint = 2; \n\ + if ((tid % 2) == 0) { \n\ + ptr = &pint; \n\ + } \n\ + else { \n\ + ptr = &gint; \n\ + } \n\ + barrier(CLK_GLOBAL_MEM_FENCE); \n\ + if ((tid % 2) == 0) { \n\ + results[tid*5] = *ptr;\n\ + results[tid*5+1] = pint;\n\ + results[tid*5+2] = (ulong)ptr;\n\ + results[tid*5+3] = (ulong)to_private(ptr);\n\ + results[tid*5+4] = (ulong)&pint;\n\ + } \n\ + else { \n\ + results[tid*5] = *ptr;\n\ + results[tid*5+1] = gint;\n\ + results[tid*5+2] = (ulong)ptr;\n\ + results[tid*5+3] = (ulong)to_global(ptr);\n\ + results[tid*5+4] = (ulong)&gint;\n\ + } \n\ + } \n"; + const size_t global_work_size = 2; + const size_t arrSize = global_work_size * 5; + cl_ulong* output_arr = (cl_ulong*)malloc(arrSize * sizeof(cl_ulong)); + memset(output_arr, 0, arrSize * sizeof(cl_ulong)); + cl_mem buffer = _wrapper->clCreateBuffer( + context_, CL_MEM_READ_WRITE, arrSize * sizeof(cl_ulong), 0, &error_); + buffers_.push_back(buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &kernel_str, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char log[400]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 400, log, 0); + printf("\n\n%s\n\n", log); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram failed"); + kernel_ = _wrapper->clCreateKernel(program_, "test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel failed"); + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + cl_event evt; + + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, NULL, + &global_work_size, NULL, 0, NULL, &evt); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers_[0], + CL_TRUE, 0, sizeof(cl_ulong) * arrSize, + output_arr, 1, &evt, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed"); + int error_cnt = 0; + for (unsigned int i = 0; i < global_work_size; ++i) { + if (((i % 2 == 0) && (output_arr[i * 5] != 2)) || + ((i % 2 == 1) && (output_arr[i * 5] != 1))) { + ++error_cnt; + } + } + if (error_cnt) { + printf("\nNumber of wrong results: %d/%d\n\n", error_cnt, + (int)global_work_size); + for (unsigned int i = 0; i < global_work_size; ++i) { + if (i % 2 == 0) { + printf( + "\n*ptr:0x%llx, pint:0x%llx, ptr:0x%llx, to_private(ptr):0x%llx, " + "&pint:0x%llx", + (unsigned long long)output_arr[i * 5], + (unsigned long long)output_arr[i * 5 + 1], + (unsigned long long)output_arr[i * 5 + 2], + (unsigned long long)output_arr[i * 5 + 3], + (unsigned long long)output_arr[i * 5 + 4]); + } else { + printf( + "\n*ptr:0x%llx, gint:0x%llx, ptr:0x%llx, to_global(ptr):0x%llx, " + "&gint:0x%llx", + (unsigned long long)output_arr[i * 5], + (unsigned long long)output_arr[i * 5 + 1], + (unsigned long long)output_arr[i * 5 + 2], + (unsigned long long)output_arr[i * 5 + 3], + (unsigned long long)output_arr[i * 5 + 4]); + } + } + printf("\n\n"); + } + free(output_arr); + CHECK_RESULT((error_cnt != 0), "Generic Address Space - test2 failed"); +} + +void OCLGenericAddressSpace::test3(void) { + const char* kernel_str = + "\n\ + #define TO_LOCAL_FAIL 0x000f0\n\ + #define TO_GLOBAL_FAIL 0x00e00\n\ + #define TO_PRIVATE_FAIL 0x0d000\n\ + #define WRONG_VALUE 0xc0000\n\ + __global unsigned int gint = 1; \n\ + __kernel void test(__global uint *results) \n\ + { \n\ + uint tid = get_global_id(0); \n\ + results[tid] = 0; \n\ + unsigned int *ptr; \n\ + __local unsigned int lint; \n\ + lint = 2; \n\ + __private unsigned int pint = 3; \n\ + switch (tid % 3) \n\ + {\n\ + case 0:\n\ + ptr = &gint; break; \n\ + case 1:\n\ + ptr = &lint; break; \n\ + case 2:\n\ + ptr = &pint; break; \n\ + }\n\ + barrier(CLK_GLOBAL_MEM_FENCE); \n\ + switch (tid % 3) \n\ + {\n\ + case 0:\n\ + if(to_global(ptr) && (*ptr == 1))\n\ + {\n\ + results[tid] = *ptr;\n\ + }\n\ + else\n\ + {\n\ + if (*ptr != 1) results[tid] = WRONG_VALUE;\n\ + if(!to_global(ptr)) results[tid] |= TO_GLOBAL_FAIL;\n\ + }\n\ + break; \n\ + case 1:\n\ + if(to_local(ptr) && (*ptr == 2))\n\ + {\n\ + results[tid] = *ptr;\n\ + }\n\ + else\n\ + {\n\ + if (*ptr != 2) results[tid] = WRONG_VALUE;\n\ + if(!to_local(ptr)) results[tid] |= TO_LOCAL_FAIL;\n\ + }\n\ + break; \n\ + case 2:\n\ + if(to_private(ptr) && (*ptr == 3))\n\ + {\n\ + results[tid] = *ptr;\n\ + }\n\ + else\n\ + {\n\ + if (*ptr != 3) results[tid] = WRONG_VALUE;\n\ + if(!to_private(ptr)) results[tid] |= TO_PRIVATE_FAIL;\n\ + }\n\ + break; \n\ + }\n\ + } \n"; + cl_uint* output_arr = (cl_uint*)malloc(arrSize * sizeof(cl_uint)); + memset(output_arr, 0, arrSize * sizeof(cl_uint)); + cl_mem buffer = _wrapper->clCreateBuffer( + context_, CL_MEM_READ_WRITE, arrSize * sizeof(cl_uint), 0, &error_); + buffers_.push_back(buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &kernel_str, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char log[400]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 400, log, 0); + printf("\n\n%s\n\n", log); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram failed"); + kernel_ = _wrapper->clCreateKernel(program_, "test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel failed"); + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + cl_event evt; + size_t global_work_size = arrSize; + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, NULL, + &global_work_size, NULL, 0, NULL, &evt); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers_[0], + CL_TRUE, 0, sizeof(cl_uint) * arrSize, + output_arr, 1, &evt, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed"); + int error_cnt = 0; + int wrong_values = 0; + int to_local_error = 0; + int to_global_error = 0; + int to_private_error = 0; + for (unsigned int i = 0; i < arrSize; ++i) { + switch (i % 3) { + case 0: + error_cnt += (output_arr[i] != 1); + break; + case 1: + error_cnt += (output_arr[i] != 2); + break; + case 2: + error_cnt += (output_arr[i] != 3); + break; + } + if (output_arr[i] & WRONG_VALUE) ++wrong_values; + if (output_arr[i] & TO_LOCAL_FAIL) ++to_local_error; + if (output_arr[i] & TO_GLOBAL_FAIL) ++to_global_error; + if (output_arr[i] & TO_PRIVATE_FAIL) ++to_private_error; + } + if (error_cnt) { + printf("\nNumber of wrong results: %d/%d ", error_cnt, (int)arrSize); + printf( + "wrong values: %d to_local_error: %d, to_global_error: %d, " + "to_private_error: %d\n", + wrong_values, to_local_error, to_global_error, to_private_error); + } + free(output_arr); + CHECK_RESULT((error_cnt != 0), "Generic Address Space - test3 failed"); +} + +void OCLGenericAddressSpace::test2(void) { + const char* kernel_str = + "\n\ + #define TO_LOCAL_FAIL 0x000f0\n\ + #define TO_GLOBAL_FAIL 0x00e00\n\ + #define TO_PRIVATE_FAIL 0x0d000\n\ + #define WRONG_VALUE 0xc0000\n\ + __global unsigned int gint = 1; \n\ + __kernel void test(__global uint *results) \n\ + { \n\ + uint tid = get_global_id(0); \n\ + results[tid] = 0; \n\ + unsigned int *ptr; \n\ + __private unsigned int pint = 2; \n\ + if ((tid % 2) == 0) { \n\ + ptr = &pint; \n\ + } \n\ + else { \n\ + ptr = &gint; \n\ + } \n\ + barrier(CLK_GLOBAL_MEM_FENCE); \n\ + if ((tid % 2) == 0) { \n\ + if (to_private(ptr) && *ptr == 2) {\n\ + results[tid] = *ptr;\n\ + }\n\ + else {\n\ + if (*ptr != 2) results[tid] = WRONG_VALUE;\n\ + if(!to_private(ptr)) results[tid] |= TO_PRIVATE_FAIL;\n\ + }\n\ + } \n\ + else { \n\ + if (to_global(ptr) && *ptr == 1) {\n\ + results[tid] = *ptr;\n\ + }\n\ + else {\n\ + if (*ptr != 1) results[tid] = WRONG_VALUE;\n\ + if(!to_global(ptr)) results[tid] |= TO_GLOBAL_FAIL;\n\ + }\n\ + } \n\ + } \n"; + cl_uint* output_arr = (cl_uint*)malloc(arrSize * sizeof(cl_uint)); + memset(output_arr, 0, arrSize * sizeof(cl_uint)); + cl_mem buffer = _wrapper->clCreateBuffer( + context_, CL_MEM_READ_WRITE, arrSize * sizeof(cl_uint), 0, &error_); + buffers_.push_back(buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &kernel_str, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char log[400]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 400, log, 0); + printf("\n\n%s\n\n", log); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram failed"); + kernel_ = _wrapper->clCreateKernel(program_, "test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel failed"); + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + cl_event evt; + size_t global_work_size = arrSize; + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, NULL, + &global_work_size, NULL, 0, NULL, &evt); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers_[0], + CL_TRUE, 0, sizeof(cl_uint) * arrSize, + output_arr, 1, &evt, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed"); + int error_cnt = 0; + int wrong_values = 0; + int to_local_error = 0; + int to_global_error = 0; + int to_private_error = 0; + + for (unsigned int i = 0; i < arrSize; ++i) { + if (((i % 2 == 0) && (output_arr[i] != 2)) || + ((i % 2 == 1) && (output_arr[i] != 1))) { + if (output_arr[i] & WRONG_VALUE) ++wrong_values; + if (output_arr[i] & TO_LOCAL_FAIL) ++to_local_error; + if (output_arr[i] & TO_GLOBAL_FAIL) ++to_global_error; + if (output_arr[i] & TO_PRIVATE_FAIL) ++to_private_error; + ++error_cnt; + } + } + free(output_arr); + if (error_cnt) { + printf("\nNumber of wrong results: %d/%d", error_cnt, (int)arrSize); + printf( + "wrong values: %d to_local_error: %d, to_global_error: %d, " + "to_private_error: %d\n", + wrong_values, to_local_error, to_global_error, to_private_error); + } + CHECK_RESULT((error_cnt != 0), "Generic Address Space - test2 failed"); +} + +void OCLGenericAddressSpace::test1(void) { + const char* kernel_str = + "\n\ + #define TO_LOCAL_FAIL 0x000f0\n\ + #define TO_GLOBAL_FAIL 0x00e00\n\ + #define TO_PRIVATE_FAIL 0x0d000\n\ + #define WRONG_VALUE 0xc0000\n\ + __global unsigned int gint1 = 1; \n\ + __global unsigned int gint2 = 2; \n\ + __kernel void test(__global uint *results) \n\ + { \n\ + uint tid = get_global_id(0); \n\ + results[tid] = 0; \n\ + unsigned int *ptr; \n\ + if ((tid % 2) == 0) { \n\ + ptr = &gint2; \n\ + } \n\ + else { \n\ + ptr = &gint1; \n\ + } \n\ + barrier(CLK_GLOBAL_MEM_FENCE); \n\ + if ((tid % 2) == 0) { \n\ + if (to_global(ptr) && *ptr == 2) {\n\ + results[tid] = *ptr;\n\ + }\n\ + else {\n\ + if (*ptr != 2) results[tid] = WRONG_VALUE;\n\ + if(!to_global(ptr)) results[tid] |= TO_GLOBAL_FAIL;\n\ + }\n\ + } \n\ + else { \n\ + if (to_global(ptr) && *ptr == 1) {\n\ + results[tid] = *ptr;\n\ + }\n\ + else {\n\ + if (*ptr != 1) results[tid] = WRONG_VALUE;\n\ + if(!to_global(ptr)) results[tid] |= TO_GLOBAL_FAIL;\n\ + }\n\ + } \n\ + } \n"; + cl_uint* output_arr = (cl_uint*)malloc(arrSize * sizeof(cl_uint)); + memset(output_arr, 0, arrSize * sizeof(cl_uint)); + cl_mem buffer = _wrapper->clCreateBuffer( + context_, CL_MEM_READ_WRITE, arrSize * sizeof(cl_uint), 0, &error_); + buffers_.push_back(buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &kernel_str, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char log[400]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 400, log, 0); + printf("\n\n%s\n\n", log); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram failed"); + kernel_ = _wrapper->clCreateKernel(program_, "test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel failed"); + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + cl_event evt; + size_t global_work_size = arrSize; + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, NULL, + &global_work_size, NULL, 0, NULL, &evt); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers_[0], + CL_TRUE, 0, sizeof(cl_uint) * arrSize, + output_arr, 1, &evt, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed"); + int error_cnt = 0; + int wrong_values = 0; + int to_local_error = 0; + int to_global_error = 0; + int to_private_error = 0; + + for (unsigned int i = 0; i < arrSize; ++i) { + if (((i % 2 == 0) && (output_arr[i] != 2)) || + ((i % 2 == 1) && (output_arr[i] != 1))) { + if (output_arr[i] & WRONG_VALUE) ++wrong_values; + if (output_arr[i] & TO_LOCAL_FAIL) ++to_local_error; + if (output_arr[i] & TO_GLOBAL_FAIL) ++to_global_error; + if (output_arr[i] & TO_PRIVATE_FAIL) ++to_private_error; + ++error_cnt; + } + } + free(output_arr); + if (error_cnt) { + printf("\nNumber of wrong results: %d/%d", error_cnt, (int)arrSize); + printf( + "wrong values: %d to_local_error: %d, to_global_error: %d, " + "to_private_error: %d\n", + wrong_values, to_local_error, to_global_error, to_private_error); + } + CHECK_RESULT((error_cnt != 0), "Generic Address Space - test1 failed"); +} + +void OCLGenericAddressSpace::test0(void) { + const char* kernel_str = + "\n\ + #define TO_LOCAL_FAIL 0x000f0\n\ + #define TO_GLOBAL_FAIL 0x00e00\n\ + #define TO_PRIVATE_FAIL 0x0d000\n\ + #define WRONG_VALUE 0xc0000\n\ + __global unsigned int gint = 1; \n\ + __kernel void test(__global uint *results) \n\ + { \n\ + uint tid = get_global_id(0); \n\ + results[tid] = 0; \n\ + unsigned int *ptr; \n\ + __local unsigned int lint; \n\ + lint = 2; \n\ + if ((tid % 2) == 0) { \n\ + ptr = &lint; \n\ + } \n\ + else { \n\ + ptr = &gint; \n\ + } \n\ + barrier(CLK_GLOBAL_MEM_FENCE); \n\ + if ((tid % 2) == 0) { \n\ + if (to_local(ptr) && *ptr == 2) {\n\ + results[tid] = *ptr;\n\ + }\n\ + else {\n\ + if (*ptr != 2) results[tid] = WRONG_VALUE;\n\ + if(!to_local(ptr)) results[tid] |= TO_LOCAL_FAIL;\n\ + }\n\ + } \n\ + else { \n\ + if (to_global(ptr) && *ptr == 1) {\n\ + results[tid] = *ptr;\n\ + }\n\ + else {\n\ + if (*ptr != 1) results[tid] = WRONG_VALUE;\n\ + if(!to_global(ptr)) results[tid] |= TO_GLOBAL_FAIL;\n\ + }\n\ + } \n\ + } \n"; + cl_uint* output_arr = (cl_uint*)malloc(arrSize * sizeof(cl_uint)); + memset(output_arr, 0, arrSize * sizeof(cl_uint)); + cl_mem buffer = _wrapper->clCreateBuffer( + context_, CL_MEM_READ_WRITE, arrSize * sizeof(cl_uint), 0, &error_); + buffers_.push_back(buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &kernel_str, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char log[400]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 400, log, 0); + printf("\n\n%s\n\n", log); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram failed"); + kernel_ = _wrapper->clCreateKernel(program_, "test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel failed"); + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + cl_event evt; + size_t global_work_size = arrSize; + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, NULL, + &global_work_size, NULL, 0, NULL, &evt); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers_[0], + CL_TRUE, 0, sizeof(cl_uint) * arrSize, + output_arr, 1, &evt, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed"); + int error_cnt = 0; + int wrong_values = 0; + int to_local_error = 0; + int to_global_error = 0; + int to_private_error = 0; + + for (unsigned int i = 0; i < arrSize; ++i) { + if (((i % 2 == 0) && (output_arr[i] != 2)) || + ((i % 2 == 1) && (output_arr[i] != 1))) { + if (output_arr[i] & WRONG_VALUE) ++wrong_values; + if (output_arr[i] & TO_LOCAL_FAIL) ++to_local_error; + if (output_arr[i] & TO_GLOBAL_FAIL) ++to_global_error; + if (output_arr[i] & TO_PRIVATE_FAIL) ++to_private_error; + ++error_cnt; + } + } + free(output_arr); + if (error_cnt) { + printf("\nNumber of wrong results: %d/%d", error_cnt, (int)arrSize); + printf( + "wrong values: %d to_local_error: %d, to_global_error: %d, " + "to_private_error: %d\n", + wrong_values, to_local_error, to_global_error, to_private_error); + } + CHECK_RESULT((error_cnt != 0), "Generic Address Space - test0 failed"); +} + +unsigned int OCLGenericAddressSpace::close(void) { + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + kernel_ = 0; + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/runtime/OCLGenericAddressSpace.h b/opencl/tests/ocltst/module/runtime/OCLGenericAddressSpace.h new file mode 100644 index 0000000000..58fde3086e --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLGenericAddressSpace.h @@ -0,0 +1,50 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GenericAddressSpace_H_ +#define _OCL_GenericAddressSpace_H_ + +#include "OCLTestImp.h" + +class OCLGenericAddressSpace : public OCLTestImp { + public: + OCLGenericAddressSpace(); + virtual ~OCLGenericAddressSpace(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + void test0(void); + void test1(void); + void test2(void); + void test3(void); + void test4(void); + void test5(void); + void test6(void); + bool silentFailure; + cl_kernel kernel_; + size_t arrSize; +}; + +#endif // _OCL_GenericAddressSpace_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLGetQueueThreadID.cpp b/opencl/tests/ocltst/module/runtime/OCLGetQueueThreadID.cpp new file mode 100644 index 0000000000..e1b32f4cc7 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLGetQueueThreadID.cpp @@ -0,0 +1,116 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGetQueueThreadID.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +#if !defined(__linux__) +#include "WinBase.h" +typedef DWORD(WINAPI* GetThreadId)(__in HANDLE Thread); +#endif +bool badThread = false; + +OCLGetQueueThreadID::OCLGetQueueThreadID() { + _numSubTests = 1; + failed_ = false; +} + +OCLGetQueueThreadID::~OCLGetQueueThreadID() {} + +void OCLGetQueueThreadID::open(unsigned int test, char* units, + double& conversion, unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + char name[1024] = {0}; + size_t size = 0; + + if (deviceId >= deviceCount_) { + failed_ = true; + return; + } + + cl_mem buffer; + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); +} + +static void CL_CALLBACK notify_callback(cl_event event, + cl_int event_command_exec_status, + void* user_data) { +#if defined(__linux__) + pthread_t id = (pthread_t)user_data; + pthread_t handle = pthread_self(); +#else + HMODULE module = GetModuleHandle("kernel32.dll"); + GetThreadId getThreadId = + reinterpret_cast(GetProcAddress(module, "GetThreadId")); + if (NULL == getThreadId) { + return; + } + DWORD id = getThreadId((HANDLE)user_data); + DWORD handle = GetCurrentThreadId(); +#endif + if (id != handle) { + badThread = true; + } +} + +void OCLGetQueueThreadID::run(void) { + if (failed_) { + return; + } + void* handle; + cl_event clEvent; + cl_event userEvent = clCreateUserEvent(context_, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateUserEvent() failed"); + + cl_uint initVal[2] = {5, 10}; + error_ = _wrapper->clGetCommandQueueInfo(cmdQueues_[_deviceId], + CL_QUEUE_THREAD_HANDLE_AMD, + sizeof(void*), &handle, NULL); + error_ = _wrapper->clEnqueueWriteBuffer(cmdQueues_[_deviceId], buffers()[0], + false, 0, sizeof(cl_uint), + &initVal[0], 1, &userEvent, &clEvent); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + + error_ = _wrapper->clSetEventCallback(clEvent, CL_SUBMITTED, notify_callback, + handle); + + clSetUserEventStatus(userEvent, CL_COMPLETE); + + clFinish(cmdQueues_[_deviceId]); + + clReleaseEvent(clEvent); + + clReleaseEvent(userEvent); + + CHECK_RESULT(badThread, "Thread ID is incorrect!"); +} + +unsigned int OCLGetQueueThreadID::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLGetQueueThreadID.h b/opencl/tests/ocltst/module/runtime/OCLGetQueueThreadID.h new file mode 100644 index 0000000000..b3cf1fbaa8 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLGetQueueThreadID.h @@ -0,0 +1,41 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GET_QUEUE_THREAD_ID_H_ +#define _OCL_GET_QUEUE_THREAD_ID_H_ + +#include "OCLTestImp.h" + +class OCLGetQueueThreadID : public OCLTestImp { + public: + OCLGetQueueThreadID(); + virtual ~OCLGetQueueThreadID(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; +}; + +#endif // _OCL_GET_QUEUE_THREAD_ID_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLGlobalOffset.cpp b/opencl/tests/ocltst/module/runtime/OCLGlobalOffset.cpp new file mode 100644 index 0000000000..48aa50b1c1 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLGlobalOffset.cpp @@ -0,0 +1,126 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLGlobalOffset.h" + +#include +#include +#include + +#include "CL/cl.h" + +const static cl_uint ThreadsForCheck = 2; +const static cl_uint GlobalOffset = 64; + +const static char* strKernel = + "__kernel void global_offset_test( \n" + " global uint* out_val) \n" + "{ \n" + " // Check the first thread \n" + " if (get_global_id(0) == get_global_offset(0)) { \n" + " out_val[0] = (uint)get_global_offset(0); \n" + " } \n" + " // Check the last thread \n" + " if (get_global_id(0) == (get_global_size(0) + get_global_offset(0) - " + "1)) { \n" + " out_val[1] = (uint)get_global_offset(0); \n" + " } \n" + "} \n"; + +OCLGlobalOffset::OCLGlobalOffset() { _numSubTests = 1; } + +OCLGlobalOffset::~OCLGlobalOffset() {} + +void OCLGlobalOffset::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + char dbuffer[1024] = {0}; + _wrapper->clGetDeviceInfo(devices_[0], CL_DEVICE_VERSION, 1024, dbuffer, + NULL); + if (strstr(dbuffer, "OpenCL 1.0")) { + return; + } + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "global_offset_test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + ThreadsForCheck * sizeof(cl_uint), NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLGlobalOffset::run(void) { + char dbuffer[1024] = {0}; + _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 1024, + dbuffer, NULL); + if (strstr(dbuffer, "OpenCL 1.0")) { + return; + } + cl_uint offsetValues[ThreadsForCheck] = {0xffffffff, 0xffffffff}; + cl_mem buffer = buffers()[0]; + error_ = _wrapper->clEnqueueWriteBuffer(cmdQueues_[_deviceId], buffer, true, + 0, ThreadsForCheck * sizeof(cl_uint), + offsetValues, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t gws[1] = {0x0800000}; + size_t gwo[1] = {GlobalOffset}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + gwo, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffer, true, 0, + ThreadsForCheck * sizeof(cl_uint), + offsetValues, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + for (cl_uint i = 0; i < ThreadsForCheck; ++i) { + if (offsetValues[i] != GlobalOffset) { + printf("%d != %d", GlobalOffset, offsetValues[i]); + CHECK_RESULT(true, " - Incorrect result for global offset!\n"); + } + } +} + +unsigned int OCLGlobalOffset::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLGlobalOffset.h b/opencl/tests/ocltst/module/runtime/OCLGlobalOffset.h new file mode 100644 index 0000000000..839bf278d0 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLGlobalOffset.h @@ -0,0 +1,38 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_GLOBAL_OFFSET_H_ +#define _OCL_GLOBAL_OFFSET_H_ + +#include "OCLTestImp.h" + +class OCLGlobalOffset : public OCLTestImp { + public: + OCLGlobalOffset(); + virtual ~OCLGlobalOffset(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); +}; + +#endif // _OCL_GLOBAL_OFFSET_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLImage2DFromBuffer.cpp b/opencl/tests/ocltst/module/runtime/OCLImage2DFromBuffer.cpp new file mode 100644 index 0000000000..f604db5a62 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLImage2DFromBuffer.cpp @@ -0,0 +1,399 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLImage2DFromBuffer.h" + +#include +#include +#include +#include + +#define GROUP_SIZE 256 +const unsigned int OCLImage2DFromBuffer::imageWidth = 1920; +const unsigned int OCLImage2DFromBuffer::imageHeight = 1080; + +const static char strKernel[] = + "__constant sampler_t imageSampler = CLK_NORMALIZED_COORDS_FALSE | " + "CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; \n" + "__kernel void image2imageCopy( " + " \n" + " __read_only image2d_t input, " + " \n" + " __write_only image2d_t output) " + " \n" + "{ " + " \n" + " int2 coord = (int2)(get_global_id(0), get_global_id(1)); " + " \n" + " uint4 temp = read_imageui(input, imageSampler, coord); " + " \n" + " write_imageui(output, coord, temp); " + " \n" + "} " + " \n"; + +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clConvertImageAMD_fn)( + cl_context context, cl_mem image, const cl_image_format *image_format, + cl_int *errcode_ret); + +clConvertImageAMD_fn clConvertImageAMD; + +OCLImage2DFromBuffer::OCLImage2DFromBuffer() : OCLTestImp() { + _numSubTests = 6; + blockSizeX = GROUP_SIZE; + blockSizeY = 1; +} + +OCLImage2DFromBuffer::~OCLImage2DFromBuffer() {} + +void OCLImage2DFromBuffer::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + buffer = clImage2DOriginal = clImage2D = clImage2DOut = NULL; + done_ = false; + pitchAlignment = 0; + + _openTest = test; + // Initialize random number seed + srand((unsigned int)time(NULL)); + + OCLTestImp::open(test, units, conversion, deviceId); + if (_errorFlag) return; + + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + testDescString = "GPU device is required for this test!\n"; + done_ = true; + return; + } + + cl_bool imageSupport; + size_t size; + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport), &imageSupport, &size); + if (!imageSupport) { + testDescString = "Image not supported, skipping this test! "; + done_ = true; + return; + } + + if (_openTest >= 4) { + clConvertImageAMD = + (clConvertImageAMD_fn)clGetExtensionFunctionAddressForPlatform( + platform_, "clConvertImageAMD"); + if (clConvertImageAMD == NULL) { + testDescString = "clConvertImageAMD not found!\n"; + done_ = true; + return; + } + } + + CompileKernel(); + AllocateOpenCLImage(); +} + +void OCLImage2DFromBuffer::run(void) { + if (_errorFlag || done_) { + return; + } + + if ((_openTest % 2) == 0) { + testReadImage(clImage2D); + } else { + testKernel(); + } +} + +void OCLImage2DFromBuffer::AllocateOpenCLImage() { + const bool pitchTest = (_openTest == 2 || _openTest == 3); + cl_int status = 0; + + size_t size = 0; + pitchAlignment = 0; + status = _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_IMAGE_PITCH_ALIGNMENT, + sizeof(cl_uint), &pitchAlignment, &size); + + if (pitchAlignment != 0) { + pitchAlignment--; + } + + const unsigned int requiredPitch = + ((imageWidth + pitchAlignment) & ~pitchAlignment); + const unsigned int pitch = (!pitchTest) ? requiredPitch : imageWidth; + const size_t bufferSize = pitch * imageHeight; + CHECK_RESULT(bufferSize == 0, "ERROR: calculated image size is zero"); + + unsigned char *sourceData = new unsigned char[bufferSize]; + + // init data + for (unsigned int y = 0; y < imageHeight; y++) { + for (unsigned int x = 0; x < imageWidth / 4; x++) { + for (unsigned int p = 0; p < 4; p++) { + *(sourceData + y * pitch + x * 4 + p) = p; + } + } + } + buffer = _wrapper->clCreateBuffer(context_, + CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE, + bufferSize, sourceData, &status); + + { + // testing clConvertImageAMD + if (_openTest == 4 || _openTest == 5) { + const cl_image_format format = {CL_R, CL_UNSIGNED_INT8}; +#if defined(CL_VERSION_2_0) + const cl_image_desc desc = {CL_MEM_OBJECT_IMAGE2D, + imageWidth, + imageHeight, + 0, + 0, + pitch, + 0, + 0, + 0, + {buffer}}; +#else + const cl_image_desc desc = {CL_MEM_OBJECT_IMAGE2D, + imageWidth, + imageHeight, + 0, + 0, + pitch, + 0, + 0, + 0, + buffer}; +#endif + clImage2DOriginal = _wrapper->clCreateImage( + context_, CL_MEM_READ_WRITE, &format, &desc, NULL, &status); + CHECK_RESULT(status != CL_SUCCESS, "clCreateImage() failed"); + + const cl_image_format formatRGBA = {CL_RGBA, CL_UNSIGNED_INT8}; + + clImage2D = + clConvertImageAMD(context_, clImage2DOriginal, &formatRGBA, &status); + CHECK_RESULT(status != CL_SUCCESS, "clConvertImageAMD() failed"); + + cl_mem fishyBuffer = 0; + status = clGetImageInfo(clImage2D, CL_IMAGE_BUFFER, sizeof(fishyBuffer), + &fishyBuffer, 0); + CHECK_RESULT(status != CL_SUCCESS, + "clGetImageInfo(CL_IMAGE_BUFFER) failed"); + CHECK_RESULT(fishyBuffer != buffer, + "clGetImageInfo() failed, buffer != fishyBuffer"); + } else { + const cl_image_format format = {CL_RGBA, CL_UNSIGNED_INT8}; +#if defined(CL_VERSION_2_0) + const cl_image_desc desc = {CL_MEM_OBJECT_IMAGE2D, + imageWidth / 4, + imageHeight, + 0, + 0, + pitch, + 0, + 0, + 0, + {buffer}}; +#else + const cl_image_desc desc = {CL_MEM_OBJECT_IMAGE2D, + imageWidth / 4, + imageHeight, + 0, + 0, + pitch, + 0, + 0, + 0, + buffer}; +#endif + + clImage2D = _wrapper->clCreateImage(context_, CL_MEM_READ_WRITE, &format, + &desc, NULL, &status); + } + + // testing pitch alignment correct check in the runtime + if (pitchTest) { + CHECK_RESULT(requiredPitch != pitch && + (clImage2D != NULL || + status != CL_INVALID_IMAGE_FORMAT_DESCRIPTOR), + "AllocateOpenCLImage() failed: (clImage2D!=NULL || " + "status!=CL_INVALID_IMAGE_FORMAT_DESCRIPTOR) <=> (%p, %x)", + clImage2D, status); + if (requiredPitch != pitch) { + done_ = true; + return; + } + } + } + + delete[] sourceData; + + { + const cl_image_format format = {CL_RGBA, CL_UNSIGNED_INT8}; +#if defined(CL_VERSION_2_0) + const cl_image_desc desc = {CL_MEM_OBJECT_IMAGE2D, + imageWidth / 4, + imageHeight, + 0, + 0, + 0, + 0, + 0, + 0, + {NULL}}; +#else + const cl_image_desc desc = {CL_MEM_OBJECT_IMAGE2D, + imageWidth / 4, + imageHeight, + 0, + 0, + 0, + 0, + 0, + 0, + NULL}; +#endif + clImage2DOut = _wrapper->clCreateImage(context_, CL_MEM_READ_WRITE, &format, + &desc, NULL, &status); + } + CHECK_RESULT(clImage2D == NULL, "AllocateOpenCLImage() failed"); +} + +void OCLImage2DFromBuffer::testReadImage(cl_mem image) { + cl_int status = 0; + size_t bufferSize = imageWidth * imageHeight; + unsigned char *dstData = new unsigned char[bufferSize]; + + size_t origin[] = {0, 0, 0}; + size_t region[] = {imageWidth / 4, imageHeight, 1}; + + status = clEnqueueReadImage(cmdQueues_[_deviceId], image, 1, origin, region, + 0, 0, dstData, 0, 0, 0); + + ::clFinish(cmdQueues_[_deviceId]); + + for (unsigned int y = 0; y < imageHeight; y++) { + for (unsigned int x = 0; x < imageWidth / 4; x++) { + for (unsigned int p = 0; p < 4; p++) { + if (*(dstData + y * imageWidth + x * 4 + p) != p) { + CHECK_RESULT( + true, + "CheckCLImage: *(dstData+y*imageWidth+x*4+p)!=p => %i != %i", + *(dstData + y * imageWidth + x * 4 + p), p); + goto cleanup; + } + } + } + } +cleanup: + + delete[] dstData; +} + +void OCLImage2DFromBuffer::testKernel() { + CopyOpenCLImage(clImage2D); + + testReadImage(clImage2DOut); +} + +unsigned int OCLImage2DFromBuffer::close(void) { + if (clImage2DOriginal != NULL) clReleaseMemObject(clImage2DOriginal); + if (clImage2D != NULL) clReleaseMemObject(clImage2D); + if (clImage2DOut != NULL) clReleaseMemObject(clImage2DOut); + if (buffer != NULL) clReleaseMemObject(buffer); + return OCLTestImp::close(); +} + +void OCLImage2DFromBuffer::CopyOpenCLImage(cl_mem clImageSrc) { + cl_int status = 0; + + // Set appropriate arguments to the kernel2D + + // input buffer image + status = clSetKernelArg(kernel_, 0, sizeof(cl_mem), &clImageSrc); + CHECK_RESULT((status != CL_SUCCESS), + "CopyOpenCLImage() failed at " + "clSetKernelArg(kernel_,0,sizeof(cl_mem),&clImageSrc)"); + status = clSetKernelArg(kernel_, 1, sizeof(cl_mem), &clImage2DOut); + CHECK_RESULT((status != CL_SUCCESS), + "CopyOpenCLImage() failed at " + "clSetKernelArg(kernel_,1,sizeof(cl_mem),&clImage2DOut)"); + + // Enqueue a kernel run call. + size_t global_work_offset[] = {0, 0}; + size_t globalThreads[] = {imageWidth / 4, imageHeight}; + size_t localThreads[] = {blockSizeX, blockSizeY}; + + status = clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 2, NULL, + globalThreads, NULL, 0, NULL, 0); + CHECK_RESULT((status != CL_SUCCESS), + "CopyOpenCLImage() failed at clEnqueueNDRangeKernel"); + + status = clFinish(cmdQueues_[_deviceId]); + CHECK_RESULT((status != CL_SUCCESS), "CopyOpenCLImage() failed at clFinish"); +} + +void OCLImage2DFromBuffer::CompileKernel() { + cl_int status = 0; + + size_t kernelSize = sizeof(strKernel); + const char *strs = (const char *)&strKernel[0]; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strs, + &kernelSize, &status); + + status = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], NULL, + NULL, NULL); + if (status != CL_SUCCESS) { + if (status == CL_BUILD_PROGRAM_FAILURE) { + cl_int logStatus; + size_t buildLogSize = 0; + logStatus = clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, buildLogSize, + NULL, &buildLogSize); + std::string buildLog; + buildLog.resize(buildLogSize); + + logStatus = clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, buildLogSize, + &buildLog[0], NULL); + printf("%s", buildLog.c_str()); + } + return; + } + // get a kernel object handle for a kernel with the given name + kernel_ = _wrapper->clCreateKernel(program_, "image2imageCopy", &status); + + size_t kernel2DWorkGroupSize = 0; + status = clGetKernelWorkGroupInfo(kernel_, devices_[_deviceId], + CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), + &kernel2DWorkGroupSize, 0); + + if ((blockSizeX * blockSizeY) > kernel2DWorkGroupSize) { + if (blockSizeX > kernel2DWorkGroupSize) { + blockSizeX = kernel2DWorkGroupSize; + blockSizeY = 1; + } + } +} diff --git a/opencl/tests/ocltst/module/runtime/OCLImage2DFromBuffer.h b/opencl/tests/ocltst/module/runtime/OCLImage2DFromBuffer.h new file mode 100644 index 0000000000..8d105dda69 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLImage2DFromBuffer.h @@ -0,0 +1,56 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCLImage2DFromBuffer_H_ +#define _OCLImage2DFromBuffer_H_ + +#include "OCLTestImp.h" + +class OCLImage2DFromBuffer : public OCLTestImp { + public: + OCLImage2DFromBuffer(); + virtual ~OCLImage2DFromBuffer(); + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual void run(void); + virtual unsigned int close(void); + + protected: + static const unsigned int imageWidth; + static const unsigned int imageHeight; + + void testReadImage(cl_mem image); + void testKernel(); + void AllocateOpenCLImage(); + void CopyOpenCLImage(cl_mem clImageSrc); + void CompileKernel(); + + bool done_; + size_t blockSizeX; /**< Work-group size in x-direction */ + size_t blockSizeY; /**< Work-group size in y-direction */ + cl_mem buffer; + cl_mem clImage2DOriginal; + cl_mem clImage2D; + cl_mem clImage2DOut; + cl_uint pitchAlignment; +}; + +#endif // _OCLImage2DFromBuffer_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLImageCopyPartial.cpp b/opencl/tests/ocltst/module/runtime/OCLImageCopyPartial.cpp new file mode 100644 index 0000000000..92bb203d05 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLImageCopyPartial.cpp @@ -0,0 +1,347 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLImageCopyPartial.h" + +#include +#include +#include + +#include "CL/opencl.h" +#include "Timer.h" + +// Quiet pesky warnings +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +#define NUM_SIZES 2 +static const unsigned int Sizes0[NUM_SIZES] = {16384, 16384}; + +#define NUM_FORMATS 1 +static const cl_image_format formats[NUM_FORMATS] = {{CL_R, CL_UNSIGNED_INT16}}; +static const char *textFormats[NUM_FORMATS] = {"R8"}; +static const unsigned int formatSize[NUM_FORMATS] = {2 * sizeof(cl_uchar)}; + +static const unsigned int Iterations[2] = {1, OCLImageCopyPartial::NUM_ITER}; + +#define NUM_SUBTESTS 3 +OCLImageCopyPartial::OCLImageCopyPartial() { + _numSubTests = NUM_SIZES * NUM_SUBTESTS * NUM_FORMATS * 2; +} + +OCLImageCopyPartial::~OCLImageCopyPartial() {} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLImageCopyPartial::setData(void *ptr, unsigned int pitch, + unsigned int size, unsigned int value) { + unsigned int *ptr2 = (unsigned int *)ptr; + value = 0; + for (unsigned int i = 0; i < size >> 2; i++) { + ptr2[i] = value; + value++; + } +} + +void OCLImageCopyPartial::checkData(void *ptr, unsigned int pitch, + unsigned int size, unsigned int value) { + unsigned int *ptr2 = (unsigned int *)ptr; + value = 0; + for (unsigned int i = 0; i < size >> 2; i++) { + if (ptr2[i] != value) { + printf("Data validation failed at %d! Got 0x%08x 0x%08x 0x%08x 0x%08x\n", + i, ptr2[i], ptr2[i + 1], ptr2[i + 2], ptr2[i + 3]); + printf("Expected 0x%08x 0x%08x 0x%08x 0x%08x\n", value, value, value, + value); + CHECK_RESULT(true, "Data validation failed!"); + break; + } + value++; + } +} + +void OCLImageCopyPartial::open(unsigned int test, char *units, + double &conversion, unsigned int deviceId) { + cl_uint typeOfDevice = type_; + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + size_t queryOut = 0; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + srcBuffer_ = 0; + dstBuffer_ = 0; + srcImage_ = false; + dstImage_ = false; + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], typeOfDevice, + 0, NULL, &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + // if (num_devices > 0) + //{ + // platform = platforms[_platformIndex]; + // break; + //} +#if 0 + } +#endif + delete platforms; + } + + bufnum_ = (_openTest / (NUM_SIZES * NUM_SUBTESTS)) % NUM_FORMATS; + + if ((((_openTest / NUM_SIZES) % NUM_SUBTESTS) + 1) & 1) { + srcImage_ = true; + } + if ((((_openTest / NUM_SIZES) % NUM_SUBTESTS) + 1) & 2) { + dstImage_ = true; + } + + numIter = Iterations[_openTest / (NUM_SIZES * NUM_SUBTESTS * NUM_FORMATS)]; + + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, "Couldn't find AMD platform, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = _wrapper->clGetDeviceIDs(platform, typeOfDevice, num_devices, + devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_WIDTH, + sizeof(size_t), &queryOut, NULL); + bufSizeW_ = (cl_uint)queryOut; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, + sizeof(size_t), &queryOut, NULL); + bufSizeH_ = (cl_uint)queryOut; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + void *mem; + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSizeW_, bufSizeH_, 1}; + size_t image_row_pitch; + size_t image_slice_pitch; + unsigned int memSize; + + if (_openTest % NUM_SIZES) { + origin[0] = bufSizeW_ - 16; + region[0] = 16; + } else { + origin[1] = bufSizeH_ - 16; + region[1] = 16; + } + + if (dstImage_) { + dstBuffer_ = + _wrapper->clCreateImage2D(context_, flags, &formats[bufnum_], bufSizeW_, + bufSizeH_, 0, NULL, &error_); + CHECK_RESULT(dstBuffer_ == 0, "clCreateImage(dstBuffer) failed"); + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_WRITE, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + memSize = (unsigned int)image_row_pitch * (unsigned int)region[1]; + } else { + dstBuffer_ = _wrapper->clCreateBuffer( + context_, flags, region[0] * region[1] * formatSize[bufnum_], NULL, + &error_); + CHECK_RESULT(dstBuffer_ == 0, "clCreateBuffer(dstBuffer) failed"); + mem = _wrapper->clEnqueueMapBuffer( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_WRITE, 0, + region[0] * region[1] * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memSize = + (unsigned int)region[0] * (unsigned int)region[1] * formatSize[bufnum_]; + image_row_pitch = 0; + } + unsigned int *ptr2 = (unsigned int *)mem; + for (unsigned int i = 0; i < memSize >> 2; i++) { + ptr2[i] = 0xdeadbeef; + } + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, dstBuffer_, mem, 0, NULL, NULL); + + flags = CL_MEM_READ_ONLY; + if (srcImage_) { + srcBuffer_ = + _wrapper->clCreateImage2D(context_, flags, &formats[bufnum_], bufSizeW_, + bufSizeH_, 0, NULL, &error_); + CHECK_RESULT(srcBuffer_ == 0, "clCreateImage(srcBuffer) failed"); + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, srcBuffer_, CL_TRUE, CL_MAP_WRITE, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + memSize = (unsigned int)image_row_pitch * (unsigned int)region[1]; + } else { + srcBuffer_ = _wrapper->clCreateBuffer( + context_, flags, region[0] * region[1] * formatSize[bufnum_], NULL, + &error_); + CHECK_RESULT(srcBuffer_ == 0, "clCreateBuffer(srcBuffer) failed"); + mem = _wrapper->clEnqueueMapBuffer( + cmd_queue_, srcBuffer_, CL_TRUE, CL_MAP_WRITE, 0, + region[0] * region[1] * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memSize = + (unsigned int)region[0] * (unsigned int)region[1] * formatSize[bufnum_]; + image_row_pitch = 0; + } + setData(mem, (unsigned int)image_row_pitch, memSize, 0xdeadbeef); + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, srcBuffer_, mem, 0, NULL, NULL); +} + +void OCLImageCopyPartial::run(void) { + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSizeW_, bufSizeH_, 1}; + + if (_openTest % NUM_SIZES) { + origin[0] = bufSizeW_ - 16; + region[0] = 16; + } else { + origin[1] = bufSizeH_ - 16; + region[1] = 16; + } + + // Warm up + if (srcImage_ == false) { + error_ = _wrapper->clEnqueueCopyBufferToImage( + cmd_queue_, srcBuffer_, dstBuffer_, 0, origin, region, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyBufferToImage failed"); + } else if (dstImage_ == false) { + error_ = _wrapper->clEnqueueCopyImageToBuffer( + cmd_queue_, srcBuffer_, dstBuffer_, origin, region, 0, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyImageToBuffer failed"); + } else { + error_ = + _wrapper->clEnqueueCopyImage(cmd_queue_, srcBuffer_, dstBuffer_, origin, + origin, region, 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyImage failed"); + } + error_ = _wrapper->clFinish(cmd_queue_); + CHECK_RESULT(error_, "clFinish failed"); + + const char *strSrc = NULL; + const char *strDst = NULL; + if (srcImage_) + strSrc = "img"; + else + strSrc = "buf"; + if (dstImage_) + strDst = "img"; + else + strDst = "buf"; + void *mem; + size_t image_row_pitch; + size_t image_slice_pitch; + unsigned int memSize; + if (dstImage_) { + mem = _wrapper->clEnqueueMapImage( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_READ, origin, region, + &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapImage failed"); + memSize = (unsigned int)image_row_pitch * (unsigned int)region[1]; + } else { + mem = _wrapper->clEnqueueMapBuffer( + cmd_queue_, dstBuffer_, CL_TRUE, CL_MAP_READ, 0, + region[0] * region[1] * formatSize[bufnum_], 0, NULL, NULL, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + memSize = + (unsigned int)region[0] * (unsigned int)region[1] * formatSize[bufnum_]; + image_row_pitch = 0; + } + checkData(mem, (unsigned int)image_row_pitch, memSize, 0x600df00d); + _wrapper->clEnqueueUnmapMemObject(cmd_queue_, dstBuffer_, mem, 0, NULL, NULL); + char buf[256]; + SNPRINTF(buf, sizeof(buf), " (%4dx%4d) fmt:%s src:%s dst:%s i: %4d (GB/s) ", + bufSizeW_, bufSizeH_, textFormats[bufnum_], strSrc, strDst, numIter); + testDescString = buf; +} + +unsigned int OCLImageCopyPartial::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (srcBuffer_) { + error_ = _wrapper->clReleaseMemObject(srcBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(srcBuffer_) failed"); + } + if (dstBuffer_) { + error_ = _wrapper->clReleaseMemObject(dstBuffer_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(dstBuffer_) failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/runtime/OCLImageCopyPartial.h b/opencl/tests/ocltst/module/runtime/OCLImageCopyPartial.h new file mode 100644 index 0000000000..5cc2188bec --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLImageCopyPartial.h @@ -0,0 +1,57 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ImageCopyCorners_H_ +#define _OCL_ImageCopyCorners_H_ + +#include "OCLTestImp.h" + +class OCLImageCopyPartial : public OCLTestImp { + public: + OCLImageCopyPartial(); + virtual ~OCLImageCopyPartial(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + static const unsigned int NUM_ITER = 1; + + cl_context context_; + cl_command_queue cmd_queue_; + cl_mem srcBuffer_; + cl_mem dstBuffer_; + cl_int error_; + + unsigned int bufSizeW_; + unsigned int bufSizeH_; + unsigned int bufnum_; + bool srcImage_; + bool dstImage_; + unsigned int numIter; + void setData(void* ptr, unsigned int pitch, unsigned int size, + unsigned int value); + void checkData(void* ptr, unsigned int pitch, unsigned int size, + unsigned int value); +}; + +#endif // _OCL_ImageCopyPartial_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLKernelBinary.cpp b/opencl/tests/ocltst/module/runtime/OCLKernelBinary.cpp new file mode 100644 index 0000000000..55be1a684b --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLKernelBinary.cpp @@ -0,0 +1,252 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLKernelBinary.h" + +#include +#include +#include + +#include "CL/cl.h" + +const static char* strKernel12 = + "typedef struct ST { \n" + " int i0; \n" + " int i1; \n" + "} ST_t; \n" + " \n" + "__constant ST_t STCArray[2] = { \n" + " { 1, 0 }, \n" + " { 2, 1 } \n" + "}; \n" + " \n" + "__kernel void foo (__global int *p, int n) \n" + "{ \n" + " int s = 0; \n" + " int i; \n" + " for (i=0; i < n; ++i) { \n" + " s += STCArray[i].i0 + STCArray[i].i1; \n" + " } \n" + " *p = s; \n" + "} \n"; + +const static char* strKernel20 = + "typedef struct ST { \n" + " int i0; \n" + " int i1; \n" + "} ST_t; \n" + " \n" + "__constant ST_t STCArray[2] = { \n" + " { -1, 0 }, \n" + " { 3, -1 } \n" + "}; \n" + " \n" + "__global int var = 1; \n" + " \n" + "__kernel void foo (__global int *p, int n) \n" + "{ \n" + " int s = 0; \n" + " int i; \n" + " for (i=0; i < n; ++i) { \n" + " s += STCArray[i].i0 + STCArray[i].i1 + var++; \n" + " } \n" + " p[get_global_id(0)] = s; \n" + "} \n"; + +OCLKernelBinary::OCLKernelBinary() { _numSubTests = 2; } + +OCLKernelBinary::~OCLKernelBinary() {} + +void OCLKernelBinary::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + + char strVersion[128]; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_VERSION, + sizeof(strVersion), strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + if (test == 1 && strVersion[7] < '2') { + program_ = NULL; + return; + } + + const char *options, *options0; + const char* strKernel; + switch (test) { + case 0: + options = ""; + options0 = "-O0"; + strKernel = strKernel12; + break; + case 1: + options = "-cl-std=CL2.0"; + options0 = "-cl-std=CL2.0 -O0"; + strKernel = strKernel20; + break; + default: + assert(false); + return; + } + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], options, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + size_t* sizes = new size_t[deviceCount_]; + CHECK_RESULT(((sizes != NULL) ? false : true), "malloc()"); + size_t* sizes1 = new size_t[deviceCount_]; + CHECK_RESULT(((sizes1 != NULL) ? false : true), "malloc()"); + size_t* sizes2 = new size_t[deviceCount_]; + CHECK_RESULT(((sizes2 != NULL) ? false : true), "malloc()"); + + unsigned int programInfoDeviceIdIndex = 0; + cl_device_id* programInfoDevices = new cl_device_id[deviceCount_]; + CHECK_RESULT(((programInfoDevices != NULL) ? false : true), "malloc()"); + // get an array of device Id's that relate to values order returned by + // 'clGetProgramInfo' + error_ = _wrapper->clGetProgramInfo(program_, CL_PROGRAM_DEVICES, + sizeof(cl_device_id) * deviceCount_, + programInfoDevices, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetProgramInfo()"); + // map between the class devices_ array and the programInfoDeviceId array + for (unsigned int i = 0; i < deviceCount_; i++) { + if (devices_[deviceId] == programInfoDevices[i]) { + programInfoDeviceIdIndex = i; + } + } + delete[] programInfoDevices; + + error_ = + _wrapper->clGetProgramInfo(program_, CL_PROGRAM_BINARY_SIZES, + sizeof(size_t) * deviceCount_, sizes, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetProgramInfo()"); + + unsigned char** binaries = new unsigned char*[deviceCount_]; + CHECK_RESULT(((binaries != NULL) ? false : true), "malloc()"); + + for (unsigned int i = 0; i < deviceCount_; i++) { + if (sizes[i] > 0) { + binaries[i] = new unsigned char[sizes[i]]; + CHECK_RESULT(((binaries[i] != NULL) ? false : true), "malloc()"); + } else { + binaries[i] = NULL; + } + } + + error_ = _wrapper->clGetProgramInfo(program_, CL_PROGRAM_BINARIES, + sizeof(unsigned char*) * deviceCount_, + binaries, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetProgramInfo()"); + + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT((error_ != CL_SUCCESS), "clReleaseProgram()"); + + const unsigned char* cBinary = binaries[programInfoDeviceIdIndex]; + cl_int status; + program_ = _wrapper->clCreateProgramWithBinary( + context_, 1, &devices_[deviceId], &(sizes[programInfoDeviceIdIndex]), + &cBinary, &status, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithBinary()"); + + for (unsigned int i = 0; i < deviceCount_; i++) { + if (binaries[i] != NULL) delete[] binaries[i]; + } + delete[] binaries; + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], options0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetProgramInfo()"); + + error_ = + _wrapper->clGetProgramInfo(program_, CL_PROGRAM_BINARY_SIZES, + sizeof(size_t) * deviceCount_, sizes1, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "1st clGetProgramInfo()"); + + kernel_ = _wrapper->clCreateKernel(program_, "foo", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "1st clCreateKernel() failed"); + + _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT((error_ != CL_SUCCESS), "1st clReleaseKernel() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], options0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetProgramInfo()"); + + error_ = + _wrapper->clGetProgramInfo(program_, CL_PROGRAM_BINARY_SIZES, + sizeof(size_t) * deviceCount_, sizes2, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "2nd clGetProgramInfo()"); + + kernel_ = _wrapper->clCreateKernel(program_, "foo", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "2nd clCreateKernel() failed"); + + cl_mem buffer; + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + 2 * sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + + delete[] sizes; + delete[] sizes1; + delete[] sizes2; +} + +void OCLKernelBinary::run(void) { + if (program_ == NULL) { + return; + } + + cl_mem buffer = buffers()[0]; + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + cl_int num = 2; + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_int), &num); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t gws[1] = {2}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + cl_uint outputV[2] = {0}; + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffer, true, 0, + 2 * sizeof(cl_uint), outputV, 0, NULL, + NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + if (outputV[0] != 4) { + CHECK_RESULT(true, "Incorrect result of kernel execution!"); + } +} + +unsigned int OCLKernelBinary::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLKernelBinary.h b/opencl/tests/ocltst/module/runtime/OCLKernelBinary.h new file mode 100644 index 0000000000..f34110b12a --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLKernelBinary.h @@ -0,0 +1,38 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_KERNEL_BINARY_H_ +#define _OCL_KERNEL_BINARY_H_ + +#include "OCLTestImp.h" + +class OCLKernelBinary : public OCLTestImp { + public: + OCLKernelBinary(); + virtual ~OCLKernelBinary(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); +}; + +#endif // _OCL_KERNEL_BINARY_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLLDS32K.cpp b/opencl/tests/ocltst/module/runtime/OCLLDS32K.cpp new file mode 100644 index 0000000000..ecc0f47f12 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLLDS32K.cpp @@ -0,0 +1,407 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLLDS32K.h" + +#include +#include +#include +#include + +#include "CL/cl.h" +// #include +#include + +typedef unsigned int uint32_t; +#if EMU_ENV +#define LDS_SIZE 1024 +#define A_SIZE 1024 +#else +#define LDS_SIZE 32768 +#define A_SIZE (8 * 1024 * 1024) +#endif // EMU_ENV + +#define LOCAL_WORK_SIZE 64 + +// We'll do a 64MB transaction +#define B_SIZE A_SIZE +#define C_SIZE A_SIZE +#define D_SIZE A_SIZE + +#define GLOBAL_WORK_SIZE (A_SIZE / LDS_SIZE * LOCAL_WORK_SIZE) + +#define TEST_NAME "lds 32K" + +// 32K has 8192 elements +// 64 threads each handle 8192/64=128 values +#if EMU_ENV +static const char program_source[] = KERNEL( + __kernel void the_kernel(__global const uint *a, __global const uint *b, + __global const uint *c, __global uint *d, + __global uint *e) { + // Reduce size for the emulator + __local uint lds[256]; + uint gid = get_global_id(0); + __global const uint* ta = a + 4 * gid; + __global const uint* tb = b + 4 * gid; + __global const uint* tc = c + 4 * gid; + __global uint* td = d + 4 * gid; + uint i; + + for (i = 0; i < 4; ++i) lds[ta[i]] = tc[i]; + + barrier(CLK_LOCAL_MEM_FENCE); + + for (i = 0; i < 4; ++i) td[i] = lds[tb[i]]; +} __kernel void the_kernel2(__global uint* d) { + __local uint lds[8192]; + uint i; + uint gid = get_global_id(0); + + for (i = 0; i < 128; ++i) lds[i] = d[gid]; + barrier(CLK_LOCAL_MEM_FENCE); + + for (i = 0; i < 128; ++i) d[gid] = lds[i]; + }); +#else +static const char program_source[] = KERNEL( + __kernel void the_kernel(__global const uint *a, __global const uint *b, + __global const uint *c, __global uint *d, + __global uint *e) { + __local uint lds[8192]; + uint gid = get_global_id(0); + __global const uint *ta = a + 128 * gid; + __global const uint *tb = b + 128 * gid; + __global const uint *tc = c + 128 * gid; + __global uint *td = d + 128 * gid; + uint i; + + for (i = 0; i < 128; ++i) lds[ta[i]] = tc[i]; + + barrier(CLK_LOCAL_MEM_FENCE); + + for (i = 0; i < 128; ++i) td[i] = lds[tb[i]]; + } __kernel void the_kernel2(__global uint *d) { + __local uint lds[8192]; + uint i; + uint gid = get_global_id(0); + + for (i = 0; i < 128; ++i) lds[i] = d[gid]; + barrier(CLK_LOCAL_MEM_FENCE); + + for (i = 0; i < 128; ++i) d[gid] = lds[i]; + }); +#endif // EMU_ENV + +static void fill(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, + uint32_t *e) { + uint32_t i, j, k, t; + static uint32_t p[LDS_SIZE / 4]; + static int is_set = 0; + + if (!is_set) { + for (i = 0; i < LDS_SIZE / 4; ++i) p[i] = i; + is_set = 1; + } + + for (j = 0; j < A_SIZE / LDS_SIZE; ++j) { + for (i = 0; i < LDS_SIZE / 4; ++i) { + k = rand() % (LDS_SIZE / 4); + t = p[i]; + p[i] = p[k]; + p[k] = t; + + c[i] = rand(); + } + memcpy(a, p, LDS_SIZE); + + for (i = 0; i < LDS_SIZE / 4; ++i) { + k = rand() % (LDS_SIZE / 4); + t = p[i]; + p[i] = p[k]; + p[k] = t; + + d[i] = 0xfeedbeefU; + } + memcpy(b, p, LDS_SIZE); + + a += LDS_SIZE / 4; + b += LDS_SIZE / 4; + c += LDS_SIZE / 4; + d += LDS_SIZE / 4; + } +} + +static int check(const uint32_t *a, const uint32_t *b, const uint32_t *c, + const uint32_t *d, const uint32_t *e) { + uint32_t i, j, t; + uint32_t lds[LDS_SIZE / 4]; + + for (j = 0; j < A_SIZE / LDS_SIZE; ++j) { + for (i = 0; i < LDS_SIZE / 4; ++i) lds[i] = 0xdeadbeef; + + for (i = 0; i < LDS_SIZE / 4; ++i) lds[a[i]] = c[i]; + + for (i = 0; i < LDS_SIZE / 4; ++i) { + t = lds[b[i]]; + if (d[i] != t) { + printf("mismatch group %u thread %u element %u: %u instead of %u\n", j, + i / 128, i % 128, d[i], t); + return EXIT_FAILURE; + } + } + + a += LDS_SIZE / 4; + b += LDS_SIZE / 4; + c += LDS_SIZE / 4; + d += LDS_SIZE / 4; + } + return EXIT_SUCCESS; +} + +#ifndef E_SIZE +#define E_SIZE 32 +#endif + +void OCLLDS32K::setup_run(const char *cmplr_opt) { + cl_ulong lsize; + const char *ps[2]; + error_ = + _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_LOCAL_MEM_SIZE, + sizeof(lsize), &lsize, NULL); + if (lsize < LDS_SIZE) { + fprintf(stderr, "Passed! Test does not support 32kb of lds space!"); + return; + } + + // create the program + ps[0] = program_source; + program_ = + _wrapper->clCreateProgramWithSource(context_, 1, ps, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource failed"); + + // build the program + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], + cmplr_opt, NULL, NULL); + if (error_ != CL_SUCCESS) { + char build_log[16384]; + size_t log_sz; + fprintf(stderr, "build program failed, err=%d\n", error_); + error_ = _wrapper->clGetProgramBuildInfo( + program_, devices_[_deviceId], CL_PROGRAM_BUILD_LOG, sizeof(build_log), + build_log, &log_sz); + if (error_ != CL_SUCCESS) + fprintf(stderr, "failed to get build log, err=%d\n", error_); + else + fprintf(stderr, "----- Build Log -----\n%s\n----- ----- --- -----\n", + build_log); + return; + } + + // create the kernel + kernel_ = _wrapper->clCreateKernel(program_, "the_kernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "create a kernel failed"); + + // create the kernel + kernel2_ = _wrapper->clCreateKernel(program_, "the_kernel2", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "create a kernel failed"); + + // allocate the buffer memory objects + a_buf_ = _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY, A_SIZE, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "create a buffer a failed"); + buffers_.push_back(a_buf_); + + b_buf_ = _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY, B_SIZE, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "create a buffer b failed"); + buffers_.push_back(b_buf_); + + c_buf_ = _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY, C_SIZE, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "create a buffer c failed"); + buffers_.push_back(c_buf_); + + d_buf_ = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, D_SIZE, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "create a buffer d failed"); + buffers_.push_back(d_buf_); + + e_buf_ = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, E_SIZE, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "create a buffer e failed"); + buffers_.push_back(e_buf_); + + // set the args values + error_ = + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&a_buf_); + error_ |= + _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), (void *)&b_buf_); + error_ |= + _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_mem), (void *)&c_buf_); + error_ |= + _wrapper->clSetKernelArg(kernel_, 3, sizeof(cl_mem), (void *)&d_buf_); + error_ |= + _wrapper->clSetKernelArg(kernel_, 4, sizeof(cl_mem), (void *)&e_buf_); + CHECK_RESULT((error_ != CL_SUCCESS), "setkernelArg failed!"); + + error_ = + _wrapper->clSetKernelArg(kernel2_, 0, sizeof(cl_mem), (void *)&d_buf_); + CHECK_RESULT((error_ != CL_SUCCESS), "setkernelArg failed!"); +} + +void OCLLDS32K::cleanup_run() { + if (kernel2_) { + _wrapper->clReleaseKernel(kernel2_); + } +} + +void OCLLDS32K::exec_kernel(void *a_mem, void *b_mem, void *c_mem, void *d_mem, + void *e_mem) { + size_t global_work_size[1]; + size_t local_work_size[1]; + + // Send data to device + error_ = _wrapper->clEnqueueWriteBuffer( + cmdQueues_[_deviceId], a_buf_, CL_TRUE, 0, A_SIZE, a_mem, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueWritebuffer failed"); + + error_ = _wrapper->clEnqueueWriteBuffer( + cmdQueues_[_deviceId], b_buf_, CL_TRUE, 0, B_SIZE, b_mem, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueWritebuffer failed"); + + error_ = _wrapper->clEnqueueWriteBuffer( + cmdQueues_[_deviceId], c_buf_, CL_TRUE, 0, C_SIZE, c_mem, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueWritebuffer failed"); + + // set work-item dimensions + global_work_size[0] = GLOBAL_WORK_SIZE; + local_work_size[0] = LOCAL_WORK_SIZE; + + // execute kernel + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, global_work_size, + local_work_size, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel failed"); + + // execute kernel + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, global_work_size, + local_work_size, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel failed"); + + // execute kernel + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, global_work_size, + local_work_size, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel failed"); + + // read results + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], d_buf_, CL_TRUE, + 0, D_SIZE, d_mem, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed"); + + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], e_buf_, CL_TRUE, + 0, E_SIZE, e_mem, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed"); + + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + CHECK_RESULT((error_ != CL_SUCCESS), "clFinish failed"); +} + +const char *OCLLDS32K::kernel_src = ""; + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +OCLLDS32K::OCLLDS32K() { _numSubTests = 1; } + +OCLLDS32K::~OCLLDS32K() {} + +void OCLLDS32K::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + _deviceId = deviceId; + testID_ = test; + OCLTestImp::open(test, units, conversion, _deviceId); +} + +void OCLLDS32K::run(void) { + void *a; + void *b; + void *c; + void *d; + void *e; + const char *cmplr_opt = NULL; + int j, nj; + double f, dj, p; + + nj = 5; + + setup_run(cmplr_opt); + CHECK_RESULT((error_ != CL_SUCCESS), "setup_run failed!"); + + p = 10.0; + dj = 100.0 / (double)nj; + + a = malloc(A_SIZE); + CHECK_RESULT((a == NULL), "malloc failed"); + memset(a, 0, A_SIZE); + + b = malloc(B_SIZE); + CHECK_RESULT((b == NULL), "malloc failed"); + memset(b, 0, B_SIZE); + + c = malloc(C_SIZE); + CHECK_RESULT((c == NULL), "malloc failed"); + memset(c, 0, C_SIZE); + + d = malloc(D_SIZE); + CHECK_RESULT((d == NULL), "malloc failed"); + memset(d, 0, D_SIZE); + + e = malloc(E_SIZE); + CHECK_RESULT((e == NULL), "malloc failed"); + memset(e, 0, E_SIZE); + + // printf("Testing " TEST_NAME " on %s\n", argv[1]); + for (j = 0; j < nj; ++j) { + fill((uint32_t *)a, (uint32_t *)b, (uint32_t *)c, (uint32_t *)d, + (uint32_t *)e); + // printf("%s Test %d: ", sDevice, j); + exec_kernel(a, b, c, d, e); + CHECK_RESULT((error_ != CL_SUCCESS), "exec_kernel failed!"); + + CHECK_RESULT((check((uint32_t *)a, (uint32_t *)b, (uint32_t *)c, + (uint32_t *)d, (uint32_t *)e) < 0), + " Failed!\n"); + f = (j + 1) * dj; + if (nj > 1 && f >= p) { + // printf("%.1lf%%...\n", f); + // fflush(stdout); + p += 10.0; + } + } +} + +unsigned int OCLLDS32K::close(void) { + cleanup_run(); + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/runtime/OCLLDS32K.h b/opencl/tests/ocltst/module/runtime/OCLLDS32K.h new file mode 100644 index 0000000000..9dedf7ee32 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLLDS32K.h @@ -0,0 +1,51 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_LDS32K_H_ +#define _OCL_LDS32K_H_ +#include "OCLTestImp.h" + +class OCLLDS32K : public OCLTestImp { + public: + OCLLDS32K(); + virtual ~OCLLDS32K(); + + public: + virtual void open(unsigned int test, char *units, double &conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + void setup_run(const char *cmplr_opt); + void cleanup_run(); + void exec_kernel(void *a_mem, void *b_mem, void *c_mem, void *d_mem, + void *e_mem); + static const char *kernel_src; + cl_kernel kernel2_; + + private: + unsigned int testID_; + cl_mem a_buf_; + cl_mem b_buf_; + cl_mem c_buf_; + cl_mem d_buf_; + cl_mem e_buf_; +}; + +#endif // _OCL_LDS32K_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLLinearFilter.cpp b/opencl/tests/ocltst/module/runtime/OCLLinearFilter.cpp new file mode 100644 index 0000000000..e6a040ebbc --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLLinearFilter.cpp @@ -0,0 +1,187 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLLinearFilter.h" + +#include +#include +#include + +#include "CL/cl.h" + +const static size_t ImageSize = 4; + +const static char* strKernel = + "const sampler_t g_Sampler = CLK_FILTER_LINEAR | \n" + " CLK_ADDRESS_CLAMP_TO_EDGE | \n" + " CLK_NORMALIZED_COORDS_FALSE; \n" + " \n" + "__kernel void linear3D(__read_only image3d_t img3D, __global float4* " + "f4Tata) \n" + "{ \n" + " float4 f4Index = { 2.25f, 1.75f, 0.5f, 0.0f }; \n" + " // copy interpolated data in result buffer \n" + " f4Tata[0] = read_imagef(img3D, g_Sampler, f4Index); \n" + "} \n" + " \n" + "__kernel void linear2D(__read_only image2d_t img2D, __global float4* " + "f4Tata) \n" + "{ \n" + " float2 f2Index = { 2.25f, 1.75f }; \n" + " // copy interpolated data in result buffer \n" + " f4Tata[0] = read_imagef(img2D, g_Sampler, f2Index); \n" + "} \n" + " \n"; + +OCLLinearFilter::OCLLinearFilter() { + done_ = false; + _numSubTests = 2; +} + +OCLLinearFilter::~OCLLinearFilter() {} + +void OCLLinearFilter::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + cl_bool imageSupport; + size_t size; + for (size_t i = 0; i < deviceCount_; ++i) { + _wrapper->clGetDeviceInfo(devices_[i], CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport), &imageSupport, &size); + if (!imageSupport) { + testDescString = "Image not supported, skipping this test! "; + done_ = true; + return; + } + } + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + const char* kernels[2] = {"linear3D", "linear2D"}; + kernel_ = _wrapper->clCreateKernel(program_, kernels[test], &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem memory; + size_t offset[3] = {0, 0, 0}; + cl_image_format imageFormat = {CL_RGBA, CL_FLOAT}; + + if (test == 0) { + float data[ImageSize][ImageSize][ImageSize][4]; + float index = 0.f; + size_t region[3] = {ImageSize, ImageSize, ImageSize}; + for (size_t z = 0; z < ImageSize; ++z) { + for (size_t y = 0; y < ImageSize; ++y) { + for (size_t x = 0; x < ImageSize; ++x) { + data[z][y][x][0] = (float)x; + data[z][y][x][1] = (float)y; + data[z][y][x][2] = (float)z; + data[z][y][x][3] = 1.0f; + } + } + } + memory = _wrapper->clCreateImage3D(context_, CL_MEM_READ_ONLY, &imageFormat, + ImageSize, ImageSize, ImageSize, 0, 0, + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateImage() failed"); + + error_ = _wrapper->clEnqueueWriteImage(cmdQueues_[_deviceId], memory, true, + offset, region, 0, 0, data, 0, NULL, + NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteImage() failed"); + } else { + float data[4][ImageSize][ImageSize]; + size_t region[3] = {ImageSize, ImageSize, 1}; + for (size_t y = 0; y < ImageSize; ++y) { + for (size_t x = 0; x < ImageSize; ++x) { + data[y][x][0] = (float)x; + data[y][x][1] = (float)y; + data[y][x][2] = data[y][x][3] = 1.0f; + } + } + + memory = _wrapper->clCreateImage2D(context_, CL_MEM_READ_ONLY, &imageFormat, + ImageSize, ImageSize, 0, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateImage() failed"); + error_ = _wrapper->clEnqueueWriteImage(cmdQueues_[_deviceId], memory, true, + offset, region, 0, 0, data, 0, NULL, + NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteImage() failed"); + } + buffers_.push_back(memory); + + memory = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + 4 * sizeof(cl_float), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(memory); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLLinearFilter::run(void) { + if (done_) { + return; + } + + cl_float values[4] = {0.f, 0.f, 0.f, 0.f}; + cl_float ref[2] = {1.75f, 1.25f}; + cl_mem image = buffers()[0]; + cl_mem buffer = buffers()[1]; + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &image); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t gws[1] = {0x1}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffer, true, 0, + 4 * sizeof(cl_float), values, 0, NULL, + NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + for (cl_uint i = 0; i < 2; ++i) { + if (values[i] != ref[i]) { + printf("%.2f != %.2f [ref]", values[i], ref[i]); + CHECK_RESULT(true, " - Incorrect result for linear filtering!\n"); + } + } +} + +unsigned int OCLLinearFilter::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLLinearFilter.h b/opencl/tests/ocltst/module/runtime/OCLLinearFilter.h new file mode 100644 index 0000000000..a896ba0f60 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLLinearFilter.h @@ -0,0 +1,41 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_LINEAR_FILTER_H_ +#define _OCL_LINEAR_FILTER_H_ + +#include "OCLTestImp.h" + +class OCLLinearFilter : public OCLTestImp { + public: + OCLLinearFilter(); + virtual ~OCLLinearFilter(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool done_; +}; + +#endif // _OCL_LINEAR_FILTER_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLMapCount.cpp b/opencl/tests/ocltst/module/runtime/OCLMapCount.cpp new file mode 100644 index 0000000000..b229f30d28 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLMapCount.cpp @@ -0,0 +1,98 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLMapCount.h" + +#include +#include +#include + +#include "CL/cl.h" + +OCLMapCount::OCLMapCount() { _numSubTests = 1; } + +OCLMapCount::~OCLMapCount() {} + +void OCLMapCount::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + size_t size; + clMemWrapper memObject; + + // Get the address alignment, so we can make sure the sub buffer test later + // works properly + cl_uint addressAlign; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], + CL_DEVICE_MEM_BASE_ADDR_ALIGN, + sizeof(addressAlign), &addressAlign, NULL); + if (addressAlign < 128) addressAlign = 128; + + void* void_buffer = malloc(addressAlign * 4); + + // Create a buffer to test against + memObject = _wrapper->clCreateBuffer(context_, + CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, + addressAlign * 4, void_buffer, &error_); + if (error_) { + free(void_buffer); + printf("Unable to create buffer to test"); + } + + // Map buffer + void* mapped = _wrapper->clEnqueueMapBuffer( + cmdQueues_[deviceId], memObject, true, CL_MAP_READ, 0, addressAlign * 4, + 0, NULL, NULL, &error_); + + cl_uint mapCount; + + // Find the number of mappings on buffer after map + error_ = _wrapper->clGetMemObjectInfo(memObject, CL_MEM_MAP_COUNT, + sizeof(mapCount), &mapCount, &size); + CHECK_RESULT((error_ != CL_SUCCESS), "Unable to get mem object map count"); + if (mapCount != 1) { + printf( + "ERROR: Returned mem object map count does not validate! (expected %d, " + "got %d)\n", + 1, mapCount); + return; + } + + // Unmap buffer + error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues_[deviceId], memObject, + mapped, 0, NULL, NULL); + + // Find the number of mappings on buffer after unmap + error_ = _wrapper->clGetMemObjectInfo(memObject, CL_MEM_MAP_COUNT, + sizeof(mapCount), &mapCount, &size); + CHECK_RESULT((error_ != CL_SUCCESS), "Unable to get mem object map count"); + if (mapCount != 0) { + printf( + "ERROR: Returned mem object map count does not validate! (expected %d, " + "got %d)\n", + 0, mapCount); + return; + } +} + +void OCLMapCount::run(void) {} + +unsigned int OCLMapCount::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLMapCount.h b/opencl/tests/ocltst/module/runtime/OCLMapCount.h new file mode 100644 index 0000000000..92c7399a51 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLMapCount.h @@ -0,0 +1,60 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_MAP_COUNT_H_ +#define _OCL_MAP_COUNT_H_ + +#include "OCLTestImp.h" + +class OCLMapCount : public OCLTestImp { + public: + OCLMapCount(); + virtual ~OCLMapCount(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); +}; + +#endif // _OCL_MAP_COUNT_H_ + +class clMemWrapper { + public: + clMemWrapper() { mMem = NULL; } + clMemWrapper(cl_mem mem) { mMem = mem; } + ~clMemWrapper() { + if (mMem != NULL) clReleaseMemObject(mMem); + } + + clMemWrapper& operator=(const cl_mem& rhs) { + mMem = rhs; + return *this; + } + operator cl_mem() { return mMem; } + + cl_mem* operator&() { return &mMem; } + + bool operator==(const cl_mem& rhs) { return mMem == rhs; } + + protected: + cl_mem mMem; +}; diff --git a/opencl/tests/ocltst/module/runtime/OCLMemDependency.cpp b/opencl/tests/ocltst/module/runtime/OCLMemDependency.cpp new file mode 100644 index 0000000000..d3ddbd4192 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLMemDependency.cpp @@ -0,0 +1,153 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLMemDependency.h" + +#include +#include +#include + +#include "CL/cl.h" + +const static cl_uint Stages = 4; +const static cl_uint ThreadsForCheck = 1 << Stages; + +#define KERNEL_CODE(...) #__VA_ARGS__ + +const static char* strKernel = KERNEL_CODE( +\n __kernel void bitonicSort(__global uint2* keys, uint stage, uint pass) { + const uint thread = get_global_id(0); + + const uint pairDistance = 1 << (stage - pass); + + /* The purpose of this is to introduce an additional zero at stage - pass + * bit*/ + const uint leftID = + (thread & (pairDistance - 1)) | + ((thread & ~(pairDistance - 1)) << 1); /* Is the same as below */ + + const uint direction = ((thread >> stage) & 1) == 1 ? 0 : 1; + + const uint rightID = leftID + pairDistance; + const uint2 left = keys[leftID]; + const uint2 right = keys[rightID]; + + const uint2 larger = left.x > right.x ? left : right; + const uint2 smaller = left.x > right.x ? right : left; + + keys[leftID] = direction ? smaller : larger; + keys[rightID] = direction ? larger : smaller; +} +\n); + +OCLMemDependency::OCLMemDependency() { _numSubTests = 1; } + +OCLMemDependency::~OCLMemDependency() {} + +void OCLMemDependency::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + char dbuffer[1024] = {0}; + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "bitonicSort", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + ThreadsForCheck * sizeof(cl_uint2), NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + cl_buffer_region reg = {0, ThreadsForCheck * sizeof(cl_uint2)}; + buffer = + _wrapper->clCreateSubBuffer(buffers()[0], CL_MEM_READ_WRITE, + CL_BUFFER_CREATE_TYPE_REGION, ®, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLMemDependency::run(void) { + cl_uint2 values[ThreadsForCheck] = { + {{3, 0}}, {{1, 5}}, {{4, 6}}, {{2, 4}}, {{0, 3}}, {{5, 10}}, + {{15, 7}}, {{13, 8}}, {{10, 2}}, {{9, 1}}, {{7, 11}}, {{11, 9}}, + {{14, 12}}, {{12, 14}}, {{6, 13}}, {{8, 15}}}; + cl_uint2 reference[ThreadsForCheck] = { + {{0, 3}}, {{1, 5}}, {{3, 0}}, {{2, 4}}, {{4, 6}}, {{5, 10}}, + {{6, 13}}, {{8, 15}}, {{7, 11}}, {{9, 1}}, {{10, 2}}, {{11, 9}}, + {{14, 12}}, {{12, 14}}, {{15, 7}}, {{13, 8}}}; + cl_uint2 results[ThreadsForCheck]; + + cl_mem buffer = buffers()[0]; + error_ = + _wrapper->clEnqueueWriteBuffer(cmdQueues_[_deviceId], buffer, true, 0, + sizeof(values), values, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + + size_t gws[1] = {ThreadsForCheck}; + + for (unsigned int i = 0; i < Stages; ++i) { + buffer = buffers()[i % 2]; + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + for (unsigned int j = 0; j < i; ++j) { + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(unsigned int), &i); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(unsigned int), &j); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel( + cmdQueues_[_deviceId], kernel_, 1, NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + } + + buffer = buffers()[0]; + error_ = + _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffer, true, 0, + sizeof(results), results, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + for (unsigned int i = 0; i < ThreadsForCheck; ++i) { + if ((results[i].s[0] != reference[i].s[0]) || + (results[i].s[1] != reference[i].s[1])) { + CHECK_RESULT(true, "Incorrect result for dependency!\n"); + } + } +} + +unsigned int OCLMemDependency::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLMemDependency.h b/opencl/tests/ocltst/module/runtime/OCLMemDependency.h new file mode 100644 index 0000000000..1a8cf64610 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLMemDependency.h @@ -0,0 +1,38 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_MEM_DEPENDENCY_H_ +#define _OCL_MEM_DEPENDENCY_H_ + +#include "OCLTestImp.h" + +class OCLMemDependency : public OCLTestImp { + public: + OCLMemDependency(); + virtual ~OCLMemDependency(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); +}; + +#endif // _OCL_MEM_DEPENDENCY_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLMemObjs.cpp b/opencl/tests/ocltst/module/runtime/OCLMemObjs.cpp new file mode 100644 index 0000000000..76c3b3fd04 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLMemObjs.cpp @@ -0,0 +1,139 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLMemObjs.h" + +#include +#include +#include + +#include +#include +#include +#include + +const char* OCLMemObjs::kernel_src = ""; + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +OCLMemObjs::OCLMemObjs() { _numSubTests = 1; } + +OCLMemObjs::~OCLMemObjs() {} + +void OCLMemObjs::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; +} + +int OCLMemObjs::test(void) { + cl_int err; + + std::vector platforms; + cl::Platform::get(&platforms); + if (platforms.empty()) { + std::cerr << "Platform::get() failed \n"; + return EXIT_FAILURE; + } + cl_context_properties properties[] = { + CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0}; + cl::Context context(CL_DEVICE_TYPE_ALL, properties, NULL, NULL, &err); + if (err != CL_SUCCESS) { + std::cerr << "Context::Context() failed (" << err << ")\n"; + return EXIT_FAILURE; + } + + std::vector devices = context.getInfo(); + if (err != CL_SUCCESS) { + std::cerr << "Context::getInfo() failed (" << err << ")\n"; + return EXIT_FAILURE; + } + if (devices.size() == 0) { + std::cerr << "No device available\n"; + return EXIT_FAILURE; + } + + const char source[] = "__kernel void test_memobjs(__global int* ptr) {}"; + cl::Program::Sources sources(1, std::make_pair(source, 0)); + + cl::Program program(context, sources, &err); + if (err != CL_SUCCESS) { + std::cerr << "Program::Program() failed (" << err << ")\n"; + return EXIT_FAILURE; + } + err = program.build(devices); + if (err != CL_SUCCESS) { + std::cerr << "Program::build() failed (" << err << ")\n"; + return EXIT_FAILURE; + } + + cl::Kernel kernel(program, "test_memobjs", &err); + if (err != CL_SUCCESS) { + std::cerr << "Kernel::Kernel() failed (" << err << ")\n"; + return EXIT_FAILURE; + } + if (err != CL_SUCCESS) { + std::cerr << "Kernel::setArg() failed (" << err << ")\n"; + return EXIT_FAILURE; + } + + cl::CommandQueue queue(context, devices[0], 0, &err); + if (err != CL_SUCCESS) { + std::cerr << "CommandQueue::CommandQueue() failed (" << err << ")\n"; + return EXIT_FAILURE; + } + + cl::Buffer buffer(context, (cl_mem_flags)0, 1024, NULL, &err); + if (err != CL_SUCCESS) { + std::cerr << "Buffer::Buffer() failed (" << err << ")\n"; + return EXIT_FAILURE; + } + + err = kernel.setArg(0, buffer); + if (err != CL_SUCCESS) { + std::cerr << "Kernel::setArg() failed (" << err << ")\n"; + return EXIT_FAILURE; + } + + err = queue.enqueueTask(kernel); + if (err != CL_SUCCESS) { + std::cerr << "CommandQueue::enqueueTask() failed (" << err << ")\n"; + } + + // Force a clReleaseMemoryObject on buffer before dispatch. + buffer = cl::Buffer(); + + err = queue.finish(); + if (err != CL_SUCCESS) { + std::cerr << "CommandQueue::finish() failed (" << err << ")\n"; + } + + // std::cout << " Test: Pass!\n"; + return EXIT_SUCCESS; +} + +void OCLMemObjs::run(void) { + CHECK_RESULT((test() != EXIT_SUCCESS), "test failed"); +} + +unsigned int OCLMemObjs::close(void) { return _crcword; } diff --git a/opencl/tests/ocltst/module/runtime/OCLMemObjs.h b/opencl/tests/ocltst/module/runtime/OCLMemObjs.h new file mode 100644 index 0000000000..390f4db3ab --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLMemObjs.h @@ -0,0 +1,45 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_Mem_Objs_H_ +#define _OCL_Mem_Objs_H_ + +#include "CL/cl.h" +#include "OCLTestImp.h" + +class OCLMemObjs : public OCLTestImp { + public: + OCLMemObjs(); + virtual ~OCLMemObjs(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + int test(void); + + static const char* kernel_src; + + private: + cl_int error; +}; + +#endif // _OCL_Mem_Objs_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLMemoryInfo.cpp b/opencl/tests/ocltst/module/runtime/OCLMemoryInfo.cpp new file mode 100644 index 0000000000..093f5ce191 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLMemoryInfo.cpp @@ -0,0 +1,210 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLMemoryInfo.h" + +#include +#include +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +OCLMemoryInfo::OCLMemoryInfo() { + // Run the second test with 64 bit only + _numSubTests = (sizeof(int*) == 8) ? 2 : 1; + failed_ = false; +} + +OCLMemoryInfo::~OCLMemoryInfo() {} + +void OCLMemoryInfo::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + _deviceId = deviceId; + test_ = test; + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + + char name[1024] = {0}; + size_t size = 0; + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_EXTENSIONS, 1024, + name, &size); + if (!strstr(name, "cl_amd_device_attribute_query")) { + printf("AMD device attribute extension is required for this test!\n"); + failed_ = true; + return; + } + // Observed failures with APUs on GSL path due to incorrect available memory, + // reported for visible heap + cl_bool is_apu = false; + error_ = clGetDeviceInfo(devices_[deviceId], CL_DEVICE_HOST_UNIFIED_MEMORY, + sizeof(cl_bool), &is_apu, nullptr); + if (is_apu && (test == 1)) { + printf("Test not supported for apus, skipping...\n"); + failed_ = true; + return; + } +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLMemoryInfo::run(void) { + if (failed_) { + return; + } +#if EMU_ENV + size_t BufSize = 0x10000; +#else + size_t BufSize = 0x1000000; +#endif // EMU_ENV + bool succeed = false; + bool done = false; + if (test_ == 0) { + // use multiple loops to make sure the failure case is not caused + // by reusing the allocation from the cached memory pool + for (int i = 0; i < 5 && !done; i++) { + cl_mem buffer; + size_t memoryInfo[2]; + _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, + 2 * sizeof(size_t), memoryInfo, NULL); + + buffer = + _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, + BufSize * sizeof(cl_int4), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + + unsigned int* values; + values = reinterpret_cast(new cl_int4[BufSize]); + + // Clear destination buffer + memset(values, 0, BufSize * sizeof(cl_int4)); + error_ = _wrapper->clEnqueueWriteBuffer( + cmdQueues_[_deviceId], buffer, CL_TRUE, 0, BufSize * sizeof(cl_int4), + values, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + + size_t memoryInfo2[2]; + _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, + 2 * sizeof(size_t), memoryInfo2, NULL); + + size_t dif = memoryInfo[0] - memoryInfo2[0]; + if (dif == 0) { // the buffer memory may come from the cached memory pool + BufSize *= 2; // double the size and try again + } else if ((dif >= + (static_cast(BufSize * sizeof(cl_int4) * 1.5f) / + 1024)) || + (dif <= ((BufSize * sizeof(cl_int4) / 2) / 1024))) { + done = true; + } else { + succeed = true; + done = true; + } + + delete[] values; + } + } else { + int i = 0; + size_t sizeAll; + size_t memoryInfo[2]; + _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, + 2 * sizeof(size_t), memoryInfo, NULL); + unsigned int* values; + values = reinterpret_cast(new cl_int4[BufSize]); + memset(values, 0, BufSize * sizeof(cl_int4)); + // Loop a few times to make sure the results are consistent + for (int k = 0; k < 3; ++k) { + sizeAll = 0; + while (true) { + cl_mem buffer; + + buffer = + _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, + BufSize * sizeof(cl_int4), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + + // Clear destination buffer + error_ = _wrapper->clEnqueueWriteBuffer( + cmdQueues_[_deviceId], buffer, CL_TRUE, 0, + BufSize * sizeof(cl_int4), values, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + + sizeAll += BufSize * sizeof(cl_int4) / 1024; + size_t memoryInfo2[2]; + _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, + 2 * sizeof(size_t), memoryInfo2, NULL); +#if EMU_ENV + // For testing on emulator with 2G RAM and buffer size of x10000 + if (memoryInfo2[0] < (0x3e000 + (BufSize * sizeof(cl_int4) / 1024))) { +#else + if (memoryInfo2[0] < (0x50000 + (BufSize * sizeof(cl_int4) / 1024))) { +#endif // EMU_ENV + break; + } + size_t dif = memoryInfo[0] - memoryInfo2[0]; + // extra memory could be allocated/destroyed in the driver + if (dif == 0) { + // the buffer memory may come from the cached memory pool + } else if ((dif / sizeAll) == 1 || (sizeAll / dif) == 1) { + succeed = true; + } else { + succeed = false; + break; + } + ++i; + } + for (auto& it : buffers()) { + error_ = _wrapper->clReleaseMemObject(it); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), + "clReleaseMemObject() failed"); + } + buffers_.clear(); + if (!succeed) { + break; + } + } + delete[] values; + } + + if (!succeed) { + CHECK_RESULT(true, "Reported free memory doesn't match allocated size!"); + } +} + +unsigned int OCLMemoryInfo::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLMemoryInfo.h b/opencl/tests/ocltst/module/runtime/OCLMemoryInfo.h new file mode 100644 index 0000000000..9a95d11a38 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLMemoryInfo.h @@ -0,0 +1,42 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_MEMORY_INFO_H_ +#define _OCL_MEMORY_INFO_H_ + +#include "OCLTestImp.h" + +class OCLMemoryInfo : public OCLTestImp { + public: + OCLMemoryInfo(); + virtual ~OCLMemoryInfo(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; + uint32_t test_; +}; + +#endif // _OCL_MEMORY_INFO_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLMultiQueue.cpp b/opencl/tests/ocltst/module/runtime/OCLMultiQueue.cpp new file mode 100644 index 0000000000..9f1cd1d5b1 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLMultiQueue.cpp @@ -0,0 +1,295 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLMultiQueue.h" + +#include +#include +#include + +#include +#include + +#include "CL/cl.h" + +const static char* strKernel = + "__kernel void \n" + "copyInc(__global uint* dst, __global uint* src) \n" + "{ \n" + " uint index = get_global_id(0); \n" + " \n" + " dst[index] = src[index] + 1; \n" + "} \n"; + +static bool useGPU = true; + +static const cl_uint NumQueues = 8; // must be power of 2 +static cl_uint NumElements = 4096; +static const cl_uint NumRuns = 16384; +static const cl_uint ExecutionsPerQueue = 256; +std::stringstream lerror; + +class MemTransfer { + public: + MemTransfer(OCLWrapper* wrapper, cl_context context, cl_command_queue queue, + cl_uint numElements) + : wrapper_(wrapper), + context_(context), + queue_(queue), + numElements_(numElements), + count_(0) {} + + ~MemTransfer() { + wrapper_->clReleaseMemObject(dst_); + wrapper_->clReleaseMemObject(src_); + } + + bool create() { + cl_int err; + size_t size = numElements_ * sizeof(cl_uint); + cl_uint* data = new cl_uint[numElements_]; + memset(data, 0, size); + + src_ = wrapper_->clCreateBuffer(context_, CL_MEM_COPY_HOST_PTR, size, data, + &err); + if (src_ == NULL) { + lerror << "clReleaseContext failed"; + delete[] data; + return false; + } + dst_ = wrapper_->clCreateBuffer(context_, 0, size, NULL, &err); + if (dst_ == NULL) { + lerror << "clCreateBuffer() failed"; + delete[] data; + return false; + } + + delete[] data; + return true; + } + + bool run(cl_kernel kernel) { + size_t global_work_size[1]; + size_t local_work_size[1]; + size_t size = numElements_ * sizeof(cl_uint); + + global_work_size[0] = (numElements_ + 63) / 64 * 64; + local_work_size[0] = 64; + + if (CL_SUCCESS != + wrapper_->clSetKernelArg(kernel, 0, sizeof(cl_mem), (void*)&dst_)) { + return false; + } + + if (CL_SUCCESS != + wrapper_->clSetKernelArg(kernel, 1, sizeof(cl_mem), (void*)&src_)) { + return false; + } + + if (CL_SUCCESS != wrapper_->clEnqueueNDRangeKernel( + queue_, kernel, 1, NULL, + (const size_t*)global_work_size, + (const size_t*)local_work_size, 0, NULL, NULL)) { + lerror << "clEnqueueNDRangeKernel() failed"; + return false; + } + + // Copy dst into src + if (CL_SUCCESS != wrapper_->clEnqueueCopyBuffer(queue_, dst_, src_, 0, 0, + size, 0, 0, NULL)) { + lerror << "clEnqueueCopyBuffer() failed"; + return false; + } + count_++; + return true; + } + + bool check() { + size_t size = numElements_ * sizeof(cl_uint); + cl_event event; + void* ptr = wrapper_->clEnqueueMapBuffer(queue_, src_, CL_TRUE, CL_MAP_READ, + 0, size, 0, NULL, NULL, NULL); + cl_uint* data = reinterpret_cast(ptr); + + for (cl_uint i = 0; i < numElements_; ++i) { + if (data[i] != count_) { + return false; + } + } + wrapper_->clEnqueueUnmapMemObject(queue_, src_, ptr, 0, NULL, &event); + wrapper_->clWaitForEvents(1, &event); + wrapper_->clReleaseEvent(event); + return true; + } + + void flush() { wrapper_->clFlush(queue_); } + + private: + OCLWrapper* wrapper_; + cl_context context_; + cl_command_queue queue_; + cl_uint numElements_; + cl_uint count_; + cl_mem dst_; + cl_mem src_; +}; + +MemTransfer* work[NumQueues]; + +bool test(cl_kernel, cl_uint, cl_uint); + +OCLMultiQueue::OCLMultiQueue() { + _numSubTests = 0; + for (cl_uint i = 1; i <= NumQueues; i <<= 1, _numSubTests++) + ; + failed_ = false; +} + +OCLMultiQueue::~OCLMultiQueue() {} + +void OCLMultiQueue::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + test_ = test; + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + testDescString = "GPU device is required for this test!\n"; + failed_ = true; + return; + } + size_t maxWorkGroupSize = 1; + cl_uint computePower = 1; + error_ = _wrapper->clGetDeviceInfo( + devices_[deviceId], CL_DEVICE_MAX_WORK_GROUP_SIZE, + sizeof(maxWorkGroupSize), &maxWorkGroupSize, NULL); + computePower *= static_cast(maxWorkGroupSize); + cl_uint maxComputeUnits = 1; + error_ = _wrapper->clGetDeviceInfo( + devices_[deviceId], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(maxComputeUnits), + &maxComputeUnits, NULL); + computePower *= 32 * maxComputeUnits; + NumElements = (NumElements < static_cast(computePower)) + ? static_cast(computePower) + : NumElements; + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + kernel_ = _wrapper->clCreateKernel(program_, "copyInc", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); +} + +void OCLMultiQueue::run(void) { + if (failed_) { + return; + } + + // Run test + cl_uint queues = 1 << test_; + if (!test(kernel_, NumRuns / queues, queues)) { + lerror << "We failed a test run!"; + CHECK_RESULT(true, lerror.str().c_str()); + } +} + +unsigned int OCLMultiQueue::close(void) { return OCLTestImp::close(); } + +bool OCLMultiQueue::test(cl_kernel kernel, cl_uint numRuns, cl_uint numQueues) { + cl_command_queue cmd_queue[NumQueues]; + CPerfCounter timer; + + for (cl_uint i = 0; i < numQueues; ++i) { + cmd_queue[i] = _wrapper->clCreateCommandQueue(context_, devices_[_deviceId], + 0, &error_); + if (cmd_queue[i] == (cl_command_queue)0) { + _wrapper->clReleaseContext(context_); + testDescString = "clCreateCommandQueue() failed"; + return false; + } + work[i] = new MemTransfer(_wrapper, context_, cmd_queue[i], NumElements); + if (work[i] == NULL || !work[i]->create()) { + testDescString = "Test creation failed"; + return false; + } + } + + timer.Reset(); + timer.Start(); + + cl_uint dispatchCount = ExecutionsPerQueue / numQueues; + for (cl_uint i = 0; i < numRuns; ++i) { + for (cl_uint j = 0; j < numQueues; ++j) { + if (!work[j]->run(kernel)) { + testDescString = "Execution failed"; + return false; + } + // Every queue should have a dispatch after 256 executions, + // but the time for dispatch on each queue + // will be shifted on dispatchCount + if (((i % dispatchCount) == 0) && + (((i / dispatchCount) % numQueues) == j)) { + work[j]->flush(); + } + } + } + + for (cl_uint i = 0; i < numQueues; ++i) { + _wrapper->clFinish(cmd_queue[i]); + } + + timer.Stop(); + + for (cl_uint j = 0; j < numQueues; ++j) { + if (!work[j]->check()) { + testDescString = "Result Check fails!"; + return false; + } + } + std::stringstream stream; + + stream << "Num Queues: " << numQueues << ", Executions Per Queue: "; + stream.flags(std::ios::right | std::ios::showbase); + stream.width(5); + stream << numRuns; + stream.precision(3); + stream << ", Time: " << (float)(timer.GetElapsedTime()) << " seconds"; + + for (cl_uint i = 0; i < numQueues; ++i) { + delete work[i]; + _wrapper->clReleaseCommandQueue(cmd_queue[i]); + } + testDescString = stream.str(); + + return true; +} diff --git a/opencl/tests/ocltst/module/runtime/OCLMultiQueue.h b/opencl/tests/ocltst/module/runtime/OCLMultiQueue.h new file mode 100644 index 0000000000..57965add0b --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLMultiQueue.h @@ -0,0 +1,43 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_MULTI_QUEUE_H_ +#define _OCL_MULTI_QUEUE_H_ + +#include "OCLTestImp.h" + +class OCLMultiQueue : public OCLTestImp { + public: + OCLMultiQueue(); + virtual ~OCLMultiQueue(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool test(cl_kernel kernel, cl_uint numRuns, cl_uint numQueues); + bool failed_; + unsigned int test_; +}; + +#endif // _OCL_ASYNC_TRANSFER_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLOfflineCompilation.cpp b/opencl/tests/ocltst/module/runtime/OCLOfflineCompilation.cpp new file mode 100644 index 0000000000..17c5ae66ef --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLOfflineCompilation.cpp @@ -0,0 +1,206 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLOfflineCompilation.h" + +#include +#include +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" +#include "cl_kernel_info_amd.h" + +typedef CL_API_ENTRY cl_int(CL_API_CALL* clGetKernelInfoAMD_fn)( + cl_kernel kernel, cl_device_id device, cl_kernel_info_amd param_name, + size_t param_value_size, void* param_value, size_t* param_value_size_ret); + +clGetKernelInfoAMD_fn clGetKernelInfoAMDp; + +#define BLIT_KERNEL(...) #__VA_ARGS__ + +const char* strKernel12 = BLIT_KERNEL( +\n const constant uint test = 1; __kernel void factorial(__global uint* out) { + uint id = get_global_id(0); + uint factorial = 1; + out[id] = factorial + test; +} +\n); + +const char* strKernel20 = BLIT_KERNEL( +\n const constant uint test = 1; global uint test2 = 0; + __kernel void factorial(__global uint* out) { + uint id = get_global_id(0); + uint factorial = 1; + out[id] = factorial + test; + if (id == 0) { + out[id] += test2++; + } + } +\n); + +OCLOfflineCompilation::OCLOfflineCompilation() { _numSubTests = 1; } + +OCLOfflineCompilation::~OCLOfflineCompilation() {} + +void OCLOfflineCompilation::open(unsigned int test, char* units, + double& conversion, unsigned int deviceId) { + size_t nDevices = 0; + cl_device_id* devices = NULL; + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + _wrapper->clReleaseContext(context_); + + cl_context_properties cprops[5]; + clGetKernelInfoAMDp = + (clGetKernelInfoAMD_fn)clGetExtensionFunctionAddressForPlatform( + platform_, "clGetKernelInfoAMD"); + if (clGetKernelInfoAMDp == NULL) { + testDescString = "clGetKernelInfoAMD not found!\n"; + return; + } + + // Utilize the CL_CONTEXT_OFFLINE_DEVICES_AMD platform option to allow for + // the generation of binary kernel without target device installed in build + // system. + cprops[0] = CL_CONTEXT_PLATFORM; + cprops[1] = (cl_context_properties)platform_; + cprops[2] = CL_CONTEXT_OFFLINE_DEVICES_AMD; + cprops[3] = (cl_context_properties)1; + cprops[4] = (cl_context_properties)0; // end of options list marker + + // Create a context with all of the available devices. + context_ = _wrapper->clCreateContextFromType(cprops, CL_DEVICE_TYPE_GPU, NULL, + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateContextFromType() failed"); + + size_t deviceListSize = 0; + error_ = _wrapper->clGetContextInfo(context_, CL_CONTEXT_NUM_DEVICES, + sizeof(size_t), &deviceListSize, NULL); + CHECK_RESULT(((error_ != CL_SUCCESS) || (deviceListSize == 0)), + "clGetContextInfo() failed"); + + devices = (cl_device_id*)malloc(sizeof(cl_device_id) * deviceListSize); + CHECK_RESULT((devices == NULL), "clGetContextInfo() failed"); + + memset(devices, 0, deviceListSize); + + error_ = _wrapper->clGetContextInfo(context_, CL_CONTEXT_DEVICES, + sizeof(cl_device_id) * deviceListSize, + devices, &nDevices); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetContextInfo() failed"); + + for (unsigned version = 1; version <= 2; ++version) { + std::string options; + const char* strKernel; + + switch (version) { + case 1: + options = ""; + strKernel = strKernel12; + break; + case 2: + options = "-cl-std=CL2.0"; + strKernel = strKernel20; + break; + default: + assert(false); + return; + } + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + for (unsigned int i = 0; i < deviceListSize; ++i) { + char name[128]; + char strVersion[128]; + _wrapper->clGetDeviceInfo(devices[i], CL_DEVICE_NAME, sizeof(name), name, + NULL); + error_ = _wrapper->clGetDeviceInfo(devices[i], CL_DEVICE_VERSION, + sizeof(strVersion), strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + if (version == 2 && strVersion[7] < '2') { + continue; + } + + // skipping the test on gfx9+ for now till we add compiler support for al + // the gfx10+ subdevices + cl_uint gfxip_major = 0; + cl_uint gfxip_minor = 0; + clGetDeviceInfo(devices[i], CL_DEVICE_GFXIP_MAJOR_AMD, + sizeof(gfxip_major), &gfxip_major, NULL); + clGetDeviceInfo(devices[i], CL_DEVICE_GFXIP_MINOR_AMD, + sizeof(gfxip_minor), &gfxip_minor, NULL); + + printf("Building on %s, OpenCL version %s, (options '%s')\n", name, + (version == 2 ? "2.0" : "1.2"), options.c_str()); + error_ = _wrapper->clBuildProgram(program_, 1, &devices[i], + options.c_str(), NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo( + program_, devices[i], CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + break; + } + kernel_ = _wrapper->clCreateKernel(program_, "factorial", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + size_t usedVGPRs = 0; + error_ = + clGetKernelInfoAMDp(kernel_, devices[i], CL_KERNELINFO_USED_VGPRS, + sizeof(usedVGPRs), &usedVGPRs, NULL); + CHECK_RESULT(((error_ != CL_SUCCESS) || (usedVGPRs == 0)), + "clGetKernelInfoAMD() failed"); + + _wrapper->clReleaseKernel(kernel_); + kernel_ = nullptr; + + size_t binSize; + error_ = _wrapper->clGetProgramInfo(program_, CL_PROGRAM_BINARY_SIZES, + sizeof(size_t), &binSize, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetProgramInfo() failed"); + char* binary = new char[binSize]; + error_ = _wrapper->clGetProgramInfo(program_, CL_PROGRAM_BINARIES, + sizeof(char*), &binary, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetProgramInfo() failed"); + delete[] binary; + } + if (version == 1) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT((error_ != CL_SUCCESS), "clReleaseProgram() failed"); + } + } + free(devices); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLOfflineCompilation::run(void) {} + +unsigned int OCLOfflineCompilation::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLOfflineCompilation.h b/opencl/tests/ocltst/module/runtime/OCLOfflineCompilation.h new file mode 100644 index 0000000000..f6dd97b3d6 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLOfflineCompilation.h @@ -0,0 +1,38 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_OFFLINE_COMPILATION_H_ +#define _OCL_OFFLINE_COMPILATION_H_ + +#include "OCLTestImp.h" + +class OCLOfflineCompilation : public OCLTestImp { + public: + OCLOfflineCompilation(); + virtual ~OCLOfflineCompilation(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); +}; + +#endif // _OCL_OFFLINE_COMPILATION_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLP2PBuffer.cpp b/opencl/tests/ocltst/module/runtime/OCLP2PBuffer.cpp new file mode 100644 index 0000000000..278ff74d01 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLP2PBuffer.cpp @@ -0,0 +1,286 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLP2PBuffer.h" + +#include +#include +#include +#include + +#include +#include +#include + +#include "CL/cl.h" + +const static size_t ChunkSize = 256 * 1024; +const static int NumSizes = 5; +const static int NumRuns = 4; +const static int NumChunksArray[NumSizes] = {1, 4, 16, 32, 64}; +const static size_t MaxSubTests = NumRuns * NumSizes; +const static int NumIterArray[NumSizes] = {20, 15, 10, 10, 10}; + +OCLP2PBuffer::OCLP2PBuffer() { +#ifdef CL_VERSION_2_0 + _numSubTests = MaxSubTests; +#else + _numSubTests = 0; +#endif + failed_ = false; + maxSize_ = 0; + context0_ = nullptr; + context1_ = nullptr; + cmdQueue0_ = nullptr; + cmdQueue1_ = nullptr; +} + +OCLP2PBuffer::~OCLP2PBuffer() {} + +void OCLP2PBuffer::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { +#ifdef CL_VERSION_2_0 + cl_uint numPlatforms = 0; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + if (deviceCount_ < 2) { + printf("\nTwo GPUs are required to run P2P test\n"); + failed_ = true; + return; + } + + testID_ = test; + char name[1024] = {0}; + size_t size = 0; + _wrapper->clGetDeviceInfo(devices_[0], CL_DEVICE_EXTENSIONS, 1024, name, + &size); + if (!strstr(name, "cl_amd_copy_buffer_p2p")) { + printf("P2P extension is required for this test!\n"); + failed_ = true; + return; + } + + _wrapper->clGetDeviceInfo(devices_[1], CL_DEVICE_EXTENSIONS, 1024, name, + &size); + if (!strstr(name, "cl_amd_copy_buffer_p2p")) { + printf("P2P extension is required for this test!\n"); + failed_ = true; + return; + } + num_p2p_0_ = 0; + _wrapper->clGetDeviceInfo(devices_[0], CL_DEVICE_NUM_P2P_DEVICES_AMD, + sizeof(num_p2p_0_), &num_p2p_0_, nullptr); + if (num_p2p_0_ != 0) { + cl_device_id* p2p = new cl_device_id[num_p2p_0_]; + _wrapper->clGetDeviceInfo(devices_[0], CL_DEVICE_P2P_DEVICES_AMD, + sizeof(cl_device_id) * num_p2p_0_, p2p, nullptr); + delete[] p2p; + } + num_p2p_1_ = 0; + _wrapper->clGetDeviceInfo(devices_[1], CL_DEVICE_NUM_P2P_DEVICES_AMD, + sizeof(num_p2p_1_), &num_p2p_1_, nullptr); + if (num_p2p_1_ != 0) { + cl_device_id* p2p = new cl_device_id[num_p2p_1_]; + _wrapper->clGetDeviceInfo(devices_[1], CL_DEVICE_P2P_DEVICES_AMD, + sizeof(cl_device_id) * num_p2p_1_, p2p, nullptr); + delete[] p2p; + } + + cl_context_properties props[3] = {CL_CONTEXT_PLATFORM, + (cl_context_properties)platform, 0}; + context0_ = + _wrapper->clCreateContext(props, 1, &devices_[0], NULL, 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateContext#0 failed"); + + context1_ = + _wrapper->clCreateContext(props, 1, &devices_[1], NULL, 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateContext#1 failed"); + + NumChunks = NumChunksArray[testID_ % NumSizes]; + NumIter = NumIterArray[testID_ % NumSizes]; + BufferSize = NumChunks * ChunkSize * sizeof(cl_uint); + + p2p_copy_ = + (clEnqueueCopyBufferP2PAMD_fn)clGetExtensionFunctionAddressForPlatform( + platform_, "clEnqueueCopyBufferP2PAMD"); + if (p2p_copy_ == NULL) { + testDescString = "Failed to initialize P2P extension!\n"; + failed_ = true; + return; + } + + cl_queue_properties prop[] = {CL_QUEUE_PROPERTIES, 0, 0}; + cmdQueue0_ = _wrapper->clCreateCommandQueueWithProperties( + context0_, devices_[0], prop, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateCommandQueueWithProperties() failed"); + cmdQueue1_ = _wrapper->clCreateCommandQueueWithProperties( + context1_, devices_[1], prop, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateCommandQueueWithProperties() failed"); + + size_t chunkSize = ChunkSize; + + cl_mem buf = NULL; + cl_uint memFlags = 0; + buf = _wrapper->clCreateBuffer(context0_, CL_MEM_READ_ONLY | memFlags, + BufferSize, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buf); + + buf = + _wrapper->clCreateBuffer(context1_, memFlags, BufferSize, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buf); +#endif +} + +void OCLP2PBuffer::run(void) { +#ifdef CL_VERSION_2_0 + if (failed_) { + return; + } + size_t finalBuf = 0; + cl_uint subTest = (testID_ / NumSizes) % 2; + + cl_uint* buffer = new cl_uint[NumChunks * ChunkSize]; + cl_uint* buffer2 = new cl_uint[NumChunks * ChunkSize]; + cl_event event; + + memset(buffer, 0x23, BufferSize); + error_ = _wrapper->clEnqueueWriteBuffer(cmdQueue1_, buffers_[1], CL_TRUE, 0, + BufferSize, buffer, 0, nullptr, + (subTest == 0) ? &event : nullptr); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + + memset(buffer2, 0xEB, BufferSize); + error_ = _wrapper->clEnqueueWriteBuffer(cmdQueue0_, buffers_[0], CL_TRUE, 0, + BufferSize, buffer2, 0, nullptr, + (subTest == 1) ? &event : nullptr); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + + CPerfCounter timer; + + double sec = 0.; + if (subTest == 0) { + error_ = p2p_copy_(cmdQueue0_, buffers_[0], buffers_[1], 0, 0, BufferSize, + 1, &event, nullptr); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueCopyBufferP2PAMD() failed"); + _wrapper->clFinish(cmdQueue0_); + } else { + error_ = p2p_copy_(cmdQueue1_, buffers_[1], buffers_[0], 0, 0, BufferSize, + 1, &event, nullptr); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueCopyBufferP2PAMD() failed"); + _wrapper->clFinish(cmdQueue1_); + } + clReleaseEvent(event); + cl_command_queue execQueue; + if (((testID_ / NumSizes) == 0) || ((testID_ / NumSizes) == 3)) { + execQueue = cmdQueue0_; + } else { + execQueue = cmdQueue1_; + } + + for (int i = 0; i < NumIter; ++i) { + timer.Reset(); + timer.Start(); + + if (subTest == 0) { + p2p_copy_(execQueue, buffers_[0], buffers_[1], 0, 0, BufferSize, 0, + nullptr, nullptr); + } else { + p2p_copy_(execQueue, buffers_[1], buffers_[0], 0, 0, BufferSize, 0, + nullptr, nullptr); + } + _wrapper->clFinish(execQueue); + timer.Stop(); + double cur = timer.GetElapsedTime(); + if (i == 0) { + sec = cur; + } else { + sec = std::min(cur, sec); + } + } + memset(buffer, 0x20, BufferSize); + if (subTest == 0) { + error_ = _wrapper->clEnqueueReadBuffer(cmdQueue1_, buffers_[1], CL_TRUE, 0, + BufferSize, buffer, 0, NULL, NULL); + } else { + error_ = _wrapper->clEnqueueReadBuffer(cmdQueue0_, buffers_[0], CL_TRUE, 0, + BufferSize, buffer, 0, NULL, NULL); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed!"); + + cl_uint cmp_value = (subTest == 0) ? 0xEBEBEBEB : 0x23232323; + for (int c = 0; c < NumChunks; ++c) { + for (cl_uint i = 0; i < ChunkSize; ++i) { + if (buffer[c * ChunkSize + i] != cmp_value) { + CHECK_RESULT(true, "Validation failed!"); + } + } + } + delete[] buffer; + delete[] buffer2; + + cl_uint* p2p = ((subTest == 0) ? &num_p2p_0_ : &num_p2p_1_); + static const char* MemTypeStr[] = {"Visible ", "Remote ", "Invisible", + "Staging"}; + _perfInfo = (float)BufferSize / ((float)sec * 1000.f * 1000.f * 1000.f); + std::stringstream str; + if ((testID_ / (2 * NumSizes)) == 0) { + str << "Write dev" << ((subTest == 0) ? 0 : 1) << "->dev" + << ((subTest == 0) ? 1 : 0) << ((*p2p != 0) ? " " : " ") << "("; + } else { + str << "Read dev" << ((subTest == 0) ? 1 : 0) << "<-dev" + << ((subTest == 0) ? 0 : 1) << ((*p2p != 0) ? " " : " ") << "("; + } + str.width(2); + str << BufferSize / (1000 * 1000); + str << " MB " + << ") transfer speed (GB/s):"; + testDescString = str.str(); +#endif +} + +unsigned int OCLP2PBuffer::close(void) { +#ifdef CL_VERSION_2_0 + if (!failed_) { + if (cmdQueue0_ != nullptr) { + _wrapper->clReleaseCommandQueue(cmdQueue0_); + } + if (cmdQueue1_ != nullptr) { + _wrapper->clReleaseCommandQueue(cmdQueue1_); + } + if (context0_ != nullptr) { + _wrapper->clReleaseContext(context0_); + } + if (context1_ != nullptr) { + _wrapper->clReleaseContext(context1_); + } + } + return OCLTestImp::close(); +#else + return CL_SUCCESS; +#endif +} diff --git a/opencl/tests/ocltst/module/runtime/OCLP2PBuffer.h b/opencl/tests/ocltst/module/runtime/OCLP2PBuffer.h new file mode 100644 index 0000000000..9e9e52fcfc --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLP2PBuffer.h @@ -0,0 +1,56 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_P2P_BUFFER_H_ +#define _OCL_P2P_BUFFER_H_ + +#include "OCLTestImp.h" + +class OCLP2PBuffer : public OCLTestImp { + public: + OCLP2PBuffer(); + virtual ~OCLP2PBuffer(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; + unsigned int testID_; + cl_ulong maxSize_; + size_t BufferSize; + int NumChunks; + int NumIter; + int NumStages; + cl_context context0_; + cl_context context1_; + cl_command_queue cmdQueue0_; + cl_command_queue cmdQueue1_; + cl_uint num_p2p_0_; + cl_uint num_p2p_1_; +#ifdef CL_VERSION_2_0 + clEnqueueCopyBufferP2PAMD_fn p2p_copy_; +#endif +}; + +#endif // _OCL_P2P_BUFFER_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLPartialWrkgrp.cpp b/opencl/tests/ocltst/module/runtime/OCLPartialWrkgrp.cpp new file mode 100644 index 0000000000..ea00f1010c --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLPartialWrkgrp.cpp @@ -0,0 +1,304 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPartialWrkgrp.h" + +#include +#include +#include +#include + +#include "CL/cl.h" + +static const size_t BufSize = 0x1000; + +const static char* strKernel = + "__kernel void fillX(__global int4* out) \n" + "{ \n" + " int id = get_global_id(0); \n" + " out[id].x = id; \n" + "} \n" + " \n" + "__kernel void fillXY(__global int4* out) \n" + "{ \n" + " int id = get_global_id(0) + get_global_id(1) * get_global_size(0); \n" + " out[id].x = get_global_id(0); \n" + " out[id].y = get_global_id(1); \n" + "} \n" + " \n" + "__kernel void fillXYZ(__global int4* out) \n" + "{ \n" + " int id = get_global_id(0) + get_global_id(1) * get_global_size(0) + \n" + " get_global_id(2) * get_global_size(0) * get_global_size(1); \n" + " out[id].x = get_global_id(0); \n" + " out[id].y = get_global_id(1); \n" + " out[id].z = get_global_id(2); \n" + "} \n"; + +OCLPartialWrkgrp::OCLPartialWrkgrp() { + _numSubTests = 3; + isOCL2_ = true; +} + +OCLPartialWrkgrp::~OCLPartialWrkgrp() {} + +void OCLPartialWrkgrp::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + _openTest = test; + + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + char version[128]; + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_VERSION, + sizeof(version), version, NULL); + + if (_openTest != 0 && strstr(version, "OpenCL 2.0") == NULL) { + isOCL2_ = false; + return; + } + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + switch (_openTest) { + case 0: + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + break; + case 1: + error_ = _wrapper->clBuildProgram( + program_, 1, &devices_[deviceId], + "-cl-uniform-work-group-size -cl-std=CL2.0", NULL, NULL); + break; + case 2: + error_ = _wrapper->clBuildProgram( + program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + break; + default: + CHECK_RESULT(false, "Invalid test number > _numSubTests"); + return; + } + + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "fillX", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, + BufSize * sizeof(cl_int4), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLPartialWrkgrp::run(void) { + if (!isOCL2_) return; + unsigned int* values; + cl_mem buffer = buffers()[0]; + values = reinterpret_cast(new cl_int4[BufSize]); + + // + // Check unaligned workgroup in X dimension + // + + // Clear destination buffer + memset(values, 0, BufSize * sizeof(cl_int4)); + error_ = _wrapper->clEnqueueWriteBuffer(cmdQueues_[_deviceId], buffer, + CL_TRUE, 0, BufSize * sizeof(cl_int4), + values, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t gws[1] = {BufSize - 1}; + size_t lws[1] = {256}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, lws, 0, NULL, NULL); + + switch (_openTest) { + case 2: + if (error_ != CL_SUCCESS) { + CHECK_RESULT(false, "clEnqueueNDRangeKernel() failed"); + return; + } + error_ = _wrapper->clEnqueueReadBuffer( + cmdQueues_[_deviceId], buffer, CL_TRUE, 0, BufSize * sizeof(cl_int4), + values, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + + for (size_t x = 0; x < BufSize; ++x) { + if (x == (BufSize - 1)) { + CHECK_RESULT((values[4 * x] != 0), "Comparison failed!"); + } else { + CHECK_RESULT((values[4 * x] != x), "Comparison failed!"); + } + } + break; + case 1: + case 0: + CHECK_RESULT((error_ != CL_INVALID_WORK_GROUP_SIZE), + "clEnqueueNDRangeKernel(): " + "Expected to fail for non-uniform work group sizes!"); + break; + default: + CHECK_RESULT(false, "Invalid test number > _numSubTests"); + return; + } + + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), "clReleaseKernel() failed"); + + // + // Check unaligned workgroup in X and Y dimensions + // + kernel_ = _wrapper->clCreateKernel(program_, "fillXY", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + // Clear destination buffer + memset(values, 0, BufSize * sizeof(cl_int4)); + error_ = _wrapper->clEnqueueWriteBuffer(cmdQueues_[_deviceId], buffer, + CL_TRUE, 0, BufSize * sizeof(cl_int4), + values, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t gws2[2] = {0x3f, 0x3f}; + size_t lws2[2] = {16, 16}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 2, + NULL, gws2, lws2, 0, NULL, NULL); + + switch (_openTest) { + case 2: + if (error_ != CL_SUCCESS) { + CHECK_RESULT(false, "clEnqueueNDRangeKernel() failed"); + return; + } + error_ = _wrapper->clEnqueueReadBuffer( + cmdQueues_[_deviceId], buffer, CL_TRUE, 0, BufSize * sizeof(cl_int4), + values, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + + for (size_t y = 0; y < 0x40; ++y) { + for (size_t x = 0; x < 0x3f; ++x) { + size_t id = x + y * 0x3f; + if (y == 0x3f) { + CHECK_RESULT((values[4 * id] != 0), "Comparison failed!"); + CHECK_RESULT((values[4 * id + 1] != 0), "Comparison failed!"); + } else { + CHECK_RESULT((values[4 * id] != x), "Comparison failed!"); + CHECK_RESULT((values[4 * id + 1] != y), "Comparison failed!"); + } + } + } + break; + case 1: + case 0: + CHECK_RESULT((error_ != CL_INVALID_WORK_GROUP_SIZE), + "clEnqueueNDRangeKernel(): " + "Expected to fail for non-uniform work group sizes!"); + break; + default: + CHECK_RESULT(false, "Invalid test number > _numSubTests"); + return; + } + + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN((error_ != CL_SUCCESS), "clReleaseKernel() failed"); + + // + // Check unaligned workgroup in X, Y and Z dimensions + // + kernel_ = _wrapper->clCreateKernel(program_, "fillXYZ", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + // Clear destination buffer + memset(values, 0, BufSize * sizeof(cl_int4)); + error_ = _wrapper->clEnqueueWriteBuffer(cmdQueues_[_deviceId], buffer, + CL_TRUE, 0, BufSize * sizeof(cl_int4), + values, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t gws3[3] = {0xf, 0x10, 0xf}; + size_t lws3[3] = {4, 4, 4}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 3, + NULL, gws3, lws3, 0, NULL, NULL); + switch (_openTest) { + case 2: + if (error_ != CL_SUCCESS) { + CHECK_RESULT(false, "clEnqueueNDRangeKernel() failed"); + return; + } + error_ = _wrapper->clEnqueueReadBuffer( + cmdQueues_[_deviceId], buffer, CL_TRUE, 0, BufSize * sizeof(cl_int4), + values, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + + for (size_t z = 0; z < 0x10; ++z) { + for (size_t y = 0; y < 0x10; ++y) { + for (size_t x = 0; x < 0xf; ++x) { + size_t id = x + y * 0xf + z * 0xf0; + if (z == 0xf) { + CHECK_RESULT((values[4 * id] != 0), "Comparison failed!"); + CHECK_RESULT((values[4 * id + 1] != 0), "Comparison failed!"); + CHECK_RESULT((values[4 * id + 2] != 0), "Comparison failed!"); + } else { + CHECK_RESULT((values[4 * id] != x), "Comparison failed!"); + CHECK_RESULT((values[4 * id + 1] != y), "Comparison failed!"); + CHECK_RESULT((values[4 * id + 2] != z), "Comparison failed!"); + } + } + } + } + break; + case 1: + case 0: + CHECK_RESULT((error_ != CL_INVALID_WORK_GROUP_SIZE), + "clEnqueueNDRangeKernel(): " + "Expected fail for non-uniform work group sizes!"); + break; + default: + CHECK_RESULT(false, "Invalid test number > _numSubTests"); + return; + } + + delete[] values; +} + +unsigned int OCLPartialWrkgrp::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLPartialWrkgrp.h b/opencl/tests/ocltst/module/runtime/OCLPartialWrkgrp.h new file mode 100644 index 0000000000..c68afdef06 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLPartialWrkgrp.h @@ -0,0 +1,41 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PARTIAL_WRKGRP_H_ +#define _OCL_PARTIAL_WRKGRP_H_ + +#include "OCLTestImp.h" + +class OCLPartialWrkgrp : public OCLTestImp { + public: + OCLPartialWrkgrp(); + virtual ~OCLPartialWrkgrp(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool isOCL2_; +}; + +#endif // _OCL_PARTIAL_WRKGRP_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLPerfCounters.cpp b/opencl/tests/ocltst/module/runtime/OCLPerfCounters.cpp new file mode 100644 index 0000000000..0e7de54e0d --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLPerfCounters.cpp @@ -0,0 +1,824 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPerfCounters.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "Timer.h" + +#ifdef WIN_OS +#define SNPRINTF sprintf_s +#else +#define SNPRINTF snprintf +#endif + +struct PerfCounterInfo { + cl_long blockIdx; //!< Block Index + cl_long counterIdx; //!< Counter Index + cl_long eventIdx; //!< Event Index +}; + +struct DeviceCounterInfo { + const char *deviceName_; //!< Device name + unsigned int devId_; //!< Device id + PerfCounterInfo perfCounter_[2]; //!< Perforamnce counter array +}; + +static const DeviceCounterInfo DeviceInfo[]{ +#ifdef _WIN32 + // GFX11 supports performance counter on Windows only. + {"gfx1100", + 11, + {{139, 0, 4}, {74, 0, 13}}}, // {SQWGP, reg 0, SQ_PERF_SEL_WAVES}, {CPC, + // reg 0, Me1 busy for packet decode} + {"gfx1101", + 11, + {{139, 0, 4}, {74, 0, 13}}}, // {SQWGP, reg 0, SQ_PERF_SEL_WAVES}, {CPC, + // reg 0, Me1 busy for packet decode} + {"gfx1102", + 11, + {{139, 0, 4}, {74, 0, 13}}}, // {SQWGP, reg 0, SQ_PERF_SEL_WAVES}, {CPC, + // reg 0, Me1 busy for packet decode} + {"gfx1103", + 11, + {{139, 0, 4}, {74, 0, 13}}}, // {SQWGP, reg 0, SQ_PERF_SEL_WAVES}, {CPC, + // reg 0, Me1 busy for packet decode} +#endif + // GFX10 + {"gfx1000", + 10, + {{15, 0, 4}, {74, 0, 13}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {CPC, + // reg 0, Me1 busy for packet decode} + {"gfx1010", + 10, + {{15, 0, 4}, {74, 0, 13}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {CPC, + // reg 0, Me1 busy for packet decode} + {"gfx1011", + 10, + {{15, 0, 4}, {74, 0, 13}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {CPC, + // reg 0, Me1 busy for packet decode} + {"gfx1012", + 10, + {{15, 0, 4}, {74, 0, 13}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {CPC, + // reg 0, Me1 busy for packet decode} + // GFX9 + {"gfx900", + 9, + {{14, 0, 4}, {97, 1, 2}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {MCVML2_l, + // reg 0, BigK bank 0 hits} + {"gfx901", + 9, + {{14, 0, 4}, {97, 1, 2}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {MCVML2_l, + // reg 0, BigK bank 0 hits} + {"gfx902", + 9, + {{14, 0, 4}, {97, 1, 2}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {MCVML2_l, + // reg 0, BigK bank 0 hits} + {"gfx903", + 9, + {{14, 0, 4}, {97, 1, 2}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {MCVML2_l, + // reg 0, BigK bank 0 hits} + {"gfx904", + 9, + {{14, 0, 4}, {97, 1, 2}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {MCVML2_l, + // reg 0, BigK bank 0 hits} + {"gfx905", + 9, + {{14, 0, 4}, {97, 1, 2}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {MCVML2_l, + // reg 0, BigK bank 0 hits} + {"gfx906", + 9, + {{14, 0, 4}, {97, 1, 2}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {MCVML2_l, + // reg 0, BigK bank 0 hits} + {"gfx907", + 9, + {{14, 0, 4}, {97, 1, 2}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {MCVML2_l, + // reg 0, BigK bank 0 hits} + // Sea Islands, GFX8 + {"Bonaire", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Hawaii", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Maui", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Casper", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Spectre", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Slimer", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Spooky", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Kalindi", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Mullins", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Iceland", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Tonga", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Bermuda", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Fiji", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Carrizo", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Ellesmere", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Baffin", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Stoney", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"gfx804", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"gfx803", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Bristol Ridge", + 0, + {{14, 0, 4}, {9, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + // Southern Islands + {"Tahiti", + 0, + {{10, 0, 4}, {5, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Pitcairn", + 0, + {{10, 0, 4}, {5, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Capeverde", + 0, + {{10, 0, 4}, {5, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Oland", + 0, + {{10, 0, 4}, {5, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} + {"Hainan", + 0, + {{10, 0, 4}, {5, 0, 3}}}, // {SQ, reg 0, SQ_PERF_SEL_WAVES}, {GRBM, reg 0, + // GRBM_PERF_SEL_CP_BUSY} +}; +const int DeviceCounterSize = sizeof(DeviceInfo) / sizeof(DeviceCounterInfo); + +static const char *sha256_kernel = + "typedef uint UINT;\n" + "\n" + "#define VECTOR_LEN 1\n" + "\n" + "#ifdef LITTLE_E\n" + "\n" + "inline UINT byteswap(UINT x)\n" + "{\n" + " UINT res = 0;\n" + " \n" + " for (uint i=0; i<4; i++)\n" + " {\n" + " res <<= 8;\n" + " res |= (x & 0xff);\n" + " x >>= 8;\n" + " }\n" + " \n" + " return res;\n" + "}\n" + "\n" + "#else\n" + "\n" + "inline UINT byteswap(const UINT x)\n" + "{\n" + " return x;\n" + "}\n" + "\n" + "#endif\n" + "\n" + "\n" + "void sha256_step( const UINT data[16], UINT *state )\n" + "{\n" + " UINT W[64], temp1, temp2;\n" + " UINT A, B, C, D, E, F, G, H;\n" + "\n" + " for( int i = 0; i < 16; i++)\n" + " {\n" + " W[i] = byteswap(data[i]);\n" + " }\n" + "\n" + "#define SHR(x,n) ((x & 0xFFFFFFFF) >> n)\n" + "#define ROTR(x,n) (SHR(x,n) | (x << (32 - n)))\n" + "\n" + "#define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))\n" + "#define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))\n" + "\n" + "#define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))\n" + "#define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))\n" + "\n" + "#define F0(x,y,z) ((x & y) | (z & (x | y)))\n" + "#define F1(x,y,z) (z ^ (x & (y ^ z)))\n" + "\n" + "#define R(t) \\\n" + "( \\\n" + " W[t] = S1(W[t - 2]) + W[t - 7] + \\\n" + " S0(W[t - 15]) + W[t - 16] \\\n" + ")\n" + "\n" + "#define P(a,b,c,d,e,f,g,h,x,K) \\\n" + "{ \\\n" + " temp1 = h + S3(e) + F1(e,f,g) + K + x; \\\n" + " temp2 = S2(a) + F0(a,b,c); \\\n" + " d += temp1; h = temp1 + temp2; \\\n" + "}\n" + "\n" + " A = state[0];\n" + " B = state[1];\n" + " C = state[2];\n" + " D = state[3];\n" + " E = state[4];\n" + " F = state[5];\n" + " G = state[6];\n" + " H = state[7];\n" + "\n" + " P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98 );\n" + " P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491 );\n" + " P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF );\n" + " P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5 );\n" + " P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B );\n" + " P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1 );\n" + " P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4 );\n" + " P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5 );\n" + " P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98 );\n" + " P( H, A, B, C, D, E, F, G, W[ 9], 0x12835B01 );\n" + " P( G, H, A, B, C, D, E, F, W[10], 0x243185BE );\n" + " P( F, G, H, A, B, C, D, E, W[11], 0x550C7DC3 );\n" + " P( E, F, G, H, A, B, C, D, W[12], 0x72BE5D74 );\n" + " P( D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE );\n" + " P( C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7 );\n" + " P( B, C, D, E, F, G, H, A, W[15], 0xC19BF174 );\n" + " P( A, B, C, D, E, F, G, H, R(16), 0xE49B69C1 );\n" + " P( H, A, B, C, D, E, F, G, R(17), 0xEFBE4786 );\n" + " P( G, H, A, B, C, D, E, F, R(18), 0x0FC19DC6 );\n" + " P( F, G, H, A, B, C, D, E, R(19), 0x240CA1CC );\n" + " P( E, F, G, H, A, B, C, D, R(20), 0x2DE92C6F );\n" + " P( D, E, F, G, H, A, B, C, R(21), 0x4A7484AA );\n" + " P( C, D, E, F, G, H, A, B, R(22), 0x5CB0A9DC );\n" + " P( B, C, D, E, F, G, H, A, R(23), 0x76F988DA );\n" + " P( A, B, C, D, E, F, G, H, R(24), 0x983E5152 );\n" + " P( H, A, B, C, D, E, F, G, R(25), 0xA831C66D );\n" + " P( G, H, A, B, C, D, E, F, R(26), 0xB00327C8 );\n" + " P( F, G, H, A, B, C, D, E, R(27), 0xBF597FC7 );\n" + " P( E, F, G, H, A, B, C, D, R(28), 0xC6E00BF3 );\n" + " P( D, E, F, G, H, A, B, C, R(29), 0xD5A79147 );\n" + " P( C, D, E, F, G, H, A, B, R(30), 0x06CA6351 );\n" + " P( B, C, D, E, F, G, H, A, R(31), 0x14292967 );\n" + " P( A, B, C, D, E, F, G, H, R(32), 0x27B70A85 );\n" + " P( H, A, B, C, D, E, F, G, R(33), 0x2E1B2138 );\n" + " P( G, H, A, B, C, D, E, F, R(34), 0x4D2C6DFC );\n" + " P( F, G, H, A, B, C, D, E, R(35), 0x53380D13 );\n" + " P( E, F, G, H, A, B, C, D, R(36), 0x650A7354 );\n" + " P( D, E, F, G, H, A, B, C, R(37), 0x766A0ABB );\n" + " P( C, D, E, F, G, H, A, B, R(38), 0x81C2C92E );\n" + " P( B, C, D, E, F, G, H, A, R(39), 0x92722C85 );\n" + " P( A, B, C, D, E, F, G, H, R(40), 0xA2BFE8A1 );\n" + " P( H, A, B, C, D, E, F, G, R(41), 0xA81A664B );\n" + " P( G, H, A, B, C, D, E, F, R(42), 0xC24B8B70 );\n" + " P( F, G, H, A, B, C, D, E, R(43), 0xC76C51A3 );\n" + " P( E, F, G, H, A, B, C, D, R(44), 0xD192E819 );\n" + " P( D, E, F, G, H, A, B, C, R(45), 0xD6990624 );\n" + " P( C, D, E, F, G, H, A, B, R(46), 0xF40E3585 );\n" + " P( B, C, D, E, F, G, H, A, R(47), 0x106AA070 );\n" + " P( A, B, C, D, E, F, G, H, R(48), 0x19A4C116 );\n" + " P( H, A, B, C, D, E, F, G, R(49), 0x1E376C08 );\n" + " P( G, H, A, B, C, D, E, F, R(50), 0x2748774C );\n" + " P( F, G, H, A, B, C, D, E, R(51), 0x34B0BCB5 );\n" + " P( E, F, G, H, A, B, C, D, R(52), 0x391C0CB3 );\n" + " P( D, E, F, G, H, A, B, C, R(53), 0x4ED8AA4A );\n" + " P( C, D, E, F, G, H, A, B, R(54), 0x5B9CCA4F );\n" + " P( B, C, D, E, F, G, H, A, R(55), 0x682E6FF3 );\n" + " P( A, B, C, D, E, F, G, H, R(56), 0x748F82EE );\n" + " P( H, A, B, C, D, E, F, G, R(57), 0x78A5636F );\n" + " P( G, H, A, B, C, D, E, F, R(58), 0x84C87814 );\n" + " P( F, G, H, A, B, C, D, E, R(59), 0x8CC70208 );\n" + " P( E, F, G, H, A, B, C, D, R(60), 0x90BEFFFA );\n" + " P( D, E, F, G, H, A, B, C, R(61), 0xA4506CEB );\n" + " P( C, D, E, F, G, H, A, B, R(62), 0xBEF9A3F7 );\n" + " P( B, C, D, E, F, G, H, A, R(63), 0xC67178F2 );\n" + "\n" + " state[0] += A;\n" + " state[1] += B;\n" + " state[2] += C;\n" + " state[3] += D;\n" + " state[4] += E;\n" + " state[5] += F;\n" + " state[6] += G;\n" + " state[7] += H;\n" + "}\n" + "\n" + "\n" + "#define choose_temp(x) ((x)/16)\n" + "\n" + "#define STORE_TO_TEMP(i) tb[((i)/16)][((i)%16)]\n" + "\n" + "\n" + "__kernel void CryptThread(__global const uint *buffer, __global uint " + "*state, const uint blockLen, const uint foo)\n" + "{\n" + " const uint init[8] = {\n" + " 0x6a09e667,\n" + " 0xbb67ae85,\n" + " 0x3c6ef372,\n" + " 0xa54ff53a,\n" + " 0x510e527f,\n" + " 0x9b05688c,\n" + " 0x1f83d9ab,\n" + " 0x5be0cd19\n" + " };\n" + " \n" + " const uint id = get_global_id(0);\n" + " uint len = blockLen;\n" + " uint i, j;\n" + " const uint startPosInDWORDs = (len*id*foo)/4;\n" + " const uint msgLenInBitsl = len * 8;\n" + " const uint msgLenInBitsh = (len) >> (32-3);\n" + " UINT localState[8];\n" + "\n" + " for (j=0; j<8; j++) {\n" + " localState[j] = init[j];\n" + " }\n" + "\n" + " i = 0;\n" + " while (len >=64)\n" + " {\n" + " UINT data[16];\n" + " for (j=0; j<16; j++) {\n" + " data[j] = buffer[j + startPosInDWORDs + i];\n" + " }\n" + "\n" + " sha256_step(data, localState);\n" + " i += 16;\n" + " len -= 64;\n" + " }\n" + "\n" + " len /= 4;\n" + "\n" + " UINT tb[2][16];\n" + "\n" + " for (j=0; jclEnqueueMapBuffer( + cmd_queue_, buffer, true, CL_MAP_WRITE, 0, bufSize_, 0, NULL, NULL, + &error_); + + if (error_ != CL_SUCCESS) { + printf("\nError code : %d\n", error_); + } else { + for (unsigned int i = 0; i < width_; i++) data[i] = val; + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, + NULL, NULL); + if (error_ == CL_SUCCESS) retVal = true; + } + return retVal; +} + +void OCLPerfCounters::checkData(cl_mem buffer) { + unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapBuffer( + cmd_queue_, buffer, true, CL_MAP_READ, 0, bufSize_, 0, NULL, NULL, + &error_); + for (unsigned int i = 0; i < width_; i++) { + } + error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, + NULL); +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLPerfCounters::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id *devices = NULL; + cl_device_id device = NULL; + _crcword = 0; + conversion = 1.0f; + _deviceId = deviceId; + _openTest = test; + + context_ = 0; + cmd_queue_ = 0; + program_ = 0; + kernel_ = 0; + inBuffer_ = 0; + outBuffer_ = 0; + num_input_buf_ = 1; + num_output_buf_ = 1; + blockSize_ = 1024; + isAMD = false; + + if (type_ != CL_DEVICE_TYPE_GPU) { + char msg[256]; + SNPRINTF(msg, sizeof(msg), "No GPU devices present. Exiting!\t"); + testDescString = msg; + return; + } + + width_ = 22347776; + // We compute a square domain + bufSize_ = width_ * sizeof(cl_uint); + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id *platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms-1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); + // Runtime returns an error when no GPU devices are present instead of just + // returning 0 devices + // CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + // Choose platform with GPU devices + if (num_devices > 0) { + if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { + isAMD = true; + } + // platform = platforms[_platformIndex]; + // break; + } +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, + "Couldn't find platform with GPU devices, cannot proceed"); + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + + global_device = device; + + context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, + &error_); + CHECK_RESULT(context_ == 0, "clCreateContext failed"); + + char charbuf[1024]; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, + charbuf, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL); + CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed"); + + inBuffer_ = new cl_mem[4]; + outBuffer_ = new cl_mem[4]; + + for (int i = 0; i < num_input_buf_; ++i) { + inBuffer_[i] = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(inBuffer_[i] == 0, "clCreateBuffer(inBuffer) failed"); + bool result = setData(inBuffer_[i], 0xdeadbeef); + CHECK_RESULT(result != true, "clEnqueueMapBuffer buffer failed"); + } + + for (int i = 0; i < num_output_buf_; ++i) { + outBuffer_[i] = + _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_); + CHECK_RESULT(outBuffer_[i] == 0, "clCreateBuffer(outBuffer) failed"); + bool result = setData(outBuffer_[i], 0xdeadbeef); + CHECK_RESULT(result != true, "clEnqueueMapBuffer buffer failed"); + } + + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, (const char **)&sha256_kernel, NULL, &error_); + CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed"); + + const char *buildOps = NULL; + if (isAMD) { + // Enable caching + buildOps = "-fno-alias"; + } + error_ = _wrapper->clBuildProgram(program_, 1, &device, buildOps, NULL, NULL); + + if (error_ != CL_SUCCESS) { + cl_int intError; + char log[16384]; + intError = + _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG, + 16384 * sizeof(char), log, NULL); + printf("Build error -> %s\n", log); + + CHECK_RESULT(0, "clBuildProgram failed"); + } + kernel_ = _wrapper->clCreateKernel(program_, "CryptThread", &error_); + CHECK_RESULT(kernel_ == 0, "clCreateKernel failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&inBuffer_[0]); + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), + (void *)&outBuffer_[0]); + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_uint), + (void *)&blockSize_); + // Foo is not part of the original test, this can be used to see how much of + // the performance is limited by fetch. Set foo to 0 and all threads will + // fetch the same 1k block. This way they will all be in cache and hit max + // fetch speed. + unsigned int foo = 1; + error_ = _wrapper->clSetKernelArg(kernel_, 3, sizeof(cl_uint), (void *)&foo); +} + +void OCLPerfCounters::run(void) { + // Test runs only on GPU + if (type_ != CL_DEVICE_TYPE_GPU) return; + + size_t global = bufSize_ / blockSize_; + // 32 gives the best result due to memory thrashing. Need to optimize and + // give feedback to SiSoft. + size_t local = 64; + char buf[256]; + + size_t global_work_size[1] = {global}; + size_t local_work_size[1] = {local}; + + cl_int err = 0; + cl_perfcounter_amd perfCounter; + cl_perfcounter_property properties[4][2]; + cl_event perfEvent; + cl_ulong result; + char deviceName[1024]; + + properties[0][0] = CL_PERFCOUNTER_GPU_BLOCK_INDEX; + properties[1][0] = CL_PERFCOUNTER_GPU_COUNTER_INDEX; + properties[2][0] = CL_PERFCOUNTER_GPU_EVENT_INDEX; + properties[3][0] = CL_PERFCOUNTER_NONE; + + err = _wrapper->clGetDeviceInfo(global_device, CL_DEVICE_NAME, 1024, + deviceName, NULL); + CHECK_RESULT(err != CL_SUCCESS, "clGetDeviceInfo failed"); + + // Remove target ID features + char* targetIdColon = strchr(deviceName, ':'); + if (targetIdColon != nullptr) { + size_t idx = targetIdColon - deviceName; + deviceName[idx] = '\0'; + } + + // Begin: to be removed when crash on Kabini is fixed + if (strcmp(deviceName, "Kalindi") == 0) { + char msg[256]; + SNPRINTF(msg, sizeof(msg), "Exiting as device is Kabini!\t"); + testDescString = msg; + return; + } + // End: to be removed when crash on Kabini is fixed + + bool found = false; + unsigned int devId = 0; + for (int idx = 0; !found && idx < DeviceCounterSize; idx++) { + if (strcmp(deviceName, DeviceInfo[idx].deviceName_) == 0) { + devId = DeviceInfo[idx].devId_; + properties[0][1] = DeviceInfo[idx].perfCounter_[_openTest].blockIdx; + properties[1][1] = DeviceInfo[idx].perfCounter_[_openTest].counterIdx; + properties[2][1] = DeviceInfo[idx].perfCounter_[_openTest].eventIdx; + found = true; + } + } + + if (!found) { + char msg[256]; + SNPRINTF(msg, sizeof(msg), "Unsupported device(%s) for the test!\t", + deviceName); + testDescString = msg; + return; + } + + perfCounter = + _wrapper->clCreatePerfCounterAMD(global_device, &properties[0][0], &err); + CHECK_RESULT(err != CL_SUCCESS, "Create PerfCounter failed\n"); + + // set clock mode + cl_set_device_clock_mode_input_amd setClockModeInput; + setClockModeInput.clock_mode = CL_DEVICE_CLOCK_MODE_PROFILING_AMD; + cl_set_device_clock_mode_output_amd setClockModeOutput = {}; + _wrapper->clSetDeviceClockModeAMD(global_device, setClockModeInput, + &setClockModeOutput); + + _wrapper->clEnqueueBeginPerfCounterAMD(cmd_queue_, 1, &perfCounter, 0, NULL, + NULL); + + for (unsigned int i = 0; i < MAX_ITERATIONS; i++) { + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void *)&inBuffer_[i % num_input_buf_]); + error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), + (void *)&outBuffer_[i % num_output_buf_]); + + error_ = _wrapper->clEnqueueNDRangeKernel( + cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size, + (const size_t *)local_work_size, 0, NULL, NULL); + } + + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueNDRangeKernel failed"); + + _wrapper->clEnqueueEndPerfCounterAMD(cmd_queue_, 1, &perfCounter, 0, NULL, + &perfEvent); + clWaitForEvents(1, &perfEvent); + + // set clock mode to default + setClockModeInput.clock_mode = CL_DEVICE_CLOCK_MODE_DEFAULT_AMD; + _wrapper->clSetDeviceClockModeAMD(global_device, setClockModeInput, + &setClockModeOutput); + + _wrapper->clGetPerfCounterInfoAMD(perfCounter, CL_PERFCOUNTER_DATA, + sizeof(cl_ulong), &result, NULL); + + err = _wrapper->clReleasePerfCounterAMD(perfCounter); + CHECK_RESULT(err != CL_SUCCESS, "Release PerfCounter failed\n"); + + switch (_openTest) { + case 0: + SNPRINTF(buf, sizeof(buf), "SQ Number of Waves: %lu ", (long)result); + break; + case 1: + if (devId >= 9) { + SNPRINTF(buf, sizeof(buf), "Me1 busy for packet decode: %lu ", (long)result); + } else { + SNPRINTF(buf, sizeof(buf), "GRBM CP Busy: %lu ", (long)result); + } + break; + } + + testDescString = buf; + CHECK_RESULT(!(result > 0), "Perf counter value read is zero!\n"); +} + +unsigned int OCLPerfCounters::close(void) { + _wrapper->clFinish(cmd_queue_); + + if (inBuffer_) { + for (int i = 0; i < num_input_buf_; ++i) { + error_ = _wrapper->clReleaseMemObject(inBuffer_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(inBuffer_) failed"); + } + delete[] inBuffer_; + } + if (outBuffer_) { + for (int i = 0; i < num_output_buf_; ++i) { + error_ = _wrapper->clReleaseMemObject(outBuffer_[i]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseMemObject(outBuffer_) failed"); + } + delete[] outBuffer_; + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (cmd_queue_) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queue_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (context_) { + error_ = _wrapper->clReleaseContext(context_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + + return _crcword; +} diff --git a/opencl/tests/ocltst/module/runtime/OCLPerfCounters.h b/opencl/tests/ocltst/module/runtime/OCLPerfCounters.h new file mode 100644 index 0000000000..21b412c9bf --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLPerfCounters.h @@ -0,0 +1,50 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLTestImp.h" + +class OCLPerfCounters : public OCLTestImp { + public: + OCLPerfCounters(); + virtual ~OCLPerfCounters(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + std::string shader_; + bool setData(cl_mem buffer, unsigned int data); + void checkData(cl_mem buffer); + cl_context context_; + cl_command_queue cmd_queue_; + cl_program program_; + cl_kernel kernel_; + cl_mem* inBuffer_; + cl_mem* outBuffer_; + cl_int num_input_buf_; + cl_int num_output_buf_; + cl_int error_; + unsigned int width_; + unsigned int bufSize_; + unsigned int blockSize_; + static const unsigned int MAX_ITERATIONS = 1; + bool isAMD; +}; diff --git a/opencl/tests/ocltst/module/runtime/OCLPersistent.cpp b/opencl/tests/ocltst/module/runtime/OCLPersistent.cpp new file mode 100644 index 0000000000..e3d158330c --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLPersistent.cpp @@ -0,0 +1,139 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPersistent.h" + +#include +#include +#include +#include +#include + +const static char* strKernel = + "__kernel void persistentImage( write_only image2d_t source){ \n" + " int tidX = get_global_id(0);\n" + " int tidY = get_global_id(1);\n" + " write_imagei( source, (int2)( tidX, tidY ),(int4)( tidX, tidY,0,0 ) " + ");\n" + "}\n"; + +OCLPersistent::OCLPersistent() : clImage_(0) { _numSubTests = 1; } + +OCLPersistent::~OCLPersistent() {} + +void OCLPersistent::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + if (_errorFlag) return; + + // Build the kernel + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed!"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed!"); + + kernel_ = _wrapper->clCreateKernel(program_, "persistentImage", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed!"); + cl_image_format format; + format.image_channel_data_type = CL_SIGNED_INT32; + format.image_channel_order = CL_RG; + cl_image_desc desc = {0}; + desc.image_type = CL_MEM_OBJECT_IMAGE2D; + desc.image_width = c_dimSize; + desc.image_height = c_dimSize; + desc.image_depth = 1; + desc.image_array_size = 1; + // CL_MEM_USE_PERSISTENT_MEM_AMD + clImage_ = + clCreateImage(context_, CL_MEM_USE_PERSISTENT_MEM_AMD | CL_MEM_WRITE_ONLY, + &format, &desc, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateImage() failed"); +} + +void OCLPersistent::run(void) { + _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &clImage_); + + size_t dimSizes[] = {c_dimSize, c_dimSize}; + + size_t origin[] = {0, 0, 0}; + size_t region[] = {c_dimSize, c_dimSize, 1}; + size_t pitch, slice; + cl_event event; + error_ = _wrapper->clEnqueueNDRangeKernel( + cmdQueues_[_deviceId], kernel_, 2, NULL, dimSizes, NULL, 0, NULL, NULL); + error_ = _wrapper->clEnqueueMarkerWithWaitList(cmdQueues_[_deviceId], 0, NULL, + &event); + + _wrapper->clFlush(cmdQueues_[_deviceId]); + + cl_uint status; + _wrapper->clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(cl_uint), &status, NULL); + while (status != CL_COMPLETE) { + _wrapper->clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(cl_uint), &status, NULL); + } + + unsigned int* image = (unsigned int*)_wrapper->clEnqueueMapImage( + cmdQueues_[_deviceId], clImage_, CL_TRUE, CL_MAP_READ, origin, region, + &pitch, &slice, 0, NULL, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueMapImage() failed"); + + bool result = validateImage(image, pitch, c_dimSize); + CHECK_RESULT(!result, "Validation failed!"); + + _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], clImage_, image, 0, + NULL, NULL); +} + +unsigned int OCLPersistent::close(void) { + _wrapper->clReleaseMemObject(clImage_); + + return OCLTestImp::close(); +} + +bool OCLPersistent::validateImage(unsigned int* image, size_t pitch, + unsigned int dimSize) { + unsigned int x, y; + int idx = 0; + for (y = 0; y < dimSize; y++) { + for (x = 0; x < dimSize; x++) { + if ((image[idx] != x) || (image[idx + 1] != y)) { + printf("Failed at coordinate (%5d, %5d) - R:%d, G:%d value\n", x, y, + image[idx], image[idx + 1]); + return false; + } + idx += 2; + } + image += pitch / sizeof(int); + idx = 0; + } + return true; +} diff --git a/opencl/tests/ocltst/module/runtime/OCLPersistent.h b/opencl/tests/ocltst/module/runtime/OCLPersistent.h new file mode 100644 index 0000000000..6000fbb123 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLPersistent.h @@ -0,0 +1,50 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PERSISTENT_H_ +#define _OCL_PERSISTENT_H_ + +#include "OCLTestImp.h" + +class OCLPersistent : public OCLTestImp { + public: + OCLPersistent(); + virtual ~OCLPersistent(); + static const unsigned int c_dimSize = 510; + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId); + virtual void run(void); + virtual unsigned int close(void); + + private: + //////////////////// + // test functions // + //////////////////// + + bool validateImage(unsigned int* image, size_t pitch, unsigned int dimSize); + ///////////////////// + // private members // + ///////////////////// + + // CL identifiers + cl_mem clImage_; +}; + +#endif // _OCL_GL_BUFFER_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLPinnedMemory.cpp b/opencl/tests/ocltst/module/runtime/OCLPinnedMemory.cpp new file mode 100644 index 0000000000..cb59c9fbc8 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLPinnedMemory.cpp @@ -0,0 +1,223 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPinnedMemory.h" + +#ifdef _WIN32 +#include +// Pick up from OCLSVM +size_t getTotalSystemMemory(); +#else +#include +size_t getTotalSystemMemory() { + struct sysinfo info; + sysinfo(&info); + return info.totalram; +} +#endif + +#include +#include +#include + +OCLPinnedMemory::OCLPinnedMemory() { _numSubTests = 2; } + +OCLPinnedMemory::~OCLPinnedMemory() {} + +void OCLPinnedMemory::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_ERROR(error_, "Error opening test"); + _openTest = test; + host_memory_ = nullptr; + +#ifdef _WIN32 + // Observed failures on Win7 + if (!IsWindows8OrGreater()) { + printf("Test requires Win10, skipping...\n"); + _openTest = -1; + return; + } +#endif + + cl_int status; + + // Observed failures with Carrizo on GSL path + cl_bool is_apu; + status = clGetDeviceInfo(devices_[deviceId], CL_DEVICE_HOST_UNIFIED_MEMORY, + sizeof(cl_bool), &is_apu, nullptr); + CHECK_ERROR(status, "clGetDeviceInfo failed."); + if (is_apu) { + printf("Test not supported for apus, skipping...\n"); + _openTest = -1; + return; + } + + cl_uint address_bits; + status = clGetDeviceInfo(devices_[deviceId], CL_DEVICE_ADDRESS_BITS, + sizeof(cl_uint), &address_bits, nullptr); + CHECK_ERROR(status, "clGetDeviceInfo failed."); + if (address_bits < 64u) { + printf("GPU VA range size below 4GB, skipping...\n"); + _openTest = -1; + return; + } + + row_size_ = getTotalSystemMemory(); + if (row_size_ <= (1ull << 32u)) { + printf("System memory below 4GB, skipping...\n"); + _openTest = -1; + return; + } + row_size_ *= ratio_; +#if EMU_ENV + if (row_size_ > 5000) { + row_size_ = 5000; + } +#endif + row_size_ = floor(sqrt(row_size_)); + row_size_ = (row_size_ + row_data_size_ - 1) & ~(row_data_size_ - 1); + + pin_size_ = row_size_ * row_size_ / row_data_size_; + host_memory_ = new row_data_t[pin_size_]; +} + +void OCLPinnedMemory::runNoPrepinnedMemory() { + cl_int status; + + row_data_t* tmp = new row_data_t[row_size_]; + std::iota(tmp, tmp + row_size_, 0); + std::fill_n(host_memory_, pin_size_, 0); + + cl_mem tmp_buffer = clCreateBuffer(context_, CL_MEM_USE_HOST_PTR, + row_size_ * row_data_size_, tmp, &status); + CHECK_ERROR(status, "clCreateBuffer failed."); + cl_mem buffer = clCreateBuffer(context_, CL_MEM_READ_WRITE, + row_size_ * row_data_size_, nullptr, &status); + CHECK_ERROR(status, "clCreateBuffer failed."); + + status = clEnqueueCopyBuffer(cmdQueues_[_deviceId], tmp_buffer, buffer, 0, 0, + row_size_ * row_data_size_, 0, nullptr, nullptr); + CHECK_ERROR(status, "clEnqueueCopyBuffer failed."); + clFinish(cmdQueues_[_deviceId]); + + size_t buffer_offset[3] = {0, 0, 0}; + size_t host_offset[3] = {0, 0, 0}; + size_t region[3] = {row_data_size_, row_size_, 1}; + + status = clEnqueueReadBufferRect( + cmdQueues_[_deviceId], buffer, CL_TRUE, buffer_offset, host_offset, + region, 0, 0, row_size_, 0, host_memory_, 0, nullptr, nullptr); + CHECK_ERROR(status, "clEnqueueReadBufferRect failed."); + status = clFinish(cmdQueues_[_deviceId]); + CHECK_ERROR(status, "clFinish failed."); + + for (uint64_t i = 0; i < row_size_; i++) { + if (tmp[i] != host_memory_[i * row_size_ / row_data_size_]) { + status = -1; + break; + } + } + + CHECK_RESULT(status == -1, "Error when reading data."); + + status = clReleaseMemObject(buffer); + CHECK_ERROR(status, "clReleaseMemObject failed."); + status = clReleaseMemObject(tmp_buffer); + CHECK_ERROR(status, "clReleaseMemObject failed."); + delete[] tmp; +} + +void OCLPinnedMemory::runPrepinnedMemory() { + cl_int status; + + row_data_t* tmp = new row_data_t[row_size_]; + std::iota(tmp, tmp + row_size_, 0); + std::fill_n(host_memory_, pin_size_, 0); + + cl_mem tmp_buffer = clCreateBuffer(context_, CL_MEM_USE_HOST_PTR, + row_size_ * row_data_size_, tmp, &status); + CHECK_ERROR(status, "clCreateBuffer failed."); + cl_mem buffer = clCreateBuffer(context_, CL_MEM_READ_WRITE, + row_size_ * row_data_size_, nullptr, &status); + CHECK_ERROR(status, "clCreateBuffer failed."); + + status = clEnqueueCopyBuffer(cmdQueues_[_deviceId], tmp_buffer, buffer, 0, 0, + row_size_ * row_data_size_, 0, nullptr, nullptr); + CHECK_ERROR(status, "clEnqueueCopyBuffer failed."); + + cl_mem pinned_buffer = + clCreateBuffer(context_, CL_MEM_USE_HOST_PTR, pin_size_ * row_data_size_, + host_memory_, &status); + CHECK_ERROR(status, "clCreateBuffer failed."); + + clEnqueueMapBuffer(cmdQueues_[_deviceId], pinned_buffer, CL_TRUE, + CL_MAP_READ | CL_MAP_WRITE, 0, pin_size_ * row_data_size_, + 0, nullptr, nullptr, &status); + CHECK_ERROR(status, "clEnqueueMapBuffer failed."); + + size_t buffer_offset[3] = {0, 0, 0}; + size_t host_offset[3] = {0, 0, 0}; + size_t region[3] = {row_data_size_, row_size_, 1}; + + status = clEnqueueReadBufferRect( + cmdQueues_[_deviceId], buffer, CL_TRUE, buffer_offset, host_offset, + region, 0, 0, row_size_, 0, host_memory_, 0, nullptr, nullptr); + CHECK_ERROR(status, "clEnqueueReadBufferRect failed."); + + for (uint64_t i = 0; i < row_size_; i++) { + if (tmp[i] != host_memory_[i * row_size_ / row_data_size_]) { + status = -1; + break; + } + } + + CHECK_RESULT(status == -1, "Error when reading data."); + + status = clEnqueueUnmapMemObject(cmdQueues_[_deviceId], pinned_buffer, + host_memory_, 0, nullptr, nullptr); + CHECK_ERROR(status, "clEnqueueUnmap failed.") + status = clFinish(cmdQueues_[_deviceId]); + CHECK_ERROR(status, "clFinish failed."); + + status = clReleaseMemObject(pinned_buffer); + CHECK_ERROR(status, "clReleaseMemObject failed."); + status = clReleaseMemObject(buffer); + CHECK_ERROR(status, "clReleaseMemObject failed."); + status = clReleaseMemObject(tmp_buffer); + CHECK_ERROR(status, "clReleaseMemObject failed."); + delete[] tmp; +} + +void OCLPinnedMemory::run() { + switch (_openTest) { + case 0: + runNoPrepinnedMemory(); + break; + case 1: + runPrepinnedMemory(); + break; + } +} + +unsigned int OCLPinnedMemory::close() { + delete[] host_memory_; + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/runtime/OCLPinnedMemory.h b/opencl/tests/ocltst/module/runtime/OCLPinnedMemory.h new file mode 100644 index 0000000000..c35c604c2f --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLPinnedMemory.h @@ -0,0 +1,51 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PINNED_MEMORY_H_ +#define _OCL_PINNED_MEMORY_H_ + +#include + +#include "OCLTestImp.h" + +class OCLPinnedMemory : public OCLTestImp { + public: + OCLPinnedMemory(); + ~OCLPinnedMemory(); + + void open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) override; + void run() override; + unsigned int close() override; + + private: + void runNoPrepinnedMemory(); + void runPrepinnedMemory(); + + static constexpr const float ratio_ = 0.4f; + using row_data_t = uint64_t; + + row_data_t* host_memory_; + size_t row_data_size_ = sizeof(row_data_t); + size_t row_size_; + size_t pin_size_; +}; + +#endif // _OCL_PINNED_MEMORY_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLPlatformAtomics.cpp b/opencl/tests/ocltst/module/runtime/OCLPlatformAtomics.cpp new file mode 100644 index 0000000000..75d3c7e126 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLPlatformAtomics.cpp @@ -0,0 +1,182 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLPlatformAtomics.h" + +#include +#include +#include + +#include "CL/cl.h" + +const static char* strKernel = + "__kernel void test_atomic_kernel(volatile __global atomic_int *pSync, " + "volatile __global atomic_int *ptr, int numIterations)\n" + "{ " + " \n" + " while(atomic_load_explicit(pSync, memory_order_acquire, " + "memory_scope_all_svm_devices) == 0); \n" + " for (int i = 0; i < numIterations; i++) { " + " \n" + " atomic_fetch_add_explicit(ptr, 1, memory_order_acq_rel, " + "memory_scope_all_svm_devices); \n" + " } " + " \n" + "} " + " \n"; + +OCLPlatformAtomics::OCLPlatformAtomics() { + _numSubTests = 1; + failed_ = false; + svmCaps_ = 0; +} + +OCLPlatformAtomics::~OCLPlatformAtomics() {} + +void OCLPlatformAtomics::open(unsigned int test, char* units, + double& conversion, unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + size_t param_size = 0; + char* strVersion = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 0, + 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[7] < '2') { + failed_ = true; + return; + } + delete strVersion; + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "test_atomic_kernel", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); +} + +static int AtomicLoad(volatile cl_int* object) { +#if defined(_MSC_VER) || defined(__INTEL_COMPILER) + return InterlockedExchangeAdd((volatile long*)object, 0); +#elif defined(__GNUC__) + return __sync_add_and_fetch(object, 0); +#else + printf("Atomic load not supported, aborting..."); + return 0; +#endif +} + +static int AtomicIncrement(volatile cl_int* object) { +#if defined(_MSC_VER) || defined(__INTEL_COMPILER) + return _InterlockedIncrement((volatile long*)object); +#elif defined(__GNUC__) + return __sync_fetch_and_add(object, 1); +#endif + printf("Atomic increment not supported, aborting..."); + return 0; +} + +void OCLPlatformAtomics::run(void) { + if (failed_) return; + +#ifdef CL_VERSION_2_0 + error_ = + _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_SVM_CAPABILITIES, + sizeof(svmCaps_), &svmCaps_, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetDeviceInfo() failed"); + + if (!(svmCaps_ & CL_DEVICE_SVM_ATOMICS)) { + printf("SVM atomics not supported, skipping test...\n"); + return; + } + + volatile cl_int* pSyncBuf = (volatile cl_int*)_wrapper->clSVMAlloc( + context_, CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS, + sizeof(cl_int), 0); + CHECK_RESULT(!pSyncBuf, "clSVMAlloc() failed"); + *pSyncBuf = 0; + + volatile cl_int* pAtomicBuf = (volatile cl_int*)_wrapper->clSVMAlloc( + context_, CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS, + sizeof(cl_int), 0); + CHECK_RESULT(!pAtomicBuf, "clSVMAlloc() failed"); + *pAtomicBuf = 0; + + error_ = + _wrapper->clSetKernelArgSVMPointer(kernel_, 0, (const void*)pSyncBuf); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArgSVMPointer() failed"); + + error_ = + _wrapper->clSetKernelArgSVMPointer(kernel_, 1, (const void*)pAtomicBuf); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArgSVMPointer() failed"); + + cl_int numIterations = 0x100000; + error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_int), &numIterations); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t globalWorkSize[1] = {1}; + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, NULL, + globalWorkSize, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + clFlush(cmdQueues_[_deviceId]); + + AtomicIncrement(pSyncBuf); + + // wait until we see some activity from a device (try to run host side + // simultaneously). + while (AtomicLoad(pAtomicBuf /*, memory_order_relaxed*/) == 0) + ; + + for (int i = 0; i < numIterations; i++) { + AtomicIncrement(pAtomicBuf); + } + + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + CHECK_ERROR(error_, "clFinish() failed"); + + int expected = numIterations * 2; + CHECK_RESULT(*pAtomicBuf != expected, "Expected: 0x%x, found: 0x%x", expected, + *pAtomicBuf); + + _wrapper->clSVMFree(context_, (void*)pSyncBuf); + _wrapper->clSVMFree(context_, (void*)pAtomicBuf); +#endif +} + +unsigned int OCLPlatformAtomics::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLPlatformAtomics.h b/opencl/tests/ocltst/module/runtime/OCLPlatformAtomics.h new file mode 100644 index 0000000000..c5e32a39e3 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLPlatformAtomics.h @@ -0,0 +1,41 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_PLATFORM_ATOMICS_H_ +#define _OCL_PLATFORM_ATOMICS_H_ + +#include "OCLTestImp.h" + +class OCLPlatformAtomics : public OCLTestImp { + public: + OCLPlatformAtomics(); + virtual ~OCLPlatformAtomics(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + bool failed_; + unsigned long long svmCaps_; +}; + +#endif // _OCL_KERNEL_BINARY_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLProgramScopeVariables.cpp b/opencl/tests/ocltst/module/runtime/OCLProgramScopeVariables.cpp new file mode 100644 index 0000000000..f7b685dc59 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLProgramScopeVariables.cpp @@ -0,0 +1,274 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLProgramScopeVariables.h" + +#include "CL/cl.h" + +OCLProgramScopeVariables::OCLProgramScopeVariables() { _numSubTests = 3; } + +OCLProgramScopeVariables::~OCLProgramScopeVariables() {} + +void OCLProgramScopeVariables::open(unsigned int test, char* units, + double& conversion, unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "error_ opening test"); + silentFailure = false; + _openTest = test; + size_t param_size = 0; + program_ = 0; + kernel1_ = kernel2_ = 0; + char* strVersion = 0; + error_ = _wrapper->clGetDeviceInfo( + devices_[_deviceId], CL_DEVICE_OPENCL_C_VERSION, 0, 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + strVersion = (char*)malloc(param_size); + error_ = + _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_OPENCL_C_VERSION, + param_size, strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformInfo failed"); + if (strVersion[9] < '2') { + printf("\nOpenCL C 2.0 not supported\n"); + silentFailure = true; + } + free(strVersion); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLProgramScopeVariables::run(void) { + if (silentFailure) return; + switch (_openTest) { + case 0: + test0(); + break; + case 1: + test1(); + break; + case 2: + test2(); + break; + } + return; +} + +void OCLProgramScopeVariables::test0(void) { + const char* kernel_str = + "global int g[1000] = {0}; \n\ + __kernel void test1 (global unsigned int * A) \n\ + { \n\ + int id = get_global_id(0); \n\ + g[id] = id; \n\ + } \n\ + __kernel void test2 (global unsigned int * A) \n\ + { \n\ + int id = get_global_id(0); \n\ + A[id] = g[id]; \n\ + } \n"; + const size_t arrSize = 1000; + cl_uint* output_arr = (cl_uint*)malloc(arrSize * sizeof(cl_uint)); + cl_mem buffer = _wrapper->clCreateBuffer( + context_, CL_MEM_READ_WRITE, arrSize * sizeof(cl_uint), 0, &error_); + buffers_.push_back(buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &kernel_str, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char log[400]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 400, log, 0); + printf("\n\n%s\n\n", log); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram failed"); + kernel1_ = _wrapper->clCreateKernel(program_, "test1", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel1 failed"); + kernel2_ = _wrapper->clCreateKernel(program_, "test2", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel2 failed"); + error_ = _wrapper->clSetKernelArg(kernel1_, 0, sizeof(cl_mem), + (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + error_ = _wrapper->clSetKernelArg(kernel2_, 0, sizeof(cl_mem), + (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + cl_event evt; + size_t global_work_size = arrSize; + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel1_, 1, NULL, + &global_work_size, NULL, 0, NULL, &evt); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel2_, 1, NULL, + &global_work_size, NULL, 0, NULL, &evt); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers_[0], + CL_TRUE, 0, sizeof(cl_uint) * arrSize, + output_arr, 1, &evt, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed"); + bool bResult = true; + for (unsigned int i = 0; i < arrSize; ++i) { + if (output_arr[i] != i) { + bResult = false; + break; + } + } + free(output_arr); + CHECK_RESULT((bResult == false), "Program Scope Variables - test0 failed"); +} + +void OCLProgramScopeVariables::test1(void) { + const char* kernel_str = + "global int temp = 0; \n\ + __kernel void test1 (global unsigned int * A) \n\ + { \n\ + int id = get_global_id(0); \n\ + if (id == 0) temp = 55; \n\ + } \n\ + __kernel void test2 (global unsigned int * A) \n\ + { \n\ + int id = get_global_id(0); \n\ + if (id == 0) A[0] = temp; \n\ + } \n"; + cl_uint* output_arr = (cl_uint*)malloc(sizeof(cl_uint)); + cl_mem buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + sizeof(cl_uint), 0, &error_); + buffers_.push_back(buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &kernel_str, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char log[400]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 400, log, 0); + printf("\n\n%s\n\n", log); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram failed"); + kernel1_ = _wrapper->clCreateKernel(program_, "test1", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel1 failed"); + kernel2_ = _wrapper->clCreateKernel(program_, "test2", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel2 failed"); + error_ = _wrapper->clSetKernelArg(kernel1_, 0, sizeof(cl_mem), + (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + error_ = _wrapper->clSetKernelArg(kernel2_, 0, sizeof(cl_mem), + (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + cl_event evt; + size_t global_work_size = 1; + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel1_, 1, NULL, + &global_work_size, NULL, 0, NULL, &evt); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel2_, 1, NULL, + &global_work_size, NULL, 0, NULL, &evt); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers_[0], + CL_TRUE, 0, sizeof(cl_uint), + output_arr, 1, &evt, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed"); + bool bResult = (output_arr[0] == 55); + free(output_arr); + CHECK_RESULT((bResult == false), "Program Scope Variables - test1 failed"); +} + +void OCLProgramScopeVariables::test2(void) { + const char* kernel_str = + "global int temp = 0; \n\ + global int* ptr[] = {&temp}; \n\ + __kernel void test1 (global unsigned int * A) \n\ + { \n\ + int id = get_global_id(0); \n\ + if (id == 0) temp = 65; \n\ + } \n\ + __kernel void test2 (global unsigned int * A) \n\ + { \n\ + int id = get_global_id(0); \n\ + if (id == 0) A[0] = *ptr[0]; \n\ + } \n"; + cl_uint* output_arr = (cl_uint*)malloc(sizeof(cl_uint)); + cl_mem buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + sizeof(cl_uint), 0, &error_); + buffers_.push_back(buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &kernel_str, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource failed"); + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], + "-cl-std=CL2.0", NULL, NULL); + if (error_ != CL_SUCCESS) { + char log[400]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 400, log, 0); + printf("\n\n%s\n\n", log); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram failed"); + kernel1_ = _wrapper->clCreateKernel(program_, "test1", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel1 failed"); + kernel2_ = _wrapper->clCreateKernel(program_, "test2", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel2 failed"); + error_ = _wrapper->clSetKernelArg(kernel1_, 0, sizeof(cl_mem), + (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + error_ = _wrapper->clSetKernelArg(kernel2_, 0, sizeof(cl_mem), + (void*)&buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed"); + cl_event evt; + size_t global_work_size = 1; + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel1_, 1, NULL, + &global_work_size, NULL, 0, NULL, &evt); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel2_, 1, NULL, + &global_work_size, NULL, 0, NULL, &evt); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel"); + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers_[0], + CL_TRUE, 0, sizeof(cl_uint), + output_arr, 1, &evt, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer failed"); + bool bResult = (output_arr[0] == 65); + free(output_arr); + CHECK_RESULT((bResult == false), "Program Scope Variables - test2 failed"); +} + +unsigned int OCLProgramScopeVariables::close(void) { + if (kernel1_) { + error_ = _wrapper->clReleaseKernel(kernel1_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel1 failed"); + kernel1_ = 0; + } + if (kernel2_) { + error_ = _wrapper->clReleaseKernel(kernel2_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel2 failed"); + kernel2_ = 0; + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/runtime/OCLProgramScopeVariables.h b/opencl/tests/ocltst/module/runtime/OCLProgramScopeVariables.h new file mode 100644 index 0000000000..738a6ea0f7 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLProgramScopeVariables.h @@ -0,0 +1,46 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_ProgramScopeVariables_H_ +#define _OCL_ProgramScopeVariables_H_ + +#include "OCLTestImp.h" + +class OCLProgramScopeVariables : public OCLTestImp { + public: + OCLProgramScopeVariables(); + virtual ~OCLProgramScopeVariables(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + void test0(void); + void test1(void); + void test2(void); + bool silentFailure; + cl_kernel kernel1_; + cl_kernel kernel2_; +}; + +#endif // _OCL_ProgramScopeVariables_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLRTQueue.cpp b/opencl/tests/ocltst/module/runtime/OCLRTQueue.cpp new file mode 100644 index 0000000000..538db830cb --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLRTQueue.cpp @@ -0,0 +1,439 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLRTQueue.h" + +#include +#include +#include +#include + +#include "CL/cl.h" + +static const size_t Iterations = 0x100; +static const size_t IterationDivider = 2; +static const size_t MaxBuffers = IterationDivider; +static const size_t BufSize = 0x800000; + +const static char* strKernel = + "__kernel void factorial(__global uint* out) \n" + "{ \n" + " uint id = get_global_id(0); \n" + " uint factorial = 1; \n" + " for (uint i = 1; i < (id / 0x400); ++i) \n" + " { \n" + " factorial *= i; \n" + " } \n" + " out[id] = factorial; \n" + "} \n"; + +OCLRTQueue::OCLRTQueue(): rtQueue_(NULL), rtQueue1_(NULL), kernel2_(NULL) { +#ifndef CL_VERSION_2_0 + _numSubTests = 0; + testID_ = 0; + failed_ = false; +#else + _numSubTests = 2; + testID_ = 0; + failed_ = false; +#endif +} + +OCLRTQueue::~OCLRTQueue() {} + +void OCLRTQueue::open(unsigned int test, char* units, double& conversion, unsigned int deviceId) { +#ifdef CL_VERSION_2_0 + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + testID_ = test; + size_t param_size = 0; + char* strVersion = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 0, + 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strVersion = new char[param_size]; + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, param_size, + strVersion, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strVersion[7] < '2') { + failed_ = true; + return; + } + cl_uint rtQueues; +#define CL_DEVICE_MAX_REAL_TIME_COMPUTE_QUEUES_AMD 0x404D +#define CL_DEVICE_MAX_REAL_TIME_COMPUTE_UNITS_AMD 0x404E +#define CL_DEVICE_MAX_REAL_TIME_COMPUTE_UNITS_GRANULARITY_AMD 0x403A + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_MAX_REAL_TIME_COMPUTE_QUEUES_AMD, + sizeof(rtQueues), &rtQueues, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (rtQueues < 2) { + failed_ = true; + return; + } + + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_MAX_REAL_TIME_COMPUTE_UNITS_AMD, + sizeof(rtCUs_), &rtCUs_, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_MAX_COMPUTE_UNITS, + sizeof(maxCUs_), &maxCUs_, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], + CL_DEVICE_MAX_REAL_TIME_COMPUTE_UNITS_GRANULARITY_AMD, + sizeof(rtCUsGranularity_), &rtCUsGranularity_, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "factorial", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + for (size_t i = 0; i < MaxBuffers; ++i) { + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + BufSize * sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + } + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_ALLOC_HOST_PTR, + BufSize * sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); +#endif +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLRTQueue::run(void) { +#ifdef CL_VERSION_2_0 + if (failed_) { + return; + } + + void* values; + CPerfCounter timer; + cl_mem mapBuffer = buffers()[MaxBuffers]; + + values = _wrapper->clEnqueueMapBuffer(cmdQueues_[_deviceId], mapBuffer, true, + (CL_MAP_READ | CL_MAP_WRITE), 0, BufSize * sizeof(cl_uint), 0, NULL, NULL, &error_); + + cl_mem buffer = buffers()[0]; + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + // SubTest: 1 + size_t gws[1] = {BufSize}; + size_t x; + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(cmdQueues_[_deviceId]); + + timer.Reset(); + timer.Start(); + for (x = 0; x < 1; x++) { + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + + timer.Stop(); + + double sec = timer.GetElapsedTime(); + // Buffer read bandwidth in GB/s + double perf = ((double)BufSize * sizeof(cl_uint) * x * (double)(1e-09)) / sec; + + printf("\n Generic Queue(CUs: %d) Time: %.3fs\n", maxCUs_, sec); + + // SubTest: 2 + bool test_rtq1 = true; + if (testID_ == 0) { + cu_ = rtCUs_ >> 1; + } else { + cu_ = rtCUs_; + test_rtq1 = false; + } + if (cu_ == 0) { + cu_ = rtCUs_; + test_rtq1 = false; + } + + if (cu_ < rtCUsGranularity_) { + printf("The num of CUs is less than granularity, skipping...\n"); + return; + } + + // Create a real time queue +#define CL_QUEUE_REAL_TIME_COMPUTE_UNITS_AMD 0x404f + const cl_queue_properties cprops[] = { + CL_QUEUE_PROPERTIES, static_cast(0), + CL_QUEUE_REAL_TIME_COMPUTE_UNITS_AMD, cu_, 0}; + rtQueue_ = _wrapper->clCreateCommandQueueWithProperties( + context_, devices_[_deviceId], cprops, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueueWithProperties() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(rtQueue_, kernel_, 1, NULL, gws, + NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(rtQueue_); + + timer.Reset(); + timer.Start(); + for (x = 0; x < 1; x++) { + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(rtQueue_, kernel_, 1, NULL, gws, + NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFinish(rtQueue_); + + timer.Stop(); + + sec = timer.GetElapsedTime(); + // Buffer read bandwidth in GB/s + perf = ((double)BufSize * sizeof(cl_uint) * x * (double)(1e-09)) / sec; + + printf(" RT Queue0 (CUs: %2d) Time: %.3fs\n", cu_, sec); + + rtQueue1_ = nullptr; + if (test_rtq1) { +#define CL_QUEUE_MEDIUM_PRIORITY_AMD 0x4050 + const cl_queue_properties cprops2[] = {CL_QUEUE_PROPERTIES, + static_cast(0), + CL_QUEUE_MEDIUM_PRIORITY_AMD, cu_, 0}; + rtQueue1_ = _wrapper->clCreateCommandQueueWithProperties( + context_, devices_[_deviceId], cprops2, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueueWithProperties() failed"); + } + if (rtQueue1_) { + error_ = _wrapper->clEnqueueNDRangeKernel(rtQueue1_, kernel_, 1, NULL, gws, + NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + _wrapper->clFinish(rtQueue1_); + + timer.Reset(); + timer.Start(); + for (x = 0; x < 1; x++) { + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(rtQueue1_, kernel_, 1, NULL, gws, + NULL, 0, NULL, NULL); + + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFinish(rtQueue1_); + + timer.Stop(); + + sec = timer.GetElapsedTime(); + // Buffer read bandwidth in GB/s + perf = ((double)BufSize * sizeof(cl_uint) * x * (double)(1e-09)) / sec; + + printf(" RT Queue1 (CUs: %2d) Time: %.3fs\n", cu_, sec); + } else { + if (testID_ == 0) { + printf(" RT Queue1 test was skipped. Not enough CUs - %2d)", cu_); + } + } + + // SubTest: 3 + timer.Reset(); + timer.Start(); + for (x = 0; x < 1; x++) { + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFinish(cmdQueues_[_deviceId]); + + timer.Stop(); + + sec = timer.GetElapsedTime(); + // Buffer read bandwidth in GB/s + perf = ((double)BufSize * sizeof(cl_uint) * x * (double)(1e-09)) / sec; + + printf(" Generic Queue(CUs: %d) Time: %.3fs\n", maxCUs_ - rtCUs_, sec); + + // SubTest: 4 + for (x = 0; x < Iterations / 10; x++) { + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFlush(cmdQueues_[_deviceId]); + timer.Reset(); + timer.Start(); + for (x = 0; x < 1; x++) { + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(rtQueue_, kernel_, 1, NULL, gws, + NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFinish(rtQueue_); + + timer.Stop(); + _wrapper->clFinish(cmdQueues_[_deviceId]); + + sec = timer.GetElapsedTime(); + // Buffer read bandwidth in GB/s + perf = ((double)BufSize * sizeof(cl_uint) * x * (double)(1e-09)) / sec; + + printf(" Async RT0(CUs: %d) + Generic(CUs: %d) Time: %.3fs\n", cu_, maxCUs_ - rtCUs_, sec); + + // SubTest: 5 + if (rtQueue1_) { + for (x = 0; x < Iterations / 10; x++) { + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFlush(cmdQueues_[_deviceId]); + timer.Reset(); + timer.Start(); + for (x = 0; x < 1; x++) { + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(rtQueue1_, kernel_, 1, NULL, gws, + NULL, 0, NULL, NULL); + + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFinish(rtQueue1_); + + timer.Stop(); + _wrapper->clFinish(cmdQueues_[_deviceId]); + + sec = timer.GetElapsedTime(); + // Buffer read bandwidth in GB/s + perf = ((double)BufSize * sizeof(cl_uint) * x * (double)(1e-09)) / sec; + + printf(" Async RT1(CUs: %d) + Generic(CUs: %d) Time: %.3fs\n", cu_, maxCUs_ - rtCUs_, sec); + } else { + if (testID_ == 0) { + printf(" RT Queue1 test was skipped. Not enough CUs - %2d)", cu_); + } + } + // SubTest: 6 + if (rtQueue1_) { + for (x = 0; x < Iterations / 10; x++) { + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFlush(cmdQueues_[_deviceId]); + timer.Reset(); + timer.Start(); + for (x = 0; x < 1; x++) { + error_ = _wrapper->clEnqueueNDRangeKernel(rtQueue_, kernel_, 1, NULL, gws, + NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + _wrapper->clFlush(rtQueue_); + for (x = 0; x < 1; x++) { + error_ = _wrapper->clEnqueueNDRangeKernel(rtQueue1_, kernel_, 1, NULL, gws, + NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + } + + _wrapper->clFlush(rtQueue1_); + _wrapper->clFinish(rtQueue_); + _wrapper->clFinish(rtQueue1_); + timer.Stop(); + _wrapper->clFlush(cmdQueues_[_deviceId]); + + sec = timer.GetElapsedTime(); + // Buffer read bandwidth in GB/s + perf = ((double)BufSize * sizeof(cl_uint) * x * (double)(1e-09)) / sec; + + printf(" Async RT0(CUs: %d) + RT1(CUs: %d) + Generic(CUs: %d) Time: %.3fs\n", + cu_, cu_, maxCUs_ - rtCUs_, sec); + error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], mapBuffer, + values, 0, NULL, NULL); + _wrapper->clFinish(cmdQueues_[_deviceId]); + } else { + if (testID_ == 0) { + printf(" RT Queue1 test was skipped. Not enough CUs - %2d)", cu_); + } + } +#endif +} + +unsigned int OCLRTQueue::close(void) { +#ifdef CL_VERSION_2_0 + if (NULL != rtQueue_) { + _wrapper->clReleaseCommandQueue(rtQueue_); + } + if (NULL != rtQueue1_) { + _wrapper->clReleaseCommandQueue(rtQueue1_); + } + if (NULL != kernel2_) { + _wrapper->clReleaseKernel(kernel2_); + } + + return OCLTestImp::close(); +#else + return CL_SUCCESS; +#endif +} diff --git a/opencl/tests/ocltst/module/runtime/OCLRTQueue.h b/opencl/tests/ocltst/module/runtime/OCLRTQueue.h new file mode 100644 index 0000000000..ee4988c676 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLRTQueue.h @@ -0,0 +1,49 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_RT_QUEUE_H_ +#define _OCL_RT_QUEUE_H_ + +#include "OCLTestImp.h" + +class OCLRTQueue : public OCLTestImp { + public: + OCLRTQueue(); + virtual ~OCLRTQueue(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + cl_command_queue rtQueue_; + cl_command_queue rtQueue1_; + cl_kernel kernel2_; + unsigned int testID_; + bool failed_; + cl_uint cu_; + cl_uint maxCUs_; + cl_uint rtCUs_; + cl_uint rtCUsGranularity_; +}; + +#endif // _OCL_RT_QUEUE_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLReadWriteImage.cpp b/opencl/tests/ocltst/module/runtime/OCLReadWriteImage.cpp new file mode 100644 index 0000000000..60f63e35e4 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLReadWriteImage.cpp @@ -0,0 +1,369 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLReadWriteImage.h" + +#include +#include +#include + +#include +#ifdef __linux__ +#include +#include +#endif + +#include "CL/cl.h" + +const static size_t imageSize = 4; +const static size_t MaxSubTests = 4; + +static const char *rgba8888_kernel_read = + "\n" + "__kernel void read_rgba8888(read_only image2d_t srcimg, __global uchar4 " + "*dst, sampler_t sampler)\n" + "{\n" + " int tid_x = get_global_id(0);\n" + " int tid_y = get_global_id(1);\n" + " int indx = tid_y * get_image_width(srcimg) + tid_x;\n" + " float4 color;\n" + "\n" + " color = read_imagef(srcimg, sampler, (int2)(tid_x, tid_y)) * 255.0f;\n" + " dst[indx] = convert_uchar4_rte(color);\n" + "\n" + "}\n"; + +static const char *rgba8888_kernel_write = + "\n" + "__kernel void write_rgba8888(__global unsigned char *src, write_only " + "image2d_t dstimg)\n" + "{\n" + " int tid_x = get_global_id(0);\n" + " int tid_y = get_global_id(1);\n" + " int indx = tid_y * get_image_width(dstimg) + tid_x;\n" + " float4 color;\n" + "\n" + " indx *= 4;\n" + " color = (float4)((float)src[indx+0], (float)src[indx+1], " + "(float)src[indx+2], (float)src[indx+3]);\n" + " color /= (float4)(255.0f, 255.0f, 255.0f, 255.0f);\n" + " write_imagef(dstimg, (int2)(tid_x, tid_y), color);\n" + "\n" + "}\n"; + +OCLReadWriteImage::OCLReadWriteImage() { + _numSubTests = MaxSubTests; + done_ = false; + imageWidth = imageSize; + imageHeight = imageSize; + imageDepth = imageSize; +} + +OCLReadWriteImage::~OCLReadWriteImage() {} + +bool OCLReadWriteImage::verifyImageData(unsigned char *inputImageData, + unsigned char *output, size_t width, + size_t height) { + for (unsigned int i = 0; i < 4 * width * height; i++) { + if (output[i] != inputImageData[i]) { + printf( + "Verification failed at byte %u in the output image => %x != %x " + "[reference]\n", + i, output[i], inputImageData[i]); + return false; + } + } + return true; +} +void OCLReadWriteImage::open(unsigned int test, char *units, double &conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + testID_ = test; + + cl_bool imageSupport; + size_t size; + for (size_t i = 0; i < deviceCount_; ++i) { + _wrapper->clGetDeviceInfo(devices_[i], CL_DEVICE_IMAGE_SUPPORT, + sizeof(imageSupport), &imageSupport, &size); + if (!imageSupport) { + testDescString = "Image not supported, skipping this test! "; + done_ = true; + return; + } + } + + if (test == 1) { + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, &rgba8888_kernel_read, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, + 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "read_rgba8888", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + } else if ((test == 2) || (test == 3)) { + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, &rgba8888_kernel_write, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, + 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "write_rgba8888", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + } + + cl_mem memory; + cl_image_format imgageFormat; + imgageFormat.image_channel_order = CL_RGBA; + imgageFormat.image_channel_data_type = CL_UNORM_INT8; + bufferSize = imageWidth * imageHeight * 4 * sizeof(unsigned char); + + memory = _wrapper->clCreateImage2D(context_, CL_MEM_READ_WRITE, &imgageFormat, + imageWidth, imageHeight, 0, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateImage() failed"); + + buffers_.push_back(memory); + + if ((test == 1) || (test == 2) || (test == 3)) { + memory = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, bufferSize, + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(memory); + } +} + +static void CL_CALLBACK notify_callback(const char *errinfo, + const void *private_info, size_t cb, + void *user_data) {} + +void OCLReadWriteImage::run(void) { + if (done_) { + return; + } + + const unsigned int inputImageData[imageSize][imageSize] = { + {0xc0752fac, 0x67c3fb43, 0xf215d309, 0xd8465724}, + {0xc13a8c58, 0xae5727e6, 0x19a55158, 0x9409484d}, + {0xc5f3d073, 0xc0af4ffe, 0xb1d86352, 0x93931df3}, + {0xc120a78e, 0x207fb909, 0x97f4ca1f, 0x72cbfea3}}; + + unsigned char *outputPtr = (unsigned char *)malloc(bufferSize); + + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {imageWidth, imageHeight, 1}; + bool validation; + size_t threads[2]; + + switch (testID_) { + case 0: // ImageWrite (w/ sDMA) and ImageRead (w/ sDMA) + error_ = _wrapper->clEnqueueWriteImage(cmdQueues_[_deviceId], buffers_[0], + true, origin, region, 0, 0, + inputImageData, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteImage() failed"); + + error_ = _wrapper->clEnqueueReadImage(cmdQueues_[_deviceId], buffers_[0], + true, origin, region, 0, 0, + outputPtr, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadImage() failed"); + + validation = verifyImageData((unsigned char *)&inputImageData, outputPtr, + imageWidth, imageHeight); + if (validation) { + printf("ImageWrite (w/ sDMA) -> ImageRead (w/ sDMA) passed!\n"); + } else { + CHECK_RESULT(true, + "ImageWrite (w/ sDMA) -> ImageRead (w/ sDMA) failed!\n"); + } + break; + case 1: // ImageWrite (w/ sDMA) and ImageRead (w/ kernel) + error_ = _wrapper->clEnqueueWriteImage(cmdQueues_[_deviceId], buffers_[0], + true, origin, region, 0, 0, + inputImageData, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteImage() failed"); + + cl_sampler sampler; + sampler = _wrapper->clCreateSampler(context_, CL_FALSE, + CL_ADDRESS_CLAMP_TO_EDGE, + CL_FILTER_NEAREST, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateSampler failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof buffers_[0], + &buffers_[0]); + error_ |= clSetKernelArg(kernel_, 1, sizeof buffers_[1], &buffers_[1]); + error_ |= clSetKernelArg(kernel_, 2, sizeof sampler, &sampler); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed\n"); + + threads[0] = (unsigned int)imageWidth; + threads[1] = (unsigned int)imageHeight; + + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 2, + NULL, threads, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers_[1], + CL_TRUE, 0, bufferSize, outputPtr, + 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + + validation = verifyImageData((unsigned char *)&inputImageData, outputPtr, + imageWidth, imageHeight); + if (validation) { + printf("ImageWrite (w/ sDMA) -> ImageRead (w/ kernel) passed!\n"); + } else { + CHECK_RESULT(true, + "ImageWrite (w/ sDMA) -> ImageRead (w/ kernel) failed!\n"); + } + + break; + case 2: // ImageWrite (w/ kernel) and ImageRead (w/ sDMA) + error_ = _wrapper->clEnqueueWriteBuffer( + cmdQueues_[_deviceId], buffers_[1], CL_TRUE, 0, bufferSize, + inputImageData, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof buffers_[1], + &buffers_[1]); + error_ |= clSetKernelArg(kernel_, 1, sizeof buffers_[0], &buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed\n"); + + threads[0] = (unsigned int)imageWidth; + threads[1] = (unsigned int)imageHeight; + + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 2, + NULL, threads, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + error_ = _wrapper->clEnqueueReadImage(cmdQueues_[_deviceId], buffers_[0], + true, origin, region, 0, 0, + outputPtr, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadImage() failed"); + + validation = verifyImageData((unsigned char *)&inputImageData, outputPtr, + imageWidth, imageHeight); + if (validation) { + printf("ImageWrite (w/ kernel) -> ImageRead (w/ sDMA) passed!\n"); + } else { + CHECK_RESULT(true, + "ImageWrite (w/ kernel) -> ImageRead (w/ sDMA) failed!\n"); + } + break; + case 3: // ImageWrite (w/ kernel) and ImageRead (w/ kernel) + error_ = _wrapper->clEnqueueWriteBuffer( + cmdQueues_[_deviceId], buffers_[1], CL_TRUE, 0, bufferSize, + inputImageData, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof buffers_[1], + &buffers_[1]); + error_ |= clSetKernelArg(kernel_, 1, sizeof buffers_[0], &buffers_[0]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed\n"); + + threads[0] = (unsigned int)imageWidth; + threads[1] = (unsigned int)imageHeight; + + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 2, + NULL, threads, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + // recreate the program_ to use the read kernel + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, &rgba8888_kernel_read, NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), + "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[_deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[_deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, + 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "read_rgba8888", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + sampler = _wrapper->clCreateSampler(context_, CL_FALSE, + CL_ADDRESS_CLAMP_TO_EDGE, + CL_FILTER_NEAREST, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateSampler failed"); + + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof buffers_[0], + &buffers_[0]); + error_ |= clSetKernelArg(kernel_, 1, sizeof buffers_[1], &buffers_[1]); + error_ |= clSetKernelArg(kernel_, 2, sizeof sampler, &sampler); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg failed\n"); + + threads[0] = (unsigned int)imageWidth; + threads[1] = (unsigned int)imageHeight; + + error_ = + _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 2, + NULL, threads, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers_[1], + CL_TRUE, 0, bufferSize, outputPtr, + 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + + validation = verifyImageData((unsigned char *)&inputImageData, outputPtr, + imageWidth, imageHeight); + if (validation) { + printf("ImageWrite (w/ kernel) -> ImageRead (w/ kernel) passed!\n"); + } else { + CHECK_RESULT( + true, "ImageWrite (w/ kernel) -> ImageRead (w/ kernel) failed!\n"); + } + + break; + } + + free(outputPtr); +} + +unsigned int OCLReadWriteImage::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLReadWriteImage.h b/opencl/tests/ocltst/module/runtime/OCLReadWriteImage.h new file mode 100644 index 0000000000..a9a2128503 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLReadWriteImage.h @@ -0,0 +1,50 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_READ_WRITE_IMAGE_H_ +#define _OCL_READ_WRITE_IMAGE_H_ + +#include "OCLTestImp.h" + +class OCLReadWriteImage : public OCLTestImp { + public: + OCLReadWriteImage(); + virtual ~OCLReadWriteImage(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool done_; + unsigned int testID_; + size_t maxSize_; + size_t imageWidth; + size_t imageHeight; + size_t imageDepth; + size_t bufferSize; + cl_sampler sampler; + bool verifyImageData(unsigned char* inputImageData, unsigned char* output, + size_t width, size_t height); +}; + +#endif // _OCL_READ_WRITE_IMAGE_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLSDI.cpp b/opencl/tests/ocltst/module/runtime/OCLSDI.cpp new file mode 100644 index 0000000000..3314b82bbf --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLSDI.cpp @@ -0,0 +1,515 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLSDI.h" + +#include "Timer.h" +#define NUM_TESTS 6 + +#include + +typedef struct _threadInfo { + int threadID_; + OCLSDI* testObj_; +} ThreadInfo; +const char* kernel_str_ = + "__kernel void test_kernel(global unsigned int * A) \ + { \ + int id = get_global_id(0); \ + A[id] = id + 2;\ + } "; +const char* testNames[NUM_TESTS] = { + "WriteBuffer", "CopyBuffer", "NDRangeKernel", + "MapBuffer", "WriteBufferRect", "CopyImageToBuffer", +}; + +void* ThreadMain(void* data) { + if (data == NULL) { + return 0; + } + ThreadInfo* threadData = (ThreadInfo*)data; + threadData->testObj_->threadEntry(threadData->threadID_); + return NULL; +} + +OCLSDI::OCLSDI() { + // If there are two different gpus in the system, + // we have to test each of them as sender and receiver + _numSubTests = 2 * NUM_TESTS; +} + +OCLSDI::~OCLSDI() {} + +void OCLSDI::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + cl_uint numPlatforms = 0; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + _crcword = 0; + conversion = 1.0f; + program_ = 0; + kernel_ = 0; + srcBuff_ = 0; + _openTest = test % NUM_TESTS; + bufSize_ = 0x10000; + error_ = 0; + markerValue_ = 0x12345; + inputArr_ = 0; + outputArr_ = 0; + success_ = true; + extPhysicalBuff_ = 0; + silentFailure = false; + busAddressableBuff_ = 0; + devices_[0] = devices_[1] = 0; + contexts_[0] = contexts_[1] = 0; + cmd_queues_[0] = cmd_queues_[1] = 0; + image_ = 0; + + inputArr_ = (cl_uint*)malloc(bufSize_); + outputArr_ = (cl_uint*)malloc(bufSize_); + for (unsigned int i = 0; i < (bufSize_ / sizeof(cl_uint)); ++i) { + inputArr_[i] = i + 1; + outputArr_[i] = 0; + } + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(numPlatforms == 0, "clGetPlatformIDs failed"); + error_ = _wrapper->clGetPlatformIDs(1, &platform, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + error_ = _wrapper->clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, + &num_devices); + if (num_devices < 2) { + printf("\nSilent Failure: Two GPUs are required to run OCLSdi test\n"); + silentFailure = true; + return; + } + error_ = + _wrapper->clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 2, devices_, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + if (test >= NUM_TESTS) { + cl_device_id temp = devices_[0]; + devices_[0] = devices_[1]; + devices_[1] = temp; + } + size_t param_size = 0; + char* strExtensions = 0; + error_ = _wrapper->clGetDeviceInfo(devices_[0], CL_DEVICE_EXTENSIONS, 0, 0, + ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strExtensions = (char*)malloc(param_size); + error_ = _wrapper->clGetDeviceInfo(devices_[0], CL_DEVICE_EXTENSIONS, + param_size, strExtensions, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strstr(strExtensions, "cl_amd_bus_addressable_memory") == 0) { + printf( + "\nSilent Failure: cl_amd_bus_addressable_memory extension is not " + "enabled on GPU 0\n"); + silentFailure = true; + free(strExtensions); + return; + } + free(strExtensions); + error_ = _wrapper->clGetDeviceInfo(devices_[1], CL_DEVICE_EXTENSIONS, 0, 0, + ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strExtensions = (char*)malloc(param_size); + error_ = _wrapper->clGetDeviceInfo(devices_[1], CL_DEVICE_EXTENSIONS, + param_size, strExtensions, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + if (strstr(strExtensions, "cl_amd_bus_addressable_memory") == 0) { + printf( + "\nSilent Failure: cl_amd_bus_addressable_memory extension is not " + "enabled on GPU 1\n"); + silentFailure = true; + free(strExtensions); + return; + } + free(strExtensions); + deviceNames_ = " ["; + param_size = 0; + char* strDeviceName = 0; + error_ = + _wrapper->clGetDeviceInfo(devices_[1], CL_DEVICE_NAME, 0, 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strDeviceName = (char*)malloc(param_size); + error_ = _wrapper->clGetDeviceInfo(devices_[1], CL_DEVICE_NAME, param_size, + strDeviceName, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + deviceNames_ = deviceNames_ + strDeviceName; + free(strDeviceName); + error_ = + _wrapper->clGetDeviceInfo(devices_[0], CL_DEVICE_NAME, 0, 0, ¶m_size); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + strDeviceName = (char*)malloc(param_size); + error_ = _wrapper->clGetDeviceInfo(devices_[0], CL_DEVICE_NAME, param_size, + strDeviceName, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + deviceNames_ = deviceNames_ + "->"; + deviceNames_ = deviceNames_ + strDeviceName; + free(strDeviceName); + deviceNames_ = deviceNames_ + "]"; + cl_context_properties props[3] = {CL_CONTEXT_PLATFORM, + (cl_context_properties)platform, 0}; + contexts_[0] = + _wrapper->clCreateContext(props, 1, &devices_[0], 0, 0, &error_); + CHECK_RESULT(contexts_[0] == 0, "clCreateContext failed"); + contexts_[1] = + _wrapper->clCreateContext(props, 1, &devices_[1], 0, 0, &error_); + CHECK_RESULT(contexts_[1] == 0, "clCreateContext failed"); + cmd_queues_[0] = + _wrapper->clCreateCommandQueue(contexts_[0], devices_[0], 0, NULL); + CHECK_RESULT(cmd_queues_[0] == 0, "clCreateCommandQueue failed"); + cmd_queues_[1] = + _wrapper->clCreateCommandQueue(contexts_[1], devices_[1], 0, NULL); + CHECK_RESULT(cmd_queues_[1] == 0, "clCreateCommandQueue failed"); + busAddressableBuff_ = _wrapper->clCreateBuffer( + contexts_[0], CL_MEM_BUS_ADDRESSABLE_AMD, bufSize_, 0, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + error_ = _wrapper->clEnqueueMakeBuffersResidentAMD( + cmd_queues_[0], 1, &busAddressableBuff_, true, &busAddr_, 0, 0, 0); + CHECK_RESULT((error_ != CL_SUCCESS), + "clEnqueueMakeBuffersResidentAMD failed"); + extPhysicalBuff_ = _wrapper->clCreateBuffer( + contexts_[1], CL_MEM_EXTERNAL_PHYSICAL_AMD, bufSize_, &busAddr_, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer failed"); + error_ = _wrapper->clEnqueueWriteSignalAMD(cmd_queues_[1], extPhysicalBuff_, + 0, 0, 0, 0, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWriteSignalAMD failed"); + error_ = _wrapper->clFinish(cmd_queues_[1]); + CHECK_RESULT(error_, "clFinish failed"); + srcBuff_ = _wrapper->clCreateBuffer(contexts_[1], + CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, + bufSize_, inputArr_, &error_); + CHECK_RESULT(error_ != CL_SUCCESS, "clCreateBuffer failed"); + error_ = _wrapper->clEnqueueMigrateMemObjects(cmd_queues_[1], 1, + &extPhysicalBuff_, 0, 0, 0, 0); + CHECK_RESULT(error_, "clEnqueueMigrateMemObjects failed"); + error_ = _wrapper->clFinish(cmd_queues_[1]); + CHECK_RESULT(error_, "clFinish failed"); + error_ = _wrapper->clEnqueueMigrateMemObjects(cmd_queues_[1], 1, &srcBuff_, 0, + 0, 0, 0); + CHECK_RESULT(error_, "clEnqueueMigrateMemObjects failed"); + error_ = _wrapper->clFinish(cmd_queues_[1]); + CHECK_RESULT(error_, "clFinish failed"); + if (_openTest == 2) { + program_ = _wrapper->clCreateProgramWithSource(contexts_[1], 1, + &kernel_str_, NULL, &error_); + CHECK_RESULT(error_, "clCreateProgramWithSource failed"); + error_ = + _wrapper->clBuildProgram(program_, 1, &devices_[1], NULL, NULL, NULL); + if (error_ != CL_SUCCESS) { + char* errorstr; + size_t size; + _wrapper->clGetProgramBuildInfo(program_, devices_[1], + CL_PROGRAM_BUILD_LOG, 0, NULL, &size); + errorstr = new char[size]; + _wrapper->clGetProgramBuildInfo( + program_, devices_[1], CL_PROGRAM_BUILD_LOG, size, errorstr, &size); + printf("\n%s\n", errorstr); + delete[] errorstr; + } + CHECK_RESULT(error_, "clBuildProgram failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "test_kernel", &error_); + CHECK_RESULT(error_, "clCreateKernel failed"); + error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), + (void*)&extPhysicalBuff_); + CHECK_RESULT(error_, "clSetKernelArg failed"); + } + if (_openTest == 5) { + cl_image_format format = {CL_R, CL_UNSIGNED_INT32}; + cl_image_desc desc; + desc.image_type = CL_MEM_OBJECT_IMAGE1D; + desc.image_width = bufSize_ / sizeof(cl_uint); + desc.image_height = 0; + desc.image_depth = 0; + desc.image_array_size = 0; + desc.image_row_pitch = 0; + desc.image_slice_pitch = 0; + desc.num_mip_levels = 0; + desc.num_samples = 0; + desc.buffer = (cl_mem)NULL; + image_ = _wrapper->clCreateImage(contexts_[1], CL_MEM_READ_ONLY, &format, + &desc, 0, &error_); + CHECK_RESULT(error_, "clCreateImage failed"); + } +} + +void OCLSDI::run(void) { + if (silentFailure) { + return; + } + ++markerValue_; + OCLutil::Thread threads[2]; + ThreadInfo threadInfo[2]; + threadInfo[0].testObj_ = threadInfo[1].testObj_ = this; + threadInfo[0].threadID_ = 0; + threadInfo[1].threadID_ = 1; + threads[0].create(ThreadMain, &threadInfo[0]); + threads[1].create(ThreadMain, &threadInfo[1]); + threads[0].join(); + threads[1].join(); + char* descString = (char*)malloc(25 + deviceNames_.size()); + sprintf(descString, "%-20s%s", testNames[_openTest], deviceNames_.c_str()); + testDescString = descString; + free(descString); + if (!success_) { + _errorFlag = true; + _crcword += 1; + } +} + +void OCLSDI::threadEntry(int threadID) { + if (silentFailure) { + return; + } + switch (_openTest) { + case 0: + testEnqueueWriteBuffer(threadID); + break; + case 1: + testEnqueueCopyBuffer(threadID); + break; + case 2: + testEnqueueNDRangeKernel(threadID); + break; + case 3: + testEnqueueMapBuffer(threadID); + break; + case 4: + testEnqueueWriteBufferRect(threadID); + break; + case 5: + testEnqueueCopyImageToBuffer(threadID); + break; + } +} + +unsigned int OCLSDI::close(void) { + if (srcBuff_) { + error_ = _wrapper->clReleaseMemObject(srcBuff_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseMemObject failed"); + } + if (extPhysicalBuff_) { + error_ = _wrapper->clReleaseMemObject(extPhysicalBuff_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseMemObject failed"); + } + if (busAddressableBuff_) { + error_ = _wrapper->clReleaseMemObject(busAddressableBuff_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseMemObject failed"); + } + if (cmd_queues_[0]) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queues_[0]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (cmd_queues_[1]) { + error_ = _wrapper->clReleaseCommandQueue(cmd_queues_[1]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, + "clReleaseCommandQueue failed"); + } + if (contexts_[0]) { + error_ = _wrapper->clReleaseContext(contexts_[0]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + if (contexts_[1]) { + error_ = _wrapper->clReleaseContext(contexts_[1]); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseContext failed"); + } + if (program_) { + error_ = _wrapper->clReleaseProgram(program_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseProgram failed"); + } + if (kernel_) { + error_ = _wrapper->clReleaseKernel(kernel_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseKernel failed"); + } + if (image_) { + error_ = _wrapper->clReleaseMemObject(image_); + CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseMemObject failed"); + } + if (inputArr_) { + free(inputArr_); + } + if (outputArr_) { + free(outputArr_); + } + return _crcword; +} + +void OCLSDI::readAndVerifyResult() { + memset(outputArr_, 0, bufSize_); + error_ = _wrapper->clEnqueueWaitSignalAMD(cmd_queues_[0], busAddressableBuff_, + markerValue_, 0, 0, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWaitSignalAMD failed"); + error_ = _wrapper->clEnqueueReadBuffer(cmd_queues_[0], busAddressableBuff_, + CL_TRUE, 0, bufSize_, outputArr_, 0, 0, + NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueReadBuffer failed"); + success_ = (memcmp(inputArr_, outputArr_, bufSize_) == 0); +} + +void OCLSDI::testEnqueueCopyImageToBuffer(int threadID) { + if (threadID == 0) { + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {bufSize_ / sizeof(cl_uint), 1, 1}; + memset(inputArr_, (_openTest + 1), bufSize_); + error_ = + _wrapper->clEnqueueWriteImage(cmd_queues_[1], image_, CL_TRUE, origin, + region, 0, 0, inputArr_, 0, 0, 0); + CHECK_RESULT(error_, "clEnqueueWriteImage failed"); + _wrapper->clFinish(cmd_queues_[1]); + error_ = _wrapper->clEnqueueCopyImageToBuffer( + cmd_queues_[1], image_, extPhysicalBuff_, origin, region, 0, 0, 0, 0); + CHECK_RESULT(error_, "clEnqueueCopyImageToBuffer failed"); + _wrapper->clFinish(cmd_queues_[1]); + error_ = _wrapper->clEnqueueWriteSignalAMD(cmd_queues_[1], extPhysicalBuff_, + markerValue_, 0, 0, 0, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWriteSignalAMD failed"); + error_ = _wrapper->clFinish(cmd_queues_[1]); + CHECK_RESULT(error_, "clFinish failed"); + } else { + readAndVerifyResult(); + } +} + +void OCLSDI::testEnqueueWriteBufferRect(int threadID) { + size_t width = (size_t)sqrt((float)bufSize_); + size_t bufOrigin[3] = {0, 0, 0}; + size_t hostOrigin[3] = {0, 0, 0}; + size_t region[3] = {width, width, 1}; + if (threadID == 0) { + memset(inputArr_, (_openTest + 1), bufSize_); + error_ = _wrapper->clEnqueueWriteBufferRect( + cmd_queues_[1], extPhysicalBuff_, CL_TRUE, bufOrigin, hostOrigin, + region, width, 0, width, 0, inputArr_, 0, 0, 0); + CHECK_RESULT(error_, "clEnqueueWriteBufferRect failed"); + error_ = _wrapper->clEnqueueWriteSignalAMD(cmd_queues_[1], extPhysicalBuff_, + markerValue_, 0, 0, 0, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWriteSignalAMD failed"); + error_ = _wrapper->clFinish(cmd_queues_[1]); + CHECK_RESULT(error_, "clFinish failed"); + } else { + memset(outputArr_, 0, bufSize_); + error_ = _wrapper->clEnqueueWaitSignalAMD( + cmd_queues_[0], busAddressableBuff_, markerValue_, 0, 0, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWaitSignalAMD failed"); + error_ = _wrapper->clEnqueueReadBufferRect( + cmd_queues_[0], busAddressableBuff_, CL_TRUE, bufOrigin, hostOrigin, + region, width, 0, width, 0, outputArr_, 0, 0, 0); + CHECK_RESULT(error_, "clEnqueueReadBufferRect failed"); + success_ = (memcmp(inputArr_, outputArr_, bufSize_) == 0); + } +} + +void OCLSDI::testEnqueueMapBuffer(int threadID) { + if (threadID == 0) { + memset(inputArr_, (_openTest + 1), bufSize_); + error_ = _wrapper->clEnqueueWriteBuffer(cmd_queues_[1], extPhysicalBuff_, + CL_TRUE, 0, bufSize_, inputArr_, 0, + 0, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWriteBuffer failed"); + error_ = _wrapper->clEnqueueWriteSignalAMD(cmd_queues_[1], extPhysicalBuff_, + markerValue_, 0, 0, 0, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWriteSignalAMD failed"); + error_ = _wrapper->clFinish(cmd_queues_[1]); + CHECK_RESULT(error_, "clFinish failed"); + } else { + error_ = _wrapper->clEnqueueWaitSignalAMD( + cmd_queues_[0], busAddressableBuff_, markerValue_, 0, 0, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWaitSignalAMD failed"); + void* ptr = _wrapper->clEnqueueMapBuffer( + cmd_queues_[0], busAddressableBuff_, CL_TRUE, CL_MAP_READ, 0, bufSize_, + 0, 0, 0, &error_); + CHECK_RESULT(error_, "clEnqueueMapBuffer failed"); + success_ = (memcmp(inputArr_, ptr, bufSize_) == 0); + error_ = _wrapper->clEnqueueUnmapMemObject( + cmd_queues_[0], busAddressableBuff_, ptr, 0, 0, 0); + CHECK_RESULT(error_, "clEnqueueUnmapMemObject failed"); + error_ = _wrapper->clFinish(cmd_queues_[0]); + CHECK_RESULT(error_, "clFinish failed"); + } +} + +void OCLSDI::testEnqueueNDRangeKernel(int threadID) { + if (threadID == 0) { + size_t global_work_size = bufSize_ / sizeof(cl_uint); + error_ = _wrapper->clEnqueueNDRangeKernel(cmd_queues_[1], kernel_, 1, NULL, + &global_work_size, NULL, 0, NULL, + NULL); + CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed"); + error_ = _wrapper->clFinish(cmd_queues_[1]); + CHECK_RESULT(error_, "clFinish failed"); + error_ = _wrapper->clEnqueueWriteSignalAMD(cmd_queues_[1], extPhysicalBuff_, + markerValue_, 0, 0, 0, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWriteSignalAMD failed"); + error_ = _wrapper->clFinish(cmd_queues_[1]); + CHECK_RESULT(error_, "clFinish failed"); + } else { + memset(outputArr_, 0, bufSize_); + error_ = _wrapper->clEnqueueWaitSignalAMD( + cmd_queues_[0], busAddressableBuff_, markerValue_, 0, 0, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWaitSignalAMD failed"); + error_ = _wrapper->clEnqueueReadBuffer(cmd_queues_[0], busAddressableBuff_, + CL_TRUE, 0, bufSize_, outputArr_, 0, + 0, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWriteBuffer failed"); + success_ = true; + for (cl_uint i = 0; i < bufSize_ / sizeof(cl_uint); ++i) { + success_ &= (outputArr_[i] == i + 2); + } + } +} + +void OCLSDI::testEnqueueCopyBuffer(int threadID) { + if (threadID == 0) { + memset(inputArr_, (_openTest + 1), bufSize_); + error_ = _wrapper->clEnqueueWriteBuffer(cmd_queues_[1], srcBuff_, CL_TRUE, + 0, bufSize_, inputArr_, 0, 0, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWriteBuffer failed"); + error_ = _wrapper->clEnqueueCopyBuffer(cmd_queues_[1], srcBuff_, + extPhysicalBuff_, 0, 0, bufSize_, 0, + NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyBuffer failed"); + error_ = _wrapper->clEnqueueWriteSignalAMD(cmd_queues_[1], extPhysicalBuff_, + markerValue_, 0, 0, 0, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWriteSignalAMD failed"); + error_ = _wrapper->clFinish(cmd_queues_[1]); + CHECK_RESULT(error_, "clFinish failed"); + } else { + readAndVerifyResult(); + } +} + +void OCLSDI::testEnqueueWriteBuffer(int threadID) { + if (threadID == 0) { + memset(inputArr_, (_openTest + 1), bufSize_); + error_ = _wrapper->clEnqueueWriteBuffer(cmd_queues_[1], extPhysicalBuff_, + CL_TRUE, 0, bufSize_, inputArr_, 0, + 0, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWriteBuffer failed"); + error_ = _wrapper->clEnqueueWriteSignalAMD(cmd_queues_[1], extPhysicalBuff_, + markerValue_, 0, 0, 0, 0); + CHECK_RESULT(error_ != CL_SUCCESS, "clEnqueueWriteSignalAMD failed"); + error_ = _wrapper->clFinish(cmd_queues_[1]); + CHECK_RESULT(error_, "clFinish failed"); + } else { + readAndVerifyResult(); + } +} diff --git a/opencl/tests/ocltst/module/runtime/OCLSDI.h b/opencl/tests/ocltst/module/runtime/OCLSDI.h new file mode 100644 index 0000000000..17ba9b781c --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLSDI.h @@ -0,0 +1,65 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_OCLSDI_H_ +#define _OCL_OCLSDI_H_ +#include + +#include "OCLTestImp.h" + +class OCLSDI : public OCLTestImp { + public: + OCLSDI(); + virtual ~OCLSDI(); + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + void threadEntry(int threadID); + + private: + void testEnqueueWriteBuffer(int threadID); + void testEnqueueCopyBuffer(int threadID); + void testEnqueueNDRangeKernel(int threadID); + void testEnqueueMapBuffer(int threadID); + void testEnqueueWriteBufferRect(int threadID); + void testEnqueueCopyImageToBuffer(int threadID); + void readAndVerifyResult(); + + bool silentFailure; + cl_context contexts_[2]; + cl_device_id devices_[2]; + cl_command_queue cmd_queues_[2]; + cl_mem extPhysicalBuff_; + cl_mem busAddressableBuff_; + cl_int error_; + cl_bus_address_amd busAddr_; + cl_uint* inputArr_; + cl_uint* outputArr_; + unsigned int bufSize_; + bool success_; + cl_uint markerValue_; + cl_mem srcBuff_; + cl_program program_; + cl_kernel kernel_; + cl_mem image_; + std::string deviceNames_; +}; +#endif // _OCL_OCLSDI_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLSVM.cpp b/opencl/tests/ocltst/module/runtime/OCLSVM.cpp new file mode 100644 index 0000000000..c311e202dd --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLSVM.cpp @@ -0,0 +1,617 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLSVM.h" + +#include + +#include +#include +#ifdef _WIN32 +#include +#include +#endif +#include + +#define NUM_SIZES 6 + +#define OCL_CHECK(error) \ + if (error != CL_SUCCESS) { \ + fprintf(stderr, "OpenCL API invocation failed at %s:%d\n", __FILE__, \ + __LINE__); \ + exit(-1); \ + } + +#define STR(__macro__) #__macro__ + +#ifdef _WIN32 +size_t getTotalSystemMemory() { + MEMORYSTATUSEX status; + status.dwLength = sizeof(status); + GlobalMemoryStatusEx(&status); + return status.ullTotalPhys; +} +#endif + +template +static unsigned countOf(const T (&)[N]) { + return N; +} + +const static char* sources[] = { + STR(__kernel void test(__global int* ptr) { + ptr[get_global_id(0)] = 0xDEADBEEF; + }), + STR(__kernel void test(__global int* ptr, __global int* ptr2) { + ptr[get_global_id(0)] = 0xDEADBEEF; + ptr2[get_global_id(0)] = 0xDEADF00D; + }), + STR(__kernel void test(__global long* ptr) { + ptr[get_global_id(0) * 1024] = 0xBAADF00D; + }), + STR(__kernel void test(__global ulong* ptr) { + while (ptr) { + *ptr = 0xDEADBEEF; + ptr = *((__global ulong* __global*)(ptr + 1)); + } + }), + STR(__kernel void test(__global volatile int* ptr, int numIterations) { + for (int i = 0; i < numIterations; i++) { + // This should be: + // atomic_fetch_add_explicit(ptr, 1, memory_order_relaxed, + // memory_scope_all_svm_devices); + // But using device atomics is mapped to the same ISA and compiles + // in OpenCL 1.2 + atomic_inc(ptr); + } + }), + STR(__kernel void test(){ + // dummy + }), + STR(__kernel void test(int8 arg0, __global int* arg1, int arg2, + __global int* arg3, __global float* arg4){ + // dummy + }), + STR(__kernel void test(__global int* ptr, int to) { + // dummy kernel that takes a long time to complete + for (int i = 0; i < to; ++i) { + // avoid compiler optimizations + if (ptr[get_global_id(0)] != 17) { + ptr[get_global_id(0)]++; + } else { + ptr[get_global_id(0)] += 2; + } + } + }), + STR(__kernel void test(){ + // dummy + })}; + +OCLSVM::OCLSVM() { _numSubTests = countOf(sources); } + +OCLSVM::~OCLSVM() {} + +void OCLSVM::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_ERROR(error_, "Error opening test"); + _openTest = test; + + if (!isOpenClSvmAvailable(devices_[_deviceId])) { + printf("Device does not support any SVM features, skipping...\n"); + return; + } + + program_ = _wrapper->clCreateProgramWithSource( + context_, 1, sources + _openTest, NULL, &error_); + CHECK_ERROR(error_, "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], + "-cl-std=CL2.0", NULL, NULL); + CHECK_ERROR(error_, "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "test", &error_); + CHECK_ERROR(error_, "clCreateKernel() failed"); +} + +#ifndef CL_VERSION_2_0 +// make sure the tests compile in OpenCL <= 1.2 +void OCLSVM::runFineGrainedBuffer() {} +void OCLSVM::runFineGrainedSystem() {} +void OCLSVM::runFineGrainedSystemLargeAllocations() {} +void OCLSVM::runLinkedListSearchUsingFineGrainedSystem() {} +void OCLSVM::runPlatformAtomics() {} +void OCLSVM::runEnqueueOperations() {} +void OCLSVM::runSvmArgumentsAreRecognized() {} +void OCLSVM::runSvmCommandsExecutedInOrder() {} +void OCLSVM::runIdentifySvmBuffers() {} +#else + +void OCLSVM::runFineGrainedBuffer() { + if (!(svmCaps_ & CL_DEVICE_SVM_FINE_GRAIN_BUFFER)) { + printf( + "Device does not support fined-grained buffer sharing, skipping " + "test...\n"); + return; + } + const size_t numElements = 256; + int* ptr = (int*)clSVMAlloc(context_, + CL_MEM_READ_WRITE | CL_MEM_SVM_FINE_GRAIN_BUFFER, + numElements * sizeof(int), 0); + CHECK_RESULT(!ptr, "clSVMAlloc() failed"); + + error_ = clSetKernelArgSVMPointer(kernel_, 0, ptr); + CHECK_ERROR(error_, "clSetKernelArgSVMPointer() failed"); + + size_t gws[1] = {numElements}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_ERROR(error_, "clEnqueueNDRangeKernel() failed"); + + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + CHECK_ERROR(error_, "Queue::finish() failed"); + + size_t matchingElements = std::count(ptr, ptr + numElements, (int)0xDEADBEEF); + CHECK_RESULT(matchingElements != numElements, "Expected: %zd, found:%zd", + numElements, matchingElements); + clSVMFree(context_, ptr); +} + +void OCLSVM::runFineGrainedSystem() { + if (!(svmCaps_ & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM)) { + printf( + "Device does not support fined-grained system sharing, skipping " + "test...\n"); + return; + } + + const size_t numElements = 256; + int* ptr = new int[numElements]; + int* ptr2 = new int[numElements]; + error_ = clSetKernelArgSVMPointer(kernel_, 0, ptr); + CHECK_ERROR(error_, "clSetKernelArgSVMPointer() failed"); + + error_ = clSetKernelArgSVMPointer(kernel_, 1, ptr2); + CHECK_ERROR(error_, "clSetKernelArgSVMPointer() failed"); + + size_t gws[1] = {numElements}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_ERROR(error_, "clEnqueueNDRangeKernel() failed"); + + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + CHECK_ERROR(error_, "Queue::finish() failed"); + + size_t matchingElements = std::count(ptr, ptr + numElements, (int)0xDEADBEEF); + size_t matchingElements2 = + std::count(ptr2, ptr2 + numElements, (int)0xDEADF00D); + CHECK_RESULT(matchingElements + matchingElements2 != 2 * numElements, + "Expected: %zd, found:%zd", numElements * 2, + matchingElements + matchingElements2); + delete[] ptr; + delete[] ptr2; +} + +void OCLSVM::runFineGrainedSystemLargeAllocations() { +#ifdef _WIN32 + if (!(svmCaps_ & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM)) { + printf( + "Device does not support fined-grained system sharing on Lnx, skipping " + "test...\n"); + return; + } + + // Max allowed multiplier for malloc + size_t allowedMemSize = getTotalSystemMemory() >> 12; + + size_t numElements = 256; + + char* s = getenv("OCLSVM_MALLOC_GB_SIZE"); + char* s2 = getenv("OCLSVM_MEMSET_ALLOC"); + + for (int j = 1; j <= NUM_SIZES; j++) { + numElements = 131072 * j; + + if (s != NULL) numElements = 131072 * atoi(s); + + if (numElements > allowedMemSize) break; + + void* ptr = malloc(numElements * 1024 * sizeof(uint64_t)); + CHECK_ERROR(ptr == NULL, "malloc failure"); + + if (s2 != NULL) memset(ptr, 0, numElements * 1024 * sizeof(uint64_t)); + + error_ = clSetKernelArgSVMPointer(kernel_, 0, ptr); + CHECK_ERROR(error_, "clSetKernelArgSVMPointer() failed"); + + size_t gws[1] = {numElements}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_ERROR(error_, "clEnqueueNDRangeKernel() failed"); + + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + CHECK_ERROR(error_, "Queue::finish() failed"); + + uint64_t* ptr64 = reinterpret_cast(ptr); + // Do a check + for (int i = 0; i < numElements; i++) { + if ((int)ptr64[i * 1024] != 0xBAADF00D) { + uint64_t temp = ptr64[i * 1024]; + delete[] ptr; + CHECK_RESULT(temp != 0xBAADF00D, "Found: %d, Expected:%d", temp, + 0xBAADF00D); + } + } + delete[] ptr; + } +#endif +} + +void OCLSVM::runLinkedListSearchUsingFineGrainedSystem() { + if (!(svmCaps_ & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM)) { + printf( + "Device does not support fined-grained system sharing, skipping " + "test...\n"); + return; + } + + uint64_t input[] = {34, 6, 0, 11, 89, 34, 6, 6, 6, 0xDEADBEEF}; + int inputSize = countOf(input); + Node* ptr = NULL; + for (int i = 0; i < inputSize; i++) { + ptr = new Node(input[i], ptr); + } + error_ = clSetKernelArgSVMPointer(kernel_, 0, ptr); + CHECK_ERROR(error_, "clSetKernelArgSVMPointer() failed"); + + size_t gws[1] = {1}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_ERROR(error_, "clEnqueueNDRangeKernel() failed"); + + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + CHECK_ERROR(error_, "Queue::finish() failed"); + + int matchingElements = 0; + // verify result while deallocating resources at the same time + while (ptr) { + if (ptr->value_ == 0xDEADBEEF) { + matchingElements++; + } + Node* tmp = ptr; + ptr = (Node*)ptr->next_; + delete tmp; + } + CHECK_RESULT(matchingElements != inputSize, "Expected: %d, found:%d", + inputSize, matchingElements); +} + +static int atomicIncrement(volatile int* loc) { +#if defined(_MSC_VER) + return _InterlockedIncrement((volatile long*)loc); +#elif defined(__GNUC__) + return __sync_fetch_and_add(loc, 1); +#endif + printf("Atomic increment not supported, aborting..."); + std::abort(); + return 0; +} + +void OCLSVM::runPlatformAtomics() { + if (!(svmCaps_ & CL_DEVICE_SVM_ATOMICS)) { + printf("SVM atomics not supported, skipping test...\n"); + return; + } + + volatile int* value = (volatile int*)clSVMAlloc( + context_, CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS, sizeof(int), + 0); + CHECK_RESULT(!value, "clSVMAlloc() failed"); + *value = 0; + const int numIterations = 1000000; + error_ = clSetKernelArgSVMPointer(kernel_, 0, (const void*)value); + CHECK_ERROR(error_, "clSetKernelArgSVMPointer() failed"); + + error_ = clSetKernelArg(kernel_, 1, sizeof(numIterations), &numIterations); + CHECK_ERROR(error_, "clSetKernelArg() failed"); + + size_t gws[1] = {1}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_ERROR(error_, "clEnqueueNDRangeKernel() failed"); + + for (int i = 0; i < numIterations; i++) { + atomicIncrement(value); + } + + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + CHECK_ERROR(error_, "Queue::finish() failed"); + + int expected = numIterations * 2; + CHECK_RESULT(*value != expected, "Expected: %d, found:%d", expected, *value); + clSVMFree(context_, (void*)value); +} + +void OCLSVM::runEnqueueOperations() { + size_t numElements = 32; + size_t size = numElements * 4; + int* ptr0 = (int*)clSVMAlloc(context_, 0, size, 0); + CHECK_RESULT(!ptr0, "clSVMAlloc() failed"); + int* ptr1 = (int*)clSVMAlloc(context_, 0, size, 0); + CHECK_RESULT(!ptr1, "clSVMAlloc() failed"); + cl_event userEvent = clCreateUserEvent(context_, &error_); + CHECK_ERROR(error_, "clCreateUserEvent() failed"); + + cl_command_queue queue = cmdQueues_[_deviceId]; + // coarse-grained buffer semantics: the SVM pointer needs to be mapped + // before the pointer can write to it + error_ = + clEnqueueSVMMap(queue, CL_TRUE, CL_MAP_WRITE, ptr0, size, 0, NULL, NULL); + CHECK_ERROR(error_, "clEnqueueSVMMap() failed"); + std::fill(ptr0, ptr0 + numElements, 1); + error_ = clEnqueueSVMUnmap(queue, ptr0, 0, NULL, NULL); + CHECK_ERROR(error_, "clEnqueueSVMUnmap() failed"); + + // we copy the 1st buffer into the 2nd buffer + error_ = clEnqueueSVMMemcpy(queue, true, ptr1, ptr0, size, 0, NULL, NULL); + CHECK_ERROR(error_, "clEnqueueSVMMemcpy() failed"); + + // verification: the 2nd buffer should be identical to the 1st + error_ = clEnqueueSVMMap(queue, CL_TRUE, CL_MAP_READ, ptr1, size, 0, NULL, + &userEvent); + CHECK_ERROR(error_, "clEnqueueSVMMap() failed"); + + error_ = clWaitForEvents(1, &userEvent); + CHECK_ERROR(error_, "clWaitForEvents() failed"); + + size_t observed = std::count(ptr1, ptr1 + numElements, 1); + size_t expected = numElements; + CHECK_RESULT(observed != expected, "Expected: %zd, found:%zd", expected, + observed); + + void* ptrs[2] = {ptr0, ptr1}; + error_ = + clEnqueueSVMFree(queue, countOf(ptrs), ptrs, NULL, NULL, 0, NULL, NULL); + CHECK_ERROR(error_, "clEnqueueSVMFree() failed"); + error_ = clFinish(queue); + CHECK_ERROR(error_, "clFinish() failed"); +} + +/** + * Simple test to ensure that SVM pointer arguments are identified properly in + * the runtime, since kernel arguments of pointer type can be bound to either + * SVM pointers or cl_mem objects. + */ +void OCLSVM::runSvmArgumentsAreRecognized() { + cl_int8 arg0; + error_ = clSetKernelArg(kernel_, 0, sizeof(arg0), &arg0); + CHECK_ERROR(error_, "clSetKernelArg() failed"); + + error_ = clSetKernelArgSVMPointer(kernel_, 1, NULL); + CHECK_ERROR(error_, "clSetKernelArgSVMPointer() failed"); + + cl_int arg2; + error_ = clSetKernelArg(kernel_, 2, sizeof(arg2), &arg2); + CHECK_ERROR(error_, "clSetKernelArg() failed"); + + error_ = clSetKernelArgSVMPointer(kernel_, 3, NULL); + CHECK_ERROR(error_, "clSetKernelArgSVMPointer() failed"); + + cl_mem arg4 = NULL; + error_ = clSetKernelArg(kernel_, 4, sizeof(arg4), &arg4); + CHECK_ERROR(error_, "clSetKernelArg() failed"); + + size_t gws[1] = {1}; + + // run dummy kernel + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_ERROR(error_, "clEnqueueNDRangeKernel() failed"); + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + CHECK_ERROR(error_, "Queue::finish() failed"); + + // now we bind a pointer argument to a standard buffer instead of a SVM one + cl_mem buffer = NULL; + error_ = clSetKernelArg(kernel_, 1, sizeof(buffer), &buffer); + CHECK_ERROR(error_, "clSetKernelArg() failed"); + + // re-execute the dummy kernel using different actual parameters + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, gws, NULL, 0, NULL, NULL); + CHECK_ERROR(error_, "clEnqueueNDRangeKernel() failed"); + error_ = _wrapper->clFinish(cmdQueues_[_deviceId]); + CHECK_ERROR(error_, "Queue::finish() failed"); +} + +void OCLSVM::runSvmCommandsExecutedInOrder() { +#if EMU_ENV + // Small number is enough to verify functionality in Emu environment + const int numElements = 5000; +#else + const int numElements = 100000; +#endif // EMU_ENV + size_t size = numElements * sizeof(int); + // allocate SVM memory + int* data = (int*)clSVMAlloc(context_, CL_MEM_READ_WRITE, size, 0); + CHECK_RESULT(!data, "clSVMAlloc failed"); + + // map the SVM buffer to host + cl_int status = clEnqueueSVMMap(cmdQueues_[_deviceId], CL_TRUE, CL_MAP_WRITE, + data, size, 0, NULL, NULL); + CHECK_ERROR(status, "Error when mapping SVM buffer"); + + // fill buffer with 0s + std::fill(data, data + numElements, 0); + + // unmap the SVM buffer to host + status = clEnqueueSVMUnmap(cmdQueues_[_deviceId], data, 0, NULL, NULL); + CHECK_ERROR(status, "Error when unmapping SVM buffer"); + + // enqueue kernel + status = clSetKernelArgSVMPointer(kernel_, 0, data); + CHECK_ERROR(status, "Error when setting kernel argument"); + status = clSetKernelArg(kernel_, 1, sizeof(int), &numElements); + CHECK_ERROR(status, "clSetKernelArg() failed"); + + cl_event event; + size_t overallSize = (size_t)numElements; + status = clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, NULL, + &overallSize, NULL, 0, NULL, &event); + CHECK_ERROR(status, "Error when enqueuing kernel"); + error_ = clFinish(cmdQueues_[_deviceId]); + CHECK_ERROR(status, "clFinish()"); + + // map the SVM buffer to host + status = clEnqueueSVMMap(cmdQueues_[_deviceId], CL_TRUE, CL_MAP_READ, data, + size, 0, NULL, NULL); + CHECK_ERROR(status, "Error when mapping SVM buffer"); + + bool pass = true; + // verify the data. Using descending order might increase the chance of + // finding an error since the GPU (when used) might not have finished + // updating the data array by the time we do the verification + for (int i = numElements - 1; i >= 0; i--) { + if (data[i] != numElements + 1) { + pass = false; + break; + } + } + + // unmap the SVM buffer to host + status = clEnqueueSVMUnmap(cmdQueues_[_deviceId], data, 0, NULL, NULL); + CHECK_ERROR(status, "Error when unmapping SVM buffer"); + + // free the SVM buffer + status = clEnqueueSVMFree(cmdQueues_[_deviceId], 1, (void**)&data, NULL, NULL, + 0, NULL, NULL); + CHECK_ERROR(status, "Error when freeing the SVM buffer"); + error_ = clFinish(cmdQueues_[_deviceId]); + CHECK_ERROR(error_, "clFinish() failed"); + CHECK_RESULT(!pass, "Wrong result"); +} + +void OCLSVM::runIdentifySvmBuffers() { + size_t size = 1024 * 1024; + + // dummy allocation to force the runtime to track several SVM buffers + clSVMAlloc(context_, CL_MEM_READ_WRITE, size * 10, 0); + + void* ptr = clSVMAlloc(context_, CL_MEM_READ_WRITE, size, 0); + cl_int status; + cl_bool usesSVMpointer = CL_FALSE; + + // dummy allocation to force the runtime to track several SVM buffers + clSVMAlloc(context_, CL_MEM_READ_WRITE, size * 4, 0); + + // buffer using the entire SVM region should be identified as such + cl_mem buf1 = + clCreateBuffer(context_, CL_MEM_USE_HOST_PTR, size, ptr, &status); + CHECK_ERROR(status, "clCreateBuffer failed."); + + size_t paramSize = 0; + status = clGetMemObjectInfo(buf1, CL_MEM_USES_SVM_POINTER, 0, 0, ¶mSize); + CHECK_ERROR(status, "clGetMemObjectInfo failed"); + CHECK_RESULT(paramSize != sizeof(cl_bool), + "clGetMemObjectInfo(CL_MEM_USES_SVM_POINTER) " + "returned wrong size."); + + status = clGetMemObjectInfo(buf1, CL_MEM_USES_SVM_POINTER, sizeof(cl_bool), + &usesSVMpointer, 0); + CHECK_ERROR(status, "clGetMemObjectInfo failed"); + CHECK_RESULT(usesSVMpointer != CL_TRUE, + "clGetMemObjectInfo(CL_MEM_USES_SVM_POINTER) " + "returned CL_FALSE for buffer created from SVM pointer."); + + // Buffer that uses random region within SVM buffers + cl_mem buf2 = clCreateBuffer(context_, CL_MEM_USE_HOST_PTR, 256, + (char*)ptr + size - 256, &status); + CHECK_ERROR(status, "clCreateBuffer failed."); + + status = clGetMemObjectInfo(buf2, CL_MEM_USES_SVM_POINTER, sizeof(cl_bool), + &usesSVMpointer, 0); + CHECK_ERROR(status, "clGetMemObjectInfo failed"); + CHECK_RESULT(usesSVMpointer != CL_TRUE, + "clGetMemObjectInfo(CL_MEM_USES_SVM_POINTER) " + "returned CL_FALSE for buffer created from SVM pointer."); + + // for any other pointer the query should return false + void* randomPtr = malloc(size); + cl_mem buf3 = + clCreateBuffer(context_, CL_MEM_USE_HOST_PTR, size, randomPtr, &status); + CHECK_ERROR(status, "clCreateBuffer failed."); + + status = clGetMemObjectInfo(buf3, CL_MEM_USES_SVM_POINTER, sizeof(cl_bool), + &usesSVMpointer, 0); + CHECK_ERROR(status, "clGetMemObjectInfo failed"); + CHECK_RESULT(usesSVMpointer == CL_TRUE, + "clGetMemObjectInfo(CL_MEM_USES_SVM_POINTER) " + "returned CL_TRUE for buffer not created from SVM pointer."); + + clReleaseMemObject(buf3); + clReleaseMemObject(buf2); + clReleaseMemObject(buf1); + clSVMFree(context_, ptr); +} +#endif + +cl_bool OCLSVM::isOpenClSvmAvailable(cl_device_id device_id) { +#ifdef CL_VERSION_2_0 + error_ = clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_SVM_CAPABILITIES, + sizeof(svmCaps_), &svmCaps_, NULL); + CHECK_ERROR_NO_RETURN(error_, "clGetDeviceInfo() failed"); + if (!(svmCaps_ & CL_DEVICE_SVM_COARSE_GRAIN_BUFFER)) { + return CL_FALSE; + } else { + return CL_TRUE; + } +#endif + // -Device does not support OpenCL >= 2.0 + // -Device supports OpenCL >= 2.0, but available headers are <= 1.2 + return CL_FALSE; +} + +void OCLSVM::run() { + if (!isOpenClSvmAvailable(devices_[_deviceId])) { + printf("Device does not support any SVM features, skipping...\n"); + return; + } + + if (_openTest == 0) { + runFineGrainedBuffer(); + } else if (_openTest == 1) { + runFineGrainedSystem(); + } else if (_openTest == 2) { + runFineGrainedSystemLargeAllocations(); + } else if (_openTest == 3) { + runLinkedListSearchUsingFineGrainedSystem(); + } else if (_openTest == 4) { + runPlatformAtomics(); + } else if (_openTest == 5) { + runEnqueueOperations(); + } else if (_openTest == 6) { + runSvmArgumentsAreRecognized(); + } else if (_openTest == 7) { + runSvmCommandsExecutedInOrder(); + } else if (_openTest == 8) { + runIdentifySvmBuffers(); + } +} + +unsigned int OCLSVM::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLSVM.h b/opencl/tests/ocltst/module/runtime/OCLSVM.h new file mode 100644 index 0000000000..ea45c52c65 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLSVM.h @@ -0,0 +1,64 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_SVM_H_ +#define _OCL_SVM_H_ + +#include + +#include "OCLTestImp.h" +#include "stdint.h" + +class OCLSVM : public OCLTestImp { + public: + OCLSVM(); + + virtual ~OCLSVM(); + + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + + virtual void run(void); + + virtual unsigned int close(void); + + private: + void runFineGrainedBuffer(); + void runFineGrainedSystem(); + void runFineGrainedSystemLargeAllocations(); + void runLinkedListSearchUsingFineGrainedSystem(); + void runPlatformAtomics(); + void runEnqueueOperations(); + void runSvmArgumentsAreRecognized(); + void runSvmCommandsExecutedInOrder(); + void runIdentifySvmBuffers(); + cl_bool isOpenClSvmAvailable(cl_device_id device_id); + + uint64_t svmCaps_; +}; + +struct Node { + Node(uint64_t value, Node* next) : value_(value), next_((uint64_t)next) {} + + uint64_t value_; + uint64_t next_; +}; + +#endif // _OCL_SVM_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLSemaphore.cpp b/opencl/tests/ocltst/module/runtime/OCLSemaphore.cpp new file mode 100644 index 0000000000..3f4211819f --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLSemaphore.cpp @@ -0,0 +1,225 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLSemaphore.h" + +#include +#include +#include + +#include "CL/cl.h" +#ifndef CL_DEVICE_MAX_SEMAPHORES_AMD +#define CL_DEVICE_MAX_SEMAPHORES_AMD 0x1041 +#else +#error "CL_DEVICE_MAX_SEMAPHORES_AMD is defined somewhere, remove this define!" +#endif +#ifndef CL_DEVICE_MAX_SEMAPHORE_SIZE_AMD +#define CL_DEVICE_MAX_SEMAPHORE_SIZE_AMD 0x1042 +#else +#error \ + "CL_DEVICE_MAX_SEMAPHORE_SIZE_AMD is defined somewhere, remove this define!" +#endif +#ifndef CL_KERNEL_MAX_SEMAPHORE_SIZE_AMD +#define CL_KERNEL_MAX_SEMAPHORE_SIZE_AMD 0x1043 +#else +#error \ + "CL_KERNEL_MAX_SEMAPHORE_SIZE_AMD is defined somewhere, remove this define!" +#endif + +const static unsigned int MaxSemaphores = 1; + +const static char* strKernel = + "#ifdef cl_amd_semaphore\n" + "#pragma OPENCL EXTENSION cl_amd_semaphore : enable \n" + "kernel void sema_test(sema_t lock, global int* a, global int* b, int " + "value)\n" + " {\n" + " size_t idx = get_global_id(0);\n" + " size_t gdx = get_group_id(0);\n" + " size_t ng = get_num_groups(0);\n" + " size_t ssize = get_max_semaphore_size();\n" + " a[1] = true;\n" + " if (gdx >= ssize) {\n" + " return;\n" + " }\n" + " barrier(CLK_GLOBAL_MEM_FENCE);\n" + " semaphore_init(lock, ng);\n" + " while (a[1]) {\n" + " atom_add(a, b[idx]);\n" + " atom_inc(a + 2);\n" + " if (gdx == (ssize - 1)) {\n" + " semaphore_signal(lock);\n" + " if (a[0] >= value) {\n" + " a[1] = false;\n" + " }\n" + " } else {\n" + " semaphore_wait(lock);\n" + " idx += get_global_size(0);\n" + " }\n" + " }\n" + " semaphore_signal(lock);\n" + " }\n" + "#endif\n"; + +OCLSemaphore::OCLSemaphore() { + _numSubTests = 1; + hasSemaphore = false; +} + +OCLSemaphore::~OCLSemaphore() {} + +void OCLSemaphore::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + char name[1024] = {0}; + size_t size = 0; + _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_EXTENSIONS, 1024, + name, &size); + if (!strstr(name, "cl_amd_semaphore")) { + error_ = CL_DEVICE_NOT_FOUND; + hasSemaphore = false; + printf("Semaphore extension is required for this test!\n"); + return; + } else { + hasSemaphore = true; + } + _wrapper->clGetDeviceInfo(devices_[deviceId], + (cl_device_info)CL_DEVICE_MAX_SEMAPHORES_AMD, + sizeof(size), &size, NULL); + _wrapper->clGetDeviceInfo(devices_[deviceId], + (cl_device_info)CL_DEVICE_MAX_SEMAPHORE_SIZE_AMD, + sizeof(size), &size, NULL); + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "sema_test", &error_); + _wrapper->clGetKernelInfo(kernel_, + (cl_kernel_info)CL_KERNEL_MAX_SEMAPHORE_SIZE_AMD, + sizeof(size), &size, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + for (unsigned int i = 0; i < MaxSemaphores; ++i) { + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + } + + buffer = + _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + 1024 * size * sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + buffer = + _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, + 1024 * size * sizeof(cl_uint), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLSemaphore::run(void) { + if (!hasSemaphore) { + return; + } + cl_uint initVal[2] = {5, 10}; + + for (unsigned int i = 0; i < MaxSemaphores; ++i) { + cl_mem buffer = buffers()[i]; + error_ = _wrapper->clSetKernelArg(kernel_, i, sizeof(cl_uint), &initVal[i]); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + } + + cl_mem buffer = buffers()[MaxSemaphores]; + error_ = + _wrapper->clSetKernelArg(kernel_, MaxSemaphores, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + buffer = buffers()[MaxSemaphores + 1]; + error_ = _wrapper->clSetKernelArg(kernel_, MaxSemaphores + 1, sizeof(cl_mem), + &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + cl_int val = 64; + error_ = + _wrapper->clSetKernelArg(kernel_, MaxSemaphores + 2, sizeof(val), &val); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + + size_t gws[1] = {64}; + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[0], kernel_, 1, NULL, + gws, NULL, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + + cl_uint outputV[MaxSemaphores] = {0}; + + // Find the new counter value + initVal[0]++; + initVal[1]--; + + for (unsigned int i = 0; i < MaxSemaphores; ++i) { + cl_mem buffer = buffers()[i]; + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[0], buffers()[i], true, 0, + sizeof(cl_uint), &outputV[i], 0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + if (initVal[i] != outputV[i]) { + printf("%u != %u", initVal[i], outputV[i]); + CHECK_RESULT(true, " - Incorrect result for counter!\n"); + } + } + + // Restore the original value to check the returned result in the kernel + initVal[0]--; + initVal[1]++; + + buffer = buffers()[MaxSemaphores]; + error_ = _wrapper->clEnqueueReadBuffer( + cmdQueues_[0], buffers()[MaxSemaphores], true, 0, + MaxSemaphores * sizeof(cl_uint), outputV, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + for (unsigned int i = 0; i < MaxSemaphores; ++i) { + if (initVal[i] != outputV[i]) { + printf("%u != %u", initVal[i], outputV[i]); + CHECK_RESULT(true, + " - Incorrect result for counter inside kernel. Returned " + "value != original.\n"); + } + } +} + +unsigned int OCLSemaphore::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLSemaphore.h b/opencl/tests/ocltst/module/runtime/OCLSemaphore.h new file mode 100644 index 0000000000..3b8e8a36e4 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLSemaphore.h @@ -0,0 +1,39 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_SEMAPHORE_H_ +#define _OCL_SEMAPHORE_H_ + +#include "OCLTestImp.h" + +class OCLSemaphore : public OCLTestImp { + public: + OCLSemaphore(); + virtual ~OCLSemaphore(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + bool hasSemaphore; +}; + +#endif // _OCL_SEMAPHORE_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLStablePState.cpp b/opencl/tests/ocltst/module/runtime/OCLStablePState.cpp new file mode 100644 index 0000000000..d4184e3e09 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLStablePState.cpp @@ -0,0 +1,129 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLStablePState.h" + +#include +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +cl_device_id gpu_device; + +OCLStablePState::OCLStablePState() { + _numSubTests = 1; + failed_ = false; +} + +OCLStablePState::~OCLStablePState() {} + +void OCLStablePState::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + cl_uint numPlatforms; + cl_platform_id platform = NULL; + cl_uint num_devices = 0; + cl_device_id* devices = NULL; + cl_device_id device = NULL; + _deviceId = deviceId; + + if (type_ != CL_DEVICE_TYPE_GPU) { + error_ = CL_DEVICE_NOT_FOUND; + printf("GPU device is required for this test!\n"); + return; + } + + error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); + if (0 < numPlatforms) { + cl_platform_id* platforms = new cl_platform_id[numPlatforms]; + error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed"); +#if 0 + // Get last for default + platform = platforms[numPlatforms - 1]; + for (unsigned i = 0; i < numPlatforms; ++i) { +#endif + platform = platforms[_platformIndex]; + char pbuf[100]; + error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], + CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, + NULL); + num_devices = 0; + /* Get the number of requested devices */ + error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, + &num_devices); +#if 0 + } +#endif + delete platforms; + } + /* + * If we could find our platform, use it. If not, die as we need the AMD + * platform for these extensions. + */ + CHECK_RESULT(platform == 0, + "Couldn't find platform with GPU devices, cannot proceed"); + + devices = (cl_device_id*)malloc(num_devices * sizeof(cl_device_id)); + CHECK_RESULT(devices == 0, "no devices"); + + /* Get the requested device */ + error_ = + _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed"); + + CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available"); + device = devices[_deviceId]; + gpu_device = device; +} + +static void CL_CALLBACK notify_callback(cl_event event, + cl_int event_command_exec_status, + void* user_data) {} + +void OCLStablePState::run(void) { + if (failed_) { + return; + } + cl_set_device_clock_mode_input_amd setClockModeInput; + setClockModeInput.clock_mode = CL_DEVICE_CLOCK_MODE_PROFILING_AMD; + cl_set_device_clock_mode_output_amd setClockModeOutput = {}; + error_ = _wrapper->clSetDeviceClockModeAMD(gpu_device, setClockModeInput, + &setClockModeOutput); +#ifdef _WIN32 + CHECK_RESULT(error_ != CL_SUCCESS, "SetClockMode profiling failed\n"); +#else + error_ = CL_SUCCESS; +#endif + + setClockModeInput.clock_mode = CL_DEVICE_CLOCK_MODE_DEFAULT_AMD; + setClockModeOutput = {}; + error_ = _wrapper->clSetDeviceClockModeAMD(gpu_device, setClockModeInput, + &setClockModeOutput); +#ifdef _WIN32 + CHECK_RESULT(error_ != CL_SUCCESS, "SetClockMode default failed\n"); +#else + error_ = CL_SUCCESS; +#endif +} + +unsigned int OCLStablePState::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLStablePState.h b/opencl/tests/ocltst/module/runtime/OCLStablePState.h new file mode 100644 index 0000000000..a4f4da841e --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLStablePState.h @@ -0,0 +1,41 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_STABLE_PSTATE_H_ +#define _OCL_STABLE_PSTATE_H_ + +#include "OCLTestImp.h" + +class OCLStablePState : public OCLTestImp { + public: + OCLStablePState(); + virtual ~OCLStablePState(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; +}; + +#endif // _OCL_STABLE_PSTATE_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLThreadTrace.cpp b/opencl/tests/ocltst/module/runtime/OCLThreadTrace.cpp new file mode 100644 index 0000000000..6a08807739 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLThreadTrace.cpp @@ -0,0 +1,349 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLThreadTrace.h" + +#include +#include +#include + +#include "CL/cl.h" + +const static unsigned int IOThreadTrace = 3; // number of input/oputput buffers +static size_t SeNum = 1; // number of SEs +// size of thread trace buffer +#if EMU_ENV +const static unsigned int ttBufSize = 5000; +#else +const static unsigned int ttBufSize = 30000; +#endif +const static unsigned int InputElements = 2048; // elements in each vector + +const static char* strKernel = + "__kernel void thread_trace_test( \n" + " __global int *A,__global int *B,__global int *C) \n" + "{ \n" + " int idx = get_global_id(0); \n" + " C[idx] = A[idx] + B[idx]; \n" + "} \n"; + +OCLThreadTrace::OCLThreadTrace() { + _numSubTests = 1; + failed_ = false; + clCreateThreadTraceAMD_ = 0; + clReleaseThreadTraceAMD_ = 0; + clRetainThreadTraceAMD_ = 0; + clGetThreadTraceInfoAMD_ = 0; + clSetThreadTraceParamAMD_ = 0; + clEnqueueThreadTraceCommandAMD_ = 0; + clEnqueueBindThreadTraceBufferAMD_ = 0; + ioBuf_ = 0; + ttBuf_ = 0; +} + +OCLThreadTrace::~OCLThreadTrace() {} + +void OCLThreadTrace::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening"); + + if (deviceId >= deviceCount_) { + failed_ = true; + return; + } + + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + + size_t threadTraceEnabled; + size_t retsize; + error_ = _wrapper->clGetDeviceInfo( + devices_[deviceId], CL_DEVICE_THREAD_TRACE_SUPPORTED_AMD, + sizeof(threadTraceEnabled), &threadTraceEnabled, &retsize); + CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed"); + + if (!threadTraceEnabled) { + failed_ = true; + testDescString = "Not supported"; + return; + } + + unsigned int datasize = sizeof(unsigned int) * InputElements; + + ioBuf_ = (unsigned int**)malloc(IOThreadTrace * sizeof(unsigned int*)); + CHECK_RESULT((ioBuf_ == NULL), "malloc failed"); + + memset(ioBuf_, 0, IOThreadTrace * sizeof(unsigned int*)); + for (unsigned i = 0; i < IOThreadTrace; ++i) { + ioBuf_[i] = (unsigned int*)malloc(datasize); + CHECK_RESULT((ioBuf_[i] == NULL), "malloc failed"); + for (unsigned j = 0; j < InputElements; ++j) { + ioBuf_[i][j] = j; + } + } + + clCreateThreadTraceAMD_ = + (fnp_clCreateThreadTraceAMD)_wrapper->clGetExtensionFunctionAddress( + "clCreateThreadTraceAMD"); + CHECK_RESULT((clCreateThreadTraceAMD_ == 0), + "clGetExtensionFunctionAddress(clCreateThreadTraceAMD) failed"); + clGetThreadTraceInfoAMD_ = + (fnp_clGetThreadTraceInfoAMD)_wrapper->clGetExtensionFunctionAddress( + "clGetThreadTraceInfoAMD"); + CHECK_RESULT((clGetThreadTraceInfoAMD_ == 0), + "clGetExtensionFunctionAddress(clGetThreadTraceInfoAMD) failed"); + + threadTrace_ = clCreateThreadTraceAMD_(devices_[_deviceId], &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateThreadTraceAMD() failed"); + + // Get number of shader engines + clGetThreadTraceInfoAMD_(threadTrace_, CL_THREAD_TRACE_SE, sizeof(SeNum), + &SeNum, NULL); + + ttBuf_ = (unsigned int**)malloc(SeNum * sizeof(unsigned int*)); + CHECK_RESULT((ttBuf_ == NULL), "malloc failed"); + + memset(ttBuf_, 0, SeNum * sizeof(unsigned int*)); + + program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel, NULL, + &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed"); + + error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], NULL, + NULL, NULL); + if (error_ != CL_SUCCESS) { + char programLog[1024]; + _wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], + CL_PROGRAM_BUILD_LOG, 1024, programLog, 0); + printf("\n%s\n", programLog); + fflush(stdout); + } + CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed"); + + kernel_ = _wrapper->clCreateKernel(program_, "thread_trace_test", &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed"); + + cl_mem buffer; + for (unsigned int i = 0; i < IOThreadTrace; ++i) { + buffer = _wrapper->clCreateBuffer(context_, + CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, + datasize, ioBuf_[i], &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + } + + for (unsigned int i = 0; i < SeNum; ++i) { + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, ttBufSize, + NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + } + + clReleaseThreadTraceAMD_ = + (fnp_clReleaseThreadTraceAMD)_wrapper->clGetExtensionFunctionAddress( + "clReleaseThreadTraceAMD"); + CHECK_RESULT((clReleaseThreadTraceAMD_ == 0), + "clGetExtensionFunctionAddress(clReleaseThreadTraceAMD) failed"); + clRetainThreadTraceAMD_ = + (fnp_clRetainThreadTraceAMD)_wrapper->clGetExtensionFunctionAddress( + "clRetainThreadTraceAMD"); + CHECK_RESULT((clRetainThreadTraceAMD_ == 0), + "clGetExtensionFunctionAddress(clRetainThreadTraceAMD) failed"); + clSetThreadTraceParamAMD_ = + (fnp_clSetThreadTraceParamAMD)_wrapper->clGetExtensionFunctionAddress( + "clSetThreadTraceParamAMD"); + CHECK_RESULT( + (clSetThreadTraceParamAMD_ == 0), + "clGetExtensionFunctionAddress(clSetThreadTraceParamAMD) failed"); + clEnqueueThreadTraceCommandAMD_ = (fnp_clEnqueueThreadTraceCommandAMD) + _wrapper->clGetExtensionFunctionAddress( + "clEnqueueThreadTraceCommandAMD"); + CHECK_RESULT( + (clEnqueueThreadTraceCommandAMD_ == 0), + "clGetExtensionFunctionAddress(clEnqueueThreadTraceCommandAMD) failed"); + clEnqueueBindThreadTraceBufferAMD_ = + (fnp_clEnqueueBindThreadTraceBufferAMD)_wrapper + ->clGetExtensionFunctionAddress("clEnqueueBindThreadTraceBufferAMD"); + CHECK_RESULT((clEnqueueBindThreadTraceBufferAMD_ == 0), + "clGetExtensionFunctionAddress(" + "clEnqueueBindThreadTraceBufferAMD) failed"); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +static void DumpTraceSI(unsigned int index, cl_ushort* tracePtr, + size_t numOfBytes) { + FILE* outFile; + char file_name[16] = {0}; + static unsigned int iii = 0; + sprintf(file_name, "TTrace%d%d.out", index, iii++); + + outFile = fopen(file_name, "w"); + + for (size_t i = 0; i < numOfBytes / 2; i++) { + fprintf(outFile, "%04x\n", (cl_ushort)(*tracePtr)); + tracePtr++; + } + + fclose(outFile); +} + +#define DUMPTRACE 0 + +void OCLThreadTrace::run(void) { + cl_mem* ttArrBuf = 0; + unsigned int* ttBufRecordedSizes = 0; + unsigned int i = 0, j = 0; + + if (failed_) { + return; + } + + for (i = 0; i < IOThreadTrace; ++i) { + cl_mem buffer = buffers()[i]; + error_ = _wrapper->clSetKernelArg(kernel_, i, sizeof(cl_mem), &buffer); + CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed"); + } + + size_t globalWorkSize[1]; + size_t localWorkSize[1]; + globalWorkSize[0] = InputElements; + localWorkSize[0] = 32; + + ttArrBuf = (cl_mem*)malloc(sizeof(cl_mem) * SeNum); + ; + for (i = 0; i < SeNum; i++) ttArrBuf[i] = buffers()[IOThreadTrace + i]; + + cl_event clEvent; + error_ = clEnqueueBindThreadTraceBufferAMD_( + cmdQueues_[_deviceId], threadTrace_, ttArrBuf, (cl_uint)SeNum, ttBufSize, + 0, NULL, &clEvent); + CHECK_RESULT((error_ != CL_SUCCESS), + "clEnqueueBindThreadTraceBufferAMD() failed"); + + error_ = clEnqueueThreadTraceCommandAMD_(cmdQueues_[_deviceId], threadTrace_, + CL_THREAD_TRACE_BEGIN_COMMAND, 0, + NULL, &clEvent); + CHECK_RESULT((error_ != CL_SUCCESS), + "clEnqueueThreadTraceCommandAMD() failed"); + + error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1, + NULL, globalWorkSize, localWorkSize, + 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed"); + clFinish(cmdQueues_[_deviceId]); + + error_ = clEnqueueThreadTraceCommandAMD_(cmdQueues_[_deviceId], threadTrace_, + CL_THREAD_TRACE_END_COMMAND, 0, NULL, + &clEvent); + CHECK_RESULT((error_ != CL_SUCCESS), + "clEnqueueThreadTraceCommandAMD() failed"); + + ttBufRecordedSizes = (unsigned int*)malloc(sizeof(unsigned int) * SeNum); + memset(ttBufRecordedSizes, 0, sizeof(unsigned int) * SeNum); + size_t ttBufRecordedSize; + error_ = clGetThreadTraceInfoAMD_(threadTrace_, CL_THREAD_TRACE_BUFFERS_SIZE, + 1, NULL, &ttBufRecordedSize); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetThreadTraceInfoAMD() failed"); + + if (ttBufRecordedSize > sizeof(unsigned int) * SeNum) { + free(ttBufRecordedSizes); + ttBufRecordedSizes = (unsigned int*)malloc(ttBufRecordedSize); + memset(ttBufRecordedSizes, 0, ttBufRecordedSize); + } + + error_ = + clGetThreadTraceInfoAMD_(threadTrace_, CL_THREAD_TRACE_BUFFERS_SIZE, + ttBufRecordedSize, ttBufRecordedSizes, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clGetThreadTraceInfoAMD() failed"); + + for (i = 0; i < SeNum; ++i) { + ttBuf_[i] = (cl_uint*)malloc(ttBufRecordedSizes[i] * sizeof(cl_uint)); + CHECK_RESULT((ttBuf_[i] == NULL), "malloc failed"); + } + + for (i = 0; i < SeNum; ++i) { + if (ttBufRecordedSizes[i] != 0) { + error_ = _wrapper->clEnqueueReadBuffer( + cmdQueues_[_deviceId], buffers()[IOThreadTrace + i], CL_TRUE, 0, + ttBufRecordedSizes[i], ttBuf_[i], 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); +#if DUMPTRACE + DumpTraceSI(i, (cl_ushort*)ttBuf_[i], ttBufRecordedSizes[i]); +#endif + } + } + + bool validRes = true; + for (i = 0; i < SeNum; ++i) { + unsigned j; + for (j = 0; j < ttBufRecordedSizes[i]; ++j) { + if (ttBuf_[i][j] != 0) { + break; + } + } + if (j >= ttBufRecordedSizes[i] && ttBufRecordedSizes[i] > 0) { + validRes = false; + break; + } + } + if (!validRes) { + CHECK_RESULT( + true, + " - Incorrect result for thread trace. no output data was recorded.\n"); + } + + if (ttArrBuf) free(ttArrBuf); + if (ttBufRecordedSizes) free(ttBufRecordedSizes); +} + +unsigned int OCLThreadTrace::close(void) { + if (clReleaseThreadTraceAMD_ && threadTrace_) + clReleaseThreadTraceAMD_(threadTrace_); + + if (ioBuf_) { + for (unsigned i = 0; i < IOThreadTrace; ++i) { + if (ioBuf_[i]) { + free(ioBuf_[i]); + } + } + free(ioBuf_); + } + if (ttBuf_) { + for (unsigned i = 0; i < SeNum; ++i) { + if (ttBuf_[i]) { + free(ttBuf_[i]); + } + } + free(ttBuf_); + } + return OCLTestImp::close(); +} diff --git a/opencl/tests/ocltst/module/runtime/OCLThreadTrace.h b/opencl/tests/ocltst/module/runtime/OCLThreadTrace.h new file mode 100644 index 0000000000..2d018d7574 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLThreadTrace.h @@ -0,0 +1,71 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_THREAD_TRACE_H_ +#define _OCL_THREAD_TRACE_H_ + +#include "OCLTestImp.h" +#include "cl_thread_trace_amd.h" + +// Thread Trace API +typedef CL_API_ENTRY cl_threadtrace_amd( + CL_API_CALL *fnp_clCreateThreadTraceAMD)(cl_device_id, cl_int *); +typedef CL_API_ENTRY cl_int(CL_API_CALL *fnp_clReleaseThreadTraceAMD)( + cl_threadtrace_amd); +typedef CL_API_ENTRY cl_int(CL_API_CALL *fnp_clRetainThreadTraceAMD)( + cl_threadtrace_amd); +typedef CL_API_ENTRY cl_int(CL_API_CALL *fnp_clGetThreadTraceInfoAMD)( + cl_threadtrace_amd, cl_threadtrace_info, size_t, void *, size_t *); +typedef CL_API_ENTRY cl_int(CL_API_CALL *fnp_clSetThreadTraceParamAMD)( + cl_threadtrace_amd, cl_thread_trace_param, cl_uint); +typedef CL_API_ENTRY cl_int(CL_API_CALL *fnp_clEnqueueThreadTraceCommandAMD)( + cl_command_queue, cl_threadtrace_amd, cl_threadtrace_command_name_amd, + cl_uint, const cl_event *, cl_event *); +typedef CL_API_ENTRY cl_int(CL_API_CALL *fnp_clEnqueueBindThreadTraceBufferAMD)( + cl_command_queue, cl_threadtrace_amd, cl_mem *, cl_uint, cl_uint, cl_uint, + const cl_event *, cl_event *); + +class OCLThreadTrace : public OCLTestImp { + public: + OCLThreadTrace(); + virtual ~OCLThreadTrace(); + + public: + virtual void open(unsigned int test, char *units, double &conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; + cl_uint **ioBuf_; + cl_uint **ttBuf_; + cl_threadtrace_amd threadTrace_; + + fnp_clCreateThreadTraceAMD clCreateThreadTraceAMD_; + fnp_clReleaseThreadTraceAMD clReleaseThreadTraceAMD_; + fnp_clRetainThreadTraceAMD clRetainThreadTraceAMD_; + fnp_clGetThreadTraceInfoAMD clGetThreadTraceInfoAMD_; + fnp_clSetThreadTraceParamAMD clSetThreadTraceParamAMD_; + fnp_clEnqueueThreadTraceCommandAMD clEnqueueThreadTraceCommandAMD_; + fnp_clEnqueueBindThreadTraceBufferAMD clEnqueueBindThreadTraceBufferAMD_; +}; + +#endif // _OCL_THREAD_TRACE_H_ diff --git a/opencl/tests/ocltst/module/runtime/OCLUnalignedCopy.cpp b/opencl/tests/ocltst/module/runtime/OCLUnalignedCopy.cpp new file mode 100644 index 0000000000..ca56b76328 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLUnalignedCopy.cpp @@ -0,0 +1,127 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLUnalignedCopy.h" + +#include +#include +#include +#include + +#include "CL/cl.h" +#include "CL/cl_ext.h" + +static const int BufSize = 64; + +OCLUnalignedCopy::OCLUnalignedCopy() { + _numSubTests = 1; + failed_ = false; +} + +OCLUnalignedCopy::~OCLUnalignedCopy() {} + +void OCLUnalignedCopy::open(unsigned int test, char* units, double& conversion, + unsigned int deviceId) { + _deviceId = deviceId; + OCLTestImp::open(test, units, conversion, deviceId); + CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test"); + + cl_device_type deviceType; + error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, + sizeof(deviceType), &deviceType, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed"); + + if (!(deviceType & CL_DEVICE_TYPE_GPU)) { + printf("GPU device is required for this test!\n"); + failed_ = true; + return; + } + cl_mem buffer; + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY, + BufSize * sizeof(cl_int4), NULL, &error_); + CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed"); + buffers_.push_back(buffer); + + buffer = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, + BufSize * sizeof(cl_int4), NULL, &error_); + buffers_.push_back(buffer); +} + +static void CL_CALLBACK notify_callback(const char* errinfo, + const void* private_info, size_t cb, + void* user_data) {} + +void OCLUnalignedCopy::run(void) { + if (failed_) { + return; + } + + char* values = new char[BufSize]; + char* results = new char[BufSize]; + + for (int i = 0; i < BufSize; ++i) { + values[i] = i; + } + + static const char TestCnt = 7; + char sizes[TestCnt][3] = { + {5, 7, 13}, {5, 7, 12}, {4, 9, 12}, {4, 9, 15}, + {27, 16, 15}, {27, 16, 13}, {32, 16, 13}, + }; + + for (int i = 0; i < TestCnt; ++i) { + error_ = _wrapper->clEnqueueWriteBuffer(cmdQueues_[_deviceId], buffers_[0], + CL_FALSE, 0, BufSize, values, 0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed"); + + cl_uint pattern = 0; + error_ = /*_wrapper->*/ clEnqueueFillBuffer( + cmdQueues_[_deviceId], buffers_[1], &pattern, sizeof(pattern), 0, + BufSize, 0, NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueFillBuffer() failed"); + + error_ = _wrapper->clEnqueueCopyBuffer( + cmdQueues_[_deviceId], buffers_[0], buffers_[1], sizes[i][0], + sizes[i][1], sizes[i][2], 0, NULL, NULL); + CHECK_RESULT(error_, "clEnqueueCopyBuffer failed"); + + error_ = _wrapper->clEnqueueReadBuffer(cmdQueues_[_deviceId], buffers_[1], + CL_TRUE, 0, BufSize, results, 0, + NULL, NULL); + CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); + + for (int j = 0; j < sizes[i][1]; ++j) { + CHECK_RESULT(results[j] != 0, "Comparison failed"); + } + for (int j = sizes[i][1], k = 0; j < (sizes[i][1] + sizes[i][2]); + ++j, ++k) { + CHECK_RESULT(results[j] != sizes[i][0] + k, "Comparison failed"); + } + for (int j = (sizes[i][1] + sizes[i][2]); j < BufSize; ++j) { + CHECK_RESULT(results[j] != 0, "Comparison failed"); + } + } + + delete[] values; + delete[] results; +} + +unsigned int OCLUnalignedCopy::close(void) { return OCLTestImp::close(); } diff --git a/opencl/tests/ocltst/module/runtime/OCLUnalignedCopy.h b/opencl/tests/ocltst/module/runtime/OCLUnalignedCopy.h new file mode 100644 index 0000000000..2bac8b9e50 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/OCLUnalignedCopy.h @@ -0,0 +1,41 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#ifndef _OCL_UNALIGNED_COPY_H_ +#define _OCL_UNALIGNED_COPY_H_ + +#include "OCLTestImp.h" + +class OCLUnalignedCopy : public OCLTestImp { + public: + OCLUnalignedCopy(); + virtual ~OCLUnalignedCopy(); + + public: + virtual void open(unsigned int test, char* units, double& conversion, + unsigned int deviceID); + virtual void run(void); + virtual unsigned int close(void); + + private: + bool failed_; +}; + +#endif // _OCL_UNALIGNED_COPY_H_ diff --git a/opencl/tests/ocltst/module/runtime/TestList.cpp b/opencl/tests/ocltst/module/runtime/TestList.cpp new file mode 100644 index 0000000000..7830c26a47 --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/TestList.cpp @@ -0,0 +1,127 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "OCLTestListImp.h" + +// +// Includes for tests +// +#include "OCLAsyncMap.h" +#include "OCLAsyncTransfer.h" +#include "OCLAtomicCounter.h" +#include "OCLBlitKernel.h" +#include "OCLBufferFromImage.h" +#include "OCLCPUGuardPages.h" +#include "OCLCreateBuffer.h" +#include "OCLCreateContext.h" +#include "OCLCreateImage.h" +#include "OCLDeviceAtomic.h" +#include "OCLDeviceQueries.h" +#include "OCLDynamic.h" +#include "OCLDynamicBLines.h" +#include "OCLGenericAddressSpace.h" +#include "OCLGetQueueThreadID.h" +#include "OCLGlobalOffset.h" +#include "OCLImage2DFromBuffer.h" +#include "OCLImageCopyPartial.h" +#include "OCLKernelBinary.h" +#include "OCLLDS32K.h" +#include "OCLLinearFilter.h" +#include "OCLMapCount.h" +#include "OCLMemDependency.h" +#include "OCLMemObjs.h" +#include "OCLMemoryInfo.h" +#include "OCLMultiQueue.h" +#include "OCLOfflineCompilation.h" +#include "OCLP2PBuffer.h" +#include "OCLPartialWrkgrp.h" +#include "OCLPerfCounters.h" +#include "OCLPersistent.h" +#include "OCLPinnedMemory.h" +#include "OCLPlatformAtomics.h" +#include "OCLProgramScopeVariables.h" +#include "OCLRTQueue.h" +#include "OCLReadWriteImage.h" +#include "OCLSDI.h" +#include "OCLSVM.h" +#include "OCLSemaphore.h" +#include "OCLStablePState.h" +#include "OCLThreadTrace.h" +#include "OCLUnalignedCopy.h" + +// +// Helper macro for adding tests +// +template +static void* dictionary_CreateTestFunc(void) { + return new T(); +} + +#define TEST(name) \ + { #name, &dictionary_CreateTestFunc < name> } + +TestEntry TestList[] = { + TEST(OCLCreateContext), + TEST(OCLAtomicCounter), + TEST(OCLKernelBinary), + TEST(OCLGlobalOffset), + TEST(OCLLinearFilter), + TEST(OCLAsyncTransfer), + TEST(OCLLDS32K), + TEST(OCLMemObjs), + TEST(OCLSemaphore), + TEST(OCLPartialWrkgrp), + TEST(OCLCreateBuffer), + TEST(OCLCreateImage), + TEST(OCLCPUGuardPages), + TEST(OCLMapCount), + TEST(OCLMemoryInfo), + TEST(OCLOfflineCompilation), + TEST(OCLMemDependency), + TEST(OCLGetQueueThreadID), + TEST(OCLDeviceQueries), + TEST(OCLSDI), + TEST(OCLThreadTrace), + TEST(OCLMultiQueue), + TEST(OCLImage2DFromBuffer), + TEST(OCLBufferFromImage), + TEST(OCLPerfCounters), + TEST(OCLSVM), + TEST(OCLProgramScopeVariables), + TEST(OCLGenericAddressSpace), + TEST(OCLDynamic), + TEST(OCLPlatformAtomics), + TEST(OCLDeviceAtomic), + TEST(OCLDynamicBLines), + TEST(OCLUnalignedCopy), + TEST(OCLBlitKernel), + TEST(OCLRTQueue), + TEST(OCLAsyncMap), + TEST(OCLPinnedMemory), + TEST(OCLReadWriteImage), + TEST(OCLStablePState), + TEST(OCLP2PBuffer), + // Failures in Linux. IOL doesn't support tiling aperture and Cypress linear + // image writes TEST(OCLPersistent), +}; + +unsigned int TestListCount = sizeof(TestList) / sizeof(TestList[0]); +unsigned int TestLibVersion = 0; +const char* TestLibName = "oclruntime"; diff --git a/opencl/tests/ocltst/module/runtime/oclruntime.exclude b/opencl/tests/ocltst/module/runtime/oclruntime.exclude new file mode 100644 index 0000000000..c39d8bb3cd --- /dev/null +++ b/opencl/tests/ocltst/module/runtime/oclruntime.exclude @@ -0,0 +1,11 @@ +# all clear +OCLImageCopyPartial + +# EPR 362715 +OCLCPUGuardPages + +OCLRegionDeviceQueries + +OCLDynamicBLines + +OCLAtomicCounter diff --git a/opencl/tools/clinfo/CMakeLists.txt b/opencl/tools/clinfo/CMakeLists.txt new file mode 100644 index 0000000000..217f18225b --- /dev/null +++ b/opencl/tools/clinfo/CMakeLists.txt @@ -0,0 +1,10 @@ +add_executable(clinfo clinfo.cpp) + +target_compile_definitions(clinfo PRIVATE CL_TARGET_OPENCL_VERSION=220 HAVE_CL2_HPP) + +target_include_directories(clinfo PRIVATE ${OPENCL_ICD_LOADER_HEADERS_DIR}) + +target_link_libraries(clinfo OpenCL) + +INSTALL(TARGETS clinfo + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/opencl/tools/clinfo/clinfo.cpp b/opencl/tools/clinfo/clinfo.cpp new file mode 100644 index 0000000000..5e1bc59907 --- /dev/null +++ b/opencl/tools/clinfo/clinfo.cpp @@ -0,0 +1,761 @@ +/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include +#include +#include +#include +#include +#include +#include +#if !defined(_WIN32) +#include +#endif + +#ifdef _MSC_VER +#pragma warning(disable: 4290) +#endif + +#if defined(HAVE_CL2_HPP) +#define CL_HPP_ENABLE_EXCEPTIONS +#define CL_HPP_MINIMUM_OPENCL_VERSION 120 +#define CL_HPP_TARGET_OPENCL_VERSION 200 +#define CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY +#include "CL/cl2.hpp" +#else // !HAVE_CL2_HPP +#define __CL_ENABLE_EXCEPTIONS +#define __MAX_DEFAULT_VECTOR_SIZE 50 +#define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#define CL_USE_DEPRECATED_OPENCL_2_0_APIS +#include "CL/cl.hpp" +#endif // !HAVE_CL2_HPP + +bool verbose = false; + +/// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure. +int +main(int argc, char** argv) +{ + /* Error flag */ + cl_int err; + + //parse input + for(int i = 1; i < argc; i++){ + if ((strcmp(argv[i], "-v") == 0) || + (strcmp(argv[i], "--verbose") == 0)){ + verbose = true; + } else if ((strcmp(argv[i], "-h") == 0) || + (strcmp(argv[i], "--help") == 0)){ + std::cout << "Usage is: " << argv[0] << " [-v|--verbose]" << std::endl; + return EXIT_FAILURE; + } + } + + // Platform info + std::vector platforms; + + try { + err = cl::Platform::get(&platforms); + + // Iteratate over platforms + std::cout << "Number of platforms:\t\t\t\t " + << platforms.size() + << std::endl; + for (std::vector::iterator i = platforms.begin(); + i != platforms.end(); + ++i) { + const cl::Platform& platform = *i; + + std::cout << " Platform Profile:\t\t\t\t " + << platform.getInfo().c_str() + << std::endl; + std::cout << " Platform Version:\t\t\t\t " + << platform.getInfo().c_str() + << std::endl; + std::cout << " Platform Name:\t\t\t\t " + << platform.getInfo().c_str() + << std::endl; + std::cout << " Platform Vendor:\t\t\t\t " + << platform.getInfo().c_str() << std::endl; + if (platform.getInfo().size() > 0) { + std::cout << " Platform Extensions:\t\t\t\t " + << platform.getInfo().c_str() + << std::endl; + } + } + + std::cout << std::endl << std:: endl; + // Now Iteratate over each platform and its devices + for (std::vector::iterator p = platforms.begin(); + p != platforms.end(); + ++p) { + const cl::Platform& platform = *p; + std::cout << " Platform Name:\t\t\t\t " + << platform.getInfo().c_str() + << std::endl; + + std::vector devices; + platform.getDevices(CL_DEVICE_TYPE_ALL, &devices); + + // Get OpenCL version + std::string platformVersionStr = platform.getInfo(); + std::string openclVerstionStr(platformVersionStr.c_str()); + size_t vStart = openclVerstionStr.find(" ", 0); + size_t vEnd = openclVerstionStr.find(" ", vStart + 1); + std::string vStrVal = openclVerstionStr.substr(vStart + 1, vEnd - vStart - 1); + + std::cout << "Number of devices:\t\t\t\t " << devices.size() << std::endl; + for (std::vector::iterator i = devices.begin(); + i != devices.end(); + ++i) { + const cl::Device& device = *i; + /* Get device name */ + std::string deviceName = device.getInfo(); + cl_device_type dtype = device.getInfo(); + + /* Get CAL driver version in int */ + std::string driverVersion = device.getInfo(); + std::string calVersion(driverVersion.c_str()); + calVersion = calVersion.substr(calVersion.find_last_of(".") + 1); + int version = atoi(calVersion.c_str()); + + std::cout << " Device Type:\t\t\t\t\t " ; + switch (dtype) { + case CL_DEVICE_TYPE_ACCELERATOR: + std::cout << "CL_DEVICE_TYPE_ACCRLERATOR" << std::endl; + break; + case CL_DEVICE_TYPE_CPU: + std::cout << "CL_DEVICE_TYPE_CPU" << std::endl; + break; + case CL_DEVICE_TYPE_DEFAULT: + std::cout << "CL_DEVICE_TYPE_DEFAULT" << std::endl; + break; + case CL_DEVICE_TYPE_GPU: + std::cout << "CL_DEVICE_TYPE_GPU" << std::endl; + break; + } + + std::cout << " Vendor ID:\t\t\t\t\t " + << std::hex + << device.getInfo() + << "h" + << std::dec + << std::endl; + + bool isAMDPlatform = (strcmp(platform.getInfo().c_str(), "AMD Accelerated Parallel Processing") == 0) ? true : false; + if (isAMDPlatform) + { + std::string boardName; + device.getInfo(CL_DEVICE_BOARD_NAME_AMD, &boardName); + std::cout << " Board name:\t\t\t\t\t " + << boardName.c_str() + << std::endl; + + cl_device_topology_amd topology; + err = device.getInfo(CL_DEVICE_TOPOLOGY_AMD, &topology); + if (topology.raw.type == CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD) { + std::cout << " Device Topology:\t\t\t\t " + << "PCI[ B#" << (int)topology.pcie.bus + << ", D#" << (int)topology.pcie.device + << ", F#" << (int)topology.pcie.function + << " ]" << std::endl; + } + } + + std::cout << " Max compute units:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max work items dimensions:\t\t\t " + << device.getInfo() + << std::endl; + + std::vector< ::size_t> witems = + device.getInfo(); + for (unsigned int x = 0; + x < device.getInfo(); + x++) { + std::cout << " Max work items[" + << x << "]:\t\t\t\t " + << witems[x] + << std::endl; + } + + std::cout << " Max work group size:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Preferred vector width char:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Preferred vector width short:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Preferred vector width int:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Preferred vector width long:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Preferred vector width float:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Preferred vector width double:\t\t " + << device.getInfo() + << std::endl; + +#ifdef CL_VERSION_1_1 + if(vStrVal.compare("1.0") > 0) + { + std::cout << " Native vector width char:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Native vector width short:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Native vector width int:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Native vector width long:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Native vector width float:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Native vector width double:\t\t\t " + << device.getInfo() + << std::endl; + } +#endif // CL_VERSION_1_1 + std::cout << " Max clock frequency:\t\t\t\t " + << device.getInfo() + << "Mhz" + << std::endl; + + std::cout << " Address bits:\t\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max memory allocation:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Image support:\t\t\t\t " + << (device.getInfo() ? "Yes" : "No") + << std::endl; + + if (device.getInfo()) + { + + std::cout << " Max number of images read arguments:\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max number of images write arguments:\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max image 2D width:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max image 2D height:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max image 3D width:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max image 3D height:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max image 3D depth:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max samplers within kernel:\t\t\t " + << device.getInfo() + << std::endl; + + if (verbose) + { + std::cout << " Image formats supported:" << std::endl; + std::vector formats; + + cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)(*p)(), 0 }; + std::vector device; + device.push_back(*i); + cl::Context context(device, cps, NULL, NULL, &err); + + std::map channelOrder; + channelOrder[CL_R] = "CL_R"; + channelOrder[CL_A] = "CL_A"; + channelOrder[CL_RG] = "CL_RG"; + channelOrder[CL_RA] = "CL_RA"; + channelOrder[CL_RGB] = "CL_RGB"; + channelOrder[CL_RGBA] = "CL_RGBA"; + channelOrder[CL_BGRA] = "CL_BGRA"; + channelOrder[CL_ARGB] = "CL_ARGB"; + channelOrder[CL_INTENSITY] = "CL_INTENSITY"; + channelOrder[CL_LUMINANCE] = "CL_LUMINANCE"; + channelOrder[CL_Rx] = "CL_Rx"; + channelOrder[CL_RGx] = "CL_RGx"; + channelOrder[CL_RGBx] = "CL_RGBx"; + + std::map > channelType; + channelType[CL_SNORM_INT8] = std::make_pair("snorm", "int8"); + channelType[CL_SNORM_INT16] = std::make_pair("snorm", "int16"); + channelType[CL_UNORM_INT8] = std::make_pair("unorm", "int8"); + channelType[CL_UNORM_INT16] = std::make_pair("unorm", "int16"); + channelType[CL_UNORM_SHORT_565] = std::make_pair("unorm", "short_565"); + channelType[CL_UNORM_SHORT_555] = std::make_pair("unorm", "short_555"); + channelType[CL_UNORM_INT_101010] = std::make_pair("unorm", "int_101010"); + channelType[CL_SIGNED_INT8] = std::make_pair("signed", "int8"); + channelType[CL_SIGNED_INT16] = std::make_pair("signed", "int16"); + channelType[CL_SIGNED_INT32] = std::make_pair("signed", "int32"); + channelType[CL_UNSIGNED_INT8] = std::make_pair("unsigned", "int8"); + channelType[CL_UNSIGNED_INT16] = std::make_pair("unsigned", "int16"); + channelType[CL_UNSIGNED_INT32] = std::make_pair("unsigned", "int32"); + channelType[CL_HALF_FLOAT] = std::make_pair("half_float", ""); + channelType[CL_FLOAT] = std::make_pair("float", ""); + + std::vector > imageDimensions; + imageDimensions.push_back(std::make_pair(CL_MEM_OBJECT_IMAGE2D, std::string("2D "))); + imageDimensions.push_back(std::make_pair(CL_MEM_OBJECT_IMAGE3D, std::string("3D "))); + for(std::vector >::iterator id = imageDimensions.begin(); + id != imageDimensions.end(); + id++){ + + struct imageAccessStruct { + std::string name; + int access; + std::vector formats; + } imageAccess[] = {{std::string("Read-Write/Read-Only/Write-Only"), CL_MEM_READ_WRITE, std::vector()}, + {std::string("Read-Only"), CL_MEM_READ_ONLY, std::vector()}, + {std::string("Write-Only"), CL_MEM_WRITE_ONLY, std::vector()}}; + + for(size_t ia=0; ia < sizeof(imageAccess)/sizeof(imageAccessStruct); ia++){ + context.getSupportedImageFormats(imageAccess[ia].access, (*id).first, &(imageAccess[ia].formats)); + bool printTopHeader = true; + for (std::map::iterator o = channelOrder.begin(); + o != channelOrder.end(); + o++) + { + bool printHeader = true; + + for (std::vector::iterator it = imageAccess[ia].formats.begin(); + it != imageAccess[ia].formats.end(); + ++it) + { + if ( (*o).first == (int)(*it).image_channel_order) + { + bool printedAlready = false; + //see if this was already print in RW/RO/WO + if (ia !=0) + { + for (std::vector::iterator searchIt = imageAccess[0].formats.begin(); + searchIt != imageAccess[0].formats.end(); + searchIt++) + { + if ( ((*searchIt).image_channel_data_type == (*it).image_channel_data_type) && + ((*searchIt).image_channel_order == (*it).image_channel_order)) + { + printedAlready = true; + break; + } + } + } + if (printedAlready) + { + continue; + } + if (printTopHeader) + { + std::cout << " " << (*id).second << imageAccess[ia].name << std::endl; + printTopHeader = false; + } + if (printHeader) + { + std::cout << " " << (*o).second << ": "; + printHeader = false; + } + std::cout << channelType[(*it).image_channel_data_type].first; + if (channelType[(*it).image_channel_data_type].second != "") + { + std::cout << "-" + << channelType[(*it).image_channel_data_type].second; + } + if (it != (imageAccess[ia].formats.end() - 1)) + { + std::cout << " "; + } + } + } + if (printHeader == false) + { + std::cout << std::endl; + } + } + } + } + } + } + + std::cout << " Max size of kernel argument:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Alignment (bits) of base address:\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Minimum alignment (bytes) for any datatype:\t " + << device.getInfo() + << std::endl; + + std::cout << " Single precision floating point capability" << std::endl; + std::cout << " Denorms:\t\t\t\t\t " + << (device.getInfo() & + CL_FP_DENORM ? "Yes" : "No") + << std::endl; + std::cout << " Quiet NaNs:\t\t\t\t\t " + << (device.getInfo() & + CL_FP_INF_NAN ? "Yes" : "No") + << std::endl; + std::cout << " Round to nearest even:\t\t\t " + << (device.getInfo() & + CL_FP_ROUND_TO_NEAREST ? "Yes" : "No") + << std::endl; + std::cout << " Round to zero:\t\t\t\t " + << (device.getInfo() & + CL_FP_ROUND_TO_ZERO ? "Yes" : "No") + << std::endl; + std::cout << " Round to +ve and infinity:\t\t\t " + << (device.getInfo() & + CL_FP_ROUND_TO_INF ? "Yes" : "No") + << std::endl; + std::cout << " IEEE754-2008 fused multiply-add:\t\t " + << (device.getInfo() & + CL_FP_FMA ? "Yes" : "No") + << std::endl; + + std::cout << " Cache type:\t\t\t\t\t " ; + switch (device.getInfo()) { + case CL_NONE: + std::cout << "None" << std::endl; + break; + case CL_READ_ONLY_CACHE: + std::cout << "Read only" << std::endl; + break; + case CL_READ_WRITE_CACHE: + std::cout << "Read/Write" << std::endl; + break; + } + + std::cout << " Cache line size:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Cache size:\t\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Global memory size:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Constant buffer size:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max number of constant args:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Local memory type:\t\t\t\t " ; + switch (device.getInfo()) { + case CL_LOCAL: + std::cout << "Scratchpad" << std::endl; + break; + case CL_GLOBAL: + std::cout << "Global" << std::endl; + break; + } + + + std::cout << " Local memory size:\t\t\t\t " + << device.getInfo() + << std::endl; + +#if defined(CL_VERSION_2_0) + if(vStrVal.compare("2") > 0) + { + std::cout << " Max pipe arguments:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max pipe active reservations:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max pipe packet size:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max global variable size:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max global variable preferred total size:\t " + << device.getInfo() + << std::endl; + + std::cout << " Max read/write image args:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max on device events:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Queue on device max size:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Max on device queues:\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Queue on device preferred size:\t\t " + << device.getInfo() + << std::endl; + + std::cout << " SVM capabilities:\t\t\t\t " << std::endl; + std::cout << " Coarse grain buffer:\t\t\t " + << (device.getInfo() & + CL_DEVICE_SVM_COARSE_GRAIN_BUFFER ? "Yes" : "No") + << std::endl; + std::cout << " Fine grain buffer:\t\t\t\t " + << (device.getInfo() & + CL_DEVICE_SVM_FINE_GRAIN_BUFFER ? "Yes" : "No") + << std::endl; + std::cout << " Fine grain system:\t\t\t\t " + << (device.getInfo() & + CL_DEVICE_SVM_FINE_GRAIN_SYSTEM ? "Yes" : "No") + << std::endl; + std::cout << " Atomics:\t\t\t\t\t " + << (device.getInfo() & + CL_DEVICE_SVM_ATOMICS ? "Yes" : "No") + << std::endl; + + std::cout << " Preferred platform atomic alignment:\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Preferred global atomic alignment:\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Preferred local atomic alignment:\t\t " + << device.getInfo() + << std::endl; + } +#endif // CL_VERSION_2_0 + +#if defined(CL_VERSION_1_1) && !defined(ATI_ARCH_ARM) + if(vStrVal.compare("1.0") > 0) + { + cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)(*p)(), 0 }; + + std::vector device; + device.push_back(*i); + + cl::Context context(device, cps, NULL, NULL, &err); + if (err != CL_SUCCESS) { + std::cerr << "Context::Context() failed (" << err << ")\n"; + return EXIT_FAILURE; + } + std::string kernelStr("__kernel void hello(){ size_t i = get_global_id(0); size_t j = get_global_id(1);}"); + cl::Program::Sources sources(1, std::make_pair(kernelStr.data(), kernelStr.size())); + + cl::Program program = cl::Program(context, sources, &err); + if (err != CL_SUCCESS) { + std::cerr << "Program::Program() failed (" << err << ")\n"; + return EXIT_FAILURE; + } + + err = program.build(device); + if (err != CL_SUCCESS) { + + if(err == CL_BUILD_PROGRAM_FAILURE) + { + std::string str = program.getBuildInfo((*i)); + + std::cout << " \n\t\t\tBUILD LOG\n"; + std::cout << " ************************************************\n"; + std::cout << str.c_str() << std::endl; + std::cout << " ************************************************\n"; + } + + std::cerr << "Program::build() failed (" << err << ")\n"; + return EXIT_FAILURE; + } + + cl::Kernel kernel(program, "hello", &err); + if (err != CL_SUCCESS) { + std::cerr << "Kernel::Kernel() failed (" << err << ")\n"; + return EXIT_FAILURE; + } + + std::cout << " Kernel Preferred work group size multiple:\t " + << kernel.getWorkGroupInfo((*i), &err) + << std::endl; + } + +#endif // CL_VERSION_1_1 + + std::cout << " Error correction support:\t\t\t " + << device.getInfo() + << std::endl; +#ifdef CL_VERSION_1_1 + if(vStrVal.compare("1.0") > 0) + { + std::cout << " Unified memory for Host and Device:\t\t " + << device.getInfo() + << std::endl; + } +#endif // CL_VERSION_1_1 + std::cout << " Profiling timer resolution:\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Device endianess:\t\t\t\t " + << (device.getInfo() ? "Little" : "Big") + << std::endl; + + std::cout << " Available:\t\t\t\t\t " + << (device.getInfo() ? "Yes" : "No") + << std::endl; + + std::cout << " Compiler available:\t\t\t\t " + << (device.getInfo() ? "Yes" : "No") + << std::endl; + + std::cout << " Execution capabilities:\t\t\t\t " << std::endl; + std::cout << " Execute OpenCL kernels:\t\t\t " + << (device.getInfo() & + CL_EXEC_KERNEL ? "Yes" : "No") + << std::endl; + std::cout << " Execute native function:\t\t\t " + << (device.getInfo() & + CL_EXEC_NATIVE_KERNEL ? "Yes" : "No") + << std::endl; + + std::cout << " Queue on Host properties:\t\t\t\t " << std::endl; + std::cout << " Out-of-Order:\t\t\t\t " + << (device.getInfo() & + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE ? "Yes" : "No") + << std::endl; + std::cout << " Profiling :\t\t\t\t\t " + << (device.getInfo() & + CL_QUEUE_PROFILING_ENABLE ? "Yes" : "No") + << std::endl; + +#ifdef CL_VERSION_2_0 + if(vStrVal.compare("2") > 0) + { + std::cout << " Queue on Device properties:\t\t\t\t " << std::endl; + std::cout << " Out-of-Order:\t\t\t\t " + << (device.getInfo() & + CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE ? "Yes" : "No") + << std::endl; + std::cout << " Profiling :\t\t\t\t\t " + << (device.getInfo() & + CL_QUEUE_PROFILING_ENABLE ? "Yes" : "No") + << std::endl; + } +#endif + + std::cout << " Platform ID:\t\t\t\t\t " + << device.getInfo() + << std::endl; + + std::cout << " Name:\t\t\t\t\t\t " + << device.getInfo().c_str() + << std::endl; + + std::cout << " Vendor:\t\t\t\t\t " + << device.getInfo().c_str() + << std::endl; +#ifdef CL_VERSION_1_1 + if(vStrVal.compare("1.0") > 0) + { + std::cout << " Device OpenCL C version:\t\t\t " + << device.getInfo().c_str() + << std::endl; + } +#endif // CL_VERSION_1_1 + std::cout << " Driver version:\t\t\t\t " + << device.getInfo().c_str() + << std::endl; + + std::cout << " Profile:\t\t\t\t\t " + << device.getInfo().c_str() + << std::endl; + + std::cout << " Version:\t\t\t\t\t " + << device.getInfo().c_str() + << std::endl; + + + std::cout << " Extensions:\t\t\t\t\t " + << device.getInfo().c_str() + << std::endl; + + std::cout << std::endl << std::endl; + } + } + } + catch (cl::Error err) + { + std::cerr + << "ERROR: " + << err.what() + << "(" + << err.err() + << ")" + << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/opencl/tools/cltrace/CMakeLists.txt b/opencl/tools/cltrace/CMakeLists.txt new file mode 100644 index 0000000000..263f9ae289 --- /dev/null +++ b/opencl/tools/cltrace/CMakeLists.txt @@ -0,0 +1,15 @@ +add_library(cltrace SHARED cltrace.cpp) + +if(WIN32) + target_sources(cltrace PRIVATE cltrace.def) +else() + target_link_libraries(cltrace PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/cltrace.map") + set_target_properties(cltrace PROPERTIES LINK_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/cltrace.map") +endif() + +target_include_directories(cltrace PRIVATE ${CMAKE_SOURCE_DIR} ${OPENCL_ICD_LOADER_HEADERS_DIR} ${ROCCLR_INCLUDE_DIR}) + +INSTALL(TARGETS cltrace + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/opencl/tools/cltrace/cltrace.cpp b/opencl/tools/cltrace/cltrace.cpp new file mode 100644 index 0000000000..5ac5b62738 --- /dev/null +++ b/opencl/tools/cltrace/cltrace.cpp @@ -0,0 +1,4441 @@ +// +// Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc. All rights reserved. +// + +#include +#include + +#if defined(CL_VERSION_2_0) +/* Deprecated in OpenCL 2.0 */ +# define CL_DEVICE_QUEUE_PROPERTIES 0x102A +# define CL_DEVICE_HOST_UNIFIED_MEMORY 0x1035 +#endif + +#include +#include +#include +#include +#include +#include +#include + +#ifdef _MSC_VER +#include +#include +#include +#else +#include +#include +#endif + +#define CASE(x) case x: return #x; + +std::ofstream clTraceLog; +std::streambuf *cerrStreamBufSave; + +// A call record with links for the checker +struct Rec { + Rec *next; + Rec *prev; + std::ostringstream *sp; + int visits; + + Rec() : sp(0) { } + Rec(std::ostringstream *ps) : sp(ps), visits(0) { } +}; + +// This is the head of the checker Rec list +static Rec recs; + +// About how many times per second the checker runs +static const int checks_per_second = 10; + +// Some OS independent synchronization for the checker Rec list +#ifdef _MSC_VER +#define CHECKERTYPE static void +#define CHECKERRETURN return +static CRITICAL_SECTION recsCS[1]; + +static inline void +initRecs(void) +{ + InitializeCriticalSection(recsCS); + recs.next = &recs; + recs.prev = &recs; +} + +static inline void +lockRecs(void) +{ + EnterCriticalSection(recsCS); +} + +static inline void +unlockRecs(void) +{ + LeaveCriticalSection(recsCS); +} + +static inline void +waitRecs(void) +{ + Sleep(1000/checks_per_second); +} +#else +#define CHECKERTYPE static void * +#define CHECKERRETURN return NULL +static pthread_mutex_t recsMtx = PTHREAD_MUTEX_INITIALIZER; + +static inline void +initRecs(void) +{ + recs.next = &recs; + recs.prev = &recs; +} + +static inline void +lockRecs(void) +{ + pthread_mutex_lock(&recsMtx); +} + +static inline void +unlockRecs(void) +{ + pthread_mutex_unlock(&recsMtx); +} + +static inline void +waitRecs(void) +{ + usleep(1000000/checks_per_second); +} +#endif + +// Link into checker Rec list +static inline void +addRec(Rec *r) +{ + lockRecs(); + r->next = recs.next; + r->prev = &recs; + recs.next->prev = r; + recs.next = r; + unlockRecs(); +} + +// unlink from checker Rec list +static inline void +delRec(Rec *r) +{ + lockRecs(); + r->next->prev = r->prev; + r->prev->next = r->next; + unlockRecs(); +} + +// This is the checker thread function +CHECKERTYPE +checker(void *) +{ + Rec *b; + Rec *e = &recs; + + for (;;) { + // Wait for a while + waitRecs(); + + std::ostringstream ss; + int go = 0; + + lockRecs(); + for (b=recs.next; b!=e; b=b->next) { + ++b->visits; + if (b->visits == 2) { + // This record has been on the list for a while + // we'll log it in case the thread has hung + ss << "Waiting for " << b->sp->str() << std::endl; + go = 1; + } + } + unlockRecs(); + + if (go) + std::cerr << ss.str(); + } + CHECKERRETURN; +} + +#ifdef _MSC_VER +static cl_int +startChecker(void) +{ + uintptr_t h = _beginthread(checker, 0, NULL); + return h == 0; +} +#else +static cl_int +startChecker(void) +{ + int e; + pthread_t tid; + pthread_attr_t pa; + + e = pthread_attr_init(&pa); + if (e) return e; + + e = pthread_attr_setdetachstate(&pa, PTHREAD_CREATE_DETACHED); + if (e) return e; + + e = pthread_create(&tid, &pa, checker, NULL); + return e; +} +#endif + +template +std::string +getDecimalString(T value) +{ + std::ostringstream ss; + ss << value; + return ss.str(); +} + +template +std::string +getDecimalString(T* value) +{ + if (value == NULL) { + return "NULL"; + } + + std::ostringstream ss; + ss << '&' << *value; + return ss.str(); +} + +template +std::string +getHexString(T value) +{ + std::ostringstream ss; + ss << "0x" << std::hex << value; + return ss.str(); +} + +template +std::string +getHexString(T* value) +{ + if (value == NULL) { + return "NULL"; + } + + std::ostringstream ss; + ss << "&0x" << std::hex << *value; + return ss.str(); +} + +template +std::string +getHexString(T** value) +{ + if (value == NULL) { + return "NULL"; + } + + std::ostringstream ss; + ss << "&" << *value; + return ss.str(); +} + +template <> +std::string +getHexString(void *value) +{ + return getHexString(reinterpret_cast(value)); +} + +static std::string +getMemoryString(const void* ptr, size_t size) +{ + switch (size) { + case 1: return getHexString((const char*)ptr); + case 2: return getHexString((const short*)ptr); + case 4: return getHexString((const int*)ptr); + case 8: return getHexString((const long long*)ptr); + default: break; + } + std::ostringstream ss; + ss << "&" << ptr; + return ss.str(); +} + +static std::string +getBoolString(cl_bool b) +{ + return (b == CL_TRUE) ? "CL_TRUE" : "CL_FALSE"; +} + +static std::string +getNDimString(const size_t* nd, size_t dims) +{ + if (nd == NULL) { + return "NULL"; + } + if (dims == 0) { + return "[]"; + } + + std::ostringstream ss; + ss << '[' << nd[0]; + if (dims > 1) { + ss << ',' << nd[1]; + if (dims > 2) { + ss << ',' << nd[2]; + } + } + ss << ']'; + return ss.str(); +} + +static std::string +getErrorString(cl_int errcode) +{ + switch(errcode) { + CASE(CL_SUCCESS); + CASE(CL_DEVICE_NOT_FOUND); + CASE(CL_DEVICE_NOT_AVAILABLE); + CASE(CL_COMPILER_NOT_AVAILABLE); + CASE(CL_MEM_OBJECT_ALLOCATION_FAILURE); + CASE(CL_OUT_OF_RESOURCES); + CASE(CL_OUT_OF_HOST_MEMORY); + CASE(CL_PROFILING_INFO_NOT_AVAILABLE); + CASE(CL_MEM_COPY_OVERLAP); + CASE(CL_IMAGE_FORMAT_MISMATCH); + CASE(CL_IMAGE_FORMAT_NOT_SUPPORTED); + CASE(CL_BUILD_PROGRAM_FAILURE); + CASE(CL_MAP_FAILURE); + CASE(CL_MISALIGNED_SUB_BUFFER_OFFSET); + CASE(CL_INVALID_VALUE); + CASE(CL_INVALID_DEVICE_TYPE); + CASE(CL_INVALID_PLATFORM); + CASE(CL_INVALID_DEVICE); + CASE(CL_INVALID_CONTEXT); + CASE(CL_INVALID_QUEUE_PROPERTIES); + CASE(CL_INVALID_COMMAND_QUEUE); + CASE(CL_INVALID_HOST_PTR); + CASE(CL_INVALID_MEM_OBJECT); + CASE(CL_INVALID_IMAGE_FORMAT_DESCRIPTOR); + CASE(CL_INVALID_IMAGE_SIZE); + CASE(CL_INVALID_SAMPLER); + CASE(CL_INVALID_BINARY); + CASE(CL_INVALID_BUILD_OPTIONS); + CASE(CL_INVALID_PROGRAM); + CASE(CL_INVALID_PROGRAM_EXECUTABLE); + CASE(CL_INVALID_KERNEL_NAME); + CASE(CL_INVALID_KERNEL_DEFINITION); + CASE(CL_INVALID_KERNEL); + CASE(CL_INVALID_ARG_INDEX); + CASE(CL_INVALID_ARG_VALUE); + CASE(CL_INVALID_ARG_SIZE); + CASE(CL_INVALID_KERNEL_ARGS); + CASE(CL_INVALID_WORK_DIMENSION); + CASE(CL_INVALID_WORK_GROUP_SIZE); + CASE(CL_INVALID_WORK_ITEM_SIZE); + CASE(CL_INVALID_GLOBAL_OFFSET); + CASE(CL_INVALID_EVENT_WAIT_LIST); + CASE(CL_INVALID_EVENT); + CASE(CL_INVALID_OPERATION); + CASE(CL_INVALID_GL_OBJECT); + CASE(CL_INVALID_BUFFER_SIZE); + CASE(CL_INVALID_MIP_LEVEL); + CASE(CL_INVALID_GLOBAL_WORK_SIZE); + default: return getDecimalString(errcode); + } +} + +static std::string +getMemObjectTypeString(cl_mem_object_type type) +{ + switch(type) { + CASE(CL_MEM_OBJECT_BUFFER); + CASE(CL_MEM_OBJECT_IMAGE2D); + CASE(CL_MEM_OBJECT_IMAGE3D); + default: return getHexString(type); + } +} + +static std::string +getMemInfoString(cl_mem_info param_name) +{ + switch(param_name) { + CASE(CL_MEM_TYPE); + CASE(CL_MEM_FLAGS); + CASE(CL_MEM_SIZE); + CASE(CL_MEM_HOST_PTR); + CASE(CL_MEM_MAP_COUNT); + CASE(CL_MEM_REFERENCE_COUNT); + CASE(CL_MEM_CONTEXT); + CASE(CL_MEM_ASSOCIATED_MEMOBJECT); + CASE(CL_MEM_OFFSET); + default: return getHexString(param_name); + } +} + +static std::string +getImageInfoString(cl_image_info param_name) +{ + switch(param_name) { + CASE(CL_IMAGE_FORMAT); + CASE(CL_IMAGE_ELEMENT_SIZE); + CASE(CL_IMAGE_ROW_PITCH); + CASE(CL_IMAGE_SLICE_PITCH); + CASE(CL_IMAGE_WIDTH); + CASE(CL_IMAGE_HEIGHT); + CASE(CL_IMAGE_DEPTH); + default: return getHexString(param_name); + } +} + +static std::string +getErrorString(cl_int* errcode_ret) +{ + if (errcode_ret == NULL) { + return "NULL"; + } + + std::ostringstream ss; + ss << '&' << getErrorString(*errcode_ret); + return ss.str(); +} + +static std::string +getHandlesString(const void* handles, cl_uint num_handles) +{ + if (handles == NULL) { + return "NULL"; + } + if (num_handles == 0) { + return "[]"; + } + + const cl_event* p = reinterpret_cast(handles); + + std::ostringstream ss; + ss << '['; + while (true) { + ss << *p++; + if (--num_handles == 0) { + break; + } + ss << ','; + } + ss << ']'; + return ss.str(); +} + +static std::string +getContextPropertyString(cl_context_properties cprop) +{ + switch(cprop) { + CASE(CL_CONTEXT_PLATFORM); + default: return getHexString(cprop); + } +} + +static std::string +getContextPropertiesString(const cl_context_properties* cprops) +{ + if (cprops == NULL) { + return "NULL"; + } + + std::ostringstream ss; + ss << '{'; + while (*cprops != 0) { + ss << getContextPropertyString(cprops[0]) + << ',' << getHexString(cprops[1]) << ","; + cprops += 2; + } + ss << "NULL}"; + return ss.str(); +} + +static std::string +getCommandQueuePropertyString(cl_command_queue_properties property) +{ + if (property == 0) { + return "0"; + } + + std::ostringstream ss; + while (property) { + if (property & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) { + ss << "CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE"; + property &= ~CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE; + } + else if (property & CL_QUEUE_PROFILING_ENABLE) { + ss << "CL_QUEUE_PROFILING_ENABLE"; + property &= ~CL_QUEUE_PROFILING_ENABLE; + } + else { + ss << "0x" << std::hex << (int)property; + property = 0; + } + if (property != 0) { + ss << '|'; + } + } + + return ss.str(); +} + +static std::string +getQueuePropertyString(const cl_queue_properties* qprops) +{ + if (qprops == NULL) { + return "NULL"; + } + + std::ostringstream ss; + cl_command_queue_properties property = 0; + unsigned int queueSize = 0; + + const struct QueueProperty { + cl_queue_properties name; + union { + cl_queue_properties raw; + cl_uint size; + } value; + } *p = reinterpret_cast(qprops); + + if (p != NULL) while(p->name != 0) { + switch(p->name) { + case CL_QUEUE_PROPERTIES: + property = static_cast(p->value.raw); + + if (property & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) { + ss << "CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE"; + property &= ~CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE; + } + else if (property & CL_QUEUE_PROFILING_ENABLE) { + ss << "CL_QUEUE_PROFILING_ENABLE"; + property &= ~CL_QUEUE_PROFILING_ENABLE; + } + else { + ss << "0x" << std::hex << (int)property; + property = 0; + } + if (property != 0) { + ss << '|'; + } + break; + case CL_QUEUE_SIZE: // Unimplemented + queueSize = p->value.size; + ss << "QUEUE_SIZE "<origin << ',' << region->size << '}'; + } + else { + ss << getHexString(type) << ',' << info; + } + return ss.str(); +} + +static std::string +getChannelOrderString(cl_channel_order order) +{ + switch(order) { + CASE(CL_R); + CASE(CL_A); + CASE(CL_RG); + CASE(CL_RA); + CASE(CL_RGB); + CASE(CL_RGBA); + CASE(CL_BGRA); + CASE(CL_ARGB); + CASE(CL_INTENSITY); + CASE(CL_LUMINANCE); + CASE(CL_Rx); + CASE(CL_RGx); + CASE(CL_RGBx); + default: return getHexString(order); + } +} + +static std::string +getChannelTypeString(cl_channel_type type) +{ + switch(type) { + CASE(CL_SNORM_INT8); + CASE(CL_SNORM_INT16); + CASE(CL_UNORM_INT8); + CASE(CL_UNORM_INT16); + CASE(CL_UNORM_SHORT_565); + CASE(CL_UNORM_SHORT_555); + CASE(CL_UNORM_INT_101010); + CASE(CL_SIGNED_INT8); + CASE(CL_SIGNED_INT16); + CASE(CL_SIGNED_INT32); + CASE(CL_UNSIGNED_INT8); + CASE(CL_UNSIGNED_INT16); + CASE(CL_UNSIGNED_INT32); + CASE(CL_HALF_FLOAT); + CASE(CL_FLOAT); + default: return getHexString(type); + } +} + +static std::string +getImageFormatsString(const cl_image_format* format, size_t num_entries) +{ + if (format == NULL) { + return "NULL"; + } + + std::ostringstream ss; + ss << '['; + while (true) { + ss << '{' << getChannelOrderString(format->image_channel_order) << ','; + ss << getChannelTypeString(format->image_channel_data_type) << '}'; + if (--num_entries == 0) { + break; + } + ss << ','; + } + ss << ']'; + return ss.str(); +} + +static std::string +getImageDescString(const cl_image_desc* image_desc) +{ + if (image_desc == NULL) { + return "NULL"; + } + + std::ostringstream ss; + ss << '{' << getMemObjectTypeString(image_desc->image_type) << ','; + ss << image_desc->image_width << ','; + ss << image_desc->image_height << ','; + ss << image_desc->image_depth << ','; + ss << image_desc->image_array_size << ','; + ss << image_desc->image_row_pitch << ','; + ss << image_desc->image_slice_pitch << ','; + ss << image_desc->num_mip_levels << ','; + ss << image_desc->num_samples << ','; + ss << image_desc->mem_object << '}'; + return ss.str(); +} + + +static std::string +getAddressingModeString(cl_addressing_mode mode) +{ + switch(mode) { + CASE(CL_ADDRESS_NONE); + CASE(CL_ADDRESS_CLAMP_TO_EDGE); + CASE(CL_ADDRESS_CLAMP); + CASE(CL_ADDRESS_REPEAT); + CASE(CL_ADDRESS_MIRRORED_REPEAT); + default: return getHexString(mode); + } +} + +std::string +getFilterModeString(cl_filter_mode mode) +{ + switch(mode) { + CASE(CL_FILTER_NEAREST); + CASE(CL_FILTER_LINEAR); + default: return getHexString(mode); + } +} + +static std::string +getSamplerInfoString(cl_sampler_info param_name) +{ + switch(param_name) { + CASE(CL_SAMPLER_REFERENCE_COUNT); + CASE(CL_SAMPLER_CONTEXT); + CASE(CL_SAMPLER_NORMALIZED_COORDS); + CASE(CL_SAMPLER_ADDRESSING_MODE); + CASE(CL_SAMPLER_FILTER_MODE); + default: return getHexString(param_name); + } +} + + +std::string +getDeviceTypeString(cl_device_type type) +{ + if (type == CL_DEVICE_TYPE_ALL) { + return "CL_DEVICE_TYPE_ALL"; + } + + std::ostringstream ss; + while (type) { + if (type & CL_DEVICE_TYPE_CPU) { + ss << "CL_DEVICE_TYPE_CPU"; + type &= ~CL_DEVICE_TYPE_CPU; + } + else if (type & CL_DEVICE_TYPE_GPU) { + ss << "CL_DEVICE_TYPE_GPU"; + type &= ~CL_DEVICE_TYPE_GPU; + } + else if (type & CL_DEVICE_TYPE_ACCELERATOR) { + ss << "CL_DEVICE_TYPE_ACCELERATOR"; + type &= ~CL_DEVICE_TYPE_ACCELERATOR; + } + else { + ss << "0x" << std::hex << (int)type; + type = 0; + } + if (type != 0) { + ss << '|'; + } + } + + return ss.str(); +} + +static std::string +getPlatformInfoString(cl_platform_info param_name) +{ + switch (param_name) { + CASE(CL_PLATFORM_PROFILE); + CASE(CL_PLATFORM_VERSION); + CASE(CL_PLATFORM_NAME); + CASE(CL_PLATFORM_VENDOR); + CASE(CL_PLATFORM_EXTENSIONS); + CASE(CL_PLATFORM_ICD_SUFFIX_KHR); + default: return getHexString(param_name); + } +} + + +static std::string +getKernelArgInfoString(cl_kernel_arg_info param_name) +{ + switch (param_name) { + CASE(CL_KERNEL_ARG_ADDRESS_QUALIFIER); + CASE(CL_KERNEL_ARG_ACCESS_QUALIFIER); + CASE(CL_KERNEL_ARG_TYPE_NAME); + CASE(CL_KERNEL_ARG_TYPE_QUALIFIER); + CASE(CL_KERNEL_ARG_NAME); + default: return getHexString(param_name); + } +} + +static std::string +getDeviceInfoString(cl_device_info param_name) +{ + switch (param_name) { + CASE(CL_DEVICE_TYPE); + CASE(CL_DEVICE_VENDOR_ID); + CASE(CL_DEVICE_MAX_COMPUTE_UNITS); + CASE(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS); + CASE(CL_DEVICE_MAX_WORK_GROUP_SIZE); + CASE(CL_DEVICE_MAX_WORK_ITEM_SIZES); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE); + CASE(CL_DEVICE_MAX_CLOCK_FREQUENCY); + CASE(CL_DEVICE_ADDRESS_BITS); + CASE(CL_DEVICE_MAX_READ_IMAGE_ARGS); + CASE(CL_DEVICE_MAX_WRITE_IMAGE_ARGS); + CASE(CL_DEVICE_MAX_MEM_ALLOC_SIZE); + CASE(CL_DEVICE_IMAGE2D_MAX_WIDTH); + CASE(CL_DEVICE_IMAGE2D_MAX_HEIGHT); + CASE(CL_DEVICE_IMAGE3D_MAX_WIDTH); + CASE(CL_DEVICE_IMAGE3D_MAX_HEIGHT); + CASE(CL_DEVICE_IMAGE3D_MAX_DEPTH); + CASE(CL_DEVICE_IMAGE_SUPPORT); + CASE(CL_DEVICE_MAX_PARAMETER_SIZE); + CASE(CL_DEVICE_MAX_SAMPLERS); + CASE(CL_DEVICE_MEM_BASE_ADDR_ALIGN); + CASE(CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE); + CASE(CL_DEVICE_SINGLE_FP_CONFIG); + CASE(CL_DEVICE_GLOBAL_MEM_CACHE_TYPE); + CASE(CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE); + CASE(CL_DEVICE_GLOBAL_MEM_CACHE_SIZE); + CASE(CL_DEVICE_GLOBAL_MEM_SIZE); + CASE(CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE); + CASE(CL_DEVICE_MAX_CONSTANT_ARGS); + CASE(CL_DEVICE_LOCAL_MEM_TYPE); + CASE(CL_DEVICE_LOCAL_MEM_SIZE); + CASE(CL_DEVICE_ERROR_CORRECTION_SUPPORT); + CASE(CL_DEVICE_PROFILING_TIMER_RESOLUTION); + CASE(CL_DEVICE_ENDIAN_LITTLE); + CASE(CL_DEVICE_AVAILABLE); + CASE(CL_DEVICE_COMPILER_AVAILABLE); + CASE(CL_DEVICE_EXECUTION_CAPABILITIES); + CASE(CL_DEVICE_QUEUE_PROPERTIES); + CASE(CL_DEVICE_NAME); + CASE(CL_DEVICE_VENDOR); + CASE(CL_DRIVER_VERSION); + CASE(CL_DEVICE_PROFILE); + CASE(CL_DEVICE_VERSION); + CASE(CL_DEVICE_EXTENSIONS); + CASE(CL_DEVICE_PLATFORM); + CASE(CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF); + CASE(CL_DEVICE_HOST_UNIFIED_MEMORY); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_INT); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE); + CASE(CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF); + CASE(CL_DEVICE_OPENCL_C_VERSION); + default: return getHexString(param_name); + } +} + +static std::string +getContextInfoString(cl_context_info param_name) +{ + switch (param_name) { + CASE(CL_CONTEXT_REFERENCE_COUNT); + CASE(CL_CONTEXT_DEVICES); + CASE(CL_CONTEXT_PROPERTIES); + CASE(CL_CONTEXT_NUM_DEVICES); + default: return getHexString(param_name); + } +} + +static std::string +getCommandQueueInfoString(cl_command_queue_info param_name) +{ + switch (param_name) { + CASE(CL_QUEUE_CONTEXT); + CASE(CL_QUEUE_DEVICE); + CASE(CL_QUEUE_REFERENCE_COUNT); + CASE(CL_QUEUE_PROPERTIES); + default: return getHexString(param_name); + } +} + +static std::string +getProgramInfoString(cl_program_info param_name) +{ + switch (param_name) { + CASE(CL_PROGRAM_REFERENCE_COUNT); + CASE(CL_PROGRAM_CONTEXT); + CASE(CL_PROGRAM_NUM_DEVICES); + CASE(CL_PROGRAM_DEVICES); + CASE(CL_PROGRAM_SOURCE); + CASE(CL_PROGRAM_BINARY_SIZES); + CASE(CL_PROGRAM_BINARIES); + default: return getHexString(param_name); + } +} + +static std::string +getKernelInfoString(cl_kernel_info param_name) +{ + switch (param_name) { + CASE(CL_KERNEL_FUNCTION_NAME); + CASE(CL_KERNEL_NUM_ARGS); + CASE(CL_KERNEL_REFERENCE_COUNT); + CASE(CL_KERNEL_CONTEXT); + CASE(CL_KERNEL_PROGRAM); + default: return getHexString(param_name); + } +} + +static std::string +getKernelExecInfoString(cl_kernel_exec_info param_name) +{ + switch (param_name) { + CASE(CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM); + CASE(CL_KERNEL_EXEC_INFO_SVM_PTRS); + CASE(CL_KERNEL_EXEC_INFO_NEW_VCOP_AMD); + CASE(CL_KERNEL_EXEC_INFO_PFPA_VCOP_AMD); + default: return getHexString(param_name); + } +} + + +static std::string +getKernelWorkGroupInfoString(cl_kernel_work_group_info param_name) +{ + switch (param_name) { + CASE(CL_KERNEL_WORK_GROUP_SIZE); + CASE(CL_KERNEL_COMPILE_WORK_GROUP_SIZE); + CASE(CL_KERNEL_LOCAL_MEM_SIZE); + CASE(CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE); + CASE(CL_KERNEL_PRIVATE_MEM_SIZE); + default: return getHexString(param_name); + } +} + +static std::string +getProgramBuildInfoString(cl_program_build_info param_name) +{ + switch (param_name) { + CASE(CL_PROGRAM_BUILD_STATUS); + CASE(CL_PROGRAM_BUILD_OPTIONS); + CASE(CL_PROGRAM_BUILD_LOG); + default: return getHexString(param_name); + } +} + +static std::string +getEventInfoString(cl_event_info param_name) +{ + switch (param_name) { + CASE(CL_EVENT_COMMAND_QUEUE); + CASE(CL_EVENT_COMMAND_TYPE); + CASE(CL_EVENT_REFERENCE_COUNT); + CASE(CL_EVENT_COMMAND_EXECUTION_STATUS); + CASE(CL_EVENT_CONTEXT); + default: return getHexString(param_name); + } +} + +static std::string +getProfilingInfoString(cl_profiling_info param_name) +{ + switch (param_name) { + CASE(CL_PROFILING_COMMAND_QUEUED); + CASE(CL_PROFILING_COMMAND_SUBMIT); + CASE(CL_PROFILING_COMMAND_START); + CASE(CL_PROFILING_COMMAND_END); + default: return getHexString(param_name); + } +} + +static std::string +getCommandExecutionStatusString(cl_int param_name) +{ + switch (param_name) { + CASE(CL_COMPLETE); + CASE(CL_RUNNING); + CASE(CL_SUBMITTED); + CASE(CL_QUEUED); + default: return getHexString(param_name); + } +} + +static std::string +getStringString(const char* src) +{ + if (src == NULL) { + return "NULL"; + } + + std::string str(src); + + if (str.length() > 60) { + str = str.substr(0, 60).append("..."); + } + + size_t found = 0; + while (true) { + found = str.find_first_of("\n\r\t\"", found); + if (found == std::string::npos) { + break; + } + char subst[] = { '\\', '\0', '\0' }; + switch (str[found]) { + case '\n': subst[1] = 'n'; break; + case '\r': subst[1] = 'r'; break; + case '\t': subst[1] = 't'; break; + case '\"': subst[1] = '\"'; break; + default: ++found; continue; + } + str.replace(found, 1, subst); + found += 2; + } + + str.insert(size_t(0), size_t(1), '\"').append(1, '\"'); + return str; +} + +static std::string +getProgramSourceString( + const char** strings, const size_t* lengths, cl_uint count) +{ + if (strings == NULL) { + return "NULL"; + } + if (count == 0) { + return "[]"; + } + std::ostringstream ss; + ss << '['; + + for (cl_uint i = 0; i < count; ++i) { + std::string src; + if (lengths != NULL && lengths[i] != 0) { + src = std::string(strings[i], lengths[i]); + } + else { + src = strings[i]; + } + if (i != 0) { + ss << ','; + } + ss << getStringString(src.c_str()); + } + + ss << ']'; + return ss.str(); +} + +static cl_icd_dispatch_table original_dispatch; + +static cl_int CL_API_CALL +GetPlatformIDs( + cl_uint num_entries, + cl_platform_id * platforms, + cl_uint * num_platforms) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetPlatformIDs(" << num_entries << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetPlatformIDs( + num_entries, platforms, num_platforms); + delRec(&r); + + ss << getHandlesString(platforms, num_entries) << ','; + ss << getHexString(num_platforms) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetPlatformInfo( + cl_platform_id platform, + cl_platform_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetPlatformInfo(" << platform << ','; + ss << getPlatformInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetPlatformInfo( + platform, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetDeviceIDs( + cl_platform_id platform, + cl_device_type device_type, + cl_uint num_entries, + cl_device_id * devices, + cl_uint * num_devices) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetDeviceIDs(" << platform << ','; + ss << getDeviceTypeString(device_type) << ','; + ss << num_entries << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetDeviceIDs( + platform, device_type, num_entries, devices, num_devices); + delRec(&r); + + ss << getHandlesString(devices, num_entries) << ','; + ss << getDecimalString(num_devices) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetDeviceInfo( + cl_device_id device, + cl_device_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetDeviceInfo(" << device << ','; + ss << getDeviceInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetDeviceInfo( + device, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_context CL_API_CALL +CreateContext( + 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) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateContext("; + ss << getContextPropertiesString(properties) << ','; + ss << num_devices << ','; + ss << getHandlesString(devices, num_devices) << ','; + ss << pfn_notify << ',' << user_data << ','; + + addRec(&r); + cl_context ret = original_dispatch.CreateContext( + properties, num_devices, devices, pfn_notify, user_data, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_context CL_API_CALL +CreateContextFromType( + 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) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateContextFromType("; + ss << getContextPropertiesString(properties) << ','; + ss << getDeviceTypeString(device_type) << ','; + ss << pfn_notify << ',' << user_data << ','; + + addRec(&r); + cl_context ret = original_dispatch.CreateContextFromType( + properties, device_type, pfn_notify, user_data, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +RetainContext(cl_context context) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clRetainContext(" << context; + + addRec(&r); + cl_int ret = original_dispatch.RetainContext(context); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +ReleaseContext(cl_context context) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clReleaseContext(" << context; + + addRec(&r); + cl_int ret = original_dispatch.ReleaseContext(context); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetContextInfo( + cl_context context, + cl_context_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetContextInfo(" << context << ','; + ss << getContextInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetContextInfo( + context, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_command_queue CL_API_CALL +CreateCommandQueue( + cl_context context, + cl_device_id device, + cl_command_queue_properties properties, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateCommandQueue(" << context << ',' << device << ','; + ss << getCommandQueuePropertyString(properties) << ','; + + addRec(&r); + cl_command_queue ret = original_dispatch.CreateCommandQueue( + context, device, properties, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_command_queue CL_API_CALL +CreateCommandQueueWithProperties( + cl_context context, + cl_device_id device, + const cl_queue_properties * properties, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateCommandQueueWithProperties(" << context << ',' << device << ','; + ss << getQueuePropertyString(properties) << ','; + + addRec(&r); + cl_command_queue ret = original_dispatch.CreateCommandQueueWithProperties( + context, device, properties, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +RetainCommandQueue(cl_command_queue command_queue) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clRetainCommandQueue(" << command_queue; + + addRec(&r); + cl_int ret = original_dispatch.RetainCommandQueue(command_queue); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +ReleaseCommandQueue(cl_command_queue command_queue) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clReleaseCommandQueue(" << command_queue; + + addRec(&r); + cl_int ret = original_dispatch.ReleaseCommandQueue(command_queue); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetCommandQueueInfo( + cl_command_queue command_queue, + cl_command_queue_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetCommandQueueInfo(" << command_queue << ','; + ss << getCommandQueueInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetCommandQueueInfo( + command_queue, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +SetCommandQueueProperty( + cl_command_queue command_queue, + cl_command_queue_properties properties, + cl_bool enable, + cl_command_queue_properties * old_properties) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clSetCommandQueueProperty(" << command_queue << ','; + ss << getCommandQueuePropertyString(properties) << ','; + ss << enable << ','; + + addRec(&r); + cl_int ret = original_dispatch.SetCommandQueueProperty( + command_queue, properties, enable, old_properties); + delRec(&r); + + ss << getHexString(old_properties) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; + +} + +static cl_mem CL_API_CALL +CreateBuffer( + cl_context context, + cl_mem_flags flags, + size_t size, + void * host_ptr, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateBuffer(" << context << ','; + ss << getMemFlagsString(flags) << ',' << size << ',' << host_ptr << ','; + + addRec(&r); + cl_mem ret = original_dispatch.CreateBuffer( + context, flags, size, host_ptr, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_mem CL_API_CALL +CreateSubBuffer( + cl_mem buffer, + cl_mem_flags flags, + cl_buffer_create_type buffer_create_type, + const void * buffer_create_info, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateSubBuffer(" << buffer << ','; + ss << getMemFlagsString(flags) << ','; + ss << getBufferCreateString(buffer_create_type, buffer_create_info) << ','; + + addRec(&r); + cl_mem ret = original_dispatch.CreateSubBuffer( + buffer, flags, buffer_create_type, buffer_create_info, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_mem CL_API_CALL +CreateImage2D( + cl_context context, + cl_mem_flags flags, + const cl_image_format * image_format, + size_t image_width, + size_t image_height, + size_t image_row_pitch, + void * host_ptr, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateImage2D(" << context << ','; + ss << getMemFlagsString(flags) << ','; + ss << getImageFormatsString(image_format, 1) << ','; + ss << image_width << ',' << image_height << ',' << image_row_pitch << ','; + ss << host_ptr << ','; + + addRec(&r); + cl_mem ret = original_dispatch.CreateImage2D( + context, flags, image_format, image_width, image_height, + image_row_pitch, host_ptr, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + + +static cl_mem CL_API_CALL +CreateImage3D( + cl_context context, + cl_mem_flags flags, + const cl_image_format * image_format, + size_t image_width, + size_t image_height, + size_t image_depth, + size_t image_row_pitch, + size_t image_slice_pitch, + void * host_ptr, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateImage3D(" << context << ','; + ss << getMemFlagsString(flags) << ','; + ss << getImageFormatsString(image_format, 1) << ','; + ss << image_width << ',' << image_height << ',' << image_depth << ','; + ss << image_row_pitch << ',' << image_slice_pitch << ','; + ss << host_ptr << ','; + + addRec(&r); + cl_mem ret = original_dispatch.CreateImage3D( + context, flags, image_format, image_width, image_height, image_depth, + image_row_pitch, image_slice_pitch, host_ptr, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + + +static cl_int CL_API_CALL +RetainMemObject(cl_mem memobj) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clRetainMemObject(" << memobj; + + addRec(&r); + cl_int ret = original_dispatch.RetainMemObject(memobj); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + + +static cl_int CL_API_CALL +ReleaseMemObject(cl_mem memobj) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clReleaseMemObject(" << memobj; + + addRec(&r); + cl_int ret = original_dispatch.ReleaseMemObject(memobj); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetSupportedImageFormats( + 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) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetSupportedImageFormats(" << context << ','; + ss << getMemFlagsString(flags) << ','; + ss << getMemObjectTypeString(image_type) << ','; + ss << num_entries << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetSupportedImageFormats( + context, flags, image_type, num_entries, image_formats, + num_image_formats); + delRec(&r); + + ss << getImageFormatsString(image_formats, num_entries) << ','; + ss << getDecimalString(num_image_formats); + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetMemObjectInfo( + cl_mem memobj, + cl_mem_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetMemObjectInfo(" << memobj << ','; + ss << getMemInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetMemObjectInfo( + memobj, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetImageInfo( + cl_mem image, + cl_image_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetImageInfo(" << image << ','; + ss << getImageInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetImageInfo( + image, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +SetMemObjectDestructorCallback( + cl_mem memobj, + void (CL_CALLBACK * pfn_notify)( cl_mem memobj, void* user_data), + void * user_data) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clSetMemObjectDestructorCallback(" << memobj << ','; + ss << pfn_notify << ',' << user_data; + + addRec(&r); + cl_int ret = original_dispatch.SetMemObjectDestructorCallback( + memobj, pfn_notify, user_data); + delRec(&r); + + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_sampler CL_API_CALL +CreateSampler( + cl_context context, + cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateSampler(" << context << ','; + ss << normalized_coords << ','; + ss << getAddressingModeString(addressing_mode) << ','; + ss << getFilterModeString(filter_mode) << ','; + + addRec(&r); + cl_sampler ret = original_dispatch.CreateSampler( + context, normalized_coords, addressing_mode, filter_mode, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +RetainSampler(cl_sampler sampler) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clRetainSampler(" << sampler; + + addRec(&r); + cl_int ret = original_dispatch.RetainSampler(sampler); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +ReleaseSampler(cl_sampler sampler) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clReleaseSampler(" << sampler; + + addRec(&r); + cl_int ret = original_dispatch.ReleaseSampler(sampler); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetSamplerInfo( + cl_sampler sampler, + cl_sampler_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetSamplerInfo(" << sampler << ','; + ss << getSamplerInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetSamplerInfo( + sampler, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_program CL_API_CALL +CreateProgramWithSource( + cl_context context, + cl_uint count, + const char ** strings, + const size_t * lengths, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateProgramWithSource(" << context << ',' << count << ','; + ss << getProgramSourceString(strings, lengths, count) << ','; + ss << lengths << ','; + + addRec(&r); + cl_program ret = original_dispatch.CreateProgramWithSource( + context, count, strings, lengths, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_program CL_API_CALL +CreateProgramWithBinary( + 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) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateProgramWithBinary(" << context << ','; + ss << num_devices << ',' << getHandlesString(device_list, num_devices); + ss << ',' << lengths << ',' << binaries << ','; + ss << binary_status << ','; + + addRec(&r); + cl_program ret = original_dispatch.CreateProgramWithBinary( + context, num_devices, device_list, lengths, + binaries, binary_status, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +RetainProgram(cl_program program) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clRetainProgram(" << program; + + addRec(&r); + cl_int ret = original_dispatch.RetainProgram(program); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +ReleaseProgram(cl_program program) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clReleaseProgram(" << program; + + addRec(&r); + cl_int ret = original_dispatch.ReleaseProgram(program); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +BuildProgram( + 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) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clBuildProgram(" << program << ','; + ss << num_devices << ',' << getHandlesString(device_list, num_devices); + ss << ',' << getStringString(options) << ','; + ss << pfn_notify << ',' << user_data; + + addRec(&r); + cl_int ret = original_dispatch.BuildProgram( + program, num_devices, device_list, options, pfn_notify, user_data); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +UnloadCompiler(void) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clUnloadCompiler("; + + addRec(&r); + cl_int ret = original_dispatch.UnloadCompiler(); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetProgramInfo( + cl_program program, + cl_program_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetProgramInfo(" << program << ','; + ss << getProgramInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetProgramInfo( + program, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetProgramBuildInfo( + 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) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetProgramBuildInfo(" << program << ',' << device << ','; + ss << getProgramBuildInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetProgramBuildInfo( + program, device, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_kernel CL_API_CALL +CreateKernel( + cl_program program, + const char * kernel_name, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateKernel(" << program << ','; + ss << getStringString(kernel_name) << ','; + + addRec(&r); + cl_kernel ret = original_dispatch.CreateKernel( + program, kernel_name, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +CreateKernelsInProgram( + cl_program program, + cl_uint num_kernels, + cl_kernel * kernels, + cl_uint * num_kernels_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateKernelInProgram(" << program << ','; + ss << num_kernels << ',' << kernels << ','; + + addRec(&r); + cl_int ret = original_dispatch.CreateKernelsInProgram( + program, num_kernels, kernels, num_kernels_ret); + delRec(&r); + + ss << getDecimalString(num_kernels_ret) << ','; + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +RetainKernel(cl_kernel kernel) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clRetainKernel(" << kernel; + + addRec(&r); + cl_int ret = original_dispatch.RetainKernel(kernel); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +ReleaseKernel(cl_kernel kernel) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clReleaseKernel(" << kernel; + + addRec(&r); + cl_int ret = original_dispatch.ReleaseKernel(kernel); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +SetKernelArg( + cl_kernel kernel, + cl_uint arg_index, + size_t arg_size, + const void * arg_value) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clSetKernelArg(" << kernel << ','; + ss << arg_index << ',' << arg_size << ','; + ss << getMemoryString(arg_value, arg_size); + + addRec(&r); + cl_int ret = original_dispatch.SetKernelArg( + kernel, arg_index, arg_size, arg_value); + delRec(&r); + + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetKernelInfo( + cl_kernel kernel, + cl_kernel_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetKernelInfo(" << kernel << ','; + ss << getKernelInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetKernelInfo( + kernel, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetKernelWorkGroupInfo( + 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) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetKernelWorkGroupInfo(" << kernel << ',' << device << ','; + ss << getKernelWorkGroupInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetKernelWorkGroupInfo( + kernel, device, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +WaitForEvents( + cl_uint num_events, + const cl_event * event_list) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clWaitForEvents(" << num_events << ','; + ss << getHandlesString(event_list, num_events); + + addRec(&r); + cl_int ret = original_dispatch.WaitForEvents( + num_events, event_list); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetEventInfo( + cl_event event, + cl_event_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetEventInfo(" << event << ','; + ss << getEventInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetEventInfo( + event, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_event CL_API_CALL +CreateUserEvent( + cl_context context, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateUserEvent(" << context << ','; + + addRec(&r); + cl_event ret = original_dispatch.CreateUserEvent( + context, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +RetainEvent(cl_event event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clRetainEvent(" << event; + + addRec(&r); + cl_int ret = original_dispatch.RetainEvent(event); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +ReleaseEvent(cl_event event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clReleaseEvent(" << event; + + addRec(&r); + cl_int ret = original_dispatch.ReleaseEvent(event); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +SetUserEventStatus( + cl_event event, + cl_int execution_status) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clSetUserEventStatus(" << event << ',' << execution_status; + + addRec(&r); + cl_int ret = original_dispatch.SetUserEventStatus( + event, execution_status); + delRec(&r); + + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +SetEventCallback( + cl_event event, + cl_int command_exec_callback_type, + void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *), + void * user_data) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clSetEventCallback(" << event << ','; + ss << getCommandExecutionStatusString(command_exec_callback_type) << ','; + ss << pfn_notify << ',' << user_data; + + addRec(&r); + cl_int ret = original_dispatch.SetEventCallback( + event, command_exec_callback_type, pfn_notify, user_data); + delRec(&r); + + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetEventProfilingInfo( + cl_event event, + cl_profiling_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetEventProfilingInfo(" << event << ','; + ss << getProfilingInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetEventProfilingInfo( + event, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +Flush(cl_command_queue command_queue) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clFlush(" << command_queue; + + addRec(&r); + cl_int ret = original_dispatch.Flush(command_queue); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +Finish(cl_command_queue command_queue) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clFinish(" << command_queue; + + addRec(&r); + cl_int ret = original_dispatch.Finish(command_queue); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueReadBuffer( + cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_read, + size_t offset, + size_t cb, + void * ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueReadBuffer(" << command_queue << ','; + ss << buffer << ',' << getBoolString(blocking_read) << ','; + ss << offset << ',' << cb << ',' << ptr << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueReadBuffer( + command_queue, buffer, blocking_read, offset, cb, ptr, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueReadBufferRect( + cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_read, + const size_t * buffer_offset, + const size_t * host_offset, + const size_t * region, + size_t buffer_row_pitch, + size_t buffer_slice_pitch, + size_t host_row_pitch, + size_t host_slice_pitch, + void * ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueReadBufferRect(" << command_queue << ','; + ss << buffer << ',' << getBoolString(blocking_read) << ','; + ss << getNDimString(buffer_offset, 3) << ','; + ss << getNDimString(host_offset, 3) << ','; + ss << getNDimString(region, 3) << ','; + ss << buffer_row_pitch << ',' << buffer_slice_pitch << ','; + ss << host_row_pitch << ',' << host_slice_pitch << ','; + ss << ptr << ',' << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueReadBufferRect( + command_queue, buffer, blocking_read, + buffer_offset, host_offset, region, + buffer_row_pitch, buffer_slice_pitch, + host_row_pitch, host_slice_pitch, + ptr, num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueWriteBuffer( + cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_write, + size_t offset, + size_t cb, + const void * ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueWriteBuffer(" << command_queue << ','; + ss << buffer << ',' << getBoolString(blocking_write) << ','; + ss << offset << ',' << cb << ',' << ptr << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueWriteBuffer( + command_queue, buffer, blocking_write, offset, cb, ptr, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueWriteBufferRect( + cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_write, + const size_t * buffer_offset, + const size_t * host_offset, + const size_t * region, + size_t buffer_row_pitch, + size_t buffer_slice_pitch, + size_t host_row_pitch, + size_t host_slice_pitch, + const void * ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueWriteBufferRect(" << command_queue << ','; + ss << buffer << ',' << getBoolString(blocking_write) << ','; + ss << getNDimString(buffer_offset, 3) << ','; + ss << getNDimString(host_offset, 3) << ','; + ss << getNDimString(region, 3) << ','; + ss << buffer_row_pitch << ',' << buffer_slice_pitch << ','; + ss << host_row_pitch << ',' << host_slice_pitch << ','; + ss << ptr << ',' << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueWriteBufferRect( + command_queue, buffer, blocking_write, + buffer_offset, host_offset, region, + buffer_row_pitch, buffer_slice_pitch, + host_row_pitch, host_slice_pitch, + ptr, num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueCopyBuffer( + cl_command_queue command_queue, + cl_mem src_buffer, + cl_mem dst_buffer, + size_t src_offset, + size_t dst_offset, + size_t cb, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueCopyBuffer(" << command_queue << ','; + ss << src_buffer << ',' << dst_buffer << ','; + ss << src_offset << ',' << dst_offset << ',' << cb << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueCopyBuffer( + command_queue, src_buffer, dst_buffer, src_offset, dst_offset, cb, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueCopyBufferRect( + cl_command_queue command_queue, + cl_mem src_buffer, + cl_mem dst_buffer, + const size_t * src_origin, + const size_t * dst_origin, + const size_t * region, + size_t src_row_pitch, + size_t src_slice_pitch, + size_t dst_row_pitch, + size_t dst_slice_pitch, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueCopyBufferRect(" << command_queue << ','; + ss << src_buffer << ',' << dst_buffer << ','; + ss << getNDimString(src_origin, 3) << ','; + ss << getNDimString(dst_origin, 3) << ','; + ss << getNDimString(region, 3) << ','; + ss << src_row_pitch << ',' << src_slice_pitch << ','; + ss << dst_row_pitch << ',' << dst_slice_pitch << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueCopyBufferRect( + command_queue, src_buffer, dst_buffer, + src_origin, dst_origin, region, + src_row_pitch, src_slice_pitch, + dst_row_pitch, dst_slice_pitch, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueReadImage( + cl_command_queue command_queue, + cl_mem image, + cl_bool blocking_read, + const size_t * origin, + const size_t * region, + 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) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueReadImage(" << command_queue << ','; + ss << image << ',' << getBoolString(blocking_read) << ','; + ss << getNDimString(origin, 3) << ','; + ss << getNDimString(region, 3) << ','; + ss << row_pitch << ',' << slice_pitch << ','; + ss << ptr << ',' << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueReadImage( + command_queue, image, blocking_read, origin, region, + row_pitch, slice_pitch, ptr, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueWriteImage( + cl_command_queue command_queue, + cl_mem image, + cl_bool blocking_write, + const size_t * origin, + const size_t * region, + 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) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueWriteImage(" << command_queue << ','; + ss << image << ',' << getBoolString(blocking_write) << ','; + ss << getNDimString(origin, 3) << ','; + ss << getNDimString(region, 3) << ','; + ss << input_row_pitch << ',' << input_slice_pitch << ','; + ss << ptr << ',' << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueWriteImage( + command_queue, image, blocking_write, origin, region, + input_row_pitch, input_slice_pitch, ptr, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueCopyImage( + cl_command_queue command_queue, + cl_mem src_image, + cl_mem dst_image, + const size_t * src_origin, + const size_t * dst_origin, + const size_t * region, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueCopyImage(" << command_queue << ','; + ss << src_image << ',' << dst_image << ','; + ss << getNDimString(src_origin, 3) << ','; + ss << getNDimString(dst_origin, 3) << ','; + ss << getNDimString(region, 3) << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueCopyImage( + command_queue, src_image, dst_image, src_origin, dst_origin, region, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueCopyImageToBuffer( + cl_command_queue command_queue, + cl_mem src_image, + cl_mem dst_buffer, + const size_t * src_origin, + const size_t * region, + size_t dst_offset, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueCopyImageToBuffer(" << command_queue << ','; + ss << src_image << ',' << dst_buffer << ','; + ss << getNDimString(src_origin, 3) << ','; + ss << getNDimString(region, 3) << ','; + ss << dst_offset << ',' << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueCopyImageToBuffer( + command_queue, src_image, dst_buffer, src_origin, region, + dst_offset, num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueCopyBufferToImage( + cl_command_queue command_queue, + cl_mem src_buffer, + cl_mem dst_image, + size_t src_offset, + const size_t * dst_origin, + const size_t * region, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueCopyBufferToImage(" << command_queue << ','; + ss << src_buffer << ',' << dst_image << ',' << src_offset << ','; + ss << getNDimString(dst_origin, 3) << ','; + ss << getNDimString(region, 3) << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueCopyBufferToImage( + command_queue, src_buffer, dst_image, src_offset, dst_origin, region, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static void * CL_API_CALL +EnqueueMapBuffer( + cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_map, + cl_map_flags map_flags, + size_t offset, + size_t cb, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueMapBuffer(" << command_queue << ','; + ss << buffer << ',' << getBoolString(blocking_map) << ','; + ss << getMapFlagsString(map_flags) << ','; + ss << offset << ',' << cb << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + void* ret = original_dispatch.EnqueueMapBuffer( + command_queue, buffer, blocking_map, map_flags, offset, cb, + num_events_in_wait_list, event_wait_list, event, errcode_ret); + delRec(&r); + + ss << getHexString(event) << ',' << getErrorString(errcode_ret); + ss << ") = " << ret; + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static void * CL_API_CALL +EnqueueMapImage( + 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) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueMapImage(" << command_queue << ','; + ss << image << ',' << getBoolString(blocking_map) << ','; + ss << getMapFlagsString(map_flags) << ','; + ss << getNDimString(origin, 3) << ','; + ss << getNDimString(region, 3) << ','; + ss << image_row_pitch << ',' << image_slice_pitch << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + void* ret = original_dispatch.EnqueueMapImage( + 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); + delRec(&r); + + ss << getHexString(event) << ',' << getErrorString(errcode_ret); + ss << ") = " << ret; + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueUnmapMemObject( + 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) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueUnmapMemObject(" << command_queue << ','; + ss << memobj << ',' << mapped_ptr << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueUnmapMemObject( + command_queue, memobj, mapped_ptr, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueNDRangeKernel( + 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) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueNDRangeKernel(" << command_queue << ','; + ss << kernel << ',' << work_dim << ','; + ss << getNDimString(global_work_offset, work_dim) << ','; + ss << getNDimString(global_work_size, work_dim) << ','; + ss << getNDimString(local_work_size, work_dim) << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueNDRangeKernel( + command_queue, kernel, work_dim, + global_work_offset, global_work_size, local_work_size, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueTask(cl_command_queue command_queue, + cl_kernel kernel, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueTask(" << command_queue << ',' << kernel << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueTask( + command_queue, kernel, num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueNativeKernel( + cl_command_queue command_queue, + void (CL_CALLBACK *user_func)(void *), + void * args, + size_t cb_args, + cl_uint num_mem_objects, + const cl_mem * mem_list, + const void ** args_mem_loc, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueNativeKernel(" << command_queue << ',' << user_func << ','; + ss << args << ',' << cb_args << ',' << num_mem_objects << ','; + ss << getHandlesString(mem_list, num_mem_objects) << ','; + ss << args_mem_loc << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueNativeKernel( + command_queue, user_func, args, cb_args, + num_mem_objects, mem_list, args_mem_loc, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueMarker( + cl_command_queue command_queue, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueMarker(" << command_queue << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueMarker(command_queue, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueWaitForEvents( + cl_command_queue command_queue, + cl_uint num_events, + const cl_event * event_list) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueWaitForEvents(" << command_queue << ','; + ss << num_events << ','; + ss << getHandlesString(event_list, num_events); + + addRec(&r); + cl_int ret = original_dispatch.EnqueueWaitForEvents( + command_queue, num_events, event_list); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueBarrier(cl_command_queue command_queue) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueBarrier(" << command_queue; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueBarrier(command_queue); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static void * CL_API_CALL +GetExtensionFunctionAddress(const char * func_name) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetExtensionFunctionAddress(" << func_name; + + addRec(&r); + void* ret = original_dispatch.GetExtensionFunctionAddress(func_name); + delRec(&r); + + ss << ") = " << ret; + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_mem CL_API_CALL +CreateFromGLBuffer( + cl_context context, + cl_mem_flags flags, + cl_GLuint bufobj, + int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateFromGLBuffer(" << context << ','; + ss << getMemFlagsString(flags) << ',' << bufobj << ','; + + addRec(&r); + cl_mem ret = original_dispatch.CreateFromGLBuffer( + context, flags, bufobj, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_mem CL_API_CALL +CreateFromGLTexture2D( + cl_context context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texture, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateFromGLTexture2D(" << context << ','; + ss << getMemFlagsString(flags) << ',' << target << ','; + ss << miplevel << ',' << texture << ','; + + addRec(&r); + cl_mem ret = original_dispatch.CreateFromGLTexture2D( + context, flags, target, miplevel, texture, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_mem CL_API_CALL +CreateFromGLTexture3D( + cl_context context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texture, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateFromGLTexture3D(" << context << ','; + ss << getMemFlagsString(flags) << ',' << target << ','; + ss << miplevel << ',' << texture << ','; + + addRec(&r); + cl_mem ret = original_dispatch.CreateFromGLTexture3D( + context, flags, target, miplevel, texture, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_mem CL_API_CALL +CreateFromGLRenderbuffer( + cl_context context, + cl_mem_flags flags, + cl_GLuint renderbuffer, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateFromGLRenderbuffer(" << context << ','; + ss << getMemFlagsString(flags) << ',' << renderbuffer << ','; + + addRec(&r); + cl_mem ret = original_dispatch.CreateFromGLRenderbuffer( + context, flags, renderbuffer, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetGLObjectInfo( + cl_mem memobj, + cl_gl_object_type * gl_object_type, + cl_GLuint * gl_object_name) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetGLObjectInfo(" << memobj << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetGLObjectInfo( + memobj, gl_object_type, gl_object_name); + delRec(&r); + + ss << getHexString(gl_object_type) << ','; + ss << getDecimalString(gl_object_name) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetGLTextureInfo( + cl_mem memobj, + cl_gl_texture_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetGLTextureInfo(" << memobj << ','; + ss << param_name << ',' << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetGLTextureInfo( + memobj, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetGLContextInfoKHR( + const cl_context_properties * properties, + cl_gl_context_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetGLContextInfoKHR("; + ss << getContextPropertiesString(properties) << ','; + ss << param_name << ',' << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetGLContextInfoKHR( + properties, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueAcquireGLObjects( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueAcquireGLObjects(" << command_queue << ','; + ss << num_objects << ',' << getHandlesString(mem_objects, num_objects); + ss << ',' << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueAcquireGLObjects( + command_queue, num_objects, mem_objects, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueReleaseGLObjects( + cl_command_queue command_queue, + cl_uint num_objects, + const cl_mem * mem_objects, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueReleaseGLObjects(" << command_queue << ','; + ss << num_objects << ',' << getHandlesString(mem_objects, num_objects); + ss << ',' << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueReleaseGLObjects( + command_queue, num_objects, mem_objects, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +RetainDevice( + cl_device_id device) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clRetainDevice(" << device; + addRec(&r); + cl_int ret = original_dispatch.RetainDevice( + device); + delRec(&r); + + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +ReleaseDevice( + cl_device_id device) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "ReleaseDevice(" << device; + addRec(&r); + cl_int ret = original_dispatch.ReleaseDevice( + device); + delRec(&r); + + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_mem CL_API_CALL +CreateImage( + 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) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "CreateImage(" << context << ','; + ss << getMemFlagsString(flags) << ','; + ss << getImageFormatsString(image_format, 1) << ','; + ss << getImageDescString(image_desc) << ','; + ss << host_ptr << ','; + + addRec(&r); + cl_mem ret = original_dispatch.CreateImage( + context, flags, image_format, image_desc, + host_ptr, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_program CL_API_CALL +CreateProgramWithBuiltInKernels( + cl_context context, + cl_uint num_devices, + const cl_device_id * device_list, + const char * kernel_names, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateProgramWithBuiltInKernels(" << context << ','; + ss << num_devices << ',' << getHandlesString(device_list, num_devices); + ss << ',' << kernel_names << ','; + + addRec(&r); + cl_program ret = original_dispatch.CreateProgramWithBuiltInKernels( + context, num_devices, device_list, kernel_names, + errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +CompileProgram( + cl_program program, + cl_uint num_devices, + const cl_device_id * device_list, + const char * options, + cl_uint num_input_headers, + const cl_program * input_headers, + const char ** header_include_names, + void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data), + void * user_data) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCompileProgram(" << program << ','; + ss << num_devices << ',' << getHandlesString(device_list, num_devices); + ss << options << ','; + ss << num_devices << ',' << getHandlesString(input_headers, num_input_headers); + ss << header_include_names << ','; + ss << pfn_notify << ','; + + addRec(&r); + cl_int ret = original_dispatch.CompileProgram( + program, num_devices, device_list, options, num_input_headers, + input_headers, header_include_names, pfn_notify, user_data); + delRec(&r); + + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_program CL_API_CALL +LinkProgram( + cl_context context, + cl_uint num_devices, + const cl_device_id * device_list, + const char * options, + cl_uint num_input_programs, + const cl_program * input_programs, + void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data), + void * user_data, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clLinkProgram(" << context << ','; + ss << num_devices << ',' << getHandlesString(device_list, num_devices); + ss << options << ','; + ss << getHandlesString(input_programs, num_input_programs); + ss << pfn_notify << ',' << user_data << ','; + + addRec(&r); + cl_program ret = original_dispatch.LinkProgram( + context, num_devices, device_list, options, num_input_programs, + input_programs, pfn_notify, user_data, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +UnloadPlatformCompiler( + cl_platform_id platform) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clUnloadPlatformCompiler(" << platform << ','; + + addRec(&r); + cl_int ret = original_dispatch.UnloadPlatformCompiler( + platform); + delRec(&r); + + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetKernelArgInfo( + cl_kernel kernel, + cl_uint arg_indx, + cl_kernel_arg_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetKernelArgInfo(" << kernel << ','; + ss << arg_indx << ','; + ss << getKernelArgInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetKernelArgInfo( + kernel, arg_indx, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueFillBuffer( + cl_command_queue command_queue, + cl_mem buffer, + const void * pattern, + size_t pattern_size, + size_t offset, + size_t cb, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueFillBuffer(" << command_queue << ','; + ss << buffer << ',' << pattern << ',' << pattern_size << ','; + ss << offset << ',' << cb << ',' ; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueFillBuffer( + command_queue, buffer, pattern, pattern_size, offset, cb, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueFillImage( + cl_command_queue command_queue, + cl_mem image, + const void * fill_color, + const size_t origin[3], + const size_t region[3], + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueFillImage(" << command_queue << ','; + ss << image << ',' << fill_color << ','; + ss << getNDimString(origin, 3) << ','; + ss << getNDimString(region, 3) << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueFillImage( + command_queue, image, fill_color, origin, region, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event) << ','; + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueMigrateMemObjects( + cl_command_queue command_queue, + cl_uint num_mem_objects, + const cl_mem * mem_objects, + cl_mem_migration_flags flags, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueMigrateMemObjects(" << command_queue << ','; + ss << ',' << num_mem_objects << ','; + ss << getHandlesString(mem_objects, num_mem_objects) << ',' << flags << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueMigrateMemObjects( + command_queue, num_mem_objects, mem_objects, flags, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event) << ','; + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueMarkerWithWaitList( + cl_command_queue command_queue, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueMarkerWithWaitList(" << command_queue << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueMarkerWithWaitList( + command_queue, num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event) << ','; + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueBarrierWithWaitList( + cl_command_queue command_queue, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueBarrierWithWaitList(" << command_queue << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueBarrierWithWaitList( + command_queue, num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event) << ','; + ss << ") = " << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static void * CL_API_CALL +GetExtensionFunctionAddressForPlatform( + cl_platform_id platform, + const char * function_name) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetExtensionFunctionAddressForPlatform(" << platform << ','; + ss << function_name << ','; + + addRec(&r); + void* ret = original_dispatch.GetExtensionFunctionAddressForPlatform( + platform, function_name); + delRec(&r); + + ss << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_mem CL_API_CALL +CreateFromGLTexture( + cl_context context, + cl_mem_flags flags, + cl_GLenum target, + cl_GLint miplevel, + cl_GLuint texture, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateFromGLTexture(" << context << ','; + ss << getMemFlagsString(flags) << ',' << target << ','; + ss << miplevel << ',' << texture << ','; + + addRec(&r); + cl_mem ret = original_dispatch.CreateFromGLTexture( + context, flags, target, miplevel, texture, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_mem CL_API_CALL +CreatePipe( + cl_context context, + cl_mem_flags flags, + cl_uint pipePacketSize, + cl_uint pipeMaxPackets, + const cl_pipe_properties * props, + cl_int * errcode_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreatePipe(" << context << ','; + ss << getMemFlagsString(flags) << ',' << pipePacketSize << ','<< pipeMaxPackets << ',' << props << ','; + + addRec(&r); + cl_mem ret = original_dispatch.CreatePipe( + context, flags, pipePacketSize, pipeMaxPackets, props, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +GetPipeInfo( + cl_mem memobj, + cl_pipe_info param_name, + size_t param_value_size, + void * param_value, + size_t * param_value_size_ret) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clGetPipeInfo(" << memobj << ','; + ss << getMemInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.GetPipeInfo( + memobj, param_name, param_value_size, + param_value, param_value_size_ret); + delRec(&r); + + ss << getHexString(param_value) << ','; + ss << getHexString(param_value_size_ret) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static void* CL_API_CALL +SVMAlloc( + cl_context context, + cl_svm_mem_flags flags, + size_t size, + cl_uint alignment) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clSVMAlloc(" << context << ','; + ss << getHexString(flags) << ','; + ss << getHexString(size) << ','; + ss << getHexString(alignment) << ") = "; + + addRec(&r); + void* ret = original_dispatch.SVMAlloc(context, flags, size, alignment); + delRec(&r); + + ss << ret << std::endl; + + std::cerr << ss.str(); + return ret; +} + +static void CL_API_CALL +SVMFree(cl_context context, void* svm_pointer) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clSVMFree(" << context << ','; + ss << svm_pointer << ')'; + + addRec(&r); + original_dispatch.SVMFree(context, svm_pointer); + delRec(&r); + + ss << std::endl; + + std::cerr << ss.str(); +} + +static cl_int CL_API_CALL +EnqueueSVMFree( + cl_command_queue command_queue, + cl_uint num_svm_pointers, + void * svm_pointers[], + void (CL_CALLBACK * pfn_free_func)(cl_command_queue /*queue */, + cl_uint /* num_svm_pointers */, + void *[] /* svm_pointers */, + void * /* user_data */), + void * user_data, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueSVMMap(" << command_queue << ','; + ss << num_svm_pointers << ','; + ss << '['; + for (cl_uint i = 0; i < num_svm_pointers; ++i) { + ss << svm_pointers[i] << ','; + } + ss << "],"; + ss << pfn_free_func << ','; + ss << user_data << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueSVMFree( + command_queue, num_svm_pointers, svm_pointers, pfn_free_func, user_data, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + + +static cl_int CL_API_CALL +EnqueueSVMMemcpy( + cl_command_queue command_queue, + cl_bool blocking_copy, + void * dst_ptr, + const void * src_ptr, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueSVMMemcpy(" << command_queue << ','; + ss << getBoolString(blocking_copy) << ','; + ss << dst_ptr << ','; + ss << src_ptr << ',' << getHexString(size) << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueSVMMemcpy( + command_queue, blocking_copy, dst_ptr, src_ptr, size, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueSVMMemFill( + cl_command_queue command_queue, + void * svm_ptr, + const void * pattern, + size_t pattern_size, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) CL_API_SUFFIX__VERSION_2_0 +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueSVMMemFill(" << command_queue << ','; + ss << svm_ptr << ','; + ss << pattern << ','; + ss << getHexString(pattern_size) << ',' << getHexString(size) << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueSVMMemFill( + command_queue, svm_ptr, pattern, pattern_size, size, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueSVMMap( + cl_command_queue command_queue, + cl_bool blocking_map, + cl_map_flags flags, + void * svm_ptr, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueSVMMap(" << command_queue << ','; + ss << getBoolString(blocking_map) << ','; + ss << getMapFlagsString(flags) << ','; + ss << svm_ptr << ',' << getHexString(size) << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueSVMMap( + command_queue, blocking_map, flags, svm_ptr, size, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +EnqueueSVMUnmap( + cl_command_queue command_queue, + void * svm_ptr, + cl_uint num_events_in_wait_list, + const cl_event * event_wait_list, + cl_event * event) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clEnqueueSVMUnmap(" << command_queue << ','; + ss << svm_ptr << ','; + ss << num_events_in_wait_list << ','; + ss << getHandlesString(event_wait_list, num_events_in_wait_list) << ','; + + addRec(&r); + cl_int ret = original_dispatch.EnqueueSVMUnmap( + command_queue, svm_ptr, + num_events_in_wait_list, event_wait_list, event); + delRec(&r); + + ss << getHexString(event); + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_sampler CL_API_CALL +CreateSamplerWithProperties( + cl_context context, + const cl_sampler_properties * sampler_properties, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_0 +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clCreateSamplerWithProperties(" << context << ','; + ss << "["; + + const struct SamplerProperty { + cl_sampler_properties name; + union { + cl_sampler_properties raw; + cl_bool normalizedCoords; + cl_addressing_mode addressingMode; + cl_filter_mode filterMode; + cl_float lod; + } value; + } *p = reinterpret_cast(sampler_properties); + + if (p != NULL) while (p->name != 0) { + ss << getSamplerInfoString((cl_sampler_info)p->name) << ':'; + switch (p->name) { + case CL_SAMPLER_NORMALIZED_COORDS: + ss << getBoolString(p->value.normalizedCoords) << ','; + break; + case CL_SAMPLER_ADDRESSING_MODE: + ss << getAddressingModeString(p->value.addressingMode) << ','; + break; + case CL_SAMPLER_FILTER_MODE: + ss << getFilterModeString(p->value.filterMode) << ','; + break; + case CL_SAMPLER_MIP_FILTER_MODE: + ss << getFilterModeString(p->value.filterMode) << ','; + break; + case CL_SAMPLER_LOD_MIN: + ss << p->value.lod << ','; + break; + case CL_SAMPLER_LOD_MAX: + ss << p->value.lod << ','; + break; + default: + break; + } + ++p; + } + + addRec(&r); + cl_sampler ret = original_dispatch.CreateSamplerWithProperties( + context, sampler_properties, errcode_ret); + delRec(&r); + + ss << getErrorString(errcode_ret) << ") = " << ret; + ss << ret << std::endl; + + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +SetKernelArgSVMPointer(cl_kernel kernel, cl_uint arg_index, const void *arg_value) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clSetKernelArgSVMPointer(" << kernel << ','; + ss << arg_index << ','; + ss << arg_value; + + addRec(&r); + cl_int ret = original_dispatch.SetKernelArgSVMPointer( + kernel, arg_index, arg_value); + delRec(&r); + + ss << ") = " << getErrorString(ret); + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_int CL_API_CALL +SetKernelExecInfo( + cl_kernel kernel, + cl_kernel_exec_info param_name, + size_t param_value_size, + const void* param_value) +{ + std::ostringstream ss; + Rec r(&ss); + + ss << "clSetKernelExecInfo(" << kernel << ','; + ss << getKernelExecInfoString(param_name) << ','; + ss << param_value_size << ','; + + addRec(&r); + cl_int ret = original_dispatch.SetKernelExecInfo( + kernel, param_name, param_value_size, + param_value); + delRec(&r); + + ss << getHexString(const_cast(param_value)) << ") = "; + ss << getErrorString(ret); + + ss << std::endl; + std::cerr << ss.str(); + return ret; +} + +static cl_icd_dispatch_table +modified_dispatch = { + /* OpenCL 1.0 */ + GetPlatformIDs, + GetPlatformInfo, + GetDeviceIDs, + GetDeviceInfo, + CreateContext, + CreateContextFromType, + RetainContext, + ReleaseContext, + GetContextInfo, + CreateCommandQueue, + RetainCommandQueue, + ReleaseCommandQueue, + GetCommandQueueInfo, + SetCommandQueueProperty, + CreateBuffer, + CreateImage2D, + CreateImage3D, + RetainMemObject, + ReleaseMemObject, + GetSupportedImageFormats, + GetMemObjectInfo, + GetImageInfo, + CreateSampler, + RetainSampler, + ReleaseSampler, + GetSamplerInfo, + CreateProgramWithSource, + CreateProgramWithBinary, + RetainProgram, + ReleaseProgram, + BuildProgram, + UnloadCompiler, + GetProgramInfo, + GetProgramBuildInfo, + CreateKernel, + CreateKernelsInProgram, + RetainKernel, + ReleaseKernel, + SetKernelArg, + GetKernelInfo, + GetKernelWorkGroupInfo, + WaitForEvents, + GetEventInfo, + RetainEvent, + ReleaseEvent, + GetEventProfilingInfo, + Flush, + Finish, + EnqueueReadBuffer, + EnqueueWriteBuffer, + EnqueueCopyBuffer, + EnqueueReadImage, + EnqueueWriteImage, + EnqueueCopyImage, + EnqueueCopyImageToBuffer, + EnqueueCopyBufferToImage, + EnqueueMapBuffer, + EnqueueMapImage, + EnqueueUnmapMemObject, + EnqueueNDRangeKernel, + EnqueueTask, + EnqueueNativeKernel, + EnqueueMarker, + EnqueueWaitForEvents, + EnqueueBarrier, + GetExtensionFunctionAddress, + CreateFromGLBuffer, + CreateFromGLTexture2D, + CreateFromGLTexture3D, + CreateFromGLRenderbuffer, + GetGLObjectInfo, + GetGLTextureInfo, + EnqueueAcquireGLObjects, + EnqueueReleaseGLObjects, + GetGLContextInfoKHR, + { NULL, NULL, NULL, NULL, NULL, NULL }, /* _reservedForD3D10KHR[6] */ + + /* OpenCL 1.1 */ + SetEventCallback, + CreateSubBuffer, + SetMemObjectDestructorCallback, + CreateUserEvent, + SetUserEventStatus, + EnqueueReadBufferRect, + EnqueueWriteBufferRect, + EnqueueCopyBufferRect, + { NULL, NULL, NULL }, /* _reservedForDeviceFissionEXT[3] */ + NULL, /* CreateEventFromGLsyncKHR */ + + /* OpenCL 1.2 */ + NULL, /* CreateSubDevices */ + RetainDevice, + ReleaseDevice, + CreateImage, + CreateProgramWithBuiltInKernels, + CompileProgram, + LinkProgram, + UnloadPlatformCompiler, + GetKernelArgInfo, + EnqueueFillBuffer, + EnqueueFillImage, + EnqueueMigrateMemObjects, + EnqueueMarkerWithWaitList, + EnqueueBarrierWithWaitList, + GetExtensionFunctionAddressForPlatform, + CreateFromGLTexture, + { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, /* _reservedD3DExtensions[10] */ + { NULL, NULL, NULL, NULL }, /* _reservedEGLExtensions[4] */ + + /* OpenCL 2.0 */ + CreateCommandQueueWithProperties, + CreatePipe, + GetPipeInfo, + SVMAlloc, + SVMFree, + EnqueueSVMFree, + EnqueueSVMMemcpy, + EnqueueSVMMemFill, + EnqueueSVMMap, + EnqueueSVMUnmap, + CreateSamplerWithProperties, + SetKernelArgSVMPointer, + SetKernelExecInfo, + NULL, /* clGetKernelSubGroupInfoKHR */ + + /* OpenCL 2.1 */ + NULL, /* clCloneKernel */ + NULL, /* clCreateProgramWithILKHR */ + NULL, /* clEnqueueSVMMigrateMem */ + NULL, /* clGetDeviceAndHostTimer */ + NULL, /* clGetHostTimer */ + NULL, /* clGetKernelSubGroupInfo */ + NULL, /* clSetDefaultDeviceCommandQueue */ + + /* OpenCL 2.2 */ + NULL, /* clSetProgramReleaseCallback */ + NULL, /* clSetProgramSpecializationConstant */ +}; + +static void +cleanup(void) +{ + std::cerr.rdbuf(cerrStreamBufSave); +} + +#define SET_ORIGINAL_EXTENSION(DISPATCH) \ + memcpy(modified_dispatch._reservedFor##DISPATCH, \ + original_dispatch._reservedFor##DISPATCH, \ + sizeof(original_dispatch._reservedFor##DISPATCH)); + +#define SET_ORIGINAL(DISPATCH) \ + modified_dispatch.DISPATCH = original_dispatch.DISPATCH; + +int32_t CL_CALLBACK +vdiAgent_OnLoad(vdi_agent * agent) +{ + char *clTraceLogEnv; + + int32_t err = agent->GetICDDispatchTable( + agent, &original_dispatch, sizeof(original_dispatch)); + if (err != CL_SUCCESS) { + return err; + } + + clTraceLogEnv = getenv("CL_TRACE_OUTPUT"); + if(clTraceLogEnv!=NULL) { + std::string clTraceLogStr = clTraceLogEnv; + const std::size_t pidPos = clTraceLogStr.find("%pid%"); + if (pidPos != std::string::npos) { +#if defined(_WIN32) + const std::int32_t pid = _getpid(); +#else + const std::int32_t pid = getpid(); +#endif + clTraceLogStr.replace(pidPos, 5, std::to_string(pid)); + } + clTraceLog.open(clTraceLogStr); + cerrStreamBufSave = std::cerr.rdbuf(clTraceLog.rdbuf()); + std::atexit(cleanup); + } + + cl_platform_id platform; + err = agent->GetPlatform(agent, &platform); + if (err != CL_SUCCESS) { + return err; + } + + char version[256]; + err = original_dispatch.GetPlatformInfo( + platform, CL_PLATFORM_VERSION, sizeof(version), version, NULL); + if (err != CL_SUCCESS) { + return err; + } + + std::cerr << "!!!" << std::endl << "!!! API trace for \"" + << version << "\"" << std::endl << "!!!" << std::endl; + + SET_ORIGINAL_EXTENSION(D3D10KHR); + SET_ORIGINAL_EXTENSION(DeviceFissionEXT); + SET_ORIGINAL(CreateEventFromGLsyncKHR); + SET_ORIGINAL(CreateSubDevices); + SET_ORIGINAL_EXTENSION(D3DExtensions); + SET_ORIGINAL_EXTENSION(EGLExtensions); + SET_ORIGINAL(GetKernelSubGroupInfoKHR); + SET_ORIGINAL(CloneKernel); + SET_ORIGINAL(CreateProgramWithILKHR); + SET_ORIGINAL(EnqueueSVMMigrateMem); + SET_ORIGINAL(GetDeviceAndHostTimer); + SET_ORIGINAL(GetHostTimer); + SET_ORIGINAL(GetKernelSubGroupInfo); + SET_ORIGINAL(SetDefaultDeviceCommandQueue); + SET_ORIGINAL(SetProgramReleaseCallback); + SET_ORIGINAL(SetProgramSpecializationConstant); + + err = agent->SetICDDispatchTable( + agent, &modified_dispatch, sizeof(modified_dispatch)); + if (err != CL_SUCCESS) { + return err; + } + + initRecs(); + err = startChecker(); + return err; +} + +void CL_CALLBACK +vdiAgent_OnUnload(vdi_agent * agent) +{ + clTraceLog.close(); +} diff --git a/opencl/tools/cltrace/cltrace.def b/opencl/tools/cltrace/cltrace.def new file mode 100644 index 0000000000..ac65c8d11f --- /dev/null +++ b/opencl/tools/cltrace/cltrace.def @@ -0,0 +1,3 @@ +EXPORTS +vdiAgent_OnLoad +vdiAgent_OnUnload diff --git a/opencl/tools/cltrace/cltrace.map b/opencl/tools/cltrace/cltrace.map new file mode 100644 index 0000000000..81c4556452 --- /dev/null +++ b/opencl/tools/cltrace/cltrace.map @@ -0,0 +1,7 @@ +CLTRACE_1.0 { +global: + vdiAgent_OnLoad; + vdiAgent_OnUnload; +local: + *; +};