Vector computing on Duo 256M

I’d like to use the vector extension of RiscV on my Duo 256M, but I only get an error message saying ‘illegal instruction’. The isa of the processor confirms that the vector extension is present, but I can’t manage to execute the code.

How can I add the vector libraries on my board?

Or is it more complicated and do I need to make a new image, compatible with vector computing?

My application is neural network, but maybe there are other solutions to accelerate the inference?

Thanks for your help and advices.

1 Like

Which instruction? There’s a chance they aren’t enabled in the provided OS image.

Here is a short example to begin with:

#include <riscv_vector.h>#include <stdio.h>
int main() {
  size_t vl = vsetvl_e32m1(8);
  printf(“Test VL: %zu\n”, vl);
  return 0;
}

Then, my code is:

static inline float vector_dot_product(const float *a, const float *b, size_t n) {
if (n == 0) return 0.0f;

/* vlmax = min(n, implementation VLmax) */
size_t vlmax = vsetvl_e32m1(n);

/* vector accumulator initialized to zero (uses vlmax lanes) */
vfloat32m1_t vacc = vfmv_v_f_f32m1(0.0f, vlmax);

size_t i = 0;
while (i < n) {
    size_t vl = vsetvl_e32m1(n - i);
    vfloat32m1_t va = vle32_v_f32m1(a + i, vl);
    vfloat32m1_t vb = vle32_v_f32m1(b + i, vl);
    /* vacc += va * vb */
    vacc = vfmacc_vv_f32m1(vacc, va, vb, vl);
    i += vl;
}

/* Reduce accumulator by storing lanes to memory and summing them */
float *tmp = (float *)malloc(vlmax * sizeof(float));

/* store vacc lanes to tmp (vl = vlmax) */
vse32_v_f32m1(tmp, vacc, vlmax);

float result = 0.0f;
for (size_t j = 0; j < vlmax; ++j) result += tmp[j];

free(tmp);
return result;
}

How can I know which instructions are enabled or not?

1 Like