mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-11-18 01:48:16 +08:00
Compare commits
71 Commits
v13.0
...
sync/v13.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b946e35723 | ||
|
|
b7c5481c55 | ||
|
|
aeab82ff30 | ||
|
|
a4526d5229 | ||
|
|
f69622b6b6 | ||
|
|
722c5dd069 | ||
|
|
e32d17e67e | ||
|
|
5cf83b5a98 | ||
|
|
191900a7b4 | ||
|
|
338df69d0f | ||
|
|
9b7a6f907a | ||
|
|
5bbae96fd3 | ||
|
|
ce9407c240 | ||
|
|
cdedff42d2 | ||
|
|
6c4d183ba3 | ||
|
|
af49216f0c | ||
|
|
17113ea87e | ||
|
|
70fcdd353f | ||
|
|
5b2dd19a21 | ||
|
|
37dcb9b61d | ||
|
|
1bc6774795 | ||
|
|
4f735616ba | ||
|
|
4ff552244d | ||
|
|
df6edf644e | ||
|
|
85231cd1b6 | ||
|
|
46a782fb44 | ||
|
|
d5dedb24d6 | ||
|
|
9600b04a3c | ||
|
|
4eae2ccc04 | ||
|
|
d759a16c4b | ||
|
|
b8191f860a | ||
|
|
547f65851f | ||
|
|
9df0ef6411 | ||
|
|
1411d243a6 | ||
|
|
57e870596c | ||
|
|
fd6707ccaa | ||
|
|
cf01c5bb28 | ||
|
|
1165d53ddf | ||
|
|
8c324afd63 | ||
|
|
0fae54dcd6 | ||
|
|
320c7e6392 | ||
|
|
22fafb0a7c | ||
|
|
cccbf2c284 | ||
|
|
69186dc51e | ||
|
|
d298bf3e6f | ||
|
|
27c7e19849 | ||
|
|
7c190dde53 | ||
|
|
5e9d44634b | ||
|
|
b0a2f2049f | ||
|
|
3e6d1858af | ||
|
|
12b046a80e | ||
|
|
036638b713 | ||
|
|
9d703d090b | ||
|
|
cbc075ef59 | ||
|
|
6e23a98575 | ||
|
|
5fc7a4c897 | ||
|
|
775d1b4dd3 | ||
|
|
eb8891b839 | ||
|
|
688fff15b2 | ||
|
|
555353b4b5 | ||
|
|
1a35902577 | ||
|
|
7c8fccc0d4 | ||
|
|
859debae1b | ||
|
|
c1166d3298 | ||
|
|
f19d33ddbc | ||
|
|
bf25251720 | ||
|
|
5a1f5008ed | ||
|
|
5ce8b512ea | ||
|
|
dd1a11f648 | ||
|
|
f288b2e261 | ||
|
|
b63fd83b6c |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,6 +1,12 @@
|
|||||||
build
|
build
|
||||||
|
build-*/
|
||||||
|
test-results*/
|
||||||
.vs
|
.vs
|
||||||
|
.vscode
|
||||||
.clangd
|
.clangd
|
||||||
test
|
test
|
||||||
settings.json
|
settings.json
|
||||||
launch.json
|
launch.json
|
||||||
|
__pycache__/
|
||||||
|
*.py[co]
|
||||||
|
.pytest_cache/
|
||||||
|
|||||||
@@ -104,3 +104,13 @@ repos:
|
|||||||
Common/.*
|
Common/.*
|
||||||
)
|
)
|
||||||
args: ["-fallback-style=none", "-style=file", "-i"]
|
args: ["-fallback-style=none", "-style=file", "-i"]
|
||||||
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
|
rev: v0.8.4
|
||||||
|
hooks:
|
||||||
|
- id: ruff
|
||||||
|
name: ruff lint
|
||||||
|
args: [--fix]
|
||||||
|
files: ^python/.*\.py$
|
||||||
|
- id: ruff-format
|
||||||
|
name: ruff format
|
||||||
|
files: ^python/.*\.py$
|
||||||
|
|||||||
47
CHANGELOG.md
47
CHANGELOG.md
@@ -1,5 +1,52 @@
|
|||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
### CUDA 13.4
|
||||||
|
* Removed obsolete samples `simpleHyperQ`, `simpleOccupancy`, `mergeSort`, `simpleTemplates`, `template`, `p2pBandwidthLatencyTest`.
|
||||||
|
* Removed redundant `_nvrtc` sample variants (`clock_nvrtc`, `matrixMul_nvrtc`, `simpleAssert_nvrtc`, `simpleAtomicIntrinsics_nvrtc`, `inlinePTX_nvrtc`, `binomialOptions_nvrtc`, `BlackScholes_nvrtc`, `quasirandomGenerator_nvrtc`); `vectorAdd_nvrtc` remains as the canonical NVRTC example.
|
||||||
|
* Rewrote `cpp/0_Introduction/simpleMultiGPU` to replace the hand-written reduction with `cub::BlockReduce` and the SDK stopwatch timer with CUDA events, removed helper header dependencies and merged `simpleMultiGPU.h` into the `.cu` for a single-file sample, modernized the code to C++17 (`std::vector`, `constexpr`), and added a minimum two-GPU check; updated README accordingly.
|
||||||
|
* Modernized `cpp/3_CUDA_Features/simpleCudaGraphs`: dropped `helper_cuda.h`/`cooperative_groups.h`; used `cub::BlockReduce`; migrated to the unified `cudaGraphAddNode` API; split into `simpleCudaGraphs_explicit` and `simpleCudaGraphs_capture` sharing `simpleCudaGraphs.cuh`; added a graph-reuse demo (fresh input each launch); rewrote README.
|
||||||
|
* Rewrote `cpp/0_Introduction/simpleAtomicIntrinsics` to show race conditions by comparing non-atomic vs atomic kernels (`atomicAdd`, `atomicMax`, `atomicCAS`), removed helper header dependencies; updated README accordingly.
|
||||||
|
* Reorganized CMake build system for all C++ samples: centralized GPU architecture detection (`DetectCudaArch.cmake`) and common build setup (`CudaSampleCommon.cmake`) into shared modules. Samples with restricted arch support now declare a `SAMPLE_DISALLOW_ARCHS` list instead of hardcoding their own arch list, and are gracefully skipped at configure time when the requested arch is unsupported.
|
||||||
|
* Added `sm_103` to the default set of GPU architectures the C++ samples build for.
|
||||||
|
* Added `sm_107` to the default set of GPU architectures the C++ samples build for.
|
||||||
|
* Rewrote `cpp/0_Introduction/simpleCallback` to replace the deprecated `cudaStreamAddCallback` with `cudaLaunchHostFunc`, replaced the `multithreading.h/.cpp` helpers with standard C++ `std::thread`, and simplified to a single-GPU, single-workload C++17 example; updated README accordingly.
|
||||||
|
* Rewrote `cpp/0_Introduction/simpleStreams` to simplify code and remove helper header dependencies; updated README accordingly.
|
||||||
|
* Added `python/2_CoreConcepts/persistentProgramCache` to demonstrate persisting and reusing compiled CUDA artifacts with `cuda.core` and `FileStreamProgramCache`.
|
||||||
|
* Updated `cpp/0_Introduction/clock` to replace the manual shared-memory tree reduction with `cub::BlockReduce` min-reduction, removed dependency on `helper_cuda.h` and `helper_functions.h`, and updated README.
|
||||||
|
* Rewrote `cpp/0_Introduction/vectorAdd` to match the corresponding example in the CUDA Programming Guide. The sample now uses Unified Memory (`cudaMallocManaged`) instead of explicit `cudaMalloc`/`cudaMemcpy`.
|
||||||
|
* Restructured the `cpp/0_Introduction/simplePrintf` README with newer style and updated sample code by removing helper dependency.
|
||||||
|
* Updated the `cpp/0_Introduction/simpleAssert` README to newer style, simplified code for better understanding.
|
||||||
|
* Added `cpp/3_CUDA_Features/dmabufInterop` - a Linux-only CUDA dma-buf interoperability sample demonstrating three scenarios in a single binary: (1) same-process round-trip export/import, (2) cross-process IPC via `fork()` + `SCM_RIGHTS`, and (3) cross-GPU sharing across processes (self-skips on systems without a qualifying GPU pair).
|
||||||
|
* Removed the unnecessary `set(CMAKE_POSITION_INDEPENDENT_CODE ON)` from the C++ sample `CMakeLists.txt` files.
|
||||||
|
* Removed `CUDA_SEPARABLE_COMPILATION ON` from C++ samples that don't require relocatable device code (kept for the CDP samples).
|
||||||
|
* Removed 26 math library samples from `cpp/4_CUDA_Libraries/` that are maintained in the [CUDA Library Samples](https://github.com/NVIDIA/CUDALibrarySamples) repository: cuBLAS (`simpleCUBLAS`, `simpleCUBLAS_LU`, `simpleCUBLASXT`, `matrixMulCUBLAS`, `batchCUBLAS`), cuFFT (`simpleCUFFT`, `simpleCUFFT_MGPU`, `simpleCUFFT_2d_MGPU`, `simpleCUFFT_callback`), cuRAND (`MersenneTwisterGP11213`), cuSOLVER (`cuSolverDn_LinearSolver`, `cuSolverRf`, `cuSolverSp_LinearSolver`, `cuSolverSp_LowlevelCholesky`, `cuSolverSp_LowlevelQR`), cuSPARSE (`conjugateGradient`, `conjugateGradientPrecond`, `conjugateGradientUM`), NPP (`boxFilterNPP`, `cannyEdgeDetectorNPP`, `FilterBorderControlNPP`, `freeImageInteropNPP`, `histEqualizationNPP`, `watershedSegmentationNPP`), and nvJPEG (`nvJPEG`, `nvJPEG_encoder`).
|
||||||
|
* Lifted the LLVM 14 upper bound on `cpp/7_libNVVM/cuda-c-linking`, which now builds against LLVM 15 and newer.
|
||||||
|
* Added samples for locality domains in `cpp/3_CUDA_FEATURES/localityDomains` and `cpp/3_CUDA_FEATURES/localityDomainsDrv`.
|
||||||
|
* Added Windows on Arm support: `cpp/5_Domain_Specific/marchingCubes` now detects the `glew32` GLEW library name used on Windows on Arm, and `cpp/7_libNVVM` searches the `nvvm/lib/arm64` directory for libNVVM.
|
||||||
|
|
||||||
|
### CUDA 13.3
|
||||||
|
* Added **CUDA Tile C++** samples under `cpp/9_CUDA_Tile`.
|
||||||
|
* Added a set of **CCCL 3.3 feature samples** under `cpp/4_CUDA_Libraries/`, each built against CCCL fetched via CPM (pinned to v3.3.3, with an optional `CCCL_SOURCE_DIR` override):
|
||||||
|
* `cubDeviceFind` - `cub::DeviceFind::FindIf`, `LowerBound`, and `UpperBound` device-wide search algorithms.
|
||||||
|
* `cubDeviceSegmentedScan` - `cub::DeviceSegmentedScan::ExclusiveSegmentedSum` and `InclusiveSegmentedScan` with a custom binary operator.
|
||||||
|
* `cubDeviceTransform` - N-to-M `cub::DeviceTransform::Transform` where the op returns a `cuda::std::tuple`.
|
||||||
|
* `libcuxxRandom` - `cuda::pcg64` and `cuda::std::philox4x32` engines driving the uniform, normal, Poisson, and Bernoulli distributions from `<cuda/std/random>`.
|
||||||
|
* `libcuxxMdspan` - DLPack <-> `cuda::std::mdspan` bridging via `cuda::to_device_mdspan` / `cuda::to_dlpack_tensor`, plus `cuda::shared_memory_mdspan` for multi-dimensional views of shared memory.
|
||||||
|
* Added **cuda.compute 1.0 Python samples** under `python/2_CoreConcepts/`:
|
||||||
|
* `cudaComputeLambdas` - Python lambdas / regular callables driving `reduce_into`, `unary_transform`, and `inclusive_scan` in `cuda.compute` (from the `cuda-cccl` package).
|
||||||
|
* `binarySearch` - parallel `cuda.compute.upper_bound` / `lower_bound`, verified against `numpy.searchsorted`.
|
||||||
|
|
||||||
|
|
||||||
|
### CUDA 13.2 (update)
|
||||||
|
* Added **CUDA Python samples** under `python/`. These scripts use [CUDA Python](https://nvidia.github.io/cuda-python/) (including `cuda.core`) and are organized like the C++ tree: `1_GettingStarted`, `2_CoreConcepts`, `3_FrameworkInterop`, and `4_DistributedComputing`, plus shared helpers in `python/Utilities`. Each sample includes a `README.md` and `requirements.txt`. They are **not** built by the root CMake project; install dependencies with `pip install -r requirements.txt` in the sample directory, then run the corresponding `.py` file as documented in that sample’s README.
|
||||||
|
* Renamed top-level `Samples` directory to `cpp` to accommodate Python samples alongside existing C++ samples; updated path references in `CMakeLists.txt`, `README.md`, and `Common` headers accordingly.
|
||||||
|
|
||||||
|
### CUDA 13.2
|
||||||
|
* Added the MSVC compile flag `-Xcompiler=/Zc:preprocessor` in CMakeLists.txt to comply with CUDA13.2 CCCL. Previously, using the traditional preprocessor triggered the warning “MSVC/cl.exe with traditional preprocessor is used…”, which now leads to a build error.
|
||||||
|
|
||||||
|
### CUDA 13.1
|
||||||
|
* Minor bug fixes and enhancements, no structural or functional changes
|
||||||
|
|
||||||
### CUDA 13.0
|
### CUDA 13.0
|
||||||
* Updated the samples using the cudaDeviceProp fields which are deprecated and removed in CUDA 13.0, replacing the fields with the equivalents in "cudaDeviceGetAttribute":
|
* Updated the samples using the cudaDeviceProp fields which are deprecated and removed in CUDA 13.0, replacing the fields with the equivalents in "cudaDeviceGetAttribute":
|
||||||
* Deprecated "cudaDeviceProp" fields
|
* Deprecated "cudaDeviceProp" fields
|
||||||
|
|||||||
@@ -1,25 +1,31 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
|
include(cmake/CudaSampleArchs.cmake)
|
||||||
|
|
||||||
|
# Default to all supported architectures if the user does not specify.
|
||||||
|
# Gated on CUDA_SAMPLES_ARCHS_DEFAULTED rather than CMAKE_CUDA_ARCHITECTURES so this
|
||||||
|
# decision is made once (on the first configure) and does not flip on reconfigure,
|
||||||
|
# when CMAKE_CUDA_ARCHITECTURES is already defined from our own cached default.
|
||||||
|
# The decision is revisited when the list itself moves, which the user can do with -D
|
||||||
|
# on any later configure of the same build directory. Keep the list each configure
|
||||||
|
# ends up with, so that such a change is told apart from our own cached default.
|
||||||
|
if(NOT DEFINED CUDA_SAMPLES_ARCHS_DEFAULTED)
|
||||||
|
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
|
||||||
|
list(JOIN CUDA_SAMPLES_MASTER_ARCHS ";" _default_archs)
|
||||||
|
set(CMAKE_CUDA_ARCHITECTURES "${_default_archs}" CACHE STRING "CUDA architectures")
|
||||||
|
unset(_default_archs)
|
||||||
|
set(CUDA_SAMPLES_ARCHS_DEFAULTED TRUE CACHE INTERNAL "")
|
||||||
|
else()
|
||||||
|
set(CUDA_SAMPLES_ARCHS_DEFAULTED FALSE CACHE INTERNAL "")
|
||||||
|
endif()
|
||||||
|
elseif(NOT "${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "${CUDA_SAMPLES_LAST_CONFIGURED_ARCHS}")
|
||||||
|
set(CUDA_SAMPLES_ARCHS_DEFAULTED FALSE CACHE INTERNAL "")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CUDA_SAMPLES_LAST_CONFIGURED_ARCHS "${CMAKE_CUDA_ARCHITECTURES}" CACHE INTERNAL "")
|
||||||
|
|
||||||
project(cuda-samples LANGUAGES C CXX CUDA)
|
project(cuda-samples LANGUAGES C CXX CUDA)
|
||||||
|
|
||||||
find_package(CUDAToolkit REQUIRED)
|
include(cmake/CudaSampleCommon.cmake)
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
add_subdirectory(cpp)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_STANDARD 17)
|
|
||||||
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90 100 110 120)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
|
||||||
if(ENABLE_CUDA_DEBUG)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G") # enable cuda-gdb (may significantly affect performance on some targets)
|
|
||||||
else()
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") # add line information to all builds for debug tools (exclusive to -G option)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --extended-lambda")
|
|
||||||
|
|
||||||
add_subdirectory(Samples)
|
|
||||||
|
|||||||
@@ -1,197 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NV_UTIL_NPP_EXCEPTIONS_H
|
|
||||||
#define NV_UTIL_NPP_EXCEPTIONS_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
/// All npp related C++ classes are put into the npp namespace.
|
|
||||||
namespace npp
|
|
||||||
{
|
|
||||||
|
|
||||||
/// Exception base class.
|
|
||||||
/// This exception base class will be used for everything C++ throught
|
|
||||||
/// the NPP project.
|
|
||||||
/// The exception contains a string message, as well as data fields for a string
|
|
||||||
/// containing the name of the file as well as the line number where the exception was thrown.
|
|
||||||
/// The easiest way of throwing exceptions and providing filename and line number is
|
|
||||||
/// to use one of the ASSERT macros defined for that purpose.
|
|
||||||
class Exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/// Constructor.
|
|
||||||
/// \param rMessage A message with information as to why the exception was thrown.
|
|
||||||
/// \param rFileName The name of the file where the exception was thrown.
|
|
||||||
/// \param nLineNumber Line number in the file where the exception was thrown.
|
|
||||||
explicit
|
|
||||||
Exception(const std::string &rMessage = "", const std::string &rFileName = "", unsigned int nLineNumber = 0)
|
|
||||||
: sMessage_(rMessage), sFileName_(rFileName), nLineNumber_(nLineNumber)
|
|
||||||
{ };
|
|
||||||
|
|
||||||
Exception(const Exception &rException)
|
|
||||||
: sMessage_(rException.sMessage_), sFileName_(rException.sFileName_), nLineNumber_(rException.nLineNumber_)
|
|
||||||
{ };
|
|
||||||
|
|
||||||
virtual
|
|
||||||
~Exception()
|
|
||||||
{ };
|
|
||||||
|
|
||||||
/// Get the exception's message.
|
|
||||||
const
|
|
||||||
std::string &
|
|
||||||
message()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return sMessage_;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the exception's file info.
|
|
||||||
const
|
|
||||||
std::string &
|
|
||||||
fileName()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return sFileName_;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the exceptions's line info.
|
|
||||||
unsigned int
|
|
||||||
lineNumber()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return nLineNumber_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Create a clone of this exception.
|
|
||||||
/// This creates a new Exception object on the heap. It is
|
|
||||||
/// the responsibility of the user of this function to free this memory
|
|
||||||
/// (delete x).
|
|
||||||
virtual
|
|
||||||
Exception *
|
|
||||||
clone()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return new Exception(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a single string with all the exceptions information.
|
|
||||||
/// The virtual toString() method is used by the operator<<()
|
|
||||||
/// so that all exceptions derived from this base-class can print
|
|
||||||
/// their full information correctly even if a reference to their
|
|
||||||
/// exact type is not had at the time of printing (i.e. the basic
|
|
||||||
/// operator<<() is used).
|
|
||||||
virtual
|
|
||||||
std::string
|
|
||||||
toString()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
std::ostringstream oOutputString;
|
|
||||||
oOutputString << fileName() << ":" << lineNumber() << ": " << message();
|
|
||||||
return oOutputString.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string sMessage_; ///< Message regarding the cause of the exception.
|
|
||||||
std::string sFileName_; ///< Name of the file where the exception was thrown.
|
|
||||||
unsigned int nLineNumber_; ///< Line number in the file where the exception was thrown
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Output stream inserter for Exception.
|
|
||||||
/// \param rOutputStream The stream the exception information is written to.
|
|
||||||
/// \param rException The exception that's being written.
|
|
||||||
/// \return Reference to the output stream being used.
|
|
||||||
std::ostream &
|
|
||||||
operator << (std::ostream &rOutputStream, const Exception &rException)
|
|
||||||
{
|
|
||||||
rOutputStream << rException.toString();
|
|
||||||
return rOutputStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Basic assert macro.
|
|
||||||
/// This macro should be used to enforce any kind of pre or post conditions.
|
|
||||||
/// Unlike the C-runtime assert macro, this macro does not abort execution, but throws
|
|
||||||
/// a C++ exception. The exception is automatically filled with information about the failing
|
|
||||||
/// condition, the filename and line number where the exception was thrown.
|
|
||||||
/// \note The macro is written in such a way that omitting a semicolon after its usage
|
|
||||||
/// causes a compiler error. The correct way to invoke this macro is:
|
|
||||||
/// NPP_ASSERT(n < MAX);
|
|
||||||
#define NPP_ASSERT(C) do {if (!(C)) throw npp::Exception(#C " assertion faild!", __FILE__, __LINE__);} while(false)
|
|
||||||
|
|
||||||
// ASSERT macro.
|
|
||||||
// Same functionality as the basic assert macro with the added ability to pass
|
|
||||||
// a message M. M should be a string literal.
|
|
||||||
// Note: Never use code inside ASSERT() that causes a side-effect ASSERT macros may get compiled
|
|
||||||
// out in release mode.
|
|
||||||
#define NPP_ASSERT_MSG(C, M) do {if (!(C)) throw npp::Exception(#C " assertion faild! Message: " M, __FILE__, __LINE__);} while(false)
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
/// Basic debug assert macro.
|
|
||||||
/// This macro is identical in every respect to NPP_ASSERT(C) but it does get compiled to a
|
|
||||||
/// no-op in release builds. It is therefor of utmost importance to not put statements into
|
|
||||||
/// this macro that cause side effects required for correct program execution.
|
|
||||||
#define NPP_DEBUG_ASSERT(C) do {if (!(C)) throw npp::Exception(#C " debug assertion faild!", __FILE__, __LINE__);} while(false)
|
|
||||||
#else
|
|
||||||
#define NPP_DEBUG_ASSERT(C)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// ASSERT for null-pointer test.
|
|
||||||
/// It is safe to put code with side effects into this macro. Also: This macro never
|
|
||||||
/// gets compiled to a no-op because resource allocation may fail based on external causes not under
|
|
||||||
/// control of a software developer.
|
|
||||||
#define NPP_ASSERT_NOT_NULL(P) do {if ((P) == 0) throw npp::Exception(#P " not null assertion faild!", __FILE__, __LINE__);} while(false)
|
|
||||||
|
|
||||||
/// Macro for flagging methods as not implemented.
|
|
||||||
/// The macro throws an exception with a message that an implementation was missing
|
|
||||||
#define NPP_NOT_IMPLEMENTED() do {throw npp::Exception("Implementation missing!", __FILE__, __LINE__);} while(false)
|
|
||||||
|
|
||||||
/// Macro for checking error return code of CUDA (runtime) calls.
|
|
||||||
/// This macro never gets disabled.
|
|
||||||
#define NPP_CHECK_CUDA(S) do {cudaError_t eCUDAResult; \
|
|
||||||
eCUDAResult = S; \
|
|
||||||
if (eCUDAResult != cudaSuccess) std::cout << "NPP_CHECK_CUDA - eCUDAResult = " << eCUDAResult << std::endl; \
|
|
||||||
NPP_ASSERT(eCUDAResult == cudaSuccess);} while (false)
|
|
||||||
|
|
||||||
/// Macro for checking error return code for NPP calls.
|
|
||||||
#define NPP_CHECK_NPP(S) do {NppStatus eStatusNPP; \
|
|
||||||
eStatusNPP = S; \
|
|
||||||
if (eStatusNPP != NPP_SUCCESS) std::cout << "NPP_CHECK_NPP - eStatusNPP = " << _cudaGetErrorEnum(eStatusNPP) << "("<< eStatusNPP << ")" << std::endl; \
|
|
||||||
NPP_ASSERT(eStatusNPP == NPP_SUCCESS);} while (false)
|
|
||||||
|
|
||||||
/// Macro for checking error return codes from cuFFT calls.
|
|
||||||
#define NPP_CHECK_CUFFT(S) do {cufftResult eCUFFTResult; \
|
|
||||||
eCUFFTResult = S; \
|
|
||||||
if (eCUFFTResult != NPP_SUCCESS) std::cout << "NPP_CHECK_CUFFT - eCUFFTResult = " << eCUFFTResult << std::endl; \
|
|
||||||
NPP_ASSERT(eCUFFTResult == CUFFT_SUCCESS);} while (false)
|
|
||||||
|
|
||||||
} // npp namespace
|
|
||||||
|
|
||||||
#endif // NV_UTIL_NPP_EXCEPTIONS_H
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NV_UTIL_NPP_IMAGE_H
|
|
||||||
#define NV_UTIL_NPP_IMAGE_H
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
namespace npp
|
|
||||||
{
|
|
||||||
|
|
||||||
class Image
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
struct Size
|
|
||||||
{
|
|
||||||
unsigned int nWidth;
|
|
||||||
unsigned int nHeight;
|
|
||||||
|
|
||||||
Size() : nWidth(0), nHeight(0)
|
|
||||||
{ };
|
|
||||||
|
|
||||||
Size(unsigned int nWidthNew, unsigned nHeightNew) : nWidth(nWidthNew), nHeight(nHeightNew)
|
|
||||||
{ };
|
|
||||||
|
|
||||||
Size(const Size &rSize) : nWidth(rSize.nWidth), nHeight(rSize.nHeight)
|
|
||||||
{ };
|
|
||||||
|
|
||||||
Size &
|
|
||||||
operator= (const Size &rSize)
|
|
||||||
{
|
|
||||||
if (&rSize == this)
|
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
nWidth = rSize.nWidth;
|
|
||||||
nHeight = rSize.nHeight;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
swap(Size &rSize)
|
|
||||||
{
|
|
||||||
unsigned int nTemp;
|
|
||||||
nTemp = nWidth;
|
|
||||||
nWidth = rSize.nWidth;
|
|
||||||
rSize.nWidth = nTemp;
|
|
||||||
|
|
||||||
nTemp = nHeight;
|
|
||||||
nHeight = rSize.nHeight;
|
|
||||||
rSize.nHeight = nTemp;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Image()
|
|
||||||
{ };
|
|
||||||
|
|
||||||
Image(unsigned int nWidth, unsigned int nHeight) : oSize_(nWidth, nHeight)
|
|
||||||
{ };
|
|
||||||
|
|
||||||
Image(const Image::Size &rSize) : oSize_(rSize)
|
|
||||||
{ };
|
|
||||||
|
|
||||||
Image(const Image &rImage) : oSize_(rImage.oSize_)
|
|
||||||
{ };
|
|
||||||
|
|
||||||
virtual
|
|
||||||
~Image()
|
|
||||||
{ };
|
|
||||||
|
|
||||||
Image &
|
|
||||||
operator= (const Image &rImage)
|
|
||||||
{
|
|
||||||
if (&rImage == this)
|
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
oSize_ = rImage.oSize_;
|
|
||||||
return *this;
|
|
||||||
};
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
width()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return oSize_.nWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
height()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return oSize_.nHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
Size
|
|
||||||
size()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return oSize_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
swap(Image &rImage)
|
|
||||||
{
|
|
||||||
oSize_.swap(rImage.oSize_);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Size oSize_;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool
|
|
||||||
operator== (const Image::Size &rFirst, const Image::Size &rSecond)
|
|
||||||
{
|
|
||||||
return rFirst.nWidth == rSecond.nWidth && rFirst.nHeight == rSecond.nHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
operator!= (const Image::Size &rFirst, const Image::Size &rSecond)
|
|
||||||
{
|
|
||||||
return rFirst.nWidth != rSecond.nWidth || rFirst.nHeight != rSecond.nHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // npp namespace
|
|
||||||
|
|
||||||
|
|
||||||
#endif // NV_UTIL_NPP_IMAGE_H
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NV_UTIL_NPP_IMAGE_ALLOCATORS_CPU_H
|
|
||||||
#define NV_UTIL_NPP_IMAGE_ALLOCATORS_CPU_H
|
|
||||||
|
|
||||||
#include "Exceptions.h"
|
|
||||||
|
|
||||||
namespace npp
|
|
||||||
{
|
|
||||||
|
|
||||||
template <typename D, size_t N>
|
|
||||||
class ImageAllocatorCPU
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
D *
|
|
||||||
Malloc2D(unsigned int nWidth, unsigned int nHeight, unsigned int *pPitch)
|
|
||||||
{
|
|
||||||
NPP_ASSERT(nWidth * nHeight > 0);
|
|
||||||
|
|
||||||
D *pResult = new D[nWidth * N * nHeight];
|
|
||||||
*pPitch = nWidth * sizeof(D) * N;
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free2D(D *pPixels)
|
|
||||||
{
|
|
||||||
delete[] pPixels;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy2D(D *pDst, size_t nDstPitch, const D *pSrc, size_t nSrcPitch, size_t nWidth, size_t nHeight)
|
|
||||||
{
|
|
||||||
const void *pSrcLine = pSrc;
|
|
||||||
void *pDstLine = pDst;
|
|
||||||
|
|
||||||
for (size_t iLine = 0; iLine < nHeight; ++iLine)
|
|
||||||
{
|
|
||||||
// copy one line worth of data
|
|
||||||
memcpy(pDst, pSrc, nWidth * N * sizeof(D));
|
|
||||||
// move data pointers to next line
|
|
||||||
pDst += nDstPitch;
|
|
||||||
pSrc += nSrcPitch;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // npp namespace
|
|
||||||
|
|
||||||
#endif // NV_UTIL_NPP_IMAGE_ALLOCATORS_CPU_H
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,149 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NV_UTIL_NPP_IMAGE_IO_H
|
|
||||||
#define NV_UTIL_NPP_IMAGE_IO_H
|
|
||||||
|
|
||||||
#include "ImagesCPU.h"
|
|
||||||
#include "ImagesNPP.h"
|
|
||||||
|
|
||||||
#include "FreeImage.h"
|
|
||||||
#include "Exceptions.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "string.h"
|
|
||||||
|
|
||||||
|
|
||||||
// Error handler for FreeImage library.
|
|
||||||
// In case this handler is invoked, it throws an NPP exception.
|
|
||||||
void
|
|
||||||
FreeImageErrorHandler(FREE_IMAGE_FORMAT oFif, const char *zMessage)
|
|
||||||
{
|
|
||||||
throw npp::Exception(zMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace npp
|
|
||||||
{
|
|
||||||
// Load a gray-scale image from disk.
|
|
||||||
void
|
|
||||||
loadImage(const std::string &rFileName, ImageCPU_8u_C1 &rImage)
|
|
||||||
{
|
|
||||||
// set your own FreeImage error handler
|
|
||||||
FreeImage_SetOutputMessage(FreeImageErrorHandler);
|
|
||||||
|
|
||||||
FREE_IMAGE_FORMAT eFormat = FreeImage_GetFileType(rFileName.c_str());
|
|
||||||
|
|
||||||
// no signature? try to guess the file format from the file extension
|
|
||||||
if (eFormat == FIF_UNKNOWN)
|
|
||||||
{
|
|
||||||
eFormat = FreeImage_GetFIFFromFilename(rFileName.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
NPP_ASSERT(eFormat != FIF_UNKNOWN);
|
|
||||||
// check that the plugin has reading capabilities ...
|
|
||||||
FIBITMAP *pBitmap;
|
|
||||||
|
|
||||||
if (FreeImage_FIFSupportsReading(eFormat))
|
|
||||||
{
|
|
||||||
pBitmap = FreeImage_Load(eFormat, rFileName.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
NPP_ASSERT(pBitmap != 0);
|
|
||||||
// make sure this is an 8-bit single channel image
|
|
||||||
NPP_ASSERT(FreeImage_GetColorType(pBitmap) == FIC_MINISBLACK);
|
|
||||||
NPP_ASSERT(FreeImage_GetBPP(pBitmap) == 8);
|
|
||||||
|
|
||||||
// create an ImageCPU to receive the loaded image data
|
|
||||||
ImageCPU_8u_C1 oImage(FreeImage_GetWidth(pBitmap), FreeImage_GetHeight(pBitmap));
|
|
||||||
|
|
||||||
// Copy the FreeImage data into the new ImageCPU
|
|
||||||
unsigned int nSrcPitch = FreeImage_GetPitch(pBitmap);
|
|
||||||
const Npp8u *pSrcLine = FreeImage_GetBits(pBitmap) + nSrcPitch * (FreeImage_GetHeight(pBitmap) -1);
|
|
||||||
Npp8u *pDstLine = oImage.data();
|
|
||||||
unsigned int nDstPitch = oImage.pitch();
|
|
||||||
|
|
||||||
for (size_t iLine = 0; iLine < oImage.height(); ++iLine)
|
|
||||||
{
|
|
||||||
memcpy(pDstLine, pSrcLine, oImage.width() * sizeof(Npp8u));
|
|
||||||
pSrcLine -= nSrcPitch;
|
|
||||||
pDstLine += nDstPitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
// swap the user given image with our result image, effecively
|
|
||||||
// moving our newly loaded image data into the user provided shell
|
|
||||||
oImage.swap(rImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save an gray-scale image to disk.
|
|
||||||
void
|
|
||||||
saveImage(const std::string &rFileName, const ImageCPU_8u_C1 &rImage)
|
|
||||||
{
|
|
||||||
// create the result image storage using FreeImage so we can easily
|
|
||||||
// save
|
|
||||||
FIBITMAP *pResultBitmap = FreeImage_Allocate(rImage.width(), rImage.height(), 8 /* bits per pixel */);
|
|
||||||
NPP_ASSERT_NOT_NULL(pResultBitmap);
|
|
||||||
unsigned int nDstPitch = FreeImage_GetPitch(pResultBitmap);
|
|
||||||
Npp8u *pDstLine = FreeImage_GetBits(pResultBitmap) + nDstPitch * (rImage.height()-1);
|
|
||||||
const Npp8u *pSrcLine = rImage.data();
|
|
||||||
unsigned int nSrcPitch = rImage.pitch();
|
|
||||||
|
|
||||||
for (size_t iLine = 0; iLine < rImage.height(); ++iLine)
|
|
||||||
{
|
|
||||||
memcpy(pDstLine, pSrcLine, rImage.width() * sizeof(Npp8u));
|
|
||||||
pSrcLine += nSrcPitch;
|
|
||||||
pDstLine -= nDstPitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
// now save the result image
|
|
||||||
bool bSuccess;
|
|
||||||
bSuccess = FreeImage_Save(FIF_PGM, pResultBitmap, rFileName.c_str(), 0) == TRUE;
|
|
||||||
NPP_ASSERT_MSG(bSuccess, "Failed to save result image.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load a gray-scale image from disk.
|
|
||||||
void
|
|
||||||
loadImage(const std::string &rFileName, ImageNPP_8u_C1 &rImage)
|
|
||||||
{
|
|
||||||
ImageCPU_8u_C1 oImage;
|
|
||||||
loadImage(rFileName, oImage);
|
|
||||||
ImageNPP_8u_C1 oResult(oImage);
|
|
||||||
rImage.swap(oResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save an gray-scale image to disk.
|
|
||||||
void
|
|
||||||
saveImage(const std::string &rFileName, const ImageNPP_8u_C1 &rImage)
|
|
||||||
{
|
|
||||||
ImageCPU_8u_C1 oHostImage(rImage.size());
|
|
||||||
// copy the device result data
|
|
||||||
rImage.copyTo(oHostImage.data(), oHostImage.pitch());
|
|
||||||
saveImage(rFileName, oHostImage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif // NV_UTIL_NPP_IMAGE_IO_H
|
|
||||||
@@ -1,171 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NV_UTIL_NPP_IMAGE_PACKED_H
|
|
||||||
#define NV_UTIL_NPP_IMAGE_PACKED_H
|
|
||||||
|
|
||||||
#include "Image.h"
|
|
||||||
#include "Pixel.h"
|
|
||||||
|
|
||||||
namespace npp
|
|
||||||
{
|
|
||||||
template<typename D, size_t N, class A>
|
|
||||||
class ImagePacked: public npp::Image
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef npp::Pixel<D, N> tPixel;
|
|
||||||
typedef D tData;
|
|
||||||
static const size_t gnChannels = N;
|
|
||||||
typedef npp::Image::Size tSize;
|
|
||||||
|
|
||||||
ImagePacked(): aPixels_(0)
|
|
||||||
, nPitch_(0)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImagePacked(unsigned int nWidth, unsigned int nHeight): Image(nWidth, nHeight)
|
|
||||||
, aPixels_(0)
|
|
||||||
, nPitch_(0)
|
|
||||||
{
|
|
||||||
aPixels_ = A::Malloc2D(width(), height(), &nPitch_);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImagePacked(unsigned int nWidth, unsigned int nHeight, bool bTight): Image(nWidth, nHeight)
|
|
||||||
, aPixels_(0)
|
|
||||||
, nPitch_(0)
|
|
||||||
{
|
|
||||||
aPixels_ = A::Malloc2D(width(), height(), &nPitch_, bTight);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImagePacked(const tSize &rSize): Image(rSize)
|
|
||||||
, aPixels_(0)
|
|
||||||
, nPitch_(0)
|
|
||||||
{
|
|
||||||
aPixels_ = A::Malloc2D(width(), height(), &nPitch_);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImagePacked(const ImagePacked<D, N, A> &rImage): Image(rImage)
|
|
||||||
, aPixels_(0)
|
|
||||||
, nPitch_(rImage.pitch())
|
|
||||||
{
|
|
||||||
aPixels_ = A::Malloc2D(width(), height(), &nPitch_);
|
|
||||||
A::Copy2D(aPixels_, nPitch_, rImage.pixels(), rImage.pitch(), width(), height());
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual
|
|
||||||
~ImagePacked()
|
|
||||||
{
|
|
||||||
A::Free2D(aPixels_);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImagePacked &
|
|
||||||
operator= (const ImagePacked<D, N, A> &rImage)
|
|
||||||
{
|
|
||||||
// in case of self-assignment
|
|
||||||
if (&rImage == this)
|
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
A::Free2D(aPixels_);
|
|
||||||
aPixels_ = 0;
|
|
||||||
nPitch_ = 0;
|
|
||||||
|
|
||||||
// assign parent class's data fields (width, height)
|
|
||||||
Image::operator =(rImage);
|
|
||||||
|
|
||||||
aPixels_ = A::Malloc2D(width(), height(), &nPitch_);
|
|
||||||
A::Copy2D(aPixels_, nPitch_, rImage.data(), rImage.pitch(), width(), height());
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
pitch()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return nPitch_;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a pointer to the pixel array.
|
|
||||||
/// The result pointer can be offset to pixel at position (x, y) and
|
|
||||||
/// even negative offsets are allowed.
|
|
||||||
/// \param nX Horizontal pointer/array offset.
|
|
||||||
/// \param nY Vertical pointer/array offset.
|
|
||||||
/// \return Pointer to the pixel array (or first pixel in array with coordinates (nX, nY).
|
|
||||||
tPixel *
|
|
||||||
pixels(int nX = 0, int nY = 0)
|
|
||||||
{
|
|
||||||
return reinterpret_cast<tPixel *>(reinterpret_cast<unsigned char *>(aPixels_) + nY * pitch() + nX * gnChannels * sizeof(D));
|
|
||||||
}
|
|
||||||
|
|
||||||
const
|
|
||||||
tPixel *
|
|
||||||
pixels(int nX = 0, int nY = 0)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return reinterpret_cast<const tPixel *>(reinterpret_cast<unsigned char *>(aPixels_) + nY * pitch() + nX * gnChannels * sizeof(D));
|
|
||||||
}
|
|
||||||
|
|
||||||
D *
|
|
||||||
data(int nX = 0, int nY = 0)
|
|
||||||
{
|
|
||||||
return reinterpret_cast<D *>(pixels(nX, nY));
|
|
||||||
}
|
|
||||||
|
|
||||||
const
|
|
||||||
D *
|
|
||||||
data(int nX = 0, int nY = 0)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return reinterpret_cast<const D *>(pixels(nX, nY));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
swap(ImagePacked<D, N, A> &rImage)
|
|
||||||
{
|
|
||||||
Image::swap(rImage);
|
|
||||||
|
|
||||||
tData *aTemp = aPixels_;
|
|
||||||
aPixels_ = rImage.aPixels_;
|
|
||||||
rImage.aPixels_ = aTemp;
|
|
||||||
|
|
||||||
unsigned int nTemp = nPitch_;
|
|
||||||
nPitch_ = rImage.nPitch_;
|
|
||||||
rImage.nPitch_ = nTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
D *aPixels_;
|
|
||||||
unsigned int nPitch_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // npp namespace
|
|
||||||
|
|
||||||
|
|
||||||
#endif // NV_IMAGE_IPP_H
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NV_UTIL_NPP_IMAGES_CPU_H
|
|
||||||
#define NV_UTIL_NPP_IMAGES_CPU_H
|
|
||||||
|
|
||||||
#include "ImagePacked.h"
|
|
||||||
|
|
||||||
#include "ImageAllocatorsCPU.h"
|
|
||||||
#include "Exceptions.h"
|
|
||||||
|
|
||||||
#include <npp.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace npp
|
|
||||||
{
|
|
||||||
|
|
||||||
template<typename D, unsigned int N, class A>
|
|
||||||
class ImageCPU: public npp::ImagePacked<D, N, A>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
ImageCPU()
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageCPU(unsigned int nWidth, unsigned int nHeight): ImagePacked<D, N, A>(nWidth, nHeight)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit
|
|
||||||
ImageCPU(const npp::Image::Size &rSize): ImagePacked<D, N, A>(rSize)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageCPU(const ImageCPU<D, N, A> &rImage): Image(rImage)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual
|
|
||||||
~ImageCPU()
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageCPU &
|
|
||||||
operator= (const ImageCPU<D, N, A> &rImage)
|
|
||||||
{
|
|
||||||
ImagePacked<D, N, A>::operator= (rImage);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
npp::Pixel<D, N> &
|
|
||||||
operator()(unsigned int iX, unsigned int iY)
|
|
||||||
{
|
|
||||||
return *ImagePacked<D, N, A>::pixels(iX, iY);
|
|
||||||
}
|
|
||||||
|
|
||||||
npp::Pixel<D, N>
|
|
||||||
operator()(unsigned int iX, unsigned int iY)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return *ImagePacked<D, N, A>::pixels(iX, iY);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
typedef ImageCPU<Npp8u, 1, npp::ImageAllocatorCPU<Npp8u, 1> > ImageCPU_8u_C1;
|
|
||||||
typedef ImageCPU<Npp8u, 2, npp::ImageAllocatorCPU<Npp8u, 2> > ImageCPU_8u_C2;
|
|
||||||
typedef ImageCPU<Npp8u, 3, npp::ImageAllocatorCPU<Npp8u, 3> > ImageCPU_8u_C3;
|
|
||||||
typedef ImageCPU<Npp8u, 4, npp::ImageAllocatorCPU<Npp8u, 4> > ImageCPU_8u_C4;
|
|
||||||
|
|
||||||
typedef ImageCPU<Npp16u, 1, npp::ImageAllocatorCPU<Npp16u, 1> > ImageCPU_16u_C1;
|
|
||||||
typedef ImageCPU<Npp16u, 3, npp::ImageAllocatorCPU<Npp16u, 3> > ImageCPU_16u_C3;
|
|
||||||
typedef ImageCPU<Npp16u, 4, npp::ImageAllocatorCPU<Npp16u, 4> > ImageCPU_16u_C4;
|
|
||||||
|
|
||||||
typedef ImageCPU<Npp16s, 1, npp::ImageAllocatorCPU<Npp16s, 1> > ImageCPU_16s_C1;
|
|
||||||
typedef ImageCPU<Npp16s, 3, npp::ImageAllocatorCPU<Npp16s, 3> > ImageCPU_16s_C3;
|
|
||||||
typedef ImageCPU<Npp16s, 4, npp::ImageAllocatorCPU<Npp16s, 4> > ImageCPU_16s_C4;
|
|
||||||
|
|
||||||
typedef ImageCPU<Npp32s, 1, npp::ImageAllocatorCPU<Npp32s, 1> > ImageCPU_32s_C1;
|
|
||||||
typedef ImageCPU<Npp32s, 3, npp::ImageAllocatorCPU<Npp32s, 3> > ImageCPU_32s_C3;
|
|
||||||
typedef ImageCPU<Npp32s, 4, npp::ImageAllocatorCPU<Npp32s, 4> > ImageCPU_32s_C4;
|
|
||||||
|
|
||||||
typedef ImageCPU<Npp32f, 1, npp::ImageAllocatorCPU<Npp32f, 1> > ImageCPU_32f_C1;
|
|
||||||
typedef ImageCPU<Npp32f, 3, npp::ImageAllocatorCPU<Npp32f, 3> > ImageCPU_32f_C3;
|
|
||||||
typedef ImageCPU<Npp32f, 4, npp::ImageAllocatorCPU<Npp32f, 4> > ImageCPU_32f_C4;
|
|
||||||
|
|
||||||
} // npp namespace
|
|
||||||
|
|
||||||
#endif // NV_IMAGE_IPP_H
|
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef NV_UTIL_NPP_IMAGES_NPP_H
|
|
||||||
#define NV_UTIL_NPP_IMAGES_NPP_H
|
|
||||||
|
|
||||||
#include "Exceptions.h"
|
|
||||||
#include "ImagePacked.h"
|
|
||||||
|
|
||||||
#include "ImageAllocatorsNPP.h"
|
|
||||||
#include <cuda_runtime.h>
|
|
||||||
|
|
||||||
namespace npp
|
|
||||||
{
|
|
||||||
// forward declaration
|
|
||||||
template<typename D, unsigned int N, class A> class ImageCPU;
|
|
||||||
|
|
||||||
template<typename D, unsigned int N>
|
|
||||||
class ImageNPP: public npp::ImagePacked<D, N, npp::ImageAllocator<D, N> >
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ImageNPP()
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageNPP(unsigned int nWidth, unsigned int nHeight, bool bTight = false): ImagePacked<D, N, npp::ImageAllocator<D, N> >(nWidth, nHeight, bTight)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageNPP(const npp::Image::Size &rSize): ImagePacked<D, N, npp::ImageAllocator<D, N> >(rSize)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageNPP(const ImageNPP<D, N> &rImage): Image(rImage)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class X>
|
|
||||||
explicit
|
|
||||||
ImageNPP(const ImageCPU<D, N, X> &rImage, bool bTight = false): ImagePacked<D, N, npp::ImageAllocator<D, N> >(rImage.width(), rImage.height(), bTight)
|
|
||||||
{
|
|
||||||
npp::ImageAllocator<D, N>::HostToDeviceCopy2D(ImagePacked<D, N, npp::ImageAllocator<D, N> >::data(),
|
|
||||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::pitch(),
|
|
||||||
rImage.data(),
|
|
||||||
rImage.pitch(),
|
|
||||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::width(),
|
|
||||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::height());
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual
|
|
||||||
~ImageNPP()
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageNPP &
|
|
||||||
operator= (const ImageNPP<D, N> &rImage)
|
|
||||||
{
|
|
||||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::operator= (rImage);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
copyTo(D *pData, unsigned int nPitch)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
NPP_ASSERT((ImagePacked<D, N, npp::ImageAllocator<D, N> >::width() * sizeof(npp::Pixel<D, N>) <= nPitch));
|
|
||||||
npp::ImageAllocator<D, N>::DeviceToHostCopy2D(pData,
|
|
||||||
nPitch,
|
|
||||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::data(),
|
|
||||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::pitch(),
|
|
||||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::width(),
|
|
||||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::height());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
copyFrom(D *pData, unsigned int nPitch)
|
|
||||||
{
|
|
||||||
NPP_ASSERT((ImagePacked<D, N, npp::ImageAllocator<D, N> >::width() * sizeof(npp::Pixel<D, N>) <= nPitch));
|
|
||||||
npp::ImageAllocator<D, N>::HostToDeviceCopy2D(ImagePacked<D, N, npp::ImageAllocator<D, N> >::data(),
|
|
||||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::pitch(),
|
|
||||||
pData,
|
|
||||||
nPitch,
|
|
||||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::width(),
|
|
||||||
ImagePacked<D, N, npp::ImageAllocator<D, N> >::height());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef ImageNPP<Npp8u, 1> ImageNPP_8u_C1;
|
|
||||||
typedef ImageNPP<Npp8u, 2> ImageNPP_8u_C2;
|
|
||||||
typedef ImageNPP<Npp8u, 3> ImageNPP_8u_C3;
|
|
||||||
typedef ImageNPP<Npp8u, 4> ImageNPP_8u_C4;
|
|
||||||
|
|
||||||
typedef ImageNPP<Npp16u, 1> ImageNPP_16u_C1;
|
|
||||||
typedef ImageNPP<Npp16u, 2> ImageNPP_16u_C2;
|
|
||||||
typedef ImageNPP<Npp16u, 3> ImageNPP_16u_C3;
|
|
||||||
typedef ImageNPP<Npp16u, 4> ImageNPP_16u_C4;
|
|
||||||
|
|
||||||
typedef ImageNPP<Npp16s, 1> ImageNPP_16s_C1;
|
|
||||||
typedef ImageNPP<Npp16s, 3> ImageNPP_16s_C3;
|
|
||||||
typedef ImageNPP<Npp16s, 4> ImageNPP_16s_C4;
|
|
||||||
|
|
||||||
typedef ImageNPP<Npp32s, 1> ImageNPP_32s_C1;
|
|
||||||
typedef ImageNPP<Npp32s, 3> ImageNPP_32s_C3;
|
|
||||||
typedef ImageNPP<Npp32s, 4> ImageNPP_32s_C4;
|
|
||||||
|
|
||||||
typedef ImageNPP<Npp32f, 1> ImageNPP_32f_C1;
|
|
||||||
typedef ImageNPP<Npp32f, 2> ImageNPP_32f_C2;
|
|
||||||
typedef ImageNPP<Npp32f, 3> ImageNPP_32f_C3;
|
|
||||||
typedef ImageNPP<Npp32f, 4> ImageNPP_32f_C4;
|
|
||||||
|
|
||||||
typedef ImageNPP<Npp64f, 1> ImageNPP_64f_C1;
|
|
||||||
typedef ImageNPP<Npp64f, 2> ImageNPP_64f_C2;
|
|
||||||
typedef ImageNPP<Npp64f, 3> ImageNPP_64f_C3;
|
|
||||||
typedef ImageNPP<Npp64f, 4> ImageNPP_64f_C4;
|
|
||||||
|
|
||||||
} // npp namespace
|
|
||||||
|
|
||||||
#endif // NV_UTIL_NPP_IMAGES_NPP_H
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef NV_UTIL_PIXEL_H
|
|
||||||
#define NV_UTIL_PIXEL_H
|
|
||||||
|
|
||||||
#include "Exceptions.h"
|
|
||||||
|
|
||||||
namespace npp
|
|
||||||
{
|
|
||||||
template <typename D, size_t N>
|
|
||||||
struct Pixel
|
|
||||||
{ };
|
|
||||||
|
|
||||||
template <typename D>
|
|
||||||
struct Pixel<D, 1>
|
|
||||||
{
|
|
||||||
D x;
|
|
||||||
|
|
||||||
const D &
|
|
||||||
operator[](size_t iChannel)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
NPP_ASSERT(iChannel < 1);
|
|
||||||
return (&x)[iChannel];
|
|
||||||
}
|
|
||||||
|
|
||||||
D &
|
|
||||||
operator[](size_t iChannel)
|
|
||||||
{
|
|
||||||
NPP_ASSERT(iChannel < 1);
|
|
||||||
return (&x)[iChannel];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename D>
|
|
||||||
struct Pixel<D, 2>
|
|
||||||
{
|
|
||||||
D x,y;
|
|
||||||
|
|
||||||
const D &
|
|
||||||
operator[](size_t iChannel)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
NPP_ASSERT(iChannel < 2);
|
|
||||||
return (&x)[iChannel];
|
|
||||||
}
|
|
||||||
|
|
||||||
D &
|
|
||||||
operator[](size_t iChannel)
|
|
||||||
{
|
|
||||||
NPP_ASSERT(iChannel < 2);
|
|
||||||
return (&x)[iChannel];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename D>
|
|
||||||
struct Pixel<D, 3>
|
|
||||||
{
|
|
||||||
D x,y,z;
|
|
||||||
|
|
||||||
const D &
|
|
||||||
operator[](size_t iChannel)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
NPP_ASSERT(iChannel < 3);
|
|
||||||
return (&x)[iChannel];
|
|
||||||
}
|
|
||||||
|
|
||||||
D &
|
|
||||||
operator[](size_t iChannel)
|
|
||||||
{
|
|
||||||
NPP_ASSERT(iChannel < 3);
|
|
||||||
return (&x)[iChannel];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename D>
|
|
||||||
struct Pixel<D, 4>
|
|
||||||
{
|
|
||||||
D x, y, z, w;
|
|
||||||
|
|
||||||
const D &
|
|
||||||
operator[](size_t iChannel)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
NPP_ASSERT(iChannel < 4);
|
|
||||||
return (&x)[iChannel];
|
|
||||||
}
|
|
||||||
|
|
||||||
D &
|
|
||||||
operator[](size_t iChannel)
|
|
||||||
{
|
|
||||||
NPP_ASSERT(iChannel < 4);
|
|
||||||
return (&x)[iChannel];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // npp namespace
|
|
||||||
|
|
||||||
#endif // NV_UTIL_PIXEL_H
|
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef NV_UTIL_NPP_SIGNAL_H
|
|
||||||
#define NV_UTIL_NPP_SIGNAL_H
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
namespace npp
|
|
||||||
{
|
|
||||||
class Signal
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Signal() : nSize_(0)
|
|
||||||
{ };
|
|
||||||
|
|
||||||
explicit
|
|
||||||
Signal(size_t nSize) : nSize_(nSize)
|
|
||||||
{ };
|
|
||||||
|
|
||||||
Signal(const Signal &rSignal) : nSize_(rSignal.nSize_)
|
|
||||||
{ };
|
|
||||||
|
|
||||||
virtual
|
|
||||||
~Signal()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
Signal &
|
|
||||||
operator= (const Signal &rSignal)
|
|
||||||
{
|
|
||||||
nSize_ = rSignal.nSize_;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
|
||||||
size()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return nSize_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
swap(Signal &rSignal)
|
|
||||||
{
|
|
||||||
size_t nTemp = nSize_;
|
|
||||||
nSize_ = rSignal.nSize_;
|
|
||||||
rSignal.nSize_ = nTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
size_t nSize_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename D, class A>
|
|
||||||
class SignalTemplate: public Signal
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef D tData;
|
|
||||||
|
|
||||||
SignalTemplate(): aValues_(0)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
SignalTemplate(size_t nSize): Signal(nSize)
|
|
||||||
, aValues_(0)
|
|
||||||
{
|
|
||||||
aValues_ = A::Malloc1D(size());
|
|
||||||
}
|
|
||||||
|
|
||||||
SignalTemplate(const SignalTemplate<D, A> &rSignal): Signal(rSignal)
|
|
||||||
, aValues_(0)
|
|
||||||
{
|
|
||||||
aValues_ = A::Malloc1D(size());
|
|
||||||
A::Copy1D(aValues_, rSignal.values(), size());
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual
|
|
||||||
~SignalTemplate()
|
|
||||||
{
|
|
||||||
A::Free1D(aValues_);
|
|
||||||
}
|
|
||||||
|
|
||||||
SignalTemplate &
|
|
||||||
operator= (const SignalTemplate<D, A> &rSignal)
|
|
||||||
{
|
|
||||||
// in case of self-assignment
|
|
||||||
if (&rSignal == this)
|
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
A::Free1D(aValues_);
|
|
||||||
this->aPixels_ = 0;
|
|
||||||
|
|
||||||
// assign parent class's data fields (width, height)
|
|
||||||
Signal::operator =(rSignal);
|
|
||||||
|
|
||||||
aValues_ = A::Malloc1D(size());
|
|
||||||
A::Copy1D(aValues_, rSignal.value(), size());
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a pointer to the pixel array.
|
|
||||||
/// The result pointer can be offset to pixel at position (x, y) and
|
|
||||||
/// even negative offsets are allowed.
|
|
||||||
/// \param nX Horizontal pointer/array offset.
|
|
||||||
/// \param nY Vertical pointer/array offset.
|
|
||||||
/// \return Pointer to the pixel array (or first pixel in array with coordinates (nX, nY).
|
|
||||||
tData *
|
|
||||||
values(int i = 0)
|
|
||||||
{
|
|
||||||
return aValues_ + i;
|
|
||||||
}
|
|
||||||
|
|
||||||
const
|
|
||||||
tData *
|
|
||||||
values(int i = 0)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return aValues_ + i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
swap(SignalTemplate<D, A> &rSignal)
|
|
||||||
{
|
|
||||||
Signal::swap(rSignal);
|
|
||||||
|
|
||||||
tData *aTemp = this->aValues_;
|
|
||||||
this->aValues_ = rSignal.aValues_;
|
|
||||||
rSignal.aValues_ = aTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
D *aValues_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // npp namespace
|
|
||||||
|
|
||||||
|
|
||||||
#endif // NV_UTIL_NPP_SIGNAL_H
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef NV_UTIL_NPP_SIGNAL_ALLOCATORS_CPU_H
|
|
||||||
#define NV_UTIL_NPP_SIGNAL_ALLOCATORS_CPU_H
|
|
||||||
|
|
||||||
#include "Exceptions.h"
|
|
||||||
|
|
||||||
namespace npp
|
|
||||||
{
|
|
||||||
|
|
||||||
template <typename D>
|
|
||||||
class SignalAllocatorCPU
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
D *
|
|
||||||
Malloc1D(unsigned int nSize)
|
|
||||||
{
|
|
||||||
return new D[nSize];;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(D *pPixels)
|
|
||||||
{
|
|
||||||
delete[] pPixels;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(D *pDst, const D *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
memcpy(pDst, pSrc, nSize * sizeof(D));
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // npp namespace
|
|
||||||
|
|
||||||
#endif // NV_UTIL_NPP_SIGNAL_ALLOCATORS_CPU_H
|
|
||||||
@@ -1,684 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef NV_UTIL_NPP_SIGNAL_ALLOCATORS_NPP_H
|
|
||||||
#define NV_UTIL_NPP_SIGNAL_ALLOCATORS_NPP_H
|
|
||||||
|
|
||||||
|
|
||||||
#include "Exceptions.h"
|
|
||||||
|
|
||||||
#include <npps.h>
|
|
||||||
#include <cuda_runtime.h>
|
|
||||||
|
|
||||||
namespace npp
|
|
||||||
{
|
|
||||||
|
|
||||||
template <typename D>
|
|
||||||
class SignalAllocator
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class SignalAllocator<Npp8u>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
Npp8u *
|
|
||||||
Malloc1D(size_t nSize)
|
|
||||||
{
|
|
||||||
Npp8u *pResult = nppsMalloc_8u(static_cast<int>(nSize));
|
|
||||||
NPP_ASSERT(pResult != 0);
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(Npp8u *pValues)
|
|
||||||
{
|
|
||||||
nppsFree(pValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(Npp8u *pDst, const Npp8u *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp8u),cudaMemcpyDeviceToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
HostToDeviceCopy1D(Npp8u *pDst, const Npp8u *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp8u), cudaMemcpyHostToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
DeviceToHostCopy1D(Npp8u *pDst, const Npp8u *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp8u), cudaMemcpyDeviceToHost);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class SignalAllocator<Npp16s>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
Npp16s *
|
|
||||||
Malloc1D(size_t nSize)
|
|
||||||
{
|
|
||||||
Npp16s *pResult = nppsMalloc_16s(static_cast<int>(nSize));
|
|
||||||
NPP_ASSERT(pResult != 0);
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(Npp16s *pValues)
|
|
||||||
{
|
|
||||||
nppsFree(pValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(Npp16s *pDst, const Npp16s *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16s),cudaMemcpyDeviceToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
HostToDeviceCopy1D(Npp16s *pDst, const Npp16s *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16s), cudaMemcpyHostToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
DeviceToHostCopy1D(Npp16s *pDst, const Npp16s *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16s), cudaMemcpyDeviceToHost);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class SignalAllocator<Npp16u>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
Npp16u *
|
|
||||||
Malloc1D(size_t nSize)
|
|
||||||
{
|
|
||||||
Npp16u *pResult = nppsMalloc_16u(static_cast<int>(nSize));
|
|
||||||
NPP_ASSERT(pResult != 0);
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(Npp16u *pValues)
|
|
||||||
{
|
|
||||||
nppsFree(pValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(Npp16u *pDst, const Npp16u *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16u),cudaMemcpyDeviceToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
HostToDeviceCopy1D(Npp16u *pDst, const Npp16u *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16u), cudaMemcpyHostToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
DeviceToHostCopy1D(Npp16u *pDst, const Npp16u *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16u), cudaMemcpyDeviceToHost);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class SignalAllocator<Npp16sc>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
Npp16sc *
|
|
||||||
Malloc1D(size_t nSize)
|
|
||||||
{
|
|
||||||
Npp16sc *pResult = nppsMalloc_16sc(static_cast<int>(nSize));
|
|
||||||
NPP_ASSERT(pResult != 0);
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(Npp16sc *pValues)
|
|
||||||
{
|
|
||||||
nppsFree(pValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(Npp16sc *pDst, const Npp16sc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16sc),cudaMemcpyDeviceToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
HostToDeviceCopy1D(Npp16sc *pDst, const Npp16sc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16sc), cudaMemcpyHostToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
DeviceToHostCopy1D(Npp16sc *pDst, const Npp16sc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp16sc), cudaMemcpyDeviceToHost);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class SignalAllocator<Npp32u>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
Npp32u *
|
|
||||||
Malloc1D(size_t nSize)
|
|
||||||
{
|
|
||||||
Npp32u *pResult = nppsMalloc_32u(static_cast<int>(nSize));
|
|
||||||
NPP_ASSERT(pResult != 0);
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(Npp32u *pValues)
|
|
||||||
{
|
|
||||||
nppsFree(pValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(Npp32u *pDst, const Npp32u *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32u),cudaMemcpyDeviceToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
HostToDeviceCopy1D(Npp32u *pDst, const Npp32u *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32u), cudaMemcpyHostToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
DeviceToHostCopy1D(Npp32u *pDst, const Npp32u *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32u), cudaMemcpyDeviceToHost);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class SignalAllocator<Npp32s>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
Npp32s *
|
|
||||||
Malloc1D(size_t nSize)
|
|
||||||
{
|
|
||||||
Npp32s *pResult = nppsMalloc_32s(static_cast<int>(nSize));
|
|
||||||
NPP_ASSERT(pResult != 0);
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(Npp32s *pValues)
|
|
||||||
{
|
|
||||||
nppsFree(pValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(Npp32s *pDst, const Npp32s *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32s),cudaMemcpyDeviceToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
HostToDeviceCopy1D(Npp32s *pDst, const Npp32s *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32s), cudaMemcpyHostToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
DeviceToHostCopy1D(Npp32s *pDst, const Npp32s *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32s), cudaMemcpyDeviceToHost);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class SignalAllocator<Npp32sc>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
Npp32sc *
|
|
||||||
Malloc1D(size_t nSize)
|
|
||||||
{
|
|
||||||
Npp32sc *pResult = nppsMalloc_32sc(static_cast<int>(nSize));
|
|
||||||
NPP_ASSERT(pResult != 0);
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(Npp32sc *pValues)
|
|
||||||
{
|
|
||||||
nppsFree(pValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(Npp32sc *pDst, const Npp32sc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32sc),cudaMemcpyDeviceToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
HostToDeviceCopy1D(Npp32sc *pDst, const Npp32sc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32sc), cudaMemcpyHostToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
DeviceToHostCopy1D(Npp32sc *pDst, const Npp32sc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32sc), cudaMemcpyDeviceToHost);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class SignalAllocator<Npp32f>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
Npp32f *
|
|
||||||
Malloc1D(size_t nSize)
|
|
||||||
{
|
|
||||||
Npp32f *pResult = nppsMalloc_32f(static_cast<int>(nSize));
|
|
||||||
NPP_ASSERT(pResult != 0);
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(Npp32f *pValues)
|
|
||||||
{
|
|
||||||
nppsFree(pValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(Npp32f *pDst, const Npp32f *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32f),cudaMemcpyDeviceToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
HostToDeviceCopy1D(Npp32f *pDst, const Npp32f *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32f), cudaMemcpyHostToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
DeviceToHostCopy1D(Npp32f *pDst, const Npp32f *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32f), cudaMemcpyDeviceToHost);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class SignalAllocator<Npp32fc>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
Npp32fc *
|
|
||||||
Malloc1D(size_t nSize)
|
|
||||||
{
|
|
||||||
Npp32fc *pResult = nppsMalloc_32fc(static_cast<int>(nSize));
|
|
||||||
NPP_ASSERT(pResult != 0);
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(Npp32fc *pValues)
|
|
||||||
{
|
|
||||||
nppsFree(pValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(Npp32fc *pDst, const Npp32fc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32fc),cudaMemcpyDeviceToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
HostToDeviceCopy1D(Npp32fc *pDst, const Npp32fc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32fc), cudaMemcpyHostToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
DeviceToHostCopy1D(Npp32fc *pDst, const Npp32fc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp32fc), cudaMemcpyDeviceToHost);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class SignalAllocator<Npp64s>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
Npp64s *
|
|
||||||
Malloc1D(size_t nSize)
|
|
||||||
{
|
|
||||||
Npp64s *pResult = nppsMalloc_64s(static_cast<int>(nSize));
|
|
||||||
NPP_ASSERT(pResult != 0);
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(Npp64s *pValues)
|
|
||||||
{
|
|
||||||
nppsFree(pValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(Npp64s *pDst, const Npp64s *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64s),cudaMemcpyDeviceToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
HostToDeviceCopy1D(Npp64s *pDst, const Npp64s *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64s), cudaMemcpyHostToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
DeviceToHostCopy1D(Npp64s *pDst, const Npp64s *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64s), cudaMemcpyDeviceToHost);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class SignalAllocator<Npp64sc>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
Npp64sc *
|
|
||||||
Malloc1D(size_t nSize)
|
|
||||||
{
|
|
||||||
Npp64sc *pResult = nppsMalloc_64sc(static_cast<int>(nSize));
|
|
||||||
NPP_ASSERT(pResult != 0);
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(Npp64sc *pValues)
|
|
||||||
{
|
|
||||||
nppsFree(pValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(Npp64sc *pDst, const Npp64sc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64sc),cudaMemcpyDeviceToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
HostToDeviceCopy1D(Npp64sc *pDst, const Npp64sc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64sc), cudaMemcpyHostToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
DeviceToHostCopy1D(Npp64sc *pDst, const Npp64sc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64sc), cudaMemcpyDeviceToHost);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class SignalAllocator<Npp64f>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
Npp64f *
|
|
||||||
Malloc1D(size_t nSize)
|
|
||||||
{
|
|
||||||
Npp64f *pResult = nppsMalloc_64f(static_cast<int>(nSize));
|
|
||||||
NPP_ASSERT(pResult != 0);
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(Npp64f *pValues)
|
|
||||||
{
|
|
||||||
nppsFree(pValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(Npp64f *pDst, const Npp64f *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64f),cudaMemcpyDeviceToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
HostToDeviceCopy1D(Npp64f *pDst, const Npp64f *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64f), cudaMemcpyHostToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
DeviceToHostCopy1D(Npp64f *pDst, const Npp64f *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64f), cudaMemcpyDeviceToHost);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class SignalAllocator<Npp64fc>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
Npp64fc *
|
|
||||||
Malloc1D(size_t nSize)
|
|
||||||
{
|
|
||||||
Npp64fc *pResult = nppsMalloc_64fc(static_cast<int>(nSize));
|
|
||||||
NPP_ASSERT(pResult != 0);
|
|
||||||
|
|
||||||
return pResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Free1D(Npp64fc *pValues)
|
|
||||||
{
|
|
||||||
nppsFree(pValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
Copy1D(Npp64fc *pDst, const Npp64fc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64fc),cudaMemcpyDeviceToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
HostToDeviceCopy1D(Npp64fc *pDst, const Npp64fc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64fc), cudaMemcpyHostToDevice);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
DeviceToHostCopy1D(Npp64fc *pDst, const Npp64fc *pSrc, size_t nSize)
|
|
||||||
{
|
|
||||||
cudaError_t eResult;
|
|
||||||
eResult = cudaMemcpy(pDst, pSrc, nSize * sizeof(Npp64fc), cudaMemcpyDeviceToHost);
|
|
||||||
NPP_ASSERT(cudaSuccess == eResult);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
} // npp namespace
|
|
||||||
|
|
||||||
#endif // NV_UTIL_NPP_SIGNAL_ALLOCATORS_NPP_H
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef NV_UTIL_NPP_SIGNALS_CPU_H
|
|
||||||
#define NV_UTIL_NPP_SIGNALS_CPU_H
|
|
||||||
|
|
||||||
#include "Signal.h"
|
|
||||||
|
|
||||||
#include "SignalAllocatorsCPU.h"
|
|
||||||
#include "Exceptions.h"
|
|
||||||
|
|
||||||
#include <npp.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace npp
|
|
||||||
{
|
|
||||||
|
|
||||||
template<typename D, class A>
|
|
||||||
class SignalCPU: public npp::SignalTemplate<D, A>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef typename npp::SignalTemplate<D, A>::tData tData;
|
|
||||||
|
|
||||||
SignalCPU()
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
SignalCPU(size_t nSize): SignalTemplate<D, A>(nSize)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
SignalCPU(const SignalCPU<D, A> &rSignal): SignalTemplate<D, A>(rSignal)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual
|
|
||||||
~SignalCPU()
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
SignalCPU &
|
|
||||||
operator= (const SignalCPU<D,A> &rSignal)
|
|
||||||
{
|
|
||||||
SignalTemplate<D, A>::operator= (rSignal);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
tData &
|
|
||||||
operator [](unsigned int i)
|
|
||||||
{
|
|
||||||
return *SignalTemplate<D, A>::values(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
tData
|
|
||||||
operator [](unsigned int i)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return *SignalTemplate<D, A>::values(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef SignalCPU<Npp8u, npp::SignalAllocatorCPU<Npp8u> > SignalCPU_8u;
|
|
||||||
typedef SignalCPU<Npp32s, npp::SignalAllocatorCPU<Npp32s> > SignalCPU_32s;
|
|
||||||
typedef SignalCPU<Npp16s, npp::SignalAllocatorCPU<Npp16s> > SignalCPU_16s;
|
|
||||||
typedef SignalCPU<Npp16sc, npp::SignalAllocatorCPU<Npp16sc> > SignalCPU_16sc;
|
|
||||||
typedef SignalCPU<Npp32sc, npp::SignalAllocatorCPU<Npp32sc> > SignalCPU_32sc;
|
|
||||||
typedef SignalCPU<Npp32f, npp::SignalAllocatorCPU<Npp32f> > SignalCPU_32f;
|
|
||||||
typedef SignalCPU<Npp32fc, npp::SignalAllocatorCPU<Npp32fc> > SignalCPU_32fc;
|
|
||||||
typedef SignalCPU<Npp64s, npp::SignalAllocatorCPU<Npp64s> > SignalCPU_64s;
|
|
||||||
typedef SignalCPU<Npp64sc, npp::SignalAllocatorCPU<Npp64sc> > SignalCPU_64sc;
|
|
||||||
typedef SignalCPU<Npp64f, npp::SignalAllocatorCPU<Npp64f> > SignalCPU_64f;
|
|
||||||
typedef SignalCPU<Npp64fc, npp::SignalAllocatorCPU<Npp64fc> > SignalCPU_64fc;
|
|
||||||
|
|
||||||
} // npp namespace
|
|
||||||
|
|
||||||
#endif // NV_UTIL_NPP_SIGNALS_CPU_H
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef NV_UTIL_NPP_SIGNALS_NPP_H
|
|
||||||
#define NV_UTIL_NPP_SIGNALS_NPP_H
|
|
||||||
|
|
||||||
#include "Exceptions.h"
|
|
||||||
#include "Signal.h"
|
|
||||||
|
|
||||||
#include "SignalAllocatorsNPP.h"
|
|
||||||
#include <cuda_runtime.h>
|
|
||||||
|
|
||||||
namespace npp
|
|
||||||
{
|
|
||||||
// forward declaration
|
|
||||||
template<typename D, class A> class SignalCPU;
|
|
||||||
|
|
||||||
template<typename D>
|
|
||||||
class SignalNPP: public npp::SignalTemplate<D, npp::SignalAllocator<D> >
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SignalNPP()
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit
|
|
||||||
SignalNPP(size_t nSize): SignalTemplate<D, npp::SignalAllocator<D> >(nSize)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
SignalNPP(const SignalNPP<D> &rSignal): SignalTemplate<D, npp::SignalAllocator<D> >(rSignal)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class X>
|
|
||||||
explicit
|
|
||||||
SignalNPP(const SignalCPU<D, X> &rSignal): SignalTemplate<D, npp::SignalAllocator<D> >(rSignal.size())
|
|
||||||
{
|
|
||||||
npp::SignalAllocator<D>::HostToDeviceCopy1D(SignalTemplate<D, npp::SignalAllocator<D> >::values(),
|
|
||||||
rSignal.values(), SignalTemplate<D, npp::SignalAllocator<D> >::size());
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual
|
|
||||||
~SignalNPP()
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
SignalNPP &
|
|
||||||
operator= (const SignalNPP<D> &rSignal)
|
|
||||||
{
|
|
||||||
SignalTemplate<D, npp::SignalAllocator<D> >::operator= (rSignal);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
copyTo(D *pValues)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
npp::SignalAllocator<D>::DeviceToHostCopy1D(pValues, SignalTemplate<D, npp::SignalAllocator<D> >::values(), SignalTemplate<D, npp::SignalAllocator<D> >::size());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
copyFrom(D *pValues)
|
|
||||||
{
|
|
||||||
npp::SignalAllocator<D>::HostToDeviceCopy1D(SignalTemplate<D, npp::SignalAllocator<D> >::values(), pValues, SignalTemplate<D, npp::SignalAllocator<D> >::size());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef SignalNPP<Npp8u> SignalNPP_8u;
|
|
||||||
typedef SignalNPP<Npp16s> SignalNPP_16s;
|
|
||||||
typedef SignalNPP<Npp16sc> SignalNPP_16sc;
|
|
||||||
typedef SignalNPP<Npp32s> SignalNPP_32s;
|
|
||||||
typedef SignalNPP<Npp32sc> SignalNPP_32sc;
|
|
||||||
typedef SignalNPP<Npp32f> SignalNPP_32f;
|
|
||||||
typedef SignalNPP<Npp32fc> SignalNPP_32fc;
|
|
||||||
typedef SignalNPP<Npp64s> SignalNPP_64s;
|
|
||||||
typedef SignalNPP<Npp64sc> SignalNPP_64sc;
|
|
||||||
typedef SignalNPP<Npp64f> SignalNPP_64f;
|
|
||||||
typedef SignalNPP<Npp64fc> SignalNPP_64fc;
|
|
||||||
|
|
||||||
} // npp namespace
|
|
||||||
|
|
||||||
#endif // NV_UTIL_NPP_SIGNALS_NPP_H
|
|
||||||
@@ -674,6 +674,7 @@ inline int _ConvertSMVer2Cores(int major, int minor) {
|
|||||||
{0xa0, 128},
|
{0xa0, 128},
|
||||||
{0xa1, 128},
|
{0xa1, 128},
|
||||||
{0xa3, 128},
|
{0xa3, 128},
|
||||||
|
{0xa7, 128},
|
||||||
{0xb0, 128},
|
{0xb0, 128},
|
||||||
{0xc0, 128},
|
{0xc0, 128},
|
||||||
{0xc1, 128},
|
{0xc1, 128},
|
||||||
@@ -729,6 +730,7 @@ inline const char* _ConvertSMVer2ArchName(int major, int minor) {
|
|||||||
{0xa0, "Blackwell"},
|
{0xa0, "Blackwell"},
|
||||||
{0xa1, "Blackwell"},
|
{0xa1, "Blackwell"},
|
||||||
{0xa3, "Blackwell"},
|
{0xa3, "Blackwell"},
|
||||||
|
{0xa7, "Rubin"},
|
||||||
{0xb0, "Blackwell"},
|
{0xb0, "Blackwell"},
|
||||||
{0xc0, "Blackwell"},
|
{0xc0, "Blackwell"},
|
||||||
{0xc1, "Blackwell"},
|
{0xc1, "Blackwell"},
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ inline int _ConvertSMVer2CoresDRV(int major, int minor) {
|
|||||||
{0xa0, 128},
|
{0xa0, 128},
|
||||||
{0xa1, 128},
|
{0xa1, 128},
|
||||||
{0xa3, 128},
|
{0xa3, 128},
|
||||||
|
{0xa7, 128},
|
||||||
{0xb0, 128},
|
{0xb0, 128},
|
||||||
{0xc0, 128},
|
{0xc0, 128},
|
||||||
{0xc1, 128},
|
{0xc1, 128},
|
||||||
|
|||||||
@@ -1143,10 +1143,16 @@ inline __host__ __device__ uint4 max(uint4 a, uint4 b)
|
|||||||
// - linear interpolation between a and b, based on value t in [0, 1] range
|
// - linear interpolation between a and b, based on value t in [0, 1] range
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// std::lerp (C++20) is pulled into the global namespace by GCC's <cmath>;
|
||||||
|
// only define our own scalar overload when std::lerp is unavailable, to avoid
|
||||||
|
// a redeclaration / ambiguous-overload clash. (The float2/3/4 overloads below
|
||||||
|
// take distinct argument types and never conflict.)
|
||||||
|
#if !defined(__cplusplus) || (__cplusplus < 202002L)
|
||||||
inline __device__ __host__ float lerp(float a, float b, float t)
|
inline __device__ __host__ float lerp(float a, float b, float t)
|
||||||
{
|
{
|
||||||
return a + t*(b-a);
|
return a + t*(b-a);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
inline __device__ __host__ float2 lerp(float2 a, float2 b, float t)
|
inline __device__ __host__ float2 lerp(float2 a, float2 b, float t)
|
||||||
{
|
{
|
||||||
return a + t*(b-a);
|
return a + t*(b-a);
|
||||||
|
|||||||
@@ -185,22 +185,24 @@ int ipcCreateSocket(ipcHandle *&handle, const char *name,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char path_name[50];
|
char path_name[sizeof(servaddr.sun_path)];
|
||||||
|
|
||||||
// Create unique name for the socket with path if SOCK_FOLDER is set.
|
// Create unique name for the socket with path if SOCK_FOLDER is set.
|
||||||
sprintf(path_name, "%s%u", SOCK_FOLDER, getpid());
|
int written = snprintf(path_name, sizeof(path_name), "%s/%u",
|
||||||
|
getSocketFolder().c_str(), getpid());
|
||||||
|
if (written < 0 || (size_t)written >= sizeof(path_name)) {
|
||||||
|
perror("IPC failure: Cannot bind provided name to socket. Name too large");
|
||||||
|
close(server_fd);
|
||||||
|
delete handle;
|
||||||
|
handle = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
unlink(path_name);
|
unlink(path_name);
|
||||||
memset(&servaddr, 0, sizeof(servaddr));
|
memset(&servaddr, 0, sizeof(servaddr));
|
||||||
servaddr.sun_family = AF_UNIX;
|
servaddr.sun_family = AF_UNIX;
|
||||||
|
|
||||||
size_t len = strlen(path_name);
|
strncpy(servaddr.sun_path, path_name, sizeof(servaddr.sun_path) - 1);
|
||||||
if (len > (sizeof(servaddr.sun_path) - 1)) {
|
|
||||||
perror("IPC failure: Cannot bind provided name to socket. Name too large");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strncpy(servaddr.sun_path, path_name, len);
|
|
||||||
|
|
||||||
if (bind(server_fd, (struct sockaddr *)&servaddr, SUN_LEN(&servaddr)) < 0) {
|
if (bind(server_fd, (struct sockaddr *)&servaddr, SUN_LEN(&servaddr)) < 0) {
|
||||||
perror("IPC failure: Binding socket failed");
|
perror("IPC failure: Binding socket failed");
|
||||||
@@ -227,10 +229,18 @@ int ipcOpenSocket(ipcHandle *&handle) {
|
|||||||
|
|
||||||
memset(&cliaddr, 0, sizeof(cliaddr));
|
memset(&cliaddr, 0, sizeof(cliaddr));
|
||||||
cliaddr.sun_family = AF_UNIX;
|
cliaddr.sun_family = AF_UNIX;
|
||||||
char temp[50];
|
char temp[sizeof(cliaddr.sun_path)];
|
||||||
|
|
||||||
// Create unique name for the socket with path if SOCK_FOLDER is set.
|
// Create unique name for the socket with path if SOCK_FOLDER is set.
|
||||||
sprintf(temp, "%s%u", SOCK_FOLDER, getpid());
|
int written = snprintf(temp, sizeof(temp), "%s/%u", getSocketFolder().c_str(),
|
||||||
|
getpid());
|
||||||
|
if (written < 0 || (size_t)written >= sizeof(temp)) {
|
||||||
|
perror("IPC failure: Cannot bind provided name to socket. Name too large");
|
||||||
|
close(sock);
|
||||||
|
delete handle;
|
||||||
|
handle = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
strcpy(cliaddr.sun_path, temp);
|
strcpy(cliaddr.sun_path, temp);
|
||||||
if (bind(sock, (struct sockaddr *)&cliaddr, sizeof(cliaddr)) < 0) {
|
if (bind(sock, (struct sockaddr *)&cliaddr, sizeof(cliaddr)) < 0) {
|
||||||
@@ -366,8 +376,14 @@ int ipcSendShareableHandle(ipcHandle *handle,
|
|||||||
// Construct client address to send this SHareable handle to
|
// Construct client address to send this SHareable handle to
|
||||||
memset(&cliaddr, 0, sizeof(cliaddr));
|
memset(&cliaddr, 0, sizeof(cliaddr));
|
||||||
cliaddr.sun_family = AF_UNIX;
|
cliaddr.sun_family = AF_UNIX;
|
||||||
char temp[20];
|
char temp[sizeof(cliaddr.sun_path)];
|
||||||
sprintf(temp, "%s%u", SOCK_FOLDER, process);
|
int written =
|
||||||
|
snprintf(temp, sizeof(temp), "%s/%u", getSocketFolder().c_str(), process);
|
||||||
|
if (written < 0 || (size_t)written >= sizeof(temp)) {
|
||||||
|
perror("IPC failure: Cannot address client socket. Name too large");
|
||||||
|
free(control_un.control);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
strcpy(cliaddr.sun_path, temp);
|
strcpy(cliaddr.sun_path, temp);
|
||||||
len = sizeof(cliaddr);
|
len = sizeof(cliaddr);
|
||||||
|
|
||||||
|
|||||||
@@ -54,11 +54,25 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// Define "/tmp" as socket creating folder for QNX
|
// The Unix domain sockets creating folder on QNX has been restricted to qnx6-mounted directories since QNX SDP 8.0.3.
|
||||||
#if defined(__QNX__)
|
#if defined(__QNX__)
|
||||||
#define SOCK_FOLDER "/tmp/"
|
#include <string>
|
||||||
|
inline std::string getSocketFolder() {
|
||||||
|
return "/storage";
|
||||||
|
}
|
||||||
|
// Simple filesystem compatibility for GCC 8.x
|
||||||
|
#elif defined(__GNUC__) && __GNUC__ < 9
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <string>
|
||||||
|
inline std::string getSocketFolder() {
|
||||||
|
const char* tmpdir = std::getenv("TMPDIR");
|
||||||
|
return tmpdir ? std::string(tmpdir) : "/tmp";
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#define SOCK_FOLDER ""
|
#include <filesystem>
|
||||||
|
inline std::string getSocketFolder() {
|
||||||
|
return std::filesystem::temp_directory_path().string();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct sharedMemoryInfo_st {
|
typedef struct sharedMemoryInfo_st {
|
||||||
|
|||||||
@@ -400,9 +400,9 @@ int getInputDir(std::string &input_dir, const char *executable_path) {
|
|||||||
std::string pathname = "";
|
std::string pathname = "";
|
||||||
const char *searchPath[] = {
|
const char *searchPath[] = {
|
||||||
"./images",
|
"./images",
|
||||||
"../../../../Samples/4_CUDA_Libraries/<executable_name>/images",
|
"../../../../cpp/4_CUDA_Libraries/<executable_name>/images",
|
||||||
"../../../Samples/4_CUDA_Libraries/<executable_name>/images",
|
"../../../cpp/4_CUDA_Libraries/<executable_name>/images",
|
||||||
"../../Samples/4_CUDA_Libraries/<executable_name>/images"};
|
"../../cpp/4_CUDA_Libraries/<executable_name>/images"};
|
||||||
|
|
||||||
for (unsigned int i = 0; i < sizeof(searchPath) / sizeof(char *); ++i) {
|
for (unsigned int i = 0; i < sizeof(searchPath) / sizeof(char *); ++i) {
|
||||||
std::string pathname(searchPath[i]);
|
std::string pathname(searchPath[i]);
|
||||||
|
|||||||
@@ -288,73 +288,79 @@ inline char *sdkFindFilePath(const char *filename,
|
|||||||
"./", // same dir
|
"./", // same dir
|
||||||
"./data/", // same dir
|
"./data/", // same dir
|
||||||
|
|
||||||
"../../../../Samples/<executable_name>/", // up 4 in tree
|
"../../../../cpp/<executable_name>/", // up 4 in tree
|
||||||
"../../../Samples/<executable_name>/", // up 3 in tree
|
"../../../cpp/<executable_name>/", // up 3 in tree
|
||||||
"../../Samples/<executable_name>/", // up 2 in tree
|
"../../cpp/<executable_name>/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/<executable_name>/data/", // up 4 in tree
|
"../../../../cpp/<executable_name>/data/", // up 4 in tree
|
||||||
"../../../Samples/<executable_name>/data/", // up 3 in tree
|
"../../../cpp/<executable_name>/data/", // up 3 in tree
|
||||||
"../../Samples/<executable_name>/data/", // up 2 in tree
|
"../../cpp/<executable_name>/data/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/0_Introduction/<executable_name>/", // up 4 in tree
|
"../../../../cpp/0_Introduction/<executable_name>/", // up 4 in tree
|
||||||
"../../../Samples/0_Introduction/<executable_name>/", // up 3 in tree
|
"../../../cpp/0_Introduction/<executable_name>/", // up 3 in tree
|
||||||
"../../Samples/0_Introduction/<executable_name>/", // up 2 in tree
|
"../../cpp/0_Introduction/<executable_name>/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/1_Utilities/<executable_name>/", // up 4 in tree
|
"../../../../cpp/1_Utilities/<executable_name>/", // up 4 in tree
|
||||||
"../../../Samples/1_Utilities/<executable_name>/", // up 3 in tree
|
"../../../cpp/1_Utilities/<executable_name>/", // up 3 in tree
|
||||||
"../../Samples/1_Utilities/<executable_name>/", // up 2 in tree
|
"../../cpp/1_Utilities/<executable_name>/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/2_Concepts_and_Techniques/<executable_name>/", // up 4 in tree
|
"../../../../cpp/2_Concepts_and_Techniques/<executable_name>/", // up 4 in tree
|
||||||
"../../../Samples/2_Concepts_and_Techniques/<executable_name>/", // up 3 in tree
|
"../../../cpp/2_Concepts_and_Techniques/<executable_name>/", // up 3 in tree
|
||||||
"../../Samples/2_Concepts_and_Techniques/<executable_name>/", // up 2 in tree
|
"../../cpp/2_Concepts_and_Techniques/<executable_name>/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/3_CUDA_Features/<executable_name>/", // up 4 in tree
|
"../../../../cpp/3_CUDA_Features/<executable_name>/", // up 4 in tree
|
||||||
"../../../Samples/3_CUDA_Features/<executable_name>/", // up 3 in tree
|
"../../../cpp/3_CUDA_Features/<executable_name>/", // up 3 in tree
|
||||||
"../../Samples/3_CUDA_Features/<executable_name>/", // up 2 in tree
|
"../../cpp/3_CUDA_Features/<executable_name>/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/4_CUDA_Libraries/<executable_name>/", // up 4 in tree
|
"../../../../cpp/4_CUDA_Libraries/<executable_name>/", // up 4 in tree
|
||||||
"../../../Samples/4_CUDA_Libraries/<executable_name>/", // up 3 in tree
|
"../../../cpp/4_CUDA_Libraries/<executable_name>/", // up 3 in tree
|
||||||
"../../Samples/4_CUDA_Libraries/<executable_name>/", // up 2 in tree
|
"../../cpp/4_CUDA_Libraries/<executable_name>/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/5_Domain_Specific/<executable_name>/", // up 4 in tree
|
"../../../../cpp/5_Domain_Specific/<executable_name>/", // up 4 in tree
|
||||||
"../../../Samples/5_Domain_Specific/<executable_name>/", // up 3 in tree
|
"../../../cpp/5_Domain_Specific/<executable_name>/", // up 3 in tree
|
||||||
"../../Samples/5_Domain_Specific/<executable_name>/", // up 2 in tree
|
"../../cpp/5_Domain_Specific/<executable_name>/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/6_Performance/<executable_name>/", // up 4 in tree
|
"../../../../cpp/6_Performance/<executable_name>/", // up 4 in tree
|
||||||
"../../../Samples/6_Performance/<executable_name>/", // up 3 in tree
|
"../../../cpp/6_Performance/<executable_name>/", // up 3 in tree
|
||||||
"../../Samples/6_Performance/<executable_name>/", // up 2 in tree
|
"../../cpp/6_Performance/<executable_name>/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/0_Introduction/<executable_name>/data/", // up 4 in tree
|
"../../../../cpp/0_Introduction/<executable_name>/data/", // up 4 in tree
|
||||||
"../../../Samples/0_Introduction/<executable_name>/data/", // up 3 in tree
|
"../../../cpp/0_Introduction/<executable_name>/data/", // up 3 in tree
|
||||||
"../../Samples/0_Introduction/<executable_name>/data/", // up 2 in tree
|
"../../cpp/0_Introduction/<executable_name>/data/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/1_Utilities/<executable_name>/data/", // up 4 in tree
|
"../../../../cpp/1_Utilities/<executable_name>/data/", // up 4 in tree
|
||||||
"../../../Samples/1_Utilities/<executable_name>/data/", // up 3 in tree
|
"../../../cpp/1_Utilities/<executable_name>/data/", // up 3 in tree
|
||||||
"../../Samples/1_Utilities/<executable_name>/data/", // up 2 in tree
|
"../../cpp/1_Utilities/<executable_name>/data/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/2_Concepts_and_Techniques/<executable_name>/data/", // up 4 in tree
|
"../../../../cpp/2_Concepts_and_Techniques/<executable_name>/data/", // up 4 in tree
|
||||||
"../../../Samples/2_Concepts_and_Techniques/<executable_name>/data/", // up 3 in tree
|
"../../../cpp/2_Concepts_and_Techniques/<executable_name>/data/", // up 3 in tree
|
||||||
"../../Samples/2_Concepts_and_Techniques/<executable_name>/data/", // up 2 in tree
|
"../../cpp/2_Concepts_and_Techniques/<executable_name>/data/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/3_CUDA_Features/<executable_name>/data/", // up 4 in tree
|
"../../../../cpp/3_CUDA_Features/<executable_name>/data/", // up 4 in tree
|
||||||
"../../../Samples/3_CUDA_Features/<executable_name>/data/", // up 3 in tree
|
"../../../cpp/3_CUDA_Features/<executable_name>/data/", // up 3 in tree
|
||||||
"../../Samples/3_CUDA_Features/<executable_name>/data/", // up 2 in tree
|
"../../cpp/3_CUDA_Features/<executable_name>/data/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/4_CUDA_Libraries/<executable_name>/data/", // up 4 in tree
|
"../../../../cpp/4_CUDA_Libraries/<executable_name>/data/", // up 4 in tree
|
||||||
"../../../Samples/4_CUDA_Libraries/<executable_name>/data/", // up 3 in tree
|
"../../../cpp/4_CUDA_Libraries/<executable_name>/data/", // up 3 in tree
|
||||||
"../../Samples/4_CUDA_Libraries/<executable_name>/data/", // up 2 in tree
|
"../../cpp/4_CUDA_Libraries/<executable_name>/data/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/5_Domain_Specific/<executable_name>/data/", // up 4 in tree
|
"../../../../cpp/5_Domain_Specific/<executable_name>/data/", // up 4 in tree
|
||||||
"../../../Samples/5_Domain_Specific/<executable_name>/data/", // up 3 in tree
|
"../../../cpp/5_Domain_Specific/<executable_name>/data/", // up 3 in tree
|
||||||
"../../Samples/5_Domain_Specific/<executable_name>/data/", // up 2 in tree
|
"../../cpp/5_Domain_Specific/<executable_name>/data/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Samples/6_Performance/<executable_name>/data/", // up 4 in tree
|
"../../../../cpp/6_Performance/<executable_name>/data/", // up 4 in tree
|
||||||
"../../../Samples/6_Performance/<executable_name>/data/", // up 3 in tree
|
"../../../cpp/6_Performance/<executable_name>/data/", // up 3 in tree
|
||||||
"../../Samples/6_Performance/<executable_name>/data/", // up 2 in tree
|
"../../cpp/6_Performance/<executable_name>/data/", // up 2 in tree
|
||||||
|
|
||||||
"../../../../Common/data/", // up 4 in tree
|
"../../../../Common/data/", // up 4 in tree
|
||||||
"../../../Common/data/", // up 3 in tree
|
"../../../Common/data/", // up 3 in tree
|
||||||
"../../Common/data/" // up 2 in tree
|
"../../Common/data/", // up 2 in tree
|
||||||
|
|
||||||
|
"../../../../cpp/9_CUDA_Tile/<executable_name>/", // up 4 in tree
|
||||||
|
"../../../cpp/9_CUDA_Tile/<executable_name>/", // up 3 in tree
|
||||||
|
"../../cpp/9_CUDA_Tile/<executable_name>/", // up 2 in tree
|
||||||
|
"../cpp/9_CUDA_Tile/<executable_name>/", // up 1 in tree
|
||||||
|
"./cpp/9_CUDA_Tile/<executable_name>/" // up 0 in tree
|
||||||
};
|
};
|
||||||
|
|
||||||
// Extract the executable name
|
// Extract the executable name
|
||||||
|
|||||||
233
README.md
233
README.md
@@ -1,6 +1,6 @@
|
|||||||
# CUDA Samples
|
# CUDA Samples
|
||||||
|
|
||||||
Samples for CUDA Developers which demonstrates features in CUDA Toolkit. This version supports [CUDA Toolkit 13.0](https://developer.nvidia.com/cuda-downloads).
|
Samples for CUDA Developers which demonstrates features in CUDA Toolkit. This version supports [CUDA Toolkit 13.4](https://developer.nvidia.com/cuda-downloads).
|
||||||
|
|
||||||
## Release Notes
|
## Release Notes
|
||||||
|
|
||||||
@@ -28,8 +28,6 @@ Without using git the easiest way to use these samples is to download the zip fi
|
|||||||
|
|
||||||
## Building CUDA Samples
|
## Building CUDA Samples
|
||||||
|
|
||||||
### Building CUDA Samples
|
|
||||||
|
|
||||||
The CUDA Samples are built using CMake. Follow the instructions below for building on Linux, Windows, and for cross-compilation to Tegra devices.
|
The CUDA Samples are built using CMake. Follow the instructions below for building on Linux, Windows, and for cross-compilation to Tegra devices.
|
||||||
|
|
||||||
### Linux
|
### Linux
|
||||||
@@ -51,7 +49,27 @@ Build the samples:
|
|||||||
```
|
```
|
||||||
make -j$(nproc)
|
make -j$(nproc)
|
||||||
```
|
```
|
||||||
Run the samples from their respective directories in the build folder. You can also follow this process from and subdirectory of the samples repo, or from within any individual sample.
|
|
||||||
|
By default, samples are compiled for all GPU architectures supported by this release. If you only need to target a specific GPU, you can override this to build for a single architecture and reduce build time considerably:
|
||||||
|
```
|
||||||
|
cmake -DCMAKE_CUDA_ARCHITECTURES=<arch> ..
|
||||||
|
```
|
||||||
|
Replace `<arch>` with your GPU's SM version (e.g. `90` for sm_90).
|
||||||
|
|
||||||
|
Run the samples from their respective directories in the build folder.
|
||||||
|
|
||||||
|
### Building a Single Sample
|
||||||
|
|
||||||
|
To build just one sample, configure CMake from within the sample's directory. You must explicitly specify a GPU architecture — standalone builds have no top-level default:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd cpp/<category>/<sampleName>
|
||||||
|
mkdir -p build && cd build
|
||||||
|
cmake -DCMAKE_CUDA_ARCHITECTURES=<arch> ..
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace `<arch>` with your GPU's SM version (e.g. `90` for sm_90).
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
@@ -142,8 +160,8 @@ $ cmake .. -DBUILD_TEGRA=True \
|
|||||||
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
|
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
|
||||||
-DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/toolchain-aarch64-linux.cmake \
|
-DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/toolchain-aarch64-linux.cmake \
|
||||||
-DTARGET_FS=/drive/temp \
|
-DTARGET_FS=/drive/temp \
|
||||||
-DCMAKE_LIBRARY_PATH=/drive/temp/usr/local/cuda-13.0/thor/lib64/ \
|
-DCMAKE_LIBRARY_PATH=/drive/temp/usr/local/cuda-13.1/thor/lib64/ \
|
||||||
-DCMAKE_INCLUDE_PATH=/drive/temp/usr/local/cuda-13.0/thor/include/
|
-DCMAKE_INCLUDE_PATH=/drive/temp/usr/local/cuda-13.1/thor/include/
|
||||||
```
|
```
|
||||||
|
|
||||||
Please note that the following libraries are not pre-installed in the DriveOS dev-nsr target filesystem:
|
Please note that the following libraries are not pre-installed in the DriveOS dev-nsr target filesystem:
|
||||||
@@ -159,34 +177,77 @@ $ make -j$(nproc) --ignore-errors # or --keep-going
|
|||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
# In Samples/5_Domain_Specific/CMakeList.txt
|
# In cpp/5_Domain_Specific/CMakeList.txt
|
||||||
# add_subdirectory(simpleGL)
|
# add_subdirectory(simpleGL)
|
||||||
# add_subdirectory(simpleVulkan)
|
# add_subdirectory(simpleVulkan)
|
||||||
# add_subdirectory(simpleVulkanMMAP)
|
# add_subdirectory(simpleVulkanMMAP)
|
||||||
|
|
||||||
# In Samples/8_Platform_Specific/Tegra/CMakeList.txt
|
# In cpp/8_Platform_Specific/Tegra/CMakeList.txt
|
||||||
# add_subdirectory(simpleGLES_EGLOutput)
|
# add_subdirectory(simpleGLES_EGLOutput)
|
||||||
```
|
```
|
||||||
|
|
||||||
### QNX
|
### QNX
|
||||||
|
|
||||||
Cross-compilation for QNX with CMake is supported in the CUDA 13.0 samples release and newer. An example build for
|
Cross-compilation for QNX with CMake is supported in the CUDA 13.0 samples release and newer.
|
||||||
the Tegra Thor QNX platform might look like this:
|
|
||||||
|
|
||||||
|
Set up the QNX SDP paths:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export QNX_HOST=/path/to/qnx/host
|
||||||
|
export QNX_TARGET=/path/to/qnx/target
|
||||||
```
|
```
|
||||||
$ mkdir build
|
|
||||||
$ cd build
|
|
||||||
|
|
||||||
QNX_HOST=/path/to/qnx/host \
|
Build the samples for the Tegra Thor QNX platform:
|
||||||
QNX_TARGET=/path/to/qnx/target \
|
|
||||||
|
```bash
|
||||||
|
mkdir -p build && cd build
|
||||||
cmake .. \
|
cmake .. \
|
||||||
-DBUILD_TEGRA=True \
|
-DBUILD_TEGRA=True \
|
||||||
-DCMAKE_CUDA_COMPILER=/usr/local/cuda-safe-13.0/bin/nvcc \
|
-DCMAKE_CUDA_COMPILER=/usr/local/cuda-13.3/bin/nvcc \
|
||||||
-DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/toolchain-aarch64-qnx.cmake \
|
-DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/toolchain-aarch64-qnx.cmake \
|
||||||
-DCMAKE_LIBRARY_PATH=/usr/local/cuda-safe-13.0/thor/targets/aarch64-qnx/lib/stubs/ \
|
-DTARGET_FS=/path/to/qnx/targetfs \
|
||||||
-DCMAKE_INCLUDE_PATH=/usr/local/cuda-safe-13.0/thor/targets/aarch64-qnx/include/
|
-DCMAKE_LIBRARY_PATH=/usr/local/cuda-13.3/thor/targets/aarch64-qnx/lib/stubs/ \
|
||||||
|
-DCMAKE_INCLUDE_PATH=/usr/local/cuda-13.3/thor/targets/aarch64-qnx/include/
|
||||||
|
cmake --build .
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`TARGET_FS` is the QNX target filesystem of your board. The `cudaNvSci` sample needs it, because the NvSci headers and libraries ship with the target filesystem and not with the CUDA toolkit. Without `TARGET_FS` the build reports `NvSCI not found` and skips the sample.
|
||||||
|
|
||||||
|
The target filesystem is part of the NVIDIA DRIVE OS QNX SDK, which registered users download from [NVONLINE](https://partners.nvidia.com). After the SDK is installed, the filesystem is in the DRIVE OS workspace: `<NV_WORKSPACE>/drive-qnx` for the standard SDK and `<NV_WORKSPACE>/drive-qnx-safety` for the safety SDK. See the [DRIVE OS documentation](https://docs.nvidia.com/drive/) for the installation guides.
|
||||||
|
|
||||||
|
For both QNX toolchains the build looks for `nvscibuf.h` in `<TARGET_FS>/include`, `<TARGET_FS>/../include` and `<TARGET_FS>/usr/include`, and for `libnvscibuf.so` in `<TARGET_FS>/lib-target`, `<TARGET_FS>/usr/libnvidia` and `<TARGET_FS>/usr/lib`. If your filesystem uses a different layout, set `NVSCIBUF_INCLUDE_DIR`, `NVSCISYNC_INCLUDE_DIR`, `NVSCIBUF_LIBRARY` and `NVSCISYNC_LIBRARY` on the cmake command line instead.
|
||||||
|
|
||||||
|
### QNX Safety (CUDA Safe toolkit)
|
||||||
|
|
||||||
|
Cross-compilation for **QNX Safety** uses the CUDA Safe toolkit (for example `/usr/local/cuda-13.3-safe`).
|
||||||
|
|
||||||
|
Set up the QNX SDP and Safe toolkit paths:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export QNX_HOST=/path/to/qnx/host
|
||||||
|
export QNX_TARGET=/path/to/qnx/target
|
||||||
|
export CUDA_PATH=/usr/local/cuda-13.3-safe
|
||||||
|
export PATH=$CUDA_PATH/nvvm/bin:$PATH
|
||||||
|
```
|
||||||
|
|
||||||
|
Build a single sample (standalone configure from the sample directory).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir -p build && cd build
|
||||||
|
cmake .. \
|
||||||
|
-DCMAKE_TOOLCHAIN_FILE=../../../cmake/toolchains/toolchain-aarch64-qnx-safe.cmake \
|
||||||
|
-DCMAKE_CUDA_COMPILER=$CUDA_PATH/bin/nvcc \
|
||||||
|
-DCMAKE_CUDA_ARCHITECTURES=110 \
|
||||||
|
-DTARGET_FS=/path/to/qnx/safety/targetfs
|
||||||
|
cmake --build .
|
||||||
|
```
|
||||||
|
|
||||||
|
The safe toolchain sets `-safety-compat`, links shared `libcudart` and `libcuda`, and uses QNX `q++` as the CUDA host compiler (`CMAKE_CUDA_HOST_COMPILER`). Set `CMAKE_CUDA_ARCHITECTURES` to match your GPU (`87` for Orin, `110` for Thor).
|
||||||
|
|
||||||
|
Supported QNX Safety samples: `matrixMul`, `cudaNvSci`.
|
||||||
|
|
||||||
|
`TARGET_FS` is only needed for `cudaNvSci`, which links the NvSci libraries from the safety target filesystem (`<NV_WORKSPACE>/drive-qnx-safety`, part of the DRIVE OS QNX Safety SDK). `matrixMul` builds without it. The NvSci search paths are the same as for the standard QNX build above.
|
||||||
|
|
||||||
### Forward Compatibility
|
### Forward Compatibility
|
||||||
|
|
||||||
To build samples with new CUDA Toolkit(CUDA 13.0 or later) and UMD(Version 580 or later) and old KMD(Version 550 or earlier),you need to set the `CMAKE_PREFIX_PATH` for using new driver library, the command might like this:
|
To build samples with new CUDA Toolkit(CUDA 13.0 or later) and UMD(Version 580 or later) and old KMD(Version 550 or earlier),you need to set the `CMAKE_PREFIX_PATH` for using new driver library, the command might like this:
|
||||||
@@ -195,6 +256,96 @@ To build samples with new CUDA Toolkit(CUDA 13.0 or later) and UMD(Version 580 o
|
|||||||
cmake -DCMAKE_PREFIX_PATH=/usr/local/cuda/lib64/stubs/ ..
|
cmake -DCMAKE_PREFIX_PATH=/usr/local/cuda/lib64/stubs/ ..
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## CUDA Python samples
|
||||||
|
|
||||||
|
The repository includes **Python** examples under the [`python/`](./python) directory. **These samples are cuda.core–focused:** they use [CUDA Python](https://nvidia.github.io/cuda-python/), with [`cuda.core`](https://nvidia.github.io/cuda-python/cuda-core/latest/) for devices, programs, launches, and memory, alongside NumPy, CuPy, or framework interop where each sample notes.
|
||||||
|
|
||||||
|
**Layout (same themes as the C++ samples):**
|
||||||
|
|
||||||
|
| Directory | Contents |
|
||||||
|
|-----------|----------|
|
||||||
|
| `python/1_GettingStarted/` | Introductory scripts (e.g. `vectorAdd`, `deviceQuery`, `systemInfo`, image blur with unified memory, NumPy vs CuPy). |
|
||||||
|
| `python/2_CoreConcepts/` | Algorithms and techniques (e.g. reductions, histograms, FFT, stream overlap, `memoryResources`, `cudaGraphs`, `jitLtoLinking`, `tmaTensorMap`). |
|
||||||
|
| `python/3_FrameworkInterop/` | Integration with PyTorch and TensorFlow. |
|
||||||
|
| `python/4_DistributedComputing/` | Multi-GPU, peer-to-peer, and IPC patterns (`ipcMemoryPool`). |
|
||||||
|
| `python/Utilities/` | Shared helpers imported by some samples. |
|
||||||
|
|
||||||
|
**How to run:** The top-level CMake build does **not** compile these samples. For each sample, use a Python 3.10+ environment with a matching [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) (the samples target CUDA 13.x and document exact package pins in `requirements.txt`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd python/<category>/<sampleName>
|
||||||
|
pip install -r requirements.txt
|
||||||
|
python <sampleScript>.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Use each sample’s `README.md` for prerequisites, CLI options, and expected output.
|
||||||
|
|
||||||
|
## Install Samples
|
||||||
|
|
||||||
|
### Installation Path Structure
|
||||||
|
|
||||||
|
The installation system automatically organizes samples into a structured directory layout based on:
|
||||||
|
- **Target Architecture**: ${CMAKE_SYSTEM_PROCESSOR}, e.g. `x64`, `aarch64`, `amd64`, etc.
|
||||||
|
- **Target OS**: `linux`, `windows`, `darwin`, `qnx`
|
||||||
|
- **Build Type**: `release`, `debug`, etc.
|
||||||
|
|
||||||
|
The default installation path is: `build/bin/${TARGET_ARCH}/${TARGET_OS}/${BUILD_TYPE}`
|
||||||
|
|
||||||
|
**Examples:**
|
||||||
|
- Linux x86_64 Release: `build/bin/x64/linux/release`
|
||||||
|
- Linux aarch64 Release: `build/bin/aarch64/linux/release`
|
||||||
|
- Windows amd64 Release: `build/bin/amd64/windows/release`
|
||||||
|
|
||||||
|
### Customizing Installation Paths
|
||||||
|
|
||||||
|
You can customize the installation location using CMake variables during the configuration step:
|
||||||
|
|
||||||
|
- `CMAKE_INSTALL_PREFIX`: Changes the root installation directory (default: `build/bin`)
|
||||||
|
```
|
||||||
|
cmake -DCMAKE_INSTALL_PREFIX=/custom/path ..
|
||||||
|
```
|
||||||
|
This will install to: `/custom/path/${TARGET_ARCH}/${TARGET_OS}/${BUILD_TYPE}`
|
||||||
|
|
||||||
|
- `CUDA_SAMPLES_INSTALL_DIR`: Specifies the exact final installation directory (overrides the structured path)
|
||||||
|
```
|
||||||
|
cmake -DCUDA_SAMPLES_INSTALL_DIR=/exact/install/path ..
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install Samples on Linux
|
||||||
|
|
||||||
|
**Prerequisites:** You must first configure the project with CMake as described in the [Building CUDA Samples - Linux](#linux) or [Building]section.
|
||||||
|
|
||||||
|
After configuring and building, install the samples:
|
||||||
|
|
||||||
|
```
|
||||||
|
cd build/
|
||||||
|
make install
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install Samples on Windows
|
||||||
|
|
||||||
|
**Prerequisites:** You must first configure the project with CMake as described in the [Building CUDA Samples - Windows](#windows) section.
|
||||||
|
|
||||||
|
#### Using Command Line
|
||||||
|
|
||||||
|
After configuring with CMake, build and install from the `x64 Native Tools Command Prompt for VS`:
|
||||||
|
|
||||||
|
```cmd
|
||||||
|
cd build
|
||||||
|
cmake --build . --config Release
|
||||||
|
cmake --install . --config Release
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note:** Replace `Release` with `Debug` if you want to install debug builds. For multi-configuration generators (like Visual Studio), the `--config` flag determines which build type to install.
|
||||||
|
|
||||||
|
#### Using Visual Studio IDE
|
||||||
|
|
||||||
|
Alternatively, open the generated solution file `CUDA_Samples.sln` in Visual Studio:
|
||||||
|
1. Select the desired configuration (`Release` or `Debug`)
|
||||||
|
2. Build the solution (F7 or Build > Build Solution)
|
||||||
|
3. Right-click on the `INSTALL` target under `CMakePredefinedTargets` in Solution Explorer
|
||||||
|
4. Select "Build"
|
||||||
|
|
||||||
## Running All Samples as Tests
|
## Running All Samples as Tests
|
||||||
|
|
||||||
It's important to note that the CUDA samples are _not_ intended as a validation suite for CUDA. They do not cover corner cases, they do not completely cover the
|
It's important to note that the CUDA samples are _not_ intended as a validation suite for CUDA. They do not cover corner cases, they do not completely cover the
|
||||||
@@ -206,7 +357,7 @@ the following command line arguments:
|
|||||||
|
|
||||||
| Switch | Purpose | Example |
|
| Switch | Purpose | Example |
|
||||||
| ---------- | -------------------------------------------------------------------------------------------------------------- | ----------------------- |
|
| ---------- | -------------------------------------------------------------------------------------------------------------- | ----------------------- |
|
||||||
| --dir | Specify the root directory to search for executables (recursively) | --dir ./build/Samples |
|
| --dir | Specify the root directory to search for executables (recursively) | --dir ./build/cpp |
|
||||||
| --config | JSON configuration file for executable arguments | --config test_args.json |
|
| --config | JSON configuration file for executable arguments | --config test_args.json |
|
||||||
| --output | Output directory for test results (stdout saved to .txt files - directory will be created if it doesn't exist) | --output ./test |
|
| --output | Output directory for test results (stdout saved to .txt files - directory will be created if it doesn't exist) | --output ./test |
|
||||||
| --args | Global arguments to pass to all executables (not currently used) | --args arg_1 arg_2 ... |
|
| --args | Global arguments to pass to all executables (not currently used) | --args arg_1 arg_2 ... |
|
||||||
@@ -331,7 +482,7 @@ make -j$(nproc)
|
|||||||
Now, return to the samples root directory and run the test script:
|
Now, return to the samples root directory and run the test script:
|
||||||
```bash
|
```bash
|
||||||
cd ..
|
cd ..
|
||||||
python3 run_tests.py --output ./test --dir ./build/Samples --config test_args.json
|
python3 run_tests.py --output ./test --dir ./build/cpp --config test_args.json
|
||||||
```
|
```
|
||||||
|
|
||||||
If all applications run successfully, you will see something similar to this (the specific number of samples will depend on your build type
|
If all applications run successfully, you will see something similar to this (the specific number of samples will depend on your build type
|
||||||
@@ -359,30 +510,36 @@ incorrectly on your system.
|
|||||||
|
|
||||||
## Samples list
|
## Samples list
|
||||||
|
|
||||||
### [0. Introduction](./Samples/0_Introduction/README.md)
|
### [0. Introduction](./cpp/0_Introduction/README.md)
|
||||||
Basic CUDA samples for beginners that illustrate key concepts with using CUDA and CUDA runtime APIs.
|
Basic CUDA samples for beginners that illustrate key concepts with using CUDA and CUDA runtime APIs.
|
||||||
|
|
||||||
### [1. Utilities](./Samples/1_Utilities/README.md)
|
### [1. Utilities](./cpp/1_Utilities/README.md)
|
||||||
Utility samples that demonstrate how to query device capabilities and measure GPU/CPU bandwidth.
|
Utility samples that demonstrate how to query device capabilities and measure GPU/CPU bandwidth.
|
||||||
|
|
||||||
### [2. Concepts and Techniques](./Samples/2_Concepts_and_Techniques/README.md)
|
### [2. Concepts and Techniques](./cpp/2_Concepts_and_Techniques/README.md)
|
||||||
Samples that demonstrate CUDA related concepts and common problem solving techniques.
|
Samples that demonstrate CUDA related concepts and common problem solving techniques.
|
||||||
|
|
||||||
### [3. CUDA Features](./Samples/3_CUDA_Features/README.md)
|
### [3. CUDA Features](./cpp/3_CUDA_Features/README.md)
|
||||||
Samples that demonstrate CUDA Features (Cooperative Groups, CUDA Dynamic Parallelism, CUDA Graphs etc).
|
Samples that demonstrate CUDA Features (Cooperative Groups, CUDA Dynamic Parallelism, CUDA Graphs etc).
|
||||||
|
|
||||||
### [4. CUDA Libraries](./Samples/4_CUDA_Libraries/README.md)
|
### [4. CUDA Libraries](./cpp/4_CUDA_Libraries/README.md)
|
||||||
Samples that demonstrate how to use CUDA platform libraries (NPP, NVJPEG, NVGRAPH cuBLAS, cuFFT, cuSPARSE, cuSOLVER and cuRAND).
|
Samples that demonstrate how to use CUDA platform libraries (NPP, NVJPEG, NVGRAPH cuBLAS, cuFFT, cuSPARSE, cuSOLVER and cuRAND).
|
||||||
|
|
||||||
### [5. Domain Specific](./Samples/5_Domain_Specific/README.md)
|
### [5. Domain Specific](./cpp/5_Domain_Specific/README.md)
|
||||||
Samples that are specific to domain (Graphics, Finance, Image Processing).
|
Samples that are specific to domain (Graphics, Finance, Image Processing).
|
||||||
|
|
||||||
### [6. Performance](./Samples/6_Performance/README.md)
|
### [6. Performance](./cpp/6_Performance/README.md)
|
||||||
Samples that demonstrate performance optimization.
|
Samples that demonstrate performance optimization.
|
||||||
|
|
||||||
### [7. libNVVM](./Samples/7_libNVVM/README.md)
|
### [7. libNVVM](./cpp/7_libNVVM/README.md)
|
||||||
Samples that demonstrate the use of libNVVVM and NVVM IR.
|
Samples that demonstrate the use of libNVVVM and NVVM IR.
|
||||||
|
|
||||||
|
### [8. Platform Specific](./cpp/8_Platform_Specific/Tegra/README.md)
|
||||||
|
Samples that are specific to certain platforms (Tegra, cuDLA, NvMedia, NvSci, OpenGL ES).
|
||||||
|
|
||||||
|
### [9. CUDA Tile](./cpp/9_CUDA_Tile/README.md)
|
||||||
|
Samples that demonstrate how to use CUDA Tile C++.
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
Some CUDA Samples rely on third-party applications and/or libraries, or features provided by the CUDA Toolkit and Driver, to either build or execute. These dependencies are listed below.
|
Some CUDA Samples rely on third-party applications and/or libraries, or features provided by the CUDA Toolkit and Driver, to either build or execute. These dependencies are listed below.
|
||||||
@@ -425,18 +582,27 @@ OpenGL is a graphics library used for 2D and 3D rendering. On systems which supp
|
|||||||
|
|
||||||
OpenGL ES is an embedded systems graphics library used for 2D and 3D rendering. On systems which support OpenGL ES, NVIDIA's OpenGL ES implementation is provided with the CUDA Driver.
|
OpenGL ES is an embedded systems graphics library used for 2D and 3D rendering. On systems which support OpenGL ES, NVIDIA's OpenGL ES implementation is provided with the CUDA Driver.
|
||||||
|
|
||||||
|
#### Freeglut
|
||||||
|
|
||||||
|
Freeglut is an open-source software library that serves as a replacement for the original OpenGL Utility Toolkit (GLUT). Its primary purpose is to make it easier for developers to create and manage windows containing OpenGL contexts, as well as handle input from devices like the mouse, keyboard, and joystick, across a wide range of platforms. To set up Freeglut on a Windowson on ARM system, you need to download the source from [Freeglut website](https://freeglut.sourceforge.net/), build freeglut on your system, and copy the freeglut.lib into the folder `./Common/lib/x64` and copy the freeglut.dll file into the `./bin/win64/${BUILD_TYPE}` execution folder.
|
||||||
|
|
||||||
#### Vulkan
|
#### Vulkan
|
||||||
|
|
||||||
Vulkan is a low-overhead, cross-platform 3D graphics and compute API. Vulkan targets high-performance realtime 3D graphics applications such as video games and interactive media across all platforms. On systems which support Vulkan, NVIDIA's Vulkan implementation is provided with the CUDA Driver. For building and running Vulkan applications one needs to install the [Vulkan SDK](https://www.lunarg.com/vulkan-sdk/).
|
Vulkan is a low-overhead, cross-platform 3D graphics and compute API. Vulkan targets high-performance realtime 3D graphics applications such as video games and interactive media across all platforms. On systems which support Vulkan, NVIDIA's Vulkan implementation is provided with the CUDA Driver. For building and running Vulkan applications one needs to install the [Vulkan SDK](https://www.lunarg.com/vulkan-sdk/).
|
||||||
|
|
||||||
|
#### GLEW
|
||||||
|
|
||||||
|
GLEW (OpenGL Extension Wrangler Library) is a cross-platform, open-source C/C++ library designed to simplify the process of using modern OpenGL features and extensions. Its main function is to dynamically load OpenGL function pointers at runtime, allowing developers to access both core OpenGL functions and additional features provided by hardware vendors, known as extensions. To set up GLEW on a Windows on ARM system, you need to download the source from [GLEW website](https://glew.sourceforge.net/), build GLEW on your system, and copy the glew32.lib into the folder `./Common/lib/x64` and the glew32.dll into the `./bin/win64/${BUILD_TYPE}` execution folder.
|
||||||
|
|
||||||
#### GLFW
|
#### GLFW
|
||||||
|
|
||||||
GLFW is a lightweight, open-source library designed for managing OpenGL, OpenGL ES, and Vulkan contexts. It simplifies the process of creating and managing windows, handling user input (keyboard, mouse, and joystick), and working with multiple monitors in a cross-platform manner.
|
GLFW is a lightweight, open-source library designed for managing OpenGL, OpenGL ES, and Vulkan contexts. It simplifies the process of creating and managing windows, handling user input (keyboard, mouse, and joystick), and working with multiple monitors in a cross-platform manner.
|
||||||
|
|
||||||
To set up GLFW on a Windows system, Download the pre-built binaries from [GLFW website](https://www.glfw.org/download.html) and extract the zip file into the folder, pass the GLFW include header folder as `-DGLFW_INCLUDE_DIR` and lib folder as `-DGLFW_LIB_DIR` for cmake configuring.
|
To set up GLFW on a Windows system, Download the pre-built binaries from [GLFW website](https://www.glfw.org/download.html) and extract the zip file into the folder, pass the GLFW include header folder as `-DGLFW_INCLUDE_DIR` and lib folder as `-DGLFW_LIB_DIR` for cmake configuring.
|
||||||
|
|
||||||
#### OpenMP
|
#### OpenMP
|
||||||
|
|
||||||
OpenMP is an API for multiprocessing programming. OpenMP can be installed using your Linux distribution's package manager system. It usually comes preinstalled with GCC. It can also be found at the [OpenMP website](http://openmp.org/). For compilers such as clang, `libomp.so` and other components for LLVM must be installed separated. You will also need to set additional flags in your CMake configuration files, such as: `-DOpenMP_CXX_FLAGS="-fopenmp=libomp" -DOpenMP_CXX_LIB_NAMES="omp" -DOpenMP_omp_LIBRARY="/path/to/libomp.so"`.
|
OpenMP is an API for multiprocessing programming. OpenMP can be installed using your Linux distribution's package manager system. It usually comes preinstalled with GCC. It can also be found at the [OpenMP website](http://openmp.org/). For compilers such as clang, make sure OpenMP is enabled when building LLVM by including `openmp` in `LLVM_ENABLE_PROJECTS`. If you use clang (from an installed prefix or directly from an LLVM build tree) with OpenMP enabled, set CMAKE_CXX_COMPILER and CMAKE_CUDA_HOST_COMPILER to that clang++ and let CMake detect OpenMP; extra OpenMP_* CMake variables are usually not needed. When using clang++ directly from an LLVM build tree, you may need to copy the generated `omp.h` into the `include/` directory under the path reported by `clang++ --print-resource-dir` before building the samples. When using an installed clang with OpenMP, if you see libomp.so: cannot open shared object file at runtime, add the directory that contains libomp.so to LD_LIBRARY_PATH (or configure it via ld.so.conf.d) so the dynamic linker can locate the OpenMP runtime.
|
||||||
|
|
||||||
#### Screen
|
#### Screen
|
||||||
|
|
||||||
@@ -526,6 +692,11 @@ NVJPEG library provides high-performance, GPU accelerated JPEG decoding function
|
|||||||
|
|
||||||
NVRTC (CUDA RunTime Compilation) is a runtime compilation library for CUDA C++.
|
NVRTC (CUDA RunTime Compilation) is a runtime compilation library for CUDA C++.
|
||||||
|
|
||||||
|
#### NVJITLINK
|
||||||
|
|
||||||
|
NVJITLINK is a CUDA runtime library that links multiple GPU device code objects at runtime and enables just‑in‑time link‑time optimization (JIT LTO).
|
||||||
|
It can take device code from tools such as NVCC and NVRTC, link and optimize it on the fly, and produce the final GPU binary.For more details, see: https://docs.nvidia.com/cuda/nvjitlink/index.html
|
||||||
|
|
||||||
#### Stream Priorities
|
#### Stream Priorities
|
||||||
|
|
||||||
Stream Priorities allows the creation of streams with specified priorities. Stream Priorities is only available on GPUs with SM architecture of 3.5 or above.
|
Stream Priorities allows the creation of streams with specified priorities. Stream Priorities is only available on GPUs with SM architecture of 3.5 or above.
|
||||||
@@ -558,7 +729,7 @@ Answers to frequently asked questions about CUDA can be found at http://develope
|
|||||||
|
|
||||||
## References
|
## References
|
||||||
|
|
||||||
* [CUDA Programming Guide](http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html)
|
* [CUDA Programming Guide](https://docs.nvidia.com/cuda/cuda-programming-guide/index.html)
|
||||||
* [Accelerated Computing Blog](https://developer.nvidia.com/blog/?tags=accelerated-computing)
|
* [Accelerated Computing Blog](https://developer.nvidia.com/blog/?tags=accelerated-computing)
|
||||||
|
|
||||||
## Attributions
|
## Attributions
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/UnifiedMemoryStreams"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
|
||||||
|
|
||||||
project(UnifiedMemoryStreams LANGUAGES C CXX CUDA)
|
|
||||||
|
|
||||||
find_package(CUDAToolkit REQUIRED)
|
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90 100 110 120)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
|
||||||
if(ENABLE_CUDA_DEBUG)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G") # enable cuda-gdb (may significantly affect performance on some targets)
|
|
||||||
else()
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") # add line information to all builds for debug tools (exclusive to -G option)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Include directories and libraries
|
|
||||||
include_directories(../../../Common)
|
|
||||||
|
|
||||||
# This sample is not supported on QNX
|
|
||||||
if(CMAKE_SYSTEM_NAME STREQUAL "QNX")
|
|
||||||
message(STATUS "Will not build sample ${PROJECT_NAME} - not supported on QNX")
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Source file
|
|
||||||
if(CMAKE_GENERATOR MATCHES "Visual Studio")
|
|
||||||
find_package(OpenMP REQUIRED C CXX)
|
|
||||||
else()
|
|
||||||
find_package(OpenMP REQUIRED)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(${OpenMP_FOUND})
|
|
||||||
# Add target for UnifiedMemoryStreams
|
|
||||||
add_executable(UnifiedMemoryStreams UnifiedMemoryStreams.cu)
|
|
||||||
|
|
||||||
target_compile_options(UnifiedMemoryStreams PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
|
||||||
|
|
||||||
target_compile_features(UnifiedMemoryStreams PRIVATE cxx_std_17 cuda_std_17)
|
|
||||||
|
|
||||||
set_target_properties(UnifiedMemoryStreams PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
|
||||||
|
|
||||||
target_link_libraries(UnifiedMemoryStreams PUBLIC
|
|
||||||
CUDA::cublas
|
|
||||||
OpenMP::OpenMP_CXX
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
message(STATUS "OpenMP not found - will not build sample 'UnifiedMemoryStreams'")
|
|
||||||
endif()
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/asyncAPI"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
|
||||||
|
|
||||||
project(asyncAPI LANGUAGES C CXX CUDA)
|
|
||||||
|
|
||||||
find_package(CUDAToolkit REQUIRED)
|
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90 100 110 120)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
|
||||||
if(ENABLE_CUDA_DEBUG)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G") # enable cuda-gdb (may significantly affect performance on some targets)
|
|
||||||
else()
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") # add line information to all builds for debug tools (exclusive to -G option)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Include directories and libraries
|
|
||||||
include_directories(../../../Common)
|
|
||||||
|
|
||||||
# Source file
|
|
||||||
# Add target for asyncAPI
|
|
||||||
add_executable(asyncAPI asyncAPI.cu)
|
|
||||||
|
|
||||||
target_compile_options(asyncAPI PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
|
||||||
|
|
||||||
target_compile_features(asyncAPI PRIVATE cxx_std_17 cuda_std_17)
|
|
||||||
|
|
||||||
set_target_properties(asyncAPI PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
10
Samples/0_Introduction/clock/.vscode/launch.json
vendored
10
Samples/0_Introduction/clock/.vscode/launch.json
vendored
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/clock"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
|
||||||
|
|
||||||
project(clock LANGUAGES C CXX CUDA)
|
|
||||||
|
|
||||||
find_package(CUDAToolkit REQUIRED)
|
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90 100 110 120)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
|
||||||
if(ENABLE_CUDA_DEBUG)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G") # enable cuda-gdb (may significantly affect performance on some targets)
|
|
||||||
else()
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") # add line information to all builds for debug tools (exclusive to -G option)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Include directories and libraries
|
|
||||||
include_directories(../../../Common)
|
|
||||||
|
|
||||||
# Source file
|
|
||||||
# Add target for asyncAPI
|
|
||||||
add_executable(clock clock.cu)
|
|
||||||
|
|
||||||
target_compile_options(clock PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
|
||||||
|
|
||||||
target_compile_features(clock PRIVATE cxx_std_17 cuda_std_17)
|
|
||||||
|
|
||||||
set_target_properties(clock PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
# clock - Clock
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
This example shows how to use the clock function to measure the performance of block of threads of a kernel accurately.
|
|
||||||
|
|
||||||
## Key Concepts
|
|
||||||
|
|
||||||
Performance Strategies
|
|
||||||
|
|
||||||
## Supported SM Architectures
|
|
||||||
|
|
||||||
[SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](https://developer.nvidia.com/cuda-gpus) [SM 5.3 ](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) [SM 8.7 ](https://developer.nvidia.com/cuda-gpus) [SM 8.9 ](https://developer.nvidia.com/cuda-gpus) [SM 9.0 ](https://developer.nvidia.com/cuda-gpus)
|
|
||||||
|
|
||||||
## Supported OSes
|
|
||||||
|
|
||||||
Linux, Windows
|
|
||||||
|
|
||||||
## Supported CPU Architecture
|
|
||||||
|
|
||||||
x86_64, armv7l
|
|
||||||
|
|
||||||
## CUDA APIs involved
|
|
||||||
|
|
||||||
### [CUDA Runtime API](http://docs.nvidia.com/cuda/cuda-runtime-api/index.html)
|
|
||||||
cudaMalloc, cudaMemcpy, cudaFree
|
|
||||||
|
|
||||||
## Prerequisites
|
|
||||||
|
|
||||||
Download and install the [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
|
||||||
|
|
||||||
## References (for more details)
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/clock_nvrtc"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
|
||||||
|
|
||||||
project(clock_nvrtc LANGUAGES C CXX CUDA)
|
|
||||||
|
|
||||||
find_package(CUDAToolkit REQUIRED)
|
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90 100 110 120)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
|
||||||
if(ENABLE_CUDA_DEBUG)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G") # enable cuda-gdb (may significantly affect performance on some targets)
|
|
||||||
else()
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") # add line information to all builds for debug tools (exclusive to -G option)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Include directories and libraries
|
|
||||||
include_directories(../../../Common)
|
|
||||||
|
|
||||||
# Source file
|
|
||||||
# Add sample target executable
|
|
||||||
add_executable(clock_nvrtc clock.cpp)
|
|
||||||
|
|
||||||
target_compile_options(clock_nvrtc PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
|
||||||
|
|
||||||
target_compile_features(clock_nvrtc PRIVATE cxx_std_17 cuda_std_17)
|
|
||||||
|
|
||||||
target_link_libraries(clock_nvrtc PRIVATE
|
|
||||||
CUDA::nvrtc
|
|
||||||
CUDA::cuda_driver
|
|
||||||
)
|
|
||||||
|
|
||||||
# Copy clock_kernel.cu to the output directory
|
|
||||||
add_custom_command(TARGET clock_nvrtc POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/clock_kernel.cu ${CMAKE_CURRENT_BINARY_DIR}
|
|
||||||
)
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
# clock_nvrtc - Clock libNVRTC
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
This example shows how to use the clock function using libNVRTC to measure the performance of block of threads of a kernel accurately.
|
|
||||||
|
|
||||||
## Key Concepts
|
|
||||||
|
|
||||||
Performance Strategies, Runtime Compilation
|
|
||||||
|
|
||||||
## Supported SM Architectures
|
|
||||||
|
|
||||||
[SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](https://developer.nvidia.com/cuda-gpus) [SM 5.3 ](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) [SM 8.7 ](https://developer.nvidia.com/cuda-gpus) [SM 8.9 ](https://developer.nvidia.com/cuda-gpus) [SM 9.0 ](https://developer.nvidia.com/cuda-gpus)
|
|
||||||
|
|
||||||
## Supported OSes
|
|
||||||
|
|
||||||
Linux, Windows, QNX
|
|
||||||
|
|
||||||
## Supported CPU Architecture
|
|
||||||
|
|
||||||
x86_64, aarch64
|
|
||||||
|
|
||||||
## CUDA APIs involved
|
|
||||||
|
|
||||||
### [CUDA Driver API](http://docs.nvidia.com/cuda/cuda-driver-api/index.html)
|
|
||||||
cuMemcpyDtoH, cuLaunchKernel, cuMemcpyHtoD, cuCtxSynchronize, cuMemAlloc, cuMemFree, cuModuleGetFunction
|
|
||||||
|
|
||||||
### [CUDA Runtime API](http://docs.nvidia.com/cuda/cuda-runtime-api/index.html)
|
|
||||||
cudaBlockSize, cudaGridSize
|
|
||||||
|
|
||||||
## Dependencies needed to build/run
|
|
||||||
[NVRTC](../../../README.md#nvrtc)
|
|
||||||
|
|
||||||
## Prerequisites
|
|
||||||
|
|
||||||
Download and install the [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
|
||||||
Make sure the dependencies mentioned in [Dependencies]() section above are installed.
|
|
||||||
|
|
||||||
## References (for more details)
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This example shows how to use the clock function to measure the performance
|
|
||||||
* of block of threads of a kernel accurately. Blocks are executed in parallel
|
|
||||||
* and out of order. Since there's no synchronization mechanism between blocks,
|
|
||||||
* we measure the clock once for each block. The clock samples are written to
|
|
||||||
* device memory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// System includes
|
|
||||||
#include <assert.h>
|
|
||||||
#include <cuda_runtime.h>
|
|
||||||
#include <nvrtc_helper.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
// helper functions and utilities to work with CUDA
|
|
||||||
#include <helper_functions.h>
|
|
||||||
|
|
||||||
#define NUM_BLOCKS 64
|
|
||||||
|
|
||||||
#define NUM_THREADS 256
|
|
||||||
|
|
||||||
// It's interesting to change the number of blocks and the number of threads to
|
|
||||||
// understand how to keep the hardware busy.
|
|
||||||
//
|
|
||||||
|
|
||||||
// Here are some numbers I get on my G80:
|
|
||||||
// blocks - clocks
|
|
||||||
// 1 - 3096
|
|
||||||
// 8 - 3232
|
|
||||||
// 16 - 3364
|
|
||||||
// 32 - 4615
|
|
||||||
// 64 - 9981
|
|
||||||
|
|
||||||
//
|
|
||||||
// With less than 16 blocks some of the multiprocessors of the device are idle.
|
|
||||||
// With
|
|
||||||
// more than 16 you are using all the multiprocessors, but there's only one
|
|
||||||
// block per
|
|
||||||
// multiprocessor and that doesn't allow you to hide the latency of the memory.
|
|
||||||
// With
|
|
||||||
// more than 32 the speed scales linearly.
|
|
||||||
|
|
||||||
// Start the main CUDA Sample here
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
printf("CUDA Clock sample\n");
|
|
||||||
|
|
||||||
typedef long clock_t;
|
|
||||||
|
|
||||||
clock_t timer[NUM_BLOCKS * 2];
|
|
||||||
|
|
||||||
float input[NUM_THREADS * 2];
|
|
||||||
|
|
||||||
for (int i = 0; i < NUM_THREADS * 2; i++) {
|
|
||||||
input[i] = (float)i;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *cubin, *kernel_file;
|
|
||||||
size_t cubinSize;
|
|
||||||
|
|
||||||
kernel_file = sdkFindFilePath("clock_kernel.cu", argv[0]);
|
|
||||||
compileFileToCUBIN(kernel_file, argc, argv, &cubin, &cubinSize, 0);
|
|
||||||
|
|
||||||
CUmodule module = loadCUBIN(cubin, argc, argv);
|
|
||||||
CUfunction kernel_addr;
|
|
||||||
|
|
||||||
checkCudaErrors(cuModuleGetFunction(&kernel_addr, module, "timedReduction"));
|
|
||||||
|
|
||||||
dim3 cudaBlockSize(NUM_THREADS, 1, 1);
|
|
||||||
dim3 cudaGridSize(NUM_BLOCKS, 1, 1);
|
|
||||||
|
|
||||||
CUdeviceptr dinput, doutput, dtimer;
|
|
||||||
checkCudaErrors(cuMemAlloc(&dinput, sizeof(float) * NUM_THREADS * 2));
|
|
||||||
checkCudaErrors(cuMemAlloc(&doutput, sizeof(float) * NUM_BLOCKS));
|
|
||||||
checkCudaErrors(cuMemAlloc(&dtimer, sizeof(clock_t) * NUM_BLOCKS * 2));
|
|
||||||
checkCudaErrors(cuMemcpyHtoD(dinput, input, sizeof(float) * NUM_THREADS * 2));
|
|
||||||
|
|
||||||
void *arr[] = {(void *)&dinput, (void *)&doutput, (void *)&dtimer};
|
|
||||||
|
|
||||||
checkCudaErrors(cuLaunchKernel(kernel_addr,
|
|
||||||
cudaGridSize.x,
|
|
||||||
cudaGridSize.y,
|
|
||||||
cudaGridSize.z, /* grid dim */
|
|
||||||
cudaBlockSize.x,
|
|
||||||
cudaBlockSize.y,
|
|
||||||
cudaBlockSize.z, /* block dim */
|
|
||||||
sizeof(float) * 2 * NUM_THREADS,
|
|
||||||
0, /* shared mem, stream */
|
|
||||||
&arr[0], /* arguments */
|
|
||||||
0));
|
|
||||||
|
|
||||||
checkCudaErrors(cuCtxSynchronize());
|
|
||||||
checkCudaErrors(cuMemcpyDtoH(timer, dtimer, sizeof(clock_t) * NUM_BLOCKS * 2));
|
|
||||||
checkCudaErrors(cuMemFree(dinput));
|
|
||||||
checkCudaErrors(cuMemFree(doutput));
|
|
||||||
checkCudaErrors(cuMemFree(dtimer));
|
|
||||||
|
|
||||||
long double avgElapsedClocks = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < NUM_BLOCKS; i++) {
|
|
||||||
avgElapsedClocks += (long double)(timer[i + NUM_BLOCKS] - timer[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
avgElapsedClocks = avgElapsedClocks / NUM_BLOCKS;
|
|
||||||
printf("Average clocks/block = %Lf\n", avgElapsedClocks);
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This example shows how to use the clock function to measure the performance
|
|
||||||
* of block of threads of a kernel accurately. Blocks are executed in parallel
|
|
||||||
* and out of order. Since there's no synchronization mechanism between blocks,
|
|
||||||
* we measure the clock once for each block. The clock samples are written to
|
|
||||||
* device memory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// This kernel computes a standard parallel reduction and evaluates the
|
|
||||||
// time it takes to do that for each block. The timing results are stored
|
|
||||||
// in device memory.
|
|
||||||
|
|
||||||
extern "C" __global__ void timedReduction(const float *input, float *output, clock_t *timer)
|
|
||||||
{
|
|
||||||
// __shared__ float shared[2 * blockDim.x];
|
|
||||||
extern __shared__ float shared[];
|
|
||||||
|
|
||||||
const int tid = threadIdx.x;
|
|
||||||
const int bid = blockIdx.x;
|
|
||||||
|
|
||||||
if (tid == 0)
|
|
||||||
timer[bid] = clock();
|
|
||||||
|
|
||||||
// Copy input.
|
|
||||||
shared[tid] = input[tid];
|
|
||||||
shared[tid + blockDim.x] = input[tid + blockDim.x];
|
|
||||||
|
|
||||||
// Perform reduction to find minimum.
|
|
||||||
for (int d = blockDim.x; d > 0; d /= 2) {
|
|
||||||
__syncthreads();
|
|
||||||
|
|
||||||
if (tid < d) {
|
|
||||||
float f0 = shared[tid];
|
|
||||||
float f1 = shared[tid + d];
|
|
||||||
|
|
||||||
if (f1 < f0) {
|
|
||||||
shared[tid] = f1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write result.
|
|
||||||
if (tid == 0)
|
|
||||||
output[bid] = shared[0];
|
|
||||||
|
|
||||||
__syncthreads();
|
|
||||||
|
|
||||||
if (tid == 0)
|
|
||||||
timer[bid + gridDim.x] = clock();
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/cudaOpenMP"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
|
||||||
|
|
||||||
project(cudaOpenMP LANGUAGES C CXX CUDA)
|
|
||||||
|
|
||||||
find_package(CUDAToolkit REQUIRED)
|
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90 100 110 120)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
|
||||||
if(ENABLE_CUDA_DEBUG)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G") # enable cuda-gdb (may significantly affect performance on some targets)
|
|
||||||
else()
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") # add line information to all builds for debug tools (exclusive to -G option)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Include directories and libraries
|
|
||||||
include_directories(../../../Common)
|
|
||||||
|
|
||||||
find_package(OpenMP)
|
|
||||||
|
|
||||||
# Source file
|
|
||||||
if(OpenMP_CXX_FOUND)
|
|
||||||
# Add target for asyncAPI
|
|
||||||
add_executable(cudaOpenMP cudaOpenMP.cu)
|
|
||||||
|
|
||||||
target_compile_options(cudaOpenMP PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
|
||||||
|
|
||||||
target_compile_features(cudaOpenMP PRIVATE cxx_std_17 cuda_std_17)
|
|
||||||
|
|
||||||
set_target_properties(cudaOpenMP PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
|
||||||
target_link_libraries(cudaOpenMP PUBLIC
|
|
||||||
OpenMP::OpenMP_CXX
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
message(STATUS "OpenMP not found - will not build sample 'cudaOpenMP'")
|
|
||||||
endif()
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/fp16ScalarProduct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/matrixMul"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
|
||||||
|
|
||||||
project(matrixMul LANGUAGES C CXX CUDA)
|
|
||||||
|
|
||||||
find_package(CUDAToolkit REQUIRED)
|
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90 100 110 120)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
|
||||||
if(ENABLE_CUDA_DEBUG)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G") # enable cuda-gdb (may significantly affect performance on some targets)
|
|
||||||
else()
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") # add line information to all builds for debug tools (exclusive to -G option)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Include directories and libraries
|
|
||||||
include_directories(../../../Common)
|
|
||||||
|
|
||||||
# Source file
|
|
||||||
# Add target for asyncAPI
|
|
||||||
add_executable(matrixMul matrixMul.cu)
|
|
||||||
|
|
||||||
target_compile_options(matrixMul PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
|
||||||
|
|
||||||
target_compile_features(matrixMul PRIVATE cxx_std_17 cuda_std_17)
|
|
||||||
|
|
||||||
set_target_properties(matrixMul PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/matrixMulDrv"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/matrixMulDynlinkJIT"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/matrixMul_nvrtc"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
|
||||||
|
|
||||||
project(matrixMul_nvrtc LANGUAGES C CXX CUDA)
|
|
||||||
|
|
||||||
find_package(CUDAToolkit REQUIRED)
|
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90 100 110 120)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
|
||||||
if(ENABLE_CUDA_DEBUG)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G") # enable cuda-gdb (may significantly affect performance on some targets)
|
|
||||||
else()
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") # add line information to all builds for debug tools (exclusive to -G option)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Include directories and libraries
|
|
||||||
include_directories(../../../Common)
|
|
||||||
|
|
||||||
# Source file
|
|
||||||
# Add sample target executable
|
|
||||||
add_executable(matrixMul_nvrtc matrixMul.cpp)
|
|
||||||
|
|
||||||
target_compile_options(matrixMul_nvrtc PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
|
||||||
|
|
||||||
target_compile_features(matrixMul_nvrtc PRIVATE cxx_std_17 cuda_std_17)
|
|
||||||
|
|
||||||
target_link_libraries(matrixMul_nvrtc PRIVATE
|
|
||||||
CUDA::nvrtc
|
|
||||||
CUDA::cuda_driver
|
|
||||||
)
|
|
||||||
|
|
||||||
# The primary directory of CUDAToolkit_INCLUDE_DIRS is the CUDA Toolkit's include directory for finding the header files.
|
|
||||||
list(GET CUDAToolkit_INCLUDE_DIRS 0 CUDA_INCLUDE_DIR)
|
|
||||||
|
|
||||||
# Copy clock_kernel.cu to the output directory
|
|
||||||
add_custom_command(TARGET matrixMul_nvrtc POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/matrixMul_kernel.cu ${CUDA_INCLUDE_DIR}/cooperative_groups.h ${CMAKE_CURRENT_BINARY_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_custom_command(TARGET matrixMul_nvrtc POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
||||||
${CUDA_INCLUDE_DIR}/cooperative_groups ${CMAKE_CURRENT_BINARY_DIR}/cooperative_groups
|
|
||||||
)
|
|
||||||
|
|
||||||
add_custom_command(TARGET matrixMul_nvrtc POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
||||||
${CUDA_INCLUDE_DIR}/cccl/nv ${CMAKE_CURRENT_BINARY_DIR}/nv
|
|
||||||
)
|
|
||||||
|
|
||||||
add_custom_command(TARGET matrixMul_nvrtc POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
||||||
${CUDA_INCLUDE_DIR}/cccl/cuda ${CMAKE_CURRENT_BINARY_DIR}/cuda
|
|
||||||
)
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
# matrixMul_nvrtc - Matrix Multiplication with libNVRTC
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
This sample implements matrix multiplication and is exactly the same as the second example of the [Shared Memory](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#shared-memory) section of the programming guide. It has been written for clarity of exposition to illustrate various CUDA programming principles, not with the goal of providing the most performant generic kernel for matrix multiplication. To illustrate GPU performance for matrix multiply, this sample also shows how to use the CUDA 4.0+ interface for cuBLAS to demonstrate high-performance performance for matrix multiplication.
|
|
||||||
|
|
||||||
## Key Concepts
|
|
||||||
|
|
||||||
CUDA Runtime API, Linear Algebra, Runtime Compilation
|
|
||||||
|
|
||||||
## Supported SM Architectures
|
|
||||||
|
|
||||||
[SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](https://developer.nvidia.com/cuda-gpus) [SM 5.3 ](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) [SM 8.7 ](https://developer.nvidia.com/cuda-gpus) [SM 8.9 ](https://developer.nvidia.com/cuda-gpus) [SM 9.0 ](https://developer.nvidia.com/cuda-gpus)
|
|
||||||
|
|
||||||
## Supported OSes
|
|
||||||
|
|
||||||
Linux, Windows, QNX
|
|
||||||
|
|
||||||
## Supported CPU Architecture
|
|
||||||
|
|
||||||
x86_64, aarch64
|
|
||||||
|
|
||||||
## CUDA APIs involved
|
|
||||||
|
|
||||||
### [CUDA Driver API](http://docs.nvidia.com/cuda/cuda-driver-api/index.html)
|
|
||||||
cuMemcpyDtoH, cuLaunchKernel, cuMemcpyHtoD, cuCtxSynchronize, cuMemAlloc, cuMemFree, cuModuleGetFunction
|
|
||||||
|
|
||||||
## Dependencies needed to build/run
|
|
||||||
[NVRTC](../../../README.md#nvrtc)
|
|
||||||
|
|
||||||
## Prerequisites
|
|
||||||
|
|
||||||
Download and install the [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
|
||||||
Make sure the dependencies mentioned in [Dependencies]() section above are installed.
|
|
||||||
|
|
||||||
## References (for more details)
|
|
||||||
@@ -1,249 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Matrix multiplication: C = A * B.
|
|
||||||
* Host code.
|
|
||||||
*
|
|
||||||
* This sample implements matrix multiplication as described in Chapter 3
|
|
||||||
* of the programming guide.
|
|
||||||
* It has been written for clarity of exposition to illustrate various CUDA
|
|
||||||
* programming principles, not with the goal of providing the most
|
|
||||||
* performant generic kernel for matrix multiplication.
|
|
||||||
*
|
|
||||||
* See also:
|
|
||||||
* V. Volkov and J. Demmel, "Benchmarking GPUs to tune dense linear algebra,"
|
|
||||||
* in Proc. 2008 ACM/IEEE Conf. on Supercomputing (SC '08),
|
|
||||||
* Piscataway, NJ: IEEE Press, 2008, pp. Art. 31:1-11.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// System includes
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
// CUDA runtime
|
|
||||||
#include <cuda_runtime.h>
|
|
||||||
|
|
||||||
#include "nvrtc_helper.h"
|
|
||||||
|
|
||||||
// Helper functions and utilities to work with CUDA
|
|
||||||
#include <helper_functions.h>
|
|
||||||
|
|
||||||
void constantInit(float *data, int size, float val)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < size; ++i) {
|
|
||||||
data[i] = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run a simple test of matrix multiplication using CUDA
|
|
||||||
*/
|
|
||||||
int matrixMultiply(int argc, char **argv, int block_size, dim3 &dimsA, dim3 &dimsB)
|
|
||||||
{
|
|
||||||
// Allocate host memory for matrices A and B
|
|
||||||
unsigned int size_A = dimsA.x * dimsA.y;
|
|
||||||
unsigned int mem_size_A = sizeof(float) * size_A;
|
|
||||||
float *h_A = (float *)malloc(mem_size_A);
|
|
||||||
unsigned int size_B = dimsB.x * dimsB.y;
|
|
||||||
unsigned int mem_size_B = sizeof(float) * size_B;
|
|
||||||
float *h_B = (float *)malloc(mem_size_B);
|
|
||||||
|
|
||||||
// Initialize host memory
|
|
||||||
const float valB = 0.01f;
|
|
||||||
constantInit(h_A, size_A, 1.0f);
|
|
||||||
constantInit(h_B, size_B, valB);
|
|
||||||
|
|
||||||
// Allocate device memory
|
|
||||||
CUdeviceptr d_A, d_B, d_C;
|
|
||||||
|
|
||||||
char *cubin, *kernel_file;
|
|
||||||
size_t cubinSize;
|
|
||||||
|
|
||||||
kernel_file = sdkFindFilePath("matrixMul_kernel.cu", argv[0]);
|
|
||||||
compileFileToCUBIN(kernel_file, argc, argv, &cubin, &cubinSize, 1);
|
|
||||||
|
|
||||||
CUmodule module = loadCUBIN(cubin, argc, argv);
|
|
||||||
|
|
||||||
// Allocate host matrix C
|
|
||||||
dim3 dimsC(dimsB.x, dimsA.y, 1);
|
|
||||||
unsigned int mem_size_C = dimsC.x * dimsC.y * sizeof(float);
|
|
||||||
float *h_C = (float *)malloc(mem_size_C);
|
|
||||||
|
|
||||||
if (h_C == NULL) {
|
|
||||||
fprintf(stderr, "Failed to allocate host matrix C!\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
checkCudaErrors(cuMemAlloc(&d_A, mem_size_A));
|
|
||||||
checkCudaErrors(cuMemAlloc(&d_B, mem_size_B));
|
|
||||||
checkCudaErrors(cuMemAlloc(&d_C, mem_size_C));
|
|
||||||
|
|
||||||
// copy host memory to device
|
|
||||||
checkCudaErrors(cuMemcpyHtoD(d_A, h_A, mem_size_A));
|
|
||||||
checkCudaErrors(cuMemcpyHtoD(d_B, h_B, mem_size_B));
|
|
||||||
|
|
||||||
// Setup execution parameters
|
|
||||||
dim3 threads(block_size, block_size);
|
|
||||||
dim3 grid(dimsB.x / threads.x, dimsA.y / threads.y);
|
|
||||||
|
|
||||||
// Create and start timer
|
|
||||||
printf("Computing result using CUDA Kernel...\n");
|
|
||||||
|
|
||||||
CUfunction kernel_addr;
|
|
||||||
if (block_size == 16) {
|
|
||||||
checkCudaErrors(cuModuleGetFunction(&kernel_addr, module, "matrixMulCUDA_block16"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
checkCudaErrors(cuModuleGetFunction(&kernel_addr, module, "matrixMulCUDA_block32"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void *arr[] = {(void *)&d_C, (void *)&d_A, (void *)&d_B, (void *)&dimsA.x, (void *)&dimsB.x};
|
|
||||||
|
|
||||||
// Execute the kernel
|
|
||||||
int nIter = 300;
|
|
||||||
|
|
||||||
for (int j = 0; j < nIter; j++) {
|
|
||||||
checkCudaErrors(cuLaunchKernel(kernel_addr,
|
|
||||||
grid.x,
|
|
||||||
grid.y,
|
|
||||||
grid.z, /* grid dim */
|
|
||||||
threads.x,
|
|
||||||
threads.y,
|
|
||||||
threads.z, /* block dim */
|
|
||||||
0,
|
|
||||||
0, /* shared mem, stream */
|
|
||||||
&arr[0], /* arguments */
|
|
||||||
0));
|
|
||||||
|
|
||||||
checkCudaErrors(cuCtxSynchronize());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy result from device to host
|
|
||||||
checkCudaErrors(cuMemcpyDtoH(h_C, d_C, mem_size_C));
|
|
||||||
|
|
||||||
printf("Checking computed result for correctness: ");
|
|
||||||
|
|
||||||
bool correct = true;
|
|
||||||
|
|
||||||
// test relative error by the formula
|
|
||||||
// |<x, y>_cpu - <x,y>_gpu|/<|x|, |y|> < eps
|
|
||||||
|
|
||||||
double eps = 1.e-6; // machine zero
|
|
||||||
|
|
||||||
for (int i = 0; i < (int)(dimsC.x * dimsC.y); i++) {
|
|
||||||
double abs_err = fabs(h_C[i] - (dimsA.x * valB));
|
|
||||||
double dot_length = dimsA.x;
|
|
||||||
double abs_val = fabs(h_C[i]);
|
|
||||||
double rel_err = abs_err / abs_val / dot_length;
|
|
||||||
|
|
||||||
if (rel_err > eps) {
|
|
||||||
printf("Error! Matrix[%05d]=%.8f, ref=%.8f error term is > %E\n", i, h_C[i], dimsA.x * valB, eps);
|
|
||||||
correct = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%s\n", correct ? "Result = PASS" : "Result = FAIL");
|
|
||||||
|
|
||||||
printf("\nNOTE: The CUDA Samples are not meant for performance measurements. "
|
|
||||||
"Results may vary when GPU Boost is enabled.\n");
|
|
||||||
|
|
||||||
// Clean up memory
|
|
||||||
free(h_A);
|
|
||||||
free(h_B);
|
|
||||||
free(h_C);
|
|
||||||
|
|
||||||
checkCudaErrors(cuMemFree(d_A));
|
|
||||||
checkCudaErrors(cuMemFree(d_B));
|
|
||||||
checkCudaErrors(cuMemFree(d_C));
|
|
||||||
|
|
||||||
if (correct) {
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Program main
|
|
||||||
*/
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
printf("[Matrix Multiply Using CUDA] - Starting...\n");
|
|
||||||
|
|
||||||
if (checkCmdLineFlag(argc, (const char **)argv, "help") || checkCmdLineFlag(argc, (const char **)argv, "?")) {
|
|
||||||
printf("Usage -device=n (n >= 0 for deviceID)\n");
|
|
||||||
printf(" -wA=WidthA -hA=HeightA (Width x Height of Matrix A)\n");
|
|
||||||
printf(" -wB=WidthB -hB=HeightB (Width x Height of Matrix B)\n");
|
|
||||||
printf(" Note: Outer matrix dimensions of A & B matrices must be equal.\n");
|
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
int block_size = 32;
|
|
||||||
|
|
||||||
// original:
|
|
||||||
dim3 dimsA(5 * 2 * block_size, 5 * 2 * block_size, 1);
|
|
||||||
dim3 dimsB(5 * 4 * block_size, 5 * 2 * block_size, 1);
|
|
||||||
|
|
||||||
// reduce sizes to avoid running out of memory
|
|
||||||
// dim3 dimsA(32,32, 1);
|
|
||||||
// dim3 dimsB(32,32,1);
|
|
||||||
|
|
||||||
// width of Matrix A
|
|
||||||
if (checkCmdLineFlag(argc, (const char **)argv, "wA")) {
|
|
||||||
dimsA.x = getCmdLineArgumentInt(argc, (const char **)argv, "wA");
|
|
||||||
}
|
|
||||||
|
|
||||||
// height of Matrix A
|
|
||||||
if (checkCmdLineFlag(argc, (const char **)argv, "hA")) {
|
|
||||||
dimsA.y = getCmdLineArgumentInt(argc, (const char **)argv, "hA");
|
|
||||||
}
|
|
||||||
|
|
||||||
// width of Matrix B
|
|
||||||
if (checkCmdLineFlag(argc, (const char **)argv, "wB")) {
|
|
||||||
dimsB.x = getCmdLineArgumentInt(argc, (const char **)argv, "wB");
|
|
||||||
}
|
|
||||||
|
|
||||||
// height of Matrix B
|
|
||||||
if (checkCmdLineFlag(argc, (const char **)argv, "hB")) {
|
|
||||||
dimsB.y = getCmdLineArgumentInt(argc, (const char **)argv, "hB");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dimsA.x != dimsB.y) {
|
|
||||||
printf("Error: outer matrix dimensions must be equal. (%d != %d)\n", dimsA.x, dimsB.y);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("MatrixA(%d,%d), MatrixB(%d,%d)\n", dimsA.x, dimsA.y, dimsB.x, dimsB.y);
|
|
||||||
|
|
||||||
int matrix_result = matrixMultiply(argc, argv, block_size, dimsA, dimsB);
|
|
||||||
|
|
||||||
exit(matrix_result);
|
|
||||||
}
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Matrix multiplication: C = A * B.
|
|
||||||
* Host code.
|
|
||||||
*
|
|
||||||
* This sample implements matrix multiplication as described in Chapter 3
|
|
||||||
* of the programming guide.
|
|
||||||
* It has been written for clarity of exposition to illustrate various CUDA
|
|
||||||
* programming principles, not with the goal of providing the most
|
|
||||||
* performant generic kernel for matrix multiplication.
|
|
||||||
*
|
|
||||||
* See also:
|
|
||||||
* V. Volkov and J. Demmel, "Benchmarking GPUs to tune dense linear algebra,"
|
|
||||||
* in Proc. 2008 ACM/IEEE Conf. on Supercomputing (SC '08),
|
|
||||||
* Piscataway, NJ: IEEE Press, 2008, pp. Art. 31:1-11.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Matrix multiplication (CUDA Kernel) on the device: C = A * B
|
|
||||||
* wA is A's width and wB is B's width
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <cooperative_groups.h>
|
|
||||||
|
|
||||||
template <int BLOCK_SIZE> __device__ void matrixMulCUDA(float *C, float *A, float *B, int wA, int wB)
|
|
||||||
{
|
|
||||||
// Handle to thread block group
|
|
||||||
cooperative_groups::thread_block cta = cooperative_groups::this_thread_block();
|
|
||||||
// Block index
|
|
||||||
int bx = blockIdx.x;
|
|
||||||
int by = blockIdx.y;
|
|
||||||
|
|
||||||
// Thread index
|
|
||||||
int tx = threadIdx.x;
|
|
||||||
int ty = threadIdx.y;
|
|
||||||
|
|
||||||
// Index of the first sub-matrix of A processed by the block
|
|
||||||
int aBegin = wA * BLOCK_SIZE * by;
|
|
||||||
|
|
||||||
// Index of the last sub-matrix of A processed by the block
|
|
||||||
int aEnd = aBegin + wA - 1;
|
|
||||||
|
|
||||||
// Step size used to iterate through the sub-matrices of A
|
|
||||||
int aStep = BLOCK_SIZE;
|
|
||||||
|
|
||||||
// Index of the first sub-matrix of B processed by the block
|
|
||||||
int bBegin = BLOCK_SIZE * bx;
|
|
||||||
|
|
||||||
// Step size used to iterate through the sub-matrices of B
|
|
||||||
int bStep = BLOCK_SIZE * wB;
|
|
||||||
|
|
||||||
// Csub is used to store the element of the block sub-matrix
|
|
||||||
// that is computed by the thread
|
|
||||||
float Csub = 0;
|
|
||||||
|
|
||||||
// Loop over all the sub-matrices of A and B
|
|
||||||
// required to compute the block sub-matrix
|
|
||||||
for (int a = aBegin, b = bBegin; a <= aEnd; a += aStep, b += bStep) {
|
|
||||||
// Declaration of the shared memory array As used to
|
|
||||||
// store the sub-matrix of A
|
|
||||||
__shared__ float As[BLOCK_SIZE][BLOCK_SIZE];
|
|
||||||
|
|
||||||
// Declaration of the shared memory array Bs used to
|
|
||||||
// store the sub-matrix of B
|
|
||||||
__shared__ float Bs[BLOCK_SIZE][BLOCK_SIZE];
|
|
||||||
|
|
||||||
// Load the matrices from device memory
|
|
||||||
// to shared memory; each thread loads
|
|
||||||
// one element of each matrix
|
|
||||||
As[ty][tx] = A[a + wA * ty + tx];
|
|
||||||
Bs[ty][tx] = B[b + wB * ty + tx];
|
|
||||||
|
|
||||||
// Synchronize to make sure the matrices are loaded
|
|
||||||
cooperative_groups::sync(cta);
|
|
||||||
|
|
||||||
// Multiply the two matrices together;
|
|
||||||
// each thread computes one element
|
|
||||||
// of the block sub-matrix
|
|
||||||
#pragma unroll
|
|
||||||
for (int k = 0; k < BLOCK_SIZE; ++k) {
|
|
||||||
Csub += As[ty][k] * Bs[k][tx];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Synchronize to make sure that the preceding
|
|
||||||
// computation is done before loading two new
|
|
||||||
// sub-matrices of A and B in the next iteration
|
|
||||||
cooperative_groups::sync(cta);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the block sub-matrix to device memory;
|
|
||||||
// each thread writes one element
|
|
||||||
int c = wB * BLOCK_SIZE * by + BLOCK_SIZE * bx;
|
|
||||||
C[c + wB * ty + tx] = Csub;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" __global__ void matrixMulCUDA_block16(float *C, float *A, float *B, int wA, int wB)
|
|
||||||
{
|
|
||||||
matrixMulCUDA<16>(C, A, B, wA, wB);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" __global__ void matrixMulCUDA_block32(float *C, float *A, float *B, int wA, int wB)
|
|
||||||
{
|
|
||||||
matrixMulCUDA<32>(C, A, B, wA, wB);
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/mergeSort"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
|
||||||
|
|
||||||
project(mergeSort LANGUAGES C CXX CUDA)
|
|
||||||
|
|
||||||
find_package(CUDAToolkit REQUIRED)
|
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90 100 110 120)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
|
||||||
if(ENABLE_CUDA_DEBUG)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G") # enable cuda-gdb (may significantly affect performance on some targets)
|
|
||||||
else()
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") # add line information to all builds for debug tools (exclusive to -G option)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Include directories and libraries
|
|
||||||
include_directories(../../../Common)
|
|
||||||
|
|
||||||
# Source file
|
|
||||||
# Add target for mergeSort
|
|
||||||
add_executable(mergeSort mergeSort.cu main.cpp mergeSort_host.cpp mergeSort_validate.cpp)
|
|
||||||
|
|
||||||
target_compile_options(mergeSort PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
|
||||||
|
|
||||||
target_compile_features(mergeSort PRIVATE cxx_std_17 cuda_std_17)
|
|
||||||
|
|
||||||
set_target_properties(mergeSort PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
|
||||||
target_include_directories(mergeSort PRIVATE
|
|
||||||
${CUDAToolkit_INCLUDE_DIRS}
|
|
||||||
)
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
# mergeSort - Merge Sort
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
This sample implements a merge sort (also known as Batcher's sort), algorithms belonging to the class of sorting networks. While generally subefficient on large sequences compared to algorithms with better asymptotic algorithmic complexity (i.e. merge sort or radix sort), may be the algorithms of choice for sorting batches of short- to mid-sized (key, value) array pairs. Refer to the excellent tutorial by H. W. Lang http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/networks/indexen.htm
|
|
||||||
|
|
||||||
## Key Concepts
|
|
||||||
|
|
||||||
Data-Parallel Algorithms
|
|
||||||
|
|
||||||
## Supported SM Architectures
|
|
||||||
|
|
||||||
[SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](https://developer.nvidia.com/cuda-gpus) [SM 5.3 ](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) [SM 8.7 ](https://developer.nvidia.com/cuda-gpus) [SM 8.9 ](https://developer.nvidia.com/cuda-gpus) [SM 9.0 ](https://developer.nvidia.com/cuda-gpus)
|
|
||||||
|
|
||||||
## Supported OSes
|
|
||||||
|
|
||||||
Linux, Windows
|
|
||||||
|
|
||||||
## Supported CPU Architecture
|
|
||||||
|
|
||||||
x86_64, armv7l
|
|
||||||
|
|
||||||
## CUDA APIs involved
|
|
||||||
|
|
||||||
### [CUDA Runtime API](http://docs.nvidia.com/cuda/cuda-runtime-api/index.html)
|
|
||||||
cudaMalloc, cudaDeviceSynchronize, cudaMemcpy, cudaFree
|
|
||||||
|
|
||||||
## Prerequisites
|
|
||||||
|
|
||||||
Download and install the [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
|
||||||
|
|
||||||
## References (for more details)
|
|
||||||
@@ -1,281 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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 <cooperative_groups.h>
|
|
||||||
|
|
||||||
namespace cg = cooperative_groups;
|
|
||||||
#include <assert.h>
|
|
||||||
#include <helper_cuda.h>
|
|
||||||
|
|
||||||
#include "mergeSort_common.h"
|
|
||||||
|
|
||||||
inline __device__ void Comparator(uint &keyA, uint &valA, uint &keyB, uint &valB, uint arrowDir)
|
|
||||||
{
|
|
||||||
uint t;
|
|
||||||
|
|
||||||
if ((keyA > keyB) == arrowDir) {
|
|
||||||
t = keyA;
|
|
||||||
keyA = keyB;
|
|
||||||
keyB = t;
|
|
||||||
t = valA;
|
|
||||||
valA = valB;
|
|
||||||
valB = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
__global__ void
|
|
||||||
bitonicSortSharedKernel(uint *d_DstKey, uint *d_DstVal, uint *d_SrcKey, uint *d_SrcVal, uint arrayLength, uint sortDir)
|
|
||||||
{
|
|
||||||
// Handle to thread block group
|
|
||||||
cg::thread_block cta = cg::this_thread_block();
|
|
||||||
// Shared memory storage for one or more short vectors
|
|
||||||
__shared__ uint s_key[SHARED_SIZE_LIMIT];
|
|
||||||
__shared__ uint s_val[SHARED_SIZE_LIMIT];
|
|
||||||
|
|
||||||
// Offset to the beginning of subbatch and load data
|
|
||||||
d_SrcKey += blockIdx.x * SHARED_SIZE_LIMIT + threadIdx.x;
|
|
||||||
d_SrcVal += blockIdx.x * SHARED_SIZE_LIMIT + threadIdx.x;
|
|
||||||
d_DstKey += blockIdx.x * SHARED_SIZE_LIMIT + threadIdx.x;
|
|
||||||
d_DstVal += blockIdx.x * SHARED_SIZE_LIMIT + threadIdx.x;
|
|
||||||
s_key[threadIdx.x + 0] = d_SrcKey[0];
|
|
||||||
s_val[threadIdx.x + 0] = d_SrcVal[0];
|
|
||||||
s_key[threadIdx.x + (SHARED_SIZE_LIMIT / 2)] = d_SrcKey[(SHARED_SIZE_LIMIT / 2)];
|
|
||||||
s_val[threadIdx.x + (SHARED_SIZE_LIMIT / 2)] = d_SrcVal[(SHARED_SIZE_LIMIT / 2)];
|
|
||||||
|
|
||||||
for (uint size = 2; size < arrayLength; size <<= 1) {
|
|
||||||
// Bitonic merge
|
|
||||||
uint dir = (threadIdx.x & (size / 2)) != 0;
|
|
||||||
|
|
||||||
for (uint stride = size / 2; stride > 0; stride >>= 1) {
|
|
||||||
cg::sync(cta);
|
|
||||||
uint pos = 2 * threadIdx.x - (threadIdx.x & (stride - 1));
|
|
||||||
Comparator(s_key[pos + 0], s_val[pos + 0], s_key[pos + stride], s_val[pos + stride], dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ddd == sortDir for the last bitonic merge step
|
|
||||||
{
|
|
||||||
for (uint stride = arrayLength / 2; stride > 0; stride >>= 1) {
|
|
||||||
cg::sync(cta);
|
|
||||||
uint pos = 2 * threadIdx.x - (threadIdx.x & (stride - 1));
|
|
||||||
Comparator(s_key[pos + 0], s_val[pos + 0], s_key[pos + stride], s_val[pos + stride], sortDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cg::sync(cta);
|
|
||||||
d_DstKey[0] = s_key[threadIdx.x + 0];
|
|
||||||
d_DstVal[0] = s_val[threadIdx.x + 0];
|
|
||||||
d_DstKey[(SHARED_SIZE_LIMIT / 2)] = s_key[threadIdx.x + (SHARED_SIZE_LIMIT / 2)];
|
|
||||||
d_DstVal[(SHARED_SIZE_LIMIT / 2)] = s_val[threadIdx.x + (SHARED_SIZE_LIMIT / 2)];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function (also used by odd-even merge sort)
|
|
||||||
extern "C" uint factorRadix2(uint *log2L, uint L)
|
|
||||||
{
|
|
||||||
if (!L) {
|
|
||||||
*log2L = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (*log2L = 0; (L & 1) == 0; L >>= 1, *log2L++)
|
|
||||||
;
|
|
||||||
|
|
||||||
return L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void bitonicSortShared(uint *d_DstKey,
|
|
||||||
uint *d_DstVal,
|
|
||||||
uint *d_SrcKey,
|
|
||||||
uint *d_SrcVal,
|
|
||||||
uint batchSize,
|
|
||||||
uint arrayLength,
|
|
||||||
uint sortDir)
|
|
||||||
{
|
|
||||||
// Nothing to sort
|
|
||||||
if (arrayLength < 2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only power-of-two array lengths are supported by this implementation
|
|
||||||
uint log2L;
|
|
||||||
uint factorizationRemainder = factorRadix2(&log2L, arrayLength);
|
|
||||||
assert(factorizationRemainder == 1);
|
|
||||||
|
|
||||||
uint blockCount = batchSize * arrayLength / SHARED_SIZE_LIMIT;
|
|
||||||
uint threadCount = SHARED_SIZE_LIMIT / 2;
|
|
||||||
|
|
||||||
assert(arrayLength <= SHARED_SIZE_LIMIT);
|
|
||||||
assert((batchSize * arrayLength) % SHARED_SIZE_LIMIT == 0);
|
|
||||||
|
|
||||||
bitonicSortSharedKernel<<<blockCount, threadCount>>>(d_DstKey, d_DstVal, d_SrcKey, d_SrcVal, arrayLength, sortDir);
|
|
||||||
getLastCudaError("bitonicSortSharedKernel<<<>>> failed!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Merge step 3: merge elementary intervals
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
static inline __host__ __device__ uint iDivUp(uint a, uint b) { return ((a % b) == 0) ? (a / b) : (a / b + 1); }
|
|
||||||
|
|
||||||
static inline __host__ __device__ uint getSampleCount(uint dividend) { return iDivUp(dividend, SAMPLE_STRIDE); }
|
|
||||||
|
|
||||||
template <uint sortDir>
|
|
||||||
static inline __device__ void
|
|
||||||
ComparatorExtended(uint &keyA, uint &valA, uint &flagA, uint &keyB, uint &valB, uint &flagB, uint arrowDir)
|
|
||||||
{
|
|
||||||
uint t;
|
|
||||||
|
|
||||||
if ((!(flagA || flagB) && ((keyA > keyB) == arrowDir)) || ((arrowDir == sortDir) && (flagA == 1))
|
|
||||||
|| ((arrowDir != sortDir) && (flagB == 1))) {
|
|
||||||
t = keyA;
|
|
||||||
keyA = keyB;
|
|
||||||
keyB = t;
|
|
||||||
t = valA;
|
|
||||||
valA = valB;
|
|
||||||
valB = t;
|
|
||||||
t = flagA;
|
|
||||||
flagA = flagB;
|
|
||||||
flagB = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint sortDir>
|
|
||||||
__global__ void bitonicMergeElementaryIntervalsKernel(uint *d_DstKey,
|
|
||||||
uint *d_DstVal,
|
|
||||||
uint *d_SrcKey,
|
|
||||||
uint *d_SrcVal,
|
|
||||||
uint *d_LimitsA,
|
|
||||||
uint *d_LimitsB,
|
|
||||||
uint stride,
|
|
||||||
uint N)
|
|
||||||
{
|
|
||||||
// Handle to thread block group
|
|
||||||
cg::thread_block cta = cg::this_thread_block();
|
|
||||||
__shared__ uint s_key[2 * SAMPLE_STRIDE];
|
|
||||||
__shared__ uint s_val[2 * SAMPLE_STRIDE];
|
|
||||||
__shared__ uint s_inf[2 * SAMPLE_STRIDE];
|
|
||||||
|
|
||||||
const uint intervalI = blockIdx.x & ((2 * stride) / SAMPLE_STRIDE - 1);
|
|
||||||
const uint segmentBase = (blockIdx.x - intervalI) * SAMPLE_STRIDE;
|
|
||||||
d_SrcKey += segmentBase;
|
|
||||||
d_SrcVal += segmentBase;
|
|
||||||
d_DstKey += segmentBase;
|
|
||||||
d_DstVal += segmentBase;
|
|
||||||
|
|
||||||
// Set up threadblock-wide parameters
|
|
||||||
__shared__ uint startSrcA, lenSrcA, startSrcB, lenSrcB, startDst;
|
|
||||||
|
|
||||||
if (threadIdx.x == 0) {
|
|
||||||
uint segmentElementsA = stride;
|
|
||||||
uint segmentElementsB = umin(stride, N - segmentBase - stride);
|
|
||||||
uint segmentSamplesA = stride / SAMPLE_STRIDE;
|
|
||||||
uint segmentSamplesB = getSampleCount(segmentElementsB);
|
|
||||||
uint segmentSamples = segmentSamplesA + segmentSamplesB;
|
|
||||||
|
|
||||||
startSrcA = d_LimitsA[blockIdx.x];
|
|
||||||
startSrcB = d_LimitsB[blockIdx.x];
|
|
||||||
startDst = startSrcA + startSrcB;
|
|
||||||
|
|
||||||
uint endSrcA = (intervalI + 1 < segmentSamples) ? d_LimitsA[blockIdx.x + 1] : segmentElementsA;
|
|
||||||
uint endSrcB = (intervalI + 1 < segmentSamples) ? d_LimitsB[blockIdx.x + 1] : segmentElementsB;
|
|
||||||
lenSrcA = endSrcA - startSrcA;
|
|
||||||
lenSrcB = endSrcB - startSrcB;
|
|
||||||
}
|
|
||||||
|
|
||||||
s_inf[threadIdx.x + 0] = 1;
|
|
||||||
s_inf[threadIdx.x + SAMPLE_STRIDE] = 1;
|
|
||||||
|
|
||||||
// Load input data
|
|
||||||
cg::sync(cta);
|
|
||||||
|
|
||||||
if (threadIdx.x < lenSrcA) {
|
|
||||||
s_key[threadIdx.x] = d_SrcKey[0 + startSrcA + threadIdx.x];
|
|
||||||
s_val[threadIdx.x] = d_SrcVal[0 + startSrcA + threadIdx.x];
|
|
||||||
s_inf[threadIdx.x] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare for bitonic merge by inversing the ordering
|
|
||||||
if (threadIdx.x < lenSrcB) {
|
|
||||||
s_key[2 * SAMPLE_STRIDE - 1 - threadIdx.x] = d_SrcKey[stride + startSrcB + threadIdx.x];
|
|
||||||
s_val[2 * SAMPLE_STRIDE - 1 - threadIdx.x] = d_SrcVal[stride + startSrcB + threadIdx.x];
|
|
||||||
s_inf[2 * SAMPLE_STRIDE - 1 - threadIdx.x] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//"Extended" bitonic merge
|
|
||||||
for (uint stride = SAMPLE_STRIDE; stride > 0; stride >>= 1) {
|
|
||||||
cg::sync(cta);
|
|
||||||
uint pos = 2 * threadIdx.x - (threadIdx.x & (stride - 1));
|
|
||||||
ComparatorExtended<sortDir>(s_key[pos + 0],
|
|
||||||
s_val[pos + 0],
|
|
||||||
s_inf[pos + 0],
|
|
||||||
s_key[pos + stride],
|
|
||||||
s_val[pos + stride],
|
|
||||||
s_inf[pos + stride],
|
|
||||||
sortDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store sorted data
|
|
||||||
cg::sync(cta);
|
|
||||||
d_DstKey += startDst;
|
|
||||||
d_DstVal += startDst;
|
|
||||||
|
|
||||||
if (threadIdx.x < lenSrcA) {
|
|
||||||
d_DstKey[threadIdx.x] = s_key[threadIdx.x];
|
|
||||||
d_DstVal[threadIdx.x] = s_val[threadIdx.x];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (threadIdx.x < lenSrcB) {
|
|
||||||
d_DstKey[lenSrcA + threadIdx.x] = s_key[lenSrcA + threadIdx.x];
|
|
||||||
d_DstVal[lenSrcA + threadIdx.x] = s_val[lenSrcA + threadIdx.x];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void bitonicMergeElementaryIntervals(uint *d_DstKey,
|
|
||||||
uint *d_DstVal,
|
|
||||||
uint *d_SrcKey,
|
|
||||||
uint *d_SrcVal,
|
|
||||||
uint *d_LimitsA,
|
|
||||||
uint *d_LimitsB,
|
|
||||||
uint stride,
|
|
||||||
uint N,
|
|
||||||
uint sortDir)
|
|
||||||
{
|
|
||||||
uint lastSegmentElements = N % (2 * stride);
|
|
||||||
|
|
||||||
uint mergePairs = (lastSegmentElements > stride) ? getSampleCount(N) : (N - lastSegmentElements) / SAMPLE_STRIDE;
|
|
||||||
|
|
||||||
if (sortDir) {
|
|
||||||
bitonicMergeElementaryIntervalsKernel<1U>
|
|
||||||
<<<mergePairs, SAMPLE_STRIDE>>>(d_DstKey, d_DstVal, d_SrcKey, d_SrcVal, d_LimitsA, d_LimitsB, stride, N);
|
|
||||||
getLastCudaError("mergeElementaryIntervalsKernel<1> failed\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
bitonicMergeElementaryIntervalsKernel<0U>
|
|
||||||
<<<mergePairs, SAMPLE_STRIDE>>>(d_DstKey, d_DstVal, d_SrcKey, d_SrcVal, d_LimitsA, d_LimitsB, stride, N);
|
|
||||||
getLastCudaError("mergeElementaryIntervalsKernel<0> failed\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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 <assert.h>
|
|
||||||
#include <cuda_runtime.h>
|
|
||||||
#include <helper_cuda.h>
|
|
||||||
#include <helper_functions.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "mergeSort_common.h"
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Test driver
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
uint *h_SrcKey, *h_SrcVal, *h_DstKey, *h_DstVal;
|
|
||||||
uint *d_SrcKey, *d_SrcVal, *d_BufKey, *d_BufVal, *d_DstKey, *d_DstVal;
|
|
||||||
StopWatchInterface *hTimer = NULL;
|
|
||||||
|
|
||||||
const uint N = 4 * 1048576;
|
|
||||||
const uint DIR = 1;
|
|
||||||
const uint numValues = 65536;
|
|
||||||
|
|
||||||
printf("%s Starting...\n\n", argv[0]);
|
|
||||||
|
|
||||||
int dev = findCudaDevice(argc, (const char **)argv);
|
|
||||||
|
|
||||||
if (dev == -1) {
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Allocating and initializing host arrays...\n\n");
|
|
||||||
sdkCreateTimer(&hTimer);
|
|
||||||
h_SrcKey = (uint *)malloc(N * sizeof(uint));
|
|
||||||
h_SrcVal = (uint *)malloc(N * sizeof(uint));
|
|
||||||
h_DstKey = (uint *)malloc(N * sizeof(uint));
|
|
||||||
h_DstVal = (uint *)malloc(N * sizeof(uint));
|
|
||||||
|
|
||||||
srand(2009);
|
|
||||||
|
|
||||||
for (uint i = 0; i < N; i++) {
|
|
||||||
h_SrcKey[i] = rand() % numValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
fillValues(h_SrcVal, N);
|
|
||||||
|
|
||||||
printf("Allocating and initializing CUDA arrays...\n\n");
|
|
||||||
checkCudaErrors(cudaMalloc((void **)&d_DstKey, N * sizeof(uint)));
|
|
||||||
checkCudaErrors(cudaMalloc((void **)&d_DstVal, N * sizeof(uint)));
|
|
||||||
checkCudaErrors(cudaMalloc((void **)&d_BufKey, N * sizeof(uint)));
|
|
||||||
checkCudaErrors(cudaMalloc((void **)&d_BufVal, N * sizeof(uint)));
|
|
||||||
checkCudaErrors(cudaMalloc((void **)&d_SrcKey, N * sizeof(uint)));
|
|
||||||
checkCudaErrors(cudaMalloc((void **)&d_SrcVal, N * sizeof(uint)));
|
|
||||||
checkCudaErrors(cudaMemcpy(d_SrcKey, h_SrcKey, N * sizeof(uint), cudaMemcpyHostToDevice));
|
|
||||||
checkCudaErrors(cudaMemcpy(d_SrcVal, h_SrcVal, N * sizeof(uint), cudaMemcpyHostToDevice));
|
|
||||||
|
|
||||||
printf("Initializing GPU merge sort...\n");
|
|
||||||
initMergeSort();
|
|
||||||
|
|
||||||
printf("Running GPU merge sort...\n");
|
|
||||||
checkCudaErrors(cudaDeviceSynchronize());
|
|
||||||
sdkResetTimer(&hTimer);
|
|
||||||
sdkStartTimer(&hTimer);
|
|
||||||
mergeSort(d_DstKey, d_DstVal, d_BufKey, d_BufVal, d_SrcKey, d_SrcVal, N, DIR);
|
|
||||||
checkCudaErrors(cudaDeviceSynchronize());
|
|
||||||
sdkStopTimer(&hTimer);
|
|
||||||
printf("Time: %f ms\n", sdkGetTimerValue(&hTimer));
|
|
||||||
|
|
||||||
printf("Reading back GPU merge sort results...\n");
|
|
||||||
checkCudaErrors(cudaMemcpy(h_DstKey, d_DstKey, N * sizeof(uint), cudaMemcpyDeviceToHost));
|
|
||||||
checkCudaErrors(cudaMemcpy(h_DstVal, d_DstVal, N * sizeof(uint), cudaMemcpyDeviceToHost));
|
|
||||||
|
|
||||||
printf("Inspecting the results...\n");
|
|
||||||
uint keysFlag = validateSortedKeys(h_DstKey, h_SrcKey, 1, N, numValues, DIR);
|
|
||||||
|
|
||||||
uint valuesFlag = validateSortedValues(h_DstKey, h_DstVal, h_SrcKey, 1, N);
|
|
||||||
|
|
||||||
printf("Shutting down...\n");
|
|
||||||
closeMergeSort();
|
|
||||||
sdkDeleteTimer(&hTimer);
|
|
||||||
checkCudaErrors(cudaFree(d_SrcVal));
|
|
||||||
checkCudaErrors(cudaFree(d_SrcKey));
|
|
||||||
checkCudaErrors(cudaFree(d_BufVal));
|
|
||||||
checkCudaErrors(cudaFree(d_BufKey));
|
|
||||||
checkCudaErrors(cudaFree(d_DstVal));
|
|
||||||
checkCudaErrors(cudaFree(d_DstKey));
|
|
||||||
free(h_DstVal);
|
|
||||||
free(h_DstKey);
|
|
||||||
free(h_SrcVal);
|
|
||||||
free(h_SrcKey);
|
|
||||||
|
|
||||||
exit((keysFlag && valuesFlag) ? EXIT_SUCCESS : EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
@@ -1,537 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Based on "Designing efficient sorting algorithms for manycore GPUs"
|
|
||||||
* by Nadathur Satish, Mark Harris, and Michael Garland
|
|
||||||
* http://mgarland.org/files/papers/gpusort-ipdps09.pdf
|
|
||||||
*
|
|
||||||
* Victor Podlozhnyuk 09/24/2009
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <cooperative_groups.h>
|
|
||||||
|
|
||||||
namespace cg = cooperative_groups;
|
|
||||||
|
|
||||||
#include <helper_cuda.h>
|
|
||||||
|
|
||||||
#include "mergeSort_common.h"
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Helper functions
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
static inline __host__ __device__ uint iDivUp(uint a, uint b) { return ((a % b) == 0) ? (a / b) : (a / b + 1); }
|
|
||||||
|
|
||||||
static inline __host__ __device__ uint getSampleCount(uint dividend) { return iDivUp(dividend, SAMPLE_STRIDE); }
|
|
||||||
|
|
||||||
#define W (sizeof(uint) * 8)
|
|
||||||
static inline __device__ uint nextPowerOfTwo(uint x)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
--x;
|
|
||||||
x |= x >> 1;
|
|
||||||
x |= x >> 2;
|
|
||||||
x |= x >> 4;
|
|
||||||
x |= x >> 8;
|
|
||||||
x |= x >> 16;
|
|
||||||
return ++x;
|
|
||||||
*/
|
|
||||||
return 1U << (W - __clz(x - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint sortDir> static inline __device__ uint binarySearchInclusive(uint val, uint *data, uint L, uint stride)
|
|
||||||
{
|
|
||||||
if (L == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint pos = 0;
|
|
||||||
|
|
||||||
for (; stride > 0; stride >>= 1) {
|
|
||||||
uint newPos = umin(pos + stride, L);
|
|
||||||
|
|
||||||
if ((sortDir && (data[newPos - 1] <= val)) || (!sortDir && (data[newPos - 1] >= val))) {
|
|
||||||
pos = newPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint sortDir> static inline __device__ uint binarySearchExclusive(uint val, uint *data, uint L, uint stride)
|
|
||||||
{
|
|
||||||
if (L == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint pos = 0;
|
|
||||||
|
|
||||||
for (; stride > 0; stride >>= 1) {
|
|
||||||
uint newPos = umin(pos + stride, L);
|
|
||||||
|
|
||||||
if ((sortDir && (data[newPos - 1] < val)) || (!sortDir && (data[newPos - 1] > val))) {
|
|
||||||
pos = newPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Bottom-level merge sort (binary search-based)
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
template <uint sortDir>
|
|
||||||
__global__ void mergeSortSharedKernel(uint *d_DstKey, uint *d_DstVal, uint *d_SrcKey, uint *d_SrcVal, uint arrayLength)
|
|
||||||
{
|
|
||||||
// Handle to thread block group
|
|
||||||
cg::thread_block cta = cg::this_thread_block();
|
|
||||||
__shared__ uint s_key[SHARED_SIZE_LIMIT];
|
|
||||||
__shared__ uint s_val[SHARED_SIZE_LIMIT];
|
|
||||||
|
|
||||||
d_SrcKey += blockIdx.x * SHARED_SIZE_LIMIT + threadIdx.x;
|
|
||||||
d_SrcVal += blockIdx.x * SHARED_SIZE_LIMIT + threadIdx.x;
|
|
||||||
d_DstKey += blockIdx.x * SHARED_SIZE_LIMIT + threadIdx.x;
|
|
||||||
d_DstVal += blockIdx.x * SHARED_SIZE_LIMIT + threadIdx.x;
|
|
||||||
s_key[threadIdx.x + 0] = d_SrcKey[0];
|
|
||||||
s_val[threadIdx.x + 0] = d_SrcVal[0];
|
|
||||||
s_key[threadIdx.x + (SHARED_SIZE_LIMIT / 2)] = d_SrcKey[(SHARED_SIZE_LIMIT / 2)];
|
|
||||||
s_val[threadIdx.x + (SHARED_SIZE_LIMIT / 2)] = d_SrcVal[(SHARED_SIZE_LIMIT / 2)];
|
|
||||||
|
|
||||||
for (uint stride = 1; stride < arrayLength; stride <<= 1) {
|
|
||||||
uint lPos = threadIdx.x & (stride - 1);
|
|
||||||
uint *baseKey = s_key + 2 * (threadIdx.x - lPos);
|
|
||||||
uint *baseVal = s_val + 2 * (threadIdx.x - lPos);
|
|
||||||
|
|
||||||
cg::sync(cta);
|
|
||||||
uint keyA = baseKey[lPos + 0];
|
|
||||||
uint valA = baseVal[lPos + 0];
|
|
||||||
uint keyB = baseKey[lPos + stride];
|
|
||||||
uint valB = baseVal[lPos + stride];
|
|
||||||
uint posA = binarySearchExclusive<sortDir>(keyA, baseKey + stride, stride, stride) + lPos;
|
|
||||||
uint posB = binarySearchInclusive<sortDir>(keyB, baseKey + 0, stride, stride) + lPos;
|
|
||||||
|
|
||||||
cg::sync(cta);
|
|
||||||
baseKey[posA] = keyA;
|
|
||||||
baseVal[posA] = valA;
|
|
||||||
baseKey[posB] = keyB;
|
|
||||||
baseVal[posB] = valB;
|
|
||||||
}
|
|
||||||
|
|
||||||
cg::sync(cta);
|
|
||||||
d_DstKey[0] = s_key[threadIdx.x + 0];
|
|
||||||
d_DstVal[0] = s_val[threadIdx.x + 0];
|
|
||||||
d_DstKey[(SHARED_SIZE_LIMIT / 2)] = s_key[threadIdx.x + (SHARED_SIZE_LIMIT / 2)];
|
|
||||||
d_DstVal[(SHARED_SIZE_LIMIT / 2)] = s_val[threadIdx.x + (SHARED_SIZE_LIMIT / 2)];
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mergeSortShared(uint *d_DstKey,
|
|
||||||
uint *d_DstVal,
|
|
||||||
uint *d_SrcKey,
|
|
||||||
uint *d_SrcVal,
|
|
||||||
uint batchSize,
|
|
||||||
uint arrayLength,
|
|
||||||
uint sortDir)
|
|
||||||
{
|
|
||||||
if (arrayLength < 2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(SHARED_SIZE_LIMIT % arrayLength == 0);
|
|
||||||
assert(((batchSize * arrayLength) % SHARED_SIZE_LIMIT) == 0);
|
|
||||||
uint blockCount = batchSize * arrayLength / SHARED_SIZE_LIMIT;
|
|
||||||
uint threadCount = SHARED_SIZE_LIMIT / 2;
|
|
||||||
|
|
||||||
if (sortDir) {
|
|
||||||
mergeSortSharedKernel<1U><<<blockCount, threadCount>>>(d_DstKey, d_DstVal, d_SrcKey, d_SrcVal, arrayLength);
|
|
||||||
getLastCudaError("mergeSortShared<1><<<>>> failed\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mergeSortSharedKernel<0U><<<blockCount, threadCount>>>(d_DstKey, d_DstVal, d_SrcKey, d_SrcVal, arrayLength);
|
|
||||||
getLastCudaError("mergeSortShared<0><<<>>> failed\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Merge step 1: generate sample ranks
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
template <uint sortDir>
|
|
||||||
__global__ void
|
|
||||||
generateSampleRanksKernel(uint *d_RanksA, uint *d_RanksB, uint *d_SrcKey, uint stride, uint N, uint threadCount)
|
|
||||||
{
|
|
||||||
uint pos = blockIdx.x * blockDim.x + threadIdx.x;
|
|
||||||
|
|
||||||
if (pos >= threadCount) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint i = pos & ((stride / SAMPLE_STRIDE) - 1);
|
|
||||||
const uint segmentBase = (pos - i) * (2 * SAMPLE_STRIDE);
|
|
||||||
d_SrcKey += segmentBase;
|
|
||||||
d_RanksA += segmentBase / SAMPLE_STRIDE;
|
|
||||||
d_RanksB += segmentBase / SAMPLE_STRIDE;
|
|
||||||
|
|
||||||
const uint segmentElementsA = stride;
|
|
||||||
const uint segmentElementsB = umin(stride, N - segmentBase - stride);
|
|
||||||
const uint segmentSamplesA = getSampleCount(segmentElementsA);
|
|
||||||
const uint segmentSamplesB = getSampleCount(segmentElementsB);
|
|
||||||
|
|
||||||
if (i < segmentSamplesA) {
|
|
||||||
d_RanksA[i] = i * SAMPLE_STRIDE;
|
|
||||||
d_RanksB[i] = binarySearchExclusive<sortDir>(
|
|
||||||
d_SrcKey[i * SAMPLE_STRIDE], d_SrcKey + stride, segmentElementsB, nextPowerOfTwo(segmentElementsB));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i < segmentSamplesB) {
|
|
||||||
d_RanksB[(stride / SAMPLE_STRIDE) + i] = i * SAMPLE_STRIDE;
|
|
||||||
d_RanksA[(stride / SAMPLE_STRIDE) + i] = binarySearchInclusive<sortDir>(
|
|
||||||
d_SrcKey[stride + i * SAMPLE_STRIDE], d_SrcKey + 0, segmentElementsA, nextPowerOfTwo(segmentElementsA));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void generateSampleRanks(uint *d_RanksA, uint *d_RanksB, uint *d_SrcKey, uint stride, uint N, uint sortDir)
|
|
||||||
{
|
|
||||||
uint lastSegmentElements = N % (2 * stride);
|
|
||||||
uint threadCount = (lastSegmentElements > stride) ? (N + 2 * stride - lastSegmentElements) / (2 * SAMPLE_STRIDE)
|
|
||||||
: (N - lastSegmentElements) / (2 * SAMPLE_STRIDE);
|
|
||||||
|
|
||||||
if (sortDir) {
|
|
||||||
generateSampleRanksKernel<1U>
|
|
||||||
<<<iDivUp(threadCount, 256), 256>>>(d_RanksA, d_RanksB, d_SrcKey, stride, N, threadCount);
|
|
||||||
getLastCudaError("generateSampleRanksKernel<1U><<<>>> failed\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
generateSampleRanksKernel<0U>
|
|
||||||
<<<iDivUp(threadCount, 256), 256>>>(d_RanksA, d_RanksB, d_SrcKey, stride, N, threadCount);
|
|
||||||
getLastCudaError("generateSampleRanksKernel<0U><<<>>> failed\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Merge step 2: generate sample ranks and indices
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
__global__ void mergeRanksAndIndicesKernel(uint *d_Limits, uint *d_Ranks, uint stride, uint N, uint threadCount)
|
|
||||||
{
|
|
||||||
uint pos = blockIdx.x * blockDim.x + threadIdx.x;
|
|
||||||
|
|
||||||
if (pos >= threadCount) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint i = pos & ((stride / SAMPLE_STRIDE) - 1);
|
|
||||||
const uint segmentBase = (pos - i) * (2 * SAMPLE_STRIDE);
|
|
||||||
d_Ranks += (pos - i) * 2;
|
|
||||||
d_Limits += (pos - i) * 2;
|
|
||||||
|
|
||||||
const uint segmentElementsA = stride;
|
|
||||||
const uint segmentElementsB = umin(stride, N - segmentBase - stride);
|
|
||||||
const uint segmentSamplesA = getSampleCount(segmentElementsA);
|
|
||||||
const uint segmentSamplesB = getSampleCount(segmentElementsB);
|
|
||||||
|
|
||||||
if (i < segmentSamplesA) {
|
|
||||||
uint dstPos = binarySearchExclusive<1U>(
|
|
||||||
d_Ranks[i], d_Ranks + segmentSamplesA, segmentSamplesB, nextPowerOfTwo(segmentSamplesB))
|
|
||||||
+ i;
|
|
||||||
d_Limits[dstPos] = d_Ranks[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i < segmentSamplesB) {
|
|
||||||
uint dstPos = binarySearchInclusive<1U>(
|
|
||||||
d_Ranks[segmentSamplesA + i], d_Ranks, segmentSamplesA, nextPowerOfTwo(segmentSamplesA))
|
|
||||||
+ i;
|
|
||||||
d_Limits[dstPos] = d_Ranks[segmentSamplesA + i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mergeRanksAndIndices(uint *d_LimitsA, uint *d_LimitsB, uint *d_RanksA, uint *d_RanksB, uint stride, uint N)
|
|
||||||
{
|
|
||||||
uint lastSegmentElements = N % (2 * stride);
|
|
||||||
uint threadCount = (lastSegmentElements > stride) ? (N + 2 * stride - lastSegmentElements) / (2 * SAMPLE_STRIDE)
|
|
||||||
: (N - lastSegmentElements) / (2 * SAMPLE_STRIDE);
|
|
||||||
|
|
||||||
mergeRanksAndIndicesKernel<<<iDivUp(threadCount, 256), 256>>>(d_LimitsA, d_RanksA, stride, N, threadCount);
|
|
||||||
getLastCudaError("mergeRanksAndIndicesKernel(A)<<<>>> failed\n");
|
|
||||||
|
|
||||||
mergeRanksAndIndicesKernel<<<iDivUp(threadCount, 256), 256>>>(d_LimitsB, d_RanksB, stride, N, threadCount);
|
|
||||||
getLastCudaError("mergeRanksAndIndicesKernel(B)<<<>>> failed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Merge step 3: merge elementary intervals
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
template <uint sortDir>
|
|
||||||
inline __device__ void merge(uint *dstKey,
|
|
||||||
uint *dstVal,
|
|
||||||
uint *srcAKey,
|
|
||||||
uint *srcAVal,
|
|
||||||
uint *srcBKey,
|
|
||||||
uint *srcBVal,
|
|
||||||
uint lenA,
|
|
||||||
uint nPowTwoLenA,
|
|
||||||
uint lenB,
|
|
||||||
uint nPowTwoLenB,
|
|
||||||
cg::thread_block cta)
|
|
||||||
{
|
|
||||||
uint keyA, valA, keyB, valB, dstPosA, dstPosB;
|
|
||||||
|
|
||||||
if (threadIdx.x < lenA) {
|
|
||||||
keyA = srcAKey[threadIdx.x];
|
|
||||||
valA = srcAVal[threadIdx.x];
|
|
||||||
dstPosA = binarySearchExclusive<sortDir>(keyA, srcBKey, lenB, nPowTwoLenB) + threadIdx.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (threadIdx.x < lenB) {
|
|
||||||
keyB = srcBKey[threadIdx.x];
|
|
||||||
valB = srcBVal[threadIdx.x];
|
|
||||||
dstPosB = binarySearchInclusive<sortDir>(keyB, srcAKey, lenA, nPowTwoLenA) + threadIdx.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
cg::sync(cta);
|
|
||||||
|
|
||||||
if (threadIdx.x < lenA) {
|
|
||||||
dstKey[dstPosA] = keyA;
|
|
||||||
dstVal[dstPosA] = valA;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (threadIdx.x < lenB) {
|
|
||||||
dstKey[dstPosB] = keyB;
|
|
||||||
dstVal[dstPosB] = valB;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint sortDir>
|
|
||||||
__global__ void mergeElementaryIntervalsKernel(uint *d_DstKey,
|
|
||||||
uint *d_DstVal,
|
|
||||||
uint *d_SrcKey,
|
|
||||||
uint *d_SrcVal,
|
|
||||||
uint *d_LimitsA,
|
|
||||||
uint *d_LimitsB,
|
|
||||||
uint stride,
|
|
||||||
uint N)
|
|
||||||
{
|
|
||||||
// Handle to thread block group
|
|
||||||
cg::thread_block cta = cg::this_thread_block();
|
|
||||||
__shared__ uint s_key[2 * SAMPLE_STRIDE];
|
|
||||||
__shared__ uint s_val[2 * SAMPLE_STRIDE];
|
|
||||||
|
|
||||||
const uint intervalI = blockIdx.x & ((2 * stride) / SAMPLE_STRIDE - 1);
|
|
||||||
const uint segmentBase = (blockIdx.x - intervalI) * SAMPLE_STRIDE;
|
|
||||||
d_SrcKey += segmentBase;
|
|
||||||
d_SrcVal += segmentBase;
|
|
||||||
d_DstKey += segmentBase;
|
|
||||||
d_DstVal += segmentBase;
|
|
||||||
|
|
||||||
// Set up threadblock-wide parameters
|
|
||||||
__shared__ uint startSrcA, startSrcB, lenSrcA, lenSrcB, startDstA, startDstB;
|
|
||||||
|
|
||||||
if (threadIdx.x == 0) {
|
|
||||||
uint segmentElementsA = stride;
|
|
||||||
uint segmentElementsB = umin(stride, N - segmentBase - stride);
|
|
||||||
uint segmentSamplesA = getSampleCount(segmentElementsA);
|
|
||||||
uint segmentSamplesB = getSampleCount(segmentElementsB);
|
|
||||||
uint segmentSamples = segmentSamplesA + segmentSamplesB;
|
|
||||||
|
|
||||||
startSrcA = d_LimitsA[blockIdx.x];
|
|
||||||
startSrcB = d_LimitsB[blockIdx.x];
|
|
||||||
uint endSrcA = (intervalI + 1 < segmentSamples) ? d_LimitsA[blockIdx.x + 1] : segmentElementsA;
|
|
||||||
uint endSrcB = (intervalI + 1 < segmentSamples) ? d_LimitsB[blockIdx.x + 1] : segmentElementsB;
|
|
||||||
lenSrcA = endSrcA - startSrcA;
|
|
||||||
lenSrcB = endSrcB - startSrcB;
|
|
||||||
startDstA = startSrcA + startSrcB;
|
|
||||||
startDstB = startDstA + lenSrcA;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load main input data
|
|
||||||
cg::sync(cta);
|
|
||||||
|
|
||||||
if (threadIdx.x < lenSrcA) {
|
|
||||||
s_key[threadIdx.x + 0] = d_SrcKey[0 + startSrcA + threadIdx.x];
|
|
||||||
s_val[threadIdx.x + 0] = d_SrcVal[0 + startSrcA + threadIdx.x];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (threadIdx.x < lenSrcB) {
|
|
||||||
s_key[threadIdx.x + SAMPLE_STRIDE] = d_SrcKey[stride + startSrcB + threadIdx.x];
|
|
||||||
s_val[threadIdx.x + SAMPLE_STRIDE] = d_SrcVal[stride + startSrcB + threadIdx.x];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merge data in shared memory
|
|
||||||
cg::sync(cta);
|
|
||||||
merge<sortDir>(s_key,
|
|
||||||
s_val,
|
|
||||||
s_key + 0,
|
|
||||||
s_val + 0,
|
|
||||||
s_key + SAMPLE_STRIDE,
|
|
||||||
s_val + SAMPLE_STRIDE,
|
|
||||||
lenSrcA,
|
|
||||||
SAMPLE_STRIDE,
|
|
||||||
lenSrcB,
|
|
||||||
SAMPLE_STRIDE,
|
|
||||||
cta);
|
|
||||||
|
|
||||||
// Store merged data
|
|
||||||
cg::sync(cta);
|
|
||||||
|
|
||||||
if (threadIdx.x < lenSrcA) {
|
|
||||||
d_DstKey[startDstA + threadIdx.x] = s_key[threadIdx.x];
|
|
||||||
d_DstVal[startDstA + threadIdx.x] = s_val[threadIdx.x];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (threadIdx.x < lenSrcB) {
|
|
||||||
d_DstKey[startDstB + threadIdx.x] = s_key[lenSrcA + threadIdx.x];
|
|
||||||
d_DstVal[startDstB + threadIdx.x] = s_val[lenSrcA + threadIdx.x];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mergeElementaryIntervals(uint *d_DstKey,
|
|
||||||
uint *d_DstVal,
|
|
||||||
uint *d_SrcKey,
|
|
||||||
uint *d_SrcVal,
|
|
||||||
uint *d_LimitsA,
|
|
||||||
uint *d_LimitsB,
|
|
||||||
uint stride,
|
|
||||||
uint N,
|
|
||||||
uint sortDir)
|
|
||||||
{
|
|
||||||
uint lastSegmentElements = N % (2 * stride);
|
|
||||||
uint mergePairs = (lastSegmentElements > stride) ? getSampleCount(N) : (N - lastSegmentElements) / SAMPLE_STRIDE;
|
|
||||||
|
|
||||||
if (sortDir) {
|
|
||||||
mergeElementaryIntervalsKernel<1U>
|
|
||||||
<<<mergePairs, SAMPLE_STRIDE>>>(d_DstKey, d_DstVal, d_SrcKey, d_SrcVal, d_LimitsA, d_LimitsB, stride, N);
|
|
||||||
getLastCudaError("mergeElementaryIntervalsKernel<1> failed\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mergeElementaryIntervalsKernel<0U>
|
|
||||||
<<<mergePairs, SAMPLE_STRIDE>>>(d_DstKey, d_DstVal, d_SrcKey, d_SrcVal, d_LimitsA, d_LimitsB, stride, N);
|
|
||||||
getLastCudaError("mergeElementaryIntervalsKernel<0> failed\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void bitonicSortShared(uint *d_DstKey,
|
|
||||||
uint *d_DstVal,
|
|
||||||
uint *d_SrcKey,
|
|
||||||
uint *d_SrcVal,
|
|
||||||
uint batchSize,
|
|
||||||
uint arrayLength,
|
|
||||||
uint sortDir);
|
|
||||||
|
|
||||||
extern "C" void bitonicMergeElementaryIntervals(uint *d_DstKey,
|
|
||||||
uint *d_DstVal,
|
|
||||||
uint *d_SrcKey,
|
|
||||||
uint *d_SrcVal,
|
|
||||||
uint *d_LimitsA,
|
|
||||||
uint *d_LimitsB,
|
|
||||||
uint stride,
|
|
||||||
uint N,
|
|
||||||
uint sortDir);
|
|
||||||
|
|
||||||
static uint *d_RanksA, *d_RanksB, *d_LimitsA, *d_LimitsB;
|
|
||||||
static const uint MAX_SAMPLE_COUNT = 32768;
|
|
||||||
|
|
||||||
extern "C" void initMergeSort(void)
|
|
||||||
{
|
|
||||||
checkCudaErrors(cudaMalloc((void **)&d_RanksA, MAX_SAMPLE_COUNT * sizeof(uint)));
|
|
||||||
checkCudaErrors(cudaMalloc((void **)&d_RanksB, MAX_SAMPLE_COUNT * sizeof(uint)));
|
|
||||||
checkCudaErrors(cudaMalloc((void **)&d_LimitsA, MAX_SAMPLE_COUNT * sizeof(uint)));
|
|
||||||
checkCudaErrors(cudaMalloc((void **)&d_LimitsB, MAX_SAMPLE_COUNT * sizeof(uint)));
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void closeMergeSort(void)
|
|
||||||
{
|
|
||||||
checkCudaErrors(cudaFree(d_RanksA));
|
|
||||||
checkCudaErrors(cudaFree(d_RanksB));
|
|
||||||
checkCudaErrors(cudaFree(d_LimitsB));
|
|
||||||
checkCudaErrors(cudaFree(d_LimitsA));
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void mergeSort(uint *d_DstKey,
|
|
||||||
uint *d_DstVal,
|
|
||||||
uint *d_BufKey,
|
|
||||||
uint *d_BufVal,
|
|
||||||
uint *d_SrcKey,
|
|
||||||
uint *d_SrcVal,
|
|
||||||
uint N,
|
|
||||||
uint sortDir)
|
|
||||||
{
|
|
||||||
uint stageCount = 0;
|
|
||||||
|
|
||||||
for (uint stride = SHARED_SIZE_LIMIT; stride < N; stride <<= 1, stageCount++)
|
|
||||||
;
|
|
||||||
|
|
||||||
uint *ikey, *ival, *okey, *oval;
|
|
||||||
|
|
||||||
if (stageCount & 1) {
|
|
||||||
ikey = d_BufKey;
|
|
||||||
ival = d_BufVal;
|
|
||||||
okey = d_DstKey;
|
|
||||||
oval = d_DstVal;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ikey = d_DstKey;
|
|
||||||
ival = d_DstVal;
|
|
||||||
okey = d_BufKey;
|
|
||||||
oval = d_BufVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(N <= (SAMPLE_STRIDE * MAX_SAMPLE_COUNT));
|
|
||||||
assert(N % SHARED_SIZE_LIMIT == 0);
|
|
||||||
mergeSortShared(ikey, ival, d_SrcKey, d_SrcVal, N / SHARED_SIZE_LIMIT, SHARED_SIZE_LIMIT, sortDir);
|
|
||||||
|
|
||||||
for (uint stride = SHARED_SIZE_LIMIT; stride < N; stride <<= 1) {
|
|
||||||
uint lastSegmentElements = N % (2 * stride);
|
|
||||||
|
|
||||||
// Find sample ranks and prepare for limiters merge
|
|
||||||
generateSampleRanks(d_RanksA, d_RanksB, ikey, stride, N, sortDir);
|
|
||||||
|
|
||||||
// Merge ranks and indices
|
|
||||||
mergeRanksAndIndices(d_LimitsA, d_LimitsB, d_RanksA, d_RanksB, stride, N);
|
|
||||||
|
|
||||||
// Merge elementary intervals
|
|
||||||
mergeElementaryIntervals(okey, oval, ikey, ival, d_LimitsA, d_LimitsB, stride, N, sortDir);
|
|
||||||
|
|
||||||
if (lastSegmentElements <= stride) {
|
|
||||||
// Last merge segment consists of a single array which just needs to be
|
|
||||||
// passed through
|
|
||||||
checkCudaErrors(cudaMemcpy(okey + (N - lastSegmentElements),
|
|
||||||
ikey + (N - lastSegmentElements),
|
|
||||||
lastSegmentElements * sizeof(uint),
|
|
||||||
cudaMemcpyDeviceToDevice));
|
|
||||||
checkCudaErrors(cudaMemcpy(oval + (N - lastSegmentElements),
|
|
||||||
ival + (N - lastSegmentElements),
|
|
||||||
lastSegmentElements * sizeof(uint),
|
|
||||||
cudaMemcpyDeviceToDevice));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint *t;
|
|
||||||
t = ikey;
|
|
||||||
ikey = okey;
|
|
||||||
okey = t;
|
|
||||||
t = ival;
|
|
||||||
ival = oval;
|
|
||||||
oval = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Shortcut definitions
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
typedef unsigned int uint;
|
|
||||||
|
|
||||||
#define SHARED_SIZE_LIMIT 1024U
|
|
||||||
#define SAMPLE_STRIDE 128
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Extensive sort validation routine
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
extern "C" uint
|
|
||||||
validateSortedKeys(uint *resKey, uint *srcKey, uint batchSize, uint arrayLength, uint numValues, uint sortDir);
|
|
||||||
|
|
||||||
extern "C" void fillValues(uint *val, uint N);
|
|
||||||
|
|
||||||
extern "C" int validateSortedValues(uint *resKey, uint *resVal, uint *srcKey, uint batchSize, uint arrayLength);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// CUDA merge sort
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
extern "C" void initMergeSort(void);
|
|
||||||
|
|
||||||
extern "C" void closeMergeSort(void);
|
|
||||||
|
|
||||||
extern "C" void
|
|
||||||
mergeSort(uint *dstKey, uint *dstVal, uint *bufKey, uint *bufVal, uint *srcKey, uint *srcVal, uint N, uint sortDir);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// CPU "emulation"
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
extern "C" void
|
|
||||||
mergeSortHost(uint *dstKey, uint *dstVal, uint *bufKey, uint *bufVal, uint *srcKey, uint *srcVal, uint N, uint sortDir);
|
|
||||||
@@ -1,363 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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 <assert.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "mergeSort_common.h"
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Helper functions
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
static void checkOrder(uint *data, uint N, uint sortDir)
|
|
||||||
{
|
|
||||||
if (N <= 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint i = 0; i < N - 1; i++)
|
|
||||||
if ((sortDir && (data[i] > data[i + 1])) || (!sortDir && (data[i] < data[i + 1]))) {
|
|
||||||
fprintf(stderr, "checkOrder() failed!!!\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint umin(uint a, uint b) { return (a <= b) ? a : b; }
|
|
||||||
|
|
||||||
static uint getSampleCount(uint dividend)
|
|
||||||
{
|
|
||||||
return ((dividend % SAMPLE_STRIDE) != 0) ? (dividend / SAMPLE_STRIDE + 1) : (dividend / SAMPLE_STRIDE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint nextPowerOfTwo(uint x)
|
|
||||||
{
|
|
||||||
--x;
|
|
||||||
x |= x >> 1;
|
|
||||||
x |= x >> 2;
|
|
||||||
x |= x >> 4;
|
|
||||||
x |= x >> 8;
|
|
||||||
x |= x >> 16;
|
|
||||||
return ++x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint binarySearchInclusive(uint val, uint *data, uint L, uint sortDir)
|
|
||||||
{
|
|
||||||
if (L == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint pos = 0;
|
|
||||||
|
|
||||||
for (uint stride = nextPowerOfTwo(L); stride > 0; stride >>= 1) {
|
|
||||||
uint newPos = umin(pos + stride, L);
|
|
||||||
|
|
||||||
if ((sortDir && (data[newPos - 1] <= val)) || (!sortDir && (data[newPos - 1] >= val))) {
|
|
||||||
pos = newPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint binarySearchExclusive(uint val, uint *data, uint L, uint sortDir)
|
|
||||||
{
|
|
||||||
if (L == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint pos = 0;
|
|
||||||
|
|
||||||
for (uint stride = nextPowerOfTwo(L); stride > 0; stride >>= 1) {
|
|
||||||
uint newPos = umin(pos + stride, L);
|
|
||||||
|
|
||||||
if ((sortDir && (data[newPos - 1] < val)) || (!sortDir && (data[newPos - 1] > val))) {
|
|
||||||
pos = newPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Merge step 1: find sample ranks in each segment
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
static void generateSampleRanks(uint *ranksA, uint *ranksB, uint *srcKey, uint stride, uint N, uint sortDir)
|
|
||||||
{
|
|
||||||
uint lastSegmentElements = N % (2 * stride);
|
|
||||||
uint sampleCount = (lastSegmentElements > stride) ? (N + 2 * stride - lastSegmentElements) / (2 * SAMPLE_STRIDE)
|
|
||||||
: (N - lastSegmentElements) / (2 * SAMPLE_STRIDE);
|
|
||||||
|
|
||||||
for (uint pos = 0; pos < sampleCount; pos++) {
|
|
||||||
const uint i = pos & ((stride / SAMPLE_STRIDE) - 1);
|
|
||||||
const uint segmentBase = (pos - i) * (2 * SAMPLE_STRIDE);
|
|
||||||
|
|
||||||
const uint lenA = stride;
|
|
||||||
const uint lenB = umin(stride, N - segmentBase - stride);
|
|
||||||
const uint nA = stride / SAMPLE_STRIDE;
|
|
||||||
const uint nB = getSampleCount(lenB);
|
|
||||||
|
|
||||||
if (i < nA) {
|
|
||||||
ranksA[(segmentBase + 0) / SAMPLE_STRIDE + i] = i * SAMPLE_STRIDE;
|
|
||||||
ranksB[(segmentBase + 0) / SAMPLE_STRIDE + i] = binarySearchExclusive(
|
|
||||||
srcKey[segmentBase + i * SAMPLE_STRIDE], srcKey + segmentBase + stride, lenB, sortDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i < nB) {
|
|
||||||
ranksB[(segmentBase + stride) / SAMPLE_STRIDE + i] = i * SAMPLE_STRIDE;
|
|
||||||
ranksA[(segmentBase + stride) / SAMPLE_STRIDE + i] = binarySearchInclusive(
|
|
||||||
srcKey[segmentBase + stride + i * SAMPLE_STRIDE], srcKey + segmentBase, lenA, sortDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Merge step 2: merge ranks and indices to derive elementary intervals
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
static void mergeRanksAndIndices(uint *limits, uint *ranks, uint stride, uint N)
|
|
||||||
{
|
|
||||||
uint lastSegmentElements = N % (2 * stride);
|
|
||||||
uint sampleCount = (lastSegmentElements > stride) ? (N + 2 * stride - lastSegmentElements) / (2 * SAMPLE_STRIDE)
|
|
||||||
: (N - lastSegmentElements) / (2 * SAMPLE_STRIDE);
|
|
||||||
|
|
||||||
for (uint pos = 0; pos < sampleCount; pos++) {
|
|
||||||
const uint i = pos & ((stride / SAMPLE_STRIDE) - 1);
|
|
||||||
const uint segmentBase = (pos - i) * (2 * SAMPLE_STRIDE);
|
|
||||||
|
|
||||||
const uint lenA = stride;
|
|
||||||
const uint lenB = umin(stride, N - segmentBase - stride);
|
|
||||||
const uint nA = stride / SAMPLE_STRIDE;
|
|
||||||
const uint nB = getSampleCount(lenB);
|
|
||||||
|
|
||||||
if (i < nA) {
|
|
||||||
uint dstPosA =
|
|
||||||
binarySearchExclusive(
|
|
||||||
ranks[(segmentBase + 0) / SAMPLE_STRIDE + i], ranks + (segmentBase + stride) / SAMPLE_STRIDE, nB, 1)
|
|
||||||
+ i;
|
|
||||||
assert(dstPosA < nA + nB);
|
|
||||||
limits[(segmentBase / SAMPLE_STRIDE) + dstPosA] = ranks[(segmentBase + 0) / SAMPLE_STRIDE + i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i < nB) {
|
|
||||||
uint dstPosA =
|
|
||||||
binarySearchInclusive(
|
|
||||||
ranks[(segmentBase + stride) / SAMPLE_STRIDE + i], ranks + (segmentBase + 0) / SAMPLE_STRIDE, nA, 1)
|
|
||||||
+ i;
|
|
||||||
assert(dstPosA < nA + nB);
|
|
||||||
limits[(segmentBase / SAMPLE_STRIDE) + dstPosA] = ranks[(segmentBase + stride) / SAMPLE_STRIDE + i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Merge step 3: merge elementary intervals (each interval is <= SAMPLE_STRIDE)
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
static void merge(uint *dstKey,
|
|
||||||
uint *dstVal,
|
|
||||||
uint *srcAKey,
|
|
||||||
uint *srcAVal,
|
|
||||||
uint *srcBKey,
|
|
||||||
uint *srcBVal,
|
|
||||||
uint lenA,
|
|
||||||
uint lenB,
|
|
||||||
uint sortDir)
|
|
||||||
{
|
|
||||||
checkOrder(srcAKey, lenA, sortDir);
|
|
||||||
checkOrder(srcBKey, lenB, sortDir);
|
|
||||||
|
|
||||||
for (uint i = 0; i < lenA; i++) {
|
|
||||||
uint dstPos = binarySearchExclusive(srcAKey[i], srcBKey, lenB, sortDir) + i;
|
|
||||||
assert(dstPos < lenA + lenB);
|
|
||||||
dstKey[dstPos] = srcAKey[i];
|
|
||||||
dstVal[dstPos] = srcAVal[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint i = 0; i < lenB; i++) {
|
|
||||||
uint dstPos = binarySearchInclusive(srcBKey[i], srcAKey, lenA, sortDir) + i;
|
|
||||||
assert(dstPos < lenA + lenB);
|
|
||||||
dstKey[dstPos] = srcBKey[i];
|
|
||||||
dstVal[dstPos] = srcBVal[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mergeElementaryIntervals(uint *dstKey,
|
|
||||||
uint *dstVal,
|
|
||||||
uint *srcKey,
|
|
||||||
uint *srcVal,
|
|
||||||
uint *limitsA,
|
|
||||||
uint *limitsB,
|
|
||||||
uint stride,
|
|
||||||
uint N,
|
|
||||||
uint sortDir)
|
|
||||||
{
|
|
||||||
uint lastSegmentElements = N % (2 * stride);
|
|
||||||
uint mergePairs = (lastSegmentElements > stride) ? getSampleCount(N) : (N - lastSegmentElements) / SAMPLE_STRIDE;
|
|
||||||
|
|
||||||
for (uint pos = 0; pos < mergePairs; pos++) {
|
|
||||||
uint i = pos & ((2 * stride) / SAMPLE_STRIDE - 1);
|
|
||||||
uint segmentBase = (pos - i) * SAMPLE_STRIDE;
|
|
||||||
|
|
||||||
const uint lenA = stride;
|
|
||||||
const uint lenB = umin(stride, N - segmentBase - stride);
|
|
||||||
const uint nA = stride / SAMPLE_STRIDE;
|
|
||||||
const uint nB = getSampleCount(lenB);
|
|
||||||
const uint n = nA + nB;
|
|
||||||
|
|
||||||
const uint startPosA = limitsA[pos];
|
|
||||||
const uint endPosA = (i + 1 < n) ? limitsA[pos + 1] : lenA;
|
|
||||||
const uint startPosB = limitsB[pos];
|
|
||||||
const uint endPosB = (i + 1 < n) ? limitsB[pos + 1] : lenB;
|
|
||||||
const uint startPosDst = startPosA + startPosB;
|
|
||||||
|
|
||||||
assert(startPosA <= endPosA && endPosA <= lenA);
|
|
||||||
assert(startPosB <= endPosB && endPosB <= lenB);
|
|
||||||
assert((endPosA - startPosA) <= SAMPLE_STRIDE);
|
|
||||||
assert((endPosB - startPosB) <= SAMPLE_STRIDE);
|
|
||||||
|
|
||||||
merge(dstKey + segmentBase + startPosDst,
|
|
||||||
dstVal + segmentBase + startPosDst,
|
|
||||||
(srcKey + segmentBase + 0) + startPosA,
|
|
||||||
(srcVal + segmentBase + 0) + startPosA,
|
|
||||||
(srcKey + segmentBase + stride) + startPosB,
|
|
||||||
(srcVal + segmentBase + stride) + startPosB,
|
|
||||||
endPosA - startPosA,
|
|
||||||
endPosB - startPosB,
|
|
||||||
sortDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Retarded bubble sort
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
static void bubbleSort(uint *key, uint *val, uint N, uint sortDir)
|
|
||||||
{
|
|
||||||
if (N <= 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint bottom = 0; bottom < N - 1; bottom++) {
|
|
||||||
uint savePos = bottom;
|
|
||||||
uint saveKey = key[bottom];
|
|
||||||
|
|
||||||
for (uint i = bottom + 1; i < N; i++)
|
|
||||||
if ((sortDir && (key[i] < saveKey)) || (!sortDir && (key[i] > saveKey))) {
|
|
||||||
savePos = i;
|
|
||||||
saveKey = key[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (savePos != bottom) {
|
|
||||||
uint t;
|
|
||||||
t = key[savePos];
|
|
||||||
key[savePos] = key[bottom];
|
|
||||||
key[bottom] = t;
|
|
||||||
t = val[savePos];
|
|
||||||
val[savePos] = val[bottom];
|
|
||||||
val[bottom] = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Interface function
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
extern "C" void
|
|
||||||
mergeSortHost(uint *dstKey, uint *dstVal, uint *bufKey, uint *bufVal, uint *srcKey, uint *srcVal, uint N, uint sortDir)
|
|
||||||
{
|
|
||||||
uint *ikey, *ival, *okey, *oval;
|
|
||||||
uint stageCount = 0;
|
|
||||||
|
|
||||||
for (uint stride = SHARED_SIZE_LIMIT; stride < N; stride <<= 1, stageCount++)
|
|
||||||
;
|
|
||||||
|
|
||||||
if (stageCount & 1) {
|
|
||||||
ikey = bufKey;
|
|
||||||
ival = bufVal;
|
|
||||||
okey = dstKey;
|
|
||||||
oval = dstVal;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ikey = dstKey;
|
|
||||||
ival = dstVal;
|
|
||||||
okey = bufKey;
|
|
||||||
oval = bufVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Bottom-level sort...\n");
|
|
||||||
memcpy(ikey, srcKey, N * sizeof(uint));
|
|
||||||
memcpy(ival, srcVal, N * sizeof(uint));
|
|
||||||
|
|
||||||
for (uint pos = 0; pos < N; pos += SHARED_SIZE_LIMIT) {
|
|
||||||
bubbleSort(ikey + pos, ival + pos, umin(SHARED_SIZE_LIMIT, N - pos), sortDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Merge...\n");
|
|
||||||
uint *ranksA = (uint *)malloc(getSampleCount(N) * sizeof(uint));
|
|
||||||
uint *ranksB = (uint *)malloc(getSampleCount(N) * sizeof(uint));
|
|
||||||
uint *limitsA = (uint *)malloc(getSampleCount(N) * sizeof(uint));
|
|
||||||
uint *limitsB = (uint *)malloc(getSampleCount(N) * sizeof(uint));
|
|
||||||
memset(ranksA, 0xFF, getSampleCount(N) * sizeof(uint));
|
|
||||||
memset(ranksB, 0xFF, getSampleCount(N) * sizeof(uint));
|
|
||||||
memset(limitsA, 0xFF, getSampleCount(N) * sizeof(uint));
|
|
||||||
memset(limitsB, 0xFF, getSampleCount(N) * sizeof(uint));
|
|
||||||
|
|
||||||
for (uint stride = SHARED_SIZE_LIMIT; stride < N; stride <<= 1) {
|
|
||||||
uint lastSegmentElements = N % (2 * stride);
|
|
||||||
|
|
||||||
// Find sample ranks and prepare for limiters merge
|
|
||||||
generateSampleRanks(ranksA, ranksB, ikey, stride, N, sortDir);
|
|
||||||
|
|
||||||
// Merge ranks and indices
|
|
||||||
mergeRanksAndIndices(limitsA, ranksA, stride, N);
|
|
||||||
mergeRanksAndIndices(limitsB, ranksB, stride, N);
|
|
||||||
|
|
||||||
// Merge elementary intervals
|
|
||||||
mergeElementaryIntervals(okey, oval, ikey, ival, limitsA, limitsB, stride, N, sortDir);
|
|
||||||
|
|
||||||
if (lastSegmentElements <= stride) {
|
|
||||||
// Last merge segment consists of a single array which just needs to be
|
|
||||||
// passed through
|
|
||||||
memcpy(
|
|
||||||
okey + (N - lastSegmentElements), ikey + (N - lastSegmentElements), lastSegmentElements * sizeof(uint));
|
|
||||||
memcpy(
|
|
||||||
oval + (N - lastSegmentElements), ival + (N - lastSegmentElements), lastSegmentElements * sizeof(uint));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint *t;
|
|
||||||
t = ikey;
|
|
||||||
ikey = okey;
|
|
||||||
okey = t;
|
|
||||||
t = ival;
|
|
||||||
ival = oval;
|
|
||||||
oval = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(limitsB);
|
|
||||||
free(limitsA);
|
|
||||||
free(ranksB);
|
|
||||||
free(ranksA);
|
|
||||||
}
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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 <assert.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "mergeSort_common.h"
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Validate sorted keys array (check for integrity and proper order)
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
extern "C" uint
|
|
||||||
validateSortedKeys(uint *resKey, uint *srcKey, uint batchSize, uint arrayLength, uint numValues, uint sortDir)
|
|
||||||
{
|
|
||||||
uint *srcHist;
|
|
||||||
uint *resHist;
|
|
||||||
|
|
||||||
if (arrayLength < 2) {
|
|
||||||
printf("validateSortedKeys(): arrays too short, exiting...\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("...inspecting keys array: ");
|
|
||||||
srcHist = (uint *)malloc(numValues * sizeof(uint));
|
|
||||||
resHist = (uint *)malloc(numValues * sizeof(uint));
|
|
||||||
|
|
||||||
int flag = 1;
|
|
||||||
|
|
||||||
for (uint j = 0; j < batchSize; j++, srcKey += arrayLength, resKey += arrayLength) {
|
|
||||||
// Build histograms for keys arrays
|
|
||||||
memset(srcHist, 0, numValues * sizeof(uint));
|
|
||||||
memset(resHist, 0, numValues * sizeof(uint));
|
|
||||||
|
|
||||||
for (uint i = 0; i < arrayLength; i++) {
|
|
||||||
if ((srcKey[i] < numValues) && (resKey[i] < numValues)) {
|
|
||||||
srcHist[srcKey[i]]++;
|
|
||||||
resHist[resKey[i]]++;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fprintf(stderr, "***Set %u source/result key arrays are not limited properly***\n", j);
|
|
||||||
flag = 0;
|
|
||||||
goto brk;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compare the histograms
|
|
||||||
for (uint i = 0; i < numValues; i++)
|
|
||||||
if (srcHist[i] != resHist[i]) {
|
|
||||||
fprintf(stderr, "***Set %u source/result keys histograms do not match***\n", j);
|
|
||||||
flag = 0;
|
|
||||||
goto brk;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally check the ordering
|
|
||||||
for (uint i = 0; i < arrayLength - 1; i++)
|
|
||||||
if ((sortDir && (resKey[i] > resKey[i + 1])) || (!sortDir && (resKey[i] < resKey[i + 1]))) {
|
|
||||||
fprintf(stderr, "***Set %u result key array is not ordered properly***\n", j);
|
|
||||||
flag = 0;
|
|
||||||
goto brk;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
brk:
|
|
||||||
free(resHist);
|
|
||||||
free(srcHist);
|
|
||||||
|
|
||||||
if (flag)
|
|
||||||
printf("OK\n");
|
|
||||||
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Value validation / stability check routines
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
extern "C" void fillValues(uint *val, uint N)
|
|
||||||
{
|
|
||||||
for (uint i = 0; i < N; i++)
|
|
||||||
val[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" int validateSortedValues(uint *resKey, uint *resVal, uint *srcKey, uint batchSize, uint arrayLength)
|
|
||||||
{
|
|
||||||
int correctFlag = 1, stableFlag = 1;
|
|
||||||
|
|
||||||
printf("...inspecting keys and values array: ");
|
|
||||||
|
|
||||||
for (uint i = 0; i < batchSize; i++, resKey += arrayLength, resVal += arrayLength) {
|
|
||||||
for (uint j = 0; j < arrayLength; j++) {
|
|
||||||
if (resKey[j] != srcKey[resVal[j]])
|
|
||||||
correctFlag = 0;
|
|
||||||
|
|
||||||
if ((j < arrayLength - 1) && (resKey[j] == resKey[j + 1]) && (resVal[j] > resVal[j + 1]))
|
|
||||||
stableFlag = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf(correctFlag ? "OK\n" : "***corrupted!!!***\n");
|
|
||||||
printf(stableFlag ? "...stability property: stable!\n" : "...stability property: NOT stable\n");
|
|
||||||
|
|
||||||
return correctFlag;
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/simpleAWBarrier"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
|
||||||
|
|
||||||
project(simpleAWBarrier LANGUAGES C CXX CUDA)
|
|
||||||
|
|
||||||
find_package(CUDAToolkit REQUIRED)
|
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90 100 110 120)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
|
||||||
|
|
||||||
if(ENABLE_CUDA_DEBUG)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G") # enable cuda-gdb (may significantly affect performance on some targets)
|
|
||||||
else()
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") # add line information to all builds for debug tools (exclusive to -G option)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Include directories and libraries
|
|
||||||
include_directories(../../../Common)
|
|
||||||
|
|
||||||
# This sample is not supported on QNX
|
|
||||||
if(CMAKE_SYSTEM_NAME STREQUAL "QNX")
|
|
||||||
message(STATUS "simpleAWBarrier is not supported on QNX")
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Source file
|
|
||||||
# Add target for simpleAWBarrier
|
|
||||||
add_executable(simpleAWBarrier simpleAWBarrier.cu)
|
|
||||||
|
|
||||||
target_compile_options(simpleAWBarrier PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
|
||||||
|
|
||||||
target_compile_features(simpleAWBarrier PRIVATE cxx_std_17 cuda_std_17)
|
|
||||||
|
|
||||||
set_target_properties(simpleAWBarrier PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/simpleAssert"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
|
||||||
|
|
||||||
project(simpleAssert LANGUAGES C CXX CUDA)
|
|
||||||
|
|
||||||
find_package(CUDAToolkit REQUIRED)
|
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90 100 110 120)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
|
||||||
if(ENABLE_CUDA_DEBUG)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G") # enable cuda-gdb (may significantly affect performance on some targets)
|
|
||||||
else()
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") # add line information to all builds for debug tools (exclusive to -G option)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Removes -DNDEBUG For Print specific logs in this sample.
|
|
||||||
string(REPLACE "-DNDEBUG" "" CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CUDA_FLAGS_RELEASE}")
|
|
||||||
|
|
||||||
# Include directories and libraries
|
|
||||||
include_directories(../../../Common)
|
|
||||||
|
|
||||||
# Source file
|
|
||||||
# Add target for simpleAssert
|
|
||||||
add_executable(simpleAssert simpleAssert.cu)
|
|
||||||
|
|
||||||
target_compile_options(simpleAssert PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
|
||||||
|
|
||||||
target_compile_features(simpleAssert PRIVATE cxx_std_17 cuda_std_17)
|
|
||||||
|
|
||||||
set_target_properties(simpleAssert PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
# simpleAssert - simpleAssert
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
This CUDA Runtime API sample is a very basic sample that implements how to use the assert function in the device code. Requires Compute Capability 2.0 .
|
|
||||||
|
|
||||||
## Key Concepts
|
|
||||||
|
|
||||||
Assert
|
|
||||||
|
|
||||||
## Supported SM Architectures
|
|
||||||
|
|
||||||
[SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](https://developer.nvidia.com/cuda-gpus) [SM 5.3 ](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) [SM 8.7 ](https://developer.nvidia.com/cuda-gpus) [SM 8.9 ](https://developer.nvidia.com/cuda-gpus) [SM 9.0 ](https://developer.nvidia.com/cuda-gpus)
|
|
||||||
|
|
||||||
## Supported OSes
|
|
||||||
|
|
||||||
Linux, Windows
|
|
||||||
|
|
||||||
## Supported CPU Architecture
|
|
||||||
|
|
||||||
x86_64, armv7l
|
|
||||||
|
|
||||||
## CUDA APIs involved
|
|
||||||
|
|
||||||
### [CUDA Runtime API](http://docs.nvidia.com/cuda/cuda-runtime-api/index.html)
|
|
||||||
cudaDeviceSynchronize, cudaGetErrorString
|
|
||||||
|
|
||||||
## Prerequisites
|
|
||||||
|
|
||||||
Download and install the [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
|
||||||
|
|
||||||
## References (for more details)
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/simpleAssert_nvrtc"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
|
||||||
|
|
||||||
project(simpleAssert_nvrtc LANGUAGES C CXX CUDA)
|
|
||||||
|
|
||||||
find_package(CUDAToolkit REQUIRED)
|
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
||||||
|
|
||||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90 100 110 120)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
|
||||||
if(ENABLE_CUDA_DEBUG)
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G") # enable cuda-gdb (may significantly affect performance on some targets)
|
|
||||||
else()
|
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") # add line information to all builds for debug tools (exclusive to -G option)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Include directories and libraries
|
|
||||||
include_directories(../../../Common)
|
|
||||||
|
|
||||||
# Source file
|
|
||||||
# Add sample target executable
|
|
||||||
add_executable(simpleAssert_nvrtc simpleAssert.cpp)
|
|
||||||
|
|
||||||
target_compile_options(simpleAssert_nvrtc PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
|
||||||
|
|
||||||
target_compile_features(simpleAssert_nvrtc PRIVATE cxx_std_17 cuda_std_17)
|
|
||||||
|
|
||||||
target_link_libraries(simpleAssert_nvrtc PRIVATE
|
|
||||||
CUDA::nvrtc
|
|
||||||
CUDA::cuda_driver
|
|
||||||
)
|
|
||||||
|
|
||||||
# Copy clock_kernel.cu to the output directory
|
|
||||||
add_custom_command(TARGET simpleAssert_nvrtc POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/simpleAssert_kernel.cu ${CMAKE_CURRENT_BINARY_DIR}
|
|
||||||
)
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
# simpleAssert_nvrtc - simpleAssert with libNVRTC
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
This CUDA Runtime API sample is a very basic sample that implements how to use the assert function in the device code. Requires Compute Capability 2.0 .
|
|
||||||
|
|
||||||
## Key Concepts
|
|
||||||
|
|
||||||
Assert, Runtime Compilation
|
|
||||||
|
|
||||||
## Supported SM Architectures
|
|
||||||
|
|
||||||
[SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](https://developer.nvidia.com/cuda-gpus) [SM 5.3 ](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) [SM 8.7 ](https://developer.nvidia.com/cuda-gpus) [SM 8.9 ](https://developer.nvidia.com/cuda-gpus) [SM 9.0 ](https://developer.nvidia.com/cuda-gpus)
|
|
||||||
|
|
||||||
## Supported OSes
|
|
||||||
|
|
||||||
Linux, Windows, QNX
|
|
||||||
|
|
||||||
## Supported CPU Architecture
|
|
||||||
|
|
||||||
x86_64, aarch64
|
|
||||||
|
|
||||||
## CUDA APIs involved
|
|
||||||
|
|
||||||
### [CUDA Driver API](http://docs.nvidia.com/cuda/cuda-driver-api/index.html)
|
|
||||||
cuModuleGetFunction, cuLaunchKernel, cuCtxSynchronize
|
|
||||||
|
|
||||||
## Dependencies needed to build/run
|
|
||||||
[NVRTC](../../../README.md#nvrtc)
|
|
||||||
|
|
||||||
## Prerequisites
|
|
||||||
|
|
||||||
Download and install the [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
|
||||||
Make sure the dependencies mentioned in [Dependencies]() section above are installed.
|
|
||||||
|
|
||||||
## References (for more details)
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#define WINDOWS_LEAN_AND_MEAN
|
|
||||||
#define NOMINMAX
|
|
||||||
#include <windows.h>
|
|
||||||
#else
|
|
||||||
#include <sys/utsname.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Includes, system
|
|
||||||
#include <cassert>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
// Includes CUDA
|
|
||||||
#include <cuda_runtime.h>
|
|
||||||
|
|
||||||
#include "nvrtc_helper.h"
|
|
||||||
|
|
||||||
// Utilities and timing functions
|
|
||||||
#include <helper_functions.h> // includes cuda.h and cuda_runtime_api.h
|
|
||||||
|
|
||||||
const char *sampleName = "simpleAssert_nvrtc";
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Auto-Verification Code
|
|
||||||
bool testResult = true;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Declaration, forward
|
|
||||||
void runTest(int argc, char **argv);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Program main
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
printf("%s starting...\n", sampleName);
|
|
||||||
|
|
||||||
runTest(argc, argv);
|
|
||||||
|
|
||||||
exit(testResult ? EXIT_SUCCESS : EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void runTest(int argc, char **argv)
|
|
||||||
{
|
|
||||||
int Nblocks = 2;
|
|
||||||
int Nthreads = 32;
|
|
||||||
|
|
||||||
// Kernel configuration, where a one-dimensional
|
|
||||||
// grid and one-dimensional blocks are configured.
|
|
||||||
|
|
||||||
dim3 dimGrid(Nblocks);
|
|
||||||
dim3 dimBlock(Nthreads);
|
|
||||||
|
|
||||||
printf("Launch kernel to generate assertion failures\n");
|
|
||||||
char *cubin, *kernel_file;
|
|
||||||
size_t cubinSize;
|
|
||||||
|
|
||||||
kernel_file = sdkFindFilePath("simpleAssert_kernel.cu", argv[0]);
|
|
||||||
compileFileToCUBIN(kernel_file, argc, argv, &cubin, &cubinSize, 0);
|
|
||||||
|
|
||||||
CUmodule module = loadCUBIN(cubin, argc, argv);
|
|
||||||
CUfunction kernel_addr;
|
|
||||||
|
|
||||||
checkCudaErrors(cuModuleGetFunction(&kernel_addr, module, "testKernel"));
|
|
||||||
|
|
||||||
int count = 60;
|
|
||||||
void *args[] = {(void *)&count};
|
|
||||||
|
|
||||||
checkCudaErrors(cuLaunchKernel(kernel_addr,
|
|
||||||
dimGrid.x,
|
|
||||||
dimGrid.y,
|
|
||||||
dimGrid.z, /* grid dim */
|
|
||||||
dimBlock.x,
|
|
||||||
dimBlock.y,
|
|
||||||
dimBlock.z, /* block dim */
|
|
||||||
0,
|
|
||||||
0, /* shared mem, stream */
|
|
||||||
&args[0], /* arguments */
|
|
||||||
0));
|
|
||||||
|
|
||||||
// Synchronize (flushes assert output).
|
|
||||||
printf("\n-- Begin assert output\n\n");
|
|
||||||
CUresult res = cuCtxSynchronize();
|
|
||||||
|
|
||||||
printf("\n-- End assert output\n\n");
|
|
||||||
|
|
||||||
// Check for errors and failed asserts in asynchronous kernel launch.
|
|
||||||
if (res == CUDA_ERROR_ASSERT) {
|
|
||||||
printf("Device assert failed as expected\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
testResult = res == CUDA_ERROR_ASSERT;
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/* Copyright (c) 2022, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Kernels
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//! Tests assert function.
|
|
||||||
//! Thread whose id > N will print assertion failed error message.
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
extern "C" __global__ void testKernel(int N)
|
|
||||||
{
|
|
||||||
int gtid = blockIdx.x * blockDim.x + threadIdx.x;
|
|
||||||
assert(gtid < N);
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"${workspaceFolder}/../../../Common"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"compilerPath": "/usr/local/cuda/bin/nvcc",
|
|
||||||
"cStandard": "gnu17",
|
|
||||||
"cppStandard": "gnu++14",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"configurationProvider": "ms-vscode.makefile-tools"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"nvidia.nsight-vscode-edition",
|
|
||||||
"ms-vscode.cpptools",
|
|
||||||
"ms-vscode.makefile-tools"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "CUDA C++: Launch",
|
|
||||||
"type": "cuda-gdb",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/simpleAtomicIntrinsics"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user