Library/ManagedCuda/CudaContext.cs
/// <summary>
/// Gets the CUDA devices associated with the current OpenGL context
/// </summary>
/// <param name="deviceList">SLI parameter</param>
/// <returns></returns>
Gets the CUDA devices associated with the current OpenGL context
Gets the CUDA devices associated with the current OpenGL context
public static CUdevice[] GetOpenGLDevices(CUGLDeviceList deviceList)
		{
			CUResult res;
			int deviceCount = 0;
			res = DriverAPINativeMethods.DeviceManagement.cuDeviceGetCount(ref deviceCount);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuDeviceGetCount", res));
			if (res == CUResult.ErrorNotInitialized)
			{
				res = DriverAPINativeMethods.cuInit(CUInitializationFlags.None);
				Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuInit", res));
				if (res != CUResult.Success)
					throw new CudaException(res);
				res = DriverAPINativeMethods.DeviceManagement.cuDeviceGetCount(ref deviceCount);
				Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuDeviceGetCount", res));
				if (res != CUResult.Success)
					throw new CudaException(res);
			}
			else if (res != CUResult.Success)
				throw new CudaException(res);
			if (deviceCount == 0)
			{
				throw new CudaException(CUResult.ErrorNoDevice, "Cuda initialization error: There is no device supporting CUDA", null);
			}
			CUdevice[] devices;
			CUdevice[] temp = new CUdevice[deviceCount];
			uint openGLDevices = 0;
			res = OpenGLNativeMethods.CUDA3.cuGLGetDevices(ref openGLDevices, temp, (uint)deviceCount, deviceList);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGLGetDevices", res));
			if (res != CUResult.Success)
				throw new CudaException(res);
			if (openGLDevices == 0)
			{
				throw new CudaException(CUResult.ErrorNoDevice, "Cuda initialization error: There is no device supporting CUDA and OpenGL", null);
			}
			devices = new CUdevice[openGLDevices];
			Array.Copy(temp, devices, openGLDevices);
			return devices;
		}
public static CUdevice [ ] GetOpenGLDevices ( CUGLDeviceList deviceList ) { CUResult res ; int deviceCount = 0 ; res = DriverAPINativeMethods . DeviceManagement . cuDeviceGetCount ( ref deviceCount ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res == CUResult . ErrorNotInitialized ) { res = DriverAPINativeMethods . cuInit ( CUInitializationFlags . None ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; res = DriverAPINativeMethods . DeviceManagement . cuDeviceGetCount ( ref deviceCount ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; } else if ( res != CUResult . Success ) throw new CudaException ( res ) ; if ( deviceCount == 0 ) { throw new CudaException ( CUResult . ErrorNoDevice , " " , null ) ; } CUdevice [ ] devices ; CUdevice [ ] temp = new CUdevice [ deviceCount ] ; uint openGLDevices = 0 ; res = OpenGLNativeMethods . CUDA3 . cuGLGetDevices ( ref openGLDevices , temp , ( uint ) deviceCount , deviceList ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; if ( openGLDevices == 0 ) { throw new CudaException ( CUResult . ErrorNoDevice , " " , null ) ; } devices = new CUdevice [ openGLDevices ] ; Array . Copy ( temp , devices , openGLDevices ) ; return devices ; }
Gets the CUDA devices associated with the current OpenGL context
Gets the CUDA devices associated with the current OpenGL context
//Don't use .Take to stay compatible with .net 2 and 3 //devices = temp.Take((int)openGLDevices).ToArray(); 
None
deviceList
CUGLDeviceList
None