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

new package: codon #23088

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/codon/0001-custom-openmp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--- a/cmake/deps.cmake
+++ b/cmake/deps.cmake
@@ -1,4 +1,4 @@
-set(CPM_DOWNLOAD_VERSION 0.32.3)
+set(CPM_DOWNLOAD_VERSION 0.40.0)
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake...")
@@ -96,6 +96,7 @@
GITHUB_REPOSITORY "exaloop/openmp"
GIT_TAG 11daa2021c590dc74a0e734b4783570b619d88c9
EXCLUDE_FROM_ALL YES
+ PATCHES "${CMAKE_SOURCE_DIR}/patches/openmp.diff"
OPTIONS "CMAKE_BUILD_TYPE Release"
"OPENMP_ENABLE_LIBOMPTARGET OFF"
"OPENMP_STANDALONE_BUILD ON")
29 changes: 29 additions & 0 deletions packages/codon/0002-do-not-pass-no-pie-to-c-compiler.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--- a/codon/cir/llvm/llvisitor.cpp
+++ b/codon/cir/llvm/llvisitor.cpp
@@ -563,10 +563,12 @@
command.push_back(uflag.str());
}

+#ifndef __ANDROID__
// Avoid "relocation R_X86_64_32 against `.bss' can not be used when making a PIE
// object" complaints by gcc when it is built with --enable-default-pie
if (!library)
command.push_back("-no-pie");
+#endif

executeCommand(command);

--- a/codon/cir/llvm/optimize.cpp
+++ b/codon/cir/llvm/optimize.cpp
@@ -25,7 +25,11 @@

return std::unique_ptr<llvm::TargetMachine>(target->createTargetMachine(
triple.getTriple(), cpuStr, featuresStr, options,
+#ifndef __ANDROID__
pic ? llvm::Reloc::Model::PIC_ : llvm::codegen::getExplicitRelocModel(),
+#else
+ llvm::Reloc::Model::PIC_,
+#endif
llvm::codegen::getExplicitCodeModel(), llvm::CodeGenOpt::Aggressive));
}

36 changes: 36 additions & 0 deletions packages/codon/0003-do-not-copy-libs-for-android.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -129,6 +129,8 @@
add_library(libgfortran SHARED IMPORTED)
set_target_properties(libgfortran PROPERTIES IMPORTED_LOCATION ${copied_libgfortran})
target_link_libraries(codonrt PRIVATE libgfortran)
+elseif(ANDROID)
+ # Do nothing
else()
message(FATAL_ERROR "Set 'CODON_SYSTEM_LIBRARIES' to the directory containing system libraries.")
endif()
@@ -471,13 +473,7 @@
COMMAND
${CMAKE_COMMAND} -E copy
"${CMAKE_BINARY_DIR}/libomp${CMAKE_SHARED_LIBRARY_SUFFIX}"
- "${CMAKE_BINARY_DIR}/lib/codon"
- COMMAND
- ${CMAKE_COMMAND} -E copy ${copied_libgfortran} "${CMAKE_BINARY_DIR}/lib/codon"
- COMMAND
- ${CMAKE_COMMAND} -E copy ${copied_libquadmath} "${CMAKE_BINARY_DIR}/lib/codon"
- COMMAND
- ${CMAKE_COMMAND} -E copy ${copied_libgcc} "${CMAKE_BINARY_DIR}/lib/codon")
+ "${CMAKE_BINARY_DIR}/lib/codon")
add_dependencies(libs codonrt codonc)

# Codon command-line tool
@@ -520,9 +516,6 @@

install(TARGETS codonrt codonc codon_jupyter DESTINATION lib/codon)
install(FILES ${CMAKE_BINARY_DIR}/libomp${CMAKE_SHARED_LIBRARY_SUFFIX} DESTINATION lib/codon)
-install(FILES ${copied_libgfortran} DESTINATION lib/codon)
-install(FILES ${copied_libquadmath} DESTINATION lib/codon)
-install(FILES ${copied_libgcc} DESTINATION lib/codon)
install(TARGETS codon DESTINATION bin)
install(DIRECTORY ${CMAKE_BINARY_DIR}/include/codon DESTINATION include)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/stdlib DESTINATION lib/codon)
12 changes: 12 additions & 0 deletions packages/codon/0004-openblas-disable-dynamic-arch.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- a/cmake/deps.cmake
+++ b/cmake/deps.cmake
@@ -172,7 +172,8 @@
GITHUB_REPOSITORY "OpenMathLib/OpenBLAS"
GIT_TAG v0.3.28
EXCLUDE_FROM_ALL YES
- OPTIONS "DYNAMIC_ARCH ON"
+ OPTIONS "C_LAPACK ON"
+ "$ENV{OPENBLAS_CROSS_TARGET}"
"BUILD_TESTING OFF"
"BUILD_BENCHMARKS OFF"
"NUM_THREADS 64"
183 changes: 183 additions & 0 deletions packages/codon/0005-hwy-use-cmp-function-rather-than-operator.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
--- a/codon/runtime/numpy/loops.cpp
+++ b/codon/runtime/numpy/loops.cpp
@@ -10,6 +10,8 @@
#include "hwy/contrib/math/math-inl.h"
// clang-format on

+#pragma clang diagnostic ignored "-Wvla-cxx-extension"
+
#include <cmath>
#include <cstring>
#include <limits>
@@ -20,6 +22,7 @@
namespace HWY_NAMESPACE {

namespace hn = hwy::HWY_NAMESPACE;
+using namespace hn;

struct AcosFunctor {
template <typename T, typename V>
@@ -38,7 +41,7 @@
const auto nan = Set(d, std::numeric_limits<T>::quiet_NaN());
const auto pinf = Set(d, std::numeric_limits<T>::infinity());
const auto pone = Set(d, static_cast<T>(1.0));
- return IfThenElse(v == pinf, pinf, IfThenElse(v < pone, nan, Acosh(d, v)));
+ return IfThenElse(Eq(v, pinf), pinf, IfThenElse(Lt(v, pone), nan, Acosh(d, v)));
}

static inline double scalar(const double x) { return acosh(x); }
@@ -78,7 +81,7 @@
const auto npi2 = Set(d, static_cast<T>(-3.14159265358979323846264 / 2));
const auto pinf = Set(d, std::numeric_limits<T>::infinity());
const auto ninf = Set(d, -std::numeric_limits<T>::infinity());
- return IfThenElse(v == pinf, ppi2, IfThenElse(v == ninf, npi2, Atan(d, v)));
+ return IfThenElse(Eq(v, pinf), ppi2, IfThenElse(Eq(v, ninf), npi2, Atan(d, v)));
}

static inline double scalar(const double x) { return atan(x); }
@@ -96,8 +99,8 @@
const auto none = Set(d, static_cast<T>(-1.0));
const auto nzero = Set(d, static_cast<T>(0.0));
return IfThenElse(
- v == pone, pinf,
- IfThenElse(v == none, ninf, IfThenElse(Abs(v) > pone, nan, Atanh(d, v))));
+ Eq(v, pone), pinf,
+ IfThenElse(Eq(v, none), ninf, IfThenElse(Gt(Abs(v), pone), nan, Atanh(d, v))));
}

static inline double scalar(const double x) { return atanh(x); }
@@ -117,8 +120,8 @@
auto nzero = Set(di, kIsF32 ? static_cast<TI>(0x80000000L)
: static_cast<TI>(0x8000000000000000LL));

- auto negneg = And(BitCast(di, v1) == nzero, BitCast(di, v2) == nzero);
- auto posneg = And(BitCast(di, v1) == pzero, BitCast(di, v2) == nzero);
+ auto negneg = And(Eq(BitCast(di, v1), nzero), Eq(BitCast(di, v2), nzero));
+ auto posneg = And(Eq(BitCast(di, v1), pzero), Eq(BitCast(di, v2), nzero));

const auto ppi = Set(d, static_cast<T>(+3.14159265358979323846264));
const auto npi = Set(d, static_cast<T>(-3.14159265358979323846264));
@@ -148,7 +151,7 @@
static inline auto vector(const hn::ScalableTag<T> d, const V &v) {
// Values outside of [-LIMIT, LIMIT] are not valid for SIMD version.
const T LIMIT = limit<T>();
- constexpr size_t L = hn::Lanes(d);
+ const size_t L = hn::Lanes(d);
T tmp[L];
Store(v, d, tmp);

@@ -185,7 +188,7 @@
static inline auto vector(const hn::ScalableTag<T> d, const V &v) {
const auto lim = Set(d, limit<T>());
const auto pinf = Set(d, std::numeric_limits<T>::infinity());
- return IfThenElse(IsNaN(v), v, IfThenElse(v >= lim, pinf, Exp(d, v)));
+ return IfThenElse(IsNaN(v), v, IfThenElse(Ge(v, lim), pinf, Exp(d, v)));
}

static inline double scalar(const double x) { return exp(x); }
@@ -208,7 +211,7 @@
static inline auto vector(const hn::ScalableTag<T> d, const V &v) {
const auto lim = Set(d, limit<T>());
const auto pinf = Set(d, std::numeric_limits<T>::infinity());
- return IfThenElse(IsNaN(v), v, IfThenElse(v >= lim, pinf, Exp2(d, v)));
+ return IfThenElse(IsNaN(v), v, IfThenElse(Ge(v, lim), pinf, Exp2(d, v)));
}

static inline double scalar(const double x) { return exp2(x); }
@@ -231,7 +234,7 @@
static inline auto vector(const hn::ScalableTag<T> d, const V &v) {
const auto lim = Set(d, limit<T>());
const auto pinf = Set(d, std::numeric_limits<T>::infinity());
- return IfThenElse(IsNaN(v), v, IfThenElse(v >= lim, pinf, Expm1(d, v)));
+ return IfThenElse(IsNaN(v), v, IfThenElse(Ge(v, lim), pinf, Expm1(d, v)));
}

static inline double scalar(const double x) { return expm1(x); }
@@ -247,9 +250,9 @@
const auto ninf = Set(d, -std::numeric_limits<T>::infinity());
const auto zero = Set(d, static_cast<T>(0.0));
return IfThenElse(
- v == zero, ninf,
- IfThenElse(v < zero, nan,
- IfThenElse(v == pinf, pinf, IfThenElse(IsNaN(v), v, Log(d, v)))));
+ Eq(v, zero), ninf,
+ IfThenElse(Lt(v, zero), nan,
+ IfThenElse(Eq(v, pinf), pinf, IfThenElse(IsNaN(v), v, Log(d, v)))));
}

static inline double scalar(const double x) { return log(x); }
@@ -265,9 +268,9 @@
const auto ninf = Set(d, -std::numeric_limits<T>::infinity());
const auto zero = Set(d, static_cast<T>(0.0));
return IfThenElse(
- v == zero, ninf,
- IfThenElse(v < zero, nan,
- IfThenElse(v == pinf, pinf, IfThenElse(IsNaN(v), v, Log10(d, v)))));
+ Eq(v, zero), ninf,
+ IfThenElse(Lt(v, zero), nan,
+ IfThenElse(Eq(v, pinf), pinf, IfThenElse(IsNaN(v), v, Log10(d, v)))));
}

static inline double scalar(const double x) { return log10(x); }
@@ -283,9 +286,9 @@
const auto ninf = Set(d, -std::numeric_limits<T>::infinity());
const auto none = Set(d, static_cast<T>(-1.0));
return IfThenElse(
- v == none, ninf,
- IfThenElse(v < none, nan,
- IfThenElse(v == pinf, pinf, IfThenElse(IsNaN(v), v, Log1p(d, v)))));
+ Eq(v, none), ninf,
+ IfThenElse(Lt(v, none), nan,
+ IfThenElse(Eq(v, pinf), pinf, IfThenElse(IsNaN(v), v, Log1p(d, v)))));
}

static inline double scalar(const double x) { return log1p(x); }
@@ -301,9 +304,9 @@
const auto ninf = Set(d, -std::numeric_limits<T>::infinity());
const auto zero = Set(d, static_cast<T>(0.0));
return IfThenElse(
- v == zero, ninf,
- IfThenElse(v < zero, nan,
- IfThenElse(v == pinf, pinf, IfThenElse(IsNaN(v), v, Log2(d, v)))));
+ Eq(v, zero), ninf,
+ IfThenElse(Lt(v, zero), nan,
+ IfThenElse(Eq(v, pinf), pinf, IfThenElse(IsNaN(v), v, Log2(d, v)))));
}

static inline double scalar(const double x) { return log2(x); }
@@ -326,7 +329,7 @@
static inline auto vector(const hn::ScalableTag<T> d, const V &v) {
// Values outside of [-LIMIT, LIMIT] are not valid for SIMD version.
const T LIMIT = limit<T>();
- constexpr size_t L = hn::Lanes(d);
+ const size_t L = hn::Lanes(d);
T tmp[L];
Store(v, d, tmp);

@@ -363,7 +366,7 @@
static inline auto vector(const hn::ScalableTag<T> d, const V &v) {
// Values outside of [-LIMIT, LIMIT] are not valid for SIMD version.
const T LIMIT = limit<T>();
- constexpr size_t L = hn::Lanes(d);
+ const size_t L = hn::Lanes(d);
T tmp[L];
Store(v, d, tmp);

@@ -410,7 +413,7 @@
template <typename T, typename F>
void UnaryLoop(const T *in, size_t is, T *out, size_t os, size_t n) {
const hn::ScalableTag<T> d;
- constexpr size_t L = Lanes(d);
+ const size_t L = Lanes(d);
T tmp[L];
size_t i;

@@ -445,7 +448,7 @@
void BinaryLoop(const T *in1, size_t is1, const T *in2, size_t is2, T *out, size_t os,
size_t n) {
const hn::ScalableTag<T> d;
- constexpr size_t L = Lanes(d);
+ const size_t L = Lanes(d);
T tmp1[L];
T tmp2[L];
size_t i;
13 changes: 13 additions & 0 deletions packages/codon/5001-llvm-include-llvm-ADT-SmallVector.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- a/llvm-project/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm-project/llvm/include/llvm/ADT/SmallVector.h
@@ -735,6 +735,10 @@
return(N);
}

+#ifdef CS
+#undef CS
+#endif
+
iterator erase(const_iterator CS, const_iterator CE) {
// Just cast away constness because this is a non-const member function.
iterator S = const_cast<iterator>(CS);
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--- a/llvm-project/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
+++ b/llvm-project/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
@@ -286,7 +286,7 @@
uintptr_t SlabSize = 0;
uintptr_t CurrentSlabOffset = 0;
SectionIDMap *SecIDMap = nullptr;
-#if defined(__x86_64__) && defined(__ELF__) && defined(__linux__)
+#if defined(__x86_64__) && defined(__ELF__) && defined(__linux__) && !defined(__ANDROID__)
unsigned UsedTLSStorage = 0;
#endif
};
@@ -350,7 +350,7 @@

// In case the execution needs TLS storage, we define a very small TLS memory
// area here that will be used in allocateTLSSection().
-#if defined(__x86_64__) && defined(__ELF__) && defined(__linux__)
+#if defined(__x86_64__) && defined(__ELF__) && defined(__linux__) && !defined(__ANDROID__)
extern "C" {
alignas(16) __attribute__((visibility("hidden"), tls_model("initial-exec"),
used)) thread_local char LLVMRTDyldTLSSpace[16];
@@ -361,7 +361,7 @@
TrivialMemoryManager::allocateTLSSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID,
StringRef SectionName) {
-#if defined(__x86_64__) && defined(__ELF__) && defined(__linux__)
+#if defined(__x86_64__) && defined(__ELF__) && defined(__linux__) && !defined(__ANDROID__)
if (Size + UsedTLSStorage > sizeof(LLVMRTDyldTLSSpace)) {
return {};
}
Loading