main.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <stdio.h>
  2. #include "insn.h"
  3. #include "nuclei_sdk_soc.h"
  4. #ifndef CFG_HAS_NICE
  5. #error "This example require CPU NICE Demo feature"
  6. #endif
  7. int main(void)
  8. {
  9. int ret = 0;
  10. unsigned int array[ROW_LEN][COL_LEN] = {
  11. {10, 30, 90},
  12. {20, 40, 80},
  13. {30, 90, 120}
  14. };
  15. unsigned int col_sum_ref[COL_LEN] = {0};
  16. unsigned int row_sum_ref[ROW_LEN] = {0};
  17. unsigned int col_sum_nice[COL_LEN] = {0};
  18. unsigned int row_sum_nice[ROW_LEN] = {0};
  19. unsigned long begin_instret, end_instret, instret_normal, instret_nice;
  20. unsigned long begin_cycle, end_cycle, cycle_normal, cycle_nice;
  21. __RV_CSR_SET(CSR_MSTATUS, MSTATUS_XS);
  22. __enable_minstret_counter();
  23. __enable_mcycle_counter();
  24. printf("\r\nNuclei Nice Acceleration Demonstration\r\n");
  25. printf("Warning: This demo required CPU to implement Nuclei provided NICE Demo instructions.\r\n");
  26. printf(" Otherwise this example will trap to cpu core exception!\r\n\r\n");
  27. printf("1. Print input matrix array\r\n");
  28. print_array(array);
  29. printf("2. Do reference matrix column sum and row sum\r\n");
  30. begin_instret = __get_rv_instret();
  31. begin_cycle = __get_rv_cycle();
  32. normal_case(array, col_sum_ref, row_sum_ref);
  33. end_instret = __get_rv_instret();
  34. end_cycle = __get_rv_cycle();
  35. instret_normal = end_instret - begin_instret;
  36. cycle_normal = end_cycle - begin_cycle;
  37. printf("2. Do nice matrix column sum and row sum\r\n");
  38. begin_instret = __get_rv_instret();
  39. begin_cycle = __get_rv_cycle();
  40. nice_case(array, col_sum_nice, row_sum_nice);
  41. end_instret = __get_rv_instret();
  42. end_cycle = __get_rv_cycle();
  43. instret_nice = end_instret - begin_instret;
  44. cycle_nice = end_cycle - begin_cycle;
  45. printf("3. Compare reference and nice result\r\n");
  46. printf(" 1) Reference result:\r\n");
  47. print_result(col_sum_ref, row_sum_ref);
  48. printf(" 2) Nice result:\r\n");
  49. print_result(col_sum_nice, row_sum_nice);
  50. printf(" 3) Compare reference vs nice: ");
  51. if (compare_result(col_sum_ref, row_sum_ref, col_sum_nice, row_sum_nice) == 0) {
  52. printf("PASS\r\n");
  53. } else {
  54. printf("FAIL\r\n");
  55. ret = 1;
  56. }
  57. printf("4. Performance summary\r\n");
  58. printf("\t normal: \r\n");
  59. printf("\t instret: %lu, cycle: %lu\r\n", instret_normal, cycle_normal);
  60. printf("\t nice : \r\n");
  61. printf("\t instret: %lu, cycle: %lu\r\n", instret_nice, cycle_nice);
  62. return ret;
  63. }