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
74 changes: 69 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,53 @@ set(BARNEY_VERSION ${BARNEY_VERSION_MAJOR}.${BARNEY_VERSION_MINOR}.${BARNEY_VERS
project(Barney VERSION ${BARNEY_VERSION} LANGUAGES C CXX)
include(GNUInstallDirs)

set(BARNEY_RTC_EXT
set(BARNEY_RTC_EXT
"" CACHE STRING
"Experimental/external rtcore config.")
mark_as_advanced(USE_EXT)

set(BARNEY_DEVICE_NAME
# barney's own cmake modules (e.g. Findhiprt.cmake for the HIPRT backend)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# AMD GPU support: compile barney's OptiX-free software ray-tracing backend
# (rtcore/cuda + rtcore/cudaCommon) through HIP/ROCm. When USE_HIP is ON the
# .cu sources are compiled with hipcc (LANGUAGE HIP); the CUDA/OptiX build is
# unaffected (this whole path is inert unless USE_HIP is requested).
option(USE_HIP "Build GPU code with HIP for AMD GPUs" OFF)

set(BARNEY_DEVICE_NAME
"barney" CACHE STRING
"Name of device to be built.")

if ((NOT BARNEY_RTC_EXT STREQUAL "") AND (EXISTS "${BARNEY_RTC_EXT}"))
set(BARNEY_HAVE_EXT ON)
include(${BARNEY_RTC_EXT}/config.cmake)
elseif (USE_HIP)
enable_language(HIP)
# enable_language(HIP) above auto-detects the host GPU arch (and errors on a
# no-GPU build host); pass -DCMAKE_HIP_ARCHITECTURES=... to override.
message("#barney: building GPU code with HIP for CMAKE_HIP_ARCHITECTURES=${CMAKE_HIP_ARCHITECTURES}")
# the cuda backend's GPU code is reused under HIP; OptiX is NVIDIA-only.
set(BARNEY_HAVE_HIP ON)
set(BARNEY_HAVE_CUDA OFF)
set(CMAKE_CUDA_ARCHITECTURES)
if (WIN32)
# On Windows, CMake's Windows-Clang platform module injects -fuse-ld=lld-link
# into HIP link commands, but the AMD clang driver rejects it when doing HIP
# device-link (--hip-link); lld-link is the default host linker already.
set(CMAKE_HIP_USING_LINKER_DEFAULT "")
endif()

# Optional hardware-RT backend on AMD GPUs via AMD HIPRT. HIPRT supplies the
# BVH build + ray traversal (hardware-accelerated on RDNA2+, software on CDNA
# such as gfx90a); barney keeps its function-pointer shading dispatch. HIPRT
# is a discovered dependency (find via hiprt_ROOT / HIPRT_PATH), never
# vendored -- mirrors how barney finds OptiX/OIDN.
option(BARNEY_BACKEND_HIPRT "Enable HIPRT hardware-RT backend (AMD)?" OFF)
if (BARNEY_BACKEND_HIPRT)
find_package(hiprt REQUIRED)
message("#barney: HIPRT backend enabled (hiprt at ${hiprt_LIBRARY})")
endif()
elseif (NOT BARNEY_DISABLE_CUDA)
include(CheckLanguage)
check_language(CUDA)
Expand Down Expand Up @@ -122,6 +157,16 @@ target_link_libraries(barney_config
INTERFACE
owl-config
)
if (BARNEY_HAVE_HIP)
# let the host (.cpp) translation units that include the backend's compat
# header (cuda_to_hip.h) select the HIP path; the .cu/HIP passes already see
# __HIPCC__, but plain-C++ TUs need this define.
target_compile_definitions(barney_config INTERFACE USE_HIP=1 BARNEY_HAVE_HIP=1)
# hip::host carries the ROCm include dirs and __HIP_PLATFORM_AMD__ so the
# host C++ TUs that call the hip runtime (hipMalloc/hipMemcpy/...) build.
find_package(hip REQUIRED)
target_link_libraries(barney_config INTERFACE hip::host)
endif()
target_include_directories(barney_config INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/>
Expand All @@ -142,6 +187,19 @@ endif()
if (BARNEY_HAVE_EXT)
# leave it to the external plugins to configure themselves - not
# currently working
elseif (BARNEY_HAVE_HIP)
# on AMD GPUs the default is the OptiX-free software tracer (the cuda backend);
# OptiX has no HIP equivalent here, embree is the CPU fallback. When the HIPRT
# backend is requested it is the GPU backend instead (one rtc backend per
# build); cuda_common (textures) is still built because the HIPRT backend
# reuses it, exactly as the optix backend does.
if (BARNEY_BACKEND_HIPRT)
set(BARNEY_BACKEND_CUDA OFF)
else()
option(BARNEY_BACKEND_CUDA "Enable software-tracer GPU backend?" ON)
endif()
set(BARNEY_BACKEND_OPTIX OFF)
set(BARNEY_BACKEND_EMBREE OFF)
elseif (BARNEY_HAVE_CUDA)
option(BARNEY_BACKEND_CUDA "Enable (native-)CUDA Backend?" OFF)
option(BARNEY_BACKEND_OPTIX "Enable OptiX Backend?" ON)
Expand All @@ -157,6 +215,9 @@ option(BARNEY_DISABLE_DENOISING "DISable denoising" OFF)
option(BARNEY_HAVE_NANOVDB "Include Support for NanoVDB" ON)

option(BARNEY_USE_EXTERNAL_CUBQL "Use External CuBQL dir" OFF)
set(BARNEY_EXTERNAL_CUBQL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../cuBQL" CACHE PATH
"Path to an external cuBQL source tree (when BARNEY_USE_EXTERNAL_CUBQL is ON)")
set(BARNEY_CUBQL_BVH_WIDTH 4 CACHE INT "CuBQL BVH width")

# ==================================================================
if (BARNEY_DISABLE_DENOISING)
Expand Down Expand Up @@ -184,18 +245,21 @@ endif()
# ------------------------------------------------------------------

if (NOT (TARGET cuBQL))
if (BARNEY_HAVE_CUDA)
if (BARNEY_HAVE_HIP)
# build cuBQL's GPU code through HIP for the same arch(s) as barney
set(CUBQL_USE_HIP ON)
elseif (BARNEY_HAVE_CUDA)
else()
set(CUBQL_DISABLE_CUDA ON)
endif()
if (BARNEY_USE_EXTERNAL_CUBQL)
add_subdirectory(../cuBQL EXCLUDE_FROM_ALL builddir_cuBQL)
add_subdirectory(${BARNEY_EXTERNAL_CUBQL_DIR} EXCLUDE_FROM_ALL builddir_cuBQL)
else()
add_subdirectory(submodules/cuBQL EXCLUDE_FROM_ALL)
endif()
endif()

if (BARNEY_HAVE_CUDA)
if (BARNEY_HAVE_CUDA OR BARNEY_HAVE_HIP)
option(BARNEY_CUBQL_HOST "Use CUBQL host builder" OFF)
else()
set(BARNEY_CUBQL_HOST ON)
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ For CUDA/OptiX Acceleration, it also requires:

- `OptiX`, as part of OWL. See documentation in OWL (https://github.com/NVIDIA/owl) for
where to get, and how to best install for OWL to easily find it)

For AMD GPU (ROCm/HIP) Acceleration, it instead requires:

- `ROCm` (https://rocm.docs.amd.com/), version 7 and up, which provides `hipcc`
and the HIP runtime. The same GPU code that builds for CUDA is compiled with
HIP; OptiX is NVIDIA-only and is not used in this configuration.

- optionally, `HIPRT` (https://github.com/GPUOpen-LibrariesAndSDKs/HIPRT) for
hardware-accelerated ray traversal. Without it, barney uses its own
(cuBQL-based) software traversal.

For MPI-based data-parallel rendering:

Expand Down Expand Up @@ -152,6 +162,13 @@ cmake --install .. [ --config Release ]
By default Barney builds without MPI support; to enable this add
`-DBARNEY_MPI=ON` to the cmake config command.

To build for AMD GPUs with HIP/ROCm instead of CUDA/OptiX, add `-DUSE_HIP=ON`
and select the target architecture with `-DCMAKE_HIP_ARCHITECTURES=<arch>` (for
example `gfx90a` for CDNA2, or `gfx1100` for RDNA3); when left unset it defaults
to `gfx90a`. To use HIPRT hardware traversal, also add `-DBARNEY_BACKEND_HIPRT=ON
-Dhiprt_ROOT=<HIPRT-install>`. The CUDA/OptiX build is unchanged when `USE_HIP`
is off.



# Examples of Supported Geometry and Volume Types
Expand Down
15 changes: 12 additions & 3 deletions anari/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,18 @@ if(WIN32)
${BARNEY_DEVICE_NAME}_static
anari::helium
)
set_target_properties(anari_library_${BARNEY_DEVICE_NAME} PROPERTIES
LINK_FLAGS "/WHOLEARCHIVE:${BARNEY_DEVICE_NAME}_static"
)
if (BARNEY_HAVE_HIP)
# When linking through the HIP device-link wrapper (clang++ --hip-link),
# /WHOLEARCHIVE must be passed via -Xlinker so clang forwards it to lld-link
# rather than treating it as an input file.
set_target_properties(anari_library_${BARNEY_DEVICE_NAME} PROPERTIES
LINK_FLAGS "-Xlinker /WHOLEARCHIVE:${BARNEY_DEVICE_NAME}_static.lib"
)
else()
set_target_properties(anari_library_${BARNEY_DEVICE_NAME} PROPERTIES
LINK_FLAGS "/WHOLEARCHIVE:${BARNEY_DEVICE_NAME}_static.lib"
)
endif()
else()
target_link_libraries(anari_library_${BARNEY_DEVICE_NAME} PRIVATE
$<BUILD_INTERFACE:banari-config>
Expand Down
48 changes: 47 additions & 1 deletion barney/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ macro(set_library_properties tgt)
CUDA_RESOLVE_DEVICE_SYMBOLS ON
CUDA_VISIBILITY_PRESET hidden
)
if (BARNEY_HAVE_HIP)
# objects were compiled -fgpu-rdc, so the final device-link of this target
# (and anything that links it) must pass -fgpu-rdc too, otherwise hipcc skips
# the device link and the __hip_gpubin_handle symbols stay undefined.
set_target_properties(${tgt} PROPERTIES HIP_SEPARABLE_COMPILATION ON)
target_link_options(${tgt} PUBLIC -fgpu-rdc --hip-link)
target_compile_options(${tgt} PRIVATE $<$<COMPILE_LANGUAGE:HIP>:-fgpu-rdc>)
endif()
if (APPLE)
set_target_properties(${tgt} PROPERTIES INSTALL_RPATH "$loader_path")
else()
Expand Down Expand Up @@ -321,7 +329,35 @@ if (BARNEY_BACKEND_CUDA)
set_library_properties(barney_mpi_cuda)
endif()
endif()


# ------------------------------------------------------------------
# barney_hiprt: the same barney host + device programs compiled against the
# HIPRT (hardware-RT) rtcore backend. Mirrors the barney_cuda instantiation;
# HIPRT replaces the BVH build + traversal, barney keeps its function-pointer
# program dispatch, so the program set device-links exactly as the software
# backend (-fgpu-rdc, set by set_library_properties).
# ------------------------------------------------------------------
if (BARNEY_BACKEND_HIPRT)
add_library(barney_hiprt_programs STATIC ${DEVICE_PROGRAM_SOURCES})
target_link_libraries(barney_hiprt_programs PUBLIC barney_config barney_rtc_hiprt)
target_compile_definitions(barney_hiprt_programs PRIVATE -DBARNEY_DEVICE_PROGRAM=1)
set_library_properties(barney_hiprt_programs)

add_library(barney_hiprt STATIC ${HOST_SOURCES})
target_link_libraries(barney_hiprt PUBLIC barney_config barney_rtc_hiprt)
target_link_libraries(barney_hiprt PRIVATE
barney_hiprt_programs
barney_config
)
set_library_properties(barney_hiprt)

if (BARNEY_MPI)
add_library(barney_mpi_hiprt ${MPI_SOURCES})
target_link_libraries(barney_mpi_hiprt PUBLIC barney_hiprt MPI::MPI_C)
set_library_properties(barney_mpi_hiprt)
endif()
endif()


# =============================================================================
# create frontends for barney and barney_static
Expand Down Expand Up @@ -427,6 +463,16 @@ if (BARNEY_BACKEND_CUDA)
endif()
endif()

# link hiprt backend (if enabled) to all frontends
if (BARNEY_BACKEND_HIPRT)
target_link_libraries(${BARNEY_DEVICE_NAME} PRIVATE $<BUILD_INTERFACE:barney_hiprt>)
target_link_libraries(${BARNEY_DEVICE_NAME}_static PRIVATE $<BUILD_INTERFACE:barney_hiprt>)
if (BARNEY_MPI)
target_link_libraries(${BARNEY_DEVICE_NAME}_mpi PUBLIC $<BUILD_INTERFACE:barney_mpi_hiprt>)
target_link_libraries(${BARNEY_DEVICE_NAME}_mpi_static PUBLIC $<BUILD_INTERFACE:barney_mpi_hiprt>)
endif()
endif()



# ##################################################################
Expand Down
44 changes: 43 additions & 1 deletion barney/LocalContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,49 @@ namespace barney_api {
// Context *ctx = new BARNEY_NS::LocalContext(dgIDs,gpuIDs);
// return ctx;
// }
}
}
#endif
#if BARNEY_RTC_HIPRT
extern "C" {
Context *createContext_hiprt(const std::vector<int> &dgIDs,
int numGPUs, const int *gpuIDs)
{
if (FromEnv::get()->logBackend)
std::cout << "#bn: creating *hiprt (AMD hardware-RT)* context" << std::endl;
int numDGs = dgIDs.size();
if (numGPUs == -1) {
BARNEY_CUDA_CALL(GetDeviceCount(&numGPUs));
}

#if ALLOW_OVERSUBSCRIBE
std::vector<int> fakeIDs;
if (numGPUs < numDGs) {
for (int i=0;i<numDGs;i++) {
int ID = gpuIDs ? gpuIDs[i%numGPUs] : (i%numGPUs);
fakeIDs.push_back(ID);
}
gpuIDs = (const int *)fakeIDs.data();
numGPUs = numDGs;
}
#endif

if (numGPUs < numDGs)
throw std::runtime_error
("not enough HIP GPUs for requested number of data groups!");
int gpusPerDG = numGPUs / numDGs;
std::vector<LocalSlot> localSlots(dgIDs.size());
for (int lsIdx=0;lsIdx<dgIDs.size();lsIdx++) {
LocalSlot &slot = localSlots[lsIdx];
slot.dataRank = dgIDs[lsIdx];
for (int j=0;j<gpusPerDG;j++) {
int idx = lsIdx*gpusPerDG+j;
slot.gpuIDs.push_back(gpuIDs?gpuIDs[idx]:idx);
}
}
Context *ctx = new BARNEY_NS::LocalContext(localSlots);
return ctx;
}
}
#endif
}

Expand Down
18 changes: 17 additions & 1 deletion barney/api/barney.cu
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ namespace barney_api {
createContext_cuda(const std::vector<int> &dgIDs,
int numGPUs, const int *gpuIDs);
#endif
#if BARNEY_BACKEND_HIPRT
barney_api::Context *
createContext_hiprt(const std::vector<int> &dgIDs,
int numGPUs, const int *gpuIDs);
#endif
#if BARNEY_MPI
# if BARNEY_BACKEND_EMBREE
barney_api::Context *
Expand Down Expand Up @@ -868,6 +873,8 @@ namespace barney_api {
return (BNContext)createContext_optix(dataGroupIDs,numGPUs,_gpuIDs);
#elif BARNEY_BACKEND_CUDA
return (BNContext)createContext_cuda(dataGroupIDs,numGPUs,_gpuIDs);
#elif BARNEY_BACKEND_HIPRT
return (BNContext)createContext_hiprt(dataGroupIDs,numGPUs,_gpuIDs);
#else
throw std::runtime_error
("explicitly asked for GPU backend, "
Expand Down Expand Up @@ -898,7 +905,16 @@ namespace barney_api {
<< e.what() << ")" << std::endl;
}
#endif


#if BARNEY_BACKEND_HIPRT
try {
return (BNContext)createContext_hiprt(dataGroupIDs,numGPUs,_gpuIDs);
} catch (std::exception &e) {
std::cerr << "#barney(warn): could not create hiprt backend (reason: "
<< e.what() << ")" << std::endl;
}
#endif

# if BARNEY_BACKEND_EMBREE
return (BNContext)createContext_embree(dataGroupIDs);
#endif
Expand Down
3 changes: 3 additions & 0 deletions barney/include/barney.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
/*! whether the embree backend has been included in this build */
#cmakedefine01 BARNEY_BACKEND_EMBREE

/*! whether the HIPRT (AMD hardware-RT) backend has been included in this build */
#cmakedefine01 BARNEY_BACKEND_HIPRT

/*! whether this build of barney has support for MPI based rendering;
i.e., wether barney/barney_mpi.h and (if anari is enabled)
anari_library_barney_mpi exist */
Expand Down
Loading