//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Creates a new <see cref="ComputeContextPropertyList"/> which contains a single item /// specifying a <see cref="ComputePlatform"/>. /// </summary> /// /// <param name="platform"> A <see cref="ComputePlatform"/>. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public ComputeContextPropertyList(ComputePlatform platform) { properties = new List <ComputeContextProperty> { new ComputeContextProperty(ComputeContextPropertyName.Platform, platform.Handle.Value) }; }
public InfoPerDevice(Cloo.ComputePlatform inPlatform, Cloo.ComputeDevice inDevice, BlockedMatMulThread inThreadObject) { platform = inPlatform; device = inDevice; threadObject = inThreadObject; thread = null; }
public ComputeContext(ICollection <ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr) { int handleCount; CLDeviceHandle[] deviceHandles = ComputeTools.ExtractHandles(devices, out handleCount); IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null; callback = notify; ComputeErrorCode error = ComputeErrorCode.Success; Handle = CL10.CreateContext(propertyArray, handleCount, deviceHandles, notify, notifyDataPtr, out error); ComputeException.ThrowOnError(error); SetID(Handle.Value); this.properties = properties; ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform); this.platform = ComputePlatform.GetByHandle(platformProperty.Value); this.devices = GetDevices(); #if DEBUG Trace.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information"); #endif }
/* long i = get_global_id(0); long j = get_global_id(1); long p = get_global_size(0); long r = get_global_size(1); output_Z[i+p*j] = isPrimeNumber(input_Z[i+p*j]); i+2*j+2*2*k j i k value 0 0 0 0 * 0 1 0 1 * 1 0 0 2 * 1 1 0 3 * 0 0 1 4 * 0 1 1 5 * 1 0 1 6 * 1 1 1 7 */ private static void BasicInfo(ComputePlatform platform) { Console.WriteLine(""); Console.WriteLine("Platform Information:"); Console.WriteLine("-----------------------------------------"); Console.WriteLine("Name: " + platform.Name); Console.WriteLine("Profile: " + platform.Profile); Console.WriteLine("Vendor: " + platform.Vendor); Console.WriteLine("Version: " + platform.Version); Console.WriteLine("Extensions:"); foreach (string extension in platform.Extensions) Console.WriteLine(" + " + extension); Console.WriteLine("Devices:"); if (platform.Devices.Count == 0) { Console.WriteLine("No OpenCL devices are availble!"); } else { for (int i = 0; i < platform.Devices.Count; i++) Console.WriteLine(" + " + platform.Devices[i].Name.Trim()); } Console.WriteLine(""); }
internal ComputeDevice(ComputePlatform platform, CLDeviceHandle handle) { Handle = handle; SetID(Handle.Value); addressBits = GetInfo <uint>(ComputeDeviceInfo.AddressBits); available = GetBoolInfo(ComputeDeviceInfo.Available); compilerAvailable = GetBoolInfo(ComputeDeviceInfo.CompilerAvailable); driverVersion = GetStringInfo(ComputeDeviceInfo.DriverVersion); endianLittle = GetBoolInfo(ComputeDeviceInfo.EndianLittle); errorCorrectionSupport = GetBoolInfo(ComputeDeviceInfo.ErrorCorrectionSupport); executionCapabilities = (ComputeDeviceExecutionCapabilities)GetInfo <long>(ComputeDeviceInfo.ExecutionCapabilities); string extensionString = GetStringInfo(ComputeDeviceInfo.Extensions); extensions = new ReadOnlyCollection <string>(extensionString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); globalMemoryCachelineSize = GetInfo <uint>(ComputeDeviceInfo.GlobalMemoryCachelineSize); globalMemoryCacheSize = (long)GetInfo <ulong>(ComputeDeviceInfo.GlobalMemoryCacheSize); globalMemoryCacheType = (ComputeDeviceMemoryCacheType)GetInfo <long>(ComputeDeviceInfo.GlobalMemoryCacheType); globalMemorySize = (long)GetInfo <ulong>(ComputeDeviceInfo.GlobalMemorySize); image2DMaxHeight = (long)GetInfo <IntPtr>(ComputeDeviceInfo.Image2DMaxHeight); image2DMaxWidth = (long)GetInfo <IntPtr>(ComputeDeviceInfo.Image2DMaxWidth); image3DMaxDepth = (long)GetInfo <IntPtr>(ComputeDeviceInfo.Image3DMaxDepth); image3DMaxHeight = (long)GetInfo <IntPtr>(ComputeDeviceInfo.Image3DMaxHeight); image3DMaxWidth = (long)GetInfo <IntPtr>(ComputeDeviceInfo.Image3DMaxWidth); imageSupport = GetBoolInfo(ComputeDeviceInfo.ImageSupport); localMemorySize = (long)GetInfo <ulong>(ComputeDeviceInfo.LocalMemorySize); localMemoryType = (ComputeDeviceLocalMemoryType)GetInfo <long>(ComputeDeviceInfo.LocalMemoryType); maxClockFrequency = GetInfo <uint>(ComputeDeviceInfo.MaxClockFrequency); maxComputeUnits = GetInfo <uint>(ComputeDeviceInfo.MaxComputeUnits); maxConstantArguments = GetInfo <uint>(ComputeDeviceInfo.MaxConstantArguments); maxConstantBufferSize = (long)GetInfo <ulong>(ComputeDeviceInfo.MaxConstantBufferSize); maxMemAllocSize = (long)GetInfo <ulong>(ComputeDeviceInfo.MaxMemoryAllocationSize); maxParameterSize = (long)GetInfo <IntPtr>(ComputeDeviceInfo.MaxParameterSize); maxReadImageArgs = GetInfo <uint>(ComputeDeviceInfo.MaxReadImageArguments); maxSamplers = GetInfo <uint>(ComputeDeviceInfo.MaxSamplers); maxWorkGroupSize = (long)GetInfo <IntPtr>(ComputeDeviceInfo.MaxWorkGroupSize); maxWorkItemDimensions = GetInfo <uint>(ComputeDeviceInfo.MaxWorkItemDimensions); maxWorkItemSizes = new ReadOnlyCollection <long>(ComputeTools.ConvertArray(GetArrayInfo <CLDeviceHandle, ComputeDeviceInfo, IntPtr>(Handle, ComputeDeviceInfo.MaxWorkItemSizes, CL10.GetDeviceInfo))); maxWriteImageArgs = GetInfo <uint>(ComputeDeviceInfo.MaxWriteImageArguments); memBaseAddrAlign = GetInfo <uint>(ComputeDeviceInfo.MemoryBaseAddressAlignment); minDataTypeAlignSize = GetInfo <uint>(ComputeDeviceInfo.MinDataTypeAlignmentSize); name = GetStringInfo(ComputeDeviceInfo.Name); this.platform = platform; preferredVectorWidthChar = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthChar); preferredVectorWidthFloat = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthFloat); preferredVectorWidthInt = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthInt); preferredVectorWidthLong = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthLong); preferredVectorWidthShort = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthShort); profile = GetStringInfo(ComputeDeviceInfo.Profile); profilingTimerResolution = (long)GetInfo <IntPtr>(ComputeDeviceInfo.ProfilingTimerResolution); queueProperties = (ComputeCommandQueueFlags)GetInfo <long>(ComputeDeviceInfo.CommandQueueProperties); singleCapabilities = (ComputeDeviceSingleCapabilities)GetInfo <long>(ComputeDeviceInfo.SingleFPConfig); type = (ComputeDeviceTypes)GetInfo <long>(ComputeDeviceInfo.Type); vendor = GetStringInfo(ComputeDeviceInfo.Vendor); vendorId = GetInfo <uint>(ComputeDeviceInfo.VendorId); version = GetStringInfo(ComputeDeviceInfo.Version); }
public virtual void Initialize() { platform = ComputePlatform.Platforms[0]; device = platform.Devices[0]; properties = new ComputeContextPropertyList(platform); context = new ComputeContext(new[] { device }, properties, null, IntPtr.Zero); program = new ComputeProgram(context, KernelSrc); }
public static IGpuHelper CreateHelper(ComputePlatform platform, ComputeDevice device, FPType fptype) { ComputeContextPropertyList properties = new ComputeContextPropertyList(platform); var context = new ComputeContext(new[] { device }, properties, null, IntPtr.Zero); if (fptype == FPType.Single) { return new GpuHelper<float>(context, fptype); } else { return new GpuHelper<double>(context, fptype); } }
/// <summary> /// Construct an OpenCL platform. /// </summary> /// /// <param name="platform">The OpenCL platform.</param> public EncogCLPlatform(ComputePlatform platform) { this.platform = platform; this.devices = new List<EncogCLDevice>(); ComputeContextPropertyList cpl = new ComputeContextPropertyList(platform); this.context = new ComputeContext(ComputeDeviceTypes.Default, cpl, null, IntPtr.Zero); this.Name = platform.Name; this.Vender = platform.Vendor; this.Enabled = true; foreach (ComputeDevice device in context.Devices) { EncogCLDevice adapter = new EncogCLDevice(this, device); this.devices.Add(adapter); } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Creates a new <see cref="ComputeContext"/> on all the <see cref="ComputeDevice"/>s that match /// the specified <see cref="ComputeDeviceTypes"/>. /// </summary> /// /// <param name="deviceType"> A bit-field that identifies the type of /// <see cref="ComputeDevice"/> to associate with the /// <see cref="ComputeContext"/>. </param> /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the /// <see cref="ComputeContext"/>. </param> /// <param name="notify"> A delegate instance that refers to a notification routine. This /// routine is a callback function that will be used by the OpenCL /// implementation to report information on errors that occur in the /// <see cref="ComputeContext"/>. The callback function may be called /// asynchronously by the OpenCL implementation. It is the /// application's responsibility to ensure that the callback function /// is thread-safe and that the delegate instance doesn't get /// collected by the Garbage Collector until /// <see cref="ComputeContext"/> is disposed. If /// <paramref name="notify"/> is <c>null</c>, no callback function is /// registered. </param> /// <param name="userDataPtr"> Optional user data that will be passed to /// <paramref name="notify"/>. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr) { IntPtr[] propertyArray = properties?.ToIntPtrArray(); callback = notify; Handle = CL12.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, out var error); ComputeException.ThrowOnError(error); SetID(Handle.Value); this.properties = properties; ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform); platform = ComputePlatform.GetByHandle(platformProperty.Value); devices = GetDevices(); RILogManager.Default?.SendTrace("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information"); }
/// <summary> /// Creates a new <see cref="ComputeContext"/> on all the <see cref="ComputeDevice"/>s that match the specified <see cref="ComputeDeviceTypes"/>. /// </summary> /// <param name="deviceType"> A bit-field that identifies the type of <see cref="ComputeDevice"/> to associate with the <see cref="ComputeContext"/>. </param> /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the <see cref="ComputeContext"/>. </param> /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <see cref="ComputeContext"/>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <see cref="ComputeContext"/> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param> /// <param name="userDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param> public ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr) { IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null; callback = notify; ComputeErrorCode error = ComputeErrorCode.Success; Handle = CLInterface.CL12.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, out error); ComputeException.ThrowOnError(error); SetID(Handle.Value); this.properties = properties; ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform); this.platform = ComputePlatform.GetByHandle(platformProperty.Value); this.devices = GetDevices(); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Creates a new <see cref="ComputeContext"/> on a collection of <see cref="ComputeDevice"/>s. /// </summary> /// /// <param name="devices"> A collection of <see cref="ComputeDevice"/>s to associate /// with the <see cref="ComputeContext"/>. </param> /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the /// <see cref="ComputeContext"/>. </param> /// <param name="notify"> A delegate instance that refers to a notification routine. /// This routine is a callback function that will be used by the /// OpenCL implementation to report information on errors that occur /// in the <see cref="ComputeContext"/>. The callback function may be /// called asynchronously by the OpenCL implementation. It is the /// application's responsibility to ensure that the callback function /// is thread-safe and that the delegate instance doesn't get /// collected by the Garbage Collector until /// <see cref="ComputeContext"/> is disposed. If /// <paramref name="notify"/> is <c>null</c>, no callback function is /// registered. </param> /// <param name="notifyDataPtr"> Optional user data that will be passed to /// <paramref name="notify"/>. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public ComputeContext(ICollection <ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr) { CLDeviceHandle[] deviceHandles = ComputeTools.ExtractHandles(devices, out var handleCount); IntPtr[] propertyArray = properties?.ToIntPtrArray(); callback = notify; Handle = CL12.CreateContext(propertyArray, handleCount, deviceHandles, notify, notifyDataPtr, out var error); ComputeException.ThrowOnError(error); SetID(Handle.Value); this.properties = properties; ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform); platform = ComputePlatform.GetByHandle(platformProperty.Value); this.devices = GetDevices(); RILogManager.Default?.SendTrace("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information"); }
/// <summary> /// Creates a new <see cref="ComputeContext"/> on all the <see cref="ComputeDevice"/>s that match the specified <see cref="ComputeDeviceTypes"/>. /// </summary> /// <param name="deviceType"> A bit-field that identifies the type of <see cref="ComputeDevice"/> to associate with the <see cref="ComputeContext"/>. </param> /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the <see cref="ComputeContext"/>. </param> /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <see cref="ComputeContext"/>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <see cref="ComputeContext"/> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param> /// <param name="userDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param> public ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr) { IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null; callback = notify; ComputeErrorCode error = ComputeErrorCode.Success; Handle = CL12.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, out error); ComputeException.ThrowOnError(error); SetID(Handle.Value); this.properties = properties; ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform); this.platform = ComputePlatform.GetByHandle(platformProperty.Value); this.devices = GetDevices(); Trace.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information"); }
public ConfigForm() { InitializeComponent(); deviceCheckList.CheckOnClick = true; deviceCheckList.SelectedIndexChanged += new EventHandler(deviceCheckList_SelectedIndexChanged); Platform = ComputePlatform.Platforms[0]; platformComboBox.SelectedIndexChanged += new EventHandler(platformComboBox_SelectedIndexChanged); object[] availablePlatforms = new object[ComputePlatform.Platforms.Count]; for (int i = 0; i < availablePlatforms.Length; i++) availablePlatforms[i] = ComputePlatform.Platforms[i].Name; platformComboBox.Items.AddRange(availablePlatforms); platformComboBox.SelectedIndex = 0; StoreState(); Shown += new EventHandler(SettingsForm_Shown); }
/// <summary> /// Creates a new <see cref="ComputeContext"/> on a collection of <see cref="ComputeDevice"/>s. /// </summary> /// <param name="devices"> A collection of <see cref="ComputeDevice"/>s to associate with the <see cref="ComputeContext"/>. </param> /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the <see cref="ComputeContext"/>. </param> /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <see cref="ComputeContext"/>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <see cref="ComputeContext"/> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param> /// <param name="notifyDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param> public ComputeContext(ICollection <ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr) { int handleCount; CLDeviceHandle[] deviceHandles = ComputeTools.ExtractHandles(devices, out handleCount); IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null; callback = notify; ComputeErrorCode error = ComputeErrorCode.Success; Handle = CLInterface.CL12.CreateContext(propertyArray, handleCount, deviceHandles, notify, notifyDataPtr, out error); ComputeException.ThrowOnError(error); SetID(Handle.Value); this.properties = properties; ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform); this.platform = ComputePlatform.GetByHandle(platformProperty.Value); this.devices = GetDevices(); }
/// <summary> /// Creates a new <see cref="ComputeContext"/> on a collection of <see cref="ComputeDevice"/>s. /// </summary> /// <param name="devices"> A collection of <see cref="ComputeDevice"/>s to associate with the <see cref="ComputeContext"/>. </param> /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the <see cref="ComputeContext"/>. </param> /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <see cref="ComputeContext"/>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <see cref="ComputeContext"/> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param> /// <param name="notifyDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param> public ComputeContext(ICollection<ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr) { int handleCount; CLDeviceHandle[] deviceHandles = ComputeTools.ExtractHandles(devices, out handleCount); IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null; callback = notify; ComputeErrorCode error = ComputeErrorCode.Success; Handle = CL10.CreateContext(propertyArray, handleCount, deviceHandles, notify, notifyDataPtr, out error); ComputeException.ThrowOnError(error); SetID(Handle.Value); this.properties = properties; ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform); this.platform = ComputePlatform.GetByHandle(platformProperty.Value); this.devices = GetDevices(); Trace.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information"); }
// initialize renderer: takes in command line parameters passed by template code public void Init(int rt, bool gpu, int platformIdx) { // pass command line parameters runningTime = rt; useGPU = gpu; gpuPlatform = platformIdx; // initialize accumulator accumulator = new Vector3[screen.width * screen.height]; ClearAccumulator(); // setup scene scene = new Scene(); // setup camera camera = new Camera(screen.width, screen.height); rngQueue = new ConcurrentQueue<Random>(); xtiles = (int)Math.Ceiling((float)screen.width / TILESIZE); ytiles = (int)Math.Ceiling((float)screen.height / TILESIZE); #if DEBUG RTTools.factorials[0] = Vector<float>.One; for (int i = 1; i < RTTools.TERMS * 2; i++) RTTools.factorials[i] = RTTools.factorials[i - 1] * i; //for (int i = 0; i < RTTools.TERMS; i++) // RTTools.atanStuff[i] = (new Vector<float>((float)Math.Pow(2, 2 * i)) * (RTTools.factorials[i] * RTTools.factorials[i])) / RTTools.factorials[2 * i + 1]; #endif #region OpenCL related things randNums = new float[screen.width * screen.height + 25]; var streamReader = new StreamReader("../../assets/GPUCode.cl"); string clSource = streamReader.ReadToEnd(); streamReader.Close(); platform = ComputePlatform.Platforms[gpuPlatform]; context = new ComputeContext(ComputeDeviceTypes.Gpu, new ComputeContextPropertyList(platform), null, IntPtr.Zero); program = new ComputeProgram(context, clSource); try { program.Build(null, null, null, IntPtr.Zero); kernel = program.CreateKernel("Test"); } catch { Console.Write("error in kernel code:\n"); Console.Write(program.GetBuildLog(context.Devices[0]) + "\n"); Debugger.Break(); } eventList = new ComputeEventList(); commands = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None); #endregion }
/// <summary> /// Creates a new <see cref="ComputeContext"/> on all the <see cref="ComputeDevice"/>s that match the specified <see cref="ComputeDeviceTypes"/>. /// </summary> /// <param name="deviceType"> A bit-field that identifies the type of <see cref="ComputeDevice"/> to associate with the <see cref="ComputeContext"/>. </param> /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the <see cref="ComputeContext"/>. </param> /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <see cref="ComputeContext"/>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <see cref="ComputeContext"/> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param> /// <param name="userDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param> public ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr) { unsafe { IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null; callback = notify; ComputeErrorCode error = ComputeErrorCode.Success; Handle = CL10.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, &error); ComputeException.ThrowOnError(error); this.properties = properties; ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform); this.platform = ComputePlatform.GetByHandle(platformProperty.Value); this.devices = GetDevices(); } resourceTable.Add(GetHashCode(), this); Trace.WriteLine("Created " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ")."); }
void comboBoxPlatform_SelectedIndexChanged(object sender, EventArgs e) { devices.Clear(); platform = ComputePlatform.Platforms[comboBoxPlatform.SelectedIndex]; object[] availableDevices = new object[platform.Devices.Count]; for (int i = 0; i < availableDevices.Length; i++) availableDevices[i] = platform.Devices[i].Name; checkedListDevices.Items.Clear(); checkedListDevices.Items.AddRange(availableDevices); checkedListDevices.SetItemChecked(0, true); }
/// <summary> /// Constructor /// </summary> /// <param name="platform">compute platform</param> /// <param name="handle">device handle</param> public ClooDevice(ComputePlatform platform, System.IntPtr handle) : base(platform, handle) { }
public void InitGPU(int platformIdx) { platform = ComputePlatform.Platforms[platformIdx]; context = new ComputeContext(ComputeDeviceTypes.Gpu, new ComputeContextPropertyList(platform), null, IntPtr.Zero); StreamReader streamReader = new StreamReader("../../program.cl"); string clSource = streamReader.ReadToEnd(); streamReader.Close(); ComputeProgram program = new ComputeProgram(context, clSource); program.Build(null, null, null, IntPtr.Zero); ComputeKernel kernelInit = program.CreateKernel("init"); ComputeKernel kernelUpdate = program.CreateKernel("update"); var flags = ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.UseHostPointer; int aantalPixels = screen.height * screen.width; rays = new GPURay[aantalPixels]; pixels = new Vector3[aantalPixels]; setGPUCameraToCamera(); GPUCamera[] gpuCamArray = { gpuCamera }; ComputeBuffer<GPURay> bufferRays = new ComputeBuffer<GPURay>(context, flags, rays); ComputeBuffer<Vector3> bufferPixels = new ComputeBuffer<Vector3>(context, flags, pixels); ComputeBuffer<GPUCamera> bufferCamera = new ComputeBuffer<GPUCamera>(context, flags, gpuCamArray); kernelUpdate.SetMemoryArgument(0, bufferRays); kernelUpdate.SetMemoryArgument(1, bufferPixels); kernelUpdate.SetMemoryArgument(2, bufferCamera); ComputeCommandQueue queue = new ComputeCommandQueue(context, context.Devices[0], 0); }
private void PlatformCombox_SelectedIndexChanged(object sender, EventArgs e) { var comboBox = sender as ComboBox; if (comboBox == null) return; _selectedComputePlatform = (ComputePlatform) comboBox.SelectedItem; DeviceCombox.DataSource = _selectedComputePlatform.Devices.ToList(); DeviceCombox.DisplayMember = "Name"; Console.WriteLine("Selected platform : " + _selectedComputePlatform.Name); }
private void DeviceCombox_SelectedIndexChanged(object sender, EventArgs e) { var comboBox = sender as ComboBox; if (comboBox == null) return; var selectedDevice = (ComputeDevice) comboBox.SelectedItem; Console.WriteLine("Selected device : " + selectedDevice.Name); _selectedComputePlatform = (ComputePlatform)PlatformCombox.SelectedItem; _selectedComputeDevice = (ComputeDevice)DeviceCombox.SelectedItem; }
public BuddhaCloo() { clPlatform = ComputePlatform.Platforms[0]; clProperties = new ComputeContextPropertyList(clPlatform); clContext = new ComputeContext(clPlatform.Devices, clProperties, null, IntPtr.Zero); clCommands = new ComputeCommandQueue(clContext, clContext.Devices[0], ComputeCommandQueueFlags.None); clEvents = new ComputeEventList(); clProgram = new ComputeProgram(clContext, new string[] { kernelSource }); R = new Random(); seed1 = (uint)R.Next(); seed2 = (uint)R.Next(); seed3 = (uint)R.Next(); seed4 = (uint)R.Next(); /* //Default buddhabrot parameters * realMin = -1.5f; * realMax = 0.75f; * imaginaryMin = -1.5f; * imaginaryMax = 1.5f; */ /* realMin = -1.05f; realMax = -0.9f; imaginaryMin = -0.3f; imaginaryMax = -0.225f; minIter = 20000; maxIter = 200000; escapeOrbit = 4.0f; minColor.R = 20000; maxColor.R = 60000; minColor.G = 60000; maxColor.G = 100000; minColor.B = 100000; maxColor.B = 200000; */ realMin = -1.22f; realMax = -1.0f; imaginaryMin = 0.16f; imaginaryMax = 0.32f; //realMin = -1.5f; //realMax = 0.75f; //imaginaryMin = -1.5f; //imaginaryMax = 1.5f; minIter =20; maxIter = 1600; escapeOrbit = 4.0f; minColor.R = 20; maxColor.R = 400; minColor.G = 400; maxColor.G = 800; minColor.B = 800; maxColor.B = 1600; width = 1000; height = 700; h_outputBuffer = new ColorVectorRGBA[width * height]; gc_outputBuffer = GCHandle.Alloc(h_outputBuffer, GCHandleType.Pinned); }
/// <summary> /// Creates a new <c>ComputeContext</c> on all the <c>ComputeDevice</c>s that match the specified <c>ComputeDeviceTypes</c>. /// </summary> /// <param name="deviceType"> A bit-field that identifies the type of <c>ComputeDevice</c> to associate with the <c>ComputeContext</c>. </param> /// <param name="properties"> A <c>ComputeContextPropertyList</c> of the <c>ComputeContext</c>. </param> /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <c>ComputeContext</c>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <c>ComputeContext</c> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param> /// <param name="userDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param> public ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr) { unsafe { IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null; callback = notify; ComputeErrorCode error = ComputeErrorCode.Success; Handle = CL10.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, &error); ComputeException.ThrowOnError(error); this.properties = properties; ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform); this.platform = ComputePlatform.GetByHandle(platformProperty.Value); this.devices = GetDevices(); } }
bool useGPU = true; // GPU code enabled (from commandline) #endregion Fields #region Methods // initialize renderer: takes in command line parameters passed by template code public void Init( int rt, bool gpu, int platformIdx ) { // pass command line parameters runningTime = rt; useGPU = gpu; gpuPlatform = platformIdx; // initialize accumulator accumulator = new Vector3[screen.width * screen.height]; ClearAccumulator(); // setup scene scene = new Scene(); // setup camera camera = new Camera( screen.width, screen.height ); // Generate randoms Console.Write("Generating randoms....\t"); randoms = new float[1000]; Random r = RTTools.GetRNG(); for (int i = 0; i < 1000; i++) randoms[i] = (float)r.NextDouble(); int variable = r.Next(); Console.WriteLine("Done!"); // initialize required opencl things if gpu is used if (useGPU) { StreamReader streamReader = new StreamReader("../../kernel.cl"); string clSource = streamReader.ReadToEnd(); streamReader.Close(); platform = ComputePlatform.Platforms[0]; context = new ComputeContext(ComputeDeviceTypes.Gpu, new ComputeContextPropertyList(platform), null, IntPtr.Zero); queue = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None); program = new ComputeProgram(context, clSource); try { program.Build(null, null, null, IntPtr.Zero); kernel = program.CreateKernel("Main"); sceneBuffer = new ComputeBuffer<Vector4>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.UseHostPointer, scene.toCL()); rndBuffer = new ComputeBuffer<float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.UseHostPointer, randoms); cameraBuffer = new ComputeBuffer<Vector3>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.UseHostPointer, camera.toCL()); outputBuffer = new ComputeBuffer<int>(context, ComputeMemoryFlags.WriteOnly | ComputeMemoryFlags.UseHostPointer, screen.pixels); skydome = new ComputeBuffer<float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.UseHostPointer, scene.Skydome); kernel.SetMemoryArgument(0, outputBuffer); kernel.SetValueArgument(1, screen.width); kernel.SetValueArgument(2, screen.height); kernel.SetMemoryArgument(3, sceneBuffer); kernel.SetValueArgument(4, scene.toCL().Length); kernel.SetMemoryArgument(5, skydome); kernel.SetMemoryArgument(6, cameraBuffer); kernel.SetMemoryArgument(7, rndBuffer); } catch (ComputeException e) { Console.WriteLine("Error in kernel code: {0}", program.GetBuildLog(context.Devices[0])); Console.ReadLine(); useGPU = false; } } else { return; } }
private void StoreState() { platformBackup = platformComboBox.SelectedIndex; devicesBackup = new bool[deviceCheckList.Items.Count]; for (int i = 0; i < devicesBackup.Length; i++) { devicesBackup[i] = false; if (deviceCheckList.GetItemChecked(i)) devicesBackup[i] = true; } optionsBackup = optionsTextBox.Text; Platform = ComputePlatform.Platforms[platformComboBox.SelectedIndex]; Devices = new ComputeDevice[deviceCheckList.CheckedItems.Count]; int k = 0; for (int i = 0; k < Devices.Length && i < Platform.Devices.Count; i++) if (deviceCheckList.GetItemChecked(i)) Devices[k++] = Platform.Devices[i]; Options = optionsTextBox.Text; }
/// <summary> /// Creates a new <c>ComputeContext</c> on a collection of <c>ComputeDevice</c>s. /// </summary> /// <param name="devices"> A collection of <c>ComputeDevice</c>s to associate with the <c>ComputeContext</c>. </param> /// <param name="properties"> A <c>ComputeContextPropertyList</c> of the <c>ComputeContext</c>. </param> /// <param name="notify"> A callback function that can be registered by the application. This callback function will be used by the OpenCL implementation to report information on errors that occur in the <c>ComputeContext</c>. This callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param> /// <param name="notifyDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param> public ComputeContext(ICollection<ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr) { unsafe { IntPtr[] deviceHandles = Tools.ExtractHandles(devices); IntPtr[] propertiesList = (properties != null) ? properties.ToIntPtrArray() : null; IntPtr notifyFuncPtr = (notify != null) ? Marshal.GetFunctionPointerForDelegate(notify) : IntPtr.Zero; ComputeErrorCode error = ComputeErrorCode.Success; fixed (IntPtr* propertiesPtr = propertiesList) fixed (IntPtr* deviceHandlesPtr = deviceHandles) Handle = CL10.CreateContext( propertiesPtr, devices.Count, deviceHandlesPtr, notifyFuncPtr, notifyDataPtr, &error); ComputeException.ThrowOnError(error); this.properties = properties; ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform); this.platform = ComputePlatform.GetByHandle(platformProperty.Value); this.devices = GetDevices(); } }
/// <summary> /// Creates a new <c>ComputeContext</c> on a collection of <c>ComputeDevice</c>s. /// </summary> /// <param name="devices"> A collection of <c>ComputeDevice</c>s to associate with the <c>ComputeContext</c>. </param> /// <param name="properties"> A <c>ComputeContextPropertyList</c> of the <c>ComputeContext</c>. </param> /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the <c>ComputeContext</c>. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until <c>ComputeContext</c> is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param> /// <param name="notifyDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param> public ComputeContext(ICollection<ComputeDevice> devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr) { unsafe { IntPtr[] deviceHandles = Tools.ExtractHandles(devices); IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null; callback = notify; ComputeErrorCode error = ComputeErrorCode.Success; Handle = CL10.CreateContext(propertyArray, devices.Count, deviceHandles, notify, notifyDataPtr, &error); ComputeException.ThrowOnError(error); this.properties = properties; ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform); this.platform = ComputePlatform.GetByHandle(platformProperty.Value); this.devices = GetDevices(); } }
/// <summary> /// OpenCLでの計算プログラムを作成する /// </summary> /// <param name="maxDt">初期時間刻み</param> /// <param name="a">振幅</param> /// <param name="omega">角速度</param> public ComputerCL(double maxDt, double a, double omega) : base(maxDt, a, omega) { // プラットフォームとデバイス群を取得 this.Platform = ComputePlatform.Platforms[0]; this.Devices = this.Platform.Devices; // コンテキストを作成 var context = new ComputeContext(this.Devices, new ComputeContextPropertyList(this.Platform), null, IntPtr.Zero); // キューを作成 this.queue = new ComputeCommandQueue(context, this.Devices[0], ComputeCommandQueueFlags.None); // プログラムを作成 var program = new ComputeProgram(context, Properties.Resources.SinAcceleration); // ビルドしてみて try { program.Build(this.Devices, null, null, IntPtr.Zero); } // 失敗したら catch(BuildProgramFailureComputeException ex) { // 例外を投げる throw new BuildCLException(program.Source[0], program.GetBuildLog(this.Devices[0])); } // カーネルを作成 this.sinAccelerationKernel = program.CreateKernel("SinAcceleration"); // 準備処理は何もしない this.prepare = () => { }; // 粒子が追加された時に base.ParticleAdded += (sender, e) => { // 準備処理の時の処理を実装 this.prepare = () => { // 粒子数を設定 this.particleCount = this.inputParticles.Count; // バッファーを作成 this.bufferX = new ComputeBuffer<Vector4>(context, ComputeMemoryFlags.ReadWrite, this.particleCount); this.bufferU = new ComputeBuffer<Vector4>(context, ComputeMemoryFlags.ReadWrite, this.particleCount); this.bufferA = new ComputeBuffer<Vector4>(context, ComputeMemoryFlags.ReadWrite, this.particleCount); this.bufferD = new ComputeBuffer<float>(context, ComputeMemoryFlags.ReadOnly, this.particleCount); // 入力データを確保 var particlesX = new Vector4[this.particleCount]; var particlesU = new Vector4[this.particleCount]; var particlesA = new Vector4[this.particleCount]; this.particlesD = new float[this.particleCount]; this.particlesMaterial = new Material[this.particleCount]; this.particlesType = new ParticleType[this.particleCount]; // 全粒子について int i = 0; foreach(var particle in this.inputParticles) { // データをコピー particlesX[i] = new Vector4((Vector3)particle.X, 0); particlesU[i] = new Vector4((Vector3)particle.U, 0); particlesA[i] = new Vector4((Vector3)particle.A, 0); this.particlesD[i] = (float)particle.D; this.particlesMaterial[i] = particle.Material; this.particlesType[i] = particle.Type; i++; } // バッファーへ転送 this.queue.WriteToBuffer(particlesX, this.bufferX, false, null); this.queue.WriteToBuffer(particlesU, this.bufferU, false, null); this.queue.WriteToBuffer(particlesA, this.bufferA, false, null); this.queue.WriteToBuffer(this.particlesD, this.bufferD, false, null); // 入力粒子群を空にする this.inputParticles.Clear(); // 準備処理は空 this.prepare = () => { }; // ここまで完了を待機 queue.Finish(); }; }; }