forked from jax-ml/jax
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[XLA:Mosaic] Support memref shapecast.
This cl supports memref shapecast: 1. if tile is (1, 128), we support shapecast on any dim. 2. if shapecast on sublane dim, we only support tile aligned shape. 3. if shapecast on non-tiling dim, we support any shapecast. 4. all other cases would be considered as invalid memref shapecast. PiperOrigin-RevId: 651924552
- Loading branch information
Showing
6 changed files
with
149 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* Copyright 2024 The JAX Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
#include "jaxlib/mosaic/dialect/tpu/util.h" | ||
|
||
#include <cstdint> | ||
|
||
#include "llvm/Support/MathExtras.h" | ||
#include "absl/types/span.h" | ||
#include "mlir/include/mlir/IR/BuiltinTypes.h" | ||
#include "mlir/include/mlir/Support/LLVM.h" | ||
|
||
namespace mlir::tpu { | ||
SmallVector<int64_t> ComputeTileStrides(MemRefType memref_ty, | ||
absl::Span<const int64_t> tiling) { | ||
SmallVector<int64_t> tile_strides(memref_ty.getRank()); | ||
int64_t stride = 1; | ||
for (int64_t i = 0; i < memref_ty.getRank(); ++i) { | ||
int64_t idx = memref_ty.getRank() - 1 - i; | ||
int64_t tiling_idx = tiling.size() - 1 - i; | ||
tile_strides[idx] = stride; | ||
if (tiling_idx >= 0) { | ||
stride *= llvm::divideCeil(memref_ty.getShape()[idx], tiling[tiling_idx]); | ||
} else { | ||
stride *= memref_ty.getShape()[idx]; | ||
} | ||
} | ||
return tile_strides; | ||
} | ||
} // namespace mlir::tpu |
This file contains 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