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.0 support
This commit is contained in:
BIN
Common/FreeImage/lib/linux/sbsa/libfreeimage.a
Normal file
BIN
Common/FreeImage/lib/linux/sbsa/libfreeimage.a
Normal file
Binary file not shown.
@@ -663,6 +663,7 @@ inline int _ConvertSMVer2Cores(int major, int minor) {
|
||||
{0x70, 64},
|
||||
{0x72, 64},
|
||||
{0x75, 64},
|
||||
{0x80, 64},
|
||||
{-1, -1}};
|
||||
|
||||
int index = 0;
|
||||
@@ -707,6 +708,7 @@ inline const char* _ConvertSMVer2ArchName(int major, int minor) {
|
||||
{0x70, "Volta"},
|
||||
{0x72, "Xavier"},
|
||||
{0x75, "Turing"},
|
||||
{0x80, "Ampere"},
|
||||
{-1, "Graphics Device"}};
|
||||
|
||||
int index = 0;
|
||||
@@ -817,7 +819,19 @@ inline int gpuGetMaxGflopsDeviceId() {
|
||||
}
|
||||
int multiProcessorCount = 0, clockRate = 0;
|
||||
checkCudaErrors(cudaDeviceGetAttribute(&multiProcessorCount, cudaDevAttrMultiProcessorCount, current_device));
|
||||
checkCudaErrors(cudaDeviceGetAttribute(&clockRate, cudaDevAttrClockRate, current_device));
|
||||
cudaError_t result = cudaDeviceGetAttribute(&clockRate, cudaDevAttrClockRate, current_device);
|
||||
if (result != cudaSuccess) {
|
||||
// If cudaDevAttrClockRate attribute is not supported we
|
||||
// set clockRate as 1, to consider GPU with most SMs and CUDA Cores.
|
||||
if(result == cudaErrorInvalidValue) {
|
||||
clockRate = 1;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \n", __FILE__, __LINE__,
|
||||
static_cast<unsigned int>(result), _cudaGetErrorEnum(result));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
uint64_t compute_perf = (uint64_t)multiProcessorCount * sm_per_multiproc * clockRate;
|
||||
|
||||
if (compute_perf > max_compute_perf) {
|
||||
|
||||
@@ -475,38 +475,19 @@ int ipcSendData(HANDLE mailslot, const void *data, size_t sz) {
|
||||
}
|
||||
|
||||
int ipcRecvData(ipcHandle *handle, void *data, size_t sz) {
|
||||
DWORD cbMessage, cMessage, cbRead;
|
||||
BOOL fResult;
|
||||
DWORD cbRead = 0;
|
||||
|
||||
cbMessage = cMessage = cbRead = 0;
|
||||
HANDLE mailslot = handle->hMailslot[0];
|
||||
|
||||
pollMailSlot:
|
||||
fResult = GetMailslotInfo(mailslot, (LPDWORD)NULL, &cbMessage, &cMessage,
|
||||
(LPDWORD)NULL);
|
||||
if (!fResult) {
|
||||
printf("IPC failure: GetMailslotInfo failed with %d.\n", GetLastError());
|
||||
if (!ReadFile(handle->hMailslot[0], data, (DWORD)sz, &cbRead, NULL)) {
|
||||
printf("IPC failure: ReadFile failed with %d.\n", GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cbMessage == MAILSLOT_NO_MESSAGE) {
|
||||
goto pollMailSlot;
|
||||
if (sz != (size_t)cbRead) {
|
||||
printf(
|
||||
"IPC failure: ReadFile didn't receive the expected number of bytes\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (cMessage != 0) {
|
||||
fResult = ReadFile(mailslot, data, (DWORD)sz, &cbRead, NULL);
|
||||
if (!fResult) {
|
||||
printf("IPC failure: ReadFile failed with %d.\n", GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
fResult = GetMailslotInfo(mailslot, (LPDWORD)NULL, &cbMessage, &cMessage,
|
||||
(LPDWORD)NULL);
|
||||
if (!fResult) {
|
||||
printf("IPC failure: GetMailslotInfo failed (%d)\n", GetLastError());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -530,7 +511,7 @@ int ipcSendShareableHandles(
|
||||
printf("IPC failure: DuplicateHandle failed (%d)\n", GetLastError());
|
||||
return -1;
|
||||
}
|
||||
checkIpcErrors(ipcSendData(handle->hMailslot[i], &hDup, sizeof(HANDLE)));
|
||||
checkIpcErrors(ipcSendData(handle->hMailslot[i], &hDup, sizeof(hDup)));
|
||||
}
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,37 @@ void compileFileToPTX(char *filename, int argc, char **argv, char **ptxResult,
|
||||
|
||||
int numCompileOptions = 0;
|
||||
|
||||
char *compileParams[1];
|
||||
char *compileParams[2];
|
||||
|
||||
int major = 0, minor = 0;
|
||||
char deviceName[256];
|
||||
|
||||
// Picks the best CUDA device available
|
||||
CUdevice cuDevice = findCudaDeviceDRV(argc, (const char **)argv);
|
||||
|
||||
// get compute capabilities and the devicename
|
||||
checkCudaErrors(cuDeviceGetAttribute(
|
||||
&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, cuDevice));
|
||||
checkCudaErrors(cuDeviceGetAttribute(
|
||||
&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, cuDevice));
|
||||
|
||||
{
|
||||
// Compile for the GPU arch on which are going to run cuda kernel.
|
||||
std::string compileOptions;
|
||||
compileOptions = "--gpu-architecture=compute_";
|
||||
|
||||
compileParams[numCompileOptions] = reinterpret_cast<char *>(
|
||||
malloc(sizeof(char) * (compileOptions.length() + 10)));
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
||||
sprintf_s(compileParams[numCompileOptions], sizeof(char) * (compileOptions.length() + 10),
|
||||
"%s%d%d", compileOptions.c_str(), major, minor);
|
||||
#else
|
||||
snprintf(compileParams[numCompileOptions], compileOptions.size() + 10, "%s%d%d",
|
||||
compileOptions.c_str(), major, minor);
|
||||
#endif
|
||||
}
|
||||
|
||||
numCompileOptions++;
|
||||
|
||||
if (requiresCGheaders) {
|
||||
std::string compileOptions;
|
||||
@@ -92,13 +122,13 @@ void compileFileToPTX(char *filename, int argc, char **argv, char **ptxResult,
|
||||
argv[0]);
|
||||
}
|
||||
compileOptions += path.c_str();
|
||||
compileParams[0] = reinterpret_cast<char *>(
|
||||
compileParams[numCompileOptions] = reinterpret_cast<char *>(
|
||||
malloc(sizeof(char) * (compileOptions.length() + 1)));
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
||||
sprintf_s(compileParams[0], sizeof(char) * (compileOptions.length() + 1),
|
||||
sprintf_s(compileParams[numCompileOptions], sizeof(char) * (compileOptions.length() + 1),
|
||||
"%s", compileOptions.c_str());
|
||||
#else
|
||||
snprintf(compileParams[0], compileOptions.size(), "%s",
|
||||
snprintf(compileParams[numCompileOptions], compileOptions.size(), "%s",
|
||||
compileOptions.c_str());
|
||||
#endif
|
||||
numCompileOptions++;
|
||||
@@ -137,7 +167,9 @@ void compileFileToPTX(char *filename, int argc, char **argv, char **ptxResult,
|
||||
*ptxResult = ptx;
|
||||
*ptxResultSize = ptxSize;
|
||||
|
||||
if (requiresCGheaders) free(compileParams[0]);
|
||||
for (int i = 0; i < numCompileOptions; i++) {
|
||||
free(compileParams[i]);
|
||||
}
|
||||
}
|
||||
|
||||
CUmodule loadPTX(char *ptx, int argc, char **argv) {
|
||||
|
||||
Reference in New Issue
Block a user