static void Main(string[] args) { try { CudafyModule km = CudafyModule.TryDeserialize(); if (km == null || !km.TryVerifyChecksums()) { km = CudafyTranslator.Cudafy(); km.TrySerialize(); } CudafyTranslator.GenerateDebug = true; // cuda or emulator GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId); gpu.LoadModule(km); //set up color profile to have a measure LAB lookup working #region Matrix3D navigationMatrix = new Matrix3D(); navigationMatrix.Translate(new Vector3D(0, 100, 110)); navigationMatrix.Scale(new Vector3D((double)1 / 5, (double)1 / 5, (double)1 / 5)); //2- Load the profile in a three dimensional array Bin[, ,] p3700 = new Bin[RANGEL, RANGEA, RANGEB]; for (int l = 0; l < RANGEL; l++) { for (int a = 0; a < RANGEA; a++) { for (int b = 0; b < RANGEB; b++) { p3700[l, a, b] = new Bin(l, a, b); } } } try { // add the csv bin file using (GenericParserAdapter parser = new GenericParserAdapter(@"C:\lev\STColorCorrection\Data\PROFILE\p3700.csv")) { System.Data.DataSet dsResult = parser.GetDataSet(); profile = dsResult.Tables[0]; } } catch { } // #region for (int i = 1; i < profile.Rows.Count; i++) { //lab vale as got form profile index Point3D labBin = new Point3D(); labBin.X = Convert.ToDouble(profile.Rows[i][0].ToString()); labBin.Y = Convert.ToDouble(profile.Rows[i][1].ToString()); labBin.Z = Convert.ToDouble(profile.Rows[i][2].ToString()); //trasfered points Point3D labCoordinate = navigationMatrix.Transform(labBin); if (labCoordinate.X == 20 && labCoordinate.Y == 20 && labCoordinate.Z == 22) { Console.WriteLine("empty"); } //gets the bin to fill up Bin actualBin = GetProfileBin(p3700, labCoordinate); //bin RGB Value actualBin.binRGB.X = Convert.ToByte(profile.Rows[i][9].ToString()); actualBin.binRGB.Y = Convert.ToByte(profile.Rows[i][10].ToString()); actualBin.binRGB.Z = Convert.ToByte(profile.Rows[i][11].ToString()); //Measure Lab Values actualBin.measuredLAB.X = Convert.ToDouble(profile.Rows[i][3].ToString()); actualBin.measuredLAB.Y = Convert.ToDouble(profile.Rows[i][4].ToString()); actualBin.measuredLAB.Z = Convert.ToDouble(profile.Rows[i][5].ToString()); //measured XYZ Values actualBin.measuredXYZ.X = Convert.ToDouble(profile.Rows[i][6].ToString()); actualBin.measuredXYZ.Y = Convert.ToDouble(profile.Rows[i][7].ToString()); actualBin.measuredXYZ.Z = Convert.ToDouble(profile.Rows[i][8].ToString()); //is empty check actualBin.isEmpty = false; } #endregion //CVS FILE CREATING AND INICIALIZATION #region //create the CSV file CsvFileWriter output_file_1 = new CsvFileWriter(@"C:\lev\STColorCorrection\Data\CUDA performance analysis\out_file1.csv"); CsvFileWriter output_file_2 = new CsvFileWriter(@"C:\lev\STColorCorrection\Data\CUDA performance analysis\out_file2.csv"); //create the header CsvRow header = new CsvRow(); header.Add("R_fg_in"); header.Add("G_fg_in"); header.Add("B_fg_in"); header.Add("L_fg_in"); header.Add("A_fg_in"); header.Add("B_fg_in"); header.Add("X_bg_in"); header.Add("Y_bg_in"); header.Add("Z_bg_in"); header.Add("BF_Dist"); header.Add("Cuda BF time"); header.Add("QC_Dist"); header.Add("Cuda QC time"); header.Add("Snake_Dist"); header.Add("Cuda Snake time"); header.Add("DecreaseStep_DS"); header.Add("Cuda DS time"); output_file_1.WriteRow(header); header = new CsvRow(); header.Add("R_fg_in"); header.Add("G_fg_in"); header.Add("B_fg_in"); header.Add("L_fg_in"); header.Add("A_fg_in"); header.Add("B_fg_in"); header.Add("X_bg_in"); header.Add("Y_bg_in"); header.Add("Z_bg_in"); header.Add("BF_Dist"); header.Add("R_fg_out"); header.Add("G_fg_out"); header.Add("B_fg_out"); header.Add("QC_Dist"); header.Add("R_fg_out"); header.Add("G_fg_out"); header.Add("B_fg_out"); header.Add("Snake_Dist"); header.Add("R_fg_out"); header.Add("G_fg_out"); header.Add("B_fg_out"); header.Add("DecreaseStep_DS"); header.Add("R_fg_out"); header.Add("G_fg_out"); header.Add("B_fg_out"); output_file_2.WriteRow(header); //write the header to the CSV file #endregion Random randomGenerater = new Random(); for (int num_colors = 0; num_colors < 500; num_colors++) { //create a new csv row CsvRow new_row_file_1 = new CsvRow(); CsvRow new_row_file_2 = new CsvRow(); //colour selection Byte[] rgb = new Byte[3]; randomGenerater.NextBytes(rgb); System.Drawing.Color foreground = System.Drawing.Color.FromArgb(rgb[0], rgb[1], rgb[2]); Point3D backgroundCIEXYZ = new Point3D(0, 0, 0); backgroundCIEXYZ.X = randomGenerater.NextDouble() * 0.9504; backgroundCIEXYZ.Y = randomGenerater.NextDouble() * 1.0000; backgroundCIEXYZ.Z = randomGenerater.NextDouble() * 1.0888; Point3D background = new Point3D(backgroundCIEXYZ.X, backgroundCIEXYZ.Y, backgroundCIEXYZ.Z); Bin foregroundBin = FindForegroundBin(p3700, navigationMatrix, foreground); PerceptionLib.Color foregroundLAB = new PerceptionLib.Color(); foregroundLAB.LA = foregroundBin.measuredLAB.X; foregroundLAB.A = foregroundBin.measuredLAB.Y; foregroundLAB.B = foregroundBin.measuredLAB.Z; //write the input colors #region new_row_file_1.Add(foreground.R.ToString()); new_row_file_1.Add(foreground.G.ToString()); new_row_file_1.Add(foreground.B.ToString()); new_row_file_1.Add(foregroundLAB.LA.ToString()); new_row_file_1.Add(foregroundLAB.A.ToString()); new_row_file_1.Add(foregroundLAB.B.ToString()); new_row_file_1.Add(background.X.ToString()); new_row_file_1.Add(background.Y.ToString()); new_row_file_1.Add(background.Z.ToString()); new_row_file_2.Add(foreground.R.ToString()); new_row_file_2.Add(foreground.G.ToString()); new_row_file_2.Add(foreground.B.ToString()); new_row_file_2.Add(foregroundLAB.LA.ToString()); new_row_file_2.Add(foregroundLAB.A.ToString()); new_row_file_2.Add(foregroundLAB.B.ToString()); new_row_file_2.Add(background.X.ToString()); new_row_file_2.Add(background.Y.ToString()); new_row_file_2.Add(background.Z.ToString()); #endregion //get the brute force values Color.TestingStructure[] results_brute_force = Color.CorrectColour(foreground, background.X, background.Y, background.Z); new_row_file_1.Add(results_brute_force[0].distance.ToString()); new_row_file_1.Add(results_brute_force[0].execution_time.ToString()); Point3D labBin = new Point3D(); labBin.X = results_brute_force[0].Given_R; labBin.Y = results_brute_force[0].Given_G; labBin.Z = results_brute_force[0].Given_B; Bin actualBin = GetProfileBin(p3700, labBin); new_row_file_2.Add(results_brute_force[0].distance.ToString()); new_row_file_2.Add(actualBin.binRGB.X.ToString()); new_row_file_2.Add(actualBin.binRGB.Y.ToString()); new_row_file_2.Add(actualBin.binRGB.Z.ToString()); quick_corr.TestingStructure[] results_quick_corr = quick_corr.CorrectColour(foreground, background.X, background.Y, background.Z); new_row_file_1.Add(results_quick_corr[0].distance.ToString()); new_row_file_1.Add(results_quick_corr[0].execution_time.ToString()); labBin = new Point3D(); labBin.X = results_quick_corr[0].Given_R; labBin.Y = results_quick_corr[0].Given_G; labBin.Z = results_quick_corr[0].Given_B; actualBin = GetProfileBin(p3700, labBin); new_row_file_2.Add(results_quick_corr[0].distance.ToString()); new_row_file_2.Add(actualBin.binRGB.X.ToString()); new_row_file_2.Add(actualBin.binRGB.Y.ToString()); new_row_file_2.Add(actualBin.binRGB.Z.ToString()); snake.TestingStructure[] results_snake = snake.CorrectColour(foreground, background.X, background.Y, background.Z); new_row_file_1.Add(results_snake[0].distance.ToString()); new_row_file_1.Add(results_snake[0].execution_time.ToString()); labBin = new Point3D(); labBin.X = results_snake[0].Given_R; labBin.Y = results_snake[0].Given_G; labBin.Z = results_snake[0].Given_B; actualBin = GetProfileBin(p3700, labBin); new_row_file_2.Add(results_snake[0].distance.ToString()); new_row_file_2.Add(actualBin.binRGB.X.ToString()); new_row_file_2.Add(actualBin.binRGB.Y.ToString()); new_row_file_2.Add(actualBin.binRGB.Z.ToString()); half_step.TestingStructure[] results_half_step = half_step.CorrectColour(foreground, background.X, background.Y, background.Z); new_row_file_1.Add(results_half_step[0].distance.ToString()); new_row_file_1.Add(results_half_step[0].execution_time.ToString()); labBin = new Point3D(); labBin.X = results_half_step[0].Given_R; labBin.Y = results_half_step[0].Given_G; labBin.Z = results_half_step[0].Given_B; actualBin = GetProfileBin(p3700, labBin); new_row_file_2.Add(results_half_step[0].distance.ToString()); new_row_file_2.Add(actualBin.binRGB.X.ToString()); new_row_file_2.Add(actualBin.binRGB.Y.ToString()); new_row_file_2.Add(actualBin.binRGB.Z.ToString()); //write the results output_file_1.WriteRow(new_row_file_1); output_file_2.WriteRow(new_row_file_2); } //Color.Execute(); //quick_corr.Execute(); //close the CSV files output_file_1.Close(); output_file_2.Close(); Console.WriteLine("Done!"); } catch (Exception ex) { Console.WriteLine(ex); } theEnd: Console.ReadKey(); }
static void Main(string[] args) { try { CudafyModule km = CudafyModule.TryDeserialize(); if (km == null || !km.TryVerifyChecksums()) { km = CudafyTranslator.Cudafy(); km.TrySerialize(); } CudafyTranslator.GenerateDebug = true; // cuda or emulator GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId); gpu.LoadModule(km); //set up color profile to have a measure LAB lookup working #region Matrix3D navigationMatrix = new Matrix3D(); navigationMatrix.Translate(new Vector3D(0, 100, 110)); navigationMatrix.Scale(new Vector3D((double)1 / 5, (double)1 / 5, (double)1 / 5)); //2- Load the profile in a three dimensional array Bin[, ,] p3700 = new Bin[RANGEL, RANGEA, RANGEB]; for (int l = 0; l < RANGEL; l++) { for (int a = 0; a < RANGEA; a++) { for (int b = 0; b < RANGEB; b++) { p3700[l, a, b] = new Bin(l, a, b); } } } try { // add the csv bin file using (GenericParserAdapter parser = new GenericParserAdapter(@"C:\lev\STColorCorrection\Data\PROFILE\p3700.csv")) { System.Data.DataSet dsResult = parser.GetDataSet(); profile = dsResult.Tables[0]; } } catch { } // #region for (int i = 1; i < profile.Rows.Count; i++) { //lab vale as got form profile index Point3D labBin = new Point3D(); labBin.X = Convert.ToDouble(profile.Rows[i][0].ToString()); labBin.Y = Convert.ToDouble(profile.Rows[i][1].ToString()); labBin.Z = Convert.ToDouble(profile.Rows[i][2].ToString()); //trasfered points Point3D labCoordinate = navigationMatrix.Transform(labBin); if (labCoordinate.X == 20 && labCoordinate.Y == 20 && labCoordinate.Z == 22) { Console.WriteLine("empty"); } //gets the bin to fill up Bin actualBin = GetProfileBin(p3700, labCoordinate); //bin RGB Value actualBin.binRGB.X = Convert.ToByte(profile.Rows[i][9].ToString()); actualBin.binRGB.Y = Convert.ToByte(profile.Rows[i][10].ToString()); actualBin.binRGB.Z = Convert.ToByte(profile.Rows[i][11].ToString()); //Measure Lab Values actualBin.measuredLAB.X = Convert.ToDouble(profile.Rows[i][3].ToString()); actualBin.measuredLAB.Y = Convert.ToDouble(profile.Rows[i][4].ToString()); actualBin.measuredLAB.Z = Convert.ToDouble(profile.Rows[i][5].ToString()); //measured XYZ Values actualBin.measuredXYZ.X = Convert.ToDouble(profile.Rows[i][6].ToString()); actualBin.measuredXYZ.Y = Convert.ToDouble(profile.Rows[i][7].ToString()); actualBin.measuredXYZ.Z = Convert.ToDouble(profile.Rows[i][8].ToString()); //is empty check actualBin.isEmpty = false; } #endregion //CVS FILE CREATING AND INICIALIZATION #region //create the CSV file CsvFileWriter output_file_1 = new CsvFileWriter(@"C:\lev\STColorCorrection\Data\CUDA performance analysis\times_file.csv"); //create the header CsvRow header = new CsvRow(); header.Add("Cuda BF time"); header.Add("Cuda QC time"); header.Add("Cuda Snake time"); header.Add("Cuda HF time"); output_file_1.WriteRow(header); #endregion Random randomGenerater = new Random(); for (int num_colors = 0; num_colors < 2; num_colors++) { //create a new csv row CsvRow new_row_file_1 = new CsvRow(); const int image_size = 1024 * 768; bf.ForeGroundStrucuture[] foregorungRGB_BF = new bf.ForeGroundStrucuture[image_size]; bf.BackGroundStrucuture[] BackgroundXYZ_BF = new bf.BackGroundStrucuture[image_size]; quick_corr.ForeGroundStrucuture[] foregorungRGB_QC = new quick_corr.ForeGroundStrucuture[image_size]; quick_corr.BackGroundStrucuture[] BackgroundXYZ_QC = new quick_corr.BackGroundStrucuture[image_size]; snake.ForeGroundStrucuture[] foregorungRGB_SN = new snake.ForeGroundStrucuture[image_size]; snake.BackGroundStrucuture[] BackgroundXYZ_SN = new snake.BackGroundStrucuture[image_size]; reduce_step.ForeGroundStrucuture[] foregorungRGB_RS = new reduce_step.ForeGroundStrucuture[image_size]; reduce_step.BackGroundStrucuture[] BackgroundXYZ_RS = new reduce_step.BackGroundStrucuture[image_size]; for (int i = 0; i < image_size; i++) { //static colour //System.Drawing.Color foreground = System.Drawing.Color.FromArgb(69, 77, 217); //Point3D backgroundCIEXYZ = new Point3D(0.0630982813175294, 0.616476271122916, 0.667048468232457); //dynamic random colour Byte[] rgb = new Byte[3]; randomGenerater.NextBytes(rgb); System.Drawing.Color foreground = System.Drawing.Color.FromArgb(rgb[0], rgb[1], rgb[2]); Point3D backgroundCIEXYZ = new Point3D(0, 0, 0); backgroundCIEXYZ.X = randomGenerater.NextDouble() * 0.9504; backgroundCIEXYZ.Y = randomGenerater.NextDouble() * 1.0000; backgroundCIEXYZ.Z = randomGenerater.NextDouble() * 1.0888; Point3D background = new Point3D(backgroundCIEXYZ.X, backgroundCIEXYZ.Y, backgroundCIEXYZ.Z); foregorungRGB_BF[i].R = foreground.R; foregorungRGB_BF[i].G = foreground.G; foregorungRGB_BF[i].B = foreground.B; BackgroundXYZ_BF[i].X = backgroundCIEXYZ.X; BackgroundXYZ_BF[i].Y = backgroundCIEXYZ.Y; BackgroundXYZ_BF[i].Z = backgroundCIEXYZ.Z; foregorungRGB_QC[i].R = foreground.R; foregorungRGB_QC[i].G = foreground.G; foregorungRGB_QC[i].B = foreground.B; BackgroundXYZ_QC[i].X = backgroundCIEXYZ.X; BackgroundXYZ_QC[i].Y = backgroundCIEXYZ.Y; BackgroundXYZ_QC[i].Z = backgroundCIEXYZ.Z; foregorungRGB_SN[i].R = foreground.R; foregorungRGB_SN[i].G = foreground.G; foregorungRGB_SN[i].B = foreground.B; BackgroundXYZ_SN[i].X = backgroundCIEXYZ.X; BackgroundXYZ_SN[i].Y = backgroundCIEXYZ.Y; BackgroundXYZ_SN[i].Z = backgroundCIEXYZ.Z; foregorungRGB_RS[i].R = foreground.R; foregorungRGB_RS[i].G = foreground.G; foregorungRGB_RS[i].B = foreground.B; BackgroundXYZ_RS[i].X = backgroundCIEXYZ.X; BackgroundXYZ_RS[i].Y = backgroundCIEXYZ.Y; BackgroundXYZ_RS[i].Z = backgroundCIEXYZ.Z; } //write the input colors #region #endregion //prepare a BF specific struct //get the brute force values //bf.TestOutput results_brute_force = bf.CorrectColour(foregorungRGB_BF, BackgroundXYZ_BF); //new_row_file_1.Add(results_brute_force.timeTaken.ToString()); //Console.WriteLine(""); quick_corr.TestOutput results_quick_corr = quick_corr.CorrectColour(foregorungRGB_QC, BackgroundXYZ_QC); new_row_file_1.Add(results_quick_corr.timeTaken.ToString()); //Console.WriteLine(results_quick_corr.timeTaken.ToString()); //snake.TestOutput results_snake_corr = snake.CorrectColour(foregorungRGB_SN, BackgroundXYZ_SN); //new_row_file_1.Add(results_snake_corr.timeTaken.ToString()); //Console.WriteLine(""); //reduce_step.TestOutput results_reduce_step = reduce_step.CorrectColour(foregorungRGB_RS, BackgroundXYZ_RS); //new_row_file_1.Add(results_reduce_step.timeTaken.ToString()); output_file_1.WriteRow(new_row_file_1); } //Color.Execute(); //quick_corr.Execute(); //close the CSV files output_file_1.Close(); Console.WriteLine("Done!"); } catch (Exception ex) { Console.WriteLine(ex); } theEnd: Console.ReadKey(); }