9 Commits
v11.2 ... v11.4

Author SHA1 Message Date
Rutwik Choughule
e950012e72 add and update samples with CUDA 11.4 support 2021-06-30 11:26:41 +05:30
Rutwik Choughule
95b7cea7bc Merge branch 'master' of https://github.com/NVIDIA/cuda-samples 2021-06-10 18:37:53 +05:30
Rutwik Choughule
2aeaf51b11 cudaNvSciNvMedia plane offset correction 2021-06-10 17:33:24 +05:30
Rutwik Choughule
ba5a483c6e update vulkan samples with SPIR-V shaders 2021-06-10 17:30:25 +05:30
Rutwik Choughule
7a5b3e6c8c update vulkan samples with SPIR-V shaders 2021-06-02 17:17:21 +05:30
Rutwik Choughule
0787bc0489 correction in include path 2021-05-04 16:36:42 +05:30
Rutwik Choughule
5c3ec60fae correction in include path 2021-05-03 14:17:55 +05:30
Rutwik Choughule
568b39bd5b add and update samples with CUDA 11.3 support 2021-04-16 11:54:26 +05:30
Mahesh Doijade
067cb65523 -- Add partitioned cuda pipeline prod-cons gemm kernel
-- Add cudaCompressibleMemory sample to use copy engine vs SM writes
   depending on arch
2021-03-03 22:53:02 +05:30
233 changed files with 11320 additions and 6740 deletions

View File

@@ -1,11 +1,21 @@
# CUDA Samples # CUDA Samples
Samples for CUDA Developers which demonstrates features in CUDA Toolkit. This version supports [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads). Samples for CUDA Developers which demonstrates features in CUDA Toolkit. This version supports [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads).
## Release Notes ## Release Notes
This section describes the release notes for the CUDA Samples on GitHub only. This section describes the release notes for the CUDA Samples on GitHub only.
### CUDA 11.4
* Added `cdpQuadtree`. Demonstrates Quad Trees implementation using CUDA Dynamic Parallelism.
* Updated `simpleVulkan`, `simpleVulkanMMAP` and `vulkanImageCUDA`. Demonstrates use of SPIR-V shaders.
### CUDA 11.3
* Added `streamOrderedAllocationIPC`. Demonstrates Inter Process Communication using one process per GPU for computation.
* Added `simpleCUBLAS_LU`. Demonstrates batched matrix LU decomposition using cuBLAS API `cublas<t>getrfBatched()`
* Updated `simpleVulkan`. Demonstrates use of timeline semaphore.
* Updated multiple samples to use pinned memory using `cudaMallocHost()`.
### CUDA 11.2 ### CUDA 11.2
* Added `streamOrderedAllocation`. Demonstrates stream ordered memory allocation on a GPU using cudaMallocAsync and cudaMemPool family of APIs. * Added `streamOrderedAllocation`. Demonstrates stream ordered memory allocation on a GPU using cudaMallocAsync and cudaMemPool family of APIs.
* Added `streamOrderedAllocationP2P`. Demonstrates peer-to-peer access of stream ordered memory allocated using cudaMallocAsync and cudaMemPool family of APIs. * Added `streamOrderedAllocationP2P`. Demonstrates peer-to-peer access of stream ordered memory allocated using cudaMallocAsync and cudaMemPool family of APIs.
@@ -103,7 +113,7 @@ This is the first release of CUDA Samples on GitHub:
### Prerequisites ### Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
For system requirements and installation instructions of cuda toolkit, please refer to the [Linux Installation Guide](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/), and the [Windows Installation Guide](http://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html). For system requirements and installation instructions of cuda toolkit, please refer to the [Linux Installation Guide](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/), and the [Windows Installation Guide](http://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html).
### Getting the CUDA Samples ### Getting the CUDA Samples
@@ -160,38 +170,39 @@ The samples makefiles can take advantage of certain options:
### Samples by OS ### Samples by OS
#### Linux #### Linux
**[warpAggregatedAtomicsCG](./Samples/warpAggregatedAtomicsCG)** | **[boxFilterNPP](./Samples/boxFilterNPP)** | **[streamOrderedAllocationP2P](./Samples/streamOrderedAllocationP2P)** | **[binaryPartitionCG](./Samples/binaryPartitionCG)** | **[vectorAdd_nvrtc](./Samples/vectorAdd_nvrtc)** | **[shfl_scan](./Samples/shfl_scan)** | **[binaryPartitionCG](./Samples/binaryPartitionCG)** | **[concurrentKernels](./Samples/concurrentKernels)** |
---|---|---|---| ---|---|---|---|
**[dmmaTensorCoreGemm](./Samples/dmmaTensorCoreGemm)** | **[EGLStream_CUDA_Interop](./Samples/EGLStream_CUDA_Interop)** | **[conjugateGradientMultiBlockCG](./Samples/conjugateGradientMultiBlockCG)** | **[simpleIPC](./Samples/simpleIPC)** | **[streamOrderedAllocationIPC](./Samples/streamOrderedAllocationIPC)** | **[UnifiedMemoryPerf](./Samples/UnifiedMemoryPerf)** | **[bf16TensorCoreGemm](./Samples/bf16TensorCoreGemm)** | **[cuSolverSp_LinearSolver](./Samples/cuSolverSp_LinearSolver)** |
**[memMapIPCDrv](./Samples/memMapIPCDrv)** | **[vectorAddMMAP](./Samples/vectorAddMMAP)** | **[shfl_scan](./Samples/shfl_scan)** | **[simpleZeroCopy](./Samples/simpleZeroCopy)** | **[nvJPEG](./Samples/nvJPEG)** | **[watershedSegmentationNPP](./Samples/watershedSegmentationNPP)** | **[vulkanImageCUDA](./Samples/vulkanImageCUDA)** | **[boxFilterNPP](./Samples/boxFilterNPP)** |
**[conjugateGradientCudaGraphs](./Samples/conjugateGradientCudaGraphs)** | **[globalToShmemAsyncCopy](./Samples/globalToShmemAsyncCopy)** | **[cudaNvSciNvMedia](./Samples/cudaNvSciNvMedia)** | **[nvJPEG](./Samples/nvJPEG)** | **[matrixMul](./Samples/matrixMul)** | **[nvJPEG_encoder](./Samples/nvJPEG_encoder)** | **[simpleCudaGraphs](./Samples/simpleCudaGraphs)** | **[simpleCUFFT](./Samples/simpleCUFFT)** |
**[batchedLabelMarkersAndLabelCompressionNPP](./Samples/batchedLabelMarkersAndLabelCompressionNPP)** | **[watershedSegmentationNPP](./Samples/watershedSegmentationNPP)** | **[simpleCudaGraphs](./Samples/simpleCudaGraphs)** | **[streamOrderedAllocation](./Samples/streamOrderedAllocation)** | **[cudaTensorCoreGemm](./Samples/cudaTensorCoreGemm)** | **[cudaOpenMP](./Samples/cudaOpenMP)** | **[NV12toBGRandResize](./Samples/NV12toBGRandResize)** | **[cudaNvSci](./Samples/cudaNvSci)** |
**[deviceQuery](./Samples/deviceQuery)** | **[simpleVoteIntrinsics](./Samples/simpleVoteIntrinsics)** | **[simpleCUBLASXT](./Samples/simpleCUBLASXT)** | **[simpleAttributes](./Samples/simpleAttributes)** | **[immaTensorCoreGemm](./Samples/immaTensorCoreGemm)** | **[simpleVulkan](./Samples/simpleVulkan)** | **[simpleCUBLAS](./Samples/simpleCUBLAS)** | **[jacobiCudaGraphs](./Samples/jacobiCudaGraphs)** |
**[cudaNvSci](./Samples/cudaNvSci)** | **[tf32TensorCoreGemm](./Samples/tf32TensorCoreGemm)** | **[UnifiedMemoryPerf](./Samples/UnifiedMemoryPerf)** | **[cudaCompressibleMemory](./Samples/cudaCompressibleMemory)** | **[streamOrderedAllocationP2P](./Samples/streamOrderedAllocationP2P)** | **[dmmaTensorCoreGemm](./Samples/dmmaTensorCoreGemm)** | **[EGLStream_CUDA_Interop](./Samples/EGLStream_CUDA_Interop)** | **[vectorAddMMAP](./Samples/vectorAddMMAP)** |
**[bf16TensorCoreGemm](./Samples/bf16TensorCoreGemm)** | **[cuSolverDn_LinearSolver](./Samples/cuSolverDn_LinearSolver)** | **[vulkanImageCUDA](./Samples/vulkanImageCUDA)** | **[conjugateGradientMultiDeviceCG](./Samples/conjugateGradientMultiDeviceCG)** | **[MersenneTwisterGP11213](./Samples/MersenneTwisterGP11213)** | **[streamOrderedAllocation](./Samples/streamOrderedAllocation)** | **[cuSolverDn_LinearSolver](./Samples/cuSolverDn_LinearSolver)** | **[cudaCompressibleMemory](./Samples/cudaCompressibleMemory)** |
**[matrixMulDrv](./Samples/matrixMulDrv)** | **[cuSolverSp_LinearSolver](./Samples/cuSolverSp_LinearSolver)** | **[simpleCUFFT](./Samples/simpleCUFFT)** | **[reduction](./Samples/reduction)** | **[simpleAWBarrier](./Samples/simpleAWBarrier)** | **[simpleGL](./Samples/simpleGL)** | **[p2pBandwidthLatencyTest](./Samples/p2pBandwidthLatencyTest)** | **[conjugateGradientCudaGraphs](./Samples/conjugateGradientCudaGraphs)** |
**[nvJPEG_encoder](./Samples/nvJPEG_encoder)** | **[simpleDrvRuntime](./Samples/simpleDrvRuntime)** | **[MersenneTwisterGP11213](./Samples/MersenneTwisterGP11213)** | **[simpleAWBarrier](./Samples/simpleAWBarrier)** | **[globalToShmemAsyncCopy](./Samples/globalToShmemAsyncCopy)** | **[deviceQuery](./Samples/deviceQuery)** | **[systemWideAtomics](./Samples/systemWideAtomics)** | **[matrixMulDrv](./Samples/matrixMulDrv)** |
**[immaTensorCoreGemm](./Samples/immaTensorCoreGemm)** | **[bandwidthTest](./Samples/bandwidthTest)** | **[concurrentKernels](./Samples/concurrentKernels)** | **[simpleCUBLAS](./Samples/simpleCUBLAS)** | **[conjugateGradientMultiBlockCG](./Samples/conjugateGradientMultiBlockCG)** | **[simpleZeroCopy](./Samples/simpleZeroCopy)** | **[simpleAttributes](./Samples/simpleAttributes)** | **[batchedLabelMarkersAndLabelCompressionNPP](./Samples/batchedLabelMarkersAndLabelCompressionNPP)** |
**[NV12toBGRandResize](./Samples/NV12toBGRandResize)** | **[simpleGL](./Samples/simpleGL)** | **[cudaTensorCoreGemm](./Samples/cudaTensorCoreGemm)** | **[jacobiCudaGraphs](./Samples/jacobiCudaGraphs)** | **[conjugateGradientMultiDeviceCG](./Samples/conjugateGradientMultiDeviceCG)** | **[simpleIPC](./Samples/simpleIPC)** | **[simpleVulkanMMAP](./Samples/simpleVulkanMMAP)** | **[cudaNvSciNvMedia](./Samples/cudaNvSciNvMedia)** |
**[simpleVulkan](./Samples/simpleVulkan)** | **[vectorAdd_nvrtc](./Samples/vectorAdd_nvrtc)** | **[cannyEdgeDetectorNPP](./Samples/cannyEdgeDetectorNPP)** | **[p2pBandwidthLatencyTest](./Samples/p2pBandwidthLatencyTest)** | **[simpleVoteIntrinsics](./Samples/simpleVoteIntrinsics)** | **[simpleCUBLAS_LU](./Samples/simpleCUBLAS_LU)** | **[bandwidthTest](./Samples/bandwidthTest)** | **[cdpQuadtree](./Samples/cdpQuadtree)** |
**[simpleVulkanMMAP](./Samples/simpleVulkanMMAP)** | **[cudaOpenMP](./Samples/cudaOpenMP)** | **[matrixMul](./Samples/matrixMul)** | **[systemWideAtomics](./Samples/systemWideAtomics)** | **[simpleCUBLASXT](./Samples/simpleCUBLASXT)** | **[tf32TensorCoreGemm](./Samples/tf32TensorCoreGemm)** | **[simpleDrvRuntime](./Samples/simpleDrvRuntime)** | **[reduction](./Samples/reduction)** |
**[memMapIPCDrv](./Samples/memMapIPCDrv)** | **[warpAggregatedAtomicsCG](./Samples/warpAggregatedAtomicsCG)** | **[cannyEdgeDetectorNPP](./Samples/cannyEdgeDetectorNPP)** |
#### Windows #### Windows
**[warpAggregatedAtomicsCG](./Samples/warpAggregatedAtomicsCG)** | **[boxFilterNPP](./Samples/boxFilterNPP)** | **[streamOrderedAllocationP2P](./Samples/streamOrderedAllocationP2P)** | **[binaryPartitionCG](./Samples/binaryPartitionCG)** | **[vectorAdd_nvrtc](./Samples/vectorAdd_nvrtc)** | **[shfl_scan](./Samples/shfl_scan)** | **[binaryPartitionCG](./Samples/binaryPartitionCG)** | **[concurrentKernels](./Samples/concurrentKernels)** |
---|---|---|---| ---|---|---|---|
**[dmmaTensorCoreGemm](./Samples/dmmaTensorCoreGemm)** | **[conjugateGradientMultiBlockCG](./Samples/conjugateGradientMultiBlockCG)** | **[simpleIPC](./Samples/simpleIPC)** | **[memMapIPCDrv](./Samples/memMapIPCDrv)** | **[UnifiedMemoryPerf](./Samples/UnifiedMemoryPerf)** | **[bf16TensorCoreGemm](./Samples/bf16TensorCoreGemm)** | **[cuSolverSp_LinearSolver](./Samples/cuSolverSp_LinearSolver)** | **[nvJPEG](./Samples/nvJPEG)** |
**[vectorAddMMAP](./Samples/vectorAddMMAP)** | **[shfl_scan](./Samples/shfl_scan)** | **[simpleZeroCopy](./Samples/simpleZeroCopy)** | **[conjugateGradientCudaGraphs](./Samples/conjugateGradientCudaGraphs)** | **[watershedSegmentationNPP](./Samples/watershedSegmentationNPP)** | **[vulkanImageCUDA](./Samples/vulkanImageCUDA)** | **[boxFilterNPP](./Samples/boxFilterNPP)** | **[matrixMul](./Samples/matrixMul)** |
**[globalToShmemAsyncCopy](./Samples/globalToShmemAsyncCopy)** | **[nvJPEG](./Samples/nvJPEG)** | **[batchedLabelMarkersAndLabelCompressionNPP](./Samples/batchedLabelMarkersAndLabelCompressionNPP)** | **[simpleD3D12](./Samples/simpleD3D12)** | **[nvJPEG_encoder](./Samples/nvJPEG_encoder)** | **[simpleCudaGraphs](./Samples/simpleCudaGraphs)** | **[simpleCUFFT](./Samples/simpleCUFFT)** | **[cudaTensorCoreGemm](./Samples/cudaTensorCoreGemm)** |
**[watershedSegmentationNPP](./Samples/watershedSegmentationNPP)** | **[simpleCudaGraphs](./Samples/simpleCudaGraphs)** | **[streamOrderedAllocation](./Samples/streamOrderedAllocation)** | **[deviceQuery](./Samples/deviceQuery)** | **[cudaOpenMP](./Samples/cudaOpenMP)** | **[NV12toBGRandResize](./Samples/NV12toBGRandResize)** | **[immaTensorCoreGemm](./Samples/immaTensorCoreGemm)** | **[simpleVulkan](./Samples/simpleVulkan)** |
**[simpleVoteIntrinsics](./Samples/simpleVoteIntrinsics)** | **[simpleCUBLASXT](./Samples/simpleCUBLASXT)** | **[simpleAttributes](./Samples/simpleAttributes)** | **[tf32TensorCoreGemm](./Samples/tf32TensorCoreGemm)** | **[simpleCUBLAS](./Samples/simpleCUBLAS)** | **[jacobiCudaGraphs](./Samples/jacobiCudaGraphs)** | **[streamOrderedAllocationP2P](./Samples/streamOrderedAllocationP2P)** | **[dmmaTensorCoreGemm](./Samples/dmmaTensorCoreGemm)** |
**[UnifiedMemoryPerf](./Samples/UnifiedMemoryPerf)** | **[cudaCompressibleMemory](./Samples/cudaCompressibleMemory)** | **[bf16TensorCoreGemm](./Samples/bf16TensorCoreGemm)** | **[cuSolverDn_LinearSolver](./Samples/cuSolverDn_LinearSolver)** | **[vectorAddMMAP](./Samples/vectorAddMMAP)** | **[MersenneTwisterGP11213](./Samples/MersenneTwisterGP11213)** | **[streamOrderedAllocation](./Samples/streamOrderedAllocation)** | **[cuSolverDn_LinearSolver](./Samples/cuSolverDn_LinearSolver)** |
**[vulkanImageCUDA](./Samples/vulkanImageCUDA)** | **[conjugateGradientMultiDeviceCG](./Samples/conjugateGradientMultiDeviceCG)** | **[matrixMulDrv](./Samples/matrixMulDrv)** | **[cuSolverSp_LinearSolver](./Samples/cuSolverSp_LinearSolver)** | **[cudaCompressibleMemory](./Samples/cudaCompressibleMemory)** | **[simpleAWBarrier](./Samples/simpleAWBarrier)** | **[simpleGL](./Samples/simpleGL)** | **[p2pBandwidthLatencyTest](./Samples/p2pBandwidthLatencyTest)** |
**[simpleCUFFT](./Samples/simpleCUFFT)** | **[reduction](./Samples/reduction)** | **[nvJPEG_encoder](./Samples/nvJPEG_encoder)** | **[simpleDrvRuntime](./Samples/simpleDrvRuntime)** | **[conjugateGradientCudaGraphs](./Samples/conjugateGradientCudaGraphs)** | **[simpleD3D11](./Samples/simpleD3D11)** | **[globalToShmemAsyncCopy](./Samples/globalToShmemAsyncCopy)** | **[deviceQuery](./Samples/deviceQuery)** |
**[simpleD3D11](./Samples/simpleD3D11)** | **[MersenneTwisterGP11213](./Samples/MersenneTwisterGP11213)** | **[simpleAWBarrier](./Samples/simpleAWBarrier)** | **[immaTensorCoreGemm](./Samples/immaTensorCoreGemm)** | **[matrixMulDrv](./Samples/matrixMulDrv)** | **[conjugateGradientMultiBlockCG](./Samples/conjugateGradientMultiBlockCG)** | **[simpleZeroCopy](./Samples/simpleZeroCopy)** | **[simpleAttributes](./Samples/simpleAttributes)** |
**[bandwidthTest](./Samples/bandwidthTest)** | **[concurrentKernels](./Samples/concurrentKernels)** | **[simpleCUBLAS](./Samples/simpleCUBLAS)** | **[NV12toBGRandResize](./Samples/NV12toBGRandResize)** | **[simpleD3D12](./Samples/simpleD3D12)** | **[batchedLabelMarkersAndLabelCompressionNPP](./Samples/batchedLabelMarkersAndLabelCompressionNPP)** | **[conjugateGradientMultiDeviceCG](./Samples/conjugateGradientMultiDeviceCG)** | **[simpleIPC](./Samples/simpleIPC)** |
**[simpleGL](./Samples/simpleGL)** | **[cudaTensorCoreGemm](./Samples/cudaTensorCoreGemm)** | **[jacobiCudaGraphs](./Samples/jacobiCudaGraphs)** | **[simpleVulkan](./Samples/simpleVulkan)** | **[simpleVulkanMMAP](./Samples/simpleVulkanMMAP)** | **[simpleVoteIntrinsics](./Samples/simpleVoteIntrinsics)** | **[simpleCUBLAS_LU](./Samples/simpleCUBLAS_LU)** | **[bandwidthTest](./Samples/bandwidthTest)** |
**[vectorAdd_nvrtc](./Samples/vectorAdd_nvrtc)** | **[cannyEdgeDetectorNPP](./Samples/cannyEdgeDetectorNPP)** | **[p2pBandwidthLatencyTest](./Samples/p2pBandwidthLatencyTest)** | **[simpleVulkanMMAP](./Samples/simpleVulkanMMAP)** | **[cdpQuadtree](./Samples/cdpQuadtree)** | **[simpleCUBLASXT](./Samples/simpleCUBLASXT)** | **[tf32TensorCoreGemm](./Samples/tf32TensorCoreGemm)** | **[simpleDrvRuntime](./Samples/simpleDrvRuntime)** |
**[cudaOpenMP](./Samples/cudaOpenMP)** | **[matrixMul](./Samples/matrixMul)** | **[reduction](./Samples/reduction)** | **[memMapIPCDrv](./Samples/memMapIPCDrv)** | **[warpAggregatedAtomicsCG](./Samples/warpAggregatedAtomicsCG)** | **[cannyEdgeDetectorNPP](./Samples/cannyEdgeDetectorNPP)** |
## Dependencies ## Dependencies

View File

@@ -30,7 +30,7 @@ cuDeviceGet, cuDeviceGetAttribute, cuDeviceComputeCapability, cuDeviceGetCount,
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -47,138 +47,134 @@
float compareResults(int rand_n, float *h_RandGPU, float *h_RandCPU); float compareResults(int rand_n, float *h_RandGPU, float *h_RandCPU);
const int DEFAULT_RAND_N = 2400000; const int DEFAULT_RAND_N = 2400000;
const unsigned int DEFAULT_SEED = 777; const unsigned int DEFAULT_SEED = 777;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Main program // Main program
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv) int main(int argc, char **argv) {
{ // Start logs
// Start logs printf("%s Starting...\n\n", argv[0]);
printf("%s Starting...\n\n", argv[0]);
// initialize the GPU, either identified by --device // initialize the GPU, either identified by --device
// or by picking the device with highest flop rate. // or by picking the device with highest flop rate.
int devID = findCudaDevice(argc, (const char **)argv); int devID = findCudaDevice(argc, (const char **)argv);
// parsing the number of random numbers to generate // parsing the number of random numbers to generate
int rand_n = DEFAULT_RAND_N; int rand_n = DEFAULT_RAND_N;
if (checkCmdLineFlag(argc, (const char **) argv, "count")) if (checkCmdLineFlag(argc, (const char **)argv, "count")) {
{ rand_n = getCmdLineArgumentInt(argc, (const char **)argv, "count");
rand_n = getCmdLineArgumentInt(argc, (const char **) argv, "count"); }
}
printf("Allocating data for %i samples...\n", rand_n); printf("Allocating data for %i samples...\n", rand_n);
// parsing the seed // parsing the seed
int seed = DEFAULT_SEED; int seed = DEFAULT_SEED;
if (checkCmdLineFlag(argc, (const char **) argv, "seed")) if (checkCmdLineFlag(argc, (const char **)argv, "seed")) {
{ seed = getCmdLineArgumentInt(argc, (const char **)argv, "seed");
seed = getCmdLineArgumentInt(argc, (const char **) argv, "seed"); }
}
printf("Seeding with %i ...\n", seed); printf("Seeding with %i ...\n", seed);
cudaStream_t stream; cudaStream_t stream;
checkCudaErrors(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking)); checkCudaErrors(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
float *d_Rand; float *d_Rand;
checkCudaErrors(cudaMalloc((void **)&d_Rand, rand_n * sizeof(float))); checkCudaErrors(cudaMalloc((void **)&d_Rand, rand_n * sizeof(float)));
curandGenerator_t prngGPU; curandGenerator_t prngGPU;
checkCudaErrors(curandCreateGenerator(&prngGPU, CURAND_RNG_PSEUDO_MTGP32)); checkCudaErrors(curandCreateGenerator(&prngGPU, CURAND_RNG_PSEUDO_MTGP32));
checkCudaErrors(curandSetStream(prngGPU, stream)); checkCudaErrors(curandSetStream(prngGPU, stream));
checkCudaErrors(curandSetPseudoRandomGeneratorSeed(prngGPU, seed)); checkCudaErrors(curandSetPseudoRandomGeneratorSeed(prngGPU, seed));
curandGenerator_t prngCPU; curandGenerator_t prngCPU;
checkCudaErrors(curandCreateGeneratorHost(&prngCPU, CURAND_RNG_PSEUDO_MTGP32)); checkCudaErrors(
checkCudaErrors(curandSetPseudoRandomGeneratorSeed(prngCPU, seed)); curandCreateGeneratorHost(&prngCPU, CURAND_RNG_PSEUDO_MTGP32));
checkCudaErrors(curandSetPseudoRandomGeneratorSeed(prngCPU, seed));
// //
// Example 1: Compare random numbers generated on GPU and CPU // Example 1: Compare random numbers generated on GPU and CPU
float *h_RandGPU = (float *)malloc(rand_n * sizeof(float)); float *h_RandGPU;
checkCudaErrors(cudaMallocHost(&h_RandGPU, rand_n * sizeof(float)));
printf("Generating random numbers on GPU...\n\n"); printf("Generating random numbers on GPU...\n\n");
checkCudaErrors(curandGenerateUniform(prngGPU, (float *) d_Rand, rand_n)); checkCudaErrors(curandGenerateUniform(prngGPU, (float *)d_Rand, rand_n));
printf("\nReading back the results...\n"); printf("\nReading back the results...\n");
checkCudaErrors(cudaMemcpyAsync(h_RandGPU, d_Rand, rand_n * sizeof(float), cudaMemcpyDeviceToHost, stream)); checkCudaErrors(cudaMemcpyAsync(h_RandGPU, d_Rand, rand_n * sizeof(float),
cudaMemcpyDeviceToHost, stream));
float *h_RandCPU = (float *)malloc(rand_n * sizeof(float));
float *h_RandCPU = (float *)malloc(rand_n * sizeof(float)); printf("Generating random numbers on CPU...\n\n");
checkCudaErrors(curandGenerateUniform(prngCPU, (float *)h_RandCPU, rand_n));
printf("Generating random numbers on CPU...\n\n"); checkCudaErrors(cudaStreamSynchronize(stream));
checkCudaErrors(curandGenerateUniform(prngCPU, (float *) h_RandCPU, rand_n)); printf("Comparing CPU/GPU random numbers...\n\n");
float L1norm = compareResults(rand_n, h_RandGPU, h_RandCPU);
checkCudaErrors(cudaStreamSynchronize(stream)); //
printf("Comparing CPU/GPU random numbers...\n\n"); // Example 2: Timing of random number generation on GPU
float L1norm = compareResults(rand_n, h_RandGPU, h_RandCPU); const int numIterations = 10;
int i;
StopWatchInterface *hTimer;
// sdkCreateTimer(&hTimer);
// Example 2: Timing of random number generation on GPU sdkResetTimer(&hTimer);
const int numIterations = 10; sdkStartTimer(&hTimer);
int i;
StopWatchInterface *hTimer;
sdkCreateTimer(&hTimer); for (i = 0; i < numIterations; i++) {
sdkResetTimer(&hTimer); checkCudaErrors(curandGenerateUniform(prngGPU, (float *)d_Rand, rand_n));
sdkStartTimer(&hTimer); }
for (i = 0; i < numIterations; i++) checkCudaErrors(cudaStreamSynchronize(stream));
{ sdkStopTimer(&hTimer);
checkCudaErrors(curandGenerateUniform(prngGPU, (float *) d_Rand, rand_n));
}
checkCudaErrors(cudaStreamSynchronize(stream)); double gpuTime = 1.0e-3 * sdkGetTimerValue(&hTimer) / (double)numIterations;
sdkStopTimer(&hTimer);
double gpuTime = 1.0e-3 * sdkGetTimerValue(&hTimer)/(double)numIterations; printf(
"MersenneTwisterGP11213, Throughput = %.4f GNumbers/s, Time = %.5f s, "
"Size = %u Numbers\n",
1.0e-9 * rand_n / gpuTime, gpuTime, rand_n);
printf("MersenneTwisterGP11213, Throughput = %.4f GNumbers/s, Time = %.5f s, Size = %u Numbers\n", printf("Shutting down...\n");
1.0e-9 * rand_n / gpuTime, gpuTime, rand_n);
printf("Shutting down...\n"); checkCudaErrors(curandDestroyGenerator(prngGPU));
checkCudaErrors(curandDestroyGenerator(prngCPU));
checkCudaErrors(cudaStreamDestroy(stream));
checkCudaErrors(cudaFree(d_Rand));
sdkDeleteTimer(&hTimer);
checkCudaErrors(cudaFreeHost(h_RandGPU));
free(h_RandCPU);
checkCudaErrors(curandDestroyGenerator(prngGPU)); exit(L1norm < 1e-6 ? EXIT_SUCCESS : EXIT_FAILURE);
checkCudaErrors(curandDestroyGenerator(prngCPU));
checkCudaErrors(cudaStreamDestroy(stream));
checkCudaErrors(cudaFree(d_Rand));
sdkDeleteTimer(&hTimer);
free(h_RandGPU);
free(h_RandCPU);
exit(L1norm < 1e-6 ? EXIT_SUCCESS : EXIT_FAILURE);
} }
float compareResults(int rand_n, float *h_RandGPU, float *h_RandCPU) {
int i;
float rCPU, rGPU, delta;
float max_delta = 0.;
float sum_delta = 0.;
float sum_ref = 0.;
float compareResults(int rand_n, float *h_RandGPU, float *h_RandCPU) for (i = 0; i < rand_n; i++) {
{ rCPU = h_RandCPU[i];
int i; rGPU = h_RandGPU[i];
float rCPU, rGPU, delta; delta = fabs(rCPU - rGPU);
float max_delta = 0.; sum_delta += delta;
float sum_delta = 0.; sum_ref += fabs(rCPU);
float sum_ref = 0.;
for (i = 0; i < rand_n; i++) if (delta >= max_delta) {
{ max_delta = delta;
rCPU = h_RandCPU[i];
rGPU = h_RandGPU[i];
delta = fabs(rCPU - rGPU);
sum_delta += delta;
sum_ref += fabs(rCPU);
if (delta >= max_delta)
{
max_delta = delta;
}
} }
}
float L1norm = (float)(sum_delta / sum_ref); float L1norm = (float)(sum_delta / sum_ref);
printf("Max absolute error: %E\n", max_delta); printf("Max absolute error: %E\n", max_delta);
printf("L1 norm: %E\n\n", L1norm); printf("L1 norm: %E\n\n", L1norm);
return L1norm; return L1norm;
} }

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -104,6 +104,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -27,7 +27,7 @@ x86_64, ppc64le, armv7l
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -113,6 +113,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -109,6 +109,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -27,7 +27,7 @@ cudaMemcpy2D, cudaMallocManaged
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
## Build and Run ## Build and Run

View File

@@ -28,7 +28,7 @@ cudaMallocManaged, cudaStreamAttachMemAsync, cudaMemcpyAsync, cudaMallocHost, cu
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -111,6 +111,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -107,6 +107,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -27,7 +27,7 @@ cudaSetDevice, cudaHostAlloc, cudaFree, cudaMallocHost, cudaFreeHost, cudaMemcpy
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -104,6 +104,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -28,7 +28,7 @@ x86_64, ppc64le, armv7l
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -36,11 +36,13 @@
#include <string.h> #include <string.h>
#include <fstream> #include <fstream>
#include <cuda_runtime.h>
#include <helper_cuda.h> #include <helper_cuda.h>
#include <helper_string.h>
#include <npp.h> #include <npp.h>
// Note: If you want to view these images we HIGHLY recommend using imagej // Note: If you want to view these images we HIGHLY recommend using imagej
// which is free on the internet and works on most platforms // which is free on the internet and works on most platforms
// because it is one of the few image viewing apps that can display 32 // because it is one of the few image viewing apps that can display 32
// bit integer image data. While it normalizes the data to floating // bit integer image data. While it normalizes the data to floating
// point values for viewing it still provides a good representation of // point values for viewing it still provides a good representation of
@@ -102,11 +104,12 @@ void tearDown() // Clean up and tear down
if (pUFBatchSrcDstImageListDev != 0) cudaFree(pUFBatchSrcDstImageListDev); if (pUFBatchSrcDstImageListDev != 0) cudaFree(pUFBatchSrcDstImageListDev);
if (pUFBatchSrcImageListDev != 0) cudaFree(pUFBatchSrcImageListDev); if (pUFBatchSrcImageListDev != 0) cudaFree(pUFBatchSrcImageListDev);
if (pUFBatchPerImageCompressedCountListHost != 0) if (pUFBatchPerImageCompressedCountListHost != 0)
free(pUFBatchPerImageCompressedCountListHost); cudaFreeHost(pUFBatchPerImageCompressedCountListHost);
if (pUFBatchSrcDstScratchBufferListHost != 0) if (pUFBatchSrcDstScratchBufferListHost != 0)
free(pUFBatchSrcDstScratchBufferListHost); cudaFreeHost(pUFBatchSrcDstScratchBufferListHost);
if (pUFBatchSrcDstImageListHost != 0) free(pUFBatchSrcDstImageListHost); if (pUFBatchSrcDstImageListHost != 0)
if (pUFBatchSrcImageListHost != 0) free(pUFBatchSrcImageListHost); cudaFreeHost(pUFBatchSrcDstImageListHost);
if (pUFBatchSrcImageListHost != 0) cudaFreeHost(pUFBatchSrcImageListHost);
for (int j = 0; j < NUMBER_OF_IMAGES; j++) { for (int j = 0; j < NUMBER_OF_IMAGES; j++) {
if (pUFCompressedLabelsScratchBufferDev[j] != 0) if (pUFCompressedLabelsScratchBufferDev[j] != 0)
@@ -115,8 +118,8 @@ void tearDown() // Clean up and tear down
cudaFree(pUFGenerateLabelsScratchBufferDev[j]); cudaFree(pUFGenerateLabelsScratchBufferDev[j]);
if (pUFLabelDev[j] != 0) cudaFree(pUFLabelDev[j]); if (pUFLabelDev[j] != 0) cudaFree(pUFLabelDev[j]);
if (pInputImageDev[j] != 0) cudaFree(pInputImageDev[j]); if (pInputImageDev[j] != 0) cudaFree(pInputImageDev[j]);
if (pUFLabelHost[j] != 0) free(pUFLabelHost[j]); if (pUFLabelHost[j] != 0) cudaFreeHost(pUFLabelHost[j]);
if (pInputImageHost[j] != 0) free(pInputImageHost[j]); if (pInputImageHost[j] != 0) cudaFreeHost(pInputImageHost[j]);
} }
} }
@@ -177,7 +180,7 @@ int loadRaw8BitImage(Npp8u *pImage, int nWidth, int nHeight, int nImage) {
exit(EXIT_WAIVED); exit(EXIT_WAIVED);
} }
bmpFile = fopen(InputFile, "rb"); FOPEN(bmpFile, InputFile, "rb");
} else if (nImage == 1) { } else if (nImage == 1) {
if (nWidth != 512 || nHeight != 512) return -1; if (nWidth != 512 || nHeight != 512) return -1;
const char *fileName = "CT_skull_512x512_8u.raw"; const char *fileName = "CT_skull_512x512_8u.raw";
@@ -187,7 +190,7 @@ int loadRaw8BitImage(Npp8u *pImage, int nWidth, int nHeight, int nImage) {
exit(EXIT_WAIVED); exit(EXIT_WAIVED);
} }
bmpFile = fopen(InputFile, "rb"); FOPEN(bmpFile, InputFile, "rb");
} else if (nImage == 2) { } else if (nImage == 2) {
if (nWidth != 509 || nHeight != 335) return -1; if (nWidth != 509 || nHeight != 335) return -1;
const char *fileName = "PCB_METAL_509x335_8u.raw"; const char *fileName = "PCB_METAL_509x335_8u.raw";
@@ -197,7 +200,7 @@ int loadRaw8BitImage(Npp8u *pImage, int nWidth, int nHeight, int nImage) {
exit(EXIT_WAIVED); exit(EXIT_WAIVED);
} }
bmpFile = fopen(InputFile, "rb"); FOPEN(bmpFile, InputFile, "rb");
} else if (nImage == 3) { } else if (nImage == 3) {
if (nWidth != 1024 || nHeight != 683) return -1; if (nWidth != 1024 || nHeight != 683) return -1;
const char *fileName = "PCB2_1024x683_8u.raw"; const char *fileName = "PCB2_1024x683_8u.raw";
@@ -207,7 +210,7 @@ int loadRaw8BitImage(Npp8u *pImage, int nWidth, int nHeight, int nImage) {
exit(EXIT_WAIVED); exit(EXIT_WAIVED);
} }
bmpFile = fopen(InputFile, "rb"); FOPEN(bmpFile, InputFile, "rb");
} else if (nImage == 4) { } else if (nImage == 4) {
if (nWidth != 1280 || nHeight != 720) return -1; if (nWidth != 1280 || nHeight != 720) return -1;
const char *fileName = "PCB_1280x720_8u.raw"; const char *fileName = "PCB_1280x720_8u.raw";
@@ -217,7 +220,7 @@ int loadRaw8BitImage(Npp8u *pImage, int nWidth, int nHeight, int nImage) {
exit(EXIT_WAIVED); exit(EXIT_WAIVED);
} }
bmpFile = fopen(InputFile, "rb"); FOPEN(bmpFile, InputFile, "rb");
} else { } else {
printf("Input file load failed.\n"); printf("Input file load failed.\n");
return -1; return -1;
@@ -347,9 +350,11 @@ int main(int argc, char **argv) {
oSizeROI[nImage].width * sizeof(Npp32u) * oSizeROI[nImage].height); oSizeROI[nImage].width * sizeof(Npp32u) * oSizeROI[nImage].height);
if (cudaError != cudaSuccess) return NPP_MEMORY_ALLOCATION_ERR; if (cudaError != cudaSuccess) return NPP_MEMORY_ALLOCATION_ERR;
pInputImageHost[nImage] = reinterpret_cast<Npp8u *>(malloc( checkCudaErrors(cudaMallocHost(
&(pInputImageHost[nImage]),
oSizeROI[nImage].width * sizeof(Npp8u) * oSizeROI[nImage].height)); oSizeROI[nImage].width * sizeof(Npp8u) * oSizeROI[nImage].height));
pUFLabelHost[nImage] = reinterpret_cast<Npp32u *>(malloc( checkCudaErrors(cudaMallocHost(
&(pUFLabelHost[nImage]),
oSizeROI[nImage].width * sizeof(Npp32u) * oSizeROI[nImage].height)); oSizeROI[nImage].width * sizeof(Npp32u) * oSizeROI[nImage].height));
// Use UF functions throughout this sample. // Use UF functions throughout this sample.
@@ -409,15 +414,15 @@ int main(int argc, char **argv) {
} }
if (nImage == 0) if (nImage == 0)
bmpFile = fopen(LabelMarkersOutputFile0.c_str(), "wb"); FOPEN(bmpFile, LabelMarkersOutputFile0.c_str(), "wb");
else if (nImage == 1) else if (nImage == 1)
bmpFile = fopen(LabelMarkersOutputFile1.c_str(), "wb"); FOPEN(bmpFile, LabelMarkersOutputFile1.c_str(), "wb");
else if (nImage == 2) else if (nImage == 2)
bmpFile = fopen(LabelMarkersOutputFile2.c_str(), "wb"); FOPEN(bmpFile, LabelMarkersOutputFile2.c_str(), "wb");
else if (nImage == 3) else if (nImage == 3)
bmpFile = fopen(LabelMarkersOutputFile3.c_str(), "wb"); FOPEN(bmpFile, LabelMarkersOutputFile3.c_str(), "wb");
else if (nImage == 4) else if (nImage == 4)
bmpFile = fopen(LabelMarkersOutputFile4.c_str(), "wb"); FOPEN(bmpFile, LabelMarkersOutputFile4.c_str(), "wb");
if (bmpFile == NULL) return -1; if (bmpFile == NULL) return -1;
size_t nSize = 0; size_t nSize = 0;
@@ -478,15 +483,15 @@ int main(int argc, char **argv) {
} }
if (nImage == 0) if (nImage == 0)
bmpFile = fopen(CompressedMarkerLabelsOutputFile0.c_str(), "wb"); FOPEN(bmpFile, CompressedMarkerLabelsOutputFile0.c_str(), "wb");
else if (nImage == 1) else if (nImage == 1)
bmpFile = fopen(CompressedMarkerLabelsOutputFile1.c_str(), "wb"); FOPEN(bmpFile, CompressedMarkerLabelsOutputFile1.c_str(), "wb");
else if (nImage == 2) else if (nImage == 2)
bmpFile = fopen(CompressedMarkerLabelsOutputFile2.c_str(), "wb"); FOPEN(bmpFile, CompressedMarkerLabelsOutputFile2.c_str(), "wb");
else if (nImage == 3) else if (nImage == 3)
bmpFile = fopen(CompressedMarkerLabelsOutputFile3.c_str(), "wb"); FOPEN(bmpFile, CompressedMarkerLabelsOutputFile3.c_str(), "wb");
else if (nImage == 4) else if (nImage == 4)
bmpFile = fopen(CompressedMarkerLabelsOutputFile4.c_str(), "wb"); FOPEN(bmpFile, CompressedMarkerLabelsOutputFile4.c_str(), "wb");
if (bmpFile == NULL) return -1; if (bmpFile == NULL) return -1;
nSize = 0; nSize = 0;
@@ -554,10 +559,11 @@ int main(int argc, char **argv) {
cudaMalloc((void **)&pUFBatchSrcDstImageListDev, nBatchImageListBytes); cudaMalloc((void **)&pUFBatchSrcDstImageListDev, nBatchImageListBytes);
if (cudaError != cudaSuccess) return NPP_MEMORY_ALLOCATION_ERR; if (cudaError != cudaSuccess) return NPP_MEMORY_ALLOCATION_ERR;
pUFBatchSrcImageListHost = checkCudaErrors(
reinterpret_cast<NppiImageDescriptor *>(malloc(nBatchImageListBytes)); cudaMallocHost((void **)&pUFBatchSrcImageListHost, nBatchImageListBytes));
pUFBatchSrcDstImageListHost =
reinterpret_cast<NppiImageDescriptor *>(malloc(nBatchImageListBytes)); checkCudaErrors(cudaMallocHost((void **)&pUFBatchSrcDstImageListHost,
nBatchImageListBytes));
NppiSize oMaxROISize = {0, 0}; NppiSize oMaxROISize = {0, 0};
@@ -620,15 +626,15 @@ int main(int argc, char **argv) {
// Save output to files // Save output to files
for (int nImage = 0; nImage < NUMBER_OF_IMAGES; nImage++) { for (int nImage = 0; nImage < NUMBER_OF_IMAGES; nImage++) {
if (nImage == 0) if (nImage == 0)
bmpFile = fopen(LabelMarkersBatchOutputFile0.c_str(), "wb"); FOPEN(bmpFile, LabelMarkersBatchOutputFile0.c_str(), "wb");
else if (nImage == 1) else if (nImage == 1)
bmpFile = fopen(LabelMarkersBatchOutputFile1.c_str(), "wb"); FOPEN(bmpFile, LabelMarkersBatchOutputFile1.c_str(), "wb");
else if (nImage == 2) else if (nImage == 2)
bmpFile = fopen(LabelMarkersBatchOutputFile2.c_str(), "wb"); FOPEN(bmpFile, LabelMarkersBatchOutputFile2.c_str(), "wb");
else if (nImage == 3) else if (nImage == 3)
bmpFile = fopen(LabelMarkersBatchOutputFile3.c_str(), "wb"); FOPEN(bmpFile, LabelMarkersBatchOutputFile3.c_str(), "wb");
else if (nImage == 4) else if (nImage == 4)
bmpFile = fopen(LabelMarkersBatchOutputFile4.c_str(), "wb"); FOPEN(bmpFile, LabelMarkersBatchOutputFile4.c_str(), "wb");
if (bmpFile == NULL) return -1; if (bmpFile == NULL) return -1;
size_t nSize = 0; size_t nSize = 0;
@@ -652,12 +658,13 @@ int main(int argc, char **argv) {
// Allocate host side scratch buffer point and size list and initialize with // Allocate host side scratch buffer point and size list and initialize with
// device scratch buffer pointers // device scratch buffer pointers
pUFBatchSrcDstScratchBufferListHost = checkCudaErrors(
reinterpret_cast<NppiBufferDescriptor *>( cudaMallocHost((void **)&pUFBatchSrcDstScratchBufferListHost,
malloc(NUMBER_OF_IMAGES * sizeof(NppiBufferDescriptor))); NUMBER_OF_IMAGES * sizeof(NppiBufferDescriptor)));
pUFBatchPerImageCompressedCountListHost = checkCudaErrors(
reinterpret_cast<Npp32u *>(malloc(NUMBER_OF_IMAGES * sizeof(Npp32u))); cudaMallocHost((void **)&pUFBatchPerImageCompressedCountListHost,
+NUMBER_OF_IMAGES * sizeof(Npp32u)));
// Start buffer pointer at beginning of full per image buffer list sized // Start buffer pointer at beginning of full per image buffer list sized
// pUFCompressedLabelsScratchBufferDev[0] // pUFCompressedLabelsScratchBufferDev[0]
@@ -728,15 +735,15 @@ int main(int argc, char **argv) {
// Save compressed label images into files // Save compressed label images into files
for (int nImage = 0; nImage < NUMBER_OF_IMAGES; nImage++) { for (int nImage = 0; nImage < NUMBER_OF_IMAGES; nImage++) {
if (nImage == 0) if (nImage == 0)
bmpFile = fopen(CompressedMarkerLabelsBatchOutputFile0.c_str(), "wb"); FOPEN(bmpFile, CompressedMarkerLabelsBatchOutputFile0.c_str(), "wb");
else if (nImage == 1) else if (nImage == 1)
bmpFile = fopen(CompressedMarkerLabelsBatchOutputFile1.c_str(), "wb"); FOPEN(bmpFile, CompressedMarkerLabelsBatchOutputFile1.c_str(), "wb");
else if (nImage == 2) else if (nImage == 2)
bmpFile = fopen(CompressedMarkerLabelsBatchOutputFile2.c_str(), "wb"); FOPEN(bmpFile, CompressedMarkerLabelsBatchOutputFile2.c_str(), "wb");
else if (nImage == 3) else if (nImage == 3)
bmpFile = fopen(CompressedMarkerLabelsBatchOutputFile3.c_str(), "wb"); FOPEN(bmpFile, CompressedMarkerLabelsBatchOutputFile3.c_str(), "wb");
else if (nImage == 4) else if (nImage == 4)
bmpFile = fopen(CompressedMarkerLabelsBatchOutputFile4.c_str(), "wb"); FOPEN(bmpFile, CompressedMarkerLabelsBatchOutputFile4.c_str(), "wb");
if (bmpFile == NULL) return -1; if (bmpFile == NULL) return -1;
size_t nSize = 0; size_t nSize = 0;

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -104,6 +104,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -27,7 +27,7 @@ cudaMallocManaged, cudaDeviceSynchronize, cudaFuncSetAttribute, cudaEventCreate,
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -104,6 +104,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -24,7 +24,7 @@ x86_64, ppc64le, armv7l
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
## Build and Run ## Build and Run

View File

@@ -31,14 +31,16 @@
* 1.) Each thread loads a value from random array. * 1.) Each thread loads a value from random array.
* 2.) then checks if it is odd or even. * 2.) then checks if it is odd or even.
* 3.) create binary partition group based on the above predicate * 3.) create binary partition group based on the above predicate
* 4.) we count the number of odd/even in the group based on size of the binary groups * 4.) we count the number of odd/even in the group based on size of the binary
groups
* 5.) write it global counter of odd. * 5.) write it global counter of odd.
* 6.) sum the values loaded by individual threads(using reduce) and write it to global * 6.) sum the values loaded by individual threads(using reduce) and write it to
* even & odd elements sum. global even & odd elements sum.
* *
* **NOTE** : binary_partition results in splitting warp into divergent thread groups * **NOTE** :
this is not good from performance perspective, but in cases where warp * binary_partition results in splitting warp into divergent thread groups
divergence is inevitable one can use binary_partition group. * this is not good from performance perspective, but in cases where warp
* divergence is inevitable one can use binary_partition group.
*/ */
#include <stdio.h> #include <stdio.h>
@@ -48,108 +50,110 @@
namespace cg = cooperative_groups; namespace cg = cooperative_groups;
void initOddEvenArr(int *inputArr, unsigned int size) void initOddEvenArr(int *inputArr, unsigned int size) {
{ for (int i = 0; i < size; i++) {
for (int i=0; i < size; i++) inputArr[i] = rand() % 50;
{ }
inputArr[i] = rand() % 50;
}
} }
/** /**
* CUDA kernel device code * CUDA kernel device code
* *
* Creates cooperative groups and performs odd/even counting & summation. * Creates cooperative groups and performs odd/even counting & summation.
*/ */
__global__ void oddEvenCountAndSumCG(int *inputArr, int *numOfOdds, int *sumOfOddAndEvens, unsigned int size) __global__ void oddEvenCountAndSumCG(int *inputArr, int *numOfOdds,
{ int *sumOfOddAndEvens, unsigned int size) {
cg::thread_block cta = cg::this_thread_block(); cg::thread_block cta = cg::this_thread_block();
cg::grid_group grid = cg::this_grid(); cg::grid_group grid = cg::this_grid();
cg::thread_block_tile<32> tile32 = cg::tiled_partition<32>(cta); cg::thread_block_tile<32> tile32 = cg::tiled_partition<32>(cta);
for (int i = grid.thread_rank(); i < size; i += grid.size()) for (int i = grid.thread_rank(); i < size; i += grid.size()) {
int elem = inputArr[i];
auto subTile = cg::binary_partition(tile32, elem & 1);
if (elem & 1) // Odd numbers group
{ {
int elem = inputArr[i]; int oddGroupSum = cg::reduce(subTile, elem, cg::plus<int>());
auto subTile = cg::binary_partition(tile32, elem & 1);
if (elem & 1) // Odd numbers group
{
int oddGroupSum = cg::reduce(subTile, elem, cg::plus<int>());
if (subTile.thread_rank() == 0) if (subTile.thread_rank() == 0) {
{ // Add number of odds present in this group of Odds.
// Add number of odds present in this group of Odds. atomicAdd(numOfOdds, subTile.size());
atomicAdd(numOfOdds, subTile.size());
// Add local reduction of odds present in this group of Odds. // Add local reduction of odds present in this group of Odds.
atomicAdd(&sumOfOddAndEvens[0], oddGroupSum); atomicAdd(&sumOfOddAndEvens[0], oddGroupSum);
}
} else // Even numbers group
{
int evenGroupSum = cg::reduce(subTile, elem, cg::plus<int>());
} if (subTile.thread_rank() == 0) {
} // Add local reduction of even present in this group of evens.
else // Even numbers group atomicAdd(&sumOfOddAndEvens[1], evenGroupSum);
{ }
int evenGroupSum = cg::reduce(subTile, elem, cg::plus<int>());
if (subTile.thread_rank() == 0)
{
// Add local reduction of even present in this group of evens.
atomicAdd(&sumOfOddAndEvens[1], evenGroupSum);
}
}
// reconverge warp so for next loop iteration we ensure convergence of
// above diverged threads to perform coalesced loads of inputArr.
cg::sync(tile32);
} }
// reconverge warp so for next loop iteration we ensure convergence of
// above diverged threads to perform coalesced loads of inputArr.
cg::sync(tile32);
}
} }
/** /**
* Host main routine * Host main routine
*/ */
int main(int argc, const char **argv) int main(int argc, const char **argv) {
{ int deviceId = findCudaDevice(argc, argv);
int deviceId = findCudaDevice(argc, argv); int *h_inputArr, *d_inputArr;
int *h_inputArr, *d_inputArr; int *h_numOfOdds, *d_numOfOdds;
int *h_numOfOdds, *d_numOfOdds; int *h_sumOfOddEvenElems, *d_sumOfOddEvenElems;
int *h_sumOfOddEvenElems, *d_sumOfOddEvenElems; unsigned int arrSize = 1024 * 100;
unsigned int arrSize = 1024 * 100;
h_inputArr = new int[arrSize]; checkCudaErrors(cudaMallocHost(&h_inputArr, sizeof(int) * arrSize));
h_numOfOdds = new int[1]; checkCudaErrors(cudaMallocHost(&h_numOfOdds, sizeof(int)));
h_sumOfOddEvenElems = new int[2]; checkCudaErrors(cudaMallocHost(&h_sumOfOddEvenElems, sizeof(int) * 2));
initOddEvenArr(h_inputArr, arrSize); initOddEvenArr(h_inputArr, arrSize);
cudaStream_t stream; cudaStream_t stream;
checkCudaErrors(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking)); checkCudaErrors(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
checkCudaErrors(cudaMalloc(&d_inputArr, sizeof(int)*arrSize)); checkCudaErrors(cudaMalloc(&d_inputArr, sizeof(int) * arrSize));
checkCudaErrors(cudaMalloc(&d_numOfOdds, sizeof(int))); checkCudaErrors(cudaMalloc(&d_numOfOdds, sizeof(int)));
checkCudaErrors(cudaMalloc(&d_sumOfOddEvenElems, sizeof(int)*2)); checkCudaErrors(cudaMalloc(&d_sumOfOddEvenElems, sizeof(int) * 2));
checkCudaErrors(cudaMemcpyAsync(d_inputArr, h_inputArr, sizeof(int)*arrSize, cudaMemcpyHostToDevice, stream)); checkCudaErrors(cudaMemcpyAsync(d_inputArr, h_inputArr, sizeof(int) * arrSize,
checkCudaErrors(cudaMemsetAsync(d_numOfOdds, 0, sizeof(int), stream)); cudaMemcpyHostToDevice, stream));
checkCudaErrors(cudaMemsetAsync(d_sumOfOddEvenElems, 0, 2*sizeof(int), stream)); checkCudaErrors(cudaMemsetAsync(d_numOfOdds, 0, sizeof(int), stream));
checkCudaErrors(
cudaMemsetAsync(d_sumOfOddEvenElems, 0, 2 * sizeof(int), stream));
//Launch the kernel // Launch the kernel
int threadsPerBlock=1024; int threadsPerBlock = 0;
int blocksPerGrid = arrSize / threadsPerBlock; int blocksPerGrid = 0;
checkCudaErrors(cudaOccupancyMaxPotentialBlockSize(
&blocksPerGrid, &threadsPerBlock, oddEvenCountAndSumCG, 0, 0));
printf("\nLaunching %d blocks with %d threads...\n\n",blocksPerGrid, threadsPerBlock); printf("\nLaunching %d blocks with %d threads...\n\n", blocksPerGrid,
threadsPerBlock);
oddEvenCountAndSumCG<<<blocksPerGrid, threadsPerBlock, 0, stream>>>(d_inputArr, d_numOfOdds, d_sumOfOddEvenElems, arrSize); oddEvenCountAndSumCG<<<blocksPerGrid, threadsPerBlock, 0, stream>>>(
d_inputArr, d_numOfOdds, d_sumOfOddEvenElems, arrSize);
checkCudaErrors(cudaMemcpyAsync(h_numOfOdds, d_numOfOdds, sizeof(int), cudaMemcpyDeviceToHost, stream)); checkCudaErrors(cudaMemcpyAsync(h_numOfOdds, d_numOfOdds, sizeof(int),
checkCudaErrors(cudaMemcpyAsync(h_sumOfOddEvenElems, d_sumOfOddEvenElems, 2*sizeof(int), cudaMemcpyDeviceToHost, stream)); cudaMemcpyDeviceToHost, stream));
checkCudaErrors(cudaMemcpyAsync(h_sumOfOddEvenElems, d_sumOfOddEvenElems,
2 * sizeof(int), cudaMemcpyDeviceToHost,
stream));
checkCudaErrors(cudaStreamSynchronize(stream));
printf("Array size = %d Num of Odds = %d Sum of Odds = %d Sum of Evens %d\n", arrSize, h_numOfOdds[0], h_sumOfOddEvenElems[0], h_sumOfOddEvenElems[1]); printf("Array size = %d Num of Odds = %d Sum of Odds = %d Sum of Evens %d\n",
printf("\n...Done.\n\n"); arrSize, h_numOfOdds[0], h_sumOfOddEvenElems[0],
h_sumOfOddEvenElems[1]);
printf("\n...Done.\n\n");
delete[] h_inputArr; checkCudaErrors(cudaFreeHost(h_inputArr));
delete[] h_numOfOdds; checkCudaErrors(cudaFreeHost(h_numOfOdds));
delete[] h_sumOfOddEvenElems; checkCudaErrors(cudaFreeHost(h_sumOfOddEvenElems));
checkCudaErrors(cudaFree(d_inputArr)); checkCudaErrors(cudaFree(d_inputArr));
checkCudaErrors(cudaFree(d_numOfOdds)); checkCudaErrors(cudaFree(d_numOfOdds));
checkCudaErrors(cudaFree(d_sumOfOddEvenElems)); checkCudaErrors(cudaFree(d_sumOfOddEvenElems));
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -104,6 +104,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -27,7 +27,7 @@ x86_64, ppc64le, armv7l
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -118,6 +118,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -114,6 +114,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -27,7 +27,7 @@ x86_64, ppc64le, armv7l
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -118,6 +118,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -114,6 +114,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -0,0 +1,370 @@
################################################################################
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
################################################################################
#
# Makefile project only supported on Mac OS X and Linux Platforms)
#
################################################################################
# Location of the CUDA Toolkit
CUDA_PATH ?= /usr/local/cuda
##############################
# start deprecated interface #
##############################
ifeq ($(x86_64),1)
$(info WARNING - x86_64 variable has been deprecated)
$(info WARNING - please use TARGET_ARCH=x86_64 instead)
TARGET_ARCH ?= x86_64
endif
ifeq ($(ARMv7),1)
$(info WARNING - ARMv7 variable has been deprecated)
$(info WARNING - please use TARGET_ARCH=armv7l instead)
TARGET_ARCH ?= armv7l
endif
ifeq ($(aarch64),1)
$(info WARNING - aarch64 variable has been deprecated)
$(info WARNING - please use TARGET_ARCH=aarch64 instead)
TARGET_ARCH ?= aarch64
endif
ifeq ($(ppc64le),1)
$(info WARNING - ppc64le variable has been deprecated)
$(info WARNING - please use TARGET_ARCH=ppc64le instead)
TARGET_ARCH ?= ppc64le
endif
ifneq ($(GCC),)
$(info WARNING - GCC variable has been deprecated)
$(info WARNING - please use HOST_COMPILER=$(GCC) instead)
HOST_COMPILER ?= $(GCC)
endif
ifneq ($(abi),)
$(error ERROR - abi variable has been removed)
endif
############################
# end deprecated interface #
############################
# architecture
HOST_ARCH := $(shell uname -m)
TARGET_ARCH ?= $(HOST_ARCH)
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le armv7l))
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le))
TARGET_SIZE := 64
else ifneq (,$(filter $(TARGET_ARCH),armv7l))
TARGET_SIZE := 32
endif
else
TARGET_SIZE := $(shell getconf LONG_BIT)
endif
else
$(error ERROR - unsupported value $(TARGET_ARCH) for TARGET_ARCH!)
endif
# sbsa and aarch64 systems look similar. Need to differentiate them at host level for now.
ifeq ($(HOST_ARCH),aarch64)
ifeq ($(CUDA_PATH)/targets/sbsa-linux,$(shell ls -1d $(CUDA_PATH)/targets/sbsa-linux 2>/dev/null))
HOST_ARCH := sbsa
TARGET_ARCH := sbsa
endif
endif
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
ifeq (,$(filter $(HOST_ARCH)-$(TARGET_ARCH),aarch64-armv7l x86_64-armv7l x86_64-aarch64 x86_64-sbsa x86_64-ppc64le))
$(error ERROR - cross compiling from $(HOST_ARCH) to $(TARGET_ARCH) is not supported!)
endif
endif
# When on native aarch64 system with userspace of 32-bit, change TARGET_ARCH to armv7l
ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_SIZE),aarch64-aarch64-32)
TARGET_ARCH = armv7l
endif
# operating system
HOST_OS := $(shell uname -s 2>/dev/null | tr "[:upper:]" "[:lower:]")
TARGET_OS ?= $(HOST_OS)
ifeq (,$(filter $(TARGET_OS),linux darwin qnx android))
$(error ERROR - unsupported value $(TARGET_OS) for TARGET_OS!)
endif
# host compiler
ifeq ($(TARGET_OS),darwin)
ifeq ($(shell expr `xcodebuild -version | grep -i xcode | awk '{print $$2}' | cut -d'.' -f1` \>= 5),1)
HOST_COMPILER ?= clang++
endif
else ifneq ($(TARGET_ARCH),$(HOST_ARCH))
ifeq ($(HOST_ARCH)-$(TARGET_ARCH),x86_64-armv7l)
ifeq ($(TARGET_OS),linux)
HOST_COMPILER ?= arm-linux-gnueabihf-g++
else ifeq ($(TARGET_OS),qnx)
ifeq ($(QNX_HOST),)
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
endif
ifeq ($(QNX_TARGET),)
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
endif
export QNX_HOST
export QNX_TARGET
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/arm-unknown-nto-qnx6.6.0eabi-g++
else ifeq ($(TARGET_OS),android)
HOST_COMPILER ?= arm-linux-androideabi-g++
endif
else ifeq ($(TARGET_ARCH),aarch64)
ifeq ($(TARGET_OS), linux)
HOST_COMPILER ?= aarch64-linux-gnu-g++
else ifeq ($(TARGET_OS),qnx)
ifeq ($(QNX_HOST),)
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
endif
ifeq ($(QNX_TARGET),)
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
endif
export QNX_HOST
export QNX_TARGET
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/q++
else ifeq ($(TARGET_OS), android)
HOST_COMPILER ?= aarch64-linux-android-clang++
endif
else ifeq ($(TARGET_ARCH),sbsa)
HOST_COMPILER ?= aarch64-linux-gnu-g++
else ifeq ($(TARGET_ARCH),ppc64le)
HOST_COMPILER ?= powerpc64le-linux-gnu-g++
endif
endif
HOST_COMPILER ?= g++
NVCC := $(CUDA_PATH)/bin/nvcc -ccbin $(HOST_COMPILER)
# internal flags
NVCCFLAGS := -m${TARGET_SIZE}
CCFLAGS :=
LDFLAGS :=
# build flags
ifeq ($(TARGET_OS),darwin)
LDFLAGS += -rpath $(CUDA_PATH)/lib
CCFLAGS += -arch $(HOST_ARCH)
else ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_OS),x86_64-armv7l-linux)
LDFLAGS += --dynamic-linker=/lib/ld-linux-armhf.so.3
CCFLAGS += -mfloat-abi=hard
else ifeq ($(TARGET_OS),android)
LDFLAGS += -pie
CCFLAGS += -fpie -fpic -fexceptions
endif
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
ifneq ($(TARGET_FS),)
GCCVERSIONLTEQ46 := $(shell expr `$(HOST_COMPILER) -dumpversion` \<= 4.6)
ifeq ($(GCCVERSIONLTEQ46),1)
CCFLAGS += --sysroot=$(TARGET_FS)
endif
LDFLAGS += --sysroot=$(TARGET_FS)
LDFLAGS += -rpath-link=$(TARGET_FS)/lib
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/arm-linux-gnueabihf
endif
endif
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
ifneq ($(TARGET_FS),)
GCCVERSIONLTEQ46 := $(shell expr `$(HOST_COMPILER) -dumpversion` \<= 4.6)
ifeq ($(GCCVERSIONLTEQ46),1)
CCFLAGS += --sysroot=$(TARGET_FS)
endif
LDFLAGS += --sysroot=$(TARGET_FS)
LDFLAGS += -rpath-link=$(TARGET_FS)/lib -L$(TARGET_FS)/lib
LDFLAGS += -rpath-link=$(TARGET_FS)/lib/aarch64-linux-gnu -L$(TARGET_FS)/lib/aarch64-linux-gnu
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib -L$(TARGET_FS)/usr/lib
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/aarch64-linux-gnu -L$(TARGET_FS)/usr/lib/aarch64-linux-gnu
LDFLAGS += --unresolved-symbols=ignore-in-shared-libs
CCFLAGS += -isystem=$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include/libdrm
CCFLAGS += -isystem=$(TARGET_FS)/usr/include/aarch64-linux-gnu -I$(TARGET_FS)/usr/include/aarch64-linux-gnu
endif
endif
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
NVCCFLAGS += --qpp-config 5.4.0,gcc_ntoaarch64le
CCFLAGS += -DWIN_INTERFACE_CUSTOM -I/usr/include/aarch64-qnx-gnu
LDFLAGS += -lsocket
LDFLAGS += -L/usr/lib/aarch64-qnx-gnu
CCFLAGS += "-Wl\,-rpath-link\,/usr/lib/aarch64-qnx-gnu"
ifdef TARGET_OVERRIDE
LDFLAGS += -lslog2
endif
ifneq ($(TARGET_FS),)
LDFLAGS += -L$(TARGET_FS)/usr/lib
CCFLAGS += "-Wl\,-rpath-link\,$(TARGET_FS)/usr/lib"
LDFLAGS += -L$(TARGET_FS)/usr/libnvidia
CCFLAGS += "-Wl\,-rpath-link\,$(TARGET_FS)/usr/libnvidia"
CCFLAGS += -I$(TARGET_FS)/../include
endif
endif
endif
ifdef TARGET_OVERRIDE # cuda toolkit targets override
NVCCFLAGS += -target-dir $(TARGET_OVERRIDE)
endif
# Install directory of different arch
CUDA_INSTALL_TARGET_DIR :=
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-gnueabihf/
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux/
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),sbsa-linux)
CUDA_INSTALL_TARGET_DIR = targets/sbsa-linux/
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-android)
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-androideabi/
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-android)
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux-androideabi/
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-qnx)
CUDA_INSTALL_TARGET_DIR = targets/ARMv7-linux-QNX/
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
CUDA_INSTALL_TARGET_DIR = targets/aarch64-qnx/
else ifeq ($(TARGET_ARCH),ppc64le)
CUDA_INSTALL_TARGET_DIR = targets/ppc64le-linux/
endif
# Debug build flags
ifeq ($(dbg),1)
NVCCFLAGS += -g -G
BUILD_TYPE := debug
else
BUILD_TYPE := release
endif
ALL_CCFLAGS :=
ALL_CCFLAGS += $(NVCCFLAGS)
ALL_CCFLAGS += $(EXTRA_NVCCFLAGS)
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(CCFLAGS))
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(EXTRA_CCFLAGS))
SAMPLE_ENABLED := 1
# This sample is not supported on QNX
ifeq ($(TARGET_OS),qnx)
$(info >>> WARNING - cdpQuadtree is not supported on QNX - waiving sample <<<)
SAMPLE_ENABLED := 0
endif
ALL_LDFLAGS :=
ALL_LDFLAGS += $(ALL_CCFLAGS)
ALL_LDFLAGS += $(addprefix -Xlinker ,$(LDFLAGS))
ALL_LDFLAGS += $(addprefix -Xlinker ,$(EXTRA_LDFLAGS))
# Common includes and paths for CUDA
INCLUDES := -I../../Common
LIBRARIES :=
################################################################################
#Detect if installed version of GCC supports required C++14
ifeq ($(TARGET_OS),linux)
empty :=
space := $(empty) $(empty)
GCCVERSIONSTRING := $(shell expr `$(HOST_COMPILER) -dumpversion`)
#Create version number without "."
GCCVERSION := $(shell expr `echo $(GCCVERSIONSTRING)` | cut -f1 -d.)
GCCVERSION += $(shell expr `echo $(GCCVERSIONSTRING)` | cut -f2 -d.)
GCCVERSION += $(shell expr `echo $(GCCVERSIONSTRING)` | cut -f3 -d.)
# Make sure the version number has at least 3 decimals
GCCVERSION += 00
# Remove spaces from the version number
GCCVERSION := $(subst $(space),$(empty),$(GCCVERSION))
#$(warning $(GCCVERSION))
IS_MIN_VERSION := $(shell expr `echo $(GCCVERSION)` \>= 50000)
ifeq ($(IS_MIN_VERSION), 1)
$(info >>> GCC Version is greater or equal to 5.0.0 <<<)
else
$(info >>> Waiving build. Minimum GCC version required is 5.0.0<<<)
SAMPLE_ENABLED := 0
endif
endif
# Gencode arguments
ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),armv7l aarch64))
SMS ?= 35 37 50 52 60 61 70 72 75 80 86
else
SMS ?= 35 37 50 52 60 61 70 75 80 86
endif
ifeq ($(SMS),)
$(info >>> WARNING - no SM architectures have been specified - waiving sample <<<)
SAMPLE_ENABLED := 0
endif
ifeq ($(GENCODE_FLAGS),)
# Generate SASS code for each SM architecture listed in $(SMS)
$(foreach sm,$(SMS),$(eval GENCODE_FLAGS += -gencode arch=compute_$(sm),code=sm_$(sm)))
# Generate PTX code from the highest SM architecture in $(SMS) to guarantee forward-compatibility
HIGHEST_SM := $(lastword $(sort $(SMS)))
ifneq ($(HIGHEST_SM),)
GENCODE_FLAGS += -gencode arch=compute_$(HIGHEST_SM),code=compute_$(HIGHEST_SM)
endif
endif
ALL_CCFLAGS += -dc --std=c++14 --threads 0
LIBRARIES += -lcudadevrt
ifeq ($(SAMPLE_ENABLED),0)
EXEC ?= @echo "[@]"
endif
################################################################################
# Target rules
all: build
build: cdpQuadtree
check.deps:
ifeq ($(SAMPLE_ENABLED),0)
@echo "Sample will be waived due to the above missing dependencies"
else
@echo "Sample is ready - all dependencies have been met"
endif
cdpQuadtree.o:cdpQuadtree.cu
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
cdpQuadtree: cdpQuadtree.o
$(EXEC) $(NVCC) $(ALL_LDFLAGS) $(GENCODE_FLAGS) -o $@ $+ $(LIBRARIES)
$(EXEC) mkdir -p ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
$(EXEC) cp $@ ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
run: build
$(EXEC) ./cdpQuadtree
clean:
rm -f cdpQuadtree cdpQuadtree.o
rm -rf ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)/cdpQuadtree
clobber: clean

View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE entry SYSTEM "SamplesInfo.dtd">
<entry>
<name>cdpQuadtree</name>
<cflags>
<flag>-dc</flag>
<flag>--std=c++14</flag>
</cflags>
<description><![CDATA[This sample demonstrates Quad Trees implemented using CUDA Dynamic Parallelism. This sample requires devices with compute capability 3.5 or higher.]]></description>
<includepaths>
<path>./</path>
<path>../</path>
<path>../../common/inc</path>
</includepaths>
<keyconcepts>
<concept level="basic">Cooperative Groups</concept>
<concept level="advanced">CUDA Dynamic Parallelism</concept>
</keyconcepts>
<keywords>
<keyword>GPGPU</keyword>
<keyword>CPP14</keyword>
</keywords>
<libraries>
<library>cudadevrt</library>
</libraries>
<librarypaths>
</librarypaths>
<nsight_eclipse>true</nsight_eclipse>
<primary_file>cdpQuadTree.cu</primary_file>
<required_dependencies>
<dependency>CDP</dependency>
</required_dependencies>
<scopes>
<scope>1:CUDA Advanced Topics</scope>
</scopes>
<sm-arch>sm35</sm-arch>
<sm-arch>sm37</sm-arch>
<sm-arch>sm50</sm-arch>
<sm-arch>sm52</sm-arch>
<sm-arch>sm60</sm-arch>
<sm-arch>sm61</sm-arch>
<sm-arch>sm70</sm-arch>
<sm-arch>sm72</sm-arch>
<sm-arch>sm75</sm-arch>
<sm-arch>sm80</sm-arch>
<sm-arch>sm86</sm-arch>
<supported_envs>
<env>
<arch>x86_64</arch>
<platform>linux</platform>
</env>
<env>
<platform>windows7</platform>
</env>
<env>
<arch>x86_64</arch>
<platform>macosx</platform>
</env>
<env>
<arch>arm</arch>
</env>
<env>
<arch>ppc64le</arch>
<platform>linux</platform>
</env>
</supported_envs>
<supported_sm_architectures>
<from>3.5</from>
</supported_sm_architectures>
<title>Quad Tree (CUDA Dynamic Parallelism)</title>
<type>exe</type>
</entry>

View File

@@ -0,0 +1,71 @@
# cdpQuadtree - Quad Tree (CUDA Dynamic Parallelism)
## Description
This sample demonstrates Quad Trees implemented using CUDA Dynamic Parallelism. This sample requires devices with compute capability 3.5 or higher.
## Key Concepts
Cooperative Groups, CUDA Dynamic Parallelism
## Supported SM Architectures
[SM 3.5 ](https://developer.nvidia.com/cuda-gpus) [SM 3.7 ](https://developer.nvidia.com/cuda-gpus) [SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](https://developer.nvidia.com/cuda-gpus) [SM 6.0 ](https://developer.nvidia.com/cuda-gpus) [SM 6.1 ](https://developer.nvidia.com/cuda-gpus) [SM 7.0 ](https://developer.nvidia.com/cuda-gpus) [SM 7.2 ](https://developer.nvidia.com/cuda-gpus) [SM 7.5 ](https://developer.nvidia.com/cuda-gpus) [SM 8.0 ](https://developer.nvidia.com/cuda-gpus) [SM 8.6 ](https://developer.nvidia.com/cuda-gpus)
## Supported OSes
Linux, Windows
## Supported CPU Architecture
x86_64, ppc64le, armv7l
## CUDA APIs involved
## Dependencies needed to build/run
[CDP](../../README.md#cdp)
## Prerequisites
Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run
### Windows
The Windows samples are built using the Visual Studio IDE. Solution files (.sln) are provided for each supported version of Visual Studio, using the format:
```
*_vs<version>.sln - for Visual Studio <version>
```
Each individual sample has its own set of solution files in its directory:
To build/examine all the samples at once, the complete solution files should be used. To build/examine a single sample, the individual sample solution files should be used.
> **Note:** Some samples require that the Microsoft DirectX SDK (June 2010 or newer) be installed and that the VC++ directory paths are properly set up (**Tools > Options...**). Check DirectX Dependencies section for details."
### Linux
The Linux samples are built using makefiles. To use the makefiles, change the current directory to the sample directory you wish to build, and run make:
```
$ cd <sample_dir>
$ make
```
The samples makefiles can take advantage of certain options:
* **TARGET_ARCH=<arch>** - cross-compile targeting a specific architecture. Allowed architectures are x86_64, ppc64le, armv7l.
By default, TARGET_ARCH is set to HOST_ARCH. On a x86_64 machine, not setting TARGET_ARCH is the equivalent of setting TARGET_ARCH=x86_64.<br/>
`$ make TARGET_ARCH=x86_64` <br/> `$ make TARGET_ARCH=ppc64le` <br/> `$ make TARGET_ARCH=armv7l` <br/>
See [here](http://docs.nvidia.com/cuda/cuda-samples/index.html#cross-samples) for more details.
* **dbg=1** - build with debug symbols
```
$ make dbg=1
```
* **SMS="A B ..."** - override the SM architectures for which the sample will be built, where `"A B ..."` is a space-delimited list of SM architectures. For example, to generate SASS for SM 50 and SM 60, use `SMS="50 60"`.
```
$ make SMS="50 60"
```
* **HOST_COMPILER=<host_compiler>** - override the default g++ host compiler. See the [Linux Installation Guide](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#system-requirements) for a list of supported host compilers.
```
$ make HOST_COMPILER=g++
```
## References (for more details)

View File

@@ -0,0 +1,742 @@
/* Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <thrust/random.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <cooperative_groups.h>
namespace cg = cooperative_groups;
#include <helper_cuda.h>
////////////////////////////////////////////////////////////////////////////////
// A structure of 2D points (structure of arrays).
////////////////////////////////////////////////////////////////////////////////
class Points {
float *m_x;
float *m_y;
public:
// Constructor.
__host__ __device__ Points() : m_x(NULL), m_y(NULL) {}
// Constructor.
__host__ __device__ Points(float *x, float *y) : m_x(x), m_y(y) {}
// Get a point.
__host__ __device__ __forceinline__ float2 get_point(int idx) const {
return make_float2(m_x[idx], m_y[idx]);
}
// Set a point.
__host__ __device__ __forceinline__ void set_point(int idx, const float2 &p) {
m_x[idx] = p.x;
m_y[idx] = p.y;
}
// Set the pointers.
__host__ __device__ __forceinline__ void set(float *x, float *y) {
m_x = x;
m_y = y;
}
};
////////////////////////////////////////////////////////////////////////////////
// A 2D bounding box
////////////////////////////////////////////////////////////////////////////////
class Bounding_box {
// Extreme points of the bounding box.
float2 m_p_min;
float2 m_p_max;
public:
// Constructor. Create a unit box.
__host__ __device__ Bounding_box() {
m_p_min = make_float2(0.0f, 0.0f);
m_p_max = make_float2(1.0f, 1.0f);
}
// Compute the center of the bounding-box.
__host__ __device__ void compute_center(float2 &center) const {
center.x = 0.5f * (m_p_min.x + m_p_max.x);
center.y = 0.5f * (m_p_min.y + m_p_max.y);
}
// The points of the box.
__host__ __device__ __forceinline__ const float2 &get_max() const {
return m_p_max;
}
__host__ __device__ __forceinline__ const float2 &get_min() const {
return m_p_min;
}
// Does a box contain a point.
__host__ __device__ bool contains(const float2 &p) const {
return p.x >= m_p_min.x && p.x < m_p_max.x && p.y >= m_p_min.y &&
p.y < m_p_max.y;
}
// Define the bounding box.
__host__ __device__ void set(float min_x, float min_y, float max_x,
float max_y) {
m_p_min.x = min_x;
m_p_min.y = min_y;
m_p_max.x = max_x;
m_p_max.y = max_y;
}
};
////////////////////////////////////////////////////////////////////////////////
// A node of a quadree.
////////////////////////////////////////////////////////////////////////////////
class Quadtree_node {
// The identifier of the node.
int m_id;
// The bounding box of the tree.
Bounding_box m_bounding_box;
// The range of points.
int m_begin, m_end;
public:
// Constructor.
__host__ __device__ Quadtree_node() : m_id(0), m_begin(0), m_end(0) {}
// The ID of a node at its level.
__host__ __device__ int id() const { return m_id; }
// The ID of a node at its level.
__host__ __device__ void set_id(int new_id) { m_id = new_id; }
// The bounding box.
__host__ __device__ __forceinline__ const Bounding_box &bounding_box() const {
return m_bounding_box;
}
// Set the bounding box.
__host__ __device__ __forceinline__ void set_bounding_box(float min_x,
float min_y,
float max_x,
float max_y) {
m_bounding_box.set(min_x, min_y, max_x, max_y);
}
// The number of points in the tree.
__host__ __device__ __forceinline__ int num_points() const {
return m_end - m_begin;
}
// The range of points in the tree.
__host__ __device__ __forceinline__ int points_begin() const {
return m_begin;
}
__host__ __device__ __forceinline__ int points_end() const { return m_end; }
// Define the range for that node.
__host__ __device__ __forceinline__ void set_range(int begin, int end) {
m_begin = begin;
m_end = end;
}
};
////////////////////////////////////////////////////////////////////////////////
// Algorithm parameters.
////////////////////////////////////////////////////////////////////////////////
struct Parameters {
// Choose the right set of points to use as in/out.
int point_selector;
// The number of nodes at a given level (2^k for level k).
int num_nodes_at_this_level;
// The recursion depth.
int depth;
// The max value for depth.
const int max_depth;
// The minimum number of points in a node to stop recursion.
const int min_points_per_node;
// Constructor set to default values.
__host__ __device__ Parameters(int max_depth, int min_points_per_node)
: point_selector(0),
num_nodes_at_this_level(1),
depth(0),
max_depth(max_depth),
min_points_per_node(min_points_per_node) {}
// Copy constructor. Changes the values for next iteration.
__host__ __device__ Parameters(const Parameters &params, bool)
: point_selector((params.point_selector + 1) % 2),
num_nodes_at_this_level(4 * params.num_nodes_at_this_level),
depth(params.depth + 1),
max_depth(params.max_depth),
min_points_per_node(params.min_points_per_node) {}
};
////////////////////////////////////////////////////////////////////////////////
// Build a quadtree on the GPU. Use CUDA Dynamic Parallelism.
//
// The algorithm works as follows. The host (CPU) launches one block of
// NUM_THREADS_PER_BLOCK threads. That block will do the following steps:
//
// 1- Check the number of points and its depth.
//
// We impose a maximum depth to the tree and a minimum number of points per
// node. If the maximum depth is exceeded or the minimum number of points is
// reached. The threads in the block exit.
//
// Before exiting, they perform a buffer swap if it is needed. Indeed, the
// algorithm uses two buffers to permute the points and make sure they are
// properly distributed in the quadtree. By design we want all points to be
// in the first buffer of points at the end of the algorithm. It is the reason
// why we may have to swap the buffer before leavin (if the points are in the
// 2nd buffer).
//
// 2- Count the number of points in each child.
//
// If the depth is not too high and the number of points is sufficient, the
// block has to dispatch the points into four geometrical buckets: Its
// children. For that purpose, we compute the center of the bounding box and
// count the number of points in each quadrant.
//
// The set of points is divided into sections. Each section is given to a
// warp of threads (32 threads). Warps use __ballot and __popc intrinsics
// to count the points. See the Programming Guide for more information about
// those functions.
//
// 3- Scan the warps' results to know the "global" numbers.
//
// Warps work independently from each other. At the end, each warp knows the
// number of points in its section. To know the numbers for the block, the
// block has to run a scan/reduce at the block level. It's a traditional
// approach. The implementation in that sample is not as optimized as what
// could be found in fast radix sorts, for example, but it relies on the same
// idea.
//
// 4- Move points.
//
// Now that the block knows how many points go in each of its 4 children, it
// remains to dispatch the points. It is straightforward.
//
// 5- Launch new blocks.
//
// The block launches four new blocks: One per children. Each of the four blocks
// will apply the same algorithm.
////////////////////////////////////////////////////////////////////////////////
template <int NUM_THREADS_PER_BLOCK>
__global__ void build_quadtree_kernel(Quadtree_node *nodes, Points *points,
Parameters params) {
// Handle to thread block group
cg::thread_block cta = cg::this_thread_block();
// The number of warps in a block.
const int NUM_WARPS_PER_BLOCK = NUM_THREADS_PER_BLOCK / warpSize;
// Shared memory to store the number of points.
extern __shared__ int smem[];
// s_num_pts[4][NUM_WARPS_PER_BLOCK];
// Addresses of shared memory.
volatile int *s_num_pts[4];
for (int i = 0; i < 4; ++i)
s_num_pts[i] = (volatile int *)&smem[i * NUM_WARPS_PER_BLOCK];
// Compute the coordinates of the threads in the block.
const int warp_id = threadIdx.x / warpSize;
const int lane_id = threadIdx.x % warpSize;
// Mask for compaction.
// Same as: asm( "mov.u32 %0, %%lanemask_lt;" : "=r"(lane_mask_lt) );
int lane_mask_lt = (1 << lane_id) - 1;
// The current node.
Quadtree_node &node = nodes[blockIdx.x];
// The number of points in the node.
int num_points = node.num_points();
float2 center;
int range_begin, range_end;
int warp_cnts[4] = {0, 0, 0, 0};
//
// 1- Check the number of points and its depth.
//
// Stop the recursion here. Make sure points[0] contains all the points.
if (params.depth >= params.max_depth ||
num_points <= params.min_points_per_node) {
if (params.point_selector == 1) {
int it = node.points_begin(), end = node.points_end();
for (it += threadIdx.x; it < end; it += NUM_THREADS_PER_BLOCK)
if (it < end) points[0].set_point(it, points[1].get_point(it));
}
return;
}
// Compute the center of the bounding box of the points.
const Bounding_box &bbox = node.bounding_box();
bbox.compute_center(center);
// Find how many points to give to each warp.
int num_points_per_warp = max(
warpSize, (num_points + NUM_WARPS_PER_BLOCK - 1) / NUM_WARPS_PER_BLOCK);
// Each warp of threads will compute the number of points to move to each
// quadrant.
range_begin = node.points_begin() + warp_id * num_points_per_warp;
range_end = min(range_begin + num_points_per_warp, node.points_end());
//
// 2- Count the number of points in each child.
//
// Input points.
const Points &in_points = points[params.point_selector];
cg::thread_block_tile<32> tile32 = cg::tiled_partition<32>(cta);
// Compute the number of points.
for (int range_it = range_begin + tile32.thread_rank();
tile32.any(range_it < range_end); range_it += warpSize) {
// Is it still an active thread?
bool is_active = range_it < range_end;
// Load the coordinates of the point.
float2 p =
is_active ? in_points.get_point(range_it) : make_float2(0.0f, 0.0f);
// Count top-left points.
int num_pts =
__popc(tile32.ballot(is_active && p.x < center.x && p.y >= center.y));
warp_cnts[0] += tile32.shfl(num_pts, 0);
// Count top-right points.
num_pts =
__popc(tile32.ballot(is_active && p.x >= center.x && p.y >= center.y));
warp_cnts[1] += tile32.shfl(num_pts, 0);
// Count bottom-left points.
num_pts =
__popc(tile32.ballot(is_active && p.x < center.x && p.y < center.y));
warp_cnts[2] += tile32.shfl(num_pts, 0);
// Count bottom-right points.
num_pts =
__popc(tile32.ballot(is_active && p.x >= center.x && p.y < center.y));
warp_cnts[3] += tile32.shfl(num_pts, 0);
}
if (tile32.thread_rank() == 0) {
s_num_pts[0][warp_id] = warp_cnts[0];
s_num_pts[1][warp_id] = warp_cnts[1];
s_num_pts[2][warp_id] = warp_cnts[2];
s_num_pts[3][warp_id] = warp_cnts[3];
}
// Make sure warps have finished counting.
cg::sync(cta);
//
// 3- Scan the warps' results to know the "global" numbers.
//
// First 4 warps scan the numbers of points per child (inclusive scan).
if (warp_id < 4) {
int num_pts = tile32.thread_rank() < NUM_WARPS_PER_BLOCK
? s_num_pts[warp_id][tile32.thread_rank()]
: 0;
#pragma unroll
for (int offset = 1; offset < NUM_WARPS_PER_BLOCK; offset *= 2) {
int n = tile32.shfl_up(num_pts, offset);
if (tile32.thread_rank() >= offset) num_pts += n;
}
if (tile32.thread_rank() < NUM_WARPS_PER_BLOCK)
s_num_pts[warp_id][tile32.thread_rank()] = num_pts;
}
cg::sync(cta);
// Compute global offsets.
if (warp_id == 0) {
int sum = s_num_pts[0][NUM_WARPS_PER_BLOCK - 1];
for (int row = 1; row < 4; ++row) {
int tmp = s_num_pts[row][NUM_WARPS_PER_BLOCK - 1];
cg::sync(tile32);
if (tile32.thread_rank() < NUM_WARPS_PER_BLOCK)
s_num_pts[row][tile32.thread_rank()] += sum;
cg::sync(tile32);
sum += tmp;
}
}
cg::sync(cta);
// Make the scan exclusive.
int val = 0;
if (threadIdx.x < 4 * NUM_WARPS_PER_BLOCK) {
val = threadIdx.x == 0 ? 0 : smem[threadIdx.x - 1];
val += node.points_begin();
}
cg::sync(cta);
if (threadIdx.x < 4 * NUM_WARPS_PER_BLOCK) {
smem[threadIdx.x] = val;
}
cg::sync(cta);
//
// 4- Move points.
//
if (!(params.depth >= params.max_depth ||
num_points <= params.min_points_per_node)) {
// Output points.
Points &out_points = points[(params.point_selector + 1) % 2];
warp_cnts[0] = s_num_pts[0][warp_id];
warp_cnts[1] = s_num_pts[1][warp_id];
warp_cnts[2] = s_num_pts[2][warp_id];
warp_cnts[3] = s_num_pts[3][warp_id];
const Points &in_points = points[params.point_selector];
// Reorder points.
for (int range_it = range_begin + tile32.thread_rank();
tile32.any(range_it < range_end); range_it += warpSize) {
// Is it still an active thread?
bool is_active = range_it < range_end;
// Load the coordinates of the point.
float2 p =
is_active ? in_points.get_point(range_it) : make_float2(0.0f, 0.0f);
// Count top-left points.
bool pred = is_active && p.x < center.x && p.y >= center.y;
int vote = tile32.ballot(pred);
int dest = warp_cnts[0] + __popc(vote & lane_mask_lt);
if (pred) out_points.set_point(dest, p);
warp_cnts[0] += tile32.shfl(__popc(vote), 0);
// Count top-right points.
pred = is_active && p.x >= center.x && p.y >= center.y;
vote = tile32.ballot(pred);
dest = warp_cnts[1] + __popc(vote & lane_mask_lt);
if (pred) out_points.set_point(dest, p);
warp_cnts[1] += tile32.shfl(__popc(vote), 0);
// Count bottom-left points.
pred = is_active && p.x < center.x && p.y < center.y;
vote = tile32.ballot(pred);
dest = warp_cnts[2] + __popc(vote & lane_mask_lt);
if (pred) out_points.set_point(dest, p);
warp_cnts[2] += tile32.shfl(__popc(vote), 0);
// Count bottom-right points.
pred = is_active && p.x >= center.x && p.y < center.y;
vote = tile32.ballot(pred);
dest = warp_cnts[3] + __popc(vote & lane_mask_lt);
if (pred) out_points.set_point(dest, p);
warp_cnts[3] += tile32.shfl(__popc(vote), 0);
}
}
cg::sync(cta);
if (tile32.thread_rank() == 0) {
s_num_pts[0][warp_id] = warp_cnts[0];
s_num_pts[1][warp_id] = warp_cnts[1];
s_num_pts[2][warp_id] = warp_cnts[2];
s_num_pts[3][warp_id] = warp_cnts[3];
}
cg::sync(cta);
//
// 5- Launch new blocks.
//
if (!(params.depth >= params.max_depth ||
num_points <= params.min_points_per_node)) {
// The last thread launches new blocks.
if (threadIdx.x == NUM_THREADS_PER_BLOCK - 1) {
// The children.
Quadtree_node *children =
&nodes[params.num_nodes_at_this_level - (node.id() & ~3)];
// The offsets of the children at their level.
int child_offset = 4 * node.id();
// Set IDs.
children[child_offset + 0].set_id(4 * node.id() + 0);
children[child_offset + 1].set_id(4 * node.id() + 1);
children[child_offset + 2].set_id(4 * node.id() + 2);
children[child_offset + 3].set_id(4 * node.id() + 3);
const Bounding_box &bbox = node.bounding_box();
// Points of the bounding-box.
const float2 &p_min = bbox.get_min();
const float2 &p_max = bbox.get_max();
// Set the bounding boxes of the children.
children[child_offset + 0].set_bounding_box(p_min.x, center.y, center.x,
p_max.y); // Top-left.
children[child_offset + 1].set_bounding_box(center.x, center.y, p_max.x,
p_max.y); // Top-right.
children[child_offset + 2].set_bounding_box(p_min.x, p_min.y, center.x,
center.y); // Bottom-left.
children[child_offset + 3].set_bounding_box(center.x, p_min.y, p_max.x,
center.y); // Bottom-right.
// Set the ranges of the children.
children[child_offset + 0].set_range(node.points_begin(),
s_num_pts[0][warp_id]);
children[child_offset + 1].set_range(s_num_pts[0][warp_id],
s_num_pts[1][warp_id]);
children[child_offset + 2].set_range(s_num_pts[1][warp_id],
s_num_pts[2][warp_id]);
children[child_offset + 3].set_range(s_num_pts[2][warp_id],
s_num_pts[3][warp_id]);
// Launch 4 children.
build_quadtree_kernel<NUM_THREADS_PER_BLOCK><<<
4, NUM_THREADS_PER_BLOCK, 4 * NUM_WARPS_PER_BLOCK * sizeof(int)>>>(
&children[child_offset], points, Parameters(params, true));
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Make sure a Quadtree is properly defined.
////////////////////////////////////////////////////////////////////////////////
bool check_quadtree(const Quadtree_node *nodes, int idx, int num_pts,
Points *pts, Parameters params) {
const Quadtree_node &node = nodes[idx];
int num_points = node.num_points();
if (!(params.depth == params.max_depth ||
num_points <= params.min_points_per_node)) {
int num_points_in_children = 0;
num_points_in_children +=
nodes[params.num_nodes_at_this_level + 4 * idx + 0].num_points();
num_points_in_children +=
nodes[params.num_nodes_at_this_level + 4 * idx + 1].num_points();
num_points_in_children +=
nodes[params.num_nodes_at_this_level + 4 * idx + 2].num_points();
num_points_in_children +=
nodes[params.num_nodes_at_this_level + 4 * idx + 3].num_points();
if (num_points_in_children != node.num_points()) return false;
return check_quadtree(&nodes[params.num_nodes_at_this_level], 4 * idx + 0,
num_pts, pts, Parameters(params, true)) &&
check_quadtree(&nodes[params.num_nodes_at_this_level], 4 * idx + 1,
num_pts, pts, Parameters(params, true)) &&
check_quadtree(&nodes[params.num_nodes_at_this_level], 4 * idx + 2,
num_pts, pts, Parameters(params, true)) &&
check_quadtree(&nodes[params.num_nodes_at_this_level], 4 * idx + 3,
num_pts, pts, Parameters(params, true));
}
const Bounding_box &bbox = node.bounding_box();
for (int it = node.points_begin(); it < node.points_end(); ++it) {
if (it >= num_pts) return false;
float2 p = pts->get_point(it);
if (!bbox.contains(p)) return false;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
// Parallel random number generator.
////////////////////////////////////////////////////////////////////////////////
struct Random_generator {
int count;
__host__ __device__ Random_generator() : count(0) {}
__host__ __device__ unsigned int hash(unsigned int a) {
a = (a + 0x7ed55d16) + (a << 12);
a = (a ^ 0xc761c23c) ^ (a >> 19);
a = (a + 0x165667b1) + (a << 5);
a = (a + 0xd3a2646c) ^ (a << 9);
a = (a + 0xfd7046c5) + (a << 3);
a = (a ^ 0xb55a4f09) ^ (a >> 16);
return a;
}
__host__ __device__ __forceinline__ thrust::tuple<float, float> operator()() {
#ifdef __CUDA_ARCH__
unsigned seed = hash(blockIdx.x * blockDim.x + threadIdx.x + count);
// thrust::generate may call operator() more than once per thread.
// Hence, increment count by grid size to ensure uniqueness of seed
count += blockDim.x * gridDim.x;
#else
unsigned seed = hash(0);
#endif
thrust::default_random_engine rng(seed);
thrust::random::uniform_real_distribution<float> distrib;
return thrust::make_tuple(distrib(rng), distrib(rng));
}
};
////////////////////////////////////////////////////////////////////////////////
// Allocate GPU structs, launch kernel and clean up
////////////////////////////////////////////////////////////////////////////////
bool cdpQuadtree(int warp_size) {
// Constants to control the algorithm.
const int num_points = 1024;
const int max_depth = 8;
const int min_points_per_node = 16;
// Allocate memory for points.
thrust::device_vector<float> x_d0(num_points);
thrust::device_vector<float> x_d1(num_points);
thrust::device_vector<float> y_d0(num_points);
thrust::device_vector<float> y_d1(num_points);
// Generate random points.
Random_generator rnd;
thrust::generate(
thrust::make_zip_iterator(thrust::make_tuple(x_d0.begin(), y_d0.begin())),
thrust::make_zip_iterator(thrust::make_tuple(x_d0.end(), y_d0.end())),
rnd);
// Host structures to analyze the device ones.
Points points_init[2];
points_init[0].set(thrust::raw_pointer_cast(&x_d0[0]),
thrust::raw_pointer_cast(&y_d0[0]));
points_init[1].set(thrust::raw_pointer_cast(&x_d1[0]),
thrust::raw_pointer_cast(&y_d1[0]));
// Allocate memory to store points.
Points *points;
checkCudaErrors(cudaMalloc((void **)&points, 2 * sizeof(Points)));
checkCudaErrors(cudaMemcpy(points, points_init, 2 * sizeof(Points),
cudaMemcpyHostToDevice));
// We could use a close form...
int max_nodes = 0;
for (int i = 0, num_nodes_at_level = 1; i < max_depth;
++i, num_nodes_at_level *= 4)
max_nodes += num_nodes_at_level;
// Allocate memory to store the tree.
Quadtree_node root;
root.set_range(0, num_points);
Quadtree_node *nodes;
checkCudaErrors(
cudaMalloc((void **)&nodes, max_nodes * sizeof(Quadtree_node)));
checkCudaErrors(
cudaMemcpy(nodes, &root, sizeof(Quadtree_node), cudaMemcpyHostToDevice));
// We set the recursion limit for CDP to max_depth.
cudaDeviceSetLimit(cudaLimitDevRuntimeSyncDepth, max_depth);
// Build the quadtree.
Parameters params(max_depth, min_points_per_node);
std::cout << "Launching CDP kernel to build the quadtree" << std::endl;
const int NUM_THREADS_PER_BLOCK = 128; // Do not use less than 128 threads.
const int NUM_WARPS_PER_BLOCK = NUM_THREADS_PER_BLOCK / warp_size;
const size_t smem_size = 4 * NUM_WARPS_PER_BLOCK * sizeof(int);
build_quadtree_kernel<
NUM_THREADS_PER_BLOCK><<<1, NUM_THREADS_PER_BLOCK, smem_size>>>(
nodes, points, params);
checkCudaErrors(cudaGetLastError());
// Copy points to CPU.
thrust::host_vector<float> x_h(x_d0);
thrust::host_vector<float> y_h(y_d0);
Points host_points;
host_points.set(thrust::raw_pointer_cast(&x_h[0]),
thrust::raw_pointer_cast(&y_h[0]));
// Copy nodes to CPU.
Quadtree_node *host_nodes = new Quadtree_node[max_nodes];
checkCudaErrors(cudaMemcpy(host_nodes, nodes,
max_nodes * sizeof(Quadtree_node),
cudaMemcpyDeviceToHost));
// Validate the results.
bool ok = check_quadtree(host_nodes, 0, num_points, &host_points, params);
std::cout << "Results: " << (ok ? "OK" : "FAILED") << std::endl;
// Free CPU memory.
delete[] host_nodes;
// Free memory.
checkCudaErrors(cudaFree(nodes));
checkCudaErrors(cudaFree(points));
return ok;
}
////////////////////////////////////////////////////////////////////////////////
// Main entry point.
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv) {
// Find/set the device.
// The test requires an architecture SM35 or greater (CDP capable).
int cuda_device = findCudaDevice(argc, (const char **)argv);
cudaDeviceProp deviceProps;
checkCudaErrors(cudaGetDeviceProperties(&deviceProps, cuda_device));
int cdpCapable = (deviceProps.major == 3 && deviceProps.minor >= 5) ||
deviceProps.major >= 4;
printf("GPU device %s has compute capabilities (SM %d.%d)\n",
deviceProps.name, deviceProps.major, deviceProps.minor);
if (!cdpCapable) {
std::cerr << "cdpQuadTree requires SM 3.5 or higher to use CUDA Dynamic "
"Parallelism. Exiting...\n"
<< std::endl;
exit(EXIT_WAIVED);
}
bool ok = cdpQuadtree(deviceProps.warpSize);
return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}

View File

@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2017
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cdpQuadtree", "cdpQuadtree_vs2017.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
<RootNamespace>cdpQuadtree_vs2017</RootNamespace>
<ProjectName>cdpQuadtree</ProjectName>
<CudaToolkitCustomDir />
</PropertyGroup>
<PropertyGroup Condition="'$(WindowsTargetPlatformVersion)'==''">
<LatestTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</LatestTargetPlatformVersion>
<WindowsTargetPlatformVersion Condition="'$(WindowsTargetPlatformVersion)' == ''">$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>
<TargetPlatformVersion>$(WindowsTargetPlatformVersion)</TargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup>
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<IntDir>$(Platform)/$(Configuration)/</IntDir>
<IncludePath>$(IncludePath)</IncludePath>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules />
<CodeAnalysisRuleAssemblies />
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='x64'">
<OutDir>../../bin/win64/$(Configuration)/</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>./;$(CudaToolkitDir)/include;../../Common;$(CudaToolkitIncludeDir);</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>cudadevrt.lib;cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(CudaToolkitLibDir);</AdditionalLibraryDirectories>
<OutputFile>$(OutDir)/cdpQuadtree.exe</OutputFile>
</Link>
<CudaCompile>
<CodeGeneration>compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75;compute_80,sm_80;compute_86,sm_86;</CodeGeneration>
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
<Include>./;../../Common</Include>
<Defines>WIN32</Defines>
<GenerateRelocatableDeviceCode>true</GenerateRelocatableDeviceCode>
<AdditionalOptions>--threads 0</AdditionalOptions>
</CudaCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
</Link>
<CudaCompile>
<Runtime>MTd</Runtime>
<TargetMachinePlatform>64</TargetMachinePlatform>
</CudaCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
<CudaCompile>
<Runtime>MT</Runtime>
<TargetMachinePlatform>64</TargetMachinePlatform>
</CudaCompile>
</ItemDefinitionGroup>
<ItemGroup>
<CudaCompile Include="cdpQuadtree.cu" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup>
</Project>

View File

@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2019
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cdpQuadtree", "cdpQuadtree_vs2019.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
<RootNamespace>cdpQuadtree_vs2019</RootNamespace>
<ProjectName>cdpQuadtree</ProjectName>
<CudaToolkitCustomDir />
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup>
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<IntDir>$(Platform)/$(Configuration)/</IntDir>
<IncludePath>$(IncludePath)</IncludePath>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules />
<CodeAnalysisRuleAssemblies />
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='x64'">
<OutDir>../../bin/win64/$(Configuration)/</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>./;$(CudaToolkitDir)/include;../../Common;$(CudaToolkitIncludeDir);</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>cudadevrt.lib;cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(CudaToolkitLibDir);</AdditionalLibraryDirectories>
<OutputFile>$(OutDir)/cdpQuadtree.exe</OutputFile>
</Link>
<CudaCompile>
<CodeGeneration>compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75;compute_80,sm_80;compute_86,sm_86;</CodeGeneration>
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
<Include>./;../../Common</Include>
<Defines>WIN32</Defines>
<GenerateRelocatableDeviceCode>true</GenerateRelocatableDeviceCode>
<AdditionalOptions>--threads 0</AdditionalOptions>
</CudaCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
</Link>
<CudaCompile>
<Runtime>MTd</Runtime>
<TargetMachinePlatform>64</TargetMachinePlatform>
</CudaCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
<CudaCompile>
<Runtime>MT</Runtime>
<TargetMachinePlatform>64</TargetMachinePlatform>
</CudaCompile>
</ItemDefinitionGroup>
<ItemGroup>
<CudaCompile Include="cdpQuadtree.cu" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup>
</Project>

View File

@@ -24,7 +24,7 @@ x86_64, ppc64le, armv7l
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -104,6 +104,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -30,7 +30,7 @@ cudaStreamBeginCapture, cudaStreamEndCapture, cudaGraphCreate, cudaGraphLaunch,
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -25,7 +25,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* /*
* This sample implements a conjugate gradient solver on GPU * This sample implements a conjugate gradient solver on GPU
* using CUBLAS and CUSPARSE with CUDA Graphs * using CUBLAS and CUSPARSE with CUDA Graphs
@@ -46,7 +45,6 @@
#include <helper_cuda.h> // helper function CUDA error checking and initialization #include <helper_cuda.h> // helper function CUDA error checking and initialization
#include <helper_functions.h> // helper for shared functions common to CUDA Samples #include <helper_functions.h> // helper for shared functions common to CUDA Samples
const char *sSDKname = "conjugateGradientCudaGraphs"; const char *sSDKname = "conjugateGradientCudaGraphs";
#ifndef WITH_GRAPH #ifndef WITH_GRAPH
@@ -145,12 +143,12 @@ int main(int argc, char **argv) {
/* Generate a random tridiagonal symmetric matrix in CSR format */ /* Generate a random tridiagonal symmetric matrix in CSR format */
N = 1048576; N = 1048576;
nz = (N - 2) * 3 + 4; nz = (N - 2) * 3 + 4;
I = (int *)malloc(sizeof(int) * (N + 1)); checkCudaErrors(cudaMallocHost(&I, sizeof(int) * (N + 1)));
J = (int *)malloc(sizeof(int) * nz); checkCudaErrors(cudaMallocHost(&J, sizeof(int) * nz));
val = (float *)malloc(sizeof(float) * nz); checkCudaErrors(cudaMallocHost(&val, sizeof(float) * nz));
genTridiag(I, J, val, N, nz); genTridiag(I, J, val, N, nz);
x = (float *)malloc(sizeof(float) * N); checkCudaErrors(cudaMallocHost(&x, sizeof(float) * N));
rhs = (float *)malloc(sizeof(float) * N); rhs = (float *)malloc(sizeof(float) * N);
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
@@ -192,9 +190,9 @@ int main(int argc, char **argv) {
/* Wrap raw data into cuSPARSE generic API objects */ /* Wrap raw data into cuSPARSE generic API objects */
cusparseSpMatDescr_t matA = NULL; cusparseSpMatDescr_t matA = NULL;
checkCudaErrors(cusparseCreateCsr( checkCudaErrors(cusparseCreateCsr(&matA, N, N, nz, d_row, d_col, d_val,
&matA, N, N, nz, d_row, d_col, d_val, CUSPARSE_INDEX_32I, CUSPARSE_INDEX_32I, CUSPARSE_INDEX_32I,
CUSPARSE_INDEX_32I, CUSPARSE_INDEX_BASE_ZERO, CUDA_R_32F)); CUSPARSE_INDEX_BASE_ZERO, CUDA_R_32F));
cusparseDnVecDescr_t vecx = NULL; cusparseDnVecDescr_t vecx = NULL;
checkCudaErrors(cusparseCreateDnVec(&vecx, N, d_x, CUDA_R_32F)); checkCudaErrors(cusparseCreateDnVec(&vecx, N, d_x, CUDA_R_32F));
cusparseDnVecDescr_t vecp = NULL; cusparseDnVecDescr_t vecp = NULL;
@@ -206,7 +204,7 @@ int main(int argc, char **argv) {
size_t bufferSize = 0; size_t bufferSize = 0;
checkCudaErrors(cusparseSpMV_bufferSize( checkCudaErrors(cusparseSpMV_bufferSize(
cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, &alpha, matA, vecx, cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, &alpha, matA, vecx,
&beta, vecAx, CUDA_R_32F, CUSPARSE_MV_ALG_DEFAULT, &bufferSize)); &beta, vecAx, CUDA_R_32F, CUSPARSE_SPMV_ALG_DEFAULT, &bufferSize));
void *buffer = NULL; void *buffer = NULL;
checkCudaErrors(cudaMalloc(&buffer, bufferSize)); checkCudaErrors(cudaMalloc(&buffer, bufferSize));
@@ -234,9 +232,9 @@ int main(int argc, char **argv) {
beta = 0.0; beta = 0.0;
checkCudaErrors(cusparseSetStream(cusparseHandle, stream1)); checkCudaErrors(cusparseSetStream(cusparseHandle, stream1));
checkCudaErrors(cusparseSpMV( checkCudaErrors(cusparseSpMV(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE,
cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, &alpha, matA, vecx, &alpha, matA, vecx, &beta, vecAx, CUDA_R_32F,
&beta, vecAx, CUDA_R_32F, CUSPARSE_MV_ALG_DEFAULT, &buffer)); CUSPARSE_SPMV_ALG_DEFAULT, buffer));
checkCudaErrors(cublasSetStream(cublasHandle, stream1)); checkCudaErrors(cublasSetStream(cublasHandle, stream1));
checkCudaErrors(cublasSaxpy(cublasHandle, N, &alpham1, d_Ax, 1, d_r, 1)); checkCudaErrors(cublasSaxpy(cublasHandle, N, &alpham1, d_Ax, 1, d_r, 1));
@@ -248,9 +246,9 @@ int main(int argc, char **argv) {
k = 1; k = 1;
// First Iteration when k=1 starts // First Iteration when k=1 starts
checkCudaErrors(cublasScopy(cublasHandle, N, d_r, 1, d_p, 1)); checkCudaErrors(cublasScopy(cublasHandle, N, d_r, 1, d_p, 1));
checkCudaErrors(cusparseSpMV( checkCudaErrors(cusparseSpMV(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE,
cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, &alpha, matA, vecp, &alpha, matA, vecp, &beta, vecAx, CUDA_R_32F,
&beta, vecAx, CUDA_R_32F, CUSPARSE_MV_ALG_DEFAULT, &buffer)); CUSPARSE_SPMV_ALG_DEFAULT, buffer));
checkCudaErrors(cublasSdot(cublasHandle, N, d_p, 1, d_Ax, 1, d_dot)); checkCudaErrors(cublasSdot(cublasHandle, N, d_p, 1, d_Ax, 1, d_dot));
@@ -290,9 +288,9 @@ int main(int argc, char **argv) {
checkCudaErrors( checkCudaErrors(
cusparseSetPointerMode(cusparseHandle, CUSPARSE_POINTER_MODE_HOST)); cusparseSetPointerMode(cusparseHandle, CUSPARSE_POINTER_MODE_HOST));
checkCudaErrors(cusparseSpMV( checkCudaErrors(cusparseSpMV(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE,
cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, &alpha, matA, vecp, &alpha, matA, vecp, &beta, vecAx, CUDA_R_32F,
&beta, vecAx, CUDA_R_32F, CUSPARSE_MV_ALG_DEFAULT, &buffer)); CUSPARSE_SPMV_ALG_DEFAULT, buffer));
checkCudaErrors(cudaMemsetAsync(d_dot, 0, sizeof(float), stream1)); checkCudaErrors(cudaMemsetAsync(d_dot, 0, sizeof(float), stream1));
checkCudaErrors(cublasSdot(cublasHandle, N, d_p, 1, d_Ax, 1, d_dot)); checkCudaErrors(cublasSdot(cublasHandle, N, d_p, 1, d_Ax, 1, d_dot));
@@ -335,8 +333,8 @@ int main(int argc, char **argv) {
checkCudaErrors(cublasSaxpy(cublasHandle, N, &alpha, d_r, 1, d_p, 1)); checkCudaErrors(cublasSaxpy(cublasHandle, N, &alpha, d_r, 1, d_p, 1));
checkCudaErrors(cusparseSpMV( checkCudaErrors(cusparseSpMV(
cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, &alpha, matA, vecp, cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, &alpha, matA, vecp,
&beta, vecAx, CUDA_R_32F, CUSPARSE_MV_ALG_DEFAULT, &buffer)); &beta, vecAx, CUDA_R_32F, CUSPARSE_SPMV_ALG_DEFAULT, buffer));
cublasSetPointerMode(cublasHandle, CUBLAS_POINTER_MODE_DEVICE); cublasSetPointerMode(cublasHandle, CUBLAS_POINTER_MODE_DEVICE);
checkCudaErrors(cublasSdot(cublasHandle, N, d_p, 1, d_Ax, 1, d_dot)); checkCudaErrors(cublasSdot(cublasHandle, N, d_p, 1, d_Ax, 1, d_dot));
@@ -395,23 +393,31 @@ int main(int argc, char **argv) {
cusparseDestroy(cusparseHandle); cusparseDestroy(cusparseHandle);
cublasDestroy(cublasHandle); cublasDestroy(cublasHandle);
if (matA ) { checkCudaErrors(cusparseDestroySpMat(matA)); } if (matA) {
if (vecx ) { checkCudaErrors(cusparseDestroyDnVec(vecx)); } checkCudaErrors(cusparseDestroySpMat(matA));
if (vecAx ) { checkCudaErrors(cusparseDestroyDnVec(vecAx)); } }
if (vecp ) { checkCudaErrors(cusparseDestroyDnVec(vecp)); } if (vecx) {
checkCudaErrors(cusparseDestroyDnVec(vecx));
}
if (vecAx) {
checkCudaErrors(cusparseDestroyDnVec(vecAx));
}
if (vecp) {
checkCudaErrors(cusparseDestroyDnVec(vecp));
}
free(I); checkCudaErrors(cudaFreeHost(I));
free(J); checkCudaErrors(cudaFreeHost(J));
free(val); checkCudaErrors(cudaFreeHost(val));
free(x); checkCudaErrors(cudaFreeHost(x));
free(rhs); free(rhs);
cudaFree(d_col); checkCudaErrors(cudaFree(d_col));
cudaFree(d_row); checkCudaErrors(cudaFree(d_row));
cudaFree(d_val); checkCudaErrors(cudaFree(d_val));
cudaFree(d_x); checkCudaErrors(cudaFree(d_x));
cudaFree(d_r); checkCudaErrors(cudaFree(d_r));
cudaFree(d_p); checkCudaErrors(cudaFree(d_p));
cudaFree(d_Ax); checkCudaErrors(cudaFree(d_Ax));
printf("Test Summary: Error amount = %f\n", err); printf("Test Summary: Error amount = %f\n", err);
exit((k <= max_iter) ? 0 : 1); exit((k <= max_iter) ? 0 : 1);

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -104,6 +104,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -27,7 +27,7 @@ x86_64, ppc64le, aarch64
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -104,6 +104,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -30,7 +30,7 @@ cudaMemAdvise, cudaMemPrefetchAsync, cudaLaunchCooperativeKernelMultiDevice, cud
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -223,8 +223,10 @@ __device__ void gpuDotProduct(float *vecA, float *vecB, int size,
cg::sync(cta); cg::sync(cta);
if (tile32.meta_group_rank() == 0) { if (tile32.meta_group_rank() == 0) {
temp_sum = tile32.thread_rank() < tile32.meta_group_size() ? tmp[tile32.thread_rank()] : 0.0; temp_sum = tile32.thread_rank() < tile32.meta_group_size()
temp_sum = cg::reduce(tile32, temp_sum, cg::plus<double>()); ? tmp[tile32.thread_rank()]
: 0.0;
temp_sum = cg::reduce(tile32, temp_sum, cg::plus<double>());
if (tile32.thread_rank() == 0) { if (tile32.thread_rank() == 0) {
atomicAdd(&grid_dot_result, temp_sum); atomicAdd(&grid_dot_result, temp_sum);
@@ -239,8 +241,9 @@ __device__ void gpuCopyVector(float *srcA, float *destB, int size,
} }
} }
__device__ void gpuScaleVectorAndSaxpy(float *x, float *y, float a, float scale, int size, __device__ void gpuScaleVectorAndSaxpy(float *x, float *y, float a, float scale,
const cg::multi_grid_group &multi_grid) { int size,
const cg::multi_grid_group &multi_grid) {
for (int i = multi_grid.thread_rank(); i < size; i += multi_grid.size()) { for (int i = multi_grid.thread_rank(); i < size; i += multi_grid.size()) {
y[i] = a * x[i] + scale * y[i]; y[i] = a * x[i] + scale * y[i];
} }
@@ -360,10 +363,11 @@ std::multimap<std::pair<int, int>, int> getIdenticalGPUs() {
// Filter unsupported devices // Filter unsupported devices
if (deviceProp.cooperativeMultiDeviceLaunch && if (deviceProp.cooperativeMultiDeviceLaunch &&
deviceProp.concurrentManagedAccess) { deviceProp.concurrentManagedAccess) {
identicalGpus.emplace(std::make_pair(deviceProp.major, deviceProp.minor), i); identicalGpus.emplace(std::make_pair(deviceProp.major, deviceProp.minor),
i);
} }
printf("GPU Device %d: \"%s\" with compute capability %d.%d\n", i, printf("GPU Device %d: \"%s\" with compute capability %d.%d\n", i,
deviceProp.name, deviceProp.major, deviceProp.minor); deviceProp.name, deviceProp.major, deviceProp.minor);
} }
return identicalGpus; return identicalGpus;
@@ -387,15 +391,17 @@ int main(int argc, char **argv) {
auto bestFit = std::make_pair(it, it); auto bestFit = std::make_pair(it, it);
// use std::distance to find the largest number of GPUs amongst architectures // use std::distance to find the largest number of GPUs amongst architectures
auto distance = [](decltype(bestFit) p){return std::distance(p.first, p.second);}; auto distance = [](decltype(bestFit) p) {
return std::distance(p.first, p.second);
};
// Read each unique key/pair element in order // Read each unique key/pair element in order
for (; it != end; it = gpusByArch.upper_bound(it->first)) { for (; it != end; it = gpusByArch.upper_bound(it->first)) {
// first and second are iterators bounded within the architecture group // first and second are iterators bounded within the architecture group
auto testFit = gpusByArch.equal_range(it->first); auto testFit = gpusByArch.equal_range(it->first);
// Always use devices with highest architecture version or whichever has the most devices available // Always use devices with highest architecture version or whichever has the
if (distance(bestFit) <= distance(testFit)) // most devices available
bestFit = testFit; if (distance(bestFit) <= distance(testFit)) bestFit = testFit;
} }
if (distance(bestFit) < kNumGpusRequired) { if (distance(bestFit) < kNumGpusRequired) {
@@ -408,33 +414,35 @@ int main(int argc, char **argv) {
std::set<int> bestFitDeviceIds; std::set<int> bestFitDeviceIds;
// check & select peer-to-peer access capable GPU devices as enabling p2p access between participating // check & select peer-to-peer access capable GPU devices as enabling p2p
// access between participating
// GPUs gives better performance for multi_grid sync. // GPUs gives better performance for multi_grid sync.
for (auto itr = bestFit.first; itr != bestFit.second; itr++) { for (auto itr = bestFit.first; itr != bestFit.second; itr++) {
int deviceId = itr->second; int deviceId = itr->second;
checkCudaErrors(cudaSetDevice(deviceId)); checkCudaErrors(cudaSetDevice(deviceId));
std::for_each(itr, bestFit.second, [&deviceId, &bestFitDeviceIds](decltype(*itr) mapPair) { std::for_each(itr, bestFit.second, [&deviceId, &bestFitDeviceIds,
if (deviceId != mapPair.second) &kNumGpusRequired](
{ decltype(*itr) mapPair) {
if (deviceId != mapPair.second) {
int access = 0; int access = 0;
checkCudaErrors(cudaDeviceCanAccessPeer(&access, deviceId, mapPair.second)); checkCudaErrors(
printf("Device=%d %s Access Peer Device=%d\n", deviceId, access ? "CAN" : "CANNOT", mapPair.second); cudaDeviceCanAccessPeer(&access, deviceId, mapPair.second));
printf("Device=%d %s Access Peer Device=%d\n", deviceId,
access ? "CAN" : "CANNOT", mapPair.second);
if (access && bestFitDeviceIds.size() < kNumGpusRequired) { if (access && bestFitDeviceIds.size() < kNumGpusRequired) {
bestFitDeviceIds.emplace(deviceId); bestFitDeviceIds.emplace(deviceId);
bestFitDeviceIds.emplace(mapPair.second); bestFitDeviceIds.emplace(mapPair.second);
} } else {
else {
printf("Ignoring device %i (max devices exceeded)\n", mapPair.second); printf("Ignoring device %i (max devices exceeded)\n", mapPair.second);
} }
} }
}); });
if (bestFitDeviceIds.size() >= kNumGpusRequired) if (bestFitDeviceIds.size() >= kNumGpusRequired) {
{
printf("Selected p2p capable devices - "); printf("Selected p2p capable devices - ");
for (auto devicesItr = bestFitDeviceIds.begin(); devicesItr != bestFitDeviceIds.end(); devicesItr++) for (auto devicesItr = bestFitDeviceIds.begin();
{ devicesItr != bestFitDeviceIds.end(); devicesItr++) {
printf("deviceId = %d ", *devicesItr); printf("deviceId = %d ", *devicesItr);
} }
printf("\n"); printf("\n");
@@ -442,33 +450,34 @@ int main(int argc, char **argv) {
} }
} }
// if bestFitDeviceIds.size() == 0 it means the GPUs in system are not p2p capable, // if bestFitDeviceIds.size() == 0 it means the GPUs in system are not p2p
// capable,
// hence we add it without p2p capability check. // hence we add it without p2p capability check.
if (!bestFitDeviceIds.size()) if (!bestFitDeviceIds.size()) {
{ printf("Devices involved are not p2p capable.. selecting %zu of them\n",
printf("Devices involved are not p2p capable.. selecting %zu of them\n", kNumGpusRequired); kNumGpusRequired);
std::for_each(bestFit.first, bestFit.second, [&bestFitDeviceIds](decltype(*bestFit.first) mapPair) { std::for_each(bestFit.first, bestFit.second,
if (bestFitDeviceIds.size() < kNumGpusRequired) { [&bestFitDeviceIds,
bestFitDeviceIds.emplace(mapPair.second); &kNumGpusRequired](decltype(*bestFit.first) mapPair) {
} if (bestFitDeviceIds.size() < kNumGpusRequired) {
else { bestFitDeviceIds.emplace(mapPair.second);
printf("Ignoring device %i (max devices exceeded)\n", mapPair.second); } else {
} printf("Ignoring device %i (max devices exceeded)\n",
// Insert the sequence into the deviceIds set mapPair.second);
}); }
} // Insert the sequence into the deviceIds set
else });
{ } else {
// perform cudaDeviceEnablePeerAccess in both directions for all participating devices // perform cudaDeviceEnablePeerAccess in both directions for all
// of a cudaLaunchCooperativeKernelMultiDevice call this gives better performance for multi_grid sync. // participating devices of a cudaLaunchCooperativeKernelMultiDevice call
for (auto p1_itr = bestFitDeviceIds.begin(); p1_itr != bestFitDeviceIds.end(); p1_itr++) // this gives better performance for multi_grid sync.
{ for (auto p1_itr = bestFitDeviceIds.begin();
p1_itr != bestFitDeviceIds.end(); p1_itr++) {
checkCudaErrors(cudaSetDevice(*p1_itr)); checkCudaErrors(cudaSetDevice(*p1_itr));
for (auto p2_itr = bestFitDeviceIds.begin(); p2_itr != bestFitDeviceIds.end(); p2_itr++) for (auto p2_itr = bestFitDeviceIds.begin();
{ p2_itr != bestFitDeviceIds.end(); p2_itr++) {
if (*p1_itr != *p2_itr) if (*p1_itr != *p2_itr) {
{ checkCudaErrors(cudaDeviceEnablePeerAccess(*p2_itr, 0));
checkCudaErrors(cudaDeviceEnablePeerAccess(*p2_itr, 0 ));
checkCudaErrors(cudaSetDevice(*p1_itr)); checkCudaErrors(cudaSetDevice(*p1_itr));
} }
} }
@@ -518,7 +527,7 @@ int main(int argc, char **argv) {
std::cout << "\nRunning on GPUs = " << kNumGpusRequired << std::endl; std::cout << "\nRunning on GPUs = " << kNumGpusRequired << std::endl;
cudaStream_t nStreams[kNumGpusRequired]; cudaStream_t nStreams[kNumGpusRequired];
int sMemSize = sizeof(double) * ((THREADS_PER_BLOCK/32) + 1); int sMemSize = sizeof(double) * ((THREADS_PER_BLOCK / 32) + 1);
int numBlocksPerSm = INT_MAX; int numBlocksPerSm = INT_MAX;
int numThreads = THREADS_PER_BLOCK; int numThreads = THREADS_PER_BLOCK;
int numSms = INT_MAX; int numSms = INT_MAX;
@@ -530,17 +539,16 @@ int main(int argc, char **argv) {
checkCudaErrors(cudaSetDevice(*deviceId)); checkCudaErrors(cudaSetDevice(*deviceId));
checkCudaErrors(cudaGetDeviceProperties(&deviceProp, *deviceId)); checkCudaErrors(cudaGetDeviceProperties(&deviceProp, *deviceId));
int numBlocksPerSm_current=0; int numBlocksPerSm_current = 0;
checkCudaErrors(cudaOccupancyMaxActiveBlocksPerMultiprocessor( checkCudaErrors(cudaOccupancyMaxActiveBlocksPerMultiprocessor(
&numBlocksPerSm_current, multiGpuConjugateGradient, numThreads, sMemSize)); &numBlocksPerSm_current, multiGpuConjugateGradient, numThreads,
sMemSize));
if (numBlocksPerSm > numBlocksPerSm_current) if (numBlocksPerSm > numBlocksPerSm_current) {
{ numBlocksPerSm = numBlocksPerSm_current;
numBlocksPerSm = numBlocksPerSm_current;
} }
if (numSms > deviceProp.multiProcessorCount) if (numSms > deviceProp.multiProcessorCount) {
{ numSms = deviceProp.multiProcessorCount;
numSms = deviceProp.multiProcessorCount;
} }
deviceId++; deviceId++;
} }
@@ -554,7 +562,7 @@ int main(int argc, char **argv) {
int device_count = 0; int device_count = 0;
int totalThreadsPerGPU = numSms * numBlocksPerSm * THREADS_PER_BLOCK; int totalThreadsPerGPU = numSms * numBlocksPerSm * THREADS_PER_BLOCK;
deviceId = bestFitDeviceIds.begin();; deviceId = bestFitDeviceIds.begin();
while (deviceId != bestFitDeviceIds.end()) { while (deviceId != bestFitDeviceIds.end()) {
checkCudaErrors(cudaSetDevice(*deviceId)); checkCudaErrors(cudaSetDevice(*deviceId));
checkCudaErrors(cudaStreamCreate(&nStreams[device_count])); checkCudaErrors(cudaStreamCreate(&nStreams[device_count]));
@@ -621,14 +629,15 @@ int main(int argc, char **argv) {
printf("Total threads per GPU = %d numBlocksPerSm = %d\n", printf("Total threads per GPU = %d numBlocksPerSm = %d\n",
numSms * numBlocksPerSm * THREADS_PER_BLOCK, numBlocksPerSm); numSms * numBlocksPerSm * THREADS_PER_BLOCK, numBlocksPerSm);
dim3 dimGrid(numSms * numBlocksPerSm, 1, 1), dimBlock(THREADS_PER_BLOCK, 1, 1); dim3 dimGrid(numSms * numBlocksPerSm, 1, 1),
dimBlock(THREADS_PER_BLOCK, 1, 1);
void *kernelArgs[] = { void *kernelArgs[] = {
(void *)&I, (void *)&J, (void *)&val, (void *)&x, (void *)&I, (void *)&J, (void *)&val, (void *)&x,
(void *)&Ax, (void *)&p, (void *)&r, (void *)&dot_result, (void *)&Ax, (void *)&p, (void *)&r, (void *)&dot_result,
(void *)&nz, (void *)&N, (void *)&tol, (void *)&nz, (void *)&N, (void *)&tol,
}; };
cudaLaunchParams *launchParamsList = (cudaLaunchParams *)malloc( cudaLaunchParams *launchParamsList =
sizeof(cudaLaunchParams) * kNumGpusRequired); (cudaLaunchParams *)malloc(sizeof(cudaLaunchParams) * kNumGpusRequired);
for (int i = 0; i < kNumGpusRequired; i++) { for (int i = 0; i < kNumGpusRequired; i++) {
launchParamsList[i].func = (void *)multiGpuConjugateGradient; launchParamsList[i].func = (void *)multiGpuConjugateGradient;
launchParamsList[i].gridDim = dimGrid; launchParamsList[i].gridDim = dimGrid;
@@ -645,12 +654,11 @@ int main(int argc, char **argv) {
cudaCooperativeLaunchMultiDeviceNoPreSync | cudaCooperativeLaunchMultiDeviceNoPreSync |
cudaCooperativeLaunchMultiDeviceNoPostSync)); cudaCooperativeLaunchMultiDeviceNoPostSync));
checkCudaErrors(cudaMemPrefetchAsync(x, sizeof(float) * N, cudaCpuDeviceId));
checkCudaErrors( checkCudaErrors(
cudaMemPrefetchAsync(x, sizeof(float) * N, cudaCpuDeviceId)); cudaMemPrefetchAsync(dot_result, sizeof(double), cudaCpuDeviceId));
checkCudaErrors(
cudaMemPrefetchAsync(dot_result, sizeof(double), cudaCpuDeviceId));
deviceId = bestFitDeviceIds.begin();; deviceId = bestFitDeviceIds.begin();
device_count = 0; device_count = 0;
while (deviceId != bestFitDeviceIds.end()) { while (deviceId != bestFitDeviceIds.end()) {
checkCudaErrors(cudaSetDevice(*deviceId)); checkCudaErrors(cudaSetDevice(*deviceId));
@@ -658,7 +666,7 @@ int main(int argc, char **argv) {
deviceId++; deviceId++;
} }
r1 = *dot_result; r1 = (float)*dot_result;
printf("GPU Final, residual = %e \n ", sqrt(r1)); printf("GPU Final, residual = %e \n ", sqrt(r1));

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -109,6 +109,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -105,6 +105,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -27,7 +27,7 @@ x86_64, ppc64le, aarch64
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -110,6 +110,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -106,6 +106,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -27,7 +27,7 @@ x86_64, ppc64le, armv7l
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -495,13 +495,13 @@ int main(int argc, char *argv[]) {
size_t bufferSize = 0; size_t bufferSize = 0;
checkCudaErrors(cusparseSpMV_bufferSize( checkCudaErrors(cusparseSpMV_bufferSize(
cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, &minus_one, matA, vecx, cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, &minus_one, matA, vecx,
&one, vecAx, CUDA_R_64F, CUSPARSE_MV_ALG_DEFAULT, &bufferSize)); &one, vecAx, CUDA_R_64F, CUSPARSE_SPMV_ALG_DEFAULT, &bufferSize));
void *buffer = NULL; void *buffer = NULL;
checkCudaErrors(cudaMalloc(&buffer, bufferSize)); checkCudaErrors(cudaMalloc(&buffer, bufferSize));
checkCudaErrors(cusparseSpMV(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, checkCudaErrors(cusparseSpMV(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE,
&minus_one, matA, vecx, &one, vecAx, CUDA_R_64F, &minus_one, matA, vecx, &one, vecAx, CUDA_R_64F,
CUSPARSE_MV_ALG_DEFAULT, &buffer)); CUSPARSE_SPMV_ALG_DEFAULT, buffer));
checkCudaErrors(cudaMemcpyAsync(h_r, d_r, sizeof(double) * rowsA, checkCudaErrors(cudaMemcpyAsync(h_r, d_r, sizeof(double) * rowsA,
cudaMemcpyDeviceToHost, stream)); cudaMemcpyDeviceToHost, stream));
@@ -559,7 +559,7 @@ int main(int argc, char *argv[]) {
checkCudaErrors(cusparseSpMV(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE, checkCudaErrors(cusparseSpMV(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE,
&minus_one, matA, vecx, &one, vecAx, CUDA_R_64F, &minus_one, matA, vecx, &one, vecAx, CUDA_R_64F,
CUSPARSE_MV_ALG_DEFAULT, &buffer)); CUSPARSE_SPMV_ALG_DEFAULT, buffer));
checkCudaErrors(cudaMemcpyAsync(h_x, d_x, sizeof(double) * colsA, checkCudaErrors(cudaMemcpyAsync(h_x, d_x, sizeof(double) * colsA,
cudaMemcpyDeviceToHost, stream)); cudaMemcpyDeviceToHost, stream));

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -110,6 +110,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -106,6 +106,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -30,7 +30,7 @@ cudaMalloc, cudaFree
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -109,6 +109,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -105,6 +105,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -48,26 +48,47 @@ __global__ void saxpy(const float a, const float4 *x, const float4 *y, float4 *z
} }
} }
__global__ void init(float4 *x, float4 *y, float4 *z, const float val, const size_t n) __global__ void init(float4 *x, float4 *y, const float val, const size_t n)
{ {
const float4 val4 = make_float4(val, val, val, val); const float4 val4 = make_float4(val, val, val, val);
for (size_t i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += gridDim.x * blockDim.x) for (size_t i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += gridDim.x * blockDim.x)
{ {
z[i] = x[i] = y[i] = val4; x[i] = y[i] = val4;
} }
} }
void launchSaxpy(const float a, float4 *x, float4 *y, float4 *z, const size_t n, const float init_val) void launchSaxpy(const float a, float4 *x, float4 *y, float4 *z, const size_t n, const float init_val, const bool compressibleZbuf)
{ {
cudaEvent_t start, stop; cudaEvent_t start, stop;
float ms; float ms;
int blockSize; int blockSize;
int minGridSize; int minGridSize;
dim3 threads, blocks;
checkCudaErrors(cudaOccupancyMaxPotentialBlockSize(&minGridSize, &blockSize, (void*)init)); if (!compressibleZbuf)
dim3 threads = dim3(blockSize, 1, 1); {
dim3 blocks = dim3(minGridSize, 1, 1); // We are on config where compressible buffer can only be initialized through cudaMemcpy
init<<<blocks, threads>>>(x, y, z, init_val, n); // hence, x & y buffers are allocated as compressible and initialized via cudaMemcpy
// whereas z buffer is allocated as non-compressible.
float4 *h_x = (float4 *) malloc(sizeof(float4) * n);
float4 *h_y = (float4 *) malloc(sizeof(float4) * n);
for (int i = 0; i < n; i++)
{
h_x[i].x = h_x[i].y = h_x[i].z = h_x[i].w = init_val;
h_y[i].x = h_y[i].y = h_y[i].z = h_y[i].w = init_val;
}
checkCudaErrors(cudaMemcpy(x, h_x, sizeof(float4) * n, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(y, h_y, sizeof(float4) * n, cudaMemcpyHostToDevice));
free(h_x);
free(h_y);
}
else
{
checkCudaErrors(cudaOccupancyMaxPotentialBlockSize(&minGridSize, &blockSize, (void*)init));
threads = dim3(blockSize, 1, 1);
blocks = dim3(minGridSize, 1, 1);
init<<<blocks, threads>>>(x, y, init_val, n);
}
checkCudaErrors(cudaOccupancyMaxPotentialBlockSize(&minGridSize, &blockSize, (void*)saxpy)); checkCudaErrors(cudaOccupancyMaxPotentialBlockSize(&minGridSize, &blockSize, (void*)saxpy));
threads = dim3(blockSize, 1, 1); threads = dim3(blockSize, 1, 1);
@@ -121,19 +142,39 @@ int main(int argc, char **argv)
printf("Generic memory compression support is available\n"); printf("Generic memory compression support is available\n");
int major, minor;
checkCudaErrors(cuDeviceGetAttribute(&major,
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR,
currentDevice));
checkCudaErrors(cuDeviceGetAttribute(&minor,
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR,
currentDevice));
float4 *x, *y, *z; float4 *x, *y, *z;
const size_t size = n * sizeof(float4); const size_t size = n * sizeof(float4);
// Allocating compressible memory // Allocating compressible memory
checkCudaErrors(allocateCompressible((void **)&x, size, true)); checkCudaErrors(allocateCompressible((void **)&x, size, true));
checkCudaErrors(allocateCompressible((void **)&y, size, true)); checkCudaErrors(allocateCompressible((void **)&y, size, true));
checkCudaErrors(allocateCompressible((void **)&z, size, true)); bool compressibleZbuf = 0;
if ((major == 8 && minor == 0) || (major == 8 && minor == 6))
{
// On SM 8.0 and 8.6 GPUs compressible buffer can only be initialized
// through cudaMemcpy.
printf("allocating non-compressible Z buffer\n");
checkCudaErrors(allocateCompressible((void **)&z, size, false));
compressibleZbuf = 0;
}
else
{
checkCudaErrors(allocateCompressible((void **)&z, size, true));
compressibleZbuf = 1;
}
printf("Running saxpy on %zu bytes of Compressible memory\n", size); printf("Running saxpy on %zu bytes of Compressible memory\n", size);
const float a = 1.0f; const float a = 1.0f;
const float init_val = 1.0f; const float init_val = 1.0f;
launchSaxpy(a, x, y, z, n, init_val); launchSaxpy(a, x, y, z, n, init_val, compressibleZbuf);
checkCudaErrors(freeCompressible(x, size, true)); checkCudaErrors(freeCompressible(x, size, true));
checkCudaErrors(freeCompressible(y, size, true)); checkCudaErrors(freeCompressible(y, size, true));
@@ -145,7 +186,7 @@ int main(int argc, char **argv)
checkCudaErrors(allocateCompressible((void **)&y, size, false)); checkCudaErrors(allocateCompressible((void **)&y, size, false));
checkCudaErrors(allocateCompressible((void **)&z, size, false)); checkCudaErrors(allocateCompressible((void **)&z, size, false));
launchSaxpy(a, x, y, z, n, init_val); launchSaxpy(a, x, y, z, n, init_val, compressibleZbuf);
checkCudaErrors(freeCompressible(x, size, false)); checkCudaErrors(freeCompressible(x, size, false));
checkCudaErrors(freeCompressible(y, size, false)); checkCudaErrors(freeCompressible(y, size, false));

View File

@@ -30,7 +30,7 @@ cudaImportExternalMemory, cudaExternalMemoryGetMappedBuffer, cudaExternalMemoryG
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -30,7 +30,7 @@ cudaImportExternalMemory, cudaExternalMemoryGetMappedBuffer, cudaExternalMemoryG
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -36,7 +36,6 @@
// Enable this to 1 if require cuda processed output to ppm file. // Enable this to 1 if require cuda processed output to ppm file.
#define WRITE_OUTPUT_IMAGE 0 #define WRITE_OUTPUT_IMAGE 0
#define checkNvSciErrors(call) \ #define checkNvSciErrors(call) \
do { \ do { \
NvSciError _status = call; \ NvSciError _status = call; \
@@ -48,325 +47,382 @@
fflush(stdout); \ fflush(stdout); \
exit(EXIT_FAILURE); \ exit(EXIT_FAILURE); \
} \ } \
} while (0) } while (0)
__global__ static void yuvToGrayscale(cudaSurfaceObject_t surfaceObject, unsigned int *dstImage, int32_t imageWidth, int32_t imageHeight) __global__ static void yuvToGrayscale(cudaSurfaceObject_t surfaceObject,
{ unsigned int *dstImage,
size_t x = blockIdx.x*blockDim.x + threadIdx.x; int32_t imageWidth, int32_t imageHeight) {
size_t y = blockIdx.y*blockDim.y + threadIdx.y; size_t x = blockIdx.x * blockDim.x + threadIdx.x;
size_t y = blockIdx.y * blockDim.y + threadIdx.y;
uchar4* dstImageUchar4 = (uchar4*)dstImage; uchar4 *dstImageUchar4 = (uchar4 *)dstImage;
for ( ; x < imageWidth && y < imageHeight; x += gridDim.x*blockDim.x, y += gridDim.y*blockDim.y) for (; x < imageWidth && y < imageHeight;
{ x += gridDim.x * blockDim.x, y += gridDim.y * blockDim.y) {
int colInBytes = x * sizeof(unsigned char); int colInBytes = x * sizeof(unsigned char);
unsigned char luma = surf2Dread<unsigned char>(surfaceObject, colInBytes, y); unsigned char luma =
uchar4 grayscalePix = make_uchar4(luma, luma, luma, 0); surf2Dread<unsigned char>(surfaceObject, colInBytes, y);
uchar4 grayscalePix = make_uchar4(luma, luma, luma, 0);
dstImageUchar4[y*imageWidth + x] = grayscalePix; dstImageUchar4[y * imageWidth + x] = grayscalePix;
} }
} }
static void cudaImportNvSciSync(cudaExternalSemaphore_t &extSem, NvSciSyncObj &syncObj) static void cudaImportNvSciSync(cudaExternalSemaphore_t &extSem,
{ NvSciSyncObj &syncObj) {
cudaExternalSemaphoreHandleDesc extSemDesc; cudaExternalSemaphoreHandleDesc extSemDesc;
memset(&extSemDesc, 0, sizeof(extSemDesc)); memset(&extSemDesc, 0, sizeof(extSemDesc));
extSemDesc.type = cudaExternalSemaphoreHandleTypeNvSciSync; extSemDesc.type = cudaExternalSemaphoreHandleTypeNvSciSync;
extSemDesc.handle.nvSciSyncObj = (void *)syncObj; extSemDesc.handle.nvSciSyncObj = (void *)syncObj;
checkCudaErrors(cudaImportExternalSemaphore(&extSem, &extSemDesc)); checkCudaErrors(cudaImportExternalSemaphore(&extSem, &extSemDesc));
} }
static void waitExternalSemaphore(cudaExternalSemaphore_t &waitSem, NvSciSyncFence *fence, static void waitExternalSemaphore(cudaExternalSemaphore_t &waitSem,
cudaStream_t stream) { NvSciSyncFence *fence, cudaStream_t stream) {
cudaExternalSemaphoreWaitParams waitParams; cudaExternalSemaphoreWaitParams waitParams;
memset(&waitParams, 0, sizeof(waitParams)); memset(&waitParams, 0, sizeof(waitParams));
// For cross-process signaler-waiter applications need to use NvSciIpc // For cross-process signaler-waiter applications need to use NvSciIpc
// and NvSciSync[Export|Import] utilities to share the NvSciSyncFence // and NvSciSync[Export|Import] utilities to share the NvSciSyncFence
// across process. This step is optional in single-process. // across process. This step is optional in single-process.
waitParams.params.nvSciSync.fence = (void *)fence; waitParams.params.nvSciSync.fence = (void *)fence;
waitParams.flags = 0; waitParams.flags = 0;
checkCudaErrors(cudaWaitExternalSemaphoresAsync(&waitSem, &waitParams, 1, stream)); checkCudaErrors(
cudaWaitExternalSemaphoresAsync(&waitSem, &waitParams, 1, stream));
} }
static void signalExternalSemaphore(cudaExternalSemaphore_t &signalSem, NvSciSyncFence *fence, static void signalExternalSemaphore(cudaExternalSemaphore_t &signalSem,
cudaStream_t stream) { NvSciSyncFence *fence,
cudaExternalSemaphoreSignalParams signalParams; cudaStream_t stream) {
memset(&signalParams, 0, sizeof(signalParams)); cudaExternalSemaphoreSignalParams signalParams;
// For cross-process signaler-waiter applications need to use NvSciIpc memset(&signalParams, 0, sizeof(signalParams));
// and NvSciSync[Export|Import] utilities to share the NvSciSyncFence // For cross-process signaler-waiter applications need to use NvSciIpc
// across process. This step is optional in single-process. // and NvSciSync[Export|Import] utilities to share the NvSciSyncFence
signalParams.params.nvSciSync.fence = (void *)fence; // across process. This step is optional in single-process.
signalParams.flags = 0; signalParams.params.nvSciSync.fence = (void *)fence;
signalParams.flags = 0;
checkCudaErrors(cudaSignalExternalSemaphoresAsync(&signalSem, &signalParams, checkCudaErrors(
1, stream)); cudaSignalExternalSemaphoresAsync(&signalSem, &signalParams, 1, stream));
} }
static void yuvToGrayscaleCudaKernel(cudaExternalResInterop &cudaExtResObj,
static void yuvToGrayscaleCudaKernel(cudaExternalResInterop& cudaExtResObj, int32_t imageWidth, int32_t imageHeight) int32_t imageWidth, int32_t imageHeight) {
{
#if WRITE_OUTPUT_IMAGE #if WRITE_OUTPUT_IMAGE
unsigned int *h_dstImage; unsigned int *h_dstImage;
checkCudaErrors(cudaMallocHost(&h_dstImage, sizeof(unsigned int)*imageHeight*imageWidth)); checkCudaErrors(cudaMallocHost(
&h_dstImage, sizeof(unsigned int) * imageHeight * imageWidth));
#endif #endif
dim3 block(16, 16, 1); dim3 block(16, 16, 1);
dim3 grid((imageWidth/block.x)+1, (imageHeight/block.y)+1, 1); dim3 grid((imageWidth / block.x) + 1, (imageHeight / block.y) + 1, 1);
yuvToGrayscale<<<grid, block, 0, cudaExtResObj.stream>>>(cudaExtResObj.cudaSurfaceNvmediaBuf[0], cudaExtResObj.d_outputImage, imageWidth, imageHeight); yuvToGrayscale<<<grid, block, 0, cudaExtResObj.stream>>>(
cudaExtResObj.cudaSurfaceNvmediaBuf[0], cudaExtResObj.d_outputImage,
imageWidth, imageHeight);
#if WRITE_OUTPUT_IMAGE #if WRITE_OUTPUT_IMAGE
checkCudaErrors(cudaMemcpyAsync(h_dstImage, cudaExtResObj.d_outputImage, sizeof(unsigned int)*imageHeight*imageWidth, cudaMemcpyDeviceToHost, cudaExtResObj.stream)); checkCudaErrors(
checkCudaErrors(cudaStreamSynchronize(cudaExtResObj.stream)); cudaMemcpyAsync(h_dstImage, cudaExtResObj.d_outputImage,
char outputFilename[1024]; sizeof(unsigned int) * imageHeight * imageWidth,
std::string image_filename = "Grayscale"; cudaMemcpyDeviceToHost, cudaExtResObj.stream));
strcpy(outputFilename, image_filename.c_str()); checkCudaErrors(cudaStreamSynchronize(cudaExtResObj.stream));
strcpy(outputFilename + image_filename.length(), "_nvsci_out.ppm"); char outputFilename[1024];
sdkSavePPM4ub(outputFilename, (unsigned char *)h_dstImage, imageWidth, imageHeight); std::string image_filename = "Grayscale";
printf("Wrote '%s'\n", outputFilename); strcpy(outputFilename, image_filename.c_str());
checkCudaErrors(cudaFreeHost(h_dstImage)); strcpy(outputFilename + image_filename.length(), "_nvsci_out.ppm");
sdkSavePPM4ub(outputFilename, (unsigned char *)h_dstImage, imageWidth,
imageHeight);
printf("Wrote '%s'\n", outputFilename);
checkCudaErrors(cudaFreeHost(h_dstImage));
#endif #endif
} }
static void cudaImportNvSciImage(cudaExternalResInterop &cudaExtResObj, NvSciBufObj& inputBufObj) static void cudaImportNvSciImage(cudaExternalResInterop &cudaExtResObj,
{ NvSciBufObj &inputBufObj) {
NvSciBufModule module = NULL; NvSciBufModule module = NULL;
NvSciBufAttrList attrlist = NULL; NvSciBufAttrList attrlist = NULL;
NvSciBufAttrKeyValuePair pairArrayOut[10]; NvSciBufAttrKeyValuePair pairArrayOut[10];
checkNvSciErrors(NvSciBufModuleOpen(&module)); checkNvSciErrors(NvSciBufModuleOpen(&module));
checkNvSciErrors(NvSciBufAttrListCreate(module, &attrlist)); checkNvSciErrors(NvSciBufAttrListCreate(module, &attrlist));
checkNvSciErrors(NvSciBufObjGetAttrList(inputBufObj, &attrlist)); checkNvSciErrors(NvSciBufObjGetAttrList(inputBufObj, &attrlist));
memset(pairArrayOut, 0, sizeof(NvSciBufAttrKeyValuePair) * 10); memset(pairArrayOut, 0, sizeof(NvSciBufAttrKeyValuePair) * 10);
int numAttrs = 0; int numAttrs = 0;
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_Size; pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_Size;
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneChannelCount; pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneChannelCount;
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneCount; pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneCount;
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneWidth; pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneWidth;
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneHeight; pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneHeight;
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_Layout; pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_Layout;
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneBitsPerPixel; pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneBitsPerPixel;
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneOffset;
checkNvSciErrors(NvSciBufAttrListGetAttrs(attrlist, pairArrayOut, numAttrs)); checkNvSciErrors(NvSciBufAttrListGetAttrs(attrlist, pairArrayOut, numAttrs));
uint64_t size = *(uint64_t *)pairArrayOut[0].value; uint64_t size = *(uint64_t *)pairArrayOut[0].value;
uint8_t channelCount = *(uint8_t *)pairArrayOut[1].value; uint8_t channelCount = *(uint8_t *)pairArrayOut[1].value;
cudaExtResObj.planeCount = *(int32_t *)pairArrayOut[2].value; cudaExtResObj.planeCount = *(int32_t *)pairArrayOut[2].value;
cudaExtResObj.imageWidth = (int32_t*) malloc(sizeof(int32_t)*cudaExtResObj.planeCount); cudaExtResObj.imageWidth =
cudaExtResObj.imageHeight = (int32_t*) malloc(sizeof(int32_t)*cudaExtResObj.planeCount); (int32_t *)malloc(sizeof(int32_t) * cudaExtResObj.planeCount);
cudaExtResObj.imageHeight =
(int32_t *)malloc(sizeof(int32_t) * cudaExtResObj.planeCount);
cudaExtResObj.planeOffset =
(uint64_t *)malloc(sizeof(uint64_t) * cudaExtResObj.planeCount);
memcpy(cudaExtResObj.imageWidth, (int32_t *)pairArrayOut[3].value, cudaExtResObj.planeCount * sizeof(int32_t)); memcpy(cudaExtResObj.imageWidth, (int32_t *)pairArrayOut[3].value,
memcpy(cudaExtResObj.imageHeight, (int32_t *)pairArrayOut[4].value, cudaExtResObj.planeCount * sizeof(int32_t)); cudaExtResObj.planeCount * sizeof(int32_t));
memcpy(cudaExtResObj.imageHeight, (int32_t *)pairArrayOut[4].value,
cudaExtResObj.planeCount * sizeof(int32_t));
memcpy(cudaExtResObj.planeOffset, (uint64_t *)pairArrayOut[7].value,
cudaExtResObj.planeCount * sizeof(uint64_t));
NvSciBufAttrValImageLayoutType layout = *(NvSciBufAttrValImageLayoutType *)pairArrayOut[5].value; NvSciBufAttrValImageLayoutType layout =
uint32_t bitsPerPixel = *(uint32_t*)pairArrayOut[6].value; *(NvSciBufAttrValImageLayoutType *)pairArrayOut[5].value;
uint32_t bitsPerPixel = *(uint32_t *)pairArrayOut[6].value;
if (layout != NvSciBufImage_BlockLinearType) { if (layout != NvSciBufImage_BlockLinearType) {
printf("Image layout is not block linear.. waiving execution\n"); printf("Image layout is not block linear.. waiving execution\n");
exit(EXIT_WAIVED); exit(EXIT_WAIVED);
}
cudaExternalMemoryHandleDesc memHandleDesc;
memset(&memHandleDesc, 0, sizeof(memHandleDesc));
memHandleDesc.type = cudaExternalMemoryHandleTypeNvSciBuf;
memHandleDesc.handle.nvSciBufObject = inputBufObj;
memHandleDesc.size = size;
checkCudaErrors(
cudaImportExternalMemory(&cudaExtResObj.extMemImageBuf, &memHandleDesc));
cudaExtResObj.d_mipmapArray = (cudaMipmappedArray_t *)malloc(
sizeof(cudaMipmappedArray_t) * cudaExtResObj.planeCount);
for (int i = 0; i < cudaExtResObj.planeCount; i++) {
cudaExtent extent = {};
memset(&extent, 0, sizeof(extent));
extent.width = cudaExtResObj.imageWidth[i];
extent.height = cudaExtResObj.imageHeight[i];
extent.depth = 0;
cudaChannelFormatDesc desc;
switch (channelCount) {
case 1:
default:
desc = cudaCreateChannelDesc(bitsPerPixel, 0, 0, 0,
cudaChannelFormatKindUnsigned);
break;
case 2:
desc = cudaCreateChannelDesc(bitsPerPixel, bitsPerPixel, 0, 0,
cudaChannelFormatKindUnsigned);
break;
case 3:
desc = cudaCreateChannelDesc(bitsPerPixel, bitsPerPixel, bitsPerPixel,
0, cudaChannelFormatKindUnsigned);
break;
case 4:
desc =
cudaCreateChannelDesc(bitsPerPixel, bitsPerPixel, bitsPerPixel,
bitsPerPixel, cudaChannelFormatKindUnsigned);
break;
} }
cudaExternalMemoryHandleDesc memHandleDesc; cudaExternalMemoryMipmappedArrayDesc mipmapDesc = {0};
memset(&memHandleDesc, 0, sizeof(memHandleDesc)); mipmapDesc.offset = cudaExtResObj.planeOffset[i];
memHandleDesc.type = cudaExternalMemoryHandleTypeNvSciBuf; mipmapDesc.formatDesc = desc;
memHandleDesc.handle.nvSciBufObject = inputBufObj; mipmapDesc.extent = extent;
memHandleDesc.size = size; mipmapDesc.flags = 0;
checkCudaErrors(cudaImportExternalMemory(&cudaExtResObj.extMemImageBuf, &memHandleDesc)); mipmapDesc.numLevels = 1;
checkCudaErrors(cudaExternalMemoryGetMappedMipmappedArray(
cudaExtResObj.d_mipmapArray = (cudaMipmappedArray_t*) malloc(sizeof(cudaMipmappedArray_t) * cudaExtResObj.planeCount); &cudaExtResObj.d_mipmapArray[i], cudaExtResObj.extMemImageBuf,
&mipmapDesc));
for (int i = 0; i < cudaExtResObj.planeCount; i++) { }
cudaExtent extent = {};
memset(&extent, 0, sizeof(extent));
extent.width = cudaExtResObj.imageWidth[i];
extent.height = cudaExtResObj.imageHeight[i];
extent.depth = 0;
cudaChannelFormatDesc desc;
switch (channelCount) {
case 1:
default:
desc = cudaCreateChannelDesc(bitsPerPixel, 0, 0, 0, cudaChannelFormatKindUnsigned);
break;
case 2:
desc = cudaCreateChannelDesc(bitsPerPixel, bitsPerPixel, 0, 0, cudaChannelFormatKindUnsigned);
break;
case 3:
desc = cudaCreateChannelDesc(bitsPerPixel, bitsPerPixel, bitsPerPixel, 0, cudaChannelFormatKindUnsigned);
break;
case 4:
desc = cudaCreateChannelDesc(bitsPerPixel, bitsPerPixel, bitsPerPixel, bitsPerPixel, cudaChannelFormatKindUnsigned);
break;
}
cudaExternalMemoryMipmappedArrayDesc mipmapDesc = {0};
mipmapDesc.offset = 0;
mipmapDesc.formatDesc = desc;
mipmapDesc.extent = extent;
mipmapDesc.flags = 0;
mipmapDesc.numLevels = 1;
checkCudaErrors(cudaExternalMemoryGetMappedMipmappedArray(&cudaExtResObj.d_mipmapArray[i], cudaExtResObj.extMemImageBuf, &mipmapDesc));
}
} }
static cudaSurfaceObject_t createCudaSurface(cudaArray_t &d_mipLevelArray) static cudaSurfaceObject_t createCudaSurface(cudaArray_t &d_mipLevelArray) {
{ cudaResourceDesc resourceDesc;
cudaResourceDesc resourceDesc; memset(&resourceDesc, 0, sizeof(resourceDesc));
memset(&resourceDesc, 0, sizeof(resourceDesc)); resourceDesc.resType = cudaResourceTypeArray;
resourceDesc.resType = cudaResourceTypeArray; resourceDesc.res.array.array = d_mipLevelArray;
resourceDesc.res.array.array = d_mipLevelArray;
cudaSurfaceObject_t surfaceObject; cudaSurfaceObject_t surfaceObject;
checkCudaErrors(cudaCreateSurfaceObject(&surfaceObject, &resourceDesc)); checkCudaErrors(cudaCreateSurfaceObject(&surfaceObject, &resourceDesc));
return surfaceObject; return surfaceObject;
} }
static cudaStream_t createCudaStream(int deviceId) static cudaStream_t createCudaStream(int deviceId) {
{ checkCudaErrors(cudaSetDevice(deviceId));
checkCudaErrors(cudaSetDevice(deviceId)); cudaStream_t stream;
cudaStream_t stream; checkCudaErrors(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
checkCudaErrors(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking)); return stream;
return stream;
} }
// CUDA setup buffers/synchronization objects for interop via NvSci API. // CUDA setup buffers/synchronization objects for interop via NvSci API.
void setupCuda(cudaExternalResInterop& cudaExtResObj, NvSciBufObj& inputBufObj, void setupCuda(cudaExternalResInterop &cudaExtResObj, NvSciBufObj &inputBufObj,
NvSciSyncObj &syncObj, NvSciSyncObj &cudaSignalerSyncObj, int deviceId) NvSciSyncObj &syncObj, NvSciSyncObj &cudaSignalerSyncObj,
{ int deviceId) {
checkCudaErrors(cudaSetDevice(deviceId)); checkCudaErrors(cudaSetDevice(deviceId));
cudaImportNvSciSync(cudaExtResObj.waitSem, syncObj); cudaImportNvSciSync(cudaExtResObj.waitSem, syncObj);
cudaImportNvSciSync(cudaExtResObj.signalSem, cudaSignalerSyncObj); cudaImportNvSciSync(cudaExtResObj.signalSem, cudaSignalerSyncObj);
cudaImportNvSciImage(cudaExtResObj, inputBufObj); cudaImportNvSciImage(cudaExtResObj, inputBufObj);
cudaExtResObj.d_mipLevelArray = (cudaArray_t *) malloc(sizeof(cudaArray_t) * cudaExtResObj.planeCount); cudaExtResObj.d_mipLevelArray =
cudaExtResObj.cudaSurfaceNvmediaBuf = (cudaSurfaceObject_t *) malloc(sizeof(cudaSurfaceObject_t) * cudaExtResObj.planeCount); (cudaArray_t *)malloc(sizeof(cudaArray_t) * cudaExtResObj.planeCount);
cudaExtResObj.cudaSurfaceNvmediaBuf = (cudaSurfaceObject_t *)malloc(
sizeof(cudaSurfaceObject_t) * cudaExtResObj.planeCount);
for (int i = 0; i < cudaExtResObj.planeCount; ++i) { for (int i = 0; i < cudaExtResObj.planeCount; ++i) {
uint32_t mipLevelId = 0; uint32_t mipLevelId = 0;
checkCudaErrors(cudaGetMipmappedArrayLevel(&cudaExtResObj.d_mipLevelArray[i], cudaExtResObj.d_mipmapArray[i], mipLevelId)); checkCudaErrors(
cudaExtResObj.cudaSurfaceNvmediaBuf[i] = createCudaSurface(cudaExtResObj.d_mipLevelArray[i]); cudaGetMipmappedArrayLevel(&cudaExtResObj.d_mipLevelArray[i],
} cudaExtResObj.d_mipmapArray[i], mipLevelId));
cudaExtResObj.cudaSurfaceNvmediaBuf[i] =
createCudaSurface(cudaExtResObj.d_mipLevelArray[i]);
}
cudaExtResObj.stream = createCudaStream(deviceId); cudaExtResObj.stream = createCudaStream(deviceId);
checkCudaErrors(cudaMalloc(&cudaExtResObj.d_outputImage, sizeof(unsigned int) * cudaExtResObj.imageWidth[0] * cudaExtResObj.imageHeight[0])); checkCudaErrors(cudaMalloc(&cudaExtResObj.d_outputImage,
sizeof(unsigned int) *
cudaExtResObj.imageWidth[0] *
cudaExtResObj.imageHeight[0]));
} }
// CUDA clean up buffers used **with** NvSci API. // CUDA clean up buffers used **with** NvSci API.
void cleanupCuda(cudaExternalResInterop& cudaExtResObj) void cleanupCuda(cudaExternalResInterop &cudaExtResObj) {
{ for (int i = 0; i < cudaExtResObj.planeCount; i++) {
for (int i=0; i < cudaExtResObj.planeCount; i++) { checkCudaErrors(
checkCudaErrors(cudaDestroySurfaceObject(cudaExtResObj.cudaSurfaceNvmediaBuf[i])); cudaDestroySurfaceObject(cudaExtResObj.cudaSurfaceNvmediaBuf[i]));
checkCudaErrors(cudaFreeMipmappedArray(cudaExtResObj.d_mipmapArray[i])); checkCudaErrors(cudaFreeMipmappedArray(cudaExtResObj.d_mipmapArray[i]));
} }
free(cudaExtResObj.d_mipmapArray); free(cudaExtResObj.d_mipmapArray);
free(cudaExtResObj.d_mipLevelArray); free(cudaExtResObj.d_mipLevelArray);
free(cudaExtResObj.cudaSurfaceNvmediaBuf); free(cudaExtResObj.cudaSurfaceNvmediaBuf);
free(cudaExtResObj.imageWidth); free(cudaExtResObj.imageWidth);
free(cudaExtResObj.imageHeight); free(cudaExtResObj.imageHeight);
checkCudaErrors(cudaDestroyExternalSemaphore(cudaExtResObj.waitSem)); checkCudaErrors(cudaDestroyExternalSemaphore(cudaExtResObj.waitSem));
checkCudaErrors(cudaDestroyExternalSemaphore(cudaExtResObj.signalSem)); checkCudaErrors(cudaDestroyExternalSemaphore(cudaExtResObj.signalSem));
checkCudaErrors(cudaDestroyExternalMemory(cudaExtResObj.extMemImageBuf)); checkCudaErrors(cudaDestroyExternalMemory(cudaExtResObj.extMemImageBuf));
checkCudaErrors(cudaStreamDestroy(cudaExtResObj.stream)); checkCudaErrors(cudaStreamDestroy(cudaExtResObj.stream));
checkCudaErrors(cudaFree(cudaExtResObj.d_outputImage)); checkCudaErrors(cudaFree(cudaExtResObj.d_outputImage));
} }
void runCudaOperation(cudaExternalResInterop& cudaExtResObj, NvSciSyncFence *cudaWaitFence, void runCudaOperation(cudaExternalResInterop &cudaExtResObj,
NvSciSyncFence *cudaSignalFence, int deviceId, int iterations) NvSciSyncFence *cudaWaitFence,
{ NvSciSyncFence *cudaSignalFence, int deviceId,
checkCudaErrors(cudaSetDevice(deviceId)); int iterations) {
static int64_t launch = 0; checkCudaErrors(cudaSetDevice(deviceId));
static int64_t launch = 0;
waitExternalSemaphore(cudaExtResObj.waitSem, cudaWaitFence, cudaExtResObj.stream); waitExternalSemaphore(cudaExtResObj.waitSem, cudaWaitFence,
cudaExtResObj.stream);
// run cuda kernel over surface object of the LUMA surface part to extract grayscale. // run cuda kernel over surface object of the LUMA surface part to extract
yuvToGrayscaleCudaKernel(cudaExtResObj, cudaExtResObj.imageWidth[0], cudaExtResObj.imageHeight[0]); // grayscale.
yuvToGrayscaleCudaKernel(cudaExtResObj, cudaExtResObj.imageWidth[0],
cudaExtResObj.imageHeight[0]);
// signal fence till the second last iterations for NvMedia2DBlit to wait for cuda signal // signal fence till the second last iterations for NvMedia2DBlit to wait for
// and for final iteration as there is no corresponding NvMedia operation pending // cuda signal and for final iteration as there is no corresponding NvMedia
// therefore we end with cudaStreamSynchronize() // operation pending therefore we end with cudaStreamSynchronize()
if (launch < iterations-1) { if (launch < iterations - 1) {
signalExternalSemaphore(cudaExtResObj.signalSem, cudaSignalFence, cudaExtResObj.stream); signalExternalSemaphore(cudaExtResObj.signalSem, cudaSignalFence,
} cudaExtResObj.stream);
else { } else {
checkCudaErrors(cudaStreamSynchronize(cudaExtResObj.stream)); checkCudaErrors(cudaStreamSynchronize(cudaExtResObj.stream));
} }
launch++; launch++;
} }
// CUDA imports and operates on NvSci buffer/synchronization objects // CUDA imports and operates on NvSci buffer/synchronization objects
void setupCuda(Blit2DTest *ctx, cudaResources &cudaResObj, int deviceId) void setupCuda(Blit2DTest *ctx, cudaResources &cudaResObj, int deviceId) {
{ checkCudaErrors(cudaSetDevice(deviceId));
checkCudaErrors(cudaSetDevice(deviceId)); cudaResObj.d_yuvArray =
cudaResObj.d_yuvArray = (cudaArray_t *) malloc(sizeof(cudaArray_t) * ctx->numSurfaces); (cudaArray_t *)malloc(sizeof(cudaArray_t) * ctx->numSurfaces);
cudaResObj.cudaSurfaceNvmediaBuf = (cudaSurfaceObject_t*) malloc(sizeof(cudaSurfaceObject_t) * ctx->numSurfaces); cudaResObj.cudaSurfaceNvmediaBuf = (cudaSurfaceObject_t *)malloc(
cudaChannelFormatDesc channelDesc; sizeof(cudaSurfaceObject_t) * ctx->numSurfaces);
switch (ctx->bytesPerPixel) { cudaChannelFormatDesc channelDesc;
case 1: switch (ctx->bytesPerPixel) {
default: case 1:
channelDesc = cudaCreateChannelDesc(8, 0, 0, 0, cudaChannelFormatKindUnsigned); default:
break; channelDesc =
} cudaCreateChannelDesc(8, 0, 0, 0, cudaChannelFormatKindUnsigned);
break;
}
for(int k = 0; k < ctx->numSurfaces; k++) { for (int k = 0; k < ctx->numSurfaces; k++) {
checkCudaErrors(cudaMallocArray(&cudaResObj.d_yuvArray[k], &channelDesc, ctx->widthSurface * ctx->xScalePtr[k] * ctx->bytesPerPixel, checkCudaErrors(cudaMallocArray(
ctx->heightSurface * ctx->yScalePtr[k])); &cudaResObj.d_yuvArray[k], &channelDesc,
cudaResObj.cudaSurfaceNvmediaBuf[k] = createCudaSurface(cudaResObj.d_yuvArray[k]); ctx->widthSurface * ctx->xScalePtr[k] * ctx->bytesPerPixel,
} ctx->heightSurface * ctx->yScalePtr[k]));
checkCudaErrors(cudaMalloc(&cudaResObj.d_outputImage, sizeof(unsigned int) * ctx->widthSurface * ctx->heightSurface)); cudaResObj.cudaSurfaceNvmediaBuf[k] =
createCudaSurface(cudaResObj.d_yuvArray[k]);
}
checkCudaErrors(cudaMalloc(
&cudaResObj.d_outputImage,
sizeof(unsigned int) * ctx->widthSurface * ctx->heightSurface));
cudaResObj.stream = createCudaStream(deviceId); cudaResObj.stream = createCudaStream(deviceId);
} }
// CUDA clean up buffers used **without** NvSci API. // CUDA clean up buffers used **without** NvSci API.
void cleanupCuda(Blit2DTest *ctx, cudaResources &cudaResObj) void cleanupCuda(Blit2DTest *ctx, cudaResources &cudaResObj) {
{ for (int k = 0; k < ctx->numSurfaces; k++) {
for(int k = 0; k < ctx->numSurfaces; k++) { checkCudaErrors(
checkCudaErrors(cudaDestroySurfaceObject(cudaResObj.cudaSurfaceNvmediaBuf[k])); cudaDestroySurfaceObject(cudaResObj.cudaSurfaceNvmediaBuf[k]));
checkCudaErrors(cudaFreeArray(cudaResObj.d_yuvArray[k])); checkCudaErrors(cudaFreeArray(cudaResObj.d_yuvArray[k]));
} }
free(cudaResObj.cudaSurfaceNvmediaBuf); free(cudaResObj.cudaSurfaceNvmediaBuf);
checkCudaErrors(cudaStreamDestroy(cudaResObj.stream)); checkCudaErrors(cudaStreamDestroy(cudaResObj.stream));
checkCudaErrors(cudaFree(cudaResObj.d_outputImage)); checkCudaErrors(cudaFree(cudaResObj.d_outputImage));
} }
static void yuvToGrayscaleCudaKernelNonNvSci(cudaResources &cudaResObj, int deviceId, int32_t imageWidth, int32_t imageHeight) static void yuvToGrayscaleCudaKernelNonNvSci(cudaResources &cudaResObj,
{ int deviceId, int32_t imageWidth,
int32_t imageHeight) {
#if WRITE_OUTPUT_IMAGE #if WRITE_OUTPUT_IMAGE
unsigned int *h_dstImage; unsigned int *h_dstImage;
checkCudaErrors(cudaMallocHost(&h_dstImage, sizeof(unsigned int)*imageHeight*imageWidth)); checkCudaErrors(cudaMallocHost(
&h_dstImage, sizeof(unsigned int) * imageHeight * imageWidth));
#endif #endif
dim3 block(16, 16, 1); dim3 block(16, 16, 1);
dim3 grid((imageWidth/block.x)+1, (imageHeight/block.y)+1, 1); dim3 grid((imageWidth / block.x) + 1, (imageHeight / block.y) + 1, 1);
yuvToGrayscale<<<grid, block, 0, cudaResObj.stream>>>(cudaResObj.cudaSurfaceNvmediaBuf[0], cudaResObj.d_outputImage, imageWidth, imageHeight); yuvToGrayscale<<<grid, block, 0, cudaResObj.stream>>>(
cudaResObj.cudaSurfaceNvmediaBuf[0], cudaResObj.d_outputImage, imageWidth,
imageHeight);
#if WRITE_OUTPUT_IMAGE #if WRITE_OUTPUT_IMAGE
checkCudaErrors(cudaMemcpyAsync(h_dstImage, cudaResObj.d_outputImage, sizeof(unsigned int)*imageHeight*imageWidth, cudaMemcpyDeviceToHost, cudaResObj.stream)); checkCudaErrors(
checkCudaErrors(cudaStreamSynchronize(cudaResObj.stream)); cudaMemcpyAsync(h_dstImage, cudaResObj.d_outputImage,
char outputFilename[1024]; sizeof(unsigned int) * imageHeight * imageWidth,
std::string image_filename = "Grayscale"; cudaMemcpyDeviceToHost, cudaResObj.stream));
strcpy(outputFilename, image_filename.c_str()); checkCudaErrors(cudaStreamSynchronize(cudaResObj.stream));
strcpy(outputFilename + image_filename.length(), "_non-nvsci_out.ppm"); char outputFilename[1024];
sdkSavePPM4ub(outputFilename, (unsigned char *)h_dstImage, imageWidth, imageHeight); std::string image_filename = "Grayscale";
printf("Wrote '%s'\n", outputFilename); strcpy(outputFilename, image_filename.c_str());
checkCudaErrors(cudaFreeHost(h_dstImage)); strcpy(outputFilename + image_filename.length(), "_non-nvsci_out.ppm");
sdkSavePPM4ub(outputFilename, (unsigned char *)h_dstImage, imageWidth,
imageHeight);
printf("Wrote '%s'\n", outputFilename);
checkCudaErrors(cudaFreeHost(h_dstImage));
#else #else
checkCudaErrors(cudaStreamSynchronize(cudaResObj.stream)); checkCudaErrors(cudaStreamSynchronize(cudaResObj.stream));
#endif #endif
} }
// CUDA operates **without** NvSci APIs buffer/synchronization objects. // CUDA operates **without** NvSci APIs buffer/synchronization objects.
void runCudaOperation(Blit2DTest *ctx, cudaResources &cudaResObj, int deviceId) void runCudaOperation(Blit2DTest *ctx, cudaResources &cudaResObj,
{ int deviceId) {
for(int k = 0; k < ctx->numSurfaces; k++) { for (int k = 0; k < ctx->numSurfaces; k++) {
checkCudaErrors(cudaMemcpy2DToArray(cudaResObj.d_yuvArray[k], 0, 0, ctx->dstBuff[k], checkCudaErrors(cudaMemcpy2DToArray(
ctx->widthSurface * ctx->xScalePtr[k] * ctx->bytesPerPixel, cudaResObj.d_yuvArray[k], 0, 0, ctx->dstBuff[k],
ctx->widthSurface * ctx->xScalePtr[k] * ctx->bytesPerPixel, ctx->widthSurface * ctx->xScalePtr[k] * ctx->bytesPerPixel,
ctx->heightSurface * ctx->yScalePtr[k], cudaMemcpyHostToDevice)); ctx->widthSurface * ctx->xScalePtr[k] * ctx->bytesPerPixel,
} ctx->heightSurface * ctx->yScalePtr[k], cudaMemcpyHostToDevice));
// run cuda kernel over surface object of the LUMA surface part to extract grayscale. }
yuvToGrayscaleCudaKernelNonNvSci(cudaResObj, deviceId, ctx->widthSurface, ctx->heightSurface); // run cuda kernel over surface object of the LUMA surface part to extract
// grayscale.
yuvToGrayscaleCudaKernelNonNvSci(cudaResObj, deviceId, ctx->widthSurface,
ctx->heightSurface);
} }

View File

@@ -25,7 +25,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef __CUDA_BUFIMPORT_KERNEL_H__ #ifndef __CUDA_BUFIMPORT_KERNEL_H__
#define __CUDA_BUFIMPORT_KERNEL_H__ #define __CUDA_BUFIMPORT_KERNEL_H__
@@ -35,38 +34,39 @@
#include "nvscisync.h" #include "nvscisync.h"
#include "nvmedia_utils/cmdline.h" #include "nvmedia_utils/cmdline.h"
struct cudaExternalResInterop struct cudaExternalResInterop {
{ cudaMipmappedArray_t *d_mipmapArray;
cudaMipmappedArray_t *d_mipmapArray; cudaArray_t *d_mipLevelArray;
cudaArray_t *d_mipLevelArray; cudaSurfaceObject_t *cudaSurfaceNvmediaBuf;
cudaSurfaceObject_t *cudaSurfaceNvmediaBuf; cudaStream_t stream;
cudaStream_t stream; cudaExternalMemory_t extMemImageBuf;
cudaExternalMemory_t extMemImageBuf; cudaExternalSemaphore_t waitSem;
cudaExternalSemaphore_t waitSem; cudaExternalSemaphore_t signalSem;
cudaExternalSemaphore_t signalSem;
int32_t planeCount; int32_t planeCount;
int32_t *imageWidth; uint64_t *planeOffset;
int32_t *imageHeight; int32_t *imageWidth;
unsigned int *d_outputImage; int32_t *imageHeight;
unsigned int *d_outputImage;
}; };
struct cudaResources struct cudaResources {
{ cudaArray_t *d_yuvArray;
cudaArray_t *d_yuvArray; cudaStream_t stream;
cudaStream_t stream; cudaSurfaceObject_t *cudaSurfaceNvmediaBuf;
cudaSurfaceObject_t *cudaSurfaceNvmediaBuf; unsigned int *d_outputImage;
unsigned int *d_outputImage;
}; };
void runCudaOperation(cudaExternalResInterop& cudaExtResObj, NvSciSyncFence *fence, void runCudaOperation(cudaExternalResInterop &cudaExtResObj,
NvSciSyncFence *cudaSignalfence, int deviceId, int iterations); NvSciSyncFence *fence, NvSciSyncFence *cudaSignalfence,
int deviceId, int iterations);
void runCudaOperation(Blit2DTest *ctx, cudaResources &cudaResObj, int deviceId); void runCudaOperation(Blit2DTest *ctx, cudaResources &cudaResObj, int deviceId);
void setupCuda(cudaExternalResInterop& cudaExtResObj, NvSciBufObj& inputBufObj, void setupCuda(cudaExternalResInterop &cudaExtResObj, NvSciBufObj &inputBufObj,
NvSciSyncObj &syncObj, NvSciSyncObj &cudaSignalerSyncObj, int deviceId); NvSciSyncObj &syncObj, NvSciSyncObj &cudaSignalerSyncObj,
int deviceId);
void setupCuda(Blit2DTest *ctx, cudaResources &cudaResObj, int deviceId); void setupCuda(Blit2DTest *ctx, cudaResources &cudaResObj, int deviceId);
void cleanupCuda(cudaExternalResInterop& cudaObjs); void cleanupCuda(cudaExternalResInterop &cudaObjs);
void cleanupCuda(Blit2DTest *ctx, cudaResources &cudaResObj); void cleanupCuda(Blit2DTest *ctx, cudaResources &cudaResObj);
#endif #endif

View File

@@ -55,144 +55,156 @@
fflush(stdout); \ fflush(stdout); \
exit(EXIT_FAILURE); \ exit(EXIT_FAILURE); \
} \ } \
} while (0) } while (0)
static void cleanup(Blit2DTest* ctx, NvMediaStatus status) static void cleanup(Blit2DTest* ctx, NvMediaStatus status) {
{ if (ctx->i2d != NULL) {
if (ctx->i2d != NULL) { NvMedia2DDestroy(ctx->i2d);
NvMedia2DDestroy(ctx->i2d); }
}
if (ctx->device != NULL) { if (ctx->device != NULL) {
NvMediaDeviceDestroy(ctx->device); NvMediaDeviceDestroy(ctx->device);
} }
if (status != NVMEDIA_STATUS_OK) { if (status != NVMEDIA_STATUS_OK) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
int main(int argc, char* argv[]) {
TestArgs args;
Blit2DTest ctx;
NvMediaStatus status = NVMEDIA_STATUS_ERROR;
NvSciSyncFence nvMediaSignalerFence = NvSciSyncFenceInitializer;
NvSciSyncFence cudaSignalerFence = NvSciSyncFenceInitializer;
int main (int argc, char *argv[]) int cudaDeviceId;
{ uint64_t startTime, endTime;
TestArgs args; uint64_t operationStartTime, operationEndTime;
Blit2DTest ctx; double processingTime;
NvMediaStatus status = NVMEDIA_STATUS_ERROR;
NvSciSyncFence nvMediaSignalerFence = NvSciSyncFenceInitializer;
NvSciSyncFence cudaSignalerFence = NvSciSyncFenceInitializer;
int cudaDeviceId; /* Read configuration from command line and config file */
uint64_t startTime, endTime; memset(&args, 0, sizeof(TestArgs));
uint64_t operationStartTime, operationEndTime; memset(&ctx, 0, sizeof(Blit2DTest));
double processingTime;
/* Read configuration from command line and config file */ /* ParseArgs parses the command line and the 2D configuration file and
memset(&args, 0, sizeof(TestArgs)); * populates all initParams and run time configuration in to appropriate
memset(&ctx, 0, sizeof(Blit2DTest)); * structures within args
*/
/* ParseArgs parses the command line and the 2D configuration file and populates all initParams if (ParseArgs(argc, argv, &args)) {
* and run time configuration in to appropriate structures within args PrintUsage();
*/ return -1;
if (ParseArgs(argc, argv, &args)) { }
PrintUsage(); /* Check version */
return -1; NvMediaVersion version;
} status = NvMedia2DGetVersion(&version);
/* Check version */ if (status == NVMEDIA_STATUS_OK) {
NvMediaVersion version; printf("Library version: %u.%u\n", version.major, version.minor);
status = NvMedia2DGetVersion(&version); printf("Header version: %u.%u\n", NVMEDIA_2D_VERSION_MAJOR,
if (status == NVMEDIA_STATUS_OK) { NVMEDIA_2D_VERSION_MINOR);
printf("Library version: %u.%u\n", version.major, version.minor); if ((version.major != NVMEDIA_2D_VERSION_MAJOR) ||
printf("Header version: %u.%u\n", NVMEDIA_2D_VERSION_MAJOR, NVMEDIA_2D_VERSION_MINOR); (version.minor != NVMEDIA_2D_VERSION_MINOR)) {
if ((version.major != NVMEDIA_2D_VERSION_MAJOR) || printf("Library and Header mismatch!\n");
(version.minor != NVMEDIA_2D_VERSION_MINOR)) { cleanup(&ctx, status);
printf("Library and Header mismatch!\n");
cleanup(&ctx, status);
}
} }
}
// Create NvMedia device // Create NvMedia device
ctx.device = NvMediaDeviceCreate(); ctx.device = NvMediaDeviceCreate();
if(!ctx.device) { if (!ctx.device) {
printf("%s: Failed to create NvMedia device\n", __func__); printf("%s: Failed to create NvMedia device\n", __func__);
cleanup(&ctx, status); cleanup(&ctx, status);
} }
// Create 2D blitter // Create 2D blitter
ctx.i2d = NvMedia2DCreate(ctx.device); ctx.i2d = NvMedia2DCreate(ctx.device);
if(!ctx.i2d) { if (!ctx.i2d) {
printf("%s: Failed to create NvMedia 2D i2d\n", __func__); printf("%s: Failed to create NvMedia 2D i2d\n", __func__);
cleanup(&ctx, status); cleanup(&ctx, status);
} }
cudaDeviceId = findCudaDevice(argc, (const char**)argv); cudaDeviceId = findCudaDevice(argc, (const char**)argv);
// NvMedia-CUDA operations without NvSCI APIs starts // NvMedia-CUDA operations without NvSCI APIs starts
cudaResources cudaResObj; cudaResources cudaResObj;
GetTimeMicroSec(&startTime); GetTimeMicroSec(&startTime);
setupNvMedia(&args, &ctx); setupNvMedia(&args, &ctx);
setupCuda(&ctx, cudaResObj, cudaDeviceId); setupCuda(&ctx, cudaResObj, cudaDeviceId);
GetTimeMicroSec(&operationStartTime); GetTimeMicroSec(&operationStartTime);
for (int i = 0; i < args.iterations; i++) for (int i = 0; i < args.iterations; i++) {
{ runNvMediaBlit2D(&args, &ctx);
runNvMediaBlit2D(&args, &ctx); runCudaOperation(&ctx, cudaResObj, cudaDeviceId);
runCudaOperation(&ctx, cudaResObj, cudaDeviceId); }
} GetTimeMicroSec(&operationEndTime);
GetTimeMicroSec(&operationEndTime);
cleanupNvMedia(&ctx); cleanupNvMedia(&ctx);
cleanupCuda(&ctx, cudaResObj); cleanupCuda(&ctx, cudaResObj);
GetTimeMicroSec(&endTime); GetTimeMicroSec(&endTime);
// NvMedia-CUDA operations without NvSCI APIs ends // NvMedia-CUDA operations without NvSCI APIs ends
processingTime = (double)(operationEndTime - operationStartTime)/1000.0; processingTime = (double)(operationEndTime - operationStartTime) / 1000.0;
printf("Overall Processing time of NvMedia-CUDA Operations without NvSCI APIs %.4f ms with %zu iterations\n", processingTime, args.iterations); printf(
processingTime = (double)(endTime - startTime)/1000.0; "Overall Processing time of NvMedia-CUDA Operations without NvSCI APIs "
printf("Overall Processing time of NvMedia-CUDA Operations + allocation/cleanup without NvSCI APIs %.4f ms with %zu iterations\n", processingTime, args.iterations); "%.4f ms with %zu iterations\n",
processingTime, args.iterations);
processingTime = (double)(endTime - startTime) / 1000.0;
printf(
"Overall Processing time of NvMedia-CUDA Operations + allocation/cleanup "
"without NvSCI APIs %.4f ms with %zu iterations\n",
processingTime, args.iterations);
NvSciBufObj dstNvSciBufobj, srcNvSciBufobj; NvSciBufObj dstNvSciBufobj, srcNvSciBufobj;
NvSciSyncObj nvMediaSignalerSyncObj, cudaSignalerSyncObj; NvSciSyncObj nvMediaSignalerSyncObj, cudaSignalerSyncObj;
cudaExternalResInterop cudaExtResObj; cudaExternalResInterop cudaExtResObj;
// NvMedia-CUDA operations via interop with NvSCI APIs starts // NvMedia-CUDA operations via interop with NvSCI APIs starts
GetTimeMicroSec(&startTime); GetTimeMicroSec(&startTime);
setupNvMediaSignalerNvSciSync(&ctx, nvMediaSignalerSyncObj, cudaDeviceId); setupNvMediaSignalerNvSciSync(&ctx, nvMediaSignalerSyncObj, cudaDeviceId);
setupCudaSignalerNvSciSync(&ctx, cudaSignalerSyncObj, cudaDeviceId); setupCudaSignalerNvSciSync(&ctx, cudaSignalerSyncObj, cudaDeviceId);
setupNvMedia(&args, &ctx, srcNvSciBufobj, dstNvSciBufobj, nvMediaSignalerSyncObj, cudaSignalerSyncObj, cudaDeviceId); setupNvMedia(&args, &ctx, srcNvSciBufobj, dstNvSciBufobj,
setupCuda(cudaExtResObj, dstNvSciBufobj, nvMediaSignalerSyncObj, cudaSignalerSyncObj, cudaDeviceId); nvMediaSignalerSyncObj, cudaSignalerSyncObj, cudaDeviceId);
setupCuda(cudaExtResObj, dstNvSciBufobj, nvMediaSignalerSyncObj,
cudaSignalerSyncObj, cudaDeviceId);
GetTimeMicroSec(&operationStartTime); GetTimeMicroSec(&operationStartTime);
for (int i = 0; i < args.iterations; i++) for (int i = 0; i < args.iterations; i++) {
{ runNvMediaBlit2D(&args, &ctx, nvMediaSignalerSyncObj, &cudaSignalerFence,
runNvMediaBlit2D(&args, &ctx, nvMediaSignalerSyncObj, &cudaSignalerFence, &nvMediaSignalerFence); &nvMediaSignalerFence);
runCudaOperation(cudaExtResObj, &nvMediaSignalerFence, &cudaSignalerFence, cudaDeviceId, args.iterations); runCudaOperation(cudaExtResObj, &nvMediaSignalerFence, &cudaSignalerFence,
} cudaDeviceId, args.iterations);
GetTimeMicroSec(&operationEndTime); }
GetTimeMicroSec(&operationEndTime);
cleanupNvMedia(&ctx, nvMediaSignalerSyncObj, cudaSignalerSyncObj); cleanupNvMedia(&ctx, nvMediaSignalerSyncObj, cudaSignalerSyncObj);
cleanupCuda(cudaExtResObj); cleanupCuda(cudaExtResObj);
cleanupNvSciSync(nvMediaSignalerSyncObj); cleanupNvSciSync(nvMediaSignalerSyncObj);
cleanupNvSciSync(cudaSignalerSyncObj); cleanupNvSciSync(cudaSignalerSyncObj);
cleanupNvSciBuf(srcNvSciBufobj); cleanupNvSciBuf(srcNvSciBufobj);
cleanupNvSciBuf(dstNvSciBufobj); cleanupNvSciBuf(dstNvSciBufobj);
GetTimeMicroSec(&endTime); GetTimeMicroSec(&endTime);
// NvMedia-CUDA operations via interop with NvSCI APIs ends // NvMedia-CUDA operations via interop with NvSCI APIs ends
processingTime = (double)(operationEndTime - operationStartTime)/1000.0; processingTime = (double)(operationEndTime - operationStartTime) / 1000.0;
printf("Overall Processing time of NvMedia-CUDA Operations with NvSCI APIs %.4f ms with %zu iterations\n", processingTime, args.iterations); printf(
processingTime = (double)(endTime - startTime)/1000.0; "Overall Processing time of NvMedia-CUDA Operations with NvSCI APIs %.4f "
printf("Overall Processing time of NvMedia-CUDA Operations + allocation/cleanup with NvSCI APIs %.4f ms with %zu iterations\n", processingTime, args.iterations); "ms with %zu iterations\n",
processingTime, args.iterations);
processingTime = (double)(endTime - startTime) / 1000.0;
printf(
"Overall Processing time of NvMedia-CUDA Operations + allocation/cleanup "
"with NvSCI APIs %.4f ms with %zu iterations\n",
processingTime, args.iterations);
if (ctx.i2d != NULL) { if (ctx.i2d != NULL) {
NvMedia2DDestroy(ctx.i2d); NvMedia2DDestroy(ctx.i2d);
} }
if (ctx.device != NULL) { if (ctx.device != NULL) {
NvMediaDeviceDestroy(ctx.device); NvMediaDeviceDestroy(ctx.device);
} }
if (status == NVMEDIA_STATUS_OK) { if (status == NVMEDIA_STATUS_OK) {
return 0; return 0;
} } else {
else { return 1;
return 1; }
}
} }

View File

@@ -38,463 +38,434 @@
#include "nvmedia_2d_nvscisync.h" #include "nvmedia_2d_nvscisync.h"
#include "nvsci_setup.h" #include "nvsci_setup.h"
NvMediaImage * NvMediaImage *NvMediaImageCreateUsingNvScibuf(NvMediaDevice *device,
NvMediaImageCreateUsingNvScibuf( NvMediaSurfaceType type,
NvMediaDevice *device, const NvMediaSurfAllocAttr *attrs,
NvMediaSurfaceType type, uint32_t numAttrs, uint32_t flags,
const NvMediaSurfAllocAttr *attrs, NvSciBufObj &bufobj,
uint32_t numAttrs, int cudaDeviceId) {
uint32_t flags, NvSciBufModule module = NULL;
NvSciBufObj &bufobj, NvSciError err = NvSciError_Success;
int cudaDeviceId) NvMediaStatus status = NVMEDIA_STATUS_OK;
{ NvSciBufAttrList attrlist = NULL;
NvSciBufModule module = NULL; NvSciBufAttrList conflictlist = NULL;
NvSciError err = NvSciError_Success; NvSciBufAttrValAccessPerm access_perm = NvSciBufAccessPerm_ReadWrite;
NvMediaStatus status = NVMEDIA_STATUS_OK; NvSciBufAttrKeyValuePair attr_kvp = {NvSciBufGeneralAttrKey_RequiredPerm,
NvSciBufAttrList attrlist = NULL; &access_perm, sizeof(access_perm)};
NvSciBufAttrList conflictlist = NULL; NvSciBufAttrKeyValuePair pairArrayOut[10];
NvSciBufAttrValAccessPerm access_perm = NvSciBufAccessPerm_ReadWrite;
NvSciBufAttrKeyValuePair attr_kvp = {NvSciBufGeneralAttrKey_RequiredPerm,
&access_perm,
sizeof(access_perm)};
NvSciBufAttrKeyValuePair pairArrayOut[10];
NvMediaImage *image = NULL; NvMediaImage *image = NULL;
err = NvSciBufModuleOpen(&module); err = NvSciBufModuleOpen(&module);
if(err != NvSciError_Success) { if (err != NvSciError_Success) {
printf("%s: NvSciBuffModuleOpen failed. Error: %d \n", __func__, err); printf("%s: NvSciBuffModuleOpen failed. Error: %d \n", __func__, err);
goto fail_cleanup; goto fail_cleanup;
} }
err = NvSciBufAttrListCreate(module, &attrlist); err = NvSciBufAttrListCreate(module, &attrlist);
if(err != NvSciError_Success) { if (err != NvSciError_Success) {
printf("%s: SciBufAttrListCreate failed. Error: %d \n", __func__, err); printf("%s: SciBufAttrListCreate failed. Error: %d \n", __func__, err);
goto fail_cleanup; goto fail_cleanup;
} }
err = NvSciBufAttrListSetAttrs(attrlist, &attr_kvp, 1); err = NvSciBufAttrListSetAttrs(attrlist, &attr_kvp, 1);
if(err != NvSciError_Success) { if (err != NvSciError_Success) {
printf("%s: AccessPermSetAttr failed. Error: %d \n", __func__, err); printf("%s: AccessPermSetAttr failed. Error: %d \n", __func__, err);
goto fail_cleanup; goto fail_cleanup;
} }
status = NvMediaImageFillNvSciBufAttrs(device, status =
type, NvMediaImageFillNvSciBufAttrs(device, type, attrs, numAttrs, 0, attrlist);
attrs,
numAttrs,
0,
attrlist);
if (status != NVMEDIA_STATUS_OK) {
printf("%s: ImageFillSciBufAttrs failed. Error: %d \n", __func__, err);
goto fail_cleanup;
}
if(status != NVMEDIA_STATUS_OK) { setupNvSciBuf(bufobj, attrlist, cudaDeviceId);
printf("%s: ImageFillSciBufAttrs failed. Error: %d \n", __func__, err);
goto fail_cleanup;
}
setupNvSciBuf(bufobj, attrlist, cudaDeviceId); status = NvMediaImageCreateFromNvSciBuf(device, bufobj, &image);
status = NvMediaImageCreateFromNvSciBuf(device, if (status != NVMEDIA_STATUS_OK) {
bufobj, printf("%s: ImageCreatefromSciBuf failed. Error: %d \n", __func__, err);
&image); goto fail_cleanup;
}
if(status != NVMEDIA_STATUS_OK) { NvSciBufAttrListFree(attrlist);
printf("%s: ImageCreatefromSciBuf failed. Error: %d \n", __func__, err);
goto fail_cleanup;
}
NvSciBufAttrListFree(attrlist); if (module != NULL) {
NvSciBufModuleClose(module);
}
if(module != NULL) { return image;
NvSciBufModuleClose(module);
}
return image;
fail_cleanup: fail_cleanup:
if(attrlist != NULL) { if (attrlist != NULL) {
NvSciBufAttrListFree(attrlist); NvSciBufAttrListFree(attrlist);
} }
if(bufobj != NULL) { if (bufobj != NULL) {
NvSciBufObjFree(bufobj); NvSciBufObjFree(bufobj);
bufobj = NULL; bufobj = NULL;
} }
if(module != NULL) { if (module != NULL) {
NvSciBufModuleClose(module); NvSciBufModuleClose(module);
} }
NvMediaImageDestroy(image); NvMediaImageDestroy(image);
return NULL; return NULL;
} }
/* Create NvMediaImage surface based on the input attributes. /* Create NvMediaImage surface based on the input attributes.
* Returns NVMEDIA_STATUS_OK on success * Returns NVMEDIA_STATUS_OK on success
*/ */
static NvMediaStatus static NvMediaStatus createSurface(Blit2DTest *ctx,
createSurface(Blit2DTest *ctx, NvMediaSurfFormatAttr *surfFormatAttrs,
NvMediaSurfFormatAttr *surfFormatAttrs, NvMediaSurfAllocAttr *surfAllocAttrs,
NvMediaSurfAllocAttr *surfAllocAttrs, uint32_t numSurfAllocAttrs,
uint32_t numSurfAllocAttrs, NvMediaImage **image, NvSciBufObj &bufObj,
NvMediaImage **image, int cudaDeviceId) {
NvSciBufObj &bufObj, NvMediaSurfaceType surfType;
int cudaDeviceId)
{
NvMediaSurfaceType surfType;
/* create source image */ /* create source image */
surfType = NvMediaSurfaceFormatGetType(surfFormatAttrs, NVM_SURF_FMT_ATTR_MAX); surfType =
*image = NvMediaImageCreateUsingNvScibuf(ctx->device, /* device */ NvMediaSurfaceFormatGetType(surfFormatAttrs, NVM_SURF_FMT_ATTR_MAX);
surfType, /* surface type */ *image = NvMediaImageCreateUsingNvScibuf(ctx->device, /* device */
surfAllocAttrs, surfType, /* surface type */
numSurfAllocAttrs, surfAllocAttrs, numSurfAllocAttrs, 0,
0, bufObj, cudaDeviceId);
bufObj,
cudaDeviceId);
if(*image == NULL) { if (*image == NULL) {
printf ("Unable to create image\n"); printf("Unable to create image\n");
return NVMEDIA_STATUS_ERROR; return NVMEDIA_STATUS_ERROR;
} }
InitImage (*image, surfAllocAttrs[0].value, surfAllocAttrs[1].value); InitImage(*image, surfAllocAttrs[0].value, surfAllocAttrs[1].value);
/* printf("%s: NvMediaImageCreate:: Image size: %ux%u Image type: %d\n", /* printf("%s: NvMediaImageCreate:: Image size: %ux%u Image type: %d\n",
__func__, surfAllocAttrs[0].value, surfAllocAttrs[1].value, surfType);*/ __func__, surfAllocAttrs[0].value, surfAllocAttrs[1].value,
surfType);*/
return NVMEDIA_STATUS_OK; return NVMEDIA_STATUS_OK;
} }
/* Create NvMediaImage surface based on the input attributes. /* Create NvMediaImage surface based on the input attributes.
* Returns NVMEDIA_STATUS_OK on success * Returns NVMEDIA_STATUS_OK on success
*/ */
static NvMediaStatus static NvMediaStatus createSurfaceNonNvSCI(
createSurfaceNonNvSCI(Blit2DTest *ctx, Blit2DTest *ctx, NvMediaSurfFormatAttr *surfFormatAttrs,
NvMediaSurfFormatAttr *surfFormatAttrs, NvMediaSurfAllocAttr *surfAllocAttrs, uint32_t numSurfAllocAttrs,
NvMediaSurfAllocAttr *surfAllocAttrs, NvMediaImage **image) {
uint32_t numSurfAllocAttrs, NvMediaSurfaceType surfType;
NvMediaImage **image)
{
NvMediaSurfaceType surfType;
/* create source image */ /* create source image */
surfType = NvMediaSurfaceFormatGetType(surfFormatAttrs, NVM_SURF_FMT_ATTR_MAX); surfType =
NvMediaSurfaceFormatGetType(surfFormatAttrs, NVM_SURF_FMT_ATTR_MAX);
*image = NvMediaImageCreateNew(ctx->device, surfType, surfAllocAttrs, numSurfAllocAttrs, 0); *image = NvMediaImageCreateNew(ctx->device, surfType, surfAllocAttrs,
numSurfAllocAttrs, 0);
if(*image == NULL) { if (*image == NULL) {
printf ("Unable to create image\n"); printf("Unable to create image\n");
return NVMEDIA_STATUS_ERROR; return NVMEDIA_STATUS_ERROR;
} }
InitImage (*image, surfAllocAttrs[0].value, surfAllocAttrs[1].value); InitImage(*image, surfAllocAttrs[0].value, surfAllocAttrs[1].value);
/* printf("%s: NvMediaImageCreate:: Image size: %ux%u Image type: %d\n", /* printf("%s: NvMediaImageCreate:: Image size: %ux%u Image type: %d\n",
__func__, surfAllocAttrs[0].value, surfAllocAttrs[1].value, surfType);*/ __func__, surfAllocAttrs[0].value, surfAllocAttrs[1].value,
surfType);*/
return NVMEDIA_STATUS_OK; return NVMEDIA_STATUS_OK;
} }
static void destroySurface(NvMediaImage *image) { NvMediaImageDestroy(image); }
static void destroySurface(NvMediaImage *image) static NvMediaStatus blit2DImage(Blit2DTest *ctx, TestArgs *args,
{ NvSciSyncObj &nvMediaSignalerSyncObj,
NvMediaImageDestroy(image); NvSciSyncFence *preSyncFence,
} NvSciSyncFence *fence) {
NvMediaStatus status;
NvMediaImageSurfaceMap surfaceMap;
status = ReadImage(args->inputFileName, /* fileName */
0, /* frameNum */
args->srcSurfAllocAttrs[0].value, /* source image width */
args->srcSurfAllocAttrs[1].value, /* source image height */
ctx->srcImage, /* srcImage */
NVMEDIA_TRUE, /* uvOrderFlag */
1, /* bytesPerPixel */
MSB_ALIGNED); /* pixelAlignment */
static NvMediaStatus blit2DImage(Blit2DTest *ctx, TestArgs* args, NvSciSyncObj &nvMediaSignalerSyncObj, if (status != NVMEDIA_STATUS_OK) {
NvSciSyncFence *preSyncFence, NvSciSyncFence *fence) printf("%s: ReadImage failed for input buffer: %d\n", __func__, status);
{ return status;
NvMediaStatus status; }
NvMediaImageSurfaceMap surfaceMap;
status = ReadImage(args->inputFileName, /* fileName */ if ((args->srcRect.x1 <= args->srcRect.x0) ||
0, /* frameNum */ (args->srcRect.y1 <= args->srcRect.y0)) {
args->srcSurfAllocAttrs[0].value, /* source image width */ ctx->srcRect = NULL;
args->srcSurfAllocAttrs[1].value, /* source image height */ } else {
ctx->srcImage, /* srcImage */ ctx->srcRect = &(args->srcRect);
NVMEDIA_TRUE, /* uvOrderFlag */ }
1, /* bytesPerPixel */
MSB_ALIGNED); /* pixelAlignment */
if ((args->dstRect.x1 <= args->dstRect.x0) ||
(args->dstRect.y1 <= args->dstRect.y0)) {
ctx->dstRect = NULL;
} else {
ctx->dstRect = &(args->dstRect);
}
static int64_t launch = 0;
// Start inserting pre-fence from second launch inorder to for NvMedia2Blit to
// wait
// for cuda signal on fence.
if (launch) {
status = NvMedia2DInsertPreNvSciSyncFence(ctx->i2d, preSyncFence);
if (status != NVMEDIA_STATUS_OK) { if (status != NVMEDIA_STATUS_OK) {
printf("%s: ReadImage failed for input buffer: %d\n", __func__, status); printf("%s: NvMedia2DSetNvSciSyncObjforEOF failed: %d\n", __func__,
return status; status);
return status;
} }
NvSciSyncFenceClear(preSyncFence);
}
launch++;
if ((args->srcRect.x1 <= args->srcRect.x0) || (args->srcRect.y1 <= args->srcRect.y0)) { status = NvMedia2DSetNvSciSyncObjforEOF(ctx->i2d, nvMediaSignalerSyncObj);
ctx->srcRect = NULL; if (status != NVMEDIA_STATUS_OK) {
} else { printf("%s: NvMedia2DSetNvSciSyncObjforEOF failed: %d\n", __func__,
ctx->srcRect = &(args->srcRect); status);
} return status;
}
if ((args->dstRect.x1 <= args->dstRect.x0) || (args->dstRect.y1 <= args->dstRect.y0)) { /* 2DBlit processing on input image */
ctx->dstRect = NULL; status = NvMedia2DBlitEx(ctx->i2d, /* i2d */
} else { ctx->dstImage, /* dstSurface */
ctx->dstRect = &(args->dstRect); ctx->dstRect, /* dstRect */
} ctx->srcImage, /* srcSurface */
ctx->srcRect, /* srcRect */
&args->blitParams, /* params */
NULL); /* paramsOut */
static int64_t launch = 0; if (status != NVMEDIA_STATUS_OK) {
// Start inserting pre-fence from second launch inorder to for NvMedia2Blit to wait printf("%s: NvMedia2DBlitEx failed: %d\n", __func__, status);
// for cuda signal on fence. return status;
if (launch) }
{
status = NvMedia2DInsertPreNvSciSyncFence(ctx->i2d, preSyncFence);
if(status != NVMEDIA_STATUS_OK) {
printf("%s: NvMedia2DSetNvSciSyncObjforEOF failed: %d\n", __func__, status);
return status;
}
NvSciSyncFenceClear(preSyncFence);
}
launch++;
status = NvMedia2DSetNvSciSyncObjforEOF(ctx->i2d, nvMediaSignalerSyncObj); status =
if(status != NVMEDIA_STATUS_OK) { NvMedia2DGetEOFNvSciSyncFence(ctx->i2d, nvMediaSignalerSyncObj, fence);
printf("%s: NvMedia2DSetNvSciSyncObjforEOF failed: %d\n", __func__, status); if (status != NVMEDIA_STATUS_OK) {
return status; printf("%s: NvMedia2DGetEOFNvSciSyncFence failed: %d\n", __func__, status);
} return status;
}
/* 2DBlit processing on input image */ return NVMEDIA_STATUS_OK;
status = NvMedia2DBlitEx(ctx->i2d, /* i2d */
ctx->dstImage, /* dstSurface */
ctx->dstRect, /* dstRect */
ctx->srcImage, /* srcSurface */
ctx->srcRect, /* srcRect */
&args->blitParams, /* params */
NULL); /* paramsOut */
if(status != NVMEDIA_STATUS_OK) {
printf("%s: NvMedia2DBlitEx failed: %d\n", __func__, status);
return status;
}
status = NvMedia2DGetEOFNvSciSyncFence(ctx->i2d, nvMediaSignalerSyncObj, fence);
if(status != NVMEDIA_STATUS_OK) {
printf("%s: NvMedia2DGetEOFNvSciSyncFence failed: %d\n", __func__, status);
return status;
}
return NVMEDIA_STATUS_OK;
} }
static NvMediaStatus blit2DImageNonNvSCI(Blit2DTest *ctx, TestArgs* args) static NvMediaStatus blit2DImageNonNvSCI(Blit2DTest *ctx, TestArgs *args) {
{ NvMediaStatus status;
NvMediaStatus status; NvMediaImageSurfaceMap surfaceMap;
NvMediaImageSurfaceMap surfaceMap;
status = ReadImage(args->inputFileName, /* fileName */ status = ReadImage(args->inputFileName, /* fileName */
0, /* frameNum */ 0, /* frameNum */
args->srcSurfAllocAttrs[0].value, /* source image width */ args->srcSurfAllocAttrs[0].value, /* source image width */
args->srcSurfAllocAttrs[1].value, /* source image height */ args->srcSurfAllocAttrs[1].value, /* source image height */
ctx->srcImage, /* srcImage */ ctx->srcImage, /* srcImage */
NVMEDIA_TRUE, /* uvOrderFlag */ NVMEDIA_TRUE, /* uvOrderFlag */
1, /* bytesPerPixel */ 1, /* bytesPerPixel */
MSB_ALIGNED); /* pixelAlignment */ MSB_ALIGNED); /* pixelAlignment */
if (status != NVMEDIA_STATUS_OK) { if (status != NVMEDIA_STATUS_OK) {
printf("%s: ReadImage failed for input buffer: %d\n", __func__, status); printf("%s: ReadImage failed for input buffer: %d\n", __func__, status);
return status; return status;
} }
if ((args->srcRect.x1 <= args->srcRect.x0) || (args->srcRect.y1 <= args->srcRect.y0)) { if ((args->srcRect.x1 <= args->srcRect.x0) ||
ctx->srcRect = NULL; (args->srcRect.y1 <= args->srcRect.y0)) {
} else { ctx->srcRect = NULL;
ctx->srcRect = &(args->srcRect); } else {
} ctx->srcRect = &(args->srcRect);
}
if ((args->dstRect.x1 <= args->dstRect.x0) || (args->dstRect.y1 <= args->dstRect.y0)) { if ((args->dstRect.x1 <= args->dstRect.x0) ||
ctx->dstRect = NULL; (args->dstRect.y1 <= args->dstRect.y0)) {
} else { ctx->dstRect = NULL;
ctx->dstRect = &(args->dstRect); } else {
} ctx->dstRect = &(args->dstRect);
}
/* 2DBlit processing on input image */ /* 2DBlit processing on input image */
status = NvMedia2DBlitEx(ctx->i2d, /* i2d */ status = NvMedia2DBlitEx(ctx->i2d, /* i2d */
ctx->dstImage, /* dstSurface */ ctx->dstImage, /* dstSurface */
ctx->dstRect, /* dstRect */ ctx->dstRect, /* dstRect */
ctx->srcImage, /* srcSurface */ ctx->srcImage, /* srcSurface */
ctx->srcRect, /* srcRect */ ctx->srcRect, /* srcRect */
&args->blitParams, /* params */ &args->blitParams, /* params */
NULL); /* paramsOut */ NULL); /* paramsOut */
if(status != NVMEDIA_STATUS_OK) { if (status != NVMEDIA_STATUS_OK) {
printf("%s: NvMedia2DBlitEx failed: %d\n", __func__, status); printf("%s: NvMedia2DBlitEx failed: %d\n", __func__, status);
return status; return status;
} }
/* Write output image into buffer */ /* Write output image into buffer */
ctx->bytesPerPixel = 1; ctx->bytesPerPixel = 1;
WriteImageToAllocatedBuffer(ctx, ctx->dstImage, WriteImageToAllocatedBuffer(ctx, ctx->dstImage, NVMEDIA_TRUE, NVMEDIA_FALSE,
NVMEDIA_TRUE,
NVMEDIA_FALSE,
ctx->bytesPerPixel); ctx->bytesPerPixel);
return NVMEDIA_STATUS_OK; return NVMEDIA_STATUS_OK;
} }
static void cleanup(Blit2DTest* ctx, NvMediaStatus status = NVMEDIA_STATUS_OK) static void cleanup(Blit2DTest *ctx, NvMediaStatus status = NVMEDIA_STATUS_OK) {
{ if (ctx->srcImage != NULL) {
if (ctx->srcImage != NULL) { NvMedia2DImageUnRegister(ctx->i2d, ctx->srcImage);
NvMedia2DImageUnRegister(ctx->i2d, ctx->srcImage); destroySurface(ctx->srcImage);
destroySurface(ctx->srcImage); }
} if (ctx->dstImage != NULL) {
if (ctx->dstImage != NULL) { NvMedia2DImageUnRegister(ctx->i2d, ctx->dstImage);
NvMedia2DImageUnRegister(ctx->i2d, ctx->dstImage); destroySurface(ctx->dstImage);
destroySurface(ctx->dstImage); }
} if (status != NVMEDIA_STATUS_OK) {
if (status != NVMEDIA_STATUS_OK) { exit(EXIT_FAILURE);
exit(EXIT_FAILURE); }
}
} }
void cleanupNvMedia(Blit2DTest* ctx, NvSciSyncObj &syncObj, NvSciSyncObj &preSyncObj) void cleanupNvMedia(Blit2DTest *ctx, NvSciSyncObj &syncObj,
{ NvSciSyncObj &preSyncObj) {
NvMediaStatus status; NvMediaStatus status;
cleanup(ctx); cleanup(ctx);
status = NvMedia2DUnregisterNvSciSyncObj(ctx->i2d, syncObj); status = NvMedia2DUnregisterNvSciSyncObj(ctx->i2d, syncObj);
if(status != NVMEDIA_STATUS_OK) { if (status != NVMEDIA_STATUS_OK) {
printf("%s: NvMediaImageSciBufInit failed\n",__func__); printf("%s: NvMediaImageSciBufInit failed\n", __func__);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
status = NvMedia2DUnregisterNvSciSyncObj(ctx->i2d, preSyncObj); status = NvMedia2DUnregisterNvSciSyncObj(ctx->i2d, preSyncObj);
if(status != NVMEDIA_STATUS_OK) { if (status != NVMEDIA_STATUS_OK) {
printf("%s: NvMediaImageSciBufInit failed\n",__func__); printf("%s: NvMediaImageSciBufInit failed\n", __func__);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
NvMediaImageNvSciBufDeinit(); NvMediaImageNvSciBufDeinit();
} }
void cleanupNvMedia(Blit2DTest* ctx) void cleanupNvMedia(Blit2DTest *ctx) {
{ cleanup(ctx);
cleanup(ctx); free(ctx->dstBuffPitches);
free(ctx->dstBuffPitches); free(ctx->dstBuffer);
free(ctx->dstBuffer); free(ctx->dstBuff);
free(ctx->dstBuff);
} }
void setupNvMedia(TestArgs* args, Blit2DTest* ctx, NvSciBufObj &srcNvSciBufobj, void setupNvMedia(TestArgs *args, Blit2DTest *ctx, NvSciBufObj &srcNvSciBufobj,
NvSciBufObj& dstNvSciBufobj, NvSciSyncObj &syncObj, NvSciSyncObj &preSyncObj, NvSciBufObj &dstNvSciBufobj, NvSciSyncObj &syncObj,
int cudaDeviceId) NvSciSyncObj &preSyncObj, int cudaDeviceId) {
{ NvMediaStatus status;
NvMediaStatus status; status = NvMediaImageNvSciBufInit();
status = NvMediaImageNvSciBufInit(); if (status != NVMEDIA_STATUS_OK) {
if(status != NVMEDIA_STATUS_OK) { printf("%s: NvMediaImageSciBufInit failed\n", __func__);
printf("%s: NvMediaImageSciBufInit failed\n",__func__); cleanup(ctx, status);
cleanup(ctx, status); }
}
// Create source surface // Create source surface
status = createSurface(ctx, status = createSurface(ctx, args->srcSurfFormatAttrs, args->srcSurfAllocAttrs,
args->srcSurfFormatAttrs, args->numSurfAllocAttrs, &ctx->srcImage,
args->srcSurfAllocAttrs, srcNvSciBufobj, cudaDeviceId);
args->numSurfAllocAttrs, if (status != NVMEDIA_STATUS_OK) {
&ctx->srcImage, printf("%s: Unable to create buffer pools\n", __func__);
srcNvSciBufobj, cleanup(ctx, status);
cudaDeviceId); }
if(status != NVMEDIA_STATUS_OK) {
printf("%s: Unable to create buffer pools\n", __func__);
cleanup(ctx, status);
}
// Create destination surface // Create destination surface
status = createSurface(ctx, status = createSurface(ctx, args->dstSurfFormatAttrs, args->dstSurfAllocAttrs,
args->dstSurfFormatAttrs, args->numSurfAllocAttrs, &ctx->dstImage,
args->dstSurfAllocAttrs, dstNvSciBufobj, cudaDeviceId);
args->numSurfAllocAttrs, if (status != NVMEDIA_STATUS_OK) {
&ctx->dstImage, printf("%s: Unable to create buffer pools\n", __func__);
dstNvSciBufobj, cleanup(ctx, status);
cudaDeviceId); }
if(status != NVMEDIA_STATUS_OK) {
printf("%s: Unable to create buffer pools\n", __func__);
cleanup(ctx, status);
}
//Register source Surface // Register source Surface
status = NvMedia2DImageRegister(ctx->i2d, ctx->srcImage, NVMEDIA_ACCESS_MODE_READ); status =
if ( status != NVMEDIA_STATUS_OK) { NvMedia2DImageRegister(ctx->i2d, ctx->srcImage, NVMEDIA_ACCESS_MODE_READ);
printf("%s: Unable to register source surface\n", __func__); if (status != NVMEDIA_STATUS_OK) {
cleanup(ctx, status); printf("%s: Unable to register source surface\n", __func__);
} cleanup(ctx, status);
//Register destination Surface }
status = NvMedia2DImageRegister(ctx->i2d, ctx->dstImage, NVMEDIA_ACCESS_MODE_READ_WRITE); // Register destination Surface
if ( status != NVMEDIA_STATUS_OK) { status = NvMedia2DImageRegister(ctx->i2d, ctx->dstImage,
printf("%s: Unable to register destination surface\n", __func__); NVMEDIA_ACCESS_MODE_READ_WRITE);
cleanup(ctx, status); if (status != NVMEDIA_STATUS_OK) {
} printf("%s: Unable to register destination surface\n", __func__);
cleanup(ctx, status);
}
status = NvMedia2DRegisterNvSciSyncObj(ctx->i2d, NVMEDIA_EOFSYNCOBJ, syncObj); status = NvMedia2DRegisterNvSciSyncObj(ctx->i2d, NVMEDIA_EOFSYNCOBJ, syncObj);
if (status != NVMEDIA_STATUS_OK) { if (status != NVMEDIA_STATUS_OK) {
printf("%s: Unable to NvMedia2DRegisterNvSciSyncObj\n", __func__); printf("%s: Unable to NvMedia2DRegisterNvSciSyncObj\n", __func__);
} }
status = NvMedia2DRegisterNvSciSyncObj(ctx->i2d, NVMEDIA_PRESYNCOBJ, preSyncObj); status =
if (status != NVMEDIA_STATUS_OK) { NvMedia2DRegisterNvSciSyncObj(ctx->i2d, NVMEDIA_PRESYNCOBJ, preSyncObj);
printf("%s: Unable to NvMedia2DRegisterNvSciSyncObj\n", __func__); if (status != NVMEDIA_STATUS_OK) {
} printf("%s: Unable to NvMedia2DRegisterNvSciSyncObj\n", __func__);
}
} }
// Create NvMedia src & dst image without NvSciBuf // Create NvMedia src & dst image without NvSciBuf
void setupNvMedia(TestArgs* args, Blit2DTest* ctx) void setupNvMedia(TestArgs *args, Blit2DTest *ctx) {
{ NvMediaStatus status;
NvMediaStatus status;
// Create source surface // Create source surface
status = createSurfaceNonNvSCI(ctx, status = createSurfaceNonNvSCI(ctx, args->srcSurfFormatAttrs,
args->srcSurfFormatAttrs, args->srcSurfAllocAttrs,
args->srcSurfAllocAttrs, args->numSurfAllocAttrs, &ctx->srcImage);
args->numSurfAllocAttrs, if (status != NVMEDIA_STATUS_OK) {
&ctx->srcImage); printf("%s: Unable to create buffer pools\n", __func__);
if(status != NVMEDIA_STATUS_OK) { cleanup(ctx, status);
printf("%s: Unable to create buffer pools\n", __func__); }
cleanup(ctx, status);
}
// Create destination surface // Create destination surface
status = createSurfaceNonNvSCI(ctx, status = createSurfaceNonNvSCI(ctx, args->dstSurfFormatAttrs,
args->dstSurfFormatAttrs, args->dstSurfAllocAttrs,
args->dstSurfAllocAttrs, args->numSurfAllocAttrs, &ctx->dstImage);
args->numSurfAllocAttrs, if (status != NVMEDIA_STATUS_OK) {
&ctx->dstImage); printf("%s: Unable to create buffer pools\n", __func__);
if(status != NVMEDIA_STATUS_OK) { cleanup(ctx, status);
printf("%s: Unable to create buffer pools\n", __func__); }
cleanup(ctx, status);
}
//Register source Surface // Register source Surface
status = NvMedia2DImageRegister(ctx->i2d, ctx->srcImage, NVMEDIA_ACCESS_MODE_READ); status =
if ( status != NVMEDIA_STATUS_OK) { NvMedia2DImageRegister(ctx->i2d, ctx->srcImage, NVMEDIA_ACCESS_MODE_READ);
printf("%s: Unable to register source surface\n", __func__); if (status != NVMEDIA_STATUS_OK) {
cleanup(ctx, status); printf("%s: Unable to register source surface\n", __func__);
} cleanup(ctx, status);
}
//Register destination Surface // Register destination Surface
status = NvMedia2DImageRegister(ctx->i2d, ctx->dstImage, NVMEDIA_ACCESS_MODE_READ_WRITE); status = NvMedia2DImageRegister(ctx->i2d, ctx->dstImage,
if ( status != NVMEDIA_STATUS_OK) { NVMEDIA_ACCESS_MODE_READ_WRITE);
printf("%s: Unable to register destination surface\n", __func__); if (status != NVMEDIA_STATUS_OK) {
cleanup(ctx, status); printf("%s: Unable to register destination surface\n", __func__);
} cleanup(ctx, status);
}
// Allocate buffer for writing image & set image parameters in Blit2DTest. // Allocate buffer for writing image & set image parameters in Blit2DTest.
ctx->bytesPerPixel = 1; ctx->bytesPerPixel = 1;
AllocateBufferToWriteImage(ctx, AllocateBufferToWriteImage(ctx, ctx->dstImage, NVMEDIA_TRUE, /* uvOrderFlag */
ctx->dstImage, NVMEDIA_FALSE); /* appendFlag */
NVMEDIA_TRUE, /* uvOrderFlag */
NVMEDIA_FALSE); /* appendFlag */
} }
void runNvMediaBlit2D(TestArgs* args, Blit2DTest* ctx) void runNvMediaBlit2D(TestArgs *args, Blit2DTest *ctx) {
{ // Blit2D function
// Blit2D function NvMediaStatus status = blit2DImageNonNvSCI(ctx, args);
NvMediaStatus status = blit2DImageNonNvSCI(ctx, args); if (status != NVMEDIA_STATUS_OK) {
if(status != NVMEDIA_STATUS_OK) { printf("%s: Blit2D failed\n", __func__);
printf("%s: Blit2D failed\n", __func__); cleanup(ctx, status);
cleanup(ctx, status); }
}
} }
void runNvMediaBlit2D(TestArgs* args, Blit2DTest* ctx, NvSciSyncObj &nvMediaSignalerSyncObj, void runNvMediaBlit2D(TestArgs *args, Blit2DTest *ctx,
NvSciSyncFence *preSyncFence, NvSciSyncFence *fence) NvSciSyncObj &nvMediaSignalerSyncObj,
{ NvSciSyncFence *preSyncFence, NvSciSyncFence *fence) {
// Blit2D function // Blit2D function
NvMediaStatus status = blit2DImage(ctx, args, nvMediaSignalerSyncObj, preSyncFence, fence); NvMediaStatus status =
if(status != NVMEDIA_STATUS_OK) { blit2DImage(ctx, args, nvMediaSignalerSyncObj, preSyncFence, fence);
printf("%s: Blit2D failed\n", __func__); if (status != NVMEDIA_STATUS_OK) {
cleanup(ctx, status); printf("%s: Blit2D failed\n", __func__);
} cleanup(ctx, status);
}
} }

View File

@@ -25,7 +25,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef __NVMEDIA_PRODUCER_H__ #ifndef __NVMEDIA_PRODUCER_H__
#define __NVMEDIA_PRODUCER_H__ #define __NVMEDIA_PRODUCER_H__
#include "nvmedia_utils/cmdline.h" #include "nvmedia_utils/cmdline.h"
@@ -36,13 +35,14 @@
#include "nvmedia_image_nvscibuf.h" #include "nvmedia_image_nvscibuf.h"
#include "nvscisync.h" #include "nvscisync.h"
void runNvMediaBlit2D(TestArgs* args, Blit2DTest* ctx, NvSciSyncObj &syncObj, void runNvMediaBlit2D(TestArgs* args, Blit2DTest* ctx, NvSciSyncObj& syncObj,
NvSciSyncFence *preSyncFence, NvSciSyncFence *fence); NvSciSyncFence* preSyncFence, NvSciSyncFence* fence);
void runNvMediaBlit2D(TestArgs* args, Blit2DTest* ctx); void runNvMediaBlit2D(TestArgs* args, Blit2DTest* ctx);
void setupNvMedia(TestArgs* args, Blit2DTest* ctx, NvSciBufObj &srcNvSciBufobj, void setupNvMedia(TestArgs* args, Blit2DTest* ctx, NvSciBufObj& srcNvSciBufobj,
NvSciBufObj& dstNvSciBufobj, NvSciSyncObj &syncObj, NvSciSyncObj &preSyncObj, NvSciBufObj& dstNvSciBufobj, NvSciSyncObj& syncObj,
int cudaDeviceId); NvSciSyncObj& preSyncObj, int cudaDeviceId);
void setupNvMedia(TestArgs* args, Blit2DTest* ctx); void setupNvMedia(TestArgs* args, Blit2DTest* ctx);
void cleanupNvMedia(Blit2DTest* ctx, NvSciSyncObj &syncObj, NvSciSyncObj &preSyncObj); void cleanupNvMedia(Blit2DTest* ctx, NvSciSyncObj& syncObj,
NvSciSyncObj& preSyncObj);
void cleanupNvMedia(Blit2DTest* ctx); void cleanupNvMedia(Blit2DTest* ctx);
#endif #endif

View File

@@ -32,7 +32,6 @@
#include "nvsci_setup.h" #include "nvsci_setup.h"
#include "nvmedia_2d_nvscisync.h" #include "nvmedia_2d_nvscisync.h"
#define checkNvSciErrors(call) \ #define checkNvSciErrors(call) \
do { \ do { \
NvSciError _status = call; \ NvSciError _status = call; \
@@ -44,111 +43,115 @@
fflush(stdout); \ fflush(stdout); \
exit(EXIT_FAILURE); \ exit(EXIT_FAILURE); \
} \ } \
} while (0) } while (0)
void setupNvMediaSignalerNvSciSync(Blit2DTest* ctx, NvSciSyncObj &syncObj, int cudaDeviceId) void setupNvMediaSignalerNvSciSync(Blit2DTest *ctx, NvSciSyncObj &syncObj,
{ int cudaDeviceId) {
NvSciSyncModule sciSyncModule; NvSciSyncModule sciSyncModule;
checkNvSciErrors(NvSciSyncModuleOpen(&sciSyncModule)); checkNvSciErrors(NvSciSyncModuleOpen(&sciSyncModule));
NvSciSyncAttrList signalerAttrList, waiterAttrList; NvSciSyncAttrList signalerAttrList, waiterAttrList;
NvSciSyncAttrList syncUnreconciledList[2]; NvSciSyncAttrList syncUnreconciledList[2];
NvSciSyncAttrList syncReconciledList, syncConflictList; NvSciSyncAttrList syncReconciledList, syncConflictList;
checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &signalerAttrList)); checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &signalerAttrList));
checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &waiterAttrList)); checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &waiterAttrList));
NvMediaStatus status = NvMedia2DFillNvSciSyncAttrList(ctx->i2d, signalerAttrList, NVMEDIA_SIGNALER); NvMediaStatus status = NvMedia2DFillNvSciSyncAttrList(
if(status != NVMEDIA_STATUS_OK) { ctx->i2d, signalerAttrList, NVMEDIA_SIGNALER);
printf("%s: NvMedia2DFillNvSciSyncAttrList failed\n",__func__); if (status != NVMEDIA_STATUS_OK) {
exit(EXIT_FAILURE); printf("%s: NvMedia2DFillNvSciSyncAttrList failed\n", __func__);
} exit(EXIT_FAILURE);
}
checkCudaErrors(cudaSetDevice(cudaDeviceId)); checkCudaErrors(cudaSetDevice(cudaDeviceId));
checkCudaErrors(cudaDeviceGetNvSciSyncAttributes(waiterAttrList, cudaDeviceId, cudaNvSciSyncAttrWait)); checkCudaErrors(cudaDeviceGetNvSciSyncAttributes(waiterAttrList, cudaDeviceId,
cudaNvSciSyncAttrWait));
syncUnreconciledList[0] = signalerAttrList; syncUnreconciledList[0] = signalerAttrList;
syncUnreconciledList[1] = waiterAttrList; syncUnreconciledList[1] = waiterAttrList;
checkNvSciErrors(NvSciSyncAttrListReconcile(syncUnreconciledList, 2, &syncReconciledList, &syncConflictList)); checkNvSciErrors(NvSciSyncAttrListReconcile(
checkNvSciErrors(NvSciSyncObjAlloc(syncReconciledList, &syncObj)); syncUnreconciledList, 2, &syncReconciledList, &syncConflictList));
checkNvSciErrors(NvSciSyncObjAlloc(syncReconciledList, &syncObj));
NvSciSyncAttrListFree(signalerAttrList); NvSciSyncAttrListFree(signalerAttrList);
NvSciSyncAttrListFree(waiterAttrList); NvSciSyncAttrListFree(waiterAttrList);
if(syncConflictList != nullptr) { if (syncConflictList != nullptr) {
NvSciSyncAttrListFree(syncConflictList); NvSciSyncAttrListFree(syncConflictList);
} }
} }
void setupCudaSignalerNvSciSync(Blit2DTest* ctx, NvSciSyncObj &syncObj, int cudaDeviceId) void setupCudaSignalerNvSciSync(Blit2DTest *ctx, NvSciSyncObj &syncObj,
{ int cudaDeviceId) {
NvSciSyncModule sciSyncModule; NvSciSyncModule sciSyncModule;
checkNvSciErrors(NvSciSyncModuleOpen(&sciSyncModule)); checkNvSciErrors(NvSciSyncModuleOpen(&sciSyncModule));
NvSciSyncAttrList signalerAttrList, waiterAttrList; NvSciSyncAttrList signalerAttrList, waiterAttrList;
NvSciSyncAttrList syncUnreconciledList[2]; NvSciSyncAttrList syncUnreconciledList[2];
NvSciSyncAttrList syncReconciledList, syncConflictList; NvSciSyncAttrList syncReconciledList, syncConflictList;
checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &signalerAttrList)); checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &signalerAttrList));
checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &waiterAttrList)); checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &waiterAttrList));
NvMediaStatus status = NvMedia2DFillNvSciSyncAttrList(ctx->i2d, waiterAttrList, NVMEDIA_WAITER); NvMediaStatus status =
if(status != NVMEDIA_STATUS_OK) { NvMedia2DFillNvSciSyncAttrList(ctx->i2d, waiterAttrList, NVMEDIA_WAITER);
printf("%s: NvMedia2DFillNvSciSyncAttrList failed\n",__func__); if (status != NVMEDIA_STATUS_OK) {
exit(EXIT_FAILURE); printf("%s: NvMedia2DFillNvSciSyncAttrList failed\n", __func__);
} exit(EXIT_FAILURE);
}
checkCudaErrors(cudaSetDevice(cudaDeviceId)); checkCudaErrors(cudaSetDevice(cudaDeviceId));
checkCudaErrors(cudaDeviceGetNvSciSyncAttributes(signalerAttrList, cudaDeviceId, cudaNvSciSyncAttrSignal)); checkCudaErrors(cudaDeviceGetNvSciSyncAttributes(
signalerAttrList, cudaDeviceId, cudaNvSciSyncAttrSignal));
syncUnreconciledList[0] = signalerAttrList; syncUnreconciledList[0] = signalerAttrList;
syncUnreconciledList[1] = waiterAttrList; syncUnreconciledList[1] = waiterAttrList;
checkNvSciErrors(NvSciSyncAttrListReconcile(syncUnreconciledList, 2, &syncReconciledList, &syncConflictList)); checkNvSciErrors(NvSciSyncAttrListReconcile(
checkNvSciErrors(NvSciSyncObjAlloc(syncReconciledList, &syncObj)); syncUnreconciledList, 2, &syncReconciledList, &syncConflictList));
checkNvSciErrors(NvSciSyncObjAlloc(syncReconciledList, &syncObj));
NvSciSyncAttrListFree(signalerAttrList); NvSciSyncAttrListFree(signalerAttrList);
NvSciSyncAttrListFree(waiterAttrList); NvSciSyncAttrListFree(waiterAttrList);
if(syncConflictList != nullptr) { if (syncConflictList != nullptr) {
NvSciSyncAttrListFree(syncConflictList); NvSciSyncAttrListFree(syncConflictList);
} }
} }
void setupNvSciBuf(NvSciBufObj &bufobj, NvSciBufAttrList &nvmediaAttrlist,
int cudaDeviceId) {
CUuuid devUUID;
NvSciBufAttrList conflictlist;
NvSciBufAttrList bufUnreconciledAttrlist[1];
void setupNvSciBuf(NvSciBufObj &bufobj, NvSciBufAttrList &nvmediaAttrlist, int cudaDeviceId) CUresult res = cuDeviceGetUuid(&devUUID, cudaDeviceId);
{ if (res != CUDA_SUCCESS) {
CUuuid devUUID; fprintf(stderr, "Driver API error = %04d \n", res);
NvSciBufAttrList conflictlist; exit(EXIT_FAILURE);
NvSciBufAttrList bufUnreconciledAttrlist[1]; }
CUresult res = cuDeviceGetUuid(&devUUID, cudaDeviceId); NvSciBufAttrKeyValuePair attr_gpuid[] = {NvSciBufGeneralAttrKey_GpuId,
if (res != CUDA_SUCCESS) { &devUUID, sizeof(devUUID)};
fprintf(stderr, "Driver API error = %04d \n", res);
exit(EXIT_FAILURE);
}
NvSciBufAttrKeyValuePair attr_gpuid[] = {NvSciBufGeneralAttrKey_GpuId, &devUUID, sizeof(devUUID)}; // set CUDA GPU ID to attribute list
checkNvSciErrors(NvSciBufAttrListSetAttrs(
nvmediaAttrlist, attr_gpuid,
sizeof(attr_gpuid) / sizeof(NvSciBufAttrKeyValuePair)));
// set CUDA GPU ID to attribute list bufUnreconciledAttrlist[0] = nvmediaAttrlist;
checkNvSciErrors(NvSciBufAttrListSetAttrs(nvmediaAttrlist, attr_gpuid, sizeof(attr_gpuid)/sizeof(NvSciBufAttrKeyValuePair)));
bufUnreconciledAttrlist[0] = nvmediaAttrlist; checkNvSciErrors(NvSciBufAttrListReconcileAndObjAlloc(
bufUnreconciledAttrlist, 1, &bufobj, &conflictlist));
checkNvSciErrors(NvSciBufAttrListReconcileAndObjAlloc(bufUnreconciledAttrlist, if (conflictlist != NULL) {
1, NvSciBufAttrListFree(conflictlist);
&bufobj, }
&conflictlist));
if (conflictlist != NULL) {
NvSciBufAttrListFree(conflictlist);
}
} }
void cleanupNvSciBuf(NvSciBufObj &Bufobj) void cleanupNvSciBuf(NvSciBufObj &Bufobj) {
{ if (Bufobj != NULL) {
if (Bufobj != NULL) { NvSciBufObjFree(Bufobj);
NvSciBufObjFree(Bufobj); }
}
} }
void cleanupNvSciSync(NvSciSyncObj &syncObj) void cleanupNvSciSync(NvSciSyncObj &syncObj) {
{ if (NvSciSyncObjFree != NULL) {
if (NvSciSyncObjFree != NULL) { NvSciSyncObjFree(syncObj);
NvSciSyncObjFree(syncObj); }
}
} }

View File

@@ -25,16 +25,18 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef __NVSCI_SETUP_H__ #ifndef __NVSCI_SETUP_H__
#define __NVSCI_SETUP_H__ #define __NVSCI_SETUP_H__
#include "nvmedia_utils/cmdline.h" #include "nvmedia_utils/cmdline.h"
#include <nvscibuf.h> #include <nvscibuf.h>
#include <nvscisync.h> #include <nvscisync.h>
void setupNvMediaSignalerNvSciSync(Blit2DTest* ctx, NvSciSyncObj &syncObj, int cudaDeviceId); void setupNvMediaSignalerNvSciSync(Blit2DTest *ctx, NvSciSyncObj &syncObj,
void setupCudaSignalerNvSciSync(Blit2DTest* ctx, NvSciSyncObj &syncObj, int cudaDeviceId); int cudaDeviceId);
void setupNvSciBuf(NvSciBufObj &bufobj, NvSciBufAttrList &nvmediaAttrlist, int cudaDeviceId); void setupCudaSignalerNvSciSync(Blit2DTest *ctx, NvSciSyncObj &syncObj,
int cudaDeviceId);
void setupNvSciBuf(NvSciBufObj &bufobj, NvSciBufAttrList &nvmediaAttrlist,
int cudaDeviceId);
void cleanupNvSciBuf(NvSciBufObj &Bufobj); void cleanupNvSciBuf(NvSciBufObj &Bufobj);
void cleanupNvSciSync(NvSciSyncObj &syncObj); void cleanupNvSciSync(NvSciSyncObj &syncObj);
#endif #endif

View File

@@ -30,7 +30,7 @@ cudaMalloc, cudaFree, cudaMemcpy
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -109,6 +109,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -105,6 +105,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -31,7 +31,7 @@ cudaMallocManaged, cudaDeviceSynchronize, cudaFuncSetAttribute, cudaEventCreate,
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -104,6 +104,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -27,7 +27,7 @@ cudaSetDevice, cudaGetDeviceCount, cudaGetDeviceProperties, cudaDriverGetVersion
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
## Build and Run ## Build and Run

View File

@@ -112,10 +112,10 @@ int main(int argc, char **argv) {
char msg[256]; char msg[256];
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
sprintf_s(msg, sizeof(msg), sprintf_s(msg, sizeof(msg),
" Total amount of global memory: %.0f MBytes " " Total amount of global memory: %.0f MBytes "
"(%llu bytes)\n", "(%llu bytes)\n",
static_cast<float>(deviceProp.totalGlobalMem / 1048576.0f), static_cast<float>(deviceProp.totalGlobalMem / 1048576.0f),
(unsigned long long)deviceProp.totalGlobalMem); (unsigned long long)deviceProp.totalGlobalMem);
#else #else
snprintf(msg, sizeof(msg), snprintf(msg, sizeof(msg),
" Total amount of global memory: %.0f MBytes " " Total amount of global memory: %.0f MBytes "
@@ -125,7 +125,7 @@ int main(int argc, char **argv) {
#endif #endif
printf("%s", msg); printf("%s", msg);
printf(" (%2d) Multiprocessors, (%3d) CUDA Cores/MP: %d CUDA Cores\n", printf(" (%03d) Multiprocessors, (%03d) CUDA Cores/MP: %d CUDA Cores\n",
deviceProp.multiProcessorCount, deviceProp.multiProcessorCount,
_ConvertSMVer2Cores(deviceProp.major, deviceProp.minor), _ConvertSMVer2Cores(deviceProp.major, deviceProp.minor),
_ConvertSMVer2Cores(deviceProp.major, deviceProp.minor) * _ConvertSMVer2Cores(deviceProp.major, deviceProp.minor) *
@@ -250,8 +250,7 @@ int main(int argc, char **argv) {
"device)", "device)",
"Exclusive Process (many threads in one process is able to use " "Exclusive Process (many threads in one process is able to use "
"::cudaSetDevice() with this device)", "::cudaSetDevice() with this device)",
"Unknown", "Unknown", NULL};
NULL};
printf(" Compute Mode:\n"); printf(" Compute Mode:\n");
printf(" < %s >\n", sComputeMode[deviceProp.computeMode]); printf(" < %s >\n", sComputeMode[deviceProp.computeMode]);
} }
@@ -272,7 +271,7 @@ int main(int argc, char **argv) {
// must be enabled to support this // must be enabled to support this
&& prop[i].tccDriver && prop[i].tccDriver
#endif #endif
) { ) {
// This is an array of P2P capable GPUs // This is an array of P2P capable GPUs
gpuid[gpu_p2p_count++] = i; gpuid[gpu_p2p_count++] = i;
} }
@@ -307,7 +306,8 @@ int main(int argc, char **argv) {
// driver version // driver version
sProfileString += ", CUDA Driver Version = "; sProfileString += ", CUDA Driver Version = ";
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
sprintf_s(cTemp, 10, "%d.%d", driverVersion/1000, (driverVersion%100)/10); sprintf_s(cTemp, 10, "%d.%d", driverVersion / 1000,
(driverVersion % 100) / 10);
#else #else
snprintf(cTemp, sizeof(cTemp), "%d.%d", driverVersion / 1000, snprintf(cTemp, sizeof(cTemp), "%d.%d", driverVersion / 1000,
(driverVersion % 100) / 10); (driverVersion % 100) / 10);
@@ -317,7 +317,8 @@ int main(int argc, char **argv) {
// Runtime version // Runtime version
sProfileString += ", CUDA Runtime Version = "; sProfileString += ", CUDA Runtime Version = ";
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
sprintf_s(cTemp, 10, "%d.%d", runtimeVersion/1000, (runtimeVersion%100)/10); sprintf_s(cTemp, 10, "%d.%d", runtimeVersion / 1000,
(runtimeVersion % 100) / 10);
#else #else
snprintf(cTemp, sizeof(cTemp), "%d.%d", runtimeVersion / 1000, snprintf(cTemp, sizeof(cTemp), "%d.%d", runtimeVersion / 1000,
(runtimeVersion % 100) / 10); (runtimeVersion % 100) / 10);

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -104,6 +104,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -27,7 +27,7 @@ cudaMallocManaged, cudaDeviceSynchronize, cudaFuncSetAttribute, cudaEventCreate,
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -104,6 +104,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -30,7 +30,7 @@ cudaEventCreate, cudaEventRecord, cudaEventQuery, cudaEventDestroy, cudaEventEla
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed. Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run ## Build and Run

File diff suppressed because it is too large Load Diff

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -104,6 +104,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -27,7 +27,7 @@ cudaMallocManaged, cudaDeviceSynchronize, cudaFuncSetAttribute, cudaEventCreate,
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -104,6 +104,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -25,7 +25,7 @@ cudaStreamBeginCapture, cudaStreamEndCapture, cudaGraphCreate, cudaGraphLaunch,
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -109,6 +109,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -34,7 +34,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -105,6 +105,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -100,8 +100,10 @@ int main(int argc, char **argv) {
double *b = NULL; double *b = NULL;
float *A = NULL; float *A = NULL;
b = (double *)calloc(N_ROWS, sizeof(double)); checkCudaErrors(cudaMallocHost(&b, N_ROWS * sizeof(double)));
A = (float *)calloc(N_ROWS * N_ROWS, sizeof(float)); memset(b, 0, N_ROWS * sizeof(double));
checkCudaErrors(cudaMallocHost(&A, N_ROWS * N_ROWS * sizeof(float)));
memset(A, 0, N_ROWS * N_ROWS * sizeof(float));
createLinearSystem(A, b); createLinearSystem(A, b);
double *x = NULL; double *x = NULL;
@@ -170,6 +172,9 @@ int main(int argc, char **argv) {
checkCudaErrors(cudaFree(d_x)); checkCudaErrors(cudaFree(d_x));
checkCudaErrors(cudaFree(d_x_new)); checkCudaErrors(cudaFree(d_x_new));
checkCudaErrors(cudaFreeHost(A));
checkCudaErrors(cudaFreeHost(b));
printf("&&&& jacobiCudaGraphs %s\n", printf("&&&& jacobiCudaGraphs %s\n",
(fabs(sum - sumGPU) < conv_threshold) ? "PASSED" : "FAILED"); (fabs(sum - sumGPU) < conv_threshold) ? "PASSED" : "FAILED");

View File

@@ -27,7 +27,7 @@ cudaEventCreate, cudaEventRecord, cudaEventQuery, cudaEventDestroy, cudaEventEla
## Prerequisites ## Prerequisites
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform. Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
## Build and Run ## Build and Run

View File

@@ -38,7 +38,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets"> <ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
@@ -108,6 +108,6 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" /> <Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>

Some files were not shown because too many files have changed in this diff Show More