You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #2590, there is an important step (here dynamic indexing refers to indexing elements of a vector/matrix field with a variable):
Develop an algorithm to identify the cases where the dynamic indexing can be turned into the form of pointer + offset at compile time, and use that form for these cases.
In this issue, I propose an algorithm, and would like to get some feedback on the design. Discussions are highly welcome! If the design looks good to most of you, I will go ahead and implement it.
I will illustrate the algorithm using the following example, which is a bit complex but able to show the ability boundary of the algorithm.
Previously, if we want to access v[field_index, vector_index], vector_index must be a compile-time constant. Supporting dynamic indexing means that we can have a variable vector_index. The main idea for enabling this is to figure out addr(v[field_index, vector_index]) = addr(v[field_index, 0]) + f(v, vector_index) whenever possible. As addr(v[field_index, 0]) is what we already have, our focus here is to design the function f(v, vector_index).
The function exists only in the following case: for any field_index, there is addr(y[field_index]) - addr(x[field_index]) == addr(z[field_index]) - addr(y[field_index]) == stride. Then we have f(v, vector_index) = vector_index * stride.
Now the problem becomes how to verify the above condition and calculate stride. My algorithm is as follows:
Get the LCA (lowest common ancestor) of x, y, z, which is S1, and check if the paths from the LCA to x, y, z are all dense (not including the LCA):
In #2590, there is an important step (here dynamic indexing refers to indexing elements of a vector/matrix field with a variable):
In this issue, I propose an algorithm, and would like to get some feedback on the design. Discussions are highly welcome! If the design looks good to most of you, I will go ahead and implement it.
I will illustrate the algorithm using the following example, which is a bit complex but able to show the ability boundary of the algorithm.
Previously, if we want to access
v[field_index, vector_index]
,vector_index
must be a compile-time constant. Supporting dynamic indexing means that we can have a variablevector_index
. The main idea for enabling this is to figure outaddr(v[field_index, vector_index]) = addr(v[field_index, 0]) + f(v, vector_index)
whenever possible. Asaddr(v[field_index, 0])
is what we already have, our focus here is to design the functionf(v, vector_index)
.The function exists only in the following case: for any
field_index
, there isaddr(y[field_index]) - addr(x[field_index]) == addr(z[field_index]) - addr(y[field_index]) == stride
. Then we havef(v, vector_index) = vector_index * stride
.Now the problem becomes how to verify the above condition and calculate
stride
. My algorithm is as follows:x, y, z
, which isS1
, and check if the paths from the LCA tox, y, z
are alldense
(not including the LCA):stride
:Running these code will get
stride == 384
on my local machine. Its correctness can be verified with:The text was updated successfully, but these errors were encountered: