Beispiel #1
0
        /// <inheritdoc/>
        public override TimeSpan MeasureFrom(ProfilingMarker marker)
        {
            using var binding = Accelerator.BindScoped();

            if (!(marker is CudaProfilingMarker startMarker))
            {
                throw new ArgumentException(
                          string.Format(
                              RuntimeErrorMessages.InvalidProfilingMarker,
                              GetType().Name,
                              marker.GetType().Name),
                          nameof(marker));
            }

            // Wait for the markers to complete, then calculate the duration.
            startMarker.Synchronize();
            Synchronize();

            CudaException.ThrowIfFailed(
                CurrentAPI.ElapsedTime(
                    out float milliseconds,
                    startMarker.EventPtr,
                    EventPtr));
            return(TimeSpan.FromMilliseconds(milliseconds));
        }
Beispiel #2
0
        /// <inheritdoc/>
        public override TimeSpan MeasureFrom(ProfilingMarker marker)
        {
            using var binding = Accelerator.BindScoped();

            return((marker is CPUProfilingMarker startMarker)
                ? Timestamp - startMarker.Timestamp
                : throw new ArgumentException(
                       string.Format(
                           RuntimeErrorMessages.InvalidProfilingMarker,
                           GetType().Name,
                           marker.GetType().Name),
                       nameof(marker)));
        }
Beispiel #3
0
        /// <inheritdoc/>
        public override TimeSpan MeasureFrom(ProfilingMarker marker)
        {
            using var binding = Accelerator.BindScoped();

            if (!(marker is CLProfilingMarker startMarker))
            {
                throw new ArgumentException(
                          string.Format(
                              RuntimeErrorMessages.InvalidProfilingMarker,
                              GetType().Name,
                              marker.GetType().Name),
                          nameof(marker));
            }

            // Wait for the markers to complete, then calculate the duration.
            startMarker.Synchronize();
            Synchronize();

            CLException.ThrowIfFailed(
                CurrentAPI.GetEventProfilingInfo(
                    EventPtr,
                    CLProfilingInfo.CL_PROFILING_COMMAND_END,
                    out var endNanoseconds));
            CLException.ThrowIfFailed(
                CurrentAPI.GetEventProfilingInfo(
                    startMarker.EventPtr,
                    CLProfilingInfo.CL_PROFILING_COMMAND_END,
                    out var startNanoseconds));

            // TimeSpan tracks time in ticks, where a single tick represents one hundred
            // nanoseconds, so we need to convert our elasped nanoseconds into ticks.
            //
            // NB: If the start time is later than the end time, reverse the calculation,
            // and then restore the correct signed result.
            bool swapped = false;

            if (endNanoseconds < startNanoseconds)
            {
                Utilities.Swap(ref startNanoseconds, ref endNanoseconds);
                swapped = true;
            }
            var elapsedNanoseconds = endNanoseconds - startNanoseconds;
            var ticks = (long)(elapsedNanoseconds / 100UL);

            if (swapped)
            {
                ticks = -ticks;
            }

            return(new TimeSpan(ticks));
        }
Beispiel #4
0
 /// <inheritdoc/>
 public override TimeSpan MeasureFrom(ProfilingMarker marker) =>
 (marker is CPUProfilingMarker startMarker)