如何使用GCC 5.1和OpenMP将工作卸载到Xeon Phi 背景
我们一直试图使用新版本将OpenMP块卸载到Intel麦克风(即Xeon Phi)上,但没有成功。在GCC页面之后,我们将如何使用GCC 5.1和OpenMP将工作卸载到Xeon Phi 背景,gcc,openmp,xeon-phi,offloading,Gcc,Openmp,Xeon Phi,Offloading,我们一直试图使用新版本将OpenMP块卸载到Intel麦克风(即Xeon Phi)上,但没有成功。在GCC页面之后,我们将build.sh脚本放在一起,为“intelmic”和主机编译器构建“accel”目标编译器。编译似乎已成功完成 使用env.sh脚本,我们尝试编译下面列出的简单hello.c程序。但是,该程序似乎只在主机上运行,而不是在目标设备上运行 由于我们对卸载以及编译GCC都是新手,所以有很多事情我们可能做得不正确。但是,我们已经调查了前面提到的资源,以及以下内容(我没有足够的代表发
build.sh
脚本放在一起,为“intelmic”和主机编译器构建“accel”目标编译器。编译似乎已成功完成
使用env.sh
脚本,我们尝试编译下面列出的简单hello.c
程序。但是,该程序似乎只在主机上运行,而不是在目标设备上运行
由于我们对卸载以及编译GCC都是新手,所以有很多事情我们可能做得不正确。但是,我们已经调查了前面提到的资源,以及以下内容(我没有足够的代表发布链接):
- Xeon-Phi的卸载
- 至强Phi教程
- 英特尔至强Phi卸载编程模型
语法。事实上,对于
mic
,它会抱怨,但对于任何设备编号(即0),它都会编译并在主机上运行。此代码以相同的方式编译。可以使用GCC 5卸载到Xeon Phi。为了让它正常工作,必须为本机MIC目标编译libdmic,这与编译的方式类似。您的安装程序的问题在于,它编译主机仿真库(libcoi_host.so、libcoi_device.so),并且即使存在物理至强Phi,也会坚持模拟卸载。当“英特尔人”监视此站点时,您可能会更幸运地将此发布在英特尔论坛上。为什么是英特尔而不是GCC?根据GCC页面:“GCC 5支持两种类型的卸载:OpenMP到Intel麦克风目标(即将推出的Intel Xeon Phi产品代号为KNL)”。因此,不支持卸载到当前一代Intel Xeon Phi(KNC)。啊…@IlyaVerbin,我明白了。感谢您的评论。我错过了这一区别(骑士角vs Knight's Landing).因此,换句话说,我们现在没有选择(对于这个硬件的未来也没有选择)但是要使用英特尔编译器。这可能会让你感兴趣。最近骑士角卡的销量很大,但GCC不支持。因此,我想澄清一下,你是说我们可以使用链接项目为我们的骑士角至强Phi卡编译一个MIC本机版本的LibOfflowDMIC和libgomp,使用最新的GCC 5?看起来在saxpy
示例中,类似CUDA的接口与简单地编写#pragma omp目标设备(0)
并不完全相同。为什么测试生成文件要求TBB使用icc
?谢谢。
#!/usr/bin/env bash
set -e -x
unset LIBRARY_PATH
GCC_DIST=$PWD/gcc-5.1.0
# Modify these to control where the compilers are installed
TARGET_PREFIX=$HOME/gcc
HOST_PREFIX=$HOME/gcc
TARGET_BUILD=/tmp/gcc-build-mic
HOST_BUILD=/tmp/gcc-build-host
# i dropped the emul since we are not planning to emulate!
TARGET=x86_64-intelmic-linux-gnu
# should this be a quad (i.e. pc)?? default (Ubuntu) build seems to be x86_64-linux-gnu
HOST=x86_64-pc-linux-gnu
# check for the GCC distribution
if [ ! -d $GCC_DIST ]; then
echo "gcc-5.1.0 distribution should be here $PWD"
exit 0
fi
#sudo apt-get install -y libmpfr-dev libgmp-dev libmpc-dev libisl-dev dejagnu autogen sysvbanner
# prepare and configure the target compiler
mkdir -p $TARGET_BUILD
pushd $TARGET_BUILD
$GCC_DIST/configure \
--prefix=$TARGET_PREFIX \
--enable-languages=c,c++,fortran,lto \
--enable-liboffloadmic=target \
--disable-multilib \
--build=$TARGET \
--host=$TARGET \
--target=$TARGET \
--enable-as-accelerator-for=$HOST \
--program-prefix="${TARGET}-"
#--program-prefix="$HOST-accel-$TARGET-" \
# try adding the program prefix as HINTED in the https://gcc.gnu.org/wiki/Offloading
# do we need to specify a sysroot??? Wiki says we don't need one... but it also says "better to configure as cross compiler....
# build and install
make -j48 && make install
popd
# prepare and build the host compiler
mkdir -p $HOST_BUILD
pushd $HOST_BUILD
$GCC_DIST/configure \
--prefix=$HOST_PREFIX \
--enable-languages=c,c++,fortran,lto \
--enable-liboffloadmic=host \
--disable-multilib \
--build=$HOST \
--host=$HOST \
--target=$HOST \
--enable-offload-targets=$TARGET=$TARGET_PREFIX
make -j48 && make install
popd
#!/usr/bin/env bash
TARGET_PREFIX=$HOME/gcc
HOST_PREFIX=$HOME/gcc
HOST=x86_64-pc-linux-gnu
VERSION=5.1.0
export LD_LIBRARY_PATH=/opt/intel/mic/coi/host-linux-release/lib:/opt/mpss/3.4.3/sysroots/k1om-mpss-linux/usr/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$HOST_PREFIX/lib:$HOST_PREFIX/lib64:$HOST_PREFIX/lib/gcc/$HOST/$VERSION:$LD_LIBRARY_PATH
export PATH=$HOST_PREFIX/bin:$PATH
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
int nthreads, tid;
/* Fork a team of threads giving them their own copies of variables */
#pragma offload target (mic)
{
#pragma omp parallel private(nthreads,tid)
{
/* Obtain thread number */
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
/* Only master thread does this */
if (tid == 0) {
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
#ifdef __MIC__
printf("on target...\n");
#else
printf("on host...\n");
#endif
}
}
}
gcc -fopenmp -foffload=x86_64-intelmic-linux-gnu hello.c -o hello
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
int nthreads, tid;
/* Fork a team of threads giving them their own copies of variables */
#pragma omp target device(mic)
{
#pragma omp parallel private(nthreads,tid)
{
/* Obtain thread number */
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
/* Only master thread does this */
if (tid == 0) {
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
#ifdef __MIC__
printf("on target...\n");
#else
printf("on host...\n");
#endif
}
}
}
#pragma omp target device