-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix
YaoBlocks.mat
for rotation gates with TracedRNumber
parameters (
#306) * fix `YaoBlocks.mat` for rotation gates with `TracedRNumber` parameters * Update ext/ReactantYaoBlocksExt.jl
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module ReactantYaoBlocksExt | ||
|
||
using Reactant | ||
using YaoBlocks | ||
|
||
function YaoBlocks.mat( | ||
::Type{T}, R::RotationGate{D,Reactant.TracedRNumber{S},<:XGate} | ||
) where {D,T,S} | ||
M = Reactant.broadcast_to_size(zero(T), (2, 2)) | ||
M[1, 1] = cos(R.theta / 2) | ||
M[2, 2] = cos(R.theta / 2) | ||
M[1, 2] = -im * sin(R.theta / 2) | ||
M[2, 1] = -im * sin(R.theta / 2) | ||
return M | ||
end | ||
|
||
function YaoBlocks.mat( | ||
::Type{T}, R::RotationGate{D,Reactant.TracedRNumber{S},<:YGate} | ||
) where {D,T,S} | ||
M = Reactant.broadcast_to_size(zero(T), (2, 2)) | ||
M[1, 1] = cos(R.theta / 2) | ||
M[2, 2] = cos(R.theta / 2) | ||
M[1, 2] = -sin(R.theta / 2) | ||
M[2, 1] = sin(R.theta / 2) | ||
return M | ||
end | ||
|
||
function YaoBlocks.mat( | ||
::Type{T}, R::RotationGate{D,Reactant.TracedRNumber{S},<:ZGate} | ||
) where {D,T,S} | ||
M = Reactant.broadcast_to_size(zero(T), (2, 2)) | ||
M[1, 1] = exp(-im * R.theta / 2) | ||
M[2, 2] = exp(im * R.theta / 2) | ||
return M | ||
end | ||
|
||
end |
4981557
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.
Reactant.jl Benchmarks
ViT base (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :after_enzyme)
1257741783
ns1262529790
ns1.00
ViT base (256 x 256 x 3 x 32)/forward/CUDA/Reactant
1443950901
ns1295960067
ns1.11
ViT base (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :before_enzyme)
1385605290
ns1388414450
ns1.00
ViT base (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :only_enzyme)
2794781252
ns2845010519
ns0.98
ViT base (256 x 256 x 3 x 32)/forward/CUDA/Lux
203499640
ns216191284
ns0.94
ViT base (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :after_enzyme)
5710482855
ns6553949825
ns0.87
ViT base (256 x 256 x 3 x 32)/forward/CPU/Reactant
5341487680
ns5529491940
ns0.97
ViT base (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :before_enzyme)
6062348395
ns5207076241
ns1.16
ViT base (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :only_enzyme)
7286146462
ns7423222920
ns0.98
ViT base (256 x 256 x 3 x 32)/forward/CPU/Lux
34742615164
ns29111245934
ns1.19
ViT small (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :after_enzyme)
1198386252
ns1210144232
ns0.99
ViT small (256 x 256 x 3 x 4)/forward/CUDA/Reactant
1183740364
ns1203258421
ns0.98
ViT small (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :before_enzyme)
1226242113
ns1201314375
ns1.02
ViT small (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :only_enzyme)
2824009338
ns2772640660
ns1.02
ViT small (256 x 256 x 3 x 4)/forward/CUDA/Lux
8581758.5
ns8101273
ns1.06
ViT small (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :after_enzyme)
1659437123
ns1562542896
ns1.06
ViT small (256 x 256 x 3 x 4)/forward/CPU/Reactant
1663747727
ns1590422736
ns1.05
ViT small (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :before_enzyme)
1575216589
ns1593527212
ns0.99
ViT small (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :only_enzyme)
3330508539
ns3448787500
ns0.97
ViT small (256 x 256 x 3 x 4)/forward/CPU/Lux
2697236030
ns2352203752.5
ns1.15
ViT tiny (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :after_enzyme)
1177894801
ns1283921788
ns0.92
ViT tiny (256 x 256 x 3 x 32)/forward/CUDA/Reactant
1231369417
ns1289501443
ns0.95
ViT tiny (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :before_enzyme)
1281022614
ns1236773657
ns1.04
ViT tiny (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :only_enzyme)
2992466689
ns2994979934
ns1.00
ViT tiny (256 x 256 x 3 x 32)/forward/CUDA/Lux
22743533
ns21119477
ns1.08
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :after_enzyme)
2143636724
ns2189596614
ns0.98
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Reactant
2146473226
ns2167135675
ns0.99
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :before_enzyme)
2157303648
ns2152353497
ns1.00
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :only_enzyme)
3959878673
ns3988887387
ns0.99
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Lux
5865019185
ns5727971331.5
ns1.02
ViT tiny (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :after_enzyme)
1387842900
ns1351251105
ns1.03
ViT tiny (256 x 256 x 3 x 4)/forward/CUDA/Reactant
1256093379
ns1334983286
ns0.94
ViT tiny (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :before_enzyme)
1257804932
ns1326564260
ns0.95
ViT tiny (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :only_enzyme)
3119512525
ns3006970362
ns1.04
ViT tiny (256 x 256 x 3 x 4)/forward/CUDA/Lux
6970194
ns7156082
ns0.97
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :after_enzyme)
1427711032
ns1442181095
ns0.99
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Reactant
1416276590
ns1449779916
ns0.98
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :before_enzyme)
1497474638
ns1440104385
ns1.04
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :only_enzyme)
3162263527
ns3206233925
ns0.99
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Lux
1224458504
ns1453999347
ns0.84
ViT tiny (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :after_enzyme)
1258743352
ns1278843849
ns0.98
ViT tiny (256 x 256 x 3 x 16)/forward/CUDA/Reactant
1272174301
ns1276785330
ns1.00
ViT tiny (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :before_enzyme)
1286613721
ns1466486039
ns0.88
ViT tiny (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :only_enzyme)
2941431002
ns3029520232
ns0.97
ViT tiny (256 x 256 x 3 x 16)/forward/CUDA/Lux
12308639.5
ns11308170.5
ns1.09
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :after_enzyme)
1728521529
ns1739952511
ns0.99
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Reactant
1726871692
ns1708928970
ns1.01
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :before_enzyme)
1724333072
ns1699255869
ns1.01
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :only_enzyme)
3485347197
ns3445714498
ns1.01
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Lux
3314985446
ns3319646969
ns1.00
ViT small (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :after_enzyme)
1296002633
ns1277942983
ns1.01
ViT small (256 x 256 x 3 x 16)/forward/CUDA/Reactant
1304207360
ns1251667936
ns1.04
ViT small (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :before_enzyme)
1255941581
ns1262343075
ns0.99
ViT small (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :only_enzyme)
3046234878
ns3208271409
ns0.95
ViT small (256 x 256 x 3 x 16)/forward/CUDA/Lux
27396872
ns25656532
ns1.07
ViT small (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :after_enzyme)
2236205101
ns2171969273
ns1.03
ViT small (256 x 256 x 3 x 16)/forward/CPU/Reactant
2198709936
ns2152154812
ns1.02
ViT small (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :before_enzyme)
2296730805
ns2160330860
ns1.06
ViT small (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :only_enzyme)
3958176139
ns3932782743
ns1.01
ViT small (256 x 256 x 3 x 16)/forward/CPU/Lux
5608465822
ns6171257189
ns0.91
ViT small (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :after_enzyme)
1251122132
ns1288285171
ns0.97
ViT small (256 x 256 x 3 x 32)/forward/CUDA/Reactant
1342649088
ns1266265410
ns1.06
ViT small (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :before_enzyme)
1266853946
ns1277150659
ns0.99
ViT small (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :only_enzyme)
3134977417
ns3063914527
ns1.02
ViT small (256 x 256 x 3 x 32)/forward/CUDA/Lux
53144411
ns50680627
ns1.05
ViT small (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :after_enzyme)
3046201375
ns2975571725
ns1.02
ViT small (256 x 256 x 3 x 32)/forward/CPU/Reactant
3063894685
ns2986093155
ns1.03
ViT small (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :before_enzyme)
3087462133
ns2978196812
ns1.04
ViT small (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :only_enzyme)
4895902746
ns4911960375
ns1.00
ViT small (256 x 256 x 3 x 32)/forward/CPU/Lux
9797674342
ns8980759371
ns1.09
ViT base (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :after_enzyme)
1295665825
ns1443741989
ns0.90
ViT base (256 x 256 x 3 x 16)/forward/CUDA/Reactant
1436872653
ns1518889344
ns0.95
ViT base (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :before_enzyme)
1277008406
ns1290151359
ns0.99
ViT base (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :only_enzyme)
3239595052
ns3140508919
ns1.03
ViT base (256 x 256 x 3 x 16)/forward/CUDA/Lux
71339137
ns68715424.5
ns1.04
ViT base (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :after_enzyme)
3189935441
ns3162377720
ns1.01
ViT base (256 x 256 x 3 x 16)/forward/CPU/Reactant
3207736040
ns3140139532
ns1.02
ViT base (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :before_enzyme)
3222417327
ns3144637121
ns1.02
ViT base (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :only_enzyme)
5319487172
ns5092189137
ns1.04
ViT base (256 x 256 x 3 x 16)/forward/CPU/Lux
12850280060
ns12329016315
ns1.04
ViT base (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :after_enzyme)
1274372415
ns1326072250
ns0.96
ViT base (256 x 256 x 3 x 4)/forward/CUDA/Reactant
1287517573
ns1283998354
ns1.00
ViT base (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :before_enzyme)
1311075350
ns1283550328
ns1.02
ViT base (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :only_enzyme)
3155538600
ns3074369011
ns1.03
ViT base (256 x 256 x 3 x 4)/forward/CUDA/Lux
20891523
ns19742705
ns1.06
ViT base (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :after_enzyme)
1909585662
ns1880491780
ns1.02
ViT base (256 x 256 x 3 x 4)/forward/CPU/Reactant
1907821565
ns1867141478
ns1.02
ViT base (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :before_enzyme)
1918208063
ns2022272204
ns0.95
ViT base (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :only_enzyme)
3741288084
ns3598201159
ns1.04
ViT base (256 x 256 x 3 x 4)/forward/CPU/Lux
3617112173
ns4440776854
ns0.81
This comment was automatically generated by workflow using github-action-benchmark.