Skip to content

Commit

Permalink
Fix dlascl api (#1522)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses authored Nov 3, 2023
1 parent 01c279c commit c808878
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 25 deletions.
4 changes: 2 additions & 2 deletions enzyme/test/Enzyme/ReverseMode/blas/gemm_f.ll
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ entry:
; CHECK-DAG: %byref.constant.int.0 = alloca i64
; CHECK-DAG: %[[byrefconstantint1:.+]] = alloca i64
; CHECK-DAG: %[[byref_fp_1_00:.+]] = alloca double
; CHECK-DAG: %[[tmp:.+]] = alloca i8
; CHECK-DAG: %[[tmp:.+]] = alloca i64
; CHECK-DAG: %transa = alloca i8, align 1
; CHECK-DAG: %transb = alloca i8, align 1
; CHECK-DAG: %m = alloca i64, align 16
Expand Down Expand Up @@ -157,6 +157,6 @@ entry:
; CHECK-NEXT: %[[int02:.+]] = bitcast i64* %[[byrefconstantint1]] to i8*
; CHECK-NEXT: store double 1.000000e+00, double* %[[byref_fp_1_00]]
; CHECK-NEXT: %[[fp11:.+]] = bitcast double* %[[byref_fp_1_00]] to i8*
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[int02]], i8* %[[fp11]], i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i8* %[[tmp]], i64 1)
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[int02]], i8* %[[fp11]], i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i64* %[[tmp]], i64 1)
; CHECK-NEXT: ret void
; CHECK-NEXT: }
4 changes: 2 additions & 2 deletions enzyme/test/Enzyme/ReverseMode/blas/gemm_f_c.ll
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ entry:
; CHECK-NEXT: %byref.constant.int.0 = alloca i64, align 8
; CHECK-NEXT: %[[byrefconstantint4:.+]] = alloca i64, align 8
; CHECK-NEXT: %[[byref_fp_1_017:.+]] = alloca double, align 8
; CHECK-NEXT: %[[tmp:.+]] = alloca i8
; CHECK-NEXT: %[[tmp:.+]] = alloca i64
; CHECK-NEXT: %transa = alloca i8, align 1
; CHECK-NEXT: %transb = alloca i8, align 1
; CHECK-NEXT: %m = alloca i64, align 16
Expand Down Expand Up @@ -275,7 +275,7 @@ entry:
; CHECK-NEXT: %[[intcast07:.+]] = bitcast i64* %[[byrefconstantint4]] to i8*
; CHECK-NEXT: store double 1.000000e+00, double* %[[byref_fp_1_017]]
; CHECK-NEXT: %[[fpcast_1_018:.+]] = bitcast double* %[[byref_fp_1_017]] to i8*
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[intcast07]], i8* %[[fpcast_1_018]], i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i8* %[[tmp]], i64 1)
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[intcast07]], i8* %[[fpcast_1_018]], i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i64* %[[tmp]], i64 1)
; CHECK-NEXT: %[[ret1:.+]] = bitcast double* %cache.A to i8*
; CHECK-NEXT: tail call void @free(i8* nonnull %[[ret1]])
; CHECK-NEXT: %[[ret2:.+]] = bitcast double* %cache.B to i8*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ entry:
; CHECK-NEXT: %byref.constant.int.0 = alloca i64, align 8
; CHECK-NEXT: %[[byref_int_019:.+]] = alloca i64, align 8
; CHECK-NEXT: %[[byref_fp_021:.+]] = alloca double, align 8
; CHECK-NEXT: %[[tmp:.+]] = alloca i8
; CHECK-NEXT: %[[tmp:.+]] = alloca i64
; CHECK-NEXT: %transa = alloca i8, align 1
; CHECK-NEXT: %transb = alloca i8, align 1
; CHECK-NEXT: %m = alloca i64, align 16
Expand Down Expand Up @@ -348,7 +348,7 @@ entry:
; CHECK-NEXT: %[[intcast_020:.+]] = bitcast i64* %[[byref_int_019]] to i8*
; CHECK-NEXT: store double 1.000000e+00, double* %[[byref_fp_021]]
; CHECK-NEXT: %[[fpcast_1_022:.+]] = bitcast double* %[[byref_fp_021]] to i8*
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[intcast_020]], i8* %[[fpcast_1_022]], i8* %beta, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i8* %[[tmp]], i64 1)
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[intcast_020]], i8* %[[fpcast_1_022]], i8* %beta, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i64* %[[tmp]], i64 1)
; CHECK-NEXT: br label %invertentry.C.done

; CHECK: invertentry.C.done: ; preds = %invertentry.C.active, %invertentry.beta.done
Expand Down
4 changes: 2 additions & 2 deletions enzyme/test/Enzyme/ReverseMode/blas/gemm_f_c_loop.ll
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ entry:
; CHECK-NEXT: %byref.constant.int.0 = alloca i64, align 8
; CHECK-NEXT: %byref.constant.int.033 = alloca i64, align 8
; CHECK-NEXT: %byref.constant.fp.1.035 = alloca double, align 8
; CHECK-NEXT: %[[tmp:.+]] = alloca i8
; CHECK-NEXT: %[[tmp:.+]] = alloca i64
; CHECK-NEXT: %transa = alloca i8, align 1
; CHECK-NEXT: %transb = alloca i8, align 1
; CHECK-NEXT: %n = alloca i64, align 16
Expand Down Expand Up @@ -295,7 +295,7 @@ entry:
; CHECK-NEXT: %intcast.constant.int.034 = bitcast i64* %byref.constant.int.033 to i8*
; CHECK-NEXT: store double 1.000000e+00, double* %byref.constant.fp.1.035, align 8
; CHECK-NEXT: %fpcast.constant.fp.1.036 = bitcast double* %byref.constant.fp.1.035 to i8*
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %intcast.constant.int.034, i8* %fpcast.constant.fp.1.036, i8* %cast.beta, i8* %[[r37]], i8* %n_p_unwrap, i8* %"C'", i8* %cast.ldc, i8* %[[tmp]], i64 1)
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %intcast.constant.int.034, i8* %fpcast.constant.fp.1.036, i8* %cast.beta, i8* %[[r37]], i8* %n_p_unwrap, i8* %"C'", i8* %cast.ldc, i64* %[[tmp]], i64 1)
; CHECK-NEXT: %[[r77:.+]] = bitcast double* %cache.A_unwrap to i8*
; CHECK-NEXT: tail call void @free(i8* nonnull %[[r77]])
; CHECK-NEXT: call void @free(i8* %[[r37]])
Expand Down
4 changes: 2 additions & 2 deletions enzyme/test/Enzyme/ReverseMode/blas/gemm_f_c_split.ll
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ entry:
; CHECK-NEXT: %byref.constant.int.0 = alloca i64
; CHECK-NEXT: %[[byref_int_0:.+]] = alloca i64
; CHECK-NEXT: %[[byref_fp_1_011:.+]] = alloca double
; CHECK-NEXT: %[[tmp:.+]] = alloca i8
; CHECK-NEXT: %[[tmp:.+]] = alloca i64
; CHECK-NEXT: %ldc = alloca i64, i64 1, align 16
; CHECK-NEXT: %[[i1:.+]] = bitcast i64* %ldc to i8*
; CHECK-NEXT: %beta = alloca double, i64 1, align 16
Expand Down Expand Up @@ -289,7 +289,7 @@ entry:
; CHECK-NEXT: %[[intcast_010:.+]] = bitcast i64* %[[byref_int_0]] to i8*
; CHECK-NEXT: store double 1.000000e+00, double* %[[byref_fp_1_011]], align 8
; CHECK-NEXT: %[[fpcast_1_0:.+]] = bitcast double* %[[byref_fp_1_011]] to i8*
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[intcast_010]], i8* %[[fpcast_1_0]], i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i8* %[[tmp]], i64 1)
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[intcast_010]], i8* %[[fpcast_1_0]], i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i64* %[[tmp]], i64 1)
; CHECK-NEXT: %[[r70:.+]] = bitcast double* %0 to i8*
; CHECK-NEXT: tail call void @free(i8* nonnull %[[r70]])
; CHECK-NEXT: ret void
Expand Down
4 changes: 2 additions & 2 deletions enzyme/test/Enzyme/ReverseMode/blas/gemm_f_c_split_lacpy.ll
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ entry:
; CHECK-NEXT: %byref.constant.int.0 = alloca i64
; CHECK-NEXT: %[[int09:.+]] = alloca i64
; CHECK-NEXT: %[[fp11:.+]] = alloca double
; CHECK-NEXT: %[[tmp:.+]] = alloca i8
; CHECK-NEXT: %[[tmp:.+]] = alloca i64
; CHECK-NEXT: %ldc = alloca i64, i64 1, align 16
; CHECK-NEXT: %[[i1:.+]] = bitcast i64* %ldc to i8*
; CHECK-NEXT: %beta = alloca double, i64 1, align 16
Expand Down Expand Up @@ -263,7 +263,7 @@ entry:
; CHECK-NEXT: %[[int010:.+]] = bitcast i64* %[[int09:.+]] to i8*
; CHECK-NEXT: store double 1.000000e+00, double* %[[fp11]], align 8
; CHECK-NEXT: %[[fp12:.+]] = bitcast double* %[[fp11]] to i8*
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[int010]], i8* %[[fp12]], i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i8* %[[tmp]], i64 1)
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[int010]], i8* %[[fp12]], i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i64* %[[tmp]], i64 1)
; CHECK-NEXT: %[[r70:.+]] = bitcast double* %0 to i8*
; CHECK-NEXT: tail call void @free(i8* nonnull %[[r70]])
; CHECK-NEXT: ret void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ entry:
; CHECK-NEXT: %byref.constant.int.0 = alloca i64, align 8
; CHECK-NEXT: %[[byref_int_0:.+]] = alloca i64, align 8
; CHECK-NEXT: %[[byref_fp_1_011:.+]] = alloca double, align 8
; CHECK-NEXT: %[[tmp:.+]] = alloca i8
; CHECK-NEXT: %[[tmp:.+]] = alloca i64
; CHECK-NEXT: %ldc = alloca i64, i64 1, align 16
; CHECK-NEXT: %[[i1:.+]] = bitcast i64* %ldc to i8*
; CHECK-NEXT: %beta = alloca double, i64 1, align 16
Expand Down Expand Up @@ -261,7 +261,7 @@ entry:
; CHECK-NEXT: %[[intcast_010:.+]] = bitcast i64* %[[byref_int_0]] to i8*
; CHECK-NEXT: store double 1.000000e+00, double* %[[byref_fp_1_011]], align 8
; CHECK-NEXT: %[[fpcast_1_012:.+]] = bitcast double* %[[byref_fp_1_011]] to i8*
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[intcast_010]], i8* %[[fpcast_1_012]], i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i8* %[[tmp]], i64 1)
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[intcast_010]], i8* %[[fpcast_1_012]], i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i64* %[[tmp]], i64 1)
; CHECK-NEXT: %[[r70:.+]] = bitcast double* %0 to i8*
; CHECK-NEXT: tail call void @free(i8* nonnull %[[r70]])
; CHECK-NEXT: ret void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ entry:
; CHECK-NEXT: %byref.constant.int.0 = alloca i64
; CHECK-NEXT: %[[int04:.+]] = alloca i64
; CHECK-NEXT: %[[byref_fp_1_018:.+]] = alloca double
; CHECK-NEXT: %[[tmp:.+]] = alloca i8
; CHECK-NEXT: %[[tmp:.+]] = alloca i64
; CHECK-NEXT: %transa = alloca i8, align 1
; CHECK-NEXT: %transb = alloca i8, align 1
; CHECK-NEXT: %m = alloca i64, align 16
Expand Down Expand Up @@ -219,7 +219,7 @@ entry:
; CHECK-NEXT: %[[intcast08:.+]] = bitcast i64* %[[int04]] to i8*
; CHECK-NEXT: store double 1.000000e+00, double* %byref.constant.fp.1.0
; CHECK-NEXT: %[[fp19:.+]] = bitcast double* %[[byref_fp_1_018]] to i8*
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %[[intcast0]], i8* %[[intcast08]], i8* %[[fp19]], i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i8* %[[tmp]], i64 1)
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %[[intcast0]], i8* %[[intcast08]], i8* %[[fp19]], i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i64* %[[tmp]], i64 1)
; CHECK-NEXT: %[[free1:.+]] = bitcast double* %cache.A to i8*
; CHECK-NEXT: tail call void @free(i8* nonnull %[[free1]])
; CHECK-NEXT: %[[free2:.+]] = bitcast double* %cache.B to i8*
Expand Down
4 changes: 2 additions & 2 deletions enzyme/test/Enzyme/ReverseMode/blas/gemm_f_change_ld.ll
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ entry:
; CHECK-NEXT: %byref.constant.int.0 = alloca i64
; CHECK-NEXT: %[[byrefint03:.+]] = alloca i64
; CHECK-NEXT: %byref.constant.fp.1.06 = alloca double
; CHECK-NEXT: %[[tmp:.+]] = alloca i8
; CHECK-NEXT: %[[tmp:.+]] = alloca i64
; CHECK-NEXT: %transa = alloca i8, align 1
; CHECK-NEXT: %transb = alloca i8, align 1
; CHECK-NEXT: %m = alloca i64, align 16
Expand Down Expand Up @@ -159,7 +159,7 @@ entry:
; CHECK-NEXT: %intcast.constant.int.05 = bitcast i64* %byref.constant.int.04 to i8*
; CHECK-NEXT: store double 1.000000e+00, double* %byref.constant.fp.1.0
; CHECK-NEXT: %fpcast.constant.fp.1.07 = bitcast double* %byref.constant.fp.1.06 to i8*
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %intcast.constant.int.05, i8* %fpcast.constant.fp.1.07, i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i8* %[[tmp]], i64 1)
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %intcast.constant.int.05, i8* %fpcast.constant.fp.1.07, i8* %beta_p, i8* %m_p, i8* %n_p, i8* %"C'", i8* %ldc_p, i64* %[[tmp]], i64 1)
; CHECK-NEXT: %[[ret:.+]] = bitcast double* %cache.B to i8*
; CHECK-NEXT: tail call void @free(i8* nonnull %[[ret]])
; CHECK-NEXT: ret void
Expand Down
4 changes: 2 additions & 2 deletions enzyme/test/Enzyme/ReverseMode/blas/gemm_f_over.ll
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ entry:
; CHECK-DAG: %byref.constant.int.0 = alloca i64
; CHECK-DAG: %[[byref_int_08:.+]] = alloca i64, align 8
; CHECK-DAG: %[[byref_fp_1_010:.+]] = alloca double
; CHECK-DAG: %[[tmp:.+]] = alloca i8
; CHECK-DAG: %[[tmp:.+]] = alloca i64
; CHECK-DAG: %transa = alloca i8, align 1
; CHECK-DAG: %transb = alloca i8, align 1
; CHECK-DAG: %m = alloca i64, align 16
Expand Down Expand Up @@ -164,6 +164,6 @@ entry:
; CHECK-NEXT: %[[int02:.+]] = bitcast i64* %[[byref_int_08]] to i8*
; CHECK-NEXT: store double 1.000000e+00, double* %byref.constant.fp.1.0
; CHECK-NEXT: %[[fp11:.+]] = bitcast double* %[[byref_fp_1_010]] to i8*
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[int02]], i8* %[[fp11]], i8* %beta_p, i8* %cast.m, i8* %n_p, i8* %"C'", i8* %ldc_p, i8* %[[tmp]], i64 1)
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[int02]], i8* %[[fp11]], i8* %beta_p, i8* %cast.m, i8* %n_p, i8* %"C'", i8* %ldc_p, i64* %[[tmp]], i64 1)
; CHECK-NEXT: ret void
; CHECK-NEXT: }
4 changes: 2 additions & 2 deletions enzyme/test/Enzyme/ReverseMode/blas/gemm_f_over_lacpy.ll
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ entry:
; CHECK-NEXT: %byref.constant.int.0 = alloca i64, align 8
; CHECK-NEXT: %[[byref_int_0:.+]] = alloca i64, align 8
; CHECK-NEXT: %[[byref_fp_1_0:.+]] = alloca double, align 8
; CHECK-NEXT: %[[tmp:.+]] = alloca i8
; CHECK-NEXT: %[[tmp:.+]] = alloca i64
; CHECK-NEXT: %transa = alloca i8, align 1
; CHECK-NEXT: %transb = alloca i8, align 1
; CHECK-NEXT: %m = alloca i64, align 16
Expand Down Expand Up @@ -164,7 +164,7 @@ entry:
; CHECK-NEXT: %[[intcast_0:.+]] = bitcast i64* %[[byref_int_0]] to i8*
; CHECK-NEXT: store double 1.000000e+00, double* %[[byref_fp_1_0]], align 8
; CHECK-NEXT: %[[fpcast_1:.+]] = bitcast double* %[[byref_fp_1_0]] to i8*
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[intcast_0]], i8* %[[fpcast_1]], i8* %beta_p, i8* %cast.m, i8* %n_p, i8* %"C'", i8* %ldc_p, i8* %[[tmp]], i64 1)
; CHECK-NEXT: call void @dlascl_64_(i8* %byref.constant.char.G, i8* %intcast.constant.int.0, i8* %[[intcast_0]], i8* %[[fpcast_1]], i8* %beta_p, i8* %cast.m, i8* %n_p, i8* %"C'", i8* %ldc_p, i64* %[[tmp]], i64 1)
; CHECK-NEXT: ret void
; CHECK-NEXT: }

5 changes: 2 additions & 3 deletions enzyme/tools/enzyme-tblgen/blas-tblgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,9 +1195,8 @@ void rev_call_arg(DagInit *ruleDag, Rule &rule, size_t actArg, size_t pos,
}
} else if (Def->isSubClassOf("Alloca")) {
auto val = Def->getValueAsInt("value");
os << "{allocationBuilder.CreateAlloca(Type::getIntNTy(allocationBuilder."
"getContext(), "
<< (8 * val) << "))}";
assert(val == 1);
os << "{allocationBuilder.CreateAlloca(intType)}";
} else if (Def->isSubClassOf("ConstantInt")) {
auto val = Def->getValueAsInt("value");
os << "{to_blas_callconv(Builder2, ConstantInt::get(intType, " << val
Expand Down

0 comments on commit c808878

Please sign in to comment.