How to compile Xeon phi patched gcc from source? - linux

I downloaded the MPSS software stack version 3.5.2 source code from the intel website. I am trying to compile the xeon phi ported GCC (ported from GCC 4.7.0) from source and install it in a local subdirectory. However, I am getting the following error-
k1om-mpss-linux-gcc -dumpspecs > tmp-specs
/bin/sh: k1om-mpss-linux-gcc: command not found
My configuration is as follows-
# The below directory contains the cross compiled libs
# like assembler and linker
export PATH=$HOME/xeon-phi-gcc/bin
# The configure command
../xeon-phi-gcc/configure \
--build=x86_64-linux \
--host=x86_64-mpsssdk-linux \
--target=k1om-mpss-linux \
--prefix=$HOME/cross-gcc \
--enable-languages=c,c++ \
--with-sysroot=/opt/mpss/3.5.1/sysroots/k1om-mpss-linux \
--disable-multilib
# Compiling
make
Why is the Makefile calling k1om-mpss-linux-gcc ? Shouldn't this be the cross compiled gcc binary after make completes ? How can I fix this or what am I missing ?
EDIT 1: I changed the config parameters to --build=x86_64-mpsssdk-linux --host=x86_64-mpsssdk-linux. I get the following errors now-
In file included from gtype-desc.c:30:0:
../../gcc-4.7.0+mpss3.5.2/gcc/tree.h:3179:11: warning: identifier ‘thread_local’ conflicts with C++ keyword [-Wc++-compat]
unsigned thread_local : 1;
^
gtype-desc.c:8696:18: error: subscripted value is neither array nor pointer nor vector
sizeof (x_rtl[0]),
^
gtype-desc.c:8815:36: error: subscripted value is neither array nor pointer nor vector
sizeof (default_target_libfuncs[0]),
^
gtype-desc.c:8899:31: error: subscripted value is neither array nor pointer nor vector
sizeof (default_target_rtl[0]),
^
gtype-desc.c:8920:31: error: subscripted value is neither array nor pointer nor vector
sizeof (default_target_rtl[0]),
^
gtype-desc.c:8927:31: error: subscripted value is neither array nor pointer nor vector
sizeof (default_target_rtl[0]),
^
gtype-desc.c:8934:31: error: subscripted value is neither array nor pointer nor vector
sizeof (default_target_rtl[0]),
^
gtype-desc.c is a machine generated file.
EDIT 2: I am now getting the error-
/tmp/cc4aDvmI.s: Assembler messages:
/tmp/cc4aDvmI.s:94: Error: no such instruction: `kmov %esi,%k2'
/tmp/cc4aDvmI.s:147: Error: no such instruction: `kmov %edi,%k2'
/tmp/cc4aDvmI.s:255: Error: no such instruction: `kmov %r8d,%k2'
/tmp/cc4aDvmI.s:258: Error: no such instruction: `vpackstorelq %zmm0,(%rsp){%k2}'
How can I fix this ? These seem to be vector instructions but I thought that the gcc cross compiler didn't support vector instructions.

Your --build, --host and --target machine are all different (this is referenced as canadian compile, which is slightly different from cross compile, where --build and --host are the same). This means that an additional compiler is needed to build target libraries.
From GCC docs (6.1):
If build and host are different, you must have already built and installed a cross compiler that will be used to build the target libraries (if you configured with --target=foo-bar, this compiler will be called foo-bar-gcc).
So, as your --target is k1om-mpss-linux, you need that version of compiler in order to build GCC.
The result will be a GCC compiled on a --build machine that will run on a --host machine and that will produce code that can run on a --target machine.

Related

Pytorch Tensor::data_ptr<long long>() not working on Linux

I cannot link my program to pytorch under Linux, get the following error:
/tmp/ccbgkLx2.o: In function `long long* at::Tensor::data<long long>() const':
test.cpp:(.text._ZNK2at6Tensor4dataIxEEPT_v[_ZNK2at6Tensor4dataIxEEPT_v]+0x14): undefined reference to `long long* at::Tensor::data_ptr<long long>() const'
I am building a very simple minimal example:
#include "torch/script.h"
#include <iostream>
int main() {
auto options = torch::TensorOptions().dtype(torch::kInt64);
torch::NoGradGuard no_grad;
auto T = torch::zeros(20, options).view({ 10, 2 });
long long *data = (long long *)T.data<long long>();
data[0] = 1;
return 0;
}
The command used to build it:
g++ -w -std=c++17 -o test-torch test.cpp -D_GLIBCXX_USE_CXX11_ABI=1 -Wl,--whole-archive -ldl -lpthread -Wl,--no-whole-archive -I../libtorch/include -L../libtorch/lib -ltorch -ltorch_cpu -lc10 -Wl,-rpath,../libtorch/lib
Pytorch has been downloaded from the link https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.7.0%2Bcpu.zip and unzipped (so I have the libtorch folder next to the folder with test.cpp).
Any ideas how to solve this problem? Same program works just fine under Visual C++.
P.S. I know pytorch is kind of designed for cmake, but I have zero experience with cmake and no desire to write a cmake-based build system for my app. Also, the examples they give are seemingly supposed to only work if pytorch is "installed" in the system. So I cannot just download the .zip with libs? And if I "install" it (e.g. from sources or in whatever other way) on an AVX512 system, will the binary I link to it and distribute to end-users work on non-AVX512? The documentation is completely incomprehensible for newbies.
UPDATE: I tried to do this via CMake following the tutorial https://pytorch.org/cppdocs/installing.html and got exactly the same error. Specifically, I renamed my directory to example-app and the source file to example-app.cpp. Then I created CMakeLists.txt in this directory with the following contents:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example-app)
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)
Then
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=../../libtorch ..
cmake --build . --config Release
And here's the output:
CMakeFiles/example-app.dir/example-app.cpp.o: In function `long long* at::Tensor::data<long long>() const':
example-app.cpp:(.text._ZNK2at6Tensor4dataIxEEPT_v[_ZNK2at6Tensor4dataIxEEPT_v]+0x14): undefined reference to `long long* at::Tensor::data_ptr<long long>() const'
Makes me think, maybe I forgot to include some header or define some variable?
Oh, this is all on Mint 19.2 (equivalent to Ubuntu 18.04), g++ version is 7.5.0, glibc is 2.27. Compiling with g++-8 gives the same result.
This is not a cmake-related error, it's just how the library was implemented. I do not know why, but it appears that the specialization of T* at::Tensor::data<T> const with T = long long was forgotten/omitted.
If you want to get your signed 64-bits pointer, you can still get it with int64_t:
auto data = T.data<int64_t>();
It's good practice to use these types for which the size is explicit in general, in order to avoid compatibility issues.

undefined reference to `__gcov_exit'?

while I am building glibc library using yocto project it is giving
error: missing attribute ((constructor)) support??
after adding the coverage flags:
TARGET_CFLAGS += "-fprofile-arcs -ftest-coverage"
TARGET_LDFLAGS += "-lgcov -fprofile-arcs -ftest-coverage"
still, I am getting an error for glibc.
Please find the link of config log file : https://drive.google.com/file/d/14tiQJ8JIFE_tDWt3H9tS8zBBQROcZDNa/view
It is not working even after adding the following line in conf/local.conf :
EXTRA_OECONF = "libc_cv_ctors_header=yes"
Even i tried this
EXTRA_OECONF_append = "libc_cv_ctors_header=yes"
please find the config log file generated during compilation : https://drive.google.com/open?id=1kxTu8pt7h_9ty55OywP9Ilmmp04T61Rr
So, How to resolve this error?
Log file error Point
poky-linux/gcc/i586-poky-linux/8.2.0/ld: /tmp/ccxetEc1.o: in function `_GLOBAL__sub_D_00100_1__start':
conftest.c:(.text.exit+0x40): undefined reference to `__gcov_exit'<br>
collect2: error: ld returned 1 exit status<br>
configure:5682: $? = 1<br>
configure:5702: error: missing __attribute__ ((constructor)) support??
You are trying to build glibc with -fprofile-arcs -ftest-coverage in CFLAGS. That will not work. The errors you see are a result of these incorrect compiler flags.
A profiling glibc requires fairly substantial changes throughout the library and needs to be created by building with --enable-profile (which is not the default).
I had this error while I tried to enable coverage on a C project using a C++ test harness (CppUTest). Build system was handled by CMake.
Compilers and gcov were aligned on the same version (gcc --version, g++ --version and gcov --version gave the same version) but it seems that my build system was generated with a gcc 5 (resulting to an additional included directory by the linker: usr/lib/gcc/x86_64-linux-gnu/5). I clean the build tree and generated it again thanks to CMake which fixed the error.

Running gem5 with DramSim2

So I've been able to build gem5 and run full system simulation . Now i want to integrate it with dramSim2 .I cloned the dramsim2 into ext directory in gem5. I ran the following command to build the .opt file
again
scons build/ARM/gem5.opt
The error it throws is -
build/dramsim2/DRAMSim2/BusPacket.cpp: In member function 'void
DRAMSim::BusPacket::print(uint64_t, bool)':
build/dramsim2/DRAMSim2/BusPacket.cpp:63:2: error: nonnull
argument
'this' compared to NULL [-Werror=nonnull-compare]
if (this == NULL)
^~
build/dramsim2/DRAMSim2/BusPacket.cpp: In member function 'void
DRAMSim::BusPacket::print()':
build/dramsim2/DRAMSim2/BusPacket.cpp:104:2: error: nonnull
argument
'this' compared to NULL [-Werror=nonnull-compare]
if (this == NULL) //pointer use makes this a necessary precaution
^~
cc1plus: all warnings being treated as errors
scons: *** [build/dramsim2/DRAMSim2/BusPacket.os] Error 1
scons: building terminated because of errors.
Anyone know what it means ?
Dramsim2 is outdated, and its original author stop actively maintaining the project. Although you may want to fix the codes as described here, can you simply test if the build passes the failure point by additionally giving -Wno-nonnull compilation switch?
I solved this problem . I changed gcc, g++ version.
I changed gcc version from 6.0 to 4.8.
Use this command and change the version.
sudo update-alternatives --config gcc
sudo update-alternatives --config g++

Setting up Rocket-chip for Questasim and getting error while compiling jtag_vpi.c

I have downloaded Rocket-chip from GIT, installed RISC-V tools and Generated the verilog files for Rocket core. Now I want to run the assembly tests that are given but I dont have VCS instead I have Questasim. I modified the Makefile to use Questasim but the two C++ files that needs to be compiled SimDTM.cc and jtag_vpi.c are giving error.
In Questa we cant compile C files along with verilog files instead we need to compile this separately and generate *.so file and link with -pli while simulating.
Here when I'm compiling jtag_vpi.c I'm getting and error saying invalid conversion from 'void*' to 'PLI_INT32. I'm compiling it with the below command and the error I'm getting is also pasted below.
g++ jtag_vpi.c -I $RISCV/include -I $MTI_HOME/questasim/include -std=c++11 -W -shared -Bsymblic -fPIC
.
.
riscv/rocket-chip/csrc/jtag_vpi.c:398:2: error: invalid conversion from ‘void*’ to ‘PLI_INT32 (*)(t_cb_data*) {aka int (*)(t_cb_data*)}’ [-fpermissive]
Line 398:2 is just an end of a function and the error is shown at the end of each such function.
Any help will be useful.
Thanks in advance.

Problem in Cross-Compiling libSDL for MIPS Platform

I was trying to compile libSDL-1.2.14 for my mips platform.
But it was not successful.
These were the steps that I tried out :
export PATH=/opt/mips-4.3/bin:$PATH
Went inside the libSDL-1.2.14 source folder.
Gave a "./configure --prefix=/usr/local/SDL_Lib --host=mips-linux-gnu"
Executed the "make" command
This was the error received :
cc1: warning: include location
"/usr/include" is unsafe for
cross-compilation
./src/audio/dma/SDL_dmaaudio.c: In
function 'DMA_WaitAudio':
./src/audio/dma/SDL_dmaaudio.c:167:
error: can't find a register in class
'COP3_REGS' while reloading 'asm'
./src/audio/dma/SDL_dmaaudio.c:167:
error: 'asm' operand has impossible
constraints make: *
[build/SDL_dmaaudio.lo] Error 1
But then i reconfigured the make file by giving the following commands :
make clean
./configure --prefix=/usr/local/SDL_Lib --host=mips-linux-gnu CPPFLAGS=-I/opt/mips-4.3/mips-linux-gnu/libc/usr/include/
make
NOTE : /opt/mips-4.3/mips-linux-gnu/libc/usr/include/ - This is the path where you can locate the select.h file for the mips Platform.
It contains the definitions of the macros FD_ZERO and FD_SET.
Still I am getting the same error.
cc1: warning: include location
"/usr/include" is unsafe for
cross-compilation
./src/audio/dma/SDL_dmaaudio.c: In
function 'DMA_WaitAudio':
./src/audio/dma/SDL_dmaaudio.c:167:
error: can't find a register in class
'COP3_REGS' while reloading 'asm'
./src/audio/dma/SDL_dmaaudio.c:167:
error: 'asm' operand has impossible
constraints make: *
[build/SDL_dmaaudio.lo] Error 1
Please help me with some valuable pointers.
Thanks,
Sen
First, don't set the path to the cross-compiler as the first part of your PATH, set it as last:
export PATH=$PATH:<path to cross-compiler>
It's safer this way. Second, run ./configure --help to get all the options. What that error message would say if it was smarter is the following:
You're trying to cross-compile since you're setting the --host flag
But you're not changing any of the other options for where to find includes and libs for the target environment
I'm going to use /usr/include by default
But that's for the host system which will not work when cross-compiling
Check what other configure options you need to set to tell the configure script where to find the .h files (includes) and the libraries for your target. These usually come with the cross-compiler that you download. Also, you should probably set the CROSS_COMPILE environment variable to the cross-compiler prefix before running configure. The prefix is the part before gcc in a cross-compiler, assuming you're using GCC as your cross-compiler.

Resources