[Mesa-dev] [PATCH 1/2] swr: allow a single architecture to be builtin
Eric Engestrom
eric.engestrom at imgtec.com
Tue Jan 16 17:57:48 UTC 2018
On Tuesday, 2018-01-16 10:36:49 -0500, Chuck Atkins wrote:
> When only a single SWR architecture is being used, this allows that
> architecture to be builtin rather than as a separate libswrARCH.so that
> gets loaded via dlopen. Since there are now several different code
> paths for each detected CPU architecture, the log output is also
> adjusted to convey where the backend is getting loaded from.
>
> This also allows SWR to be used for static mesa builds which are still
> important for large HPC environments where shared libraries can impose
> unacceptable application startup times as hundreds of thousands of copies
> of the libs are loaded from a shared parallel filesystem.
>
> Based on an initial implementation by Tim Rowley.
>
> Signed-off-by: Chuck Atkins <chuck.atkins at kitware.com>
> CC: Tim Rowley <timothy.o.rowley at intel.com>
> CC: Bruce Cherniak <bruce.cherniak at intel.com>
> ---
> configure.ac | 12 ++++-
> src/gallium/drivers/swr/Makefile.am | 48 +++++++++++++----
Meson needs these changes as well.
> src/gallium/drivers/swr/swr_loader.cpp | 95 ++++++++++++++++++++++------------
> 3 files changed, 110 insertions(+), 45 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index e236a3c54f..7c1fbe0ed1 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -2640,6 +2640,11 @@ if test -n "$with_gallium_drivers"; then
> AC_MSG_ERROR([swr enabled but no swr architectures selected])
> fi
>
> + # test if more than one swr arch configured
> + if test `echo $swr_archs | wc -w` -eq 1; then
> + HAVE_SWR_BUILTIN=yes
> + fi
> +
> HAVE_GALLIUM_SWR=yes
> ;;
> xvc4)
> @@ -2689,6 +2694,7 @@ AM_CONDITIONAL(HAVE_SWR_AVX, test "x$HAVE_SWR_AVX" = xyes)
> AM_CONDITIONAL(HAVE_SWR_AVX2, test "x$HAVE_SWR_AVX2" = xyes)
> AM_CONDITIONAL(HAVE_SWR_KNL, test "x$HAVE_SWR_KNL" = xyes)
> AM_CONDITIONAL(HAVE_SWR_SKX, test "x$HAVE_SWR_SKX" = xyes)
> +AM_CONDITIONAL(HAVE_SWR_BUILTIN, test "x$HAVE_SWR_BUILTIN" = xyes)
>
> dnl We need to validate some needed dependencies for renderonly drivers.
>
> @@ -3153,7 +3159,11 @@ fi
>
> echo ""
> if test "x$HAVE_GALLIUM_SWR" != x; then
> - echo " SWR archs: $swr_archs"
> + if test "x$HAVE_SWR_BUILTIN" = xyes; then
> + echo " SWR archs: $swr_archs (builtin)"
> + else
> + echo " SWR archs: $swr_archs"
> + fi
> fi
>
> dnl Libraries
> diff --git a/src/gallium/drivers/swr/Makefile.am b/src/gallium/drivers/swr/Makefile.am
> index c995f1b84a..69cd52d18f 100644
> --- a/src/gallium/drivers/swr/Makefile.am
> +++ b/src/gallium/drivers/swr/Makefile.am
> @@ -29,10 +29,7 @@ noinst_LTLIBRARIES = libmesaswr.la
> # gen_knobs.* included here to provide driver access to swr configuration
> libmesaswr_la_SOURCES = \
> $(CXX_SOURCES) \
> - $(COMMON_CXX_SOURCES) \
> $(JITTER_CXX_SOURCES) \
> - rasterizer/codegen/gen_knobs.cpp \
> - rasterizer/codegen/gen_knobs.h \
> $(LOADER_SOURCES)
>
> COMMON_CXXFLAGS = \
> @@ -243,8 +240,6 @@ COMMON_LDFLAGS = \
> lib_LTLIBRARIES =
>
> if HAVE_SWR_AVX
> -lib_LTLIBRARIES += libswrAVX.la
> -
> libswrAVX_la_CXXFLAGS = \
> $(PTHREAD_CFLAGS) \
> $(SWR_AVX_CXXFLAGS) \
> @@ -262,7 +257,6 @@ libswrAVX_la_LDFLAGS = \
> endif
>
> if HAVE_SWR_AVX2
> -lib_LTLIBRARIES += libswrAVX2.la
> libswrAVX2_la_CXXFLAGS = \
> $(PTHREAD_CFLAGS) \
> $(SWR_AVX2_CXXFLAGS) \
> @@ -280,8 +274,6 @@ libswrAVX2_la_LDFLAGS = \
> endif
>
> if HAVE_SWR_KNL
> -lib_LTLIBRARIES += libswrKNL.la
> -
> libswrKNL_la_CXXFLAGS = \
> $(PTHREAD_CFLAGS) \
> $(SWR_KNL_CXXFLAGS) \
> @@ -299,8 +291,6 @@ libswrKNL_la_LDFLAGS = \
> endif
>
> if HAVE_SWR_SKX
> -lib_LTLIBRARIES += libswrSKX.la
> -
> libswrSKX_la_CXXFLAGS = \
> $(PTHREAD_CFLAGS) \
> $(SWR_SKX_CXXFLAGS) \
> @@ -317,6 +307,44 @@ libswrSKX_la_LDFLAGS = \
> $(COMMON_LDFLAGS)
> endif
>
> +if HAVE_SWR_BUILTIN
> +libmesaswr_la_CXXFLAGS += -DHAVE_SWR_BUILTIN
> +libmesaswr_la_LIBADD =
> +if HAVE_SWR_AVX
> +noinst_LTLIBRARIES += libswrAVX.la
> +libmesaswr_la_LIBADD += libswrAVX.la
> +endif
> +if HAVE_SWR_AVX2
> +noinst_LTLIBRARIES += libswrAVX2.la
> +libmesaswr_la_LIBADD += libswrAVX2.la
> +endif
> +if HAVE_SWR_KNL
> +noinst_LTLIBRARIES += libswrKNL.la
> +libmesaswr_la_LIBADD += libswrKNL.la
> +endif
> +if HAVE_SWR_SKX
> +noinst_LTLIBRARIES += libswrSKX.la
> +libmesaswr_la_LIBADD += libswrSKX.la
> +endif
> +else # !HAVE_SWR_BUILTIN
> +libmesaswr_la_SOURCES += \
> + $(COMMON_CXX_SOURCES) \
> + rasterizer/codegen/gen_knobs.cpp \
> + rasterizer/codegen/gen_knobs.h
> +if HAVE_SWR_AVX
> +lib_LTLIBRARIES += libswrAVX.la
> +endif
> +if HAVE_SWR_AVX2
> +lib_LTLIBRARIES += libswrAVX2.la
> +endif
> +if HAVE_SWR_KNL
> +lib_LTLIBRARIES += libswrKNL.la
> +endif
> +if HAVE_SWR_SKX
> +lib_LTLIBRARIES += libswrSKX.la
> +endif
> +endif
> +
> include $(top_srcdir)/install-gallium-links.mk
>
> # Generated gen_builder.hpp is not backwards compatible. So ship only one
> diff --git a/src/gallium/drivers/swr/swr_loader.cpp b/src/gallium/drivers/swr/swr_loader.cpp
> index 9d6f918e34..40324904d9 100644
> --- a/src/gallium/drivers/swr/swr_loader.cpp
> +++ b/src/gallium/drivers/swr/swr_loader.cpp
> @@ -31,78 +31,105 @@
> struct pipe_screen *
> swr_create_screen(struct sw_winsys *winsys)
> {
> + struct pipe_screen *screen = swr_create_screen_internal(winsys);
> +
> + bool found = false;
> + bool is_knl = false;
> +
> +#ifndef HAVE_SWR_BUILTIN
> char filename[256] = { 0 };
> - fprintf(stderr, "SWR detected ");
> +#endif
>
> - util_dl_library *pLibrary = nullptr;
>
> util_cpu_detect();
>
> - bool is_knl = false;
> -
> - if (!strlen(filename) &&
> - util_cpu_caps.has_avx512f && util_cpu_caps.has_avx512er) {
> -#if HAVE_SWR_KNL
> - fprintf(stderr, "KNL ");
> - sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrKNL", UTIL_DL_EXT);
> - is_knl = true;
> + if (!found && util_cpu_caps.has_avx512f && util_cpu_caps.has_avx512er) {
> + fprintf(stderr, "SWR detected KNL instruction support ");
> +#ifndef HAVE_SWR_KNL
> + fprintf(stderr, "(skipping; not built).\n");
> #else
> - fprintf(stderr, "KNL (not built) ");
> + #ifdef HAVE_SWR_BUILTIN
> + swr_screen(screen)->pfnSwrGetInterface = SwrGetInterface;
> + fprintf(stderr, "(using; builtin).\n");
> + #else
> + sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrKNL", UTIL_DL_EXT);
> + fprintf(stderr, "(using; %s).\n", filename);
> + #endif
> + found = true;
> + is_knl = true;
> #endif
> }
>
> - if (!strlen(filename) &&
> - util_cpu_caps.has_avx512f && util_cpu_caps.has_avx512bw) {
> -#if HAVE_SWR_SKX
> - fprintf(stderr, "SKX ");
> - sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrSKX", UTIL_DL_EXT);
> + if (!found && util_cpu_caps.has_avx512f && util_cpu_caps.has_avx512bw) {
> + fprintf(stderr, "SWR detected SKX instruction support ");
> +#ifndef HAVE_SWR_SKX
> + fprintf(stderr, "(skipping; not built).\n");
> #else
> - fprintf(stderr, "SKX (not built) ");
> + #ifdef HAVE_SWR_BUILTIN
> + swr_screen(screen)->pfnSwrGetInterface = SwrGetInterface;
> + fprintf(stderr, "(using; builtin).\n");
> + #else
> + sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrSKX", UTIL_DL_EXT);
> + fprintf(stderr, "(using; %s).\n", filename);
> + #endif
> + found = true;
> #endif
> }
>
> - if (!strlen(filename) && util_cpu_caps.has_avx2) {
> -#if HAVE_SWR_AVX2
> - fprintf(stderr, "AVX2 ");
> - sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrAVX2", UTIL_DL_EXT);
> + if (!found && util_cpu_caps.has_avx2) {
> + fprintf(stderr, "SWR detected AVX2 instruction support ");
> +#ifndef HAVE_SWR_AVX2
> + fprintf(stderr, "(skipping; not built).\n");
> #else
> - fprintf(stderr, "AVX2 (not built) ");
> + #ifdef HAVE_SWR_BUILTIN
> + swr_screen(screen)->pfnSwrGetInterface = SwrGetInterface;
> + fprintf(stderr, "(using; builtin).\n");
> + #else
> + sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrAVX2", UTIL_DL_EXT);
> + fprintf(stderr, "(using; %s).\n", filename);
> + #endif
> + found = true;
> #endif
> }
>
> - if (!strlen(filename) && util_cpu_caps.has_avx) {
> -#if HAVE_SWR_AVX
> - fprintf(stderr, "AVX ");
> - sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrAVX", UTIL_DL_EXT);
> + if (!found && util_cpu_caps.has_avx) {
> + fprintf(stderr, "SWR detected AVX instruction support ");
> +#ifndef HAVE_SWR_AVX
> + fprintf(stderr, "(skipping; not built).\n");
> #else
> - fprintf(stderr, "AVX (not built) ");
> + #ifdef HAVE_SWR_BUILTIN
> + swr_screen(screen)->pfnSwrGetInterface = SwrGetInterface;
> + fprintf(stderr, "(using; builtin).\n");
> + #else
> + sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrAVX", UTIL_DL_EXT);
> + fprintf(stderr, "(using; %s).\n", filename);
> + #endif
> + found = true;
> #endif
> }
>
> - if (!strlen(filename)) {
> - fprintf(stderr, "- no appropriate swr architecture library. Aborting!\n");
> + if (!found) {
> + fprintf(stderr, "SWR could not detect a supported CPU architecture.\n");
> exit(-1);
> - } else {
> - fprintf(stderr, "\n");
> }
>
> - pLibrary = util_dl_open(filename);
>
> +#ifndef HAVE_SWR_BUILTIN
> + util_dl_library *pLibrary = util_dl_open(filename);
> if (!pLibrary) {
> fprintf(stderr, "SWR library load failure: %s\n", util_dl_error());
> exit(-1);
> }
>
> util_dl_proc pApiProc = util_dl_get_proc_address(pLibrary, "SwrGetInterface");
> -
> if (!pApiProc) {
> fprintf(stderr, "SWR library search failure: %s\n", util_dl_error());
> exit(-1);
> }
>
> - struct pipe_screen *screen = swr_create_screen_internal(winsys);
> swr_screen(screen)->pfnSwrGetInterface = (PFNSwrGetInterface)pApiProc;
> swr_screen(screen)->is_knl = is_knl;
> +#endif
>
> return screen;
> }
> --
> 2.14.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list