Merge branch 'master' into support-malloc
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// RUN: %run_test hipify "%s" "%t" %cuda_args
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
// CHECK: #include "hipblas.h"
|
||||
#include "cublas.h"
|
||||
#define M 6
|
||||
#define N 5
|
||||
#define IDX2C(i,j,ld) (((j)*(ld))+(i))
|
||||
static __inline__ void modify(float *m, int ldm, int n, int p, int q, float
|
||||
alpha, float beta) {
|
||||
// CHECK: hipblasSscal(n - p, alpha, &m[IDX2C(p, q, ldm)], ldm);
|
||||
// CHECK: hipblasSscal(ldm - p, beta, &m[IDX2C(p, q, ldm)], 1);
|
||||
cublasSscal(n - p, alpha, &m[IDX2C(p, q, ldm)], ldm);
|
||||
cublasSscal(ldm - p, beta, &m[IDX2C(p, q, ldm)], 1);
|
||||
}
|
||||
int main(void) {
|
||||
int i, j;
|
||||
// CHECK: hipblasStatus_t stat;
|
||||
cublasStatus stat;
|
||||
float* devPtrA;
|
||||
float* a = 0;
|
||||
a = (float *)malloc(M * N * sizeof(*a));
|
||||
if (!a) {
|
||||
printf("host memory allocation failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
for (j = 0; j < N; j++) {
|
||||
for (i = 0; i < M; i++) {
|
||||
a[IDX2C(i, j, M)] = (float)(i * M + j + 1);
|
||||
}
|
||||
}
|
||||
// cublasInit is not supported yet
|
||||
cublasInit();
|
||||
stat = cublasAlloc(M*N, sizeof(*a), (void**)&devPtrA);
|
||||
// CHECK: if (stat != HIPBLAS_STATUS_SUCCESS) {
|
||||
if (stat != CUBLAS_STATUS_SUCCESS) {
|
||||
printf("device memory allocation failed");
|
||||
// cublasShutdown is not supported yet
|
||||
cublasShutdown();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// CHECK: stat = hipblasSetMatrix(M, N, sizeof(*a), a, M, devPtrA, M);
|
||||
stat = cublasSetMatrix(M, N, sizeof(*a), a, M, devPtrA, M);
|
||||
// CHECK: if (stat != HIPBLAS_STATUS_SUCCESS) {
|
||||
if (stat != CUBLAS_STATUS_SUCCESS) {
|
||||
printf("data download failed");
|
||||
// cublasFree is not supported yet
|
||||
cublasFree(devPtrA);
|
||||
// cublasShutdown is not supported yet
|
||||
cublasShutdown();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
modify(devPtrA, M, N, 1, 2, 16.0f, 12.0f);
|
||||
// CHECK: stat = hipblasGetMatrix(M, N, sizeof(*a), devPtrA, M, a, M);
|
||||
stat = cublasGetMatrix(M, N, sizeof(*a), devPtrA, M, a, M);
|
||||
// CHECK: if (stat != HIPBLAS_STATUS_SUCCESS) {
|
||||
if (stat != CUBLAS_STATUS_SUCCESS) {
|
||||
printf("data upload failed");
|
||||
// cublasFree is not supported yet
|
||||
cublasFree(devPtrA);
|
||||
// cublasShutdown is not supported yet
|
||||
cublasShutdown();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// cublasFree is not supported yet
|
||||
cublasFree(devPtrA);
|
||||
// cublasShutdown is not supported yet
|
||||
cublasShutdown();
|
||||
for (j = 0; j < N; j++) {
|
||||
for (i = 0; i < M; i++) {
|
||||
printf("%7.0f", a[IDX2C(i, j, M)]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
free(a);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// RUN: %run_test hipify "%s" "%t" %cuda_args
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
// CHECK: #include <hip/hip_runtime.h>
|
||||
#include <cuda_runtime.h>
|
||||
// CHECK: #include "hipblas.h"
|
||||
#include "cublas_v2.h"
|
||||
#define M 6
|
||||
#define N 5
|
||||
#define IDX2F(i,j,ld) ((((j)-1)*(ld))+((i)-1))
|
||||
// CHECK: static __inline__ void modify(hipblasHandle_t handle, float *m, int ldm, int
|
||||
static __inline__ void modify(cublasHandle_t handle, float *m, int ldm, int
|
||||
n, int p, int q, float alpha, float beta) {
|
||||
// CHECK: hipblasSscal(handle, n - p + 1, &alpha, &m[IDX2F(p, q, ldm)], ldm);
|
||||
// CHECK: hipblasSscal(handle, ldm - p + 1, &beta, &m[IDX2F(p, q, ldm)], 1);
|
||||
cublasSscal(handle, n - p + 1, &alpha, &m[IDX2F(p, q, ldm)], ldm);
|
||||
cublasSscal(handle, ldm - p + 1, &beta, &m[IDX2F(p, q, ldm)], 1);
|
||||
}
|
||||
int main(void) {
|
||||
// CHECK: hipError_t cudaStat;
|
||||
// CHECK: hipblasStatus_t stat;
|
||||
// CHECK: hipblasHandle_t handle;
|
||||
cudaError_t cudaStat;
|
||||
cublasStatus_t stat;
|
||||
cublasHandle_t handle;
|
||||
int i, j;
|
||||
float* devPtrA;
|
||||
float* a = 0;
|
||||
a = (float *)malloc(M * N * sizeof(*a));
|
||||
if (!a) {
|
||||
printf("host memory allocation failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
for (j = 1; j <= N; j++) {
|
||||
for (i = 1; i <= M; i++) {
|
||||
a[IDX2F(i, j, M)] = (float)((i - 1) * M + j);
|
||||
}
|
||||
}
|
||||
// CHECK: cudaStat = hipMalloc((void**)&devPtrA, M*N * sizeof(*a));
|
||||
cudaStat = cudaMalloc((void**)&devPtrA, M*N * sizeof(*a));
|
||||
// CHECK: if (cudaStat != hipSuccess) {
|
||||
if (cudaStat != cudaSuccess) {
|
||||
printf("device memory allocation failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// CHECK: stat = hipblasCreate(&handle);
|
||||
stat = cublasCreate(&handle);
|
||||
// CHECK: if (stat != HIPBLAS_STATUS_SUCCESS) {
|
||||
if (stat != CUBLAS_STATUS_SUCCESS) {
|
||||
printf("CUBLAS initialization failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// CHECK: stat = hipblasSetMatrix(M, N, sizeof(*a), a, M, devPtrA, M);
|
||||
stat = cublasSetMatrix(M, N, sizeof(*a), a, M, devPtrA, M);
|
||||
// CHECK: if (stat != HIPBLAS_STATUS_SUCCESS) {
|
||||
if (stat != CUBLAS_STATUS_SUCCESS) {
|
||||
printf("data download failed");
|
||||
// CHECK: hipFree(devPtrA);
|
||||
// CHECK: hipblasDestroy(handle);
|
||||
cudaFree(devPtrA);
|
||||
cublasDestroy(handle);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
modify(handle, devPtrA, M, N, 2, 3, 16.0f, 12.0f);
|
||||
// CHECK: stat = hipblasGetMatrix(M, N, sizeof(*a), devPtrA, M, a, M);
|
||||
stat = cublasGetMatrix(M, N, sizeof(*a), devPtrA, M, a, M);
|
||||
// CHECK: if (stat != HIPBLAS_STATUS_SUCCESS) {
|
||||
if (stat != CUBLAS_STATUS_SUCCESS) {
|
||||
printf("data upload failed");
|
||||
// CHECK: hipFree(devPtrA);
|
||||
// CHECK: hipblasDestroy(handle);
|
||||
cudaFree(devPtrA);
|
||||
cublasDestroy(handle);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// CHECK: hipFree(devPtrA);
|
||||
// CHECK: hipblasDestroy(handle);
|
||||
cudaFree(devPtrA);
|
||||
cublasDestroy(handle);
|
||||
for (j = 1; j <= N; j++) {
|
||||
for (i = 1; i <= M; i++) {
|
||||
printf("%7.0f", a[IDX2F(i, j, M)]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
free(a);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
// RUN: %run_test hipify "%s" "%t" %cuda_args
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
// CHECK: #include <hip/hip_runtime.h>
|
||||
#include <cuda_runtime.h>
|
||||
// CHECK: #include "hipblas.h"
|
||||
#include "cublas_v2.h"
|
||||
#define IDX2C(i,j,ld) (((j)*(ld))+(i))
|
||||
#define m 6
|
||||
#define n 4
|
||||
#define k 5
|
||||
int main(void) {
|
||||
// CHECK: hipError_t cudaStat;
|
||||
// CHECK: hipblasStatus_t stat;
|
||||
// CHECK: hipblasHandle_t handle;
|
||||
cudaError_t cudaStat;
|
||||
cublasStatus_t stat;
|
||||
cublasHandle_t handle;
|
||||
int i, j;
|
||||
float * a;
|
||||
float * b;
|
||||
float * c;
|
||||
a = (float *)malloc(m*k * sizeof(float));
|
||||
b = (float *)malloc(k*n * sizeof(float));
|
||||
c = (float *)malloc(m*n * sizeof(float));
|
||||
int ind = 11;
|
||||
for (j = 0; j<k; j++) {
|
||||
for (i = 0; i<m; i++) {
|
||||
a[IDX2C(i, j, m)] = (float)ind++;
|
||||
}
|
||||
}
|
||||
printf("a:\n");
|
||||
for (i = 0; i<m; i++) {
|
||||
for (j = 0; j<k; j++) {
|
||||
printf(" %5.0f", a[IDX2C(i, j, m)]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
ind = 11;
|
||||
for (j = 0; j<n; j++) {
|
||||
for (i = 0; i<k; i++) {
|
||||
b[IDX2C(i, j, k)] = (float)ind++;
|
||||
}
|
||||
}
|
||||
printf("b:\n");
|
||||
for (i = 0; i<k; i++) {
|
||||
for (j = 0; j<n; j++) {
|
||||
printf(" %5.0f", b[IDX2C(i, j, k)]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
ind = 11;
|
||||
for (j = 0; j<n; j++) {
|
||||
for (i = 0; i<m; i++) {
|
||||
c[IDX2C(i, j, m)] = (float)ind++;
|
||||
}
|
||||
}
|
||||
printf("c:\n");
|
||||
for (i = 0; i<m; i++) {
|
||||
for (j = 0; j<n; j++) {
|
||||
printf(" %5.0f", c[IDX2C(i, j, m)]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
float * d_a;
|
||||
float * d_b;
|
||||
float * d_c;
|
||||
// CHECK: cudaStat = hipMalloc((void **)& d_a, m*k * sizeof(*a));
|
||||
// CHECK: cudaStat = hipMalloc((void **)& d_b, k*n * sizeof(*b));
|
||||
// CHECK: cudaStat = hipMalloc((void **)& d_c, m*n * sizeof(*c));
|
||||
cudaStat = cudaMalloc((void **)& d_a, m*k * sizeof(*a));
|
||||
cudaStat = cudaMalloc((void **)& d_b, k*n * sizeof(*b));
|
||||
cudaStat = cudaMalloc((void **)& d_c, m*n * sizeof(*c));
|
||||
// CHECK: stat = hipblasCreate(&handle);
|
||||
stat = cublasCreate(&handle);
|
||||
// CHECK: stat = hipblasSetMatrix(m, k, sizeof(*a), a, m, d_a, m);
|
||||
// CHECK: stat = hipblasSetMatrix(k, n, sizeof(*b), b, k, d_b, k);
|
||||
// CHECK: stat = hipblasSetMatrix(m, n, sizeof(*c), c, m, d_c, m);
|
||||
stat = cublasSetMatrix(m, k, sizeof(*a), a, m, d_a, m);
|
||||
stat = cublasSetMatrix(k, n, sizeof(*b), b, k, d_b, k);
|
||||
stat = cublasSetMatrix(m, n, sizeof(*c), c, m, d_c, m);
|
||||
float al = 1.0f;
|
||||
float bet = 1.0f;
|
||||
// CHECK: stat = hipblasSgemm(handle, HIPBLAS_OP_N, HIPBLAS_OP_N, m, n, k, &al, d_a, m, d_b, k, &bet, d_c, m);
|
||||
stat = cublasSgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, m, n, k, &al, d_a, m, d_b, k, &bet, d_c, m);
|
||||
// CHECK: stat = hipblasGetMatrix(m, n, sizeof(*c), d_c, m, c, m);
|
||||
stat = cublasGetMatrix(m, n, sizeof(*c), d_c, m, c, m);
|
||||
printf("c after Sgemm :\n");
|
||||
for (i = 0; i<m; i++) {
|
||||
for (j = 0; j<n; j++) {
|
||||
printf(" %7.0f", c[IDX2C(i, j, m)]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
// CHECK: hipFree(d_a);
|
||||
// CHECK: hipFree(d_b);
|
||||
// CHECK: hipFree(d_c);
|
||||
// CHECK: hipblasDestroy(handle);
|
||||
cudaFree(d_a);
|
||||
cudaFree(d_b);
|
||||
cudaFree(d_c);
|
||||
cublasDestroy(handle);
|
||||
free(a);
|
||||
free(b);
|
||||
free(c);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// RUN: %run_test hipify "%s" "%t" %cuda_args
|
||||
|
||||
// CHECK: #include <hip/hip_runtime.h>
|
||||
// CHECK: #include "hip/hip_complex.h"
|
||||
#include "cuComplex.h"
|
||||
|
||||
#define TYPEFLOAT
|
||||
#define DIMX 100
|
||||
#define DIMY 40
|
||||
#define moveX 2
|
||||
#define moveY 1
|
||||
|
||||
#define MAXITERATIONS 10
|
||||
|
||||
#ifdef TYPEFLOAT
|
||||
#define TYPE float
|
||||
// CHECK: #define cTYPE hipFloatComplex
|
||||
#define cTYPE cuFloatComplex
|
||||
// CHECK: #define cMakecuComplex(re,i) make_hipFloatComplex(re,i)
|
||||
#define cMakecuComplex(re,i) make_cuFloatComplex(re,i)
|
||||
#endif
|
||||
#ifdef TYPEDOUBLE
|
||||
// CHECK: #define TYPE hipDoubleComplex
|
||||
#define TYPE cuDoubleComplex
|
||||
// CHECK: #define cMakecuComplex(re,i) make_hipDoubleComplex(re,i)
|
||||
#define cMakecuComplex(re,i) make_cuDoubleComplex(re,i)
|
||||
#endif
|
||||
|
||||
__device__ cTYPE juliaFunctor(cTYPE p, cTYPE c) {
|
||||
// CHECK: return hipCaddf(hipCmulf(p, p), c);
|
||||
return cuCaddf(cuCmulf(p, p), c);
|
||||
}
|
||||
|
||||
__device__ cTYPE convertToComplex(int x, int y, float zoom) {
|
||||
TYPE jx = 1.5 * (x - DIMX / 2) / (0.5 * zoom * DIMX) + moveX;
|
||||
TYPE jy = (y - DIMY / 2) / (0.5 * zoom * DIMY) + moveY;
|
||||
return cMakecuComplex(jx, jy);
|
||||
}
|
||||
|
||||
__device__ int evolveComplexPoint(cTYPE p, cTYPE c) {
|
||||
int it = 1;
|
||||
// CHECK: while (it <= MAXITERATIONS && hipCabsf(p) <= 4) {
|
||||
while (it <= MAXITERATIONS && cuCabsf(p) <= 4) {
|
||||
p = juliaFunctor(p, c);
|
||||
it++;
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
__global__ void computeJulia(int* data, cTYPE c, float zoom) {
|
||||
int i = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int j = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
|
||||
if (i<DIMX && j<DIMY) {
|
||||
cTYPE p = convertToComplex(i, j, zoom);
|
||||
data[i*DIMY + j] = evolveComplexPoint(p, c);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
// RUN: %run_test hipify "%s" "%t" %cuda_args
|
||||
|
||||
// CHECK: #include <hip/hip_runtime.h>
|
||||
#include <cuda.h>
|
||||
// CHECK: #include <hipfft.h>
|
||||
#include <cufft.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#define DATASIZE 8
|
||||
#define BATCH 2
|
||||
|
||||
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
|
||||
// CHECK: inline void gpuAssert(hipError_t code, const char *file, int line, bool abort = true)
|
||||
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort = true)
|
||||
{
|
||||
// CHECK: if (code != hipSuccess)
|
||||
if (code != cudaSuccess)
|
||||
{
|
||||
// CHECK: fprintf(stderr, "GPUassert: %s %s %dn", hipGetErrorString(code), file, line);
|
||||
fprintf(stderr, "GPUassert: %s %s %dn", cudaGetErrorString(code), file, line);
|
||||
if (abort) exit(code);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// --- Host side input data allocation and initialization
|
||||
// CHECK: hipfftReal *hostInputData = (hipfftReal*)malloc(DATASIZE*BATCH * sizeof(hipfftReal));
|
||||
cufftReal *hostInputData = (cufftReal*)malloc(DATASIZE*BATCH * sizeof(cufftReal));
|
||||
for (int i = 0; i<BATCH; i++)
|
||||
for (int j = 0; j<DATASIZE; j++) hostInputData[i*DATASIZE + j] = (cufftReal)(i + 1);
|
||||
|
||||
// --- Device side input data allocation and initialization
|
||||
cufftReal *deviceInputData; gpuErrchk(cudaMalloc((void**)&deviceInputData, DATASIZE * BATCH * sizeof(cufftReal)));
|
||||
// CHECK: hipMemcpy(deviceInputData, hostInputData, DATASIZE * BATCH * sizeof(hipfftReal), hipMemcpyHostToDevice);
|
||||
cudaMemcpy(deviceInputData, hostInputData, DATASIZE * BATCH * sizeof(cufftReal), cudaMemcpyHostToDevice);
|
||||
|
||||
// --- Host side output data allocation
|
||||
cufftComplex *hostOutputData = (cufftComplex*)malloc((DATASIZE / 2 + 1) * BATCH * sizeof(cufftComplex));
|
||||
|
||||
// --- Device side output data allocation
|
||||
cufftComplex *deviceOutputData; gpuErrchk(cudaMalloc((void**)&deviceOutputData, (DATASIZE / 2 + 1) * BATCH * sizeof(cufftComplex)));
|
||||
|
||||
// --- Batched 1D FFTs
|
||||
// CHECK: hipfftHandle handle;
|
||||
cufftHandle handle;
|
||||
int rank = 1; // --- 1D FFTs
|
||||
int n[] = { DATASIZE }; // --- Size of the Fourier transform
|
||||
int istride = 1, ostride = 1; // --- Distance between two successive input/output elements
|
||||
int idist = DATASIZE, odist = (DATASIZE / 2 + 1); // --- Distance between batches
|
||||
int inembed[] = { 0 }; // --- Input size with pitch (ignored for 1D transforms)
|
||||
int onembed[] = { 0 }; // --- Output size with pitch (ignored for 1D transforms)
|
||||
int batch = BATCH; // --- Number of batched executions
|
||||
// CHECK: hipfftPlanMany(&handle, rank, n,
|
||||
cufftPlanMany(&handle, rank, n,
|
||||
inembed, istride, idist,
|
||||
// CHECK: onembed, ostride, odist, HIPFFT_R2C, batch);
|
||||
onembed, ostride, odist, CUFFT_R2C, batch);
|
||||
|
||||
// CHECK: hipfftExecR2C(handle, deviceInputData, deviceOutputData);
|
||||
cufftExecR2C(handle, deviceInputData, deviceOutputData);
|
||||
|
||||
// --- Device->Host copy of the results
|
||||
// CHECK: gpuErrchk(hipMemcpy(hostOutputData, deviceOutputData, (DATASIZE / 2 + 1) * BATCH * sizeof(hipfftComplex), hipMemcpyDeviceToHost));
|
||||
gpuErrchk(cudaMemcpy(hostOutputData, deviceOutputData, (DATASIZE / 2 + 1) * BATCH * sizeof(cufftComplex), cudaMemcpyDeviceToHost));
|
||||
|
||||
for (int i = 0; i<BATCH; i++)
|
||||
for (int j = 0; j<(DATASIZE / 2 + 1); j++)
|
||||
printf("%i %i %f %fn", i, j, hostOutputData[i*(DATASIZE / 2 + 1) + j].x, hostOutputData[i*(DATASIZE / 2 + 1) + j].y);
|
||||
|
||||
// CHECK: hipfftDestroy(handle);
|
||||
cufftDestroy(handle);
|
||||
// CHECK: gpuErrchk(hipFree(deviceOutputData));
|
||||
// CHECK: gpuErrchk(hipFree(deviceInputData));
|
||||
gpuErrchk(cudaFree(deviceOutputData));
|
||||
gpuErrchk(cudaFree(deviceInputData));
|
||||
}
|
||||
@@ -47,6 +47,8 @@
|
||||
|
||||
// CHECK: #include <string>
|
||||
|
||||
// CHECK: #include "hipfft.h"
|
||||
|
||||
#include <cuda.h>
|
||||
|
||||
#include <memory>
|
||||
@@ -91,3 +93,5 @@
|
||||
#include "curand_uniform.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "cufft.h"
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
Copyright (c) 2015-Present 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* RUN: %t
|
||||
* HIT_END
|
||||
*/
|
||||
#include "hipClassKernel.h"
|
||||
|
||||
#ifdef ENABLE_OVERLOAD_OVERRIDE_TESTS
|
||||
__global__ void
|
||||
ovrdClassKernel(bool* result_ecd){
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
testOvrD tobj1;
|
||||
result_ecd[tid] = (tobj1.ovrdFunc1() == 30);
|
||||
}
|
||||
|
||||
void HipClassTests::TestForOverride(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
hipLaunchKernelGGL(ovrdClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
|
||||
|
||||
__global__ void
|
||||
ovldClassKernel(bool* result_ecd){
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
testFuncOvld tfo1;
|
||||
result_ecd[tid] = (tfo1.func1(10) == 20)
|
||||
&& (tfo1.func1(10,10) == 30);
|
||||
}
|
||||
|
||||
void HipClassTests::TestForOverload(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
hipLaunchKernelGGL(ovldClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FRIEND_TEST
|
||||
// check for friend
|
||||
__global__ void
|
||||
friendClassKernel(bool* result_ecd){
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
testFrndB tfb1;
|
||||
result_ecd[tid] = (tfb1.showA() == 10);
|
||||
}
|
||||
#endif
|
||||
|
||||
// check sizeof empty class is 1
|
||||
__global__ void
|
||||
emptyClassKernel(bool* result_ecd) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
testClassEmpty ob1,ob2;
|
||||
result_ecd[tid] = (sizeof(testClassEmpty) == 1)
|
||||
&& (&ob1 != &ob2);
|
||||
}
|
||||
|
||||
void HipClassTests::TestForEmptyClass(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
hipLaunchKernelGGL(emptyClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
|
||||
// tests for classes >8 bytes
|
||||
__global__ void
|
||||
sizeClassBKernel(bool* result_ecd) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
result_ecd[tid] = (sizeof(testSizeB) == 12)
|
||||
&& (sizeof(testSizeC) == 16)
|
||||
&& (sizeof(testSizeP1) == 6)
|
||||
&& (sizeof(testSizeP2) == 13)
|
||||
&& (sizeof(testSizeP3) == 8);
|
||||
}
|
||||
|
||||
void HipClassTests::TestForClassBSize(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
hipLaunchKernelGGL(sizeClassBKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
|
||||
__global__ void
|
||||
sizeClassKernel(bool* result_ecd) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
result_ecd[tid] = (sizeof(testSizeA) == 16)
|
||||
&& (sizeof(testSizeDerived) == 24)
|
||||
&& (sizeof(testSizeDerived2) == 20);
|
||||
}
|
||||
|
||||
void HipClassTests::TestForClassSize(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
hipLaunchKernelGGL(sizeClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_VIRTUAL_TESTS
|
||||
__global__ void
|
||||
sizeVirtualClassKernel(bool* result_ecd) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
result_ecd[tid] = (sizeof(testSizeDV) == 16)
|
||||
&& (sizeof(testSizeDerivedDV) == 16)
|
||||
&& (sizeof(testSizeVirtDerPack) == 24)
|
||||
&& (sizeof(testSizeVirtDer) == 24)
|
||||
&& (sizeof(testSizeDerMulti) == 48) ;
|
||||
}
|
||||
|
||||
void HipClassTests::TestForVirtualClassSize(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
hipLaunchKernelGGL(sizeVirtualClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
#endif
|
||||
|
||||
// check pass by value
|
||||
__global__ void
|
||||
passByValueKernel(testPassByValue obj, bool* result_ecd) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
result_ecd[tid] = (obj.exI == 10)
|
||||
&& (obj.exC == 'C');
|
||||
}
|
||||
|
||||
void HipClassTests::TestForPassByValue(void){
|
||||
bool *result_ecd,*result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
testPassByValue exObj;
|
||||
exObj.exI = 10;
|
||||
exObj.exC = 'C';
|
||||
hipLaunchKernelGGL(passByValueKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
exObj,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
|
||||
// check obj created with hipMalloc
|
||||
__global__ void
|
||||
mallocObjKernel(testPassByValue *obj, bool* result_ecd) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
result_ecd[tid] = (obj->exI == 100)
|
||||
&& (obj->exC == 'C');
|
||||
}
|
||||
|
||||
void HipClassTests::TestForMallocPassByValue(void){
|
||||
bool *result_ecd,*result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
|
||||
testPassByValue *exObjM;
|
||||
HIPCHECK(hipMalloc(&exObjM, sizeof(testPassByValue)));
|
||||
exObjM->exI = 100;
|
||||
exObjM->exC = 'C';
|
||||
hipLaunchKernelGGL(mallocObjKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
exObjM,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
|
||||
}
|
||||
|
||||
// check if constr and destr are accessible from kernel
|
||||
#ifdef ENABLE_DESTRUCTOR_TEST
|
||||
__global__ void
|
||||
testDeviceClassKernel() {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
testDeviceClass ob1;
|
||||
testDeviceClass ob2;
|
||||
ob2.iVar = 10;
|
||||
}
|
||||
|
||||
void HipClassTests::TestForConsrtDesrt(){
|
||||
testDeviceClass tDC;
|
||||
hipLaunchKernelGGL(testDeviceClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FRIEND_TEST
|
||||
void HipClassTests::TestForFriend(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
hipLaunchKernelGGL(friendClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool* HipClassTests::AllocateHostMemory(void){
|
||||
bool *result_ech;
|
||||
HIPCHECK(hipHostMalloc(&result_ech,
|
||||
NBOOL,
|
||||
hipHostMallocDefault));
|
||||
return result_ech;
|
||||
}
|
||||
|
||||
bool* HipClassTests::AllocateDeviceMemory(void){
|
||||
bool* result_ecd;
|
||||
HIPCHECK(hipMalloc(&result_ecd,
|
||||
NBOOL));
|
||||
HIPCHECK(hipMemset(result_ecd,
|
||||
false,
|
||||
NBOOL));
|
||||
return result_ecd;
|
||||
}
|
||||
|
||||
void HipClassTests::VerifyResult(bool* result_ech, bool* result_ecd){
|
||||
HIPCHECK(hipMemcpy(result_ech,
|
||||
result_ecd,
|
||||
BLOCKS*sizeof(bool),
|
||||
hipMemcpyDeviceToHost));
|
||||
// validation on host side
|
||||
for (int i = 0; i < BLOCKS; i++) {
|
||||
HIPASSERT(result_ech[i] == true);
|
||||
}
|
||||
}
|
||||
|
||||
void HipClassTests::FreeMem(bool* result_ech, bool* result_ecd){
|
||||
HIPCHECK(hipHostFree(result_ech));
|
||||
HIPCHECK(hipFree(result_ecd));
|
||||
}
|
||||
|
||||
int main(){
|
||||
HipClassTests classTests;
|
||||
classTests.TestForEmptyClass();
|
||||
test_passed(TestForEmptyClass);
|
||||
classTests.TestForClassBSize();
|
||||
test_passed(TestForClassBSize);
|
||||
classTests.TestForClassSize();
|
||||
test_passed(TestForClassSize);
|
||||
classTests.TestForPassByValue();
|
||||
test_passed(TestForPassByValue);
|
||||
|
||||
#ifdef ENABLE_OVERLOAD_OVERRIDE_TESTS
|
||||
classTests.TestForOverload();
|
||||
test_passed(TestForOverload);
|
||||
classTests.TestForOverride();
|
||||
test_passed(TestForOverride);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FRIEND_TEST
|
||||
classTests.TestForFriend();
|
||||
test_passed(TestForFriend);
|
||||
#endif
|
||||
|
||||
// classTests.TestForMallocPassByValue();
|
||||
// test_passed(TestForMallocPassByValue); #this test is crashing
|
||||
|
||||
#ifdef ENABLE_VIRTUAL_TESTS
|
||||
classTests.TestForVirtualClassSize();
|
||||
test_passed(TestForVirtualClassSize);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_DESTRUCTOR_TEST
|
||||
classTests.TestForConsrtDesrt();
|
||||
test_passed(TestForConsrtDesrt);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
Copyright (c) 2015-Present 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
#ifndef _COMPILER_HIPCLASSKERNEL_H_
|
||||
#define _COMPILER_HIPCLASSKERNEL_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
static const int BLOCKS = 512;
|
||||
static const int THREADS_PER_BLOCK = 1;
|
||||
static const int ENABLE_DESTRUCTOR_TEST = 0;
|
||||
static const int ENABLE_VIRTUAL_TESTS = 0;
|
||||
static const int ENABLE_FRIEND_TEST = 0;
|
||||
static const int ENABLE_OVERLAD_OVERRIDE_TESTS = 0;
|
||||
size_t NBOOL = BLOCKS * sizeof(bool);
|
||||
|
||||
#define test_passed(test_name) printf("%s %s PASSED!%s\n", KGRN, #test_name, KNRM);
|
||||
|
||||
#ifdef ENABLE_OVERLOAD_OVERRIDE_TESTS
|
||||
class testFuncOvld{
|
||||
public:
|
||||
int __host__ __device__ func1(int a){
|
||||
return a + 10;
|
||||
}
|
||||
|
||||
int __host__ __device__ func1(int a , int b){
|
||||
return a + b + 10;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class testOvrB{
|
||||
public:
|
||||
int __host__ __device__ ovrdFunc1(){
|
||||
return 10;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
class testOvrD: public testOvrB{
|
||||
public:
|
||||
int __host__ __device__ ovrdFunc1(){
|
||||
int x = testOvrB::ovrdFunc1();
|
||||
return x + 20;
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FRIEND_TEST
|
||||
class testFrndA{
|
||||
private:
|
||||
int fa = 10;
|
||||
public:
|
||||
friend class testFrndB;
|
||||
};
|
||||
|
||||
class testFrndB{
|
||||
public:
|
||||
__host__ __device__ int showA(){
|
||||
testFrndA x;
|
||||
return x.fa;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
class testClassEmpty {};
|
||||
|
||||
class testPassByValue{
|
||||
public:
|
||||
int exI;
|
||||
char exC;
|
||||
};
|
||||
|
||||
class testSizeA {
|
||||
public:
|
||||
float xa;
|
||||
int ia;
|
||||
double da;
|
||||
static char ca;
|
||||
};
|
||||
|
||||
class testSizeDerived : testSizeA {
|
||||
public:
|
||||
float fd;
|
||||
};
|
||||
|
||||
#pragma pack(push,4)
|
||||
class testSizeDerived2 : testSizeA {
|
||||
public:
|
||||
float fd;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
class testSizeB {
|
||||
public:
|
||||
char ab;
|
||||
int ib;
|
||||
char cb;
|
||||
};
|
||||
|
||||
#ifdef ENBABLE_VIRTUAL_TESTS
|
||||
class testSizeVirtDer : public virtual testSizeB {
|
||||
public:
|
||||
int ivd;
|
||||
};
|
||||
|
||||
class testSizeVirtDer1 : public virtual testSizeB {
|
||||
public:
|
||||
int ivd1;
|
||||
};
|
||||
|
||||
class testSizeDerMulti : public testSizeVirtDer, public testSizeVirtDer1 {
|
||||
public:
|
||||
int ivd2;
|
||||
};
|
||||
|
||||
#pragma pack(push,4)
|
||||
class testSizeVirtDerPack : public virtual testSizeB {
|
||||
public:
|
||||
int ivd;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
class testSizeC {
|
||||
public:
|
||||
char ac;
|
||||
int ic;
|
||||
int bc[2];
|
||||
};
|
||||
|
||||
#ifdef ENABLE_VIRTUAL_TESTS
|
||||
class testSizeDV {
|
||||
public:
|
||||
virtual void __host__ __device__ func1();
|
||||
private:
|
||||
int iDV;
|
||||
|
||||
};
|
||||
|
||||
class testSizeDerivedDV : testSizeDV {
|
||||
public:
|
||||
virtual void __host__ __device__ funcD1();
|
||||
private:
|
||||
int iDDV;
|
||||
};
|
||||
#endif
|
||||
|
||||
#pragma pack(push, 1)
|
||||
class testSizeP1 {
|
||||
public:
|
||||
char ap;
|
||||
int ip;
|
||||
char cp;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
class testSizeP2 {
|
||||
public:
|
||||
char ap1;
|
||||
int ip1;
|
||||
int bp1[2];
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 2)
|
||||
class testSizeP3 {
|
||||
public:
|
||||
char ap2;
|
||||
int ip2;
|
||||
char cp2;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef ENABLE_DESTRUCTOR_TEST
|
||||
class testDeviceClass {
|
||||
public:
|
||||
int iVar;
|
||||
__host__ __device__ testDeviceClass();
|
||||
__host__ __device__ testDeviceClass(int a);
|
||||
__host__ __device__ ~testDeviceClass();
|
||||
};
|
||||
|
||||
__host__ __device__
|
||||
testDeviceClass::testDeviceClass() {
|
||||
iVar = 5;
|
||||
}
|
||||
|
||||
__host__ __device__
|
||||
testDeviceClass::testDeviceClass(int a) {
|
||||
iVar = a;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _HIPCLASSKERNEL_H_
|
||||
|
||||
class HipClassTests{
|
||||
public:
|
||||
void TestForEmptyClass(void);
|
||||
void TestForClassBSize(void);
|
||||
void TestForClassSize(void);
|
||||
void TestForVirtualClassSize(void);
|
||||
void TestForPassByValue(void);
|
||||
void TestForMallocPassByValue(void);
|
||||
void TestForConsrtDesrt(void);
|
||||
void TestForOverload(void);
|
||||
void TestForOverride(void);
|
||||
|
||||
bool* AllocateHostMemory(void);
|
||||
bool* AllocateDeviceMemory(void);
|
||||
void VerifyResult(bool* result_ech, bool* result_ecd);
|
||||
void FreeMem(bool* result_ech, bool* result_ecd);
|
||||
};
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* RUN: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#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 LEN 512
|
||||
#define SIZE 2048
|
||||
|
||||
struct TestClock {
|
||||
|
||||
static __global__ void kernel1(int* Ad) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Ad[tid] = clock() + clock64() + __clock() + __clock64();
|
||||
}
|
||||
|
||||
static __global__ void kernel2(int* Ad) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Ad[tid] = clock() + clock64() + __clock() + __clock64() - Ad[tid];
|
||||
}
|
||||
|
||||
void run() {
|
||||
int *A, *Ad;
|
||||
A = new int[LEN];
|
||||
for (unsigned i = 0; i < LEN; i++) {
|
||||
A[i] = 0;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&Ad, SIZE));
|
||||
hipLaunchKernelGGL(kernel1, dim3(1, 1, 1), dim3(LEN, 1, 1), 0, 0, Ad);
|
||||
hipLaunchKernelGGL(kernel2, dim3(1, 1, 1), dim3(LEN, 1, 1), 0, 0, Ad);
|
||||
HIP_ASSERT(hipMemcpy(A, Ad, SIZE, hipMemcpyDeviceToHost));
|
||||
|
||||
for (unsigned i = 0; i < LEN; i++) {
|
||||
assert(0 != A[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
TestClock().run();
|
||||
passed();
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* RUN: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
// Test include math_functions.h then hip_runtime.h.
|
||||
// Incorrect implementation causes compilation failure due to conflict
|
||||
// declartions.
|
||||
|
||||
#include <hip/math_functions.h>
|
||||
|
||||
// Test __HIP_DEVICE_COMPILE__ is defined after math_functions.h
|
||||
// is included.
|
||||
//
|
||||
__device__ __host__ inline void throw_std_bad_alloc()
|
||||
{
|
||||
#ifndef __HIP_DEVICE_COMPILE__
|
||||
throw std::bad_alloc();
|
||||
#else
|
||||
std::size_t huge = static_cast<std::size_t>(-1);
|
||||
new int[huge];
|
||||
#endif
|
||||
}
|
||||
|
||||
// Test __HIP_ARCH_HAS_WARP_FUNNEL_SHIFT__ and __HIP_ARCH_HAS_DYNAMIC_PARALLEL__
|
||||
// is defined. Eigen HIP/hcc/Half.h __ldg depends on this.
|
||||
#if !defined(__HIP_ARCH_HAS_WARP_FUNNEL_SHIFT__) || \
|
||||
!defined(__HIP_ARCH_HAS_DYNAMIC_PARALLEL__)
|
||||
#error \
|
||||
"__HIP_ARCH_HAS_WARP_FUNNEL_SHIFT__ or __HIP_ARCH_HAS_DYNAMIC_PARALLEL__ not defined"
|
||||
#endif
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include "test_common.h"
|
||||
|
||||
__global__ void FloatMathPrecise() {
|
||||
int iX;
|
||||
float fX, fY;
|
||||
|
||||
acosf(1.0f);
|
||||
acoshf(1.0f);
|
||||
asinf(0.0f);
|
||||
asinhf(0.0f);
|
||||
atan2f(0.0f, 1.0f);
|
||||
atanf(0.0f);
|
||||
atanhf(0.0f);
|
||||
cbrtf(0.0f);
|
||||
fX = ceilf(0.0f);
|
||||
fX = copysignf(1.0f, -2.0f);
|
||||
cosf(0.0f);
|
||||
coshf(0.0f);
|
||||
cospif(0.0f);
|
||||
cyl_bessel_i0f(0.0f);
|
||||
cyl_bessel_i1f(0.0f);
|
||||
erfcf(0.0f);
|
||||
erfcinvf(2.0f);
|
||||
erfcxf(0.0f);
|
||||
erff(0.0f);
|
||||
erfinvf(1.0f);
|
||||
exp10f(0.0f);
|
||||
exp2f(0.0f);
|
||||
expf(0.0f);
|
||||
expm1f(0.0f);
|
||||
fX = fabsf(1.0f);
|
||||
fdimf(1.0f, 0.0f);
|
||||
fdividef(0.0f, 1.0f);
|
||||
fX = floorf(0.0f);
|
||||
fmaf(1.0f, 2.0f, 3.0f);
|
||||
fX = fmaxf(0.0f, 0.0f);
|
||||
fX = fminf(0.0f, 0.0f);
|
||||
fmodf(0.0f, 1.0f);
|
||||
frexpf(0.0f, &iX);
|
||||
hypotf(1.0f, 0.0f);
|
||||
ilogbf(1.0f);
|
||||
isfinite(0.0f);
|
||||
fX = isinf(0.0f);
|
||||
fX = isnan(0.0f);
|
||||
j0f(0.0f);
|
||||
j1f(0.0f);
|
||||
jnf(-1.0f, 1.0f);
|
||||
ldexpf(0.0f, 0);
|
||||
lgammaf(1.0f);
|
||||
llrintf(0.0f);
|
||||
llroundf(0.0f);
|
||||
log10f(1.0f);
|
||||
log1pf(-1.0f);
|
||||
log2f(1.0f);
|
||||
logbf(1.0f);
|
||||
logf(1.0f);
|
||||
lrintf(0.0f);
|
||||
lroundf(0.0f);
|
||||
modff(0.0f, &fX);
|
||||
fX = nanf("1");
|
||||
fX = nearbyintf(0.0f);
|
||||
nextafterf(0.0f, 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);
|
||||
powf(1.0f, 0.0f);
|
||||
rcbrtf(1.0f);
|
||||
remainderf(2.0f, 1.0f);
|
||||
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);
|
||||
fY = roundf(0.0f);
|
||||
rsqrtf(1.0f);
|
||||
scalblnf(0.0f, 1);
|
||||
scalbnf(0.0f, 1);
|
||||
signbit(1.0f);
|
||||
sincosf(0.0f, &fX, &fY);
|
||||
sincospif(0.0f, &fX, &fY);
|
||||
sinf(0.0f);
|
||||
sinhf(0.0f);
|
||||
sinpif(0.0f);
|
||||
sqrtf(0.0f);
|
||||
tanf(0.0f);
|
||||
tanhf(0.0f);
|
||||
tgammaf(2.0f);
|
||||
fY = truncf(0.0f);
|
||||
y0f(1.0f);
|
||||
y1f(1.0f);
|
||||
ynf(1, 1.0f);
|
||||
}
|
||||
|
||||
int main() {
|
||||
hipLaunchKernelGGL(FloatMathPrecise, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0);
|
||||
passed();
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* RUN: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#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 LEN 512
|
||||
#define SIZE 2048
|
||||
|
||||
struct TestPlacementNew {
|
||||
class A {
|
||||
public:
|
||||
__device__ A() {
|
||||
a = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
}
|
||||
private:
|
||||
int a;
|
||||
};
|
||||
|
||||
static __global__ void kernel(int* Ad) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
new(Ad+tid) A();
|
||||
}
|
||||
|
||||
void run() {
|
||||
int *A, *Ad;
|
||||
A = new int[LEN];
|
||||
for (unsigned i = 0; i < LEN; i++) {
|
||||
A[i] = 0;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&Ad, SIZE));
|
||||
hipLaunchKernelGGL(kernel, dim3(1, 1, 1), dim3(LEN, 1, 1), 0, 0, Ad);
|
||||
HIP_ASSERT(hipMemcpy(A, Ad, SIZE, hipMemcpyDeviceToHost));
|
||||
|
||||
for (unsigned i = 0; i < LEN; i++) {
|
||||
assert(i == A[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
TestPlacementNew().run();
|
||||
passed();
|
||||
}
|
||||
@@ -86,28 +86,15 @@ int main(int argc, char* argv[]) {
|
||||
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;
|
||||
#else
|
||||
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");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#else
|
||||
if (anycount == 0 && allcount == 1)
|
||||
printf("PASSED\n");
|
||||
else {
|
||||
printf("FAILED\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp EXCLUDE_HIP_PLATFORM nvcc
|
||||
* RUN: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
#define TEST_DEBUG (0)
|
||||
|
||||
|
||||
// CPU implementation of bitextract
|
||||
template <typename T>
|
||||
T bit_extract(T src0, unsigned int src1, unsigned int src2) {
|
||||
unsigned int bits = sizeof(T) * 8;
|
||||
T offset = src1 & (bits - 1);
|
||||
T width = src2 & (bits - 1);
|
||||
if (width == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return (src0 << (bits - width - offset)) >> (bits - width);
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void HIP_kernel(hipLaunchParm lp,
|
||||
unsigned int* out32, unsigned int* in32_0,
|
||||
unsigned int* in32_1, unsigned int* in32_2,
|
||||
unsigned long long int* out64, unsigned long long int* in64_0,
|
||||
unsigned int* in64_1, unsigned int* in64_2) {
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
|
||||
out32[x] = __bitextract_u32(in32_0[x], in32_1[x], in32_2[x]);
|
||||
out64[x] = __bitextract_u64(in64_0[x], in64_1[x], in64_2[x]);
|
||||
}
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
unsigned int* hostOut32;
|
||||
unsigned int* hostSrc032;
|
||||
unsigned int* hostSrc132;
|
||||
unsigned int* hostSrc232;
|
||||
unsigned long long int* hostOut64;
|
||||
unsigned long long int* hostSrc064;
|
||||
unsigned int* hostSrc164;
|
||||
unsigned int* hostSrc264;
|
||||
|
||||
unsigned int* deviceOut32;
|
||||
unsigned int* deviceSrc032;
|
||||
unsigned int* deviceSrc132;
|
||||
unsigned int* deviceSrc232;
|
||||
unsigned long long int* deviceOut64;
|
||||
unsigned long long int* deviceSrc064;
|
||||
unsigned int* deviceSrc164;
|
||||
unsigned int* deviceSrc264;
|
||||
|
||||
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;
|
||||
|
||||
unsigned int wave_size = devProp.warpSize;
|
||||
unsigned int num_waves_per_block = 2;
|
||||
unsigned int num_threads_per_block = wave_size * num_waves_per_block;
|
||||
unsigned int num_blocks = 2;
|
||||
unsigned int NUM = num_threads_per_block * num_blocks;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostOut32 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc032 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc132 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc232 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
|
||||
hostOut64 = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
hostSrc064 = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
hostSrc164 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc264 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
|
||||
// initialize the input data
|
||||
std::random_device rd;
|
||||
std::uniform_int_distribution<uint32_t> uint32_src0_dist;
|
||||
std::uniform_int_distribution<uint32_t> uint32_src12_dist(0,31);
|
||||
std::uniform_int_distribution<uint64_t> uint64_src0_dist;
|
||||
std::uniform_int_distribution<uint32_t> uint64_src12_dist(0,63);
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostOut32[i] = 0;
|
||||
hostSrc032[i] = uint32_src0_dist(rd);
|
||||
hostSrc132[i] = uint32_src12_dist(rd);
|
||||
hostSrc232[i] = uint32_src12_dist(rd);
|
||||
hostOut64[i] = 0;
|
||||
hostSrc064[i] = uint64_src0_dist(rd);
|
||||
hostSrc164[i] = uint64_src12_dist(rd);
|
||||
hostSrc264[i] = uint64_src12_dist(rd);
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceOut32, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc032, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc132, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc232, NUM * sizeof(unsigned int)));
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceOut64, NUM * sizeof(unsigned long long int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc064, NUM * sizeof(unsigned long long int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc164, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc264, NUM * sizeof(unsigned int)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc032, hostSrc032, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc132, hostSrc132, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc232, hostSrc232, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc064, hostSrc064, NUM * sizeof(unsigned long long int),
|
||||
hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc164, hostSrc164, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc264, hostSrc264, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
|
||||
|
||||
hipLaunchKernel(HIP_kernel, dim3(num_blocks), dim3(num_threads_per_block),
|
||||
0, 0,
|
||||
deviceOut32, deviceSrc032, deviceSrc132, deviceSrc232,
|
||||
deviceOut64, deviceSrc064, deviceSrc164, deviceSrc264);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostOut32, deviceOut32, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(hostOut64, deviceOut64,
|
||||
NUM * sizeof(unsigned long long int), hipMemcpyDeviceToHost));
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostOut32[i] != bit_extract<uint32_t>(hostSrc032[i], hostSrc132[i], hostSrc232[i])) {
|
||||
errors++;
|
||||
#if TEST_DEBUG
|
||||
cout << "device: " << hostOut32[i] << " host: "
|
||||
<< bit_extract<uint32_t>(hostSrc032[i], hostSrc132[i], hostSrc232[i])
|
||||
<< " " << hostSrc032[i] << " " << hostSrc132[i] << " " << hostSrc232[i] << "\n";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "__bitextract_u32() FAILED\n" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__bitextract_u32() checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostOut64[i] != bit_extract<uint64_t>(hostSrc064[i], hostSrc164[i], hostSrc264[i])) {
|
||||
errors++;
|
||||
#if TEST_DEBUG
|
||||
cout << "device: " << hostOut64[i] << " host: "
|
||||
<< bit_extract<uint64_t>(hostSrc064[i], hostSrc164[i], hostSrc264[i])
|
||||
<< " " << hostSrc064[i] << " " << hostSrc164[i] << " " << hostSrc264[i] << "\n";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "__bitextract_u64() FAILED" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__bitextract_u64() checked!" << endl;
|
||||
}
|
||||
|
||||
cout << "__bitextract_u32() and __bitextract_u64() PASSED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(deviceOut32));
|
||||
HIP_ASSERT(hipFree(deviceSrc032));
|
||||
HIP_ASSERT(hipFree(deviceSrc132));
|
||||
HIP_ASSERT(hipFree(deviceSrc232));
|
||||
HIP_ASSERT(hipFree(deviceOut64));
|
||||
HIP_ASSERT(hipFree(deviceSrc064));
|
||||
HIP_ASSERT(hipFree(deviceSrc164));
|
||||
HIP_ASSERT(hipFree(deviceSrc264));
|
||||
|
||||
free(hostOut32);
|
||||
free(hostSrc032);
|
||||
free(hostSrc132);
|
||||
free(hostSrc232);
|
||||
free(hostOut64);
|
||||
free(hostSrc064);
|
||||
free(hostSrc164);
|
||||
free(hostSrc264);
|
||||
|
||||
return errors;
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp EXCLUDE_HIP_PLATFORM nvcc
|
||||
* RUN: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
#define TEST_DEBUG (0)
|
||||
|
||||
|
||||
// CPU implementation of bitinsert
|
||||
template <typename T>
|
||||
T bit_insert(T src0, T src1, unsigned int src2, unsigned int src3) {
|
||||
unsigned int bits = sizeof(T) * 8;
|
||||
T offset = src2 & (bits - 1);
|
||||
T width = src3 & (bits - 1);
|
||||
T mask = (1 << width) - 1;
|
||||
return ((src0 & ~(mask << offset)) | ((src1 & mask) << offset));
|
||||
}
|
||||
|
||||
__global__ void HIP_kernel(hipLaunchParm lp, unsigned int* out32,
|
||||
unsigned int* in32_0, unsigned int* in32_1,
|
||||
unsigned int* in32_2, unsigned int* in32_3,
|
||||
unsigned long long int* out64, unsigned long long int* in64_0,
|
||||
unsigned long long int* in64_1, unsigned int* in64_2,
|
||||
unsigned int* in64_3) {
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
|
||||
out32[x] = __bitinsert_u32(in32_0[x], in32_1[x], in32_2[x], in32_3[x]);
|
||||
out64[x] = __bitinsert_u64(in64_0[x], in64_1[x], in64_2[x], in64_3[x]);
|
||||
}
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
unsigned int* hostOut32;
|
||||
unsigned int* hostSrc032;
|
||||
unsigned int* hostSrc132;
|
||||
unsigned int* hostSrc232;
|
||||
unsigned int* hostSrc332;
|
||||
unsigned long long int* hostOut64;
|
||||
unsigned long long int* hostSrc064;
|
||||
unsigned long long int* hostSrc164;
|
||||
unsigned int* hostSrc264;
|
||||
unsigned int* hostSrc364;
|
||||
|
||||
unsigned int* deviceOut32;
|
||||
unsigned int* deviceSrc032;
|
||||
unsigned int* deviceSrc132;
|
||||
unsigned int* deviceSrc232;
|
||||
unsigned int* deviceSrc332;
|
||||
unsigned long long int* deviceOut64;
|
||||
unsigned long long int* deviceSrc064;
|
||||
unsigned long long int* deviceSrc164;
|
||||
unsigned int* deviceSrc264;
|
||||
unsigned int* deviceSrc364;
|
||||
|
||||
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;
|
||||
|
||||
unsigned int wave_size = devProp.warpSize;
|
||||
unsigned int num_waves_per_block = 2;
|
||||
unsigned int num_threads_per_block = wave_size * num_waves_per_block;
|
||||
unsigned int num_blocks = 2;
|
||||
unsigned int NUM = num_threads_per_block * num_blocks;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostOut32 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc032 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc132 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc232 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc332 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
|
||||
hostOut64 = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
hostSrc064 = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
hostSrc164 = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
hostSrc264 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc364 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
|
||||
// initialize the input data
|
||||
std::random_device rd;
|
||||
std::uniform_int_distribution<uint32_t> uint32_src01_dist;
|
||||
std::uniform_int_distribution<uint32_t> uint32_src23_dist(0,31);
|
||||
std::uniform_int_distribution<uint64_t> uint64_src01_dist;
|
||||
std::uniform_int_distribution<uint32_t> uint64_src23_dist(0,63);
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostOut32[i] = 0;
|
||||
hostSrc032[i] = uint32_src01_dist(rd);
|
||||
hostSrc132[i] = uint32_src01_dist(rd);
|
||||
hostSrc232[i] = uint32_src23_dist(rd);
|
||||
hostSrc232[i] = uint32_src23_dist(rd);
|
||||
hostOut64[i] = 0;
|
||||
hostSrc064[i] = uint64_src01_dist(rd);
|
||||
hostSrc164[i] = uint64_src01_dist(rd);
|
||||
hostSrc264[i] = uint64_src23_dist(rd);
|
||||
hostSrc264[i] = uint64_src23_dist(rd);
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceOut32, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc032, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc132, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc232, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc332, NUM * sizeof(unsigned int)));
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceOut64, NUM * sizeof(unsigned long long int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc064, NUM * sizeof(unsigned long long int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc164, NUM * sizeof(unsigned long long int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc264, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc364, NUM * sizeof(unsigned int)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc032, hostSrc032, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc132, hostSrc132, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc232, hostSrc232, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc332, hostSrc332, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc064, hostSrc064, NUM * sizeof(unsigned long long int),
|
||||
hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc164, hostSrc164, NUM * sizeof(unsigned long long int),
|
||||
hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc264, hostSrc264, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc364, hostSrc364, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
|
||||
|
||||
hipLaunchKernel(HIP_kernel, dim3(num_blocks), dim3(num_threads_per_block),
|
||||
0, 0,
|
||||
deviceOut32, deviceSrc032, deviceSrc132, deviceSrc232, deviceSrc332,
|
||||
deviceOut64, deviceSrc064, deviceSrc164, deviceSrc264, deviceSrc364);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostOut32, deviceOut32, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(hostOut64, deviceOut64,
|
||||
NUM * sizeof(unsigned long long int), hipMemcpyDeviceToHost));
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostOut32[i] != bit_insert<uint32_t>(hostSrc032[i], hostSrc132[i],
|
||||
hostSrc232[i], hostSrc332[i])) {
|
||||
errors++;
|
||||
#if TEST_DEBUG
|
||||
cout << "device: " << hostOut32[i] << " host: "
|
||||
<< bit_insert<uint32_t>(hostSrc032[i], hostSrc132[i], hostSrc232[i], hostSrc332[i])
|
||||
<< " " << hostSrc032[i] << " " << hostSrc132[i] << " " << hostSrc232[i]
|
||||
<< " " << hostSrc332[i] << "\n";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "__bitinsert_u32() FAILED\n" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__bitinsert_u32() checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostOut64[i] != bit_insert<uint64_t>(hostSrc064[i], hostSrc164[i],
|
||||
hostSrc264[i], hostSrc364[i])) {
|
||||
errors++;
|
||||
#if TEST_DEBUG
|
||||
cout << "device: " << hostOut64[i] << " host: "
|
||||
<< bit_insert<uint64_t>(hostSrc064[i], hostSrc164[i], hostSrc264[i], hostSrc364[i])
|
||||
<< " " << hostSrc064[i] << " " << hostSrc164[i] << " " << hostSrc264[i]
|
||||
<< " " << hostSrc364[i] << "\n";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "__bitinsert_u64() FAILED" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__bitinsert_u64() checked!" << endl;
|
||||
}
|
||||
|
||||
cout << "__bitinsert_u32() and __bitinsert_u64() PASSED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(deviceOut32));
|
||||
HIP_ASSERT(hipFree(deviceSrc032));
|
||||
HIP_ASSERT(hipFree(deviceSrc132));
|
||||
HIP_ASSERT(hipFree(deviceSrc232));
|
||||
HIP_ASSERT(hipFree(deviceSrc332));
|
||||
HIP_ASSERT(hipFree(deviceOut64));
|
||||
HIP_ASSERT(hipFree(deviceSrc064));
|
||||
HIP_ASSERT(hipFree(deviceSrc164));
|
||||
HIP_ASSERT(hipFree(deviceSrc264));
|
||||
HIP_ASSERT(hipFree(deviceSrc364));
|
||||
|
||||
free(hostOut32);
|
||||
free(hostSrc032);
|
||||
free(hostSrc132);
|
||||
free(hostSrc232);
|
||||
free(hostSrc332);
|
||||
free(hostOut64);
|
||||
free(hostSrc064);
|
||||
free(hostSrc164);
|
||||
free(hostSrc264);
|
||||
free(hostSrc364);
|
||||
|
||||
return errors;
|
||||
}
|
||||
@@ -45,12 +45,7 @@ THE SOFTWARE.
|
||||
|
||||
unsigned int firstbit_u32(unsigned int a) {
|
||||
if (a == 0) {
|
||||
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
|
||||
|
||||
return -1;
|
||||
#else
|
||||
return 32;
|
||||
#endif
|
||||
}
|
||||
unsigned int pos = 0;
|
||||
while ((int)a > 0) {
|
||||
@@ -62,11 +57,7 @@ unsigned int firstbit_u32(unsigned int a) {
|
||||
|
||||
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;
|
||||
#endif
|
||||
}
|
||||
unsigned int pos = 0;
|
||||
while ((long long int)a > 0) {
|
||||
@@ -76,6 +67,21 @@ unsigned int firstbit_u64(unsigned long long int a) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
// Check implicit conversion will not cause ambiguity.
|
||||
__device__ void test_ambiguity() {
|
||||
short s;
|
||||
unsigned short us;
|
||||
float f;
|
||||
int i;
|
||||
unsigned int ui;
|
||||
__clz(f);
|
||||
__clz(s);
|
||||
__clz(us);
|
||||
__clzll(f);
|
||||
__clzll(i);
|
||||
__clzll(ui);
|
||||
}
|
||||
|
||||
__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;
|
||||
|
||||
@@ -49,21 +49,13 @@ THE SOFTWARE.
|
||||
template <typename T>
|
||||
int lastbit(T a) {
|
||||
if (a == 0)
|
||||
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
|
||||
return -1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
int pos = 1;
|
||||
while ((a & 1) != 1) {
|
||||
a >>= 1;
|
||||
pos++;
|
||||
}
|
||||
#if defined(__HIP_PLATFORM_HCC__) && !defined(NVCC_COMPAT)
|
||||
return pos - 1;
|
||||
#else
|
||||
return pos;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,10 @@ int getDeviceNumber() {
|
||||
string str;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
if (!(in = popen("./directed_tests/hipEnvVar -c", "r"))) {
|
||||
return 1;
|
||||
// Check at same level
|
||||
if (!(in = popen("./hipEnvVar -c", "r"))) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
while (fgets(buff, 512, in) != NULL) {
|
||||
cout << buff;
|
||||
@@ -54,7 +57,11 @@ void getDevicePCIBusNumRemote(int deviceID, char* pciBusID) {
|
||||
str += std::to_string(deviceID);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
if (!(in = popen(str.c_str(), "r"))) {
|
||||
exit(1);
|
||||
// Check at same level
|
||||
if (!(in = popen("./hipEnvVar -d ", "r"))) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
while (fgets(pciBusID, 100, in) != NULL) {
|
||||
cout << pciBusID;
|
||||
|
||||
@@ -170,8 +170,8 @@ void runTests(int64_t numElements) {
|
||||
// for (int waitStart=0; waitStart<2; waitStart++) {
|
||||
for (int waitStart = 1; waitStart >= 0; waitStart--) {
|
||||
unsigned W = waitStart ? 0x1000 : 0;
|
||||
test(W | 0x01, C_d, C_h, numElements, 0, waitStart, syncNone);
|
||||
test(W | 0x02, C_d, C_h, numElements, stream, waitStart, syncNone);
|
||||
test(W | 0x01, C_d, C_h, numElements, 0, 0, syncNone);
|
||||
test(W | 0x02, C_d, C_h, numElements, stream, 0, syncNone);
|
||||
test(W | 0x04, C_d, C_h, numElements, 0, waitStart, syncStream);
|
||||
test(W | 0x08, C_d, C_h, numElements, stream, waitStart, syncStream);
|
||||
test(W | 0x10, C_d, C_h, numElements, 0, waitStart, syncStopEvent);
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
Copyright (c) 2015-Present 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* RUN: %t
|
||||
* HIT_END
|
||||
*/
|
||||
#include <hip/hip_runtime.h>
|
||||
#include "test_common.h"
|
||||
|
||||
using namespace std;
|
||||
#define R 8 //rows, height
|
||||
#define C 8 //columns, width
|
||||
|
||||
texture<int, hipTextureType2D,hipReadModeElementType> tex;
|
||||
|
||||
bool runTest(void);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
bool testResult=runTest();
|
||||
|
||||
if (testResult) {
|
||||
passed();
|
||||
} else {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
bool runTest()
|
||||
{
|
||||
int val[R][C],i,j;
|
||||
size_t offset;
|
||||
|
||||
for(i=0;i<R;i++)
|
||||
for(j=0;j<C;j++)
|
||||
{
|
||||
val[i][j]=(i+1)*(j+1);
|
||||
}
|
||||
hipChannelFormatDesc chan_desc=hipCreateChannelDesc(32,0,0,0,hipChannelFormatKindSigned);
|
||||
hipArray *hipArray;
|
||||
HIPCHECK(hipMallocArray(&hipArray, &chan_desc,C,R,0));
|
||||
|
||||
HIPCHECK(hipMemcpyToArray(hipArray,0,0, val, R*C*sizeof(int), hipMemcpyHostToDevice));
|
||||
|
||||
tex.addressMode[0]=hipAddressModeWrap;
|
||||
tex.addressMode[1]=hipAddressModeWrap;
|
||||
tex.filterMode=hipFilterModePoint;
|
||||
tex.normalized=0;
|
||||
|
||||
HIPCHECK(hipBindTextureToArray(&tex, hipArray, &chan_desc));
|
||||
HIPCHECK(hipGetTextureAlignmentOffset(&offset,&tex));
|
||||
HIPCHECK(hipUnbindTexture(&tex));
|
||||
HIPCHECK(hipFreeArray(hipArray));
|
||||
if(offset != 0)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Copyright (c) 2015-Present 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* RUN: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include "test_common.h"
|
||||
|
||||
using namespace std;
|
||||
#define R 8 //rows, height
|
||||
#define C 8 //columns, width
|
||||
|
||||
bool runTest(void);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
bool testResult=runTest();
|
||||
|
||||
if (testResult) {
|
||||
passed();
|
||||
} else {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
bool runTest()
|
||||
{
|
||||
bool testResult=true;
|
||||
hipChannelFormatDesc chan_test,chan_desc=hipCreateChannelDesc(32,0,0,0,hipChannelFormatKindSigned);
|
||||
hipArray *hipArray;
|
||||
HIPCHECK(hipMallocArray(&hipArray, &chan_desc,C,R,0));
|
||||
HIPCHECK(hipGetChannelDesc(&chan_test,hipArray));
|
||||
|
||||
if((chan_test.x == 32)&&(chan_test.y == 0)&&(chan_test.z == 0)&&(chan_test.f == 0))
|
||||
testResult=true;
|
||||
else
|
||||
testResult=false;
|
||||
|
||||
HIPCHECK(hipFreeArray(hipArray));
|
||||
return testResult;
|
||||
}
|
||||
Reference in New Issue
Block a user