Re-sync with upstream.

[ROCm/clr commit: 602280eb8b]
This commit is contained in:
Alex Voicu
2018-10-18 12:27:03 +01:00
103 changed files with 1478 additions and 1308 deletions
@@ -28,7 +28,7 @@ THE SOFTWARE.
const int NN = 1 << 21;
__global__ void kernel(hipLaunchParm lp, float* x, float* y, int n) {
__global__ void kernel(float* x, float* y, int n) {
int tid = threadIdx.x;
if (tid < 1) {
for (int i = 0; i < n; i++) {
@@ -38,7 +38,7 @@ __global__ void kernel(hipLaunchParm lp, float* x, float* y, int n) {
}
}
__global__ void nKernel(hipLaunchParm lp, float* y) {
__global__ void nKernel(float* y) {
int tid = threadIdx.x;
y[tid] = y[tid] + 1.0f;
}
@@ -55,8 +55,8 @@ int main() {
for (int i = 0; i < num_streams; i++) {
HIPCHECK(hipStreamCreate(&streams[i]));
HIPCHECK(hipMalloc(&data[i], NN * sizeof(float)));
hipLaunchKernel(HIP_KERNEL_NAME(kernel), dim3(1), dim3(1), 0, streams[i], data[i], xd, N);
hipLaunchKernel(HIP_KERNEL_NAME(nKernel), dim3(1), dim3(1), 0, 0, yd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(kernel), dim3(1), dim3(1), 0, streams[i], data[i], xd, N);
hipLaunchKernelGGL(HIP_KERNEL_NAME(nKernel), dim3(1), dim3(1), 0, 0, yd);
}
HIPCHECK(hipMemcpy(&x, xd, sizeof(float), hipMemcpyDeviceToHost));
@@ -30,7 +30,7 @@ THE SOFTWARE.
const int NN = 1 << 21;
__global__ void kernel(hipLaunchParm lp, float* x, float* y, int n) {
__global__ void kernel(float* x, float* y, int n) {
int tid = threadIdx.x;
if (tid < 1) {
for (int i = 0; i < n; i++) {
@@ -40,7 +40,7 @@ __global__ void kernel(hipLaunchParm lp, float* x, float* y, int n) {
}
}
__global__ void nKernel(hipLaunchParm lp, float* y) {
__global__ void nKernel(float* y) {
int tid = threadIdx.x;
y[tid] = y[tid] + 1.0f;
}
@@ -57,8 +57,8 @@ int main() {
for (int i = 0; i < num_streams; i++) {
HIPCHECK(hipStreamCreate(&streams[i]));
HIPCHECK(hipMalloc(&data[i], NN * sizeof(float)));
hipLaunchKernel(HIP_KERNEL_NAME(kernel), dim3(1), dim3(1), 0, streams[i], data[i], xd, N);
hipLaunchKernel(HIP_KERNEL_NAME(nKernel), dim3(1), dim3(1), 0, 0, yd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(kernel), dim3(1), dim3(1), 0, streams[i], data[i], xd, N);
hipLaunchKernelGGL(HIP_KERNEL_NAME(nKernel), dim3(1), dim3(1), 0, 0, yd);
}
HIPCHECK(hipMemcpy(&x, xd, sizeof(float), hipMemcpyDeviceToHost));
@@ -37,7 +37,7 @@ int p_db = 0;
using namespace std;
template <typename T>
__global__ void vectorADDRepeat(hipLaunchParm lp, const T* A_d, const T* B_d, T* C_d, size_t NELEM,
__global__ void vectorADDRepeat(const T* A_d, const T* B_d, T* C_d, size_t NELEM,
int repeat) {
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x;
@@ -117,7 +117,7 @@ void Streamer<T>::enqueAsync() {
printf("testing: %s numElements=%zu size=%6.2fMB\n", __func__, _numElements,
_numElements * sizeof(T) / 1024.0 / 1024.0);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, _numElements);
hipLaunchKernel(vectorADDRepeat, dim3(blocks), dim3(threadsPerBlock), 0, _stream,
hipLaunchKernelGGL(vectorADDRepeat, dim3(blocks), dim3(threadsPerBlock), 0, _stream,
static_cast<const T*>(_A_d), static_cast<const T*>(_B_d), _C_d, _numElements,
p_repeat);
}
@@ -210,7 +210,7 @@ int main(int argc, char* argv[]) {
// Dispatch to NULL stream, should wait for prior async activity to complete before
// beginning:
hipLaunchKernel(vectorADDRepeat, dim3(blocks), dim3(threadsPerBlock), 0,
hipLaunchKernelGGL(vectorADDRepeat, dim3(blocks), dim3(threadsPerBlock), 0,
0 /*nullstream*/, static_cast<const int*>(lastStreamer->_C_d),
static_cast<const int*>(lastStreamer->_C_d), nullStreamer->_C_d,
numElements, 1 /*repeat*/);
@@ -246,7 +246,7 @@ int main(int argc, char* argv[]) {
// Dispatch to NULL stream, should wait for prior async activity to complete before
// beginning:
hipLaunchKernel(vectorADDRepeat, dim3(blocks), dim3(threadsPerBlock), 0,
hipLaunchKernelGGL(vectorADDRepeat, dim3(blocks), dim3(threadsPerBlock), 0,
0 /*nullstream*/, static_cast<const int*>(lastStreamer->_C_d),
static_cast<const int*>(lastStreamer->_C_d), nullStreamer->_C_d,
numElements, 1 /*repeat*/);
@@ -72,7 +72,7 @@ void D2H(T* Dst, T* Src, size_t size) {
}
template <typename T>
__global__ void Inc(hipLaunchParm lp, T* In) {
__global__ void Inc(T* In) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
In[tx] = In[tx] + 1;
}
@@ -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
* RUN: %t
* HIT_END
*/
#include "hip/hip_runtime.h"
#include "test_common.h"
#define MEMCPYSIZE 64*1024*1024
#define NUMITERS 2
#define GRIDSIZE 1024
#define BLOCKSIZE 256
// helper rountine to initialize memory
template <typename T>
void mem_init(T* buf, size_t n)
{
for (int i = 0; i < n; i++)
{
buf[i] = i;
}
}
// kernel to copy n elements from src to dst
template <typename T>
__global__ void memcpy_kernel(T* dst, T* src, size_t n)
{
int num = gridDim.x * blockDim.x;
int id = blockDim.x * blockIdx.x + threadIdx.x;
for (int i = id; i < n; i += num)
{
dst[i] = src[i];
}
}
template <typename T>
void runTest()
{
size_t size = NUMITERS*MEMCPYSIZE;
// get the range of priorities available
#define OP(x) \
int priority_##x; \
bool enable_priority_##x = false;
OP(low)
OP(normal)
OP(high)
#undef OP
HIPCHECK(hipDeviceGetStreamPriorityRange(&priority_low, &priority_high));
printf("HIP stream priority range - low: %d to high: %d\n", priority_low, priority_high);
// Check if priorities are indeed supported
if ((priority_low - priority_high) == 0) { passed(); }
// Enable/disable priorities based on number of available priority levels
enable_priority_low = true;
enable_priority_high = true;
if ((priority_low - priority_high) > 1) enable_priority_normal = true;
if (enable_priority_normal) priority_normal = ((priority_low - priority_high) / 2);
// create streams with highest and lowest available priorities
#define OP(x) \
hipStream_t stream_##x; \
if (enable_priority_##x) { \
HIPCHECK(hipStreamCreateWithPriority(&stream_##x, hipStreamDefault, priority_##x)); \
}
OP(low)
OP(normal)
OP(high)
#undef OP
// allocate and initialise host source and destination buffers
#define OP(x) \
T* src_h_##x; \
T* dst_h_##x; \
if (enable_priority_##x) { \
src_h_##x = (T*)malloc(size); \
if (src_h_##x == NULL) { printf("src_h_%s malloc failed!\n", #x); exit(-1); } \
mem_init<T>(src_h_##x, (size / sizeof(T))); \
dst_h_##x = (T*)malloc(size); \
if (dst_h_##x == NULL) { printf("dst_h_%s malloc failed!\n", #x); exit(-1); } \
memset(dst_h_##x, 0, size); \
}
OP(low)
OP(normal)
OP(high)
#undef OP
// allocate and initialize device source and destination buffers
#define OP(x) \
T* src_d_##x; \
T* dst_d_##x; \
if (enable_priority_##x) { \
HIPCHECK(hipMalloc(&src_d_##x, size)); \
HIPCHECK(hipMemcpy(src_d_##x, src_h_##x, size, hipMemcpyHostToDevice)); \
HIPCHECK(hipMalloc(&dst_d_##x, size)); \
}
OP(low)
OP(normal)
OP(high)
#undef OP
// create events for measuring time spent in kernel execution
#define OP(x) \
hipEvent_t event_start_##x; \
hipEvent_t event_end_##x; \
if (enable_priority_##x) { \
HIPCHECK(hipEventCreate(&event_start_##x)); \
HIPCHECK(hipEventCreate(&event_end_##x)); \
}
OP(low)
OP(normal)
OP(high)
#undef OP
// record start events for each of the priority streams
#define OP(x) \
if (enable_priority_##x) { \
HIPCHECK(hipEventRecord(event_start_##x, stream_##x)); \
}
OP(low)
OP(normal)
OP(high)
#undef OP
// launch kernels repeatedly on each of the prioritiy streams
for (int i = 0; i < size; i += MEMCPYSIZE)
{
int j = i / sizeof(T);
#define OP(x) \
if (enable_priority_##x) { \
hipLaunchKernelGGL((memcpy_kernel<T>), dim3(GRIDSIZE), dim3(BLOCKSIZE), 0, stream_##x, dst_d_##x + j, src_d_##x + j, (MEMCPYSIZE / sizeof(T))); \
}
OP(low)
OP(normal)
OP(high)
#undef OP
}
// record end events for each of the priority streams
#define OP(x) \
if (enable_priority_##x) { \
HIPCHECK(hipEventRecord(event_end_##x, stream_##x)); \
}
OP(low)
OP(normal)
OP(high)
#undef OP
// synchronize events for each of the priority streams
#define OP(x) \
if (enable_priority_##x) { \
HIPCHECK(hipEventSynchronize(event_end_##x)); \
}
OP(low)
OP(normal)
OP(high)
#undef OP
// compute time spent for memcpy in each stream
#define OP(x) \
float time_spent_##x; \
if (enable_priority_##x) { \
HIPCHECK(hipEventElapsedTime(&time_spent_##x, event_start_##x, event_end_##x)); \
printf("time spent for memcpy in %6s priority stream: %.3lf ms\n", #x, time_spent_##x); \
}
OP(low)
OP(normal)
OP(high)
#undef OP
// sanity check
#define OP(x) \
if (enable_priority_##x) { \
HIPCHECK(hipMemcpy(dst_h_##x, dst_d_##x, size, hipMemcpyDeviceToHost)); \
if (memcmp(dst_h_##x, src_h_##x, size) != 0) { printf("memcmp for %s failed!\n", #x); exit(-1); } \
}
OP(low)
OP(normal)
OP(high)
#undef OP
// validate that stream priorities are working as expected
#define OP(x, y) \
if (enable_priority_##x && enable_priority_##y) { \
if (time_spent_##x < time_spent_##y) { printf("FAILED!"); exit(-1); } \
}
OP(low, normal)
OP(normal, high)
OP(low, high)
#undef OP
passed();
}
int main(int argc, char **argv)
{
HipTest::parseStandardArguments(argc, argv, false);
runTest<int>();
}
@@ -76,7 +76,7 @@ void test12345() {
H2HAsync(Bh, Ah, size, stream);
H2DAsync(Ad, Bh, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
D2DAsync(Bd, Ad, size, stream);
D2HAsync(Ch, Bd, size, stream);
HIPCHECK(hipDeviceSynchronize());
@@ -111,7 +111,7 @@ void test13452() {
H2D(Ad, Dh, size);
H2HAsync(Bh, Ah, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
D2DAsync(Bd, Ad, size, stream);
D2HAsync(Ch, Bd, size, stream);
H2DAsync(Cd, Ch, size, stream);
@@ -152,7 +152,7 @@ void test14523() {
D2DAsync(Bd, Ad, size, stream);
D2HAsync(Ch, Bd, size, stream);
H2DAsync(Cd, Ch, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Cd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Cd);
HIPCHECK(hipDeviceSynchronize());
@@ -190,7 +190,7 @@ void test15234() {
H2HAsync(Bh, Ah, size, stream);
D2HAsync(Ch, Ad, size, stream);
H2DAsync(Bd, Ch, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Bd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Bd);
D2DAsync(Cd, Bd, size, stream);
D2H(Eh, Cd, size);
@@ -217,7 +217,7 @@ void test23451() {
setArray(Ah, N, T(1));
H2DAsync(Ad, Ah, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
D2DAsync(Bd, Ad, size, stream);
D2HAsync(Bh, Bd, size, stream);
H2HAsync(Ch, Bh, size, stream);
@@ -254,7 +254,7 @@ void test24513() {
D2DAsync(Bd, Ad, size, stream);
D2HAsync(Bh, Bd, size, stream);
H2HAsync(Ch, Bh, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Cd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Cd);
HIPCHECK(hipDeviceSynchronize());
D2H(Eh, Cd, size);
@@ -291,7 +291,7 @@ void test25134() {
H2DAsync(Ad, Ah, size, stream);
D2HAsync(Bh, Ad, size, stream);
H2HAsync(Ch, Bh, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Bd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Bd);
D2DAsync(Cd, Bd, size, stream);
D2H(Eh, Cd, size);
@@ -324,7 +324,7 @@ void test21345() {
H2DAsync(Ad, Ah, size, stream);
H2HAsync(Ch, Bh, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
D2DAsync(Bd, Ad, size, stream);
D2HAsync(Dh, Bd, size, stream);
@@ -358,7 +358,7 @@ void test34512() {
H2D(Ad, Ah, size);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
D2DAsync(Bd, Ad, size, stream);
D2HAsync(Bh, Bd, size, stream);
H2HAsync(Ch, Bh, size, stream);
@@ -393,7 +393,7 @@ void test35124() {
H2D(Ad, Dh, size);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
D2HAsync(Ah, Ad, size, stream);
H2HAsync(Bh, Ah, size, stream);
H2DAsync(Bd, Bh, size, stream);
@@ -430,7 +430,7 @@ void test31245() {
H2D(Ad, Dh, size);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
H2HAsync(Bh, Ah, size, stream);
H2DAsync(Bd, Bh, size, stream);
D2DAsync(Cd, Bd, size, stream);
@@ -469,7 +469,7 @@ void test32451() {
setArray(Eh, N, T(2));
H2D(Ad, Eh, size);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Ad);
H2DAsync(Bd, Ah, size, stream);
D2DAsync(Cd, Bd, size, stream);
D2HAsync(Bh, Cd, size, stream);
@@ -507,7 +507,7 @@ void test45123() {
D2HAsync(Ah, Bd, size, stream);
H2HAsync(Bh, Ah, size, stream);
H2DAsync(Cd, Bh, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Cd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Cd);
D2H(Ch, Cd, size);
HIPCHECK(hipDeviceSynchronize());
@@ -539,7 +539,7 @@ void test41235() {
D2DAsync(Bd, Ad, size, stream);
D2HAsync(Ah, Bd, size, stream);
H2DAsync(Cd, Ah, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Cd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Cd);
D2HAsync(Bh, Cd, size, stream);
HIPCHECK(hipDeviceSynchronize());
@@ -574,7 +574,7 @@ void test42351() {
D2DAsync(Bd, Ad, size, stream);
H2DAsync(Cd, Ah, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Cd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Cd);
D2HAsync(Bh, Cd, size, stream);
H2HAsync(Ch, Bh, size, stream);
@@ -609,7 +609,7 @@ void test43512() {
H2D(Ad, Dh, size);
D2DAsync(Bd, Ad, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Bd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Bd);
D2HAsync(Ah, Bd, size, stream);
H2HAsync(Bh, Ah, size, stream);
H2DAsync(Cd, Bh, size, stream);
@@ -645,7 +645,7 @@ void test51234() {
D2HAsync(Ah, Ad, size, stream);
H2HAsync(Bh, Ah, size, stream);
H2DAsync(Bd, Bh, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Bd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Bd);
D2DAsync(Cd, Bd, size, stream);
D2H(Ch, Cd, size);
@@ -681,7 +681,7 @@ void test52341() {
D2HAsync(Ah, Ad, size, stream);
H2DAsync(Bd, Ah, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Bd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Bd);
D2DAsync(Cd, Bd, size, stream);
H2HAsync(Ch, Bh, size, stream);
@@ -723,7 +723,7 @@ void test53412() {
H2D(Bd, Eh, size);
D2HAsync(Ah, Ad, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Bd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Bd);
D2DAsync(Cd, Bd, size, stream);
H2HAsync(Ch, Bh, size, stream);
H2DAsync(Dd, Ch, size, stream);
@@ -770,7 +770,7 @@ void test54123() {
D2DAsync(Cd, Bd, size, stream);
H2HAsync(Ch, Bh, size, stream);
H2DAsync(Dd, Ch, size, stream);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Dd);
hipLaunchKernelGGL(HIP_KERNEL_NAME(Inc), dim3(N / 512), dim3(512), 0, stream, Dd);
D2H(Fh, Cd, size);
D2H(Gh, Dd, size);