Skip to content
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

Add support for pairwise_widening_add in wasm #5850

Merged
merged 12 commits into from
Mar 29, 2021

Conversation

steven-johnson
Copy link
Contributor

No description provided.

@steven-johnson steven-johnson changed the base branch from master to srj/wasm-widening-mul March 25, 2021 00:52
case VectorReduce::Add:
accumulator += v;
break;
case VectorReduce::Min:
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no intrinsic for this case is there? Maybe this should just be internal_assert(op->op == VectorReduce::Add) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, copypasta from CodegenARM and I was lazy about cutting it down. Will do.

const char *intrin = nullptr;
std::vector<Expr> intrin_args;
Expr accumulator = init;
if (op->op == VectorReduce::Add && factor == 2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to do this with a pattern, even if there is only one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, but FWIW, this was taken directly from the existing code in Codegen_ARM, which doesn't use a pattern here. (Maybe I should backport it there afterwards...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(the source in Codegen_ARM has the comment: // TODO: Move this to be patterns? The patterns are pretty trivial, but some of the other logic is tricky, which got lost in translation.)

};

check("i16x8.extadd_pairwise_i8x16_s", 8 * w, sum_(i16(in_i8(f * x + r))));
check("i16x8.extadd_pairwise_i8x16_u", 8 * w, sum_(u16(in_u8(f * x + r))));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should also check for signed widening from unsigned operands, e.g.: https://github.com/halide/Halide/blob/master/src/CodeGen_ARM.cpp#L1139

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There isn't a wasm instruction that does this -- just i8->i16 and u8->u16 (and wider variants).

I guess we could just use the u8->u16 op in this case and cast the result to i16, on the assumption that the u16 result will always have a zero sign bit for 128-bit vectors....

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's all the ARM and other targets are doing anyways. I'm not actually sure you need to change the implementation at all, it might just work (and the ARM version might be redundant too), but I think we should test for it.

Base automatically changed from srj/wasm-widening-mul to master March 25, 2021 16:40
@steven-johnson
Copy link
Contributor Author

PTAL

@steven-johnson
Copy link
Contributor Author

Monday Morning Review Ping


namespace Halide {
namespace Internal {

using std::string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to change this here? Most of the other backends do this (and don't quality string with std::).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a mixture of usage so I normalize to std:: since that is the pattern in most non-backend code. Will normalize the other way if that's the unspoken standard here.

int factor;
Expr pattern;
const char *intrin;
Type narrow_type;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need this, all of the patterns have the narrow type the same as the pattern's type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the moment, yes, but I'm not sure if that will be the case for everything, and I wanted to preserve this logic (adapted from Codegen_X86.cpp). That said, easy enough to restore if/when it's needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should just add it when needed. It adds a fair bit of code that is currently dead. Note that CodeGen_ARM doesn't have either of these.

Expr pattern;
const char *intrin;
Type narrow_type;
uint32_t flags;
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this either, no patterns use any flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above, ditto.

while (getline(asm_file, line)) {
msg << line << "\n";
{
std::ifstream asm_file;
Copy link
Contributor

Choose a reason for hiding this comment

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

What actually changed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

code restructuring that no longer matters. Will revert.

@steven-johnson steven-johnson merged commit 07f880e into master Mar 29, 2021
@steven-johnson steven-johnson deleted the srj/wasm-widening-add branch March 29, 2021 23:37
gasparitiago pushed a commit to gasparitiago/Halide that referenced this pull request Mar 30, 2021
@alexreinking alexreinking added this to the v12.0.0 milestone May 19, 2021
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.

None yet

3 participants