Commit 6b052b35 authored by Leonardo Solis's avatar Leonardo Solis
Browse files

improved readability of gradient-norm calc

parent 478124ff
...@@ -66,10 +66,12 @@ bool is_gradDescent_enabled( ...@@ -66,10 +66,12 @@ bool is_gradDescent_enabled(
return *is_gradDescentEn; return *is_gradDescentEn;
} }
float inner_product(__local float* vector1, void gradient_norm(
__local float* vector2, __local float* vector1,
uint inputSize, uint inputSize,
__local float* init) { __local float* init,
__local float* inner_product
) {
float temp = 0.0f; float temp = 0.0f;
...@@ -77,10 +79,11 @@ float inner_product(__local float* vector1, ...@@ -77,10 +79,11 @@ float inner_product(__local float* vector1,
for(uint i = get_local_id(0); for(uint i = get_local_id(0);
i < inputSize; i < inputSize;
i+= NUM_OF_THREADS_PER_BLOCK) { i+= NUM_OF_THREADS_PER_BLOCK) {
init[i] = vector1[i] * vector2[i]; init[i] = vector1[i] * vector1[i];
} }
// Accumulating dot product // Accumulating dot product,
// and then getting the norm
if(get_local_id(0) == 0) { if(get_local_id(0) == 0) {
for(uint i = 0; for(uint i = 0;
i < inputSize; i < inputSize;
...@@ -88,11 +91,7 @@ float inner_product(__local float* vector1, ...@@ -88,11 +91,7 @@ float inner_product(__local float* vector1,
temp += init[i]; temp += init[i];
} }
init [0] = temp; *inner_product = native_sqrt(temp);
} }
barrier(CLK_LOCAL_MEM_FENCE);
return init[0];
} }
...@@ -168,7 +168,6 @@ gradient_minimizer( ...@@ -168,7 +168,6 @@ gradient_minimizer(
__local float gradient_intra_z[MAX_NUM_OF_ATOMS]; __local float gradient_intra_z[MAX_NUM_OF_ATOMS];
__local float gradient_per_intracontributor[MAX_INTRAE_CONTRIBUTORS]; __local float gradient_per_intracontributor[MAX_INTRAE_CONTRIBUTORS];
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Variables to store partial energies // Variables to store partial energies
...@@ -266,11 +265,7 @@ gradient_minimizer( ...@@ -266,11 +265,7 @@ gradient_minimizer(
} }
// Storing the norm of all gradients // Storing the norm of all gradients
local_gNorm = inner_product(local_gradient, local_gradient, dockpars_num_of_genes, dotProduct); gradient_norm(local_gradient, dockpars_num_of_genes, dotProduct, &local_gNorm);
if (get_local_id(0) == 0) {
local_gNorm = native_sqrt(local_gNorm);
}
barrier(CLK_LOCAL_MEM_FENCE); barrier(CLK_LOCAL_MEM_FENCE);
...@@ -353,10 +348,12 @@ gradient_minimizer( ...@@ -353,10 +348,12 @@ gradient_minimizer(
async_work_group_copy(dockpars_conformations_next+(run_id*dockpars_pop_size+entity_id)*GENOTYPE_LENGTH_IN_GLOBMEM, async_work_group_copy(dockpars_conformations_next+(run_id*dockpars_pop_size+entity_id)*GENOTYPE_LENGTH_IN_GLOBMEM,
local_genotype, local_genotype,
dockpars_num_of_genes,0); dockpars_num_of_genes, 0);
// FIXME: maybe not used outside? // FIXME: maybe not used outside?
// Copying final "local" results into "global" memory // Copying final "local" results into "global" memory
/*
local_nIter = local_nIter - 1; local_nIter = local_nIter - 1;
*/
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment