Browse Source

gcc: Use the `heap_allocated' attribute in examples.

* gcc-plugin/examples/matrix-mult.c (__heap): New macro.
  (main): Use it to allocate A, B, and C.

* gcc-plugin/examples/cholesky/cholesky.c (dw_cholesky): Turn `matA'
  into a 3-dimension matrix.  Adjust `register' pragma accordingly.
  (main): Turn `bmat' into a 3-dimension array, and remove calls to
  `starpu_malloc' and `starpu_free'.
Ludovic Courtès 12 years ago
parent
commit
8b7218fb0b
2 changed files with 11 additions and 18 deletions
  1. 4 12
      gcc-plugin/examples/cholesky/cholesky.c
  2. 7 6
      gcc-plugin/examples/matrix-mult.c

+ 4 - 12
gcc-plugin/examples/cholesky/cholesky.c

@@ -25,7 +25,8 @@
  *	code to bootstrap the factorization
  *	and construct the DAG
  */
-static void dw_cholesky(unsigned nblocks, unsigned size, unsigned ld, float *matA[nblocks][nblocks])
+static void dw_cholesky(unsigned nblocks, unsigned size, unsigned ld,
+			float matA[nblocks][nblocks][size/nblocks * size/nblocks])
 {
 	struct timeval start;
 	struct timeval end;
@@ -36,7 +37,7 @@ static void dw_cholesky(unsigned nblocks, unsigned size, unsigned ld, float *mat
 
         for(x = 0; x < nblocks ;  x++) {
                 for (y = 0; y < nblocks; y++) {
-#pragma starpu register matA[x][y] size/nblocks*size/nblocks
+#pragma starpu register matA[x][y]
 		}
         }
 
@@ -112,14 +113,13 @@ int main(int argc, char **argv)
 
         starpu_helper_cublas_init();
 
-	float *bmat[nblocks][nblocks] __heap;
+	float bmat[nblocks][nblocks][BLOCKSIZE * BLOCKSIZE] __heap;
 
 	unsigned i,j,x,y;
         for(x=0 ; x<nblocks ; x++)
 	{
                 for(y=0 ; y<nblocks ; y++)
 		{
-                        starpu_malloc((void **)&bmat[x][y], BLOCKSIZE*BLOCKSIZE*sizeof(float));
 			for (i = 0; i < BLOCKSIZE; i++)
 			{
 				for (j = 0; j < BLOCKSIZE; j++)
@@ -247,14 +247,6 @@ int main(int argc, char **argv)
 		}
         }
 
-        for(x=0 ; x<nblocks ; x++)
-	{
-                for(y=0 ; y<nblocks ; y++)
-		{
-                        starpu_free((void *)bmat[x][y]);
-		}
-	}
-
         starpu_helper_cublas_shutdown();
 #pragma starpu shutdown
 

+ 7 - 6
gcc-plugin/examples/matrix-mult.c

@@ -1,5 +1,5 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
-   Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
+   Copyright (C) 2011, 2012 Inria
    Copyright (C) 2010 Sylvain Gault
 
    StarPU is free software; you can redistribute it and/or modify
@@ -19,6 +19,9 @@
 # error must be compiled with the StarPU GCC plug-in
 #endif
 
+/* Convenience macro.  */
+#define __heap __attribute__ ((__heap_allocated__))
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
@@ -163,11 +166,9 @@ main (int argc, char **argv)
 
   gettimeofday (&start_all, NULL);
 
-  float *A, *B, *C;
-
-  A = malloc (zdim * ydim * sizeof *A);
-  B = malloc (xdim * zdim * sizeof *B);
-  C = malloc (xdim * ydim * sizeof *C);
+  float A[zdim * ydim] __heap;
+  float B[xdim * zdim] __heap;
+  float C[xdim * ydim] __heap;
 
   srand (time (NULL));
   for (i = 0; i < zdim * ydim; i++)