mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-25 22:28:17 +08:00
Updating Samples for 12.3 and updating props files
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user