Skip to content

Commit

Permalink
build: Change cmake option USE_OPTIX -> OSL_USE_OPTIX (#1668)
Browse files Browse the repository at this point in the history
This avoids some possible confusion with other projects, or if this
is built as a subproject.

Also, change from the C++ side having an OSL_USE_OPTIX defined -- only
for building OSL itself -- to having it always defined in oslconfig.h
and set to 0 or 1 depending on whether OptiX support was turned on at
build time. This allows app-side use of OSL headers to know if it's
dealing with an OptiX-capable OSL build.

Clean up OSL_USE_OPTIX and OSL_USE_BATCHED symbol defs

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz committed May 3, 2023
1 parent cd22f60 commit ed9857c
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 47 deletions.
7 changes: 2 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ else ()
endif ()
option (OSL_BUILD_PLUGINS "Bool OSL plugins, for example OIIO plugin" ON)
option (OSL_BUILD_SHADERS "Build shaders" ON)
option (USE_OPTIX "Include OptiX support" OFF)
option (OSL_USE_OPTIX "Include OptiX support" OFF)
message(STATUS "OSL_USE_OPTIX: ${OSL_USE_OPTIX}")
set (OPTIX_EXTRA_LIBS CACHE STRING "Extra lib targets needed for OptiX")
set (CUDA_EXTRA_LIBS CACHE STRING "Extra lib targets needed for CUDA")
set (CUDA_TARGET_ARCH "sm_60" CACHE STRING "CUDA GPU architecture (e.g. sm_50)")
Expand Down Expand Up @@ -127,10 +128,6 @@ if (OIIO_FMATH_SIMD_FRIENDLY)
add_definitions (-DOIIO_FMATH_SIMD_FRIENDLY=1)
endif ()

if (USE_OPTIX)
add_definitions ("-DOSL_USE_OPTIX=1")
endif ()

# Define OSL_INTERNAL symbol only when building OSL itself, will not be
# defined for downstream projects using OSL.
add_definitions (-DOSL_INTERNAL=1)
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ ifneq (${BUILD_MISSING_DEPS},)
endif

ifneq (${USE_OPTIX},)
MY_CMAKE_FLAGS += -DUSE_OPTIX:BOOL=${USE_OPTIX}
MY_CMAKE_FLAGS += -DOSL_USE_OPTIX:BOOL=${USE_OPTIX}
endif
ifneq (${OSL_USE_OPTIX},)
MY_CMAKE_FLAGS += -DOSL_USE_OPTIX:BOOL=${OSL_USE_OPTIX}
endif

ifneq (${USE_PYTHON},)
Expand Down Expand Up @@ -397,7 +400,7 @@ help:
@echo " USE_SIMD=arch Build with SIMD support (comma-separated choices:"
@echo " 0, sse2, sse3, ssse3, sse4.1, sse4.2, f16c,"
@echo " avx, avx2, avx512f)"
@echo " USE_OPTIX=1 Build the OptiX test renderer"
@echo " OSL_USE_OPTIX=1 Build the OptiX test renderer"
@echo " USE_BATCHED=targets Build batched SIMD execution of shaders for (comma-separated choices:"
@echo " 0, b8_AVX, b8_AVX2, b8_AVX2_noFMA,"
@echo " b8_AVX512, b8_AVX512_noFMA,"
Expand Down
4 changes: 2 additions & 2 deletions site/spi/Makefile-bits
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ ifeq (${SP_OS}, rhel7)
endif

# Cuda/OptiX
USE_OPTIX ?= 1
OSL_USE_OPTIX ?= 1
CUDA_VERSION ?= 11.1.1
OPTIX_VERSION ?= 7.2.0
# CUDA_TOOLKIT_ROOT_DIR = $(shell rez-env -b cuda-${CUDA_VERSION} ${SPI_COMPILER_PLATFORM} -c "echo '$CUDA_TOOLKIT_ROOT'")
CUDA_TOOLKIT_ROOT_DIR ?= /shots/spi/home/lib/arnold/rhel7/cuda_${CUDA_VERSION}
OptiX_ROOT ?= /shots/spi/home/lib/arnold/rhel7/optix_${OPTIX_VERSION}
OPTIXHOME = ${OptiX_ROOT}
MY_CMAKE_FLAGS += -DUSE_OPTIX=${USE_OPTIX} \
MY_CMAKE_FLAGS += -DOSL_USE_OPTIX=${OSL_USE_OPTIX} \
-DCUDA_TOOLKIT_ROOT_DIR=${CUDA_TOOLKIT_ROOT_DIR} \
-DCUDA_EXTRA_LIBS=${CUDA_EXTRA_LIBS} \
-DOPTIXHOME=${OPTIXHOME} -DOPTIX_EXTRA_LIBS=lzma
Expand Down
4 changes: 2 additions & 2 deletions src/cmake/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,11 @@ set (USE_BATCHED "" CACHE STRING "Build batched SIMD shader execution for (0, b8
option (VEC_REPORT "Enable compiler's reporting system for vectorization" OFF)
set (BATCHED_SUPPORT_DEFINES "")
set (BATCHED_TARGET_LIBS "")
set (BUILD_BATCHED False)
set (OSL_BUILD_BATCHED 0)
if (NOT USE_BATCHED STREQUAL "")
message (STATUS "Compiling with batched SIMD targets ${USE_BATCHED}")
if (NOT USE_BATCHED STREQUAL "0")
set (BUILD_BATCHED 1)
set (OSL_BUILD_BATCHED 1)
string (REPLACE "," ";" BATCHED_TARGET_LIST ${USE_BATCHED})
foreach (batched_target ${BATCHED_TARGET_LIST})
if (VERBOSE)
Expand Down
4 changes: 2 additions & 2 deletions src/cmake/externalpackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ endif ()


# CUDA setup
if (USE_CUDA OR USE_OPTIX)
if (OSL_USE_OPTIX)
if (USE_LLVM_BITCODE)
if (NOT CUDA_TOOLKIT_ROOT_DIR AND NOT $ENV{CUDA_TOOLKIT_ROOT_DIR} STREQUAL "")
set (CUDA_TOOLKIT_ROOT_DIR $ENV{CUDA_TOOLKIT_ROOT_DIR})
Expand Down Expand Up @@ -221,7 +221,7 @@ if (USE_CUDA OR USE_OPTIX)
endif()

# OptiX setup
if (USE_OPTIX AND OSL_BUILD_TESTS)
if (OSL_USE_OPTIX AND OSL_BUILD_TESTS)
checked_find_package (OptiX REQUIRED
VERSION_MIN 7.0)
include_directories (BEFORE "${OPTIX_INCLUDES}")
Expand Down
6 changes: 3 additions & 3 deletions src/cmake/testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ macro ( TESTSUITE )
# if there is an OPTIX marker file in the directory.
# If an environment variable $TESTSUITE_OPTIX is nonzero, then
# run all tests with OptiX, even if there's no OPTIX marker.
if (USE_OPTIX
if (OSL_USE_OPTIX
AND (EXISTS "${_testsrcdir}/OPTIX" OR test_all_optix OR _testname MATCHES "optix")
AND NOT EXISTS "${_testsrcdir}/NOOPTIX"
AND NOT EXISTS "${_testsrcdir}/NOOPTIX-FIXME"
Expand All @@ -162,7 +162,7 @@ macro ( TESTSUITE )
ENV TESTSHADE_OPT=2 TESTSHADE_OPTIX=1 )
endif ()

if (BUILD_BATCHED)
if (OSL_BUILD_BATCHED)
# When building for Batched support, also run it in Batched mode
# if there is an BATCHED marker file in the directory.
# If an environment variable $TESTSUITE_BATCHED is nonzero, then
Expand Down Expand Up @@ -397,7 +397,7 @@ macro (osl_add_all_tests)
endif ()

# Some regression tests have a lot of combinations and may need more time to finish
if (BUILD_BATCHED)
if (OSL_BUILD_BATCHED)
set_tests_properties (arithmetic-reg.regress.batched.opt
PROPERTIES TIMEOUT ${OSL_TEST_BIG_TIMEOUT})
set_tests_properties (transform-reg.regress.batched.opt
Expand Down
7 changes: 5 additions & 2 deletions src/include/OSL/oslconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

#pragma once

#cmakedefine01 OSL_USE_OPTIX
#cmakedefine01 OSL_BUILD_BATCHED
#define OSL_USE_BATCHED OSL_BUILD_BATCHED


#include <OSL/export.h>
#include <OSL/oslversion.h>
#include <OSL/platform.h>
Expand Down Expand Up @@ -62,8 +67,6 @@

OSL_NAMESPACE_ENTER

#define OSL_USE_BATCHED @BUILD_BATCHED@

/// Various compile-time defaults are defined here that could, in
/// principle, be redefined if you are using OSL in some particular
/// renderer that wanted things a different way.
Expand Down
6 changes: 3 additions & 3 deletions src/include/optix_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <OSL/oslconfig.h>
#include <OSL/oslversion.h>

#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
# include <cuda_runtime_api.h>
# include <optix.h>
# ifdef _WIN32
Expand All @@ -19,7 +19,7 @@
#endif


#if !defined(OSL_USE_OPTIX) && !defined(__CUDA_ARCH__)
#if !OSL_USE_OPTIX && !defined(__CUDA_ARCH__)
using CUdeviceptr = void*;
using float3 = OSL::Vec3;
#endif
Expand All @@ -28,7 +28,7 @@ using float3 = OSL::Vec3;

OSL_NAMESPACE_ENTER

#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX

////////////////////////////////////////////////////////////////////////
// If OptiX is available, alias everything in optix:: namespace into
Expand Down
2 changes: 1 addition & 1 deletion src/liboslexec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ set (lib_src
llvm_gen.cpp llvm_instance.cpp llvm_util.cpp
rs_fallback.cpp
)
if (BUILD_BATCHED)
if (OSL_BUILD_BATCHED)
list(APPEND lib_src
batched_analysis.cpp
batched_backendllvm.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/liboslexec/backendllvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ BackendLLVM::getOrAllocateLLVMSymbol(const Symbol& sym)



#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
llvm::Value*
BackendLLVM::addCUDAGlobalVariable(const std::string& name, int size,
int alignment, const void* init_data,
Expand Down Expand Up @@ -427,7 +427,7 @@ BackendLLVM::llvm_get_pointer(const Symbol& sym, int deriv,
llvm::Value* result = NULL;
if (sym.symtype() == SymTypeConst) {
TypeSpec elemtype = sym.typespec().elementtype();
#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
if (use_optix()) {
// Check the constant map for the named Symbol; if it's found, then
// a GlobalVariable has been created for it
Expand Down
2 changes: 1 addition & 1 deletion src/liboslexec/backendllvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class BackendLLVM final : public OSOProcessorBase {
/// map, the symbol is alloca'd and placed in the map.
llvm::Value* getOrAllocateLLVMSymbol(const Symbol& sym);

#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
/// Allocate a CUDA variable for the given OSL symbol and return a pointer
/// to the corresponding LLVM GlobalVariable, or return the pointer if it
/// has already been allocated.
Expand Down
4 changes: 2 additions & 2 deletions src/liboslexec/llvm_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ LLVMGEN(llvm_gen_printf)
}


#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
// In OptiX, printf currently supports 0 or 1 arguments, and the signature
// requires 1 argument, so push a null pointer onto the call args if there
// is no argument.
Expand All @@ -401,7 +401,7 @@ LLVMGEN(llvm_gen_printf)
}

// Now go back and put the new format string in its place
#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
if (rop.use_optix()) {
// In OptiX7+ case, we do this:
// void* args = { args_size, arg0, arg1, arg2 };
Expand Down
8 changes: 4 additions & 4 deletions src/liboslexec/llvm_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ BackendLLVM::llvm_assign_initial_value(const Symbol& sym, bool force)
if (sym.has_init_ops() && sym.valuesource() == Symbol::DefaultVal) {
// Handle init ops.
build_llvm_code(sym.initbegin(), sym.initend());
#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
} else if (use_optix() && !sym.typespec().is_closure()) {
// If the call to osl_bind_interpolated_param returns 0, the default
// value needs to be loaded from a CUDA variable.
Expand Down Expand Up @@ -1300,7 +1300,7 @@ BackendLLVM::initialize_llvm_group()
}
types += advance;
}
#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
if (varargs && use_optix()) {
varargs = false;
params.push_back(ll.type_void_ptr());
Expand Down Expand Up @@ -1361,7 +1361,7 @@ BackendLLVM::run()
#ifdef OSL_LLVM_NO_BITCODE
OSL_ASSERT(!use_rs_bitcode());
ll.module(ll.new_module("llvm_ops"));
# ifdef OSL_USE_OPTIX
# if OSL_USE_OPTIX
if (use_optix()) {
// If the module is created from LLVM bitcode, the target and
// data layout is inherited from that, but if creating an empty
Expand Down Expand Up @@ -1615,7 +1615,7 @@ BackendLLVM::run()
}
}

#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
if (use_optix()) {
ll.ptx_compile_group(nullptr, group().name().string(),
group().m_llvm_ptx_compiled_version);
Expand Down
2 changes: 1 addition & 1 deletion src/liboslexec/llvm_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5828,7 +5828,7 @@ bool
LLVM_Util::ptx_compile_group(llvm::Module* lib_module, const std::string& name,
std::string& out)
{
#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
std::string target_triple = module()->getTargetTriple();

OSL_ASSERT(
Expand Down
2 changes: 1 addition & 1 deletion src/testrender/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set (testrender_srcs
simpleraytracer.cpp
testrender.cpp)

if (USE_OPTIX)
if (OSL_USE_OPTIX)
list (APPEND testrender_srcs optixraytracer.cpp)
set (testrender_cuda_srcs
cuda/quad.cu
Expand Down
8 changes: 4 additions & 4 deletions src/testrender/raytracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <OSL/oslconfig.h>


#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
# include <optix.h>
# include <vector_functions.h> // from CUDA
#endif
Expand Down Expand Up @@ -167,7 +167,7 @@ struct Primitive {
void getBounds(float& minx, float& miny, float& minz, float& maxx,
float& maxy, float& maxz) const;

#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
virtual void setOptixVariables(void* data) const = 0;
#endif

Expand Down Expand Up @@ -278,7 +278,7 @@ struct Sphere final : public Primitive {
return 1 / (TWOPI * (1 - cmax));
}

#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
virtual void setOptixVariables(void* data) const
{
SphereParams* sphere_data = reinterpret_cast<SphereParams*>(data);
Expand Down Expand Up @@ -377,7 +377,7 @@ struct Quad final : public Primitive {
return d2 / (a * fabsf(dir.dot(n)));
}

#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
virtual void setOptixVariables(void* data) const
{
QuadParams* quad_data = reinterpret_cast<QuadParams*>(data);
Expand Down
2 changes: 1 addition & 1 deletion src/testrender/render_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "optix_compat.h"

#if defined(OSL_USE_OPTIX) || defined(__CUDA_ARCH__)
#if OSL_USE_OPTIX || defined(__CUDA_ARCH__)

struct RenderParams {
float3 bad_color;
Expand Down
6 changes: 3 additions & 3 deletions src/testrender/testrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "shading.h"
#include "simpleraytracer.h"

#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
# include "optixraytracer.h"
#endif

Expand Down Expand Up @@ -234,7 +234,7 @@ main(int argc, const char* argv[])
aa = aaoverride;

SimpleRaytracer* rend = nullptr;
#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
if (use_optix)
rend = new OptixRaytracer;
else
Expand Down Expand Up @@ -267,7 +267,7 @@ main(int argc, const char* argv[])
// Setup common attributes
set_shadingsys_options();

#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
if (use_optix)
reinterpret_cast<OptixRaytracer*>(rend)->synch_attributes();
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/testshade/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ set ( testshade_srcs
testshade.cpp
simplerend.cpp )

if (BUILD_BATCHED)
if (OSL_BUILD_BATCHED)
list(APPEND testshade_srcs
batched_simplerend.cpp)
endif()

if (USE_OPTIX)
if (OSL_USE_OPTIX)
list (APPEND testshade_srcs optixgridrender.cpp)
set ( testshade_cuda_srcs
cuda/optix_grid_renderer.cu
Expand Down
8 changes: 4 additions & 4 deletions src/testshade/testshade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#if OSL_USE_BATCHED
# include <OSL/batched_shaderglobals.h>
#endif
#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
# include "optixgridrender.h"
#endif

Expand Down Expand Up @@ -593,7 +593,7 @@ print_info()
{
ErrorHandler errhandler;
SimpleRenderer* rend = nullptr;
#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
if (use_optix)
rend = new OptixGridRenderer;
else
Expand Down Expand Up @@ -1846,7 +1846,7 @@ test_shade(int argc, const char* argv[])
}

SimpleRenderer* rend = nullptr;
#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
if (use_optix)
rend = new OptixGridRenderer;
else
Expand Down Expand Up @@ -2007,7 +2007,7 @@ test_shade(int argc, const char* argv[])
// object.
setup_transformations(*rend, Mshad, Mobj);

#ifdef OSL_USE_OPTIX
#if OSL_USE_OPTIX
if (use_optix) {
reinterpret_cast<OptixGridRenderer*>(rend)->set_transforms(Mobj, Mshad);
reinterpret_cast<OptixGridRenderer*>(rend)->register_named_transforms();
Expand Down

0 comments on commit ed9857c

Please sign in to comment.