cast metal::atomic_int to int

Is there any way to cast metal::atomic_intto int in MSLibrary like C++ Standard Library ?

C++:
Code Block
 std::atomic<int> atom {10};
 int num = (int)atom;

MSL:
Code Block
kernel void compute_shader (device metal::atomic_int& incremental [[buffer(0)]],threadgroup atomic_int& local [[threadgroup(0)]],ushort lid [[thread_position_in_threadgroup]] ){
  atomic_fetch_add_explicit(&local, 1, memory_order_relaxed);
  threadgroup_barrier(mem_flags::mem_threadgroup);
  if(lid == 0) {
    atomic_fetch_add_explicit(&incremental, (int)local, memory_order_relaxed);//ERROR
    atomic_fetch_add_explicit(&incremental, as_type<int>(local), memory_order_relaxed);//ERROR
  }
}


Answered by Graphics and Games Engineer in 668975022
You can use the atomic_load_explicit() function as follows:

Code Block
kernel void compute_shader (device metal::atomic_int& my_atomic_int)
{
    int my_thread_int = atomic_load_explicit(&my_atomic_int, memory_order_relaxed);
...
}

Accepted Answer
You can use the atomic_load_explicit() function as follows:

Code Block
kernel void compute_shader (device metal::atomic_int& my_atomic_int)
{
    int my_thread_int = atomic_load_explicit(&my_atomic_int, memory_order_relaxed);
...
}

cast metal::atomic_int to int
 
 
Q