IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /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. /get-started.md).

Mojo struct

AccessPolicyWindow

struct AccessPolicyWindow

Specifies an access policy for a window of memory.

This struct defines a contiguous extent of memory beginning at base_ptr and ending at base_ptr + num_bytes, with associated access policies. It allows fine-grained control over how memory is accessed and cached, which can significantly impact performance for memory-bound workloads.

The window is partitioned into segments with different access properties based on the hit_ratio. Accesses to "hit segments" use the hit_prop policy, while accesses to "miss segments" use the miss_prop policy.

Note: The num_bytes value is limited by CU_DEVICE_ATTRIBUTE_MAX_ACCESS_POLICY_WINDOW_SIZE. The CUDA driver may align the base_ptr and restrict the maximum size.

Fields​

  • ​base_ptr (Optional[Pointer[NoneType, MutUntrackedOrigin]]): Starting address of the access policy window. Driver may align it.
  • ​num_bytes (Int): Size in bytes of the window policy. CUDA driver may restrict the maximum size and alignment.
  • ​hit_ratio (Float32): Specifies percentage of lines assigned hit_prop, rest are assigned miss_prop. Value should be between 0.0 and 1.0.
  • ​hit_prop (AccessProperty): AccessProperty applied to hit segments within the window.
  • ​miss_prop (AccessProperty): AccessProperty applied to miss segments within the window. Must be either NORMAL or STREAMING.

Implemented traits​

AnyType, Copyable, Defaultable, Deinitable, ImplicitlyCopyable, Movable, RegisterPassable, Writable

Methods​

__init__​

def __init__() -> Self

Initializes a new AccessPolicyWindow with default values.

def __init__[T: AnyType](*, base_ptr: Pointer[T, address_space=base_ptr.address_space], count: Int, hit_ratio: Float32, hit_prop: AccessProperty = AccessProperty.NORMAL, miss_prop: AccessProperty = AccessProperty.NORMAL) -> Self

Initializes an AccessPolicyWindow for a typed memory region.

Parameters:

  • ​T (AnyType): The type of data in the memory region.

Args:

  • ​base_ptr (Pointer[T, address_space=base_ptr.address_space]): Pointer to the start of the memory region.
  • ​count (Int): Number of elements of type T in the memory region.
  • ​hit_ratio (Float32): Fraction of the window that should use hit_prop (0.0 to 1.0).
  • ​hit_prop (AccessProperty): Access property for hit segments (default: NORMAL).
  • ​miss_prop (AccessProperty): Access property for miss segments (default: NORMAL).

write_to​

def write_to(self, mut writer: T)

Writes a string representation of the AccessPolicyWindow to a writer.

This method formats all the fields of the AccessPolicyWindow into a human-readable string representation and writes it to the provided writer.

Args:

  • ​writer (T): The writer instance to write the formatted string to.