我正在尝试使此最小的Rcpp / Intel pragma代码正常工作,但是遇到了一些我要克服的相当大的错误。
代码
这是我要运行的完整代码-它是一条简单的文本,显示是否按照以下网站Offload Computations from Servers with an Intel® Xeon Phi™ Processor使用了目标Xeon Phi设备,并且这是基于示例代码的在这里找到:Lightning-Fast R Machine Learning Algorithms:
library(Rcpp)
library(inline)
# Create and register a Rcpp plugin
plug <- Rcpp:::Rcpp.plugin.maker(
include.before = "#include <stdint.h>
#include <stdio.h>
#include <omp.h>"
)
registerPlugin("daalNB", plug)
whatCPU <-
'
#pragma omp declare target
void what_cpu()
{
uint32_t eax;
const uint32_t xeon_phi_x100_id = 0x00010;
const uint32_t xeon_phi_x200_id = 0x50070;
__asm volatile("cpuid":"=a"(eax):"a"(1));
uint32_t this_cpu_id = eax & 0xF00F0;
if (this_cpu_id == xeon_phi_x100_id)
printf("This CPU is Intel(R) XeonPhi(TM) x100 Processor!");
else
if (this_cpu_id == xeon_phi_x200_id)
printf("This CPU is Intel(R) XeonPhi(TM) x200 Processor!");
else
printf("This CPU is other Intel(R) Processor.");
}
'
offloadExampleRcpp <-
'
//[[Rcpp::plugins(openmp)]]
printf("Running on host: ");
what_cpu();
#pragma offload target(mic:0)
{
printf("Running on target: ");
what_cpu();
}
'
runOffloadExample <- cxxfunction(sig = signature(), body = offloadExampleRcpp, plugin="daalNB", includes = '
//[[Rcpp::plugins(openmp)]]
#pragma omp declare target
void what_cpu()
{
uint32_t eax;
const uint32_t xeon_phi_x100_id = 0x225d;
const uint32_t xeon_phi_x200_id = 0x50070;
__asm volatile("cpuid":"=a"(eax):"a"(1));
uint32_t this_cpu_id = eax & 0xF00F0;
if (this_cpu_id == xeon_phi_x100_id)
printf("This CPU is Intel(R) XeonPhi(TM) x100 Processor!");
else
if (this_cpu_id == xeon_phi_x200_id)
printf("This CPU is Intel(R) XeonPhi(TM) x200 Processor!");
else
printf("This CPU is other Intel(R) Processor.");
}
', verbose = 2)
runOffloadExample()
我尝试过的内容和错误:
我已经正确设置了Xeon Phi的软件堆栈,当我使用Intel icc编译器在R之外编译.c代码(上述代码中包装在Rcpp中)时,可以确认这一点。成功了;也就是说,我能够获得Intel website处理器中显示的确切输出。
但是,似乎相同的.c代码包装在Rcpp中时,会出现以下错误,阻止编译(此示例来自更长的读取时间):
Compilation argument:
/usr/local/lib64/R/bin/R CMD SHLIB file306737f15222.cpp 2> file306737f15222.cpp.err.txt
/opt/intel/compilers_and_libraries_2017.1.132/linux/bin/intel64/icc -I/usr/local/lib64/R/include -DNDEBUG -I"/home/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include" -I/usr/local/include -fpic -qopenmp -c file306737f15222.cpp -o file306737f15222.o
file306737f15222.cpp(52): warning #2571: variable has not been declared with compatible "target" attribute
BEGIN_RCPP
^
file306737f15222.cpp(63): warning #2570: function has not been declared with compatible "target" attribute
END_RCPP
^
file306737f15222.cpp(63): warning #2570: function has not been declared with compatible "target" attribute
END_RCPP
^
此外,上面的错误读数后面跟着下面的错误的吨数(再次,为简洁起见,我仅包括了一个样本,但是我相信其他错误都是与我提出的问题相同)
/home/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/protection/Shelter.h(34): warning #2570: function has not been declared with compatible "target" attribute
Rcpp_unprotect(nprotected) ;
^
detected during:
instantiation of "Rcpp::Shelter<T>::~Shelter() [with T=SEXP]" at line 323 of "/home/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/exceptions.h"
instantiation of "SEXP exception_to_condition_template(const Exception &, bool) [with Exception=Rcpp::exception]" at line 339 of "/home/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/exceptions.h"
/home/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/protection/Shelter.h(30): warning #2570: function has not been declared with compatible "target" attribute
return Rcpp_protect(x) ;
^
detected during:
instantiation of "SEXP Rcpp::Shelter<T>::operator()(SEXP) [with T=SEXP]" at line 326 of "/home/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/exceptions.h"
instantiation of "SEXP exception_to_condition_template(const Exception &, bool) [with Exception=Rcpp::exception]" at line 339 of "/home/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/exceptions.h"
/home/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/utils/tinyformat/tinyformat.h(218): warning #2570: function has not been declared with compatible "target" attribute
static void invoke(std::ostream& /*out*/, const T& /*value*/) { TINYFORMAT_ASSERT(0); }
^
detected during:
instantiation of "void tinyformat::detail::formatValueAsType<T, fmtT, convertible>::invoke(std::ostream &, const T &) [with T=const char *, fmtT=char, convertible=false]" at line 329
instantiation of "void tinyformat::formatValue(std::ostream &, const char *, const char *, int, const T &) [with T=const char *]" at line 528
instantiation of "void tinyformat::detail::FormatArg::formatImpl<T>(std::ostream &, const char *, const char *, int, const void *) [with T=const char *]" at line 504
instantiation of "tinyformat::detail::FormatArg::FormatArg(const T &) [with T=const char *]" at line 881
instantiation of "tinyformat::detail::FormatListN<N>::FormatListN(const Args &...) [with N=1, Args=<const char *>]" at line 930
instantiation of "tinyformat::detail::FormatListN<<expression>> tinyformat::makeFormatList(const Args &...) [with Args=<const char *>]" at line 966
instantiation of "void tinyformat::format(std::ostream &, const char *, const Args &...) [with Args=<const char *>]" at line 975
instantiation of "std::string tinyformat::format(const char *, const Args &...) [with Args=<const char *>]" at line 226 of "/home/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/exceptions.h"
instantiation of "Rcpp::not_compatible::not_compatible(const char *, Args &&...) [with Args=<const char *const &>]" at line 37 of "/home/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/r_cast.h"
想知道是否有人可以帮助我指出导致上述错误的问题是什么?我认识到由于熟悉C和Rcpp软件包,我可能会缺少一些基本知识,因此请原谅。
非常感谢,