1/* 2Copyright (c) 2012 Advanced Micro Devices, Inc. 3 4This software is provided 'as-is', without any express or implied warranty. 5In no event will the authors be held liable for any damages arising from the use of this software. 6Permission is granted to anyone to use this software for any purpose, 7including commercial applications, and to alter it and redistribute it freely, 8subject to the following restrictions: 9 101. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 112. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 123. This notice may not be removed or altered from any source distribution. 13*/ 14//Originally written by Takahiro Harada 15 16#pragma OPENCL EXTENSION cl_amd_printf : enable 17#pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable 18 19typedef unsigned int u32; 20#define GET_GROUP_IDX get_group_id(0) 21#define GET_LOCAL_IDX get_local_id(0) 22#define GET_GLOBAL_IDX get_global_id(0) 23#define GET_GROUP_SIZE get_local_size(0) 24#define GROUP_LDS_BARRIER barrier(CLK_LOCAL_MEM_FENCE) 25#define GROUP_MEM_FENCE mem_fence(CLK_LOCAL_MEM_FENCE) 26#define AtomInc(x) atom_inc(&(x)) 27#define AtomInc1(x, out) out = atom_inc(&(x)) 28 29#define make_uint4 (uint4) 30#define make_uint2 (uint2) 31#define make_int2 (int2) 32 33typedef struct 34{ 35 int m_n; 36 int m_padding[3]; 37} ConstBuffer; 38 39 40 41__kernel 42__attribute__((reqd_work_group_size(64,1,1))) 43void Copy1F4Kernel(__global float4* dst, __global float4* src, 44 ConstBuffer cb) 45{ 46 int gIdx = GET_GLOBAL_IDX; 47 48 if( gIdx < cb.m_n ) 49 { 50 float4 a0 = src[gIdx]; 51 52 dst[ gIdx ] = a0; 53 } 54} 55 56__kernel 57__attribute__((reqd_work_group_size(64,1,1))) 58void Copy2F4Kernel(__global float4* dst, __global float4* src, 59 ConstBuffer cb) 60{ 61 int gIdx = GET_GLOBAL_IDX; 62 63 if( 2*gIdx <= cb.m_n ) 64 { 65 float4 a0 = src[gIdx*2+0]; 66 float4 a1 = src[gIdx*2+1]; 67 68 dst[ gIdx*2+0 ] = a0; 69 dst[ gIdx*2+1 ] = a1; 70 } 71} 72 73__kernel 74__attribute__((reqd_work_group_size(64,1,1))) 75void Copy4F4Kernel(__global float4* dst, __global float4* src, 76 ConstBuffer cb) 77{ 78 int gIdx = GET_GLOBAL_IDX; 79 80 if( 4*gIdx <= cb.m_n ) 81 { 82 int idx0 = gIdx*4+0; 83 int idx1 = gIdx*4+1; 84 int idx2 = gIdx*4+2; 85 int idx3 = gIdx*4+3; 86 87 float4 a0 = src[idx0]; 88 float4 a1 = src[idx1]; 89 float4 a2 = src[idx2]; 90 float4 a3 = src[idx3]; 91 92 dst[ idx0 ] = a0; 93 dst[ idx1 ] = a1; 94 dst[ idx2 ] = a2; 95 dst[ idx3 ] = a3; 96 } 97} 98 99__kernel 100__attribute__((reqd_work_group_size(64,1,1))) 101void CopyF1Kernel(__global float* dstF1, __global float* srcF1, 102 ConstBuffer cb) 103{ 104 int gIdx = GET_GLOBAL_IDX; 105 106 if( gIdx < cb.m_n ) 107 { 108 float a0 = srcF1[gIdx]; 109 110 dstF1[ gIdx ] = a0; 111 } 112} 113 114__kernel 115__attribute__((reqd_work_group_size(64,1,1))) 116void CopyF2Kernel(__global float2* dstF2, __global float2* srcF2, 117 ConstBuffer cb) 118{ 119 int gIdx = GET_GLOBAL_IDX; 120 121 if( gIdx < cb.m_n ) 122 { 123 float2 a0 = srcF2[gIdx]; 124 125 dstF2[ gIdx ] = a0; 126 } 127} 128 129