Merge branch 'master' into support-malloc
このコミットが含まれているのは:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする