// Copyright Advanced Micro Devices, Inc., or its affiliates. // SPDX-License-Identifier: MIT #pragma once #include "../catch/TestContext.hpp" #include "../catch/TestKernels.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include namespace rocRoller { /** * @brief Results from kernel profiling and latency collection */ struct KernelLatencyResults { std::vector filteredInstructions; std::vector> medianLatencies; std::string infoStr; }; /** * @brief Results from latency delta analysis */ struct LatencyAnalysisResult { int totalDelta; int totalAbsoluteDelta; int incorrectPredictionCount; }; /** * @brief Base class for LDS test kernels with shared functionality */ class LDSTestKernelBase : public AssemblyTestKernel { public: LDSTestKernelBase(ContextPtr context, uint32_t workgroupSize, size_t instrDwords, size_t strideMultiplier, const std::vector& baseAddresses, bool write); void operator()(); const std::vector& getInstructions() const; std::string getSectionName() const; protected: virtual void generate() override; virtual Generator generateKernelBody() = 0; protected: uint32_t m_workgroupSize; size_t m_instrDwords; size_t m_strideMultiplier; std::vector m_baseAddresses; bool m_write; std::vector m_instructions; std::shared_ptr m_ldsDst; std::shared_ptr m_ldsWithOffset; std::shared_ptr m_workitemIndex; }; /** * @brief Helper function for profiling and collecting median latencies */ KernelLatencyResults runKernelAndCollectLatencies(TestContext& context, LDSTestKernelBase& kernel); /** * @brief Analyzes latency deltas between model predictions and profiler measurements * * @param filteredInstructions The list of instructions to analyze * @param medianLatencies The measured latencies for each instruction * @return Structure containing total delta, absolute delta, and incorrect prediction count */ LatencyAnalysisResult analyzeLatencyDeltas(const std::vector& filteredInstructions, const std::vector>& medianLatencies); /** * @brief Generic parameterized kernel class for LDS tests */ class ParameterizedLDSKernel : public LDSTestKernelBase { public: using BodyGenerator = std::function(ParameterizedLDSKernel*)>; ParameterizedLDSKernel(ContextPtr context, uint32_t workgroupSize, size_t instrDwords, size_t strideMultiplier, const std::vector& baseAddresses, bool write, BodyGenerator bodyGen); Generator scheduleLdsInstruction(int& counter); ContextPtr getContext() const; protected: Generator generateKernelBody() override; private: BodyGenerator m_bodyGenerator; }; /** * @brief Configuration for LDS test cases */ struct LDSTestConfig { bool useMultipleWorkgroupSizes; std::function(ParameterizedLDSKernel*)> kernelBodyGen; std::function validationFunc; }; /** * @brief Common test harness function for LDS tests * Handles workgroup/item set up, kernel generation, profiling, latency collection, and validation based on the provided configuration * Test need only implement the kernel body generation and validation logic */ void runLDSTest(const LDSTestConfig& config); } // namespace rocRoller