MacでEclipse CDTでCUDA開発をする
※cuda単体の開発環境は構築済とする。
Eclipse CDTをインストール。
その後の設定は基本的にはこちらに書いてある通り。
今回は/Developer/GPU Computing/C/src/cudatest_devをロケーションとしてプロジェクトを作成してみる。
●cuファイルの関連づけ
Syntax Highlighting for .cu Files:
Window -> Preferences -> in C/C++ -> File Types -> New -> enter "*.cu" and select "C++ Source File"
●新規プロジェクトディレクトリ(cudatest_dev)にtemplate内のファイルを全てコピーする
Working with NVidia's Makefiles:
Here we'll make a copy of NVidia's template project and set it up in Eclipse.
cd /Developer/GPU Computing/C/src
cp -r template/* cudatest_dev/*
●template〜のファイル名を変更する
mv cudatest_dev/template_kernel.cu cudatest_dev/cudatest_dev_kernel.cu
mv cudatest_dev/template_gold.cpp cudatest_dev/cudatest_dev_gold.cpp
mv cudatest_dev/template.cu cudatest_dev/cudatest_dev.cu
●上記で作成したディレクトリをロケーションとしてEclipseにプロジェクトを作成する
In Eclipse:
New -> C++ Project ->
* Project Name: "cudatest_dev"
* uncheck "Use default location"
* Location: "/Developer/GPU Computing/C/src"
* Project types: Executable -> Empty Project
●Makefileの自動生成オフにして、インクリメンタルビルド対象も空にする
- > Next -> uncheck "Debug", select "Release" -> Advanced Settings ->
in "C/C++ build" ->
* in "Builder Settings" tab -> uncheck "Generate Makefiles"
* Build Directory: "${workspace_loc:/foobar}"
* in "Behaviour" tab -> Build (incremental build):"" (delete "all")
●PATHの設定(CDTのバグなのか追加設定しただけだと、セパレータがセミコロンになっているようなので、わざわざコロンに書き換える
in C/C++ build -> Environment ->
* Add -> Name: "PATH" Value: "/usr/local/cuda/bin" -> OK
* Select PATH -> Edit -> Value: change ";/usr/local/cuda/bin" to ":/usr/local/cuda/bin"
- > Ok -> Finish
●ビルドできるか確認
Ctrl+b to build should work now.
●Makefile内のファイル名がtemplateのままになっているところを修正する
In Makefile, replace "EXECUTABLE := template" with "EXECUTABLE := foobar" so it puts the executable in the right place.
●実行時の設定で実行アプリを出力されるアプリのパスに合わせる
To set up Eclipse to run it:
Run -> Run Configurations -> select "C/C++ Local Application" -> "New launch configuration (click the leftmost icon on the top) ->
* Name: "cudatest_dev Release"
* Project: cudatest_dev
* C/C++ Application: "/Developer/GPU Computing/C/bin/darwin/release/cudatest_dev"
- > Apply -> Close
●実行できるか確認
Try Ctrl+F11 to run.
Macの場合はCUDAのSDKが
/Developer/GPU Computing
にインストールされるのでEclipseのプロジェクトは
/Developer/GPU Computing/C/src/cudatest_dev
のように合わせる必要がありました。
※合わせたくない人はMakefileのcommon.mkへのパスを書き換えればいけるかもしれない
それとリンク先の記事にもある通り、プロジェクト作成後にMakefileのtemplate〜〜とついている、ファイル名を書き換える必要がありますが、これに加えてmy_project.cu内の
#include
も
#include
に書き換える必要があります。
※これはビルドエラーが出るのですぐ気づくと思いますが、、、、