Skip to content

Commit

Permalink
Adapted CPUMemoryBuffer to support new Velocity buffers.
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rs-mt committed Sep 26, 2023
1 parent 63433e3 commit c5ca0bb
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Src/ILGPU/Runtime/CPU/CPUMemoryBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ public static void CPUCopyFrom<T>(
in ArrayView<T> targetView)
where T : unmanaged
{
if (targetView.GetAcceleratorType() != AcceleratorType.CPU)
switch (targetView.GetAcceleratorType())
{
case AcceleratorType.CPU:
case AcceleratorType.Velocity:
break;
default:
throw new NotSupportedException(
RuntimeErrorMessages.NotSupportedTargetAccelerator);
}
Expand All @@ -107,6 +111,7 @@ public static void CPUCopyFrom<T>(
switch (sourceView.GetAcceleratorType())
{
case AcceleratorType.CPU:
case AcceleratorType.Velocity:
// Copy from CPU to CPU
CPUCopyToCPU(
ref sourceView.LoadEffectiveAddress(),
Expand Down Expand Up @@ -157,10 +162,14 @@ public static void CPUCopyTo<T>(
in ArrayView<T> targetView)
where T : unmanaged
{
if (sourceView.GetAcceleratorType() != AcceleratorType.CPU)
switch (sourceView.GetAcceleratorType())
{
throw new NotSupportedException(
RuntimeErrorMessages.NotSupportedTargetAccelerator);
case AcceleratorType.CPU:
case AcceleratorType.Velocity:
break;
default:
throw new NotSupportedException(
RuntimeErrorMessages.NotSupportedTargetAccelerator);
}
if (targetView.Length > sourceView.Length)
throw new ArgumentOutOfRangeException(nameof(sourceView));
Expand All @@ -172,6 +181,7 @@ public static void CPUCopyTo<T>(
switch (targetView.GetAcceleratorType())
{
case AcceleratorType.CPU:
case AcceleratorType.Velocity:
// Copy from CPU to CPU
CPUCopyToCPU(
ref sourceView.LoadEffectiveAddress(),
Expand Down Expand Up @@ -223,11 +233,14 @@ public static void CPUCopy<T>(
in ArrayView<T> targetView)
where T : unmanaged
{
if (sourceView.GetAcceleratorType() == AcceleratorType.CPU)
if (sourceView.GetAcceleratorType() == AcceleratorType.CPU ||
sourceView.GetAcceleratorType() == AcceleratorType.Velocity)
{
CPUCopyTo(stream, sourceView, targetView);
}
else if (targetView.GetAcceleratorType() == AcceleratorType.CPU)
else if (
targetView.GetAcceleratorType() == AcceleratorType.CPU ||
sourceView.GetAcceleratorType() == AcceleratorType.Velocity)
{
CPUCopyFrom(stream, sourceView, targetView);
}
Expand Down

0 comments on commit c5ca0bb

Please sign in to comment.