This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[hsa] Better workaround in locating the file with HSAIL


Hi,

this patch has been mostly written by Ganesh and has only slightly
been then amended by me.  It improves the current workaround which we
use to locate HSAIL until we can link it properly by attempting to
derive the file name from the current input name.  More details in the
README.hsa changes.  Committed to the branch.

Thanks,

Martin


2014-10-24  Ganesh Gopalasubramanian  <Ganesh.Gopalasubramanian@amd.com>
	    Martin Jambor  <mjambor@suse.cz>

gcc/
	* README.hsa: Removed the part about extracting the HSA ELF sections.
	* hsa-gen.c (wrap_hsa): Deduce the file name and pass it to libgomp.

libgomp/
	* hsaokra.c (__hsa_launch_kernel): Do not segfault if file cannot be
	opened.

diff --git a/gcc/ChangeLog.hsa b/gcc/ChangeLog.hsa
index 04ecd06..8e592e7 100644
--- a/gcc/ChangeLog.hsa
+++ b/gcc/ChangeLog.hsa
@@ -1,3 +1,9 @@
+2014-10-24  Martin Jambor  <mjambor@suse.cz>
+
+	* README.hsa: Removed the part about extracting the HSA ELF sections.
+	* hsa-gen.c (wrap_hsa): Deduce the file name and pass it to libgomp.
+
+
 2014-10-24  Martin Jambor  <mjambor@suse.cz>
 
 	* hsa.h (hsa_symbol): Renamed offset to directive_offset.  Updated all
diff --git a/gcc/README.hsa b/gcc/README.hsa
index e41d762..a15f4ec 100644
--- a/gcc/README.hsa
+++ b/gcc/README.hsa
@@ -65,8 +65,8 @@ have not tested anything else):
    $ git clone 'https://github.com/HSAFoundation/Okra-Interface-to-HSA-Device'
    $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/testhsa/Okra-Interface-to-HSA-Device/okra/dist/bin
 
-   These and the steps below were tested with revision 4c4dc65 from
-   August 14 2014.
+   These and the steps below were tested with revision d457e8c from
+   October 6 2014.
 
    You can now also try the sample check shipped with OKRA to test
    whether your setup works.  Go into directory
@@ -135,19 +135,21 @@ example, however, it reports success like this:
 
 omp_veccopy.c:15:12: note: Parallel construct will be turned into an HSA kernel
 
-The next step is to extract the HSA ELF sections to a 32-bit file
-called hsakernel.o.  OKRA currently handles 32-bit ELF files only.
-This step is currently necessary but there is ongoing work aimed at
-eliminating it (yes, it means that currently there is no way of
-combining HSA from different compilation units):
-
-  $ objcopy -O elf32-i386 -j hsa_data -j hsa_code -j hsa_operand omp_veccopy.o hsakernel.o
-  
 Now link the program as usual, providing a path to libgomp of the
 installed hsa branch gcc:
 
   $ $HOME/gcc/hsa/inst/bin/gcc omp_veccopy.o -lm -fopenmp -Wl,-rpath,$HOME/gcc/hsa/inst/lib64 -o omp_veccopy
 
+The reason why it is necessary to proceed in two steps rather than do
+both at once is that at this point, HSA run time will expect the HSA
+kernel in object file with the same name as the input file, only with
+the suffix changed to .o, in the current working directory when
+executing the program.  If you use LTO, there is no input file (such
+as when compiling from standard input) or the input file name does not
+have a dot in it, run-time will expect the HSA ELF sections in a file
+called hsakernel.o.  This is a temporary situation and will be fixed,
+of course.
+
 Assuming you have all necessary libraries in your LD_LIBRARY_PATH, you
 can now run the example:
 
diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 05e3015..1080ea2 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -2102,8 +2102,25 @@ wrap_hsa (void)
 	    str = build_string_literal (1, "");
 	    bool kern_p = lookup_attribute ("hsakernel",
 					    DECL_ATTRIBUTES (fndecl));
+	    if (!in_lto_p && main_input_filename)
+	      {
+		char *filename;
+		const char *part = strrchr (main_input_filename, '/');
+		if (!part)
+		  part = main_input_filename;
+		asprintf (&filename, "%s", part);
+		char* extension = strchr (filename, '.');
+		if (extension)
+		  {
+		    strcpy (extension, "\0");
+		    asprintf (&extension, "%s", ".o\0");
+		    strcat (filename, extension);
+		    str = build_string_literal (strlen(filename)+1,filename);
+		  }
+	      }
 	    CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, str);
 
+
 	    int slen = IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (fndecl));
 	    if (asprintf (&tmpname, "&%s",
 			  IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl))) < 0)
diff --git a/libgomp/ChangeLog.hsa b/libgomp/ChangeLog.hsa
index 1deae12..1ff5486 100644
--- a/libgomp/ChangeLog.hsa
+++ b/libgomp/ChangeLog.hsa
@@ -1,3 +1,8 @@
+2014-10-24  Martin Jambor  <mjambor@suse.cz>
+
+	* hsaokra.c (__hsa_launch_kernel): Do not segfault if file cannot be
+	opened.
+
 2014-09-26  Saravanan Ekanathan <saravanan.ekanathan@amd.com>
 
 	* hsaokra.c (__hsa_launch_kernel): Use BRIG generated by
diff --git a/libgomp/hsaokra.c b/libgomp/hsaokra.c
index c9e0b1e..c41b86b 100644
--- a/libgomp/hsaokra.c
+++ b/libgomp/hsaokra.c
@@ -129,6 +129,11 @@ __hsa_launch_kernel (__hsa_kernel_desc * _kd, __hsa_launch_range *range_p,
       if (_kd->filename[0] == 0)
 	fileName = "hsakernel.o";
       pfile = (const char *) fopen (fileName, "rb");
+      if (!pfile)
+	{
+	  fprintf (stderr, "Unable to open file %s\n", fileName);
+	  return NULL;
+	}
       status = _okra_kernel_create_from_binary(context, pfile, size, _kd->name, &kernel);
       fclose((FILE *)pfile);
       if (status != OKRA_SUCCESS)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]