Updating Samples for 12.3 and updating props files

This commit is contained in:
Rob Nertney
2023-10-23 18:44:49 +00:00
parent c46754b877
commit b5c84e6996
584 changed files with 2725 additions and 1167 deletions

View File

@@ -87,7 +87,7 @@ message(STATUS "Using rpath: ${CMAKE_INSTALL_RPATH}")
# On Windows, locate the nvvm.dll so we can install it.
if (WIN32)
find_file(NVVM_DLL nvvm64_40_0.dll PATHS "${LIBNVVM_HOME}/bin")
if (NOT NVVM_DLL)
if(NOT NVVM_DLL)
message(FATAL_ERROR "Found nvvm .h/.lib, but not .dll")
endif()
install(FILES ${NVVM_DLL} DESTINATION bin)
@@ -98,18 +98,10 @@ add_definitions(-DLIBDEVICE_MAJOR_VERSION=1)
add_definitions(-DLIBDEVICE_MINOR_VERSION=0)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/common/include")
# If you wish to build the cuda-c-linking sample and have the LLVM dependencies
# met, then set the ENABLE_CUDA_C_LINKING_SAMPLE variable. This variable can be
# set locally or by adding "-DENABLE_CUDA_C_LINKING_SAMPLE=1" to your cmake
# invocation. See the note about "cuda-c-linking" in README.md.
if (ENABLE_CUDA_C_LINKING_SAMPLE)
# Include the LLVM dev package which is required to build cuda-c-linking.
find_package(LLVM CONFIG PATHS "$ENV{LLVM_HOME}")
if (LLVM_FOUND)
add_subdirectory(cuda-c-linking)
else ()
message(STATUS "Skipping the build of the cuda-c-linking sample: Failed to locate the LLVM package.")
endif ()
# Include the LLVM dev package which is required to build cuda-c-linking.
find_package(LLVM CONFIG PATHS "$ENV{LLVM_HOME}")
if (LLVM_FOUND)
add_subdirectory(cuda-c-linking)
else ()
message(STATUS "Skipping the build of the cuda-c-linking sample.")
endif ()

View File

@@ -44,7 +44,7 @@ identify all of these paths.
locally. This is only required for building the cuda-c-linking
sample (see the cuda-c-linking note below).
After setting the environment variables and adding the path to the CMake tool
After setting the environment variables and adding the path to the cmake tool
via the PATH environment variable, sample script utils/build.sh (for Linux) or
utils/build.bat (for Windows) may be executed. This script will use build
directory "build" to build the samples, and then install them in the "install"
@@ -70,11 +70,6 @@ cuda-c-linking sample and have a locally built copy of LLVM that they wish to
use. That sample requires the development package of LLVM with the LLVM header
files and libraries.
If the LLVM dependencies are met, the user can enable the building of this
sample by setting the CMake variable "ENABLE_CUDA_C_LINKING_SAMPLE" from either
the command line invocation of CMake or by modifying the CMakeLists.txt in this
directory.
Windows users should download LLVM 14 sources from llvm.org and build+install
LLVM locally. Using the llvm.org provided Windows installer lacks some of
the required components the cuda-c-linking sample depends on.
@@ -83,8 +78,8 @@ For Ubuntu users, the "llvm-dev" package contains the LLVM headers and libraries
this sample requires, the user should not have to explicitly define an LLVM_HOME
in this case.
Windows users will want to build this sample using the same CMake build mode
Windows users will want to build this sample using the same cmake build mode
as they built LLVM with. For instance if they built LLVM in Release mode,
then this sample should also be built in Release mode. The utils/build.bat can
be updated to reflect this: Add "-DCMAKE_BUILD_TYPE=Release" to the CMake
be updated to reflect this: Add "-DCMAKE_BUILD_TYPE=Release" to the cmake
invocation.

View File

@@ -23,9 +23,8 @@ Files
Building
--------
This sample is optionally built as part of the libnvvm samples from the CUDA
samples tree. Please see the README file at the root of the libnvvm samples
for build instructions.
This sample is built as part of the libnvvm samples tree. Please see the
README file at the root of the libnvvm samples tree for build instructions.
Usage
-----

View File

@@ -40,7 +40,7 @@ retrieve a device pointer first, which can be done using cuModuleGetGlobal().
size_t size_xxx; // size of xxx
result = cuModuleGetGlobal(&devp_xxx, &size_xxx, hModule, "xxx");
Whether or not the pointer points to managed memory may be queried
Whether of not the pointer points to a managed memory may be queried
by calling cuPointerGetAttribute() with the pointer attribute
CU_POINTER_ATTRIBUTE_IS_MANAGED.

View File

@@ -34,12 +34,6 @@
#include <string.h>
#include <sys/stat.h>
#define ERROR_IF(expr) \
if (expr) { \
fprintf(stderr, "Failed check at %s:%d\n", __FILE__, __LINE__); \
exit(EXIT_FAILURE); \
}
// If 'err' is non-zero, emit an error message and exit.
#define checkCudaErrors(err) __checkCudaErrors(err, __FILE__, __LINE__)
static void __checkCudaErrors(CUresult err, const char *filename, int line) {
@@ -227,7 +221,7 @@ static CUresult buildKernel(CUcontext *phContext, CUdevice *phDevice,
return CUDA_SUCCESS;
}
int main(void) {
int main(int argc, char **argv) {
const unsigned int nThreads = 1;
const unsigned int nBlocks = 1;
@@ -251,7 +245,7 @@ int main(void) {
int attrVal;
checkCudaErrors(cuDeviceGetAttribute(
&attrVal, CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING, hDevice));
ERROR_IF(attrVal != 1);
assert(attrVal == 1);
}
// Get the address of the variable xxx, yyy in the managed memory.
@@ -266,10 +260,23 @@ int main(void) {
checkCudaErrors(cuPointerGetAttribute(
&attrVal, CU_POINTER_ATTRIBUTE_IS_MANAGED, devp_xxx));
ERROR_IF(attrVal != 1);
assert(attrVal == 1);
checkCudaErrors(cuPointerGetAttribute(
&attrVal, CU_POINTER_ATTRIBUTE_IS_MANAGED, devp_yyy));
ERROR_IF(attrVal != 1);
assert(attrVal == 1);
}
// The "physical" memory location of the memory that the devp_yyy addresses is
// the device memory type.
{
unsigned int attrVal;
checkCudaErrors(cuPointerGetAttribute(
&attrVal, CU_POINTER_ATTRIBUTE_MEMORY_TYPE, devp_xxx));
assert(attrVal == CU_MEMORYTYPE_DEVICE);
checkCudaErrors(cuPointerGetAttribute(
&attrVal, CU_POINTER_ATTRIBUTE_MEMORY_TYPE, devp_yyy));
assert(attrVal == CU_MEMORYTYPE_DEVICE);
}
// Since CUdeviceptr is opaque, it is safe to use cuPointerGetAttribute to get
@@ -289,8 +296,8 @@ int main(void) {
printf("The initial value of xxx initialized by the device = %d\n", *p_xxx);
printf("The initial value of yyy initialized by the device = %d\n", *p_yyy);
ERROR_IF(*p_xxx != 10);
ERROR_IF(*p_yyy != 100);
assert(*p_xxx == 10);
assert(*p_yyy == 100);
// The host adds 1 and 11 to xxx and yyy.
*p_xxx += 1;