Quick Question : how to change the default SM architecture in the Optix samples ?


I have created a project based on the bundled Optix-Samples.

I am using some features that need SM architecture greater than 2.1 and i fear that the default is lower when compiling the samples. Could you help me change it ? I have tried and failed so far.

P.S. when building the samples is reads “nvcc : warning : The ‘compute_10’ and ‘sm_10’ architectures are deprecated, and may be removed in a future release.”

and at run time
“blah blah filename : error : Feature ‘Addresses as initial values’ require PTX ISA version 2.1 of later”

OptiX ships with a FindCUDA.cmake version which is newer than the one shipped with CMake, but will probably find its way into the official release. The difference is that it supports static linking of the CUDA runtime.

(The macro(CUDA_COMPILE_PTX generated_files) contains the main logic for the custom build rule generation.)

According to the comments at the top of that FindCUDA.cmake file you should change CUDA_NVCC_FLAGS to add more nvcc command line parameters and that is done in OptiX’ top-level CMakeLists.txt file.

Search for this block

# Add some useful default arguments to the nvcc flags.  This is an example of how we use
# PASSED_FIRST_CONFIGURE.  Once you have configured, this variable is TRUE and following
# block of code will not be executed leaving you free to edit the values as much as you
# wish from the GUI or from ccmake.
  set(flag "--use_fast_math")
  list(FIND CUDA_NVCC_FLAGS ${flag} index)
  if(index EQUAL -1)
    list(APPEND CUDA_NVCC_FLAGS ${flag})
    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} CACHE LIST "Semi-colon delimit multiple arguments." FORCE)

and add your desired -arch parameter accordingly.

That comment says you can also do that in the CMake GUI after the first configuration was successful which sounds convenient, so try adding -arch sm_21 in the CUDA_NVCC_FLAGS line.
You could add a message to the CMakeLists.txt to dump what CUDA_NVCC_FLAGS is during the following configure step.

I was trying that exact solution,among others that seemed possible yesterday, but eventually it refused to add the “use fast math” directive when i added the -arch … I will try it again more carefully. Thank you very much for your time!

Building PTX binaries from CU files is actually VERY simple from a command line. My scripts look like this (Windows):

nvcc.exe -O3 -use_fast_math -arch=compute_30 -code=sm_30 -I “C:\ProgramData\NVIDIA Corporation\OptiX SDK 3.6.2\include” -I “C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include” -m 64 -ptx INPUTFILE -o OUTPUTFILENAME

You can change -arch and -code accordingly to your needs (put 21 instead of 30) and you must change the -m 64 option to -m 32 if building a 32 bits executable. You probably just want to remove this (-m) option if you’re not under Windows.

I am having the same difficulty as conkal in changing the SM architecture of the OptiX samples using Detlef’s approach. Oddly, it works just fine on my code; it’s only a problem with the samples.

Here’s the error I get:

nvcc : fatal error : redefinition of argument 'gpu-architecture'

And I can see that the -arch flag has been added twice somehow:

45>    "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v6.0/bin/nvcc.exe" -M
45>    -D__CUDACC__ "C:/ProgramData/NVIDIA Corporation/OptiX SDK
45>    3.6.2/SDK/shadeTree/sphere_array.cu" -o
45>    D:/nljones/optixTest/shadeTree/CMakeFiles/shadeTree.dir//shadeTree_generated_sphere_array.cu.ptx.NVCC-depend
45>    -ccbin "C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin" -m32
45>    --use_fast_math -arch sm_20 --compiler-options /D_USE_MATH_DEFINES -arch
45>    sm_20 -DNVCC "-IC:/Program Files/NVIDIA GPU Computing
45>    Toolkit/CUDA/v6.0/include" "-IC:/ProgramData/NVIDIA Corporation/OptiX SDK
45>    3.6.2/include" "-IC:/ProgramData/NVIDIA Corporation/OptiX SDK
45>    3.6.2/SDK/sutil" "-IC:/ProgramData/NVIDIA Corporation/OptiX SDK
45>    3.6.2/include/optixu" -ID:/nljones/optixTest "-IC:/Program Files/NVIDIA GPU
45>    Computing Toolkit/CUDA/v6.0/include" "-IC:/ProgramData/NVIDIA
45>    Corporation/OptiX SDK 3.6.2/SDK/support/freeglut/include"

As far as I can tell, I’m only responsible for the first occurrence of “-arch SM_20” in that string. However, if I remove the first -arch flag using CMake, the code compiles as SM_10.

Any ideas?

Edit: This is with Windows 7, CUDA 6.0, CMake 3.0.0, and VS 2010.