Skip to content

Commit

Permalink
Add cppcoreguidelines-pro-type-cstyle-cast
Browse files Browse the repository at this point in the history
  • Loading branch information
masterleinad committed Jul 8, 2021
1 parent 7b5ffcc commit 422c820
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Checks: '-*,kokkos-*,modernize-use-using,modernize-use-nullptr'
Checks: '-*,kokkos-*,modernize-use-using,modernize-use-nullptr,cppcoreguidelines-pro-type-cstyle-cast'
FormatStyle: file
HeaderFilterRegex: '.*/*.hpp'
2 changes: 1 addition & 1 deletion containers/src/impl/Kokkos_Functional_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ uint32_t fmix32(uint32_t h) {

KOKKOS_INLINE_FUNCTION
uint32_t MurmurHash3_x86_32(const void* key, int len, uint32_t seed) {
const uint8_t* data = (const uint8_t*)key;
const uint8_t* data = static_cast<const uint8_t*>(key);
const int nblocks = len / 4;

uint32_t h1 = seed;
Expand Down
3 changes: 2 additions & 1 deletion core/perf_test/PerfTest_ViewAllocate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ void run_allocateview_tests(int N, int R) {
{
Kokkos::Timer timer;
for (int r = 0; r < R; r++) {
double* a_ptr = (double*)Kokkos::kokkos_malloc("A", sizeof(double) * N8);
double* a_ptr =
static_cast<double*>(Kokkos::kokkos_malloc("A", sizeof(double) * N8));
Kokkos::parallel_for(
N8, KOKKOS_LAMBDA(const int& i) { a_ptr[i] = 0.0; });
Kokkos::fence();
Expand Down
8 changes: 4 additions & 4 deletions core/perf_test/test_mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct TestFunctor {

const unsigned size_alloc = chunk * (1 + (j % chunk_span));

ptrs(j) = (uintptr_t)pool.allocate(size_alloc);
ptrs(j) = reinterpret_cast<uintptr_t>(pool.allocate(size_alloc));

if (ptrs(j)) ++update;
}
Expand Down Expand Up @@ -129,7 +129,7 @@ struct TestFunctor {

const unsigned size_alloc = chunk * (1 + (j % chunk_span));

pool.deallocate((void*)ptrs(j), size_alloc);
pool.deallocate(reinterpret_cast<void*>(ptrs(j)), size_alloc);
}
}

Expand All @@ -153,9 +153,9 @@ struct TestFunctor {
for (unsigned k = 0; k < repeat_inner; ++k) {
const unsigned size_alloc = chunk * (1 + (j % chunk_span));

pool.deallocate((void*)ptrs(j), size_alloc);
pool.deallocate(reinterpret_cast<void*>(ptrs(j)), size_alloc);

ptrs(j) = (uintptr_t)pool.allocate(size_alloc);
ptrs(j) = reinterpret_cast<uintptr_t>(pool.allocate(size_alloc));

if (0 == ptrs(j)) update++;
}
Expand Down
7 changes: 4 additions & 3 deletions core/src/Cuda/Kokkos_Cuda_Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int cuda_kernel_arch() {
int arch = 0;
int *d_arch = nullptr;

cudaMalloc((void **)&d_arch, sizeof(int));
cudaMalloc(reinterpret_cast<void **>(&d_arch), sizeof(int));
cudaMemcpy(d_arch, &arch, sizeof(int), cudaMemcpyDefault);

query_cuda_kernel_arch<<<1, 1>>>(d_arch);
Expand Down Expand Up @@ -537,8 +537,9 @@ Kokkos::Cuda::initialize WARNING: Cuda is allocating into UVMSpace by default
// Allocate a staging buffer for constant mem in pinned host memory
// and an event to avoid overwriting driver for previous kernel launches
if (stream == nullptr) {
CUDA_SAFE_CALL(cudaMallocHost((void **)&constantMemHostStaging,
CudaTraits::ConstantMemoryUsage));
CUDA_SAFE_CALL(
cudaMallocHost(reinterpret_cast<void **>(&constantMemHostStaging),
CudaTraits::ConstantMemoryUsage));

CUDA_SAFE_CALL(cudaEventCreate(&constantMemReusable));
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/Cuda/Kokkos_Cuda_Team.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class CudaTeamMember {
void* scratch_level_1_ptr, const int scratch_level_1_size,
const int arg_league_rank, const int arg_league_size)
: m_team_reduce(shared),
m_team_shared(((char*)shared) + shared_begin, shared_size,
m_team_shared(static_cast<char*>(shared) + shared_begin, shared_size,
scratch_level_1_ptr, scratch_level_1_size),
m_team_reduce_size(shared_begin),
m_league_rank(arg_league_rank),
Expand Down
3 changes: 2 additions & 1 deletion core/src/Kokkos_MemoryPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,8 @@ class MemoryPool {

// Determine which superblock and block
const ptrdiff_t d =
((char *)p) - ((char *)(m_sb_state_array + m_data_offset));
static_cast<char *>(p) -
reinterpret_cast<char *>(m_sb_state_array + m_data_offset);

// Verify contained within the memory pool's superblocks:
const int ok_contains =
Expand Down
8 changes: 4 additions & 4 deletions core/src/Kokkos_ScratchSpace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ class ScratchMemorySpace {
const IntType& size_L0,
void* ptr_L1 = nullptr,
const IntType& size_L1 = 0)
: m_iter_L0((char*)ptr_L0),
m_iter_L1((char*)ptr_L1),
m_end_L0((char*)ptr_L0 + size_L0),
m_end_L1((char*)ptr_L1 + size_L1),
: m_iter_L0(static_cast<char*>(ptr_L0)),
m_iter_L1(static_cast<char*>(ptr_L1)),
m_end_L0(static_cast<char*>(ptr_L0) + size_L0),
m_end_L1(static_cast<char*>(ptr_L1) + size_L1),
m_multiplier(1),
m_offset(0),
m_default_level(0) {}
Expand Down
18 changes: 10 additions & 8 deletions core/src/impl/Kokkos_ConcurrentBitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ struct concurrent_bitset {
// when is full at the atomic_fetch_add(+1)
// then a release occurs before the atomic_fetch_add(-1).

const uint32_t state =
(uint32_t)Kokkos::atomic_fetch_add((volatile int *)buffer, 1);
const uint32_t state = (uint32_t)Kokkos::atomic_fetch_add(
reinterpret_cast<volatile int *>(buffer), 1);

const uint32_t state_error = state_header != (state & state_header_mask);

const uint32_t state_bit_used = state & state_used_mask;

if (state_error || (bit_bound <= state_bit_used)) {
Kokkos::atomic_fetch_add((volatile int *)buffer, -1);
Kokkos::atomic_fetch_add(reinterpret_cast<volatile int *>(buffer), -1);
return state_error ? type(-2, -2) : type(-1, -1);
}

Expand Down Expand Up @@ -222,15 +222,15 @@ struct concurrent_bitset {
// when is full at the atomic_fetch_add(+1)
// then a release occurs before the atomic_fetch_add(-1).

const uint32_t state =
(uint32_t)Kokkos::atomic_fetch_add((volatile int *)buffer, 1);
const uint32_t state = (uint32_t)Kokkos::atomic_fetch_add(
reinterpret_cast<volatile int *>(buffer), 1);

const uint32_t state_error = state_header != (state & state_header_mask);

const uint32_t state_bit_used = state & state_used_mask;

if (state_error || (bit_bound <= state_bit_used)) {
Kokkos::atomic_fetch_add((volatile int *)buffer, -1);
Kokkos::atomic_fetch_add(reinterpret_cast<volatile int *>(buffer), -1);
return state_error ? type(-2, -2) : type(-1, -1);
}

Expand Down Expand Up @@ -300,7 +300,8 @@ struct concurrent_bitset {
// Do not update count until bit clear is visible
Kokkos::memory_fence();

const int count = Kokkos::atomic_fetch_add((volatile int *)buffer, -1);
const int count =
Kokkos::atomic_fetch_add(reinterpret_cast<volatile int *>(buffer), -1);

// Flush the store-release
Kokkos::memory_fence();
Expand Down Expand Up @@ -336,7 +337,8 @@ struct concurrent_bitset {
// Do not update count until bit clear is visible
Kokkos::memory_fence();

const int count = Kokkos::atomic_fetch_add((volatile int *)buffer, -1);
const int count =
Kokkos::atomic_fetch_add(reinterpret_cast<volatile int *>(buffer), -1);

return (count & state_used_mask) - 1;
}
Expand Down
14 changes: 8 additions & 6 deletions core/src/impl/Kokkos_HostThreadTeam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ void HostThreadTeamData::organize_pool(HostThreadTeamData *members[],
}

{
HostThreadTeamData **const pool =
(HostThreadTeamData **)(root_scratch + m_pool_members);
HostThreadTeamData **const pool = reinterpret_cast<HostThreadTeamData **>(
root_scratch + m_pool_members);

// team size == 1, league size == pool_size

Expand Down Expand Up @@ -136,7 +136,8 @@ int HostThreadTeamData::organize_team(const int team_size) {
if (team_size == 1) return 1; // Already organized in teams of one

HostThreadTeamData *const *const pool =
(HostThreadTeamData **)(m_pool_scratch + m_pool_members);
reinterpret_cast<HostThreadTeamData **>(m_pool_scratch +
m_pool_members);

// "league_size" in this context is the number of concurrent teams
// that the pool can accommodate. Excess threads are idle.
Expand Down Expand Up @@ -239,7 +240,8 @@ int HostThreadTeamData::get_work_stealing() noexcept {

if (w.first == -1 && m_steal_rank != m_pool_rank) {
HostThreadTeamData *const *const pool =
(HostThreadTeamData **)(m_pool_scratch + m_pool_members);
reinterpret_cast<HostThreadTeamData **>(m_pool_scratch +
m_pool_members);

// Attempt from beginning failed, try to steal from end of neighbor

Expand Down Expand Up @@ -287,12 +289,12 @@ int HostThreadTeamData::get_work_stealing() noexcept {

if (1 < m_team_size) {
// Must share the work index
*((int volatile *)team_reduce()) = w.first;
*reinterpret_cast<int volatile *>(team_reduce()) = w.first;

team_rendezvous_release();
}
} else if (1 < m_team_size) {
w.first = *((int volatile *)team_reduce());
w.first = *reinterpret_cast<int volatile *>(team_reduce());
}

// May exit because successfully stole work and w is good.
Expand Down
25 changes: 14 additions & 11 deletions core/src/impl/Kokkos_HostThreadTeam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ class HostThreadTeamData {
int mutable m_team_rendezvous_step;

HostThreadTeamData* team_member(int r) const noexcept {
return ((HostThreadTeamData**)(m_pool_scratch +
m_pool_members))[m_team_base + r];
return (reinterpret_cast<HostThreadTeamData**>(
m_pool_scratch + m_pool_members))[m_team_base + r];
}

public:
inline bool team_rendezvous() const noexcept {
int* ptr = (int*)(m_team_scratch + m_team_rendezvous);
int* ptr = reinterpret_cast<int*>(m_team_scratch + m_team_rendezvous);
HostBarrier::split_arrive(ptr, m_team_size, m_team_rendezvous_step);
if (m_team_rank != 0) {
HostBarrier::wait(ptr, m_team_size, m_team_rendezvous_step);
Expand All @@ -138,7 +138,7 @@ class HostThreadTeamData {
}

inline bool team_rendezvous(const int source_team_rank) const noexcept {
int* ptr = (int*)(m_team_scratch + m_team_rendezvous);
int* ptr = reinterpret_cast<int*>(m_team_scratch + m_team_rendezvous);
HostBarrier::split_arrive(ptr, m_team_size, m_team_rendezvous_step);
if (m_team_rank != source_team_rank) {
HostBarrier::wait(ptr, m_team_size, m_team_rendezvous_step);
Expand All @@ -150,12 +150,13 @@ class HostThreadTeamData {
}

inline void team_rendezvous_release() const noexcept {
HostBarrier::split_release((int*)(m_team_scratch + m_team_rendezvous),
m_team_size, m_team_rendezvous_step);
HostBarrier::split_release(
reinterpret_cast<int*>(m_team_scratch + m_team_rendezvous), m_team_size,
m_team_rendezvous_step);
}

inline int pool_rendezvous() const noexcept {
int* ptr = (int*)(m_pool_scratch + m_pool_rendezvous);
int* ptr = reinterpret_cast<int*>(m_pool_scratch + m_pool_rendezvous);
HostBarrier::split_arrive(ptr, m_pool_size, m_pool_rendezvous_step);
if (m_pool_rank != 0) {
HostBarrier::wait(ptr, m_pool_size, m_pool_rendezvous_step);
Expand All @@ -167,8 +168,9 @@ class HostThreadTeamData {
}

inline void pool_rendezvous_release() const noexcept {
HostBarrier::split_release((int*)(m_pool_scratch + m_pool_rendezvous),
m_pool_size, m_pool_rendezvous_step);
HostBarrier::split_release(
reinterpret_cast<int*>(m_pool_scratch + m_pool_rendezvous), m_pool_size,
m_pool_rendezvous_step);
}

//----------------------------------------
Expand Down Expand Up @@ -230,7 +232,8 @@ class HostThreadTeamData {
constexpr int pool_size() const { return m_pool_size; }

HostThreadTeamData* pool_member(int r) const noexcept {
return ((HostThreadTeamData**)(m_pool_scratch + m_pool_members))[r];
return (reinterpret_cast<HostThreadTeamData**>(m_pool_scratch +
m_pool_members))[r];
}

//----------------------------------------
Expand Down Expand Up @@ -330,7 +333,7 @@ class HostThreadTeamData {
team_shared_size = align_to_int64(team_shared_size);
// thread_local_size = align_to_int64( thread_local_size );

m_scratch = (int64_t*)alloc_ptr;
m_scratch = static_cast<int64_t*>(alloc_ptr);
m_team_reduce = m_pool_reduce + pool_reduce_size;
m_team_shared = m_team_reduce + team_reduce_size;
m_thread_local = m_team_shared + team_shared_size;
Expand Down
4 changes: 2 additions & 2 deletions core/src/impl/Kokkos_Profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ void initialize(const std::string& profileLibrary) {

char* envProfileLibrary = const_cast<char*>(profileLibrary.c_str());

char* envProfileCopy =
(char*)malloc(sizeof(char) * (strlen(envProfileLibrary) + 1));
char* envProfileCopy = static_cast<char*>(
malloc(sizeof(char) * (strlen(envProfileLibrary) + 1)));
sprintf(envProfileCopy, "%s", envProfileLibrary);

char* profileLibraryName = strtok(envProfileCopy, ";");
Expand Down
2 changes: 1 addition & 1 deletion core/src/impl/Kokkos_Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void SerialInternal::resize_thread_team_data(size_t pool_reduce_bytes,
Kokkos::Impl::throw_runtime_exception(failure.get_error_message());
}

m_thread_team_data.scratch_assign(((char*)ptr), alloc_bytes,
m_thread_team_data.scratch_assign(static_cast<char*>(ptr), alloc_bytes,
pool_reduce_bytes, team_reduce_bytes,
team_shared_bytes, thread_local_bytes);

Expand Down
4 changes: 2 additions & 2 deletions core/unit_test/cuda/TestCuda_Spaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ TEST(cuda, space_access) {

TEST(cuda, uvm) {
if (Kokkos::CudaUVMSpace::available()) {
int *uvm_ptr = (int *)Kokkos::kokkos_malloc<Kokkos::CudaUVMSpace>(
"uvm_ptr", sizeof(int));
int *uvm_ptr = static_cast<int *>(
Kokkos::kokkos_malloc<Kokkos::CudaUVMSpace>("uvm_ptr", sizeof(int)));

*uvm_ptr = 42;

Expand Down
7 changes: 4 additions & 3 deletions core/unit_test/default/TestDefaultDeviceType_d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@
namespace Test {

TEST(defaultdevicetype, malloc) {
int* data = (int*)Kokkos::kokkos_malloc(100 * sizeof(int));
ASSERT_NO_THROW(data = (int*)Kokkos::kokkos_realloc(data, 120 * sizeof(int)));
int* data = static_cast<int*>(Kokkos::kokkos_malloc(100 * sizeof(int)));
ASSERT_NO_THROW(data = static_cast<int*>(
Kokkos::kokkos_realloc(data, 120 * sizeof(int))));
Kokkos::kokkos_free(data);

int* data2 = (int*)Kokkos::kokkos_malloc(0);
int* data2 = static_cast<int*>(Kokkos::kokkos_malloc(0));
ASSERT_EQ(data2, nullptr);
Kokkos::kokkos_free(data2);
}
Expand Down

0 comments on commit 422c820

Please sign in to comment.