mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-23 21:28:17 +08:00
Add and update samples for cuda 11.0 support
This commit is contained in:
@@ -72,9 +72,9 @@ endif
|
||||
# architecture
|
||||
HOST_ARCH := $(shell uname -m)
|
||||
TARGET_ARCH ?= $(HOST_ARCH)
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 ppc64le armv7l))
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le armv7l))
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 ppc64le))
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le))
|
||||
TARGET_SIZE := 64
|
||||
else ifneq (,$(filter $(TARGET_ARCH),armv7l))
|
||||
TARGET_SIZE := 32
|
||||
@@ -85,8 +85,17 @@ ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 ppc64le armv7l))
|
||||
else
|
||||
$(error ERROR - unsupported value $(TARGET_ARCH) for TARGET_ARCH!)
|
||||
endif
|
||||
|
||||
# sbsa and aarch64 systems look similar. Need to differentiate them at host level for now.
|
||||
ifeq ($(HOST_ARCH),aarch64)
|
||||
ifeq ($(CUDA_PATH)/targets/sbsa-linux,$(shell ls -1d $(CUDA_PATH)/targets/sbsa-linux))
|
||||
HOST_ARCH := sbsa
|
||||
TARGET_ARCH := sbsa
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq (,$(filter $(HOST_ARCH)-$(TARGET_ARCH),aarch64-armv7l x86_64-armv7l x86_64-aarch64 x86_64-ppc64le))
|
||||
ifeq (,$(filter $(HOST_ARCH)-$(TARGET_ARCH),aarch64-armv7l x86_64-armv7l x86_64-aarch64 x86_64-sbsa x86_64-ppc64le))
|
||||
$(error ERROR - cross compiling from $(HOST_ARCH) to $(TARGET_ARCH) is not supported!)
|
||||
endif
|
||||
endif
|
||||
@@ -141,6 +150,8 @@ else ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
else ifeq ($(TARGET_OS), android)
|
||||
HOST_COMPILER ?= aarch64-linux-android-clang++
|
||||
endif
|
||||
else ifeq ($(TARGET_ARCH),sbsa)
|
||||
HOST_COMPILER ?= aarch64-linux-gnu-g++
|
||||
else ifeq ($(TARGET_ARCH),ppc64le)
|
||||
HOST_COMPILER ?= powerpc64le-linux-gnu-g++
|
||||
endif
|
||||
@@ -185,19 +196,27 @@ ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
CCFLAGS += --sysroot=$(TARGET_FS)
|
||||
endif
|
||||
LDFLAGS += --sysroot=$(TARGET_FS)
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib -L $(TARGET_FS)/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib -L $(TARGET_FS)/usr/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/aarch64-linux-gnu -L $(TARGET_FS)/usr/lib/aarch64-linux-gnu
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib -L$(TARGET_FS)/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib/aarch64-linux-gnu -L$(TARGET_FS)/lib/aarch64-linux-gnu
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib -L$(TARGET_FS)/usr/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/aarch64-linux-gnu -L$(TARGET_FS)/usr/lib/aarch64-linux-gnu
|
||||
LDFLAGS += --unresolved-symbols=ignore-in-shared-libs
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include/aarch64-linux-gnu
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include/aarch64-linux-gnu -I$(TARGET_FS)/usr/include/aarch64-linux-gnu
|
||||
endif
|
||||
endif
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
|
||||
CCFLAGS += -DWIN_INTERFACE_CUSTOM -I/usr/include/aarch64-qnx-gnu
|
||||
LDFLAGS += -lsocket
|
||||
LDFLAGS += -rpath=/usr/lib/aarch64-qnx-gnu -L/usr/lib/aarch64-qnx-gnu
|
||||
ifneq ($(TARGET_FS),)
|
||||
LDFLAGS += -rpath=$(TARGET_FS)/usr/lib -L $(TARGET_FS)/usr/lib
|
||||
LDFLAGS += -rpath=$(TARGET_FS)/usr/libnvidia -L $(TARGET_FS)/usr/libnvidia
|
||||
endif
|
||||
ifdef TARGET_OVERRIDE # cuda toolkit targets override
|
||||
NVCCFLAGS += -target-dir $(TARGET_OVERRIDE)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_OS),qnx)
|
||||
CCFLAGS += -DWIN_INTERFACE_CUSTOM
|
||||
LDFLAGS += -lsocket
|
||||
endif
|
||||
|
||||
# Install directory of different arch
|
||||
@@ -206,6 +225,8 @@ ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-gnueabihf/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),sbsa-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/sbsa-linux/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-android)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-androideabi/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-android)
|
||||
@@ -254,6 +275,12 @@ ifeq ($(TARGET_ARCH),aarch64)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
|
||||
# This sample is not supported on sbsa
|
||||
ifeq ($(TARGET_ARCH),sbsa)
|
||||
$(info >>> WARNING - memMapIPCDrv is not supported on sbsa - waiving sample <<<)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
|
||||
ALL_LDFLAGS :=
|
||||
ALL_LDFLAGS += $(ALL_CCFLAGS)
|
||||
ALL_LDFLAGS += $(addprefix -Xlinker ,$(LDFLAGS))
|
||||
@@ -275,8 +302,8 @@ ifeq ($(GENCODE_FLAGS),)
|
||||
$(foreach sm,$(SMS),$(eval GENCODE_FLAGS += -gencode arch=compute_$(sm),code=sm_$(sm)))
|
||||
|
||||
ifeq ($(SMS),)
|
||||
# Generate PTX code from SM 30
|
||||
GENCODE_FLAGS += -gencode arch=compute_30,code=compute_30
|
||||
# Generate PTX code from SM 35
|
||||
GENCODE_FLAGS += -gencode arch=compute_35,code=compute_35
|
||||
endif
|
||||
|
||||
# Generate PTX code from the highest SM architecture in $(SMS) to guarantee forward-compatibility
|
||||
@@ -302,6 +329,10 @@ else
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/targets/aarch64-linux/lib/stubs
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),sbsa-linux)
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/targets/sbsa-linux/lib/stubs
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-android)
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/targets/armv7-linux-androideabi/lib/stubs
|
||||
endif
|
||||
@@ -316,12 +347,19 @@ else
|
||||
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/targets/aarch64-qnx/lib/stubs
|
||||
ifdef TARGET_OVERRIDE
|
||||
CUDA_SEARCH_PATH := $(CUDA_PATH)/targets/$(TARGET_OVERRIDE)/lib/stubs
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_ARCH),ppc64le)
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/targets/ppc64le-linux/lib/stubs
|
||||
endif
|
||||
|
||||
ifeq ($(HOST_ARCH),ppc64le)
|
||||
CUDA_SEARCH_PATH += $(CUDA_PATH)/lib64/stubs
|
||||
endif
|
||||
|
||||
CUDALIB ?= $(shell find -L $(CUDA_SEARCH_PATH) -maxdepth 1 -name libcuda.so 2> /dev/null)
|
||||
ifeq ("$(CUDALIB)","")
|
||||
$(info >>> WARNING - libcuda.so not found, CUDA Driver is not installed. Please re-install the driver. <<<)
|
||||
|
||||
@@ -10,7 +10,7 @@ CUDA Driver API, cuMemMap IPC, MMAP
|
||||
|
||||
## Supported SM Architectures
|
||||
|
||||
[SM 3.0 ](https://developer.nvidia.com/cuda-gpus) [SM 3.5 ](https://developer.nvidia.com/cuda-gpus) [SM 3.7 ](https://developer.nvidia.com/cuda-gpus) [SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](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 3.5 ](https://developer.nvidia.com/cuda-gpus) [SM 3.7 ](https://developer.nvidia.com/cuda-gpus) [SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](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)
|
||||
|
||||
## Supported OSes
|
||||
|
||||
@@ -30,7 +30,7 @@ cuModuleLoad, cuModuleLoadDataEx, cuModuleGetFunction, cuLaunchKernel, cuMemcpyD
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Download and install the [CUDA Toolkit 10.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
||||
Download and install the [CUDA Toolkit 11.0](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
||||
Make sure the dependencies mentioned in [Dependencies]() section above are installed.
|
||||
|
||||
## Build and Run
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
<OutputFile>$(OutDir)/memMapIPCDrv.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_30,compute_30;</CodeGeneration>
|
||||
<CodeGeneration>compute_35,compute_35;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
<OutputFile>$(OutDir)/memMapIPCDrv.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_30,compute_30;</CodeGeneration>
|
||||
<CodeGeneration>compute_35,compute_35;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
<OutputFile>$(OutDir)/memMapIPCDrv.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_30,compute_30;</CodeGeneration>
|
||||
<CodeGeneration>compute_35,compute_35;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
<OutputFile>$(OutDir)/memMapIPCDrv.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_30,compute_30;</CodeGeneration>
|
||||
<CodeGeneration>compute_35,compute_35;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
<OutputFile>$(OutDir)/memMapIPCDrv.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_30,compute_30;</CodeGeneration>
|
||||
<CodeGeneration>compute_35,compute_35;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
|
||||
@@ -302,7 +302,7 @@ static void memMapGetDeviceFunction(char **argv) {
|
||||
cuModuleGetFunction(&_memMapIpc_kernel, cuModule, "memMapIpc_kernel"));
|
||||
}
|
||||
|
||||
static void childProcess(int id, char **argv) {
|
||||
static void childProcess(int devId, int id, char **argv) {
|
||||
volatile shmStruct *shm = NULL;
|
||||
sharedMemoryInfo info;
|
||||
ipcHandle *ipcChildHandle = NULL;
|
||||
@@ -329,7 +329,7 @@ static void childProcess(int id, char **argv) {
|
||||
CUstream stream;
|
||||
int multiProcessorCount;
|
||||
|
||||
checkCudaErrors(cuDeviceGet(&device, id));
|
||||
checkCudaErrors(cuDeviceGet(&device, devId));
|
||||
checkCudaErrors(cuCtxCreate(&ctx, 0, device));
|
||||
checkCudaErrors(cuStreamCreate(&stream, CU_STREAM_NON_BLOCKING));
|
||||
|
||||
@@ -350,7 +350,7 @@ static void childProcess(int id, char **argv) {
|
||||
|
||||
// Import the memory allocations shared by the parent with us and map them in
|
||||
// our address space.
|
||||
memMapImportAndMapMemory(d_ptr, DATA_BUF_SIZE, shHandle, id);
|
||||
memMapImportAndMapMemory(d_ptr, DATA_BUF_SIZE, shHandle, devId);
|
||||
|
||||
// Since we have imported allocations shared by the parent with us, we can
|
||||
// close all the ShareableHandles.
|
||||
@@ -424,7 +424,6 @@ static void parentProcess(char *app) {
|
||||
|
||||
checkCudaErrors(cuDeviceGetCount(&devCount));
|
||||
std::vector<CUdevice> devices(devCount);
|
||||
std::vector<CUcontext> ctxs(devCount);
|
||||
|
||||
if (sharedMemoryCreate(shmName, sizeof(*shm), &info) != 0) {
|
||||
printf("Failed to create shared memory slab\n");
|
||||
@@ -436,9 +435,11 @@ static void parentProcess(char *app) {
|
||||
|
||||
for (i = 0; i < devCount; i++) {
|
||||
checkCudaErrors(cuDeviceGet(&devices[i], i));
|
||||
checkCudaErrors(cuCtxCreate(&ctxs[i], 0, devices[i]));
|
||||
}
|
||||
|
||||
std::vector<CUcontext> ctxs;
|
||||
std::vector<unsigned char> selectedDevices;
|
||||
|
||||
// Pick all the devices that can access each other's memory for this test
|
||||
// Keep in mind that CUDA has minimal support for fork() without a
|
||||
// corresponding exec() in the child process, but in this case our
|
||||
@@ -500,6 +501,10 @@ static void parentProcess(char *app) {
|
||||
}
|
||||
}
|
||||
if (allPeers) {
|
||||
CUcontext ctx;
|
||||
checkCudaErrors(cuCtxCreate(&ctx, 0, devices[i]));
|
||||
ctxs.push_back(ctx);
|
||||
|
||||
// Enable peers here. This isn't necessary for IPC, but it will
|
||||
// setup the peers for the device. For systems that only allow 8
|
||||
// peers per GPU at a time, this acts to remove devices from CanAccessPeer
|
||||
@@ -509,6 +514,7 @@ static void parentProcess(char *app) {
|
||||
checkCudaErrors(cuCtxSetCurrent(ctxs[j]));
|
||||
checkCudaErrors(cuCtxEnablePeerAccess(ctxs[i], 0));
|
||||
}
|
||||
selectedDevices.push_back(i);
|
||||
nprocesses++;
|
||||
if (nprocesses >= MAX_DEVICES) {
|
||||
break;
|
||||
@@ -521,13 +527,17 @@ static void parentProcess(char *app) {
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < ctxs.size(); ++i) {
|
||||
checkCudaErrors(cuCtxDestroy(ctxs[i]));
|
||||
};
|
||||
|
||||
if (nprocesses == 0) {
|
||||
printf("No CUDA devices support IPC\n");
|
||||
exit(EXIT_WAIVED);
|
||||
}
|
||||
shm->nprocesses = nprocesses;
|
||||
|
||||
unsigned char firstSelectedDevice = 0;
|
||||
unsigned char firstSelectedDevice = selectedDevices[0];
|
||||
|
||||
std::vector<ShareableHandle> shHandles(nprocesses);
|
||||
std::vector<CUmemGenericAllocationHandle> allocationHandles(nprocesses);
|
||||
@@ -540,10 +550,12 @@ static void parentProcess(char *app) {
|
||||
// Launch the child processes!
|
||||
for (i = 0; i < nprocesses; i++) {
|
||||
char devIdx[10];
|
||||
char *const args[] = {app, devIdx, NULL};
|
||||
char procIdx[10];
|
||||
char *const args[] = {app, devIdx, procIdx, NULL};
|
||||
Process process;
|
||||
|
||||
SPRINTF(devIdx, "%d", i);
|
||||
SPRINTF(devIdx, "%d", selectedDevices[i]);
|
||||
SPRINTF(procIdx, "%d", i);
|
||||
|
||||
if (spawnProcess(&process, app, args)) {
|
||||
printf("Failed to create process\n");
|
||||
@@ -593,7 +605,7 @@ int main(int argc, char **argv) {
|
||||
if (argc == 1) {
|
||||
parentProcess(argv[0]);
|
||||
} else {
|
||||
childProcess(atoi(argv[1]), argv);
|
||||
childProcess(atoi(argv[1]), atoi(argv[2]), argv);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user