Skip to main content
Log in

Mojo struct

CacheOperation

struct CacheOperation

Represents different GPU cache operation policies.

This struct defines various caching behaviors for GPU memory operations, controlling how data is cached and evicted at different cache levels. The policies affect performance and memory coherency.

Aliases

  • ALWAYS = CacheOperation(0): Cache at all levels. This will be accessed again. Best for data that will be frequently reused across multiple threads. Provides fastest subsequent access but uses the most cache space.
  • GLOBAL = CacheOperation(1): Cache at global level. Caches data only in the L2 cache, bypassing L1. Good for data shared between different thread blocks.
  • STREAMING = CacheOperation(2): Streaming, this is likely to be accessed once. Optimizes for streaming access patterns where data is only read once. May bypass certain cache levels for better throughput.
  • LAST_USE = CacheOperation(3): Indicates the cache line will not be used again. Hints to the cache that this data can be evicted after this access. Helps optimize cache utilization.
  • VOLATILE = CacheOperation(4): Don't cache, and fetch again. Forces reads/writes to bypass cache and go directly to memory. Useful for memory-mapped I/O or when cache coherency is required.
  • WRITE_BACK = CacheOperation(5): Write back at all coherent levels. Updates all cache levels and eventually writes to memory. Most efficient for multiple writes to same location.
  • WRITE_THROUGH = CacheOperation(6): Write through to system memory. Immediately writes updates to memory while updating cache. Provides stronger consistency but lower performance than write-back.

Implemented traits

AnyType, Copyable, ExplicitlyCopyable, Movable, UnknownDestructibility

Methods

__eq__

__eq__(self, other: Self) -> Bool

Tests if two CacheOperation instances are equal.

Args:

  • other (Self): The CacheOperation to compare against.

Returns:

True if the operations are equal, False otherwise.

__ne__

__ne__(self, other: Self) -> Bool

Tests if two CacheOperation instances are not equal.

Args:

  • other (Self): The CacheOperation to compare against.

Returns:

True if the operations are not equal, False otherwise.

__is__

__is__(self, other: Self) -> Bool

Tests if two CacheOperation instances are identical.

Args:

  • other (Self): The CacheOperation to compare against.

Returns:

True if the operations are identical, False otherwise.

__isnot__

__isnot__(self, other: Self) -> Bool

Tests if two CacheOperation instances are not identical.

Args:

  • other (Self): The CacheOperation to compare against.

Returns:

True if the operations are not identical, False otherwise.

mnemonic

mnemonic(self) -> StringLiteral

Returns the PTX mnemonic string for this cache operation.

Converts the cache operation into its corresponding PTX assembly mnemonic string used in GPU instructions.

Returns:

A string literal containing the PTX mnemonic for this operation.