Width, Alignment and Size
from TargetInfo import ( alignof, bitwidthof, simdwidthof, simdbitwidth, simd_byte_width, sizeof ) from DType import DType
You can check the alignment of a type, in the struct below it returns 4 bytes:
struct Foo: var a: UInt8 var b: UInt32 print(alignof[Foo]())
This means each instance of
Foo will start at a memory address that is a multiple of 4 bytes, there will also be 3 bytes of padding to accommodate the
You can use this for anything falling under an
The same as alignof above, but uses bits instead of bytes:
struct Foo: var a: UInt8 var b: UInt32 print(bitwidthof[Foo]())
There will be 24 bits of padding for this type as each object can only be placed at multiples of 64 in memory
How many of the type can fit into the targets SIMD register, e.g. to see how many uint64's can be processed with a single instruction:
The total amount of bits that can be processed at the same time on the host systems SIMD register
Take note how the result of
dtype_simd_width[DType.uint64]() shows you how many of that data type can fit into the systems SIMD register, e.g. 512 / 64 = 8
The total amount of bytes that can be processed at the same time on the host systems SIMD register
The total size in bytes of an
from TargetInfo import os_is_linux, os_is_macos, os_is_windows
Example of conditional compilation based on the operating system:
@parameter if os_is_linux(): print("this will be included in the binary") else: print("this will be eliminated from compilation process")
this will be included in the binary
from TargetInfo import ( has_avx, has_avx2, has_avx512f, has_intel_amx, has_neon, has_sse4, is_apple_m1 )
Advanced Vector Extensions are instructions for x86 SIMD support, they are commonly used in Intel and AMD chips, the first version of AVX first began shipping in 2011.
Advanced Vector Extensions 2 are instructions for x86 SIMD support, expanding integer commands to 256 bits, and started shipping in 2013l
Advanced Vector Extensions 512 added 512 bit support for x86 SIMD instructions, and began shipping in 2016.
AMX is an extension to x86 with instructions for special units designed for ML workloads such as TMUL which is a matrix multiply on BF16, it began shipping in 2023.
Neon also known as Advanced SIMD is an ARM extension for specialized instructions.
SSE4 is the older SIMD instruction extension for x86 processors introduced in the mid 2000's