4 月
11
2012

CUDA multiple/dynamic texture reference

最近論文慢到不用CUDA無法跑完的境界,在使用Texture Reference上遇到了許多問題,故寫下此整理後查

我遇到的問題是必須要做驚人次數的bi-linear interpolation warping,故希望能用GPU的texture mapping功能,但同時必須要在多張影像中間切換

先轉述一篇文章片段

Those of you who have used CUDA textures should be familiar with the insane programming interface that they present. Texture references can be declared only as global variables, and only in the file where you are using them. You can’t pass them around as by-value/by-reference arguments in functions, you can’t create them inside function/class scope, and you cannot make arrays of them.

我們都看到這些限制拉,既然不能做texture reference array,這也代表我們不能在kernel function中index它,故每張影像一個texture reference是不可行的,當然這並不包括你硬刻影像數量的texture reference array在code中,同時你還必須受到一個kernel function僅能access 128個texture rerference的限制,並且在未知影像數量下也做不到硬刻code。

解決辦法一:在要使用texture時bind texture reference,但這似乎牽涉到複製到texture memory的問題,當你頻繁的切換時會有巨大的overhead。

解決辦法二:爛招合併所有影像到同一個texture,自然就可以僅用一texture reference,但你會受到texture size limit,這僅對小影像的合併有用,並且CUDA似乎不希望你開一個巨大的texture block,會在runtime時死掉,這個大小是與你的GPU記憶體無關的。還有另一個問題是你在fetch影像邊界的texture時可能會染到上下一張影像的pixel顏色,因為它當作是同一張圖了!

解決辦法三:使用3D texture reference,使用第三個維度來作為2D texture的影像index,但明顯的你的影像大小最好要全部一樣,並且也會發生解法二的顏色問題

解決辦法四:放棄使用你的高階CUDA語法,有low-level的解法,使用”DEPRECATED”的CUDA Driver API,咦?

解決辦法五:放棄使用CUDA! DirectX10有提供texture array! XDD

最終解法:使用cudaArrayLayered! interpolation 僅在該layer,不會跨layer interpolation

Written by in: 電腦三兩事 | 標籤:

尚無留言 »

RSS feed for comments on this post. TrackBack URL


Leave a Reply

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com