Sorry for the late reply! The post was on my ToDo list for some time and I just got a bit of time for debugging.
I’m wondering, why the code compiles fine without throwing any errors, as these points might cause some trouble:


convert_to_mask is called with a template argument, while its definition isn’t templated

zbufferpacked_accessoris passed with as a 2-dim accessor, which fits the dimensions of the tensor. Howeverconvert_to_masktakes afloat *` as the input argument. I would assume this will throw an error.

zbuffer is indexed in a single dimension, although a 2-dim accessor is passed and the tensor wasn’t flattened to a 1-dim tensor

Given that and removing some unused code, this should work:
from torch.utils import cpp_extension

cuda_source = """
template <typename scalar_t>
__global__ void convert_to_mask(
  torch::PackedTensorAccessor32<scalar_t, 2, torch::RestrictPtrTraits> zbuffer,
  int img_size) {
    int row = blockIdx.y;
    int index = blockIdx.x * blockDim.x + threadIdx.x;
    int stride = blockDim.x * gridDim.x;
    
    for(int i = index; i < img_size; i += stride) {
        if(zbuffer[row][i] == -INFINITY) {
            zbuffer[row][i] = 0;
        } else {
            zbuffer[row][i] = 1;
        }
    }
}

std::vector<torch::Tensor> zbuffertri_cuda_forward(torch::Tensor s2d, int img_size = 224)
{
    auto out = torch::ones({img_size, img_size}, torch::device(s2d.device())) * 10.;
    auto zbuffer = torch::ones({img_size, img_size}, torch::device(s2d.device())) * (-INFINITY);

    const int threads = 256;
    const dim3 blocks((img_size + threads - 1) / threads, img_size);

    std::cout << "zbuffer size " << zbuffer.sizes();

    AT_DISPATCH_FLOATING_TYPES(zbuffer.type(), "zbuffer_tri_dispatch", ([&] {
        convert_to_mask<scalar_t><<<blocks, threads>>>(
          zbuffer.packed_accessor32<scalar_t, 2, torch::RestrictPtrTraits>(),
          img_size);
    }));

    return {out, zbuffer};
}
"""

cpp_source = """
    std::vector<torch::Tensor> zbuffertri_cuda_forward(torch::Tensor s2d, int img_size);
"""

module = torch.utils.cpp_extension.load_inline(
    name="cuda_test_extension",
    cpp_sources=cpp_source,
    cuda_sources=cuda_source,
    functions="zbuffertri_cuda_forward",
    verbose=True,
)

s2d = torch.randn(1).cuda()
img_size = 100
out, zb = module.zbuffertri_cuda_forward(s2d, img_size)

print(out)
print(zb)

Let me know, if that fits your use case.