Skip to content

Commit

Permalink
Fixing several problems: GCHandle.Free() when it shouldn't; fix type …
Browse files Browse the repository at this point in the history
…casting to GPU BCL methods; finding .LIB file for GPU BCL when tests aren't set up correctly. Comb test works, sort of, but only if 'swaps' variable is an Int32. This is because the meta used by JITER does not correspond to what is layed out via BUFFER. This will need to be fixed, using the meta for the GPU.
  • Loading branch information
kaby76 committed Mar 14, 2018
1 parent 9f14e66 commit fba9328
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
18 changes: 11 additions & 7 deletions Campy.Compiler/inst.cs
Expand Up @@ -1315,7 +1315,7 @@ public override INST Convert(JITER converter, STATE state)
LLVM.SetAlignment(param_buffer, 64); LLVM.SetAlignment(param_buffer, 64);
//LLVM.PositionBuilderAtEnd(Builder, this.Block.BasicBlock); //LLVM.PositionBuilderAtEnd(Builder, this.Block.BasicBlock);
var base_of_parameters = LLVM.BuildPointerCast(Builder, param_buffer, var base_of_parameters = LLVM.BuildPointerCast(Builder, param_buffer,
LLVM.PointerType(LLVM.Int64Type(), 0), "i" + instruction_id++); LLVM.PointerType(LLVM.Int64Type(), 0), "i" + instruction_id++);
for (int i = mr.Parameters.Count - 1; i >= 0; i--) for (int i = mr.Parameters.Count - 1; i >= 0; i--)
{ {
VALUE p = state._stack.Pop(); VALUE p = state._stack.Pop();
Expand All @@ -1341,12 +1341,16 @@ public override INST Convert(JITER converter, STATE state)
//LLVM.PositionBuilderAtEnd(Builder, this.Block.BasicBlock); //LLVM.PositionBuilderAtEnd(Builder, this.Block.BasicBlock);


// Set up call. // Set up call.
var pt = LLVM.BuildPointerCast(Builder, t.V, var pt = LLVM.BuildPtrToInt(Builder, t.V, LLVM.Int64Type(), "i" + instruction_id++);
LLVM.PointerType(LLVM.VoidType(), 0), "i" + instruction_id++); var pp = LLVM.BuildPtrToInt(Builder, param_buffer, LLVM.Int64Type(), "i" + instruction_id++);
var pp = LLVM.BuildPointerCast(Builder, param_buffer, var pr = LLVM.BuildPtrToInt(Builder, return_buffer, LLVM.Int64Type(), "i" + instruction_id++);
LLVM.PointerType(LLVM.VoidType(), 0), "i" + instruction_id++);
var pr = LLVM.BuildPointerCast(Builder, return_buffer, //var pt = LLVM.BuildPointerCast(Builder, t.V,
LLVM.PointerType(LLVM.VoidType(), 0), "i" + instruction_id++); // LLVM.PointerType(LLVM.VoidType(), 0), "i" + instruction_id++);
//var pp = LLVM.BuildPointerCast(Builder, param_buffer,
// LLVM.PointerType(LLVM.VoidType(), 0), "i" + instruction_id++);
//var pr = LLVM.BuildPointerCast(Builder, return_buffer,
// LLVM.PointerType(LLVM.VoidType(), 0), "i" + instruction_id++);


args[0] = pt; args[0] = pt;
args[1] = pp; args[1] = pp;
Expand Down
21 changes: 21 additions & 0 deletions Campy.Compiler/runtime.cs
Expand Up @@ -288,6 +288,8 @@ public static string FindNativeCoreLib()
{ {
} }


// Try something else...

try try
{ {
// Let's try the calling executable directory. // Let's try the calling executable directory.
Expand All @@ -303,6 +305,25 @@ public static string FindNativeCoreLib()
{ {
} }


// Try something else...

try
{
// This could be a unit test in Campy. If that is true, then look in the standard directory structure
// for Campy source/object. It should have actually copied the damn corlib.dll to the output executable directory,
// but someone set up the test wrong. Anyways, assume that the project is up to date, and load from Campy.Runtime.
// ../../../../../Campy.Runtime/Corlib/bin/Debug/net20/
var path_of_campy = @"../../../../../Campy.Runtime/Corlib/bin/Debug/net20";
string full_path_assem = path_of_campy + Path.DirectorySeparatorChar + "corlib.dll";
full_path_assem = Path.GetFullPath(full_path_assem);
Stream stream = new FileStream(full_path_assem, FileMode.Open, FileAccess.Read, FileShare.Read);
stream.Close();
return full_path_assem;
}
catch (Exception e)
{
}

// Fuck. I have no idea. // Fuck. I have no idea.
return null; return null;
} }
Expand Down
4 changes: 2 additions & 2 deletions Campy/Parallel.cs
Expand Up @@ -192,8 +192,8 @@ public static void For(int number_of_threads, KernelType kernel)
} }
finally finally
{ {
handle1.Free(); if (default(GCHandle) != handle1) handle1.Free();
handle2.Free(); if (default(GCHandle) != handle2) handle2.Free();
} }
} }


Expand Down

0 comments on commit fba9328

Please sign in to comment.