From 5cb4ad449f12a6fe0e6141d50054213d01de67b4 Mon Sep 17 00:00:00 2001 From: "Kandula, Venkateshwar reddy" Date: Wed, 19 Feb 2025 19:10:16 -0600 Subject: [PATCH] SWDEV-515574: Cache Number_Node static value. (#217) * Cache Number_Node static value. To avoid value overwriting in consecutive dispatch callbacks. * Format. * tests for number_node evaluate. --------- Co-authored-by: Venkateshwar Reddy Kandula --- .../rocprofiler-sdk/counters/evaluate_ast.cpp | 7 +++++- .../counters/tests/evaluate_ast_test.cpp | 23 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/source/lib/rocprofiler-sdk/counters/evaluate_ast.cpp b/source/lib/rocprofiler-sdk/counters/evaluate_ast.cpp index a9301fd5a6..096e9f1dc4 100644 --- a/source/lib/rocprofiler-sdk/counters/evaluate_ast.cpp +++ b/source/lib/rocprofiler-sdk/counters/evaluate_ast.cpp @@ -767,7 +767,12 @@ EvaluateAST::evaluate( case NONE: case CONSTANT_NODE: case RANGE_NODE: break; - case NUMBER_NODE: return &_static_value; + case NUMBER_NODE: + { + cache.emplace_back(std::make_unique>()); + *cache.back() = _static_value; + return cache.back().get(); + } case ADDITION_NODE: return perform_op([](auto& a, auto& b) { return rocprofiler_record_counter_t{ diff --git a/source/lib/rocprofiler-sdk/counters/tests/evaluate_ast_test.cpp b/source/lib/rocprofiler-sdk/counters/tests/evaluate_ast_test.cpp index a69d7551ce..7b002ca526 100644 --- a/source/lib/rocprofiler-sdk/counters/tests/evaluate_ast_test.cpp +++ b/source/lib/rocprofiler-sdk/counters/tests/evaluate_ast_test.cpp @@ -1054,8 +1054,9 @@ TEST(evaluate_ast, evaluate_mixed_counters) Metric("gfx9", "BATES", "a", "a", "a", "MAX_WAVE_SIZE*reduce(VOORHEES,sum)", "", 6)}, {"KRAMER", Metric("gfx9", "KRAMER", "a", "a", "a", "reduce(KRUEGER,sum)*SE_NUM", "", 7)}, {"TORRANCE", - Metric("gfx9", "TORRANCE", "a", "a", "a", "reduce(KRUEGER,sum)*SIMD_NUM", "", 8)}}; - add_constants(metrics, 9); + Metric("gfx9", "TORRANCE", "a", "a", "a", "reduce(KRUEGER,sum)*SIMD_NUM", "", 8)}, + {"DODGE", Metric("gfx9", "DODGE", "a", "a", "a", "10*TORRANCE", "", 9)}}; + add_constants(metrics, 10); std::unordered_map> base_counter_data = { {"VOORHEES", construct_test_data_dim(get_base_rec_id(0), {ROCPROFILER_DIMENSION_NONE}, 8)}, @@ -1088,6 +1089,24 @@ TEST(evaluate_ast, evaluate_mixed_counters) .user_data = {.value = 0}, .agent_id = {.handle = 0}}}), 2}, + + {"DODGE", + times_vec(sum_vec(base_counter_data["KRUEGER"]), + std::vector{{.id = 0, + .counter_value = 6240, + .dispatch_id = 0, + .user_data = {.value = 0}, + .agent_id = {.handle = 0}}}), + 2}, + {"DODGE", + times_vec(sum_vec(base_counter_data["KRUEGER"]), + std::vector{{.id = 0, + .counter_value = 6240, + .dispatch_id = 0, + .user_data = {.value = 0}, + .agent_id = {.handle = 0}}}), + 2}, + }; std::unordered_map> asts;