Skip to content

Commit

Permalink
Added assert to hardware tile group shared memory library to make sur…
Browse files Browse the repository at this point in the history
…e tile group dimensions are power of two
  • Loading branch information
bornaehsani committed Aug 24, 2020
1 parent 5ba8aef commit d5a0ac4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions software/bsg_manycore_lib/bsg_shared_mem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ namespace bsg_manycore {
* <5> <4> - <11-x-y> - <12 - s> - <y> - <x> - <s-2> - <2>
* Stripe is lowest bits of offset from local dmem
*
* TODO: Assert local offset fits in 12 bits
* TODO: Asser index < array size
* TODO: Assert tile group dimensions are power of two
*/

// log2 is non-constexpr in llvm so we define a custom
Expand All @@ -27,10 +24,20 @@ namespace bsg_manycore {
return val ? 1 + cilog2(val >> 1) : -1;
}

constexpr bool is_powerof2(std::size_t v) {
return v && ((v & (v - 1)) == 0);
}


template <typename TYPE, std::size_t SIZE, std::size_t TG_DIM_X, std::size_t TG_DIM_Y, std::size_t STRIPE_SIZE=1>
class TileGroupSharedMem {
public:

// Harware tile group shared memory is only supported in tile groups
// with power of 2 x,y dimensions
static_assert (is_powerof2(TG_DIM_X), "While using hardware shared memory, tile group X dimension should be power of 2");
static_assert (is_powerof2(TG_DIM_Y), "While using hardware shared memory, tile group Y dimension should be power of 2");

static constexpr std::size_t TILES = TG_DIM_X * TG_DIM_Y;
static constexpr std::size_t STRIPES = SIZE/STRIPE_SIZE + SIZE%STRIPE_SIZE;
static constexpr std::size_t STRIPES_PER_TILE = (STRIPES/TILES) + (STRIPES%TILES == 0 ? 0 : 1);
Expand Down Expand Up @@ -98,10 +105,3 @@ namespace bsg_manycore {
};
}



// constexpr bool is_powerof2(int v) {
// return v && ((v & (v - 1)) == 0);
// }


0 comments on commit d5a0ac4

Please sign in to comment.