Commit 24fb19fa authored by Andrey Filippov's avatar Andrey Filippov
Browse files

co-debugging code with C++ for GPU

parent 6bcd9932
Loading
Loading
Loading
Loading
+102 −34
Original line number Diff line number Diff line
@@ -1221,14 +1221,14 @@ public class DttRad2 {


	private double [] _dctii_nrecurs2(double[] x){
//		int n = x.length; == 2
		double [] y= {x[0]+x[1],x[0]-x[1]};
		System.out.println(String.format("_dctii_nrecurs2: x={%8f,%8f}",x[0],x[1]));
		System.out.println(String.format("_dctii_nrecurs2: y={%8f,%8f}",y[0],y[1]));

		return y;
	}

	private double [] _dctii_nrecurs4(double[] x){
//		int n = x.length; // 4
//		int n1 = n >> 1; // 2
		double [] u0 = new double [2];
		double [] u1 = new double [2];
		for (int j = 0; j < 2; j++){
@@ -1242,6 +1242,12 @@ public class DttRad2 {
			y[2*j] =     v0[j];
			y[2*j+1] =   v1[j];
		}

		System.out.println(String.format("_dctii_nrecurs4: x={%8f,%8f,%8f,%8f}",x[0],x[1],x[2],x[3]));
		System.out.println(String.format("_dctii_nrecurs4: u0={%8f,%8f}, u1={%8f,%8f}",u0[0],u0[1],u1[0],u1[1]));
		System.out.println(String.format("_dctii_nrecurs4: v0={%8f,%8f}, v1={%8f,%8f}",v0[0],v0[1],v1[0],v1[1]));
		System.out.println(String.format("_dctii_nrecurs4: y={%8f,%8f,%8f,%8f}",y[0],y[1],y[2],y[3]));

		return y;
	}

@@ -1261,6 +1267,11 @@ public class DttRad2 {
			y[2*j] =     v0[j];
			y[2*j+1] =   v1[j];
		}
		System.out.println(String.format("_dctii_nrecurs8: x={%8f,%8f,%8f,%8f,%8f,%8f,%8f,%8f}",x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7]));
		System.out.println(String.format("_dctii_nrecurs8: u0={%8f,%8f,%8f,%8f}, u1={%8f,%8f,%8f,%8f}",u0[0],u0[1],u0[2],u0[3],u1[0],u1[1],u1[2],u1[3]));
		System.out.println(String.format("_dctii_nrecurs8: v0={%8f,%8f,%8f,%8f}, v1={%8f,%8f,%8f,%8f}",v0[0],v0[1],v0[2],v0[3],v1[0],v1[1],v1[2],v1[3]));
		System.out.println(String.format("_dctii_nrecurs8: y={%8f,%8f,%8f,%8f,%8f,%8f,%8f,%8f}",y[0],y[1],y[2],y[3],y[4],y[5],y[6],y[7]));

		return y;
	}

@@ -1269,14 +1280,13 @@ public class DttRad2 {
//		int n = x.length; == 2
		double [] y= {COSPI_1_8_SQRT2*x[0] + COSPI_3_8_SQRT2*x[1],
				      COSPI_3_8_SQRT2*x[0] - COSPI_1_8_SQRT2*x[1]};
		System.out.println(String.format("_dctiv_nrecurs2: x={%8f,%8f}",x[0],x[1]));
		System.out.println(String.format("_dctiv_nrecurs2: y={%8f,%8f}",y[0],y[1]));

		return y;
	}

	private double [] _dctiv_nrecurs4(double[] x){
//		int n = x.length; // 4
//		int n1 = n >> 1; // 2
//		int t = ilog2(n1)-1; // 0

		double [] u0 = new double [2];
		double [] u1 = new double [2];
		for (int j = 0; j< 2; j++){
@@ -1303,23 +1313,23 @@ public class DttRad2 {
			y[2*j] =     w0[j];
			y[2*j+1] =   w1[j];
		}

		System.out.println(String.format("_dctiv_nrecurs4: x={%8f,%8f,%8f,%8f}",x[0],x[1],x[2],x[3]));
		System.out.println(String.format("_dctiv_nrecurs4: u0={%8f,%8f}, u1={%8f,%8f}",u0[0],u0[1],u1[0],u1[1]));
		System.out.println(String.format("_dctiv_nrecurs4: v0={%8f,%8f}, v1={%8f,%8f}",v0[0],v0[1],v1[0],v1[1]));
		System.out.println(String.format("_dctiv_nrecurs4: w0={%8f,%8f}, w1={%8f,%8f}",w0[0],w0[1],w1[0],w1[1]));
		System.out.println(String.format("_dctiv_nrecurs4: y={%8f,%8f,%8f,%8f}",y[0],y[1],y[2],y[3]));
		return y;
	}

	private double [] _dctiv_nrecurs8(double[] x){
//		int n = x.length; // 8
//		int n1 = n >> 1; // 4
//		int t = ilog2(n1)-1; // 1

		double [] u0 = new double [4];
		double [] u1 = new double [4];
		// u = sqrt(2)*Tn(1) * x
		for (int j = 0; j< 4; j++){
			u0[j]=                             ( CN1[1][j] *   x[j] +     SN1[1][j] *     x[7 - j]);
			u1[j]=            ( 1 - 2*(j & 1))*(-SN1[1][3-j] * x[3 - j] + CN1[1][3 - j] * x[4 + j]);
		}
//		double [] v0 = _dctii_recurs(u0);
//		double [] v1 = _dctii_recurs(u1); //both cos-II

		double [] v0 = _dctii_nrecurs4(u0);
		double [] v1 = _dctii_nrecurs4(u1); //both cos-II
@@ -1340,6 +1350,11 @@ public class DttRad2 {
			y[2*j] =     w0[j];
			y[2*j+1] =   w1[j];
		}
		System.out.println(String.format("_dctiv_nrecurs8: x={%8f,%8f,%8f,%8f,%8f,%8f,%8f,%8f}",x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7]));
		System.out.println(String.format("_dctiv_nrecurs8: u0={%8f,%8f,%8f,%8f}, u1={%8f,%8f,%8f,%8f}",u0[0],u0[1],u0[2],u0[3],u1[0],u1[1],u1[2],u1[3]));
		System.out.println(String.format("_dctiv_nrecurs8: v0={%8f,%8f,%8f,%8f}, v1={%8f,%8f,%8f,%8f}",v0[0],v0[1],v0[2],v0[3],v1[0],v1[1],v1[2],v1[3]));
		System.out.println(String.format("_dctiv_nrecurs8: w0={%8f,%8f,%8f,%8f}, w1={%8f,%8f,%8f,%8f}",w0[0],w0[1],w0[2],w0[3],w1[0],w1[1],w1[2],w1[3]));
		System.out.println(String.format("_dctiv_nrecurs8: y={%8f,%8f,%8f,%8f,%8f,%8f,%8f,%8f}",y[0],y[1],y[2],y[3],y[4],y[5],y[6],y[7]));
		return y;
	}

@@ -1386,6 +1401,37 @@ public class DttRad2 {
		double v03= COSPI_3_8_SQRT2 * w10 - COSPI_1_8_SQRT2 * w11;

//		_dctiv_nrecurs4(u10, u11, u12, u13, &v10, &v11, &v12, &v13);

/*
		double [] u0 = new double [2];
		double [] u1 = new double [2];
		for (int j = 0; j< 2; j++){
			u0[j]=                             ( CN1[0][j] *   x[j] +   SN1[0][j] *   x[3 - j]);
			u1[j]=            ( 1 - 2*(j & 1))*(-SN1[0][1-j] * x[1-j] + CN1[0][1-j] * x[2 + j]);
		}
		double [] v0 = _dctii_nrecurs2(u0);
		double [] v1 = _dctii_nrecurs2(u1); //both cos-II


		double [] w0 = new double [2];
		double [] w1 = new double [2];

		w0[0] =     sqrt2 * v0[0];
		w1[1] =     sqrt2 * v1[0];
		for (int j = 0; j< 2; j++){
			int sgn = (1 - 2* (j & 1));
			if (j > 0)	    w0[j] = v0[j]   - sgn * v1[2 - j];
			if (j < (1))	w1[j] = v0[j+1] - sgn * v1[2 - j -1];
		}

		double [] y = new double[4];
		for (int j = 0; j< 2; j++){
			y[2*j] =     w0[j];
			y[2*j+1] =   w1[j];
		}
 */


		double w20=            ( COSN1[0] * u10 + SINN1[0] * u13);
		double w30=            (-SINN1[1] * u11 + COSN1[1] * u12);

@@ -1393,7 +1439,7 @@ public class DttRad2 {
		double w31=           -(-SINN1[0] * u10 + COSN1[0] * u13);
	//u->t, v ->z, t0->w2, t1->w3
//		double z00, z01, z10,z11;

// TODO: change w20<->w02
//		_dctii_nrecurs2(u00, u01, &v00, &v01);
		double z00= w20 + w21;
		double z01= w20 - w21;
@@ -1419,6 +1465,12 @@ public class DttRad2 {

		y[6] =   v03;
		y[7] =   v13;
		System.out.println(String.format("_dctii_nrecurs8-gpu: x={%8f,%8f,%8f,%8f,%8f,%8f,%8f,%8f}",x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7]));
		System.out.println(String.format("_dctii_nrecurs8-gpu: u0={%8f,%8f,%8f,%8f}, u1={%8f,%8f,%8f,%8f}",u00,u01,u02,u03,u10,u11,u12,u13));
		System.out.println(String.format("_dctii_nrecurs8-gpu: v0={%8f,%8f,%8f,%8f}, v1={%8f,%8f,%8f,%8f}",v00,v01,v02,v03,v10,v11,v12,v13));
		System.out.println(String.format("_dctii_nrecurs8-gpu: w0={%8f,%8f,%8f,%8f}, w1={%8f,%8f,%8f,%8f}",w00,w10,w20,w30,w01,w11,w21,w31));
		System.out.println(String.format("_dctii_nrecurs8-gpu: y={%8f,%8f,%8f,%8f,%8f,%8f,%8f,%8f}",y[0],y[1],y[2],y[3],y[4],y[5],y[6],y[7]));

	}

	void _dctiv_nrecurs8( double [] x, double [] y) // x,y point to 8-element arrays each
@@ -1430,36 +1482,47 @@ public class DttRad2 {
		double u11=           -(-SINN2[2] * x[2] + COSN2[2] * x[5]);

		double u02=            ( COSN2[2] * x[2] + SINN2[2] * x[5]);
		double u12=           -(-SINN2[1] * x[1] + COSN2[1] * x[6]);
		double u12=            (-SINN2[1] * x[1] + COSN2[1] * x[6]);

		double u03=            ( COSN2[3] * x[3] + SINN2[3] * x[4]);
		double u13=           -(-SINN2[0] * x[0] + COSN2[0] * x[7]);

//		_dctii_nrecurs4(u00, u01, u02, u03, &v00, &v01, &v02, &v03);
		double w00= u00 + u03;
		double w10= u00 - u03;
//		_dctii_nrecurs4(u00, u01, u02, u03, &v00, &v01, &v02, &v03); // ua - u inside first _dctii_nrecurs4, ub - inside second
		double ua00= u00 + u03;
		double ua10= u00 - u03;

		double w01= u01 + u02;
		double w11= u01 - u02;
		double ua01= u01 + u02;
		double ua11= u01 - u02;

		double v00= w00 + w01;
		double v02= w00 - w01;

		double v01= COSPI_1_8_SQRT2*w10 + COSPI_3_8_SQRT2*w11;
		double v03= COSPI_3_8_SQRT2*w10 - COSPI_1_8_SQRT2*w11;
		double v00= ua00 + ua01;
		double v02= ua00 - ua01;

		double v01= COSPI_1_8_SQRT2 * ua10 + COSPI_3_8_SQRT2 * ua11;
		double v03= COSPI_3_8_SQRT2 * ua10 - COSPI_1_8_SQRT2 * ua11;
//		_dctii_nrecurs4(u10, u11, u12, u13, &v10, &v11, &v12, &v13);

		double w20= u10 + u13; // t0x-> w2x, gt1x-> w3x
		double w30= u10 - u13;
		System.out.println(String.format("_dctiv_nrecurs8-gpu (_dctii_nrecurs4(x): x={%8f,%8f,%8f,%8f}",u10, u11, u12, u13));

		double ub00= u10 + u13;
		double ub10= u10 - u13;

		double ub01= u11 + u12;
		double ub11= u11 - u12;
		System.out.println(String.format("_dctiv_nrecurs8-gpu: ub0={%8f,%8f}, ub1={%8f,%8f}",ub00,ub01,ub10,ub11));

		double vb00= ub00 + ub01;
		double vb01= ub00 - ub01;

		double vb10= COSPI_1_8_SQRT2*ub10 + COSPI_3_8_SQRT2*ub11;
		double vb11= COSPI_3_8_SQRT2*ub10 - COSPI_1_8_SQRT2*ub11;

		double w21= u11 + u12;
		double w31= u11 - u12;
		System.out.println(String.format("_dctiv_nrecurs8-gpu: vb0={%8f,%8f}, vb1={%8f,%8f}",vb00,vb01,vb10,vb11));

		double v10= w20 + w21;
		double v12= w20 - w21;
		double v11= COSPI_1_8_SQRT2*w30 + COSPI_3_8_SQRT2*w31;
		double v13= COSPI_3_8_SQRT2*w30 - COSPI_1_8_SQRT2*w31;
		double v10 = vb00;
		double v11 = vb10;
		double v12 = vb01;
		double v13 = vb11;
		System.out.println(String.format("_dctiv_nrecurs8-gpu: yb={%8f,%8f,%8f,%8f}",vb00, vb10, vb01, vb11));

		// j == 0
		y[0] =  SQRT_2 * v00;    // w0[0];
@@ -1469,10 +1532,15 @@ public class DttRad2 {
		y[3] =  v02 +  v12;    // w1[1];
		// j == 2
		y[4] =  v02 -  v12;    // w0[2];
		y[5] =  v02 +  v12;    // w1[2];
		y[5] =  v03 -  v11;    // w1[2]; - same as y[3]
		// j == 3
		y[6] =  v03 +  v11;    // w0[3];
		y[7] =  SQRT_2 * v10;    // w1[3];
		System.out.println(String.format("_dctiv_nrecurs8-gpu: x={%8f,%8f,%8f,%8f,%8f,%8f,%8f,%8f}",x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7]));
		System.out.println(String.format("_dctiv_nrecurs8-gpu: u0={%8f,%8f,%8f,%8f}, u1={%8f,%8f,%8f,%8f}",u00,u01,u02,u03,u10,u11,u12,u13));
		System.out.println(String.format("_dctiv_nrecurs8-gpu: v0={%8f,%8f,%8f,%8f}, v1={%8f,%8f,%8f,%8f}",v00,v01,v02,v03,v10,v11,v12,v13));
//		System.out.println(String.format("_dctiv_nrecurs8-gpu: w0={%8f,%8f,%8f,%8f}, w1={%8f,%8f,%8f,%8f}",w00,w10,w20,w30,w01,w11,w21,w31));
		System.out.println(String.format("_dctiv_nrecurs8-gpu: y={%8f,%8f,%8f,%8f,%8f,%8f,%8f,%8f}",y[0],y[1],y[2],y[3],y[4],y[5],y[6],y[7]));
	}