Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error while running example.py #5

Open
bening-gawitsa opened this issue Mar 7, 2023 · 5 comments
Open

error while running example.py #5

bening-gawitsa opened this issue Mar 7, 2023 · 5 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request question Further information is requested

Comments

@bening-gawitsa
Copy link

Hi Amir,
As your suggestion for adding argument "set_env_variable=False" in wave.WavePropagator, then I got this error

PS C:\Users\ASUS\Desktop\bismillah> & C:/Users/ASUS/AppData/Local/Microsoft/WindowsApps/python3.10.exe c:/Users/ASUS/Desktop/bismillah/example.py
Device 0 is chosen.
Choose platform:
[0] <pyopencl.Platform 'Intel(R) OpenCL HD Graphics' at 0x1cf38ace6a0>
[1] <pyopencl.Platform 'NVIDIA CUDA' at 0x1cf38ae0a20>
[2] <pyopencl.Platform 'Intel(R) OpenCL' at 0x1cf2e529808>
[3] <pyopencl.Platform 'Intel(R) FPGA Emulation Platform for OpenCL(TM)' at 0x1cf2e52abf8>
[4] <pyopencl.Platform 'Intel(R) FPGA SDK for OpenCL(TM)' at 0x7ffdeca44f20>
Choice [0]:1
Set the environment variable PYOPENCL_CTX='1' to avoid being asked again.
Device 0 is chosen.
Choose platform:
[0] <pyopencl.Platform 'Intel(R) OpenCL HD Graphics' at 0x1cf38ace6a0>
[1] <pyopencl.Platform 'NVIDIA CUDA' at 0x1cf38ae0a20>
[2] <pyopencl.Platform 'Intel(R) OpenCL' at 0x1cf2e529808>
[3] <pyopencl.Platform 'Intel(R) FPGA Emulation Platform for OpenCL(TM)' at 0x1cf2e52abf8>
[4] <pyopencl.Platform 'Intel(R) FPGA SDK for OpenCL(TM)' at 0x7ffdeca44f20>
    self.__kernel(s, coeff)
  File "C:\Users\ASUS\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyFWI\wave_propagation.py", line 712, in __kernel
    cl.enqueue_copy(self.queue, copy_purpose, self.vx_b)
  File "C:\Users\ASUS\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyopencl\__init__.py", line 2009, in enqueue_copy    return _cl._enqueue_read_buffer(queue, src, dest, **kwargs)
pyopencl._cl.RuntimeError: clEnqueueReadBuffer failed: OUT_OF_RESOURCES
@AmirMardan
Copy link
Owner

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}")

@AmirMardan AmirMardan added documentation Improvements or additions to documentation enhancement New feature or request question Further information is requested labels Mar 8, 2023
@AmirMardan AmirMardan pinned this issue Mar 22, 2023
@zj15001
Copy link

zj15001 commented Nov 17, 2023

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 []
 ================

@AmirMardan
Copy link
Owner

@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

@petrolworker
Copy link

petrolworker commented Nov 21, 2023

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')

@AmirMardan
Copy link
Owner

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants