コード例 #1
0
        /// <summary>
        /// Waits on the host thread for the specified events to complete.
        /// </summary>
        /// <param name="events"> The events to be waited for completition. </param>
        public static void Wait(ICollection <ComputeEventBase> events)
        {
            CLEventHandle[]  eventHandles = ComputeTools.ExtractHandles(events, out var eventWaitListSize);
            ComputeErrorCode error        = CL12.WaitForEvents(eventWaitListSize, eventHandles);

            ComputeException.ThrowOnError(error);
        }
コード例 #2
0
        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 [] { ' ' }, 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, CL12.GetDeviceInfo)));
            _maxWriteImageArgs     = GetInfo <uint>(ComputeDeviceInfo.MaxWriteImageArguments);
            _memBaseAddrAlign      = GetInfo <uint>(ComputeDeviceInfo.MemoryBaseAddressAlignment);
            _minDataTypeAlignSize  = GetInfo <uint>(ComputeDeviceInfo.MinDataTypeAlignmentSize);
            _name     = GetStringInfo(ComputeDeviceInfo.Name);
            _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);
        }
コード例 #3
0
ファイル: ComputeBuffer.cs プロジェクト: myso42/Amplifier.NET
        /// <summary>
        /// Creates a new <see cref="ComputeBuffer{T}"/>.
        /// </summary>
        /// <param name="context"> A <see cref="ComputeContext"/> used to create the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="count"> The number of elements of the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="dataPtr"> A pointer to the data for the <see cref="ComputeBuffer{T}"/>. </param>
        public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, long count, IntPtr dataPtr)
            : base(context, flags)
        {
            var size = ComputeTools.SizeOf <T>() * count;

            Handle = CL12.CreateBuffer(context.Handle, flags, new IntPtr(size), dataPtr, out var error);
            ComputeException.ThrowOnError(error);
            Init(size, count);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        protected void Init(long size)
        {
            SetID(Handle.Value);

            Size  = size;
            Count = Size / ComputeTools.SizeOf <T>();

            //Debug.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        protected void Init()
        {
            SetID(Handle.Value);

            Size  = (long)GetInfo <CLMemoryHandle, ComputeMemoryInfo, IntPtr>(Handle, ComputeMemoryInfo.Size, CL12.GetMemObjectInfo);
            Count = Size / ComputeTools.SizeOf <T>();

            //Debug.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
        }
コード例 #6
0
        /// <summary>
        /// Creates a new <see cref="ComputeSubBuffer{T}"/> from a specified <see cref="ComputeBuffer{T}"/>.
        /// </summary>
        /// <param name="buffer"> The buffer to create the <see cref="ComputeSubBuffer{T}"/> from. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="offset"> The index of the element of <paramref name="buffer"/>, where the <see cref="ComputeSubBuffer{T}"/> starts. </param>
        /// <param name="count"> The number of elements of <paramref name="buffer"/> to include in the <see cref="ComputeSubBuffer{T}"/>. </param>
        public ComputeSubBuffer(ComputeBuffer <T> buffer, ComputeMemoryFlags flags, long offset, long count)
            : base(buffer.Context, flags)
        {
            var sizeofT = ComputeTools.SizeOf <T>();

            SysIntX2 region = new SysIntX2(offset * sizeofT, count * sizeofT);

            Handle = CL11.CreateSubBuffer(buffer.Handle, flags, ComputeBufferCreateType.Region, ref region, out var error);
            ComputeException.ThrowOnError(error);

            Init();
        }
コード例 #7
0
ファイル: ComputeBuffer.cs プロジェクト: myso42/Amplifier.NET
        /// <summary>
        /// Creates a new <see cref="ComputeBuffer{T}"/>.
        /// </summary>
        /// <param name="context"> A <see cref="ComputeContext"/> used to create the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="data"> The data for the <see cref="ComputeBuffer{T}"/>. </param>
        /// <remarks> Note, that <paramref name="data"/> cannot be an "immediate" parameter, i.e.: <c>new T[100]</c>, because it could be quickly collected by the GC causing Amplifier.OpenCL.Cloo to send and invalid reference to OpenCL. </remarks>
        public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, T[] data)
            : base(context, flags)
        {
            var size = ComputeTools.SizeOf <T>() * data.Length;

            GCHandle dataPtr = GCHandle.Alloc(data, GCHandleType.Pinned);

            try
            {
                Handle = CL12.CreateBuffer(context.Handle, flags, new IntPtr(size), dataPtr.AddrOfPinnedObject(), out var error);
                ComputeException.ThrowOnError(error);
            }
            finally
            {
                dataPtr.Free();
            }

            Init(size, data.Length);
        }