Jetson TK1 Use CUDA 6.5 After Upgrade to Ubuntu 16.04
After previously I am successfully upgrading my Jetson TK1 in here,
Then check nvcc
,
ubuntu@tegra-ubuntu:~$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2014 NVIDIA Corporation
Built on Wed_Nov_12_15:57:57_CST_2014
Cuda compilation tools, release 6.5, V6.5.30
I see there nvcc
still recognized. But, when I try to run simple CUDA program like this,
#include <iostream>
#include <math.h>
// Kernel function to add the elements of two arrays
__global__
void add(int n, float *x, float *y)
{
for (int i = 0; i < n; i++)
y[i] = x[i] + y[i];
}
int main(void)
{
int N = 1<<20;
float *x, *y;
// Allocate Unified Memory – accessible from CPU or GPU
cudaMallocManaged(&x, N*sizeof(float));
cudaMallocManaged(&y, N*sizeof(float));
// initialize x and y arrays on the host
for (int i = 0; i < N; i++) {
x[i] = 1.0f;
y[i] = 2.0f;
}
// Run kernel on 1M elements on the GPU
add<<<1, 1>>>(N, x, y); // Wait for GPU to finish before accessing on host
cudaDeviceSynchronize();
// Check for errors (all values should be 3.0f)
float maxError = 0.0f;
for (int i = 0; i < N; i++)
maxError = fmax(maxError, fabs(y[i]-3.0f));
std::cout << "Max error: " << maxError << std::endl;
// Free memory
cudaFree(x);
cudaFree(y);
return 0;
}
Just give the code with name array_addition.cu
, then compile using nvcc
,
nvcc array_addition.cu -o array_addition
It’s giving me error related to gcc
not supported,
In file included from /usr/local/cuda/bin/../targets/armv7-linux-gnueabihf/include/cuda_runtime.h:59:0,
from <command-line>:0:
/usr/local/cuda/bin/../targets/armv7-linux-gnueabihf/include/host_config.h:82:2: error: #error -- unsupported GNU version! gcc 4.9 and up are not supported!
#error -- unsupported GNU version! gcc 4.9 and up are not supported!
Then if you check, the gcc
version,
ubuntu@tegra-ubuntu:~$ gcc --version
gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
It’s gives you newer than the original (gcc 4.8
).
I just found the solution from here,
By adding symlink
from the supported gcc
to the CUDA 6.5,
Before do that, first installing gcc 4.8
and g++4.8
,
sudo apt-get install gcc-4.8 g++-4.8 -y
Add symlink,
sudo ln -s /usr/bin/gcc-4.8 /usr/local/cuda/bin/gcc
sudo ln -s /usr/bin/g++-4.8 /usr/local/cuda/bin/g++
Then retry to build above Simple CUDA code, then program should be compiled successfully.