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

atomic_fetch_add fix for Kokkos::Serial #157

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 15 additions & 15 deletions src/common/KokkosKernels_HashmapAccumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ struct HashmapAccumulator{
(*used_size_) += num_writes;
});
*/
size_type my_write_index = Kokkos::atomic_fetch_add(used_size_, 1);
size_type my_write_index = Kokkos::atomic_fetch_add(used_size_, (size_type)1);


if (my_write_index >= max_value_size_) {
Expand All @@ -749,7 +749,7 @@ struct HashmapAccumulator{
values[my_write_index] = value;
size_type hashbeginning = Kokkos::atomic_exchange(hash_begins+hash, my_write_index);
if (hashbeginning == -1){
used_hashes[Kokkos::atomic_fetch_add(used_hash_size, 1)] = hash;
used_hashes[Kokkos::atomic_fetch_add(used_hash_size, (size_type)1)] = hash;
}
hash_nexts[my_write_index] = hashbeginning;
return INSERT_SUCCESS;
Expand Down Expand Up @@ -821,7 +821,7 @@ struct HashmapAccumulator{
if (used_size_[0] >= max_value_size_){
return INSERT_FULL;
}
size_type my_write_index = Kokkos::atomic_fetch_add(used_size_, 1);
size_type my_write_index = Kokkos::atomic_fetch_add(used_size_, (size_type)1);


if (my_write_index >= max_value_size_) {
Expand Down Expand Up @@ -886,7 +886,7 @@ struct HashmapAccumulator{

size_type my_write_index = 0;
if (key_not_found){
my_write_index = Kokkos::atomic_fetch_add(used_size_, 1);
my_write_index = Kokkos::atomic_fetch_add(used_size_, (size_type)1);
//my_write_index = used_size_[0]++;
}
else {
Expand All @@ -910,7 +910,7 @@ struct HashmapAccumulator{
hash_nexts[my_write_index] = hashbeginning;

if (hashbeginning == -1){
used_hashes[Kokkos::atomic_fetch_add(used_hash_size, 1)] = hash;
used_hashes[Kokkos::atomic_fetch_add(used_hash_size, (size_type)1)] = hash;
}
return INSERT_SUCCESS;
}
Expand Down Expand Up @@ -975,7 +975,7 @@ struct HashmapAccumulator{

size_type my_write_index = 0;
if (key_not_found){
my_write_index = Kokkos::atomic_fetch_add(used_size_, 1);
my_write_index = Kokkos::atomic_fetch_add(used_size_, (size_type)1);
//my_write_index = used_size_[0]++;
}
else {
Expand Down Expand Up @@ -1103,7 +1103,7 @@ struct HashmapAccumulator{
//md note somehow commented part
if (initial_hash_begin == end_of_link || (keys[initial_hash_begin] > key)){
{
volatile size_type my_write_index = Kokkos::atomic_fetch_add(used_size_, 1);
volatile size_type my_write_index = Kokkos::atomic_fetch_add(used_size_, (size_type)1);
#if 0
if (print) std::cout << "\t 8 my_write_index :" << my_write_index << " max_value_size_:" << max_value_size_ << std::endl;
#endif
Expand Down Expand Up @@ -1255,7 +1255,7 @@ struct HashmapAccumulator{
#endif
//we need to insert it to beginning.
{
size_type my_write_index = Kokkos::atomic_fetch_add(used_size_, 1);
size_type my_write_index = Kokkos::atomic_fetch_add(used_size_, (size_type)1);
#if 0
if (print) std::cout << "\t 13 my_write_index :" << my_write_index << " max_value_size_:" << max_value_size_ << std::endl;
#endif
Expand Down Expand Up @@ -1708,7 +1708,7 @@ struct HashmapAccumulator{
values[my_write_index] = value;
size_type hashbeginning = Kokkos::atomic_exchange(hash_begins+hash, my_write_index);
if (hashbeginning == -1){
used_hashes[Kokkos::atomic_fetch_add(used_hash_size, 1)] = hash;
used_hashes[Kokkos::atomic_fetch_add(used_hash_size, (size_type)1)] = hash;
}
hash_nexts[my_write_index] = hashbeginning;
vals_counts_gmem[my_write_index] = 1;
Expand Down Expand Up @@ -1742,7 +1742,7 @@ struct HashmapAccumulator{
return INSERT_SUCCESS;
}

size_type my_write_index = Kokkos::atomic_fetch_add(used_size_,1 );
size_type my_write_index = Kokkos::atomic_fetch_add(used_size_, (size_type)1);

if (my_write_index >= max_value_size_) {
return INSERT_FULL;
Expand Down Expand Up @@ -1790,7 +1790,7 @@ struct HashmapAccumulator{
return INSERT_SUCCESS;
}

size_type my_write_index = Kokkos::atomic_fetch_add(used_size_,1 );
size_type my_write_index = Kokkos::atomic_fetch_add(used_size_,(size_type)1);

if (my_write_index >= max_value_size_) {
return INSERT_FULL;
Expand Down Expand Up @@ -1877,7 +1877,7 @@ struct HashmapAccumulator{
return INSERT_SUCCESS;
}

size_type my_write_index = Kokkos::atomic_fetch_add(used_size_,1 );
size_type my_write_index = Kokkos::atomic_fetch_add(used_size_,(size_type)1);

if (my_write_index >= max_value_size_) {
return INSERT_FULL;
Expand All @@ -1888,7 +1888,7 @@ struct HashmapAccumulator{
values[my_write_index] = value;
size_type hashbeginning = Kokkos::atomic_exchange(hash_begins+hash, my_write_index);
if (hashbeginning == -1){
used_hashes[Kokkos::atomic_fetch_add(used_hash_size, 1)] = hash;
used_hashes[Kokkos::atomic_fetch_add(used_hash_size, (size_type)1)] = hash;
}
hash_nexts[my_write_index] = hashbeginning;
return INSERT_SUCCESS;
Expand Down Expand Up @@ -1921,7 +1921,7 @@ struct HashmapAccumulator{
return INSERT_SUCCESS;
}

size_type my_write_index = Kokkos::atomic_fetch_add(used_size_,1 );
size_type my_write_index = Kokkos::atomic_fetch_add(used_size_, (size_type)1 );

if (my_write_index >= max_value_size_) {
return INSERT_FULL;
Expand All @@ -1932,7 +1932,7 @@ struct HashmapAccumulator{
//values[my_write_index] = value;
size_type hashbeginning = Kokkos::atomic_exchange(hash_begins+hash, my_write_index);
if (hashbeginning == -1){
used_hashes[Kokkos::atomic_fetch_add(used_hash_size, 1)] = hash;
used_hashes[Kokkos::atomic_fetch_add(used_hash_size, (size_type)1)] = hash;
}
hash_nexts[my_write_index] = hashbeginning;
return INSERT_SUCCESS;
Expand Down
4 changes: 3 additions & 1 deletion src/common/KokkosKernels_PrintUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ namespace Impl{
template <typename in_lno_view_t,
typename out_lno_view_t>
struct Histogram{
typedef typename out_lno_view_t::value_type atomic_increment_type;

in_lno_view_t inview;
out_lno_view_t outview;
Histogram (in_lno_view_t inview_, out_lno_view_t outview_): inview(inview_), outview(outview_){}

KOKKOS_INLINE_FUNCTION
void operator()(const size_t &ii) const {
Kokkos::atomic_fetch_add(&(outview(inview(ii))),1);
Kokkos::atomic_fetch_add(&(outview(inview(ii))),(atomic_increment_type)1);
}
};

Expand Down
23 changes: 13 additions & 10 deletions src/common/KokkosKernels_SparseUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct TransposeMatrix{

typedef typename in_nnz_view_t::non_const_value_type nnz_lno_t;
typedef typename in_row_view_t::non_const_value_type size_type;
typedef typename out_row_view_t::value_type atomic_increment_type;


typename in_nnz_view_t::non_const_value_type num_rows;
Expand Down Expand Up @@ -135,7 +136,7 @@ struct TransposeMatrix{
[&] (nnz_lno_t i) {
const size_type adjind = i + col_begin;
const nnz_lno_t colIndex = adj[adjind];
Kokkos::atomic_fetch_add(&(t_xadj(colIndex)),1);
Kokkos::atomic_fetch_add(&(t_xadj(colIndex)),(atomic_increment_type)1);
});
});
}
Expand All @@ -157,7 +158,7 @@ struct TransposeMatrix{
[&] (nnz_lno_t i) {
const size_type adjind = i + col_begin;
const nnz_lno_t colIndex = adj[adjind];
const size_type pos = Kokkos::atomic_fetch_add(&(tmp_txadj(colIndex)),1);
const size_type pos = Kokkos::atomic_fetch_add(&(tmp_txadj(colIndex)),(atomic_increment_type)1);

t_adj(pos) = row_index;
if (transpose_values){
Expand Down Expand Up @@ -300,7 +301,7 @@ struct Fill_Reverse_Scale_Functor{
forward_type fm = forward_map[ii];
fm = fm << multiply_shift_for_scale;
fm += ii >> division_shift_for_bucket;
Kokkos::atomic_fetch_add( &(reverse_map_xadj(fm)), 1);
Kokkos::atomic_fetch_add( &(reverse_map_xadj(fm)), (reverse_type)1);
}

KOKKOS_INLINE_FUNCTION
Expand All @@ -309,7 +310,7 @@ struct Fill_Reverse_Scale_Functor{

fm = fm << multiply_shift_for_scale;
fm += ii >> division_shift_for_bucket;
const reverse_type future_index = Kokkos::atomic_fetch_add( &(reverse_map_xadj(fm )), 1);
const reverse_type future_index = Kokkos::atomic_fetch_add( &(reverse_map_xadj(fm )), (reverse_type)1);
reverse_map_adj(future_index) = ii;
}
};
Expand Down Expand Up @@ -358,13 +359,13 @@ struct Reverse_Map_Functor{
KOKKOS_INLINE_FUNCTION
void operator()(const CountTag&, const size_t &ii) const {
forward_type fm = forward_map[ii];
Kokkos::atomic_fetch_add( &(reverse_map_xadj(fm)), 1);
Kokkos::atomic_fetch_add( &(reverse_map_xadj(fm)), (reverse_type)1);
}

KOKKOS_INLINE_FUNCTION
void operator()(const FillTag&, const size_t &ii) const {
forward_type c = forward_map[ii];
const reverse_type future_index = Kokkos::atomic_fetch_add( &(reverse_map_xadj(c)), 1);
const reverse_type future_index = Kokkos::atomic_fetch_add( &(reverse_map_xadj(c)), (reverse_type)1);
reverse_map_adj(future_index) = ii;
}
};
Expand Down Expand Up @@ -1646,6 +1647,7 @@ void kk_create_incidence_matrix_from_lower_triangle(

typedef typename row_map_view_t::non_const_value_type size_type;
typedef typename cols_view_t::non_const_value_type lno_t;
typedef typename out_row_map_view_t::value_type atomic_increment_type;



Expand All @@ -1657,7 +1659,7 @@ void kk_create_incidence_matrix_from_lower_triangle(

Kokkos::parallel_for(my_exec_space(0, ne),
KOKKOS_LAMBDA(const lno_t& i) {
Kokkos::atomic_fetch_add(&(out_rowmap[in_lower_entries[i]]),1);
Kokkos::atomic_fetch_add(&(out_rowmap[in_lower_entries[i]]),(atomic_increment_type)1);
});

exec_space::fence();
Expand Down Expand Up @@ -1694,7 +1696,7 @@ void kk_create_incidence_matrix_from_lower_triangle(
Kokkos::parallel_for(my_exec_space(0, ne),
KOKKOS_LAMBDA(const size_type& edge_ind) {
lno_t col = in_lower_entries[edge_ind];
size_type write_ind = Kokkos::atomic_fetch_add(&(out_rowmap_copy(col)),1);
size_type write_ind = Kokkos::atomic_fetch_add(&(out_rowmap_copy(col)),(atomic_increment_type)1);
out_entries[write_ind] = edge_ind;
});

Expand Down Expand Up @@ -1737,6 +1739,7 @@ void kk_create_incidence_matrix_from_original_matrix(

typedef typename row_map_view_t::non_const_value_type size_type;
typedef typename cols_view_t::non_const_value_type lno_t;
typedef typename out_row_map_view_t::value_type atomic_increment_type;
typedef Kokkos::RangePolicy<exec_space> my_exec_space;
lno_t * perm = permutation.data();
const size_type ne = in_entries.dimension_0();
Expand Down Expand Up @@ -1786,8 +1789,8 @@ void kk_create_incidence_matrix_from_original_matrix(
lno_t col_perm = col;
if (perm) col_perm = perm[col];
if (row_perm > col_perm){
size_type row_write_index = Kokkos::atomic_fetch_add(&(out_rowmap_copy[row]),1);
size_type col_write_index = Kokkos::atomic_fetch_add(&(out_rowmap_copy[col]),1);
size_type row_write_index = Kokkos::atomic_fetch_add(&(out_rowmap_copy[row]),(atomic_increment_type)1);
size_type col_write_index = Kokkos::atomic_fetch_add(&(out_rowmap_copy[col]),(atomic_increment_type)1);
out_entries[row_write_index] = used_edge_index + used_count;
out_entries[col_write_index] = used_edge_index + used_count;
++used_count;
Expand Down
34 changes: 19 additions & 15 deletions src/common/KokkosKernels_Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ template <typename in_lno_row_view_t,
typename team_member>
struct FillSymmetricEdgesHashMap{
typedef typename in_lno_row_view_t::value_type idx;
typedef typename out_lno_row_view_t::value_type atomic_increment_type;
idx num_rows;
idx nnz;
in_lno_row_view_t xadj;
Expand Down Expand Up @@ -244,22 +245,22 @@ struct FillSymmetricEdgesHashMap{
Kokkos::UnorderedMapInsertResult r = umap.insert(Kokkos::pair<idx, idx>(colIndex, ii));
if (r.success()){

Kokkos::atomic_fetch_add(&(pre_pps(ii)),1);
Kokkos::atomic_fetch_add(&(pre_pps(ii)),(atomic_increment_type)1);

Kokkos::atomic_fetch_add(&(pre_pps(colIndex)),1);
Kokkos::atomic_fetch_add(&(pre_pps(colIndex)),(atomic_increment_type)1);
}
}
else if (colIndex > ii){

Kokkos::UnorderedMapInsertResult r = umap.insert(Kokkos::pair<idx, idx>(ii, colIndex));
if (r.success()){
Kokkos::atomic_fetch_add(&(pre_pps(colIndex)),1);
Kokkos::atomic_fetch_add(&(pre_pps(colIndex)),(atomic_increment_type)1);

Kokkos::atomic_fetch_add(&(pre_pps(ii)),1);
Kokkos::atomic_fetch_add(&(pre_pps(ii)),(atomic_increment_type)1);
}
}
else {
Kokkos::atomic_fetch_add(&(pre_pps(ii)),1);
Kokkos::atomic_fetch_add(&(pre_pps(ii)),(atomic_increment_type)1);
}
}

Expand All @@ -275,6 +276,7 @@ template <typename in_lno_row_view_t,
typename team_member>
struct FillSymmetricLowerEdgesHashMap{
typedef typename in_lno_row_view_t::value_type idx;
typedef typename out_lno_row_view_t::value_type atomic_increment_type;
idx num_rows;
idx nnz;
in_lno_row_view_t xadj;
Expand Down Expand Up @@ -312,14 +314,14 @@ struct FillSymmetricLowerEdgesHashMap{
Kokkos::UnorderedMapInsertResult r = umap.insert(Kokkos::pair<idx, idx>(colIndex, ii));
if (r.success()){

Kokkos::atomic_fetch_add(&(pre_pps(colIndex)),1);
Kokkos::atomic_fetch_add(&(pre_pps(colIndex)),(atomic_increment_type)1);
}
}
else if (colIndex > ii){

Kokkos::UnorderedMapInsertResult r = umap.insert(Kokkos::pair<idx, idx>(ii, colIndex));
if (r.success()){
Kokkos::atomic_fetch_add(&(pre_pps(ii)),1);
Kokkos::atomic_fetch_add(&(pre_pps(ii)),(atomic_increment_type)1);
}
}

Expand All @@ -337,6 +339,7 @@ template <typename in_lno_row_view_t,
typename team_member_t>
struct FillSymmetricCRS_HashMap{
typedef typename in_lno_row_view_t::value_type idx;
typedef typename out_lno_row_view_t::value_type atomic_increment_type;
idx num_rows;
idx nnz;
in_lno_row_view_t xadj;
Expand Down Expand Up @@ -372,22 +375,22 @@ struct FillSymmetricCRS_HashMap{
if (colIndex < num_rows){
if (colIndex < ii){
if (umap.insert(Kokkos::pair<idx, idx>(colIndex, ii)).success()){
idx cAdjInd = Kokkos::atomic_fetch_add(&(pre_pps(colIndex)),1);
idx iAdjInd = Kokkos::atomic_fetch_add(&(pre_pps(ii)),1);
idx cAdjInd = Kokkos::atomic_fetch_add(&(pre_pps(colIndex)),(atomic_increment_type)1);
idx iAdjInd = Kokkos::atomic_fetch_add(&(pre_pps(ii)),(atomic_increment_type)1);
sym_adj[cAdjInd] = ii;
sym_adj[iAdjInd] = colIndex;
}
}
else if (colIndex > ii){
if (umap.insert(Kokkos::pair<idx, idx>(ii, colIndex)).success()){
idx cAdjInd = Kokkos::atomic_fetch_add(&(pre_pps(colIndex)),1);
idx iAdjInd = Kokkos::atomic_fetch_add(&(pre_pps(ii)),1);
idx cAdjInd = Kokkos::atomic_fetch_add(&(pre_pps(colIndex)),(atomic_increment_type)1);
idx iAdjInd = Kokkos::atomic_fetch_add(&(pre_pps(ii)),(atomic_increment_type)1);
sym_adj[cAdjInd] = ii;
sym_adj[iAdjInd] = colIndex;
}
}
else {
idx cAdjInd = Kokkos::atomic_fetch_add(&(pre_pps(colIndex)),1);
idx cAdjInd = Kokkos::atomic_fetch_add(&(pre_pps(colIndex)),(atomic_increment_type)1);
sym_adj[cAdjInd] = ii;
}
}
Expand All @@ -405,6 +408,7 @@ template <typename in_lno_row_view_t,
typename team_member_t>
struct FillSymmetricEdgeList_HashMap{
typedef typename in_lno_row_view_t::value_type idx;
typedef typename out_lno_row_view_t::value_type atomic_increment_type;
idx num_rows;
idx nnz;
in_lno_row_view_t xadj;
Expand Down Expand Up @@ -443,14 +447,14 @@ struct FillSymmetricEdgeList_HashMap{
if (colIndex < num_rows){
if (colIndex < ii){
if (umap.insert(Kokkos::pair<idx, idx>(colIndex, ii)).success()){
idx cAdjInd = Kokkos::atomic_fetch_add(&(pps(colIndex)),1);
idx cAdjInd = Kokkos::atomic_fetch_add(&(pps(colIndex)),(atomic_increment_type)1);
sym_src[cAdjInd] = colIndex;
sym_dst[cAdjInd] = ii;
}
}
else if (colIndex > ii){
if (umap.insert(Kokkos::pair<idx, idx>(ii, colIndex)).success()){
idx cAdjInd = Kokkos::atomic_fetch_add(&(pps(ii)),1);
idx cAdjInd = Kokkos::atomic_fetch_add(&(pps(ii)),(atomic_increment_type)1);
sym_src[cAdjInd] = ii;
sym_dst[cAdjInd] = colIndex;
}
Expand Down Expand Up @@ -486,7 +490,7 @@ struct Reverse_Map_Init{
KOKKOS_INLINE_FUNCTION
void operator()(const size_t &ii) const {
forward_type fm = forward_map[ii];
Kokkos::atomic_fetch_add( &(reverse_map_xadj(fm)), 1);
Kokkos::atomic_fetch_add( &(reverse_map_xadj(fm)), (reverse_type)1);
}

/*
Expand Down
Loading