|
| 1 | +from conans import ConanFile, CMake, tools |
| 2 | +import os |
| 3 | + |
| 4 | + |
| 5 | +ARRAYFIRE_VERSION = "3.7.1" |
| 6 | +BINARY_INSTALLER_NAME_SUFFIX = "-1" |
| 7 | +BINARY_INSTALLER_NAME = f"ArrayFire-v{ARRAYFIRE_VERSION}{BINARY_INSTALLER_NAME_SUFFIX}_Linux_x86_64.sh" |
| 8 | +CUDA_TOOLKIT_VERSION = "10.0" |
| 9 | + |
| 10 | +class ArrayFireConan(ConanFile): |
| 11 | + name = "arrayfire" |
| 12 | + version = ARRAYFIRE_VERSION |
| 13 | + license = "BSD" |
| 14 | + author = "jacobkahn jacobkahn1@gmail.com" |
| 15 | + url = "https://github.com/arrayfire/arrayfire" |
| 16 | + requires = [] |
| 17 | + description = "ArrayFire: a general purpose GPU library" |
| 18 | + topics = ("arrayfire", "gpu", "cuda", "opencl", "gpgpu", |
| 19 | + "hpc", "performance", "scientific-computing") |
| 20 | + settings = "os", "compiler", "build_type", "arch" |
| 21 | + options = { |
| 22 | + "cpu_backend": [True, False], |
| 23 | + "cuda_backend": [True, False], |
| 24 | + "opencl_backend": [True, False], |
| 25 | + "unified_backend": [True, False], |
| 26 | + "graphics": [True, False], |
| 27 | + } |
| 28 | + generators = "cmake" # unused |
| 29 | + |
| 30 | + def configure(self): |
| 31 | + if self.settings.os == "Windows": |
| 32 | + raise ConanInvalidConfiguration( |
| 33 | + "Linux binary installer not compaible with Windows.") |
| 34 | + |
| 35 | + def requirements(self): |
| 36 | + if self.options.graphics: |
| 37 | + self.requires('glfw/3.3.2@bincrafters/stable') |
| 38 | + |
| 39 | + def _download_arrayfire(self): |
| 40 | + self.af_installer_local_path = BINARY_INSTALLER_NAME |
| 41 | + if not os.path.exists(self.af_installer_local_path): |
| 42 | + self.output.info( |
| 43 | + f"Downloading the ArrayFire {ARRAYFIRE_VERSION} binary installer...") |
| 44 | + tools.download( |
| 45 | + f"https://arrayfire.s3.amazonaws.com/{ARRAYFIRE_VERSION}/{BINARY_INSTALLER_NAME}", self.af_installer_local_path) |
| 46 | + self.output.success( |
| 47 | + f"ArrayFire {ARRAYFIRE_VERSION} binary installer successfully downloaded to {self.af_installer_local_path}") |
| 48 | + else: |
| 49 | + self.output.info( |
| 50 | + f"ArrayFire {ARRAYFIRE_VERSION} binary installer already exists - skipping download.") |
| 51 | + |
| 52 | + def _unpack_arrayfire(self): |
| 53 | + if not os.path.exists(self.af_unpack_path): |
| 54 | + os.mkdir(self.af_unpack_path) |
| 55 | + self.output.info( |
| 56 | + f"Unpacking ArrayFire {ARRAYFIRE_VERSION} binary installer...") |
| 57 | + cmd = f"bash {self.af_installer_local_path} --prefix={self.af_unpack_path} --skip-license" |
| 58 | + self.run(cmd) |
| 59 | + self.output.success( |
| 60 | + f"ArrayFire {ARRAYFIRE_VERSION} successfully unpacked.") |
| 61 | + |
| 62 | + def _process_arrayfire(self): |
| 63 | + # Install ArrayFire to requisite path |
| 64 | + self.af_unpack_path = os.path.join(self.source_folder, 'arrayfire') |
| 65 | + |
| 66 | + # Only proceed if missing |
| 67 | + if os.path.exists(os.path.join(self.af_unpack_path, 'include', 'arrayfire.h')): |
| 68 | + self.output.info( |
| 69 | + f"ArrayFire {ARRAYFIRE_VERSION} already unpacked - skipping.") |
| 70 | + else: |
| 71 | + self._download_arrayfire() |
| 72 | + self._unpack_arrayfire() |
| 73 | + |
| 74 | + def build(self): |
| 75 | + self._process_arrayfire() |
| 76 | + |
| 77 | + def package(self): |
| 78 | + # libs |
| 79 | + self.copy("*.so", dst="lib", keep_path=False, symlinks=True) |
| 80 | + self.copy("*.so.*", dst="lib", keep_path=False, symlinks=True) |
| 81 | + |
| 82 | + # headers |
| 83 | + self.copy("*.h", dst="include", src="arrayfire/include") |
| 84 | + self.copy("*.hpp", dst="include", src="arrayfire/include") |
| 85 | + |
| 86 | + def package_info(self): |
| 87 | + self.cpp_info.libs = [] |
| 88 | + if self.options.unified_backend: |
| 89 | + self.cpp_info.libs.extend([ |
| 90 | + f"libaf.so.{ARRAYFIRE_VERSION}", |
| 91 | + ]) |
| 92 | + if self.options.graphics: |
| 93 | + self.cpp_info.libs.extend([ |
| 94 | + "libforge.so.1.0.5", |
| 95 | + ]) |
| 96 | + if self.options.cuda_backend: |
| 97 | + self.cpp_info.libs.extend([ |
| 98 | + f"libafcuda.so.{ARRAYFIRE_VERSION}", |
| 99 | + "libnvrtc-builtins.so", |
| 100 | + f"libcudnn.so.{CUDA_TOOLKIT_VERSION}", |
| 101 | + f"libcusparse.so.{CUDA_TOOLKIT_VERSION}", |
| 102 | + f"libcublas.so.{CUDA_TOOLKIT_VERSION}", |
| 103 | + f"libcusolver.so.{CUDA_TOOLKIT_VERSION}", |
| 104 | + f"libnvrtc.so.{CUDA_TOOLKIT_VERSION}", |
| 105 | + f"libcufft.so.{CUDA_TOOLKIT_VERSION}", |
| 106 | + ]) |
| 107 | + if self.options.cpu_backend: |
| 108 | + self.cpp_info.libs.extend([ |
| 109 | + f"libafcpu.so.{ARRAYFIRE_VERSION}", |
| 110 | + "libmkl_avx2.so", |
| 111 | + "libmkl_mc.so", |
| 112 | + "libmkl_intel_lp64.so", |
| 113 | + "libmkl_core.so", |
| 114 | + "libmkl_avx.so", |
| 115 | + "libmkl_def.so", |
| 116 | + "libiomp5.so", |
| 117 | + "libmkl_avx512.so", |
| 118 | + "libmkl_intel_thread.so", |
| 119 | + "libmkl_mc3.so", |
| 120 | + |
| 121 | + ]) |
| 122 | + if self.options.opencl_backend: |
| 123 | + self.cpp_info.libs.extend([ |
| 124 | + f"libafopencl.so.{ARRAYFIRE_VERSION}", |
| 125 | + "libOpenCL.so.1", |
| 126 | + ]) |
0 commit comments