math_functions.hpp not found when using CUDA with Eigen
Asked Answered
E

4

6

I have some code that is heavily dependent on Eigen. I would like to optimize it with CUDA, but when I am compiling I get:

[tcai4@golubh4 Try1]$ nvcc conv_parallel.cu -I /home/tcai4/project-cse/Try1 -lfftw3 -o conv.o
In file included from Eigen/Dense:1,
             from Eigen/Eigen:1,
             from functions.h:8,
             from conv_parallel.cu:10:
Eigen/Core:44:34: error: math_functions.hpp: No such file or directory

I think math_functions.hpp is a file from CUDA. Can someone help me figure out why nvcc cannot find it?

edit: I am using CUDA 5.5 and Eigen 3.3, except from linking Eigen and fftw3 library, I did not use any other flags(as you can see from my code).

Este answered 30/3, 2017 at 9:18 Comment(3)
Can you specify which version of Eigen and nvcc you are using? Also, compiler flags and include paths? Better yet, can you reduce it to a minimal reproducible example?Stephanistephania
What version of CUDA are you using?Benedicite
@Benedicite CUDA 5.5Este
B
4

The reason nvcc cannot find the file in question is because that file is part of the CUDA Math library, which was introduced in CUDA 6. Your almost 4 year old version of CUDA predates the release of the Math library. Your CUDA version doesn't contain said file.

You should, therefore, assume that what you are trying to do cannot work without first updating to a newer version of the CUDA toolkit.

Benedicite answered 30/3, 2017 at 9:19 Comment(3)
I am using a campus cluster where software cannot easily be updated (by me). Is there no work around?Este
If this is on blue waters you should certainly have newer versions of CUDA available to you than CUDA 5.5. Are you loading the correct modules/programming environment?Homoiousian
@RobertCrovella you are right! The document on CUDA gave an example to load CUDA 5.5, so I thought I can only load CUDA 5.5, however apparently I can also load CUDA 7.0 and that solves my issue. Thank you!Este
A
25

I encountered this issue while building TensorFlow 1.4.1 with Cuda 9.1, and strangely math_functions.hpp existed only in include/crt.

Creating a symlink from cuda/include/math_functions.hpp to cuda/include/crt/math_functions.hpp fixed the issue:

ln -s /usr/local/cuda/include/crt/math_functions.hpp /usr/local/cuda/include/math_functions.hpp
Autocrat answered 14/12, 2017 at 6:26 Comment(1)
Thanks! This worked. For convenience, the command is: ln -s /usr/local/cuda/include/crt/math_functions.hpp /usr/local/cuda/include/math_functions.hppVisitation
B
4

The reason nvcc cannot find the file in question is because that file is part of the CUDA Math library, which was introduced in CUDA 6. Your almost 4 year old version of CUDA predates the release of the Math library. Your CUDA version doesn't contain said file.

You should, therefore, assume that what you are trying to do cannot work without first updating to a newer version of the CUDA toolkit.

Benedicite answered 30/3, 2017 at 9:19 Comment(3)
I am using a campus cluster where software cannot easily be updated (by me). Is there no work around?Este
If this is on blue waters you should certainly have newer versions of CUDA available to you than CUDA 5.5. Are you loading the correct modules/programming environment?Homoiousian
@RobertCrovella you are right! The document on CUDA gave an example to load CUDA 5.5, so I thought I can only load CUDA 5.5, however apparently I can also load CUDA 7.0 and that solves my issue. Thank you!Este
O
0

Creating symlink sometimes causes other complication.

You can try replacing

// We need math_functions.hpp to ensure that that EIGEN_USING_STD_MATH macro
// works properly on the device side
#include <math_functions.hpp>

with

// We need cuda_runtime.h to ensure that that EIGEN_USING_STD_MATH macro
// works properly on the device side
#include <cuda_runtime.h>

in

/usr/include/eigen3/Eigen/Core,

which works for me.

Orton answered 28/7, 2019 at 18:24 Comment(0)
B
0

The reason why "math_functions.hpp" cannot be found is because "math_functions.hpp" has been renamed to "math_functions.h". So you just need to go to

/usr/include/eigen3/Eigen/Core

and change "math_functions.hpp" to "math_functions.h"

Bud answered 21/9, 2020 at 2:18 Comment(1)
actually I met the same issue and this is how I solved it.Bud

© 2022 - 2024 — McMap. All rights reserved.