Files
rocm-systems/hipamd/tests/src/deviceLib/hipDeviceMemcpy.cpp
T

61 lines
1.3 KiB
C++
Raw Normal View History

#include <iostream>
#include "hip/hip_runtime.h"
#include "hip/hip_runtime_api.h"
#include "../test_common.h"
2016-08-27 11:13:56 -05:00
#define LEN 1024
2016-08-27 11:13:56 -05:00
#define SIZE LEN << 2
/* HIT_START
* BUILD: %t %s ../test_common.cpp
* RUN: %t
* HIT_END
*/
__global__ void cpy(uint32_t* Out, uint32_t* In) {
int tx = threadIdx.x;
memcpy(Out + tx, In + tx, sizeof(uint32_t));
2016-08-27 11:13:56 -05:00
}
__global__ void set(uint32_t* ptr, uint8_t val, size_t size) {
int tx = threadIdx.x;
memset(ptr + tx, val, sizeof(uint32_t));
2016-08-27 11:13:56 -05:00
}
2018-03-12 11:29:03 +05:30
int main() {
2016-08-27 11:13:56 -05:00
uint32_t *A, *Ad, *B, *Bd;
2018-03-12 11:29:03 +05:30
uint32_t* Val;
2016-08-27 11:13:56 -05:00
A = new uint32_t[LEN];
B = new uint32_t[LEN];
Val = new uint32_t;
*Val = 0;
2018-03-12 11:29:03 +05:30
for (int i = 0; i < LEN; i++) {
A[i] = i;
B[i] = 0;
2016-08-27 11:13:56 -05:00
}
hipMalloc((void**)&Ad, SIZE);
hipMalloc((void**)&Bd, SIZE);
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
hipLaunchKernelGGL(cpy, dim3(1), dim3(LEN), 0, 0, Bd, Ad);
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
2018-03-12 11:29:03 +05:30
for (int i = LEN - 16; i < LEN; i++) {
if (A[i] != B[i]) {
return 0;
}
}
hipLaunchKernelGGL(set, dim3(1), dim3(LEN), 0, 0, Bd, 0x1, LEN);
2016-08-27 11:13:56 -05:00
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
2018-03-12 11:29:03 +05:30
for (int i = LEN - 16; i < LEN; i++) {
if (0x01010101 != B[i]) {
return 0;
}
2016-08-27 11:13:56 -05:00
}
passed();
2016-08-27 11:13:56 -05:00
}