// Input domain: the definition-and-launch carrier shape that Part 3 accepts // for an effect-form forall selected as an AccCore thread domain // (docs/spec-compiler-part-3-dfg.md lines 2057-2061). Each module carries one // or more module-scope `dataflow.thread` definitions (private visibility, a // closed dense or dynamic-work domain, the `(args_*, thread_ctrl, coord_*)` // entry block) and one host `func.func` holding the matching // `dataflow.thread.launch` ops. No `scf.forall` is emitted: a graph-owned // forall retained by Part 2 is mapping-free, effect-form and fixed-domain, and // this boundary carries no shared_outs, results or combining action. start: {new TYPE_NAMES = ['i32', 'f32', 'i64', 'index', 'memref', 'i32', 'f32', 'i64', 'index', 'memref']; new VALUE_NAMES = ['%c_i32', '%c_f32', '%c_i64', '%c_idx', '%m_ref', '%c_i32', '%c_f32', '%c_i64', '%c_idx', '%m_ref']; new NUM = random.randint(1, 3); new ARITIES = []; new OFFSETS = []; new RANKS = []; new IDX = 0} thread_defs {IDX = 0} 'func.func @host(%m_ref: memref) {\n' ' %c_i32 = arith.constant 1 : i32\n' ' %c_f32 = arith.constant 1.000000e+00 : f32\n' ' %c_i64 = arith.constant 1 : i64\n' ' %c_idx = arith.constant 4 : index\n' launches ' return\n' '}\n'; thread_defs: (IDX < NUM) thread_def {IDX += 1} thread_defs | (IDX == NUM) ''; // Arity, argument types and coordinate rank are sampled per definition and // recorded so the launch side can reproduce the same signature. thread_def: {new ARITY = random.randint(0, 3); new OFFSET = random.randint(0, 4); new RANK = random.randint(0, 2); new DYN_SEL = random.choice([0, 1]); new ORDINAL = 0} thread_shape; thread_shape: (ARITY > 0 and DYN_SEL == 1) {RANK = 0; ORDINAL = random.randint(0, ARITY - 1)} dynamic_def | (ARITY == 0 or DYN_SEL == 0) dense_def; // A dynamic definition has coordinate rank zero and its ordinal selects // exactly one function_type input. dynamic_def: {ARITIES.append(ARITY); OFFSETS.append(OFFSET); RANKS.append(0)} 'dataflow.thread private @' def_symbol ' domain(#dataflow.thread_domain)' def_args ' ctrl (%thread_ctrl: none) {\n' terminator '}\n\n'; // A dense definition has no work-item ordinal and carries one `index` // coordinate argument per launch-domain dimension. dense_def: {ARITIES.append(ARITY); OFFSETS.append(OFFSET); RANKS.append(RANK)} 'dataflow.thread private @' def_symbol ' domain(#dataflow.thread_domain)' def_args ' ctrl (%thread_ctrl: none)' coord_clause ' {\n' terminator '}\n\n'; def_symbol: 't_' index_text; index_text: [str(IDX)]; ordinal_text: [str(ORDINAL)]; terminator: ' dataflow.thread.yield\n' | ' dataflow.thread.yield %thread_ctrl : none\n'; def_args: {new J = 0} '(' def_arg_list ')'; def_arg_list: (J < ARITY) arg_sep def_arg {J += 1} def_arg_list | (J == ARITY) ''; arg_sep: (J == 0) '' | (J > 0) ', '; def_arg: '%arg_' arg_index ': ' arg_type; arg_index: [str(J)]; arg_type: [TYPE_NAMES[OFFSET + J]]; coord_clause: (RANK == 0) '' | (RANK > 0) {new K = 0} ' iv (' coord_list ')'; coord_list: (K < RANK) coord_sep coord_arg {K += 1} coord_list | (K == RANK) ''; coord_sep: (K == 0) '' | (K > 0) ', '; coord_arg: '%coord_' coord_index ': index'; coord_index: [str(K)]; // One launch per definition; body operands reproduce function_type.inputs and // the grid upper bounds match the definition's coordinate rank. launches: (IDX < NUM) launch {IDX += 1} launches | (IDX == NUM) ''; launch: {new ARITY = ARITIES[IDX]; new OFFSET = OFFSETS[IDX]; new RANK = RANKS[IDX]} ' %token_' index_text ' = dataflow.thread.launch @t_' index_text launch_operands grid_clause ' : ' launch_signature ' -> !dataflow.thread_token\n' wait_clause; wait_clause: '' | ' dataflow.thread.wait %token_' index_text ' : !dataflow.thread_token\n'; launch_operands: {new J = 0} '(' launch_operand_list ')'; launch_operand_list: (J < ARITY) arg_sep launch_operand {J += 1} launch_operand_list | (J == ARITY) ''; launch_operand: operand_name; operand_name: [VALUE_NAMES[OFFSET + J]]; grid_clause: (RANK == 0) '' | (RANK > 0) {new K = 0} ' grid(' grid_list ')'; grid_list: (K < RANK) coord_sep grid_bound {K += 1} grid_list | (K == RANK) ''; grid_bound: '%c_idx'; launch_signature: {new J = 0} '(' launch_type_list ')'; launch_type_list: (J < ARITY) arg_sep launch_type {J += 1} launch_type_list | (J == ARITY) ''; launch_type: arg_type;