Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed bug in bookeeping of allocated/freed objects, fixing bitonic so…
…rt. Clean up.
  • Loading branch information
kaby76 committed Mar 21, 2018
1 parent 686f6ec commit 4ede1e1
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 7,050 deletions.
28 changes: 18 additions & 10 deletions Campy.Compiler/buffers.cs
Expand Up @@ -225,25 +225,32 @@ public void SynchDataStructures()
// "top level" data structures.
Stack<object> nuke = new Stack<object>();

foreach (object k in _copied_to_gpu)
foreach (object back_to_cpu in _copied_to_gpu)
{
if (_never_copy_from_gpu.Contains(k))
if (_never_copy_from_gpu.Contains(back_to_cpu))
continue;

if (_delayed_from_gpu.Contains(k))
if (_delayed_from_gpu.Contains(back_to_cpu))
continue;

if (!_allocated_objects.ContainsKey(k))
if (!_allocated_objects.ContainsKey(back_to_cpu))
continue; // Honestly, this is actually a problem as the object was somehow lost.

if (!_allocated_object_level.ContainsKey(k))
if (!_allocated_object_level.ContainsKey(back_to_cpu))
throw new Exception();

IntPtr v = _allocated_objects[k];
IntPtr gpu_buffer_pointer = _allocated_objects[back_to_cpu];

if (Campy.Utils.Options.IsOn("copy_trace"))
{
System.Console.Write("Copying GPU buffer {0:X}", gpu_buffer_pointer.ToInt64());
System.Console.Write(" back to CPU object " + back_to_cpu);
System.Console.WriteLine();
}

DeepCopyFromImplementation(v, out object to, k.GetType());
DeepCopyFromImplementation(gpu_buffer_pointer, out object to, back_to_cpu.GetType());

nuke.Push(k);
nuke.Push(back_to_cpu);
}

// After copying object back to CPU, we need to delete the GPU copy
Expand All @@ -256,6 +263,7 @@ public void SynchDataStructures()
_copied_to_gpu.Remove(k);
_allocated_objects.Remove(k);
_copied_from_gpu.Remove(k);
_allocated_buffers.Remove(v);
Free(v);
}

Expand Down Expand Up @@ -760,7 +768,7 @@ public unsafe void DeepCopyFromImplementation(IntPtr from_gpu, out object to_cpu

to_cpu = to_array;

if (to_cpu != default(Array))
if (to_cpu != null)
{
if (_delayed_from_gpu.Contains(to_cpu))
{
Expand Down Expand Up @@ -839,7 +847,7 @@ public unsafe void DeepCopyFromImplementation(IntPtr from_gpu, out object to_cpu

_allocated_buffers[from_gpu] = to_cpu;

if (to_cpu != default(Array))
if (to_cpu != null)
{
if (_delayed_from_gpu.Contains(to_cpu))
{
Expand Down
2 changes: 1 addition & 1 deletion Campy.Compiler/cfg.cs
Expand Up @@ -394,7 +394,7 @@ public void OutputEntireGraph()
return;
System.Console.WriteLine("Graph:");
System.Console.WriteLine();
System.Console.WriteLine("List of entries blocks:");
System.Console.WriteLine("List of entry blocks:");
System.Console.WriteLine(new String(' ', 4) + "Node" + new string(' ', 4) + "Method");
foreach (Vertex n in this._entries)
{
Expand Down
24 changes: 0 additions & 24 deletions Campy.Graphs/x

This file was deleted.

0 comments on commit 4ede1e1

Please sign in to comment.