hipMemcpy fails to copy

141 views Asked by At

I am trying to use <hip/hip_runtime.h> library, but I keep getting gibberish when exchanging data.

here is my code:

#include <hip/hip_runtime.h>
#include <iostream>

int main() {
    int* hipC;
    int a = 123;
    int* ap = &a;
    int* ap2 = new int;

    hipMalloc(&hipC, sizeof(int));
    hipMemcpy(hipC, ap, sizeof(int), hipMemcpyHostToDevice);
    hipMemcpy(ap2, hipC, sizeof(int), hipMemcpyDeviceToHost);

    std::cout << *ap2 << '\n';

    return 0;
}

if I understand how hip malloc / memcpy works, this code should allocate space for hipC pointer, take value of a, copy it to *hipC and back to *ap2. But when running following code it prints random ints. There are also no errors/compiler warnings to speak of, so I'm quite stumped. I compile code with hipcc if that matters. thanks

0

There are 0 answers