GPU Accelerated Spectra (recalc_gpu() demo)¶
Example using GPU calculation with recalc_gpu()
After producing a spectrum object with sf.eq_spectrum_gpu(), new spectra can be produced quickly with spectrum.recalc_gpu().
Note
Systems with a dedicated GPU often have multiple devices available, because they also have an integrated GPU in the main processor. This can be selected by chosing a different device_id (e.g. ânvidiaâ or âintelâ). The device id could be a string or an integer. The integer is the device number, starting from 0. Look at the device overview printed when running the GPU spectrum to see what options are available.
Make sure to call gpu_exit() at the end to release all GPU resources. This canât be done automatically because Radis doesnât know how long you want to keep using the GPU. If you want to immediately exit the GPU calculations, the keyword exit_gpu=True can be passed to sf.eq_spectrum_gpu(), but this is uncommon because it doesnât leverage the full power of GPU calculations.

--------------------------------------------------------------------------------
CO - HITRAN - Downloading database
--------------------------------------------------------------------------------
Download:
- All files already downloaded.
Caching to HDF5/H5 format:
- All files already cached.
0.03s - Loaded database
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:434: HighTemperatureWarning: HITRAN is valid for low temperatures (typically < 700 K). For higher temperatures you may need HITEMP or CDSD. See the 'databank=' parameter
warnings.warn(WarningType(message))
Vulkan version: 1.3.275.1
Selected device (device_id = 0):
[X] 0: llvmpipe (LLVM 15.0.7, 256 bits)
Finished calculating spectrum!
0.67s - Spectrum calculated
Slice 1/1
Plot0 finished in 667.7 ms
Plot1 finished in 190.1 ms
Slice 1/1
Plot2 finished in 188.6 ms
Slice 1/1
Plot3 finished in 193.8 ms
Slice 1/1
Plot4 finished in 191.5 ms
Slice 1/1
from radis import SpectrumFactory
sf = SpectrumFactory(
2150,
2450, # cm-1
# molecule="CO2",
molecule="CO",
isotope="1,2,3",
wstep=0.002,
)
sf.fetch_databank("hitran")
##sf.fetch_databank("exomol")
T_list = [1000.0, 1250.0, 1500.0, 1750.0, 2000.0]
s = sf.eq_spectrum_gpu(
Tgas=T_list[0], # K
pressure=1, # bar
mole_fraction=0.8,
path_length=0.2, # cm
# device_id='intel',
# device_id='nvidia',
)
s.apply_slit(0.5, unit="cm-1") # cm-1
print(f"Plot0 finished in {s.conditions['calculation_time'] * 1e3:6.1f} ms")
s.plot("radiance", wunit="nm", show=False)
for i, T in enumerate(T_list[1:]):
s.recalc_gpu(Tgas=T)
print(f"Plot{i + 1:d} finished in {s.conditions['calculation_time'] * 1e3:6.1f} ms")
show = True if T == T_list[-1] else False
s.plot("radiance", wunit="nm", show=show, nfig="same")
s.exit_gpu()
Total running time of the script: (0 minutes 2.242 seconds)