Skip to content

Add cl_khr_cooperative_matrix OpenCL C extension - #1627

Open
asudarsa-qti wants to merge 9 commits into
KhronosGroup:mainfrom
asudarsa-qti:cl_ext_kernel_cooperative_matrix1
Open

asudarsa-qti wants to merge 9 commits into
KhronosGroup:mainfrom
asudarsa-qti:cl_ext_kernel_cooperative_matrix1

Conversation

@asudarsa-qti

Copy link
Copy Markdown

No description provided.

AlexGalazin-IMG and others added 8 commits May 29, 2025 13:16
…invocation

update the sizeof operation description for coop matrix (result is total size for entire scope)
add saturation modes
fix various typos
Signed-off-by: Arvind Sudarsanam <asudarsa@qti.qualcomm.com>
Signed-off-by: Arvind Sudarsanam <asudarsa@qti.qualcomm.com>
@CLAassistant

CLAassistant commented Sep 29, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 3 committers have signed the CLA.

✅ asudarsa-qti
❌ tomasz-platek
❌ AlexGalazin-IMG
You have signed the CLA already but the status is still pending? Let us recheck it.

void coop_mat_store(const gentype *p, component_type __attribute__((coop_mat(...))) m, const coop_matrix_layout_t layout, const size_t _stride);
component_type __attribute__((coop_mat(...))) coop_mat_mulAdd(component_type __attribute__((coop_mat(...))) A, component_type __attribute__((coop_mat(...))) B, component_type __attribute__((coop_mat(...))) C);
component_type __attribute__((coop_mat(...))) coop_mat_mulAdd(component_type __attribute__((coop_mat(...))) A, component_type __attribute__((coop_mat(...))) B, component_type __attribute__((coop_mat(...))) C, coop_matrix_operands_t matrix_operands);
uint coop_mat_length(component_type __attribute__((coop_mat(...))) m);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is coop_mat_init missing from this list?


[source,c]
----
component_type __attribute__((coop_mat(...))) coop_mat_load(const gentype p, const coop_matrix_layout_t layout, const size_t stride);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggesting to manually line-wrap the longer lines here to improve readability.

=== (Add to Section 6.4.3. *Explicit Conversions*) :

Conversions are allowed between cooperative matrix type only if
the scope, row, column, and use parameters are the same.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Section 6.4.3 says

Explicit conversions may be performed using the

convert_destType(sourceType)

suite of functions.

Are we defining any new forms of convert_* here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm confused, there are 2 files with the same content now?

== Version

Built On: {docdate} +
Version: 1.0.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be 2.0.0 I think; version 1 is #1533


[source,c]
----
__opencl_c_ext_cooperative_matrix

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
__opencl_c_ext_cooperative_matrix
__opencl_c_khr_cooperative_matrix

----

enum coop_matrix_operands_t
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think all of the enum values may need a _KHR suffix. And maybe the enums themselves and functions too, though I'm not 100% sure.

== Dependencies

This extension is written against the OpenCL 3.0 C Language specification and the OpenCL SPIR-V Environment specification, V3.0.8.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps we should also mention the dependency on cl_khr_cooperative_matrix version 1.0.0 (which brings the API and SPIR-V parts)?


== Modifications to the OpenCL C Specification

=== (Add a new Section 6.3.X, *Cooperative Matrix Type*) :

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
=== (Add a new Section 6.3.X, *Cooperative Matrix Type*) :
=== (Add a new Section 6.3.X, *Cooperative Matrix Types*) :

----
coop_mat -> OpTypeCooperativeMatrixKHR
coop_mat_init(scalar value) -> OpConstantComposite
coop_mat_init(coop_mat) -> Op*Convert, OpConvert*To*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This variant of coop_mat_init isn't explained further down.

If _layout_ is `CLK_COOPERATIVE_MATRIX_LAYOUT_COLUMN_MAJOR`,
then elements (*,col) of the result are taken in
order from contiguous locations starting at _p_ + _col_*_stride_.
| void **coop_mat_store**(const gentype *_p_, coop_mat _m_, const coop_matrix_layout_t _layout_, const size_t _stride_);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
| void **coop_mat_store**(const gentype *_p_, coop_mat _m_, const coop_matrix_layout_t _layout_, const size_t _stride_);
| void **coop_mat_store**(gentype *_p_, coop_mat _m_, const coop_matrix_layout_t _layout_, const size_t _stride_);

?

enum coop_matrix_operands_t
{
CLK_COOPERATIVE_MATRIX_OPERAND_NONE = 0,
CLK_COOPERATIVE_MATRIX_OPERAND_MATRIX_A_SIGNED = 0x10,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are we deliberately deviating from the SPV_KHR_cooperative_matrix "Cooperative Matrix Operands" values?


The arithmetic binary operators add (+), subtract (-), multiply (*), and
divide (/) operate on cooperative matrix types and perform the operation
component-wise. The operands must have identical types.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we say something about uniformity of the operands?

[cols="7,3",options="header",]
|====
| Function | Description
| coop_mat **coop_mat_load**(const gentype *_p_, const coop_matrix_layout_t _layout_, const size_t _stride_)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a "first" for OpenCL I think: the full return type cannot be determined from the arguments/function name. Which means something like coop_mat_length(coop_mat_load(p, layout, stride)) cannot work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants