Skip to content
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
23 changes: 0 additions & 23 deletions .github/workflows/build-and-test.yml

This file was deleted.

55 changes: 55 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Documentation

on:
push:
branches: ["template"]
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build-docs:
runs-on: ubuntu-latest
container: registry.cern.ch/ngt-wp1.7/wp1.7-soa-wrapper@sha256:16432eae6635379637e67c4cc00334c46b6dce845b83da7e75fb754d24266897
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Build Docs
run: |
cmake -B ${{github.workspace}}/build -DBUILD_DOCS=ON
cmake --build ${{github.workspace}}/build
mv ${{github.workspace}}/build/docs/html /root/
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: docs-artifact
path: /root/html

deploy:
needs: build-docs
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Download artifact
uses: actions/download-artifact@v5
with:
name: docs-artifact
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload Pages Artifact
uses: actions/upload-pages-artifact@v3
with:
path: .
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

62 changes: 62 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Unit Tests

on:
workflow_dispatch:
pull_request:
push:
branches:
- '**'

permissions:
contents: read
actions: read
checks: write
pull-requests: write

jobs:
unit-tests:
runs-on: cern-nextgen-h100
container: registry.cern.ch/ngt-wp1.7/wp1.7-soa-wrapper@sha256:16432eae6635379637e67c4cc00334c46b6dce845b83da7e75fb754d24266897
steps:
- uses: actions/checkout@v4
name: checkout repository
- name: gcc
env:
CXX: g++
CC: gcc
NVCC_CCBIN: gcc
CUDACXX: nvcc
TEST_TAG: gcc
run: &build-and-test |
cmake -B ${{github.workspace}}/build/ -DBUILD_TESTING=ON -DCMAKE_COMPILE_WARNING_AS_ERROR=ON
cmake --build ${{github.workspace}}/build/
ctest --test-dir ${{github.workspace}}/build/tests --output-on-failure --output-junit /root/test_${TEST_TAG}.xml
rm -rf ${{github.workspace}}/build
- name: clang
env:
CXX: clang++
CC: clang
NVCC_CCBIN: clang
CUDACXX: nvcc
TEST_TAG: clang
run: *build-and-test
- name: upload artifact
uses: actions/upload-artifact@v4
with:
name: junit-artifacts
path: |
/root/test_gcc.xml
/root/test_clang.xml
publish-test-results:
needs: unit-tests
runs-on: ubuntu-latest
steps:
- name: download artifact
uses: actions/download-artifact@v5
with:
name: junit-artifacts
- name: publish test results
uses: EnricoMi/publish-unit-test-result-action@v2
if: (!cancelled())
with:
files: "test_*.xml"
48 changes: 10 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,43 +1,15 @@
cmake_minimum_required(VERSION 4.0)
project(cmake_and_cuda LANGUAGES CXX CUDA)
project(memlayout LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CUDA_STANDARD 20)
set(CMAKE_CUDA_STANDARD_REQUIRED True)
option(BUILD_TESTING "Build unit tests" OFF)
option(BUILD_DOCS "Build documentation" OFF)

# Allow "std::span" on the device
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
add_subdirectory(memlayout)

# Optimize
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
if(BUILD_TESTING)
add_subdirectory(tests)
endif()

# Avoid linker error "undefined reference to std::__cxx11::basic_string"
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)

# Executable ----------------------------------

add_executable(wrapper main.cu)
set_target_properties(wrapper PROPERTIES CUDA_SEPARABLE_COMPILATION ON CUDA_ARCHITECTURES native)
target_include_directories(wrapper PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})


# Unit Tests ----------------------------------

include(FetchContent)
FetchContent_Declare(
googletest
DOWNLOAD_EXTRACT_TIMESTAMP NEW
URL https://github.com/google/googletest/archive/52eb8108c5bdec04579160ae17225d66034bd723.zip
)
FetchContent_MakeAvailable(googletest)

enable_testing()

add_executable(unittests unittests.cu)
set_target_properties(unittests PROPERTIES CUDA_SEPARABLE_COMPILATION ON CUDA_ARCHITECTURES native)
target_include_directories(unittests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(unittests GTest::gtest_main)

include(GoogleTest)
gtest_discover_tests(unittests)
if(BUILD_DOCS)
add_subdirectory(docs)
endif()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ In Step 9, instead of running nvidia-smi, execute the commands in the section [B
## TODO
- Default initializations
- Choose between uninitialized, default initialized, and custom initialized arrays
- Allow putting default values in skeleton struct definition, e.g. by template spcialization
- Allow putting default values in skeleton struct definition, e.g. by template specialization
- Aggregate initialization for arrays
- Don't define closures twice
- Return classical reference to struct in AoS case
Expand Down
41 changes: 0 additions & 41 deletions allocator.h

This file was deleted.

13 changes: 13 additions & 0 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
find_package(Doxygen REQUIRED)

set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)

add_custom_target(docs ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
25 changes: 25 additions & 0 deletions docs/Doxyfile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
PROJECT_NAME = "memlayout"
PROJECT_BRIEF = "Minimal CPU/GPU header-only example library"
OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@

INPUT = @CMAKE_SOURCE_DIR@/include \
@CMAKE_CURRENT_SOURCE_DIR@/mainpage.md

RECURSIVE = YES
GENERATE_HTML = YES
GENERATE_LATEX = NO

EXTRACT_ALL = YES
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO

QUIET = NO
WARN_IF_UNDOCUMENTED = YES

USE_MDFILE_AS_MAINPAGE = @CMAKE_CURRENT_SOURCE_DIR@/mainpage.md

GENERATE_TREEVIEW = YES
FULL_PATH_NAMES = NO
STRIP_FROM_PATH = @CMAKE_SOURCE_DIR@
SOURCE_BROWSER = YES
INLINE_SOURCES = YES
49 changes: 49 additions & 0 deletions docs/mainpage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# memlayout

`memlayout` is a minimal header-only C++20 library designed to compile on:

- GCC
- Clang
- NVCC (CUDA)

## Features

- Header-only design
- __host__ / __device__ compatibility
- Unit tested with GoogleTest
- Documented with Doxygen

## Example

```cpp
#include <iostream>

#include <memlayout.h>

template <template <class> class Container>
struct Point {
MEMLAYOUT_APPLY_UNARY(x, y, z)
MEMLAYOUT_APPLY_BINARY(Point, MEMLAYOUT_EXPAND(x), MEMLAYOUT_EXPAND(y), MEMLAYOUT_EXPAND(z))
Container<int> x, y, z;
};

template <template <class> class Container>
struct Momentum {
MEMLAYOUT_APPLY_UNARY(p, i)
MEMLAYOUT_APPLY_BINARY(Momentum, MEMLAYOUT_EXPAND(v), MEMLAYOUT_EXPAND(m))
memlayout::Wrapper<Point, Container> v;
Container<int> m;
};

int main()
{
constexpr int N = 10;
memlayout::Wrapper<Momentum, int[N], memlayout::Layout::soa> p{};
for (int n = 0; n < N; ++n) {
p[n].v.x = N - n;
std::cout << p[n].v.x << ", ";
}
std::cout << std::endl;
return 0;
}
```
Loading