コード例 #1
0
ファイル: CudaDecoder.cs プロジェクト: anthrax3/Flame
        public override BoxPointer LoadBoxPointer(BoxPointer pointer)
        {
            var basePtr = (CUdeviceptr)(SizeT)Marshal.ReadIntPtr(pointer.ToIntPtr(this));

            return(DownloadBox(basePtr));
        }
コード例 #2
0
ファイル: CudaDecoder.cs プロジェクト: anthrax3/Flame
        public override bool TryDecodePrimitive(BoxPointer pointer, IType type, out object obj)
        {
            if (pointer.BasePointer == 0)
            {
                obj = null;
                return(true);
            }
            else if (type == TypeSystem.Int8)
            {
                obj = (sbyte)Marshal.ReadByte(pointer.ToIntPtr(this));
                return(true);
            }
            else if (type == TypeSystem.UInt8)
            {
                obj = Marshal.ReadByte(pointer.ToIntPtr(this));
                return(true);
            }
            else if (type == TypeSystem.Int16)
            {
                obj = Marshal.ReadInt16(pointer.ToIntPtr(this));
                return(true);
            }
            else if (type == TypeSystem.UInt16)
            {
                obj = (ushort)Marshal.ReadInt16(pointer.ToIntPtr(this));
                return(true);
            }
            else if (type == TypeSystem.Char)
            {
                obj = (char)Marshal.ReadInt16(pointer.ToIntPtr(this));
                return(true);
            }
            else if (type == TypeSystem.Int32)
            {
                obj = Marshal.ReadInt32(pointer.ToIntPtr(this));
                return(true);
            }
            else if (type == TypeSystem.UInt32)
            {
                obj = (uint)Marshal.ReadInt32(pointer.ToIntPtr(this));
                return(true);
            }
            else if (type == TypeSystem.Int64)
            {
                obj = Marshal.ReadInt64(pointer.ToIntPtr(this));
                return(true);
            }
            else if (type == TypeSystem.UInt64)
            {
                obj = (ulong)Marshal.ReadInt64(pointer.ToIntPtr(this));
                return(true);
            }
            else if (type == TypeSystem.NaturalInt)
            {
                obj = Marshal.ReadIntPtr(pointer.ToIntPtr(this));
                return(true);
            }
            else if (type == TypeSystem.NaturalUInt ||
                     type == TypeSystem.Float32 ||
                     type == TypeSystem.Float64)
            {
                throw new System.NotImplementedException();
            }
            else if (ClrArrayType.IsArrayType(type))
            {
                int rank;
                ClrArrayType.TryGetArrayRank(type, out rank);
                IType elementType;
                ClrArrayType.TryGetArrayElementType(type, out elementType);

                // Decode array dimensions.
                var ptr  = pointer.ToIntPtr(this);
                var dims = new long[rank];
                for (int i = 0; i < rank; i++)
                {
                    dims[i] = Marshal.ReadInt64(ptr);
                    ptr    += sizeof(long);
                }

                // Create a host array.
                var arr = Array.CreateInstance(ToClr(type), dims);
                obj = arr;
                RegisterDecoded(pointer, arr);

                // Decode array contents.
                DecodeArrayContents(pointer, elementType, dims, arr);
                return(true);
            }
            else
            {
                // TODO: handle delegates.
                obj = null;
                return(false);
            }
        }