internal static unsafe JobHandle ScheduleXO <T>(this T jobData,
                                                        BurstTensorData pinX,
                                                        int offsetX,
                                                        BurstTensorData pinO,
                                                        int offsetO,
                                                        FencingHelperMode fencingMode = FencingHelperMode.UpdateResourcesFencesOnScheduling)
            where T : struct, IJob, BurstCPUOps.IJobResourceDeclarationXO
        {
            var fenceBeforeJobStart = GetFenceBeforeJobStartXO(pinX, pinO);

            JobHandle jobFence;

            fixed(float *
                  ptrX = &pinX.array[pinX.offset],
                  ptrO = &pinO.array[pinO.offset])
            {
                jobFence = ScheduleXOInternal(jobData, fenceBeforeJobStart, ptrX + offsetX, ptrO + offsetO);
            }

            if (fencingMode == FencingHelperMode.UpdateResourcesFencesOnScheduling)
            {
                jobFence.SetXOFences(pinX, pinO);
            }

            return(jobFence);
        }
Exemple #2
0
            public JobHandle ScheduleXSBO(BurstTensorData pinX, BurstTensorData pinS, BurstTensorData pinB, BurstTensorData pinO, int arrayLength, int innerBatchCount, FencingHelperMode fencingMode = FencingHelperMode.UpdateResourcesFencesOnScheduling)
            {
                bool AHalf = pinX.array.Type == DataType.Half;
                bool WHalf = pinS.array.Type == DataType.Half;
                bool BHalf = pinB.array.Type == DataType.Half;
                bool OHalf = pinO.array.Type == DataType.Half;

                UnityEngine.Assertions.Assert.AreEqual(AHalf, OHalf);
                UnityEngine.Assertions.Assert.AreEqual(WHalf, BHalf);
                if (AHalf && WHalf)
                {
                    var job = new DepthwiseConv2DJob_Full_Half();
                    job.data = this;
                    return(job.ScheduleXSBO(pinX, pinS, pinB, pinO, arrayLength, innerBatchCount, fencingMode));
                }
                else if (!AHalf && WHalf)
                {
                    var job = new DepthwiseConv2DJob_ActAsFloat_WeightAsHalf();
                    job.data = this;
                    return(job.ScheduleXSBO(pinX, pinS, pinB, pinO, arrayLength, innerBatchCount, fencingMode));
                }
                else if (!AHalf && !WHalf)
                {
                    var job = new DepthwiseConv2DJob_Full_Float();
                    job.data = this;
                    return(job.ScheduleXSBO(pinX, pinS, pinB, pinO, arrayLength, innerBatchCount, fencingMode));
                }
                else //if (AHalf && !WHalf)
                {
                    UnityEngine.Assertions.Assert.IsTrue(false, "DepthwiseConv2DJob does not support activation as half while weights are floats.");
                    return(new JobHandle());
                }
            }
        internal static unsafe JobHandle ScheduleXO <T>(this T jobData,
                                                        BurstTensorData pinX,
                                                        FencedMemoryAlloc pinO,
                                                        int arrayLength, int innerloopBatchCount,
                                                        FencingHelperMode fencingMode = FencingHelperMode.UpdateResourcesFencesOnScheduling)
            where T : struct, IJobParallelFor, BurstCPUOps.IJobResourceDeclarationXO
        {
            var fenceBeforeJobStart = GetFenceBeforeJobStartXO(pinX, pinO);

            JobHandle jobFence;

            fixed(float *
                  ptrX = &pinX.array[pinX.offset])
            {
                var ptrO = pinO.data;

                jobFence = ScheduleXOInternal(jobData, fenceBeforeJobStart, ptrX, ptrO, arrayLength, innerloopBatchCount);
            }

            if (fencingMode == FencingHelperMode.UpdateResourcesFencesOnScheduling)
            {
                jobFence.SetXOFences(pinX, pinO);
            }

            return(jobFence);
        }
        internal static unsafe JobHandle ScheduleXBO <T>(this T jobData,
                                                         BurstTensorData pinX,
                                                         BurstTensorData pinB,
                                                         BurstTensorData pinO,
                                                         int arrayLength, int innerloopBatchCount,
                                                         FencingHelperMode fencingMode = FencingHelperMode.UpdateResourcesFencesOnScheduling)
            where T : struct, IJobParallelFor, BurstCPUOps.IJobResourceDeclarationXBO
        {
            var fenceBeforeJobStart = GetFenceBeforeJobStartXBO(pinX, pinB, pinO);

            JobHandle jobFence;

            {
                void *ptrX = pinX.array.RawAddressAt(pinX.offset);
                void *ptrB = pinB.array.RawAddressAt(pinB.offset);
                void *ptrO = pinO.array.RawAddressAt(pinO.offset);
                jobFence = ScheduleXBOInternal(jobData, fenceBeforeJobStart, ptrX, ptrB, ptrO, arrayLength, innerloopBatchCount);
            }

            if (fencingMode == FencingHelperMode.UpdateResourcesFencesOnScheduling)
            {
                jobFence.SetXBOFences(pinX, pinB, pinO);
            }

            return(jobFence);
        }
        public void ScheduleO <T>(
            T jobData,
            BurstTensorData pinO, int offsetO,
            int arrayLength, int innerloopBatchCount)
            where T : struct, IJobParallelFor, BurstCPUOps.IJobResourceDeclarationO
        {
            Assert.IsTrue(pinO == outputResource);
            var jobFence = jobData.ScheduleO(pinO, offsetO, arrayLength, innerloopBatchCount, BurstSchedulingHelper.FencingHelperMode.CustomResourcesFencesHandling);

            AddJobDependencyToOutputFence(jobFence);
        }
        public void ScheduleXO <T>(
            T jobData,
            BurstTensorData pinX, int offsetX,
            BurstTensorData pinO, int offsetO)
            where T : struct, IJob, BurstCPUOps.IJobResourceDeclarationXO
        {
            Assert.IsTrue(pinO == outputResource);
            var jobFence = jobData.ScheduleXO(pinX, offsetX, pinO, offsetO, BurstSchedulingHelper.FencingHelperMode.CustomResourcesFencesHandling);

            TrackJobReadDependencies(pinX, jobFence);
            AddJobDependencyToOutputFence(jobFence);
        }
        //For now only CopyStrideJobHelper and tests need ParallelJobsContext. If this code need to be duplicated for more case in the future:
        //- Maybe add generic version by having CopyStrideJobHelper and other helper struct implement an interface (but beware of GC).
        //- Or make ParallelJobsContext partial and code generated by jobs template.
        public JobHandle ScheduleXO(
            BurstCPUOps.CopyStrideJobHelper jobData,//See comment above.
            BurstTensorData pinX, int offsetX,
            BurstTensorData pinO, int offsetO)
        {
            Assert.IsTrue(pinO == outputResource);
            var jobFence = jobData.ScheduleXO(pinX, offsetX, pinO, offsetO, BurstSchedulingHelper.FencingHelperMode.CustomResourcesFencesHandling);

            TrackJobReadDependencies(pinX, jobFence);
            AddJobDependencyToOutputFence(jobFence);
            return(jobFence);
        }
        public JobHandle ScheduleXO <T>(
            T jobData,
            BurstTensorData pinX,
            BurstTensorData pinO,
            int arrayLength, int innerloopBatchCount)
            where T : struct, IJobParallelFor, BurstCPUOps.IJobResourceDeclarationXO
        {
            Assert.IsTrue(pinO == outputResource);
            var jobFence = jobData.ScheduleXO(pinX, pinO, arrayLength, innerloopBatchCount, BurstSchedulingHelper.FencingHelperMode.CustomResourcesFencesHandling);

            TrackJobReadDependencies(pinX, jobFence);
            AddJobDependencyToOutputFence(jobFence);
            return(jobFence);
        }
        internal static unsafe JobHandle ScheduleO <T>(this T jobData,
                                                       BurstTensorData pinO,
                                                       FencingHelperMode fencingMode = FencingHelperMode.UpdateResourcesFencesOnScheduling)
            where T : struct, IJob, BurstCPUOps.IJobResourceDeclarationO
        {
            var fenceBeforeJobStart = pinO.reuse;

            JobHandle jobFence;

            fixed(float *ptrO = &pinO.array[pinO.offset])
            {
                jobFence = ScheduleOInternal(jobData, fenceBeforeJobStart, ptrO);
            }

            if (fencingMode == FencingHelperMode.UpdateResourcesFencesOnScheduling)
            {
                pinO.fence = jobFence;
            }

            return(jobFence);
        }
        internal static unsafe JobHandle ScheduleXO <T>(this T jobData,
                                                        BurstTensorData pinX,
                                                        BurstTensorData pinO,
                                                        FencingHelperMode fencingMode = FencingHelperMode.UpdateResourcesFencesOnScheduling)
            where T : struct, IJob, BurstCPUOps.IJobResourceDeclarationXO
        {
            var fenceBeforeJobStart = GetFenceBeforeJobStartXO(pinX, pinO);

            JobHandle jobFence;

            {
                void *ptrX = pinX.array.RawAddressAt(pinX.offset);
                void *ptrO = pinO.array.RawAddressAt(pinO.offset);
                jobFence = ScheduleXOInternal(jobData, fenceBeforeJobStart, ptrX, ptrO);
            }

            if (fencingMode == FencingHelperMode.UpdateResourcesFencesOnScheduling)
            {
                jobFence.SetXOFences(pinX, pinO);
            }

            return(jobFence);
        }
        internal static unsafe JobHandle ScheduleO <T>(this T jobData,
                                                       BurstTensorData pinO,
                                                       int offsetO,
                                                       int arrayLength, int innerloopBatchCount,
                                                       FencingHelperMode fencingMode = FencingHelperMode.UpdateResourcesFencesOnScheduling)
            where T : struct, IJobParallelFor, BurstCPUOps.IJobResourceDeclarationO
        {
            var fenceBeforeJobStart = pinO.reuse;

            JobHandle jobFence;

            {
                void *ptrO = pinO.array.RawAddressAt(pinO.offset + offsetO);
                jobFence = ScheduleOInternal(jobData, fenceBeforeJobStart, ptrO, arrayLength, innerloopBatchCount);
            }

            if (fencingMode == FencingHelperMode.UpdateResourcesFencesOnScheduling)
            {
                pinO.fence = jobFence;
            }

            return(jobFence);
        }