Processor Elementwise (PE) Boolean Functions
The anyOf API provides an efficient way to evaluate a boolean condition across all cores in the architecture. The function returns a boolean value, true if the condition is satisfied by at least one core, and false otherwise.
This is effectively act as an “OR“ operation.
/src/core/epu_common.hppLines 140–147 /**
* @brief Evaluate if any of the cores satisfy the condition.
*
* @param[in] cond The condition
*
* @return true or false dependent on the conditions evaluation.
*/
static bool anyOf(qVar_t<bool> cond) {
Examples
Example #1
Let's say we have a QB1 Chimera architecture (8x8 core array) and a tensor of shape <1, 1, 8, 8> with integer values. We want to check if any core in the architecture has a value equal to 10.
if(anyOf(qIn[tileIdx] == 10)) {
qOut[tileIdx] = 10;
} else {
qOut[tileIdx] = qIn[tileIdx] + 1;
}

When evaluating for left tile, the expression (anyOf(qIn[tileIdx] == 10)) will return FALSE as 10 is not present in any of the cores.
In contrast, when evaluating the right tile, the expression will return TRUE. This is because the values in two cores (marked in bold red) are equal to 10.
Example #2
/tests/static_data_tests/tile_any_of.cppLines 41–65EPU_ENTRY void ifAnyTileTest(DdrTensorShape::ptrType ddrOutPtr) {
initCycleCount();
DdrTensorShape ddrOut(ddrOutPtr);
MemAllocator ocmMem;
using WriteAccess = TensorAccessor<MinRoiDescriptor<DdrTensorShape, DefaultAxisGroup, Granularity::Square>>;
auto elsWrite = createGeneralWriteFlow<WriteAccess>(ddrOut, ocmMem);
typename decltype(elsWrite)::MinRoiArray qOutput;
qVar_t<std::int32_t> qData = (qRow<> * core_array::coreDim) + qCol<>;
// Find which row 49 is on.
if(qArrayCore) {
for(std::int32_t row = 0; row < core_array::coreDim; row++) {
/* For each row, search for any element that matches numToSearchFor
* Upon a match, break from the loop.
*/
if(anyOf(qRow<> == row && qData == numToSearchFor)) {
qOutput[0] = row;
break;
}
}
}
elsWrite.write(qOutput);
}
Example #3
This example demonstrates the usage of conditional logic with anyOf in a nested context.
/tests/static_data_tests/tile_any_all_nested.cppLines 38–70EPU_ENTRY void tileAnyAllNested(DdrOutTensorShape::ptrType ddrOutPtr) {
initCycleCount();
DdrOutTensorShape ddrOut(ddrOutPtr);
MemAllocator ocmMem;
qVar_t<std::int32_t> qData = (qRow<> * core_array::coreDim) + qCol<>;
std::int32_t b = 2;
if(!chimera::allOf(qData < core_array::coreDim)) {
b = 4;
}
using WriteAccess = TensorAccessor<MinRoiDescriptor<DdrOutTensorShape, DefaultAxisGroup, Granularity::Square>>;
auto elsWrite = createGeneralWriteFlow<WriteAccess>(ddrOut, ocmMem);
typename decltype(elsWrite)::MinRoiArray qOutput = {0};
// Ensure b has not been promoted to qVar by using it in a loop.
for(std::int32_t i = 0; i < b; i++) {
qOutput[0] += 1;
}
// qOutput should be uniform 4's at this point
if(qRow<> < qOutput[0]) {
// Only cores in rows less than 4 should execute the following.
if(chimera::anyOf(qOutput[0] < qCol<>)) {
qOutput[0] = 7;
}
}
// Write tile out to Ddr
elsWrite.write(qOutput);
}
The allOf API provides an efficient way to evaluate a boolean condition across all cores in the architecture. The function returns a boolean value, true if the condition is satisfied by all the cores, and false otherwise.
Essentially, the allOf API functions as an "AND" operation.
/src/core/epu_common.hppLines 154–161 /**
* @brief Evaluate if all of the cores satisfy the condition.
*
* @param[in] cond The condition
*
* @return true or false dependent on the conditions evaluation.
*/
static bool allOf(qVar_t<bool> cond) {
Examples
Example #1
Let's say we have a QB1 Chimera architecture (8x8 PE array) and a tensor of shape <1, 1, 8, 8> with integer values. We want to check if all cores have values that do not exceed a certain threshold (e.g., 100) and perform different operations based on the evaluation of this condition.
std::int32_t threshold = 100;
if(allOf(qData[tileIdx] <= threshold)) {
normalOperation(qData[tileIdx]);
} else {
specialOperation(qData[tileIdx]);
}
Example #2
In this example, we count tiles where the numbers are less than a specific threshold.
/tests/static_data_tests/tile_all_of.cppLines 44–65EPU_ENTRY void ifAllTileTest(DdrInpTensorShape::ptrType ddrInpPtr, DdrOutTensorShape::ptrType ddrOutPtr) {
initCycleCount();
DdrInpTensorShape ddrInp(ddrInpPtr);
DdrOutTensorShape ddrOut(ddrOutPtr);
MemAllocator ocmMem;
using ReadAccess = TensorAccessor<MinRoiDescriptor<DdrInpTensorShape, DefaultAxisGroup, Granularity::Square>>;
using WriteAccess = TensorAccessor<MinRoiDescriptor<DdrOutTensorShape, DefaultAxisGroup, Granularity::Square>>;
auto elsRead = createGeneralReadFlow<ReadAccess>(ddrInp, ocmMem);
auto elsWrite = createGeneralWriteFlow<WriteAccess>(ddrOut, ocmMem);
auto qInput = elsRead.read();
typename decltype(elsWrite)::MinRoiArray qOutput = {0};
for(std::int32_t i = 0; i < DdrInpTensorShape::NUM_TILES; i++) {
if(allOf(qInput[i] < lessThan)) {
qOutput[0] += 1;
}
}
elsWrite.write(qOutput);
}

When evaluating the left tile using the expression
/tests/static_data_tests/tile_all_of.cppSymbol: (allOf(qInput[i] < lessThan))(allOf(qInput[i] < lessThan))TRUE because all of the values are less than the threshold (100).In contrast, for the right tile, when evaluating the same expression
(allOf(qData[tileIdx] <= threshold)), the function will return FALSE because values at some cores (marked in bold red) exceed the threshold.