@@ -635,30 +635,40 @@ class ROFVertexLookupTable : public LayerTimingBase<NLayers>
635635};
636636
637637// GPU friendly view of the table below
638- template <uint32_t NLayers, typename ROFRange>
638+ template <int32_t NLayers, typename ROFRange>
639639struct ROFTimeSliceTableView {
640640 const ROFRange* mFlatTable {nullptr };
641+ const uint8_t * mFlatMask {nullptr };
642+ const int32_t * mLayerROFOffsets {nullptr };
641643 int32_t mSlices {0 };
642644
645+ GPUhdi () const uint8_t * getMask (int32_t layer, int32_t slice) const
646+ {
647+ assert (layer < NLayers);
648+ assert (sliceIdx < mSlices );
649+ const auto & range = getSlice (layer, slice);
650+ return &mFlatMask [mLayerROFOffsets [layer] + range.getFirstEntry ()];
651+ }
652+
643653 // Get the BC range for a given layer and slice
644- GPUhdi () const ROFRange& getSlice (uint32_t layer, int32_t sliceIdx ) const
654+ GPUhdi () const ROFRange& getSlice (int32_t layer, int32_t slice ) const
645655 {
646656 assert (layer < NLayers);
647657 assert (sliceIdx < mSlices );
648- return mFlatTable [(layer * mSlices ) + sliceIdx ];
658+ return mFlatTable [(layer * mSlices ) + slice ];
649659 }
650660
651661 // Check if a BC falls within a specific slice
652- GPUhdi () bool isInSlice (uint32_t layer, int32_t sliceIdx , int32_t bc) const
662+ GPUhdi () bool isInSlice (int32_t layer, int32_t slice , int32_t bc) const
653663 {
654- const auto & range = getSlice (layer, sliceIdx );
664+ const auto & range = getSlice (layer, slice );
655665 int32_t start = range.getFirstEntry ();
656666 int32_t end = range.getEntriesBound ();
657667 return bc >= start && bc < end;
658668 }
659669
660670 // Find which slice a BC belongs to (returns -1 if not found)
661- GPUhdi () int32_t findSlice (uint32_t layer, int32_t bc) const
671+ GPUhdi () int32_t findSlice (int32_t layer, int32_t bc) const
662672 {
663673 assert (layer < NLayers);
664674 int32_t left = 0 ;
@@ -694,17 +704,24 @@ struct ROFTimeSliceTableView {
694704 constexpr int w_start = 12 ;
695705 constexpr int w_end = 12 ;
696706 constexpr int w_range = 10 ;
697-
707+ constexpr int w_active = 12 ;
698708 LOGF (info, " Slice table: Layer %d" , layer);
699- LOGF (info, " %*s | %*s | %*s | %*s" , w_slice, " Slice" , w_start, " BC.Start" , w_end, " BC.End" , w_range, " Range" );
700- LOGF (info, " %.*s-+-%.*s-+-%.*s-+-%.*s" , w_slice, " ----------" , w_start, " ------------" , w_end, " ------------" , w_range, " ----------" );
701-
709+ LOGF (info, " %*s | %*s | %*s | %*s | %*s" , w_slice, " Slice" , w_start, " BC.Start" , w_end, " BC.End" , w_range, " Range" , w_active, " ActiveROFs" );
710+ LOGF (info, " %.*s-+-%.*s-+-%.*s-+-%.*s-+-%.*s" , w_slice, " ----------" , w_start, " ------------" , w_end, " ------------" , w_range, " ----------" , w_active, " ------------" );
702711 for (int32_t i = 0 ; i < mSlices ; ++i) {
703712 const auto & range = getSlice (layer, i);
704713 int32_t start = range.getFirstEntry ();
705714 int32_t rangeLen = range.getEntries ();
706715 int32_t end = range.getEntriesBound ();
707- LOGF (info, " %*d | %*d | %*d | %*d" , w_slice, i, w_start, start, w_end, end, w_range, rangeLen);
716+
717+ // Count active ROFs in this slice
718+ const uint8_t * mask = getMask (layer, i);
719+ int32_t activeCount = 0 ;
720+ for (int32_t j = 0 ; j < rangeLen; ++j) {
721+ activeCount += mask[j];
722+ }
723+
724+ LOGF (info, " %*d | %*d | %*d | %*d | %*d/%d" , w_slice, i, w_start, start, w_end, end, w_range, rangeLen, w_active, activeCount, rangeLen);
708725 }
709726 }
710727};
@@ -723,24 +740,47 @@ class ROFTimeSliceTable : public LayerTimingBase<NLayers>
723740 {
724741 mSlices = nSlices;
725742 std::vector<ROFRange> table[NLayers];
743+ int32_t totalROFs = 0 ;
726744 for (int32_t layer{0 }; layer < NLayers; ++layer) {
727745 buildSlices (layer, table[layer]);
746+ mLayerROFOffsets [layer] = totalROFs;
747+ totalROFs += this ->getLayer (layer).mNROFsTF ;
728748 }
749+ mFlatMask .resize (totalROFs, 1 );
729750 flatten (table);
730751 }
731752
753+ GPUh () void selectROFs (int32_t bcStart, int32_t bcEnd)
754+ {
755+ for (int32_t layer{0 }; layer < NLayers; ++layer) {
756+ const auto & lay = this ->getLayer (layer);
757+ int32_t offset = mLayerROFOffsets [layer];
758+ for (int32_t rofId{0 }; rofId < lay.mNROFsTF ; ++rofId) {
759+ auto bounds = lay.getROFTimeBounds (rofId);
760+ int32_t rofStart = bounds.getFirstEntry ();
761+ int32_t rofEnd = bounds.getEntriesBound ();
762+ bool isCompatible = rofStart < bcEnd && rofEnd > bcStart;
763+ mFlatMask [offset + rofId] = isCompatible ? 1 : 0 ;
764+ }
765+ }
766+ }
767+
732768 GPUhd () View getView () const
733769 {
734770 View view;
735771 view.mFlatTable = mFlatTable .data ();
772+ view.mFlatMask = mFlatMask .data ();
773+ view.mLayerROFOffsets = mLayerROFOffsets ;
736774 view.mSlices = mSlices ;
737775 return view;
738776 }
739777
740- GPUd () View getDeviceView (const ROFRange* deviceFlatTablePtr) const
778+ GPUd () View getDeviceView (const ROFRange* deviceFlatTablePtr, const uint8_t * deviceFlatMaskPtr ) const
741779 {
742780 View view;
743781 view.mFlatTable = deviceFlatTablePtr;
782+ view.mFlatMask = deviceFlatMaskPtr;
783+ view.mLayerROFOffsets = mLayerROFOffsets ;
744784 view.mSlices = mSlices ;
745785 return view;
746786 }
@@ -768,7 +808,9 @@ class ROFTimeSliceTable : public LayerTimingBase<NLayers>
768808 }
769809
770810 int32_t mSlices {0 };
811+ int32_t mLayerROFOffsets [NLayers];
771812 std::vector<ROFRange> mFlatTable ;
813+ std::vector<uint8_t > mFlatMask ;
772814};
773815
774816} // namespace o2::its
0 commit comments