-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cblas level 1 routines and corresponding regression tests #364
Open
tansongchen
wants to merge
8
commits into
main
Choose a base branch
from
cblas_sscal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+638
−1
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7756342
Add cblas sscal
tansongchen 5bd85f7
Implementation for BLAS level 1 and 2 routines
tansongchen bc0f779
Add many tests
tansongchen 59df75a
Make tests more concise and fix several gradient computation bugs
tansongchen 83c19d8
Improve and add test cases for BLAS level 1 routines
tansongchen b9c7431
Fix operand bundles and simplify test cases for BLAS
tansongchen 17b7f8d
Temporarily remove generalization
tansongchen b1818f4
Improve adjoint of swap
tansongchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
;RUN: %opt < %s %loadEnzyme -enzyme -mem2reg -instsimplify -simplifycfg -S | FileCheck %s | ||
|
||
@enzyme_const = common global i32 0, align 4 | ||
|
||
define void @wrapper(i32 %n, double* %x, i32 %incx, double* %y, i32 %incy) { | ||
entry: | ||
tail call void @cblas_dcopy(i32 %n, double* %x, i32 %incx, double* %y, i32 %incy) | ||
ret void | ||
} | ||
|
||
declare void @cblas_dcopy(i32, double*, i32, double*, i32) | ||
|
||
define void @wrapperMod(i32 %n, double* %x, i32 %incx, double* %y, i32 %incy) { | ||
entry: | ||
tail call void @cblas_dcopy(i32 %n, double* %x, i32 %incx, double* %y, i32 %incy) | ||
store double 0.000000e+00, double* %x, align 8 | ||
store double 1.000000e+00, double* %y, align 8 | ||
ret void | ||
} | ||
|
||
define void @active(i32 %n, double* %x, double* %_x, i32 %incx, double* %y, double* %_y, i32 %incy) { | ||
entry: | ||
tail call void (i8*, ...) @__enzyme_autodiff(i8* bitcast (void (i32, double*, i32, double*, i32)* @wrapper to i8*), i32 %n, double* %x, double* %_x, i32 %incx, double* %y, double* %_y, i32 %incy) | ||
ret void | ||
} | ||
|
||
declare void @__enzyme_autodiff(i8*, ...) | ||
|
||
define void @inactiveX(i32 %n, double* %x, double* nocapture readnone %_x, i32 %incx, double* %y, double* %_y, i32 %incy) { | ||
entry: | ||
%0 = load i32, i32* @enzyme_const, align 4 | ||
tail call void (i8*, ...) @__enzyme_autodiff(i8* bitcast (void (i32, double*, i32, double*, i32)* @wrapper to i8*), i32 %n, i32 %0, double* %x, i32 %incx, double* %y, double* %_y, i32 %incy) | ||
ret void | ||
} | ||
|
||
define void @inactiveY(i32 %n, double* %x, double* %_x, i32 %incx, double* %y, double* nocapture readnone %_y, i32 %incy) { | ||
entry: | ||
%0 = load i32, i32* @enzyme_const, align 4 | ||
tail call void (i8*, ...) @__enzyme_autodiff(i8* bitcast (void (i32, double*, i32, double*, i32)* @wrapper to i8*), i32 %n, double* %x, double* %_x, i32 %incx, i32 %0, double* %y, i32 %incy) | ||
ret void | ||
} | ||
|
||
define void @activeMod(i32 %n, double* %x, double* %_x, i32 %incx, double* %y, double* %_y, i32 %incy) { | ||
entry: | ||
tail call void (i8*, ...) @__enzyme_autodiff(i8* bitcast (void (i32, double*, i32, double*, i32)* @wrapperMod to i8*), i32 %n, double* %x, double* %_x, i32 %incx, double* %y, double* %_y, i32 %incy) | ||
ret void | ||
} | ||
|
||
;CHECK: define void @active | ||
;CHECK-NEXT: entry | ||
;CHECK-NEXT: call void @[[active:.+]]( | ||
|
||
;CHECK: define void @inactiveX | ||
;CHECK-NEXT: entry | ||
;CHECK-NEXT: call void @[[inactiveX:.+]]( | ||
|
||
;CHECK: define void @inactiveY | ||
;CHECK-NEXT: entry | ||
;CHECK-NEXT: call void @[[inactiveY:.+]]( | ||
|
||
;CHECK: define void @activeMod | ||
;CHECK-NEXT: entry | ||
;CHECK-NEXT: call void @[[activeMod:.+]]( | ||
|
||
;CHECK:define internal void @[[active]](i32 %n, double* %x, double* %"x'", i32 %incx, double* %y, double* %"y'", i32 %incy) | ||
;CHECK-NEXT:entry: | ||
;CHECK-NEXT: tail call void @cblas_dcopy(i32 %n, double* %x, i32 %incx, double* %y, i32 %incy) | ||
;CHECK-NEXT: call void @cblas_daxpy(i32 %n, double 1.000000e+00, double* %"y'", i32 %incy, double* %"x'", i32 %incx) | ||
;CHECK-NEXT: ret void | ||
;CHECK-NEXT:} | ||
|
||
;CHECK:define internal void @[[inactiveX]](i32 %n, double* %x, i32 %incx, double* %y, double* %"y'", i32 %incy) | ||
;CHECK-NEXT:entry: | ||
;CHECK-NEXT: tail call void @cblas_dcopy(i32 %n, double* %x, i32 %incx, double* %y, i32 %incy) | ||
;CHECK-NEXT: ret void | ||
;CHECK-NEXT:} | ||
|
||
;CHECK:define internal void @[[inactiveY]](i32 %n, double* %x, double* %"x'", i32 %incx, double* %y, i32 %incy) | ||
;CHECK-NEXT:entry: | ||
;CHECK-NEXT: tail call void @cblas_dcopy(i32 %n, double* %x, i32 %incx, double* %y, i32 %incy) | ||
;CHECK-NEXT: ret void | ||
;CHECK-NEXT:} | ||
|
||
;CHECK:define internal void @[[activeMod]](i32 %n, double* %x, double* %"x'", i32 %incx, double* %y, double* %"y'", i32 %incy) | ||
;CHECK-NEXT:entry: | ||
;CHECK-NEXT: tail call void @cblas_dcopy(i32 %n, double* %x, i32 %incx, double* %y, i32 %incy) | ||
;CHECK-NEXT: store double 0.000000e+00, double* %x, align 8 | ||
;CHECK-NEXT: store double 1.000000e+00, double* %y, align 8 | ||
;CHECK-NEXT: store double 0.000000e+00, double* %"y'", align 8 | ||
;CHECK-NEXT: store double 0.000000e+00, double* %"x'", align 8 | ||
;CHECK-NEXT: call void @cblas_daxpy(i32 %n, double 1.000000e+00, double* %"y'", i32 %incy, double* %"x'", i32 %incx) | ||
;CHECK-NEXT: ret void | ||
;CHECK-NEXT:} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add to differentialuseanalysis.h a corresponding note that neither primal x, nor primal y are needed for the reverse pass here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which function should I add to? and is there some example to see how to add them