Skip to content

Commit fb960dd

Browse files
committed
Fix other platforms
1 parent f6ee38c commit fb960dd

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

ext/RandomExt.jl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module RandomExt
2+
3+
@static if Sys.isapple()
4+
25
using BFloat16s
36
using AppleAccelerate: BNNS
47
using .BNNS: BNNSFilterParameters,
@@ -43,11 +46,20 @@ end
4346
BNNS.bnns_rng() = RNG()
4447
BNNS.bnns_rng(seed::Integer) = RNG(seed)
4548

46-
function _get_rng_state(rng::RNG)
47-
stateSize = BNNSRandomGeneratorStateSize(rng.ptr)
48-
state = Memory{UInt8}(undef, Int64(stateSize))
49-
BNNSRandomGeneratorGetState(rng.ptr, stateSize, state)
50-
return state
49+
@static if isdefined(Base, :Memory) #VERSION >= v"1.11"
50+
function _get_rng_state(rng::RNG)
51+
stateSize = BNNSRandomGeneratorStateSize(rng.ptr)
52+
state = Memory{UInt8}(undef, Int64(stateSize))
53+
BNNSRandomGeneratorGetState(rng.ptr, stateSize, state)
54+
return state
55+
end
56+
else
57+
function _get_rng_state(rng::RNG)
58+
stateSize = BNNSRandomGeneratorStateSize(rng.ptr)
59+
state = Vector{UInt8}(undef, Int64(stateSize))
60+
BNNSRandomGeneratorGetState(rng.ptr, stateSize, state)
61+
return state
62+
end
5163
end
5264

5365
function Base.copy!(dest::RNG, src::RNG)
@@ -170,5 +182,5 @@ function BNNS.seed!(seed=Base.rand(UInt64))
170182
Random.seed!(BNNS.default_rng(), seed)
171183
end
172184

173-
185+
end
174186
end # module

0 commit comments

Comments
 (0)