Compiling Tests for RISC-V

username: derekz.tu
cooked: <p>I’m trying to have tests be created for RISC-V. In particular I’m looking at the GemmTest. From what I understand because GemmTest depends on libjit_matmul_f I should be building libjit targeting RISC-V. However, doing only that does not result in the test/GemmTest binary being built for RISC-V. Is there something else I should be doing?</p>
<p>From the build log I can see that GemmTest gets compiled twice. The first time GemmTest.cpp is compiled into GemmTest.cpp.o. Then again later on, after some supporting libraries are built I assume, GemmTest.cpp.o is compiled into the executable GemmTest binary. Would someone be kind enough to explain what each compilation step does, and which step(s) I should be looking at in order to build GemmTest for another target?</p>

username: Bert_Maher
cooked: <p>Hey Derek,</p>
<p>GemmTest is actually a pretty straightforward CMake executable, so you can ignore a bunch of the libjit complexity.  The bits of CMake that are most interesting here are:</p>
<ul>
<li>the GemmTest definition itself: <a href="https://github.com/pytorch/glow/blob/master/tests/unittests/CMakeLists.txt#L129" rel="nofollow noopener">https://github.com/pytorch/glow/blob/master/tests/unittests/CMakeLists.txt#L129</a>
</li>
<li>the CPURuntimeNative library which compiles libjit as a typical library: <a href="https://github.com/pytorch/glow/blob/master/lib/Backends/CPU/CMakeLists.txt#L65" rel="nofollow noopener">https://github.com/pytorch/glow/blob/master/lib/Backends/CPU/CMakeLists.txt#L65</a>
</li>
</ul>
<p>Do note that these targets are disabled when building with MSVC; I don’t remember why since I haven’t built on Windows myself.</p>
<p>Bert</p>

username: derekz.tu
cooked: <p>Hi Bert,</p>
<p>Thanks for the reply. So from these two CMakeLists.txt I can see that GemmTest depends on CPURuntimeNative, etc, and CPURuntimeNative is built using the libjit files. I know for the libjit files you can build them for a different architecture by<br>
adding "-target " into: <a href="https://github.com/pytorch/glow/blob/71f2ec208b1306f422da7fb1562254eb225d32ae/lib/Backends/CPU/CMakeLists.txt#L16" rel="nofollow noopener">https://github.com/pytorch/glow/blob/71f2ec208b1306f422da7fb1562254eb225d32ae/lib/Backends/CPU/CMakeLists.txt#L16</a></p>
<p>However, I am unable to find such an option/figure out what to change that will allow me to have GemmTest be compiled for another architecture ie ARM or RISC-V. Is this possible? Or would it better for me to write my own test case? In which case again are there any pointers on how I would build it for another architecture already supported by the LLVM?</p>

username: Bert_Maher
cooked: <p>Ah, I see the confusion - the cmake options you’re pointing to are for building libjit as bytecode, to be later loaded by the Glow runtime.  You want to configure the cmake project for cross-compilation to build a RISC-V binary</p>

username: derekz.tu
cooked: <p>Yep is it possible to configure the cmake project for cross-compilations to build a RISC-V binary? Or would it be better for me to try and emit a RISC-V bundle through model-runner/image-classifier?</p>

username: Bert_Maher
cooked: <p>You can definitely configure CMake to do cross compilation though I’ve not done it with Glow myself (here’s, e.g., an example of how to cross-compile llvm/clang itself: <a href="https://llvm.org/docs/HowToCrossCompileLLVM.html" rel="nofollow noopener">https://llvm.org/docs/HowToCrossCompileLLVM.html</a>).  The main things to do are to set --target and --sysroot appropriately in your CMAKE_CXX_FLAGS.</p>