Bug 5196362, 5184356, 5212196, 5214258 and 5214259: Update sameples for CUDA13.0 API changes

This commit is contained in:
shawnz
2025-04-10 18:27:18 +08:00
parent 278f4adbd2
commit 02fdb070ad
27 changed files with 181 additions and 116 deletions

View File

@@ -247,7 +247,9 @@ int main(int argc, char **argv)
exit(EXIT_WAIVED);
}
if (device_prop.computeMode == cudaComputeModeProhibited) {
int computeMode;
checkCudaErrors(cudaDeviceGetAttribute(&computeMode, cudaDevAttrComputeMode, dev_id));
if (computeMode == cudaComputeModeProhibited) {
// This sample requires being run with a default or process exclusive mode
fprintf(stderr,
"This sample requires a device in either default or process "

View File

@@ -268,9 +268,10 @@ void randomInit(float *data, int size)
static int initCUDA(int argc, char **argv, CUfunction *pMatrixMul, int *blk_size)
{
CUfunction cuFunction = 0;
int major = 0, minor = 0;
char deviceName[100];
CUfunction cuFunction = 0;
int major = 0, minor = 0;
char deviceName[100];
CUctxCreateParams ctxCreateParams = {};
cuDevice = findCudaDeviceDRV(argc, (const char **)argv);
@@ -283,7 +284,7 @@ static int initCUDA(int argc, char **argv, CUfunction *pMatrixMul, int *blk_size
checkCudaErrors(cuDeviceTotalMem(&totalGlobalMem, cuDevice));
printf(" Total amount of global memory: %llu bytes\n", (long long unsigned int)totalGlobalMem);
checkCudaErrors(cuCtxCreate(&cuContext, 0, cuDevice));
checkCudaErrors(cuCtxCreate(&cuContext, &ctxCreateParams, 0, cuDevice));
// first search for the module path before we load the results
std::string module_path;

View File

@@ -80,19 +80,20 @@ static void check(CUresult result, char const *const func, const char *const fil
int main(int argc, char **argv)
{
printf("simpleDrvRuntime..\n");
int N = 50000, devID = 0;
size_t size = N * sizeof(float);
CUdevice cuDevice;
CUfunction vecAdd_kernel;
CUmodule cuModule = 0;
CUcontext cuContext;
int N = 50000, devID = 0;
size_t size = N * sizeof(float);
CUdevice cuDevice;
CUfunction vecAdd_kernel;
CUmodule cuModule = 0;
CUcontext cuContext;
CUctxCreateParams ctxCreateParams = {};
// Initialize
checkCudaDrvErrors(cuInit(0));
cuDevice = findCudaDevice(argc, (const char **)argv);
// Create context
checkCudaDrvErrors(cuCtxCreate(&cuContext, 0, cuDevice));
checkCudaDrvErrors(cuCtxCreate(&cuContext, &ctxCreateParams, 0, cuDevice));
// first search for the module path before we load the results
string module_path;

View File

@@ -127,6 +127,10 @@ int main(int argc, char **argv)
checkCudaErrors(cudaGetDevice(&cuda_device));
checkCudaErrors(cudaGetDeviceProperties(&deviceProp, cuda_device));
// Get device clock rate
int clockRate;
checkCudaErrors(cudaDeviceGetAttribute(&clockRate, cudaDevAttrClockRate, cuda_device));
// HyperQ is available in devices of Compute Capability 3.5 and higher
if (deviceProp.major < 3 || (deviceProp.major == 3 && deviceProp.minor < 5)) {
if (deviceProp.concurrentKernels == 0) {
@@ -170,9 +174,9 @@ int main(int argc, char **argv)
#if defined(__arm__) || defined(__aarch64__)
// the kernel takes more time than the channel reset time on arm archs, so to
// prevent hangs reduce time_clocks.
clock_t time_clocks = (clock_t)(kernel_time * (deviceProp.clockRate / 100));
clock_t time_clocks = (clock_t)(kernel_time * (clockRate / 100));
#else
clock_t time_clocks = (clock_t)(kernel_time * deviceProp.clockRate);
clock_t time_clocks = (clock_t)(kernel_time * clockRate);
#endif
clock_t total_clocks = 0;

View File

@@ -218,9 +218,11 @@ int main(int argc, char *argv[])
printf("\n");
printf("Relevant properties of this CUDA device\n");
int canOverlap;
checkCudaErrors(cudaDeviceGetAttribute(&canOverlap, cudaDevAttrGpuOverlap, cuda_device));
printf("(%s) Can overlap one CPU<>GPU data transfer with GPU kernel execution "
"(device property \"deviceOverlap\")\n",
deviceProp.deviceOverlap ? "X" : " ");
"(device property \"cudaDevAttrGpuOverlap\")\n",
canOverlap ? "X" : " ");
// printf("(%s) Can execute several GPU kernels simultaneously (compute
// capability >= 2.0)\n", deviceProp.major >= 2 ? "X": " ");
printf("(%s) Can overlap two CPU<>GPU data transfers with GPU kernel execution\n"

View File

@@ -309,10 +309,11 @@ void runTest(int argc, char **argv)
////////////////////////////////////////////////////////////////////////////////
static CUresult initCUDA(int argc, char **argv, CUfunction *transform)
{
CUfunction cuFunction = 0;
int major = 0, minor = 0, devID = 0;
char deviceName[100];
string module_path;
CUfunction cuFunction = 0;
int major = 0, minor = 0, devID = 0;
char deviceName[100];
string module_path;
CUctxCreateParams ctxCreateParams = {};
cuDevice = findCudaDeviceDRV(argc, (const char **)argv);
@@ -322,7 +323,7 @@ static CUresult initCUDA(int argc, char **argv, CUfunction *transform)
checkCudaErrors(cuDeviceGetName(deviceName, sizeof(deviceName), cuDevice));
printf("> GPU Device has SM %d.%d compute capability\n", major, minor);
checkCudaErrors(cuCtxCreate(&cuContext, 0, cuDevice));
checkCudaErrors(cuCtxCreate(&cuContext, &ctxCreateParams, 0, cuDevice));
// first search for the module_path before we try to load the results
std::ostringstream fatbin;

View File

@@ -75,15 +75,16 @@ bool findModulePath(const char *, string &, char **, string &);
int main(int argc, char **argv)
{
printf("Vector Addition (Driver API)\n");
int N = 50000, devID = 0;
size_t size = N * sizeof(float);
int N = 50000, devID = 0;
size_t size = N * sizeof(float);
CUctxCreateParams ctxCreateParams = {};
// Initialize
checkCudaErrors(cuInit(0));
cuDevice = findCudaDeviceDRV(argc, (const char **)argv);
// Create context
checkCudaErrors(cuCtxCreate(&cuContext, 0, cuDevice));
checkCudaErrors(cuCtxCreate(&cuContext, &ctxCreateParams, 0, cuDevice));
// first search for the module path before we load the results
string module_path;