mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-23 13:18:16 +08:00
Add and update samples for cuda 11.1 support
This commit is contained in:
BIN
Common/data/CT_skull_512x512_8u.raw
Normal file
BIN
Common/data/CT_skull_512x512_8u.raw
Normal file
Binary file not shown.
BIN
Common/data/CT_skull_512x512_8u_Gray.raw
Normal file
BIN
Common/data/CT_skull_512x512_8u_Gray.raw
Normal file
Binary file not shown.
1
Common/data/Lena_512x512_8u_Gray.raw
Normal file
1
Common/data/Lena_512x512_8u_Gray.raw
Normal file
File diff suppressed because one or more lines are too long
BIN
Common/data/PCB2_1024x683_8u.raw
Normal file
BIN
Common/data/PCB2_1024x683_8u.raw
Normal file
Binary file not shown.
BIN
Common/data/PCB_1280x720_8u.raw
Normal file
BIN
Common/data/PCB_1280x720_8u.raw
Normal file
Binary file not shown.
BIN
Common/data/PCB_METAL_509x335_8u.raw
Normal file
BIN
Common/data/PCB_METAL_509x335_8u.raw
Normal file
Binary file not shown.
285
Common/data/Rocks_512x512_8u_Gray.raw
Normal file
285
Common/data/Rocks_512x512_8u_Gray.raw
Normal file
File diff suppressed because one or more lines are too long
BIN
Common/data/lena_512x512_8u.raw
Normal file
BIN
Common/data/lena_512x512_8u.raw
Normal file
Binary file not shown.
@@ -664,6 +664,7 @@ inline int _ConvertSMVer2Cores(int major, int minor) {
|
||||
{0x72, 64},
|
||||
{0x75, 64},
|
||||
{0x80, 64},
|
||||
{0x86, 128},
|
||||
{-1, -1}};
|
||||
|
||||
int index = 0;
|
||||
@@ -709,6 +710,7 @@ inline const char* _ConvertSMVer2ArchName(int major, int minor) {
|
||||
{0x72, "Xavier"},
|
||||
{0x75, "Turing"},
|
||||
{0x80, "Ampere"},
|
||||
{0x86, "Ampere"},
|
||||
{-1, "Graphics Device"}};
|
||||
|
||||
int index = 0;
|
||||
|
||||
@@ -33,8 +33,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
#include <drvapi_error_string.h>
|
||||
#include <helper_string.h>
|
||||
|
||||
#ifndef MAX
|
||||
@@ -66,48 +68,22 @@ inline int ftoi(float value) {
|
||||
// These are the inline versions for all of the SDK helper functions
|
||||
inline void __checkCudaErrors(CUresult err, const char *file, const int line) {
|
||||
if (CUDA_SUCCESS != err) {
|
||||
const char *errorStr = NULL;
|
||||
cuGetErrorString(err, &errorStr);
|
||||
fprintf(stderr,
|
||||
"checkCudaErrors() Driver API error = %04d \"%s\" from file <%s>, "
|
||||
"line %i.\n",
|
||||
err, getCudaDrvErrorString(err), file, line);
|
||||
err, errorStr, file, line);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef getLastCudaDrvErrorMsg
|
||||
#undef getLastCudaDrvErrorMsg
|
||||
#endif
|
||||
|
||||
#define getLastCudaDrvErrorMsg(msg) \
|
||||
__getLastCudaDrvErrorMsg(msg, __FILE__, __LINE__)
|
||||
|
||||
inline void __getLastCudaDrvErrorMsg(const char *msg, const char *file,
|
||||
const int line) {
|
||||
CUresult err = cuCtxSynchronize();
|
||||
|
||||
if (CUDA_SUCCESS != err) {
|
||||
fprintf(stderr, "getLastCudaDrvErrorMsg -> %s", msg);
|
||||
fprintf(stderr,
|
||||
"getLastCudaDrvErrorMsg -> cuCtxSynchronize API error = %04d "
|
||||
"\"%s\" in file <%s>, line %i.\n",
|
||||
err, getCudaDrvErrorString(err), file, line);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// This function wraps the CUDA Driver API into a template function
|
||||
template <class T>
|
||||
inline void getCudaAttribute(T *attribute, CUdevice_attribute device_attribute,
|
||||
int device) {
|
||||
CUresult error_result =
|
||||
cuDeviceGetAttribute(attribute, device_attribute, device);
|
||||
|
||||
if (error_result != CUDA_SUCCESS) {
|
||||
printf("cuDeviceGetAttribute returned %d\n-> %s\n",
|
||||
static_cast<int>(error_result), getCudaDrvErrorString(error_result));
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
checkCudaErrors(cuDeviceGetAttribute(attribute, device_attribute, device));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -135,6 +111,8 @@ inline int _ConvertSMVer2CoresDRV(int major, int minor) {
|
||||
{0x70, 64},
|
||||
{0x72, 64},
|
||||
{0x75, 64},
|
||||
{0x80, 64},
|
||||
{0x86, 128},
|
||||
{-1, -1}};
|
||||
|
||||
int index = 0;
|
||||
@@ -161,11 +139,9 @@ inline int _ConvertSMVer2CoresDRV(int major, int minor) {
|
||||
inline int gpuDeviceInitDRV(int ARGC, const char **ARGV) {
|
||||
int cuDevice = 0;
|
||||
int deviceCount = 0;
|
||||
CUresult err = cuInit(0);
|
||||
checkCudaErrors(cuInit(0));
|
||||
|
||||
if (CUDA_SUCCESS == err) {
|
||||
checkCudaErrors(cuDeviceGetCount(&deviceCount));
|
||||
}
|
||||
checkCudaErrors(cuDeviceGetCount(&deviceCount));
|
||||
|
||||
if (deviceCount == 0) {
|
||||
fprintf(stderr, "cudaDeviceInit error: no devices supporting CUDA\n");
|
||||
@@ -192,7 +168,7 @@ inline int gpuDeviceInitDRV(int ARGC, const char **ARGV) {
|
||||
|
||||
checkCudaErrors(cuDeviceGet(&cuDevice, dev));
|
||||
char name[100];
|
||||
cuDeviceGetName(name, 100, cuDevice);
|
||||
checkCudaErrors(cuDeviceGetName(name, 100, cuDevice));
|
||||
|
||||
int computeMode;
|
||||
getCudaAttribute<int>(&computeMode, CU_DEVICE_ATTRIBUTE_COMPUTE_MODE, dev);
|
||||
@@ -218,7 +194,6 @@ inline int gpuGetMaxGflopsDeviceIdDRV() {
|
||||
int device_count = 0;
|
||||
int sm_per_multiproc = 0;
|
||||
unsigned long long max_compute_perf = 0;
|
||||
int best_SM_arch = 0;
|
||||
int major = 0;
|
||||
int minor = 0;
|
||||
int multiProcessorCount;
|
||||
@@ -234,19 +209,6 @@ inline int gpuGetMaxGflopsDeviceIdDRV() {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Find the best major SM Architecture GPU device
|
||||
while (current_device < device_count) {
|
||||
checkCudaErrors(cuDeviceGetAttribute(
|
||||
&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, current_device));
|
||||
checkCudaErrors(cuDeviceGetAttribute(
|
||||
&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, current_device));
|
||||
if (major > 0 && major < 9999) {
|
||||
best_SM_arch = MAX(best_SM_arch, major);
|
||||
}
|
||||
|
||||
current_device++;
|
||||
}
|
||||
|
||||
// Find the best CUDA capable GPU device
|
||||
current_device = 0;
|
||||
|
||||
@@ -277,17 +239,8 @@ inline int gpuGetMaxGflopsDeviceIdDRV() {
|
||||
clockRate);
|
||||
|
||||
if (compute_perf > max_compute_perf) {
|
||||
// If we find GPU with SM major > 2, search only these
|
||||
if (best_SM_arch > 2) {
|
||||
// If our device==dest_SM_arch, choose this, or else pass
|
||||
if (major == best_SM_arch) {
|
||||
max_compute_perf = compute_perf;
|
||||
max_perf_device = current_device;
|
||||
}
|
||||
} else {
|
||||
max_compute_perf = compute_perf;
|
||||
max_perf_device = current_device;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
devices_prohibited++;
|
||||
@@ -414,7 +367,39 @@ inline bool checkCudaCapabilitiesDRV(int major_version, int minor_version,
|
||||
}
|
||||
}
|
||||
#endif
|
||||
bool inline findFatbinPath(const char *module_file, std::string &module_path, char **argv, std::ostringstream &ostrm)
|
||||
{
|
||||
char *actual_path = sdkFindFilePath(module_file, argv[0]);
|
||||
|
||||
// end of CUDA Helper Functions
|
||||
if (actual_path)
|
||||
{
|
||||
module_path = actual_path;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("> findModulePath file not found: <%s> \n", module_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (module_path.empty())
|
||||
{
|
||||
printf("> findModulePath could not find file: <%s> \n", module_file);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("> findModulePath found file at <%s>\n", module_path.c_str());
|
||||
if (module_path.rfind("fatbin") != std::string::npos)
|
||||
{
|
||||
std::ifstream fileIn(module_path.c_str(), std::ios::binary);
|
||||
ostrm << fileIn.rdbuf();
|
||||
fileIn.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// end of CUDA Helper Functions
|
||||
|
||||
#endif // COMMON_HELPER_CUDA_DRVAPI_H_
|
||||
|
||||
|
||||
@@ -293,6 +293,9 @@ inline char *sdkFindFilePath(const char *filename,
|
||||
"../../../../Samples/<executable_name>/data/", // up 4 in tree
|
||||
"../../../Samples/<executable_name>/data/", // up 3 in tree
|
||||
"../../Samples/<executable_name>/data/", // up 2 in tree
|
||||
"../../../../Common/data/", // up 4 in tree
|
||||
"../../../Common/data", // up 3 in tree
|
||||
"../../Common/data/" // up 2 in tree
|
||||
};
|
||||
|
||||
// Extract the executable name
|
||||
|
||||
@@ -47,8 +47,8 @@
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void compileFileToPTX(char *filename, int argc, char **argv, char **ptxResult,
|
||||
size_t *ptxResultSize, int requiresCGheaders) {
|
||||
void compileFileToCUBIN(char *filename, int argc, char **argv, char **cubinResult,
|
||||
size_t *cubinResultSize, int requiresCGheaders) {
|
||||
std::ifstream inputFile(filename,
|
||||
std::ios::in | std::ios::binary | std::ios::ate);
|
||||
|
||||
@@ -83,9 +83,9 @@ void compileFileToPTX(char *filename, int argc, char **argv, char **ptxResult,
|
||||
&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, cuDevice));
|
||||
|
||||
{
|
||||
// Compile for the GPU arch on which are going to run cuda kernel.
|
||||
// Compile cubin for the GPU arch on which are going to run cuda kernel.
|
||||
std::string compileOptions;
|
||||
compileOptions = "--gpu-architecture=compute_";
|
||||
compileOptions = "--gpu-architecture=sm_";
|
||||
|
||||
compileParams[numCompileOptions] = reinterpret_cast<char *>(
|
||||
malloc(sizeof(char) * (compileOptions.length() + 10)));
|
||||
@@ -158,21 +158,20 @@ void compileFileToPTX(char *filename, int argc, char **argv, char **ptxResult,
|
||||
free(log);
|
||||
|
||||
NVRTC_SAFE_CALL("nvrtcCompileProgram", res);
|
||||
// fetch PTX
|
||||
size_t ptxSize;
|
||||
NVRTC_SAFE_CALL("nvrtcGetPTXSize", nvrtcGetPTXSize(prog, &ptxSize));
|
||||
char *ptx = reinterpret_cast<char *>(malloc(sizeof(char) * ptxSize));
|
||||
NVRTC_SAFE_CALL("nvrtcGetPTX", nvrtcGetPTX(prog, ptx));
|
||||
NVRTC_SAFE_CALL("nvrtcDestroyProgram", nvrtcDestroyProgram(&prog));
|
||||
*ptxResult = ptx;
|
||||
*ptxResultSize = ptxSize;
|
||||
|
||||
size_t codeSize;
|
||||
NVRTC_SAFE_CALL("nvrtcGetCUBINSize", nvrtcGetCUBINSize(prog, &codeSize));
|
||||
char *code = new char[codeSize];
|
||||
NVRTC_SAFE_CALL("nvrtcGetCUBIN", nvrtcGetCUBIN(prog, code));
|
||||
*cubinResult = code;
|
||||
*cubinResultSize = codeSize;
|
||||
|
||||
for (int i = 0; i < numCompileOptions; i++) {
|
||||
free(compileParams[i]);
|
||||
}
|
||||
}
|
||||
|
||||
CUmodule loadPTX(char *ptx, int argc, char **argv) {
|
||||
CUmodule loadCUBIN(char *cubin, int argc, char **argv) {
|
||||
CUmodule module;
|
||||
CUcontext context;
|
||||
int major = 0, minor = 0;
|
||||
@@ -190,11 +189,10 @@ CUmodule loadPTX(char *ptx, int argc, char **argv) {
|
||||
printf("> GPU Device has SM %d.%d compute capability\n", major, minor);
|
||||
|
||||
checkCudaErrors(cuInit(0));
|
||||
checkCudaErrors(cuDeviceGet(&cuDevice, 0));
|
||||
checkCudaErrors(cuCtxCreate(&context, 0, cuDevice));
|
||||
|
||||
checkCudaErrors(cuModuleLoadDataEx(&module, ptx, 0, 0, 0));
|
||||
free(ptx);
|
||||
checkCudaErrors(cuModuleLoadData(&module, cubin));
|
||||
free(cubin);
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user