FAQ  •  Login

CMake Questions (Please post them here)

<<

jiashenboon

Newbie
Newbie

Posts: 34

Joined: Fri Sep 04, 2015 12:51 pm

Unread post Sun Oct 04, 2015 7:33 pm

Re: CMake Questions (Please post them here)

michaeltaylor wrote:I was running into the same issue. From what I gathered, the issue had to do with using c++11.

If that is what you are doing, try adding the following line to ~/.bashrc
module load cuda gcc/4.9.2

Then use the following CMAKE file:
  Code:
# Set the required version of CMake
cmake_minimum_required(VERSION 2.8)
# Set your project title
project(ME759_Homework)

# Include macros from the ParallelUtils library
include(ParallelUtils.cmake)

enable_cuda_support()
if(UNIX)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    SET(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11")
endif()

#The following will put all binary files in a "bin" directory
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

#Add subdirectories for each homework
add_subdirectory(homework_01)
add_subdirectory(homework_02)
add_subdirectory(homework_03)


Best of Luck,

Mike


Hey it works, thanks! Ang (the TA) suggested that I do:

  Code:
cmake .. -DCMAKE_BUILD_TYPE=Release -DCUDA_NVCC_FLAGS_RELEASE=-std=c++11 -DCMAKE_CXX_FLAGS=-std=c++11


But your method seems cleaner since I don't have to copy-paste this command all the time. Thanks!

[EDIT: OK after I deleted my build directory and ran cmake/make again, your method didn't work even after I did the module load. CMake works in mysterious ways.]
<<

jiashenboon

Newbie
Newbie

Posts: 34

Joined: Fri Sep 04, 2015 12:51 pm

Unread post Sun Oct 04, 2015 7:52 pm

Re: CMake Questions (Please post them here)

This is on HW4Q3b. Is anyone else having issues getting matrixadd.cu's MatrixAddOnDevice() to "see" matrixadd_kernel's MatrixAddKernel()? I'm getting a

  Code:
/home/jiashen/me759_homework/homework_04/matrixadd.cu(219): error: identifier "MatrixAddKernel" is undefined


when I make, which makes a lot of sense, since there's no header file with a function prototype for MatrixAddKernel. Right now my CMakeLists.txt has a cuda_add_executable which includes all the matrix*.h matrix*.cpp and matrix*.cu. Am I missing something?
<<

HammadM

Supreme Overlord
Supreme Overlord

Posts: 37

Joined: Wed Sep 03, 2008 12:23 pm

Unread post Mon Oct 05, 2015 11:06 am

Re: CMake Questions (Please post them here)

jiashenboon wrote:
michaeltaylor wrote:I was running into the same issue. From what I gathered, the issue had to do with using c++11.

If that is what you are doing, try adding the following line to ~/.bashrc
module load cuda gcc/4.9.2

Then use the following CMAKE file:
  Code:
# Set the required version of CMake
cmake_minimum_required(VERSION 2.8)
# Set your project title
project(ME759_Homework)

# Include macros from the ParallelUtils library
include(ParallelUtils.cmake)

enable_cuda_support()
if(UNIX)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    SET(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11")
endif()

#The following will put all binary files in a "bin" directory
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

#Add subdirectories for each homework
add_subdirectory(homework_01)
add_subdirectory(homework_02)
add_subdirectory(homework_03)


Best of Luck,

Mike


Hey it works, thanks! Ang (the TA) suggested that I do:

  Code:
cmake .. -DCMAKE_BUILD_TYPE=Release -DCUDA_NVCC_FLAGS_RELEASE=-std=c++11 -DCMAKE_CXX_FLAGS=-std=c++11


But your method seems cleaner since I don't have to copy-paste this command all the time. Thanks!

[EDIT: OK after I deleted my build directory and ran cmake/make again, your method didn't work even after I did the module load. CMake works in mysterious ways.]


Cmake has a weird issue where even after you module load it will not pick up the correct compiler for nvcc. if you run "ccmake ." you should be able to change the path for the cuda host compiler.

Here is what I would try:
Module load compiler (module load gcc/4.9.2)
Delete cmake build and regenerate it
run "ccmake ." in your build directory
hit the "t" key
set CMAKE_CXX_COMPILER to /usr/local/gcc/4.9.2/bin/g++
set CMAKE_C_COMPILER to /usr/local/gcc/4.9.2/bin/gcc
hit the "c" key to reconfigure
it will say that the compiler changed, hit "e" to exit the message
set CUDA_HOST_COMPILER to /usr/local/gcc/4.9.2/bin/gcc or /usr/local/gcc/4.9.2/bin/g++
reconfigure and generate -> "c" and then "g"

You will still need to set "-std=c++11" like you were earlier if you need c++11 functionality

Basically we force cmake to use the correct compiler for both host compilation (CMAKE_CXX_COMPILER, CMAKE_C_COMPILER) and host compialtion through nvcc (CUDA_HOST_COMPILER)
<<

jiashenboon

Newbie
Newbie

Posts: 34

Joined: Fri Sep 04, 2015 12:51 pm

Unread post Mon Oct 05, 2015 8:16 pm

Re: CMake Questions (Please post them here)

jiashenboon wrote:This is on HW4Q3b. Is anyone else having issues getting matrixadd.cu's MatrixAddOnDevice() to "see" matrixadd_kernel's MatrixAddKernel()? I'm getting a

  Code:
/home/jiashen/me759_homework/homework_04/matrixadd.cu(219): error: identifier "MatrixAddKernel" is undefined


when I make, which makes a lot of sense, since there's no header file with a function prototype for MatrixAddKernel. Right now my CMakeLists.txt has a cuda_add_executable which includes all the matrix*.h matrix*.cpp and matrix*.cu. Am I missing something?


Answering my own question, I solved this compilation problem by adding a function prototype for MatrixAddKernel to matrixadd.cu. Including matrixadd_kernel.cu to matrix.add.cu doesn't work because make will complain about duplication definitions.
<<

parvathimadathilkooloth

Newbie
Newbie

Posts: 11

Joined: Fri Sep 04, 2015 12:51 pm

Unread post Mon Oct 05, 2015 11:04 pm

Re: CMake Questions (Please post them here)

jiashenboon wrote:
jiashenboon wrote:This is on HW4Q3b. Is anyone else having issues getting matrixadd.cu's MatrixAddOnDevice() to "see" matrixadd_kernel's MatrixAddKernel()? I'm getting a

  Code:
/home/jiashen/me759_homework/homework_04/matrixadd.cu(219): error: identifier "MatrixAddKernel" is undefined


when I make, which makes a lot of sense, since there's no header file with a function prototype for MatrixAddKernel. Right now my CMakeLists.txt has a cuda_add_executable which includes all the matrix*.h matrix*.cpp and matrix*.cu. Am I missing something?


Answering my own question, I solved this compilation problem by adding a function prototype for MatrixAddKernel to matrixadd.cu. Including matrixadd_kernel.cu to matrix.add.cu doesn't work because make will complain about duplication definitions.


Hey Jiashen,

I had the same issue and fixed it by adding a function prototype for 'MatrixAddKernel' in matrixadd.cu like you said. And it makes sense why that should work. But I am a little concerned as the question forbids changes to source code except where specified. Is there another way around this?

-Parvathi
<<

HammadM

Supreme Overlord
Supreme Overlord

Posts: 37

Joined: Wed Sep 03, 2008 12:23 pm

Unread post Tue Oct 06, 2015 9:23 am

Re: CMake Questions (Please post them here)

I would suggest adding

"__global__ void MatrixAddKernel(const float* Melems, const float alpha, const float* Nelems, const float beta, float* Pelems);" to "matrixadd.h"

but there are other ways to fix the issue that are just as good.

Also in viewtopic.php?f=17&t=713 Dan says that you can modify source files for this homework.
<<

kaizhao

Newbie
Newbie

Posts: 21

Joined: Fri Sep 04, 2015 12:51 pm

Unread post Sun Oct 25, 2015 4:27 pm

Re: CMake Questions (Please post them here)

So it seems like the homework folder structure has changed in HW5 and HW6 so that each problem has been put into a separate folder. In the past, we were told to put all homework problems in the same folder structure. I know how to modify the CMakeList.txt file, but my question is: Does the grader want to provide us with the CMakeList.txt file/standard so that it is more convenient/easier to grade?
Previous

Return to ME759 Fall 2015: High Performance Computing

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software.