Skip to content

Any tutorial about avoiding GPU data starvation ? #729

Closed

Description

@minhduc66532

So basically i want to use multithreads to feed my model to prevent data starvation. But there isn't any tutorial i found that is easy to understand and follow. Any ideas ?

Activity

  1. Oceania2018 commented on Jan 21, 2021

    @Oceania2018
    Member

    There is a memory leak issue in Keras implementation. #727

  2. minhduc66532 commented on Jan 22, 2021

    @minhduc66532
    Author

    First i do not use Keras.NET. Second i think u misunderstood my question. So currently i'm running my model with session.run() but it's slow and my GPU is having some weird usage spike #719 . After googling around i found out that my GPU is starving of data aka the CPU is too slow preparing data to push it into the GPU.

    Example, the entire process from preparing data to invoke session.run() to preparing result take 120ms.
    Preparing data need 60ms, session.run() need 30ms, preparing result need 30ms

    The entire thing run on 1 thread 60 + 30 + 30 = 120ms. So after the session.run() done processing the GPU need entire 90ms = 30ms (preparing result step) + 60ms (preparing data step) for new data to process (data starvation). So the idea is to create 4 threads, 2 threads for data preparing step (step 1), 1 thread invoke session.run() (step 2), 1 thread for preparing step (step 3).

    So the pipeline will change as follow. Step 1 pump out 2 new piece of data after 60ms. Step 2 somehow get the data from step 2 and after 30ms step 2 pump out 1 piece of result, step 2 get the other data and process it (AND step 1 is half way done). Step 3 get the result and process it 30ms (step 1 is done and step 2 ALSO done), step 3 get the new result from step 2 and step 2 get 2 new data from step 1. And the loop continue, so with thread the entire process is 4 times FASTER from 120ms to 30ms.

    And this is the result i want to achieve, any ideas (concurrent queue) ?

  3. Oceania2018 commented on Jan 22, 2021

    @Oceania2018
    Member

    Check if the Queue help

    // create a first in first out queue with capacity up to 2

  4. minhduc66532 commented on Jan 22, 2021

    @minhduc66532
    Author

    // init queue, push 3 elements into queue.

    You mean "push 2 elements" ? Anyway thanks for the suggestion, i will report back result soon enough (hopefully)

  5. Oceania2018 commented on Feb 7, 2021

    @Oceania2018
    Member

    Please try latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions