13 Replies Latest reply on May 14, 2009 10:07 AM by gaurav.garg

    Error in Kernel Code

    dabrunhosa
      Beginner Errors

      Hi, I'm a beginner to the Brook+ development and I can't understand what is wrong with the code that follows:

      kernel void calcular_integral(float input<>,float xo_g,float xf_g,float h,float num_processos,out float output<>
      {
          float tam;
          float xo_l;
          float xf_l;
          float soma;
          float nx;
          float x;
          float i;
          tam = ((xf_g - xo_g)/num_processos);
          xo_l = tam * input;
          xf_l = (tam * input)+ tam;
          nx = (xf_l - xo_l) / h;
          soma = (xo_l * xo_l) + (xf_l * xf_l);
          i = 1.0f;
         
          for(; i < nx; i++)
          {
              x = (xo_l + (h * i));
              soma += 2.0f *(x*x);
          }
          output = soma * (h/2.0f);
      }

       

      Please Help me. If you need more information than the code above, please tell me. The rest of my code executes perfectly, but when begins to execute the kernel code the following error occur :

      Stream Write : Stream can't write to a NULL pointer.

      I appreciate any help you can give me.

        • Error in Kernel Code
          gaurav.garg

          It seems the problem is not with your kernel code, but the host code. It is clear from the error that the pointer passed to streamWrite operator is NULL.

          Could you post your host side code?

            • Error in Kernel Code
              dabrunhosa

              The host code is:

              void Integral:reencherStream()
              {
                  _input = (float*) malloc(sizeof(float));
                  for(int i = 0; i< _length; i++)
                  {
                      _input = (float)(i+1);
                  }
              }
              ////////////////////////////////////////////////////////////////////////////////
              //!
              //! \brief  backend implementation for the sample
              //!
              ////////////////////////////////////////////////////////////////////////////////

              bool Integral::run()
              {
                  unsigned int retVal = 0;
                  const float h = 0.00000001f;
                  const float xo_g = 0.0f;
                  const float xo_f = 4.0f;
                 
                  /////////////////////////////////////////////////////////////////////////
                  // Brook code block
                  /////////////////////////////////////////////////////////////////////////
                  {
                      unsigned int dim[] = {1};
                      ::brook::Stream<float> inputStream(1, dim);
                      ::brook::Stream<float> outputStream(1, dim);
                      unsigned int redDim[] = {1};
                      ::brook::Stream<float> res(1, redDim);
                      PreencherStream();
                      inputStream.read(_input);
                      calcular_integral(inputStream,xo_g,xo_f,h (float)_length,outputStream);
                      outputStream.write(_output);
                     
                      // Handle errors if any
                      if(outputStream.error())
                      {
                          std::cout << "Error occured" << std::endl;
                          std::cout << outputStream.errorLog() << std::endl;
                          retVal = -1;
                      }
                                    
                      streamWrite(res, &_result);
                           
                      // Handle errors if any
                      if(res.error())
                      {
                          std::cout << "Error occured" << std::endl;
                          std::cout << res.errorLog() << std::endl;
                          retVal = -1;
                      }
                  }

                  /////////////////////////////////////////////////////////////////////////
                  // Print results
                  /////////////////////////////////////////////////////////////////////////
                     
                  return true;
              }

               

              If you need any more information tell me. I'm appreciate the help you already gave to me.

                • Error in Kernel Code
                  gaurav.garg

                  Check the value of _output. It seems you have not allocated memory for it.

                    • Error in Kernel Code
                      dabrunhosa

                      I did what you said, the new code is:

                      void Integral:reencherStream()
                      {
                          _input = (float*) malloc(sizeof(float));
                          _output = (float*) malloc(sizeof(float));
                          for(int i = 0; i< _length; i++)
                          {
                              _input = (float)(i+1);
                          }
                      }

                      But now the error is :

                      Stream Write : Unintialized stream.

                      I saw the examples that came with the Stream SDK and i think that my code is similar. What else could be missing ?

                        • Error in Kernel Code
                          gaurav.garg

                          Where are you getting this error outputStream.errorLog() or res.errorLog()?

                          As you can see res is not an initialized stream (neither called streamRead nor its an output to kernel), hence you see this error.

                            • Error in Kernel Code
                              dabrunhosa

                              I get the error in the res.errorLog, you are right that part i was not using it.

                              The new code is this :

                              bool Integral::run()
                              {
                                  unsigned int retVal = 0;
                                  const float h = 0.00000001f;
                                  const float xo_g = 0.0f;
                                  const float xo_f = 4.0f;
                                 
                                  /////////////////////////////////////////////////////////////////////////
                                  // Brook code block
                                  /////////////////////////////////////////////////////////////////////////
                                  {
                                      unsigned int dim[] = {1};
                                      ::brook::Stream<float> inputStream(1, dim);
                                      ::brook::Stream<float> outputStream(1, dim);

                                      PreencherStream();
                                      inputStream.read(_input);
                                      calcular_integral(inputStream,xo_g,xo_f,h,(float)_length,outputStream);
                                      outputStream.write(_output);
                                     
                                      // Handle errors if any
                                      if(outputStream.error())
                                      {
                                          std::cout << "Error occured" << std::endl;
                                          std::cout << outputStream.errorLog() << std::endl;
                                          retVal = -1;
                                      }
                                  }

                                  /////////////////////////////////////////////////////////////////////////
                                  // Print results
                                  /////////////////////////////////////////////////////////////////////////
                                     
                                  return true;
                              }

                               

                              The problem is that the error above was always present in the execution of my code:

                              "VPU Recover has reset your graphic accelerator as it was no longer responding to graphics driver commands"

                              My graphic card is the Ati HD 4830 with 512 Mb of Memory.

                              It has to be something wrong if my kernel code, right ? I don't know what to think.

                              Do you need more information ?

                              Thanks for your help so far.