Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ComputeLibrary] Add new package for ARM-software/ComputeLibrary #19958

Merged
merged 12 commits into from
Aug 22, 2024
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"
jcar87 marked this conversation as resolved.
Show resolved Hide resolved
126 changes: 126 additions & 0 deletions recipes/compute_library/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
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.gnu import AutotoolsDeps
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": True,
"enable_neon": True,
}

@property
def _min_cppstd(self):
return 14
uilianries marked this conversation as resolved.
Show resolved Hide resolved

@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" not in str(self.settings.arch):
del self.options.enable_neon
# INFO: OpenMP option only works with g++, according to the documentation
if self.settings.compiler == "clang":
del self.options.enable_openmp
# INFO: OpenCL fails to build with MacOS
if self.settings.os == "Macos":
self.options.enable_opencl = False

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 requirements(self):
if self.options.enable_opencl:
self.requires("opencl-headers/2023.04.17")

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"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arm and x86 usually imply 32bits
should we write arm / arm64 and x86_64 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good clarification.

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 = AutotoolsDeps(self)
tc.generate()
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
# INFO: https://arm-software.github.io/ComputeLibrary/latest/how_to_build.xhtml
yes_no = lambda v: "1" if v else "0"
debug = yes_no(self.settings.build_type == "Debug")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can also add these options for debug debug=1 asserts=1 logging=1

build_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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ARM compute allows to build code with armv8.2a (fp16 support), SVE and SME.
How to use it via this recipe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example Apple M1, M2 support fp16, so we need to enable it by default.

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={build_os} arch={arch} build={build} build_dir={self.build_folder} install_dir={self.package_folder} -j{build_jobs(self)}", env="conanbuild")

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