cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

fandango
Journeyman III

Kernel function problem

Hi,

I have faced with small problem. My kernel function does not work correctly and return partly right result. This is function is very simple and I believe it is not my mistake. Could you please look at my example? What's wrong?

kernel void func1(unsigned char src[][],  unsigned char str, out unsigned char o_img<>
{
    // Output position
    int j = instance().x; // width
    int i = instance().y; // height
   
    int rest = j % 16;
   
    if (rest == 0)
    {
        o_img = src [ i] ;
    }
    else
    {
        o_img = str;
    }
}

 

Input:

3   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   3   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   3   1   1   1   1   1   1   1   1

I just replace 1 by 9.

Wrong output:

  3      9   9   9   9   9   9   9   9   9   9   9   9   9   9   3      9   9   9   9   9   9   9   9   9   9   9   9   9   9   3      9   9   9   9   9   9   9

You can see garbage in memory. If I remove if statement from the kernel , the output will be without garbage. But I need the first way.

 

 

0 Likes
74 Replies
gaurav_garg
Adept I

Kernel function problem

I could not reproduce this issue on my system. Could you send me your system configuration?

0 Likes
fandango
Journeyman III

Kernel function problem

Yes,

ATI Radeon 4800 HD, driver 8.600.0.0

Intel Core 2 6300 1.86 GHz, 1 Gb DDR2

 

0 Likes
fandango
Journeyman III

Kernel function problem

Chunk of code just in case:


 // Specifying the size of the 2D stream
    unsigned int streamSize[] = {width, height};

    // Specifying the rank of the stream
    unsigned int rank = 2;
   
    brook::Stream<unsigned char> inputStream(rank, streamSize);

    // Copying data from input buffer to input stream
    inputStream.read(src);

    //--------------------------------------------------------------------------
    // Creating the output stream
    //--------------------------------------------------------------------------    
    streamSize[0] = width;
    streamSize[1] = height;

    brook::Stream<unsigned char> outputStream(rank, streamSize);

    //--------------------------------------------------------------------------
    // Executing kernel and copying back data
    //--------------------------------------------------------------------------    
    unsigned char str = '9';
    
    // Calling the kernel on the input and output streams
    func1(inputStream, str, outputStream);

    // Creating an output buffer
    unsigned char* ref = new unsigned char[width * height];
    memset(ref, 0, width * height);


    // Copying data from output stream to output buffer
    outputStream.write(ref);

0 Likes
fandango
Journeyman III

Kernel function problem

Any ideas?

0 Likes
anlongstar
Journeyman III

Kernel function problem

no idea, because some mistakes is too strange.

0 Likes
fandango
Journeyman III

Kernel function problem

ok. i will try to reinstall driver or stream sdk.

0 Likes
gaurav_garg
Adept I

Kernel function problem

I am also using 8.60 driver, but I don't see the issue.

What is your OS and what are the value for width & height?

0 Likes
fandango
Journeyman III

Kernel function problem

I have tried the Windows Xp 32 and Windows Vista 64 SP1. The same result. The latest stream sdk and driver.

I have tried the different w&h. Full code:

#include <iostream>

#include "brook/Stream.h"
#include "brook/KernelInterface.h"
#include "brookgenfiles/kernel.h"


void print(unsigned char* arr, int width, int height)
{
    for (int i = 0; i < height; i++)
    {
        for(int j = 0; j < width; j++)
        {
            char cStr[256];
            sprintf(cStr, "% 3c ", arr[j + i * width]);
            OutputDebugString(cStr);
        }

        OutputDebugString("\n");
    }
}

int
main(int argc, char* argv[])
{
// Specifying the width and height of the 2D buffer
    const unsigned int width = 49;
    const unsigned int height = 6;

    //--------------------------------------------------------------------------
    // Creating and initializing the input buffer
    //--------------------------------------------------------------------------

    // Creating an input buffer
    unsigned char* src = new unsigned char[width * height];
    //memset(src, 7, width * height);

    for (int i = 0; i < height; i++)
    {
        for(int j = 0; j < width; j++)
        {
            if (j % 16 == 0)
            {
                src[j + i * width] = '3';
            }
            else
            {
                src[j + i * width] = '1';
            }
        }

        OutputDebugString("\n");
    }

     print(src, width, height);

    // Initializing the input buffer such that
    // input(i,j) = i*width + j
//    fillBuffer(inputBuffer, width, height);

    // Printing input buffer
    fprintf(stdout, "Input buffer:\n");

    //--------------------------------------------------------------------------
    // Creating the input stream and copying data from input buffer
    //--------------------------------------------------------------------------

    // Specifying the size of the 2D stream
    unsigned int streamSize[] = {width, height};

    // Specifying the rank of the stream
    unsigned int rank = 2;

    // Create a 2D stream of specified size i.e. 64x64 floating-point values   
    brook::Stream<unsigned char> inputStream(rank, streamSize);

    // Copying data from input buffer to input stream
    inputStream.read(src);

    //--------------------------------------------------------------------------
    // Creating the output stream
    //--------------------------------------------------------------------------   
    streamSize[0] = width;
    streamSize[1] = height;

    brook::Stream<unsigned char> outputStream(rank, streamSize);

    //--------------------------------------------------------------------------
    // Executing kernel and copying back data
    //--------------------------------------------------------------------------   
    unsigned char str = '9';
   
    // Calling the kernel on the input and output streams
    func1(inputStream, str, outputStream);

    // Creating an output buffer
    unsigned char* ref = new unsigned char[width * height];
    memset(ref, 0, width * height);
    //memset(ref, 0, width * height * sizeof(just));

    //print(ref, width, height);

    // Copying data from output stream to output buffer
    outputStream.write(ref);

    print(ref, width, height);

    // Check error on stream
    if(outputStream.error())
    {
        // Print error Log associated to stream
        fprintf(stdout, "%s\n", outputStream.errorLog());
    }

    fprintf(stdout, "Output buffer:\n");
//    printBuffer(outputBuffer, width, 0, 0, 8, 8);

    //--------------------------------------------------------------------------
    // Checking whether the result is correct or not
    //--------------------------------------------------------------------------
   

    //--------------------------------------------------------------------------
    // Cleaning up
    //--------------------------------------------------------------------------
   
    delete[] src;
    delete[] ref;
   
    return 0;
}

0 Likes
fandango
Journeyman III

Kernel function problem

I just have noticed one thing. Depence on width and height of streamSize for output brook stream I have the different results. I mean the different garbage location.

I suppose something wrong in my kernel function

0 Likes