Skip to content

Commit 4dc94b7

Browse files
authored
refactor: use custom command for CUDA NVCC compilation (#91)
* Test new CUDA setup * Fixes, rename GPU targets * Force override PTX cache * Fix GPU targets * Cache GPU dependencies * MSCV fixes * Format * Rename BoundaryCondition enum * Fix tests * Move GPU includes into include folder * Bump version
1 parent 12dc5b9 commit 4dc94b7

53 files changed

Lines changed: 216 additions & 342 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
22
project(
33
ViennaRay
44
LANGUAGES CXX
5-
VERSION 3.9.1)
5+
VERSION 3.10.0)
66

77
# --------------------------------------------------------------------------------------------------------
88
# Library switches
@@ -74,6 +74,7 @@ if(VIENNARAY_GPU_DOUBLE_PRECISION)
7474
endif()
7575

7676
if(VIENNARAY_PRINT_PROGRESS)
77+
message(STATUS "[ViennaRay] Enabling progress printing")
7778
target_compile_definitions(${PROJECT_NAME} INTERFACE VIENNARAY_PRINT_PROGRESS)
7879
endif()
7980

@@ -98,7 +99,7 @@ include("cmake/cpm.cmake")
9899

99100
CPMAddPackage(
100101
NAME ViennaCore
101-
VERSION 1.8.0
102+
VERSION 1.9.0
102103
GIT_REPOSITORY "https://github.com/ViennaTools/ViennaCore"
103104
OPTIONS "VIENNACORE_USE_GPU ${VIENNARAY_USE_GPU}")
104105

@@ -149,12 +150,9 @@ endif()
149150
# Setup GPU
150151
# --------------------------------------------------------------------------------------------------------
151152

152-
# If CUDA or OptiX is not found in ViennaCore, VIENNACORE_PTX_DIR is not set
153-
if(VIENNARAY_USE_GPU AND VIENNACORE_PTX_DIR)
153+
if(VIENNARAY_USE_GPU)
154154
message(STATUS "[ViennaRay] Enabling GPU support")
155155
add_subdirectory(gpu)
156-
target_include_directories(${PROJECT_NAME}
157-
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/gpu/include>)
158156
endif()
159157

160158
# --------------------------------------------------------------------------------------------------------

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ We recommend using [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) to consum
6363
* Installation with CPM
6464

6565
```cmake
66-
CPMAddPackage("gh:viennatools/viennaray@3.8.5") # Use the latest release version
66+
CPMAddPackage("gh:viennatools/viennaray@3.10.0") # Use the latest release version
6767
```
6868

6969
* With a local installation

cmake/generate_ptx.cmake

Lines changed: 0 additions & 151 deletions
This file was deleted.

examples/disk2D/disk2D.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ int main() {
2828
// however the boundary condition in direction of the tracing direction will
2929
// not be used. Possible choices are: PERIODIC, REFLECTIVE, IGNORE
3030
BoundaryCondition boundaryConds[D];
31-
boundaryConds[0] = BoundaryCondition::PERIODIC; // x
32-
boundaryConds[1] = BoundaryCondition::PERIODIC; // y
31+
boundaryConds[0] = BoundaryCondition::PERIODIC_BOUNDARY; // x
32+
boundaryConds[1] = BoundaryCondition::PERIODIC_BOUNDARY; // y
3333

3434
// ParticleType: The particle types provides the sticking probability and
3535
// the reflection process for each surface hit. This class can be user
3636
// defined, but has to interface the rayParticle<NumericType> class and
3737
// provide the functions: initNew(...), surfaceCollision(...),
3838
// surfaceReflection(...).
39-
auto particle =
40-
std::make_unique<DiffuseParticle<NumericType, D>>(0.5, "flux");
39+
NumericType stickingProbability = 0.1;
40+
auto particle = std::make_unique<DiffuseParticle<NumericType, D>>(
41+
stickingProbability, "flux");
4142

4243
TraceDisk<NumericType, D> rayTracer;
4344
rayTracer.setGeometry(points, normals, gridDelta);

examples/disk3D/disk3D.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ int main() {
3030
// however the boundary condition in direction of the tracing direction will
3131
// not be used. Possible choices are: PERIODIC, REFLECTIVE, IGNORE
3232
BoundaryCondition boundaryConds[D];
33-
boundaryConds[0] = BoundaryCondition::PERIODIC; // x
34-
boundaryConds[1] = BoundaryCondition::PERIODIC; // y
35-
boundaryConds[2] = BoundaryCondition::PERIODIC; // z
33+
boundaryConds[0] = BoundaryCondition::PERIODIC_BOUNDARY; // x
34+
boundaryConds[1] = BoundaryCondition::PERIODIC_BOUNDARY; // y
35+
boundaryConds[2] = BoundaryCondition::PERIODIC_BOUNDARY; // z
3636

3737
// ParticleType: The particle types provides the sticking probability and
3838
// the reflection process for each surface hit. This class can be user
3939
// defined, but has to interface the rayParticle<NumericType> class and
4040
// provide the functions: initNew(...), surfaceCollision(...),
4141
// surfaceReflection(...).
42-
auto particle =
43-
std::make_unique<DiffuseParticle<NumericType, D>>(0.1, "flux");
42+
NumericType stickingProbability = 0.1;
43+
auto particle = std::make_unique<DiffuseParticle<NumericType, D>>(
44+
stickingProbability, "flux");
4445

4546
TraceDisk<NumericType, D> rayTracer;
4647
rayTracer.setGeometry(points, normals, gridDelta);

examples/triangle2D/triangle2D.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ int main() {
2323
TraceTriangle<NumericType, D> tracer;
2424
tracer.setGeometry(lineMesh);
2525

26-
auto particle =
27-
std::make_unique<DiffuseParticle<NumericType, D>>(0.1, "flux");
26+
NumericType stickingProbability = 0.1;
27+
auto particle = std::make_unique<DiffuseParticle<NumericType, D>>(
28+
stickingProbability, "flux");
2829
tracer.setParticleType(particle);
2930
tracer.setNumberOfRaysPerPoint(5000);
3031

examples/triangle3D/triangle3D.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ int main() {
2323
TraceTriangle<NumericType, D> tracer;
2424
tracer.setGeometry(mesh);
2525

26-
auto particle =
27-
std::make_unique<DiffuseParticle<NumericType, D>>(0.1, "flux");
26+
NumericType stickingProbability = 0.1;
27+
auto particle = std::make_unique<DiffuseParticle<NumericType, D>>(
28+
stickingProbability, "flux");
2829
tracer.setParticleType(particle);
2930
tracer.setNumberOfRaysPerPoint(2000);
3031

gpu/CMakeLists.txt

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
1-
project(ViennaRay-GPU)
2-
3-
option(VIENNARAY_ENABLE_OPTIXIR_SUPPORT
4-
"Enable support for generating OptiX-IR targeted input files" ON)
5-
6-
if(CUDA_VERSION VERSION_LESS 11.7)
7-
if(VIENNARAY_ENABLE_OPTIXIR_SUPPORT)
8-
message(
9-
SEND_ERROR "VIENNARAY_ENABLE_OPTIXIR_SUPPORT is not supported in CUDA versions less than 11.7"
10-
)
11-
endif()
12-
endif()
13-
14-
if(VIENNARAY_ENABLE_OPTIXIR_SUPPORT)
15-
option(VIENNARAY_GENERATE_OPTIXIR "Generate Optix-IR OptiX shaders" ON)
16-
option(VIENNARAY_GENERATE_PTX "Generate PTX OptiX shaders" OFF)
17-
else()
18-
option(VIENNARAY_GENERATE_OPTIXIR "Generate Optix-IR OptiX shaders" OFF)
19-
option(VIENNARAY_GENERATE_PTX "Generate PTX OptiX shaders" ON)
20-
endif()
21-
221
#### Set variables
23-
set(VIENNARAY_GPU_INCLUDE
24-
"${PROJECT_SOURCE_DIR}/include"
25-
CACHE STRING "ViennaRay GPU headers.")
262
set(VIENNARAY_CUDA_KERNELS
27-
"${PROJECT_SOURCE_DIR}/kernels/normKernels.cu"
3+
"${PROJECT_SOURCE_DIR}/gpu/kernels/normKernels.cu"
284
CACHE STRING "ViennaRay CUDA kernel source files.")
295
set(VIENNARAY_PIPELINE_DIR
30-
"${PROJECT_SOURCE_DIR}/pipelines"
6+
"${PROJECT_SOURCE_DIR}/gpu/pipelines"
317
CACHE STRING "ViennaRay pipeline directory.")
32-
include("../cmake/generate_ptx.cmake")
8+
9+
# Incldue directories for PTX and optix-ir compilation (force cache to update with new entries)
10+
if(NOT VIENNARAY_PASSED_FIRST_CONFIGURE)
11+
set(VIENNACORE_NVCC_INCLUDE_DIRS
12+
${VIENNACORE_NVCC_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include/viennaray/gpu
13+
CACHE STRING "PTX include directories" FORCE)
14+
if(VIENNARAY_GPU_DOUBLE_PRECISION)
15+
set(VIENNACORE_NVCC_DEFINES
16+
${VIENNACORE_NVCC_DEFINES} "VIENNARAY_GPU_DOUBLE_PRECISION=1"
17+
CACHE STRING "PTX compile definitions" FORCE)
18+
endif()
19+
endif()
20+
21+
# Add the general pipelines and callable wrapper
22+
viennacore_add_optixir(GeneralPipelineDisk ${VIENNARAY_PIPELINE_DIR}/GeneralPipelineDisk.cu)
23+
viennacore_add_optixir(GeneralPipelineTriangle ${VIENNARAY_PIPELINE_DIR}/GeneralPipelineTriangle.cu)
24+
viennacore_add_optixir(GeneralPipelineLine ${VIENNARAY_PIPELINE_DIR}/GeneralPipelineLine.cu)
25+
viennacore_add_optixir(ViennaRayCallableWrapper ${VIENNARAY_PIPELINE_DIR}/CallableWrapper.cu)
26+
27+
# Add the norm kernels
28+
viennacore_add_ptx(normKernels ${VIENNARAY_CUDA_KERNELS})
29+
30+
# CMake target to collect all GPU dependencies for tests and examples
31+
set(VIENNARAY_GPU_DEPENDENCIES
32+
GeneralPipelineDisk GeneralPipelineTriangle GeneralPipelineLine normKernels
33+
CACHE STRING "ViennaRay GPU dependencies.")
34+
# Install PTX files
35+
install(DIRECTORY "${VIENNACORE_NVCC_PTX_DIR}/" DESTINATION "lib/ptx")
3336

3437
if(VIENNARAY_BUILD_EXAMPLES)
3538
message(STATUS "[ViennaRay] Adding GPU Examples")
@@ -40,3 +43,7 @@ if(VIENNARAY_BUILD_TESTS)
4043
message(STATUS "[ViennaRay] Adding GPU Tests")
4144
add_subdirectory(tests)
4245
endif()
46+
47+
set(VIENNARAY_PASSED_FIRST_CONFIGURE
48+
ON
49+
CACHE INTERNAL "Indicates whether the first configure has been passed.")

gpu/examples/CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ project(ViennaRay-GPU_Examples)
22

33
add_custom_target(ViennaRay-GPU_Examples ALL)
44

5-
add_gpu_executable(GPU_trenchTriangles target_name trenchTriangles.cpp)
5+
add_executable(GPU_trenchTriangles trenchTriangles.cpp)
6+
target_link_libraries(GPU_trenchTriangles PRIVATE ViennaRay)
67
configure_file(${CMAKE_SOURCE_DIR}/examples/triangle3D/trenchMesh.dat
78
${CMAKE_CURRENT_BINARY_DIR}/trenchMesh.dat COPYONLY)
8-
add_dependencies(ViennaRay-GPU_Examples ${target_name})
9+
add_dependencies(ViennaRay-GPU_Examples GPU_trenchTriangles)
910

10-
add_gpu_executable(GPU_trenchDisks target_name trenchDisks.cpp)
11+
add_executable(GPU_trenchDisks trenchDisks.cpp)
12+
target_link_libraries(GPU_trenchDisks PRIVATE ViennaRay)
1113
configure_file(${CMAKE_SOURCE_DIR}/examples/disk3D/trenchGrid3D.dat
1214
${CMAKE_CURRENT_BINARY_DIR}/trenchGrid3D.dat COPYONLY)
13-
add_dependencies(ViennaRay-GPU_Examples ${target_name})
15+
add_dependencies(ViennaRay-GPU_Examples GPU_trenchDisks)
1416

15-
add_gpu_executable(GPU_trenchLines target_name trenchLines.cpp)
17+
add_executable(GPU_trenchLines trenchLines.cpp)
18+
target_link_libraries(GPU_trenchLines PRIVATE ViennaRay)
1619
configure_file(${CMAKE_SOURCE_DIR}/examples/triangle2D/lineMesh.dat
1720
${CMAKE_CURRENT_BINARY_DIR}/lineMesh.dat COPYONLY)
18-
add_dependencies(ViennaRay-GPU_Examples ${target_name})
21+
add_dependencies(ViennaRay-GPU_Examples GPU_trenchLines)
22+
23+
add_dependencies(ViennaRay-GPU_Examples ${VIENNARAY_GPU_DEPENDENCIES} ViennaRayCallableWrapper)

gpu/examples/trenchDisks.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <raygTraceDisk.hpp>
1+
#include <gpu/raygTraceDisk.hpp>
22

33
#include <omp.h>
44

@@ -11,8 +11,7 @@ int main() {
1111
using NumericType = float;
1212
Logger::setLogLevel(LogLevel::DEBUG);
1313

14-
auto context = DeviceContext::createContext("../../lib/ptx", 0);
15-
// relative to build directory
14+
auto context = DeviceContext::createContext();
1615

1716
// Read stored geometry grid
1817
NumericType gridDelta;
@@ -43,7 +42,7 @@ int main() {
4342
gpu::TraceDisk<NumericType, D> tracer(context);
4443
tracer.setGeometry(mesh);
4544
tracer.setMaterialIds(materialIds);
46-
tracer.setCallables("CallableWrapper", context->modulePath);
45+
tracer.setCallables("ViennaRayCallableWrapper", context->modulePath);
4746
tracer.setParticleCallableMap({pMap, cMap});
4847
tracer.setNumberOfRaysPerPoint(1000);
4948
tracer.insertNextParticle(particle);

0 commit comments

Comments
 (0)