Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable conversion warnings #809

Merged
merged 29 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2a51436
Enable implicit conversion warnings
joaander Oct 13, 2020
4aa8675
Merge branch 'master' into enable-conversion-warnings
joaander Oct 16, 2020
75516a7
Fix conversion warnings in GPU builds of the core module
joaander Oct 16, 2020
363577c
Compile MD module with no warnings.
joaander Oct 19, 2020
701447c
Merge branch 'master' into enable-conversion-warnings
joaander Oct 20, 2020
a315465
Enable warnings in nvcc compilation
joaander Oct 21, 2020
46dc9af
Merge branch 'master' into enable-conversion-warnings
joaander Dec 4, 2020
0971079
Fix warnings in DEM and EAM
joaander Dec 7, 2020
32dc39e
Fix warnings in MPCD
joaander Dec 7, 2020
6eb35fd
Start fixing warnings in HPMC
joaander Dec 7, 2020
dca5587
Merge branch 'master' into enable-conversion-warnings
joaander Dec 10, 2020
23bebbe
Remove conversion warnings in HPMC
joaander Dec 11, 2020
f1cf390
Fix another round of warnings with ENABLE_GPU=on
joaander Dec 11, 2020
950d5a4
Compile with no warnings
joaander Dec 14, 2020
e492844
Fix more warnings on clang11
joaander Dec 14, 2020
e9ba5b6
Create warning to test CI
joaander Dec 14, 2020
edf6167
Make warnings errors in CI
joaander Dec 14, 2020
7707f92
Work around more compiler warnings
joaander Dec 14, 2020
6441f78
Work around more compiler warnings
joaander Dec 14, 2020
353f018
Fix another compiler warning
joaander Dec 14, 2020
00533dd
Fix another warning
joaander Dec 14, 2020
26c499e
Test with verbose compiles
joaander Dec 14, 2020
ef4addb
Fix last warnings
joaander Dec 14, 2020
8adf3f1
Disable warnings in thrust and cub
joaander Dec 15, 2020
98bd253
Fix more warnings
joaander Dec 15, 2020
b6e1e44
Solve remaining warnings
joaander Dec 15, 2020
33b02bc
Merge branch 'master' into enable-conversion-warnings
joaander Dec 15, 2020
d7c66b1
Use latest neighbor submodule.
joaander Dec 15, 2020
5f0f657
Merge branch 'master' into enable-conversion-warnings
joaander Dec 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .azp/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ variables:
ctest_stride: 1
mpiexec_timeout: 3000
suite_name: $(Agent.JobName)
cxxflags: "-Werror"

jobs:
- job: linux_cpu
Expand Down
2 changes: 1 addition & 1 deletion CMake/hoomd/HOOMDCUDASetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MARK_AS_ADVANCED(ALWAYS_USE_MANAGED_MEMORY)
if (ENABLE_HIP)
if (HIP_PLATFORM STREQUAL "nvcc")
# supress warnings in random123
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --diag_suppress=code_is_unreachable")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --diag_suppress=code_is_unreachable -Xcompiler=-Wall -Xcompiler=-Wconversion")

# setup nvcc to build for all CUDA architectures. Allow user to modify the list if desired
if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER 8.99)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ set(CMAKE_CUDA_STANDARD 14)

# Enable compiler warnings on gcc and clang (common compilers used by developers)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unknown-pragmas")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wno-sign-conversion -Wno-unknown-pragmas -Wno-deprecated-declarations")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
endif()

Expand Down
3 changes: 2 additions & 1 deletion hoomd.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
"*.cuh": "cpp",
"*.in": "cpp",
"cfenv": "cpp",
"fft": "cpp"
"fft": "cpp",
"__nullptr": "cpp"
},
"cSpell.words": [
"Frenkel",
Expand Down
2 changes: 1 addition & 1 deletion hoomd/Autotuner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ unsigned int Autotuner::computeOptimalParameter()
float sum = 0.0f;
for (std::vector<float>::iterator it = v.begin(); it != v.end(); ++it)
sum += *it;
m_sample_median[i] = sum/v.size();
m_sample_median[i] = sum/float(v.size());
}
else if (m_mode == mode_max)
{
Expand Down
13 changes: 4 additions & 9 deletions hoomd/BondedGroupData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ BondedGroupData<group_size, Group, name, has_type_mapping>::BondedGroupData(
// offer a default type mapping
for (unsigned int i = 0; i < n_group_types; i++)
{
char suffix[2];
suffix[0] = 'A' + i;
suffix[1] = '\0';

std::string type_name = std::string(name) + std::string(suffix);
m_type_mapping.push_back(type_name);
m_type_mapping.push_back(getDefaultTypeName(i));
}
}

Expand Down Expand Up @@ -854,7 +849,7 @@ void BondedGroupData<group_size, Group, name, has_type_mapping>::rebuildGPUTable

// allocate scratch buffers
CachedAllocator& alloc = m_exec_conf->getCachedAllocator();
unsigned int tmp_size = m_groups.size()*group_size;
size_t tmp_size = m_groups.size()*group_size;
unsigned int nptl = m_pdata->getN()+m_pdata->getNGhosts();
ScopedAllocation<unsigned int> d_scratch_g(alloc, tmp_size);
ScopedAllocation<unsigned int> d_scratch_idx(alloc, tmp_size);
Expand Down Expand Up @@ -1094,7 +1089,7 @@ void BondedGroupData<group_size, Group, name, has_type_mapping>::moveParticleGro

MPI_Status stat;
MPI_Request req;
unsigned int num = send_groups.size();
unsigned int num = (unsigned int)send_groups.size();

MPI_Isend(&num, 1, MPI_UNSIGNED, new_rank, 0, m_exec_conf->getMPICommunicator(), &req);
MPI_Wait(&req, &stat);
Expand Down Expand Up @@ -1174,7 +1169,7 @@ void BondedGroupData<group_size, Group, name, has_type_mapping>::moveParticleGro
if (! is_local)
{
// append to end of group data
unsigned int n = m_groups.size();
unsigned int n = (unsigned int)m_groups.size();
m_group_tag.push_back(tag);
m_groups.push_back(members);
m_group_typeval.push_back(typeval);
Expand Down
3 changes: 3 additions & 0 deletions hoomd/BondedGroupData.cu
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
#include "ParticleData.cuh"
#include "BondedGroupData.cuh"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#include <hip/hip_runtime.h>
#include <thrust/sort.h>
#include <thrust/device_ptr.h>
#include <thrust/execution_policy.h>
#pragma GCC diagnostic pop

/*! \file BondedGroupData.cu
\brief Implements the helper functions (GPU version) for updating the GPU bonded group tables
Expand Down
8 changes: 4 additions & 4 deletions hoomd/BondedGroupData.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class BondedGroupData
*/
void removeAllGhostGroups()
{
unsigned int new_size = m_groups.size() - m_n_ghost;
unsigned int new_size = (unsigned int)m_groups.size() - m_n_ghost;
reallocate(new_size);
m_n_ghost = 0;
}
Expand All @@ -279,7 +279,7 @@ class BondedGroupData
*/
void addGhostGroups(unsigned int ngroup)
{
unsigned int new_size = m_groups.size()+ngroup;
unsigned int new_size = (unsigned int)m_groups.size() + ngroup;
reallocate(new_size);
m_n_ghost += ngroup;
}
Expand All @@ -300,7 +300,7 @@ class BondedGroupData
//! Get the number of group types
unsigned int getNTypes() const
{
return m_type_mapping.size();
return (unsigned int)m_type_mapping.size();
}

//! Return name of this template
Expand Down Expand Up @@ -678,7 +678,7 @@ class BondedGroupData
//! Resize internal tables
/*! \param new_size New size of local group tables, new_size = n_local + n_ghost
*/
void reallocate(unsigned int new_size)
void reallocate(size_t new_size)
{
m_groups.resize(new_size);
m_group_typeval.resize(new_size);
Expand Down
16 changes: 8 additions & 8 deletions hoomd/BoxDim.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,25 +299,25 @@ BoxDim
#ifdef __HIPCC__
if (m_periodic.z)
{
Scalar img = rintf(w.z * m_Linv.z);
Scalar img = rint(w.z * m_Linv.z);
w.z -= L.z * img;
w.y -= L.z * m_yz * img;
w.x -= L.z * m_xz * img;
}

if (m_periodic.y)
{
Scalar img = rintf(w.y * m_Linv.y);
Scalar img = rint(w.y * m_Linv.y);
w.y -= L.y * img;
w.x -= L.y * m_xy * img;
}

if (m_periodic.x)
{
w.x -= L.x * rintf(w.x * m_Linv.x);
w.x -= L.x * rint(w.x * m_Linv.x);
}
#else
// on the cpu, branches are faster than calling rintf
// on the cpu, branches are faster than calling rint
if (m_periodic.z)
{
if (w.z >= m_hi.z)
Expand All @@ -338,13 +338,13 @@ BoxDim
{
if (w.y >= m_hi.y)
{
int i = (w.y*m_Linv.y+Scalar(0.5));
int i = int(w.y*m_Linv.y+Scalar(0.5));
w.y -= (Scalar)i*L.y;
w.x -= (Scalar)i*L.y * m_xy;
}
else if (w.y < m_lo.y)
{
int i = (-w.y*m_Linv.y+Scalar(0.5));
int i = int(-w.y*m_Linv.y+Scalar(0.5));
w.y += (Scalar)i*L.y;
w.x += (Scalar)i*L.y * m_xy;
}
Expand All @@ -354,12 +354,12 @@ BoxDim
{
if (w.x >= m_hi.x)
{
int i = (w.x*m_Linv.x+Scalar(0.5));
int i = int(w.x*m_Linv.x+Scalar(0.5));
w.x -= (Scalar)i*L.x;
}
else if (w.x < m_lo.x)
{
int i = (-w.x*m_Linv.x+Scalar(0.5));
int i = int(-w.x*m_Linv.x+Scalar(0.5));
w.x += (Scalar)i*L.x;
}
}
Expand Down
23 changes: 23 additions & 0 deletions hoomd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ set(_hoomd_sources Analyzer.cc
filter/export_filters.cc
)

# ignore conversion warnings in external files
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set_source_files_properties(extern/kiss_fft.cc PROPERTIES COMPILE_FLAGS "-Wno-conversion -Wno-float-conversion")
set_source_files_properties(extern/vmdsock.cc PROPERTIES COMPILE_FLAGS "-Wno-conversion")
set_source_files_properties(extern/imd.cc PROPERTIES COMPILE_FLAGS "-Wno-conversion")
endif()

set(_hoomd_headers
AABB.h
AABBTree.h
Expand Down Expand Up @@ -190,6 +197,17 @@ endforeach(getar_src)
# quiet some warnings locally on files we can't modify
if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set_source_files_properties("extern/libgetar/vogl_miniz/vogl_miniz.cpp" PROPERTIES COMPILE_FLAGS "-Wno-strict-aliasing")
set_source_files_properties(extern/libgetar/src/DirArchive.cpp PROPERTIES COMPILE_FLAGS "-Wno-conversion")
set_source_files_properties(extern/libgetar/src/SqliteArchive.cpp PROPERTIES COMPILE_FLAGS "-Wno-conversion")
set_source_files_properties(extern/libgetar/src/TarArchive.cpp PROPERTIES COMPILE_FLAGS "-Wno-conversion")
set_source_files_properties(extern/libgetar/src/ZipArchive.cpp PROPERTIES COMPILE_FLAGS "-Wno-conversion")
set_source_files_properties(extern/libgetar/src/lz4.c PROPERTIES COMPILE_FLAGS "-Wno-conversion")
set_source_files_properties(extern/libgetar/miniz/miniz.cpp PROPERTIES COMPILE_FLAGS "-Wno-conversion")
if (CMAKE_COMPILER_IS_GNUCXX)
set_source_files_properties(extern/libgetar/sqlite3/sqlite3.c PROPERTIES COMPILE_FLAGS "-Wno-conversion -Wno-return-local-addr")
else()
set_source_files_properties(extern/libgetar/sqlite3/sqlite3.c PROPERTIES COMPILE_FLAGS "-Wno-conversion")
endif()
endif()

if (ENABLE_HIP)
Expand All @@ -206,6 +224,11 @@ add_library(HOOMD::_hoomd ALIAS _hoomd)
# add quick hull as its own library so that it's symbols can be public
add_library (quickhull SHARED extern/quickhull/QuickHull.cpp)

# ignore conversion warnings in quickull
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(quickhull PRIVATE "-Wno-conversion;-Wno-pessimizing-move")
endif()

# link the library to its dependencies
target_link_libraries(_hoomd PUBLIC pybind11::pybind11 quickhull Eigen3::Eigen)

Expand Down
14 changes: 7 additions & 7 deletions hoomd/CachedAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class __attribute__((visibility("default"))) CachedAllocator
* \returns a pointer to the allocated buffer
*/
template<typename T>
T *getTemporaryBuffer(unsigned int num_elements);
T *getTemporaryBuffer(size_t num_elements);

// Specifically allocate a char* buffer
char *allocate(std::ptrdiff_t num_bytes)
Expand Down Expand Up @@ -106,8 +106,8 @@ class __attribute__((visibility("default"))) CachedAllocator

bool m_managed; //! True if we use unified memory

unsigned int m_num_bytes_tot;
unsigned int m_max_cached_bytes;
size_t m_num_bytes_tot;
size_t m_max_cached_bytes;
float m_cache_reltol;

free_blocks_type m_free_blocks;
Expand Down Expand Up @@ -163,7 +163,7 @@ class ScopedAllocation
{
public:
//! Copy constructor
ScopedAllocation(CachedAllocator& alloc, unsigned int num_elements);
ScopedAllocation(CachedAllocator& alloc, size_t num_elements);

//! Destructor
~ScopedAllocation();
Expand All @@ -184,15 +184,15 @@ class ScopedAllocation
};

template<typename T>
T* CachedAllocator::getTemporaryBuffer(unsigned int num_elements)
T* CachedAllocator::getTemporaryBuffer(size_t num_elements)
{
std::ptrdiff_t num_bytes = sizeof(T)*num_elements;
char *result = 0;

// short-cut to avoid storing duplicate NULL ptrs in the map
if (!num_bytes) return (T*)NULL;

unsigned int num_allocated_bytes = num_bytes;
size_t num_allocated_bytes = num_bytes;

// search the cache for a free block
free_blocks_type::iterator free_block = m_free_blocks.lower_bound(num_bytes);
Expand Down Expand Up @@ -264,7 +264,7 @@ T* CachedAllocator::getTemporaryBuffer(unsigned int num_elements)

//! Constructor
template<typename T>
ScopedAllocation<T>::ScopedAllocation(CachedAllocator& alloc, unsigned int num_elements)
ScopedAllocation<T>::ScopedAllocation(CachedAllocator& alloc, size_t num_elements)
: m_alloc(alloc)
{
data = m_alloc.getTemporaryBuffer<T>(num_elements);
Expand Down
3 changes: 3 additions & 0 deletions hoomd/CellListGPU.cu
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

#include "CellListGPU.cuh"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#include <thrust/sort.h>
#include <thrust/device_ptr.h>
#pragma GCC diagnostic pop

/*! \file CellListGPU.cu
\brief Defines GPU kernel code for cell list generation on the GPU
Expand Down
Loading