DeepGPR 0.0.18__tar.gz → 0.0.19__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {deepgpr-0.0.18 → deepgpr-0.0.19}/PKG-INFO +1 -1
- {deepgpr-0.0.18 → deepgpr-0.0.19}/pyproject.toml +1 -1
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/compute2.py +17 -8
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr.dll +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr_cpu.dll +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR.egg-info/PKG-INFO +1 -1
- {deepgpr-0.0.18 → deepgpr-0.0.19}/tests/test_discrete_adjoint.py +45 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/README.md +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/license +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/setup.cfg +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/__init__.py +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/common.py +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr.cu +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr.h +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr.so +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr_cpu.c +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr_cpu.dylib +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr_cpu.so +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/libomp.dylib +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/multiscale.py +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/wavelet.py +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR.egg-info/SOURCES.txt +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR.egg-info/dependency_links.txt +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR.egg-info/requires.txt +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR.egg-info/top_level.txt +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/tests/test_numerics.py +0 -0
- {deepgpr-0.0.18 → deepgpr-0.0.19}/tests/test_wavelet.py +0 -0
|
@@ -445,23 +445,32 @@ def _save_forward_wavefield(wavefield, directory, run_time):
|
|
|
445
445
|
|
|
446
446
|
|
|
447
447
|
def _begin_native_call(device):
|
|
448
|
-
"""
|
|
448
|
+
"""Select the tensor device and order the native CUDA default stream."""
|
|
449
449
|
if device.type != "cuda":
|
|
450
450
|
return None
|
|
451
451
|
|
|
452
|
+
previous_device = torch.cuda.current_device()
|
|
453
|
+
target_device = previous_device if device.index is None else device.index
|
|
454
|
+
restore_device = None
|
|
455
|
+
if target_device != previous_device:
|
|
456
|
+
torch.cuda.set_device(target_device)
|
|
457
|
+
restore_device = previous_device
|
|
458
|
+
|
|
452
459
|
current_stream = torch.cuda.current_stream(device)
|
|
453
460
|
default_stream = torch.cuda.default_stream(device)
|
|
454
461
|
if current_stream.cuda_stream != default_stream.cuda_stream:
|
|
455
462
|
default_stream.wait_stream(current_stream)
|
|
456
|
-
|
|
457
|
-
return None
|
|
463
|
+
return current_stream, default_stream, restore_device
|
|
458
464
|
|
|
459
465
|
|
|
460
|
-
def _end_native_call(
|
|
461
|
-
"""
|
|
462
|
-
if
|
|
463
|
-
current_stream, default_stream =
|
|
464
|
-
current_stream.
|
|
466
|
+
def _end_native_call(native_state):
|
|
467
|
+
"""Order native results before PyTorch and restore the caller's device."""
|
|
468
|
+
if native_state is not None:
|
|
469
|
+
current_stream, default_stream, restore_device = native_state
|
|
470
|
+
if current_stream.cuda_stream != default_stream.cuda_stream:
|
|
471
|
+
current_stream.wait_stream(default_stream)
|
|
472
|
+
if restore_device is not None:
|
|
473
|
+
torch.cuda.set_device(restore_device)
|
|
465
474
|
|
|
466
475
|
|
|
467
476
|
def _check_nonzero_source_created_fields(c_lib, source_amplitudes, *fields):
|
|
Binary file
|
|
Binary file
|
|
@@ -279,6 +279,51 @@ class DiscreteAdjointTests(unittest.TestCase):
|
|
|
279
279
|
2.0e-4,
|
|
280
280
|
)
|
|
281
281
|
|
|
282
|
+
@unittest.skipUnless(
|
|
283
|
+
torch.cuda.is_available() and torch.cuda.device_count() >= 2,
|
|
284
|
+
"At least two CUDA devices are required",
|
|
285
|
+
)
|
|
286
|
+
def test_cuda_explicit_device_selects_matching_native_runtime(self):
|
|
287
|
+
original_device = torch.cuda.current_device()
|
|
288
|
+
target_index = (original_device + 1) % torch.cuda.device_count()
|
|
289
|
+
target_device = torch.device(f"cuda:{target_index}")
|
|
290
|
+
torch.cuda.set_device(original_device)
|
|
291
|
+
|
|
292
|
+
try:
|
|
293
|
+
shape = (10, 11, 9)
|
|
294
|
+
nt = 8
|
|
295
|
+
eps_r = torch.full(shape, 4.0, device=target_device)
|
|
296
|
+
sigma = torch.zeros_like(eps_r)
|
|
297
|
+
source = torch.zeros((1, nt, 1), device=target_device)
|
|
298
|
+
source[0, 1, 0] = 1.0
|
|
299
|
+
source_location = torch.tensor(
|
|
300
|
+
[[[5, 5, 4]]], dtype=torch.int32, device=target_device
|
|
301
|
+
)
|
|
302
|
+
receiver_location = torch.tensor(
|
|
303
|
+
[[[5, 7, 4]]], dtype=torch.int32, device=target_device
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
receiver = DeepGPR.compute(
|
|
307
|
+
device=target_device,
|
|
308
|
+
dx=0.02,
|
|
309
|
+
dt=1.0e-11,
|
|
310
|
+
source_amplitudes=source,
|
|
311
|
+
source_location=source_location,
|
|
312
|
+
receiver_location=receiver_location,
|
|
313
|
+
eps_r=eps_r,
|
|
314
|
+
sigma=sigma,
|
|
315
|
+
pmlthick=2,
|
|
316
|
+
fdtd_order=2,
|
|
317
|
+
mode=3,
|
|
318
|
+
)[-1]
|
|
319
|
+
torch.cuda.synchronize(target_device)
|
|
320
|
+
|
|
321
|
+
self.assertEqual(receiver.device, target_device)
|
|
322
|
+
self.assertTrue(torch.isfinite(receiver).all().item())
|
|
323
|
+
self.assertEqual(torch.cuda.current_device(), original_device)
|
|
324
|
+
finally:
|
|
325
|
+
torch.cuda.set_device(original_device)
|
|
326
|
+
|
|
282
327
|
def test_source_waveform_gradient_matches_finite_difference(self):
|
|
283
328
|
nx, ny, nt = 12, 14, 60
|
|
284
329
|
eps_r = torch.full((nx, ny), 4.0)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|