image_filter_test.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:Gpu-Stencil-Operations 作者: ebadali 项目源码 文件源码
def thresholding(arry, hist):

    # We have 10*10 threads per block
    A = cuda.shared.array(shape=(32,32), dtype=int32)

    x,y = cuda.grid(2)

    ty = cuda.threadIdx.x
    tx = cuda.threadIdx.y

    A[ty,tx] = arry[x,y]


    cuda.syncthreads()

    threadCountX = A.shape[0] - 1
    threadCountY = A.shape[1] - 1
    # If within x range and y range then calculate the LBP discriptor along
    # with histogram value to specific bin

    # Other wise Ignore the Value
    if (ty > 0 and  (threadCountX-ty) > 0 ) and (tx > 0 and (threadCountY-tx) > 0):
        # You can do the Processing here. ^_^
        code = 0
        #  We need to make sure that each value is accessable to each thread
        #  TODO: make them atomic
        center = A[ty, tx]
        code = 0 if center > 150  else 255

        code = ( code - center)

        A[ty,tx] = code

        # Wait All Threads to Sync here.
        cuda.syncthreads()

        val  = A[ty,tx]
        cuda.atomic.add(arry, (x,y),val)
        cuda.syncthreads()

        # This Atomic Operation is equivalent to  hist[code % 256] += 1
        ind = code % BIN_COUNT
        cuda.atomic.add(hist, ind, 1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号