Apply .clangformat to all repo source files
Change-Id: I7e79c6058f0303f9a98911e3b7dd2e8596079344
[ROCm/clr commit: 9e47fccc89]
This commit is contained in:
@@ -24,19 +24,19 @@ THE SOFTWARE.
|
||||
#ifndef GHIPAPI_H
|
||||
#define GHIPAPI_H
|
||||
|
||||
#include<stdlib.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct {
|
||||
void *hst_ptr;
|
||||
void *dev_ptr;
|
||||
size_t size;
|
||||
void (*h2d)();
|
||||
void (*d2h)();
|
||||
void (*malloc_hip)();
|
||||
void (*malloc_hst)();
|
||||
void* hst_ptr;
|
||||
void* dev_ptr;
|
||||
size_t size;
|
||||
void (*h2d)();
|
||||
void (*d2h)();
|
||||
void (*malloc_hip)();
|
||||
void (*malloc_hst)();
|
||||
} mem_manager;
|
||||
|
||||
mem_manager *mem_manager_start(size_t);
|
||||
mem_manager* mem_manager_start(size_t);
|
||||
|
||||
void memset_hst(mem_manager*, float);
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ THE SOFTWARE.
|
||||
|
||||
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include<iostream>
|
||||
#include <iostream>
|
||||
|
||||
#define size 1024*1024
|
||||
#define size 1024 * 1024
|
||||
|
||||
int main(){
|
||||
float *Ad;
|
||||
hipMalloc((void**)&Ad, size);
|
||||
int main() {
|
||||
float* Ad;
|
||||
hipMalloc((void**)&Ad, size);
|
||||
}
|
||||
|
||||
@@ -21,12 +21,11 @@ THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include"gxxApi1.h"
|
||||
#include "gxxApi1.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
|
||||
void* mallocHip(size_t size)
|
||||
{
|
||||
void *ptr;
|
||||
hipMalloc(&ptr, size);
|
||||
return ptr;
|
||||
void* mallocHip(size_t size) {
|
||||
void* ptr;
|
||||
hipMalloc(&ptr, size);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ THE SOFTWARE.
|
||||
|
||||
#ifndef GXXAPI1_H
|
||||
#define GXXAPI1_H
|
||||
#include<stdlib.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void* mallocHip(size_t size);
|
||||
|
||||
|
||||
@@ -21,22 +21,14 @@ THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include "gxxHipApi.h"
|
||||
|
||||
#include"gxxHipApi.h"
|
||||
|
||||
memManager::memManager(const memManager &obj)
|
||||
{
|
||||
memManager::memManager(const memManager& obj) {
|
||||
devPtr = obj.devPtr;
|
||||
hstPtr = obj.hstPtr;
|
||||
size = obj.size;
|
||||
}
|
||||
|
||||
void memManager::H2D()
|
||||
{
|
||||
hipMemcpy(devPtr, hstPtr, size, hipMemcpyHostToDevice);
|
||||
}
|
||||
void memManager::H2D() { hipMemcpy(devPtr, hstPtr, size, hipMemcpyHostToDevice); }
|
||||
|
||||
void memManager::D2H()
|
||||
{
|
||||
hipMemcpy(hstPtr, devPtr, size, hipMemcpyDeviceToHost);
|
||||
}
|
||||
void memManager::D2H() { hipMemcpy(hstPtr, devPtr, size, hipMemcpyDeviceToHost); }
|
||||
|
||||
@@ -24,57 +24,51 @@ THE SOFTWARE.
|
||||
#ifndef GXXHIPAPI_H
|
||||
#define GXXHIPAPI_H
|
||||
|
||||
#include<stdlib.h>
|
||||
#include <stdlib.h>
|
||||
#include "hip/hip_runtime_api.h"
|
||||
|
||||
class memManager{
|
||||
private:
|
||||
class memManager {
|
||||
private:
|
||||
void* devPtr;
|
||||
void* hstPtr;
|
||||
size_t size;
|
||||
public:
|
||||
|
||||
public:
|
||||
memManager(size_t size) : size(size) {}
|
||||
memManager(){}
|
||||
memManager(const memManager &obj);
|
||||
template<typename T>
|
||||
void setDevPtr(T* ptr)
|
||||
{
|
||||
memManager() {}
|
||||
memManager(const memManager& obj);
|
||||
template <typename T>
|
||||
void setDevPtr(T* ptr) {
|
||||
devPtr = (void*)ptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* getDevPtr()
|
||||
{
|
||||
return (T*)devPtr;
|
||||
template <typename T>
|
||||
T* getDevPtr() {
|
||||
return (T*)devPtr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void setHstPtr(T* ptr)
|
||||
{
|
||||
hstPtr = (void*)ptr;
|
||||
template <typename T>
|
||||
void setHstPtr(T* ptr) {
|
||||
hstPtr = (void*)ptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* getHstPtr()
|
||||
{
|
||||
return (T*)hstPtr;
|
||||
template <typename T>
|
||||
T* getHstPtr() {
|
||||
return (T*)hstPtr;
|
||||
}
|
||||
|
||||
void H2D();
|
||||
void D2H();
|
||||
template<typename T>
|
||||
void hostMemSet(T val)
|
||||
{
|
||||
template <typename T>
|
||||
void hostMemSet(T val) {
|
||||
T* tmpPtr = (T*)hstPtr;
|
||||
for(int i=0;i<size/sizeof(T);i++)
|
||||
{
|
||||
for (int i = 0; i < size / sizeof(T); i++) {
|
||||
tmpPtr[i] = val;
|
||||
}
|
||||
}
|
||||
template<typename T>
|
||||
void memAlloc()
|
||||
{
|
||||
hipMalloc((void**)&devPtr, size);
|
||||
template <typename T>
|
||||
void memAlloc() {
|
||||
hipMalloc((void**)&devPtr, size);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -23,36 +23,31 @@ THE SOFTWARE.
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include"gxxApi1.h"
|
||||
#include "gxxApi1.h"
|
||||
|
||||
#define len 1024*1024
|
||||
#define len 1024 * 1024
|
||||
#define size len * sizeof(float)
|
||||
|
||||
__global__ void Kern(hipLaunchParm lp, float *A)
|
||||
{
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
A[tx] += 1.0f;
|
||||
__global__ void Kern(hipLaunchParm lp, float* A) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
A[tx] += 1.0f;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
float A[len];
|
||||
float *Ad;
|
||||
int main() {
|
||||
float A[len];
|
||||
float* Ad;
|
||||
|
||||
for(int i=0;i<len;i++)
|
||||
{
|
||||
A[i] = 1.0f;
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
A[i] = 1.0f;
|
||||
}
|
||||
|
||||
Ad = (float*)mallocHip(size);
|
||||
memcpyHipH2D(Ad, A, size);
|
||||
hipLaunchKernel(
|
||||
HIP_KERNEL_NAME(Kern), dim3(len/1024), dim3(1024), 0, 0, Ad);
|
||||
memcpyHipD2H(A, Ad, size);
|
||||
for(int i=0;i<len;i++)
|
||||
{
|
||||
assert(A[i] == 2.0f);
|
||||
}
|
||||
Ad = (float*)mallocHip(size);
|
||||
memcpyHipH2D(Ad, A, size);
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Kern), dim3(len / 1024), dim3(1024), 0, 0, Ad);
|
||||
memcpyHipD2H(A, Ad, size);
|
||||
for (int i = 0; i < len; i++) {
|
||||
assert(A[i] == 2.0f);
|
||||
}
|
||||
|
||||
hipFree(Ad);
|
||||
hipFree(Ad);
|
||||
}
|
||||
|
||||
@@ -21,46 +21,44 @@ THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include"gxxHipApi.h"
|
||||
#include<vector>
|
||||
#include "gxxHipApi.h"
|
||||
#include <vector>
|
||||
#include "hip/hip_runtime.h"
|
||||
|
||||
#define LEN 1024*1024
|
||||
#define LEN 1024 * 1024
|
||||
#define SIZE LEN * sizeof(float)
|
||||
|
||||
class memManager;
|
||||
|
||||
template<typename T>
|
||||
__global__ void Add(hipLaunchParm lp, T* Ad, T* Bd, T* Cd, size_t Len)
|
||||
{
|
||||
template <typename T>
|
||||
__global__ void Add(hipLaunchParm lp, T* Ad, T* Bd, T* Cd, size_t Len) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
if(tx < Len)
|
||||
{
|
||||
if (tx < Len) {
|
||||
Cd[tx] = Ad[tx] + Bd[tx];
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
std::vector<class memManager> Vec(3);
|
||||
for(int i=0;i<Vec.size();i++){
|
||||
for (int i = 0; i < Vec.size(); i++) {
|
||||
Vec[i] = memManager(SIZE);
|
||||
}
|
||||
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Vec[i].setHstPtr(new float[LEN]);
|
||||
Vec[i].memAlloc<float>();
|
||||
}
|
||||
|
||||
for(int i=0;i<Vec.size()-1;i++)
|
||||
{
|
||||
Vec[i].hostMemSet((i+1)*1.0f);
|
||||
for (int i = 0; i < Vec.size() - 1; i++) {
|
||||
Vec[i].hostMemSet((i + 1) * 1.0f);
|
||||
Vec[i].H2D();
|
||||
}
|
||||
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Add), dim3(LEN/1024), dim3(1024), 0, 0, Vec[0].getDevPtr<float>(), Vec[1].getDevPtr<float>(), Vec[2].getDevPtr<float>(), LEN);
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Add), dim3(LEN / 1024), dim3(1024), 0, 0,
|
||||
Vec[0].getDevPtr<float>(), Vec[1].getDevPtr<float>(), Vec[2].getDevPtr<float>(),
|
||||
LEN);
|
||||
|
||||
Vec[2].D2H();
|
||||
assert(Vec[0].getHstPtr<float>()[10] + Vec[1].getHstPtr<float>()[10] == Vec[2].getHstPtr<float>()[10]);
|
||||
assert(Vec[0].getHstPtr<float>()[10] + Vec[1].getHstPtr<float>()[10] ==
|
||||
Vec[2].getHstPtr<float>()[10]);
|
||||
}
|
||||
|
||||
@@ -21,46 +21,41 @@ THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include"gxxHipApi.h"
|
||||
#include<vector>
|
||||
#include "gxxHipApi.h"
|
||||
#include <vector>
|
||||
#include "hip/hip_runtime.h"
|
||||
|
||||
#define LEN 1024*1024
|
||||
#define LEN 1024 * 1024
|
||||
#define SIZE LEN * sizeof(float)
|
||||
|
||||
class memManager;
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
std::vector<class memManager> Vec(4);
|
||||
for(int i=0;i<Vec.size();i++){
|
||||
for (int i = 0; i < Vec.size(); i++) {
|
||||
Vec[i] = memManager(SIZE);
|
||||
}
|
||||
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Vec[i].setHstPtr(new float[LEN]);
|
||||
}
|
||||
|
||||
for(int i=0;i<2;i++)
|
||||
{
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Vec[i].memAlloc<float>();
|
||||
}
|
||||
|
||||
for(int i=0;i<2;i++)
|
||||
{
|
||||
Vec[i].hostMemSet((i+1)*1.0f);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Vec[i].hostMemSet((i + 1) * 1.0f);
|
||||
Vec[i].H2D();
|
||||
}
|
||||
|
||||
Vec[2].setDevPtr(Vec[0].getDevPtr<float>());
|
||||
Vec[3].setDevPtr(Vec[1].getDevPtr<float>());
|
||||
|
||||
for(int i=2;i<Vec.size();i++)
|
||||
{
|
||||
for (int i = 2; i < Vec.size(); i++) {
|
||||
Vec[i].D2H();
|
||||
}
|
||||
|
||||
|
||||
assert(Vec[0].getHstPtr<float>()[10] == Vec[2].getHstPtr<float>()[10]);
|
||||
assert(Vec[1].getHstPtr<float>()[10] == Vec[3].getHstPtr<float>()[10]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user