# Concurrency about default stream

**URL:** <https://forums.developer.nvidia.com/t/concurrency-about-default-stream/37295>\
**Category:** CUDA Programming and Performance\
**Created:** [March 22, 2015, 7:12am UTC](https://forums.developer.nvidia.com/t/concurrency-about-default-stream/37295 "2015-03-22T07:12:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruanjm](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/ruanjm/32/12500_2.png) [@ruanjm](https://forums.developer.nvidia.com/u/ruanjm)\
**Post date:** [March 22, 2015, 7:12am UTC](https://forums.developer.nvidia.com/t/concurrency-about-default-stream/37295/1 "2015-03-22T07:12:09Z")

</div>

I’ve read the article written by Mark Harris about CUDA 7 Streams Simplify Concurrency and it is really useful to me. So I want to run the sample in the article to see the real performance. My device is GTX970 and I use visual studio 2013 to compile and test the sample.But I’m disappointed to find that the concurrency have not happened.  
I’ve added --default-stream per-thread in “CUDA C/C++ → Command Line” but there was nothing changed.  
I’ve also #define the CUDA\_API\_PER\_THREAD\_DEFAULT\_STREAM in “CUDA C/C++ → Host → Preprocessor Definitions” and write the macro on the first line of the source code but there is still nothing changed.  
Finally, I replaced cudaStreamCreate function with cudaStreamCreateWithFlags and use cudaStreamNonBlocking as the second parameter， but there was no concurrency at all!

Does anyone know the way to solve this problem?

---

<div class="post-metadata">

**Author:** ![ruanjm](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/ruanjm/32/12500_2.png) [@ruanjm](https://forums.developer.nvidia.com/u/ruanjm)\
**Post date:** [March 22, 2015, 7:46am UTC](https://forums.developer.nvidia.com/t/concurrency-about-default-stream/37295/2 "2015-03-22T07:46:14Z")

</div>

I got it. cudaStreamCreate and cudaMalloc should not be written in the kernel launch loop because these functions need synchronization.

---

<div class="post-metadata">

**Author:** ![MutantJohn](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@MutantJohn](https://forums.developer.nvidia.com/u/MutantJohn)\
**Post date:** [March 22, 2015, 3:41pm UTC](https://forums.developer.nvidia.com/t/concurrency-about-default-stream/37295/3 "2015-03-22T15:41:53Z")

</div>

cudaFree() is also a synchronous function. That being said, I didn’t modify any of the source code and I still got overlapping execution. But doing it your way, I got significantly improved overlapped execution.

---

<div class="post-metadata">

**Author:** ![ruanjm](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/ruanjm/32/12500_2.png) [@ruanjm](https://forums.developer.nvidia.com/u/ruanjm)\
**Post date:** [March 23, 2015, 2:02am UTC](https://forums.developer.nvidia.com/t/concurrency-about-default-stream/37295/4 "2015-03-23T02:02:32Z")

</div>

Thanks for your advice. I guess that something is different in the optimization of compiler.
