Created
March 29, 2023 23:59
-
-
Save doug65536/399ab9c9cc26363ac163d3a6d5e30bb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define __restrict __restrict__ | |
__kernel void genann_run_input_to_hidden( | |
genann_cfg const __constant *__restrict ann, | |
genann_real __global *__restrict data) | |
{ | |
// One work item per hidden neuron | |
size_t global_index = get_global_index(); | |
if (global_index >= ann->hidden) | |
return; | |
genann_real const __global *w = data; | |
genann_real __global *o = data + ann->total_weights + ann->inputs; | |
genann_real const __global *i = data + ann->total_weights; | |
// Find the bias and array of weights for this output | |
w += global_index * (ann->hidden + 1); | |
// Load bias | |
genann_real sum = -w[0]; | |
for (size_t k = 0, e = ann->inputs; k < e; ++k) | |
sum += w[k+1] * i[k]; | |
// This should get inlined away to just the correct | |
// activation function, at compile time | |
o[global_index] = genann_act_hidden_indirect(ann, sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment