From e7541a353922acc3618563f45a5d6ad152774766 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 31 Jan 2024 00:09:26 -0800 Subject: [PATCH] Make `idcpu` signed --- Src/Particle/AMReX_Particle.H | 36 ++++++++++---------- Src/Particle/AMReX_ParticleCommunication.H | 2 +- Src/Particle/AMReX_ParticleContainerI.H | 26 +++++++------- Src/Particle/AMReX_ParticleIO.H | 4 +-- Src/Particle/AMReX_ParticleInit.H | 4 +-- Src/Particle/AMReX_ParticleTile.H | 22 ++++++------ Src/Particle/AMReX_StructOfArrays.H | 4 +-- Src/Particle/AMReX_WriteBinaryParticleData.H | 4 +-- Tests/Particles/RedistributeSOA/main.cpp | 2 +- 9 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Src/Particle/AMReX_Particle.H b/Src/Particle/AMReX_Particle.H index 1642e0e3b56..20f8bc9e7e8 100644 --- a/Src/Particle/AMReX_Particle.H +++ b/Src/Particle/AMReX_Particle.H @@ -26,11 +26,11 @@ namespace using namespace LongParticleIds; - /** Flags used to set the entire uint64_t idcpu + /** Flags used to set the entire int64_t idcpu to special values at once. */ namespace ParticleIdCpus { - constexpr std::uint64_t Invalid = 16777216; // corresponds to id = -1, cpu = 0 + constexpr std::int64_t Invalid = -16777216LL; // corresponds to id = -1, cpu = 0 } using namespace ParticleIdCpus; @@ -38,12 +38,12 @@ namespace struct ParticleIDWrapper { - uint64_t& m_idata; + int64_t& m_idata; ~ParticleIDWrapper () noexcept = default; AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - ParticleIDWrapper (uint64_t& idata) noexcept + ParticleIDWrapper (int64_t& idata) noexcept : m_idata(idata) {} @@ -133,12 +133,12 @@ struct ParticleIDWrapper struct ParticleCPUWrapper { - uint64_t& m_idata; + int64_t& m_idata; ~ParticleCPUWrapper () noexcept = default; AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - ParticleCPUWrapper (uint64_t& idata) noexcept + ParticleCPUWrapper (int64_t& idata) noexcept : m_idata(idata) {} @@ -181,10 +181,10 @@ struct ParticleCPUWrapper struct ConstParticleIDWrapper { - const uint64_t& m_idata; + const int64_t& m_idata; AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - ConstParticleIDWrapper (const uint64_t& idata) noexcept + ConstParticleIDWrapper (const int64_t& idata) noexcept : m_idata(idata) {} @@ -212,10 +212,10 @@ struct ConstParticleIDWrapper struct ConstParticleCPUWrapper { - const uint64_t& m_idata; + const int64_t& m_idata; AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - ConstParticleCPUWrapper (const uint64_t& idata) noexcept + ConstParticleCPUWrapper (const int64_t& idata) noexcept : m_idata(idata) {} @@ -229,8 +229,8 @@ struct ConstParticleCPUWrapper * to avoid writing twice into the same memory bank. */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -std::uint64_t SetParticleIDandCPU (Long id, int cpu) noexcept{ - std::uint64_t idcpu = 0; +std::int64_t SetParticleIDandCPU (Long id, int cpu) noexcept{ + std::int64_t idcpu = 0; ParticleIDWrapper{idcpu} = id; ParticleCPUWrapper{idcpu} = cpu; return idcpu; @@ -241,7 +241,7 @@ struct ParticleBase { T m_pos[AMREX_SPACEDIM]; T m_rdata[NReal]; - uint64_t m_idcpu = 0; + int64_t m_idcpu = 0; int m_idata[NInt]; }; @@ -249,7 +249,7 @@ template struct ParticleBase { T m_pos[AMREX_SPACEDIM]; - uint64_t m_idcpu = 0; + int64_t m_idcpu = 0; int m_idata[NInt]; }; @@ -258,14 +258,14 @@ struct ParticleBase { T m_pos[AMREX_SPACEDIM]; T m_rdata[NReal]; - uint64_t m_idcpu = 0; + int64_t m_idcpu = 0; }; template struct ParticleBase { T m_pos[AMREX_SPACEDIM]; - uint64_t m_idcpu = 0; + int64_t m_idcpu = 0; }; @@ -314,7 +314,7 @@ struct Particle AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void atomicSetID (const Long id) { - uint64_t tmp = 0; + int64_t tmp = 0; ParticleIDWrapper wrapper(tmp); wrapper = id; #if defined(AMREX_USE_OMP) @@ -424,7 +424,7 @@ struct Particle template ::type = 0> AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - uint64_t& idata (int /*index*/) & + int64_t& idata (int /*index*/) & { AMREX_ALWAYS_ASSERT(false); return this->m_idcpu; //bc we must return something diff --git a/Src/Particle/AMReX_ParticleCommunication.H b/Src/Particle/AMReX_ParticleCommunication.H index 9c9372a192f..0bd6722535f 100644 --- a/Src/Particle/AMReX_ParticleCommunication.H +++ b/Src/Particle/AMReX_ParticleCommunication.H @@ -221,7 +221,7 @@ struct ParticleCopyPlan } if constexpr (PC::ParticleType::is_soa_particle) { - m_superparticle_size = sizeof(uint64_t); // idcpu + m_superparticle_size = sizeof(int64_t); // idcpu } else { m_superparticle_size = sizeof(typename PC::ParticleType); } diff --git a/Src/Particle/AMReX_ParticleContainerI.H b/Src/Particle/AMReX_ParticleContainerI.H index fe83ce5ba1c..c116ceb0742 100644 --- a/Src/Particle/AMReX_ParticleContainerI.H +++ b/Src/Particle/AMReX_ParticleContainerI.H @@ -19,7 +19,7 @@ ParticleContainer_impl; + int64_t, uint32_t>; constexpr std::size_t nchunks = sizeof(ParticleType) / sizeof(tmp_t); Gpu::DeviceVector tmp(np); auto* ptmp = tmp.data(); @@ -1722,8 +1722,8 @@ ParticleContainer_impl >& not_ours, Particle p; if constexpr (ParticleType::is_soa_particle) { - std::memcpy(&p.m_idcpu, pbuf, sizeof(uint64_t)); + std::memcpy(&p.m_idcpu, pbuf, sizeof(int64_t)); ParticleReal pos[AMREX_SPACEDIM]; - std::memcpy(&pos[0], pbuf + sizeof(uint64_t), AMREX_SPACEDIM*sizeof(ParticleReal)); + std::memcpy(&pos[0], pbuf + sizeof(int64_t), AMREX_SPACEDIM*sizeof(ParticleReal)); AMREX_D_TERM(p.pos(0) = pos[0];, p.pos(1) = pos[1];, p.pos(2) = pos[2]); @@ -2115,9 +2115,9 @@ RedistributeMPI (std::map >& not_ours, char* pbuf = ((char*) &recvdata[offset]) + j*superparticle_size; if constexpr (ParticleType::is_soa_particle) { - uint64_t idcpudata; - std::memcpy(&idcpudata, pbuf, sizeof(uint64_t)); - pbuf += sizeof(uint64_t); + int64_t idcpudata; + std::memcpy(&idcpudata, pbuf, sizeof(int64_t)); + pbuf += sizeof(int64_t); ptile.GetStructOfArrays().GetIdCPUData().push_back(idcpudata); } else { ParticleType p; @@ -2168,7 +2168,7 @@ RedistributeMPI (std::map >& not_ours, host_int_attribs.reserve(15); host_int_attribs.resize(finestLevel()+1); - Vector, Gpu::HostVector > > host_idcpu; + Vector, Gpu::HostVector > > host_idcpu; host_idcpu.reserve(15); host_idcpu.resize(finestLevel()+1); @@ -2189,9 +2189,9 @@ RedistributeMPI (std::map >& not_ours, host_int_attribs[lev][ind].resize(NumIntComps()); if constexpr (ParticleType::is_soa_particle) { - uint64_t idcpudata; - std::memcpy(&idcpudata, pbuf, sizeof(uint64_t)); - pbuf += sizeof(uint64_t); + int64_t idcpudata; + std::memcpy(&idcpudata, pbuf, sizeof(int64_t)); + pbuf += sizeof(int64_t); host_idcpu[lev][ind].push_back(idcpudata); } else { ParticleType p; diff --git a/Src/Particle/AMReX_ParticleIO.H b/Src/Particle/AMReX_ParticleIO.H index 22c0c5a35f9..15ef4904225 100644 --- a/Src/Particle/AMReX_ParticleIO.H +++ b/Src/Particle/AMReX_ParticleIO.H @@ -992,7 +992,7 @@ ParticleContainer_impl, Gpu::HostVector > > host_idcpu; + Vector, Gpu::HostVector > > host_idcpu; host_idcpu.reserve(15); host_idcpu.resize(finestLevel()+1); @@ -1006,7 +1006,7 @@ ParticleContainer_impl, Gpu::HostVector > > host_idcpu; + Vector, Gpu::HostVector > > host_idcpu; host_idcpu.reserve(15); host_idcpu.resize(finestLevel()+1); @@ -1211,7 +1211,7 @@ InitRandom (Long icount, host_int_attribs.reserve(15); host_int_attribs.resize(finestLevel()+1); - Vector, Gpu::HostVector > > host_idcpu; + Vector, Gpu::HostVector > > host_idcpu; host_idcpu.reserve(15); host_idcpu.resize(finestLevel()+1); diff --git a/Src/Particle/AMReX_ParticleTile.H b/Src/Particle/AMReX_ParticleTile.H index c072680e61d..00758790cd1 100644 --- a/Src/Particle/AMReX_ParticleTile.H +++ b/Src/Particle/AMReX_ParticleTile.H @@ -47,7 +47,7 @@ struct ParticleTileData void * AMREX_RESTRICT, ParticleType * AMREX_RESTRICT>; AOS_PTR m_aos; - uint64_t* m_idcpu; + int64_t* m_idcpu; GpuArray m_rdata; GpuArray m_idata; @@ -128,8 +128,8 @@ struct ParticleTileData memcpy(dst, m_aos + src_index, sizeof(ParticleType)); dst += sizeof(ParticleType); } else { - memcpy(dst, m_idcpu + src_index, sizeof(uint64_t)); - dst += sizeof(uint64_t); + memcpy(dst, m_idcpu + src_index, sizeof(int64_t)); + dst += sizeof(int64_t); } int array_start_index = AMREX_SPACEDIM + NStructReal; for (int i = 0; i < NAR; ++i) @@ -179,8 +179,8 @@ struct ParticleTileData memcpy(m_aos + dst_index, src, sizeof(ParticleType)); src += sizeof(ParticleType); } else { - memcpy(m_idcpu + dst_index, src, sizeof(uint64_t)); - src += sizeof(uint64_t); + memcpy(m_idcpu + dst_index, src, sizeof(int64_t)); + src += sizeof(int64_t); } int array_start_index = AMREX_SPACEDIM + NStructReal; for (int i = 0; i < NAR; ++i) @@ -393,7 +393,7 @@ struct SoAParticle : SoAParticleBase ParticleIDWrapper id () & { return this->m_particle_tile_data.m_idcpu[m_index]; } [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - uint64_t& idcpu () & { return this->m_particle_tile_data.m_idcpu[m_index]; } + int64_t& idcpu () & { return this->m_particle_tile_data.m_idcpu[m_index]; } [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ConstParticleCPUWrapper cpu () const & { return this->m_particle_tile_data.m_idcpu[m_index]; } @@ -402,7 +402,7 @@ struct SoAParticle : SoAParticleBase ConstParticleIDWrapper id () const & { return this->m_particle_tile_data.m_idcpu[m_index]; } [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - const uint64_t& idcpu () const & { return this->m_particle_tile_data.m_idcpu[m_index]; } + const int64_t& idcpu () const & { return this->m_particle_tile_data.m_idcpu[m_index]; } //functions to get positions of the particle in the SOA data @@ -508,7 +508,7 @@ struct ConstParticleTileData void const * AMREX_RESTRICT, ParticleType const * AMREX_RESTRICT>; AOS_PTR m_aos; - const uint64_t* m_idcpu; + const int64_t* m_idcpu; GpuArray m_rdata; GpuArray m_idata; @@ -589,8 +589,8 @@ struct ConstParticleTileData memcpy(dst, m_aos + src_index, sizeof(ParticleType)); dst += sizeof(ParticleType); } else { - memcpy(dst, m_idcpu + src_index, sizeof(uint64_t)); - dst += sizeof(uint64_t); + memcpy(dst, m_idcpu + src_index, sizeof(int64_t)); + dst += sizeof(int64_t); } int array_start_index = AMREX_SPACEDIM + NStructReal; for (int i = 0; i < NArrayReal; ++i) @@ -1069,7 +1069,7 @@ struct ParticleTile { Long nbytes = 0; if constexpr (ParticleType::is_soa_particle) { - nbytes += GetStructOfArrays().GetIdCPUData().capacity() * sizeof(uint64_t); + nbytes += GetStructOfArrays().GetIdCPUData().capacity() * sizeof(int64_t); } else { nbytes += m_aos_tile().capacity() * sizeof(ParticleType); } diff --git a/Src/Particle/AMReX_StructOfArrays.H b/Src/Particle/AMReX_StructOfArrays.H index 4de35e085ca..82ad87c35f3 100644 --- a/Src/Particle/AMReX_StructOfArrays.H +++ b/Src/Particle/AMReX_StructOfArrays.H @@ -15,7 +15,7 @@ template struct StructOfArrays { - using IdCPU = amrex::PODVector >; + using IdCPU = amrex::PODVector >; using RealVector = amrex::PODVector >; using IntVector = amrex::PODVector >; @@ -195,7 +195,7 @@ struct StructOfArrays { for (int i = 0; i < int(m_runtime_idata.size()); ++i) { m_runtime_idata[i].resize(count); } } - [[nodiscard]] uint64_t* idcpuarray () { + [[nodiscard]] int64_t* idcpuarray () { if constexpr (use64BitIdCpu == true) { return m_idcpu.dataPtr(); } else { diff --git a/Src/Particle/AMReX_WriteBinaryParticleData.H b/Src/Particle/AMReX_WriteBinaryParticleData.H index 449c26c6ef2..cc90297fa3b 100644 --- a/Src/Particle/AMReX_WriteBinaryParticleData.H +++ b/Src/Particle/AMReX_WriteBinaryParticleData.H @@ -338,7 +338,7 @@ packIOData (Vector& idata, Vector& rdata, const PC& pc, int l else { amrex::ignore_unused(is_checkpoint); // Int: id, cpu - uint64_t idcpu = soa.GetIdCPUData()[pindex]; + int64_t idcpu = soa.GetIdCPUData()[pindex]; *iptr = (int) ParticleIDWrapper(idcpu); iptr += 1; *iptr = (int) ParticleCPUWrapper(idcpu); @@ -1033,7 +1033,7 @@ void WriteBinaryParticleDataAsync (PC const& pc, } else { // Ints: id, cpu - uint64_t idcpu = soa.GetIdCPUData()[pindex]; + int64_t idcpu = soa.GetIdCPUData()[pindex]; *iptr = (int) ParticleIDWrapper(idcpu); iptr += 1; *iptr = (int) ParticleCPUWrapper(idcpu); diff --git a/Tests/Particles/RedistributeSOA/main.cpp b/Tests/Particles/RedistributeSOA/main.cpp index 62da81def81..823098658e3 100644 --- a/Tests/Particles/RedistributeSOA/main.cpp +++ b/Tests/Particles/RedistributeSOA/main.cpp @@ -92,7 +92,7 @@ class TestParticleContainer { const Box& tile_box = mfi.tilebox(); - Gpu::HostVector host_idcpu; + Gpu::HostVector host_idcpu; std::array, NR> host_real; std::array, NI> host_int;