You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

opencl.cmake 2.1 kB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. if(ENABLE_GITEE)
  2. set(REQ_URL "https://gitee.com/mirrors/OpenCL-Headers/repository/archive/v2020.12.18.tar.gz")
  3. set(MD5 "9a34e50198ac54b795bf3822bb6e429a")
  4. set(PKG_GIT_TAG "")
  5. __download_pkg_with_git(OpenCL-Headers ${REQ_URL} ${PKG_GIT_TAG} ${MD5})
  6. set(REQ_URL "https://gitee.com/mirrors/OpenCL-CLHPP/repository/archive/v2.0.12.tar.gz")
  7. set(MD5 "3439d8eb6d247bfd02164bcd0c8e5adb")
  8. set(PKG_GIT_TAG "")
  9. __download_pkg_with_git(OpenCL-CLHPP ${REQ_URL} ${PKG_GIT_TAG} ${MD5})
  10. else()
  11. set(REQ_URL "https://github.com/KhronosGroup/OpenCL-Headers/archive/v2020.12.18.tar.gz")
  12. set(MD5 "ea0296fb79951f43082b742234f26c9a")
  13. __download_pkg(OpenCL-Headers ${REQ_URL} ${MD5})
  14. set(REQ_URL "https://github.com/KhronosGroup/OpenCL-CLHPP/archive/v2.0.12.tar.gz")
  15. set(MD5 "bd00fca8f861b3b65660d719f00a58dd")
  16. __download_pkg(OpenCL-CLHPP ${REQ_URL} ${MD5})
  17. endif()
  18. function(gene_opencl CL_SRC_DIR)
  19. message(STATUS "**********gene opencl********* cl path: " "${CL_SRC_DIR}")
  20. if(NOT EXISTS ${CL_SRC_DIR})
  21. return()
  22. endif()
  23. file(GLOB_RECURSE CL_LIST ${CL_SRC_DIR}/*.cl)
  24. foreach(file_path ${CL_LIST})
  25. file(REMOVE ${file_path}.inc)
  26. string(REGEX REPLACE ".+/(.+)\\..*" "\\1" kernel_name "${file_path}")
  27. set(inc_file_ex "${file_path}.inc")
  28. execute_process(
  29. COMMAND bash -c "sed 's/\\\\/\\\\\\\\/g' "
  30. COMMAND bash -c "sed 's/\\\"/\\\\\\\"/g' "
  31. COMMAND bash -c "sed 's/$/\\\\n\\\" \\\\/' "
  32. COMMAND bash -c "sed 's/^/\\\"/' "
  33. WORKING_DIRECTORY ${CL_SRC_DIR}
  34. INPUT_FILE ${file_path}
  35. OUTPUT_FILE ${inc_file_ex}
  36. RESULT_VARIABLE RESULT)
  37. if(NOT RESULT EQUAL "0")
  38. message(FATAL_ERROR "error! when generate ${inc_file_ex}")
  39. endif()
  40. __exec_cmd(COMMAND sed -i "1i\\static const char *${kernel_name}_source =\\\"\\\\n\\\" \\\\"
  41. ${inc_file_ex} WORKING_DIRECTORY ${CL_SRC_DIR})
  42. __exec_cmd(COMMAND sed -i "$a\\\\\;" ${inc_file_ex} WORKING_DIRECTORY ${CL_SRC_DIR})
  43. endforeach()
  44. endfunction()