Skip to content

Conversation

@Mousius
Copy link
Member

@Mousius Mousius commented Jul 12, 2021

This patch passes the resource_handle variable through the AOT executor
down to the backend operators. In order to model this on the PrimFunc
the resource_handle was added as a property, the resource_handle property
is then added to the arguments when transformed via MakeUnpackedAPI.

The flow of the resource_handle looks similar to this:

int32_t __tvm_main__(void* args, void* type_code, int num_args, void* out_value, void* out_type_code, void* resource_handle) {
  return tvmgen_run_model(
    ((DLTensor*)(((TVMValue*)args)[0].v_handle))[0].data,
    ((DLTensor*)(((TVMValue*)args)[1].v_handle))[0].data,
    ((DLTensor*)(((TVMValue*)args)[2].v_handle))[0].data,
    ((DLTensor*)(((TVMValue*)args)[3].v_handle))[0].data,
    resource_handle
  );
}
TVM_DLL int32_t tvmgen_run_model(void* arg0, void* arg1, void* arg2, void* arg3, void* resource_handle) {
  void* input = arg0;
  void* input1 = arg1;
  void* input2 = arg2;
  void* output = arg3;
  (void)tvmgen_fused_concatenate_add(input, input1, input2, output, resource_handle);
  return 0;
}

@areusch @manupa-arm

@Mousius Mousius force-pushed the resource-handle-unpacked branch 2 times, most recently from 4e8e6e3 to 003135a Compare July 13, 2021 16:15
@Mousius Mousius force-pushed the resource-handle-unpacked branch from 003135a to d488448 Compare July 22, 2021 14:42
@Mousius Mousius force-pushed the resource-handle-unpacked branch 4 times, most recently from 782928e to 203a51f Compare July 29, 2021 19:23
*/
Map<tir::Var, Buffer> buffer_map;
/*! \brief The resource handle to be used by the function when accessing platform resources */
tir::Var resource_handle;
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems like this should be a property of the call site rather than a function. how come you want to add it here?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is referring to the variable used in the function to pass into further calls, similar to the params above except we don't treat it as a parameter which would get packed.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, but is there just one resource_handle associated with each function? suppose you had two instances of the same accelerator and wanted to launch the same compute function twice concurrently? also, what about the AOT top-level function, which should have a struct like TVMDevices_my_model?

Mousius added 2 commits August 4, 2021 13:40
This patch passes the resource_handle variable through the AOT executor
down to the backend operators. In order to model this on the `PrimFunc`
the resource_handle was added as a property, the resource_handle property
is then added to the arguments when transformed via MakeUnpackedAPI.

The flow of the resource_handle looks similar to this:
```c
int32_t __tvm_main__(void* args, void* type_code, int num_args, void* out_value, void* out_type_code, void* resource_handle) {
  return tvmgen_run_model(
    ((DLTensor*)(((TVMValue*)args)[0].v_handle))[0].data,
    ((DLTensor*)(((TVMValue*)args)[1].v_handle))[0].data,
    ((DLTensor*)(((TVMValue*)args)[2].v_handle))[0].data,
    ((DLTensor*)(((TVMValue*)args)[3].v_handle))[0].data,
    resource_handle
  );
}
TVM_DLL int32_t tvmgen_run_model(void* arg0, void* arg1, void* arg2, void* arg3, void* resource_handle) {
  void* input = arg0;
  void* input1 = arg1;
  void* input2 = arg2;
  void* output = arg3;
  (void)tvmgen_fused_concatenate_add(input, input1, input2, output, resource_handle);
  return 0;
}
```
Black autoformats this to a longer line than pylint allows, only marking
the relevant variable causes the formatting to run correctly.

I think this is fine based on the assumption that the ignores should be
removed in favour of proper typing at some point.
@Mousius Mousius force-pushed the resource-handle-unpacked branch from 203a51f to c69c994 Compare August 4, 2021 12:43
@junrushao
Copy link
Member

This PR changes the signature of PrimFunc, but I am not sure I am the best guy to decide if it is the best way to do this. CC: @tqchen @jroesch

@areusch areusch added the status: need update need update based on feedbacks label Aug 10, 2021
@junrushao junrushao added the status: need RFC need RFC discussion label Aug 22, 2021
@Mousius
Copy link
Member Author

Mousius commented Aug 24, 2021

@junrushao1994 / @areusch I've posted https://discuss.tvm.apache.org/t/pre-rfc-c-device-api/10874 to motivate the changes here, but given this is a simple wiring exercise if the assumptions sound reasonable to you it'd be good to review this now 😸

@areusch
Copy link
Contributor

areusch commented Sep 4, 2021

@Mousius Let's just resolve the places in which we want to pass through resource_handle on the pre-RFC thread first.

@Mousius
Copy link
Member Author

Mousius commented Nov 16, 2021

Replaced by #9395 / #9501

@Mousius Mousius closed this Nov 16, 2021
@Mousius Mousius deleted the resource-handle-unpacked branch November 16, 2021 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: need RFC need RFC discussion status: need update need update based on feedbacks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants