Exemple #1
0
        /// <inheritdoc />
        protected override Util.ISigmaDiffDataBuffer <T> _InternalDeepCopy()
        {
            T[] copyData = SigmaDiffSharpBackendProvider.Instance.GetBackend <T>(BackendTag).BackendHandle.CreateUninitialisedArray((int)Length);
            CudaSigmaDiffDataBuffer <T> copy = new CudaSigmaDiffDataBuffer <T>(copyData, 0L, Length, BackendTag, CudaContext, Type);

            if (_initialisedInContext && !_flagHostModified)
            {
                copy.InitialiseCudaBuffer(copyHostToDevice: false);

                copy._cudaBuffer.AsyncCopyToDevice(_cudaBuffer, CudaFloat32Handler.GetStreamForContext(CudaContext));

                copy._flagHostModified   = false;
                copy._flagDeviceModified = true;
            }
            else
            {
                OnReadAccess();

                Buffer.BlockCopy(_data, (int)(Offset * Type.SizeBytes), copyData, 0, (int)(Length * Type.SizeBytes));

                copy._flagHostModified = true;
            }

            return(copy);
        }
Exemple #2
0
        /// <summary>
        /// Called after this object was de-serialised.
        /// </summary>
        public void OnDeserialised()
        {
            CudaContext restoredContext = CudaFloat32Handler.GetContextForDeviceId(_cudaContextDeviceId);

            PrepareCudaBuffer(restoredContext, _data, Offset, Length);

            _flagDeviceModified = false;
            _flagHostModified   = true;
        }
Exemple #3
0
        /// <inheritdoc />
        public override IDataBuffer <T> GetValues(long startIndex, long length)
        {
            if (_initialisedInContext && !_flagHostModified)
            {
                CudaSigmaDiffDataBuffer <T> vData = new CudaSigmaDiffDataBuffer <T>(_data, startIndex, length, BackendTag, CudaContext);

                vData.InitialiseCudaBuffer(copyHostToDevice: false);

                vData._cudaBuffer.AsyncCopyToDevice(_cudaBuffer.DevicePointer, new SizeT(startIndex * sizeof(float)), vData._cudaZero, vData._cudaLengthBytes,
                                                    CudaFloat32Handler.GetStreamForContext(CudaContext));

                vData._flagHostModified   = false;
                vData._flagDeviceModified = false;

                return(vData);
            }
            else
            {
                OnReadAccess();

                return(new CudaSigmaDiffDataBuffer <T>(this, startIndex, length, BackendTag, CudaContext));
            }
        }