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

[PYTHON][FFI] Skip numpy.ascontiguousarray if C_CONTIGUOUS == True #9073

Merged
merged 4 commits into from
Sep 24, 2021
Merged

[PYTHON][FFI] Skip numpy.ascontiguousarray if C_CONTIGUOUS == True #9073

merged 4 commits into from
Sep 24, 2021

Conversation

wangxiang2713
Copy link
Contributor

@wangxiang2713 wangxiang2713 commented Sep 22, 2021

Hi, i just run a tensorflow model with TVM. My model has 321 inputs so i find create NDArray inputs for model is time consuming.

Code:

source_array = np.ascontiguousarray(
    source_array, dtype="uint16" if dtype == "bfloat16" else dtype
)

is used in function NDArray.copyfrom when create NDArray from Numpy. I find this code cost 0.47ms for my model, but a numpy array without operation like slice is contiguous and ascontiguousarray is not needed. In fact this code do nothing in my case, but 0.47ms is used.

So i add a type check, and i use a table DataType.NUMPY2STR to avoid str(np.dtype) as i find it time comusing, as i do in commit: #9072

@wangxiang2713 wangxiang2713 changed the title Skip numpy.ascontiguousarray if C_CONTIGUOUS == True [PYTHON][FFI] Skip numpy.ascontiguousarray if C_CONTIGUOUS == True Sep 23, 2021
@tqchen tqchen merged commit d3d7e8e into apache:main Sep 24, 2021
@tqchen
Copy link
Member

tqchen commented Sep 24, 2021

Thanks @wangxiang2713

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