12.07.2015 Views

CUDA TIPS and FAQ

CUDA TIPS and FAQ

CUDA TIPS and FAQ

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>CUDA</strong> <strong>TIPS</strong> <strong>and</strong> <strong>FAQ</strong>GTC 2013 チュートリアルエヌビディアジャパン<strong>CUDA</strong>エンジニア 森 野 慎 也


<strong>CUDA</strong> <strong>TIPS</strong> <strong>and</strong> <strong>FAQ</strong>• NVIDIA Japanでは、 開 発 者 のみなさんへの 支 援 を行 っています。その 中 で…よくいただく 質 問「へー」と 言 ってもらえたことなど、まとめて、お 話 しします。


Topic 1: Compute Capability• GPUのCompute Capabilityを 知 りたいのですが。— お 答 え:<strong>CUDA</strong> GPUs ページにアクセスしてください!— https://developer.nvidia.com/cuda-gpus


Topic 1: Compute Capability• GPUの 確 認 方 法


Topic 2: 開 発 ・デバッグ 環 境• 開 発 環 境 は、 何 を 使 えばよいのですか?• Windows— Windows XP 以 降 で 動 作— Visual Studio 2008, 2010, 2012• MacOS X— 10.7.5+、10.8.x(64 bit)— Compiler : gcc or clang**いくつかの 機 能 はサポートされていません


Topic 2: 開 発 ・デバッグ 環 境• サポートされている LinuxDistribution Version 32 bit 64 bitFedora 18 XRedHat Enterprise 5.5+, 6.xXOpenSUSE 12.2 XSUSE SLES 11 SP1, SP2 XUbuntu 12.10, 12.04, 10.04 X XUbuntu (ARMv7) 12.04 X X


Topic 2: 開 発 ・デバッグ 環 境• Nsight Visual Studio Edition— <strong>CUDA</strong> Toolkitに 含 まれます。(<strong>CUDA</strong> 5.5より)— Windows Vista 以 降• GPUカーネルのデバッグができます!— Datatip 、Breakpoint( 条 件 指 定 可 能 )、assert()、デバイスメモリのダンプ— Visual Studio IDEに、 統 合


Topic 2: 開 発 ・デバッグ 環 境• VS2010


Topic 3: ホストコンパイラのオプション• 質 問*.cuに 書 いた、CPUコードが 遅 いのです。nvccの 生 成 するコードが、 遅 いのでは?— お 答 えnvccでは、ホストコードは、 各 プラットフォームのコンパイラでコンパイルされます。— ホストコード 用 のコンパイルオプションを、 指 定 してください。


Topic 3: ホストコンパイラのオプション• nvcc— <strong>CUDA</strong> 用 のコンパイラ• 内 部 でホストコンパイラを 使 用— デフォルトでC++• ホストコンパイラのオプションも 指 定 します。ソースホスト/GPU ソース 分 割ホストコンパイラマージオブジェクトカーネルコンパイラ


Topic 3: ホストコンパイラのオプション• NVCCオプション— -Xcompiler• ホストコンパイラ 向 けのオプション— -ccbin• ホストコンパイラのパス 指 定— -gencode— -G• Compute Capability (GPUバージョン)の 指 定 _35,sm_35• デバッグ 情 報 生 成— -Xptxas• 最 適 化 に 必 要 な 情 報 を 得 るために 指 定• PTX(GPUアセンブラ)のオプション11


Topic 3: ホストコンパイラのオプション.SUFFIXES: .cpp .h .cu .oDEBUG=0CXXFLAGS=-Wall -gNVCCFLAGS=-gencode arch=compute_30,code=sm_30 -Xptxas -v( 略 )all: ….cu.o: $


Topic 3: ホストコンパイラのオプション• Windowsの 場 合


Topic 4: 並 列 化• 質 問<strong>CUDA</strong>では、 非 常 に 多 くのスレッドを 使 いますが、スレッド 数 を 増 やすよりは、ループで 書 けませんか?— お 答 え通 常 、 性 能 が 出 ないので、お 勧 めしません。<strong>CUDA</strong>では、 多 くのスレッドを 動 作 させることで、 性 能 が 出 ます。— メモリコピーのコードで、 説 明 します。


Topic 4: 並 列 化 (Coalesced Access)• <strong>CUDA</strong>に 適 した 並 列 化 (Coalesced Access)<strong>CUDA</strong> coreint *dSrc 0 1 2 3 4 5 6 7 8……int *dDst…


Topic 4: 並 列 化 (Coalesced Access)__global__void coalescedMemcpyKernel(int *dDst, const int *dSrc, size_t size) {/* Global IDを 算 出 */int globalID = blockDim.x * blockIdx.x + threadIdx.x;}if (globalID < size) {/* 自 スレッド 担 当 の 要 素 のみ、 処 理 */dDst[globalID] = dSrc[globalID];}


Topic 4: ループによる 実 装• スレッドでループ— 1スレッドで、4 回 ループする 場 合ThreadsThread 0Thread 1…Thread 2int *dSrc 0 1 2 3 4 5 6 7 8…int *dDst…


Topic 4: 並 列 化 (loop)__global__void loopMemcpyKernel(int *dDst, const int *dSrc,size_t size, size_t loopCount) {/* Global IDを 算 出 */int globalID = blockDim.x * blockIdx.x + threadIdx.x;unsigned int begin = gid * loopCount;unsigned int end = min((gid + 1) * loopCount, size);}for (unsigned int index = begin; index < end; ++index) {dDst[index] = dSrc[index];}


バンド 幅 (GB/sec)Topic 4: ベンチマーク 結 果200150Spec : 208 GB/secCoalesced Access : 146 GB/sec• Tesla K20cECC off100ループによるコピー5001 8 64 512 4096スレッドあたりのループ 回 数


Topic 4: 並 列 化• ループは、なぜ 遅 い?— メモリアクセスが、 歯 抜 けになっている!Threads Thread 0 Thread 1…Thread 20 1 2 3 4 5 6 7 8 …Cache…DRAM…


Topic 4: 並 列 化• スレッド(Warp) 数 が 足 りないと、 性 能 が 出 ません。スレッド(Warp)が多 数 、 実 行 されている。スレッド(Warp)の実 行 数 がすくない。Warp XWarp AWarp BWarp CWarp ……Warp …Warp XWarp AWarp Bca. 11 clock (Kepler)ca. 22 clock (Fermi)StallWarp AStallStallStall…StallStallWarp AStall


Topic 4: 並 列 化• メモリアクセスにも、スレッド(Warp)の 数 が 必 要 です。スレッド(Warp)が多 数 、 実 行 されている。スレッド(Warp)の実 行 数 がすくない。Warp XWarp AWarp BWarp CWarp ……メモリアクセス要 求 が 多 いStallWarp AStallStallStall…メモリアクセス要 求 が 少 ないWarp …Warp XWarp AWarp Bバンド 幅 大StallStallWarp AStallバンド 幅 小


バンド 幅 (GB/sec)Topic 4: ベンチマーク(Thread 数 )200150Spec : 208 GB/secCoalesced Access : 146 GB/sec• Tesla K20c(ECC off)1005000 20 40 60SMXあたりのWarp 数


Topic 5: 開 発 者 登 録• NVIDIA Registered Developer program— https://developer.nvidia.com/registered-developer-programs• 誰 でも 登 録 できます。— 企 業 の 方 、 学 生 の 方 、 皆 さんOKです。— 無 償 です。• メリット— プレリリース 版 のダウンロード— バグレポート


NVIDIA Japan <strong>CUDA</strong> Monthly Seminar• NVIDIA Japanでは、 毎 月 、<strong>CUDA</strong> 関 連 の 無 償 セミナーを 実 施 しています。— 申 し 込 み :http://www.nvidia.co.jp/object/event-calendar-jp.html— 場 所 : NVIDIA Japan 赤 坂 オフィス— 定 員 : 20 名


Thank you

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!