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 ConcatenateN Subgraph #7642

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

RahulSundarMCW
Copy link
Contributor

@RahulSundarMCW RahulSundarMCW commented Jan 6, 2025

  • Replaced existing concatenate2, concatenate3, concatenate4, concatenate5, tests with a single test covering the Concatenate API.
  • Marked old functions as XNN_DEPRECATED.
  • Added shims in deprecated.c to call the new Concatenate API functions.
  • Ensured the subgraph API remains stable with the new implementation.

  - Replaced existing concatenate2, concatenate3, concatenate4, concatenate5, tests with a single test covering the ConcatenateN API.
  - Marked old functions as XNN_DEPRECATED.
  - Added shims in deprecated.c to call the new EvenSplitN API functions.
  - Ensured the subgraph API remains stable with the new implementation.
size_t num_values,
pthreadpool_t threadpool)
{
return reshape_concatenate_n_operator(opdata, values, num_values, opdata->num_inputs, threadpool);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the num_inputs parameter now that we don't use it It looks like you just don't need these wrappers at all any more.

{
return setup_concatenate_n_operator(opdata, values, num_values, opdata->num_inputs, threadpool);
}

enum xnn_status xnn_define_concatenate_n(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't need this any more. I think you should just rename this xnn_define_concatenate and remove the new function below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We pass node_type while calling xnn_define_concatenate_n() from xnn_define_concatenate() and renamed xnn_define_concatenate_n to xnn_define_concatenate_impl.

@@ -17,6 +17,7 @@ XNN_ENUM_ITEM(xnn_node_type_concatenate2, "Concatenate2")
XNN_ENUM_ITEM(xnn_node_type_concatenate3, "Concatenate3")
XNN_ENUM_ITEM(xnn_node_type_concatenate4, "Concatenate4")
XNN_ENUM_ITEM(xnn_node_type_concatenate5, "Concatenate5")
XNN_ENUM_ITEM(xnn_node_type_concatenate_n, "ConcatenateN")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just call it concatenate. Also, remove the xnn_node_type_concatenateX if they are unused now.

SubgraphTester& AddConcatenate2(size_t axis, uint32_t input1_id, uint32_t input2_id, uint32_t output_id) {
const xnn_status status = xnn_define_concatenate2(
subgraph_.get(), axis, input1_id, input2_id, output_id, 0 /* flags */);
SubgraphTester& AddConcatenate2(size_t axis, uint32_t input1_id, uint32_t input2_id, uint32_t output_id) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fix indentation

@@ -149,7 +116,7 @@ static enum xnn_status reshape_concatenate_n_operator(
{
enum xnn_status status;

assert(opdata->num_inputs == num_inputs);
num_inputs = opdata->num_inputs;
Copy link
Collaborator

Choose a reason for hiding this comment

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

There needs to be an error check here, that num_inputs <= XNN_MAX_OPERATOR_OJBECTS

@@ -0,0 +1,708 @@
// Copyright 2022 Google LLC
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rename to concatenate.cc


size_t RandomNumInputs()
{
return std::uniform_int_distribution<size_t>(2, 5)(rng); // You can adjust the range
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use XNN_MAX_OPERATOR_OJBECTS as the upper bound

src/subgraph/concatenate.c Outdated Show resolved Hide resolved
src/subgraph/concatenate.c Outdated Show resolved Hide resolved
src/subgraph/concatenate.c Outdated Show resolved Hide resolved
src/subgraph/concatenate.c Outdated Show resolved Hide resolved
src/subgraph/concatenate.c Show resolved Hide resolved
}
if (num_inputs > 2) {
status = check_datatype_copyable(subgraph, input_ids[2], output_id, "third", node_type);
for (size_t i = 0; i < num_inputs; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need another check like this that the number of inputs is supported. Asserts are good, but we shouldn't crash if we hit an unsupported number of inputs, it should result in status != xnn_status_success and an error message like the one produced by check_datatype_copyable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added the required check for the number of inputs exceeding the maximum limit. Whether it is fine or should it be implemented within a loop?

@dsharlet
Copy link
Collaborator

I don't see how that commit is going to fix all of the check failures, e.g.:

deprecated.c.obj : error LNK2019: unresolved external symbol _xnn_define_concatenate referenced in function _xnn_define_concatenate2

Can you please make sure the checks are passing locally to the extent that you can?

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.

2 participants