Skip to content

Commit

Permalink
add comment for nvdiffrast usage in dibr example, add option for skip…
Browse files Browse the repository at this point in the history
…ping tests with nvdiffrast (NVIDIAGameWorks#569)

Signed-off-by: Clement Fuji Tsang <[email protected]>
  • Loading branch information
Caenorst authored May 25, 2022
1 parent 006fbf6 commit b52da8f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "third_party/cub"]
path = third_party/cub
url = https://github.com/NVIDIA/cub
[submodule "third_party/nvdiffrast"]
path = third_party/nvdiffrast
url = https://github.com/NVlabs/nvdiffrast
5 changes: 4 additions & 1 deletion ci/gitlab_jenkins_templates/ubuntu_test_CI.jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ spec:
}
}, "Pytest": {
stage("Pytest") {
sh 'pytest -s --cov=/kaolin/kaolin /kaolin/tests/python/kaolin'
sh '''
export KAOLIN_TEST_NVIDIFFRAST=1
pytest -s --cov=/kaolin/kaolin /kaolin/tests/python/kaolin
'''
}
}, "Doc examples": {
if (arch == "TITAN_RTX") {
Expand Down
5 changes: 4 additions & 1 deletion examples/tutorial/dibr_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,12 @@
" torch.ones((batch_size, nb_faces, 3, 1), device='cuda')\n",
" ]\n",
"\n",
" # If you have nvdiffrast installed you can change rast_backend to\n",
" # nvdiffrast or nvdiffrast_fwd\n",
" image_features, soft_mask, face_idx = kal.render.mesh.dibr_rasterization(\n",
" gt_image.shape[1], gt_image.shape[2], face_vertices_camera[:, :, :, -1],\n",
" face_vertices_image, face_attributes, face_normals[:, :, -1])\n",
" face_vertices_image, face_attributes, face_normals[:, :, -1],\n",
" rast_backend='cuda')\n",
"\n",
" # image_features is a tuple in composed of the interpolated attributes of face_attributes\n",
" texture_coords, mask = image_features\n",
Expand Down
7 changes: 5 additions & 2 deletions tests/python/kaolin/render/mesh/test_dibr.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,11 @@ def face_uvs(self, mesh, batch_size, dtype, flip):
def test_dibr_rasterization(self, height, width, face_vertices_z,
face_vertices_image, face_uvs, face_normals_z,
sigmainv, boxlen, knum, multiplier, rast_backend):
if rast_backend in {'nvdiffrast_fwd', 'nvdiffrast'} and face_vertices_z.dtype == torch.double:
pytest.skip("nvdiffrast not compatible with double")
if rast_backend in {'nvdiffrast_fwd', 'nvdiffrast'}:
if os.getenv('KAOLIN_TEST_NVDIFFRAST', '0') == '0':
pytest.skip(f'test is ignored as KAOLIN_TEST_NVDIFFRAST is not set')
if face_vertices_z.dtype == torch.double:
pytest.skip("nvdiffrast not compatible with double")
gt_interpolated_features, gt_face_idx = rasterize(
height, width,
face_vertices_z,
Expand Down
15 changes: 14 additions & 1 deletion tests/python/kaolin/render/mesh/test_rasterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def test_nvdiffrast_fwd_forward(
self, batch_size, height, width, pixel_coords,
render_ranges, face_vertices_z, face_vertices_image,
face_uvs, with_valid_faces, valid_faces):
if os.getenv('KAOLIN_TEST_NVDIFFRAST', '0') == '0':
pytest.skip(f'test is ignored as KAOLIN_TEST_NVDIFFRAST is not set')
if face_vertices_image.dtype == torch.double:
pytest.skip("nvdiffrast not compatible with double")
kwargs = {}
Expand Down Expand Up @@ -328,6 +330,8 @@ def test_nvdiffrast_fwd_forward_with_list(
render_ranges, face_vertices_z, face_vertices_image,
face_uvs, with_valid_faces, valid_faces, dtype):
"""Test with list of tensors as features"""
if os.getenv('KAOLIN_TEST_NVDIFFRAST', '0') == '0':
pytest.skip(f'test is ignored as KAOLIN_TEST_NVDIFFRAST is not set')
if face_vertices_image.dtype == torch.double:
pytest.skip("nvdiffrast not compatible with double")
kwargs = {}
Expand Down Expand Up @@ -370,6 +374,8 @@ def test_nvdiffrast_fwd_backward(
self, batch_size, height, width, pixel_coords,
render_ranges, face_vertices_z, face_vertices_image,
face_uvs, with_valid_faces, valid_faces):
if os.getenv('KAOLIN_TEST_NVDIFFRAST', '0') == '0':
pytest.skip(f'test is ignored as KAOLIN_TEST_NVDIFFRAST is not set')
if face_vertices_image.dtype == torch.double:
pytest.skip("nvdiffrast not compatible with double")
kwargs = {}
Expand Down Expand Up @@ -422,6 +428,8 @@ def test_nvdiffrast_fwd_backward_with_mask(
self, batch_size, height, width, pixel_coords,
render_ranges, face_vertices_z, face_vertices_image,
face_uvs, with_valid_faces, valid_faces):
if os.getenv('KAOLIN_TEST_NVDIFFRAST', '0') == '0':
pytest.skip(f'test is ignored as KAOLIN_TEST_NVDIFFRAST is not set')
if face_vertices_image.dtype == torch.double:
pytest.skip("nvdiffrast not compatible with double")
kwargs = {}
Expand Down Expand Up @@ -482,6 +490,8 @@ def test_nvdiffrast_fwd_backward_with_mask(
def test_nvdiffrast_forward(
self, batch_size, height, width, face_vertices_z,
face_vertices_image, face_uvs, with_valid_faces, valid_faces):
if os.getenv('KAOLIN_TEST_NVDIFFRAST', '0') == '0':
pytest.skip(f'test is ignored as KAOLIN_TEST_NVDIFFRAST is not set')
if face_vertices_image.dtype == torch.double:
pytest.skip("nvdiffrast not compatible with double")
kwargs = {}
Expand Down Expand Up @@ -509,6 +519,8 @@ def test_nvdiffrast_forward_with_list(
self, batch_size, height, width, face_vertices_z,
face_vertices_image, face_uvs, with_valid_faces, valid_faces):
"""Test with list of tensors as features"""
if os.getenv('KAOLIN_TEST_NVDIFFRAST', '0') == '0':
pytest.skip(f'test is ignored as KAOLIN_TEST_NVDIFFRAST is not set')
if face_vertices_image.dtype == torch.double:
pytest.skip("nvdiffrast not compatible with double")
kwargs = {}
Expand Down Expand Up @@ -537,6 +549,8 @@ def test_nvdiffrast_forward_with_list(
def test_nvdiffrast_backward(
self, batch_size, height, width, face_vertices_z,
face_vertices_image, face_uvs, with_valid_faces, valid_faces):
if os.getenv('KAOLIN_TEST_NVDIFFRAST', '0') == '0':
pytest.skip(f'test is ignored as KAOLIN_TEST_NVDIFFRAST is not set')
if face_vertices_image.dtype == torch.double:
pytest.skip("nvdiffrast not compatible with double")
kwargs = {}
Expand Down Expand Up @@ -577,4 +591,3 @@ def test_nvdiffrast_backward(
assert torch.allclose(face_uvs.grad,
face_uvs2.grad,
rtol=1e-2, atol=1e-2)

1 change: 0 additions & 1 deletion third_party/nvdiffrast
Submodule nvdiffrast deleted from 78528e

0 comments on commit b52da8f

Please sign in to comment.