Skip to content

Commit 13cd8b0

Browse files
committed
fixed segfault by static const and reuse
1 parent a644eef commit 13cd8b0

File tree

1 file changed

+27
-40
lines changed

1 file changed

+27
-40
lines changed

gen_32x32_code.py

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,23 @@ def generate_fm_source_files(A_eval_order, A_reduced_exprs, B_reduced_exprs, B_r
6161
n_B_mats = len(B_names)
6262

6363

64-
65-
content += f" matlincomb_double_contiguous(tmp0, {n_A_mats}, (double_cmat[{n_A_mats}])"
66-
content += "{"
67-
for name in A_names:
68-
content += f"{name}, "
69-
content += "}"
70-
content += f", (int8_t[{n_A_mats}])"
71-
content += "{"
64+
content += f" static const int8_t A_coeffs_{fm_index}[{n_A_mats}] = {{"
7265
for c in A_coeffs:
7366
content += f"{c}, "
74-
content += "}"
75-
content += ");\n"
76-
77-
content += f" matlincomb_double_contiguous(tmp1, {n_B_mats}, (double_cmat[{n_B_mats}])"
78-
content += "{"
79-
for name in B_names:
80-
content += f"{name}, "
81-
content += "}"
82-
content += f", (int8_t[{n_B_mats}])"
83-
content += "{"
67+
content += "};\n"
68+
69+
for idx, name in enumerate(A_names):
70+
content += f" marr[{idx}]={name};\n"
71+
content += f" matlincomb_double_contiguous(tmp0, {n_A_mats}, (double_cmat*)marr, (int8_t*)A_coeffs_{fm_index});\n"
72+
73+
content += f" static const int8_t B_coeffs_{fm_index}[{n_B_mats}] = {{"
8474
for c in B_coeffs:
8575
content += f"{c}, "
86-
content += "}"
87-
content += ");\n"
76+
content += "};\n"
77+
78+
for idx, name in enumerate(B_names):
79+
content += f" marr[{idx}]={name};\n"
80+
content += f" matlincomb_double_contiguous(tmp1, {n_B_mats}, (double_cmat*)marr, (int8_t*)B_coeffs_{fm_index});\n"
8881

8982
content += " cblas_dscal(BL*BL, dnum17, &tmp0.data[0][0], 1);\n"
9083

@@ -167,6 +160,7 @@ def generate_fmm_32x32_source():
167160
double_cmat tmp0, tmp1;
168161
create_double_matrix(pairint {BL, BL}, &tmp0);
169162
create_double_matrix(pairint {BL, BL}, &tmp1);
163+
double_cmat marr[60] = {NULL};
170164
"""
171165

172166
for j in range(1,33):
@@ -284,17 +278,14 @@ def generate_fAxxeval_source_files(A_eval_order, A_reduced_exprs, B_reduced_expr
284278

285279
n_A_mats = len(A_names)
286280

287-
288-
content += f" matlincomb_double_contiguous({idf}, {n_A_mats}, (double_cmat[{n_A_mats}])"
289-
content += "{"
290-
for name in A_names:
291-
content += f"{name}, "
292-
content += "}"
293-
content += f", (int8_t[{n_A_mats}])"
294-
content += "{"
281+
content += f" static const int8_t A_coeffs_{func_name}[{n_A_mats}] = {{"
295282
for c in A_coeffs:
296283
content += f"{c}, "
297-
content += "});\n"
284+
content += "};\n"
285+
286+
for idx, name in enumerate(A_names):
287+
content += f" marr[{idx}]={name};\n"
288+
content += f" matlincomb_double_contiguous({idf}, {n_A_mats}, (double_cmat*)marr, (int8_t*)A_coeffs_{func_name});\n"
298289
Axxi2code[i] = content
299290
return Axxi2code
300291

@@ -314,19 +305,15 @@ def generate_fBx_source_files(A_eval_order, A_reduced_exprs, B_reduced_exprs, B_
314305

315306

316307
reset_var = f"{idf}"
317-
content+= f" memset(&{reset_var}.data[0][0], 0, sizeof({reset_var}.data[0][0])*{reset_var}.shape[0]*{reset_var}.shape[1]);\n"
318-
319-
content += f" matlincomb_double_contiguous({idf}, {n_B_mats}, (double_cmat[{n_B_mats}])"
320-
content += "{"
321-
for name in B_names:
322-
content += f"{name}, "
323-
content += "}"
324-
content += f", (int8_t[{n_B_mats}])"
325-
content += "{"
308+
309+
content += f" static const int8_t B_coeffs_{idf}[{n_B_mats}] = {{"
326310
for c in B_coeffs:
327311
content += f"{c}, "
328-
content += "}"
329-
content += ");\n"
312+
content += "};\n"
313+
314+
for idx, name in enumerate(B_names):
315+
content += f" marr[{idx}]={name};\n"
316+
content += f" matlincomb_double_contiguous({idf}, {n_B_mats}, (double_cmat*)marr, (int8_t*)B_coeffs_{idf});\n"
330317
Bxi2code[idf] = content
331318
return Bxi2code
332319

0 commit comments

Comments
 (0)