mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-13 00:08:26 +08:00
CUDA 13.4 samples update - v13.4-public
Release 13.4 of the CUDA Samples supported by CUDA Toolkit 13.4. See Changelog for more information.
This commit is contained in:
@@ -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,34 +1,25 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(BlackScholes LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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 BlackScholes
|
||||
add_executable(BlackScholes BlackScholes.cu BlackScholes_gold.cpp)
|
||||
|
||||
target_compile_options(BlackScholes PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(BlackScholes PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(BlackScholes PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This sample evaluates fair call and put prices for a
|
||||
* given set of European options by Black-Scholes formula.
|
||||
* See supplied whitepaper for more explanations.
|
||||
*/
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include <helper_functions.h> // helper functions for string parsing
|
||||
#include <nvrtc_helper.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Process an array of optN options on CPU
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" void BlackScholesCPU(float *h_CallResult,
|
||||
float *h_PutResult,
|
||||
float *h_StockPrice,
|
||||
float *h_OptionStrike,
|
||||
float *h_OptionYears,
|
||||
float Riskfree,
|
||||
float Volatility,
|
||||
int optN);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Process an array of OptN options on GPU
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Helper function, returning uniformly distributed
|
||||
// random float in [low, high] range
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
float RandFloat(float low, float high)
|
||||
{
|
||||
float t = (float)rand() / (float)RAND_MAX;
|
||||
return (1.0f - t) * low + t * high;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Data configuration
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const int OPT_N = 4000000;
|
||||
const int NUM_ITERATIONS = 512;
|
||||
const int OPT_SZ = OPT_N * sizeof(float);
|
||||
const float RISKFREE = 0.02f;
|
||||
const float VOLATILITY = 0.30f;
|
||||
|
||||
#define DIV_UP(a, b) (((a) + (b) - 1) / (b))
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Main program
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Start logs
|
||||
printf("[%s] - Starting...\n", argv[0]);
|
||||
|
||||
//'h_' prefix - CPU (host) memory space
|
||||
float
|
||||
// Results calculated by CPU for reference
|
||||
*h_CallResultCPU,
|
||||
*h_PutResultCPU,
|
||||
// CPU copy of GPU results
|
||||
*h_CallResultGPU, *h_PutResultGPU,
|
||||
// CPU instance of input data
|
||||
*h_StockPrice, *h_OptionStrike, *h_OptionYears;
|
||||
|
||||
//'d_' prefix - GPU (device) memory space
|
||||
CUdeviceptr
|
||||
// Results calculated by GPU
|
||||
d_CallResult,
|
||||
d_PutResult,
|
||||
|
||||
// GPU instance of input data
|
||||
d_StockPrice, d_OptionStrike, d_OptionYears;
|
||||
|
||||
double delta, ref, sum_delta, sum_ref, max_delta, L1norm, gpuTime;
|
||||
|
||||
StopWatchInterface *hTimer = NULL;
|
||||
int i;
|
||||
|
||||
sdkCreateTimer(&hTimer);
|
||||
|
||||
printf("Initializing data...\n");
|
||||
printf("...allocating CPU memory for options.\n");
|
||||
|
||||
h_CallResultCPU = (float *)malloc(OPT_SZ);
|
||||
h_PutResultCPU = (float *)malloc(OPT_SZ);
|
||||
h_CallResultGPU = (float *)malloc(OPT_SZ);
|
||||
h_PutResultGPU = (float *)malloc(OPT_SZ);
|
||||
h_StockPrice = (float *)malloc(OPT_SZ);
|
||||
h_OptionStrike = (float *)malloc(OPT_SZ);
|
||||
h_OptionYears = (float *)malloc(OPT_SZ);
|
||||
|
||||
char *cubin, *kernel_file;
|
||||
size_t cubinSize;
|
||||
kernel_file = sdkFindFilePath("BlackScholes_kernel.cuh", argv[0]);
|
||||
|
||||
// Compile the kernel BlackScholes_kernel.
|
||||
compileFileToCUBIN(kernel_file, argc, argv, &cubin, &cubinSize, 0);
|
||||
CUmodule module = loadCUBIN(cubin, argc, argv);
|
||||
|
||||
CUfunction kernel_addr;
|
||||
checkCudaErrors(cuModuleGetFunction(&kernel_addr, module, "BlackScholesGPU"));
|
||||
|
||||
printf("...allocating GPU memory for options.\n");
|
||||
checkCudaErrors(cuMemAlloc(&d_CallResult, OPT_SZ));
|
||||
checkCudaErrors(cuMemAlloc(&d_PutResult, OPT_SZ));
|
||||
checkCudaErrors(cuMemAlloc(&d_StockPrice, OPT_SZ));
|
||||
checkCudaErrors(cuMemAlloc(&d_OptionStrike, OPT_SZ));
|
||||
checkCudaErrors(cuMemAlloc(&d_OptionYears, OPT_SZ));
|
||||
|
||||
printf("...generating input data in CPU mem.\n");
|
||||
srand(5347);
|
||||
|
||||
// Generate options set
|
||||
for (i = 0; i < OPT_N; i++) {
|
||||
h_CallResultCPU[i] = 0.0f;
|
||||
h_PutResultCPU[i] = -1.0f;
|
||||
h_StockPrice[i] = RandFloat(5.0f, 30.0f);
|
||||
h_OptionStrike[i] = RandFloat(1.0f, 100.0f);
|
||||
h_OptionYears[i] = RandFloat(0.25f, 10.0f);
|
||||
}
|
||||
|
||||
printf("...copying input data to GPU mem.\n");
|
||||
// Copy options data to GPU memory for further processing
|
||||
checkCudaErrors(cuMemcpyHtoD(d_StockPrice, h_StockPrice, OPT_SZ));
|
||||
checkCudaErrors(cuMemcpyHtoD(d_OptionStrike, h_OptionStrike, OPT_SZ));
|
||||
checkCudaErrors(cuMemcpyHtoD(d_OptionYears, h_OptionYears, OPT_SZ));
|
||||
|
||||
printf("Data init done.\n\n");
|
||||
printf("Executing Black-Scholes GPU kernel (%i iterations)...\n", NUM_ITERATIONS);
|
||||
|
||||
sdkResetTimer(&hTimer);
|
||||
sdkStartTimer(&hTimer);
|
||||
|
||||
dim3 cudaBlockSize(128, 1, 1);
|
||||
dim3 cudaGridSize(DIV_UP(OPT_N / 2, 128), 1, 1);
|
||||
|
||||
float risk = RISKFREE;
|
||||
float volatility = VOLATILITY;
|
||||
int optval = OPT_N;
|
||||
|
||||
void *arr[] = {(void *)&d_CallResult,
|
||||
(void *)&d_PutResult,
|
||||
(void *)&d_StockPrice,
|
||||
(void *)&d_OptionStrike,
|
||||
(void *)&d_OptionYears,
|
||||
(void *)&risk,
|
||||
(void *)&volatility,
|
||||
(void *)&optval};
|
||||
|
||||
for (i = 0; i < NUM_ITERATIONS; i++) {
|
||||
checkCudaErrors(cuLaunchKernel(kernel_addr,
|
||||
cudaGridSize.x,
|
||||
cudaGridSize.y,
|
||||
cudaGridSize.z, /* grid dim */
|
||||
cudaBlockSize.x,
|
||||
cudaBlockSize.y,
|
||||
cudaBlockSize.z, /* block dim */
|
||||
0,
|
||||
0, /* shared mem, stream */
|
||||
&arr[0], /* arguments */
|
||||
0));
|
||||
}
|
||||
|
||||
checkCudaErrors(cuCtxSynchronize());
|
||||
|
||||
sdkStopTimer(&hTimer);
|
||||
gpuTime = sdkGetTimerValue(&hTimer) / NUM_ITERATIONS;
|
||||
|
||||
// Both call and put is calculated
|
||||
printf("Options count : %i \n", 2 * OPT_N);
|
||||
printf("BlackScholesGPU() time : %f msec\n", gpuTime);
|
||||
printf("Effective memory bandwidth: %f GB/s\n", ((double)(5 * OPT_N * sizeof(float)) * 1E-9) / (gpuTime * 1E-3));
|
||||
printf("Gigaoptions per second : %f \n\n", ((double)(2 * OPT_N) * 1E-9) / (gpuTime * 1E-3));
|
||||
printf("BlackScholes, Throughput = %.4f GOptions/s, Time = %.5f s, Size = %u "
|
||||
"options, NumDevsUsed = %u, Workgroup = %u\n",
|
||||
(((double)(2.0 * OPT_N) * 1.0E-9) / (gpuTime * 1.0E-3)),
|
||||
gpuTime * 1e-3,
|
||||
(2 * OPT_N),
|
||||
1,
|
||||
128);
|
||||
|
||||
printf("\nReading back GPU results...\n");
|
||||
|
||||
// Read back GPU results to compare them to CPU results
|
||||
checkCudaErrors(cuMemcpyDtoH(h_CallResultGPU, d_CallResult, OPT_SZ));
|
||||
checkCudaErrors(cuMemcpyDtoH(h_PutResultGPU, d_PutResult, OPT_SZ));
|
||||
|
||||
printf("Checking the results...\n");
|
||||
printf("...running CPU calculations.\n\n");
|
||||
|
||||
// Calculate options values on CPU
|
||||
BlackScholesCPU(
|
||||
h_CallResultCPU, h_PutResultCPU, h_StockPrice, h_OptionStrike, h_OptionYears, RISKFREE, VOLATILITY, OPT_N);
|
||||
|
||||
printf("Comparing the results...\n");
|
||||
// Calculate max absolute difference and L1 distance
|
||||
// between CPU and GPU results
|
||||
sum_delta = 0;
|
||||
sum_ref = 0;
|
||||
max_delta = 0;
|
||||
|
||||
for (i = 0; i < OPT_N; i++) {
|
||||
ref = h_CallResultCPU[i];
|
||||
delta = fabs(h_CallResultCPU[i] - h_CallResultGPU[i]);
|
||||
|
||||
if (delta > max_delta) {
|
||||
max_delta = delta;
|
||||
}
|
||||
|
||||
sum_delta += delta;
|
||||
sum_ref += fabs(ref);
|
||||
}
|
||||
|
||||
L1norm = sum_delta / sum_ref;
|
||||
printf("L1 norm: %E\n", L1norm);
|
||||
printf("Max absolute error: %E\n\n", max_delta);
|
||||
|
||||
printf("Shutting down...\n");
|
||||
printf("...releasing GPU memory.\n");
|
||||
|
||||
checkCudaErrors(cuMemFree(d_OptionYears));
|
||||
checkCudaErrors(cuMemFree(d_OptionStrike));
|
||||
checkCudaErrors(cuMemFree(d_StockPrice));
|
||||
checkCudaErrors(cuMemFree(d_PutResult));
|
||||
checkCudaErrors(cuMemFree(d_CallResult));
|
||||
|
||||
printf("...releasing CPU memory.\n");
|
||||
|
||||
free(h_OptionYears);
|
||||
free(h_OptionStrike);
|
||||
free(h_StockPrice);
|
||||
free(h_PutResultGPU);
|
||||
free(h_CallResultGPU);
|
||||
free(h_PutResultCPU);
|
||||
free(h_CallResultCPU);
|
||||
|
||||
sdkDeleteTimer(&hTimer);
|
||||
printf("Shutdown done.\n");
|
||||
|
||||
printf("\n[%s] - Test Summary\n", argv[0]);
|
||||
|
||||
if (L1norm > 1e-6) {
|
||||
printf("Test failed!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test passed\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
@@ -1,100 +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 <math.h>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Polynomial approximation of cumulative normal distribution function
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static double CND(double d)
|
||||
{
|
||||
const double A1 = 0.31938153;
|
||||
const double A2 = -0.356563782;
|
||||
const double A3 = 1.781477937;
|
||||
const double A4 = -1.821255978;
|
||||
const double A5 = 1.330274429;
|
||||
const double RSQRT2PI = 0.39894228040143267793994605993438;
|
||||
|
||||
double K = 1.0 / (1.0 + 0.2316419 * fabs(d));
|
||||
|
||||
double cnd = RSQRT2PI * exp(-0.5 * d * d) * (K * (A1 + K * (A2 + K * (A3 + K * (A4 + K * A5)))));
|
||||
|
||||
if (d > 0)
|
||||
cnd = 1.0 - cnd;
|
||||
|
||||
return cnd;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Black-Scholes formula for both call and put
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
static void BlackScholesBodyCPU(float &callResult,
|
||||
float &putResult,
|
||||
float Sf, // Stock price
|
||||
float Xf, // Option strike
|
||||
float Tf, // Option years
|
||||
float Rf, // Riskless rate
|
||||
float Vf // Volatility rate
|
||||
)
|
||||
{
|
||||
double S = Sf, X = Xf, T = Tf, R = Rf, V = Vf;
|
||||
double sqrtT = sqrt(T);
|
||||
double d1 = (log(S / X) + (R + 0.5 * V * V) * T) / (V * sqrtT);
|
||||
double d2 = d1 - V * sqrtT;
|
||||
double CNDD1 = CND(d1);
|
||||
double CNDD2 = CND(d2);
|
||||
|
||||
// Calculate Call and Put simultaneously
|
||||
double expRT = exp(-R * T);
|
||||
|
||||
callResult = (float)(S * CNDD1 - X * expRT * CNDD2);
|
||||
putResult = (float)(X * expRT * (1.0 - CNDD2) - S * (1.0 - CNDD1));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Process an array of optN options
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" void BlackScholesCPU(float *h_CallResult,
|
||||
float *h_PutResult,
|
||||
float *h_StockPrice,
|
||||
float *h_OptionStrike,
|
||||
float *h_OptionYears,
|
||||
float Riskfree,
|
||||
float Volatility,
|
||||
int optN)
|
||||
{
|
||||
for (int opt = 0; opt < optN; opt++)
|
||||
BlackScholesBodyCPU(h_CallResult[opt],
|
||||
h_PutResult[opt],
|
||||
h_StockPrice[opt],
|
||||
h_OptionStrike[opt],
|
||||
h_OptionYears[opt],
|
||||
Riskfree,
|
||||
Volatility);
|
||||
}
|
||||
@@ -1,116 +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.
|
||||
*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Polynomial approximation of cumulative normal distribution function
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
__device__ inline float cndGPU(float d)
|
||||
{
|
||||
const float A1 = 0.31938153f;
|
||||
const float A2 = -0.356563782f;
|
||||
const float A3 = 1.781477937f;
|
||||
const float A4 = -1.821255978f;
|
||||
const float A5 = 1.330274429f;
|
||||
const float RSQRT2PI = 0.39894228040143267793994605993438f;
|
||||
|
||||
float K = __fdividef(1.0f, (1.0f + 0.2316419f * fabsf(d)));
|
||||
|
||||
float cnd = RSQRT2PI * __expf(-0.5f * d * d) * (K * (A1 + K * (A2 + K * (A3 + K * (A4 + K * A5)))));
|
||||
|
||||
if (d > 0)
|
||||
cnd = 1.0f - cnd;
|
||||
|
||||
return cnd;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Black-Scholes formula for both call and put
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
__device__ inline void BlackScholesBodyGPU(float &CallResult,
|
||||
float &PutResult,
|
||||
float S, // Stock price
|
||||
float X, // Option strike
|
||||
float T, // Option years
|
||||
float R, // Riskless rate
|
||||
float V // Volatility rate
|
||||
)
|
||||
{
|
||||
float sqrtT, expRT;
|
||||
float d1, d2, CNDD1, CNDD2;
|
||||
|
||||
sqrtT = __fdividef(1.0F, rsqrtf(T));
|
||||
d1 = __fdividef(__logf(S / X) + (R + 0.5f * V * V) * T, V * sqrtT);
|
||||
d2 = d1 - V * sqrtT;
|
||||
|
||||
CNDD1 = cndGPU(d1);
|
||||
CNDD2 = cndGPU(d2);
|
||||
|
||||
// Calculate Call and Put simultaneously
|
||||
expRT = __expf(-R * T);
|
||||
CallResult = S * CNDD1 - X * expRT * CNDD2;
|
||||
PutResult = X * expRT * (1.0f - CNDD2) - S * (1.0f - CNDD1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Process an array of optN options on GPU
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
extern "C" __launch_bounds__(128) __global__ void BlackScholesGPU(float2 *__restrict d_CallResult,
|
||||
float2 *__restrict d_PutResult,
|
||||
float2 *__restrict d_StockPrice,
|
||||
float2 *__restrict d_OptionStrike,
|
||||
float2 *__restrict d_OptionYears,
|
||||
float Riskfree,
|
||||
float Volatility,
|
||||
int optN)
|
||||
{
|
||||
////Thread index
|
||||
const int opt = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
|
||||
// Calculating 2 options per thread to increase ILP (instruction level
|
||||
// parallelism)
|
||||
if (opt < (optN / 2)) {
|
||||
float callResult1, callResult2;
|
||||
float putResult1, putResult2;
|
||||
BlackScholesBodyGPU(callResult1,
|
||||
putResult1,
|
||||
d_StockPrice[opt].x,
|
||||
d_OptionStrike[opt].x,
|
||||
d_OptionYears[opt].x,
|
||||
Riskfree,
|
||||
Volatility);
|
||||
BlackScholesBodyGPU(callResult2,
|
||||
putResult2,
|
||||
d_StockPrice[opt].y,
|
||||
d_OptionStrike[opt].y,
|
||||
d_OptionYears[opt].y,
|
||||
Riskfree,
|
||||
Volatility);
|
||||
d_CallResult[opt] = make_float2(callResult1, callResult2);
|
||||
d_PutResult[opt] = make_float2(putResult1, putResult2);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
project(BlackScholes_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 target for BlackScholes_nvrtc
|
||||
add_executable(BlackScholes_nvrtc BlackScholes.cpp BlackScholes_gold.cpp)
|
||||
|
||||
target_compile_options(BlackScholes_nvrtc PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(BlackScholes_nvrtc PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(BlackScholes_nvrtc PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_link_libraries(BlackScholes_nvrtc PRIVATE
|
||||
CUDA::nvrtc
|
||||
CUDA::cuda_driver
|
||||
)
|
||||
|
||||
# Copy kernel to the output directory
|
||||
add_custom_command(TARGET BlackScholes_nvrtc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BlackScholes_kernel.cuh ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
@@ -1,39 +0,0 @@
|
||||
# BlackScholes_nvrtc - Black-Scholes Option Pricing with libNVRTC
|
||||
|
||||
## Description
|
||||
|
||||
This sample evaluates fair call and put prices for a given set of European options by Black-Scholes formula, compiling the CUDA kernels involved at runtime using NVRTC.
|
||||
|
||||
## Key Concepts
|
||||
|
||||
Computational Finance, 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,5 +1,4 @@
|
||||
add_subdirectory(BlackScholes)
|
||||
add_subdirectory(BlackScholes_nvrtc)
|
||||
add_subdirectory(FDTD3d)
|
||||
add_subdirectory(HSOpticalFlow)
|
||||
add_subdirectory(Mandelbrot)
|
||||
@@ -10,7 +9,6 @@ add_subdirectory(SobolQRNG)
|
||||
add_subdirectory(bicubicTexture)
|
||||
add_subdirectory(bilateralFilter)
|
||||
add_subdirectory(binomialOptions)
|
||||
add_subdirectory(binomialOptions_nvrtc)
|
||||
add_subdirectory(convolutionFFT2D)
|
||||
add_subdirectory(dwtHaar1D)
|
||||
add_subdirectory(dxtc)
|
||||
@@ -18,10 +16,8 @@ add_subdirectory(fastWalshTransform)
|
||||
add_subdirectory(fluidsGL)
|
||||
add_subdirectory(marchingCubes)
|
||||
add_subdirectory(nbody)
|
||||
add_subdirectory(p2pBandwidthLatencyTest)
|
||||
add_subdirectory(postProcessGL)
|
||||
add_subdirectory(quasirandomGenerator)
|
||||
add_subdirectory(quasirandomGenerator_nvrtc)
|
||||
add_subdirectory(recursiveGaussian)
|
||||
add_subdirectory(simpleD3D11)
|
||||
add_subdirectory(simpleD3D11Texture)
|
||||
|
||||
@@ -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,38 +1,29 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(FDTD3d LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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 FDTD3d
|
||||
add_executable(FDTD3d src/FDTD3d.cpp src/FDTD3dGPU.cu src/FDTD3dReference.cpp)
|
||||
|
||||
target_compile_options(FDTD3d PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(FDTD3d PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(FDTD3d PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(FDTD3d PRIVATE
|
||||
inc
|
||||
)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,34 +1,26 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(HSOpticalFlow LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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 HSOpticalFlow
|
||||
add_executable(HSOpticalFlow flowCUDA.cu flowGold.cpp main.cpp)
|
||||
|
||||
target_compile_options(HSOpticalFlow PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(HSOpticalFlow PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(HSOpticalFlow PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(HSOpticalFlow PRIVATE
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
)
|
||||
@@ -39,6 +31,5 @@ add_custom_command(TARGET HSOpticalFlow POST_BUILD
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,22 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(Mandelbrot LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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)
|
||||
|
||||
if(WIN32)
|
||||
@@ -33,49 +29,37 @@ endif()
|
||||
find_package(OpenGL)
|
||||
find_package(GLUT)
|
||||
|
||||
# Source file
|
||||
if(${OpenGL_FOUND})
|
||||
if (${GLUT_FOUND})
|
||||
# Add target for Mandelbrot
|
||||
add_executable(Mandelbrot Mandelbrot_cuda.cu Mandelbrot_gold.cpp Mandelbrot.cpp)
|
||||
|
||||
target_compile_options(Mandelbrot PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(Mandelbrot PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(Mandelbrot PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_compile_options(Mandelbrot PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
target_compile_features(Mandelbrot PRIVATE cxx_std_17 cuda_std_17)
|
||||
target_include_directories(Mandelbrot PUBLIC
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
${GLUT_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(Mandelbrot
|
||||
${OPENGL_LIBRARIES}
|
||||
${GLUT_LIBRARIES}
|
||||
)
|
||||
|
||||
# Copy data files to the output directory
|
||||
add_custom_command(TARGET Mandelbrot POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(Mandelbrot
|
||||
${PC_GLUT_LIBRARY_DIRS}/freeglut.lib
|
||||
${PC_GLUT_LIBRARY_DIRS}/${GLEW_LIB_NAME}.lib
|
||||
)
|
||||
|
||||
add_custom_command(TARGET Mandelbrot
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/win64/$<CONFIGURATION>/freeglut.dll
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
|
||||
add_custom_command(TARGET Mandelbrot
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
@@ -83,14 +67,11 @@ target_compile_features(Mandelbrot PRIVATE cxx_std_17 cuda_std_17)
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
endif()
|
||||
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
else()
|
||||
message(STATUS "GLUT not found - will not build sample 'Mandelbrot'")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "OpenGL not found - will not build sample 'Mandelbrot'")
|
||||
endif()
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,34 +1,26 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(MonteCarloMultiGPU LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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 MonteCarloMultiGPU
|
||||
add_executable(MonteCarloMultiGPU MonteCarlo_gold.cpp MonteCarlo_kernel.cu multithreading.cpp MonteCarloMultiGPU.cpp)
|
||||
|
||||
target_compile_options(MonteCarloMultiGPU PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(MonteCarloMultiGPU PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(MonteCarloMultiGPU PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(MonteCarloMultiGPU PRIVATE
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
)
|
||||
@@ -37,6 +29,5 @@ target_link_libraries(MonteCarloMultiGPU PRIVATE
|
||||
CUDA::curand
|
||||
)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,34 +1,26 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(NV12toBGRandResize LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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 NV12toBGRandResize
|
||||
add_executable(NV12toBGRandResize bgr_resize.cu nv12_resize.cu nv12_to_bgr_planar.cu resize_convert_main.cpp utils.cu)
|
||||
|
||||
target_compile_options(NV12toBGRandResize PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(NV12toBGRandResize PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(NV12toBGRandResize PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(NV12toBGRandResize PRIVATE
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
)
|
||||
@@ -39,6 +31,5 @@ add_custom_command(TARGET NV12toBGRandResize POST_BUILD
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -10,15 +10,9 @@ Bilateral filter is an edge-preserving non-linear smoothing filter that is imple
|
||||
### [binomialOptions](./binomialOptions)
|
||||
This sample evaluates fair call price for a given set of European options under binomial model.
|
||||
|
||||
### [binomialOptions_nvrtc](./binomialOptions_nvrtc)
|
||||
This sample evaluates fair call price for a given set of European options under binomial model. This sample makes use of NVRTC for Runtime Compilation.
|
||||
|
||||
### [BlackScholes](./BlackScholes)
|
||||
This sample evaluates fair call and put prices for a given set of European options by Black-Scholes formula.
|
||||
|
||||
### [BlackScholes_nvrtc](./BlackScholes_nvrtc)
|
||||
This sample evaluates fair call and put prices for a given set of European options by Black-Scholes formula, compiling the CUDA kernels involved at runtime using NVRTC.
|
||||
|
||||
|
||||
### [convolutionFFT2D](./convolutionFFT2D)
|
||||
This sample demonstrates how 2D convolutions with very large kernel sizes can be efficiently implemented using FFT transformations.
|
||||
@@ -59,18 +53,12 @@ This sample demonstrates efficient all-pairs simulation of a gravitational n-bod
|
||||
### [NV12toBGRandResize](./NV12toBGRandResize)
|
||||
This code shows two ways to convert and resize NV12 frames to BGR 3 planars frames using CUDA in batch. Way-1, Convert NV12 Input to BGR @ Input Resolution-1, then Resize to Resolution#2. Way-2, resize NV12 Input to Resolution#2 then convert it to BGR Output. NVIDIA HW Decoder, both dGPU and Tegra, normally outputs NV12 pitch format frames. For the inference using TensorRT, the input frame needs to be BGR planar format with possibly different size. So, conversion and resizing from NV12 to BGR planar is usually required for the inference following decoding. This CUDA code provides a reference implementation for conversion and resizing.
|
||||
|
||||
### [p2pBandwidthLatencyTest](./p2pBandwidthLatencyTest)
|
||||
This application demonstrates the CUDA Peer-To-Peer (P2P) data transfers between pairs of GPUs and computes latency and bandwidth. Tests on GPU pairs using P2P and without P2P are tested.
|
||||
|
||||
### [postProcessGL](./postProcessGL)
|
||||
This sample shows how to post-process an image rendered in OpenGL using CUDA.
|
||||
|
||||
### [quasirandomGenerator](./quasirandomGenerator)
|
||||
This sample implements Niederreiter Quasirandom Sequence Generator and Inverse Cumulative Normal Distribution functions for the generation of Standard Normal Distributions.
|
||||
|
||||
### [quasirandomGenerator_nvrtc](./quasirandomGenerator_nvrtc)
|
||||
This sample implements Niederreiter Quasirandom Sequence Generator and Inverse Cumulative Normal Distribution functions for the generation of Standard Normal Distributions, compiling the CUDA kernels involved at runtime using NVRTC.
|
||||
|
||||
### [recursiveGaussian](./recursiveGaussian)
|
||||
This sample implements a Gaussian blur using Deriche's recursive method. The advantage of this method is that the execution time is independent of the filter width.
|
||||
|
||||
|
||||
@@ -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,22 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(SobelFilter LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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)
|
||||
|
||||
if(WIN32)
|
||||
@@ -33,48 +29,36 @@ endif()
|
||||
find_package(OpenGL)
|
||||
find_package(GLUT)
|
||||
|
||||
# Source file
|
||||
if(${OpenGL_FOUND})
|
||||
if (${GLUT_FOUND})
|
||||
# Add target for SobelFilter
|
||||
add_executable(SobelFilter SobelFilter.cpp SobelFilter_kernels.cu)
|
||||
|
||||
target_compile_options(SobelFilter PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(SobelFilter PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(SobelFilter PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(SobelFilter PUBLIC
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
${GLUT_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(SobelFilter
|
||||
${OPENGL_LIBRARIES}
|
||||
${GLUT_LIBRARIES}
|
||||
)
|
||||
|
||||
add_custom_command(TARGET SobelFilter POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(SobelFilter
|
||||
${PC_GLUT_LIBRARY_DIRS}/freeglut.lib
|
||||
${PC_GLUT_LIBRARY_DIRS}/${GLEW_LIB_NAME}.lib
|
||||
)
|
||||
|
||||
add_custom_command(TARGET SobelFilter
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/win64/$<CONFIGURATION>/freeglut.dll
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
|
||||
add_custom_command(TARGET SobelFilter
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
@@ -82,14 +66,11 @@ if(${OpenGL_FOUND})
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
endif()
|
||||
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
else()
|
||||
message(STATUS "GLUT not found - will not build sample 'SobelFilter'")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "OpenGL not found - will not build sample 'SobelFilter'")
|
||||
endif()
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,38 +1,29 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(SobolQRNG LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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 SobolQRNG
|
||||
add_executable(SobolQRNG sobol_gold.cpp sobol_gpu.cu sobol_primitives.cpp sobol.cpp)
|
||||
|
||||
target_compile_options(SobolQRNG PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(SobolQRNG PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(SobolQRNG PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(SobolQRNG PRIVATE
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,22 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(bicubicTexture LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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)
|
||||
|
||||
if(WIN32)
|
||||
@@ -33,49 +29,37 @@ endif()
|
||||
find_package(OpenGL)
|
||||
find_package(GLUT)
|
||||
|
||||
# Source file
|
||||
if(${OpenGL_FOUND})
|
||||
if (${GLUT_FOUND})
|
||||
# Add target for bicubicTexture
|
||||
add_executable(bicubicTexture bicubicTexture.cpp bicubicTexture_cuda.cu)
|
||||
|
||||
target_compile_options(bicubicTexture PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_options(bicubicTexture PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda;--expt-relaxed-constexpr>)
|
||||
target_compile_features(bicubicTexture PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(bicubicTexture PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(bicubicTexture PUBLIC
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
${GLUT_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(bicubicTexture
|
||||
${OPENGL_LIBRARIES}
|
||||
${GLUT_LIBRARIES}
|
||||
)
|
||||
|
||||
# Copy data files to the output directory
|
||||
add_custom_command(TARGET bicubicTexture POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(bicubicTexture
|
||||
${PC_GLUT_LIBRARY_DIRS}/freeglut.lib
|
||||
${PC_GLUT_LIBRARY_DIRS}/${GLEW_LIB_NAME}.lib
|
||||
)
|
||||
|
||||
add_custom_command(TARGET bicubicTexture
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/win64/$<CONFIGURATION>/freeglut.dll
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
|
||||
add_custom_command(TARGET bicubicTexture
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
@@ -83,14 +67,11 @@ if(${OpenGL_FOUND})
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
endif()
|
||||
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
else()
|
||||
message(STATUS "GLUT not found - will not build sample 'bicubicTexture'")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "OpenGL not found - will not build sample 'bicubicTexture'")
|
||||
endif()
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,22 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(bilateralFilter LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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)
|
||||
|
||||
if(WIN32)
|
||||
@@ -33,49 +29,37 @@ endif()
|
||||
find_package(OpenGL)
|
||||
find_package(GLUT)
|
||||
|
||||
# Source file
|
||||
if(${OpenGL_FOUND})
|
||||
if (${GLUT_FOUND})
|
||||
# Add target for bilateralFilter
|
||||
add_executable(bilateralFilter bilateralFilter.cpp bilateralFilter_cpu.cpp bilateral_kernel.cu bmploader.cpp)
|
||||
|
||||
target_compile_options(bilateralFilter PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(bilateralFilter PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(bilateralFilter PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_compile_options(bilateralFilter PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
target_compile_features(bilateralFilter PRIVATE cxx_std_17 cuda_std_17)
|
||||
target_include_directories(bilateralFilter PUBLIC
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
${GLUT_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(bilateralFilter
|
||||
${OPENGL_LIBRARIES}
|
||||
${GLUT_LIBRARIES}
|
||||
)
|
||||
|
||||
# Copy data files to the output directory
|
||||
add_custom_command(TARGET bilateralFilter POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(bilateralFilter
|
||||
${PC_GLUT_LIBRARY_DIRS}/freeglut.lib
|
||||
${PC_GLUT_LIBRARY_DIRS}/${GLEW_LIB_NAME}.lib
|
||||
)
|
||||
|
||||
add_custom_command(TARGET bilateralFilter
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/win64/$<CONFIGURATION>/freeglut.dll
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
|
||||
add_custom_command(TARGET bilateralFilter
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
@@ -83,15 +67,11 @@ target_compile_features(bilateralFilter PRIVATE cxx_std_17 cuda_std_17)
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
else()
|
||||
message(STATUS "GLUT not found - will not build sample 'bilateralFilter'")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "OpenGL not found - will not build sample 'bilateralFilter'")
|
||||
endif()
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,38 +1,29 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(binomialOptions LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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 binomialOptions
|
||||
add_executable(binomialOptions binomialOptions.cpp binomialOptions_gold.cpp binomialOptions_kernel.cu)
|
||||
|
||||
target_compile_options(binomialOptions PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(binomialOptions PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(binomialOptions PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(binomialOptions PUBLIC
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,63 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
project(binomialOptions_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 target for binomialOptions_nvrtc
|
||||
add_executable(binomialOptions_nvrtc binomialOptions.cpp binomialOptions_gold.cpp binomialOptions_gpu.cpp)
|
||||
|
||||
target_compile_options(binomialOptions_nvrtc PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(binomialOptions_nvrtc PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(binomialOptions_nvrtc PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_link_libraries(binomialOptions_nvrtc PRIVATE
|
||||
CUDA::nvrtc
|
||||
CUDA::cuda_driver
|
||||
)
|
||||
|
||||
# Copy kernel to the output directory
|
||||
add_custom_command(TARGET binomialOptions_nvrtc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/binomialOptions_kernel.cu ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
# Copy header to the output directory
|
||||
add_custom_command(TARGET binomialOptions_nvrtc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common_gpu_header.h ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
# Copy header to the output directory
|
||||
add_custom_command(TARGET binomialOptions_nvrtc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/binomialOptions_common.h ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
# Copy header to the output directory
|
||||
add_custom_command(TARGET binomialOptions_nvrtc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/realtype.h ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
@@ -1,39 +0,0 @@
|
||||
# binomialOptions_nvrtc - Binomial Option Pricing with libNVRTC
|
||||
|
||||
## Description
|
||||
|
||||
This sample evaluates fair call price for a given set of European options under binomial model. This sample makes use of NVRTC for Runtime Compilation.
|
||||
|
||||
## Key Concepts
|
||||
|
||||
Computational Finance, 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, cuModuleGetGlobal, cuCtxSynchronize, 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,198 +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 sample evaluates fair call price for a
|
||||
* given set of European options under binomial model.
|
||||
* See supplied whitepaper for more explanations.
|
||||
*/
|
||||
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
#include <helper_functions.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "binomialOptions_common.h"
|
||||
#include "realtype.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Black-Scholes formula for binomial tree results validation
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" void BlackScholesCall(real &callResult, TOptionData optionData);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Process single option on CPU
|
||||
// Note that CPU code is for correctness testing only and not for benchmarking.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" void binomialOptionsCPU(real &callResult, TOptionData optionData);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Process an array of OptN options on GPU
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" void binomialOptionsGPU(real *callValue, TOptionData *optionData, int optN, int argc, char **argv);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Helper function, returning uniformly distributed
|
||||
// random float in [low, high] range
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
real randData(real low, real high)
|
||||
{
|
||||
real t = (real)rand() / (real)RAND_MAX;
|
||||
return ((real)1.0 - t) * low + t * high;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Main program
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("[%s] - Starting...\n", argv[0]);
|
||||
|
||||
const int OPT_N = MAX_OPTIONS;
|
||||
|
||||
TOptionData optionData[MAX_OPTIONS];
|
||||
real callValueBS[MAX_OPTIONS], callValueGPU[MAX_OPTIONS], callValueCPU[MAX_OPTIONS];
|
||||
|
||||
real sumDelta, sumRef, gpuTime, errorVal;
|
||||
|
||||
StopWatchInterface *hTimer = NULL;
|
||||
|
||||
int i;
|
||||
|
||||
sdkCreateTimer(&hTimer);
|
||||
|
||||
printf("Generating input data...\n");
|
||||
|
||||
// Generate options set
|
||||
srand(123);
|
||||
|
||||
for (i = 0; i < OPT_N; i++) {
|
||||
optionData[i].S = randData(5.0f, 30.0f);
|
||||
optionData[i].X = randData(1.0f, 100.0f);
|
||||
optionData[i].T = randData(0.25f, 10.0f);
|
||||
optionData[i].R = 0.06f;
|
||||
optionData[i].V = 0.10f;
|
||||
|
||||
BlackScholesCall(callValueBS[i], optionData[i]);
|
||||
}
|
||||
|
||||
printf("Running GPU binomial tree...\n");
|
||||
|
||||
sdkResetTimer(&hTimer);
|
||||
sdkStartTimer(&hTimer);
|
||||
|
||||
binomialOptionsGPU(callValueGPU, optionData, OPT_N, argc, argv);
|
||||
|
||||
sdkStopTimer(&hTimer);
|
||||
|
||||
gpuTime = sdkGetTimerValue(&hTimer);
|
||||
|
||||
printf("Options count : %i \n", OPT_N);
|
||||
printf("Time steps : %i \n", NUM_STEPS);
|
||||
printf("binomialOptionsGPU() time: %f msec\n", gpuTime);
|
||||
printf("Options per second : %f \n", OPT_N / (gpuTime * 0.001));
|
||||
|
||||
printf("Running CPU binomial tree...\n");
|
||||
|
||||
for (i = 0; i < OPT_N; i++) {
|
||||
binomialOptionsCPU(callValueCPU[i], optionData[i]);
|
||||
}
|
||||
|
||||
printf("Comparing the results...\n");
|
||||
|
||||
sumDelta = 0;
|
||||
sumRef = 0;
|
||||
printf("GPU binomial vs. Black-Scholes\n");
|
||||
|
||||
for (i = 0; i < OPT_N; i++) {
|
||||
sumDelta += fabs(callValueBS[i] - callValueGPU[i]);
|
||||
sumRef += fabs(callValueBS[i]);
|
||||
}
|
||||
|
||||
if (sumRef > 1E-5) {
|
||||
printf("L1 norm: %E\n", (double)(sumDelta / sumRef));
|
||||
}
|
||||
else {
|
||||
printf("Avg. diff: %E\n", (double)(sumDelta / (real)OPT_N));
|
||||
}
|
||||
|
||||
printf("CPU binomial vs. Black-Scholes\n");
|
||||
sumDelta = 0;
|
||||
sumRef = 0;
|
||||
|
||||
for (i = 0; i < OPT_N; i++) {
|
||||
sumDelta += fabs(callValueBS[i] - callValueCPU[i]);
|
||||
sumRef += fabs(callValueBS[i]);
|
||||
}
|
||||
|
||||
if (sumRef > 1E-5) {
|
||||
printf("L1 norm: %E\n", sumDelta / sumRef);
|
||||
}
|
||||
else {
|
||||
printf("Avg. diff: %E\n", (double)(sumDelta / (real)OPT_N));
|
||||
}
|
||||
|
||||
printf("CPU binomial vs. GPU binomial\n");
|
||||
sumDelta = 0;
|
||||
sumRef = 0;
|
||||
|
||||
for (i = 0; i < OPT_N; i++) {
|
||||
sumDelta += fabs(callValueGPU[i] - callValueCPU[i]);
|
||||
sumRef += callValueCPU[i];
|
||||
}
|
||||
|
||||
if (sumRef > 1E-5) {
|
||||
printf("L1 norm: %E\n", errorVal = sumDelta / sumRef);
|
||||
}
|
||||
else {
|
||||
printf("Avg. diff: %E\n", (double)(sumDelta / (real)OPT_N));
|
||||
}
|
||||
|
||||
printf("Shutting down...\n");
|
||||
|
||||
sdkDeleteTimer(&hTimer);
|
||||
|
||||
printf("\nNOTE: The CUDA Samples are not meant for performance measurements. "
|
||||
"Results may vary when GPU Boost is enabled.\n\n");
|
||||
|
||||
if (errorVal > 5e-4) {
|
||||
printf("Test failed!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test passed\n");
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
@@ -1,54 +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 BINOMIALOPTIONS_COMMON_H
|
||||
#define BINOMIALOPTIONS_COMMON_H
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Global types
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float S;
|
||||
float X;
|
||||
float T;
|
||||
float R;
|
||||
float V;
|
||||
} TOptionData;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Global parameters
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Number of time steps
|
||||
#define NUM_STEPS 2048
|
||||
|
||||
// Max option batch size
|
||||
#define MAX_OPTIONS 1024
|
||||
|
||||
#endif
|
||||
@@ -1,132 +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 <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "binomialOptions_common.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Polynomial approximation of cumulative normal distribution function
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static double CND(double d)
|
||||
{
|
||||
const double A1 = 0.31938153;
|
||||
const double A2 = -0.356563782;
|
||||
const double A3 = 1.781477937;
|
||||
const double A4 = -1.821255978;
|
||||
const double A5 = 1.330274429;
|
||||
const double RSQRT2PI = 0.39894228040143267793994605993438;
|
||||
|
||||
double K = 1.0 / (1.0 + 0.2316419 * fabs(d));
|
||||
|
||||
double cnd = RSQRT2PI * exp(-0.5 * d * d) * (K * (A1 + K * (A2 + K * (A3 + K * (A4 + K * A5)))));
|
||||
|
||||
if (d > 0)
|
||||
cnd = 1.0 - cnd;
|
||||
|
||||
return cnd;
|
||||
}
|
||||
|
||||
extern "C" void BlackScholesCall(float &callResult, TOptionData optionData)
|
||||
{
|
||||
double S = optionData.S;
|
||||
double X = optionData.X;
|
||||
double T = optionData.T;
|
||||
double R = optionData.R;
|
||||
double V = optionData.V;
|
||||
double sqrtT = sqrt(T);
|
||||
|
||||
double d1 = (log(S / X) + (R + 0.5 * V * V) * T) / (V * sqrtT);
|
||||
double d2 = d1 - V * sqrtT;
|
||||
|
||||
double CNDD1 = CND(d1);
|
||||
double CNDD2 = CND(d2);
|
||||
|
||||
// Calculate Call and Put simultaneously
|
||||
double expRT = exp(-R * T);
|
||||
|
||||
callResult = (float)(S * CNDD1 - X * expRT * CNDD2);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Process an array of OptN options on CPU
|
||||
// Note that CPU code is for correctness testing only and not for benchmarking.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static double expiryCallValue(double S, double X, double vDt, int i)
|
||||
{
|
||||
double d = S * exp(vDt * (2.0 * i - NUM_STEPS)) - X;
|
||||
return (d > 0) ? d : 0;
|
||||
}
|
||||
|
||||
extern "C" void binomialOptionsCPU(float &callResult, TOptionData optionData)
|
||||
{
|
||||
static double Call[NUM_STEPS + 1];
|
||||
const double S = optionData.S;
|
||||
const double X = optionData.X;
|
||||
const double T = optionData.T;
|
||||
const double R = optionData.R;
|
||||
const double V = optionData.V;
|
||||
|
||||
const double dt = T / (double)NUM_STEPS;
|
||||
const double vDt = V * sqrt(dt);
|
||||
const double rDt = R * dt;
|
||||
|
||||
// Per-step interest and discount factors
|
||||
const double If = exp(rDt);
|
||||
const double Df = exp(-rDt);
|
||||
|
||||
// Values and pseudoprobabilities of upward and downward moves
|
||||
const double u = exp(vDt);
|
||||
const double d = exp(-vDt);
|
||||
const double pu = (If - d) / (u - d);
|
||||
const double pd = 1.0 - pu;
|
||||
const double puByDf = pu * Df;
|
||||
const double pdByDf = pd * Df;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Compute values at expiration date:
|
||||
// call option value at period end is V(T) = S(T) - X
|
||||
// if S(T) is greater than X, or zero otherwise.
|
||||
// The computation is similar for put options.
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
for (int i = 0; i <= NUM_STEPS; i++)
|
||||
Call[i] = expiryCallValue(S, X, vDt, i);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Walk backwards up binomial tree
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
for (int i = NUM_STEPS; i > 0; i--)
|
||||
for (int j = 0; j <= i - 1; j++)
|
||||
Call[j] = puByDf * Call[j + 1] + pdByDf * Call[j];
|
||||
|
||||
callResult = (float)Call[0];
|
||||
}
|
||||
@@ -1,132 +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.
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Global types and parameters
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmath>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Other helpers
|
||||
#include <helper_cuda.h>
|
||||
#include <nvrtc_helper.h>
|
||||
|
||||
// CUDA runtime
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#include "binomialOptions_common.h"
|
||||
#include "common_gpu_header.h"
|
||||
#include "realtype.h"
|
||||
|
||||
|
||||
// Preprocessed input option data
|
||||
typedef struct
|
||||
{
|
||||
real S;
|
||||
real X;
|
||||
real vDt;
|
||||
real puByDf;
|
||||
real pdByDf;
|
||||
|
||||
} __TOptionData;
|
||||
|
||||
static bool moduleLoaded = false;
|
||||
char *cubin, *kernel_file;
|
||||
size_t cubinSize;
|
||||
CUmodule module;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Host-side interface to GPU binomialOptions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" void binomialOptionsGPU(real *callValue, TOptionData *optionData, int optN, int argc, char **argv)
|
||||
{
|
||||
if (!moduleLoaded) {
|
||||
kernel_file = sdkFindFilePath("binomialOptions_kernel.cu", argv[0]);
|
||||
compileFileToCUBIN(kernel_file, argc, argv, &cubin, &cubinSize, 0);
|
||||
module = loadCUBIN(cubin, argc, argv);
|
||||
moduleLoaded = true;
|
||||
}
|
||||
|
||||
__TOptionData h_OptionData[MAX_OPTIONS];
|
||||
|
||||
for (int i = 0; i < optN; i++) {
|
||||
const real T = optionData[i].T;
|
||||
const real R = optionData[i].R;
|
||||
const real V = optionData[i].V;
|
||||
|
||||
const real dt = T / (real)NUM_STEPS;
|
||||
const real vDt = V * sqrt(dt);
|
||||
const real rDt = R * dt;
|
||||
// Per-step interest and discount factors
|
||||
const real If = exp(rDt);
|
||||
const real Df = exp(-rDt);
|
||||
// Values and pseudoprobabilities of upward and downward moves
|
||||
const real u = exp(vDt);
|
||||
const real d = exp(-vDt);
|
||||
const real pu = (If - d) / (u - d);
|
||||
const real pd = (real)1.0 - pu;
|
||||
const real puByDf = pu * Df;
|
||||
const real pdByDf = pd * Df;
|
||||
|
||||
h_OptionData[i].S = (real)optionData[i].S;
|
||||
h_OptionData[i].X = (real)optionData[i].X;
|
||||
h_OptionData[i].vDt = (real)vDt;
|
||||
h_OptionData[i].puByDf = (real)puByDf;
|
||||
h_OptionData[i].pdByDf = (real)pdByDf;
|
||||
}
|
||||
|
||||
CUfunction kernel_addr;
|
||||
checkCudaErrors(cuModuleGetFunction(&kernel_addr, module, "binomialOptionsKernel"));
|
||||
|
||||
CUdeviceptr d_OptionData;
|
||||
checkCudaErrors(cuModuleGetGlobal(&d_OptionData, NULL, module, "d_OptionData"));
|
||||
checkCudaErrors(cuMemcpyHtoD(d_OptionData, h_OptionData, optN * sizeof(__TOptionData)));
|
||||
|
||||
dim3 cudaBlockSize(128, 1, 1);
|
||||
dim3 cudaGridSize(optN, 1, 1);
|
||||
|
||||
checkCudaErrors(cuLaunchKernel(kernel_addr,
|
||||
cudaGridSize.x,
|
||||
cudaGridSize.y,
|
||||
cudaGridSize.z, /* grid dim */
|
||||
cudaBlockSize.x,
|
||||
cudaBlockSize.y,
|
||||
cudaBlockSize.z, /* block dim */
|
||||
0,
|
||||
0, /* shared mem, stream */
|
||||
NULL, /* arguments */
|
||||
0));
|
||||
|
||||
checkCudaErrors(cuCtxSynchronize());
|
||||
|
||||
CUdeviceptr d_CallValue;
|
||||
checkCudaErrors(cuModuleGetGlobal(&d_CallValue, NULL, module, "d_CallValue"));
|
||||
checkCudaErrors(cuMemcpyDtoH(callValue, d_CallValue, optN * sizeof(real)));
|
||||
}
|
||||
@@ -1,110 +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 "binomialOptions_common.h"
|
||||
#include "common_gpu_header.h"
|
||||
#include "realtype.h"
|
||||
|
||||
// Preprocessed input option data
|
||||
typedef struct
|
||||
{
|
||||
real S;
|
||||
real X;
|
||||
real vDt;
|
||||
real puByDf;
|
||||
real pdByDf;
|
||||
} __TOptionData;
|
||||
static __constant__ __TOptionData d_OptionData[MAX_OPTIONS];
|
||||
__device__ real d_CallValue[MAX_OPTIONS];
|
||||
|
||||
#define THREADBLOCK_SIZE 128
|
||||
#define ELEMS_PER_THREAD (NUM_STEPS / THREADBLOCK_SIZE)
|
||||
#if NUM_STEPS % THREADBLOCK_SIZE
|
||||
#error Bad constants
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Overloaded shortcut functions for different precision modes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef DOUBLE_PRECISION
|
||||
__device__ inline float expiryCallValue(float S, float X, float vDt, int i)
|
||||
{
|
||||
float d = S * __expf(vDt * (2.0f * i - NUM_STEPS)) - X;
|
||||
return (d > 0.0F) ? d : 0.0F;
|
||||
}
|
||||
|
||||
#else
|
||||
__device__ inline double expiryCallValue(double S, double X, double vDt, int i)
|
||||
{
|
||||
double d = S * exp(vDt * (2.0 * i - NUM_STEPS)) - X;
|
||||
return (d > 0.0) ? d : 0.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// GPU kernel
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
extern "C" __global__ void binomialOptionsKernel()
|
||||
{
|
||||
__shared__ real call_exchange[THREADBLOCK_SIZE + 1];
|
||||
|
||||
const int tid = threadIdx.x;
|
||||
const real S = d_OptionData[blockIdx.x].S;
|
||||
const real X = d_OptionData[blockIdx.x].X;
|
||||
const real vDt = d_OptionData[blockIdx.x].vDt;
|
||||
const real puByDf = d_OptionData[blockIdx.x].puByDf;
|
||||
const real pdByDf = d_OptionData[blockIdx.x].pdByDf;
|
||||
|
||||
real call[ELEMS_PER_THREAD + 1];
|
||||
#pragma unroll
|
||||
for (int i = 0; i < ELEMS_PER_THREAD; ++i)
|
||||
call[i] = expiryCallValue(S, X, vDt, tid * ELEMS_PER_THREAD + i);
|
||||
|
||||
if (tid == 0)
|
||||
call_exchange[THREADBLOCK_SIZE] = expiryCallValue(S, X, vDt, NUM_STEPS);
|
||||
|
||||
int final_it = max(0, tid * ELEMS_PER_THREAD - 1);
|
||||
|
||||
#pragma unroll 16
|
||||
for (int i = NUM_STEPS; i > 0; --i) {
|
||||
call_exchange[tid] = call[0];
|
||||
__syncthreads();
|
||||
call[ELEMS_PER_THREAD] = call_exchange[tid + 1];
|
||||
__syncthreads();
|
||||
|
||||
if (i > final_it) {
|
||||
#pragma unroll
|
||||
for (int j = 0; j < ELEMS_PER_THREAD; ++j)
|
||||
call[j] = puByDf * call[j + 1] + pdByDf * call[j];
|
||||
}
|
||||
}
|
||||
|
||||
if (tid == 0) {
|
||||
d_CallValue[blockIdx.x] = call[0];
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2015 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* Please refer to the NVIDIA end user license agreement (EULA) associated
|
||||
* with this source code for terms and conditions that govern your use of
|
||||
* this software. Any use, reproduction, disclosure, or distribution of
|
||||
* this software and related documentation outside the terms of the EULA
|
||||
* is strictly prohibited.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(__COMMON_GPU_HEADER_H)
|
||||
#define __COMMON_GPU_HEADER_H
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Internal GPU-side constants and data structures
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define TIME_STEPS 16
|
||||
|
||||
#define CACHE_DELTA (2 * TIME_STEPS)
|
||||
|
||||
#define CACHE_SIZE (256)
|
||||
|
||||
#define CACHE_STEP (CACHE_SIZE - CACHE_DELTA)
|
||||
|
||||
#if NUM_STEPS % CACHE_DELTA
|
||||
#error Bad constants
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,41 +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 REALTYPE_H
|
||||
#define REALTYPE_H
|
||||
|
||||
// To use double precision uncomment the macro DOUBLE_PRECISION below, default
|
||||
// is single precision.
|
||||
// #define DOUBLE_PRECISION
|
||||
|
||||
#ifndef DOUBLE_PRECISION
|
||||
typedef float real;
|
||||
#else
|
||||
typedef double real;
|
||||
#endif
|
||||
|
||||
#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,34 +1,26 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(convolutionFFT2D LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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 convolutionFFT2D
|
||||
add_executable(convolutionFFT2D convolutionFFT2D.cu convolutionFFT2D_gold.cpp main.cpp)
|
||||
|
||||
target_compile_options(convolutionFFT2D PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(convolutionFFT2D PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(convolutionFFT2D PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(convolutionFFT2D PRIVATE
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
)
|
||||
@@ -37,6 +29,5 @@ target_link_libraries(convolutionFFT2D PUBLIC
|
||||
CUDA::cufft
|
||||
)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,40 +1,31 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(dwtHaar1D LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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 dwtHaar1D
|
||||
add_executable(dwtHaar1D dwtHaar1D.cu)
|
||||
|
||||
target_compile_options(dwtHaar1D PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(dwtHaar1D PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(dwtHaar1D PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
add_custom_command(TARGET dwtHaar1D POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,40 +1,31 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(dxtc LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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 dxtc
|
||||
add_executable(dxtc dxtc.cu)
|
||||
|
||||
target_compile_options(dxtc PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(dxtc PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(dxtc PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
add_custom_command(TARGET dxtc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,34 +1,25 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(fastWalshTransform LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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 fastWalshTransform
|
||||
add_executable(fastWalshTransform fastWalshTransform.cu fastWalshTransform_gold.cpp)
|
||||
|
||||
target_compile_options(fastWalshTransform PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(fastWalshTransform PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(fastWalshTransform PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,22 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(fluidsGL LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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)
|
||||
|
||||
if(WIN32)
|
||||
@@ -33,50 +29,38 @@ endif()
|
||||
find_package(OpenGL)
|
||||
find_package(GLUT)
|
||||
|
||||
# Source file
|
||||
if(${OpenGL_FOUND})
|
||||
if (${GLUT_FOUND})
|
||||
# Add target for fluidsGL
|
||||
add_executable(fluidsGL fluidsGL_kernels.cu fluidsGL.cpp)
|
||||
|
||||
target_compile_options(fluidsGL PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(fluidsGL PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(fluidsGL PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_compile_options(fluidsGL PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
target_compile_features(fluidsGL PRIVATE cxx_std_17 cuda_std_17)
|
||||
target_include_directories(fluidsGL PUBLIC
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
${GLUT_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(fluidsGL
|
||||
${OPENGL_LIBRARIES}
|
||||
${GLUT_LIBRARIES}
|
||||
CUDA::cufft
|
||||
)
|
||||
|
||||
# Copy data files to the output directory
|
||||
add_custom_command(TARGET fluidsGL POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(fluidsGL
|
||||
${PC_GLUT_LIBRARY_DIRS}/freeglut.lib
|
||||
${PC_GLUT_LIBRARY_DIRS}/${GLEW_LIB_NAME}.lib
|
||||
)
|
||||
|
||||
add_custom_command(TARGET fluidsGL
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/win64/$<CONFIGURATION>/freeglut.dll
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
|
||||
add_custom_command(TARGET fluidsGL
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
@@ -84,14 +68,11 @@ target_compile_features(fluidsGL PRIVATE cxx_std_17 cuda_std_17)
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
endif()
|
||||
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
else()
|
||||
message(STATUS "GLUT not found - will not build sample 'fluidsGL'")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "OpenGL not found - will not build sample 'fluidsGL'")
|
||||
endif()
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,90 +1,77 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(marchingCubes LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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)
|
||||
|
||||
if(WIN32)
|
||||
set(PC_GLUT_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../Common")
|
||||
set(PC_GLUT_LIBRARY_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../Common/lib/x64")
|
||||
# The GLEW library built on Windows on Arm system is named as glew32.lib/glew32.dll by default.
|
||||
if(EXISTS "${PC_GLUT_LIBRARY_DIRS}/glew32.lib")
|
||||
set(GLEW_LIB_NAME "glew32")
|
||||
else()
|
||||
set(GLEW_LIB_NAME "glew64")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(OpenGL)
|
||||
find_package(GLUT)
|
||||
|
||||
# Source file
|
||||
if(${OpenGL_FOUND})
|
||||
if (${GLUT_FOUND})
|
||||
# Add target for marchingCubes
|
||||
add_executable(marchingCubes marchingCubes_kernel.cu marchingCubes.cpp)
|
||||
|
||||
target_compile_options(marchingCubes PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(marchingCubes PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(marchingCubes PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_compile_options(marchingCubes PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda;--expt-relaxed-constexpr>)
|
||||
target_compile_features(marchingCubes PRIVATE cxx_std_17 cuda_std_17)
|
||||
target_include_directories(marchingCubes PUBLIC
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
${GLUT_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(marchingCubes
|
||||
${OPENGL_LIBRARIES}
|
||||
${GLUT_LIBRARIES}
|
||||
)
|
||||
|
||||
# Copy data files to the output directory
|
||||
add_custom_command(TARGET marchingCubes POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(marchingCubes
|
||||
${PC_GLUT_LIBRARY_DIRS}/freeglut.lib
|
||||
${PC_GLUT_LIBRARY_DIRS}/glew64.lib
|
||||
${PC_GLUT_LIBRARY_DIRS}/${GLEW_LIB_NAME}.lib
|
||||
)
|
||||
|
||||
add_custom_command(TARGET marchingCubes
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/win64/$<CONFIGURATION>/freeglut.dll
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
|
||||
add_custom_command(TARGET marchingCubes
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/win64/$<CONFIGURATION>/glew64.dll
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/win64/$<CONFIGURATION>/${GLEW_LIB_NAME}.dll
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
endif()
|
||||
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
else()
|
||||
message(STATUS "GLUT not found - will not build sample 'marchingCubes'")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "OpenGL not found - will not build sample 'marchingCubes'")
|
||||
endif()
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -431,6 +431,9 @@ int main(int argc, char **argv)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void initMC(int argc, char **argv)
|
||||
{
|
||||
// Enlarge the per-thread device stack: under -G the CUB warpspeed exclusive_scan is not inlined and its deep call chain overflows the default 1KB stack.
|
||||
checkCudaErrors(cudaDeviceSetLimit(cudaLimitStackSize, 8192));
|
||||
|
||||
// parse command line arguments
|
||||
int 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,22 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(nbody LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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)
|
||||
|
||||
if(WIN32)
|
||||
@@ -33,42 +29,31 @@ endif()
|
||||
find_package(OpenGL)
|
||||
find_package(GLUT)
|
||||
|
||||
# Source file
|
||||
if(${OpenGL_FOUND})
|
||||
if (${GLUT_FOUND})
|
||||
# Add target for nbody
|
||||
add_executable(nbody bodysystemcuda.cu render_particles.cpp nbody.cpp)
|
||||
|
||||
target_compile_options(nbody PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(nbody PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(nbody PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(nbody PUBLIC
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
${GLUT_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(nbody
|
||||
${OPENGL_LIBRARIES}
|
||||
${GLUT_LIBRARIES}
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(nbody
|
||||
${PC_GLUT_LIBRARY_DIRS}/freeglut.lib
|
||||
${PC_GLUT_LIBRARY_DIRS}/${GLEW_LIB_NAME}.lib
|
||||
)
|
||||
|
||||
add_custom_command(TARGET nbody
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/win64/$<CONFIGURATION>/freeglut.dll
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
|
||||
add_custom_command(TARGET nbody
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
@@ -76,14 +61,11 @@ if(${OpenGL_FOUND})
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
endif()
|
||||
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
else()
|
||||
message(STATUS "GLUT not found - will not build sample 'nbody'")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "OpenGL not found - will not build sample 'nbody'")
|
||||
endif()
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,34 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
project(p2pBandwidthLatencyTest 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 p2pBandwidthLatencyTest
|
||||
add_executable(p2pBandwidthLatencyTest p2pBandwidthLatencyTest.cu)
|
||||
|
||||
target_compile_options(p2pBandwidthLatencyTest PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(p2pBandwidthLatencyTest PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(p2pBandwidthLatencyTest PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
@@ -1,32 +0,0 @@
|
||||
# p2pBandwidthLatencyTest - Peer-to-Peer Bandwidth Latency Test with Multi-GPUs
|
||||
|
||||
## Description
|
||||
|
||||
This application demonstrates the CUDA Peer-To-Peer (P2P) data transfers between pairs of GPUs and computes latency and bandwidth. Tests on GPU pairs using P2P and without P2P are tested.
|
||||
|
||||
## Key Concepts
|
||||
|
||||
Performance Strategies, Asynchronous Data Transfers, Unified Virtual Address Space, Peer to Peer Data Transfers, Multi-GPU
|
||||
|
||||
## 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)
|
||||
cudaSetDevice, cudaEventDestroy, cudaOccupancyMaxPotentialBlockSize, cudaCheckError, cudaFreeHost, cudaGetDeviceCount, cudaDeviceCanAccessPeer, cudaStreamCreateWithFlags, cudaStreamDestroy, cudaGetLastError, cudaMemset, cudaStreamWaitEvent, cudaEventElapsedTime, cudaEventCreate, cudaHostAlloc, cudaFree, cudaGetErrorString, cudaMemcpyPeerAsync, cudaDeviceDisablePeerAccess, cudaEventRecord, cudaStreamSynchronize, cudaDeviceEnablePeerAccess, cudaMalloc, cudaGetDeviceProperties
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Download and install the [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
||||
|
||||
## References (for more details)
|
||||
@@ -1,836 +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 <cstdio>
|
||||
#include <helper_cuda.h>
|
||||
#include <helper_timer.h>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const char *sSampleName = "P2P (Peer-to-Peer) GPU Bandwidth Latency Test";
|
||||
|
||||
typedef enum {
|
||||
P2P_WRITE = 0,
|
||||
P2P_READ = 1,
|
||||
} P2PDataTransfer;
|
||||
|
||||
typedef enum {
|
||||
CE = 0,
|
||||
SM = 1,
|
||||
} P2PEngine;
|
||||
|
||||
P2PEngine p2p_mechanism = CE; // By default use Copy Engine
|
||||
|
||||
// Macro for checking cuda errors following a cuda launch or api call
|
||||
#define cudaCheckError() \
|
||||
{ \
|
||||
cudaError_t e = cudaGetLastError(); \
|
||||
if (e != cudaSuccess) { \
|
||||
printf("Cuda failure %s:%d: '%s'\n", __FILE__, __LINE__, cudaGetErrorString(e)); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} \
|
||||
}
|
||||
__global__ void delay(volatile int *flag, unsigned long long timeout_clocks = 10000000)
|
||||
{
|
||||
// Wait until the application notifies us that it has completed queuing up the
|
||||
// experiment, or timeout and exit, allowing the application to make progress
|
||||
long long int start_clock, sample_clock;
|
||||
start_clock = clock64();
|
||||
|
||||
while (!*flag) {
|
||||
sample_clock = clock64();
|
||||
|
||||
if (sample_clock - start_clock > timeout_clocks) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This kernel is for demonstration purposes only, not a performant kernel for
|
||||
// p2p transfers.
|
||||
__global__ void copyp2p(int4 *__restrict__ dest, int4 const *__restrict__ src, size_t num_elems)
|
||||
{
|
||||
size_t globalId = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
size_t gridSize = blockDim.x * gridDim.x;
|
||||
|
||||
#pragma unroll(5)
|
||||
for (size_t i = globalId; i < num_elems; i += gridSize) {
|
||||
dest[i] = src[i];
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Print help screen
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void printHelp(void)
|
||||
{
|
||||
printf("Usage: p2pBandwidthLatencyTest [OPTION]...\n");
|
||||
printf("Tests bandwidth/latency of GPU pairs using P2P and without P2P\n");
|
||||
printf("\n");
|
||||
|
||||
printf("Options:\n");
|
||||
printf("--help\t\tDisplay this help menu\n");
|
||||
printf("--p2p_read\tUse P2P reads for data transfers between GPU pairs and show "
|
||||
"corresponding results.\n \t\tDefault used is P2P write operation.\n");
|
||||
printf("--sm_copy Use SM intiated p2p transfers instead of Copy Engine\n");
|
||||
printf("--numElems=<NUM_OF_INT_ELEMS> Number of integer elements to be used in p2p copy.\n");
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Detect if cudaMemcpyPeerAsync will automatically fall back to
|
||||
// host-staged copies when P2P is disabled.
|
||||
//
|
||||
// We probe a single representative pair (device 0 -> device 1).
|
||||
// On a given system, confidential-computing (CC) and security
|
||||
// policies are uniform across GPUs, so if this pair is blocked
|
||||
// with cudaErrorNotSupported in P2P-off mode, it is reasonable
|
||||
// to assume all cross-GPU pairs behave the same.
|
||||
//
|
||||
// For a production application that must handle heterogeneous
|
||||
// environments, users may want to probe all device pairs.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
bool detectFallback(int numGPUs)
|
||||
{
|
||||
if (numGPUs <= 1)
|
||||
return false;
|
||||
|
||||
cudaSetDevice(0);
|
||||
int *tmp0 = nullptr, *tmp1 = nullptr;
|
||||
cudaStream_t s;
|
||||
cudaStreamCreateWithFlags(&s, cudaStreamNonBlocking);
|
||||
|
||||
size_t testElems = 1;
|
||||
cudaMalloc(&tmp0, testElems * sizeof(int));
|
||||
cudaSetDevice(1);
|
||||
cudaMalloc(&tmp1, testElems * sizeof(int));
|
||||
cudaCheckError();
|
||||
|
||||
// Explicitly ensure P2P is disabled for this test
|
||||
// (Clear any pre-existing P2P access if it happens to be enabled)
|
||||
cudaSetDevice(0);
|
||||
cudaDeviceDisablePeerAccess(1);
|
||||
cudaGetLastError(); // Clear error if peer access was not enabled
|
||||
|
||||
cudaSetDevice(1);
|
||||
cudaDeviceDisablePeerAccess(0);
|
||||
cudaGetLastError(); // Clear error if peer access was not enabled
|
||||
|
||||
bool needsFallback = false;
|
||||
cudaError_t testErr = cudaMemcpyPeerAsync(tmp1, 1, tmp0, 0, testElems * sizeof(int), s);
|
||||
|
||||
if (testErr == cudaErrorPeerAccessNotEnabled || testErr == cudaErrorNotSupported) {
|
||||
needsFallback = true;
|
||||
printf("Note: cudaMemcpyPeerAsync reported '%s' - will use host-mediated copy when P2P is disabled\n",
|
||||
cudaGetErrorString(testErr));
|
||||
cudaGetLastError();
|
||||
}
|
||||
|
||||
cudaStreamSynchronize(s);
|
||||
cudaFree(tmp0);
|
||||
cudaFree(tmp1);
|
||||
cudaStreamDestroy(s);
|
||||
cudaCheckError();
|
||||
|
||||
return needsFallback;
|
||||
}
|
||||
|
||||
void checkP2Paccess(int numGPUs)
|
||||
{
|
||||
for (int i = 0; i < numGPUs; i++) {
|
||||
cudaSetDevice(i);
|
||||
cudaCheckError();
|
||||
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
int access;
|
||||
if (i != j) {
|
||||
cudaDeviceCanAccessPeer(&access, i, j);
|
||||
cudaCheckError();
|
||||
printf("Device=%d %s Access Peer Device=%d\n", i, access ? "CAN" : "CANNOT", j);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n***NOTE: In case a device doesn't have P2P access to other one, it "
|
||||
"falls back to normal memcopy procedure.\nSo you can see lesser "
|
||||
"Bandwidth (GB/s) and unstable Latency (us) in those cases.\n\n");
|
||||
}
|
||||
|
||||
void performP2PCopy(int *dest,
|
||||
int destDevice,
|
||||
int *src,
|
||||
int srcDevice,
|
||||
int num_elems,
|
||||
int repeat,
|
||||
bool p2paccess,
|
||||
cudaStream_t streamToRun,
|
||||
bool useFallback,
|
||||
int *hostBuffer)
|
||||
{
|
||||
int blockSize = 0;
|
||||
int numBlocks = 0;
|
||||
|
||||
cudaOccupancyMaxPotentialBlockSize(&numBlocks, &blockSize, copyp2p);
|
||||
cudaCheckError();
|
||||
|
||||
if (p2p_mechanism == SM && p2paccess) {
|
||||
for (int r = 0; r < repeat; r++) {
|
||||
copyp2p<<<numBlocks, blockSize, 0, streamToRun>>>((int4 *)dest, (int4 *)src, num_elems / 4);
|
||||
}
|
||||
cudaCheckError();
|
||||
}
|
||||
else if (useFallback && srcDevice != destDevice) {
|
||||
// Use host-mediated copy for cross-GPU transfers when cudaMemcpyPeerAsync is not supported
|
||||
for (int r = 0; r < repeat; r++) {
|
||||
cudaMemcpyAsync(hostBuffer, src, sizeof(int) * num_elems, cudaMemcpyDeviceToHost, streamToRun);
|
||||
cudaMemcpyAsync(dest, hostBuffer, sizeof(int) * num_elems, cudaMemcpyHostToDevice, streamToRun);
|
||||
}
|
||||
cudaCheckError();
|
||||
}
|
||||
else if (useFallback && srcDevice == destDevice) {
|
||||
// Same device copy
|
||||
for (int r = 0; r < repeat; r++) {
|
||||
cudaMemcpyAsync(dest, src, sizeof(int) * num_elems, cudaMemcpyDeviceToDevice, streamToRun);
|
||||
}
|
||||
cudaCheckError();
|
||||
}
|
||||
else {
|
||||
// Use cudaMemcpyPeerAsync
|
||||
for (int r = 0; r < repeat; r++) {
|
||||
cudaMemcpyPeerAsync(dest, destDevice, src, srcDevice, sizeof(int) * num_elems, streamToRun);
|
||||
}
|
||||
cudaCheckError();
|
||||
}
|
||||
}
|
||||
|
||||
void outputBandwidthMatrix(int numElems, int numGPUs, bool p2p, P2PDataTransfer p2p_method, bool needsFallback)
|
||||
{
|
||||
int repeat = 5;
|
||||
volatile int *flag = NULL;
|
||||
vector<int *> buffers(numGPUs);
|
||||
vector<int *> buffersD2D(numGPUs); // buffer for D2D, that is, intra-GPU copy
|
||||
vector<cudaEvent_t> start(numGPUs);
|
||||
vector<cudaEvent_t> stop(numGPUs);
|
||||
vector<cudaStream_t> stream(numGPUs);
|
||||
|
||||
cudaHostAlloc((void **)&flag, sizeof(*flag), cudaHostAllocPortable);
|
||||
cudaCheckError();
|
||||
|
||||
for (int d = 0; d < numGPUs; d++) {
|
||||
cudaSetDevice(d);
|
||||
cudaStreamCreateWithFlags(&stream[d], cudaStreamNonBlocking);
|
||||
cudaMalloc(&buffers[d], numElems * sizeof(int));
|
||||
cudaCheckError();
|
||||
cudaMemset(buffers[d], 0, numElems * sizeof(int));
|
||||
cudaCheckError();
|
||||
cudaMalloc(&buffersD2D[d], numElems * sizeof(int));
|
||||
cudaCheckError();
|
||||
cudaMemset(buffersD2D[d], 0, numElems * sizeof(int));
|
||||
cudaCheckError();
|
||||
cudaEventCreate(&start[d]);
|
||||
cudaCheckError();
|
||||
cudaEventCreate(&stop[d]);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
// Decide if fallback is needed based on global detection result and current test scenario
|
||||
bool useFallback = (!p2p && needsFallback);
|
||||
int *hostBuffer = nullptr;
|
||||
|
||||
if (useFallback) {
|
||||
// Allocate hostBuffer for this function's numElems
|
||||
cudaHostAlloc((void **)&hostBuffer, sizeof(int) * numElems, cudaHostAllocDefault);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
vector<double> bandwidthMatrix(numGPUs * numGPUs);
|
||||
|
||||
for (int i = 0; i < numGPUs; i++) {
|
||||
cudaSetDevice(i);
|
||||
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
int access = 0;
|
||||
if (p2p) {
|
||||
cudaDeviceCanAccessPeer(&access, i, j);
|
||||
if (access) {
|
||||
cudaDeviceEnablePeerAccess(j, 0);
|
||||
cudaCheckError();
|
||||
cudaSetDevice(j);
|
||||
cudaCheckError();
|
||||
cudaDeviceEnablePeerAccess(i, 0);
|
||||
cudaCheckError();
|
||||
cudaSetDevice(i);
|
||||
cudaCheckError();
|
||||
}
|
||||
}
|
||||
|
||||
cudaStreamSynchronize(stream[i]);
|
||||
cudaCheckError();
|
||||
|
||||
// Block the stream until all the work is queued up
|
||||
// DANGER! - cudaMemcpy*Async may infinitely block waiting for
|
||||
// room to push the operation, so keep the number of repeatitions
|
||||
// relatively low. Higher repeatitions will cause the delay kernel
|
||||
// to timeout and lead to unstable results.
|
||||
*flag = 0;
|
||||
delay<<<1, 1, 0, stream[i]>>>(flag);
|
||||
cudaCheckError();
|
||||
cudaEventRecord(start[i], stream[i]);
|
||||
cudaCheckError();
|
||||
|
||||
if (i == j) {
|
||||
// Perform intra-GPU, D2D copies
|
||||
performP2PCopy(
|
||||
buffers[i], i, buffersD2D[i], i, numElems, repeat, access, stream[i], useFallback, hostBuffer);
|
||||
}
|
||||
else {
|
||||
if (p2p_method == P2P_WRITE) {
|
||||
performP2PCopy(
|
||||
buffers[j], j, buffers[i], i, numElems, repeat, access, stream[i], useFallback, hostBuffer);
|
||||
}
|
||||
else {
|
||||
performP2PCopy(
|
||||
buffers[i], i, buffers[j], j, numElems, repeat, access, stream[i], useFallback, hostBuffer);
|
||||
}
|
||||
}
|
||||
cudaCheckError();
|
||||
|
||||
cudaEventRecord(stop[i], stream[i]);
|
||||
cudaCheckError();
|
||||
|
||||
// Release the queued events
|
||||
*flag = 1;
|
||||
cudaStreamSynchronize(stream[i]);
|
||||
cudaCheckError();
|
||||
|
||||
float time_ms;
|
||||
cudaEventElapsedTime(&time_ms, start[i], stop[i]);
|
||||
double time_s = time_ms / 1e3;
|
||||
|
||||
double gb = numElems * sizeof(int) * repeat / (double)1e9;
|
||||
if (i == j) {
|
||||
gb *= 2; // must count both the read and the write here
|
||||
}
|
||||
bandwidthMatrix[i * numGPUs + j] = gb / time_s;
|
||||
if (p2p && access) {
|
||||
cudaDeviceDisablePeerAccess(j);
|
||||
cudaSetDevice(j);
|
||||
cudaDeviceDisablePeerAccess(i);
|
||||
cudaSetDevice(i);
|
||||
cudaCheckError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf(" D\\D");
|
||||
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
printf("%6d ", j);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (int i = 0; i < numGPUs; i++) {
|
||||
printf("%6d ", i);
|
||||
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
printf("%6.02f ", bandwidthMatrix[i * numGPUs + j]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
for (int d = 0; d < numGPUs; d++) {
|
||||
cudaSetDevice(d);
|
||||
cudaFree(buffers[d]);
|
||||
cudaFree(buffersD2D[d]);
|
||||
cudaCheckError();
|
||||
cudaEventDestroy(start[d]);
|
||||
cudaCheckError();
|
||||
cudaEventDestroy(stop[d]);
|
||||
cudaCheckError();
|
||||
cudaStreamDestroy(stream[d]);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
if (hostBuffer) {
|
||||
cudaFreeHost(hostBuffer);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
cudaFreeHost((void *)flag);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
void outputBidirectionalBandwidthMatrix(int numElems, int numGPUs, bool p2p, bool needsFallback)
|
||||
{
|
||||
int repeat = 5;
|
||||
volatile int *flag = NULL;
|
||||
vector<int *> buffers(numGPUs);
|
||||
vector<int *> buffersD2D(numGPUs);
|
||||
vector<cudaEvent_t> start(numGPUs);
|
||||
vector<cudaEvent_t> stop(numGPUs);
|
||||
vector<cudaStream_t> stream0(numGPUs);
|
||||
vector<cudaStream_t> stream1(numGPUs);
|
||||
|
||||
cudaHostAlloc((void **)&flag, sizeof(*flag), cudaHostAllocPortable);
|
||||
cudaCheckError();
|
||||
|
||||
for (int d = 0; d < numGPUs; d++) {
|
||||
cudaSetDevice(d);
|
||||
cudaMalloc(&buffers[d], numElems * sizeof(int));
|
||||
cudaMemset(buffers[d], 0, numElems * sizeof(int));
|
||||
cudaMalloc(&buffersD2D[d], numElems * sizeof(int));
|
||||
cudaMemset(buffersD2D[d], 0, numElems * sizeof(int));
|
||||
cudaCheckError();
|
||||
cudaEventCreate(&start[d]);
|
||||
cudaCheckError();
|
||||
cudaEventCreate(&stop[d]);
|
||||
cudaCheckError();
|
||||
cudaStreamCreateWithFlags(&stream0[d], cudaStreamNonBlocking);
|
||||
cudaCheckError();
|
||||
cudaStreamCreateWithFlags(&stream1[d], cudaStreamNonBlocking);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
// Decide if fallback is needed based on global detection result and current test scenario
|
||||
bool useFallback = (!p2p && needsFallback);
|
||||
int *hostBuffer = nullptr;
|
||||
|
||||
if (useFallback) {
|
||||
// Allocate hostBuffer for this function's numElems
|
||||
cudaHostAlloc((void **)&hostBuffer, sizeof(int) * numElems, cudaHostAllocDefault);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
vector<double> bandwidthMatrix(numGPUs * numGPUs);
|
||||
|
||||
for (int i = 0; i < numGPUs; i++) {
|
||||
cudaSetDevice(i);
|
||||
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
int access = 0;
|
||||
if (p2p) {
|
||||
cudaDeviceCanAccessPeer(&access, i, j);
|
||||
if (access) {
|
||||
cudaSetDevice(i);
|
||||
cudaDeviceEnablePeerAccess(j, 0);
|
||||
cudaCheckError();
|
||||
cudaSetDevice(j);
|
||||
cudaDeviceEnablePeerAccess(i, 0);
|
||||
cudaCheckError();
|
||||
}
|
||||
}
|
||||
|
||||
cudaSetDevice(i);
|
||||
cudaStreamSynchronize(stream0[i]);
|
||||
cudaStreamSynchronize(stream1[j]);
|
||||
cudaCheckError();
|
||||
|
||||
// Block the stream until all the work is queued up
|
||||
// DANGER! - cudaMemcpy*Async may infinitely block waiting for
|
||||
// room to push the operation, so keep the number of repeatitions
|
||||
// relatively low. Higher repeatitions will cause the delay kernel
|
||||
// to timeout and lead to unstable results.
|
||||
*flag = 0;
|
||||
cudaSetDevice(i);
|
||||
// No need to block stream1 since it'll be blocked on stream0's event
|
||||
delay<<<1, 1, 0, stream0[i]>>>(flag);
|
||||
cudaCheckError();
|
||||
|
||||
// Force stream1 not to start until stream0 does, in order to ensure
|
||||
// the events on stream0 fully encompass the time needed for all
|
||||
// operations
|
||||
cudaEventRecord(start[i], stream0[i]);
|
||||
cudaStreamWaitEvent(stream1[j], start[i], 0);
|
||||
|
||||
if (i == j) {
|
||||
// For intra-GPU perform 2 memcopies buffersD2D <-> buffers
|
||||
performP2PCopy(
|
||||
buffers[i], i, buffersD2D[i], i, numElems, repeat, access, stream0[i], useFallback, hostBuffer);
|
||||
performP2PCopy(
|
||||
buffersD2D[i], i, buffers[i], i, numElems, repeat, access, stream1[i], useFallback, hostBuffer);
|
||||
}
|
||||
else {
|
||||
if (access && p2p_mechanism == SM) {
|
||||
cudaSetDevice(j);
|
||||
}
|
||||
performP2PCopy(
|
||||
buffers[i], i, buffers[j], j, numElems, repeat, access, stream1[j], useFallback, hostBuffer);
|
||||
if (access && p2p_mechanism == SM) {
|
||||
cudaSetDevice(i);
|
||||
}
|
||||
performP2PCopy(
|
||||
buffers[j], j, buffers[i], i, numElems, repeat, access, stream0[i], useFallback, hostBuffer);
|
||||
}
|
||||
|
||||
// Notify stream0 that stream1 is complete and record the time of
|
||||
// the total transaction
|
||||
cudaEventRecord(stop[j], stream1[j]);
|
||||
cudaStreamWaitEvent(stream0[i], stop[j], 0);
|
||||
cudaEventRecord(stop[i], stream0[i]);
|
||||
|
||||
// Release the queued operations
|
||||
*flag = 1;
|
||||
cudaStreamSynchronize(stream0[i]);
|
||||
cudaStreamSynchronize(stream1[j]);
|
||||
cudaCheckError();
|
||||
|
||||
float time_ms;
|
||||
cudaEventElapsedTime(&time_ms, start[i], stop[i]);
|
||||
double time_s = time_ms / 1e3;
|
||||
|
||||
double gb = 2.0 * numElems * sizeof(int) * repeat / (double)1e9;
|
||||
if (i == j) {
|
||||
gb *= 2; // must count both the read and the write here
|
||||
}
|
||||
bandwidthMatrix[i * numGPUs + j] = gb / time_s;
|
||||
if (p2p && access) {
|
||||
cudaSetDevice(i);
|
||||
cudaDeviceDisablePeerAccess(j);
|
||||
cudaSetDevice(j);
|
||||
cudaDeviceDisablePeerAccess(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf(" D\\D");
|
||||
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
printf("%6d ", j);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (int i = 0; i < numGPUs; i++) {
|
||||
printf("%6d ", i);
|
||||
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
printf("%6.02f ", bandwidthMatrix[i * numGPUs + j]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
for (int d = 0; d < numGPUs; d++) {
|
||||
cudaSetDevice(d);
|
||||
cudaFree(buffers[d]);
|
||||
cudaFree(buffersD2D[d]);
|
||||
cudaCheckError();
|
||||
cudaEventDestroy(start[d]);
|
||||
cudaCheckError();
|
||||
cudaEventDestroy(stop[d]);
|
||||
cudaCheckError();
|
||||
cudaStreamDestroy(stream0[d]);
|
||||
cudaCheckError();
|
||||
cudaStreamDestroy(stream1[d]);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
if (hostBuffer) {
|
||||
cudaFreeHost(hostBuffer);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
cudaFreeHost((void *)flag);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
void outputLatencyMatrix(int numGPUs, bool p2p, P2PDataTransfer p2p_method, bool needsFallback)
|
||||
{
|
||||
int repeat = 100;
|
||||
int numElems = 4; // perform 1-int4 transfer.
|
||||
volatile int *flag = NULL;
|
||||
StopWatchInterface *stopWatch = NULL;
|
||||
vector<int *> buffers(numGPUs);
|
||||
vector<int *> buffersD2D(numGPUs); // buffer for D2D, that is, intra-GPU copy
|
||||
vector<cudaStream_t> stream(numGPUs);
|
||||
vector<cudaEvent_t> start(numGPUs);
|
||||
vector<cudaEvent_t> stop(numGPUs);
|
||||
|
||||
cudaHostAlloc((void **)&flag, sizeof(*flag), cudaHostAllocPortable);
|
||||
cudaCheckError();
|
||||
|
||||
if (!sdkCreateTimer(&stopWatch)) {
|
||||
printf("Failed to create stop watch\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sdkStartTimer(&stopWatch);
|
||||
|
||||
for (int d = 0; d < numGPUs; d++) {
|
||||
cudaSetDevice(d);
|
||||
cudaStreamCreateWithFlags(&stream[d], cudaStreamNonBlocking);
|
||||
cudaMalloc(&buffers[d], sizeof(int) * numElems);
|
||||
cudaMemset(buffers[d], 0, sizeof(int) * numElems);
|
||||
cudaMalloc(&buffersD2D[d], sizeof(int) * numElems);
|
||||
cudaMemset(buffersD2D[d], 0, sizeof(int) * numElems);
|
||||
cudaCheckError();
|
||||
cudaEventCreate(&start[d]);
|
||||
cudaCheckError();
|
||||
cudaEventCreate(&stop[d]);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
// Decide if fallback is needed based on global detection result and current test scenario
|
||||
bool useFallback = (!p2p && needsFallback);
|
||||
int *hostBuffer = nullptr;
|
||||
|
||||
if (useFallback) {
|
||||
// Allocate hostBuffer for this function's numElems
|
||||
cudaHostAlloc((void **)&hostBuffer, sizeof(int) * numElems, cudaHostAllocDefault);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
vector<double> gpuLatencyMatrix(numGPUs * numGPUs);
|
||||
vector<double> cpuLatencyMatrix(numGPUs * numGPUs);
|
||||
|
||||
for (int i = 0; i < numGPUs; i++) {
|
||||
cudaSetDevice(i);
|
||||
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
int access = 0;
|
||||
if (p2p) {
|
||||
cudaDeviceCanAccessPeer(&access, i, j);
|
||||
if (access) {
|
||||
cudaDeviceEnablePeerAccess(j, 0);
|
||||
cudaCheckError();
|
||||
cudaSetDevice(j);
|
||||
cudaDeviceEnablePeerAccess(i, 0);
|
||||
cudaSetDevice(i);
|
||||
cudaCheckError();
|
||||
}
|
||||
}
|
||||
cudaStreamSynchronize(stream[i]);
|
||||
cudaCheckError();
|
||||
|
||||
// Block the stream until all the work is queued up
|
||||
// DANGER! - cudaMemcpy*Async may infinitely block waiting for
|
||||
// room to push the operation, so keep the number of repeatitions
|
||||
// relatively low. Higher repeatitions will cause the delay kernel
|
||||
// to timeout and lead to unstable results.
|
||||
*flag = 0;
|
||||
delay<<<1, 1, 0, stream[i]>>>(flag);
|
||||
cudaCheckError();
|
||||
cudaEventRecord(start[i], stream[i]);
|
||||
|
||||
sdkResetTimer(&stopWatch);
|
||||
if (i == j) {
|
||||
// Perform intra-GPU, D2D copies
|
||||
performP2PCopy(
|
||||
buffers[i], i, buffersD2D[i], i, numElems, repeat, access, stream[i], useFallback, hostBuffer);
|
||||
}
|
||||
else {
|
||||
if (p2p_method == P2P_WRITE) {
|
||||
performP2PCopy(
|
||||
buffers[j], j, buffers[i], i, numElems, repeat, access, stream[i], useFallback, hostBuffer);
|
||||
}
|
||||
else {
|
||||
performP2PCopy(
|
||||
buffers[i], i, buffers[j], j, numElems, repeat, access, stream[i], useFallback, hostBuffer);
|
||||
}
|
||||
}
|
||||
float cpu_time_ms = sdkGetTimerValue(&stopWatch);
|
||||
|
||||
cudaEventRecord(stop[i], stream[i]);
|
||||
// Now that the work has been queued up, release the stream
|
||||
*flag = 1;
|
||||
cudaStreamSynchronize(stream[i]);
|
||||
cudaCheckError();
|
||||
|
||||
float gpu_time_ms;
|
||||
cudaEventElapsedTime(&gpu_time_ms, start[i], stop[i]);
|
||||
|
||||
gpuLatencyMatrix[i * numGPUs + j] = gpu_time_ms * 1e3 / repeat;
|
||||
cpuLatencyMatrix[i * numGPUs + j] = cpu_time_ms * 1e3 / repeat;
|
||||
if (p2p && access) {
|
||||
cudaDeviceDisablePeerAccess(j);
|
||||
cudaSetDevice(j);
|
||||
cudaDeviceDisablePeerAccess(i);
|
||||
cudaSetDevice(i);
|
||||
cudaCheckError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf(" GPU");
|
||||
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
printf("%6d ", j);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (int i = 0; i < numGPUs; i++) {
|
||||
printf("%6d ", i);
|
||||
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
printf("%6.02f ", gpuLatencyMatrix[i * numGPUs + j]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("\n CPU");
|
||||
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
printf("%6d ", j);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (int i = 0; i < numGPUs; i++) {
|
||||
printf("%6d ", i);
|
||||
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
printf("%6.02f ", cpuLatencyMatrix[i * numGPUs + j]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
for (int d = 0; d < numGPUs; d++) {
|
||||
cudaSetDevice(d);
|
||||
cudaFree(buffers[d]);
|
||||
cudaFree(buffersD2D[d]);
|
||||
cudaCheckError();
|
||||
cudaEventDestroy(start[d]);
|
||||
cudaCheckError();
|
||||
cudaEventDestroy(stop[d]);
|
||||
cudaCheckError();
|
||||
cudaStreamDestroy(stream[d]);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
sdkDeleteTimer(&stopWatch);
|
||||
|
||||
if (hostBuffer) {
|
||||
cudaFreeHost(hostBuffer);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
cudaFreeHost((void *)flag);
|
||||
cudaCheckError();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int numGPUs, numElems = 40000000;
|
||||
P2PDataTransfer p2p_method = P2P_WRITE;
|
||||
|
||||
cudaGetDeviceCount(&numGPUs);
|
||||
cudaCheckError();
|
||||
|
||||
// process command line args
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "help")) {
|
||||
printHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "p2p_read")) {
|
||||
p2p_method = P2P_READ;
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "sm_copy")) {
|
||||
p2p_mechanism = SM;
|
||||
}
|
||||
|
||||
// number of elements of int to be used in copy.
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "numElems")) {
|
||||
numElems = getCmdLineArgumentInt(argc, (const char **)argv, "numElems");
|
||||
}
|
||||
|
||||
printf("[%s]\n", sSampleName);
|
||||
|
||||
// output devices
|
||||
for (int i = 0; i < numGPUs; i++) {
|
||||
cudaDeviceProp prop;
|
||||
cudaGetDeviceProperties(&prop, i);
|
||||
cudaCheckError();
|
||||
printf("Device: %d, %s, pciBusID: %x, pciDeviceID: %x, pciDomainID:%x\n",
|
||||
i,
|
||||
prop.name,
|
||||
prop.pciBusID,
|
||||
prop.pciDeviceID,
|
||||
prop.pciDomainID);
|
||||
}
|
||||
|
||||
checkP2Paccess(numGPUs);
|
||||
|
||||
// Environment detection: One-time check if cudaMemcpyPeerAsync is supported when P2P is disabled
|
||||
bool needsFallback = detectFallback(numGPUs);
|
||||
|
||||
// Check peer-to-peer connectivity
|
||||
printf("P2P Connectivity Matrix\n");
|
||||
printf(" D\\D");
|
||||
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
printf("%6d", j);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
for (int i = 0; i < numGPUs; i++) {
|
||||
printf("%6d\t", i);
|
||||
for (int j = 0; j < numGPUs; j++) {
|
||||
if (i != j) {
|
||||
int access;
|
||||
cudaDeviceCanAccessPeer(&access, i, j);
|
||||
cudaCheckError();
|
||||
printf("%6d", (access) ? 1 : 0);
|
||||
}
|
||||
else {
|
||||
printf("%6d", 1);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("Unidirectional P2P=Disabled Bandwidth Matrix (GB/s)\n");
|
||||
outputBandwidthMatrix(numElems, numGPUs, false, P2P_WRITE, needsFallback);
|
||||
printf("Unidirectional P2P=Enabled Bandwidth (P2P Writes) Matrix (GB/s)\n");
|
||||
outputBandwidthMatrix(numElems, numGPUs, true, P2P_WRITE, needsFallback);
|
||||
if (p2p_method == P2P_READ) {
|
||||
printf("Unidirectional P2P=Enabled Bandwidth (P2P Reads) Matrix (GB/s)\n");
|
||||
outputBandwidthMatrix(numElems, numGPUs, true, p2p_method, needsFallback);
|
||||
}
|
||||
printf("Bidirectional P2P=Disabled Bandwidth Matrix (GB/s)\n");
|
||||
outputBidirectionalBandwidthMatrix(numElems, numGPUs, false, needsFallback);
|
||||
printf("Bidirectional P2P=Enabled Bandwidth Matrix (GB/s)\n");
|
||||
outputBidirectionalBandwidthMatrix(numElems, numGPUs, true, needsFallback);
|
||||
|
||||
printf("P2P=Disabled Latency Matrix (us)\n");
|
||||
outputLatencyMatrix(numGPUs, false, P2P_WRITE, needsFallback);
|
||||
printf("P2P=Enabled Latency (P2P Writes) Matrix (us)\n");
|
||||
outputLatencyMatrix(numGPUs, true, P2P_WRITE, needsFallback);
|
||||
if (p2p_method == P2P_READ) {
|
||||
printf("P2P=Enabled Latency (P2P Reads) Matrix (us)\n");
|
||||
outputLatencyMatrix(numGPUs, true, p2p_method, needsFallback);
|
||||
}
|
||||
|
||||
printf("\nNOTE: The CUDA Samples are not meant for performance measurements. "
|
||||
"Results may vary when GPU Boost is enabled.\n");
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
@@ -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,22 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(postProcessGL LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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)
|
||||
|
||||
if(WIN32)
|
||||
@@ -33,48 +29,36 @@ endif()
|
||||
find_package(OpenGL)
|
||||
find_package(GLUT)
|
||||
|
||||
# Source file
|
||||
if(${OpenGL_FOUND})
|
||||
if (${GLUT_FOUND})
|
||||
# Add target for postProcessGL
|
||||
add_executable(postProcessGL main.cpp postProcessGL.cu)
|
||||
|
||||
target_compile_options(postProcessGL PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(postProcessGL PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(postProcessGL PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(postProcessGL PUBLIC
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
${GLUT_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(postProcessGL
|
||||
${OPENGL_LIBRARIES}
|
||||
${GLUT_LIBRARIES}
|
||||
)
|
||||
|
||||
add_custom_command(TARGET postProcessGL POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(postProcessGL
|
||||
${PC_GLUT_LIBRARY_DIRS}/freeglut.lib
|
||||
${PC_GLUT_LIBRARY_DIRS}/${GLEW_LIB_NAME}.lib
|
||||
)
|
||||
|
||||
add_custom_command(TARGET postProcessGL
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/win64/$<CONFIGURATION>/freeglut.dll
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
|
||||
add_custom_command(TARGET postProcessGL
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
@@ -82,14 +66,11 @@ if(${OpenGL_FOUND})
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
endif()
|
||||
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
else()
|
||||
message(STATUS "GLUT not found - will not build sample 'postProcessGL'")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "OpenGL not found - will not build sample 'postProcessGL'")
|
||||
endif()
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,38 +1,29 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(quasirandomGenerator LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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 quasirandomGenerator
|
||||
add_executable(quasirandomGenerator quasirandomGenerator.cpp quasirandomGenerator_gold.cpp quasirandomGenerator_kernel.cu)
|
||||
|
||||
target_compile_options(quasirandomGenerator PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(quasirandomGenerator PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(quasirandomGenerator PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(quasirandomGenerator PRIVATE
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -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,45 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
project(quasirandomGenerator_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 target for quasirandomGenerator_nvrtc
|
||||
add_executable(quasirandomGenerator_nvrtc quasirandomGenerator.cpp quasirandomGenerator_gold.cpp)
|
||||
|
||||
target_compile_options(quasirandomGenerator_nvrtc PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(quasirandomGenerator_nvrtc PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(quasirandomGenerator_nvrtc PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_link_libraries(quasirandomGenerator_nvrtc PRIVATE
|
||||
CUDA::nvrtc
|
||||
CUDA::cuda_driver
|
||||
)
|
||||
|
||||
# Copy kernel to the output directory
|
||||
add_custom_command(TARGET quasirandomGenerator_nvrtc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/quasirandomGenerator_kernel.cu ${CMAKE_CURRENT_SOURCE_DIR}/quasirandomGenerator_gpu.cuh ${CMAKE_CURRENT_SOURCE_DIR}/quasirandomGenerator_common.h ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
@@ -1,36 +0,0 @@
|
||||
# quasirandomGenerator_nvrtc - Niederreiter Quasirandom Sequence Generator with libNVRTC
|
||||
|
||||
## Description
|
||||
|
||||
This sample implements Niederreiter Quasirandom Sequence Generator and Inverse Cumulative Normal Distribution functions for the generation of Standard Normal Distributions, compiling the CUDA kernels involved at runtime using NVRTC.
|
||||
|
||||
## Key Concepts
|
||||
|
||||
Computational Finance, 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, cuMemAlloc, cuMemFree
|
||||
|
||||
## 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,180 +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.
|
||||
*/
|
||||
|
||||
// CUDA Runtime
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
// Utilities and system includes
|
||||
#include <helper_functions.h>
|
||||
|
||||
#include "quasirandomGenerator_common.h"
|
||||
#include "quasirandomGenerator_gpu.cuh"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// CPU code
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" void initQuasirandomGenerator(unsigned int table[QRNG_DIMENSIONS][QRNG_RESOLUTION]);
|
||||
|
||||
extern "C" float getQuasirandomValue(unsigned int table[QRNG_DIMENSIONS][QRNG_RESOLUTION], int i, int dim);
|
||||
|
||||
extern "C" double getQuasirandomValue63(INT64 i, int dim);
|
||||
extern "C" double MoroInvCNDcpu(unsigned int p);
|
||||
|
||||
const int N = 1048576;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Start logs
|
||||
printf("%s Starting...\n\n", argv[0]);
|
||||
|
||||
// Compile the kernels
|
||||
char *kernel_file = sdkFindFilePath("quasirandomGenerator_kernel.cu", argv[0]);
|
||||
compileFileToCUBIN(kernel_file, argc, argv, &cubin, &cubinSize, 0);
|
||||
module = loadCUBIN(cubin, argc, argv);
|
||||
|
||||
unsigned int tableCPU[QRNG_DIMENSIONS][QRNG_RESOLUTION];
|
||||
float *h_OutputGPU;
|
||||
CUdeviceptr d_Output;
|
||||
|
||||
int dim, pos;
|
||||
double delta, ref, sumDelta, sumRef, L1norm, gpuTime;
|
||||
|
||||
StopWatchInterface *hTimer = NULL;
|
||||
|
||||
if (sizeof(INT64) != 8) {
|
||||
printf("sizeof(INT64) != 8\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
sdkCreateTimer(&hTimer);
|
||||
|
||||
printf("Allocating GPU memory...\n");
|
||||
checkCudaErrors(cuMemAlloc(&d_Output, QRNG_DIMENSIONS * N * sizeof(float)));
|
||||
|
||||
printf("Allocating CPU memory...\n");
|
||||
h_OutputGPU = (float *)malloc(QRNG_DIMENSIONS * N * sizeof(float));
|
||||
|
||||
printf("Initializing QRNG tables...\n\n");
|
||||
initQuasirandomGenerator(tableCPU);
|
||||
|
||||
initTableGPU(tableCPU);
|
||||
|
||||
printf("Testing QRNG...\n\n");
|
||||
|
||||
checkCudaErrors(cuMemsetD8(d_Output, 0, QRNG_DIMENSIONS * N * sizeof(float)));
|
||||
|
||||
int numIterations = 20;
|
||||
|
||||
for (int i = -1; i < numIterations; i++) {
|
||||
if (i == 0) {
|
||||
sdkResetTimer(&hTimer);
|
||||
sdkStartTimer(&hTimer);
|
||||
}
|
||||
|
||||
quasirandomGeneratorGPU(d_Output, 0, N);
|
||||
}
|
||||
|
||||
sdkStopTimer(&hTimer);
|
||||
gpuTime = sdkGetTimerValue(&hTimer) / (double)numIterations * 1e-3;
|
||||
printf("quasirandomGenerator, Throughput = %.4f GNumbers/s, Time = %.5f s, Size "
|
||||
"= %u Numbers, NumDevsUsed = %u, Workgroup = %u\n",
|
||||
(double)QRNG_DIMENSIONS * (double)N * 1.0E-9 / gpuTime,
|
||||
gpuTime,
|
||||
QRNG_DIMENSIONS * N,
|
||||
1,
|
||||
128 * QRNG_DIMENSIONS);
|
||||
|
||||
printf("\nReading GPU results...\n");
|
||||
|
||||
checkCudaErrors(cuMemcpyDtoH(h_OutputGPU, d_Output, QRNG_DIMENSIONS * N * sizeof(float)));
|
||||
|
||||
printf("Comparing to the CPU results...\n\n");
|
||||
sumDelta = 0;
|
||||
sumRef = 0;
|
||||
|
||||
for (dim = 0; dim < QRNG_DIMENSIONS; dim++)
|
||||
for (pos = 0; pos < N; pos++) {
|
||||
ref = getQuasirandomValue63(pos, dim);
|
||||
delta = (double)h_OutputGPU[dim * N + pos] - ref;
|
||||
sumDelta += fabs(delta);
|
||||
sumRef += fabs(ref);
|
||||
}
|
||||
|
||||
printf("L1 norm: %E\n", sumDelta / sumRef);
|
||||
|
||||
printf("\nTesting inverseCNDgpu()...\n\n");
|
||||
|
||||
checkCudaErrors(cuMemsetD8(d_Output, 0, QRNG_DIMENSIONS * N * sizeof(float)));
|
||||
|
||||
for (int i = -1; i < numIterations; i++) {
|
||||
if (i == 0) {
|
||||
sdkResetTimer(&hTimer);
|
||||
sdkStartTimer(&hTimer);
|
||||
}
|
||||
|
||||
inverseCNDgpu(d_Output, QRNG_DIMENSIONS * N);
|
||||
}
|
||||
|
||||
sdkStopTimer(&hTimer);
|
||||
gpuTime = sdkGetTimerValue(&hTimer) / (double)numIterations * 1e-3;
|
||||
printf("quasirandomGenerator-inverse, Throughput = %.4f GNumbers/s, Time = %.5f "
|
||||
"s, Size = %u Numbers, NumDevsUsed = %u, Workgroup = %u\n",
|
||||
(double)QRNG_DIMENSIONS * (double)N * 1E-9 / gpuTime,
|
||||
gpuTime,
|
||||
QRNG_DIMENSIONS * N,
|
||||
1,
|
||||
128);
|
||||
|
||||
printf("Reading GPU results...\n");
|
||||
checkCudaErrors(cuMemcpyDtoH(h_OutputGPU, d_Output, QRNG_DIMENSIONS * N * sizeof(float)));
|
||||
|
||||
printf("\nComparing to the CPU results...\n");
|
||||
|
||||
sumDelta = 0;
|
||||
sumRef = 0;
|
||||
unsigned int distance = ((unsigned int)-1) / (QRNG_DIMENSIONS * N + 1);
|
||||
|
||||
for (pos = 0; pos < QRNG_DIMENSIONS * N; pos++) {
|
||||
unsigned int d = (pos + 1) * distance;
|
||||
ref = MoroInvCNDcpu(d);
|
||||
delta = (double)h_OutputGPU[pos] - ref;
|
||||
sumDelta += fabs(delta);
|
||||
sumRef += fabs(ref);
|
||||
}
|
||||
|
||||
printf("L1 norm: %E\n\n", L1norm = sumDelta / sumRef);
|
||||
printf("Shutting down...\n");
|
||||
|
||||
sdkDeleteTimer(&hTimer);
|
||||
free(h_OutputGPU);
|
||||
|
||||
checkCudaErrors(cuMemFree(d_Output));
|
||||
|
||||
exit(L1norm < 1e-6 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
@@ -1,41 +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 QUASIRANDOMGENERATOR_COMMON_H
|
||||
#define QUASIRANDOMGENERATOR_COMMON_H
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Global types and constants
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef long long int INT64;
|
||||
|
||||
#define QRNG_DIMENSIONS 3
|
||||
#define QRNG_RESOLUTION 31
|
||||
#define INT_SCALE (1.0f / (float)0x80000001U)
|
||||
|
||||
#endif
|
||||
@@ -1,339 +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 <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "quasirandomGenerator_common.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Table generation functions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Internal 64(63)-bit table
|
||||
static INT64 cjn[63][QRNG_DIMENSIONS];
|
||||
|
||||
static int GeneratePolynomials(int buffer[QRNG_DIMENSIONS], bool primitive)
|
||||
{
|
||||
int i, j, n, p1, p2, l;
|
||||
int e_p1, e_p2, e_b;
|
||||
|
||||
// generate all polynomials to buffer
|
||||
for (n = 1, buffer[0] = 0x2, p2 = 0, l = 0; n < QRNG_DIMENSIONS; ++n) {
|
||||
// search for the next irreducible polynomial
|
||||
for (p1 = buffer[n - 1] + 1;; ++p1) {
|
||||
// find degree of polynomial p1
|
||||
for (e_p1 = 30; (p1 & (1 << e_p1)) == 0; --e_p1) {
|
||||
}
|
||||
|
||||
// try to divide p1 by all polynomials in buffer
|
||||
for (i = 0; i < n; ++i) {
|
||||
// find the degree of buffer[i]
|
||||
for (e_b = e_p1; (buffer[i] & (1 << e_b)) == 0; --e_b) {
|
||||
}
|
||||
|
||||
// divide p2 by buffer[i] until the end
|
||||
for (p2 = (buffer[i] << ((e_p2 = e_p1) - e_b)) ^ p1; p2 >= buffer[i];
|
||||
p2 = (buffer[i] << (e_p2 - e_b)) ^ p2) {
|
||||
for (; (p2 & (1 << e_p2)) == 0; --e_p2) {
|
||||
}
|
||||
} // compute new degree of p2
|
||||
|
||||
// division without remainder!!! p1 is not irreducible
|
||||
if (p2 == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// all divisions were with remainder - p1 is irreducible
|
||||
if (p2 != 0) {
|
||||
e_p2 = 0;
|
||||
|
||||
if (primitive) {
|
||||
// check that p1 has only one cycle (i.e. is monic, or primitive)
|
||||
j = ~(0xffffffff << (e_p1 + 1));
|
||||
e_b = (1 << e_p1) | 0x1;
|
||||
|
||||
for (p2 = e_b, e_p2 = (1 << e_p1) - 2; e_p2 > 0; --e_p2) {
|
||||
p2 <<= 1;
|
||||
i = p2 & p1;
|
||||
i = (i & 0x55555555) + ((i >> 1) & 0x55555555);
|
||||
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
|
||||
i = (i & 0x07070707) + ((i >> 4) & 0x07070707);
|
||||
p2 |= (i % 255) & 1;
|
||||
|
||||
if ((p2 & j) == e_b)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// it is monic - add it to the list of polynomials
|
||||
if (e_p2 == 0) {
|
||||
buffer[n] = p1;
|
||||
l += e_p1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return l + 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// @misc{Bratley92:LDS,
|
||||
// author = "B. Fox and P. Bratley and H. Niederreiter",
|
||||
// title = "Implementation and test of low discrepancy sequences",
|
||||
// text = "B. L. Fox, P. Bratley, and H. Niederreiter. Implementation and
|
||||
// test of
|
||||
// low discrepancy sequences. ACM Trans. Model. Comput. Simul.,
|
||||
// 2(3):195--213,
|
||||
// July 1992.",
|
||||
// year = "1992" }
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void GenerateCJ()
|
||||
{
|
||||
int buffer[QRNG_DIMENSIONS];
|
||||
int *polynomials;
|
||||
int n, p1, l, e_p1;
|
||||
|
||||
// Niederreiter (in contrast to Sobol) allows to use not primitive, but just
|
||||
// irreducible polynomials
|
||||
l = GeneratePolynomials(buffer, false);
|
||||
|
||||
// convert all polynomials from buffer to polynomials table
|
||||
polynomials = new int[l + 2 * QRNG_DIMENSIONS + 1];
|
||||
|
||||
for (n = 0, l = 0; n < QRNG_DIMENSIONS; ++n) {
|
||||
// find degree of polynomial p1
|
||||
for (p1 = buffer[n], e_p1 = 30; (p1 & (1 << e_p1)) == 0; --e_p1) {
|
||||
}
|
||||
|
||||
// fill polynomials table with values for this polynomial
|
||||
polynomials[l++] = 1;
|
||||
|
||||
for (--e_p1; e_p1 >= 0; --e_p1) {
|
||||
polynomials[l++] = (p1 >> e_p1) & 1;
|
||||
}
|
||||
|
||||
polynomials[l++] = -1;
|
||||
}
|
||||
|
||||
polynomials[l] = -1;
|
||||
|
||||
// irreducible polynomial p
|
||||
int *p = polynomials, e, d;
|
||||
|
||||
// polynomial b
|
||||
int b_arr[1024], *b, m;
|
||||
|
||||
// v array
|
||||
int v_arr[1024], *v;
|
||||
|
||||
// temporary polynomial, required to do multiplication of p and b
|
||||
int t_arr[1024], *t;
|
||||
|
||||
// subsidiary variables
|
||||
int i, j, u, m1, ip, it;
|
||||
|
||||
// cycle over monic irreducible polynomials
|
||||
for (d = 0; p[0] != -1; p += e + 2) {
|
||||
// allocate memory for cj array for dimension (ip + 1)
|
||||
for (i = 0; i < 63; ++i) {
|
||||
cjn[i][d] = 0;
|
||||
}
|
||||
|
||||
// determine the power of irreducible polynomial
|
||||
for (e = 0; p[e + 1] != -1; ++e) {
|
||||
}
|
||||
|
||||
// polynomial b in the beginning is just '1'
|
||||
(b = b_arr + 1023)[m = 0] = 1;
|
||||
|
||||
// v array needs only (63 + e - 2) length
|
||||
v = v_arr + 1023 - (63 + e - 2);
|
||||
|
||||
// cycle over all coefficients
|
||||
for (j = 63 - 1, u = e; j >= 0; --j, ++u) {
|
||||
if (u == e) {
|
||||
u = 0;
|
||||
|
||||
// multiply b by p (polynomials multiplication)
|
||||
for (i = 0, t = t_arr + 1023 - (m1 = m); i <= m; ++i) {
|
||||
t[i] = b[i];
|
||||
}
|
||||
|
||||
b = b_arr + 1023 - (m += e);
|
||||
|
||||
for (i = 0; i <= m; ++i) {
|
||||
b[i] = 0;
|
||||
|
||||
for (ip = e - (m - i), it = m1; ip <= e && it >= 0; ++ip, --it) {
|
||||
if (ip >= 0) {
|
||||
b[i] ^= p[ip] & t[it];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// multiplication of polynomials finished
|
||||
// calculate v
|
||||
for (i = 0; i < m1; ++i) {
|
||||
v[i] = 0;
|
||||
}
|
||||
|
||||
for (; i < m; ++i) {
|
||||
v[i] = 1;
|
||||
}
|
||||
|
||||
for (; i <= 63 + e - 2; ++i) {
|
||||
v[i] = 0;
|
||||
for (it = 1; it <= m; ++it) {
|
||||
v[i] ^= v[i - it] & b[it];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// copy calculated v to cj
|
||||
for (i = 0; i < 63; i++) {
|
||||
cjn[i][d] |= (INT64)v[i + u] << j;
|
||||
}
|
||||
}
|
||||
|
||||
++d;
|
||||
}
|
||||
|
||||
delete[] polynomials;
|
||||
}
|
||||
|
||||
// Generate 63-bit quasirandom number for given index and dimension and
|
||||
// normalize
|
||||
|
||||
extern "C" double getQuasirandomValue63(INT64 i, int dim)
|
||||
{
|
||||
const double INT63_SCALE = (1.0 / (double)0x8000000000000001ULL);
|
||||
INT64 result = 0;
|
||||
|
||||
for (int bit = 0; bit < 63; bit++, i >>= 1)
|
||||
if (i & 1)
|
||||
result ^= cjn[bit][dim];
|
||||
|
||||
return (double)(result + 1) * INT63_SCALE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Initialization (table setup)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" void initQuasirandomGenerator(unsigned int table[QRNG_DIMENSIONS][QRNG_RESOLUTION])
|
||||
{
|
||||
GenerateCJ();
|
||||
|
||||
for (int dim = 0; dim < QRNG_DIMENSIONS; dim++)
|
||||
for (int bit = 0; bit < QRNG_RESOLUTION; bit++)
|
||||
table[dim][bit] = (int)((cjn[bit][dim] >> 32) & 0x7FFFFFFF);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Generate 31-bit quasirandom number for given index and dimension
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
extern "C" float getQuasirandomValue(unsigned int table[QRNG_DIMENSIONS][QRNG_RESOLUTION], int i, int dim)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
for (int bit = 0; bit < QRNG_RESOLUTION; bit++, i >>= 1)
|
||||
if (i & 1)
|
||||
result ^= table[dim][bit];
|
||||
|
||||
return (float)(result + 1) * INT_SCALE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Moro's Inverse Cumulative Normal Distribution function approximation
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
extern "C" double MoroInvCNDcpu(unsigned int x)
|
||||
{
|
||||
const double a1 = 2.50662823884;
|
||||
const double a2 = -18.61500062529;
|
||||
const double a3 = 41.39119773534;
|
||||
const double a4 = -25.44106049637;
|
||||
const double b1 = -8.4735109309;
|
||||
const double b2 = 23.08336743743;
|
||||
const double b3 = -21.06224101826;
|
||||
const double b4 = 3.13082909833;
|
||||
const double c1 = 0.337475482272615;
|
||||
const double c2 = 0.976169019091719;
|
||||
const double c3 = 0.160797971491821;
|
||||
const double c4 = 2.76438810333863E-02;
|
||||
const double c5 = 3.8405729373609E-03;
|
||||
const double c6 = 3.951896511919E-04;
|
||||
const double c7 = 3.21767881768E-05;
|
||||
const double c8 = 2.888167364E-07;
|
||||
const double c9 = 3.960315187E-07;
|
||||
|
||||
double z;
|
||||
|
||||
bool negate = false;
|
||||
|
||||
// Ensure the conversion to floating point will give a value in the
|
||||
// range (0,0.5] by restricting the input to the bottom half of the
|
||||
// input domain. We will later reflect the result if the input was
|
||||
// originally in the top half of the input domain
|
||||
|
||||
if (x >= 0x80000000UL) {
|
||||
x = 0xffffffffUL - x;
|
||||
negate = true;
|
||||
}
|
||||
|
||||
// x is now in the range [0,0x80000000) (i.e. [0,0x7fffffff])
|
||||
// Convert to floating point in (0,0.5]
|
||||
const double x1 = 1.0 / static_cast<double>(0xffffffffUL);
|
||||
const double x2 = x1 / 2.0;
|
||||
double p1 = x * x1 + x2;
|
||||
|
||||
// Convert to floating point in (-0.5,0]
|
||||
double p2 = p1 - 0.5;
|
||||
|
||||
// The input to the Moro inversion is p2 which is in the range
|
||||
// (-0.5,0]. This means that our output will be the negative side
|
||||
// of the bell curve (which we will reflect if "negate" is true).
|
||||
|
||||
// Main body of the bell curve for |p| < 0.42
|
||||
if (p2 > -0.42) {
|
||||
z = p2 * p2;
|
||||
z = p2 * (((a4 * z + a3) * z + a2) * z + a1) / ((((b4 * z + b3) * z + b2) * z + b1) * z + 1.0);
|
||||
}
|
||||
// Special case (Chebychev) for tail
|
||||
else {
|
||||
z = log(-log(p1));
|
||||
z = -(c1 + z * (c2 + z * (c3 + z * (c4 + z * (c5 + z * (c6 + z * (c7 + z * (c8 + z * c9))))))));
|
||||
}
|
||||
|
||||
// If the original input (x) was in the top half of the range, reflect
|
||||
// to get the positive side of the bell curve
|
||||
return negate ? -z : z;
|
||||
}
|
||||
@@ -1,108 +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 QUASIRANDOMGENERATOR_GPU_CUH
|
||||
#define QUASIRANDOMGENERATOR_GPU_CUH
|
||||
|
||||
#include <nvrtc_helper.h>
|
||||
|
||||
#include "quasirandomGenerator_common.h"
|
||||
|
||||
// Fast integer multiplication
|
||||
#define MUL(a, b) __umul24(a, b)
|
||||
|
||||
// Global variables for nvrtc outputs
|
||||
char *cubin;
|
||||
size_t cubinSize;
|
||||
CUmodule module;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// GPU code
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Niederreiter quasirandom number generation kernel
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Table initialization routine
|
||||
void initTableGPU(unsigned int tableCPU[QRNG_DIMENSIONS][QRNG_RESOLUTION])
|
||||
{
|
||||
CUdeviceptr c_Table;
|
||||
checkCudaErrors(cuModuleGetGlobal(&c_Table, NULL, module, "c_Table"));
|
||||
checkCudaErrors(cuMemcpyHtoD(c_Table, tableCPU, QRNG_DIMENSIONS * QRNG_RESOLUTION * sizeof(unsigned int)));
|
||||
}
|
||||
|
||||
// Host-side interface
|
||||
void quasirandomGeneratorGPU(CUdeviceptr d_Output, unsigned int seed, unsigned int N)
|
||||
{
|
||||
dim3 threads(128, QRNG_DIMENSIONS);
|
||||
dim3 cudaGridSize(128, 1, 1);
|
||||
|
||||
CUfunction kernel_addr;
|
||||
checkCudaErrors(cuModuleGetFunction(&kernel_addr, module, "quasirandomGeneratorKernel"));
|
||||
|
||||
void *args[] = {(void *)&d_Output, (void *)&seed, (void *)&N};
|
||||
checkCudaErrors(cuLaunchKernel(kernel_addr,
|
||||
cudaGridSize.x,
|
||||
cudaGridSize.y,
|
||||
cudaGridSize.z, /* grid dim */
|
||||
threads.x,
|
||||
threads.y,
|
||||
threads.z, /* block dim */
|
||||
0,
|
||||
0, /* shared mem, stream */
|
||||
&args[0], /* arguments */
|
||||
0));
|
||||
|
||||
checkCudaErrors(cuCtxSynchronize());
|
||||
}
|
||||
|
||||
void inverseCNDgpu(CUdeviceptr d_Output, unsigned int N)
|
||||
{
|
||||
dim3 threads(128, 1, 1);
|
||||
dim3 cudaGridSize(128, 1, 1);
|
||||
|
||||
CUfunction kernel_addr;
|
||||
checkCudaErrors(cuModuleGetFunction(&kernel_addr, module, "inverseCNDKernel"));
|
||||
|
||||
void *args[] = {(void *)&d_Output, (void *)&N};
|
||||
checkCudaErrors(cuLaunchKernel(kernel_addr,
|
||||
cudaGridSize.x,
|
||||
cudaGridSize.y,
|
||||
cudaGridSize.z, /* grid dim */
|
||||
threads.x,
|
||||
threads.y,
|
||||
threads.z, /* block dim */
|
||||
0,
|
||||
0, /* shared mem, stream */
|
||||
&args[0], /* arguments */
|
||||
0));
|
||||
|
||||
checkCudaErrors(cuCtxSynchronize());
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,157 +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 QUASIRANDOMGENERATOR_KERNEL_CUH
|
||||
#define QUASIRANDOMGENERATOR_KERNEL_CUH
|
||||
|
||||
#include "quasirandomGenerator_common.h"
|
||||
|
||||
// Fast integer multiplication
|
||||
#define MUL(a, b) __umul24(a, b)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Niederreiter quasirandom number generation kernel
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
__constant__ unsigned int c_Table[QRNG_DIMENSIONS][QRNG_RESOLUTION];
|
||||
|
||||
extern "C" __global__ void quasirandomGeneratorKernel(float *d_Output, unsigned int seed, unsigned int N)
|
||||
{
|
||||
unsigned int *dimBase = &c_Table[threadIdx.y][0];
|
||||
unsigned int tid = MUL(blockDim.x, blockIdx.x) + threadIdx.x;
|
||||
unsigned int threadN = MUL(blockDim.x, gridDim.x);
|
||||
|
||||
for (unsigned int pos = tid; pos < N; pos += threadN) {
|
||||
unsigned int result = 0;
|
||||
unsigned int data = seed + pos;
|
||||
|
||||
for (int bit = 0; bit < QRNG_RESOLUTION; bit++, data >>= 1)
|
||||
if (data & 1) {
|
||||
result ^= dimBase[bit];
|
||||
}
|
||||
|
||||
d_Output[MUL(threadIdx.y, N) + pos] = (float)(result + 1) * INT_SCALE;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Moro's Inverse Cumulative Normal Distribution function approximation
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
__device__ inline float MoroInvCNDgpu(unsigned int x)
|
||||
{
|
||||
const float a1 = 2.50662823884f;
|
||||
const float a2 = -18.61500062529f;
|
||||
const float a3 = 41.39119773534f;
|
||||
const float a4 = -25.44106049637f;
|
||||
const float b1 = -8.4735109309f;
|
||||
const float b2 = 23.08336743743f;
|
||||
const float b3 = -21.06224101826f;
|
||||
const float b4 = 3.13082909833f;
|
||||
const float c1 = 0.337475482272615f;
|
||||
const float c2 = 0.976169019091719f;
|
||||
const float c3 = 0.160797971491821f;
|
||||
const float c4 = 2.76438810333863E-02f;
|
||||
const float c5 = 3.8405729373609E-03f;
|
||||
const float c6 = 3.951896511919E-04f;
|
||||
const float c7 = 3.21767881768E-05f;
|
||||
const float c8 = 2.888167364E-07f;
|
||||
const float c9 = 3.960315187E-07f;
|
||||
|
||||
float z;
|
||||
|
||||
bool negate = false;
|
||||
|
||||
// Ensure the conversion to floating point will give a value in the
|
||||
// range (0,0.5] by restricting the input to the bottom half of the
|
||||
// input domain. We will later reflect the result if the input was
|
||||
// originally in the top half of the input domain
|
||||
if (x >= 0x80000000UL) {
|
||||
x = 0xffffffffUL - x;
|
||||
negate = true;
|
||||
}
|
||||
|
||||
// x is now in the range [0,0x80000000) (i.e. [0,0x7fffffff])
|
||||
// Convert to floating point in (0,0.5]
|
||||
const float x1 = 1.0f / static_cast<float>(0xffffffffUL);
|
||||
const float x2 = x1 / 2.0f;
|
||||
float p1 = x * x1 + x2;
|
||||
// Convert to floating point in (-0.5,0]
|
||||
float p2 = p1 - 0.5f;
|
||||
|
||||
// The input to the Moro inversion is p2 which is in the range
|
||||
// (-0.5,0]. This means that our output will be the negative side
|
||||
// of the bell curve (which we will reflect if "negate" is true).
|
||||
|
||||
// Main body of the bell curve for |p| < 0.42
|
||||
if (p2 > -0.42f) {
|
||||
z = p2 * p2;
|
||||
z = p2 * (((a4 * z + a3) * z + a2) * z + a1) / ((((b4 * z + b3) * z + b2) * z + b1) * z + 1.0f);
|
||||
}
|
||||
// Special case (Chebychev) for tail
|
||||
else {
|
||||
z = __logf(-__logf(p1));
|
||||
z = -(c1 + z * (c2 + z * (c3 + z * (c4 + z * (c5 + z * (c6 + z * (c7 + z * (c8 + z * c9))))))));
|
||||
}
|
||||
|
||||
// If the original input (x) was in the top half of the range, reflect
|
||||
// to get the positive side of the bell curve
|
||||
|
||||
return negate ? -z : z;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Main kernel. Choose between transforming
|
||||
// input sequence and uniform ascending (0, 1) sequence
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" __global__ void inverseCNDKernel(float *d_Output, unsigned int pathN)
|
||||
{
|
||||
unsigned int distance = ((unsigned int)-1) / (pathN + 1);
|
||||
unsigned int tid = MUL(blockDim.x, blockIdx.x) + threadIdx.x;
|
||||
unsigned int threadN = MUL(blockDim.x, gridDim.x);
|
||||
|
||||
// Transform input number sequence if it's supplied
|
||||
if (0) // d_Input)
|
||||
{
|
||||
/*
|
||||
for (unsigned int pos = tid; pos < pathN; pos += threadN)
|
||||
{
|
||||
unsigned int d = d_Input[pos];
|
||||
d_Output[pos] = (float)MoroInvCNDgpu(d);
|
||||
}
|
||||
*/
|
||||
}
|
||||
// Else generate input uniformly placed samples on the fly
|
||||
// and write to destination
|
||||
else {
|
||||
for (unsigned int pos = tid; pos < pathN; pos += threadN) {
|
||||
unsigned int d = (pos + 1) * distance;
|
||||
d_Output[pos] = (float)MoroInvCNDgpu(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#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,22 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(recursiveGaussian LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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)
|
||||
|
||||
if(WIN32)
|
||||
@@ -33,48 +29,36 @@ endif()
|
||||
find_package(OpenGL)
|
||||
find_package(GLUT)
|
||||
|
||||
# Source file
|
||||
if(${OpenGL_FOUND})
|
||||
if (${GLUT_FOUND})
|
||||
# Add target for recursiveGaussian
|
||||
add_executable(recursiveGaussian recursiveGaussian_cuda.cu recursiveGaussian.cpp)
|
||||
|
||||
target_compile_options(recursiveGaussian PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(recursiveGaussian PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(recursiveGaussian PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(recursiveGaussian PUBLIC
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
${GLUT_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(recursiveGaussian
|
||||
${OPENGL_LIBRARIES}
|
||||
${GLUT_LIBRARIES}
|
||||
)
|
||||
|
||||
add_custom_command(TARGET recursiveGaussian POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(recursiveGaussian
|
||||
${PC_GLUT_LIBRARY_DIRS}/freeglut.lib
|
||||
${PC_GLUT_LIBRARY_DIRS}/${GLEW_LIB_NAME}.lib
|
||||
)
|
||||
|
||||
add_custom_command(TARGET recursiveGaussian
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/win64/$<CONFIGURATION>/freeglut.dll
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
|
||||
add_custom_command(TARGET recursiveGaussian
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
@@ -82,14 +66,11 @@ if(${OpenGL_FOUND})
|
||||
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>
|
||||
)
|
||||
endif()
|
||||
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
else()
|
||||
message(STATUS "GLUT not found - will not build sample 'recursiveGaussian'")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "OpenGL not found - will not build sample 'recursiveGaussian'")
|
||||
endif()
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -1,59 +1,44 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(simpleD3D11 LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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)
|
||||
|
||||
if(WIN32)
|
||||
# Source file
|
||||
# Add target for simpleD3D11
|
||||
add_executable(simpleD3D11
|
||||
simpleD3D11.cpp
|
||||
sinewave_cuda.cu
|
||||
../../../Common/rendercheck_d3d11.cpp
|
||||
)
|
||||
|
||||
target_compile_options(simpleD3D11 PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(simpleD3D11 PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(simpleD3D11 PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(simpleD3D11 PRIVATE
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(simpleD3D11 PRIVATE
|
||||
d3d11
|
||||
dxgi
|
||||
dxguid
|
||||
d3dcompiler
|
||||
)
|
||||
|
||||
add_custom_command(TARGET simpleD3D11 POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
else()
|
||||
message(STATUS "Sample 'simpleD3D11' is Windows-only - skipping")
|
||||
endif()
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
|
||||
@@ -1,27 +1,21 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/DetectCudaArch.cmake")
|
||||
|
||||
if(SAMPLE_SKIP_BUILD)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(simpleD3D11Texture LANGUAGES C CXX CUDA)
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/CudaSampleCommon.cmake")
|
||||
|
||||
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)
|
||||
|
||||
if(WIN32)
|
||||
# Source file
|
||||
# Add target for simpleD3D11Texture
|
||||
add_executable(simpleD3D11Texture
|
||||
simpleD3D11Texture.cpp
|
||||
../../../Common/rendercheck_d3d11.cpp
|
||||
@@ -29,33 +23,24 @@ if(WIN32)
|
||||
texture_3d.cu
|
||||
texture_cube.cu
|
||||
)
|
||||
|
||||
target_compile_options(simpleD3D11Texture PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
|
||||
|
||||
target_compile_features(simpleD3D11Texture PRIVATE cxx_std_17 cuda_std_17)
|
||||
|
||||
set_target_properties(simpleD3D11Texture PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
target_include_directories(simpleD3D11Texture PRIVATE
|
||||
${CUDAToolkit_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(simpleD3D11Texture PRIVATE
|
||||
d3d11
|
||||
dxgi
|
||||
dxguid
|
||||
d3dcompiler
|
||||
)
|
||||
|
||||
add_custom_command(TARGET simpleD3D11Texture POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
include(InstallSamples)
|
||||
setup_samples_install()
|
||||
else()
|
||||
message(STATUS "Sample 'simpleD3D11Texture' is Windows-only - skipping")
|
||||
endif()
|
||||
|
||||
# Include installation configuration
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
|
||||
setup_samples_install()
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user