Пример #1
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);
        }
Пример #2
0
        public static ClPlatformID[] GetPlatformIDs()
        {
            uint required;

            ErrorHandler.ThrowOnFailure(clGetPlatformIDs(0, null, out required));
            if (required == 0)
            {
                return(new ClPlatformID[0]);
            }

            ClPlatformID[] platforms = new ClPlatformID[required];
            uint           actual;

            ErrorHandler.ThrowOnFailure(clGetPlatformIDs(required, platforms, out actual));
            Array.Resize(ref platforms, (int)actual);
            return(platforms);
        }
        public static ClDeviceID[] GetDeviceIDs(ClPlatformID platform, DeviceType deviceType)
        {
            uint required;

            ErrorHandler.ThrowOnFailure(clGetDeviceIDs(platform, deviceType, 0, null, out required));
            if (required == 0)
            {
                return(new ClDeviceID[0]);
            }

            ClDeviceID[] devices = new ClDeviceID[required];
            uint         actual;

            ErrorHandler.ThrowOnFailure(clGetDeviceIDs(platform, deviceType, required, devices, out actual));
            Array.Resize(ref devices, (int)actual);
            return(devices);
        }
Пример #4
0
        public static T GetPlatformInfo <T>(ClPlatformID platform, PlatformParameterInfo <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(clGetPlatformInfo(platform, 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(clGetPlatformInfo(platform, parameter.ParameterInfo.Name, requiredSize, memory, out actualSize));
                return(parameter.ParameterInfo.Deserialize(actualSize, memory));
            }
            finally
            {
                Marshal.FreeHGlobal(memory);
            }
        }
Пример #5
0
 private static extern ErrorCode clGetPlatformInfo(
     ClPlatformID platform,
     int paramName,
     UIntPtr paramValueSize,
     IntPtr paramValue,
     out UIntPtr paramValueSizeRet);
 private static extern ErrorCode clGetDeviceIDs(
     ClPlatformID platform,
     DeviceType deviceType,
     uint numEntries,
     [Out, MarshalAs(UnmanagedType.LPArray)] ClDeviceID[] devices,
     out uint numDevices);
Пример #7
0
 /// <summary>
 /// Invokes <see cref="clUnloadPlatformCompiler"/>, and throws an exception if
 /// the call does not succeed.
 /// </summary>
 /// <param name="platform">A valid platform.</param>
 /// <seealso cref="Platform.UnloadCompiler"/>
 public static void UnloadPlatformCompiler(ClPlatformID platform)
 {
     ErrorHandler.ThrowOnFailure(clUnloadPlatformCompiler(platform));
 }
Пример #8
0
 private static extern ErrorCode clUnloadPlatformCompiler(ClPlatformID platform);