@@ -55,12 +55,11 @@ function declare_var(lang::LangC, val, id, type)
55
55
end
56
56
function declare_coeff (lang:: LangC , val:: T , id) where T
57
57
# Use real type regardless of T.
58
- is_real_val = isreal (val)
59
- actual_val = is_real_val ? real (val) : val
58
+ actual_val = isreal (val) ? real (val) : val
60
59
(blas_t, blas_prefix) = get_blas_type (lang, typeof (actual_val))
61
60
variable_string = " coeff_$id "
62
61
dec_init_string = declare_var (lang, actual_val, variable_string, blas_t)
63
- return (is_real_val , variable_string, dec_init_string)
62
+ return (val , variable_string, dec_init_string)
64
63
end
65
64
66
65
function assignment_string (:: LangC , var, real_part)
@@ -305,7 +304,7 @@ function function_end(lang::LangC, graph, mem)
305
304
end
306
305
307
306
function add_lincomb_body (code, lang:: LangC , T, nodemem,
308
- coeff_names, coeff_is_real , parent_mems)
307
+ coeff_names, coeff_values , parent_mems)
309
308
rhs = join ((coeff_names .* " * " ) .* (" *(" .* parent_mems .* " + i)" ),
310
309
" + \n " )
311
310
for_body = " *(" * nodemem * " + i) = " * (isempty (rhs) ? " 0" : rhs) * " ;"
@@ -321,13 +320,14 @@ fma_function_name(T::Type{Complex{Float32}}, coeff_real) =
321
320
fma_function_name (T:: Type{Complex{Float64}} , coeff_real) =
322
321
coeff_real ? " fma_MKL_Complex16_double" : " fma_MKL_Complex16"
323
322
function add_lincomb_body (code, lang:: LangC_MKL , T:: Type{Complex{S}} , nodemem,
324
- coeff_names, coeff_is_real ,
323
+ coeff_names, coeff_values ,
325
324
parent_mems) where S <: Real
326
- for (it, (coeff, coeff_real, parent)) in
327
- enumerate (zip (coeff_names, coeff_is_real, parent_mems))
328
- statement = (it == 1 ?
329
- prod_function_name (T, coeff_real) :
330
- fma_function_name (T, coeff_real)) *
325
+ for (it, (coeff, coeff_value, parent)) in
326
+ enumerate (zip (coeff_names, coeff_values, parent_mems))
327
+ operation = it == 1 ?
328
+ prod_function_name (T, isreal (coeff_value)) :
329
+ fma_function_name (T, isreal (coeff_value))
330
+ statement = operation *
331
331
" (" * nodemem * " + i, " *
332
332
reference_value (lang, T, coeff) * " , " *
333
333
parent * " + i);"
@@ -336,17 +336,21 @@ function add_lincomb_body(code, lang::LangC_MKL, T::Type{Complex{S}}, nodemem,
336
336
end
337
337
338
338
function add_lincomb_identity_body (code, lang:: LangC , T,
339
- nodemem, coeff_id, coeff_real)
340
- push_code! (code, " *(" * nodemem * " + i) += " * coeff_id * " ;" , ind_lvl = 2 )
339
+ nodemem, coeff_id, coeff_value)
340
+ push_code! (
341
+ code,
342
+ " *(" * nodemem * " + i) += " * coeff_id * " ;" ,
343
+ ind_lvl = 2
344
+ )
341
345
end
342
346
343
347
acc_function_name (T:: Type{Complex{Float32}} , coeff_real) =
344
348
coeff_real ? " acc_MKL_Complex8_float" : " acc_MKL_Complex8"
345
349
acc_function_name (T:: Type{Complex{Float64}} , coeff_real) =
346
350
coeff_real ? " acc_MKL_Complex16_double" : " acc_MKL_Complex16"
347
351
function add_lincomb_identity_body (code, lang:: LangC_MKL , T:: Type{Complex{S}} ,
348
- nodemem, coeff_id, coeff_real ) where S <: Real
349
- statement = acc_function_name (T, coeff_real ) * " (" * nodemem * " + i, " *
352
+ nodemem, coeff_id, coeff_value ) where S <: Real
353
+ statement = acc_function_name (T, isreal (coeff_value) ) * " (" * nodemem * " + i, " *
350
354
reference_value (lang, T, coeff_id) * " );"
351
355
push_code! (code, statement, ind_lvl = 2 )
352
356
end
@@ -483,7 +487,7 @@ function execute_operation!(lang::LangC, T, graph, node, dealloc_list, mem)
483
487
484
488
# Set coefficients.
485
489
coeff_names = Vector ()
486
- coeff_is_real = Vector ()
490
+ coeff_values = Vector ()
487
491
parent_mems = Vector ()
488
492
id_coefficient = 0
489
493
counter = 1
@@ -497,12 +501,12 @@ function execute_operation!(lang::LangC, T, graph, node, dealloc_list, mem)
497
501
id_coefficient += v
498
502
else
499
503
# Coefficient of other nodes.
500
- (coeff_real , coeff_i, coeff_i_code) = declare_coeff (lang, v,
504
+ (coeff_value , coeff_i, coeff_i_code) = declare_coeff (lang, v,
501
505
" $node " * " _" * " $counter " )
502
506
counter += 1
503
507
push_code! (code, coeff_i_code)
504
508
push! (coeff_names, coeff_i)
505
- push! (coeff_is_real, coeff_real )
509
+ push! (coeff_values, coeff_value )
506
510
push! (parent_mems, get_slot_name (mem, n))
507
511
end
508
512
end
@@ -532,9 +536,9 @@ function execute_operation!(lang::LangC, T, graph, node, dealloc_list, mem)
532
536
splice! (coeff_names, index)
533
537
pushfirst! (coeff_names, coeff_name)
534
538
535
- coeff_real = coeff_is_real [index]
536
- splice! (coeff_is_real , index)
537
- pushfirst! (coeff_is_real, coeff_real )
539
+ coeff_value = coeff_values [index]
540
+ splice! (coeff_values , index)
541
+ pushfirst! (coeff_values, coeff_value )
538
542
end
539
543
540
544
# Write the linear combination.
@@ -543,19 +547,16 @@ function execute_operation!(lang::LangC, T, graph, node, dealloc_list, mem)
543
547
else
544
548
push_code! (code, " for (size_t i = 0; i < n * n; i++) {" )
545
549
add_lincomb_body (code, lang, T, nodemem,
546
- coeff_names, coeff_is_real , parent_mems)
550
+ coeff_names, coeff_value , parent_mems)
547
551
push_code! (code, " }" )
548
552
end
549
553
550
554
if id_coefficient != 0
551
- (coeff_real , coeff_id, coeff_id_code) = declare_coeff (lang,
555
+ (coeff_value , coeff_id, coeff_id_code) = declare_coeff (lang,
552
556
id_coefficient, " $node " * " _0" )
553
557
push_code! (code, coeff_id_code)
554
- # for statement in coeff_id_code
555
- # push_code!(code, statement)
556
- # end
557
558
push_code! (code, " for (size_t i = 0; i < n * n; i += n + 1) {" )
558
- add_lincomb_identity_body (code, lang, T, nodemem, coeff_id, coeff_real )
559
+ add_lincomb_identity_body (code, lang, T, nodemem, coeff_id, coeff_value )
559
560
push_code! (code, " }" )
560
561
end
561
562
0 commit comments