Skip to content

Feature 1.2.0#25

Merged
KelCodesStuff merged 6 commits intomainfrom
feature-1.2.0
Sep 29, 2025
Merged

Feature 1.2.0#25
KelCodesStuff merged 6 commits intomainfrom
feature-1.2.0

Conversation

@KelCodesStuff
Copy link
Owner

Summary

  • Removed P-value calculation to simplify test output.
  • Removed left over metric simulation code.
  • Make triangle variations deterministic.
  • Simplified GPU utilization calculations.

Testing

All tests pass

Documentation

  • Have you updated README instructions to reflect any code/process changes?

@gemini-code-assist
Copy link

Summary of Changes

Hello @KelCodesStuff, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the accuracy and reproducibility of performance testing by transitioning from simulated GPU metrics to direct sampling of Metal performance counters. It introduces deterministic data generation for consistent test workloads and streamlines statistical output by removing P-value calculations, providing a clearer and more reliable foundation for performance analysis.

Highlights

  • Actual GPU Performance Metrics: The system now uses actual Metal performance counters to gather GPU utilization and statistics, replacing previous simulated metrics for more accurate and reliable performance analysis.
  • Deterministic Test Data: Triangle variations and compute input buffers are now initialized with deterministic patterns instead of random data, ensuring consistent and reproducible performance measurements across test runs.
  • Simplified Statistical Output: The calculation and display of P-values have been removed from the statistical analysis output to simplify test results and focus on core performance metrics like mean difference and confidence intervals.
  • Refined GPU Utilization Calculations: GPU utilization metrics (compute, memory, vertex, fragment) have been simplified to directly leverage raw hardware counter values with minimal workload context, improving the accuracy and clarity of these measurements.
  • Removal of Old Baselines: Outdated baseline JSON files, which were based on simulated metrics, have been removed to align with the new approach of using actual hardware performance data.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Removes P-value calculation to simplify test output, eliminates left over metric simulation code, makes triangle variations deterministic, and simplifies GPU utilization calculations. The changes focus on making GPU performance calculations more accurate by using direct hardware counter data instead of simulated values.

  • Replaced complex simulated GPU utilization calculations with simpler hardware counter-based approaches
  • Removed P-value reporting from statistical output displays
  • Deleted baseline data files to ensure clean regeneration with deterministic values

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Metal-Performance-Tester/Metrics/GraphicsPerformanceMetrics.swift Simplified GPU utilization calculations to use direct hardware counters and added finite value checks
Metal-Performance-Tester/Metrics/ComputePerformanceMetrics.swift Simplified compute utilization calculations to use direct hardware counters and added finite value checks
Metal-Performance-Tester/Managers/GraphicsTestManager.swift Removed P-value display from test output to simplify statistical reporting
Metal-Performance-Tester/Managers/ComputeTestManager.swift Removed P-value display from test output to simplify statistical reporting
Metal-Performance-Tester/Data/baselines/baseline_ultra_high_baseline.json Deleted baseline data file for clean regeneration
Metal-Performance-Tester/Data/baselines/baseline_moderate_baseline.json Deleted baseline data file for clean regeneration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +117 to +119
let totalCacheAccess = estimatedCacheHits + estimatedCacheMisses
let cacheHitRate = totalCacheAccess > 0 && totalCacheAccess.isFinite ?
(estimatedCacheHits / totalCacheAccess) * 100.0 : 0.0
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider extracting this cache hit rate calculation into a separate helper method since it's used in both GraphicsPerformanceMetrics and ComputePerformanceMetrics.

Copilot uses AI. Check for mistakes.
// Convert raw counter value to percentage utilization
// Metal counters typically provide values in different scales depending on the specific counter
// For vertex utilization, we normalize based on typical counter ranges
let normalizedUtilization = min(rawUtilization / 1000.0, 100.0) // Normalize to 0-100%
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

[nitpick] The magic number 1000.0 for normalization should be extracted as a named constant to improve code readability and maintainability.

Copilot uses AI. Check for mistakes.
let COMPLEXITY_SCALING_DIVISOR = 20.0
// Convert raw counter value to percentage utilization
// Metal counters provide actual compute unit utilization from hardware
let normalizedUtilization = min(rawUtilization / 1000.0, 100.0) // Normalize to 0-100%
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

[nitpick] The magic number 1000.0 for normalization should be extracted as a named constant to improve code readability and maintainability.

Copilot uses AI. Check for mistakes.
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant improvements to the performance testing framework. Key changes include removing the P-value calculation to simplify output, replacing simulated metrics with actual Metal performance counter data, and making test workloads deterministic for more reliable and reproducible results. The code is cleaner and more robust, especially with the added NaN protection in statistical calculations and the simplification of utilization metrics.

I've provided a few suggestions to further improve maintainability and readability by refactoring duplicated code and replacing magic numbers with named constants. Overall, this is a solid update that enhances the accuracy and reliability of the performance tester.

Comment on lines +160 to +161
let coefficientOfVariation = (mean != 0 && mean.isFinite) ?
(standardDeviation.isFinite ? standardDeviation / mean : 0.0) : 0.0

Choose a reason for hiding this comment

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

medium

This NaN-protection logic for division is repeated in calculateUtilizationStatistic (line 237) and in a similar form for percentage calculations in compare (lines 260, 299) and create...Comparison functions (lines 497, 513). To improve maintainability and reduce code duplication, consider extracting this into a private static helper function for safe division.

Comment on lines +303 to +311
if let buffer = metrics.timestampBuffer {
computeEncoder.sampleCounters(sampleBuffer: buffer, sampleIndex: 0, barrier: false)
}
if let buffer = metrics.stageUtilizationBuffer {
computeEncoder.sampleCounters(sampleBuffer: buffer, sampleIndex: 0, barrier: false)
}
if let buffer = metrics.statisticsBuffer {
computeEncoder.sampleCounters(sampleBuffer: buffer, sampleIndex: 0, barrier: false)
}

Choose a reason for hiding this comment

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

medium

The repeated if let checks for each buffer can be refactored into a more concise and maintainable form using compactMap and forEach. This approach is cleaner and scales better if more counter buffers are added in the future. A similar refactoring can be applied to sampleComputeCountersEnd.

[metrics.timestampBuffer, metrics.stageUtilizationBuffer, metrics.statisticsBuffer]
    .compactMap { $0 }
    .forEach { buffer in
        computeEncoder.sampleCounters(sampleBuffer: buffer, sampleIndex: 0, barrier: false)
    }

Comment on lines +578 to +582
let cacheEfficiency = cacheHitRate.isFinite ? cacheHitRate / 100.0 : 0.0 // Convert percentage to 0-1 range
let bandwidthEfficiency = memoryBandwidth.isFinite ? min(max(memoryBandwidth / 1000000.0, 0.0), 1.0) : 0.0 // Normalize to 0-1 range

// Weighted average with cache performance being more important for threadgroup efficiency
let efficiency = (cacheEfficiency * 0.7) + (bandwidthEfficiency * 0.3)

Choose a reason for hiding this comment

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

medium

The values 1000000.0, 0.7, and 0.3 are magic numbers. Extracting them into named constants with explanatory comments would improve the readability and maintainability of this calculation. For example, you could define constants like bandwidthNormalizationFactor, cacheEfficiencyWeight, and bandwidthEfficiencyWeight.

Comment on lines +620 to +621
let workloadScale = (complexity / 10.0) * (threadgroupCount / (256.0 * 256.0))
let scaledInstructionsPerSecond = instructionsPerSecond * (1.0 + workloadScale)

Choose a reason for hiding this comment

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

medium

The values 10.0 and 256.0 appear to be magic numbers related to workload scaling. To improve clarity and maintainability, consider defining them as named constants with comments explaining their significance (e.g., maxComplexityScale, referenceThreadgroupDimension).

let COMPLEXITY_SCALING_DIVISOR = 20.0
// Convert raw counter value to percentage utilization
// Metal counters provide actual compute unit utilization from hardware
let normalizedUtilization = min(rawUtilization / 1000.0, 100.0) // Normalize to 0-100%

Choose a reason for hiding this comment

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

medium

The value 1000.0 is used here and in calculateComputeMemoryUtilization to normalize the raw counter value. It's not immediately clear what this number represents. It would be beneficial to define it as a named constant with a comment explaining its purpose, for instance, if it's a scaling factor provided by Metal's documentation for this specific counter.

// Convert raw counter value to percentage utilization
// Metal counters typically provide values in different scales depending on the specific counter
// For vertex utilization, we normalize based on typical counter ranges
let normalizedUtilization = min(rawUtilization / 1000.0, 100.0) // Normalize to 0-100%

Choose a reason for hiding this comment

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

medium

The value 1000.0 is used here and in calculateGraphicsFragmentUtilization and calculateGraphicsMemoryUtilization to normalize the raw counter value. It's not immediately clear what this number represents. It would be beneficial to define it as a named constant with a comment explaining its purpose, for instance, if it's a scaling factor provided by Metal's documentation for this specific counter.

@KelCodesStuff
Copy link
Owner Author

There are separate tickets for the findings in the comments above.

@KelCodesStuff KelCodesStuff merged commit 395b8f6 into main Sep 29, 2025
2 checks passed
@KelCodesStuff KelCodesStuff deleted the feature-1.2.0 branch September 30, 2025 14:42
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