Skip to content

Use new accordo APIs - #157

Merged
mawad-amd merged 7 commits into
mainfrom
muhaawad/accordo-1
Nov 8, 2025
Merged

mawad-amd merged 7 commits into
mainfrom
muhaawad/accordo-1

Conversation

@mawad-amd

Copy link
Copy Markdown
Member

No description provided.

mawad-amd and others added 5 commits November 3, 2025 04:36
**New Accordo API (clean abstraction):**
- New Accordo module structure with public API (__init__, config, result, snapshot, exceptions, validator)
- Internal implementation (_internal/codegen, hip_interop, ipc/communication)
- Snapshot-based caching: capture reference once, compare multiple optimized versions
- AccordoValidator with proper timeout handling and error detection
- KernelArg dataclass for cleaner argument specification

**Formula changes (preserves all main improvements):**
- Updated correctness_validation_pass() to use new Accordo API with caching
- Added write_and_log_optimized_code() to centralize iteration logging
- All formulas use write_and_log_optimized_code() for immediate LLM output capture
- find_kernel_file() already in main - formulas use it correctly

**Infrastructure:**
- Logger.save_iteration_code() for centralized iteration file management
- __main__.py passes trace_path to logger
- All examples/*.hip updated with hip_try macro for error handling
- .gitignore: added .rocprofv3/

**Preserved from main ("Unify counters report" #155):**
- OptimizationTracker helper methods (is_successful, get_best_code, etc.)
- Auto-success determination logic
- Proper tie-breaker with speedup
- _filter_compiler_errors() method
- Correct failure metrics (speedup 0.0 for build, 1.0 for correctness)
- Correct performance_validation flow (add_step first, query values, build report)
Clean API with everything under Accordo namespace:
- Accordo.Config (ValidationConfig)
- Accordo.KernelArg
- Accordo.Snapshot
- Accordo.Result (ValidationResult)
- Accordo.ArrayMismatch
- Accordo.Error (AccordoError)
- Accordo.BuildError (AccordoBuildError)
- Accordo.TimeoutError (AccordoTimeoutError)
- Accordo.ProcessError (AccordoProcessError)
- Accordo.ValidationError (AccordoValidationError)

Usage:
    from accordo import Accordo
    config = Accordo.Config(kernel_name="...", kernel_args=[...])
    validator = Accordo(config)
    result = validator.validate(...)
@mawad-amd
mawad-amd requested review from Copilot and removed request for coleramos425 November 8, 2025 04:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the Accordo validation system to improve efficiency and adds iteration code logging for better debugging. The key changes include:

  • Refactored Accordo into a clean public API with snapshot-based validation caching
  • Introduced snapshot caching to capture the reference application once and reuse it across multiple validations
  • Added automatic iteration code logging to trace directory
  • Enhanced example files with hip_try error handling macros

Reviewed Changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/accordo/validator.py New Accordo validator with snapshot-based API
src/accordo/config.py Configuration classes for validation setup
src/accordo/snapshot.py Snapshot data structure for cached validation
src/accordo/result.py Validation result classes with detailed metrics
src/accordo/exceptions.py Custom exception hierarchy for Accordo errors
src/accordo/init.py Clean public API with nested class structure
src/accordo/_internal/ Internal implementation modules (IPC, codegen, HIP interop)
src/intelliperf/formulas/formula_base.py Snapshot caching in validation, new write_and_log_optimized_code method
src/intelliperf/formulas/memory_access.py Uses new code logging method, reordered output fields
src/intelliperf/formulas/bank_conflict.py Uses new code logging method, reordered output fields
src/intelliperf/formulas/atomic_contention.py Uses new code logging method, reordered output fields
src/intelliperf/formulas/diagnose_only.py Updated signature for API consistency
src/intelliperf/core/logger.py New save_iteration_code method
src/intelliperf/main.py Sets trace_path on logger for iteration logging
examples/*.hip Added hip_try error handling macros

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/accordo/validator.py
original_dir = os.getcwd()
try:
os.chdir(working_directory)
process_pid = os.posix_spawn(binary_cmd[0], binary_cmd, env)

Copilot AI Nov 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The os.posix_spawn function spawns a process but there is no corresponding wait or cleanup after send_response. This can lead to zombie processes accumulating. After send_response(pipe_name) on line 373, add code to wait for the process to finish, such as os.waitpid(process_pid, 0).

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +37
#define hip_try(expr) \
do { \
hipError_t err = (expr); \
if (err != hipSuccess) { \
const char* msg = hipGetErrorString(err); \
throw std::runtime_error(std::string("HIP error: ") + msg); \
} \

Copilot AI Nov 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The hip_try macro is defined inconsistently across example files. Most files use hipError_t err as the variable name, but examples/access_pattern/uncoalesced/uncoalesced.hip uses hipError_t status and includes FILE and LINE in the error message. Consider standardizing the macro definition across all examples for consistency and maintainability. The version with FILE and LINE provides better error diagnostics.

Suggested change
#define hip_try(expr) \
do { \
hipError_t err = (expr); \
if (err != hipSuccess) { \
const char* msg = hipGetErrorString(err); \
throw std::runtime_error(std::string("HIP error: ") + msg); \
} \
#define hip_try(expr) \
do { \
hipError_t err = (expr); \
if (err != hipSuccess) { \
const char* msg = hipGetErrorString(err); \
throw std::runtime_error(std::string("HIP error at " + std::string(__FILE__) + ":" + \
std::to_string(__LINE__) + ": " + msg)); \
} \

Copilot uses AI. Check for mistakes.
Comment on lines +753 to 754
"optimization_history": self.optimization_tracker.to_dict(),
"formula": "memoryAccess",

Copilot AI Nov 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The 'optimization_history' field has been moved before 'formula' in the output dictionary. This reordering changes the JSON output format which could break downstream consumers that rely on field ordering. While Python 3.7+ dictionaries maintain insertion order, changing the order of fields in API responses should be done deliberately as a breaking change.

Suggested change
"optimization_history": self.optimization_tracker.to_dict(),
"formula": "memoryAccess",
"formula": "memoryAccess",
"optimization_history": self.optimization_tracker.to_dict(),

Copilot uses AI. Check for mistakes.
return super().compile_pass()

def correctness_validation_pass(self):
def correctness_validation_pass(self, accordo_absolute_tolerance: float = 1e-6):

Copilot AI Nov 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method requires at most 2 positional arguments, whereas overridden Formula_Base.correctness_validation_pass requires at least 3.

Copilot uses AI. Check for mistakes.
@mawad-amd
mawad-amd merged commit 60d5276 into main Nov 8, 2025
2 of 3 checks passed
@mawad-amd
mawad-amd deleted the muhaawad/accordo-1 branch November 8, 2025 04:14
@github-actions
github-actions Bot restored the muhaawad/accordo-1 branch November 8, 2025 04:14
mawad-amd added a commit that referenced this pull request Nov 8, 2025
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@mawad-amd
mawad-amd deleted the muhaawad/accordo-1 branch November 8, 2025 04:40
mawad-amd added a commit that referenced this pull request Nov 8, 2025
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants