There is a simple and direct way to fix this issue. Checking both the target_name and nvcc.have_tensorcore as below instead of only checking nvcc.have_tensorcore,
if target.target_name == "cuda" and nvcc.have_tensorcore(tvm.gpu(0).compute_version):
# tensorcore codes...
The codes regarding both conv2d and dense should be modified.
In this case, the nvcc.have_tensorcore check will be skipped when CUDA is not available.