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);
}
}
After fixing some compilation issues, it seems to be running fine on my system for complete iteration.
Which SDK version are you using?
The problem was on 1.2.1-beta. Have now upgraded to 1.3 and all seems fine. Thanks.
*deleted* spotted my mistake as soon as I posted
yes, that was it, although I thought marking the kernel with reduce wasn't necessary
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;
}
}
Can you post your runtime side of code?
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.
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.
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;
}
}
Calling instance() or indexof() in reduction kernel is invalid.
You can use domain operator on input stream-
bestMatch(matches.domain(domainOffset, domainOffset+domainSize), result);