MCPcopy Create free account
hub / github.com/RightNow-AI/rightnow-cli / _run_optimization

Method _run_optimization

rightnow_cli/interactive.py:335–482  ·  view source on GitHub ↗

Run optimization - SIMPLIFIED.

(self, file: Path, kernels: List[Dict], options: Dict)

Source from the content-addressed store, hash-verified

333 }
334
335 def _run_optimization(self, file: Path, kernels: List[Dict], options: Dict):
336 """Run optimization - SIMPLIFIED."""
337
338 from .kernel_analyzer import KernelAnalyzer
339 from .openrouter import OpenRouterClient
340 from .compiler import CUDACompiler
341 from .bench import Benchmarker
342
343 api_key = self.cache_manager.get_api_key()
344 client = OpenRouterClient(api_key)
345 analyzer = KernelAnalyzer()
346 compiler = CUDACompiler()
347 benchmarker = Benchmarker(iterations=options['iterations'])
348
349 for idx, kernel in enumerate(kernels, 1):
350 console.print(f"\n[bold cyan]Kernel {idx}/{len(kernels)}: {kernel['name']}[/bold cyan]")
351
352 # Analyze
353 console.print("[dim]Analyzing...[/dim]")
354 try:
355 analysis = analyzer.analyze_kernel(kernel['code'])
356 console.print(f"[green]✓ Found {len(analysis.get('optimization_opportunities', []))} optimization opportunities[/green]")
357 except Exception as e:
358 console.print(f"[red]✗ Analysis failed: {e}[/red]")
359 continue
360
361 # Generate variants
362 console.print(f"[dim]Generating {options['variants']} variants with AI...[/dim]")
363
364 constraints = {
365 'max_registers': options['max_registers'],
366 'shared_memory_kb': options['shared_mem_kb'],
367 'target_gpu': options['target_gpu']
368 }
369
370 variants = []
371 with Progress(
372 SpinnerColumn(),
373 TextColumn("[dim]{task.description}[/dim]"),
374 BarColumn(bar_width=30),
375 TextColumn("{task.percentage:>3.0f}%"),
376 console=console,
377 transient=True
378 ) as progress:
379 task = progress.add_task("", total=options['variants'])
380
381 for i in range(options['variants']):
382 try:
383 generated = client.generate_kernel_optimizations(
384 original_code=kernel['code'],
385 analysis=analysis,
386 constraints=constraints,
387 num_variants=1
388 )
389 if generated:
390 variants.extend(generated)
391 except Exception as e:
392 console.print(f"[yellow]Variant {i+1} failed: {str(e)[:50]}[/yellow]")

Callers 1

_optimize_workflowMethod · 0.95

Calls 10

analyze_kernelMethod · 0.95
compile_kernelMethod · 0.95
OpenRouterClientClass · 0.85
KernelAnalyzerClass · 0.85
CUDACompilerClass · 0.85
BenchmarkerClass · 0.85
get_api_keyMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected