cs344 ยป

CS344/cmake dev

This page describes setting up the homework assignments on your local machine using cmake to create the project / solution files. For those who do not know cmake see http://en.wikipedia.org/wiki/CMake

In CS344 using cmake makes sense since the students have different OS and using different compilers. The following how to was tested with CUDA 4.2, OpenCV and Visual Studio 2010 on Windows 7, as well as CUDA 5 with NSight on Ubuntu 13.04.

For Windows

Prerequisites

  • Install the CUDA toolkit.  This has been tested with versions 4.2 and 5.0.
  • Download and install CMake: Cmake.org
  • "Install" OpenCV.  Follow the download link on http://opencv.org/
    • Run the EXE to extract the files.  This EXE does not have an installer.  Instead, you put your files where you want, and then add an environment variable
    • Adding the environment variable: The variable you need to add is named "OpenCV_DIR" (no quotes).
      • to add variables, see here: http://www.itechtalk.com/thread3595.html (first hit on Google.)
      • set the OpenCV_DIR variable to the "build" subfolder in the folder where you extracted.  The exact folder you need will have one very important file in it: OpenCVConfig.cmake - this tells CMake which variables to set for you.
      • Here's the really awesome thing: OpenCV comes built for several versions of Visual Studio (and versions for 32-bit and 64-bit.) CMake is smart enough to choose the correct one automatically!
  • To make sure that all the path variables are sorted out, log out and log back in (or restart your computer.) This may not be necessary, but it's a good idea for not getting stale PATH variables.
  • Proceed with building the classwork

Down to business

  • checkout the sourcecode of cs344 using git clone with repository from Udacity's github
  • Try to run cmake-gui:
    • Select the source folder and select an empty binary folder (I prefer a binary outside of the source folder so you won't struggle with git).
    • Click configure
    • Choose your compiler
    • If configuration was successful click on generate. Done! You now can open the project / solution in your IDE and compile everything.
  • You probably will need to add a directory to your PATH system variable.  This will make the OpenCV binary DLLs available to your compiled programs.  The CMake GUI will tell you which folder to add as it generates your project files.

Linux - compile/debug with command line

Prerequisites:

  • For Ubuntu/Debian, follow the instructions provided by your classmates: Ubuntu setup
  • For Red Hat/Fedora based systems: follow the instructions provided by your classmates: Fedora setup
  • install ccmake

Ubuntu:

sudo apt-get install cmake-curses-gui

Fedora:

sudo yum install cmake

Down to business

Checkout the sourcecode of cs344 using git clone with repository from Udacity's github

git clone https://github.com/udacity/cs344.git

Create a folder for the build.  This can be a subdirectory of the checked out folder, or it can be anywhere else.

cd cs344
mkdir build

From a command prompt, navigate into this folder.

  cd build

Run ccmake, with the argument being the path to the root of the cloned source code.

ccmake ../
  • Configure using the "c" key, then generate using the "g" key.
  • Run "make"
  • If make completes successfully, your binaries will be in their respective HW folders of your cloned source code.

Linux/Mac OSX - compile/debug with Nvidia NSight

Prerequisites:

  • Similar to above instructions for Linux, but with addition of CUDA toolkit that comes with CUDA 5.0 - this includes nsight.

Down to business

Checkout the sourcecode of cs344 using git clone with repository from Udacity's github

git clone https://github.com/udacity/cs344.git

Navigate to the checked out folder.

Generate the Eclipse project files:

cmake -G"Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug

Open NSight.  Import the project into your workspace from the File->Import... menu.

  • Under the "General" root folder, select "Existing projects into workspace"
  • Browse for the root directory; point it to the folder where you checked out the code.  You do not need to copy projects into your workspace.

Running binaries built using CMake:

Prerequisites:

  • Your system needs to be able to find the appropriate OpenCV shared libraries (dll for windows, so for linux.) On Windows, these are not automatically added to your PATH environment variable.
    • Linux needs no additional work.
    • Windows:
      • Follow directions here on how to edit your PATH variable: http://java.com/en/download/help/path.xml
      • Add the path to your OpenCV dll's, wherever you have placed them.

Windows:

  • In visual studio, right-click a project.  Select "Properties" from the context menu.
  • From the options on the right, pick the "debugging" menu.

Linux - command line:

Navigate to the root project folder

Run the executable of interest, optionally specifying the first argument as the input file.  There are several optional arguments, which must be specified in order:

  • the output filename for the image generated using your code
  • the reference filename for the image generated using the reference code

If approximate image matching is desired, then both of the following two arguments must be specified.  The code will not run if only the first is specified.

  • perPixelError: For approximate result matching, the per-pixel threshold determining whether your image matches the reference
  • globalError: For approximate result matching, the global threshold determining whether your image matches the reference

Currently, each week's test data lives with the code for that week.

Homework 1:

HW1/hw1
or
HW1/hw1 HW1/cinque_terre_small.jpg

Homework 2:

HW2/hw2
or
HW2/hw2 HW2/cinque_terre_small.jpg

Homework 3:

HW3/hw3
or
HW3/hw3 ../HW3/memorial.exr

NSight Eclipse edition - Linux or Mac

  • Build your specific project:
    • Either build all (Ctrl-B)
    • Build only current project: Right click -> Make targets -> Build (select [exe] hw*)
  • Add debug or run configurations:
    • Select the run menu -> Debug configurations
    • Add an entry for each project executable (it will only allow to you add existing binaries!)
      • Click icon of white rectangle with plus sign in right corner to add new config
      • Enter path to executable.  For example, HW1/hw1
      • click close
  • Run/debug:
    • In the main window's toolbar, click the bug icon to start debugging.  Click the arrow to the right of the button to select a different configuration (another hw project)

Known issues/Troubleshooting:

  • If CMake just isn't working and you can't figure out why, try to delete the cache.  This option is in the CMake GUI, under "File." When you next click "Configure" you'll be able to choose your compiler again, and hopefully CMake will run successfully.
  • For linux, clearing the cache can be done by simply deleting the folder you've created for building.

Original Posts:

https://forums.udacity.com/questions/100021751/how-to-opencv-cuda-vs10-using-cmake#cs344

https://forums.udacity.com/questions/100024026/how-to-using-cmake-to-create-build-targets-for-all-hw-assignments#cs344