-
Notifications
You must be signed in to change notification settings - Fork 212
Add support for strided tensors #494
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do not commit spurious files (tags
and .swp
)
ff1ed36
to
2f842fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the point about passing possibly empty information which is default initialized to empty.
Simply passing the actual values everywhere should be enough.
codegen is called (without TensorInfo) from a number of unit tests. I can either either remove the default argument, or change the unit tests. Please let me know what you think.
c4be53d
to
9229b0c
Compare
This commit is to start support for strided tensors. I made changes to percolate a vector in TensorInfo down to emitCudaKernel to allow codegen to cast strided tensors. This required changes to an unit test to expect the correct cast.
After looking a bit deeper at the impl, I am not a fan of having 2 ways of specifying the strides during codegen (both Halide and TensorInfo) so we should chose 1. Worse, the mechanisms themselves may be incorrect because the name of the generated kernel will not vary with strides but the content of the kernel will be hardcoded for strides. So I think I would go the following route, but this probably requires a second set of eyes cc @abadams
This will increase the dimension of the parameter space for ISL, it will also increase the specializedName and the list of values we send to each kernel call. On the other hand, this will allow us to go to a parametric stride version since strides will be passed to the kernel. So this is more complex than I originally anticipated for a bootcamp task, sorry about that. |
Because Scop already owns the description of in/out tensors (through Halide in/out parameters), it makes sense for it to also own the stride information. It is more consistent than passing this information to
And we probably need to introduce new parameters due to polynomial strides. That is, for A[N][M][K], the strides are |
On Fri, Jun 08, 2018 at 10:03:18AM -0700, Nicolas Vasilache wrote:
So I think I would go the following route, but this probably requires a second set of eyes cc @abadams
@ftynse:
1. since Halide can represent strides, let's use Halide
I don't agree with this reasoning. It's not because we _can_
do something that we necessarily need to do it.
This will increase the dimension of the parameter space for ISL, it will also increase the specializedName and the list of values we send to each kernel call.
Hold on! Why does this need to be encoded as isl parameters?
skimo
|
Yeah that's essentially my motto. Who said we need to do it this way? I am putting a strawman proposal, feel free to propose something better. The reasoning behind using Halide for strides is that we are already using Halide at this level and that Halide already supports strides; we have just not used them. What's your alternative?
They definitely don't need to, it is a proposal that followed the code flow as I was reading it and that would with minimal changes. But if having these extra parameters passed through ISL is a problem then by all means let's have an separate storage for them. |
At some point I will also reconsider pulling this piece of code we had been using in ancient days. |
Also, note that there is a tradeoff:
|
On Tue, Jun 12, 2018 at 06:51:13AM -0700, Nicolas Vasilache wrote:
> I don't agree with this reasoning. It's not because we _can_ do something that we necessarily need to do it.
Yeah that's essentially my motto. Who said we *need* to do it this way? I am putting a strawman proposal, feel free to propose something better. The reasoning behind using Halide for strides is that we are already using Halide at this level and that Halide already supports strides; we have just not used them. What's your alternative?
I haven't look at it in detail, so I can't propose anything for now.
Note that I don't necessarily disagree with the conclusion.
I was only commenting on the reasoning.
> Hold on! Why does this need to be encoded as isl parameters?
They definitely don't need to, it is a proposal that followed the code flow as I was reading it and that would with minimal changes. But if having these extra parameters passed through ISL is a problem then by all means let's have an separate storage for them.
I don't see any reason at this point why the strides
should be made available as parameters, but
a proper motivation might be able to convince me.
skimo
|
On Tue, Jun 12, 2018 at 06:57:31AM -0700, Nicolas Vasilache wrote:
Also, note that there is a tradeoff:
1. hardcoding the strides in the kernel which forces us to recompile each time there is a change in strides;
Doesn't changing the strides usually change the sizes too?
That is, if you only look at the even elements, then
from the point of view of the polyhedral model, the array
is only half as big and this may make a difference
on the promotion decisions.
skimo
|
That's because strides in an overloaded term .. in this instance polyhedral folks have been using it improperly IMO. Sizes and strides are totally unrelated you can mix and match them arbitrarily. In ML a tensor is almost always defined as a "view" over a contiguous block of memory. A Torch/DLPack/Numpy/other tensor is a view with an initial offset and a list of sizes and strides (of the same length). The sizes (sometimes also called shape) determine the number of elements in the view; the strides determine the spacing between consecutive elements in the view. Here is an example:
Strides corresponding to C99 variable length array are a special case: Such a view of a memory region has many properties that people like to use. For instance a transpose operation just consists of permuting 2 strides, it is a pure metadata transformation and requires no memory copy (contiguity and performance are not factors of course). People also like to "review" tensors (traditionally called the reshape operation), for instance a 4-D output of a batched 2-D convolution can be reshaped (stride contiguity permitting) into a 2-D matric that can be passed to a GEMM operation. This is happening in many places in neural networks. Of all these properties, we only care about non-aliasing because of obvious correctness issues. Lastly note that the type of compact representation polyhedral folks are accustomed to are called "contiguous" tensors (i.e. So the classification is Makes sense? |
Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours has expired. Before we can review or merge your code, we need you to email [email protected] with your details so we can update your status. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
This commit is to start support for strided tensors. I made changes
to percolate a vector in TensorInfo down to emitCudaKernel to allow
codegen to cast strided tensors. This required changes to an unit test
to expect the correct cast.