Error in rtPrintf format string: "", [7995426]

Dear all,
I can’t find a reason of the message:

OptiX Error: Invalid value (Details: Function "_rtContextLaunch2D" caught exception: Error in rtPrintf format string: "", [7995426])

Hystory:
From sample5pp I created a very simple application consisting of the only sample5pp.cpp and pinhole_camera.cu.
Extract from sample5pp.cpp:

int polarization = 2;
  context["polarization"]->setInt(polarization);

File pinhole_camera.cu:

#include <optix_world.h>

using namespace optix;
rtDeclareVariable(int,   polarization, , );

RT_PROGRAM void pinhole_camera()
  {
  //int polarization = 3; // or = 2;  it is LINE_B
  double I = 0.0, Iup = 1.0, Idown = 1.0, del1 = 0.0, del2 = 0.0, shift = 0.0;

  if (polarization != 3)
    {
    ;
    }

  else
    {
    I += 2.0 * (1.0 + cos(shift)); // LINE_A
    rtPrintf("E I %f Iup %f Idown %f shift %f del1 %f del2 %f\n", I, Iup, Idown, shift, del1, del2);
    }
  rtPrintf("E I %f Iup %f Idown %f shift %f del1 %f del2 %f\n", I, Iup, Idown, shift, del1, del2);
  rtPrintf("E I %f Iup %f Idown %f shift %f del1 %f del2 %f\n", I, Iup, Idown, shift, del1, del2);
  }

Remarks:

  1. That message arises independetly on a value of polarization ( 2 or 3 ).
  2. If I comment the line LINE_A - this message is absent
  3. if I uncomment the line LINE_B - this message is absent
  4. If rtPrintf’s fmt contains “%lf” instead of “%f” - the same result.

Where my mistake?
My configuration:
Win 8.1, x64, VS2013, GeForce GT 650M, OptiX 7.0 (final), CUDA 6.5

I assume you use OptiX 3.7.0?

Please try if the behaviour changes when not using any double variables, constants, and functions.
That is replace all “double” declarations with “float”, add an ‘f’-suffix to all immediate floating point values, and use the float variants of built-in functions: cosf() and the like.
Doubles will definitely be slow on your system.

When compiling your *.cu files use the --use_fast_math command line option and do not use any debug option -g and -G.

Other than that, I would remove all redundant rtPrintf calls. Only the last one is needed, all others print the same in your current code.

Thank you!
I assume you use OptiX 3.7.0?” - Yes, sorry.

Please try if the behaviour changes when not using any double variables, constants, and functions.
That is replace all “double” declarations with “float”, add an ‘f’-suffix to all immediate floating point values, and use the float variants of built-in functions: cosf() and the like.

Done:

#include <optix_world.h>

using namespace optix;
rtDeclareVariable(int,   polarization, , );
RT_PROGRAM void pinhole_camera()
  {
//  int polarization = 2;  // LINE_C
  float I = 0.0f, Iup = 1.0f, Idown = 1.0f, del1 = 0.0f, del2 = 0.0f, shift = 0.0f;

  if (polarization != 3)
    {
    ;
    }

  else
    {
    I += 2.0f * (1.0f + cosf(shift));
    rtPrintf("E I %f Iup %f Idown %f shift %f del1 %f del2 %f\n", I, Iup, Idown, shift, del1, del2);
    }
  rtPrintf("E I %f Iup %f Idown %f shift %f del1 %f del2 %f\n", I, Iup, Idown, shift, del1, del2);
  rtPrintf("E I %f Iup %f Idown %f shift %f del1 %f del2 %f\n", I, Iup, Idown, shift, del1, del2);
  }

Output:

E I 0.000000 Iup 1.000000 Idown 1.000000 shift 0.000000 del1 0.000000 del2 0.000
000
OptiX Error: Invalid value (Details: Function "_rtContextLaunch2D" caught except
ion: Error in rtPrintf format string: "", [7995426])

The line marked “LINE_C” if uncommented result in the same message. And host assigns “polarization = 2”.

Doubles will definitely be slow on your system.” - that’s my choice. I know about doubles/floats but the algorithm requres. I became happy once when had read in forum that cos(double) allowed.

When compiling your *.cu files use the --use_fast_math command line option and do not use any debug option -g and -G.” - I do not understand this as I use standard way of sample5pp from installed OptiX 3.7.0. So if it is necessary to change something, please, send proper corrections to makefile.

Other than that, I would remove all redundant rtPrintf calls. Only the last one is needed, all others print the same in your current code.
Yes. Nevertheless it is a legal code. I withdraw about 300 lines from pinhole_camera.cu in order to obtain a clear error. Before I had a lot of situations when rtPrintf spoiled runs of my programs (even without any doubles). Total commenting of rtPrintf was a solution. Now I decided to minimize the code.

BTW the same behavior this program shows on a desktop: Win 8.1, x64, VS2013, GeForce GTX 560 Ti, OptiX 3.7.0 (final), CUDA 6.5.
Driver 350.12 on both platforms.

Could you please try if the error is also reproducible with the OptiX 3.8.0 beta release?
I’m unable to reproduce this problem with an OptiX 3.8.0 version (though at a newer code state and a Kepler based board).

Yes.
0. download OptiX 3.8.0

  1. Run precompiled amboc, cook, whitted - ok.

  2. Create working dir, copy
    assemblies
    bin64
    doc
    include
    lib64
    SDK

  3. Bild all samples (cmake 3.1.2) SDK, vs2013
    52 successful
    Run built amboc, cook, whitted, sample5pp - ok.

  4. Taking into account that INSTALL-WIN.txt and CMakeLists.txt are the same, examine one
    of my workable projects without corrections. OK.

  5. Try our error example: the same output:

E I 0.000000 Iup 1.000000 Idown 1.000000 shift 0.000000 del1 0.000000 del2 0.000000
OptiX Error: Invalid value (Details: Function "_rtContextLaunch2D" caught exception: 
Error in rtPrintf format string: "", [7995426])
  1. Contents of the project dir: 3 files.

File pinhole_camera.cu: the same as in the post above.
Sorry I renamed project sample5pp as tworayif.

File tworayif.cpp:

//  derived from sample5pp.cpp
#include <iostream>
#include <cstdlib>
#include <optixu/optixpp_namespace.h>
#include <optixu/optixu_math_namespace.h>
#include <optixu/optixu_matrix_namespace.h>
#include <sutil.h>

using namespace optix;

unsigned int width  = 300;
unsigned int height = 300;

std::string ptxPath( const std::string& base )
  {
  return std::string(sutilSamplesPtxDir()) + "/tworayif_generated_" + base + ".ptx";
  }

int main( int argc, char** argv )
  {
  Context context = Context::create();
  context->setEntryPointCount(1);
  // test in lambdas
  int polarization = 2;
  context["polarization"]->setInt(polarization);
  // Ray generation program
  std::string ptx_path(ptxPath("pinhole_camera.cu"));
  Program ray_gen_program = context->createProgramFromPTXFile(ptx_path, 

"pinhole_camera");
  context->setRayGenerationProgram(0, ray_gen_program);
  try
  {
    // Setup state
    context->setPrintEnabled(true);
    context->setPrintBufferSize(32000);
    context->setPrintLaunchIndex(150, 200);
    // Run
    context->validate();
    context->compile();
    context->launch( 0, width, height );
    // Clean up
    context->destroy();

  } catch( Exception& e ){
    sutilReportError( e.getErrorString().c_str() );
    exit(1);
  }
  return( 0 );
}

File CMakeLists.txt:

OPTIX_add_sample_executable( tworayif
  tworayif.cpp
  pinhole_camera.cu
  )

If you have any new ideas I am ready to implement experiments.

Remove line 37 (setPrintLaunchIndex)

Dear over0219,
your suggestion means “to remove all rtPrintfs”. I am interesting in calculations of the pixel (150, 200).
My test will allow me to know whether to trust rtPrintf or not. Probably, it helps to developers to improve OptiX (or its docs) as the code of my test is a legal code, in my opinion.
sudak

I was able to reproduce your error on my own machine. Removing the duplicate rtPrintf (line 22 of your original post) makes the problem go away.

In my first pass at reproducing your error, removing the setPrintLaunchIndex ran successfully, and I figured you could just constrain your rtPrintf in your kernel (i.e if launch_index.x == 150…). But when I tested this, the same error came back. After commenting out the redundant rtPrintf, everything works peachy.

setPrintLaunchIndex(150…) plays role of " (i.e if launch_index.x == 150…).".

You do not understand my intention. I wrote a legal code (let it be stupid), it ran with errors. In current situation this means that from now on if I see some error message related to rtPrintf I don’t know who is guilty: me or OptiX.

You’re right that I didn’t understand your intention was to create an error with legal code. Usually, people just want to get passed a bug so they can continue with their work.

For what it’s worth, I’ve had rtPrintf cause odd behavior when used inappropriately.

Dear developers,

It seems I’ve found a reason of a problem. This crash of a program run occurs if 2 or more format strings are identical. See the example:

rtPrintf("q0 %f ener %f\n", q1, q2);  // Printed
  ...
  rtPrintf("q1 %f R %f ener %f\n", q, R, q2); // Printed
  ...
  rtPrintf("q1 %f R %f ener %f\n", q, R, q2); // Crash
  ...
  rtPrintf("q1 %f R %f ener %f\n", q, R, q2);
OUTPUT:
  q0 1.000000 ener 47.894001
  q1 0.960000 R 0.040000 ener 45.978241
  OptiX Error : Invalid value(Details : Function "_rtContextLaunch3D" caught exception : Error in rtPrintf format string : "", [7995426
  ])

NEXT try

  rtPrintf("q0 %f ener %f\n", q1, q2);
  ...
  rtPrintf("q1 %f R %f ener %f\n", q, R, q2);
  ...
  rtPrintf("q1 %f ener %f\n", q, q2);
  rtPrintf("R %f\n", R);
  ...
  rtPrintf("q1 %f ener %f\n", q, q2); // crash
  rtPrintf("R %f\n", R);  // crash
OUTPUT:
  q0 1.000000 ener 47.894001
  q1 0.960000 R 0.040000 ener 45.978241
  q1 0.608620 ener 29.149267
  R 0.633980
  OptiX Error : Invalid value(Details : Function "_rtContextLaunch3D" caught exception : Error in rtPrintf format string : "", [7995426
  ])
    
NEXT try
  rtPrintf("q0 %f ener %f\n", q1, q2);
  ...
  rtPrintf("q1 %f R %f ener %f\n", q, R, q2);
  ...
  rtPrintf("q1 %f ener %f\n", q, q2);
  rtPrintf("R %f\n", R);
  ...
  rtPrintf("q1 %f\n", q);
  rtPrintf("R %f ener %f\n", R, q2); // Passed
OUTPUT:
  q0 1.000000 ener 47.894001
  q1 0.960000 R 0.040000 ener 45.978241
  q1 0.608620 ener 29.149267
  R 0.633980
  q1 0.559405
  R 0.080864 ener 26.792132

All calculations are marked as “…”.
Probably compiler tries to optomize memory.