-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new VelocityStream to represent streams in Velocity land.
- Loading branch information
Showing
2 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
||
|