Skip to main content
Log in

Mojo struct

AccessPolicyWindow

@register_passable(trivial) 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 (UnsafePointer[NoneType]): 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 (SIMD[float32, 1]): 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, UnknownDestructibility, Writable

Methods

__init__

__init__() -> Self

Initializes a new AccessPolicyWindow with default values.

__init__[T: AnyType](*, base_ptr: UnsafePointer[T, address_space=address_space, alignment=alignment, mut=mut, origin=origin], count: Int, hit_ratio: SIMD[float32, 1], hit_prop: AccessProperty = AccessProperty(__init__[__mlir_type.!pop.int_literal](0)), miss_prop: AccessProperty = AccessProperty(__init__[__mlir_type.!pop.int_literal](0))) -> Self

Initializes an AccessPolicyWindow for a typed memory region.

Parameters:

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

Args:

  • base_ptr (UnsafePointer[T, address_space=address_space, alignment=alignment, mut=mut, origin=origin]): Pointer to the start of the memory region.
  • count (Int): Number of elements of type T in the memory region.
  • hit_ratio (SIMD[float32, 1]): 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).

__str__

__str__(self) -> String

Returns a string representation of the AccessPolicyWindow.

Returns:

A string representation of the AccessPolicyWindow.

write_to

write_to[W: Writer](self, mut writer: W)

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.

Parameters:

  • W (Writer): The type of writer to use for output. Must implement the Writer trait.

Args:

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