Skip to content

VNL::vkb is allocated in CPU even if device set to gpu, resulting in bad_array_new_length #7294

@Cstandardlib

Description

@Cstandardlib

Describe the bug

The vkb memory block of size (nkb, npwx) is allocated by new (CPU MEMORY),
and this snippet is called even in GPU branch.

in source/source_pw/module_pwdft/vnl_pw.cpp:

if (nkb > 0 && allocate_vkb)
    {
        vkb.create(nkb, npwx);
        ModuleBase::Memory::record("VNL::vkb", nkb * npwx * sizeof(std::complex<double>));
    }

in source/source_base/complexmatrix.cpp:

// reallocate memory for Complex Matrix
void ComplexMatrix::create(const int nr_in, const int nc_in, const bool flag_zero)
{
	if( nr_in && nc_in )
	{
		if(c)
		{
			const int size_in=nr_in*nc_in;
			if( size_in!=nr*nc )
			{
				delete[] c;
				c = new std::complex<double>[size_in];
			}
		}
		else
		{
			c = new std::complex<double>[nr_in * nc_in];
		}

		nr = nr_in;
		nc = nc_in;
		size = nr*nc;
		if(flag_zero)	zero_out();
	}
	else
	{
		if(c)	delete[] c;
		c = nullptr;
		nr = nr_in;
		nc = nc_in;
		size = nr*nc;
	}
}

When running on GPU-like device with many atoms and huge ecutwfc, the new expression will raise a std::bad_array_new_length error.

Expected behavior

No response

To Reproduce

No response

Environment

No response

Additional Context

No response

Task list for Issue attackers (only for developers)

  • Verify the issue is not a duplicate.
  • Describe the bug.
  • Steps to reproduce.
  • Expected behavior.
  • Error message.
  • Environment details.
  • Additional context.
  • Assign a priority level (low, medium, high, urgent).
  • Assign the issue to a team member.
  • Label the issue with relevant tags.
  • Identify possible related issues.
  • Create a unit test or automated test to reproduce the bug (if applicable).
  • Fix the bug.
  • Test the fix.
  • Update documentation (if necessary).
  • Close the issue and inform the reporter (if applicable).

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugsBugs that only solvable with sufficient knowledge of DFTMemoryMemory issuesRefactorRefactor ABACUS codes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions