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).

3
  • 2
    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? Mar 30, 2017 at 9:31
  • 1
    What version of CUDA are you using?
    – talonmies
    Mar 30, 2017 at 9:50
  • @talonmies CUDA 5.5
    – Linda Cai
    Mar 30, 2017 at 16:53

4 Answers 4

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
1
  • 12
    Thanks! This worked. For convenience, the command is: ln -s /usr/local/cuda/include/crt/math_functions.hpp /usr/local/cuda/include/math_functions.hpp Dec 23, 2017 at 1:31
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.

3
  • I am using a campus cluster where software cannot easily be updated (by me). Is there no work around?
    – Linda Cai
    Mar 30, 2017 at 18:39
  • 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? Mar 30, 2017 at 19:22
  • @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!
    – Linda Cai
    Mar 30, 2017 at 21:48
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.

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"

1
  • actually I met the same issue and this is how I solved it.
    – hanyang
    Sep 21, 2020 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.