ARM build fixes
Before I issue a PR, let me explain the issues and how invasive this PR might be. The ARM compilers currently shipping in Ubuntu 12.04 and 14.04 for ARM have a but with members instantiated from multiple files. Secondly, currently on TK1, there is a bug in nvcc from the shipping CUDA 6.0 release that requires a workaround.
- Here is a script to swap things around to workaround the compiler bug. It clearly touches lots of files and impacts readability of the code. This is a GCC bug that only seems to crop up on ARM, but there isn't a pending fix we have been able to find. This seems to work on all platforms I've tested, although we are hitting a separate bug on PowerPC we need to figure out:
In src/caffe/layers
mkdir cpu for i in *.cu; do mv ${i%.cu}.cpp cpu/${i%.cu}.hpp; done for i in *.cu; do sed -i 's/INSTANTIATE///INSTANTIATE/' $i; done for i in *.cu; do sed -i "$a#include "cpu/${i%.cu}.hpp"\n " $i; done sed -i "s/const float kBNLL_THRESHOLD///const float kBNLL_THRESHOLD/" cpu/bnll_layer.hpp
- For CUDA 6.0 on L4T 19.3 - Shouldn't be needed when 6.5 ships on TK1 I believe, but don't cause harm.
In /caffe/src/caffe/util/math_functions.cu
replace:
template
template void caffe_gpu_set
with:
template <>
void caffe_gpu_set(const int N, const float alpha, float* Y) {
if (alpha == 0) {
CUDA_CHECK(cudaMemset(Y, 0, sizeof(float) * N));
return;
}
// NOLINT_NEXT_LINE(whitespace/operators)
set_kernel
template <>
void caffe_gpu_set(const int N, const double alpha, double* Y) {
if (alpha == 0) {
CUDA_CHECK(cudaMemset(Y, 0, sizeof(double) * N));
return;
}
// NOLINT_NEXT_LINE(whitespace/operators)
set_kernel
template <>
void caffe_gpu_set(const int N, const int alpha, int* Y) {
if (alpha == 0) {
CUDA_CHECK(cudaMemset(Y, 0, sizeof(int) * N));
return;
}
// NOLINT_NEXT_LINE(whitespace/operators)
set_kernel
Rebasing is proving to be a challenge with all of the layer code restructuring. This may take a little while. We'll get the script updated and then attempt the PR again.
Thanks for the attention to cross-platform issues. Could ARM installation be best covered in the Caffe wiki instead of a PR that re-arranges the code? I fully support making Caffe work on with the ARM toolchain, but am wary of costs to organization and clarity.
Personally I would rather not warp the project code for corner cases and dependencies bugs. There is already some pain from having to work around NVCC incompatibilities we've encountered with clang, boost, and opencv.
I tend to agree, which is why I started with the script that rearranges things before the (crazy) PR. The second patch just works around a CUDA 6 NVCC bug. And if you find NVCC bugs, please file bug reports through nvidia developer bug forms so we can attempt to get them fixed for the next release. Hopefully clang issues will be addressed with the next CUDA release.
I'm happy just to work on the script that move things around and post it to the wiki for now and that should cause much less noise.
I'm happy just to work on the script that move things around and post it to the wiki for now and that should cause much less noise.
Sounds good, thanks!
Could you double check that the current dev head still has the problem? I have already fixed all the issues (among some other C++ standard non-compliant stuff). The only thing you need to specify is
CUSTOM_CXX := g++-4.7
but that is because cuda 6.0 does not work with g++4.8 (a known issue).
(please see PR #1258 and #1264 for more details. I am going to release a more complete recipe once some internal review process finishes)
(forgot to mention, I got it compilable on jetson tk1)
Ah, forcing back to G++-4.7. Interestingly, we hit issues even with CUDA 6.5 internal builds and later builds with Ubuntu 12.04 and 14.04 which use newer GCC versions by default. It's something with the updated GCC, but we don't see it on x86. Different issues on Power. Let me give your workaround a go and perhaps this will go away.
And it does actually work with g++4.8 with your changes. Looks like we just crossed and your method was MUCH cleaner. Still some complaints from LMDB about integer sizes, but that is because LMDB I think assumes 64-bit devices.