Hello,
I have trouble compiling .ptx Files from within Visual Studio, I’ll tell you what i’m trying to do and go into the exact error afterwards
Optix Prime 3.7
Windows 7 Enterprise
Visual Studio 2012
I’m working with the “tutorial” project and i’m trying to add a sphere to this scene.
In order to do so i’ve basically copied the sample5pp sphere.cu file and added the following in the main “tutorial.cpp”
std::string sphere_ptx( ptxpath( "tutorial", "sphere.cu" ) );
Program sphere_bounds = m_context->createProgramFromPTXFile( sphere_ptx, "sphere_bounds" );
Program sphere_intersect = m_context->createProgramFromPTXFile( sphere_ptx, "sphere_intersect" );
Geometry sphere = m_context->createGeometry();
sphere->setPrimitiveCount( 1u );
sphere->setBoundingBoxProgram( sphere_bounds ); //TO be written: sphere_bounds, sphere_intersect
sphere->setIntersectionProgram( sphere_intersect );
sphere["sphere"]->setFloat( 0, 0, 0, 1.5 );
Material sphere_matl = m_context->createMaterial();
Program sphere_ch = m_context->createProgramFromPTXFile( m_ptx_path , "closest_hit_radiance" );
sphere_matl->setClosestHitProgram( 0, sphere_ch );
to the createGeometry part.
now if i try to compile sample5pp i get an compilation error
1>------ Build started: Project: sample5pp, Configuration: Debug x64 ------
1> Building NVCC ptx file lib/ptx/sample5pp_generated_sphere.cu.ptx
1> CMake Warning (dev) at sample5pp_generated_sphere.cu.ptx.cmake:136 (if):
1> Policy CMP0054 is not set: Only interpret if() arguments as variables or
1> keywords when unquoted. Run "cmake --help-policy CMP0054" for policy
1> details. Use the cmake_policy command to set the policy and suppress this
1> warning.
1>
1> Quoted keywords like "COMMAND" will no longer be interpreted as keywords
1> when the policy is set to NEW. Since the policy is not set the OLD
1> behavior will be used.
1> Call Stack (most recent call first):
1> sample5pp_generated_sphere.cu.ptx.cmake:219 (cuda_execute_process)
1> This warning is for project developers. Use -Wno-dev to suppress it.
1>
1> sphere.cu
1>
1> sphere.cu
1>
1>C:/ProgramData/NVIDIA Corporation/OptiX SDK 3.7.0/SDK/sample5pp/sphere.cu(55): error : identifier "use_robust_method" is undefined
1>
1> 1 error detected in the compilation of "C:/Users/BLOODY~1/AppData/Local/Temp/tmpxft_00001694_00000000-8_sphere.cpp1.ii".
1>
1> CMake Error at sample5pp_generated_sphere.cu.ptx.cmake:320 (message):
1> Error generating file
1> C:/Users/bloodydragon/Documents/OptiX/lib/ptx/sample5pp_generated_sphere.cu.ptx
1>
1>
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
I compile by checking CUDA 7.0 in the Build Customizations of the project
In my tutorial project the sphere.cu file contains the following:
/*
* Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
*
* NVIDIA Corporation and its licensors retain all intellectual property and proprietary
* rights in and to this software, related documentation and any modifications thereto.
* Any use, reproduction, disclosure or distribution of this software and related
* documentation without an express license agreement from NVIDIA Corporation is strictly
* prohibited.
*
* TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS*
* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
* INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY
* SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF
* BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
* INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGES
*/
#include <optix_world.h>
#include <optixu/optixu_math_namespace.h>
#include <optixu/optixu_matrix_namespace.h>
#include <optixu/optixu_aabb_namespace.h>
using namespace optix;
rtDeclareVariable(float4, sphere, , );
rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, );
rtDeclareVariable(float3, shading_normal, attribute shading_normal, );
rtDeclareVariable(optix::Ray, ray, rtCurrentRay, );
template<bool use_robust_method>
RT_PROGRAM void sphere_intersect(int)
{
float3 center = make_float3(sphere);
float3 O = ray.origin - center;
float3 D = ray.direction;
float radius = sphere.w;
float b = dot(O, D);
float c = dot(O, O)-radius*radius;
float disc = b*b-c;
if(disc > 0.0f){
float sdisc = sqrtf(disc);
float root1 = (-b - sdisc);
bool do_refine = false;
float root11 = 0.0f;
if(use_robust_method && fabsf(root1) > 10.f * radius) {
do_refine = true;
}
if(do_refine) {
// refine root1
float3 O1 = O + root1 * ray.direction;
b = dot(O1, D);
c = dot(O1, O1) - radius*radius;
disc = b*b - c;
if(disc > 0.0f) {
sdisc = sqrtf(disc);
root11 = (-b - sdisc);
}
}
bool check_second = true;
if( rtPotentialIntersection( root1 + root11 ) ) {
shading_normal = geometric_normal = (O + (root1 + root11)*D)/radius;
if(rtReportIntersection(0))
check_second = false;
}
if(check_second) {
float root2 = (-b + sdisc) + (do_refine ? root1 : 0);
if( rtPotentialIntersection( root2 ) ) {
shading_normal = geometric_normal = (O + root2*D)/radius;
rtReportIntersection(0);
}
}
}
}
RT_PROGRAM void sphere_bounds (int, float result[6])
{
const float3 cen = make_float3( sphere );
const float3 rad = make_float3( sphere.w );
optix::Aabb* aabb = (optix::Aabb*)result;
if( rad.x > 0.0f && !isinf(rad.x) ) {
aabb->m_min = cen - rad;
aabb->m_max = cen + rad;
} else {
aabb->invalidate();
}
}
If i build the tutorial project i get:
1>------ Build started: Project: tutorial, Configuration: Debug x64 ------
1>sphere.cu.obj : error LNK2019: unresolved external symbol cudaSetupArgument referenced in function “void __cdecl __device_stub__Z13sphere_boundsiPf(int,float *)” (?__device_stub__Z13sphere_boundsiPf@@YAXHPEAM@Z)
1>sphere.cu.obj : error LNK2019: unresolved external symbol cudaLaunch referenced in function “enum cudaError __cdecl cudaLaunch(char *)” (??$cudaLaunch@D@@YA?AW4cudaError@@PEAD@Z)
1>sphere.cu.obj : error LNK2019: unresolved external symbol __cudaRegisterFatBinary referenced in function “void __cdecl __nv_cudaEntityRegisterCallback(void * *)” (?__nv_cudaEntityRegisterCallback@@YAXPEAPEAX@Z)
1>sphere.cu.obj : error LNK2019: unresolved external symbol __cudaUnregisterFatBinary referenced in function “void __cdecl __cudaUnregisterBinaryUtil(void)” (?__cudaUnregisterBinaryUtil@@YAXXZ)
1>sphere.cu.obj : error LNK2019: unresolved external symbol __cudaRegisterVar referenced in function “void __cdecl __nv_cudaEntityRegisterCallback(void * *)” (?__nv_cudaEntityRegisterCallback@@YAXPEAPEAX@Z)
1>sphere.cu.obj : error LNK2019: unresolved external symbol __cudaRegisterFunction referenced in function “void __cdecl __nv_cudaEntityRegisterCallback(void * *)” (?__nv_cudaEntityRegisterCallback@@YAXPEAPEAX@Z)
1>C:\Users\bloodydragon\Documents\OptiX\bin\Debug\tutorial.exe : fatal error LNK1120: 6 unresolved externals
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
Can you explain to me wheter my apporach to building is flawed - how come sample projects cannot be build?
or what else could be wrong?
lg
Mike
PS: please let me know how to improve my question asking approach