Skip to content

Commit

Permalink
Add ComputeLibrary
Browse files Browse the repository at this point in the history
Signed-off-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
uilianries committed Sep 19, 2023
1 parent ef547a5 commit 34022db
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/compute_library/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"23.08":
url: "https://github.com/ARM-software/ComputeLibrary/archive/refs/tags/v23.08.tar.gz"
sha256: "62f514a555409d4401e5250b290cdf8cf1676e4eb775e5bd61ea6a740a8ce24f"
115 changes: 115 additions & 0 deletions recipes/compute_library/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import get, copy, rm, chdir
from conan.tools.build import check_min_cppstd, cross_building, build_jobs
from conan.tools.scm import Version
from conan.tools.env import VirtualBuildEnv
from conan.tools.layout import basic_layout
import os


required_conan_version = ">=1.53.0"


class ComputeLibraryConan(ConanFile):
name = "compute_library"
description = "The Compute Library is a set of computer vision and machine learning functions optimized for both Arm CPUs and GPUs using SIMD technologies"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/ARM-software/ComputeLibrary"
topics = ("android", "linux", "machine-learning", "arm", "computer-vision", "neural-network")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"enable_openmp": [True, False],
"enable_opencl": [True, False],
"enable_neon": [True, False],
}
default_options = {
"shared": False,
"enable_openmp": False,
"enable_opencl": False,
"enable_neon": True,
}

@property
def _min_cppstd(self):
return 14

@property
def _compilers_minimum_version(self):
return {
"gcc": "10",
"clang": "5",
"apple-clang": "5.1",
}

def config_options(self):
# INFO: Neon option is reserved to arm architecture
if "arm" in str(self.settings.arch):
del self.options.enable_neon
# INFO: OpenCL option only works with g++, according to the documentation
if self.settings.compiler == "clang":
del self.options.enable_openmp

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def layout(self):
basic_layout(self, src_folder="src")

def build_requirements(self):
self.tool_requires("scons/4.3.0")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.")
supported_os = ["Android", "Linux", "OpenBSD", "Macos", "Tizen"]
if str(self.settings.os) not in supported_os:
raise ConanInvalidConfiguration(f"{self.ref} does not support {self.settings.os}. It is only supported on {supported_os}.")
if "arm" not in str(self.settings.arch) and "x86" not in str(self.settings.arch):
raise ConanInvalidConfiguration(f"{self.ref} does not support {self.settings.arch}. It is only supported on arm and x86.")
if "x86" in str(self.settings.arch) and (self.options.get_safe("enable_neon") or not self.options.enable_opencl):
raise ConanInvalidConfiguration(f"{self.ref} can be built for x86_64 targets only with enable_neon=False and enable_opencl=True.")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = VirtualBuildEnv(self)
tc.generate(scope="build")

def build(self):
# INFO: Using scons to build the library we don't have control over shared/static and install step, it is done all together always
yes_no = lambda v: "1" if v else "0"
debug = yes_no(self.settings.build_type == "Debug")
os = str(self.settings.os).lower()
arch = {"armv8": "armv8a", "x86": "x86_32", "armv7": "armv7a", "armv7hf": "armv7a-hf"}.get(str(self.settings.arch), str(self.settings.arch))
neon = yes_no(self.options.get_safe("enable_neon"))
opencl = yes_no(self.options.enable_opencl)
openmp = yes_no(self.options.get_safe("enable_openmp"))
build = "cross_compile" if cross_building(self) else "native"
with chdir(self, self.source_folder):
self.run(f"scons Werror=0 validation_tests=0 examples=0 openmp={openmp} debug={debug} neon={neon} opencl={opencl} os={os} arch={arch} build={build} build_dir={self.build_folder} install_dir={self.package_folder} -j{build_jobs(self)}", env="conanbuildenv")

def package(self):
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
# INFO: Artifacts are installed during build step, so we just need to remove what we don't want
rm(self, "*.bazel", self.package_folder, recursive=True)
rm(self, "*.cpp", self.package_folder, recursive=True)
if self.options.shared:
rm(self, "*.a", os.path.join(self.package_folder, "lib"))
else:
rm(self, "*.so*", os.path.join(self.package_folder, "lib"))
rm(self, "*.dylib*", os.path.join(self.package_folder, "lib"))

def package_info(self):
suffix = "" if self.options.shared else "-static"
self.cpp_info.libs = [f"arm_compute{suffix}", f"arm_compute_core{suffix}", f"arm_compute_graph{suffix}"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m", "pthread"]
8 changes: 8 additions & 0 deletions recipes/compute_library/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package CXX)

find_package(compute_library REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE compute_library::compute_library)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
26 changes: 26 additions & 0 deletions recipes/compute_library/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
11 changes: 11 additions & 0 deletions recipes/compute_library/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <cstdlib>
#include <iostream>
#include "arm_compute/core/Version.h"


int main(void) {
std::cout << "ComputeLibrary information:" << std::endl;
std::cout << arm_compute::build_information() << std::endl;

return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/compute_library/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"23.08":
folder: all

0 comments on commit 34022db

Please sign in to comment.