pyscf / gpu4pyscf

A plugin to use Nvidia GPU in PySCF package
GNU General Public License v3.0
138 stars 24 forks source link

Hamiltonian computation does not use GPU #12

Closed Obs01ete closed 7 months ago

Obs01ete commented 1 year ago

I run the GPU-patched version of pyscf to compute the hamiltonian.

import pyscf
from gpu4pyscf import patch_pyscf

from pyscf import gto, scf

def ...
    mol = gto.Mole()
    mol.atom = [(Z, pos) for Z, pos in zip(atomic_numbers, positions)]
    mol.basis = 'def2-tzvp'
    # number of electrons
    num_electrons = mol.nelectron

    if num_electrons % 2 != 0:
        mol.spin = 1
    else:
        mol.spin = 0

    mf = scf.RHF(mol)

    # Obtain the Hamiltonian matrix
    hcore = mf.get_hcore()

This code does not load my V100 unlike the example in README.md. What do I do to speed up this code with GPU?

wxj6000 commented 1 year ago

Certain modules of GPU4PySCF are still running on CPU, such as mf.get_hcore(), since it is not very expensive. More modules are moved into GPU in the recent release. The current release is gpu4pyscf-0.5. Please notice that the patch-mechanism may not be fully supported. You can explicitly import the module instead. Here is the example. https://github.com/pyscf/gpu4pyscf/blob/master/examples/01-h2o_dftd3.py

Obs01ete commented 1 year ago

@wxj6000 Thank you for clarifying the state of the library. I'd be glad to see get_hcore() sped up in the future release of GPU4PySCF. For bigger molecules or crystal cells get_hcore runtime can go up to 10s of seconds. If course it is way faster than the DFT compute but it would be great to make use of my GPU.

wxj6000 commented 1 year ago

Thank you for the feedback. I will add this to the future development.

Obs01ete commented 7 months ago

Sweet, sweet, that HF iterations now run on GPU nicely. Here is my benchmarking:

CPU 48 cores: 40 s/molecule
GPU V100: 15 s/molecule
GPU A100: 15 s/molecule
wxj6000 commented 7 months ago

@Obs01ete Glad to hear that! Do A100 and V100 have the similar performance in your benchmark?

Obs01ete commented 5 months ago

@Obs01ete Glad to hear that! Do A100 and V100 have the similar performance in your benchmark?

Yes. I am not sure why, though.