Exemple #1
0
        public static ContextSafeHandle CreateContextFromType(DeviceType deviceType, CreateContextCallback pfnNotify, IntPtr userData)
        {
            ErrorCode         errorCode = ErrorCode.Success;
            ContextSafeHandle result    = clCreateContextFromType(null, deviceType, pfnNotify, userData, out errorCode);

            ErrorHandler.ThrowOnFailure(errorCode);
            return(result);
        }
        public static CommandQueueSafeHandle CreateCommandQueue(ContextSafeHandle context, ClDeviceID device, CommandQueueProperties properties)
        {
            ErrorCode errorCode;
            CommandQueueSafeHandle result = clCreateCommandQueue(context, device, properties, out errorCode);

            ErrorHandler.ThrowOnFailure(errorCode);
            return(result);
        }
Exemple #3
0
 private static extern ProgramSafeHandle clCreateProgramWithBinary(
     ContextSafeHandle context,
     uint numDevices,
     [In, MarshalAs(UnmanagedType.LPArray)] ClDeviceID[] devices,
     [In, MarshalAs(UnmanagedType.LPArray)] IntPtr[] lengths,
     [In, MarshalAs(UnmanagedType.LPArray)] IntPtr[] binaries,
     [Out, MarshalAs(UnmanagedType.LPArray)] ErrorCode[] binaryStatus,
     out ErrorCode errorCode);
Exemple #4
0
        public static ContextSafeHandle CreateContext(ClDeviceID[] devices, CreateContextCallback pfnNotify, IntPtr userData)
        {
            ErrorCode         errorCode = ErrorCode.Success;
            ContextSafeHandle result    = clCreateContext(null, (uint)devices.Length, devices, pfnNotify, userData, out errorCode);

            ErrorHandler.ThrowOnFailure(errorCode);
            return(result);
        }
Exemple #5
0
        private Context(ContextSafeHandle context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            _context = context;
        }
Exemple #6
0
        public static ContextSafeHandle CreateContext(ClPlatformID platform, ClDeviceID[] devices, CreateContextCallback pfnNotify, IntPtr userData)
        {
            IntPtr[]          properties = { ContextProperties.Platform, platform.Handle, IntPtr.Zero };
            ErrorCode         errorCode  = ErrorCode.Success;
            ContextSafeHandle result     = clCreateContext(properties, (uint)devices.Length, devices, pfnNotify, userData, out errorCode);

            ErrorHandler.ThrowOnFailure(errorCode);
            return(result);
        }
Exemple #7
0
        /// <summary>
        /// Destroy the Forms API context.
        /// </summary>
        public static void Destroy()
        {
            if (_context.IsInvalid)
            {
                return;
            }

            _context.Dispose();
            _context = null;
        }
Exemple #8
0
 private static extern ProgramSafeHandle clLinkProgram(
     ContextSafeHandle context,
     uint numDevices,
     [In, MarshalAs(UnmanagedType.LPArray)] ClDeviceID[] devices,
     [MarshalAs(UnmanagedType.LPStr)] string options,
     uint numInputPrograms,
     [In, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(SafeHandleArrayMarshaler))] ProgramSafeHandle[] inputPrograms,
     BuildProgramCallback pfnNotify,
     IntPtr userData,
     out ErrorCode errorCode);
Exemple #9
0
        public static Context Create(Platform platform, DeviceType deviceType)
        {
            if (platform == null)
            {
                throw new ArgumentNullException("platform");
            }

            ContextSafeHandle handle = UnsafeNativeMethods.CreateContextFromType(platform.ID, deviceType, null, IntPtr.Zero);

            return(new Context(handle));
        }
Exemple #10
0
        /// <summary>
        /// Creates a program object for a <paramref name="context"/>, and loads specified binary
        /// data into the <see cref="Program"/> object.
        /// </summary>
        /// <remarks>
        /// OpenCL allows applications to create a program object using the program source or binary
        /// and build appropriate program executables. This allows applications to determine whether
        /// they want to use the pre-built offline binary or load and compile the program source
        /// and use the executable compiled/linked online as the program executable. This can be
        /// very useful as it allows applications to load and build program executables online on
        /// its first instance for appropriate OpenCL devices in the system. These executables can
        /// now be queried and cached by the application. Future instances of the application
        /// launching will no longer need to compile and build the program executables. The cached
        /// executables can be read and loaded by the application, which can help significantly
        /// reduce the application initialization time.
        /// </remarks>
        /// <param name="context">Must be a valid OpenCL context.</param>
        /// <param name="devices">A pointer to a list of devices that are in context. device_list
        /// must be a non-NULL value. The binaries are loaded for devices specified in this list.</param>
        /// <param name="bins">An array of pointers to program binaries to be loaded for devices
        /// specified by device_list. For each device given by device_list[i], the pointer to the
        /// program binary for that device is given by binaries[i] and the length of this
        /// corresponding binary is given by lengths[i]. lengths[i] cannot be zero and binaries[i]
        /// cannot be a NULL pointer.</param>
        /// <returns>
        /// <see cref="clUnloadPlatformCompiler"/> returns <see cref="ErrorCode.Success"/>
        /// if the function is executed successfully. Otherwise, it returns one of the following
        /// errors:
        ///
        /// <list type="bullet">
        /// <item><see cref="ErrorCode.InvalidContext"/> if <paramref name="context"/> is not a valid context.</item>
        /// <item><see cref="ErrorCode.InvalidValue"/> if device_list is NULL or num_devices is zero; or if lengths or binaries are null or if any entry in lengths[i] or binaries[i] is NULL.</item>
        /// <item><see cref="ErrorCode.InvalidDevice"/> if OpenCL devices listed in device_list are not in the list of devices associated with context.</item>
        /// <item><see cref="ErrorCode.InvalidBinary"/> if an invalid program binary was encountered for any device. binary_status will return specific status for each device.</item>
        /// <item><see cref="ErrorCode.OutOfHostMemory"/>  if there is a failure to allocate resources required by the OpenCL implementation on the host.</item>
        /// </list>
        /// </returns>
        public static ProgramSafeHandle CreateProgramWithBinary(ContextSafeHandle context, ClDeviceID[] devices, byte[][] bins)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (bins == null)
            {
                throw new ArgumentNullException("bins");
            }
            if (devices == null)
            {
                throw new ArgumentNullException("devices");
            }
            if (devices.Length == 0)
            {
                throw new ArgumentException("No devices specified.");
            }

            uint devCt = (devices != null && devices.Length > 0) ? (uint)devices.Length : 0;

            int binCt = bins.Length;

            IntPtr[] lengths = Array.ConvertAll(bins, b => (IntPtr)b.Length);

            ErrorCode errorCode;

            ErrorCode[] binaryStatus = new ErrorCode[binCt];
            GCHandle[]  gh           = null;

            ProgramSafeHandle handle;

            try
            {
                gh = Array.ConvertAll(bins, b => GCHandle.Alloc(b, GCHandleType.Pinned));
                IntPtr[] binaries = Array.ConvertAll(gh, h => h.AddrOfPinnedObject());

                //todo: had to put in a 1 for devCt. On systems with more then 1 device using
                //anything larger then 1 here fails so forcing 1 for now because at least it works.
                //was: handle = clCreateProgramWithBinary(context, devCt, devices, lengths, binaries, binaryStatus, out errorCode);
                handle = clCreateProgramWithBinary(context, 1, devices, lengths, binaries, binaryStatus, out errorCode);
            }
            finally
            {
                for (int i = 0; i < gh.Length; i++)
                {
                    gh[i].Free();
                }
            }

            ErrorHandler.ThrowOnFailure(errorCode);

            return(handle);
        }
Exemple #11
0
        internal static SamplerSafeHandle CreateSampler(ContextSafeHandle context, bool normalizedCoordinates, AddressingMode addressingMode, FilterMode filterMode)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            ErrorCode         errorCode;
            SamplerSafeHandle handle = clCreateSampler(context, normalizedCoordinates, addressingMode, filterMode, out errorCode);

            ErrorHandler.ThrowOnFailure(errorCode);
            return(handle);
        }
Exemple #12
0
        public static EventSafeHandle CreateUserEvent(ContextSafeHandle context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ErrorCode       errorCode;
            EventSafeHandle handle = clCreateUserEvent(context, out errorCode);

            ErrorHandler.ThrowOnFailure(errorCode);
            return(handle);
        }
Exemple #13
0
        public static Context Create(Platform platform, params Device[] devices)
        {
            if (devices == null)
            {
                throw new ArgumentNullException("devices");
            }
            if (devices.Length == 0)
            {
                throw new ArgumentException("No devices specified.");
            }

            UnsafeNativeMethods.ClDeviceID[] deviceIDs = Array.ConvertAll(devices, device => device.ID);
            ContextSafeHandle handle = UnsafeNativeMethods.CreateContext(platform.ID, deviceIDs, null, IntPtr.Zero);

            return(new Context(handle));
        }
Exemple #14
0
        public static ProgramSafeHandle CreateProgramWithSource(ContextSafeHandle context, string[] strings)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (strings == null)
            {
                throw new ArgumentNullException("strings");
            }

            ErrorCode         errorCode;
            ProgramSafeHandle handle = clCreateProgramWithSource(context, (uint)strings.Length, strings, null, out errorCode);

            ErrorHandler.ThrowOnFailure(errorCode);
            return(handle);
        }
Exemple #15
0
        public static T GetContextInfo <T>(ContextSafeHandle context, ContextParameterInfo <T> parameter)
        {
            int?fixedSize = parameter.ParameterInfo.FixedSize;

#if DEBUG
            bool verifyFixedSize = true;
#else
            bool verifyFixedSize = false;
#endif

            UIntPtr requiredSize;
            if (fixedSize.HasValue && !verifyFixedSize)
            {
                requiredSize = (UIntPtr)fixedSize;
            }
            else
            {
                ErrorHandler.ThrowOnFailure(clGetContextInfo(context, parameter.ParameterInfo.Name, UIntPtr.Zero, IntPtr.Zero, out requiredSize));
            }

            if (verifyFixedSize && fixedSize.HasValue)
            {
                if (requiredSize.ToUInt64() != (ulong)fixedSize.Value)
                {
                    throw new ArgumentException("The parameter definition includes a fixed size that does not match the required size according to the runtime.");
                }
            }

            IntPtr memory = IntPtr.Zero;
            try
            {
                memory = Marshal.AllocHGlobal((int)requiredSize.ToUInt32());
                UIntPtr actualSize;
                ErrorHandler.ThrowOnFailure(clGetContextInfo(context, parameter.ParameterInfo.Name, requiredSize, memory, out actualSize));
                return(parameter.ParameterInfo.Deserialize(actualSize, memory));
            }
            finally
            {
                Marshal.FreeHGlobal(memory);
            }
        }
Exemple #16
0
 private static extern EventSafeHandle clCreateUserEvent(ContextSafeHandle context, out ErrorCode errorCode);
Exemple #17
0
 public static extern D2fErrorCode d2fcrdap_Apply(ContextSafeHandle pd2fctx, ObjectSafeHandle pd2fcrd, ObjectSafeHandle pd2ffmd);
Exemple #18
0
 private static extern ProgramSafeHandle clCreateProgramWithBuiltInKernels(
     ContextSafeHandle context,
     uint numDevices,
     [In, MarshalAs(UnmanagedType.LPArray)] ClDeviceID[] devices,
     [MarshalAs(UnmanagedType.LPStr)] string kernelNames,
     out ErrorCode errorCode);
Exemple #19
0
 public static extern D2fErrorCode d2fobfo_FindObj(ContextSafeHandle pd2fctx,
                                                   ObjectSafeHandle owner,
                                                   string name,
                                                   ObjectType objtyp,
                                                   out ObjectSafeHandle ppd2fob);
Exemple #20
0
 private static extern ProgramSafeHandle clCreateProgramWithSource(
     ContextSafeHandle context,
     uint count,
     [In, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] string[] strings,
     [In, MarshalAs(UnmanagedType.LPArray)] IntPtr[] lengths,
     out ErrorCode errorCode);
Exemple #21
0
 public static extern D2fErrorCode d2ffmdsv_Save(ContextSafeHandle pd2fctx,
                                                 ObjectSafeHandle pd2ffmd,
                                                 string formname,
                                                 [MarshalAs(UnmanagedType.I1)] bool db);
Exemple #22
0
 private static extern ErrorCode clRetainContext(ContextSafeHandle context);
Exemple #23
0
 public static extern D2fErrorCode d2fcrdex_Extract(ContextSafeHandle pd2fctx, ObjectSafeHandle pd2fcrd, ObjectSafeHandle pd2ffmd);
Exemple #24
0
 public static extern D2fErrorCode d2ffntcr_Create(ContextSafeHandle pd2fctx, out ObjectSafeHandle ppd2ffnt);
Exemple #25
0
 public static extern D2fErrorCode d2fobmv_Move(ContextSafeHandle pd2fctx, ObjectSafeHandle pd2fob, ObjectSafeHandle pd2fob_nxt);
Exemple #26
0
 public static extern D2fErrorCode d2ffntap_Apply(ContextSafeHandle pd2fctx, ObjectSafeHandle pd2ffnt, ObjectSafeHandle pd2fob, VisualAttributeType vat_typ);
Exemple #27
0
 private static extern ErrorCode clGetContextInfo(
     ContextSafeHandle context,
     int paramName,
     UIntPtr paramValueSize,
     IntPtr paramValue,
     out UIntPtr paramValueSizeRet);
Exemple #28
0
 public static extern D2fErrorCode d2ffmdco_CompileObj(ContextSafeHandle pd2fctx, ObjectSafeHandle pd2ffmd);
Exemple #29
0
 public static extern D2fErrorCode d2fobsc_SubClass(ContextSafeHandle pd2fctx,
                                                    ObjectSafeHandle pd2fob,
                                                    ObjectSafeHandle parent,
                                                    [MarshalAs(UnmanagedType.I1)] bool keep_path);
Exemple #30
0
 public static extern D2fErrorCode d2falbdt_Detach(ContextSafeHandle pd2fctx, ObjectSafeHandle pd2falb);