-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #752 from CHIP-SPV/WaitForPerThread
Refactor WaitForThreadExit
- Loading branch information
Showing
6 changed files
with
105 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <iostream> | ||
#include <thread> | ||
#include "hip/hip_runtime.h" | ||
|
||
static constexpr int numThreads = 1000; | ||
|
||
void threadFunction(int threadId) { | ||
int src = threadId; // Source data unique to each thread | ||
int dst; | ||
|
||
// Use hipStreamPerThread to get a per-thread default stream | ||
hipMemcpyAsync(&dst, &src, sizeof(int), hipMemcpyHostToHost, | ||
hipStreamPerThread); | ||
// std::cout << "Thread " << threadId << " completed memcpy." << std::endl; | ||
} | ||
|
||
int main() { | ||
std::thread threads[numThreads]; | ||
|
||
for (int i = 0; i < numThreads; ++i) { | ||
threads[i] = std::thread(threadFunction, i); | ||
} | ||
|
||
// Main thread exits without waiting for the threads to finish | ||
std::cout << "Main thread exiting." << std::endl; | ||
|
||
// Threads are detached, allowing them to continue independently | ||
for (int i = 0; i < numThreads; ++i) { | ||
threads[i].detach(); | ||
} | ||
|
||
return 0; | ||
} |