CUDA-L1 Reinforcement Learning Framework

repository·main·Indexed 43 days ago

https://github.com/deepreinforce-ai/cuda-l1

An automated reinforcement learning (RL) framework that uses a contrastive RL model to optimize CUDA kernels. It improves GPU kernel efficiency by outperforming torch.compile and CUDA Graphs on KernelBench workloads.

Tokens
776
Snippets
3
Records
3
Agent score
6%

What's inside CUDA-L1

  1. Understand the structure of the CUDA-L1 release code JSON

    main

    The release files contain JSON objects representing optimized workloads from the KernelBench dataset. Each object provides a comparison between reference code and CUDA-L1 generated code across different execution modes.

    Note: If custom_code is null (None), the RL model either failed to generate code faster than the reference or simply copied the reference code.

    {
      "level_id": 1,
      "task_id": 1,
      "ref_code": "import torch...",
      "custom_code": "import torch...",
      "cuda_graph_code": "import torch...",
      "score_default": 1.762,
      "score_torch_compile_default": 1.958,
      "score_torch_compile_reduce_overhead": 2.118,
      "score_cuda_graph": 1.566
    }
  2. How to reproduce CUDA-L1 optimization results

    main

    To reproduce the performance results reported in the paper, use the optimized CUDA code snippets provided in the optimized_cuda_code directory. The snippets are organized by GPU device.

    For example, to reproduce results on an H100 device:

    1. Download the specific JSON file for your device: ./optimized_cuda_code/h100.json.
    2. Run each code snippet contained in that file on your H100 hardware.
    Download ./optimized_cuda_code/h100.json and run each code snippet on your H100 device.
  3. Reference the release code JSON schema

    main

    Each entry in the release JSON files uses the following fields:

    | Field | Description |
    |-------|-------------|
    | `level_id` | Level index in KernelBench (values: 1, 2, 3) |
    | `task_id` | Task index for that level |
    | `ref_code` | Reference CUDA code provided by KernelBench |
    | `custom_code` | Optimized code generated by CUDA-L1 |
    | `cuda_graph_code` | KernelBench reference code with CUDA Graph modifications |
    | `score_default` | Execution time ratio: ref_code / custom_code |
    | `score_torch_compile_default` | Execution time ratio: ref_code / custom_code (with torch.compile) |
    | `score_torch_compile_reduce_overhead` | Execution time ratio: ref_code / custom_code (with torch.compile reduce_overhead mode) |
    | `score_cuda_graph` | Execution time ratio: cuda_graph_code / custom_code |