5 Replies Latest reply on Oct 10, 2008 11:50 PM by udeepta@amd

    Seg-fault on second run

    the729

      Hi, all

      #include <stdio.h>

      kernel void increase(float a<>, out float c<>
      {
          c = a+1;
      }

      int main(int argc, char** argv)
      {
        int i, j;
        float input_a[4] = {1, 2, 3, 4};
        float c<4>;

        for(i=0; i<2; i++) {
          float a<4>;
          streamRead(a, input_a);
          increase(a, c);
          streamWrite(c, input_a);
        }

        return 0;
      }

      This piece of code lead to a segment fault on my system. It is OK on the first iteration, but crashes at __k->Map() on the second iteration.
      However, everything is fine if I move the declaration of stream a<> outside of the loop, like this:
        .....
        float c<4>;
        float a<4>;

        for(i=0; i<2; i++) {
          ......
        }

      I'm not sure if it is related to this thread:
      http://forums.amd.com/devforum/messageview.cfm?catid=328&threadid=101244&enterthread=y

        • Seg-fault on second run
          jean-claude

          Not sure but I tend to think that you already found the reason:

          Having a stream declaration inside a loop simply create an stream object

          any time the instruction is encountered (see generated code).

          So get your stream float a<4> outside of the loop....

            • Seg-fault on second run
              the729

              For this particular case, putting the declaration outside will indeed solve the problem.

              However, this means functions doing GPU works cannot be called more then once. For instance, this also breaks:

              int main()
              {
                ....
                for(...) {
                  process_data(....);
                }
                ....
              }

              void process_data(i, o)
              {
                float i_stream<...>;
                float o_stream<...>;
                doing GPU computation
              }

                • Seg-fault on second run
                  jean-claude

                  I think this is related to a weakness already identified and brought to

                  the attention of ATI: there should be an explicit statement to dispose (free) stream objects. At least one would know and understand what is going on !

                   

                    • Seg-fault on second run
                      jean-claude

                      In this case why don't you use your approach as you described in:

                      http://forums.amd.com/devforum/messageview.cfm?catid=328&threadid=100999&enterthread=y

                      and add the statements

                      i_stream.~stream();

                      o_stream.~stream();

                      at the end of process data(i,o)

                       

                      or better: get your stream declarations

                       ::brook::stream i_stream(::brook::getStreamType(( float  *)0), wx,wy,-1);

                       ::brook::stream o_stream(::brook::getStreamType(( float  *)0), wx,wy,-1);

                       

                      out of the loop

                       

                      • Seg-fault on second run
                        udeepta@amd

                        Agreed. As I wrote in another response:

                        Currently, streams have auto-pointer behavior -- they are de-allocated when they go out of memory. We are working towards adding dynamic allocation behavior in the next release.

                         

                        float a<height,width>;

                        {

                         

                        float b<height,width>; // intermediate working stream





                        streamread(a,...)

                        process(a,b,..)

                        } //b goes out of scope

                        streamwrite(a,...)

                         

                         

                        Originally posted by: jean-claude I think this is related to a weakness already identified and brought to

                         

                        the attention of ATI: there should be an explicit statement to dispose (free) stream objects. At least one would know and understand what is going on !