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
2 changes: 1 addition & 1 deletion .github/workflows/cpp-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
shell: spack-bash {0}
run: |
spack env activate lobxp
cmake -S . -B build -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
cmake -S . -B build -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DBUILD_CUDA=OFF

- name: Build
run: cmake --build build -j $(nproc)
Expand Down
60 changes: 59 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,62 @@

The purpose of this repository is to provide a space for exploring numerical methods, algorithms, and patterns in C++ in a practical and modular way. It is not intended as a tutorial or comprehensive learning resource, but rather as a set of working examples and references.

Contributions are welcome. If you spot an issue, find an area that could be improved, or want to add your own example, feel free to open an issue or submit a pull request.
Contributions are welcome. If you spot an issue, find an area that could be improved, or want to add your own example, feel free to open an issue or submit a pull request.

# Developper guide

## Spack

We use spack to manage dependencies and build the projects. To get started, clone the repository and run:

```bash
git clone https://github.com/bstaber/cppplorers.git
cd cppXplorers
spack env activate .
spack concretize -f
spack install
```

This will set up the environment and install the necessary packages. You can then enter the environment with:

```bash
spack env activate .
```

Note that we set the CUDA dependency externally, so if you want to use CUDA, make sure to have it installed and configured properly.

## Building

Each crate has its own `CMakeLists.txt` file and can be built independently. However, we provide a top-level `CMakeLists.txt` that can be used to build all crates at once. To build all crates, run:

```bash
just
```

This will run the `justfile` which builds all crates and runs all tests.

## Adding a new crate

To add a new crate, create a new directory under `crates/` and add a `CMakeLists.txt` file. You can use one of the existing crates as a template. Make sure to update the top-level `CMakeLists.txt` to include your new crate.

## Documenting a crate
We use `mdbook` to document each crate. You can find the book source files in the `books/` directory. To build and serve the book, run:

```bash
just serve-book
```

This will build the book and serve it at `http://localhost:3000`. You can then navigate to the book in your web browser.

## Just

We use `just` as a task runner to automate common tasks. You can find the `justfile` in the root directory. Some common tasks include:

- `just build`: Build all crates
- `just test`: Run all tests
- `just serve-book`: Build and serve the documentation book
- `just clean`: Clean all build artifacts
- `just fmt`: Format all code using `clang-format`
- `just lint`: Run `clang-tidy` on all code
- `just configure`: Configure all crates with CMake
- `just`: Configure, build, and test all crates
5 changes: 4 additions & 1 deletion crates/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
add_subdirectory("kf_linear")
add_subdirectory("simple_optimizers")
add_subdirectory("ar_models")
add_subdirectory("ar_models")
if(BUILD_CUDA)
add_subdirectory("cuda_hello")
endif()
15 changes: 15 additions & 0 deletions crates/cuda_hello/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.25)
project(cuda_hello LANGUAGES CXX CUDA)

set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)

set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)

add_executable(cuda_hello main.cu)

find_package(CUDAToolkit REQUIRED)
target_link_libraries(cuda_hello PRIVATE CUDA::cudart)

set_property(TARGET cuda_hello PROPERTY CUDA_ARCHITECTURES native)
15 changes: 15 additions & 0 deletions crates/cuda_hello/main.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <cstdio>

// Kernel function that runs on the GPU
__global__ void hello_kernel() {
printf("Hello from GPU thread %d in block %d!\n", threadIdx.x, blockIdx.x);
}

int main() {
// Launch 2 blocks with 4 threads each
hello_kernel<<<2, 4>>>();
cudaDeviceSynchronize(); // wait for GPU to finish

printf("Hello from CPU!\n");
return 0;
}
1 change: 1 addition & 0 deletions spack.lock

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions spack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ spack:
specs:
- eigen@3.4
- catch2@3

- cuda
- cmake
packages:
all:
target: [x86_64]
Expand All @@ -15,6 +16,11 @@ spack:
- spec: cmake@3.22.1
prefix: /usr
buildable: false

cuda:
externals:
- spec: cuda@12.0
prefix: /usr/local/cuda-12.0
buildable: false
config:
install_tree: $spack/opt/spack
install_tree:
root: $spack/opt/spack