Apply .clangformat to all repo source files

Change-Id: I7e79c6058f0303f9a98911e3b7dd2e8596079344
This commit is contained in:
Maneesh Gupta
2018-03-12 11:29:03 +05:30
parent 18e70b1e6b
commit 1ba06f63c4
293 changed files with 43980 additions and 45830 deletions
+74 -76
View File
@@ -35,95 +35,93 @@ THE SOFTWARE.
#include "hip/device_functions.h"
#include "test_common.h"
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
__host__ __device__ void fence_system() {
#ifdef __HIP_DEVICE_COMPILE__
__threadfence_system();
__threadfence_system();
#else
std::atomic_thread_fence(std::memory_order_seq_cst);
std::atomic_thread_fence(std::memory_order_seq_cst);
#endif
}
__host__ __device__ void round_robin(const int id, const int num_dev, const int num_iter, volatile int* data, volatile int* flag) {
for (int i = 0; i < num_iter; i++) {
while(*flag%num_dev != id)
fence_system(); // invalid the cache for read
__host__ __device__ void round_robin(const int id, const int num_dev, const int num_iter,
volatile int* data, volatile int* flag) {
for (int i = 0; i < num_iter; i++) {
while (*flag % num_dev != id) fence_system(); // invalid the cache for read
(*data)++;
fence_system(); // make sure the store to data is sequenced before the store to flag
(*flag)++;
fence_system(); // invalid the cache to flush out flag
}
(*data)++;
fence_system(); // make sure the store to data is sequenced before the store to flag
(*flag)++;
fence_system(); // invalid the cache to flush out flag
}
}
__global__ void gpu_round_robin(const int id, const int num_dev, const int num_iter, volatile int* data, volatile int* flag) {
round_robin(id, num_dev, num_iter, data, flag);
__global__ void gpu_round_robin(const int id, const int num_dev, const int num_iter,
volatile int* data, volatile int* flag) {
round_robin(id, num_dev, num_iter, data, flag);
}
int main() {
int num_gpus = 0;
HIP_ASSERT(hipGetDeviceCount(&num_gpus));
if (num_gpus == 0) {
passed();
return 0;
}
volatile int* data;
HIP_ASSERT(hipHostMalloc(&data, sizeof(int), hipHostMallocCoherent));
constexpr int init_data = 1000;
*data = init_data;
volatile int* flag;
HIP_ASSERT(hipHostMalloc(&flag, sizeof(int), hipHostMallocCoherent));
*flag = 0;
// number of rounds per device
constexpr int num_iter = 1000;
// one CPU thread + 1 kernel/GPU
const int num_dev = num_gpus + 1;
int next_id = 0;
std::vector<std::thread> threads;
// create a CPU thread for the round_robin
threads.push_back(std::thread(round_robin, next_id++, num_dev, num_iter, data, flag));
// run one thread per GPU
dim3 dim_block(1, 1, 1);
dim3 dim_grid(1, 1, 1);
// launch one kernel per device for the round robin
for (; next_id < num_dev; ++next_id) {
threads.push_back(std::thread([=]() {
HIP_ASSERT(hipSetDevice(next_id - 1));
hipLaunchKernelGGL(gpu_round_robin, dim_grid, dim_block, 0, 0x0, next_id, num_dev,
num_iter, data, flag);
HIP_ASSERT(hipDeviceSynchronize());
}));
}
for (auto& t : threads) {
t.join();
}
int expected_data = init_data + num_dev * num_iter;
int expected_flag = num_dev * num_iter;
bool passed = *data == expected_data && *flag == expected_flag;
HIP_ASSERT(hipHostFree((void*)data));
HIP_ASSERT(hipHostFree((void*)flag));
if (passed) {
passed();
} else {
failed("Failed Verification!\n");
}
int num_gpus = 0;
HIP_ASSERT(hipGetDeviceCount(&num_gpus));
if (num_gpus == 0) {
passed();
return 0;
}
volatile int* data;
HIP_ASSERT(hipHostMalloc(&data, sizeof(int), hipHostMallocCoherent));
constexpr int init_data = 1000;
*data = init_data;
volatile int* flag;
HIP_ASSERT(hipHostMalloc(&flag, sizeof(int), hipHostMallocCoherent));
*flag = 0;
// number of rounds per device
constexpr int num_iter = 1000;
// one CPU thread + 1 kernel/GPU
const int num_dev = num_gpus + 1;
int next_id = 0;
std::vector<std::thread> threads;
// create a CPU thread for the round_robin
threads.push_back(std::thread(round_robin, next_id++, num_dev, num_iter, data, flag));
// run one thread per GPU
dim3 dim_block(1,1,1);
dim3 dim_grid(1,1,1);
// launch one kernel per device for the round robin
for (; next_id < num_dev; ++next_id) {
threads.push_back(std::thread([=]() {
HIP_ASSERT(hipSetDevice(next_id-1));
hipLaunchKernelGGL(gpu_round_robin, dim_grid, dim_block, 0, 0x0
, next_id, num_dev, num_iter, data, flag);
HIP_ASSERT(hipDeviceSynchronize());
}));
}
for (auto& t : threads) {
t.join();
}
int expected_data = init_data + num_dev * num_iter;
int expected_flag = num_dev * num_iter;
bool passed = *data == expected_data
&& *flag == expected_flag;
HIP_ASSERT(hipHostFree((void*)data));
HIP_ASSERT(hipHostFree((void*)flag));
if (passed) {
passed();
}
else {
failed("Failed Verification!\n");
}
return 0;
}