背景
我们一直在尝试使用新的GCC 5.1版本将 OpenMP 块卸载到英特尔 MIC(即 Xeon Phi),但没有成功。在 GCC卸载页面之后,我们将build.sh
脚本放在一起,为“intelmic”和主机编译器构建“accel”目标编译器。编译似乎成功完成。
然后,我们使用该env.sh
脚本尝试编译hello.c
下面列出的简单程序。但是,该程序似乎只在主机上运行,而不是在目标设备上运行。
由于我们通常不熟悉卸载以及编译 GCC,因此我们可能会做很多错误的事情。但是,我们已经调查了已经提到的资源以及以下资源(我没有足够的代表来发布链接):
- Xeon Phi 卸载
- 至强融核教程
- 英特尔至强融核卸载编程模型
最大的问题是他们通常引用英特尔编译器。虽然我们计划购买副本,但我们目前没有副本。此外,我们的大部分开发管道已经与 GCC 集成,我们更愿意保持这种方式(如果可能的话)。
我们已经安装了最新的 MPSS 3.5 发行版,进行了必要的修改以在 Ubuntu 下工作。我们可以成功通信并检查系统中 Xeon Phis 的状态。
在我们的努力中,我们也从未看到任何迹象表明代码正在麦克风仿真模式下运行。
问题
- 有没有人成功构建了实际上卸载到 Xeon Phi 的主机/目标 GCC 编译器组合?如果是这样,您使用了哪些资源?
- 我们是否遗漏了构建脚本中的任何内容?
- 测试源代码有什么问题吗?它们编译时没有错误(除了下面提到的)并运行 48 个线程(即主机系统中的逻辑线程数)。
- 由于谷歌搜索没有透露太多信息,是否有人对下一步有建议(除了放弃 GCC 卸载)?这是一个错误吗?
谢谢!
构建.sh
#!/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
你好.c(版本 1)
#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
hello_omp.c(版本 2)
#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
句法。事实上,mic
它会抱怨,但是对于任何设备号(即 0),它都会在主机上编译和运行。此代码以相同的方式编译。