Hi,
I want to write a MLIR code to implement a function of merging two ordered arrays into one (the merged one also ordered). The c++ of code this function looks like the following:
void Merge(int array1[N], int array2[N], int array3[N], int n1, int n2) {
int i = 0, j = 0, k = 0;
while (i < n1 && j < n2) { // Traverse both array.
if (array1[i] < array2[j])
array3[k++] = array1[i++];
else
array3[k++] = array2[j++];
}
while (i < n1) // Copy remaining elements of first array.
array3[k++] = array1[i++];
while (j < n2) // Copy remaining elements of second array
array3[k++] = array2[j++];
}
I am trying to implement a loop which can do the same thing with loop “while (i < n1 && j < n2) { …}”, this loop need to have two induction variables and the step of the variables are not constant. I checked scf dialect, and I haven’t found a operation to implement such a loop. In Affine dialect, there is affine.parallel, it says it supports two induction variables at the same time in the loop, but the step size should be constant.
So could anyone please give me any suggestions that I can implement such a loop, which has two induction variables and non-constant step size for each of them, in mlir?
Thank you so much for your time.
Best,
Ruiqin
Student in W&M