Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/libxc-v0.6' into feat/td…
Browse files Browse the repository at this point in the history
…dft-grad-pzc-only
  • Loading branch information
puzhichen committed Feb 28, 2025
2 parents e927cdf + 1d805bd commit 7ce8dd3
Show file tree
Hide file tree
Showing 19 changed files with 9,680 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/nightly_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ jobs:
echo $GITHUB_WORKSPACE
export PYTHONPATH="${PYTHONPATH}:$(pwd)"
pytest gpu4pyscf/tests/test_benchmark_uks.py -s -v -m "not slow and not high_memory" --benchmark-compare-fail=min:10% --benchmark-compare=v1.3.0_uks_1v100 --benchmark-storage=gpu4pyscf/tests/benchmark_results/
- name: Test TDDFT
run: |
echo $GITHUB_WORKSPACE
export PYTHONPATH="${PYTHONPATH}:$(pwd)"
pytest gpu4pyscf/tests/test_benchmark_tddft.py -s -v -m "not slow and not high_memory" --benchmark-compare-fail=min:10% --benchmark-compare=v1.3.0_tddft_1v100 --benchmark-storage=gpu4pyscf/tests/benchmark_results/
2 changes: 1 addition & 1 deletion builder/build_libxc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ rm -rf /gpu4pyscf/put4pyscf/lib/*.so

setup_dir=$(dirname $0)

cmake -S /gpu4pyscf/gpu4pyscf/lib -B build/temp.gpu4pyscf-libxc -DBUILD_DFTD3=OFF -DBUILD_DFTD4=OFF -DBUILD_GINT=OFF -DBUILD_GVHF=OFF -DBUILD_GDFT=OFF -DBUILD_CUPY_HELPER=OFF -DBUILD_SOLVENT=OFF
cmake -S /gpu4pyscf/gpu4pyscf/lib -B build/temp.gpu4pyscf-libxc -DBUILD_GINT=OFF -DBUILD_GVHF=OFF -DBUILD_GDFT=OFF -DBUILD_CUPY_HELPER=OFF -DBUILD_SOLVENT=OFF -DBUILD_GVHF_RYS=OFF -DBUILD_GVHF_MD=OFF -DBUILD_PBC=OFF -DCUDA_ARCHITECTURES="70-real"
cmake --build build/temp.gpu4pyscf-libxc -j 4

mkdir -p build/lib.gpu4pyscf-libxc/gpu4pyscf/lib/deps/lib
Expand Down
10 changes: 5 additions & 5 deletions builder/setup_libxc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
from distutils.util import get_platform

NAME = 'gpu4pyscf-libxc'
AUTHOR = 'Qiming Sun'
AUTHOR_EMAIL = '[email protected]'
DESCRIPTION = 'GPU extensions for PySCF'
LICENSE = 'GPLv3'
AUTHOR = 'PySCF developers'
AUTHOR_EMAIL = None
DESCRIPTION = 'Customized LibXC for GPU4PySCF'
LICENSE = 'Apache-2.0'
URL = None
DOWNLOAD_URL = None
CLASSIFIERS = None
PLATFORMS = None
VERSION = '0.5'
VERSION = '0.6'

def get_cuda_version():
nvcc_out = subprocess.check_output(["nvcc", "--version"]).decode('utf-8')
Expand Down
53 changes: 53 additions & 0 deletions gpu4pyscf/df/df.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
from gpu4pyscf.lib.cupy_helper import (cholesky, tag_array, get_avail_mem,
cart2sph, p2p_transfer, copy_array)
from gpu4pyscf.df import int3c2e, df_jk
from gpu4pyscf.df import int3c2e_bdiv
from gpu4pyscf.lib import logger
from gpu4pyscf import __config__
from gpu4pyscf.__config__ import _streams, num_devices

MIN_BLK_SIZE = getattr(__config__, 'min_ao_blksize', 128)
ALIGNED = getattr(__config__, 'ao_aligned', 32)
GB = 1024*1024*1024
INT3C2E_V2 = False

LINEAR_DEP_THR = incore.LINEAR_DEP_THR
GROUP_SIZE = 256
Expand Down Expand Up @@ -82,6 +84,42 @@ def build(self, direct_scf_tol=1e-14, omega=None):
if auxmol is None:
self.auxmol = auxmol = addons.make_auxmol(mol, self.auxbasis)

if INT3C2E_V2:
self.intopt = intopt = int3c2e_bdiv.Int3c2eOpt(mol, auxmol)
self._cderi = {}
self._cderi[0] = _cholesky_eri_bdiv(intopt, omega=omega)
ao_pair_mapping = intopt.create_ao_pair_mapping(cart=mol.cart)
rows, cols = divmod(cupy.asarray(ao_pair_mapping), mol.nao)
intopt.cderi_row = rows
intopt.cderi_col = cols

# intopt.cderi_diag stores the indices for cderi_row that
# corresponds to the diagonal blocks. Note this index array can
# contain some of the off-diagonal elements which happen to be the
# off-diagonal elements while within the diagonal blocks.
uniq_l = intopt.uniq_l_ctr[:,0]
if mol.cart:
nf = (uniq_l + 1) * (uniq_l + 2) // 2
else:
nf = uniq_l * 2 + 1
n_groups = len(uniq_l)
ij_tasks = ((i, j) for i in range(n_groups) for j in range(i+1))
nbas = intopt.sorted_mol.nbas
offset = 0
cderi_diag = []
for (i, j), bas_ij_idx in zip(ij_tasks, intopt.shl_pair_idx):
nfi = nf[i]
nfj = nf[j]
if i == j: # the diagonal blocks
ish, jsh = divmod(bas_ij_idx, nbas)
idx = np.where(ish == jsh)[0]
addr = offset + idx[:,None] * (nfi*nfi) + np.arange(nfi*nfi)
cderi_diag.append(addr.ravel())
offset += bas_ij_idx.size * nfi * nfj
intopt.cderi_diag = cupy.asarray(np.hstack(cderi_diag))
log.timer_debug1('cholesky_eri', *t0)
return self

if omega and omega > 1e-10:
with auxmol.with_range_coulomb(omega):
j2c_cpu = auxmol.intor('int2c2e', hermi=1)
Expand Down Expand Up @@ -364,3 +402,18 @@ def _cderi_task(intopt, cd_low, task_list, _cderi, aux_blksize,
_cderi[0][:,ij0:ij1] = cderi_block
t1 = log.timer_debug1(f'transfer data for {cp_ij_id} / {nq} on Device {device_id}', *t1)
return

# Generate CDERI using the new int3c2e_bdiv algorithm
def _cholesky_eri_bdiv(intopt, omega=None):
assert isinstance(intopt, int3c2e_bdiv.Int3c2eOpt)
assert omega is None
eri3c = intopt.int3c2e_bdiv_kernel()
if intopt.mol.cart:
eri3c = intopt.orbital_pair_cart2sph(eri3c)
auxmol = intopt.auxmol
j2c = cupy.asarray(auxmol.intor('int2c2e', hermi=1), order='C')
cd_low = cholesky(j2c)
aux_coeff = cupy.array(intopt.aux_coeff, copy=True)
cd_low = solve_triangular(cd_low, aux_coeff.T, lower=True, overwrite_b=True)
cderi = cd_low.dot(eri3c.T)
return cderi
Loading

0 comments on commit 7ce8dd3

Please sign in to comment.