8 #include "../_internal/go_fish_impl.cuh" 11 namespace go_fish_details{
34 __global__
void reverse_array(
float * array,
const int N){
35 int myID = blockIdx.x*blockDim.x + threadIdx.x;
36 for(
int id = myID;
id < N/2;
id += blockDim.x*gridDim.x){
37 float temp = array[N -
id - 1];
38 array[N -
id - 1] = array[id];
45 __global__
void initialize_mse_mutation_array(
float * mutations_freq,
const int * freq_index,
const int * scan_index,
const int offset,
const int Nchrom,
const int population,
const int num_populations,
const int array_Length){
46 int myIDy = blockIdx.y*blockDim.y + threadIdx.y;
47 for(
int idy = myIDy; idy < (Nchrom-1); idy+= blockDim.y*gridDim.y){
48 int myIDx = blockIdx.x*blockDim.x + threadIdx.x;
49 int start = scan_index[offset+idy];
50 int num_mutations = freq_index[offset+idy];
51 float freq = (idy+1.f)/Nchrom;
52 for(
int idx = myIDx; idx < num_mutations; idx+= blockDim.x*gridDim.x){
53 for(
int pop = 0; pop < num_populations; pop++){ mutations_freq[pop*array_Length + start + idx] = 0; }
54 mutations_freq[population*array_Length + start + idx] = freq;
59 __global__
void mse_set_mutID(int4 * mutations_ID,
const float *
const mutations_freq,
const int mutations_Index,
const int num_populations,
const int array_Length,
const bool preserve_mutations){
60 int myID = blockIdx.x*blockDim.x + threadIdx.x;
61 for(
int id = myID;
id < mutations_Index;
id+= blockDim.x*gridDim.x){
62 for(
int pop = 0; pop < num_populations; pop++){
63 if(mutations_freq[pop*array_Length+
id] > 0){
64 if(!preserve_mutations){ mutations_ID[id] = make_int4(0,pop,(
id+1),0); }
65 else{ mutations_ID[id] = make_int4(0,pop,-1*(
id+1),0); }
138 __global__
void add_new_mutations(
float * mutations_freq, int4 * mutations_ID,
const int prev_mutations_Index,
const int new_mutations_Index,
const int array_Length,
float freq,
const int population,
const int num_populations,
const int generation){
139 int myID = blockIdx.x*blockDim.x + threadIdx.x;
140 for(
int id = myID; (
id < (new_mutations_Index-prev_mutations_Index)) && ((
id + prev_mutations_Index) < array_Length);
id+= blockDim.x*gridDim.x){
141 for(
int pop = 0; pop < num_populations; pop++){ mutations_freq[(pop*array_Length+prev_mutations_Index+id)] = 0; }
142 mutations_freq[(population*array_Length+prev_mutations_Index+id)] = freq;
143 mutations_ID[(prev_mutations_Index+id)] = make_int4(generation,population,(
id+1),0);
147 __global__
void scatter_arrays(
float * new_mutations_freq, int4 * new_mutations_ID,
const float *
const mutations_freq,
const int4 *
const mutations_ID,
const unsigned int *
const flag,
const unsigned int *
const scan_Index,
const int padded_mut_Index,
const int new_array_Length,
const int old_array_Length,
const bool preserve_mutations,
const int warp_size){
149 int myID = blockIdx.x*blockDim.x + threadIdx.x;
150 int population = blockIdx.y;
152 for(
int id = myID; id < (padded_mut_Index >> 5);
id+= blockDim.x*gridDim.x){
153 int lnID = threadIdx.x % warp_size;
154 int warpID =
id >> 5;
156 unsigned int predmask;
159 predmask = flag[(warpID<<5)+lnID];
160 cnt = __popc(predmask);
164 for(
int offset = 1; offset < 32; offset<<=1){
165 unsigned int n = __shfl_up(cnt, offset);
166 if(lnID >= offset) cnt += n;
169 unsigned int global_index = 0;
170 if(warpID > 0) global_index = scan_Index[warpID - 1];
172 for(
int i = 0; i < 32; i++){
173 unsigned int mask = __shfl(predmask, i);
174 unsigned int sub_group_index = 0;
175 if(i > 0) sub_group_index = __shfl(cnt, i-1);
176 if(mask & (1 << lnID)){
177 int write = global_index + sub_group_index + __popc(mask & ((1 << lnID) - 1));
178 int read = (warpID<<10)+(i<<5)+lnID;
179 new_mutations_freq[population*new_array_Length + write] = mutations_freq[population*old_array_Length+read];
181 if(preserve_mutations){
182 int4 ID = mutations_ID[read];
183 new_mutations_ID[write] = make_int4(ID.x,ID.y,-1*abs(ID.z),ID.w);
184 }
else{ new_mutations_ID[write] = mutations_ID[read]; }
191 __global__
void preserve_prev_run_mutations(int4 * mutations_ID,
const int mutations_Index){
192 int myID = blockIdx.x*blockDim.x + threadIdx.x;
193 for(
int id = myID;
id < mutations_Index;
id+= blockDim.x*gridDim.x){ mutations_ID[id].z = -1*abs(mutations_ID[
id].z); }