• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
michaelruecker

Many dispatch calls vs. higher ThreadGroupCount

8 posts in this topic

I wonder if it is performance wise much worse to do more dispatch calls instead of a higher ThreadGroupCount.

 

 

To explain this in a stupid example:

ID3D11DeviceContext::Dispatch(10,1,1);

vs

for(int i = 0; i < 10; i++)
  ID3D11DeviceContext::Dispatch(1,1,1);

Has anyone tested this already or has some theoretical knowledge? 

0

Share this post


Link to post
Share on other sites

My understanding is dispatch(1,1,1) is a bad idea.  I think the most recent directcompute performance advice from both vendors is in this presentation:

 

http://developer.amd.com/wordpress/media/2013/04/DX11PerformanceReloaded.ppsx

 

It's toward the end of the slides.  I believe ideally you want your dispatch threadgroups to be a multiple of 64 to ensure full thread occupancy on the hardware, since the GPUs run threads in groups of 32/64 (ie. their warp size), though the ideal thread group size depends on the numthreads in the actual hlsl compute shader, i would assume.

 

I guess technically dispatch(1,1,1) would be fine if you wanted to process a tiny 16x16 texture with [numthreads(16,16,1)] in your hlsl, since that'd give you a single thread group of 256 threads.  

 

However for processing more realistic data sizes, I think it's a bad idea to manually call multiple dispatches on a single threadgroup rather than call a single dispatch with multiple threadgroups.  Multiple dispatch calls would certainly cause more API overhead, and I would expect the driver/hardware scheduling will handle the single call better also.

 

Perhaps a good analogy would be drawing a 10 triangle object with a single drawindexed(30,0,0) versus looping 10 times with drawindexed(3, i*3, 0), you'd never do the latter.

1

Share this post


Link to post
Share on other sites

Thank you for the reply.

 

Yep I know about the thread group size. But for example if your shader is configured so that you have [numthreads(64, 1, 1)] as thread group size you could dispatch(1,1,1) (one) of that group and still have a full 64 threads running. As far as I know you should always run a multiple of 64.

 

So, if we take my first example again:

ID3D11DeviceContext::Dispatch(10,1,1); // dispatches 10 x 64 threads -> 640
for(int i = 0; i < 10; i++)
  ID3D11DeviceContext::Dispatch(1,1,1); // dispatches 10 x 64 threads -> 640

Lets say I am forced to use the second "solution" for some complicated reason. I wonder how much worse it will be. Or what other disadvantage I would have.

Edited by me_12
0

Share this post


Link to post
Share on other sites

Thank you for the reply.

 

Yep I know about the thread group size. But for example if your shader is configured so that you have [numthreads(64, 1, 1)] as thread group size you could dispatch(1,1,1) (one) of that group and still have a full 64 threads running. As far as I know you should always run a multiple of 64.

 

So, if we take my first example again:

ID3D11DeviceContext::Dispatch(10,1,1); // dispatches 10 x 64 threads -> 640
for(int i = 0; i < 10; i++)
  ID3D11DeviceContext::Dispatch(1,1,1); // dispatches 10 x 64 threads -> 640

Lets say I am forced to use the second "solution" for some complicated reason. I wonder how much worse it will be. Or what other disadvantage I would have.

if you only have one thread group, whatever it's size, you will probably run into issues when the GPU stalls it's execution waiting for mem fetches / whatever. Typically it would then just start working on another warp/wavefront, and get back to the original one once the data was ready and it's current group stalled for some reason.

If you dispatch many groups one by one, there is no guarantee that they will run in parallel and allow the GPU to jump in between. ( In fact, I am pretty sure than on current PC gpus you are guaranteed that they won't ).

1

Share this post


Link to post
Share on other sites

I'm no expert in directcompute, really just starting out with it, but I would think the difference in your example would come down to how the API command queue is handled by the driver.  I mean your hardware probably has more than 64 threads available, but will it share them amongst multiple small dispatches?
 
Assuming each loop is operating on different data and there are no collisions, it could run the multiple dispatches in parallel the same as the single dispatch.  I don't know what level of support GPUs have for concurrently running multiple compute kernels, and that's what it'd come down to.
 
Unless anyone else here is more knowledgeable on how compute command queues are handled once they leave the API, my advice would be to profile it.  You can use http://graphics.stanford.edu/~mdfisher/GPUView.html (part of the SDK now) to check the command queue in the API and see how the driver/gpu schedules your calls to see if the looped version runs in series or parallel.   You could also grab a vendor profiling tool like nsight for nvidia or perfstudio for amd to check that also, and get some feedback on the thread occupancy as well.

Edit: Just noticed ATEfred's reply and he put it more succintly, you're asking the GPU to run multiple dispatches concurrently and it sounds like that isn't supported.

Edited by backstep
1

Share this post


Link to post
Share on other sites

Ah thank you for that tip with GPUView. Before I try getting this to work maybe ATEFred knows the answer about the question if they run in parallel or series.

 

Because actually I would need them to run in series. I am doing something like this:

for(int i = 0; i < x; i++) {
  // 1. update a small constant buffer which holds data for the upcoming particle spawns processed in the dispatch call
  // 2. Dispatch(1,1,1);
}

So if this constant buffer gets overwritten by the second loop while the first dispatch is not done it would access wrong data. :/

 

 

 

I could also do it like this:

// 1. bind 250kb data to hold the full spawn over time graph processed in this dispatch call
// 2. Dispatch(x,1,1);

The thing is, that the x is variable. Its random based on time passed. It can be 1 or it can be 30000. But mostly, like 99% of the time it will be 1.

 

Thats why I thought it might be better to just pass the data actually needed in small junks and process only that bit. And if it happens that I actually need more than 1 pass, I would just use a loop.

 

Maybe there is even another solution i haven't noticed yet.

 

If it was only possible to allocate memory dynamically... but no I have to allocate as much memory as is needed in the worst case.

Edited by me_12
0

Share this post


Link to post
Share on other sites

If you've called dispatch before mapping the constant buffer, then I believe it won't get overwritten.  Depending on the type of constant buffer (usage and cpu access) and how you're mapping it, it will either stall the pipeline or use an alias of the buffer for the map/unmap.  That's to say, it'll either wait to update the buffer until it's not in use, or if you're mapping with discard it'll just update to an alias of it without making your context cpu thread wait.  That's my understanding at least.

 

So I don't think you need to worry about serial vs parallel execution of your dispatches causing errors.  I think the main problem is you'll be underutilzing the GPU constantly, since only 64 threads will be active at once (out of hundreds available).  Another possible issue could be constant waterfalling, which occurs if each thread is accessing a unique value from the constant buffer, which makes each thread block the others while it accesses it's value from the constant buffer.  From your example of dispatch(10, 1, 1) with numthreads(64, 1, 1) requiring a 100KB constant buffer, it sounds like each thread accesses a different part in the constant buffer.  So that would mean at the point in your shader where you access the thread-unique constant buffer values your utilization would drop to a single thread out of hundreds.

 

I am still a beginner like you, but a better approach might be to use a SRV of a structured buffer instead of a constant buffer.  That would allow you to update with a single map (write_discard to prevent a stall), then use a single dispatch with multiple threadgroups when required, and also avoid constant waterfalling performance problems.

 

Oh also if you don't need to update the whole 100KB every frame, you could simply make two structured buffers - a smaller one for typical use cases, and a 100KB one for your worst case scenario.  Then simply map/update/unmap/bind whichever one's SRV is required for that frame.  It's not quite dynamic allocation but it'd allow you the benefit of the smaller buffer 99% of the time.

 

Also from what I can tell from a quick google, directcompute does only support a single dispatch being processed on the GPU at once (slide 43 in http://www.slideshare.net/NVIDIA/1015-gtc09-5013444 ).  CUDA appears to have some kernel concurrency support, but that's something else entirely.

Edited by backstep
1

Share this post


Link to post
Share on other sites

Thank you guys!

 

Oh also if you don't need to update the whole 100KB every frame, you could simply make two structured buffers - a smaller one for typical use cases, and a 100KB one for your worst case scenario.  Then simply map/update/unmap/bind whichever one's SRV is required for that frame.  It's not quite dynamic allocation but it'd allow you the benefit of the smaller buffer 99% of the time.

 

This is kind of what I am doing now.

 

I have a very small buffer and one overflow buffer. 99% of the time the small one will be used. Only if the system lags or if I have more data to process, the overflow buffer will be used as well. And in some very extrem situation or when doing a prewarm I run the overflow buffer in a loop.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0