Commit 809fc997 authored by Leonardo Solis's avatar Leonardo Solis
Browse files

removed unneeded kernels files

parent fc53c03e
Loading
Loading
Loading
Loading
+0 −98
Original line number Diff line number Diff line
channel bool  chan_IGL_active;
channel char  chan_IGL_mode;
channel float chan_IGL_genotype __attribute__((depth(ACTUAL_GENOTYPE_LENGTH)));

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
__kernel __attribute__ ((max_global_work_dim(0)))
void Krnl_Conf_Arbiter(unsigned int DockConst_num_of_genes) {

	__local float genotype[ACTUAL_GENOTYPE_LENGTH];

	bool active = true;

while(active) {

	//printf("BEFORE In Conf_Arbiter CHANNEL\n");
	// --------------------------------------------------------------
	// Wait for genotypes in channel
	// --------------------------------------------------------------
	bool IC_valid     = false;
	bool GG_valid     = false;
	bool LS_valid     = false;
	bool Off_valid    = false;

	float IC_active;
	float GG_active;
	float LS_active;
	bool Off_active;

	uchar pipe_cnt = 0;

	while (
	       (Off_valid == false) && (pipe_cnt < DockConst_num_of_genes) 
	) {
		IC_active  = read_channel_nb_altera(chan_IC2Conf_genotype, &IC_valid);
		GG_active  = read_channel_nb_altera(chan_GG2Conf_genotype, &GG_valid);
		LS_active  = read_channel_nb_altera(chan_LS2Conf_genotype, &LS_valid);
		Off_active = read_channel_nb_altera(chan_Off2Conf_active,  &Off_valid);

		if (IC_valid || GG_valid || LS_valid) {
			genotype[pipe_cnt] = (IC_valid)  ?  IC_active :
	       			    	     (GG_valid)  ?  GG_active : 
				     	     (LS_valid)  ?  LS_active :
                                     	     (Off_valid) ?  0.0f:
				     	     0.0f; // last case should never occur, otherwise above while would be still running
			
			if (pipe_cnt > 2) {
				genotype [pipe_cnt] = genotype [pipe_cnt]*DEG_TO_RAD;
			}
			
			pipe_cnt++;
		}	
	}

	char mode;

	/*
	active = (IC_valid)     ? true :
		 (GG_valid)     ? true :
		 (LS_valid)     ? true :
		 (Off_valid)    ? Off_active :
		 false; // last case should never occur, otherwise above while would be still running
	*/
	active = (Off_valid) ? Off_active : true; 

	/*
	mode = (IC_valid)  ? 0x01 :
	       (GG_valid)  ? 0x02 :
	       (LS_valid)  ? 0x03 :
	       (Off_valid) ? 0x05 :
	       0x05; // last case should never occur, otherwise above while would be still running
	*/
	mode = (Off_valid) ? 0x05 : (IC_valid) ? 0x01 : (GG_valid) ? 0x02 : 0x03 ; // last case is LS (0x03)
	       
	// --------------------------------------------------------------
	//printf("AFTER In Conf_Arbiter CHANNEL\n");


	// communicate to Krnl_Conform
	for (uchar i=0; i<DockConst_num_of_genes; i++) {
		if (i == 0) {
			write_channel_altera(chan_IGL_active, active);
			mem_fence(CLK_CHANNEL_MEM_FENCE);

			write_channel_altera(chan_IGL_mode,   mode);
			mem_fence(CLK_CHANNEL_MEM_FENCE);
		}

		write_channel_altera(chan_IGL_genotype, genotype[i]);
	}

	

} // End of while (active)

}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
+0 −205
Original line number Diff line number Diff line
//channel bool  chan_Conf2LS_LS2_token;
//channel bool  chan_Conf2LS_LS3_token;

channel bool  chan_LS23_active;
channel char  chan_LS23_mode;
channel float chan_LS23_genotype     __attribute__((depth(ACTUAL_GENOTYPE_LENGTH)));

//channel bool chan_LS2Arbiter_LS2_end;
//channel bool chan_LS2Arbiter_LS3_end;

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
__kernel __attribute__ ((max_global_work_dim(0)))
void Krnl_Conf_Arbiter2(unsigned int DockConst_num_of_genes) {

	__local float genotype2 [ACTUAL_GENOTYPE_LENGTH];
	__local float genotype3 [ACTUAL_GENOTYPE_LENGTH];
	__local float genotype_if_bound_1 [ACTUAL_GENOTYPE_LENGTH];
	__local float genotype [2][ACTUAL_GENOTYPE_LENGTH];

	bool active = true;
	bool LS2_last_geno = false;
	bool LS3_last_geno = false;
	bool bothLS_last_geno = false;

	uint LS2_eval = 0;
	uint LS3_eval = 0;

while(active) {
	bool Off_valid     = false;
	bool LS2_end_valid = false;
	bool LS3_end_valid = false;
	bool Off_active;
	bool LS2_end_active;
	bool LS3_end_active;

	while (
		(Off_valid == false) && (LS2_end_valid == false) && (LS3_end_valid == false)
	){
		Off_active     = read_channel_nb_altera(chan_ConfArbiter_Off,    &Off_valid);
		LS2_end_active = read_channel_nb_altera(chan_LS2Arbiter_LS2_end, &LS2_end_valid);
		LS3_end_active = read_channel_nb_altera(chan_LS2Arbiter_LS3_end, &LS3_end_valid);

		/*
		printf("%-15s %5s",   "Off_valid: ",     Off_valid?"true":"false");
		printf("%-15s %5s ",  "LS2_end_valid: ", LS2_end_valid?"true":"false");
		printf("%-15s %5s\n", "LS3_end_valid: ", LS3_end_valid?"true":"false");
		*/
	}
	
	/*
	if ((LS2_end_valid == true) &&  (LS3_end_valid == true)){
		printf("BOTH LS WANT TO PROCESS DATA!!!!!!\n");
	}
	*/

	uchar bound_tmp = 0;

	/*
	active = Off_valid?Off_active:
		 LS2_end_valid?true:
		 LS3_end_valid?true:
		 false; // last case should never occur, otherwise above while would be still running
	*/
	active = Off_valid ? Off_active : true;

	// get genos from LS2 and LS3
/*
	if (active == true) {

		// if LS2 sent geno
		if (LS2_end_valid == true) {
			bound_tmp++;
			for (uchar i=0; i<DockConst_num_of_genes; i++) {
				genotype2 [i] = read_channel_altera(chan_LS2Conf_LS2_genotype);
			}
			LS2_eval++;

			#if defined (DEBUG_KRNL_CONF_ARBITER)
			printf("LS2 genotype: %u\n", LS2_eval);
			#endif
		}

		// if LS3 sent geno
		if (LS3_end_valid == true) {
			bound_tmp++;
			for (uchar i=0; i<DockConst_num_of_genes; i++) {
				genotype3 [i] = read_channel_altera(chan_LS2Conf_LS3_genotype);
			}
			LS3_eval++;

			#if defined (DEBUG_KRNL_CONF_ARBITER)
			printf("LS3 genotype: %u\n", LS3_eval);
			#endif
		}
	} // End if (active == true)
*/



	if (active == true) {
		for (uchar i=0; i<DockConst_num_of_genes; i++) {
			// if LS2 sent geno
			if (LS2_end_valid == true) {
				genotype2 [i] = read_channel_altera(chan_LS2Conf_LS2_genotype);
			}

			// if LS3 sent geno
			if (LS3_end_valid == true) {
				genotype3 [i] = read_channel_altera(chan_LS2Conf_LS3_genotype);
			}
		}
		
		// if LS2 sent geno
		if (LS2_end_valid == true) {
			bound_tmp++;
			LS2_eval++;
		}

		// if LS3 sent geno
		if (LS3_end_valid == true) {
			bound_tmp++;
			LS3_eval++;
		}
	} // End if (active == true)














	
	uchar bound = (active)?bound_tmp:1;

	// mode for both LS
	char mode [2];
	mode [0] = (LS2_end_valid)? 0x02: 0x00; 
	mode [1] = (LS3_end_valid)? 0x03: 0x00;
	char mode_if_bound_1 = LS2_end_valid?0x02:(LS3_end_valid?0x03:0x00);

	// genotype for both LS
	#pragma ivdep
	for (uchar i=0; i<DockConst_num_of_genes; i++) {
		genotype[0][i & 0x3F] = (LS2_end_valid)?genotype2[i]:0.0f;
		genotype[1][i & 0x3F] = (LS3_end_valid)?genotype3[i]:0.0f;
		genotype_if_bound_1[i] = LS2_end_valid?genotype2[i]:(LS3_end_valid?genotype3[i]:0.0f);
	}

	// Send data to Krnl_Conform2
	for (uchar j=0; j<bound; j++) {
		write_channel_altera(chan_LS23_active, active);
		mem_fence(CLK_CHANNEL_MEM_FENCE);

		write_channel_altera(chan_LS23_mode,(bound==1)?mode_if_bound_1:mode[j]);
		mem_fence(CLK_CHANNEL_MEM_FENCE);

		/*
		for (uchar i=0; i<DockConst_num_of_genes; i++) {
			write_channel_altera(chan_LS23_genotype, (bound==1)?genotype_if_bound_1[i]:genotype[j][i & 0x3F]);
		}
		*/

		for (uchar i=0; i<DockConst_num_of_genes; i++) {
/*
			float tmp;
			
			if (i > 2) {
				tmp = ((bound==1)?genotype_if_bound_1[i]:genotype[j][i & 0x3F]) * DEG_TO_RAD;
			}
*/
			float tmp = (bound==1)?genotype_if_bound_1[i]:genotype[j][i & 0x3F];
			
			if (i > 2) {
				tmp =  tmp * DEG_TO_RAD;
			}

			write_channel_altera(chan_LS23_genotype, tmp);
		}

		#if defined (DEBUG_KRNL_CONF_ARBITER)
		printf("bound: %u, mode: %u\n", bound, (bound==1)?mode_if_bound_1:mode[j]);
		#endif
	}

	if (LS2_end_active == true) {
		LS2_eval = 0;
	}

	if (LS3_end_active == true) {
		LS3_eval = 0;
	}

} // End of while (active)

}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
+0 −325
Original line number Diff line number Diff line
// --------------------------------------------------------------------------
// The function changes the conformation of myligand according to 
// the genotype given by the second parameter.
// Originally from: processligand.c
// --------------------------------------------------------------------------
__kernel __attribute__ ((max_global_work_dim(0)))
void Krnl_Conform2(
	     __constant int*    restrict KerConstStatic_rotlist_const,
	     __constant float3* restrict KerConstDynamic_ref_coords_const,
	     __constant float3* restrict KerConstDynamic_rotbonds_moving_vectors_const,
	     __constant float3* restrict KerConstDynamic_rotbonds_unit_vectors_const,
	    
			      unsigned int                     DockConst_rotbondlist_length,
			      unsigned char                    DockConst_num_of_atoms,
			      unsigned int                     DockConst_num_of_genes,

			      float                            ref_orientation_quats_const_0,
			      float                            ref_orientation_quats_const_1,
			      float                            ref_orientation_quats_const_2,
			      float                            ref_orientation_quats_const_3
)
{
	#if defined (DEBUG_KRNL_Conform) 
	printf("\n");
	printf("%-40s %u\n", "DockConst->rotbondlist_length: ",	DockConst_rotbondlist_length);
	printf("%-40s %u\n", "DockConst->num_of_atoms: ",  	DockConst_num_of_atoms);
	printf("%-40s %u\n", "DockConst_num_of_genes: ",        DockConst_num_of_genes);	
	#endif

/*
	// check best practices guide
	// Table 11. Effects of numbanks and bankwidth on the Bank Geometry ...
	// only first three indexes of the lower array are used
	// however size of lower array was declared as 4, just to keep sizes equal to power of 2
	__local float  __attribute__((numbanks(8), bankwidth(16))) loc_coords[MAX_NUM_OF_ATOMS][4];
*/

	__local float genotype[ACTUAL_GENOTYPE_LENGTH];

	bool active = true;

	// local mem to cache KerConstStatic->rotlist_const[], marked as bottleneck by profiler
	__local int rotlist_localcache [MAX_NUM_OF_ROTATIONS];
	for (ushort c = 0; c < DockConst_rotbondlist_length; c++) {
		rotlist_localcache [c] = KerConstStatic_rotlist_const [c];
	}

	__local float3 ref_coords_localcache [MAX_NUM_OF_ATOMS];
	for (uchar c = 0; c < DockConst_num_of_atoms; c++) {
		ref_coords_localcache [c] = KerConstDynamic_ref_coords_const [c];
	}

	__local float3 rotbonds_moving_vectors_localcache[MAX_NUM_OF_ROTBONDS];
	__local float3 rotbonds_unit_vectors_localcache[MAX_NUM_OF_ROTBONDS];
	for (uchar c = 0; c < MAX_NUM_OF_ROTBONDS; c++) {
		rotbonds_moving_vectors_localcache [c] = KerConstDynamic_rotbonds_moving_vectors_const[c];
		rotbonds_unit_vectors_localcache   [c] = KerConstDynamic_rotbonds_unit_vectors_const [c];
	}


while(active) {

	//printf("BEFORE In CONFORM CHANNEL\n");
	// --------------------------------------------------------------
	// Wait for genotypes in channel
	// --------------------------------------------------------------
/*
	bool LS2_valid  = false;
	bool Off2_valid = false;

	float LS2_active;
	bool  Off2_active;

	uchar pipe_cnt = 0;

	while (
		(Off2_valid == false) && (pipe_cnt < DockConst_num_of_genes)
	) {
		LS2_active = read_channel_nb_altera(chan_LS2Conf_LS2_genotype, &LS2_valid);
		Off2_active = read_channel_nb_altera(chan_LS2Conf_Off, &Off2_valid);

		if (LS2_valid) {
			genotype [pipe_cnt] = (LS2_valid)? LS2_active:
					      (Off2_valid)? 0.0f:
					      0.0f; // last case should never occur, otherwise above while would be still running
			if (pipe_cnt > 2) {
				genotype [pipe_cnt] = genotype [pipe_cnt]*DEG_TO_RAD;
			}

			pipe_cnt++;
		}
	}

	char mode;

	active = (LS2_valid) ? true :
		 (Off2_valid)? Off2_active :
		 false;	// last case should never occur, otherwise above while would be still running
*/
	char mode;

	active = read_channel_altera(chan_LS23_active);
	mem_fence(CLK_CHANNEL_MEM_FENCE);

	for (uchar i=0; i<DockConst_num_of_genes; i++) {
		if (i == 0) {
			mode = read_channel_altera(chan_LS23_mode);
			mem_fence(CLK_CHANNEL_MEM_FENCE);
		}

		genotype [i] = read_channel_altera(chan_LS23_genotype);
		/*
		if (i > 2) {
			genotype [i] = genotype [i]*DEG_TO_RAD;
		}
		*/
	}
	
	// --------------------------------------------------------------
	//printf("AFTER In CONFORM 2 CHANNEL\n");

	/*
	float3 __attribute__ ((
			      memory,
			      numbanks(2),
			      bankwidth(16),
			      singlepump,
			      numreadports(2),
			      numwriteports(1)
			    )) loc_coords[MAX_NUM_OF_ATOMS];
	*/
	float3 loc_coords[MAX_NUM_OF_ATOMS];

	#if defined (DEBUG_ACTIVE_KERNEL)
	if (active == 0) {printf("	%-20s: %s\n", "Krnl_Conform", "must be disabled");}
	#endif

	
	float3 genotype_xyz = {genotype[0], genotype[1], genotype[2]};

	float phi         = genotype [3];
	float theta       = genotype [4];
	float genrotangle = genotype [5];

	float sin_theta, cos_theta;
	sin_theta = native_sin(theta);
	cos_theta = native_cos(theta);

	float3 genrot_unitvec;
	genrot_unitvec.x = sin_theta*native_cos(phi);
	genrot_unitvec.y = sin_theta*native_sin(phi);
	genrot_unitvec.z = cos_theta;

	for (ushort rotation_counter = 0; rotation_counter < DockConst_rotbondlist_length; rotation_counter++)
	{
		int rotation_list_element = rotlist_localcache [rotation_counter];

		if ((rotation_list_element & RLIST_DUMMY_MASK) == 0)	//if not dummy rotation
		{
			uint atom_id = rotation_list_element & RLIST_ATOMID_MASK;

			//capturing atom coordinates
			float3 atom_to_rotate;

			if ((rotation_list_element & RLIST_FIRSTROT_MASK) != 0)	//if first rotation of this atom
			{	
				atom_to_rotate = ref_coords_localcache [atom_id];
			}
			else
			{	
				atom_to_rotate = loc_coords[atom_id];
			}

			//capturing rotation vectors and angle
			float3 rotation_unitvec;
			float3 rotation_movingvec;
			float rotation_angle;

			if ((rotation_list_element & RLIST_GENROT_MASK) != 0)	//if general rotation
			{
				rotation_unitvec = genrot_unitvec;

				rotation_angle = genrotangle;

				rotation_movingvec = genotype_xyz;
			}
			else	//if rotating around rotatable bond
			{
				uint rotbond_id = (rotation_list_element & RLIST_RBONDID_MASK) >> RLIST_RBONDID_SHIFT;
				rotation_unitvec = rotbonds_unit_vectors_localcache [rotbond_id];
				
				rotation_angle = genotype[6+rotbond_id];

				rotation_movingvec = rotbonds_moving_vectors_localcache [rotbond_id];

				//in addition performing the first movement 
				//which is needed only if rotating around rotatable bond
				atom_to_rotate -= rotation_movingvec;
			}

			//performing rotation
			float quatrot_left_x, quatrot_left_y, quatrot_left_z, quatrot_left_q;
			float quatrot_temp_x, quatrot_temp_y, quatrot_temp_z, quatrot_temp_q;

			rotation_angle = rotation_angle*0.5f;

			float sin_angle, cos_angle;
			sin_angle = native_sin(rotation_angle);
			cos_angle = native_cos(rotation_angle);
			quatrot_left_x = sin_angle*rotation_unitvec.x;
			quatrot_left_y = sin_angle*rotation_unitvec.y;
			quatrot_left_z = sin_angle*rotation_unitvec.z;
			quatrot_left_q = cos_angle;

			if ((rotation_list_element & RLIST_GENROT_MASK) != 0)	//if general rotation, 
										//two rotations should be performed 
										//(multiplying the quaternions)
			{
				//calculating quatrot_left*ref_orientation_quats_const, 
				//which means that reference orientation rotation is the first
				quatrot_temp_q = quatrot_left_q;
				quatrot_temp_x = quatrot_left_x;
				quatrot_temp_y = quatrot_left_y;
				quatrot_temp_z = quatrot_left_z;

				// L30nardoSV: taking the first element of ref_orientation_quats_const member
				quatrot_left_q = quatrot_temp_q*ref_orientation_quats_const_0-
						 quatrot_temp_x*ref_orientation_quats_const_1-
						 quatrot_temp_y*ref_orientation_quats_const_2-
						 quatrot_temp_z*ref_orientation_quats_const_3;
				quatrot_left_x = quatrot_temp_q*ref_orientation_quats_const_1+
						 ref_orientation_quats_const_0*quatrot_temp_x+
						 quatrot_temp_y*ref_orientation_quats_const_3-
						 ref_orientation_quats_const_2*quatrot_temp_z;
				quatrot_left_y = quatrot_temp_q*ref_orientation_quats_const_2+
						 ref_orientation_quats_const_0*quatrot_temp_y+
						 ref_orientation_quats_const_1*quatrot_temp_z-
						 quatrot_temp_x*ref_orientation_quats_const_3;
				quatrot_left_z = quatrot_temp_q*ref_orientation_quats_const_3+
						 ref_orientation_quats_const_0*quatrot_temp_z+
						 quatrot_temp_x*ref_orientation_quats_const_2-
						 ref_orientation_quats_const_1*quatrot_temp_y;
			}

			quatrot_temp_q = - 
					(quatrot_left_x*atom_to_rotate.x +
					 quatrot_left_y*atom_to_rotate.y +
					 quatrot_left_z*atom_to_rotate.z);

			quatrot_temp_x = quatrot_left_q*atom_to_rotate.x +
					 quatrot_left_y*atom_to_rotate.z -
					 quatrot_left_z*atom_to_rotate.y;
			quatrot_temp_y = quatrot_left_q*atom_to_rotate.y -
					 quatrot_left_x*atom_to_rotate.z +
					 quatrot_left_z*atom_to_rotate.x;
			quatrot_temp_z = quatrot_left_q*atom_to_rotate.z +
					 quatrot_left_x*atom_to_rotate.y -
					 quatrot_left_y*atom_to_rotate.x;

			atom_to_rotate.x = quatrot_temp_x*quatrot_left_q - quatrot_temp_q*quatrot_left_x - 
					     quatrot_temp_y*quatrot_left_z + quatrot_temp_z*quatrot_left_y;
			atom_to_rotate.y = quatrot_temp_x*quatrot_left_z + quatrot_temp_y*quatrot_left_q - 
					     quatrot_temp_z*quatrot_left_x - quatrot_temp_q*quatrot_left_y ;
			atom_to_rotate.z = quatrot_temp_y*quatrot_left_x - quatrot_temp_x*quatrot_left_y - 
					     quatrot_temp_q*quatrot_left_z + quatrot_temp_z*quatrot_left_q;

			//performing final movement and storing values
			loc_coords[atom_id] = atom_to_rotate + rotation_movingvec;

		} // End if-statement not dummy rotation
	} // End rotation_counter for-loop

	#if defined (DEBUG_KRNL_CONFORM)
	printf("BEFORE Out CONFORM CHANNEL\n");
	#endif

	// --------------------------------------------------------------
	// Send ligand atomic coordinates to channel 
	// --------------------------------------------------------------
	/*
	write_channel_altera(chan_Conf2Intere_LS2_active, active);
	write_channel_altera(chan_Conf2Intrae_LS2_active, active);
	mem_fence(CLK_CHANNEL_MEM_FENCE);

	write_channel_altera(chan_Conf2Intere_LS2_mode,   mode);
	write_channel_altera(chan_Conf2Intrae_LS2_mode,   mode);
	mem_fence(CLK_CHANNEL_MEM_FENCE);

	//float3 position_xyz;
	for (uchar pipe_cnt=0; pipe_cnt<DockConst_num_of_atoms; pipe_cnt++) {
		write_channel_altera(chan_Conf2Intere_LS2_xyz, loc_coords[pipe_cnt]);
		write_channel_altera(chan_Conf2Intrae_LS2_xyz, loc_coords[pipe_cnt]);
	}
	mem_fence(CLK_CHANNEL_MEM_FENCE);
	*/

	for (uchar pipe_cnt=0; pipe_cnt<DockConst_num_of_atoms; pipe_cnt++) {
		if (pipe_cnt == 0) {
			write_channel_altera(chan_Conf2Intere_LS2_active, active);
			write_channel_altera(chan_Conf2Intrae_LS2_active, active);
			mem_fence(CLK_CHANNEL_MEM_FENCE);

			write_channel_altera(chan_Conf2Intere_LS2_mode,   mode);
			write_channel_altera(chan_Conf2Intrae_LS2_mode,   mode);
			mem_fence(CLK_CHANNEL_MEM_FENCE);
		}

		write_channel_altera(chan_Conf2Intere_LS2_xyz, loc_coords[pipe_cnt]);
		write_channel_altera(chan_Conf2Intrae_LS2_xyz, loc_coords[pipe_cnt]);
	}

	// --------------------------------------------------------------
	#if defined (DEBUG_KRNL_CONFORM)
	printf("AFTER Out CONFORM CHANNEL\n");
	#endif

} // End of while(1)

#if defined (DEBUG_ACTIVE_KERNEL)
printf("	%-20s: %s\n", "Krnl_Conform", "disabled");
#endif

}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
+0 −257

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −293

File deleted.

Preview size limit exceeded, changes collapsed.

Loading