Files
TheRock/rocm-libraries/shared/stinkytofu/tools/intrinsic-compiler/test_loader.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

161 lines
5.8 KiB
C++

/* ************************************************************************
* Copyright (C) 2025-2026 Advanced Micro Devices, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* ************************************************************************ */
/**
* @file test_loader.cpp
* @brief Test program to verify IntrinsicLibrary loading
*
* This program tests the complete intrinsic compilation flow:
* 1. intrinsic-compiler: Intrinsics.intrinsic -> intrinsics.st.bc
* 2. IntrinsicLibrary: Load intrinsics.st.bc
* 3. Query and display intrinsic definitions
*/
#include <bit>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include "stinkytofu/ir/logical/IntrinsicLibrary.hpp"
using namespace stinkytofu;
static void printIntrinsicDetails(const IntrinsicLibrary& lib, const std::string& name) {
std::cout << "\n=== Intrinsic: " << name << " ===\n";
const Pattern* pattern = lib.lookup(name);
if (!pattern) {
std::cout << " NOT FOUND\n";
return;
}
// Print comment
std::cout << " Comment: " << pattern->comment << "\n";
// Print arguments
std::cout << " Arguments (" << pattern->arguments.size() << "):\n";
for (const auto& arg : pattern->arguments) {
std::cout << " " << arg.name << ": " << arg.regType << "\n";
}
// Print body instructions
std::cout << " Body (" << pattern->body.size() << " instructions):\n";
for (const auto& inst : pattern->body) {
std::cout << " " << inst.destReg << " = " << inst.operation << "(";
for (size_t i = 0; i < inst.operands.size(); ++i) {
if (i > 0) std::cout << ", ";
const auto& op = inst.operands[i];
if (op.type == IntrinsicOperand::Register) {
std::cout << op.registerName;
} else if (op.type == IntrinsicOperand::IntLiteral) {
std::cout << op.intValue;
} else if (op.type == IntrinsicOperand::FloatLiteral) {
std::cout << op.floatValue;
} else if (op.type == IntrinsicOperand::HexLiteral) {
float floatVal = static_cast<float>(op.floatValue);
uint32_t bits = std::bit_cast<uint32_t>(floatVal);
std::cout << "0x" << std::hex << bits << std::dec;
}
}
std::cout << ")\n";
}
// Print Python binding status
std::cout << " Python Binding: " << (pattern->pythonBinding ? "enabled" : "disabled") << "\n";
}
int main(int argc, char** argv) {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " <intrinsics.st.bc>\n";
return 1;
}
std::string bcFilePath = argv[1];
std::cout << "=== StinkyTofu Intrinsic Loader Test ===\n\n";
std::cout << "Loading: " << bcFilePath << "\n\n";
// Step 1: Load intrinsics library
auto lib = IntrinsicLibrary::loadFromFile(bcFilePath);
if (!lib) {
std::cerr << "Error: Failed to load intrinsic library\n";
return 1;
}
std::cout << "? Successfully loaded " << lib->size() << " intrinsic(s)\n\n";
// Step 2: Print library statistics
lib->printStats();
// Step 3: Test specific intrinsic lookups
std::cout << "\n=== Testing Intrinsic Lookups ===\n";
std::vector<std::string> testNames = {"ReluF32", "ClampF16", "SigmoidF32", "ExpF32",
"NonExistent"};
for (const auto& name : testNames) {
std::cout << "\nLookup '" << name << "': ";
if (lib->hasIntrinsic(name)) {
std::cout << "FOUND ?\n";
printIntrinsicDetails(*lib, name);
} else {
std::cout << "NOT FOUND ?\n";
}
}
// Step 4: Test accessor methods
std::cout << "\n\n=== Testing Accessor Methods ===\n";
std::string testIntrinsic = "ReluF32";
if (lib->hasIntrinsic(testIntrinsic)) {
std::cout << "\nTesting " << testIntrinsic << " accessors:\n";
auto args = lib->getArguments(testIntrinsic);
std::cout << " getArguments(): " << args.size() << " argument(s)\n";
for (const auto& arg : args) {
std::cout << " - " << arg.name << "\n";
}
auto body = lib->getBody(testIntrinsic);
std::cout << " getBody(): " << body.size() << " instruction(s)\n";
auto comment = lib->getComment(testIntrinsic);
std::cout << " getComment(): \"" << comment << "\"\n";
bool hasPython = lib->hasPythonBinding(testIntrinsic);
std::cout << " hasPythonBinding(): " << (hasPython ? "true" : "false") << "\n";
}
// Step 5: List all intrinsics
std::cout << "\n\n=== All Intrinsics ===\n";
auto allNames = lib->getIntrinsicNames();
for (const auto& name : allNames) {
std::cout << " - " << name << "\n";
}
std::cout << "\n\n=== Test Complete ? ===\n";
return 0;
}