Open bening-gawitsa opened 1 year ago
Hi,
The error here is about picking the right platform and device to run the code.
It seems you need set_env_variable=True
. You should define the right platform and device using inpa
dictionary.
You can use the following lines of code to see how many platforms you have and how many devices are available on each platform.
import pyopencl as cl
platforms = cl.get_platforms()
for platform in platforms:
print(f"platform: {platform}")
devices = platform.get_devices()
gpu_devices = platform.get_devices(device_type=cl.device_type.GPU)
cpu_devices = platform.get_devices(device_type=cl.device_type.CPU)
print(f"Devices:\nAll: {devices}\nGPU: {gpu_devices}\nCPU {cpu_devices}\n {'='*16}")
Hi Amir,
I also met an error while creating the wave object with
W = wave.WavePropagator(inpa, src, rec_loc, model_shape, components=seisout, chpr=20)
the error message is
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
Cell In[24], line 2
1 # Create the wave object
----> 2 W = wave.WavePropagator(inpa, src, rec_loc, model_shape,
3 n_well_rec=n_well_rec,
4 components=seisout, chpr=0)
6 # Call the forward modelling
7 d_obs = W.forward_modeling(model, show=False) # show=True can show the propagation of the wave
File ~\.conda\envs\yolov5\lib\site-packages\PyFWI\wave_propagation.py:621, in WavePropagator.__init__(self, inpa, src, rec_loc, model_shape, components, n_well_rec, chpr, set_env_variable)
620 def __init__(self, inpa, src, rec_loc, model_shape, components=0, n_well_rec=0, chpr=0, set_env_variable=True):
--> 621 WavePreparation.__init__(self, inpa=inpa, src=src, rec_loc=rec_loc, model_shape=model_shape, components=components,
622 n_well_rec=n_well_rec, chpr=chpr,
623 set_env_variable=set_env_variable)
File ~\.conda\envs\yolov5\lib\site-packages\PyFWI\wave_propagation.py:172, in WavePreparation.__init__(self, inpa, src, rec_loc, model_shape, components, n_well_rec, chpr, set_env_variable)
170 device = inpa["device"]
171 if device >= len(devices):
--> 172 raise Exception("Bad chosen device. There are {} available device(s).".format(len(devices)))
173 else:
174 device = 0
Exception: Bad chosen device. There are 1 available device(s).
I have running the code
import pyopencl as cl
platforms = cl.get_platforms()
for platform in platforms:
print(f"platform: {platform}")
devices = platform.get_devices()
gpu_devices = platform.get_devices(device_type=cl.device_type.GPU)
cpu_devices = platform.get_devices(device_type=cl.device_type.CPU)
print(f"Devices:\nAll: {devices}\nGPU: {gpu_devices}\nCPU {cpu_devices}\n {'='*16}")
and get the platform and Devices information
platform: <pyopencl.Platform 'NVIDIA CUDA' at 0x26a76cbd0a0>
Devices:
All: [<pyopencl.Device 'NVIDIA GeForce RTX 3070' on 'NVIDIA CUDA' at 0x26a76cbc290>]
GPU: [<pyopencl.Device 'NVIDIA GeForce RTX 3070' on 'NVIDIA CUDA' at 0x26a76cbc290>]
CPU []
================
@zj15001
Your system has only one device, but in the example, the device is set to 1. So, you should set the device in inpa
to 0 before creating the wave propagator object.
inpa["device"] = 0
Hi Amir, I have checked my device and obtained the following information:
platform: <pyopencl.Platform 'NVIDIA CUDA' at 0x37b8f30>
Devices:
All: [<pyopencl.Device 'NVIDIA GeForce RTX 3060 Ti' on 'NVIDIA CUDA' at 0x3818ed0>]
GPU: [<pyopencl.Device 'NVIDIA GeForce RTX 3060 Ti' on 'NVIDIA CUDA' at 0x3818ed0>]
CPU []
================
I have set ’ inpa["device"] = 0‘, but I have received a new error:
RuntimeError Traceback (most recent call last)
[/home/Downloads/FWI/docs/sub_doc/example.ipynb] Cell 15 line 2
[1] # Create the wave object
----> [2] W = wave.WavePropagator(inpa, src, rec_loc, model_shape, components=seisout, chpr=20)
[4] # Call the forward modelling
[5]d_obs = W.forward_modeling(model, show=False) # show=True can show the propagation of the wave
File [~/anaconda3/envs/pytorch/lib/python3.11/site-packages/PyFWI/wave_propagation.py:621], in WavePropagator.__init__(self, inpa, src, rec_loc, model_shape, components, n_well_rec, chpr, set_env_variable)
[620] def __init__(self, inpa, src, rec_loc, model_shape, components=0, n_well_rec=0, chpr=0, set_env_variable=True):
--> [621] WavePreparation.__init__(self, inpa=inpa, src=src, rec_loc=rec_loc, model_shape=model_shape, components=components,
[622] n_well_rec=n_well_rec, chpr=chpr,
[623] set_env_variable=set_env_variable)
File [~/anaconda3/envs/pytorch/lib/python3.11/site-packages/PyFWI/wave_propagation.py:181], in WavePreparation.__init__(self, inpa, src, rec_loc, model_shape, components, n_well_rec, chpr, set_env_variable)
[178] os.environ['PYOPENCL_CTX'] = str(platform) + ':' + str(device)
[179] os.environ['PYOPENCL_COMPILER_OUTPUT'] = '1'
--> [181] self.ctx = cl.create_some_context()
[182] self.queue = cl.CommandQueue(self.ctx)
[184] kernel, kernel_crosswell, kernel_surface = self.kernel_caller()
File [~/anaconda3/envs/pytorch/lib/python3.11/site-packages/pyopencl/__init__.py:1679], in create_some_context(interactive, answers)
[1675] cc_print("Set the environment variable PYOPENCL_CTX='%s' to "
[1676] "avoid being asked again." % ":".join(user_inputs))
[1678]if answers:
-> [1679] raise RuntimeError("not all provided choices were used by "
[1680] "create_some_context. (left over: '%s')" % ":".join(answers))
[1682]return Context(devices)
RuntimeError: not all provided choices were used by create_some_context. (left over: '0')
@petrolworker
Another option is that you define inpa
without the key device
. Then create a wave propagator object as
wave.WavePropagator(inpa, src, rec_loc, model_shape, components=seisout, chpr=20, set_env_variable=False)
The important argument is set_env_variable=False
that you should provide the wave propagator object with.
Hi Amir, As your suggestion for adding argument "set_env_variable=False" in wave.WavePropagator, then I got this error