cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

thesquiff
Journeyman III

Problem with Reduction

I've got a very simple reduction kernel which sums up all the elements in a stream.

The kernel will run once, but then crashes the next time with an access violation.

With the truncated code below, the kernel should always return 0.

Any ideas?

 

reduce void getMatchLength(float matchesIn<>, reduce float length) {
    length += matchesIn;
}

int gpuprocess()
{
 
    float matches<256>;
    float matchPattern[256];

    while (index < 32000) {
   
        matchLength = 0.0;
        printf("calling getMatchLength\n");

 

        streamRead(matches, matchPattern);

        getMatchLength(matches, matchLength);


        printf("Match length = %f\n", matchLength);
        index++;
        printf("Looping... index=%d\n", index);
       
    }

}

0 Likes
12 Replies
gaurav_garg
Adept I

After fixing some compilation issues, it seems to be running fine on my system for complete iteration.

Which SDK version are you using?

0 Likes

The problem was on 1.2.1-beta. Have now upgraded to 1.3 and all seems fine. Thanks.

0 Likes

*deleted* spotted my mistake as soon as I posted

0 Likes

You didn't make the function a reduce function? When I did this it fixed your problem, as you probably already know.
0 Likes

yes, that was it, although I thought marking the kernel with reduce wasn't necessary

0 Likes

And another... Have checked against all my previous mistakes and no stream errors. Have also tried assigning x and y components separately.

No matter what the inputs are, result.x=108 and result.y=101!

reduce void bestMatch(int2 inputs<>, reduce int2 result) {
    if (inputs.x > result.x) {
        result = inputs;
    }
}

0 Likes

Can you post your runtime side of code?

0 Likes

thesquiff, your code compiles fine. Are you noticing runtime problems or incorrect results?
0 Likes

OK, I've tested the kernel on a small hand written dataset and the kernel seems to work fine there, however back in my program it gives consistently incorrect results regardless of the input data.

domainSize.x = 50; //all other components set to 1

domainOffset.x = 3; //all other components set to 0

               //we run a string match routine
                stringMatch.domainSize(domainSize);
                stringMatch.domainOffset(domainOffset);
                stringMatch(textStream, nextPosition, hashTableStream, hashIndex, matches);

//all outputted data in matches is manually verified to be correct
                matches.write(matchesArray);
                for (count = 3; count < hashTable[hashIndex*500+2]+3; count++) {
                    printf("Match length %d at position %d (should be %d)\n", matchesArray[count].x, matchesArray[count].y, hashTable[hashIndex*500+count]);
                }
                printf("%s\n",matches.errorLog());
                result.x = 0;
                result.y = 0;
                printf("Domain size %d\n", domainSize.x);
                bestMatch.domainOffset(domainOffset);
                bestMatch.domainSize(domainSize);
                bestMatch(matches, result);

result in result is then always x=108, y = 101 regardless of what data is in matches.

0 Likes

bestMatch.domainOffset(domainOffset);                 bestMatch.domainSize(domainSize);                 bestMatch(matches, result);

 

result in result is then always x=108, y = 101 regardless of what data is in matches.



Specified domain on bestMatch is wrong as output stream size is 1X1. Currently, reduction implementation ignores domain specified, so result will contain the maximum value of the complete stream (not just the domain part of it).

As I can see you are not probably initializing all the input stream elements (count < 3 & count >= 53), hence result might have random numbers.

Initialize complete input stream and see if you get the correct results.

0 Likes

Thanks for your reply. Is there any other way of restricting the input domain? I tried this but it hangs the compiler...

 

reduce void bestMatch(int2 inputs<>, int maxindex, reduce int2 result) {
    int idx = instance().x;
    if ((idx < maxindex) & (inputs.x > result.x)) {
        result = inputs;
    }
}

0 Likes

Calling instance() or indexof() in reduction kernel is invalid.

You can use domain operator on input stream-

bestMatch(matches.domain(domainOffset, domainOffset+domainSize), result);

0 Likes