Skip to content

Commit

Permalink
minor fix to reset in Attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahdhn committed Nov 20, 2023
1 parent f7bf933 commit ee6ffcc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
8 changes: 5 additions & 3 deletions include/rxmesh/attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class Attribute : public AttributeBase
#pragma omp parallel for
for (int p = 0; p < static_cast<int>(m_rxmesh->get_num_patches());
++p) {
for (int e = 0; e < size(p); ++e) {
for (int e = 0; e < capacity(p); ++e) {
m_h_attr[p][e] = value;
}
}
Expand Down Expand Up @@ -571,11 +571,12 @@ class Attribute : public AttributeBase
{
assert(p_id < m_max_num_patches);
assert(attr < m_num_attributes);
//assert(local_id < size(p_id));

#ifdef __CUDA_ARCH__
assert(local_id < capacity(p_id));
return m_d_attr[p_id][local_id * pitch_x() + attr * pitch_y(p_id)];
#else
assert(local_id < size(p_id));
return m_h_attr[p_id][local_id * pitch_x() + attr * pitch_y(p_id)];
#endif
}
Expand All @@ -594,11 +595,12 @@ class Attribute : public AttributeBase
{
assert(p_id < m_max_num_patches);
assert(attr < m_num_attributes);
//assert(local_id < size(p_id));

#ifdef __CUDA_ARCH__
assert(local_id < capacity(p_id));
return m_d_attr[p_id][local_id * pitch_x() + attr * pitch_y(p_id)];
#else
assert(local_id < size(p_id));
return m_h_attr[p_id][local_id * pitch_x() + attr * pitch_y(p_id)];
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion include/rxmesh/kernels/attribute.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ __global__ void memset_attribute(const Attribute<T, HandleT> attr,
{
uint32_t p_id = blockIdx.x;
if (p_id < num_patches) {
const uint16_t element_per_patch = attr.size(p_id);
const uint16_t element_per_patch = attr.capacity(p_id);
for (uint16_t i = threadIdx.x; i < element_per_patch; i += blockDim.x) {
for (uint32_t j = 0; j < num_attributes; ++j) {
attr(p_id, i, j) = value;
Expand Down
6 changes: 3 additions & 3 deletions include/rxmesh/lp_hashtable.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ struct LPHashTable
/**
* @brief compute current load factor
*/
__host__ __device__ __inline__ float compute_load_factor(LPPair* s_table)
__host__ __device__ __inline__ float compute_load_factor(
LPPair* s_table = nullptr)const
{
auto lf = [&]() {
uint32_t m = 0;
Expand All @@ -211,7 +212,7 @@ struct LPHashTable
* @brief compute current load factor for the stash
*/
__host__ __device__ __inline__ float compute_stash_load_factor(
LPPair* s_stash)
LPPair* s_stash = nullptr)const
{
auto lf = [&]() {
uint32_t m = 0;
Expand All @@ -233,7 +234,6 @@ struct LPHashTable
}



/**
* @brief memcpy the hashtable from host to device, host to host, device to
* host, device to device depending on where the src and this is allocated
Expand Down
18 changes: 14 additions & 4 deletions include/rxmesh/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,30 @@ void copy(const std::vector<T>& src, std::vector<T>& tar, int tar_start = 0)
* @brief Compute the average and standard deviation of an input array
*/
template <typename T>
inline void compute_avg_stddev(const T* arr,
uint32_t size,
double& avg,
double& stddev)
inline void compute_avg_stddev_max_min(const T* arr,
uint32_t size,
double& avg,
double& stddev,
T& max,
T& min)
{
max = std::numeric_limits<T>::min();
min = std::numeric_limits<T>::max();

if (size == 1) {
avg = arr[0];
max = arr[0];
min = arr[0];
stddev = 0;
return;
}
avg = 0;
// compute avg
for (uint32_t i = 0; i < size; i++) {
avg += arr[i];

max = std::max(max, arr[i]);
min = std::min(min, arr[i]);
}
avg /= size;

Expand Down

0 comments on commit ee6ffcc

Please sign in to comment.