12 Replies Latest reply on Feb 3, 2009 8:25 AM by gaurav.garg

    Problem with Reduction

    thesquiff

      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);
             
          }

      }

        • Problem with Reduction
          gaurav.garg

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

          Which SDK version are you using?

            • Problem with Reduction
              thesquiff

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

                • Problem with Reduction
                  thesquiff

                  *deleted* spotted my mistake as soon as I posted

                    • Problem with Reduction
                      ryta1203
                      You didn't make the function a reduce function? When I did this it fixed your problem, as you probably already know.
                        • Problem with Reduction
                          thesquiff

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

                            • Problem with Reduction
                              thesquiff

                              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;
                                  }
                              }

                                • Problem with Reduction
                                  gaurav.garg

                                  Can you post your runtime side of code?

                                  • Problem with Reduction
                                    ryta1203
                                    thesquiff, your code compiles fine. Are you noticing runtime problems or incorrect results?
                                      • Problem with Reduction
                                        thesquiff

                                        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.

                                          • Problem with Reduction
                                            gaurav.garg

                                             

                                            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.

                                              • Problem with Reduction
                                                thesquiff

                                                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;
                                                    }
                                                }