Skip to content

Commit

Permalink
update malloc sample (new double[] instead of malloc)
Browse files Browse the repository at this point in the history
  • Loading branch information
Regis Portalez committed Feb 1, 2019
1 parent aff612e commit 3d36f0c
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions HybridizerBasicSamples_CUDA100/1.Simple/Malloc/Malloc/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,8 @@ namespace Malloc
/// </summary>
unsafe class Program
{
[IntrinsicFunction("malloc")]
public static void* malloc(int size)
{
return Marshal.AllocHGlobal(size).ToPointer();
}

[IntrinsicFunction("free")]
public static void free(void* ptr)
{
Marshal.Release(new IntPtr(ptr));
}

[Kernel]
public static double apply(double* stencil, double[] src, int i)
public static double apply(double[] stencil, double[] src, int i)
{
double res = 0.0;
for(int k = -4; k <= 4; ++k)
Expand All @@ -41,7 +29,7 @@ public static double apply(double* stencil, double[] src, int i)
[EntryPoint]
public static void test(double[] dest, double[] src, int N)
{
double* stencil = (double*)malloc(9 * sizeof(double));
double[] stencil = new double[9];
stencil[0] = -4.0;
stencil[1] = -3.0;
stencil[2] = -2.0;
Expand All @@ -55,7 +43,6 @@ public static void test(double[] dest, double[] src, int N)
{
dest[k] = apply(stencil, src, k);
}
free(stencil);
}

static void Main(string[] args)
Expand Down

0 comments on commit 3d36f0c

Please sign in to comment.