예제 #1
0
 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);
         }
     });
 }
예제 #2
0
        //private CUcontext _pctx;

        public CUcontext MakeFloating()
        {
            CUcontext pctx = new CUcontext();

            this.LastError = CUDADriver.cuCtxPopCurrent(ref pctx);
            return(pctx);
        }
예제 #3
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
 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);
 }
예제 #4
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
        public CUcontext GetPointerContext(CUdeviceptr ptr)
        {
            CUcontext ctx = new CUcontext();

            this.LastError = CUDADriver.cuPointerGetAttribute(ref ctx, CUPointerAttribute.Context, ptr);
            return(ctx);
        }
예제 #5
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
        public CUcontext GetCurrentContextV1()
        {
            CUcontext ctx = new CUcontext();

            this.LastError = CUDADriver.cuCtxGetCurrent(ref ctx);
            return(ctx);
        }
예제 #6
0
 /// <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);
     }
 }
예제 #7
0
        /// <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));
        }
예제 #8
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
        public static CUcontext GetCurrentContext()
        {
            CUcontext ctx = new CUcontext();
            CUResult  res = CUDADriver.cuCtxGetCurrent(ref ctx);

            if (res != CUResult.Success)
            {
                throw new CUDAException(res);
            }
            return(ctx);
        }
예제 #9
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
 public void PushCurrentContext(CUcontext ctx)
 {
     if (_version >= 4000)
     {
         this.LastError = CUDADriver.cuCtxPushCurrent_v2(ctx);
     }
     else
     {
         this.LastError = CUDADriver.cuCtxPushCurrent(ctx);
     }
 }
예제 #10
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
 public void DestroyContext(CUcontext ctx)
 {
     if (_version >= 4000)
     {
         this.LastError = CUDADriver.cuCtxDestroy_v2(ctx);
     }
     else
     {
         this.LastError = CUDADriver.cuCtxDestroy(ctx);
     }
 }
예제 #11
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
        public static CUcontext?TryGetCurrentContext()
        {
            CUcontext ctx = new CUcontext();
            CUResult  res = CUDADriver.cuCtxGetCurrent(ref ctx);

            if (res != CUResult.Success)
            {
                return(null);
            }
            return(ctx);
        }
예제 #12
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
        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);
        }
예제 #13
0
        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);
        }
예제 #14
0
        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
        }
예제 #15
0
            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.");
            }
예제 #16
0
 /// <summary> see CUDA doc; </summary>
 public static void CtxDestroy(CUcontext ctx)
 {
     TestResult(my.cuCtxDestroy(ctx));
 }
예제 #17
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
 public void EnablePeerAccess(CUcontext peerContext, uint flags)
 {
     this.LastError = CUDADriver.cuCtxEnablePeerAccess(peerContext, flags);
 }
예제 #18
0
 public static extern CUResult cuD3D10CtxCreate(ref CUcontext pCtx, ref CUdevice pCuDevice, uint Flags, IntPtr pDxDevice);
예제 #19
0
 public static extern CUResult cuD3D9CtxCreate(ref CUcontext pCtx, ref CUdevice pCudaDevice, CUCtxFlags Flags, IntPtr pD3DDevice);
예제 #20
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
 public void DisablePeerAccess(CUcontext peerContext)
 {
     this.LastError = CUDADriver.cuCtxDisablePeerAccess(peerContext);
 }
예제 #21
0
 public static extern CUResult cuD3D11CtxCreateOnDevice(ref CUcontext pCtx, CUCtxFlags flags, IntPtr pD3DDevice, CUdevice cudaDevice);
예제 #22
0
 public void StopFloating(CUcontext pctx)
 {
     this.LastError = CUDADriver.cuCtxPushCurrent(pctx);
 }
예제 #23
0
 public static extern CUResult cuGLCtxCreate(ref CUcontext pCtx, uint Flags, CUdevice device);
예제 #24
0
 public CUDAContextSynchronizer(CUcontext ctx)
 {
     this.ctx = ctx;
 }
예제 #25
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
 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);
 }
예제 #26
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
 public CUDA(int ordinal, bool initialize) : this(initialize)
 {
     //this.CurrentContext = this.CreateContext(ordinal);//, CUCtxFlags.MapHost);
     curCtx = this.CreateContext(ordinal);
     SetCurrentContext(curCtx);
 }
예제 #27
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
 public void DetachContext(CUcontext ctx)
 {
     this.LastError = CUDADriver.cuCtxDetach(ctx);
 }
예제 #28
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
 public void AttachContext(CUcontext ctx)
 {
     this.AttachContext(ctx, CUCtxFlags.SchedAuto);
 }
예제 #29
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
 public void AttachContext(CUcontext ctx, CUCtxFlags flags)
 {
     //this.LastError = CUDADriver.cuCtxAttach(ref this.curCtx, (uint) flags);
     this.LastError = CUDADriver.cuCtxAttach(ref ctx, (uint)flags);
 }
예제 #30
0
파일: CUDA.cs 프로젝트: rblenis/cudafy
 public void SetCurrentContext(CUcontext ctx)
 {
     this.LastError = CUDADriver.cuCtxSetCurrent(ctx);
 }