public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC
@ 2014-10-21 17:16 Ilya Verbin
  2014-10-21 17:20 ` [PATCH 1/4] Add mkoffload for " Ilya Verbin
                   ` (4 more replies)
  0 siblings, 5 replies; 111+ messages in thread
From: Ilya Verbin @ 2014-10-21 17:16 UTC (permalink / raw)
  To: gcc-patches

Hello,

This patchset would contain target-specific things to support offloading to the
devices with Intel MIC architecture.
Particularly: mkoffload tool, liboffloadmic library and a plugin for libgomp.

  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* [PATCH 1/4] Add mkoffload for Intel MIC
  2014-10-21 17:16 [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC Ilya Verbin
@ 2014-10-21 17:20 ` Ilya Verbin
  2014-10-21 21:58   ` Joseph S. Myers
                     ` (2 more replies)
  2014-10-21 17:24 ` [PATCH 2/4] Add liboffloadmic Ilya Verbin
                   ` (3 subsequent siblings)
  4 siblings, 3 replies; 111+ messages in thread
From: Ilya Verbin @ 2014-10-21 17:20 UTC (permalink / raw)
  To: Jakub Jelinek, gcc-patches; +Cc: Kirill Yukhin, Andrey Turetskiy

Hello,

This patch contains mkoffload tool and the appropriate changes for makefiles.

mkoffload is executed by lto-wrapper.  It runs offload compiler, which produces
a dynamic shared library for MIC (so far, it requires offload compiler to be
installed).  Then mkoffload copies the DSO into a new object file that can be
linked in with the host binary.  Also the final object contains a constructor
that calls GOMP_offload_register to identify itself at runtime. 

Autogenerated files are skipped.  Is it ok for trunk?

Thanks,
  -- Ilya


2014-10-21  Ilya Verbin  <ilya.verbin@intel.com>
	    Andrey Turetskiy  <andrey.turetskiy@intel.com>

gcc/
	* Makefile.in (mkoffload.o, mkoffload$(exeext)): New rules.
	* config.gcc (i[34567]86-*-* | x86_64-*-*): Build mkoffload$(exeext)
	with the accelerator compiler.
	* config/intelmic/mkoffload.c: New file.

---

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 45a10b6..63a40b6 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -3895,3 +3895,14 @@ DEPFILES = \
   $(foreach obj,$(ALL_HOST_OBJS),\
     $(dir $(obj))$(DEPDIR)/$(patsubst %.o,%.Po,$(notdir $(obj))))
 -include $(DEPFILES)
+
+
+mkoffload.o: $(srcdir)/config/intelmic/mkoffload.c | insn-modes.h
+	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
+	  -I$(srcdir)/../libgomp \
+	  -DDEFAULT_REAL_TARGET_MACHINE=\"$(real_target_noncanonical)\" \
+	  -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
+	  $< $(OUTPUT_OPTION)
+
+mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
+	$(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 6bbbb26..2c6b3a5 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4214,3 +4214,11 @@ then
 		target_cpu_default=$target_cpu_default2
 	fi
 fi
+
+case ${target} in
+i[34567]86-*-* | x86_64-*-*)
+	if test x$enable_as_accelerator = xyes; then
+		extra_programs="mkoffload\$(exeext)"
+	fi
+	;;
+esac
diff --git a/gcc/config/intelmic/mkoffload.c b/gcc/config/intelmic/mkoffload.c
new file mode 100644
index 0000000..8625a94
--- /dev/null
+++ b/gcc/config/intelmic/mkoffload.c
@@ -0,0 +1,551 @@
+/* Offload image generation tool for Intel MIC devices.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   Contributed by Ilya Verbin <ilya.verbin@intel.com>.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GCC is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <libgen.h>
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "obstack.h"
+#include "intl.h"
+#include "diagnostic.h"
+#include "collect-utils.h"
+#include <libgomp_target.h>
+
+const char tool_name[] = "intelmic mkoffload";
+
+const char image_section_name[] = ".gnu.offload_images";
+const char *symbols[3] = { "__offload_image_intelmic_start",
+			   "__offload_image_intelmic_end",
+			   "__offload_image_intelmic_size" };
+const char *out_obj_filename = NULL;
+
+int num_temps = 0;
+const int MAX_NUM_TEMPS = 10;
+const char *temp_files[MAX_NUM_TEMPS];
+
+/* Shows if we should compile binaries for i386 instead of x86-64.  */
+bool target_ilp32 = false;
+
+/* Delete tempfiles and exit function.  */
+void
+tool_cleanup (__attribute__((unused)) bool from_signal)
+{
+  for (int i = 0; i < num_temps; i++)
+    maybe_unlink (temp_files[i]);
+}
+
+static void
+mkoffload_atexit (void)
+{
+  tool_cleanup (false);
+}
+
+/* Unlink FILE unless we are debugging.  */
+void
+maybe_unlink (const char *file)
+{
+  if (debug)
+    notice ("[Leaving %s]\n", file);
+  else
+    unlink_if_ordinary (file);
+}
+
+/* Add or change the value of an environment variable, outputting the
+   change to standard error if in verbose mode.  */
+static void
+xputenv (const char *string)
+{
+  if (verbose)
+    fprintf (stderr, "%s\n", string);
+  putenv (CONST_CAST (char *, string));
+}
+
+/* Parse STR, saving found tokens into PVALUES and return their number.
+   Tokens are assumed to be delimited by ':'.  */
+static unsigned
+parse_env_var (const char *str, char ***pvalues)
+{
+  const char *curval, *nextval;
+  char **values;
+  unsigned num = 1, i;
+
+  curval = strchr (str, ':');
+  while (curval)
+    {
+      num++;
+      curval = strchr (curval + 1, ':');
+    }
+
+  values = (char**) xmalloc (num * sizeof (char*));
+  curval = str;
+  nextval = strchrnul (curval, ':');
+
+  for (i = 0; i < num; i++)
+    {
+      int l = nextval - curval;
+      values[i] = (char*) xmalloc (l + 1);
+      memcpy (values[i], curval, l);
+      values[i][l] = 0;
+      curval = nextval + 1;
+      nextval = strchrnul (curval, ':');
+    }
+  *pvalues = values;
+  return num;
+}
+
+/* Auxiliary function that frees elements of PTR and PTR itself.
+   N is number of elements to be freed.  If PTR is NULL, nothing is freed.
+   If an element is NULL, subsequent elements are not freed.  */
+static void
+free_array_of_ptrs (void **ptr, unsigned n)
+{
+  unsigned i;
+  if (!ptr)
+    return;
+  for (i = 0; i < n; i++)
+    {
+      if (!ptr[i])
+	break;
+      free (ptr[i]);
+    }
+  free (ptr);
+  return;
+}
+
+/* Check whether NAME can be accessed in MODE.  This is like access,
+   except that it never considers directories to be executable.  */
+static int
+access_check (const char *name, int mode)
+{
+  if (mode == X_OK)
+    {
+      struct stat st;
+
+      if (stat (name, &st) < 0 || S_ISDIR (st.st_mode))
+	return -1;
+    }
+
+  return access (name, mode);
+}
+
+/* Find target compiler using a path from COLLECT_GCC or COMPILER_PATH.  */
+static char *
+find_target_compiler (const char *name)
+{
+  bool found = false;
+  char **paths = NULL;
+  unsigned n_paths, i;
+  const char *collect_path = dirname (ASTRDUP (getenv ("COLLECT_GCC")));
+  size_t len = strlen (collect_path) + 1 + strlen (name) + 1;
+  char *target_compiler = XNEWVEC (char, len);
+  sprintf (target_compiler, "%s/%s", collect_path, name);
+  if (access_check (target_compiler, X_OK) == 0)
+    {
+      found = true;
+      goto out;
+    }
+
+  n_paths = parse_env_var (getenv ("COMPILER_PATH"), &paths);
+  for (i = 0; i < n_paths; i++)
+    {
+      len = strlen (paths[i]) + 1 + strlen (name) + 1;
+      target_compiler = XRESIZEVEC (char, target_compiler, len);
+      sprintf (target_compiler, "%s/%s", paths[i], name);
+      if (access_check (target_compiler, X_OK) == 0)
+	{
+	  found = true;
+	  break;
+	}
+    }
+
+out:
+  free_array_of_ptrs ((void **) paths, n_paths);
+  return found ? target_compiler : NULL;
+}
+
+static void
+compile_for_target (struct obstack *argv_obstack)
+{
+  if (target_ilp32)
+    obstack_ptr_grow (argv_obstack, "-m32");
+  obstack_ptr_grow (argv_obstack, NULL);
+  char **argv = XOBFINISH (argv_obstack, char **);
+
+  /* Save environment variables.  */
+  const char *epath = getenv ("GCC_EXEC_PREFIX");
+  const char *cpath = getenv ("COMPILER_PATH");
+  const char *lpath = getenv ("LIBRARY_PATH");
+  const char *rpath = getenv ("LD_RUN_PATH");
+  unsetenv ("GCC_EXEC_PREFIX");
+  unsetenv ("COMPILER_PATH");
+  unsetenv ("LIBRARY_PATH");
+  unsetenv ("LD_RUN_PATH");
+
+  fork_execute (argv[0], argv, false);
+  obstack_free (argv_obstack, NULL);
+
+  /* Restore environment variables.  */
+  xputenv (concat ("GCC_EXEC_PREFIX=", epath, NULL));
+  xputenv (concat ("COMPILER_PATH=", cpath, NULL));
+  xputenv (concat ("LIBRARY_PATH=", lpath, NULL));
+  xputenv (concat ("LD_RUN_PATH=", rpath, NULL));
+}
+
+/* Generates object file with the descriptor for the target library.  */
+static const char *
+generate_target_descr_file (const char *target_compiler)
+{
+  const char *src_filename = make_temp_file ("_target_descr.c");
+  const char *obj_filename = make_temp_file ("_target_descr.o");
+  temp_files[num_temps++] = src_filename;
+  temp_files[num_temps++] = obj_filename;
+  FILE *src_file = fopen (src_filename, "w");
+
+  if (!src_file)
+    fatal_error ("cannot open '%s'", src_filename);
+
+  fprintf (src_file,
+	   "extern void *__offload_funcs_end[];\n"
+	   "extern void *__offload_vars_end[];\n\n"
+
+	   "void *__offload_func_table[0]\n"
+	   "__attribute__ ((__used__, visibility (\"hidden\"),\n"
+	   "section (\".gnu.offload_funcs\"))) = { };\n\n"
+
+	   "void *__offload_var_table[0]\n"
+	   "__attribute__ ((__used__, visibility (\"hidden\"),\n"
+	   "section (\".gnu.offload_vars\"))) = { };\n\n"
+
+	   "void *__OFFLOAD_TARGET_TABLE__[]\n"
+	   "__attribute__ ((__used__, visibility (\"hidden\"))) = {\n"
+	   "  &__offload_func_table, &__offload_funcs_end,\n"
+	   "  &__offload_var_table, &__offload_vars_end\n"
+	   "};\n\n");
+
+  fprintf (src_file,
+	   "#ifdef __cplusplus\n"
+	   "extern \"C\"\n"
+	   "#endif\n"
+	   "void target_register_lib (const void *);\n\n"
+
+	   "__attribute__((constructor))\n"
+	   "static void\n"
+	   "init (void)\n"
+	   "{\n"
+	   "  target_register_lib (__OFFLOAD_TARGET_TABLE__);\n"
+	   "}\n");
+  fclose (src_file);
+
+  struct obstack argv_obstack;
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, target_compiler);
+  obstack_ptr_grow (&argv_obstack, "-c");
+  obstack_ptr_grow (&argv_obstack, "-shared");
+  obstack_ptr_grow (&argv_obstack, "-fPIC");
+  obstack_ptr_grow (&argv_obstack, src_filename);
+  obstack_ptr_grow (&argv_obstack, "-o");
+  obstack_ptr_grow (&argv_obstack, obj_filename);
+  compile_for_target (&argv_obstack);
+
+  return obj_filename;
+}
+
+/* Generates object file with __offload_*_end symbols for the target
+   library.  */
+static const char *
+generate_target_offloadend_file (const char *target_compiler)
+{
+  const char *src_filename = make_temp_file ("_target_offloadend.c");
+  const char *obj_filename = make_temp_file ("_target_offloadend.o");
+  temp_files[num_temps++] = src_filename;
+  temp_files[num_temps++] = obj_filename;
+  FILE *src_file = fopen (src_filename, "w");
+
+  if (!src_file)
+    fatal_error ("cannot open '%s'", src_filename);
+
+  fprintf (src_file,
+	   "void *__offload_funcs_end[0]\n"
+	   "__attribute__ ((__used__, visibility (\"hidden\"),\n"
+	   "section (\".gnu.offload_funcs\"))) = { };\n\n"
+
+	   "void *__offload_vars_end[0]\n"
+	   "__attribute__ ((__used__, visibility (\"hidden\"),\n"
+	   "section (\".gnu.offload_vars\"))) = { };\n");
+  fclose (src_file);
+
+  struct obstack argv_obstack;
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, target_compiler);
+  obstack_ptr_grow (&argv_obstack, "-c");
+  obstack_ptr_grow (&argv_obstack, "-shared");
+  obstack_ptr_grow (&argv_obstack, "-fPIC");
+  obstack_ptr_grow (&argv_obstack, src_filename);
+  obstack_ptr_grow (&argv_obstack, "-o");
+  obstack_ptr_grow (&argv_obstack, obj_filename);
+  compile_for_target (&argv_obstack);
+
+  return obj_filename;
+}
+
+/* Generates object file with the host side descriptor.  */
+static const char *
+generate_host_descr_file (const char *host_compiler)
+{
+  const char *src_filename = make_temp_file ("_host_descr.c");
+  const char *obj_filename = make_temp_file ("_host_descr.o");
+  temp_files[num_temps++] = src_filename;
+  temp_files[num_temps++] = obj_filename;
+  FILE *src_file = fopen (src_filename, "w");
+
+  if (!src_file)
+    fatal_error ("cannot open '%s'", src_filename);
+
+  fprintf (src_file,
+	   "extern void *__OFFLOAD_TABLE__;\n"
+	   "extern void *__offload_image_intelmic_start;\n"
+	   "extern void *__offload_image_intelmic_end;\n\n"
+
+	   "static const void *__offload_target_data[] = {\n"
+	   "  &__offload_image_intelmic_start, &__offload_image_intelmic_end\n"
+	   "};\n\n");
+
+  fprintf (src_file,
+	   "#ifdef __cplusplus\n"
+	   "extern \"C\"\n"
+	   "#endif\n"
+	   "void GOMP_offload_register (void *, int, void *);\n\n"
+
+	   "__attribute__((constructor))\n"
+	   "static void\n"
+	   "init (void)\n"
+	   "{\n"
+	   "  GOMP_offload_register (&__OFFLOAD_TABLE__, %d, __offload_target_data);\n"
+	   "}\n", OFFLOAD_TARGET_TYPE_INTEL_MIC);
+  fclose (src_file);
+
+  struct obstack argv_obstack;
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, host_compiler);
+  if (target_ilp32)
+    obstack_ptr_grow (&argv_obstack, "-m32");
+  obstack_ptr_grow (&argv_obstack, "-c");
+  obstack_ptr_grow (&argv_obstack, "-shared");
+  obstack_ptr_grow (&argv_obstack, "-fPIC");
+  obstack_ptr_grow (&argv_obstack, src_filename);
+  obstack_ptr_grow (&argv_obstack, "-o");
+  obstack_ptr_grow (&argv_obstack, obj_filename);
+  obstack_ptr_grow (&argv_obstack, NULL);
+
+  char **argv = XOBFINISH (&argv_obstack, char **);
+  fork_execute (argv[0], argv, false);
+  obstack_free (&argv_obstack, NULL);
+
+  return obj_filename;
+}
+
+static const char *
+prepare_target_image (const char *target_compiler, int argc, char **argv)
+{
+  const char *target_descr_filename
+    = generate_target_descr_file (target_compiler);
+  const char *target_offloadend_filename
+    = generate_target_offloadend_file (target_compiler);
+
+  char *opt1
+    = XALLOCAVEC (char, sizeof ("-Wl,") + strlen (target_descr_filename));
+  char *opt2
+    = XALLOCAVEC (char, sizeof ("-Wl,") + strlen (target_offloadend_filename));
+  sprintf (opt1, "-Wl,%s", target_descr_filename);
+  sprintf (opt2, "-Wl,%s", target_offloadend_filename);
+
+  const char *target_so_filename = make_temp_file ("_offload_intelmic.so");
+  temp_files[num_temps++] = target_so_filename;
+  struct obstack argv_obstack;
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, target_compiler);
+  obstack_ptr_grow (&argv_obstack, "-xlto");
+  obstack_ptr_grow (&argv_obstack, "-fopenmp");
+  obstack_ptr_grow (&argv_obstack, "-shared");
+  obstack_ptr_grow (&argv_obstack, "-fPIC");
+  obstack_ptr_grow (&argv_obstack, opt1);
+  for (int i = 1; i < argc; i++)
+    {
+      if (!strcmp (argv[i], "-o") && i + 1 != argc)
+	out_obj_filename = argv[++i];
+      else
+	obstack_ptr_grow (&argv_obstack, argv[i]);
+    }
+  if (!out_obj_filename)
+    fatal_error ("output file not specified.");
+  obstack_ptr_grow (&argv_obstack, opt2);
+  obstack_ptr_grow (&argv_obstack, "-o");
+  obstack_ptr_grow (&argv_obstack, target_so_filename);
+  compile_for_target (&argv_obstack);
+
+  /* Run objcopy.  */
+  char *opt3
+    = XALLOCAVEC (char, sizeof (".data=") + strlen (image_section_name));
+  sprintf (opt3, ".data=%s", image_section_name);
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, "objcopy");
+  obstack_ptr_grow (&argv_obstack, "-B");
+  obstack_ptr_grow (&argv_obstack, "i386");
+  obstack_ptr_grow (&argv_obstack, "-I");
+  obstack_ptr_grow (&argv_obstack, "binary");
+  obstack_ptr_grow (&argv_obstack, "-O");
+  if (target_ilp32)
+    obstack_ptr_grow (&argv_obstack, "elf32-i386");
+  else
+    obstack_ptr_grow (&argv_obstack, "elf64-x86-64");
+  obstack_ptr_grow (&argv_obstack, target_so_filename);
+  obstack_ptr_grow (&argv_obstack, "--rename-section");
+  obstack_ptr_grow (&argv_obstack, opt3);
+  obstack_ptr_grow (&argv_obstack, NULL);
+  char **new_argv = XOBFINISH (&argv_obstack, char **);
+  fork_execute (new_argv[0], new_argv, false);
+  obstack_free (&argv_obstack, NULL);
+
+  /* Objcopy has created symbols, containing the input file name with
+     special characters replaced with '_'.  We are going to rename these
+     new symbols.  */
+  char *symbol_name = XALLOCAVEC (char, strlen (target_so_filename) + 1);
+  int i = 0;
+  while (target_so_filename[i])
+    {
+      char c = target_so_filename[i];
+      if ((c == '/') || (c == '.'))
+	c = '_';
+      symbol_name[i] = c;
+      i++;
+    }
+  symbol_name[i] = 0;
+
+  char *opt_for_objcopy[3];
+  opt_for_objcopy[0] = XALLOCAVEC (char, sizeof ("_binary__start=")
+					 + strlen (symbol_name)
+					 + strlen (symbols[0]));
+  opt_for_objcopy[1] = XALLOCAVEC (char, sizeof ("_binary__end=")
+					 + strlen (symbol_name)
+					 + strlen (symbols[1]));
+  opt_for_objcopy[2] = XALLOCAVEC (char, sizeof ("_binary__size=")
+					 + strlen (symbol_name)
+					 + strlen (symbols[2]));
+  sprintf (opt_for_objcopy[0], "_binary_%s_start=%s", symbol_name, symbols[0]);
+  sprintf (opt_for_objcopy[1], "_binary_%s_end=%s", symbol_name, symbols[1]);
+  sprintf (opt_for_objcopy[2], "_binary_%s_size=%s", symbol_name, symbols[2]);
+
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, "objcopy");
+  obstack_ptr_grow (&argv_obstack, target_so_filename);
+  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
+  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[0]);
+  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
+  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[1]);
+  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
+  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[2]);
+  obstack_ptr_grow (&argv_obstack, NULL);
+  new_argv = XOBFINISH (&argv_obstack, char **);
+  fork_execute (new_argv[0], new_argv, false);
+  obstack_free (&argv_obstack, NULL);
+
+  return target_so_filename;
+}
+
+int
+main (int argc, char **argv)
+{
+  progname = "mkoffload-intelmic";
+  gcc_init_libintl ();
+  diagnostic_initialize (global_dc, 0);
+
+  if (atexit (mkoffload_atexit) != 0)
+    fatal_error ("atexit failed");
+
+  const char *host_compiler = getenv ("COLLECT_GCC");
+  if (!host_compiler)
+    fatal_error ("COLLECT_GCC must be set.");
+
+  const char *target_driver_name
+    = DEFAULT_REAL_TARGET_MACHINE "-accel-" DEFAULT_TARGET_MACHINE "-gcc";
+  char *target_compiler = find_target_compiler (target_driver_name);
+  if (target_compiler == NULL)
+    fatal_error ("offload compiler %s not found.", target_driver_name);
+
+  /* We may be called with all the arguments stored in some file and
+     passed with @file.  Expand them into argv before processing.  */
+  expandargv (&argc, &argv);
+
+  /* Find out whether we should compile binaries for i386 or x86-64.  */
+  for (int i = argc - 1; i > 0; i--)
+    if (strncmp (argv[i], "-foffload-abi=", strlen ("-foffload-abi=")) == 0)
+      {
+	if (strstr (argv[i], "ilp32"))
+	  target_ilp32 = true;
+	else if (!strstr (argv[i], "lp64"))
+	  fatal_error ("unrecognizable argument of option -foffload-abi");
+	break;
+      }
+
+  const char *target_so_filename
+    = prepare_target_image (target_compiler, argc, argv);
+
+  const char *host_descr_filename = generate_host_descr_file (host_compiler);
+
+  /* Perform partial linking for the target image and host side descriptor.
+     As a result we'll get a finalized object file with all offload data.  */
+  struct obstack argv_obstack;
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, "ld");
+  if (target_ilp32)
+    {
+      obstack_ptr_grow (&argv_obstack, "-m");
+      obstack_ptr_grow (&argv_obstack, "elf_i386");
+    }
+  obstack_ptr_grow (&argv_obstack, "-r");
+  obstack_ptr_grow (&argv_obstack, host_descr_filename);
+  obstack_ptr_grow (&argv_obstack, target_so_filename);
+  obstack_ptr_grow (&argv_obstack, "-o");
+  obstack_ptr_grow (&argv_obstack, out_obj_filename);
+  obstack_ptr_grow (&argv_obstack, NULL);
+  char **new_argv = XOBFINISH (&argv_obstack, char **);
+  fork_execute (new_argv[0], new_argv, false);
+  obstack_free (&argv_obstack, NULL);
+
+  /* Run objcopy on the resultant object file to localize generated symbols
+     to avoid conflicting between different DSO and an executable.  */
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, "objcopy");
+  obstack_ptr_grow (&argv_obstack, "-L");
+  obstack_ptr_grow (&argv_obstack, symbols[0]);
+  obstack_ptr_grow (&argv_obstack, "-L");
+  obstack_ptr_grow (&argv_obstack, symbols[1]);
+  obstack_ptr_grow (&argv_obstack, "-L");
+  obstack_ptr_grow (&argv_obstack, symbols[2]);
+  obstack_ptr_grow (&argv_obstack, out_obj_filename);
+  obstack_ptr_grow (&argv_obstack, NULL);
+  new_argv = XOBFINISH (&argv_obstack, char **);
+  fork_execute (new_argv[0], new_argv, false);
+  obstack_free (&argv_obstack, NULL);
+
+  return 0;
+}
-- 
1.7.1

^ permalink raw reply	[flat|nested] 111+ messages in thread

* [PATCH 2/4] Add liboffloadmic
  2014-10-21 17:16 [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC Ilya Verbin
  2014-10-21 17:20 ` [PATCH 1/4] Add mkoffload for " Ilya Verbin
@ 2014-10-21 17:24 ` Ilya Verbin
  2014-10-22  8:55   ` Jakub Jelinek
                     ` (2 more replies)
  2014-10-21 17:28 ` [PATCH 3/4] Add libgomp plugin for Intel MIC Ilya Verbin
                   ` (2 subsequent siblings)
  4 siblings, 3 replies; 111+ messages in thread
From: Ilya Verbin @ 2014-10-21 17:24 UTC (permalink / raw)
  To: Jakub Jelinek, gcc-patches; +Cc: Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: text/plain, Size: 4994 bytes --]

Hello,

This patch contains liboffloadmic library.

It is used by ICC for offloading.  The sources are imported from upstream
( https://www.openmprtl.org/sites/default/files/liboffload_oss.tgz )
Configure and makefiles are new.

Also liboffloadmic/runtime/emulator directory is new.  This emulator consists
of 4 shared libraries which replace COI and MYO libraries from MPSS stack.
This allows to run a binary with offloading in non-fallback mode without HW
(target region is executed in a separate process).

By default it builds automatically, if the compiler is configured with
--enable-as-accelerator-for or --enable-offload-targets options and MIC targets
(liboffloadmic_target.so and liboffloadmic_host.so respectively).

Autogenerated files are skipped.  Is it ok for trunk?


2014-10-21  Ilya Verbin  <ilya.verbin@intel.com>

	* Makefile.def: Add liboffloadmic to target_modules.  Make
	liboffloadmic depend on libgomp's configure, libstdc++ and libgcc.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Add liboffloadmic to target binaries.
	Restrict liboffloadmic for POSIX and i*86, and x86_64 architectures.
	Add liboffloadmic to noconfig list when C++ is not supported.
config/
	* target-posix: New file.
libcilkrts/
	* configure.tgt: Use config/target-posix.
liboffloadmic/
	Initial commit.  Imported from upstream:
	https://www.openmprtl.org/sites/default/files/liboffload_oss.tgz
	* Makefile.am: New file.
	* Makefile.in: New file, generated by automake.
	* aclocal.m4: New file, generated by aclocal.
	* configure: New file, generated by autoconf.
	* configure.ac: New file.
	* configure.tgt: Ditto.
	* doc/doxygen/config: Ditto.
	* doc/doxygen/header.tex: Ditto.
	* include/coi/common/COIEngine_common.h: Ditto.
	* include/coi/common/COIMacros_common.h: Ditto.
	* include/coi/common/COIPerf_common.h : Ditto.
	* include/coi/common/COIResult_common.h : Ditto.
	* include/coi/common/COITypes_common.h: Ditto.
	* include/coi/sink/COIBuffer_sink.h: Ditto.
	* include/coi/sink/COIPipeline_sink.h: Ditto.
	* include/coi/sink/COIProcess_sink.h: Ditto.
	* include/coi/source/COIBuffer_source.h: Ditto.
	* include/coi/source/COIEngine_source.h: Ditto.
	* include/coi/source/COIEvent_source.h: Ditto.
	* include/coi/source/COIPipeline_source.h: Ditto.
	* include/coi/source/COIProcess_source.h: Ditto.
	* include/myo/myo.h: Ditto.
	* include/myo/myoimpl.h: Ditto.
	* include/myo/myotypes.h: Ditto.
	* liboffloadmic_host.spec.in: Ditto.
	* liboffloadmic_target.spec.in: Ditto.
	* runtime/cean_util.cpp: Ditto.
	* runtime/cean_util.h: Ditto.
	* runtime/coi/coi_client.cpp: Ditto.
	* runtime/coi/coi_client.h: Ditto.
	* runtime/coi/coi_server.cpp: Ditto.
	* runtime/coi/coi_server.h: Ditto.
	* runtime/compiler_if_host.cpp: Ditto.
	* runtime/compiler_if_host.h: Ditto.
	* runtime/compiler_if_target.cpp: Ditto.
	* runtime/compiler_if_target.h: Ditto.
	* runtime/dv_util.cpp: Ditto.
	* runtime/dv_util.h: Ditto.
	* runtime/emulator/coi_common.h: Ditto.
	* runtime/emulator/coi_device.cpp: Ditto.
	* runtime/emulator/coi_device.h: Ditto.
	* runtime/emulator/coi_host.cpp: Ditto.
	* runtime/emulator/coi_host.h: Ditto.
	* runtime/emulator/coi_version_asm.h: Ditto.
	* runtime/emulator/coi_version_linker_script.map: Ditto.
	* runtime/emulator/myo_client.cpp: Ditto.
	* runtime/emulator/myo_service.cpp: Ditto.
	* runtime/emulator/myo_service.h: Ditto.
	* runtime/emulator/myo_version_asm.h: Ditto.
	* runtime/emulator/myo_version_linker_script.map: Ditto.
	* runtime/liboffload_error.c: Ditto.
	* runtime/liboffload_error_codes.h: Ditto.
	* runtime/liboffload_msg.c: Ditto.
	* runtime/liboffload_msg.h: Ditto.
	* runtime/mic_lib.f90: Ditto.
	* runtime/offload.h: Ditto.
	* runtime/offload_common.cpp: Ditto.
	* runtime/offload_common.h: Ditto.
	* runtime/offload_engine.cpp: Ditto.
	* runtime/offload_engine.h: Ditto.
	* runtime/offload_env.cpp: Ditto.
	* runtime/offload_env.h: Ditto.
	* runtime/offload_host.cpp: Ditto.
	* runtime/offload_host.h: Ditto.
	* runtime/offload_myo_host.cpp: Ditto.
	* runtime/offload_myo_host.h: Ditto.
	* runtime/offload_myo_target.cpp: Ditto.
	* runtime/offload_myo_target.h: Ditto.
	* runtime/offload_omp_host.cpp: Ditto.
	* runtime/offload_omp_target.cpp: Ditto.
	* runtime/offload_orsl.cpp: Ditto.
	* runtime/offload_orsl.h: Ditto.
	* runtime/offload_table.cpp: Ditto.
	* runtime/offload_table.h: Ditto.
	* runtime/offload_target.cpp: Ditto.
	* runtime/offload_target.h: Ditto.
	* runtime/offload_target_main.cpp: Ditto.
	* runtime/offload_timer.h: Ditto.
	* runtime/offload_timer_host.cpp: Ditto.
	* runtime/offload_timer_target.cpp: Ditto.
	* runtime/offload_trace.cpp: Ditto.
	* runtime/offload_trace.h: Ditto.
	* runtime/offload_util.cpp: Ditto.
	* runtime/offload_util.h: Ditto.
	* runtime/ofldbegin.cpp: Ditto.
	* runtime/ofldend.cpp: Ditto.
	* runtime/orsl-lite/include/orsl-lite.h: Ditto.
	* runtime/orsl-lite/lib/orsl-lite.c: Ditto.
	* runtime/orsl-lite/version.txt: Ditto.
	* runtime/use_mpss2.txt: Ditto.

Thanks,
  -- Ilya

[-- Attachment #2: liboffloadmic.bz2 --]
[-- Type: application/x-bzip2, Size: 142698 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* [PATCH 3/4] Add libgomp plugin for Intel MIC
  2014-10-21 17:16 [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC Ilya Verbin
  2014-10-21 17:20 ` [PATCH 1/4] Add mkoffload for " Ilya Verbin
  2014-10-21 17:24 ` [PATCH 2/4] Add liboffloadmic Ilya Verbin
@ 2014-10-21 17:28 ` Ilya Verbin
  2014-10-22  9:47   ` Jakub Jelinek
  2015-07-08 14:16   ` Thomas Schwinge
  2014-10-30 12:45 ` [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing Ilya Verbin
  2014-12-22 12:08 ` [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC Thomas Schwinge
  4 siblings, 2 replies; 111+ messages in thread
From: Ilya Verbin @ 2014-10-21 17:28 UTC (permalink / raw)
  To: Jakub Jelinek, gcc-patches; +Cc: Kirill Yukhin, Andrey Turetskiy

Hello,

This patch contains a plugin for libgomp and appropriate changes for makefiles.

The plugin uses liboffloadmic_host.so to interact with the device (or with an
emulator).  Also the patch contains offload_target_main executable, which is the
corresponding target side part of a libgomp plugin, and it uses
liboffloadmic_target.so.

The plugin builds automatically with liboffloadmic.

Autogenerated files are skipped.  Is it ok for trunk?

Thanks,
  -- Ilya


2014-10-21  Ilya Verbin  <ilya.verbin@intel.com>
	    Andrey Turetskiy  <andrey.turetskiy@intel.com>

liboffloadmic/
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Add subdirectory 'plugin'.
	* plugin/Makefile.am: New file.
	* plugin/Makefile.in: New file, generated by automake.
	* plugin/aclocal.m4: New file, generated by aclocal.
	* plugin/configure: New file, generated by autoconf.
	* plugin/configure.ac: New file.
	* plugin/libgomp-plugin-intelmic.cpp: New file.
	* plugin/offload_target_main.cpp: New file.

---

diff --git a/liboffloadmic/configure.ac b/liboffloadmic/configure.ac
index fb575b3..81fae8f 100644
--- a/liboffloadmic/configure.ac
+++ b/liboffloadmic/configure.ac
@@ -42,6 +42,7 @@ AC_PROG_CC
 AC_PROG_CXX
 AC_CONFIG_FILES([Makefile liboffloadmic_host.spec liboffloadmic_target.spec])
 AM_ENABLE_MULTILIB(, ..)
+AC_CONFIG_SUBDIRS(plugin)
 AC_FUNC_ALLOCA
 AC_CHECK_HEADERS([mm_malloc.h], [], [AC_MSG_ERROR(["Couldn't find mm_malloc.h"])])
 AC_CHECK_FUNCS([__secure_getenv secure_getenv])
diff --git a/liboffloadmic/plugin/Makefile.am b/liboffloadmic/plugin/Makefile.am
new file mode 100644
index 0000000..0baf70d
--- /dev/null
+++ b/liboffloadmic/plugin/Makefile.am
@@ -0,0 +1,123 @@
+# Plugin for offload execution on Intel MIC devices.
+#
+# Copyright (C) 2014 Free Software Foundation, Inc.
+#
+# Contributed by Ilya Verbin <ilya.verbin@intel.com> and
+# Andrey Turetskiy <andrey.turetskiy@intel.com>.
+#
+# This file is part of the GNU OpenMP Library (libgomp).
+#
+# Libgomp is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# Under Section 7 of GPL version 3, you are granted additional
+# permissions described in the GCC Runtime Library Exception, version
+# 3.1, as published by the Free Software Foundation.
+#
+# You should have received a copy of the GNU General Public License and
+# a copy of the GCC Runtime Library Exception along with this program;
+# see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+
+AUTOMAKE_OPTIONS = foreign
+ACLOCAL_AMFLAGS = -I ../.. -I ../../config
+
+# Directories
+build_dir = $(top_builddir)
+source_dir = $(top_srcdir)
+coi_inc_dir = $(top_srcdir)/../include/coi
+myo_inc_dir = $(top_srcdir)/../include/myo
+libgomp_src_dir = $(top_srcdir)/../../libgomp
+libgomp_dir = $(build_dir)/../../libgomp
+liboffload_src_dir = $(top_srcdir)/../runtime
+liboffload_dir = $(top_builddir)/..
+
+# May be used by toolexeclibdir.
+gcc_version := $(shell cat $(top_srcdir)/../../gcc/BASE-VER)
+libsubincludedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/include
+# Search for main_target_image.h in these directories
+target_prefix_dir = $(libdir)/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
+target_build_dir = $(accel_search_dir)/$(accel_target)$(MULTISUBDIR)/liboffloadmic/plugin
+target_install_dir = $(accel_search_dir)/lib/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
+
+if PLUGIN_HOST
+  toolexeclib_LTLIBRARIES = libgomp-plugin-intelmic.la
+  libgomp_plugin_intelmic_la_SOURCES = libgomp-plugin-intelmic.cpp
+  libgomp_plugin_intelmic_la_CPPFLAGS = $(CPPFLAGS) -DLINUX -DCOI_LIBRARY_VERSION=2 -DMYO_SUPPORT -DOFFLOAD_DEBUG=1 -DSEP_SUPPORT -DTIMING_SUPPORT -DHOST_LIBRARY=1 -I$(coi_inc_dir) -I$(myo_inc_dir) -I$(liboffload_src_dir) -I$(libgomp_src_dir) -I$(libgomp_dir) -I$(target_prefix_dir)/include -I$(target_build_dir) -I$(target_install_dir)/include
+  libgomp_plugin_intelmic_la_LDFLAGS = -L$(liboffload_dir)/.libs -loffloadmic_host -version-info 1:0:0
+else # PLUGIN_TARGET
+  plugin_includedir = $(libsubincludedir)
+  plugin_include_HEADERS = main_target_image.h
+  AM_CPPFLAGS = $(CPPFLAGS) -DLINUX -DCOI_LIBRARY_VERSION=2 -DMYO_SUPPORT -DOFFLOAD_DEBUG=1 -DSEP_SUPPORT -DTIMING_SUPPORT -DHOST_LIBRARY=0 -I$(coi_inc_dir) -I$(myo_inc_dir) -I$(liboffload_src_dir) -I$(libgomp_dir)
+  AM_CXXFLAGS = $(CXXFLAGS)
+  AM_LDFLAGS = -L$(liboffload_dir)/.libs -L$(libgomp_dir)/.libs -loffloadmic_target -lcoi_device -lmyo-service -lgomp -rdynamic
+endif
+
+main_target_image.h: offload_target_main
+	@echo -n "const int image_size = " > $@
+	@stat -c '%s' $< >> $@
+	@echo ";" >> $@
+	@echo "struct MainTargetImage {" >> $@
+	@echo "  int64_t size;" >> $@
+	@echo "  char name[sizeof \"offload_target_main\"];" >> $@
+	@echo "  char data[image_size];" >> $@
+	@echo "};" >> $@
+	@echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
+	@echo "  image_size, \"offload_target_main\"," >> $@
+	@cat $< | xxd -include >> $@
+	@echo "};" >> $@
+
+offload_target_main: $(liboffload_dir)/ofldbegin.o offload_target_main.o $(liboffload_dir)/ofldend.o
+	$(CXX) $(AM_LDFLAGS) $^ -o $@
+
+offload_target_main.o: offload_target_main.cpp
+	$(CXX) $(AM_CXXFLAGS) $(AM_CPPFLAGS) -c $< -o $@
+
+# Work around what appears to be a GNU make bug handling MAKEFLAGS
+# values defined in terms of make variables, as is the case for CC and
+# friends when we are called from the top level Makefile.
+AM_MAKEFLAGS = \
+       "AR_FLAGS=$(AR_FLAGS)" \
+       "CC_FOR_BUILD=$(CC_FOR_BUILD)" \
+       "CFLAGS=$(CFLAGS)" \
+       "CXXFLAGS=$(CXXFLAGS)" \
+       "CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
+       "CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
+       "INSTALL=$(INSTALL)" \
+       "INSTALL_DATA=$(INSTALL_DATA)" \
+       "INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
+       "INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
+       "JC1FLAGS=$(JC1FLAGS)" \
+       "LDFLAGS=$(LDFLAGS)" \
+       "LIBCFLAGS=$(LIBCFLAGS)" \
+       "LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
+       "MAKE=$(MAKE)" \
+       "MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
+       "PICFLAG=$(PICFLAG)" \
+       "PICFLAG_FOR_TARGET=$(PICFLAG_FOR_TARGET)" \
+       "SHELL=$(SHELL)" \
+       "RUNTESTFLAGS=$(RUNTESTFLAGS)" \
+       "exec_prefix=$(exec_prefix)" \
+       "infodir=$(infodir)" \
+       "libdir=$(libdir)" \
+       "prefix=$(prefix)" \
+       "includedir=$(includedir)" \
+       "AR=$(AR)" \
+       "AS=$(AS)" \
+       "LD=$(LD)" \
+       "LIBCFLAGS=$(LIBCFLAGS)" \
+       "NM=$(NM)" \
+       "PICFLAG=$(PICFLAG)" \
+       "RANLIB=$(RANLIB)" \
+       "DESTDIR=$(DESTDIR)"
+
+MAKEOVERRIDES =
+
diff --git a/liboffloadmic/plugin/configure.ac b/liboffloadmic/plugin/configure.ac
new file mode 100644
index 0000000..283faad
--- /dev/null
+++ b/liboffloadmic/plugin/configure.ac
@@ -0,0 +1,135 @@
+# Plugin for offload execution on Intel MIC devices.
+#
+# Copyright (C) 2014 Free Software Foundation, Inc.
+#
+# Contributed by Andrey Turetskiy <andrey.turetskiy@intel.com>.
+#
+# This file is part of the GNU OpenMP Library (libgomp).
+#
+# Libgomp is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# Under Section 7 of GPL version 3, you are granted additional
+# permissions described in the GCC Runtime Library Exception, version
+# 3.1, as published by the Free Software Foundation.
+#
+# You should have received a copy of the GNU General Public License and
+# a copy of the GCC Runtime Library Exception along with this program;
+# see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+# Process this file with autoconf to produce a configure script, like so:
+# aclocal -I ../.. -I ../../config && autoconf && automake
+
+AC_PREREQ([2.64])
+AC_INIT([Intel MIC Offload Plugin], [1.0], ,[libgomp-plugin-intelmic])
+
+AC_CONFIG_AUX_DIR(../..)
+
+AC_CANONICAL_SYSTEM
+target_alias=${target_alias-$host_alias}
+AC_SUBST(target_alias)
+
+AM_INIT_AUTOMAKE([1.9.0 foreign no-dist])
+
+AM_MAINTAINER_MODE
+
+AC_PROG_CC
+AC_PROG_CXX
+AC_CONFIG_FILES([Makefile])
+AM_ENABLE_MULTILIB(, ../..)
+
+if test "${multilib}" = "yes"; then
+  multilib_arg="--enable-multilib"
+else
+  multilib_arg=
+fi
+
+# Make sure liboffloadmic is enabled
+case "$enable_liboffloadmic" in
+  host | target)
+    ;;
+  *)
+    AC_MSG_ERROR([Liboffloadmic is disabled]) ;;
+esac
+AM_CONDITIONAL(PLUGIN_HOST, [test x"$enable_liboffloadmic" = xhost])
+
+# Get accel target and path to build or install tree of accel compiler
+accel_search_dir=
+accel_target=
+if test x"$enable_liboffloadmic" = xhost; then
+  for accel in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
+    accel_name=`echo $accel | sed 's/=.*//'`
+    accel_dir=`echo $accel | grep '=' | sed 's/.*=//'`
+    case "$accel_name" in
+      *-intelmic-* | *-intelmicemul-*)
+	accel_target=$accel_name
+	accel_search_dir=$accel_dir
+	;;
+    esac
+  done
+  if test x"$accel_target" = x; then
+    AC_MSG_ERROR([--enable-offload-targets does not contain intelmic target])
+  fi
+fi
+AC_SUBST(accel_search_dir)
+AC_SUBST(accel_target)
+
+AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
+AC_ARG_ENABLE([version-specific-runtime-libs],
+  AC_HELP_STRING([--enable-version-specific-runtime-libs],
+		 [Specify that runtime libraries should be installed in a compiler-specific directory]),
+  [case "$enableval" in
+    yes) enable_version_specific_runtime_libs=yes ;;
+    no)  enable_version_specific_runtime_libs=no ;;
+    *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
+   esac],
+  [enable_version_specific_runtime_libs=no])
+AC_MSG_RESULT($enable_version_specific_runtime_libs)
+
+
+# Calculate toolexeclibdir.
+# Also toolexecdir, though it's only used in toolexeclibdir.
+case ${enable_version_specific_runtime_libs} in
+  yes)
+    # Need the gcc compiler version to know where to install libraries
+    # and header files if --enable-version-specific-runtime-libs option
+    # is selected.
+    toolexecdir='$(libdir)/gcc/$(target_alias)'
+    toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
+    ;;
+  no)
+    if test -n "$with_cross_host" &&
+       test x"$with_cross_host" != x"no"; then
+      # Install a library built with a cross compiler in tooldir, not libdir.
+      toolexecdir='$(exec_prefix)/$(target_alias)'
+      toolexeclibdir='$(toolexecdir)/lib'
+    else
+      toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+      toolexeclibdir='$(libdir)'
+    fi
+    multi_os_directory=`$CC -print-multi-os-directory`
+    case $multi_os_directory in
+      .) ;; # Avoid trailing /.
+      *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
+    esac
+    ;;
+esac
+
+AC_LIBTOOL_DLOPEN
+AM_PROG_LIBTOOL
+# Forbid libtool to hardcode RPATH, because we want to be able to specify
+# library search directory using LD_LIBRARY_PATH
+hardcode_into_libs=no
+AC_SUBST(toolexecdir)
+AC_SUBST(toolexeclibdir)
+
+# Must be last
+AC_OUTPUT
diff --git a/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp
new file mode 100644
index 0000000..dbbeeaf
--- /dev/null
+++ b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp
@@ -0,0 +1,442 @@
+/* Plugin for offload execution on Intel MIC devices.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   Contributed by Ilya Verbin <ilya.verbin@intel.com>.
+
+   This file is part of the GNU OpenMP Library (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Host side part of a libgomp plugin.  */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <utility>
+#include <vector>
+#include <libgomp_target.h>
+#include "compiler_if_host.h"
+#include "main_target_image.h"
+
+#define LD_LIBRARY_PATH_ENV	"LD_LIBRARY_PATH"
+#define MIC_LD_LIBRARY_PATH_ENV	"MIC_LD_LIBRARY_PATH"
+
+#ifdef DEBUG
+#define TRACE(...)					    \
+{							    \
+fprintf (stderr, "HOST:\t%s:%s ", __FILE__, __FUNCTION__);  \
+fprintf (stderr, __VA_ARGS__);				    \
+fprintf (stderr, "\n");					    \
+}
+#else
+#define TRACE { }
+#endif
+
+
+static VarDesc vd_host2tgt = {
+  { 1, 1 },		      /* dst, src			      */
+  { 1, 0 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+static VarDesc vd_tgt2host = {
+  { 1, 1 },		      /* dst, src			      */
+  { 0, 1 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+
+/* Total number of shared libraries with offloading to Intel MIC.  */
+static int num_libraries;
+
+/* Pointers to the descriptors, containing pointers to host-side tables and to
+   target images.  */
+static std::vector< std::pair<void *, void *> > lib_descrs;
+
+/* Mutex to control parallel plugin calls.  */
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+
+/* Add path specified in LD_LIBRARY_PATH to MIC_LD_LIBRARY_PATH, which is
+   required by liboffloadmic.  */
+__attribute__((constructor))
+static void
+set_mic_lib_path (void)
+{
+  const char *ld_lib_path = getenv (LD_LIBRARY_PATH_ENV);
+  const char *mic_lib_path = getenv (MIC_LD_LIBRARY_PATH_ENV);
+  char *mic_lib_path_new;
+
+  if (!ld_lib_path)
+    return;
+
+  mic_lib_path_new = (char *) malloc ((mic_lib_path ? strlen (mic_lib_path) : 0)
+				      + strlen (ld_lib_path) + 2);
+
+  if (!mic_lib_path)
+    strcpy (mic_lib_path_new, ld_lib_path);
+  else
+    sprintf (mic_lib_path_new, "%s:%s", mic_lib_path, ld_lib_path);
+  setenv (MIC_LD_LIBRARY_PATH_ENV, mic_lib_path_new, 1);
+  free (mic_lib_path_new);
+}
+
+extern "C" enum offload_target_type
+GOMP_OFFLOAD_get_type (void)
+{
+  enum offload_target_type res = OFFLOAD_TARGET_TYPE_INTEL_MIC;
+  TRACE ("(): return %d", res);
+  return res;
+}
+
+extern "C" int
+GOMP_OFFLOAD_get_num_devices (void)
+{
+  int res = _Offload_number_of_devices ();
+  TRACE ("(): return %d", res);
+  return res;
+}
+
+/* This should be called from every shared library with offloading.  */
+extern "C" void
+GOMP_OFFLOAD_register_image (void *host_table, void *target_image)
+{
+  TRACE ("(host_table = %p, target_image = %p)", host_table, target_image);
+
+  if (num_libraries >= 1000)
+    {
+      fprintf (stderr,
+	       "%s: The number of loaded shared libraries is over 1000!\n",
+	       __FILE__);
+      exit (1);
+    }
+
+  lib_descrs.push_back (std::make_pair (host_table, target_image));
+  num_libraries++;
+}
+
+static void
+offload (const char *file, uint64_t line, int device, const char *name,
+	 int num_vars, VarDesc *vars, VarDesc2 *vars2)
+{
+  OFFLOAD ofld = __offload_target_acquire1 (&device, file, line);
+  if (ofld)
+    __offload_offload1 (ofld, name, 0, num_vars, vars, vars2, 0, NULL, NULL);
+  else
+    {
+      fprintf (stderr, "%s:%d: Offload target acquire failed\n", file, line);
+      exit (1);
+    }
+}
+
+static int first_init = 1;
+
+/* Load offload_target_main on target.  */
+extern "C" void
+GOMP_OFFLOAD_init_device (int device)
+{
+  TRACE ("");
+  pthread_mutex_lock (&mutex);
+  if (first_init)
+    {
+      __offload_register_image (&main_target_image);
+      first_init = 0;
+    }
+  pthread_mutex_unlock (&mutex);
+  offload (__FILE__, __LINE__, device, "__offload_target_init_proc", 0,
+	   NULL, NULL);
+}
+
+static void
+get_target_table (int device, int &num_funcs, int &num_vars, void **&table)
+{
+  VarDesc vd1[2] = { vd_tgt2host, vd_tgt2host };
+  vd1[0].ptr = &num_funcs;
+  vd1[0].size = sizeof (num_funcs);
+  vd1[1].ptr = &num_vars;
+  vd1[1].size = sizeof (num_vars);
+  VarDesc2 vd1g[2] = { { "num_funcs", 0 }, { "num_vars", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_table_p1", 2,
+	   vd1, vd1g);
+
+  int table_size = num_funcs + 2 * num_vars;
+  if (table_size > 0)
+    {
+      table = new void * [table_size];
+
+      VarDesc vd2;
+      vd2 = vd_tgt2host;
+      vd2.ptr = table;
+      vd2.size = table_size * sizeof (void *);
+      VarDesc2 vd2g = { "table", 0 };
+
+      offload (__FILE__, __LINE__, device, "__offload_target_table_p2", 1,
+	       &vd2, &vd2g);
+    }
+}
+
+static void
+load_lib_and_get_table (int device, int lib_num, mapping_table *&table,
+			int &table_size)
+{
+  /* 1000 shared libraries with offloading ought to be enough for anybody.  */
+  struct TargetImage {
+    int64_t size;
+    char name[sizeof "lib000.so"];
+    char data[];
+  } __attribute__ ((packed));
+
+  void ***host_table_descr = (void ***) lib_descrs[lib_num].first;
+  void **host_func_start = host_table_descr[0];
+  void **host_func_end   = host_table_descr[1];
+  void **host_var_start  = host_table_descr[2];
+  void **host_var_end    = host_table_descr[3];
+
+  void **target_image_descr = (void **) lib_descrs[lib_num].second;
+  void *image_start = target_image_descr[0];
+  void *image_end   = target_image_descr[1];
+
+  TRACE ("() host_table_descr { %p, %p, %p, %p }", host_func_start,
+	 host_func_end, host_var_start, host_var_end);
+  TRACE ("() target_image_descr { %p, %p }", image_start, image_end);
+
+  int64_t image_size = (uintptr_t) image_end - (uintptr_t) image_start;
+  TargetImage *image
+    = (TargetImage *) malloc (sizeof (int64_t) + sizeof ("lib000.so")
+			      + image_size);
+  image->size = image_size;
+  sprintf (image->name, "lib%03d.so", lib_num);
+  memcpy (image->data, image_start, image->size);
+
+  TRACE ("() __offload_register_image %s { %p, %d }",
+	 image->name, image_start, image->size);
+  __offload_register_image (image);
+
+  int tgt_num_funcs = 0;
+  int tgt_num_vars = 0;
+  void **tgt_table = NULL;
+  get_target_table (device, tgt_num_funcs, tgt_num_vars, tgt_table);
+  free (image);
+
+  /* The func table contains only addresses, the var table contains addresses
+     and corresponding sizes.  */
+  int host_num_funcs = host_func_end - host_func_start;
+  int host_num_vars  = (host_var_end - host_var_start) / 2;
+  TRACE ("() host_num_funcs = %d, tgt_num_funcs = %d",
+	 host_num_funcs, tgt_num_funcs);
+  TRACE ("() host_num_vars = %d, tgt_num_vars = %d",
+	 host_num_vars, tgt_num_vars);
+  if (host_num_funcs != tgt_num_funcs)
+    {
+      fprintf (stderr, "%s: Can't map target functions\n", __FILE__);
+      exit (1);
+    }
+  if (host_num_vars != tgt_num_vars)
+    {
+      fprintf (stderr, "%s: Can't map target variables\n", __FILE__);
+      exit (1);
+    }
+
+  table = (mapping_table *) realloc (table, (table_size + host_num_funcs
+					     + host_num_vars)
+					    * sizeof (mapping_table));
+  if (table == NULL)
+    {
+      fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
+      exit (1);
+    }
+
+  for (int i = 0; i < host_num_funcs; i++)
+    {
+      mapping_table t;
+      t.host_start = (uintptr_t) host_func_start[i];
+      t.host_end = t.host_start + 1;
+      t.tgt_start = (uintptr_t) tgt_table[i];
+      t.tgt_end = t.tgt_start + 1;
+
+      TRACE ("() lib %d, func %d:\t0x%llx -- 0x%llx",
+	     lib_num, i, t.host_start, t.tgt_start);
+
+      table[table_size++] = t;
+    }
+
+  for (int i = 0; i < host_num_vars * 2; i += 2)
+    {
+      mapping_table t;
+      t.host_start = (uintptr_t) host_var_start[i];
+      t.host_end = t.host_start + (uintptr_t) host_var_start[i+1];
+      t.tgt_start = (uintptr_t) tgt_table[tgt_num_funcs+i];
+      t.tgt_end = t.tgt_start + (uintptr_t) tgt_table[tgt_num_funcs+i+1];
+
+      TRACE ("() lib %d, var %d:\t0x%llx (%d) -- 0x%llx (%d)", lib_num, i/2,
+	     t.host_start, t.host_end - t.host_start,
+	     t.tgt_start, t.tgt_end - t.tgt_start);
+
+      table[table_size++] = t;
+    }
+
+  delete [] tgt_table;
+}
+
+extern "C" int
+GOMP_OFFLOAD_get_table (int device, void *result)
+{
+  TRACE ("(num_libraries = %d)", num_libraries);
+
+  mapping_table *table = NULL;
+  int table_size = 0;
+
+  for (int i = 0; i < num_libraries; i++)
+    load_lib_and_get_table (device, i, table, table_size);
+
+  *(void **) result = table;
+  return table_size;
+}
+
+extern "C" void *
+GOMP_OFFLOAD_alloc (int device, size_t size)
+{
+  TRACE ("(size = %d)", size);
+
+  void *tgt_ptr;
+  VarDesc vd1[2] = { vd_host2tgt, vd_tgt2host };
+  vd1[0].ptr = &size;
+  vd1[0].size = sizeof (size);
+  vd1[1].ptr = &tgt_ptr;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd1g[2] = { { "size", 0 }, { "tgt_ptr", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_alloc", 2, vd1, vd1g);
+
+  return tgt_ptr;
+}
+
+extern "C" void
+GOMP_OFFLOAD_free (int device, void *tgt_ptr)
+{
+  TRACE ("(tgt_ptr = %p)", tgt_ptr);
+
+  VarDesc vd1 = vd_host2tgt;
+  vd1.ptr = &tgt_ptr;
+  vd1.size = sizeof (void *);
+  VarDesc2 vd1g = { "tgt_ptr", 0 };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_free", 1, &vd1, &vd1g);
+}
+
+extern "C" void *
+GOMP_OFFLOAD_host2dev (int device, void *tgt_ptr, const void *host_ptr,
+		       size_t size)
+{
+  TRACE ("(tgt_ptr = %p, host_ptr = %p, size = %d)", tgt_ptr, host_ptr, size);
+  if (!size)
+    return tgt_ptr;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &tgt_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &size;
+  vd1[1].size = sizeof (size);
+  VarDesc2 vd1g[2] = { { "tgt_ptr", 0 }, { "size", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p1", 2,
+	   vd1, vd1g);
+
+  VarDesc vd2 = vd_host2tgt;
+  vd2.ptr = (void *) host_ptr;
+  vd2.size = size;
+  VarDesc2 vd2g = { "var", 0 };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p2", 1,
+	   &vd2, &vd2g);
+
+  return tgt_ptr;
+}
+
+extern "C" void *
+GOMP_OFFLOAD_dev2host (int device, void *host_ptr, const void *tgt_ptr,
+		       size_t size)
+{
+  TRACE ("(host_ptr = %p, tgt_ptr = %p, size = %d)", host_ptr, tgt_ptr, size);
+  if (!size)
+    return host_ptr;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &tgt_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &size;
+  vd1[1].size = sizeof (size);
+  VarDesc2 vd1g[2] = { { "tgt_ptr", 0 }, { "size", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p1", 2,
+	   vd1, vd1g);
+
+  VarDesc vd2 = vd_tgt2host;
+  vd2.ptr = (void *) host_ptr;
+  vd2.size = size;
+  VarDesc2 vd2g = { "var", 0 };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p2", 1,
+	   &vd2, &vd2g);
+
+  return host_ptr;
+}
+
+extern "C" void
+GOMP_OFFLOAD_run (int device, void *tgt_fn, void *tgt_vars)
+{
+  TRACE ("(tgt_fn = %p, tgt_vars = %p)", tgt_fn, tgt_vars);
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &tgt_fn;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &tgt_vars;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd1g[2] = { { "tgt_fn", 0 }, { "tgt_vars", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_run", 2, vd1, vd1g);
+}
diff --git a/liboffloadmic/plugin/offload_target_main.cpp b/liboffloadmic/plugin/offload_target_main.cpp
new file mode 100644
index 0000000..4a2778e
--- /dev/null
+++ b/liboffloadmic/plugin/offload_target_main.cpp
@@ -0,0 +1,366 @@
+/* Plugin for offload execution on Intel MIC devices.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   Contributed by Ilya Verbin <ilya.verbin@intel.com>.
+
+   This file is part of the GNU OpenMP Library (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Target side part of a libgomp plugin.  */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "compiler_if_target.h"
+
+
+#ifdef DEBUG
+#define TRACE(...)					      \
+{							      \
+fprintf (stderr, "TARGET:\t%s:%s ", __FILE__, __FUNCTION__);  \
+fprintf (stderr, __VA_ARGS__);				      \
+fprintf (stderr, "\n");					      \
+}
+#else
+#define TRACE { }
+#endif
+
+
+static VarDesc vd_host2tgt = {
+  { 1, 1 },		      /* dst, src			      */
+  { 1, 0 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+static VarDesc vd_tgt2host = {
+  { 1, 1 },		      /* dst, src			      */
+  { 0, 1 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+/* Pointer to the descriptor of the last loaded shared library.  */
+static void *last_loaded_library = NULL;
+
+/* Pointer and size of the variable, used in __offload_target_host2tgt_p[12]
+   and __offload_target_tgt2host_p[12].  */
+static void *last_var_ptr = NULL;
+static int last_var_size = 0;
+
+
+/* Override the corresponding functions from libgomp.  */
+extern "C" int
+omp_is_initial_device (void) __GOMP_NOTHROW
+{
+  return 0;
+}
+
+extern "C" int32_t
+omp_is_initial_device_ (void)
+{
+  return omp_is_initial_device ();
+}
+
+
+/* Dummy function needed for the initialization of target process during the
+   first call to __offload_offload1.  */
+static void
+__offload_target_init_proc (OFFLOAD ofldt)
+{
+  TRACE ("");
+}
+
+/* Collect addresses of the offload functions and of the global variables from
+   the library descriptor and send them to host.
+   Part 1: Send num_funcs and num_vars to host.  */
+static void
+__offload_target_table_p1 (OFFLOAD ofldt)
+{
+  void ***lib_descr = (void ***) last_loaded_library;
+
+  if (lib_descr == NULL)
+    {
+      TRACE ("");
+      fprintf (stderr, "Error! No shared libraries loaded on target.\n");
+      return;
+    }
+
+  void **func_table_begin = lib_descr[0];
+  void **func_table_end   = lib_descr[1];
+  void **var_table_begin  = lib_descr[2];
+  void **var_table_end    = lib_descr[3];
+
+  /* The func table contains only addresses, the var table contains addresses
+     and corresponding sizes.  */
+  int num_funcs = func_table_end - func_table_begin;
+  int num_vars = (var_table_end - var_table_begin) / 2;
+  TRACE ("(num_funcs = %d, num_vars = %d)", num_funcs, num_vars);
+
+  VarDesc vd1[2] = { vd_tgt2host, vd_tgt2host };
+  vd1[0].ptr = &num_funcs;
+  vd1[0].size = sizeof (num_funcs);
+  vd1[1].ptr = &num_vars;
+  vd1[1].size = sizeof (num_vars);
+  VarDesc2 vd2[2] = { { "num_funcs", 0 }, { "num_vars", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  __offload_target_leave (ofldt);
+}
+
+/* Part 2: Send the table with addresses to host.  */
+static void
+__offload_target_table_p2 (OFFLOAD ofldt)
+{
+  void ***lib_descr = (void ***) last_loaded_library;
+  void **func_table_begin = lib_descr[0];
+  void **func_table_end   = lib_descr[1];
+  void **var_table_begin  = lib_descr[2];
+  void **var_table_end    = lib_descr[3];
+
+  int num_funcs = func_table_end - func_table_begin;
+  int num_vars = (var_table_end - var_table_begin) / 2;
+  int table_size = (num_funcs + 2 * num_vars) * sizeof (void *);
+  void **table = (void **) malloc (table_size);
+  TRACE ("(table_size = %d)", table_size);
+
+  VarDesc vd1;
+  vd1 = vd_tgt2host;
+  vd1.ptr = table;
+  vd1.size = table_size;
+  VarDesc2 vd2 = { "table", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+
+  void **p;
+  int i = 0;
+  for (p = func_table_begin; p < func_table_end; p++, i++)
+    table[i] = *p;
+
+  for (p = var_table_begin; p < var_table_end; p++, i++)
+    table[i] = *p;
+
+  __offload_target_leave (ofldt);
+  free (table);
+}
+
+/* Allocate size bytes and send a pointer to the allocated memory to host.  */
+static void
+__offload_target_alloc (OFFLOAD ofldt)
+{
+  size_t size = 0;
+  void *ptr = NULL;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_tgt2host };
+  vd1[0].ptr = &size;
+  vd1[0].size = sizeof (size);
+  vd1[1].ptr = &ptr;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd2[2] = { { "size", 0 }, { "ptr", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  ptr = malloc (size);
+  TRACE ("(size = %d): ptr = %p", size, ptr);
+  __offload_target_leave (ofldt);
+}
+
+/* Free the memory space pointed to by ptr.  */
+static void
+__offload_target_free (OFFLOAD ofldt)
+{
+  void *ptr = 0;
+
+  VarDesc vd1 = vd_host2tgt;
+  vd1.ptr = &ptr;
+  vd1.size = sizeof (void *);
+  VarDesc2 vd2 = { "ptr", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+  TRACE ("(ptr = %p)", ptr);
+  free (ptr);
+  __offload_target_leave (ofldt);
+}
+
+/* Receive var_size bytes from host and store to var_ptr.
+   Part 1: Receive var_ptr and var_size from host.  */
+static void
+__offload_target_host2tgt_p1 (OFFLOAD ofldt)
+{
+  void *var_ptr = NULL;
+  size_t var_size = 0;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &var_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &var_size;
+  vd1[1].size = sizeof (var_size);
+  VarDesc2 vd2[2] = { { "var_ptr", 0 }, { "var_size", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  TRACE ("(var_ptr = %p, var_size = %d)", var_ptr, var_size);
+  last_var_ptr = var_ptr;
+  last_var_size = var_size;
+  __offload_target_leave (ofldt);
+}
+
+/* Part 2: Receive the data from host.  */
+static void
+__offload_target_host2tgt_p2 (OFFLOAD ofldt)
+{
+  TRACE ("(last_var_ptr = %p, last_var_size = %d)",
+	 last_var_ptr, last_var_size);
+
+  VarDesc vd1 = vd_host2tgt;
+  vd1.ptr = last_var_ptr;
+  vd1.size = last_var_size;
+  VarDesc2 vd2 = { "var", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+  __offload_target_leave (ofldt);
+}
+
+/* Send var_size bytes from var_ptr to host.
+   Part 1: Receive var_ptr and var_size from host.  */
+static void
+__offload_target_tgt2host_p1 (OFFLOAD ofldt)
+{
+  void *var_ptr = NULL;
+  size_t var_size = 0;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &var_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &var_size;
+  vd1[1].size = sizeof (var_size);
+  VarDesc2 vd2[2] = { { "var_ptr", 0 }, { "var_size", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  TRACE ("(var_ptr = %p, var_size = %d)", var_ptr, var_size);
+  last_var_ptr = var_ptr;
+  last_var_size = var_size;
+  __offload_target_leave (ofldt);
+}
+
+/* Part 2: Send the data to host.  */
+static void
+__offload_target_tgt2host_p2 (OFFLOAD ofldt)
+{
+  TRACE ("(last_var_ptr = %p, last_var_size = %d)",
+	 last_var_ptr, last_var_size);
+
+  VarDesc vd1 = vd_tgt2host;
+  vd1.ptr = last_var_ptr;
+  vd1.size = last_var_size;
+  VarDesc2 vd2 = { "var", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+  __offload_target_leave (ofldt);
+}
+
+/* Call offload function by the address fn_ptr and pass vars_ptr to it.  */
+static void
+__offload_target_run (OFFLOAD ofldt)
+{
+  void *fn_ptr;
+  void *vars_ptr;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &fn_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &vars_ptr;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd2[2] = { { "fn_ptr", 0 }, { "vars_ptr", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  TRACE ("(fn_ptr = %p, vars_ptr = %p)", fn_ptr, vars_ptr);
+  void (*fn)(void *) = (void (*)(void *)) fn_ptr;
+  fn (vars_ptr);
+  __offload_target_leave (ofldt);
+}
+
+
+/* This should be called from every library with offloading.  */
+extern "C" void
+target_register_lib (const void *target_table)
+{
+  TRACE ("(target_table = %p { %p, %p, %p, %p })", target_table,
+	 ((void **) target_table)[0], ((void **) target_table)[1],
+	 ((void **) target_table)[2], ((void **) target_table)[3]);
+
+  last_loaded_library = (void *) target_table;
+}
+
+/* Use __offload_target_main from liboffload.  */
+int
+main (int argc, char **argv)
+{
+  __offload_target_main ();
+  return 0;
+}
+
+
+/* Register offload_target_main's functions in the liboffload.  */
+
+struct Entry {
+  const char *name;
+  void *func;
+};
+
+#define REGISTER(f)				      \
+extern "C" const Entry __offload_target_##f##_$entry  \
+__attribute__ ((section(".OffloadEntryTable."))) = {  \
+  "__offload_target_"#f,			      \
+  (void *) __offload_target_##f			      \
+}
+REGISTER (init_proc);
+REGISTER (table_p1);
+REGISTER (table_p2);
+REGISTER (alloc);
+REGISTER (free);
+REGISTER (host2tgt_p1);
+REGISTER (host2tgt_p2);
+REGISTER (tgt2host_p1);
+REGISTER (tgt2host_p2);
+REGISTER (run);
+#undef REGISTER
-- 
1.7.1

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2014-10-21 17:20 ` [PATCH 1/4] Add mkoffload for " Ilya Verbin
@ 2014-10-21 21:58   ` Joseph S. Myers
  2014-10-21 22:31     ` Ilya Verbin
  2014-10-22  8:27   ` Jakub Jelinek
  2015-03-06 13:55   ` [PATCH] Fix intelmic-mkoffload " Ilya Verbin
  2 siblings, 1 reply; 111+ messages in thread
From: Joseph S. Myers @ 2014-10-21 21:58 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: Jakub Jelinek, gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Tue, 21 Oct 2014, Ilya Verbin wrote:

> +#include <libgen.h>
> +#include "config.h"
> +#include "system.h"

You should never include system headers before config.h because config.h 
may define feature test macros such as _FILE_OFFSET_BITS=64 that are 
ineffective if defined after any system header is included.

I don't see anything restricting this program to being built for GNU 
*hosts*.  Thus, it needs to be portable (to different hosts; obviously 
it's target-architecture-specific) rather than relying on glibc 
interfaces.  (Providing appropriate functions in libiberty is of course an 
option; thus, freely using obstacks is fine because they're in libiberty.)

> +#include <libgomp_target.h>

Where does this header come from?

> +      nextval = strchrnul (curval, ':');

I don't think strchrnul is portable (unless added to libiberty).

> +  if (!host_compiler)
> +    fatal_error ("COLLECT_GCC must be set.");

Diagnostics should not end with ".".

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2014-10-21 21:58   ` Joseph S. Myers
@ 2014-10-21 22:31     ` Ilya Verbin
  2014-10-22  7:59       ` Jakub Jelinek
  0 siblings, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2014-10-21 22:31 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: Jakub Jelinek, gcc, Kirill Yukhin, Andrey Turetskiy

2014-10-22 1:55 GMT+04:00 Joseph S. Myers <joseph@codesourcery.com>:
> On Tue, 21 Oct 2014, Ilya Verbin wrote:
>
>> +#include <libgen.h>
>> +#include "config.h"
>> +#include "system.h"
>
> You should never include system headers before config.h because config.h
> may define feature test macros such as _FILE_OFFSET_BITS=64 that are
> ineffective if defined after any system header is included.

I will fix this.

> I don't see anything restricting this program to being built for GNU
> *hosts*.  Thus, it needs to be portable (to different hosts; obviously
> it's target-architecture-specific) rather than relying on glibc
> interfaces.  (Providing appropriate functions in libiberty is of course an
> option; thus, freely using obstacks is fine because they're in libiberty.)

This mkoffload is expected to be built only with the offload compiler,
which is expected to be configured with
'--enable-as-accelerator-for=... --host=x86_64-*-linux-gnu
--target=x86_64-*-linux-gnu'.
Without $enable_as_accelerator it wouldn't be built. I will add more
restrictions to config.gcc.

>> +#include <libgomp_target.h>
>
> Where does this header come from?

It comes from libgomp directory (
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg00475.html ).

>> +      nextval = strchrnul (curval, ':');
>
> I don't think strchrnul is portable (unless added to libiberty).

It seems that there is no need to make this mkoffload so portable.

>> +  if (!host_compiler)
>> +    fatal_error ("COLLECT_GCC must be set.");
>
> Diagnostics should not end with ".".

I will fix all fatal_errors.

Thanks,
  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2014-10-21 22:31     ` Ilya Verbin
@ 2014-10-22  7:59       ` Jakub Jelinek
  0 siblings, 0 replies; 111+ messages in thread
From: Jakub Jelinek @ 2014-10-22  7:59 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: Joseph S. Myers, gcc, Kirill Yukhin, Andrey Turetskiy

On Wed, Oct 22, 2014 at 02:30:44AM +0400, Ilya Verbin wrote:
> > I don't see anything restricting this program to being built for GNU
> > *hosts*.  Thus, it needs to be portable (to different hosts; obviously
> > it's target-architecture-specific) rather than relying on glibc
> > interfaces.  (Providing appropriate functions in libiberty is of course an
> > option; thus, freely using obstacks is fine because they're in libiberty.)
> 
> This mkoffload is expected to be built only with the offload compiler,
> which is expected to be configured with
> '--enable-as-accelerator-for=... --host=x86_64-*-linux-gnu
> --target=x86_64-*-linux-gnu'.
> Without $enable_as_accelerator it wouldn't be built. I will add more
> restrictions to config.gcc.

But why the --host=x86_64-*-linux-gnu restriction?
mkoffload looks to me like a typical host tool, but I don't understand
why it would require native compilation, it is a tool that arranges that
the offloading target compiler is invoked, and results linked back, but it
doesn't need to execute anything on the target, you don't need access to the
acceleration device for that and I don't see any reason why it couldn't be
run on s390-linux, or say mingw.
Both the primary compiler and offloading target compilers obviously have to
be configured for the same (or similar?) host, the target (for what they
generate code for) is given for both too (unless we start supporting say
powerpc64-linux primary compiler offloading to Intel MIC etc.) and build
irrelevant (e.g. you could build offloading compiler using canadian cross
with --enable-as-accelerator-for=x86_64-pc-linux --build=aarch64-linux \
--host=s390-linux --target=x86_64-intelmicemul-linux
and primary compiler with
--enable-offload-targets=x86_64-intelmicemul-linux-gnu=/some/path/ \
--build=armv7tel-linux-gnueabi --host=s390-linux --target=x86_64-pc-linux
).  Or do you see any substantial reasons why this can't work?

> >> +      nextval = strchrnul (curval, ':');
> >
> > I don't think strchrnul is portable (unless added to libiberty).
> 
> It seems that there is no need to make this mkoffload so portable.

I disagree, see above.  I think this isn't so performance critical code
that you can't just use portable:
  nextval = strchr (curval, ':');
  if (nextval == NULL)
    nextval = strchr (curval, '\0');

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2014-10-21 17:20 ` [PATCH 1/4] Add mkoffload for " Ilya Verbin
  2014-10-21 21:58   ` Joseph S. Myers
@ 2014-10-22  8:27   ` Jakub Jelinek
  2014-10-22 18:57     ` Ilya Verbin
  2015-03-06 13:55   ` [PATCH] Fix intelmic-mkoffload " Ilya Verbin
  2 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2014-10-22  8:27 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Tue, Oct 21, 2014 at 09:16:02PM +0400, Ilya Verbin wrote:
> --- a/gcc/Makefile.in
> +++ b/gcc/Makefile.in
> @@ -3895,3 +3895,14 @@ DEPFILES = \
>    $(foreach obj,$(ALL_HOST_OBJS),\
>      $(dir $(obj))$(DEPDIR)/$(patsubst %.o,%.Po,$(notdir $(obj))))
>  -include $(DEPFILES)
> +
> +
> +mkoffload.o: $(srcdir)/config/intelmic/mkoffload.c | insn-modes.h
> +	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
> +	  -I$(srcdir)/../libgomp \
> +	  -DDEFAULT_REAL_TARGET_MACHINE=\"$(real_target_noncanonical)\" \
> +	  -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
> +	  $< $(OUTPUT_OPTION)
> +
> +mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
> +	$(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)

I don't like this.  I thought every offloading target will have its own
mkoffload binary, so hardcoding a particular mkoffload implementation in
the generic Makefile.in looks very much wrong.  The rules should come from
some config/i386/t-intelmic target snippet enabled by config.gcc.

Also, is there a reason why do you want to use config/intelmic/
subdirectory?  Is there any plan to make intelmic offloading for different
ISA than x86_64?  I mean, even K10M would use i386/ backend, if it got
added, right?
So, I'd use config/i386/t-intelmic and config/i386/intelmic-mkoffload.c .
> +
> +/* Delete tempfiles and exit function.  */
> +void
> +tool_cleanup (__attribute__((unused)) bool from_signal)

boo from_signal ATTRIBUTE_UNUSED ?

> +  values = (char**) xmalloc (num * sizeof (char*));

Formatting, spaces before *, so char ** and char *.

> +  curval = str;
> +  nextval = strchrnul (curval, ':');
> +
> +  for (i = 0; i < num; i++)
> +    {
> +      int l = nextval - curval;
> +      values[i] = (char*) xmalloc (l + 1);

Idem.

> +  /* Objcopy has created symbols, containing the input file name with
> +     special characters replaced with '_'.  We are going to rename these
> +     new symbols.  */
> +  char *symbol_name = XALLOCAVEC (char, strlen (target_so_filename) + 1);
> +  int i = 0;
> +  while (target_so_filename[i])
> +    {
> +      char c = target_so_filename[i];
> +      if ((c == '/') || (c == '.'))
> +	c = '_';
> +      symbol_name[i] = c;
> +      i++;
> +    }
> +  symbol_name[i] = 0;

So, you certainly know strlen (symbol_name) here.

> +  char *opt_for_objcopy[3];
> +  opt_for_objcopy[0] = XALLOCAVEC (char, sizeof ("_binary__start=")
> +					 + strlen (symbol_name)

Thus you can use it here etc. (or rename i to symbol_name_len).

> +					 + strlen (symbols[0]));
> +  opt_for_objcopy[1] = XALLOCAVEC (char, sizeof ("_binary__end=")
> +					 + strlen (symbol_name)

Likewise.

> +					 + strlen (symbols[1]));
> +  opt_for_objcopy[2] = XALLOCAVEC (char, sizeof ("_binary__size=")
> +					 + strlen (symbol_name)

Likewise.

> +					 + strlen (symbols[2]));
> +  sprintf (opt_for_objcopy[0], "_binary_%s_start=%s", symbol_name, symbols[0]);
> +  sprintf (opt_for_objcopy[1], "_binary_%s_end=%s", symbol_name, symbols[1]);
> +  sprintf (opt_for_objcopy[2], "_binary_%s_size=%s", symbol_name, symbols[2]);
> +
> +  obstack_init (&argv_obstack);
> +  obstack_ptr_grow (&argv_obstack, "objcopy");
> +  obstack_ptr_grow (&argv_obstack, target_so_filename);
> +  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
> +  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[0]);
> +  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
> +  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[1]);
> +  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
> +  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[2]);
> +  obstack_ptr_grow (&argv_obstack, NULL);
> +  new_argv = XOBFINISH (&argv_obstack, char **);

Why do you use an obstack for an array of pointers where you know
you have exactly 9 pointers?  Wouldn't
  char *new_argv[9];
and just pointer assignments be better?

> +  fork_execute (new_argv[0], new_argv, false);
> +  obstack_free (&argv_obstack, NULL);
> +
> +  return target_so_filename;
> +}
> +
> +int
> +main (int argc, char **argv)
> +{
> +  progname = "mkoffload-intelmic";
> +  gcc_init_libintl ();
> +  diagnostic_initialize (global_dc, 0);
> +
> +  if (atexit (mkoffload_atexit) != 0)
> +    fatal_error ("atexit failed");
> +
> +  const char *host_compiler = getenv ("COLLECT_GCC");
> +  if (!host_compiler)
> +    fatal_error ("COLLECT_GCC must be set.");
> +
> +  const char *target_driver_name
> +    = DEFAULT_REAL_TARGET_MACHINE "-accel-" DEFAULT_TARGET_MACHINE "-gcc";
> +  char *target_compiler = find_target_compiler (target_driver_name);
> +  if (target_compiler == NULL)
> +    fatal_error ("offload compiler %s not found.", target_driver_name);
> +
> +  /* We may be called with all the arguments stored in some file and
> +     passed with @file.  Expand them into argv before processing.  */
> +  expandargv (&argc, &argv);
> +
> +  /* Find out whether we should compile binaries for i386 or x86-64.  */
> +  for (int i = argc - 1; i > 0; i--)
> +    if (strncmp (argv[i], "-foffload-abi=", strlen ("-foffload-abi=")) == 0)
> +      {
> +	if (strstr (argv[i], "ilp32"))
> +	  target_ilp32 = true;
> +	else if (!strstr (argv[i], "lp64"))
> +	  fatal_error ("unrecognizable argument of option -foffload-abi");
> +	break;
> +      }
> +
> +  const char *target_so_filename
> +    = prepare_target_image (target_compiler, argc, argv);
> +
> +  const char *host_descr_filename = generate_host_descr_file (host_compiler);
> +
> +  /* Perform partial linking for the target image and host side descriptor.
> +     As a result we'll get a finalized object file with all offload data.  */
> +  struct obstack argv_obstack;
> +  obstack_init (&argv_obstack);
> +  obstack_ptr_grow (&argv_obstack, "ld");
> +  if (target_ilp32)
> +    {
> +      obstack_ptr_grow (&argv_obstack, "-m");
> +      obstack_ptr_grow (&argv_obstack, "elf_i386");
> +    }
> +  obstack_ptr_grow (&argv_obstack, "-r");
> +  obstack_ptr_grow (&argv_obstack, host_descr_filename);
> +  obstack_ptr_grow (&argv_obstack, target_so_filename);
> +  obstack_ptr_grow (&argv_obstack, "-o");
> +  obstack_ptr_grow (&argv_obstack, out_obj_filename);
> +  obstack_ptr_grow (&argv_obstack, NULL);
> +  char **new_argv = XOBFINISH (&argv_obstack, char **);

Similarly (well, here it is not constant, still, you know small upper bound
and can just use some int index you ++ in each assignment.

> +  /* Run objcopy on the resultant object file to localize generated symbols
> +     to avoid conflicting between different DSO and an executable.  */
> +  obstack_init (&argv_obstack);
> +  obstack_ptr_grow (&argv_obstack, "objcopy");
> +  obstack_ptr_grow (&argv_obstack, "-L");
> +  obstack_ptr_grow (&argv_obstack, symbols[0]);
> +  obstack_ptr_grow (&argv_obstack, "-L");
> +  obstack_ptr_grow (&argv_obstack, symbols[1]);
> +  obstack_ptr_grow (&argv_obstack, "-L");
> +  obstack_ptr_grow (&argv_obstack, symbols[2]);
> +  obstack_ptr_grow (&argv_obstack, out_obj_filename);
> +  obstack_ptr_grow (&argv_obstack, NULL);
> +  new_argv = XOBFINISH (&argv_obstack, char **);
> +  fork_execute (new_argv[0], new_argv, false);
> +  obstack_free (&argv_obstack, NULL);

Likewise.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 2/4] Add liboffloadmic
  2014-10-21 17:24 ` [PATCH 2/4] Add liboffloadmic Ilya Verbin
@ 2014-10-22  8:55   ` Jakub Jelinek
  2014-10-22 17:13     ` Joseph S. Myers
  2014-10-22 19:31     ` Ilya Verbin
  2014-12-12 10:46   ` Thomas Schwinge
  2015-07-09 10:00   ` Thomas Schwinge
  2 siblings, 2 replies; 111+ messages in thread
From: Jakub Jelinek @ 2014-10-22  8:55 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Tue, Oct 21, 2014 at 09:20:34PM +0400, Ilya Verbin wrote:
> This patch contains liboffloadmic library.
> 
> It is used by ICC for offloading.  The sources are imported from upstream
> ( https://www.openmprtl.org/sites/default/files/liboffload_oss.tgz )
> Configure and makefiles are new.
> 
> Also liboffloadmic/runtime/emulator directory is new.  This emulator consists
> of 4 shared libraries which replace COI and MYO libraries from MPSS stack.

For the real offloading rather than emulation, are there any further
libraries needed, or are the COI and MYO bits included in the source
everything that is needed?  Does one need some kernel module, will it be
open source, are there any plans to push it to Linus' tree?
I know the HW isn't shipping yet, but it would be nice to get those
questions answered now.

In git, I see that liboffloadmic/Makefile.am has -rwxrwxr-x permissions,
please avoid that, only use executable permissions for shell scripts (so,
configure is fine and desirable).

From quick look at git, write_message has been supposedly fixed to use
va_list, but I see it is wrong:

    void write_message(FILE * file, int msgCode, va_list args_p) {
        va_list args;
        char buf[1024];

        va_copy(args, args_p);
        buf[0] = '\r';
        vsnprintf(buf + 1, sizeof(buf), MESSAGE_TABLE_NAME[ msgCode ], args);
        strcat(buf, "\n");
        va_end(args);
        fputs(buf, file);
        fflush(file);
    }

As vsnprintf's first argument is buf + 1, it might happily overflow the
buffer, and if not that, then the strcat could too.
So, I'd expect sizeof(buf) - 2 be needed there instead of sizeof(buf).
Also, do we really want the messy DOS/Windows '\r' in the messages on
Unix-ish targets?  Shouldn't that be dependent on what target is the library
configured for?

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2014-10-21 17:28 ` [PATCH 3/4] Add libgomp plugin for Intel MIC Ilya Verbin
@ 2014-10-22  9:47   ` Jakub Jelinek
  2014-10-23 16:00     ` Ilya Verbin
  2015-07-08 14:16   ` Thomas Schwinge
  1 sibling, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2014-10-22  9:47 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Tue, Oct 21, 2014 at 09:24:13PM +0400, Ilya Verbin wrote:
> +/* Add path specified in LD_LIBRARY_PATH to MIC_LD_LIBRARY_PATH, which is
> +   required by liboffloadmic.  */
> +__attribute__((constructor))
> +static void
> +set_mic_lib_path (void)
> +{
> +  const char *ld_lib_path = getenv (LD_LIBRARY_PATH_ENV);
> +  const char *mic_lib_path = getenv (MIC_LD_LIBRARY_PATH_ENV);
> +  char *mic_lib_path_new;
> +
> +  if (!ld_lib_path)
> +    return;
> +
> +  mic_lib_path_new = (char *) malloc ((mic_lib_path ? strlen (mic_lib_path) : 0)
> +				      + strlen (ld_lib_path) + 2);

malloc can fail, SIGSEGV in response to that is not desirable.
Can't you fallback to alloca, or use just alloca, or use alloca
with malloc fallback?
> + 
> +  if (!mic_lib_path)
> +    strcpy (mic_lib_path_new, ld_lib_path);
> +  else
> +    sprintf (mic_lib_path_new, "%s:%s", mic_lib_path, ld_lib_path);
> +  setenv (MIC_LD_LIBRARY_PATH_ENV, mic_lib_path_new, 1);
> +  free (mic_lib_path_new);

> +extern "C" void
> +GOMP_OFFLOAD_register_image (void *host_table, void *target_image)
> +{
> +  TRACE ("(host_table = %p, target_image = %p)", host_table, target_image);
> +
> +  if (num_libraries >= 1000)
> +    {
> +      fprintf (stderr,
> +	       "%s: The number of loaded shared libraries is over 1000!\n",
> +	       __FILE__);
> +      exit (1);

Where does this artificial limit come from?  Using libNNN.so library names?
Can't you use lib%d.so instead?

Also, seeing register_image, shouldn't there be
GOMP_OFFLOAD_unregister_image which would be invoked when the library
containing MIC offloading regions is dlclosed?
One could use __cxa_atexit or similar for that, something that is given
&__dso_handle.  Or is no cleanup necessary?  At least unregistering it
from translation tables, because the same addresses might be reused by a
different shared library?
With dlopen/dlclose in mind, 1000 might be easily reached, consider 10000
times dlopening/dlclosing (perhaps over longer time, by long running daemon)
a shared library containg #pragma omp target region.

> +static int first_init = 1;
> +
> +/* Load offload_target_main on target.  */
> +extern "C" void
> +GOMP_OFFLOAD_init_device (int device)
> +{
> +  TRACE ("");
> +  pthread_mutex_lock (&mutex);
> +  if (first_init)
> +    {
> +      __offload_register_image (&main_target_image);
> +      first_init = 0;
> +    }
> +  pthread_mutex_unlock (&mutex);

pthread_once instead?

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 2/4] Add liboffloadmic
  2014-10-22  8:55   ` Jakub Jelinek
@ 2014-10-22 17:13     ` Joseph S. Myers
  2014-10-22 19:31     ` Ilya Verbin
  1 sibling, 0 replies; 111+ messages in thread
From: Joseph S. Myers @ 2014-10-22 17:13 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Ilya Verbin, gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Wed, 22 Oct 2014, Jakub Jelinek wrote:

> Also, do we really want the messy DOS/Windows '\r' in the messages on
> Unix-ish targets?  Shouldn't that be dependent on what target is the library
> configured for?

On platforms where it matters, I think it's still right to use \n only - 
if in the end something is output on a text stream, it's stdio's job to 
convert \n to \r\n as needed.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2014-10-22  8:27   ` Jakub Jelinek
@ 2014-10-22 18:57     ` Ilya Verbin
  2014-11-03 17:36       ` [gomp4] Mark fopenacc as LTO option Tom de Vries
                         ` (5 more replies)
  0 siblings, 6 replies; 111+ messages in thread
From: Ilya Verbin @ 2014-10-22 18:57 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On 22 Oct 09:57, Jakub Jelinek wrote:
> On Wed, Oct 22, 2014 at 02:30:44AM +0400, Ilya Verbin wrote:
> > This mkoffload is expected to be built only with the offload compiler,
> > which is expected to be configured with
> > '--enable-as-accelerator-for=... --host=x86_64-*-linux-gnu
> > --target=x86_64-*-linux-gnu'.
> > Without $enable_as_accelerator it wouldn't be built. I will add more
> > restrictions to config.gcc.
> 
> But why the --host=x86_64-*-linux-gnu restriction?
> mkoffload looks to me like a typical host tool, but I don't understand
> why it would require native compilation, it is a tool that arranges that
> the offloading target compiler is invoked, and results linked back, but it
> doesn't need to execute anything on the target, you don't need access to the
> acceleration device for that and I don't see any reason why it couldn't be
> run on s390-linux, or say mingw.
> Both the primary compiler and offloading target compilers obviously have to
> be configured for the same (or similar?) host, the target (for what they
> generate code for) is given for both too (unless we start supporting say
> powerpc64-linux primary compiler offloading to Intel MIC etc.) and build
> irrelevant (e.g. you could build offloading compiler using canadian cross
> with --enable-as-accelerator-for=x86_64-pc-linux --build=aarch64-linux \
> --host=s390-linux --target=x86_64-intelmicemul-linux
> and primary compiler with
> --enable-offload-targets=x86_64-intelmicemul-linux-gnu=/some/path/ \
> --build=armv7tel-linux-gnueabi --host=s390-linux --target=x86_64-pc-linux
> ).  Or do you see any substantial reasons why this can't work?

There are no substantial reasons, we simply don't expect that someone will build
MIC offloading compiler using systems other than x86 linux.
Maybe we will support mingw in the future...
Anyway, I'll try to make mkoffload portable.

> > >> +      nextval = strchrnul (curval, ':');
> > >
> > > I don't think strchrnul is portable (unless added to libiberty).
> > 
> > It seems that there is no need to make this mkoffload so portable.
> 
> I disagree, see above.  I think this isn't so performance critical code
> that you can't just use portable:
>   nextval = strchr (curval, ':');
>   if (nextval == NULL)
>     nextval = strchr (curval, '\0');

Done, strchrnul is replaced with strchr.

On 22 Oct 10:21, Jakub Jelinek wrote:
> On Tue, Oct 21, 2014 at 09:16:02PM +0400, Ilya Verbin wrote:
> > --- a/gcc/Makefile.in
> > +++ b/gcc/Makefile.in
> > @@ -3895,3 +3895,14 @@ DEPFILES = \
> >    $(foreach obj,$(ALL_HOST_OBJS),\
> >      $(dir $(obj))$(DEPDIR)/$(patsubst %.o,%.Po,$(notdir $(obj))))
> >  -include $(DEPFILES)
> > +
> > +
> > +mkoffload.o: $(srcdir)/config/intelmic/mkoffload.c | insn-modes.h
> > +	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
> > +	  -I$(srcdir)/../libgomp \
> > +	  -DDEFAULT_REAL_TARGET_MACHINE=\"$(real_target_noncanonical)\" \
> > +	  -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
> > +	  $< $(OUTPUT_OPTION)
> > +
> > +mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
> > +	$(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)
> 
> I don't like this.  I thought every offloading target will have its own
> mkoffload binary, so hardcoding a particular mkoffload implementation in
> the generic Makefile.in looks very much wrong.  The rules should come from
> some config/i386/t-intelmic target snippet enabled by config.gcc.

Missed that, fixed.
 
> Also, is there a reason why do you want to use config/intelmic/
> subdirectory?  Is there any plan to make intelmic offloading for different
> ISA than x86_64?  I mean, even K10M would use i386/ backend, if it got
> added, right?
> So, I'd use config/i386/t-intelmic and config/i386/intelmic-mkoffload.c .

Right, the ISA would be x86_64, so I moved it to i386/intelmic-mkoffload.c .

> > +/* Delete tempfiles and exit function.  */
> > +void
> > +tool_cleanup (__attribute__((unused)) bool from_signal)
> 
> boo from_signal ATTRIBUTE_UNUSED ?

Done.

> > +  values = (char**) xmalloc (num * sizeof (char*));
> 
> Formatting, spaces before *, so char ** and char *.

Fixed.

> > +      values[i] = (char*) xmalloc (l + 1);
> 
> Idem.

Fixed.

> > +  /* Objcopy has created symbols, containing the input file name with
> > +     special characters replaced with '_'.  We are going to rename these
> > +     new symbols.  */
> > +  char *symbol_name = XALLOCAVEC (char, strlen (target_so_filename) + 1);
> > +  int i = 0;
> > +  while (target_so_filename[i])
> > +    {
> > +      char c = target_so_filename[i];
> > +      if ((c == '/') || (c == '.'))
> > +	c = '_';
> > +      symbol_name[i] = c;
> > +      i++;
> > +    }
> > +  symbol_name[i] = 0;
> 
> So, you certainly know strlen (symbol_name) here.
> 
> > +  char *opt_for_objcopy[3];
> > +  opt_for_objcopy[0] = XALLOCAVEC (char, sizeof ("_binary__start=")
> > +					 + strlen (symbol_name)
> 
> Thus you can use it here etc. (or rename i to symbol_name_len).

Done.

> > +  opt_for_objcopy[1] = XALLOCAVEC (char, sizeof ("_binary__end=")
> > +					 + strlen (symbol_name)
> 
> Likewise.

Done.

> > +  opt_for_objcopy[2] = XALLOCAVEC (char, sizeof ("_binary__size=")
> > +					 + strlen (symbol_name)
> 
> Likewise.

Done.

> > +  obstack_init (&argv_obstack);
> > +  obstack_ptr_grow (&argv_obstack, "objcopy");
> > +  obstack_ptr_grow (&argv_obstack, target_so_filename);
> > +  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
> > +  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[0]);
> > +  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
> > +  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[1]);
> > +  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
> > +  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[2]);
> > +  obstack_ptr_grow (&argv_obstack, NULL);
> > +  new_argv = XOBFINISH (&argv_obstack, char **);
> 
> Why do you use an obstack for an array of pointers where you know
> you have exactly 9 pointers?  Wouldn't
>   char *new_argv[9];
> and just pointer assignments be better?

Yes, done.

> > +  /* Perform partial linking for the target image and host side descriptor.
> > +     As a result we'll get a finalized object file with all offload data.  */
> > +  struct obstack argv_obstack;
> > +  obstack_init (&argv_obstack);
> > +  obstack_ptr_grow (&argv_obstack, "ld");
> > +  if (target_ilp32)
> > +    {
> > +      obstack_ptr_grow (&argv_obstack, "-m");
> > +      obstack_ptr_grow (&argv_obstack, "elf_i386");
> > +    }
> > +  obstack_ptr_grow (&argv_obstack, "-r");
> > +  obstack_ptr_grow (&argv_obstack, host_descr_filename);
> > +  obstack_ptr_grow (&argv_obstack, target_so_filename);
> > +  obstack_ptr_grow (&argv_obstack, "-o");
> > +  obstack_ptr_grow (&argv_obstack, out_obj_filename);
> > +  obstack_ptr_grow (&argv_obstack, NULL);
> > +  char **new_argv = XOBFINISH (&argv_obstack, char **);
> 
> Similarly (well, here it is not constant, still, you know small upper bound
> and can just use some int index you ++ in each assignment.

Done.

> > +  /* Run objcopy on the resultant object file to localize generated symbols
> > +     to avoid conflicting between different DSO and an executable.  */
> > +  obstack_init (&argv_obstack);
> > +  obstack_ptr_grow (&argv_obstack, "objcopy");
> > +  obstack_ptr_grow (&argv_obstack, "-L");
> > +  obstack_ptr_grow (&argv_obstack, symbols[0]);
> > +  obstack_ptr_grow (&argv_obstack, "-L");
> > +  obstack_ptr_grow (&argv_obstack, symbols[1]);
> > +  obstack_ptr_grow (&argv_obstack, "-L");
> > +  obstack_ptr_grow (&argv_obstack, symbols[2]);
> > +  obstack_ptr_grow (&argv_obstack, out_obj_filename);
> > +  obstack_ptr_grow (&argv_obstack, NULL);
> > +  new_argv = XOBFINISH (&argv_obstack, char **);
> > +  fork_execute (new_argv[0], new_argv, false);
> > +  obstack_free (&argv_obstack, NULL);
> 
> Likewise.

Done.

Here is an updated patch, it also fixes the issues found by Joseph.

Thanks,
  -- Ilya


gcc/
	* config.gcc (*-intelmic-* | *-intelmicemul-*): Add i386/t-intelmic to
	tmake_file.
	(i[34567]86-*-* | x86_64-*-*): Build mkoffload$(exeext) with the
	accelerator compiler.
	* config/i386/intelmic-mkoffload.c: New file.
	* config/i386/t-intelmic: Ditto.

---

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 6bbbb26..49599b5 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2871,6 +2871,13 @@ powerpc*-*-* | rs6000-*-*)
 	tm_file="${tm_file} rs6000/option-defaults.h"
 esac
 
+# Build mkoffload tool
+case ${target} in
+*-intelmic-* | *-intelmicemul-*)
+	tmake_file="${tmake_file} i386/t-intelmic"
+	;;
+esac
+
 if [ "$target_has_targetcm" = "no" ]; then
   c_target_objs="$c_target_objs default-c.o"
   cxx_target_objs="$cxx_target_objs default-c.o"
@@ -4214,3 +4221,11 @@ then
 		target_cpu_default=$target_cpu_default2
 	fi
 fi
+
+case ${target} in
+i[34567]86-*-* | x86_64-*-*)
+	if test x$enable_as_accelerator = xyes; then
+		extra_programs="mkoffload\$(exeext)"
+	fi
+	;;
+esac
diff --git a/gcc/config/i386/intelmic-mkoffload.c b/gcc/config/i386/intelmic-mkoffload.c
new file mode 100644
index 0000000..c972f56
--- /dev/null
+++ b/gcc/config/i386/intelmic-mkoffload.c
@@ -0,0 +1,541 @@
+/* Offload image generation tool for Intel MIC devices.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   Contributed by Ilya Verbin <ilya.verbin@intel.com>.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GCC is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include <libgen.h>
+#include "system.h"
+#include "coretypes.h"
+#include "obstack.h"
+#include "intl.h"
+#include "diagnostic.h"
+#include "collect-utils.h"
+#include <libgomp_target.h>
+
+const char tool_name[] = "intelmic mkoffload";
+
+const char image_section_name[] = ".gnu.offload_images";
+const char *symbols[3] = { "__offload_image_intelmic_start",
+			   "__offload_image_intelmic_end",
+			   "__offload_image_intelmic_size" };
+const char *out_obj_filename = NULL;
+
+int num_temps = 0;
+const int MAX_NUM_TEMPS = 10;
+const char *temp_files[MAX_NUM_TEMPS];
+
+/* Shows if we should compile binaries for i386 instead of x86-64.  */
+bool target_ilp32 = false;
+
+/* Delete tempfiles and exit function.  */
+void
+tool_cleanup (bool from_signal ATTRIBUTE_UNUSED)
+{
+  for (int i = 0; i < num_temps; i++)
+    maybe_unlink (temp_files[i]);
+}
+
+static void
+mkoffload_atexit (void)
+{
+  tool_cleanup (false);
+}
+
+/* Unlink FILE unless we are debugging.  */
+void
+maybe_unlink (const char *file)
+{
+  if (debug)
+    notice ("[Leaving %s]\n", file);
+  else
+    unlink_if_ordinary (file);
+}
+
+/* Add or change the value of an environment variable, outputting the
+   change to standard error if in verbose mode.  */
+static void
+xputenv (const char *string)
+{
+  if (verbose)
+    fprintf (stderr, "%s\n", string);
+  putenv (CONST_CAST (char *, string));
+}
+
+/* Parse STR, saving found tokens into PVALUES and return their number.
+   Tokens are assumed to be delimited by ':'.  */
+static unsigned
+parse_env_var (const char *str, char ***pvalues)
+{
+  const char *curval, *nextval;
+  char **values;
+  unsigned num = 1, i;
+
+  curval = strchr (str, ':');
+  while (curval)
+    {
+      num++;
+      curval = strchr (curval + 1, ':');
+    }
+
+  values = (char **) xmalloc (num * sizeof (char *));
+  curval = str;
+  nextval = strchr (curval, ':');
+  if (nextval == NULL)
+    nextval = strchr (curval, '\0');
+
+  for (i = 0; i < num; i++)
+    {
+      int l = nextval - curval;
+      values[i] = (char *) xmalloc (l + 1);
+      memcpy (values[i], curval, l);
+      values[i][l] = 0;
+      curval = nextval + 1;
+      nextval = strchr (curval, ':');
+      if (nextval == NULL)
+	nextval = strchr (curval, '\0');
+    }
+  *pvalues = values;
+  return num;
+}
+
+/* Auxiliary function that frees elements of PTR and PTR itself.
+   N is number of elements to be freed.  If PTR is NULL, nothing is freed.
+   If an element is NULL, subsequent elements are not freed.  */
+static void
+free_array_of_ptrs (void **ptr, unsigned n)
+{
+  unsigned i;
+  if (!ptr)
+    return;
+  for (i = 0; i < n; i++)
+    {
+      if (!ptr[i])
+	break;
+      free (ptr[i]);
+    }
+  free (ptr);
+  return;
+}
+
+/* Check whether NAME can be accessed in MODE.  This is like access,
+   except that it never considers directories to be executable.  */
+static int
+access_check (const char *name, int mode)
+{
+  if (mode == X_OK)
+    {
+      struct stat st;
+
+      if (stat (name, &st) < 0 || S_ISDIR (st.st_mode))
+	return -1;
+    }
+
+  return access (name, mode);
+}
+
+/* Find target compiler using a path from COLLECT_GCC or COMPILER_PATH.  */
+static char *
+find_target_compiler (const char *name)
+{
+  bool found = false;
+  char **paths = NULL;
+  unsigned n_paths, i;
+  const char *collect_path = dirname (ASTRDUP (getenv ("COLLECT_GCC")));
+  size_t len = strlen (collect_path) + 1 + strlen (name) + 1;
+  char *target_compiler = XNEWVEC (char, len);
+  sprintf (target_compiler, "%s/%s", collect_path, name);
+  if (access_check (target_compiler, X_OK) == 0)
+    {
+      found = true;
+      goto out;
+    }
+
+  n_paths = parse_env_var (getenv ("COMPILER_PATH"), &paths);
+  for (i = 0; i < n_paths; i++)
+    {
+      len = strlen (paths[i]) + 1 + strlen (name) + 1;
+      target_compiler = XRESIZEVEC (char, target_compiler, len);
+      sprintf (target_compiler, "%s/%s", paths[i], name);
+      if (access_check (target_compiler, X_OK) == 0)
+	{
+	  found = true;
+	  break;
+	}
+    }
+
+out:
+  free_array_of_ptrs ((void **) paths, n_paths);
+  return found ? target_compiler : NULL;
+}
+
+static void
+compile_for_target (struct obstack *argv_obstack)
+{
+  if (target_ilp32)
+    obstack_ptr_grow (argv_obstack, "-m32");
+  obstack_ptr_grow (argv_obstack, NULL);
+  char **argv = XOBFINISH (argv_obstack, char **);
+
+  /* Save environment variables.  */
+  const char *epath = getenv ("GCC_EXEC_PREFIX");
+  const char *cpath = getenv ("COMPILER_PATH");
+  const char *lpath = getenv ("LIBRARY_PATH");
+  const char *rpath = getenv ("LD_RUN_PATH");
+  unsetenv ("GCC_EXEC_PREFIX");
+  unsetenv ("COMPILER_PATH");
+  unsetenv ("LIBRARY_PATH");
+  unsetenv ("LD_RUN_PATH");
+
+  fork_execute (argv[0], argv, false);
+  obstack_free (argv_obstack, NULL);
+
+  /* Restore environment variables.  */
+  xputenv (concat ("GCC_EXEC_PREFIX=", epath, NULL));
+  xputenv (concat ("COMPILER_PATH=", cpath, NULL));
+  xputenv (concat ("LIBRARY_PATH=", lpath, NULL));
+  xputenv (concat ("LD_RUN_PATH=", rpath, NULL));
+}
+
+/* Generates object file with the descriptor for the target library.  */
+static const char *
+generate_target_descr_file (const char *target_compiler)
+{
+  const char *src_filename = make_temp_file ("_target_descr.c");
+  const char *obj_filename = make_temp_file ("_target_descr.o");
+  temp_files[num_temps++] = src_filename;
+  temp_files[num_temps++] = obj_filename;
+  FILE *src_file = fopen (src_filename, "w");
+
+  if (!src_file)
+    fatal_error ("cannot open '%s'", src_filename);
+
+  fprintf (src_file,
+	   "extern void *__offload_funcs_end[];\n"
+	   "extern void *__offload_vars_end[];\n\n"
+
+	   "void *__offload_func_table[0]\n"
+	   "__attribute__ ((__used__, visibility (\"hidden\"),\n"
+	   "section (\".gnu.offload_funcs\"))) = { };\n\n"
+
+	   "void *__offload_var_table[0]\n"
+	   "__attribute__ ((__used__, visibility (\"hidden\"),\n"
+	   "section (\".gnu.offload_vars\"))) = { };\n\n"
+
+	   "void *__OFFLOAD_TARGET_TABLE__[]\n"
+	   "__attribute__ ((__used__, visibility (\"hidden\"))) = {\n"
+	   "  &__offload_func_table, &__offload_funcs_end,\n"
+	   "  &__offload_var_table, &__offload_vars_end\n"
+	   "};\n\n");
+
+  fprintf (src_file,
+	   "#ifdef __cplusplus\n"
+	   "extern \"C\"\n"
+	   "#endif\n"
+	   "void target_register_lib (const void *);\n\n"
+
+	   "__attribute__((constructor))\n"
+	   "static void\n"
+	   "init (void)\n"
+	   "{\n"
+	   "  target_register_lib (__OFFLOAD_TARGET_TABLE__);\n"
+	   "}\n");
+  fclose (src_file);
+
+  struct obstack argv_obstack;
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, target_compiler);
+  obstack_ptr_grow (&argv_obstack, "-c");
+  obstack_ptr_grow (&argv_obstack, "-shared");
+  obstack_ptr_grow (&argv_obstack, "-fPIC");
+  obstack_ptr_grow (&argv_obstack, src_filename);
+  obstack_ptr_grow (&argv_obstack, "-o");
+  obstack_ptr_grow (&argv_obstack, obj_filename);
+  compile_for_target (&argv_obstack);
+
+  return obj_filename;
+}
+
+/* Generates object file with __offload_*_end symbols for the target
+   library.  */
+static const char *
+generate_target_offloadend_file (const char *target_compiler)
+{
+  const char *src_filename = make_temp_file ("_target_offloadend.c");
+  const char *obj_filename = make_temp_file ("_target_offloadend.o");
+  temp_files[num_temps++] = src_filename;
+  temp_files[num_temps++] = obj_filename;
+  FILE *src_file = fopen (src_filename, "w");
+
+  if (!src_file)
+    fatal_error ("cannot open '%s'", src_filename);
+
+  fprintf (src_file,
+	   "void *__offload_funcs_end[0]\n"
+	   "__attribute__ ((__used__, visibility (\"hidden\"),\n"
+	   "section (\".gnu.offload_funcs\"))) = { };\n\n"
+
+	   "void *__offload_vars_end[0]\n"
+	   "__attribute__ ((__used__, visibility (\"hidden\"),\n"
+	   "section (\".gnu.offload_vars\"))) = { };\n");
+  fclose (src_file);
+
+  struct obstack argv_obstack;
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, target_compiler);
+  obstack_ptr_grow (&argv_obstack, "-c");
+  obstack_ptr_grow (&argv_obstack, "-shared");
+  obstack_ptr_grow (&argv_obstack, "-fPIC");
+  obstack_ptr_grow (&argv_obstack, src_filename);
+  obstack_ptr_grow (&argv_obstack, "-o");
+  obstack_ptr_grow (&argv_obstack, obj_filename);
+  compile_for_target (&argv_obstack);
+
+  return obj_filename;
+}
+
+/* Generates object file with the host side descriptor.  */
+static const char *
+generate_host_descr_file (const char *host_compiler)
+{
+  const char *src_filename = make_temp_file ("_host_descr.c");
+  const char *obj_filename = make_temp_file ("_host_descr.o");
+  temp_files[num_temps++] = src_filename;
+  temp_files[num_temps++] = obj_filename;
+  FILE *src_file = fopen (src_filename, "w");
+
+  if (!src_file)
+    fatal_error ("cannot open '%s'", src_filename);
+
+  fprintf (src_file,
+	   "extern void *__OFFLOAD_TABLE__;\n"
+	   "extern void *__offload_image_intelmic_start;\n"
+	   "extern void *__offload_image_intelmic_end;\n\n"
+
+	   "static const void *__offload_target_data[] = {\n"
+	   "  &__offload_image_intelmic_start, &__offload_image_intelmic_end\n"
+	   "};\n\n");
+
+  fprintf (src_file,
+	   "#ifdef __cplusplus\n"
+	   "extern \"C\"\n"
+	   "#endif\n"
+	   "void GOMP_offload_register (void *, int, void *);\n\n"
+
+	   "__attribute__((constructor))\n"
+	   "static void\n"
+	   "init (void)\n"
+	   "{\n"
+	   "  GOMP_offload_register (&__OFFLOAD_TABLE__, %d, __offload_target_data);\n"
+	   "}\n", OFFLOAD_TARGET_TYPE_INTEL_MIC);
+  fclose (src_file);
+
+  unsigned new_argc = 0;
+  const char *new_argv[9];
+  new_argv[new_argc++] = host_compiler;
+  new_argv[new_argc++] = "-c";
+  new_argv[new_argc++] = "-fPIC";
+  new_argv[new_argc++] = "-shared";
+  if (target_ilp32)
+    new_argv[new_argc++] = "-m32";
+  new_argv[new_argc++] = src_filename;
+  new_argv[new_argc++] = "-o";
+  new_argv[new_argc++] = obj_filename;
+  new_argv[new_argc++] = NULL;
+
+  fork_execute (new_argv[0], CONST_CAST (char **, new_argv), false);
+
+  return obj_filename;
+}
+
+static const char *
+prepare_target_image (const char *target_compiler, int argc, char **argv)
+{
+  const char *target_descr_filename
+    = generate_target_descr_file (target_compiler);
+  const char *target_offloadend_filename
+    = generate_target_offloadend_file (target_compiler);
+
+  char *opt1
+    = XALLOCAVEC (char, sizeof ("-Wl,") + strlen (target_descr_filename));
+  char *opt2
+    = XALLOCAVEC (char, sizeof ("-Wl,") + strlen (target_offloadend_filename));
+  sprintf (opt1, "-Wl,%s", target_descr_filename);
+  sprintf (opt2, "-Wl,%s", target_offloadend_filename);
+
+  const char *target_so_filename = make_temp_file ("_offload_intelmic.so");
+  temp_files[num_temps++] = target_so_filename;
+  struct obstack argv_obstack;
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, target_compiler);
+  obstack_ptr_grow (&argv_obstack, "-xlto");
+  obstack_ptr_grow (&argv_obstack, "-fopenmp");
+  obstack_ptr_grow (&argv_obstack, "-shared");
+  obstack_ptr_grow (&argv_obstack, "-fPIC");
+  obstack_ptr_grow (&argv_obstack, opt1);
+  for (int i = 1; i < argc; i++)
+    {
+      if (!strcmp (argv[i], "-o") && i + 1 != argc)
+	out_obj_filename = argv[++i];
+      else
+	obstack_ptr_grow (&argv_obstack, argv[i]);
+    }
+  if (!out_obj_filename)
+    fatal_error ("output file not specified");
+  obstack_ptr_grow (&argv_obstack, opt2);
+  obstack_ptr_grow (&argv_obstack, "-o");
+  obstack_ptr_grow (&argv_obstack, target_so_filename);
+  compile_for_target (&argv_obstack);
+
+  /* Run objcopy.  */
+  char *rename_section_opt
+    = XALLOCAVEC (char, sizeof (".data=") + strlen (image_section_name));
+  sprintf (rename_section_opt, ".data=%s", image_section_name);
+  const char *objcopy_argv[11];
+  objcopy_argv[0] = "objcopy";
+  objcopy_argv[1] = "-B";
+  objcopy_argv[2] = "i386";
+  objcopy_argv[3] = "-I";
+  objcopy_argv[4] = "binary";
+  objcopy_argv[5] = "-O";
+  if (target_ilp32)
+    objcopy_argv[6] = "elf32-i386";
+  else
+    objcopy_argv[6] = "elf64-x86-64";
+  objcopy_argv[7] = target_so_filename;
+  objcopy_argv[8] = "--rename-section";
+  objcopy_argv[9] = rename_section_opt;
+  objcopy_argv[10] = NULL;
+  fork_execute (objcopy_argv[0], CONST_CAST (char **, objcopy_argv), false);
+
+  /* Objcopy has created symbols, containing the input file name with
+     special characters replaced with '_'.  We are going to rename these
+     new symbols.  */
+  size_t symbol_name_len = strlen (target_so_filename);
+  char *symbol_name = XALLOCAVEC (char, symbol_name_len + 1);
+  for (size_t i = 0; i <= symbol_name_len; i++)
+    {
+      char c = target_so_filename[i];
+      if ((c == '/') || (c == '.'))
+	c = '_';
+      symbol_name[i] = c;
+    }
+
+  char *opt_for_objcopy[3];
+  opt_for_objcopy[0] = XALLOCAVEC (char, sizeof ("_binary__start=")
+					 + symbol_name_len
+					 + strlen (symbols[0]));
+  opt_for_objcopy[1] = XALLOCAVEC (char, sizeof ("_binary__end=")
+					 + symbol_name_len
+					 + strlen (symbols[1]));
+  opt_for_objcopy[2] = XALLOCAVEC (char, sizeof ("_binary__size=")
+					 + symbol_name_len
+					 + strlen (symbols[2]));
+  sprintf (opt_for_objcopy[0], "_binary_%s_start=%s", symbol_name, symbols[0]);
+  sprintf (opt_for_objcopy[1], "_binary_%s_end=%s", symbol_name, symbols[1]);
+  sprintf (opt_for_objcopy[2], "_binary_%s_size=%s", symbol_name, symbols[2]);
+
+  objcopy_argv[0] = "objcopy";
+  objcopy_argv[1] = target_so_filename;
+  objcopy_argv[2] = "--redefine-sym";
+  objcopy_argv[3] = opt_for_objcopy[0];
+  objcopy_argv[4] = "--redefine-sym";
+  objcopy_argv[5] = opt_for_objcopy[1];
+  objcopy_argv[6] = "--redefine-sym";
+  objcopy_argv[7] = opt_for_objcopy[2];
+  objcopy_argv[8] = NULL;
+  fork_execute (objcopy_argv[0], CONST_CAST (char **, objcopy_argv), false);
+
+  return target_so_filename;
+}
+
+int
+main (int argc, char **argv)
+{
+  progname = "mkoffload-intelmic";
+  gcc_init_libintl ();
+  diagnostic_initialize (global_dc, 0);
+
+  if (atexit (mkoffload_atexit) != 0)
+    fatal_error ("atexit failed");
+
+  const char *host_compiler = getenv ("COLLECT_GCC");
+  if (!host_compiler)
+    fatal_error ("COLLECT_GCC must be set");
+
+  const char *target_driver_name
+    = DEFAULT_REAL_TARGET_MACHINE "-accel-" DEFAULT_TARGET_MACHINE "-gcc";
+  char *target_compiler = find_target_compiler (target_driver_name);
+  if (target_compiler == NULL)
+    fatal_error ("offload compiler %s not found", target_driver_name);
+
+  /* We may be called with all the arguments stored in some file and
+     passed with @file.  Expand them into argv before processing.  */
+  expandargv (&argc, &argv);
+
+  /* Find out whether we should compile binaries for i386 or x86-64.  */
+  for (int i = argc - 1; i > 0; i--)
+    if (strncmp (argv[i], "-foffload-abi=", sizeof ("-foffload-abi=") - 1) == 0)
+      {
+	if (strstr (argv[i], "ilp32"))
+	  target_ilp32 = true;
+	else if (!strstr (argv[i], "lp64"))
+	  fatal_error ("unrecognizable argument of option -foffload-abi");
+	break;
+      }
+
+  const char *target_so_filename
+    = prepare_target_image (target_compiler, argc, argv);
+
+  const char *host_descr_filename = generate_host_descr_file (host_compiler);
+
+  /* Perform partial linking for the target image and host side descriptor.
+     As a result we'll get a finalized object file with all offload data.  */
+  unsigned new_argc = 0;
+  const char *new_argv[9];
+  new_argv[new_argc++] = "ld";
+  if (target_ilp32)
+    {
+      new_argv[new_argc++] = "-m";
+      new_argv[new_argc++] = "elf_i386";
+    }
+  new_argv[new_argc++] = "--relocatable";
+  new_argv[new_argc++] = host_descr_filename;
+  new_argv[new_argc++] = target_so_filename;
+  new_argv[new_argc++] = "-o";
+  new_argv[new_argc++] = out_obj_filename;
+  new_argv[new_argc++] = NULL;
+  fork_execute (new_argv[0], CONST_CAST (char **, new_argv), false);
+
+  /* Run objcopy on the resultant object file to localize generated symbols
+     to avoid conflicting between different DSO and an executable.  */
+  new_argv[0] = "objcopy";
+  new_argv[1] = "-L";
+  new_argv[2] = symbols[0];
+  new_argv[3] = "-L";
+  new_argv[4] = symbols[1];
+  new_argv[5] = "-L";
+  new_argv[6] = symbols[2];
+  new_argv[7] = out_obj_filename;
+  new_argv[8] = NULL;
+  fork_execute (new_argv[0], CONST_CAST (char **, new_argv), false);
+
+  return 0;
+}
diff --git a/gcc/config/i386/t-intelmic b/gcc/config/i386/t-intelmic
new file mode 100644
index 0000000..8b36e0d
--- /dev/null
+++ b/gcc/config/i386/t-intelmic
@@ -0,0 +1,9 @@
+mkoffload.o: $(srcdir)/config/i386/intelmic-mkoffload.c | insn-modes.h
+	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
+	  -I$(srcdir)/../libgomp \
+	  -DDEFAULT_REAL_TARGET_MACHINE=\"$(real_target_noncanonical)\" \
+	  -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
+	  $< $(OUTPUT_OPTION)
+
+mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
+	$(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)
-- 
1.7.1

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 2/4] Add liboffloadmic
  2014-10-22  8:55   ` Jakub Jelinek
  2014-10-22 17:13     ` Joseph S. Myers
@ 2014-10-22 19:31     ` Ilya Verbin
  2014-10-29 16:31       ` Ilya Verbin
  2014-11-06 18:21       ` Jakub Jelinek
  1 sibling, 2 replies; 111+ messages in thread
From: Ilya Verbin @ 2014-10-22 19:31 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On 22 Oct 10:54, Jakub Jelinek wrote:
> On Tue, Oct 21, 2014 at 09:20:34PM +0400, Ilya Verbin wrote:
> > This patch contains liboffloadmic library.
> > 
> > It is used by ICC for offloading.  The sources are imported from upstream
> > ( https://www.openmprtl.org/sites/default/files/liboffload_oss.tgz )
> > Configure and makefiles are new.
> > 
> > Also liboffloadmic/runtime/emulator directory is new.  This emulator consists
> > of 4 shared libraries which replace COI and MYO libraries from MPSS stack.
> 
> For the real offloading rather than emulation, are there any further
> libraries needed, or are the COI and MYO bits included in the source
> everything that is needed?  Does one need some kernel module, will it be
> open source, are there any plans to push it to Linus' tree?
> I know the HW isn't shipping yet, but it would be nice to get those
> questions answered now.

In case of the real offloading, user is supposed to specify the path to real COI
and MYO libraries from MPSS:
https://software.intel.com/en-us/articles/intel-manycore-platform-software-stack-mpss
Their sources can be found in 'Downloads' section, in 'mpss-src-3.4.tar'.

COI in MYO depend only on the SCIF library, which is also open source.
And SCIF requires some kernel module(s).  I'll ask the authors of MPSS, whether
all these modules are open source, and about their plans of pushing them to
Linus' tree.

> In git, I see that liboffloadmic/Makefile.am has -rwxrwxr-x permissions,
> please avoid that, only use executable permissions for shell scripts (so,
> configure is fine and desirable).

Fixed, I will update the patch in kyukhin/gomp4-offload git branch tomorrow, to
avoid resending the huge archive.

> From quick look at git, write_message has been supposedly fixed to use
> va_list, but I see it is wrong:
> 
>     void write_message(FILE * file, int msgCode, va_list args_p) {
>         va_list args;
>         char buf[1024];
> 
>         va_copy(args, args_p);
>         buf[0] = '\r';
>         vsnprintf(buf + 1, sizeof(buf), MESSAGE_TABLE_NAME[ msgCode ], args);
>         strcat(buf, "\n");
>         va_end(args);
>         fputs(buf, file);
>         fflush(file);
>     }
> 
> As vsnprintf's first argument is buf + 1, it might happily overflow the
> buffer, and if not that, then the strcat could too.
> So, I'd expect sizeof(buf) - 2 be needed there instead of sizeof(buf).

Fixed.

> Also, do we really want the messy DOS/Windows '\r' in the messages on
> Unix-ish targets?  Shouldn't that be dependent on what target is the library
> configured for?

Fixed.

Thanks,
  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2014-10-22  9:47   ` Jakub Jelinek
@ 2014-10-23 16:00     ` Ilya Verbin
  2014-10-24 14:57       ` Jakub Jelinek
  0 siblings, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2014-10-23 16:00 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On 22 Oct 11:22, Jakub Jelinek wrote:
> On Tue, Oct 21, 2014 at 09:24:13PM +0400, Ilya Verbin wrote:
> > +  mic_lib_path_new = (char *) malloc ((mic_lib_path ? strlen (mic_lib_path) : 0)
> > +				      + strlen (ld_lib_path) + 2);
> 
> malloc can fail, SIGSEGV in response to that is not desirable.
> Can't you fallback to alloca, or use just alloca, or use alloca
> with malloc fallback?

I replaced it with alloca.

> > +extern "C" void
> > +GOMP_OFFLOAD_register_image (void *host_table, void *target_image)
> > +{
> > +  TRACE ("(host_table = %p, target_image = %p)", host_table, target_image);
> > +
> > +  if (num_libraries >= 1000)
> > +    {
> > +      fprintf (stderr,
> > +	       "%s: The number of loaded shared libraries is over 1000!\n",
> > +	       __FILE__);
> > +      exit (1);
> 
> Where does this artificial limit come from?  Using libNNN.so library names?
> Can't you use lib%d.so instead?

Yes, it comes from the Image structure (liboffloadmic/runtime/offload_host.h:52)
It must contain a null-terminated name, therefore I need to allocate some space
for the name in plugin's struct TargetImage.  But the structure can't contain
any bytes after the trailing zero and before the actual data.
So, now I extended the name to 10 digits and removed the comparison with 1000.

> Also, seeing register_image, shouldn't there be
> GOMP_OFFLOAD_unregister_image which would be invoked when the library
> containing MIC offloading regions is dlclosed?
> One could use __cxa_atexit or similar for that, something that is given
> &__dso_handle.  Or is no cleanup necessary?  At least unregistering it
> from translation tables, because the same addresses might be reused by a
> different shared library?
> With dlopen/dlclose in mind, 1000 might be easily reached, consider 10000
> times dlopening/dlclosing (perhaps over longer time, by long running daemon)
> a shared library containg #pragma omp target region.

Hmm, previously we've tested only cases when all libraries are loaded before the
first offload.  Offloading from a dlopened library after the call to
gomp_target_init isn't working.  So, this will require some changes in
libgomp/target.c .  Is it ok to fix this bug in a separate patch?
And yes, there should be GOMP_OFFLOAD_unregister_image for this case.

> > +static int first_init = 1;
> > +
> > +/* Load offload_target_main on target.  */
> > +extern "C" void
> > +GOMP_OFFLOAD_init_device (int device)
> > +{
> > +  TRACE ("");
> > +  pthread_mutex_lock (&mutex);
> > +  if (first_init)
> > +    {
> > +      __offload_register_image (&main_target_image);
> > +      first_init = 0;
> > +    }
> > +  pthread_mutex_unlock (&mutex);
> 
> pthread_once instead?

Done.

Patch is updated.

Thanks,
  -- Ilya


---

diff --git a/liboffloadmic/configure.ac b/liboffloadmic/configure.ac
index fb575b3..81fae8f 100644
--- a/liboffloadmic/configure.ac
+++ b/liboffloadmic/configure.ac
@@ -42,6 +42,7 @@ AC_PROG_CC
 AC_PROG_CXX
 AC_CONFIG_FILES([Makefile liboffloadmic_host.spec liboffloadmic_target.spec])
 AM_ENABLE_MULTILIB(, ..)
+AC_CONFIG_SUBDIRS(plugin)
 AC_FUNC_ALLOCA
 AC_CHECK_HEADERS([mm_malloc.h], [], [AC_MSG_ERROR(["Couldn't find mm_malloc.h"])])
 AC_CHECK_FUNCS([__secure_getenv secure_getenv])
diff --git a/liboffloadmic/plugin/Makefile.am b/liboffloadmic/plugin/Makefile.am
new file mode 100644
index 0000000..0baf70d
--- /dev/null
+++ b/liboffloadmic/plugin/Makefile.am
@@ -0,0 +1,123 @@
+# Plugin for offload execution on Intel MIC devices.
+#
+# Copyright (C) 2014 Free Software Foundation, Inc.
+#
+# Contributed by Ilya Verbin <ilya.verbin@intel.com> and
+# Andrey Turetskiy <andrey.turetskiy@intel.com>.
+#
+# This file is part of the GNU OpenMP Library (libgomp).
+#
+# Libgomp is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# Under Section 7 of GPL version 3, you are granted additional
+# permissions described in the GCC Runtime Library Exception, version
+# 3.1, as published by the Free Software Foundation.
+#
+# You should have received a copy of the GNU General Public License and
+# a copy of the GCC Runtime Library Exception along with this program;
+# see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+
+AUTOMAKE_OPTIONS = foreign
+ACLOCAL_AMFLAGS = -I ../.. -I ../../config
+
+# Directories
+build_dir = $(top_builddir)
+source_dir = $(top_srcdir)
+coi_inc_dir = $(top_srcdir)/../include/coi
+myo_inc_dir = $(top_srcdir)/../include/myo
+libgomp_src_dir = $(top_srcdir)/../../libgomp
+libgomp_dir = $(build_dir)/../../libgomp
+liboffload_src_dir = $(top_srcdir)/../runtime
+liboffload_dir = $(top_builddir)/..
+
+# May be used by toolexeclibdir.
+gcc_version := $(shell cat $(top_srcdir)/../../gcc/BASE-VER)
+libsubincludedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/include
+# Search for main_target_image.h in these directories
+target_prefix_dir = $(libdir)/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
+target_build_dir = $(accel_search_dir)/$(accel_target)$(MULTISUBDIR)/liboffloadmic/plugin
+target_install_dir = $(accel_search_dir)/lib/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
+
+if PLUGIN_HOST
+  toolexeclib_LTLIBRARIES = libgomp-plugin-intelmic.la
+  libgomp_plugin_intelmic_la_SOURCES = libgomp-plugin-intelmic.cpp
+  libgomp_plugin_intelmic_la_CPPFLAGS = $(CPPFLAGS) -DLINUX -DCOI_LIBRARY_VERSION=2 -DMYO_SUPPORT -DOFFLOAD_DEBUG=1 -DSEP_SUPPORT -DTIMING_SUPPORT -DHOST_LIBRARY=1 -I$(coi_inc_dir) -I$(myo_inc_dir) -I$(liboffload_src_dir) -I$(libgomp_src_dir) -I$(libgomp_dir) -I$(target_prefix_dir)/include -I$(target_build_dir) -I$(target_install_dir)/include
+  libgomp_plugin_intelmic_la_LDFLAGS = -L$(liboffload_dir)/.libs -loffloadmic_host -version-info 1:0:0
+else # PLUGIN_TARGET
+  plugin_includedir = $(libsubincludedir)
+  plugin_include_HEADERS = main_target_image.h
+  AM_CPPFLAGS = $(CPPFLAGS) -DLINUX -DCOI_LIBRARY_VERSION=2 -DMYO_SUPPORT -DOFFLOAD_DEBUG=1 -DSEP_SUPPORT -DTIMING_SUPPORT -DHOST_LIBRARY=0 -I$(coi_inc_dir) -I$(myo_inc_dir) -I$(liboffload_src_dir) -I$(libgomp_dir)
+  AM_CXXFLAGS = $(CXXFLAGS)
+  AM_LDFLAGS = -L$(liboffload_dir)/.libs -L$(libgomp_dir)/.libs -loffloadmic_target -lcoi_device -lmyo-service -lgomp -rdynamic
+endif
+
+main_target_image.h: offload_target_main
+	@echo -n "const int image_size = " > $@
+	@stat -c '%s' $< >> $@
+	@echo ";" >> $@
+	@echo "struct MainTargetImage {" >> $@
+	@echo "  int64_t size;" >> $@
+	@echo "  char name[sizeof \"offload_target_main\"];" >> $@
+	@echo "  char data[image_size];" >> $@
+	@echo "};" >> $@
+	@echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
+	@echo "  image_size, \"offload_target_main\"," >> $@
+	@cat $< | xxd -include >> $@
+	@echo "};" >> $@
+
+offload_target_main: $(liboffload_dir)/ofldbegin.o offload_target_main.o $(liboffload_dir)/ofldend.o
+	$(CXX) $(AM_LDFLAGS) $^ -o $@
+
+offload_target_main.o: offload_target_main.cpp
+	$(CXX) $(AM_CXXFLAGS) $(AM_CPPFLAGS) -c $< -o $@
+
+# Work around what appears to be a GNU make bug handling MAKEFLAGS
+# values defined in terms of make variables, as is the case for CC and
+# friends when we are called from the top level Makefile.
+AM_MAKEFLAGS = \
+       "AR_FLAGS=$(AR_FLAGS)" \
+       "CC_FOR_BUILD=$(CC_FOR_BUILD)" \
+       "CFLAGS=$(CFLAGS)" \
+       "CXXFLAGS=$(CXXFLAGS)" \
+       "CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
+       "CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
+       "INSTALL=$(INSTALL)" \
+       "INSTALL_DATA=$(INSTALL_DATA)" \
+       "INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
+       "INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
+       "JC1FLAGS=$(JC1FLAGS)" \
+       "LDFLAGS=$(LDFLAGS)" \
+       "LIBCFLAGS=$(LIBCFLAGS)" \
+       "LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
+       "MAKE=$(MAKE)" \
+       "MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
+       "PICFLAG=$(PICFLAG)" \
+       "PICFLAG_FOR_TARGET=$(PICFLAG_FOR_TARGET)" \
+       "SHELL=$(SHELL)" \
+       "RUNTESTFLAGS=$(RUNTESTFLAGS)" \
+       "exec_prefix=$(exec_prefix)" \
+       "infodir=$(infodir)" \
+       "libdir=$(libdir)" \
+       "prefix=$(prefix)" \
+       "includedir=$(includedir)" \
+       "AR=$(AR)" \
+       "AS=$(AS)" \
+       "LD=$(LD)" \
+       "LIBCFLAGS=$(LIBCFLAGS)" \
+       "NM=$(NM)" \
+       "PICFLAG=$(PICFLAG)" \
+       "RANLIB=$(RANLIB)" \
+       "DESTDIR=$(DESTDIR)"
+
+MAKEOVERRIDES =
+
diff --git a/liboffloadmic/plugin/configure.ac b/liboffloadmic/plugin/configure.ac
new file mode 100644
index 0000000..283faad
--- /dev/null
+++ b/liboffloadmic/plugin/configure.ac
@@ -0,0 +1,135 @@
+# Plugin for offload execution on Intel MIC devices.
+#
+# Copyright (C) 2014 Free Software Foundation, Inc.
+#
+# Contributed by Andrey Turetskiy <andrey.turetskiy@intel.com>.
+#
+# This file is part of the GNU OpenMP Library (libgomp).
+#
+# Libgomp is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# Under Section 7 of GPL version 3, you are granted additional
+# permissions described in the GCC Runtime Library Exception, version
+# 3.1, as published by the Free Software Foundation.
+#
+# You should have received a copy of the GNU General Public License and
+# a copy of the GCC Runtime Library Exception along with this program;
+# see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+# Process this file with autoconf to produce a configure script, like so:
+# aclocal -I ../.. -I ../../config && autoconf && automake
+
+AC_PREREQ([2.64])
+AC_INIT([Intel MIC Offload Plugin], [1.0], ,[libgomp-plugin-intelmic])
+
+AC_CONFIG_AUX_DIR(../..)
+
+AC_CANONICAL_SYSTEM
+target_alias=${target_alias-$host_alias}
+AC_SUBST(target_alias)
+
+AM_INIT_AUTOMAKE([1.9.0 foreign no-dist])
+
+AM_MAINTAINER_MODE
+
+AC_PROG_CC
+AC_PROG_CXX
+AC_CONFIG_FILES([Makefile])
+AM_ENABLE_MULTILIB(, ../..)
+
+if test "${multilib}" = "yes"; then
+  multilib_arg="--enable-multilib"
+else
+  multilib_arg=
+fi
+
+# Make sure liboffloadmic is enabled
+case "$enable_liboffloadmic" in
+  host | target)
+    ;;
+  *)
+    AC_MSG_ERROR([Liboffloadmic is disabled]) ;;
+esac
+AM_CONDITIONAL(PLUGIN_HOST, [test x"$enable_liboffloadmic" = xhost])
+
+# Get accel target and path to build or install tree of accel compiler
+accel_search_dir=
+accel_target=
+if test x"$enable_liboffloadmic" = xhost; then
+  for accel in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
+    accel_name=`echo $accel | sed 's/=.*//'`
+    accel_dir=`echo $accel | grep '=' | sed 's/.*=//'`
+    case "$accel_name" in
+      *-intelmic-* | *-intelmicemul-*)
+	accel_target=$accel_name
+	accel_search_dir=$accel_dir
+	;;
+    esac
+  done
+  if test x"$accel_target" = x; then
+    AC_MSG_ERROR([--enable-offload-targets does not contain intelmic target])
+  fi
+fi
+AC_SUBST(accel_search_dir)
+AC_SUBST(accel_target)
+
+AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
+AC_ARG_ENABLE([version-specific-runtime-libs],
+  AC_HELP_STRING([--enable-version-specific-runtime-libs],
+		 [Specify that runtime libraries should be installed in a compiler-specific directory]),
+  [case "$enableval" in
+    yes) enable_version_specific_runtime_libs=yes ;;
+    no)  enable_version_specific_runtime_libs=no ;;
+    *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
+   esac],
+  [enable_version_specific_runtime_libs=no])
+AC_MSG_RESULT($enable_version_specific_runtime_libs)
+
+
+# Calculate toolexeclibdir.
+# Also toolexecdir, though it's only used in toolexeclibdir.
+case ${enable_version_specific_runtime_libs} in
+  yes)
+    # Need the gcc compiler version to know where to install libraries
+    # and header files if --enable-version-specific-runtime-libs option
+    # is selected.
+    toolexecdir='$(libdir)/gcc/$(target_alias)'
+    toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
+    ;;
+  no)
+    if test -n "$with_cross_host" &&
+       test x"$with_cross_host" != x"no"; then
+      # Install a library built with a cross compiler in tooldir, not libdir.
+      toolexecdir='$(exec_prefix)/$(target_alias)'
+      toolexeclibdir='$(toolexecdir)/lib'
+    else
+      toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+      toolexeclibdir='$(libdir)'
+    fi
+    multi_os_directory=`$CC -print-multi-os-directory`
+    case $multi_os_directory in
+      .) ;; # Avoid trailing /.
+      *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
+    esac
+    ;;
+esac
+
+AC_LIBTOOL_DLOPEN
+AM_PROG_LIBTOOL
+# Forbid libtool to hardcode RPATH, because we want to be able to specify
+# library search directory using LD_LIBRARY_PATH
+hardcode_into_libs=no
+AC_SUBST(toolexecdir)
+AC_SUBST(toolexeclibdir)
+
+# Must be last
+AC_OUTPUT
diff --git a/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp
new file mode 100644
index 0000000..9c8b3b4
--- /dev/null
+++ b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp
@@ -0,0 +1,430 @@
+/* Plugin for offload execution on Intel MIC devices.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   Contributed by Ilya Verbin <ilya.verbin@intel.com>.
+
+   This file is part of the GNU OpenMP Library (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Host side part of a libgomp plugin.  */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <utility>
+#include <vector>
+#include <libgomp_target.h>
+#include "compiler_if_host.h"
+#include "main_target_image.h"
+
+#define LD_LIBRARY_PATH_ENV	"LD_LIBRARY_PATH"
+#define MIC_LD_LIBRARY_PATH_ENV	"MIC_LD_LIBRARY_PATH"
+
+#ifdef DEBUG
+#define TRACE(...)					    \
+{							    \
+fprintf (stderr, "HOST:\t%s:%s ", __FILE__, __FUNCTION__);  \
+fprintf (stderr, __VA_ARGS__);				    \
+fprintf (stderr, "\n");					    \
+}
+#else
+#define TRACE { }
+#endif
+
+
+static VarDesc vd_host2tgt = {
+  { 1, 1 },		      /* dst, src			      */
+  { 1, 0 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+static VarDesc vd_tgt2host = {
+  { 1, 1 },		      /* dst, src			      */
+  { 0, 1 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+
+/* Total number of shared libraries with offloading to Intel MIC.  */
+static int num_libraries;
+
+/* Pointers to the descriptors, containing pointers to host-side tables and to
+   target images.  */
+static std::vector< std::pair<void *, void *> > lib_descrs;
+
+/* Thread-safe registration of the main image.  */
+static pthread_once_t main_image_is_registered = PTHREAD_ONCE_INIT;
+
+
+/* Add path specified in LD_LIBRARY_PATH to MIC_LD_LIBRARY_PATH, which is
+   required by liboffloadmic.  */
+__attribute__((constructor))
+static void
+set_mic_lib_path (void)
+{
+  const char *ld_lib_path = getenv (LD_LIBRARY_PATH_ENV);
+  const char *mic_lib_path = getenv (MIC_LD_LIBRARY_PATH_ENV);
+  char *mic_lib_path_new;
+
+  if (!ld_lib_path)
+    return;
+
+  mic_lib_path_new = (char *) alloca ((mic_lib_path ? strlen (mic_lib_path) : 0)
+				      + strlen (ld_lib_path) + 2);
+
+  if (!mic_lib_path)
+    strcpy (mic_lib_path_new, ld_lib_path);
+  else
+    sprintf (mic_lib_path_new, "%s:%s", mic_lib_path, ld_lib_path);
+  setenv (MIC_LD_LIBRARY_PATH_ENV, mic_lib_path_new, 1);
+}
+
+extern "C" enum offload_target_type
+GOMP_OFFLOAD_get_type (void)
+{
+  enum offload_target_type res = OFFLOAD_TARGET_TYPE_INTEL_MIC;
+  TRACE ("(): return %d", res);
+  return res;
+}
+
+extern "C" int
+GOMP_OFFLOAD_get_num_devices (void)
+{
+  int res = _Offload_number_of_devices ();
+  TRACE ("(): return %d", res);
+  return res;
+}
+
+/* This should be called from every shared library with offloading.  */
+extern "C" void
+GOMP_OFFLOAD_register_image (void *host_table, void *target_image)
+{
+  TRACE ("(host_table = %p, target_image = %p)", host_table, target_image);
+  lib_descrs.push_back (std::make_pair (host_table, target_image));
+  num_libraries++;
+}
+
+static void
+offload (const char *file, uint64_t line, int device, const char *name,
+	 int num_vars, VarDesc *vars, VarDesc2 *vars2)
+{
+  OFFLOAD ofld = __offload_target_acquire1 (&device, file, line);
+  if (ofld)
+    __offload_offload1 (ofld, name, 0, num_vars, vars, vars2, 0, NULL, NULL);
+  else
+    {
+      fprintf (stderr, "%s:%d: Offload target acquire failed\n", file, line);
+      exit (1);
+    }
+}
+
+static void
+register_main_image ()
+{
+  __offload_register_image (&main_target_image);
+}
+
+/* Load offload_target_main on target.  */
+extern "C" void
+GOMP_OFFLOAD_init_device (int device)
+{
+  TRACE ("");
+  pthread_once (&main_image_is_registered, register_main_image);
+  offload (__FILE__, __LINE__, device, "__offload_target_init_proc", 0,
+	   NULL, NULL);
+}
+
+static void
+get_target_table (int device, int &num_funcs, int &num_vars, void **&table)
+{
+  VarDesc vd1[2] = { vd_tgt2host, vd_tgt2host };
+  vd1[0].ptr = &num_funcs;
+  vd1[0].size = sizeof (num_funcs);
+  vd1[1].ptr = &num_vars;
+  vd1[1].size = sizeof (num_vars);
+  VarDesc2 vd1g[2] = { { "num_funcs", 0 }, { "num_vars", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_table_p1", 2,
+	   vd1, vd1g);
+
+  int table_size = num_funcs + 2 * num_vars;
+  if (table_size > 0)
+    {
+      table = new void * [table_size];
+
+      VarDesc vd2;
+      vd2 = vd_tgt2host;
+      vd2.ptr = table;
+      vd2.size = table_size * sizeof (void *);
+      VarDesc2 vd2g = { "table", 0 };
+
+      offload (__FILE__, __LINE__, device, "__offload_target_table_p2", 1,
+	       &vd2, &vd2g);
+    }
+}
+
+static void
+load_lib_and_get_table (int device, int lib_num, mapping_table *&table,
+			int &table_size)
+{
+  struct TargetImage {
+    int64_t size;
+    /* 10 characters is enough for max int value.  */
+    char name[sizeof ("lib0000000000.so")];
+    char data[];
+  } __attribute__ ((packed));
+
+  void ***host_table_descr = (void ***) lib_descrs[lib_num].first;
+  void **host_func_start = host_table_descr[0];
+  void **host_func_end   = host_table_descr[1];
+  void **host_var_start  = host_table_descr[2];
+  void **host_var_end    = host_table_descr[3];
+
+  void **target_image_descr = (void **) lib_descrs[lib_num].second;
+  void *image_start = target_image_descr[0];
+  void *image_end   = target_image_descr[1];
+
+  TRACE ("() host_table_descr { %p, %p, %p, %p }", host_func_start,
+	 host_func_end, host_var_start, host_var_end);
+  TRACE ("() target_image_descr { %p, %p }", image_start, image_end);
+
+  int64_t image_size = (uintptr_t) image_end - (uintptr_t) image_start;
+  TargetImage *image
+    = (TargetImage *) malloc (sizeof (int64_t) + sizeof ("lib0000000000.so")
+			      + image_size);
+  image->size = image_size;
+  sprintf (image->name, "lib%010d.so", lib_num);
+  memcpy (image->data, image_start, image->size);
+
+  TRACE ("() __offload_register_image %s { %p, %d }",
+	 image->name, image_start, image->size);
+  __offload_register_image (image);
+
+  int tgt_num_funcs = 0;
+  int tgt_num_vars = 0;
+  void **tgt_table = NULL;
+  get_target_table (device, tgt_num_funcs, tgt_num_vars, tgt_table);
+  free (image);
+
+  /* The func table contains only addresses, the var table contains addresses
+     and corresponding sizes.  */
+  int host_num_funcs = host_func_end - host_func_start;
+  int host_num_vars  = (host_var_end - host_var_start) / 2;
+  TRACE ("() host_num_funcs = %d, tgt_num_funcs = %d",
+	 host_num_funcs, tgt_num_funcs);
+  TRACE ("() host_num_vars = %d, tgt_num_vars = %d",
+	 host_num_vars, tgt_num_vars);
+  if (host_num_funcs != tgt_num_funcs)
+    {
+      fprintf (stderr, "%s: Can't map target functions\n", __FILE__);
+      exit (1);
+    }
+  if (host_num_vars != tgt_num_vars)
+    {
+      fprintf (stderr, "%s: Can't map target variables\n", __FILE__);
+      exit (1);
+    }
+
+  table = (mapping_table *) realloc (table, (table_size + host_num_funcs
+					     + host_num_vars)
+					    * sizeof (mapping_table));
+  if (table == NULL)
+    {
+      fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
+      exit (1);
+    }
+
+  for (int i = 0; i < host_num_funcs; i++)
+    {
+      mapping_table t;
+      t.host_start = (uintptr_t) host_func_start[i];
+      t.host_end = t.host_start + 1;
+      t.tgt_start = (uintptr_t) tgt_table[i];
+      t.tgt_end = t.tgt_start + 1;
+
+      TRACE ("() lib %d, func %d:\t0x%llx -- 0x%llx",
+	     lib_num, i, t.host_start, t.tgt_start);
+
+      table[table_size++] = t;
+    }
+
+  for (int i = 0; i < host_num_vars * 2; i += 2)
+    {
+      mapping_table t;
+      t.host_start = (uintptr_t) host_var_start[i];
+      t.host_end = t.host_start + (uintptr_t) host_var_start[i+1];
+      t.tgt_start = (uintptr_t) tgt_table[tgt_num_funcs+i];
+      t.tgt_end = t.tgt_start + (uintptr_t) tgt_table[tgt_num_funcs+i+1];
+
+      TRACE ("() lib %d, var %d:\t0x%llx (%d) -- 0x%llx (%d)", lib_num, i/2,
+	     t.host_start, t.host_end - t.host_start,
+	     t.tgt_start, t.tgt_end - t.tgt_start);
+
+      table[table_size++] = t;
+    }
+
+  delete [] tgt_table;
+}
+
+extern "C" int
+GOMP_OFFLOAD_get_table (int device, void *result)
+{
+  TRACE ("(num_libraries = %d)", num_libraries);
+
+  mapping_table *table = NULL;
+  int table_size = 0;
+
+  for (int i = 0; i < num_libraries; i++)
+    load_lib_and_get_table (device, i, table, table_size);
+
+  *(void **) result = table;
+  return table_size;
+}
+
+extern "C" void *
+GOMP_OFFLOAD_alloc (int device, size_t size)
+{
+  TRACE ("(size = %d)", size);
+
+  void *tgt_ptr;
+  VarDesc vd1[2] = { vd_host2tgt, vd_tgt2host };
+  vd1[0].ptr = &size;
+  vd1[0].size = sizeof (size);
+  vd1[1].ptr = &tgt_ptr;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd1g[2] = { { "size", 0 }, { "tgt_ptr", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_alloc", 2, vd1, vd1g);
+
+  return tgt_ptr;
+}
+
+extern "C" void
+GOMP_OFFLOAD_free (int device, void *tgt_ptr)
+{
+  TRACE ("(tgt_ptr = %p)", tgt_ptr);
+
+  VarDesc vd1 = vd_host2tgt;
+  vd1.ptr = &tgt_ptr;
+  vd1.size = sizeof (void *);
+  VarDesc2 vd1g = { "tgt_ptr", 0 };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_free", 1, &vd1, &vd1g);
+}
+
+extern "C" void *
+GOMP_OFFLOAD_host2dev (int device, void *tgt_ptr, const void *host_ptr,
+		       size_t size)
+{
+  TRACE ("(tgt_ptr = %p, host_ptr = %p, size = %d)", tgt_ptr, host_ptr, size);
+  if (!size)
+    return tgt_ptr;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &tgt_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &size;
+  vd1[1].size = sizeof (size);
+  VarDesc2 vd1g[2] = { { "tgt_ptr", 0 }, { "size", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p1", 2,
+	   vd1, vd1g);
+
+  VarDesc vd2 = vd_host2tgt;
+  vd2.ptr = (void *) host_ptr;
+  vd2.size = size;
+  VarDesc2 vd2g = { "var", 0 };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p2", 1,
+	   &vd2, &vd2g);
+
+  return tgt_ptr;
+}
+
+extern "C" void *
+GOMP_OFFLOAD_dev2host (int device, void *host_ptr, const void *tgt_ptr,
+		       size_t size)
+{
+  TRACE ("(host_ptr = %p, tgt_ptr = %p, size = %d)", host_ptr, tgt_ptr, size);
+  if (!size)
+    return host_ptr;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &tgt_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &size;
+  vd1[1].size = sizeof (size);
+  VarDesc2 vd1g[2] = { { "tgt_ptr", 0 }, { "size", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p1", 2,
+	   vd1, vd1g);
+
+  VarDesc vd2 = vd_tgt2host;
+  vd2.ptr = (void *) host_ptr;
+  vd2.size = size;
+  VarDesc2 vd2g = { "var", 0 };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p2", 1,
+	   &vd2, &vd2g);
+
+  return host_ptr;
+}
+
+extern "C" void
+GOMP_OFFLOAD_run (int device, void *tgt_fn, void *tgt_vars)
+{
+  TRACE ("(tgt_fn = %p, tgt_vars = %p)", tgt_fn, tgt_vars);
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &tgt_fn;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &tgt_vars;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd1g[2] = { { "tgt_fn", 0 }, { "tgt_vars", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_run", 2, vd1, vd1g);
+}
diff --git a/liboffloadmic/plugin/offload_target_main.cpp b/liboffloadmic/plugin/offload_target_main.cpp
new file mode 100644
index 0000000..4a2778e
--- /dev/null
+++ b/liboffloadmic/plugin/offload_target_main.cpp
@@ -0,0 +1,366 @@
+/* Plugin for offload execution on Intel MIC devices.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   Contributed by Ilya Verbin <ilya.verbin@intel.com>.
+
+   This file is part of the GNU OpenMP Library (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Target side part of a libgomp plugin.  */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "compiler_if_target.h"
+
+
+#ifdef DEBUG
+#define TRACE(...)					      \
+{							      \
+fprintf (stderr, "TARGET:\t%s:%s ", __FILE__, __FUNCTION__);  \
+fprintf (stderr, __VA_ARGS__);				      \
+fprintf (stderr, "\n");					      \
+}
+#else
+#define TRACE { }
+#endif
+
+
+static VarDesc vd_host2tgt = {
+  { 1, 1 },		      /* dst, src			      */
+  { 1, 0 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+static VarDesc vd_tgt2host = {
+  { 1, 1 },		      /* dst, src			      */
+  { 0, 1 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+/* Pointer to the descriptor of the last loaded shared library.  */
+static void *last_loaded_library = NULL;
+
+/* Pointer and size of the variable, used in __offload_target_host2tgt_p[12]
+   and __offload_target_tgt2host_p[12].  */
+static void *last_var_ptr = NULL;
+static int last_var_size = 0;
+
+
+/* Override the corresponding functions from libgomp.  */
+extern "C" int
+omp_is_initial_device (void) __GOMP_NOTHROW
+{
+  return 0;
+}
+
+extern "C" int32_t
+omp_is_initial_device_ (void)
+{
+  return omp_is_initial_device ();
+}
+
+
+/* Dummy function needed for the initialization of target process during the
+   first call to __offload_offload1.  */
+static void
+__offload_target_init_proc (OFFLOAD ofldt)
+{
+  TRACE ("");
+}
+
+/* Collect addresses of the offload functions and of the global variables from
+   the library descriptor and send them to host.
+   Part 1: Send num_funcs and num_vars to host.  */
+static void
+__offload_target_table_p1 (OFFLOAD ofldt)
+{
+  void ***lib_descr = (void ***) last_loaded_library;
+
+  if (lib_descr == NULL)
+    {
+      TRACE ("");
+      fprintf (stderr, "Error! No shared libraries loaded on target.\n");
+      return;
+    }
+
+  void **func_table_begin = lib_descr[0];
+  void **func_table_end   = lib_descr[1];
+  void **var_table_begin  = lib_descr[2];
+  void **var_table_end    = lib_descr[3];
+
+  /* The func table contains only addresses, the var table contains addresses
+     and corresponding sizes.  */
+  int num_funcs = func_table_end - func_table_begin;
+  int num_vars = (var_table_end - var_table_begin) / 2;
+  TRACE ("(num_funcs = %d, num_vars = %d)", num_funcs, num_vars);
+
+  VarDesc vd1[2] = { vd_tgt2host, vd_tgt2host };
+  vd1[0].ptr = &num_funcs;
+  vd1[0].size = sizeof (num_funcs);
+  vd1[1].ptr = &num_vars;
+  vd1[1].size = sizeof (num_vars);
+  VarDesc2 vd2[2] = { { "num_funcs", 0 }, { "num_vars", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  __offload_target_leave (ofldt);
+}
+
+/* Part 2: Send the table with addresses to host.  */
+static void
+__offload_target_table_p2 (OFFLOAD ofldt)
+{
+  void ***lib_descr = (void ***) last_loaded_library;
+  void **func_table_begin = lib_descr[0];
+  void **func_table_end   = lib_descr[1];
+  void **var_table_begin  = lib_descr[2];
+  void **var_table_end    = lib_descr[3];
+
+  int num_funcs = func_table_end - func_table_begin;
+  int num_vars = (var_table_end - var_table_begin) / 2;
+  int table_size = (num_funcs + 2 * num_vars) * sizeof (void *);
+  void **table = (void **) malloc (table_size);
+  TRACE ("(table_size = %d)", table_size);
+
+  VarDesc vd1;
+  vd1 = vd_tgt2host;
+  vd1.ptr = table;
+  vd1.size = table_size;
+  VarDesc2 vd2 = { "table", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+
+  void **p;
+  int i = 0;
+  for (p = func_table_begin; p < func_table_end; p++, i++)
+    table[i] = *p;
+
+  for (p = var_table_begin; p < var_table_end; p++, i++)
+    table[i] = *p;
+
+  __offload_target_leave (ofldt);
+  free (table);
+}
+
+/* Allocate size bytes and send a pointer to the allocated memory to host.  */
+static void
+__offload_target_alloc (OFFLOAD ofldt)
+{
+  size_t size = 0;
+  void *ptr = NULL;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_tgt2host };
+  vd1[0].ptr = &size;
+  vd1[0].size = sizeof (size);
+  vd1[1].ptr = &ptr;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd2[2] = { { "size", 0 }, { "ptr", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  ptr = malloc (size);
+  TRACE ("(size = %d): ptr = %p", size, ptr);
+  __offload_target_leave (ofldt);
+}
+
+/* Free the memory space pointed to by ptr.  */
+static void
+__offload_target_free (OFFLOAD ofldt)
+{
+  void *ptr = 0;
+
+  VarDesc vd1 = vd_host2tgt;
+  vd1.ptr = &ptr;
+  vd1.size = sizeof (void *);
+  VarDesc2 vd2 = { "ptr", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+  TRACE ("(ptr = %p)", ptr);
+  free (ptr);
+  __offload_target_leave (ofldt);
+}
+
+/* Receive var_size bytes from host and store to var_ptr.
+   Part 1: Receive var_ptr and var_size from host.  */
+static void
+__offload_target_host2tgt_p1 (OFFLOAD ofldt)
+{
+  void *var_ptr = NULL;
+  size_t var_size = 0;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &var_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &var_size;
+  vd1[1].size = sizeof (var_size);
+  VarDesc2 vd2[2] = { { "var_ptr", 0 }, { "var_size", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  TRACE ("(var_ptr = %p, var_size = %d)", var_ptr, var_size);
+  last_var_ptr = var_ptr;
+  last_var_size = var_size;
+  __offload_target_leave (ofldt);
+}
+
+/* Part 2: Receive the data from host.  */
+static void
+__offload_target_host2tgt_p2 (OFFLOAD ofldt)
+{
+  TRACE ("(last_var_ptr = %p, last_var_size = %d)",
+	 last_var_ptr, last_var_size);
+
+  VarDesc vd1 = vd_host2tgt;
+  vd1.ptr = last_var_ptr;
+  vd1.size = last_var_size;
+  VarDesc2 vd2 = { "var", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+  __offload_target_leave (ofldt);
+}
+
+/* Send var_size bytes from var_ptr to host.
+   Part 1: Receive var_ptr and var_size from host.  */
+static void
+__offload_target_tgt2host_p1 (OFFLOAD ofldt)
+{
+  void *var_ptr = NULL;
+  size_t var_size = 0;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &var_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &var_size;
+  vd1[1].size = sizeof (var_size);
+  VarDesc2 vd2[2] = { { "var_ptr", 0 }, { "var_size", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  TRACE ("(var_ptr = %p, var_size = %d)", var_ptr, var_size);
+  last_var_ptr = var_ptr;
+  last_var_size = var_size;
+  __offload_target_leave (ofldt);
+}
+
+/* Part 2: Send the data to host.  */
+static void
+__offload_target_tgt2host_p2 (OFFLOAD ofldt)
+{
+  TRACE ("(last_var_ptr = %p, last_var_size = %d)",
+	 last_var_ptr, last_var_size);
+
+  VarDesc vd1 = vd_tgt2host;
+  vd1.ptr = last_var_ptr;
+  vd1.size = last_var_size;
+  VarDesc2 vd2 = { "var", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+  __offload_target_leave (ofldt);
+}
+
+/* Call offload function by the address fn_ptr and pass vars_ptr to it.  */
+static void
+__offload_target_run (OFFLOAD ofldt)
+{
+  void *fn_ptr;
+  void *vars_ptr;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &fn_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &vars_ptr;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd2[2] = { { "fn_ptr", 0 }, { "vars_ptr", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  TRACE ("(fn_ptr = %p, vars_ptr = %p)", fn_ptr, vars_ptr);
+  void (*fn)(void *) = (void (*)(void *)) fn_ptr;
+  fn (vars_ptr);
+  __offload_target_leave (ofldt);
+}
+
+
+/* This should be called from every library with offloading.  */
+extern "C" void
+target_register_lib (const void *target_table)
+{
+  TRACE ("(target_table = %p { %p, %p, %p, %p })", target_table,
+	 ((void **) target_table)[0], ((void **) target_table)[1],
+	 ((void **) target_table)[2], ((void **) target_table)[3]);
+
+  last_loaded_library = (void *) target_table;
+}
+
+/* Use __offload_target_main from liboffload.  */
+int
+main (int argc, char **argv)
+{
+  __offload_target_main ();
+  return 0;
+}
+
+
+/* Register offload_target_main's functions in the liboffload.  */
+
+struct Entry {
+  const char *name;
+  void *func;
+};
+
+#define REGISTER(f)				      \
+extern "C" const Entry __offload_target_##f##_$entry  \
+__attribute__ ((section(".OffloadEntryTable."))) = {  \
+  "__offload_target_"#f,			      \
+  (void *) __offload_target_##f			      \
+}
+REGISTER (init_proc);
+REGISTER (table_p1);
+REGISTER (table_p2);
+REGISTER (alloc);
+REGISTER (free);
+REGISTER (host2tgt_p1);
+REGISTER (host2tgt_p2);
+REGISTER (tgt2host_p1);
+REGISTER (tgt2host_p2);
+REGISTER (run);
+#undef REGISTER
-- 
1.7.1

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2014-10-23 16:00     ` Ilya Verbin
@ 2014-10-24 14:57       ` Jakub Jelinek
  2014-10-24 15:12         ` Ilya Verbin
  0 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2014-10-24 14:57 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Thu, Oct 23, 2014 at 07:41:12PM +0400, Ilya Verbin wrote:
> > malloc can fail, SIGSEGV in response to that is not desirable.
> > Can't you fallback to alloca, or use just alloca, or use alloca
> > with malloc fallback?
> 
> I replaced it with alloca.

There is a risk if a suid or otherwise priviledge escalated program
uses it and attacker passes huge env vars.
Perhaps use alloca if it is <= 2KB and malloc otherwise, and in that case
if malloc fails, just do a fatal error?

> > Where does this artificial limit come from?  Using libNNN.so library names?
> > Can't you use lib%d.so instead?
> 
> Yes, it comes from the Image structure (liboffloadmic/runtime/offload_host.h:52)
> It must contain a null-terminated name, therefore I need to allocate some space
> for the name in plugin's struct TargetImage.  But the structure can't contain
> any bytes after the trailing zero and before the actual data.
> So, now I extended the name to 10 digits and removed the comparison with 1000.

Ok.

> > Also, seeing register_image, shouldn't there be
> > GOMP_OFFLOAD_unregister_image which would be invoked when the library
> > containing MIC offloading regions is dlclosed?
> > One could use __cxa_atexit or similar for that, something that is given
> > &__dso_handle.  Or is no cleanup necessary?  At least unregistering it
> > from translation tables, because the same addresses might be reused by a
> > different shared library?
> > With dlopen/dlclose in mind, 1000 might be easily reached, consider 10000
> > times dlopening/dlclosing (perhaps over longer time, by long running daemon)
> > a shared library containg #pragma omp target region.
> 
> Hmm, previously we've tested only cases when all libraries are loaded before the
> first offload.  Offloading from a dlopened library after the call to
> gomp_target_init isn't working.  So, this will require some changes in
> libgomp/target.c .  Is it ok to fix this bug in a separate patch?

I guess it can be done incrementally, even during stage3.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2014-10-24 14:57       ` Jakub Jelinek
@ 2014-10-24 15:12         ` Ilya Verbin
  2014-10-24 15:19           ` Jakub Jelinek
  0 siblings, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2014-10-24 15:12 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On 24 Oct 16:35, Jakub Jelinek wrote:
> On Thu, Oct 23, 2014 at 07:41:12PM +0400, Ilya Verbin wrote:
> > > malloc can fail, SIGSEGV in response to that is not desirable.
> > > Can't you fallback to alloca, or use just alloca, or use alloca
> > > with malloc fallback?
> > 
> > I replaced it with alloca.
> 
> There is a risk if a suid or otherwise priviledge escalated program
> uses it and attacker passes huge env vars.
> Perhaps use alloca if it is <= 2KB and malloc otherwise, and in that case
> if malloc fails, just do a fatal error?

Why is this more preferable than just a malloc + fatal error?
This function is executed only once at plugin initialization, therefore no real
performance gain could be achived.

Thanks,
  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2014-10-24 15:12         ` Ilya Verbin
@ 2014-10-24 15:19           ` Jakub Jelinek
  2014-10-27 14:24             ` Ilya Verbin
  0 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2014-10-24 15:19 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Fri, Oct 24, 2014 at 07:08:44PM +0400, Ilya Verbin wrote:
> On 24 Oct 16:35, Jakub Jelinek wrote:
> > On Thu, Oct 23, 2014 at 07:41:12PM +0400, Ilya Verbin wrote:
> > > > malloc can fail, SIGSEGV in response to that is not desirable.
> > > > Can't you fallback to alloca, or use just alloca, or use alloca
> > > > with malloc fallback?
> > > 
> > > I replaced it with alloca.
> > 
> > There is a risk if a suid or otherwise priviledge escalated program
> > uses it and attacker passes huge env vars.
> > Perhaps use alloca if it is <= 2KB and malloc otherwise, and in that case
> > if malloc fails, just do a fatal error?
> 
> Why is this more preferable than just a malloc + fatal error?
> This function is executed only once at plugin initialization, therefore no real
> performance gain could be achived.

Even if it is executed once, using malloc for short env vars that will be
the 99% of all cases sounds like waste of resources to me.
You already know the strlen of the vars, so it is just a matter of
comparing that and setting a bool flag.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2014-10-24 15:19           ` Jakub Jelinek
@ 2014-10-27 14:24             ` Ilya Verbin
  2014-11-06 18:25               ` Jakub Jelinek
  0 siblings, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2014-10-27 14:24 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On 24 Oct 17:18, Jakub Jelinek wrote:
> On Fri, Oct 24, 2014 at 07:08:44PM +0400, Ilya Verbin wrote:
> > On 24 Oct 16:35, Jakub Jelinek wrote:
> > > On Thu, Oct 23, 2014 at 07:41:12PM +0400, Ilya Verbin wrote:
> > > > > malloc can fail, SIGSEGV in response to that is not desirable.
> > > > > Can't you fallback to alloca, or use just alloca, or use alloca
> > > > > with malloc fallback?
> > > > 
> > > > I replaced it with alloca.
> > > 
> > > There is a risk if a suid or otherwise priviledge escalated program
> > > uses it and attacker passes huge env vars.
> > > Perhaps use alloca if it is <= 2KB and malloc otherwise, and in that case
> > > if malloc fails, just do a fatal error?
> > 
> > Why is this more preferable than just a malloc + fatal error?
> > This function is executed only once at plugin initialization, therefore no real
> > performance gain could be achived.
> 
> Even if it is executed once, using malloc for short env vars that will be
> the 99% of all cases sounds like waste of resources to me.
> You already know the strlen of the vars, so it is just a matter of
> comparing that and setting a bool flag.

Done.  Is it ok?

Thanks,
  -- Ilya


---

diff --git a/liboffloadmic/configure.ac b/liboffloadmic/configure.ac
index fb575b3..81fae8f 100644
--- a/liboffloadmic/configure.ac
+++ b/liboffloadmic/configure.ac
@@ -42,6 +42,7 @@ AC_PROG_CC
 AC_PROG_CXX
 AC_CONFIG_FILES([Makefile liboffloadmic_host.spec liboffloadmic_target.spec])
 AM_ENABLE_MULTILIB(, ..)
+AC_CONFIG_SUBDIRS(plugin)
 AC_FUNC_ALLOCA
 AC_CHECK_HEADERS([mm_malloc.h], [], [AC_MSG_ERROR(["Couldn't find mm_malloc.h"])])
 AC_CHECK_FUNCS([__secure_getenv secure_getenv])
diff --git a/liboffloadmic/plugin/Makefile.am b/liboffloadmic/plugin/Makefile.am
new file mode 100644
index 0000000..0baf70d
--- /dev/null
+++ b/liboffloadmic/plugin/Makefile.am
@@ -0,0 +1,123 @@
+# Plugin for offload execution on Intel MIC devices.
+#
+# Copyright (C) 2014 Free Software Foundation, Inc.
+#
+# Contributed by Ilya Verbin <ilya.verbin@intel.com> and
+# Andrey Turetskiy <andrey.turetskiy@intel.com>.
+#
+# This file is part of the GNU OpenMP Library (libgomp).
+#
+# Libgomp is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# Under Section 7 of GPL version 3, you are granted additional
+# permissions described in the GCC Runtime Library Exception, version
+# 3.1, as published by the Free Software Foundation.
+#
+# You should have received a copy of the GNU General Public License and
+# a copy of the GCC Runtime Library Exception along with this program;
+# see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+
+AUTOMAKE_OPTIONS = foreign
+ACLOCAL_AMFLAGS = -I ../.. -I ../../config
+
+# Directories
+build_dir = $(top_builddir)
+source_dir = $(top_srcdir)
+coi_inc_dir = $(top_srcdir)/../include/coi
+myo_inc_dir = $(top_srcdir)/../include/myo
+libgomp_src_dir = $(top_srcdir)/../../libgomp
+libgomp_dir = $(build_dir)/../../libgomp
+liboffload_src_dir = $(top_srcdir)/../runtime
+liboffload_dir = $(top_builddir)/..
+
+# May be used by toolexeclibdir.
+gcc_version := $(shell cat $(top_srcdir)/../../gcc/BASE-VER)
+libsubincludedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/include
+# Search for main_target_image.h in these directories
+target_prefix_dir = $(libdir)/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
+target_build_dir = $(accel_search_dir)/$(accel_target)$(MULTISUBDIR)/liboffloadmic/plugin
+target_install_dir = $(accel_search_dir)/lib/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
+
+if PLUGIN_HOST
+  toolexeclib_LTLIBRARIES = libgomp-plugin-intelmic.la
+  libgomp_plugin_intelmic_la_SOURCES = libgomp-plugin-intelmic.cpp
+  libgomp_plugin_intelmic_la_CPPFLAGS = $(CPPFLAGS) -DLINUX -DCOI_LIBRARY_VERSION=2 -DMYO_SUPPORT -DOFFLOAD_DEBUG=1 -DSEP_SUPPORT -DTIMING_SUPPORT -DHOST_LIBRARY=1 -I$(coi_inc_dir) -I$(myo_inc_dir) -I$(liboffload_src_dir) -I$(libgomp_src_dir) -I$(libgomp_dir) -I$(target_prefix_dir)/include -I$(target_build_dir) -I$(target_install_dir)/include
+  libgomp_plugin_intelmic_la_LDFLAGS = -L$(liboffload_dir)/.libs -loffloadmic_host -version-info 1:0:0
+else # PLUGIN_TARGET
+  plugin_includedir = $(libsubincludedir)
+  plugin_include_HEADERS = main_target_image.h
+  AM_CPPFLAGS = $(CPPFLAGS) -DLINUX -DCOI_LIBRARY_VERSION=2 -DMYO_SUPPORT -DOFFLOAD_DEBUG=1 -DSEP_SUPPORT -DTIMING_SUPPORT -DHOST_LIBRARY=0 -I$(coi_inc_dir) -I$(myo_inc_dir) -I$(liboffload_src_dir) -I$(libgomp_dir)
+  AM_CXXFLAGS = $(CXXFLAGS)
+  AM_LDFLAGS = -L$(liboffload_dir)/.libs -L$(libgomp_dir)/.libs -loffloadmic_target -lcoi_device -lmyo-service -lgomp -rdynamic
+endif
+
+main_target_image.h: offload_target_main
+	@echo -n "const int image_size = " > $@
+	@stat -c '%s' $< >> $@
+	@echo ";" >> $@
+	@echo "struct MainTargetImage {" >> $@
+	@echo "  int64_t size;" >> $@
+	@echo "  char name[sizeof \"offload_target_main\"];" >> $@
+	@echo "  char data[image_size];" >> $@
+	@echo "};" >> $@
+	@echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
+	@echo "  image_size, \"offload_target_main\"," >> $@
+	@cat $< | xxd -include >> $@
+	@echo "};" >> $@
+
+offload_target_main: $(liboffload_dir)/ofldbegin.o offload_target_main.o $(liboffload_dir)/ofldend.o
+	$(CXX) $(AM_LDFLAGS) $^ -o $@
+
+offload_target_main.o: offload_target_main.cpp
+	$(CXX) $(AM_CXXFLAGS) $(AM_CPPFLAGS) -c $< -o $@
+
+# Work around what appears to be a GNU make bug handling MAKEFLAGS
+# values defined in terms of make variables, as is the case for CC and
+# friends when we are called from the top level Makefile.
+AM_MAKEFLAGS = \
+       "AR_FLAGS=$(AR_FLAGS)" \
+       "CC_FOR_BUILD=$(CC_FOR_BUILD)" \
+       "CFLAGS=$(CFLAGS)" \
+       "CXXFLAGS=$(CXXFLAGS)" \
+       "CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
+       "CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
+       "INSTALL=$(INSTALL)" \
+       "INSTALL_DATA=$(INSTALL_DATA)" \
+       "INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
+       "INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
+       "JC1FLAGS=$(JC1FLAGS)" \
+       "LDFLAGS=$(LDFLAGS)" \
+       "LIBCFLAGS=$(LIBCFLAGS)" \
+       "LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
+       "MAKE=$(MAKE)" \
+       "MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
+       "PICFLAG=$(PICFLAG)" \
+       "PICFLAG_FOR_TARGET=$(PICFLAG_FOR_TARGET)" \
+       "SHELL=$(SHELL)" \
+       "RUNTESTFLAGS=$(RUNTESTFLAGS)" \
+       "exec_prefix=$(exec_prefix)" \
+       "infodir=$(infodir)" \
+       "libdir=$(libdir)" \
+       "prefix=$(prefix)" \
+       "includedir=$(includedir)" \
+       "AR=$(AR)" \
+       "AS=$(AS)" \
+       "LD=$(LD)" \
+       "LIBCFLAGS=$(LIBCFLAGS)" \
+       "NM=$(NM)" \
+       "PICFLAG=$(PICFLAG)" \
+       "RANLIB=$(RANLIB)" \
+       "DESTDIR=$(DESTDIR)"
+
+MAKEOVERRIDES =
+
diff --git a/liboffloadmic/plugin/configure.ac b/liboffloadmic/plugin/configure.ac
new file mode 100644
index 0000000..283faad
--- /dev/null
+++ b/liboffloadmic/plugin/configure.ac
@@ -0,0 +1,135 @@
+# Plugin for offload execution on Intel MIC devices.
+#
+# Copyright (C) 2014 Free Software Foundation, Inc.
+#
+# Contributed by Andrey Turetskiy <andrey.turetskiy@intel.com>.
+#
+# This file is part of the GNU OpenMP Library (libgomp).
+#
+# Libgomp is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# Under Section 7 of GPL version 3, you are granted additional
+# permissions described in the GCC Runtime Library Exception, version
+# 3.1, as published by the Free Software Foundation.
+#
+# You should have received a copy of the GNU General Public License and
+# a copy of the GCC Runtime Library Exception along with this program;
+# see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+# Process this file with autoconf to produce a configure script, like so:
+# aclocal -I ../.. -I ../../config && autoconf && automake
+
+AC_PREREQ([2.64])
+AC_INIT([Intel MIC Offload Plugin], [1.0], ,[libgomp-plugin-intelmic])
+
+AC_CONFIG_AUX_DIR(../..)
+
+AC_CANONICAL_SYSTEM
+target_alias=${target_alias-$host_alias}
+AC_SUBST(target_alias)
+
+AM_INIT_AUTOMAKE([1.9.0 foreign no-dist])
+
+AM_MAINTAINER_MODE
+
+AC_PROG_CC
+AC_PROG_CXX
+AC_CONFIG_FILES([Makefile])
+AM_ENABLE_MULTILIB(, ../..)
+
+if test "${multilib}" = "yes"; then
+  multilib_arg="--enable-multilib"
+else
+  multilib_arg=
+fi
+
+# Make sure liboffloadmic is enabled
+case "$enable_liboffloadmic" in
+  host | target)
+    ;;
+  *)
+    AC_MSG_ERROR([Liboffloadmic is disabled]) ;;
+esac
+AM_CONDITIONAL(PLUGIN_HOST, [test x"$enable_liboffloadmic" = xhost])
+
+# Get accel target and path to build or install tree of accel compiler
+accel_search_dir=
+accel_target=
+if test x"$enable_liboffloadmic" = xhost; then
+  for accel in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
+    accel_name=`echo $accel | sed 's/=.*//'`
+    accel_dir=`echo $accel | grep '=' | sed 's/.*=//'`
+    case "$accel_name" in
+      *-intelmic-* | *-intelmicemul-*)
+	accel_target=$accel_name
+	accel_search_dir=$accel_dir
+	;;
+    esac
+  done
+  if test x"$accel_target" = x; then
+    AC_MSG_ERROR([--enable-offload-targets does not contain intelmic target])
+  fi
+fi
+AC_SUBST(accel_search_dir)
+AC_SUBST(accel_target)
+
+AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
+AC_ARG_ENABLE([version-specific-runtime-libs],
+  AC_HELP_STRING([--enable-version-specific-runtime-libs],
+		 [Specify that runtime libraries should be installed in a compiler-specific directory]),
+  [case "$enableval" in
+    yes) enable_version_specific_runtime_libs=yes ;;
+    no)  enable_version_specific_runtime_libs=no ;;
+    *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
+   esac],
+  [enable_version_specific_runtime_libs=no])
+AC_MSG_RESULT($enable_version_specific_runtime_libs)
+
+
+# Calculate toolexeclibdir.
+# Also toolexecdir, though it's only used in toolexeclibdir.
+case ${enable_version_specific_runtime_libs} in
+  yes)
+    # Need the gcc compiler version to know where to install libraries
+    # and header files if --enable-version-specific-runtime-libs option
+    # is selected.
+    toolexecdir='$(libdir)/gcc/$(target_alias)'
+    toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
+    ;;
+  no)
+    if test -n "$with_cross_host" &&
+       test x"$with_cross_host" != x"no"; then
+      # Install a library built with a cross compiler in tooldir, not libdir.
+      toolexecdir='$(exec_prefix)/$(target_alias)'
+      toolexeclibdir='$(toolexecdir)/lib'
+    else
+      toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+      toolexeclibdir='$(libdir)'
+    fi
+    multi_os_directory=`$CC -print-multi-os-directory`
+    case $multi_os_directory in
+      .) ;; # Avoid trailing /.
+      *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
+    esac
+    ;;
+esac
+
+AC_LIBTOOL_DLOPEN
+AM_PROG_LIBTOOL
+# Forbid libtool to hardcode RPATH, because we want to be able to specify
+# library search directory using LD_LIBRARY_PATH
+hardcode_into_libs=no
+AC_SUBST(toolexecdir)
+AC_SUBST(toolexeclibdir)
+
+# Must be last
+AC_OUTPUT
diff --git a/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp
new file mode 100644
index 0000000..22d8625
--- /dev/null
+++ b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp
@@ -0,0 +1,448 @@
+/* Plugin for offload execution on Intel MIC devices.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   Contributed by Ilya Verbin <ilya.verbin@intel.com>.
+
+   This file is part of the GNU OpenMP Library (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Host side part of a libgomp plugin.  */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <utility>
+#include <vector>
+#include <libgomp_target.h>
+#include "compiler_if_host.h"
+#include "main_target_image.h"
+
+#define LD_LIBRARY_PATH_ENV	"LD_LIBRARY_PATH"
+#define MIC_LD_LIBRARY_PATH_ENV	"MIC_LD_LIBRARY_PATH"
+
+#ifdef DEBUG
+#define TRACE(...)					    \
+{							    \
+fprintf (stderr, "HOST:\t%s:%s ", __FILE__, __FUNCTION__);  \
+fprintf (stderr, __VA_ARGS__);				    \
+fprintf (stderr, "\n");					    \
+}
+#else
+#define TRACE { }
+#endif
+
+
+static VarDesc vd_host2tgt = {
+  { 1, 1 },		      /* dst, src			      */
+  { 1, 0 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+static VarDesc vd_tgt2host = {
+  { 1, 1 },		      /* dst, src			      */
+  { 0, 1 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+
+/* Total number of shared libraries with offloading to Intel MIC.  */
+static int num_libraries;
+
+/* Pointers to the descriptors, containing pointers to host-side tables and to
+   target images.  */
+static std::vector< std::pair<void *, void *> > lib_descrs;
+
+/* Thread-safe registration of the main image.  */
+static pthread_once_t main_image_is_registered = PTHREAD_ONCE_INIT;
+
+
+/* Add path specified in LD_LIBRARY_PATH to MIC_LD_LIBRARY_PATH, which is
+   required by liboffloadmic.  */
+__attribute__((constructor))
+static void
+set_mic_lib_path (void)
+{
+  bool use_alloca;
+  const char *ld_lib_path = getenv (LD_LIBRARY_PATH_ENV);
+  const char *mic_lib_path = getenv (MIC_LD_LIBRARY_PATH_ENV);
+  char *mic_lib_path_new;
+  size_t len;
+
+  if (!ld_lib_path)
+    return;
+
+  len = (mic_lib_path ? strlen (mic_lib_path) : 0) + strlen (ld_lib_path) + 2;
+  use_alloca = len <= 2048;
+
+  mic_lib_path_new = (char *) (use_alloca ? alloca (len) : malloc (len));
+  if (!mic_lib_path_new)
+    {
+      fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
+      exit (1);
+    }
+
+  if (!mic_lib_path)
+    strcpy (mic_lib_path_new, ld_lib_path);
+  else
+    sprintf (mic_lib_path_new, "%s:%s", mic_lib_path, ld_lib_path);
+  setenv (MIC_LD_LIBRARY_PATH_ENV, mic_lib_path_new, 1);
+
+  if (!use_alloca)
+    free (mic_lib_path_new);
+}
+
+extern "C" enum offload_target_type
+GOMP_OFFLOAD_get_type (void)
+{
+  enum offload_target_type res = OFFLOAD_TARGET_TYPE_INTEL_MIC;
+  TRACE ("(): return %d", res);
+  return res;
+}
+
+extern "C" int
+GOMP_OFFLOAD_get_num_devices (void)
+{
+  int res = _Offload_number_of_devices ();
+  TRACE ("(): return %d", res);
+  return res;
+}
+
+/* This should be called from every shared library with offloading.  */
+extern "C" void
+GOMP_OFFLOAD_register_image (void *host_table, void *target_image)
+{
+  TRACE ("(host_table = %p, target_image = %p)", host_table, target_image);
+  lib_descrs.push_back (std::make_pair (host_table, target_image));
+  num_libraries++;
+}
+
+static void
+offload (const char *file, uint64_t line, int device, const char *name,
+	 int num_vars, VarDesc *vars, VarDesc2 *vars2)
+{
+  OFFLOAD ofld = __offload_target_acquire1 (&device, file, line);
+  if (ofld)
+    __offload_offload1 (ofld, name, 0, num_vars, vars, vars2, 0, NULL, NULL);
+  else
+    {
+      fprintf (stderr, "%s:%d: Offload target acquire failed\n", file, line);
+      exit (1);
+    }
+}
+
+static void
+register_main_image ()
+{
+  __offload_register_image (&main_target_image);
+}
+
+/* Load offload_target_main on target.  */
+extern "C" void
+GOMP_OFFLOAD_init_device (int device)
+{
+  TRACE ("");
+  pthread_once (&main_image_is_registered, register_main_image);
+  offload (__FILE__, __LINE__, device, "__offload_target_init_proc", 0,
+	   NULL, NULL);
+}
+
+static void
+get_target_table (int device, int &num_funcs, int &num_vars, void **&table)
+{
+  VarDesc vd1[2] = { vd_tgt2host, vd_tgt2host };
+  vd1[0].ptr = &num_funcs;
+  vd1[0].size = sizeof (num_funcs);
+  vd1[1].ptr = &num_vars;
+  vd1[1].size = sizeof (num_vars);
+  VarDesc2 vd1g[2] = { { "num_funcs", 0 }, { "num_vars", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_table_p1", 2,
+	   vd1, vd1g);
+
+  int table_size = num_funcs + 2 * num_vars;
+  if (table_size > 0)
+    {
+      table = new void * [table_size];
+
+      VarDesc vd2;
+      vd2 = vd_tgt2host;
+      vd2.ptr = table;
+      vd2.size = table_size * sizeof (void *);
+      VarDesc2 vd2g = { "table", 0 };
+
+      offload (__FILE__, __LINE__, device, "__offload_target_table_p2", 1,
+	       &vd2, &vd2g);
+    }
+}
+
+static void
+load_lib_and_get_table (int device, int lib_num, mapping_table *&table,
+			int &table_size)
+{
+  struct TargetImage {
+    int64_t size;
+    /* 10 characters is enough for max int value.  */
+    char name[sizeof ("lib0000000000.so")];
+    char data[];
+  } __attribute__ ((packed));
+
+  void ***host_table_descr = (void ***) lib_descrs[lib_num].first;
+  void **host_func_start = host_table_descr[0];
+  void **host_func_end   = host_table_descr[1];
+  void **host_var_start  = host_table_descr[2];
+  void **host_var_end    = host_table_descr[3];
+
+  void **target_image_descr = (void **) lib_descrs[lib_num].second;
+  void *image_start = target_image_descr[0];
+  void *image_end   = target_image_descr[1];
+
+  TRACE ("() host_table_descr { %p, %p, %p, %p }", host_func_start,
+	 host_func_end, host_var_start, host_var_end);
+  TRACE ("() target_image_descr { %p, %p }", image_start, image_end);
+
+  int64_t image_size = (uintptr_t) image_end - (uintptr_t) image_start;
+  TargetImage *image
+    = (TargetImage *) malloc (sizeof (int64_t) + sizeof ("lib0000000000.so")
+			      + image_size);
+  if (!image)
+    {
+      fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
+      exit (1);
+    }
+
+  image->size = image_size;
+  sprintf (image->name, "lib%010d.so", lib_num);
+  memcpy (image->data, image_start, image->size);
+
+  TRACE ("() __offload_register_image %s { %p, %d }",
+	 image->name, image_start, image->size);
+  __offload_register_image (image);
+
+  int tgt_num_funcs = 0;
+  int tgt_num_vars = 0;
+  void **tgt_table = NULL;
+  get_target_table (device, tgt_num_funcs, tgt_num_vars, tgt_table);
+  free (image);
+
+  /* The func table contains only addresses, the var table contains addresses
+     and corresponding sizes.  */
+  int host_num_funcs = host_func_end - host_func_start;
+  int host_num_vars  = (host_var_end - host_var_start) / 2;
+  TRACE ("() host_num_funcs = %d, tgt_num_funcs = %d",
+	 host_num_funcs, tgt_num_funcs);
+  TRACE ("() host_num_vars = %d, tgt_num_vars = %d",
+	 host_num_vars, tgt_num_vars);
+  if (host_num_funcs != tgt_num_funcs)
+    {
+      fprintf (stderr, "%s: Can't map target functions\n", __FILE__);
+      exit (1);
+    }
+  if (host_num_vars != tgt_num_vars)
+    {
+      fprintf (stderr, "%s: Can't map target variables\n", __FILE__);
+      exit (1);
+    }
+
+  table = (mapping_table *) realloc (table, (table_size + host_num_funcs
+					     + host_num_vars)
+					    * sizeof (mapping_table));
+  if (table == NULL)
+    {
+      fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
+      exit (1);
+    }
+
+  for (int i = 0; i < host_num_funcs; i++)
+    {
+      mapping_table t;
+      t.host_start = (uintptr_t) host_func_start[i];
+      t.host_end = t.host_start + 1;
+      t.tgt_start = (uintptr_t) tgt_table[i];
+      t.tgt_end = t.tgt_start + 1;
+
+      TRACE ("() lib %d, func %d:\t0x%llx -- 0x%llx",
+	     lib_num, i, t.host_start, t.tgt_start);
+
+      table[table_size++] = t;
+    }
+
+  for (int i = 0; i < host_num_vars * 2; i += 2)
+    {
+      mapping_table t;
+      t.host_start = (uintptr_t) host_var_start[i];
+      t.host_end = t.host_start + (uintptr_t) host_var_start[i+1];
+      t.tgt_start = (uintptr_t) tgt_table[tgt_num_funcs+i];
+      t.tgt_end = t.tgt_start + (uintptr_t) tgt_table[tgt_num_funcs+i+1];
+
+      TRACE ("() lib %d, var %d:\t0x%llx (%d) -- 0x%llx (%d)", lib_num, i/2,
+	     t.host_start, t.host_end - t.host_start,
+	     t.tgt_start, t.tgt_end - t.tgt_start);
+
+      table[table_size++] = t;
+    }
+
+  delete [] tgt_table;
+}
+
+extern "C" int
+GOMP_OFFLOAD_get_table (int device, void *result)
+{
+  TRACE ("(num_libraries = %d)", num_libraries);
+
+  mapping_table *table = NULL;
+  int table_size = 0;
+
+  for (int i = 0; i < num_libraries; i++)
+    load_lib_and_get_table (device, i, table, table_size);
+
+  *(void **) result = table;
+  return table_size;
+}
+
+extern "C" void *
+GOMP_OFFLOAD_alloc (int device, size_t size)
+{
+  TRACE ("(size = %d)", size);
+
+  void *tgt_ptr;
+  VarDesc vd1[2] = { vd_host2tgt, vd_tgt2host };
+  vd1[0].ptr = &size;
+  vd1[0].size = sizeof (size);
+  vd1[1].ptr = &tgt_ptr;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd1g[2] = { { "size", 0 }, { "tgt_ptr", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_alloc", 2, vd1, vd1g);
+
+  return tgt_ptr;
+}
+
+extern "C" void
+GOMP_OFFLOAD_free (int device, void *tgt_ptr)
+{
+  TRACE ("(tgt_ptr = %p)", tgt_ptr);
+
+  VarDesc vd1 = vd_host2tgt;
+  vd1.ptr = &tgt_ptr;
+  vd1.size = sizeof (void *);
+  VarDesc2 vd1g = { "tgt_ptr", 0 };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_free", 1, &vd1, &vd1g);
+}
+
+extern "C" void *
+GOMP_OFFLOAD_host2dev (int device, void *tgt_ptr, const void *host_ptr,
+		       size_t size)
+{
+  TRACE ("(tgt_ptr = %p, host_ptr = %p, size = %d)", tgt_ptr, host_ptr, size);
+  if (!size)
+    return tgt_ptr;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &tgt_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &size;
+  vd1[1].size = sizeof (size);
+  VarDesc2 vd1g[2] = { { "tgt_ptr", 0 }, { "size", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p1", 2,
+	   vd1, vd1g);
+
+  VarDesc vd2 = vd_host2tgt;
+  vd2.ptr = (void *) host_ptr;
+  vd2.size = size;
+  VarDesc2 vd2g = { "var", 0 };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p2", 1,
+	   &vd2, &vd2g);
+
+  return tgt_ptr;
+}
+
+extern "C" void *
+GOMP_OFFLOAD_dev2host (int device, void *host_ptr, const void *tgt_ptr,
+		       size_t size)
+{
+  TRACE ("(host_ptr = %p, tgt_ptr = %p, size = %d)", host_ptr, tgt_ptr, size);
+  if (!size)
+    return host_ptr;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &tgt_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &size;
+  vd1[1].size = sizeof (size);
+  VarDesc2 vd1g[2] = { { "tgt_ptr", 0 }, { "size", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p1", 2,
+	   vd1, vd1g);
+
+  VarDesc vd2 = vd_tgt2host;
+  vd2.ptr = (void *) host_ptr;
+  vd2.size = size;
+  VarDesc2 vd2g = { "var", 0 };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p2", 1,
+	   &vd2, &vd2g);
+
+  return host_ptr;
+}
+
+extern "C" void
+GOMP_OFFLOAD_run (int device, void *tgt_fn, void *tgt_vars)
+{
+  TRACE ("(tgt_fn = %p, tgt_vars = %p)", tgt_fn, tgt_vars);
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &tgt_fn;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &tgt_vars;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd1g[2] = { { "tgt_fn", 0 }, { "tgt_vars", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_run", 2, vd1, vd1g);
+}
diff --git a/liboffloadmic/plugin/offload_target_main.cpp b/liboffloadmic/plugin/offload_target_main.cpp
new file mode 100644
index 0000000..4a2778e
--- /dev/null
+++ b/liboffloadmic/plugin/offload_target_main.cpp
@@ -0,0 +1,366 @@
+/* Plugin for offload execution on Intel MIC devices.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   Contributed by Ilya Verbin <ilya.verbin@intel.com>.
+
+   This file is part of the GNU OpenMP Library (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Target side part of a libgomp plugin.  */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "compiler_if_target.h"
+
+
+#ifdef DEBUG
+#define TRACE(...)					      \
+{							      \
+fprintf (stderr, "TARGET:\t%s:%s ", __FILE__, __FUNCTION__);  \
+fprintf (stderr, __VA_ARGS__);				      \
+fprintf (stderr, "\n");					      \
+}
+#else
+#define TRACE { }
+#endif
+
+
+static VarDesc vd_host2tgt = {
+  { 1, 1 },		      /* dst, src			      */
+  { 1, 0 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+static VarDesc vd_tgt2host = {
+  { 1, 1 },		      /* dst, src			      */
+  { 0, 1 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+/* Pointer to the descriptor of the last loaded shared library.  */
+static void *last_loaded_library = NULL;
+
+/* Pointer and size of the variable, used in __offload_target_host2tgt_p[12]
+   and __offload_target_tgt2host_p[12].  */
+static void *last_var_ptr = NULL;
+static int last_var_size = 0;
+
+
+/* Override the corresponding functions from libgomp.  */
+extern "C" int
+omp_is_initial_device (void) __GOMP_NOTHROW
+{
+  return 0;
+}
+
+extern "C" int32_t
+omp_is_initial_device_ (void)
+{
+  return omp_is_initial_device ();
+}
+
+
+/* Dummy function needed for the initialization of target process during the
+   first call to __offload_offload1.  */
+static void
+__offload_target_init_proc (OFFLOAD ofldt)
+{
+  TRACE ("");
+}
+
+/* Collect addresses of the offload functions and of the global variables from
+   the library descriptor and send them to host.
+   Part 1: Send num_funcs and num_vars to host.  */
+static void
+__offload_target_table_p1 (OFFLOAD ofldt)
+{
+  void ***lib_descr = (void ***) last_loaded_library;
+
+  if (lib_descr == NULL)
+    {
+      TRACE ("");
+      fprintf (stderr, "Error! No shared libraries loaded on target.\n");
+      return;
+    }
+
+  void **func_table_begin = lib_descr[0];
+  void **func_table_end   = lib_descr[1];
+  void **var_table_begin  = lib_descr[2];
+  void **var_table_end    = lib_descr[3];
+
+  /* The func table contains only addresses, the var table contains addresses
+     and corresponding sizes.  */
+  int num_funcs = func_table_end - func_table_begin;
+  int num_vars = (var_table_end - var_table_begin) / 2;
+  TRACE ("(num_funcs = %d, num_vars = %d)", num_funcs, num_vars);
+
+  VarDesc vd1[2] = { vd_tgt2host, vd_tgt2host };
+  vd1[0].ptr = &num_funcs;
+  vd1[0].size = sizeof (num_funcs);
+  vd1[1].ptr = &num_vars;
+  vd1[1].size = sizeof (num_vars);
+  VarDesc2 vd2[2] = { { "num_funcs", 0 }, { "num_vars", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  __offload_target_leave (ofldt);
+}
+
+/* Part 2: Send the table with addresses to host.  */
+static void
+__offload_target_table_p2 (OFFLOAD ofldt)
+{
+  void ***lib_descr = (void ***) last_loaded_library;
+  void **func_table_begin = lib_descr[0];
+  void **func_table_end   = lib_descr[1];
+  void **var_table_begin  = lib_descr[2];
+  void **var_table_end    = lib_descr[3];
+
+  int num_funcs = func_table_end - func_table_begin;
+  int num_vars = (var_table_end - var_table_begin) / 2;
+  int table_size = (num_funcs + 2 * num_vars) * sizeof (void *);
+  void **table = (void **) malloc (table_size);
+  TRACE ("(table_size = %d)", table_size);
+
+  VarDesc vd1;
+  vd1 = vd_tgt2host;
+  vd1.ptr = table;
+  vd1.size = table_size;
+  VarDesc2 vd2 = { "table", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+
+  void **p;
+  int i = 0;
+  for (p = func_table_begin; p < func_table_end; p++, i++)
+    table[i] = *p;
+
+  for (p = var_table_begin; p < var_table_end; p++, i++)
+    table[i] = *p;
+
+  __offload_target_leave (ofldt);
+  free (table);
+}
+
+/* Allocate size bytes and send a pointer to the allocated memory to host.  */
+static void
+__offload_target_alloc (OFFLOAD ofldt)
+{
+  size_t size = 0;
+  void *ptr = NULL;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_tgt2host };
+  vd1[0].ptr = &size;
+  vd1[0].size = sizeof (size);
+  vd1[1].ptr = &ptr;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd2[2] = { { "size", 0 }, { "ptr", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  ptr = malloc (size);
+  TRACE ("(size = %d): ptr = %p", size, ptr);
+  __offload_target_leave (ofldt);
+}
+
+/* Free the memory space pointed to by ptr.  */
+static void
+__offload_target_free (OFFLOAD ofldt)
+{
+  void *ptr = 0;
+
+  VarDesc vd1 = vd_host2tgt;
+  vd1.ptr = &ptr;
+  vd1.size = sizeof (void *);
+  VarDesc2 vd2 = { "ptr", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+  TRACE ("(ptr = %p)", ptr);
+  free (ptr);
+  __offload_target_leave (ofldt);
+}
+
+/* Receive var_size bytes from host and store to var_ptr.
+   Part 1: Receive var_ptr and var_size from host.  */
+static void
+__offload_target_host2tgt_p1 (OFFLOAD ofldt)
+{
+  void *var_ptr = NULL;
+  size_t var_size = 0;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &var_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &var_size;
+  vd1[1].size = sizeof (var_size);
+  VarDesc2 vd2[2] = { { "var_ptr", 0 }, { "var_size", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  TRACE ("(var_ptr = %p, var_size = %d)", var_ptr, var_size);
+  last_var_ptr = var_ptr;
+  last_var_size = var_size;
+  __offload_target_leave (ofldt);
+}
+
+/* Part 2: Receive the data from host.  */
+static void
+__offload_target_host2tgt_p2 (OFFLOAD ofldt)
+{
+  TRACE ("(last_var_ptr = %p, last_var_size = %d)",
+	 last_var_ptr, last_var_size);
+
+  VarDesc vd1 = vd_host2tgt;
+  vd1.ptr = last_var_ptr;
+  vd1.size = last_var_size;
+  VarDesc2 vd2 = { "var", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+  __offload_target_leave (ofldt);
+}
+
+/* Send var_size bytes from var_ptr to host.
+   Part 1: Receive var_ptr and var_size from host.  */
+static void
+__offload_target_tgt2host_p1 (OFFLOAD ofldt)
+{
+  void *var_ptr = NULL;
+  size_t var_size = 0;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &var_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &var_size;
+  vd1[1].size = sizeof (var_size);
+  VarDesc2 vd2[2] = { { "var_ptr", 0 }, { "var_size", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  TRACE ("(var_ptr = %p, var_size = %d)", var_ptr, var_size);
+  last_var_ptr = var_ptr;
+  last_var_size = var_size;
+  __offload_target_leave (ofldt);
+}
+
+/* Part 2: Send the data to host.  */
+static void
+__offload_target_tgt2host_p2 (OFFLOAD ofldt)
+{
+  TRACE ("(last_var_ptr = %p, last_var_size = %d)",
+	 last_var_ptr, last_var_size);
+
+  VarDesc vd1 = vd_tgt2host;
+  vd1.ptr = last_var_ptr;
+  vd1.size = last_var_size;
+  VarDesc2 vd2 = { "var", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+  __offload_target_leave (ofldt);
+}
+
+/* Call offload function by the address fn_ptr and pass vars_ptr to it.  */
+static void
+__offload_target_run (OFFLOAD ofldt)
+{
+  void *fn_ptr;
+  void *vars_ptr;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &fn_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &vars_ptr;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd2[2] = { { "fn_ptr", 0 }, { "vars_ptr", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  TRACE ("(fn_ptr = %p, vars_ptr = %p)", fn_ptr, vars_ptr);
+  void (*fn)(void *) = (void (*)(void *)) fn_ptr;
+  fn (vars_ptr);
+  __offload_target_leave (ofldt);
+}
+
+
+/* This should be called from every library with offloading.  */
+extern "C" void
+target_register_lib (const void *target_table)
+{
+  TRACE ("(target_table = %p { %p, %p, %p, %p })", target_table,
+	 ((void **) target_table)[0], ((void **) target_table)[1],
+	 ((void **) target_table)[2], ((void **) target_table)[3]);
+
+  last_loaded_library = (void *) target_table;
+}
+
+/* Use __offload_target_main from liboffload.  */
+int
+main (int argc, char **argv)
+{
+  __offload_target_main ();
+  return 0;
+}
+
+
+/* Register offload_target_main's functions in the liboffload.  */
+
+struct Entry {
+  const char *name;
+  void *func;
+};
+
+#define REGISTER(f)				      \
+extern "C" const Entry __offload_target_##f##_$entry  \
+__attribute__ ((section(".OffloadEntryTable."))) = {  \
+  "__offload_target_"#f,			      \
+  (void *) __offload_target_##f			      \
+}
+REGISTER (init_proc);
+REGISTER (table_p1);
+REGISTER (table_p2);
+REGISTER (alloc);
+REGISTER (free);
+REGISTER (host2tgt_p1);
+REGISTER (host2tgt_p2);
+REGISTER (tgt2host_p1);
+REGISTER (tgt2host_p2);
+REGISTER (run);
+#undef REGISTER
-- 
1.7.1

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 2/4] Add liboffloadmic
  2014-10-22 19:31     ` Ilya Verbin
@ 2014-10-29 16:31       ` Ilya Verbin
  2014-11-06 18:21       ` Jakub Jelinek
  1 sibling, 0 replies; 111+ messages in thread
From: Ilya Verbin @ 2014-10-29 16:31 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On 22 Oct 23:21, Ilya Verbin wrote:
> On 22 Oct 10:54, Jakub Jelinek wrote:
> > On Tue, Oct 21, 2014 at 09:20:34PM +0400, Ilya Verbin wrote:
> > > This patch contains liboffloadmic library.
> > > 
> > > It is used by ICC for offloading.  The sources are imported from upstream
> > > ( https://www.openmprtl.org/sites/default/files/liboffload_oss.tgz )
> > > Configure and makefiles are new.
> > > 
> > > Also liboffloadmic/runtime/emulator directory is new.  This emulator consists
> > > of 4 shared libraries which replace COI and MYO libraries from MPSS stack.
> > 
> > For the real offloading rather than emulation, are there any further
> > libraries needed, or are the COI and MYO bits included in the source
> > everything that is needed?  Does one need some kernel module, will it be
> > open source, are there any plans to push it to Linus' tree?
> > I know the HW isn't shipping yet, but it would be nice to get those
> > questions answered now.
> 
> In case of the real offloading, user is supposed to specify the path to real COI
> and MYO libraries from MPSS:
> https://software.intel.com/en-us/articles/intel-manycore-platform-software-stack-mpss
> Their sources can be found in 'Downloads' section, in 'mpss-src-3.4.tar'.
> 
> COI in MYO depend only on the SCIF library, which is also open source.
> And SCIF requires some kernel module(s).  I'll ask the authors of MPSS, whether
> all these modules are open source, and about their plans of pushing them to
> Linus' tree.

Yes, the kernel module required by SCIF is also open source.
(the sources are in mpss-modules-3.4.1.tar.bz2 inside mpss-src-3.4.1.tar)
And there are plans of pushing it to Linus' tree.

  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-10-21 17:16 [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC Ilya Verbin
                   ` (2 preceding siblings ...)
  2014-10-21 17:28 ` [PATCH 3/4] Add libgomp plugin for Intel MIC Ilya Verbin
@ 2014-10-30 12:45 ` Ilya Verbin
  2014-11-06 17:55   ` Jakub Jelinek
                     ` (2 more replies)
  2014-12-22 12:08 ` [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC Thomas Schwinge
  4 siblings, 3 replies; 111+ messages in thread
From: Ilya Verbin @ 2014-10-30 12:45 UTC (permalink / raw)
  To: Jakub Jelinek, gcc-patches; +Cc: Kirill Yukhin, Andrey Turetskiy

Hello,

This patch allows to run non-fallback 'make check-target-libgomp'.  It passes to
the host compiler additional -B options with the paths to the offload compilers,
since non-installed host compiler doesn't know where to find mkoffload tools.
Also in case of intelmic offload targets it appends paths to liboffloadmic lib.
Is it ok for trunk?

Thanks,
  -- Ilya


2014-10-30  Andrey Turetskiy  <andrey.turetskiy@intel.com>
	    Ilya Verbin  <ilya.verbin@intel.com>

libgomp/
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Set up offload_additional_options,
	offload_additional_lib_paths and offload_targets.
	* testsuite/Makefile.am: Overrule site.exp.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/lib/libgomp.exp (libgomp_init): Append
	offload_additional_lib_paths to LD_LIBRARY_PATH.  Append
	offload_additional_options to ALWAYS_CFLAGS.  Append liboffloadmic
	build directory to LD_LIBRARY_PATH for intelmic offload targets.

---

diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 5cd666f..8e4774f 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -268,6 +268,9 @@ lt_host_flags = @lt_host_flags@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 multi_basedir = @multi_basedir@
+offload_additional_lib_paths = @offload_additional_lib_paths@
+offload_additional_options = @offload_additional_options@
+offload_targets = @offload_targets@
 oldincludedir = @oldincludedir@
 pdfdir = @pdfdir@
 prefix = @prefix@
diff --git a/libgomp/configure b/libgomp/configure
index 97c9be6..aabf25f 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -616,6 +616,9 @@ OMP_LOCK_SIZE
 USE_FORTRAN_FALSE
 USE_FORTRAN_TRUE
 link_gomp
+offload_additional_lib_paths
+offload_additional_options
+offload_targets
 XLDFLAGS
 XCFLAGS
 config_path
@@ -11094,7 +11097,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11097 "configure"
+#line 11100 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11200,7 +11203,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11203 "configure"
+#line 11206 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -16207,9 +16210,13 @@ else
   multilib_arg=
 fi
 
+# Get accel target and path to install tree of accel compiler
+offload_additional_options=
+offload_additional_lib_paths=
 offload_targets=
 if test x"$enable_offload_targets" != x; then
   for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
+    tgt_dir=`echo $tgt | grep '=' | sed 's/.*=//'`
     tgt=`echo $tgt | sed 's/=.*//'`
     case $tgt in
       *-intelmic-* | *-intelmicemul-*)
@@ -16222,6 +16229,13 @@ if test x"$enable_offload_targets" != x; then
     else
       offload_targets=$offload_targets,$tgt_name
     fi
+    if test x"$tgt_dir" != x; then
+      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
+      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib"
+    else
+      offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
+      offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"
+    fi
   done
 fi
 
@@ -16230,6 +16244,9 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+
+
+
 # Set up the set of libraries that we need to link against for libgomp.
 # Note that the GOMP_SELF_SPEC in gcc.c may force -pthread,
 # which will force linkage against -lpthread (or equivalent for the system).
diff --git a/libgomp/configure.ac b/libgomp/configure.ac
index 3f34ff8..cea6366 100644
--- a/libgomp/configure.ac
+++ b/libgomp/configure.ac
@@ -280,9 +280,13 @@ else
   multilib_arg=
 fi
 
+# Get accel target and path to install tree of accel compiler
+offload_additional_options=
+offload_additional_lib_paths=
 offload_targets=
 if test x"$enable_offload_targets" != x; then
   for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
+    tgt_dir=`echo $tgt | grep '=' | sed 's/.*=//'`
     tgt=`echo $tgt | sed 's/=.*//'`
     case $tgt in
       *-intelmic-* | *-intelmicemul-*)
@@ -295,10 +299,20 @@ if test x"$enable_offload_targets" != x; then
     else
       offload_targets=$offload_targets,$tgt_name
     fi
+    if test x"$tgt_dir" != x; then
+      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
+      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib"
+    else
+      offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
+      offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"
+    fi
   done
 fi
 AC_DEFINE_UNQUOTED(OFFLOAD_TARGETS, "$offload_targets",
   [Define to hold the list of target names suitable for offloading.])
+AC_SUBST(offload_targets)
+AC_SUBST(offload_additional_options)
+AC_SUBST(offload_additional_lib_paths)
 
 # Set up the set of libraries that we need to link against for libgomp.
 # Note that the GOMP_SELF_SPEC in gcc.c may force -pthread,
diff --git a/libgomp/testsuite/Makefile.am b/libgomp/testsuite/Makefile.am
index 561b7e2..d2ff1ed 100644
--- a/libgomp/testsuite/Makefile.am
+++ b/libgomp/testsuite/Makefile.am
@@ -11,3 +11,30 @@ EXPECT = $(shell if test -f $(top_builddir)/../expect/expect; then \
 _RUNTEST = $(shell if test -f $(top_srcdir)/../dejagnu/runtest; then \
 	     echo $(top_srcdir)/../dejagnu/runtest; else echo runtest; fi)
 RUNTEST = "$(_RUNTEST) $(AM_RUNTESTFLAGS)"
+
+# We need more things in site.exp, but automake completely controls the
+# creation of that file; there's no way to append to it without messing up
+# the dependancy chains.  So we overrule automake.  This rule is exactly
+# what it would have generated, plus our own additions.
+site.exp: Makefile
+	@echo 'Making a new site.exp file...'
+	@echo '## these variables are automatically generated by make ##' >site.tmp
+	@echo '# Do not edit here.  If you wish to override these values' >>site.tmp
+	@echo '# edit the last section' >>site.tmp
+	@echo 'set srcdir $(srcdir)' >>site.tmp
+	@echo "set objdir `pwd`" >>site.tmp
+	@echo 'set build_alias "$(build_alias)"' >>site.tmp
+	@echo 'set build_triplet $(build_triplet)' >>site.tmp
+	@echo 'set host_alias "$(host_alias)"' >>site.tmp
+	@echo 'set host_triplet $(host_triplet)' >>site.tmp
+	@echo 'set target_alias "$(target_alias)"' >>site.tmp
+	@echo 'set target_triplet $(target_triplet)' >>site.tmp
+	@echo 'set offload_targets "$(offload_targets)"' >>site.tmp
+	@echo 'set offload_additional_options "$(offload_additional_options)"' >>site.tmp
+	@echo 'set offload_additional_lib_paths "$(offload_additional_lib_paths)"' >>site.tmp
+	@echo '## All variables above are generated by configure. Do Not Edit ##' >>site.tmp
+	@test ! -f site.exp || \
+	  sed '1,/^## All variables above are.*##/ d' site.exp >> site.tmp
+	@-rm -f site.bak
+	@test ! -f site.exp || mv site.exp site.bak
+	@mv site.tmp site.exp
diff --git a/libgomp/testsuite/Makefile.in b/libgomp/testsuite/Makefile.in
index 5273eaa..ab326cf 100644
--- a/libgomp/testsuite/Makefile.in
+++ b/libgomp/testsuite/Makefile.in
@@ -184,6 +184,9 @@ lt_host_flags = @lt_host_flags@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 multi_basedir = @multi_basedir@
+offload_additional_lib_paths = @offload_additional_lib_paths@
+offload_additional_options = @offload_additional_options@
+offload_targets = @offload_targets@
 oldincludedir = @oldincludedir@
 pdfdir = @pdfdir@
 prefix = @prefix@
@@ -272,25 +275,6 @@ check-DEJAGNU: site.exp
 	else echo "WARNING: could not find \`runtest'" 1>&2; :;\
 	fi; \
 	exit $$exit_status
-site.exp: Makefile
-	@echo 'Making a new site.exp file...'
-	@echo '## these variables are automatically generated by make ##' >site.tmp
-	@echo '# Do not edit here.  If you wish to override these values' >>site.tmp
-	@echo '# edit the last section' >>site.tmp
-	@echo 'set srcdir $(srcdir)' >>site.tmp
-	@echo "set objdir `pwd`" >>site.tmp
-	@echo 'set build_alias "$(build_alias)"' >>site.tmp
-	@echo 'set build_triplet $(build_triplet)' >>site.tmp
-	@echo 'set host_alias "$(host_alias)"' >>site.tmp
-	@echo 'set host_triplet $(host_triplet)' >>site.tmp
-	@echo 'set target_alias "$(target_alias)"' >>site.tmp
-	@echo 'set target_triplet $(target_triplet)' >>site.tmp
-	@echo '## All variables above are generated by configure. Do Not Edit ##' >>site.tmp
-	@test ! -f site.exp || \
-	  sed '1,/^## All variables above are.*##/ d' site.exp >> site.tmp
-	@-rm -f site.bak
-	@test ! -f site.exp || mv site.exp site.bak
-	@mv site.tmp site.exp
 
 distclean-DEJAGNU:
 	-rm -f site.exp site.bak
@@ -408,6 +392,33 @@ uninstall-am:
 	uninstall uninstall-am
 
 
+# We need more things in site.exp, but automake completely controls the
+# creation of that file; there's no way to append to it without messing up
+# the dependancy chains.  So we overrule automake.  This rule is exactly
+# what it would have generated, plus our own additions.
+site.exp: Makefile
+	@echo 'Making a new site.exp file...'
+	@echo '## these variables are automatically generated by make ##' >site.tmp
+	@echo '# Do not edit here.  If you wish to override these values' >>site.tmp
+	@echo '# edit the last section' >>site.tmp
+	@echo 'set srcdir $(srcdir)' >>site.tmp
+	@echo "set objdir `pwd`" >>site.tmp
+	@echo 'set build_alias "$(build_alias)"' >>site.tmp
+	@echo 'set build_triplet $(build_triplet)' >>site.tmp
+	@echo 'set host_alias "$(host_alias)"' >>site.tmp
+	@echo 'set host_triplet $(host_triplet)' >>site.tmp
+	@echo 'set target_alias "$(target_alias)"' >>site.tmp
+	@echo 'set target_triplet $(target_triplet)' >>site.tmp
+	@echo 'set offload_targets "$(offload_targets)"' >>site.tmp
+	@echo 'set offload_additional_options "$(offload_additional_options)"' >>site.tmp
+	@echo 'set offload_additional_lib_paths "$(offload_additional_lib_paths)"' >>site.tmp
+	@echo '## All variables above are generated by configure. Do Not Edit ##' >>site.tmp
+	@test ! -f site.exp || \
+	  sed '1,/^## All variables above are.*##/ d' site.exp >> site.tmp
+	@-rm -f site.bak
+	@test ! -f site.exp || mv site.exp site.bak
+	@mv site.tmp site.exp
+
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
diff --git a/libgomp/testsuite/lib/libgomp.exp b/libgomp/testsuite/lib/libgomp.exp
index 071e22f..cea4520 100644
--- a/libgomp/testsuite/lib/libgomp.exp
+++ b/libgomp/testsuite/lib/libgomp.exp
@@ -62,6 +62,9 @@ proc libgomp_init { args } {
     global TESTING_IN_BUILD_TREE
     global target_triplet
     global always_ld_library_path
+    global offload_targets
+    global offload_additional_options
+    global offload_additional_lib_paths
 
     set blddir [lookfor_file [get_multilibs] libgomp]
 
@@ -107,6 +110,20 @@ proc libgomp_init { args } {
     # Compute what needs to be put into LD_LIBRARY_PATH
     set always_ld_library_path ".:${blddir}/.libs"
 
+    # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
+    # non-fallback testing for Intel MIC targets
+    if { [string match "*-intelmic-*" $offload_targets]
+	|| [string match "*-intelmicemul-*" $offload_targets] } {
+	append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
+	append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
+	# libstdc++ is required by liboffloadmic
+	append always_ld_library_path ":${blddir}/../libstdc++-v3/src/.libs"
+    }
+
+    if { $offload_additional_lib_paths != ""} {
+	append always_ld_library_path "${offload_additional_lib_paths}"
+    }
+
     # Compute what needs to be added to the existing LD_LIBRARY_PATH.
     if {$gccdir != ""} {
 	# Add AIX pthread directory first.
@@ -169,6 +186,10 @@ proc libgomp_init { args } {
 
     # Disable color diagnostics
     lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
+
+    # Required to support non-fallback testing of '#pragma omp target'.
+    # Help GCC to find target mkoffload.
+    lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
 }
 
 #
-- 
1.7.1

^ permalink raw reply	[flat|nested] 111+ messages in thread

* [gomp4] Mark fopenacc as LTO option
@ 2014-11-03 17:36       ` Tom de Vries
  2015-01-23 15:44         ` [committed][PR64707] Make fopenmp an " Tom de Vries
  0 siblings, 1 reply; 111+ messages in thread
From: Tom de Vries @ 2014-11-03 17:36 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 274 bytes --]

Thomas,

This patch marks fopenacc as LTO option.

This allows fopenacc to be passed to lto, which means the openacc builtins are 
recognized when reading in the LTO stream. This fixes a number of testcases in 
the libgomp testsuite.

ok for gomp-4_0-branch?

Thanks,
- Tom

[-- Attachment #2: 0001-Mark-fopenacc-as-LTO-option.patch --]
[-- Type: text/x-patch, Size: 811 bytes --]

2014-11-03  Tom de Vries  <tom@codesourcery.com>

	* c.opt (fopenacc): Mark as LTO option.

	* lang.opt (fopenacc): Mark as LTO option.

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 09951c9..fd5a615 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1193,7 +1193,7 @@ ObjC ObjC++ Var(flag_objc1_only)
 Conform to the Objective-C 1.0 language as implemented in GCC 4.0
 
 fopenacc
-C ObjC C++ ObjC++ Var(flag_openacc)
+C ObjC C++ ObjC++ LTO Var(flag_openacc)
 Enable OpenACC
 
 fopenmp
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index bbea334..48b47af 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -530,7 +530,7 @@ Fortran
 Set default accessibility of module entities to PRIVATE.
 
 fopenacc
-Fortran
+Fortran LTO
 ; Documented in C
 
 fopenmp
-- 
1.9.1


^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-10-30 12:45 ` [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing Ilya Verbin
@ 2014-11-06 17:55   ` Jakub Jelinek
  2014-11-10 14:51     ` Ilya Verbin
  2014-12-18 15:56   ` Thomas Schwinge
  2016-03-13 19:10   ` Thomas Schwinge
  2 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2014-11-06 17:55 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Thu, Oct 30, 2014 at 02:40:01PM +0300, Ilya Verbin wrote:
> 2014-10-30  Andrey Turetskiy  <andrey.turetskiy@intel.com>
> 	    Ilya Verbin  <ilya.verbin@intel.com>
> 
> libgomp/
> 	* Makefile.in: Regenerate.
> 	* configure: Regenerate.
> 	* configure.ac: Set up offload_additional_options,
> 	offload_additional_lib_paths and offload_targets.
> 	* testsuite/Makefile.am: Overrule site.exp.
> 	* testsuite/Makefile.in: Regenerate.
> 	* testsuite/lib/libgomp.exp (libgomp_init): Append
> 	offload_additional_lib_paths to LD_LIBRARY_PATH.  Append
> 	offload_additional_options to ALWAYS_CFLAGS.  Append liboffloadmic
> 	build directory to LD_LIBRARY_PATH for intelmic offload targets.

Looks mostly good, but:

> --- a/libgomp/testsuite/Makefile.am
> +++ b/libgomp/testsuite/Makefile.am
> @@ -11,3 +11,30 @@ EXPECT = $(shell if test -f $(top_builddir)/../expect/expect; then \
>  _RUNTEST = $(shell if test -f $(top_srcdir)/../dejagnu/runtest; then \
>  	     echo $(top_srcdir)/../dejagnu/runtest; else echo runtest; fi)
>  RUNTEST = "$(_RUNTEST) $(AM_RUNTESTFLAGS)"
> +
> +# We need more things in site.exp, but automake completely controls the
> +# creation of that file; there's no way to append to it without messing up
> +# the dependancy chains.  So we overrule automake.  This rule is exactly
> +# what it would have generated, plus our own additions.
> +site.exp: Makefile
> +	@echo 'Making a new site.exp file...'
> +	@echo '## these variables are automatically generated by make ##' >site.tmp
> +	@echo '# Do not edit here.  If you wish to override these values' >>site.tmp
> +	@echo '# edit the last section' >>site.tmp
> +	@echo 'set srcdir $(srcdir)' >>site.tmp
> +	@echo "set objdir `pwd`" >>site.tmp
> +	@echo 'set build_alias "$(build_alias)"' >>site.tmp
> +	@echo 'set build_triplet $(build_triplet)' >>site.tmp
> +	@echo 'set host_alias "$(host_alias)"' >>site.tmp
> +	@echo 'set host_triplet $(host_triplet)' >>site.tmp
> +	@echo 'set target_alias "$(target_alias)"' >>site.tmp
> +	@echo 'set target_triplet $(target_triplet)' >>site.tmp
> +	@echo 'set offload_targets "$(offload_targets)"' >>site.tmp
> +	@echo 'set offload_additional_options "$(offload_additional_options)"' >>site.tmp
> +	@echo 'set offload_additional_lib_paths "$(offload_additional_lib_paths)"' >>site.tmp
> +	@echo '## All variables above are generated by configure. Do Not Edit ##' >>site.tmp
> +	@test ! -f site.exp || \
> +	  sed '1,/^## All variables above are.*##/ d' site.exp >> site.tmp
> +	@-rm -f site.bak
> +	@test ! -f site.exp || mv site.exp site.bak
> +	@mv site.tmp site.exp

I don't like this, that is too fragile.  If automake is changed, we'll
forget to update this.
If all you are about are the 3 additional variables, can't you instead
put them into env vars and query them in the tcl code using getenv?
Or append them into AM_RUNTESTFLAGS ?
AM_RUNTESTFLAGS += @something@

> @@ -169,6 +186,10 @@ proc libgomp_init { args } {
>  
>      # Disable color diagnostics
>      lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
> +
> +    # Required to support non-fallback testing of '#pragma omp target'.
> +    # Help GCC to find target mkoffload.
> +    lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
>  }

Perhaps add this only if offload_additional_options is non-empty?

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2014-10-22 18:57     ` Ilya Verbin
  2014-11-03 17:36       ` [gomp4] Mark fopenacc as LTO option Tom de Vries
@ 2014-11-06 18:02       ` Jakub Jelinek
  2014-12-22 11:25       ` OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC) Thomas Schwinge
                         ` (3 subsequent siblings)
  5 siblings, 0 replies; 111+ messages in thread
From: Jakub Jelinek @ 2014-11-06 18:02 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Wed, Oct 22, 2014 at 10:57:01PM +0400, Ilya Verbin wrote:
> gcc/
> 	* config.gcc (*-intelmic-* | *-intelmicemul-*): Add i386/t-intelmic to
> 	tmake_file.
> 	(i[34567]86-*-* | x86_64-*-*): Build mkoffload$(exeext) with the
> 	accelerator compiler.
> 	* config/i386/intelmic-mkoffload.c: New file.
> 	* config/i386/t-intelmic: Ditto.

Ok, thanks.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 2/4] Add liboffloadmic
  2014-10-22 19:31     ` Ilya Verbin
  2014-10-29 16:31       ` Ilya Verbin
@ 2014-11-06 18:21       ` Jakub Jelinek
  2014-11-12 10:52         ` Jakub Jelinek
  1 sibling, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2014-11-06 18:21 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Wed, Oct 22, 2014 at 11:21:28PM +0400, Ilya Verbin wrote:
> > Also, do we really want the messy DOS/Windows '\r' in the messages on
> > Unix-ish targets?  Shouldn't that be dependent on what target is the library
> > configured for?
> 
> Fixed.

...

I'm still seeing various unhandled malloc failures, e.g.:

cean_util.cpp:    res =(CeanReadRanges *)malloc(sizeof(CeanReadRanges) +
cean_util.cpp-                                  (ap->rank - rank) * sizeof(CeanReadDim));
cean_util.cpp-    res->current_number = 0;
dv_util.cpp:        res = (CeanReadRanges *)malloc(
dv_util.cpp-            sizeof(CeanReadRanges) + (rank - i) * sizeof(CeanReadDim));
dv_util.cpp-        res -> last_noncont_ind = rank - i - 1;
offload_env.cpp:        env_var_def = (char*)malloc(sz);
offload_env.cpp-        memcpy(env_var_def, env_var_name, sz);
offload_env.cpp-        env_var_def[sz] = 0;
offload_env.cpp-    int new_env_size = new_env.size();
offload_env.cpp:    rez = (char**) malloc((new_env_size + 1) * sizeof(char*));
offload_env.cpp-    std::copy(new_env.begin(), new_env.end(), rez);
offload_env.cpp-    rez[new_env_size] = 0;
offload_host.cpp:    char * ptr = (char*)malloc(size);
offload_host.cpp-    COIRESULT res;
offload_host.cpp-
offload_host.cpp-    memset(ptr, 0, size);
offload_host.cpp:        m_vars = (VarDesc*) malloc(m_vars_total * sizeof(VarDesc));
offload_host.cpp-        memcpy(m_vars, vars, m_vars_total * sizeof(VarDesc));
offload_host.cpp:        m_func_desc = (FunctionDescriptor*) malloc(m_func_desc_size +
offload_host.cpp-                                                   misc_data_size);
offload_host.cpp-        m_func_desc->console_enabled = console_enabled;
offload_host.cpp:    res = (arr_desc *)malloc(sizeof(arr_desc));
offload_host.cpp-    res->base = reinterpret_cast<int64_t>(ptr_val);

would crash if malloc returns NULL.  Similarly for realloc:

offload_host.cpp:    m_vars       = (VarDesc*)realloc(m_vars, m_vars_total * sizeof(VarDesc));
offload_host.cpp-    m_vars_extra =
offload_host.cpp:        (VarExtra*)realloc(m_vars_extra, m_vars_total * sizeof(VarExtra));
...
offload_host.cpp-        ext_elements.val = m_vars[i].count;

Also, I see you heavily use malloc.h, not sure how portable that is,
certainly e.g. gcc checks through configure for its presence.  I suppose
stdlib.h being more portable.  Or, if you want liboffloadmic to be supported
only on i?86-*-linux* / x86_64-*-linux* rather than all i?86/x86_64 targets,
maybe you should say so in configure.tgt.  If you leave it on for all
i?86/x86_64 targets, be prepared to handle issues on Darwin, mingw/cygwin,
BSDs etc.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2014-10-27 14:24             ` Ilya Verbin
@ 2014-11-06 18:25               ` Jakub Jelinek
  2014-11-10 14:32                 ` Ilya Verbin
  0 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2014-11-06 18:25 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Mon, Oct 27, 2014 at 03:15:56PM +0300, Ilya Verbin wrote:

> +  bool use_alloca;
> +  const char *ld_lib_path = getenv (LD_LIBRARY_PATH_ENV);
> +  const char *mic_lib_path = getenv (MIC_LD_LIBRARY_PATH_ENV);
> +  char *mic_lib_path_new;
> +  size_t len;
> +
> +  if (!ld_lib_path)
> +    return;
> +
> +  len = (mic_lib_path ? strlen (mic_lib_path) : 0) + strlen (ld_lib_path) + 2;
> +  use_alloca = len <= 2048;
> +
> +  mic_lib_path_new = (char *) (use_alloca ? alloca (len) : malloc (len));
> +  if (!mic_lib_path_new)
> +    {
> +      fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
> +      exit (1);
> +    }
> +
> +  if (!mic_lib_path)
> +    strcpy (mic_lib_path_new, ld_lib_path);
> +  else
> +    sprintf (mic_lib_path_new, "%s:%s", mic_lib_path, ld_lib_path);

Oh, one more point, if mic_lib_path is NULL, what is the point
to do the alloca/malloc and string copying?  Can't you just
  setenv (MIC_LD_LIBRARY_PATH_ENV, ld_lib_path, 1);
in that case early?

Otherwise LGTM.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2014-11-06 18:25               ` Jakub Jelinek
@ 2014-11-10 14:32                 ` Ilya Verbin
  2014-11-11  7:07                   ` Jakub Jelinek
  2014-12-12  9:42                   ` Thomas Schwinge
  0 siblings, 2 replies; 111+ messages in thread
From: Ilya Verbin @ 2014-11-10 14:32 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On 06 Nov 19:25, Jakub Jelinek wrote:
> Oh, one more point, if mic_lib_path is NULL, what is the point
> to do the alloca/malloc and string copying?  Can't you just
>   setenv (MIC_LD_LIBRARY_PATH_ENV, ld_lib_path, 1);
> in that case early?
> 
> Otherwise LGTM.

Done.

Thanks,
  -- Ilya


---

diff --git a/liboffloadmic/configure.ac b/liboffloadmic/configure.ac
index fb575b3..81fae8f 100644
--- a/liboffloadmic/configure.ac
+++ b/liboffloadmic/configure.ac
@@ -42,6 +42,7 @@ AC_PROG_CC
 AC_PROG_CXX
 AC_CONFIG_FILES([Makefile liboffloadmic_host.spec liboffloadmic_target.spec])
 AM_ENABLE_MULTILIB(, ..)
+AC_CONFIG_SUBDIRS(plugin)
 AC_FUNC_ALLOCA
 AC_CHECK_HEADERS([mm_malloc.h], [], [AC_MSG_ERROR(["Couldn't find mm_malloc.h"])])
 AC_CHECK_FUNCS([__secure_getenv secure_getenv])
diff --git a/liboffloadmic/plugin/Makefile.am b/liboffloadmic/plugin/Makefile.am
new file mode 100644
index 0000000..0baf70d
--- /dev/null
+++ b/liboffloadmic/plugin/Makefile.am
@@ -0,0 +1,123 @@
+# Plugin for offload execution on Intel MIC devices.
+#
+# Copyright (C) 2014 Free Software Foundation, Inc.
+#
+# Contributed by Ilya Verbin <ilya.verbin@intel.com> and
+# Andrey Turetskiy <andrey.turetskiy@intel.com>.
+#
+# This file is part of the GNU OpenMP Library (libgomp).
+#
+# Libgomp is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# Under Section 7 of GPL version 3, you are granted additional
+# permissions described in the GCC Runtime Library Exception, version
+# 3.1, as published by the Free Software Foundation.
+#
+# You should have received a copy of the GNU General Public License and
+# a copy of the GCC Runtime Library Exception along with this program;
+# see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+
+AUTOMAKE_OPTIONS = foreign
+ACLOCAL_AMFLAGS = -I ../.. -I ../../config
+
+# Directories
+build_dir = $(top_builddir)
+source_dir = $(top_srcdir)
+coi_inc_dir = $(top_srcdir)/../include/coi
+myo_inc_dir = $(top_srcdir)/../include/myo
+libgomp_src_dir = $(top_srcdir)/../../libgomp
+libgomp_dir = $(build_dir)/../../libgomp
+liboffload_src_dir = $(top_srcdir)/../runtime
+liboffload_dir = $(top_builddir)/..
+
+# May be used by toolexeclibdir.
+gcc_version := $(shell cat $(top_srcdir)/../../gcc/BASE-VER)
+libsubincludedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/include
+# Search for main_target_image.h in these directories
+target_prefix_dir = $(libdir)/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
+target_build_dir = $(accel_search_dir)/$(accel_target)$(MULTISUBDIR)/liboffloadmic/plugin
+target_install_dir = $(accel_search_dir)/lib/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
+
+if PLUGIN_HOST
+  toolexeclib_LTLIBRARIES = libgomp-plugin-intelmic.la
+  libgomp_plugin_intelmic_la_SOURCES = libgomp-plugin-intelmic.cpp
+  libgomp_plugin_intelmic_la_CPPFLAGS = $(CPPFLAGS) -DLINUX -DCOI_LIBRARY_VERSION=2 -DMYO_SUPPORT -DOFFLOAD_DEBUG=1 -DSEP_SUPPORT -DTIMING_SUPPORT -DHOST_LIBRARY=1 -I$(coi_inc_dir) -I$(myo_inc_dir) -I$(liboffload_src_dir) -I$(libgomp_src_dir) -I$(libgomp_dir) -I$(target_prefix_dir)/include -I$(target_build_dir) -I$(target_install_dir)/include
+  libgomp_plugin_intelmic_la_LDFLAGS = -L$(liboffload_dir)/.libs -loffloadmic_host -version-info 1:0:0
+else # PLUGIN_TARGET
+  plugin_includedir = $(libsubincludedir)
+  plugin_include_HEADERS = main_target_image.h
+  AM_CPPFLAGS = $(CPPFLAGS) -DLINUX -DCOI_LIBRARY_VERSION=2 -DMYO_SUPPORT -DOFFLOAD_DEBUG=1 -DSEP_SUPPORT -DTIMING_SUPPORT -DHOST_LIBRARY=0 -I$(coi_inc_dir) -I$(myo_inc_dir) -I$(liboffload_src_dir) -I$(libgomp_dir)
+  AM_CXXFLAGS = $(CXXFLAGS)
+  AM_LDFLAGS = -L$(liboffload_dir)/.libs -L$(libgomp_dir)/.libs -loffloadmic_target -lcoi_device -lmyo-service -lgomp -rdynamic
+endif
+
+main_target_image.h: offload_target_main
+	@echo -n "const int image_size = " > $@
+	@stat -c '%s' $< >> $@
+	@echo ";" >> $@
+	@echo "struct MainTargetImage {" >> $@
+	@echo "  int64_t size;" >> $@
+	@echo "  char name[sizeof \"offload_target_main\"];" >> $@
+	@echo "  char data[image_size];" >> $@
+	@echo "};" >> $@
+	@echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
+	@echo "  image_size, \"offload_target_main\"," >> $@
+	@cat $< | xxd -include >> $@
+	@echo "};" >> $@
+
+offload_target_main: $(liboffload_dir)/ofldbegin.o offload_target_main.o $(liboffload_dir)/ofldend.o
+	$(CXX) $(AM_LDFLAGS) $^ -o $@
+
+offload_target_main.o: offload_target_main.cpp
+	$(CXX) $(AM_CXXFLAGS) $(AM_CPPFLAGS) -c $< -o $@
+
+# Work around what appears to be a GNU make bug handling MAKEFLAGS
+# values defined in terms of make variables, as is the case for CC and
+# friends when we are called from the top level Makefile.
+AM_MAKEFLAGS = \
+       "AR_FLAGS=$(AR_FLAGS)" \
+       "CC_FOR_BUILD=$(CC_FOR_BUILD)" \
+       "CFLAGS=$(CFLAGS)" \
+       "CXXFLAGS=$(CXXFLAGS)" \
+       "CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
+       "CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
+       "INSTALL=$(INSTALL)" \
+       "INSTALL_DATA=$(INSTALL_DATA)" \
+       "INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
+       "INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
+       "JC1FLAGS=$(JC1FLAGS)" \
+       "LDFLAGS=$(LDFLAGS)" \
+       "LIBCFLAGS=$(LIBCFLAGS)" \
+       "LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
+       "MAKE=$(MAKE)" \
+       "MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
+       "PICFLAG=$(PICFLAG)" \
+       "PICFLAG_FOR_TARGET=$(PICFLAG_FOR_TARGET)" \
+       "SHELL=$(SHELL)" \
+       "RUNTESTFLAGS=$(RUNTESTFLAGS)" \
+       "exec_prefix=$(exec_prefix)" \
+       "infodir=$(infodir)" \
+       "libdir=$(libdir)" \
+       "prefix=$(prefix)" \
+       "includedir=$(includedir)" \
+       "AR=$(AR)" \
+       "AS=$(AS)" \
+       "LD=$(LD)" \
+       "LIBCFLAGS=$(LIBCFLAGS)" \
+       "NM=$(NM)" \
+       "PICFLAG=$(PICFLAG)" \
+       "RANLIB=$(RANLIB)" \
+       "DESTDIR=$(DESTDIR)"
+
+MAKEOVERRIDES =
+
diff --git a/liboffloadmic/plugin/configure.ac b/liboffloadmic/plugin/configure.ac
new file mode 100644
index 0000000..283faad
--- /dev/null
+++ b/liboffloadmic/plugin/configure.ac
@@ -0,0 +1,135 @@
+# Plugin for offload execution on Intel MIC devices.
+#
+# Copyright (C) 2014 Free Software Foundation, Inc.
+#
+# Contributed by Andrey Turetskiy <andrey.turetskiy@intel.com>.
+#
+# This file is part of the GNU OpenMP Library (libgomp).
+#
+# Libgomp is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# Under Section 7 of GPL version 3, you are granted additional
+# permissions described in the GCC Runtime Library Exception, version
+# 3.1, as published by the Free Software Foundation.
+#
+# You should have received a copy of the GNU General Public License and
+# a copy of the GCC Runtime Library Exception along with this program;
+# see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+# Process this file with autoconf to produce a configure script, like so:
+# aclocal -I ../.. -I ../../config && autoconf && automake
+
+AC_PREREQ([2.64])
+AC_INIT([Intel MIC Offload Plugin], [1.0], ,[libgomp-plugin-intelmic])
+
+AC_CONFIG_AUX_DIR(../..)
+
+AC_CANONICAL_SYSTEM
+target_alias=${target_alias-$host_alias}
+AC_SUBST(target_alias)
+
+AM_INIT_AUTOMAKE([1.9.0 foreign no-dist])
+
+AM_MAINTAINER_MODE
+
+AC_PROG_CC
+AC_PROG_CXX
+AC_CONFIG_FILES([Makefile])
+AM_ENABLE_MULTILIB(, ../..)
+
+if test "${multilib}" = "yes"; then
+  multilib_arg="--enable-multilib"
+else
+  multilib_arg=
+fi
+
+# Make sure liboffloadmic is enabled
+case "$enable_liboffloadmic" in
+  host | target)
+    ;;
+  *)
+    AC_MSG_ERROR([Liboffloadmic is disabled]) ;;
+esac
+AM_CONDITIONAL(PLUGIN_HOST, [test x"$enable_liboffloadmic" = xhost])
+
+# Get accel target and path to build or install tree of accel compiler
+accel_search_dir=
+accel_target=
+if test x"$enable_liboffloadmic" = xhost; then
+  for accel in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
+    accel_name=`echo $accel | sed 's/=.*//'`
+    accel_dir=`echo $accel | grep '=' | sed 's/.*=//'`
+    case "$accel_name" in
+      *-intelmic-* | *-intelmicemul-*)
+	accel_target=$accel_name
+	accel_search_dir=$accel_dir
+	;;
+    esac
+  done
+  if test x"$accel_target" = x; then
+    AC_MSG_ERROR([--enable-offload-targets does not contain intelmic target])
+  fi
+fi
+AC_SUBST(accel_search_dir)
+AC_SUBST(accel_target)
+
+AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
+AC_ARG_ENABLE([version-specific-runtime-libs],
+  AC_HELP_STRING([--enable-version-specific-runtime-libs],
+		 [Specify that runtime libraries should be installed in a compiler-specific directory]),
+  [case "$enableval" in
+    yes) enable_version_specific_runtime_libs=yes ;;
+    no)  enable_version_specific_runtime_libs=no ;;
+    *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
+   esac],
+  [enable_version_specific_runtime_libs=no])
+AC_MSG_RESULT($enable_version_specific_runtime_libs)
+
+
+# Calculate toolexeclibdir.
+# Also toolexecdir, though it's only used in toolexeclibdir.
+case ${enable_version_specific_runtime_libs} in
+  yes)
+    # Need the gcc compiler version to know where to install libraries
+    # and header files if --enable-version-specific-runtime-libs option
+    # is selected.
+    toolexecdir='$(libdir)/gcc/$(target_alias)'
+    toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
+    ;;
+  no)
+    if test -n "$with_cross_host" &&
+       test x"$with_cross_host" != x"no"; then
+      # Install a library built with a cross compiler in tooldir, not libdir.
+      toolexecdir='$(exec_prefix)/$(target_alias)'
+      toolexeclibdir='$(toolexecdir)/lib'
+    else
+      toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+      toolexeclibdir='$(libdir)'
+    fi
+    multi_os_directory=`$CC -print-multi-os-directory`
+    case $multi_os_directory in
+      .) ;; # Avoid trailing /.
+      *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
+    esac
+    ;;
+esac
+
+AC_LIBTOOL_DLOPEN
+AM_PROG_LIBTOOL
+# Forbid libtool to hardcode RPATH, because we want to be able to specify
+# library search directory using LD_LIBRARY_PATH
+hardcode_into_libs=no
+AC_SUBST(toolexecdir)
+AC_SUBST(toolexeclibdir)
+
+# Must be last
+AC_OUTPUT
diff --git a/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp
new file mode 100644
index 0000000..28ddbc3
--- /dev/null
+++ b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp
@@ -0,0 +1,447 @@
+/* Plugin for offload execution on Intel MIC devices.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   Contributed by Ilya Verbin <ilya.verbin@intel.com>.
+
+   This file is part of the GNU OpenMP Library (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Host side part of a libgomp plugin.  */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <utility>
+#include <vector>
+#include <libgomp_target.h>
+#include "compiler_if_host.h"
+#include "main_target_image.h"
+
+#define LD_LIBRARY_PATH_ENV	"LD_LIBRARY_PATH"
+#define MIC_LD_LIBRARY_PATH_ENV	"MIC_LD_LIBRARY_PATH"
+
+#ifdef DEBUG
+#define TRACE(...)					    \
+{							    \
+fprintf (stderr, "HOST:\t%s:%s ", __FILE__, __FUNCTION__);  \
+fprintf (stderr, __VA_ARGS__);				    \
+fprintf (stderr, "\n");					    \
+}
+#else
+#define TRACE { }
+#endif
+
+
+static VarDesc vd_host2tgt = {
+  { 1, 1 },		      /* dst, src			      */
+  { 1, 0 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+static VarDesc vd_tgt2host = {
+  { 1, 1 },		      /* dst, src			      */
+  { 0, 1 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+
+/* Total number of shared libraries with offloading to Intel MIC.  */
+static int num_libraries;
+
+/* Pointers to the descriptors, containing pointers to host-side tables and to
+   target images.  */
+static std::vector< std::pair<void *, void *> > lib_descrs;
+
+/* Thread-safe registration of the main image.  */
+static pthread_once_t main_image_is_registered = PTHREAD_ONCE_INIT;
+
+
+/* Add path specified in LD_LIBRARY_PATH to MIC_LD_LIBRARY_PATH, which is
+   required by liboffloadmic.  */
+__attribute__((constructor))
+static void
+set_mic_lib_path (void)
+{
+  const char *ld_lib_path = getenv (LD_LIBRARY_PATH_ENV);
+  const char *mic_lib_path = getenv (MIC_LD_LIBRARY_PATH_ENV);
+
+  if (!ld_lib_path)
+    return;
+
+  if (!mic_lib_path)
+    setenv (MIC_LD_LIBRARY_PATH_ENV, ld_lib_path, 1);
+  else
+    {
+      size_t len = strlen (mic_lib_path) + strlen (ld_lib_path) + 2;
+      bool use_alloca = len <= 2048;
+      char *mic_lib_path_new = (char *) (use_alloca ? alloca (len)
+						    : malloc (len));
+      if (!mic_lib_path_new)
+	{
+	  fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
+	  exit (1);
+	}
+
+      sprintf (mic_lib_path_new, "%s:%s", mic_lib_path, ld_lib_path);
+      setenv (MIC_LD_LIBRARY_PATH_ENV, mic_lib_path_new, 1);
+
+      if (!use_alloca)
+	free (mic_lib_path_new);
+    }
+}
+
+extern "C" enum offload_target_type
+GOMP_OFFLOAD_get_type (void)
+{
+  enum offload_target_type res = OFFLOAD_TARGET_TYPE_INTEL_MIC;
+  TRACE ("(): return %d", res);
+  return res;
+}
+
+extern "C" int
+GOMP_OFFLOAD_get_num_devices (void)
+{
+  int res = _Offload_number_of_devices ();
+  TRACE ("(): return %d", res);
+  return res;
+}
+
+/* This should be called from every shared library with offloading.  */
+extern "C" void
+GOMP_OFFLOAD_register_image (void *host_table, void *target_image)
+{
+  TRACE ("(host_table = %p, target_image = %p)", host_table, target_image);
+  lib_descrs.push_back (std::make_pair (host_table, target_image));
+  num_libraries++;
+}
+
+static void
+offload (const char *file, uint64_t line, int device, const char *name,
+	 int num_vars, VarDesc *vars, VarDesc2 *vars2)
+{
+  OFFLOAD ofld = __offload_target_acquire1 (&device, file, line);
+  if (ofld)
+    __offload_offload1 (ofld, name, 0, num_vars, vars, vars2, 0, NULL, NULL);
+  else
+    {
+      fprintf (stderr, "%s:%d: Offload target acquire failed\n", file, line);
+      exit (1);
+    }
+}
+
+static void
+register_main_image ()
+{
+  __offload_register_image (&main_target_image);
+}
+
+/* Load offload_target_main on target.  */
+extern "C" void
+GOMP_OFFLOAD_init_device (int device)
+{
+  TRACE ("");
+  pthread_once (&main_image_is_registered, register_main_image);
+  offload (__FILE__, __LINE__, device, "__offload_target_init_proc", 0,
+	   NULL, NULL);
+}
+
+static void
+get_target_table (int device, int &num_funcs, int &num_vars, void **&table)
+{
+  VarDesc vd1[2] = { vd_tgt2host, vd_tgt2host };
+  vd1[0].ptr = &num_funcs;
+  vd1[0].size = sizeof (num_funcs);
+  vd1[1].ptr = &num_vars;
+  vd1[1].size = sizeof (num_vars);
+  VarDesc2 vd1g[2] = { { "num_funcs", 0 }, { "num_vars", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_table_p1", 2,
+	   vd1, vd1g);
+
+  int table_size = num_funcs + 2 * num_vars;
+  if (table_size > 0)
+    {
+      table = new void * [table_size];
+
+      VarDesc vd2;
+      vd2 = vd_tgt2host;
+      vd2.ptr = table;
+      vd2.size = table_size * sizeof (void *);
+      VarDesc2 vd2g = { "table", 0 };
+
+      offload (__FILE__, __LINE__, device, "__offload_target_table_p2", 1,
+	       &vd2, &vd2g);
+    }
+}
+
+static void
+load_lib_and_get_table (int device, int lib_num, mapping_table *&table,
+			int &table_size)
+{
+  struct TargetImage {
+    int64_t size;
+    /* 10 characters is enough for max int value.  */
+    char name[sizeof ("lib0000000000.so")];
+    char data[];
+  } __attribute__ ((packed));
+
+  void ***host_table_descr = (void ***) lib_descrs[lib_num].first;
+  void **host_func_start = host_table_descr[0];
+  void **host_func_end   = host_table_descr[1];
+  void **host_var_start  = host_table_descr[2];
+  void **host_var_end    = host_table_descr[3];
+
+  void **target_image_descr = (void **) lib_descrs[lib_num].second;
+  void *image_start = target_image_descr[0];
+  void *image_end   = target_image_descr[1];
+
+  TRACE ("() host_table_descr { %p, %p, %p, %p }", host_func_start,
+	 host_func_end, host_var_start, host_var_end);
+  TRACE ("() target_image_descr { %p, %p }", image_start, image_end);
+
+  int64_t image_size = (uintptr_t) image_end - (uintptr_t) image_start;
+  TargetImage *image
+    = (TargetImage *) malloc (sizeof (int64_t) + sizeof ("lib0000000000.so")
+			      + image_size);
+  if (!image)
+    {
+      fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
+      exit (1);
+    }
+
+  image->size = image_size;
+  sprintf (image->name, "lib%010d.so", lib_num);
+  memcpy (image->data, image_start, image->size);
+
+  TRACE ("() __offload_register_image %s { %p, %d }",
+	 image->name, image_start, image->size);
+  __offload_register_image (image);
+
+  int tgt_num_funcs = 0;
+  int tgt_num_vars = 0;
+  void **tgt_table = NULL;
+  get_target_table (device, tgt_num_funcs, tgt_num_vars, tgt_table);
+  free (image);
+
+  /* The func table contains only addresses, the var table contains addresses
+     and corresponding sizes.  */
+  int host_num_funcs = host_func_end - host_func_start;
+  int host_num_vars  = (host_var_end - host_var_start) / 2;
+  TRACE ("() host_num_funcs = %d, tgt_num_funcs = %d",
+	 host_num_funcs, tgt_num_funcs);
+  TRACE ("() host_num_vars = %d, tgt_num_vars = %d",
+	 host_num_vars, tgt_num_vars);
+  if (host_num_funcs != tgt_num_funcs)
+    {
+      fprintf (stderr, "%s: Can't map target functions\n", __FILE__);
+      exit (1);
+    }
+  if (host_num_vars != tgt_num_vars)
+    {
+      fprintf (stderr, "%s: Can't map target variables\n", __FILE__);
+      exit (1);
+    }
+
+  table = (mapping_table *) realloc (table, (table_size + host_num_funcs
+					     + host_num_vars)
+					    * sizeof (mapping_table));
+  if (table == NULL)
+    {
+      fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
+      exit (1);
+    }
+
+  for (int i = 0; i < host_num_funcs; i++)
+    {
+      mapping_table t;
+      t.host_start = (uintptr_t) host_func_start[i];
+      t.host_end = t.host_start + 1;
+      t.tgt_start = (uintptr_t) tgt_table[i];
+      t.tgt_end = t.tgt_start + 1;
+
+      TRACE ("() lib %d, func %d:\t0x%llx -- 0x%llx",
+	     lib_num, i, t.host_start, t.tgt_start);
+
+      table[table_size++] = t;
+    }
+
+  for (int i = 0; i < host_num_vars * 2; i += 2)
+    {
+      mapping_table t;
+      t.host_start = (uintptr_t) host_var_start[i];
+      t.host_end = t.host_start + (uintptr_t) host_var_start[i+1];
+      t.tgt_start = (uintptr_t) tgt_table[tgt_num_funcs+i];
+      t.tgt_end = t.tgt_start + (uintptr_t) tgt_table[tgt_num_funcs+i+1];
+
+      TRACE ("() lib %d, var %d:\t0x%llx (%d) -- 0x%llx (%d)", lib_num, i/2,
+	     t.host_start, t.host_end - t.host_start,
+	     t.tgt_start, t.tgt_end - t.tgt_start);
+
+      table[table_size++] = t;
+    }
+
+  delete [] tgt_table;
+}
+
+extern "C" int
+GOMP_OFFLOAD_get_table (int device, void *result)
+{
+  TRACE ("(num_libraries = %d)", num_libraries);
+
+  mapping_table *table = NULL;
+  int table_size = 0;
+
+  for (int i = 0; i < num_libraries; i++)
+    load_lib_and_get_table (device, i, table, table_size);
+
+  *(void **) result = table;
+  return table_size;
+}
+
+extern "C" void *
+GOMP_OFFLOAD_alloc (int device, size_t size)
+{
+  TRACE ("(size = %d)", size);
+
+  void *tgt_ptr;
+  VarDesc vd1[2] = { vd_host2tgt, vd_tgt2host };
+  vd1[0].ptr = &size;
+  vd1[0].size = sizeof (size);
+  vd1[1].ptr = &tgt_ptr;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd1g[2] = { { "size", 0 }, { "tgt_ptr", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_alloc", 2, vd1, vd1g);
+
+  return tgt_ptr;
+}
+
+extern "C" void
+GOMP_OFFLOAD_free (int device, void *tgt_ptr)
+{
+  TRACE ("(tgt_ptr = %p)", tgt_ptr);
+
+  VarDesc vd1 = vd_host2tgt;
+  vd1.ptr = &tgt_ptr;
+  vd1.size = sizeof (void *);
+  VarDesc2 vd1g = { "tgt_ptr", 0 };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_free", 1, &vd1, &vd1g);
+}
+
+extern "C" void *
+GOMP_OFFLOAD_host2dev (int device, void *tgt_ptr, const void *host_ptr,
+		       size_t size)
+{
+  TRACE ("(tgt_ptr = %p, host_ptr = %p, size = %d)", tgt_ptr, host_ptr, size);
+  if (!size)
+    return tgt_ptr;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &tgt_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &size;
+  vd1[1].size = sizeof (size);
+  VarDesc2 vd1g[2] = { { "tgt_ptr", 0 }, { "size", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p1", 2,
+	   vd1, vd1g);
+
+  VarDesc vd2 = vd_host2tgt;
+  vd2.ptr = (void *) host_ptr;
+  vd2.size = size;
+  VarDesc2 vd2g = { "var", 0 };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p2", 1,
+	   &vd2, &vd2g);
+
+  return tgt_ptr;
+}
+
+extern "C" void *
+GOMP_OFFLOAD_dev2host (int device, void *host_ptr, const void *tgt_ptr,
+		       size_t size)
+{
+  TRACE ("(host_ptr = %p, tgt_ptr = %p, size = %d)", host_ptr, tgt_ptr, size);
+  if (!size)
+    return host_ptr;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &tgt_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &size;
+  vd1[1].size = sizeof (size);
+  VarDesc2 vd1g[2] = { { "tgt_ptr", 0 }, { "size", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p1", 2,
+	   vd1, vd1g);
+
+  VarDesc vd2 = vd_tgt2host;
+  vd2.ptr = (void *) host_ptr;
+  vd2.size = size;
+  VarDesc2 vd2g = { "var", 0 };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p2", 1,
+	   &vd2, &vd2g);
+
+  return host_ptr;
+}
+
+extern "C" void
+GOMP_OFFLOAD_run (int device, void *tgt_fn, void *tgt_vars)
+{
+  TRACE ("(tgt_fn = %p, tgt_vars = %p)", tgt_fn, tgt_vars);
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &tgt_fn;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &tgt_vars;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd1g[2] = { { "tgt_fn", 0 }, { "tgt_vars", 0 } };
+
+  offload (__FILE__, __LINE__, device, "__offload_target_run", 2, vd1, vd1g);
+}
diff --git a/liboffloadmic/plugin/offload_target_main.cpp b/liboffloadmic/plugin/offload_target_main.cpp
new file mode 100644
index 0000000..4a2778e
--- /dev/null
+++ b/liboffloadmic/plugin/offload_target_main.cpp
@@ -0,0 +1,366 @@
+/* Plugin for offload execution on Intel MIC devices.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   Contributed by Ilya Verbin <ilya.verbin@intel.com>.
+
+   This file is part of the GNU OpenMP Library (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Target side part of a libgomp plugin.  */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "compiler_if_target.h"
+
+
+#ifdef DEBUG
+#define TRACE(...)					      \
+{							      \
+fprintf (stderr, "TARGET:\t%s:%s ", __FILE__, __FUNCTION__);  \
+fprintf (stderr, __VA_ARGS__);				      \
+fprintf (stderr, "\n");					      \
+}
+#else
+#define TRACE { }
+#endif
+
+
+static VarDesc vd_host2tgt = {
+  { 1, 1 },		      /* dst, src			      */
+  { 1, 0 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+static VarDesc vd_tgt2host = {
+  { 1, 1 },		      /* dst, src			      */
+  { 0, 1 },		      /* in, out			      */
+  1,			      /* alloc_if			      */
+  1,			      /* free_if			      */
+  4,			      /* align				      */
+  0,			      /* mic_offset			      */
+  { 0, 0, 0, 0, 0, 0, 0, 0 }, /* is_static, is_static_dstn, has_length,
+				 is_stack_buf, sink_addr, alloc_disp,
+				 is_noncont_src, is_noncont_dst	      */
+  0,			      /* offset				      */
+  0,			      /* size				      */
+  1,			      /* count				      */
+  0,			      /* alloc				      */
+  0,			      /* into				      */
+  0			      /* ptr				      */
+};
+
+/* Pointer to the descriptor of the last loaded shared library.  */
+static void *last_loaded_library = NULL;
+
+/* Pointer and size of the variable, used in __offload_target_host2tgt_p[12]
+   and __offload_target_tgt2host_p[12].  */
+static void *last_var_ptr = NULL;
+static int last_var_size = 0;
+
+
+/* Override the corresponding functions from libgomp.  */
+extern "C" int
+omp_is_initial_device (void) __GOMP_NOTHROW
+{
+  return 0;
+}
+
+extern "C" int32_t
+omp_is_initial_device_ (void)
+{
+  return omp_is_initial_device ();
+}
+
+
+/* Dummy function needed for the initialization of target process during the
+   first call to __offload_offload1.  */
+static void
+__offload_target_init_proc (OFFLOAD ofldt)
+{
+  TRACE ("");
+}
+
+/* Collect addresses of the offload functions and of the global variables from
+   the library descriptor and send them to host.
+   Part 1: Send num_funcs and num_vars to host.  */
+static void
+__offload_target_table_p1 (OFFLOAD ofldt)
+{
+  void ***lib_descr = (void ***) last_loaded_library;
+
+  if (lib_descr == NULL)
+    {
+      TRACE ("");
+      fprintf (stderr, "Error! No shared libraries loaded on target.\n");
+      return;
+    }
+
+  void **func_table_begin = lib_descr[0];
+  void **func_table_end   = lib_descr[1];
+  void **var_table_begin  = lib_descr[2];
+  void **var_table_end    = lib_descr[3];
+
+  /* The func table contains only addresses, the var table contains addresses
+     and corresponding sizes.  */
+  int num_funcs = func_table_end - func_table_begin;
+  int num_vars = (var_table_end - var_table_begin) / 2;
+  TRACE ("(num_funcs = %d, num_vars = %d)", num_funcs, num_vars);
+
+  VarDesc vd1[2] = { vd_tgt2host, vd_tgt2host };
+  vd1[0].ptr = &num_funcs;
+  vd1[0].size = sizeof (num_funcs);
+  vd1[1].ptr = &num_vars;
+  vd1[1].size = sizeof (num_vars);
+  VarDesc2 vd2[2] = { { "num_funcs", 0 }, { "num_vars", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  __offload_target_leave (ofldt);
+}
+
+/* Part 2: Send the table with addresses to host.  */
+static void
+__offload_target_table_p2 (OFFLOAD ofldt)
+{
+  void ***lib_descr = (void ***) last_loaded_library;
+  void **func_table_begin = lib_descr[0];
+  void **func_table_end   = lib_descr[1];
+  void **var_table_begin  = lib_descr[2];
+  void **var_table_end    = lib_descr[3];
+
+  int num_funcs = func_table_end - func_table_begin;
+  int num_vars = (var_table_end - var_table_begin) / 2;
+  int table_size = (num_funcs + 2 * num_vars) * sizeof (void *);
+  void **table = (void **) malloc (table_size);
+  TRACE ("(table_size = %d)", table_size);
+
+  VarDesc vd1;
+  vd1 = vd_tgt2host;
+  vd1.ptr = table;
+  vd1.size = table_size;
+  VarDesc2 vd2 = { "table", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+
+  void **p;
+  int i = 0;
+  for (p = func_table_begin; p < func_table_end; p++, i++)
+    table[i] = *p;
+
+  for (p = var_table_begin; p < var_table_end; p++, i++)
+    table[i] = *p;
+
+  __offload_target_leave (ofldt);
+  free (table);
+}
+
+/* Allocate size bytes and send a pointer to the allocated memory to host.  */
+static void
+__offload_target_alloc (OFFLOAD ofldt)
+{
+  size_t size = 0;
+  void *ptr = NULL;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_tgt2host };
+  vd1[0].ptr = &size;
+  vd1[0].size = sizeof (size);
+  vd1[1].ptr = &ptr;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd2[2] = { { "size", 0 }, { "ptr", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  ptr = malloc (size);
+  TRACE ("(size = %d): ptr = %p", size, ptr);
+  __offload_target_leave (ofldt);
+}
+
+/* Free the memory space pointed to by ptr.  */
+static void
+__offload_target_free (OFFLOAD ofldt)
+{
+  void *ptr = 0;
+
+  VarDesc vd1 = vd_host2tgt;
+  vd1.ptr = &ptr;
+  vd1.size = sizeof (void *);
+  VarDesc2 vd2 = { "ptr", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+  TRACE ("(ptr = %p)", ptr);
+  free (ptr);
+  __offload_target_leave (ofldt);
+}
+
+/* Receive var_size bytes from host and store to var_ptr.
+   Part 1: Receive var_ptr and var_size from host.  */
+static void
+__offload_target_host2tgt_p1 (OFFLOAD ofldt)
+{
+  void *var_ptr = NULL;
+  size_t var_size = 0;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &var_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &var_size;
+  vd1[1].size = sizeof (var_size);
+  VarDesc2 vd2[2] = { { "var_ptr", 0 }, { "var_size", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  TRACE ("(var_ptr = %p, var_size = %d)", var_ptr, var_size);
+  last_var_ptr = var_ptr;
+  last_var_size = var_size;
+  __offload_target_leave (ofldt);
+}
+
+/* Part 2: Receive the data from host.  */
+static void
+__offload_target_host2tgt_p2 (OFFLOAD ofldt)
+{
+  TRACE ("(last_var_ptr = %p, last_var_size = %d)",
+	 last_var_ptr, last_var_size);
+
+  VarDesc vd1 = vd_host2tgt;
+  vd1.ptr = last_var_ptr;
+  vd1.size = last_var_size;
+  VarDesc2 vd2 = { "var", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+  __offload_target_leave (ofldt);
+}
+
+/* Send var_size bytes from var_ptr to host.
+   Part 1: Receive var_ptr and var_size from host.  */
+static void
+__offload_target_tgt2host_p1 (OFFLOAD ofldt)
+{
+  void *var_ptr = NULL;
+  size_t var_size = 0;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &var_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &var_size;
+  vd1[1].size = sizeof (var_size);
+  VarDesc2 vd2[2] = { { "var_ptr", 0 }, { "var_size", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  TRACE ("(var_ptr = %p, var_size = %d)", var_ptr, var_size);
+  last_var_ptr = var_ptr;
+  last_var_size = var_size;
+  __offload_target_leave (ofldt);
+}
+
+/* Part 2: Send the data to host.  */
+static void
+__offload_target_tgt2host_p2 (OFFLOAD ofldt)
+{
+  TRACE ("(last_var_ptr = %p, last_var_size = %d)",
+	 last_var_ptr, last_var_size);
+
+  VarDesc vd1 = vd_tgt2host;
+  vd1.ptr = last_var_ptr;
+  vd1.size = last_var_size;
+  VarDesc2 vd2 = { "var", 0 };
+
+  __offload_target_enter (ofldt, 1, &vd1, &vd2);
+  __offload_target_leave (ofldt);
+}
+
+/* Call offload function by the address fn_ptr and pass vars_ptr to it.  */
+static void
+__offload_target_run (OFFLOAD ofldt)
+{
+  void *fn_ptr;
+  void *vars_ptr;
+
+  VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
+  vd1[0].ptr = &fn_ptr;
+  vd1[0].size = sizeof (void *);
+  vd1[1].ptr = &vars_ptr;
+  vd1[1].size = sizeof (void *);
+  VarDesc2 vd2[2] = { { "fn_ptr", 0 }, { "vars_ptr", 0 } };
+
+  __offload_target_enter (ofldt, 2, vd1, vd2);
+  TRACE ("(fn_ptr = %p, vars_ptr = %p)", fn_ptr, vars_ptr);
+  void (*fn)(void *) = (void (*)(void *)) fn_ptr;
+  fn (vars_ptr);
+  __offload_target_leave (ofldt);
+}
+
+
+/* This should be called from every library with offloading.  */
+extern "C" void
+target_register_lib (const void *target_table)
+{
+  TRACE ("(target_table = %p { %p, %p, %p, %p })", target_table,
+	 ((void **) target_table)[0], ((void **) target_table)[1],
+	 ((void **) target_table)[2], ((void **) target_table)[3]);
+
+  last_loaded_library = (void *) target_table;
+}
+
+/* Use __offload_target_main from liboffload.  */
+int
+main (int argc, char **argv)
+{
+  __offload_target_main ();
+  return 0;
+}
+
+
+/* Register offload_target_main's functions in the liboffload.  */
+
+struct Entry {
+  const char *name;
+  void *func;
+};
+
+#define REGISTER(f)				      \
+extern "C" const Entry __offload_target_##f##_$entry  \
+__attribute__ ((section(".OffloadEntryTable."))) = {  \
+  "__offload_target_"#f,			      \
+  (void *) __offload_target_##f			      \
+}
+REGISTER (init_proc);
+REGISTER (table_p1);
+REGISTER (table_p2);
+REGISTER (alloc);
+REGISTER (free);
+REGISTER (host2tgt_p1);
+REGISTER (host2tgt_p2);
+REGISTER (tgt2host_p1);
+REGISTER (tgt2host_p2);
+REGISTER (run);
+#undef REGISTER
-- 
1.7.1

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-11-06 17:55   ` Jakub Jelinek
@ 2014-11-10 14:51     ` Ilya Verbin
  2014-11-11  7:10       ` Jakub Jelinek
                         ` (2 more replies)
  0 siblings, 3 replies; 111+ messages in thread
From: Ilya Verbin @ 2014-11-10 14:51 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On 06 Nov 18:55, Jakub Jelinek wrote:
> Looks mostly good, but:
> 
> > +# We need more things in site.exp, but automake completely controls the
> > +# creation of that file; there's no way to append to it without messing up
> > +# the dependancy chains.  So we overrule automake.  This rule is exactly
> > +# what it would have generated, plus our own additions.
> > +site.exp: Makefile
> > +	@echo 'Making a new site.exp file...'
> > +	@echo '## these variables are automatically generated by make ##' >site.tmp
> > +	@echo '# Do not edit here.  If you wish to override these values' >>site.tmp
> > +	@echo '# edit the last section' >>site.tmp
> > +	@echo 'set srcdir $(srcdir)' >>site.tmp
> > +	@echo "set objdir `pwd`" >>site.tmp
> > +	@echo 'set build_alias "$(build_alias)"' >>site.tmp
> > +	@echo 'set build_triplet $(build_triplet)' >>site.tmp
> > +	@echo 'set host_alias "$(host_alias)"' >>site.tmp
> > +	@echo 'set host_triplet $(host_triplet)' >>site.tmp
> > +	@echo 'set target_alias "$(target_alias)"' >>site.tmp
> > +	@echo 'set target_triplet $(target_triplet)' >>site.tmp
> > +	@echo 'set offload_targets "$(offload_targets)"' >>site.tmp
> > +	@echo 'set offload_additional_options "$(offload_additional_options)"' >>site.tmp
> > +	@echo 'set offload_additional_lib_paths "$(offload_additional_lib_paths)"' >>site.tmp
> > +	@echo '## All variables above are generated by configure. Do Not Edit ##' >>site.tmp
> > +	@test ! -f site.exp || \
> > +	  sed '1,/^## All variables above are.*##/ d' site.exp >> site.tmp
> > +	@-rm -f site.bak
> > +	@test ! -f site.exp || mv site.exp site.bak
> > +	@mv site.tmp site.exp
> 
> I don't like this, that is too fragile.  If automake is changed, we'll
> forget to update this.
> If all you are about are the 3 additional variables, can't you instead
> put them into env vars and query them in the tcl code using getenv?
> Or append them into AM_RUNTESTFLAGS ?
> AM_RUNTESTFLAGS += @something@

Done, I put them into env vars.

> > +    lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
> >  }
> 
> Perhaps add this only if offload_additional_options is non-empty?

Done.

Thanks,
  -- Ilya


---

diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 5cd666f..8e4774f 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -268,6 +268,9 @@ lt_host_flags = @lt_host_flags@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 multi_basedir = @multi_basedir@
+offload_additional_lib_paths = @offload_additional_lib_paths@
+offload_additional_options = @offload_additional_options@
+offload_targets = @offload_targets@
 oldincludedir = @oldincludedir@
 pdfdir = @pdfdir@
 prefix = @prefix@
diff --git a/libgomp/configure b/libgomp/configure
index 97c9be6..aabf25f 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -616,6 +616,9 @@ OMP_LOCK_SIZE
 USE_FORTRAN_FALSE
 USE_FORTRAN_TRUE
 link_gomp
+offload_additional_lib_paths
+offload_additional_options
+offload_targets
 XLDFLAGS
 XCFLAGS
 config_path
@@ -11094,7 +11097,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11097 "configure"
+#line 11100 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11200,7 +11203,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11203 "configure"
+#line 11206 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -16207,9 +16210,13 @@ else
   multilib_arg=
 fi
 
+# Get accel target and path to install tree of accel compiler
+offload_additional_options=
+offload_additional_lib_paths=
 offload_targets=
 if test x"$enable_offload_targets" != x; then
   for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
+    tgt_dir=`echo $tgt | grep '=' | sed 's/.*=//'`
     tgt=`echo $tgt | sed 's/=.*//'`
     case $tgt in
       *-intelmic-* | *-intelmicemul-*)
@@ -16222,6 +16229,13 @@ if test x"$enable_offload_targets" != x; then
     else
       offload_targets=$offload_targets,$tgt_name
     fi
+    if test x"$tgt_dir" != x; then
+      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
+      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib"
+    else
+      offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
+      offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"
+    fi
   done
 fi
 
@@ -16230,6 +16244,9 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+
+
+
 # Set up the set of libraries that we need to link against for libgomp.
 # Note that the GOMP_SELF_SPEC in gcc.c may force -pthread,
 # which will force linkage against -lpthread (or equivalent for the system).
diff --git a/libgomp/configure.ac b/libgomp/configure.ac
index 3f34ff8..cea6366 100644
--- a/libgomp/configure.ac
+++ b/libgomp/configure.ac
@@ -280,9 +280,13 @@ else
   multilib_arg=
 fi
 
+# Get accel target and path to install tree of accel compiler
+offload_additional_options=
+offload_additional_lib_paths=
 offload_targets=
 if test x"$enable_offload_targets" != x; then
   for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
+    tgt_dir=`echo $tgt | grep '=' | sed 's/.*=//'`
     tgt=`echo $tgt | sed 's/=.*//'`
     case $tgt in
       *-intelmic-* | *-intelmicemul-*)
@@ -295,10 +299,20 @@ if test x"$enable_offload_targets" != x; then
     else
       offload_targets=$offload_targets,$tgt_name
     fi
+    if test x"$tgt_dir" != x; then
+      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
+      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib"
+    else
+      offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
+      offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"
+    fi
   done
 fi
 AC_DEFINE_UNQUOTED(OFFLOAD_TARGETS, "$offload_targets",
   [Define to hold the list of target names suitable for offloading.])
+AC_SUBST(offload_targets)
+AC_SUBST(offload_additional_options)
+AC_SUBST(offload_additional_lib_paths)
 
 # Set up the set of libraries that we need to link against for libgomp.
 # Note that the GOMP_SELF_SPEC in gcc.c may force -pthread,
diff --git a/libgomp/testsuite/Makefile.am b/libgomp/testsuite/Makefile.am
index 561b7e2..9cc103a 100644
--- a/libgomp/testsuite/Makefile.am
+++ b/libgomp/testsuite/Makefile.am
@@ -11,3 +11,8 @@ EXPECT = $(shell if test -f $(top_builddir)/../expect/expect; then \
 _RUNTEST = $(shell if test -f $(top_srcdir)/../dejagnu/runtest; then \
 	     echo $(top_srcdir)/../dejagnu/runtest; else echo runtest; fi)
 RUNTEST = "$(_RUNTEST) $(AM_RUNTESTFLAGS)"
+
+# Used for support non-fallback offloading.
+export OFFLOAD_TARGETS = $(offload_targets)
+export OFFLOAD_ADDITIONAL_OPTIONS = $(offload_additional_options)
+export OFFLOAD_ADDITIONAL_LIB_PATHS = $(offload_additional_lib_paths)
diff --git a/libgomp/testsuite/Makefile.in b/libgomp/testsuite/Makefile.in
index 5273eaa..2f845f0 100644
--- a/libgomp/testsuite/Makefile.in
+++ b/libgomp/testsuite/Makefile.in
@@ -184,6 +184,9 @@ lt_host_flags = @lt_host_flags@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 multi_basedir = @multi_basedir@
+offload_additional_lib_paths = @offload_additional_lib_paths@
+offload_additional_options = @offload_additional_options@
+offload_targets = @offload_targets@
 oldincludedir = @oldincludedir@
 pdfdir = @pdfdir@
 prefix = @prefix@
@@ -408,6 +411,11 @@ uninstall-am:
 	uninstall uninstall-am
 
 
+# Used for support non-fallback offloading.
+export OFFLOAD_TARGETS = $(offload_targets)
+export OFFLOAD_ADDITIONAL_OPTIONS = $(offload_additional_options)
+export OFFLOAD_ADDITIONAL_LIB_PATHS = $(offload_additional_lib_paths)
+
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
diff --git a/libgomp/testsuite/lib/libgomp.exp b/libgomp/testsuite/lib/libgomp.exp
index 071e22f..a154684 100644
--- a/libgomp/testsuite/lib/libgomp.exp
+++ b/libgomp/testsuite/lib/libgomp.exp
@@ -107,6 +107,25 @@ proc libgomp_init { args } {
     # Compute what needs to be put into LD_LIBRARY_PATH
     set always_ld_library_path ".:${blddir}/.libs"
 
+    # Get offload-related variables from environment (exported by Makefile)
+    set offload_targets [getenv OFFLOAD_TARGETS]
+    set offload_additional_options [getenv OFFLOAD_ADDITIONAL_OPTIONS]
+    set offload_additional_lib_paths [getenv OFFLOAD_ADDITIONAL_LIB_PATHS]
+
+    # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
+    # non-fallback testing for Intel MIC targets
+    if { [string match "*-intelmic-*" $offload_targets]
+	|| [string match "*-intelmicemul-*" $offload_targets] } {
+	append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
+	append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
+	# libstdc++ is required by liboffloadmic
+	append always_ld_library_path ":${blddir}/../libstdc++-v3/src/.libs"
+    }
+
+    if { $offload_additional_lib_paths != "" } {
+	append always_ld_library_path "${offload_additional_lib_paths}"
+    }
+
     # Compute what needs to be added to the existing LD_LIBRARY_PATH.
     if {$gccdir != ""} {
 	# Add AIX pthread directory first.
@@ -169,6 +188,12 @@ proc libgomp_init { args } {
 
     # Disable color diagnostics
     lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
+
+    # Used for support non-fallback offloading.
+    # Help GCC to find target mkoffload.
+    if { $offload_additional_options != "" } {
+	lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
+    }
 }
 
 #
-- 
1.7.1

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2014-11-10 14:32                 ` Ilya Verbin
@ 2014-11-11  7:07                   ` Jakub Jelinek
  2014-12-12  9:42                   ` Thomas Schwinge
  1 sibling, 0 replies; 111+ messages in thread
From: Jakub Jelinek @ 2014-11-11  7:07 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Mon, Nov 10, 2014 at 05:30:38PM +0300, Ilya Verbin wrote:
> On 06 Nov 19:25, Jakub Jelinek wrote:
> > Oh, one more point, if mic_lib_path is NULL, what is the point
> > to do the alloca/malloc and string copying?  Can't you just
> >   setenv (MIC_LD_LIBRARY_PATH_ENV, ld_lib_path, 1);
> > in that case early?
> > 
> > Otherwise LGTM.
> 
> Done.

Ok (with appropriate ChangeLog entry).

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-11-10 14:51     ` Ilya Verbin
@ 2014-11-11  7:10       ` Jakub Jelinek
  2014-11-12  9:18       ` Jakub Jelinek
  2014-12-17 22:53       ` Thomas Schwinge
  2 siblings, 0 replies; 111+ messages in thread
From: Jakub Jelinek @ 2014-11-11  7:10 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Mon, Nov 10, 2014 at 05:34:30PM +0300, Ilya Verbin wrote:
> Done, I put them into env vars.
> 
> > > +    lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
> > >  }
> > 
> > Perhaps add this only if offload_additional_options is non-empty?
> 
> Done.

Ok (with appropriate ChangeLog entry).

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-11-10 14:51     ` Ilya Verbin
  2014-11-11  7:10       ` Jakub Jelinek
@ 2014-11-12  9:18       ` Jakub Jelinek
  2014-12-17 22:53       ` Thomas Schwinge
  2 siblings, 0 replies; 111+ messages in thread
From: Jakub Jelinek @ 2014-11-12  9:18 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Mon, Nov 10, 2014 at 05:34:30PM +0300, Ilya Verbin wrote:
> > I don't like this, that is too fragile.  If automake is changed, we'll
> > forget to update this.
> > If all you are about are the 3 additional variables, can't you instead
> > put them into env vars and query them in the tcl code using getenv?
> > Or append them into AM_RUNTESTFLAGS ?
> > AM_RUNTESTFLAGS += @something@
> 
> Done, I put them into env vars.

Thanks.

> > > +    lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
> > >  }
> > 
> > Perhaps add this only if offload_additional_options is non-empty?
> 
> Done.

Ok for trunk.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 2/4] Add liboffloadmic
  2014-11-06 18:21       ` Jakub Jelinek
@ 2014-11-12 10:52         ` Jakub Jelinek
  2014-11-12 13:29           ` Ilya Verbin
  0 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2014-11-12 10:52 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Thu, Nov 06, 2014 at 07:21:31PM +0100, Jakub Jelinek wrote:
> On Wed, Oct 22, 2014 at 11:21:28PM +0400, Ilya Verbin wrote:
> > > Also, do we really want the messy DOS/Windows '\r' in the messages on
> > > Unix-ish targets?  Shouldn't that be dependent on what target is the library
> > > configured for?
> > 
> > Fixed.
> 
> ...
> 
> I'm still seeing various unhandled malloc failures, e.g.:

Note, I'm ok with liboffloadmic being checked in right now as is and
these things fixed in it soon (within say 14 days from now).

So, the whole series is ok to check in now.  Thanks.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 2/4] Add liboffloadmic
  2014-11-12 10:52         ` Jakub Jelinek
@ 2014-11-12 13:29           ` Ilya Verbin
  0 siblings, 0 replies; 111+ messages in thread
From: Ilya Verbin @ 2014-11-12 13:29 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

On 06 Nov 19:21, Jakub Jelinek wrote:
> I'm still seeing various unhandled malloc failures, e.g.:
> ...
> would crash if malloc returns NULL.  Similarly for realloc:

Fixed in the branch:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=534b201fadf0af05ca509dc3f8e13ef26ee719a2

> Also, I see you heavily use malloc.h, not sure how portable that is,
> certainly e.g. gcc checks through configure for its presence.  I suppose
> stdlib.h being more portable.  Or, if you want liboffloadmic to be supported
> only on i?86-*-linux* / x86_64-*-linux* rather than all i?86/x86_64 targets,
> maybe you should say so in configure.tgt.  If you leave it on for all
> i?86/x86_64 targets, be prepared to handle issues on Darwin, mingw/cygwin,
> BSDs etc.

So far we have tested only i686/x86_64 linux, but probably we will support other
systems in the future.
I restricted $target to x86_64-*-linux* and i?86-*-linux* in configure.tgt.

On 12 Nov 11:40, Jakub Jelinek wrote:
> So, the whole series is ok to check in now.  Thanks.

Great, thank you!
We're going to check in all patches today after additional regtesting.

  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2014-11-10 14:32                 ` Ilya Verbin
  2014-11-11  7:07                   ` Jakub Jelinek
@ 2014-12-12  9:42                   ` Thomas Schwinge
  2015-01-08 14:48                     ` Thomas Schwinge
  1 sibling, 1 reply; 111+ messages in thread
From: Thomas Schwinge @ 2014-12-12  9:42 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: text/plain, Size: 2742 bytes --]

Hi!

On Mon, 10 Nov 2014 17:30:38 +0300, Ilya Verbin <iverbin@gmail.com> wrote:
> --- /dev/null
> +++ b/liboffloadmic/plugin/Makefile.am
> @@ -0,0 +1,123 @@
> +# Plugin for offload execution on Intel MIC devices.

> +libgomp_src_dir = $(top_srcdir)/../../libgomp
> +libgomp_dir = $(build_dir)/../../libgomp

Hmm, I'm not too happy about external (to libgomp) files using (for
example, #include) stuff from libgomp, for the reason given in
<http://news.gmane.org/find-root.php?message_id=%3C87ioishf5z.fsf%40kepler.schwinge.homeip.net%3E>:
it can then easily happen that any such files depend on, for example,
Autoconf definitions which are provided in only one of the instances.
That said, libgomp_target.h as well as omp.h currently are self-contained
(the latter file after having been created from omp.h.in by libgomp's
configure script), so this currently is not an actual problem.


> +  AM_LDFLAGS = -L$(liboffload_dir)/.libs -L$(libgomp_dir)/.libs -loffloadmic_target -lcoi_device -lmyo-service -lgomp -rdynamic

Given that this plugin wishes to link against libgomp, don't we have to
make sure that libgomp has actually been built before that is attempted,
and the following (untested) patch would be required?

diff --git Makefile.def Makefile.def
index 7c8761a..f0a3a91 100644
--- Makefile.def
+++ Makefile.def
@@ -550,7 +550,7 @@ dependencies = { module=configure-target-libvtv; on=all-target-libstdc++-v3; };
 // generated by the libgomp configure.  Unfortunately, due to the use of
 //  recursive make, we can't be that specific.
 dependencies = { module=all-target-libstdc++-v3; on=configure-target-libgomp; };
-dependencies = { module=all-target-liboffloadmic; on=configure-target-libgomp; };
+dependencies = { module=all-target-liboffloadmic; on=all-target-libgomp; };
 
 dependencies = { module=install-target-libgo; on=install-target-libatomic; };
 dependencies = { module=install-target-libgfortran; on=install-target-libquadmath; };
diff --git Makefile.in Makefile.in
index ba5ae4c..8c060b9 100644
--- Makefile.in
+++ Makefile.in
@@ -48884,7 +48884,7 @@ all-stage3-target-libstdc++-v3: maybe-configure-stage3-target-libgomp
 all-stage4-target-libstdc++-v3: maybe-configure-stage4-target-libgomp
 all-stageprofile-target-libstdc++-v3: maybe-configure-stageprofile-target-libgomp
 all-stagefeedback-target-libstdc++-v3: maybe-configure-stagefeedback-target-libgomp
-all-target-liboffloadmic: maybe-configure-target-libgomp
+all-target-liboffloadmic: maybe-all-target-libgomp
 install-target-libgo: maybe-install-target-libatomic
 install-target-libgfortran: maybe-install-target-libquadmath
 install-target-libgfortran: maybe-install-target-libgcc


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 2/4] Add liboffloadmic
  2014-10-21 17:24 ` [PATCH 2/4] Add liboffloadmic Ilya Verbin
  2014-10-22  8:55   ` Jakub Jelinek
@ 2014-12-12 10:46   ` Thomas Schwinge
  2015-02-04 17:45     ` Ilya Verbin
  2015-07-09 10:00   ` Thomas Schwinge
  2 siblings, 1 reply; 111+ messages in thread
From: Thomas Schwinge @ 2014-12-12 10:46 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek, gcc-patches; +Cc: Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: text/plain, Size: 654 bytes --]

Hi!

On Tue, 21 Oct 2014 21:20:34 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> This patch contains liboffloadmic library.

> liboffloadmic/
> 	Initial commit.  Imported from upstream:
> 	https://www.openmprtl.org/sites/default/files/liboffload_oss.tgz
> 	* Makefile.am: New file.
> 	* Makefile.in: New file, generated by automake.
> 	* aclocal.m4: New file, generated by aclocal.
> 	* configure: New file, generated by autoconf.
> 	* configure.ac: New file.

contrib/gcc_update:files_and_dependencies needs to be updated for those
build machinery files as well as those added in liboffloadmic/plugin/
later on.


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-11-10 14:51     ` Ilya Verbin
  2014-11-11  7:10       ` Jakub Jelinek
  2014-11-12  9:18       ` Jakub Jelinek
@ 2014-12-17 22:53       ` Thomas Schwinge
  2014-12-18 10:46         ` Jakub Jelinek
  2 siblings, 1 reply; 111+ messages in thread
From: Thomas Schwinge @ 2014-12-17 22:53 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: text/plain, Size: 8821 bytes --]

Hi!

On Mon, 10 Nov 2014 17:34:30 +0300, Ilya Verbin <iverbin@gmail.com> wrote:
> On 06 Nov 18:55, Jakub Jelinek wrote:
> > Looks mostly good, but:
> > 
> > > +# We need more things in site.exp, but automake completely controls the
> > > +# creation of that file; there's no way to append to it without messing up
> > > +# the dependancy chains.  So we overrule automake.  This rule is exactly
> > > +# what it would have generated, plus our own additions.
> > > +site.exp: Makefile
> > > +	@echo 'Making a new site.exp file...'
> > > +	@echo '## these variables are automatically generated by make ##' >site.tmp
> > > +	@echo '# Do not edit here.  If you wish to override these values' >>site.tmp
> > > +	@echo '# edit the last section' >>site.tmp
> > > +	@echo 'set srcdir $(srcdir)' >>site.tmp
> > > +[...]
> > > +	@echo 'set target_triplet $(target_triplet)' >>site.tmp
> > > +	@echo 'set offload_targets "$(offload_targets)"' >>site.tmp
> > > +	@echo 'set offload_additional_options "$(offload_additional_options)"' >>site.tmp
> > > +	@echo 'set offload_additional_lib_paths "$(offload_additional_lib_paths)"' >>site.tmp
> > > +	@echo '## All variables above are generated by configure. Do Not Edit ##' >>site.tmp
> > > +	@test ! -f site.exp || \
> > > +	  sed '1,/^## All variables above are.*##/ d' site.exp >> site.tmp
> > > +	@-rm -f site.bak
> > > +	@test ! -f site.exp || mv site.exp site.bak
> > > +	@mv site.tmp site.exp
> > 
> > I don't like this, that is too fragile.  If automake is changed, we'll
> > forget to update this.

(The same problem exists elsewhere in GCC.  But I certainly do agree that
it's ugly.)

> > If all you are about are the 3 additional variables, can't you instead
> > put them into env vars and query them in the tcl code using getenv?
> > Or append them into AM_RUNTESTFLAGS ?
> > AM_RUNTESTFLAGS += @something@
> 
> Done, I put them into env vars.

> --- a/libgomp/testsuite/Makefile.am
> +++ b/libgomp/testsuite/Makefile.am
> @@ -11,3 +11,8 @@ EXPECT = $(shell if test -f $(top_builddir)/../expect/expect; then \
>  _RUNTEST = $(shell if test -f $(top_srcdir)/../dejagnu/runtest; then \
>  	     echo $(top_srcdir)/../dejagnu/runtest; else echo runtest; fi)
>  RUNTEST = "$(_RUNTEST) $(AM_RUNTESTFLAGS)"
> +
> +# Used for support non-fallback offloading.
> +export OFFLOAD_TARGETS = $(offload_targets)
> +export OFFLOAD_ADDITIONAL_OPTIONS = $(offload_additional_options)
> +export OFFLOAD_ADDITIONAL_LIB_PATHS = $(offload_additional_lib_paths)

> --- a/libgomp/testsuite/lib/libgomp.exp
> +++ b/libgomp/testsuite/lib/libgomp.exp
> @@ -107,6 +107,25 @@ proc libgomp_init { args } {
>      # Compute what needs to be put into LD_LIBRARY_PATH
>      set always_ld_library_path ".:${blddir}/.libs"
>  
> +    # Get offload-related variables from environment (exported by Makefile)
> +    set offload_targets [getenv OFFLOAD_TARGETS]
> +    set offload_additional_options [getenv OFFLOAD_ADDITIONAL_OPTIONS]
> +    set offload_additional_lib_paths [getenv OFFLOAD_ADDITIONAL_LIB_PATHS]
> +[...]

I have another suggestion: on gomp-4_0-branch, we had already started
using a libgomp-test-support.exp file for a similar purpose.  I now
changed your code on gomp-4_0-branch in r218845 as follows (though, not
very much tested).  The advantage here is that people who are not using
GCC build-tree testing, but are directly invoking runtest, then don't
have to set various environment variables, but instead just have to copy
this one libgomp-test-support.exp file from the build tree to the testing
tree.  Does this make sense?

commit de01639bf47e29a20959771e587fb6f30c372a45
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed Dec 17 22:45:05 2014 +0000

    libgomp: Route offloading data through the libgomp-test-support.exp file.
    
    	libgomp/
    	* testsuite/Makefile.am: Don't export OFFLOAD_TARGETS,
    	OFFLOAD_ADDITIONAL_OPTIONS, and OFFLOAD_ADDITIONAL_LIB_PATHS...
    	* testsuite/libgomp-test-support.exp.in: ..., and instead set
    	offload_targets, offload_additional_options, and
    	offload_additional_lib_paths here.  Update all users.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@218845 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog.gomp                        | 6 ++++++
 libgomp/testsuite/Makefile.am                 | 5 -----
 libgomp/testsuite/Makefile.in                 | 5 -----
 libgomp/testsuite/lib/libgomp.exp             | 8 +++-----
 libgomp/testsuite/libgomp-test-support.exp.in | 4 ++++
 5 files changed, 13 insertions(+), 15 deletions(-)

diff --git libgomp/ChangeLog.gomp libgomp/ChangeLog.gomp
index 1fca220..9c23c80 100644
--- libgomp/ChangeLog.gomp
+++ libgomp/ChangeLog.gomp
@@ -1,5 +1,11 @@
 2014-12-17  Thomas Schwinge  <thomas@codesourcery.com>
 
+	* testsuite/Makefile.am: Don't export OFFLOAD_TARGETS,
+	OFFLOAD_ADDITIONAL_OPTIONS, and OFFLOAD_ADDITIONAL_LIB_PATHS...
+	* testsuite/libgomp-test-support.exp.in: ..., and instead set
+	offload_targets, offload_additional_options, and
+	offload_additional_lib_paths here.  Update all users.
+
 	* testsuite/libgomp.oacc-c++/c++.exp
 	(check_effective_target_oacc_c): Remove, and ...
 	* testsuite/libgomp.oacc-c/c.exp (check_effective_target_oacc_c):
diff --git libgomp/testsuite/Makefile.am libgomp/testsuite/Makefile.am
index 9cc103a..561b7e2 100644
--- libgomp/testsuite/Makefile.am
+++ libgomp/testsuite/Makefile.am
@@ -11,8 +11,3 @@ EXPECT = $(shell if test -f $(top_builddir)/../expect/expect; then \
 _RUNTEST = $(shell if test -f $(top_srcdir)/../dejagnu/runtest; then \
 	     echo $(top_srcdir)/../dejagnu/runtest; else echo runtest; fi)
 RUNTEST = "$(_RUNTEST) $(AM_RUNTESTFLAGS)"
-
-# Used for support non-fallback offloading.
-export OFFLOAD_TARGETS = $(offload_targets)
-export OFFLOAD_ADDITIONAL_OPTIONS = $(offload_additional_options)
-export OFFLOAD_ADDITIONAL_LIB_PATHS = $(offload_additional_lib_paths)
diff --git libgomp/testsuite/Makefile.in libgomp/testsuite/Makefile.in
index 78b6351..016d0d4 100644
--- libgomp/testsuite/Makefile.in
+++ libgomp/testsuite/Makefile.in
@@ -421,11 +421,6 @@ uninstall-am:
 	uninstall uninstall-am
 
 
-# Used for support non-fallback offloading.
-export OFFLOAD_TARGETS = $(offload_targets)
-export OFFLOAD_ADDITIONAL_OPTIONS = $(offload_additional_options)
-export OFFLOAD_ADDITIONAL_LIB_PATHS = $(offload_additional_lib_paths)
-
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
diff --git libgomp/testsuite/lib/libgomp.exp libgomp/testsuite/lib/libgomp.exp
index 81545db..6600c25 100644
--- libgomp/testsuite/lib/libgomp.exp
+++ libgomp/testsuite/lib/libgomp.exp
@@ -111,13 +111,9 @@ proc libgomp_init { args } {
     # Compute what needs to be put into LD_LIBRARY_PATH
     set always_ld_library_path ".:${blddir}/.libs"
 
-    # Get offload-related variables from environment (exported by Makefile)
-    set offload_targets [getenv OFFLOAD_TARGETS]
-    set offload_additional_options [getenv OFFLOAD_ADDITIONAL_OPTIONS]
-    set offload_additional_lib_paths [getenv OFFLOAD_ADDITIONAL_LIB_PATHS]
-
     # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
     # non-fallback testing for Intel MIC targets
+    global offload_targets
     if { [string match "*-intelmic-*" $offload_targets]
 	|| [string match "*-intelmicemul-*" $offload_targets] } {
 	append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
@@ -126,6 +122,7 @@ proc libgomp_init { args } {
 	append always_ld_library_path ":${blddir}/../libstdc++-v3/src/.libs"
     }
 
+    global offload_additional_lib_paths
     if { $offload_additional_lib_paths != "" } {
 	append always_ld_library_path "${offload_additional_lib_paths}"
     }
@@ -215,6 +212,7 @@ proc libgomp_init { args } {
 
     # Used for support non-fallback offloading.
     # Help GCC to find target mkoffload.
+    global offload_additional_options
     if { $offload_additional_options != "" } {
 	lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
     }
diff --git libgomp/testsuite/libgomp-test-support.exp.in libgomp/testsuite/libgomp-test-support.exp.in
index dcadad7..4586fbe 100644
--- libgomp/testsuite/libgomp-test-support.exp.in
+++ libgomp/testsuite/libgomp-test-support.exp.in
@@ -1,2 +1,6 @@
 set cuda_driver_include "@CUDA_DRIVER_INCLUDE@"
 set cuda_driver_lib "@CUDA_DRIVER_LIB@"
+
+set offload_targets "@offload_targets@"
+set offload_additional_options "@offload_additional_options@"
+set offload_additional_lib_paths "@offload_additional_lib_paths@"


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-12-17 22:53       ` Thomas Schwinge
@ 2014-12-18 10:46         ` Jakub Jelinek
  2014-12-22 16:37           ` Thomas Schwinge
  0 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2014-12-18 10:46 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: Ilya Verbin, gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Wed, Dec 17, 2014 at 11:48:01PM +0100, Thomas Schwinge wrote:
> I have another suggestion: on gomp-4_0-branch, we had already started
> using a libgomp-test-support.exp file for a similar purpose.  I now
> changed your code on gomp-4_0-branch in r218845 as follows (though, not
> very much tested).  The advantage here is that people who are not using
> GCC build-tree testing, but are directly invoking runtest, then don't
> have to set various environment variables, but instead just have to copy
> this one libgomp-test-support.exp file from the build tree to the testing
> tree.  Does this make sense?
> 
> commit de01639bf47e29a20959771e587fb6f30c372a45
> Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
> Date:   Wed Dec 17 22:45:05 2014 +0000
> 
>     libgomp: Route offloading data through the libgomp-test-support.exp file.
>     
>     	libgomp/
>     	* testsuite/Makefile.am: Don't export OFFLOAD_TARGETS,
>     	OFFLOAD_ADDITIONAL_OPTIONS, and OFFLOAD_ADDITIONAL_LIB_PATHS...
>     	* testsuite/libgomp-test-support.exp.in: ..., and instead set
>     	offload_targets, offload_additional_options, and
>     	offload_additional_lib_paths here.  Update all users.

LGTM.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-10-30 12:45 ` [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing Ilya Verbin
  2014-11-06 17:55   ` Jakub Jelinek
@ 2014-12-18 15:56   ` Thomas Schwinge
  2014-12-18 17:43     ` Ilya Verbin
  2016-03-13 19:10   ` Thomas Schwinge
  2 siblings, 1 reply; 111+ messages in thread
From: Thomas Schwinge @ 2014-12-18 15:56 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek; +Cc: Kirill Yukhin, Andrey Turetskiy, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2685 bytes --]

Hi!

On Thu, 30 Oct 2014 14:40:01 +0300, Ilya Verbin <iverbin@gmail.com> wrote:
> This patch allows to run non-fallback 'make check-target-libgomp'.  It passes to
> the host compiler additional -B options with the paths to the offload compilers,
> since non-installed host compiler doesn't know where to find mkoffload tools.
> Also in case of intelmic offload targets it appends paths to liboffloadmic lib.

> --- a/libgomp/configure.ac
> +++ b/libgomp/configure.ac
> @@ -280,9 +280,13 @@ else
>    multilib_arg=
>  fi
>  
> +# Get accel target and path to install tree of accel compiler
> +offload_additional_options=
> +offload_additional_lib_paths=
>  offload_targets=
>  if test x"$enable_offload_targets" != x; then
>    for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
> +    tgt_dir=`echo $tgt | grep '=' | sed 's/.*=//'`
>      tgt=`echo $tgt | sed 's/=.*//'`
>      case $tgt in
>        *-intelmic-* | *-intelmicemul-*)
> @@ -295,10 +299,20 @@ if test x"$enable_offload_targets" != x; then
>      else
>        offload_targets=$offload_targets,$tgt_name
>      fi
> +    if test x"$tgt_dir" != x; then
> +      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
> +      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib"
> +    else
> +      offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
> +      offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"
> +    fi
>    done
>  fi

Hmm, maybe I'm seeing a problem where there isn't one, but in case I'm
not: how will this work if there is more than one offloading compiler
configured?  Won't you get conflicting -B paths added to
offload_additional_options in this case?

> --- a/libgomp/testsuite/lib/libgomp.exp
> +++ b/libgomp/testsuite/lib/libgomp.exp
> @@ -169,6 +186,10 @@ proc libgomp_init { args } {
>  
>      # Disable color diagnostics
>      lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
> +
> +    # Required to support non-fallback testing of '#pragma omp target'.
> +    # Help GCC to find target mkoffload.
> +    lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
>  }

What we're doing in OpenACC offloading testing (gomp-4_0-branch), is in
the libgomp.oacc-c/c.exp (etc.) file cycle through all the available
offloading devices, and then in there -- I think -- such options should
be set, that are specific to one particular offloading device/compiler?


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-12-18 15:56   ` Thomas Schwinge
@ 2014-12-18 17:43     ` Ilya Verbin
  2014-12-18 17:56       ` Jakub Jelinek
  2014-12-22 11:49       ` Thomas Schwinge
  0 siblings, 2 replies; 111+ messages in thread
From: Ilya Verbin @ 2014-12-18 17:43 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: Jakub Jelinek, Kirill Yukhin, Andrey Turetskiy, gcc

Hi,

2014-12-18 16:27 GMT+01:00 Thomas Schwinge <thomas@codesourcery.com>:
> Hi!
>
> On Thu, 30 Oct 2014 14:40:01 +0300, Ilya Verbin <iverbin@gmail.com> wrote:
>> This patch allows to run non-fallback 'make check-target-libgomp'.  It passes to
>> the host compiler additional -B options with the paths to the offload compilers,
>> since non-installed host compiler doesn't know where to find mkoffload tools.
>> Also in case of intelmic offload targets it appends paths to liboffloadmic lib.
>
>> --- a/libgomp/configure.ac
>> +++ b/libgomp/configure.ac
>> @@ -280,9 +280,13 @@ else
>>    multilib_arg=
>>  fi
>>
>> +# Get accel target and path to install tree of accel compiler
>> +offload_additional_options=
>> +offload_additional_lib_paths=
>>  offload_targets=
>>  if test x"$enable_offload_targets" != x; then
>>    for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
>> +    tgt_dir=`echo $tgt | grep '=' | sed 's/.*=//'`
>>      tgt=`echo $tgt | sed 's/=.*//'`
>>      case $tgt in
>>        *-intelmic-* | *-intelmicemul-*)
>> @@ -295,10 +299,20 @@ if test x"$enable_offload_targets" != x; then
>>      else
>>        offload_targets=$offload_targets,$tgt_name
>>      fi
>> +    if test x"$tgt_dir" != x; then
>> +      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
>> +      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib"
>> +    else
>> +      offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
>> +      offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"
>> +    fi
>>    done
>>  fi
>
> Hmm, maybe I'm seeing a problem where there isn't one, but in case I'm
> not: how will this work if there is more than one offloading compiler
> configured?  Won't you get conflicting -B paths added to
> offload_additional_options in this case?
>
>> --- a/libgomp/testsuite/lib/libgomp.exp
>> +++ b/libgomp/testsuite/lib/libgomp.exp
>> @@ -169,6 +186,10 @@ proc libgomp_init { args } {
>>
>>      # Disable color diagnostics
>>      lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
>> +
>> +    # Required to support non-fallback testing of '#pragma omp target'.
>> +    # Help GCC to find target mkoffload.
>> +    lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
>>  }
>
> What we're doing in OpenACC offloading testing (gomp-4_0-branch), is in
> the libgomp.oacc-c/c.exp (etc.) file cycle through all the available
> offloading devices, and then in there -- I think -- such options should
> be set, that are specific to one particular offloading device/compiler?
>
>
> Grüße,
>  Thomas

I have not tested a compiler, configured to support 2 different
offloading targets, so there might be some corner cases.

In this place I don't see any problems, at least for the case with
installed offloading compilers.
One -B allows to find mkoffload in lto-wrapper:compile_offload_image.
This function tries to open all paths + '/accel/target_name/mkoffload'
suffix. So, there should be no conflicts.
Another -B allows mkoffload to find target driver. It tries to open
'host_name-accel-target_name-gcc', so, there also should be no
conflicts.

However, I still did not tried to enable 'make check' with
non-installed offloading compilers. Probably such target specific
paths can help there.

  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-12-18 17:43     ` Ilya Verbin
@ 2014-12-18 17:56       ` Jakub Jelinek
  2014-12-22 11:49       ` Thomas Schwinge
  1 sibling, 0 replies; 111+ messages in thread
From: Jakub Jelinek @ 2014-12-18 17:56 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: Thomas Schwinge, Kirill Yukhin, Andrey Turetskiy, gcc

On Thu, Dec 18, 2014 at 06:41:18PM +0100, Ilya Verbin wrote:
> > What we're doing in OpenACC offloading testing (gomp-4_0-branch), is in
> > the libgomp.oacc-c/c.exp (etc.) file cycle through all the available
> > offloading devices, and then in there -- I think -- such options should
> > be set, that are specific to one particular offloading device/compiler?
> 
> I have not tested a compiler, configured to support 2 different
> offloading targets, so there might be some corner cases.
> 
> In this place I don't see any problems, at least for the case with
> installed offloading compilers.
> One -B allows to find mkoffload in lto-wrapper:compile_offload_image.
> This function tries to open all paths + '/accel/target_name/mkoffload'
> suffix. So, there should be no conflicts.
> Another -B allows mkoffload to find target driver. It tries to open
> 'host_name-accel-target_name-gcc', so, there also should be no
> conflicts.
> 
> However, I still did not tried to enable 'make check' with
> non-installed offloading compilers. Probably such target specific
> paths can help there.

Yeah, generally we want to be able to support all 3 (or 4 etc.) compilers
installed into the same DESTDIR and prefix, so extra -B arguments in there
should not break anything, for each of the offloading compilers you'd just
add what -B options it needs.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2014-10-22 18:57     ` Ilya Verbin
  2014-11-03 17:36       ` [gomp4] Mark fopenacc as LTO option Tom de Vries
  2014-11-06 18:02       ` [PATCH 1/4] Add mkoffload for Intel MIC Jakub Jelinek
@ 2014-12-22 11:25       ` Thomas Schwinge
  2014-12-22 11:28         ` Jakub Jelinek
  2014-12-22 11:27       ` [PATCH 1/4] Add mkoffload for Intel MIC Thomas Schwinge
                         ` (2 subsequent siblings)
  5 siblings, 1 reply; 111+ messages in thread
From: Thomas Schwinge @ 2014-12-22 11:25 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek
  Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy, Bernd Schmidt

[-- Attachment #1: Type: text/plain, Size: 5637 bytes --]

Hi!

On Wed, 22 Oct 2014 22:57:01 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> --- /dev/null
> +++ b/gcc/config/i386/intelmic-mkoffload.c
> @@ -0,0 +1,541 @@
> +/* Offload image generation tool for Intel MIC devices.

> +static const char *
> +prepare_target_image (const char *target_compiler, int argc, char **argv)
> +{
> +  [...]
> +  obstack_init (&argv_obstack);
> +  obstack_ptr_grow (&argv_obstack, target_compiler);
> +  obstack_ptr_grow (&argv_obstack, "-xlto");
> +  obstack_ptr_grow (&argv_obstack, "-fopenmp");
> +  obstack_ptr_grow (&argv_obstack, "-shared");
> +  obstack_ptr_grow (&argv_obstack, "-fPIC");
> +  obstack_ptr_grow (&argv_obstack, opt1);

What is the reason that you're adding -fopenmp here?  I assume it is that
otherwise you'd get tree streaming errors because of different builtins
configurations, like this?

    $ [...]/build-gcc/gcc/xgcc -B[...]/build-gcc/gcc/ [...]/source-gcc/libgomp/testsuite/libgomp.oacc-c/../libgomp.oacc-c-c++-common/collapse-1.c -B[...]/build-gcc/x86_64-unknown-linux-gnu/./libgomp/ -B[...]/build-gcc/x86_64-unknown-linux-gnu/./libgomp/.libs -I[...]/build-gcc/x86_64-unknown-linux-gnu/./libgomp -I[...]/source-gcc/libgomp/testsuite/../../include -I[...]/source-gcc/libgomp/testsuite/.. -fmessage-length=0 -fno-diagnostics-show-caret -fdiagnostics-color=never -B[...]/install/offload-x86_64-intelmicemul-linux-gnu/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0 -B[...]/install/offload-x86_64-intelmicemul-linux-gnu/bin -fopenacc -DACC_DEVICE_TYPE_host_nonshm=1 -DACC_MEM_SHARED=0 -O2 -L[...]/build-gcc/x86_64-unknown-linux-gnu/./libgomp/.libs -lm -o ./collapse-1.exe
    lto1: internal compiler error: in streamer_get_builtin_tree, at tree-streamer-in.c:1136
    0xc0b7ff streamer_get_builtin_tree(lto_input_block*, data_in*)
            [...]/source-gcc/gcc/tree-streamer-in.c:1136
    0x8f7cc4 lto_input_tree_1(lto_input_block*, data_in*, LTO_tags, unsigned int)
            [...]/source-gcc/gcc/lto-streamer-in.c:1303
    0x8f7ee0 lto_input_scc(lto_input_block*, data_in*, unsigned int*, unsigned int*)
            [...]/source-gcc/gcc/lto-streamer-in.c:1231
    0x5e9bee lto_read_decls
            [...]/source-gcc/gcc/lto/lto.c:1889
    0x5ebc5c lto_file_finalize
            [...]/source-gcc/gcc/lto/lto.c:2218
    0x5ebc5c lto_create_files_from_ids
            [...]/source-gcc/gcc/lto/lto.c:2228
    0x5ebc5c lto_file_read
            [...]/source-gcc/gcc/lto/lto.c:2269
    0x5ebc5c read_cgraph_and_symbols
            [...]/source-gcc/gcc/lto/lto.c:2969
    0x5ebc5c lto_main()
            [...]/source-gcc/gcc/lto/lto.c:3424
    [...]
    mkoffload-intelmic: fatal error: [...]/install/offload-x86_64-intelmicemul-linux-gnu/bin//x86_64-unknown-linux-gnu-accel-x86_64-intelmicemul-linux-gnu-gcc returned 1 exit status
    compilation terminated.
    lto-wrapper: fatal error: [...]/install/offload-x86_64-intelmicemul-linux-gnu/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0//accel/x86_64-intelmicemul-linux-gnu/mkoffload returned 1 exit status
    compilation terminated.
    [...]/ld: lto-wrapper failed
    collect2: error: ld returned 1 exit status

If that is the "only" reason to add -fopenmp there, can we then instead
do the following?

 gcc/builtins.def                     | 8 ++++++--
 gcc/config/i386/intelmic-mkoffload.c | 1 -
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git gcc/builtins.def gcc/builtins.def
index b70e8e0..08bf62e 100644
--- gcc/builtins.def
+++ gcc/builtins.def
@@ -148,10 +148,13 @@ along with GCC; see the file COPYING3.  If not see
 
 /* Builtin used by the implementation of OpenACC and OpenMP.  Few of these are
    actually implemented in the compiler; most are in libgomp.  */
+/* These builtins also need to be enabled in offloading compilers invoked from
+   mkoffload; for that purpose, we're checking the -foffload-abi flag here.  */
 #undef DEF_GOACC_BUILTIN
 #define DEF_GOACC_BUILTIN(ENUM, NAME, TYPE, ATTRS) \
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,    \
-	       false, true, true, ATTRS, false, flag_openacc)
+	       false, true, true, ATTRS, false,				\
+	       (flag_openacc || flag_offload_abi != OFFLOAD_ABI_UNSET))
 #undef DEF_GOACC_BUILTIN_COMPILER
 #define DEF_GOACC_BUILTIN_COMPILER(ENUM, NAME, TYPE, ATTRS) \
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,    \
@@ -160,7 +163,8 @@ along with GCC; see the file COPYING3.  If not see
 #define DEF_GOMP_BUILTIN(ENUM, NAME, TYPE, ATTRS) \
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,    \
                false, true, true, ATTRS, false, \
-	       (flag_openmp || flag_tree_parallelize_loops))
+	       (flag_openmp || flag_tree_parallelize_loops \
+		|| flag_offload_abi != OFFLOAD_ABI_UNSET))
 
 /* Builtin used by implementation of Cilk Plus.  Most of these are decomposed
    by the compiler but a few are implemented in libcilkrts.  */ 
diff --git gcc/config/i386/intelmic-mkoffload.c gcc/config/i386/intelmic-mkoffload.c
index c972f56..caf58a1 100644
--- gcc/config/i386/intelmic-mkoffload.c
+++ gcc/config/i386/intelmic-mkoffload.c
@@ -386,7 +386,6 @@ prepare_target_image (const char *target_compiler, int argc, char **argv)
   obstack_init (&argv_obstack);
   obstack_ptr_grow (&argv_obstack, target_compiler);
   obstack_ptr_grow (&argv_obstack, "-xlto");
-  obstack_ptr_grow (&argv_obstack, "-fopenmp");
   obstack_ptr_grow (&argv_obstack, "-shared");
   obstack_ptr_grow (&argv_obstack, "-fPIC");
   obstack_ptr_grow (&argv_obstack, opt1);


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2014-10-22 18:57     ` Ilya Verbin
                         ` (2 preceding siblings ...)
  2014-12-22 11:25       ` OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC) Thomas Schwinge
@ 2014-12-22 11:27       ` Thomas Schwinge
  2014-12-22 11:48         ` Jakub Jelinek
  2015-02-18 11:48       ` [PATCH 1/4] Add mkoffload for Intel MIC Thomas Schwinge
  2015-09-28  9:39       ` Thomas Schwinge
  5 siblings, 1 reply; 111+ messages in thread
From: Thomas Schwinge @ 2014-12-22 11:27 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: text/plain, Size: 1991 bytes --]

Hi!

On Wed, 22 Oct 2014 22:57:01 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> --- /dev/null
> +++ b/gcc/config/i386/intelmic-mkoffload.c
> @@ -0,0 +1,541 @@
> +/* Offload image generation tool for Intel MIC devices.

> +/* Shows if we should compile binaries for i386 instead of x86-64.  */
> +bool target_ilp32 = false;

My linker defaults to 32-bit x86, so I explicitly have to switch to
64-bit x86_64 mode; OK to commit the following, to always explicitly
specify what is wanted?

 gcc/config/i386/intelmic-mkoffload.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git gcc/config/i386/intelmic-mkoffload.c gcc/config/i386/intelmic-mkoffload.c
index c972f56..7337c31 100644
--- gcc/config/i386/intelmic-mkoffload.c
+++ gcc/config/i386/intelmic-mkoffload.c
@@ -191,6 +191,8 @@ compile_for_target (struct obstack *argv_obstack)
 {
   if (target_ilp32)
     obstack_ptr_grow (argv_obstack, "-m32");
+  else
+    obstack_ptr_grow (argv_obstack, "-m64");
   obstack_ptr_grow (argv_obstack, NULL);
   char **argv = XOBFINISH (argv_obstack, char **);
 
@@ -355,6 +357,8 @@ generate_host_descr_file (const char *host_compiler)
   new_argv[new_argc++] = "-shared";
   if (target_ilp32)
     new_argv[new_argc++] = "-m32";
+  else
+    new_argv[new_argc++] = "-m64";
   new_argv[new_argc++] = src_filename;
   new_argv[new_argc++] = "-o";
   new_argv[new_argc++] = obj_filename;
@@ -511,11 +515,11 @@ main (int argc, char **argv)
   unsigned new_argc = 0;
   const char *new_argv[9];
   new_argv[new_argc++] = "ld";
+  new_argv[new_argc++] = "-m";
   if (target_ilp32)
-    {
-      new_argv[new_argc++] = "-m";
-      new_argv[new_argc++] = "elf_i386";
-    }
+    new_argv[new_argc++] = "elf_i386";
+  else
+    new_argv[new_argc++] = "elf_x86_64";
   new_argv[new_argc++] = "--relocatable";
   new_argv[new_argc++] = host_descr_filename;
   new_argv[new_argc++] = target_so_filename;


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2014-12-22 11:25       ` OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC) Thomas Schwinge
@ 2014-12-22 11:28         ` Jakub Jelinek
  2014-12-26 15:49           ` Ilya Verbin
  0 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2014-12-22 11:28 UTC (permalink / raw)
  To: Thomas Schwinge
  Cc: Ilya Verbin, gcc-patches, Kirill Yukhin, Andrey Turetskiy, Bernd Schmidt

On Mon, Dec 22, 2014 at 12:20:58PM +0100, Thomas Schwinge wrote:
> On Wed, 22 Oct 2014 22:57:01 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> > --- /dev/null
> > +++ b/gcc/config/i386/intelmic-mkoffload.c
> > @@ -0,0 +1,541 @@
> > +/* Offload image generation tool for Intel MIC devices.
> 
> > +static const char *
> > +prepare_target_image (const char *target_compiler, int argc, char **argv)
> > +{
> > +  [...]
> > +  obstack_init (&argv_obstack);
> > +  obstack_ptr_grow (&argv_obstack, target_compiler);
> > +  obstack_ptr_grow (&argv_obstack, "-xlto");
> > +  obstack_ptr_grow (&argv_obstack, "-fopenmp");
> > +  obstack_ptr_grow (&argv_obstack, "-shared");
> > +  obstack_ptr_grow (&argv_obstack, "-fPIC");
> > +  obstack_ptr_grow (&argv_obstack, opt1);
> 
> What is the reason that you're adding -fopenmp here?  I assume it is that
> otherwise you'd get tree streaming errors because of different builtins
> configurations, like this?
> 
>     $ [...]/build-gcc/gcc/xgcc -B[...]/build-gcc/gcc/ [...]/source-gcc/libgomp/testsuite/libgomp.oacc-c/../libgomp.oacc-c-c++-common/collapse-1.c -B[...]/build-gcc/x86_64-unknown-linux-gnu/./libgomp/ -B[...]/build-gcc/x86_64-unknown-linux-gnu/./libgomp/.libs -I[...]/build-gcc/x86_64-unknown-linux-gnu/./libgomp -I[...]/source-gcc/libgomp/testsuite/../../include -I[...]/source-gcc/libgomp/testsuite/.. -fmessage-length=0 -fno-diagnostics-show-caret -fdiagnostics-color=never -B[...]/install/offload-x86_64-intelmicemul-linux-gnu/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0 -B[...]/install/offload-x86_64-intelmicemul-linux-gnu/bin -fopenacc -DACC_DEVICE_TYPE_host_nonshm=1 -DACC_MEM_SHARED=0 -O2 -L[...]/build-gcc/x86_64-unknown-linux-gnu/./libgomp/.libs -lm -o ./collapse-1.exe
>     lto1: internal compiler error: in streamer_get_builtin_tree, at tree-streamer-in.c:1136
>     0xc0b7ff streamer_get_builtin_tree(lto_input_block*, data_in*)
>             [...]/source-gcc/gcc/tree-streamer-in.c:1136
>     0x8f7cc4 lto_input_tree_1(lto_input_block*, data_in*, LTO_tags, unsigned int)
>             [...]/source-gcc/gcc/lto-streamer-in.c:1303
>     0x8f7ee0 lto_input_scc(lto_input_block*, data_in*, unsigned int*, unsigned int*)
>             [...]/source-gcc/gcc/lto-streamer-in.c:1231
>     0x5e9bee lto_read_decls
>             [...]/source-gcc/gcc/lto/lto.c:1889
>     0x5ebc5c lto_file_finalize
>             [...]/source-gcc/gcc/lto/lto.c:2218
>     0x5ebc5c lto_create_files_from_ids
>             [...]/source-gcc/gcc/lto/lto.c:2228
>     0x5ebc5c lto_file_read
>             [...]/source-gcc/gcc/lto/lto.c:2269
>     0x5ebc5c read_cgraph_and_symbols
>             [...]/source-gcc/gcc/lto/lto.c:2969
>     0x5ebc5c lto_main()
>             [...]/source-gcc/gcc/lto/lto.c:3424
>     [...]
>     mkoffload-intelmic: fatal error: [...]/install/offload-x86_64-intelmicemul-linux-gnu/bin//x86_64-unknown-linux-gnu-accel-x86_64-intelmicemul-linux-gnu-gcc returned 1 exit status
>     compilation terminated.
>     lto-wrapper: fatal error: [...]/install/offload-x86_64-intelmicemul-linux-gnu/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0//accel/x86_64-intelmicemul-linux-gnu/mkoffload returned 1 exit status
>     compilation terminated.
>     [...]/ld: lto-wrapper failed
>     collect2: error: ld returned 1 exit status
> 
> If that is the "only" reason to add -fopenmp there, can we then instead
> do the following?
> 
>  gcc/builtins.def                     | 8 ++++++--
>  gcc/config/i386/intelmic-mkoffload.c | 1 -
>  2 files changed, 6 insertions(+), 3 deletions(-)

If Ilya confirms that is the sole reason, I'm fine with this change.
Please write ChangeLog entry for it.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2014-12-22 11:27       ` [PATCH 1/4] Add mkoffload for Intel MIC Thomas Schwinge
@ 2014-12-22 11:48         ` Jakub Jelinek
  2015-01-08 14:59           ` Thomas Schwinge
  0 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2014-12-22 11:48 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: Ilya Verbin, gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Mon, Dec 22, 2014 at 12:25:32PM +0100, Thomas Schwinge wrote:
> Hi!
> 
> On Wed, 22 Oct 2014 22:57:01 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> > --- /dev/null
> > +++ b/gcc/config/i386/intelmic-mkoffload.c
> > @@ -0,0 +1,541 @@
> > +/* Offload image generation tool for Intel MIC devices.
> 
> > +/* Shows if we should compile binaries for i386 instead of x86-64.  */
> > +bool target_ilp32 = false;
> 
> My linker defaults to 32-bit x86, so I explicitly have to switch to
> 64-bit x86_64 mode; OK to commit the following, to always explicitly
> specify what is wanted?
> 
>  gcc/config/i386/intelmic-mkoffload.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)

Ok with proper ChangeLog entry.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-12-18 17:43     ` Ilya Verbin
  2014-12-18 17:56       ` Jakub Jelinek
@ 2014-12-22 11:49       ` Thomas Schwinge
  2014-12-22 12:50         ` Jakub Jelinek
  2014-12-26 20:53         ` Ilya Verbin
  1 sibling, 2 replies; 111+ messages in thread
From: Thomas Schwinge @ 2014-12-22 11:49 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek; +Cc: Kirill Yukhin, Andrey Turetskiy, gcc

[-- Attachment #1: Type: text/plain, Size: 8908 bytes --]

Hi!

On Thu, 18 Dec 2014 18:41:18 +0100, Ilya Verbin <iverbin@gmail.com> wrote:
> 2014-12-18 16:27 GMT+01:00 Thomas Schwinge <thomas@codesourcery.com>:
> > On Thu, 30 Oct 2014 14:40:01 +0300, Ilya Verbin <iverbin@gmail.com> wrote:
> >> This patch allows to run non-fallback 'make check-target-libgomp'.  It passes to
> >> the host compiler additional -B options with the paths to the offload compilers,
> >> since non-installed host compiler doesn't know where to find mkoffload tools.
> >> Also in case of intelmic offload targets it appends paths to liboffloadmic lib.
> >
> >> --- a/libgomp/configure.ac
> >> +++ b/libgomp/configure.ac
> >> @@ -280,9 +280,13 @@ else
> >>    multilib_arg=
> >>  fi
> >>
> >> +# Get accel target and path to install tree of accel compiler
> >> +offload_additional_options=
> >> +offload_additional_lib_paths=
> >>  offload_targets=
> >>  if test x"$enable_offload_targets" != x; then
> >>    for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
> >> +    tgt_dir=`echo $tgt | grep '=' | sed 's/.*=//'`
> >>      tgt=`echo $tgt | sed 's/=.*//'`
> >>      case $tgt in
> >>        *-intelmic-* | *-intelmicemul-*)
> >> @@ -295,10 +299,20 @@ if test x"$enable_offload_targets" != x; then
> >>      else
> >>        offload_targets=$offload_targets,$tgt_name
> >>      fi
> >> +    if test x"$tgt_dir" != x; then
> >> +      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
> >> +      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib"
> >> +    else
> >> +      offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
> >> +      offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"
> >> +    fi
> >>    done
> >>  fi
> >
> > Hmm, maybe I'm seeing a problem where there isn't one, but in case I'm
> > not: how will this work if there is more than one offloading compiler
> > configured?  Won't you get conflicting -B paths added to
> > offload_additional_options in this case?

> In this place I don't see any problems, at least for the case with
> installed offloading compilers.
> One -B allows to find mkoffload in lto-wrapper:compile_offload_image.
> This function tries to open all paths + '/accel/target_name/mkoffload'
> suffix. So, there should be no conflicts.
> Another -B allows mkoffload to find target driver. It tries to open
> 'host_name-accel-target_name-gcc', so, there also should be no
> conflicts.

Aha, thanks for the explanation, and yes, that seems all good.


What is the reason for adding paths if $tgt_dir is empty?  (I mean, if
properly installed and $tgt_dir empty, this should just work, because
that's what a user will be doing, so why does the libgomp testsuite have
to do differently?)  These paths will (basically) point to GCC's
configured --prefix=[...] -- which may not actually match where the
installed offloading compilers are to be found, for example, in the
common case that DESTDIR is used with make install.  And, isn't it that
GCC by default will already be looking into "$prefix" installation
directories, or is this solving an actual problem for you?  If not, is it
then OK to remove the cases for empty $tgt_dir?


> However, I still did not tried to enable 'make check' with
> non-installed offloading compilers.

I'm working of that (with low priority, though).

In my understanding, we'd like to support the modes that either all
compilers are installed (which is what a user will be using), or all are
tested from their build trees.  Or, do we also have to support the mode
that only the offloading compilers are installed, but the target
(offloading host) compiler is not?  (Doesn't make much sense to me.)


Here is a patch to correctly match intelmic in $offload_targets; OK to
commit, I assume?  I suppose I'm the first one to ever do build-tree
testing?  (Jakub?)

--- libgomp/testsuite/lib/libgomp.exp
+++ libgomp/testsuite/lib/libgomp.exp
@@ -115,8 +115,7 @@ proc libgomp_init { args } {
 
     # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
     # non-fallback testing for Intel MIC targets
-    if { [string match "*-intelmic-*" $offload_targets]
-	|| [string match "*-intelmicemul-*" $offload_targets] } {
+    if { [string match "*,intelmic,*" ",$offload_targets,"] } {
 	append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
 	append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
 	# libstdc++ is required by liboffloadmic


Such things also need to be guarded to be done for build-tree testing
only; I'll address this later on, where missing.


Here is a patch to fix 32-bit x86 Intel MIC offloading; OK to commit, I
assume?

    [...]
    spawn [...]/build-gcc/gcc/xgcc -B[...]/build-gcc/gcc/ [...]/source-gcc/libgomp/testsuite/libgomp.c/examples-4/e.50.1.c -B[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/ -B[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/.libs -I[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp -I[...]/source-gcc/libgomp/testsuite/.. -march=i486 -fmessage-length=0 -fno-diagnostics-show-caret -fdiagnostics-color=never -B[...]/install/offload-x86_64-intelmicemul-linux-gnu/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0 -B[...]/install/offload-x86_64-intelmicemul-linux-gnu/bin -fopenmp -O2 -L[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/.libs -lm -m32 -o ./e.50.1.exe
    PASS: libgomp.c/examples-4/e.50.1.c (test for excess errors)
    Setting LD_LIBRARY_PATH to .:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/../liboffloadmic/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/../liboffloadmic/plugin/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/../libstdc++-v3/src/.libs:[...]/install/offload-x86_64-intelmicemul-linux-gnu/lib64:[...]/install/offload-x86_64-intelmicemul-linux-gnu/lib:[...]/build-gcc/gcc:[...]/build-gcc/gcc/32:.:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/../liboffloadmic/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/../liboffloadmic/plugin/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/../libstdc++-v3/src/.libs:[...]/install/offload-x86_64-intelmicemul-linux-gnu/lib64:[...]/install/offload-x86_64-intelmicemul-linux-gnu/lib:[...]/build-gcc/gcc:[...]/build-gcc/gcc/32:[...]/build-gcc/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libsanitizer/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libvtv/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libcilkrts/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/liboffloadmic/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libssp/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libgomp/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libitm/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libatomic/.libs:[...]/build-gcc/./gcc:[...]/build-gcc/./prev-gcc
    spawn [open ...]
    /tmp/offload_WCXKRZ/offload_target_main: error while loading shared libraries: liboffloadmic_target.so.5: wrong ELF class: ELFCLASS64
    WARNING: program timed out.
    FAIL: libgomp.c/examples-4/e.50.1.c execution test
    [...]

(It is bad that testing is running into loooong timeouts for every single
offloading test case, but I'm not addressing that with my patch.)

This is a "standard" GCC configuration: x86_64-intelmicemul-linux-gnu with
(default) multilibs enabled:

    $ find -name liboffloadmic_target.so.5
    ./install/offload-x86_64-intelmicemul-linux-gnu/lib64/liboffloadmic_target.so.5
    ./install/offload-x86_64-intelmicemul-linux-gnu/lib32/liboffloadmic_target.so.5
    ./build-gcc-offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/32/liboffloadmic/.libs/liboffloadmic_target.so.5
    ./build-gcc-offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/liboffloadmic/.libs/liboffloadmic_target.so.5

--- libgomp/configure.ac
+++ libgomp/configure.ac
@@ -304,7 +304,7 @@ if test x"$enable_offload_targets" != x; then
     fi
     if test x"$tgt_dir" != x; then
       offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
-      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib"
+      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
     else
       offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
       offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC
  2014-10-21 17:16 [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC Ilya Verbin
                   ` (3 preceding siblings ...)
  2014-10-30 12:45 ` [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing Ilya Verbin
@ 2014-12-22 12:08 ` Thomas Schwinge
  2015-10-22 18:28   ` Ilya Verbin
  4 siblings, 1 reply; 111+ messages in thread
From: Thomas Schwinge @ 2014-12-22 12:08 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: Jakub Jelinek, Kirill Yukhin, Andrey Turetskiy, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 8268 bytes --]

Hi!

On Tue, 21 Oct 2014 21:13:23 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> This patchset would contain target-specific things to support offloading to the
> devices with Intel MIC architecture.
> Particularly: mkoffload tool, liboffloadmic library and a plugin for libgomp.

By chance (when tracking down a different problem), I've found the
following.  Would you please check whether that's a real problem in
liboffloadmic, or its libgomp plugin, or just a mis-diagnosis by
Valgrind?

    $ build-gcc/gcc/xgcc -Bbuild-gcc/gcc/ source-gcc/libgomp/testsuite/libgomp.fortran/examples-4/e.55.2.f90 -Bbuild-gcc/x86_64-unknown-linux-gnu/./libgomp/ -Bbuild-gcc/x86_64-unknown-linux-gnu/./libgomp/.libs -Ibuild-gcc/x86_64-unknown-linux-gnu/./libgomp -Isource-gcc/libgomp/testsuite/../../include -Isource-gcc/libgomp/testsuite/.. -Binstall/offload-x86_64-intelmicemul-linux-gnu/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0 -Binstall/offload-x86_64-intelmicemul-linux-gnu/bin -fopenmp -Bbuild-gcc/x86_64-unknown-linux-gnu/./libgomp/../libquadmath/.libs/ -O0 -Bbuild-gcc/x86_64-unknown-linux-gnu/./libgomp/../libgfortran/.libs -fintrinsic-modules-path=build-gcc/x86_64-unknown-linux-gnu/./libgomp -Lbuild-gcc/x86_64-unknown-linux-gnu/./libgomp/.libs -Lbuild-gcc/x86_64-unknown-linux-gnu/./libgomp/../libquadmath/.libs/ -Lbuild-gcc/x86_64-unknown-linux-gnu/./libgomp/../libgfortran/.libs -lgfortran -lm -g
    $ LD_LIBRARY_PATH=.:build-gcc/x86_64-unknown-linux-gnu/./libgomp/.libs:build-gcc/x86_64-unknown-linux-gnu/./libgomp/../liboffloadmic/.libs:build-gcc/x86_64-unknown-linux-gnu/./libgomp/../liboffloadmic/plugin/.libs:build-gcc/x86_64-unknown-linux-gnu/./libgomp/../libstdc++-v3/src/.libs:install/offload-x86_64-intelmicemul-linux-gnu/lib64:install/offload-x86_64-intelmicemul-linux-gnu/lib:build-gcc/gcc:build-gcc/x86_64-unknown-linux-gnu/./libgomp/../libgfortran/.libs:build-gcc/x86_64-unknown-linux-gnu/./libgomp/../libquadmath/.libs:.:build-gcc/x86_64-unknown-linux-gnu/./libgomp/.libs:build-gcc/x86_64-unknown-linux-gnu/./libgomp/../liboffloadmic/.libs:build-gcc/x86_64-unknown-linux-gnu/./libgomp/../liboffloadmic/plugin/.libs:build-gcc/x86_64-unknown-linux-gnu/./libgomp/../libstdc++-v3/src/.libs:install/offload-x86_64-intelmicemul-linux-gnu/lib64:install/offload-x86_64-intelmicemul-linux-gnu/lib:build-gcc/gcc:build-gcc/x86_64-unknown-linux-gnu/./libgomp/../libgfortran/.libs:build-gcc/x86_64-unknown-linux-gnu/./libgomp/../libquadmath/.libs: valgrind ./a.out
    ==21327== Memcheck, a memory error detector
    ==21327== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
    ==21327== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
    ==21327== Command: ./a.out
    ==21327== 
    ==21327== Syscall param write(buf) points to uninitialised byte(s)
    ==21327==    at 0x5686340: __write_nocancel (syscall-template.S:81)
    ==21327==    by 0x6AFC5C8: COIPipelineRunFunction@@COI_1.0 (coi_host.cpp:798)
    ==21327==    by 0x68D942A: _ZN6Engine7computeERKSt4listB5cxx11IP9coibufferSaIS2_EEPKvtPvtjPK8coieventPSA_ (offload_engine.cpp:424)
    ==21327==    by 0x68DED45: OffloadDescriptor::compute() (offload_host.cpp:2934)
    ==21327==    by 0x68E64F8: OffloadDescriptor::offload(char const*, bool, VarDesc*, VarDesc2*, int, void const**, int, void const**, int, void const*) (offload_host.cpp:2191)
    ==21327==    by 0x68D8D10: offload_offload_wrap(OffloadDescriptor*, char const*, int, int, VarDesc*, VarDesc2*, int, void const**, void const**, int, void const*) (compiler_if_host.cpp:259)
    ==21327==    by 0x68D8E19: __offload_offload1 (compiler_if_host.cpp:281)
    ==21327==    by 0x66B5387: offload(char const*, unsigned long, int, char const*, int, VarDesc*, VarDesc2*) [clone .constprop.24] (libgomp-plugin-intelmic.cpp:168)
    ==21327==    by 0x54716C7: gomp_init_device (target.c:628)
    ==21327==    by 0x5471E0D: GOMP_target_data (target.c:750)
    ==21327==    by 0x400E6F: vec_mult_ (e.55.2.f90:38)
    ==21327==    by 0x4011C9: MAIN__ (e.55.2.f90:55)
    ==21327==  Address 0x62ce6a2 is 18 bytes inside a block of size 72 alloc'd
    ==21327==    at 0x4C2AB80: malloc (vg_replace_malloc.c:292)
    ==21327==    by 0x68DD278: OffloadDescriptor::setup_misc_data(char const*) (offload_host.cpp:2060)
    ==21327==    by 0x68E64D8: OffloadDescriptor::offload(char const*, bool, VarDesc*, VarDesc2*, int, void const**, int, void const**, int, void const*) (offload_host.cpp:2179)
    ==21327==    by 0x68D8D10: offload_offload_wrap(OffloadDescriptor*, char const*, int, int, VarDesc*, VarDesc2*, int, void const**, void const**, int, void const*) (compiler_if_host.cpp:259)
    ==21327==    by 0x68D8E19: __offload_offload1 (compiler_if_host.cpp:281)
    ==21327==    by 0x66B5387: offload(char const*, unsigned long, int, char const*, int, VarDesc*, VarDesc2*) [clone .constprop.24] (libgomp-plugin-intelmic.cpp:168)
    ==21327==    by 0x54716C7: gomp_init_device (target.c:628)
    ==21327==    by 0x5471E0D: GOMP_target_data (target.c:750)
    ==21327==    by 0x400E6F: vec_mult_ (e.55.2.f90:38)
    ==21327==    by 0x4011C9: MAIN__ (e.55.2.f90:55)
    ==21327==    by 0x401200: main (e.55.2.f90:56)
    ==21327== 
    ==21327== Invalid read of size 4
    ==21327==    at 0x6AFD808: COIProcessLoadLibraryFromMemory@COI_2.0 (coi_host.cpp:1168)
    ==21327==    by 0x68D9146: Engine::load_libraries() (offload_engine.cpp:243)
    ==21327==    by 0x68DA269: Engine::init() (offload_engine.cpp:102)
    ==21327==    by 0x68D8B85: __offload_target_acquire1 (compiler_if_host.cpp:188)
    ==21327==    by 0x66B5362: offload(char const*, unsigned long, int, char const*, int, VarDesc*, VarDesc2*) [clone .constprop.24] (libgomp-plugin-intelmic.cpp:166)
    ==21327==    by 0x66B5509: get_target_table(int, int&, int&, void**&) [clone .constprop.23] (libgomp-plugin-intelmic.cpp:203)
    ==21327==    by 0x66B573E: GOMP_OFFLOAD_get_table (libgomp-plugin-intelmic.cpp:267)
    ==21327==    by 0x54716ED: gomp_init_device (target.c:632)
    ==21327==    by 0x5471E0D: GOMP_target_data (target.c:750)
    ==21327==    by 0x400E6F: vec_mult_ (e.55.2.f90:38)
    ==21327==    by 0x4011C9: MAIN__ (e.55.2.f90:55)
    ==21327==    by 0x401200: main (e.55.2.f90:56)
    ==21327==  Address 0x62d1424 is 36 bytes inside a block of size 37 alloc'd
    ==21327==    at 0x4C2AB80: malloc (vg_replace_malloc.c:292)
    ==21327==    by 0x6AFD706: COIProcessLoadLibraryFromMemory@COI_2.0 (coi_host.cpp:1154)
    ==21327==    by 0x68D9146: Engine::load_libraries() (offload_engine.cpp:243)
    ==21327==    by 0x68DA269: Engine::init() (offload_engine.cpp:102)
    ==21327==    by 0x68D8B85: __offload_target_acquire1 (compiler_if_host.cpp:188)
    ==21327==    by 0x66B5362: offload(char const*, unsigned long, int, char const*, int, VarDesc*, VarDesc2*) [clone .constprop.24] (libgomp-plugin-intelmic.cpp:166)
    ==21327==    by 0x66B5509: get_target_table(int, int&, int&, void**&) [clone .constprop.23] (libgomp-plugin-intelmic.cpp:203)
    ==21327==    by 0x66B573E: GOMP_OFFLOAD_get_table (libgomp-plugin-intelmic.cpp:267)
    ==21327==    by 0x54716ED: gomp_init_device (target.c:632)
    ==21327==    by 0x5471E0D: GOMP_target_data (target.c:750)
    ==21327==    by 0x400E6F: vec_mult_ (e.55.2.f90:38)
    ==21327==    by 0x4011C9: MAIN__ (e.55.2.f90:55)
    ==21327== 
    ==21327== 
    ==21327== HEAP SUMMARY:
    ==21327==     in use at exit: 18,480 bytes in 55 blocks
    ==21327==   total heap usage: 851 allocs, 796 frees, 227,151 bytes allocated
    ==21327== 
    ==21327== LEAK SUMMARY:
    ==21327==    definitely lost: 16 bytes in 1 blocks
    ==21327==    indirectly lost: 0 bytes in 0 blocks
    ==21327==      possibly lost: 673 bytes in 17 blocks
    ==21327==    still reachable: 17,791 bytes in 37 blocks
    ==21327==         suppressed: 0 bytes in 0 blocks
    ==21327== Rerun with --leak-check=full to see details of leaked memory
    ==21327== 
    ==21327== For counts of detected and suppressed errors, rerun with: -v
    ==21327== Use --track-origins=yes to see where uninitialised values come from
    ==21327== ERROR SUMMARY: 72 errors from 2 contexts (suppressed: 0 from 0)


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-12-22 11:49       ` Thomas Schwinge
@ 2014-12-22 12:50         ` Jakub Jelinek
  2015-01-15 19:21           ` Ilya Verbin
  2014-12-26 20:53         ` Ilya Verbin
  1 sibling, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2014-12-22 12:50 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: Ilya Verbin, Kirill Yukhin, Andrey Turetskiy, gcc

On Mon, Dec 22, 2014 at 12:48:08PM +0100, Thomas Schwinge wrote:
> In my understanding, we'd like to support the modes that either all
> compilers are installed (which is what a user will be using), or all are
> tested from their build trees.  Or, do we also have to support the mode
> that only the offloading compilers are installed, but the target
> (offloading host) compiler is not?  (Doesn't make much sense to me.)

All 3 of these, yes.
The nothing is installed yet mode supposedly doesn't work properly on the
trunk yet (and is what I'd like to use e.g. in distro rpm builds), the offloading
compilers installed, host is not is useful that you actually test the host compiler
before installing, and that supposedly works on the trunk, the all installed testing
I've never used myself, but some people are using it.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-12-18 10:46         ` Jakub Jelinek
@ 2014-12-22 16:37           ` Thomas Schwinge
  0 siblings, 0 replies; 111+ messages in thread
From: Thomas Schwinge @ 2014-12-22 16:37 UTC (permalink / raw)
  To: Jakub Jelinek, gcc-patches; +Cc: Ilya Verbin, Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: text/plain, Size: 10339 bytes --]

Hi!

On Thu, 18 Dec 2014 11:21:20 +0100, Jakub Jelinek <jakub@redhat.com> wrote:
> On Wed, Dec 17, 2014 at 11:48:01PM +0100, Thomas Schwinge wrote:
> > I have another suggestion: on gomp-4_0-branch, we had already started
> > using a libgomp-test-support.exp file for a similar purpose.  I now
> > changed your code on gomp-4_0-branch in r218845 as follows (though, not
> > very much tested).  The advantage here is that people who are not using
> > GCC build-tree testing, but are directly invoking runtest, then don't
> > have to set various environment variables, but instead just have to copy
> > this one libgomp-test-support.exp file from the build tree to the testing
> > tree.  Does this make sense?
> > 
> > commit de01639bf47e29a20959771e587fb6f30c372a45
> > Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
> > Date:   Wed Dec 17 22:45:05 2014 +0000
> > 
> >     libgomp: Route offloading data through the libgomp-test-support.exp file.
> >     
> >     	libgomp/
> >     	* testsuite/Makefile.am: Don't export OFFLOAD_TARGETS,
> >     	OFFLOAD_ADDITIONAL_OPTIONS, and OFFLOAD_ADDITIONAL_LIB_PATHS...
> >     	* testsuite/libgomp-test-support.exp.in: ..., and instead set
> >     	offload_targets, offload_additional_options, and
> >     	offload_additional_lib_paths here.  Update all users.
> 
> LGTM.

As discussed in
<http://news.gmane.org/find-root.php?message_id=%3C87388dropf.fsf%40schwinge.name%3E>,
that doesn't really work: there may be additional (recursive) expansions
required (similar to: libexecdir being defined in terms of exec_prefix,
that in terms of prefix, and so on), so we really need to handle that in
the Makefile, where all these variables are available.  Committed to
gomp-4_0-branch in r219016:

commit 6bb8cfa151e40ab1e991112d2bbe2719f0a2c46a
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Mon Dec 22 16:17:15 2014 +0000

    libgomp: Handle Makefile variable usage in testsuite/libgomp-test-support.exp.
    
    	libgomp/
    	* testsuite/libgomp-test-support.exp.in
    	(offload_additional_options, offload_additional_lib_paths): Don't
    	set.
    	* configure.ac: Instantiate testsuite/libgomp-test-support.pt.exp
    	instead of testsuite/libgomp-test-support.exp.
    	* testsuite/Makefile.am (libgomp-test-support.exp): New rule.
    	(all-local): Depend on it.
    	* configure: Regenerate.
    	* testsuite/Makefile.in: Likewise.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@219016 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog.gomp                        | 12 ++++++++
 libgomp/configure                             |  4 +--
 libgomp/configure.ac                          |  2 +-
 libgomp/testsuite/Makefile.am                 | 14 +++++++++
 libgomp/testsuite/Makefile.in                 | 41 ++++++++++++++++++---------
 libgomp/testsuite/libgomp-test-support.exp.in |  2 --
 6 files changed, 56 insertions(+), 19 deletions(-)

diff --git libgomp/ChangeLog.gomp libgomp/ChangeLog.gomp
index b7a0e7d..6653e58 100644
--- libgomp/ChangeLog.gomp
+++ libgomp/ChangeLog.gomp
@@ -1,3 +1,15 @@
+2014-12-22  Thomas Schwinge  <thomas@codesourcery.com>
+
+	* testsuite/libgomp-test-support.exp.in
+	(offload_additional_options, offload_additional_lib_paths): Don't
+	set.
+	* configure.ac: Instantiate testsuite/libgomp-test-support.pt.exp
+	instead of testsuite/libgomp-test-support.exp.
+	* testsuite/Makefile.am (libgomp-test-support.exp): New rule.
+	(all-local): Depend on it.
+	* configure: Regenerate.
+	* testsuite/Makefile.in: Likewise.
+
 2014-12-17  Thomas Schwinge  <thomas@codesourcery.com>
 	    Tom de Vries  <tom@codesourcery.com>
 
diff --git libgomp/configure libgomp/configure
index f72378e..839b2c6 100755
--- libgomp/configure
+++ libgomp/configure
@@ -16553,7 +16553,7 @@ ac_config_files="$ac_config_files omp.h omp_lib.h omp_lib.f90 libgomp_f.h"
 
 ac_config_files="$ac_config_files Makefile testsuite/Makefile libgomp.spec"
 
-ac_config_files="$ac_config_files testsuite/libgomp-test-support.exp"
+ac_config_files="$ac_config_files testsuite/libgomp-test-support.pt.exp:testsuite/libgomp-test-support.exp.in"
 
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
@@ -17699,7 +17699,7 @@ do
     "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
     "testsuite/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/Makefile" ;;
     "libgomp.spec") CONFIG_FILES="$CONFIG_FILES libgomp.spec" ;;
-    "testsuite/libgomp-test-support.exp") CONFIG_FILES="$CONFIG_FILES testsuite/libgomp-test-support.exp" ;;
+    "testsuite/libgomp-test-support.pt.exp") CONFIG_FILES="$CONFIG_FILES testsuite/libgomp-test-support.pt.exp:testsuite/libgomp-test-support.exp.in" ;;
 
   *) as_fn_error "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
   esac
diff --git libgomp/configure.ac libgomp/configure.ac
index 178c34d..4687b01 100644
--- libgomp/configure.ac
+++ libgomp/configure.ac
@@ -352,5 +352,5 @@ CFLAGS="$save_CFLAGS"
 
 AC_CONFIG_FILES(omp.h omp_lib.h omp_lib.f90 libgomp_f.h)
 AC_CONFIG_FILES(Makefile testsuite/Makefile libgomp.spec)
-AC_CONFIG_FILES([testsuite/libgomp-test-support.exp])
+AC_CONFIG_FILES([testsuite/libgomp-test-support.pt.exp:testsuite/libgomp-test-support.exp.in])
 AC_OUTPUT
diff --git libgomp/testsuite/Makefile.am libgomp/testsuite/Makefile.am
index 561b7e2..66a9d94 100644
--- libgomp/testsuite/Makefile.am
+++ libgomp/testsuite/Makefile.am
@@ -11,3 +11,17 @@ EXPECT = $(shell if test -f $(top_builddir)/../expect/expect; then \
 _RUNTEST = $(shell if test -f $(top_srcdir)/../dejagnu/runtest; then \
 	     echo $(top_srcdir)/../dejagnu/runtest; else echo runtest; fi)
 RUNTEST = "$(_RUNTEST) $(AM_RUNTESTFLAGS)"
+
+
+# Instead of directly in ../testsuite/libgomp-test-support.exp.in, the
+# following variables have to be "routed through" this Makefile, for expansion
+# of the several (Makefile) variables used therein.
+libgomp-test-support.exp: libgomp-test-support.pt.exp Makefile
+	cp $< $@.tmp
+	echo >> $@.tmp \
+	  'set offload_additional_options "$(offload_additional_options)"'
+	echo >> $@.tmp \
+	  'set offload_additional_lib_paths "$(offload_additional_lib_paths)"'
+	mv $@.tmp $@
+
+all-local: libgomp-test-support.exp
diff --git libgomp/testsuite/Makefile.in libgomp/testsuite/Makefile.in
index 016d0d4..352fc3f 100644
--- libgomp/testsuite/Makefile.in
+++ libgomp/testsuite/Makefile.in
@@ -56,7 +56,7 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
 	$(ACLOCAL_M4)
 mkinstalldirs = $(SHELL) $(top_srcdir)/../mkinstalldirs
 CONFIG_HEADER = $(top_builddir)/config.h
-CONFIG_CLEAN_FILES = libgomp-test-support.exp
+CONFIG_CLEAN_FILES = libgomp-test-support.pt.exp
 CONFIG_CLEAN_VPATH_FILES =
 SOURCES =
 DEJATOOL = $(PACKAGE)
@@ -258,7 +258,7 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
 $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 $(am__aclocal_m4_deps):
-libgomp-test-support.exp: $(top_builddir)/config.status $(srcdir)/libgomp-test-support.exp.in
+libgomp-test-support.pt.exp: $(top_builddir)/config.status $(srcdir)/libgomp-test-support.exp.in
 	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
 
 mostlyclean-libtool:
@@ -313,7 +313,7 @@ distclean-DEJAGNU:
 check-am: all-am
 	$(MAKE) $(AM_MAKEFLAGS) check-DEJAGNU
 check: check-am
-all-am: Makefile
+all-am: Makefile all-local
 installdirs:
 install: install-am
 install-exec: install-exec-am
@@ -408,19 +408,32 @@ uninstall-am:
 
 .MAKE: check-am install-am install-strip
 
-.PHONY: all all-am check check-DEJAGNU check-am clean clean-generic \
-	clean-libtool distclean distclean-DEJAGNU distclean-generic \
-	distclean-libtool dvi dvi-am html html-am info info-am install \
-	install-am install-data install-data-am install-dvi \
-	install-dvi-am install-exec install-exec-am install-html \
-	install-html-am install-info install-info-am install-man \
-	install-pdf install-pdf-am install-ps install-ps-am \
-	install-strip installcheck installcheck-am installdirs \
-	maintainer-clean maintainer-clean-generic mostlyclean \
-	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
-	uninstall uninstall-am
+.PHONY: all all-am all-local check check-DEJAGNU check-am clean \
+	clean-generic clean-libtool distclean distclean-DEJAGNU \
+	distclean-generic distclean-libtool dvi dvi-am html html-am \
+	info info-am install install-am install-data install-data-am \
+	install-dvi install-dvi-am install-exec install-exec-am \
+	install-html install-html-am install-info install-info-am \
+	install-man install-pdf install-pdf-am install-ps \
+	install-ps-am install-strip installcheck installcheck-am \
+	installdirs maintainer-clean maintainer-clean-generic \
+	mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \
+	ps ps-am uninstall uninstall-am
 
 
+# Instead of directly in ../testsuite/libgomp-test-support.exp.in, the
+# following variables have to be "routed through" this Makefile, for expansion
+# of the several (Makefile) variables used therein.
+libgomp-test-support.exp: libgomp-test-support.pt.exp Makefile
+	cp $< $@.tmp
+	echo >> $@.tmp \
+	  'set offload_additional_options "$(offload_additional_options)"'
+	echo >> $@.tmp \
+	  'set offload_additional_lib_paths "$(offload_additional_lib_paths)"'
+	mv $@.tmp $@
+
+all-local: libgomp-test-support.exp
+
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
diff --git libgomp/testsuite/libgomp-test-support.exp.in libgomp/testsuite/libgomp-test-support.exp.in
index 4586fbe..764bec0 100644
--- libgomp/testsuite/libgomp-test-support.exp.in
+++ libgomp/testsuite/libgomp-test-support.exp.in
@@ -2,5 +2,3 @@ set cuda_driver_include "@CUDA_DRIVER_INCLUDE@"
 set cuda_driver_lib "@CUDA_DRIVER_LIB@"
 
 set offload_targets "@offload_targets@"
-set offload_additional_options "@offload_additional_options@"
-set offload_additional_lib_paths "@offload_additional_lib_paths@"


Grüße,
 Thomas

[-- Attachment #2: Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2014-12-22 11:28         ` Jakub Jelinek
@ 2014-12-26 15:49           ` Ilya Verbin
  2015-01-08 15:42             ` Thomas Schwinge
  0 siblings, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2014-12-26 15:49 UTC (permalink / raw)
  To: Thomas Schwinge
  Cc: Jakub Jelinek, gcc-patches, Kirill Yukhin, Andrey Turetskiy,
	Bernd Schmidt

On 22 Dec 12:26, Jakub Jelinek wrote:
> On Mon, Dec 22, 2014 at 12:20:58PM +0100, Thomas Schwinge wrote:
> > What is the reason that you're adding -fopenmp here?  I assume it is that
> > otherwise you'd get tree streaming errors because of different builtins
> > configurations, like this?
> > 
> > If that is the "only" reason to add -fopenmp there, can we then instead
> > do the following?
> > 
> >  gcc/builtins.def                     | 8 ++++++--
> >  gcc/config/i386/intelmic-mkoffload.c | 1 -
> >  2 files changed, 6 insertions(+), 3 deletions(-)
> 
> If Ilya confirms that is the sole reason, I'm fine with this change.
> Please write ChangeLog entry for it.
> 
> 	Jakub

Ok to me.

Thanks,
  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-12-22 11:49       ` Thomas Schwinge
  2014-12-22 12:50         ` Jakub Jelinek
@ 2014-12-26 20:53         ` Ilya Verbin
  2015-01-08 16:03           ` Thomas Schwinge
  1 sibling, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2014-12-26 20:53 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: Jakub Jelinek, Kirill Yukhin, Andrey Turetskiy, gcc

On 22 Dec 12:48, Thomas Schwinge wrote:
> What is the reason for adding paths if $tgt_dir is empty?  (I mean, if
> properly installed and $tgt_dir empty, this should just work, because
> that's what a user will be doing, so why does the libgomp testsuite have
> to do differently?)

The case for empty $tgt_dir is required when offload compiler is installed, but
host compiler isn't.

> These paths will (basically) point to GCC's
> configured --prefix=[...] -- which may not actually match where the
> installed offloading compilers are to be found, for example, in the
> common case that DESTDIR is used with make install.  And, isn't it that
> GCC by default will already be looking into "$prefix" installation
> directories, or is this solving an actual problem for you?  If not, is it
> then OK to remove the cases for empty $tgt_dir?

If DESTDIR is used, then $tgt_dir can not be empty, otherwise during the build
of host compiler the host's part of MIC plugin for libgomp will not find
target's part, which is built along with target compiler.

> Here is a patch to correctly match intelmic in $offload_targets; OK to
> commit, I assume?  I suppose I'm the first one to ever do build-tree
> testing?  (Jakub?)
> 
> --- libgomp/testsuite/lib/libgomp.exp
> +++ libgomp/testsuite/lib/libgomp.exp
> @@ -115,8 +115,7 @@ proc libgomp_init { args } {
>  
>      # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
>      # non-fallback testing for Intel MIC targets
> -    if { [string match "*-intelmic-*" $offload_targets]
> -	|| [string match "*-intelmicemul-*" $offload_targets] } {
> +    if { [string match "*,intelmic,*" ",$offload_targets,"] } {
>  	append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
>  	append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
>  	# libstdc++ is required by liboffloadmic

OK, thanks.
I verified this case some time ago, but missed when it started failing, since
tests just become UNSUPPORTED or PASSED with host fallback, rather than FAILing.

> Here is a patch to fix 32-bit x86 Intel MIC offloading; OK to commit, I
> assume?
> 
>     $ find -name liboffloadmic_target.so.5
>     ./install/offload-x86_64-intelmicemul-linux-gnu/lib64/liboffloadmic_target.so.5
>     ./install/offload-x86_64-intelmicemul-linux-gnu/lib32/liboffloadmic_target.so.5
>     ./build-gcc-offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/32/liboffloadmic/.libs/liboffloadmic_target.so.5
>     ./build-gcc-offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/liboffloadmic/.libs/liboffloadmic_target.so.5
> 
> --- libgomp/configure.ac
> +++ libgomp/configure.ac
> @@ -304,7 +304,7 @@ if test x"$enable_offload_targets" != x; then
>      fi
>      if test x"$tgt_dir" != x; then
>        offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
> -      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib"
> +      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
>      else
>        offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
>        offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"

OK, thanks.

  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2014-12-12  9:42                   ` Thomas Schwinge
@ 2015-01-08 14:48                     ` Thomas Schwinge
  0 siblings, 0 replies; 111+ messages in thread
From: Thomas Schwinge @ 2015-01-08 14:48 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: text/plain, Size: 4775 bytes --]

Hi!

On Fri, 12 Dec 2014 10:42:30 +0100, I wrote:
> On Mon, 10 Nov 2014 17:30:38 +0300, Ilya Verbin <iverbin@gmail.com> wrote:
> > --- /dev/null
> > +++ b/liboffloadmic/plugin/Makefile.am
> > @@ -0,0 +1,123 @@
> > +# Plugin for offload execution on Intel MIC devices.

> > +  AM_LDFLAGS = -L$(liboffload_dir)/.libs -L$(libgomp_dir)/.libs -loffloadmic_target -lcoi_device -lmyo-service -lgomp -rdynamic
> 
> Given that this plugin wishes to link against libgomp, don't we have to
> make sure that libgomp has actually been built before that is attempted,
> and the following (untested) patch would be required?

As shown by a »make -j1« build: yes, we have to.  As obvious, committed
to trunk in r219344:

commit fb5eef67f6b041cd0bc4f1f8d62c1a000d59f497
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Jan 8 14:46:22 2015 +0000

    liboffloadmic/plugin: Depend on libgomp being built.
    
        [...]
        Making all in plugin
        make[6]: Entering directory `[...]/build-gcc-offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/32/liboffloadmic/plugin'
        [...]
        [...]/build-gcc-offload-x86_64-intelmicemul-linux-gnu/./gcc/xg++ -B[...]/build-gcc-offload-x86_64-intelmicemul-linux-gnu/./gcc/ -nostdinc++ -nostdinc++ -I[...]/build-gcc-offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/32/libstdc++-v3/include/x86_64-intelmicemul-linux-gnu -I[...]/build-gcc-offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/32/libstdc++-v3/include -I[...]/source-gcc/libstdc++-v3/libsupc++ -I[...]/source-gcc/libstdc++-v3/include/backward -I[...]/source-gcc/libstdc++-v3/testsuite/util -L[...]/build-gcc-offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/32/libstdc++-v3/src -L[...]/build-gcc-offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/32/libstdc++-v3/src/.libs -L[...]/build-gcc-offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/32/libstdc++-v3/libsupc++/.libs -B/x86_64-intelmicemul-linux-gnu/bin/ -B/x86_64-intelmicemul-linux-gnu/lib/ -isystem /x86_64-intelmicemul-linux-gnu/include -isystem /x86_64-intelmicemul-linux-gnu/sys-include  -m32 -L./../.libs -L./../../libgomp/.libs -loffloadmic_target -lcoi_device -lmyo-service -lgomp -rdynamic ../ofldbegin.o offload_target_main.o ../ofldend.o -o offload_target_main
        /usr/bin/ld: cannot find -lgomp
        collect2: error: ld returned 1 exit status
    
    	* Makefile.def (dependencies) <all-target-liboffloadmic>: Depend on
    	all-target-libgomp.
    	* Makefile.in: Regenerate.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219344 138bc75d-0d04-0410-961f-82ee72b054a4
---
 ChangeLog    | 6 ++++++
 Makefile.def | 2 +-
 Makefile.in  | 2 +-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git ChangeLog ChangeLog
index 325f4cc..9012087 100644
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,9 @@
+2015-01-08  Thomas Schwinge  <thomas@codesourcery.com>
+
+	* Makefile.def (dependencies) <all-target-liboffloadmic>: Depend on
+	all-target-libgomp.
+	* Makefile.in: Regenerate.
+
 2015-01-06  Eric Botcazou  <ebotcazou@adacore.com>
 
 	* MAINTAINERS (CPU Port Maintainers): Add myself for Visium port.
diff --git Makefile.def Makefile.def
index ffab409..15ab613 100644
--- Makefile.def
+++ Makefile.def
@@ -551,7 +551,7 @@ dependencies = { module=configure-target-libvtv; on=all-target-libstdc++-v3; };
 // generated by the libgomp configure.  Unfortunately, due to the use of
 //  recursive make, we can't be that specific.
 dependencies = { module=all-target-libstdc++-v3; on=configure-target-libgomp; };
-dependencies = { module=all-target-liboffloadmic; on=configure-target-libgomp; };
+dependencies = { module=all-target-liboffloadmic; on=all-target-libgomp; };
 
 dependencies = { module=install-target-libgo; on=install-target-libatomic; };
 dependencies = { module=install-target-libgfortran; on=install-target-libquadmath; };
diff --git Makefile.in Makefile.in
index 7355bf1..428898a 100644
--- Makefile.in
+++ Makefile.in
@@ -48893,7 +48893,7 @@ all-stage3-target-libstdc++-v3: maybe-configure-stage3-target-libgomp
 all-stage4-target-libstdc++-v3: maybe-configure-stage4-target-libgomp
 all-stageprofile-target-libstdc++-v3: maybe-configure-stageprofile-target-libgomp
 all-stagefeedback-target-libstdc++-v3: maybe-configure-stagefeedback-target-libgomp
-all-target-liboffloadmic: maybe-configure-target-libgomp
+all-target-liboffloadmic: maybe-all-target-libgomp
 install-target-libgo: maybe-install-target-libatomic
 install-target-libgfortran: maybe-install-target-libquadmath
 install-target-libgfortran: maybe-install-target-libgcc


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2014-12-22 11:48         ` Jakub Jelinek
@ 2015-01-08 14:59           ` Thomas Schwinge
  2015-01-08 15:02             ` H.J. Lu
  0 siblings, 1 reply; 111+ messages in thread
From: Thomas Schwinge @ 2015-01-08 14:59 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Ilya Verbin, gcc-patches, Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: text/plain, Size: 3700 bytes --]

Hi!

On Mon, 22 Dec 2014 12:28:20 +0100, Jakub Jelinek <jakub@redhat.com> wrote:
> On Mon, Dec 22, 2014 at 12:25:32PM +0100, Thomas Schwinge wrote:
> > On Wed, 22 Oct 2014 22:57:01 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> > > --- /dev/null
> > > +++ b/gcc/config/i386/intelmic-mkoffload.c
> > > @@ -0,0 +1,541 @@
> > > +/* Offload image generation tool for Intel MIC devices.
> > 
> > > +/* Shows if we should compile binaries for i386 instead of x86-64.  */
> > > +bool target_ilp32 = false;
> > 
> > My linker defaults to 32-bit x86, so I explicitly have to switch to
> > 64-bit x86_64 mode; OK to commit the following, to always explicitly
> > specify what is wanted?
> > 
> >  gcc/config/i386/intelmic-mkoffload.c | 12 ++++++++----
> >  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> Ok with proper ChangeLog entry.

Committed to trunk in r219345:

commit c049b358f961f72d0c0cf61a707e9a5855b12b28
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Jan 8 14:58:45 2015 +0000

    intelmic-mkoffload: Deal with linker defaulting to 32-bit x86 mode.
    
    ... which explicitly has to be switched into 64-bit x86_64 mode.
    
    	gcc/
    	* config/i386/intelmic-mkoffload.c (compile_for_target): Always
    	add "-m32" or "-m64" to argv_obstack.
    	(generate_host_descr_file): Likewise, when invoking host_compiler.
    	(main): Always add "-m elf_i386" or "-m elf_x86_64" when invoking
    	ld.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219345 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog                        |  8 ++++++++
 gcc/config/i386/intelmic-mkoffload.c | 12 ++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git gcc/ChangeLog gcc/ChangeLog
index bee5f1e..01b6cc6 100644
--- gcc/ChangeLog
+++ gcc/ChangeLog
@@ -1,3 +1,11 @@
+2015-01-08  Thomas Schwinge  <thomas@codesourcery.com>
+
+	* config/i386/intelmic-mkoffload.c (compile_for_target): Always
+	add "-m32" or "-m64" to argv_obstack.
+	(generate_host_descr_file): Likewise, when invoking host_compiler.
+	(main): Always add "-m elf_i386" or "-m elf_x86_64" when invoking
+	ld.
+
 2015-01-08  Oleg Endo  <olegendo@gcc.gnu.org>
 
 	* config/sh/sh-mem.cc: Use constant as second operand when emitting
diff --git gcc/config/i386/intelmic-mkoffload.c gcc/config/i386/intelmic-mkoffload.c
index c3d2b23..23bc955 100644
--- gcc/config/i386/intelmic-mkoffload.c
+++ gcc/config/i386/intelmic-mkoffload.c
@@ -191,6 +191,8 @@ compile_for_target (struct obstack *argv_obstack)
 {
   if (target_ilp32)
     obstack_ptr_grow (argv_obstack, "-m32");
+  else
+    obstack_ptr_grow (argv_obstack, "-m64");
   obstack_ptr_grow (argv_obstack, NULL);
   char **argv = XOBFINISH (argv_obstack, char **);
 
@@ -355,6 +357,8 @@ generate_host_descr_file (const char *host_compiler)
   new_argv[new_argc++] = "-shared";
   if (target_ilp32)
     new_argv[new_argc++] = "-m32";
+  else
+    new_argv[new_argc++] = "-m64";
   new_argv[new_argc++] = src_filename;
   new_argv[new_argc++] = "-o";
   new_argv[new_argc++] = obj_filename;
@@ -511,11 +515,11 @@ main (int argc, char **argv)
   unsigned new_argc = 0;
   const char *new_argv[9];
   new_argv[new_argc++] = "ld";
+  new_argv[new_argc++] = "-m";
   if (target_ilp32)
-    {
-      new_argv[new_argc++] = "-m";
-      new_argv[new_argc++] = "elf_i386";
-    }
+    new_argv[new_argc++] = "elf_i386";
+  else
+    new_argv[new_argc++] = "elf_x86_64";
   new_argv[new_argc++] = "--relocatable";
   new_argv[new_argc++] = host_descr_filename;
   new_argv[new_argc++] = target_so_filename;


Grüße,
 Thomas

[-- Attachment #2: Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2015-01-08 14:59           ` Thomas Schwinge
@ 2015-01-08 15:02             ` H.J. Lu
  2015-01-08 16:21               ` Thomas Schwinge
  2015-08-04 11:20               ` Use gcc/coretypes.h:enum offload_abi in mkoffloads (was: [PATCH 1/4] Add mkoffload for Intel MIC) Thomas Schwinge
  0 siblings, 2 replies; 111+ messages in thread
From: H.J. Lu @ 2015-01-08 15:02 UTC (permalink / raw)
  To: Thomas Schwinge
  Cc: Jakub Jelinek, Ilya Verbin, GCC Patches, Kirill Yukhin, Andrey Turetskiy

On Thu, Jan 8, 2015 at 6:59 AM, Thomas Schwinge <thomas@codesourcery.com> wrote:
> Hi!
>
> On Mon, 22 Dec 2014 12:28:20 +0100, Jakub Jelinek <jakub@redhat.com> wrote:
>> On Mon, Dec 22, 2014 at 12:25:32PM +0100, Thomas Schwinge wrote:
>> > On Wed, 22 Oct 2014 22:57:01 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
>> > > --- /dev/null
>> > > +++ b/gcc/config/i386/intelmic-mkoffload.c
>> > > @@ -0,0 +1,541 @@
>> > > +/* Offload image generation tool for Intel MIC devices.
>> >
>> > > +/* Shows if we should compile binaries for i386 instead of x86-64.  */
>> > > +bool target_ilp32 = false;
>> >
>> > My linker defaults to 32-bit x86, so I explicitly have to switch to
>> > 64-bit x86_64 mode; OK to commit the following, to always explicitly
>> > specify what is wanted?
>> >
>> >  gcc/config/i386/intelmic-mkoffload.c | 12 ++++++++----
>> >  1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> Ok with proper ChangeLog entry.
>
> Committed to trunk in r219345:
>
> commit c049b358f961f72d0c0cf61a707e9a5855b12b28
> Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
> Date:   Thu Jan 8 14:58:45 2015 +0000
>
>     intelmic-mkoffload: Deal with linker defaulting to 32-bit x86 mode.
>
>     ... which explicitly has to be switched into 64-bit x86_64 mode.
>
>         gcc/
>         * config/i386/intelmic-mkoffload.c (compile_for_target): Always
>         add "-m32" or "-m64" to argv_obstack.
>         (generate_host_descr_file): Likewise, when invoking host_compiler.
>         (main): Always add "-m elf_i386" or "-m elf_x86_64" when invoking
>         ld.
>
>     git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219345 138bc75d-0d04-0410-961f-82ee72b054a4
> ---
>  gcc/ChangeLog                        |  8 ++++++++
>  gcc/config/i386/intelmic-mkoffload.c | 12 ++++++++----
>  2 files changed, 16 insertions(+), 4 deletions(-)
>
> diff --git gcc/ChangeLog gcc/ChangeLog
> index bee5f1e..01b6cc6 100644
> --- gcc/ChangeLog
> +++ gcc/ChangeLog
> @@ -1,3 +1,11 @@
> +2015-01-08  Thomas Schwinge  <thomas@codesourcery.com>
> +
> +       * config/i386/intelmic-mkoffload.c (compile_for_target): Always
> +       add "-m32" or "-m64" to argv_obstack.
> +       (generate_host_descr_file): Likewise, when invoking host_compiler.
> +       (main): Always add "-m elf_i386" or "-m elf_x86_64" when invoking
> +       ld.
> +
>  2015-01-08  Oleg Endo  <olegendo@gcc.gnu.org>
>
>         * config/sh/sh-mem.cc: Use constant as second operand when emitting
> diff --git gcc/config/i386/intelmic-mkoffload.c gcc/config/i386/intelmic-mkoffload.c
> index c3d2b23..23bc955 100644
> --- gcc/config/i386/intelmic-mkoffload.c
> +++ gcc/config/i386/intelmic-mkoffload.c
> @@ -191,6 +191,8 @@ compile_for_target (struct obstack *argv_obstack)
>  {
>    if (target_ilp32)
>      obstack_ptr_grow (argv_obstack, "-m32");
> +  else
> +    obstack_ptr_grow (argv_obstack, "-m64");
>    obstack_ptr_grow (argv_obstack, NULL);
>    char **argv = XOBFINISH (argv_obstack, char **);
>
> @@ -355,6 +357,8 @@ generate_host_descr_file (const char *host_compiler)
>    new_argv[new_argc++] = "-shared";
>    if (target_ilp32)
>      new_argv[new_argc++] = "-m32";
> +  else
> +    new_argv[new_argc++] = "-m64";
>    new_argv[new_argc++] = src_filename;
>    new_argv[new_argc++] = "-o";
>    new_argv[new_argc++] = obj_filename;
> @@ -511,11 +515,11 @@ main (int argc, char **argv)
>    unsigned new_argc = 0;
>    const char *new_argv[9];
>    new_argv[new_argc++] = "ld";
> +  new_argv[new_argc++] = "-m";
>    if (target_ilp32)
> -    {
> -      new_argv[new_argc++] = "-m";
> -      new_argv[new_argc++] = "elf_i386";
> -    }
> +    new_argv[new_argc++] = "elf_i386";
> +  else
> +    new_argv[new_argc++] = "elf_x86_64";
>    new_argv[new_argc++] = "--relocatable";
>    new_argv[new_argc++] = host_descr_filename;
>    new_argv[new_argc++] = target_so_filename;
>
>

Should we also handle x32?

-- 
H.J.

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2014-12-26 15:49           ` Ilya Verbin
@ 2015-01-08 15:42             ` Thomas Schwinge
  2015-01-08 15:49               ` Jakub Jelinek
  2021-08-04  9:46               ` OMP builtins in offloading Thomas Schwinge
  0 siblings, 2 replies; 111+ messages in thread
From: Thomas Schwinge @ 2015-01-08 15:42 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek
  Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy, Bernd Schmidt

[-- Attachment #1: Type: text/plain, Size: 3941 bytes --]

Hi!

On Fri, 26 Dec 2014 16:22:43 +0300, Ilya Verbin <iverbin@gmail.com> wrote:
> On 22 Dec 12:26, Jakub Jelinek wrote:
> > On Mon, Dec 22, 2014 at 12:20:58PM +0100, Thomas Schwinge wrote:
> > > What is the reason that you're adding -fopenmp here?  I assume it is that
> > > otherwise you'd get tree streaming errors because of different builtins
> > > configurations, like this?
> > > 
> > > If that is the "only" reason to add -fopenmp there, can we then instead
> > > do the following?
> > > 
> > >  gcc/builtins.def                     | 8 ++++++--
> > >  gcc/config/i386/intelmic-mkoffload.c | 1 -
> > >  2 files changed, 6 insertions(+), 3 deletions(-)
> > 
> > If Ilya confirms that is the sole reason, I'm fine with this change.
> > Please write ChangeLog entry for it.
> 
> Ok to me.

Committed to trunk in r219346:

commit 752cfdfdd758616a0fee3071d33e4add83f34a51
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Jan 8 15:41:13 2015 +0000

    Make sure that OMP builtins are available in offloading compilers.
    
    	gcc/
    	* builtins.def (DEF_GOMP_BUILTIN): Also consider flag_offload_abi
    	for registering builtins.
    	* config/i386/intelmic-mkoffload.c (prepare_target_image): Don't
    	add -fopenmp to the argv_obstack used when invoking
    	compile_for_target.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219346 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog                        | 6 ++++++
 gcc/builtins.def                     | 5 ++++-
 gcc/config/i386/intelmic-mkoffload.c | 1 -
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git gcc/ChangeLog gcc/ChangeLog
index 01b6cc6..5bc6591 100644
--- gcc/ChangeLog
+++ gcc/ChangeLog
@@ -1,5 +1,11 @@
 2015-01-08  Thomas Schwinge  <thomas@codesourcery.com>
 
+	* builtins.def (DEF_GOMP_BUILTIN): Also consider flag_offload_abi
+	for registering builtins.
+	* config/i386/intelmic-mkoffload.c (prepare_target_image): Don't
+	add -fopenmp to the argv_obstack used when invoking
+	compile_for_target.
+
 	* config/i386/intelmic-mkoffload.c (compile_for_target): Always
 	add "-m32" or "-m64" to argv_obstack.
 	(generate_host_descr_file): Likewise, when invoking host_compiler.
diff --git gcc/builtins.def gcc/builtins.def
index 28b1646..5a7ed10 100644
--- gcc/builtins.def
+++ gcc/builtins.def
@@ -148,11 +148,14 @@ along with GCC; see the file COPYING3.  If not see
 
 /* Builtin used by the implementation of GNU OpenMP.  None of these are
    actually implemented in the compiler; they're all in libgomp.  */
+/* These builtins also need to be enabled in offloading compilers invoked from
+   mkoffload; for that purpose, we're checking the -foffload-abi flag here.  */
 #undef DEF_GOMP_BUILTIN
 #define DEF_GOMP_BUILTIN(ENUM, NAME, TYPE, ATTRS) \
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,    \
                false, true, true, ATTRS, false, \
-	       (flag_openmp || flag_tree_parallelize_loops))
+	       (flag_openmp || flag_tree_parallelize_loops \
+		|| flag_offload_abi != OFFLOAD_ABI_UNSET))
 
 /* Builtin used by implementation of Cilk Plus.  Most of these are decomposed
    by the compiler but a few are implemented in libcilkrts.  */ 
diff --git gcc/config/i386/intelmic-mkoffload.c gcc/config/i386/intelmic-mkoffload.c
index 23bc955..050f2e6 100644
--- gcc/config/i386/intelmic-mkoffload.c
+++ gcc/config/i386/intelmic-mkoffload.c
@@ -390,7 +390,6 @@ prepare_target_image (const char *target_compiler, int argc, char **argv)
   obstack_init (&argv_obstack);
   obstack_ptr_grow (&argv_obstack, target_compiler);
   obstack_ptr_grow (&argv_obstack, "-xlto");
-  obstack_ptr_grow (&argv_obstack, "-fopenmp");
   obstack_ptr_grow (&argv_obstack, "-shared");
   obstack_ptr_grow (&argv_obstack, "-fPIC");
   obstack_ptr_grow (&argv_obstack, opt1);


Grüße,
 Thomas

[-- Attachment #2: Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2015-01-08 15:42             ` Thomas Schwinge
@ 2015-01-08 15:49               ` Jakub Jelinek
  2015-01-08 16:32                 ` Ilya Verbin
  2015-02-16 18:58                 ` Ilya Verbin
  2021-08-04  9:46               ` OMP builtins in offloading Thomas Schwinge
  1 sibling, 2 replies; 111+ messages in thread
From: Jakub Jelinek @ 2015-01-08 15:49 UTC (permalink / raw)
  To: Thomas Schwinge
  Cc: Ilya Verbin, gcc-patches, Kirill Yukhin, Andrey Turetskiy, Bernd Schmidt

Hi!

On Thu, Jan 08, 2015 at 04:41:50PM +0100, Thomas Schwinge wrote:
> On Fri, 26 Dec 2014 16:22:43 +0300, Ilya Verbin <iverbin@gmail.com> wrote:

BTW, today when looking at the TARGET_OPTION_NODE streaming caused
regressions, I've discovered that it is very hard to debug issues in the
offloading compiler.  Would be nice if
-save-temps -v
printed enough information that it is actually possible to reproduce it,
e.g. while mkoffload command is printed, one can't cut and paste it easily,
because some env vars are required and those aren't printed in the -v dump.
Similarly, the lto1 offloading compiler invocation is not printed, and
wrapping offloading compiler's lto1 into a script that runs gdb on it
doesn't work, because stdout/stderr (and stdin) is redirected.

This is something that can be solved during stage4, but would be really nice
if it wasn't terribly hard to debug stuff.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-12-26 20:53         ` Ilya Verbin
@ 2015-01-08 16:03           ` Thomas Schwinge
  0 siblings, 0 replies; 111+ messages in thread
From: Thomas Schwinge @ 2015-01-08 16:03 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: Jakub Jelinek, Kirill Yukhin, Andrey Turetskiy, gcc

[-- Attachment #1: Type: text/plain, Size: 8328 bytes --]

Hi!

On Fri, 26 Dec 2014 22:15:24 +0300, Ilya Verbin <iverbin@gmail.com> wrote:
> On 22 Dec 12:48, Thomas Schwinge wrote:
> > Here is a patch to correctly match intelmic in $offload_targets; OK to
> > commit, I assume?  I suppose I'm the first one to ever do build-tree
> > testing?  (Jakub?)

> OK, thanks.
> I verified this case some time ago, but missed when it started failing, since
> tests just become UNSUPPORTED or PASSED with host fallback, rather than FAILing.

Yeah.  (I diff the *.sum files, so I do see such regressions.)  Committed
to trunk in r219348:

commit b21c795fa27f6fcefdb38d1bc50f1d1634f4e0b3
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Jan 8 16:01:24 2015 +0000

    libgomp: Fix "intelmic" offloading in build-tree testing.
    
    	libgomp/
    	* testsuite/lib/libgomp.exp (libgomp_init): Correctly match
    	"intelmic" in $offload_targets.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219348 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog                 | 5 +++++
 libgomp/testsuite/lib/libgomp.exp | 3 +--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git libgomp/ChangeLog libgomp/ChangeLog
index afbde87..beecba9 100644
--- libgomp/ChangeLog
+++ libgomp/ChangeLog
@@ -1,3 +1,8 @@
+2015-01-08  Thomas Schwinge  <thomas@codesourcery.com>
+
+	* testsuite/lib/libgomp.exp (libgomp_init): Correctly match
+	"intelmic" in $offload_targets.
+
 2015-01-05  Jakub Jelinek  <jakub@redhat.com>
 
 	Update copyright years.
diff --git libgomp/testsuite/lib/libgomp.exp libgomp/testsuite/lib/libgomp.exp
index ff22f10..2d6f822 100644
--- libgomp/testsuite/lib/libgomp.exp
+++ libgomp/testsuite/lib/libgomp.exp
@@ -115,8 +115,7 @@ proc libgomp_init { args } {
 
     # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
     # non-fallback testing for Intel MIC targets
-    if { [string match "*-intelmic-*" $offload_targets]
-	|| [string match "*-intelmicemul-*" $offload_targets] } {
+    if { [string match "*,intelmic,*" ",$offload_targets,"] } {
 	append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
 	append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
 	# libstdc++ is required by liboffloadmic


> > Here is a patch to fix 32-bit x86 Intel MIC offloading; OK to commit, I
> > assume?

> OK, thanks.

Committed to trunk in r219349:

commit 49b6c472197cbb443c55cc1064de5b24384bbf7f
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Jan 8 16:01:37 2015 +0000

    libgomp: Fix 32-bit x86 Intel MIC offloading testing.
    
        [...]
        spawn [...]/build-gcc/gcc/xgcc -B[...]/build-gcc/gcc/ [...]/source-gcc/libgomp/testsuite/libgomp.c/examples-4/e.50.1.c -B[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/ -B[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/.libs -I[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp -I[...]/source-gcc/libgomp/testsuite/.. -march=i486 -fmessage-length=0 -fno-diagnostics-show-caret -fdiagnostics-color=never -B[...]/install/offload-x86_64-intelmicemul-linux-gnu/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0 -B[...]/install/offload-x86_64-intelmicemul-linux-gnu/bin -fopenmp -O2 -L[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/.libs -lm -m32 -o ./e.50.1.exe
        PASS: libgomp.c/examples-4/e.50.1.c (test for excess errors)
        Setting LD_LIBRARY_PATH to .:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/../liboffloadmic/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/../liboffloadmic/plugin/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/../libstdc++-v3/src/.libs:[...]/install/offload-x86_64-intelmicemul-linux-gnu/lib64:[...]/install/offload-x86_64-intelmicemul-linux-gnu/lib:[...]/build-gcc/gcc:[...]/build-gcc/gcc/32:.:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/../liboffloadmic/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/../liboffloadmic/plugin/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/32/libgomp/../libstdc++-v3/src/.libs:[...]/install/offload-x86_64-intelmicemul-linux-gnu/lib64:[...]/install/offload-x86_64-intelmicemul-linux-gnu/lib:[...]/build-gcc/gcc:[...]/build-gcc/gcc/32:[...]/build-gcc/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libsanitizer/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libvtv/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libcilkrts/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/liboffloadmic/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libssp/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libgomp/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libitm/.libs:[...]/build-gcc/x86_64-unknown-linux-gnu/libatomic/.libs:[...]/build-gcc/./gcc:[...]/build-gcc/./prev-gcc
        spawn [open ...]
        /tmp/offload_WCXKRZ/offload_target_main: error while loading shared libraries: liboffloadmic_target.so.5: wrong ELF class: ELFCLASS64
        WARNING: program timed out.
        FAIL: libgomp.c/examples-4/e.50.1.c execution test
        [...]
    
        $ find -name liboffloadmic_target.so.5
        ./install/offload-x86_64-intelmicemul-linux-gnu/lib64/liboffloadmic_target.so.5
        ./install/offload-x86_64-intelmicemul-linux-gnu/lib32/liboffloadmic_target.so.5
        ./build-gcc-offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/32/liboffloadmic/.libs/liboffloadmic_target.so.5
        ./build-gcc-offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/liboffloadmic/.libs/liboffloadmic_target.so.5
    
    This is a "standard" GCC configuration: x86_64-intelmicemul-linux-gnu with
    (default) multilibs enabled.
    
    	libgomp/
    	* configure.ac [tgt_dir] (offload_additional_lib_paths): Also add
    	"$tgt_dir/lib32".
    	* configure: Regenerate.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219349 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog    | 4 ++++
 libgomp/configure    | 2 +-
 libgomp/configure.ac | 2 +-
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git libgomp/ChangeLog libgomp/ChangeLog
index beecba9..11e0086 100644
--- libgomp/ChangeLog
+++ libgomp/ChangeLog
@@ -1,5 +1,9 @@
 2015-01-08  Thomas Schwinge  <thomas@codesourcery.com>
 
+	* configure.ac [tgt_dir] (offload_additional_lib_paths): Also add
+	"$tgt_dir/lib32".
+	* configure: Regenerate.
+
 	* testsuite/lib/libgomp.exp (libgomp_init): Correctly match
 	"intelmic" in $offload_targets.
 
diff --git libgomp/configure libgomp/configure
index f5d6b6b..d109fc1 100755
--- libgomp/configure
+++ libgomp/configure
@@ -16262,7 +16262,7 @@ if test x"$enable_offload_targets" != x; then
     fi
     if test x"$tgt_dir" != x; then
       offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
-      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib"
+      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
     else
       offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
       offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"
diff --git libgomp/configure.ac libgomp/configure.ac
index 16ec158..c8a98f0 100644
--- libgomp/configure.ac
+++ libgomp/configure.ac
@@ -304,7 +304,7 @@ if test x"$enable_offload_targets" != x; then
     fi
     if test x"$tgt_dir" != x; then
       offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
-      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib"
+      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
     else
       offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
       offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"


Grüße,
 Thomas

[-- Attachment #2: Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2015-01-08 15:02             ` H.J. Lu
@ 2015-01-08 16:21               ` Thomas Schwinge
  2015-08-04 11:20               ` Use gcc/coretypes.h:enum offload_abi in mkoffloads (was: [PATCH 1/4] Add mkoffload for Intel MIC) Thomas Schwinge
  1 sibling, 0 replies; 111+ messages in thread
From: Thomas Schwinge @ 2015-01-08 16:21 UTC (permalink / raw)
  To: H.J. Lu
  Cc: Jakub Jelinek, Ilya Verbin, GCC Patches, Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: text/plain, Size: 2660 bytes --]

Hi!

On Thu, 8 Jan 2015 07:02:19 -0800, "H.J. Lu" <hjl.tools@gmail.com> wrote:
> On Thu, Jan 8, 2015 at 6:59 AM, Thomas Schwinge <thomas@codesourcery.com> wrote:
> > commit c049b358f961f72d0c0cf61a707e9a5855b12b28
> > Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
> > Date:   Thu Jan 8 14:58:45 2015 +0000
> >
> >     intelmic-mkoffload: Deal with linker defaulting to 32-bit x86 mode.
> >
> >     ... which explicitly has to be switched into 64-bit x86_64 mode.
> >
> >         gcc/
> >         * config/i386/intelmic-mkoffload.c (compile_for_target): Always
> >         add "-m32" or "-m64" to argv_obstack.
> >         (generate_host_descr_file): Likewise, when invoking host_compiler.
> >         (main): Always add "-m elf_i386" or "-m elf_x86_64" when invoking
> >         ld.
> >
> >     git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219345 138bc75d-0d04-0410-961f-82ee72b054a4

> > --- gcc/config/i386/intelmic-mkoffload.c
> > +++ gcc/config/i386/intelmic-mkoffload.c
> > @@ -191,6 +191,8 @@ compile_for_target (struct obstack *argv_obstack)
> >  {
> >    if (target_ilp32)
> >      obstack_ptr_grow (argv_obstack, "-m32");
> > +  else
> > +    obstack_ptr_grow (argv_obstack, "-m64");
> >    obstack_ptr_grow (argv_obstack, NULL);
> >    char **argv = XOBFINISH (argv_obstack, char **);
> >
> > @@ -355,6 +357,8 @@ generate_host_descr_file (const char *host_compiler)
> >    new_argv[new_argc++] = "-shared";
> >    if (target_ilp32)
> >      new_argv[new_argc++] = "-m32";
> > +  else
> > +    new_argv[new_argc++] = "-m64";
> >    new_argv[new_argc++] = src_filename;
> >    new_argv[new_argc++] = "-o";
> >    new_argv[new_argc++] = obj_filename;
> > @@ -511,11 +515,11 @@ main (int argc, char **argv)
> >    unsigned new_argc = 0;
> >    const char *new_argv[9];
> >    new_argv[new_argc++] = "ld";
> > +  new_argv[new_argc++] = "-m";
> >    if (target_ilp32)
> > -    {
> > -      new_argv[new_argc++] = "-m";
> > -      new_argv[new_argc++] = "elf_i386";
> > -    }
> > +    new_argv[new_argc++] = "elf_i386";
> > +  else
> > +    new_argv[new_argc++] = "elf_x86_64";
> >    new_argv[new_argc++] = "--relocatable";
> >    new_argv[new_argc++] = host_descr_filename;
> >    new_argv[new_argc++] = target_so_filename;
> >
> >
> 
> Should we also handle x32?

Yes, probably, but following the standards you've been setting,
<http://news.gmane.org/find-root.php?message_id=%3Calpine.DEB.2.10.1412151845470.4719%40digraph.polyomino.org.uk%3E>,
I only made it work for the case I've been interested in.  ;-)
(Half-smiley, half-serious...)


Grüße,
 Thomas

[-- Attachment #2: Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2015-01-08 15:49               ` Jakub Jelinek
@ 2015-01-08 16:32                 ` Ilya Verbin
  2015-01-08 16:39                   ` Jakub Jelinek
  2015-02-16 18:58                 ` Ilya Verbin
  1 sibling, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2015-01-08 16:32 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Thomas Schwinge, gcc-patches, Kirill Yukhin, Andrey Turetskiy,
	Bernd Schmidt

On 08 Jan 16:49, Jakub Jelinek wrote:
> BTW, today when looking at the TARGET_OPTION_NODE streaming caused
> regressions, I've discovered that it is very hard to debug issues in the
> offloading compiler.  Would be nice if
> -save-temps -v
> printed enough information that it is actually possible to reproduce it,
> e.g. while mkoffload command is printed, one can't cut and paste it easily,
> because some env vars are required and those aren't printed in the -v dump.

I agree, this should be improved.  Unfortunately, I didn't have time so far.

> Similarly, the lto1 offloading compiler invocation is not printed, and

It can be printed by -foffload="-save-temps -v", or should we pass through these
options from host to offload compiler by default?

> wrapping offloading compiler's lto1 into a script that runs gdb on it
> doesn't work, because stdout/stderr (and stdin) is redirected.
> 
> This is something that can be solved during stage4, but would be really nice
> if it wasn't terribly hard to debug stuff.

  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2015-01-08 16:32                 ` Ilya Verbin
@ 2015-01-08 16:39                   ` Jakub Jelinek
  2015-01-09 10:40                     ` Richard Biener
  0 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2015-01-08 16:39 UTC (permalink / raw)
  To: Ilya Verbin
  Cc: Thomas Schwinge, gcc-patches, Kirill Yukhin, Andrey Turetskiy,
	Bernd Schmidt

On Thu, Jan 08, 2015 at 07:32:13PM +0300, Ilya Verbin wrote:
> On 08 Jan 16:49, Jakub Jelinek wrote:
> > BTW, today when looking at the TARGET_OPTION_NODE streaming caused
> > regressions, I've discovered that it is very hard to debug issues in the
> > offloading compiler.  Would be nice if
> > -save-temps -v
> > printed enough information that it is actually possible to reproduce it,
> > e.g. while mkoffload command is printed, one can't cut and paste it easily,
> > because some env vars are required and those aren't printed in the -v dump.
> 
> I agree, this should be improved.  Unfortunately, I didn't have time so far.
> 
> > Similarly, the lto1 offloading compiler invocation is not printed, and
> 
> It can be printed by -foffload="-save-temps -v", or should we pass through these
> options from host to offload compiler by default?

Certainly not if they weren't passed by the user to the host compiler.
But if they have been passed, it might be useful, having to add -save-temps -v 
to too many spaces is annoying.
And it would be really nice to print the essential env vars mkoffload is
relying on, like:
var1=value1
var2=value2
...../mkoffload /tmp/@ccABCDEF

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2015-01-08 16:39                   ` Jakub Jelinek
@ 2015-01-09 10:40                     ` Richard Biener
  2015-01-09 10:45                       ` Jakub Jelinek
  0 siblings, 1 reply; 111+ messages in thread
From: Richard Biener @ 2015-01-09 10:40 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Ilya Verbin, Thomas Schwinge, GCC Patches, Kirill Yukhin,
	Andrey Turetskiy, Bernd Schmidt

On Thu, Jan 8, 2015 at 5:39 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Thu, Jan 08, 2015 at 07:32:13PM +0300, Ilya Verbin wrote:
>> On 08 Jan 16:49, Jakub Jelinek wrote:
>> > BTW, today when looking at the TARGET_OPTION_NODE streaming caused
>> > regressions, I've discovered that it is very hard to debug issues in the
>> > offloading compiler.  Would be nice if
>> > -save-temps -v
>> > printed enough information that it is actually possible to reproduce it,
>> > e.g. while mkoffload command is printed, one can't cut and paste it easily,
>> > because some env vars are required and those aren't printed in the -v dump.
>>
>> I agree, this should be improved.  Unfortunately, I didn't have time so far.
>>
>> > Similarly, the lto1 offloading compiler invocation is not printed, and
>>
>> It can be printed by -foffload="-save-temps -v", or should we pass through these
>> options from host to offload compiler by default?
>
> Certainly not if they weren't passed by the user to the host compiler.
> But if they have been passed, it might be useful, having to add -save-temps -v
> to too many spaces is annoying.
> And it would be really nice to print the essential env vars mkoffload is
> relying on, like:
> var1=value1
> var2=value2
> ...../mkoffload /tmp/@ccABCDEF

Maybe pass it through if you specify -Wl,-debug -v -save-temps
(that also makes sure to disable collect2s error output buffering
which is annoying with LTO)

Richard.

>         Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2015-01-09 10:40                     ` Richard Biener
@ 2015-01-09 10:45                       ` Jakub Jelinek
  0 siblings, 0 replies; 111+ messages in thread
From: Jakub Jelinek @ 2015-01-09 10:45 UTC (permalink / raw)
  To: Richard Biener
  Cc: Ilya Verbin, Thomas Schwinge, GCC Patches, Kirill Yukhin,
	Andrey Turetskiy, Bernd Schmidt

On Fri, Jan 09, 2015 at 11:36:54AM +0100, Richard Biener wrote:
> Maybe pass it through if you specify -Wl,-debug -v -save-temps
> (that also makes sure to disable collect2s error output buffering
> which is annoying with LTO)

Works with me too (but should be documented somewhere).

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-12-22 12:50         ` Jakub Jelinek
@ 2015-01-15 19:21           ` Ilya Verbin
  2015-01-15 19:25             ` Jakub Jelinek
  0 siblings, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2015-01-15 19:21 UTC (permalink / raw)
  To: Jakub Jelinek, Thomas Schwinge; +Cc: Kirill Yukhin, gcc-patches

On 22 Dec 13:35, Jakub Jelinek wrote:
> On Mon, Dec 22, 2014 at 12:48:08PM +0100, Thomas Schwinge wrote:
> > In my understanding, we'd like to support the modes that either all
> > compilers are installed (which is what a user will be using), or all are
> > tested from their build trees.  Or, do we also have to support the mode
> > that only the offloading compilers are installed, but the target
> > (offloading host) compiler is not?  (Doesn't make much sense to me.)
> 
> All 3 of these, yes.
> The nothing is installed yet mode supposedly doesn't work properly on the
> trunk yet (and is what I'd like to use e.g. in distro rpm builds), the offloading
> compilers installed, host is not is useful that you actually test the host compiler
> before installing, and that supposedly works on the trunk, the all installed testing
> I've never used myself, but some people are using it.

This patch enables 'make check-target-libgomp' with noninstalled offloading
compilers.  It creates gcc/accel/<target>/ directory in the build tree of the
offloading compiler, this allows lto-wrapper to find corresponding mkoffload in
case if there is more than one offloading compiler.  Is this approach ok?
I don't like changes in config.gcc and t-intelmic, probably there is a better
way to create a link?


diff --git a/gcc/config.gcc b/gcc/config.gcc
index 0dfc08f..76eef6f 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4369,7 +4369,7 @@ fi
 case ${target} in
 i[34567]86-*-* | x86_64-*-*)
 	if test x$enable_as_accelerator = xyes; then
-		extra_programs="mkoffload\$(exeext)"
+		extra_programs="mkoffload\$(exeext) accel/${target_noncanonical}/mkoffload$(exeext)"
 	fi
 	;;
 esac
diff --git a/gcc/config/i386/intelmic-mkoffload.c b/gcc/config/i386/intelmic-mkoffload.c
index 8e490ff..41807cf 100644
--- a/gcc/config/i386/intelmic-mkoffload.c
+++ b/gcc/config/i386/intelmic-mkoffload.c
@@ -45,6 +45,11 @@ const char *temp_files[MAX_NUM_TEMPS];
 /* Shows if we should compile binaries for i386 instead of x86-64.  */
 bool target_ilp32 = false;
 
+/* An optional prefix for the target compiler, which is required when target
+   compiler is not installed.  */
+char *optional_target_path = NULL;
+
+
 /* Delete tempfiles and exit function.  */
 void
 tool_cleanup (bool from_signal ATTRIBUTE_UNUSED)
@@ -151,14 +156,18 @@ access_check (const char *name, int mode)
   return access (name, mode);
 }
 
-/* Find target compiler using a path from COLLECT_GCC or COMPILER_PATH.  */
+/* Find target compiler using a path from COLLECT_GCC, COMPILER_PATH, or a path
+   relative to ARGV0.  */
 static char *
-find_target_compiler (const char *name)
+find_target_compiler (const char *argv0)
 {
   bool found = false;
   char **paths = NULL;
   unsigned n_paths, i;
+  const char *current_path;
   const char *collect_path = dirname (ASTRDUP (getenv ("COLLECT_GCC")));
+  const char *name
+    = DEFAULT_REAL_TARGET_MACHINE "-accel-" DEFAULT_TARGET_MACHINE "-gcc";
   size_t len = strlen (collect_path) + 1 + strlen (name) + 1;
   char *target_compiler = XNEWVEC (char, len);
   sprintf (target_compiler, "%s/%s", collect_path, name);
@@ -177,13 +186,28 @@ find_target_compiler (const char *name)
       if (access_check (target_compiler, X_OK) == 0)
 	{
 	  found = true;
-	  break;
+	  goto out;
 	}
     }
 
+  /* If installed compiler wasn't found, try to find a non-installed compiler,
+     using a path relative to mkoffload.  */
+  current_path = dirname (ASTRDUP (argv0));
+  len = strlen (current_path) + sizeof ("/../../") - 1;
+  target_compiler = XRESIZEVEC (char, target_compiler, len + sizeof ("xgcc"));
+  sprintf (target_compiler, "%s/../../xgcc", current_path);
+  if (access_check (target_compiler, X_OK) == 0)
+    {
+      optional_target_path = XNEWVEC (char, len + sizeof ("-B"));
+      sprintf (optional_target_path, "-B%s/../../", current_path);
+      found = true;
+    }
+
 out:
   free_array_of_ptrs ((void **) paths, n_paths);
-  return found ? target_compiler : NULL;
+  if (!found)
+    fatal_error ("offload compiler %s not found", name);
+  return target_compiler;
 }
 
 static void
@@ -193,6 +217,10 @@ compile_for_target (struct obstack *argv_obstack)
     obstack_ptr_grow (argv_obstack, "-m32");
   else
     obstack_ptr_grow (argv_obstack, "-m64");
+
+  if (optional_target_path)
+    obstack_ptr_grow (argv_obstack, optional_target_path);
+
   obstack_ptr_grow (argv_obstack, NULL);
   char **argv = XOBFINISH (argv_obstack, char **);
 
@@ -492,11 +520,7 @@ main (int argc, char **argv)
   if (!host_compiler)
     fatal_error ("COLLECT_GCC must be set");
 
-  const char *target_driver_name
-    = DEFAULT_REAL_TARGET_MACHINE "-accel-" DEFAULT_TARGET_MACHINE "-gcc";
-  char *target_compiler = find_target_compiler (target_driver_name);
-  if (target_compiler == NULL)
-    fatal_error ("offload compiler %s not found", target_driver_name);
+  char *target_compiler = find_target_compiler (argv[0]);
 
   /* We may be called with all the arguments stored in some file and
      passed with @file.  Expand them into argv before processing.  */
diff --git a/gcc/config/i386/t-intelmic b/gcc/config/i386/t-intelmic
index 8b36e0d..efc50fca 100644
--- a/gcc/config/i386/t-intelmic
+++ b/gcc/config/i386/t-intelmic
@@ -7,3 +7,9 @@ mkoffload.o: $(srcdir)/config/i386/intelmic-mkoffload.c | insn-modes.h
 
 mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
 	$(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)
+
+accel/$(target_noncanonical)/mkoffload$(exeext): mkoffload$(exeext)
+	test -d accel || mkdir accel
+	test -d accel/$(target_noncanonical) || mkdir accel/$(target_noncanonical)
+	rm -f $@
+	$(LN) mkoffload$(exeext) $@
diff --git a/libgomp/configure b/libgomp/configure
index 3214e9d..134064a 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -16251,7 +16251,11 @@ if test x"$enable_offload_targets" != x; then
     tgt=`echo $tgt | sed 's/=.*//'`
     case $tgt in
       *-intelmic-* | *-intelmicemul-*)
-	tgt_name="intelmic" ;;
+	tgt_name="intelmic"
+	if test x"$tgt_dir" != x; then
+	  offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/$tgt/liboffloadmic/.libs"
+	fi
+	;;
       *)
 	as_fn_error "unknown offload target specified" "$LINENO" 5 ;;
     esac
@@ -16261,7 +16265,7 @@ if test x"$enable_offload_targets" != x; then
       offload_targets=$offload_targets,$tgt_name
     fi
     if test x"$tgt_dir" != x; then
-      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
+      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/gcc -B$tgt_dir/bin"
       offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
     else
       offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
diff --git a/libgomp/configure.ac b/libgomp/configure.ac
index 8ed1bae..d74fce0 100644
--- a/libgomp/configure.ac
+++ b/libgomp/configure.ac
@@ -293,7 +293,11 @@ if test x"$enable_offload_targets" != x; then
     tgt=`echo $tgt | sed 's/=.*//'`
     case $tgt in
       *-intelmic-* | *-intelmicemul-*)
-	tgt_name="intelmic" ;;
+	tgt_name="intelmic"
+	if test x"$tgt_dir" != x; then
+	  offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/$tgt/liboffloadmic/.libs"
+	fi
+	;;
       *)
 	AC_MSG_ERROR([unknown offload target specified]) ;;
     esac
@@ -303,7 +307,7 @@ if test x"$enable_offload_targets" != x; then
       offload_targets=$offload_targets,$tgt_name
     fi
     if test x"$tgt_dir" != x; then
-      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
+      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/gcc -B$tgt_dir/bin"
       offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
     else
       offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"


  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2015-01-15 19:21           ` Ilya Verbin
@ 2015-01-15 19:25             ` Jakub Jelinek
  2015-01-28 17:28               ` Ilya Verbin
  0 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2015-01-15 19:25 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: Thomas Schwinge, Kirill Yukhin, gcc-patches

On Thu, Jan 15, 2015 at 09:55:40PM +0300, Ilya Verbin wrote:
> This patch enables 'make check-target-libgomp' with noninstalled offloading
> compilers.  It creates gcc/accel/<target>/ directory in the build tree of the
> offloading compiler, this allows lto-wrapper to find corresponding mkoffload in
> case if there is more than one offloading compiler.  Is this approach ok?
> I don't like changes in config.gcc and t-intelmic, probably there is a better
> way to create a link?

Let's wait until Thomas hopefully checks in the OpenACC merge in order not
to make him work even harder.
I'll look at your patch afterwards.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* [committed][PR64707] Make fopenmp an LTO option
@ 2015-01-23 15:44         ` Tom de Vries
  2015-01-23 15:53           ` [committed][PR64672] Make fopenacc " Tom de Vries
  0 siblings, 1 reply; 111+ messages in thread
From: Tom de Vries @ 2015-01-23 15:44 UTC (permalink / raw)
  To: Richard Biener, Jakub Jelinek; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 169 bytes --]

Hi,

This patch fixes PR64707.

It marks fopenmp as LTO option, which enables openmp builtins in lto1.

Bootstrapped, reg-tested on x86_64 and committed.

Thanks,
- Tom

[-- Attachment #2: 0001-Make-fopenmp-an-LTO-option.patch --]
[-- Type: text/x-patch, Size: 3059 bytes --]

2015-01-22  Tom de Vries  <tom@codesourcery.com>

	PR libgomp/64707
	* lto-opts.c (lto_write_options): Output non-explicit conservative
	-fno-openmp.
	* lto-wrapper.c (merge_and_complain): Handle merging -fopenmp.
	(append_compiler_options): Pass -fopenmp through.

	* c.opt (fopenmp): Mark as LTO option.

	* lang.opt (fopenmp): Mark as LTO option.

	* testsuite/libgomp.c/target-9.c: Add -ftree-parallelize-loops=0 to
	dg-options.
---
 gcc/c-family/c.opt                     | 2 +-
 gcc/fortran/lang.opt                   | 2 +-
 gcc/lto-opts.c                         | 4 ++++
 gcc/lto-wrapper.c                      | 2 ++
 libgomp/testsuite/libgomp.c/target-9.c | 2 +-
 5 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 62b6c685..4b92022 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1288,7 +1288,7 @@ C ObjC C++ ObjC++ Var(flag_openacc)
 Enable OpenACC
 
 fopenmp
-C ObjC C++ ObjC++ Var(flag_openmp)
+C ObjC C++ ObjC++ LTO Var(flag_openmp)
 Enable OpenMP (implies -frecursive in Fortran)
 
 fopenmp-simd
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index a7a4ed6..0360f6c 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -571,7 +571,7 @@ Fortran
 ; Documented in C
 
 fopenmp
-Fortran
+Fortran LTO
 ; Documented in C
 
 fopenmp-simd
diff --git a/gcc/lto-opts.c b/gcc/lto-opts.c
index 026b323..d44dba0 100644
--- a/gcc/lto-opts.c
+++ b/gcc/lto-opts.c
@@ -166,6 +166,10 @@ lto_write_options (void)
     append_to_collect_gcc_options (&temporary_obstack, &first_p,
 			       "-fno-strict-overflow");
 
+  if (!global_options_set.x_flag_openmp
+      && !global_options.x_flag_openmp)
+    append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fno-openmp");
+
   /* Append options from target hook and store them to offload_lto section.  */
   if (lto_stream_offload_p)
     {
diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
index b1efed2..2d0d451 100644
--- a/gcc/lto-wrapper.c
+++ b/gcc/lto-wrapper.c
@@ -271,6 +271,7 @@ merge_and_complain (struct cl_decoded_option **decoded_options,
 	case OPT_fsigned_zeros:
 	case OPT_ftrapping_math:
 	case OPT_fwrapv:
+	case OPT_fopenmp:
 	  /* For selected options we can merge conservatively.  */
 	  for (j = 0; j < *decoded_options_count; ++j)
 	    if ((*decoded_options)[j].opt_index == foption->opt_index)
@@ -490,6 +491,7 @@ append_compiler_options (obstack *argv_obstack, struct cl_decoded_option *opts,
 	case OPT_fsigned_zeros:
 	case OPT_ftrapping_math:
 	case OPT_fwrapv:
+	case OPT_fopenmp:
 	case OPT_ftrapv:
 	case OPT_fstrict_overflow:
 	case OPT_foffload_abi_:
diff --git a/libgomp/testsuite/libgomp.c/target-9.c b/libgomp/testsuite/libgomp.c/target-9.c
index 00fe0cb..4f3c812 100644
--- a/libgomp/testsuite/libgomp.c/target-9.c
+++ b/libgomp/testsuite/libgomp.c/target-9.c
@@ -1,5 +1,5 @@
 /* { dg-do run } */
-/* { dg-options "-O1" } */
+/* { dg-options "-O1 -ftree-parallelize-loops=0" } */
 /* { dg-additional-options "-flto" { target lto } } */
 
 #include <stdlib.h>
-- 
1.9.1


^ permalink raw reply	[flat|nested] 111+ messages in thread

* [committed][PR64672] Make fopenacc an LTO option
@ 2015-01-23 15:53           ` Tom de Vries
  0 siblings, 0 replies; 111+ messages in thread
From: Tom de Vries @ 2015-01-23 15:53 UTC (permalink / raw)
  To: Richard Biener, Jakub Jelinek; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 171 bytes --]

Hi,

This patch fixes PR64672.

It marks fopenacc as LTO option, which enables openacc builtins in lto1.

Bootstrapped, reg-tested on x86_64 and committed.

Thanks,
- Tom

[-- Attachment #2: 0002-Make-fopenacc-an-LTO-option.patch --]
[-- Type: text/x-patch, Size: 3417 bytes --]

2015-01-22  Tom de Vries  <tom@codesourcery.com>

	PR libgomp/64672
	* lto-opts.c (lto_write_options): Output non-explicit conservative
	-fno-openacc.
	* lto-wrapper.c (merge_and_complain): Handle merging -fopenacc.
	(append_compiler_options): Pass -fopenacc through.

	* c.opt (fopenacc): Mark as LTO option.

	* lang.opt (fopenacc): Mark as LTO option.

	* testsuite/libgomp.oacc-c-c++-common/abort-5.c: New test.
---
 gcc/c-family/c.opt                                    |  2 +-
 gcc/fortran/lang.opt                                  |  2 +-
 gcc/lto-opts.c                                        |  4 ++++
 gcc/lto-wrapper.c                                     |  2 ++
 libgomp/testsuite/libgomp.oacc-c-c++-common/abort-5.c | 18 ++++++++++++++++++
 5 files changed, 26 insertions(+), 2 deletions(-)
 create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/abort-5.c

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 4b92022..fd00407 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1284,7 +1284,7 @@ ObjC ObjC++ Var(flag_objc1_only)
 Conform to the Objective-C 1.0 language as implemented in GCC 4.0
 
 fopenacc
-C ObjC C++ ObjC++ Var(flag_openacc)
+C ObjC C++ ObjC++ LTO Var(flag_openacc)
 Enable OpenACC
 
 fopenmp
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index 0360f6c..d86376a 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -567,7 +567,7 @@ Fortran Var(flag_module_private)
 Set default accessibility of module entities to PRIVATE.
 
 fopenacc
-Fortran
+Fortran LTO
 ; Documented in C
 
 fopenmp
diff --git a/gcc/lto-opts.c b/gcc/lto-opts.c
index d44dba0..279107f 100644
--- a/gcc/lto-opts.c
+++ b/gcc/lto-opts.c
@@ -169,6 +169,10 @@ lto_write_options (void)
   if (!global_options_set.x_flag_openmp
       && !global_options.x_flag_openmp)
     append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fno-openmp");
+  if (!global_options_set.x_flag_openacc
+      && !global_options.x_flag_openacc)
+    append_to_collect_gcc_options (&temporary_obstack, &first_p,
+				   "-fno-openacc");
 
   /* Append options from target hook and store them to offload_lto section.  */
   if (lto_stream_offload_p)
diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
index 2d0d451..e950771 100644
--- a/gcc/lto-wrapper.c
+++ b/gcc/lto-wrapper.c
@@ -272,6 +272,7 @@ merge_and_complain (struct cl_decoded_option **decoded_options,
 	case OPT_ftrapping_math:
 	case OPT_fwrapv:
 	case OPT_fopenmp:
+	case OPT_fopenacc:
 	  /* For selected options we can merge conservatively.  */
 	  for (j = 0; j < *decoded_options_count; ++j)
 	    if ((*decoded_options)[j].opt_index == foption->opt_index)
@@ -492,6 +493,7 @@ append_compiler_options (obstack *argv_obstack, struct cl_decoded_option *opts,
 	case OPT_ftrapping_math:
 	case OPT_fwrapv:
 	case OPT_fopenmp:
+	case OPT_fopenacc:
 	case OPT_ftrapv:
 	case OPT_fstrict_overflow:
 	case OPT_foffload_abi_:
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/abort-5.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/abort-5.c
new file mode 100644
index 0000000..314f04a
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/abort-5.c
@@ -0,0 +1,18 @@
+/* { dg-do run } */
+/* { dg-additional-options "-flto" { target lto } } */
+
+#include <stdlib.h>
+
+int
+main (int argc, char **argv)
+{
+
+#pragma acc parallel
+  {
+    if (argc != 1)
+      abort ();
+  }
+
+  return 0;
+}
+
-- 
1.9.1


^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2015-01-15 19:25             ` Jakub Jelinek
@ 2015-01-28 17:28               ` Ilya Verbin
  2015-01-28 17:42                 ` Jakub Jelinek
  0 siblings, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2015-01-28 17:28 UTC (permalink / raw)
  To: Jakub Jelinek, Thomas Schwinge; +Cc: Kirill Yukhin, gcc-patches

On 15 Jan 19:58, Jakub Jelinek wrote:
> On Thu, Jan 15, 2015 at 09:55:40PM +0300, Ilya Verbin wrote:
> > This patch enables 'make check-target-libgomp' with noninstalled offloading
> > compilers.  It creates gcc/accel/<target>/ directory in the build tree of the
> > offloading compiler, this allows lto-wrapper to find corresponding mkoffload in
> > case if there is more than one offloading compiler.  Is this approach ok?
> > I don't like changes in config.gcc and t-intelmic, probably there is a better
> > way to create a link?
> 
> Let's wait until Thomas hopefully checks in the OpenACC merge in order not
> to make him work even harder.
> I'll look at your patch afterwards.

I've rebased this patch.


diff --git a/gcc/config.gcc b/gcc/config.gcc
index bf67beb..c56c055 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4371,7 +4371,7 @@ fi
 case ${target} in
 i[34567]86-*-* | x86_64-*-*)
 	if test x$enable_as_accelerator = xyes; then
-		extra_programs="mkoffload\$(exeext)"
+		extra_programs="mkoffload\$(exeext) accel/${target_noncanonical}/mkoffload$(exeext)"
 	fi
 	;;
 esac
diff --git a/gcc/config/i386/intelmic-mkoffload.c b/gcc/config/i386/intelmic-mkoffload.c
index 5d9ed33..73ca9ce 100644
--- a/gcc/config/i386/intelmic-mkoffload.c
+++ b/gcc/config/i386/intelmic-mkoffload.c
@@ -45,6 +45,13 @@ const char *temp_files[MAX_NUM_TEMPS];
 /* Shows if we should compile binaries for i386 instead of x86-64.  */
 bool target_ilp32 = false;
 
+/* Optional prefixes for the target compiler, which are required when target
+   compiler is not installed.  */
+char *optional_target_path1 = NULL;
+char *optional_target_path2 = NULL;
+char *optional_target_lib_path = NULL;
+
+
 /* Delete tempfiles and exit function.  */
 void
 tool_cleanup (bool from_signal ATTRIBUTE_UNUSED)
@@ -151,14 +158,18 @@ access_check (const char *name, int mode)
   return access (name, mode);
 }
 
-/* Find target compiler using a path from COLLECT_GCC or COMPILER_PATH.  */
+/* Find target compiler using a path from COLLECT_GCC, COMPILER_PATH, or a path
+   relative to ARGV0.  */
 static char *
-find_target_compiler (const char *name)
+find_target_compiler (const char *argv0)
 {
   bool found = false;
   char **paths = NULL;
   unsigned n_paths, i;
+  const char *current_path;
   const char *collect_path = dirname (ASTRDUP (getenv ("COLLECT_GCC")));
+  const char *name
+    = DEFAULT_REAL_TARGET_MACHINE "-accel-" DEFAULT_TARGET_MACHINE "-gcc";
   size_t len = strlen (collect_path) + 1 + strlen (name) + 1;
   char *target_compiler = XNEWVEC (char, len);
   sprintf (target_compiler, "%s/%s", collect_path, name);
@@ -177,13 +188,38 @@ find_target_compiler (const char *name)
       if (access_check (target_compiler, X_OK) == 0)
 	{
 	  found = true;
-	  break;
+	  goto out;
 	}
     }
 
+  /* If installed compiler wasn't found, try to find a non-installed compiler,
+     using a path relative to mkoffload.  */
+  current_path = dirname (ASTRDUP (argv0));
+  len = strlen (current_path) + sizeof ("/../../") - 1;
+  target_compiler = XRESIZEVEC (char, target_compiler, len + sizeof ("xgcc"));
+  sprintf (target_compiler, "%s/../../xgcc", current_path);
+  if (access_check (target_compiler, X_OK) == 0)
+    {
+      optional_target_path1 = XNEWVEC (char, len + sizeof ("-B"));
+      sprintf (optional_target_path1, "-B%s/../../", current_path);
+      optional_target_path2
+	= XNEWVEC (char, len + sizeof ("-B" "../" DEFAULT_TARGET_MACHINE
+				       "/libgomp/"));
+      sprintf (optional_target_path2, "-B%s/../../../" DEFAULT_TARGET_MACHINE
+				      "/libgomp/", current_path);
+      optional_target_lib_path
+	= XNEWVEC (char, len + sizeof ("-L" "../" DEFAULT_TARGET_MACHINE
+				       "/libgomp/.libs/"));
+      sprintf (optional_target_lib_path, "-L%s/../../../" DEFAULT_TARGET_MACHINE
+					 "/libgomp/.libs/", current_path);
+      found = true;
+    }
+
 out:
   free_array_of_ptrs ((void **) paths, n_paths);
-  return found ? target_compiler : NULL;
+  if (!found)
+    fatal_error ("offload compiler %s not found", name);
+  return target_compiler;
 }
 
 static void
@@ -193,6 +229,14 @@ compile_for_target (struct obstack *argv_obstack)
     obstack_ptr_grow (argv_obstack, "-m32");
   else
     obstack_ptr_grow (argv_obstack, "-m64");
+
+  if (optional_target_path1)
+    obstack_ptr_grow (argv_obstack, optional_target_path1);
+  if (optional_target_path2)
+    obstack_ptr_grow (argv_obstack, optional_target_path2);
+  if (optional_target_lib_path)
+    obstack_ptr_grow (argv_obstack, optional_target_lib_path);
+
   obstack_ptr_grow (argv_obstack, NULL);
   char **argv = XOBFINISH (argv_obstack, char **);
 
@@ -492,11 +536,7 @@ main (int argc, char **argv)
   if (!host_compiler)
     fatal_error ("COLLECT_GCC must be set");
 
-  const char *target_driver_name
-    = DEFAULT_REAL_TARGET_MACHINE "-accel-" DEFAULT_TARGET_MACHINE "-gcc";
-  char *target_compiler = find_target_compiler (target_driver_name);
-  if (target_compiler == NULL)
-    fatal_error ("offload compiler %s not found", target_driver_name);
+  char *target_compiler = find_target_compiler (argv[0]);
 
   /* We may be called with all the arguments stored in some file and
      passed with @file.  Expand them into argv before processing.  */
diff --git a/gcc/config/i386/t-intelmic b/gcc/config/i386/t-intelmic
index 8b36e0d..efc50fca 100644
--- a/gcc/config/i386/t-intelmic
+++ b/gcc/config/i386/t-intelmic
@@ -7,3 +7,9 @@ mkoffload.o: $(srcdir)/config/i386/intelmic-mkoffload.c | insn-modes.h
 
 mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
 	$(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)
+
+accel/$(target_noncanonical)/mkoffload$(exeext): mkoffload$(exeext)
+	test -d accel || mkdir accel
+	test -d accel/$(target_noncanonical) || mkdir accel/$(target_noncanonical)
+	rm -f $@
+	$(LN) mkoffload$(exeext) $@
diff --git a/libgomp/configure b/libgomp/configure
index 0818707..8d96950 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -15226,6 +15226,9 @@ if test x"$enable_offload_targets" != x; then
     case $tgt in
       *-intelmic-* | *-intelmicemul-*)
 	tgt_name=intelmic
+	if test x"$tgt_dir" != x; then
+	  offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/$tgt/liboffloadmic/.libs"
+	fi
 	;;
       nvptx*)
         tgt_name=nvptx
@@ -15276,7 +15279,7 @@ rm -f core conftest.err conftest.$ac_objext \
       offload_targets=$offload_targets,$tgt_name
     fi
     if test x"$tgt_dir" != x; then
-      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
+      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/gcc -B$tgt_dir/bin"
       offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
     else
       offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
diff --git a/libgomp/plugin/configfrag.ac b/libgomp/plugin/configfrag.ac
index 254c688..2861e68 100644
--- a/libgomp/plugin/configfrag.ac
+++ b/libgomp/plugin/configfrag.ac
@@ -94,6 +94,9 @@ if test x"$enable_offload_targets" != x; then
     case $tgt in
       *-intelmic-* | *-intelmicemul-*)
 	tgt_name=intelmic
+	if test x"$tgt_dir" != x; then
+	  offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/$tgt/liboffloadmic/.libs"
+	fi
 	;;
       nvptx*)
         tgt_name=nvptx
@@ -133,7 +136,7 @@ if test x"$enable_offload_targets" != x; then
       offload_targets=$offload_targets,$tgt_name
     fi
     if test x"$tgt_dir" != x; then
-      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
+      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/gcc -B$tgt_dir/bin"
       offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
     else
       offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"


  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2015-01-28 17:28               ` Ilya Verbin
@ 2015-01-28 17:42                 ` Jakub Jelinek
  2015-01-28 17:51                   ` Ilya Verbin
  0 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2015-01-28 17:42 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: Thomas Schwinge, Kirill Yukhin, gcc-patches

On Wed, Jan 28, 2015 at 07:02:59PM +0300, Ilya Verbin wrote:
> +	= XNEWVEC (char, len + sizeof ("-B" "../" DEFAULT_TARGET_MACHINE
> +				       "/libgomp/"));
> +      sprintf (optional_target_path2, "-B%s/../../../" DEFAULT_TARGET_MACHINE
> +				      "/libgomp/", current_path);

This will surely overflow the buffer, won't it?  There is space just for
"../" but you put there "/../../../".

I'd strongly prefer if you rewrote all these XNEWVEC or XRESIZEVEC etc.
+ sprintf cases into concat, like
  optional_target_path2 = concat ("-B", current_path,
				  "/../../../" DEFAULT_TARGET_MACHINE
				  "/libgomp/", NULL);
and similar.  That way you avoid all such bugs.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2015-01-28 17:42                 ` Jakub Jelinek
@ 2015-01-28 17:51                   ` Ilya Verbin
  2015-02-02 14:03                     ` Ilya Verbin
  0 siblings, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2015-01-28 17:51 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Thomas Schwinge, Kirill Yukhin, gcc-patches

On 28 Jan 17:15, Jakub Jelinek wrote:
> On Wed, Jan 28, 2015 at 07:02:59PM +0300, Ilya Verbin wrote:
> > +	= XNEWVEC (char, len + sizeof ("-B" "../" DEFAULT_TARGET_MACHINE
> > +				       "/libgomp/"));
> > +      sprintf (optional_target_path2, "-B%s/../../../" DEFAULT_TARGET_MACHINE
> > +				      "/libgomp/", current_path);
> 
> This will surely overflow the buffer, won't it?  There is space just for
> "../" but you put there "/../../../".
> 
> I'd strongly prefer if you rewrote all these XNEWVEC or XRESIZEVEC etc.
> + sprintf cases into concat, like
>   optional_target_path2 = concat ("-B", current_path,
> 				  "/../../../" DEFAULT_TARGET_MACHINE
> 				  "/libgomp/", NULL);
> and similar.  That way you avoid all such bugs.

The variable 'len' contains sizeof ("/../../").
I agree that this code looks ugly :)  I'll rewrite it using concat.

  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2015-01-28 17:51                   ` Ilya Verbin
@ 2015-02-02 14:03                     ` Ilya Verbin
  0 siblings, 0 replies; 111+ messages in thread
From: Ilya Verbin @ 2015-02-02 14:03 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Thomas Schwinge, Kirill Yukhin, gcc-patches

On 28 Jan 19:20, Ilya Verbin wrote:
> On 28 Jan 17:15, Jakub Jelinek wrote:
> > On Wed, Jan 28, 2015 at 07:02:59PM +0300, Ilya Verbin wrote:
> > > +	= XNEWVEC (char, len + sizeof ("-B" "../" DEFAULT_TARGET_MACHINE
> > > +				       "/libgomp/"));
> > > +      sprintf (optional_target_path2, "-B%s/../../../" DEFAULT_TARGET_MACHINE
> > > +				      "/libgomp/", current_path);
> > 
> > This will surely overflow the buffer, won't it?  There is space just for
> > "../" but you put there "/../../../".
> > 
> > I'd strongly prefer if you rewrote all these XNEWVEC or XRESIZEVEC etc.
> > + sprintf cases into concat, like
> >   optional_target_path2 = concat ("-B", current_path,
> > 				  "/../../../" DEFAULT_TARGET_MACHINE
> > 				  "/libgomp/", NULL);
> > and similar.  That way you avoid all such bugs.
> 
> The variable 'len' contains sizeof ("/../../").
> I agree that this code looks ugly :)  I'll rewrite it using concat.

Here is the patch with concat.


diff --git a/gcc/config.gcc b/gcc/config.gcc
index abd915e..0ebdbd2 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4374,7 +4374,7 @@ fi
 case ${target} in
 i[34567]86-*-* | x86_64-*-*)
 	if test x$enable_as_accelerator = xyes; then
-		extra_programs="mkoffload\$(exeext)"
+		extra_programs="mkoffload\$(exeext) accel/${target_noncanonical}/mkoffload$(exeext)"
 	fi
 	;;
 esac
diff --git a/gcc/config/i386/intelmic-mkoffload.c b/gcc/config/i386/intelmic-mkoffload.c
index edc3f92e..bc71004 100644
--- a/gcc/config/i386/intelmic-mkoffload.c
+++ b/gcc/config/i386/intelmic-mkoffload.c
@@ -22,13 +22,13 @@
 
 #include "config.h"
 #include <libgen.h>
-#include "libgomp-plugin.h"
 #include "system.h"
 #include "coretypes.h"
 #include "obstack.h"
 #include "intl.h"
 #include "diagnostic.h"
 #include "collect-utils.h"
+#include "intelmic-offload.h"
 
 const char tool_name[] = "intelmic mkoffload";
 
@@ -45,6 +45,13 @@ const char *temp_files[MAX_NUM_TEMPS];
 /* Shows if we should compile binaries for i386 instead of x86-64.  */
 bool target_ilp32 = false;
 
+/* Optional prefixes for the target compiler, which are required when target
+   compiler is not installed.  */
+char *optional_target_path1 = NULL;
+char *optional_target_path2 = NULL;
+char *optional_target_lib_path = NULL;
+
+
 /* Delete tempfiles and exit function.  */
 void
 tool_cleanup (bool from_signal ATTRIBUTE_UNUSED)
@@ -151,14 +158,17 @@ access_check (const char *name, int mode)
   return access (name, mode);
 }
 
-/* Find target compiler using a path from COLLECT_GCC or COMPILER_PATH.  */
+/* Find target compiler using a path from COLLECT_GCC, COMPILER_PATH, or a path
+   relative to ARGV0.  */
 static char *
-find_target_compiler (const char *name)
+find_target_compiler (const char *argv0)
 {
   bool found = false;
   char **paths = NULL;
   unsigned n_paths, i;
+  const char *current_path;
   const char *collect_path = dirname (ASTRDUP (getenv ("COLLECT_GCC")));
+  const char *name = GCC_INSTALL_NAME;
   size_t len = strlen (collect_path) + 1 + strlen (name) + 1;
   char *target_compiler = XNEWVEC (char, len);
   sprintf (target_compiler, "%s/%s", collect_path, name);
@@ -177,13 +187,32 @@ find_target_compiler (const char *name)
       if (access_check (target_compiler, X_OK) == 0)
 	{
 	  found = true;
-	  break;
+	  goto out;
 	}
     }
+  XDELETEVEC (target_compiler);
+
+  /* If installed compiler wasn't found, try to find a non-installed compiler,
+     using a path relative to mkoffload.  */
+  current_path = dirname (ASTRDUP (argv0));
+  target_compiler = concat (current_path, "/../../xgcc", NULL);
+  if (access_check (target_compiler, X_OK) == 0)
+    {
+      optional_target_path1 = concat ("-B", current_path, "/../../", NULL);
+      optional_target_path2
+	= concat ("-B", current_path,
+		  "/../../../" DEFAULT_TARGET_MACHINE "/libgomp/", NULL);
+      optional_target_lib_path
+	= concat ("-L", current_path,
+		  "/../../../" DEFAULT_TARGET_MACHINE "/libgomp/.libs/", NULL);
+      found = true;
+    }
 
 out:
   free_array_of_ptrs ((void **) paths, n_paths);
-  return found ? target_compiler : NULL;
+  if (!found)
+    fatal_error ("offload compiler %s not found", name);
+  return target_compiler;
 }
 
 static void
@@ -193,6 +222,14 @@ compile_for_target (struct obstack *argv_obstack)
     obstack_ptr_grow (argv_obstack, "-m32");
   else
     obstack_ptr_grow (argv_obstack, "-m64");
+
+  if (optional_target_path1)
+    obstack_ptr_grow (argv_obstack, optional_target_path1);
+  if (optional_target_path2)
+    obstack_ptr_grow (argv_obstack, optional_target_path2);
+  if (optional_target_lib_path)
+    obstack_ptr_grow (argv_obstack, optional_target_lib_path);
+
   obstack_ptr_grow (argv_obstack, NULL);
   char **argv = XOBFINISH (argv_obstack, char **);
 
@@ -346,7 +383,7 @@ generate_host_descr_file (const char *host_compiler)
 	   "init (void)\n"
 	   "{\n"
 	   "  GOMP_offload_register (&__OFFLOAD_TABLE__, %d, __offload_target_data);\n"
-	   "}\n", OFFLOAD_TARGET_TYPE_INTEL_MIC);
+	   "}\n", GOMP_DEVICE_INTEL_MIC);
   fclose (src_file);
 
   unsigned new_argc = 0;
@@ -483,11 +520,7 @@ main (int argc, char **argv)
   if (!host_compiler)
     fatal_error ("COLLECT_GCC must be set");
 
-  const char *target_driver_name
-    = DEFAULT_REAL_TARGET_MACHINE "-accel-" DEFAULT_TARGET_MACHINE "-gcc";
-  char *target_compiler = find_target_compiler (target_driver_name);
-  if (target_compiler == NULL)
-    fatal_error ("offload compiler %s not found", target_driver_name);
+  char *target_compiler = find_target_compiler (argv[0]);
 
   /* We may be called with all the arguments stored in some file and
      passed with @file.  Expand them into argv before processing.  */
diff --git a/gcc/config/i386/t-intelmic b/gcc/config/i386/t-intelmic
index 8b36e0d..86e10eb 100644
--- a/gcc/config/i386/t-intelmic
+++ b/gcc/config/i386/t-intelmic
@@ -1,9 +1,16 @@
+CFLAGS-mkoffload.o += $(DRIVER_DEFINES) \
+	-DGCC_INSTALL_NAME=\"$(GCC_INSTALL_NAME)\"
+
 mkoffload.o: $(srcdir)/config/i386/intelmic-mkoffload.c | insn-modes.h
-	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
-	  -I$(srcdir)/../libgomp \
-	  -DDEFAULT_REAL_TARGET_MACHINE=\"$(real_target_noncanonical)\" \
-	  -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
-	  $< $(OUTPUT_OPTION)
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 
 mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
-	$(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)
+	$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
+	  mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)
+
+accel/$(target_noncanonical)/mkoffload$(exeext): mkoffload$(exeext)
+	test -d accel || mkdir accel
+	test -d accel/$(target_noncanonical) || mkdir accel/$(target_noncanonical)
+	rm -f $@
+	$(LN) mkoffload$(exeext) $@
diff --git a/libgomp/configure b/libgomp/configure
index 0818707..8d96950 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -15226,6 +15226,9 @@ if test x"$enable_offload_targets" != x; then
     case $tgt in
       *-intelmic-* | *-intelmicemul-*)
 	tgt_name=intelmic
+	if test x"$tgt_dir" != x; then
+	  offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/$tgt/liboffloadmic/.libs"
+	fi
 	;;
       nvptx*)
         tgt_name=nvptx
@@ -15276,7 +15279,7 @@ rm -f core conftest.err conftest.$ac_objext \
       offload_targets=$offload_targets,$tgt_name
     fi
     if test x"$tgt_dir" != x; then
-      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
+      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/gcc -B$tgt_dir/bin"
       offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
     else
       offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
diff --git a/libgomp/plugin/configfrag.ac b/libgomp/plugin/configfrag.ac
index 254c688..2861e68 100644
--- a/libgomp/plugin/configfrag.ac
+++ b/libgomp/plugin/configfrag.ac
@@ -94,6 +94,9 @@ if test x"$enable_offload_targets" != x; then
     case $tgt in
       *-intelmic-* | *-intelmicemul-*)
 	tgt_name=intelmic
+	if test x"$tgt_dir" != x; then
+	  offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/$tgt/liboffloadmic/.libs"
+	fi
 	;;
       nvptx*)
         tgt_name=nvptx
@@ -133,7 +136,7 @@ if test x"$enable_offload_targets" != x; then
       offload_targets=$offload_targets,$tgt_name
     fi
     if test x"$tgt_dir" != x; then
-      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
+      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/gcc -B$tgt_dir/bin"
       offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
     else
       offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"


  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 2/4] Add liboffloadmic
  2014-12-12 10:46   ` Thomas Schwinge
@ 2015-02-04 17:45     ` Ilya Verbin
  2015-02-04 17:46       ` Jakub Jelinek
  0 siblings, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2015-02-04 17:45 UTC (permalink / raw)
  To: Thomas Schwinge, Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin

Hi,

On 12 Dec 11:46, Thomas Schwinge wrote:
> On Tue, 21 Oct 2014 21:20:34 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> > This patch contains liboffloadmic library.
> 
> > liboffloadmic/
> > 	Initial commit.  Imported from upstream:
> > 	https://www.openmprtl.org/sites/default/files/liboffload_oss.tgz
> > 	* Makefile.am: New file.
> > 	* Makefile.in: New file, generated by automake.
> > 	* aclocal.m4: New file, generated by aclocal.
> > 	* configure: New file, generated by autoconf.
> > 	* configure.ac: New file.
> 
> contrib/gcc_update:files_and_dependencies needs to be updated for those
> build machinery files as well as those added in liboffloadmic/plugin/
> later on.

This patch adds rules for liboffloadmic and liboffloadmic/plugin to gcc_update.
OK for trunk?


contrib/
	* gcc_update (files_and_dependencies): Add rules for liboffloadmic and
	liboffloadmic/plugin.


diff --git a/contrib/gcc_update b/contrib/gcc_update
index 5ba3a05..2df9da4 100755
--- a/contrib/gcc_update
+++ b/contrib/gcc_update
@@ -167,6 +167,12 @@ libvtv/configure: libvtv/configure.ac libvtv/aclocal.m4
 libcilkrts/aclocal.m4: libcilkrts/configure.ac
 libcilkrts/Makefile.in: libcilkrts/Makefile.am
 libcilkrts/configure: libcilkrts/configure.ac
+liboffloadmic/aclocal.m4: liboffloadmic/configure.ac
+liboffloadmic/Makefile.in: liboffloadmic/Makefile.am
+liboffloadmic/configure: liboffloadmic/configure.ac
+liboffloadmic/plugin/aclocal.m4: liboffloadmic/plugin/configure.ac
+liboffloadmic/plugin/Makefile.in: liboffloadmic/plugin/Makefile.am
+liboffloadmic/plugin/configure: liboffloadmic/plugin/configure.ac
 # Top level
 Makefile.in: Makefile.tpl Makefile.def
 configure: configure.ac config/acx.m4


  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 2/4] Add liboffloadmic
  2015-02-04 17:45     ` Ilya Verbin
@ 2015-02-04 17:46       ` Jakub Jelinek
  0 siblings, 0 replies; 111+ messages in thread
From: Jakub Jelinek @ 2015-02-04 17:46 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: Thomas Schwinge, gcc-patches, Kirill Yukhin

On Wed, Feb 04, 2015 at 08:44:42PM +0300, Ilya Verbin wrote:
> contrib/
> 	* gcc_update (files_and_dependencies): Add rules for liboffloadmic and
> 	liboffloadmic/plugin.

Ok, thanks.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2015-01-08 15:49               ` Jakub Jelinek
  2015-01-08 16:32                 ` Ilya Verbin
@ 2015-02-16 18:58                 ` Ilya Verbin
  1 sibling, 0 replies; 111+ messages in thread
From: Ilya Verbin @ 2015-02-16 18:58 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Thomas Schwinge, gcc-patches, Kirill Yukhin

On Thu, Jan 08, 2015 at 16:49:40 +0100, Jakub Jelinek wrote:
> BTW, today when looking at the TARGET_OPTION_NODE streaming caused
> regressions, I've discovered that it is very hard to debug issues in the
> offloading compiler.  Would be nice if
> -save-temps -v
> printed enough information that it is actually possible to reproduce it,
> e.g. while mkoffload command is printed, one can't cut and paste it easily,
> because some env vars are required and those aren't printed in the -v dump.

Currently I see all required env vars for mkoffload in the -v dump:
COLLECT_GCC=...
COMPILER_PATH=...
.../mkoffload @...

It doesn't need anything more.

  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2014-10-22 18:57     ` Ilya Verbin
                         ` (3 preceding siblings ...)
  2014-12-22 11:27       ` [PATCH 1/4] Add mkoffload for Intel MIC Thomas Schwinge
@ 2015-02-18 11:48       ` Thomas Schwinge
  2015-02-18 11:56         ` Ilya Verbin
  2015-02-18 12:01         ` [PATCH 1/4] Add mkoffload for Intel MIC Jakub Jelinek
  2015-09-28  9:39       ` Thomas Schwinge
  5 siblings, 2 replies; 111+ messages in thread
From: Thomas Schwinge @ 2015-02-18 11:48 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: text/plain, Size: 1678 bytes --]

Hi!

On Wed, 22 Oct 2014 22:57:01 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> --- /dev/null
> +++ b/gcc/config/i386/intelmic-mkoffload.c
> +[...]
> +#include "config.h"
> +#include <libgen.h>
> +#include "system.h"
> +#include "coretypes.h"
> +#include "obstack.h"
> +#include "intl.h"
> +#include "diagnostic.h"
> +#include "collect-utils.h"
> +#include <libgomp_target.h>
> +[...]

> --- /dev/null
> +++ b/gcc/config/i386/t-intelmic
> @@ -0,0 +1,9 @@
> +mkoffload.o: $(srcdir)/config/i386/intelmic-mkoffload.c | insn-modes.h
> +	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
> +	  -I$(srcdir)/../libgomp \
> +	  -DDEFAULT_REAL_TARGET_MACHINE=\"$(real_target_noncanonical)\" \
> +	  -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
> +	  $< $(OUTPUT_OPTION)
> +
> +mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
> +	$(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)

What is the rationale for the insn-modes.h order-only prerequisites for
mkoffload.o?  Is this simply to get past the build issue which, for
example, Jakub also reported for the nvptx mkoffload,
<http://news.gmane.org/find-root.php?message_id=%3C20150217153918.GX1746%40tucnak.redhat.com%3E>
(»missing mkoffload.o dependencies, patch attached«), or is there a
better rationale for adding (only) this one (indirect) dependency,
instead of listing all of the (real) dependencies?  (After all, we do
want the mkoffload executables to be rebuilt if one of their dependencies
is updated.)  (I have not yet tried to figure out how to do that.)


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2015-02-18 11:48       ` [PATCH 1/4] Add mkoffload for Intel MIC Thomas Schwinge
@ 2015-02-18 11:56         ` Ilya Verbin
  2015-02-18 12:23           ` [PATCH] Use automatic dependencies for mkoffload.o Jakub Jelinek
  2015-02-18 12:01         ` [PATCH 1/4] Add mkoffload for Intel MIC Jakub Jelinek
  1 sibling, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2015-02-18 11:56 UTC (permalink / raw)
  To: Thomas Schwinge
  Cc: Jakub Jelinek, gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Wed, Feb 18, 2015 at 12:48:21 +0100, Thomas Schwinge wrote:
> What is the rationale for the insn-modes.h order-only prerequisites for
> mkoffload.o?  Is this simply to get past the build issue which, for
> example, Jakub also reported for the nvptx mkoffload,
> <http://news.gmane.org/find-root.php?message_id=%3C20150217153918.GX1746%40tucnak.redhat.com%3E>
> (»missing mkoffload.o dependencies, patch attached«), or is there a
> better rationale for adding (only) this one (indirect) dependency,
> instead of listing all of the (real) dependencies?  (After all, we do
> want the mkoffload executables to be rebuilt if one of their dependencies
> is updated.)  (I have not yet tried to figure out how to do that.)

Yes, mkoffload is just not working without this dependency, and works well with
it.  Do you know the right way how to add all other dependencies?

  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2015-02-18 11:48       ` [PATCH 1/4] Add mkoffload for Intel MIC Thomas Schwinge
  2015-02-18 11:56         ` Ilya Verbin
@ 2015-02-18 12:01         ` Jakub Jelinek
  1 sibling, 0 replies; 111+ messages in thread
From: Jakub Jelinek @ 2015-02-18 12:01 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: Ilya Verbin, gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Wed, Feb 18, 2015 at 12:48:21PM +0100, Thomas Schwinge wrote:
> > --- /dev/null
> > +++ b/gcc/config/i386/t-intelmic
> > @@ -0,0 +1,9 @@
> > +mkoffload.o: $(srcdir)/config/i386/intelmic-mkoffload.c | insn-modes.h
> > +	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
> > +	  -I$(srcdir)/../libgomp \
> > +	  -DDEFAULT_REAL_TARGET_MACHINE=\"$(real_target_noncanonical)\" \
> > +	  -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
> > +	  $< $(OUTPUT_OPTION)
> > +
> > +mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
> > +	$(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)
> 
> What is the rationale for the insn-modes.h order-only prerequisites for
> mkoffload.o?  Is this simply to get past the build issue which, for
> example, Jakub also reported for the nvptx mkoffload,
> <http://news.gmane.org/find-root.php?message_id=%3C20150217153918.GX1746%40tucnak.redhat.com%3E>
> (»missing mkoffload.o dependencies, patch attached«), or is there a
> better rationale for adding (only) this one (indirect) dependency,
> instead of listing all of the (real) dependencies?  (After all, we do
> want the mkoffload executables to be rebuilt if one of their dependencies
> is updated.)  (I have not yet tried to figure out how to do that.)

Perhaps if we try to
ALL_HOST_OBJS += mkoffload.o
everything would be handled fine?  I mean, in that case it should
have automatic dependency on all the $(generated_files) and
additionally automatic dependencies for mkoffload.o would be sourced in from
.deps/mkoffload.Po

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* [PATCH] Use automatic dependencies for mkoffload.o
  2015-02-18 11:56         ` Ilya Verbin
@ 2015-02-18 12:23           ` Jakub Jelinek
  2015-02-18 13:10             ` Richard Biener
  0 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2015-02-18 12:23 UTC (permalink / raw)
  To: Richard Biener, Paolo Bonzini, Alexandre Oliva
  Cc: Thomas Schwinge, gcc-patches, Kirill Yukhin, Andrey Turetskiy

On Wed, Feb 18, 2015 at 02:56:07PM +0300, Ilya Verbin wrote:
> On Wed, Feb 18, 2015 at 12:48:21 +0100, Thomas Schwinge wrote:
> > What is the rationale for the insn-modes.h order-only prerequisites for
> > mkoffload.o?  Is this simply to get past the build issue which, for
> > example, Jakub also reported for the nvptx mkoffload,
> > <http://news.gmane.org/find-root.php?message_id=%3C20150217153918.GX1746%40tucnak.redhat.com%3E>
> > (»missing mkoffload.o dependencies, patch attached«), or is there a
> > better rationale for adding (only) this one (indirect) dependency,
> > instead of listing all of the (real) dependencies?  (After all, we do
> > want the mkoffload executables to be rebuilt if one of their dependencies
> > is updated.)  (I have not yet tried to figure out how to do that.)
> 
> Yes, mkoffload is just not working without this dependency, and works well with
> it.  Do you know the right way how to add all other dependencies?

I've tested this for both intelmic and nvptx and it works fine.
Ok for trunk?

2015-02-18  Jakub Jelinek  <jakub@redhat.com>

	* config/i386/t-intelmic (mkoffload.o): Remove dependency on
	insn-modes.h.
	(ALL_HOST_OBJS): Add mkoffload.o.
	* config/nvptx/t-nvptx (ALL_HOST_OBJS): Likewise.

--- gcc/config/i386/t-intelmic.jj	2014-11-13 15:13:25.000000000 +0100
+++ gcc/config/i386/t-intelmic	2015-02-18 13:11:15.650820901 +0100
@@ -1,9 +1,10 @@
-mkoffload.o: $(srcdir)/config/i386/intelmic-mkoffload.c | insn-modes.h
+mkoffload.o: $(srcdir)/config/i386/intelmic-mkoffload.c
 	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
 	  -I$(srcdir)/../libgomp \
 	  -DDEFAULT_REAL_TARGET_MACHINE=\"$(real_target_noncanonical)\" \
 	  -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
 	  $< $(OUTPUT_OPTION)
+ALL_HOST_OBJS += mkoffload.o
 
 mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
 	$(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)
--- gcc/config/nvptx/t-nvptx.jj	2015-02-18 12:36:20.000000000 +0100
+++ gcc/config/nvptx/t-nvptx	2015-02-18 13:10:19.822762534 +0100
@@ -3,6 +3,7 @@ CFLAGS-mkoffload.o += $(DRIVER_DEFINES)
 mkoffload.o: $(srcdir)/config/nvptx/mkoffload.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+ALL_HOST_OBJS += mkoffload.o
 
 mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
 	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \


	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH] Use automatic dependencies for mkoffload.o
  2015-02-18 12:23           ` [PATCH] Use automatic dependencies for mkoffload.o Jakub Jelinek
@ 2015-02-18 13:10             ` Richard Biener
  0 siblings, 0 replies; 111+ messages in thread
From: Richard Biener @ 2015-02-18 13:10 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Paolo Bonzini, Alexandre Oliva, Thomas Schwinge, gcc-patches,
	Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2781 bytes --]

On Wed, 18 Feb 2015, Jakub Jelinek wrote:

> On Wed, Feb 18, 2015 at 02:56:07PM +0300, Ilya Verbin wrote:
> > On Wed, Feb 18, 2015 at 12:48:21 +0100, Thomas Schwinge wrote:
> > > What is the rationale for the insn-modes.h order-only prerequisites for
> > > mkoffload.o?  Is this simply to get past the build issue which, for
> > > example, Jakub also reported for the nvptx mkoffload,
> > > <http://news.gmane.org/find-root.php?message_id=%3C20150217153918.GX1746%40tucnak.redhat.com%3E>
> > > (»missing mkoffload.o dependencies, patch attached«), or is there a
> > > better rationale for adding (only) this one (indirect) dependency,
> > > instead of listing all of the (real) dependencies?  (After all, we do
> > > want the mkoffload executables to be rebuilt if one of their dependencies
> > > is updated.)  (I have not yet tried to figure out how to do that.)
> > 
> > Yes, mkoffload is just not working without this dependency, and works well with
> > it.  Do you know the right way how to add all other dependencies?
> 
> I've tested this for both intelmic and nvptx and it works fine.
> Ok for trunk?

Ok.

Thanks,
Richard.

> 2015-02-18  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* config/i386/t-intelmic (mkoffload.o): Remove dependency on
> 	insn-modes.h.
> 	(ALL_HOST_OBJS): Add mkoffload.o.
> 	* config/nvptx/t-nvptx (ALL_HOST_OBJS): Likewise.
> 
> --- gcc/config/i386/t-intelmic.jj	2014-11-13 15:13:25.000000000 +0100
> +++ gcc/config/i386/t-intelmic	2015-02-18 13:11:15.650820901 +0100
> @@ -1,9 +1,10 @@
> -mkoffload.o: $(srcdir)/config/i386/intelmic-mkoffload.c | insn-modes.h
> +mkoffload.o: $(srcdir)/config/i386/intelmic-mkoffload.c
>  	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
>  	  -I$(srcdir)/../libgomp \
>  	  -DDEFAULT_REAL_TARGET_MACHINE=\"$(real_target_noncanonical)\" \
>  	  -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
>  	  $< $(OUTPUT_OPTION)
> +ALL_HOST_OBJS += mkoffload.o
>  
>  mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
>  	$(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)
> --- gcc/config/nvptx/t-nvptx.jj	2015-02-18 12:36:20.000000000 +0100
> +++ gcc/config/nvptx/t-nvptx	2015-02-18 13:10:19.822762534 +0100
> @@ -3,6 +3,7 @@ CFLAGS-mkoffload.o += $(DRIVER_DEFINES)
>  mkoffload.o: $(srcdir)/config/nvptx/mkoffload.c
>  	$(COMPILE) $<
>  	$(POSTCOMPILE)
> +ALL_HOST_OBJS += mkoffload.o
>  
>  mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
>  	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
> 
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Jennifer Guild,
Dilip Upmanyu, Graham Norton HRB 21284 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 111+ messages in thread

* [PATCH] Fix intelmic-mkoffload (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2014-10-21 17:20 ` [PATCH 1/4] Add mkoffload for " Ilya Verbin
  2014-10-21 21:58   ` Joseph S. Myers
  2014-10-22  8:27   ` Jakub Jelinek
@ 2015-03-06 13:55   ` Ilya Verbin
  2015-03-09 14:49     ` Jakub Jelinek
  2 siblings, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2015-03-06 13:55 UTC (permalink / raw)
  To: Jakub Jelinek, gcc-patches; +Cc: Kirill Yukhin, Thomas Schwinge

Hi,

I've found a bug in intelmic-mkoffload, it works only when the path to gcc is
absolute or relative, but doesn't work when it's specified in the PATH env var.
Here is the fix, I've got a piece of code from gcc/config/nvptx/mkoffload.c.
Regtested on x86_64-linux and i686-linux.  Ok for trunk?


gcc/
	* config/i386/intelmic-mkoffload.c: Include intelmic-offload.h instead
	of libgomp-plugin.h.
	(find_target_compiler): Support a case when the path to gcc is specified
	in the PATH env var, so COLLECT_GCC doesn't contain a path.
	(generate_host_descr_file): Use GOMP_DEVICE_INTEL_MIC from
	intelmic-offload.h instead of OFFLOAD_TARGET_TYPE_INTEL_MIC from
	libgomp-plugin.h.
	(main): Use GCC_INSTALL_NAME as target_driver_name.
	* config/i386/t-intelmic (CFLAGS-mkoffload.o): Add GCC_INSTALL_NAME
	define.
	(mkoffload.o): Remove obsolete include path and defines.
	(mkoffload$(exeext)): Use $(LINKER) instead of $(COMPILER).


diff --git a/gcc/config/i386/intelmic-mkoffload.c b/gcc/config/i386/intelmic-mkoffload.c
index e6394e9..f93007c 100644
--- a/gcc/config/i386/intelmic-mkoffload.c
+++ b/gcc/config/i386/intelmic-mkoffload.c
@@ -22,13 +22,13 @@
 
 #include "config.h"
 #include <libgen.h>
-#include "libgomp-plugin.h"
 #include "system.h"
 #include "coretypes.h"
 #include "obstack.h"
 #include "intl.h"
 #include "diagnostic.h"
 #include "collect-utils.h"
+#include "intelmic-offload.h"
 
 const char tool_name[] = "intelmic mkoffload";
 
@@ -158,10 +158,21 @@ find_target_compiler (const char *name)
   bool found = false;
   char **paths = NULL;
   unsigned n_paths, i;
-  const char *collect_path = dirname (ASTRDUP (getenv ("COLLECT_GCC")));
-  size_t len = strlen (collect_path) + 1 + strlen (name) + 1;
-  char *target_compiler = XNEWVEC (char, len);
-  sprintf (target_compiler, "%s/%s", collect_path, name);
+  char *target_compiler;
+  const char *collect_gcc = getenv ("COLLECT_GCC");
+  const char *gcc_path = dirname (ASTRDUP (collect_gcc));
+  const char *gcc_exec = basename (ASTRDUP (collect_gcc));
+
+  if (strcmp (gcc_exec, collect_gcc) == 0)
+    {
+      /* collect_gcc has no path, so it was found in PATH.  Make sure we also
+	 find accel-gcc in PATH.  */
+      target_compiler = XDUPVEC (char, name, strlen (name) + 1);
+      found = true;
+      goto out;
+    }
+
+  target_compiler = concat (gcc_path, "/", name, NULL);
   if (access_check (target_compiler, X_OK) == 0)
     {
       found = true;
@@ -171,7 +182,7 @@ find_target_compiler (const char *name)
   n_paths = parse_env_var (getenv ("COMPILER_PATH"), &paths);
   for (i = 0; i < n_paths; i++)
     {
-      len = strlen (paths[i]) + 1 + strlen (name) + 1;
+      size_t len = strlen (paths[i]) + 1 + strlen (name) + 1;
       target_compiler = XRESIZEVEC (char, target_compiler, len);
       sprintf (target_compiler, "%s/%s", paths[i], name);
       if (access_check (target_compiler, X_OK) == 0)
@@ -346,7 +357,7 @@ generate_host_descr_file (const char *host_compiler)
 	   "init (void)\n"
 	   "{\n"
 	   "  GOMP_offload_register (&__OFFLOAD_TABLE__, %d, __offload_target_data);\n"
-	   "}\n", OFFLOAD_TARGET_TYPE_INTEL_MIC);
+	   "}\n", GOMP_DEVICE_INTEL_MIC);
   fclose (src_file);
 
   unsigned new_argc = 0;
@@ -483,8 +494,7 @@ main (int argc, char **argv)
   if (!host_compiler)
     fatal_error (input_location, "COLLECT_GCC must be set");
 
-  const char *target_driver_name
-    = DEFAULT_REAL_TARGET_MACHINE "-accel-" DEFAULT_TARGET_MACHINE "-gcc";
+  const char *target_driver_name = GCC_INSTALL_NAME;
   char *target_compiler = find_target_compiler (target_driver_name);
   if (target_compiler == NULL)
     fatal_error (input_location, "offload compiler %s not found",
diff --git a/gcc/config/i386/t-intelmic b/gcc/config/i386/t-intelmic
index 287460e..9de4b76 100644
--- a/gcc/config/i386/t-intelmic
+++ b/gcc/config/i386/t-intelmic
@@ -1,10 +1,10 @@
+CFLAGS-mkoffload.o += $(DRIVER_DEFINES) -DGCC_INSTALL_NAME=\"$(GCC_INSTALL_NAME)\"
+
 mkoffload.o: $(srcdir)/config/i386/intelmic-mkoffload.c
-	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
-	  -I$(srcdir)/../libgomp \
-	  -DDEFAULT_REAL_TARGET_MACHINE=\"$(real_target_noncanonical)\" \
-	  -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
-	  $< $(OUTPUT_OPTION)
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 ALL_HOST_OBJS += mkoffload.o
 
 mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
-	$(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)
+	$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
+	  mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)


Thanks,
  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH] Fix intelmic-mkoffload (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2015-03-06 13:55   ` [PATCH] Fix intelmic-mkoffload " Ilya Verbin
@ 2015-03-09 14:49     ` Jakub Jelinek
  0 siblings, 0 replies; 111+ messages in thread
From: Jakub Jelinek @ 2015-03-09 14:49 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin, Thomas Schwinge

On Fri, Mar 06, 2015 at 04:55:07PM +0300, Ilya Verbin wrote:
> Hi,
> 
> I've found a bug in intelmic-mkoffload, it works only when the path to gcc is
> absolute or relative, but doesn't work when it's specified in the PATH env var.
> Here is the fix, I've got a piece of code from gcc/config/nvptx/mkoffload.c.
> Regtested on x86_64-linux and i686-linux.  Ok for trunk?
> 
> 
> gcc/
> 	* config/i386/intelmic-mkoffload.c: Include intelmic-offload.h instead
> 	of libgomp-plugin.h.
> 	(find_target_compiler): Support a case when the path to gcc is specified
> 	in the PATH env var, so COLLECT_GCC doesn't contain a path.
> 	(generate_host_descr_file): Use GOMP_DEVICE_INTEL_MIC from
> 	intelmic-offload.h instead of OFFLOAD_TARGET_TYPE_INTEL_MIC from
> 	libgomp-plugin.h.
> 	(main): Use GCC_INSTALL_NAME as target_driver_name.
> 	* config/i386/t-intelmic (CFLAGS-mkoffload.o): Add GCC_INSTALL_NAME
> 	define.
> 	(mkoffload.o): Remove obsolete include path and defines.
> 	(mkoffload$(exeext)): Use $(LINKER) instead of $(COMPILER).

Ok, thanks.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2014-10-21 17:28 ` [PATCH 3/4] Add libgomp plugin for Intel MIC Ilya Verbin
  2014-10-22  9:47   ` Jakub Jelinek
@ 2015-07-08 14:16   ` Thomas Schwinge
  2015-07-08 15:14     ` Ilya Verbin
  2015-07-23 19:05     ` Ilya Verbin
  1 sibling, 2 replies; 111+ messages in thread
From: Thomas Schwinge @ 2015-07-08 14:16 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek, gcc-patches; +Cc: Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: text/plain, Size: 4036 bytes --]

Hi!

On Tue, 21 Oct 2014 21:24:13 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> This patch contains a plugin for libgomp and appropriate changes for makefiles.
> 
> The plugin uses liboffloadmic_host.so to interact with the device (or with an
> emulator).  Also the patch contains offload_target_main executable, which is the
> corresponding target side part of a libgomp plugin, and it uses
> liboffloadmic_target.so.
> 
> The plugin builds automatically with liboffloadmic.

With recent GCC trunk sources, builds of the Intel MIC Offload Plugin
fail as follows:

    libtool: compile:  [...]/build-gcc/./gcc/xg++ [...] -I[...]/install/offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/liboffloadmic/plugin -I[...]/install/offload-x86_64-intelmicemul-linux-gnu/lib/gcc/x86_64-intelmicemul-linux-gnu/6.0.0/include -c [...]/source-gcc/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp  -fPIC -DPIC -o .libs/libgomp_plugin_intelmic_la-libgomp-plugin-intelmic.o
    In file included from [...]/source-gcc/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp:40:0:
    [...]/install/offload-x86_64-intelmicemul-linux-gnu/lib/gcc/x86_64-intelmicemul-linux-gnu/6.0.0/include/main_target_image.h:8628:1: error: narrowing conversion of '192' from 'int' to 'char' inside { } [-Wnarrowing]
     };
     ^
    [...]/install/offload-x86_64-intelmicemul-linux-gnu/lib/gcc/x86_64-intelmicemul-linux-gnu/6.0.0/include/main_target_image.h:8628:1: error: narrowing conversion of '192' from 'int' to 'char' inside { } [-Wnarrowing]
    [...]/install/offload-x86_64-intelmicemul-linux-gnu/lib/gcc/x86_64-intelmicemul-linux-gnu/6.0.0/include/main_target_image.h:8628:1: error: narrowing conversion of '164' from 'int' to 'char' inside { } [-Wnarrowing]
    [many more]

Apart from the actual compilation error, it is surprising for me to see
the GCC build reference/depend on the Intel MIC offloading compiler's
installation directory (which I built and installed earlier),
[...]/install/offload-x86_64-intelmicemul-linux-gnu/ -- is that the
correct thing to do?  Shouldn't the GCC build be self-contained?  (I have
not yet made an attempt to understand how the target and device
liboffloadmic builds work together.)

This main_target_image.h file is coming from here:

> --- /dev/null
> +++ b/liboffloadmic/plugin/Makefile.am
> @@ -0,0 +1,123 @@
> +# Plugin for offload execution on Intel MIC devices.

> +main_target_image.h: offload_target_main
> +	@echo -n "const int image_size = " > $@
> +	@stat -c '%s' $< >> $@
> +	@echo ";" >> $@
> +	@echo "struct MainTargetImage {" >> $@
> +	@echo "  int64_t size;" >> $@
> +	@echo "  char name[sizeof \"offload_target_main\"];" >> $@
> +	@echo "  char data[image_size];" >> $@
> +	@echo "};" >> $@
> +	@echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
> +	@echo "  image_size, \"offload_target_main\"," >> $@
> +	@cat $< | xxd -include >> $@
> +	@echo "};" >> $@
> +
> +offload_target_main: $(liboffload_dir)/ofldbegin.o offload_target_main.o $(liboffload_dir)/ofldend.o
> +	$(CXX) $(AM_LDFLAGS) $^ -o $@
> +
> +offload_target_main.o: offload_target_main.cpp
> +	$(CXX) $(AM_CXXFLAGS) $(AM_CPPFLAGS) -c $< -o $@

Here, I note that the xxd tool is being used, which in my distribution is
part of the Vim editor's package, which -- as far as I know -- is not
currently declared as a build dependency of GCC?

Anyway, all that aside for the moment -- OK to commit the following?

--- liboffloadmic/plugin/Makefile.am
+++ liboffloadmic/plugin/Makefile.am
@@ -69,7 +69,7 @@ main_target_image.h: offload_target_main
 	@echo "struct MainTargetImage {" >> $@
 	@echo "  int64_t size;" >> $@
 	@echo "  char name[sizeof \"offload_target_main\"];" >> $@
-	@echo "  char data[image_size];" >> $@
+	@echo "  uint8_t data[image_size];" >> $@
 	@echo "};" >> $@
 	@echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
 	@echo "  image_size, \"offload_target_main\"," >> $@


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2015-07-08 14:16   ` Thomas Schwinge
@ 2015-07-08 15:14     ` Ilya Verbin
  2015-07-08 15:52       ` Thomas Schwinge
  2015-07-23 19:05     ` Ilya Verbin
  1 sibling, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2015-07-08 15:14 UTC (permalink / raw)
  To: Thomas Schwinge
  Cc: Jakub Jelinek, <gcc-patches@gcc.gnu.org>,
	Kirill Yukhin, Andrey Turetskiy


> On 8 июля 2015 г., at 17:16, Thomas Schwinge <thomas@codesourcery.com> wrote:
> 
> Hi!
> 
>> On Tue, 21 Oct 2014 21:24:13 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
>> This patch contains a plugin for libgomp and appropriate changes for makefiles.
>> 
>> The plugin uses liboffloadmic_host.so to interact with the device (or with an
>> emulator).  Also the patch contains offload_target_main executable, which is the
>> corresponding target side part of a libgomp plugin, and it uses
>> liboffloadmic_target.so.
>> 
>> The plugin builds automatically with liboffloadmic.
> 
> With recent GCC trunk sources, builds of the Intel MIC Offload Plugin
> fail as follows:
> 
>    libtool: compile:  [...]/build-gcc/./gcc/xg++ [...] -I[...]/install/offload-x86_64-intelmicemul-linux-gnu/x86_64-intelmicemul-linux-gnu/liboffloadmic/plugin -I[...]/install/offload-x86_64-intelmicemul-linux-gnu/lib/gcc/x86_64-intelmicemul-linux-gnu/6.0.0/include -c [...]/source-gcc/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp  -fPIC -DPIC -o .libs/libgomp_plugin_intelmic_la-libgomp-plugin-intelmic.o
>    In file included from [...]/source-gcc/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp:40:0:
>    [...]/install/offload-x86_64-intelmicemul-linux-gnu/lib/gcc/x86_64-intelmicemul-linux-gnu/6.0.0/include/main_target_image.h:8628:1: error: narrowing conversion of '192' from 'int' to 'char' inside { } [-Wnarrowing]
>     };
>     ^
>    [...]/install/offload-x86_64-intelmicemul-linux-gnu/lib/gcc/x86_64-intelmicemul-linux-gnu/6.0.0/include/main_target_image.h:8628:1: error: narrowing conversion of '192' from 'int' to 'char' inside { } [-Wnarrowing]
>    [...]/install/offload-x86_64-intelmicemul-linux-gnu/lib/gcc/x86_64-intelmicemul-linux-gnu/6.0.0/include/main_target_image.h:8628:1: error: narrowing conversion of '164' from 'int' to 'char' inside { } [-Wnarrowing]
>    [many more]
> 
> Apart from the actual compilation error, it is surprising for me to see
> the GCC build reference/depend on the Intel MIC offloading compiler's
> installation directory (which I built and installed earlier),
> [...]/install/offload-x86_64-intelmicemul-linux-gnu/ -- is that the
> correct thing to do?  Shouldn't the GCC build be self-contained?  (I have
> not yet made an attempt to understand how the target and device
> liboffloadmic builds work together.)
> 
> This main_target_image.h file is coming from here:
> 
>> --- /dev/null
>> +++ b/liboffloadmic/plugin/Makefile.am
>> @@ -0,0 +1,123 @@
>> +# Plugin for offload execution on Intel MIC devices.
> 
>> +main_target_image.h: offload_target_main
>> +    @echo -n "const int image_size = " > $@
>> +    @stat -c '%s' $< >> $@
>> +    @echo ";" >> $@
>> +    @echo "struct MainTargetImage {" >> $@
>> +    @echo "  int64_t size;" >> $@
>> +    @echo "  char name[sizeof \"offload_target_main\"];" >> $@
>> +    @echo "  char data[image_size];" >> $@
>> +    @echo "};" >> $@
>> +    @echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
>> +    @echo "  image_size, \"offload_target_main\"," >> $@
>> +    @cat $< | xxd -include >> $@
>> +    @echo "};" >> $@
>> +
>> +offload_target_main: $(liboffload_dir)/ofldbegin.o offload_target_main.o $(liboffload_dir)/ofldend.o
>> +    $(CXX) $(AM_LDFLAGS) $^ -o $@
>> +
>> +offload_target_main.o: offload_target_main.cpp
>> +    $(CXX) $(AM_CXXFLAGS) $(AM_CPPFLAGS) -c $< -o $@
> 
> Here, I note that the xxd tool is being used, which in my distribution is
> part of the Vim editor's package, which -- as far as I know -- is not
> currently declared as a build dependency of GCC?
> 
> Anyway, all that aside for the moment -- OK to commit the following?
> 
> --- liboffloadmic/plugin/Makefile.am
> +++ liboffloadmic/plugin/Makefile.am
> @@ -69,7 +69,7 @@ main_target_image.h: offload_target_main
>    @echo "struct MainTargetImage {" >> $@
>    @echo "  int64_t size;" >> $@
>    @echo "  char name[sizeof \"offload_target_main\"];" >> $@
> -    @echo "  char data[image_size];" >> $@
> +    @echo "  uint8_t data[image_size];" >> $@
>    @echo "};" >> $@
>    @echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
>    @echo "  image_size, \"offload_target_main\"," >> $@
> 
> 
> Grüße,
> Thomas

Ok to me, thanks.

The plugin consists of 2 parts: offload_target_main is a target part, which is embedded into the host part (libgomp plugin itself). Target part is linked with liboffloadmic_target.so and host part is linked with liboffloadmic_host.so. Both offload_target_main and liboffloadmic_target.so are compiled by the target compiler during its build.

As for xxd, I've found its usage in some Makefile inside gcc tree, so I thought it's ok to use it.

  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2015-07-08 15:14     ` Ilya Verbin
@ 2015-07-08 15:52       ` Thomas Schwinge
  0 siblings, 0 replies; 111+ messages in thread
From: Thomas Schwinge @ 2015-07-08 15:52 UTC (permalink / raw)
  To: Ilya Verbin
  Cc: Jakub Jelinek, <gcc-patches@gcc.gnu.org>,
	Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: text/plain, Size: 4302 bytes --]

Hi!

On Wed, 8 Jul 2015 18:13:56 +0300, Ilya Verbin <iverbin@gmail.com> wrote:
> 
> > On 8 июля 2015 г., at 17:16, Thomas Schwinge <thomas@codesourcery.com> wrote:
> > With recent GCC trunk sources, builds of the Intel MIC Offload Plugin
> > fail as follows: [...]

> > [...] -- OK to commit the following?

> Ok to me, thanks.

Committed in r225562:

commit cacef506e4205bac13a0dd1de238d1a8cc78af28
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed Jul 8 15:47:59 2015 +0000

    liboffloadmic plugin: Address -Wnarrowing diagnostics
    
        libtool: compile:  [...]/build-gcc/./gcc/xg++ [...] -c [...]/source-gcc/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp [...]
        In file included from [...]/source-gcc/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp:40:0:
        [...]/install/offload-x86_64-intelmicemul-linux-gnu/lib/gcc/x86_64-intelmicemul-linux-gnu/6.0.0/include/main_target_image.h:8628:1: error: narrowing conversion of '192' from 'int' to 'char' inside { } [-Wnarrowing]
         };
         ^
        [...]/install/offload-x86_64-intelmicemul-linux-gnu/lib/gcc/x86_64-intelmicemul-linux-gnu/6.0.0/include/main_target_image.h:8628:1: error: narrowing conversion of '192' from 'int' to 'char' inside { } [-Wnarrowing]
        [...]/install/offload-x86_64-intelmicemul-linux-gnu/lib/gcc/x86_64-intelmicemul-linux-gnu/6.0.0/include/main_target_image.h:8628:1: error: narrowing conversion of '164' from 'int' to 'char' inside { } [-Wnarrowing]
        [many more]
    
    	liboffloadmic/
    	* plugin/Makefile.am (main_target_image.h): Change type of data
    	member in struct MainTargetImage to uint8_t.
    	* plugin/Makefile.in: Regenerate.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@225562 138bc75d-0d04-0410-961f-82ee72b054a4
---
 liboffloadmic/ChangeLog          |    6 ++++++
 liboffloadmic/plugin/Makefile.am |    2 +-
 liboffloadmic/plugin/Makefile.in |    2 +-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git liboffloadmic/ChangeLog liboffloadmic/ChangeLog
index 01fb9f4..b0f9e90 100644
--- liboffloadmic/ChangeLog
+++ liboffloadmic/ChangeLog
@@ -1,3 +1,9 @@
+2015-07-08  Thomas Schwinge  <thomas@codesourcery.com>
+
+	* plugin/Makefile.am (main_target_image.h): Change type of data
+	member of struct MainTargetImage to uint8_t.
+	* plugin/Makefile.in: Regenerate.
+
 2015-05-13  Michael Haubenwallner  <michael.haubenwallner@ssi-schaefer.com>
 
 	* Makefile.in: Regenerated with automake-1.11.6.
diff --git liboffloadmic/plugin/Makefile.am liboffloadmic/plugin/Makefile.am
index a814f0c..19d69ab 100644
--- liboffloadmic/plugin/Makefile.am
+++ liboffloadmic/plugin/Makefile.am
@@ -69,7 +69,7 @@ main_target_image.h: offload_target_main
 	@echo "struct MainTargetImage {" >> $@
 	@echo "  int64_t size;" >> $@
 	@echo "  char name[sizeof \"offload_target_main\"];" >> $@
-	@echo "  char data[image_size];" >> $@
+	@echo "  uint8_t data[image_size];" >> $@
 	@echo "};" >> $@
 	@echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
 	@echo "  image_size, \"offload_target_main\"," >> $@
diff --git liboffloadmic/plugin/Makefile.in liboffloadmic/plugin/Makefile.in
index 6f7eec9..19a1a96 100644
--- liboffloadmic/plugin/Makefile.in
+++ liboffloadmic/plugin/Makefile.in
@@ -715,7 +715,7 @@ main_target_image.h: offload_target_main
 	@echo "struct MainTargetImage {" >> $@
 	@echo "  int64_t size;" >> $@
 	@echo "  char name[sizeof \"offload_target_main\"];" >> $@
-	@echo "  char data[image_size];" >> $@
+	@echo "  uint8_t data[image_size];" >> $@
 	@echo "};" >> $@
 	@echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
 	@echo "  image_size, \"offload_target_main\"," >> $@


Thanks for the explanation:

> The plugin consists of 2 parts: offload_target_main is a target part, which is embedded into the host part (libgomp plugin itself). Target part is linked with liboffloadmic_target.so and host part is linked with liboffloadmic_host.so. Both offload_target_main and liboffloadmic_target.so are compiled by the target compiler during its build.
> 
> As for xxd, I've found its usage in some Makefile inside gcc tree, so I thought it's ok to use it.


Grüße,
 Thomas

[-- Attachment #2: Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 2/4] Add liboffloadmic
  2014-10-21 17:24 ` [PATCH 2/4] Add liboffloadmic Ilya Verbin
  2014-10-22  8:55   ` Jakub Jelinek
  2014-12-12 10:46   ` Thomas Schwinge
@ 2015-07-09 10:00   ` Thomas Schwinge
  2015-07-13 14:31     ` Ilya Verbin
  2 siblings, 1 reply; 111+ messages in thread
From: Thomas Schwinge @ 2015-07-09 10:00 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: Kirill Yukhin, Andrey Turetskiy, Jakub Jelinek, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 3826 bytes --]

Hi Ilya!

On Tue, 21 Oct 2014 21:20:34 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> This patch contains liboffloadmic library.
> 
> It is used by ICC for offloading.  The sources are imported from upstream
> ( https://www.openmprtl.org/sites/default/files/liboffload_oss.tgz )
> Configure and makefiles are new.
> 
> Also liboffloadmic/runtime/emulator directory is new.  [...]

I noticed that -- at least with current versions of GCC -- there are
several compiler diagnostics displayed during the build.  It would be
nice to get these addressed -- as applicable, presumably in the Intel
upstream version, and then a new import be done into GCC?  For example, I
noticed the following changes in my build logs (not a complete list):

    {+[...]/source-gcc/liboffloadmic/runtime/emulator/coi_device.cpp:112:28: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]+}
    {+   sprintf (pipe_host_path, "%s"PIPE_HOST_PATH, mic_dir);+}
    {+                            ^+}
    {+[...]/source-gcc/liboffloadmic/runtime/emulator/coi_device.cpp:113:30: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]+}
    {+   sprintf (pipe_target_path, "%s"PIPE_TARGET_PATH, mic_dir);+}
    {+                              ^+}
    
    {+[...]/source-gcc/liboffloadmic/runtime/emulator/coi_host.cpp:892:24: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]+}
    {+   sprintf (pipes_path, "%s"PIPES_PATH, eng->dir);+}
    {+                        ^+}
    {+[...]/source-gcc/liboffloadmic/runtime/emulator/coi_host.cpp:903:28: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]+}
    {+   sprintf (pipe_host_path, "%s"PIPE_HOST_PATH, eng->dir);+}
    {+                            ^+}
    {+[...]/source-gcc/liboffloadmic/runtime/emulator/coi_host.cpp:904:30: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]+}
    {+   sprintf (pipe_target_path, "%s"PIPE_TARGET_PATH, eng->dir);+}
    {+                              ^+}
    
    [...]/source-gcc/liboffloadmic/runtime/offload_host.cpp:107:30: warning: [-deprecated conversion from-]{+ISO C++ forbids converting a+} string constant to 'char*' [-Wwrite-strings]
     static char *timer_envname = "H_TIME";
                                  ^
    
    [...]/source-gcc/liboffloadmic/runtime/offload_myo_host.cpp: In function 'void __intel_cilk_for_32_offload(int, void (*)(void*, void*), int, void*, void*, unsigned int, unsigned int)':
    [...]/source-gcc/liboffloadmic/runtime/offload_myo_host.cpp:762:55: warning: [-deprecated conversion from-]{+ISO C++ forbids converting a+} string constant to 'char*' [-Wwrite-strings]
                                        args, target_number)
                                                           ^
    [...]/source-gcc/liboffloadmic/runtime/offload_myo_host.cpp: In function 'void __intel_cilk_for_64_offload(int, void (*)(void*, void*), int, void*, void*, uint64_t, uint64_t)':
    [...]/source-gcc/liboffloadmic/runtime/offload_myo_host.cpp:815:49: warning: [-deprecated conversion from-]{+ISO C++ forbids converting a+} string constant to 'char*' [-Wwrite-strings]
                                        target_number)
                                                     ^
    
    [...]/source-gcc/liboffloadmic/runtime/offload_orsl.cpp:39:33: warning: [-deprecated conversion from-]{+ISO C++ forbids converting a+} string constant to 'ORSLTag {aka char*}' [-Wwrite-strings]
     static const ORSLTag   my_tag = "Offload";
                                     ^


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 2/4] Add liboffloadmic
  2015-07-09 10:00   ` Thomas Schwinge
@ 2015-07-13 14:31     ` Ilya Verbin
  0 siblings, 0 replies; 111+ messages in thread
From: Ilya Verbin @ 2015-07-13 14:31 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: Kirill Yukhin, gcc-patches

On Thu, Jul 09, 2015 at 12:00:29 +0200, Thomas Schwinge wrote:
> I noticed that -- at least with current versions of GCC -- there are
> several compiler diagnostics displayed during the build.  It would be
> nice to get these addressed -- as applicable, presumably in the Intel
> upstream version, and then a new import be done into GCC?  For example, I
> noticed the following changes in my build logs (not a complete list):
> 
>     {+[...]/source-gcc/liboffloadmic/runtime/emulator/coi_device.cpp:112:28: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]+}
>     {+   sprintf (pipe_host_path, "%s"PIPE_HOST_PATH, mic_dir);+}
>     {+                            ^+}
>     {+[...]/source-gcc/liboffloadmic/runtime/emulator/coi_device.cpp:113:30: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]+}
>     {+   sprintf (pipe_target_path, "%s"PIPE_TARGET_PATH, mic_dir);+}
>     {+                              ^+}
>     
>     {+[...]/source-gcc/liboffloadmic/runtime/emulator/coi_host.cpp:892:24: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]+}
>     {+   sprintf (pipes_path, "%s"PIPES_PATH, eng->dir);+}
>     {+                        ^+}
>     {+[...]/source-gcc/liboffloadmic/runtime/emulator/coi_host.cpp:903:28: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]+}
>     {+   sprintf (pipe_host_path, "%s"PIPE_HOST_PATH, eng->dir);+}
>     {+                            ^+}
>     {+[...]/source-gcc/liboffloadmic/runtime/emulator/coi_host.cpp:904:30: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]+}
>     {+   sprintf (pipe_target_path, "%s"PIPE_TARGET_PATH, eng->dir);+}
>     {+                              ^+}
>     
>     [...]/source-gcc/liboffloadmic/runtime/offload_host.cpp:107:30: warning: [-deprecated conversion from-]{+ISO C++ forbids converting a+} string constant to 'char*' [-Wwrite-strings]
>      static char *timer_envname = "H_TIME";
>                                   ^
>     
>     [...]/source-gcc/liboffloadmic/runtime/offload_myo_host.cpp: In function 'void __intel_cilk_for_32_offload(int, void (*)(void*, void*), int, void*, void*, unsigned int, unsigned int)':
>     [...]/source-gcc/liboffloadmic/runtime/offload_myo_host.cpp:762:55: warning: [-deprecated conversion from-]{+ISO C++ forbids converting a+} string constant to 'char*' [-Wwrite-strings]
>                                         args, target_number)
>                                                            ^
>     [...]/source-gcc/liboffloadmic/runtime/offload_myo_host.cpp: In function 'void __intel_cilk_for_64_offload(int, void (*)(void*, void*), int, void*, void*, uint64_t, uint64_t)':
>     [...]/source-gcc/liboffloadmic/runtime/offload_myo_host.cpp:815:49: warning: [-deprecated conversion from-]{+ISO C++ forbids converting a+} string constant to 'char*' [-Wwrite-strings]
>                                         target_number)
>                                                      ^
>     
>     [...]/source-gcc/liboffloadmic/runtime/offload_orsl.cpp:39:33: warning: [-deprecated conversion from-]{+ISO C++ forbids converting a+} string constant to 'ORSLTag {aka char*}' [-Wwrite-strings]
>      static const ORSLTag   my_tag = "Offload";

Yeah, they are already fixed in the upstream version.  I'll prepare an update
for GCC soon.

  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2015-07-08 14:16   ` Thomas Schwinge
  2015-07-08 15:14     ` Ilya Verbin
@ 2015-07-23 19:05     ` Ilya Verbin
  2015-07-24  8:06       ` Jakub Jelinek
  1 sibling, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2015-07-23 19:05 UTC (permalink / raw)
  To: Thomas Schwinge, Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin, bvmaks

On Wed, Jul 08, 2015 at 16:16:44 +0200, Thomas Schwinge wrote:
> > --- /dev/null
> > +++ b/liboffloadmic/plugin/Makefile.am
> > @@ -0,0 +1,123 @@
> > +# Plugin for offload execution on Intel MIC devices.
> 
> > +main_target_image.h: offload_target_main
> > +	@echo -n "const int image_size = " > $@
> > +	@stat -c '%s' $< >> $@
> > +	@echo ";" >> $@
> > +	@echo "struct MainTargetImage {" >> $@
> > +	@echo "  int64_t size;" >> $@
> > +	@echo "  char name[sizeof \"offload_target_main\"];" >> $@
> > +	@echo "  char data[image_size];" >> $@
> > +	@echo "};" >> $@
> > +	@echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
> > +	@echo "  image_size, \"offload_target_main\"," >> $@
> > +	@cat $< | xxd -include >> $@
> > +	@echo "};" >> $@
> > +
> > +offload_target_main: $(liboffload_dir)/ofldbegin.o offload_target_main.o $(liboffload_dir)/ofldend.o
> > +	$(CXX) $(AM_LDFLAGS) $^ -o $@
> > +
> > +offload_target_main.o: offload_target_main.cpp
> > +	$(CXX) $(AM_CXXFLAGS) $(AM_CPPFLAGS) -c $< -o $@
> 
> Here, I note that the xxd tool is being used, which in my distribution is
> part of the Vim editor's package, which -- as far as I know -- is not
> currently declared as a build dependency of GCC?

We have a patch, which checks for xxd availability, is it ok for trunk?


2015-07-23  Maxim Blumenthal  <maxim.blumenthal@intel.com>

	* configure.ac: Add a check for xxd presence when the target is
	intelmic or intelmicemul.
	* configure: Regenerate.


diff --git a/configure b/configure
index 5ba9489..bd8fed8 100755
--- a/configure
+++ b/configure
[regenerate]

diff --git a/configure.ac b/configure.ac
index 2ff9be0..63eebfc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -494,6 +494,17 @@ else
 fi])
 AC_SUBST(extra_liboffloadmic_configure_flags)
 
+# Check if xxd is present in the system
+# when the target is intelmic or intelmicemul.
+case "${target}" in
+  *-intelmic-* | *-intelmicemul-*)
+    AC_CHECK_PROG(xxd_present, xxd, "yes", "no")
+    if test "$xxd_present" = "no"; then
+      AC_MSG_ERROR([cannot find xxd])
+    fi
+    ;;
+esac
+
 # Save it here so that, even in case of --enable-libgcj, if the Java
 # front-end isn't enabled, we still get libgcj disabled.
 libgcj_saved=$libgcj


  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2015-07-23 19:05     ` Ilya Verbin
@ 2015-07-24  8:06       ` Jakub Jelinek
  2015-07-24 14:27         ` David Malcolm
  0 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2015-07-24  8:06 UTC (permalink / raw)
  To: Ilya Verbin, David Malcolm
  Cc: Thomas Schwinge, gcc-patches, Kirill Yukhin, bvmaks

On Thu, Jul 23, 2015 at 09:50:55PM +0300, Ilya Verbin wrote:
> > Here, I note that the xxd tool is being used, which in my distribution is
> > part of the Vim editor's package, which -- as far as I know -- is not
> > currently declared as a build dependency of GCC?
> 
> We have a patch, which checks for xxd availability, is it ok for trunk?

I'd prefer at least some alternatives.  E.g. the following xxd.py

#!/usr/bin/python
import sys
with open(sys.argv[1],"rb") as f:
    nextblock = f.read(12)
    while 1:
	block = nextblock
	nextblock = f.read(12)
	if block == "":
	    break
	str = ""
	for ch in block:
	    if str == "":
		str = "  "
	    else:
		str += ", "
	    if ord(ch) < 10:
		str += "0x0" + chr(ord('0')+ord(ch))
	    elif ord(ch) < 16:
		str += "0x0" + chr(ord('a')+ord(ch)-10)
	    else:
		str += hex(ord(ch))
	if nextblock != "":
	    str += ","
	print str

	python ./xxd.py $< >> $@
does the same thing as
	cat $< | xxd -include >> $@
(CCing David as python expert, my python knowledge is limited and
15 years old, not sure how portable this is (python 2 vs. python 3, and
even python 2 minimal versions)).

Thus, perhaps configure could check for python that can handle this,
or xxd, and substitute the right command into the makefile and
only bail out if neither is found?

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2015-07-24  8:06       ` Jakub Jelinek
@ 2015-07-24 14:27         ` David Malcolm
  2015-07-28 15:51           ` Maxim Blumental
  0 siblings, 1 reply; 111+ messages in thread
From: David Malcolm @ 2015-07-24 14:27 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Ilya Verbin, Thomas Schwinge, gcc-patches, Kirill Yukhin, bvmaks

[-- Attachment #1: Type: text/plain, Size: 1426 bytes --]

On Fri, 2015-07-24 at 10:01 +0200, Jakub Jelinek wrote:
> #!/usr/bin/python
> import sys
> with open(sys.argv[1],"rb") as f:
>     nextblock = f.read(12)
>     while 1:
>         block = nextblock
>         nextblock = f.read(12)
>         if block == "":
>             break
>         str = ""
>         for ch in block:
>             if str == "":
>                 str = "  "
>             else:
>                 str += ", "
>             if ord(ch) < 10:
>                 str += "0x0" + chr(ord('0')+ord(ch))
>             elif ord(ch) < 16:
>                 str += "0x0" + chr(ord('a')+ord(ch)-10)
>             else:
>                 str += hex(ord(ch))
>         if nextblock != "":
>             str += ","
>         print str
> 
>         python ./xxd.py $< >> $@
> does the same thing as
>         cat $< | xxd -include >> $@
> (CCing David as python expert, my python knowledge is limited and
> 15 years old, not sure how portable this is (python 2 vs. python 3,
> and
> even python 2 minimal versions)).

It doesn't work with Python 3 for various reasons ("print" syntax, and
str vs bytes issues).

I'm attaching a version which works with both Python 2 and Python 3
(2.7.5 and 3.3.2 were the versions I tried).

It ought to work with much older python 2 versions (as your script
appears to), but I don't have them handy.

Presumably it would need a license header and some descriptive comments.

(snip)

Dave

[-- Attachment #2: xxd.py --]
[-- Type: text/x-python, Size: 1019 bytes --]

#!/usr/bin/python
import sys

if sys.version_info[0] == 2:
    # Python 2:
    # 'block' below is an instance of str; iterating over it gives us
    # str instances of len 1.
    def get_byte(ch):
        return ord(ch)
else:
    # Python 3:
    # 'block' below is an instance of bytes; iterating over it gives us
    # instances of int, in the range 0-255.
    def get_byte(ch):
        return ch

with open(sys.argv[1],"rb") as f:
    nextblock = f.read(12)
    while 1:
        block = nextblock
        nextblock = f.read(12)
        if not block:
            break
        str = ""
        for item in block:
            byte = get_byte(item)
            if str == "":
                str = "  "
            else:
                str += ", "
            if byte < 10:
                str += "0x0" + chr(ord('0')+byte)
            elif byte < 16:
                str += "0x0" + chr(ord('a')+byte-10)
            else:
                str += hex(byte)
        if nextblock:
            str += ","
        print(str)

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2015-07-24 14:27         ` David Malcolm
@ 2015-07-28 15:51           ` Maxim Blumental
  2015-08-03 10:24             ` Maxim Blumental
  2015-08-06 14:35             ` Fwd: " Maxim Blumental
  0 siblings, 2 replies; 111+ messages in thread
From: Maxim Blumental @ 2015-07-28 15:51 UTC (permalink / raw)
  To: David Malcolm
  Cc: Jakub Jelinek, Ilya Verbin, Thomas Schwinge, gcc-patches, Kirill Yukhin

[-- Attachment #1: Type: text/plain, Size: 1678 bytes --]

 Applied the idea with python script alternative. Review, please.

2015-07-24 17:18 GMT+03:00 David Malcolm <dmalcolm@redhat.com>:
> On Fri, 2015-07-24 at 10:01 +0200, Jakub Jelinek wrote:
>> #!/usr/bin/python
>> import sys
>> with open(sys.argv[1],"rb") as f:
>>     nextblock = f.read(12)
>>     while 1:
>>         block = nextblock
>>         nextblock = f.read(12)
>>         if block == "":
>>             break
>>         str = ""
>>         for ch in block:
>>             if str == "":
>>                 str = "  "
>>             else:
>>                 str += ", "
>>             if ord(ch) < 10:
>>                 str += "0x0" + chr(ord('0')+ord(ch))
>>             elif ord(ch) < 16:
>>                 str += "0x0" + chr(ord('a')+ord(ch)-10)
>>             else:
>>                 str += hex(ord(ch))
>>         if nextblock != "":
>>             str += ","
>>         print str
>>
>>         python ./xxd.py $< >> $@
>> does the same thing as
>>         cat $< | xxd -include >> $@
>> (CCing David as python expert, my python knowledge is limited and
>> 15 years old, not sure how portable this is (python 2 vs. python 3,
>> and
>> even python 2 minimal versions)).
>
> It doesn't work with Python 3 for various reasons ("print" syntax, and
> str vs bytes issues).
>
> I'm attaching a version which works with both Python 2 and Python 3
> (2.7.5 and 3.3.2 were the versions I tried).
>
> It ought to work with much older python 2 versions (as your script
> appears to), but I don't have them handy.
>
> Presumably it would need a license header and some descriptive comments.
>
> (snip)
>
> Dave



-- 


---------------------
Sincerely yours,
Maxim Blumental

[-- Attachment #2: ChangeLog.txt --]
[-- Type: text/plain, Size: 489 bytes --]

2015-07-28  Maxim Blumenthal  <maxim.blumenthal@intel.com>

	* configure.ac: Add a check for xxd or python presence when the target
	is intelmic or intelmicemul.
	* configure: Regenerate.
	* liboffloadmic/plugin/Makefile.am: Add a condition into
	make_target_image.h generating code.  This condition performs an
	action with either xxd or a special python script during the
	generating.
	* liboffloadmic/plugin/xxd.py: New file.
	* liboffloadmic/plugin/Makefile.in: Regenerate.

[-- Attachment #3: xxd_check.patch --]
[-- Type: application/octet-stream, Size: 8208 bytes --]

commit ab7826ee4ee5f2920b015d01aa538c3ebf50dccd
Author: Maxim Blumenthal <maxim.blumenthal@intel.com>
Date:   Mon Jul 27 20:15:01 2015 +0300

    Check xxd

diff --git a/configure b/configure
index 6d7152e..faad566 100755
--- a/configure
+++ b/configure
@@ -674,6 +674,8 @@ LDFLAGS
 CFLAGS
 CC
 EXTRA_CONFIGARGS_LIBJAVA
+python_present
+xxd_present
 extra_liboffloadmic_configure_flags
 target_subdir
 host_subdir
@@ -3131,6 +3133,92 @@ fi
 
 
 
+# Check if xxd is present in the system
+# when the target is intelmic or intelmicemul.
+case "${target}" in
+  *-intelmic-* | *-intelmicemul-*)
+    # Extract the first word of "xxd", so it can be a program name with args.
+set dummy xxd; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_xxd_present+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$xxd_present"; then
+  ac_cv_prog_xxd_present="$xxd_present" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_xxd_present=""yes""
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_prog_xxd_present" && ac_cv_prog_xxd_present=""no""
+fi
+fi
+xxd_present=$ac_cv_prog_xxd_present
+if test -n "$xxd_present"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $xxd_present" >&5
+$as_echo "$xxd_present" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    # Extract the first word of "python", so it can be a program name with args.
+set dummy python; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_python_present+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$python_present"; then
+  ac_cv_prog_python_present="$python_present" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_python_present=""yes""
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_prog_python_present" && ac_cv_prog_python_present=""no""
+fi
+fi
+python_present=$ac_cv_prog_python_present
+if test -n "$python_present"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $python_present" >&5
+$as_echo "$python_present" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    if test "$xxd_present$python_present" = "nono"; then
+      as_fn_error "cannot find neither xxd nor python" "$LINENO" 5
+    fi
+    ;;
+esac
+
 # Save it here so that, even in case of --enable-libgcj, if the Java
 # front-end isn't enabled, we still get libgcj disabled.
 libgcj_saved=$libgcj
diff --git a/configure.ac b/configure.ac
index fbc49ce..f429a1f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -494,6 +494,18 @@ else
 fi])
 AC_SUBST(extra_liboffloadmic_configure_flags)
 
+# Check if xxd is present in the system
+# when the target is intelmic or intelmicemul.
+case "${target}" in
+  *-intelmic-* | *-intelmicemul-*)
+    AC_CHECK_PROG(xxd_present, xxd, "yes", "no")
+    AC_CHECK_PROG(python_present, python, "yes", "no")
+    if test "$xxd_present$python_present" = "nono"; then
+      AC_MSG_ERROR([cannot find neither xxd nor python])
+    fi
+    ;;
+esac
+
 # Save it here so that, even in case of --enable-libgcj, if the Java
 # front-end isn't enabled, we still get libgcj disabled.
 libgcj_saved=$libgcj
diff --git a/liboffloadmic/plugin/Makefile.am b/liboffloadmic/plugin/Makefile.am
index 19d69ab..cb93309 100644
--- a/liboffloadmic/plugin/Makefile.am
+++ b/liboffloadmic/plugin/Makefile.am
@@ -49,6 +49,10 @@ target_prefix_dir = $(libdir)/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
 target_build_dir = $(accel_search_dir)/$(accel_target)$(MULTISUBDIR)/liboffloadmic/plugin
 target_install_dir = $(accel_search_dir)/lib/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
 
+XXD_PY = $(source_dir)/xxd.py
+xxd_path=`which xxd`
+python_path=`which python`
+
 if PLUGIN_HOST
   toolexeclib_LTLIBRARIES = libgomp-plugin-intelmic.la
   libgomp_plugin_intelmic_la_SOURCES = libgomp-plugin-intelmic.cpp
@@ -73,7 +77,7 @@ main_target_image.h: offload_target_main
 	@echo "};" >> $@
 	@echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
 	@echo "  image_size, \"offload_target_main\"," >> $@
-	@cat $< | xxd -include >> $@
+	@if test "x$(xxd_path)" != "x"; then cat $< | $(xxd_path) -include >> $@; else $(python_path) $(XXD_PY) $< >> $@; fi;
 	@echo "};" >> $@
 
 offload_target_main: $(liboffload_dir)/ofldbegin.o offload_target_main.o $(liboffload_dir)/ofldend.o
diff --git a/liboffloadmic/plugin/Makefile.in b/liboffloadmic/plugin/Makefile.in
index 19a1a96..12fe5ca 100644
--- a/liboffloadmic/plugin/Makefile.in
+++ b/liboffloadmic/plugin/Makefile.in
@@ -318,6 +318,9 @@ libsubincludedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/in
 target_prefix_dir = $(libdir)/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
 target_build_dir = $(accel_search_dir)/$(accel_target)$(MULTISUBDIR)/liboffloadmic/plugin
 target_install_dir = $(accel_search_dir)/lib/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
+XXD_PY = $(source_dir)/xxd.py
+xxd_path = `which xxd`
+python_path = `which python`
 @PLUGIN_HOST_TRUE@toolexeclib_LTLIBRARIES = libgomp-plugin-intelmic.la
 @PLUGIN_HOST_TRUE@libgomp_plugin_intelmic_la_SOURCES = libgomp-plugin-intelmic.cpp
 @PLUGIN_HOST_TRUE@libgomp_plugin_intelmic_la_CPPFLAGS = $(CPPFLAGS) -DLINUX -DCOI_LIBRARY_VERSION=2 -DMYO_SUPPORT -DOFFLOAD_DEBUG=1 -DSEP_SUPPORT -DTIMING_SUPPORT -DHOST_LIBRARY=1 -I$(coi_inc_dir) -I$(myo_inc_dir) -I$(liboffload_src_dir) -I$(libgomp_src_dir) -I$(libgomp_dir) -I$(target_prefix_dir)/include -I$(target_build_dir) -I$(target_install_dir)/include
@@ -719,7 +722,7 @@ main_target_image.h: offload_target_main
 	@echo "};" >> $@
 	@echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
 	@echo "  image_size, \"offload_target_main\"," >> $@
-	@cat $< | xxd -include >> $@
+	@if test "x$(xxd_path)" != "x"; then cat $< | $(xxd_path) -include >> $@; else $(python_path) $(XXD_PY) $< >> $@; fi;
 	@echo "};" >> $@
 
 offload_target_main: $(liboffload_dir)/ofldbegin.o offload_target_main.o $(liboffload_dir)/ofldend.o
diff --git a/liboffloadmic/plugin/xxd.py b/liboffloadmic/plugin/xxd.py
new file mode 100644
index 0000000..fd9d7f0
--- /dev/null
+++ b/liboffloadmic/plugin/xxd.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+import sys
+
+if sys.version_info[0] == 2:
+    # Python 2:
+    # 'block' below is an instance of str; iterating over it gives us
+    # str instances of len 1.
+    def get_byte(ch):
+        return ord(ch)
+else:
+    # Python 3:
+    # 'block' below is an instance of bytes; iterating over it gives us
+    # instances of int, in the range 0-255.
+    def get_byte(ch):
+        return ch
+
+with open(sys.argv[1],"rb") as f:
+    nextblock = f.read(12)
+    while 1:
+        block = nextblock
+        nextblock = f.read(12)
+        if not block:
+            break
+        str = ""
+        for item in block:
+            byte = get_byte(item)
+            if str == "":
+                str = "  "
+            else:
+                str += ", "
+            if byte < 10:
+                str += "0x0" + chr(ord('0')+byte)
+            elif byte < 16:
+                str += "0x0" + chr(ord('a')+byte-10)
+            else:
+                str += hex(byte)
+        if nextblock:
+            str += ","
+        print(str)

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2015-07-28 15:51           ` Maxim Blumental
@ 2015-08-03 10:24             ` Maxim Blumental
  2015-08-04 17:40               ` David Malcolm
  2015-08-06 14:35             ` Fwd: " Maxim Blumental
  1 sibling, 1 reply; 111+ messages in thread
From: Maxim Blumental @ 2015-08-03 10:24 UTC (permalink / raw)
  To: David Malcolm
  Cc: Jakub Jelinek, Ilya Verbin, Thomas Schwinge, gcc-patches, Kirill Yukhin

Could you probably review the patch, please?

2015-07-28 18:42 GMT+03:00 Maxim Blumental <bvmaks@gmail.com>:
>  Applied the idea with python script alternative. Review, please.
>
> 2015-07-24 17:18 GMT+03:00 David Malcolm <dmalcolm@redhat.com>:
>> On Fri, 2015-07-24 at 10:01 +0200, Jakub Jelinek wrote:
>>> #!/usr/bin/python
>>> import sys
>>> with open(sys.argv[1],"rb") as f:
>>>     nextblock = f.read(12)
>>>     while 1:
>>>         block = nextblock
>>>         nextblock = f.read(12)
>>>         if block == "":
>>>             break
>>>         str = ""
>>>         for ch in block:
>>>             if str == "":
>>>                 str = "  "
>>>             else:
>>>                 str += ", "
>>>             if ord(ch) < 10:
>>>                 str += "0x0" + chr(ord('0')+ord(ch))
>>>             elif ord(ch) < 16:
>>>                 str += "0x0" + chr(ord('a')+ord(ch)-10)
>>>             else:
>>>                 str += hex(ord(ch))
>>>         if nextblock != "":
>>>             str += ","
>>>         print str
>>>
>>>         python ./xxd.py $< >> $@
>>> does the same thing as
>>>         cat $< | xxd -include >> $@
>>> (CCing David as python expert, my python knowledge is limited and
>>> 15 years old, not sure how portable this is (python 2 vs. python 3,
>>> and
>>> even python 2 minimal versions)).
>>
>> It doesn't work with Python 3 for various reasons ("print" syntax, and
>> str vs bytes issues).
>>
>> I'm attaching a version which works with both Python 2 and Python 3
>> (2.7.5 and 3.3.2 were the versions I tried).
>>
>> It ought to work with much older python 2 versions (as your script
>> appears to), but I don't have them handy.
>>
>> Presumably it would need a license header and some descriptive comments.
>>
>> (snip)
>>
>> Dave
>
>
>
> --
>
>
> ---------------------
> Sincerely yours,
> Maxim Blumental



-- 


---------------------
Sincerely yours,
Maxim Blumental

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Use gcc/coretypes.h:enum offload_abi in mkoffloads (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2015-01-08 15:02             ` H.J. Lu
  2015-01-08 16:21               ` Thomas Schwinge
@ 2015-08-04 11:20               ` Thomas Schwinge
  2015-09-28  8:26                 ` Use gcc/coretypes.h:enum offload_abi in mkoffloads Thomas Schwinge
  1 sibling, 1 reply; 111+ messages in thread
From: Thomas Schwinge @ 2015-08-04 11:20 UTC (permalink / raw)
  To: H.J. Lu, Jakub Jelinek, Ilya Verbin, GCC Patches
  Cc: Kirill Yukhin, Andrey Turetskiy

[-- Attachment #1: Type: text/plain, Size: 8719 bytes --]

Hi!

On Thu, 8 Jan 2015 07:02:19 -0800, "H.J. Lu" <hjl.tools@gmail.com> wrote:
> On Thu, Jan 8, 2015 at 6:59 AM, Thomas Schwinge <thomas@codesourcery.com> wrote:
> > On Mon, 22 Dec 2014 12:28:20 +0100, Jakub Jelinek <jakub@redhat.com> wrote:
> >> On Mon, Dec 22, 2014 at 12:25:32PM +0100, Thomas Schwinge wrote:
> >> > On Wed, 22 Oct 2014 22:57:01 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> >> > > --- /dev/null
> >> > > +++ b/gcc/config/i386/intelmic-mkoffload.c
> >> > > @@ -0,0 +1,541 @@
> >> > > +/* Offload image generation tool for Intel MIC devices.
> >> >
> >> > > +/* Shows if we should compile binaries for i386 instead of x86-64.  */
> >> > > +bool target_ilp32 = false;

Once the following refactoring to use gcc/coretypes.h:enum offload_abi in
mkoffloads gets approved...

> Should we also handle x32?

..., that should be more easy to do.  OK for trunk, once testing
succeeds?

commit de4d7cbcf979edc095a48dff5b38d12846bdab6f
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Tue Aug 4 13:12:36 2015 +0200

    Use gcc/coretypes.h:enum offload_abi in mkoffloads
---
 gcc/config/i386/intelmic-mkoffload.c |   90 +++++++++++++++++++++++-----------
 gcc/config/nvptx/mkoffload.c         |   56 +++++++++++++++------
 2 files changed, 101 insertions(+), 45 deletions(-)

diff --git gcc/config/i386/intelmic-mkoffload.c gcc/config/i386/intelmic-mkoffload.c
index ca15868..ffa6d01 100644
--- gcc/config/i386/intelmic-mkoffload.c
+++ gcc/config/i386/intelmic-mkoffload.c
@@ -42,8 +42,7 @@ int num_temps = 0;
 const int MAX_NUM_TEMPS = 10;
 const char *temp_files[MAX_NUM_TEMPS];
 
-/* Shows if we should compile binaries for i386 instead of x86-64.  */
-bool target_ilp32 = false;
+enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
 
 /* Delete tempfiles and exit function.  */
 void
@@ -200,10 +199,17 @@ out:
 static void
 compile_for_target (struct obstack *argv_obstack)
 {
-  if (target_ilp32)
-    obstack_ptr_grow (argv_obstack, "-m32");
-  else
-    obstack_ptr_grow (argv_obstack, "-m64");
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      obstack_ptr_grow (argv_obstack, "-m64");
+      break;
+    case OFFLOAD_ABI_ILP32:
+      obstack_ptr_grow (argv_obstack, "-m32");
+      break;
+    default:
+      abort ();
+    }
   obstack_ptr_grow (argv_obstack, NULL);
   char **argv = XOBFINISH (argv_obstack, char **);
 
@@ -379,10 +385,17 @@ generate_host_descr_file (const char *host_compiler)
   new_argv[new_argc++] = "-c";
   new_argv[new_argc++] = "-fPIC";
   new_argv[new_argc++] = "-shared";
-  if (target_ilp32)
-    new_argv[new_argc++] = "-m32";
-  else
-    new_argv[new_argc++] = "-m64";
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      new_argv[new_argc++] = "-m64";
+      break;
+    case OFFLOAD_ABI_ILP32:
+      new_argv[new_argc++] = "-m32";
+      break;
+    default:
+      abort ();
+    }
   new_argv[new_argc++] = src_filename;
   new_argv[new_argc++] = "-o";
   new_argv[new_argc++] = obj_filename;
@@ -442,10 +455,17 @@ prepare_target_image (const char *target_compiler, int argc, char **argv)
   objcopy_argv[3] = "-I";
   objcopy_argv[4] = "binary";
   objcopy_argv[5] = "-O";
-  if (target_ilp32)
-    objcopy_argv[6] = "elf32-i386";
-  else
-    objcopy_argv[6] = "elf64-x86-64";
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      objcopy_argv[6] = "elf64-x86-64";
+      break;
+    case OFFLOAD_ABI_ILP32:
+      objcopy_argv[6] = "elf32-i386";
+      break;
+    default:
+      abort ();
+    }
   objcopy_argv[7] = target_so_filename;
   objcopy_argv[8] = "--rename-section";
   objcopy_argv[9] = rename_section_opt;
@@ -517,17 +537,22 @@ main (int argc, char **argv)
      passed with @file.  Expand them into argv before processing.  */
   expandargv (&argc, &argv);
 
-  /* Find out whether we should compile binaries for i386 or x86-64.  */
-  for (int i = argc - 1; i > 0; i--)
-    if (strncmp (argv[i], "-foffload-abi=", sizeof ("-foffload-abi=") - 1) == 0)
-      {
-	if (strstr (argv[i], "ilp32"))
-	  target_ilp32 = true;
-	else if (!strstr (argv[i], "lp64"))
-	  fatal_error (input_location,
-		       "unrecognizable argument of option -foffload-abi");
-	break;
-      }
+  /* Scan the argument vector.  */
+  for (int i = 1; i < argc; i++)
+    {
+#define STR "-foffload-abi="
+      if (strncmp (argv[i], STR, strlen (STR)) == 0)
+	{
+	  if (strcmp (argv[i] + strlen (STR), "lp64"))
+	    offload_abi = OFFLOAD_ABI_LP64;
+	  else if (strcmp (argv[i] + strlen (STR), "ilp32"))
+	    offload_abi = OFFLOAD_ABI_ILP32;
+	  else
+	    fatal_error (input_location,
+			 "unrecognizable argument of option " STR);
+	}
+#undef STR
+    }
 
   const char *target_so_filename
     = prepare_target_image (target_compiler, argc, argv);
@@ -540,10 +565,17 @@ main (int argc, char **argv)
   const char *new_argv[9];
   new_argv[new_argc++] = "ld";
   new_argv[new_argc++] = "-m";
-  if (target_ilp32)
-    new_argv[new_argc++] = "elf_i386";
-  else
-    new_argv[new_argc++] = "elf_x86_64";
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      new_argv[new_argc++] = "elf_x86_64";
+      break;
+    case OFFLOAD_ABI_ILP32:
+      new_argv[new_argc++] = "elf_i386";
+      break;
+    default:
+      abort ();
+    }
   new_argv[new_argc++] = "--relocatable";
   new_argv[new_argc++] = host_descr_filename;
   new_argv[new_argc++] = target_so_filename;
diff --git gcc/config/nvptx/mkoffload.c gcc/config/nvptx/mkoffload.c
index 1e154c8..f134e7f 100644
--- gcc/config/nvptx/mkoffload.c
+++ gcc/config/nvptx/mkoffload.c
@@ -126,8 +126,7 @@ static id_map *var_ids, **vars_tail = &var_ids;
 static const char *ptx_name;
 static const char *ptx_cfile_name;
 
-/* Shows if we should compile binaries for i386 instead of x86-64.  */
-bool target_ilp32 = false;
+enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
 
 /* Delete tempfiles.  */
 
@@ -916,7 +915,17 @@ compile_native (const char *infile, const char *outfile, const char *compiler)
   struct obstack argv_obstack;
   obstack_init (&argv_obstack);
   obstack_ptr_grow (&argv_obstack, compiler);
-  obstack_ptr_grow (&argv_obstack, target_ilp32 ? "-m32" : "-m64");
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      obstack_ptr_grow (&argv_obstack, "-m64");
+      break;
+    case OFFLOAD_ABI_ILP32:
+      obstack_ptr_grow (&argv_obstack, "-m32");
+      break;
+    default:
+      abort ();
+    }
   obstack_ptr_grow (&argv_obstack, infile);
   obstack_ptr_grow (&argv_obstack, "-c");
   obstack_ptr_grow (&argv_obstack, "-o");
@@ -994,23 +1003,38 @@ main (int argc, char **argv)
      passed with @file.  Expand them into argv before processing.  */
   expandargv (&argc, &argv);
 
-  /* Find out whether we should compile binaries for i386 or x86-64.  */
-  for (int i = argc - 1; i > 0; i--)
-    if (strncmp (argv[i], "-foffload-abi=", sizeof ("-foffload-abi=") - 1) == 0)
-      {
-	if (strstr (argv[i], "ilp32"))
-	  target_ilp32 = true;
-	else if (!strstr (argv[i], "lp64"))
-	  fatal_error (input_location,
-		       "unrecognizable argument of option -foffload-abi");
-	break;
-      }
+  /* Scan the argument vector.  */
+  for (int i = 1; i < argc; i++)
+    {
+#define STR "-foffload-abi="
+      if (strncmp (argv[i], STR, strlen (STR)) == 0)
+	{
+	  if (strcmp (argv[i] + strlen (STR), "lp64"))
+	    offload_abi = OFFLOAD_ABI_LP64;
+	  else if (strcmp (argv[i] + strlen (STR), "ilp32"))
+	    offload_abi = OFFLOAD_ABI_ILP32;
+	  else
+	    fatal_error (input_location,
+			 "unrecognizable argument of option " STR);
+	}
+#undef STR
+    }
 
   struct obstack argv_obstack;
   obstack_init (&argv_obstack);
   obstack_ptr_grow (&argv_obstack, driver);
   obstack_ptr_grow (&argv_obstack, "-xlto");
-  obstack_ptr_grow (&argv_obstack, target_ilp32 ? "-m32" : "-m64");
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      obstack_ptr_grow (&argv_obstack, "-m64");
+      break;
+    case OFFLOAD_ABI_ILP32:
+      obstack_ptr_grow (&argv_obstack, "-m32");
+      break;
+    default:
+      abort ();
+    }
   obstack_ptr_grow (&argv_obstack, "-S");
 
   for (int ix = 1; ix != argc; ix++)
@@ -1029,7 +1053,7 @@ main (int argc, char **argv)
 
   /* PR libgomp/65099: Currently, we only support offloading in 64-bit
      configurations.  */
-  if (!target_ilp32)
+  if (offload_abi == OFFLOAD_ABI_LP64)
     {
       ptx_name = make_temp_file (".mkoffload");
       obstack_ptr_grow (&argv_obstack, "-o");


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2015-08-03 10:24             ` Maxim Blumental
@ 2015-08-04 17:40               ` David Malcolm
  0 siblings, 0 replies; 111+ messages in thread
From: David Malcolm @ 2015-08-04 17:40 UTC (permalink / raw)
  To: Maxim Blumental
  Cc: Jakub Jelinek, Ilya Verbin, Thomas Schwinge, gcc-patches, Kirill Yukhin

On Mon, 2015-08-03 at 13:23 +0300, Maxim Blumental wrote:
> Could you probably review the patch, please?

Sorry, I'm not the best person to review the patch: Jakub CCed me for my
knowledge of python, so I ported his script to work with both python 2
and 3, and it ought to work with early python 2 versions (or be easily
fixable).

It looks like you're using the resulting python script I wrote.  Other
than that, I don't have reviewer-level expertise in the domains of the
rest of the patch (e.g. Intel MIC, and or the build system).

> 2015-07-28 18:42 GMT+03:00 Maxim Blumental <bvmaks@gmail.com>:
> >  Applied the idea with python script alternative. Review, please.
> >
> > 2015-07-24 17:18 GMT+03:00 David Malcolm <dmalcolm@redhat.com>:
> >> On Fri, 2015-07-24 at 10:01 +0200, Jakub Jelinek wrote:
> >>> #!/usr/bin/python
> >>> import sys
> >>> with open(sys.argv[1],"rb") as f:
> >>>     nextblock = f.read(12)
> >>>     while 1:
> >>>         block = nextblock
> >>>         nextblock = f.read(12)
> >>>         if block == "":
> >>>             break
> >>>         str = ""
> >>>         for ch in block:
> >>>             if str == "":
> >>>                 str = "  "
> >>>             else:
> >>>                 str += ", "
> >>>             if ord(ch) < 10:
> >>>                 str += "0x0" + chr(ord('0')+ord(ch))
> >>>             elif ord(ch) < 16:
> >>>                 str += "0x0" + chr(ord('a')+ord(ch)-10)
> >>>             else:
> >>>                 str += hex(ord(ch))
> >>>         if nextblock != "":
> >>>             str += ","
> >>>         print str
> >>>
> >>>         python ./xxd.py $< >> $@
> >>> does the same thing as
> >>>         cat $< | xxd -include >> $@
> >>> (CCing David as python expert, my python knowledge is limited and
> >>> 15 years old, not sure how portable this is (python 2 vs. python 3,
> >>> and
> >>> even python 2 minimal versions)).
> >>
> >> It doesn't work with Python 3 for various reasons ("print" syntax, and
> >> str vs bytes issues).
> >>
> >> I'm attaching a version which works with both Python 2 and Python 3
> >> (2.7.5 and 3.3.2 were the versions I tried).
> >>
> >> It ought to work with much older python 2 versions (as your script
> >> appears to), but I don't have them handy.
> >>
> >> Presumably it would need a license header and some descriptive comments.
> >>
> >> (snip)
> >>
> >> Dave


^ permalink raw reply	[flat|nested] 111+ messages in thread

* Fwd: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2015-07-28 15:51           ` Maxim Blumental
  2015-08-03 10:24             ` Maxim Blumental
@ 2015-08-06 14:35             ` Maxim Blumental
  2015-08-11 12:27               ` Maxim Blumental
  2015-08-24  8:51               ` Fwd: " Jakub Jelinek
  1 sibling, 2 replies; 111+ messages in thread
From: Maxim Blumental @ 2015-08-06 14:35 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: David Malcolm, Kirill Yukhin, Ilya Verbin, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 66 bytes --]

 Applied the idea with python script alternative. Review, please.

[-- Attachment #2: ChangeLog.txt --]
[-- Type: text/plain, Size: 489 bytes --]

2015-07-28  Maxim Blumenthal  <maxim.blumenthal@intel.com>

	* configure.ac: Add a check for xxd or python presence when the target
	is intelmic or intelmicemul.
	* configure: Regenerate.
	* liboffloadmic/plugin/Makefile.am: Add a condition into
	make_target_image.h generating code.  This condition performs an
	action with either xxd or a special python script during the
	generating.
	* liboffloadmic/plugin/xxd.py: New file.
	* liboffloadmic/plugin/Makefile.in: Regenerate.

[-- Attachment #3: xxd_check.patch --]
[-- Type: application/octet-stream, Size: 8208 bytes --]

commit ab7826ee4ee5f2920b015d01aa538c3ebf50dccd
Author: Maxim Blumenthal <maxim.blumenthal@intel.com>
Date:   Mon Jul 27 20:15:01 2015 +0300

    Check xxd

diff --git a/configure b/configure
index 6d7152e..faad566 100755
--- a/configure
+++ b/configure
@@ -674,6 +674,8 @@ LDFLAGS
 CFLAGS
 CC
 EXTRA_CONFIGARGS_LIBJAVA
+python_present
+xxd_present
 extra_liboffloadmic_configure_flags
 target_subdir
 host_subdir
@@ -3131,6 +3133,92 @@ fi
 
 
 
+# Check if xxd is present in the system
+# when the target is intelmic or intelmicemul.
+case "${target}" in
+  *-intelmic-* | *-intelmicemul-*)
+    # Extract the first word of "xxd", so it can be a program name with args.
+set dummy xxd; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_xxd_present+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$xxd_present"; then
+  ac_cv_prog_xxd_present="$xxd_present" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_xxd_present=""yes""
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_prog_xxd_present" && ac_cv_prog_xxd_present=""no""
+fi
+fi
+xxd_present=$ac_cv_prog_xxd_present
+if test -n "$xxd_present"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $xxd_present" >&5
+$as_echo "$xxd_present" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    # Extract the first word of "python", so it can be a program name with args.
+set dummy python; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_python_present+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$python_present"; then
+  ac_cv_prog_python_present="$python_present" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_python_present=""yes""
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_prog_python_present" && ac_cv_prog_python_present=""no""
+fi
+fi
+python_present=$ac_cv_prog_python_present
+if test -n "$python_present"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $python_present" >&5
+$as_echo "$python_present" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    if test "$xxd_present$python_present" = "nono"; then
+      as_fn_error "cannot find neither xxd nor python" "$LINENO" 5
+    fi
+    ;;
+esac
+
 # Save it here so that, even in case of --enable-libgcj, if the Java
 # front-end isn't enabled, we still get libgcj disabled.
 libgcj_saved=$libgcj
diff --git a/configure.ac b/configure.ac
index fbc49ce..f429a1f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -494,6 +494,18 @@ else
 fi])
 AC_SUBST(extra_liboffloadmic_configure_flags)
 
+# Check if xxd is present in the system
+# when the target is intelmic or intelmicemul.
+case "${target}" in
+  *-intelmic-* | *-intelmicemul-*)
+    AC_CHECK_PROG(xxd_present, xxd, "yes", "no")
+    AC_CHECK_PROG(python_present, python, "yes", "no")
+    if test "$xxd_present$python_present" = "nono"; then
+      AC_MSG_ERROR([cannot find neither xxd nor python])
+    fi
+    ;;
+esac
+
 # Save it here so that, even in case of --enable-libgcj, if the Java
 # front-end isn't enabled, we still get libgcj disabled.
 libgcj_saved=$libgcj
diff --git a/liboffloadmic/plugin/Makefile.am b/liboffloadmic/plugin/Makefile.am
index 19d69ab..cb93309 100644
--- a/liboffloadmic/plugin/Makefile.am
+++ b/liboffloadmic/plugin/Makefile.am
@@ -49,6 +49,10 @@ target_prefix_dir = $(libdir)/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
 target_build_dir = $(accel_search_dir)/$(accel_target)$(MULTISUBDIR)/liboffloadmic/plugin
 target_install_dir = $(accel_search_dir)/lib/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
 
+XXD_PY = $(source_dir)/xxd.py
+xxd_path=`which xxd`
+python_path=`which python`
+
 if PLUGIN_HOST
   toolexeclib_LTLIBRARIES = libgomp-plugin-intelmic.la
   libgomp_plugin_intelmic_la_SOURCES = libgomp-plugin-intelmic.cpp
@@ -73,7 +77,7 @@ main_target_image.h: offload_target_main
 	@echo "};" >> $@
 	@echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
 	@echo "  image_size, \"offload_target_main\"," >> $@
-	@cat $< | xxd -include >> $@
+	@if test "x$(xxd_path)" != "x"; then cat $< | $(xxd_path) -include >> $@; else $(python_path) $(XXD_PY) $< >> $@; fi;
 	@echo "};" >> $@
 
 offload_target_main: $(liboffload_dir)/ofldbegin.o offload_target_main.o $(liboffload_dir)/ofldend.o
diff --git a/liboffloadmic/plugin/Makefile.in b/liboffloadmic/plugin/Makefile.in
index 19a1a96..12fe5ca 100644
--- a/liboffloadmic/plugin/Makefile.in
+++ b/liboffloadmic/plugin/Makefile.in
@@ -318,6 +318,9 @@ libsubincludedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/in
 target_prefix_dir = $(libdir)/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
 target_build_dir = $(accel_search_dir)/$(accel_target)$(MULTISUBDIR)/liboffloadmic/plugin
 target_install_dir = $(accel_search_dir)/lib/gcc/$(accel_target)/$(gcc_version)$(MULTISUBDIR)
+XXD_PY = $(source_dir)/xxd.py
+xxd_path = `which xxd`
+python_path = `which python`
 @PLUGIN_HOST_TRUE@toolexeclib_LTLIBRARIES = libgomp-plugin-intelmic.la
 @PLUGIN_HOST_TRUE@libgomp_plugin_intelmic_la_SOURCES = libgomp-plugin-intelmic.cpp
 @PLUGIN_HOST_TRUE@libgomp_plugin_intelmic_la_CPPFLAGS = $(CPPFLAGS) -DLINUX -DCOI_LIBRARY_VERSION=2 -DMYO_SUPPORT -DOFFLOAD_DEBUG=1 -DSEP_SUPPORT -DTIMING_SUPPORT -DHOST_LIBRARY=1 -I$(coi_inc_dir) -I$(myo_inc_dir) -I$(liboffload_src_dir) -I$(libgomp_src_dir) -I$(libgomp_dir) -I$(target_prefix_dir)/include -I$(target_build_dir) -I$(target_install_dir)/include
@@ -719,7 +722,7 @@ main_target_image.h: offload_target_main
 	@echo "};" >> $@
 	@echo "extern \"C\" const MainTargetImage main_target_image = {" >> $@
 	@echo "  image_size, \"offload_target_main\"," >> $@
-	@cat $< | xxd -include >> $@
+	@if test "x$(xxd_path)" != "x"; then cat $< | $(xxd_path) -include >> $@; else $(python_path) $(XXD_PY) $< >> $@; fi;
 	@echo "};" >> $@
 
 offload_target_main: $(liboffload_dir)/ofldbegin.o offload_target_main.o $(liboffload_dir)/ofldend.o
diff --git a/liboffloadmic/plugin/xxd.py b/liboffloadmic/plugin/xxd.py
new file mode 100644
index 0000000..fd9d7f0
--- /dev/null
+++ b/liboffloadmic/plugin/xxd.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+import sys
+
+if sys.version_info[0] == 2:
+    # Python 2:
+    # 'block' below is an instance of str; iterating over it gives us
+    # str instances of len 1.
+    def get_byte(ch):
+        return ord(ch)
+else:
+    # Python 3:
+    # 'block' below is an instance of bytes; iterating over it gives us
+    # instances of int, in the range 0-255.
+    def get_byte(ch):
+        return ch
+
+with open(sys.argv[1],"rb") as f:
+    nextblock = f.read(12)
+    while 1:
+        block = nextblock
+        nextblock = f.read(12)
+        if not block:
+            break
+        str = ""
+        for item in block:
+            byte = get_byte(item)
+            if str == "":
+                str = "  "
+            else:
+                str += ", "
+            if byte < 10:
+                str += "0x0" + chr(ord('0')+byte)
+            elif byte < 16:
+                str += "0x0" + chr(ord('a')+byte-10)
+            else:
+                str += hex(byte)
+        if nextblock:
+            str += ","
+        print(str)

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2015-08-06 14:35             ` Fwd: " Maxim Blumental
@ 2015-08-11 12:27               ` Maxim Blumental
  2015-08-24  8:51               ` Fwd: " Jakub Jelinek
  1 sibling, 0 replies; 111+ messages in thread
From: Maxim Blumental @ 2015-08-11 12:27 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: David Malcolm, Kirill Yukhin, Ilya Verbin, gcc-patches

Review the patches in the previous letter, please.

2015-08-06 17:34 GMT+03:00 Maxim Blumental <bvmaks@gmail.com>:
>  Applied the idea with python script alternative. Review, please.



-- 


---------------------
Sincerely yours,
Maxim Blumental

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: Fwd: [PATCH 3/4] Add libgomp plugin for Intel MIC
  2015-08-06 14:35             ` Fwd: " Maxim Blumental
  2015-08-11 12:27               ` Maxim Blumental
@ 2015-08-24  8:51               ` Jakub Jelinek
  1 sibling, 0 replies; 111+ messages in thread
From: Jakub Jelinek @ 2015-08-24  8:51 UTC (permalink / raw)
  To: Maxim Blumental; +Cc: David Malcolm, Kirill Yukhin, Ilya Verbin, gcc-patches

On Thu, Aug 06, 2015 at 05:34:56PM +0300, Maxim Blumental wrote:
>  Applied the idea with python script alternative. Review, please.

> 2015-07-28  Maxim Blumenthal  <maxim.blumenthal@intel.com>
> 
> 	* configure.ac: Add a check for xxd or python presence when the target
> 	is intelmic or intelmicemul.
> 	* configure: Regenerate.
> 	* liboffloadmic/plugin/Makefile.am: Add a condition into
> 	make_target_image.h generating code.  This condition performs an
> 	action with either xxd or a special python script during the
> 	generating.
> 	* liboffloadmic/plugin/xxd.py: New file.
> 	* liboffloadmic/plugin/Makefile.in: Regenerate.

I still don't like this, there should be no `which ...` uses in the
Makefile.
Instead, use AC_CHECK_PROG/AC_CHECK_PROGS in configure.ac, for python
perhaps search for python python2 python3 or what is common in the python
land.  And prepare the command line to use in the Makefile.am in configure
too, then AC_SUBST it and use the variable in there (and the variable will
use $@ etc.).

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: Use gcc/coretypes.h:enum offload_abi in mkoffloads
  2015-08-04 11:20               ` Use gcc/coretypes.h:enum offload_abi in mkoffloads (was: [PATCH 1/4] Add mkoffload for Intel MIC) Thomas Schwinge
@ 2015-09-28  8:26                 ` Thomas Schwinge
  2015-09-28 11:28                   ` Bernd Schmidt
  0 siblings, 1 reply; 111+ messages in thread
From: Thomas Schwinge @ 2015-09-28  8:26 UTC (permalink / raw)
  To: H.J. Lu, Jakub Jelinek, Ilya Verbin, GCC Patches
  Cc: Kirill Yukhin, Andrey Turetskiy, Bernd Schmidt

[-- Attachment #1: Type: text/plain, Size: 10867 bytes --]

Hi!

On Tue, 4 Aug 2015 13:20:12 +0200, I wrote:
> On Thu, 8 Jan 2015 07:02:19 -0800, "H.J. Lu" <hjl.tools@gmail.com> wrote:
> > On Thu, Jan 8, 2015 at 6:59 AM, Thomas Schwinge <thomas@codesourcery.com> wrote:
> > > On Mon, 22 Dec 2014 12:28:20 +0100, Jakub Jelinek <jakub@redhat.com> wrote:
> > >> On Mon, Dec 22, 2014 at 12:25:32PM +0100, Thomas Schwinge wrote:
> > >> > On Wed, 22 Oct 2014 22:57:01 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> > >> > > --- /dev/null
> > >> > > +++ b/gcc/config/i386/intelmic-mkoffload.c
> > >> > > @@ -0,0 +1,541 @@
> > >> > > +/* Offload image generation tool for Intel MIC devices.
> > >> >
> > >> > > +/* Shows if we should compile binaries for i386 instead of x86-64.  */
> > >> > > +bool target_ilp32 = false;
> 
> Once the following refactoring to use gcc/coretypes.h:enum offload_abi in
> mkoffloads gets approved...
> 
> > Should we also handle x32?
> 
> ..., that should be more easy to do.  OK for trunk, once testing
> succeeds?
> 
> commit de4d7cbcf979edc095a48dff5b38d12846bdab6f
> Author: Thomas Schwinge <thomas@codesourcery.com>
> Date:   Tue Aug 4 13:12:36 2015 +0200
> 
>     Use gcc/coretypes.h:enum offload_abi in mkoffloads

That one included unfortunate yet popular ;-) strcmp "typos":

> +#define STR "-foffload-abi="
> +      if (strncmp (argv[i], STR, strlen (STR)) == 0)
> +	{
> +	  if (strcmp (argv[i] + strlen (STR), "lp64"))
> +	    offload_abi = OFFLOAD_ABI_LP64;
> +	  else if (strcmp (argv[i] + strlen (STR), "ilp32"))
> +	    offload_abi = OFFLOAD_ABI_ILP32;

..., so with these fixed up:

--- gcc/config/i386/intelmic-mkoffload.c
+++ gcc/config/i386/intelmic-mkoffload.c
@@ -544,9 +544,9 @@ main (int argc, char **argv)
 #define STR "-foffload-abi="
       if (strncmp (argv[i], STR, strlen (STR)) == 0)
 	{
-	  if (strcmp (argv[i] + strlen (STR), "lp64"))
+	  if (strcmp (argv[i] + strlen (STR), "lp64") == 0)
 	    offload_abi = OFFLOAD_ABI_LP64;
-	  else if (strcmp (argv[i] + strlen (STR), "ilp32"))
+	  else if (strcmp (argv[i] + strlen (STR), "ilp32") == 0)
 	    offload_abi = OFFLOAD_ABI_ILP32;
 	  else
 	    fatal_error (input_location,
--- gcc/config/nvptx/mkoffload.c
+++ gcc/config/nvptx/mkoffload.c
@@ -1013,9 +1013,9 @@ main (int argc, char **argv)
 #define STR "-foffload-abi="
       if (strncmp (argv[i], STR, strlen (STR)) == 0)
 	{
-	  if (strcmp (argv[i] + strlen (STR), "lp64"))
+	  if (strcmp (argv[i] + strlen (STR), "lp64") == 0)
 	    offload_abi = OFFLOAD_ABI_LP64;
-	  else if (strcmp (argv[i] + strlen (STR), "ilp32"))
+	  else if (strcmp (argv[i] + strlen (STR), "ilp32") == 0)
 	    offload_abi = OFFLOAD_ABI_ILP32;
 	  else
 	    fatal_error (input_location,

..., I'll again propose the following patch for trunk:

commit 9288882278239a9d346ebde99e616185a91fbfaf
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Tue Aug 4 13:12:36 2015 +0200

    Use gcc/coretypes.h:enum offload_abi in mkoffloads
    
    	gcc/
    	* config/i386/intelmic-mkoffload.c (target_ilp32): Remove
    	variable, replacing it with...
    	(offload_abi): ... this new variable.  Adjust all users.
    	* config/nvptx/mkoffload.c (target_ilp32, offload_abi): Likewise.
---
 gcc/config/i386/intelmic-mkoffload.c |   90 +++++++++++++++++++++++-----------
 gcc/config/nvptx/mkoffload.c         |   56 +++++++++++++++------
 2 files changed, 101 insertions(+), 45 deletions(-)

diff --git gcc/config/i386/intelmic-mkoffload.c gcc/config/i386/intelmic-mkoffload.c
index 4a7812c..8028584 100644
--- gcc/config/i386/intelmic-mkoffload.c
+++ gcc/config/i386/intelmic-mkoffload.c
@@ -42,8 +42,7 @@ int num_temps = 0;
 const int MAX_NUM_TEMPS = 10;
 const char *temp_files[MAX_NUM_TEMPS];
 
-/* Shows if we should compile binaries for i386 instead of x86-64.  */
-bool target_ilp32 = false;
+enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
 
 /* Delete tempfiles and exit function.  */
 void
@@ -200,10 +199,17 @@ out:
 static void
 compile_for_target (struct obstack *argv_obstack)
 {
-  if (target_ilp32)
-    obstack_ptr_grow (argv_obstack, "-m32");
-  else
-    obstack_ptr_grow (argv_obstack, "-m64");
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      obstack_ptr_grow (argv_obstack, "-m64");
+      break;
+    case OFFLOAD_ABI_ILP32:
+      obstack_ptr_grow (argv_obstack, "-m32");
+      break;
+    default:
+      abort ();
+    }
   obstack_ptr_grow (argv_obstack, NULL);
   char **argv = XOBFINISH (argv_obstack, char **);
 
@@ -379,10 +385,17 @@ generate_host_descr_file (const char *host_compiler)
   new_argv[new_argc++] = "-c";
   new_argv[new_argc++] = "-fPIC";
   new_argv[new_argc++] = "-shared";
-  if (target_ilp32)
-    new_argv[new_argc++] = "-m32";
-  else
-    new_argv[new_argc++] = "-m64";
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      new_argv[new_argc++] = "-m64";
+      break;
+    case OFFLOAD_ABI_ILP32:
+      new_argv[new_argc++] = "-m32";
+      break;
+    default:
+      abort ();
+    }
   new_argv[new_argc++] = src_filename;
   new_argv[new_argc++] = "-o";
   new_argv[new_argc++] = obj_filename;
@@ -442,10 +455,17 @@ prepare_target_image (const char *target_compiler, int argc, char **argv)
   objcopy_argv[3] = "-I";
   objcopy_argv[4] = "binary";
   objcopy_argv[5] = "-O";
-  if (target_ilp32)
-    objcopy_argv[6] = "elf32-i386";
-  else
-    objcopy_argv[6] = "elf64-x86-64";
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      objcopy_argv[6] = "elf64-x86-64";
+      break;
+    case OFFLOAD_ABI_ILP32:
+      objcopy_argv[6] = "elf32-i386";
+      break;
+    default:
+      abort ();
+    }
   objcopy_argv[7] = target_so_filename;
   objcopy_argv[8] = "--rename-section";
   objcopy_argv[9] = rename_section_opt;
@@ -518,17 +538,22 @@ main (int argc, char **argv)
      passed with @file.  Expand them into argv before processing.  */
   expandargv (&argc, &argv);
 
-  /* Find out whether we should compile binaries for i386 or x86-64.  */
-  for (int i = argc - 1; i > 0; i--)
-    if (strncmp (argv[i], "-foffload-abi=", sizeof ("-foffload-abi=") - 1) == 0)
-      {
-	if (strstr (argv[i], "ilp32"))
-	  target_ilp32 = true;
-	else if (!strstr (argv[i], "lp64"))
-	  fatal_error (input_location,
-		       "unrecognizable argument of option -foffload-abi");
-	break;
-      }
+  /* Scan the argument vector.  */
+  for (int i = 1; i < argc; i++)
+    {
+#define STR "-foffload-abi="
+      if (strncmp (argv[i], STR, strlen (STR)) == 0)
+	{
+	  if (strcmp (argv[i] + strlen (STR), "lp64") == 0)
+	    offload_abi = OFFLOAD_ABI_LP64;
+	  else if (strcmp (argv[i] + strlen (STR), "ilp32") == 0)
+	    offload_abi = OFFLOAD_ABI_ILP32;
+	  else
+	    fatal_error (input_location,
+			 "unrecognizable argument of option " STR);
+	}
+#undef STR
+    }
 
   const char *target_so_filename
     = prepare_target_image (target_compiler, argc, argv);
@@ -541,10 +566,17 @@ main (int argc, char **argv)
   const char *new_argv[9];
   new_argv[new_argc++] = "ld";
   new_argv[new_argc++] = "-m";
-  if (target_ilp32)
-    new_argv[new_argc++] = "elf_i386";
-  else
-    new_argv[new_argc++] = "elf_x86_64";
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      new_argv[new_argc++] = "elf_x86_64";
+      break;
+    case OFFLOAD_ABI_ILP32:
+      new_argv[new_argc++] = "elf_i386";
+      break;
+    default:
+      abort ();
+    }
   new_argv[new_argc++] = "--relocatable";
   new_argv[new_argc++] = host_descr_filename;
   new_argv[new_argc++] = target_so_filename;
diff --git gcc/config/nvptx/mkoffload.c gcc/config/nvptx/mkoffload.c
index ba0454e..78ac8fe 100644
--- gcc/config/nvptx/mkoffload.c
+++ gcc/config/nvptx/mkoffload.c
@@ -126,8 +126,7 @@ static id_map *var_ids, **vars_tail = &var_ids;
 static const char *ptx_name;
 static const char *ptx_cfile_name;
 
-/* Shows if we should compile binaries for i386 instead of x86-64.  */
-bool target_ilp32 = false;
+enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
 
 /* Delete tempfiles.  */
 
@@ -920,7 +919,17 @@ compile_native (const char *infile, const char *outfile, const char *compiler)
   struct obstack argv_obstack;
   obstack_init (&argv_obstack);
   obstack_ptr_grow (&argv_obstack, compiler);
-  obstack_ptr_grow (&argv_obstack, target_ilp32 ? "-m32" : "-m64");
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      obstack_ptr_grow (&argv_obstack, "-m64");
+      break;
+    case OFFLOAD_ABI_ILP32:
+      obstack_ptr_grow (&argv_obstack, "-m32");
+      break;
+    default:
+      abort ();
+    }
   obstack_ptr_grow (&argv_obstack, infile);
   obstack_ptr_grow (&argv_obstack, "-c");
   obstack_ptr_grow (&argv_obstack, "-o");
@@ -998,23 +1007,38 @@ main (int argc, char **argv)
      passed with @file.  Expand them into argv before processing.  */
   expandargv (&argc, &argv);
 
-  /* Find out whether we should compile binaries for i386 or x86-64.  */
-  for (int i = argc - 1; i > 0; i--)
-    if (strncmp (argv[i], "-foffload-abi=", sizeof ("-foffload-abi=") - 1) == 0)
-      {
-	if (strstr (argv[i], "ilp32"))
-	  target_ilp32 = true;
-	else if (!strstr (argv[i], "lp64"))
-	  fatal_error (input_location,
-		       "unrecognizable argument of option -foffload-abi");
-	break;
-      }
+  /* Scan the argument vector.  */
+  for (int i = 1; i < argc; i++)
+    {
+#define STR "-foffload-abi="
+      if (strncmp (argv[i], STR, strlen (STR)) == 0)
+	{
+	  if (strcmp (argv[i] + strlen (STR), "lp64") == 0)
+	    offload_abi = OFFLOAD_ABI_LP64;
+	  else if (strcmp (argv[i] + strlen (STR), "ilp32") == 0)
+	    offload_abi = OFFLOAD_ABI_ILP32;
+	  else
+	    fatal_error (input_location,
+			 "unrecognizable argument of option " STR);
+	}
+#undef STR
+    }
 
   struct obstack argv_obstack;
   obstack_init (&argv_obstack);
   obstack_ptr_grow (&argv_obstack, driver);
   obstack_ptr_grow (&argv_obstack, "-xlto");
-  obstack_ptr_grow (&argv_obstack, target_ilp32 ? "-m32" : "-m64");
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      obstack_ptr_grow (&argv_obstack, "-m64");
+      break;
+    case OFFLOAD_ABI_ILP32:
+      obstack_ptr_grow (&argv_obstack, "-m32");
+      break;
+    default:
+      abort ();
+    }
   obstack_ptr_grow (&argv_obstack, "-S");
 
   for (int ix = 1; ix != argc; ix++)
@@ -1033,7 +1057,7 @@ main (int argc, char **argv)
 
   /* PR libgomp/65099: Currently, we only support offloading in 64-bit
      configurations.  */
-  if (!target_ilp32)
+  if (offload_abi == OFFLOAD_ABI_LP64)
     {
       ptx_name = make_temp_file (".mkoffload");
       obstack_ptr_grow (&argv_obstack, "-o");


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2014-10-22 18:57     ` Ilya Verbin
                         ` (4 preceding siblings ...)
  2015-02-18 11:48       ` [PATCH 1/4] Add mkoffload for Intel MIC Thomas Schwinge
@ 2015-09-28  9:39       ` Thomas Schwinge
  2015-09-28 11:26         ` Bernd Schmidt
  5 siblings, 1 reply; 111+ messages in thread
From: Thomas Schwinge @ 2015-09-28  9:39 UTC (permalink / raw)
  To: gcc-patches, Ilya Verbin, Jakub Jelinek
  Cc: Kirill Yukhin, Andrey Turetskiy, Bernd Schmidt

[-- Attachment #1: Type: text/plain, Size: 9600 bytes --]

Hi!

On Wed, 22 Oct 2014 22:57:01 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> On 22 Oct 09:57, Jakub Jelinek wrote:
> > On Wed, Oct 22, 2014 at 02:30:44AM +0400, Ilya Verbin wrote:
> > > +  obstack_init (&argv_obstack);
> > > +  obstack_ptr_grow (&argv_obstack, "objcopy");
> > > +  obstack_ptr_grow (&argv_obstack, target_so_filename);
> > > +  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
> > > +  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[0]);
> > > +  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
> > > +  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[1]);
> > > +  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
> > > +  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[2]);
> > > +  obstack_ptr_grow (&argv_obstack, NULL);
> > > +  new_argv = XOBFINISH (&argv_obstack, char **);
> > 
> > Why do you use an obstack for an array of pointers where you know
> > you have exactly 9 pointers?  Wouldn't
> >   char *new_argv[9];
> > and just pointer assignments be better?
> 
> Yes, done.
> 
> > > +  /* Perform partial linking for the target image and host side descriptor.
> > > +     As a result we'll get a finalized object file with all offload data.  */
> > > +  struct obstack argv_obstack;
> > > +  obstack_init (&argv_obstack);
> > > +  obstack_ptr_grow (&argv_obstack, "ld");
> > > +  if (target_ilp32)
> > > +    {
> > > +      obstack_ptr_grow (&argv_obstack, "-m");
> > > +      obstack_ptr_grow (&argv_obstack, "elf_i386");
> > > +    }
> > > +  obstack_ptr_grow (&argv_obstack, "-r");
> > > +  obstack_ptr_grow (&argv_obstack, host_descr_filename);
> > > +  obstack_ptr_grow (&argv_obstack, target_so_filename);
> > > +  obstack_ptr_grow (&argv_obstack, "-o");
> > > +  obstack_ptr_grow (&argv_obstack, out_obj_filename);
> > > +  obstack_ptr_grow (&argv_obstack, NULL);
> > > +  char **new_argv = XOBFINISH (&argv_obstack, char **);
> > 
> > Similarly (well, here it is not constant, still, you know small upper bound
> > and can just use some int index you ++ in each assignment.
> 
> Done.
> 
> > > +  /* Run objcopy on the resultant object file to localize generated symbols
> > > +     to avoid conflicting between different DSO and an executable.  */
> > > +  obstack_init (&argv_obstack);
> > > +  obstack_ptr_grow (&argv_obstack, "objcopy");
> > > +  obstack_ptr_grow (&argv_obstack, "-L");
> > > +  obstack_ptr_grow (&argv_obstack, symbols[0]);
> > > +  obstack_ptr_grow (&argv_obstack, "-L");
> > > +  obstack_ptr_grow (&argv_obstack, symbols[1]);
> > > +  obstack_ptr_grow (&argv_obstack, "-L");
> > > +  obstack_ptr_grow (&argv_obstack, symbols[2]);
> > > +  obstack_ptr_grow (&argv_obstack, out_obj_filename);
> > > +  obstack_ptr_grow (&argv_obstack, NULL);
> > > +  new_argv = XOBFINISH (&argv_obstack, char **);
> > > +  fork_execute (new_argv[0], new_argv, false);
> > > +  obstack_free (&argv_obstack, NULL);
> > 
> > Likewise.
> 
> Done.

After approval for "Use gcc/coretypes.h:enum offload_abi in mkoffloads",
<http://news.gmane.org/find-root.php?message_id=%3C87vbavuft0.fsf%40kepler.schwinge.homeip.net%3E>,
I'd like to commit the following refactoring patch to trunk, in
preparation for another change:

commit 91fbe15ce2e539a4017f65cc167b362a4b4e4553
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Tue Aug 4 14:06:39 2015 +0200

    Refactor intelmic-mkoffload.c argv building
    
    	gcc/
    	* config/i386/intelmic-mkoffload.c (generate_host_descr_file)
    	(prepare_target_image, main): Refactor argv building.
---
 gcc/config/i386/intelmic-mkoffload.c |   88 +++++++++++++++++++++-------------
 1 file changed, 54 insertions(+), 34 deletions(-)

diff --git gcc/config/i386/intelmic-mkoffload.c gcc/config/i386/intelmic-mkoffload.c
index 8028584..8d5af0d 100644
--- gcc/config/i386/intelmic-mkoffload.c
+++ gcc/config/i386/intelmic-mkoffload.c
@@ -380,7 +380,8 @@ generate_host_descr_file (const char *host_compiler)
   fclose (src_file);
 
   unsigned new_argc = 0;
-  const char *new_argv[9];
+#define NEW_ARGC_MAX 9
+  const char *new_argv[NEW_ARGC_MAX];
   new_argv[new_argc++] = host_compiler;
   new_argv[new_argc++] = "-c";
   new_argv[new_argc++] = "-fPIC";
@@ -400,6 +401,8 @@ generate_host_descr_file (const char *host_compiler)
   new_argv[new_argc++] = "-o";
   new_argv[new_argc++] = obj_filename;
   new_argv[new_argc++] = NULL;
+  gcc_checking_assert (new_argc <= NEW_ARGC_MAX);
+#undef NEW_ARGC_MAX
 
   fork_execute (new_argv[0], CONST_CAST (char **, new_argv), false);
 
@@ -444,32 +447,37 @@ prepare_target_image (const char *target_compiler, int argc, char **argv)
   obstack_ptr_grow (&argv_obstack, target_so_filename);
   compile_for_target (&argv_obstack);
 
+  unsigned objcopy_argc;
+#define OBJCOPY_ARGC_MAX 11
+  const char *objcopy_argv[OBJCOPY_ARGC_MAX];
+
   /* Run objcopy.  */
   char *rename_section_opt
     = XALLOCAVEC (char, sizeof (".data=") + strlen (image_section_name));
   sprintf (rename_section_opt, ".data=%s", image_section_name);
-  const char *objcopy_argv[11];
-  objcopy_argv[0] = "objcopy";
-  objcopy_argv[1] = "-B";
-  objcopy_argv[2] = "i386";
-  objcopy_argv[3] = "-I";
-  objcopy_argv[4] = "binary";
-  objcopy_argv[5] = "-O";
+  objcopy_argc = 0;
+  objcopy_argv[objcopy_argc++] = "objcopy";
+  objcopy_argv[objcopy_argc++] = "-B";
+  objcopy_argv[objcopy_argc++] = "i386";
+  objcopy_argv[objcopy_argc++] = "-I";
+  objcopy_argv[objcopy_argc++] = "binary";
+  objcopy_argv[objcopy_argc++] = "-O";
   switch (offload_abi)
     {
     case OFFLOAD_ABI_LP64:
-      objcopy_argv[6] = "elf64-x86-64";
+      objcopy_argv[objcopy_argc++] = "elf64-x86-64";
       break;
     case OFFLOAD_ABI_ILP32:
-      objcopy_argv[6] = "elf32-i386";
+      objcopy_argv[objcopy_argc++] = "elf32-i386";
       break;
     default:
       abort ();
     }
-  objcopy_argv[7] = target_so_filename;
-  objcopy_argv[8] = "--rename-section";
-  objcopy_argv[9] = rename_section_opt;
-  objcopy_argv[10] = NULL;
+  objcopy_argv[objcopy_argc++] = target_so_filename;
+  objcopy_argv[objcopy_argc++] = "--rename-section";
+  objcopy_argv[objcopy_argc++] = rename_section_opt;
+  objcopy_argv[objcopy_argc++] = NULL;
+  gcc_checking_assert (objcopy_argc <= OBJCOPY_ARGC_MAX);
   fork_execute (objcopy_argv[0], CONST_CAST (char **, objcopy_argv), false);
 
   /* Objcopy has created symbols, containing the input file name with
@@ -500,17 +508,21 @@ prepare_target_image (const char *target_compiler, int argc, char **argv)
   sprintf (opt_for_objcopy[1], "_binary_%s_end=%s", symbol_name, symbols[1]);
   sprintf (opt_for_objcopy[2], "_binary_%s_size=%s", symbol_name, symbols[2]);
 
-  objcopy_argv[0] = "objcopy";
-  objcopy_argv[1] = target_so_filename;
-  objcopy_argv[2] = "--redefine-sym";
-  objcopy_argv[3] = opt_for_objcopy[0];
-  objcopy_argv[4] = "--redefine-sym";
-  objcopy_argv[5] = opt_for_objcopy[1];
-  objcopy_argv[6] = "--redefine-sym";
-  objcopy_argv[7] = opt_for_objcopy[2];
-  objcopy_argv[8] = NULL;
+  objcopy_argc = 0;
+  objcopy_argv[objcopy_argc++] = "objcopy";
+  objcopy_argv[objcopy_argc++] = target_so_filename;
+  objcopy_argv[objcopy_argc++] = "--redefine-sym";
+  objcopy_argv[objcopy_argc++] = opt_for_objcopy[0];
+  objcopy_argv[objcopy_argc++] = "--redefine-sym";
+  objcopy_argv[objcopy_argc++] = opt_for_objcopy[1];
+  objcopy_argv[objcopy_argc++] = "--redefine-sym";
+  objcopy_argv[objcopy_argc++] = opt_for_objcopy[2];
+  objcopy_argv[objcopy_argc++] = NULL;
+  gcc_checking_assert (objcopy_argc <= OBJCOPY_ARGC_MAX);
   fork_execute (objcopy_argv[0], CONST_CAST (char **, objcopy_argv), false);
 
+#undef OBJCOPY_ARGC_MAX
+
   return target_so_filename;
 }
 
@@ -560,10 +572,13 @@ main (int argc, char **argv)
 
   const char *host_descr_filename = generate_host_descr_file (host_compiler);
 
+  unsigned new_argc;
+#define NEW_ARGC_MAX 9
+  const char *new_argv[NEW_ARGC_MAX];
+
   /* Perform partial linking for the target image and host side descriptor.
      As a result we'll get a finalized object file with all offload data.  */
-  unsigned new_argc = 0;
-  const char *new_argv[9];
+  new_argc = 0;
   new_argv[new_argc++] = "ld";
   new_argv[new_argc++] = "-m";
   switch (offload_abi)
@@ -583,20 +598,25 @@ main (int argc, char **argv)
   new_argv[new_argc++] = "-o";
   new_argv[new_argc++] = out_obj_filename;
   new_argv[new_argc++] = NULL;
+  gcc_checking_assert (new_argc <= NEW_ARGC_MAX);
   fork_execute (new_argv[0], CONST_CAST (char **, new_argv), false);
 
   /* Run objcopy on the resultant object file to localize generated symbols
      to avoid conflicting between different DSO and an executable.  */
-  new_argv[0] = "objcopy";
-  new_argv[1] = "-L";
-  new_argv[2] = symbols[0];
-  new_argv[3] = "-L";
-  new_argv[4] = symbols[1];
-  new_argv[5] = "-L";
-  new_argv[6] = symbols[2];
-  new_argv[7] = out_obj_filename;
-  new_argv[8] = NULL;
+  new_argc = 0;
+  new_argv[new_argc++] = "objcopy";
+  new_argv[new_argc++] = "-L";
+  new_argv[new_argc++] = symbols[0];
+  new_argv[new_argc++] = "-L";
+  new_argv[new_argc++] = symbols[1];
+  new_argv[new_argc++] = "-L";
+  new_argv[new_argc++] = symbols[2];
+  new_argv[new_argc++] = out_obj_filename;
+  new_argv[new_argc++] = NULL;
+  gcc_checking_assert (new_argc <= NEW_ARGC_MAX);
   fork_execute (new_argv[0], CONST_CAST (char **, new_argv), false);
 
+#undef NEW_ARGC_MAX
+
   return 0;
 }


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2015-09-28  9:39       ` Thomas Schwinge
@ 2015-09-28 11:26         ` Bernd Schmidt
  2015-09-28 11:27           ` Bernd Schmidt
  0 siblings, 1 reply; 111+ messages in thread
From: Bernd Schmidt @ 2015-09-28 11:26 UTC (permalink / raw)
  To: Thomas Schwinge, gcc-patches, Ilya Verbin, Jakub Jelinek
  Cc: Kirill Yukhin, Andrey Turetskiy

On 09/28/2015 10:26 AM, Thomas Schwinge wrote:
> -  objcopy_argv[8] = NULL;
> +  objcopy_argv[objcopy_argc++] = NULL;
> +  gcc_checking_assert (objcopy_argc <= OBJCOPY_ARGC_MAX);

On its own this is not an improvement - you're trading a compile time 
error for a runtime error. So, what is the other change this is 
preparing for?


Bernd

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2015-09-28 11:26         ` Bernd Schmidt
@ 2015-09-28 11:27           ` Bernd Schmidt
  2015-09-28 12:00             ` Ilya Verbin
  0 siblings, 1 reply; 111+ messages in thread
From: Bernd Schmidt @ 2015-09-28 11:27 UTC (permalink / raw)
  To: Thomas Schwinge, gcc-patches, Ilya Verbin, Jakub Jelinek
  Cc: Kirill Yukhin, Andrey Turetskiy

On 09/28/2015 12:03 PM, Bernd Schmidt wrote:
> On 09/28/2015 10:26 AM, Thomas Schwinge wrote:
>> -  objcopy_argv[8] = NULL;
>> +  objcopy_argv[objcopy_argc++] = NULL;
>> +  gcc_checking_assert (objcopy_argc <= OBJCOPY_ARGC_MAX);
>
> On its own this is not an improvement - you're trading a compile time
> error for a runtime error. So, what is the other change this is
> preparing for?

Ok, I now see the other patch. But I also see that other code in the 
same file and in the nvptx mkoffload is using the obstack_ptr_grow 
method to build argv arrays, I think that would be preferrable to this.


Bernd

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: Use gcc/coretypes.h:enum offload_abi in mkoffloads
  2015-09-28  8:26                 ` Use gcc/coretypes.h:enum offload_abi in mkoffloads Thomas Schwinge
@ 2015-09-28 11:28                   ` Bernd Schmidt
  2015-09-30 10:05                     ` Thomas Schwinge
  0 siblings, 1 reply; 111+ messages in thread
From: Bernd Schmidt @ 2015-09-28 11:28 UTC (permalink / raw)
  To: Thomas Schwinge, H.J. Lu, Jakub Jelinek, Ilya Verbin, GCC Patches
  Cc: Kirill Yukhin, Andrey Turetskiy

Hi Thomas,

Your patch submissions are sometimes very verbose which makes them hard 
to follow.

>> commit de4d7cbcf979edc095a48dff5b38d12846bdab6f
>> Author: Thomas Schwinge <thomas@codesourcery.com>
>> Date:   Tue Aug 4 13:12:36 2015 +0200

Cut unnecessary information such as this. git headers are uninteresting.

>>      Use gcc/coretypes.h:enum offload_abi in mkoffloads
>
> That one included unfortunate yet popular ;-) strcmp "typos":
>
>> +#define STR "-foffload-abi="
>> +      if (strncmp (argv[i], STR, strlen (STR)) == 0)
>> +	{
>> +	  if (strcmp (argv[i] + strlen (STR), "lp64"))
>> +	    offload_abi = OFFLOAD_ABI_LP64;
>> +	  else if (strcmp (argv[i] + strlen (STR), "ilp32"))
>> +	    offload_abi = OFFLOAD_ABI_ILP32;
>
> ..., so with these fixed up:
>
> --- gcc/config/i386/intelmic-mkoffload.c
> +++ gcc/config/i386/intelmic-mkoffload.c
> @@ -544,9 +544,9 @@ main (int argc, char **argv)
>   #define STR "-foffload-abi="
>         if (strncmp (argv[i], STR, strlen (STR)) == 0)
>   	{
> -	  if (strcmp (argv[i] + strlen (STR), "lp64"))
> +	  if (strcmp (argv[i] + strlen (STR), "lp64") == 0)
>   	    offload_abi = OFFLOAD_ABI_LP64;
> -	  else if (strcmp (argv[i] + strlen (STR), "ilp32"))
> +	  else if (strcmp (argv[i] + strlen (STR), "ilp32") == 0)
>   	    offload_abi = OFFLOAD_ABI_ILP32;
>   	  else
>   	    fatal_error (input_location,
> --- gcc/config/nvptx/mkoffload.c
> +++ gcc/config/nvptx/mkoffload.c
> @@ -1013,9 +1013,9 @@ main (int argc, char **argv)
>   #define STR "-foffload-abi="
>         if (strncmp (argv[i], STR, strlen (STR)) == 0)
>   	{
> -	  if (strcmp (argv[i] + strlen (STR), "lp64"))
> +	  if (strcmp (argv[i] + strlen (STR), "lp64") == 0)
>   	    offload_abi = OFFLOAD_ABI_LP64;
> -	  else if (strcmp (argv[i] + strlen (STR), "ilp32"))
> +	  else if (strcmp (argv[i] + strlen (STR), "ilp32") == 0)
>   	    offload_abi = OFFLOAD_ABI_ILP32;
>   	  else
>   	    fatal_error (input_location,

This confused me for a while because I thought you were proposing the 
above patch. A single line "I fixed that in the following version" would 
have been a clearer way to communicate that doesn't take up a page of space.

> ..., I'll again propose the following patch for trunk:
>
> commit 9288882278239a9d346ebde99e616185a91fbfaf
> Author: Thomas Schwinge <thomas@codesourcery.com>
> Date:   Tue Aug 4 13:12:36 2015 +0200
>
>      Use gcc/coretypes.h:enum offload_abi in mkoffloads
>
>      	gcc/
>      	* config/i386/intelmic-mkoffload.c (target_ilp32): Remove
>      	variable, replacing it with...
>      	(offload_abi): ... this new variable.  Adjust all users.
>      	* config/nvptx/mkoffload.c (target_ilp32, offload_abi): Likewise.
> ---
>   gcc/config/i386/intelmic-mkoffload.c |   90 +++++++++++++++++++++++-----------
>   gcc/config/nvptx/mkoffload.c         |   56 +++++++++++++++------
>   2 files changed, 101 insertions(+), 45 deletions(-)

Just the ChangeLog please, not the other noise.

> +      abort ();

Can we have gcc_unreachable() in these tools?

Other than that, it looks ok but it also doesn't seem to do anything. 
Are you intending to add more ABIs?


Bernd

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2015-09-28 11:27           ` Bernd Schmidt
@ 2015-09-28 12:00             ` Ilya Verbin
  2015-09-28 12:05               ` Bernd Schmidt
  0 siblings, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2015-09-28 12:00 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: Thomas Schwinge, gcc-patches, Jakub Jelinek, Kirill Yukhin

On Mon, Sep 28, 2015 at 12:09:19 +0200, Bernd Schmidt wrote:
> On 09/28/2015 12:03 PM, Bernd Schmidt wrote:
> >On 09/28/2015 10:26 AM, Thomas Schwinge wrote:
> >>-  objcopy_argv[8] = NULL;
> >>+  objcopy_argv[objcopy_argc++] = NULL;
> >>+  gcc_checking_assert (objcopy_argc <= OBJCOPY_ARGC_MAX);
> >
> >On its own this is not an improvement - you're trading a compile time
> >error for a runtime error. So, what is the other change this is
> >preparing for?
> 
> Ok, I now see the other patch. But I also see that other code in the same
> file and in the nvptx mkoffload is using the obstack_ptr_grow method to
> build argv arrays, I think that would be preferrable to this.

I've removed obstack_ptr_grow for arrays with known sizes after this review:
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg02210.html

  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2015-09-28 12:00             ` Ilya Verbin
@ 2015-09-28 12:05               ` Bernd Schmidt
  2015-09-28 12:33                 ` Jakub Jelinek
  2015-09-30 17:55                 ` Refactor intelmic-mkoffload.c argv building to use obstacks (was: [PATCH 1/4] Add mkoffload for Intel MIC) Thomas Schwinge
  0 siblings, 2 replies; 111+ messages in thread
From: Bernd Schmidt @ 2015-09-28 12:05 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: Thomas Schwinge, gcc-patches, Jakub Jelinek, Kirill Yukhin

On 09/28/2015 01:25 PM, Ilya Verbin wrote:
> On Mon, Sep 28, 2015 at 12:09:19 +0200, Bernd Schmidt wrote:
>> On 09/28/2015 12:03 PM, Bernd Schmidt wrote:
>>> On 09/28/2015 10:26 AM, Thomas Schwinge wrote:
>>>> -  objcopy_argv[8] = NULL;
>>>> +  objcopy_argv[objcopy_argc++] = NULL;
>>>> +  gcc_checking_assert (objcopy_argc <= OBJCOPY_ARGC_MAX);
>>>
>>> On its own this is not an improvement - you're trading a compile time
>>> error for a runtime error. So, what is the other change this is
>>> preparing for?
>>
>> Ok, I now see the other patch. But I also see that other code in the same
>> file and in the nvptx mkoffload is using the obstack_ptr_grow method to
>> build argv arrays, I think that would be preferrable to this.
>
> I've removed obstack_ptr_grow for arrays with known sizes after this review:
> https://gcc.gnu.org/ml/gcc-patches/2014-10/msg02210.html

That's unfortunate, I think that made the code less future-proof. IMO we 
should revert to the obstack method especially if Thomas -v patch goes in.


Bernd

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2015-09-28 12:05               ` Bernd Schmidt
@ 2015-09-28 12:33                 ` Jakub Jelinek
  2015-09-28 12:33                   ` Bernd Schmidt
  2015-09-30 17:55                 ` Refactor intelmic-mkoffload.c argv building to use obstacks (was: [PATCH 1/4] Add mkoffload for Intel MIC) Thomas Schwinge
  1 sibling, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2015-09-28 12:33 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: Ilya Verbin, Thomas Schwinge, gcc-patches, Kirill Yukhin

On Mon, Sep 28, 2015 at 01:27:32PM +0200, Bernd Schmidt wrote:
> >I've removed obstack_ptr_grow for arrays with known sizes after this review:
> >https://gcc.gnu.org/ml/gcc-patches/2014-10/msg02210.html
> 
> That's unfortunate, I think that made the code less future-proof. IMO we
> should revert to the obstack method especially if Thomas -v patch goes in.

Why?  If the number of arguments is bound by a small constant, using
automatic fixed size array is certainly more efficient, and I really don't
see it as less readable or maintainable.

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2015-09-28 12:33                 ` Jakub Jelinek
@ 2015-09-28 12:33                   ` Bernd Schmidt
  2015-09-29 11:24                     ` Richard Biener
  0 siblings, 1 reply; 111+ messages in thread
From: Bernd Schmidt @ 2015-09-28 12:33 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Ilya Verbin, Thomas Schwinge, gcc-patches, Kirill Yukhin

On 09/28/2015 02:00 PM, Jakub Jelinek wrote:
> On Mon, Sep 28, 2015 at 01:27:32PM +0200, Bernd Schmidt wrote:
>>> I've removed obstack_ptr_grow for arrays with known sizes after this review:
>>> https://gcc.gnu.org/ml/gcc-patches/2014-10/msg02210.html
>>
>> That's unfortunate, I think that made the code less future-proof. IMO we
>> should revert to the obstack method especially if Thomas -v patch goes in.
>
> Why?  If the number of arguments is bound by a small constant, using
> automatic fixed size array is certainly more efficient, and I really don't
> see it as less readable or maintainable.

The code becomes harder to modify, with more room for error, and you no 
longer have consistency in how you build argv arrays within the same 
file. The obstack method is pretty much foolproof and doesn't even 
remotely allow for the possibility of a buffer overflow, and adding new 
arguments, even conditionally, is entirely trivial. Efficiency is really 
not an issue for building arguments compared to the cost of executing 
another binary.


Bernd

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2015-09-28 12:33                   ` Bernd Schmidt
@ 2015-09-29 11:24                     ` Richard Biener
  2015-09-29 12:11                       ` Bernd Schmidt
  0 siblings, 1 reply; 111+ messages in thread
From: Richard Biener @ 2015-09-29 11:24 UTC (permalink / raw)
  To: Bernd Schmidt
  Cc: Jakub Jelinek, Ilya Verbin, Thomas Schwinge, GCC Patches, Kirill Yukhin

On Mon, Sep 28, 2015 at 2:05 PM, Bernd Schmidt <bschmidt@redhat.com> wrote:
> On 09/28/2015 02:00 PM, Jakub Jelinek wrote:
>>
>> On Mon, Sep 28, 2015 at 01:27:32PM +0200, Bernd Schmidt wrote:
>>>>
>>>> I've removed obstack_ptr_grow for arrays with known sizes after this
>>>> review:
>>>> https://gcc.gnu.org/ml/gcc-patches/2014-10/msg02210.html
>>>
>>>
>>> That's unfortunate, I think that made the code less future-proof. IMO we
>>> should revert to the obstack method especially if Thomas -v patch goes
>>> in.
>>
>>
>> Why?  If the number of arguments is bound by a small constant, using
>> automatic fixed size array is certainly more efficient, and I really don't
>> see it as less readable or maintainable.
>
>
> The code becomes harder to modify, with more room for error, and you no
> longer have consistency in how you build argv arrays within the same file.
> The obstack method is pretty much foolproof and doesn't even remotely allow
> for the possibility of a buffer overflow, and adding new arguments, even
> conditionally, is entirely trivial. Efficiency is really not an issue for
> building arguments compared to the cost of executing another binary.

I agree that obstacks are better here.  Efficiency shouldn't matter here.
But we're in C++ now so can't we statically construct the array with
sth like

const char *new_argv[] = { "objcopy", ... };

?  Thus have the compiler figure out the number of args.  That would work
for me as well.

Richard.

>
> Bernd

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 1/4] Add mkoffload for Intel MIC
  2015-09-29 11:24                     ` Richard Biener
@ 2015-09-29 12:11                       ` Bernd Schmidt
  0 siblings, 0 replies; 111+ messages in thread
From: Bernd Schmidt @ 2015-09-29 12:11 UTC (permalink / raw)
  To: Richard Biener
  Cc: Jakub Jelinek, Ilya Verbin, Thomas Schwinge, GCC Patches, Kirill Yukhin

On 09/29/2015 12:29 PM, Richard Biener wrote:
> I agree that obstacks are better here.  Efficiency shouldn't matter here.
> But we're in C++ now so can't we statically construct the array with
> sth like
>
> const char *new_argv[] = { "objcopy", ... };
>
> ?  Thus have the compiler figure out the number of args.  That would work
> for me as well.

The issue is that the code is about to be changed to conditionally pass 
certain arguments ("-v"), so you no longer have a fixed arglist.


Bernd

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: Use gcc/coretypes.h:enum offload_abi in mkoffloads
  2015-09-28 11:28                   ` Bernd Schmidt
@ 2015-09-30 10:05                     ` Thomas Schwinge
  0 siblings, 0 replies; 111+ messages in thread
From: Thomas Schwinge @ 2015-09-30 10:05 UTC (permalink / raw)
  To: Bernd Schmidt, H.J. Lu
  Cc: Kirill Yukhin, Andrey Turetskiy, Jakub Jelinek, Ilya Verbin, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 9748 bytes --]

Hi!

On Mon, 28 Sep 2015 12:19:41 +0200, Bernd Schmidt <bschmidt@redhat.com> wrote:
> >      Use gcc/coretypes.h:enum offload_abi in mkoffloads

> > +      abort ();
> 
> Can we have gcc_unreachable() in these tools?

Good suggestion, thanks!

> Other than that, it looks ok but it also doesn't seem to do anything. 

Thanks for the review.  This refactoring patch happend to come into
existance when I worked on the other mkoffload patches that I recently
posted, and as I considered it an improvement in its own right, I posted
it.

> Are you intending to add more ABIs?

As I had quoted in my previous email, H.J. Lu expressed an interest in
supporting the x32 ABI,
<http://news.gmane.org/find-root.php?message_id=%3CCAMe9rOoG5e2NHusRggT-5BN4O_kszixEduK-S%2BU72JPjNv4LPA%40mail.gmail.com%3E>,
which is now more easy to do than before.

With the abort calls replaced with gcc_unreachable, committed in r228283:

commit dc0452858cb0d7f56fada1bb2f795f92cd551795
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed Sep 30 08:58:04 2015 +0000

    Use gcc/coretypes.h:enum offload_abi in mkoffloads
    
    	gcc/
    	* config/i386/intelmic-mkoffload.c (target_ilp32): Remove
    	variable, replacing it with...
    	(offload_abi): ... this new variable.  Adjust all users.
    	* config/nvptx/mkoffload.c (target_ilp32, offload_abi): Likewise.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@228283 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog                        |  7 +++
 gcc/config/i386/intelmic-mkoffload.c | 90 ++++++++++++++++++++++++------------
 gcc/config/nvptx/mkoffload.c         | 56 +++++++++++++++-------
 3 files changed, 108 insertions(+), 45 deletions(-)

diff --git gcc/ChangeLog gcc/ChangeLog
index e24c7bc..d29e5d9 100644
--- gcc/ChangeLog
+++ gcc/ChangeLog
@@ -1,3 +1,10 @@
+2015-09-30  Thomas Schwinge  <thomas@codesourcery.com>
+
+	* config/i386/intelmic-mkoffload.c (target_ilp32): Remove
+	variable, replacing it with...
+	(offload_abi): ... this new variable.  Adjust all users.
+	* config/nvptx/mkoffload.c (target_ilp32, offload_abi): Likewise.
+
 2015-09-30  Matthias Klose  <doko@ubuntu.com>
 
 	* configure.ac: Remove extraneous ;;.
diff --git gcc/config/i386/intelmic-mkoffload.c gcc/config/i386/intelmic-mkoffload.c
index 4a7812c..065d408 100644
--- gcc/config/i386/intelmic-mkoffload.c
+++ gcc/config/i386/intelmic-mkoffload.c
@@ -42,8 +42,7 @@ int num_temps = 0;
 const int MAX_NUM_TEMPS = 10;
 const char *temp_files[MAX_NUM_TEMPS];
 
-/* Shows if we should compile binaries for i386 instead of x86-64.  */
-bool target_ilp32 = false;
+enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
 
 /* Delete tempfiles and exit function.  */
 void
@@ -200,10 +199,17 @@ out:
 static void
 compile_for_target (struct obstack *argv_obstack)
 {
-  if (target_ilp32)
-    obstack_ptr_grow (argv_obstack, "-m32");
-  else
-    obstack_ptr_grow (argv_obstack, "-m64");
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      obstack_ptr_grow (argv_obstack, "-m64");
+      break;
+    case OFFLOAD_ABI_ILP32:
+      obstack_ptr_grow (argv_obstack, "-m32");
+      break;
+    default:
+      gcc_unreachable ();
+    }
   obstack_ptr_grow (argv_obstack, NULL);
   char **argv = XOBFINISH (argv_obstack, char **);
 
@@ -379,10 +385,17 @@ generate_host_descr_file (const char *host_compiler)
   new_argv[new_argc++] = "-c";
   new_argv[new_argc++] = "-fPIC";
   new_argv[new_argc++] = "-shared";
-  if (target_ilp32)
-    new_argv[new_argc++] = "-m32";
-  else
-    new_argv[new_argc++] = "-m64";
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      new_argv[new_argc++] = "-m64";
+      break;
+    case OFFLOAD_ABI_ILP32:
+      new_argv[new_argc++] = "-m32";
+      break;
+    default:
+      gcc_unreachable ();
+    }
   new_argv[new_argc++] = src_filename;
   new_argv[new_argc++] = "-o";
   new_argv[new_argc++] = obj_filename;
@@ -442,10 +455,17 @@ prepare_target_image (const char *target_compiler, int argc, char **argv)
   objcopy_argv[3] = "-I";
   objcopy_argv[4] = "binary";
   objcopy_argv[5] = "-O";
-  if (target_ilp32)
-    objcopy_argv[6] = "elf32-i386";
-  else
-    objcopy_argv[6] = "elf64-x86-64";
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      objcopy_argv[6] = "elf64-x86-64";
+      break;
+    case OFFLOAD_ABI_ILP32:
+      objcopy_argv[6] = "elf32-i386";
+      break;
+    default:
+      gcc_unreachable ();
+    }
   objcopy_argv[7] = target_so_filename;
   objcopy_argv[8] = "--rename-section";
   objcopy_argv[9] = rename_section_opt;
@@ -518,17 +538,22 @@ main (int argc, char **argv)
      passed with @file.  Expand them into argv before processing.  */
   expandargv (&argc, &argv);
 
-  /* Find out whether we should compile binaries for i386 or x86-64.  */
-  for (int i = argc - 1; i > 0; i--)
-    if (strncmp (argv[i], "-foffload-abi=", sizeof ("-foffload-abi=") - 1) == 0)
-      {
-	if (strstr (argv[i], "ilp32"))
-	  target_ilp32 = true;
-	else if (!strstr (argv[i], "lp64"))
-	  fatal_error (input_location,
-		       "unrecognizable argument of option -foffload-abi");
-	break;
-      }
+  /* Scan the argument vector.  */
+  for (int i = 1; i < argc; i++)
+    {
+#define STR "-foffload-abi="
+      if (strncmp (argv[i], STR, strlen (STR)) == 0)
+	{
+	  if (strcmp (argv[i] + strlen (STR), "lp64") == 0)
+	    offload_abi = OFFLOAD_ABI_LP64;
+	  else if (strcmp (argv[i] + strlen (STR), "ilp32") == 0)
+	    offload_abi = OFFLOAD_ABI_ILP32;
+	  else
+	    fatal_error (input_location,
+			 "unrecognizable argument of option " STR);
+	}
+#undef STR
+    }
 
   const char *target_so_filename
     = prepare_target_image (target_compiler, argc, argv);
@@ -541,10 +566,17 @@ main (int argc, char **argv)
   const char *new_argv[9];
   new_argv[new_argc++] = "ld";
   new_argv[new_argc++] = "-m";
-  if (target_ilp32)
-    new_argv[new_argc++] = "elf_i386";
-  else
-    new_argv[new_argc++] = "elf_x86_64";
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      new_argv[new_argc++] = "elf_x86_64";
+      break;
+    case OFFLOAD_ABI_ILP32:
+      new_argv[new_argc++] = "elf_i386";
+      break;
+    default:
+      gcc_unreachable ();
+    }
   new_argv[new_argc++] = "--relocatable";
   new_argv[new_argc++] = host_descr_filename;
   new_argv[new_argc++] = target_so_filename;
diff --git gcc/config/nvptx/mkoffload.c gcc/config/nvptx/mkoffload.c
index e0ff8fc..fe0e8cd 100644
--- gcc/config/nvptx/mkoffload.c
+++ gcc/config/nvptx/mkoffload.c
@@ -126,8 +126,7 @@ static id_map *var_ids, **vars_tail = &var_ids;
 static const char *ptx_name;
 static const char *ptx_cfile_name;
 
-/* Shows if we should compile binaries for i386 instead of x86-64.  */
-bool target_ilp32 = false;
+enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
 
 /* Delete tempfiles.  */
 
@@ -926,7 +925,17 @@ compile_native (const char *infile, const char *outfile, const char *compiler)
   struct obstack argv_obstack;
   obstack_init (&argv_obstack);
   obstack_ptr_grow (&argv_obstack, compiler);
-  obstack_ptr_grow (&argv_obstack, target_ilp32 ? "-m32" : "-m64");
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      obstack_ptr_grow (&argv_obstack, "-m64");
+      break;
+    case OFFLOAD_ABI_ILP32:
+      obstack_ptr_grow (&argv_obstack, "-m32");
+      break;
+    default:
+      gcc_unreachable ();
+    }
   obstack_ptr_grow (&argv_obstack, infile);
   obstack_ptr_grow (&argv_obstack, "-c");
   obstack_ptr_grow (&argv_obstack, "-o");
@@ -1004,23 +1013,38 @@ main (int argc, char **argv)
      passed with @file.  Expand them into argv before processing.  */
   expandargv (&argc, &argv);
 
-  /* Find out whether we should compile binaries for i386 or x86-64.  */
-  for (int i = argc - 1; i > 0; i--)
-    if (strncmp (argv[i], "-foffload-abi=", sizeof ("-foffload-abi=") - 1) == 0)
-      {
-	if (strstr (argv[i], "ilp32"))
-	  target_ilp32 = true;
-	else if (!strstr (argv[i], "lp64"))
-	  fatal_error (input_location,
-		       "unrecognizable argument of option -foffload-abi");
-	break;
-      }
+  /* Scan the argument vector.  */
+  for (int i = 1; i < argc; i++)
+    {
+#define STR "-foffload-abi="
+      if (strncmp (argv[i], STR, strlen (STR)) == 0)
+	{
+	  if (strcmp (argv[i] + strlen (STR), "lp64") == 0)
+	    offload_abi = OFFLOAD_ABI_LP64;
+	  else if (strcmp (argv[i] + strlen (STR), "ilp32") == 0)
+	    offload_abi = OFFLOAD_ABI_ILP32;
+	  else
+	    fatal_error (input_location,
+			 "unrecognizable argument of option " STR);
+	}
+#undef STR
+    }
 
   struct obstack argv_obstack;
   obstack_init (&argv_obstack);
   obstack_ptr_grow (&argv_obstack, driver);
   obstack_ptr_grow (&argv_obstack, "-xlto");
-  obstack_ptr_grow (&argv_obstack, target_ilp32 ? "-m32" : "-m64");
+  switch (offload_abi)
+    {
+    case OFFLOAD_ABI_LP64:
+      obstack_ptr_grow (&argv_obstack, "-m64");
+      break;
+    case OFFLOAD_ABI_ILP32:
+      obstack_ptr_grow (&argv_obstack, "-m32");
+      break;
+    default:
+      gcc_unreachable ();
+    }
   obstack_ptr_grow (&argv_obstack, "-S");
 
   for (int ix = 1; ix != argc; ix++)
@@ -1039,7 +1063,7 @@ main (int argc, char **argv)
 
   /* PR libgomp/65099: Currently, we only support offloading in 64-bit
      configurations.  */
-  if (!target_ilp32)
+  if (offload_abi == OFFLOAD_ABI_LP64)
     {
       ptx_name = make_temp_file (".mkoffload");
       obstack_ptr_grow (&argv_obstack, "-o");


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Refactor intelmic-mkoffload.c argv building to use obstacks (was: [PATCH 1/4] Add mkoffload for Intel MIC)
  2015-09-28 12:05               ` Bernd Schmidt
  2015-09-28 12:33                 ` Jakub Jelinek
@ 2015-09-30 17:55                 ` Thomas Schwinge
  1 sibling, 0 replies; 111+ messages in thread
From: Thomas Schwinge @ 2015-09-30 17:55 UTC (permalink / raw)
  To: gcc-patches, Bernd Schmidt, Ilya Verbin; +Cc: Jakub Jelinek, Kirill Yukhin

[-- Attachment #1: Type: text/plain, Size: 10359 bytes --]

Hi!

On Mon, 28 Sep 2015 13:27:32 +0200, Bernd Schmidt <bschmidt@redhat.com> wrote:
> On 09/28/2015 01:25 PM, Ilya Verbin wrote:
> > On Mon, Sep 28, 2015 at 12:09:19 +0200, Bernd Schmidt wrote:
> >> On 09/28/2015 12:03 PM, Bernd Schmidt wrote:
> >>> On 09/28/2015 10:26 AM, Thomas Schwinge wrote:
> >>>> -  objcopy_argv[8] = NULL;
> >>>> +  objcopy_argv[objcopy_argc++] = NULL;
> >>>> +  gcc_checking_assert (objcopy_argc <= OBJCOPY_ARGC_MAX);
> >>>
> >>> On its own this is not an improvement - you're trading a compile time
> >>> error for a runtime error. So, what is the other change this is
> >>> preparing for?
> >>
> >> Ok, I now see the other patch. But I also see that other code in the same
> >> file and in the nvptx mkoffload is using the obstack_ptr_grow method to
> >> build argv arrays, I think that would be preferrable to this.
> >
> > I've removed obstack_ptr_grow for arrays with known sizes after this review:
> > https://gcc.gnu.org/ml/gcc-patches/2014-10/msg02210.html
> 
> That's unfortunate, I think that made the code less future-proof. IMO we 
> should revert to the obstack method especially if Thomas -v patch goes in.

Given that the discussion has settled in favor of using obstacks, I have
committed the following in r228300:

commit 99043644772bdc4b76d44058014d664ce27867f7
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed Sep 30 16:42:22 2015 +0000

    Refactor intelmic-mkoffload.c argv building to use obstacks
    
    That is, restore and adapt the code as originally proposed.
    
    	gcc/
    	* config/i386/intelmic-mkoffload.c (generate_host_descr_file)
    	(prepare_target_image, main): Refactor argv building to use
    	obstacks.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@228300 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog                        |   8 +++
 gcc/config/i386/intelmic-mkoffload.c | 132 +++++++++++++++++++----------------
 2 files changed, 80 insertions(+), 60 deletions(-)

diff --git gcc/ChangeLog gcc/ChangeLog
index 86f81d6..15f84ab 100644
--- gcc/ChangeLog
+++ gcc/ChangeLog
@@ -1,3 +1,11 @@
+2015-09-30  Thomas Schwinge  <thomas@codesourcery.com>
+	    Ilya Verbin  <ilya.verbin@intel.com>
+	    Andrey Turetskiy  <andrey.turetskiy@intel.com>
+
+	* config/i386/intelmic-mkoffload.c (generate_host_descr_file)
+	(prepare_target_image, main): Refactor argv building to use
+	obstacks.
+
 2015-09-30  Ulrich Weigand  <Ulrich.Weigand@de.ibm.com>
 
 	* config/spu/spu-protos.h (spu_expand_atomic_op): Add prototype.
diff --git gcc/config/i386/intelmic-mkoffload.c gcc/config/i386/intelmic-mkoffload.c
index 065d408..ae88ecd 100644
--- gcc/config/i386/intelmic-mkoffload.c
+++ gcc/config/i386/intelmic-mkoffload.c
@@ -379,29 +379,31 @@ generate_host_descr_file (const char *host_compiler)
 
   fclose (src_file);
 
-  unsigned new_argc = 0;
-  const char *new_argv[9];
-  new_argv[new_argc++] = host_compiler;
-  new_argv[new_argc++] = "-c";
-  new_argv[new_argc++] = "-fPIC";
-  new_argv[new_argc++] = "-shared";
+  struct obstack argv_obstack;
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, host_compiler);
+  obstack_ptr_grow (&argv_obstack, "-c");
+  obstack_ptr_grow (&argv_obstack, "-fPIC");
+  obstack_ptr_grow (&argv_obstack, "-shared");
   switch (offload_abi)
     {
     case OFFLOAD_ABI_LP64:
-      new_argv[new_argc++] = "-m64";
+      obstack_ptr_grow (&argv_obstack, "-m64");
       break;
     case OFFLOAD_ABI_ILP32:
-      new_argv[new_argc++] = "-m32";
+      obstack_ptr_grow (&argv_obstack, "-m32");
       break;
     default:
       gcc_unreachable ();
     }
-  new_argv[new_argc++] = src_filename;
-  new_argv[new_argc++] = "-o";
-  new_argv[new_argc++] = obj_filename;
-  new_argv[new_argc++] = NULL;
+  obstack_ptr_grow (&argv_obstack, src_filename);
+  obstack_ptr_grow (&argv_obstack, "-o");
+  obstack_ptr_grow (&argv_obstack, obj_filename);
+  obstack_ptr_grow (&argv_obstack, NULL);
 
-  fork_execute (new_argv[0], CONST_CAST (char **, new_argv), false);
+  char **argv = XOBFINISH (&argv_obstack, char **);
+  fork_execute (argv[0], argv, false);
+  obstack_free (&argv_obstack, NULL);
 
   return obj_filename;
 }
@@ -448,29 +450,31 @@ prepare_target_image (const char *target_compiler, int argc, char **argv)
   char *rename_section_opt
     = XALLOCAVEC (char, sizeof (".data=") + strlen (image_section_name));
   sprintf (rename_section_opt, ".data=%s", image_section_name);
-  const char *objcopy_argv[11];
-  objcopy_argv[0] = "objcopy";
-  objcopy_argv[1] = "-B";
-  objcopy_argv[2] = "i386";
-  objcopy_argv[3] = "-I";
-  objcopy_argv[4] = "binary";
-  objcopy_argv[5] = "-O";
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, "objcopy");
+  obstack_ptr_grow (&argv_obstack, "-B");
+  obstack_ptr_grow (&argv_obstack, "i386");
+  obstack_ptr_grow (&argv_obstack, "-I");
+  obstack_ptr_grow (&argv_obstack, "binary");
+  obstack_ptr_grow (&argv_obstack, "-O");
   switch (offload_abi)
     {
     case OFFLOAD_ABI_LP64:
-      objcopy_argv[6] = "elf64-x86-64";
+      obstack_ptr_grow (&argv_obstack, "elf64-x86-64");
       break;
     case OFFLOAD_ABI_ILP32:
-      objcopy_argv[6] = "elf32-i386";
+      obstack_ptr_grow (&argv_obstack, "elf32-i386");
       break;
     default:
       gcc_unreachable ();
     }
-  objcopy_argv[7] = target_so_filename;
-  objcopy_argv[8] = "--rename-section";
-  objcopy_argv[9] = rename_section_opt;
-  objcopy_argv[10] = NULL;
-  fork_execute (objcopy_argv[0], CONST_CAST (char **, objcopy_argv), false);
+  obstack_ptr_grow (&argv_obstack, target_so_filename);
+  obstack_ptr_grow (&argv_obstack, "--rename-section");
+  obstack_ptr_grow (&argv_obstack, rename_section_opt);
+  obstack_ptr_grow (&argv_obstack, NULL);
+  char **new_argv = XOBFINISH (&argv_obstack, char **);
+  fork_execute (new_argv[0], new_argv, false);
+  obstack_free (&argv_obstack, NULL);
 
   /* Objcopy has created symbols, containing the input file name with
      non-alphanumeric characters replaced by underscores.
@@ -500,16 +504,19 @@ prepare_target_image (const char *target_compiler, int argc, char **argv)
   sprintf (opt_for_objcopy[1], "_binary_%s_end=%s", symbol_name, symbols[1]);
   sprintf (opt_for_objcopy[2], "_binary_%s_size=%s", symbol_name, symbols[2]);
 
-  objcopy_argv[0] = "objcopy";
-  objcopy_argv[1] = target_so_filename;
-  objcopy_argv[2] = "--redefine-sym";
-  objcopy_argv[3] = opt_for_objcopy[0];
-  objcopy_argv[4] = "--redefine-sym";
-  objcopy_argv[5] = opt_for_objcopy[1];
-  objcopy_argv[6] = "--redefine-sym";
-  objcopy_argv[7] = opt_for_objcopy[2];
-  objcopy_argv[8] = NULL;
-  fork_execute (objcopy_argv[0], CONST_CAST (char **, objcopy_argv), false);
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, "objcopy");
+  obstack_ptr_grow (&argv_obstack, target_so_filename);
+  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
+  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[0]);
+  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
+  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[1]);
+  obstack_ptr_grow (&argv_obstack, "--redefine-sym");
+  obstack_ptr_grow (&argv_obstack, opt_for_objcopy[2]);
+  obstack_ptr_grow (&argv_obstack, NULL);
+  new_argv = XOBFINISH (&argv_obstack, char **);
+  fork_execute (new_argv[0], new_argv, false);
+  obstack_free (&argv_obstack, NULL);
 
   return target_so_filename;
 }
@@ -562,41 +569,46 @@ main (int argc, char **argv)
 
   /* Perform partial linking for the target image and host side descriptor.
      As a result we'll get a finalized object file with all offload data.  */
-  unsigned new_argc = 0;
-  const char *new_argv[9];
-  new_argv[new_argc++] = "ld";
-  new_argv[new_argc++] = "-m";
+  struct obstack argv_obstack;
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, "ld");
+  obstack_ptr_grow (&argv_obstack, "-m");
   switch (offload_abi)
     {
     case OFFLOAD_ABI_LP64:
-      new_argv[new_argc++] = "elf_x86_64";
+      obstack_ptr_grow (&argv_obstack, "elf_x86_64");
       break;
     case OFFLOAD_ABI_ILP32:
-      new_argv[new_argc++] = "elf_i386";
+      obstack_ptr_grow (&argv_obstack, "elf_i386");
       break;
     default:
       gcc_unreachable ();
     }
-  new_argv[new_argc++] = "--relocatable";
-  new_argv[new_argc++] = host_descr_filename;
-  new_argv[new_argc++] = target_so_filename;
-  new_argv[new_argc++] = "-o";
-  new_argv[new_argc++] = out_obj_filename;
-  new_argv[new_argc++] = NULL;
-  fork_execute (new_argv[0], CONST_CAST (char **, new_argv), false);
+  obstack_ptr_grow (&argv_obstack, "--relocatable");
+  obstack_ptr_grow (&argv_obstack, host_descr_filename);
+  obstack_ptr_grow (&argv_obstack, target_so_filename);
+  obstack_ptr_grow (&argv_obstack, "-o");
+  obstack_ptr_grow (&argv_obstack, out_obj_filename);
+  obstack_ptr_grow (&argv_obstack, NULL);
+  char **new_argv = XOBFINISH (&argv_obstack, char **);
+  fork_execute (new_argv[0], new_argv, false);
+  obstack_free (&argv_obstack, NULL);
 
   /* Run objcopy on the resultant object file to localize generated symbols
      to avoid conflicting between different DSO and an executable.  */
-  new_argv[0] = "objcopy";
-  new_argv[1] = "-L";
-  new_argv[2] = symbols[0];
-  new_argv[3] = "-L";
-  new_argv[4] = symbols[1];
-  new_argv[5] = "-L";
-  new_argv[6] = symbols[2];
-  new_argv[7] = out_obj_filename;
-  new_argv[8] = NULL;
-  fork_execute (new_argv[0], CONST_CAST (char **, new_argv), false);
+  obstack_init (&argv_obstack);
+  obstack_ptr_grow (&argv_obstack, "objcopy");
+  obstack_ptr_grow (&argv_obstack, "-L");
+  obstack_ptr_grow (&argv_obstack, symbols[0]);
+  obstack_ptr_grow (&argv_obstack, "-L");
+  obstack_ptr_grow (&argv_obstack, symbols[1]);
+  obstack_ptr_grow (&argv_obstack, "-L");
+  obstack_ptr_grow (&argv_obstack, symbols[2]);
+  obstack_ptr_grow (&argv_obstack, out_obj_filename);
+  obstack_ptr_grow (&argv_obstack, NULL);
+  new_argv = XOBFINISH (&argv_obstack, char **);
+  fork_execute (new_argv[0], new_argv, false);
+  obstack_free (&argv_obstack, NULL);
 
   return 0;
 }


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC
  2014-12-22 12:08 ` [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC Thomas Schwinge
@ 2015-10-22 18:28   ` Ilya Verbin
  2015-10-23  8:10     ` Jakub Jelinek
  0 siblings, 1 reply; 111+ messages in thread
From: Ilya Verbin @ 2015-10-22 18:28 UTC (permalink / raw)
  To: Thomas Schwinge, Jakub Jelinek; +Cc: Kirill Yukhin, gcc-patches

On Mon, Dec 22, 2014 at 13:01:40 +0100, Thomas Schwinge wrote:
> By chance (when tracking down a different problem), I've found the
> following.  Would you please check whether that's a real problem in
> liboffloadmic, or its libgomp plugin, or just a mis-diagnosis by
> Valgrind?
> 
>     ==21327== Syscall param write(buf) points to uninitialised byte(s)

Finally we have investigated this :)  Valgrind warns about uninitialized bytes,
inserted into the struct for alignment.  It's possible to avoid the warning by
the patch bellow.  Should I commit it, or just leave it as is?


diff --git a/liboffloadmic/runtime/offload_host.cpp b/liboffloadmic/runtime/offload_host.cpp
index d04233f..66c2a01 100644
--- a/liboffloadmic/runtime/offload_host.cpp
+++ b/liboffloadmic/runtime/offload_host.cpp
@@ -2425,6 +2425,7 @@ bool OffloadDescriptor::setup_misc_data(const char *name)
                                                    misc_data_size);
         if (m_func_desc == NULL)
           LIBOFFLOAD_ERROR(c_malloc);
+	memset (m_func_desc, 0, m_func_desc_size + misc_data_size);
         m_func_desc->console_enabled = console_enabled;
         m_func_desc->timer_enabled = offload_report_enabled &&
             (timer_enabled || offload_report_level);


  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC
  2015-10-22 18:28   ` Ilya Verbin
@ 2015-10-23  8:10     ` Jakub Jelinek
  2015-10-26 14:39       ` Ilya Verbin
  0 siblings, 1 reply; 111+ messages in thread
From: Jakub Jelinek @ 2015-10-23  8:10 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: Thomas Schwinge, Kirill Yukhin, gcc-patches

On Thu, Oct 22, 2015 at 09:26:37PM +0300, Ilya Verbin wrote:
> On Mon, Dec 22, 2014 at 13:01:40 +0100, Thomas Schwinge wrote:
> > By chance (when tracking down a different problem), I've found the
> > following.  Would you please check whether that's a real problem in
> > liboffloadmic, or its libgomp plugin, or just a mis-diagnosis by
> > Valgrind?
> > 
> >     ==21327== Syscall param write(buf) points to uninitialised byte(s)
> 
> Finally we have investigated this :)  Valgrind warns about uninitialized bytes,
> inserted into the struct for alignment.  It's possible to avoid the warning by
> the patch bellow.  Should I commit it, or just leave it as is?

Or use calloc instead of malloc, or add two uint8_t padding fields after the
two uint8_t fields and initialize them too.  Though, as you have some
padding after the name, I think calloc is best.

> diff --git a/liboffloadmic/runtime/offload_host.cpp b/liboffloadmic/runtime/offload_host.cpp
> index d04233f..66c2a01 100644
> --- a/liboffloadmic/runtime/offload_host.cpp
> +++ b/liboffloadmic/runtime/offload_host.cpp
> @@ -2425,6 +2425,7 @@ bool OffloadDescriptor::setup_misc_data(const char *name)
>                                                     misc_data_size);
>          if (m_func_desc == NULL)
>            LIBOFFLOAD_ERROR(c_malloc);
> +	memset (m_func_desc, 0, m_func_desc_size + misc_data_size);
>          m_func_desc->console_enabled = console_enabled;
>          m_func_desc->timer_enabled = offload_report_enabled &&
>              (timer_enabled || offload_report_level);
> 
> 
>   -- Ilya

	Jakub

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC
  2015-10-23  8:10     ` Jakub Jelinek
@ 2015-10-26 14:39       ` Ilya Verbin
  0 siblings, 0 replies; 111+ messages in thread
From: Ilya Verbin @ 2015-10-26 14:39 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Thomas Schwinge, Kirill Yukhin, gcc-patches

On Fri, Oct 23, 2015 at 10:10:06 +0200, Jakub Jelinek wrote:
> On Thu, Oct 22, 2015 at 09:26:37PM +0300, Ilya Verbin wrote:
> > On Mon, Dec 22, 2014 at 13:01:40 +0100, Thomas Schwinge wrote:
> > > By chance (when tracking down a different problem), I've found the
> > > following.  Would you please check whether that's a real problem in
> > > liboffloadmic, or its libgomp plugin, or just a mis-diagnosis by
> > > Valgrind?
> > > 
> > >     ==21327== Syscall param write(buf) points to uninitialised byte(s)
> > 
> > Finally we have investigated this :)  Valgrind warns about uninitialized bytes,
> > inserted into the struct for alignment.  It's possible to avoid the warning by
> > the patch bellow.  Should I commit it, or just leave it as is?
> 
> Or use calloc instead of malloc, or add two uint8_t padding fields after the
> two uint8_t fields and initialize them too.  Though, as you have some
> padding after the name, I think calloc is best.

Here is what I committed to trunk together with an obvious change.


liboffloadmic/
	* runtime/offload_host.cpp (OffloadDescriptor::setup_misc_data): Use
	calloc instead of malloc.
	(__offload_fini_library): Set mic_engines_total to zero.


diff --git a/liboffloadmic/runtime/offload_host.cpp b/liboffloadmic/runtime/offload_host.cpp
index c6c6518..a150410 100644
--- a/liboffloadmic/runtime/offload_host.cpp
+++ b/liboffloadmic/runtime/offload_host.cpp
@@ -2424,8 +2424,8 @@ bool OffloadDescriptor::setup_misc_data(const char *name)
         }
 
         // initialize function descriptor
-        m_func_desc = (FunctionDescriptor*) malloc(m_func_desc_size +
-                                                   misc_data_size);
+        m_func_desc = (FunctionDescriptor*) calloc(1, m_func_desc_size
+						      + misc_data_size);
         if (m_func_desc == NULL)
           LIBOFFLOAD_ERROR(c_malloc);
         m_func_desc->console_enabled = console_enabled;
@@ -5090,6 +5090,7 @@ static void __offload_fini_library(void)
     OFFLOAD_DEBUG_TRACE(2, "Cleanup offload library ...\n");
     if (mic_engines_total > 0) {
         delete[] mic_engines;
+        mic_engines_total = 0;
 
         if (mic_proxy_fs_root != 0) {
             free(mic_proxy_fs_root);


  -- Ilya

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing
  2014-10-30 12:45 ` [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing Ilya Verbin
  2014-11-06 17:55   ` Jakub Jelinek
  2014-12-18 15:56   ` Thomas Schwinge
@ 2016-03-13 19:10   ` Thomas Schwinge
  2 siblings, 0 replies; 111+ messages in thread
From: Thomas Schwinge @ 2016-03-13 19:10 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek, gcc-patches; +Cc: Kirill Yukhin

[-- Attachment #1: Type: text/plain, Size: 5034 bytes --]

Hi!

On Thu, 30 Oct 2014 14:40:01 +0300, Ilya Verbin <iverbin@gmail.com> wrote:
> This patch allows to run non-fallback 'make check-target-libgomp'.  It passes to
> the host compiler additional -B options with the paths to the offload compilers,
> since non-installed host compiler doesn't know where to find mkoffload tools.
> Also in case of intelmic offload targets it appends paths to liboffloadmic lib.

> --- a/libgomp/testsuite/lib/libgomp.exp
> +++ b/libgomp/testsuite/lib/libgomp.exp

> @@ -107,6 +110,20 @@ proc libgomp_init { args } {
>      # Compute what needs to be put into LD_LIBRARY_PATH
>      set always_ld_library_path ".:${blddir}/.libs"
>  
> +    # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
> +    # non-fallback testing for Intel MIC targets
> +    if { [string match "*-intelmic-*" $offload_targets]
> +	|| [string match "*-intelmicemul-*" $offload_targets] } {
> +	append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
> +	append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
> +	# libstdc++ is required by liboffloadmic
> +	append always_ld_library_path ":${blddir}/../libstdc++-v3/src/.libs"
> +    }
> +
> +    if { $offload_additional_lib_paths != ""} {
> +	append always_ld_library_path "${offload_additional_lib_paths}"
> +    }

Hmm, looking at this again.  Suddenly/unexpectedly (after a long-overdue
system reboot, software upgrades, etc.), the
libgomp.oacc-c/../libgomp.oacc-c-c++-common/context-1.c execution test
(on gomp-4_0-branch) regressed from PASS to FAIL, with the very first
cublasCreate call not returning the exptected CUBLAS_STATUS_SUCCESS.
While I could never figure out what exactly is going wrong in/with
libcublas, I did figure out that the problem comes to existence in GCC
configurations with Intel MIC offloading enabled, where the above stanza
is active.  Remember that offload_additional_lib_paths specifies paths to
the Intel MIC offloading libraries' builds
(x86_64-intelmicemul-linux-gnu), and these are prepended by paths to
satisfy liboffloadmic's dependencies: libstdc++ (x86_64-pc-linux-gnu).
But: libstdc++ depends on libgcc_s, whose path is not specified here, but
a path to libgcc_s is specified with offload_additional_lib_paths, but
that's the variant for Intel MIC offloading
(x86_64-intelmicemul-linux-gnu), not the regular target library
(x86_64-pc-linux-gnu).  And, for some reason this caused breakage in/with
libcublas.

All in all, this whole setup still seems fragile to me (I
wondered/worried about this before): as the x86_64-pc-linux-gnu (target)
and x86_64-intelmicemul-linux-gnu (Intel MIC offloading) libraries are
ABI compatible, ld.so is free to intermix these...  For certain libraries
it may not matter, but certainly the libgomp builds for
x86_64-pc-linux-gnu vs. x86_64-intelmicemul-linux-gnu will have different
semantics for certain functions, for example.

In r234170, I applied the following fix as obvious, but this may still
need further attention; compare the stanza cited above to the potentially
more compilated dependencies of libstdc++.  See
libgomp/testsuite/libgomp.c++/c++.exp, and
libstdc++-v3/testsuite/lib/libstdc++.exp:libstdc++_init mentions that in
certain configurations, also libvtv may be a dependency of libstdc++, for
example.

Also, is the stanza cited above doing the right thing for GCC multilib
configurations?

commit 16603d6b5b9073537c00b706b854f0a87101b991
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Sun Mar 13 19:08:21 2016 +0000

    libgcc_s is required by libstdc++
    
    	libgomp/
    	* testsuite/lib/libgomp.exp (libgomp_init): Potentially append to
    	always_ld_library_path the path to libgcc_s.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234170 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog                 | 5 +++++
 libgomp/testsuite/lib/libgomp.exp | 2 ++
 2 files changed, 7 insertions(+)

diff --git libgomp/ChangeLog libgomp/ChangeLog
index 7293e69..5a91504 100644
--- libgomp/ChangeLog
+++ libgomp/ChangeLog
@@ -1,3 +1,8 @@
+2016-03-13  Thomas Schwinge  <thomas@codesourcery.com>
+
+	* testsuite/lib/libgomp.exp (libgomp_init): Potentially append to
+	always_ld_library_path the path to libgcc_s.
+
 2016-03-10  Cesar Philippidis  <cesar@codesourcery.com>
 
 	PR testsuite/70009
diff --git libgomp/testsuite/lib/libgomp.exp libgomp/testsuite/lib/libgomp.exp
index 0d5b6d4..1cb4991 100644
--- libgomp/testsuite/lib/libgomp.exp
+++ libgomp/testsuite/lib/libgomp.exp
@@ -142,6 +142,8 @@ proc libgomp_init { args } {
 	append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
 	# libstdc++ is required by liboffloadmic
 	append always_ld_library_path ":${blddir}/../libstdc++-v3/src/.libs"
+	# libgcc_s is required by libstdc++
+	append always_ld_library_path ":${blddir}/../libgcc"
     }
 
     global offload_additional_lib_paths


Grüße
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: OMP builtins in offloading
  2015-01-08 15:42             ` Thomas Schwinge
  2015-01-08 15:49               ` Jakub Jelinek
@ 2021-08-04  9:46               ` Thomas Schwinge
  1 sibling, 0 replies; 111+ messages in thread
From: Thomas Schwinge @ 2021-08-04  9:46 UTC (permalink / raw)
  To: gcc-patches, Jakub Jelinek

[-- Attachment #1: Type: text/plain, Size: 1906 bytes --]

Hi!

On 2015-01-08T16:41:50+0100, I wrote:
> Committed to trunk in r219346:

(Git commit 45f46750a3513790573791c0eec6b600b42f2042.)

>     Make sure that OMP builtins are available in offloading compilers.

> --- gcc/builtins.def
> +++ gcc/builtins.def
> @@ -148,11 +148,14 @@ along with GCC; see the file COPYING3.  If not see
>
>  /* Builtin used by the implementation of GNU OpenMP.  None of these are
>     actually implemented in the compiler; they're all in libgomp.  */
> +/* These builtins also need to be enabled in offloading compilers invoked from
> +   mkoffload; for that purpose, we're checking the -foffload-abi flag here.  */
>  #undef DEF_GOMP_BUILTIN
>  #define DEF_GOMP_BUILTIN(ENUM, NAME, TYPE, ATTRS) \
>    DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,    \
>                 false, true, true, ATTRS, false, \
> -            (flag_openmp || flag_tree_parallelize_loops))
> +            (flag_openmp || flag_tree_parallelize_loops \
> +             || flag_offload_abi != OFFLOAD_ABI_UNSET))

(Similar for 'DEF_GOACC_BUILTIN', later.)

Since Tom's PR64707 commit r220037 (Git commit
1506ae0e1e865fb7a42fc37a47f1799b71f21c53) "Make fopenmp an LTO option" as
well as PR64672 commit r220038 (Git commit
a0c88d0629a33161add8d5bc083f1e59f3f756f7) "Make fopenacc an LTO option",
we're now actually passing '-fopenacc'/'-fopenmp' to the 'mkoffload's,
which will pass these on to the offload compilers, so we may clean up
this change.

OK to push "Don't consider '-foffload-abi' in 'DEF_GOACC_BUILTIN',
'DEF_GOMP_BUILTIN'", see attached?


Grüße
 Thomas


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Don-t-consider-foffload-abi-in-DEF_GOACC_BUILTIN-DEF.patch --]
[-- Type: text/x-diff, Size: 3520 bytes --]

From bd83a68fb7ed0d746149029424f01cd857219fc0 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Mon, 2 Aug 2021 18:33:50 +0200
Subject: [PATCH] Don't consider '-foffload-abi' in 'DEF_GOACC_BUILTIN',
 'DEF_GOMP_BUILTIN'

Since Tom's PR64707 commit r220037 (Git commit
1506ae0e1e865fb7a42fc37a47f1799b71f21c53) "Make fopenmp an LTO option" as well
as PR64672 commit r220038 (Git commit a0c88d0629a33161add8d5bc083f1e59f3f756f7)
"Make fopenacc an LTO option", we're now actually passing
'-fopenacc'/'-fopenmp' to the 'mkoffload's, which will pass these on to the
offload compilers.

	gcc/
	* builtins.def (DEF_GOACC_BUILTIN, DEF_GOMP_BUILTIN): Don't
	consider '-foffload-abi'.
	* common.opt (-foffload-abi): Remove 'Var', 'Init'.
	* opts.c (common_handle_option) <-foffload-abi> [ACCEL_COMPILER]:
	Ignore.
---
 gcc/builtins.def | 8 ++------
 gcc/common.opt   | 2 +-
 gcc/opts.c       | 6 ++++--
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/gcc/builtins.def b/gcc/builtins.def
index ec556df4f66..45a09b4d42d 100644
--- a/gcc/builtins.def
+++ b/gcc/builtins.def
@@ -205,14 +205,11 @@ along with GCC; see the file COPYING3.  If not see
 
 /* Builtin used by the implementation of OpenACC and OpenMP.  Few of these are
    actually implemented in the compiler; most are in libgomp.  */
-/* These builtins also need to be enabled in offloading compilers invoked from
-   mkoffload; for that purpose, we're checking the -foffload-abi flag here.  */
 #undef DEF_GOACC_BUILTIN
 #define DEF_GOACC_BUILTIN(ENUM, NAME, TYPE, ATTRS) \
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,    \
 	       false, true, true, ATTRS, false, \
-	       (flag_openacc \
-		|| flag_offload_abi != OFFLOAD_ABI_UNSET))
+	       flag_openacc)
 #undef DEF_GOACC_BUILTIN_COMPILER
 #define DEF_GOACC_BUILTIN_COMPILER(ENUM, NAME, TYPE, ATTRS) \
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,    \
@@ -227,8 +224,7 @@ along with GCC; see the file COPYING3.  If not see
                false, true, true, ATTRS, false, \
 	       (flag_openacc \
 		|| flag_openmp \
-		|| flag_tree_parallelize_loops > 1 \
-		|| flag_offload_abi != OFFLOAD_ABI_UNSET))
+		|| flag_tree_parallelize_loops > 1))
 
 /* Builtin used by the implementation of GNU TM.  These
    functions are mapped to the actual implementation of the STM library. */
diff --git a/gcc/common.opt b/gcc/common.opt
index d9da1131eda..ed8ab5fbe13 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2112,7 +2112,7 @@ Common Driver Joined MissingArgError(options or targets=options missing after %q
 -foffload-options=<targets>=<options>	Specify options for the offloading targets.
 
 foffload-abi=
-Common Joined RejectNegative Enum(offload_abi) Var(flag_offload_abi) Init(OFFLOAD_ABI_UNSET)
+Common Joined RejectNegative Enum(offload_abi)
 -foffload-abi=[lp64|ilp32]	Set the ABI to use in an offload compiler.
 
 Enum
diff --git a/gcc/opts.c b/gcc/opts.c
index 93366e6eb2d..1f52e1139c7 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -2737,12 +2737,14 @@ common_handle_option (struct gcc_options *opts,
       /* Deferred.  */
       break;
 
-#ifndef ACCEL_COMPILER
     case OPT_foffload_abi_:
+#ifdef ACCEL_COMPILER
+      /* Handled in the 'mkoffload's.  */
+#else
       error_at (loc, "%<-foffload-abi%> option can be specified only for "
 		"offload compiler");
-      break;
 #endif
+      break;
 
     case OPT_fpack_struct_:
       if (value <= 0 || (value & (value - 1)) || value > 16)
-- 
2.25.1


^ permalink raw reply	[flat|nested] 111+ messages in thread

end of thread, other threads:[~2021-08-04  9:46 UTC | newest]

Thread overview: 111+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-21 17:16 [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC Ilya Verbin
2014-10-21 17:20 ` [PATCH 1/4] Add mkoffload for " Ilya Verbin
2014-10-21 21:58   ` Joseph S. Myers
2014-10-21 22:31     ` Ilya Verbin
2014-10-22  7:59       ` Jakub Jelinek
2014-10-22  8:27   ` Jakub Jelinek
2014-10-22 18:57     ` Ilya Verbin
2014-11-03 17:36       ` [gomp4] Mark fopenacc as LTO option Tom de Vries
2015-01-23 15:44         ` [committed][PR64707] Make fopenmp an " Tom de Vries
2015-01-23 15:53           ` [committed][PR64672] Make fopenacc " Tom de Vries
2014-11-06 18:02       ` [PATCH 1/4] Add mkoffload for Intel MIC Jakub Jelinek
2014-12-22 11:25       ` OMP builtins in offloading (was: [PATCH 1/4] Add mkoffload for Intel MIC) Thomas Schwinge
2014-12-22 11:28         ` Jakub Jelinek
2014-12-26 15:49           ` Ilya Verbin
2015-01-08 15:42             ` Thomas Schwinge
2015-01-08 15:49               ` Jakub Jelinek
2015-01-08 16:32                 ` Ilya Verbin
2015-01-08 16:39                   ` Jakub Jelinek
2015-01-09 10:40                     ` Richard Biener
2015-01-09 10:45                       ` Jakub Jelinek
2015-02-16 18:58                 ` Ilya Verbin
2021-08-04  9:46               ` OMP builtins in offloading Thomas Schwinge
2014-12-22 11:27       ` [PATCH 1/4] Add mkoffload for Intel MIC Thomas Schwinge
2014-12-22 11:48         ` Jakub Jelinek
2015-01-08 14:59           ` Thomas Schwinge
2015-01-08 15:02             ` H.J. Lu
2015-01-08 16:21               ` Thomas Schwinge
2015-08-04 11:20               ` Use gcc/coretypes.h:enum offload_abi in mkoffloads (was: [PATCH 1/4] Add mkoffload for Intel MIC) Thomas Schwinge
2015-09-28  8:26                 ` Use gcc/coretypes.h:enum offload_abi in mkoffloads Thomas Schwinge
2015-09-28 11:28                   ` Bernd Schmidt
2015-09-30 10:05                     ` Thomas Schwinge
2015-02-18 11:48       ` [PATCH 1/4] Add mkoffload for Intel MIC Thomas Schwinge
2015-02-18 11:56         ` Ilya Verbin
2015-02-18 12:23           ` [PATCH] Use automatic dependencies for mkoffload.o Jakub Jelinek
2015-02-18 13:10             ` Richard Biener
2015-02-18 12:01         ` [PATCH 1/4] Add mkoffload for Intel MIC Jakub Jelinek
2015-09-28  9:39       ` Thomas Schwinge
2015-09-28 11:26         ` Bernd Schmidt
2015-09-28 11:27           ` Bernd Schmidt
2015-09-28 12:00             ` Ilya Verbin
2015-09-28 12:05               ` Bernd Schmidt
2015-09-28 12:33                 ` Jakub Jelinek
2015-09-28 12:33                   ` Bernd Schmidt
2015-09-29 11:24                     ` Richard Biener
2015-09-29 12:11                       ` Bernd Schmidt
2015-09-30 17:55                 ` Refactor intelmic-mkoffload.c argv building to use obstacks (was: [PATCH 1/4] Add mkoffload for Intel MIC) Thomas Schwinge
2015-03-06 13:55   ` [PATCH] Fix intelmic-mkoffload " Ilya Verbin
2015-03-09 14:49     ` Jakub Jelinek
2014-10-21 17:24 ` [PATCH 2/4] Add liboffloadmic Ilya Verbin
2014-10-22  8:55   ` Jakub Jelinek
2014-10-22 17:13     ` Joseph S. Myers
2014-10-22 19:31     ` Ilya Verbin
2014-10-29 16:31       ` Ilya Verbin
2014-11-06 18:21       ` Jakub Jelinek
2014-11-12 10:52         ` Jakub Jelinek
2014-11-12 13:29           ` Ilya Verbin
2014-12-12 10:46   ` Thomas Schwinge
2015-02-04 17:45     ` Ilya Verbin
2015-02-04 17:46       ` Jakub Jelinek
2015-07-09 10:00   ` Thomas Schwinge
2015-07-13 14:31     ` Ilya Verbin
2014-10-21 17:28 ` [PATCH 3/4] Add libgomp plugin for Intel MIC Ilya Verbin
2014-10-22  9:47   ` Jakub Jelinek
2014-10-23 16:00     ` Ilya Verbin
2014-10-24 14:57       ` Jakub Jelinek
2014-10-24 15:12         ` Ilya Verbin
2014-10-24 15:19           ` Jakub Jelinek
2014-10-27 14:24             ` Ilya Verbin
2014-11-06 18:25               ` Jakub Jelinek
2014-11-10 14:32                 ` Ilya Verbin
2014-11-11  7:07                   ` Jakub Jelinek
2014-12-12  9:42                   ` Thomas Schwinge
2015-01-08 14:48                     ` Thomas Schwinge
2015-07-08 14:16   ` Thomas Schwinge
2015-07-08 15:14     ` Ilya Verbin
2015-07-08 15:52       ` Thomas Schwinge
2015-07-23 19:05     ` Ilya Verbin
2015-07-24  8:06       ` Jakub Jelinek
2015-07-24 14:27         ` David Malcolm
2015-07-28 15:51           ` Maxim Blumental
2015-08-03 10:24             ` Maxim Blumental
2015-08-04 17:40               ` David Malcolm
2015-08-06 14:35             ` Fwd: " Maxim Blumental
2015-08-11 12:27               ` Maxim Blumental
2015-08-24  8:51               ` Fwd: " Jakub Jelinek
2014-10-30 12:45 ` [PATCH 4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing Ilya Verbin
2014-11-06 17:55   ` Jakub Jelinek
2014-11-10 14:51     ` Ilya Verbin
2014-11-11  7:10       ` Jakub Jelinek
2014-11-12  9:18       ` Jakub Jelinek
2014-12-17 22:53       ` Thomas Schwinge
2014-12-18 10:46         ` Jakub Jelinek
2014-12-22 16:37           ` Thomas Schwinge
2014-12-18 15:56   ` Thomas Schwinge
2014-12-18 17:43     ` Ilya Verbin
2014-12-18 17:56       ` Jakub Jelinek
2014-12-22 11:49       ` Thomas Schwinge
2014-12-22 12:50         ` Jakub Jelinek
2015-01-15 19:21           ` Ilya Verbin
2015-01-15 19:25             ` Jakub Jelinek
2015-01-28 17:28               ` Ilya Verbin
2015-01-28 17:42                 ` Jakub Jelinek
2015-01-28 17:51                   ` Ilya Verbin
2015-02-02 14:03                     ` Ilya Verbin
2014-12-26 20:53         ` Ilya Verbin
2015-01-08 16:03           ` Thomas Schwinge
2016-03-13 19:10   ` Thomas Schwinge
2014-12-22 12:08 ` [PATCH 0/4] OpenMP 4.0 offloading to Intel MIC Thomas Schwinge
2015-10-22 18:28   ` Ilya Verbin
2015-10-23  8:10     ` Jakub Jelinek
2015-10-26 14:39       ` Ilya Verbin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).