Skip to content

Commit

Permalink
(conan-io#12705) OpenBlas: Add arch target option
Browse files Browse the repository at this point in the history
  • Loading branch information
aborzunov committed Oct 14, 2022
1 parent 399efd2 commit 6513bb2
Showing 1 changed file with 157 additions and 9 deletions.
166 changes: 157 additions & 9 deletions recipes/openblas/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,148 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile, CMake
from conan.errors import ConanInvalidConfiguration
from conan.tools import cross_building
from conan.tools.scm import Version
from conan.tools.files import get, replace_in_file, rmdir, collect_libs
import os
import functools

required_conan_version = ">=1.43.0"

# Copypasting here content of OpenBlas/TargetList.txt
# https://github.com/xianyi/OpenBLAS/blob/develop/TargetList.txt
# https://github.com/xianyi/OpenBLAS#normal-compile
openblas_target_list = [
"native", # We rely on architecture detection in OpenBlas cmake scripts

# 1.X86/X86_64
# a)Intel CPU:
"P2",
"KATMAI",
"COPPERMINE",
"NORTHWOOD",
"PRESCOTT",
"BANIAS",
"YONAH",
"CORE2",
"PENRYN",
"DUNNINGTON",
"NEHALEM",
"SANDYBRIDGE",
"HASWELL",
"SKYLAKEX",
"ATOM",
"COOPERLAKE",
"SAPPHIRERAPIDS",

# b)AMD CPU:
"ATHLON",
"OPTERON",
"OPTERON_SSE3",
"BARCELONA",
"SHANGHAI",
"ISTANBUL",
"BOBCAT",
"BULLDOZER",
"PILEDRIVER",
"STEAMROLLER",
"EXCAVATOR",
"ZEN",

# c)VIA CPU:
"SSE_GENERIC",
"VIAC3",
"NANO",

# 2.Power CPU:
"POWER4",
"POWER5",
"POWER6",
"POWER7",
"POWER8",
"POWER9",
"POWER10",
"PPCG4",
"PPC970",
"PPC970MP",
"PPC440",
"PPC440FP2",
"CELL",

# 3.MIPS CPU:
"P5600",
"MIPS1004K",
"MIPS24K",

# 4.MIPS64 CPU:
"MIPS64_GENERIC",
"SICORTEX",
"LOONGSON3A",
"LOONGSON3B",
"I6400",
"P6600",
"I6500",

# 5.IA64 CPU:
"ITANIUM2",

# 6.SPARC CPU:
"SPARC",
"SPARCV7",

# 7.ARM CPU:
"CORTEXA15",
"CORTEXA9",
"ARMV7",
"ARMV6",
"ARMV5",

# 8.ARM 64-bit CPU:
"ARMV8",
"CORTEXA53",
"CORTEXA57",
"CORTEXA72",
"CORTEXA73",
"CORTEXA510",
"CORTEXA710",
"CORTEXX1",
"CORTEXX2",
"NEOVERSEN1",
"NEOVERSEV1",
"NEOVERSEN2",
"CORTEXA55",
"EMAG8180",
"FALKOR",
"THUNDERX",
"THUNDERX2T99",
"TSV110",
"THUNDERX3T110",
"VORTEX",
"A64FX",
"ARMV8SVE",
"FT2000",

# 9.System Z:
"ZARCH_GENERIC",
"Z13",
"Z14",

# 10.RISC-V 64:
"RISCV64_GENERIC",
"C910V",

# 11.LOONGARCH64:
"LOONGSONGENERIC",
"LOONGSON3R5",
"LOONGSON2K1000",

# 12. Elbrus E2000:
"E2K",

# 13. Alpha
"EV4",
"EV5",
"EV6",
]

class OpenblasConan(ConanFile):
name = "openblas"
Expand All @@ -20,13 +158,15 @@ class OpenblasConan(ConanFile):
"build_lapack": [True, False],
"use_thread": [True, False],
"dynamic_arch": [True, False],
"target": openblas_target_list,
}
default_options = {
"shared": False,
"fPIC": True,
"build_lapack": False,
"use_thread": True,
"dynamic_arch": False,
"target": "native",
}
generators = "cmake"
short_paths = True
Expand All @@ -51,11 +191,11 @@ def configure(self):
del self.options.fPIC

def validate(self):
if hasattr(self, "settings_build") and tools.cross_building(self, skip_x64_x86=True):
if hasattr(self, "settings_build") and cross_building(self, skip_x64_x86=True):
raise ConanInvalidConfiguration("Cross-building not implemented")

def source(self):
tools.get(
get(
**self.conan_data["sources"][self.version],
strip_root=True,
destination=self._source_subfolder
Expand All @@ -72,6 +212,14 @@ def _configure_cmake(self):
cmake.definitions["DYNAMIC_ARCH"] = self.options.dynamic_arch
cmake.definitions["USE_THREAD"] = self.options.use_thread

if self.options.target != "native":
cmake.definitions["TARGET"] = self.options.target
self.output.info(
f"Setting target arch to {self.options.target} and "
"passing this as value to TARGET variable of openblas cmake. "
"For more information, check out "
"https://github.com/xianyi/OpenBLAS#normal-compile")

# Required for safe concurrent calls to OpenBLAS routines
cmake.definitions["USE_LOCKING"] = not self.options.use_thread

Expand All @@ -87,7 +235,7 @@ def _configure_cmake(self):
return cmake

def build(self):
if tools.Version(self.version) >= "0.3.12":
if Version(self.version) >= "0.3.12":
search = """message(STATUS "No Fortran compiler found, can build only BLAS but not LAPACK")"""
replace = (
"""message(FATAL_ERROR "No Fortran compiler found. Cannot build with LAPACK.")"""
Expand All @@ -104,7 +252,7 @@ def build(self):
set (NO_LAPACK 1)
endif()"""

tools.replace_in_file(
replace_in_file(
os.path.join(self._source_subfolder, "cmake", "f_check.cmake"),
search,
replace,
Expand All @@ -116,8 +264,8 @@ def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))
rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(os.path.join(self.package_folder, "share"))

def package_info(self):
# CMake config file:
Expand All @@ -132,7 +280,7 @@ def package_info(self):
self.cpp_info.components["openblas_component"].includedirs.append(
os.path.join("include", "openblas")
)
self.cpp_info.components["openblas_component"].libs = tools.collect_libs(self)
self.cpp_info.components["openblas_component"].libs = collect_libs(self)
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["openblas_component"].system_libs.append("m")
if self.options.use_thread:
Expand Down

0 comments on commit 6513bb2

Please sign in to comment.