Skip to content

Commit

Permalink
Added new VelocityStream to represent streams in Velocity land.
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rs-mt committed Sep 26, 2023
1 parent a547c95 commit 72826ad
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
76 changes: 76 additions & 0 deletions Src/ILGPU/Runtime/Velocity/VelocityProfilingMarker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2023 ILGPU Project
// www.ilgpu.net
//
// File: VelocityProfilingMarker.cs
//
// This file is part of ILGPU and is distributed under the University of Illinois Open
// Source License. See LICENSE.txt for details.
// ---------------------------------------------------------------------------------------

using ILGPU.Resources;
using System;
using System.Diagnostics;

namespace ILGPU.Runtime.Velocity
{
/// <summary>
/// Represents a point-in-time marker used in Velocity profiling.
/// </summary>
internal sealed class VelocityProfilingMarker : ProfilingMarker
{
#region Instance

internal VelocityProfilingMarker(Accelerator accelerator)
: base(accelerator)
{
#if NET7_0_OR_GREATER
Timestamp = Stopwatch.GetTimestamp();
#else
Timestamp = DateTime.UtcNow.ToBinary();
#endif
}

#endregion

#region Properties

/// <summary>
/// The timestamp this profiling marker was created.
/// </summary>
public long Timestamp { get; private set; }

#endregion

#region Methods

/// <inheritdoc/>
public override void Synchronize() { }

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

return (marker is VelocityProfilingMarker startMarker)
#if NET7_0_OR_GREATER
? Stopwatch.GetElapsedTime(startMarker.Timestamp, Timestamp)
#else
? DateTime.FromBinary(Timestamp) -
DateTime.FromBinary(startMarker.Timestamp)
#endif
: throw new ArgumentException(
string.Format(
RuntimeErrorMessages.InvalidProfilingMarker,
GetType().Name,
marker.GetType().Name),
nameof(marker));
}

/// <inheritdoc/>
protected override void DisposeAcceleratorObject(bool disposing) { }

#endregion
}
}
58 changes: 58 additions & 0 deletions Src/ILGPU/Runtime/Velocity/VelocityStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2022-2023 ILGPU Project
// www.ilgpu.net
//
// File: VelocityStream.cs
//
// This file is part of ILGPU and is distributed under the University of Illinois Open
// Source License. See LICENSE.txt for details.
// ---------------------------------------------------------------------------------------

namespace ILGPU.Runtime.Velocity
{
/// <summary>
/// Represents a velocity stream.
/// </summary>
sealed class VelocityStream : AcceleratorStream
{
#region Instance

/// <summary>
/// Constructs a new Velocity stream.
/// </summary>
/// <param name="accelerator">The associated accelerator.</param>
internal VelocityStream(Accelerator accelerator)
: base(accelerator)
{ }

#endregion

#region Methods

/// <summary>
/// Does not perform any operation.
/// </summary>
public override void Synchronize() { }

/// <inheritdoc/>
protected override ProfilingMarker AddProfilingMarkerInternal()
{
using var binding = Accelerator.BindScoped();
return new VelocityProfilingMarker(Accelerator);
}

#endregion

#region IDisposable

/// <summary>
/// Does not perform any operation.
/// </summary>
protected override void DisposeAcceleratorObject(bool disposing) { }

#endregion
}
}


0 comments on commit 72826ad

Please sign in to comment.