1 Reply Latest reply on Oct 15, 2009 7:57 AM by AIF Bob

    CPU vs GPU bug

    Denis N

      Hi there. So, here's the kernel I've tryed to run on both CPU & GPU in PixelBender Toolkit:

       

       

      <languageVersion : 1.0;>
      
      kernel VectorTransform
      <   namespace : "QuickMathShaders";
          vendor : "GloomyBrain";
          version : 1;
          description : "your description";
      >
      
      {
      input image3 src;
      output pixel4 dst;
      
      parameter float4x4 matrix
      <
      minValue : float4x4(
                          -1000000.0, -1000000.0, -1000000.0, -1000000.0,
                          -1000000.0, -1000000.0, -1000000.0, -1000000.0,
                          -1000000.0, -1000000.0, -1000000.0, -1000000.0,
                          -1000000.0, -1000000.0, -1000000.0, -1000000.0
                          );
      maxValue : float4x4(
                          1000000.0, 1000000.0, 1000000.0, 1000000.0,
                          1000000.0, 1000000.0, 1000000.0, 1000000.0,
                          1000000.0, 1000000.0, 1000000.0, 1000000.0,
                          1000000.0, 1000000.0, 1000000.0, 1000000.0
                          );
      defaultValue : float4x4(
                              0.0, 0.0, 0.0, 0.0,
                              0.0, 0.0, 0.0, 0.0,
                              0.0, 0.0, 0.0, 0.0,
                              0.0, 0.0, 0.0, 0.0
                              );
      description : "";
      >;
      
          void evaluatePixel()
          {
              float3 currentVector = sampleNearest(src, outCoord());
              float4 preResult = matrix*float4(currentVector[0], currentVector[1], currentVector[2], 0.0);
              dst = float4(preResult[0], preResult[1], preResult[2], 1.0/preResult[2]);
      
          }
      }
      

       

      And the problem is that when I loaded YellowFlowers.png (standart image) as Image1 and ran the filter with GPU - there's no problem, it works nice
      BUT
      Then I ran it with CPU - and I've got a runtime error, wich is division by zero ( and there SHOULD be such an error in GPU-mode)
      So the question is - how would it work in FlashPlayer ????
        • 1. Re: CPU vs GPU bug
          AIF Bob Level 3

          Division by zero is undefined which means that the GPU version is correct, and the CPU version is correct, and whatever Flash does is also correct, and they don't necessarily have to match.

           

          If you need specific behaviour when preResult[2] is zero, you need to check for it and do whatever is correct for your algorithm. Something like this:

           

          if( abs( preResult[2] < 0.001 ) )

          {

              // Handle division by zero case

          }

          else

          {

              dst = float4(preResult[0], preResult[1], preResult[2], 1.0/preResult[2]);

          }