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
والد eee7fa6072
کامیت 9e47fccc89
293فایلهای تغییر یافته به همراه43980 افزوده شده و 45830 حذف شده
@@ -20,7 +20,7 @@ THE SOFTWARE.
/*
* Test for checking the functionality of
* hipError_t hipDeviceSynchronize();
*/
*/
/* HIT_START
* BUILD: %t %s ../../test_common.cpp
@@ -28,47 +28,49 @@ THE SOFTWARE.
* HIT_END
*/
#include"test_common.h"
#include "test_common.h"
#define _SIZE sizeof(int)*1024*1024
#define _SIZE sizeof(int) * 1024 * 1024
#define NUM_STREAMS 2
__global__ void Iter(hipLaunchParm lp, int *Ad, int num){
__global__ void Iter(hipLaunchParm lp, int* Ad, int num) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
// Kernel loop designed to execute very slowly... ... ... so we can test timing-related behavior below
if(tx == 0){
for(int i = 0; i<num;i++){
// Kernel loop designed to execute very slowly... ... ... so we can test timing-related
// behavior below
if (tx == 0) {
for (int i = 0; i < num; i++) {
Ad[tx] += 1;
}
}
}
int main(){
int *A[NUM_STREAMS];
int *Ad[NUM_STREAMS];
int main() {
int* A[NUM_STREAMS];
int* Ad[NUM_STREAMS];
hipStream_t stream[NUM_STREAMS];
for(int i=0;i<NUM_STREAMS;i++){
for (int i = 0; i < NUM_STREAMS; i++) {
HIPCHECK(hipHostMalloc((void**)&A[i], _SIZE, hipHostMallocDefault));
A[i][0] = 1;
HIPCHECK(hipMalloc((void**)&Ad[i], _SIZE));
HIPCHECK(hipStreamCreate(&stream[i]));
}
for(int i=0;i<NUM_STREAMS;i++){
for (int i = 0; i < NUM_STREAMS; i++) {
HIPCHECK(hipMemcpyAsync(Ad[i], A[i], _SIZE, hipMemcpyHostToDevice, stream[i]));
}
for(int i=0;i<NUM_STREAMS;i++){
hipLaunchKernel(HIP_KERNEL_NAME(Iter), dim3(1), dim3(1), 0, stream[i], Ad[i], 1<<30);
for (int i = 0; i < NUM_STREAMS; i++) {
hipLaunchKernel(HIP_KERNEL_NAME(Iter), dim3(1), dim3(1), 0, stream[i], Ad[i], 1 << 30);
}
for(int i=0;i<NUM_STREAMS;i++){
for (int i = 0; i < NUM_STREAMS; i++) {
HIPCHECK(hipMemcpyAsync(A[i], Ad[i], _SIZE, hipMemcpyDeviceToHost, stream[i]));
}
// This first check but relies on the kernel running for so long that the D2H async memcopy has not started yet.
// This will be true in an optimal asynchronous implementation.
// Conservative implementations which synchronize the hipMemcpyAsync will fail, ie if HIP_LAUNCH_BLOCKING=true
HIPASSERT(1<<30 != A[NUM_STREAMS-1][0]-1);
// This first check but relies on the kernel running for so long that the D2H async memcopy has
// not started yet. This will be true in an optimal asynchronous implementation. Conservative
// implementations which synchronize the hipMemcpyAsync will fail, ie if
// HIP_LAUNCH_BLOCKING=true
HIPASSERT(1 << 30 != A[NUM_STREAMS - 1][0] - 1);
HIPCHECK(hipDeviceSynchronize());
HIPASSERT(1<<30 == A[NUM_STREAMS-1][0]-1);
HIPASSERT(1 << 30 == A[NUM_STREAMS - 1][0] - 1);
passed();
}
@@ -30,12 +30,11 @@ THE SOFTWARE.
#include "test_common.h"
int main()
{
int main() {
int numDevices = 0;
int device;
HIPCHECK(hipGetDeviceCount(&numDevices));
for(int i=0;i<numDevices;i++){
for (int i = 0; i < numDevices; i++) {
HIPCHECK(hipSetDevice(i));
HIPCHECK(hipGetDevice(&device));
HIPASSERT(device == i);
@@ -25,10 +25,10 @@ THE SOFTWARE.
#include "test_common.h"
int main(){
int main() {
int numDevices = 0;
HIPCHECK(hipGetDeviceCount(&numDevices));
for(int i=0;i<numDevices;i++){
for (int i = 0; i < numDevices; i++) {
HIPCHECK(hipSetDevice(i));
}
HIPASSERT(hipErrorInvalidDevice == hipSetDevice(numDevices));
@@ -25,27 +25,24 @@ THE SOFTWARE.
#include "test_common.h"
int main()
{
int main() {
unsigned flag = 0;
HIPCHECK(hipDeviceReset());
int deviceCount = 0;
HIPCHECK(hipGetDeviceCount(&deviceCount));
for(int j=0;j<deviceCount;j++){
for (int j = 0; j < deviceCount; j++) {
HIPCHECK(hipSetDevice(j));
for(int i=0;i<4;i++){
for (int i = 0; i < 4; i++) {
flag = 1 << i;
printf ("Flag=%x\n", flag);
printf("Flag=%x\n", flag);
HIPCHECK(hipSetDeviceFlags(flag));
//HIPCHECK_API(hipSetDeviceFlags(flag), hipErrorInvalidValue);
// HIPCHECK_API(hipSetDeviceFlags(flag), hipErrorInvalidValue);
}
flag = 0;
}
passed();
@@ -1,12 +1,11 @@
#include "hip/hip_runtime.h"
#include "hip/hip_runtime_api.h"
#include"hipDeviceUtil.h"
#include "hipDeviceUtil.h"
int main()
{
int main() {
int pi;
int attr = 0;
// hipDeviceAttribute_t attr = hipDeviceAttributeMaxThreadsPerBlock;
// hipDeviceAttribute_t attr = hipDeviceAttributeMaxThreadsPerBlock;
HIP_CHECK(hipDeviceGetAttribute(NULL, hipDeviceAttribute_t(attr), 0), hipDeviceGetAttribute);
HIP_CHECK(hipDeviceGetAttribute(&pi, hipDeviceAttribute_t(attr), 0), hipDeviceGetAttribute);
attr = -1;
@@ -2,9 +2,10 @@
#define HIPDEVICEUTIL_H
#include "hip/hip_runtime_api.h"
#include<iostream>
#include <iostream>
#define HIP_CHECK(status, func) \
std::cout<<#func<<" returned "<<hipGetErrorString(status)<<" in "<<__func__<<" at "<<__LINE__<<" in file "<<__FILE__<<std::endl;
#define HIP_CHECK(status, func) \
std::cout << #func << " returned " << hipGetErrorString(status) << " in " << __func__ \
<< " at " << __LINE__ << " in file " << __FILE__ << std::endl;
#endif
@@ -1,9 +1,8 @@
#include "hip/hip_runtime.h"
#include "hip/hip_runtime_api.h"
#include"hipDeviceUtil.h"
#include "hipDeviceUtil.h"
int main()
{
int main() {
int device;
HIP_CHECK(hipGetDevice(NULL), hipGetDevice);
HIP_CHECK(hipGetDevice(&device), hipGetDevice);
@@ -1,9 +1,8 @@
#include "hip/hip_runtime.h"
#include "hip/hip_runtime_api.h"
#include"hipDeviceUtil.h"
#include "hipDeviceUtil.h"
int main()
{
int main() {
int deviceCnt;
HIP_CHECK(hipGetDeviceCount(&deviceCnt), hipGetDeviceCount);
HIP_CHECK(hipGetDeviceCount(0), hipGetDeviceCount);
@@ -1,9 +1,8 @@
#include "hip/hip_runtime.h"
#include "hip/hip_runtime_api.h"
#include"hipDeviceUtil.h"
#include "hipDeviceUtil.h"
int main()
{
int main() {
hipDeviceProp_t props;
HIP_CHECK(hipGetDeviceProperties(&props, 0), hipGetDeviceProperties);
HIP_CHECK(hipGetDeviceProperties(NULL, 0), hipGetDeviceProperties);
@@ -1,9 +1,8 @@
#include "hip/hip_runtime.h"
#include "hip/hip_runtime_api.h"
#include"hipDeviceUtil.h"
#include "hipDeviceUtil.h"
int main()
{
int main() {
HIP_CHECK(hipSetDevice(0), hipSetDevice);
HIP_CHECK(hipSetDevice(1026), hipSetDevice);
HIP_CHECK(hipSetDevice(-1), hipSetDevice);
@@ -17,45 +17,45 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include"test_common.h"
#include<iostream>
#include<time.h>
#include "test_common.h"
#include <iostream>
#include <time.h>
#define NUM_SIZE 8
#define NUM_ITER 1 << 30
static size_t size[NUM_SIZE];
void setup(){
for(int i=0;i<NUM_SIZE;i++){
size[i] = 1<<(i+6); // start at 8 bytes
}
void setup() {
for (int i = 0; i < NUM_SIZE; i++) {
size[i] = 1 << (i + 6); // start at 8 bytes
}
}
void valSet(int *A, int val, size_t size){
size_t len = size/sizeof(int);
for(int i=0;i<len;i++){
A[i] = val;
}
void valSet(int* A, int val, size_t size) {
size_t len = size / sizeof(int);
for (int i = 0; i < len; i++) {
A[i] = val;
}
}
int main(){
setup();
int *A, *Ad;
for(int i=0;i<NUM_SIZE;i++){
std::cout<<size[i]<<std::endl;
A = (int*)malloc(size[i]);
valSet(A, 1, size[i]);
hipMalloc(&Ad, size[i]);
std::cout<<"Malloc success at size: "<<size[i]<<std::endl;
clock_t start ,end;
start = clock();
for(int j=0;j<NUM_ITER;j++){
// std::cout<<"At iter: "<<j<<std::endl;
hipMemcpy(Ad, A, size[i], hipMemcpyHostToDevice);
}
hipDeviceSynchronize();
end = clock();
double uS = (double)(end - start)*1000/(NUM_ITER*CLOCKS_PER_SEC);
std::cout<<uS<<std::endl;
}
int main() {
setup();
int *A, *Ad;
for (int i = 0; i < NUM_SIZE; i++) {
std::cout << size[i] << std::endl;
A = (int*)malloc(size[i]);
valSet(A, 1, size[i]);
hipMalloc(&Ad, size[i]);
std::cout << "Malloc success at size: " << size[i] << std::endl;
clock_t start, end;
start = clock();
for (int j = 0; j < NUM_ITER; j++) {
// std::cout<<"At iter: "<<j<<std::endl;
hipMemcpy(Ad, A, size[i], hipMemcpyHostToDevice);
}
hipDeviceSynchronize();
end = clock();
double uS = (double)(end - start) * 1000 / (NUM_ITER * CLOCKS_PER_SEC);
std::cout << uS << std::endl;
}
}
@@ -29,16 +29,15 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include "test_common.h"
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
HipTest::parseStandardArguments(argc, argv, true);
HIPCHECK(hipInit(0));
hipDevice_t device;
hipDevice_t device1;
hipCtx_t ctx;
hipCtx_t ctx1;
hipCtx_t ctx;
hipCtx_t ctx1;
HIPCHECK(hipDeviceGet(&device, 0));
HIPCHECK(hipCtxCreate(&ctx, 0, device));
@@ -19,17 +19,17 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include "hip/hip_runtime_api.h"
#include<iostream>
#include<fstream>
#include<vector>
#include <iostream>
#include <fstream>
#include <vector>
int main(){
int main() {
hipInit(0);
hipDevice_t device;
hipDeviceGet(&device, 0);
hipDevice_t device;
hipDeviceGet(&device, 0);
char pciBusId[10];
memset(pciBusId,0,10);
hipDeviceGetPCIBusId(pciBusId,100,device);
printf("PCI Bus ID= %s\n",pciBusId);
memset(pciBusId, 0, 10);
hipDeviceGetPCIBusId(pciBusId, 100, device);
printf("PCI Bus ID= %s\n", pciBusId);
return 0;
}
@@ -1,44 +1,44 @@
#include<iostream>
#include <iostream>
#include "hip/hip_runtime.h"
#include "hip/hip_runtime_api.h"
#define LEN 1024
#define SIZE LEN<<2
#define SIZE LEN << 2
int main(){
int *A, *B;
hipDeviceptr_t Ad, Bd;
A = new int[LEN];
B = new int[LEN];
int main() {
int *A, *B;
hipDeviceptr_t Ad, Bd;
A = new int[LEN];
B = new int[LEN];
for(int i=0;i<LEN;i++){
A[i] = i;
}
for (int i = 0; i < LEN; i++) {
A[i] = i;
}
hipMalloc((void**)&Ad, SIZE);
hipMalloc((void**)&Bd, SIZE);
hipMalloc((void**)&Ad, SIZE);
hipMalloc((void**)&Bd, SIZE);
hipMemcpyHtoD(Ad, A, SIZE);
hipMemcpyDtoD(Bd, Ad, SIZE);
hipMemcpyDtoH(B, Bd, SIZE);
hipMemcpyHtoD(Ad, A, SIZE);
hipMemcpyDtoD(Bd, Ad, SIZE);
hipMemcpyDtoH(B, Bd, SIZE);
for(int i=0;i<16;i++){
std::cout<<A[i]<<" "<<B[i]<<std::endl;
}
for (int i = 0; i < 16; i++) {
std::cout << A[i] << " " << B[i] << std::endl;
}
int *Ah, *Bh;
hipHostMalloc(&Ah, SIZE, 0);
hipHostMalloc(&Bh, SIZE, 0);
memcpy(Ah, A, SIZE);
hipStream_t stream;
hipStreamCreate(&stream);
int *Ah, *Bh;
hipHostMalloc(&Ah, SIZE, 0);
hipHostMalloc(&Bh, SIZE, 0);
memcpy(Ah, A, SIZE);
hipStream_t stream;
hipStreamCreate(&stream);
hipMemcpyHtoDAsync(Ad, Ah, SIZE, stream);
hipStreamSynchronize(stream);
hipMemcpyDtoDAsync(Bd, Ad, SIZE, stream);
hipStreamSynchronize(stream);
hipMemcpyDtoHAsync(Bh, Bd, SIZE, stream);
hipStreamSynchronize(stream);
hipMemcpyHtoDAsync(Ad, Ah, SIZE, stream);
hipStreamSynchronize(stream);
hipMemcpyDtoDAsync(Bd, Ad, SIZE, stream);
hipStreamSynchronize(stream);
hipMemcpyDtoHAsync(Bh, Bd, SIZE, stream);
hipStreamSynchronize(stream);
std::cout<<Ah[10]<<" "<<Bh[10]<<std::endl;
std::cout << Ah[10] << " " << Bh[10] << std::endl;
}
@@ -37,30 +37,28 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include "test_common.h"
int main(int argc, char *argv[])
{
HipTest::parseStandardArguments(argc, argv, true);
size_t Nbytes = N*sizeof(char);
char *A_h;
hipDeviceptr_t A_d;
A_h = new char[Nbytes];
int main(int argc, char* argv[]) {
HipTest::parseStandardArguments(argc, argv, true);
size_t Nbytes = N * sizeof(char);
char* A_h;
hipDeviceptr_t A_d;
A_h = new char[Nbytes];
HIPCHECK ( hipMalloc((void **) &A_d, Nbytes) );
HIPCHECK(hipMalloc((void**)&A_d, Nbytes));
printf ("Size=%zu memsetval=%2x \n", Nbytes, memsetval);
HIPCHECK ( hipMemsetD8(A_d, memsetval, Nbytes) );
printf("Size=%zu memsetval=%2x \n", Nbytes, memsetval);
HIPCHECK(hipMemsetD8(A_d, memsetval, Nbytes));
HIPCHECK ( hipMemcpy(A_h, (void *) A_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK(hipMemcpy(A_h, (void*)A_d, Nbytes, hipMemcpyDeviceToHost));
for (int i=0; i<N; i++) {
for (int i = 0; i < N; i++) {
if (A_h[i] != memsetval) {
failed("mismatch at index:%d computed:%02x, memsetval:%02x\n", i, (int)A_h[i], (int)memsetval);
failed("mismatch at index:%d computed:%02x, memsetval:%02x\n", i, (int)A_h[i],
(int)memsetval);
}
}
hipFree((void *) A_d);
delete [] A_h;
hipFree((void*)A_d);
delete[] A_h;
passed();
}
@@ -24,22 +24,22 @@ THE SOFTWARE.
#include "hip/hcc_detail/hip_complex.h"
#define LEN 64
#define SIZE 64<<2
#define SIZE 64 << 2
__global__ void getSqAbs(hipLaunchParm lp, float *A, float *B, float *C){
__global__ void getSqAbs(hipLaunchParm lp, float* A, float* B, float* C) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
C[tx] = hipCsqabsf(make_hipFloatComplex(A[tx], B[tx]));
}
int main(){
int main() {
float *A, *Ad, *B, *Bd, *C, *Cd;
A = new float[LEN];
B = new float[LEN];
C = new float[LEN];
for(uint32_t i=0;i<LEN;i++){
A[i] = i*1.0f;
B[i] = i*1.0f;
C[i] = i*1.0f;
for (uint32_t i = 0; i < LEN; i++) {
A[i] = i * 1.0f;
B[i] = i * 1.0f;
C[i] = i * 1.0f;
}
hipMalloc((void**)&Ad, SIZE);
@@ -49,5 +49,5 @@ int main(){
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
hipLaunchKernel(getSqAbs, dim3(1), dim3(LEN), 0, 0, Ad, Bd, Cd);
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
std::cout<<A[11]<<" "<<B[11]<<" "<<C[11]<<std::endl;
std::cout << A[11] << " " << B[11] << " " << C[11] << std::endl;
}
@@ -14,27 +14,24 @@
*/
__global__ void cpy(hipLaunchParm lp, uint32_t *Out, uint32_t *In)
{
__global__ void cpy(hipLaunchParm lp, uint32_t* Out, uint32_t* In) {
int tx = threadIdx.x;
memcpy(Out + tx, In + tx, sizeof(uint32_t));
}
__global__ void set(hipLaunchParm lp, uint32_t *ptr, uint8_t val, size_t size)
{
__global__ void set(hipLaunchParm lp, uint32_t* ptr, uint8_t val, size_t size) {
int tx = threadIdx.x;
memset(ptr + tx, val, sizeof(uint32_t));
}
int main()
{
int main() {
uint32_t *A, *Ad, *B, *Bd;
uint32_t *Val;
uint32_t* Val;
A = new uint32_t[LEN];
B = new uint32_t[LEN];
Val = new uint32_t;
*Val = 0;
for(int i=0;i<LEN;i++){
for (int i = 0; i < LEN; i++) {
A[i] = i;
B[i] = 0;
}
@@ -45,16 +42,16 @@ int main()
hipLaunchKernel(cpy, dim3(1), dim3(LEN), 0, 0, Bd, Ad);
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
for(int i=LEN-16;i<LEN;i++){
if(A[i]!=B[i]){
for (int i = LEN - 16; i < LEN; i++) {
if (A[i] != B[i]) {
return 0;
}
}
hipLaunchKernel(set, dim3(1), dim3(LEN), 0, 0, Bd, 0x1, LEN);
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
for(int i=LEN-16;i<LEN;i++){
if(0x01010101!=B[i]){
for (int i = LEN - 16; i < LEN; i++) {
if (0x01010101 != B[i]) {
return 0;
}
}
@@ -33,8 +33,7 @@ THE SOFTWARE.
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__device__ void double_precision_intrinsics()
{
__device__ void double_precision_intrinsics() {
__dadd_rd(0.0, 1.0);
__dadd_rn(0.0, 1.0);
__dadd_ru(0.0, 1.0);
@@ -65,13 +64,11 @@ __device__ void double_precision_intrinsics()
__fma_rz(1.0, 2.0, 3.0);
}
__global__ void compileDoublePrecisionIntrinsics(hipLaunchParm lp, int ignored)
{
__global__ void compileDoublePrecisionIntrinsics(hipLaunchParm lp, int ignored) {
double_precision_intrinsics();
}
int main()
{
hipLaunchKernel(compileDoublePrecisionIntrinsics, dim3(1,1,1), dim3(1,1,1), 0, 0, 1);
passed();
int main() {
hipLaunchKernel(compileDoublePrecisionIntrinsics, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
passed();
}
@@ -33,8 +33,7 @@ THE SOFTWARE.
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__device__ void double_precision_math_functions()
{
__device__ void double_precision_math_functions() {
int iX;
double fX, fY;
@@ -51,8 +50,8 @@ __device__ void double_precision_math_functions()
cos(0.0);
cosh(0.0);
cospi(0.0);
// cyl_bessel_i0(0.0);
// cyl_bessel_i1(0.0);
// cyl_bessel_i0(0.0);
// cyl_bessel_i1(0.0);
erf(0.0);
erfc(0.0);
erfcinv(2.0);
@@ -79,7 +78,7 @@ __device__ void double_precision_math_functions()
j1(0.0);
jn(-1.0, 1.0);
ldexp(0.0, 0);
// lgamma(1.0);
// lgamma(1.0);
llrint(0.0);
llround(0.0);
log(1.0);
@@ -89,28 +88,30 @@ __device__ void double_precision_math_functions()
logb(1.0);
lrint(0.0);
lround(0.0);
// modf(0.0, &fX);
// modf(0.0, &fX);
nan("1");
nearbyint(0.0);
nextafter(0.0, 0.0);
fX = 1.0; norm(1, &fX);
fX = 1.0;
norm(1, &fX);
norm3d(1.0, 0.0, 0.0);
norm4d(1.0, 0.0, 0.0, 0.0);
normcdf(0.0);
normcdfinv(1.0);
pow(1.0, 0.0);
//rcbrt(1.0);
// rcbrt(1.0);
remainder(2.0, 1.0);
// remquo(1.0, 2.0, &iX);
// remquo(1.0, 2.0, &iX);
rhypot(0.0, 1.0);
rint(1.0);
fX = 1.0; rnorm(1, &fX);
fX = 1.0;
rnorm(1, &fX);
rnorm3d(0.0, 0.0, 1.0);
rnorm4d(0.0, 0.0, 0.0, 1.0);
round(0.0);
rsqrt(1.0);
//scalbln(0.0, 1);
//scalbn(0.0, 1);
// scalbln(0.0, 1);
// scalbn(0.0, 1);
signbit(1.0);
sin(0.0);
sincos(0.0, &fX, &fY);
@@ -127,13 +128,11 @@ __device__ void double_precision_math_functions()
yn(1, 1.0);
}
__global__ void compileDoublePrecisionMathOnDevice(hipLaunchParm lp, int ignored)
{
__global__ void compileDoublePrecisionMathOnDevice(hipLaunchParm lp, int ignored) {
double_precision_math_functions();
}
int main()
{
hipLaunchKernel(compileDoublePrecisionMathOnDevice, dim3(1,1,1), dim3(1,1,1), 0, 0, 1);
passed();
int main() {
hipLaunchKernel(compileDoublePrecisionMathOnDevice, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
passed();
}
@@ -29,13 +29,12 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
//#include <hip/math_functions.h>
#include "test_common.h"
#include<cmath>
#include <cmath>
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__host__ void double_precision_math_functions()
{
__host__ void double_precision_math_functions() {
int iX;
double fX, fY;
@@ -51,14 +50,14 @@ __host__ void double_precision_math_functions()
copysign(1.0, -2.0);
cos(0.0);
cosh(0.0);
//cospi(0.0);
//cyl_bessel_i0(0.0);
//cyl_bessel_i1(0.0);
// cospi(0.0);
// cyl_bessel_i0(0.0);
// cyl_bessel_i1(0.0);
erf(0.0);
erfc(0.0);
//erfcinv(2.0);
//erfcx(0.0);
//erfinv(1.0);
// erfcinv(2.0);
// erfcx(0.0);
// erfinv(1.0);
exp(0.0);
exp10(0.0);
exp2(0.0);
@@ -80,7 +79,7 @@ __host__ void double_precision_math_functions()
j1(0.0);
jn(-1.0, 1.0);
ldexp(0.0, 0);
// lgamma(1.0);
// lgamma(1.0);
llrint(0.0);
llround(0.0);
log(1.0);
@@ -93,38 +92,38 @@ __host__ void double_precision_math_functions()
modf(0.0, &fX);
nan("1");
nearbyint(0.0);
//nextafter(0.0);
fX = 1.0; //norm(1, &fX);
// nextafter(0.0);
fX = 1.0; // norm(1, &fX);
#if defined(__HIP_PLATFORM_HCC__)
//norm3d(1.0, 0.0, 0.0);
//norm4d(1.0, 0.0, 0.0, 0.0);
// norm3d(1.0, 0.0, 0.0);
// norm4d(1.0, 0.0, 0.0, 0.0);
#endif
// normcdf(0.0);
// normcdfinv(1.0);
// normcdf(0.0);
// normcdfinv(1.0);
pow(1.0, 0.0);
//rcbrt(1.0);
// rcbrt(1.0);
remainder(2.0, 1.0);
remquo(1.0, 2.0, &iX);
#if defined(__HIP_PLATFORM_HCC__)
//rhypot(0.0, 1.0);
// rhypot(0.0, 1.0);
#endif
rint(1.0);
#if defined(__HIP_PLATFORM_HCC__)
fX = 1.0; //rnorm(1, &fX);
//rnorm3d(0.0, 0.0, 1.0);
//rnorm4d(0.0, 0.0, 0.0, 1.0);
fX = 1.0; // rnorm(1, &fX);
// rnorm3d(0.0, 0.0, 1.0);
// rnorm4d(0.0, 0.0, 0.0, 1.0);
#endif
round(0.0);
//rsqrt(1.0);
// rsqrt(1.0);
scalbln(0.0, 1);
scalbn(0.0, 1);
std::signbit(1.0);
sin(0.0);
sincos(0.0, &fX, &fY);
//sincospi(0.0, &fX, &fY);
// sincospi(0.0, &fX, &fY);
sinh(0.0);
//sinpi(0.0);
// sinpi(0.0);
sqrt(0.0);
tan(0.0);
tanh(0.0);
@@ -135,13 +134,9 @@ __host__ void double_precision_math_functions()
yn(1, 1.0);
}
static void compileOnHost()
{
double_precision_math_functions();
}
static void compileOnHost() { double_precision_math_functions(); }
int main()
{
compileOnHost();
passed();
int main() {
compileOnHost();
passed();
}
@@ -30,34 +30,33 @@ THE SOFTWARE.
#include <hip/device_functions.h>
#define LEN 512
#define SIZE LEN<<2
#define SIZE LEN << 2
__global__ void floatMath(hipLaunchParm lp, float *In, float *Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
Out[tid] = __cosf(In[tid]);
Out[tid] = __exp10f(Out[tid]);
Out[tid] = __expf(Out[tid]);
Out[tid] = __frsqrt_rn(Out[tid]);
Out[tid] = __fsqrt_rd(Out[tid]);
Out[tid] = __fsqrt_rn(Out[tid]);
Out[tid] = __fsqrt_ru(Out[tid]);
Out[tid] = __fsqrt_rz(Out[tid]);
Out[tid] = __log10f(Out[tid]);
Out[tid] = __log2f(Out[tid]);
Out[tid] = __logf(Out[tid]);
Out[tid] = __powf(2.0f, Out[tid]);
__sincosf(Out[tid], &In[tid], &Out[tid]);
Out[tid] = __sinf(Out[tid]);
Out[tid] = __cosf(Out[tid]);
Out[tid] = __tanf(Out[tid]);
__global__ void floatMath(hipLaunchParm lp, float* In, float* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
Out[tid] = __cosf(In[tid]);
Out[tid] = __exp10f(Out[tid]);
Out[tid] = __expf(Out[tid]);
Out[tid] = __frsqrt_rn(Out[tid]);
Out[tid] = __fsqrt_rd(Out[tid]);
Out[tid] = __fsqrt_rn(Out[tid]);
Out[tid] = __fsqrt_ru(Out[tid]);
Out[tid] = __fsqrt_rz(Out[tid]);
Out[tid] = __log10f(Out[tid]);
Out[tid] = __log2f(Out[tid]);
Out[tid] = __logf(Out[tid]);
Out[tid] = __powf(2.0f, Out[tid]);
__sincosf(Out[tid], &In[tid], &Out[tid]);
Out[tid] = __sinf(Out[tid]);
Out[tid] = __cosf(Out[tid]);
Out[tid] = __tanf(Out[tid]);
}
int main(){
float *Ind, *Outd;
hipMalloc((void**)&Ind, SIZE);
hipMalloc((void**)&Outd, SIZE);
hipLaunchKernel(floatMath, dim3(LEN,1,1), dim3(1,1,1), 0, 0, Ind, Outd);
passed();
int main() {
float *Ind, *Outd;
hipMalloc((void**)&Ind, SIZE);
hipMalloc((void**)&Outd, SIZE);
hipLaunchKernel(floatMath, dim3(LEN, 1, 1), dim3(1, 1, 1), 0, 0, Ind, Outd);
passed();
}
@@ -30,9 +30,8 @@ THE SOFTWARE.
#include <hip/math_functions.h>
#include "test_common.h"
__global__ void FloatMathPrecise(hipLaunchParm lp)
{
//int iX; //uncomment this when remqouf() is enabled again
__global__ void FloatMathPrecise(hipLaunchParm lp) {
// int iX; //uncomment this when remqouf() is enabled again
float fX, fY;
acosf(1.0f);
@@ -48,8 +47,8 @@ __global__ void FloatMathPrecise(hipLaunchParm lp)
cosf(0.0f);
coshf(0.0f);
cospif(0.0f);
//cyl_bessel_i0f(0.0f);
//cyl_bessel_i1f(0.0f);
// cyl_bessel_i0f(0.0f);
// cyl_bessel_i1f(0.0f);
erfcf(0.0f);
erfcinvf(2.0f);
erfcxf(0.0f);
@@ -67,7 +66,7 @@ __global__ void FloatMathPrecise(hipLaunchParm lp)
fX = fmaxf(0.0f, 0.0f);
fX = fminf(0.0f, 0.0f);
fmodf(0.0f, 1.0f);
//frexpf(0.0f, &iX);
// frexpf(0.0f, &iX);
hypotf(1.0f, 0.0f);
ilogbf(1.0f);
isfinite(0.0f);
@@ -77,7 +76,7 @@ __global__ void FloatMathPrecise(hipLaunchParm lp)
j1f(0.0f);
jnf(-1.0f, 1.0f);
ldexpf(0.0f, 0);
//lgammaf(1.0f);
// lgammaf(1.0f);
llrintf(0.0f);
llroundf(0.0f);
log10f(1.0f);
@@ -87,24 +86,26 @@ __global__ void FloatMathPrecise(hipLaunchParm lp)
logf(1.0f);
lrintf(0.0f);
lroundf(0.0f);
//modff(0.0f, &fX);
// modff(0.0f, &fX);
fX = nanf("1");
fX = nearbyintf(0.0f);
//nextafterf(0.0f);
// nextafterf(0.0f);
norm3df(1.0f, 0.0f, 0.0f);
norm4df(1.0f, 0.0f, 0.0f, 0.0f);
normcdff(0.0f);
normcdfinvf(1.0f);
fX = 1.0f; normf(1, &fX);
fX = 1.0f;
normf(1, &fX);
powf(1.0f, 0.0f);
rcbrtf(1.0f);
remainderf(2.0f, 1.0f);
//remquof(1.0f, 2.0f, &iX);
// remquof(1.0f, 2.0f, &iX);
rhypotf(0.0f, 1.0f);
fY = rintf(1.0f);
rnorm3df(0.0f, 0.0f, 1.0f);
rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
fX = 1.0f; rnormf(1, &fX);
fX = 1.0f;
rnormf(1, &fX);
fY = roundf(0.0f);
rsqrtf(1.0f);
scalblnf(0.0f, 1);
@@ -126,6 +127,6 @@ __global__ void FloatMathPrecise(hipLaunchParm lp)
}
int main() {
hipLaunchKernel(FloatMathPrecise, dim3(1,1,1), dim3(1,1,1), 0, 0);
hipLaunchKernel(FloatMathPrecise, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0);
passed();
}
@@ -34,8 +34,7 @@ THE SOFTWARE.
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__device__ void integer_intrinsics()
{
__device__ void integer_intrinsics() {
__brev((unsigned int)10);
__brevll((unsigned long long)10);
__byte_perm((unsigned int)0, (unsigned int)0, 0);
@@ -63,13 +62,9 @@ __device__ void integer_intrinsics()
assert(1);
}
__global__ void compileIntegerIntrinsics(hipLaunchParm lp, int ignored)
{
integer_intrinsics();
}
__global__ void compileIntegerIntrinsics(hipLaunchParm lp, int ignored) { integer_intrinsics(); }
int main()
{
hipLaunchKernel(compileIntegerIntrinsics, dim3(1,1,1), dim3(1,1,1), 0, 0, 1);
passed();
int main() {
hipLaunchKernel(compileIntegerIntrinsics, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
passed();
}
@@ -24,8 +24,7 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include "test_common.h"
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
HipTest::parseStandardArguments(argc, argv, true);
passed();
@@ -34,9 +34,9 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include <test_common.h>
#define EXIT_WAIVED 2
#define EXIT_WAIVED 2
const char *sampleName = "hipSimpleAtomicsTest";
const char* sampleName = "hipSimpleAtomicsTest";
////////////////////////////////////////////////////////////////////////////////
// Auto-Verification Code
@@ -44,81 +44,69 @@ bool testResult = true;
////////////////////////////////////////////////////////////////////////////////
// Declaration, forward
void runTest(int argc, char **argv);
void runTest(int argc, char** argv);
#define min(a,b) (a) < (b) ? (a) : (b)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a, b) (a) < (b) ? (a) : (b)
#define max(a, b) (a) > (b) ? (a) : (b)
int computeGold(int *gpuData, const int len)
{
int computeGold(int* gpuData, const int len) {
int val = 0;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
val += 10;
}
if (val != gpuData[0])
{
if (val != gpuData[0]) {
printf("atomicAdd failed\n");
return false;
}
val = 0;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
val -= 10;
}
if (val != gpuData[1])
{
if (val != gpuData[1]) {
printf("atomicSub failed\n");
return false;
}
bool found = false;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
// third element should be a member of [0, len)
if (i == gpuData[2])
{
if (i == gpuData[2]) {
found = true;
break;
}
}
if (!found)
{
if (!found) {
printf("atomicExch failed\n");
return false;
}
val = -(1 << 8);
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
// fourth element should be len-1
val = max(val, i);
}
if (val != gpuData[3])
{
if (val != gpuData[3]) {
printf("atomicMax failed\n");
return false;
}
val = 1 << 8;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
val = min(val, i);
}
if (val != gpuData[4])
{
if (val != gpuData[4]) {
printf("atomicMin failed\n");
return false;
}
@@ -126,13 +114,11 @@ int computeGold(int *gpuData, const int len)
int limit = 17;
val = 0;
for (int i = 0; i < len; ++i)
{
val = (val >= limit) ? 0 : val+1;
for (int i = 0; i < len; ++i) {
val = (val >= limit) ? 0 : val + 1;
}
if (val != gpuData[5])
{
if (val != gpuData[5]) {
printf("atomicInc failed\n");
return false;
}
@@ -140,73 +126,62 @@ int computeGold(int *gpuData, const int len)
limit = 137;
val = 0;
for (int i = 0; i < len; ++i)
{
val = ((val == 0) || (val > limit)) ? limit : val-1;
for (int i = 0; i < len; ++i) {
val = ((val == 0) || (val > limit)) ? limit : val - 1;
}
if (val != gpuData[6])
{
if (val != gpuData[6]) {
printf("atomicDec failed\n");
return false;
}
found = false;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
// eighth element should be a member of [0, len)
if (i == gpuData[7])
{
if (i == gpuData[7]) {
found = true;
break;
}
}
if (!found)
{
if (!found) {
printf("atomicCAS failed\n");
return false;
}
val = 0xff;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
// 9th element should be 1
val &= (2 * i + 7);
}
if (val != gpuData[8])
{
if (val != gpuData[8]) {
printf("atomicAnd failed\n");
return false;
}
val = 0;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
// 10th element should be 0xff
val |= (1 << i);
}
if (val != gpuData[9])
{
if (val != gpuData[9]) {
printf("atomicOr failed\n");
return false;
}
val = 0xff;
for (int i = 0; i < len; ++i)
{
for (int i = 0; i < len; ++i) {
// 11th element should be 0xff
val ^= i;
}
if (val != gpuData[10])
{
if (val != gpuData[10]) {
printf("atomicXor failed\n");
return false;
}
@@ -214,8 +189,7 @@ int computeGold(int *gpuData, const int len)
return true;
}
__global__ void testKernel(hipLaunchParm lp,int *g_odata)
{
__global__ void testKernel(hipLaunchParm lp, int* g_odata) {
// access thread id
const unsigned int tid = blockDim.x * blockIdx.x + threadIdx.x;
@@ -239,18 +213,18 @@ __global__ void testKernel(hipLaunchParm lp,int *g_odata)
atomicMin(&g_odata[4], tid);
// Atomic increment (modulo 17+1)
atomicInc((unsigned int *)&g_odata[5], 17);
atomicInc((unsigned int*)&g_odata[5], 17);
// Atomic decrement
atomicDec((unsigned int *)&g_odata[6], 137);
atomicDec((unsigned int*)&g_odata[6], 137);
// Atomic compare-and-swap
atomicCAS(&g_odata[7], tid-1, tid);
atomicCAS(&g_odata[7], tid - 1, tid);
// Bitwise atomic instructions
// Atomic AND
atomicAnd(&g_odata[8], 2*tid+7);
atomicAnd(&g_odata[8], 2 * tid + 7);
// Atomic OR
atomicOr(&g_odata[9], 1 << tid);
@@ -260,21 +234,17 @@ __global__ void testKernel(hipLaunchParm lp,int *g_odata)
}
int main(int argc, char **argv)
{
int main(int argc, char** argv) {
printf("%s starting...\n", sampleName);
runTest(argc, argv);
hipDeviceReset();
printf("%s completed, returned %s\n",
sampleName,
testResult ? "OK" : "ERROR!");
printf("%s completed, returned %s\n", sampleName, testResult ? "OK" : "ERROR!");
exit(testResult ? EXIT_SUCCESS : EXIT_FAILURE);
}
void runTest(int argc, char **argv)
{
void runTest(int argc, char** argv) {
hipDeviceProp_t deviceProp;
deviceProp.major = 0;
deviceProp.minor = 0;
@@ -283,10 +253,10 @@ void runTest(int argc, char **argv)
hipGetDeviceProperties(&deviceProp, dev);
// Statistics about the GPU device
printf("> GPU device has %d Multi-Processors, "
"SM %d.%d compute capabilities\n\n",
deviceProp.multiProcessorCount, deviceProp.major, deviceProp.minor);
printf(
"> GPU device has %d Multi-Processors, "
"SM %d.%d compute capabilities\n\n",
deviceProp.multiProcessorCount, deviceProp.major, deviceProp.minor);
unsigned int numThreads = 256;
@@ -294,27 +264,26 @@ void runTest(int argc, char **argv)
unsigned int numData = 11;
unsigned int memSize = sizeof(int) * numData;
//allocate mem for the result on host side
int *hOData = (int *) malloc(memSize);
// allocate mem for the result on host side
int* hOData = (int*)malloc(memSize);
//initialize the memory
for (unsigned int i = 0; i < numData; i++)
hOData[i] = 0;
// initialize the memory
for (unsigned int i = 0; i < numData; i++) hOData[i] = 0;
//To make the AND and XOR tests generate something other than 0...
// To make the AND and XOR tests generate something other than 0...
hOData[8] = hOData[10] = 0xff;
// allocate device memory for result
int *dOData;
hipMalloc((void **) &dOData, memSize);
int* dOData;
hipMalloc((void**)&dOData, memSize);
// copy host memory to device to initialize to zero
hipMemcpy(dOData, hOData, memSize,hipMemcpyHostToDevice);
hipMemcpy(dOData, hOData, memSize, hipMemcpyHostToDevice);
// execute the kernel
hipLaunchKernel(testKernel, dim3(numBlocks), dim3(numThreads), 0, 0, dOData);
//Copy result from device to host
hipMemcpy(hOData,dOData, memSize,hipMemcpyDeviceToHost);
// Copy result from device to host
hipMemcpy(hOData, dOData, memSize, hipMemcpyDeviceToHost);
// Compute reference solution
testResult = computeGold(hOData, numThreads * numBlocks);
@@ -32,8 +32,7 @@ THE SOFTWARE.
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__device__ void single_precision_intrinsics()
{
__device__ void single_precision_intrinsics() {
float fX, fY;
__cosf(0.0f);
@@ -80,14 +79,12 @@ __device__ void single_precision_intrinsics()
}
__global__ void compileSinglePrecisionIntrinsics(hipLaunchParm lp, int ignored)
{
__global__ void compileSinglePrecisionIntrinsics(hipLaunchParm lp, int ignored) {
single_precision_intrinsics();
}
int main()
{
hipLaunchKernel(compileSinglePrecisionIntrinsics, dim3(1,1,1), dim3(1,1,1), 0, 0, 1);
passed();
int main() {
hipLaunchKernel(compileSinglePrecisionIntrinsics, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
passed();
}
@@ -33,8 +33,7 @@ THE SOFTWARE.
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__device__ void single_precision_math_functions()
{
__device__ void single_precision_math_functions() {
int iX;
float fX, fY;
@@ -51,8 +50,8 @@ __device__ void single_precision_math_functions()
cosf(0.0f);
coshf(0.0f);
cospif(0.0f);
//cyl_bessel_i0f(0.0f);
//cyl_bessel_i1f(0.0f);
// cyl_bessel_i0f(0.0f);
// cyl_bessel_i1f(0.0f);
erfcf(0.0f);
erfcinvf(2.0f);
erfcxf(0.0f);
@@ -80,7 +79,7 @@ __device__ void single_precision_math_functions()
j1f(0.0f);
jnf(-1.0f, 1.0f);
ldexpf(0.0f, 0);
//lgammaf(1.0f);
// lgammaf(1.0f);
llrintf(0.0f);
llroundf(0.0f);
log10f(1.0f);
@@ -90,28 +89,30 @@ __device__ void single_precision_math_functions()
logf(1.0f);
lrintf(0.0f);
lroundf(0.0f);
//modff(0.0f, &fX);
// modff(0.0f, &fX);
nanf("1");
nearbyintf(0.0f);
//nextafterf(0.0f);
// nextafterf(0.0f);
norm3df(1.0f, 0.0f, 0.0f);
norm4df(1.0f, 0.0f, 0.0f, 0.0f);
normcdff(0.0f);
normcdfinvf(1.0f);
fX = 1.0f; normf(1, &fX);
fX = 1.0f;
normf(1, &fX);
powf(1.0f, 0.0f);
//rcbrtf(1.0f);
// rcbrtf(1.0f);
remainderf(2.0f, 1.0f);
//remquof(1.0f, 2.0f, &iX);
// remquof(1.0f, 2.0f, &iX);
rhypotf(0.0f, 1.0f);
rintf(1.0f);
rnorm3df(0.0f, 0.0f, 1.0f);
rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
fX = 1.0f; rnormf(1, &fX);
fX = 1.0f;
rnormf(1, &fX);
roundf(0.0f);
rsqrtf(1.0f);
//scalblnf(0.0f, 1);
//scalbnf(0.0f, 1);
// scalblnf(0.0f, 1);
// scalbnf(0.0f, 1);
signbit(1.0f);
sincosf(0.0f, &fX, &fY);
sincospif(0.0f, &fX, &fY);
@@ -128,13 +129,11 @@ __device__ void single_precision_math_functions()
ynf(1, 1.0f);
}
__global__ void compileSinglePrecisionMathOnDevice(hipLaunchParm lp, int ignored)
{
__global__ void compileSinglePrecisionMathOnDevice(hipLaunchParm lp, int ignored) {
single_precision_math_functions();
}
int main()
{
hipLaunchKernel(compileSinglePrecisionMathOnDevice, dim3(1,1,1), dim3(1,1,1), 0, 0, 1);
passed();
int main() {
hipLaunchKernel(compileSinglePrecisionMathOnDevice, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
passed();
}
@@ -29,13 +29,12 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
//#include <hip/math_functions.h>
#include "test_common.h"
#include<cmath>
#include <cmath>
#pragma GCC diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wunused-variable"
__host__ void single_precision_math_functions()
{
__host__ void single_precision_math_functions() {
int iX;
float fX, fY;
@@ -51,14 +50,14 @@ __host__ void single_precision_math_functions()
copysignf(1.0f, -2.0f);
cosf(0.0f);
coshf(0.0f);
//cospif(0.0f);
//cyl_bessel_i0f(0.0f);
//cyl_bessel_i1f(0.0f);
// cospif(0.0f);
// cyl_bessel_i0f(0.0f);
// cyl_bessel_i1f(0.0f);
erfcf(0.0f);
//erfcinvf(2.0f);
//erfcxf(0.0f);
// erfcinvf(2.0f);
// erfcxf(0.0f);
erff(0.0f);
//erfinvf(1.0f);
// erfinvf(1.0f);
exp10f(0.0f);
exp2f(0.0f);
expf(0.0f);
@@ -66,7 +65,7 @@ __host__ void single_precision_math_functions()
fabsf(1.0f);
fdimf(1.0f, 0.0f);
#if defined(__HIP_PLATFORM_HCC__)
//fdividef(0.0f, 1.0f);
// fdividef(0.0f, 1.0f);
#endif
floorf(0.0f);
fmaf(1.0f, 2.0f, 3.0f);
@@ -96,37 +95,37 @@ __host__ void single_precision_math_functions()
modff(0.0f, &fX);
nanf("1");
nearbyintf(0.0f);
//nextafterf(0.0f);
// nextafterf(0.0f);
#if defined(__HIP_PLATFORM_HCC__)
//norm3df(1.0f, 0.0f, 0.0f);
//norm4df(1.0f, 0.0f, 0.0f, 0.0f);
// norm3df(1.0f, 0.0f, 0.0f);
// norm4df(1.0f, 0.0f, 0.0f, 0.0f);
#endif
//normcdff(0.0f);
//normcdfinvf(1.0f);
//fX = 1.0f; normf(1, &fX);
// normcdff(0.0f);
// normcdfinvf(1.0f);
// fX = 1.0f; normf(1, &fX);
powf(1.0f, 0.0f);
//rcbrtf(1.0f);
// rcbrtf(1.0f);
remainderf(2.0f, 1.0f);
remquof(1.0f, 2.0f, &iX);
#if defined(__HIP_PLATFORM_HCC__)
//rhypotf(0.0f, 1.0f);
// rhypotf(0.0f, 1.0f);
#endif
rintf(1.0f);
#if defined(__HIP_PLATFORM_HCC__)
//rnorm3df(0.0f, 0.0f, 1.0f);
//rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
fX = 1.0f; //rnormf(1, &fX);
// rnorm3df(0.0f, 0.0f, 1.0f);
// rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
fX = 1.0f; // rnormf(1, &fX);
#endif
roundf(0.0f);
///rsqrtf(1.0f);
/// rsqrtf(1.0f);
scalblnf(0.0f, 1);
scalbnf(0.0f, 1);
std::signbit(1.0f);
sincosf(0.0f, &fX, &fY);
//sincospif(0.0f, &fX, &fY);
// sincospif(0.0f, &fX, &fY);
sinf(0.0f);
sinhf(0.0f);
//sinpif(0.0f);
// sinpif(0.0f);
sqrtf(0.0f);
tanf(0.0f);
tanhf(0.0f);
@@ -137,13 +136,9 @@ __host__ void single_precision_math_functions()
ynf(1, 1.0f);
}
static void compileOnHost()
{
single_precision_math_functions();
}
static void compileOnHost() { single_precision_math_functions(); }
int main()
{
compileOnHost();
passed();
int main() {
compileOnHost();
passed();
}
تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است Diff را بارگزاری کن
تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است Diff را بارگزاری کن
@@ -17,12 +17,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include<hip/hip_runtime_api.h>
#include<iostream>
#include<assert.h>
#include <hip/hip_runtime_api.h>
#include <iostream>
#include <assert.h>
int main()
{
int main() {
size_t heap;
assert(hipSuccess == hipDeviceGetLimit(&heap, hipLimitMallocHeapSize));
assert(heap == 4194304);
@@ -23,32 +23,30 @@ THE SOFTWARE.
* HIT_END
*/
#include<hip/hip_runtime.h>
#include<hip/hip_runtime_api.h>
#include"test_common.h"
#include<iostream>
#include <hip/hip_runtime.h>
#include <hip/hip_runtime_api.h>
#include "test_common.h"
#include <iostream>
#define NUM 1024
#define SIZE 1024*4
#define SIZE 1024 * 4
__device__ int globalIn[NUM];
__device__ int globalOut[NUM];
__global__ void Assign(hipLaunchParm lp, int* Out)
{
__global__ void Assign(hipLaunchParm lp, int* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
Out[tid] = globalIn[tid];
globalOut[tid] = globalIn[tid];
}
int main()
{
int main() {
int *A, *Am, *B, *Ad, *C, *Cm;
A = new int[NUM];
B = new int[NUM];
C = new int[NUM];
for(int i=0;i<NUM;i++) {
A[i] = -1*i;
for (int i = 0; i < NUM; i++) {
A[i] = -1 * i;
B[i] = 0;
C[i] = 0;
}
@@ -56,8 +54,8 @@ int main()
hipMalloc((void**)&Ad, SIZE);
hipHostMalloc((void**)&Am, SIZE);
hipHostMalloc((void**)&Cm, SIZE);
for(int i=0;i<NUM;i++) {
Am[i] = -1*i;
for (int i = 0; i < NUM; i++) {
Am[i] = -1 * i;
Cm[i] = 0;
}
@@ -65,41 +63,41 @@ int main()
hipStreamCreate(&stream);
hipMemcpyToSymbolAsync(HIP_SYMBOL(globalIn), Am, SIZE, 0, hipMemcpyHostToDevice, stream);
hipStreamSynchronize(stream);
hipLaunchKernel(Assign, dim3(1,1,1), dim3(NUM,1,1), 0, 0, Ad);
hipLaunchKernel(Assign, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, Ad);
hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost);
hipMemcpyFromSymbolAsync(Cm, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost, stream);
hipStreamSynchronize(stream);
for(int i=0;i<NUM;i++) {
for (int i = 0; i < NUM; i++) {
assert(Am[i] == B[i]);
assert(Am[i] == Cm[i]);
}
for(int i=0;i<NUM;i++) {
A[i] = -2*i;
for (int i = 0; i < NUM; i++) {
A[i] = -2 * i;
B[i] = 0;
}
hipMemcpyToSymbol(HIP_SYMBOL(globalIn), A, SIZE, 0, hipMemcpyHostToDevice);
hipLaunchKernel(Assign, dim3(1,1,1), dim3(NUM,1,1), 0, 0, Ad);
hipLaunchKernel(Assign, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, Ad);
hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost);
hipMemcpyFromSymbol(C, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost);
for(int i=0;i<NUM;i++) {
for (int i = 0; i < NUM; i++) {
assert(A[i] == B[i]);
assert(A[i] == C[i]);
}
for(int i=0;i<NUM;i++) {
A[i] = -3*i;
for (int i = 0; i < NUM; i++) {
A[i] = -3 * i;
B[i] = 0;
}
hipMemcpyToSymbolAsync(HIP_SYMBOL(globalIn), A, SIZE, 0, hipMemcpyHostToDevice, stream);
hipStreamSynchronize(stream);
hipLaunchKernel(Assign, dim3(1,1,1), dim3(NUM,1,1), 0, 0, Ad);
hipLaunchKernel(Assign, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, Ad);
hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost);
hipMemcpyFromSymbolAsync(C, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost, stream);
hipStreamSynchronize(stream);
for(int i=0;i<NUM;i++) {
for (int i = 0; i < NUM; i++) {
assert(A[i] == B[i]);
assert(A[i] == C[i]);
}
@@ -23,50 +23,50 @@ THE SOFTWARE.
#include "test_common.h"
#define LEN 64
#define HALF_SIZE 64*sizeof(__half)
#define HALF2_SIZE 64*sizeof(__half2)
#define HALF_SIZE 64 * sizeof(__half)
#define HALF2_SIZE 64 * sizeof(__half2)
#if __HIP_ARCH_GFX803__ || __HIP_ARCH_GFX900__
__global__ void __halfMath(hipLaunchParm lp, __half *A, __half *B, __half *C) {
int tx = threadIdx.x;
__half a = A[tx];
__half b = B[tx];
__half c = C[tx];
c = __hadd(a, c);
c = __hadd_sat(b, c);
c = __hfma(a, c, b);
c = __hfma_sat(b, c, a);
c = __hsub(a, c);
c = __hsub_sat(b, c);
c = __hmul(a, c);
c = __hmul_sat(b, c);
c = hdiv(a, c);
__global__ void __halfMath(hipLaunchParm lp, __half* A, __half* B, __half* C) {
int tx = threadIdx.x;
__half a = A[tx];
__half b = B[tx];
__half c = C[tx];
c = __hadd(a, c);
c = __hadd_sat(b, c);
c = __hfma(a, c, b);
c = __hfma_sat(b, c, a);
c = __hsub(a, c);
c = __hsub_sat(b, c);
c = __hmul(a, c);
c = __hmul_sat(b, c);
c = hdiv(a, c);
}
__global__ void __half2Math(hipLaunchParm lp, __half2 *A, __half2 *B, __half2 *C) {
int tx = threadIdx.x;
__half2 a = A[tx];
__half2 b = B[tx];
__half2 c = C[tx];
c = __hadd2(a, c);
c = __hadd2_sat(b, c);
c = __hfma2(a, c, b);
c = __hfma2_sat(b, c, a);
c = __hsub2(a, c);
c = __hsub2_sat(b, c);
c = __hmul2(a, c);
c = __hmul2_sat(b, c);
__global__ void __half2Math(hipLaunchParm lp, __half2* A, __half2* B, __half2* C) {
int tx = threadIdx.x;
__half2 a = A[tx];
__half2 b = B[tx];
__half2 c = C[tx];
c = __hadd2(a, c);
c = __hadd2_sat(b, c);
c = __hfma2(a, c, b);
c = __hfma2_sat(b, c, a);
c = __hsub2(a, c);
c = __hsub2_sat(b, c);
c = __hmul2(a, c);
c = __hmul2_sat(b, c);
}
#endif
int main(){
int main() {
__half *A, *B, *C;
hipMalloc(&A, HALF_SIZE);
hipMalloc(&B, HALF_SIZE);
hipMalloc(&C, HALF_SIZE);
hipLaunchKernel(__halfMath, dim3(1,1,1), dim3(LEN,1,1), 0, 0, A, B, C);
hipLaunchKernel(__halfMath, dim3(1, 1, 1), dim3(LEN, 1, 1), 0, 0, A, B, C);
hipFree(A);
hipFree(B);
hipFree(C);
@@ -74,7 +74,7 @@ int main(){
hipMalloc(&A2, HALF2_SIZE);
hipMalloc(&B2, HALF2_SIZE);
hipMalloc(&C2, HALF2_SIZE);
hipLaunchKernel(__half2Math, dim3(1,1,1), dim3(LEN,1,1), 0, 0, A2, B2, C2);
hipLaunchKernel(__half2Math, dim3(1, 1, 1), dim3(LEN, 1, 1), 0, 0, A2, B2, C2);
hipFree(A2);
hipFree(B2);
hipFree(C2);
@@ -23,234 +23,212 @@ THE SOFTWARE.
#define N 512
bool check_erfcinvf(){
bool check_erfcinvf() {
uint32_t len = 4;
float Val[] = {0.1, 1.2, 1, 0.9};
float Out[] = {1.16309, -0.179144, 0, 0.0889};
for(int i=0;i<len;i++){
if(Out[i] - erfcinvf(Val[i]) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Out[i] - erfcinvf(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_erfcxf(){
bool check_erfcxf() {
uint32_t len = 4;
float Val[] = {-0.5, 15, 3.2, 1};
float Out[] = {1.9524, 0.0375, 0.1687, 0.4276};
for(int i=0;i<len;i++){
if(Out[i] - erfcxf(Val[i]) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Out[i] - erfcxf(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_erfinvf()
{
bool check_erfinvf() {
uint32_t len = 4;
float Val[] = {0, -0.5, 0.9, -0.2};
float Out[] = {0, -0.4769, 1.1631, -0.1791};
for(int i=0;i<len;i++){
if(Out[i] - erfinvf(Val[i]) > 0.0001){
for (int i = 0; i < len; i++) {
if (Out[i] - erfinvf(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_fdividef()
{
bool check_fdividef() {
uint32_t len = 4;
float Val[] = {0, -0.5, 0.9, -0.2};
float Out[] = {1, -0.4769, 1.1631, -0.1791};
for(int i=0;i<len;i++){
if(Val[i]/Out[i] - fdividef(Val[i], Out[i]) > 0.0001){
for (int i = 0; i < len; i++) {
if (Val[i] / Out[i] - fdividef(Val[i], Out[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_erfcinv(){
bool check_erfcinv() {
uint32_t len = 4;
double Val[] = {0.1, 1.2, 1, 0.9};
double Out[] = {1.16309, -0.179144, 0, 0.0889};
for(int i=0;i<len;i++){
if(Out[i] - erfcinv(Val[i]) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Out[i] - erfcinv(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_erfcx(){
bool check_erfcx() {
uint32_t len = 4;
double Val[] = {-0.5, 15, 3.2, 1};
double Out[] = {1.9524, 0.0375, 0.1687, 0.4276};
for(int i=0;i<len;i++){
if(Out[i] - erfcx(Val[i]) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Out[i] - erfcx(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_erfinv()
{
bool check_erfinv() {
uint32_t len = 4;
double Val[] = {0, -0.5, 0.9, -0.2};
double Out[] = {0, -0.4769, 1.1631, -0.1791};
for(int i=0;i<len;i++){
if(Out[i] - erfinv(Val[i]) > 0.0001){
for (int i = 0; i < len; i++) {
if (Out[i] - erfinv(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_fdivide()
{
bool check_fdivide() {
uint32_t len = 4;
double Val[] = {0, -0.5, 0.9, -0.2};
double Out[] = {1, -0.4769, 1.1631, -0.1791};
for(int i=0;i<len;i++){
if(Val[i]/Out[i] - fdivide(Val[i], Out[i]) > 0.0001){
for (int i = 0; i < len; i++) {
if (Val[i] / Out[i] - fdivide(Val[i], Out[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_modff()
{
bool check_modff() {
uint32_t len = 4;
float Val[] = {0, -0.5, 0.9, -0.2};
float iPtr[] = {0, 0, 0, 0};
float frac[] = {0, -0.5, 0.9, -0.2};
float Out[] = {1, 1, 1, 1};
for(int i=0;i<len;i++){
if(frac[i] - modff(Val[i], Out+i) > 0.0001 && iPtr[i] == Out[i]){
for (int i = 0; i < len; i++) {
if (frac[i] - modff(Val[i], Out + i) > 0.0001 && iPtr[i] == Out[i]) {
return false;
}
}
return true;
}
bool check_modf()
{
bool check_modf() {
uint32_t len = 4;
double Val[] = {0, -0.5, 0.9, -0.2};
double iPtr[] = {0, 0, 0, 0};
double frac[] = {0, -0.5, 0.9, -0.2};
double Out[] = {1, 1, 1, 1};
for(int i=0;i<len;i++){
if(frac[i] - modf(Val[i], Out+i) > 0.0001 && iPtr[i] == Out[i]){
for (int i = 0; i < len; i++) {
if (frac[i] - modf(Val[i], Out + i) > 0.0001 && iPtr[i] == Out[i]) {
return false;
}
}
return true;
}
bool check_nextafterf()
{
bool check_nextafterf() {
uint32_t len = 4;
float Val[] = {0, -0.5, 0.9, -0.2};
float iPtr[] = {0, 0, 0, 0};
float frac[] = {0, -0.5, 0.9, -0.2};
float Out[] = {1, 1, 1, 1};
for(int i=0;i<len;i++){
if(nextafterf(Val[i],1) - Val[i] > 0.0001){
for (int i = 0; i < len; i++) {
if (nextafterf(Val[i], 1) - Val[i] > 0.0001) {
return false;
}
}
return true;
}
bool check_nextafter()
{
bool check_nextafter() {
uint32_t len = 4;
double Val[] = {0, -0.5, 0.9, -0.2};
double iPtr[] = {0, 0, 0, 0};
double frac[] = {0, -0.5, 0.9, -0.2};
double Out[] = {1, 1, 1, 1};
for(int i=0;i<len;i++){
if(nextafter(Val[i],1) - Val[i] > 0.0001){
for (int i = 0; i < len; i++) {
if (nextafter(Val[i], 1) - Val[i] > 0.0001) {
return false;
}
}
return true;
}
bool check_norm3df(float *A)
{
bool check_norm3df(float* A) {
float f = norm3df(A[0], A[1], A[2]);
float out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]);
if(f - out > 0.0001)
{
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
if (f - out > 0.0001) {
return false;
}
return true;
}
bool check_norm3d(double *A)
{
bool check_norm3d(double* A) {
double f = norm3d(A[0], A[1], A[2]);
double out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]);
if(f - out > 0.0001)
{
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
if (f - out > 0.0001) {
return false;
}
return true;
}
bool check_norm4df(float *A)
{
bool check_norm4df(float* A) {
float f = norm4df(A[0], A[1], A[2], A[3]);
float out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2] + A[3]*A[3]);
if(f - out > 0.0001)
{
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
if (f - out > 0.0001) {
return false;
}
return true;
}
bool check_norm4d(double *A)
{
bool check_norm4d(double* A) {
double f = norm4d(A[0], A[1], A[2], A[3]);
double out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2] + A[3]*A[3]);
if(f - out > 0.0001)
{
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
if (f - out > 0.0001) {
return false;
}
return true;
}
bool check_normcdff(){
bool check_normcdff() {
uint32_t len = 2;
float Val[] = {0,1};
float Val[] = {0, 1};
float Out[] = {0.5, 0.8413};
for(int i=0;i<len;i++){
if(Out[i] - normcdff(Val[i]) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Out[i] - normcdff(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
bool check_normcdf(){
bool check_normcdf() {
uint32_t len = 2;
float Val[] = {0,1};
float Val[] = {0, 1};
float Out[] = {0.5, 0.8413};
for(int i=0;i<len;i++){
if(Out[i] - normcdf(Val[i]) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Out[i] - normcdf(Val[i]) > 0.0001) {
return false;
}
}
@@ -258,174 +236,149 @@ bool check_normcdf(){
}
bool check_normcdfinvf(){
bool check_normcdfinvf() {
uint32_t len = 2;
double Val[] = {0.5, 0.8413};
for(int i=0;i<len;i++){
if(Val[i] - normcdfinvf(normcdff(Val[i])) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Val[i] - normcdfinvf(normcdff(Val[i])) > 0.0001) {
return false;
}
}
return true;
}
bool check_normcdfinv(){
bool check_normcdfinv() {
uint32_t len = 2;
double Val[] = {0.5, 0.8413};
for(int i=0;i<len;i++){
if(Val[i] - normcdfinv(normcdf(Val[i])) > 0.0001)
{
for (int i = 0; i < len; i++) {
if (Val[i] - normcdfinv(normcdf(Val[i])) > 0.0001) {
return false;
}
}
return true;
}
bool check_rcbrtf()
{
bool check_rcbrtf() {
float f = 1.0f;
if(rcbrtf(f) != 1.0f)
{
if (rcbrtf(f) != 1.0f) {
return false;
}
return true;
}
bool check_rcbrt()
{
bool check_rcbrt() {
double f = 1.0;
if(rcbrt(f) != 1.0)
{
if (rcbrt(f) != 1.0) {
return false;
}
return true;
}
bool check_rhypotf()
{
bool check_rhypotf() {
float f = 1.0f;
float g = 2.0f;
float val = rhypotf(f, g);
float sq = f*f + g*g ;
if(1/(val*val) - sq > 0.0001)
{
float sq = f * f + g * g;
if (1 / (val * val) - sq > 0.0001) {
return false;
}
return true;
}
bool check_rhypot()
{
bool check_rhypot() {
double f = 1.0f;
double g = 2.0f;
double val = rhypot(f, g);
double sq = f*f + g*g;
if(1/(val*val) - sq > 0.0001)
{
double sq = f * f + g * g;
if (1 / (val * val) - sq > 0.0001) {
return false;
}
return true;
}
bool check_rnorm3df(float *A)
{
bool check_rnorm3df(float* A) {
float f = rnorm3df(A[0], A[1], A[2]);
float out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]);
if(f - 1/out > 0.0001)
{
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
if (f - 1 / out > 0.0001) {
return false;
}
return true;
}
bool check_rnorm3d(double *A)
{
bool check_rnorm3d(double* A) {
double f = rnorm3d(A[0], A[1], A[2]);
double out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]);
if(f - 1/out > 0.0001)
{
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
if (f - 1 / out > 0.0001) {
return false;
}
return true;
}
bool check_rnorm4df(float *A)
{
bool check_rnorm4df(float* A) {
float f = rnorm4df(A[0], A[1], A[2], A[3]);
float out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2] + A[3]*A[3]);
if(f - 1/out > 0.0001)
{
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
if (f - 1 / out > 0.0001) {
return false;
}
return true;
}
bool check_rnorm4d(double *A)
{
bool check_rnorm4d(double* A) {
double f = rnorm4d(A[0], A[1], A[2], A[3]);
double out = sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2] + A[3]*A[3]);
if(f - 1/out > 0.0001)
{
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
if (f - 1 / out > 0.0001) {
return false;
}
return true;
}
bool check_rnormf(float *A)
{
return (rnorm3df(A[0],A[1],A[2]) - rnormf(3,A) < 0.0001) && (rnorm4df(A[0],A[1],A[2],A[3]) - rnormf(4, A) < 0.0001 );
bool check_rnormf(float* A) {
return (rnorm3df(A[0], A[1], A[2]) - rnormf(3, A) < 0.0001) &&
(rnorm4df(A[0], A[1], A[2], A[3]) - rnormf(4, A) < 0.0001);
}
bool check_rnorm(double *A)
{
return (rnorm3d(A[0],A[1],A[2]) - rnorm(3,A) < 0.0001) && (rnorm4d(A[0],A[1],A[2],A[3]) - rnorm(4, A) < 0.0001 );
bool check_rnorm(double* A) {
return (rnorm3d(A[0], A[1], A[2]) - rnorm(3, A) < 0.0001) &&
(rnorm4d(A[0], A[1], A[2], A[3]) - rnorm(4, A) < 0.0001);
}
bool check_sincospif()
{
bool check_sincospif() {
float s1, c1, s2, c2;
float in1 = 1, in2 = 0.5;
sincospif(in1, &s1, &c1);
sincospif(in2, &s2, &c2);
if( (s1 - 0 < 0.00001) && (s2 - 1 < 0.00001) && (c1 + 1 < 0.00001) && (c2 - 0 < 0.00001)){
if ((s1 - 0 < 0.00001) && (s2 - 1 < 0.00001) && (c1 + 1 < 0.00001) && (c2 - 0 < 0.00001)) {
return true;
}
return false;
}
bool check_sincospi()
{
bool check_sincospi() {
double s1, c1, s2, c2;
double in1 = 1, in2 = 0.5;
sincospi(in1, &s1, &c1);
sincospi(in2, &s2, &c2);
if( (s1 - 0 < 0.00001) && (s2 - 1 < 0.00001) && (c1 + 1 < 0.00001) && (c2 - 0 < 0.00001)){
if ((s1 - 0 < 0.00001) && (s2 - 1 < 0.00001) && (c1 + 1 < 0.00001) && (c2 - 0 < 0.00001)) {
return true;
}
return false;
}
int main(){
float *Af = new float[N];
double *A = new double[N];
for(int i=0;i<N;i++){
int main() {
float* Af = new float[N];
double* A = new double[N];
for (int i = 0; i < N; i++) {
Af[i] = i * 1.0f;
A[i] = i * 1.0;
}
if(check_erfcinvf() && check_erfcxf() && check_erfcinvf() &&
check_erfcinv() && check_erfcx() && check_erfcinv() &&
check_fdividef() && check_fdivide() && check_modff() &&
check_modf() && check_nextafterf() && check_norm3df(Af) &&
check_norm3d(A) && check_norm4df(Af) && check_norm4d(A) &&
check_normcdff() && check_normcdf() && check_normcdfinvf() &&
check_normcdfinv() && check_rcbrtf() && check_rcbrt() &&
check_rhypotf() && check_rhypot() && check_rnorm3df(Af) &&
check_rnorm3d(A) && check_rnorm4df(Af) && check_rnorm4d(A) &&
check_rnormf(Af) && check_rnorm(A) && check_sincospif() &&
check_sincospi()
){
if (check_erfcinvf() && check_erfcxf() && check_erfcinvf() && check_erfcinv() &&
check_erfcx() && check_erfcinv() && check_fdividef() && check_fdivide() && check_modff() &&
check_modf() && check_nextafterf() && check_norm3df(Af) && check_norm3d(A) &&
check_norm4df(Af) && check_norm4d(A) && check_normcdff() && check_normcdf() &&
check_normcdfinvf() && check_normcdfinv() && check_rcbrtf() && check_rcbrt() &&
check_rhypotf() && check_rhypot() && check_rnorm3df(Af) && check_rnorm3d(A) &&
check_rnorm4df(Af) && check_rnorm4d(A) && check_rnormf(Af) && check_rnorm(A) &&
check_sincospif() && check_sincospi()) {
passed();
}
}
@@ -23,34 +23,31 @@ THE SOFTWARE.
* HIT_END
*/
#include<iostream>
#include<hip/hip_runtime_api.h>
#include<hip/hip_runtime.h>
#include"test_common.h"
#include <iostream>
#include <hip/hip_runtime_api.h>
#include <hip/hip_runtime.h>
#include "test_common.h"
#define NUM 1024
#define SIZE NUM*sizeof(float)
#define SIZE NUM * sizeof(float)
__global__ void vAdd(hipLaunchParm lp, float *In1, float *In2, float *In3, float *In4, float *Out)
{
__global__ void vAdd(hipLaunchParm lp, float* In1, float* In2, float* In3, float* In4, float* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
In4[tid] = In1[tid] + In2[tid];
__threadfence();
In3[tid] = In3[tid] + In4[tid];
__threadfence_block();
Out[tid] = In4[tid] + In3[tid];
}
int main(){
float *In1 = new float[1024];
float *In2 = new float[1024];
float *In3 = new float[1024];
float *In4 = new float[1024];
float *Out = new float[1024];
int main() {
float* In1 = new float[1024];
float* In2 = new float[1024];
float* In3 = new float[1024];
float* In4 = new float[1024];
float* Out = new float[1024];
for(uint32_t i=0;i<1024;i++)
{
for (uint32_t i = 0; i < 1024; i++) {
In1[i] = 1.0f;
In2[i] = 1.0f;
In3[i] = 1.0f;
@@ -69,8 +66,8 @@ int main(){
hipMemcpy(In3d, In3, SIZE, hipMemcpyHostToDevice);
hipMemcpy(In4d, In4, SIZE, hipMemcpyHostToDevice);
hipLaunchKernel(vAdd, dim3(32,1,1), dim3(32,1,1), 0, 0, In1d, In2d, In3d, In4d, Outd);
hipLaunchKernel(vAdd, dim3(32, 1, 1), dim3(32, 1, 1), 0, 0, In1d, In2d, In3d, In4d, Outd);
hipMemcpy(Out, Outd, SIZE, hipMemcpyDeviceToHost);
assert(Out[10] == 2*In1[10] + 2*In2[10] + In3[10]);
assert(Out[10] == 2 * In1[10] + 2 * In2[10] + In3[10]);
passed();
}
تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است Diff را بارگزاری کن
تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است Diff را بارگزاری کن
@@ -21,7 +21,7 @@ THE SOFTWARE.
*/
/* HIT_START
* BUILD: %t %s ../test_common.cpp NVCC_OPTIONS --Wno-deprecated-declarations
* BUILD: %t %s ../test_common.cpp NVCC_OPTIONS --Wno-deprecated-declarations
* RUN: %t
* HIT_END
*/
@@ -31,75 +31,79 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
#include <hip/device_functions.h>
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
__global__ void
warpvote(hipLaunchParm lp, int* device_any, int* device_all , int Num_Warps_per_Block, int pshift)
{
int tid = threadIdx.x + blockIdx.x * blockDim.x;
device_any[threadIdx.x>>pshift] = __any(tid -77);
device_all[threadIdx.x>>pshift] = __all(tid -77);
__global__ void warpvote(hipLaunchParm lp, int* device_any, int* device_all,
int Num_Warps_per_Block, int pshift) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
device_any[threadIdx.x >> pshift] = __any(tid - 77);
device_all[threadIdx.x >> pshift] = __all(tid - 77);
}
int main(int argc, char *argv[])
{ int warpSize, pshift;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
warpSize = devProp.warpSize;
int main(int argc, char* argv[]) {
int warpSize, pshift;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
warpSize = devProp.warpSize;
int w = warpSize;
pshift = 0;
while (w >>= 1) ++pshift;
int w = warpSize;
pshift = 0;
while (w >>= 1) ++pshift;
printf ("warpSize=%d pshift=%d\n", warpSize, pshift);
printf("warpSize=%d pshift=%d\n", warpSize, pshift);
int anycount =0;
int allcount =0;
int Num_Threads_per_Block = 1024;
int Num_Blocks_per_Grid = 1;
int Num_Warps_per_Block = Num_Threads_per_Block/warpSize;
int Num_Warps_per_Grid = (Num_Threads_per_Block*Num_Blocks_per_Grid)/warpSize;
int anycount = 0;
int allcount = 0;
int Num_Threads_per_Block = 1024;
int Num_Blocks_per_Grid = 1;
int Num_Warps_per_Block = Num_Threads_per_Block / warpSize;
int Num_Warps_per_Grid = (Num_Threads_per_Block * Num_Blocks_per_Grid) / warpSize;
int * host_any = ( int*)malloc(Num_Warps_per_Grid*sizeof(int));
int * host_all = ( int*)malloc(Num_Warps_per_Grid*sizeof(int));
int *device_any;
int *device_all;
HIP_ASSERT(hipMalloc((void**)&device_any,Num_Warps_per_Grid*sizeof( int)));
HIP_ASSERT(hipMalloc((void**)&device_all,Num_Warps_per_Grid*sizeof(int)));
for (int i=0; i<Num_Warps_per_Grid; i++)
{
host_any[i] = 0;
host_all[i] = 0;
}
HIP_ASSERT(hipMemcpy(device_any, host_any,sizeof(int), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(device_all, host_all,sizeof(int), hipMemcpyHostToDevice));
int* host_any = (int*)malloc(Num_Warps_per_Grid * sizeof(int));
int* host_all = (int*)malloc(Num_Warps_per_Grid * sizeof(int));
int* device_any;
int* device_all;
HIP_ASSERT(hipMalloc((void**)&device_any, Num_Warps_per_Grid * sizeof(int)));
HIP_ASSERT(hipMalloc((void**)&device_all, Num_Warps_per_Grid * sizeof(int)));
for (int i = 0; i < Num_Warps_per_Grid; i++) {
host_any[i] = 0;
host_all[i] = 0;
}
HIP_ASSERT(hipMemcpy(device_any, host_any, sizeof(int), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(device_all, host_all, sizeof(int), hipMemcpyHostToDevice));
hipLaunchKernel(warpvote, dim3(Num_Blocks_per_Grid),dim3(Num_Threads_per_Block),0,0, device_any, device_all ,Num_Warps_per_Block,pshift);
hipLaunchKernel(warpvote, dim3(Num_Blocks_per_Grid), dim3(Num_Threads_per_Block), 0, 0,
device_any, device_all, Num_Warps_per_Block, pshift);
HIP_ASSERT(hipMemcpy(host_any, device_any, Num_Warps_per_Grid*sizeof(int), hipMemcpyDeviceToHost));
HIP_ASSERT(hipMemcpy(host_all, device_all, Num_Warps_per_Grid*sizeof(int), hipMemcpyDeviceToHost));
for (int i=0; i<Num_Warps_per_Grid; i++) {
HIP_ASSERT(
hipMemcpy(host_any, device_any, Num_Warps_per_Grid * sizeof(int), hipMemcpyDeviceToHost));
HIP_ASSERT(
hipMemcpy(host_all, device_all, Num_Warps_per_Grid * sizeof(int), hipMemcpyDeviceToHost));
for (int i = 0; i < Num_Warps_per_Grid; i++) {
printf("warp no. %d __any = %d \n", i, host_any[i]);
printf("warp no. %d __all = %d \n", i, host_all[i]);
printf("warp no. %d __any = %d \n",i,host_any[i]);
printf("warp no. %d __all = %d \n",i,host_all[i]);
if (host_all[i]!=1) ++allcount;
#if defined (__HIP_PLATFORM_HCC__) && !defined ( NVCC_COMPAT )
if (host_any[i]!=64) ++anycount;
if (host_all[i] != 1) ++allcount;
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
if (host_any[i] != 64) ++anycount;
#else
if (host_any[i]!=1) ++anycount;
if (host_any[i] != 1) ++anycount;
#endif
}
}
#if defined (__HIP_PLATFORM_HCC__) && !defined ( NVCC_COMPAT )
if (anycount == 1 && allcount ==1) printf("PASSED\n"); else printf("FAILED\n");
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
if (anycount == 1 && allcount == 1)
printf("PASSED\n");
else
printf("FAILED\n");
#else
if (anycount == 0 && allcount ==1) printf("PASSED\n"); else printf("FAILED\n");
if (anycount == 0 && allcount == 1)
printf("PASSED\n");
else
printf("FAILED\n");
#endif
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}
@@ -28,60 +28,68 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
#include <hip/device_functions.h>
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
__global__ void
gpu_ballot(hipLaunchParm lp, unsigned int* device_ballot, int Num_Warps_per_Block,int pshift)
{
int tid = threadIdx.x + blockIdx.x * blockDim.x;
const unsigned int warp_num = threadIdx.x >> pshift;
__global__ void gpu_ballot(hipLaunchParm lp, unsigned int* device_ballot, int Num_Warps_per_Block,
int pshift) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
const unsigned int warp_num = threadIdx.x >> pshift;
#ifdef __HIP_PLATFORM_HCC__
atomicAdd(&device_ballot[warp_num+blockIdx.x*Num_Warps_per_Block],__popcll(__ballot(tid - 245)));
atomicAdd(&device_ballot[warp_num + blockIdx.x * Num_Warps_per_Block],
__popcll(__ballot(tid - 245)));
#else
atomicAdd(&device_ballot[warp_num+blockIdx.x*Num_Warps_per_Block],__popc(__ballot(tid - 245)));
atomicAdd(&device_ballot[warp_num + blockIdx.x * Num_Warps_per_Block],
__popc(__ballot(tid - 245)));
#endif
}
int main(int argc, char *argv[])
{ int warpSize, pshift;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
int main(int argc, char* argv[]) {
int warpSize, pshift;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
warpSize = devProp.warpSize;
warpSize = devProp.warpSize;
int w = warpSize;
pshift = 0;
while (w >>= 1) ++pshift;
int w = warpSize;
pshift = 0;
while (w >>= 1) ++pshift;
unsigned int Num_Threads_per_Block = 512;
unsigned int Num_Blocks_per_Grid = 1;
unsigned int Num_Warps_per_Block = Num_Threads_per_Block/warpSize;
unsigned int Num_Warps_per_Grid = (Num_Threads_per_Block*Num_Blocks_per_Grid)/warpSize;
unsigned int* host_ballot = (unsigned int*)malloc(Num_Warps_per_Grid*sizeof(unsigned int));
unsigned int* device_ballot;
HIP_ASSERT(hipMalloc((void**)&device_ballot, Num_Warps_per_Grid*sizeof(unsigned int)));
int divergent_count =0;
for (int i=0; i<Num_Warps_per_Grid; i++) host_ballot[i] = 0;
unsigned int Num_Threads_per_Block = 512;
unsigned int Num_Blocks_per_Grid = 1;
unsigned int Num_Warps_per_Block = Num_Threads_per_Block / warpSize;
unsigned int Num_Warps_per_Grid = (Num_Threads_per_Block * Num_Blocks_per_Grid) / warpSize;
unsigned int* host_ballot = (unsigned int*)malloc(Num_Warps_per_Grid * sizeof(unsigned int));
unsigned int* device_ballot;
HIP_ASSERT(hipMalloc((void**)&device_ballot, Num_Warps_per_Grid * sizeof(unsigned int)));
int divergent_count = 0;
for (int i = 0; i < Num_Warps_per_Grid; i++) host_ballot[i] = 0;
HIP_ASSERT(hipMemcpy(device_ballot, host_ballot, Num_Warps_per_Grid*sizeof(unsigned int), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(device_ballot, host_ballot, Num_Warps_per_Grid * sizeof(unsigned int),
hipMemcpyHostToDevice));
hipLaunchKernel(gpu_ballot, dim3(Num_Blocks_per_Grid),dim3(Num_Threads_per_Block),0,0, device_ballot,Num_Warps_per_Block,pshift);
hipLaunchKernel(gpu_ballot, dim3(Num_Blocks_per_Grid), dim3(Num_Threads_per_Block), 0, 0,
device_ballot, Num_Warps_per_Block, pshift);
HIP_ASSERT(hipMemcpy(host_ballot, device_ballot, Num_Warps_per_Grid*sizeof(unsigned int), hipMemcpyDeviceToHost));
for (int i=0; i<Num_Warps_per_Grid; i++) {
HIP_ASSERT(hipMemcpy(host_ballot, device_ballot, Num_Warps_per_Grid * sizeof(unsigned int),
hipMemcpyDeviceToHost));
for (int i = 0; i < Num_Warps_per_Grid; i++) {
if ((host_ballot[i] == 0) || (host_ballot[i] / warpSize == warpSize))
std::cout << "Warp " << i << " IS convergent- Predicate true for "
<< host_ballot[i] / warpSize << " threads\n";
if ((host_ballot[i] == 0)||(host_ballot[i]/warpSize == warpSize)) std::cout << "Warp " << i << " IS convergent- Predicate true for " << host_ballot[i]/warpSize << " threads\n";
else {std::cout << " Warp " << i << " IS divergent - Predicate true for " << host_ballot[i]/warpSize<< " threads\n";
divergent_count++;}
}
if (divergent_count==1) printf("PASSED\n"); else printf("FAILED\n");
return EXIT_SUCCESS;
else {
std::cout << " Warp " << i << " IS divergent - Predicate true for "
<< host_ballot[i] / warpSize << " threads\n";
divergent_count++;
}
}
if (divergent_count == 1)
printf("PASSED\n");
else
printf("FAILED\n");
return EXIT_SUCCESS;
}
@@ -34,150 +34,142 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include <hip/device_functions.h>
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
#define WIDTH 32
#define HEIGHT 32
#define WIDTH 32
#define HEIGHT 32
#define NUM (WIDTH*HEIGHT)
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
#define NUM (WIDTH * HEIGHT)
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
// CPU implementation of bitreverse
template<typename T>
T bitreverse(T num)
{
template <typename T>
T bitreverse(T num) {
T count = sizeof(num) * 8 - 1;
T reverse_num = num;
num >>= 1;
while(num)
{
reverse_num <<= 1;
reverse_num |= num & 1;
num >>= 1;
count--;
while (num) {
reverse_num <<= 1;
reverse_num |= num & 1;
num >>= 1;
count--;
}
reverse_num <<= count;
return reverse_num;
}
__global__ void
HIP_kernel(hipLaunchParm lp,
unsigned int* a, unsigned int* b,unsigned long long int* c, unsigned long long int* d, int width, int height)
{
__global__ void HIP_kernel(hipLaunchParm lp, unsigned int* a, unsigned int* b,
unsigned long long int* c, unsigned long long int* d, int width,
int height) {
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
int i = y * width + x;
if (i < (width * height)) {
a[i] = __brev(b[i]);
c[i] = __brevll(d[i]);
}
}
c[i] = __brevll(d[i]);
}
}
using namespace std;
int main() {
unsigned int* hostA;
unsigned int* hostB;
unsigned long long int* hostC;
unsigned long long int* hostD;
unsigned int* hostA;
unsigned int* hostB;
unsigned long long int* hostC;
unsigned long long int* hostD;
unsigned int* deviceA;
unsigned int* deviceB;
unsigned long long int* deviceC;
unsigned long long int* deviceD;
unsigned int* deviceA;
unsigned int* deviceB;
unsigned long long int* deviceC;
unsigned long long int* deviceD;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
cout << " System minor " << devProp.minor << endl;
cout << " System major " << devProp.major << endl;
cout << " agent prop name " << devProp.name << endl;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
cout << " System minor " << devProp.minor << endl;
cout << " System major " << devProp.major << endl;
cout << " agent prop name " << devProp.name << endl;
cout << "hip Device prop succeeded " << endl ;
cout << "hip Device prop succeeded " << endl;
int i;
int errors;
int i;
int errors;
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostC = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostC = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = i;
hostD[i] = i;
}
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned long long int)));
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(unsigned int), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceD, hostD, NUM*sizeof(unsigned long long int), hipMemcpyHostToDevice));
hipLaunchKernel(HIP_kernel,
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
0, 0,
deviceA ,deviceB, deviceC,deviceD ,WIDTH ,HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM*sizeof(unsigned long long int), hipMemcpyDeviceToHost));
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != bitreverse(hostB[i])) {
errors++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = i;
hostD[i] = i;
}
}
if (errors!=0) {
cout << "__brev() FAILED\n" << endl;
return -1;
} else {
cout << "__brev() checked!" << endl;
}
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostC[i] != bitreverse(hostD[i])) {
errors++;
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned long long int)));
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
HIP_ASSERT(
hipMemcpy(deviceD, hostD, NUM * sizeof(unsigned long long int), hipMemcpyHostToDevice));
hipLaunchKernel(HIP_kernel, dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
deviceD, WIDTH, HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
HIP_ASSERT(
hipMemcpy(hostC, deviceC, NUM * sizeof(unsigned long long int), hipMemcpyDeviceToHost));
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != bitreverse(hostB[i])) {
errors++;
}
}
if (errors != 0) {
cout << "__brev() FAILED\n" << endl;
return -1;
} else {
cout << "__brev() checked!" << endl;
}
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostC[i] != bitreverse(hostD[i])) {
errors++;
}
}
if (errors != 0) {
cout << "__brevll() FAILED" << endl;
return -1;
} else {
cout << "__brevll() checked!" << endl;
}
}
if (errors!=0) {
cout << "__brevll() FAILED" << endl;
return -1;
} else {
cout << "__brevll() checked!" << endl;
}
cout << "__brev() and __brevll() PASSED!" << endl;
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
free(hostA);
free(hostB);
free(hostC);
free(hostD);
free(hostA);
free(hostB);
free(hostC);
free(hostD);
return errors;
return errors;
}
@@ -34,158 +34,151 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include <hip/device_functions.h>
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define WIDTH 8
#define HEIGHT 8
#define NUM (WIDTH*HEIGHT)
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
#define WIDTH 8
#define HEIGHT 8
#define NUM (WIDTH * HEIGHT)
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
unsigned int firstbit_u32(unsigned int a)
{
if (a == 0)
{
#if defined (__HIP_PLATFORM_HCC__) && !defined ( NVCC_COMPAT )
unsigned int firstbit_u32(unsigned int a) {
if (a == 0) {
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
return -1;
return -1;
#else
return 32;
return 32;
#endif
}
unsigned int pos = 0;
while ((int )a > 0) {
a <<= 1; pos++;
}
return pos;
}
unsigned int pos = 0;
while ((int)a > 0) {
a <<= 1;
pos++;
}
return pos;
}
unsigned int firstbit_u64(unsigned long long int a)
{
if (a == 0)
{
#if defined (__HIP_PLATFORM_HCC__) && !defined ( NVCC_COMPAT )
return -1;
unsigned int firstbit_u64(unsigned long long int a) {
if (a == 0) {
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
return -1;
#else
return 64;
return 64;
#endif
}
unsigned int pos = 0;
while ((long long int)a > 0) {
a <<= 1; pos++;
}
return pos;
}
unsigned int pos = 0;
while ((long long int)a > 0) {
a <<= 1;
pos++;
}
return pos;
}
__global__ void
HIP_kernel(hipLaunchParm lp,
unsigned int* a, unsigned int* b,unsigned int* c, unsigned long long int* d, int width, int height)
{
__global__ void HIP_kernel(hipLaunchParm lp, unsigned int* a, unsigned int* b, unsigned int* c,
unsigned long long int* d, int width, int height) {
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
int i = y * width + x;
if (i < (width * height)) {
a[i] = __clz(b[i]);
c[i] = __clzll(d[i]);
}
}
c[i] = __clzll(d[i]);
}
}
using namespace std;
int main() {
unsigned int* hostA;
unsigned int* hostB;
unsigned int* hostC;
unsigned long long int* hostD;
unsigned int* hostA;
unsigned int* hostB;
unsigned int* hostC;
unsigned long long int* hostD;
unsigned int* deviceA;
unsigned int* deviceB;
unsigned int* deviceC;
unsigned long long int* deviceD;
unsigned int* deviceA;
unsigned int* deviceB;
unsigned int* deviceC;
unsigned long long int* deviceD;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
cout << " System minor " << devProp.minor << endl;
cout << " System major " << devProp.major << endl;
cout << " agent prop name " << devProp.name << endl;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
cout << " System minor " << devProp.minor << endl;
cout << " System major " << devProp.major << endl;
cout << " agent prop name " << devProp.name << endl;
cout << "hip Device prop succeeded " << endl;
cout << "hip Device prop succeeded " << endl ;
unsigned int i;
int errors;
unsigned int i;
int errors;
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostC = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostC = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = 419430*i;
hostD[i] = i;
}
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(unsigned int), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceD, hostD, NUM*sizeof(unsigned long long int), hipMemcpyHostToDevice));
hipLaunchKernel(HIP_kernel,
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
0, 0,
deviceA ,deviceB, deviceC ,deviceD , WIDTH ,HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_clz =%d, cpu_clz =%d \n",hostA[i],firstbit_u32(hostB[i]));
if (hostA[i] != firstbit_u32(hostB[i])) {
errors++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = 419430 * i;
hostD[i] = i;
}
}
if (errors!=0) {
cout << "FAILED clz" << endl;
return -1;
} else {
cout << "__clz() checked!" << endl;
}
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_clzll =%d, cpu_clzll =%d \n",hostC[i],firstbit_u64(hostD[i]));
if (hostC[i] != firstbit_u64(hostD[i])) {
errors++;
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
HIP_ASSERT(
hipMemcpy(deviceD, hostD, NUM * sizeof(unsigned long long int), hipMemcpyHostToDevice));
hipLaunchKernel(HIP_kernel, dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
deviceD, WIDTH, HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_clz =%d, cpu_clz =%d \n", hostA[i], firstbit_u32(hostB[i]));
if (hostA[i] != firstbit_u32(hostB[i])) {
errors++;
}
}
if (errors != 0) {
cout << "FAILED clz" << endl;
return -1;
} else {
cout << "__clz() checked!" << endl;
}
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_clzll =%d, cpu_clzll =%d \n", hostC[i], firstbit_u64(hostD[i]));
if (hostC[i] != firstbit_u64(hostD[i])) {
errors++;
}
}
if (errors != 0) {
cout << "FAILED clz" << endl;
return -1;
} else {
cout << "__clzll() checked!" << endl;
}
}
if (errors!=0) {
cout << "FAILED clz" << endl;
return -1;
} else {
cout << "__clzll() checked!" << endl;
}
cout << "clz test PASSED!" << endl;
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
free(hostA);
free(hostB);
free(hostC);
free(hostD);
free(hostA);
free(hostB);
free(hostC);
free(hostD);
return errors;
return errors;
}
@@ -34,153 +34,145 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
#include <hip/device_functions.h>
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
#define WIDTH 8
#define HEIGHT 8
#define WIDTH 8
#define HEIGHT 8
#define NUM (WIDTH*HEIGHT)
#define NUM (WIDTH * HEIGHT)
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
template<typename T>
int lastbit( T a)
{
if (a == 0)
#if defined (__HIP_PLATFORM_HCC__) && !defined ( NVCC_COMPAT )
return -1;
template <typename T>
int lastbit(T a) {
if (a == 0)
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
return -1;
#else
return 0;
return 0;
#endif
int pos = 1;
while ((a&1) != 1) {
a >>= 1; pos++;
}
#if defined (__HIP_PLATFORM_HCC__) && !defined ( NVCC_COMPAT )
return pos-1;
int pos = 1;
while ((a & 1) != 1) {
a >>= 1;
pos++;
}
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
return pos - 1;
#else
return pos;
return pos;
#endif
}
__global__ void
HIP_kernel(hipLaunchParm lp,
unsigned int* a, unsigned int* b, unsigned int* c, unsigned long long int* d,
int width, int height)
{
__global__ void HIP_kernel(hipLaunchParm lp, unsigned int* a, unsigned int* b, unsigned int* c,
unsigned long long int* d, int width, int height) {
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
int i = y * width + x;
if (i < (width * height)) {
a[i] = __ffs(b[i]);
c[i] = __ffsll(d[i]);
}
}
c[i] = __ffsll(d[i]);
}
}
using namespace std;
int main() {
unsigned int* hostA;
unsigned int* hostB;
unsigned int* hostC;
unsigned long long int* hostD;
unsigned int* hostA;
unsigned int* hostB;
unsigned int* hostC;
unsigned long long int* hostD;
unsigned int* deviceA;
unsigned int* deviceB;
unsigned int* deviceC;
unsigned long long int* deviceD;
unsigned int* deviceA;
unsigned int* deviceB;
unsigned int* deviceC;
unsigned long long int* deviceD;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
cout << " System minor " << devProp.minor << endl;
cout << " System major " << devProp.major << endl;
cout << " agent prop name " << devProp.name << endl;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
cout << " System minor " << devProp.minor << endl;
cout << " System major " << devProp.major << endl;
cout << " agent prop name " << devProp.name << endl;
cout << "hip Device prop succeeded " << endl ;
cout << "hip Device prop succeeded " << endl;
int i;
int errors;
int i;
int errors;
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostC = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostC = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = i;
hostD[i] = 1099511627776+i;
}
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(unsigned int), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceD, hostD, NUM*sizeof(unsigned long long int), hipMemcpyHostToDevice));
hipLaunchKernel(HIP_kernel,
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
0, 0,
deviceA ,deviceB, deviceC,deviceD, WIDTH ,HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_ffs =%d, cpu_ffs =%d \n",hostA[i],lastbit(hostB[i]));
if (hostA[i] != lastbit(hostB[i])) {
errors++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = i;
hostD[i] = 1099511627776 + i;
}
}
if (errors!=0) {
cout << "FAILED: ffs" << endl;
return -1;
} else {
cout << "__ffs() for unsigned checked!" << endl;
}
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_ffsll =%d, cpu_ffsll =%d \n",hostC[i],lastbit(hostD[i]));
if (hostC[i] != lastbit(hostD[i])) {
errors++;
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
HIP_ASSERT(
hipMemcpy(deviceD, hostD, NUM * sizeof(unsigned long long int), hipMemcpyHostToDevice));
hipLaunchKernel(HIP_kernel, dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
deviceD, WIDTH, HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_ffs =%d, cpu_ffs =%d \n", hostA[i], lastbit(hostB[i]));
if (hostA[i] != lastbit(hostB[i])) {
errors++;
}
}
if (errors != 0) {
cout << "FAILED: ffs" << endl;
return -1;
} else {
cout << "__ffs() for unsigned checked!" << endl;
}
errors = 0;
for (i = 0; i < NUM; i++) {
printf("gpu_ffsll =%d, cpu_ffsll =%d \n", hostC[i], lastbit(hostD[i]));
if (hostC[i] != lastbit(hostD[i])) {
errors++;
}
}
if (errors != 0) {
cout << "FAILED: ffs" << endl;
return -1;
} else {
cout << "__ffsll() for unsigned checked!" << endl;
}
}
if (errors!=0) {
cout << "FAILED: ffs" << endl;
return -1;
} else {
cout << "__ffsll() for unsigned checked!" << endl;
}
cout << "ffs test PASSED!" << endl;
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
free(hostA);
free(hostB);
free(hostC);
free(hostD);
free(hostA);
free(hostB);
free(hostC);
free(hostD);
return errors;
return errors;
}
@@ -34,141 +34,133 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
#include <hip/device_functions.h>
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
#define WIDTH 16
#define HEIGHT 16
#define WIDTH 16
#define HEIGHT 16
#define NUM (WIDTH*HEIGHT)
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
#define NUM (WIDTH * HEIGHT)
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
// CPU implementation of popcount
template<typename T>
unsigned int popcountCPU( T value) {
unsigned int ret = 0;
while (value) {
if (value & 0x1) ++ret;
value >>=1;
}
return ret;
template <typename T>
unsigned int popcountCPU(T value) {
unsigned int ret = 0;
while (value) {
if (value & 0x1) ++ret;
value >>= 1;
}
return ret;
}
__global__ void
HIP_kernel(hipLaunchParm lp,
unsigned int* a, unsigned int* b,unsigned int* c, unsigned long long int* d, int width, int height)
{
__global__ void HIP_kernel(hipLaunchParm lp, unsigned int* a, unsigned int* b, unsigned int* c,
unsigned long long int* d, int width, int height) {
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
int i = y * width + x;
if (i < (width * height)) {
a[i] = __popc(b[i]);
c[i] = __popcll(d[i]);
}
}
c[i] = __popcll(d[i]);
}
}
using namespace std;
int main() {
unsigned int* hostA;
unsigned int* hostB;
unsigned int* hostC;
unsigned long long int* hostD;
unsigned int* hostA;
unsigned int* hostB;
unsigned int* hostC;
unsigned long long int* hostD;
unsigned int* deviceA;
unsigned int* deviceB;
unsigned int* deviceC;
unsigned long long int* deviceD;
unsigned int* deviceA;
unsigned int* deviceB;
unsigned int* deviceC;
unsigned long long int* deviceD;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
cout << " System minor " << devProp.minor << endl;
cout << " System major " << devProp.major << endl;
cout << " agent prop name " << devProp.name << endl;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
cout << " System minor " << devProp.minor << endl;
cout << " System major " << devProp.major << endl;
cout << " agent prop name " << devProp.name << endl;
cout << "hip Device prop succeeded " << endl ;
cout << "hip Device prop succeeded " << endl;
int i;
int errors;
int i;
int errors;
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostC = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostC = (unsigned int*)malloc(NUM * sizeof(unsigned int));
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = i;
hostD[i] = 1099511627776-i;
}
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(unsigned int), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceD, hostD, NUM*sizeof(unsigned long long int), hipMemcpyHostToDevice));
hipLaunchKernel(HIP_kernel,
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
0, 0,
deviceA ,deviceB, deviceC,deviceD ,WIDTH ,HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM*sizeof(unsigned int), hipMemcpyDeviceToHost));
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != popcountCPU(hostB[i])) {
errors++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = i;
hostD[i] = 1099511627776 - i;
}
}
if (errors!=0) {
cout << "FAILED: popc" << endl;
return -1;
} else {
cout << "__popc() checked!" << endl;
}
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostC[i] != popcountCPU(hostD[i])) {
errors++;
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned int)));
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
HIP_ASSERT(
hipMemcpy(deviceD, hostD, NUM * sizeof(unsigned long long int), hipMemcpyHostToDevice));
hipLaunchKernel(HIP_kernel, dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
deviceD, WIDTH, HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != popcountCPU(hostB[i])) {
errors++;
}
}
if (errors != 0) {
cout << "FAILED: popc" << endl;
return -1;
} else {
cout << "__popc() checked!" << endl;
}
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostC[i] != popcountCPU(hostD[i])) {
errors++;
}
}
if (errors != 0) {
cout << "FAILED:popc" << endl;
return -1;
} else {
cout << "__popcll() checked!" << endl;
}
}
if (errors!=0) {
cout << "FAILED:popc" << endl;
return -1;
} else {
cout << "__popcll() checked!" << endl;
}
cout << "popc test PASSED!" << endl;
cout << "popc test PASSED!" << endl;
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipFree(deviceD));
free(hostA);
free(hostB);
free(hostC);
free(hostD);
free(hostA);
free(hostB);
free(hostC);
free(hostD);
return errors;
return errors;
}
@@ -30,353 +30,282 @@ THE SOFTWARE.
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include<iostream>
#include <iostream>
#include "hip/hip_runtime.h"
#include "hip/hip_vector_types.h"
#include "test_common.h"
#if (__hcc_workweek__ >= 16164) || defined (__HIP_PLATFORM_NVCC__)
#if (__hcc_workweek__ >= 16164) || defined(__HIP_PLATFORM_NVCC__)
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
#define WIDTH 8
#define HEIGHT 8
#define WIDTH 8
#define HEIGHT 8
#define NUM (WIDTH*HEIGHT)
#define NUM (WIDTH * HEIGHT)
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
using namespace std;
template<typename T>
__global__ void
vectoradd_float(hipLaunchParm lp,
T* a, const T* bm, int width, int height)
template <typename T>
__global__ void vectoradd_float(hipLaunchParm lp, T* a, const T* bm, int width, int height)
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
a[i] = __ldg(&bm[i]) ;
}
}
int2 make_vector2(int a){
return make_int2(a,a);
}
char2 make_vector2(signed char a){
return make_char2(a, a);
}
char4 make_vector4(signed char a){
return make_char4(a, a, a ,a);
}
short2 make_vector2(short a){
return make_short2(a,a);
}
ushort2 make_vector2(unsigned short a){
return make_ushort2(a,a);
}
short4 make_vector4(short a){
return make_short4(a,a,a,a);
}
int4 make_vector4(int a){
return make_int4(a,a,a,a);
}
uint2 make_vector2 (unsigned int a){
return make_uint2 (a,a);
}
uint4 make_vector4 (unsigned int a){
return make_uint4 (a,a,a,a);
}
float2 make_vector2 (float a){
return make_float2 (a,a);
}
float4 make_vector4 (float a){
return make_float4 (a,a,a,a);
}
uchar2 make_vector2 (unsigned char a){
return make_uchar2 (a,a);
}
uchar4 make_vector4 (unsigned char a){
return make_uchar4 (a,a,a,a);
}
double2 make_vector2 (double a){
return make_double2 (a,a);
}
template<typename T, typename U>
bool dataTypesRun(){
T* hostA;
T* hostB;
T* deviceA;
T* deviceB;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (U)i;
}
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
hipLaunchKernel(
vectoradd_float,
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
0,
0,
deviceA,
static_cast<const T*>(deviceB),
WIDTH,
HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i])) {
errors++;
int i = y * width + x;
if (i < (width * height)) {
a[i] = __ldg(&bm[i]);
}
}
if (errors!=0) {
std::cout << "FAILED\n"<<std::endl;
ret = false;
} else {
ret = true;
}
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
int2 make_vector2(int a) { return make_int2(a, a); }
free(hostA);
free(hostB);
char2 make_vector2(signed char a) { return make_char2(a, a); }
return ret;
char4 make_vector4(signed char a) { return make_char4(a, a, a, a); }
short2 make_vector2(short a) { return make_short2(a, a); }
ushort2 make_vector2(unsigned short a) { return make_ushort2(a, a); }
short4 make_vector4(short a) { return make_short4(a, a, a, a); }
int4 make_vector4(int a) { return make_int4(a, a, a, a); }
uint2 make_vector2(unsigned int a) { return make_uint2(a, a); }
uint4 make_vector4(unsigned int a) { return make_uint4(a, a, a, a); }
float2 make_vector2(float a) { return make_float2(a, a); }
float4 make_vector4(float a) { return make_float4(a, a, a, a); }
uchar2 make_vector2(unsigned char a) { return make_uchar2(a, a); }
uchar4 make_vector4(unsigned char a) { return make_uchar4(a, a, a, a); }
double2 make_vector2(double a) { return make_double2(a, a); }
template <typename T, typename U>
bool dataTypesRun() {
T* hostA;
T* hostB;
T* deviceA;
T* deviceB;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (U)i;
}
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
hipLaunchKernel(vectoradd_float,
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA,
static_cast<const T*>(deviceB), WIDTH, HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i])) {
errors++;
}
}
if (errors != 0) {
std::cout << "FAILED\n" << std::endl;
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
free(hostA);
free(hostB);
return ret;
}
template<typename T, typename U>
bool dataTypesRun2(){
T* hostA;
T* hostB;
template <typename T, typename U>
bool dataTypesRun2() {
T* hostA;
T* hostB;
T* deviceA;
T* deviceB;
T* deviceA;
T* deviceB;
int i;
int errors;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = make_vector2((U)i);
}
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
hipLaunchKernel(
vectoradd_float,
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
0,
0,
deviceA,
static_cast<const T*>(deviceB),
WIDTH,
HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i].x != (hostB[i].x) && hostA[i].y != (hostB[i].y)) {
errors++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = make_vector2((U)i);
}
}
if (errors!=0) {
std::cout << "FAILED\n"<<std::endl;
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
free(hostA);
free(hostB);
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
hipLaunchKernel(vectoradd_float,
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA,
static_cast<const T*>(deviceB), WIDTH, HEIGHT);
return ret;
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i].x != (hostB[i].x) && hostA[i].y != (hostB[i].y)) {
errors++;
}
}
if (errors != 0) {
std::cout << "FAILED\n" << std::endl;
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
free(hostA);
free(hostB);
return ret;
}
template<typename T, typename U>
bool dataTypesRun4(){
T* hostA;
T* hostB;
template <typename T, typename U>
bool dataTypesRun4() {
T* hostA;
T* hostB;
T* deviceA;
T* deviceB;
T* deviceA;
T* deviceB;
int i;
int errors;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = make_vector4((U)i);
}
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
hipLaunchKernel(
vectoradd_float,
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
0,
0,
deviceA,
static_cast<const T*>(deviceB),
WIDTH,
HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i].x != (hostB[i].x ) && hostA[i].y != (hostB[i].y ) && hostA[i].z != (hostB[i].z ) && hostA[i].w != (hostB[i].w )) {
errors++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = make_vector4((U)i);
}
}
if (errors!=0) {
std::cout << "FAILED\n"<<std::endl;
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
free(hostA);
free(hostB);
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
return ret;
hipLaunchKernel(vectoradd_float,
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA,
static_cast<const T*>(deviceB), WIDTH, HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i].x != (hostB[i].x) && hostA[i].y != (hostB[i].y) &&
hostA[i].z != (hostB[i].z) && hostA[i].w != (hostB[i].w)) {
errors++;
}
}
if (errors != 0) {
std::cout << "FAILED\n" << std::endl;
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
free(hostA);
free(hostB);
return ret;
}
int main() {
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
cout << " System minor " << devProp.minor << endl;
cout << " System major " << devProp.major << endl;
cout << " agent prop name " << devProp.name << endl;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
cout << " System minor " << devProp.minor << endl;
cout << " System major " << devProp.major << endl;
cout << " agent prop name " << devProp.name << endl;
int errors;
errors = dataTypesRun<char,char>() &
dataTypesRun<short, short>() &
dataTypesRun<int,int>() &
dataTypesRun<long, long>() &
dataTypesRun<long long, long long>() &
dataTypesRun<signed char,signed char>() &
dataTypesRun<unsigned char, unsigned char>()&
dataTypesRun<unsigned short, unsigned short>()&
dataTypesRun<unsigned int, unsigned int>()&
dataTypesRun<unsigned long, unsigned long>()&
dataTypesRun<unsigned long long,unsigned long long>()&
dataTypesRun<float, float>()&
dataTypesRun<double, double>();
errors =
dataTypesRun<char, char>() & dataTypesRun<short, short>() & dataTypesRun<int, int>() &
dataTypesRun<long, long>() & dataTypesRun<long long, long long>() &
dataTypesRun<signed char, signed char>() & dataTypesRun<unsigned char, unsigned char>() &
dataTypesRun<unsigned short, unsigned short>() &
dataTypesRun<unsigned int, unsigned int>() & dataTypesRun<unsigned long, unsigned long>() &
dataTypesRun<unsigned long long, unsigned long long>() & dataTypesRun<float, float>() &
dataTypesRun<double, double>();
if(errors == 1){
if (errors == 1) {
errors = 0;
std::cout<<"ldg working for single element data types\n"<<std::endl;
}else{
std::cout<<"Failed single element data types"<<std::endl;
std::cout << "ldg working for single element data types\n" << std::endl;
} else {
std::cout << "Failed single element data types" << std::endl;
return -1;
}
#if 1
errors = dataTypesRun2<int2,int>() &
dataTypesRun2<short2,short>() &
dataTypesRun2<ushort2,unsigned short>() &
dataTypesRun2<char2,signed char>() &
dataTypesRun2<uchar2,unsigned char>() &
dataTypesRun2<uint2,unsigned int>() &
dataTypesRun2<float2,float>() &
dataTypesRun2<double2,double>();
errors = dataTypesRun2<int2, int>() & dataTypesRun2<short2, short>() &
dataTypesRun2<ushort2, unsigned short>() & dataTypesRun2<char2, signed char>() &
dataTypesRun2<uchar2, unsigned char>() & dataTypesRun2<uint2, unsigned int>() &
dataTypesRun2<float2, float>() & dataTypesRun2<double2, double>();
if(errors == 1){
if (errors == 1) {
errors = 0;
std::cout<<"ldg working for two element data types\n"<<std::endl;
}else{
std::cout<<"Failed two element vector data types"<<std::endl;
std::cout << "ldg working for two element data types\n" << std::endl;
} else {
std::cout << "Failed two element vector data types" << std::endl;
return -1;
}
#endif
@@ -384,24 +313,20 @@ int main() {
#if 1
errors = dataTypesRun4<int4,int>() &
dataTypesRun4<char4,signed char>() &
dataTypesRun4<uchar4,unsigned char>() &
dataTypesRun4<short4, short>() &
dataTypesRun4<uint4,unsigned int>() &
dataTypesRun4<float4,float>() ;
errors = dataTypesRun4<int4, int>() & dataTypesRun4<char4, signed char>() &
dataTypesRun4<uchar4, unsigned char>() & dataTypesRun4<short4, short>() &
dataTypesRun4<uint4, unsigned int>() & dataTypesRun4<float4, float>();
if(errors == 1){
if (errors == 1) {
errors = 0;
std::cout<<"ldg working for four element data types\n"<<std::endl;
}else{
std::cout<<"Failed four element vector data types"<<std::endl;
std::cout << "ldg working for four element data types\n" << std::endl;
} else {
std::cout << "Failed four element vector data types" << std::endl;
return -1;
}
#endif
std::cout<<"ldg test PASSED \n"<<std::endl;
std::cout << "ldg test PASSED \n" << std::endl;
}
#endif
@@ -23,76 +23,73 @@ THE SOFTWARE.
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include<iostream>
#include <iostream>
#include "hip/hip_runtime.h"
#include "test_common.h"
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
#define WIDTH 8
#define HEIGHT 8
#define WIDTH 8
#define HEIGHT 8
#define NUM (WIDTH*HEIGHT)
#define NUM (WIDTH * HEIGHT)
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
__global__ void
vectoradd_char1(hipLaunchParm lp,
char1* a, const char1* bm, const char1* cm, int width, int height)
__global__ void vectoradd_char1(hipLaunchParm lp, char1* a, const char1* bm, const char1* cm,
int width, int height)
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
int i = y * width + x;
if (i < (width * height)) {
a[i] = make_char1(bm[i].x) + make_char1(cm[i].x);
}
}
}
}
__global__ void
vectoradd_char2(hipLaunchParm lp,
char2* a, const char2* bm, const char2* cm, int width, int height)
__global__ void vectoradd_char2(hipLaunchParm lp, char2* a, const char2* bm, const char2* cm,
int width, int height)
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
int i = y * width + x;
if (i < (width * height)) {
a[i] = make_char2(bm[i].x, bm[i].y) + make_char2(cm[i].x, cm[i].y);
}
}
}
__global__ void
vectoradd_char3(hipLaunchParm lp,
char3* a, const char3* bm, const char3* cm, int width, int height)
__global__ void vectoradd_char3(hipLaunchParm lp, char3* a, const char3* bm, const char3* cm,
int width, int height)
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
int i = y * width + x;
if (i < (width * height)) {
a[i] = make_char3(bm[i].x, bm[i].y, bm[i].z) + make_char3(cm[i].x, cm[i].y, cm[i].z);
}
}
}
__global__ void
vectoradd_char4(hipLaunchParm lp,
char4* a, const char4* bm, const char4* cm, int width, int height)
__global__ void vectoradd_char4(hipLaunchParm lp, char4* a, const char4* bm, const char4* cm,
int width, int height)
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
{
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if ( i < (width * height)) {
a[i] = make_char4(bm[i].x, bm[i].y, bm[i].z, bm[i].w) + make_char4(cm[i].x, cm[i].y, cm[i].z, cm[i].w);
}
int i = y * width + x;
if (i < (width * height)) {
a[i] = make_char4(bm[i].x, bm[i].y, bm[i].z, bm[i].w) +
make_char4(cm[i].x, cm[i].y, cm[i].z, cm[i].w);
}
}
@@ -112,282 +109,275 @@ __kernel__ void vectoradd_float(float* a, const float* b, const float* c, int wi
using namespace std;
template<typename T>
bool dataTypesRun(){
T* hostA;
T* hostB;
T* hostC;
template <typename T>
bool dataTypesRun() {
T* hostA;
T* hostB;
T* hostC;
T* deviceA;
T* deviceB;
T* deviceC;
T* deviceA;
T* deviceB;
T* deviceC;
int i;
int errors;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostC = (T*)malloc(NUM * sizeof(T));
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostC = (T*)malloc(NUM * sizeof(T));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM*sizeof(T), hipMemcpyHostToDevice));
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
0, 0,
deviceA ,deviceB ,deviceC ,WIDTH ,HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i] + hostC[i])) {
errors++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
free(hostA);
free(hostB);
free(hostC);
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
return ret;
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
WIDTH, HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i] + hostC[i])) {
errors++;
}
}
if (errors != 0) {
printf("FAILED: %d errors\n", errors);
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
free(hostA);
free(hostB);
free(hostC);
return ret;
}
template<typename T>
bool dataTypesRun(){
T* hostA;
T* hostB;
T* hostC;
template <typename T>
bool dataTypesRun() {
T* hostA;
T* hostB;
T* hostC;
T* deviceA;
T* deviceB;
T* deviceC;
T* deviceA;
T* deviceB;
T* deviceC;
int i;
int errors;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostC = (T*)malloc(NUM * sizeof(T));
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostC = (T*)malloc(NUM * sizeof(T));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM*sizeof(T), hipMemcpyHostToDevice));
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
0, 0,
deviceA ,deviceB ,deviceC ,WIDTH ,HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i] + hostC[i])) {
errors++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
free(hostA);
free(hostB);
free(hostC);
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
return ret;
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
WIDTH, HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i] + hostC[i])) {
errors++;
}
}
if (errors != 0) {
printf("FAILED: %d errors\n", errors);
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
free(hostA);
free(hostB);
free(hostC);
return ret;
}
template<typename T>
bool dataTypesRun(){
T* hostA;
T* hostB;
T* hostC;
template <typename T>
bool dataTypesRun() {
T* hostA;
T* hostB;
T* hostC;
T* deviceA;
T* deviceB;
T* deviceC;
T* deviceA;
T* deviceB;
T* deviceC;
int i;
int errors;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostC = (T*)malloc(NUM * sizeof(T));
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostC = (T*)malloc(NUM * sizeof(T));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM*sizeof(T), hipMemcpyHostToDevice));
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
0, 0,
deviceA ,deviceB ,deviceC ,WIDTH ,HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i] + hostC[i])) {
errors++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
free(hostA);
free(hostB);
free(hostC);
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
return ret;
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
WIDTH, HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i] + hostC[i])) {
errors++;
}
}
if (errors != 0) {
printf("FAILED: %d errors\n", errors);
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
free(hostA);
free(hostB);
free(hostC);
return ret;
}
bool dataTypesRunChar4(){
char4* hostA;
char4* hostB;
char4* hostC;
bool dataTypesRunChar4() {
char4* hostA;
char4* hostB;
char4* hostC;
char4* deviceA;
char4* deviceB;
char4* deviceC;
char4* deviceA;
char4* deviceB;
char4* deviceC;
int i;
int errors;
int i;
int errors;
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostC = (T*)malloc(NUM * sizeof(T));
hostA = (T*)malloc(NUM * sizeof(T));
hostB = (T*)malloc(NUM * sizeof(T));
hostC = (T*)malloc(NUM * sizeof(T));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM*sizeof(T), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM*sizeof(T), hipMemcpyHostToDevice));
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
dim3(WIDTH/THREADS_PER_BLOCK_X, HEIGHT/THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y),
0, 0,
deviceA ,deviceB ,deviceC ,WIDTH ,HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM*sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i] + hostC[i])) {
errors++;
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
free(hostA);
free(hostB);
free(hostC);
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
return ret;
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
WIDTH, HEIGHT);
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i] + hostC[i])) {
errors++;
}
}
if (errors != 0) {
printf("FAILED: %d errors\n", errors);
ret = false;
} else {
ret = true;
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
free(hostA);
free(hostB);
free(hostC);
return ret;
}
int main() {
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
cout << " System minor " << devProp.minor << endl;
cout << " System major " << devProp.major << endl;
cout << " agent prop name " << devProp.name << endl;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
cout << " System minor " << devProp.minor << endl;
cout << " System major " << devProp.major << endl;
cout << " agent prop name " << devProp.name << endl;
int errors;
errors = dataTypesRun<char1>() &
dataTypesRun<char2>() &
dataTypesRun<char3>() &
dataTypesRun<char4>();
errors = dataTypesRun<char1>() & dataTypesRun<char2>() & dataTypesRun<char3>() &
dataTypesRun<char4>();
//hipResetDefaultAccelerator();
if(errors == 1){
// hipResetDefaultAccelerator();
if (errors == 1) {
passed();
}else{
std::cout<<"Failed Float"<<std::endl;
} else {
std::cout << "Failed Float" << std::endl;
return -1;
}
}
@@ -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;
}
@@ -26,57 +26,59 @@ THE SOFTWARE.
* HIT_END
*/
#include<hip/hip_runtime_api.h>
#include<hip/hip_runtime.h>
#include<iostream>
#include"test_common.h"
#include<hip/device_functions.h>
#include <hip/hip_runtime_api.h>
#include <hip/hip_runtime.h>
#include <iostream>
#include "test_common.h"
#include <hip/device_functions.h>
#define LEN 512
#define SIZE LEN<<2
#define SIZE LEN << 2
__global__ void kernel_trig(hipLaunchParm lp, float *In, float *sin_d, float *cos_d, float *tan_d, float *sin_pd, float *cos_pd){
int tid = threadIdx.x + blockIdx.x * blockDim.x;
sin_d[tid] = __sinf(In[tid]);
cos_d[tid] = __cosf(In[tid]);
tan_d[tid] = __tanf(In[tid]);
__sincosf(In[tid], &sin_pd[tid], &cos_pd[tid]);
__global__ void kernel_trig(hipLaunchParm lp, float* In, float* sin_d, float* cos_d, float* tan_d,
float* sin_pd, float* cos_pd) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
sin_d[tid] = __sinf(In[tid]);
cos_d[tid] = __cosf(In[tid]);
tan_d[tid] = __tanf(In[tid]);
__sincosf(In[tid], &sin_pd[tid], &cos_pd[tid]);
}
int main(){
float *In, *sin_h, *cos_h, *tan_h, *sin_ph, *cos_ph;
float *In_d, *sin_d, *cos_d, *tan_d, *sin_pd, *cos_pd;
In = new float[LEN];
sin_h = new float[LEN];
cos_h = new float[LEN];
tan_h = new float[LEN];
sin_ph = new float[LEN];
cos_ph = new float[LEN];
for(int i=0;i<LEN;i++){
In[i] = 1.0f;
sin_h[i] = 0.0f;
cos_h[i] = 0.0f;
tan_h[i] = 0.0f;
sin_ph[i] = 0.0f;
cos_ph[i] = 0.0f;
}
hipMalloc((void**)&In_d, SIZE);
hipMalloc((void**)&sin_d, SIZE);
hipMalloc((void**)&cos_d, SIZE);
hipMalloc((void**)&tan_d, SIZE);
hipMalloc((void**)&sin_pd, SIZE);
hipMalloc((void**)&cos_pd, SIZE);
hipMemcpy(In_d, In, SIZE, hipMemcpyHostToDevice);
hipLaunchKernel(kernel_trig, dim3(LEN,1,1), dim3(1,1,1), 0, 0, In_d, sin_d, cos_d, tan_d, sin_pd, cos_pd);
hipMemcpy(sin_h, sin_d, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(cos_h, cos_d, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(tan_h, tan_d, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(sin_ph, sin_pd, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(cos_ph, cos_pd, SIZE, hipMemcpyDeviceToHost);
for(int i=0;i<LEN;i++) {
if(sin_h[i] != sin_ph[i] || cos_h[i] != cos_ph[i] || tan_h[i]*cos_h[i] != sin_h[i]){
std::cout<<"Failed!"<<std::endl;
int main() {
float *In, *sin_h, *cos_h, *tan_h, *sin_ph, *cos_ph;
float *In_d, *sin_d, *cos_d, *tan_d, *sin_pd, *cos_pd;
In = new float[LEN];
sin_h = new float[LEN];
cos_h = new float[LEN];
tan_h = new float[LEN];
sin_ph = new float[LEN];
cos_ph = new float[LEN];
for (int i = 0; i < LEN; i++) {
In[i] = 1.0f;
sin_h[i] = 0.0f;
cos_h[i] = 0.0f;
tan_h[i] = 0.0f;
sin_ph[i] = 0.0f;
cos_ph[i] = 0.0f;
}
}
passed();
hipMalloc((void**)&In_d, SIZE);
hipMalloc((void**)&sin_d, SIZE);
hipMalloc((void**)&cos_d, SIZE);
hipMalloc((void**)&tan_d, SIZE);
hipMalloc((void**)&sin_pd, SIZE);
hipMalloc((void**)&cos_pd, SIZE);
hipMemcpy(In_d, In, SIZE, hipMemcpyHostToDevice);
hipLaunchKernel(kernel_trig, dim3(LEN, 1, 1), dim3(1, 1, 1), 0, 0, In_d, sin_d, cos_d, tan_d,
sin_pd, cos_pd);
hipMemcpy(sin_h, sin_d, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(cos_h, cos_d, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(tan_h, tan_d, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(sin_ph, sin_pd, SIZE, hipMemcpyDeviceToHost);
hipMemcpy(cos_ph, cos_pd, SIZE, hipMemcpyDeviceToHost);
for (int i = 0; i < LEN; i++) {
if (sin_h[i] != sin_ph[i] || cos_h[i] != cos_ph[i] || tan_h[i] * cos_h[i] != sin_h[i]) {
std::cout << "Failed!" << std::endl;
}
}
passed();
}
@@ -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]);
}
@@ -1,8 +1,7 @@
#include<hip/hip_runtime_api.h>
#include<iostream>
#include <hip/hip_runtime_api.h>
#include <iostream>
int main()
{
int *Ad;
hipMalloc((void**)&Ad, 1024);
int main() {
int* Ad;
hipMalloc((void**)&Ad, 1024);
}
+7 -7
مشاهده پرونده
@@ -25,20 +25,20 @@ THE SOFTWARE.
#include "test_common.h"
#include <stdio.h>
#define ITER 1<<20
#define SIZE 1024*1024*sizeof(int)
#define ITER 1 << 20
#define SIZE 1024 * 1024 * sizeof(int)
__global__ void Iter(hipLaunchParm lp, int *Ad){
__global__ void Iter(hipLaunchParm lp, int* Ad) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
if(tx == 0){
for(int i=0;i<ITER;i++){
if (tx == 0) {
for (int i = 0; i < ITER; i++) {
Ad[tx] += 1;
}
}
}
int main(){
int A=0, *Ad;
int main() {
int A = 0, *Ad;
hipMalloc((void**)&Ad, SIZE);
hipMemcpy(Ad, &A, SIZE, hipMemcpyHostToDevice);
hipLaunchKernel(HIP_KERNEL_NAME(Iter), dim3(1), dim3(1), 0, 0, Ad);
+46 -48
مشاهده پرونده
@@ -35,89 +35,87 @@ THE SOFTWARE.
using namespace std;
void usage() {
printf("hipEnvVar [otpions]\n\
printf(
"hipEnvVar [otpions]\n\
-c,\t\ttotal number of available GPUs and their pciBusID\n\
-d,\t\tselect one GPU and return its pciBusID\n\
-v,\t\tsend the list to HIP_VISIBLE_DEVICES env var\n\
-h,\t\tshow this help message\n\
");
}
int main(int argc, char **argv)
{
//string str = getenv("HIP_VISIBLE_DEVICES");
//std::cout << "The current env HIP_VISIBLE_DEVICES is"<<str << std::endl;
extern char *optarg;
int main(int argc, char** argv) {
// string str = getenv("HIP_VISIBLE_DEVICES");
// std::cout << "The current env HIP_VISIBLE_DEVICES is"<<str << std::endl;
extern char* optarg;
extern int optind;
int c = 0;
int retDevCnt=0, retDevInfo=0, setEnvVar=0;
int device=0;
int retDevCnt = 0, retDevInfo = 0, setEnvVar = 0;
int device = 0;
string env;
while ((c = getopt(argc, argv, "cd:v:h")) != -1)
switch (c) {
case 'c':
retDevCnt = true;
break;
case 'd':
retDevInfo = true;
device = atoi(optarg);
break;
case 'v':
setEnvVar = true;
env = optarg;
break;
case 'h':
usage();
return 0;
default :
//usage();
return -1;
while ((c = getopt(argc, argv, "cd:v:h")) != -1) switch (c) {
case 'c':
retDevCnt = true;
break;
case 'd':
retDevInfo = true;
device = atoi(optarg);
break;
case 'v':
setEnvVar = true;
env = optarg;
break;
case 'h':
usage();
return 0;
default:
// usage();
return -1;
}
if (setEnvVar ) {
//env = "export HIP_VISIBLE_DEVICES=" + env;
//cout<<"The received env var is: "<<env<<endl;
setenv("HIP_VISIBLE_DEVICES",env.c_str(),1);
setenv("CUDA_VISIBLE_DEVICES",env.c_str(),1);
cout<<"set env HIP_VISIBLE_DEVICES = "<< env.c_str()<<endl;
//verify if the environment variable is set
if (setEnvVar) {
// env = "export HIP_VISIBLE_DEVICES=" + env;
// cout<<"The received env var is: "<<env<<endl;
setenv("HIP_VISIBLE_DEVICES", env.c_str(), 1);
setenv("CUDA_VISIBLE_DEVICES", env.c_str(), 1);
cout << "set env HIP_VISIBLE_DEVICES = " << env.c_str() << endl;
// verify if the environment variable is set
char* pPath;
pPath = getenv ("HIP_VISIBLE_DEVICES");
if(pPath!=NULL)
pPath = getenv("HIP_VISIBLE_DEVICES");
if (pPath != NULL)
printf("HIP_VISIBLE_DEVICES is %s\n", pPath);
else
printf("HIP_VISIBLE_DEVICES is not set\n");
}
// device init
int devCount=0;
int devCount = 0;
hipGetDeviceCount(&devCount);
//printf("\nTotal number of GPU devices in the system is %d\n",devCount);
// printf("\nTotal number of GPU devices in the system is %d\n",devCount);
if (devCount == 0) {
printf("No HIP enabled device\n");
return -1;
}
if (device < 0 || device > devCount -1) {
if (device < 0 || device > devCount - 1) {
printf("Selected device %d is out of bound. Devices on your system are in range %d - %d\n",
device, 0, devCount -1);
device, 0, devCount - 1);
return -1;
}
if (retDevCnt) {
//std::cout << "Total number of devices visible in system is "<< devCount << std::endl;
std::cout << devCount << std::endl;
// std::cout << "Total number of devices visible in system is "<< devCount << std::endl;
std::cout << devCount << std::endl;
}
if (retDevInfo) {
hipDevice_t deviceT;
hipDeviceGet(&deviceT, device);
hipDevice_t deviceT;
hipDeviceGet(&deviceT, device);
char pciBusId[100];
memset(pciBusId,0,100);
hipDeviceGetPCIBusId(pciBusId,100,deviceT);
memset(pciBusId, 0, 100);
hipDeviceGetPCIBusId(pciBusId, 100, deviceT);
cout<<pciBusId<<endl;
cout << pciBusId << endl;
}
exit(0);
}
@@ -1,19 +1,19 @@
/* Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/* HIT_START
* BUILD: %t %s test_common.cpp NVCC_OPTIONS -std=c++11
@@ -32,99 +32,99 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <thread>
using namespace std;
int getDeviceNumber(){
FILE *in;
int getDeviceNumber() {
FILE* in;
char buff[512];
string str;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
if(!(in = popen("./directed_tests/hipEnvVar -c", "r"))){
return 1;
}
while(fgets(buff, 512, in)!=NULL){
cout << buff;
if (!(in = popen("./directed_tests/hipEnvVar -c", "r"))) {
return 1;
}
while (fgets(buff, 512, in) != NULL) {
cout << buff;
}
pclose(in);
return atoi(buff);
}
// Query the current device ID remotely to hipEnvVar
void getDevicePCIBusNumRemote(int deviceID, char* pciBusID){
FILE *in;
void getDevicePCIBusNumRemote(int deviceID, char* pciBusID) {
FILE* in;
string str = "./directed_tests/hipEnvVar -d ";
str += std::to_string(deviceID);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
if(!(in = popen(str.c_str(), "r"))){
if (!(in = popen(str.c_str(), "r"))) {
exit(1);
}
while(fgets(pciBusID, 100, in)!=NULL){
while (fgets(pciBusID, 100, in) != NULL) {
cout << pciBusID;
}
pclose(in);
}
// Query the current device ID locally on AMD path
void getDevicePCIBusNum(int deviceID, char* pciBusID){
void getDevicePCIBusNum(int deviceID, char* pciBusID) {
hipDevice_t deviceT;
hipDeviceGet(&deviceT, deviceID);
memset(pciBusID,0,100);
hipDeviceGetPCIBusId(pciBusID,100,deviceT);
memset(pciBusID, 0, 100);
hipDeviceGetPCIBusId(pciBusID, 100, deviceT);
}
int main() {
unsetenv("HIP_VISIBLE_DEVICES");
unsetenv("CUDA_VISIBLE_DEVICES");
std::vector<std::string> devPCINum;
char pciBusID[100];
//collect the device pci bus ID for all devices
char pciBusID[100];
// collect the device pci bus ID for all devices
int totalDeviceNum = getDeviceNumber();
std::cout << "The total number of available devices is " << totalDeviceNum<< std::endl
<<"Valid index range is 0 - "<<totalDeviceNum-1<<std::endl;
for (int i = 0; i < totalDeviceNum ; i++) {
std::cout << "The total number of available devices is " << totalDeviceNum << std::endl
<< "Valid index range is 0 - " << totalDeviceNum - 1 << std::endl;
for (int i = 0; i < totalDeviceNum; i++) {
getDevicePCIBusNum(i, pciBusID);
devPCINum.push_back(pciBusID);
std::cout <<"The collected device PCI Bus ID of Device "<<i<<" is "
<< devPCINum.back() << std::endl;
std::cout << "The collected device PCI Bus ID of Device " << i << " is " << devPCINum.back()
<< std::endl;
}
//select each of the available devices to be the target device,
//query the returned device pci bus number, check if match the database
for (int i = 0; i < totalDeviceNum ; i++) {
setenv("HIP_VISIBLE_DEVICES",(char*)std::to_string(i).c_str(),1);
setenv("CUDA_VISIBLE_DEVICES",(char*)std::to_string(i).c_str(),1);
getDevicePCIBusNumRemote(0, pciBusID);
// select each of the available devices to be the target device,
// query the returned device pci bus number, check if match the database
for (int i = 0; i < totalDeviceNum; i++) {
setenv("HIP_VISIBLE_DEVICES", (char*)std::to_string(i).c_str(), 1);
setenv("CUDA_VISIBLE_DEVICES", (char*)std::to_string(i).c_str(), 1);
getDevicePCIBusNumRemote(0, pciBusID);
if (devPCINum[i] == pciBusID) {
std::cout << "The returned PciBusID is not correct"<< std::endl;
std::cout << "Expected "<< devPCINum[i] << ", but get " << pciBusID << endl;
std::cout << "The returned PciBusID is not correct" << std::endl;
std::cout << "Expected " << devPCINum[i] << ", but get " << pciBusID << endl;
exit(-1);
} else {
continue;
}
}
//check when set an invalid device number
setenv("HIP_VISIBLE_DEVICES","1000,0,1",1);
setenv("CUDA_VISIBLE_DEVICES","1000,0,1",1);
// check when set an invalid device number
setenv("HIP_VISIBLE_DEVICES", "1000,0,1", 1);
setenv("CUDA_VISIBLE_DEVICES", "1000,0,1", 1);
assert(getDeviceNumber() == 0);
if(totalDeviceNum > 2){
setenv("HIP_VISIBLE_DEVICES","0,1,1000,2",1);
setenv("CUDA_VISIBLE_DEVICES","0,1,1000,2",1);
if (totalDeviceNum > 2) {
setenv("HIP_VISIBLE_DEVICES", "0,1,1000,2", 1);
setenv("CUDA_VISIBLE_DEVICES", "0,1,1000,2", 1);
assert(getDeviceNumber() == 2);
setenv("HIP_VISIBLE_DEVICES","0,1,2",1);
setenv("CUDA_VISIBLE_DEVICES","0,1,2",1);
setenv("HIP_VISIBLE_DEVICES", "0,1,2", 1);
setenv("CUDA_VISIBLE_DEVICES", "0,1,2", 1);
assert(getDeviceNumber() == 3);
// test if CUDA_VISIBLE_DEVICES will be accepted by the runtime
unsetenv("HIP_VISIBLE_DEVICES");
unsetenv("CUDA_VISIBLE_DEVICES");
setenv("CUDA_VISIBLE_DEVICES","0,1,2",1);
setenv("CUDA_VISIBLE_DEVICES", "0,1,2", 1);
assert(getDeviceNumber() == 3);
}
setenv("HIP_VISIBLE_DEVICES","-100,0,1",1);
setenv("CUDA_VISIBLE_DEVICES","-100,0,1",1);
setenv("HIP_VISIBLE_DEVICES", "-100,0,1", 1);
setenv("CUDA_VISIBLE_DEVICES", "-100,0,1", 1);
assert(getDeviceNumber() == 0);
std::cout << "PASSED" << std::endl;
+10 -11
مشاهده پرونده
@@ -33,31 +33,30 @@ THE SOFTWARE.
#include "hip/hip_hcc.h"
#include "test_common.h"
#define CHECK(error) \
if (error != hipSuccess) { \
fprintf(stderr, "error: '%s'(%d) at %s:%d\n", hipGetErrorString(error), error,__FILE__, __LINE__); \
exit(EXIT_FAILURE);\
#define CHECK(error) \
if (error != hipSuccess) { \
fprintf(stderr, "error: '%s'(%d) at %s:%d\n", hipGetErrorString(error), error, __FILE__, \
__LINE__); \
exit(EXIT_FAILURE); \
}
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
int deviceId;
CHECK (hipGetDevice(&deviceId));
CHECK(hipGetDevice(&deviceId));
hipDeviceProp_t props;
CHECK(hipGetDeviceProperties(&props, deviceId));
printf ("info: running on device #%d %s\n", deviceId, props.name);
printf("info: running on device #%d %s\n", deviceId, props.name);
#ifdef __HCC__
hc::accelerator acc;
CHECK(hipHccGetAccelerator(deviceId, &acc));
std::wcout << "device_path=" << acc.get_device_path() << "\n";
hc::accelerator_view *av;
CHECK(hipHccGetAcceleratorView(0/*nullStream*/, &av));
hc::accelerator_view* av;
CHECK(hipHccGetAcceleratorView(0 /*nullStream*/, &av));
#endif
passed();
};
@@ -39,38 +39,33 @@ size_t Nbytes = 0;
// Utility Functions:
//=================================================================================================
bool operator==(const hipPointerAttribute_t &lhs, const hipPointerAttribute_t &rhs)
{
return ((lhs.hostPointer == rhs.hostPointer) &&
(lhs.devicePointer == rhs.devicePointer) &&
(lhs.memoryType == rhs.memoryType) &&
(lhs.device == rhs.device) &&
(lhs.allocationFlags == rhs.allocationFlags)
) ;
bool operator==(const hipPointerAttribute_t& lhs, const hipPointerAttribute_t& rhs) {
return ((lhs.hostPointer == rhs.hostPointer) && (lhs.devicePointer == rhs.devicePointer) &&
(lhs.memoryType == rhs.memoryType) && (lhs.device == rhs.device) &&
(lhs.allocationFlags == rhs.allocationFlags));
};
bool operator!=(const hipPointerAttribute_t &lhs, const hipPointerAttribute_t &rhs)
{
return ! (lhs == rhs);
bool operator!=(const hipPointerAttribute_t& lhs, const hipPointerAttribute_t& rhs) {
return !(lhs == rhs);
}
const char *memoryTypeToString(hipMemoryType memoryType)
{
const char* memoryTypeToString(hipMemoryType memoryType) {
switch (memoryType) {
case hipMemoryTypeHost : return "[Host]";
case hipMemoryTypeDevice : return "[Device]";
default: return "[Unknown]";
case hipMemoryTypeHost:
return "[Host]";
case hipMemoryTypeDevice:
return "[Device]";
default:
return "[Unknown]";
};
}
void resetAttribs(hipPointerAttribute_t *attribs)
{
attribs->hostPointer = (void*) (-1);
attribs->devicePointer = (void*) (-1);
void resetAttribs(hipPointerAttribute_t* attribs) {
attribs->hostPointer = (void*)(-1);
attribs->devicePointer = (void*)(-1);
attribs->memoryType = hipMemoryTypeHost;
attribs->device = -2;
attribs->isManaged = -1;
@@ -78,49 +73,42 @@ void resetAttribs(hipPointerAttribute_t *attribs)
};
void printAttribs(const hipPointerAttribute_t *attribs)
{
printf ("hostPointer:%p devicePointer:%p memoryType:%s deviceId:%d isManaged:%d allocationFlags:%u\n",
attribs->hostPointer,
attribs->devicePointer,
memoryTypeToString(attribs->memoryType),
attribs->device,
attribs->isManaged,
attribs->allocationFlags
);
void printAttribs(const hipPointerAttribute_t* attribs) {
printf(
"hostPointer:%p devicePointer:%p memoryType:%s deviceId:%d isManaged:%d "
"allocationFlags:%u\n",
attribs->hostPointer, attribs->devicePointer, memoryTypeToString(attribs->memoryType),
attribs->device, attribs->isManaged, attribs->allocationFlags);
};
inline int zrand(int max)
{
return rand() % max;
}
inline int zrand(int max) { return rand() % max; }
//=================================================================================================
// Functions to run tests
//=================================================================================================
//--
//Run through a couple simple cases to test lookups and host pointer arithmetic:
void testSimple()
{
printf ("\n");
printf ("===========================================================================\n");
printf ("Simple Tests\n");
printf ("===========================================================================\n");
// Run through a couple simple cases to test lookups and host pointer arithmetic:
void testSimple() {
printf("\n");
printf("===========================================================================\n");
printf("Simple Tests\n");
printf("===========================================================================\n");
char *A_d;
char *A_Pinned_h;
char *A_OSAlloc_h;
char* A_d;
char* A_Pinned_h;
char* A_OSAlloc_h;
hipError_t e;
HIPCHECK ( hipMalloc(&A_d, Nbytes) );
HIPCHECK ( hipHostMalloc((void**)&A_Pinned_h, Nbytes, hipHostMallocDefault) );
HIPCHECK(hipMalloc(&A_d, Nbytes));
HIPCHECK(hipHostMalloc((void**)&A_Pinned_h, Nbytes, hipHostMallocDefault));
A_OSAlloc_h = (char*)malloc(Nbytes);
size_t free, total;
HIPCHECK(hipMemGetInfo(&free, &total));
printf ("hipMemGetInfo: free=%zu (%4.2f) Nbytes=%lu total=%zu (%4.2f)\n", free, (float)(free/1024.0/1024.0), Nbytes, total, (float)(total/1024.0/1024.0));
printf("hipMemGetInfo: free=%zu (%4.2f) Nbytes=%lu total=%zu (%4.2f)\n", free,
(float)(free / 1024.0 / 1024.0), Nbytes, total, (float)(total / 1024.0 / 1024.0));
HIPASSERT(free + Nbytes <= total);
@@ -128,102 +116,109 @@ void testSimple()
hipPointerAttribute_t attribs2;
// Device memory
printf ("\nDevice memory (hipMalloc)\n");
HIPCHECK( hipPointerGetAttributes(&attribs, A_d));
printf("getAttr:%-20s", "A_d"); printAttribs(&attribs);
printf("\nDevice memory (hipMalloc)\n");
HIPCHECK(hipPointerGetAttributes(&attribs, A_d));
printf("getAttr:%-20s", "A_d");
printAttribs(&attribs);
// Check pointer arithmetic cases:
resetAttribs(&attribs2);
HIPCHECK( hipPointerGetAttributes(&attribs2, A_d+100));
printf("getAttr:%-20s", "A_d+100"); printAttribs(&attribs2);
HIPASSERT((char*)attribs.devicePointer+100 == (char*)attribs2.devicePointer);
HIPCHECK(hipPointerGetAttributes(&attribs2, A_d + 100));
printf("getAttr:%-20s", "A_d+100");
printAttribs(&attribs2);
HIPASSERT((char*)attribs.devicePointer + 100 == (char*)attribs2.devicePointer);
// Corner case at end of array:
resetAttribs(&attribs2);
HIPCHECK( hipPointerGetAttributes(&attribs2, A_d+Nbytes-1));
printf("getAttr:%-20s", "A_d+Nbytes-1"); printAttribs(&attribs2);
HIPASSERT((char*)attribs.devicePointer+Nbytes-1 == (char*)attribs2.devicePointer);
HIPCHECK(hipPointerGetAttributes(&attribs2, A_d + Nbytes - 1));
printf("getAttr:%-20s", "A_d+Nbytes-1");
printAttribs(&attribs2);
HIPASSERT((char*)attribs.devicePointer + Nbytes - 1 == (char*)attribs2.devicePointer);
// Pointer just beyond array - must be invalid or at least a different pointer
resetAttribs(&attribs2);
e = hipPointerGetAttributes(&attribs2, A_d+Nbytes+1);
e = hipPointerGetAttributes(&attribs2, A_d + Nbytes + 1);
printf("getAttr:%-20s err=%d (%s), neg-test expected\n", "A_d+NBytes", e, hipGetErrorString(e));
if (e != hipErrorInvalidValue) {
// We might have strayed into another pointer area.
printf("getAttr:%-20s", "A_d+NBytes"); printAttribs(&attribs2);
printf("getAttr:%-20s", "A_d+NBytes");
printAttribs(&attribs2);
HIPASSERT((char*)attribs.devicePointer != (char*)attribs2.devicePointer);
}
resetAttribs(&attribs2);
e = hipPointerGetAttributes(&attribs2, A_d+Nbytes);
e = hipPointerGetAttributes(&attribs2, A_d + Nbytes);
if (e != hipErrorInvalidValue) {
printf("%-20s", "A_d+Nbytes"); printAttribs(&attribs2);
printf("%-20s", "A_d+Nbytes");
printAttribs(&attribs2);
HIPASSERT(attribs.devicePointer != attribs2.devicePointer);
}
hipFree(A_d);
e = hipPointerGetAttributes(&attribs, A_d);
HIPASSERT(e == hipErrorUnknown); // Just freed the pointer, this should return an error.
HIPASSERT(e == hipErrorUnknown); // Just freed the pointer, this should return an error.
// Device-visible host memory
printf ("\nDevice-visible host memory (hipHostMalloc)\n");
HIPCHECK( hipPointerGetAttributes(&attribs, A_Pinned_h));
printf("getAttr:%-20s", "A_pinned_h"); printAttribs(&attribs);
printf("\nDevice-visible host memory (hipHostMalloc)\n");
HIPCHECK(hipPointerGetAttributes(&attribs, A_Pinned_h));
printf("getAttr:%-20s", "A_pinned_h");
printAttribs(&attribs);
resetAttribs(&attribs2);
HIPCHECK( hipPointerGetAttributes(&attribs2, A_Pinned_h+Nbytes/2));
printf("getAttr:%-20s", "A_pinned_h+NBytes/2"); printAttribs(&attribs2);
HIPASSERT((char*)attribs.hostPointer+Nbytes/2 == (char*)attribs2.hostPointer);
HIPCHECK(hipPointerGetAttributes(&attribs2, A_Pinned_h + Nbytes / 2));
printf("getAttr:%-20s", "A_pinned_h+NBytes/2");
printAttribs(&attribs2);
HIPASSERT((char*)attribs.hostPointer + Nbytes / 2 == (char*)attribs2.hostPointer);
hipHostFree(A_Pinned_h);
e = hipPointerGetAttributes(&attribs, A_Pinned_h);
HIPASSERT(e == hipErrorUnknown); // Just freed the pointer, this should return an error.
HIPASSERT(e == hipErrorUnknown); // Just freed the pointer, this should return an error.
printf("getAttr:%-20s err=%d (%s), neg-test expected\n", "A_d+NBytes", e, hipGetErrorString(e));
// OS memory
printf ("\nOS-allocated memory (malloc)\n");
printf("\nOS-allocated memory (malloc)\n");
e = hipPointerGetAttributes(&attribs, A_OSAlloc_h);
printf("getAttr:%-20s err=%d (%s), neg-test expected\n", "A_OSAlloc_h", e, hipGetErrorString(e));
HIPASSERT(e == hipErrorUnknown); // OS-allocated pointers should return hipErrorUnknown.
printf("getAttr:%-20s err=%d (%s), neg-test expected\n", "A_OSAlloc_h", e,
hipGetErrorString(e));
HIPASSERT(e == hipErrorUnknown); // OS-allocated pointers should return hipErrorUnknown.
}
//---
//Reset the memory tracker (remove allocations from all known devices):
//This frees any memory allocated through the runtime.
//The routine will not release any
void resetTracker ()
{
// Reset the memory tracker (remove allocations from all known devices):
// This frees any memory allocated through the runtime.
// The routine will not release any
void resetTracker() {
if (p_verbose & 0x1) {
printf ("info: reset tracker for all devices in platform\n");
printf("info: reset tracker for all devices in platform\n");
}
int numDevices;
HIPCHECK(hipGetDeviceCount(&numDevices));
// Clean up:
for (int i=0; i<numDevices; i++) {
for (int i = 0; i < numDevices; i++) {
HIPCHECK(hipSetDevice(i));
HIPCHECK(hipDeviceReset());
};
}
// Store the hipPointer attrib and some extra info so can later compare the looked-up info against the reference expectation
// Store the hipPointer attrib and some extra info so can later compare the looked-up info against
// the reference expectation
struct SuperPointerAttribute {
void * _pointer;
size_t _sizeBytes;
hipPointerAttribute_t _attrib;
void* _pointer;
size_t _sizeBytes;
hipPointerAttribute_t _attrib;
};
//---
//Support function to check result against a reference:
void checkPointer(SuperPointerAttribute &ref, int major, int minor, void *pointer)
{
// Support function to check result against a reference:
void checkPointer(SuperPointerAttribute& ref, int major, int minor, void* pointer) {
hipPointerAttribute_t attribs;
resetAttribs(&attribs);
@@ -231,28 +226,30 @@ void checkPointer(SuperPointerAttribute &ref, int major, int minor, void *pointe
if ((e != hipSuccess) || (attribs != ref._attrib)) {
printf("Test %d.%d (err=%d)\n", major, minor, e);
HIPCHECK(e);
printf(" ref :: "); printAttribs(&ref._attrib);
printf(" getattr:: "); printAttribs(&attribs);
printf(" ref :: ");
printAttribs(&ref._attrib);
printf(" getattr:: ");
printAttribs(&attribs);
HIPASSERT(attribs != ref._attrib);
} else {
if (p_verbose & 0x1) {
printf("#%4d.%d GOOD:%p getattr :: ",major, minor, pointer); printAttribs(&attribs);
printf("#%4d.%d GOOD:%p getattr :: ", major, minor, pointer);
printAttribs(&attribs);
}
}
}
//---
//Test that allocates memory across all 4 devices withing the specified size range (minSize...maxSize).
//Then does lookups to make sure the info reported by the tracker matches expecations
//Then deallocates it all.
// Test that allocates memory across all 4 devices withing the specified size range
// (minSize...maxSize). Then does lookups to make sure the info reported by the tracker matches
// expecations Then deallocates it all.
//
//Multiple threads can call this funtion and in fact we do this in the testMultiThreaded_1 test.
void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize)
{
printf (" clusterAllocs numAllocs=%d size=%lu..%lu\n", numAllocs, minSize, maxSize);
std::vector <SuperPointerAttribute> reference(numAllocs);
// Multiple threads can call this funtion and in fact we do this in the testMultiThreaded_1 test.
void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize) {
printf(" clusterAllocs numAllocs=%d size=%lu..%lu\n", numAllocs, minSize, maxSize);
std::vector<SuperPointerAttribute> reference(numAllocs);
HIPASSERT(minSize > 0);
HIPASSERT(maxSize >= minSize);
@@ -261,62 +258,66 @@ void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize)
HIPCHECK(hipGetDeviceCount(&numDevices));
//---
//Populate with device and host allocations.
// Populate with device and host allocations.
size_t totalDeviceAllocated[numDevices];
for (int i =0; i<numDevices; i++) {
for (int i = 0; i < numDevices; i++) {
totalDeviceAllocated[i] = 0;
}
for (int i=0; i<numAllocs; i++) {
for (int i = 0; i < numAllocs; i++) {
bool isDevice = rand() & 0x1;
reference[i]._sizeBytes = zrand(maxSize-minSize) + minSize;
reference[i]._sizeBytes = zrand(maxSize - minSize) + minSize;
reference[i]._attrib.device = zrand(numDevices);
HIPCHECK(hipSetDevice(reference[i]._attrib.device));
reference[i]._attrib.isManaged = 0;
void * ptr;
void* ptr;
if (isDevice) {
totalDeviceAllocated[reference[i]._attrib.device] += reference[i]._sizeBytes;
HIPCHECK(hipMalloc((void**)&ptr, reference[i]._sizeBytes));
reference[i]._attrib.memoryType = hipMemoryTypeDevice;
reference[i]._attrib.memoryType = hipMemoryTypeDevice;
reference[i]._attrib.devicePointer = ptr;
reference[i]._attrib.hostPointer = NULL;
reference[i]._attrib.allocationFlags = 0; // TODO-randomize these.
reference[i]._attrib.hostPointer = NULL;
reference[i]._attrib.allocationFlags = 0; // TODO-randomize these.
} else {
HIPCHECK(hipHostMalloc((void**)&ptr, reference[i]._sizeBytes, hipHostMallocDefault));
reference[i]._attrib.memoryType = hipMemoryTypeHost;
reference[i]._attrib.memoryType = hipMemoryTypeHost;
reference[i]._attrib.devicePointer = ptr;
reference[i]._attrib.hostPointer = ptr;
reference[i]._attrib.allocationFlags = 0; // TODO-randomize these.
reference[i]._attrib.hostPointer = ptr;
reference[i]._attrib.allocationFlags = 0; // TODO-randomize these.
}
reference[i]._pointer = ptr;
}
#ifdef __HIP_PLATFORM_HCC__
if (p_verbose & 0x2) {
printf ("Tracker after insertions:\n");
printf("Tracker after insertions:\n");
hc::am_memtracker_print();
}
#endif
for (int i =0; i<numDevices; i++) {
for (int i = 0; i < numDevices; i++) {
size_t free, total;
HIPCHECK(hipSetDevice(i));
HIPCHECK(hipMemGetInfo(&free, &total));
printf (" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) totalDevice=%lu (%4.2fMB) total=%zu (%4.2fMB)\n",
i, free, (float)(free/1024.0/1024.0), totalDeviceAllocated[i], (float)(totalDeviceAllocated[i])/1024.0/1024.0, total, (float)(total/1024.0/1024.0));
printf(
" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) totalDevice=%lu (%4.2fMB) total=%zu "
"(%4.2fMB)\n",
i, free, (float)(free / 1024.0 / 1024.0), totalDeviceAllocated[i],
(float)(totalDeviceAllocated[i]) / 1024.0 / 1024.0, total,
(float)(total / 1024.0 / 1024.0));
HIPASSERT(free + totalDeviceAllocated[i] <= total);
}
// Now look up each pointer we inserted and verify we can find it:
for (int i=0; i<numAllocs; i++) {
SuperPointerAttribute &ref = reference[i];
for (int i = 0; i < numAllocs; i++) {
SuperPointerAttribute& ref = reference[i];
checkPointer(ref, i, 0, ref._pointer);
checkPointer(ref, i, 1, (char *)ref._pointer + ref._sizeBytes/2);
checkPointer(ref, i, 1, (char*)ref._pointer + ref._sizeBytes / 2);
if (ref._sizeBytes > 1) {
checkPointer(ref, i, 2, (char *)ref._pointer + ref._sizeBytes-1);
checkPointer(ref, i, 2, (char*)ref._pointer + ref._sizeBytes - 1);
}
if (ref._attrib.memoryType == hipMemoryTypeDevice) {
@@ -324,12 +325,11 @@ void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize)
} else {
hipHostFree(ref._pointer);
}
}
#ifdef __HIP_PLATFORM_HCC__
if (p_verbose & 0x2) {
printf ("Tracker after cleanup:\n");
printf("Tracker after cleanup:\n");
hc::am_memtracker_print();
}
#endif
@@ -339,23 +339,23 @@ void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize)
//---
// Multi-threaded test with many simul allocs.
// IN : serialize will force the test to run in serial fashion.
// Seems like this does not hit MT corner cases in the tracker very often - testMultiThreaded_2 below seems more effective.
void testMultiThreaded_1(bool serialize=false)
{
printf ("\n===========================================================================\n");
printf ("MultiThreaded_1\n");
if (serialize) printf ("[SERIALIZE]\n");
printf ("===========================================================================\n");
// Seems like this does not hit MT corner cases in the tracker very often - testMultiThreaded_2
// below seems more effective.
void testMultiThreaded_1(bool serialize = false) {
printf("\n===========================================================================\n");
printf("MultiThreaded_1\n");
if (serialize) printf("[SERIALIZE]\n");
printf("===========================================================================\n");
std::thread t1(clusterAllocs, 1000, 101, 1000);
if (serialize) t1.join();
std::thread t2(clusterAllocs, 1000, 11, 100);
std::thread t2(clusterAllocs, 1000, 11, 100);
if (serialize) t2.join();
std::thread t3(clusterAllocs, 1000, 5, 10);
std::thread t3(clusterAllocs, 1000, 5, 10);
if (serialize) t3.join();
std::thread t4(clusterAllocs, 1000, 1, 4);
std::thread t4(clusterAllocs, 1000, 1, 4);
if (serialize) t4.join();
if (!serialize) {
@@ -372,20 +372,21 @@ void testMultiThreaded_1(bool serialize=false)
///================================================================================================
//---
//Repeatedly query a single entry:
void thread_query(void *ptr, const hipPointerAttribute_t *refAttrib)
{
// Repeatedly query a single entry:
void thread_query(void* ptr, const hipPointerAttribute_t* refAttrib) {
int count = 0;
for (int count=0; count< 1000000; count++) {
for (int count = 0; count < 1000000; count++) {
hipPointerAttribute_t a;
hipError_t e = hipPointerGetAttributes(&a, ptr);
if ((e != hipSuccess) || (a!= *refAttrib)) {
if ((e != hipSuccess) || (a != *refAttrib)) {
printf("Test %d (err=%d)\n", count, e);
HIPCHECK(e);
printf(" ref :: "); printAttribs(refAttrib);
printf(" getattr:: "); printAttribs(&a);
printf(" ref :: ");
printAttribs(refAttrib);
printf(" getattr:: ");
printAttribs(&a);
}
}
}
@@ -394,37 +395,36 @@ void thread_query(void *ptr, const hipPointerAttribute_t *refAttrib)
#ifdef __HIP_PLATFORM_HCC__
//---
// Add pointers to tracker very quickly, then remove them quickly:
enum Dir {Up, Down};
void thread_noise_generator(int iters, size_t numBuffers, Dir addDir, Dir removeDir)
{
enum Dir { Up, Down };
void thread_noise_generator(int iters, size_t numBuffers, Dir addDir, Dir removeDir) {
const size_t bufferSize = 16;
size_t maxSize = numBuffers*bufferSize;
HIPASSERT((maxSize % bufferSize) == 0); // loop logic assumes this is true
size_t maxSize = numBuffers * bufferSize;
HIPASSERT((maxSize % bufferSize) == 0); // loop logic assumes this is true
for (int i=0; i<iters; i++) {
char * basePtr = (char*)malloc(maxSize);
for (int i = 0; i < iters; i++) {
char* basePtr = (char*)malloc(maxSize);
auto acc = hc::accelerator();
if (addDir == Up) {
for (char *p = basePtr; p<basePtr + maxSize; p+=bufferSize) {
for (char* p = basePtr; p < basePtr + maxSize; p += bufferSize) {
hc::AmPointerInfo info(p, p, bufferSize, acc, false, false);
hc::am_memtracker_add(p, info);
}
} else if (addDir == Down) {
for (char *p = basePtr+maxSize-bufferSize; p>=0; p-=bufferSize) {
for (char* p = basePtr + maxSize - bufferSize; p >= 0; p -= bufferSize) {
hc::AmPointerInfo info(p, p, bufferSize, acc, false, false);
hc::am_memtracker_add(p, info);
}
}
if (removeDir == Up) {
for (char *p = basePtr; p<basePtr + maxSize; p+=bufferSize) {
for (char* p = basePtr; p < basePtr + maxSize; p += bufferSize) {
hc::am_memtracker_remove(p);
}
} else if (removeDir == Down) {
for (char *p = basePtr+maxSize-bufferSize; p>=0; p-=bufferSize) {
for (char* p = basePtr + maxSize - bufferSize; p >= 0; p -= bufferSize) {
hc::am_memtracker_remove(p);
}
}
@@ -433,32 +433,31 @@ void thread_noise_generator(int iters, size_t numBuffers, Dir addDir, Dir remove
//---
//Multi-thread test that is effective at catching locking errors in the alloc/dealloc/tracker.
//The query thread repeately requests information on the same block of memory.
//Meanwhile, the thread_noise_generator registers a large number of blocks, and
//then unregisters them. This causes a large amount of rebalancing in the tree
//structure and will generate errors unless the locks in the tracker are preventing reading
//while writing.
void testMultiThreaded_2()
{
// Multi-thread test that is effective at catching locking errors in the alloc/dealloc/tracker.
// The query thread repeately requests information on the same block of memory.
// Meanwhile, the thread_noise_generator registers a large number of blocks, and
// then unregisters them. This causes a large amount of rebalancing in the tree
// structure and will generate errors unless the locks in the tracker are preventing reading
// while writing.
void testMultiThreaded_2() {
std::atomic<int> inflight(2);
printf ("\n===========================================================================\n");
printf ("MultiThreaded_2\n");
printf ("===========================================================================\n");
printf("\n===========================================================================\n");
printf("MultiThreaded_2\n");
printf("===========================================================================\n");
hipSetDevice(0);
hipDeviceReset();
// Create some entries in the tracker:
for (int i=0; i<1000; i++) {
void *C_d;
for (int i = 0; i < 1000; i++) {
void* C_d;
HIPCHECK(hipMalloc(&C_d, 32));
}
// Allocate a pointer that we will repeatedly lookup:
void *A_d;
void* A_d;
HIPCHECK(hipMalloc(&A_d, 10000));
hipPointerAttribute_t attrib1;
HIPCHECK(hipPointerGetAttributes(&attrib1, A_d));
@@ -475,35 +474,33 @@ void testMultiThreaded_2()
#endif
int main(int argc, char *argv[])
{
N= 1000000;
int main(int argc, char* argv[]) {
N = 1000000;
HipTest::parseStandardArguments(argc, argv, true);
Nbytes = N*sizeof(char);
Nbytes = N * sizeof(char);
printf ("N=%zu (%6.2f MB) device=%d\n", N, Nbytes/(1024.0*1024.0), p_gpuDevice);
printf("N=%zu (%6.2f MB) device=%d\n", N, Nbytes / (1024.0 * 1024.0), p_gpuDevice);
if (p_tests & 0x01) {
printf ("info: set device to %d\n", p_gpuDevice);
printf("info: set device to %d\n", p_gpuDevice);
HIPCHECK(hipSetDevice(p_gpuDevice));
testSimple();
}
if (p_tests & 0x02) {
srand(0x100);
printf ("\n===========================================================================\n");
clusterAllocs(100, 1024*1, 1024*1024);
printf("\n===========================================================================\n");
clusterAllocs(100, 1024 * 1, 1024 * 1024);
resetTracker();
}
if (p_tests & 0x04) {
srand(0x200);
printf ("\n===========================================================================\n");
clusterAllocs(1000, 1, 10); // Many tiny allocations;
printf("\n===========================================================================\n");
clusterAllocs(1000, 1, 10); // Many tiny allocations;
resetTracker();
}
@@ -522,6 +519,6 @@ int main(int argc, char *argv[])
}
#endif
printf ("\n");
printf("\n");
passed();
}
@@ -29,15 +29,15 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include "test_common.h"
template<typename T>
__global__ void testExternSharedKernel(hipLaunchParm lp, const T* A_d, const T* B_d, T* C_d, size_t numElements, size_t groupElements) {
template <typename T>
__global__ void testExternSharedKernel(hipLaunchParm lp, const T* A_d, const T* B_d, T* C_d,
size_t numElements, size_t groupElements) {
// declare dynamic shared memory
#if defined(__HIP_PLATFORM_HCC__)
HIP_DYNAMIC_SHARED(T, sdata)
#else
HIP_DYNAMIC_SHARED(__align__(sizeof(T)) unsigned char, my_sdata)
T *sdata = reinterpret_cast<T *>(my_sdata);
T* sdata = reinterpret_cast<T*>(my_sdata);
#endif
size_t gid = (blockIdx.x * blockDim.x + threadIdx.x);
@@ -50,25 +50,52 @@ __global__ void testExternSharedKernel(hipLaunchParm lp, const T* A_d, const T*
// prefix sum inside dynamic shared memory
if (groupElements >= 512) {
if (tid >= 256) { sdata[tid] += sdata[tid - 256]; } __syncthreads();
if (tid >= 256) {
sdata[tid] += sdata[tid - 256];
}
__syncthreads();
}
if (groupElements >= 256) {
if (tid >= 128) { sdata[tid] += sdata[tid - 128]; } __syncthreads();
if (tid >= 128) {
sdata[tid] += sdata[tid - 128];
}
__syncthreads();
}
if (groupElements >= 128) {
if (tid >= 64) { sdata[tid] += sdata[tid - 64]; } __syncthreads();
if (tid >= 64) {
sdata[tid] += sdata[tid - 64];
}
__syncthreads();
}
if (groupElements >= 64) { sdata[tid] += sdata[tid - 32]; } __syncthreads();
if (groupElements >= 32) { sdata[tid] += sdata[tid - 16]; } __syncthreads();
if (groupElements >= 16) { sdata[tid] += sdata[tid - 8]; } __syncthreads();
if (groupElements >= 8) { sdata[tid] += sdata[tid - 4]; } __syncthreads();
if (groupElements >= 4) { sdata[tid] += sdata[tid - 2]; } __syncthreads();
if (groupElements >= 2) { sdata[tid] += sdata[tid - 1]; } __syncthreads();
if (groupElements >= 64) {
sdata[tid] += sdata[tid - 32];
}
__syncthreads();
if (groupElements >= 32) {
sdata[tid] += sdata[tid - 16];
}
__syncthreads();
if (groupElements >= 16) {
sdata[tid] += sdata[tid - 8];
}
__syncthreads();
if (groupElements >= 8) {
sdata[tid] += sdata[tid - 4];
}
__syncthreads();
if (groupElements >= 4) {
sdata[tid] += sdata[tid - 2];
}
__syncthreads();
if (groupElements >= 2) {
sdata[tid] += sdata[tid - 1];
}
__syncthreads();
C_d[gid] = A_d[gid] + B_d[gid] + sdata[tid % groupElements];
}
template<typename T>
template <typename T>
void testExternShared(size_t N, size_t groupElements) {
size_t Nbytes = N * sizeof(T);
@@ -78,7 +105,7 @@ void testExternShared(size_t N, size_t groupElements) {
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
//printf("blocksPerCU: %d\nthreadsPerBlock: %d\nN: %zu\n", blocksPerCU, threadsPerBlock, N);
// printf("blocksPerCU: %d\nthreadsPerBlock: %d\nN: %zu\n", blocksPerCU, threadsPerBlock, N);
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
@@ -87,7 +114,8 @@ void testExternShared(size_t N, size_t groupElements) {
size_t groupMemBytes = groupElements * sizeof(T);
// launch kernel with dynamic shared memory
hipLaunchKernel(HIP_KERNEL_NAME(testExternSharedKernel<T>), dim3(blocks), dim3(threadsPerBlock), groupMemBytes, 0, A_d, B_d, C_d, N, groupElements);
hipLaunchKernel(HIP_KERNEL_NAME(testExternSharedKernel<T>), dim3(blocks), dim3(threadsPerBlock),
groupMemBytes, 0, A_d, B_d, C_d, N, groupElements);
HIPCHECK(hipDeviceSynchronize());
@@ -99,25 +127,25 @@ void testExternShared(size_t N, size_t groupElements) {
T sumFromSharedMemory = static_cast<T>(tid * (tid + 1) / 2);
T expected = A_h[i] + B_h[i] + sumFromSharedMemory;
if (C_h[i] != expected) {
std::cout << std::fixed << std::setprecision(32);
std::cout << "At " << i << std::endl;
std::cout << " Computed:" << C_h[i] << std::endl;
std::cout << " Expected:" << expected << std::endl;
std::cout << sumFromSharedMemory << std::endl;
std::cout << A_h[i] << std::endl;
std::cout << B_h[i] << std::endl;
std::cout << std::fixed << std::setprecision(32);
std::cout << "At " << i << std::endl;
std::cout << " Computed:" << C_h[i] << std::endl;
std::cout << " Expected:" << expected << std::endl;
std::cout << sumFromSharedMemory << std::endl;
std::cout << A_h[i] << std::endl;
std::cout << B_h[i] << std::endl;
failed("Failed at index:%zu\n", i);
failed("Failed at index:%zu\n", i);
}
}
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
}
int main(int argc, char *argv[]) {
int main(int argc, char* argv[]) {
HipTest::parseStandardArguments(argc, argv, true);
//printf("info: set device to %d\n", p_gpuDevice);
// printf("info: set device to %d\n", p_gpuDevice);
HIPCHECK(hipSetDevice(p_gpuDevice));
testExternShared<float>(1024, 4);
@@ -26,37 +26,37 @@ THE SOFTWARE.
* HIT_END
*/
#include "hip/hip_runtime.h"
#include "test_common.h"
#include "hip/hip_runtime.h"
#include "test_common.h"
#define LEN 16*1024
#define SIZE LEN*4
#define LEN 16 * 1024
#define SIZE LEN * 4
__global__ void vectorAdd(hipLaunchParm lp, float *Ad, float *Bd) {
HIP_DYNAMIC_SHARED(float, sBd);
int tx = threadIdx.x;
for(int i=0;i<LEN/64;i++) {
sBd[tx + i * 64] = Ad[tx + i * 64] + 1.0f;
Bd[tx + i * 64] = sBd[tx + i * 64];
}
__global__ void vectorAdd(hipLaunchParm lp, float* Ad, float* Bd) {
HIP_DYNAMIC_SHARED(float, sBd);
int tx = threadIdx.x;
for (int i = 0; i < LEN / 64; i++) {
sBd[tx + i * 64] = Ad[tx + i * 64] + 1.0f;
Bd[tx + i * 64] = sBd[tx + i * 64];
}
}
int main() {
float *A, *B, *Ad, *Bd;
A = new float[LEN];
B = new float[LEN];
for(int i=0;i<LEN;i++) {
A[i] = 1.0f;
B[i] = 1.0f;
}
hipMalloc(&Ad, SIZE);
hipMalloc(&Bd, SIZE);
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
hipLaunchKernel(vectorAdd, dim3(1,1,1), dim3(64,1,1), SIZE, 0, Ad, Bd);
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
for(int i=0;i<LEN;i++) {
assert(B[i] > 1.0f && B[i] < 3.0f);
}
passed();
float *A, *B, *Ad, *Bd;
A = new float[LEN];
B = new float[LEN];
for (int i = 0; i < LEN; i++) {
A[i] = 1.0f;
B[i] = 1.0f;
}
hipMalloc(&Ad, SIZE);
hipMalloc(&Bd, SIZE);
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
hipLaunchKernel(vectorAdd, dim3(1, 1, 1), dim3(64, 1, 1), SIZE, 0, Ad, Bd);
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
for (int i = 0; i < LEN; i++) {
assert(B[i] > 1.0f && B[i] < 3.0f);
}
passed();
}
@@ -23,12 +23,12 @@ THE SOFTWARE.
* HIT_END
*/
#include"test_common.h"
#include "test_common.h"
__global__ void Empty(hipLaunchParm lp, int param){}
__global__ void Empty(hipLaunchParm lp, int param) {}
int main(){
hipLaunchKernel(HIP_KERNEL_NAME(Empty), dim3(1), dim3(1), 0, 0, 0);
hipDeviceSynchronize();
passed();
int main() {
hipLaunchKernel(HIP_KERNEL_NAME(Empty), dim3(1), dim3(1), 0, 0, 0);
hipDeviceSynchronize();
passed();
}
@@ -31,65 +31,51 @@ THE SOFTWARE.
#include "test_common.h"
// __device__ maps to __attribute__((hc))
__device__ int foo(int i)
{
return i+1;
}
__device__ int foo(int i) { return i + 1; }
//---
//Syntax we would like to support with GRID_LAUNCH enabled:
// Syntax we would like to support with GRID_LAUNCH enabled:
template <typename T>
__global__ void
vectorADD2( hipLaunchParm lp,
T *A_d,
T *B_d,
T *C_d,
size_t N)
{
__global__ void vectorADD2(hipLaunchParm lp, T* A_d, T* B_d, T* C_d, size_t N) {
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x ;
size_t stride = blockDim.x * gridDim.x;
for (size_t i=offset; i<N; i+=stride) {
for (size_t i = offset; i < N; i += stride) {
double foo = __hiloint2double(A_d[i], B_d[i]);
C_d[i] = __double2loint(foo) + __double2hiint(foo);//A_d[i] + B_d[i] ;
C_d[i] = __double2loint(foo) + __double2hiint(foo); // A_d[i] + B_d[i] ;
}
}
int test_gl2(size_t N) {
size_t Nbytes = N*sizeof(int);
size_t Nbytes = N * sizeof(int);
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
HipTest::initArrays (&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N);
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
// Full vadd in one large chunk, to get things started:
HIPCHECK ( hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK ( hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
hipLaunchKernel(vectorADD2, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d, C_d, N);
HIPCHECK ( hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK (hipDeviceSynchronize());
HIPCHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, N);
return 0;
}
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
HipTest::parseStandardArguments(argc, argv, true);
test_gl2(N);
@@ -45,50 +45,38 @@ __constant__ int constantVar1;
__constant__ __device__ int constantVar2;
// Test HOST space:
__host__ void foo() {
printf ("foo!\n");
}
__host__ void foo() { printf("foo!\n"); }
__device__ __noinline__ int sum1_noinline(int a) { return a+1;};
__device__ __forceinline__ int sum1_forceinline(int a) { return a+1;};
__device__ __noinline__ int sum1_noinline(int a) { return a + 1; };
__device__ __forceinline__ int sum1_forceinline(int a) { return a + 1; };
__device__ __host__ float PlusOne(float x)
{
return x + 1.0;
}
__device__ __host__ float PlusOne(float x) { return x + 1.0; }
__global__ void MyKernel (const hipLaunchParm lp, const float *a, const float *b, float *c, unsigned N)
{
//KERNELBEGIN;
__global__ void MyKernel(const hipLaunchParm lp, const float* a, const float* b, float* c,
unsigned N) {
// KERNELBEGIN;
unsigned gid = threadIdx.x;
if (gid < N) {
c[gid] = a[gid] + PlusOne(b[gid]);
}
//KERNELEND;
// KERNELEND;
}
void callMyKernel()
{
void callMyKernel() {
float *a, *b, *c;
const unsigned blockSize = 256;
unsigned N = blockSize;
hipLaunchKernel(MyKernel, dim3(N/blockSize), dim3(blockSize), 0, 0, a,b,c,N);
hipLaunchKernel(MyKernel, dim3(N / blockSize), dim3(blockSize), 0, 0, a, b, c, N);
}
template <typename T>
__global__ void
vectorADD(const hipLaunchParm lp,
T __restrict__ *A_d,
T *B_d,
T *C_d,
size_t N)
{
__global__ void vectorADD(const hipLaunchParm lp, T __restrict__* A_d, T* B_d, T* C_d, size_t N) {
// KERNELBEGIN;
#ifdef NOT_YET
int a = __shfl_up(x, 1);
@@ -102,31 +90,31 @@ vectorADD(const hipLaunchParm lp,
#ifdef __HCC__
int b = threadIdx.x;
int c;
int b = threadIdx.x;
int c;
// TODO - move to HIP atomics when ready.
concurrency :: atomic_fetch_add(&c, b);
//Concurrency::atomic_add_unsigned (&x, a);
// TODO - move to HIP atomics when ready.
concurrency ::atomic_fetch_add(&c, b);
// Concurrency::atomic_add_unsigned (&x, a);
//concurrency ::atomic_add_ (x, a);
// concurrency ::atomic_add_ (x, a);
#endif
__syncthreads();
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x ;
size_t stride = blockDim.x * gridDim.x;
for (size_t i=offset; i<N; i+=stride) {
C_d[i] = A_d[i] + B_d[i];
}
for (size_t i = offset; i < N; i += stride) {
C_d[i] = A_d[i] + B_d[i];
}
// KERNELEND;
// KERNELEND;
}
int main() {
printf ("Hello world\n");
printf("Hello world\n");
passed();
}
@@ -24,48 +24,46 @@ THE SOFTWARE.
*/
#include "hip/hip_runtime.h"
#include"test_common.h"
#include "test_common.h"
#include "hip/hip_runtime_api.h"
#include<iostream>
#include <iostream>
__global__ void vAdd(hipLaunchParm lp, float *a){}
__global__ void vAdd(hipLaunchParm lp, float* a) {}
//---
//Some wrapper macro for testing:
// Some wrapper macro for testing:
#define WRAP(...) __VA_ARGS__
#include <sys/time.h>
#define GPU_PRINT_TIME(cmd, elapsed, quiet) do {\
struct timeval start, stop;\
float elapsed;\
gettimeofday(&start, NULL);\
hipDeviceSynchronize();\
cmd;\
hipDeviceSynchronize();\
gettimeofday(&stop, NULL);\
} while(0);
#define GPU_PRINT_TIME(cmd, elapsed, quiet) \
do { \
struct timeval start, stop; \
float elapsed; \
gettimeofday(&start, NULL); \
hipDeviceSynchronize(); \
cmd; \
hipDeviceSynchronize(); \
gettimeofday(&stop, NULL); \
} while (0);
#define MY_LAUNCH(command, doTrace, msg) \
{\
if (doTrace) printf ("TRACE: %s %s\n", msg, #command); \
command;\
}
#define MY_LAUNCH(command, doTrace, msg) \
{ \
if (doTrace) printf("TRACE: %s %s\n", msg, #command); \
command; \
}
#define MY_LAUNCH_WITH_PAREN(command, doTrace, msg) \
{\
if (doTrace) printf ("TRACE: %s %s\n", msg, #command); \
(command);\
}
#define MY_LAUNCH_WITH_PAREN(command, doTrace, msg) \
{ \
if (doTrace) printf("TRACE: %s %s\n", msg, #command); \
(command); \
}
int main()
{
float *Ad;
int main() {
float* Ad;
hipMalloc((void**)&Ad, 1024);
// Test the different hipLaunchParm options:
@@ -76,23 +74,23 @@ int main()
// Test case with hipLaunchKernel inside another macro:
float e0;
GPU_PRINT_TIME (hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad), e0, j);
GPU_PRINT_TIME (WRAP(hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad)), e0, j);
GPU_PRINT_TIME(hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad), e0, j);
GPU_PRINT_TIME(WRAP(hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad)), e0, j);
#ifdef EXTRA_PARENS_1
// Don't wrap hipLaunchKernel in extra set of parens:
GPU_PRINT_TIME ((hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad)), e0, j);
GPU_PRINT_TIME((hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad)), e0, j);
#endif
MY_LAUNCH (hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad), true, "firstCall");
MY_LAUNCH(hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad), true, "firstCall");
float *A;
float* A;
float e1;
MY_LAUNCH_WITH_PAREN (hipMalloc(&A, 100), true, "launch2");
MY_LAUNCH_WITH_PAREN(hipMalloc(&A, 100), true, "launch2");
#ifdef EXTRA_PARENS_2
//MY_LAUNCH_WITH_PAREN wraps cmd in () which can cause issues.
MY_LAUNCH_WITH_PAREN (hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad), true, "firstCall");
// MY_LAUNCH_WITH_PAREN wraps cmd in () which can cause issues.
MY_LAUNCH_WITH_PAREN(hipLaunchKernel(vAdd, dim3(1024), dim3(1), 0, 0, Ad), true, "firstCall");
#endif
passed();
@@ -18,21 +18,19 @@ THE SOFTWARE.
*/
/* HIT_START
* BUILD: %t %s ../test_common.cpp
* BUILD: %t %s ../test_common.cpp
* RUN: %t
* HIT_END
*/
#define HIP_ENABLE_PRINTF
#include"test_common.h"
#include "test_common.h"
__global__ void run_printf(hipLaunchParm lp){
printf("Hello World\n");
}
__global__ void run_printf(hipLaunchParm lp) { printf("Hello World\n"); }
int main(){
hipLaunchKernel(HIP_KERNEL_NAME(run_printf), dim3(1), dim3(1), 0, 0);
hipDeviceSynchronize();
passed();
int main() {
hipLaunchKernel(HIP_KERNEL_NAME(run_printf), dim3(1), dim3(1), 0, 0);
hipDeviceSynchronize();
passed();
}
@@ -23,44 +23,39 @@ THE SOFTWARE.
* HIT_END
*/
#include<hip/hip_runtime.h>
#include<hip/hip_runtime_api.h>
#include<iostream>
#include <hip/hip_runtime.h>
#include <hip/hip_runtime_api.h>
#include <iostream>
#include "test_common.h"
#define HIP_ASSERT(status) \
assert(status == hipSuccess)
#define HIP_ASSERT(status) assert(status == hipSuccess)
#define LEN 512
#define SIZE 2048
__constant__ int Value[LEN];
__global__ void Get(hipLaunchParm lp, int *Ad)
{
__global__ void Get(hipLaunchParm lp, int* Ad) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
Ad[tid] = Value[tid];
}
int main()
{
int main() {
int *A, *B, *Ad;
A = new int[LEN];
B = new int[LEN];
for(unsigned i=0;i<LEN;i++)
{
A[i] = -1*i;
for (unsigned i = 0; i < LEN; i++) {
A[i] = -1 * i;
B[i] = 0;
}
HIP_ASSERT(hipMalloc((void**)&Ad, SIZE));
HIP_ASSERT(hipMemcpyToSymbol(HIP_SYMBOL(Value), A, SIZE, 0, hipMemcpyHostToDevice));
hipLaunchKernel(Get, dim3(1,1,1), dim3(LEN,1,1), 0, 0, Ad);
hipLaunchKernel(Get, dim3(1, 1, 1), dim3(LEN, 1, 1), 0, 0, Ad);
HIP_ASSERT(hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost));
for(unsigned i=0;i<LEN;i++)
{
for (unsigned i = 0; i < LEN; i++) {
assert(A[i] == B[i]);
}
passed();
@@ -23,45 +23,44 @@ THE SOFTWARE.
* HIT_END
*/
#include<hip/hip_runtime.h>
#include<hip/hip_runtime_api.h>
#include<iostream>
#include <hip/hip_runtime.h>
#include <hip/hip_runtime_api.h>
#include <iostream>
#define HIP_ASSERT(status) assert(hipSuccess == status);
#define NUM 1024
#define NUM 1024
#define SIZE NUM * 8
__global__ void Alloc(hipLaunchParm lp, uint64_t *Ptr) {
__global__ void Alloc(hipLaunchParm lp, uint64_t* Ptr) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
Ptr[tid] = (uint64_t)malloc(128);
}
__global__ void Free(hipLaunchParm lp, uint64_t *Ptr) {
__global__ void Free(hipLaunchParm lp, uint64_t* Ptr) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
free((void*)Ptr[tid]);
}
int main()
{
int main() {
uint64_t *hPtr, *dPtr;
hPtr = new uint64_t[NUM];
for(uint32_t i=0;i<NUM;i++) {
for (uint32_t i = 0; i < NUM; i++) {
hPtr[i] = 1;
}
int devCnt;
hipGetDeviceCount(&devCnt);
for(uint32_t i=0;i<devCnt;i++){
for (uint32_t i = 0; i < devCnt; i++) {
HIP_ASSERT(hipSetDevice(i));
HIP_ASSERT(hipMalloc((void**)&dPtr, SIZE));
HIP_ASSERT(hipMemcpy(dPtr, hPtr, SIZE, hipMemcpyHostToDevice));
hipLaunchKernel(Alloc, dim3(1,1,1), dim3(NUM,1,1), 0, 0, dPtr);
hipLaunchKernel(Alloc, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, dPtr);
HIP_ASSERT(hipMemcpy(hPtr, dPtr, SIZE, hipMemcpyDeviceToHost));
assert(hPtr[0] != 0);
hipLaunchKernel(Free, dim3(1,1,1), dim3(NUM,1,1), 0, 0, dPtr);
hipLaunchKernel(Free, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, dPtr);
HIP_ASSERT(hipFree(dPtr));
for(uint32_t i=1;i<NUM;i++) {
assert(hPtr[i] == hPtr[i-1] + 4096);
for (uint32_t i = 1; i < NUM; i++) {
assert(hPtr[i] == hPtr[i - 1] + 4096);
}
}
}
@@ -23,73 +23,73 @@ THE SOFTWARE.
* HIT_END
*/
#include<hip/hip_runtime_api.h>
#include<hip/hip_runtime.h>
#include<iostream>
#include"test_common.h"
#include <hip/hip_runtime_api.h>
#include <hip/hip_runtime.h>
#include <iostream>
#include "test_common.h"
#define LEN8 8 * 4
#define LEN9 9 * 4
#define LEN8 8 * 4
#define LEN9 9 * 4
#define LEN10 10 * 4
#define LEN11 11 * 4
#define LEN12 12 * 4
__global__ void MemCpy8(hipLaunchParm lp, uint8_t *In, uint8_t *Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid*8, In + tid*8, 8);
__global__ void MemCpy8(hipLaunchParm lp, uint8_t* In, uint8_t* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid * 8, In + tid * 8, 8);
}
__global__ void MemCpy9(hipLaunchParm lp, uint8_t *In, uint8_t *Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid*9, In + tid*9, 9);
__global__ void MemCpy9(hipLaunchParm lp, uint8_t* In, uint8_t* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid * 9, In + tid * 9, 9);
}
__global__ void MemCpy10(hipLaunchParm lp, uint8_t *In, uint8_t *Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid*10, In + tid*10, 10);
__global__ void MemCpy10(hipLaunchParm lp, uint8_t* In, uint8_t* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid * 10, In + tid * 10, 10);
}
__global__ void MemCpy11(hipLaunchParm lp, uint8_t *In, uint8_t *Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid*11, In + tid*11, 11);
__global__ void MemCpy11(hipLaunchParm lp, uint8_t* In, uint8_t* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid * 11, In + tid * 11, 11);
}
__global__ void MemCpy12(hipLaunchParm lp, uint8_t *In, uint8_t *Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid*12, In + tid*12, 12);
__global__ void MemCpy12(hipLaunchParm lp, uint8_t* In, uint8_t* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memcpy(Out + tid * 12, In + tid * 12, 12);
}
__global__ void MemSet8(hipLaunchParm lp, uint8_t *In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid*8, 1, 8);
__global__ void MemSet8(hipLaunchParm lp, uint8_t* In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid * 8, 1, 8);
}
__global__ void MemSet9(hipLaunchParm lp, uint8_t *In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid*9, 1, 9);
__global__ void MemSet9(hipLaunchParm lp, uint8_t* In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid * 9, 1, 9);
}
__global__ void MemSet10(hipLaunchParm lp, uint8_t *In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid*10, 1, 10);
__global__ void MemSet10(hipLaunchParm lp, uint8_t* In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid * 10, 1, 10);
}
__global__ void MemSet11(hipLaunchParm lp, uint8_t *In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid*11, 1, 11);
__global__ void MemSet11(hipLaunchParm lp, uint8_t* In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid * 11, 1, 11);
}
__global__ void MemSet12(hipLaunchParm lp, uint8_t *In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid*12, 1, 12);
__global__ void MemSet12(hipLaunchParm lp, uint8_t* In) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
memset(In + tid * 12, 1, 12);
}
int main(){
int main() {
uint8_t *A, *Ad, *B, *Bd, *C, *Cd;
A = new uint8_t[LEN8];
B = new uint8_t[LEN8];
C = new uint8_t[LEN8];
for(uint32_t i=0;i<LEN8;i++) {
for (uint32_t i = 0; i < LEN8; i++) {
A[i] = i;
B[i] = 0;
C[i] = 0;
@@ -98,18 +98,18 @@ int main(){
hipMalloc((void**)&Bd, LEN8);
hipMalloc((void**)&Cd, LEN8);
hipMemcpy(Ad, A, LEN8, hipMemcpyHostToDevice);
hipLaunchKernel(MemCpy8, dim3(2,1,1), dim3(2,1,1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet8, dim3(2,1,1), dim3(2,1,1), 0, 0, Cd);
hipLaunchKernel(MemCpy8, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet8, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Cd);
hipMemcpy(B, Bd, LEN8, hipMemcpyDeviceToHost);
hipMemcpy(C, Cd, LEN8, hipMemcpyDeviceToHost);
for(uint32_t i=0;i<LEN8;i++) {
for (uint32_t i = 0; i < LEN8; i++) {
assert(A[i] == B[i]);
assert(C[i] == 1);
}
delete [] A;
delete [] B;
delete [] C;
delete[] A;
delete[] B;
delete[] C;
hipFree(Ad);
hipFree(Bd);
hipFree(Cd);
@@ -117,7 +117,7 @@ int main(){
A = new uint8_t[LEN9];
B = new uint8_t[LEN9];
C = new uint8_t[LEN9];
for(uint32_t i=0;i<LEN9;i++) {
for (uint32_t i = 0; i < LEN9; i++) {
A[i] = i;
B[i] = 0;
C[i] = 0;
@@ -126,18 +126,18 @@ int main(){
hipMalloc((void**)&Bd, LEN9);
hipMalloc((void**)&Cd, LEN9);
hipMemcpy(Ad, A, LEN9, hipMemcpyHostToDevice);
hipLaunchKernel(MemCpy9, dim3(2,1,1), dim3(2,1,1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet9, dim3(2,1,1), dim3(2,1,1), 0, 0, Cd);
hipLaunchKernel(MemCpy9, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet9, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Cd);
hipMemcpy(B, Bd, LEN9, hipMemcpyDeviceToHost);
hipMemcpy(C, Cd, LEN9, hipMemcpyDeviceToHost);
for(uint32_t i=0;i<LEN9;i++) {
for (uint32_t i = 0; i < LEN9; i++) {
assert(A[i] == B[i]);
assert(C[i] == 1);
}
delete [] A;
delete [] B;
delete [] C;
delete[] A;
delete[] B;
delete[] C;
hipFree(Ad);
hipFree(Bd);
hipFree(Cd);
@@ -145,7 +145,7 @@ int main(){
A = new uint8_t[LEN10];
B = new uint8_t[LEN10];
C = new uint8_t[LEN10];
for(uint32_t i=0;i<LEN10;i++) {
for (uint32_t i = 0; i < LEN10; i++) {
A[i] = i;
B[i] = 0;
C[i] = 0;
@@ -154,18 +154,18 @@ int main(){
hipMalloc((void**)&Bd, LEN10);
hipMalloc((void**)&Cd, LEN10);
hipMemcpy(Ad, A, LEN10, hipMemcpyHostToDevice);
hipLaunchKernel(MemCpy10, dim3(2,1,1), dim3(2,1,1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet10, dim3(2,1,1), dim3(2,1,1), 0, 0, Cd);
hipLaunchKernel(MemCpy10, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet10, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Cd);
hipMemcpy(B, Bd, LEN10, hipMemcpyDeviceToHost);
hipMemcpy(C, Cd, LEN10, hipMemcpyDeviceToHost);
for(uint32_t i=0;i<LEN10;i++) {
for (uint32_t i = 0; i < LEN10; i++) {
assert(A[i] == B[i]);
assert(C[i] == 1);
}
delete [] A;
delete [] B;
delete [] C;
delete[] A;
delete[] B;
delete[] C;
hipFree(Ad);
hipFree(Bd);
hipFree(Cd);
@@ -173,7 +173,7 @@ int main(){
A = new uint8_t[LEN11];
B = new uint8_t[LEN11];
C = new uint8_t[LEN11];
for(uint32_t i=0;i<LEN11;i++) {
for (uint32_t i = 0; i < LEN11; i++) {
A[i] = i;
B[i] = 0;
C[i] = 0;
@@ -182,18 +182,18 @@ int main(){
hipMalloc((void**)&Bd, LEN11);
hipMalloc((void**)&Cd, LEN11);
hipMemcpy(Ad, A, LEN11, hipMemcpyHostToDevice);
hipLaunchKernel(MemCpy11, dim3(2,1,1), dim3(2,1,1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet11, dim3(2,1,1), dim3(2,1,1), 0, 0, Cd);
hipLaunchKernel(MemCpy11, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet11, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Cd);
hipMemcpy(B, Bd, LEN11, hipMemcpyDeviceToHost);
hipMemcpy(C, Cd, LEN11, hipMemcpyDeviceToHost);
for(uint32_t i=0;i<LEN11;i++) {
for (uint32_t i = 0; i < LEN11; i++) {
assert(A[i] == B[i]);
assert(C[i] == 1);
}
delete [] A;
delete [] B;
delete [] C;
delete[] A;
delete[] B;
delete[] C;
hipFree(Ad);
hipFree(Bd);
hipFree(Cd);
@@ -201,7 +201,7 @@ int main(){
A = new uint8_t[LEN12];
B = new uint8_t[LEN12];
C = new uint8_t[LEN12];
for(uint32_t i=0;i<LEN12;i++) {
for (uint32_t i = 0; i < LEN12; i++) {
A[i] = i;
B[i] = 0;
C[i] = 0;
@@ -210,18 +210,18 @@ int main(){
hipMalloc((void**)&Bd, LEN12);
hipMalloc((void**)&Cd, LEN12);
hipMemcpy(Ad, A, LEN12, hipMemcpyHostToDevice);
hipLaunchKernel(MemCpy12, dim3(2,1,1), dim3(2,1,1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet12, dim3(2,1,1), dim3(2,1,1), 0, 0, Cd);
hipLaunchKernel(MemCpy12, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Ad, Bd);
hipLaunchKernel(MemSet12, dim3(2, 1, 1), dim3(2, 1, 1), 0, 0, Cd);
hipMemcpy(B, Bd, LEN12, hipMemcpyDeviceToHost);
hipMemcpy(C, Cd, LEN12, hipMemcpyDeviceToHost);
for(uint32_t i=0;i<LEN12;i++) {
for (uint32_t i = 0; i < LEN12; i++) {
assert(A[i] == B[i]);
assert(C[i] == 1);
}
delete [] A;
delete [] B;
delete [] C;
delete[] A;
delete[] B;
delete[] C;
hipFree(Ad);
hipFree(Bd);
hipFree(Cd);
@@ -1,19 +1,19 @@
/* Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/* HIT_START
* BUILD: %t %s
@@ -22,46 +22,37 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
*/
#include<iostream>
#include <iostream>
// hip header file
#include "hip/hip_runtime.h"
#define NUM 1024
#define NUM 1024
#define THREADS_PER_BLOCK_X 4
#define THREADS_PER_BLOCK_X 4
// Device (Kernel) function, it must be void
// hipLaunchParm provides the execution configuration
__global__ void vadd_asm(hipLaunchParm lp,
float *out,
float *in)
{
__global__ void vadd_asm(hipLaunchParm lp, float* out, float* in) {
int i = blockDim.x * blockIdx.x + threadIdx.x;
#ifdef __HIP_PLATFORM_NVCC__
asm volatile("add.f32 %0,%1,%2;":"=f"(out[i]):"f"(in[i]),"f"(out[i]));
asm volatile("add.f32 %0,%1,%2;" : "=f"(out[i]) : "f"(in[i]), "f"(out[i]));
#endif
#ifdef __HIP_PLATFORM_HCC__
asm volatile ("v_add_f32_e32 %0, %1, %2" : "=v" (out[i]) : "v"(in[i]),"v" (out[i]));
asm volatile("v_add_f32_e32 %0, %1, %2" : "=v"(out[i]) : "v"(in[i]), "v"(out[i]));
#endif
}
// CPU implementation of Vector Result
void addCPUReference(
float * output,
float * input)
{
for(unsigned int j=0; j < NUM; j++)
{
output[j]= input[j] + output[j];
void addCPUReference(float* output, float* input) {
for (unsigned int j = 0; j < NUM; j++) {
output[j] = input[j] + output[j];
}
}
int main(){
int main() {
float* VectorA;
float* ResultVector;
float* VectorB;
@@ -78,8 +69,8 @@ int main(){
// initialize the input data
for (i = 0; i < NUM; i++) {
VectorA[i] = (float)i*10.0f;
VectorB[i] = (float)i*30.0f;
VectorA[i] = (float)i * 10.0f;
VectorB[i] = (float)i * 30.0f;
}
// allocate the memory on the device side
@@ -87,18 +78,15 @@ int main(){
hipMalloc((void**)&gpuResultVector, NUM * sizeof(float));
// Memory transfer from host to device
hipMemcpy(gpuVector, VectorA, NUM*sizeof(float), hipMemcpyHostToDevice);
hipMemcpy(gpuResultVector, VectorB, NUM*sizeof(float), hipMemcpyHostToDevice);
hipMemcpy(gpuVector, VectorA, NUM * sizeof(float), hipMemcpyHostToDevice);
hipMemcpy(gpuResultVector, VectorB, NUM * sizeof(float), hipMemcpyHostToDevice);
// Lauching kernel from host
hipLaunchKernel(vadd_asm,
dim3(NUM/THREADS_PER_BLOCK_X),
dim3(THREADS_PER_BLOCK_X),
0, 0,
gpuResultVector , gpuVector);
hipLaunchKernel(vadd_asm, dim3(NUM / THREADS_PER_BLOCK_X), dim3(THREADS_PER_BLOCK_X), 0, 0,
gpuResultVector, gpuVector);
// Memory transfer from device to host
hipMemcpy(ResultVector, gpuResultVector, NUM*sizeof(float), hipMemcpyDeviceToHost);
hipMemcpy(ResultVector, gpuResultVector, NUM * sizeof(float), hipMemcpyDeviceToHost);
// CPU Result computation
addCPUReference(VectorB, VectorA);
@@ -107,23 +95,23 @@ int main(){
errors = 0;
double eps = 1.0E-3;
for (i = 0; i < NUM; i++) {
if (std::abs(ResultVector[i] - VectorB[i]) > eps ) {
errors++;
if (std::abs(ResultVector[i] - VectorB[i]) > eps) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
if (errors != 0) {
printf("FAILED: %d errors\n", errors);
} else {
printf ("PASSED!\n");
printf("PASSED!\n");
}
//free the resources on device side
// free the resources on device side
hipFree(gpuVector);
hipFree(gpuResultVector);
hipDeviceReset();
//free the resources on host side
// free the resources on host side
free(VectorA);
free(ResultVector);
free(VectorB);
@@ -20,40 +20,31 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include<iostream>
#include <iostream>
// hip header file
#include "hip/hip_runtime.h"
#define NUM 1024
#define NUM 1024
#define THREADS_PER_BLOCK_X 4
#define THREADS_PER_BLOCK_X 4
// Device (Kernel) function, it must be void
// hipLaunchParm provides the execution configuration
__global__ void vmac_asm(hipLaunchParm lp,
float *out,
float *in)
{
__global__ void vmac_asm(hipLaunchParm lp, float* out, float* in) {
int i = blockDim.x * blockIdx.x + threadIdx.x;
asm volatile ("v_mac_f32_e32 %0, %2, %3" : "=v" (out[i]) : "0"(out[i]), "v" (a), "v" (in[i]));
asm volatile("v_mac_f32_e32 %0, %2, %3" : "=v"(out[i]) : "0"(out[i]), "v"(a), "v"(in[i]));
}
// CPU implementation of saxpy
void CPUReference(
float * output,
float * input)
{
for(unsigned int j=0; j < NUM; j++)
{
output[j]= a*input[j] + output[j];
void CPUReference(float* output, float* input) {
for (unsigned int j = 0; j < NUM; j++) {
output[j] = a * input[j] + output[j];
}
}
int main(){
int main() {
float* VectorA;
float* ResultVector;
float* VectorB;
@@ -61,8 +52,7 @@ int main(){
float* gpuVector;
float* gpuResultVector;
const float a = 10.0f
int i;
const float a = 10.0f int i;
int errors;
VectorA = (float*)malloc(NUM * sizeof(float));
@@ -71,8 +61,8 @@ int main(){
// initialize the input data
for (i = 0; i < NUM; i++) {
VectorA[i] = (float)i*10.0f;
VectorB[i] = (float)i*30.0f;
VectorA[i] = (float)i * 10.0f;
VectorB[i] = (float)i * 30.0f;
}
// allocate the memory on the device side
@@ -80,18 +70,15 @@ int main(){
hipMalloc((void**)&gpuResultVector, NUM * sizeof(float));
// Memory transfer from host to device
hipMemcpy(gpuVector, VectorA, NUM*sizeof(float), hipMemcpyHostToDevice);
hipMemcpy(gpuResultVector, VectorB, NUM*sizeof(float), hipMemcpyHostToDevice);
hipMemcpy(gpuVector, VectorA, NUM * sizeof(float), hipMemcpyHostToDevice);
hipMemcpy(gpuResultVector, VectorB, NUM * sizeof(float), hipMemcpyHostToDevice);
// Lauching kernel from host
hipLaunchKernel(vmac_asm,
dim3(NUM/THREADS_PER_BLOCK_X),
dim3(THREADS_PER_BLOCK_X),
0, 0,
gpuResultVector , gpuVector);
hipLaunchKernel(vmac_asm, dim3(NUM / THREADS_PER_BLOCK_X), dim3(THREADS_PER_BLOCK_X), 0, 0,
gpuResultVector, gpuVector);
// Memory transfer from device to host
hipMemcpy(ResultVector, gpuResultVector, NUM*sizeof(float), hipMemcpyDeviceToHost);
hipMemcpy(ResultVector, gpuResultVector, NUM * sizeof(float), hipMemcpyDeviceToHost);
// CPU Result computation
addCPUReference(VectorB, VectorA);
@@ -100,23 +87,23 @@ int main(){
errors = 0;
double eps = 1.0E-3;
for (i = 0; i < NUM; i++) {
if (std::abs(ResultVector[i] - VectorB[i]) > eps ) {
errors++;
if (std::abs(ResultVector[i] - VectorB[i]) > eps) {
errors++;
}
}
if (errors!=0) {
printf("FAILED: %d errors\n",errors);
if (errors != 0) {
printf("FAILED: %d errors\n", errors);
} else {
printf ("PASSED!\n");
printf("PASSED!\n");
}
//free the resources on device side
// free the resources on device side
hipFree(gpuVector);
hipFree(gpuResultVector);
hipDeviceReset();
//free the resources on host side
// free the resources on host side
free(VectorA);
free(ResultVector);
free(VectorB);
@@ -28,11 +28,8 @@ THE SOFTWARE.
int p_blockSize = 256;
__global__
void
__launch_bounds__(256, 2)
myKern(hipLaunchParm lp, int *C, const int *A, int N, int xfactor)
{
__global__ void __launch_bounds__(256, 2)
myKern(hipLaunchParm lp, int* C, const int* A, int N, int xfactor) {
int tid = (blockIdx.x * blockDim.x + threadIdx.x);
if (tid < N) {
@@ -41,16 +38,15 @@ myKern(hipLaunchParm lp, int *C, const int *A, int N, int xfactor)
};
void parseMyArguments(int argc, char *argv[])
{
void parseMyArguments(int argc, char* argv[]) {
int more_argc = HipTest::parseStandardArguments(argc, argv, false);
// parse args for this test:
for (int i = 1; i < more_argc; i++) {
const char *arg = argv[i];
const char* arg = argv[i];
if (!strcmp(arg, "--blockSize")) {
if (++i >= argc || !HipTest::parseInt(argv[i], &p_blockSize)) {
failed("Bad peerDevice argument");
failed("Bad peerDevice argument");
}
} else {
failed("Bad argument '%s'", arg);
@@ -59,63 +55,58 @@ void parseMyArguments(int argc, char *argv[])
};
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
parseMyArguments(argc, argv);
size_t Nbytes = N*sizeof(int);
size_t Nbytes = N * sizeof(int);
int *A_d, *C_d, *A_h, *C_h;
HIPCHECK ( hipMalloc(&A_d, Nbytes) );
HIPCHECK ( hipMalloc(&C_d, Nbytes) );
HIPCHECK(hipMalloc(&A_d, Nbytes));
HIPCHECK(hipMalloc(&C_d, Nbytes));
A_h = (int*)malloc (Nbytes);
C_h = (int*)malloc (Nbytes);
A_h = (int*)malloc(Nbytes);
C_h = (int*)malloc(Nbytes);
for (int i=0; i<N; i++) {
A_h[i] = i*10;
for (int i = 0; i < N; i++) {
A_h[i] = i * 10;
C_h[i] = 0x0;
}
int blocks = N / p_blockSize;
printf ("running with N=%zu p_blockSize=%d blocks=%d\n", N, p_blockSize, blocks);
printf("running with N=%zu p_blockSize=%d blocks=%d\n", N, p_blockSize, blocks);
HIPCHECK ( hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice) );
HIPCHECK ( hipGetLastError() );
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIPCHECK(hipGetLastError());
hipLaunchKernel(myKern, dim3(blocks), dim3(p_blockSize), 0, 0, C_d, A_d, N, 0);
#ifdef __HIP_PLATFORM_NVCC__
cudaFuncAttributes attrib;
cudaFuncGetAttributes (&attrib, myKern);
printf ("binaryVersion = %d\n", attrib.binaryVersion);
printf ("cacheModeCA = %d\n", attrib.cacheModeCA);
printf ("constSizeBytes = %zu\n", attrib.constSizeBytes);
printf ("localSizeBytes = %zud\n", attrib.localSizeBytes);
printf ("maxThreadsPerBlock = %d\n", attrib.maxThreadsPerBlock);
printf ("numRegs = %d\n", attrib.numRegs);
printf ("ptxVersion = %d\n", attrib.ptxVersion);
printf ("sharedSizeBytes = %zud\n", attrib.sharedSizeBytes);
cudaFuncGetAttributes(&attrib, myKern);
printf("binaryVersion = %d\n", attrib.binaryVersion);
printf("cacheModeCA = %d\n", attrib.cacheModeCA);
printf("constSizeBytes = %zu\n", attrib.constSizeBytes);
printf("localSizeBytes = %zud\n", attrib.localSizeBytes);
printf("maxThreadsPerBlock = %d\n", attrib.maxThreadsPerBlock);
printf("numRegs = %d\n", attrib.numRegs);
printf("ptxVersion = %d\n", attrib.ptxVersion);
printf("sharedSizeBytes = %zud\n", attrib.sharedSizeBytes);
#endif
HIPCHECK ( hipDeviceSynchronize() );
HIPCHECK(hipDeviceSynchronize());
HIPCHECK ( hipGetLastError() );
HIPCHECK(hipGetLastError());
HIPCHECK ( hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost) );
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIPCHECK ( hipDeviceSynchronize() );
HIPCHECK(hipDeviceSynchronize());
for (int i=0; i<N; i++) {
for (int i = 0; i < N; i++) {
int goldVal = i * 10;
if (C_h[i] != goldVal) {
failed("mismatch at index:%d computed:%02d, gold:%02d\n", i, (int)C_h[i], (int)goldVal);
}
}
passed();
};
@@ -17,11 +17,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include<hip/hip_runtime_api.h>
#include"test_common.h"
#include <hip/hip_runtime_api.h>
#include "test_common.h"
int main()
{
int main() {
int dev;
hipDeviceProp_t prop;
HIP_PRINT_STATUS(hipChooseDevice(&dev, &prop));
@@ -17,13 +17,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include<hip/hip_runtime_api.h>
#include"test_common.h"
#include <hip/hip_runtime_api.h>
#include "test_common.h"
int main()
{
int main() {
int val;
hipDeviceAttribute_t attr = hipDeviceAttributeMaxThreadsPerBlock; ///< Maximum number of threads per block.
hipDeviceAttribute_t attr =
hipDeviceAttributeMaxThreadsPerBlock; ///< Maximum number of threads per block.
HIP_PRINT_STATUS(hipDeviceGetAttribute(NULL, attr, 0));
HIP_PRINT_STATUS(hipDeviceGetAttribute(&val, attr, 0));
@@ -35,5 +35,4 @@ int main()
HIP_PRINT_STATUS(hipDeviceGetAttribute(&val, attr, 0));
HIP_PRINT_STATUS(hipDeviceGetAttribute(NULL, attr, -1));
HIP_PRINT_STATUS(hipDeviceGetAttribute(&val, attr, -1));
}
@@ -17,11 +17,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include<hip/hip_runtime_api.h>
#include"test_common.h"
#include <hip/hip_runtime_api.h>
#include "test_common.h"
int main()
{
int main() {
hipFuncCache_t pCacheConfig;
HIP_PRINT_STATUS(hipDeviceGetCacheConfig(&pCacheConfig));
HIP_PRINT_STATUS(hipDeviceGetCacheConfig(NULL));
@@ -20,8 +20,7 @@ THE SOFTWARE.
#include <hip/hip_runtime_api.h>
#include "test_common.h"
int main()
{
int main() {
hipLimit_t lim = hipLimitMallocHeapSize;
HIP_PRINT_STATUS(hipDeviceGetLimit(NULL, lim));
}
@@ -17,11 +17,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include<hip/hip_runtime_api.h>
#include"test_common.h"
#include <hip/hip_runtime_api.h>
#include "test_common.h"
int main()
{
int main() {
hipSharedMemConfig_t config;
HIP_PRINT_STATUS(hipDeviceGetSharedMemConfig(NULL));
HIP_PRINT_STATUS(hipDeviceGetSharedMemConfig(&config));
@@ -20,8 +20,7 @@ THE SOFTWARE.
#include <hip/hip_runtime_api.h>
#include "test_common.h"
int main()
{
int main() {
HIP_PRINT_STATUS(hipGetDevice(NULL));
HIP_PRINT_STATUS(hipGetDevice(0));
}
@@ -20,7 +20,4 @@ THE SOFTWARE.
#include <hip/hip_runtime_api.h>
#include "test_common.h"
int main()
{
HIP_PRINT_STATUS(hipGetDeviceCount(NULL));
}
int main() { HIP_PRINT_STATUS(hipGetDeviceCount(NULL)); }
@@ -20,12 +20,11 @@ THE SOFTWARE.
#include <hip/hip_runtime_api.h>
#include "test_common.h"
int main()
{
int main() {
hipDeviceProp_t prop;
HIP_PRINT_STATUS(hipGetDeviceProperties(&prop, -1));
int cnt;
hipGetDeviceCount(&cnt);
HIP_PRINT_STATUS(hipGetDeviceProperties(&prop, cnt+1));
HIP_PRINT_STATUS(hipGetDeviceProperties(&prop, cnt + 1));
HIP_PRINT_STATUS(hipGetDeviceProperties(NULL, 0));
}
@@ -20,10 +20,9 @@ THE SOFTWARE.
#include <hip/hip_runtime_api.h>
#include "test_common.h"
int main()
{
int main() {
HIP_PRINT_STATUS(hipSetDevice(-1));
int count;
hipGetDeviceCount(&count);
HIP_PRINT_STATUS(hipSetDevice(count+1));
HIP_PRINT_STATUS(hipSetDevice(count + 1));
}
@@ -20,8 +20,7 @@ THE SOFTWARE.
#include <hip/hip_runtime_api.h>
#include "test_common.h"
int main()
{
int main() {
HIP_PRINT_STATUS(hipSetDeviceFlags(-1));
HIP_PRINT_STATUS(hipSetDeviceFlags(11));
}
@@ -24,7 +24,7 @@ THE SOFTWARE.
/* HIT_START
* BUILD: %t %s ../test_common.cpp
* RUN: %t EXCLUDE_HIP_PLATFORM hcc
* RUN: %t EXCLUDE_HIP_PLATFORM hcc
* RUN: %t --memcpyWithPeer EXCLUDE_HIP_PLATFORM hcc
* RUN: %t --mirrorPeers EXCLUDE_HIP_PLATFORM hcc
* HIT_END
@@ -33,41 +33,42 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include "test_common.h"
bool p_memcpyWithPeer = false; // use the peer device for the P2P copy
bool p_mirrorPeers = false; // in addition to mapping current to peer space, map peer to current space.
int p_peerDevice = -1; // explicly specify which peer to use, else use p_gpuDevice + 1.
bool p_memcpyWithPeer = false; // use the peer device for the P2P copy
bool p_mirrorPeers =
false; // in addition to mapping current to peer space, map peer to current space.
int p_peerDevice = -1; // explicly specify which peer to use, else use p_gpuDevice + 1.
int g_currentDevice;
int g_peerDevice;
void help(char *argv[])
{
printf ("usage: %s [OPTIONS]\n", argv[0]);
printf (" --memcpyWithPeer : Perform memcpy with peer.\n");
printf (" --mirrorPeers : Mirror memory onto both default device and peerdevice. If 0, memory is mapped only on the default device.\n");
printf (" --peerDevice N : Set peer device.\n");
void help(char* argv[]) {
printf("usage: %s [OPTIONS]\n", argv[0]);
printf(" --memcpyWithPeer : Perform memcpy with peer.\n");
printf(
" --mirrorPeers : Mirror memory onto both default device and peerdevice. If 0, memory "
"is mapped only on the default device.\n");
printf(" --peerDevice N : Set peer device.\n");
};
static hipError_t myHipMemcpy(void *dest, const void *src, size_t sizeBytes, hipMemcpyKind kind, hipStream_t stream, bool async)
{
static hipError_t myHipMemcpy(void* dest, const void* src, size_t sizeBytes, hipMemcpyKind kind,
hipStream_t stream, bool async) {
if (async) {
hipError_t e = hipMemcpyAsync(dest, src, sizeBytes, kind, stream);
//HIPCHECK(hipStreamSynchronize(stream));
hipError_t e = hipMemcpyAsync(dest, src, sizeBytes, kind, stream);
// HIPCHECK(hipStreamSynchronize(stream));
return (e);
} else {
return hipMemcpy(dest, src, sizeBytes, kind);
return hipMemcpy(dest, src, sizeBytes, kind);
};
}
void parseMyArguments(int argc, char *argv[])
{
void parseMyArguments(int argc, char* argv[]) {
int more_argc = HipTest::parseStandardArguments(argc, argv, false);
// parse args for this test:
for (int i = 1; i < more_argc; i++) {
const char *arg = argv[i];
const char* arg = argv[i];
if (!strcmp(arg, "--help")) {
help(argv);
@@ -78,7 +79,7 @@ void parseMyArguments(int argc, char *argv[])
p_mirrorPeers = true;
} else if (!strcmp(arg, "--peerDevice")) {
if (++i >= argc || !HipTest::parseInt(argv[i], &p_peerDevice)) {
failed("Bad peerDevice argument");
failed("Bad peerDevice argument");
}
} else {
failed("Bad argument '%s'", arg);
@@ -86,8 +87,7 @@ void parseMyArguments(int argc, char *argv[])
};
};
void syncBothDevices()
{
void syncBothDevices() {
int saveDevice;
HIPCHECK(hipGetDevice(&saveDevice));
HIPCHECK(hipSetDevice(g_currentDevice));
@@ -101,37 +101,36 @@ void syncBothDevices()
// Sets globals g_currentDevice, g_peerDevice
void setupPeerTests()
{
void setupPeerTests() {
int deviceCnt;
HIPCHECK(hipGetDeviceCount(&deviceCnt));
g_currentDevice = p_gpuDevice;
g_peerDevice = (p_peerDevice == -1) ? ((g_currentDevice + 1) % deviceCnt) : p_peerDevice;
g_peerDevice = (p_peerDevice == -1) ? ((g_currentDevice + 1) % deviceCnt) : p_peerDevice;
printf ("N=%zu device=%d peerDevice=%d (%d devices total)\n", N, g_currentDevice, g_peerDevice, deviceCnt);
printf("N=%zu device=%d peerDevice=%d (%d devices total)\n", N, g_currentDevice, g_peerDevice,
deviceCnt);
// Must be on a multi-gpu system:
assert (g_currentDevice != g_peerDevice);
assert(g_currentDevice != g_peerDevice);
int canAccessPeer;
HIPCHECK(hipDeviceCanAccessPeer(&canAccessPeer, g_currentDevice, g_peerDevice));
printf ("dev#%d canAccessPeer:#%d=%d\n", g_currentDevice, g_peerDevice, canAccessPeer);
printf("dev#%d canAccessPeer:#%d=%d\n", g_currentDevice, g_peerDevice, canAccessPeer);
assert(canAccessPeer);
HIPCHECK (hipSetDevice(g_currentDevice));
HIPCHECK(hipSetDevice(g_currentDevice));
HIPCHECK(hipDeviceReset());
HIPCHECK (hipSetDevice(g_peerDevice));
HIPCHECK(hipSetDevice(g_peerDevice));
HIPCHECK(hipDeviceReset());
}
//---
// Test which enables peer2peer first, then allocates the memory.
void enablePeerFirst(bool useAsyncCopy)
{
printf ("\n==testing: %s useAsyncCopy=%d\n", __func__, useAsyncCopy);
void enablePeerFirst(bool useAsyncCopy) {
printf("\n==testing: %s useAsyncCopy=%d\n", __func__, useAsyncCopy);
setupPeerTests();
@@ -149,82 +148,83 @@ void enablePeerFirst(bool useAsyncCopy)
HIPCHECK(hipDeviceEnablePeerAccess(g_currentDevice, 0));
}
size_t Nbytes = N*sizeof(char);
size_t Nbytes = N * sizeof(char);
char *A_d0, *A_d1;
char *A_h;
char* A_h;
A_h = (char*)malloc(Nbytes);
// allocate and initialize memory on device0
HIPCHECK (hipSetDevice(g_currentDevice));
HIPCHECK (hipMalloc(&A_d0, Nbytes) );
HIPCHECK (hipMemset(A_d0, memsetval, Nbytes) );
HIPCHECK(hipSetDevice(g_currentDevice));
HIPCHECK(hipMalloc(&A_d0, Nbytes));
HIPCHECK(hipMemset(A_d0, memsetval, Nbytes));
// allocate and initialize memory on peer device
HIPCHECK (hipSetDevice(g_peerDevice));
HIPCHECK (hipMalloc(&A_d1, Nbytes) );
HIPCHECK (hipMemset(A_d1, 0x13, Nbytes) );
HIPCHECK(hipSetDevice(g_peerDevice));
HIPCHECK(hipMalloc(&A_d1, Nbytes));
HIPCHECK(hipMemset(A_d1, 0x13, Nbytes));
// Device0 push to device1, using P2P:
// NOTE : if p_mirrorPeers=0 and p_memcpyWithPeer=1, then peer device does not have mapping for A_d1 and we need to use a
// NOTE : if p_mirrorPeers=0 and p_memcpyWithPeer=1, then peer device does not have mapping for
// A_d1 and we need to use a
// a host staging copy for the P2P access.
HIPCHECK (hipSetDevice(p_memcpyWithPeer ? g_peerDevice : g_currentDevice));
HIPCHECK (myHipMemcpy(A_d1, A_d0, Nbytes, hipMemcpyDefault, 0/*stream*/, useAsyncCopy)); // This is P2P copy.
HIPCHECK(hipSetDevice(p_memcpyWithPeer ? g_peerDevice : g_currentDevice));
HIPCHECK(myHipMemcpy(A_d1, A_d0, Nbytes, hipMemcpyDefault, 0 /*stream*/,
useAsyncCopy)); // This is P2P copy.
// Copy data back to host:
// Have to wait for previous operation to finish, since we are switching to another one:
HIPCHECK(hipDeviceSynchronize());
HIPCHECK (hipSetDevice(g_peerDevice));
HIPCHECK (myHipMemcpy(A_h, A_d1, Nbytes, hipMemcpyDeviceToHost, 0/*stream*/, useAsyncCopy));
HIPCHECK(hipSetDevice(g_peerDevice));
HIPCHECK(myHipMemcpy(A_h, A_d1, Nbytes, hipMemcpyDeviceToHost, 0 /*stream*/, useAsyncCopy));
HIPCHECK(hipDeviceSynchronize());
HIPCHECK (hipSetDevice(g_currentDevice));
HIPCHECK(hipSetDevice(g_currentDevice));
// Check host data:
for (int i=0; i<N; i++) {
for (int i = 0; i < N; i++) {
if (A_h[i] != memsetval) {
failed("mismatch at index:%d computed:0x%02x, golden memsetval:0x%02x\n", i, (int)A_h[i], (int)memsetval);
failed("mismatch at index:%d computed:0x%02x, golden memsetval:0x%02x\n", i,
(int)A_h[i], (int)memsetval);
}
}
printf ("==done: %s useAsyncCopy:%d\n\n", __func__, useAsyncCopy);
printf("==done: %s useAsyncCopy:%d\n\n", __func__, useAsyncCopy);
}
//---
// Test which allocated memory first, then enables peer2peer.
// Enabling peer needs to scan all allocated memory and enable peer access.
void allocMemoryFirst(bool useAsyncCopy)
{
printf ("\n==testing: %s useAsyncCopy=%d\n", __func__, useAsyncCopy);
void allocMemoryFirst(bool useAsyncCopy) {
printf("\n==testing: %s useAsyncCopy=%d\n", __func__, useAsyncCopy);
setupPeerTests();
size_t Nbytes = N*sizeof(char);
size_t Nbytes = N * sizeof(char);
char *A_d0, *A_d1;
char *A_h;
char* A_h;
A_h = (char*)malloc(Nbytes);
//---
// allocate and initialize memory on device0
HIPCHECK (hipSetDevice(g_currentDevice));
HIPCHECK (hipMalloc(&A_d0, Nbytes) );
HIPCHECK ( hipMemset(A_d0, memsetval, Nbytes) );
HIPCHECK(hipSetDevice(g_currentDevice));
HIPCHECK(hipMalloc(&A_d0, Nbytes));
HIPCHECK(hipMemset(A_d0, memsetval, Nbytes));
// allocate and initialize memory on peer device
HIPCHECK (hipSetDevice(g_peerDevice));
HIPCHECK (hipMalloc(&A_d1, Nbytes) );
HIPCHECK ( hipMemset(A_d1, 0x13, Nbytes) );
HIPCHECK(hipSetDevice(g_peerDevice));
HIPCHECK(hipMalloc(&A_d1, Nbytes));
HIPCHECK(hipMemset(A_d1, 0x13, Nbytes));
//---
//Enable peer access, for memory already allocated:
// Enable peer access, for memory already allocated:
HIPCHECK(hipSetDevice(g_currentDevice));
HIPCHECK(hipDeviceEnablePeerAccess(g_peerDevice, 0));
@@ -241,26 +241,27 @@ void allocMemoryFirst(bool useAsyncCopy)
//---
// Copies to test functionality:
// Device0 push to device1, using P2P:
HIPCHECK (hipSetDevice(p_memcpyWithPeer ? g_peerDevice : g_currentDevice));
HIPCHECK (myHipMemcpy(A_d1, A_d0, Nbytes, hipMemcpyDefault, 0/*stream*/, useAsyncCopy));
HIPCHECK(hipSetDevice(p_memcpyWithPeer ? g_peerDevice : g_currentDevice));
HIPCHECK(myHipMemcpy(A_d1, A_d0, Nbytes, hipMemcpyDefault, 0 /*stream*/, useAsyncCopy));
syncBothDevices(); // TODO - remove me, should handle this in implementation.
syncBothDevices(); // TODO - remove me, should handle this in implementation.
// Copy data back to host:
HIPCHECK (hipSetDevice(g_peerDevice));
HIPCHECK (myHipMemcpy(A_h, A_d1, Nbytes, hipMemcpyDeviceToHost, 0/*stream*/, useAsyncCopy));
HIPCHECK(hipSetDevice(g_peerDevice));
HIPCHECK(myHipMemcpy(A_h, A_d1, Nbytes, hipMemcpyDeviceToHost, 0 /*stream*/, useAsyncCopy));
syncBothDevices(); // TODO - remove me, should handle this in implementation.
syncBothDevices(); // TODO - remove me, should handle this in implementation.
//---
// Check host data:
for (int i=0; i<N; i++) {
for (int i = 0; i < N; i++) {
if (A_h[i] != memsetval) {
failed("mismatch at index:%d computed:0x%02x, golden memsetval:0x%02x\n", i, (int)A_h[i], (int)memsetval);
failed("mismatch at index:%d computed:0x%02x, golden memsetval:0x%02x\n", i,
(int)A_h[i], (int)memsetval);
}
}
printf ("==done: %s useAsyncCopy=%d\n\n", __func__, useAsyncCopy);
printf("==done: %s useAsyncCopy=%d\n\n", __func__, useAsyncCopy);
}
@@ -269,9 +270,8 @@ void allocMemoryFirst(bool useAsyncCopy)
// A_d0 is pinned host on dev0 (this)
// A_d1 is device memory on dev1 (peer)
//
void testPeerHostToDevice(bool useAsyncCopy)
{
printf ("\n==testing: %s useAsyncCopy=%d\n", __func__, useAsyncCopy);
void testPeerHostToDevice(bool useAsyncCopy) {
printf("\n==testing: %s useAsyncCopy=%d\n", __func__, useAsyncCopy);
setupPeerTests();
@@ -289,126 +289,124 @@ void testPeerHostToDevice(bool useAsyncCopy)
HIPCHECK(hipDeviceEnablePeerAccess(g_currentDevice, 0));
}
size_t Nbytes = N*sizeof(char);
size_t Nbytes = N * sizeof(char);
char *A_host_d0, *A_d1;
char *A_h;
char* A_h;
A_h = (char*)malloc(Nbytes);
// allocate and initialize memory on device0
HIPCHECK (hipSetDevice(g_currentDevice));
HIPCHECK (hipHostMalloc(&A_host_d0, Nbytes) );
HIPCHECK (hipMemset(A_host_d0, memsetval, Nbytes) );
HIPCHECK(hipSetDevice(g_currentDevice));
HIPCHECK(hipHostMalloc(&A_host_d0, Nbytes));
HIPCHECK(hipMemset(A_host_d0, memsetval, Nbytes));
// allocate and initialize memory on peer device
HIPCHECK (hipSetDevice(g_peerDevice));
HIPCHECK (hipMalloc(&A_d1, Nbytes) );
HIPCHECK (hipMemset(A_d1, 0x13, Nbytes) );
HIPCHECK(hipSetDevice(g_peerDevice));
HIPCHECK(hipMalloc(&A_d1, Nbytes));
HIPCHECK(hipMemset(A_d1, 0x13, Nbytes));
bool firstAsyncCopy = useAsyncCopy; /*TODO - should be useAsyncCopy*/
syncBothDevices();
// Device0 push to device1, using P2P:
// NOTE : if p_mirrorPeers=0 and p_memcpyWithPeer=1, then peer device does not have mapping for A_d1 and we need to use a
// NOTE : if p_mirrorPeers=0 and p_memcpyWithPeer=1, then peer device does not have mapping for
// A_d1 and we need to use a
// a host staging copy for the P2P access.
if (p_memcpyWithPeer) {
// p_memcpyWithPeer=1 case is HostToDevice.
// if p_mirrorPeers = 1, this is accelerated copy over PCIe.
// if p_mirrorPeers = 0, this should fall back to host (because peer can't see A_host_d0)
HIPCHECK (hipSetDevice(g_peerDevice));
HIPCHECK (myHipMemcpy(A_d1, A_host_d0, Nbytes, hipMemcpyHostToDevice, 0/*stream*/, firstAsyncCopy)); // This is P2P copy.
HIPCHECK(hipSetDevice(g_peerDevice));
HIPCHECK(myHipMemcpy(A_d1, A_host_d0, Nbytes, hipMemcpyHostToDevice, 0 /*stream*/,
firstAsyncCopy)); // This is P2P copy.
} else {
// p_memcpyWithPeer=0 case is HostToDevice.
// if p_mirrorPeers = 1, this is accelerated copy over PCIe.
// if p_mirrorPeers = 0, this should fall back to host (because device0 can't see A_d1)
HIPCHECK (hipSetDevice(g_currentDevice));
HIPCHECK (myHipMemcpy(A_d1, A_host_d0, Nbytes, hipMemcpyHostToDevice, 0/*stream*/, firstAsyncCopy)); // This is P2P copy.
HIPCHECK(hipSetDevice(g_currentDevice));
HIPCHECK(myHipMemcpy(A_d1, A_host_d0, Nbytes, hipMemcpyHostToDevice, 0 /*stream*/,
firstAsyncCopy)); // This is P2P copy.
}
syncBothDevices();
// Copy data back to host:
HIPCHECK (hipSetDevice(g_peerDevice));
HIPCHECK (myHipMemcpy(A_h, A_d1, Nbytes, hipMemcpyDeviceToHost, 0/*stream*/, useAsyncCopy));
HIPCHECK(hipSetDevice(g_peerDevice));
HIPCHECK(myHipMemcpy(A_h, A_d1, Nbytes, hipMemcpyDeviceToHost, 0 /*stream*/, useAsyncCopy));
HIPCHECK(hipDeviceSynchronize());
HIPCHECK (hipSetDevice(g_currentDevice));
HIPCHECK(hipSetDevice(g_currentDevice));
HIPCHECK(hipDeviceSynchronize());
// Check host data:
for (int i=0; i<N; i++) {
for (int i = 0; i < N; i++) {
if (A_h[i] != memsetval) {
failed("mismatch at index:%d computed:0x%02x, golden memsetval:0x%02x\n", i, (int)A_h[i], (int)memsetval);
failed("mismatch at index:%d computed:0x%02x, golden memsetval:0x%02x\n", i,
(int)A_h[i], (int)memsetval);
}
}
printf ("==done: %s useAsyncCopy:%d\n\n", __func__, useAsyncCopy);
printf("==done: %s useAsyncCopy:%d\n\n", __func__, useAsyncCopy);
}
void simpleNegative()
{
printf ("\n==testing: %s\n", __func__);
void simpleNegative() {
printf("\n==testing: %s\n", __func__);
setupPeerTests();
int deviceId;
HIPCHECK (hipGetDevice(&deviceId));
HIPCHECK(hipGetDevice(&deviceId));
//---
//-- self is not a peer
int canAccessPeer;
hipError_t e = hipDeviceCanAccessPeer(&canAccessPeer, deviceId, deviceId);
HIPASSERT( e == hipSuccess); // no error returned, it doesn't hurt to ask.
HIPASSERT (canAccessPeer == 0); // but self is not a peer.
HIPASSERT(e == hipSuccess); // no error returned, it doesn't hurt to ask.
HIPASSERT(canAccessPeer == 0); // but self is not a peer.
e = hipSuccess;
//---
// Enable same device twice in a row:
HIPCHECK(hipSetDevice(g_currentDevice));
HIPCHECK(hipDeviceEnablePeerAccess(g_peerDevice, 0));
e =(hipDeviceEnablePeerAccess(g_peerDevice, 0));
HIPASSERT (e == hipErrorPeerAccessAlreadyEnabled);
e = (hipDeviceEnablePeerAccess(g_peerDevice, 0));
HIPASSERT(e == hipErrorPeerAccessAlreadyEnabled);
//---
// try disabling twice in a row
HIPCHECK(hipDeviceDisablePeerAccess(g_peerDevice));
e =(hipDeviceDisablePeerAccess(g_peerDevice));
HIPASSERT (e == hipErrorPeerAccessNotEnabled);
e = (hipDeviceDisablePeerAccess(g_peerDevice));
HIPASSERT(e == hipErrorPeerAccessNotEnabled);
// More tests here:
printf ("==done: %s\n\n", __func__);
printf("==done: %s\n\n", __func__);
}
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
parseMyArguments(argc, argv);
int gpuCount;
HIPCHECK(hipGetDeviceCount(&gpuCount));
if (gpuCount < 2)
{
if (gpuCount < 2) {
printf("P2P application requires atleast 2 gpu devices\n");
} else {
if (p_tests & 0x100) {
testPeerHostToDevice(false/*useAsyncCopy*/);
testPeerHostToDevice(false /*useAsyncCopy*/);
}
testPeerHostToDevice(true/*useAsyncCopy*/);
testPeerHostToDevice(true /*useAsyncCopy*/);
if (p_tests & 0x1) {
enablePeerFirst(false/*useAsyncCopy*/);
enablePeerFirst(false /*useAsyncCopy*/);
}
if (p_tests & 0x2) {
allocMemoryFirst(false/*useAsyncCopy*/);
allocMemoryFirst(false /*useAsyncCopy*/);
}
if (p_tests & 0x4) {
@@ -416,10 +414,10 @@ int main(int argc, char *argv[])
}
if (p_tests & 0x8) {
enablePeerFirst(true/*useAsyncCopy*/);
enablePeerFirst(true /*useAsyncCopy*/);
}
if (p_tests & 0x10) {
allocMemoryFirst(true/*useAsyncCopy*/);
allocMemoryFirst(true /*useAsyncCopy*/);
}
}
passed();
@@ -30,20 +30,20 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include "test_common.h"
int main( void ) {
hipDeviceProp_t prop;
int main(void) {
hipDeviceProp_t prop;
int dev;
hipGetDevice( &dev ) ;
printf( "ID of current HIP device: %d\n", dev );
hipGetDevice(&dev);
printf("ID of current HIP device: %d\n", dev);
memset( &prop, 0, sizeof( hipDeviceProp_t ) );
memset(&prop, 0, sizeof(hipDeviceProp_t));
prop.major = 1;
prop.minor = 3;
hipChooseDevice( &dev, &prop );
printf( "ID of hip device closest to revision 1.3: %d\n", dev );
hipChooseDevice(&dev, &prop);
printf("ID of hip device closest to revision 1.3: %d\n", dev);
hipSetDevice( dev );
hipSetDevice(dev);
passed();
}
@@ -30,14 +30,13 @@ THE SOFTWARE.
#include "test_common.h"
int main()
{
int main() {
int numDevices = 0;
int major,minor;
int major, minor;
hipDevice_t device;
HIPCHECK(hipGetDeviceCount(&numDevices));
for(int i=0;i<numDevices;i++){
HIPCHECK(hipDeviceGet(&device,i));
for (int i = 0; i < numDevices; i++) {
HIPCHECK(hipDeviceGet(&device, i));
HIPCHECK(hipDeviceComputeCapability(&major, &minor, device));
HIPASSERT(major >= 0);
HIPASSERT(minor >= 0);
@@ -30,25 +30,25 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include "test_common.h"
int main( void ) {
int main(void) {
char pciBusId[13];
int deviceCount = 0;
HIPCHECK(hipGetDeviceCount(&deviceCount));
HIPASSERT(deviceCount != 0);
for(int i=0; i< deviceCount;i++) {
for (int i = 0; i < deviceCount; i++) {
int pciBusID = -1;
int pciDeviceID = -1;
int pciDomainID = -1;
int tempPciBusId = -1;
int tempDeviceId = -1;
HIPCHECK(hipDeviceGetPCIBusId ( &pciBusId[0], 13, i ));
sscanf (pciBusId,"%04x:%02x:%02x",&pciDomainID,&pciBusID,&pciDeviceID);
HIPCHECK(hipDeviceGetAttribute(&tempPciBusId,hipDeviceAttributePciBusId , i));
if(pciBusID != tempPciBusId) {
HIPCHECK(hipDeviceGetPCIBusId(&pciBusId[0], 13, i));
sscanf(pciBusId, "%04x:%02x:%02x", &pciDomainID, &pciBusID, &pciDeviceID);
HIPCHECK(hipDeviceGetAttribute(&tempPciBusId, hipDeviceAttributePciBusId, i));
if (pciBusID != tempPciBusId) {
exit(EXIT_FAILURE);
}
HIPCHECK(hipDeviceGetByPCIBusId ( &tempDeviceId, pciBusId ));
if(tempDeviceId != i) {
HIPCHECK(hipDeviceGetByPCIBusId(&tempDeviceId, pciBusId));
if (tempDeviceId != i) {
exit(EXIT_FAILURE);
}
}
@@ -32,15 +32,14 @@ THE SOFTWARE.
#define len 256
int main()
{
int main() {
int numDevices = 0;
char name[len];
hipDevice_t device;
HIPCHECK(hipGetDeviceCount(&numDevices));
for(int i=0;i<numDevices;i++){
HIPCHECK(hipDeviceGet(&device,i));
HIPCHECK(hipDeviceGetName(name,len,device));
for (int i = 0; i < numDevices; i++) {
HIPCHECK(hipDeviceGet(&device, i));
HIPCHECK(hipDeviceGetName(name, len, device));
HIPASSERT(name != "");
}
passed();
@@ -30,20 +30,20 @@ THE SOFTWARE.
#include "hip/hip_runtime.h"
#include "test_common.h"
int main( void ) {
int main(void) {
char pciBusId[13];
int deviceCount = 0;
HIPCHECK(hipGetDeviceCount(&deviceCount));
HIPASSERT(deviceCount != 0);
for(int i=0; i< deviceCount;i++) {
for (int i = 0; i < deviceCount; i++) {
int pciBusID = -1;
int pciDeviceID = -1;
int pciDomainID = -1;
int tempPciBusId = -1;
HIPCHECK(hipDeviceGetPCIBusId ( &pciBusId[0], 13, i ));
sscanf (pciBusId,"%04x:%02x:%02x",&pciDomainID,&pciBusID,&pciDeviceID);
HIPCHECK(hipDeviceGetAttribute(&tempPciBusId,hipDeviceAttributePciBusId , i));
if(pciBusID != tempPciBusId) {
HIPCHECK(hipDeviceGetPCIBusId(&pciBusId[0], 13, i));
sscanf(pciBusId, "%04x:%02x:%02x", &pciDomainID, &pciBusID, &pciDeviceID);
HIPCHECK(hipDeviceGetAttribute(&tempPciBusId, hipDeviceAttributePciBusId, i));
if (pciBusID != tempPciBusId) {
exit(EXIT_FAILURE);
}
}
@@ -20,7 +20,7 @@ THE SOFTWARE.
/*
* Test for checking the functionality of
* hipError_t hipDeviceSynchronize();
*/
*/
/* HIT_START
* BUILD: %t %s ../../test_common.cpp
@@ -28,47 +28,49 @@ THE SOFTWARE.
* HIT_END
*/
#include"test_common.h"
#include "test_common.h"
#define _SIZE sizeof(int)*1024*1024
#define _SIZE sizeof(int) * 1024 * 1024
#define NUM_STREAMS 2
__global__ void Iter(hipLaunchParm lp, int *Ad, int num){
__global__ void Iter(hipLaunchParm lp, int* Ad, int num) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
// Kernel loop designed to execute very slowly... ... ... so we can test timing-related behavior below
if(tx == 0){
for(int i = 0; i<num;i++){
// Kernel loop designed to execute very slowly... ... ... so we can test timing-related
// behavior below
if (tx == 0) {
for (int i = 0; i < num; i++) {
Ad[tx] += 1;
}
}
}
int main(){
int *A[NUM_STREAMS];
int *Ad[NUM_STREAMS];
int main() {
int* A[NUM_STREAMS];
int* Ad[NUM_STREAMS];
hipStream_t stream[NUM_STREAMS];
for(int i=0;i<NUM_STREAMS;i++){
for (int i = 0; i < NUM_STREAMS; i++) {
HIPCHECK(hipHostMalloc((void**)&A[i], _SIZE, hipHostMallocDefault));
A[i][0] = 1;
HIPCHECK(hipMalloc((void**)&Ad[i], _SIZE));
HIPCHECK(hipStreamCreate(&stream[i]));
}
for(int i=0;i<NUM_STREAMS;i++){
for (int i = 0; i < NUM_STREAMS; i++) {
HIPCHECK(hipMemcpyAsync(Ad[i], A[i], _SIZE, hipMemcpyHostToDevice, stream[i]));
}
for(int i=0;i<NUM_STREAMS;i++){
hipLaunchKernel(HIP_KERNEL_NAME(Iter), dim3(1), dim3(1), 0, stream[i], Ad[i], 1<<30);
for (int i = 0; i < NUM_STREAMS; i++) {
hipLaunchKernel(HIP_KERNEL_NAME(Iter), dim3(1), dim3(1), 0, stream[i], Ad[i], 1 << 30);
}
for(int i=0;i<NUM_STREAMS;i++){
for (int i = 0; i < NUM_STREAMS; i++) {
HIPCHECK(hipMemcpyAsync(A[i], Ad[i], _SIZE, hipMemcpyDeviceToHost, stream[i]));
}
// This first check but relies on the kernel running for so long that the D2H async memcopy has not started yet.
// This will be true in an optimal asynchronous implementation.
// Conservative implementations which synchronize the hipMemcpyAsync will fail, ie if HIP_LAUNCH_BLOCKING=true
HIPASSERT(1<<30 != A[NUM_STREAMS-1][0]-1);
// This first check but relies on the kernel running for so long that the D2H async memcopy has
// not started yet. This will be true in an optimal asynchronous implementation. Conservative
// implementations which synchronize the hipMemcpyAsync will fail, ie if
// HIP_LAUNCH_BLOCKING=true
HIPASSERT(1 << 30 != A[NUM_STREAMS - 1][0] - 1);
HIPCHECK(hipDeviceSynchronize());
HIPASSERT(1<<30 == A[NUM_STREAMS-1][0]-1);
HIPASSERT(1 << 30 == A[NUM_STREAMS - 1][0] - 1);
passed();
}
@@ -30,15 +30,14 @@ THE SOFTWARE.
#include "test_common.h"
int main()
{
int main() {
int numDevices = 0;
size_t totMem;
hipDevice_t device;
HIPCHECK(hipGetDeviceCount(&numDevices));
for(int i=0;i<numDevices;i++){
HIPCHECK(hipDeviceGet(&device,i));
HIPCHECK(hipDeviceTotalMem(&totMem,device));
for (int i = 0; i < numDevices; i++) {
HIPCHECK(hipDeviceGet(&device, i));
HIPCHECK(hipDeviceTotalMem(&totMem, device));
HIPASSERT(totMem != 0);
}
passed();
@@ -30,12 +30,11 @@ THE SOFTWARE.
#include "test_common.h"
int main()
{
int main() {
int numDevices = 0;
int device;
HIPCHECK(hipGetDeviceCount(&numDevices));
for(int i=0;i<numDevices;i++){
for (int i = 0; i < numDevices; i++) {
HIPCHECK(hipSetDevice(i));
HIPCHECK(hipGetDevice(&device));
HIPASSERT(device == i);
@@ -33,17 +33,20 @@ THE SOFTWARE.
#include "test_common.h"
#define CHECK(error) \
if (error != hipSuccess) { \
fprintf(stderr, "error: '%s'(%d) at %s:%d\n", hipGetErrorString(error), error,__FILE__, __LINE__); \
exit(EXIT_FAILURE);\
#define CHECK(error) \
if (error != hipSuccess) { \
fprintf(stderr, "error: '%s'(%d) at %s:%d\n", hipGetErrorString(error), error, __FILE__, \
__LINE__); \
exit(EXIT_FAILURE); \
}
hipError_t test_hipDeviceGetAttribute(int deviceId, hipDeviceAttribute_t attr, int expectedValue = -1)
{
hipError_t test_hipDeviceGetAttribute(int deviceId, hipDeviceAttribute_t attr,
int expectedValue = -1) {
int value = 0;
std::cout << "Test hipDeviceGetAttribute attribute " << attr;
if (expectedValue != -1) { std::cout << " expected value " << expectedValue; }
if (expectedValue != -1) {
std::cout << " expected value " << expectedValue;
}
hipError_t e = hipDeviceGetAttribute(&value, attr, deviceId);
std::cout << " actual value " << value << std::endl;
if ((expectedValue != -1) && value != expectedValue) {
@@ -53,39 +56,57 @@ hipError_t test_hipDeviceGetAttribute(int deviceId, hipDeviceAttribute_t attr, i
return hipSuccess;
}
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
int deviceId;
CHECK (hipGetDevice(&deviceId));
CHECK(hipGetDevice(&deviceId));
hipDeviceProp_t props;
CHECK(hipGetDeviceProperties(&props, deviceId));
printf ("info: running on device #%d %s\n", deviceId, props.name);
printf("info: running on device #%d %s\n", deviceId, props.name);
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxThreadsPerBlock, props.maxThreadsPerBlock));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimX, props.maxThreadsDim[0]));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimY, props.maxThreadsDim[1]));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimZ, props.maxThreadsDim[2]));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimX, props.maxGridSize[0]));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimY, props.maxGridSize[1]));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimZ, props.maxGridSize[2]));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxSharedMemoryPerBlock, props.sharedMemPerBlock));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeTotalConstantMemory, props.totalConstMem));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxThreadsPerBlock,
props.maxThreadsPerBlock));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimX,
props.maxThreadsDim[0]));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimY,
props.maxThreadsDim[1]));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimZ,
props.maxThreadsDim[2]));
CHECK(
test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimX, props.maxGridSize[0]));
CHECK(
test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimY, props.maxGridSize[1]));
CHECK(
test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimZ, props.maxGridSize[2]));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxSharedMemoryPerBlock,
props.sharedMemPerBlock));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeTotalConstantMemory,
props.totalConstMem));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeWarpSize, props.warpSize));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxRegistersPerBlock, props.regsPerBlock));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxRegistersPerBlock,
props.regsPerBlock));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeClockRate, props.clockRate));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMemoryClockRate, props.memoryClockRate));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMemoryBusWidth, props.memoryBusWidth));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMultiprocessorCount, props.multiProcessorCount));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeIsMultiGpuBoard, props.isMultiGpuBoard));//
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMemoryClockRate,
props.memoryClockRate));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMemoryBusWidth,
props.memoryBusWidth));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMultiprocessorCount,
props.multiProcessorCount));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeIsMultiGpuBoard,
props.isMultiGpuBoard)); //
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeComputeMode, props.computeMode));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeL2CacheSize, props.l2CacheSize));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxThreadsPerMultiProcessor, props.maxThreadsPerMultiProcessor));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeComputeCapabilityMajor, props.major));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeComputeCapabilityMinor, props.minor));//
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeConcurrentKernels, props.concurrentKernels));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxThreadsPerMultiProcessor,
props.maxThreadsPerMultiProcessor));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeComputeCapabilityMajor,
props.major));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeComputeCapabilityMinor,
props.minor)); //
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeConcurrentKernels,
props.concurrentKernels));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributePciBusId, props.pciBusID));
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributePciDeviceId, props.pciDeviceID));//
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxSharedMemoryPerMultiprocessor, props.maxSharedMemoryPerMultiProcessor));
CHECK(
test_hipDeviceGetAttribute(deviceId, hipDeviceAttributePciDeviceId, props.pciDeviceID)); //
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxSharedMemoryPerMultiprocessor,
props.maxSharedMemoryPerMultiProcessor));
passed();
};
@@ -20,7 +20,8 @@ THE SOFTWARE.
/*
* Conformance test for checking functionality of
* hipError_t hipRuntimeGetVersion(int* runtimeVersion);
* On HIP/HCC path this function returns HIP runtime patch version(a 5 digit code) however on HIP/NVCC path this function return CUDA runtime version.
* On HIP/HCC path this function returns HIP runtime patch version(a 5 digit code) however on
* HIP/NVCC path this function return CUDA runtime version.
*/
/* HIT_START
@@ -31,8 +32,7 @@ THE SOFTWARE.
#include "test_common.h"
int main()
{
int main() {
int runtimeVersion;
HIPCHECK(hipRuntimeGetVersion(&runtimeVersion));
passed();
@@ -23,14 +23,13 @@ THE SOFTWARE.
* HIT_END
*/
#include<hip/hip_runtime_api.h>
#include<iostream>
#include"test_common.h"
#include <hip/hip_runtime_api.h>
#include <iostream>
#include "test_common.h"
int main(){
hipFuncCache_t cacheConfig;
void *func;
hipFuncSetCacheConfig(func, cacheConfig);
passed();
int main() {
hipFuncCache_t cacheConfig;
void* func;
hipFuncSetCacheConfig(func, cacheConfig);
passed();
}
@@ -25,10 +25,10 @@ THE SOFTWARE.
#include "test_common.h"
int main(){
int main() {
int numDevices = 0;
HIPCHECK(hipGetDeviceCount(&numDevices));
for(int i=0;i<numDevices;i++){
for (int i = 0; i < numDevices; i++) {
HIPCHECK(hipSetDevice(i));
}
HIPASSERT(hipErrorInvalidDevice == hipSetDevice(numDevices));
@@ -25,27 +25,24 @@ THE SOFTWARE.
#include "test_common.h"
int main()
{
int main() {
unsigned flag = 0;
HIPCHECK(hipDeviceReset());
int deviceCount = 0;
HIPCHECK(hipGetDeviceCount(&deviceCount));
for(int j=0;j<deviceCount;j++){
for (int j = 0; j < deviceCount; j++) {
HIPCHECK(hipSetDevice(j));
for(int i=0;i<4;i++){
for (int i = 0; i < 4; i++) {
flag = 1 << i;
printf ("Flag=%x\n", flag);
printf("Flag=%x\n", flag);
HIPCHECK(hipSetDeviceFlags(flag));
//HIPCHECK_API(hipSetDeviceFlags(flag), hipErrorInvalidValue);
// HIPCHECK_API(hipSetDeviceFlags(flag), hipErrorInvalidValue);
}
flag = 0;
}
passed();
@@ -30,9 +30,7 @@ THE SOFTWARE.
#include "test_common.h"
int main()
{
hipSetDevice(-1);
if(hipPeekAtLastError() != hipSuccess)
passed();
int main() {
hipSetDevice(-1);
if (hipPeekAtLastError() != hipSuccess) passed();
}

برخی از فایل ها نشان داده نشدند زیرا تعداد زیادی فایل در این تفاوت تغییر کرده اند نمایش بیشتر