cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

dabrunhosa
Journeyman III

Error in Kernel Code

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.

0 Likes
13 Replies
gaurav_garg
Adept I

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?

0 Likes

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.

0 Likes

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

0 Likes

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 ?

0 Likes

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.

0 Likes

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.

 

0 Likes

Stream application require VPU recover to be disabled using Catalyst Control center on Windows system. Look at CAL FAQs point 1 under $(CALROOT)\CAL_Documentation

0 Likes

I read the document that you asked. But the ati2dvag still didn't respond. I think that my problem is simply a infinity loop in the Kernel Code. I will look in to that and if this do not work I will come back and tell you.

Thanks for your help so far.

0 Likes

Run with CPU backend to see if there is infinite loop in kernel. Set environment variable BRT_RUNTIME=cpu and run your application to use CPU runtime.

0 Likes

I'm using Visual Studio 2005, how can i do this ?

0 Likes

It has nothing to do with Visual Studio, you need to set the environment variable in your system. Also, make sure you close command prompt or visual studio application after setting env variable and then open it again.

0 Likes

Where can i find this environment variable ? In the documet from ATI it does not say.

0 Likes

Stream computing user guide : Section 2.1, 2.2.4

0 Likes