Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ const rocke_type_t*
return t;
}

/* SmemType(elem, shape) -> "smem<{elem}, [{d0}x{d1}...]>" */
const rocke_type_t*
rocke_smem_type(rocke_ir_builder_t* b, const rocke_type_t* elem, const int* shape, int rank)
/* SmemType(elem, shape) -> "smem<{elem}, [{d0}x{d1}...]>"
* `exclusive` is kept OUT of the name (default 0 stays byte-identical). */
const rocke_type_t* rocke_smem_type(
rocke_ir_builder_t* b, const rocke_type_t* elem, const int* shape, int rank, int exclusive)
{
rocke_type_t* t;
int* shape_copy = NULL;
Expand All @@ -146,6 +147,9 @@ const rocke_type_t*
if(!elem)
return (const rocke_type_t*)rocke_i_set_err(
b, ROCKE_ERR_VALUE, "smem_type: NULL element type");
if(exclusive != 0 && exclusive != 1)
return (const rocke_type_t*)rocke_i_set_err(
b, ROCKE_ERR_VALUE, "smem_type: exclusive must be 0 or 1, got %d", exclusive);
if(rank < 0)
rank = 0;

Expand All @@ -166,6 +170,7 @@ const rocke_type_t*
t->elem = elem;
t->shape = shape_copy;
t->rank = rank;
t->smem_exclusive = exclusive; /* guarded to 0/1 above */

/* Build the "[d0xd1x...]" body, then the full canonical name. The Python
* form is f"smem<{elem.name}, [{'x'.join(...)}]>". */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,46 @@ static rocke_value_t** rocke_build_mem_operands(rocke_ir_builder_t* b,
/* LDS (shared memory) -- alloc */
/* ===================================================================== */

rocke_value_t* rocke_b_smem_alloc(rocke_ir_builder_t* b,
const rocke_type_t* elem,
const int* shape,
int rank,
const char* name_hint)
rocke_value_t* rocke_b_smem_alloc_ex(rocke_ir_builder_t* b,
const rocke_type_t* elem,
const int* shape,
int rank,
const char* name_hint,
int exclusive)
{
const rocke_type_t* t;
rocke_attr_map_t attrs;
const rocke_attr_map_t* attrs_p = NULL;
if(!rocke_i_live(b))
{
return NULL;
}
t = rocke_smem_type(b, elem, shape, rank);
t = rocke_smem_type(b, elem, shape, rank, exclusive);
if(!t)
{
return NULL;
}
/* Carry the exclusive bit as an op attr so it round-trips through the
* ck.dsl.ir/v1 serializer (the type name deliberately omits it). Only
* emitted when set, so the default stays byte-identical. Ignored by the
* native .ll lowering (which reads the SmemType's smem_exclusive). */
if(exclusive)
{
attrs = rocke_i_attrs(b);
rocke_attr_set_bool(b, &attrs, "exclusive", true);
attrs_p = &attrs;
}
return rocke_i_op1(
b, ROCKE_OP_TILE_SMEM_ALLOC, NULL, 0, t, NULL, name_hint ? name_hint : "smem");
b, ROCKE_OP_TILE_SMEM_ALLOC, NULL, 0, t, attrs_p, name_hint ? name_hint : "smem");
}

rocke_value_t* rocke_b_smem_alloc(rocke_ir_builder_t* b,
const rocke_type_t* elem,
const int* shape,
int rank,
const char* name_hint)
{
return rocke_b_smem_alloc_ex(b, elem, shape, rank, name_hint, 0);
}

/* ===================================================================== */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,8 @@ static const rocke_type_t* parse_type(rocke_ir_builder_t* b, const char* s, size
}
}
}
return rocke_smem_type(b, elem, shape, rank);
/* exclusive is reconstructed from the op attr in parse_op (name-only). */
return rocke_smem_type(b, elem, shape, rank, 0);
}

/* scalar: reconstruct the singleton by name. */
Expand Down Expand Up @@ -1859,6 +1860,21 @@ static rocke_op_t* parse_op(rocke_ir_builder_t* b, line_reader_t* lr, val_table_
op->num_operands = num_operands;
}

/* The smem type name deliberately omits the `exclusive` bit; it rides on
* the smem_alloc op as an attr. Rebuild the result SmemType with exclusive
* set so the packer's no-alias behavior round-trips through the serializer. */
if(opcode == ROCKE_OP_TILE_SMEM_ALLOC && num_results > 0 && result_types[0]
&& result_types[0]->kind == ROCKE_TYPE_SMEM
&& rocke_attr_get_bool(&attrs, "exclusive", false))
{
result_types[0] = rocke_smem_type(
b, result_types[0]->elem, result_types[0]->shape, result_types[0]->rank, 1);
if(!result_types[0])
{
return NULL;
}
}

if(num_results > 0)
{
op->results = (rocke_value_t**)rocke_arena_alloc(
Expand Down
Loading
Loading