2020-05-30 08:49:25 +08:00
|
|
|
// RUN: npcomp-opt -lower-ranked-shapes <%s -split-input-file -verify-diagnostics | FileCheck %s --dump-input=fail
|
2020-05-12 12:22:40 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: func @broadcast_rank2_rank1
|
2020-05-16 07:33:01 +08:00
|
|
|
func @broadcast_rank2_rank1(%arg0: index, %arg1: index, %arg2: index) -> (index, index) {
|
2020-05-12 12:22:40 +08:00
|
|
|
// CHECK-NOT: shape.broadcast
|
|
|
|
// CHECK-NOT: tcp.get_extent
|
2020-05-30 08:49:25 +08:00
|
|
|
// CHECK-NOT: shape.from_extents
|
2020-05-22 05:51:01 +08:00
|
|
|
%0 = shape.from_extents %arg0, %arg1
|
2020-08-03 13:06:12 +08:00
|
|
|
%1 = shape.to_extent_tensor %0 : !shape.shape -> tensor<?xindex>
|
|
|
|
%2 = shape.from_extents %arg2
|
|
|
|
%3 = shape.to_extent_tensor %2 : !shape.shape -> tensor<?xindex>
|
|
|
|
%4 = "shape.broadcast"(%1, %3) : (tensor<?xindex>, tensor<?xindex>) -> !shape.shape
|
|
|
|
%5 = shape.to_extent_tensor %4 : !shape.shape -> tensor<?xindex>
|
|
|
|
%c0 = constant 0 : index
|
|
|
|
%c1 = constant 1 : index
|
|
|
|
%e0 = shape.get_extent %5, %c0 : tensor<?xindex>, index -> index
|
|
|
|
%e1 = shape.get_extent %5, %c1 : tensor<?xindex>, index -> index
|
2020-05-12 12:22:40 +08:00
|
|
|
return %e0, %e1 : index, index
|
|
|
|
}
|
2020-05-19 04:35:25 +08:00
|
|
|
|
2020-08-03 13:06:12 +08:00
|
|
|
// -----
|
Rework e2e flow to use new "npcomprt"
This ~totally reworks the existing "runtime" stuff to be more
principled and usable, such as from Python. It's still not fully
production-quality, mainly in the department of memory management (e.g.
it currently leaks memory; we need to figure out "who frees memrefs" +
the analysis and transformation needed to do that (maybe use upstream
buffer allocation pass?)).
The user API is in include/npcomp/runtime/UserAPI.h, though
include/npcomp/JITRuntime/JITModule.h is a friendlier wrapper.
The stuff under {include,lib}/runtime is totally firewalled from the
compiler and tiny (<6kB, though no attention has gone into optimizing
that size). For example, we don't link in libSupport into the runtime,
instead having our own bare bones replacements for basics like ArrayRef
(the JITRuntime helps with bridging that gap, since it *can* depend on
all common LLVM utilities).
The overall features of npcomprt is that it exposes a module that
with multiple function entry points. Each function has arguments and
results that are tensor-valued, and npcomprt::Tensor is the runtime type
that is used to interact with that (and a npcomprt::Ref<T>
reference-counting wrapper is provided to wrap npcomprt::Tensor in the
common case).
From an implementation perspective, an npcomprt module at the
LLVM/object/binary level exposes a single module descriptor struct that
has pointers to other metadata (currently just a list of function
metadata descriptors). All interactions with the npcomp runtime are
keyed off of that module descriptor, including function lookups and
dispatching. This is done to dodge platform ABI issues and also allow
enough reflection to e.g. verify provided arguments.
Most of the compiler-side work here was in LowerToNpcomprtABI and
LowerToLLVM.
Also,
- Rename npcomp_rt/NpcompRt to npcomprt/Npcomprt; it was getting
annoying to type the underscores/caps.
- misc improvements to bash_helpers.sh
2020-07-09 08:15:40 +08:00
|
|
|
// CHECK-LABEL: func @erase_stray_shape_ops
|
|
|
|
func @erase_stray_shape_ops(%arg0: index) {
|
2020-05-30 08:49:25 +08:00
|
|
|
// CHECK-NOT: tcp.shape_observe_error
|
|
|
|
// CHECK-NOT: shape.from_extents
|
2020-05-22 05:51:01 +08:00
|
|
|
%0 = shape.from_extents %arg0
|
2020-05-19 04:35:25 +08:00
|
|
|
"tcp.shape_observe_error"(%0) : (!shape.shape) -> none
|
|
|
|
return
|
|
|
|
}
|
2020-05-30 08:49:25 +08:00
|
|
|
|
|
|
|
// -----
|
Rework e2e flow to use new "npcomprt"
This ~totally reworks the existing "runtime" stuff to be more
principled and usable, such as from Python. It's still not fully
production-quality, mainly in the department of memory management (e.g.
it currently leaks memory; we need to figure out "who frees memrefs" +
the analysis and transformation needed to do that (maybe use upstream
buffer allocation pass?)).
The user API is in include/npcomp/runtime/UserAPI.h, though
include/npcomp/JITRuntime/JITModule.h is a friendlier wrapper.
The stuff under {include,lib}/runtime is totally firewalled from the
compiler and tiny (<6kB, though no attention has gone into optimizing
that size). For example, we don't link in libSupport into the runtime,
instead having our own bare bones replacements for basics like ArrayRef
(the JITRuntime helps with bridging that gap, since it *can* depend on
all common LLVM utilities).
The overall features of npcomprt is that it exposes a module that
with multiple function entry points. Each function has arguments and
results that are tensor-valued, and npcomprt::Tensor is the runtime type
that is used to interact with that (and a npcomprt::Ref<T>
reference-counting wrapper is provided to wrap npcomprt::Tensor in the
common case).
From an implementation perspective, an npcomprt module at the
LLVM/object/binary level exposes a single module descriptor struct that
has pointers to other metadata (currently just a list of function
metadata descriptors). All interactions with the npcomp runtime are
keyed off of that module descriptor, including function lookups and
dispatching. This is done to dodge platform ABI issues and also allow
enough reflection to e.g. verify provided arguments.
Most of the compiler-side work here was in LowerToNpcomprtABI and
LowerToLLVM.
Also,
- Rename npcomp_rt/NpcompRt to npcomprt/Npcomprt; it was getting
annoying to type the underscores/caps.
- misc improvements to bash_helpers.sh
2020-07-09 08:15:40 +08:00
|
|
|
func @cannot_erase_stray_shape_ops() -> !shape.shape {
|
2020-05-30 08:49:25 +08:00
|
|
|
// expected-error @+1 {{could not be eliminated}}
|
|
|
|
%0 = shape.from_extents
|
|
|
|
return %0 : !shape.shape
|
|
|
|
}
|
2020-07-09 11:10:01 +08:00
|
|
|
|
|
|
|
// -----
|
2020-08-03 13:06:12 +08:00
|
|
|
// TODO: Remove this as it is now just testing shape and std ops.
|
2020-07-09 11:10:01 +08:00
|
|
|
// CHECK-LABEL: func @const_shape
|
|
|
|
func @const_shape() -> index {
|
|
|
|
// CHECK-NOT: shape.const_shape
|
2020-08-03 13:06:12 +08:00
|
|
|
%0 = shape.const_shape [] : tensor<?xindex>
|
|
|
|
%1 = shape.const_shape [7] : tensor<?xindex>
|
|
|
|
%2 = constant 0 : index
|
|
|
|
%3 = shape.get_extent %1, %2 : tensor<?xindex>, index -> index
|
2020-07-09 11:10:01 +08:00
|
|
|
// CHECK: %[[C7:.*]] = constant 7 : index
|
|
|
|
// CHECK: return %[[C7]]
|
2020-08-03 13:06:12 +08:00
|
|
|
return %3 : index
|
2020-07-09 11:10:01 +08:00
|
|
|
}
|