diff --git a/samples/0_Intro/module_api_global/runKernel.cpp b/samples/0_Intro/module_api_global/runKernel.cpp index 1e10dba5c6..7031b9f898 100644 --- a/samples/0_Intro/module_api_global/runKernel.cpp +++ b/samples/0_Intro/module_api_global/runKernel.cpp @@ -31,7 +31,6 @@ THE SOFTWARE. #define SIZE LEN * sizeof(float) #define fileName "vcpy_kernel.code" -float myDeviceGlobalArray[16]; #define HIP_CHECK(cmd) \ { \ hipError_t status = cmd; \ @@ -71,14 +70,17 @@ int main() { float* deviceGlobal; size_t deviceGlobalSize; HIP_CHECK(hipModuleGetGlobal((void**)&deviceGlobal, &deviceGlobalSize, Module, "myDeviceGlobal")); - *deviceGlobal = 42.0; + HIP_CHECK(hipMemcpyHtoD(hipDeviceptr_t(deviceGlobal), &myDeviceGlobal_h, deviceGlobalSize)); #define ARRAY_SIZE 16 float myDeviceGlobalArray_h[ARRAY_SIZE]; + float *myDeviceGlobalArray; + size_t myDeviceGlobalArraySize; + HIP_CHECK(hipModuleGetGlobal((void**)&myDeviceGlobalArray, &myDeviceGlobalArraySize, Module, "myDeviceGlobalArray")); for (int i = 0; i < ARRAY_SIZE; i++) { myDeviceGlobalArray_h[i] = i * 1000.0f; - myDeviceGlobalArray[i] = i * 1000.0f; + HIP_CHECK(hipMemcpyHtoD(hipDeviceptr_t(myDeviceGlobalArray), &myDeviceGlobalArray_h, myDeviceGlobalArraySize)); } struct { diff --git a/samples/0_Intro/module_api_global/vcpy_kernel.cpp b/samples/0_Intro/module_api_global/vcpy_kernel.cpp index 662dcd0cc3..9e8d7c9e29 100644 --- a/samples/0_Intro/module_api_global/vcpy_kernel.cpp +++ b/samples/0_Intro/module_api_global/vcpy_kernel.cpp @@ -25,8 +25,7 @@ THE SOFTWARE. #define ARRAY_SIZE (16) __device__ float myDeviceGlobal; -extern float myDeviceGlobalArray[16]; -; +__device__ float myDeviceGlobalArray[16]; extern "C" __global__ void hello_world(const float* a, float* b) { int tx = hipThreadIdx_x;