commit 487a0819ce5c14c6c70c1a5959350de4f27dac4d Author: BlubbFish Date: Thu Mar 9 20:44:48 2017 +0000 OpenCLImageFilter hinzugefügt diff --git a/WindowsFormsApplication1.sln b/WindowsFormsApplication1.sln new file mode 100644 index 0000000..b7f2945 --- /dev/null +++ b/WindowsFormsApplication1.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenCLImageFilter", "WindowsFormsApplication1\OpenCLImageFilter.csproj", "{25E1C72C-5114-4EA3-8DD8-F9435E832214}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {25E1C72C-5114-4EA3-8DD8-F9435E832214}.Debug|x86.ActiveCfg = Debug|x86 + {25E1C72C-5114-4EA3-8DD8-F9435E832214}.Debug|x86.Build.0 = Debug|x86 + {25E1C72C-5114-4EA3-8DD8-F9435E832214}.Release|x86.ActiveCfg = Release|x86 + {25E1C72C-5114-4EA3-8DD8-F9435E832214}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/WindowsFormsApplication1/Bild2.png b/WindowsFormsApplication1/Bild2.png new file mode 100644 index 0000000..0136271 Binary files /dev/null and b/WindowsFormsApplication1/Bild2.png differ diff --git a/WindowsFormsApplication1/Form1.Designer.cs b/WindowsFormsApplication1/Form1.Designer.cs new file mode 100644 index 0000000..9372919 --- /dev/null +++ b/WindowsFormsApplication1/Form1.Designer.cs @@ -0,0 +1,303 @@ +namespace OpenCLImageFilter +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pictureBrowse = new System.Windows.Forms.Button(); + this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + this.pictureFile = new System.Windows.Forms.TextBox(); + this.openclBrowse = new System.Windows.Forms.Button(); + this.openCLFile = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.openFileDialog2 = new System.Windows.Forms.OpenFileDialog(); + this.buttonApplyFilter = new System.Windows.Forms.Button(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.pictureBox2 = new System.Windows.Forms.PictureBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.buttonBrowseFilter = new System.Windows.Forms.Button(); + this.label4 = new System.Windows.Forms.Label(); + this.textStatus = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.filterSelector = new System.Windows.Forms.ComboBox(); + this.openFileDialog3 = new System.Windows.Forms.OpenFileDialog(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBrowse + // + this.pictureBrowse.Location = new System.Drawing.Point(224, 16); + this.pictureBrowse.Name = "pictureBrowse"; + this.pictureBrowse.Size = new System.Drawing.Size(85, 20); + this.pictureBrowse.TabIndex = 0; + this.pictureBrowse.Text = "Browse..."; + this.pictureBrowse.UseVisualStyleBackColor = true; + this.pictureBrowse.Click += new System.EventHandler(this.button1_Click); + // + // openFileDialog1 + // + this.openFileDialog1.Filter = "Images|*.bmp;*.jpg;*.png"; + this.openFileDialog1.Title = "Select Source Image"; + // + // pictureFile + // + this.pictureFile.Location = new System.Drawing.Point(73, 16); + this.pictureFile.Name = "pictureFile"; + this.pictureFile.Size = new System.Drawing.Size(145, 20); + this.pictureFile.TabIndex = 1; + this.pictureFile.Text = "..\\..\\Bild2.png"; + this.pictureFile.TextChanged += new System.EventHandler(this.pictureFile_TextChanged); + // + // openclBrowse + // + this.openclBrowse.Location = new System.Drawing.Point(224, 42); + this.openclBrowse.Name = "openclBrowse"; + this.openclBrowse.Size = new System.Drawing.Size(85, 20); + this.openclBrowse.TabIndex = 2; + this.openclBrowse.Text = "Browse..."; + this.openclBrowse.UseVisualStyleBackColor = true; + this.openclBrowse.Click += new System.EventHandler(this.openclBrowse_Click); + // + // openCLFile + // + this.openCLFile.Location = new System.Drawing.Point(73, 42); + this.openCLFile.Name = "openCLFile"; + this.openCLFile.Size = new System.Drawing.Size(145, 20); + this.openCLFile.TabIndex = 3; + this.openCLFile.Text = "..\\..\\filter.cl"; + this.openCLFile.TextChanged += new System.EventHandler(this.openCLFile_TextChanged); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 20); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(64, 13); + this.label1.TabIndex = 4; + this.label1.Text = "Image-Path:"; + this.label1.Click += new System.EventHandler(this.label1_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(6, 45); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(50, 13); + this.label2.TabIndex = 5; + this.label2.Text = "\"filter.cl\":"; + // + // openFileDialog2 + // + this.openFileDialog2.Filter = "OpenCL|*.cl"; + this.openFileDialog2.Title = "Select OpenCL-File"; + // + // buttonApplyFilter + // + this.buttonApplyFilter.Location = new System.Drawing.Point(234, 41); + this.buttonApplyFilter.Name = "buttonApplyFilter"; + this.buttonApplyFilter.Size = new System.Drawing.Size(75, 21); + this.buttonApplyFilter.TabIndex = 6; + this.buttonApplyFilter.Text = "Apply Filter"; + this.buttonApplyFilter.UseVisualStyleBackColor = true; + this.buttonApplyFilter.Click += new System.EventHandler(this.button1_Click_1); + // + // pictureBox1 + // + this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.pictureBox1.Location = new System.Drawing.Point(9, 110); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(300, 300); + this.pictureBox1.TabIndex = 7; + this.pictureBox1.TabStop = false; + // + // pictureBox2 + // + this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.pictureBox2.Location = new System.Drawing.Point(9, 112); + this.pictureBox2.Name = "pictureBox2"; + this.pictureBox2.Size = new System.Drawing.Size(300, 300); + this.pictureBox2.TabIndex = 8; + this.pictureBox2.TabStop = false; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.pictureBox1); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Controls.Add(this.openCLFile); + this.groupBox1.Controls.Add(this.pictureFile); + this.groupBox1.Controls.Add(this.pictureBrowse); + this.groupBox1.Controls.Add(this.openclBrowse); + this.groupBox1.Location = new System.Drawing.Point(15, 12); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(319, 421); + this.groupBox1.TabIndex = 11; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Source-Image"; + this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter); + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.textBox1); + this.groupBox2.Controls.Add(this.button1); + this.groupBox2.Controls.Add(this.buttonBrowseFilter); + this.groupBox2.Controls.Add(this.label4); + this.groupBox2.Controls.Add(this.textStatus); + this.groupBox2.Controls.Add(this.label3); + this.groupBox2.Controls.Add(this.filterSelector); + this.groupBox2.Controls.Add(this.pictureBox2); + this.groupBox2.Controls.Add(this.buttonApplyFilter); + this.groupBox2.Location = new System.Drawing.Point(349, 12); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(319, 421); + this.groupBox2.TabIndex = 12; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Output-Image"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(74, 41); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(73, 20); + this.textBox1.TabIndex = 8; + this.textBox1.Text = "100"; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(153, 41); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 21); + this.button1.TabIndex = 13; + this.button1.Text = "Apply Again"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click_2); + // + // buttonBrowseFilter + // + this.buttonBrowseFilter.Location = new System.Drawing.Point(234, 15); + this.buttonBrowseFilter.Name = "buttonBrowseFilter"; + this.buttonBrowseFilter.Size = new System.Drawing.Size(75, 21); + this.buttonBrowseFilter.TabIndex = 8; + this.buttonBrowseFilter.Text = "Browse..."; + this.buttonBrowseFilter.UseVisualStyleBackColor = true; + this.buttonBrowseFilter.Click += new System.EventHandler(this.buttonBrowseFilter_Click); + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(6, 70); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(37, 13); + this.label4.TabIndex = 12; + this.label4.Text = "Status"; + // + // textStatus + // + this.textStatus.BackColor = System.Drawing.SystemColors.Control; + this.textStatus.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.textStatus.Enabled = false; + this.textStatus.Location = new System.Drawing.Point(9, 86); + this.textStatus.Name = "textStatus"; + this.textStatus.Size = new System.Drawing.Size(300, 13); + this.textStatus.TabIndex = 11; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(6, 20); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(62, 13); + this.label3.TabIndex = 10; + this.label3.Text = "Select Filter"; + this.label3.Click += new System.EventHandler(this.label3_Click); + // + // filterSelector + // + this.filterSelector.FormattingEnabled = true; + this.filterSelector.Location = new System.Drawing.Point(74, 15); + this.filterSelector.Name = "filterSelector"; + this.filterSelector.Size = new System.Drawing.Size(154, 21); + this.filterSelector.TabIndex = 9; + this.filterSelector.SelectedIndexChanged += new System.EventHandler(this.filterSelector_SelectedIndexChanged); + // + // openFileDialog3 + // + this.openFileDialog3.Filter = "Filter-Matrix|filter*.txt"; + this.openFileDialog3.Title = "Select Filter-File"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(681, 450); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.groupBox2); + this.Name = "Form1"; + this.Text = "OpenCL ImageFilter"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button pictureBrowse; + private System.Windows.Forms.OpenFileDialog openFileDialog1; + private System.Windows.Forms.TextBox pictureFile; + private System.Windows.Forms.Button openclBrowse; + private System.Windows.Forms.TextBox openCLFile; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.OpenFileDialog openFileDialog2; + private System.Windows.Forms.Button buttonApplyFilter; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.PictureBox pictureBox2; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.ComboBox filterSelector; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox textStatus; + private System.Windows.Forms.Button buttonBrowseFilter; + private System.Windows.Forms.OpenFileDialog openFileDialog3; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.TextBox textBox1; + } +} + diff --git a/WindowsFormsApplication1/Form1.cs b/WindowsFormsApplication1/Form1.cs new file mode 100644 index 0000000..aac3ae5 --- /dev/null +++ b/WindowsFormsApplication1/Form1.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.IO; +using System.Windows.Forms; +using SimpleOpenCLRunner; + + +namespace OpenCLImageFilter +{ + public partial class Form1 : Form + { + private ImageFilter oImageFilter; + + public Form1() + { + InitializeComponent(); + this.oImageFilter = new ImageFilter(); + this.setPicture(); + this.readCL(); + } + + private void button1_Click(object sender, EventArgs e) + { + this.openFileDialog1.FileName = this.pictureFile.Text; + if (this.openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + if (!File.Exists(this.openFileDialog1.FileName)) + { + MessageBox.Show("Invalid Picture Path"); + return; + } + this.pictureFile.Text = openFileDialog1.FileName; + this.setPicture(); + } + } + + private void openclBrowse_Click(object sender, EventArgs e) + { + this.openFileDialog2.FileName = this.openCLFile.Text; + if (this.openFileDialog2.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + if (!File.Exists(this.openFileDialog2.FileName)) + { + MessageBox.Show("Invalid OpenCL-File Path"); + return; + } + this.openCLFile.Text = openFileDialog2.FileName; + this.readCL(); + + } + } + + private void button1_Click_1(object sender, EventArgs e) + { + this.readCL(); + + if (!File.Exists(this.pictureFile.Text)) + { + MessageBox.Show("Invalid Picture Path"); + return; + } + Bitmap org_file = new Bitmap(this.pictureFile.Text); + + this.pictureBox1.Image = org_file; + this.Refresh(); + this.pictureBox2.Image = this.oImageFilter.run(org_file, this.textStatus); + this.Refresh(); + } + + private void label4_Click(object sender, EventArgs e) + { + + } + + private void label1_Click(object sender, EventArgs e) + { + + } + + private void groupBox1_Enter(object sender, EventArgs e) + { + + } + + private void label3_Click(object sender, EventArgs e) + { + + } + + private void buttonBrowseFilter_Click(object sender, EventArgs e) + { + this.openFileDialog3.FileName = this.openCLFile.Text; + if (this.openFileDialog3.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + if (!File.Exists(this.openFileDialog3.FileName)) + { + MessageBox.Show("Invalid Filter-File Path"); + return; + } + + if (!this.filterSelector.Items.Contains(this.openFileDialog3.FileName)) + { + this.filterSelector.Items.Add(this.openFileDialog3.FileName); + } + this.filterSelector.SelectedIndex = this.filterSelector.Items.IndexOf(this.openFileDialog3.FileName); + this.setFilter(); + } + } + + private void filterSelector_SelectedIndexChanged(object sender, EventArgs e) + { + this.setFilter(); + } + + private void setFilter() + { + this.textStatus.Text = "Preparing Filter..."; + this.Refresh(); + + string oFileName = (string)this.filterSelector.Items[this.filterSelector.SelectedIndex]; + + this.oImageFilter.readMask(oFileName); + + this.textStatus.Text += " Done!"; + this.Refresh(); + } + + private void setPicture() + { + this.textStatus.Text = "Reading Source-Image..."; + this.Refresh(); + Bitmap org_file = new Bitmap(this.pictureFile.Text); + this.pictureBox1.Image = org_file; + this.textStatus.Text += " Done!"; + this.Refresh(); + } + + private void readCL() + { + this.textStatus.Text = "Preparing OpenCL-File..."; + this.Refresh(); + this.oImageFilter.readCL(this.openCLFile.Text); + this.textStatus.Text += " Done!"; + this.Refresh(); + } + + + private void button1_Click_2(object sender, EventArgs e) + { + this.textStatus.Text = "Running " + this.textBox1.Text + " times incrementell..."; + this.pictureBox2.Image = this.oImageFilter.run_again(int.Parse(this.textBox1.Text)); + this.Refresh(); + this.textStatus.Text += " Done!"; + } + + private void pictureFile_TextChanged(object sender, EventArgs e) + { + this.setPicture(); + } + + private void openCLFile_TextChanged(object sender, EventArgs e) + { + this.readCL(); + } + } +} diff --git a/WindowsFormsApplication1/Form1.resx b/WindowsFormsApplication1/Form1.resx new file mode 100644 index 0000000..cc85890 --- /dev/null +++ b/WindowsFormsApplication1/Form1.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 150, 17 + + + True + + + 283, 17 + + \ No newline at end of file diff --git a/WindowsFormsApplication1/ImageFilter.cs b/WindowsFormsApplication1/ImageFilter.cs new file mode 100644 index 0000000..c16fc77 --- /dev/null +++ b/WindowsFormsApplication1/ImageFilter.cs @@ -0,0 +1,181 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Drawing; +using OpenCLTemplate; +using System.Windows.Forms; +using System.IO; +using SimpleOpenCLRunner; + +namespace OpenCLImageFilter +{ + class ImageFilter + { + private float[] afMask; + + private bool bInit = false; + + private Bitmap oInputImage; + private byte[] bPicture; + private byte[] bPictureOut; + + private int[] anWorkers; + + public ImageFilter() + { + OpenCLRunner.init(); + } + + public void readCL(string oFileName) + { + OpenCLRunner.readCL(oFileName); + OpenCLRunner.compile(); + } + + + public void readMask(string oFileName) + { + StreamReader oBuffer = new StreamReader(oFileName, System.Text.Encoding.UTF8); + + int size = int.Parse(oBuffer.ReadLine()); + float[] afMask = new float[size * size]; + String[] oVars; + for (int nI = 0; nI < size; nI++) + { + oVars = (oBuffer.ReadLine()).Split(','); + for (int nJ = 0; nJ < size; nJ++) + { + afMask[nJ * size + nI] = float.Parse(oVars[nJ]); + } + } + + this.setMask(afMask); + } + + public void setMask(float[] afMask) + { + this.afMask = afMask; + this.bInit = true; + + int nMaskSize = (int)Math.Sqrt((double)this.afMask.Length); + + OpenCLRunner.createVariable("mask", this.afMask); + OpenCLRunner.createVariable("maskSize", new int[] { nMaskSize }); + } + + public Bitmap run_again(int times) + { + if (!this.bInit) + { + MessageBox.Show("Select an Filter first!"); + return new Bitmap(1,1); + } + Bitmap oOutputImage = new Bitmap(this.oInputImage.Width, this.oInputImage.Height); + + + OpenCLRunner.createFunction("recycle", new string[] {"pictureIn", + "pictureOut", + "dimensions"}); + + for (int nI = 0; nI < times; nI++) + { + OpenCLRunner.runFunction("recycle"); + OpenCLRunner.runFunction("filter"); + } + + OpenCLRunner.returnData("pictureOut", ref bPictureOut); + + + //unserialzing the image + long i; + i = 0; + for (int nI = 0; nI < oInputImage.Height; nI++) + { + for (int nJ = 0; nJ < oInputImage.Width; nJ++) + { + oOutputImage.SetPixel(nJ, nI, Color.FromArgb((int)bPictureOut[i + 0], (int)bPictureOut[i + 1], (int)bPictureOut[i + 2], (int)bPictureOut[i + 3])); + i += 4; + } + } + + return oOutputImage; + } + + public Bitmap run(Bitmap oInputImage, TextBox textStatus) + { + if (!this.bInit) + { + MessageBox.Show("Select an Filter first!"); + return oInputImage; + } + + textStatus.Text = "Preparing Image..."; + textStatus.Parent.Refresh(); + + Bitmap oOutputImage = new Bitmap(oInputImage.Width, oInputImage.Height); + + this.oInputImage = oInputImage; + + this.bPicture = new byte[oInputImage.Width * oInputImage.Height * 4]; + this.bPictureOut = new byte[oInputImage.Width * oInputImage.Height * 4]; + + this.anWorkers = new int[] { oInputImage.Height, oInputImage.Width }; + + + OpenCLRunner.setWorkers(this.anWorkers); + + //serializing the Image + long i = 0; + for (int nI = 0; nI < oInputImage.Height; nI++) + { + for (int nJ = 0; nJ < oInputImage.Width; nJ++) + { + this.bPicture[i + 0] = oInputImage.GetPixel(nJ, nI).A; + this.bPicture[i + 1] = oInputImage.GetPixel(nJ, nI).R; + this.bPicture[i + 2] = oInputImage.GetPixel(nJ, nI).G; + this.bPicture[i + 3] = oInputImage.GetPixel(nJ, nI).B; + i += 4; + } + } + + textStatus.Text = "Sending Image to GPU..."; + textStatus.Parent.Refresh(); + + OpenCLRunner.createVariable("pictureIn", bPicture); + OpenCLRunner.createVariable("pictureOut", bPictureOut); + OpenCLRunner.createVariable("dimensions", new int[] { oInputImage.Width, oInputImage.Height }); + + textStatus.Text = "Calculating..."; + textStatus.Parent.Refresh(); + + OpenCLRunner.createFunction("filter", new string[] { "pictureIn", + "pictureOut", + "dimensions", + "mask", + "maskSize" }); + OpenCLRunner.runFunction("filter"); + + + textStatus.Text = "Pulling back the data..."; + textStatus.Parent.Refresh(); + + OpenCLRunner.returnData("pictureOut", ref bPictureOut); + + //unserializing the image + i = 0; + for (int nI = 0; nI < oInputImage.Height; nI++) + { + for (int nJ = 0; nJ < oInputImage.Width; nJ++) + { + oOutputImage.SetPixel(nJ, nI, Color.FromArgb((int)bPictureOut[i + 0], (int)bPictureOut[i + 1], (int)bPictureOut[i + 2], (int)bPictureOut[i + 3])); + i += 4; + } + } + + textStatus.Text += " Done!"; + textStatus.Parent.Refresh(); + return oOutputImage; + } + } +} diff --git a/WindowsFormsApplication1/OpenCLImageFilter.csproj b/WindowsFormsApplication1/OpenCLImageFilter.csproj new file mode 100644 index 0000000..7e8410a --- /dev/null +++ b/WindowsFormsApplication1/OpenCLImageFilter.csproj @@ -0,0 +1,98 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {25E1C72C-5114-4EA3-8DD8-F9435E832214} + WinExe + Properties + OpenCLImageFilter + WindowsFormsApplication1 + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\Code Snippets\OpenCLTemplate\OpenCL.NET.dll + + + False + ..\..\..\Code Snippets\OpenCLTemplate\OpenCLTemplate.dll + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + \ No newline at end of file diff --git a/WindowsFormsApplication1/OpenCLRunner.cs b/WindowsFormsApplication1/OpenCLRunner.cs new file mode 100644 index 0000000..4a2f485 --- /dev/null +++ b/WindowsFormsApplication1/OpenCLRunner.cs @@ -0,0 +1,560 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using OpenCLTemplate; +using System.Windows.Forms; + + +namespace SimpleOpenCLRunner +{ + class OpenCLRunner + { + private static String oCLCode; + private static bool bInit = false; + private static bool bCompiled = false; + private static bool bRead = false; + private static int[] anWorkers = new int[] { 1 }; + + private static TimeSpan oElapsedExecutionTime; + private static TimeSpan oElapsedInitTime; + private static TimeSpan oElapsedCompileTime; + + private static System.Diagnostics.Stopwatch oWatch = new System.Diagnostics.Stopwatch(); + + private static Dictionary oFunctionDict = new Dictionary(); + private static Dictionary oVarDict = new Dictionary(); + + private static List oCompileLogsList = new List(); + + public static bool init() + { + try + { + System.Diagnostics.Stopwatch oWatch = new System.Diagnostics.Stopwatch(); + oWatch.Start(); + + //init + CLCalc.InitCL(); + OpenCLRunner.bInit = true; + + oWatch.Stop(); + OpenCLRunner.oElapsedInitTime = oWatch.Elapsed; CLCalc.InitCL(); + } + catch (Exception e) + { + MessageBox.Show("CLCalc-Error:\n===================\n\n" + e.ToString() + "\n\n" + e.Message); + OpenCLRunner.bInit = false; + } + return OpenCLRunner.bInit; + } + + + public static void start() + { + OpenCLRunner.oWatch.Start(); + } + public static TimeSpan stop() + { + OpenCLRunner.oWatch.Stop(); + return OpenCLRunner.oWatch.Elapsed; + } + + public static void setWorkers(int[] anWorkers) + { + OpenCLRunner.anWorkers = anWorkers; + } + + public static int[] getWorkers() + { + return OpenCLRunner.anWorkers; + } + + public static TimeSpan getExecutionTime() + { + return OpenCLRunner.oElapsedExecutionTime; + } + public static TimeSpan getInitTime() + { + return OpenCLRunner.oElapsedInitTime; + } + public static TimeSpan getCompileTime() + { + return OpenCLRunner.oElapsedCompileTime; + } + + + public static void readCL(String oFilename) + { + if (!OpenCLRunner.bInit) + { + OpenCLRunner.init(); + } + if (!File.Exists(oFilename)) + { + MessageBox.Show("Datei \"" + oFilename + "\" nicht vorhanden"); + OpenCLRunner.bRead = false; + } + else + { + StreamReader oBuffer = new StreamReader(oFilename, System.Text.Encoding.UTF8); + OpenCLRunner.bRead = false; + OpenCLRunner.oCLCode = ""; + while (!oBuffer.EndOfStream) + { + OpenCLRunner.oCLCode += oBuffer.ReadLine() + "\r\n"; + } + oBuffer.Close(); + OpenCLRunner.bCompiled = false; + OpenCLRunner.bRead = true; + } + } + + + public static bool compile() + { + if (OpenCLRunner.bInit) + { + if (OpenCLRunner.bRead) + { + try + { + System.Diagnostics.Stopwatch oWatch = new System.Diagnostics.Stopwatch(); + oWatch.Start(); + + OpenCLRunner.bCompiled = false; + CLCalc.Program.Compile(OpenCLRunner.oCLCode, out OpenCLRunner.oCompileLogsList); + OpenCLRunner.bCompiled = true; + + oWatch.Stop(); + OpenCLRunner.oElapsedCompileTime = oWatch.Elapsed; + } + catch (Exception e) + { + MessageBox.Show("CLCalc-Error:\n===================\n\n" + e.ToString() + "\n\n" + e.Data); + + List.Enumerator iCompileLogs = OpenCLRunner.oCompileLogsList.GetEnumerator(); + while(iCompileLogs.MoveNext()) + { + MessageBox.Show("CompileLogs:\n===================\n\n" + iCompileLogs.Current); + } + } + } + else + { + MessageBox.Show("CL-Code must be read before compile!"); + } + } + else + { + MessageBox.Show("CL-Device must be initiated before compile!"); + } + + return OpenCLRunner.bCompiled; + } + + + + public static OpenCLFunction createFunction(String oCLFunctionName, string[] oVarNames) + { + return OpenCLRunner.createFunction(oCLFunctionName, OpenCLRunner.Variables(oVarNames)); + } + + public static OpenCLFunction createFunction(String oCLFunctionName, OpenCLVariable[] aoCLVars) + { + OpenCLFunction oCLFunction = OpenCLRunner.createFunction(oCLFunctionName); + oCLFunction.setVars(aoCLVars); + return oCLFunction; + } + + public static OpenCLFunction createFunction(String oCLFunctionName) + { + OpenCLFunction oCLFunction; + if (OpenCLRunner.oFunctionDict.ContainsKey(oCLFunctionName)) + { + OpenCLRunner.oFunctionDict.TryGetValue(oCLFunctionName, out oCLFunction); + } + else + { + oCLFunction = new OpenCLFunction(oCLFunctionName); + OpenCLRunner.oFunctionDict.Add(oCLFunctionName, oCLFunction); + } + return oCLFunction; + } + + + + public static OpenCLVariable createVariable(string oVarName, float[] fInput) + { + OpenCLVariable oCLVar; + if (OpenCLRunner.oVarDict.TryGetValue(oVarName, out oCLVar)) + { + oCLVar.set(fInput); + } + else + { + oCLVar = new OpenCLVariable(fInput); + OpenCLRunner.oVarDict.Add(oVarName, oCLVar); + } + return oCLVar; + } + + public static OpenCLVariable createVariable(string oVarName, byte[] bInput) + { + OpenCLVariable oCLVar; + if (OpenCLRunner.oVarDict.TryGetValue(oVarName, out oCLVar)) + { + oCLVar.set(bInput); + } + else + { + oCLVar = new OpenCLVariable(bInput); + OpenCLRunner.oVarDict.Add(oVarName, oCLVar); + } + return oCLVar; + } + public static OpenCLVariable createVariable(string oVarName, double[] dInput) + { + OpenCLVariable oCLVar; + if (OpenCLRunner.oVarDict.TryGetValue(oVarName, out oCLVar)) + { + oCLVar.set(dInput); + } + else + { + oCLVar = new OpenCLVariable(dInput); + OpenCLRunner.oVarDict.Add(oVarName, oCLVar); + } + return oCLVar; + } + public static OpenCLVariable createVariable(string oVarName, char[] cInput) + { + OpenCLVariable oCLVar; + if (OpenCLRunner.oVarDict.TryGetValue(oVarName, out oCLVar)) + { + oCLVar.set(cInput); + } + else + { + oCLVar = new OpenCLVariable(cInput); + OpenCLRunner.oVarDict.Add(oVarName, oCLVar); + } + return oCLVar; + } + public static OpenCLVariable createVariable(string oVarName, int[] nInput) + { + OpenCLVariable oCLVar; + if (OpenCLRunner.oVarDict.TryGetValue(oVarName, out oCLVar)) + { + oCLVar.set(nInput); + } + else + { + oCLVar = new OpenCLVariable(nInput); + OpenCLRunner.oVarDict.Add(oVarName, oCLVar); + } + return oCLVar; + } + public static OpenCLVariable createVariable(string oVarName, long[] lInput) + { + OpenCLVariable oCLVar; + if (OpenCLRunner.oVarDict.TryGetValue(oVarName, out oCLVar)) + { + oCLVar.set(lInput); + } + else + { + oCLVar = new OpenCLVariable(lInput); + OpenCLRunner.oVarDict.Add(oVarName, oCLVar); + } + return oCLVar; + } + + + + public static OpenCLVariable Variable(string oVarName) + { + OpenCLVariable oCLVar; + if (!OpenCLRunner.oVarDict.TryGetValue(oVarName, out oCLVar)) + { + MessageBox.Show("Variable \"" + oVarName + "\" existiert nicht!"); + } + return oCLVar; + } + + public static OpenCLVariable[] Variables(string[] oVarNames) + { + OpenCLVariable[] oCLVars = new OpenCLVariable[oVarNames.Length]; + + for (int nI = 0; nI < oVarNames.Length; nI++) + { + if (!OpenCLRunner.oVarDict.TryGetValue(oVarNames[nI], out oCLVars[nI])) + { + MessageBox.Show("Variable \"" + oVarNames[nI] + "\" existiert nicht!"); + } + } + return oCLVars; + } + + + + public static bool returnData(string oVarName, ref byte[] bOutput) + { + OpenCLVariable oCLVar; + if (OpenCLRunner.oVarDict.TryGetValue(oVarName, out oCLVar)) + { + oCLVar.returnData(ref bOutput); + return true; + } + else + { + MessageBox.Show("Variable \"" + oVarName + "\" existiert nicht!"); + return false; + } + } + public static bool returnData(string oVarName, ref float[] fOutput) + { + OpenCLVariable oCLVar; + if (OpenCLRunner.oVarDict.TryGetValue(oVarName, out oCLVar)) + { + oCLVar.returnData(ref fOutput); + return true; + } + else + { + MessageBox.Show("Variable \"" + oVarName + "\" existiert nicht!"); + return false; + } + } + public static bool returnData(string oVarName, ref double[] dOutput) + { + OpenCLVariable oCLVar; + if (OpenCLRunner.oVarDict.TryGetValue(oVarName, out oCLVar)) + { + oCLVar.returnData(ref dOutput); + return true; + } + else + { + MessageBox.Show("Variable \"" + oVarName + "\" existiert nicht!"); + return false; + } + } + public static bool returnData(string oVarName, ref int[] nOutput) + { + OpenCLVariable oCLVar; + if (OpenCLRunner.oVarDict.TryGetValue(oVarName, out oCLVar)) + { + oCLVar.returnData(ref nOutput); + return true; + } + else + { + MessageBox.Show("Variable \"" + oVarName + "\" existiert nicht!"); + return false; + } + } + public static bool returnData(string oVarName, ref long[] lOutput) + { + OpenCLVariable oCLVar; + if (OpenCLRunner.oVarDict.TryGetValue(oVarName, out oCLVar)) + { + oCLVar.returnData(ref lOutput); + return true; + } + else + { + MessageBox.Show("Variable \"" + oVarName + "\" existiert nicht!"); + return false; + } + } + public static bool returnData(string oVarName, ref char[] cOutput) + { + OpenCLVariable oCLVar; + if (OpenCLRunner.oVarDict.TryGetValue(oVarName, out oCLVar)) + { + oCLVar.returnData(ref cOutput); + return true; + } + else + { + MessageBox.Show("Variable \"" + oVarName + "\" existiert nicht!"); + return false; + } + } + + + + + public static void runFunction(String oCLFunctionName) + { + OpenCLFunction oCLFunction; + if (OpenCLRunner.oFunctionDict.TryGetValue(oCLFunctionName, out oCLFunction)) + { + oCLFunction.run(); + } + else + { + MessageBox.Show("Funktion \"" + oCLFunctionName + "\" existiert nicht!"); + } + } + + public static void runFunction(String oCLFunctionName, OpenCLVariable[] aoCLVars) + { + OpenCLFunction oCLFunction; + if (OpenCLRunner.oFunctionDict.TryGetValue(oCLFunctionName, out oCLFunction)) + { + System.Diagnostics.Stopwatch oWatch = new System.Diagnostics.Stopwatch(); + oWatch.Start(); + + oCLFunction.run(aoCLVars); + + oWatch.Stop(); + oElapsedExecutionTime = oWatch.Elapsed; + } + else + { + MessageBox.Show("Funktion \"" + oCLFunctionName + "\" existiert nicht!"); + } + } + + + } + + + + + class OpenCLFunction + { + private CLCalc.Program.Kernel oCLFunction; + private bool bArgsSet = false; + private OpenCLVariable[] aoCLVars; + + public OpenCLFunction(string oCLFunctionName) + { + try + { + this.oCLFunction = new CLCalc.Program.Kernel(oCLFunctionName); + } + catch (Exception e) + { + MessageBox.Show("CLCalc-Error:\n===================\n\n" + e.ToString()); + } + } + + public void run() + { + if(bArgsSet) { + this.run(this.aoCLVars); + } else { + MessageBox.Show("Variablen wurden nicht gesetzt!"); + } + } + + public void setVars(OpenCLVariable[] aoCLVars) { + this.aoCLVars = aoCLVars; + this.bArgsSet = true; + } + + public void run(OpenCLVariable[] aoGpuVars) + { + CLCalc.Program.Variable[] aoCLGpuVars = new CLCalc.Program.Variable[aoGpuVars.Length]; + for(int nI = 0; nI < aoGpuVars.Length; nI++) { + aoCLGpuVars[nI] = aoGpuVars[nI].getCLVar(); + } + //run on GPU + this.oCLFunction.Execute(aoCLGpuVars, OpenCLRunner.getWorkers()); + } + } + + + + + class OpenCLVariable + { + private CLCalc.Program.Variable oCLVar; + + public CLCalc.Program.Variable getCLVar() + { + return this.oCLVar; + } + + public OpenCLVariable(byte[] bInput) + { + this.oCLVar = new CLCalc.Program.Variable(bInput); + } + public OpenCLVariable(char[] cInput) + { + this.oCLVar = new CLCalc.Program.Variable(cInput); + } + public OpenCLVariable(double[] dInput) + { + this.oCLVar = new CLCalc.Program.Variable(dInput); + } + public OpenCLVariable(float[] fInput) + { + this.oCLVar = new CLCalc.Program.Variable(fInput); + } + public OpenCLVariable(int[] nInput) + { + this.oCLVar = new CLCalc.Program.Variable(nInput); + } + public OpenCLVariable(long[] lInput) + { + this.oCLVar = new CLCalc.Program.Variable(lInput); + } + + + public void set(byte[] bInput) + { + this.oCLVar.WriteToDevice(bInput); + } + public void set(char[] cInput) + { + this.oCLVar.WriteToDevice(cInput); + } + public void set(double[] dInput) + { + this.oCLVar.WriteToDevice(dInput); + } + public void set(float[] fInput) + { + this.oCLVar.WriteToDevice(fInput); + } + public void set(int[] nInput) + { + this.oCLVar.WriteToDevice(nInput); + } + public void set(long[] lInput) + { + this.oCLVar.WriteToDevice(lInput); + } + + + public void returnData(ref byte[] bVar) + { + this.oCLVar.ReadFromDeviceTo(bVar); + } + public void returnData(ref char[] cVar) + { + this.oCLVar.ReadFromDeviceTo(cVar); + } + public void returnData(ref double[] dVar) + { + this.oCLVar.ReadFromDeviceTo(dVar); + } + public void returnData(ref float[] fVar) + { + this.oCLVar.ReadFromDeviceTo(fVar); + } + public void returnData(ref int[] nVar) + { + this.oCLVar.ReadFromDeviceTo(nVar); + } + public void returnData(ref long[] lVar) + { + this.oCLVar.ReadFromDeviceTo(lVar); + } + } +} diff --git a/WindowsFormsApplication1/Program.cs b/WindowsFormsApplication1/Program.cs new file mode 100644 index 0000000..01de5a2 --- /dev/null +++ b/WindowsFormsApplication1/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace OpenCLImageFilter +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/WindowsFormsApplication1/Properties/AssemblyInfo.cs b/WindowsFormsApplication1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f640cbc --- /dev/null +++ b/WindowsFormsApplication1/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WindowsFormsApplication1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("WindowsFormsApplication1")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e8c53c6f-4a95-467d-98f8-284f6a222ff2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/WindowsFormsApplication1/Properties/Resources.Designer.cs b/WindowsFormsApplication1/Properties/Resources.Designer.cs new file mode 100644 index 0000000..d770331 --- /dev/null +++ b/WindowsFormsApplication1/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.1 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace OpenCLImageFilter.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OpenCLImageFilter.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/WindowsFormsApplication1/Properties/Resources.resx b/WindowsFormsApplication1/Properties/Resources.resx new file mode 100644 index 0000000..ffecec8 --- /dev/null +++ b/WindowsFormsApplication1/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WindowsFormsApplication1/Properties/Settings.Designer.cs b/WindowsFormsApplication1/Properties/Settings.Designer.cs new file mode 100644 index 0000000..c1c350b --- /dev/null +++ b/WindowsFormsApplication1/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.1 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace OpenCLImageFilter.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/WindowsFormsApplication1/Properties/Settings.settings b/WindowsFormsApplication1/Properties/Settings.settings new file mode 100644 index 0000000..abf36c5 --- /dev/null +++ b/WindowsFormsApplication1/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/WindowsFormsApplication1/SimpleCL.cl b/WindowsFormsApplication1/SimpleCL.cl new file mode 100644 index 0000000..85c0791 --- /dev/null +++ b/WindowsFormsApplication1/SimpleCL.cl @@ -0,0 +1,6 @@ +kernel void +sum(global float16 * x, global float16 * y) +{ + int i = get_global_id(0); + x[i] = x[i] + y[i]; +} diff --git a/WindowsFormsApplication1/bin/Debug/OpenCL.NET.dll b/WindowsFormsApplication1/bin/Debug/OpenCL.NET.dll new file mode 100644 index 0000000..1cb7ace Binary files /dev/null and b/WindowsFormsApplication1/bin/Debug/OpenCL.NET.dll differ diff --git a/WindowsFormsApplication1/bin/Debug/OpenCL.NET.xml b/WindowsFormsApplication1/bin/Debug/OpenCL.NET.xml new file mode 100644 index 0000000..3026ddc --- /dev/null +++ b/WindowsFormsApplication1/bin/Debug/OpenCL.NET.xml @@ -0,0 +1,143 @@ + + + + OpenCL.NET + + + + + This class provides the driver interface for OpenGL interoperability + with OpenCL standard. + + + + + This class provides the driver interface to OpenCL functions. + + + + + Used to represent a platform dependent sized variable. + On 32 bit platforms it is 4 bytes wide (int, uint), on 64 bit it is + 8 bytes wide (long, ulong). + + This class maps to the C/C++ native size_t data type. + + + + + Creates a new instance based on the given value. + + Integer value to represent. + + + + Creates a new instance based on the given value. + + Integer value to represent. + + + + Creates a new instance based on the given value. + + Integer value to represent. + + + + Creates a new instance based on the given value. + + Integer value to represent. + + + + Converts the object to int. + + Object to convert. + Integer value represented by the object. + + + + Converts the object to uint. + + Object to convert. + Integer value represented by the object. + + + + Converts the object to long. + + Object to convert. + Integer value represented by the object. + + + + Converts the object to ulong. + + Object to convert. + Integer value represented by the object. + + + + Converts the given integer to an object. + + Integer value to convert. + New object representing this value. + + + + Converts the given integer to an object. + + Integer value to convert. + New object representing this value. + + + + Converts the given integer to an object. + + Integer value to convert. + New object representing this value. + + + + Converts the given integer to an object. + + Integer value to convert. + New object representing this value. + + + + Compares two SizeT objects. + + First value to compare. + Second value to compare. + true or false for the comparison result. + + + + Compares two SizeT objects. + + First value to compare. + Second value to compare. + true or false for the comparison result. + + + + Returns a value indicating whether this instance is equal to a specified object. + + An object to compare with this instance or null. + true if obj is an instance of System.IntPtr and equals the value of this instance; otherwise, false. + + + + Converts the numeric value of the current object to its equivalent string representation. + + The string representation of the value of this instance. + + + + Returns the hash code for this instance. + + A 32-bit signed integer hash code. + + + diff --git a/WindowsFormsApplication1/bin/Debug/OpenCLTemplate.dll b/WindowsFormsApplication1/bin/Debug/OpenCLTemplate.dll new file mode 100644 index 0000000..5e2b3d4 Binary files /dev/null and b/WindowsFormsApplication1/bin/Debug/OpenCLTemplate.dll differ diff --git a/WindowsFormsApplication1/bin/Debug/OpenCLTemplate.xml b/WindowsFormsApplication1/bin/Debug/OpenCLTemplate.xml new file mode 100644 index 0000000..bcbd296 --- /dev/null +++ b/WindowsFormsApplication1/bin/Debug/OpenCLTemplate.xml @@ -0,0 +1,1417 @@ + + + + OpenCLTemplate + + + + OpenCL calculations class + + + String to include to enable Double Precision calculations + + + Currently used acceleration + + + Initialization error + + + Sets CLCalc status to NotUsingCL + + + Initializes OpenCL and reads devices + + + Initializes OpenCL from an existing Context and reads devices + Existing context pointer + Existing command queue pointer + + + Tries to execute actual code in device to check its availability. + Command queue number to check + + + Releases OpenCL resources + + + Last found error + + + List of available platforms + + + List of available devices + + + Gets string to include to enable Double Precision calculations + + + Gets acceleration type being used + + + Gets initialization error description + + + Last error. Throws exception if not set to success. + + + OpenCL accelerations + + + Has not tested what type of acceleration is going to be used. + + + OpenCL used to accelerate calculations + + + No OpenCL used/supported + + + Class to hold OpenCL devices + + + Device ID + + + Device type string + + + Device name string + + + Device vendor string + + + OpenCL version string + + + Execution capabilities of the device + + + Is device available? + + + Is device compiler available? + + + Maximum memory allocation size in bytes + + + Memory size in bytes + + + Maximum number of work-items + that can be specified in each dimension of the work-group + to clEnqueueNDRangeKernel. + + + Maximum number of work-items in a + work-group executing a kernel using the data parallel execution model. + + + Constructor + Device ID + + + Class to hold OpenCL Platforms + + + Platform ID + + + OpenCL profile string. Profile name supported by the implementation. + + + OpenCL version string. + + + OpenCL name string. + + + OpenCL vendor string. + + + OpenCL extensions string. + + + Constructor. + Sets this platform's ID + + + Program related stuff + + + Local event + + + OpenCL context using all devices + + + Synchronous command queues that are executed in call order + + + Asynchronous command queues + + + Default synchronous command queue set as the first GPU, for ease of use. + + + Compiled program + + + Ends all commands being executed + + + Compiles program contained in a single string. + Source code to compile + + + Compiles program contained in a single string. Returns build logs for each device. + Source code to compile + Build logs for each device + + + Compiles the program. + Source code to compile + + + Compiles the program. Returns the build logs for each device. + Source code array to compile + Build logs for each device + + + Variables class + + + Data to be stored + + + Original variable length + + + Memory buffer + + + Constructor. Creates from an existing OpenCL variable + OpenCL variable pointer + Original array length + sizeOf(array datatype) + + + Constructor. + Variable whose size will be allocated in device memory. + + + Constructor. + Variable whose size will be allocated in device memory. + + + Constructor. + Variable whose size will be allocated in device memory. + + + Constructor. + Variable whose size will be allocated in device memory. + + + Constructor. + Variable whose size will be allocated in device memory. + + + Constructor. + Variable whose size will be allocated in device memory. + + + Writes variable to device + Values to write to device + Command queue to use + TRUE to return only after completed writing. + OpenCL Event associated to this operation + OpenCL Events that need to finish before this one can start + + + Writes variable to device + Values to write to device + + + Writes variable to device + Values to write to device + Command queue to use + TRUE to return only after completed writing. + OpenCL Event associated to this operation + OpenCL Events that need to finish before this one can start + + + Writes variable to device + Values to write to device + + + Writes variable to device + Values to write to device + Command queue to use + TRUE to return only after completed writing. + OpenCL Event associated to this operation + OpenCL Events that need to finish before this one can start + + + Writes variable to device + Values to write to device + + + Writes variable to device + Values to write to device + Command queue to use + TRUE to return only after completed writing. + OpenCL Event associated to this operation + OpenCL Events that need to finish before this one can start + + + Writes variable to device + Values to write to device + + + Writes variable to device + Values to write to device + Command queue to use + TRUE to return only after completed writing. + OpenCL Event associated to this operation + OpenCL Events that need to finish before this one can start + + + Writes variable to device + Values to write to device + + + Writes variable to device + Values to write to device + Command queue to use + TRUE to return only after completed writing. + OpenCL Event associated to this operation + OpenCL Events that need to finish before this one can start + + + Writes variable to device + Values to write to device + + + Reads variable from device. + Values to store data coming from device + Command queue to use + TRUE to return only after completed reading. + OpenCL Event associated with this operation + OpenCL Events that need to finish before this one can start + + + Reads variable from device. Does not return until data has been copied. + Values to store data coming from device + + + Reads variable from device. + Values to store data coming from device + Command queue to use + TRUE to return only after completed reading. + OpenCL Event associated with this operation + OpenCL Events that need to finish before this one can start + + + Reads variable from device. Does not return until data has been copied. + Values to store data coming from device + + + Reads variable from device. + Values to store data coming from device + Command queue to use + TRUE to return only after completed reading. + OpenCL Event associated with this operation + OpenCL Events that need to finish before this one can start + + + Reads variable from device. Does not return until data has been copied. + Values to store data coming from device + + + Reads variable from device. + Values to store data coming from device + Command queue to use + TRUE to return only after completed reading. + OpenCL Event associated with this operation + OpenCL Events that need to finish before this one can start + + + Reads variable from device. Does not return until data has been copied. + Values to store data coming from device + + + Reads variable from device. + Values to store data coming from device + Command queue to use + TRUE to return only after completed reading. + OpenCL Event associated with this operation + OpenCL Events that need to finish before this one can start + + + Reads variable from device. Does not return until data has been copied. + Values to store data coming from device + + + Reads variable from device. + Values to store data coming from device + Command queue to use + TRUE to return only after completed reading. + OpenCL Event associated with this operation + OpenCL Events that need to finish before this one can start + + + Reads variable from device. Does not return until data has been copied. + Values to store data coming from device + + + Sets this variable as an argument for a kernel + Index of kernel argument + Kernel to receive argument + + + Releases variable from memory. + + + Destructor + + + Returns the size of the stored variable + + + Kernels class + + + Local kernel storage + + + Number of arguments + + + Creates a new Kernel + + + + "Remember" variables + + + Sets kernel arguments + Variables to be set as arguments + + + Execute this kernel + Command queue to use + Arguments of the kernel function + Array of maximum index arrays. Total work-items = product(max[i],i+0..n-1), n=max.Length + Events to wait before executing this + Event of this command + + + Execute this kernel + Command queue to use + Arguments of the kernel function + Array of maximum index arrays. Total work-items = product(max[i],i+0..n-1), n=max.Length + Local work sizes + Events to wait before executing this + Event of this command + + + Execute this kernel + Array of maximum index arrays. Total work-items = product(max[i],i+0..n-1), n=max.Length + Arguments of the kernel function + + + Execute this kernel using work_dim = 1 + Global work size in one-dimension. global_work_size = new int[1] {GlobalWorkSize} + Arguments of the kernel function + + + Execute this kernel + Array of maximum index arrays. Total work-items = product(max[i],i+0..n-1), n=max.Length + Local work sizes + Arguments of the kernel function + + + Releases kernel from memory + + + Destructor + + + Gets how many arguments this kernel has + + + OpenCL programs + + + Basic linear algebra functions + + + Float vector sum kernel + + + float matrix multiplication kernel + + + float Gauss Seidel method + + + LU factorizaton method + + + Constructor. Builds OpenCL program. + + + Converts vector to matrix + Vector + Matrix first dimension + Matrix second dimension + + + Converts matrix to vector + Matrix + Matrix first dimension + Matrix second dimension + + + Returns the sum of two matrices + Matrix 1 + Matrix 2 + + + Matrix multiplication + Matrix 1 + Matrix 2 + + + Gauss Seidel method for iterative linear system solving. Returns unknown x + Matrix M so that Mx=b + Initial estimate + Known vector b + Gauss-Seidel iterations per step + Maximum number of times Gauss-Seidel iterations + Desired sqrt(Sum(error[i]^2))*number of equations + Estimated absolute error per component + + + Gauss Seidel method for iterative linear system solving. Returns unknown x + Matrix M so that Mx=b + Initial estimate + Known vector b + Estimated error per equation + + + Solves linear system Mx = b by LU decomposition. Returns x + Matrix M + Vector b + Maximum acceptable absolute error + Maximum iterations + + + Calculates LU decomposition of M matrix + Matrix to decompose + Matrix dimension + Swap index + + + Gauss Seidel method. Make sure to send x = b. Replaces x. + + + Matrix multiplication. Dimensions { p, r }. + + + + Basic linear algebra functions + + + Float vector sum kernel + + + double matrix multiplication kernel + + + double Gauss Seidel method + + + LU factorizaton method + + + Constructor. Builds OpenCL program. + + + Converts vector to matrix + Vector + Matrix first dimension + Matrix second dimension + + + Converts matrix to vector + Matrix + Matrix first dimension + Matrix second dimension + + + Returns the sum of two matrices + Matrix 1 + Matrix 2 + + + Matrix multiplication + Matrix 1 + Matrix 2 + + + Gauss Seidel method for iterative linear system solving. Returns unknown x + Matrix M so that Mx=b + Initial estimate + Known vector b + Gauss-Seidel iterations per step + Maximum number of times Gauss-Seidel iterations + Desired sqrt(Sum(error[i]^2))*number of equations + Estimated absolute error per component + + + Gauss Seidel method for iterative linear system solving. Returns unknown x + Matrix M so that Mx=b + Initial estimate + Known vector b + Estimated error per equation + + + Solves linear system Mx = b by LU decomposition. Returns x + Matrix M + Vector b + Maximum acceptable absolute error + Maximum iterations + + + Calculates LU decomposition of M matrix + Matrix to decompose + Matrix dimension + Swap index + + + Gauss Seidel method. Make sure to send x = b. Replaces x. + + + Matrix multiplication. Dimensions { p, r }. + + + + Float differential equation integrator + + + Writes final Y values and estimated absolute errors + + + Updates X to current time + + + Independent variable current value in OpenCL memory + + + Dynamic system current state in OpenCL memory + + + Derivative calculator + + + Constructor. + Initial state of system + Desired step per integration pass + Initial independent variable value + Function to calculate derivatives vector + + + Integrates equation set to a final value using current stepsize. Ideally, final value + and currentX should multiples of stepsize. + Final value to reach. + + + Sets current state + New independent variable value + New state values + + + Takes an integration step. Saves and returns stepsize back to what it was. + Step size to use + + + Takes an integration step + + + Sets step size. + Step size to use + + + Gets current values of space-state variables (from Device). + + + Gets current absolute error sum + + + Gets current independent variable value (from Device). + + + Function to calculate derivatives vector + IN: Scalar. Independent variable. + IN: State-space vector. + OUT: Derivatives + + + OpenCL source + + + double differential equation integrator + + + Writes final Y values and estimated absolute errors + + + Updates X to current time + + + Independent variable current value in OpenCL memory + + + Dynamic system current state in OpenCL memory + + + Derivative calculator + + + Constructor. + Initial state of system + Desired step per integration pass + Initial independent variable value + Function to calculate derivatives vector + + + Integrates equation set to a final value using current stepsize. Ideally, final value + and currentX should multiples of stepsize. + Final value to reach. + + + Sets current state + New independent variable value + New state values + + + Takes an integration step. Saves and returns stepsize back to what it was. + Step size to use + + + Takes an integration step + + + Sets step size. + Step size to use + + + Gets current values of space-state variables (from Device). + + + Gets current absolute error sum + + + Gets current independent variable value (from Device). + + + Function to calculate derivatives vector + IN: Scalar. Independent variable. + IN: State-space vector. + OUT: Derivatives + + + OpenCL source + + + Discrete element modeling. Calculates derivatives of n particle-spring model into a 6n space-state + system (positions, velocities, x,y,z each). + + + Mass values (n) + + + Original positions (3n) + + + Origins (L) origs[i] connects to dests[i] + + + Destinations (L) + + + Spring constants (L) + + + Spring constants to ground (n) + + + Damping (L) + + + Damping to ground (n) + + + Number of Connections (1) + + + Initial distances (L) + + + Actuating forces (3*n) + + + Connection forces (L) + + + Nodes connections (int, 20*n) + + + Initial lengths kernel. work_dim = 1, globalsize = n + + + Initial length arguments + + + Reset forces kernel. work_dim = 1, globalsize = 3n + + + Reset forces arguments + + + Calculate forces kernel. work_dim = 1, globalsize = L + + + Calculate forces arguments + + + Calculate forces kernel. work_dim = 1, globalsize = n + + + Calculate forces arguments + + + Calculate forces kernel. work_dim = 1, globalsize = L + + + Calculate forces arguments + + + Calculate nodes connections. work_dim = 1, globalsize = n + + + Calculate nodes connections arguments + + + Constructor. + Number of masses in the system + Number of connections + Mass of each vertex + Position and velocity of vertexes + [2*3*i] - posx, [2*(3*i+1)] - posy, [2*(3*i+2)] - posz, + [1+2*3*i] - velx, [1+2*(3*i+1)] - vely, [1+2*(3*i+2)] - velz + Origin vertex of connections. Spring connects Origin[i] to Dests[i] + Destination vertex of connections. Spring connects Origin[i] to Dests[i] + Spring constant for each connection + Spring constant for each mass, connecting to ground (nMass) + Structural damping (relative-speed dependant) (nConnections) + Absolute damping proportional to speed relative to Earth (nMass) + + + Calculates derivatives of deformable body space-state vector dydx[6n]. dydx[2i] - i-th position deriv, + dydx[2i+1] - ith velocity deriv + + + Reset forces. Work_dim = 1, nmax = { nMasses } + + + Derivatives sketch. Work_dim = 1, nmax = { 3 * nMasses } + Forces + Masses + Independent variable + State space vector + Derivatives + + + Initial L0 calculation. work_dim = 1, global_work_size[0]=nConnections + + + Forces calculation. Returns forces. Work_dim = 1, nmax = { nConnections } + + + Calculates forces to ground. w_dim=1, global_work_size = nMasses + + + Calculates forces to ground. w_dim=1, global_work_size = nMasses + + + Floating point particle system physics + + + Motion Newton-law 1D solver. Kernel: rk46 + + + Force applier to particles. Kernels: ResetForces, ApplyGravity, FloorCollision + + + Collision applier to particles. Kernels: ResetForces, ApplyGravity, FloorCollision + + + Initializes physics program. Components indexes: [i] - x, [i+1] - y, [i+2] - z + Number of particles + + + Sets particles parameters + Positions (3*numParticles) + Speeds (3*numParticles) + Masses (numParticles) + Collision sizes (numParticles) + + + Gets particles positions + + + Gets how many close neighbors a particle has. Use this to avoid drawing unnecessary particles + + + Gets simulation time + + + Stepsize + + + Executes an integration step + + + Motion step arguments + + + Takes an integration step + Step size + + + Applies gravity + + + Apply gravity arguments + + + Applies gravity force. + Gravity force. Remember to use negative for down direction. + + + Clear forces + + + Apply gravity arguments + + + Clears forces + + + Floor collision + + + Apply floor collision arguments + + + Applies floor collision? + + + Wall collision + + + Apply floor collision arguments + + + Applies floor collision? + + + Self collision + + + Apply self collision arguments + + + Applies self collision? + + + Reset close neighbors + + + Apply self collision arguments + + + Marching cubes algorithm for isosurface reconstruction + + + Compute normals of faces? + + + X, y and z increments. step[0] = deltaX, step[1] = deltaY, step[2] = deltaZ + + + X, y and z initial values. initVals[0] = x0, initVals[1] = y0, initVals[2] = z0 + + + Isolevel to look for + + + Values of the function + + + Length of each dimension - max[0] = maxX, max[1]=maxY, max[2]=maxZ + + + Edge coordinates. + + + Edge normals. + + + Edge coordinates. + + + Element index to build triangles + + + CL variable isolevel + + + OpenCL variable that stores function values. F(x,y,z) = CLFuncVals[x+maxX*y+maxX*maxY*z] + + + CL Edge coordinates. Geometry data compatible with OpenGL + + + CL Edge normals. Geometry data compatible with OpenGL + + + CL Element index array. Geometry data compatible with OpenGL + + + Auxiliary/preliminary normals + + + OpenCL x, y and z step sizes + + + OpenCL x, y and z initial values within grid + + + Kernel to interpolate points + + + Creates a new isosurface calculator. You may pass variables created from a OpenGL context to the CL variables if you are using interop or NULL + if not using OpenCL/GL interop. + Values of the evaluated 3D function f(x,y,z). FuncValues=float[maxX,maxY,maxZ] + + + Creates a new isosurface calculator. You may pass variables created from a OpenGL context to the CL variables if you are using interop or NULL + if not using OpenCL/GL interop. + Values of the evaluated 3D function f(x,y,z). FuncValues=float[maxX,maxY,maxZ] + OpenCL variable (float) to hold edge coordinates. Dimension has to be 9 * maxX * maxY * maxZ + OpenCL variable (float) to hold edge normals. Dimension has to be 9 * maxX * maxY * maxZ + OpenCL variable (int) to hold element array index. Dimension has to be 5 * 3 * (maxX - 1) * (maxY - 1) * (maxZ - 1) + + + Creates a new isosurface calculator. You may pass variables created from a OpenGL context to the CL variables if you are using interop or NULL + if not using OpenCL/GL interop. + Values of the evaluated 3D function f(x,y,z). FuncValues=float[maxX,maxY,maxZ] + OpenCL variable (float) to hold edge coordinates. Dimension has to be 9 * maxX * maxY * maxZ + OpenCL variable (float) to hold edge normals. Dimension has to be 9 * maxX * maxY * maxZ + OpenCL variable (int) to hold element array index. Dimension has to be 5 * 3 * (maxX - 1) * (maxY - 1) * (maxZ - 1) + + + Sets function values + Values to set + + + Calculates isosurface corresponding to a given isolevel + + + + Retrieves edge information. Can be used to draw marching cubes geometry using OpeGL + Edge vertexes coordinates + Edge vertexes normal vectors + Element index array (triangles) + + + Gets or sets x, y and z increments. Increments[0] = deltaX, Increments[1] = deltaY, Increments[2] = deltaZ + + + Gets or sets x, y and z intial values. InitValues[0] = x0, InitValues[1] = y0, InitValues[2] = z0 + + + Gets or sets current isolevel + + + Displays OpenCL related information + + + + Required designer variable. + + + + + Clean up any resources being used. + + true if managed resources should be disposed; otherwise, false. + + + + Required method for Designer support - do not modify + the contents of this method with the code editor. + + + + Constructor. + + + + An useful class to read/write/delete/count registry keys + + + + + To read a registry key. + input: KeyName (string) + output: value (string) + + + + + To write into a registry key. + input: KeyName (string) , Value (object) + output: true or false + + + + + To delete a registry key. + input: KeyName (string) + output: true or false + + + + + To delete a sub key and any child. + input: void + output: true or false + + + + + Retrive the count of subkeys at the current key. + input: void + output: number of subkeys + + + + + Retrive the count of values in the key. + input: void + output: number of keys + + + + + A property to show or hide error messages + (default = false) + + + + + A property to set the SubKey value + (default = "SOFTWARE\\" + Application.ProductName.ToUpper()) + + + + + A property to set the BaseRegistryKey value. + (default = Registry.LocalMachine) + + + + + A strongly-typed resource class, for looking up localized strings, etc. + + + + + Returns the cached ResourceManager instance used by this class. + + + + + Overrides the current thread's CurrentUICulture property for all + resource lookups using this strongly typed resource class. + + + + Creates a Matrix of real numbers. + + + Matrix items + + + Linear Solve parameter. Maximum mean error allowable to linear solve method. + + + Linear Solve parameter. Limit linear solution correction iterations. + + + Linear Solve parameter. Should the solution method halt if a hard singulariry is found in matrix? + + + Linear Solve parameter. Should the method ignore if the matrix has a close-to-zero determinant and keep solving? + + + Constructor. Initializes a [0,0] matrix. + + + Constructor. Creates matrix from existing items. + Matrix items to create matrix from. + + + Copy constructor. + Matrix to copy from. + + + Constructor. Creates empty matrix with specified dimensions. + Number of rows in matrix. + Number of columns in matrix. + + + Sums two matrixes. + First matrix to sum. + Second matrix to sum. + + + Subtracts two matrixes. + Matrix to subtract from. + Matrix to be subtracted. + + + Matrix multiplication. Notice that m1 rows should be the same as m2 lines for compatibility. + First matrix to multiply. + Second matrix to multiply. + + + Matrix scalar multiplication. + Matrix to multiply. + Scalar to multiply. + + + Matrix scalar multiplication. + Matrix to multiply. + Scalar to multiply. + + + Matrix post-vector multiplication. Notice that a vector is a [1,Cols] matrix which means + vector length should be equal matrix number of columns. + Matrix to multiply. + vector to multiply. + + + Matrix pre-vector multiplication. Notice that a vector is a [1,Cols] matrix which means + vector length should be equal matrix number of lines. + Matrix to multiply. + vector to multiply. + + + Matrix scalar division. + Matrix to multiply. + Scalar to divide each element of matrix. + + + Compares matrixes and returns true if they are identical. + Matrix to compare to. + + + Returns matrix transpose. + + + Element-wise product. This is not regular matrix product. It multiplies elements + at corresponding positions. + Matrix to multiply element-wise. + + + Returns Euclidean norm of the matrix. + + + Dot product of two matrixes. + Matrix to dot product with/ + + + Element-wise inversion. Returns the matrix with each element (x) inverted (1/x). + + + Creates internal LU factorization of this matrix. + + + Returns the solution x to the linear system Ax=b, A being this matrix. + Right-hand side known values. + + + Returns the determinant of this matrix. + + + Returns the inverse of this matrix. + + + Returns the solution x to the linear system A'Ax=A'b, A being this matrix. + Right-hand side known values. + + + Returns the weighted solution x to the linear system A'WAx=A'Wb, + A being this matrix. TO DO: Correct quality check + Right-hand side known values. + Weight matrix. + + + Returns the weighted solution x to the linear system A'DAx=A'Db, + A being this matrix. D is a diagonal weight matrix. + Right-hand side known values. + Main diagonal elements of diagonal weight matrix D. + + + Calculates R², corrected R² and Quadratic Error for the trySolution x to the linear system A'Ax=A'b, + A being this matrix. + Right-hand side known values. + Solution to use to evaluate quality indexers. + + + Applies the Gram-Schmidt orthonormalization method to this matrix, replacing + it by the orthonormalized matrix. + + + Applies the Gram-Schmidt orthonormalization method to this matrix, replacing + it by the orthonormalized matrix and also correcting right-hand Y values for a linear system solve. + Right-hand side known values. + + + Applies the Gram-Schmidt orthonormalization method to this matrix using + a pre-set order of normalization. Replaces current matrix + by the orthonormalized matrix and also correcting + right-hand Y values for a linear system solve. + Right-hand side known values. + Line order to apply the orthonormalization method. + Starts orthonormalization from line lineOrder[indStart]. Assumes previous lines are already + normalized. + + + Returns a string representing this matrix. + + + Accesses items in current matrix. + Row of element to access. + Column of element to access. + + + Gets the number of rows in this matrix. + + + Gets the number of columns in this matrix. + + + Returns the R² index of last fit. + + + Returns corrected R² index of last fit. + + + Returns the sum of quadratic errors of last fit. + + + Class to help editing OpenCL code + + + Constructor. Takes care of a Rich Text Box KeyUp event to paint things + RichTextBox to control + + + Help indentation? + + + Regular text color + + + Regular text font + + + Comments color + + + Comments font + + + List of string structures to mark + + + KeyUp event handler + + + Forces OpenCL RichTextBox to be updated + + + Stops updating text box while coloring text + Rich text box to lock + + + Restarts updating text box + Rich text box to unlock + + + Defines a structure of strings to mark + + + Description of string type + + + Color to use for this string type + + + Font to be used in this list of strings + + + List of strings of this type + + + OpenCL Helper Editor + + + + Required designer variable. + + + + + Clean up any resources being used. + + true if managed resources should be disposed; otherwise, false. + + + + Required method for Designer support - do not modify + the contents of this method with the code editor. + + + + Constructor. + + + Button to test code + + + + The main entry point for the application. + + + + diff --git a/WindowsFormsApplication1/bin/Debug/WindowsFormsApplication1.exe b/WindowsFormsApplication1/bin/Debug/WindowsFormsApplication1.exe new file mode 100644 index 0000000..af1defb Binary files /dev/null and b/WindowsFormsApplication1/bin/Debug/WindowsFormsApplication1.exe differ diff --git a/WindowsFormsApplication1/filter.cl b/WindowsFormsApplication1/filter.cl new file mode 100644 index 0000000..66351b0 --- /dev/null +++ b/WindowsFormsApplication1/filter.cl @@ -0,0 +1,64 @@ +uchar4 calcPixel(global uchar4*, int, int, global float*, int); + + +kernel void +filter(global uchar4* ac4PictureIn, global uchar4* ac4PictureOut, global int* nDim, global float* afMask, global int* nMaskSize) +{ + int nXpixel = get_global_id(0); + int nYpixel = get_global_id(1); + + int nPos = (nYpixel * nDim[0]) + nXpixel; + + *(ac4PictureOut+nPos) = calcPixel(ac4PictureIn, nDim[0], nDim[1], afMask, *nMaskSize); +} + + +uchar4 calcPixel(global uchar4* ac4PictureIn, int nWidth, int nHeight, global float* afMask, int nMaskSize) { + int nXpixel = get_global_id(0); + int nYpixel = get_global_id(1); + int nDx, nDy; + int nX, nY; + + int nDelta = (nMaskSize/2); + int nMaskLength = nMaskSize * nMaskSize; + + float4 f4Pixel = {0.0f, 0.0f, 0.0f, 0.0f}; + + float fMaskSum = 0; + for(int nK = 0; nK < nMaskLength; nK++) { + fMaskSum += afMask[nK]; + } + //float fFactor; + + for(int nK = 0; nK < nMaskLength; nK++) { + nDx = (nK%nMaskSize) - nDelta; + nDy = (nK/nMaskSize) - nDelta; + nX = nXpixel+nDx; + nY = nYpixel+nDy; + if(nX < 0) nX = 0; + if(nX >= nWidth) nX = nWidth-1; + if(nY < 0) nY = 0; + if(nY >= nHeight) nY = nHeight-1; + +// if(nX > -1 && nX < nWidth && nY > -1 && nY < nHeight) { //if mask is not outside the image + f4Pixel += (afMask[nK]/fMaskSum) * convert_float4(ac4PictureIn[(nY * nWidth) + nX]); +// } + } + + return convert_uchar4(f4Pixel); +} + + +kernel void +recycle(global uchar4* ac4PictureIn, global uchar4* ac4PictureOut, global int* nDim) +{ + int nXpixel = get_global_id(0); + int nYpixel = get_global_id(1); + + int nPos = (nYpixel * nDim[0]) + nXpixel; + +// uchar4 c4Temp = ac4PictureIn[nPos]; + + ac4PictureIn[nPos] = ac4PictureOut[nPos]; +// ac4PictureOut[nPos] = c4Temp; +} \ No newline at end of file diff --git a/WindowsFormsApplication1/filter_gauss3x3.txt b/WindowsFormsApplication1/filter_gauss3x3.txt new file mode 100644 index 0000000..842098d --- /dev/null +++ b/WindowsFormsApplication1/filter_gauss3x3.txt @@ -0,0 +1,4 @@ +3 +1, 2, 1 +2, 4, 2 +1, 2, 1 \ No newline at end of file diff --git a/WindowsFormsApplication1/filter_gauss5x5.txt b/WindowsFormsApplication1/filter_gauss5x5.txt new file mode 100644 index 0000000..7780211 --- /dev/null +++ b/WindowsFormsApplication1/filter_gauss5x5.txt @@ -0,0 +1,6 @@ +5 +1, 2, 4, 2, 1, +2, 4, 8, 4, 2, +4, 8, 16,8, 4, +2, 4, 8, 4, 2, +1, 2, 4, 2, 1, \ No newline at end of file diff --git a/WindowsFormsApplication1/filter_neutral.txt b/WindowsFormsApplication1/filter_neutral.txt new file mode 100644 index 0000000..27f5fe8 --- /dev/null +++ b/WindowsFormsApplication1/filter_neutral.txt @@ -0,0 +1,13 @@ +3 +0,0,0 +0,1,0 +0,0,0 + + + +5 +0,0,0,0,0 +0,0,0,0,0 +0,0,1,0,0 +0,0,0,0,0 +0,0,0,0,0 diff --git a/WindowsFormsApplication1/filter_test.txt b/WindowsFormsApplication1/filter_test.txt new file mode 100644 index 0000000..564f2f8 --- /dev/null +++ b/WindowsFormsApplication1/filter_test.txt @@ -0,0 +1,6 @@ +5 +1, 1, 1, 1, 1, +1, 0, 0, 0, 1, +1, 0, 0, 0, 1, +1, 0, 0, 0, 1, +1, 1, 1, 1, 1, \ No newline at end of file