Added support for OpenCL samples.
Added VectorAdd sample. Bumped version number.
This commit is contained in:
parent
1df3101a47
commit
16f209497b
7 changed files with 5494 additions and 5237 deletions
|
@ -50,9 +50,10 @@ namespace Examples
|
|||
|
||||
public enum ExampleCategory
|
||||
{
|
||||
Default = 0,
|
||||
OpenTK = Default,
|
||||
OpenTK = 0,
|
||||
OpenGL,
|
||||
OpenAL,
|
||||
OpenCL,
|
||||
OpenGLES
|
||||
}
|
||||
}
|
||||
|
|
4
Source/Examples/ExampleBrowser.Designer.cs
generated
4
Source/Examples/ExampleBrowser.Designer.cs
generated
|
@ -161,6 +161,7 @@
|
|||
this.imageListSampleCategories.Images.SetKeyName(16, "Test.jpg");
|
||||
this.imageListSampleCategories.Images.SetKeyName(17, "Fonts.jpg");
|
||||
this.imageListSampleCategories.Images.SetKeyName(18, "OpenTK.jpg");
|
||||
this.imageListSampleCategories.Images.SetKeyName(19, "OpenCL.png");
|
||||
//
|
||||
// tabControlSample
|
||||
//
|
||||
|
@ -187,7 +188,6 @@
|
|||
//
|
||||
// richTextBoxDescription
|
||||
//
|
||||
this.richTextBoxDescription.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
||||
this.richTextBoxDescription.ContextMenuStrip = this.contextMenuStripDescription;
|
||||
this.richTextBoxDescription.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.richTextBoxDescription.Location = new System.Drawing.Point(3, 3);
|
||||
|
@ -226,7 +226,6 @@
|
|||
// richTextBoxSource
|
||||
//
|
||||
this.richTextBoxSource.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(216)))), ((int)(((byte)(242)))), ((int)(((byte)(240)))));
|
||||
this.richTextBoxSource.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
||||
this.richTextBoxSource.ContextMenuStrip = this.contextMenuStripSource;
|
||||
this.richTextBoxSource.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.richTextBoxSource.Location = new System.Drawing.Point(3, 3);
|
||||
|
@ -265,7 +264,6 @@
|
|||
// textBoxOutput
|
||||
//
|
||||
this.textBoxOutput.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(216)))), ((int)(((byte)(242)))), ((int)(((byte)(240)))));
|
||||
this.textBoxOutput.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
||||
this.textBoxOutput.ContextMenuStrip = this.contextMenuStripOutput;
|
||||
this.textBoxOutput.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.textBoxOutput.Location = new System.Drawing.Point(3, 3);
|
||||
|
|
|
@ -305,6 +305,10 @@ namespace Examples
|
|||
return list.Images.IndexOfKey(subcategory.ToString() + ".jpg");
|
||||
if (list.Images.ContainsKey(category.ToString() + ".jpg"))
|
||||
return list.Images.IndexOfKey(category.ToString() + ".jpg");
|
||||
if (list.Images.ContainsKey(subcategory.ToString() + ".png"))
|
||||
return list.Images.IndexOfKey(subcategory.ToString() + ".png");
|
||||
if (list.Images.ContainsKey(category.ToString() + ".png"))
|
||||
return list.Images.IndexOfKey(category.ToString() + ".png");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
115
Source/Examples/OpenCL/VectorAdd.cs
Normal file
115
Source/Examples/OpenCL/VectorAdd.cs
Normal file
|
@ -0,0 +1,115 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using OpenTK.Compute.CL10;
|
||||
|
||||
namespace Examples
|
||||
{
|
||||
using cl_context = IntPtr;
|
||||
using cl_device_id = IntPtr;
|
||||
using cl_command_queue = IntPtr;
|
||||
using cl_program = IntPtr;
|
||||
using cl_kernel = IntPtr;
|
||||
using cl_mem = IntPtr;
|
||||
|
||||
[Example("Vector Addition", ExampleCategory.OpenCL, "1.0")]
|
||||
class FFT
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
const int cnBlockSize = 512;
|
||||
const int cnBlocks = 3;
|
||||
IntPtr cnDimension = new IntPtr(cnBlocks * cnBlockSize);
|
||||
string sProgramSource = @"
|
||||
__kernel void
|
||||
vectorAdd(__global const float * a,
|
||||
__global const float * b,
|
||||
__global float * c)
|
||||
{
|
||||
// Vector element index
|
||||
int nIndex = get_global_id(0);
|
||||
c[nIndex] = a[nIndex] + b[nIndex];
|
||||
}
|
||||
";
|
||||
|
||||
ErrorCode error;
|
||||
|
||||
// create OpenCL device & context
|
||||
cl_context hContext;
|
||||
unsafe { hContext = CL.CreateContextFromType((ContextProperties*)null, DeviceTypeFlags.DeviceTypeDefault, IntPtr.Zero, IntPtr.Zero, &error); }
|
||||
|
||||
// query all devices available to the context
|
||||
IntPtr nContextDescriptorSize;
|
||||
CL.GetContextInfo(hContext, ContextInfo.ContextDevices, IntPtr.Zero, IntPtr.Zero, out nContextDescriptorSize);
|
||||
cl_device_id[] aDevices = new cl_device_id[nContextDescriptorSize.ToInt32()];
|
||||
unsafe
|
||||
{
|
||||
fixed (cl_device_id* ptr = aDevices)
|
||||
{
|
||||
IntPtr ret;
|
||||
CL.GetContextInfo(hContext, ContextInfo.ContextDevices, nContextDescriptorSize, new IntPtr(ptr), out ret);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// create a command queue for first device the context reported
|
||||
cl_command_queue hCmdQueue = CL.CreateCommandQueue(hContext, aDevices[0], (CommandQueueFlags)0, out error);
|
||||
// create & compile program
|
||||
cl_program hProgram;
|
||||
unsafe { hProgram = CL.CreateProgramWithSource(hContext, 1, new string[] { sProgramSource }, null, &error); }
|
||||
CL.BuildProgram(hProgram, 0, (IntPtr[])null, null, IntPtr.Zero, IntPtr.Zero);
|
||||
|
||||
// create kernel
|
||||
cl_kernel hKernel = CL.CreateKernel(hProgram, "vectorAdd", out error);
|
||||
// allocate host vectors
|
||||
float[] A = new float[cnDimension.ToInt32()];
|
||||
float[] B = new float[cnDimension.ToInt32()];
|
||||
float[] C = new float[cnDimension.ToInt32()];
|
||||
// initialize host memory
|
||||
// randomInit(pA, cnDimension);
|
||||
//randomInit(pB, cnDimension);
|
||||
|
||||
// allocate device memory
|
||||
unsafe
|
||||
{
|
||||
fixed (float* pA = A)
|
||||
fixed (float* pB = B)
|
||||
fixed (float* pC = C)
|
||||
{
|
||||
cl_mem hDeviceMemA, hDeviceMemB, hDeviceMemC;
|
||||
hDeviceMemA = CL.CreateBuffer(hContext,
|
||||
MemFlags.MemReadOnly | MemFlags.MemCopyHostPtr,
|
||||
new IntPtr(cnDimension.ToInt32() * sizeof(float)),
|
||||
new IntPtr(pA),
|
||||
out error);
|
||||
hDeviceMemB = CL.CreateBuffer(hContext,
|
||||
MemFlags.MemReadOnly | MemFlags.MemCopyHostPtr,
|
||||
new IntPtr(cnDimension.ToInt32() * sizeof(float)),
|
||||
new IntPtr(pA),
|
||||
out error);
|
||||
hDeviceMemC = CL.CreateBuffer(hContext,
|
||||
MemFlags.MemWriteOnly,
|
||||
new IntPtr(cnDimension.ToInt32() * sizeof(float)),
|
||||
IntPtr.Zero,
|
||||
out error);
|
||||
|
||||
// setup parameter values
|
||||
CL.SetKernelArg(hKernel, 0, new IntPtr(sizeof(cl_mem)), new IntPtr(&hDeviceMemA));
|
||||
CL.SetKernelArg(hKernel, 1, new IntPtr(sizeof(cl_mem)), new IntPtr(&hDeviceMemB));
|
||||
CL.SetKernelArg(hKernel, 2, new IntPtr(sizeof(cl_mem)), new IntPtr(&hDeviceMemC));
|
||||
|
||||
// execute kernel
|
||||
CL.EnqueueNDRangeKernel(hCmdQueue, hKernel, 1, null, &cnDimension, null, 0, null, null);
|
||||
// copy results from device back to host
|
||||
CL.EnqueueReadBuffer(hContext, hDeviceMemC, true, IntPtr.Zero,
|
||||
new IntPtr(cnDimension.ToInt32() * sizeof(float)),
|
||||
new IntPtr(pC), 0, null, (IntPtr[])null);
|
||||
|
||||
CL.ReleaseMemObject(hDeviceMemA);
|
||||
CL.ReleaseMemObject(hDeviceMemB);
|
||||
CL.ReleaseMemObject(hDeviceMemC);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
|||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("0.9.9.1")]
|
||||
[assembly: AssemblyFileVersion("0.9.9.1")]
|
||||
[assembly: AssemblyVersion("0.9.9.2")]
|
||||
[assembly: AssemblyFileVersion("0.9.9.2")]
|
||||
|
|
45
Source/Examples/Properties/Resources.Designer.cs
generated
45
Source/Examples/Properties/Resources.Designer.cs
generated
|
@ -80,31 +80,17 @@ namespace Examples.Properties {
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to #region --- License ---
|
||||
////* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
/// * See license.txt for license info
|
||||
/// */
|
||||
///#endregion
|
||||
///
|
||||
///#region --- Using Directives ---
|
||||
///
|
||||
///using System;
|
||||
///using System.Collections.Generic;
|
||||
///using System.ComponentModel;
|
||||
///using System.Data;
|
||||
///using System.Drawing;
|
||||
///using System.Text;
|
||||
///using System.Windows.Forms;
|
||||
///using System.Threading;
|
||||
///
|
||||
///using OpenTK;
|
||||
///using OpenTK.Graphics;
|
||||
///
|
||||
///#endregion --- Using Directives ---
|
||||
///
|
||||
///namespace Examples.Tutorial
|
||||
///{
|
||||
/// [Example("Display Lists", E [rest of string was truncated]";.
|
||||
/// Looks up a localized string similar to #region License
|
||||
/////
|
||||
///// The Open Toolkit Library License
|
||||
/////
|
||||
///// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
||||
/////
|
||||
///// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
///// of this software and associated documentation files (the "Software"), to deal
|
||||
///// in the Software without restriction, including without limitation the rights to
|
||||
///// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
///// the Software, and to permit persons to whom the Softwa [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string DisplayLists {
|
||||
get {
|
||||
|
@ -249,13 +235,12 @@ namespace Examples.Properties {
|
|||
///
|
||||
///using OpenTK;
|
||||
///using OpenTK.Input;
|
||||
//
|
||||
///using OpenTK.Graphics;
|
||||
///using OpenTK.Graphics.OpenGL;
|
||||
///
|
||||
///namespace Examples.Tutorial
|
||||
///{
|
||||
/// [Example("Framebuffer Objects", ExampleCategory.OpenGL, "FB [rest of string was truncated]";.
|
||||
/// [Example("Framebuffer Objects", ExampleCategory.OpenGL, "FBO", Documentation="F [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string FramebufferObject {
|
||||
get {
|
||||
|
@ -792,12 +777,11 @@ namespace Examples.Properties {
|
|||
///using OpenTK.Graphics;
|
||||
///using OpenTK.Platform;
|
||||
///
|
||||
///
|
||||
///#endregion
|
||||
///
|
||||
///namespace Examples.Tutorial
|
||||
///{
|
||||
/// [Example("Vertex Buffer Objects", ExampleCategory.OpenGL, "1.5", false, [rest of string was truncated]";.
|
||||
/// [Example("Vertex Buffer Objects", ExampleCategory.OpenGL, "1.5", false, Documentation="Vert [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string VertexBufferObject {
|
||||
get {
|
||||
|
@ -821,13 +805,12 @@ namespace Examples.Properties {
|
|||
///using OpenTK.Graphics;
|
||||
///using Examples.Shapes;
|
||||
///
|
||||
///
|
||||
///namespace Examples.Tutorial
|
||||
///{
|
||||
/// /// <summary>
|
||||
/// /// Demonstrates fixed-function OpenGL lighting. Example is incomplete (documentation).
|
||||
/// /// </summary>
|
||||
/// [Example("Vertex Lighting", E [rest of string was truncated]";.
|
||||
/// [Example("Vertex Lighting", ExampleCategory.OpenG [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string VertexLighting {
|
||||
get {
|
||||
|
|
Loading…
Reference in a new issue