xmake.lua 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package("arrayfire")
  2. set_homepage("https://arrayfire.org/")
  3. set_description("A general purpose GPU library.")
  4. set_license("BSD-3-Clause")
  5. add_urls("https://github.com/arrayfire/arrayfire/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/arrayfire/arrayfire.git")
  7. add_versions("v3.10.0", "959f6c00a5ad6e030a178271c3976bbb06a16eef77f431ed42f4fd003c73761c")
  8. add_versions("v3.9.0", "ffd078dde66a1a707d049f5d2dab128e86748a92ca7204d0b3a7933a9a9904be")
  9. add_configs("cpu", {description = "Build ArrayFire with a CPU backend.", default = true, type = "boolean"})
  10. add_configs("cuda", {description = "Build ArrayFire with a CUDA backend.", default = false, type = "boolean"})
  11. add_configs("opencl", {description = "Build ArrayFire with a OpenCL backend.", default = false, type = "boolean"})
  12. add_configs("oneapi", {description = "Build ArrayFire with a oneAPI backend.", default = false, type = "boolean"})
  13. add_configs("unified", {description = "Build Backend-Independent ArrayFire API.", default = true, type = "boolean"})
  14. add_configs("cudnn", {description = "Use cuDNN for convolveNN functions.", default = false, type = "boolean"})
  15. add_configs("forge", {description = "Forge libs are not built by default as it is not link time dependency.", default = false, type = "boolean"})
  16. add_configs("nonfree", {description = "Build ArrayFire nonfree algorithms.", default = false, type = "boolean"})
  17. add_configs("logging", {description = "Build ArrayFire with logging support.", default = true, type = "boolean"})
  18. add_configs("stacktrace", {description = "Add stacktraces to the error messages.", default = true, type = "boolean"})
  19. add_configs("kernel_to_disk", {description = "Enable caching kernels to disk.", default = true, type = "boolean"})
  20. add_configs("fast_math", {description = "Use lower precision but high performance numeric optimizations.", default = true, type = "boolean"})
  21. add_configs("compute_lib", {description = "Compute library for signal processing and linear algebra routines", default = "FFTW/LAPACK/BLAS", values = {"Intel-MKL", "FFTW/LAPACK/BLAS"}, type = "string"})
  22. add_configs("imageio", {description = "Build ArrayFire with Image IO support.", default = false, type = "boolean"})
  23. add_configs("mkl_thread_layer", {description = "The thread layer to choose for MKL.", default = "TBB", type = "string", values = {"TBB", "GNU OpenMP", "Intel OpenMP", "Sequential"}})
  24. if is_plat("windows", "mingw", "msys", "cygwin") then
  25. add_configs("stacktrace_type", {description = "The type of backtrace features.", default = "Windbg", values = {"None", "Windbg"}})
  26. else
  27. add_configs("stacktrace_type", {description = "The type of backtrace features.", default = "Basic", values = {"None", "Basic", "libbacktrace", "addr2line"}})
  28. end
  29. if is_plat("linux", "bsd") then
  30. add_syslinks("pthread")
  31. end
  32. add_deps("cmake")
  33. if not is_subhost("windows") then
  34. add_deps("pkg-config")
  35. else
  36. add_deps("pkgconf")
  37. end
  38. add_deps("opengl", "opengl-headers", "glad", "span-lite", "clblast", "fmt")
  39. add_deps("spdlog", {configs = {header_only = false}})
  40. add_deps("boost", {configs = {filesystem = false, stacktrace = true}})
  41. on_load(function (package)
  42. if package:config("cudnn") then
  43. package:config_set("cuda", true)
  44. end
  45. if package:config("cuda") then
  46. package:add("deps", "cuda", {configs = {utils = {"cusolver", "cudnn", "cufft", "cublas", "culibos", "cusparse", "nvrtc"}}})
  47. end
  48. if package:config("opencl") then
  49. package:add("deps", "opencl", "opencl-headers")
  50. end
  51. if package:config("imageio") then
  52. package:add("deps", "freeimage")
  53. package:add("defines", "WITH_FREEIMAGE")
  54. end
  55. if package:config("compute_lib") == "Intel-MKL" then
  56. package:add("deps", "mkl")
  57. if package:is_arch("x64", "x86_64", "arm64", "arm64ec", "arm64-v8a") then
  58. package:add("defines", "AF_MKL_INTERFACE_SIZE=8")
  59. else
  60. package:add("defines", "AF_MKL_INTERFACE_SIZE=4")
  61. end
  62. else
  63. package:add("deps", "fftw", {configs = {precisions = {"float", "double"}}})
  64. package:add("deps", "lapack")
  65. end
  66. local mkl_thread_layer_map = {
  67. Sequential = "0",
  68. ["GNU OpenMP"] = "1",
  69. ["Intel OpenMP"] = "2",
  70. TBB = "3"
  71. }
  72. local layer_val = mkl_thread_layer_map[package:config("mkl_thread_layer")] or "3"
  73. package:add("defines", "AF_MKL_THREAD_LAYER=" .. layer_val)
  74. end)
  75. -- the lapack dep in xrepo only supports linux :(
  76. on_install("linux", function (package)
  77. io.replace("CMakeLists.txt", "find_package(BLAS)", "pkg_check_modules(BLAS blas)", {plain = true})
  78. io.replace("CMakeLists.txt", "find_package(LAPACK)", "pkg_check_modules(LAPACK lapack)\nlink_directories(${LAPACK_LIBRARY_DIRS})", {plain = true})
  79. io.replace("src/backend/common/deterministicHash.cpp", "#include <numeric>", "#include <numeric>\n#include <cstdint>", {plain = true})
  80. io.replace("src/backend/common/ArrayFireTypesIO.hpp", "auto format(const arrayfire::common::Version& ver, FormatContext& ctx)", "auto format(const arrayfire::common::Version& ver, FormatContext& ctx) const", {plain = true})
  81. io.replace("src/backend/common/ArrayFireTypesIO.hpp", "bool show_", "mutable bool show_", {plain = true})
  82. local configs = {
  83. "-DAF_WITH_EXTERNAL_PACKAGES_ONLY=ON",
  84. "-DAF_BUILD_DOCS=OFF",
  85. "-DAF_BUILD_EXAMPLES=OFF",
  86. "-DBUILD_TESTING=OFF"
  87. }
  88. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  89. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  90. table.insert(configs, "-DAF_BUILD_CPU=" .. (package:config("cpu") and "ON" or "OFF"))
  91. table.insert(configs, "-DAF_BUILD_CUDA=" .. (package:config("cuda") and "ON" or "OFF"))
  92. table.insert(configs, "-DAF_BUILD_OPENCL=" .. (package:config("opencl") and "ON" or "OFF"))
  93. table.insert(configs, "-DAF_BUILD_ONEAPI=" .. (package:config("oneapi") and "ON" or "OFF"))
  94. table.insert(configs, "-DAF_BUILD_UNIFIED=" .. (package:config("unified") and "ON" or "OFF"))
  95. table.insert(configs, "-DAF_WITH_CUDNN=" .. (package:config("cudnn") and "ON" or "OFF"))
  96. table.insert(configs, "-DAF_BUILD_FORGE=" .. (package:config("forge") and "ON" or "OFF"))
  97. table.insert(configs, "-DAF_WITH_NONFREE=" .. (package:config("nonfree") and "ON" or "OFF"))
  98. table.insert(configs, "-DAF_WITH_LOGGING=" .. (package:config("logging") and "ON" or "OFF"))
  99. table.insert(configs, "-DAF_WITH_STACKTRACE=" .. (package:config("stacktrace") and "ON" or "OFF"))
  100. table.insert(configs, "-DAF_CACHE_KERNELS_TO_DISK=" .. (package:config("kernel_to_disk") and "ON" or "OFF"))
  101. table.insert(configs, "-DAF_WITH_FAST_MATH=" .. (package:config("fast_math") and "ON" or "OFF"))
  102. table.insert(configs, "-DAF_COMPUTE_LIBRARY=" .. package:config("compute_lib"))
  103. table.insert(configs, "-DAF_STACKTRACE_TYPE=" .. package:config("stacktrace_type"))
  104. if package:dep("freeimage") then
  105. if not package:dep("freeimage"):config("shared") then
  106. table.insert(configs, "-DAF_WITH_STATIC_FREEIMAGE=ON")
  107. package:add("defines", "FREEIMAGE_STATIC")
  108. else
  109. table.insert(configs, "-DAF_WITH_STATIC_FREEIMAGE=OFF")
  110. end
  111. end
  112. if package:dep("mkl") then
  113. table.insert(configs, "-DAF_WITH_STATIC_MKL=" .. (package:dep("mkl"):config("shared") and "OFF" or "ON"))
  114. end
  115. import("package.tools.cmake").install(package, configs)
  116. end)
  117. on_test(function (package)
  118. assert(package:check_cxxsnippets({test = [[
  119. using namespace af;
  120. void test() {
  121. array A = randu(5, 3, f32);
  122. af_print(A);
  123. }
  124. ]]}, {configs = {languages = "c++17"}, includes = "arrayfire.h"}))
  125. end)