Skip to content

Commit

Permalink
Refined peer-access implementation of CPUAccelerator.
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rs-mt committed Nov 26, 2022
1 parent e13209b commit 35e7f72
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Src/ILGPU/Runtime/CPU/CPUAccelerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2016-2021 ILGPU Project
// Copyright (c) 2016-2022 ILGPU Project
// www.ilgpu.net
//
// File: CPUAccelerator.cs
Expand All @@ -12,6 +12,7 @@
using ILGPU.Backends;
using ILGPU.Backends.IL;
using ILGPU.Resources;
using ILGPU.Runtime.Velocity;
using System;
using System.Diagnostics;
using System.Reflection;
Expand Down Expand Up @@ -240,12 +241,13 @@ protected override void OnUnbind() { }

/// <summary cref="Accelerator.CanAccessPeerInternal(Accelerator)"/>
protected override bool CanAccessPeerInternal(Accelerator otherAccelerator) =>
otherAccelerator as CPUAccelerator != null;
otherAccelerator is CPUAccelerator ||
otherAccelerator is VelocityAccelerator;

/// <summary cref="Accelerator.EnablePeerAccessInternal(Accelerator)"/>
protected override void EnablePeerAccessInternal(Accelerator otherAccelerator)
{
if (otherAccelerator as CPUAccelerator == null)
if (!CanAccessPeerInternal(otherAccelerator))
{
throw new InvalidOperationException(
RuntimeErrorMessages.CannotEnablePeerAccessToOtherAccelerator);
Expand All @@ -256,7 +258,7 @@ protected override void EnablePeerAccessInternal(Accelerator otherAccelerator)
protected override void DisablePeerAccessInternal(
Accelerator otherAccelerator) =>
Debug.Assert(
otherAccelerator is CPUAccelerator,
CanAccessPeerInternal(otherAccelerator),
"Invalid EnablePeerAccess method");

#endregion
Expand Down Expand Up @@ -472,7 +474,7 @@ protected override int EstimateGroupSizeInternal(
#region Page Lock Scope

/// <inheritdoc/>
protected unsafe override PageLockScope<T> CreatePageLockFromPinnedInternal<T>(
protected override PageLockScope<T> CreatePageLockFromPinnedInternal<T>(
IntPtr pinned,
long numElements)
{
Expand Down

0 comments on commit 35e7f72

Please sign in to comment.