Created
December 24, 2025 04:17
-
-
Save youkaichao/e40b1c59c19e2d59463c1b0d6a8bf44a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include <cuda_runtime.h> | |
| #include <cstdio> | |
| #include <cstdlib> | |
| #include <unordered_set> | |
| #include <vector> | |
| #include <cstdint> | |
| static void check(cudaError_t e, const char* msg) { | |
| if (e != cudaSuccess) { | |
| std::fprintf(stderr, "CUDA error (%s): %s\n", msg, cudaGetErrorString(e)); | |
| std::exit(1); | |
| } | |
| } | |
| int main() { | |
| const int N = 10000; | |
| std::vector<cudaStream_t> streams(N); | |
| for (int i = 0; i < N; ++i) { | |
| check(cudaStreamCreateWithFlags(&streams[i], cudaStreamNonBlocking), | |
| "cudaStreamCreateWithFlags(cudaStreamNonBlocking)"); | |
| } | |
| std::unordered_set<std::uintptr_t> seen; | |
| bool any_dup = false; | |
| for (int i = 0; i < N; ++i) { | |
| // cudaStream_t is an opaque handle; usually pointer-like. | |
| std::uintptr_t h = reinterpret_cast<std::uintptr_t>(streams[i]); | |
| std::printf("Stream %d: handle = 0x%zx\n", i, (size_t)h); | |
| if (!seen.insert(h).second) { | |
| any_dup = true; | |
| std::printf(" >>> DUPLICATE handle detected: 0x%zx (at stream %d)\n", | |
| (size_t)h, i); | |
| } | |
| } | |
| std::printf("\nSummary:\n"); | |
| std::printf("Total streams created: %d\n", N); | |
| std::printf("Unique handles: %zu\n", seen.size()); | |
| std::printf("%s\n", any_dup ? "⚠️ Duplicates detected" : "✅ No duplicates detected"); | |
| for (int i = 0; i < N; ++i) { | |
| check(cudaStreamDestroy(streams[i]), "cudaStreamDestroy"); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment