Slide 63
Slide 63 text
Copyright © Fixstars Group
モデル更新のCUDA実装例
⚫ カーネル関数及び、カーネル関数呼び出し
62
__global__ void propagateAndRefineACMHKernel(float* Z, Vec3f* N, float* C,
int w, int h, int nviews, int color, float minZ, float maxZ, bool geom)
{
// checkerboardパターン(市松模様)となるようx,yを計算
const int x = 2 * (blockIdx.x * blockDim.x + threadIdx.x) + ((y % 2) ^ color);
const int y = blockIdx.y * blockDim.y + threadIdx.y;
if (x >= w || y >= h)
return;
MatchingCost MC(nviews, geom); // マッチングコスト計算クラス
float viewWeights[MAX_VIEWS]; // コスト集約時の視点重み
// モデル伝搬
propagateACMH(MC, Z, N, C, w, h, x, y, minZ, maxZ, viewWeights);
// ランダム改善
Xorshift random(getRandomSeed(x, y, w)); // 乱数生成器
refineACMH(MC, Z, N, C, w, h, x, y, minZ, maxZ, viewWeights, random);
}
void propagateAndRefineACMH(GpuMat& depths, GpuMat& normals, GpuMat& costs,
int nviews, int color, float minZ, float maxZ, bool geom)
{
const int w = depths.cols;
const int h = depths.rows;
const int npixelsX = w / 2; // x方向はw/2個の画素を更新
const int npixelsY = h;
constexpr int BLOCK_SIZE = 16;
const dim3 block(BLOCK_SIZE, BLOCK_SIZE);
const dim3 grid(divUp(npixelsX, block.x), divUp(npixelsY, block.y));
auto Z = depths.ptr();
auto N = normals.ptr();
auto C = costs.ptr();
propagateAndRefineACMHKernel<<>>(Z, N, C, w, h,
nviews, color, minZ, maxZ, geom);
CUDA_CHECK(cudaGetLastError());
}
カーネル関数呼び出し
モデル伝搬(ACMH)のカーネル関数