Apply .clangformat to all repo source files
Change-Id: I7e79c6058f0303f9a98911e3b7dd2e8596079344
[ROCm/hip commit: 1ba06f63c4]
Этот коммит содержится в:
@@ -27,18 +27,18 @@
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include"test_common.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#define LEN 1024*1024
|
||||
#define SIZE LEN*sizeof(float)
|
||||
#define LEN 1024 * 1024
|
||||
#define SIZE LEN * sizeof(float)
|
||||
|
||||
__global__ void Add(float *Ad, float *Bd, float *Cd){
|
||||
__global__ void Add(float* Ad, float* Bd, float* Cd) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Cd[tx] = Ad[tx] + Bd[tx];
|
||||
}
|
||||
|
||||
|
||||
__global__ void Set(int *Ad, int val){
|
||||
__global__ void Set(int* Ad, int val) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Ad[tx] = val;
|
||||
}
|
||||
@@ -50,16 +50,16 @@ __global__ void Set(int *Ad, int val){
|
||||
|
||||
std::vector<std::string> syncMsg = {"event", "stream", "device"};
|
||||
|
||||
void CheckHostPointer(int numElements, int *ptr, unsigned eventFlags, int syncMethod, std::string msg)
|
||||
{
|
||||
std::cerr << "test: CheckHostPointer " << msg
|
||||
void CheckHostPointer(int numElements, int* ptr, unsigned eventFlags, int syncMethod,
|
||||
std::string msg) {
|
||||
std::cerr << "test: CheckHostPointer "
|
||||
<< msg
|
||||
//<< " HIP_COHERENT_HOST_ALLOC=" << HIP_COHERENT_HOST_ALLOC
|
||||
//<< " HIP_EVENT_SYS_RELEASE=" << HIP_EVENT_SYS_RELEASE
|
||||
<< " eventFlags = " << std::hex << eventFlags
|
||||
<< ((eventFlags & hipEventReleaseToDevice) ? " hipEventReleaseToDevice" : "")
|
||||
<< ((eventFlags & hipEventReleaseToDevice) ? " hipEventReleaseToDevice" : "")
|
||||
<< ((eventFlags & hipEventReleaseToSystem) ? " hipEventReleaseToSystem" : "")
|
||||
<< " ptr=" << ptr
|
||||
<< " syncMethod=" << syncMsg[syncMethod] << "\n";
|
||||
<< " ptr=" << ptr << " syncMethod=" << syncMsg[syncMethod] << "\n";
|
||||
|
||||
hipStream_t s;
|
||||
hipEvent_t e;
|
||||
@@ -67,8 +67,8 @@ void CheckHostPointer(int numElements, int *ptr, unsigned eventFlags, int syncMe
|
||||
// Init:
|
||||
HIPCHECK(hipStreamCreate(&s));
|
||||
HIPCHECK(hipEventCreateWithFlags(&e, eventFlags))
|
||||
dim3 dimBlock(64,1,1);
|
||||
dim3 dimGrid(numElements/dimBlock.x,1,1);
|
||||
dim3 dimBlock(64, 1, 1);
|
||||
dim3 dimGrid(numElements / dimBlock.x, 1, 1);
|
||||
|
||||
const int expected = 13;
|
||||
|
||||
@@ -94,9 +94,9 @@ void CheckHostPointer(int numElements, int *ptr, unsigned eventFlags, int syncMe
|
||||
assert(0);
|
||||
};
|
||||
|
||||
for (int i=0; i<numElements; i++) {
|
||||
for (int i = 0; i < numElements; i++) {
|
||||
if (ptr[i] != expected) {
|
||||
printf ("mismatch at %d: %d != %d\n", i, ptr[i], expected);
|
||||
printf("mismatch at %d: %d != %d\n", i, ptr[i], expected);
|
||||
assert(ptr[i] == expected);
|
||||
}
|
||||
}
|
||||
@@ -105,15 +105,13 @@ void CheckHostPointer(int numElements, int *ptr, unsigned eventFlags, int syncMe
|
||||
HIPCHECK(hipEventDestroy(e));
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
int main() {
|
||||
hipDeviceProp_t prop;
|
||||
int device;
|
||||
HIPCHECK(hipGetDevice(&device));
|
||||
HIPCHECK(hipGetDeviceProperties(&prop, device));
|
||||
if(prop.canMapHostMemory != 1){
|
||||
std::cout<<"Exiting..."<<std::endl;
|
||||
if (prop.canMapHostMemory != 1) {
|
||||
std::cout << "Exiting..." << std::endl;
|
||||
failed("Does support HostPinned Memory");
|
||||
}
|
||||
|
||||
@@ -128,7 +126,7 @@ int main(){
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Ad, A, 0));
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Cd, C, 0));
|
||||
|
||||
for(int i=0;i<LEN;i++){
|
||||
for (int i = 0; i < LEN; i++) {
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
}
|
||||
@@ -136,8 +134,8 @@ int main(){
|
||||
HIPCHECK(hipMalloc((void**)&Bd, SIZE));
|
||||
HIPCHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
|
||||
|
||||
dim3 dimGrid(LEN/512,1,1);
|
||||
dim3 dimBlock(512,1,1);
|
||||
dim3 dimGrid(LEN / 512, 1, 1);
|
||||
dim3 dimBlock(512, 1, 1);
|
||||
|
||||
hipLaunchKernelGGL(Add, dimGrid, dimBlock, 0, 0, Ad, Bd, Cd);
|
||||
|
||||
@@ -149,64 +147,61 @@ int main(){
|
||||
}
|
||||
|
||||
{
|
||||
int numElements = 1024*16;
|
||||
size_t sizeBytes = numElements * sizeof (int);
|
||||
int numElements = 1024 * 16;
|
||||
size_t sizeBytes = numElements * sizeof(int);
|
||||
|
||||
#ifdef __HIP_PLATFORM_HCC__
|
||||
{
|
||||
// Stimulate error condition:
|
||||
int *A = &numElements;
|
||||
HIPCHECK_API(hipHostMalloc((void**)&A, sizeBytes, hipHostMallocCoherent|hipHostMallocNonCoherent), hipErrorInvalidValue);
|
||||
int* A = &numElements;
|
||||
HIPCHECK_API(hipHostMalloc((void**)&A, sizeBytes,
|
||||
hipHostMallocCoherent | hipHostMallocNonCoherent),
|
||||
hipErrorInvalidValue);
|
||||
|
||||
assert (A == 0);
|
||||
assert(A == 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
{
|
||||
int *A = nullptr;
|
||||
int* A = nullptr;
|
||||
HIPCHECK(hipHostMalloc((void**)&A, sizeBytes, hipHostMallocNonCoherent));
|
||||
const char *ptrType = "non-coherent"; // TODO
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
|
||||
const char* ptrType = "non-coherent"; // TODO
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
|
||||
|
||||
// agent-scope releases don't provide host visibility, don't use them here:
|
||||
}
|
||||
|
||||
if (1) {
|
||||
int *A = nullptr;
|
||||
int* A = nullptr;
|
||||
HIPCHECK(hipHostMalloc((void**)&A, sizeBytes, hipHostMallocCoherent));
|
||||
const char *ptrType = "coherent";
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_EVENT, ptrType);
|
||||
const char* ptrType = "coherent";
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_EVENT, ptrType);
|
||||
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
|
||||
}
|
||||
|
||||
|
||||
// Check defaults:
|
||||
if (1) {
|
||||
int *A = nullptr;
|
||||
int* A = nullptr;
|
||||
HIPCHECK(hipHostMalloc((void**)&A, sizeBytes));
|
||||
const char *ptrType = "default";
|
||||
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
|
||||
const char* ptrType = "default";
|
||||
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
|
||||
|
||||
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
passed();
|
||||
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user