IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Mojo function

shmem_calloc

shmem_calloc[dtype: DType](count: Int, size: Int = Int[Int](size_of[dtype]())) -> UnsafePointer[Scalar[dtype], MutExternalOrigin]

Collectively allocate a zeroed block of symmetric memory.

The shmem_calloc routine is a collective operation on the world team that allocates a region of remotely accessible memory for an array of count objects of size bytes each and returns a pointer to the lowest byte address of the allocated symmetric memory. The space is initialized to all bits zero. If the allocation succeeds, the pointer returned shall be suitably aligned so that it may be assigned to a pointer to any type of object. If the allocation does not succeed, or either count or size is 0, the return value is a null pointer. The values for count and size shall each be equal across all PEs calling shmem_calloc; otherwise, the behavior is undefined. When count or size is 0, the shmem_calloc routine returns without performing a barrier. Otherwise, this routine calls a procedure that is semantically equivalent to shmem_barrier_all on exit.

Note: on ROCSHMEM this will raise an error if exceeding the default static symmetric heap size of 1GB across all GPUs, while NVSHMEM uses dynamic symmetric heap allocation and won't error.

Parameters:

  • โ€‹dtype (DType): The data type of elements to allocate memory for.

Args:

  • โ€‹count (Int): The number of elements to allocate.
  • โ€‹size (Int): The size in bytes of each element (defaults to size_ofdtype).

Returns:

UnsafePointer[Scalar[dtype], MutExternalOrigin]: A pointer to the lowest byte address of the allocated space; otherwise, it returns a null pointer.