Skip to content

Conversation

@huajsj
Copy link
Contributor

@huajsj huajsj commented Nov 11, 2021

  1. Add "param" connection into pipeline config to support such case
    like set params into module 1 by a param name "param0"

  2. Add using input name to locate backend runtime index and input index
    implemention.

  3. Add interface like run/stop/set_input/get_output etc.

  4. Add a implemention of serialized pipeline backend runtime execution
    for the purpose to test all the said interface.

Thanks for contributing to TVM! Please refer to guideline https://tvm.apache.org/docs/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from Reviewers by @ them in the pull request thread.

1. Add "param" connection into pipeline config to support such case
   like set params into module 1 by a param name "param0"

2. Add using input name to locate backend runtime index and input index
   implemention.

3. Add interface like run/stop/set_input/get_output etc.

4. Add a implemention of serialized pipeline backend runtime execution
   for the purpose to test all the said interface.
@huajsj
Copy link
Contributor Author

huajsj commented Nov 11, 2021

@comaniac @masahi please take a look.

Copy link
Contributor

@comaniac comaniac left a comment

Choose a reason for hiding this comment

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

Please add the RFC and tracking issue information to the PR description. Also please update the tracking issue.

v = self._get_input(key)
if v is None:
raise RuntimeError("Could not find '%s' in pipeline's inputs" % key)
v.copyfrom(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

I just realized that you need to do this because all buffers were created when initializing the pipeline executor. In this way we will double the memory usage of global inputs. Can we avoid allocating redundant buffers to reduce memory consumption, similar to graph executor and VM?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, the said logic seems like already follow the same logic as what graph_executor did and no redundant buffer creation, could you help to give more detail information about which part cause the problem?

Comment on lines 459 to 460
// If the source device and target device is not same, we use a local DLTensor
// as a medium to do the cross device copy work.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// If the source device and target device is not same, we use a local DLTensor
// as a medium to do the cross device copy work.
// If the source device and target device are not the same, we use a temporary DLTensor on CPU
// as the bridge.

After thinking twice, I feel this may still introduce unnecessary overhead. Isn't it possible for non-CPU device APIs to support from? Should we first try TVMArrayCopyFromTo(from, to, nullptr), and then go through CPU if failed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Current existing TVMArrayCopyFromTo logic supported from device, once two device both are non-cpu, the said copy function will calling from DeviceAPI function to copy data from from to to, in such case reading data from from device is not problem, but write data to to device may cause crash issue. the reason is the from device may have no capability to access the data of DLTensor of to, for example when to device is VTA, the memory address in DLTensor actually is the address of data structure VTABuffer pointer instead of data memory address, a try of TVMArrayCopyFromTo to directly copy data into the to DLTensor will cause a crash by memory access violation.

if we revise the logic to let TVMArrayCopyFromTo to support to device, then read data from from device would become a new problem, hence here we use a bridge NDArray as a solution.

@huajsj huajsj requested a review from comaniac November 13, 2021 01:01
@huajsj
Copy link
Contributor Author

huajsj commented Nov 16, 2021

thanks @comaniac , all review comments addressed, please take a look.

@huajsj
Copy link
Contributor Author

huajsj commented Nov 29, 2021

@comaniac @masahi

@masahi
Copy link
Member

masahi commented Dec 1, 2021

I can take a look this week end / next week.

@huajsj
Copy link
Contributor Author

huajsj commented Dec 1, 2021

thanks @masahi.

Copy link
Member

@masahi masahi left a comment

Choose a reason for hiding this comment

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

I started reviewing, but on the first file I saw many basic grammar errors. I have to say you didn't learn from previous PRs. I won't review 1K code like this unless you make some effort to make reviewing easier.

self._stop()

def set_input(self, key, value):
"""Set inputs to the module via "value".
Copy link
Member

Choose a reason for hiding this comment

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

via "value" doesn't make sense

v.copyfrom(value)

def set_params(self, params_name, params_data):
"""Set params to the module via param name and params data.
Copy link
Member

Choose a reason for hiding this comment

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

Choose param or params

self._set_param(params_name, key, val)

def get_input(self, key):
"""Get the input via a input name.
Copy link
Member

Choose a reason for hiding this comment

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

an input

Returns
-------
data : NDArray
Then input data.
Copy link
Member

Choose a reason for hiding this comment

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

The

The params name

params_data : dict of str to NDArray
A list of params data and params key name.
Copy link
Member

Choose a reason for hiding this comment

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

what is the difference between params key and params_name

A list of params data and params key name.
"""
for key, val in params_data.items():
self._set_param(params_name, key, val)
Copy link
Member

Choose a reason for hiding this comment

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

Related to the above comment, this is a weird API.

@huajsj
Copy link
Contributor Author

huajsj commented Dec 3, 2021

Thanks @masahi for the review, besides of fixing grammar issue, do you think that splitting this PR into couple small PR can make it be more review friendly? I will go to split this PR if you think that can help for the review.

@masahi
Copy link
Member

masahi commented Dec 3, 2021

Thanks @masahi for the review, besides of fixing grammar issue, do you think that splitting this PR into couple small PR can make it be more review friendly? I will go to split this PR if you think that can help for the review.

Yes! That sounds great, thanks.

@huajsj huajsj changed the title [Runtime] Pipeline Executor Add Set and Get Input/Output interfaces. [WIP][Runtime] Pipeline Executor Add Set and Get Input/Output interfaces. Dec 3, 2021
@huajsj
Copy link
Contributor Author

huajsj commented Dec 3, 2021

thanks @masahi @comaniac for the review, and sorry for inconvenience caused by the big PR code size, I start to split this PR into 4 small PR to make it more review friendly, following is the plan of patch splitting, associated tracking issue also get updated. the current PR will get keep for a while for review comments tracking purpose.

  1. Pipeline executor set_input implementation and input configuration loading.
  2. Pipeline executor set_params implementation and params configuration loading.
  3. Pipeline executor runtime interface declare and implementation.
  4. Pipeline executor pipe line sequence execution.

@huajsj huajsj closed this Jan 29, 2022
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.

3 participants