# Taking advantage of Apple M1?

**URL:** <https://discourse.julialang.org/t/taking-advantage-of-apple-m1/93310>\
**Category:** Performance\
**Tags:** mac-m1, hardware\
**Created:** [January 21, 2023, 1:17pm UTC](https://discourse.julialang.org/t/taking-advantage-of-apple-m1/93310 "2023-01-21T13:17:25Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [February 16, 2023, 7:40am UTC](https://discourse.julialang.org/t/taking-advantage-of-apple-m1/93310/21 "2023-02-16T07:40:11Z")

</div>

128Gb with M1 ultra and 96 with M2s. But this is clearly a drawback of this SOC integrated architecture.

---

<div class="post-metadata">

**Author:** ![Vitaliy\_Yakovchuk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vitaliy_yakovchuk/32/47023_2.png) [@Vitaliy\_Yakovchuk](https://discourse.julialang.org/u/Vitaliy_Yakovchuk)\
**Post date:** [February 18, 2023, 5:02pm UTC](https://discourse.julialang.org/t/taking-advantage-of-apple-m1/93310/22 "2023-02-18T17:02:27Z")

</div>

And Apple M2 Max results (30% faster compare to M1 Max):

```julia
julia> include("SingleSpring.jl")
27.5 GFLOPS
132.0 GB/s
  7.324295 seconds (1.40 M allocations: 1.162 GiB, 0.77% gc time, 1.46% compilation time)

julia> versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65e* (2023-01-08 06:45 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin22.1.0)
  CPU: 12 × Apple M2 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
  Threads: 8 on 8 virtual cores
Environment:
  JULIA_EDITOR = code

```

But what is interesting it significantly better with Julia 1.9.0 beta 4:

```julia
julia> include("SingleSpring.jl")
33.5 GFLOPS
161.0 GB/s
  6.690864 seconds (1.30 M allocations: 1.165 GiB, 0.87% gc time, 4.50% compilation time)

julia> versioninfo()
Julia Version 1.9.0-beta4
Commit b75ddb787ff (2023-02-07 21:53 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.5.0)
  CPU: 12 × Apple M2 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1)
  Threads: 8 on 8 virtual cores
Environment:
  JULIA_IMAGE_THREADS = 1

```

---

<div class="post-metadata">

**Author:** ![Vitaliy\_Yakovchuk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vitaliy_yakovchuk/32/47023_2.png) [@Vitaliy\_Yakovchuk](https://discourse.julialang.org/u/Vitaliy_Yakovchuk)\
**Post date:** [February 18, 2023, 5:21pm UTC](https://discourse.julialang.org/t/taking-advantage-of-apple-m1/93310/23 "2023-02-18T17:21:03Z")

</div>

and the

```julia
using BenchmarkTools

n=500000;

x=rand(n);

y=zeros(n);

function threaded_exp!(y,x)
           Threads.@threads for i in eachindex(x)
               @inbounds y[i]=@inline exp(x[i])
           end
       end

function sequential_exp!(y,x)
           for i in eachindex(x)
               @inbounds y[i]=@inline exp(x[i])
           end
       end

tseq = @belapsed sequential_exp!(y,x)

tmt = @belapsed threaded_exp!(y,x)

SpUp = tseq/tmt; Threads.nthreads()

@show tseq,tmt,SpUp;

```

gives me:

```julia
(tseq, tmt, SpUp) = (0.000863083, 0.000123042, 7.014539750654248)
(0.000863083, 0.000123042, 7.014539750654248)

julia> versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65e* (2023-01-08 06:45 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin22.1.0)
  CPU: 12 × Apple M2 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
  Threads: 8 on 8 virtual cores

```

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [February 18, 2023, 5:28pm UTC](https://discourse.julialang.org/t/taking-advantage-of-apple-m1/93310/24 "2023-02-18T17:28:25Z")

</div>

Thanks for the feedback : the bandwidth increases again !

I would launch the `SingleSpring.jl` test twice to ensure that no compilation is included in the timing.  
Is the GLMakie animation smooth ?

---

<div class="post-metadata">

**Author:** ![Vitaliy\_Yakovchuk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vitaliy_yakovchuk/32/47023_2.png) [@Vitaliy\_Yakovchuk](https://discourse.julialang.org/u/Vitaliy_Yakovchuk)\
**Post date:** [February 18, 2023, 5:43pm UTC](https://discourse.julialang.org/t/taking-advantage-of-apple-m1/93310/25 "2023-02-18T17:43:36Z")

</div>

Yes, it is smooth.

I’m working with more real Julia code, which generally uses a lot of memory and is 2x-4x faster than my Intel i9 2019 MacBook Pro (without proving 🙂 ). Just CPU, mostly Float32 Flux operations, and Intel i9 Macbook is significantly hotter and noisier for the case.

---

<div class="post-metadata">

**Author:** ![ndinsmore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ndinsmore/32/7433_2.png) [@ndinsmore](https://discourse.julialang.org/u/ndinsmore)\
**Post date:** [March 11, 2023, 5:01pm UTC](https://discourse.julialang.org/t/taking-advantage-of-apple-m1/93310/26 "2023-03-11T17:01:28Z")

</div>

@Ronis_BR can you share what tools you are using to take advantage of the shared memory?

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [March 11, 2023, 5:02pm UTC](https://discourse.julialang.org/t/taking-advantage-of-apple-m1/93310/27 "2023-03-11T17:02:30Z")

</div>

Hi @ndinsmore !

Nothing special, just Metal.jl. The only important thing is creating the arrays memory aligned so that you can use the same memory region in CPU and GPU.

---

<div class="post-metadata">

**Author:** ![Aakhash\_Sundaresan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aakhash_sundaresan/32/202478_2.png) [@Aakhash\_Sundaresan](https://discourse.julialang.org/u/Aakhash_Sundaresan)\
**Post date:** [November 10, 2023, 8:45pm UTC](https://discourse.julialang.org/t/taking-advantage-of-apple-m1/93310/28 "2023-11-10T20:45:31Z")

</div>

Just use the Threads.@threads macro before a for loop that you want to use in your code…Be mindful of the data-race problem. Initialize the arrays with the appropriate size and manipulate data with multi-threading in a particular memory location of the array elements.

[Previous page](https://discourse.julialang.org/t/taking-advantage-of-apple-m1/93310.md?page=1)
