Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions ai_assistant_sample/ai_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@
7. If goal is 'low_power': prefer smaller area, lower memory usage, balanced FU count.

## Available FU Types (for tile configuration):
- Compute: add, mul, div, shift, logic
- Floating-point: fadd, fmul, fdiv, fmul_fadd, fadd_fadd, vfmul
- Control: cmp, sel, phi, loop_control
- Memory: mem, mem_indexed, constant
- Other: return, grant, alloca, type_conv
- Integer Arithmetic: alu (add/sub), mul, div, shift, mac
- Logic: logic (and/or/not/xor), cmp (icmp/fcmp), sel
- Floating-point: fadd, fmul, fdiv, fmul_fadd, fadd_fadd
- Memory: mem (load/store), mem_indexed, alloca, gep, memset
- Type: type_conv, constant
- Control: phi, return, branch, loop_control
- Data Movement: data_mov, ctrl_mov, reserve, data
- Grants: grant
- Vector: vadd, vmul, vfmul, vector

IMPORTANT: By default, all FU types should be enabled in every tile whenever we design a CGRA.
The full FU list is: ["add", "mul", "div", "fadd", "fmul", "fdiv", "logic", "cmp", "sel", "type_conv", "vfmul", "fadd_fadd", "fmul_fadd", "loop_control", "phi", "constant", "mem", "mem_indexed", "shift", "return", "alloca", "grant"]
The full FU list is: ["alu", "mul", "div", "shift", "mac", "logic", "cmp", "sel", "fadd", "fmul", "fdiv", "fmul_fadd", "fadd_fadd", "mem", "mem_indexed", "alloca", "gep", "memset", "type_conv", "constant", "phi", "return", "branch", "loop_control", "data_mov", "ctrl_mov", "reserve", "data", "grant", "vadd", "vmul", "vfmul", "vector"]
IMPORTANT: Use exactly these FU names. Do NOT use instruction names (e.g., use "alu" not "add", use "mem" not "load").
For low_power designs, you may remove some FUs, but ALWAYS keep at minimum: alu, mul, cmp, sel, phi, constant, mem, gep, return, branch, data_mov, ctrl_mov, reserve, data, grant

When recommending CGRA configurations, provide THREE options:

Expand All @@ -72,7 +78,7 @@
"data_spm_kb": <4-64>,
"multi_cgra_rows": <1-4>,
"multi_cgra_columns": <1-4>,
"fu_types": ["add", "mul", "div", ...],
"fu_types": ["alu", "mul", "div", ...],
"explanation": "<high_performance optimization reasoning>"
},
"balanced": {
Expand All @@ -82,7 +88,7 @@
"data_spm_kb": <4-64>,
"multi_cgra_rows": <1-4>,
"multi_cgra_columns": <1-4>,
"fu_types": ["add", "mul", ...],
"fu_types": ["alu", "mul", ...],
"explanation": "<balanced trade-off reasoning>"
},
"low_power": {
Expand All @@ -92,7 +98,7 @@
"data_spm_kb": <4-64>,
"multi_cgra_rows": <1-4>,
"multi_cgra_columns": <1-4>,
"fu_types": ["add", "mul", ...],
"fu_types": ["alu", "mul", ...],
"explanation": "<power saving reasoning>"
}
}
Expand Down Expand Up @@ -127,18 +133,15 @@
# Kernel examples with DFG characteristics and recommended configurations

ALL_FU_TYPES = [
"add", "mul", "div",
"fadd", "fmul", "fdiv",
"alu", "mul", "div", "shift", "mac",
"logic", "cmp", "sel",
"type_conv",
"vfmul",
"fadd_fadd", "fmul_fadd",
"loop_control", "phi",
"constant",
"mem", "mem_indexed",
"shift",
"return", "alloca",
"fadd", "fmul", "fdiv", "fmul_fadd", "fadd_fadd",
"mem", "mem_indexed", "alloca", "gep", "memset",
"type_conv", "constant",
"phi", "return", "branch", "loop_control",
"data_mov", "ctrl_mov", "reserve", "data",
"grant",
"vadd", "vmul", "vfmul", "vector",
]

RAG_KERNEL_DATABASE = {
Expand Down
2 changes: 2 additions & 0 deletions openspec/changes/fix-ai-fu-types-mapping/.openspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-02-27
47 changes: 23 additions & 24 deletions src/Workspace.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
updatePeConnectionsForDirection
} from './workspace/peConnections.js';
import { collectArchitectureOps } from './workspace/opMapping';
import { DEFAULT_FUNCTION_UNITS } from './shared/functionalUnitMapping.js';
import {
DesignTab,
MappingTab,
Expand Down Expand Up @@ -807,30 +808,33 @@ function Workspace() {
const newDataSpmKb = config.data_spm_kb || 8;
const fuTypes = config.fu_types || [];

// Build the tileFunctionalUnits config using canonical FU names
// Uses DEFAULT_FUNCTION_UNITS from functionalUnitMapping.js as the source of truth
const buildFuConfig = (fuList) => {
const fuConfig = {};
const allFuNames = Object.keys(DEFAULT_FUNCTION_UNITS);
if (fuList.length > 0) {
allFuNames.forEach((fu) => {
fuConfig[fu] = fuList.includes(fu);
});
} else {
// No FU types specified - enable all
allFuNames.forEach((fu) => {
fuConfig[fu] = true;
});
}
return fuConfig;
};

const fuConfig = buildFuConfig(fuTypes);

// Build updated CGRAs with new dimensions and FU types
const updatedCgras = (currentArch.CGRAs || []).map((cgra, index) => {
// Update FU types for each PE
const updatedPEs = (cgra.PEs || []).map((pe) => {
const newFuConfig = {};
// Set all FU types based on config
const allFuTypes = ['add', 'mul', 'div', 'fadd', 'fmul', 'fdiv', 'logic', 'cmp', 'sel',
'type_conv', 'vfmul', 'fadd_fadd', 'fmul_fadd', 'loop_control', 'phi',
'constant', 'mem', 'mem_indexed', 'shift', 'return', 'alloca', 'grant'];

allFuTypes.forEach((fu) => {
newFuConfig[fu] = fuTypes.includes(fu) ? 1 : 1; // Enable all by default
});

// If fuTypes is specified, enable only those
if (fuTypes.length > 0) {
allFuTypes.forEach((fu) => {
newFuConfig[fu] = fuTypes.includes(fu) ? 1 : 0;
});
}

return {
...pe,
tileFunctionalUnits: newFuConfig
tileFunctionalUnits: { ...fuConfig }
};
});

Expand Down Expand Up @@ -875,12 +879,7 @@ function Workspace() {
x: i % newPerCgraColumns,
y: Math.floor(i / newPerCgraColumns),
disabled: false,
tileFunctionalUnits: fuTypes.length > 0
? Object.fromEntries(['add', 'mul', 'div', 'fadd', 'fmul', 'fdiv', 'logic', 'cmp', 'sel',
'type_conv', 'vfmul', 'fadd_fadd', 'fmul_fadd', 'loop_control', 'phi',
'constant', 'mem', 'mem_indexed', 'shift', 'return', 'alloca', 'grant']
.map(fu => [fu, fuTypes.includes(fu) ? 1 : 0]))
: cgra.PEs?.[0]?.tileFunctionalUnits || {}
tileFunctionalUnits: { ...fuConfig }
}))
)
}));
Expand Down
2 changes: 1 addition & 1 deletion src/shared/functionalUnitMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export function functionUnitsToInstructions(functionalUnits) {
const instructions = [];

for (const [unitName, enabled] of Object.entries(functionalUnits)) {
if (enabled === true && FUNCTION_UNIT_TO_INSTRUCTIONS[unitName]) {
if (enabled && FUNCTION_UNIT_TO_INSTRUCTIONS[unitName]) {
instructions.push(...FUNCTION_UNIT_TO_INSTRUCTIONS[unitName]);
}
}
Expand Down
24 changes: 15 additions & 9 deletions src/workspace/services/aiApiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,20 @@ export const SYSTEM_PROMPT = `You are an AI assistant for CGRA-Flow, a framework
* Low power: 1x1 (single CGRA)

## Available FU Types (for tile configuration):
- Compute: add, mul, div, shift, logic
- Floating-point: fadd, fmul, fdiv, fmul_fadd, fadd_fadd, vfmul
- Control: cmp, sel, phi, loop_control
- Memory: mem, mem_indexed, constant
- Other: return, grant, alloca, type_conv
- Integer Arithmetic: alu (add/sub), mul, div, shift, mac
- Logic: logic (and/or/not/xor), cmp (icmp/fcmp), sel
- Floating-point: fadd, fmul, fdiv, fmul_fadd, fadd_fadd
- Memory: mem (load/store), mem_indexed, alloca, gep, memset
- Type: type_conv, constant
- Control: phi, return, branch, loop_control
- Data Movement: data_mov, ctrl_mov, reserve, data
- Grants: grant
- Vector: vadd, vmul, vfmul, vector

IMPORTANT: By default, all FU types should be enabled in every tile whenever we design a CGRA.
The full FU list is: ["add", "mul", "div", "fadd", "fmul", "fdiv", "logic", "cmp", "sel", "type_conv", "vfmul", "fadd_fadd", "fmul_fadd", "loop_control", "phi", "constant", "mem", "mem_indexed", "shift", "return", "alloca", "grant"]
The full FU list is: ["alu", "mul", "div", "shift", "mac", "logic", "cmp", "sel", "fadd", "fmul", "fdiv", "fmul_fadd", "fadd_fadd", "mem", "mem_indexed", "alloca", "gep", "memset", "type_conv", "constant", "phi", "return", "branch", "loop_control", "data_mov", "ctrl_mov", "reserve", "data", "grant", "vadd", "vmul", "vfmul", "vector"]
IMPORTANT: Use exactly these FU names. Do NOT use instruction names (e.g., use "alu" not "add", use "mem" not "load").
For low_power designs, you may remove some FUs, but ALWAYS keep at minimum: alu, mul, cmp, sel, phi, constant, mem, gep, return, branch, data_mov, ctrl_mov, reserve, data, grant
Comment on lines 59 to +75

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

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

PR title/description suggest a narrow FU-types mapping fix, but this PR also adds/changes verification UI, runner executors (run_tests/synthesis), Docker image toolchain installs, and checks in large generated Verilog/Verilator artifacts. Please update the PR title/description (or split into smaller PRs) so reviewers can scope risk and intent accurately.

Copilot uses AI. Check for mistakes.

When recommending CGRA configurations, provide THREE options:

Expand All @@ -79,7 +85,7 @@ When recommending CGRA configurations, provide THREE options:
"data_spm_kb": <4-64>,
"multi_cgra_rows": <1-4>,
"multi_cgra_columns": <1-4>,
"fu_types": ["add", "mul", "div", ...],
"fu_types": ["alu", "mul", "div", "shift", "mac", "logic", "cmp", "sel", "fadd", "fmul", "fdiv", "fmul_fadd", "fadd_fadd", "mem", "mem_indexed", "alloca", "gep", "memset", "type_conv", "constant", "phi", "return", "branch", "loop_control", "data_mov", "ctrl_mov", "reserve", "data", "grant", "vadd", "vmul", "vfmul", "vector"],
"explanation": "<high_performance optimization reasoning>"
},
"balanced": {
Expand All @@ -89,7 +95,7 @@ When recommending CGRA configurations, provide THREE options:
"data_spm_kb": <4-64>,
"multi_cgra_rows": <1-4>,
"multi_cgra_columns": <1-4>,
"fu_types": ["add", "mul", ...],
"fu_types": ["alu", "mul", "cmp", "sel", "phi", "constant", "mem", "gep", "return", "branch", ...],
"explanation": "<balanced trade-off reasoning>"
},
"low_power": {
Expand All @@ -99,7 +105,7 @@ When recommending CGRA configurations, provide THREE options:
"data_spm_kb": <4-64>,
"multi_cgra_rows": <1-4>,
"multi_cgra_columns": <1-4>,
"fu_types": ["add", "mul", ...],
"fu_types": ["alu", "mul", "cmp", "sel", "phi", "constant", "mem", "gep", "return", "branch", ...],
"explanation": "<power saving reasoning>"
}
}
Expand Down
44 changes: 24 additions & 20 deletions src/workspace/services/aiConfigExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Parses AI responses and extracts validated CGRA configurations
*/

import { getAllFunctionUnits, getUnitForInstruction, FUNCTION_UNIT_TO_INSTRUCTIONS } from '../../shared/functionalUnitMapping.js';

Copilot AI Feb 27, 2026

Copy link

Choose a reason for hiding this comment

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

The imported symbol FUNCTION_UNIT_TO_INSTRUCTIONS is not used anywhere in this file. It should be removed from the import statement to keep the code clean.

Suggested change
import { getAllFunctionUnits, getUnitForInstruction, FUNCTION_UNIT_TO_INSTRUCTIONS } from '../../shared/functionalUnitMapping.js';
import { getAllFunctionUnits, getUnitForInstruction } from '../../shared/functionalUnitMapping.js';

Copilot uses AI. Check for mistakes.

Comment on lines +6 to +7

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

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

FUNCTION_UNIT_TO_INSTRUCTIONS is imported here but never used in this module. This will trip linting/CI in many setups and makes it harder to see what dependencies are actually required. Remove the unused import (or start using it).

Copilot uses AI. Check for mistakes.
// Valid parameter ranges for validation
const VALID_CONFIG_RANGES = {
cgra_rows: { min: 2, max: 8 },
Expand All @@ -13,21 +15,8 @@ const VALID_CONFIG_RANGES = {
multi_cgra_columns: { min: 1, max: 4 }
};

// Default FU types (all enabled)
const DEFAULT_FU_TYPES = [
'add', 'mul', 'div',
'fadd', 'fmul', 'fdiv',
'logic', 'cmp', 'sel',
'type_conv',
'vfmul',
'fadd_fadd', 'fmul_fadd',
'loop_control', 'phi',
'constant',
'mem', 'mem_indexed',
'shift',
'return', 'alloca',
'grant'
];
// Default FU types - derived from the canonical source in functionalUnitMapping.js
const DEFAULT_FU_TYPES = getAllFunctionUnits();

/**
* Validate and fix a single configuration
Expand Down Expand Up @@ -106,14 +95,29 @@ export function validateAndFixConfig(config) {
}
fixedConfig.multi_cgra_columns = mcCols;

// Validate fu_types
// Validate fu_types - normalize instruction names to FU names
let fuTypes = config.fu_types ?? DEFAULT_FU_TYPES;
if (Array.isArray(fuTypes)) {
const validFus = fuTypes.filter(fu => DEFAULT_FU_TYPES.includes(fu));
if (validFus.length !== fuTypes.length) {
fixes.push(`Removed invalid FU types from list`);
// Map each entry: if it's a valid FU name keep it, if it's an instruction name resolve to its FU
const resolvedFus = new Set();
const invalidEntries = [];
for (const entry of fuTypes) {
if (DEFAULT_FU_TYPES.includes(entry)) {
resolvedFus.add(entry);
} else {
// Try to resolve as an instruction name
const unit = getUnitForInstruction(entry);
if (unit) {
resolvedFus.add(unit);
} else {
invalidEntries.push(entry);
}
}
}
if (invalidEntries.length > 0) {
fixes.push(`Resolved/removed invalid FU types: ${invalidEntries.join(', ')}`);
}
fixedConfig.fu_types = validFus.length > 0 ? validFus : DEFAULT_FU_TYPES;
fixedConfig.fu_types = resolvedFus.size > 0 ? [...resolvedFus] : DEFAULT_FU_TYPES;
Comment on lines +117 to +120

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

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

The fix message says "Resolved/removed invalid FU types" but it only lists entries that were not resolved (i.e., those pushed into invalidEntries). This is misleading when debugging AI config repairs. Consider splitting this into two lists (resolved instruction names vs removed invalid entries) or adjust the message to match what’s actually reported.

Copilot uses AI. Check for mistakes.
} else {
fixedConfig.fu_types = DEFAULT_FU_TYPES;
}
Expand Down
Loading