Skip to content

Commit

Permalink
Merge branch 'test' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Pencilcaseman committed May 27, 2024
2 parents cf85246 + fae6d03 commit a8f1b26
Show file tree
Hide file tree
Showing 38 changed files with 1,328 additions and 933 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ jobs:
- os: windows-latest
cc: ../llvm/clang
cxx: ../llvm/clang++
clangVer: "15.0"
clangVer: "16.0"
blas: off
getBlas: off
fftw: off
Expand All @@ -197,7 +197,7 @@ jobs:
- os: windows-latest
cc: ../llvm/clang
cxx: ../llvm/clang++
clangVer: "15.0"
clangVer: "16.0"
blas: on
getBlas: on
fftw: on
Expand All @@ -208,7 +208,7 @@ jobs:
- os: windows-latest
cc: ./llvm/clang
cxx: ./llvm/clang++
clangVer: "15.0"
clangVer: "16.0"
blas: off
getBlas: off
fftw: off
Expand All @@ -219,7 +219,7 @@ jobs:
- os: windows-latest
cc: ./llvm/clang
cxx: ./llvm/clang++
clangVer: "15.0"
clangVer: "16.0"
blas: on
getBlas: on
fftw: on
Expand Down Expand Up @@ -290,7 +290,7 @@ jobs:
if: matrix.os == 'macos-latest'
uses: maxim-lobanov/setup-xcode@v1.5.1
with:
xcode-version: latest
xcode-version: latest

# Tests must pass in both debug and release mode
- name: Compile (Debug)
Expand Down Expand Up @@ -394,7 +394,7 @@ jobs:
run: |
sudo apt --fix-broken install
sudo apt-get install python3-sphinx
- name: Configure Files
run: |
touch .is_local
Expand Down Expand Up @@ -428,14 +428,14 @@ jobs:
- os: ubuntu-latest
cc: ../../llvm/bin/clang
cxx: ../../llvm/bin/clang++
clangVer: "15.0"
clangVer: "16.0"
smallArrays: ON
pretty: "LibRapid_Ubuntu_Clang_OptimiseSmallArrays"

- os: ubuntu-latest
cc: ../../llvm/bin/clang
cxx: ../../llvm/bin/clang++
clangVer: "15.0"
clangVer: "16.0"
smallArrays: OFF
pretty: "LibRapid_Ubuntu_Clang"

Expand All @@ -454,14 +454,14 @@ jobs:
- os: macos-latest
cc: ../../llvm/bin/clang
cxx: ../../llvm/bin/clang++
clangVer: "15.0"
clangVer: "16.0"
smallArrays: ON
pretty: "LibRapid_MacOS_Clang_OptimiseSmallArrays"

- os: macos-latest
cc: ../../llvm/bin/clang
cxx: ../../llvm/bin/clang++
clangVer: "15.0"
clangVer: "16.0"
smallArrays: OFF
pretty: "LibRapid_MacOS_Clang"

Expand All @@ -480,14 +480,14 @@ jobs:
- os: windows-latest
cc: ../../llvm/clang
cxx: ../../llvm/clang++
clangVer: "15.0"
clangVer: "16.0"
smallArrays: ON
pretty: "LibRapid_Windows_Clang_OptimiseSmallArrays"

- os: windows-latest
cc: ../../llvm/clang
cxx: ../../llvm/clang++
clangVer: "15.0"
clangVer: "16.0"
smallArrays: OFF
pretty: "LibRapid_Windows_Clang"

Expand Down Expand Up @@ -607,7 +607,7 @@ jobs:
run: |
cd IntermediateBenchmarkResults
tree
- name: Upload Intermediate Benchmark Results
uses: actions/upload-artifact@v3
with:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ jobs:
LIBRAPID_GET_FFTW: OFF
CC: /usr/local/opt/llvm/bin/clang
CXX: /usr/local/opt/llvm/bin/clang++
CIBW_ENVIRONMENT: CC=/usr/local/opt/llvm/bin/clang CXX=/usr/local/opt/llvm/bin/clang++
CIBW_ENVIRONMENT: CC=/usr/local/opt/llvm/bin/clang CXX=/usr/local/opt/llvm/bin/clang++ CMAKE_BUILD_PARALLEL_LEVEL=1
CMAKE_C_COMPILER: /usr/local/opt/llvm/bin/clang
CMAKE_CXX_COMPILER: /usr/local/opt/llvm/bin/clang++

Expand All @@ -357,7 +357,9 @@ jobs:
LIBRAPID_GET_FFTW: OFF
CC: ${RUNNER_TOOL_CACHE}/llvm/bin/clang
CXX: ${RUNNER_TOOL_CACHE}/llvm/bin/clang++
CIBW_ENVIRONMENT: CC=${RUNNER_TOOL_CACHE}/llvm/bin/clang CXX=${RUNNER_TOOL_CACHE}/llvm/bin/clang++
CIBW_ENVIRONMENT: CC=${RUNNER_TOOL_CACHE}/llvm/bin/clang CXX=${RUNNER_TOOL_CACHE}/llvm/bin/clang++ CMAKE_BUILD_PARALLEL_LEVEL=1
CIBW_BEFORE_ALL: |
set CMAKE_BUILD_PARALLEL_LEVEL=1
CMAKE_C_COMPILER: ${RUNNER_TOOL_CACHE}/llvm/bin/clang
CMAKE_CXX_COMPILER: ${RUNNER_TOOL_CACHE}/llvm/bin/clang++

Expand All @@ -378,6 +380,7 @@ jobs:
GITHUB_ACTIONS: ON
LIBRAPID_GET_BLAS: ON
LIBRAPID_GET_FFTW: OFF
CIBW_ENVIRONMENT: CMAKE_BUILD_PARALLEL_LEVEL=1

- name: Store Artifacts
uses: actions/upload-artifact@v3
Expand Down
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ if (${SKBUILD})
)
FetchContent_MakeAvailable(pybind11)

# Set CMAKE_BUILD_PARALLEL_LEVEL=1 to reduce memory usage
set(CMAKE_BUILD_PARALLEL_LEVEL 1)

# Set environment variable CMAKE_BUILD_PARALLEL_LEVEL=1 to reduce memory usage
set(ENV{CMAKE_BUILD_PARALLEL_LEVEL} 1)

# Run auto-generation script
# 1. Find the Python executable
# 2. cd into 'librapid/bindings/generators'
Expand Down Expand Up @@ -157,7 +163,7 @@ if (${SKBUILD})
set(LIBRAPID_USE_CUDA ON)
set(LIBRAPID_USE_OPENCL ON)
set(LIBRAPID_NATIVE_ARCH ON)
else()
else ()
set(LIBRAPID_NO_ALWAYS_INLINE ON) # Reduce compile memory
endif ()

Expand All @@ -181,6 +187,11 @@ if (${SKBUILD})
${PYTHON_SOURCES}
)

# If using MSVC with GitHub, set /Zm512 to reduce memory usage
if (MSVC AND "$ENV{CI}")
target_compile_options(${module_name} PRIVATE /Zm512)
endif ()

target_compile_definitions(${module_name} PUBLIC
LIBRAPID_PYTHON
WIN32_LEAN_AND_MEAN
Expand Down
1 change: 1 addition & 0 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2310,6 +2310,7 @@ PREDEFINED = LIBRAPID_DOXYGEN=1\
LIBRAPID_NODISCARD=\
LIBRAPID_ALWAYS_INLINE=\
LIBRAPID_INLINE=\
concept=\

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand Down
6 changes: 3 additions & 3 deletions examples/example-cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace lrc = librapid;

auto main() -> int {
#if defined(LIBRAPID_HAS_CUDA)
auto cudaArray = lrc::Array<float, lrc::backend::CUDA>::fromData({{1, 2, 3}, {4, 5, 6}});
auto cudaArray = lrc::Array<float, lrc::backend::CUDA>({{1, 2, 3}, {4, 5, 6}});
fmt::print("CUDA Array:\n{}\n", cudaArray);

// Operations on CUDA arrays work exactly the same as on CPU arrays
Expand All @@ -26,13 +26,13 @@ auto main() -> int {
// Linear algebra operations also work
fmt::print("Transposed CUDA Array:\n{}\n", lrc::transpose(prod));

auto vector = lrc::Array<float, lrc::backend::CUDA>::fromData({{1, 2, 3}});
auto vector = lrc::Array<float, lrc::backend::CUDA>({{1, 2, 3}});
fmt::print("Array: \n{}\n", cudaArray);
fmt::print("Vector: \n{}\n", vector);
fmt::print("Matrix dot Vector^T:\n{}\n", lrc::dot(cudaArray, lrc::transpose(vector)));
#else
fmt::print("CUDA not enabled in this build of librapid\n");
fmt::print("Check the documentation for more information on enabling OpenCL\n");
fmt::print("Check the documentation for more information on enabling CUDA\n");
fmt::print("https://librapid.readthedocs.io/en/latest/cmakeIntegration.html#librapid-use-cuda\n");
#endif // LIBRAPID_HAS_CUDA

Expand Down
4 changes: 2 additions & 2 deletions examples/example-opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ auto main() -> int {
// (You can pass (true, true) to select the device manually)
lrc::configureOpenCL(true);

auto openclArray = lrc::Array<float, lrc::backend::OpenCL>::fromData({{1, 2, 3}, {4, 5, 6}});
auto openclArray = lrc::Array<float, lrc::backend::OpenCL>({{1, 2, 3}, {4, 5, 6}});
fmt::print("OpenCL Array:\n{}\n", openclArray);

// Operations on OpenCL arrays work exactly the same as on CPU arrays
Expand All @@ -31,7 +31,7 @@ auto main() -> int {
// Linear algebra operations also work
fmt::print("Transposed OpenCL Array:\n{}\n", lrc::transpose(prod));

auto vector = lrc::Array<float, lrc::backend::OpenCL>::fromData({{1, 2, 3}});
auto vector = lrc::Array<float, lrc::backend::OpenCL>({{1, 2, 3}});
fmt::print("Array: \n{}\n", openclArray);
fmt::print("Vector: \n{}\n", vector);
fmt::print("Matrix dot Vector^T:\n{}\n", lrc::dot(openclArray, lrc::transpose(vector)));
Expand Down
131 changes: 42 additions & 89 deletions librapid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,56 +103,23 @@ def Array(*args, **kwargs):
backend = CPU

if backend == CPU:
cpuTypeList = {
float32: _librapid.ArrayFloatCPU,
float64: _librapid.ArrayDoubleCPU,
int32: _librapid.ArrayInt32CPU,
int64: _librapid.ArrayInt64CPU,
uint32: _librapid.ArrayUInt32CPU,
uint64: _librapid.ArrayUInt64CPU,
# Complex32: _librapid.ArrayComplexFloatCPU,
# Complex64: _librapid.ArrayComplexDoubleCPU,
}

arrayType = cpuTypeList.get(dtype, None)
arrayType = __cpuTypeList.get(dtype, None)
elif backend == OpenCL:
if not _librapid.hasOpenCL():
raise RuntimeError("OpenCL is not supported in this build "
"of librapid. Ensure OpenCL is installed "
"on your system and reinstall librapid "
"from source.")

openclTypeList = {
float32: _librapid.ArrayFloatOpenCL,
float64: _librapid.ArrayDoubleOpenCL,
int32: _librapid.ArrayInt32OpenCL,
int64: _librapid.ArrayInt64OpenCL,
uint32: _librapid.ArrayUInt32OpenCL,
uint64: _librapid.ArrayUInt64OpenCL,
# Complex32: _librapid.ArrayComplexFloatOpenCL,
# Complex64: _librapid.ArrayComplexDoubleOpenCL,
}

arrayType = openclTypeList.get(dtype, None)
arrayType = __openclTypeList.get(dtype, None)
elif backend == CUDA:
if not _librapid.hasCUDA():
raise RuntimeError("CUDA is not supported in this build "
"of librapid. Ensure CUDA is installed "
"on your system and reinstall librapid "
"from source.")

cudaTypeList = {
float32: _librapid.ArrayFloatCUDA,
float64: _librapid.ArrayDoubleCUDA,
int32: _librapid.ArrayInt32CUDA,
int64: _librapid.ArrayInt64CUDA,
uint32: _librapid.ArrayUInt32CUDA,
uint64: _librapid.ArrayUInt64CUDA,
# Complex32: _librapid.ArrayComplexFloatCUDA,
# Complex64: _librapid.ArrayComplexDoubleCUDA,
}

arrayType = cudaTypeList.get(dtype, None)
arrayType = __cudaTypeList.get(dtype, None)
else:
raise ValueError(f"Unknown backend {backend}")

Expand All @@ -167,58 +134,6 @@ def Array(*args, **kwargs):
raise RuntimeError("Unknown error")


def isArray(obj):
"""
Checks if an object is an Array.
Parameters
----------
obj : object
The object to check.
Returns
-------
bool
True if the object is an Array, False otherwise.
"""

if type(obj) in [
_librapid.ArrayFloatCPU,
_librapid.ArrayDoubleCPU,
_librapid.ArrayInt32CPU,
_librapid.ArrayInt64CPU,
_librapid.ArrayUInt32CPU,
_librapid.ArrayUInt64CPU,
# _librapid.ArrayComplexFloatCPU,
# _librapid.ArrayComplexDoubleCPU
]:
return True

if _librapid.hasOpenCL() and type(obj) in [
_librapid.ArrayFloatOpenCL,
_librapid.ArrayDoubleOpenCL,
_librapid.ArrayInt32OpenCL,
_librapid.ArrayInt64OpenCL,
_librapid.ArrayUInt32OpenCL,
_librapid.ArrayUInt64OpenCL,
# _librapid.ArrayComplexFloatOpenCL,
# _librapid.ArrayComplexDoubleOpenCL
]:
return True

if _librapid.hasCUDA() and type(obj) in [
_librapid.ArrayFloatCUDA,
_librapid.ArrayDoubleCUDA,
_librapid.ArrayInt32CUDA,
_librapid.ArrayInt64CUDA,
_librapid.ArrayUInt32CUDA,
_librapid.ArrayUInt64CUDA,
# _librapid.ArrayComplexFloatCUDA,
# _librapid.ArrayComplexDoubleCUDA
]:
return True


def hasOpenCL():
"""
Checks if OpenCL is supported.
Expand Down Expand Up @@ -320,7 +235,6 @@ def getSeed():
exp2 = _librapid.exp2
exp10 = _librapid.exp10


float32 = DataType("float32", 4)
float64 = DataType("float64", 8)
int32 = DataType("int32", 4)
Expand All @@ -330,6 +244,45 @@ def getSeed():
# Complex32 = DataType("Complex32", 8)
# Complex64 = DataType("Complex64", 16)

__cpuTypeList = {
int32: _librapid.ArrayInt32CPU,
int64: _librapid.ArrayInt64CPU,
uint32: _librapid.ArrayUInt32CPU,
uint64: _librapid.ArrayUInt64CPU,
float32: _librapid.ArrayFloatCPU,
float64: _librapid.ArrayDoubleCPU,
# Complex32: _librapid.ArrayComplexFloatCPU,
# Complex64: _librapid.ArrayComplexDoubleCPU,
}

if _librapid.hasOpenCL():
__openclTypeList = {
int32: _librapid.ArrayInt32OpenCL,
int64: _librapid.ArrayInt64OpenCL,
uint32: _librapid.ArrayUInt32OpenCL,
uint64: _librapid.ArrayUInt64OpenCL,
float32: _librapid.ArrayFloatOpenCL,
float64: _librapid.ArrayDoubleOpenCL,
# Complex32: _librapid.ArrayComplexFloatOpenCL,
# Complex64: _librapid.ArrayComplexDoubleOpenCL,
}
else:
__openclTypeList = None

if _librapid.hasCUDA():
__cudaTypeList = {
int32: _librapid.ArrayInt32CUDA,
int64: _librapid.ArrayInt64CUDA,
uint32: _librapid.ArrayUInt32CUDA,
uint64: _librapid.ArrayUInt64CUDA,
float32: _librapid.ArrayFloatCUDA,
float64: _librapid.ArrayDoubleCUDA,
# Complex32: _librapid.ArrayComplexFloatCUDA,
# Complex64: _librapid.ArrayComplexDoubleCUDA,
}
else:
__cudaTypeList = None

CPU = Backend("CPU")
OpenCL = Backend("OpenCL")
CUDA = Backend("CUDA")
Loading

0 comments on commit a8f1b26

Please sign in to comment.