Skip to content
Snippets Groups Projects

Vectorise kernel

Merged James Willis requested to merge vectorise_kernel into master

Should fix issue #154 (closed). Includes updates to testKernel.c that test kernel_deval_vec against the serial kernel_deval. I have tested it with Cubic Spline, Wendland C2 + C6 kernels.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
220 * Return 0 if $u > \\gamma = H/h$
221 *
222 * @param u The ratio of the distance to the smoothing length $u = x/h$.
223 * @param W (return) The value of the kernel function $W(x,h)$.
224 * @param dW_dx (return) The norm of the gradient of $|\\nabla W(x,h)|$.
225 */
226
227 __attribute__((always_inline))
228 INLINE static void kernel_deval_vec(vector *u, vector *w, vector *dw_dx) {
229
230 vector ind, c[kernel_degree + 1], x;
231 int j, k;
232
233 /* Go to the range [0,1[ from [0,H[ */
234 x.v = u->v * vec_set1((float)kernel_igamma);
235
  • 242 c[j].f[k] = kernel_coeffs[ind.i[k] * (kernel_degree + 1) + j];
    243
    244 /* Init the iteration for Horner's scheme. */
    245 w->v = (c[0].v * x.v) + c[1].v;
    246 dw_dx->v = c[0].v;
    247
    248 /* And we're off! */
    249 for (int k = 2; k <= kernel_degree; k++) {
    250 dw_dx->v = (dw_dx->v * x.v) + w->v;
    251 w->v = (x.v * w->v) + c[k].v;
    252 }
    253
    254 /* Return everything */
    255 w->v = w->v * vec_set1((float)kernel_constant) * vec_set1((float)kernel_igamma3);
    256 dw_dx->v = dw_dx->v * vec_set1((float)kernel_constant) * vec_set1((float)kernel_igamma4);
    257
  • 17 17 *
    18 18 ******************************************************************************/
    19 19
    20 #define NO__AVX__
  • Added 1 commit:

  • I have taken the liberty to improve a bit the output (create the same number of points for the scalar and vector version) to ease the comparison.

    I had almost written you an email complaining that the numbers didn't match before noticing you did not output the same number of lines for both cases.

  • Feel free to revet this or change the output in a different way if you disagree.

  • James Willis Added 1 commit:

    Added 1 commit:

    • d6739db2 - Defined vector kernel constants prior to function call, so that they are set only once.
  • The improved output is fine with me. I have defined the vectors const prior to the function call in kernel_hydro.h. It doesn't look the nicest but it wouldn't let me call .v = vec_set1((float)kernel_igamma) outside the function call.

  • Ok. Does it make a difference to the generated assembly and code speed ? What does vector advizer say ?

  • The assembly code generated is definitely different. I quickly ran testKernel on COSMA-f but I couldn't see any difference. It would be better to test it with Angus' code which I can't get to run at the minute. Vector Advisor doesn't analyse intrinsic code.

  • Added 1 commit:

  • James Willis Added 1 commit:

    Added 1 commit:

    • 660bef5f - Added macro FILL_VEC to setup constants as vectors, depending on the vector size.
  • I've added a macro that fills the vectors depending on the vector length. I'm not sure if FILL_VEC should be in vector.h or where I have put it. Thoughts?

  • James Willis Added 2 commits:

    Added 2 commits:

    • 862ac61e - Added three macros to populate a vector for each vector size.
    • 1475cd05 - Removed FILL_VEC macro and placed it in vector.h
  • I've moved the macro to vector.h and added {} around it.

  • Matthieu Schaller Added 2 commits:

    Added 2 commits:

    • fde569a8 - Code formatting
    • e78b25f5 - Made the kernel test part of the testing suite and checks that the vector/scalar…
  • Ok, I have applied the code formatting tool and slightly updated the style to conform with the rest of the code. Also, make the test crash if discrepancies are found. Should allow you/us to update the vectorized kernel function and very rapidly check whether it is correct.

  • Can I remove the branch ?

  • mentioned in commit efdf7330

  • Matthieu Schaller Status changed to merged

    Status changed to merged

  • Yeah, fine with me.

  • Please register or sign in to reply
    Loading