It looks like you are using CMake to build your sample judging from the text in the output. It looks like the build system thinks you want to compile object files instead of PTX files. The error messages you are seeing are also indicative of this symptom.
There are several methods of compiling CUDA code from within CMake.
If you are using the CUDA run time, then you typically do the following:
cuda_add_executable(myprogram main.cpp mycuda.cu myheader.h)
This creates an executable called myprogram that is composed of two object files: main.cpp.o and mycuda.cu.o. The CUDA runtime expects the code inside the cuda file to conform to the CUDA runtime API.
In addition to cuda_add_executable
there is also cuda_add_library
which compiles a library instead of an executable. Both of these macros use another macro called cuda_wrap_srcs
that does most of the heavy lifting as far as generating the build commands to compile CUDA code. Among other things this macro has an argument for specifying if you want to use the CUDA run time or to target only PTX (the arguments are OBJ or PTX).
In order to get OptiX shaders to compile you must target PTX. In our SDK we ship, this is handled through a CMake functions called OPTIX_add_sample_executable
which can be found in <install>/SDK/CMakeLists.txt
. Mostly what this function does is call cuda_wrap_srcs
with the PTX option specified. I've included the function here for reference as well.
#########################################################
# OPTIX_add_sample_executable
#
# Convenience function for adding samples to the code. You can copy the contents of this
# function into your individual project if you wish to customize the behavior. Note that
# in CMake, functions have their own scope, whereas macros use the scope of the caller.
function(OPTIX_add_sample_executable target_name)
# These calls will group PTX and CUDA files into their own directories in the Visual
# Studio projects.
source_group("PTX Files" REGULAR_EXPRESSION ".+\\.ptx$")
source_group("CUDA Files" REGULAR_EXPRESSION ".+\\.cu$")
# Separate the sources from the CMake and CUDA options fed to the macro. This code
# comes from the CUDA_COMPILE_PTX macro found in FindCUDA.cmake. We are copying the
# code here, so that we can use our own name for the target. target_name is used in the
# creation of the output file names, and we want this to be unique for each target in
# the SDK.
CUDA_GET_SOURCES_AND_OPTIONS(source_files cmake_options options ${ARGN})
# Create the rules to build the PTX from the CUDA files.
CUDA_WRAP_SRCS( ${target_name} PTX generated_files ${source_files} ${cmake_options}
OPTIONS ${options} )
# Here is where we create the rule to make the executable. We define a target name and
# list all the source files used to create the target. In addition we also pass along
# the cmake_options parsed out of the arguments.
add_executable(${target_name}
${source_files}
${generated_files}
${cmake_options}
)
# Most of the samples link against the sutil library and the optix library. Here is the
# rule that specifies this linkage.
target_link_libraries( ${target_name}
sutil
optix
${optix_rpath}
)
endfunction()