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.
Files changed (27) hide show
  1. {deepgpr-0.0.18 → deepgpr-0.0.19}/PKG-INFO +1 -1
  2. {deepgpr-0.0.18 → deepgpr-0.0.19}/pyproject.toml +1 -1
  3. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/compute2.py +17 -8
  4. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr.dll +0 -0
  5. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr_cpu.dll +0 -0
  6. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR.egg-info/PKG-INFO +1 -1
  7. {deepgpr-0.0.18 → deepgpr-0.0.19}/tests/test_discrete_adjoint.py +45 -0
  8. {deepgpr-0.0.18 → deepgpr-0.0.19}/README.md +0 -0
  9. {deepgpr-0.0.18 → deepgpr-0.0.19}/license +0 -0
  10. {deepgpr-0.0.18 → deepgpr-0.0.19}/setup.cfg +0 -0
  11. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/__init__.py +0 -0
  12. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/common.py +0 -0
  13. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr.cu +0 -0
  14. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr.h +0 -0
  15. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr.so +0 -0
  16. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr_cpu.c +0 -0
  17. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr_cpu.dylib +0 -0
  18. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/deepgpr_cpu.so +0 -0
  19. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/lib/libomp.dylib +0 -0
  20. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/multiscale.py +0 -0
  21. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR/wavelet.py +0 -0
  22. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR.egg-info/SOURCES.txt +0 -0
  23. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR.egg-info/dependency_links.txt +0 -0
  24. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR.egg-info/requires.txt +0 -0
  25. {deepgpr-0.0.18 → deepgpr-0.0.19}/src/DeepGPR.egg-info/top_level.txt +0 -0
  26. {deepgpr-0.0.18 → deepgpr-0.0.19}/tests/test_numerics.py +0 -0
  27. {deepgpr-0.0.18 → deepgpr-0.0.19}/tests/test_wavelet.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DeepGPR
3
- Version: 0.0.18
3
+ Version: 0.0.19
4
4
  Summary: PyTorch and CUDA for GPR FWI
5
5
  Author-email: Lei Liu <liulei990222@gmail.com>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "DeepGPR"
7
- version = "0.0.18"
7
+ version = "0.0.19"
8
8
  authors = [
9
9
  { name = "Lei Liu", email = "liulei990222@gmail.com" }
10
10
  ]
@@ -445,23 +445,32 @@ def _save_forward_wavefield(wavefield, directory, run_time):
445
445
 
446
446
 
447
447
  def _begin_native_call(device):
448
- """Order the native default stream after PyTorch's current CUDA stream."""
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
- return current_stream, default_stream
457
- return None
463
+ return current_stream, default_stream, restore_device
458
464
 
459
465
 
460
- def _end_native_call(streams):
461
- """Make PyTorch's current stream wait for an asynchronous native call."""
462
- if streams is not None:
463
- current_stream, default_stream = streams
464
- current_stream.wait_stream(default_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):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DeepGPR
3
- Version: 0.0.18
3
+ Version: 0.0.19
4
4
  Summary: PyTorch and CUDA for GPR FWI
5
5
  Author-email: Lei Liu <liulei990222@gmail.com>
6
6
  License-Expression: MIT
@@ -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