示例#1
0
        /// <summary>
        /// Copy denseVector to host, numerically finds the non-zero indices, and then copy back to device
        /// </summary>
        public SparseVector(Vector denseVector)
            : base(false, denseVector.memorySpace, denseVector.mathDomain)
        {
            this.denseSize = denseVector.Size;

            switch (denseVector.mathDomain)
            {
            case MathDomain.Int:
                Compress <int>(denseVector);
                break;

            case MathDomain.Float:
                Compress <float>(denseVector);
                break;

            case MathDomain.Double:
                Compress <double>(denseVector);
                break;

            default:
                break;
            }

            _buffer = new SparseMemoryBuffer(0, (uint)nonZeroIndices.Size, 0, memorySpace, mathDomain);
            SyncPointers();
        }
 public ResidentAttributeRecord(AttributeType type, string name, ushort id, bool indexed, AttributeFlags flags)
     : base(type, name, id, flags)
 {
     _nonResidentFlag = 0;
     _indexedFlag     = (byte)(indexed ? 1 : 0);
     _memoryBuffer    = new SparseMemoryBuffer(1024);
 }
 public ResidentAttributeRecord(AttributeType type, string name, ushort id, bool indexed, AttributeFlags flags)
     : base(type, name, id, flags)
 {
     _nonResidentFlag = 0;
     _indexedFlag = (byte)(indexed ? 1 : 0);
     _memoryBuffer = new SparseMemoryBuffer(1024);
 }
        public static DiscUtils.Ntfs.NtfsFileSystem NtfsFileSystem()
        {
            SparseMemoryBuffer buffer       = new SparseMemoryBuffer(4096);
            SparseMemoryStream ms           = new SparseMemoryStream();
            Geometry           diskGeometry = Geometry.FromCapacity(30 * 1024 * 1024);

            return(DiscUtils.Ntfs.NtfsFileSystem.Format(ms, "", diskGeometry, 0, diskGeometry.TotalSectorsLong));
        }
        private static DiscFileSystem FatFileSystem()
        {
            SparseMemoryBuffer buffer       = new SparseMemoryBuffer(4096);
            SparseMemoryStream ms           = new SparseMemoryStream();
            Geometry           diskGeometry = Geometry.FromCapacity(30 * 1024 * 1024);

            return(DiscUtils.Fat.FatFileSystem.FormatFloppy(ms, FloppyDiskType.Extended, null));
        }
示例#6
0
        public static void SparseSubtract(MemoryBuffer z, SparseMemoryBuffer x, MemoryBuffer y)
        {
            int err = _SparseSubtractRaw(z.pointer, x.pointer, y.pointer, x.size, x.indices, x.memorySpace, x.mathDomain, z.size);

            if (err != 0)
            {
                Exceptions.CuBlasKernelExceptionFactory.ThrowException("_SparseSubtract", err);
            }
        }
示例#7
0
        public static void SparseAdd(MemoryBuffer z, SparseMemoryBuffer x, MemoryBuffer y, double alpha)
        {
            int err = _SparseAddRaw(z.pointer, x.pointer, y.pointer, x.size, x.indices, x.memorySpace, x.mathDomain, z.size, alpha);

            if (err != 0)
            {
                Exceptions.CuBlasKernelExceptionFactory.ThrowException("_SparseAddRaw", err);
            }
        }
        public static DiscFileSystem DiagnosticNtfsFileSystem()
        {
            SparseMemoryBuffer buffer       = new SparseMemoryBuffer(4096);
            SparseMemoryStream ms           = new SparseMemoryStream();
            Geometry           diskGeometry = Geometry.FromCapacity(30 * 1024 * 1024);

            DiscUtils.Ntfs.NtfsFileSystem.Format(ms, "", diskGeometry, 0, diskGeometry.TotalSectorsLong);
            var discFs = new DiscUtils.Diagnostics.ValidatingFileSystem <NtfsFileSystem, NtfsFileSystemChecker>(ms);

            discFs.CheckpointInterval = 1;
            discFs.GlobalIOTraceCapturesStackTraces = false;
            return(discFs);
        }
示例#9
0
        public SparseVector(int denseSize, Vector nonZeroIndices, MathDomain mathDomain)
            : base(false, // SparseVector doesn't allocate its memory in its buffer, but it uses the convenience vector this.values
                   nonZeroIndices.memorySpace, mathDomain)
        {
            Debug.Assert(denseSize > nonZeroIndices.Size);

            this.denseSize = denseSize;

            values = new Vector(nonZeroIndices.Size, nonZeroIndices.memorySpace, mathDomain);
            this.nonZeroIndices = nonZeroIndices;

            _buffer = new SparseMemoryBuffer(0, (uint)nonZeroIndices.Size, 0, memorySpace, mathDomain);
            SyncPointers();
        }
示例#10
0
        public void SparseMemoryBufferClear()
        {
            SparseMemoryBuffer memoryBuffer = new SparseMemoryBuffer(10);

            byte[] buffer = new byte[20];

            memoryBuffer.Write(0, buffer, 0, 20);
            Assert.Equal(2, memoryBuffer.AllocatedChunks.Count());
            memoryBuffer.Clear(0, 20);
            Assert.Equal(0, memoryBuffer.AllocatedChunks.Count());

            memoryBuffer.Write(0, buffer, 0, 15);
            Assert.Equal(2, memoryBuffer.AllocatedChunks.Count());
            memoryBuffer.Clear(0, 15);
            Assert.Equal(1, memoryBuffer.AllocatedChunks.Count());
        }
        protected override void Read(byte[] buffer, int offset, out int length)
        {
            base.Read(buffer, offset, out length);

            uint   dataLength = Utilities.ToUInt32LittleEndian(buffer, offset + 0x10);
            ushort dataOffset = Utilities.ToUInt16LittleEndian(buffer, offset + 0x14);

            _indexedFlag = buffer[offset + 0x16];

            if (dataOffset + dataLength > length)
            {
                throw new IOException("Corrupt attribute, data outside of attribute");
            }

            _memoryBuffer = new SparseMemoryBuffer(1024);
            _memoryBuffer.Write(0, buffer, offset + dataOffset, (int)dataLength);
        }
示例#12
0
        public void TargetPath_Works()
        {
            var content = Encoding.UTF8.GetBytes("/var/lib/discutils.so");
            var buffer  = new SparseMemoryBuffer(0x100);

            buffer.Write(0, content, 0, content.Length);

            var symlinkMock = new Mock <Symlink>(MockBehavior.Strict, new Context(), new CatalogNodeId(0), new CatalogFileInfo());

            symlinkMock.Setup(s => s.FileContent).Returns(buffer);

            var symlink = symlinkMock.Object;

            Assert.Equal(@"\var\lib\discutils.so", symlink.TargetPath);

            // Calling .TargetPath twice will excercise the caching code path.
            Assert.Equal(@"\var\lib\discutils.so", symlink.TargetPath);
        }
示例#13
0
 public override SparseStream OpenFile(string path, FileMode mode, FileAccess access)
 {
     if (_files.ContainsKey(path))
     {
         if (mode == FileMode.CreateNew)
         {
             throw new IOException("File already exists");
         }
         return(new SparseMemoryStream(_files[path], access));
     }
     else if (mode == FileMode.Create || mode == FileMode.CreateNew || mode == FileMode.OpenOrCreate || mode == FileMode.Truncate)
     {
         _files[path] = new SparseMemoryBuffer(16 * 1024);
         return(new SparseMemoryStream(_files[path], access));
     }
     else
     {
         throw new FileNotFoundException();
     }
 }
        protected override void Read(byte[] buffer, int offset, out int length)
        {
            base.Read(buffer, offset, out length);

            uint dataLength = Utilities.ToUInt32LittleEndian(buffer, offset + 0x10);
            ushort dataOffset = Utilities.ToUInt16LittleEndian(buffer, offset + 0x14);
            _indexedFlag = buffer[offset + 0x16];

            if (dataOffset + dataLength > length)
            {
                throw new IOException("Corrupt attribute, data outside of attribute");
            }

            _memoryBuffer = new SparseMemoryBuffer(1024);
            _memoryBuffer.Write(0, buffer, offset + dataOffset, (int)dataLength);
        }