kernel_code
stringlengths
49
1.22M
kernel void compiler_clz_int(global int* src, global int* dst) { int i = get_global_id(0); dst[i] = clz(src[i]); }
kernel void wander(global float* in_pos_x, global float* in_pos_y, global float* in_pos_z, global float* in_vel_x, global float* in_vel_y, global float* in_vel_z) { const int i = get_global_id(0); in_pos_x[i] + 1.0f; }
kernel void toColorDense(global float* buff) { int gid = get_global_id(0); buff[gid] = exp(-buff[gid]); }
kernel void relational_greater_than_or_equal_to_int8int8(global int8* src_0, global int8* src_1, global int8* dst) { int gid = get_global_id(0); dst[gid] = src_0[gid] >= src_1[gid]; }
kernel void set_elem_vector(global float* in, const int index, global float* out) { if (get_global_id(0) == 0) out[index] = (*in); }
kernel void kernel_atan2_withoutDD1(global float* result_atan2, int N) { float t1 = 12345.64; float t2 = 12345.64; float t3 = 12345.64; float t4 = 12345.64; float t5 = 12345.64; float t6 = 12345.64; float t7 = 12345.64; float t8 = 12345.64; float t9 = 12345.64; float t10 = 12345.64; float i = 0.0; float j = 0.01; float n = (float)(N); for (i = 0.0; i < n; i = i + 0.1) { t1 = atan2(i, j); t2 = atan2(i, j); t3 = atan2(i, j); t4 = atan2(i, j); t5 = atan2(i, j); t6 = atan2(i, j); t7 = atan2(i, j); t8 = atan2(i, j); t9 = atan2(i, j); t10 = atan2(i, j); } *result_atan2 = t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10; }
kernel void test2(global int* buf0, global int* buf1) { int gidx = get_global_id(0); buf0[gidx] = buf1[gidx] + 1; }
kernel void pmax(global int* A, global int* B, const int x, const unsigned int n) { const int globalRow = get_global_id(0); if (globalRow < n) { B[globalRow] = max(A[globalRow], x); } }
kernel void NL_SIGM_BWD(global float* dX, global float* Y, global float* dY) { unsigned int element = get_global_id(0); const float Y_value = Y[element]; const float dY_value = dY[element]; dX[element] = dY_value * Y_value * (1.0 - Y_value); }
constant size_t ELEMENTS_PER_WORK_ITEM_SCAN = 2; constant size_t ELEMENTS_PER_WORK_ITEM_OTHERS = 2; kernel void prefixSumScan(global unsigned int* elements, const unsigned int count, local unsigned int* temp, global unsigned int* sums, const unsigned int doWriteSums, const unsigned int bitMask, global unsigned int* prefixSums, const unsigned int doWriteTotalFalses, global unsigned int* totalFalses) { size_t i = get_local_id(0); size_t group = get_group_id(0); size_t groupSize = get_local_size(0); size_t elementsPerGroup = groupSize * ELEMENTS_PER_WORK_ITEM_SCAN; size_t groupOffset = group * elementsPerGroup; size_t itemOffset = ELEMENTS_PER_WORK_ITEM_SCAN * i; if (bitMask == 0) { temp[itemOffset] = elements[groupOffset + itemOffset]; temp[itemOffset + 1] = elements[groupOffset + itemOffset + 1]; } else { temp[itemOffset] = !(elements[groupOffset + itemOffset] & bitMask); temp[itemOffset + 1] = !(elements[groupOffset + itemOffset + 1] & bitMask); } int offset = 1; size_t binaryOffset = i * 2; for (int d = elementsPerGroup >> 1; d > 0; d >>= 1) { barrier(0x01); if (i < d) { int a = offset * (binaryOffset + 1) - 1; int b = offset * (binaryOffset + 2) - 1; temp[b] += temp[a]; } offset *= 2; } barrier(0x01); if (get_local_id(0) == 0) { if (doWriteSums) { sums[group] = temp[elementsPerGroup - 1]; } temp[elementsPerGroup - 1] = 0; } for (int d = 1; d < elementsPerGroup; d *= 2) { offset >>= 1; barrier(0x01); if (i < d) { int a = offset * (binaryOffset + 1) - 1; int b = offset * (binaryOffset + 2) - 1; unsigned int t = temp[a]; temp[a] = temp[b]; temp[b] += t; } } barrier(0x01); if (get_global_id(0) == 0) { if (doWriteTotalFalses) { unsigned int lastIndex = count - 1; totalFalses[0] = !(elements[lastIndex] & bitMask) + temp[lastIndex]; } } prefixSums[groupOffset + itemOffset] = temp[itemOffset]; prefixSums[groupOffset + itemOffset + 1] = temp[itemOffset + 1]; }
inline float _distance_2_point(float x, float y, float rx, float ry, float sw, float sh, float ez, float ex, float ey) { float dx = x / rx * sw - sw / 2.0f + ex; float dy = y / ry * sh - sh / 2.0f - ey; return sqrt(ez * ez + dx * dx + dy * dy); } kernel void distance_2_point(global float* x, global float* y, float rx, float ry, float sw, float sh, global float* ez, global float* ex, global float* ey, global float* out) { unsigned int i = get_global_id(0); out[i] = _distance_2_point(x[i], y[i], rx, ry, sw, sh, ez[i], ex[i], ey[i]); }
kernel void sax_vectorized_and_squarenorm_reduction(global float* out, global float* result_tmp, const unsigned int elems, const unsigned int num_fields) { const unsigned int id = get_global_id(0); for (unsigned int i = 0; i < num_fields; i++) out[i] = 0.0; if (id == 0) { for (unsigned int s = 0; s < elems; s++) { out[s - (s / num_fields) * num_fields] += result_tmp[s]; } } }
kernel void mem_write(global volatile float* buffer, int num_it, global float* dummyBuffer) { const int k = get_global_id(0); while (num_it-- != 0) buffer[k] = 0; }
kernel void Stencil2D(global float const* restrict memory_in, global float* restrict memory_out) { for (int i = 1; i < 32 - 1; ++i) { for (int j = 0; j < 32; ++j) { const float above = memory_in[(i - 1) * 32 + j]; const float center = memory_in[i * 32 + j]; const float below = memory_in[(i + 1) * 32 + j]; const float factor = 0.3333f; const float average = factor * (above + center + below); memory_out[i * 32 + j] = average; } } }
kernel void kernel_1(global float* inputA, global float* inputB, global float* output, const unsigned int count) { float L = 0; for (int i = 0; i < count; i++) { float x = fabs(inputA[i] - inputB[i]); L += x; } output[1] = L; }
kernel void foo(global float2* A, float2 y, float2 x) { *A = atan2pi(y, x); }
union BufferType { float f; unsigned int u; }; kernel void applyCoulombsLaw(global float4* pointPosition, global float4* pointAcceleration, global float* pointMass, const int numPoints, const float repulsion) { const int p1 = get_global_id(0); if (p1 >= numPoints) return; float4 pointPositionP1 = pointPosition[p1]; float pointMassP1 = pointMass[p1]; float4 accelerationSum = 0; for (int p2 = 0; p2 < numPoints; p2++) { if (p1 == p2) continue; float4 direction = pointPositionP1 - pointPosition[p2]; float distance = length(direction); direction *= (float)1 / fmax(distance, (float)0.1f); float f = repulsion / fmax(distance * distance * (float)0.5f, (float)0.005f); float4 force = direction * f; accelerationSum += force * ((float)1 / pointMassP1); } pointAcceleration[p1] += accelerationSum; }
kernel void pre_increment_float(global float* src_0, global float* dst) { int gid = get_global_id(0); dst[gid] = ++src_0[gid]; }
kernel void abs_diff_ulong2ulong2(global ulong2* src_0, global ulong2* src_1, global ulong2* dst) { int gid = get_global_id(0); dst[gid] = abs_diff(src_0[gid], src_1[gid]); }
kernel void compiler_hadd(global int* src1, global int* src2, global int* dst) { int i = get_global_id(0); dst[i] = hadd(src1[i], src2[i]); }
kernel void fill_ones(global float* out) { out[get_global_id(0)] = 1.0; }
kernel void initWorkBuffer(global float* workBuffer) { int idx = get_global_id(0); workBuffer[idx] = 0; }
kernel void foo(global int* data) { *data = get_global_offset(0) + get_num_groups(0) + get_enqueued_local_size(0) + get_global_size(0) + get_global_id(0) + get_group_id(0); }
kernel void kernel_fmax_withoutDD2(global float* result_fmax, int N) { float2 t1 = -1 + (float2)(0); float2 t2 = -1 + (float2)(0); float2 t3 = t1; float2 t4 = t3; float2 t5 = t4; float2 t6 = t5; float2 t7 = t6; float2 t8 = t7; float2 t9 = t8; float2 t10 = t9; float2 t11 = -1 + (float2)(0); float2 t12 = -1 + (float2)(0); float2 t13 = t1; float2 t14 = t3; float2 t15 = t4; float2 t16 = t5; float2 t17 = t6; float2 t18 = t7; float2 t19 = t8; float2 t20 = t9; float2 t21 = -1; float2 t22 = -1; float2 t23 = t1; float2 t24 = t3; float2 t25 = t4; float2 t26 = t5; float2 t27 = t6; float2 t28 = t7; float2 t29 = t8; float2 t30 = t9; float2 i = 0 + (float2)(0); int j = 0; for (j = 0; j < 100 * N; j++) { t1 += fmax(t1, i); t2 += fmax(t2, i); t3 += fmax(t3, i); t4 += fmax(t4, i); t5 += fmax(t5, i); t6 += fmax(t6, i); t7 += fmax(t7, i); t8 += fmax(t8, i); t9 += fmax(t9, i); t10 += fmax(t10, i); t11 += fmax(t11, i); t12 += fmax(t12, i); t13 += fmax(t13, i); t14 += fmax(t14, i); t15 += fmax(t15, i); t16 += fmax(t16, i); t17 += fmax(t17, i); t18 += fmax(t18, i); t19 += fmax(t19, i); t20 += fmax(t20, i); t21 += fmax(t21, i); t22 += fmax(t22, i); t22 += fmax(t23, i); t24 += fmax(t24, i); t25 += fmax(t25, i); t26 += fmax(t26, i); t27 += fmax(t27, i); t28 += fmax(t28, i); t29 += fmax(t29, i); t30 += fmax(t30, i); } *result_fmax = t1.s0 + t1.s1 + t2.s0 + t2.s1 + t3.s0 + t3.s1 + t4.s0 + t4.s1 + t5.s0 + t5.s1 + t6.s0 + t6.s1 + t7.s0 + t7.s1 + t8.s0 + t8.s1 + t9.s0 + t9.s1 + t10.s0 + t10.s1 + t11.s0 + t11.s1 + t12.s0 + t12.s1 + t13.s0 + t13.s1 + t14.s0 + t14.s1 + t15.s0 + t15.s1 + t16.s0 + t16.s1 + t17.s0 + t17.s1 + t18.s0 + t18.s1 + t19.s0 + t19.s1 + t20.s0 + t20.s1 + t21.s0 + t21.s1 + t22.s0 + t22.s1 + t23.s0 + t23.s1 + t24.s0 + t24.s1 + t25.s0 + t25.s1 + t26.s0 + t26.s1 + t27.s0 + t27.s1 + t28.s0 + t28.s1 + t29.s0 + t29.s1 + t30.s0 + t30.s1; }
inline int changeTranspositionIndex(int i, int n) { int ip; ip = i; return ip; } kernel void kernel_ScanHistograms(global int* histo, local int* temp, global int* globsum) { size_t it = get_local_id(0); size_t ig = get_global_id(0); int decale = 1; size_t n = get_local_size(0) * 2; size_t gr = get_group_id(0); temp[2 * it] = histo[2 * ig]; temp[2 * it + 1] = histo[2 * ig + 1]; for (int d = n >> 1; d > 0; d >>= 1) { barrier(0x01); if (it < d) { int ai = decale * (2 * it + 1) - 1; int bi = decale * (2 * it + 2) - 1; temp[bi] += temp[ai]; } decale *= 2; } if (it == 0) { globsum[gr] = temp[n - 1]; temp[n - 1] = 0; } for (int d = 1; d < n; d *= 2) { decale >>= 1; barrier(0x01); if (it < d) { int ai = decale * (2 * it + 1) - 1; int bi = decale * (2 * it + 2) - 1; int t = temp[ai]; temp[ai] = temp[bi]; temp[bi] += t; } } barrier(0x01); histo[2 * ig] = temp[2 * it]; histo[2 * ig + 1] = temp[2 * it + 1]; barrier(0x02); }
kernel void compact_exscan(global int* pred, global int* prefSum) { int id = get_global_id(0); prefSum[id] = (id > 0) ? pred[id - 1] : 0; barrier(0x02); for (int s = 1; s < get_global_size(0); s *= 2) { int tmp = prefSum[id]; if (id + s < get_global_size(0)) { prefSum[id + s] += tmp; } barrier(0x02); } if (id == 0) { prefSum[0] = 0; } }
kernel void Test(global unsigned int* dst) { unsigned int index = get_global_id(0); dst[index] = index; }
int whoHasWon(global const float* ballPosX, global const int* ballRad, global const int* width, global const float* ballVelX) { if (*ballPosX + *ballRad >= *width && *ballVelX > 0) return -1; else if (*ballPosX <= 0 && *ballVelX < 0) return 1; else return 0; } void reset(global float* ballPosX, global float* ballPosY, global float* ballVelX, global float* ballVelY, global const int* ballRad, global const int* width, global const int* height, global const int* maxBallSpeed, global const int* minBallSpeed, global float* paddle1Pos, global float* paddle2Pos, float rand1, float rand2, float rand3, float rand4) { *ballPosX = *width / 2; *ballPosY = *height / 2; *ballVelX = rand1 * (*maxBallSpeed - *minBallSpeed) / 8.0f + *minBallSpeed; if (rand2 > 0.5f) *ballVelX *= -1; *ballVelY = rand3 * (*maxBallSpeed - *minBallSpeed) / 8.0f + *minBallSpeed; if (rand4 > 0.5f) *ballVelY *= -1; *paddle1Pos = *height / 2; *paddle2Pos = *height / 2; } kernel void get_nn_input(global int* time, global const int* maxTime, global float* ballPosX, global float* ballPosY, global float* ballVelX, global float* ballVelY, global const int* ballRad, global const int* width, global const int* height, global const int* maxBallSpeed, global const int* minBallSpeed, global float* paddle1Pos, global float* paddle2Pos, global const int* paddleHeight, float rand1, float rand2, float rand3, float rand4, global float* input, global int* currentPlayer) { if (get_global_id(0) == 0) { if (whoHasWon(ballPosX, ballRad, width, ballVelX) != 0 || *time >= *maxTime || *time == -1) { *time = 0; reset(ballPosX, ballPosY, ballVelX, ballVelY, ballRad, width, height, maxBallSpeed, minBallSpeed, paddle1Pos, paddle2Pos, rand1, rand2, rand3, rand4); } *currentPlayer = 1; input[0] = *ballPosX / *width; input[1] = *ballPosY / *height; input[2] = *ballVelX / *maxBallSpeed; input[3] = *ballVelY / *maxBallSpeed; input[4] = *paddle1Pos / (*height - *paddleHeight); input[5] = 0; } }
kernel void kraljice_brojac1(global float* data, global float* output) { int brPolja = 4; int n = 4; int k, ind; int x[4]; int resenje; float sum = 0.0; x[1] = 0; k = 1; while (k > 0) { x[k]++; if (x[k] <= n) { if (k == n) { resenje = 0; for (ind = 1; ind <= brPolja; ind++) { sum += (float)x[ind]; } } else { k++; x[k] = 0; } } else { k--; } } *output = sum; }
kernel void test_shuffle(const global char16* in, global char16* out) { char16 tmp = in[0]; char16 tmp1 = in[1]; out[0] = shuffle(tmp, (uchar16)(7, 6, 4, 8, 1, 12, 13, 1, 0, 9, 14, 15, 4, 3, 8, 6)); out[1] = shuffle2(tmp, tmp1, (uchar16)(1, 7, 11, 18, 21, 15, 8, 9, 0, 19, 2, 1, 17, 13, 7, 8)); char16 tmp2 = in[0]; tmp2.s5170abc3 = tmp1.s9b7ac3a0; out[2] = tmp2; char4 tmp3 = in[0].xyzw; tmp3.wx = tmp1.xy; out[3] = (char16)(tmp3, tmp3, tmp3, tmp3); char16 tmp4 = 0; tmp4.s43b79acd = (char8)(tmp3, tmp3); out[4] = tmp4; out[5] = shuffle(tmp, (uchar16)(0, 0, 0, 0, 4, 4, 4, 4, 8, 8, 8, 8, 12, 12, 12, 12)); out[6] = shuffle2(tmp, tmp1, (uchar16)(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); out[7] = shuffle(tmp, convert_uchar16(tmp)); out[8] = shuffle(tmp, (uchar16)(10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); out[9] = shuffle(tmp, (uchar16)(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)); }
float myAbs(float v) { if (v < 0) return -1.0 * v; else return v; } float lanczos(float x, int a) { if (x == 0) return 1; float absX = myAbs(x); if (0 < absX && absX < a) return (a * sin(3.1415926535897932384626433832795 * x) * sin(3.1415926535897932384626433832795 * x / a)) / (9.8696044010893586188344909998762 * x * x); return 0; } float gauss(float x, float d) { float tmp = x / d; tmp *= tmp; return (1.0 / (d * 2.506628274631000502415765284811)) * exp(-0.5 * tmp); } float gauss2(float x, float d) { float tmp = (x - 4.0 / 2) / (d * 4.0 / 2); tmp *= tmp; return (1.0 / (d * 2.506628274631000502415765284811)) * exp(-0.5 * tmp); } kernel void upSample2(int by, int N, global float* input, global float* output) { int idx = get_global_id(0); int center = idx / by; float x = (idx % by); x /= by; int b1 = center - 1; int b2 = center - 2; int a1 = center + 1; int a2 = center + 2; float y = gauss2(x, 0.4) * input[center]; if (b1 >= 0) y += gauss2(x + 1, 0.4) * input[b1]; if (b2 >= 0) y += gauss2(x + 2, 0.4) * input[b2]; if (a1 < N) y += gauss2(x - 1, 0.4) * input[a1]; if (a2 < N) y += gauss2(x - 2, 0.4) * input[a2]; output[idx] = y; }
kernel void selfdot_ints_withscratch(global int* in, global int* out, local int* scratch1, local int* scratch2) { int globalId = get_global_id(0); int localId = get_local_id(0); int workgroupSize = get_local_size(0); int workgroupid = get_group_id(0); scratch1[localId] = in[globalId]; barrier(0x01); int sum = 0; int us = scratch1[localId]; for (int i = 0; i < workgroupSize; i++) { sum += us * scratch1[i]; } scratch2[localId] = sum; barrier(0x01); for (int offset = (workgroupSize >> 1); offset > 0; offset >>= 1) { if (localId < offset) { scratch2[localId] = scratch2[localId] + scratch2[localId + offset]; } barrier(0x01); } if (localId == 0) { out[workgroupid] = scratch2[0]; } }
kernel void dotProduct1(global const float* gridA, global const float* gridB, global float* result, int const numElements) { int iGID = get_global_id(0); int totalThreads = get_global_size(0); int workPerThread = (numElements / totalThreads) + 1; int offset = 0; offset = iGID * workPerThread; result[iGID] = 0; for (int i = 0; i < workPerThread; ++i) { if (offset + i < numElements) { result[iGID] += (gridB[offset + i] * gridA[offset + i]); } } }
kernel void mul(global long* out, long a, long b) { out[0] = a * b; }
kernel void ScanNaive(global int* src, global int* dst, unsigned int offset, unsigned int n) { size_t id = get_global_id(0); if (id >= n) return; if (id >= offset) dst[id] = src[id] + src[id - offset]; else if (id >= (offset >> 1)) dst[id] = src[id]; }
kernel void array_exp_f32(global float* a, global float* b) { unsigned int i = get_global_id(0); b[i] = exp(a[i]); }
kernel void kernelVectorSixteen(char16 inputChar, uchar16 inputUChar, short16 inputShort, ushort16 inputUShort, int16 inputInt, uint16 inputUInt, long16 inputLong, ulong16 inputULong, float16 inputFloat, double16 inputDouble, global float16* output) { output[0] = convert_float16(inputChar); output[1] = convert_float16(inputUChar); output[2] = convert_float16(inputShort); output[3] = convert_float16(inputUShort); output[4] = convert_float16(inputInt); output[5] = convert_float16(inputUInt); output[6] = convert_float16(inputLong); output[7] = convert_float16(inputULong); output[8] = convert_float16(inputFloat); output[9] = convert_float16(inputDouble); }
extern constant float foo; kernel void test(global float* buf) { buf[0] += foo; }
kernel void op_test(global int4* output) { int4 vec = (int4)(1, 2, 3, 4); vec += 4; if (vec.s2 == 7) vec &= (int4)(-1, -1, 0, -1); vec.s01 = vec.s23 < 7; while (vec.s3 > 7 && (vec.s0 < 16 || vec.s1 < 16)) vec.s3 >>= 1; *output = vec; }
kernel void async_copy_out_of_bounds(local int* src, global int* dst) { int l = get_local_id(0); src[l] = l; barrier(0x01); event_t event = async_work_group_copy(dst + 1, src, get_local_size(0), 0); wait_group_events(1, &event); }
kernel void test_clamp(global char2* out, global char2* in) { *out = clamp(*in, (char2)7, (char2)42); }
float4 calculateLocalDirection(global const float4* points, int begin, int trackLength, int myIndex) { int end = begin + trackLength - 1; int first = myIndex - 1; int last = myIndex + 1; first = max(begin, first); last = min(end, last); float4 result = normalize(points[last] - points[first]); return result; } float4 calculateOverallDirection(global const float4* points, int begin, int trackLength) { int end = begin + trackLength - 1; float4 result = normalize(points[end] - points[begin]); return result; } bool checkCurvature(global const float4* points, int begin, int trackLength, int myIndex, float4 newPoint, float angleMin) { return true; int end = begin + trackLength - 1; int prePrev = myIndex - 2; int prev = myIndex - 1; int next = myIndex + 1; int postNext = myIndex + 2; prePrev = max(begin, prePrev); prev = max(begin, prev); next = min(end, next); postNext = min(end, postNext); float anglePrev1 = dot(normalize(points[prePrev] - points[prev]), normalize(points[prev] - points[myIndex])); float angle1 = dot(normalize(points[prev] - points[myIndex]), normalize(points[myIndex] - points[next])); float angleNext1 = dot(normalize(points[myIndex] - points[next]), normalize(points[next] - points[postNext])); float angleSum1 = anglePrev1 + angle1 + angleNext1; float anglePrev2 = dot(normalize(points[prePrev] - points[prev]), normalize(points[prev] - newPoint)); float angle2 = dot(normalize(points[prev] - newPoint), normalize(newPoint - points[next])); float angleNext2 = dot(normalize(newPoint - points[next]), normalize(points[next] - points[postNext])); float angleSum2 = anglePrev2 + angle2 + angleNext2; if (angleSum2 > angleSum1) return true; return (angleMin <= anglePrev2) && (angleMin <= angle2) && (angleMin <= angleNext2); } int calculateClosestIndex(int trackStart, int trackLength, global const float4* points, float4 myPosition) { float minDistance = 99999; int bestIndex = -1; for (int i = trackStart; i < trackStart + trackLength; i++) { float newDistance = length(points[i] - myPosition); if (newDistance < minDistance) { minDistance = newDistance; bestIndex = i; } } return bestIndex; } float4 transformForcePerpendicular(float4 direction, float4 force) { float l = length(force); float4 forceOriginal = force; if (l <= 0.0) { return force; } force /= l; float t = dot(direction, force); float sgn = 1.; if (t > 0) { t = t * -1.; sgn = 1.; } force.x -= t * direction.x; force.y -= t * direction.y; force.z -= t * direction.z; if (dot(forceOriginal, force) < 0.) { force *= -1.f; } return l * force; } float4 calculateForce(global const int* clusterIndices, int clusterStart, int clusterLength, global const int* trackStarts, global const int* trackLengths, global const float4* points, float4 myPosition, float4 myDirection, float angleStick, float radius) { float weightSum = 1.; float4 force = {0., 0., 0., 0.}; for (int i = clusterStart; i < clusterStart + clusterLength; i++) { int trackId = clusterIndices[i]; int trackStart = trackStarts[trackId]; int trackLength = trackLengths[trackId]; int closestIndex = calculateClosestIndex(trackStart, trackLength, points, myPosition); float minDistance = length(points[closestIndex] - myPosition); if (minDistance > radius || minDistance < 0.00001) { continue; } float4 direction = calculateLocalDirection(points, trackStart, trackLength, closestIndex); float weight = ((radius - minDistance) / radius); if (!isnan(myDirection.x) && !isnan(direction.x)) { float angle = pow((float)dot(myDirection, direction), (float)2.); angle = max(0., (angle - angleStick) / (1. - angleStick)); float weight = angle * weight; } weight = pow((float)weight, (float)2.); weightSum += weight; force += weight * (points[closestIndex] - myPosition); } force /= weightSum; if (!isnan(myDirection.x)) { force = transformForcePerpendicular(myDirection, force); } return force; } float4 smoothPosition(global const float4* points, int begin, int trackLength, int myIndex, const int radius, const float intensity) { float4 reference = points[myIndex]; int end = begin + trackLength - 1; int first = myIndex - radius; int last = myIndex + radius; first = max(begin, first); last = min(end, last); float4 result = {0., 0., 0., 0.}; for (int i = first; i < last + 1; i++) { result.x += points[i].x / (last - first + 1); result.y += points[i].y / (last - first + 1); result.z += points[i].z / (last - first + 1); } result.x = result.x * intensity + reference.x * (1. - intensity); result.y = result.y * intensity + reference.y * (1. - intensity); result.z = result.z * intensity + reference.z * (1. - intensity); return result; } kernel void smooth(global const int* trackStarts, global const int* trackLengths, global const float4* points, global float4* pointsResult, global const int* pointToTrackIndices, const int pointSize, const int radius, const float intensity, const int offset) { if (radius == 0 || intensity <= 0.0) { return; } int pointId = get_global_id(0) + offset; int trackId = pointToTrackIndices[pointId]; int trackStart = trackStarts[trackId]; int trackLength = trackLengths[trackId]; int trackEnd = trackStart + trackLengths[trackId] - 1; ; if (pointId == trackStart || pointId == trackEnd) { return; } float4 resultPoint = smoothPosition(points, trackStart, trackLength, pointId, radius, intensity); if (pointId < pointSize) { pointsResult[pointId] = resultPoint; } }
inline int modulo(int a, int b) { const int result = a % b; return result >= 0 ? result : result + b; } kernel void gameOfLifeKernel(int rows, int columns, global int* matrix, global int* result) { int globalId = get_global_id(0); short neighbors = 0; int x = globalId % columns; int y = globalId / columns; if (matrix[modulo(x - 1, columns) + y * columns] == 1) neighbors++; if (matrix[modulo(x + 1, columns) + y * columns] == 1) neighbors++; if (matrix[x + modulo(y - 1, rows) * columns] == 1) neighbors++; if (matrix[x + modulo(y + 1, rows) * columns] == 1) neighbors++; if (matrix[modulo(x + 1, columns) + modulo(y + 1, rows) * columns] == 1) neighbors++; if (matrix[modulo(x + 1, columns) + modulo(y - 1, rows) * columns] == 1) neighbors++; if (matrix[modulo(x - 1, columns) + modulo(y + 1, rows) * columns] == 1) neighbors++; if (matrix[modulo(x - 1, columns) + modulo(y - 1, rows) * columns] == 1) neighbors++; if (matrix[globalId] == 0) { if (neighbors == 3) result[globalId] = 1; else result[globalId] = 0; } else if (matrix[globalId] == 1) { if (neighbors < 2) result[globalId] = 0; else if (neighbors == 2 || neighbors == 3) result[globalId] = 1; else if (neighbors > 3) result[globalId] = 0; ; } }
kernel void FillIndices(global float* x, float start, float step) { unsigned int id = get_global_id(0); x[id] = start + id * step; }
float2 force_LJ(float2 p1, float2 p2) { float2 d = p2 - p1; float ir2 = 1 / (d.x * d.x + d.y * d.y + 1.0e-2); float ir6 = ir2 * ir2 * ir2; float fr = ir6 - ir6 * ir6; return d * fr; } kernel void NBody_force_naive(unsigned int num, global float2* pos, global float2* force) { const int i = get_global_id(0); float2 p = pos[i]; float2 f = (float2)(0.0f, 0.0f); for (int j = 0; j < num; j++) { float2 pj = pos[j]; f += force_LJ(p, pj); } force[i] = f; }
kernel void dot3(global float* a_vec, global float* b_vec, global float* output, local float* l_vec) { size_t gid = get_global_id(0); size_t lid = get_local_id(0); l_vec[lid] = a_vec[gid] * b_vec[gid]; barrier(0x01); if (lid == 0) { l_vec[lid] = l_vec[lid] + l_vec[lid + 1]; } output[gid] = l_vec[lid]; }
union BufferType { float f; unsigned int u; }; kernel void totalEnergyGroup(global float4* pointVelocity, global float* pointMass, global float* pointEnergy, const int workGroupSize, const int numPoints) { int p = get_global_id(0); float energy = (float)0; while (p < numPoints) { float speed = length(pointVelocity[p]); energy += (float)0.5f * pointMass[p] * speed * speed; p += get_global_size(0); } pointEnergy[get_global_id(0)] = energy; }
kernel void divide(global float* a, global float* b, global float* result) { int i; i = get_global_id(0); if (b[i] != 0) { result[i] = a[i] / b[i]; } else { result[i] = 0; } }
void calc_pq_index(int size, int idx, int* p, int* q); void calc_pq_index(int size, int idx, int* p, int* q) { int i; int count = idx; *p = 0; *q = *p + 1; for (i = size - 1; i > 0; i--) { if (count < i) { *q = count + *q; break; } else { count -= i; *p = *p + 1; *q = *p + 1; } } } kernel void calc_distance(int size, global float* x, global float* y, global float* final) { int global_id = get_global_id(0); int p_idx, q_idx; calc_pq_index(size, global_id, &p_idx, &q_idx); float2 p = (float2)(x[p_idx], y[p_idx]); float2 q = (float2)(x[q_idx], y[q_idx]); final[global_id] = distance(p, q); }
kernel void test_kernel(global ulong* output) { local char l_int8[3]; local int l_int32[3]; local float l_float[3]; output[0] = (ulong)l_int8; output[1] = (ulong)l_int32; output[2] = (ulong)l_float; }
constant float GRAVITY = 0.000000000066742; kernel void vortex(global float4* pos, global float4* float3, global float* masses, global float4* vel, float dt) { unsigned int i = get_global_id(0); unsigned int particle_count = get_global_size(0); float4 p = pos[i]; float4 v = vel[i]; float mass = masses[i]; float4 accelerationDirection = (float4)(0, 0, 0, 0); if (mass == 0) return; for (int j = 0; j < particle_count; j++) { if (masses[j] == 0 || j == i) continue; float4 distance = pos[j] - p; float qdistance = dot(distance, distance); if (qdistance <= 0) continue; if (qdistance > 0.01) { float acceleration = GRAVITY * masses[j] / qdistance; accelerationDirection += normalize(distance) * acceleration; } if ( qdistance < 0.0001 && masses[i] < masses[j]) { masses[j] += masses[i]; vel[j] += vel[i] * masses[i] / masses[j]; masses[i] = 0; return; } } v += accelerationDirection * dt; v.w = 1; p += v * dt; p.w = 1; pos[i] = p; vel[i] = v; }
kernel void abs_diff_intint(global int* src_0, global int* src_1, global unsigned int* dst) { int gid = get_global_id(0); dst[gid] = (unsigned int)(abs_diff(src_0[gid], src_1[gid])); }
kernel void test_uchar(global uchar* C, global uchar* A, global uchar* B) { int id = get_global_id(0); C[id] = add_sat(A[id], B[id]); }
kernel void prefixSum(global int* restrict output, global int* restrict input, const unsigned int in_size) { int8 tmp_buff; tmp_buff.s0 = 0; int size = in_size / 8; for (int i = 0; i < size; i++) { int8 in = ((global int8*)input)[i]; tmp_buff.s1 = tmp_buff.s0 + in.s0; tmp_buff.s2 = tmp_buff.s1 + in.s1; tmp_buff.s3 = tmp_buff.s2 + in.s2; tmp_buff.s4 = tmp_buff.s3 + in.s3; tmp_buff.s5 = tmp_buff.s4 + in.s4; tmp_buff.s6 = tmp_buff.s5 + in.s5; tmp_buff.s7 = tmp_buff.s6 + in.s6; ((global int8*)output)[i] = tmp_buff; tmp_buff.s0 = tmp_buff.s7 + in.s7; } }
kernel void sph_kernel_sort(global uint2* partIdx, int stage, int passOfStage, int direction) { unsigned int sortIncreasing = direction; unsigned int threadId = get_global_id(0); unsigned int pairDistance = 1 << (stage - passOfStage); unsigned int blockWidth = 2 * pairDistance; unsigned int leftId = (threadId % pairDistance) + (threadId / pairDistance) * blockWidth; unsigned int rightId = leftId + pairDistance; uint2 leftElement = partIdx[leftId]; uint2 rightElement = partIdx[rightId]; unsigned int sameDirectionBlockWidth = 1 << stage; if ((threadId / sameDirectionBlockWidth) % 2 == 1) sortIncreasing = 1 - sortIncreasing; uint2 greater; uint2 lesser; if (leftElement.x > rightElement.x) { greater = leftElement; lesser = rightElement; } else { greater = rightElement; lesser = leftElement; } if (sortIncreasing) { partIdx[leftId] = lesser; partIdx[rightId] = greater; } else { partIdx[leftId] = greater; partIdx[rightId] = lesser; } }
kernel void qssa2_kernel(global float* RF, global float* RB, global const float* A) { float xq4 = (A[((((((4) * (11)) + 0)) - 1) * (4)) + (get_global_id(0))]); float xq3 = (A[((((((3) * (11)) + 0)) - 1) * (4)) + (get_global_id(0))]) + (A[((((((3) * (11)) + 4)) - 1) * (4)) + (get_global_id(0))]) * xq4; float xq7 = (A[((((((7) * (11)) + 0)) - 1) * (4)) + (get_global_id(0))]) + (A[((((((7) * (11)) + 4)) - 1) * (4)) + (get_global_id(0))]) * xq4 + (A[((((((7) * (11)) + 3)) - 1) * (4)) + (get_global_id(0))]) * xq3; float xq2 = (A[((((((2) * (11)) + 0)) - 1) * (4)) + (get_global_id(0))]) + (A[((((((2) * (11)) + 4)) - 1) * (4)) + (get_global_id(0))]) * xq4 + (A[((((((2) * (11)) + 3)) - 1) * (4)) + (get_global_id(0))]) * xq3 + (A[((((((2) * (11)) + 7)) - 1) * (4)) + (get_global_id(0))]) * xq7; float xq1 = (A[((((((1) * (11)) + 0)) - 1) * (4)) + (get_global_id(0))]) + (A[((((((1) * (11)) + 4)) - 1) * (4)) + (get_global_id(0))]) * xq4 + (A[((((((1) * (11)) + 3)) - 1) * (4)) + (get_global_id(0))]) * xq3 + (A[((((((1) * (11)) + 7)) - 1) * (4)) + (get_global_id(0))]) * xq7 + (A[((((((1) * (11)) + 2)) - 1) * (4)) + (get_global_id(0))]) * xq2; float xq8 = (A[((((((8) * (11)) + 0)) - 1) * (4)) + (get_global_id(0))]) + (A[((((((8) * (11)) + 4)) - 1) * (4)) + (get_global_id(0))]) * xq4 + (A[((((((8) * (11)) + 3)) - 1) * (4)) + (get_global_id(0))]) * xq3; float xq6 = (A[((((((6) * (11)) + 0)) - 1) * (4)) + (get_global_id(0))]) + (A[((((((6) * (11)) + 3)) - 1) * (4)) + (get_global_id(0))]) * xq3 + (A[((((((6) * (11)) + 7)) - 1) * (4)) + (get_global_id(0))]) * xq7 + (A[((((((6) * (11)) + 2)) - 1) * (4)) + (get_global_id(0))]) * xq2; float xq9 = (A[((((((9) * (11)) + 0)) - 1) * (4)) + (get_global_id(0))]) + (A[((((((9) * (11)) + 4)) - 1) * (4)) + (get_global_id(0))]) * xq4 + (A[((((((9) * (11)) + 7)) - 1) * (4)) + (get_global_id(0))]) * xq7; float xq5 = (A[((((((5) * (11)) + 0)) - 1) * (4)) + (get_global_id(0))]) + (A[((((((5) * (11)) + 3)) - 1) * (4)) + (get_global_id(0))]) * xq3; float xq10 = (A[((((((10) * (11)) + 0)) - 1) * (4)) + (get_global_id(0))]) + (A[((((((10) * (11)) + 8)) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((34) - 1) * (4)) + (get_global_id(0))]) = (RF[(((34) - 1) * (4)) + (get_global_id(0))]) * xq1; (RF[(((35) - 1) * (4)) + (get_global_id(0))]) = (RF[(((35) - 1) * (4)) + (get_global_id(0))]) * xq1; (RB[(((35) - 1) * (4)) + (get_global_id(0))]) = (RB[(((35) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((36) - 1) * (4)) + (get_global_id(0))]) = (RF[(((36) - 1) * (4)) + (get_global_id(0))]) * xq1; (RB[(((36) - 1) * (4)) + (get_global_id(0))]) = (RB[(((36) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((37) - 1) * (4)) + (get_global_id(0))]) = (RF[(((37) - 1) * (4)) + (get_global_id(0))]) * xq1; (RF[(((38) - 1) * (4)) + (get_global_id(0))]) = (RF[(((38) - 1) * (4)) + (get_global_id(0))]) * xq1; (RB[(((38) - 1) * (4)) + (get_global_id(0))]) = (RB[(((38) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((39) - 1) * (4)) + (get_global_id(0))]) = (RF[(((39) - 1) * (4)) + (get_global_id(0))]) * xq1; (RF[(((40) - 1) * (4)) + (get_global_id(0))]) = (RF[(((40) - 1) * (4)) + (get_global_id(0))]) * xq1; (RB[(((40) - 1) * (4)) + (get_global_id(0))]) = (RB[(((40) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((41) - 1) * (4)) + (get_global_id(0))]) = (RF[(((41) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((42) - 1) * (4)) + (get_global_id(0))]) = (RF[(((42) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((43) - 1) * (4)) + (get_global_id(0))]) = (RF[(((43) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((44) - 1) * (4)) + (get_global_id(0))]) = (RF[(((44) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((45) - 1) * (4)) + (get_global_id(0))]) = (RF[(((45) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((46) - 1) * (4)) + (get_global_id(0))]) = (RF[(((46) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((47) - 1) * (4)) + (get_global_id(0))]) = (RF[(((47) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((48) - 1) * (4)) + (get_global_id(0))]) = (RF[(((48) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((49) - 1) * (4)) + (get_global_id(0))]) = (RF[(((49) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((50) - 1) * (4)) + (get_global_id(0))]) = (RF[(((50) - 1) * (4)) + (get_global_id(0))]) * xq2; (RB[(((50) - 1) * (4)) + (get_global_id(0))]) = (RB[(((50) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((51) - 1) * (4)) + (get_global_id(0))]) = (RF[(((51) - 1) * (4)) + (get_global_id(0))]) * xq2; (RB[(((51) - 1) * (4)) + (get_global_id(0))]) = (RB[(((51) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((52) - 1) * (4)) + (get_global_id(0))]) = (RF[(((52) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((53) - 1) * (4)) + (get_global_id(0))]) = (RF[(((53) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((54) - 1) * (4)) + (get_global_id(0))]) = (RF[(((54) - 1) * (4)) + (get_global_id(0))]) * xq2; (RB[(((54) - 1) * (4)) + (get_global_id(0))]) = (RB[(((54) - 1) * (4)) + (get_global_id(0))]) * xq1; (RF[(((55) - 1) * (4)) + (get_global_id(0))]) = (RF[(((55) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((56) - 1) * (4)) + (get_global_id(0))]) = (RF[(((56) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((59) - 1) * (4)) + (get_global_id(0))]) = (RF[(((59) - 1) * (4)) + (get_global_id(0))]) * xq3; (RB[(((59) - 1) * (4)) + (get_global_id(0))]) = (RB[(((59) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((60) - 1) * (4)) + (get_global_id(0))]) = (RF[(((60) - 1) * (4)) + (get_global_id(0))]) * xq3; (RB[(((60) - 1) * (4)) + (get_global_id(0))]) = (RB[(((60) - 1) * (4)) + (get_global_id(0))]) * xq1; (RF[(((61) - 1) * (4)) + (get_global_id(0))]) = (RF[(((61) - 1) * (4)) + (get_global_id(0))]) * xq3; (RF[(((62) - 1) * (4)) + (get_global_id(0))]) = (RF[(((62) - 1) * (4)) + (get_global_id(0))]) * xq3; (RB[(((62) - 1) * (4)) + (get_global_id(0))]) = (RB[(((62) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((63) - 1) * (4)) + (get_global_id(0))]) = (RF[(((63) - 1) * (4)) + (get_global_id(0))]) * xq3; (RF[(((64) - 1) * (4)) + (get_global_id(0))]) = (RF[(((64) - 1) * (4)) + (get_global_id(0))]) * xq3; (RF[(((65) - 1) * (4)) + (get_global_id(0))]) = (RF[(((65) - 1) * (4)) + (get_global_id(0))]) * xq3; (RF[(((66) - 1) * (4)) + (get_global_id(0))]) = (RF[(((66) - 1) * (4)) + (get_global_id(0))]) * xq3; (RF[(((67) - 1) * (4)) + (get_global_id(0))]) = (RF[(((67) - 1) * (4)) + (get_global_id(0))]) * xq3; (RB[(((67) - 1) * (4)) + (get_global_id(0))]) = (RB[(((67) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((68) - 1) * (4)) + (get_global_id(0))]) = (RF[(((68) - 1) * (4)) + (get_global_id(0))]) * xq3; (RB[(((68) - 1) * (4)) + (get_global_id(0))]) = (RB[(((68) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((69) - 1) * (4)) + (get_global_id(0))]) = (RF[(((69) - 1) * (4)) + (get_global_id(0))]) * xq3; (RB[(((69) - 1) * (4)) + (get_global_id(0))]) = (RB[(((69) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((70) - 1) * (4)) + (get_global_id(0))]) = (RF[(((70) - 1) * (4)) + (get_global_id(0))]) * xq3; (RB[(((71) - 1) * (4)) + (get_global_id(0))]) = (RB[(((71) - 1) * (4)) + (get_global_id(0))]) * xq5; (RB[(((72) - 1) * (4)) + (get_global_id(0))]) = (RB[(((72) - 1) * (4)) + (get_global_id(0))]) * xq4; (RB[(((73) - 1) * (4)) + (get_global_id(0))]) = (RB[(((73) - 1) * (4)) + (get_global_id(0))]) * xq4; (RB[(((74) - 1) * (4)) + (get_global_id(0))]) = (RB[(((74) - 1) * (4)) + (get_global_id(0))]) * xq4; (RB[(((75) - 1) * (4)) + (get_global_id(0))]) = (RB[(((75) - 1) * (4)) + (get_global_id(0))]) * xq4; (RB[(((76) - 1) * (4)) + (get_global_id(0))]) = (RB[(((76) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((77) - 1) * (4)) + (get_global_id(0))]) = (RF[(((77) - 1) * (4)) + (get_global_id(0))]) * xq1; (RB[(((80) - 1) * (4)) + (get_global_id(0))]) = (RB[(((80) - 1) * (4)) + (get_global_id(0))]) * xq2; (RB[(((81) - 1) * (4)) + (get_global_id(0))]) = (RB[(((81) - 1) * (4)) + (get_global_id(0))]) * xq3; (RB[(((82) - 1) * (4)) + (get_global_id(0))]) = (RB[(((82) - 1) * (4)) + (get_global_id(0))]) * xq5; (RB[(((85) - 1) * (4)) + (get_global_id(0))]) = (RB[(((85) - 1) * (4)) + (get_global_id(0))]) * xq5; (RF[(((87) - 1) * (4)) + (get_global_id(0))]) = (RF[(((87) - 1) * (4)) + (get_global_id(0))]) * xq1; (RB[(((87) - 1) * (4)) + (get_global_id(0))]) = (RB[(((87) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((88) - 1) * (4)) + (get_global_id(0))]) = (RF[(((88) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((89) - 1) * (4)) + (get_global_id(0))]) = (RF[(((89) - 1) * (4)) + (get_global_id(0))]) * xq4; (RB[(((90) - 1) * (4)) + (get_global_id(0))]) = (RB[(((90) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((91) - 1) * (4)) + (get_global_id(0))]) = (RF[(((91) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((92) - 1) * (4)) + (get_global_id(0))]) = (RF[(((92) - 1) * (4)) + (get_global_id(0))]) * xq3; (RB[(((94) - 1) * (4)) + (get_global_id(0))]) = (RB[(((94) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((96) - 1) * (4)) + (get_global_id(0))]) = (RF[(((96) - 1) * (4)) + (get_global_id(0))]) * xq5; (RF[(((97) - 1) * (4)) + (get_global_id(0))]) = (RF[(((97) - 1) * (4)) + (get_global_id(0))]) * xq5; (RF[(((98) - 1) * (4)) + (get_global_id(0))]) = (RF[(((98) - 1) * (4)) + (get_global_id(0))]) * xq5; (RB[(((98) - 1) * (4)) + (get_global_id(0))]) = (RB[(((98) - 1) * (4)) + (get_global_id(0))]) * xq3; (RF[(((99) - 1) * (4)) + (get_global_id(0))]) = (RF[(((99) - 1) * (4)) + (get_global_id(0))]) * xq5; (RF[(((100) - 1) * (4)) + (get_global_id(0))]) = (RF[(((100) - 1) * (4)) + (get_global_id(0))]) * xq5; (RF[(((101) - 1) * (4)) + (get_global_id(0))]) = (RF[(((101) - 1) * (4)) + (get_global_id(0))]) * xq5; (RF[(((105) - 1) * (4)) + (get_global_id(0))]) = (RF[(((105) - 1) * (4)) + (get_global_id(0))]) * xq1; (RF[(((106) - 1) * (4)) + (get_global_id(0))]) = (RF[(((106) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((107) - 1) * (4)) + (get_global_id(0))]) = (RF[(((107) - 1) * (4)) + (get_global_id(0))]) * xq3; (RB[(((108) - 1) * (4)) + (get_global_id(0))]) = (RB[(((108) - 1) * (4)) + (get_global_id(0))]) * xq3; (RF[(((111) - 1) * (4)) + (get_global_id(0))]) = (RF[(((111) - 1) * (4)) + (get_global_id(0))]) * xq1; (RF[(((112) - 1) * (4)) + (get_global_id(0))]) = (RF[(((112) - 1) * (4)) + (get_global_id(0))]) * xq2; (RB[(((112) - 1) * (4)) + (get_global_id(0))]) = (RB[(((112) - 1) * (4)) + (get_global_id(0))]) * xq7; (RB[(((114) - 1) * (4)) + (get_global_id(0))]) = (RB[(((114) - 1) * (4)) + (get_global_id(0))]) * xq6; (RF[(((115) - 1) * (4)) + (get_global_id(0))]) = (RF[(((115) - 1) * (4)) + (get_global_id(0))]) * xq7; (RB[(((117) - 1) * (4)) + (get_global_id(0))]) = (RB[(((117) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((120) - 1) * (4)) + (get_global_id(0))]) = (RF[(((120) - 1) * (4)) + (get_global_id(0))]) * xq4; (RB[(((120) - 1) * (4)) + (get_global_id(0))]) = (RB[(((120) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((122) - 1) * (4)) + (get_global_id(0))]) = (RF[(((122) - 1) * (4)) + (get_global_id(0))]) * xq6; (RF[(((123) - 1) * (4)) + (get_global_id(0))]) = (RF[(((123) - 1) * (4)) + (get_global_id(0))]) * xq6; (RB[(((123) - 1) * (4)) + (get_global_id(0))]) = (RB[(((123) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((124) - 1) * (4)) + (get_global_id(0))]) = (RF[(((124) - 1) * (4)) + (get_global_id(0))]) * xq6; (RF[(((125) - 1) * (4)) + (get_global_id(0))]) = (RF[(((125) - 1) * (4)) + (get_global_id(0))]) * xq6; (RB[(((125) - 1) * (4)) + (get_global_id(0))]) = (RB[(((125) - 1) * (4)) + (get_global_id(0))]) * xq2; (RB[(((126) - 1) * (4)) + (get_global_id(0))]) = (RB[(((126) - 1) * (4)) + (get_global_id(0))]) * xq9; (RB[(((130) - 1) * (4)) + (get_global_id(0))]) = (RB[(((130) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((132) - 1) * (4)) + (get_global_id(0))]) = (RF[(((132) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((133) - 1) * (4)) + (get_global_id(0))]) = (RF[(((133) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((134) - 1) * (4)) + (get_global_id(0))]) = (RF[(((134) - 1) * (4)) + (get_global_id(0))]) * xq7; (RB[(((134) - 1) * (4)) + (get_global_id(0))]) = (RB[(((134) - 1) * (4)) + (get_global_id(0))]) * xq6; (RF[(((135) - 1) * (4)) + (get_global_id(0))]) = (RF[(((135) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((136) - 1) * (4)) + (get_global_id(0))]) = (RF[(((136) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((137) - 1) * (4)) + (get_global_id(0))]) = (RF[(((137) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((138) - 1) * (4)) + (get_global_id(0))]) = (RF[(((138) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((139) - 1) * (4)) + (get_global_id(0))]) = (RF[(((139) - 1) * (4)) + (get_global_id(0))]) * xq7; (RB[(((139) - 1) * (4)) + (get_global_id(0))]) = (RB[(((139) - 1) * (4)) + (get_global_id(0))]) * xq9; (RF[(((140) - 1) * (4)) + (get_global_id(0))]) = (RF[(((140) - 1) * (4)) + (get_global_id(0))]) * xq7; (RB[(((140) - 1) * (4)) + (get_global_id(0))]) = (RB[(((140) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((141) - 1) * (4)) + (get_global_id(0))]) = (RF[(((141) - 1) * (4)) + (get_global_id(0))]) * xq7; (RB[(((141) - 1) * (4)) + (get_global_id(0))]) = (RB[(((141) - 1) * (4)) + (get_global_id(0))]) * xq9; (RF[(((142) - 1) * (4)) + (get_global_id(0))]) = (RF[(((142) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((144) - 1) * (4)) + (get_global_id(0))]) = (RF[(((144) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((145) - 1) * (4)) + (get_global_id(0))]) = (RF[(((145) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((146) - 1) * (4)) + (get_global_id(0))]) = (RF[(((146) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((147) - 1) * (4)) + (get_global_id(0))]) = (RF[(((147) - 1) * (4)) + (get_global_id(0))]) * xq9; (RF[(((148) - 1) * (4)) + (get_global_id(0))]) = (RF[(((148) - 1) * (4)) + (get_global_id(0))]) * xq9; (RF[(((149) - 1) * (4)) + (get_global_id(0))]) = (RF[(((149) - 1) * (4)) + (get_global_id(0))]) * xq9; (RB[(((149) - 1) * (4)) + (get_global_id(0))]) = (RB[(((149) - 1) * (4)) + (get_global_id(0))]) * xq4; (RF[(((150) - 1) * (4)) + (get_global_id(0))]) = (RF[(((150) - 1) * (4)) + (get_global_id(0))]) * xq9; (RF[(((151) - 1) * (4)) + (get_global_id(0))]) = (RF[(((151) - 1) * (4)) + (get_global_id(0))]) * xq9; (RF[(((152) - 1) * (4)) + (get_global_id(0))]) = (RF[(((152) - 1) * (4)) + (get_global_id(0))]) * xq9; (RF[(((153) - 1) * (4)) + (get_global_id(0))]) = (RF[(((153) - 1) * (4)) + (get_global_id(0))]) * xq9; (RF[(((154) - 1) * (4)) + (get_global_id(0))]) = (RF[(((154) - 1) * (4)) + (get_global_id(0))]) * xq9; (RB[(((155) - 1) * (4)) + (get_global_id(0))]) = (RB[(((155) - 1) * (4)) + (get_global_id(0))]) * xq6; (RB[(((156) - 1) * (4)) + (get_global_id(0))]) = (RB[(((156) - 1) * (4)) + (get_global_id(0))]) * xq8; (RB[(((157) - 1) * (4)) + (get_global_id(0))]) = (RB[(((157) - 1) * (4)) + (get_global_id(0))]) * xq7; (RB[(((158) - 1) * (4)) + (get_global_id(0))]) = (RB[(((158) - 1) * (4)) + (get_global_id(0))]) * xq7; (RB[(((159) - 1) * (4)) + (get_global_id(0))]) = (RB[(((159) - 1) * (4)) + (get_global_id(0))]) * xq4; (RB[(((160) - 1) * (4)) + (get_global_id(0))]) = (RB[(((160) - 1) * (4)) + (get_global_id(0))]) * xq2; (RB[(((161) - 1) * (4)) + (get_global_id(0))]) = (RB[(((161) - 1) * (4)) + (get_global_id(0))]) * xq7; (RB[(((162) - 1) * (4)) + (get_global_id(0))]) = (RB[(((162) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((164) - 1) * (4)) + (get_global_id(0))]) = (RF[(((164) - 1) * (4)) + (get_global_id(0))]) * xq4; (RB[(((164) - 1) * (4)) + (get_global_id(0))]) = (RB[(((164) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((165) - 1) * (4)) + (get_global_id(0))]) = (RF[(((165) - 1) * (4)) + (get_global_id(0))]) * xq2; (RF[(((166) - 1) * (4)) + (get_global_id(0))]) = (RF[(((166) - 1) * (4)) + (get_global_id(0))]) * xq3; (RB[(((166) - 1) * (4)) + (get_global_id(0))]) = (RB[(((166) - 1) * (4)) + (get_global_id(0))]) * xq6; (RF[(((167) - 1) * (4)) + (get_global_id(0))]) = (RF[(((167) - 1) * (4)) + (get_global_id(0))]) * xq3; (RB[(((168) - 1) * (4)) + (get_global_id(0))]) = (RB[(((168) - 1) * (4)) + (get_global_id(0))]) * xq7; (RB[(((169) - 1) * (4)) + (get_global_id(0))]) = (RB[(((169) - 1) * (4)) + (get_global_id(0))]) * xq10; (RF[(((170) - 1) * (4)) + (get_global_id(0))]) = (RF[(((170) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((171) - 1) * (4)) + (get_global_id(0))]) = (RF[(((171) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((172) - 1) * (4)) + (get_global_id(0))]) = (RF[(((172) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((173) - 1) * (4)) + (get_global_id(0))]) = (RF[(((173) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((174) - 1) * (4)) + (get_global_id(0))]) = (RF[(((174) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((175) - 1) * (4)) + (get_global_id(0))]) = (RF[(((175) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((176) - 1) * (4)) + (get_global_id(0))]) = (RF[(((176) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((177) - 1) * (4)) + (get_global_id(0))]) = (RF[(((177) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((178) - 1) * (4)) + (get_global_id(0))]) = (RF[(((178) - 1) * (4)) + (get_global_id(0))]) * xq8; (RB[(((180) - 1) * (4)) + (get_global_id(0))]) = (RB[(((180) - 1) * (4)) + (get_global_id(0))]) * xq8; (RB[(((181) - 1) * (4)) + (get_global_id(0))]) = (RB[(((181) - 1) * (4)) + (get_global_id(0))]) * xq8; (RB[(((182) - 1) * (4)) + (get_global_id(0))]) = (RB[(((182) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((183) - 1) * (4)) + (get_global_id(0))]) = (RF[(((183) - 1) * (4)) + (get_global_id(0))]) * xq3; (RB[(((183) - 1) * (4)) + (get_global_id(0))]) = (RB[(((183) - 1) * (4)) + (get_global_id(0))]) * xq8; (RB[(((184) - 1) * (4)) + (get_global_id(0))]) = (RB[(((184) - 1) * (4)) + (get_global_id(0))]) * xq8; (RB[(((186) - 1) * (4)) + (get_global_id(0))]) = (RB[(((186) - 1) * (4)) + (get_global_id(0))]) * xq6; (RB[(((188) - 1) * (4)) + (get_global_id(0))]) = (RB[(((188) - 1) * (4)) + (get_global_id(0))]) * xq7; (RF[(((189) - 1) * (4)) + (get_global_id(0))]) = (RF[(((189) - 1) * (4)) + (get_global_id(0))]) * xq4; (RB[(((190) - 1) * (4)) + (get_global_id(0))]) = (RB[(((190) - 1) * (4)) + (get_global_id(0))]) * xq10; (RF[(((199) - 1) * (4)) + (get_global_id(0))]) = (RF[(((199) - 1) * (4)) + (get_global_id(0))]) * xq10; (RB[(((199) - 1) * (4)) + (get_global_id(0))]) = (RB[(((199) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((200) - 1) * (4)) + (get_global_id(0))]) = (RF[(((200) - 1) * (4)) + (get_global_id(0))]) * xq10; (RF[(((201) - 1) * (4)) + (get_global_id(0))]) = (RF[(((201) - 1) * (4)) + (get_global_id(0))]) * xq10; (RB[(((201) - 1) * (4)) + (get_global_id(0))]) = (RB[(((201) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((202) - 1) * (4)) + (get_global_id(0))]) = (RF[(((202) - 1) * (4)) + (get_global_id(0))]) * xq10; (RF[(((203) - 1) * (4)) + (get_global_id(0))]) = (RF[(((203) - 1) * (4)) + (get_global_id(0))]) * xq10; (RF[(((204) - 1) * (4)) + (get_global_id(0))]) = (RF[(((204) - 1) * (4)) + (get_global_id(0))]) * xq10; (RB[(((204) - 1) * (4)) + (get_global_id(0))]) = (RB[(((204) - 1) * (4)) + (get_global_id(0))]) * xq8; (RF[(((205) - 1) * (4)) + (get_global_id(0))]) = (RF[(((205) - 1) * (4)) + (get_global_id(0))]) * xq10; }
float3 matrixmul3(const constant float* m, float3 v) { float3 retr; retr.x = dot(vload3(0, m), v); retr.y = dot(vload3(1, m), v); retr.z = dot(vload3(2, m), v); return retr; } float4 matrixmul4(const constant float* m, float4 v) { float4 retr; retr.x = dot(vload4(0, m), v); retr.y = dot(vload4(1, m), v); retr.z = dot(vload4(2, m), v); retr.w = dot(vload4(3, m), v); return retr; } int is_finite(float3 v) { return isfinite(v.x) && isfinite(v.y) && isfinite(v.z); } void zero_ab(local float* ms) { for (size_t i = 0; i < (27U); ++i) ms[i] = 0; } void icp(float3 p, float3 q, float3 n, local float* ms) { float3 c = cross(p, n); float pqn = dot(p - q, n); ms[0] = c.x * c.x; ms[1] = c.x * c.y; ms[2] = c.x * c.z; ms[3] = c.x * n.x; ms[4] = c.x * n.y; ms[5] = c.x * n.z; ms[6] = c.y * c.y; ms[7] = c.y * c.z; ms[8] = c.y * n.x; ms[9] = c.y * n.y; ms[10] = c.y * n.z; ms[11] = c.z * c.z; ms[12] = c.z * n.x; ms[13] = c.z * n.y; ms[14] = c.z * n.z; ms[15] = n.x * n.x; ms[16] = n.x * n.y; ms[17] = n.x * n.z; ms[18] = n.y * n.y; ms[19] = n.y * n.z; ms[20] = n.z * n.z; pqn *= -1; ms[21] = c.x * pqn; ms[22] = c.y * pqn; ms[23] = c.z * pqn; ms[24] = n.x * pqn; ms[25] = n.y * pqn; ms[26] = n.z * pqn; } void correspondences_impl(const global float* map, const global float* prev_map, const constant float* t_frame_frame, const constant float* t_z, float epsilon_d, float epsilon_theta, const constant float* k, size_t x, size_t y, size_t width, size_t height, local float* ms) { size_t idx = (y * width) + x; idx *= 2U; float3 curr_v = vload3(idx, map); float3 curr_n = vload3(idx + 1U, map); if (!is_finite(curr_v) || !is_finite(curr_n)) { zero_ab(ms); return; } float4 curr_v_homo = (float4)(curr_v, 1); float4 v_pc_h = matrixmul4(t_frame_frame, curr_v_homo); float3 v_pc = (float3)(v_pc_h.x, v_pc_h.y, v_pc_h.z); float3 uv3 = matrixmul3(k, v_pc); int2 u = (int2)(round(uv3.x / uv3.z), round(uv3.y / uv3.z)); if ((u.x < 0) || (u.y < 0) || (((size_t)u.x) >= width) || (((size_t)u.y) >= height)) { zero_ab(ms); return; } size_t lin_idx = u.x + u.y * width; lin_idx *= 2U; float3 curr_pv = vload3(lin_idx, prev_map); float3 curr_pn = vload3(lin_idx + 1U, prev_map); if (!(is_finite(curr_pv) && is_finite(curr_pn))) { zero_ab(ms); return; } float4 curr_pv_homo = (float4)(curr_pv, 1); float4 t_z_curr_v_homo = matrixmul4(t_z, curr_v_homo); float4 t_z_curr_v_homo_curr_pv_homo = t_z_curr_v_homo - curr_pv_homo; float3 t_z_curr_v = (float3)(t_z_curr_v_homo.x, t_z_curr_v_homo.y, t_z_curr_v_homo.z); if (fast_length(t_z_curr_v_homo_curr_pv_homo) > epsilon_d) { zero_ab(ms); return; } float3 r_z_curr_n; r_z_curr_n.x = (t_z[0] * curr_n.x) + (t_z[1] * curr_n.y) + (t_z[2] * curr_n.z); r_z_curr_n.y = (t_z[4] * curr_n.x) + (t_z[5] * curr_n.y) + (t_z[6] * curr_n.z); r_z_curr_n.z = (t_z[8] * curr_n.x) + (t_z[9] * curr_n.y) + (t_z[10] * curr_n.z); float3 crzcncpn = cross(r_z_curr_n, curr_pn); if (fast_length(crzcncpn) > epsilon_theta) { zero_ab(ms); return; } icp(t_z_curr_v, curr_pv, curr_pn, ms); } void parallel_sum_impl(size_t l, size_t size, global float* dest, local float* lmats) { for (size_t stride = size / 2U; stride > 0; stride /= 2U) { barrier(0x01); if (l >= stride) continue; local float* a = lmats + (l * (27U)); const local float* b = lmats + ((l + stride) * (27U)); for (size_t i = 0; i < (27U); ++i) a[i] += b[i]; } if (l != 0) return; for (size_t i = 0; i < (27U); ++i, ++dest) *dest = lmats[i]; } kernel void parallel_sum(const global float* src, global float* dest, local float* lmats) { size_t g = get_global_id(0); size_t l = get_local_id(0); const global float* ld = src + (g * (27U)); local float* sv = lmats + (l * (27U)); for (size_t i = 0; i < (27U); ++i, ++sv, ++ld) *sv = *ld; parallel_sum_impl(l, get_local_size(0), dest + (get_group_id(0) * (27U)), lmats); }
kernel void loop(global float* a) { for (int i = 0; i < 100; i++) { a[i] = i * 2; } }
kernel void minus(global long* out, long in) { out[0] = -in; }
kernel void dynproc_kernel(global int* restrict wall, global int* restrict src, global int* restrict dst, int cols, int t) { for (int n = 0; n < cols; n++) { int min = src[n]; if (n > 0) { min = ((min) <= (src[n - 1]) ? (min) : (src[n - 1])); } if (n < cols - 1) { min = ((min) <= (src[n + 1]) ? (min) : (src[n + 1])); } dst[n] = wall[(t + 1) * cols + n] + min; } }
kernel void intraBlockInclusiveScanByKey(global unsigned int* keySumArray, global int* preSumArray, global int* postSumArray, const unsigned int vecSize, local unsigned int* ldsKeys, local int* ldsVals, const unsigned int workPerThread) { size_t groId = get_group_id(0); size_t gloId = get_global_id(0); size_t locId = get_local_id(0); size_t wgSize = get_local_size(0); unsigned int mapId = gloId * workPerThread; unsigned int offset; unsigned int key; int workSum; if (mapId < vecSize) { unsigned int prevKey; offset = 0; key = keySumArray[mapId + offset]; workSum = preSumArray[mapId + offset]; postSumArray[mapId + offset] = workSum; for (offset = offset + 1; offset < workPerThread; offset += 1) { prevKey = key; key = keySumArray[mapId + offset]; if (mapId + offset < vecSize) { int y = preSumArray[mapId + offset]; if (key == prevKey) { workSum = (workSum + y); } else { workSum = y; } postSumArray[mapId + offset] = workSum; } } } barrier(0x01); int scanSum = workSum; offset = 1; ldsVals[locId] = workSum; ldsKeys[locId] = key; for (offset = offset * 1; offset < wgSize; offset *= 2) { barrier(0x01); if (mapId < vecSize) { if (locId >= offset) { int y = ldsVals[locId - offset]; unsigned int key1 = ldsKeys[locId]; unsigned int key2 = ldsKeys[locId - offset]; if (key1 == key2) { scanSum = (scanSum + y); } else scanSum = ldsVals[locId]; } } barrier(0x01); ldsVals[locId] = scanSum; } barrier(0x01); for (offset = 0; offset < workPerThread; offset += 1) { barrier(0x02); if (mapId < vecSize && locId > 0) { int y = postSumArray[mapId + offset]; unsigned int key1 = keySumArray[mapId + offset]; unsigned int key2 = ldsKeys[locId - 1]; if (key1 == key2) { int y2 = ldsVals[locId - 1]; y = (y + y2); } postSumArray[mapId + offset] = y; } } }
kernel void sph_kernel_indexx(int kParticleCount, global float4* sortedPos, global int* gridCellIdx) { unsigned int gid = get_global_id(0); gridCellIdx[gid] = -1; int low = 0; int hi = kParticleCount - 1; int mid = 0; while (low <= hi) { mid = (hi + low) / 2; if (floor(sortedPos[mid].w) == gid) { int front = mid - 1; while ((front >= 0) && (sortedPos[front].w == gid)) { front--; } if (mid > front - 1) { gridCellIdx[gid] = front + 1; } break; } else if (sortedPos[mid].w < gid) { low = mid + 1; } else { hi = mid - 1; } } }
kernel void saxpy_naive(const int numElems, const float factor, global const float* src_0, global const float* src_1, global float* dst_0) { unsigned int gid = get_global_id(0); if (gid < numElems) dst_0[gid] = factor * src_0[gid] * src_1[gid]; }
kernel void test_arg_1_1_kern(global float* a0, global float* b0) { unsigned int gtid = get_global_id(0); float tmp0 = a0[gtid] + 0.1f; b0[gtid] = (0.0f + 1.1f) * (+tmp0); }
kernel void double_test(global float* a, global float* b, global float* out) { *out = *a * *b; }
kernel void isnotequal_float2float2(global float2* src_0, global float2* src_1, global int2* dst) { int gid = get_global_id(0); dst[gid] = (int2)(isnotequal(src_0[gid], src_1[gid])); }
kernel void Reduction_Decomp(const global unsigned int* inArray, global unsigned int* outArray, unsigned int N, local unsigned int* block) { int LID = get_local_id(0); int Elem = get_local_size(0) * get_group_id(0) * 2 + LID; int LSize = get_local_size(0); block[LID] = inArray[Elem] + inArray[Elem + LSize]; barrier(0x01); for (int stride = LSize / 2; stride >= 1; stride /= 2) { if (LID < stride) block[LID] += block[LID + stride]; barrier(0x01); } if (LID == 0) outArray[get_group_id(0)] = block[0]; }
kernel void Sdot_naive(int n, global float* x, int incx, global float* y, int incy, global float* result) { float acc = 0.f; for (int i = 0; i < n; ++i) { acc += x[i * incx] * y[i * incy]; ; } result[0] = acc; }
__attribute__((work_group_size_hint(256, 1, 1))) kernel void vector_equals(global const float* x, const unsigned int offset_x, const unsigned int stride_x, global const float* y, const unsigned int offset_y, const unsigned int stride_y, global unsigned int* eq_flag) { const unsigned int ix = offset_x + get_global_id(0) * stride_x; const unsigned int iy = offset_y + get_global_id(0) * stride_y; if (x[ix] != y[iy]) { eq_flag[0]++; } }
kernel void test_arg_1_1_kern(global float4* a0, global float4* b0) { float4 za = (float4)(0.75f, 0.5f, 0.25f, 0.33f); unsigned int gtid = get_global_id(0); float4 tmp0 = a0[gtid] + 0.1f + za; b0[gtid] = (0.0f + 1.1f) * (+tmp0); }
float boundRange(float x, float lowerLimit, float upperLimit) { return (x < lowerLimit ? lowerLimit : (x > upperLimit ? upperLimit : x)); } float Logistic_fn(float x) { if (x < 88.722839f) { if (x > -88.722839f) return (float)1.0 / ((float)1.0 + exp(-x)); else return 0; } return 1; } float Maxmin1_fn(float x) { return ((float)2.0 * Logistic_fn(x) - (float)1.0); } float Tanh_fn(float x) { return Maxmin1_fn((float)2.0 * x); } float Identity_fn(float x) { return x; } float Tanh_deriv(float y) { return (float)1.0 - (y * y); } float Logistic_deriv(float y) { return y * ((float)1.0 - y); } float Identity_deriv(float y) { return 1; } kernel void bcl_computeCrossEntropyErrorFn(global char* patTypes, global float* targets, global float* outputs, global float* out, local float* shared, int n) { int index = get_local_id(0); shared[get_local_id(0)] = 0; barrier(0x01); while (index < n) { if (patTypes[index] != 0) { float target = targets[index]; float output = outputs[index]; float act = max(output, 1.1754944e-038f); float targetProb = (target > 0 ? act : 1 - act); float error = -log(targetProb); shared[get_local_id(0)] += error; } index += get_local_size(0); } index = get_local_id(0); barrier(0x01); for (unsigned int s = get_local_size(0) / 2; s > 0; s >>= 1) { if (index < s) { shared[index] += shared[index + s]; } barrier(0x01); } if (get_local_id(0) == 0) { out[0] = shared[0]; } }
kernel void test_normalize(const global float* in, global float* out) { unsigned int gid = get_global_id(0); vstore3(normalize(vload3(gid, in)), gid, out); }
kernel void sub(global double* a, global const double* b, const int aoffset, const int boffset) { int gid = get_global_id(0); a[gid + aoffset] -= b[gid + boffset]; }
kernel void multiply_matrix(global float* m1, global float* m2, global float* res, unsigned long int wm1, unsigned long int wm2) { unsigned long int i = get_group_id(0); unsigned long int j = get_local_id(0); unsigned long int k; float sum = 0.0f; for (k = 0; k < wm1; ++k) sum += m1[i * wm1 + k] * m2[k * wm2 + j]; res[i * wm2 + j] = sum; }
kernel void kernel_fmin_withoutDD1(global float* result_fmin, int N) { float t1 = 0.234; float t2 = 0.235; float t3 = t1; float t4 = t3; float t5 = t4; float t6 = t5; float t7 = t6; float t8 = t7; float t9 = t8; float t10 = t9; float t11 = 0.234; float t12 = 0.235; float t13 = t1; float t14 = t3; float t15 = t4; float t16 = t5; float t17 = t6; float t18 = t7; float t19 = t8; float t20 = t9; float t21 = 0.234; float t22 = 0.235; float t23 = t1; float t24 = t3; float t25 = t4; float t26 = t5; float t27 = t6; float t28 = t7; float t29 = t8; float t30 = t9; float i = 0.01; int j = 0; for (j = 0; j <= 100 * N; j++) { t1 += fmin(t1, i); t2 += fmin(t2, i); t3 += fmin(t3, i); t4 += fmin(t4, i); t5 += fmin(t5, i); t6 += fmin(t6, i); t7 += fmin(t7, i); t8 += fmin(t8, i); t9 += fmin(t9, i); t10 += fmin(t10, i); t11 += fmin(t11, i); t12 += fmin(t12, i); t13 += fmin(t13, i); t14 += fmin(t14, i); t15 += fmin(t15, i); t16 += fmin(t16, i); t17 += fmin(t17, i); t18 += fmin(t18, i); t19 += fmin(t19, i); t20 += fmin(t20, i); t21 += fmin(t21, i); t22 += fmin(t22, i); t23 += fmin(t23, i); t24 += fmin(t24, i); t25 += fmin(t25, i); t26 += fmin(t26, i); t27 += fmin(t27, i); t28 += fmin(t28, i); t29 += fmin(t29, i); t30 += fmin(t30, i); } *result_fmin = t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + t11 + t12 + t13 + t14 + t15 + t16 + t17 + t18 + t19 + t20 + t21 + t22 + t23 + t24 + t25 + t26 + t27 + t28 + t29 + t30; }
kernel void private_array_initializer_list(global float* output) { float scratch[4] = {7.f, 42.f, -1.f, 0.f}; for (int i = 0; i < 4; i++) { output[i] = scratch[i]; } }
kernel void prefixSum(global int* restrict output, global int* restrict input, const unsigned int in_size) { output[0] = 0; for (int i = 1; i < in_size; i++) output[i] = output[i - 1] + input[i - 1]; }
kernel void createSpace(float d1, float d2, float n, global float* result, int type) { int i = get_global_id(0); float n1 = floor(n) - 1; float value = d1 + i * (d2 - d1) / n1; if (type == 1) result[i] = value; else result[i] = pown(value, 10); if (i == n1) { result[0] = d1; result[i] = d2; } return; }
typedef enum { LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN, LHTAN } ACTIVATION; kernel void image2columarray3x3(int n, global float* data_im, int height, int width, int ksize, const int pad, int stride, int height_col, int width_col, global float* data_col) { int index = get_global_id(0); int stepSize = get_local_size(0) * get_num_groups(0); int w_out, h_index, h_out, channel_in, channel_out, h_in, w_in, i, j, h, w; for (; index < n; index += stepSize) { w_out = index % width_col; h_index = index / width_col; h_out = h_index % height_col; channel_in = h_index / height_col; channel_out = channel_in * ksize * ksize; h_in = h_out * stride - pad; w_in = w_out * stride - pad; global float* data_col_ptr = data_col; data_col_ptr += (channel_out * height_col + h_out) * width_col + w_out; const global float* data_im_ptr = data_im; data_im_ptr += (channel_in * height + h_in) * width + w_in; for (i = 0; i < 3; ++i) { for (j = 0; j < 3; ++j) { h = h_in + i; w = w_in + j; *data_col_ptr = (h >= 0 && w >= 0 && h < height && w < width) ? data_im_ptr[i * width + j] : 0; data_col_ptr += height_col * width_col; } } } }
kernel void vector_mult_opencl(global float* val, int nx, float factor) { const int i = get_global_id(0); if (i < nx) { val[i] *= factor; } }
kernel void find_minimum(global const float* values, global float* results, local float* scratch) { int i = get_local_id(0); int n = get_local_size(0); scratch[i] = values[get_global_id(0)]; barrier(0x01); for (int j = n / 2; j > 0; j /= 2) { if (i < j) scratch[i] = min(scratch[i], scratch[i + j]); barrier(0x01); } if (i == 0) results[get_group_id(0)] = scratch[0]; }
kernel void test_select_read_address_simple(const global int* in0, const global int* in1, global int* out) { unsigned int gid = (unsigned int)get_global_id(0); const global int* ptr = (gid & 1) ? in1 : in0; int tmp = ptr[gid]; out[gid] = tmp + 17; }
kernel void prescanReduce(global unsigned int const* restrict a, global unsigned int* restrict sum, unsigned int m, unsigned int n) { size_t localID = get_local_id(0); size_t groupID = get_group_id(0); local unsigned int lsum[256]; m >>= 2; global uint4* a4 = (global uint4*)a; size_t startIndex = m * groupID; size_t stopIndex = startIndex + m; uint4 sum4 = 0; for (size_t i = startIndex; i < stopIndex; i += 256) sum4 += a4[i + localID]; lsum[localID] = sum4.x + sum4.y + sum4.z + sum4.w; barrier(0x01); for (size_t offset = 128; offset >= 2; offset >>= 1) { if (localID < offset) lsum[localID] += lsum[localID + offset]; barrier(0x01); } if (localID == 0) sum[groupID] = lsum[localID] + lsum[localID + 1]; } kernel __attribute__((reqd_work_group_size(16, 1, 1))) void prescanLocal16(global unsigned int* restrict sum) { size_t localID = get_local_id(0); local unsigned int lsum[16 + 16 / 2]; global uint4* sum4 = (global uint4*)sum; if (localID < 16 / 2) lsum[localID] = 0; size_t idx = localID + 16 / 2; uint4 val = sum4[localID]; lsum[idx] = val.x + val.y + val.z + val.w; lsum[idx] += lsum[idx - 1]; lsum[idx] += lsum[idx - 2]; lsum[idx] += lsum[idx - 4]; lsum[idx] += lsum[idx - 8]; unsigned int p = lsum[idx - 1]; uint4 result; result.x = p; p += val.x; result.y = p; p += val.y; result.z = p; p += val.z; result.w = p; sum4[localID] = result; } kernel __attribute__((reqd_work_group_size(64, 1, 1))) void prescanLocal64(global unsigned int* restrict sum) { local unsigned int lsum[32 + 64]; global uint4* sum4 = (global uint4*)sum; size_t localID = get_local_id(0); size_t idx = localID + 32; lsum[localID] = 0; uint4 val = sum4[localID]; unsigned int sl = val.x + val.y, sh = val.z + val.w; uint4 res = (uint4)(sl + sh, val.y + sh, sh, val.w); lsum[idx] = res.x; lsum[idx] += lsum[idx - 1]; lsum[idx] += lsum[idx - 2]; lsum[idx] += lsum[idx - 4]; lsum[idx] += lsum[idx - 8]; lsum[idx] += lsum[idx - 16]; unsigned int p = lsum[idx] + lsum[idx - 32]; sum4[localID] = (uint4)(p)-res; } kernel void prescanLocal2(global unsigned int* restrict sum) { size_t localID = get_local_id(0); size_t localWork = get_local_size(0); local unsigned int lsum[256]; global uint4* sum4 = (global uint4*)sum; uint4 val = sum4[localID]; lsum[localID] = val.x + val.y + val.z + val.w; barrier(0x01); unsigned int d2; unsigned int dstop = localWork >> 1; for (unsigned int d = 1; d < dstop; d = d2) { d2 = 2 * d; if ((localID + 1) % d2 == 0) { lsum[localID] += lsum[localID - d]; } barrier(0x01); } if (localID == localWork - 1) { unsigned int indexLeft = localID - dstop; lsum[localID] = lsum[indexLeft]; lsum[indexLeft] = 0; } barrier(0x01); for (unsigned int d = dstop; d >= 2; d = d2) { d2 = d / 2; if ((localID + 1) % d == 0) { unsigned int indexLeft = localID - d2; unsigned int t = lsum[indexLeft]; lsum[indexLeft] = lsum[localID]; lsum[localID] += t; } barrier(0x01); } unsigned int p = lsum[localID]; uint4 result; result.x = p; p += val.x; result.y = p; p += val.y; result.z = p; p += val.z; result.w = p; sum4[localID] = result; }
float linear_to_gamma_2_2(float value); float gamma_2_2_to_linear(float value); float linear_to_gamma_2_2(float value) { if (value > 0.003130804954f) return 1.055f * native_powr(value, (1.0f / 2.4f)) - 0.055f; return 12.92f * value; } float gamma_2_2_to_linear(float value) { if (value > 0.04045f) return native_powr((value + 0.055f) / 1.055f, 2.4f); return value / 12.92f; } kernel void rgbaf_to_rgba_gamma_f(global const float4* in, global float4* out) { int gid = get_global_id(0); float4 in_v = in[gid]; float4 out_v; out_v = (float4)(linear_to_gamma_2_2(in_v.x), linear_to_gamma_2_2(in_v.y), linear_to_gamma_2_2(in_v.z), in_v.w); out[gid] = out_v; }
kernel void compiler_double_convert_float(global double* src, global float* dst) { int i = get_global_id(0); float f = src[i]; dst[i] = f; }
kernel void paste(global int* histograms, global int* globsum) { int ig = get_global_id(0); int gr = get_group_id(0); int s; s = globsum[gr]; histograms[2 * ig] += s; histograms[2 * ig + 1] += s; barrier(0x02); }
kernel void minus(global short* out, short in) { out[0] = -in; }
kernel void testMemCL(global unsigned int* memoryC, global const unsigned int* memoryA, global const unsigned int* memoryB) { size_t id = get_global_id(0); memoryC[id] = memoryA[id] + memoryB[id]; }
constant float beta = 0.66666f; kernel void calc_layer_gradient(global const float* inputs, global const float* errors, int inputs_ofs, int errors_ofs, int inputs_per_neuron, int grad_ofs, global float* gradient, int weights_count, local float* temp_mem) { int i = get_global_id(0); global const float* err = errors + errors_ofs; global const float* inp = inputs + inputs_ofs; global float* grad = gradient + grad_ofs; int input_index = i % inputs_per_neuron; int error_index = i / inputs_per_neuron; int lid = get_local_id(0); int lid_inp = lid % inputs_per_neuron; int lid_div_inp = lid / inputs_per_neuron; if (lid < inputs_per_neuron) temp_mem[lid] = input_index == 0 ? 1.0 : inp[input_index - 1]; if (lid_inp == 0) temp_mem[inputs_per_neuron + lid_div_inp] = err[error_index]; float g = grad[i]; barrier(0x01); if (i >= weights_count) return; float e = temp_mem[inputs_per_neuron + lid_div_inp] * temp_mem[lid_inp]; grad[i] = g + e; }
kernel void frequencies(global double* kx, const double Lx, const int Nx) { const int ind = get_global_id(0); if (ind < Nx / 2) kx[ind] = -1.0 * ((double)((ind)) / Lx) * ((double)(ind) / Lx); if (ind == Nx / 2) kx[ind] = 0.0; if (ind > Nx / 2) kx[ind] = -1.0 * (double)(Nx - ind) / Lx * (double)(Nx - ind) / Lx; }
kernel void cl_square_array_int(global float* in_data, global float* out_data) { int g_x = get_global_id(0); int l_x = get_local_id(0); int size_g_x = get_global_size(0); int size_l_x = get_local_size(0); if (g_x < size_g_x && l_x < size_l_x) out_data[l_x + (g_x * size_l_x)] = sqrt(in_data[l_x + (g_x * size_l_x)]); }
kernel void test_arg_4_1_kern(global int* a0, global int* a1, global int* a2, global int* a3, global int* b0) { unsigned int gtid = get_global_id(0); int tmp0 = a0[gtid] + 0; int tmp1 = a1[gtid] + 1; int tmp2 = a2[gtid] + 2; int tmp3 = a3[gtid] + 3; b0[gtid] = (0 + 1) * (+tmp0 + tmp1 + tmp2 + tmp3); }
kernel void scaleAdd_vector(global double* a, const int aoffset, const double afactor, global double* b, const int boffset, const double bfactor, const double c) { int i = get_global_id(0); a[i + aoffset] = (a[i + aoffset] * afactor) + (b[i + boffset] * bfactor) + c; }
kernel void compute_means(global unsigned int* coords, global int* sizes) { int pos = get_global_id(0); uint2 sum = vload2(pos, coords); int size = sizes[pos]; uint2 centroid = (uint2)(sum.x / size, sum.y / size); vstore2(centroid, pos, coords); }
int baz(global int* x) { return x[0]; } int bar(global int* x) { return baz(x); } kernel void foo(global int* data) { int x = bar(data); barrier(0x02); data[1] = x; }
kernel void blockAddition_kernel(global int* restrict input, global int* restrict output) { int globalId = get_global_id(0); int groupId = get_group_id(0); int localId = get_local_id(0); local int value[1]; if (localId == 0) { value[0] = input[groupId]; } barrier(0x01); output[globalId * 2] += value[0]; output[globalId * 2 + 1] += value[0]; }
int getPosHash(int4 gridPos, global float4* pParams) { int4 gridDim = *((global int4*)(pParams + 1)); gridPos.x &= gridDim.x - 1; gridPos.y &= gridDim.y - 1; gridPos.z &= gridDim.z - 1; int hash = gridPos.z * gridDim.y * gridDim.x + gridPos.y * gridDim.x + gridPos.x; return hash; } int4 getGridPos(float4 worldPos, global float4* pParams) { int4 gridPos; int4 gridDim = *((global int4*)(pParams + 1)); gridPos.x = (int)floor(worldPos.x * pParams[0].x) & (gridDim.x - 1); gridPos.y = (int)floor(worldPos.y * pParams[0].y) & (gridDim.y - 1); gridPos.z = (int)floor(worldPos.z * pParams[0].z) & (gridDim.z - 1); return gridPos; } kernel void kClearCellStart(int numCells, global int* pCellStart) { int index = get_global_id(0); if (index >= numCells) { return; } pCellStart[index] = -1; }
kernel void test_tgamma(const global float* in, global float* out) { size_t gid = get_global_id(0); out[gid] = tgamma(in[gid]); }
kernel void dlacpy_kernel(int m, int n, global double* A, int offset_A, int lda, global double* B, int offset_B, int ldb) { int row = get_group_id(0) * 64 + get_local_id(0); if (row < m) { A += (offset_A + row); B += (offset_B + row); global double* Aend = A + lda * n; while (A < Aend) { *B = *A; A += lda; B += ldb; } } }
kernel void matMulSingle(global int* matC, const unsigned int mC, const unsigned int nC, const global int* matA, const unsigned int mA, const unsigned int nA, const global int* matB, const unsigned int mB, const unsigned int nB) { unsigned int w = get_global_id(0); unsigned int c = w % nC; unsigned int r = (w - c) / nC; if (w >= mC * nC) return; int tmp = 0; for (size_t j = 0; j < nA && j < mB; ++j) { tmp += matA[r * nA + j] * matB[j * nB + c]; } matC[w] = tmp; }