Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cb67959
Added cuBQL as a submodule
Waqar-ukaea Apr 27, 2026
d024cef
Added required CMake wiring + a CMakePresets.json for offload flags
Waqar-ukaea Apr 28, 2026
5bbaf15
Added constructor setup for a cubql backend
Waqar-ukaea Apr 28, 2026
42d8b94
Added cubql ray tracer header + implmentation stubs
Waqar-ukaea Apr 28, 2026
e3ef067
Added a nvhpc preset
Waqar-ukaea Apr 28, 2026
f83cefc
Added some guards to ensure that cubql path stays on OMP and doesnt s…
Waqar-ukaea Apr 28, 2026
3b97785
Added a TODO comment to fix the loading of libomptarget.so
Waqar-ukaea Apr 29, 2026
250fe62
Working towards creation of a surface BLAS from mesh manager data
Waqar-ukaea Apr 30, 2026
41cd31c
Copy vertices+indices to device and build bvh
Waqar-ukaea Apr 30, 2026
4031f75
Added objects for storage of bvhs
Waqar-ukaea May 1, 2026
a70df01
Prototyping with codex. Working ray-fire. MAKE SURE TO RESET TO PREVI…
Waqar-ukaea May 1, 2026
1766d71
Added some additional comments and cleanups
Waqar-ukaea May 6, 2026
69895a0
Cleaned up the plucker intersection function for cuBQL
Waqar-ukaea May 7, 2026
764086d
Removed constexpr EARLY_EXIT as nvlink couldn't resolve it
Waqar-ukaea May 7, 2026
21c9fd2
Fixes for rebase from main
Waqar-ukaea May 14, 2026
68c51ae
Updated CMakeLists to make proper use of PRIVATE after rebasing recen…
Waqar-ukaea May 14, 2026
b742aeb
Fix runtime check for available rt libraries
Waqar-ukaea May 15, 2026
6cf0adb
Reducing the number of queries in cross check for now since cubql pat…
Waqar-ukaea May 15, 2026
f486c3b
Reworked normal/sense handling so normals are calculated and sense ha…
Waqar-ukaea May 15, 2026
1895ee0
Added an omp_target_device_probe and put it into the same header as t…
Waqar-ukaea May 15, 2026
3473b76
Introduced a cubql_backend Context object to store host_id and device_id
Waqar-ukaea May 15, 2026
0fd848e
Implemented a version of DPRT's AutoUploadArray for RAII style contai…
Waqar-ukaea May 15, 2026
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@
[submodule "vendor/GPRT"]
path = vendor/GPRT
url = https://github.com/gprt-org/GPRT.git
[submodule "vendor/cuBQL"]
path = vendor/cuBQL
url = https://github.com/NVIDIA/cuBQL
54 changes: 51 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ option(XDG_ENABLE_LIBMESH "Enable support for the libMesh mesh library" OFF
option(XDG_LINK_MPI "Link with MPI (for dependency compatibility)" OFF)
option(XDG_ENABLE_EMBREE "Enable support for the Embree ray tracing library" ON)
option(XDG_ENABLE_GPRT "Enable support for the GPRT ray tracing library" OFF)
option(XDG_ENABLE_CUBQL "Enable support for the cuBQL ray tracing library" OFF)
option(XDG_BUILD_TESTS "Enable C++ unit testing" ON)
option(XDG_BUILD_TOOLS "Enable tools and miniapps" ON)

Expand All @@ -20,6 +21,10 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose build type" FORCE)
endif()

if(DEFINED XDG_CMAKE_PRESET)
message(STATUS "XDG CMake preset: ${XDG_CMAKE_PRESET}")
endif()

# Compiler options (things in this section may not be platform-portable)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

Expand Down Expand Up @@ -111,6 +116,12 @@ if(XDG_ENABLE_GPRT)
)
endif()

if(XDG_ENABLE_CUBQL)
list(APPEND VENDOR_PATHS
vendor/cuBQL
)
endif()

if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
option(XDG_GIT_SUBMODULE "Check submodules during build" ON)
if(XDG_GIT_SUBMODULE)
Expand Down Expand Up @@ -175,11 +186,12 @@ if (NOT XDG_ENABLE_MOAB AND NOT XDG_ENABLE_LIBMESH)
endif()

# Ensure at least one ray tracing backend is enabled
if (NOT XDG_ENABLE_EMBREE AND NOT XDG_ENABLE_GPRT)
if (NOT XDG_ENABLE_EMBREE AND NOT XDG_ENABLE_GPRT AND NOT XDG_ENABLE_CUBQL)
message(FATAL_ERROR
"No ray tracing backend enabled. Enable at least one of:\n"
" -DXDG_ENABLE_EMBREE=ON\n"
" -DXDG_ENABLE_GPRT=ON")
" -DXDG_ENABLE_GPRT=ON\n"
" -DXDG_ENABLE_CUBQL=ON")
endif()

# GPRT
Expand All @@ -188,6 +200,11 @@ if (XDG_ENABLE_GPRT)
add_subdirectory(vendor/GPRT)
endif()

if (XDG_ENABLE_CUBQL)
set(CUBQL_OMP ON CACHE BOOL "Build cuBQL with OpenMP target offload" FORCE)
add_subdirectory(vendor/cuBQL)
endif()

list(APPEND xdg_sources
src/geometry/measure.cpp
src/geometry/plucker.cpp
Expand Down Expand Up @@ -221,6 +238,20 @@ dbl_deviceCode

endif()

if (XDG_ENABLE_CUBQL)
list(APPEND xdg_sources
src/cuBQL/ray_tracer.cpp
)

# We need a precompile definition to switch to using the cuBQL math types in the shared
# plucker intersection code. The compile definition is used in dp__math.h
set_source_files_properties(
src/cuBQL/ray_tracer.cpp
PROPERTIES COMPILE_DEFINITIONS XDG_DP_MATH_CUBQL
)

endif()

if (XDG_ENABLE_LIBMESH)
list(APPEND xdg_sources
src/libmesh/mesh_manager.cpp
Expand Down Expand Up @@ -281,7 +312,12 @@ if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
endif()

# attempt to find OpenMP and include it if found
find_package(OpenMP)
if (XDG_ENABLE_CUBQL)
find_package(OpenMP REQUIRED)
else()
find_package(OpenMP)
endif()

if (OpenMP_CXX_FOUND)
target_link_libraries(xdg PRIVATE OpenMP::OpenMP_CXX)
target_compile_definitions(xdg PRIVATE XDG_HAVE_OPENMP)
Expand Down Expand Up @@ -319,6 +355,18 @@ if (XDG_ENABLE_GPRT)
target_link_options(xdg PRIVATE -Wl,--unresolved-symbols=ignore-in-shared-libs)
endif()

if (XDG_ENABLE_CUBQL)
target_compile_definitions(xdg PUBLIC XDG_ENABLE_CUBQL)
target_link_libraries(xdg PRIVATE $<BUILD_INTERFACE:cuBQL>)
# TODO: Stop relying on LD_LIBRARY_PATH for LLVM OpenMP offload runtimes.
# As a temporary measure whilst figuring out our way around cuBQL this is
# okay but in the long run we should aim for a more robust solutions here.
# Clang injects libomptarget when offload flags are supplied by presets, but
# CMake does not currently add that compiler runtime directory to RPATH.
# Add targeted BUILD_RPATH handling for libomptarget/libomp, and decide
# whether install RPATH should remain environment-module based or be opt-in.
endif()

target_link_libraries(xdg PRIVATE fmt::fmt)

# ==========================
Expand Down
68 changes: 68 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"version": 3,
"configurePresets": [
{
"name": "base",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_CXX_FLAGS": "$env{PRESET_CXX_FLAGS} $env{LLVM_CXX_FLAGS} $env{COMMON_CXX_FLAGS}",
"XDG_CMAKE_PRESET": "${presetName}"
},
"environment": {
"COMMON_CXX_FLAGS": ""
}
},
{
"name": "llvm",
"inherits": ["base"],
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
},
"environment": {
"LLVM_CXX_FLAGS": "-fopenmp -fopenmp-cuda-mode"
}
},
{
"name": "cubql_llvm_ada",
"inherits": ["llvm"],
"displayName": "cuBQL LLVM OpenMP offload RTX 2000 Ada",
"cacheVariables": {
"XDG_ENABLE_CUBQL": "ON"
},
"environment": {
"PRESET_CXX_FLAGS": "-fopenmp-targets=nvptx64 -Xopenmp-target -march=sm_80"
}
},
{
"name": "nvhpc",
"inherits": ["base"],
"cacheVariables": {
"CMAKE_C_COMPILER": "nvc",
"CMAKE_CXX_COMPILER": "nvc++"
}
},
{
"name": "cubql_nvhpc_ada",
"inherits": ["nvhpc"],
"displayName": "cuBQL NVHPC OpenMP offload RTX 2000 Ada",
"cacheVariables": {
"XDG_ENABLE_CUBQL": "ON"
},
"environment": {
"PRESET_CXX_FLAGS": "-mp=gpu -Minfo=mp -gpu=cc89"
}
}
],
"buildPresets": [
{
"name": "cubql_llvm_ada",
"configurePreset": "cubql_llvm_ada"
},
{
"name": "cubql_nvhpc_ada",
"configurePreset": "cubql_nvhpc_ada"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#pragma once

#ifdef XDG_ENABLE_GPRT
#include "xdg/error.h"

// --------------------------------------------------------------------------------------
// Vulkan probe functions to check for ray tracing capable devices at runtime
// --------------------------------------------------------------------------------------
#ifdef XDG_ENABLE_GPRT

#include <cstring>
#include <string>
#include <vector>
Expand Down Expand Up @@ -90,5 +94,47 @@ inline bool system_has_vk_device()
missing);
return false;
}
#endif

// --------------------------------------------------------------------------------------
// OpenMP target probe functions to check for devices capable of running cuBQL at runtime
// --------------------------------------------------------------------------------------

#ifdef XDG_ENABLE_CUBQL

#include <omp.h>

inline bool system_has_omp_target_device()
{
const int device_count = omp_get_num_devices();
if (device_count <= 0) {
warning("No OpenMP target devices found; cuBQL ray tracer unavailable.");
return false;
}

const int host_id = omp_get_initial_device();
for (int device_id = 0; device_id < device_count; ++device_id) {
int value = 1;
void* d_value = omp_target_alloc(sizeof(int), device_id);
if (!d_value) continue;

const int copy_result = omp_target_memcpy(d_value,
&value,
sizeof(int),
0,
0,
device_id,
host_id);
omp_target_free(d_value, device_id);

if (copy_result == 0) {
write_message("Found OpenMP target device {}.", device_id);
return true;
}
}

warning("OpenMP target devices were found, but none accepted target allocation; cuBQL ray tracer unavailable.");
return false;
}

#endif
8 changes: 5 additions & 3 deletions include/xdg/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ enum class MeshLibrary {
// Ray Tracing library identifier
enum class RTLibrary {
EMBREE,
GPRT
GPRT,
CUBQL
};

static const std::map<MeshLibrary, std::string> MESH_LIB_TO_STR =
Expand All @@ -67,7 +68,8 @@ static const std::map<MeshLibrary, std::string> MESH_LIB_TO_STR =
static const std::map<RTLibrary, std::string> RT_LIB_TO_STR =
{
{RTLibrary::EMBREE, "EMBREE"},
{RTLibrary::GPRT, "GPRT"}
{RTLibrary::GPRT, "GPRT"},
{RTLibrary::CUBQL, "CUBQL"}
};

// Mesh identifer type
Expand Down Expand Up @@ -148,4 +150,4 @@ struct formatter<xdg::MeshLibrary> : fmt::formatter<std::string> {

}

#endif // include guard
#endif // include guard
Loading