-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable bfloat16 for micro sdpa kernel #2344
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,7 +227,11 @@ status_t micro_sdpa_t::pd_t::init_microkernels(impl::engine_t *engine) { | |
GEMMProblem problem; | ||
problem.Ta_ext = jit::convert_dnnl_to_kernel_type(key_md()->data_type); | ||
problem.Tb_ext = jit::convert_dnnl_to_kernel_type(qry_md()->data_type); | ||
problem.Ta = problem.Tb = Type::f16; | ||
if (qry_md()->data_type == data_type::f16) { | ||
problem.Ta = problem.Tb = Type::f16; | ||
} else { // data_type is bf16 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. else if, and else for error/unimplemented. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its not needed since the init function will return if its not f16 or bf16. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the next data type will start being supported, it would be more difficult to find this particular spot what goes wrong instead of catching nicely here. This is about being nice to others in the future, not about the current state in the present. |
||
problem.Ta = problem.Tb = Type::bf16; | ||
} | ||
problem.Tc = problem.Tc_ext = Type::f32; | ||
problem.Ts = problem.Tc; | ||
|
||
|
@@ -398,7 +402,11 @@ status_t micro_sdpa_t::init(impl::engine_t *engine) { | |
kernel_ctx.define_int("NDIMS", ndims); | ||
|
||
def_data_type(kernel_ctx, key_mdw.data_type(), "KEY"); | ||
def_data_type(kernel_ctx, qry_mdw.data_type(), "QRY"); | ||
def_data_type(kernel_ctx, val_mdw.data_type(), "VAL"); | ||
def_data_type(kernel_ctx, dst_mdw.data_type(), "DST"); | ||
def_data_type(kernel_ctx, | ||
pd()->with_attn_mask() ? msk_mdw.data_type() : dnnl_f32, "MSK"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If no mask, shouldn't data type be undef to catch error earlier? Maybe make a normal name "MASK", not sure I see the value of shorting one letter out... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The kernel is written in a way that mask has to be defined in any case. Its unavoidable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mind to put a comment on this regard next to this line for other developers in a separate PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can follow it up with since I still have to create a PR for enabling quantization for bf16. |
||
|
||
def_data_type(kernel_ctx, pd()->key_scales_dt(), "KEY_ATTR_SCALES"); | ||
def_data_type(kernel_ctx, pd()->value_scales_dt(), "VAL_ATTR_SCALES"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.