Table of Contents

Interface IFenceInjectionService

Namespace
DotCompute.Abstractions.Memory
Assembly
DotCompute.Abstractions.dll

Service interface for fence injection during kernel compilation.

public interface IFenceInjectionService

Remarks

This interface provides the bridge between IMemoryOrderingProvider (which queues fence requests) and the kernel compiler (which injects fence instructions).

Usage Pattern:

// 1. Application code requests fences via IMemoryOrderingProvider
orderingProvider.InsertFence(FenceType.Device, FenceLocation.Release);

// 2. Kernel compiler queries pending fences during compilation var fences = fenceService.GetPendingFences(); foreach (var fence in fences) { InjectFence(ptxCode, fence); }

// 3. Clear processed fences fenceService.ClearPendingFences();

Thread Safety: Implementations must be thread-safe as fence requests may be queued from multiple threads while compilation proceeds concurrently.

Properties

PendingFenceCount

Gets the number of pending fence requests.

int PendingFenceCount { get; }

Property Value

int

Methods

ClearPendingFences()

Clears all pending fence requests after they have been processed.

void ClearPendingFences()

Remarks

Call this after successfully compiling a kernel to avoid re-injecting the same fences in subsequent compilations.

GetFencesForLocation(bool, bool, bool, bool)

Gets fences appropriate for the specified location in kernel code.

IReadOnlyList<FenceRequest> GetFencesForLocation(bool atEntry = false, bool atExit = false, bool afterWrites = false, bool beforeReads = false)

Parameters

atEntry bool

Include fences marked for kernel entry.

atExit bool

Include fences marked for kernel exit.

afterWrites bool

Include fences marked for after write operations.

beforeReads bool

Include fences marked for before read operations.

Returns

IReadOnlyList<FenceRequest>

Filtered collection of fence requests matching the criteria.

GetPendingFences()

Gets all pending fence requests that should be injected during the next compilation.

IReadOnlyList<FenceRequest> GetPendingFences()

Returns

IReadOnlyList<FenceRequest>

A collection of pending fence requests, ordered by request time.

Remarks

This method returns a snapshot of pending fences. The returned collection is not affected by subsequent calls to QueueFence(FenceRequest) or ClearPendingFences().

QueueFence(FenceRequest)

Queues a new fence request for injection during the next kernel compilation.

void QueueFence(FenceRequest request)

Parameters

request FenceRequest

The fence request to queue.