unsafe IntPtr IOperatorDescriptionMarshal.__MarshalAlloc()
    {
        __Native * @ref = UnsafeUtilities.Alloc <__Native>();

        @ref->InputTensor          = InputTensor.__MarshalAlloc();
        @ref->ScaleTensor          = ScaleTensor.__MarshalAlloc();
        @ref->BiasTensor           = BiasTensor.__MarshalAlloc();
        @ref->FusedAddTensor       = (FusedAddTensor != null) ? FusedAddTensor.Value.__MarshalAlloc() : IntPtr.Zero;
        @ref->OutputTensor         = OutputTensor.__MarshalAlloc();
        @ref->OutputMeanTensor     = OutputMeanTensor.__MarshalAlloc();
        @ref->OutputVarianceTensor = OutputVarianceTensor.__MarshalAlloc();
        @ref->Epsilon         = Epsilon;
        @ref->FusedActivation = (FusedActivation != null) ? FusedActivation.Value.__MarshalAlloc() : IntPtr.Zero;

        return(new(@ref));
    }
Example #2
0
    unsafe IntPtr IBindingDescriptionMarshal.__MarshalAlloc()
    {
        __Native * @ref = UnsafeUtilities.Alloc <__Native>();


        BufferBinding.__Native *bindings = UnsafeUtilities.Alloc <BufferBinding.__Native>(Bindings.Length);
        for (int i = 0; i < Bindings.Length; i++)
        {
            Bindings[i].__MarshalTo(ref bindings[i]);
        }

        @ref->Count    = (uint)Bindings.Length;
        @ref->Bindings = new(bindings);

        return(new(@ref));
    }
 internal unsafe void __MarshalTo(ref __Native @ref)
 {
     @ref.ByteStride       = ByteStride;
     @ref.NumArgumentDescs = IndirectArguments?.Length ?? 0;
     if (@ref.NumArgumentDescs > 0)
     {
         @ref.pArgumentDescs = UnsafeUtilities.Alloc <IndirectArgumentDescription>(@ref.NumArgumentDescs);
         fixed(void *indirectArgumentsPtr = &IndirectArguments[0])
         {
             MemoryHelpers.CopyMemory(
                 @ref.pArgumentDescs,
                 (IntPtr)indirectArgumentsPtr,
                 @ref.NumArgumentDescs * sizeof(IndirectArgumentDescription));
         }
     }
     @ref.NodeMask = NodeMask;
 }
Example #4
0
    unsafe IntPtr IOperatorDescriptionMarshal.__MarshalAlloc()
    {
        __Native * @ref = UnsafeUtilities.Alloc <__Native>();

        @ref->InputTensor             = InputTensor.__MarshalAlloc();
        @ref->RoiTensor               = RoiTensor.__MarshalAlloc();
        @ref->BatchIndicesTensor      = BatchIndicesTensor.__MarshalAlloc();
        @ref->OutputTensor            = OutputTensor.__MarshalAlloc();
        @ref->ReductionFunction       = ReductionFunction;
        @ref->InterpolationMode       = InterpolationMode;
        @ref->SpatialScaleX           = SpatialScaleX;
        @ref->SpatialScaleY           = SpatialScaleY;
        @ref->OutOfBoundsInputValue   = OutOfBoundsInputValue;
        @ref->MinimumSamplesPerOutput = MinimumSamplesPerOutput;
        @ref->MaximumSamplesPerOutput = MaximumSamplesPerOutput;

        return(new(@ref));
    }
        unsafe IntPtr IStateSubObjectDescriptionMarshal.__MarshalAlloc(Dictionary <StateSubObject, IntPtr> subObjectLookup)
        {
            __Native *native = (__Native *)Marshal.AllocHGlobal(sizeof(__Native));

            native->pExistingCollection = CppObject.ToCallbackPtr <ID3D12StateObject>(ExistingCollection);
            native->NumExports          = Exports?.Length ?? 0;
            if (native->NumExports > 0)
            {
                var nativeExports = (ExportDescription.__Native *)UnsafeUtilities.Alloc <ExportDescription.__Native>(native->NumExports);
                for (int i = 0; i < native->NumExports; i++)
                {
                    Exports[i].__MarshalTo(ref nativeExports[i]);
                }

                native->pExports = nativeExports;
            }

            return((IntPtr)native);
        }
        unsafe IntPtr IStateSubObjectDescriptionMarshal.__MarshalAlloc(Dictionary <StateSubObject, IntPtr> subObjectLookup)
        {
            __Native *native = (__Native *)Marshal.AllocHGlobal(sizeof(__Native));

            DxilLibrary.__MarshalTo(ref native->DXILLibrary);
            native->NumExports = Exports?.Length ?? 0;
            if (native->NumExports > 0)
            {
                var nativeExports = (ExportDescription.__Native *)UnsafeUtilities.Alloc <ExportDescription.__Native>(native->NumExports);
                for (int i = 0; i < native->NumExports; i++)
                {
                    Exports[i].__MarshalTo(ref nativeExports[i]);
                }

                native->pExports = nativeExports;
            }

            return((IntPtr)native);
        }
    unsafe IntPtr IOperatorDescriptionMarshal.__MarshalAlloc()
    {
        __Native * @ref = UnsafeUtilities.Alloc <__Native>();

        @ref->InputParametersTensor    = InputParametersTensor.__MarshalAlloc();
        @ref->InputFirstMomentTensor   = InputFirstMomentTensor.__MarshalAlloc();
        @ref->InputSecondMomentTensor  = InputSecondMomentTensor.__MarshalAlloc();
        @ref->GradientTensor           = GradientTensor.__MarshalAlloc();
        @ref->TrainingStepTensor       = TrainingStepTensor.__MarshalAlloc();
        @ref->OutputParametersTensor   = OutputParametersTensor.__MarshalAlloc();
        @ref->OutputFirstMomentTensor  = OutputFirstMomentTensor.__MarshalAlloc();
        @ref->OutputSecondMomentTensor = OutputSecondMomentTensor.__MarshalAlloc();
        @ref->LearningRate             = LearningRate;
        @ref->Beta1   = Beta1;
        @ref->Beta2   = Beta2;
        @ref->Epsilon = Epsilon;

        return(new(@ref));
    }
Example #8
0
    unsafe IntPtr IOperatorDescriptionMarshal.__MarshalAlloc()
    {
        __Native * @ref = UnsafeUtilities.Alloc <__Native>();

        @ref->InputTensor  = InputTensor.__MarshalAlloc();
        @ref->FilterTensor = FilterTensor.__MarshalAlloc();
        @ref->BiasTensor   = (BiasTensor != null) ? BiasTensor.Value.__MarshalAlloc() : IntPtr.Zero;
        @ref->OutputTensor = OutputTensor.__MarshalAlloc();
        @ref->Mode         = Mode;
        @ref->Direction    = Direction;

        var dimensionCount = Strides.Length;

        if (Dilations.Length != dimensionCount)
        {
            throw new IndexOutOfRangeException("Dilations must have the same length as Strides.");
        }
        if (StartPadding.Length != dimensionCount)
        {
            throw new IndexOutOfRangeException("StartPadding must have the same length as Strides.");
        }
        if (EndPadding.Length != dimensionCount)
        {
            throw new IndexOutOfRangeException("EndPadding must have the same length as Strides.");
        }
        if (OutputPadding.Length != dimensionCount)
        {
            throw new IndexOutOfRangeException("OutputPadding must have the same length as Strides.");
        }
        @ref->DimensionCount = dimensionCount;

        @ref->Strides         = new(UnsafeUtilities.AllocWithData(Strides));
        @ref->Dilations       = new(UnsafeUtilities.AllocWithData(Dilations));
        @ref->StartPadding    = new(UnsafeUtilities.AllocWithData(StartPadding));
        @ref->EndPadding      = new(UnsafeUtilities.AllocWithData(EndPadding));
        @ref->OutputPadding   = new(UnsafeUtilities.AllocWithData(OutputPadding));
        @ref->GroupCount      = GroupCount;
        @ref->FusedActivation = (FusedActivation != null) ? FusedActivation.Value.__MarshalAlloc() : IntPtr.Zero;

        return(new(@ref));
    }
    unsafe IntPtr IOperatorDescriptionMarshal.__MarshalAlloc()
    {
        __Native * @ref = UnsafeUtilities.Alloc <__Native>();

        @ref->InputCount = InputTensors.Length;

        @ref->InputTensors = IntPtr.Zero;
        if (InputTensors.Length != 0)
        {
            var inputTensorsPtr = UnsafeUtilities.Alloc <TensorDescription.__Native>(InputTensors.Length);
            for (int i = 0; i < InputTensors.Length; i++)
            {
                InputTensors[i].__MarshalTo(ref inputTensorsPtr[i]);
            }
            @ref->InputTensors = new(inputTensorsPtr);
        }

        @ref->OutputTensor = OutputTensor.__MarshalAlloc();
        @ref->Axis         = Axis;

        return(new(@ref));
    }
    unsafe IntPtr IOperatorDescriptionMarshal.__MarshalAlloc()
    {
        __Native * @ref = UnsafeUtilities.Alloc <__Native>();

        @ref->InputTensor  = InputTensor.__MarshalAlloc();
        @ref->OutputTensor = OutputTensor.__MarshalAlloc();
        @ref->PaddingMode  = PaddingMode;
        @ref->PaddingValue = PaddingValue;

        var dimensionCount = StartPadding.Length;

        if (EndPadding.Length != dimensionCount)
        {
            throw new IndexOutOfRangeException("EndPadding must have the same length as StartPadding.");
        }
        @ref->DimensionCount = dimensionCount;

        @ref->StartPadding = new(UnsafeUtilities.AllocWithData(StartPadding));
        @ref->EndPadding   = new(UnsafeUtilities.AllocWithData(EndPadding));

        return(new(@ref));
    }
    unsafe IntPtr ITensorDescriptionMarshal.__MarshalAlloc()
    {
        __Native * @ref = UnsafeUtilities.Alloc <__Native>();

        @ref->DataType       = DataType;
        @ref->Flags          = Flags;
        @ref->DimensionCount = Sizes.Length;
        @ref->PSizes         = UnsafeUtilities.AllocToPointer(Sizes);
        @ref->PStrides       = IntPtr.Zero;
        if (Strides != null)
        {
            if (Strides.Length != Sizes.Length)
            {
                throw new IndexOutOfRangeException("Strides must have the same length as Sizes.");
            }
            @ref->PStrides = UnsafeUtilities.AllocToPointer(Strides);
        }
        @ref->TotalTensorSizeInBytes        = TotalTensorSizeInBytes;
        @ref->GuaranteedBaseOffsetAlignment = GuaranteedBaseOffsetAlignment;

        return(new(@ref));
    }
    unsafe IntPtr IOperatorDescriptionMarshal.__MarshalAlloc()
    {
        __Native * @ref = UnsafeUtilities.Alloc <__Native>();

        @ref->InputTensor             = (InputTensor != null) ? InputTensor.Value.__MarshalAlloc() : IntPtr.Zero;
        @ref->InputGradientTensor     = InputGradientTensor.__MarshalAlloc();
        @ref->RoiTensor               = RoiTensor.__MarshalAlloc();
        @ref->BatchIndicesTensor      = BatchIndicesTensor.__MarshalAlloc();
        @ref->OutputGradientTensor    = (OutputGradientTensor != null) ? OutputGradientTensor.Value.__MarshalAlloc() : IntPtr.Zero;
        @ref->OutputROIGradientTensor = (OutputROIGradientTensor != null) ? OutputROIGradientTensor.Value.__MarshalAlloc() : IntPtr.Zero;
        @ref->ReductionFunction       = ReductionFunction;
        @ref->InterpolationMode       = InterpolationMode;
        @ref->SpatialScaleX           = SpatialScaleX;
        @ref->SpatialScaleY           = SpatialScaleY;
        @ref->InputPixelOffset        = InputPixelOffset;
        @ref->OutputPixelOffset       = OutputPixelOffset;
        @ref->MinimumSamplesPerOutput = MinimumSamplesPerOutput;
        @ref->MaximumSamplesPerOutput = MaximumSamplesPerOutput;
        @ref->AlignRegionsToCorners   = AlignRegionsToCorners;

        return(new(@ref));
    }
        internal unsafe void __MarshalTo(ref __Native @ref)
        {
            @ref.Type          = Type;
            @ref.NumSubobjects = SubObjects?.Length ?? 0;
            if (@ref.NumSubobjects > 0)
            {
                var subObjectLookup  = new Dictionary <StateSubObject, IntPtr>();
                var nativeSubObjects = (StateSubObject.__Native *)UnsafeUtilities.Alloc <StateSubObject.__Native>(@ref.NumSubobjects);

                // Create lookup table first
                for (int i = 0; i < @ref.NumSubobjects; i++)
                {
                    subObjectLookup.Add(SubObjects[i], new IntPtr(&nativeSubObjects[i]));
                }

                for (int i = 0; i < @ref.NumSubobjects; i++)
                {
                    SubObjects[i].__MarshalTo(ref nativeSubObjects[i], subObjectLookup);
                }

                @ref.pSubobjects = nativeSubObjects;
            }
        }
    unsafe IntPtr IOperatorDescriptionMarshal.__MarshalAlloc()
    {
        __Native * @ref = UnsafeUtilities.Alloc <__Native>();

        @ref->InputTensor          = InputTensor.__MarshalAlloc();
        @ref->InputGradientTensor  = InputGradientTensor.__MarshalAlloc();
        @ref->OutputGradientTensor = OutputGradientTensor.__MarshalAlloc();

        var dimensionCount = Strides.Length;

        if (WindowSize.Length != dimensionCount)
        {
            throw new IndexOutOfRangeException("WindowSize must have the same length as Strides.");
        }
        if (StartPadding.Length != dimensionCount)
        {
            throw new IndexOutOfRangeException("StartPadding must have the same length as Strides.");
        }
        if (EndPadding.Length != dimensionCount)
        {
            throw new IndexOutOfRangeException("EndPadding must have the same length as Strides.");
        }
        if (Dilations.Length != dimensionCount)
        {
            throw new IndexOutOfRangeException("Dilations must have the same length as Strides.");
        }
        @ref->DimensionCount = dimensionCount;

        @ref->Strides      = new(UnsafeUtilities.AllocWithData(Strides));
        @ref->WindowSize   = new(UnsafeUtilities.AllocWithData(WindowSize));
        @ref->StartPadding = new(UnsafeUtilities.AllocWithData(StartPadding));
        @ref->EndPadding   = new(UnsafeUtilities.AllocWithData(EndPadding));
        @ref->Dilations    = new(UnsafeUtilities.AllocWithData(Dilations));

        return(new(@ref));
    }