Exemple #1
0
        static OpenCLPlatform()
        {
            try
            {
                if (platforms != null)
                {
                    return;
                }
                CLPlatformHandle[] handles;
                int             handlesLength;
                OpenCLErrorCode error = CL10.GetPlatformIDs(0, null, out handlesLength);
                OpenCLException.ThrowOnError(error);
                handles = new CLPlatformHandle[handlesLength];

                error = CL10.GetPlatformIDs(handlesLength, handles, out handlesLength);
                OpenCLException.ThrowOnError(error);

                List <OpenCLPlatform> platformList = new List <OpenCLPlatform>(handlesLength);
                foreach (CLPlatformHandle handle in handles)
                {
                    platformList.Add(new OpenCLPlatform(handle));
                }

                platforms = platformList.AsReadOnly();
            }
            catch (DllNotFoundException)
            {
                platforms = new List <OpenCLPlatform>().AsReadOnly();
            }
        }
Exemple #2
0
        static ComputePlatform()
        {
            lock (typeof(ComputePlatform))
            {
                try
                {
                    if (Platforms != null)
                    {
                        return;
                    }

                    CLPlatformHandle[] handles;
                    var error = CL10.GetPlatformIDs(0, null, out int handlesLength);
                    ComputeException.ThrowOnError(error);
                    handles = new CLPlatformHandle[handlesLength];

                    error = CL10.GetPlatformIDs(handlesLength, handles, out handlesLength);
                    ComputeException.ThrowOnError(error);

                    var platformList = new List <ComputePlatform>(handlesLength);
                    foreach (CLPlatformHandle handle in handles)
                    {
                        platformList.Add(new ComputePlatform(handle));
                    }
                    Platforms = platformList.AsReadOnly();
                }
                catch (DllNotFoundException)
                {
                    Platforms = new List <ComputePlatform>().AsReadOnly();
                }
            }
        }