0

This might actually be a ridiculous question, but there is so much about compilers/compiling that I don't understand. I'm aware of the concepts of cross compiling, cross-native compiling, etc. However, I am unaware of what applies for my scenario:

What I want to do is this.

Say I have two computers with different hardware, A and B.

Suppose that the only similarities between A and B I know for sure are:

  1. Both have some Intel processor capable of 64 bit computing.
  2. Both run Windows 10, and thus can access Linux through other means (e.g. WSL).
  3. Both A and B have all the programs necessary to compile (arbitrary) code.

Suppose that I also have administrative access to A (i.e. I can do/run/install whatever I want to/on it). This is not the case for B.

In addition, (this may be irrelevant), A can be accessed physically (and remotely if necessary). B can only be accessed remotely (via SSH, RDP, etc.)


Now say I want to compile some arbitrarily complex C/C++ code optimized specifically for the hardware on A with some compiler. For example, I believe -march=native can achieve this if I use gcc on A.

However, say A is special, and that its processing power cannot be "wasted" on compiling, for it has more important tasks to do. In other words, I do not want to go through the time and power consuming process of compilation on A.

Instead, I want to do this compilation for A on B.

How can I obtain an end result equivalent to a "-march=native" compile done on A (if gcc is used)? In other words, how can I compile code on B optimized precisely for the hardware on A?

For gcc, is it as simple as finding the equivalent flags for -march=native on A to then run execute on B? If so, is there a way to streamline this process and if not, how can it be done (if at all?).

Can the process be done with compilers other than gcc (namely, the Visual C++ and Intel C++ compilers)?

YenForYang
  • 2,998
  • 25
  • 22
  • If both systems have the same type of CPU and run the same OS, then you don't need cross-compilation as the target for both systems will be the same. If you want optimizations specific to a *variant* of the target CPU you can specify it with `-march` (and other [optimization flags and options](https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gcc/Optimize-Options.html#Optimize-Options)). – Some programmer dude Sep 25 '18 at 18:16

2 Answers2

0

Assuming you know architecture of destination server (A in your case) just pass it to gcc on B as -march.

Example

A architecture is skylake

so on B use

gcc -march=skylake ..... (rest of the flags)

if A is ryzen

gcc -march=znver1 ..... (rest of the flags)

and then copy files from B to A.

Anty
  • 1,486
  • 1
  • 9
  • 12
0

Intel Compiler can be used for generating executables targeting other architectures either by using GCC compatible option which is -march or ICC specific option which is -x. These options are documented at https://software.intel.com/en-us/cpp-compiler-developer-guide-and-reference-x-qx and https://software.intel.com/en-us/cpp-compiler-developer-guide-and-reference-march.

Anoop - Intel
  • 354
  • 2
  • 11