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

Use ViennaCore and add namespace #59

Merged
merged 20 commits into from
Jun 14, 2024
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
19 changes: 11 additions & 8 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ name: 🏗️ Setup Environment
description: Install Dependencies & Deploy Workarounds

inputs:
container:
os:
required: true
description: Build container used
description: Operating System used

runs:
using: "composite"

steps:
- name: 📋 Install Dependencies
- name: 🩹 Enable Long Paths
shell: bash
if: ${{ inputs.container == 'ubuntu-latest' }}
run: dnf install -y make automake gcc gcc-c++ kernel-devel cmake git tbb tbb-devel
if: ${{ inputs.os == 'windows-latest' }}
run: git config --system core.longpaths true

- name: 🖥️ Enable MSVC Dev Console
uses: ilammy/msvc-dev-cmd@v1

- name: 📋 Install OpenMP
shell: bash
if: ${{ inputs.container == 'macos-latest' }}
if: ${{ inputs.os == 'macos-latest' }}
run: |
brew reinstall --build-from-source --formula ./.github/homebrew/libomp.rb
brew install tbb
brew reinstall --build-from-source --formula ./.github/homebrew/libomp.rb
echo "OpenMP_ROOT=$(brew --prefix)/opt/libomp" >> $GITHUB_ENV
156 changes: 78 additions & 78 deletions .github/homebrew/libomp.rb
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
# SPDX-License-Identifier: BSD-2-Clause

class Libomp < Formula
desc "LLVM's OpenMP runtime library"
homepage "https://openmp.llvm.org/"
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/openmp-15.0.7.src.tar.xz"
sha256 "3f168d38e7a37b928dcb94b33ce947f75d81eef6fa6a4f9d16b6dc5511c07358"
license "MIT"

livecheck do
url :stable
regex(/^llvmorg[._-]v?(\d+(?:\.\d+)+)$/i)
end

bottle do
sha256 cellar: :any, arm64_ventura: "8c5c7b912a075e598fb7ae10f2999853343b2662061d92040b1a584cbb3ba7d2"
sha256 cellar: :any, arm64_monterey: "1b1aad07e8677744cdaa264419fade98bd1a852894c77d01985053a96b7d1c7d"
sha256 cellar: :any, arm64_big_sur: "00e04fbe9783ad7751eaa6d2edda92dfbff85131777255a74e364f3217a7a2df"
sha256 cellar: :any, ventura: "762c461db6af3cf78983b1eb58aee62699652b96237abf79469c8ac034b2156b"
sha256 cellar: :any, monterey: "0b944a6bbe8955e7900882b94f1b0b09030d5791191dc5b0c8b3d5d0895f4b12"
sha256 cellar: :any, big_sur: "f92e5b31f86c22c0fe875b50e050c19a89993b36106a9ad2737230ae2cb68069"
sha256 cellar: :any_skip_relocation, x86_64_linux: "d2a16a906c029e8405a11924837417ad1008d41bb1877399f494cb872a179f01"
end

# Ref: https://github.com/Homebrew/homebrew-core/issues/112107
keg_only "it can override GCC headers and result in broken builds"

depends_on "cmake" => :build
depends_on "lit" => :build
uses_from_macos "llvm" => :build

resource "cmake" do
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/cmake-15.0.7.src.tar.xz"
sha256 "8986f29b634fdaa9862eedda78513969fe9788301c9f2d938f4c10a3e7a3e7ea"
end

def install
(buildpath/"src").install buildpath.children
(buildpath/"cmake").install resource("cmake")

# Disable LIBOMP_INSTALL_ALIASES, otherwise the library is installed as
# libgomp alias which can conflict with GCC's libgomp.
args = ["-DLIBOMP_INSTALL_ALIASES=OFF"]
args << "-DOPENMP_ENABLE_LIBOMPTARGET=OFF" if OS.linux?

# Build universal binary
ENV.permit_arch_flags
ENV.runtime_cpu_detection
args << "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64"

system "cmake", "-S", "src", "-B", "build/shared", *std_cmake_args, *args
system "cmake", "--build", "build/shared"
system "cmake", "--install", "build/shared"

system "cmake", "-S", "src", "-B", "build/static",
"-DLIBOMP_ENABLE_SHARED=OFF",
*std_cmake_args, *args
system "cmake", "--build", "build/static"
system "cmake", "--install", "build/static"
end

test do
(testpath/"test.cpp").write <<~EOS
#include <omp.h>
#include <array>
int main (int argc, char** argv) {
std::array<size_t,2> arr = {0,0};
#pragma omp parallel num_threads(2)
{
size_t tid = omp_get_thread_num();
arr.at(tid) = tid + 1;
}
if(arr.at(0) == 1 && arr.at(1) == 2)
return 0;
else
return 1;
desc "LLVM's OpenMP runtime library"
homepage "https://openmp.llvm.org/"
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/openmp-15.0.7.src.tar.xz"
sha256 "3f168d38e7a37b928dcb94b33ce947f75d81eef6fa6a4f9d16b6dc5511c07358"
license "MIT"

livecheck do
url :stable
regex(/^llvmorg[._-]v?(\d+(?:\.\d+)+)$/i)
end

bottle do
sha256 cellar: :any, arm64_ventura: "8c5c7b912a075e598fb7ae10f2999853343b2662061d92040b1a584cbb3ba7d2"
sha256 cellar: :any, arm64_monterey: "1b1aad07e8677744cdaa264419fade98bd1a852894c77d01985053a96b7d1c7d"
sha256 cellar: :any, arm64_big_sur: "00e04fbe9783ad7751eaa6d2edda92dfbff85131777255a74e364f3217a7a2df"
sha256 cellar: :any, ventura: "762c461db6af3cf78983b1eb58aee62699652b96237abf79469c8ac034b2156b"
sha256 cellar: :any, monterey: "0b944a6bbe8955e7900882b94f1b0b09030d5791191dc5b0c8b3d5d0895f4b12"
sha256 cellar: :any, big_sur: "f92e5b31f86c22c0fe875b50e050c19a89993b36106a9ad2737230ae2cb68069"
sha256 cellar: :any_skip_relocation, x86_64_linux: "d2a16a906c029e8405a11924837417ad1008d41bb1877399f494cb872a179f01"
end

# Ref: https://github.com/Homebrew/homebrew-core/issues/112107
keg_only "it can override GCC headers and result in broken builds"

depends_on "cmake" => :build
depends_on "lit" => :build
uses_from_macos "llvm" => :build

resource "cmake" do
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/cmake-15.0.7.src.tar.xz"
sha256 "8986f29b634fdaa9862eedda78513969fe9788301c9f2d938f4c10a3e7a3e7ea"
end

def install
(buildpath/"src").install buildpath.children
(buildpath/"cmake").install resource("cmake")

# Disable LIBOMP_INSTALL_ALIASES, otherwise the library is installed as
# libgomp alias which can conflict with GCC's libgomp.
args = ["-DLIBOMP_INSTALL_ALIASES=OFF"]
args << "-DOPENMP_ENABLE_LIBOMPTARGET=OFF" if OS.linux?

# Build universal binary
ENV.permit_arch_flags
ENV.runtime_cpu_detection
args << "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64"

system "cmake", "-S", "src", "-B", "build/shared", *std_cmake_args, *args
system "cmake", "--build", "build/shared"
system "cmake", "--install", "build/shared"

system "cmake", "-S", "src", "-B", "build/static",
"-DLIBOMP_ENABLE_SHARED=OFF",
*std_cmake_args, *args
system "cmake", "--build", "build/static"
system "cmake", "--install", "build/static"
end

test do
(testpath/"test.cpp").write <<~EOS
#include <omp.h>
#include <array>
int main (int argc, char** argv) {
std::array<size_t,2> arr = {0,0};
#pragma omp parallel num_threads(2)
{
size_t tid = omp_get_thread_num();
arr.at(tid) = tid + 1;
}
EOS
system ENV.cxx, "-Werror", "-Xpreprocessor", "-fopenmp", "test.cpp", "-std=c++11",
"-I#{include}", "-L#{lib}", "-lomp", "-o", "test"
system "./test"
end
if(arr.at(0) == 1 && arr.at(1) == 2)
return 0;
else
return 1;
}
EOS
system ENV.cxx, "-Werror", "-Xpreprocessor", "-fopenmp", "test.cpp", "-std=c++11",
"-I#{include}", "-L#{lib}", "-lomp", "-o", "test"
system "./test"
end
end
37 changes: 21 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@ jobs:
fail-fast: false

matrix:
config: [Release, Debug]
os: [ubuntu-latest, windows-latest, macos-latest]
config:
- Release
- Debug

os:
- macos-latest
- windows-latest

include:
- os: ubuntu-latest
config: Release
container: ghcr.io/viennatools/vienna-builder:suite
- os: ubuntu-latest
config: Debug
container: ghcr.io/viennatools/vienna-builder:suite

runs-on: ${{ matrix.os }}
container: ${{ matrix.os == 'ubuntu-latest' && 'fedora:38' || null }}
container: ${{ matrix.container }}

name: '🧪 Test on ${{ matrix.os }} [Config: "${{ matrix.config }}"]'
name: "🧪 Test on ${{ matrix.os }} (⚙️: ${{ matrix.config }}, 💿: ${{ matrix.container || matrix.os }})"

steps:
- name: 📥 Checkout
Expand All @@ -28,21 +41,13 @@ jobs:
- name: 🖥️ Setup Environment
uses: ./.github/actions/setup
with:
container: ${{ matrix.os }}
os: ${{ matrix.os }}

- name: 🦥 Cache Dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
key: ${{ matrix.os }}-${{ matrix.config }}-cache
path: |
deps-cache

- name: 🦥 Cache Build
uses: actions/cache@v3
with:
key: ${{ matrix.os }}-${{ matrix.config }}-build-cache
path: |
build
key: test-${{ matrix.os }}-${{ matrix.config }}
path: build

- name: 🏗️ Compile
run: cmake -B build -DCPM_SOURCE_CACHE=deps-cache -DVIENNARAY_BUILD_TESTS=ON && cmake --build build --config ${{ matrix.config }}
Expand Down
40 changes: 10 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(
ViennaRay
LANGUAGES CXX
VERSION 2.1.3)
VERSION 3.0.0)

# --------------------------------------------------------------------------------------------------------
# Library switches
Expand All @@ -11,22 +11,11 @@ project(
option(EMBREE_ISPC_SUPPORT "Enable Intel's SPMD Compiler" OFF)
option(EMBREE_RAY_MASK "Enable Embree Ray Masking" OFF)

option(VIENNARAY_DISABLE_COPY "Disable Embree Environment setup" OFF)
option(VIENNARAY_LEGACY_OPENMP "Use legacy OpenMP flags" OFF)

option(VIENNARAY_USE_WDIST "Enable weighted distribution of ray weights" OFF)
option(VIENNARAY_PRINT_PROGRESS "Enable progress bar" OFF)

option(VIENNARAY_BUILD_EXAMPLES "Build examples" OFF)
option(VIENNARAY_BUILD_TESTS "Build tests" OFF)

if(VIENNARAY_LEGACY_OPENMP)
message(STATUS "[ViennaRay] Using legacy OpenMP flags")

find_package(OpenMP REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

# --------------------------------------------------------------------------------------------------------
# Library options
# --------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -58,20 +47,9 @@ endif()
# Configuration
# --------------------------------------------------------------------------------------------------------

include("cmake/openmp.cmake")
include("cmake/embree.cmake")
include("cmake/tbb.cmake")

find_package(embree ${VIENNARAY_EMBREE_VERSION} QUIET)
set(VIENNARAY_SYSTEM_EMBREE
${embree_FOUND}
CACHE INTERNAL "")

find_package(TBB QUIET)
set(VIENNARAY_SYSTEM_TBB
${TBB_FOUND}
CACHE INTERNAL "")

# --------------------------------------------------------------------------------------------------------
# Setup Library
# --------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -118,6 +96,12 @@ target_include_directories(

include("cmake/cpm.cmake")

CPMAddPackage(
NAME ViennaCore
GIT_TAG v1.0.0
GIT_REPOSITORY "https://github.com/ViennaTools/ViennaCore"
OPTIONS "VIENNACORE_FORMAT_EXCLUDE docs/")

CPMAddPackage(
NAME PackageProject
VERSION 1.11.1
Expand All @@ -139,12 +123,8 @@ CPMFindPackage(
GIT_REPOSITORY "https://github.com/embree/embree"
OPTIONS "EMBREE_TUTORIALS OFF")

if(NOT VIENNARAY_LEGACY_OPENMP)
find_package(OpenMP REQUIRED)
target_link_libraries(${PROJECT_NAME} INTERFACE OpenMP::OpenMP_CXX)
endif()

target_link_libraries(${PROJECT_NAME} INTERFACE embree)
find_package(OpenMP REQUIRED)
target_link_libraries(${PROJECT_NAME} INTERFACE embree OpenMP::OpenMP_CXX ViennaTools::ViennaCore)

# --------------------------------------------------------------------------------------------------------
# Setup Examples
Expand Down Expand Up @@ -177,4 +157,4 @@ packageProject(
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include/viennaray
INCLUDE_DESTINATION include/viennaray-${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
DEPENDENCIES "embree;TBB;OpenMP")
DEPENDENCIES "embree;TBB;OpenMP;ViennaCore")
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,18 @@ We recommend using [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) to consum
* Installation with CPM

```cmake
CPMAddPackage("gh:viennatools/viennaray@2.1.3")
CPMAddPackage("gh:viennatools/viennaray@3.0.0")
```

* With a local installation
> In case you have ViennaRay installed in a custom directory, make sure to properly specify the `CMAKE_MODULE_PATH` or `PATHS` in your find_package call.
> In case you have ViennaRay installed in a custom directory, make sure to properly specify the [`CMAKE_PREFIX_PATH`](https://cmake.org/cmake/help/latest/envvar/CMAKE_PREFIX_PATH.html#envvar:CMAKE_PREFIX_PATH).

```cmake
set(VIENNARAY_PATH "/your/local/installation")

find_package(TBB REQUIRED)
find_package(OpenMP REQUIRED)
```cmake
list(APPEND CMAKE_PREFIX_PATH "/your/local/installation")

find_package(embree 4 PATHS ${VIENNARAY_PATH})
find_package(ViennaRay PATHS ${VIENNARAY_PATH})

target_link_libraries(${PROJECT_NAME} PUBLIC ViennaTools::ViennaRay)
```
find_package(ViennaRay)
target_link_libraries(${PROJECT_NAME} PUBLIC ViennaTools::ViennaRay)
```

### Building examples

Expand Down Expand Up @@ -110,6 +105,8 @@ If you want to contribute to ViennaRay, make sure to follow the [LLVM Coding gui

## Authors

Current contributors: Tobias Reiter

Contact us via: [email protected]

ViennaRay was developed under the aegis of the 'Institute for Microelectronics' at the 'TU Wien'.
Expand Down
5 changes: 5 additions & 0 deletions cmake/embree.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
macro(setup_embree_env TARGET OUTPUT)
message(STATUS "[ViennaRay] Setting up Embree-Environment for ${TARGET}")

if(NOT TARGET embree)
message(WARNING "[ViennaRay] Could not find Embree-Target")
return()
endif()

add_custom_command(
TARGET ${TARGET}
POST_BUILD
Expand Down
Loading
Loading