2121#include < unordered_map>
2222#include < sstream>
2323
24+ #if ROCPROFILER_VERSION_MAJOR >= 1
25+ #define CALI_ROCPROFILER_HAVE_COUNTERS
26+ #endif
27+
2428using namespace cali ;
2529
2630#define ROCPROFILER_CALL (result ) \
@@ -90,6 +94,7 @@ class RocProfilerService
9094 bool m_enable_activity_tracing = false ;
9195 bool m_enable_snapshot_timestamps = false ;
9296 bool m_enable_allocation_tracing = false ;
97+ bool m_enable_counters = false ;
9398
9499 unsigned m_num_activity_records = 0 ;
95100 unsigned m_num_counter_records = 0 ;
@@ -99,6 +104,8 @@ class RocProfilerService
99104 std::mutex m_kernel_info_mutex;
100105
101106 std::unordered_map<uint64_t , const rocprofiler_agent_t *> m_agent_info_map;
107+
108+ #ifdef CALI_ROCPROFILER_HAVE_COUNTERS
102109 std::unordered_map<uint64_t , rocprofiler_counter_config_id_t > m_counter_profile_map;
103110 std::unordered_map<uint64_t , Attribute> m_counter_attr_map;
104111
@@ -111,6 +118,7 @@ class RocProfilerService
111118 };
112119
113120 std::unordered_map<uint64_t , std::vector<CounterDimensionData>> m_counter_dimension_info_map;
121+ #endif
114122
115123 Channel m_channel;
116124
@@ -217,7 +225,9 @@ class RocProfilerService
217225 mpi_rank_entry = c.get (mpi_rank_attr);
218226 }
219227
228+ #ifdef CALI_ROCPROFILER_HAVE_COUNTERS
220229 Entry counter_dispatch_entry;
230+ #endif
221231
222232 for (size_t i = 0 ; i < num_headers; ++i) {
223233 auto * header = headers[i];
@@ -321,6 +331,7 @@ class RocProfilerService
321331 s_instance->m_channel .events ().process_snapshot (&c, SnapshotView (), snapshot.view ());
322332
323333 ++s_instance->m_num_activity_records ;
334+ #ifdef CALI_ROCPROFILER_HAVE_COUNTERS
324335 } else if (header->category == ROCPROFILER_BUFFER_CATEGORY_COUNTERS &&
325336 header->kind == ROCPROFILER_COUNTER_RECORD_PROFILE_COUNTING_DISPATCH_HEADER ) {
326337
@@ -393,6 +404,7 @@ class RocProfilerService
393404 s_instance->m_channel .events ().process_snapshot (&c, SnapshotView (), snapshot.view ());
394405
395406 ++s_instance->m_num_counter_records ;
407+ #endif // CALI_ROCPROFILER_HAVE_COUNTERS
396408 }
397409 }
398410
@@ -456,6 +468,7 @@ class RocProfilerService
456468 }
457469 }
458470
471+ #ifdef CALI_ROCPROFILER_HAVE_COUNTERS
459472 static void dispatch_counter_config_callback (
460473 rocprofiler_dispatch_counting_service_data_t dispatch_data,
461474 rocprofiler_counter_config_id_t * config,
@@ -476,6 +489,7 @@ class RocProfilerService
476489 std::lock_guard<std::mutex> g (s_instance->m_counter_dispatch_correlation_mutex );
477490 s_instance->m_counter_dispatch_correlation_map .emplace (dispatch_data.dispatch_info .dispatch_id , e);
478491 }
492+ #endif
479493
480494 void snapshot_cb (Caliper* c, SnapshotView trigger_info, SnapshotBuilder& snapshot)
481495 {
@@ -513,11 +527,11 @@ class RocProfilerService
513527 ROCPROFILER_CALL (rocprofiler_start_context (alloc_tracing_ctx));
514528 }
515529
516- if (!m_counter_profile_map. empty () ) {
530+ if (m_enable_counters ) {
517531 ROCPROFILER_CALL (rocprofiler_start_context (counter_ctx));
518532 }
519533
520- if (m_enable_activity_tracing || !m_counter_profile_map. empty () ) {
534+ if (m_enable_activity_tracing || m_enable_counters ) {
521535 channel->events ().pre_flush_evt .connect ([this ](Caliper*, ChannelBody*, SnapshotView) { this ->pre_flush_cb (); });
522536 }
523537
@@ -559,10 +573,12 @@ class RocProfilerService
559573
560574 Log (1 ).stream () << channel->name () << " : rocprofiler: wrote " << m_num_activity_records
561575 << " activity records, " << m_num_counter_records << " counter records.\n " ;
562- Log (1 ).stream () << channel->name () << " : rocprofiler: " << m_failed_correlations
563- << " correlation lookups failed.\n " ;
576+ if (m_failed_correlations > 0 )
577+ Log (1 ).stream () << channel->name () << " : rocprofiler: " << m_failed_correlations
578+ << " correlation lookups failed.\n " ;
564579 }
565580
581+ #ifdef CALI_ROCPROFILER_HAVE_COUNTERS
566582 void setup_counter_profile_for_agent (Caliper* c, rocprofiler_agent_id_t agent, const std::vector<std::string>& counter_names)
567583 {
568584 std::vector<rocprofiler_counter_id_t > agent_counters;
@@ -632,7 +648,10 @@ class RocProfilerService
632648 dispatch_counter_config_callback,
633649 nullptr
634650 ));
651+
652+ m_enable_counters = !m_counter_profile_map.empty ();
635653 }
654+ #endif
636655
637656 RocProfilerService (Caliper* c, Channel* channel) : m_channel { *channel }
638657 {
@@ -666,8 +685,13 @@ class RocProfilerService
666685 ));
667686
668687 auto counter_names = config.get (" counters" ).to_stringlist ();
669- if (!counter_names.empty ())
688+ if (!counter_names.empty ()) {
689+ #ifdef CALI_ROCPROFILER_HAVE_COUNTERS
670690 setup_counter_profiles (c, counter_names);
691+ #else
692+ Log (0 ).stream () << channel->name () << " : rocprofiler: Counter collection is not supported!\n " ;
693+ #endif
694+ }
671695 }
672696
673697public:
@@ -710,8 +734,8 @@ class RocProfilerService
710734
711735 ROCPROFILER_CALL (rocprofiler_create_buffer (
712736 activity_ctx,
713- 4 * 1024 * 1024 ,
714- 4 * 1024 * 1024 - 65536 ,
737+ 1024 * 1024 ,
738+ 1024 * 1024 - 8192 ,
715739 ROCPROFILER_BUFFER_POLICY_LOSSLESS ,
716740 tool_tracing_callback,
717741 nullptr ,
0 commit comments