feat(aten): implement as_strided, resize_, _reshape_alias; refactor empty ops#5
Merged
Conversation
…mpty ops - Add as_strided, resize_, and _reshape_alias native implementations and register them in TORCH_LIBRARY_IMPL - Refactor empty_memory_format and empty_strided to use at::detail::empty_generic / empty_strided_generic instead of the custom make_opencl_tensor helper - Remove CPUFallback include; drop commented-out stub declarations from header and replace with real signatures - Tighten error messages (pin_memory, layout, peer-to-peer copy) - Reformat to 80-column limit throughout - Expand test coverage: zero-size alloc, dtype variants, pin_memory / layout error paths, as_strided (basic, negative stride/offset, size-stride mismatch), resize_ (shrink, scalar), _reshape_alias, and additional _copy_from error cases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements three previously stubbed ATen native operations for the OpenCL backend —
as_strided,resize_, and_reshape_alias— and refactors the existingempty_memory_formatandempty_stridedimplementations to delegate to the upstreamat::detailallocation helpers, removing the bespokemake_opencl_tensorpath.Changes
as_strided,resize_, and_reshape_aliastoMinimal.cpp/Minimal.h, and register all three inTORCH_LIBRARY_IMPL.empty_memory_formatto useat::detail::empty_genericandempty_stridedto useat::detail::empty_strided_generic; remove the internalmake_opencl_tensorhelper.CPUFallbackinclude fromOpenCLMinimal.cpp; previously commented-out stub declarations in the header are replaced with real signatures.TORCH_CHECKmessages across all ops (pin memory, non-strided layout, peer-to-peer copy)..clang-format.Tests
test_allocator.py: add zero-size allocation, multi-dtype,pin_memoryerror, and unsupported layout tests.test_minimal.py: addTestAsStrided,TestResize, andTestReshapeAliastest classes; extendTestCopyFromwith dtype mismatch, numel mismatch, and non-contiguous source cases.test_device.py: add lifecycle,is_in_bad_fork, andexchange_devicebinding tests.Notes
resize_performs amemcpy-based reallocation when the new size exceeds the current storage; shrinking is metadata-only.as_strided; this is a current OpenCL backend limitation, not a general ATen constraint._copy_frompeer-to-peer error message was reformatted to fit the 80-column limit; no functional change.Checklist
clang-format(80-column limit)