Skip to content

Commit

Permalink
Check for driver version before running Optix Denoiser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
njroussel committed Oct 24, 2022
1 parent 28ec2cf commit 5529318
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 44 deletions.
10 changes: 1 addition & 9 deletions src/core/tests/test_bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
import drjit as dr
import mitsuba as mi

def find_resource(fname):
path = os.path.dirname(os.path.realpath(__file__))
while True:
full = os.path.join(path, fname)
if os.path.exists(full):
return full
if path == '' or path == '/':
raise Exception("find_resource(): could not find \"%s\"" % fname)
path = os.path.dirname(path)
from mitsuba.scalar_rgb.test.util import find_resource


def test_read_convert_yc(variant_scalar_rgb, tmpdir):
Expand Down
10 changes: 10 additions & 0 deletions src/python/python/test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
import pytest
import drjit as dr

def find_resource(fname):
path = os.path.dirname(os.path.realpath(__file__))
while True:
full = os.path.join(path, fname)
if os.path.exists(full):
return full
if path == '' or path == '/':
raise Exception("find_resource(): could not find \"%s\"" % fname)
path = os.path.dirname(path)

def fresolver_append_path(func):
"""
Function decorator that adds the mitsuba project root
Expand Down
11 changes: 1 addition & 10 deletions src/render/tests/test_megakernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@
import drjit as dr
import mitsuba as mi

def find_resource(fname):
import os
path = os.path.dirname(os.path.realpath(__file__))
while True:
full = os.path.join(path, fname)
if os.path.exists(full):
return full
if path == '' or path == '/':
raise Exception("find_resource(): could not find \"%s\"" % fname)
path = os.path.dirname(path)
from mitsuba.scalar_rgb.test.util import find_resource

def write_kernels(*args, output_dir='kernels', scene_fname=None):
import os
Expand Down
130 changes: 108 additions & 22 deletions src/render/tests/test_optixdenoiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import mitsuba as mi
import drjit as dr

from mitsuba.scalar_rgb.test.util import fresolver_append_path
from mitsuba.scalar_rgb.test.util import find_resource

###
### Reference images are generated using the `optixDenoiser` example provided
Expand All @@ -26,6 +26,69 @@ def fix_normals(normals):
return normals


def skip_if_wrong_driver_version(func):
import os
import re
import subprocess
import sys
import locale

from functools import wraps

REF_DRIVER_VERSION = '515.65.01'

def run(command):
p = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
raw_output, raw_err = p.communicate()
rc = p.returncode
if sys.platform.startswith('win32'):
enc = 'oem'
else:
enc = locale.getpreferredencoding()
output = raw_output.decode(enc)
err = raw_err.decode(enc)
return rc, output.strip(), err.strip()

def run_and_match(command, regex):
rc, out, _ = run(command)
if rc != 0:
return None
match = re.search(regex, out)
if match is None:
return None
return match.group(1)

def nvidia_smi_path():
smi = 'nvidia-smi'
if sys.platform.startswith('win32'):
system_root = os.environ.get('SYSTEMROOT', 'C:\\Windows')
program_files_root = os.environ.get('PROGRAMFILES', 'C:\\Program Files')
legacy_path = os.path.join(program_files_root, 'NVIDIA Corporation', 'NVSMI', smi)
new_path = os.path.join(system_root, 'System32', smi)
smis = [new_path, legacy_path]
for candidate_smi in smis:
if os.path.exists(candidate_smi):
smi = '"{}"'.format(candidate_smi)
break
return smi

driver_version = run_and_match(nvidia_smi_path(), r'Driver Version: (.*?) ')

@wraps(func)
def f(*args, **kwargs):
if REF_DRIVER_VERSION != driver_version:
pytest.skip(f"Cannot compare with `OptixDenoiser` references "
"images because they were generated with NVidia "
"driver version: {driver_version}.")

return func(*args, **kwargs)

return f


def test01_denoiser_construct(variants_any_cuda):
input_res = [33, 18]

Expand All @@ -40,10 +103,10 @@ def test01_denoiser_construct(variants_any_cuda):
"also providing albedo information!")


@fresolver_append_path
@skip_if_wrong_driver_version
def test02_denoiser_denoise(variant_cuda_ad_rgb):
noisy = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/noisy.exr"))
ref = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/ref.exr"))[...,:3]
noisy = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/noisy.exr")))
ref = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/ref.exr")))[...,:3]

denoiser = mi.OptixDenoiser(noisy.shape[:2])
denoised = mi.util.convert_to_bitmap(
Expand All @@ -57,11 +120,11 @@ def test02_denoiser_denoise(variant_cuda_ad_rgb):
assert dr.allclose(denoised_array, ref_array)


@fresolver_append_path
@skip_if_wrong_driver_version
def test03_denoiser_denoise_albedo(variant_cuda_ad_rgb):
noisy = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/noisy.exr"))
albedo = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/albedo.exr"))
ref = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/ref_albedo.exr"))
noisy = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/noisy.exr")))
albedo = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/albedo.exr")))
ref = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/ref_albedo.exr")))

denoiser = mi.OptixDenoiser(noisy.shape[:2], True)
denoised = mi.util.convert_to_bitmap(
Expand All @@ -78,12 +141,12 @@ def test03_denoiser_denoise_albedo(variant_cuda_ad_rgb):
assert dr.allclose(denoised_array, ref_array)


@fresolver_append_path
@skip_if_wrong_driver_version
def test04_denoiser_denoise_normals(variant_cuda_ad_rgb):
noisy = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/noisy.exr"))
albedo = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/albedo.exr"))
normals = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/normals.exr"))
ref = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/ref_normals.exr"))
noisy = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/noisy.exr")))
albedo = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/albedo.exr")))
normals = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/normals.exr")))
ref = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/ref_normals.exr")))

normals = fix_normals(normals)

Expand All @@ -101,14 +164,15 @@ def test04_denoiser_denoise_normals(variant_cuda_ad_rgb):

assert dr.allclose(denoised_array, ref_array)

@fresolver_append_path

@skip_if_wrong_driver_version
def test05_denoiser_denoise_temporal(variant_cuda_ad_rgb):
noisy = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/noisy.exr"))
albedo = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/albedo.exr"))
normals = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/normals.exr"))
flow = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/flow.exr"))
noisy = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/noisy.exr")))
albedo = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/albedo.exr")))
normals = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/normals.exr")))
flow = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/flow.exr")))
previous_denoised = noisy
ref = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/ref_temporal.exr"))
ref = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/ref_temporal.exr")))

normals = fix_normals(mi.TensorXf(normals))

Expand All @@ -127,11 +191,12 @@ def test05_denoiser_denoise_temporal(variant_cuda_ad_rgb):

assert dr.allclose(denoised_array, ref_array)

@fresolver_append_path

@skip_if_wrong_driver_version
def test05_denoiser_denoise_multichannel_bitmap(variant_cuda_ad_rgb):
ref = mi.TensorXf(mi.Bitmap("resources/data/tests/denoiser/ref_normals.exr"))
ref = mi.TensorXf(mi.Bitmap(find_resource("resources/data/tests/denoiser/ref_normals.exr")))

scene = mi.load_file("resources/data/scenes/cbox/cbox-rgb.xml", res=64)
scene = mi.load_file(find_resource("resources/data/scenes/cbox/cbox-rgb.xml"), res=64)
sensor = scene.sensors()[0]
integrator = mi.load_dict({
'type': 'aov',
Expand All @@ -155,3 +220,24 @@ def test05_denoiser_denoise_multichannel_bitmap(variant_cuda_ad_rgb):
denoised_array = denoised_tensor.array

assert dr.allclose(denoised_array, ref_array)

def test05_denoiser_denoise_multichannel_bitmap_runs(variant_cuda_ad_rgb):
scene = mi.load_file(find_resource("resources/data/scenes/cbox/cbox-rgb.xml"), res=64)
sensor = scene.sensors()[0]
integrator = mi.load_dict({
'type': 'aov',
'aovs': 'albedo:albedo,sh_normal:sh_normal',
'img': {
'type': 'path',
'max_depth' : 6,
}
})
mi.render(scene, spp=2, integrator=integrator, sensor=sensor)
multichannel = sensor.film().bitmap()

denoiser = mi.OptixDenoiser(multichannel.size(), True, True)
denoised = denoiser(multichannel, False, "albedo", "sh_normal", sensor.world_transform().inverse())
denoised = mi.TensorXf(denoised.convert(component_format=mi.Struct.Type.Float16))
dr.eval(denoised)

assert True
2 changes: 1 addition & 1 deletion tutorials

0 comments on commit 5529318

Please sign in to comment.