Build MAGMA for Windows with CMake and VS, no Fortran

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)
Post Reply
mct
Posts: 3
Joined: Tue Jun 30, 2015 2:23 pm

Build MAGMA for Windows with CMake and VS, no Fortran

Post by mct » Tue Jul 07, 2015 4:25 pm

Hello, I have seen plenty of posts saying people have successfully built MAGMA on Windows, but few with step-by-step instructions and none that used Cmake and without Fortran.

So far, I have generated the solutions with Cmake by altering the CMakeLists.txt as follows:
removed FORTRAN from the line: project( MAGMA C CXX FORTRAN )
commented out the lines:
include( FortranCInterface )
FortranCInterface_HEADER( ${CMAKE_SOURCE_DIR}/include/mangling.h MACRO_NAMESPACE MAGMA_ )

This was necessary for CMake to configure without errors.
I also input the path to the LAPACK libraries, and CMake generated with no problems.

Next, I open MAGMA.sln (in Visual Studio 2010), and attempt to build the solution.
I get the error: "One of ADD_, NOCHANGE, or UPCASE must be defined to set how Fortran functions are name mangled. For example, in MAGMA, add -DADD_ to CFLAGS, FFLAGS, etc. in make.inc. If using CMake, it defines MAGMA_GLOBAL instead."

Evidently, CMake is not defining MAGMA_GLOBAL. I cannot see where this should be occurring, any help on the CMakeLists would be appreciated as I have little experience with it.
I also tried explicitly defining NOCHANGE in magma_mangling.h, which allowed a few of the MAGMA projects to build, including the main project titled magma, lapacktest, and testing, thus building the three .lib files. The nearly all the other 433 projects fail due to unresolved externals for what look like every BLAS and LAPACK routine. When I instead define ADD_, the same unresolved externals occur except with _ at the end of each symbol, which seems to indicate the problem is that the Fortran functions are not being found, which makes sense.
Since there seems to be plenty of documentation on building MAGMA without Fortran, I am guessing there is something more necessary though I cannot find what that is.

If there is no way to do this without ifort, then I will just keep trying to use mingw, since there seem to be plenty of people to successfully compiled MAGMA for Windows that way, though it seems less straightforward than CMake -> Visual Studio should be.
Thank you

mgates3
Posts: 918
Joined: Fri Jan 06, 2012 2:13 pm

Re: Build MAGMA for Windows with CMake and VS, no Fortran

Post by mgates3 » Tue Jul 07, 2015 10:58 pm

FortranCInterface_HEADER determines the Fortran calling convention and generates the header mangling.h. Since you disabled that, you can simply put

#define ADD_

inside the include/mangling.h header. Assuming that your Fortran calling convention is to add _ after the routine name. This is very common.

-mark

mct
Posts: 3
Joined: Tue Jun 30, 2015 2:23 pm

Re: Build MAGMA for Windows with CMake and VS, no Fortran

Post by mct » Wed Jul 08, 2015 11:26 am

Thanks for the quick reply. I have tried this but I keep getting unresolved externals for what looks like the entire (non-MAGMA) LAPACK suite.
I get: unresolved external symbol ______ referenced in function main
where ______ is any LAPACK subroutine. I have tested my LAPACK libraries and they seem to compile for many of these (using the ADD_ convention) without needing Fortran. Is this more likely an issue of needing Fortran, or CMake not setting up the path to LAPACK properly?

mgates3
Posts: 918
Joined: Fri Jan 06, 2012 2:13 pm

Re: Build MAGMA for Windows with CMake and VS, no Fortran

Post by mgates3 » Wed Jul 08, 2015 1:40 pm

Is your error message like this:
unresolved external symbol dpotrf referenced in function main
or with an underscore like this:
unresolved external symbol dpotrf_ referenced in function main
or something else?

Since you defined ADD_, it should be the later, dpotrf_.

It sounds like it isn't finding the LAPACK library. What is the output when you do configure in CMake? Does it look like it found the right library?

For instance, on our machine, it looks something like below. You can override the LAPACK_LIBRARIES if you want a different library than what it found automatically. (This actually doesn't work -- I don't know why cmake sets LAPACK_LIBRARIES to FALSE. But if I set LAPACK_LIBRARIES to what it found for BLAS_LIBRARIES, everything links.)

Code: Select all

 -- Found OpenMP
    OpenMP_C_FLAGS   -fopenmp
    OpenMP_CXX_FLAGS -fopenmp
 -- Found CUDA 7.0
    CUDA_INCLUDE_DIRS:   /mnt/scratch/cuda/include
    CUDA_CUDART_LIBRARY: /mnt/scratch/cuda/lib64/libcudart.so
    GPU_TARGET Fermi Kepler
    GPU_TARGET_NEW Fermi Kepler sm20 sm30 sm35
    compile for CUDA arch 2.x (Fermi)
    compile for CUDA arch 3.0 (Kepler)
    compile for CUDA arch 3.5 (Kepler)
 -- Searching for BLAS and LAPACK. To override, set LAPACK_LIBRARIES using ccmake.

    BLAS_LIBRARIES:
 /mnt/scratch/sw/intel/composer_xe_2015.3.187/mkl/lib/intel64/libmkl_intel_lp64.so;/mnt/scratch/sw/intel/composer_xe_2015.3.187/mkl/lib/intel64/libmkl_gnu_thread.so;/mnt/scratch/sw/intel/composer_xe_2015.3.187/mkl/lib/intel64/libmkl_core.so

    LAPACK_LIBRARIES:    FALSE

 -- MKLROOT set to /mnt/scratch/sw/intel/composer_xe_2015.3.187/mkl. To change, edit MKLROOT using ccmake.

 -- Flags
    CFLAGS        -fopenmp -Wall -Wno-unused-function -std=c99
    CXXFLAGS	  -fopenmp -Wall -Wno-unused-function
    NFLAGS        -DHAVE_CUBLAS  -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode
 arch=compute_35,code=sm_35 -gencode arch=compute_35,code=compute_35
    FFLAGS
-mark

mct
Posts: 3
Joined: Tue Jun 30, 2015 2:23 pm

Re: Build MAGMA for Windows with CMake and VS, no Fortran

Post by mct » Wed Jul 08, 2015 3:06 pm

The error messages I am getting were initially the former, as I was using NOCHANGE before I did some testing with LAPACK to determine how it is used. Now that I am instead defining ADD_ my error messages are the latter, and some are:

unresolved external symbol sgetrf_ referenced in function magma_sgesv

or of that form.

CMake is setting BLAS_LIBRARIES to FALSE for me, and leaving LAPACK_LIBRARIES blank. I get this when I first configure:

Code: Select all

Try OpenMP C flag = [/openmp]
Performing Test OpenMP_FLAG_DETECTED
Performing Test OpenMP_FLAG_DETECTED - Success
Try OpenMP CXX flag = [/openmp]
Performing Test OpenMP_FLAG_DETECTED
Performing Test OpenMP_FLAG_DETECTED - Success
Found OpenMP: /openmp  
-- Found OpenMP
   OpenMP_C_FLAGS   /openmp
   OpenMP_CXX_FLAGS /openmp
Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.0 (found version "7.0") 
-- Found CUDA 7.0
   CUDA_INCLUDE_DIRS:   C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.0/include
   CUDA_CUDART_LIBRARY: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.0/lib/Win32/cudart.lib
   GPU_TARGET Fermi Kepler
   compile for CUDA arch 2.x (Fermi)
   compile for CUDA arch 3.x (Kepler)
-- Searching for BLAS and LAPACK. To override, set LAPACK_LIBRARIES using ccmake.
Looking for include file pthread.h
Looking for include file pthread.h - not found
Found Threads: TRUE  
A library with BLAS API not found. Please specify library location.
LAPACK requires BLAS
A library with LAPACK API not found. Please specify library location.
   BLAS_LIBRARIES:      FALSE
   LAPACK_LIBRARIES:    
-- MKLROOT not set. To change, set MKLROOT using ccmake.
Looking for sys/types.h
Looking for sys/types.h - found
Looking for stdint.h
Looking for stdint.h - found
Looking for stddef.h
Looking for stddef.h - found
Check size of void*
Check size of void* - done
-- Flags
   CFLAGS    /DWIN32 /D_WINDOWS /openmp -W4 -MP
   CXXFLAGS  /DWIN32 /D_WINDOWS /GR /EHsc /openmp -W4 -MP
   NFLAGS    -DHAVE_CUBLAS  -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_35,code=compute_35
   FFLAGS    /W1 /nologo /fpp /libs:dll /threads -Dmagma_devptr_t="integer(kind=4)"
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_cublas_LIBRARY (ADVANCED)
    linked by target "magma" in directory C:/Users/t0598608/Downloads/magma

Configuring incomplete, errors occurred!
See also "C:/Users/t0598608/Downloads/magma/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/t0598608/Downloads/magma/build/CMakeFiles/CMakeError.log".
Then I set the LAPACK_LIBRARIES to the libblas.lib and liblapack.lib, and the CMake output becomes:

Code: Select all

-- Found OpenMP
   OpenMP_C_FLAGS   /openmp
   OpenMP_CXX_FLAGS /openmp
Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.5 (found version "5.5") 
-- Found CUDA 5.5
   CUDA_INCLUDE_DIRS:   C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.5/include
   CUDA_CUDART_LIBRARY: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.5/lib/Win32/cudart.lib
   GPU_TARGET Fermi Kepler
   compile for CUDA arch 2.x (Fermi)
   compile for CUDA arch 3.x (Kepler)
-- User set LAPACK_LIBRARIES. To change, edit LAPACK_LIBRARIES using ccmake (set to empty to enable search).
   BLAS_LIBRARIES:      
   LAPACK_LIBRARIES:    C:\Users\t0598608\Documents\SampleLAPACK\SampleLAPACK\libblas.lib;C:\Users\t0598608\Documents\SampleLAPACK\SampleLAPACK\liblapack.lib
-- MKLROOT not set. To change, set MKLROOT using ccmake.
-- Flags
   CFLAGS    /DWIN32 /D_WINDOWS /openmp -W4 -MP
   CXXFLAGS  /DWIN32 /D_WINDOWS /GR /EHsc /openmp -W4 -MP
   NFLAGS    -DHAVE_CUBLAS  -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_35,code=compute_35
   FFLAGS    /W1 /nologo /fpp /libs:dll /threads -Dmagma_devptr_t="integer(kind=4)"
Configuring done
I do not have mkl, and it appears the BLAS_LIBRARIES has a different value at output, as it is blank for me. Should I be including libblas.lib in a different way, maybe setting the BLAS_LIBRARIES directly?

mgates3
Posts: 918
Joined: Fri Jan 06, 2012 2:13 pm

Re: Build MAGMA for Windows with CMake and VS, no Fortran

Post by mgates3 » Wed Jul 08, 2015 3:59 pm

If you manually set LAPACK_LIBRARIES, then BLAS_LIBRARIES will be empty. Just put both the LAPACK and BLAS libraries into LAPACK_LIBRARIES, as you did. You may need to swap the order, putting lapack first, then blas -- I don't know if Visual Studio is finicky about the library order, but that's the order needed with gcc.

What BLAS and LAPACK libraries are you using? The lapack library in ATLAS is incomplete -- it needs to be linked with the full lapack library from netlib.

Can you link a simple test program that calls those same missing functions in LAPACK? For example, this should link.

Code: Select all

extern "C"
void sgetrf_( int* m, int* n, float* A, int* lda, int* ipiv, int* info );

int main()
{
    int m=0, n=0, lda=1, info=0;
    int *ipiv = 0;
    float *A  = 0;
    sgetrf_( &m, &n, A, &lda, ipiv, &info );
    return 0;
}
-mark
Last edited by mgates3 on Wed Jul 08, 2015 4:03 pm, edited 1 time in total.
Reason: add lda and initialize m=0, n=0 to avoid segfault

Post Reply