Ejemplo n.º 1
0
        public static unsafe PrimeBuffer Create <T>(PrimeContext ctx, PrimeBufferDesc desc, T[] data)
            where T : struct
        {
            var dataToCopy = new Memory <T>(data);
            var data2Cpy   = dataToCopy.Pin();
            var dataLength = Unsafe.SizeOf <T>() * data.Length;
            var dataPtr    = IntPtr.Zero;

            if (desc.Type == RTPBufferType.CudaLinear)
            {
                //CudaDriverApi.CudaCall(CudaDriverApi.cuMemAlloc(ref dataPtr, (uint) dataLength));

                CudaRunTimeApi.CudaCall(CudaRunTimeApi.cudaMalloc(ref dataPtr, (uint)dataLength));
                CudaRunTimeApi.CudaCall(CudaRunTimeApi.cudaMemcpy(dataPtr.ToPointer(), new IntPtr(data2Cpy.Pointer), (uint)dataLength, CudaMemCpyKind.cudaMemcpyHostToDevice));
                // CudaDriverApi.CudaCall(CudaDriverApi.cuMemcpyHtoD(ref dataPtr, data2Cpy.Pointer, (uint) dataLength));
            }
            else
            {
                dataPtr = Marshal.AllocHGlobal(dataLength);
                GC.AddMemoryPressure(dataLength);
                var span = new Span <T>(data);
                MemoryHelper.CopyFromManaged(ref span, dataPtr, (uint)data.Length);
                // Unsafe.Copy(dataPtr.ToPointer(), ref data);
            }
            data2Cpy.Dispose();

            var buffer = new PrimeBuffer(ctx, desc, dataPtr)
            {
                size = dataLength
            };

            return(buffer);
        }
Ejemplo n.º 2
0
        public static PrimeBuffer Create <T>(PrimeContext ctx, PrimeBufferDesc desc, T[] data)
        {
            var h    = GCHandle.Alloc(data, GCHandleType.Pinned);
            var span = new Span <T>(data);

            //MemoryHelper.CopyFromManaged(ref span, );
            throw new NotImplementedException();
        }
Ejemplo n.º 3
0
        public PrimeBuffer CreateBuffer <T>(RTPBufferType type, RtpBufferFormat format, T[] data)
            where T : struct
        {
            var desc = new PrimeBufferDesc {
                Type = type, Format = format
            };
            var buffer = PrimeBuffer.Create(this, desc, data);

            _buffers.Add(buffer);
            return(buffer);
        }
Ejemplo n.º 4
0
 public PrimeBuffer(PrimeContext context, PrimeBufferDesc fmt, IntPtr data) : base(context)
 {
     _dataPointer = data;
     CheckError(PrimeApi.rtpBufferDescCreate(context.InternalPtr, (RTPbufferformat)fmt.Format, (RTPbuffertype)fmt.Type, data, out InternalPtr));
 }