()
| 107 | relative_loss("cosT:", cosT_ref.grad, cosT_cuda.grad) |
| 108 | |
| 109 | def test_lambda_ggx(): |
| 110 | alphaSqr_cuda = torch.rand(1, RES, RES, 1, dtype=DTYPE, device='cuda', requires_grad=True) |
| 111 | alphaSqr_ref = alphaSqr_cuda.clone().detach().requires_grad_(True) |
| 112 | cosT_cuda = torch.rand(1, RES, RES, 1, dtype=DTYPE, device='cuda', requires_grad=True) * 3.0 - 1 |
| 113 | cosT_cuda = cosT_cuda.clone().detach().requires_grad_(True) |
| 114 | cosT_ref = cosT_cuda.clone().detach().requires_grad_(True) |
| 115 | target = torch.rand(1, RES, RES, 1, dtype=DTYPE, device='cuda') |
| 116 | |
| 117 | ref = ru._lambda_ggx(alphaSqr_ref, cosT_ref, use_python=True) |
| 118 | ref_loss = torch.nn.MSELoss()(ref, target) |
| 119 | ref_loss.backward() |
| 120 | |
| 121 | cuda = ru._lambda_ggx(alphaSqr_cuda, cosT_cuda) |
| 122 | cuda_loss = torch.nn.MSELoss()(cuda, target) |
| 123 | cuda_loss.backward() |
| 124 | |
| 125 | print("-------------------------------------------------------------") |
| 126 | print(" Lambda GGX") |
| 127 | print("-------------------------------------------------------------") |
| 128 | relative_loss("res:", ref, cuda) |
| 129 | relative_loss("alpha:", alphaSqr_ref.grad, alphaSqr_cuda.grad) |
| 130 | relative_loss("cosT:", cosT_ref.grad, cosT_cuda.grad) |
| 131 | |
| 132 | def test_masking_smith(): |
| 133 | alphaSqr_cuda = torch.rand(1, RES, RES, 1, dtype=DTYPE, device='cuda', requires_grad=True) |
no test coverage detected