1

そこで、SDLを使用して衝突するボールをMac OS Xのサーフェス/ウィンドウに描画する衝突検出コードを高速化しようとしています。衝突を実行して、既に問題なく連続して描画することができます。cuPrintfを使用してcudaバージョンをデバッグできるようにしたいのですが、main()が.cuファイルにないため、動作させることができません。そのため、cuPrintfを初期化することも、バッファーを印刷することもできません。いくつかの外部「C」関数を作成し、それらを.cppファイルにビルドすると、何も得られません。ラッパー関数を残りのcudaコードとともに.cuファイルに入れようとすると、「エラー:外部関数の使用はサポートされていません...」というメッセージが表示されます。1つの大きな.cuファイル内にすべてが含まれている小さなプロジェクトで使用しましたが、うまく機能します。でも、できるのに'

他の誰かがこの問題を抱えていますか?

4

1 に答える 1

1

基本的に、メイン関数に配置する必要がある cuPrintf によって提供される 3 つの呼び出しのラッパーを作成しました。私の kernel.cu ファイルでは、いくつかの extern "C" 関数を定義しました。次に、main.cpp で、それらをスコープに入れるように宣言しました。

kernel.cu で:

// Include section
#include "cuPrintf.cu"

//define all __device__ and __global__ functions for the kernel here
extern "C"
{
void LaunchKernel(<type> *input) { kernel<<< grid, dim >>>(input); }

void InitCuPrintf() { cudaPrintfInit(); }

void DisplayCuPrintf() { cudaPrintfDisplay(stdout, 1); }

void EndCuPrintf() { cudaPrintfEnd(); }
}

main.cpp で:

// you do NOT need to include any cuPrintf files here. Just in the kernel.cu file
#include <SDL.h>  // this is the library requiring me to do this stuff ...
#include "SDL_helper.h"  // all of the SDL functions I defined are separated out
#include <cuda_runtime.h>

// in global space
extern "C" {
void LaunchKernel(struct circle *circles);
void InitCuPrintf();
void DisplayCuPrintf();
void EndCuPrintf();
}

int main(nt argc, char **argv)
{
    // put these where you would normally place the cuPrintf functions they correspond to
    InitCuPrintf();

    // I left his in here because if you're needing to do this for cuPrintf, you prolly need
    // need a wrapper to lauch your kernel from outside the .cu file as well.
    LaunchKernel( input );

    DisplayCuPrintf();

    // SDL functions from SDL.h and SDL_helper.h would be in here somewhere

    EndCuPrintf()
}

それでおしまい!プロジェクト ディレクトリに cuPrintf.cu と cuPrintf.cuh のコピーを作成したので、コンパイル時にランダムなディレクトリにリンクする必要はありませんでした。私の nvcc / g++ コマンドは以下のとおりです。私はMACでコーディングしているので、Mac OS X固有のものです...

nvcc ./kernel.cu -I./ -I/usr/local/cuda/include/ -c -m64
g++ ./main.cpp -I./ -I/usr/include/ -I/usr/local/cuda/include/ -L/usr/local/cuda/lib/ -lcudart -LSDLmain -lSDL -framework Cocoa ./SDL_helper.o ./kernel.o

注: すべての SDL 関数を別の SDL_helper.c ファイルに分割し、nvcc を実行する前にコンパイルしました。

g++ ./SDL_helper.c -I./ -c

これが他の誰かに役立つことを願っています。

于 2012-04-30T17:58:49.670 に答える