// Part 3 definition-and-launch carrier inputs for loom-lower-forall-to-thread. // Each sample is a module of `dataflow.thread` definitions (dense domain, // private visibility, entry block `(args_*, thread_ctrl, coord_*)`) whose // bodies carry a mapping-free, effect-form, compile-time fixed-domain // `scf.forall` with no shared_outs, no results and an empty in_parallel // terminator, paired with the module-scope launch of each definition. start: {new NTHREADS = random.randint(1, 3); new T = 0} module_body; module_body: (T < NTHREADS) thread_unit {T += 1} module_body | (T == NTHREADS) ''; thread_unit: {new EXTRA = random.randint(0, 2); new RANK = random.randint(0, 2); new TYPES = []; new A = 0; new B = 0; new C = 0; new D = 0; new G = 0; new H = 0; new K = 0} 'dataflow.thread private @thread_' t_idx ' domain(#dataflow.thread_domain)(%buf: memref<8xi32>' extra_decls ') ctrl (%thread_ctrl: none)' iv_clause ' {\n' thread_body '}\n' host_func; t_idx: [str(T)]; // Payload arguments after the leading memref: the `args_*` prefix. extra_decls: (A < EXTRA) {TYPES.append(random.choice(['i32', 'f32', 'index']))} ', %arg' a_idx ': ' a_ty {A += 1} extra_decls | (A == EXTRA) ''; a_idx: [str(A)]; a_ty: [TYPES[A]]; // Dense coordinate suffix: one `index` slot per launch-domain dimension. iv_clause: (RANK == 0) '' | (RANK > 0) ' iv (' iv_decls ')'; iv_decls: (K < RANK) iv_sep '%coord_' k_idx ': index' {K += 1} iv_decls | (K == RANK) ''; iv_sep: (K == 0) '' | (K > 0) ', '; k_idx: [str(K)]; thread_body: ' %value = arith.constant 7 : i32\n' forall_op yield_op; // Effect-form forall: no shared_outs, no results, no mapping attribute, // compile-time fixed zero-based domain, empty in_parallel terminator. forall_op: ' scf.forall (%lane) in (' extent ') {\n' ' memref.store %value, %buf[%lane] : memref<8xi32>\n' ' }\n' | ''; extent: '2' | '4' | '8'; yield_op: ' dataflow.thread.yield\n' | ' dataflow.thread.yield %thread_ctrl : none\n'; host_func: 'func.func @host_' t_idx '() {\n' ' %buf = memref.alloc() : memref<8xi32>\n' extra_defs grid_defs ' %token = dataflow.thread.launch @thread_' t_idx '(%buf' extra_uses ')' grid_clause ' : (memref<8xi32>' extra_types ') -> !dataflow.thread_token\n' ' return\n' '}\n'; extra_defs: (B < EXTRA) ' %h' b_idx ' = ' const_rhs '\n' {B += 1} extra_defs | (B == EXTRA) ''; b_idx: [str(B)]; const_rhs: (TYPES[B] == 'i32') 'arith.constant 3 : i32' | (TYPES[B] == 'f32') 'arith.constant 1.000000e+00 : f32' | (TYPES[B] == 'index') 'arith.constant 2 : index'; extra_uses: (C < EXTRA) ', %h' c_idx {C += 1} extra_uses | (C == EXTRA) ''; c_idx: [str(C)]; extra_types: (D < EXTRA) ', ' d_ty {D += 1} extra_types | (D == EXTRA) ''; d_ty: [TYPES[D]]; grid_defs: (G < RANK) ' %g' g_idx ' = arith.constant 4 : index\n' {G += 1} grid_defs | (G == RANK) ''; g_idx: [str(G)]; grid_clause: (RANK == 0) '' | (RANK > 0) ' grid(' grid_uses ')'; grid_uses: (H < RANK) grid_sep '%g' h_idx {H += 1} grid_uses | (H == RANK) ''; grid_sep: (H == 0) '' | (H > 0) ', '; h_idx: [str(H)];