std::vector<int> ClintStmtOccurrence::findBoundlikeForm(Bound bound, int dimIdx, int constValue) { std::vector<int> zeroParameters(m_oslStatement->domain->nb_parameters, 0); std::vector<int> parameterValues = scop()->parameterValues(); int oslDimIdx = 1 + dimIdx * 2 + 1; osl_relation_p scheduledDomain = ISLEnumerator::scheduledDomain(m_oslStatement->domain, m_oslScattering); int lowerRow = oslRelationDimUpperBound(scheduledDomain, oslDimIdx); int upperRow = oslRelationDimLowerBound(scheduledDomain, oslDimIdx); // Check if the request boundary exists and is unique. // If failed, try the opposite boundary. If the opposite does not // exist or is not unique, use constant form. if (lowerRow < 0 && upperRow < 0) { return makeBoundlikeForm(bound, dimIdx, constValue, 0, zeroParameters, parameterValues); } else if (lowerRow < 0 && bound == Bound::LOWER) { bound = Bound::UPPER; } else if (upperRow < 0 && bound == Bound::UPPER) { bound = Bound::LOWER; } // Check if the current boundary (either request or opposite) is // variable. If it is, try the opposite unless the opposite does // not exist. If both are variable or one is variable and another // does not exit, use constant form. bool upperVariable = upperRow >= 0 ? isVariableBoundary(upperRow, scheduledDomain, oslDimIdx) : true; bool lowerVariable = lowerRow >= 0 ? isVariableBoundary(lowerRow, scheduledDomain, oslDimIdx) : true; if (upperVariable && lowerVariable) { return makeBoundlikeForm(bound, dimIdx, constValue, 0, zeroParameters, parameterValues); } if (upperVariable && lowerRow >= 0) { bound = Bound::LOWER; } else if (lowerVariable && upperRow >= 0) { bound = Bound::UPPER; } int row = bound == Bound::UPPER ? upperRow : lowerRow; int firstParameterIdx = 1 + scheduledDomain->nb_input_dims + scheduledDomain->nb_output_dims + scheduledDomain->nb_local_dims; std::vector<int> parameters; parameters.reserve(scheduledDomain->nb_parameters); for (int i = 0; i < scheduledDomain->nb_parameters; i++) { int p = osl_int_get_si(scheduledDomain->precision, scheduledDomain->m[row][firstParameterIdx + i]); parameters.push_back(p); } // Make parametric form is the boundary itself is parametric. // Make constant form otherwise. if (isParametricBoundary(row, scheduledDomain)) { int boundaryConstantPart = osl_int_get_si(scheduledDomain->precision, scheduledDomain->m[row][scheduledDomain->nb_columns - 1]); return makeBoundlikeForm(bound, dimIdx, constValue, boundaryConstantPart, parameters, parameterValues); } else { return makeBoundlikeForm(bound, dimIdx, constValue, 0, zeroParameters, parameterValues); } }
/** * clay_util_body_regenerate_access function: * Read the access array and re-generate the code in the body * \param[in] ebody An extbody structure * \param[in] access The relation to regenerate the code * \param[in] index nth access (needed to access to the array start and * length of the extbody structure) */ void clay_util_body_regenerate_access(osl_extbody_p ebody, osl_relation_p access, int index, osl_arrays_p arrays, osl_scatnames_p scatnames, osl_strings_p params) { if (!arrays || !scatnames || !params || access->nb_output_dims == 0 || index >= ebody->nb_access) return; const int precision = access->precision; int i, j, k, row, val, print_plus; // check if there are no inequ for (i = 0 ; i < access->nb_rows ; i++) { if (!osl_int_zero(precision, access->m[i][0])) CLAY_error("I don't know how to regenerate access with inequalities"); } // check identity matrix in output dims int n; for (j = 0 ; j < access->nb_output_dims ; j++) { n = 0; for (i = 0 ; i < access->nb_rows ; i++) if (!osl_int_zero(precision, access->m[i][j+1])) { if (n >= 1) CLAY_error("I don't know how to regenerate access with " "dependences in output dims"); n++; } } char *body = ebody->body->expression->string[0]; int body_len = strlen(body); int start = ebody->start[index]; int len = ebody->length[index]; int is_zero; // if the line contains only zeros if (start >= body_len || start + len >= body_len || (start == -1 && len == -1)) return; char *new_body; char end_body[OSL_MAX_STRING]; int hwm = OSL_MAX_STRING; CLAY_malloc(new_body, char *, OSL_MAX_STRING * sizeof(char)); // copy the beginning of the body if (start+1 >= OSL_MAX_STRING) CLAY_error("memcpy: please recompile osl with a higher OSL_MAX_STRING"); memcpy(new_body, body, start); new_body[start] = '\0'; // save the end in a buffer int sz = body_len - start - len; if (sz + 1 >= OSL_MAX_STRING) CLAY_error("memcpy: please recompile osl with a higher OSL_MAX_STRING"); memcpy(end_body, body + start + len, sz); end_body[sz] = '\0'; // copy access name string val = osl_relation_get_array_id(access); val = clay_util_arrays_search(arrays, val); // get the index in th array osl_util_safe_strcat(&new_body, arrays->names[val], &hwm); // generate each dims for (i = 1 ; i < access->nb_output_dims ; i++) { row = clay_util_relation_get_line(access, i); if (row == -1) continue; osl_util_safe_strcat(&new_body, "[", &hwm); is_zero = 1; print_plus = 0; k = 1 + access->nb_output_dims; // iterators for (j = 0 ; j < access->nb_input_dims ; j++, k++) { val = osl_int_get_si(precision, access->m[row][k]); if (val != 0) { clay_util_name_sprint(&new_body, &hwm, &print_plus, val, scatnames->names->string[j*2+1]); is_zero = 0; } } // params for (j = 0 ; j < access->nb_parameters ; j++, k++) { val = osl_int_get_si(precision, access->m[row][k]); if (val != 0) { clay_util_name_sprint(&new_body, &hwm, &print_plus, val, params->string[j]); is_zero = 0; } } // const val = osl_int_get_si(precision, access->m[row][k]); if (val != 0 || is_zero) clay_util_name_sprint(&new_body, &hwm, &print_plus, val, NULL); osl_util_safe_strcat(&new_body, "]", &hwm); } // length of the generated access ebody->length[index] = strlen(new_body) - start; // concat the end osl_util_safe_strcat(&new_body, end_body, &hwm); // update ebody free(ebody->body->expression->string[0]); ebody->body->expression->string[0] = new_body; // shift the start int diff = ebody->length[index] - len; for (i = index+1 ; i < ebody->nb_access ; i++) if (ebody->start[i] != -1) ebody->start[i] += diff; }
int main(int argc, char** argv) { if (argc > 1) { printf("argv are ignored\n"); } unsigned int nb_fail = 0; #ifdef OSL_GMP_IS_HERE int i; for (i = SCHAR_MIN; i <= SCHAR_MAX; ++i) { osl_int_t a_sp; osl_int_init_set_si(OSL_PRECISION_SP, &a_sp, i); osl_int_t a_dp; osl_int_init_set_si(OSL_PRECISION_DP, &a_dp, i); osl_int_t a_mp; osl_int_init_set_si(OSL_PRECISION_MP, &a_mp, i); int j; for (j = SCHAR_MIN; j <= SCHAR_MAX; ++j) { int error = 0; osl_int_t b_sp; osl_int_init_set_si(OSL_PRECISION_SP, &b_sp, j); osl_int_t b_dp; osl_int_init_set_si(OSL_PRECISION_DP, &b_dp, j); osl_int_t b_mp; osl_int_init_set_si(OSL_PRECISION_MP, &b_mp, j); osl_int_t c_sp; osl_int_init(OSL_PRECISION_SP, &c_sp); osl_int_t c_dp; osl_int_init(OSL_PRECISION_DP, &c_dp); osl_int_t c_mp; osl_int_init(OSL_PRECISION_MP, &c_mp); int const a_sp_i = osl_int_get_si(OSL_PRECISION_SP, a_sp); int const a_dp_i = osl_int_get_si(OSL_PRECISION_DP, a_dp); int const a_mp_i = osl_int_get_si(OSL_PRECISION_MP, a_mp); int const b_sp_i = osl_int_get_si(OSL_PRECISION_SP, b_sp); int const b_dp_i = osl_int_get_si(OSL_PRECISION_DP, b_dp); int const b_mp_i = osl_int_get_si(OSL_PRECISION_MP, b_mp); // osl_int_init_set_si & osl_int_init & osl_int_get_si if (!error) { int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (a_sp_i != a_dp_i || a_sp_i != a_mp_i) { error++; printf("Error osl_int_init_set_si or osl_int_get_si\n"); } if (b_sp_i != b_dp_i || b_sp_i != b_mp_i) { error++; printf("Error osl_int_init_set_si or osl_int_get_si\n"); } if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != 0) { error++; printf("Error osl_int_init or osl_int_get_si\n"); } } // osl_int_assign if (!error) { osl_int_assign(OSL_PRECISION_SP, &c_sp, b_sp); osl_int_assign(OSL_PRECISION_DP, &c_dp, b_dp); osl_int_assign(OSL_PRECISION_MP, &c_mp, b_mp); if (osl_int_ne(OSL_PRECISION_SP, c_sp, b_sp)) { error++; printf("Error osl_int_assign\n"); } if (osl_int_ne(OSL_PRECISION_DP, c_dp, b_dp)) { error++; printf("Error osl_int_assign\n"); } if (osl_int_ne(OSL_PRECISION_MP, c_mp, b_mp)) { error++; printf("Error osl_int_assign\n"); } } // osl_int_swap // osl_int_increment if (!error) { osl_int_increment(OSL_PRECISION_SP, &c_sp, a_sp); osl_int_increment(OSL_PRECISION_DP, &c_dp, a_dp); osl_int_increment(OSL_PRECISION_MP, &c_mp, a_mp); int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i + 1) { error++; printf("Error osl_int_increment\n"); } } // osl_int_decrement if (!error) { osl_int_decrement(OSL_PRECISION_SP, &c_sp, a_sp); osl_int_decrement(OSL_PRECISION_DP, &c_dp, a_dp); osl_int_decrement(OSL_PRECISION_MP, &c_mp, a_mp); int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i - 1) { error++; printf("Error osl_int_decrement\n"); } } // osl_int_add if (!error) { osl_int_add(OSL_PRECISION_SP, &c_sp, a_sp, b_sp); osl_int_add(OSL_PRECISION_DP, &c_dp, a_dp, b_dp); osl_int_add(OSL_PRECISION_MP, &c_mp, a_mp, b_mp); int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i + b_sp_i) { error++; printf("Error osl_int_add\n"); } } // osl_int_add_si // osl_int_sub if (!error) { osl_int_sub(OSL_PRECISION_SP, &c_sp, a_sp, b_sp); osl_int_sub(OSL_PRECISION_DP, &c_dp, a_dp, b_dp); osl_int_sub(OSL_PRECISION_MP, &c_mp, a_mp, b_mp); int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i - b_sp_i) { error++; printf("Error osl_int_add\n"); } } // osl_int_mul if (!error) { osl_int_mul(OSL_PRECISION_SP, &c_sp, a_sp, b_sp); osl_int_mul(OSL_PRECISION_DP, &c_dp, a_dp, b_dp); osl_int_mul(OSL_PRECISION_MP, &c_mp, a_mp, b_mp); int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i * b_sp_i) { error++; printf("Error osl_int_mul\n"); } } // osl_int_mul_si if (!error) { osl_int_mul_si(OSL_PRECISION_SP, &c_sp, a_sp, b_sp_i); osl_int_mul_si(OSL_PRECISION_DP, &c_dp, a_dp, b_dp_i); osl_int_mul_si(OSL_PRECISION_MP, &c_mp, a_mp, b_mp_i); int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i * b_sp_i) { error++; printf("Error osl_int_mul_si\n"); } } // osl_int_div_exact if (!error && b_sp_i != 0 && a_sp_i % b_sp_i == 0) { osl_int_div_exact(OSL_PRECISION_SP, &c_sp, a_sp, b_sp); osl_int_div_exact(OSL_PRECISION_DP, &c_dp, a_dp, b_dp); osl_int_div_exact(OSL_PRECISION_MP, &c_mp, a_mp, b_mp); int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i / b_sp_i) { error++; printf("Error osl_int_div_exact\n"); } } // osl_int_floor_div_q if (!error && b_sp_i != 0) { osl_int_floor_div_q(OSL_PRECISION_SP, &c_sp, a_sp, b_sp); osl_int_floor_div_q(OSL_PRECISION_DP, &c_dp, a_dp, b_dp); osl_int_floor_div_q(OSL_PRECISION_MP, &c_mp, a_mp, b_mp); int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (c_sp_i != c_dp_i || c_sp_i != c_mp_i) { error++; printf("Error osl_int_floor_div_q\n"); } } // osl_int_floor_div_r if (!error && b_sp_i != 0) { osl_int_floor_div_r(OSL_PRECISION_SP, &c_sp, a_sp, b_sp); osl_int_floor_div_r(OSL_PRECISION_DP, &c_dp, a_dp, b_dp); osl_int_floor_div_r(OSL_PRECISION_MP, &c_mp, a_mp, b_mp); int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (c_sp_i != c_dp_i || c_sp_i != c_mp_i) { error++; printf("Error osl_int_floor_div_r\n"); } } // osl_int_floor_div_q_r if (!error && b_sp_i != 0) { osl_int_t q_sp; osl_int_init(OSL_PRECISION_SP, &q_sp); osl_int_t q_dp; osl_int_init(OSL_PRECISION_DP, &q_dp); osl_int_t q_mp; osl_int_init(OSL_PRECISION_MP, &q_mp); osl_int_t r_sp; osl_int_init(OSL_PRECISION_SP, &r_sp); osl_int_t r_dp; osl_int_init(OSL_PRECISION_DP, &r_dp); osl_int_t r_mp; osl_int_init(OSL_PRECISION_MP, &r_mp); osl_int_floor_div_q_r(OSL_PRECISION_SP, &q_sp, &r_sp, a_sp, b_sp); osl_int_floor_div_q_r(OSL_PRECISION_DP, &q_dp, &r_dp, a_dp, b_dp); osl_int_floor_div_q_r(OSL_PRECISION_MP, &q_mp, &r_mp, a_mp, b_mp); int q_sp_i = osl_int_get_si(OSL_PRECISION_SP, q_sp); int q_dp_i = osl_int_get_si(OSL_PRECISION_DP, q_dp); int q_mp_i = osl_int_get_si(OSL_PRECISION_MP, q_mp); int r_sp_i = osl_int_get_si(OSL_PRECISION_SP, r_sp); int r_dp_i = osl_int_get_si(OSL_PRECISION_DP, r_dp); int r_mp_i = osl_int_get_si(OSL_PRECISION_MP, r_mp); if (q_sp_i != q_dp_i || q_sp_i != q_mp_i) { error++; printf("Error osl_int_floor_div_q_r\n"); } if (r_sp_i != r_dp_i || r_sp_i != r_mp_i) { error++; printf("Error osl_int_floor_div_q_r\n"); } } // osl_int_mod if (!error && b_sp_i != 0) { osl_int_mod(OSL_PRECISION_SP, &c_sp, a_sp, b_sp); osl_int_mod(OSL_PRECISION_DP, &c_dp, a_dp, b_dp); osl_int_mod(OSL_PRECISION_MP, &c_mp, a_mp, b_mp); int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (c_sp_i != c_dp_i || c_sp_i != c_mp_i) { error++; printf("Error osl_int_mod\n"); } } // osl_int_gcd if (!error) { osl_int_gcd(OSL_PRECISION_SP, &c_sp, a_sp, b_sp); osl_int_gcd(OSL_PRECISION_DP, &c_dp, a_dp, b_dp); osl_int_gcd(OSL_PRECISION_MP, &c_mp, a_mp, b_mp); int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (c_sp_i != c_dp_i || c_sp_i != c_mp_i) { error++; printf("Error osl_int_gcd\n"); } } // osl_int_oppose if (!error) { osl_int_oppose(OSL_PRECISION_SP, &c_sp, b_sp); osl_int_oppose(OSL_PRECISION_DP, &c_dp, b_dp); osl_int_oppose(OSL_PRECISION_MP, &c_mp, b_mp); int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (c_sp_i != c_dp_i || c_sp_i != c_mp_i) { error++; printf("Error osl_int_oppose\n"); } } // osl_int_abs if (!error) { osl_int_abs(OSL_PRECISION_SP, &c_sp, b_sp); osl_int_abs(OSL_PRECISION_DP, &c_dp, b_dp); osl_int_abs(OSL_PRECISION_MP, &c_mp, b_mp); int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp); int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp); int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp); if (c_sp_i != c_dp_i || c_sp_i != c_mp_i) { error++; printf("Error osl_int_abs\n"); } } // osl_int_size_in_base_2 if (!error) { size_t r_sp = osl_int_size_in_base_2(OSL_PRECISION_SP, b_sp); size_t r_dp = osl_int_size_in_base_2(OSL_PRECISION_DP, b_dp); size_t r_mp = osl_int_size_in_base_2(OSL_PRECISION_MP, b_mp); osl_int_set_si(OSL_PRECISION_SP, &c_sp, r_sp); osl_int_set_si(OSL_PRECISION_DP, &c_dp, r_dp); osl_int_set_si(OSL_PRECISION_MP, &c_mp, r_mp); if (r_sp != r_dp || r_sp != r_mp) { error++; printf("Error osl_int_size_in_base_2\n"); } } // osl_int_size_in_base_10 // if (!error) { // size_t r_sp = osl_int_size_in_base_10(OSL_PRECISION_SP, b_sp); // size_t r_dp = osl_int_size_in_base_10(OSL_PRECISION_DP, b_dp); // size_t r_mp = osl_int_size_in_base_10(OSL_PRECISION_MP, b_mp); // // osl_int_set_si(OSL_PRECISION_SP, &c_sp, r_sp); // osl_int_set_si(OSL_PRECISION_DP, &c_dp, r_dp); // osl_int_set_si(OSL_PRECISION_MP, &c_mp, r_mp); // // if (r_sp != r_dp || r_sp != r_mp) // { error++; printf("Error osl_int_size_in_base_10\n"); } // } // osl_int_eq // osl_int_ne // osl_int_pos // osl_int_neg // osl_int_zero // osl_int_one // osl_int_mone // osl_int_divisible if (error) { printf("Error with:\n"); printf("\n"); printf("a_sp = "); osl_int_print(stdout, OSL_PRECISION_SP, a_sp); printf("\n"); printf("a_dp = "); osl_int_print(stdout, OSL_PRECISION_DP, a_dp); printf("\n"); printf("a_mp = "); osl_int_print(stdout, OSL_PRECISION_MP, a_mp); printf("\n"); printf("\n"); printf("b_sp = "); osl_int_print(stdout, OSL_PRECISION_SP, b_sp); printf("\n"); printf("b_dp = "); osl_int_print(stdout, OSL_PRECISION_DP, b_dp); printf("\n"); printf("b_mp = "); osl_int_print(stdout, OSL_PRECISION_MP, b_mp); printf("\n"); printf("\n"); printf("c_sp = "); osl_int_print(stdout, OSL_PRECISION_SP, c_sp); printf("\n"); printf("c_dp = "); osl_int_print(stdout, OSL_PRECISION_DP, c_dp); printf("\n"); printf("c_mp = "); osl_int_print(stdout, OSL_PRECISION_MP, c_mp); printf("\n"); printf("\n"); nb_fail += error; } } } printf("%s ", argv[0]); printf("fails = %d\n", nb_fail); #else printf("%s ", argv[0]); printf("works only with GMP\n"); #endif return nb_fail; }