ryanwoodsmall / gcc-5.1.1-knc

GCC 5.1.1 cross-compiler for Intel Xeon Phi Knights Corner / k1om

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GCC 5.1.1 cross-compiler for Intel Xeon Phi Knights Corner / k1om

This repository contains the source code for GCC 5.1.1 branch used by Intel in their Manycore Platform Software Stack 3.6.1 (MPSS). The provided build instructions could be used to e.g. create a modified compiler (include more languages, Fortran for MIC, etc.), or to backport newer version of GCC compiler to older MPSS, if older MPSS is preferred by HPC center/provider.

Build instructions below are intended to build GCC from MPSS 3.6.1 for MPSS 3.4.1. An important advantage of GCC 5.1.1 is the availability of AVX512 builtins, e.g. __m512d and AVX512 intrinsics, enabling the use of GCC as a replacement for Intel's ICC in case of explicit vector programming.

$ git clone https://github.com/apc-llc/gcc-5.1.1-knc.git
$ cd gcc-5.1.1-knc/
$ mkdir build/
$ cd build/
$ export PATH=/opt/mpss/3.4.2/sysroots/x86_64-mpsssdk-linux/usr/bin/k1om-mpss-linux/:$PATH
$ sudo ln -s /opt/mpss/3.4.2/sysroots/k1om-mpss-linux/usr/lib64 /opt/mpss/3.4.2/sysroots/k1om-mpss-linux/usr/lib
$ ../configure --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=k1om-mpss-linux --prefix=$(pwd)/../install --disable-silent-rules --disable-dependency-tracking --with-ld=/opt/mpss/3.4.2/sysroots/x86_64-mpsssdk-linux/usr/bin/k1om-mpss-linux/k1om-mpss-linux-ld --with-as=/opt/mpss/3.4.2/sysroots/x86_64-mpsssdk-linux/usr/bin/k1om-mpss-linux/k1om-mpss-linux-as --enable-shared --enable-languages=c,c++ --enable-threads=posix --disable-multilib --enable-c99 --enable-long-long --enable-symvers=gnu --enable-libstdcxx-pch --program-prefix=k1om-mpss-linux- --enable-target-optspace --enable-lto --disable-bootstrap --with-system-zlib --with-linker-hash-style=gnu --enable-cheaders=c_global --with-local-prefix=/opt/mpss/3.4.2/sysroots/k1om-mpss-linux/usr --with-sysroot=/opt/mpss/3.4.2/sysroots/k1om-mpss-linux/ --disable-libunwind-exceptions --disable-libssp --disable-libgomp --disable-libmudflap --enable-nls --enable-__cxa_atexit --disable-libitm
$ make -j48
$ make -j48 install
$ export PATH=$(pwd)/../install/bin:$PATH

Note the line $ sudo ln -s /opt/mpss/3.4.2/sysroots/k1om-mpss-linux/usr/lib64 /opt/mpss/3.4.2/sysroots/k1om-mpss-linux/usr/lib is needed on systems whose host compiler returns ../lib on $ gcc -print-multi-os-directory instead of ../lib64, e.g. on Ubuntu. MPSS is bound to ../lib64, because RPMs shipped by Intel are for RedHat/SuSE family. On Debian/Ubuntu this fix is required.

Testing

Create reduce_mul.c:

#include <immintrin.h>

double reduce(double* values)
{
	__m512d val = _mm512_load_pd(values);
	return _mm512_reduce_mul_pd(val);
}

Create main.c:

#include <immintrin.h>
#include <stdio.h>
#include <stdlib.h>

double reduce(double* values);

int main(int argc, char* argv[])
{
	// Generate random input vector of [-1, 1] values.
	double values[8] __attribute__((aligned(64)));
	for (int i = 0; i < 8; i++)
		values[i] = 2 * (0.5 - rand() / (double)RAND_MAX);

	double vector = reduce(values);
	double scalar = values[0];
	for (int i = 1; i < 8; i++)
		scalar *= values[i];

	printf("%f vs %f\n", vector, scalar);

	fflush(stdout);

	return 0;
}

We keep driver stuff and reduction intrinsic call in separate sources, in order to compile reduce_mul.c with -mavx512f and main.c -- without. When in single source, GCC will cease to compile scalar values management logic, due to absence of SSE/AVX instructions also triggered by -mavx512f. This is something still to be fixed.

Create the makefile:

all: reduce_mul

reduce_mul: reduce_mul.o main_gcc.o
	k1om-mpss-linux-gcc -O3 $^ -o $@

main_gcc.o: main.c
	k1om-mpss-linux-gcc -std=c99 -O3 -c $< -o $@

reduce_mul.o: reduce_mul.s
	k1om-mpss-linux-gcc -O3 -c $< -o $@

reduce_mul.s: reduce_mul.c
	k1om-mpss-linux-gcc -mavx512f -O3 -c $< -o $@ -S

clean:
	rm -rf reduce_mul *.s *.o

Compile and run:

$ make
k1om-mpss-linux-gcc -mavx512f -O3 -c reduce_mul.c -o reduce_mul.s -S
k1om-mpss-linux-gcc -O3 -c reduce_mul.s -o reduce_mul.o
k1om-mpss-linux-gcc -std=c99 -O3 -c main.c -o main_gcc.o
k1om-mpss-linux-gcc -O3 reduce_mul.o main_gcc.o -o reduce_mul
$ micnativeloadex ./reduce_mul
-0.004276 vs -0.004276

About

GCC 5.1.1 cross-compiler for Intel Xeon Phi Knights Corner / k1om

License:GNU General Public License v2.0


Languages

Language:C 36.7%Language:C++ 15.9%Language:Ada 15.4%Language:Java 14.3%Language:Go 4.4%Language:GCC Machine Description 3.2%Language:HTML 2.7%Language:Makefile 2.0%Language:Fortran 1.8%Language:Assembly 0.8%Language:Shell 0.6%Language:M4 0.6%Language:Objective-C 0.5%Language:TeX 0.2%Language:Scheme 0.1%Language:Objective-C++ 0.1%Language:Logos 0.1%Language:Scilab 0.1%Language:Python 0.1%Language:Perl 0.1%Language:XSLT 0.0%Language:OCaml 0.0%Language:Awk 0.0%Language:Roff 0.0%Language:SourcePawn 0.0%Language:Pascal 0.0%Language:C# 0.0%Language:CSS 0.0%Language:DIGITAL Command Language 0.0%Language:Yacc 0.0%Language:PHP 0.0%Language:Tcl 0.0%Language:RPC 0.0%Language:GAP 0.0%Language:CMake 0.0%Language:JavaScript 0.0%Language:CLIPS 0.0%Language:Lex 0.0%Language:Smarty 0.0%Language:Haskell 0.0%Language:Pawn 0.0%Language:SAS 0.0%Language:Vim Script 0.0%Language:Module Management System 0.0%Language:Mercury 0.0%Language:GDB 0.0%Language:Brainfuck 0.0%Language:Batchfile 0.0%Language:Mathematica 0.0%