Spaces:
Running
Running
File size: 5,971 Bytes
7b4f5dd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | /* βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
AMDMigrationPanel β CUDA β ROCm Migration Advisor
Shows compatibility score + per-finding migration guidance
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
import { useState } from 'react';
import './AMDMigrationPanel.css';
function ScoreCircle({ score }) {
const radius = 58;
const circumference = 2 * Math.PI * radius;
const offset = circumference - (score / 100) * circumference;
let colorClass = 'score-red';
let strokeClass = 'stroke-red';
if (score >= 90) { colorClass = 'score-green'; strokeClass = 'stroke-green'; }
else if (score >= 70) { colorClass = 'score-yellow'; strokeClass = 'stroke-yellow'; }
else if (score >= 50) { colorClass = 'score-orange'; strokeClass = 'stroke-orange'; }
return (
<div className="amd-score-circle">
<svg viewBox="0 0 140 140">
<circle className="amd-score-circle-bg" cx="70" cy="70" r={radius} />
<circle
className={`amd-score-circle-fill ${strokeClass}`}
cx="70"
cy="70"
r={radius}
strokeDasharray={circumference}
strokeDashoffset={offset}
/>
</svg>
<div className="amd-score-value">
<span className={`amd-score-number ${colorClass}`}>{score}</span>
<span className="amd-score-pct">%</span>
</div>
</div>
);
}
function MigrationFinding({ finding }) {
const [expanded, setExpanded] = useState(false);
const sevClass = `sev-${finding.severity}`;
return (
<div className="amd-mig-finding">
<div className="amd-mig-finding-header" onClick={() => setExpanded(!expanded)}>
<span className={`amd-mig-sev-badge ${sevClass}`}>{finding.severity}</span>
<span className="amd-mig-finding-id">{finding.id}</span>
<span className="amd-mig-finding-title">{finding.title}</span>
<button className="amd-mig-expand-btn" aria-label="Toggle details">
{expanded ? 'βΎ' : 'βΈ'}
</button>
</div>
{expanded && (
<div className="amd-mig-finding-detail">
{finding.file && (
<div className="amd-mig-file-loc">
<span>π</span>
<span>{finding.file}{finding.line ? `:${finding.line}` : ''}</span>
</div>
)}
<p className="amd-mig-description">{finding.description}</p>
<div className="amd-mig-fix-section">
<div className="amd-mig-fix-label">π§ ROCm Fix</div>
<p className="amd-mig-fix-text">{finding.rocm_fix}</p>
</div>
</div>
)}
</div>
);
}
export default function AMDMigrationPanel({ migrationData }) {
if (!migrationData) return null;
const {
compatibility_score = 100,
compatibility_label = 'Fully ROCm Ready',
findings = [],
total_cuda_patterns_found = 0,
summary = '',
} = migrationData;
let labelColor = 'score-red';
if (compatibility_score >= 90) labelColor = 'score-green';
else if (compatibility_score >= 70) labelColor = 'score-yellow';
else if (compatibility_score >= 50) labelColor = 'score-orange';
const handleExport = () => {
let md = `# AMD ROCm Migration Guide β CodeSentry\n\n`;
md += `## Compatibility Score: ${compatibility_score}% β ${compatibility_label}\n\n`;
md += `## Found ${total_cuda_patterns_found} CUDA-Specific Pattern(s)\n\n`;
if (summary) {
md += `> ${summary}\n\n`;
}
md += `---\n\n`;
findings.forEach((f) => {
md += `### ${f.id}: ${f.title}\n\n`;
md += `**Severity:** ${f.severity.toUpperCase()}\n\n`;
if (f.file) {
md += `**File:** \`${f.file}${f.line ? ':' + f.line : ''}\`\n\n`;
}
md += `**Issue:** ${f.description}\n\n`;
md += `**ROCm Fix:** ${f.rocm_fix}\n\n`;
if (f.code_snippet) {
md += `**Code:**\n\`\`\`python\n${f.code_snippet}\n\`\`\`\n\n`;
}
md += `---\n\n`;
});
md += `\n*Generated by CodeSentry AMD Migration Advisor*\n`;
const blob = new Blob([md], { type: 'text/markdown' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'AMD_MIGRATION_GUIDE.md';
a.click();
URL.revokeObjectURL(url);
};
return (
<div className="amd-migration-panel" id="amd-migration-panel">
{/* Header */}
<div className="amd-mig-header">
<span style={{ fontSize: '1.4rem' }}>π΄</span>
<h3>AMD ROCm Migration Advisor</h3>
</div>
{/* Score */}
<div className="amd-score-section">
<ScoreCircle score={compatibility_score} />
<span className={`amd-score-label ${labelColor}`}>{compatibility_label}</span>
</div>
{/* Findings */}
{findings.length > 0 ? (
<div className="amd-mig-findings">
{findings.map((f, idx) => (
<MigrationFinding key={`${f.id}-${idx}`} finding={f} />
))}
</div>
) : (
<div className="amd-no-findings">
β
No CUDA-specific patterns detected
<div className="amd-no-findings-sub">This codebase is fully AMD ROCm compatible</div>
</div>
)}
{/* Footer */}
<div className="amd-mig-footer">
<button className="btn btn-secondary btn-sm" onClick={handleExport} style={{ marginBottom: '8px' }}>
π΄ Export AMD Migration Guide
</button>
<div className="amd-mig-footer-text">
{total_cuda_patterns_found > 0
? `Apply all AMD fixes β Generate ROCm-optimized patch`
: `Codebase verified for AMD MI300X deployment`}
</div>
</div>
</div>
);
}
|