tazwarrrr commited on
Commit
5504db3
·
1 Parent(s): 86f9ce1

remove hackathon

Browse files
Files changed (2) hide show
  1. backend/main.py +33 -25
  2. frontend/index.html +29 -4
backend/main.py CHANGED
@@ -11,7 +11,7 @@ from fastapi import FastAPI, HTTPException
11
  import json
12
  import asyncio
13
  import zipfile
14
- import tempfile
15
  import os
16
  import difflib
17
  from dotenv import load_dotenv
@@ -244,24 +244,37 @@ async def export_migration_package(req: dict):
244
  Returns a zip file with diff and migration report.
245
  """
246
  try:
247
- original_cuda = req.get("original_cuda")
248
- final_rocm = req.get("final_rocm")
249
  migration_report = req.get("migration_report", {})
250
-
251
- with tempfile.NamedTemporaryFile(delete=False, suffix=".zip") as tmp_file:
252
- with zipfile.ZipFile(tmp_file, 'w', zipfile.ZIP_DEFLATED) as zf:
253
- # Add professional unified diff
254
- diff = difflib.unified_diff(
255
- original_cuda.splitlines(keepends=True),
256
- final_rocm.splitlines(keepends=True),
257
- fromfile="original.cu",
258
- tofile="optimized.hip"
259
- )
260
- diff_text = "".join(diff)
261
- zf.writestr("migration.diff", diff_text)
262
-
263
- # Add migration report as markdown
264
- md_report = f"""# ROCmPort AI Migration Report
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
 
266
  ## Performance Results
267
  - Speedup: {migration_report.get('speedup', 'N/A')}x
@@ -276,14 +289,9 @@ async def export_migration_package(req: dict):
276
 
277
  Generated by ROCmPort AI.
278
  """
279
- zf.writestr("migration_report.md", md_report)
280
-
281
- # Read the zip file content
282
- with open(tmp_file, 'rb') as f:
283
- zip_content = f.read()
284
 
285
- # Clean up
286
- os.unlink(tmp_file)
287
 
288
  from fastapi.responses import Response
289
  return Response(
 
11
  import json
12
  import asyncio
13
  import zipfile
14
+ import io
15
  import os
16
  import difflib
17
  from dotenv import load_dotenv
 
244
  Returns a zip file with diff and migration report.
245
  """
246
  try:
 
 
247
  migration_report = req.get("migration_report", {})
248
+ if not isinstance(migration_report, dict):
249
+ migration_report = {}
250
+
251
+ original_cuda = str(req.get("original_cuda") or "")
252
+ # Fallback to report content when frontend omits final_rocm.
253
+ final_rocm = str(req.get("final_rocm")
254
+ or migration_report.get("optimized_code") or "")
255
+
256
+ if not final_rocm.strip():
257
+ raise HTTPException(
258
+ status_code=400, detail="No ROCm code provided for export")
259
+
260
+ zip_buffer = io.BytesIO()
261
+ with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_DEFLATED) as zf:
262
+ # Add professional unified diff
263
+ diff = difflib.unified_diff(
264
+ original_cuda.splitlines(keepends=True),
265
+ final_rocm.splitlines(keepends=True),
266
+ fromfile="original.cu",
267
+ tofile="optimized.hip"
268
+ )
269
+ diff_text = "".join(diff)
270
+ zf.writestr("migration.diff", diff_text)
271
+
272
+ # Include source snapshots for easier review in PRs.
273
+ zf.writestr("original.cu", original_cuda)
274
+ zf.writestr("optimized.hip", final_rocm)
275
+
276
+ # Add migration report as markdown
277
+ md_report = f"""# ROCmPort AI Migration Report
278
 
279
  ## Performance Results
280
  - Speedup: {migration_report.get('speedup', 'N/A')}x
 
289
 
290
  Generated by ROCmPort AI.
291
  """
292
+ zf.writestr("migration_report.md", md_report)
 
 
 
 
293
 
294
+ zip_content = zip_buffer.getvalue()
 
295
 
296
  from fastapi.responses import Response
297
  return Response(
frontend/index.html CHANGED
@@ -1183,7 +1183,7 @@ __global__ void kernel(float* A, float* B, int N) {
1183
  </div>
1184
 
1185
  <footer>
1186
- <div>ROCmPort AI — AMD Developer Hackathon 2025</div>
1187
  <div><a href="https://x.com/TazwarEnan" target="_blank">Tazwar Ahnaf Enan</a> · <a
1188
  href="https://github.com/tazwaryayyyy" target="_blank">GitHub</a></div>
1189
  </footer>
@@ -1541,9 +1541,34 @@ __global__ void kernel(float* A, float* B, int N) {
1541
  async function exM() {
1542
  if (!S.rep) return;
1543
  try {
1544
- const res = await fetch(API + '/export', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ original_cuda: S.code, final_rocm: S.rep.optimized_code, migration_report: S.rep }) });
1545
- if (res.ok) { const a = document.createElement('a'); a.href = URL.createObjectURL(await res.blob()); a.download = 'rocmport-migration.zip'; a.click() }
1546
- } catch (e) { alert('Export error') }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1547
  }
1548
 
1549
  function tsm() {
 
1183
  </div>
1184
 
1185
  <footer>
1186
+ <div>ROCmPort AI</div>
1187
  <div><a href="https://x.com/TazwarEnan" target="_blank">Tazwar Ahnaf Enan</a> · <a
1188
  href="https://github.com/tazwaryayyyy" target="_blank">GitHub</a></div>
1189
  </footer>
 
1541
  async function exM() {
1542
  if (!S.rep) return;
1543
  try {
1544
+ const currentInput = document.getElementById('inp')?.value || '';
1545
+ const payload = {
1546
+ original_cuda: S.code || currentInput,
1547
+ final_rocm: S.rep.optimized_code || '',
1548
+ migration_report: S.rep
1549
+ };
1550
+ const res = await fetch(API + '/export', {
1551
+ method: 'POST',
1552
+ headers: { 'Content-Type': 'application/json' },
1553
+ body: JSON.stringify(payload)
1554
+ });
1555
+
1556
+ if (!res.ok) {
1557
+ let msg = `Export failed (${res.status})`;
1558
+ try {
1559
+ const err = await res.json();
1560
+ if (err && err.detail) msg = err.detail;
1561
+ } catch (_) { }
1562
+ throw new Error(msg);
1563
+ }
1564
+
1565
+ const a = document.createElement('a');
1566
+ a.href = URL.createObjectURL(await res.blob());
1567
+ a.download = 'rocmport-migration.zip';
1568
+ a.click();
1569
+ } catch (e) {
1570
+ alert('Export error: ' + (e.message || 'Unknown error'));
1571
+ }
1572
  }
1573
 
1574
  function tsm() {