private static void cuCtxDestroy(CUcontext ctx) { Wrap(() => { try { var error = nativeCtxDestroy(ctx); if (error != CUresult.CUDA_SUCCESS) { throw new CudaException(error); } } catch (CudaException) { throw; } catch (DllNotFoundException dnfe) { throw new CudaException(CudaError.NoDriver, dnfe); } catch (Exception e) { throw new CudaException(CudaError.Unknown, e); } }); }
//private CUcontext _pctx; public CUcontext MakeFloating() { CUcontext pctx = new CUcontext(); this.LastError = CUDADriver.cuCtxPopCurrent(ref pctx); return(pctx); }
public CUcontext CreateContext(int ordinal, CUCtxFlags flags) { this.curCtx = new CUcontext(); this.LastError = CUDADriver.cuCtxCreate(ref this.curCtx, (uint)flags, this.Devices[ordinal].Handle); this.CurrentDevice = this.Devices[ordinal]; return(this.curCtx); }
public CUcontext GetPointerContext(CUdeviceptr ptr) { CUcontext ctx = new CUcontext(); this.LastError = CUDADriver.cuPointerGetAttribute(ref ctx, CUPointerAttribute.Context, ptr); return(ctx); }
public CUcontext GetCurrentContextV1() { CUcontext ctx = new CUcontext(); this.LastError = CUDADriver.cuCtxGetCurrent(ref ctx); return(ctx); }
/// <summary> /// Sets the parameters for a memcpy node in the given graphExec.<para/> /// Updates the work represented by \p hNode in \p hGraphExec as though \p hNode had /// contained \p copyParams at instantiation. hNode must remain in the graph which was /// used to instantiate \p hGraphExec. Changed edges to and from hNode are ignored.<para/> /// The source and destination memory in \p copyParams must be allocated from the same /// contexts as the original source and destination memory. Both the instantiation-time /// memory operands and the memory operands in \p copyParams must be 1-dimensional. /// Zero-length operations are not supported.<para/> /// The modifications only affect future launches of \p hGraphExec. Already enqueued /// or running launches of \p hGraphExec are not affected by this call. hNode is also /// not modified by this call.<para/> /// Returns CUDA_ERROR_INVALID_VALUE if the memory operands' mappings changed or /// either the original or new memory operands are multidimensional. /// </summary> public void SetParams(CUgraphNode hNode, ref CUDAMemCpy3D copyParams, CUcontext ctx) { res = DriverAPINativeMethods.GraphManagment.cuGraphExecMemcpyNodeSetParams(_graph, hNode, ref copyParams, ctx); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphExecMemcpyNodeSetParams", res)); if (res != CUResult.Success) { throw new CudaException(res); } }
/// <summary> see CUDA doc; </summary> public static void CtxCreate(out CUcontext pctx, CUdevice dev, params CUctx_flags_enum[] flags) { uint _flags = 0; foreach (CUctx_flags_enum x in flags) { _flags |= (uint)x; } TestResult(my.cuCtxCreate(out pctx, _flags, dev)); }
public static CUcontext GetCurrentContext() { CUcontext ctx = new CUcontext(); CUResult res = CUDADriver.cuCtxGetCurrent(ref ctx); if (res != CUResult.Success) { throw new CUDAException(res); } return(ctx); }
public void PushCurrentContext(CUcontext ctx) { if (_version >= 4000) { this.LastError = CUDADriver.cuCtxPushCurrent_v2(ctx); } else { this.LastError = CUDADriver.cuCtxPushCurrent(ctx); } }
public void DestroyContext(CUcontext ctx) { if (_version >= 4000) { this.LastError = CUDADriver.cuCtxDestroy_v2(ctx); } else { this.LastError = CUDADriver.cuCtxDestroy(ctx); } }
public static CUcontext?TryGetCurrentContext() { CUcontext ctx = new CUcontext(); CUResult res = CUDADriver.cuCtxGetCurrent(ref ctx); if (res != CUResult.Success) { return(null); } return(ctx); }
public CUcontext PopCurrentContext() { CUcontext pctx = new CUcontext(); if (_version >= 4000) { this.LastError = CUDADriver.cuCtxPopCurrent_v2(ref pctx); } else { this.LastError = CUDADriver.cuCtxPopCurrent(ref pctx); } this.curCtx = pctx; return(pctx); }
protected void InitCudaModule() { int deviceNr = 0; cuda = new CUDA(deviceNr, true); cuCtx = cuda.CreateContext(deviceNr, CUCtxFlags.MapHost); string modluePath = Path.Combine(Environment.CurrentDirectory, cudaModuleName); if (!File.Exists(modluePath)) { throw new ArgumentException("Failed access to cuda module" + modluePath); } cuModule = cuda.LoadModule(modluePath); cuFunc = cuda.GetModuleFunction(cudaProductKernelName); }
public HuForceDirectedLayout(int steps) { #if !DEBUG try { #endif CUDADriver.cuInit(0); dev = new CUdevice(); CUDADriver.cuDeviceGet(ref dev, 0); ctx = new CUcontext(); CUDADriver.cuCtxCreate(ref ctx, 0, dev); mod = new CUmodule(); CUDADriver.cuModuleLoad(ref mod, "BarnesHut.cubin"); prop = new CUDeviceProperties(); CUDADriver.cuDeviceGetProperties(ref prop, dev); int version = 0; CUDADriver.cuDriverGetVersion(ref version); string caps = ""; GASS.CUDA.CUDARuntime.cudaRuntimeGetVersion(ref version); caps += "\tClock rate = " + prop.clockRate / 1000000 + " MHz\n"; caps += "\tMemory size = " + prop.totalConstantMemory / 1024 + " KB\n"; caps += "\tThreads per block = " + prop.maxThreadsPerBlock + "\n"; caps += "\tWarp size = " + prop.SIMDWidth + "\n"; caps += "\tCUDA version = " + version + "\n"; Logger.AddMessage(LogEntryType.Info, "Successfully initialized CUDA GPU computation\n" + caps); #if !DEBUG } catch (Exception ex) { Logger.AddMessage(LogEntryType.Warning, "CUDA not available, falling back to CPU. Exception was: " + ex.Message); CUDAEnabled = false; } #endif }
public GlobalContext() { Log.EnsureBlankLine(); Log.WriteLine("Acquiring number of CUDA-capable devices..."); var deviceCount = cuDeviceGetCount(); Log.WriteLine("{0} device(s) found.", cuDeviceGetCount()); (deviceCount > 0).AssertTrue(); Log.EnsureBlankLine(); Log.WriteLine("Accessing device #0..."); var device = CudaDevice.First; Log.WriteLine("Success."); Log.EnsureBlankLine(); Log.WriteLine(device); Log.EnsureBlankLine(); Log.WriteLine("Creating CUDA context for device #0..."); _handle = cuCtxCreate(CUctx_flags.None, device.Handle); Log.WriteLine("Success."); }
/// <summary> see CUDA doc; </summary> public static void CtxDestroy(CUcontext ctx) { TestResult(my.cuCtxDestroy(ctx)); }
public void EnablePeerAccess(CUcontext peerContext, uint flags) { this.LastError = CUDADriver.cuCtxEnablePeerAccess(peerContext, flags); }
public static extern CUResult cuD3D10CtxCreate(ref CUcontext pCtx, ref CUdevice pCuDevice, uint Flags, IntPtr pDxDevice);
public static extern CUResult cuD3D9CtxCreate(ref CUcontext pCtx, ref CUdevice pCudaDevice, CUCtxFlags Flags, IntPtr pD3DDevice);
public void DisablePeerAccess(CUcontext peerContext) { this.LastError = CUDADriver.cuCtxDisablePeerAccess(peerContext); }
public static extern CUResult cuD3D11CtxCreateOnDevice(ref CUcontext pCtx, CUCtxFlags flags, IntPtr pD3DDevice, CUdevice cudaDevice);
public void StopFloating(CUcontext pctx) { this.LastError = CUDADriver.cuCtxPushCurrent(pctx); }
public static extern CUResult cuGLCtxCreate(ref CUcontext pCtx, uint Flags, CUdevice device);
public CUDAContextSynchronizer(CUcontext ctx) { this.ctx = ctx; }
public void CopyPeerToPeerAsync(CUdeviceptr dstDevice, CUcontext dstContext, CUdeviceptr srcDevice, CUcontext srcContext, SizeT ByteCount, CUstream stream) { this.LastError = CUDADriver.cuMemcpyPeerAsync(dstDevice, dstContext, srcDevice, srcContext, ByteCount, stream); }
public CUDA(int ordinal, bool initialize) : this(initialize) { //this.CurrentContext = this.CreateContext(ordinal);//, CUCtxFlags.MapHost); curCtx = this.CreateContext(ordinal); SetCurrentContext(curCtx); }
public void DetachContext(CUcontext ctx) { this.LastError = CUDADriver.cuCtxDetach(ctx); }
public void AttachContext(CUcontext ctx) { this.AttachContext(ctx, CUCtxFlags.SchedAuto); }
public void AttachContext(CUcontext ctx, CUCtxFlags flags) { //this.LastError = CUDADriver.cuCtxAttach(ref this.curCtx, (uint) flags); this.LastError = CUDADriver.cuCtxAttach(ref ctx, (uint)flags); }
public void SetCurrentContext(CUcontext ctx) { this.LastError = CUDADriver.cuCtxSetCurrent(ctx); }