mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-23 21:28:17 +08:00
add and update samples with CUDA 11.3 support
This commit is contained in:
@@ -302,14 +302,10 @@ LIBRARIES :=
|
||||
|
||||
################################################################################
|
||||
|
||||
FATBIN_FILE := memMapIpc_kernel${TARGET_SIZE}.fatbin
|
||||
PTX_FILE := memMapIpc_kernel${TARGET_SIZE}.ptx
|
||||
|
||||
# Gencode arguments
|
||||
ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),armv7l aarch64))
|
||||
SMS ?= 35 37 50 52 60 61 70 72 75 80 86
|
||||
else
|
||||
SMS ?= 35 37 50 52 60 61 70 75 80 86
|
||||
endif
|
||||
SMS ?=
|
||||
|
||||
ifeq ($(GENCODE_FLAGS),)
|
||||
# Generate SASS code for each SM architecture listed in $(SMS)
|
||||
@@ -395,7 +391,7 @@ endif
|
||||
# Target rules
|
||||
all: build
|
||||
|
||||
build: memMapIPCDrv $(FATBIN_FILE)
|
||||
build: memMapIPCDrv $(PTX_FILE)
|
||||
|
||||
check.deps:
|
||||
ifeq ($(SAMPLE_ENABLED),0)
|
||||
@@ -404,8 +400,8 @@ else
|
||||
@echo "Sample is ready - all dependencies have been met"
|
||||
endif
|
||||
|
||||
$(FATBIN_FILE): memMapIpc_kernel.cu
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -fatbin $<
|
||||
$(PTX_FILE): memMapIpc_kernel.cu
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -ptx $<
|
||||
$(EXEC) mkdir -p data
|
||||
$(EXEC) cp -f $@ ./data
|
||||
$(EXEC) mkdir -p ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
|
||||
@@ -426,9 +422,8 @@ run: build
|
||||
$(EXEC) ./memMapIPCDrv
|
||||
|
||||
clean:
|
||||
rm -f memMapIPCDrv helper_multiprocess.o memMapIpc.o data/$(FATBIN_FILE) $(FATBIN_FILE)
|
||||
rm -f memMapIPCDrv helper_multiprocess.o memMapIpc.o data/$(PTX_FILE) $(PTX_FILE)
|
||||
rm -rf ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)/memMapIPCDrv
|
||||
|
||||
rm -rf ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)/$(FATBIN_FILE)
|
||||
rm -rf ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)/$(PTX_FILE)
|
||||
|
||||
clobber: clean
|
||||
|
||||
@@ -30,7 +30,7 @@ cuModuleLoad, cuModuleLoadDataEx, cuModuleGetFunction, cuLaunchKernel, cuMemcpyD
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Download and install the [CUDA Toolkit 11.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
||||
Download and install the [CUDA Toolkit 11.3](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
||||
Make sure the dependencies mentioned in [Dependencies]() section above are installed.
|
||||
|
||||
## Build and Run
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" />
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.3.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
|
||||
@@ -67,7 +67,7 @@
|
||||
<OutputFile>$(OutDir)/memMapIPCDrv.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_35,compute_35;compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75;compute_80,sm_80;compute_86,sm_86;</CodeGeneration>
|
||||
<CodeGeneration>compute_35,compute_35;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
@@ -105,14 +105,14 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="memMapIpc.cpp" />
|
||||
<CudaCompile Include="memMapIpc_kernel.cu">
|
||||
<CompileOut Condition="'$(Platform)'=='x64'">data/%(Filename)64.fatbin</CompileOut>
|
||||
<NvccCompilation>fatbin</NvccCompilation>
|
||||
<CompileOut Condition="'$(Platform)'=='x64'">data/%(Filename)64.ptx</CompileOut>
|
||||
<NvccCompilation>ptx</NvccCompilation>
|
||||
</CudaCompile>
|
||||
<ClCompile Include="../../Common/helper_multiprocess.cpp" />
|
||||
<ClInclude Include="../../Common/helper_multiprocess.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" />
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.3.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.2.props" />
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.3.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
|
||||
@@ -63,7 +63,7 @@
|
||||
<OutputFile>$(OutDir)/memMapIPCDrv.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_35,compute_35;compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75;compute_80,sm_80;compute_86,sm_86;</CodeGeneration>
|
||||
<CodeGeneration>compute_35,compute_35;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
@@ -101,14 +101,14 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="memMapIpc.cpp" />
|
||||
<CudaCompile Include="memMapIpc_kernel.cu">
|
||||
<CompileOut Condition="'$(Platform)'=='x64'">data/%(Filename)64.fatbin</CompileOut>
|
||||
<NvccCompilation>fatbin</NvccCompilation>
|
||||
<CompileOut Condition="'$(Platform)'=='x64'">data/%(Filename)64.ptx</CompileOut>
|
||||
<NvccCompilation>ptx</NvccCompilation>
|
||||
</CudaCompile>
|
||||
<ClCompile Include="../../Common/helper_multiprocess.cpp" />
|
||||
<ClInclude Include="../../Common/helper_multiprocess.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.2.targets" />
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.3.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
|
||||
@@ -64,9 +64,13 @@ typedef struct shmStruct_st {
|
||||
int sense;
|
||||
} shmStruct;
|
||||
|
||||
// define input fatbin file
|
||||
#ifndef FATBIN_FILE
|
||||
#define FATBIN_FILE "memMapIpc_kernel64.fatbin"
|
||||
bool findModulePath(const char *, string &, char **, string &);
|
||||
|
||||
// define input ptx file for different platforms
|
||||
#if defined(_WIN64) || defined(__LP64__)
|
||||
#define PTX_FILE "memMapIpc_kernel64.ptx"
|
||||
#else
|
||||
#define PTX_FILE "memMapIpc_kernel32.ptx"
|
||||
#endif
|
||||
|
||||
// `ipcHandleTypeFlag` specifies the platform specific handle type this sample
|
||||
@@ -255,23 +259,44 @@ static void memMapUnmapAndFreeMemory(CUdeviceptr dptr, size_t size) {
|
||||
|
||||
static void memMapGetDeviceFunction(char **argv) {
|
||||
// first search for the module path before we load the results
|
||||
string module_path;
|
||||
std::ostringstream fatbin;
|
||||
|
||||
if (!findFatbinPath(FATBIN_FILE, module_path, argv, fatbin)) {
|
||||
exit(EXIT_FAILURE);
|
||||
string module_path, ptx_source;
|
||||
if (!findModulePath(PTX_FILE, module_path, argv, ptx_source)) {
|
||||
if (!findModulePath("memMapIpc_kernel.cubin", module_path, argv,
|
||||
ptx_source)) {
|
||||
printf(
|
||||
"> findModulePath could not find <simpleMemMapIpc> ptx or cubin\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
printf("> initCUDA loading module: <%s>\n", module_path.c_str());
|
||||
}
|
||||
|
||||
if (!fatbin.str().size()) {
|
||||
printf("fatbin file empty. exiting..\n");
|
||||
exit(EXIT_FAILURE);
|
||||
// Create module from binary file (PTX or CUBIN)
|
||||
if (module_path.rfind("ptx") != string::npos) {
|
||||
// in this branch we use compilation with parameters
|
||||
const unsigned int jitNumOptions = 3;
|
||||
CUjit_option *jitOptions = new CUjit_option[jitNumOptions];
|
||||
void **jitOptVals = new void *[jitNumOptions];
|
||||
// set up size of compilation log buffer
|
||||
jitOptions[0] = CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES;
|
||||
int jitLogBufferSize = 1024;
|
||||
jitOptVals[0] = (void *)(size_t)jitLogBufferSize;
|
||||
// set up pointer to the compilation log buffer
|
||||
jitOptions[1] = CU_JIT_INFO_LOG_BUFFER;
|
||||
char *jitLogBuffer = new char[jitLogBufferSize];
|
||||
jitOptVals[1] = jitLogBuffer;
|
||||
// set up pointer to set the Maximum # of registers for a particular kernel
|
||||
jitOptions[2] = CU_JIT_MAX_REGISTERS;
|
||||
int jitRegCount = 32;
|
||||
jitOptVals[2] = (void *)(size_t)jitRegCount;
|
||||
checkCudaErrors(cuModuleLoadDataEx(&cuModule, ptx_source.c_str(),
|
||||
jitNumOptions, jitOptions,
|
||||
(void **)jitOptVals));
|
||||
printf("> PTX JIT log:\n%s\n", jitLogBuffer);
|
||||
} else {
|
||||
checkCudaErrors(cuModuleLoad(&cuModule, module_path.c_str()));
|
||||
}
|
||||
|
||||
// Create module from binary file (FATBIN)
|
||||
checkCudaErrors(cuModuleLoadData(&cuModule, fatbin.str().c_str()));
|
||||
|
||||
// Get function handle from module
|
||||
checkCudaErrors(
|
||||
cuModuleGetFunction(&_memMapIpc_kernel, cuModule, "memMapIpc_kernel"));
|
||||
@@ -585,3 +610,37 @@ int main(int argc, char **argv) {
|
||||
return EXIT_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool inline findModulePath(const char *module_file, string &module_path,
|
||||
char **argv, string &ptx_source) {
|
||||
char *actual_path = sdkFindFilePath(module_file, argv[0]);
|
||||
|
||||
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(".ptx") != string::npos) {
|
||||
FILE *fp = fopen(module_path.c_str(), "rb");
|
||||
fseek(fp, 0, SEEK_END);
|
||||
int file_size = ftell(fp);
|
||||
char *buf = new char[file_size + 1];
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
fread(buf, sizeof(char), file_size, fp);
|
||||
fclose(fp);
|
||||
buf[file_size] = '\0';
|
||||
ptx_source = buf;
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user