3.6.3.3 SHLS-4

Message

Error:   (SHLS-4) Loop unrolling failed on {location}.
                  This error occurred because SmartHLS does not support code containing an unknown number of thread API calls at compile time.

SmartHLS supports only static thread assignment, requiring the number of threads to be determined at compile time. As a result, thread construction calls cannot be placed within a loop that has a dynamic loop bound, since the number of iterations, and thus the number of threads, would not be known at compile time. If a thread construction call is identified in such a loop, an SHLS-4 message will be generated, indicating an error in the input design.

/*****************************************************************
 *  This example is expected to result in
 *  - Code  : SHLS-4
 *  - Type  : Error
 *  - Cause : Failed to resolve the total number of HLS thread
 *            call at compile time due to run-time variable 
 *            value 'nthread'.
 *****************************************************************/
#include "hls/thread.hpp"

int add(int a, int b) {
    return a + b;
}

int DUT(int a, int b, int nthread) {
    #pragma HLS function top

    int result = 0;
    for (int i = 0; i < nthread; i++) {
        hls::thread<int> thread(add, a, b);
        result += thread.join();
    }
    return result;
}

Related to: Loop Unrolling