/* 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. */ #include #include #include #include #include #include "hip/hip_runtime.h" #include #include #ifdef NDEBUG #define HIP_ASSERT(x) x #else #define HIP_ASSERT(x) (assert((x)==hipSuccess)) #endif #define WIDTH (1024) #define HEIGHT (1024) #define NUM (WIDTH*HEIGHT) #define THREADS_PER_BLOCK_X 64 #define THREADS_PER_BLOCK_Y 1 #define THREADS_PER_BLOCK_Z 1 // Computes vectorAdd with matrix-multiply template __global__ void addition_kernel( T* __restrict__ a, const float* __restrict__ b, const float* __restrict__ c, int width, int height ) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; if (x >= WIDTH || y >= HEIGHT) return; int index = y * width + x; a[index] = b[index]+c[index]; } __global__ void subtract_kernel( float* __restrict__ a, const float* __restrict__ b, const float* __restrict__ c, int width, int height ) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; if (x >= WIDTH || y >= HEIGHT) return; int index = y * width + x; a[index] = abs(b[index]-c[index]); } __global__ void multiply_kernel( float* __restrict__ a, const float* __restrict__ b, const float* __restrict__ c, int width, int height ) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; if (x >= WIDTH || y >= HEIGHT) return; int index = y * width + x; a[index] = (b[index]-1)*(c[index]-1)+1; } __global__ void divide_kernel( float* __restrict__ a, const float* __restrict__ b, const float* __restrict__ c, int width, int height ) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; if (x >= WIDTH || y >= HEIGHT) return; int index = y * width + x; a[index] = (b[index]-c[index]) / abs(c[index]+b[index]) + 1; } using namespace std; void run(int NUM_QUEUE) { std::vector hostA(NUM_QUEUE); std::vector hostB(NUM_QUEUE); std::vector hostC(NUM_QUEUE); std::vector deviceA(NUM_QUEUE); std::vector deviceB(NUM_QUEUE); std::vector deviceC(NUM_QUEUE); std::vector streams(NUM_QUEUE); 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 ; int i; int errors; for (int q=0; q