示例#1
0
        /// <summary>
        /// Gets the device count.
        /// </summary>
        /// <param name="type">The type of device.</param>
        /// <returns>Number of devices of type specified.</returns>
        public static int GetDeviceCount(eGPUType type)
        {
            int cnt = 0;

            if (type == eGPUType.Emulator)
            {
                cnt = GPGPUs.Count(g => g.Key.StartsWith(eGPUType.Emulator.ToString()));
                if (cnt == 0)
                {
                    GetDevice(eGPUType.Emulator, 0);
                    cnt++;
                }
            }
            else if (type == eGPUType.Cuda)
            {
                cnt += CudaGPU.GetDeviceCount();
            }
            else if (type == eGPUType.OpenCL)
            {
                foreach (var platform in ComputePlatform.Platforms)
                {
                    cnt += platform.Devices.Count;
                }
            }
            else
            {
                throw new CudafyHostException(CudafyHostException.csX_NOT_CURRENTLY_SUPPORTED, type);
            }
            return(cnt);
        }
示例#2
0
文件: CudaFFT.cs 项目: ingted/Cudafy
 internal CudaFFT(CudaGPU gpu)
 {
     _gpu = gpu;
     if (IntPtr.Size == 8)
     {
         _driver = new CUFFTDriver64();
     }
     else
     {
         _driver = new CUFFTDriver32();
     }
 }
示例#3
0
 internal CudaFFT(CudaGPU gpu)
 {
     _gpu = gpu;
     if (IntPtr.Size == 8)
     {
         _driver = new CUFFTDriver64();
     }
     else
     {
         throw new NotSupportedException();
     }
     //_driver = new CUFFTDriver32();
 }
示例#4
0
        /// <summary>
        /// Gets the device properties.
        /// </summary>
        /// <param name="type">The type of GPU.</param>
        /// <param name="useAdvanced">Whether to get the additional device settings via the cudart dll.</param>
        /// <returns>Device properties for all devices of the specified type.</returns>
        public static IEnumerable <GPGPUProperties> GetDeviceProperties(eGPUType type, bool useAdvanced = true)
        {
            if (type == eGPUType.Emulator)
            {
                foreach (var kvp in GPGPUs.Where(g => g.Value is EmulatedGPU))
                {
                    yield return(kvp.Value.GetDeviceProperties(useAdvanced));
                }
            }
            else if (type == eGPUType.Cuda)
            {
                // Store the current context
                CUcontext?ctx        = CUDA.TryGetCurrentContext();
                GPGPU     currentGPU = null;
                int       devCnt     = CudaGPU.GetDeviceCount();
                for (int i = 0; i < devCnt; i++)
                {
                    CudaGPU         gpu = null;
                    GPGPUProperties props;

                    gpu = (CudaGPU)GetDevice(eGPUType.Cuda, i);
                    if (gpu == null)
                    {
                        throw new CudafyHostException(CudafyHostException.csDEVICE_X_NOT_FOUND, string.Format("{0}{1}", eGPUType.Cuda.ToString(), i));
                    }
                    props = gpu.GetDeviceProperties(useAdvanced);
                    if (ctx != null && gpu.GetDeviceContext().Pointer == ctx.Value.Pointer)
                    {
                        currentGPU = gpu;
                    }
                    yield return(props);
                }
                // Reset context to current GPU
                if (ctx != null && currentGPU != null)
                {
                    currentGPU.SetCurrentContext();
                }
            }
            else if (type == eGPUType.OpenCL)
            {
                int deviceId = 0;
                foreach (ComputeDevice computeDevice in OpenCLDevice.ComputeDevices)
                {
                    yield return(OpenCLDevice.GetDeviceProperties(computeDevice, deviceId++));
                }
            }
            else
            {
                throw new CudafyHostException(CudafyHostException.csX_NOT_CURRENTLY_SUPPORTED, type);
            }
        }
示例#5
0
        public static IEnumerable <string> EnumerateDevices(bool openCL = false)//out string info, out bool driverInstalled)
        {
            int    count   = 0;
            string message = string.Empty;
            string info    = string.Empty;

            IsDriverInstalled = true;
            List <string>          sb          = new List <string>();
            List <GPGPUProperties> deviceProps = new List <GPGPUProperties>();
            bool failed = true;

            try
            {
                count       = openCL ? OpenCLDevice.GetDeviceCount() : CudaGPU.GetDeviceCount();
                deviceProps = CudafyHost.GetDeviceProperties(openCL ? eGPUType.OpenCL : eGPUType.Cuda).ToList();
                failed      = false;
            }
            catch (DllNotFoundException dnfe)
            {
                sb.Add("Suitable driver not installed. " + dnfe.Message);
                IsDriverInstalled = false;
            }
            catch (GASS.CUDA.CUDAException ex)
            {
                if (ex.Message == "ErrorNotInitialized")
                {
                    sb.Add("Found 0 CUDA devices.");
                }
                else
                {
                    sb.Add("CUDAException: " + ex.Message);
                }
            }
            catch (Exception ex)
            {
                sb.Add("Error: " + ex.Message);
            }

            if (failed)
            {
                foreach (var s in sb)
                {
                    yield return(s);
                }
            }
            else
            {
                yield return(string.Format("Found {0} devices.\r\n", count));

                foreach (var prop in deviceProps)
                {
                    yield return("Name: " + prop.Name);

                    if (openCL)
                    {
                        yield return("OpenCL Version: " + prop.Capability.ToString());
                    }
                    else
                    {
                        yield return("Compute capability: " + prop.Capability.ToString());
                    }
                    if (!openCL && prop.Capability < new Version(1, 4))
                    {
                        yield return("Note: This device will not support default calls to Cudafy(). Use overloads to give specific value.");
                    }
                    yield return(string.Empty);
                }
            }
        }