Created
May 12, 2014 13:20
-
-
Save daramkun/16e9afa54c50b3c789ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.IO; | |
| using System.Text; | |
| namespace OpenCLTest | |
| { | |
| class Program | |
| { | |
| static void Main ( string [] args ) | |
| { | |
| Cloo.ComputeContext cc = new Cloo.ComputeContext ( Cloo.ComputeDeviceTypes.All, new Cloo.ComputeContextPropertyList ( Cloo.ComputePlatform.Platforms [ 0 ] ), | |
| ( string errorInfo, IntPtr clDataPtr, IntPtr clDataSize, IntPtr userDataPtr ) => { Console.WriteLine ( "Error: ", errorInfo ); }, IntPtr.Zero ); | |
| foreach ( var v in cc.Devices ) | |
| { | |
| Console.WriteLine ( "===== {0} ({1}) =====", v.Vendor, v.Name.Trim () ); | |
| Console.WriteLine ( "Is Available: {0} (Compiler: {1})", v.Available, v.CompilerAvailable ); | |
| Console.WriteLine ( "Driver version: {0}", v.DriverVersion ); | |
| Console.WriteLine ( "OpenCL version: {0} (OpenCL C: {1})", v.VersionString, v.OpenCLCVersionString ); | |
| Console.WriteLine ( "Platform: {0}({1})", v.Platform.Name, v.Platform.Profile ); | |
| Console.WriteLine ( "Type: {0}", v.Type ); | |
| Console.WriteLine ( "Properties:" ); | |
| foreach ( var vv in cc.Properties ) | |
| Console.WriteLine ( "\t{0} : {1}", vv.Name, vv.Value ); | |
| } | |
| Console.WriteLine ( "<<<<<<<<<<<<<<<<<<<<<<< Build Source >>>>>>>>>>>>>>>>>>>>>>>>" ); | |
| Cloo.ComputeProgram cp = new Cloo.ComputeProgram ( cc, string.Format ( @"__constant char hw[] = {0}Hello OpenCL!\n{0}; | |
| __kernel void hello(__global char * out) | |
| {{ | |
| size_t tid = get_global_id(0); | |
| for(; tid < 14; tid++) | |
| out[tid] = hw[tid]; | |
| }}", '"' ) ); | |
| cp.Build ( cc.Devices, null, ( Cloo.Bindings.CLProgramHandle programHandle, IntPtr notifyDataPtr ) => | |
| { | |
| Console.WriteLine ( "Is Program Handle Vaild? {0}", programHandle.IsValid ); | |
| }, IntPtr.Zero ); | |
| Console.WriteLine ( "Build Status: {0}", cp.GetBuildStatus ( cc.Devices [ 0 ] ) ); | |
| Console.WriteLine ( "Build Log: {0}", cp.GetBuildLog ( cc.Devices [ 0 ] ) ); | |
| Console.WriteLine ( "<<<<<<<<<<<<<<<<<<<<<<< Run Hello >>>>>>>>>>>>>>>>>>>>>>>>" ); | |
| Cloo.ComputeKernel ck = cp.CreateKernel ( "hello" ); | |
| byte [] data = new byte [ 128 ]; | |
| Cloo.ComputeBuffer<byte> cb = new Cloo.ComputeBuffer<byte> ( cc, Cloo.ComputeMemoryFlags.ReadWrite | Cloo.ComputeMemoryFlags.UseHostPointer, data ); | |
| ck.SetMemoryArgument ( 0, cb ); | |
| Cloo.ComputeCommandQueue ccq = new Cloo.ComputeCommandQueue ( cc, cc.Devices [ 0 ], Cloo.ComputeCommandQueueFlags.OutOfOrderExecution ); | |
| ccq.ExecuteTask ( ck, null ); | |
| ccq.Finish (); | |
| Console.WriteLine ( Encoding.UTF8.GetString ( data ).Trim ( '\0' ) ); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment