3 Replies Latest reply on Oct 15, 2012 1:00 PM by Zac Lam

    Is the Memory Suite thread safe?

    Rallymax-forum Level 3

      Hi all,

       

      Is the memory suite thread safe (at least when used from the Exporter context)?

       

      I ask because I have many threads getting and freeing memory and I've found that I get back null sometimes. This, I suspect, is the problem that's all the talk in the user forum with CS6 crashing with CUDA enabled. I'm starting to suspect that there is a memory management problem when there is also a lot of memory allocation and freeing going on by the CUDA driver. It seems that the faster the nVidia card the more likely it is to crash. That would suggest the CUDA driver (ie the code that manages the scheduling of the CUDA kernels) is in some way coupled to the memory use by Adobe or by Windows alloc|free too.

       

      I replaced the memory functions with _aligned_malloc|free and it seems far more reliable. Maybe it's because the OS malloc|free are thread safe or maybe it's because it's pulling from a different pool of memory (vs the Memory Suite's pool or the CUDA pool)

       

      comments?

       

      Edward

        • 1. Re: Is the Memory Suite thread safe?
          Zac Lam Adobe Employee

          The Memory Suite does pull from a specific memory pool that is set based on the user-specified Memory settings in the Preferences.  If you use standard OS calls, then you could end up allocating memory beyond the user-specified settings, whereas using the Memory Suite will help you stick to the Memory settings in the Preferences.

           

          When you get back NULL when allocating memory, are you hitting the upper boundaries of your memory usage?  Are you getting any error code returned from the function calls themselves?

          1 person found this helpful
          • 2. Re: Is the Memory Suite thread safe?
            Rallymax-forum Level 3

            Zac Lam wrote:

             

            The Memory Suite does pull from a specific memory pool that is set based on the user-specified Memory settings in the Preferences.  If you use standard OS calls, then you could end up allocating memory beyond the user-specified settings, whereas using the Memory Suite will help you stick to the Memory settings in the Preferences.

             

            When you get back NULL when allocating memory, are you hitting the upper boundaries of your memory usage?  Are you getting any error code returned from the function calls themselves?

            I am not hitting the upper memory bounds - I have several customers that have 10's of Gb free.

             

            There is no error return code from the ->NewPtr() call.

                 PrMemoryPtr (*NewPtr)(csSDK_uint32 byteCount);

             

             

            A NULL pointer is how you detect a problem.

             

            Note that changing the size of the ->ReserveMemory() doesn't seem to make any difference as to whether you'll get a memory ptr or NULL back.

             

            btw my NewPtr size is either

                 W x H x sizeof(PrPixelFormat_YUVA4444_32f)

                 W x H x sizeof(PrPixelFormat_YUVA4444_8u)

            and happens concurrently on #cpu's threads (eg 16 to 32 instances at once is pretty common).

             

            The more processing power that the nVidia card has seems to make it fall over faster.

            eg I don't see it at all on a GTS 250 but do on a GTX 480, Quadro 4000 & 5000 and GTX 660

             

            I think there is a threading issue and an issue with the Memory Suite's pool and how it interacts with the CUDA memory pool. - note that CUDA sets RESERVED (aka locked) memory which can easily cause a fragmenting problem if you're not using the OS memory handler.

            • 3. Re: Is the Memory Suite thread safe?
              Zac Lam Adobe Employee

              Thanks for the extra info.  Let me check on this with the team and get back to you.