MUSA Driver API Reference
1. Introduction
The MUSA Driver API is the low-level mu* interface for applications and libraries that need direct control over devices, contexts, modules, memory, streams, events, graphs, and interoperability objects.
This reference describes the MUSA Driver APIs supported in MUSA SDK 5.2.0. Use it as the compatibility reference for the functions, types, structures, fields, constants, and result values documented here.
Note: Some Driver API declarations may appear in the headers but are not described in this reference. These declarations are experimental in MUSA SDK 5.2.0 and are provided for reference only.
2. Using the Driver API
Start with the Runtime API when you want the application-level musa* interface. Use this Driver reference when you need lower-level mu* control, or when a Runtime entry points to a Driver-level object or equivalent.
Driver API use depends on initialization and context state. Review Initialization, Primary Context Management, and Context Management before allocating memory, loading modules, launching work, or sharing resources across APIs.
Synchronization behavior, asynchronous error reporting, object lifetime, and thread-safety constraints are documented in the function entries. For Stream Management, Event Management, Memory Management, Execution Control, and Graph Management APIs, read the Returns and Note sections before relying on host-side completion or object sharing.
Use Version Management for Driver version checks and Driver Entry Point Access to resolve Driver symbols dynamically.
3. Modules
The API reference is organized by capability module.
Module List
- 3.1 Error Handling
- 3.2 Initialization
- 3.3 Version Management
- 3.4 Device Management
- 3.5 Device Management [DEPRECATED]
- 3.6 Primary Context Management
- 3.7 Context Management
- 3.8 Context Management [DEPRECATED]
- 3.9 Module Management
- 3.10 Module Management [DEPRECATED]
- 3.11 Library Management
- 3.12 Memory Management
- 3.13 Virtual Memory Management
- 3.14 Stream Ordered Memory Allocator
- 3.15 Unified Addressing
- 3.16 Stream Management
- 3.17 Event Management
- 3.18 External Resource Interoperability
- 3.19 Stream Memory Operations
- 3.20 Execution Control
- 3.21 Execution Control [DEPRECATED]
- 3.22 Graph Management
- 3.23 Occupancy
- 3.24 Texture Reference Management [DEPRECATED]
- 3.25 Surface Reference Management [DEPRECATED]
- 3.26 Texture Object Management
- 3.27 Surface Object Management
- 3.28 Tensor Map Object Management
- 3.29 Peer Context Memory Access
- 3.30 Graphics Interoperability
- 3.31 Driver Entry Point Access
- 3.32 Memory Atomic Management
- 3.33 Coredump Attributes Control API
- 3.34 Green Contexts
- 3.35 Error Log Management
- 3.36 OpenGL Interoperability
- 3.37 Profiler Control
3.1 Error Handling
muGetErrorString
MUresult muGetErrorString(MUresult error, const char **pStr)
Description
- Gets the string description of an error code.
- Sets *pStr to the address of a NULL-terminated string description of the error code error. If the error code is not recognized, MUSA_ERROR_INVALID_VALUE will be returned and *pStr will be set to the NULL address.
Parameters
error(MUresult): Error code to convert to stringpStr(const char **): Address of the string pointer.
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
See also
- MUresult, musaGetErrorString
muGetErrorName
MUresult muGetErrorName(MUresult error, const char **pStr)
Description
- Gets the string representation of an error code enum name.
- Sets *pStr to the address of a NULL-terminated string representation of the name of the enum error code error. If the error code is not recognized, MUSA_ERROR_INVALID_VALUE will be returned and *pStr will be set to the NULL address.
Parameters
error(MUresult): Error code to convert to stringpStr(const char **): Address of the string pointer.
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
See also
- MUresult, musaGetErrorName
3.2 Initialization
muInit
MUresult muInit(unsigned int Flags)
Description
- Initialize the MUSA driver API Initializes the driver API and must be called before any other function from the driver API in the current process. Currently, the Flags parameter must be 0. If muInit() has not been called, any function from the driver API will return MUSA_ERROR_NOT_INITIALIZED.
- Note: muInit preloads various libraries needed for JIT compilation. To opt-out of this behavior, set the environment variable MUSA_FORCE_PRELOAD_LIBRARIES=0. MUSA will lazily load JIT libraries as needed. To disable JIT entirely, set the environment variable MUSA_DISABLE_JIT=1.
Parameters
Flags(unsigned int): Initialization flag for MUSA.
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_SYSTEM_DRIVER_MISMATCH, MUSA_ERROR_COMPAT_NOT_SUPPORTED_ON_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
3.3 Version Management
muDriverGetVersion
MUresult muDriverGetVersion(int *driverVersion)
Description
- Returns the latest MUSA version supported by driver.
- Returns in *driverVersion the version of MUSA supported by the driver. The version is returned as (1000 major + 10 minor). For example, MUSA 9.2 would be represented by 9020.
- This function automatically returns MUSA_ERROR_INVALID_VALUE if driverVersion is NULL.
Parameters
driverVersion(int *): Returns the MUSA driver version
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
3.4 Device Management
muDeviceGet
MUresult muDeviceGet(MUdevice *device, int ordinal)
Description
- Returns a handle to a compute device.
- Returns in *device a device handle given an ordinal in the range [0, muDeviceGetCount()-1].
Parameters
device(MUdevice *): Returned device handleordinal(int): Device number to get handle for
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muDeviceGetAttribute, muDeviceGetCount, muDeviceGetName, muDeviceGetUuid, muDeviceGetLuid, muDeviceTotalMem, muDeviceGetExecAffinitySupport
muDeviceGetCount
MUresult muDeviceGetCount(int *count)
Description
- Returns the number of compute-capable devices.
- Returns in *count the number of devices with compute capability greater than or equal to 2.0 that are available for execution. If there is no such device, muDeviceGetCount() returns 0.
Parameters
count(int *): Returned number of compute-capable devices
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muDeviceGetAttribute, muDeviceGetName, muDeviceGetUuid, muDeviceGetLuid, muDeviceGet, muDeviceTotalMem, muDeviceGetExecAffinitySupport, musaGetDeviceCount
muDeviceGetName
MUresult muDeviceGetName(char *name, int len, MUdevice dev)
Description
- Returns an identifier string for the device.
- Returns an ASCII string identifying the device dev in the NULL-terminated string pointed to by name. len specifies the maximum length of the string that may be returned.
Parameters
name(char *): Returned identifier string for the devicelen(int): Maximum length of string to store in namedev(MUdevice): Device to get identifier string for
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muDeviceGetAttribute, muDeviceGetUuid, muDeviceGetLuid, muDeviceGetCount, muDeviceGet, muDeviceTotalMem, muDeviceGetExecAffinitySupport, musaGetDeviceProperties
muDeviceGetUuid
MUresult muDeviceGetUuid(MUuuid *uuid, MUdevice dev)
Description
- Return an UUID for the device.
- Note there is a later version of this API, muDeviceGetUuid_v2. It will supplant this version in 12.0, which is retained for minor version compatibility.
- Returns 16-octets identifying the device dev in the structure pointed by the uuid.
Parameters
uuid(MUuuid *): Returned UUIDdev(MUdevice): Device to get identifier string for
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muDeviceGetUuid_v2 muDeviceGetAttribute, muDeviceGetCount, muDeviceGetName, muDeviceGetLuid, muDeviceGet, muDeviceTotalMem, muDeviceGetExecAffinitySupport, musaGetDeviceProperties
muDeviceGetUuid_v2
MUresult muDeviceGetUuid_v2(MUuuid *uuid, MUdevice dev)
Description
- Return an UUID for the device (11.4+)
- Returns 16-octets identifying the device dev in the structure pointed by the uuid. If the device is in MIG mode, returns its MIG UUID which uniquely identifies the subscribed MIG compute instance.
Parameters
uuid(MUuuid *): Returned UUIDdev(MUdevice): Device to get identifier string for
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muDeviceGetAttribute, muDeviceGetCount, muDeviceGetName, muDeviceGetLuid, muDeviceGet, muDeviceTotalMem, musaGetDeviceProperties
muDeviceTotalMem
MUresult muDeviceTotalMem(size_t *bytes, MUdevice dev)
Description
- Return an LUID and device node mask for the device.
- Return identifying information (luid and deviceNodeMask) to allow matching device with graphics APIs.
- Returns in *bytes the total amount of memory available on the device dev in bytes.
Parameters
bytes(size_t *): Returned memory available on device in bytesdev(MUdevice): Device handle
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- Additional exported symbol names in scope:
muDeviceTotalMem_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muDeviceGetAttribute, muDeviceGetCount, muDeviceGetName, muDeviceGet, muDeviceTotalMem, muDeviceGetExecAffinitySupport, musaGetDeviceProperties
- muDeviceGetAttribute, muDeviceGetCount, muDeviceGetName, muDeviceGetUuid, muDeviceGet, muDeviceGetExecAffinitySupport, musaMemGetInfo
muDeviceGetTexture1DLinearMaxWidth
MUresult muDeviceGetTexture1DLinearMaxWidth(size_t *maxWidthInElements, MUarray_format format, unsigned numChannels, MUdevice dev)
Description
- Returns the maximum number of elements allocatable in a 1D linear texture for a given texture element size.
- Returns in maxWidthInElements the maximum number of texture elements allocatable in a 1D linear texture for given format and numChannels.
Parameters
maxWidthInElements(size_t *): Returned maximum number of texture elements allocatable for given format and numChannels.format(MUarray_format): Texture format.numChannels(unsigned): Number of channels per texture element.dev(MUdevice): Device handle.
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muDeviceGetAttribute, muDeviceGetCount, muDeviceGetName, muDeviceGetUuid, muDeviceGet, musaMemGetInfo, muDeviceTotalMem
muDeviceGetAttribute
MUresult muDeviceGetAttribute(int *pi, MUdevice_attribute attrib, MUdevice dev)
Description
- Returns information about the device.
- Returns in *pi the integer value of the attribute attrib on device dev. The supported attributes are: MU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK: Maximum number of threads per block; MU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_X: Maximum x-dimension of a block MU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Y: Maximum y-dimension of a block MU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Z: Maximum z-dimension of a block MU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_X: Maximum x-dimension of a grid MU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Y: Maximum y-dimension of a grid MU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Z: Maximum z-dimension of a grid MU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK: Maximum amount of shared memory available to a thread block in bytes MU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY: Memory available on device for constant variables in a MUSA C kernel in bytes MU_DEVICE_ATTRIBUTE_WARP_SIZE: Warp size in threads MU_DEVICE_ATTRIBUTE_MAX_PITCH: Maximum pitch in bytes allowed by the memory copy functions that involve memory regions allocated through muMemAllocPitch() MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_WIDTH: Maximum 1D texture width MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_LINEAR_WIDTH: Maximum width for a 1D texture bound to linear memory MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_MIPMAPPED_WIDTH: Maximum mipmapped 1D texture width MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_WIDTH: Maximum 2D texture width MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_HEIGHT: Maximum 2D texture height MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_WIDTH: Maximum width for a 2D texture bound to linear memory MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_HEIGHT: Maximum height for a 2D texture bound to linear memory MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_PITCH: Maximum pitch in bytes for a 2D texture bound to linear memory MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_MIPMAPPED_WIDTH: Maximum mipmapped 2D texture width MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_MIPMAPPED_HEIGHT: Maximum mipmapped 2D texture height MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_WIDTH: Maximum 3D texture width MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_HEIGHT: Maximum 3D texture height MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_DEPTH: Maximum 3D texture depth MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_WIDTH_ALTERNATE: Alternate maximum 3D texture width, 0 if no alternate maximum 3D texture size is supported MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_HEIGHT_ALTERNATE: Alternate maximum 3D texture height, 0 if no alternate maximum 3D texture size is supported MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_DEPTH_ALTERNATE: Alternate maximum 3D texture depth, 0 if no alternate maximum 3D texture size is supported MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURECUBEMAP_WIDTH: Maximum cubemap texture width or height MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_LAYERED_WIDTH: Maximum 1D layered texture width MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_LAYERED_LAYERS: Maximum layers in a 1D layered texture MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LAYERED_WIDTH: Maximum 2D layered texture width MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LAYERED_HEIGHT: Maximum 2D layered texture height MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LAYERED_LAYERS: Maximum layers in a 2D layered texture MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURECUBEMAP_LAYERED_WIDTH: Maximum cubemap layered texture width or height MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURECUBEMAP_LAYERED_LAYERS: Maximum layers in a cubemap layered texture MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE1D_WIDTH: Maximum 1D surface width MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_WIDTH: Maximum 2D surface width MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_HEIGHT: Maximum 2D surface height MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_WIDTH: Maximum 3D surface width MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_HEIGHT: Maximum 3D surface height MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_DEPTH: Maximum 3D surface depth MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE1D_LAYERED_WIDTH: Maximum 1D layered surface width MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE1D_LAYERED_LAYERS: Maximum layers in a 1D layered surface MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_LAYERED_WIDTH: Maximum 2D layered surface width MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_LAYERED_HEIGHT: Maximum 2D layered surface height MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_LAYERED_LAYERS: Maximum layers in a 2D layered surface MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACECUBEMAP_WIDTH: Maximum cubemap surface width MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACECUBEMAP_LAYERED_WIDTH: Maximum cubemap layered surface width MU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACECUBEMAP_LAYERED_LAYERS: Maximum layers in a cubemap layered surface MU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_BLOCK: Maximum number of 32-bit registers available to a thread block MU_DEVICE_ATTRIBUTE_CLOCK_RATE: The typical clock frequency in kilohertz MU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT: Alignment requirement; texture base addresses aligned to textureAlign bytes do not need an offset applied to texture fetches MU_DEVICE_ATTRIBUTE_TEXTURE_PITCH_ALIGNMENT: Pitch alignment requirement for 2D texture references bound to pitched memory MU_DEVICE_ATTRIBUTE_GPU_OVERLAP: 1 if the device can concurrently copy memory between host and device while executing a kernel, or 0 if not MU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT: Number of multiprocessors on the device MU_DEVICE_ATTRIBUTE_KERNEL_EXEC_TIMEOUT: 1 if there is a run time limit for kernels executed on the device, or 0 if not MU_DEVICE_ATTRIBUTE_INTEGRATED: 1 if the device is integrated with the memory subsystem, or 0 if not MU_DEVICE_ATTRIBUTE_CAN_MAP_HOST_MEMORY: 1 if the device can map host memory into the MUSA address space, or 0 if not MU_DEVICE_ATTRIBUTE_COMPUTE_MODE: Compute mode that device is currently in. Available modes are as follows: MU_COMPUTEMODE_DEFAULT: Default mode - Device is not restricted and can have multiple MUSA contexts present at a single time. MU_COMPUTEMODE_PROHIBITED: Compute-prohibited mode - Device is prohibited from creating new MUSA contexts. MU_COMPUTEMODE_EXCLUSIVE_PROCESS: Compute-exclusive-process mode - Device can have only one context used by a single process at a time. MU_DEVICE_ATTRIBUTE_CONCURRENT_KERNELS: 1 if the device supports executing multiple kernels within the same context simultaneously, or 0 if not. It is not guaranteed that multiple kernels will be resident on the device concurrently so this feature should not be relied upon for correctness. MU_DEVICE_ATTRIBUTE_ECC_ENABLED: 1 if error correction is enabled on the device, 0 if error correction is disabled or not supported by the device MU_DEVICE_ATTRIBUTE_PCI_BUS_ID: PCI bus identifier of the device MU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID: PCI device (also known as slot) identifier of the device MU_DEVICE_ATTRIBUTE_PCI_DOMAIN_ID: PCI domain identifier of the device MU_DEVICE_ATTRIBUTE_TCC_DRIVER: 1 if the device is using a TCC driver. TCC is only available on Tesla hardware running Windows Vista or later MU_DEVICE_ATTRIBUTE_MEMORY_CLOCK_RATE: Peak memory clock frequency in kilohertz MU_DEVICE_ATTRIBUTE_GLOBAL_MEMORY_BUS_WIDTH: Global memory bus width in bits MU_DEVICE_ATTRIBUTE_L2_CACHE_SIZE: Size of L2 cache in bytes. 0 if the device doesn't have L2 cache MU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR: Maximum resident threads per multiprocessor MU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING: 1 if the device shares a unified address space with the host, or 0 if not MU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR: Major compute capability version number MU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR: Minor compute capability version number MU_DEVICE_ATTRIBUTE_GLOBAL_L1_CACHE_SUPPORTED: 1 if device supports caching globals in L1 cache, 0 if caching globals in L1 cache is not supported by the device MU_DEVICE_ATTRIBUTE_LOCAL_L1_CACHE_SUPPORTED: 1 if device supports caching locals in L1 cache, 0 if caching locals in L1 cache is not supported by the device MU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_MULTIPROCESSOR: Maximum amount of shared memory available to a multiprocessor in bytes; this amount is shared by all thread blocks simultaneously resident on a multiprocessor MU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR: Maximum number of 32-bit registers available to a multiprocessor; this number is shared by all thread blocks simultaneously resident on a multiprocessor MU_DEVICE_ATTRIBUTE_MANAGED_MEMORY: 1 if device supports allocating managed memory on this system, 0 if allocating managed memory is not supported by the device on this system. MU_DEVICE_ATTRIBUTE_MULTI_GPU_BOARD: 1 if device is on a multi-GPU board, 0 if not. MU_DEVICE_ATTRIBUTE_MULTI_GPU_BOARD_GROUP_ID: Unique identifier for a group of devices associated with the same board. Devices on the same multi-GPU board will share the same identifier. MU_DEVICE_ATTRIBUTE_HOST_NATIVE_ATOMIC_SUPPORTED: 1 if Link between the device and the host supports native atomic operations. MU_DEVICE_ATTRIBUTE_SINGLE_TO_DOUBLE_PRECISION_PERF_RATIO: Ratio of single precision performance (in floating-point operations per second) to double precision performance. MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS: Device supports coherently accessing pageable memory without calling musaHostRegister on it. MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS: Device can coherently access managed memory concurrently with the CPU. MU_DEVICE_ATTRIBUTE_COMPUTE_PREEMPTION_SUPPORTED: Device supports Compute Preemption. MU_DEVICE_ATTRIBUTE_CAN_USE_HOST_POINTER_FOR_REGISTERED_MEM: Device can access host registered memory at the same virtual address as the CPU. MU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK_OPTIN: The maximum per block shared memory size supported on this device. This is the maximum value that can be opted into when using the muFuncSetAttribute() or muKernelSetAttribute() call. For more details see MU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES: Device accesses pageable memory via the host's page tables. MU_DEVICE_ATTRIBUTE_DIRECT_MANAGED_MEM_ACCESS_FROM_HOST: The host can directly access managed memory on the device without migration. MU_DEVICE_ATTRIBUTE_VIRTUAL_MEMORY_MANAGEMENT_SUPPORTED: Device supports virtual memory management APIs like muMemAddressReserve, muMemCreate, muMemMap and related APIs MU_DEVICE_ATTRIBUTE_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR_SUPPORTED: Device supports exporting memory to a posix file descriptor with muMemExportToShareableHandle, if requested via muMemCreate MU_DEVICE_ATTRIBUTE_HANDLE_TYPE_WIN32_HANDLE_SUPPORTED: Device supports exporting memory to a Win32 NT handle with muMemExportToShareableHandle, if requested via muMemCreate MU_DEVICE_ATTRIBUTE_HANDLE_TYPE_WIN32_KMT_HANDLE_SUPPORTED: Device supports exporting memory to a Win32 KMT handle with muMemExportToShareableHandle, if requested via muMemCreate MU_DEVICE_ATTRIBUTE_MAX_BLOCKS_PER_MULTIPROCESSOR: Maximum number of thread blocks that can reside on a multiprocessor MU_DEVICE_ATTRIBUTE_GENERIC_COMPRESSION_SUPPORTED: Device supports compressible memory allocation via muMemCreate MU_DEVICE_ATTRIBUTE_MAX_PERSISTING_L2_CACHE_SIZE: Maximum L2 persisting lines capacity setting in bytes MU_DEVICE_ATTRIBUTE_MAX_ACCESS_POLICY_WINDOW_SIZE: Maximum value of MUaccessPolicyWindow::num_bytes MU_DEVICE_ATTRIBUTE_GPU_DIRECT_RDMA_WITH_MUSA_VMM_SUPPORTED: Device supports specifying the GPUDirect RDMA flag with muMemCreate. MU_DEVICE_ATTRIBUTE_RESERVED_SHARED_MEMORY_PER_BLOCK: Amount of shared memory per block reserved by MUSA driver in bytes MU_DEVICE_ATTRIBUTE_SPARSE_MUSA_ARRAY_SUPPORTED: Device supports sparse MUSA arrays and sparse MUSA mipmapped arrays. MU_DEVICE_ATTRIBUTE_READ_ONLY_HOST_REGISTER_SUPPORTED: Device supports using the muMemHostRegister flag MU_MEMHOSTERGISTER_READ_ONLY to register memory that must be mapped as read-only to the GPU MU_DEVICE_ATTRIBUTE_MEMORY_POOLS_SUPPORTED: Device supports using the muMemAllocAsync and muMemPool family of APIs MU_DEVICE_ATTRIBUTE_GPU_DIRECT_RDMA_SUPPORTED: Device supports GPUDirect RDMA APIs, like mthreads_p2p_get_pages (see https://docs.mthreads.com/musa/gpudirect-rdma for more information) MU_DEVICE_ATTRIBUTE_GPU_DIRECT_RDMA_FLUSH_WRITES_OPTIONS: The returned attribute shall be interpreted as a bitmask, where the individual bits are described by the MUflushGPUDirectRDMAWritesOptions enum MU_DEVICE_ATTRIBUTE_GPU_DIRECT_RDMA_WRITES_ORDERING: GPUDirect RDMA writes to the device do not need to be flushed for consumers within the scope indicated by the returned attribute. See MUGPUDirectRDMAWritesOrdering for the numerical values returned here. MU_DEVICE_ATTRIBUTE_MEMPOOL_SUPPORTED_HANDLE_TYPES: Bitmask of handle types supported with mempool based IPC MU_DEVICE_ATTRIBUTE_DEFERRED_MAPPING_MUSA_ARRAY_SUPPORTED: Device supports deferred mapping MUSA arrays and MUSA mipmapped arrays. MU_DEVICE_ATTRIBUTE_NUMA_CONFIG: NUMA configuration of a device: value is of type MUdeviceNumaConfig enum MU_DEVICE_ATTRIBUTE_NUMA_ID: NUMA node ID of the GPU memory MU_DEVICE_ATTRIBUTE_MULTICAST_SUPPORTED: Device supports switch multicast and reduction operations. MU_DEVICE_ATTRIBUTE_GPU_PCI_DEVICE_ID: The combined 16-bit PCI device ID and 16-bit PCI vendor ID. MU_DEVICE_ATTRIBUTE_GPU_PCI_SUBSYSTEM_ID: The combined 16-bit PCI subsystem ID and 16-bit PCI subsystem vendor ID. ID.
Parameters
pi(int *): Returned device attribute valueattrib(MUdevice_attribute): Device attribute to querydev(MUdevice): Device handle
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muDeviceGetCount, muDeviceGetName, muDeviceGetUuid, muDeviceGet, muDeviceTotalMem, muDeviceGetExecAffinitySupport, musaDeviceGetAttribute, musaGetDeviceProperties
muDeviceSetMemPool
MUresult muDeviceSetMemPool(MUdevice dev, MUmemoryPool pool)
Description
- Queries details about atomic operations supported between the device and host.
- Returns in *capabilities the details about requested atomic *operations over the the link between dev and the host. The allocated size of *operations and *capabilities must be count.
- For each MUatomicOperation in *operations, the corresponding result in *capabilities will be a bitmask indicating which of MUatomicOperationCapability the link supports natively.
- Returns MUSA_ERROR_INVALID_DEVICE if dev is not valid.
- Returns MUSA_ERROR_INVALID_VALUE if *capabilities or *operations is NULL, if count is 0, or if any of *operations is not valid.
- Returns in mtSciSyncAttrList, the properties of NvSciSync that this MUSA device, dev can support. The returned mtSciSyncAttrList can be used to create an NvSciSync object that matches this device's capabilities.
- If NvSciSyncAttrKey_RequiredPerm field in mtSciSyncAttrList is already set this API will return MUSA_ERROR_INVALID_VALUE.
- The applications should set mtSciSyncAttrList to a valid NvSciSyncAttrList failing which this API will return MUSA_ERROR_INVALID_HANDLE.
- The flags controls how applications intends to use the NvSciSync created from the mtSciSyncAttrList. The valid flags are: MUSA_MTSCISYNC_ATTR_SIGNAL, specifies that the applications intends to signal an NvSciSync on this MUSA device. MUSA_MTSCISYNC_ATTR_WAIT, specifies that the applications intends to wait on an NvSciSync on this MUSA device.
- At least one of these flags must be set, failing which the API returns MUSA_ERROR_INVALID_VALUE. Both the flags are orthogonal to one another: a developer may set both these flags that allows to set both wait and signal specific attributes in the same mtSciSyncAttrList.
- Note that this API updates the input mtSciSyncAttrList with values equivalent to the following public attribute key-values: NvSciSyncAttrKey_RequiredPerm is set to NvSciSyncAccessPerm_SignalOnly if MUSA_MTSCISYNC_ATTR_SIGNAL is set in flags. NvSciSyncAccessPerm_WaitOnly if MUSA_MTSCISYNC_ATTR_WAIT is set in flags. NvSciSyncAccessPerm_WaitSignal if both MUSA_MTSCISYNC_ATTR_WAIT and MUSA_MTSCISYNC_ATTR_SIGNAL are set in flags. NvSciSyncAttrKey_PrimitiveInfo is set to NvSciSyncAttrValPrimitiveType_SysmemSemaphore on any valid device. NvSciSyncAttrValPrimitiveType_Syncpoint if device is a Tegra device. NvSciSyncAttrValPrimitiveType_SysmemSemaphorePayload64b if device is GA10X+. NvSciSyncAttrKey_GpuId is set to the same UUID that is returned for this device from muDeviceGetUuid.
- The memory pool must be local to the specified device. muMemAllocAsync allocates from the current mempool of the provided stream's device. By default, a device's current memory pool is its default memory pool.
Parameters
dev(MUdevice): Valid Musa Device to get NvSciSync attributes for.pool(MUmemoryPool)
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_INVALID_VALUE
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
- Use muMemAllocFromPoolAsync to specify asynchronous allocations from a device different than the one the stream runs on.
See also
- muDeviceGetAttribute, muDeviceGetP2PAtomicCapabilities, musaDeviceGeHostAtomicCapabilities
- muImportExternalSemaphore, muDestroyExternalSemaphore, muSignalExternalSemaphoresAsync, muWaitExternalSemaphoresAsync
- muDeviceGetDefaultMemPool, muDeviceGetMemPool, muMemPoolCreate, muMemPoolDestroy, muMemAllocFromPoolAsync
muDeviceGetMemPool
MUresult muDeviceGetMemPool(MUmemoryPool *pool, MUdevice dev)
Description
- Gets the current mempool for a device.
- Returns the last pool provided to muDeviceSetMemPool for this device or the device's default memory pool if muDeviceSetMemPool has never been called. By default the current mempool is the default mempool for a device. Otherwise the returned pool must have been set with muDeviceSetMemPool.
Parameters
pool(MUmemoryPool *)dev(MUdevice)
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
See also
muDeviceGetDefaultMemPool
MUresult muDeviceGetDefaultMemPool(MUmemoryPool *pool_out, MUdevice dev)
Description
- Returns the default mempool of a device.
- The default mempool of a device contains device memory from that device.
Parameters
pool_out(MUmemoryPool *)dev(MUdevice)
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_NOT_SUPPORTED
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muMemAllocAsync, muMemPoolTrimTo, muMemPoolGetAttribute, muMemPoolSetAttribute, muMemPoolSetAccess, muDeviceGetMemPool, muMemPoolCreate
3.5 Device Management [DEPRECATED]
muDeviceGetProperties
MUresult muDeviceGetProperties(MUdevprop *prop, MUdevice dev)
Description
- Returns properties for a selected device.
- Deprecated
- This function was deprecated as of MUSA 5.0 and replaced by muDeviceGetAttribute().
- Returns in *prop the properties of device dev. The MUdevprop structure is defined as:
typedef struct MUdevprop_st {
int maxThreadsPerBlock;
int maxThreadsDim[3];
int maxGridSize[3];
int sharedMemPerBlock;
int totalConstantMemory;
int SIMDWidth;
int memPitch;
int regsPerBlock;
int clockRate;
int textureAlign;
} MUdevprop;
- where:
- maxThreadsPerBlock is the maximum number of threads per block; maxThreadsDim[3] is the maximum sizes of each dimension of a block; maxGridSize[3] is the maximum sizes of each dimension of a grid; sharedMemPerBlock is the total amount of shared memory available per block in bytes; totalConstantMemory is the total amount of constant memory available on the device in bytes; SIMDWidth is the warp size; memPitch is the maximum pitch allowed by the memory copy functions that involve memory regions allocated through muMemAllocPitch(); regsPerBlock is the total number of registers available per block; clockRate is the clock frequency in kilohertz; textureAlign is the alignment requirement; texture base addresses that are aligned to textureAlign bytes do not need an offset applied to texture fetches.
Parameters
prop(MUdevprop *): Returned properties of devicedev(MUdevice): Device to get properties for
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muDeviceGetAttribute, muDeviceGetCount, muDeviceGetName, muDeviceGetUuid, muDeviceGet, muDeviceTotalMem
muDeviceComputeCapability
MUresult muDeviceComputeCapability(int *major, int *minor, MUdevice dev)
Description
- Returns the compute capability of the device.
- Deprecated
- This function was deprecated as of MUSA 5.0 and its functionality superseded by muDeviceGetAttribute().
- Returns in *major and *minor the major and minor revision numbers that define the compute capability of the device dev.
Parameters
major(int *): Major revision numberminor(int *): Minor revision numberdev(MUdevice): Device handle
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muDeviceGetAttribute, muDeviceGetCount, muDeviceGetName, muDeviceGetUuid, muDeviceGet, muDeviceTotalMem
3.6 Primary Context Management
muDevicePrimaryCtxRetain
MUresult muDevicePrimaryCtxRetain(MUcontext *pctx, MUdevice dev)
Description
- Retain the primary context on the GPU.
- Retains the primary context on the device. Once the user successfully retains the primary context, the primary context will be active and available to the user until the user releases it with muDevicePrimaryCtxRelease() or resets it with muDevicePrimaryCtxReset(). Unlike muCtxCreate() the newly retained context is not pushed onto the stack.
- Retaining the primary context for the first time will fail with MUSA_ERROR_UNKNOWN if the compute mode of the device is MU_COMPUTEMODE_PROHIBITED. The function muDeviceGetAttribute() can be used with MU_DEVICE_ATTRIBUTE_COMPUTE_MODE to determine the compute mode of the device. The mthreads-smi tool can be used to set the compute mode for devices. Documentation for mthreads-smi can be obtained by passing a -h option to it.
- Please note that the primary context always supports pinned allocations. Other flags can be specified by muDevicePrimaryCtxSetFlags().
Parameters
pctx(MUcontext *): Returned context handle of the new contextdev(MUdevice): Device for which primary context is requested
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_UNKNOWN
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muDevicePrimaryCtxRelease, muDevicePrimaryCtxSetFlags, muCtxCreate, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCtxSynchronize
muDevicePrimaryCtxRelease
MUresult muDevicePrimaryCtxRelease(MUdevice dev)
Description
- Release the primary context on the GPU.
- Releases the primary context interop on the device. A retained context should always be released once the user is done using it. The context is automatically reset once the last reference to it is released. This behavior is different when the primary context was retained by the MUSA runtime from MUSA 4.0 and earlier. In this case, the primary context remains always active.
- Releasing a primary context that has not been previously retained will fail with MUSA_ERROR_INVALID_CONTEXT.
- Please note that unlike muCtxDestroy() this method does not pop the context from stack in any circumstances.
Parameters
dev(MUdevice): Device which primary context is released
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_INVALID_CONTEXT
Note
- Additional exported symbol names in scope:
muDevicePrimaryCtxRelease_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muDevicePrimaryCtxRetain, muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCtxSynchronize
muDevicePrimaryCtxSetFlags
MUresult muDevicePrimaryCtxSetFlags(MUdevice dev, unsigned int flags)
Description
- Set flags for the primary context.
- Sets the flags for the primary context on the device overwriting perviously set ones.
- The three LSBs of the flags parameter can be used to control how the OS thread, which owns the MUSA context at the time of an API call, interacts with the OS scheduler when waiting for results from the GPU. Only one of the scheduling flags can be set when creating a context.
- MU_CTX_SCHED_SPIN: Instruct MUSA to actively spin when waiting for results from the GPU. This can decrease latency when waiting for the GPU, but may lower the performance of CPU threads if they are performing work in parallel with the MUSA thread. MU_CTX_SCHED_YIELD: Instruct MUSA to yield its thread when waiting for results from the GPU. This can increase latency when waiting for the GPU, but can increase the performance of CPU threads performing work in parallel with the GPU. MU_CTX_SCHED_BLOCKING_SYNC: Instruct MUSA to block the CPU thread on a synchronization primitive when waiting for the GPU to finish work. MU_CTX_BLOCKING_SYNC: Instruct MUSA to block the CPU thread on a synchronization primitive when waiting for the GPU to finish work. Deprecated: This flag was deprecated as of MUSA 4.0 and was replaced with MU_CTX_SCHED_BLOCKING_SYNC. MU_CTX_SCHED_AUTO: The default value if the flags parameter is zero, uses a heuristic based on the number of active MUSA contexts in the process C and the number of logical processors in the system P. If C > P, then MUSA will yield to other OS threads when waiting for the GPU (MU_CTX_SCHED_YIELD), otherwise MUSA will not yield while waiting for results and actively spin on the processor (MU_CTX_SCHED_SPIN). Additionally, on Tegra devices, MU_CTX_SCHED_AUTO uses a heuristic based on the power profile of the platform and may choose MU_CTX_SCHED_BLOCKING_SYNC for low-powered devices. MU_CTX_LMEM_RESIZE_TO_MAX: Instruct MUSA to not reduce local memory after resizing local memory for a kernel. This can prevent thrashing by local memory allocations when launching many kernels with high local memory usage at the cost of potentially increased memory usage. Deprecated: This flag is deprecated and the behavior enabled by this flag is now the default and cannot be disabled. MU_CTX_COREDUMP_ENABLE: If GPU coredumps have not been enabled globally with muCoredumpSetAttributeGlobal or environment variables, this flag can be set during context creation to instruct MUSA to create a coredump if this context raises an exception during execution. These environment variables are described in the MUSA-GDB user guide under the "GPU core dump support" section. The initial settings will be taken from the global settings at the time of context creation. The other settings that control coredump output can be modified by calling muCoredumpSetAttribute from the created context after it becomes current. MU_CTX_USER_COREDUMP_ENABLE: If user-triggered GPU coredumps have not been enabled globally with muCoredumpSetAttributeGlobal or environment variables, this flag can be set during context creation to instruct MUSA to create a coredump if data is written to a certain pipe that is present in the OS space. These environment variables are described in the MUSA-GDB user guide under the "GPU core dump support" section. It is important to note that the pipe name must be set with muCoredumpSetAttributeGlobal before creating the context if this flag is used. Setting this flag implies that MU_CTX_COREDUMP_ENABLE is set. The initial settings will be taken from the global settings at the time of context creation. The other settings that control coredump output can be modified by calling muCoredumpSetAttribute from the created context after it becomes current. MU_CTX_SYNC_MEMOPS: Ensures that synchronous memory operations initiated on this context will always synchronize. See further documentation in the section titled "API Synchronization behavior" to learn more about cases when synchronous memory operations can exhibit asynchronous behavior.
Parameters
dev(MUdevice): Device for which the primary context flags are setflags(unsigned int): New flags for the device
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muDevicePrimaryCtxSetFlags_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muDevicePrimaryCtxRetain, muDevicePrimaryCtxGetState, muCtxCreate, muCtxGetFlags, muCtxSetFlags, musaSetDeviceFlags
muDevicePrimaryCtxGetState
MUresult muDevicePrimaryCtxGetState(MUdevice dev, unsigned int *flags, int *active)
Description
- Get the state of the primary context.
- Returns in *flags the flags for the primary context of dev, and in *active whether it is active. See muDevicePrimaryCtxSetFlags for flag values.
Parameters
dev(MUdevice): Device to get primary context flags forflags(unsigned int *): Pointer to store flagsactive(int *): Pointer to store context state; 0 = inactive, 1 = active
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muDevicePrimaryCtxReset
MUresult muDevicePrimaryCtxReset(MUdevice dev)
Description
- Destroy all allocations and reset all state on the primary context.
- Explicitly destroys and cleans up all resources associated with the current device in the current process.
- Note that it is responsibility of the calling function to ensure that no other module in the process is using the device any more. For that reason it is recommended to use muDevicePrimaryCtxRelease() in most cases. However it is safe for other modules to call muDevicePrimaryCtxRelease() even after resetting the device. Resetting the primary context does not release it, an application that has retained the primary context should explicitly release its usage.
Parameters
dev(MUdevice): Device for which primary context is destroyed
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_PRIMARY_CONTEXT_ACTIVE
Note
- Additional exported symbol names in scope:
muDevicePrimaryCtxReset_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muDevicePrimaryCtxRetain, muDevicePrimaryCtxRelease, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCtxSynchronize, musaDeviceReset
3.7 Context Management
muCtxCreate
MUresult muCtxCreate(MUcontext *pctx, unsigned int flags, MUdevice dev)
Description
- Create a MUSA context.
- The three LSBs of the flags parameter can be used to control how the OS thread, which owns the MUSA context at the time of an API call, interacts with the OS scheduler when waiting for results from the GPU. Only one of the scheduling flags can be set when creating a context.
- MU_CTX_SCHED_SPIN: Instruct MUSA to actively spin when waiting for results from the GPU. This can decrease latency when waiting for the GPU, but may lower the performance of CPU threads if they are performing work in parallel with the MUSA thread. MU_CTX_SCHED_YIELD: Instruct MUSA to yield its thread when waiting for results from the GPU. This can increase latency when waiting for the GPU, but can increase the performance of CPU threads performing work in parallel with the GPU. MU_CTX_SCHED_BLOCKING_SYNC: Instruct MUSA to block the CPU thread on a synchronization primitive when waiting for the GPU to finish work. MU_CTX_BLOCKING_SYNC: Instruct MUSA to block the CPU thread on a synchronization primitive when waiting for the GPU to finish work. Deprecated: This flag was deprecated as of MUSA 4.0 and was replaced with MU_CTX_SCHED_BLOCKING_SYNC. MU_CTX_SCHED_AUTO: The default value if the flags parameter is zero, uses a heuristic based on the number of active MUSA contexts in the process C and the number of logical processors in the system P. If C > P, then MUSA will yield to other OS threads when waiting for the GPU (MU_CTX_SCHED_YIELD), otherwise MUSA will not yield while waiting for results and actively spin on the processor (MU_CTX_SCHED_SPIN). Additionally, on Tegra devices, MU_CTX_SCHED_AUTO uses a heuristic based on the power profile of the platform and may choose MU_CTX_SCHED_BLOCKING_SYNC for low-powered devices. MU_CTX_MAP_HOST: Instruct MUSA to support mapped pinned allocations. This flag must be set in order to allocate pinned host memory that is accessible to the GPU. MU_CTX_LMEM_RESIZE_TO_MAX: Instruct MUSA to not reduce local memory after resizing local memory for a kernel. This can prevent thrashing by local memory allocations when launching many kernels with high local memory usage at the cost of potentially increased memory usage. Deprecated: This flag is deprecated and the behavior enabled by this flag is now the default and cannot be disabled. Instead, the per-thread stack size can be controlled with muCtxSetLimit(). MU_CTX_COREDUMP_ENABLE: If GPU coredumps have not been enabled globally with muCoredumpSetAttributeGlobal or environment variables, this flag can be set during context creation to instruct MUSA to create a coredump if this context raises an exception during execution. These environment variables are described in the MUSA-GDB user guide under the "GPU core dump support" section. The initial attributes will be taken from the global attributes at the time of context creation. The other attributes that control coredump output can be modified by calling muCoredumpSetAttribute from the created context after it becomes current. MU_CTX_USER_COREDUMP_ENABLE: If user-triggered GPU coredumps have not been enabled globally with muCoredumpSetAttributeGlobal or environment variables, this flag can be set during context creation to instruct MUSA to create a coredump if data is written to a certain pipe that is present in the OS space. These environment variables are described in the MUSA-GDB user guide under the "GPU core dump support" section. It is important to note that the pipe name must be set with muCoredumpSetAttributeGlobal before creating the context if this flag is used. Setting this flag implies that MU_CTX_COREDUMP_ENABLE is set. The initial attributes will be taken from the global attributes at the time of context creation. The other attributes that control coredump output can be modified by calling muCoredumpSetAttribute from the created context after it becomes current. Setting this flag on any context creation is equivalent to setting the MU_COREDUMP_ENABLE_USER_TRIGGER attribute to true globally. MU_CTX_SYNC_MEMOPS: Ensures that synchronous memory operations initiated on this context will always synchronize. See further documentation in the section titled "API Synchronization behavior" to learn more about cases when synchronous memory operations can exhibit asynchronous behavior.
- Context creation will fail with MUSA_ERROR_UNKNOWN if the compute mode of the device is MU_COMPUTEMODE_PROHIBITED. The function muDeviceGetAttribute() can be used with MU_DEVICE_ATTRIBUTE_COMPUTE_MODE to determine the compute mode of the device. The mthreads-smi tool can be used to set the compute mode for * devices. Documentation for mthreads-smi can be obtained by passing a -h option to it.
Parameters
pctx(MUcontext *): Returned context handle of the new contextflags(unsigned int): Context creation flagsdev(MUdevice): Device to create context on
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_UNKNOWN
Note
- Additional exported symbol names in scope:
muCtxCreate_v2. - In most cases it is recommended to use muDevicePrimaryCtxRetain.
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCoredumpSetAttributeGlobal, muCoredumpSetAttribute, muCtxSynchronize
muCtxDestroy
MUresult muCtxDestroy(MUcontext ctx)
Description
- Create a MUSA context with execution affinity.
- Creates a new MUSA context with execution affinity and associates it with the calling thread. The paramsArray and flags parameter are described below. The context is created with a usage count of 1 and the caller of muCtxCreate() must call muCtxDestroy() when done using the context. If a context is already current to the thread, it is supplanted by the newly created context and may be restored by a subsequent call to muCtxPopCurrent().
- The type and the amount of execution resource the context can use is limited by paramsArray and numParams. The paramsArray is an array of MUexecAffinityParam and the numParams describes the size of the array. If two MUexecAffinityParam in the array have the same type, the latter execution affinity parameter overrides the former execution affinity parameter. The supported execution affinity types are: MU_EXEC_AFFINITY_TYPE_SM_COUNT limits the portion of SMs that the context can use. The portion of SMs is specified as the number of SMs via MUexecAffinitySmCount. This limit will be internally rounded up to the next hardware-supported amount. Hence, it is imperative to query the actual execution affinity of the context via muCtxGetExecAffinity after context creation. Currently, this attribute is only supported under Volta+ MPS.
- The three LSBs of the flags parameter can be used to control how the OS thread, which owns the MUSA context at the time of an API call, interacts with the OS scheduler when waiting for results from the GPU. Only one of the scheduling flags can be set when creating a context.
- MU_CTX_SCHED_SPIN: Instruct MUSA to actively spin when waiting for results from the GPU. This can decrease latency when waiting for the GPU, but may lower the performance of CPU threads if they are performing work in parallel with the MUSA thread. MU_CTX_SCHED_YIELD: Instruct MUSA to yield its thread when waiting for results from the GPU. This can increase latency when waiting for the GPU, but can increase the performance of CPU threads performing work in parallel with the GPU. MU_CTX_SCHED_BLOCKING_SYNC: Instruct MUSA to block the CPU thread on a synchronization primitive when waiting for the GPU to finish work. MU_CTX_BLOCKING_SYNC: Instruct MUSA to block the CPU thread on a synchronization primitive when waiting for the GPU to finish work. Deprecated: This flag was deprecated as of MUSA 4.0 and was replaced with MU_CTX_SCHED_BLOCKING_SYNC. MU_CTX_SCHED_AUTO: The default value if the flags parameter is zero, uses a heuristic based on the number of active MUSA contexts in the process C and the number of logical processors in the system P. If C > P, then MUSA will yield to other OS threads when waiting for the GPU (MU_CTX_SCHED_YIELD), otherwise MUSA will not yield while waiting for results and actively spin on the processor (MU_CTX_SCHED_SPIN). Additionally, on Tegra devices, MU_CTX_SCHED_AUTO uses a heuristic based on the power profile of the platform and may choose MU_CTX_SCHED_BLOCKING_SYNC for low-powered devices. MU_CTX_MAP_HOST: Instruct MUSA to support mapped pinned allocations. This flag must be set in order to allocate pinned host memory that is accessible to the GPU. MU_CTX_LMEM_RESIZE_TO_MAX: Instruct MUSA to not reduce local memory after resizing local memory for a kernel. This can prevent thrashing by local memory allocations when launching many kernels with high local memory usage at the cost of potentially increased memory usage. Deprecated: This flag is deprecated and the behavior enabled by this flag is now the default and cannot be disabled. Instead, the per-thread stack size can be controlled with muCtxSetLimit(). MU_CTX_COREDUMP_ENABLE: If GPU coredumps have not been enabled globally with muCoredumpSetAttributeGlobal or environment variables, this flag can be set during context creation to instruct MUSA to create a coredump if this context raises an exception during execution. These environment variables are described in the MUSA-GDB user guide under the "GPU core dump support" section. The initial attributes will be taken from the global attributes at the time of context creation. The other attributes that control coredump output can be modified by calling muCoredumpSetAttribute from the created context after it becomes current. MU_CTX_USER_COREDUMP_ENABLE: If user-triggered GPU coredumps have not been enabled globally with muCoredumpSetAttributeGlobal or environment variables, this flag can be set during context creation to instruct MUSA to create a coredump if data is written to a certain pipe that is present in the OS space. These environment variables are described in the MUSA-GDB user guide under the "GPU core dump support" section. It is important to note that the pipe name must be set with muCoredumpSetAttributeGlobal before creating the context if this flag is used. Setting this flag implies that MU_CTX_COREDUMP_ENABLE is set. The initial attributes will be taken from the global attributes at the time of context creation. The other attributes that control coredump output can be modified by calling muCoredumpSetAttribute from the created context after it becomes current. Setting this flag on any context creation is equivalent to setting the MU_COREDUMP_ENABLE_USER_TRIGGER attribute to true globally.
- Context creation will fail with MUSA_ERROR_UNKNOWN if the compute mode of the device is MU_COMPUTEMODE_PROHIBITED. The function muDeviceGetAttribute() can be used with MU_DEVICE_ATTRIBUTE_COMPUTE_MODE to determine the compute mode of the device. The mthreads-smi tool can be used to set the compute mode for * devices. Documentation for mthreads-smi can be obtained by passing a -h option to it.
- Creates a new MUSA context and associates it with the calling thread. The flags parameter is described below. The context is created with a usage count of 1 and the caller of muCtxCreate() must call muCtxDestroy() when done using the context. If a context is already current to the thread, it is supplanted by the newly created context and may be restored by a subsequent call to muCtxPopCurrent().
- MUSA context can be created with execution affinity. The type and the amount of execution resource the context can use is limited by paramsArray and numExecAffinityParams in execAffinity. The paramsArray is an array of MUexecAffinityParam and the numExecAffinityParams describes the size of the paramsArray. If two MUexecAffinityParam in the array have the same type, the latter execution affinity parameter overrides the former execution affinity parameter. The supported execution affinity types are: MU_EXEC_AFFINITY_TYPE_SM_COUNT limits the portion of SMs that the context can use. The portion of SMs is specified as the number of SMs via MUexecAffinitySmCount. This limit will be internally rounded up to the next hardware-supported amount. Hence, it is imperative to query the actual execution affinity of the context via muCtxGetExecAffinity after context creation. Currently, this attribute is only supported under Volta+ MPS.
- MUSA context can be created in CIG(MUSA in Graphics) mode by setting cigParams. Data from graphics client is shared with MUSA via the sharedData in cigParams. Support for D3D12 graphics client can be determined using muDeviceGetAttribute() with MU_DEVICE_ATTRIBUTE_D3D12_CIG_SUPPORTED. sharedData is a ID3D12CommandQueue handle. Either execAffinityParams or cigParams can be set to a non-null value. Setting both to a non-null value will result in an undefined behavior.
- MU_CTX_SCHED_SPIN: Instruct MUSA to actively spin when waiting for results from the GPU. This can decrease latency when waiting for the GPU, but may lower the performance of CPU threads if they are performing work in parallel with the MUSA thread. MU_CTX_SCHED_YIELD: Instruct MUSA to yield its thread when waiting for results from the GPU. This can increase latency when waiting for the GPU, but can increase the performance of CPU threads performing work in parallel with the GPU. MU_CTX_SCHED_BLOCKING_SYNC: Instruct MUSA to block the CPU thread on a synchronization primitive when waiting for the GPU to finish work. MU_CTX_BLOCKING_SYNC: Instruct MUSA to block the CPU thread on a synchronization primitive when waiting for the GPU to finish work. Deprecated: This flag was deprecated as of MUSA 4.0 and was replaced with MU_CTX_SCHED_BLOCKING_SYNC. MU_CTX_SCHED_AUTO: The default value if the flags parameter is zero, uses a heuristic based on the number of active MUSA contexts in the process C and the number of logical processors in the system P. If C > P, then MUSA will yield to other OS threads when waiting for the GPU (MU_CTX_SCHED_YIELD), otherwise MUSA will not yield while waiting for results and actively spin on the processor (MU_CTX_SCHED_SPIN). Additionally, on Tegra devices, MU_CTX_SCHED_AUTO uses a heuristic based on the power profile of the platform and may choose MU_CTX_SCHED_BLOCKING_SYNC for low-powered devices. MU_CTX_MAP_HOST: Instruct MUSA to support mapped pinned allocations. This flag must be set in order to allocate pinned host memory that is accessible to the GPU. MU_CTX_LMEM_RESIZE_TO_MAX: Instruct MUSA to not reduce local memory after resizing local memory for a kernel. This can prevent thrashing by local memory allocations when launching many kernels with high local memory usage at the cost of potentially increased memory usage. Deprecated: This flag is deprecated and the behavior enabled by this flag is now the default and cannot be disabled. Instead, the per-thread stack size can be controlled with muCtxSetLimit(). MU_CTX_COREDUMP_ENABLE: If GPU coredumps have not been enabled globally with muCoredumpSetAttributeGlobal or environment variables, this flag can be set during context creation to instruct MUSA to create a coredump if this context raises an exception during execution. These environment variables are described in the MUSA-GDB user guide under the "GPU core dump support" section. The initial attributes will be taken from the global attributes at the time of context creation. The other attributes that control coredump output can be modified by calling muCoredumpSetAttribute from the created context after it becomes current. This flag is not supported when MUSA context is created in CIG(MUSA in Graphics) mode. MU_CTX_USER_COREDUMP_ENABLE: If user-triggered GPU coredumps have not been enabled globally with muCoredumpSetAttributeGlobal or environment variables, this flag can be set during context creation to instruct MUSA to create a coredump if data is written to a certain pipe that is present in the OS space. These environment variables are described in the MUSA-GDB user guide under the "GPU core dump support" section. It is important to note that the pipe name must be set with muCoredumpSetAttributeGlobal before creating the context if this flag is used. Setting this flag implies that MU_CTX_COREDUMP_ENABLE is set. The initial attributes will be taken from the global attributes at the time of context creation. The other attributes that control coredump output can be modified by calling muCoredumpSetAttribute from the created context after it becomes current. Setting this flag on any context creation is equivalent to setting the MU_COREDUMP_ENABLE_USER_TRIGGER attribute to true globally. This flag is not supported when MUSA context is created in CIG(MUSA in Graphics) mode. MU_CTX_SYNC_MEMOPS: Ensures that synchronous memory operations initiated on this context will always synchronize. See further documentation in the section titled "API Synchronization behavior" to learn more about cases when synchronous memory operations can exhibit asynchronous behavior.
- Context creation will fail with MUSA_ERROR_INVALID_VALUE if invalid parameter was passed by client to create the MUSA context.
- Destroys the MUSA context specified by ctx. The context ctx will be destroyed regardless of how many threads it is current to. It is the responsibility of the calling function to ensure that no API call issues using ctx while muCtxDestroy() is executing.
- Destroys and cleans up all resources associated with the context. It is the caller's responsibility to ensure that the context or its resources are not accessed or passed in subsequent API calls and doing so will result in undefined behavior. These resources include MUSA types MUmodule, MUfunction, MUstream, MUevent, MUarray, MUmipmappedArray, MUtexObject, MUsurfObject, MUtexref, MUsurfref, MUgraphicsResource, MUlinkState, MUexternalMemory and MUexternalSemaphore. These resources also include memory allocations by muMemAlloc(), muMemAllocHost(), muMemAllocManaged() and muMemAllocPitch().
- If ctx is current to the calling thread then ctx will also be popped from the current thread's context stack (as though muCtxPopCurrent() were called). If ctx is current to other threads, then ctx will remain current to those threads, and attempting to access ctx from those threads will result in the error MUSA_ERROR_CONTEXT_IS_DESTROYED.
Parameters
ctx(MUcontext): Context to destroy
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_UNSUPPORTED_EXEC_AFFINITY, MUSA_ERROR_UNKNOWN
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_SUPPORTED, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_UNKNOWN
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muCtxDestroy_v2. - This function may also return error codes from previous, asynchronous launches.
- muCtxDestroy() will not destroy memory allocations by muMemCreate(), muMemAllocAsync() and muMemAllocFromPoolAsync(). These memory allocations are not associated with any MUSA context and need to be destroyed explicitly.
See also
- muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCtxSynchronize, muCoredumpSetAttributeGlobal, muCoredumpSetAttribute, MUexecAffinityParam
- muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCoredumpSetAttributeGlobal, muCoredumpSetAttribute, muCtxSynchronize
- muCtxCreate, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCtxSynchronize
muCtxPushCurrent
MUresult muCtxPushCurrent(MUcontext ctx)
Description
- Pushes a context on the current CPU thread.
- Pushes the given context ctx onto the CPU thread's stack of current contexts. The specified context becomes the CPU thread's current context, so all MUSA functions that operate on the current context are affected.
- The previous current context may be made current again by calling muCtxDestroy() or muCtxPopCurrent().
Parameters
ctx(MUcontext): Context to push
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muCtxPushCurrent_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCtxSynchronize
muCtxPopCurrent
MUresult muCtxPopCurrent(MUcontext *pctx)
Description
- Pops the current MUSA context from the current CPU thread.
- Pops the current MUSA context from the CPU thread and passes back the old context handle in *pctx. That context may then be made current to a different CPU thread by calling muCtxPushCurrent().
- If a context was current to the CPU thread before muCtxCreate() or muCtxPushCurrent() was called, this function makes that context current to the CPU thread again.
Parameters
pctx(MUcontext *): Returned popped context handle
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT
Note
- Additional exported symbol names in scope:
muCtxPopCurrent_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCtxSynchronize
muCtxSetCurrent
MUresult muCtxSetCurrent(MUcontext ctx)
Description
- Binds the specified MUSA context to the calling CPU thread.
- Binds the specified MUSA context to the calling CPU thread. If ctx is NULL then the MUSA context previously bound to the calling CPU thread is unbound and MUSA_SUCCESS is returned.
- If there exists a MUSA context stack on the calling CPU thread, this will replace the top of that stack with ctx. If ctx is NULL then this will be equivalent to popping the top of the calling CPU thread's MUSA context stack (or a no-op if the calling CPU thread's MUSA context stack is empty).
Parameters
ctx(MUcontext): Context to bind to the calling CPU thread
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muCtxGetCurrent
MUresult muCtxGetCurrent(MUcontext *pctx)
Description
- Returns the MUSA context bound to the calling CPU thread.
- Returns in *pctx the MUSA context bound to the calling CPU thread. If no context is bound to the calling CPU thread then *pctx is set to NULL and MUSA_SUCCESS is returned.
Parameters
pctx(MUcontext *): Returned context handle
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muCtxGetDevice
MUresult muCtxGetDevice(MUdevice *device)
Description
- Returns the device handle for the current context.
- Returns in *device the handle of the current context's device.
Parameters
device(MUdevice *): Returned device handle for the current context
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCtxSynchronize, musaGetDevice
muCtxGetFlags
MUresult muCtxGetFlags(unsigned int *flags)
Description
- Returns the device handle for the specified context.
- Returns in *device the handle of the specified context's device. If the specified context is NULL, the API will return the current context's device.
- Returns in *flags the flags of the current context. See muCtxCreate for flag values.
Parameters
flags(unsigned int *): Pointer to store flags of current context
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxGetCurrent, muCtxPopCurrent, muCtxPushCurrent
- muCtxCreate, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetCurrent, muCtxGetDevice, muCtxGetLimit, muCtxGetSharedMemConfig, muCtxGetStreamPriorityRange, muCtxSetFlags, musaGetDeviceFlags
muCtxSetFlags
MUresult muCtxSetFlags(unsigned int flags)
Description
- Sets the flags for the current context.
- Sets the flags for the current context overwriting previously set ones. See muDevicePrimaryCtxSetFlags for flag values.
Parameters
flags(unsigned int): Flags to set on the current context
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetCurrent, muCtxGetDevice, muCtxGetLimit, muCtxGetSharedMemConfig, muCtxGetStreamPriorityRange, muCtxGetFlags, musaGetDeviceFlags, muDevicePrimaryCtxSetFlags,
muCtxGetId
MUresult muCtxGetId(MUcontext ctx, unsigned long long *ctxId)
Description
- Returns the unique Id associated with the context supplied.
- Returns in ctxId the unique Id which is associated with a given context. The Id is unique for the life of the program for this instance of MUSA. If context is supplied as NULL and there is one current, the Id of the current context is returned.
Parameters
ctx(MUcontext): Context for which to obtain the IdctxId(unsigned long long *): Pointer to store the Id of the context
Returns
- MUSA_SUCCESS, MUSA_ERROR_CONTEXT_IS_DESTROYED, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPushCurrent
muCtxSynchronize
MUresult muCtxSynchronize(void)
Description
- Block for the current context's tasks to complete.
- Blocks until the current context has completed all preceding requested tasks. If the current context is the primary context, green contexts that have been created will also be synchronized. muCtxSynchronize() returns an error if one of the preceding tasks failed. If the context was created with the MU_CTX_SCHED_BLOCKING_SYNC flag, the CPU thread will block until the GPU context has finished its work.
Parameters
(unnamed)(void)
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, musaDeviceSynchronize
muCtxSetLimit
MUresult muCtxSetLimit(MUlimit limit, size_t value)
Description
- Block for the specified context's tasks to complete.
- Blocks until the specified context has completed all preceding requested tasks. If the specified context is the primary context, green contexts that have been created will also be synchronized. The API returns an error if one of the preceding tasks failed.
- If the context was created with the MU_CTX_SCHED_BLOCKING_SYNC flag, the CPU thread will block until the GPU context has finished its work.
- If the specified context is NULL, the API will operate on the current context.
- Setting limit to value is a request by the application to update the current limit maintained by the context. The driver is free to modify the requested value to meet h/w requirements (this could be clamping to minimum or maximum values, rounding up to nearest element size, etc). The application can use muCtxGetLimit() to find out exactly what the limit has been set to.
- Setting each MUlimit has its own specific restrictions, so each is discussed here.
- MU_LIMIT_STACK_SIZE controls the stack size in bytes of each GPU thread. The driver automatically increases the per-thread stack size for each kernel launch as needed. This size isn't reset back to the original value after each launch. Setting this value will take effect immediately, and if necessary, the device will block until all preceding requested tasks are complete. MU_LIMIT_PRINTF_FIFO_SIZE controls the size in bytes of the FIFO used by the printf() device system call. Setting MU_LIMIT_PRINTF_FIFO_SIZE must be performed before launching any kernel that uses the printf() device system call, otherwise MUSA_ERROR_INVALID_VALUE will be returned. MU_LIMIT_MALLOC_HEAP_SIZE controls the size in bytes of the heap used by the malloc() and free() device system calls. Setting MU_LIMIT_MALLOC_HEAP_SIZE must be performed before launching any kernel that uses the malloc() or free() device system calls, otherwise MUSA_ERROR_INVALID_VALUE will be returned. MU_LIMIT_DEV_RUNTIME_SYNC_DEPTH controls the maximum nesting depth of a grid at which a thread can safely call musaDeviceSynchronize(). Setting this limit must be performed before any launch of a kernel that uses the device runtime and calls musaDeviceSynchronize() above the default sync depth, two levels of grids. Calls to musaDeviceSynchronize() will fail with error code musaErrorSyncDepthExceeded if the limitation is violated. This limit can be set smaller than the default or up the maximum launch depth of 24. When setting this limit, keep in mind that additional levels of sync depth require the driver to reserve large amounts of device memory which can no longer be used for user allocations. If these reservations of device memory fail, muCtxSetLimit() will return MUSA_ERROR_OUT_OF_MEMORY, and the limit can be reset to a lower value. This limit is only applicable to devices of compute capability < 9.0. Attempting to set this limit on devices of other compute capability versions will result in the error MUSA_ERROR_UNSUPPORTED_LIMIT being returned. MU_LIMIT_DEV_RUNTIME_PENDING_LAUNCH_COUNT controls the maximum number of outstanding device runtime launches that can be made from the current context. A grid is outstanding from the point of launch up until the grid is known to have been completed. Device runtime launches which violate this limitation fail and return musaErrorLaunchPendingCountExceeded when musaGetLastError() is called after launch. If more pending launches than the default (2048 launches) are needed for a module using the device runtime, this limit can be increased. Keep in mind that being able to sustain additional pending launches will require the driver to reserve larger amounts of device memory upfront which can no longer be used for allocations. If these reservations fail, muCtxSetLimit() will return MUSA_ERROR_OUT_OF_MEMORY, and the limit can be reset to a lower value. This limit is only applicable to devices of compute capability 3.5 and higher. Attempting to set this limit on devices of compute capability less than 3.5 will result in the error MUSA_ERROR_UNSUPPORTED_LIMIT being returned. MU_LIMIT_MAX_L2_FETCH_GRANULARITY controls the L2 cache fetch granularity. Values can range from 0B to 128B. This is purely a performance hint and it can be ignored or clamped depending on the platform. MU_LIMIT_PERSISTING_L2_CACHE_SIZE controls size in bytes available for persisting L2 cache. This is purely a performance hint and it can be ignored or clamped depending on the platform.
Parameters
limit(MUlimit): Limit to setvalue(size_t): Size of limit
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_STREAM_CAPTURE_UNSUPPORTED
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_UNSUPPORTED_LIMIT, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_INVALID_CONTEXT
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxGetCurrent, muCtxPopCurrent, muCtxPushCurrent, muGreenCtxCreate, muCtxFromGreenCtx, musaDeviceSynchronize
- muCtxCreate, muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSynchronize, musaDeviceSetLimit
muCtxGetLimit
MUresult muCtxGetLimit(size_t *pvalue, MUlimit limit)
Description
- Returns resource limits.
- Returns in *pvalue the current size of limit. The supported MUlimit values are: MU_LIMIT_STACK_SIZE: stack size in bytes of each GPU thread. MU_LIMIT_PRINTF_FIFO_SIZE: size in bytes of the FIFO used by the printf() device system call. MU_LIMIT_MALLOC_HEAP_SIZE: size in bytes of the heap used by the malloc() and free() device system calls. MU_LIMIT_DEV_RUNTIME_SYNC_DEPTH: maximum grid depth at which a thread can issue the device runtime call musaDeviceSynchronize() to wait on child grid launches to complete. MU_LIMIT_DEV_RUNTIME_PENDING_LAUNCH_COUNT: maximum number of outstanding device runtime launches that can be made from this context. MU_LIMIT_MAX_L2_FETCH_GRANULARITY: L2 cache fetch granularity. MU_LIMIT_PERSISTING_L2_CACHE_SIZE: Persisting L2 cache size in bytes
Parameters
pvalue(size_t *): Returned size of limitlimit(MUlimit): Limit to query
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_UNSUPPORTED_LIMIT
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCtxSynchronize, musaDeviceGetLimit
muCtxGetCacheConfig
MUresult muCtxGetCacheConfig(MUfunc_cache *pconfig)
Description
- Returns the preferred cache configuration for the current context.
- On devices where the L1 cache and shared memory use the same hardware resources, this function returns through pconfig the preferred cache configuration for the current context. This is only a preference. The driver will use the requested configuration if possible, but it is free to choose a different configuration if required to execute functions.
- This will return a pconfig of MU_FUNC_CACHE_PREFER_NONE on devices where the size of the L1 cache and shared memory are fixed.
- The supported cache configurations are: MU_FUNC_CACHE_PREFER_NONE: no preference for shared memory or L1 (default) MU_FUNC_CACHE_PREFER_SHARED: prefer larger shared memory and smaller L1 cache MU_FUNC_CACHE_PREFER_L1: prefer larger L1 cache and smaller shared memory MU_FUNC_CACHE_PREFER_EQUAL: prefer equal sized L1 cache and shared memory
Parameters
pconfig(MUfunc_cache *): Returned cache configuration
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxDestroy, muCtxGetApiVersion, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCtxSynchronize, muFuncSetCacheConfig, musaDeviceGetCacheConfig
muCtxSetCacheConfig
MUresult muCtxSetCacheConfig(MUfunc_cache config)
Description
- Sets the preferred cache configuration for the current context.
- On devices where the L1 cache and shared memory use the same hardware resources, this sets through config the preferred cache configuration for the current context. This is only a preference. The driver will use the requested configuration if possible, but it is free to choose a different configuration if required to execute the function. Any function preference set via muFuncSetCacheConfig() or muKernelSetCacheConfig() will be preferred over this context-wide setting. Setting the context-wide cache configuration to MU_FUNC_CACHE_PREFER_NONE will cause subsequent kernel launches to prefer to not change the cache configuration unless required to launch the kernel.
- This setting does nothing on devices where the size of the L1 cache and shared memory are fixed.
- Launching a kernel with a different preference than the most recent preference setting may insert a device-side synchronization point.
- The supported cache configurations are: MU_FUNC_CACHE_PREFER_NONE: no preference for shared memory or L1 (default) MU_FUNC_CACHE_PREFER_SHARED: prefer larger shared memory and smaller L1 cache MU_FUNC_CACHE_PREFER_L1: prefer larger L1 cache and smaller shared memory MU_FUNC_CACHE_PREFER_EQUAL: prefer equal sized L1 cache and shared memory
Parameters
config(MUfunc_cache): Requested cache configuration
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetLimit, muCtxSynchronize, muFuncSetCacheConfig, musaDeviceSetCacheConfig, muKernelSetCacheConfig
muCtxGetApiVersion
MUresult muCtxGetApiVersion(MUcontext ctx, unsigned int *version)
Description
- Gets the context's API version.
- Returns a version number in version corresponding to the capabilities of the context (e.g. 3010 or 3020), which library developers can use to direct callers to a specific API version. If ctx is NULL, returns the API version used to create the currently bound context.
- Note that new API versions are only introduced when context capabilities are changed that break binary compatibility, so the API version and driver version may be different. For example, it is valid for the API version to be 3020 while the driver version is 4020.
Parameters
ctx(MUcontext): Context to checkversion(unsigned int *): Pointer to version
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_UNKNOWN
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxDestroy, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCtxSynchronize
muCtxGetStreamPriorityRange
MUresult muCtxGetStreamPriorityRange(int *leastPriority, int *greatestPriority)
Description
- Returns numerical values that correspond to the least and greatest stream priorities.
- Returns in *leastPriority and *greatestPriority the numerical values that correspond to the least and greatest stream priorities respectively. Stream priorities follow a convention where lower numbers imply greater priorities. The range of meaningful stream priorities is given by [*greatestPriority, *leastPriority]. If the user attempts to create a stream with a priority value that is outside the meaningful range as specified by this API, the priority is automatically clamped down or up to either *leastPriority or *greatestPriority respectively. See muStreamCreateWithPriority for details on creating a priority stream. A NULL may be passed in for *leastPriority or *greatestPriority if the value is not desired.
- This function will return '0' in both *leastPriority and *greatestPriority if the current context's device does not support stream priorities (see muDeviceGetAttribute).
Parameters
leastPriority(int *): Pointer to an int in which the numerical value for least stream priority is returnedgreatestPriority(int *): Pointer to an int in which the numerical value for greatest stream priority is returned
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muStreamCreateWithPriority, muStreamGetPriority, muCtxGetDevice, muCtxGetFlags, muCtxSetLimit, muCtxSynchronize, musaDeviceGetStreamPriorityRange
muCtxResetPersistingL2Cache
MUresult muCtxResetPersistingL2Cache(void)
Description
- Resets all persisting lines in cache to normal status.
- muCtxResetPersistingL2Cache Resets all persisting lines in cache to normal status. Takes effect on function return.
Parameters
(unnamed)(void)
Returns
- MUSA_SUCCESS, MUSA_ERROR_NOT_SUPPORTED
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- MUaccessPolicyWindow
muCtxRecordEvent
MUresult muCtxRecordEvent(MUcontext hCtx, MUevent hEvent)
Description
- Returns the execution affinity setting for the current context.
- Returns in *pExecAffinity the current value of type. The supported MUexecAffinityType values are: MU_EXEC_AFFINITY_TYPE_SM_COUNT: number of SMs the context is limited to use.
- Captures in hEvent all the activities of the context hCtx at the time of this call. hEvent and hCtx must be from the same MUSA context, otherwise MUSA_ERROR_INVALID_HANDLE will be returned. Calls such as muEventQuery() or muCtxWaitEvent() will then examine or wait for completion of the work that was captured. Uses of hCtx after this call do not modify hEvent. If the context passed to hCtx is the primary context, hEvent will capture all the activities of the primary context and its green contexts. If the context passed to hCtx is a context converted from green context via muCtxFromGreenCtx(), hEvent will capture only the activities of the green context.
Parameters
hCtx(MUcontext): Context to record event forhEvent(MUevent): Event to record
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_UNSUPPORTED_EXEC_AFFINITY
- MUSA_SUCCESS MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_STREAM_CAPTURE_UNSUPPORTED
Note
- This function may also return error codes from previous, asynchronous launches.
- The API will return MUSA_ERROR_STREAM_CAPTURE_UNSUPPORTED if the specified context hCtx has a stream in the capture mode. In such a case, the call will invalidate all the conflicting captures.
See also
- MUexecAffinityParam
- muCtxWaitEvent, muGreenCtxRecordEvent, muGreenCtxWaitEvent, muEventRecord
muCtxWaitEvent
MUresult muCtxWaitEvent(MUcontext hCtx, MUevent hEvent)
Description
- Make a context wait on an event.
- Makes all future work submitted to context hCtx wait for all work captured in hEvent. The synchronization will be performed on the device and will not block the calling CPU thread. See muCtxRecordEvent() for details on what is captured by an event. If the context passed to hCtx is the primary context, the primary context and its green contexts will wait for hEvent. If the context passed to hCtx is a context converted from green context via muCtxFromGreenCtx(), the green context will wait for hEvent.
Parameters
hCtx(MUcontext): Context to waithEvent(MUevent): Event to wait on
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_STREAM_CAPTURE_UNSUPPORTED
Note
- hEvent may be from a different context or device than hCtx.
- The API will return MUSA_ERROR_STREAM_CAPTURE_UNSUPPORTED and invalidate the capture if the specified event hEvent is part of an ongoing capture sequence or if the specified context hCtx has a stream in the capture mode.
See also
3.8 Context Management [DEPRECATED]
muCtxAttach
MUresult muCtxAttach(MUcontext *pctx, unsigned int flags)
Description
- Increment a context's usage-count.
- Deprecated
- Note that this function is deprecated and should not be used.
- Increments the usage count of the context and passes back a context handle in *pctx that must be passed to muCtxDetach() when the application is done with the context. muCtxAttach() fails if there is no context current to the thread.
- Currently, the flags parameter must be 0.
Parameters
pctx(MUcontext *): Returned context handle of the current contextflags(unsigned int): Context attach flags (must be 0)
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxDestroy, muCtxDetach, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCtxSynchronize
muCtxDetach
MUresult muCtxDetach(MUcontext ctx)
Description
- Decrement a context's usage-count.
- Deprecated
- Note that this function is deprecated and should not be used.
- Decrements the usage count of the context ctx, and destroys the context if the usage count goes to 0. The context must be a handle that was passed back by muCtxCreate() or muCtxAttach(), and must be current to the calling thread.
Parameters
ctx(MUcontext): Context to destroy
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetCacheConfig, muCtxSetLimit, muCtxSynchronize
muCtxGetSharedMemConfig
MUresult muCtxGetSharedMemConfig(MUsharedconfig *pConfig)
Description
- Returns the current shared memory configuration for the current context.
- Deprecated
- This function will return in pConfig the current size of shared memory banks in the current context. On devices with configurable shared memory banks, muCtxSetSharedMemConfig can be used to change this setting, so that all subsequent kernel launches will by default use the new bank size. When muCtxGetSharedMemConfig is called on devices without configurable shared memory, it will return the fixed bank size of the hardware.
- The returned bank configurations can be either: MU_SHARED_MEM_CONFIG_FOUR_BYTE_BANK_SIZE: shared memory bank width is four bytes. MU_SHARED_MEM_CONFIG_EIGHT_BYTE_BANK_SIZE: shared memory bank width will eight bytes.
Parameters
pConfig(MUsharedconfig *): returned shared memory configuration
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetLimit, muCtxSynchronize, muCtxGetSharedMemConfig, muFuncSetCacheConfig, musaDeviceGetSharedMemConfig
muCtxSetSharedMemConfig
MUresult muCtxSetSharedMemConfig(MUsharedconfig config)
Description
- Sets the shared memory configuration for the current context.
- Deprecated
- On devices with configurable shared memory banks, this function will set the context's shared memory bank size which is used for subsequent kernel launches.
- Changed the shared memory configuration between launches may insert a device side synchronization point between those launches.
- Changing the shared memory bank size will not increase shared memory usage or affect occupancy of kernels, but may have major effects on performance. Larger bank sizes will allow for greater potential bandwidth to shared memory, but will change what kinds of accesses to shared memory will result in bank conflicts.
- This function will do nothing on devices with fixed shared memory bank size.
- The supported bank configurations are: MU_SHARED_MEM_CONFIG_DEFAULT_BANK_SIZE: set bank width to the default initial setting (currently, four bytes). MU_SHARED_MEM_CONFIG_FOUR_BYTE_BANK_SIZE: set shared memory bank width to be natively four bytes. MU_SHARED_MEM_CONFIG_EIGHT_BYTE_BANK_SIZE: set shared memory bank width to be natively eight bytes.
Parameters
config(MUsharedconfig): requested shared memory configuration
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muCtxCreate, muCtxDestroy, muCtxGetApiVersion, muCtxGetCacheConfig, muCtxGetDevice, muCtxGetFlags, muCtxGetLimit, muCtxPopCurrent, muCtxPushCurrent, muCtxSetLimit, muCtxSynchronize, muCtxGetSharedMemConfig, muFuncSetCacheConfig, musaDeviceSetSharedMemConfig
3.9 Module Management
muModuleLoad
MUresult muModuleLoad(MUmodule *module, const char *fname)
Description
- Loads a compute module.
- Takes a filename fname and loads the corresponding module module into the current context. The MUSA driver API does not attempt to lazily allocate the resources needed by a module; if the memory for functions and data (constant and global) needed by the module cannot be allocated, muModuleLoad() fails. The file should be a mubin file as output by nvcc, or a PTX file either as output by nvcc or handwritten, or a fatbin file as output by nvcc from toolchain 4.0 or later.
Parameters
module(MUmodule *): Returned modulefname(const char *): Filename of module to load
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_PTX, MUSA_ERROR_UNSUPPORTED_PTX_VERSION, MUSA_ERROR_NOT_FOUND, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_FILE_NOT_FOUND, MUSA_ERROR_NO_BINARY_FOR_GPU, MUSA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND, MUSA_ERROR_SHARED_OBJECT_INIT_FAILED, MUSA_ERROR_JIT_COMPILER_NOT_FOUND
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muModuleGetFunction, muModuleGetGlobal, muModuleGetTexRef, muModuleLoadData, muModuleLoadDataEx, muModuleLoadFatBinary, muModuleUnload
muModuleLoadData
MUresult muModuleLoadData(MUmodule *module, const void *image)
Description
- Load a module's data.
- Takes a pointer image and loads the corresponding module module into the current context. The image may be a mubin or fatbin as output by nvcc, or a NULL-terminated PTX, either as output by nvcc or hand-written.
Parameters
module(MUmodule *): Returned moduleimage(const void *): Module data to load
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_PTX, MUSA_ERROR_UNSUPPORTED_PTX_VERSION, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_NO_BINARY_FOR_GPU, MUSA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND, MUSA_ERROR_SHARED_OBJECT_INIT_FAILED, MUSA_ERROR_JIT_COMPILER_NOT_FOUND
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muModuleGetFunction, muModuleGetGlobal, muModuleGetTexRef, muModuleLoad, muModuleLoadDataEx, muModuleLoadFatBinary, muModuleUnload
muModuleLoadDataEx
MUresult muModuleLoadDataEx(MUmodule *module, const void *image, unsigned int numOptions, MUjit_option *options, void **optionValues)
Description
- Load a module's data with options.
- Takes a pointer image and loads the corresponding module module into the current context. The image may be a mubin or fatbin as output by nvcc, or a NULL-terminated PTX, either as output by nvcc or hand-written.
Parameters
module(MUmodule *): Returned moduleimage(const void *): Module data to loadnumOptions(unsigned int): Number of optionsoptions(MUjit_option *): Options for JIToptionValues(void **): Option values for JIT
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_PTX, MUSA_ERROR_UNSUPPORTED_PTX_VERSION, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_NO_BINARY_FOR_GPU, MUSA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND, MUSA_ERROR_SHARED_OBJECT_INIT_FAILED, MUSA_ERROR_JIT_COMPILER_NOT_FOUND
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muModuleGetFunction, muModuleGetGlobal, muModuleGetTexRef, muModuleLoad, muModuleLoadData, muModuleLoadFatBinary, muModuleUnload
muModuleLoadFatBinary
MUresult muModuleLoadFatBinary(MUmodule *module, const void *fatMubin)
Description
- Load a module's data.
- Takes a pointer fatCubin and loads the corresponding module module into the current context. The pointer represents a fat binary object, which is a collection of different mubin and/or PTX files, all representing the same device code, but compiled and optimized for different architectures.
- Prior to MUSA 4.0, there was no documented API for constructing and using fat binary objects by programmers. Starting with MUSA 4.0, fat binary objects can be constructed by providing the -fatbin option to nvcc. More information can be found in the nvcc document.
Parameters
module(MUmodule *): Returned modulefatMubin(const void *)
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_PTX, MUSA_ERROR_UNSUPPORTED_PTX_VERSION, MUSA_ERROR_NOT_FOUND, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_NO_BINARY_FOR_GPU, MUSA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND, MUSA_ERROR_SHARED_OBJECT_INIT_FAILED, MUSA_ERROR_JIT_COMPILER_NOT_FOUND
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muModuleGetFunction, muModuleGetGlobal, muModuleGetTexRef, muModuleLoad, muModuleLoadData, muModuleLoadDataEx, muModuleUnload
muModuleUnload
MUresult muModuleUnload(MUmodule hmod)
Description
- Unloads a module.
- Unloads a module hmod from the current context. Attempting to unload a module which was obtained from the Library Management API such as muLibraryGetModule will return MUSA_ERROR_NOT_PERMITTED.
Parameters
hmod(MUmodule): Module to unload
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_PERMITTED
Note
- This function may also return error codes from previous, asynchronous launches.
- Destroying the target object while work is still pending results in undefined behavior.
See also
- muModuleGetFunction, muModuleGetGlobal, muModuleGetTexRef, muModuleLoad, muModuleLoadData, muModuleLoadDataEx, muModuleLoadFatBinary
muModuleGetLoadingMode
MUresult muModuleGetLoadingMode(MUmoduleLoadingMode *mode)
Description
- Query lazy loading mode.
- Returns lazy loading mode Module loading mode is controlled by MUSA_MODULE_LOADING env variable
Parameters
mode(MUmoduleLoadingMode *): Returns the lazy loading mode
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muModuleGetFunction
MUresult muModuleGetFunction(MUfunction *hfunc, MUmodule hmod, const char *name)
Description
- Returns a function handle.
- Returns in *hfunc the handle of the function of name name located in module hmod. If no function of that name exists, muModuleGetFunction() returns MUSA_ERROR_NOT_FOUND.
Parameters
hfunc(MUfunction *): Returned function handlehmod(MUmodule): Module to retrieve function fromname(const char *): Name of function to retrieve
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_FOUND
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muModuleGetGlobal, muModuleGetTexRef, muModuleLoad, muModuleLoadData, muModuleLoadDataEx, muModuleLoadFatBinary, muModuleUnload
muModuleGetFunctionCount
MUresult muModuleGetFunctionCount(unsigned int *count, MUmodule mod)
Description
- Returns the number of functions within a module.
- Returns in count the number of functions in mod.
Parameters
count(unsigned int *): Number of functions found within the modulemod(MUmodule): Module to query
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_INVALID_VALUE
muModuleEnumerateFunctions
MUresult muModuleEnumerateFunctions(MUfunction *functions, unsigned int numFunctions, MUmodule mod)
Description
- Returns the function handles within a module.
- Returns in functions a maximum number of numFunctions function handles within mod. When function loading mode is set to LAZY the function retrieved may be partially loaded. The loading state of a function can be queried using muFunctionIsLoaded. MUSA APIs may load the function automatically when called with partially loaded function handle which may incur additional latency. Alternatively, muFunctionLoad can be used to explicitly load a function. The returned function handles become invalid when the module is unloaded.
Parameters
functions(MUfunction *): Buffer where the function handles are returned tonumFunctions(unsigned int): Maximum number of function handles may be returned to the buffermod(MUmodule): Module to query from
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_INVALID_VALUE
See also
muModuleGetGlobal
MUresult muModuleGetGlobal(MUdeviceptr *dptr, size_t *bytes, MUmodule hmod, const char *name)
Description
- Returns a global pointer from a module.
- Returns in *dptr and *bytes the base pointer and size of the global of name name located in module hmod. If no variable of that name exists, muModuleGetGlobal() returns MUSA_ERROR_NOT_FOUND. One of the parameters dptr or bytes (not both) can be NULL in which case it is ignored.
Parameters
dptr(MUdeviceptr *): Returned global device pointerbytes(size_t *): Returned global size in byteshmod(MUmodule): Module to retrieve global fromname(const char *): Name of global to retrieve
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_FOUND
Note
- Additional exported symbol names in scope:
muModuleGetGlobal_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muModuleGetFunction, muModuleGetTexRef, muModuleLoad, muModuleLoadData, muModuleLoadDataEx, muModuleLoadFatBinary, muModuleUnload, musaGetSymbolAddress, musaGetSymbolSize
3.10 Module Management [DEPRECATED]
muModuleGetTexRef
MUresult muModuleGetTexRef(MUtexref *pTexRef, MUmodule hmod, const char *name)
Description
- Returns a handle to a texture reference.
- Deprecated
- Returns in *pTexRef the handle of the texture reference of name name in the module hmod. If no texture reference of that name exists, muModuleGetTexRef() returns MUSA_ERROR_NOT_FOUND. This texture reference handle should not be destroyed, since it will be destroyed when the module is unloaded.
Parameters
pTexRef(MUtexref *): Returned texture referencehmod(MUmodule): Module to retrieve texture reference fromname(const char *): Name of texture reference to retrieve
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_FOUND
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muModuleGetFunction, muModuleGetGlobal, muModuleGetSurfRef, muModuleLoad, muModuleLoadData, muModuleLoadDataEx, muModuleLoadFatBinary, muModuleUnload
muModuleGetSurfRef
MUresult muModuleGetSurfRef(MUsurfref *pSurfRef, MUmodule hmod, const char *name)
Description
- Returns a handle to a surface reference.
- Deprecated
- Returns in *pSurfRef the handle of the surface reference of name name in the module hmod. If no surface reference of that name exists, muModuleGetSurfRef() returns MUSA_ERROR_NOT_FOUND.
Parameters
pSurfRef(MUsurfref *): Returned surface referencehmod(MUmodule): Module to retrieve surface reference fromname(const char *): Name of surface reference to retrieve
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_FOUND
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muModuleGetFunction, muModuleGetGlobal, muModuleGetTexRef, muModuleLoad, muModuleLoadData, muModuleLoadDataEx, muModuleLoadFatBinary, muModuleUnload
3.11 Library Management
muLibraryLoadData
MUresult muLibraryLoadData(MUlibrary *library, const void *code, MUjit_option *jitOptions, void **jitOptionsValues, unsigned int numJitOptions, MUlibraryOption *libraryOptions, void **libraryOptionValues, unsigned int numLibraryOptions)
Description
- Load a library with specified code and options.
- Takes a pointer code and loads the corresponding library library based on the application defined library loading mode: If module loading is set to EAGER, via the environment variables described in "Module loading", library is loaded eagerly into all contexts at the time of the call and future contexts at the time of creation until the library is unloaded with muLibraryUnload(). If the environment variables are set to LAZY, library is not immediately loaded onto all existent contexts and will only be loaded when a function is needed for that context, such as a kernel launch.
- These environment variables are described in the MUSA programming guide under the "MUSA environment variables" section.
- The code may be a mubin or fatbin as output by nvcc, or a NULL-terminated PTX, either as output by nvcc or hand-written. A fatbin should also contain relocatable code when doing separate compilation.
- Options are passed as an array via jitOptions and any corresponding parameters are passed in jitOptionsValues. The number of total JIT options is supplied via numJitOptions. Any outputs will be returned via jitOptionsValues.
- Library load options are passed as an array via libraryOptions and any corresponding parameters are passed in libraryOptionValues. The number of total library load options is supplied via numLibraryOptions.
Parameters
library(MUlibrary *): Returned librarycode(const void *): Code to loadjitOptions(MUjit_option *): Options for JITjitOptionsValues(void **): Option values for JITnumJitOptions(unsigned int): Number of optionslibraryOptions(MUlibraryOption *): Options for loadinglibraryOptionValues(void **): Option values for loadingnumLibraryOptions(unsigned int): Number of options for loading
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_PTX, MUSA_ERROR_UNSUPPORTED_PTX_VERSION, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_NO_BINARY_FOR_GPU, MUSA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND, MUSA_ERROR_SHARED_OBJECT_INIT_FAILED, MUSA_ERROR_JIT_COMPILER_NOT_FOUND, MUSA_ERROR_NOT_SUPPORTED
Note
- If the library contains managed variables and no device in the system supports managed variables this call is expected to return MUSA_ERROR_NOT_SUPPORTED
See also
muLibraryLoadFromFile
MUresult muLibraryLoadFromFile(MUlibrary *library, const char *fileName, MUjit_option *jitOptions, void **jitOptionsValues, unsigned int numJitOptions, MUlibraryOption *libraryOptions, void **libraryOptionValues, unsigned int numLibraryOptions)
Description
- Load a library with specified file and options.
- Takes a pointer code and loads the corresponding library library based on the application defined library loading mode: If module loading is set to EAGER, via the environment variables described in "Module loading", library is loaded eagerly into all contexts at the time of the call and future contexts at the time of creation until the library is unloaded with muLibraryUnload(). If the environment variables are set to LAZY, library is not immediately loaded onto all existent contexts and will only be loaded when a function is needed for that context, such as a kernel launch.
- These environment variables are described in the MUSA programming guide under the "MUSA environment variables" section.
- The file should be a mubin file as output by nvcc, or a PTX file either as output by nvcc or handwritten, or a fatbin file as output by nvcc. A fatbin should also contain relocatable code when doing separate compilation.
- Options are passed as an array via jitOptions and any corresponding parameters are passed in jitOptionsValues. The number of total options is supplied via numJitOptions. Any outputs will be returned via jitOptionsValues.
- Library load options are passed as an array via libraryOptions and any corresponding parameters are passed in libraryOptionValues. The number of total library load options is supplied via numLibraryOptions.
Parameters
library(MUlibrary *): Returned libraryfileName(const char *): File to load fromjitOptions(MUjit_option *): Options for JITjitOptionsValues(void **): Option values for JITnumJitOptions(unsigned int): Number of optionslibraryOptions(MUlibraryOption *): Options for loadinglibraryOptionValues(void **): Option values for loadingnumLibraryOptions(unsigned int): Number of options for loading
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_PTX, MUSA_ERROR_UNSUPPORTED_PTX_VERSION, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_NO_BINARY_FOR_GPU, MUSA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND, MUSA_ERROR_SHARED_OBJECT_INIT_FAILED, MUSA_ERROR_JIT_COMPILER_NOT_FOUND, MUSA_ERROR_NOT_SUPPORTED
Note
- If the library contains managed variables and no device in the system supports managed variables this call is expected to return MUSA_ERROR_NOT_SUPPORTED
See also
muLibraryUnload
MUresult muLibraryUnload(MUlibrary library)
Description
- Unloads a library.
- Unloads the library specified with library
Parameters
library(MUlibrary): Library to unload
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE
See also
muLibraryGetKernel
MUresult muLibraryGetKernel(MUkernel *pKernel, MUlibrary library, const char *name)
Description
- Returns a kernel handle.
- Returns in pKernel the handle of the kernel with name name located in library library. If kernel handle is not found, the call returns MUSA_ERROR_NOT_FOUND.
Parameters
pKernel(MUkernel *): Returned kernel handlelibrary(MUlibrary): Library to retrieve kernel fromname(const char *): Name of kernel to retrieve
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_FOUND
See also
- muLibraryLoadData, muLibraryLoadFromFile, muLibraryUnload, muKernelGetFunction, muLibraryGetModule, muModuleGetFunction
muLibraryGetKernelCount
MUresult muLibraryGetKernelCount(unsigned int *count, MUlibrary lib)
Description
- Returns the number of kernels within a library.
- Returns in count the number of kernels in lib.
Parameters
count(unsigned int *): Number of kernels found within the librarylib(MUlibrary): Library to query
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_INVALID_VALUE
muLibraryEnumerateKernels
MUresult muLibraryEnumerateKernels(MUkernel *kernels, unsigned int numKernels, MUlibrary lib)
Description
- Retrieve the kernel handles within a library.
- Returns in kernels a maximum number of numKernels kernel handles within lib. The returned kernel handle becomes invalid when the library is unloaded.
Parameters
kernels(MUkernel *): Buffer where the kernel handles are returned tonumKernels(unsigned int): Maximum number of kernel handles may be returned to the bufferlib(MUlibrary): Library to query from
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_INVALID_VALUE
See also
muLibraryGetModule
MUresult muLibraryGetModule(MUmodule *pMod, MUlibrary library)
Description
- Returns a module handle.
- Returns in pMod the module handle associated with the current context located in library library. If module handle is not found, the call returns MUSA_ERROR_NOT_FOUND.
Parameters
pMod(MUmodule *): Returned module handlelibrary(MUlibrary): Library to retrieve module from
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_FOUND, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_CONTEXT_IS_DESTROYED
See also
muKernelGetFunction
MUresult muKernelGetFunction(MUfunction *pFunc, MUkernel kernel)
Description
- Returns a function handle.
- Returns in pFunc the handle of the function for the requested kernel kernel and the current context. If function handle is not found, the call returns MUSA_ERROR_NOT_FOUND.
Parameters
pFunc(MUfunction *): Returned function handlekernel(MUkernel): Kernel to retrieve function for the requested context
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_FOUND, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_CONTEXT_IS_DESTROYED
See also
- muLibraryLoadData, muLibraryLoadFromFile, muLibraryUnload, muLibraryGetKernel, muLibraryGetModule, muModuleGetFunction
muKernelGetLibrary
MUresult muKernelGetLibrary(MUlibrary *pLib, MUkernel kernel)
Description
- Returns a library handle.
- Returns in pLib the handle of the library for the requested kernel kernel
Parameters
pLib(MUlibrary *): Returned library handlekernel(MUkernel): Kernel to retrieve library handle
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_FOUND
See also
muLibraryGetGlobal
MUresult muLibraryGetGlobal(MUdeviceptr *dptr, size_t *bytes, MUlibrary library, const char *name)
Description
- Returns a global device pointer.
- Returns in *dptr and *bytes the base pointer and size of the global with name name for the requested library library and the current context. If no global for the requested name name exists, the call returns MUSA_ERROR_NOT_FOUND. One of the parameters dptr or bytes (not both) can be NULL in which case it is ignored.
Parameters
dptr(MUdeviceptr *): Returned global device pointer for the requested contextbytes(size_t *): Returned global size in byteslibrary(MUlibrary): Library to retrieve global fromname(const char *): Name of global to retrieve
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_FOUND, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_CONTEXT_IS_DESTROYED
See also
muLibraryGetManaged
MUresult muLibraryGetManaged(MUdeviceptr *dptr, size_t *bytes, MUlibrary library, const char *name)
Description
- Returns a pointer to managed memory.
- Returns in *dptr and *bytes the base pointer and size of the managed memory with name name for the requested library library. If no managed memory with the requested name name exists, the call returns MUSA_ERROR_NOT_FOUND. One of the parameters dptr or bytes (not both) can be NULL in which case it is ignored. Note that managed memory for library library is shared across devices and is registered when the library is loaded into atleast one context.
Parameters
dptr(MUdeviceptr *): Returned pointer to the managed memorybytes(size_t *): Returned memory size in byteslibrary(MUlibrary): Library to retrieve managed memory fromname(const char *): Name of managed memory to retrieve
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_FOUND
See also
muLibraryGetUnifiedFunction
MUresult muLibraryGetUnifiedFunction(void **fptr, MUlibrary library, const char *symbol)
Description
- Returns a pointer to a unified function.
- Returns in *fptr the function pointer to a unified function denoted by symbol. If no unified function with name symbol exists, the call returns MUSA_ERROR_NOT_FOUND. If there is no device with attribute MU_DEVICE_ATTRIBUTE_UNIFIED_FUNCTION_POINTERS present in the system, the call may return MUSA_ERROR_NOT_FOUND.
Parameters
fptr(void **): Returned pointer to a unified functionlibrary(MUlibrary): Library to retrieve function pointer memory fromsymbol(const char *): Name of function pointer to retrieve
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_FOUND
See also
muKernelGetAttribute
MUresult muKernelGetAttribute(int *pi, MUfunction_attribute attrib, MUkernel kernel, MUdevice dev)
Description
- Returns information about a kernel.
- Returns in *pi the integer value of the attribute attrib for the kernel kernel for the requested device dev. The supported attributes are: MU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK: The maximum number of threads per block, beyond which a launch of the kernel would fail. This number depends on both the kernel and the requested device. MU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES: The size in bytes of statically-allocated shared memory per block required by this kernel. This does not include dynamically-allocated shared memory requested by the user at runtime. MU_FUNC_ATTRIBUTE_CONST_SIZE_BYTES: The size in bytes of user-allocated constant memory required by this kernel. MU_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES: The size in bytes of local memory used by each thread of this kernel. MU_FUNC_ATTRIBUTE_NUM_REGS: The number of registers used by each thread of this kernel. MU_FUNC_ATTRIBUTE_PTX_VERSION: The PTX virtual architecture version for which the kernel was compiled. This value is the major PTX version * 10 the minor PTX version, so a PTX version 1.3 function would return the value 13. Note that this may return the undefined value of 0 for mubins compiled prior to MUSA 3.0. MU_FUNC_ATTRIBUTE_BINARY_VERSION: The binary architecture version for which the kernel was compiled. This value is the major binary version * 10 + the minor binary version, so a binary version 1.3 function would return the value 13. Note that this will return a value of 10 for legacy mubins that do not have a properly-encoded binary architecture version. MU_FUNC_CACHE_MODE_CA: The attribute to indicate whether the kernel has been compiled with user specified option "-Xptxas --dlcm=ca" set. MU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES: The maximum size in bytes of dynamically-allocated shared memory. MU_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT: Preferred shared memory-L1 cache split ratio in percent of total shared memory. MU_FUNC_ATTRIBUTE_CLUSTER_SIZE_MUST_BE_SET: If this attribute is set, the kernel must launch with a valid cluster size specified. MU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_WIDTH: The required cluster width in blocks. MU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_HEIGHT: The required cluster height in blocks. MU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_DEPTH: The required cluster depth in blocks. MU_FUNC_ATTRIBUTE_NON_PORTABLE_CLUSTER_SIZE_ALLOWED: Indicates whether the function can be launched with non-portable cluster size. 1 is allowed, 0 is disallowed. A non-portable cluster size may only function on the specific SKUs the program is tested on. The launch might fail if the program is run on a different hardware platform. MUSA API provides musaOccupancyMaxActiveClusters to assist with checking whether the desired size can be launched on the current device. A portable cluster size is guaranteed to be functional on all compute capabilities higher than the target compute capability. The portable cluster size for sm_90 is 8 blocks per cluster. This value may increase for future compute capabilities. The specific hardware unit may support higher cluster sizes that’s not guaranteed to be portable. MU_FUNC_ATTRIBUTE_CLUSTER_SCHEDULING_POLICY_PREFERENCE: The block scheduling policy of a function. The value type is MUclusterSchedulingPolicy.
Parameters
pi(int *): Returned attribute valueattrib(MUfunction_attribute): Attribute requestedkernel(MUkernel): Kernel to query attribute ofdev(MUdevice): Device to query attribute of
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- If another thread is trying to set the same attribute on the same device using muKernelSetAttribute() simultaneously, the attribute query will give the old or new value depending on the interleavings chosen by the OS scheduler and memory consistency.
See also
- muLibraryLoadData, muLibraryLoadFromFile, muLibraryUnload, muKernelSetAttribute, muLibraryGetKernel, muLaunchKernel, muKernelGetFunction, muLibraryGetModule, muModuleGetFunction, muFuncGetAttribute
muKernelSetAttribute
MUresult muKernelSetAttribute(MUfunction_attribute attrib, int val, MUkernel kernel, MUdevice dev)
Description
- Sets information about a kernel.
- This call sets the value of a specified attribute attrib on the kernel kernel for the requested device dev to an integer value specified by val. This function returns MUSA_SUCCESS if the new value of the attribute could be successfully set. If the set fails, this call will return an error. Not all attributes can have values set. Attempting to set a value on a read-only attribute will result in an error (MUSA_ERROR_INVALID_VALUE)
- Note that attributes set using muFuncSetAttribute() will override the attribute set by this API irrespective of whether the call to muFuncSetAttribute() is made before or after this API call. However, muKernelGetAttribute() will always return the attribute value set by this API.
- Supported attributes are: MU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES: This is the maximum size in bytes of dynamically-allocated shared memory. The value should contain the requested maximum size of dynamically-allocated shared memory. The sum of this value and the function attribute MU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES cannot exceed the device attribute MU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK_OPTIN. The maximal size of requestable dynamic shared memory may differ by GPU architecture. MU_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT: On devices where the L1 cache and shared memory use the same hardware resources, this sets the shared memory carveout preference, in percent of the total shared memory. See MU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_MULTIPROCESSOR This is only a hint, and the driver can choose a different ratio if required to execute the function. MU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_WIDTH: The required cluster width in blocks. The width, height, and depth values must either all be 0 or all be positive. The validity of the cluster dimensions is checked at launch time. If the value is set during compile time, it cannot be set at runtime. Setting it at runtime will return MUSA_ERROR_NOT_PERMITTED. MU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_HEIGHT: The required cluster height in blocks. The width, height, and depth values must either all be 0 or all be positive. The validity of the cluster dimensions is checked at launch time. If the value is set during compile time, it cannot be set at runtime. Setting it at runtime will return MUSA_ERROR_NOT_PERMITTED. MU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_DEPTH: The required cluster depth in blocks. The width, height, and depth values must either all be 0 or all be positive. The validity of the cluster dimensions is checked at launch time. If the value is set during compile time, it cannot be set at runtime. Setting it at runtime will return MUSA_ERROR_NOT_PERMITTED. MU_FUNC_ATTRIBUTE_NON_PORTABLE_CLUSTER_SIZE_ALLOWED: Indicates whether the function can be launched with non-portable cluster size. 1 is allowed, 0 is disallowed. MU_FUNC_ATTRIBUTE_CLUSTER_SCHEDULING_POLICY_PREFERENCE: The block scheduling policy of a function. The value type is MUclusterSchedulingPolicy.
Parameters
attrib(MUfunction_attribute): Attribute requestedval(int): Value to setkernel(MUkernel): Kernel to set attribute ofdev(MUdevice): Device to set attribute of
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_OUT_OF_MEMORY
Note
- The API has stricter locking requirements in comparison to its legacy counterpart muFuncSetAttribute() due to device-wide semantics. If multiple threads are trying to set the same attribute on the same device simultaneously, the attribute setting will depend on the interleavings chosen by the OS scheduler and memory consistency.
See also
- muLibraryLoadData, muLibraryLoadFromFile, muLibraryUnload, muKernelGetAttribute, muLibraryGetKernel, muLaunchKernel, muKernelGetFunction, muLibraryGetModule, muModuleGetFunction, muFuncSetAttribute
muKernelSetCacheConfig
MUresult muKernelSetCacheConfig(MUkernel kernel, MUfunc_cache config, MUdevice dev)
Description
- Sets the preferred cache configuration for a device kernel.
- On devices where the L1 cache and shared memory use the same hardware resources, this sets through config the preferred cache configuration for the device kernel kernel on the requested device dev. This is only a preference. The driver will use the requested configuration if possible, but it is free to choose a different configuration if required to execute kernel. Any context-wide preference set via muCtxSetCacheConfig() will be overridden by this per-kernel setting.
- Note that attributes set using muFuncSetCacheConfig() will override the attribute set by this API irrespective of whether the call to muFuncSetCacheConfig() is made before or after this API call.
- This setting does nothing on devices where the size of the L1 cache and shared memory are fixed.
- Launching a kernel with a different preference than the most recent preference setting may insert a device-side synchronization point.
- The supported cache configurations are: MU_FUNC_CACHE_PREFER_NONE: no preference for shared memory or L1 (default) MU_FUNC_CACHE_PREFER_SHARED: prefer larger shared memory and smaller L1 cache MU_FUNC_CACHE_PREFER_L1: prefer larger L1 cache and smaller shared memory MU_FUNC_CACHE_PREFER_EQUAL: prefer equal sized L1 cache and shared memory
Parameters
kernel(MUkernel): Kernel to configure cache forconfig(MUfunc_cache): Requested cache configurationdev(MUdevice): Device to set attribute of
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_OUT_OF_MEMORY
Note
- The API has stricter locking requirements in comparison to its legacy counterpart muFuncSetCacheConfig() due to device-wide semantics. If multiple threads are trying to set a config on the same device simultaneously, the cache config setting will depend on the interleavings chosen by the OS scheduler and memory consistency.
See also
- muLibraryLoadData, muLibraryLoadFromFile, muLibraryUnload, muLibraryGetKernel, muKernelGetFunction, muLibraryGetModule, muModuleGetFunction, muFuncSetCacheConfig, muCtxSetCacheConfig, muLaunchKernel
muKernelGetName
MUresult muKernelGetName(const char **name, MUkernel hfunc)
Description
- Returns the function name for a MUkernel handle.
- Returns in **name the function name associated with the kernel handle hfunc . The function name is returned as a null-terminated string. The returned name is only valid when the kernel handle is valid. If the library is unloaded or reloaded, one must call the API again to get the updated name. This API may return a mangled name if the function is not declared as having C linkage. If either **name or hfunc is NULL, MUSA_ERROR_INVALID_VALUE is returned.
Parameters
name(const char **): The returned name of the functionhfunc(MUkernel): The function handle to retrieve the name for
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
muKernelGetParamInfo
MUresult muKernelGetParamInfo(MUkernel kernel, size_t paramIndex, size_t *paramOffset, size_t *paramSize)
Description
- Returns the offset and size of a kernel parameter in the device-side parameter layout.
- Queries the kernel parameter at paramIndex into kernel's list of parameters, and returns in paramOffset and paramSize the offset and size, respectively, where the parameter will reside in the device-side parameter layout. This information can be used to update kernel node parameters from the device via musaGraphKernelNodeSetParam() and musaGraphKernelNodeUpdatesApply(). paramIndex must be less than the number of parameters that kernel takes. paramSize can be set to NULL if only the parameter offset is desired.
Parameters
kernel(MUkernel): The kernel to queryparamIndex(size_t): The parameter index to queryparamOffset(size_t *): Returns the offset into the device-side parameter layout at which the parameter residesparamSize(size_t *): Optionally returns the size of the parameter in the device-side parameter layout
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
3.12 Memory Management
muMemGetInfo
MUresult muMemGetInfo(size_t *free, size_t *total)
Description
- Gets free and total memory.
- Returns in *total the total amount of memory available to the the current context. Returns in *free the amount of memory on the device that is free according to the OS. MUSA is not guaranteed to be able to allocate all of the memory that the OS reports as free. In a multi-tenet situation, free estimate returned is prone to race condition where a new allocation/free done by a different process or a different thread in the same process between the time when free memory was estimated and reported, will result in deviation in free value reported and actual free memory.
- The integrated GPU on Tegra shares memory with CPU and other component of the SoC. The free and total values returned by the API excludes the SWAP memory space maintained by the OS on some platforms. The OS may move some of the memory pages into swap area as the GPU or CPU allocate or access memory. See Tegra app note on how to calculate total and free memory on Tegra.
Parameters
free(size_t *): Returned free memory in bytestotal(size_t *): Returned total memory in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemGetInfo_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMemGetInfo
muMemAlloc
MUresult muMemAlloc(MUdeviceptr *dptr, size_t bytesize)
Description
- Allocates device memory.
- Allocates bytesize bytes of linear memory on the device and returns in *dptr a pointer to the allocated memory. The allocated memory is suitably aligned for any kind of variable. The memory is not cleared. If bytesize is 0, muMemAlloc() returns MUSA_ERROR_INVALID_VALUE.
Parameters
dptr(MUdeviceptr *): Returned device pointerbytesize(size_t): Requested allocation size in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY
Note
- Additional exported symbol names in scope:
muMemAlloc_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMalloc
muMemAllocPitch
MUresult muMemAllocPitch(MUdeviceptr *dptr, size_t *pPitch, size_t WidthInBytes, size_t Height, unsigned int ElementSizeBytes)
Description
- Allocates pitched device memory.
- Allocates at least WidthInBytes * Height bytes of linear memory on the device and returns in dptr a pointer to the allocated memory. The function may pad the allocation to ensure that corresponding pointers in any given row will continue to meet the alignment requirements for coalescing as the address is updated from row to row. ElementSizeBytes specifies the size of the largest reads and writes that will be performed on the memory range. ElementSizeBytes may be 4, 8 or 16 (since coalesced memory transactions are not possible on other data sizes). If ElementSizeBytes is smaller than the actual read/write size of a kernel, the kernel will run correctly, but possibly at reduced speed. The pitch returned in pPitch by muMemAllocPitch() is the width in bytes of the allocation. The intended usage of pitch is as a separate parameter of the allocation, used to compute addresses within the 2D array. Given the row and column of an array element of type T, the address is computed as: TpElement=(T)((char*)BaseAddress+Row*Pitch)+Column;
- The pitch returned by muMemAllocPitch() is guaranteed to work with muMemcpy2D() under all circumstances. For allocations of 2D arrays, it is recommended that programmers consider performing pitch allocations using muMemAllocPitch(). Due to alignment restrictions in the hardware, this is especially true if the application will be performing 2D memory copies between different regions of device memory (whether linear memory or MUSA arrays).
- The byte alignment of the pitch returned by muMemAllocPitch() is guaranteed to match or exceed the alignment requirement for texture binding with muTexRefSetAddress2D().
Parameters
dptr(MUdeviceptr *): Returned device pointerpPitch(size_t *): Returned pitch of allocation in bytesWidthInBytes(size_t): Requested allocation width in bytesHeight(size_t): Requested allocation height in rowsElementSizeBytes(unsigned int): Size of largest reads/writes for range
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY
Note
- Additional exported symbol names in scope:
muMemAllocPitch_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMallocPitch
muMemFree
MUresult muMemFree(MUdeviceptr dptr)
Description
- Frees device memory.
- Frees the memory space pointed to by dptr, which must have been returned by a previous call to one of the following memory allocation APIs - muMemAlloc(), muMemAllocPitch(), muMemAllocManaged(), muMemAllocAsync(), muMemAllocFromPoolAsync()
- Note - This API will not perform any implict synchronization when the pointer was allocated with muMemAllocAsync or muMemAllocFromPoolAsync. Callers must ensure that all accesses to these pointer have completed before invoking muMemFree. For best performance and memory reuse, users should use muMemFreeAsync to free memory allocated via the stream ordered memory allocator. For all other pointers, this API may perform implicit synchronization.
Parameters
dptr(MUdeviceptr): Pointer to memory to free
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemFree_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemAllocManaged, muMemAllocAsync, muMemAllocFromPoolAsync, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemFreeAsync, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaFree
muMemGetAddressRange
MUresult muMemGetAddressRange(MUdeviceptr *pbase, size_t *psize, MUdeviceptr dptr)
Description
- Get information on memory allocations.
- Returns the base address in *pbase and size in *psize of the allocation by muMemAlloc() or muMemAllocPitch() that contains the input pointer dptr. Both parameters pbase and psize are optional. If one of them is NULL, it is ignored.
Parameters
pbase(MUdeviceptr *): Returned base addresspsize(size_t *): Returned size of device memory allocationdptr(MUdeviceptr): Device pointer to query
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_NOT_FOUND, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemGetAddressRange_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32
muMemAllocHost
MUresult muMemAllocHost(void **pp, size_t bytesize)
Description
- Allocates page-locked host memory.
- Allocates bytesize bytes of host memory that is page-locked and accessible to the device. The driver tracks the virtual memory ranges allocated with this function and automatically accelerates calls to functions such as muMemcpy(). Since the memory can be accessed directly by the device, it can be read or written with much higher bandwidth than pageable memory obtained with functions such as malloc().
- On systems where MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES is true, muMemAllocHost may not page-lock the allocated memory.
- Page-locking excessive amounts of memory with muMemAllocHost() may degrade system performance, since it reduces the amount of memory available to the system for paging. As a result, this function is best used sparingly to allocate staging areas for data exchange between host and device.
- Note all host memory allocated using muMemAllocHost() will automatically be immediately accessible to all contexts on all devices which support unified addressing (as may be queried using MU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING). The device pointer that may be used to access this host memory from those contexts is always equal to the returned host pointer *pp. See Unified Addressing for additional details.
Parameters
pp(void **): Returned pointer to host memorybytesize(size_t): Requested allocation size in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY
Note
- Additional exported symbol names in scope:
muMemAllocHost_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMallocHost
muMemFreeHost
MUresult muMemFreeHost(void *p)
Description
- Frees page-locked host memory.
- Frees the memory space pointed to by p, which must have been returned by a previous call to muMemAllocHost().
Parameters
p(void *): Pointer to memory to free
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaFreeHost
muMemHostAlloc
MUresult muMemHostAlloc(void **pp, size_t bytesize, unsigned int Flags)
Description
- Allocates page-locked host memory.
- Allocates bytesize bytes of host memory that is page-locked and accessible to the device. The driver tracks the virtual memory ranges allocated with this function and automatically accelerates calls to functions such as muMemcpyHtoD(). Since the memory can be accessed directly by the device, it can be read or written with much higher bandwidth than pageable memory obtained with functions such as malloc().
- On systems where MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES is true, muMemHostAlloc may not page-lock the allocated memory.
- Page-locking excessive amounts of memory may degrade system performance, since it reduces the amount of memory available to the system for paging. As a result, this function is best used sparingly to allocate staging areas for data exchange between host and device.
- The Flags parameter enables different options to be specified that affect the allocation, as follows.
- MU_MEMHOSTALLOC_PORTABLE: The memory returned by this call will be considered as pinned memory by all MUSA contexts, not just the one that performed the allocation. MU_MEMHOSTALLOC_DEVICEMAP: Maps the allocation into the MUSA address space. The device pointer to the memory may be obtained by calling muMemHostGetDevicePointer(). MU_MEMHOSTALLOC_WRITECOMBINED: Allocates the memory as write-combined (WC). WC memory can be transferred across the PCI Express bus more quickly on some system configurations, but cannot be read efficiently by most CPUs. WC memory is a good option for buffers that will be written by the CPU and read by the GPU via mapped pinned memory or host->device transfers.
- All of these flags are orthogonal to one another: a developer may allocate memory that is portable, mapped and/or write-combined with no restrictions.
- The MU_MEMHOSTALLOC_DEVICEMAP flag may be specified on MUSA contexts for devices that do not support mapped pinned memory. The failure is deferred to muMemHostGetDevicePointer() because the memory may be mapped into other MUSA contexts via the MU_MEMHOSTALLOC_PORTABLE flag.
- The memory allocated by this function must be freed with muMemFreeHost().
- Note all host memory allocated using muMemHostAlloc() will automatically be immediately accessible to all contexts on all devices which support unified addressing (as may be queried using MU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING). Unless the flag MU_MEMHOSTALLOC_WRITECOMBINED is specified, the device pointer that may be used to access this host memory from those contexts is always equal to the returned host pointer *pp. If the flag MU_MEMHOSTALLOC_WRITECOMBINED is specified, then the function muMemHostGetDevicePointer() must be used to query the device pointer, even if the context supports unified addressing. See Unified Addressing for additional details.
Parameters
pp(void **): Returned pointer to host memorybytesize(size_t): Requested allocation size in bytesFlags(unsigned int): Flags for allocation request
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaHostAlloc
muMemHostGetDevicePointer
MUresult muMemHostGetDevicePointer(MUdeviceptr *pdptr, void *p, unsigned int Flags)
Description
- Passes back device pointer of mapped pinned memory.
- Passes back the device pointer pdptr corresponding to the mapped, pinned host buffer p allocated by muMemHostAlloc.
- muMemHostGetDevicePointer() will fail if the MU_MEMHOSTALLOC_DEVICEMAP flag was not specified at the time the memory was allocated, or if the function is called on a GPU that does not support mapped pinned memory.
- For devices that have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CAN_USE_HOST_POINTER_FOR_REGISTERED_MEM, the memory can also be accessed from the device using the host pointer p. The device pointer returned by muMemHostGetDevicePointer() may or may not match the original host pointer p and depends on the devices visible to the application. If all devices visible to the application have a non-zero value for the device attribute, the device pointer returned by muMemHostGetDevicePointer() will match the original pointer p. If any device visible to the application has a zero value for the device attribute, the device pointer returned by muMemHostGetDevicePointer() will not match the original host pointer p, but it will be suitable for use on all devices provided Unified Virtual Addressing is enabled. In such systems, it is valid to access the memory using either pointer on devices that have a non-zero value for the device attribute. Note however that such devices should access the memory using only one of the two pointers and not both.
- Flags provides for future releases. For now, it must be set to 0.
Parameters
pdptr(MUdeviceptr *): Returned device pointerp(void *): Host pointerFlags(unsigned int): Options (must be 0)
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemHostGetDevicePointer_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaHostGetDevicePointer
muMemHostGetFlags
MUresult muMemHostGetFlags(unsigned int *pFlags, void *p)
Description
- Passes back flags that were used for a pinned allocation.
- Passes back the flags pFlags that were specified when allocating the pinned host buffer p allocated by muMemHostAlloc.
- muMemHostGetFlags() will fail if the pointer does not reside in an allocation performed by muMemAllocHost() or muMemHostAlloc().
Parameters
pFlags(unsigned int *): Returned flags wordp(void *): Host pointer
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muMemAllocManaged
MUresult muMemAllocManaged(MUdeviceptr *dptr, size_t bytesize, unsigned int flags)
Description
- Allocates memory that will be automatically managed by the Unified Memory system.
- Allocates bytesize bytes of managed memory on the device and returns in *dptr a pointer to the allocated memory. If the device doesn't support allocating managed memory, MUSA_ERROR_NOT_SUPPORTED is returned. Support for managed memory can be queried using the device attribute MU_DEVICE_ATTRIBUTE_MANAGED_MEMORY. The allocated memory is suitably aligned for any kind of variable. The memory is not cleared. If bytesize is 0, muMemAllocManaged returns MUSA_ERROR_INVALID_VALUE. The pointer is valid on the CPU and on all GPUs in the system that support managed memory. All accesses to this pointer must obey the Unified Memory programming model.
- flags specifies the default stream association for this allocation. flags must be one of MU_MEM_ATTACH_GLOBAL or MU_MEM_ATTACH_HOST. If MU_MEM_ATTACH_GLOBAL is specified, then this memory is accessible from any stream on any device. If MU_MEM_ATTACH_HOST is specified, then the allocation should not be accessed from devices that have a zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS; an explicit call to muStreamAttachMemAsync will be required to enable access on such devices.
- If the association is later changed via muStreamAttachMemAsync to a single stream, the default association as specified during muMemAllocManaged is restored when that stream is destroyed. For managed variables, the default association is always MU_MEM_ATTACH_GLOBAL. Note that destroying a stream is an asynchronous operation, and as a result, the change to default association won't happen until all work in the stream has completed.
- Memory allocated with muMemAllocManaged should be released with muMemFree.
- Device memory oversubscription is possible for GPUs that have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS. Managed memory on such GPUs may be evicted from device memory to host memory at any time by the Unified Memory driver in order to make room for other allocations.
- In a system where all GPUs have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS, managed memory may not be populated when this API returns and instead may be populated on access. In such systems, managed memory can migrate to any processor's memory at any time. The Unified Memory driver will employ heuristics to maintain data locality and prevent excessive page faults to the extent possible. The application can also guide the driver about memory usage patterns via muMemAdvise. The application can also explicitly migrate memory to a desired processor's memory via muMemPrefetchAsync.
- In a multi-GPU system where all of the GPUs have a zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS and all the GPUs have peer-to-peer support with each other, the physical storage for managed memory is created on the GPU which is active at the time muMemAllocManaged is called. All other GPUs will reference the data at reduced bandwidth via peer mappings over the PCIe bus. The Unified Memory driver does not migrate memory among such GPUs.
- In a multi-GPU system where not all GPUs have peer-to-peer support with each other and where the value of the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS is zero for at least one of those GPUs, the location chosen for physical storage of managed memory is system-dependent. On Linux, the location chosen will be device memory as long as the current set of active contexts are on devices that either have peer-to-peer support with each other or have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS. If there is an active context on a GPU that does not have a non-zero value for that device attribute and it does not have peer-to-peer support with the other devices that have active contexts on them, then the location for physical storage will be 'zero-copy' or host memory. Note that this means that managed memory that is located in device memory is migrated to host memory if a new context is created on a GPU that doesn't have a non-zero value for the device attribute and does not support peer-to-peer with at least one of the other devices that has an active context. This in turn implies that context creation may fail if there is insufficient host memory to migrate all managed allocations. On Windows, the physical storage is always created in 'zero-copy' or host memory. All GPUs will reference the data at reduced bandwidth over the PCIe bus. In these circumstances, use of the environment variable MUSA_VISIBLE_DEVICES is recommended to restrict MUSA to only use those GPUs that have peer-to-peer support. Alternatively, users can also set MUSA_MANAGED_FORCE_DEVICE_ALLOC to a non-zero value to force the driver to always use device memory for physical storage. When this environment variable is set to a non-zero value, all contexts created in that process on devices that support managed memory have to be peer-to-peer compatible with each other. Context creation will fail if a context is created on a device that supports managed memory and is not peer-to-peer compatible with any of the other managed memory supporting devices on which contexts were previously created, even if those contexts have been destroyed. These environment variables are described in the MUSA programming guide under the "MUSA environment variables" section. On ARM, managed memory is not available on discrete gpu with Drive PX-2.
Parameters
dptr(MUdeviceptr *): Returned device pointerbytesize(size_t): Requested allocation size in bytesflags(unsigned int): Must be one of MU_MEM_ATTACH_GLOBAL or MU_MEM_ATTACH_HOST
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_NOT_SUPPORTED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, muDeviceGetAttribute, muStreamAttachMemAsync, musaMallocManaged
muDeviceGetByPCIBusId
MUresult muDeviceGetByPCIBusId(MUdevice *dev, const char *pciBusId)
Description
- Returns a handle to a compute device.
- Returns in *device a device handle given a PCI bus ID string.
Parameters
dev(MUdevice *): Returned device handlepciBusId(const char *): String in one of the following forms:
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muDeviceGetPCIBusId
MUresult muDeviceGetPCIBusId(char *pciBusId, int len, MUdevice dev)
Description
- Returns a PCI Bus Id string for the device.
- Returns an ASCII string identifying the device dev in the NULL-terminated string pointed to by pciBusId. len specifies the maximum length of the string that may be returned.
Parameters
pciBusId(char *): Returned identifier string for the device in the following formatlen(int): Maximum length of string to store in namedev(MUdevice): Device to get identifier string for
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muIpcGetEventHandle
MUresult muIpcGetEventHandle(MUipcEventHandle *pHandle, MUevent event)
Description
- Gets an interprocess handle for a previously allocated event.
- Takes as input a previously allocated event. This event must have been created with the MU_EVENT_INTERPROCESS and MU_EVENT_DISABLE_TIMING flags set. This opaque handle may be copied into other processes and opened with muIpcOpenEventHandle to allow efficient hardware synchronization between GPU work in different processes.
- After the event has been opened in the importing process, muEventRecord, muEventSynchronize, muStreamWaitEvent and muEventQuery may be used in either process. Performing operations on the imported event after the exported event has been freed with muEventDestroy will result in undefined behavior.
- IPC functionality is restricted to devices with support for unified addressing on Linux and Windows operating systems. IPC functionality on Windows is supported for compatibility purposes but not recommended as it comes with performance cost. Users can test their device for IPC functionality by calling muapiDeviceGetAttribute with MU_DEVICE_ATTRIBUTE_IPC_EVENT_SUPPORTED
Parameters
pHandle(MUipcEventHandle *): Pointer to a user allocated MUipcEventHandle in which to return the opaque event handleevent(MUevent): Event allocated with MU_EVENT_INTERPROCESS and MU_EVENT_DISABLE_TIMING flags.
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_MAP_FAILED, MUSA_ERROR_INVALID_VALUE
See also
- muEventCreate, muEventDestroy, muEventSynchronize, muEventQuery, muStreamWaitEvent, muIpcOpenEventHandle, muIpcGetMemHandle, muIpcOpenMemHandle, muIpcCloseMemHandle, musaIpcGetEventHandle
muIpcOpenEventHandle
MUresult muIpcOpenEventHandle(MUevent *phEvent, MUipcEventHandle handle)
Description
- Opens an interprocess event handle for use in the current process.
- Opens an interprocess event handle exported from another process with muIpcGetEventHandle. This function returns a MUevent that behaves like a locally created event with the MU_EVENT_DISABLE_TIMING flag specified. This event must be freed with muEventDestroy.
- Performing operations on the imported event after the exported event has been freed with muEventDestroy will result in undefined behavior.
- IPC functionality is restricted to devices with support for unified addressing on Linux and Windows operating systems. IPC functionality on Windows is supported for compatibility purposes but not recommended as it comes with performance cost. Users can test their device for IPC functionality by calling muapiDeviceGetAttribute with MU_DEVICE_ATTRIBUTE_IPC_EVENT_SUPPORTED
Parameters
phEvent(MUevent *): Returns the imported eventhandle(MUipcEventHandle): Interprocess handle to open
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_MAP_FAILED, MUSA_ERROR_PEER_ACCESS_UNSUPPORTED, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_INVALID_VALUE
See also
- muEventCreate, muEventDestroy, muEventSynchronize, muEventQuery, muStreamWaitEvent, muIpcGetEventHandle, muIpcGetMemHandle, muIpcOpenMemHandle, muIpcCloseMemHandle, musaIpcOpenEventHandle
muIpcGetMemHandle
MUresult muIpcGetMemHandle(MUipcMemHandle *pHandle, MUdeviceptr dptr)
Description
- Gets an interprocess memory handle for an existing device memory allocation.
- Takes a pointer to the base of an existing device memory allocation created with muMemAlloc and exports it for use in another process. This is a lightweight operation and may be called multiple times on an allocation without adverse effects.
- If a region of memory is freed with muMemFree and a subsequent call to muMemAlloc returns memory with the same device address, muIpcGetMemHandle will return a unique handle for the new memory.
- IPC functionality is restricted to devices with support for unified addressing on Linux and Windows operating systems. IPC functionality on Windows is supported for compatibility purposes but not recommended as it comes with performance cost. Users can test their device for IPC functionality by calling muapiDeviceGetAttribute with MU_DEVICE_ATTRIBUTE_IPC_EVENT_SUPPORTED
Parameters
pHandle(MUipcMemHandle *): Pointer to user allocated MUipcMemHandle to return the handle in.dptr(MUdeviceptr): Base pointer to previously allocated device memory
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_MAP_FAILED, MUSA_ERROR_INVALID_VALUE
See also
- muMemAlloc, muMemFree, muIpcGetEventHandle, muIpcOpenEventHandle, muIpcOpenMemHandle, muIpcCloseMemHandle, musaIpcGetMemHandle
muIpcOpenMemHandle
MUresult muIpcOpenMemHandle(MUdeviceptr *pdptr, MUipcMemHandle handle, unsigned int Flags)
Description
- Opens an interprocess memory handle exported from another process and returns a device pointer usable in the local process.
- Maps memory exported from another process with muIpcGetMemHandle into the current device address space. For contexts on different devices muIpcOpenMemHandle can attempt to enable peer access between the devices as if the user called muCtxEnablePeerAccess. This behavior is controlled by the MU_IPC_MEM_LAZY_ENABLE_PEER_ACCESS flag. muDeviceCanAccessPeer can determine if a mapping is possible.
- Contexts that may open MUipcMemHandles are restricted in the following way. MUipcMemHandles from each MUdevice in a given process may only be opened by one MUcontext per MUdevice per other process.
- If the memory handle has already been opened by the current context, the reference count on the handle is incremented by 1 and the existing device pointer is returned.
- Memory returned from muIpcOpenMemHandle must be freed with muIpcCloseMemHandle.
- Calling muMemFree on an exported memory region before calling muIpcCloseMemHandle in the importing context will result in undefined behavior.
- IPC functionality is restricted to devices with support for unified addressing on Linux and Windows operating systems. IPC functionality on Windows is supported for compatibility purposes but not recommended as it comes with performance cost. Users can test their device for IPC functionality by calling muapiDeviceGetAttribute with MU_DEVICE_ATTRIBUTE_IPC_EVENT_SUPPORTED
Parameters
pdptr(MUdeviceptr *): Returned device pointerhandle(MUipcMemHandle): MUipcMemHandle to openFlags(unsigned int): Flags for this operation. Must be specified as MU_IPC_MEM_LAZY_ENABLE_PEER_ACCESS
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_MAP_FAILED, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_TOO_MANY_PEERS, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muIpcOpenMemHandle_v2. - No guarantees are made about the address returned in *pdptr. In particular, multiple processes may not receive the same address for the same handle.
See also
- muMemAlloc, muMemFree, muIpcGetEventHandle, muIpcOpenEventHandle, muIpcGetMemHandle, muIpcCloseMemHandle, muCtxEnablePeerAccess, muDeviceCanAccessPeer, musaIpcOpenMemHandle
muIpcCloseMemHandle
MUresult muIpcCloseMemHandle(MUdeviceptr dptr)
Description
- Attempts to close memory mapped with muIpcOpenMemHandle.
- Decrements the reference count of the memory returned by muIpcOpenMemHandle by 1. When the reference count reaches 0, this API unmaps the memory. The original allocation in the exporting process as well as imported mappings in other processes will be unaffected.
- Any resources used to enable peer access will be freed if this is the last mapping using them.
- IPC functionality is restricted to devices with support for unified addressing on Linux and Windows operating systems. IPC functionality on Windows is supported for compatibility purposes but not recommended as it comes with performance cost. Users can test their device for IPC functionality by calling muapiDeviceGetAttribute with MU_DEVICE_ATTRIBUTE_IPC_EVENT_SUPPORTED
Parameters
dptr(MUdeviceptr): Device pointer returned by muIpcOpenMemHandle
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_MAP_FAILED, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_INVALID_VALUE
See also
- muMemAlloc, muMemFree, muIpcGetEventHandle, muIpcOpenEventHandle, muIpcGetMemHandle, muIpcOpenMemHandle, musaIpcCloseMemHandle
muMemHostRegister
MUresult muMemHostRegister(void *p, size_t bytesize, unsigned int Flags)
Description
- Registers an existing host memory range for use by MUSA.
- Page-locks the memory range specified by p and bytesize and maps it for the device(s) as specified by Flags. This memory range also is added to the same tracking mechanism as muMemHostAlloc to automatically accelerate calls to functions such as muMemcpyHtoD(). Since the memory can be accessed directly by the device, it can be read or written with much higher bandwidth than pageable memory that has not been registered. Page-locking excessive amounts of memory may degrade system performance, since it reduces the amount of memory available to the system for paging. As a result, this function is best used sparingly to register staging areas for data exchange between host and device.
- On systems where MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES is true, muMemHostRegister will not page-lock the memory range specified by ptr but only populate unpopulated pages.
- The Flags parameter enables different options to be specified that affect the allocation, as follows.
- MU_MEMHOSTREGISTER_PORTABLE: The memory returned by this call will be considered as pinned memory by all MUSA contexts, not just the one that performed the allocation. MU_MEMHOSTREGISTER_DEVICEMAP: Maps the allocation into the MUSA address space. The device pointer to the memory may be obtained by calling muMemHostGetDevicePointer(). MU_MEMHOSTREGISTER_IOMEMORY: The pointer is treated as pointing to some I/O memory space, e.g. the PCI Express resource of a 3rd party device. MU_MEMHOSTREGISTER_READ_ONLY: The pointer is treated as pointing to memory that is considered read-only by the device. On platforms without MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES, this flag is required in order to register memory mapped to the CPU as read-only. Support for the use of this flag can be queried from the device attribute MU_DEVICE_ATTRIBUTE_READ_ONLY_HOST_REGISTER_SUPPORTED. Using this flag with a current context associated with a device that does not have this attribute set will cause muMemHostRegister to error with MUSA_ERROR_NOT_SUPPORTED.
- All of these flags are orthogonal to one another: a developer may page-lock memory that is portable or mapped with no restrictions.
- The MU_MEMHOSTREGISTER_DEVICEMAP flag may be specified on MUSA contexts for devices that do not support mapped pinned memory. The failure is deferred to muMemHostGetDevicePointer() because the memory may be mapped into other MUSA contexts via the MU_MEMHOSTREGISTER_PORTABLE flag.
- For devices that have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CAN_USE_HOST_POINTER_FOR_REGISTERED_MEM, the memory can also be accessed from the device using the host pointer p. The device pointer returned by muMemHostGetDevicePointer() may or may not match the original host pointer ptr and depends on the devices visible to the application. If all devices visible to the application have a non-zero value for the device attribute, the device pointer returned by muMemHostGetDevicePointer() will match the original pointer ptr. If any device visible to the application has a zero value for the device attribute, the device pointer returned by muMemHostGetDevicePointer() will not match the original host pointer ptr, but it will be suitable for use on all devices provided Unified Virtual Addressing is enabled. In such systems, it is valid to access the memory using either pointer on devices that have a non-zero value for the device attribute. Note however that such devices should access the memory using only of the two pointers and not both.
- The memory page-locked by this function must be unregistered with muMemHostUnregister().
Parameters
p(void *): Host pointer to memory to page-lockbytesize(size_t): Size in bytes of the address range to page-lockFlags(unsigned int): Flags for allocation request
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_HOST_MEMORY_ALREADY_REGISTERED, MUSA_ERROR_NOT_PERMITTED, MUSA_ERROR_NOT_SUPPORTED
Note
- Additional exported symbol names in scope:
muMemHostRegister_v2. - This function may also return error codes from previous, asynchronous launches.
See also
muMemHostUnregister
MUresult muMemHostUnregister(void *p)
Description
- Unregisters a memory range that was registered with muMemHostRegister.
- Unmaps the memory range whose base address is specified by p, and makes it pageable again.
- The base address must be the same one specified to muMemHostRegister().
Parameters
p(void *): Host pointer to memory to unregister
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_HOST_MEMORY_NOT_REGISTERED
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muMemcpy
MUresult muMemcpy(MUdeviceptr dst, MUdeviceptr src, size_t ByteCount)
Description
- Copies memory.
- Copies data between two pointers. dst and src are base pointers of the destination and source, respectively. ByteCount specifies the number of bytes to copy. Note that this function infers the type of the transfer (host to host, host to device, device to device, or device to host) from the pointer values. This function is only allowed in contexts which support unified addressing.
Parameters
dst(MUdeviceptr): Destination unified virtual address space pointersrc(MUdeviceptr): Source unified virtual address space pointerByteCount(size_t): Size of memory copy in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemcpy_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMemcpy, musaMemcpyToSymbol, musaMemcpyFromSymbol
muMemcpyPeer
MUresult muMemcpyPeer(MUdeviceptr dstDevice, MUcontext dstContext, MUdeviceptr srcDevice, MUcontext srcContext, size_t ByteCount)
Description
- Copies device memory between two contexts.
- Copies from device memory in one context to device memory in another context. dstDevice is the base device pointer of the destination memory and dstContext is the destination context. srcDevice is the base device pointer of the source memory and srcContext is the source pointer. ByteCount specifies the number of bytes to copy.
Parameters
dstDevice(MUdeviceptr): Destination device pointerdstContext(MUcontext): Destination contextsrcDevice(MUdeviceptr): Source device pointersrcContext(MUcontext): Source contextByteCount(size_t): Size of memory copy in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muMemcpyDtoD, muMemcpy3DPeer, muMemcpyDtoDAsync, muMemcpyPeerAsync, muMemcpy3DPeerAsync, musaMemcpyPeer
muMemcpyHtoD
MUresult muMemcpyHtoD(MUdeviceptr dstDevice, const void *srcHost, size_t ByteCount)
Description
- Copies memory from Host to Device.
- Copies from host memory to device memory. dstDevice and srcHost are the base addresses of the destination and source, respectively. ByteCount specifies the number of bytes to copy.
Parameters
dstDevice(MUdeviceptr): Destination device pointersrcHost(const void *): Source host pointerByteCount(size_t): Size of memory copy in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemcpyHtoD_v2,muMemcpyHtoD_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMemcpy, musaMemcpyToSymbol
muMemcpyDtoH
MUresult muMemcpyDtoH(void *dstHost, MUdeviceptr srcDevice, size_t ByteCount)
Description
- Copies memory from Device to Host.
- Copies from device to host memory. dstHost and srcDevice specify the base pointers of the destination and source, respectively. ByteCount specifies the number of bytes to copy.
Parameters
dstHost(void *): Destination host pointersrcDevice(MUdeviceptr): Source device pointerByteCount(size_t): Size of memory copy in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemcpyDtoH_v2,muMemcpyDtoH_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMemcpy, musaMemcpyFromSymbol
muMemcpyDtoD
MUresult muMemcpyDtoD(MUdeviceptr dstDevice, MUdeviceptr srcDevice, size_t ByteCount)
Description
- Copies memory from Device to Device.
- Copies from device memory to device memory. dstDevice and srcDevice are the base pointers of the destination and source, respectively. ByteCount specifies the number of bytes to copy.
Parameters
dstDevice(MUdeviceptr): Destination device pointersrcDevice(MUdeviceptr): Source device pointerByteCount(size_t): Size of memory copy in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemcpyDtoD_v2,muMemcpyDtoD_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMemcpy, musaMemcpyToSymbol, musaMemcpyFromSymbol
muMemcpyDtoA
MUresult muMemcpyDtoA(MUarray dstArray, size_t dstOffset, MUdeviceptr srcDevice, size_t ByteCount)
Description
- Copies memory from Device to Array.
- Copies from device memory to a 1D MUSA array. dstArray and dstOffset specify the MUSA array handle and starting index of the destination data. srcDevice specifies the base pointer of the source. ByteCount specifies the number of bytes to copy.
Parameters
dstArray(MUarray): Destination arraydstOffset(size_t): Offset in bytes of destination arraysrcDevice(MUdeviceptr): Source device pointerByteCount(size_t): Size of memory copy in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemcpyDtoA_v2,muMemcpyDtoA_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMemcpyToArray
muMemcpyAtoD
MUresult muMemcpyAtoD(MUdeviceptr dstDevice, MUarray srcArray, size_t srcOffset, size_t ByteCount)
Description
- Copies memory from Array to Device.
- Copies from one 1D MUSA array to device memory. dstDevice specifies the base pointer of the destination and must be naturally aligned with the MUSA array elements. srcArray and srcOffset specify the MUSA array handle and the offset in bytes into the array where the copy is to begin. ByteCount specifies the number of bytes to copy and must be evenly divisible by the array element size.
Parameters
dstDevice(MUdeviceptr): Destination device pointersrcArray(MUarray): Source arraysrcOffset(size_t): Offset in bytes of source arrayByteCount(size_t): Size of memory copy in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemcpyAtoD_v2,muMemcpyAtoD_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMemcpyFromArray
muMemcpyHtoA
MUresult muMemcpyHtoA(MUarray dstArray, size_t dstOffset, const void *srcHost, size_t ByteCount)
Description
- Copies memory from Host to Array.
- Copies from host memory to a 1D MUSA array. dstArray and dstOffset specify the MUSA array handle and starting offset in bytes of the destination data. pSrc specifies the base address of the source. ByteCount specifies the number of bytes to copy.
Parameters
dstArray(MUarray): Destination arraydstOffset(size_t): Offset in bytes of destination arraysrcHost(const void *): Source host pointerByteCount(size_t): Size of memory copy in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemcpyHtoA_v2. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMemcpyToArray
muMemcpyAtoH
MUresult muMemcpyAtoH(void *dstHost, MUarray srcArray, size_t srcOffset, size_t ByteCount)
Description
- Copies memory from Array to Host.
- Copies from one 1D MUSA array to host memory. dstHost specifies the base pointer of the destination. srcArray and srcOffset specify the MUSA array handle and starting offset in bytes of the source data. ByteCount specifies the number of bytes to copy.
Parameters
dstHost(void *): Destination device pointersrcArray(MUarray): Source arraysrcOffset(size_t): Offset in bytes of source arrayByteCount(size_t): Size of memory copy in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemcpyAtoH_v2. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMemcpyFromArray
muMemcpyAtoA
MUresult muMemcpyAtoA(MUarray dstArray, size_t dstOffset, MUarray srcArray, size_t srcOffset, size_t ByteCount)
Description
- Copies memory from Array to Array.
- Copies from one 1D MUSA array to another. dstArray and srcArray specify the handles of the destination and source MUSA arrays for the copy, respectively. dstOffset and srcOffset specify the destination and source offsets in bytes into the MUSA arrays. ByteCount is the number of bytes to be copied. The size of the elements in the MUSA arrays need not be the same format, but the elements must be the same size; and count must be evenly divisible by that size.
Parameters
dstArray(MUarray): Destination arraydstOffset(size_t): Offset in bytes of destination arraysrcArray(MUarray): Source arraysrcOffset(size_t): Offset in bytes of source arrayByteCount(size_t): Size of memory copy in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemcpyAtoA_v2,muMemcpyAtoA_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMemcpyArrayToArray
muMemcpy2D
MUresult muMemcpy2D(const MUSA_MEMCPY2D *pCopy)
Description
- Copies memory for 2D arrays.
- Perform a 2D memory copy according to the parameters specified in pCopy. The MUSA_MEMCPY2D structure is defined as:
typedef struct MUSA_MEMCPY2D_st {
unsigned int srcXInBytes, srcY;
MUmemorytype srcMemoryType;
const void *srcHost;
MUdeviceptr srcDevice;
MUarray srcArray;
unsigned int srcPitch;
unsigned int dstXInBytes, dstY;
MUmemorytype dstMemoryType;
void *dstHost;
MUdeviceptr dstDevice;
MUarray dstArray;
unsigned int dstPitch;
unsigned int WidthInBytes;
unsigned int Height;
} MUSA_MEMCPY2D;
- where: srcMemoryType and dstMemoryType specify the type of memory of the source and destination, respectively; MUmemorytype_enum is defined as:
typedef enum MUmemorytype_enum {
MU_MEMORYTYPE_HOST = 0x01,
MU_MEMORYTYPE_DEVICE = 0x02,
MU_MEMORYTYPE_ARRAY = 0x03,
MU_MEMORYTYPE_UNIFIED = 0x04;
} MUmemorytype;
Parameters
pCopy(const MUSA_MEMCPY2D *): Parameters for the memory copy
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemcpy2D_v2,muMemcpy2D_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DFromArray
muMemcpy2DUnaligned
MUresult muMemcpy2DUnaligned(const MUSA_MEMCPY2D *pCopy)
Description
- Copies memory for 2D arrays.
- Perform a 2D memory copy according to the parameters specified in pCopy. The MUSA_MEMCPY2D structure is defined as:
typedef struct MUSA_MEMCPY2D_st {
unsigned int srcXInBytes, srcY;
MUmemorytype srcMemoryType;
const void *srcHost;
MUdeviceptr srcDevice;
MUarray srcArray;
unsigned int srcPitch;
unsigned int dstXInBytes, dstY;
MUmemorytype dstMemoryType;
void *dstHost;
MUdeviceptr dstDevice;
MUarray dstArray;
unsigned int dstPitch;
unsigned int WidthInBytes;
unsigned int Height;
} MUSA_MEMCPY2D;
- where: srcMemoryType and dstMemoryType specify the type of memory of the source and destination, respectively; MUmemorytype_enum is defined as:
typedef enum MUmemorytype_enum {
MU_MEMORYTYPE_HOST = 0x01,
MU_MEMORYTYPE_DEVICE = 0x02,
MU_MEMORYTYPE_ARRAY = 0x03,
MU_MEMORYTYPE_UNIFIED = 0x04;
} MUmemorytype;
Parameters
pCopy(const MUSA_MEMCPY2D *): Parameters for the memory copy
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemcpy2DUnaligned_v2,muMemcpy2DUnaligned_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DFromArray
muMemcpy3D
MUresult muMemcpy3D(const MUSA_MEMCPY3D *pCopy)
Description
- Copies memory for 3D arrays.
- Perform a 3D memory copy according to the parameters specified in pCopy. The MUSA_MEMCPY3D structure is defined as:
typedef struct MUSA_MEMCPY3D_st {
unsigned int srcXInBytes, srcY, srcZ;
unsigned int srcLOD;
MUmemorytype srcMemoryType;
const void *srcHost;
MUdeviceptr srcDevice;
MUarray srcArray;
unsigned int srcPitch;
//ignoredwhensrcisarray unsigned int srcHeight;
//ignoredwhensrcisarray;
maybe0ifDepth==1 unsigned int dstXInBytes, dstY, dstZ;
unsigned int dstLOD;
MUmemorytype dstMemoryType;
void *dstHost;
MUdeviceptr dstDevice;
MUarray dstArray;
unsigned int dstPitch;
//ignoredwhendstisarray unsigned int dstHeight;
//ignoredwhendstisarray;
maybe0ifDepth==1 unsigned int WidthInBytes;
unsigned int Height;
unsigned int Depth;
} MUSA_MEMCPY3D;
- where: srcMemoryType and dstMemoryType specify the type of memory of the source and destination, respectively; MUmemorytype_enum is defined as:
typedef enum MUmemorytype_enum {
MU_MEMORYTYPE_HOST = 0x01,
MU_MEMORYTYPE_DEVICE = 0x02,
MU_MEMORYTYPE_ARRAY = 0x03,
MU_MEMORYTYPE_UNIFIED = 0x04;
} MUmemorytype;
Parameters
pCopy(const MUSA_MEMCPY3D *): Parameters for the memory copy
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemcpy3D_v2,muMemcpy3D_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMemcpy3D
muMemcpy3DPeer
MUresult muMemcpy3DPeer(const MUSA_MEMCPY3D_PEER *pCopy)
Description
- Copies memory between contexts.
- Perform a 3D memory copy according to the parameters specified in pCopy. See the definition of the MUSA_MEMCPY3D_PEER structure for documentation of its parameters.
Parameters
pCopy(const MUSA_MEMCPY3D_PEER *): Parameters for the memory copy
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muMemcpyDtoD, muMemcpyPeer, muMemcpyDtoDAsync, muMemcpyPeerAsync, muMemcpy3DPeerAsync, musaMemcpy3DPeer
muMemcpyAsync
MUresult muMemcpyAsync(MUdeviceptr dst, MUdeviceptr src, size_t ByteCount, MUstream hStream)
Description
- Copies memory asynchronously.
- Copies data between two pointers. dst and src are base pointers of the destination and source, respectively. ByteCount specifies the number of bytes to copy. Note that this function infers the type of the transfer (host to host, host to device, device to device, or device to host) from the pointer values. This function is only allowed in contexts which support unified addressing.
Parameters
dst(MUdeviceptr): Destination unified virtual address space pointersrc(MUdeviceptr): Source unified virtual address space pointerByteCount(size_t): Size of memory copy in byteshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muMemcpyAsync_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemcpyAsync, musaMemcpyToSymbolAsync, musaMemcpyFromSymbolAsync
muMemcpyPeerAsync
MUresult muMemcpyPeerAsync(MUdeviceptr dstDevice, MUcontext dstContext, MUdeviceptr srcDevice, MUcontext srcContext, size_t ByteCount, MUstream hStream)
Description
- Copies device memory between two contexts asynchronously.
- Copies from device memory in one context to device memory in another context. dstDevice is the base device pointer of the destination memory and dstContext is the destination context. srcDevice is the base device pointer of the source memory and srcContext is the source pointer. ByteCount specifies the number of bytes to copy.
Parameters
dstDevice(MUdeviceptr): Destination device pointerdstContext(MUcontext): Destination contextsrcDevice(MUdeviceptr): Source device pointersrcContext(MUcontext): Source contextByteCount(size_t): Size of memory copy in byteshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muMemcpyDtoD, muMemcpyPeer, muMemcpy3DPeer, muMemcpyDtoDAsync, muMemcpy3DPeerAsync, musaMemcpyPeerAsync
muMemcpyHtoDAsync
MUresult muMemcpyHtoDAsync(MUdeviceptr dstDevice, const void *srcHost, size_t ByteCount, MUstream hStream)
Description
- Copies memory from Host to Device.
- Copies from host memory to device memory. dstDevice and srcHost are the base addresses of the destination and source, respectively. ByteCount specifies the number of bytes to copy.
Parameters
dstDevice(MUdeviceptr): Destination device pointersrcHost(const void *): Source host pointerByteCount(size_t): Size of memory copy in byteshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muMemcpyHtoDAsync_v2,muMemcpyHtoDAsync_v2_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemcpyAsync, musaMemcpyToSymbolAsync
muMemcpyDtoHAsync
MUresult muMemcpyDtoHAsync(void *dstHost, MUdeviceptr srcDevice, size_t ByteCount, MUstream hStream)
Description
- Copies memory from Device to Host.
- Copies from device to host memory. dstHost and srcDevice specify the base pointers of the destination and source, respectively. ByteCount specifies the number of bytes to copy.
Parameters
dstHost(void *): Destination host pointersrcDevice(MUdeviceptr): Source device pointerByteCount(size_t): Size of memory copy in byteshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muMemcpyDtoHAsync_v2,muMemcpyDtoHAsync_v2_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemcpyAsync, musaMemcpyFromSymbolAsync
muMemcpyDtoDAsync
MUresult muMemcpyDtoDAsync(MUdeviceptr dstDevice, MUdeviceptr srcDevice, size_t ByteCount, MUstream hStream)
Description
- Copies memory from Device to Device.
- Copies from device memory to device memory. dstDevice and srcDevice are the base pointers of the destination and source, respectively. ByteCount specifies the number of bytes to copy.
Parameters
dstDevice(MUdeviceptr): Destination device pointersrcDevice(MUdeviceptr): Source device pointerByteCount(size_t): Size of memory copy in byteshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muMemcpyDtoDAsync_v2,muMemcpyDtoDAsync_v2_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemcpyAsync, musaMemcpyToSymbolAsync, musaMemcpyFromSymbolAsync
muMemcpyHtoAAsync
MUresult muMemcpyHtoAAsync(MUarray dstArray, size_t dstOffset, const void *srcHost, size_t ByteCount, MUstream hStream)
Description
- Copies memory from Host to Array.
- Copies from host memory to a 1D MUSA array. dstArray and dstOffset specify the MUSA array handle and starting offset in bytes of the destination data. srcHost specifies the base address of the source. ByteCount specifies the number of bytes to copy.
Parameters
dstArray(MUarray): Destination arraydstOffset(size_t): Offset in bytes of destination arraysrcHost(const void *): Source host pointerByteCount(size_t): Size of memory copy in byteshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muMemcpyHtoAAsync_v2. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemcpyToArrayAsync
muMemcpyAtoHAsync
MUresult muMemcpyAtoHAsync(void *dstHost, MUarray srcArray, size_t srcOffset, size_t ByteCount, MUstream hStream)
Description
- Copies memory from Array to Host.
- Copies from one 1D MUSA array to host memory. dstHost specifies the base pointer of the destination. srcArray and srcOffset specify the MUSA array handle and starting offset in bytes of the source data. ByteCount specifies the number of bytes to copy.
Parameters
dstHost(void *): Destination pointersrcArray(MUarray): Source arraysrcOffset(size_t): Offset in bytes of source arrayByteCount(size_t): Size of memory copy in byteshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muMemcpyAtoHAsync_v2. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemcpyFromArrayAsync
muMemcpy2DAsync
MUresult muMemcpy2DAsync(const MUSA_MEMCPY2D *pCopy, MUstream hStream)
Description
- Copies memory for 2D arrays.
- Perform a 2D memory copy according to the parameters specified in pCopy. The MUSA_MEMCPY2D structure is defined as:
typedef struct MUSA_MEMCPY2D_st {
unsigned int srcXInBytes, srcY;
MUmemorytype srcMemoryType;
const void *srcHost;
MUdeviceptr srcDevice;
MUarray srcArray;
unsigned int srcPitch;
unsigned int dstXInBytes, dstY;
MUmemorytype dstMemoryType;
void *dstHost;
MUdeviceptr dstDevice;
MUarray dstArray;
unsigned int dstPitch;
unsigned int WidthInBytes;
unsigned int Height;
} MUSA_MEMCPY2D;
- where: srcMemoryType and dstMemoryType specify the type of memory of the source and destination, respectively; MUmemorytype_enum is defined as:
typedef enum MUmemorytype_enum {
MU_MEMORYTYPE_HOST = 0x01,
MU_MEMORYTYPE_DEVICE = 0x02,
MU_MEMORYTYPE_ARRAY = 0x03,
MU_MEMORYTYPE_UNIFIED = 0x04;
} MUmemorytype;
Parameters
pCopy(const MUSA_MEMCPY2D *): Parameters for the memory copyhStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muMemcpy2DAsync_v2,muMemcpy2DAsync_v2_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync
muMemcpy3DAsync
MUresult muMemcpy3DAsync(const MUSA_MEMCPY3D *pCopy, MUstream hStream)
Description
- Copies memory for 3D arrays.
- Perform a 3D memory copy according to the parameters specified in pCopy. The MUSA_MEMCPY3D structure is defined as:
typedef struct MUSA_MEMCPY3D_st {
unsigned int srcXInBytes, srcY, srcZ;
unsigned int srcLOD;
MUmemorytype srcMemoryType;
const void *srcHost;
MUdeviceptr srcDevice;
MUarray srcArray;
unsigned int srcPitch;
//ignoredwhensrcisarray unsigned int srcHeight;
//ignoredwhensrcisarray;
maybe0ifDepth==1 unsigned int dstXInBytes, dstY, dstZ;
unsigned int dstLOD;
MUmemorytype dstMemoryType;
void *dstHost;
MUdeviceptr dstDevice;
MUarray dstArray;
unsigned int dstPitch;
//ignoredwhendstisarray unsigned int dstHeight;
//ignoredwhendstisarray;
maybe0ifDepth==1 unsigned int WidthInBytes;
unsigned int Height;
unsigned int Depth;
} MUSA_MEMCPY3D;
- where: srcMemoryType and dstMemoryType specify the type of memory of the source and destination, respectively; MUmemorytype_enum is defined as:
typedef enum MUmemorytype_enum {
MU_MEMORYTYPE_HOST = 0x01,
MU_MEMORYTYPE_DEVICE = 0x02,
MU_MEMORYTYPE_ARRAY = 0x03,
MU_MEMORYTYPE_UNIFIED = 0x04;
} MUmemorytype;
Parameters
pCopy(const MUSA_MEMCPY3D *): Parameters for the memory copyhStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muMemcpy3DAsync_v2,muMemcpy3DAsync_v2_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemcpy3DAsync
muMemcpy3DPeerAsync
MUresult muMemcpy3DPeerAsync(const MUSA_MEMCPY3D_PEER *pCopy, MUstream hStream)
Description
- Copies memory between contexts asynchronously.
- Perform a 3D memory copy according to the parameters specified in pCopy. See the definition of the MUSA_MEMCPY3D_PEER structure for documentation of its parameters.
Parameters
pCopy(const MUSA_MEMCPY3D_PEER *): Parameters for the memory copyhStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muMemcpyDtoD, muMemcpyPeer, muMemcpyDtoDAsync, muMemcpyPeerAsync, muMemcpy3DPeerAsync, musaMemcpy3DPeerAsync
muMemcpyBatchAsync
MUresult muMemcpyBatchAsync(MUdeviceptr *dsts, MUdeviceptr *srcs, size_t *sizes, size_t count, MUmemcpyAttributes *attrs, size_t *attrsIdxs, size_t numAttrs, size_t *failIdx, MUstream hStream)
Description
- Performs a batch of memory copies asynchronously.
- Performs a batch of memory copies. The batch as a whole executes in stream order but copies within a batch are not guaranteed to execute in any specific order. This API only supports pointer-to-pointer copies. For copies involving MUSA arrays, please see muMemcpy3DBatchAsync.
- Performs memory copies from source buffers specified in srcs to destination buffers specified in dsts. The size of each copy is specified in sizes. All three arrays must be of the same length as specified by count. Since there are no ordering guarantees for copies within a batch, specifying any dependent copies within a batch will result in undefined behavior.
- Every copy in the batch has to be associated with a set of attributes specified in the attrs array. Each entry in this array can apply to more than one copy. This can be done by specifying in the attrsIdxs array, the index of the first copy that the corresponding entry in the attrs array applies to. Both attrs and attrsIdxs must be of the same length as specified by numAttrs. For example, if a batch has 10 copies listed in dst/src/sizes, the first 6 of which have one set of attributes and the remaining 4 another, then numAttrs will be 2, attrsIdxs will be {0, 6} and attrs will contains the two sets of attributes. Note that the first entry in attrsIdxs must always be 0. Also, each entry must be greater than the previous entry and the last entry should be less than count. Furthermore, numAttrs must be lesser than or equal to count.
- The MUmemcpyAttributes::srcAccessOrder indicates the source access ordering to be observed for copies associated with the attribute. If the source access order is set to MU_MEMCPY_SRC_ACCESS_ORDER_STREAM, then the source will be accessed in stream order. If the source access order is set to MU_MEMCPY_SRC_ACCESS_ORDER_DURING_API_CALL then it indicates that access to the source pointer can be out of stream order and all accesses must be complete before the API call returns. This flag is suited for ephemeral sources (ex., stack variables) when it's known that no prior operations in the stream can be accessing the memory and also that the lifetime of the memory is limited to the scope that the source variable was declared in. Specifying this flag allows the driver to optimize the copy and removes the need for the user to synchronize the stream after the API call. If the source access order is set to MU_MEMCPY_SRC_ACCESS_ORDER_ANY then it indicates that access to the source pointer can be out of stream order and the accesses can happen even after the API call returns. This flag is suited for host pointers allocated outside MUSA (ex., via malloc) when it's known that no prior operations in the stream can be accessing the memory. Specifying this flag allows the driver to optimize the copy on certain platforms. Each memcpy operation in the batch must have a valid MUmemcpyAttributes corresponding to it including the appropriate srcAccessOrder setting, otherwise the API will return MUSA_ERROR_INVALID_VALUE.
- The MUmemcpyAttributes::srcLocHint and MUmemcpyAttributes::dstLocHint allows applications to specify hint locations for operands of a copy when the operand doesn't have a fixed location. That is, these hints are only applicable for managed memory pointers on devices where MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS is true or system-allocated pageable memory on devices where MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS is true. For other cases, these hints are ignored.
- The MUmemcpyAttributes::flags field can be used to specify certain flags for copies. Setting the MU_MEMCPY_FLAG_PREFER_OVERLAP_WITH_COMPUTE flag indicates that the associated copies should preferably overlap with any compute work. Note that this flag is a hint and can be ignored depending on the platform and other parameters of the copy.
- If any error is encountered while parsing the batch, the index within the batch where the error was encountered will be returned in failIdx.
Parameters
dsts(MUdeviceptr *): Array of destination pointers.srcs(MUdeviceptr *): Array of memcpy source pointers.sizes(size_t *): Array of sizes for memcpy operations.count(size_t): Size of dsts, srcs and sizes arraysattrs(MUmemcpyAttributes *): Array of memcpy attributes.attrsIdxs(size_t *): Array of indices to specify which copies each entry in the attrs array applies to. The attributes specified in attrs[k] will be applied to copies starting from attrsIdxs[k] through attrsIdxs[k+1] - 1. Also attrs[numAttrs-1] will apply to copies starting from attrsIdxs[numAttrs-1] through count - 1.numAttrs(size_t): Size of attrs and attrsIdxs arrays.failIdx(size_t *): Pointer to a location to return the index of the copy where a failure was encountered. The value will be SIZE_MAX if the error doesn't pertain to any specific copy.hStream(MUstream): The stream to enqueue the operations in. Must not be legacy NULL stream.
Returns
- MUSA_SUCCESS MUSA_ERROR_DEINITIALIZED MUSA_ERROR_NOT_INITIALIZED MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for asynchronous host/device behavior.
muMemoryTransferBatchAsync
MUresult muMemoryTransferBatchAsync(MUdeviceptr *dsts, MUdeviceptr *srcs, size_t *sizes, size_t count, MUmemcpyAttributes *attrs, size_t *attrsIdxs, size_t numAttrs, size_t *failIdx, MUstream hStream)
Description
- Performs a batch of memory copies asynchronously, and the memory can't be pinned host memory, now just support d2d and p2p.
- Performs a batch of memory copies. The batch as a whole executes in stream order but copies within a batch are not guaranteed to execute in any specific order. This API only supports pointer-to-pointer copies. For copies involving MUSA arrays, please see muMemcpy3DBatchAsync.
- Performs memory copies from source buffers specified in srcs to destination buffers specified in dsts. The size of each copy is specified in sizes. All three arrays must be of the same length as specified by count. Since there are no ordering guarantees for copies within a batch, specifying any dependent copies within a batch will result in undefined behavior.
- Every copy in the batch has to be associated with a set of attributes specified in the attrs array. Each entry in this array can apply to more than one copy. This can be done by specifying in the attrsIdxs array, the index of the first copy that the corresponding entry in the attrs array applies to. Both attrs and attrsIdxs must be of the same length as specified by numAttrs. For example, if a batch has 10 copies listed in dst/src/sizes, the first 6 of which have one set of attributes and the remaining 4 another, then numAttrs will be 2, attrsIdxs will be {0, 6} and attrs will contains the two sets of attributes. Note that the first entry in attrsIdxs must always be 0. Also, each entry must be greater than the previous entry and the last entry should be less than count. Furthermore, numAttrs must be lesser than or equal to count.
- The MUmemcpyAttributes::srcAccessOrder indicates the source access ordering to be observed for copies associated with the attribute. If the source access order is set to MU_MEMCPY_SRC_ACCESS_ORDER_STREAM, then the source will be accessed in stream order. If the source access order is set to MU_MEMCPY_SRC_ACCESS_ORDER_DURING_API_CALL then it indicates that access to the source pointer can be out of stream order and all accesses must be complete before the API call returns. This flag is suited for ephemeral sources (ex., stack variables) when it's known that no prior operations in the stream can be accessing the memory and also that the lifetime of the memory is limited to the scope that the source variable was declared in. Specifying this flag allows the driver to optimize the copy and removes the need for the user to synchronize the stream after the API call. If the source access order is set to MU_MEMCPY_SRC_ACCESS_ORDER_ANY then it indicates that access to the source pointer can be out of stream order and the accesses can happen even after the API call returns. This flag is suited for host pointers allocated outside MUSA (ex., via malloc) when it's known that no prior operations in the stream can be accessing the memory. Specifying this flag allows the driver to optimize the copy on certain platforms. Each memcpy operation in the batch must have a valid MUmemcpyAttributes corresponding to it including the appropriate srcAccessOrder setting, otherwise the API will return MUSA_ERROR_INVALID_VALUE.
- The MUmemcpyAttributes::srcLocHint and MUmemcpyAttributes::dstLocHint allows applications to specify hint locations for operands of a copy when the operand doesn't have a fixed location. That is, these hints are only applicable for managed memory pointers on devices where MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS is true or system-allocated pageable memory on devices where MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS is true. For other cases, these hints are ignored.
- The MUmemcpyAttributes::flags field can be used to specify certain flags for copies. Setting the MU_MEMCPY_FLAG_PREFER_OVERLAP_WITH_COMPUTE flag indicates that the associated copies should preferably overlap with any compute work. Note that this flag is a hint and can be ignored depending on the platform and other parameters of the copy.
- If any error is encountered while parsing the batch, the index within the batch where the error was encountered will be returned in failIdx.
Parameters
dsts(MUdeviceptr *): Array of destination pointers.srcs(MUdeviceptr *): Array of memcpy source pointers.sizes(size_t *): Array of sizes for memcpy operations.count(size_t): Size of dsts, srcs and sizes arraysattrs(MUmemcpyAttributes *): Array of memcpy attributes.attrsIdxs(size_t *): Array of indices to specify which copies each entry in the attrs array applies to. The attributes specified in attrs[k] will be applied to copies starting from attrsIdxs[k] through attrsIdxs[k+1] - 1. Also attrs[numAttrs-1] will apply to copies starting from attrsIdxs[numAttrs-1] through count - 1.numAttrs(size_t): Size of attrs and attrsIdxs arrays.failIdx(size_t *): Pointer to a location to return the index of the copy where a failure was encountered. The value will be SIZE_MAX if the error doesn't pertain to any specific copy.hStream(MUstream): The stream to enqueue the operations in. Must not be legacy NULL stream.
Returns
- MUSA_SUCCESS MUSA_ERROR_DEINITIALIZED MUSA_ERROR_NOT_INITIALIZED MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for asynchronous host/device behavior.
muMemoryAtomicBatchAsync
MUresult muMemoryAtomicBatchAsync(MUdeviceptr *dsts, MUdeviceptr *srcs, size_t *elements, MUatomicType *operation, size_t count, MUmemcpyAttributes *attrs, size_t *attrsIdxs, size_t numAttrs, size_t *failIdx, MUstream hStream)
Description
- Performs a batch of memory copies asynchronously, and the memory can't be pinned host memory, now just support d2d and p2p.
- Performs a batch of memory copies. The batch as a whole executes in stream order but copies within a batch are not guaranteed to execute in any specific order. This API only supports pointer-to-pointer copies. For copies involving MUSA arrays, please see muMemcpy3DBatchAsync.
- Performs memory copies from source buffers specified in srcs to destination buffers specified in dsts. The size of each copy is specified in sizes. All three arrays must be of the same length as specified by count. Since there are no ordering guarantees for copies within a batch, specifying any dependent copies within a batch will result in undefined behavior.
- Every copy in the batch has to be associated with a set of attributes specified in the attrs array. Each entry in this array can apply to more than one copy. This can be done by specifying in the attrsIdxs array, the index of the first copy that the corresponding entry in the attrs array applies to. Both attrs and attrsIdxs must be of the same length as specified by numAttrs. For example, if a batch has 10 copies listed in dst/src/sizes, the first 6 of which have one set of attributes and the remaining 4 another, then numAttrs will be 2, attrsIdxs will be {0, 6} and attrs will contains the two sets of attributes. Note that the first entry in attrsIdxs must always be 0. Also, each entry must be greater than the previous entry and the last entry should be less than count. Furthermore, numAttrs must be lesser than or equal to count.
- The MUmemcpyAttributes::srcAccessOrder indicates the source access ordering to be observed for copies associated with the attribute. If the source access order is set to MU_MEMCPY_SRC_ACCESS_ORDER_STREAM, then the source will be accessed in stream order. If the source access order is set to MU_MEMCPY_SRC_ACCESS_ORDER_DURING_API_CALL then it indicates that access to the source pointer can be out of stream order and all accesses must be complete before the API call returns. This flag is suited for ephemeral sources (ex., stack variables) when it's known that no prior operations in the stream can be accessing the memory and also that the lifetime of the memory is limited to the scope that the source variable was declared in. Specifying this flag allows the driver to optimize the copy and removes the need for the user to synchronize the stream after the API call. If the source access order is set to MU_MEMCPY_SRC_ACCESS_ORDER_ANY then it indicates that access to the source pointer can be out of stream order and the accesses can happen even after the API call returns. This flag is suited for host pointers allocated outside MUSA (ex., via malloc) when it's known that no prior operations in the stream can be accessing the memory. Specifying this flag allows the driver to optimize the copy on certain platforms. Each memcpy operation in the batch must have a valid MUmemcpyAttributes corresponding to it including the appropriate srcAccessOrder setting, otherwise the API will return MUSA_ERROR_INVALID_VALUE.
- The MUmemcpyAttributes::srcLocHint and MUmemcpyAttributes::dstLocHint allows applications to specify hint locations for operands of a copy when the operand doesn't have a fixed location. That is, these hints are only applicable for managed memory pointers on devices where MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS is true or system-allocated pageable memory on devices where MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS is true. For other cases, these hints are ignored.
- The MUmemcpyAttributes::flags field can be used to specify certain flags for copies. Setting the MU_MEMCPY_FLAG_PREFER_OVERLAP_WITH_COMPUTE flag indicates that the associated copies should preferably overlap with any compute work. Note that this flag is a hint and can be ignored depending on the platform and other parameters of the copy.
- If any error is encountered while parsing the batch, the index within the batch where the error was encountered will be returned in failIdx.
Parameters
dsts(MUdeviceptr *): Array of destination pointers.srcs(MUdeviceptr *): Array of memcpy source pointers.elements(size_t *): Array of elements for memcpy operations.operation(MUatomicType *): Array of atomic operations type.count(size_t): Size of dsts, srcs and sizes arraysattrs(MUmemcpyAttributes *): Array of memcpy attributes.attrsIdxs(size_t *): Array of indices to specify which copies each entry in the attrs array applies to. The attributes specified in attrs[k] will be applied to copies starting from attrsIdxs[k] through attrsIdxs[k+1] - 1. Also attrs[numAttrs-1] will apply to copies starting from attrsIdxs[numAttrs-1] through count - 1.numAttrs(size_t): Size of attrs and attrsIdxs arrays.failIdx(size_t *): Pointer to a location to return the index of the copy where a failure was encountered. The value will be SIZE_MAX if the error doesn't pertain to any specific copy.hStream(MUstream): The stream to enqueue the operations in. Must not be legacy NULL stream.
Returns
- MUSA_SUCCESS MUSA_ERROR_DEINITIALIZED MUSA_ERROR_NOT_INITIALIZED MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for asynchronous host/device behavior.
muMemcpy3DBatchAsync
MUresult muMemcpy3DBatchAsync(size_t numOps, MUSA_MEMCPY3D_BATCH_OP *opList, size_t *failIdx, unsigned long long flags, MUstream hStream)
Description
- Performs a batch of 3D memory copies asynchronously.
- Performs a batch of memory copies. The batch as a whole executes in stream order but copies within a batch are not guaranteed to execute in any specific order. Note that this means specifying any dependent copies within a batch will result in undefined behavior.
- Performs memory copies as specified in the opList array. The length of this array is specified in numOps. Each entry in this array describes a copy operation. This includes among other things, the source and destination operands for the copy as specified in MUSA_MEMCPY3D_BATCH_OP::src and MUSA_MEMCPY3D_BATCH_OP::dst respectively. The source and destination operands of a copy can either be a pointer or a MUSA array. The width, height and depth of a copy is specified in MUSA_MEMCPY3D_BATCH_OP::extent. The width, height and depth of a copy are specified in elements and must not be zero. For pointer-to-pointer copies, the element size is considered to be 1. For pointer to MUSA array or vice versa copies, the element size is determined by the MUSA array. For MUSA array to MUSA array copies, the element size of the two MUSA arrays must match.
- For a given operand, if MUmemcpy3DOperand::type is specified as MU_MEMCPY_OPERAND_TYPE_POINTER, then MUmemcpy3DOperand::op::ptr will be used. The MUmemcpy3DOperand::op::ptr::ptr field must contain the pointer where the copy should begin. The MUmemcpy3DOperand::op::ptr::rowLength field specifies the length of each row in elements and must either be zero or be greater than or equal to the width of the copy specified in MUSA_MEMCPY3D_BATCH_OP::extent::width. The MUmemcpy3DOperand::op::ptr::layerHeight field specifies the height of each layer and must either be zero or be greater than or equal to the height of the copy specified in MUSA_MEMCPY3D_BATCH_OP::extent::height. When either of these values is zero, that aspect of the operand is considered to be tightly packed according to the copy extent. For managed memory pointers on devices where MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS is true or system-allocated pageable memory on devices where MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS is true, the MUmemcpy3DOperand::op::ptr::locHint field can be used to hint the location of the operand.
- If an operand's type is specified as MU_MEMCPY_OPERAND_TYPE_ARRAY, then MUmemcpy3DOperand::op::array will be used. The MUmemcpy3DOperand::op::array::array field specifies the MUSA array and MUmemcpy3DOperand::op::array::offset specifies the 3D offset into that array where the copy begins.
- The MUmemcpyAttributes::srcAccessOrder indicates the source access ordering to be observed for copies associated with the attribute. If the source access order is set to MU_MEMCPY_SRC_ACCESS_ORDER_STREAM, then the source will be accessed in stream order. If the source access order is set to MU_MEMCPY_SRC_ACCESS_ORDER_DURING_API_CALL then it indicates that access to the source pointer can be out of stream order and all accesses must be complete before the API call returns. This flag is suited for ephemeral sources (ex., stack variables) when it's known that no prior operations in the stream can be accessing the memory and also that the lifetime of the memory is limited to the scope that the source variable was declared in. Specifying this flag allows the driver to optimize the copy and removes the need for the user to synchronize the stream after the API call. If the source access order is set to MU_MEMCPY_SRC_ACCESS_ORDER_ANY then it indicates that access to the source pointer can be out of stream order and the accesses can happen even after the API call returns. This flag is suited for host pointers allocated outside MUSA (ex., via malloc) when it's known that no prior operations in the stream can be accessing the memory. Specifying this flag allows the driver to optimize the copy on certain platforms. Each memcopy operation in opList must have a valid srcAccessOrder setting, otherwise this API will return MUSA_ERROR_INVALID_VALUE.
- The MUmemcpyAttributes::flags field can be used to specify certain flags for copies. Setting the MU_MEMCPY_FLAG_PREFER_OVERLAP_WITH_COMPUTE flag indicates that the associated copies should preferably overlap with any compute work. Note that this flag is a hint and can be ignored depending on the platform and other parameters of the copy.
- If any error is encountered while parsing the batch, the index within the batch where the error was encountered will be returned in failIdx.
Parameters
numOps(size_t): Total number of memcpy operations.opList(MUSA_MEMCPY3D_BATCH_OP *): Array of size numOps containing the actual memcpy operations.failIdx(size_t *): Pointer to a location to return the index of the copy where a failure was encountered. The value will be SIZE_MAX if the error doesn't pertain to any specific copy.flags(unsigned long long): Flags for future use, must be zero now.hStream(MUstream): The stream to enqueue the operations in. Must not be default NULL stream.
Returns
- MUSA_SUCCESS MUSA_ERROR_DEINITIALIZED MUSA_ERROR_NOT_INITIALIZED MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for asynchronous host/device behavior.
muMemsetD8
MUresult muMemsetD8(MUdeviceptr dstDevice, unsigned char uc, size_t N)
Description
- Initializes device memory.
- Performs asynchronous memory copy operation with the specified attributes.
- Performs asynchronous memory copy operation where dst and src are the destination and source pointers respectively. size specifies the number of bytes to copy. attr specifies the attributes for the copy and hStream specifies the stream to enqueue the operation in.
- For more information regarding the attributes, please refer to MUmemcpyAttributes and it's usage desciption in::muMemcpyBatchAsync
- For more information regarding the operation, please refer to MUSA_MEMCPY3D_BATCH_OP and it's usage desciption in::muMemcpy3DBatchAsync
Parameters
dstDevice(MUdeviceptr): Destination device pointeruc(unsigned char): Value to setN(size_t): Number of elements
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemsetD8_v2,muMemsetD8_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
See also
- muMemcpyBatchAsync Performs 3D memory copy with attributes asynchronously
- muMemcpy3DBatchAsync
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemset
muMemsetD16
MUresult muMemsetD16(MUdeviceptr dstDevice, unsigned short us, size_t N)
Description
- Initializes device memory.
- Sets the memory range of N 16-bit values to the specified value us. The dstDevice pointer must be two byte aligned.
Parameters
dstDevice(MUdeviceptr): Destination device pointerus(unsigned short): Value to setN(size_t): Number of elements
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemsetD16_v2,muMemsetD16_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemset
muMemsetD32
MUresult muMemsetD32(MUdeviceptr dstDevice, unsigned int ui, size_t N)
Description
- Initializes device memory.
- Sets the memory range of N 32-bit values to the specified value ui. The dstDevice pointer must be four byte aligned.
Parameters
dstDevice(MUdeviceptr): Destination device pointerui(unsigned int): Value to setN(size_t): Number of elements
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemsetD32_v2,muMemsetD32_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32Async, musaMemset
muMemsetD2D8
MUresult muMemsetD2D8(MUdeviceptr dstDevice, size_t dstPitch, unsigned char uc, size_t Width, size_t Height)
Description
- Initializes device memory.
- Sets the 2D memory range of Width 8-bit values to the specified value uc. Height specifies the number of rows to set, and dstPitch specifies the number of bytes between each row. This function performs fastest when the pitch is one that has been passed back by muMemAllocPitch().
Parameters
dstDevice(MUdeviceptr): Destination device pointerdstPitch(size_t): Pitch of destination device pointer(Unused if Height is 1)uc(unsigned char): Value to setWidth(size_t): Width of rowHeight(size_t): Number of rows
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemsetD2D8_v2,muMemsetD2D8_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemset2D
muMemsetD2D16
MUresult muMemsetD2D16(MUdeviceptr dstDevice, size_t dstPitch, unsigned short us, size_t Width, size_t Height)
Description
- Initializes device memory.
- Sets the 2D memory range of Width 16-bit values to the specified value us. Height specifies the number of rows to set, and dstPitch specifies the number of bytes between each row. The dstDevice pointer and dstPitch offset must be two byte aligned. This function performs fastest when the pitch is one that has been passed back by muMemAllocPitch().
Parameters
dstDevice(MUdeviceptr): Destination device pointerdstPitch(size_t): Pitch of destination device pointer(Unused if Height is 1)us(unsigned short): Value to setWidth(size_t): Width of rowHeight(size_t): Number of rows
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemsetD2D16_v2,muMemsetD2D16_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemset2D
muMemsetD2D32
MUresult muMemsetD2D32(MUdeviceptr dstDevice, size_t dstPitch, unsigned int ui, size_t Width, size_t Height)
Description
- Initializes device memory.
- Sets the 2D memory range of Width 32-bit values to the specified value ui. Height specifies the number of rows to set, and dstPitch specifies the number of bytes between each row. The dstDevice pointer and dstPitch offset must be four byte aligned. This function performs fastest when the pitch is one that has been passed back by muMemAllocPitch().
Parameters
dstDevice(MUdeviceptr): Destination device pointerdstPitch(size_t): Pitch of destination device pointer(Unused if Height is 1)ui(unsigned int): Value to setWidth(size_t): Width of rowHeight(size_t): Number of rows
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemsetD2D32_v2,muMemsetD2D32_v2_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemset2D
muMemsetD8Async
MUresult muMemsetD8Async(MUdeviceptr dstDevice, unsigned char uc, size_t N, MUstream hStream)
Description
- Sets device memory.
- Sets the memory range of N 8-bit values to the specified value uc.
Parameters
dstDevice(MUdeviceptr): Destination device pointeruc(unsigned char): Value to setN(size_t): Number of elementshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemsetD8Async_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemsetAsync
muMemsetD16Async
MUresult muMemsetD16Async(MUdeviceptr dstDevice, unsigned short us, size_t N, MUstream hStream)
Description
- Sets device memory.
- Sets the memory range of N 16-bit values to the specified value us. The dstDevice pointer must be two byte aligned.
Parameters
dstDevice(MUdeviceptr): Destination device pointerus(unsigned short): Value to setN(size_t): Number of elementshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemsetD16Async_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD32, muMemsetD32Async, musaMemsetAsync
muMemsetD32Async
MUresult muMemsetD32Async(MUdeviceptr dstDevice, unsigned int ui, size_t N, MUstream hStream)
Description
- Sets device memory.
- Sets the memory range of N 32-bit values to the specified value ui. The dstDevice pointer must be four byte aligned.
Parameters
dstDevice(MUdeviceptr): Destination device pointerui(unsigned int): Value to setN(size_t): Number of elementshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemsetD32Async_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, musaMemsetAsync
muMemsetD2D8Async
MUresult muMemsetD2D8Async(MUdeviceptr dstDevice, size_t dstPitch, unsigned char uc, size_t Width, size_t Height, MUstream hStream)
Description
- Sets device memory.
- Sets the 2D memory range of Width 8-bit values to the specified value uc. Height specifies the number of rows to set, and dstPitch specifies the number of bytes between each row. This function performs fastest when the pitch is one that has been passed back by muMemAllocPitch().
Parameters
dstDevice(MUdeviceptr): Destination device pointerdstPitch(size_t): Pitch of destination device pointer(Unused if Height is 1)uc(unsigned char): Value to setWidth(size_t): Width of rowHeight(size_t): Number of rowshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemsetD2D8Async_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemset2DAsync
muMemsetD2D16Async
MUresult muMemsetD2D16Async(MUdeviceptr dstDevice, size_t dstPitch, unsigned short us, size_t Width, size_t Height, MUstream hStream)
Description
- Sets device memory.
- Sets the 2D memory range of Width 16-bit values to the specified value us. Height specifies the number of rows to set, and dstPitch specifies the number of bytes between each row. The dstDevice pointer and dstPitch offset must be two byte aligned. This function performs fastest when the pitch is one that has been passed back by muMemAllocPitch().
Parameters
dstDevice(MUdeviceptr): Destination device pointerdstPitch(size_t): Pitch of destination device pointer(Unused if Height is 1)us(unsigned short): Value to setWidth(size_t): Width of rowHeight(size_t): Number of rowshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemsetD2D16Async_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D32, muMemsetD2D32Async, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemset2DAsync
muMemsetD2D32Async
MUresult muMemsetD2D32Async(MUdeviceptr dstDevice, size_t dstPitch, unsigned int ui, size_t Width, size_t Height, MUstream hStream)
Description
- Sets device memory.
- Sets the 2D memory range of Width 32-bit values to the specified value ui. Height specifies the number of rows to set, and dstPitch specifies the number of bytes between each row. The dstDevice pointer and dstPitch offset must be four byte aligned. This function performs fastest when the pitch is one that has been passed back by muMemAllocPitch().
Parameters
dstDevice(MUdeviceptr): Destination device pointerdstPitch(size_t): Pitch of destination device pointer(Unused if Height is 1)ui(unsigned int): Value to setWidth(size_t): Width of rowHeight(size_t): Number of rowshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemsetD2D32Async_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
- See the default-stream note for NULL stream semantics.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D8Async, muMemsetD2D16, muMemsetD2D16Async, muMemsetD2D32, muMemsetD8, muMemsetD8Async, muMemsetD16, muMemsetD16Async, muMemsetD32, muMemsetD32Async, musaMemset2DAsync
muArrayCreate
MUresult muArrayCreate(MUarray *pHandle, const MUSA_ARRAY_DESCRIPTOR *pAllocateArray)
Description
- Creates a 1D or 2D MUSA array.
- Creates a MUSA array according to the MUSA_ARRAY_DESCRIPTOR structure pAllocateArray and returns a handle to the new MUSA array in *pHandle. The MUSA_ARRAY_DESCRIPTOR is defined as:
typedef struct {
unsigned int Width;
unsigned int Height;
MUarray_format Format;
unsigned int NumChannels;
} MUSA_ARRAY_DESCRIPTOR;
- where:
- Width, and Height are the width, and height of the MUSA array (in elements); the MUSA array is one-dimensional if height is 0, two-dimensional otherwise; Format specifies the format of the elements; MUarray_format is defined as:
typedef enum MUarray_format_enum {
MU_AD_FORMAT_UNSIGNED_INT8 = 0x01,
MU_AD_FORMAT_UNSIGNED_INT16 = 0x02,
MU_AD_FORMAT_UNSIGNED_INT32 = 0x03,
MU_AD_FORMAT_SIGNED_INT8 = 0x08,
MU_AD_FORMAT_SIGNED_INT16 = 0x09,
MU_AD_FORMAT_SIGNED_INT32 = 0x0a,
MU_AD_FORMAT_HALF = 0x10,
MU_AD_FORMAT_FLOAT = 0x20,
MU_AD_FORMAT_NV12 = 0xb0,
MU_AD_FORMAT_UNORM_INT8X1 = 0xc0,
MU_AD_FORMAT_UNORM_INT8X2 = 0xc1,
MU_AD_FORMAT_UNORM_INT8X4 = 0xc2,
MU_AD_FORMAT_UNORM_INT16X1 = 0xc3,
MU_AD_FORMAT_UNORM_INT16X2 = 0xc4,
MU_AD_FORMAT_UNORM_INT16X4 = 0xc5,
MU_AD_FORMAT_SNORM_INT8X1 = 0xc6,
MU_AD_FORMAT_SNORM_INT8X2 = 0xc7,
MU_AD_FORMAT_SNORM_INT8X4 = 0xc8,
MU_AD_FORMAT_SNORM_INT16X1 = 0xc9,
MU_AD_FORMAT_SNORM_INT16X2 = 0xca,
MU_AD_FORMAT_SNORM_INT16X4 = 0xcb,
MU_AD_FORMAT_BC1_UNORM = 0x91,
MU_AD_FORMAT_BC1_UNORM_SRGB = 0x92,
MU_AD_FORMAT_BC2_UNORM = 0x93,
MU_AD_FORMAT_BC2_UNORM_SRGB = 0x94,
MU_AD_FORMAT_BC3_UNORM = 0x95,
MU_AD_FORMAT_BC3_UNORM_SRGB = 0x96,
MU_AD_FORMAT_BC4_UNORM = 0x97,
MU_AD_FORMAT_BC4_SNORM = 0x98,
MU_AD_FORMAT_BC5_UNORM = 0x99,
MU_AD_FORMAT_BC5_SNORM = 0x9a,
MU_AD_FORMAT_BC6H_UF16 = 0x9b,
MU_AD_FORMAT_BC6H_SF16 = 0x9c,
MU_AD_FORMAT_BC7_UNORM = 0x9d,
MU_AD_FORMAT_BC7_UNORM_SRGB = 0x9e,
MU_AD_FORMAT_P010 = 0x9f,
MU_AD_FORMAT_P016 = 0xa1,
MU_AD_FORMAT_NV16 = 0xa2,
MU_AD_FORMAT_P210 = 0xa3,
MU_AD_FORMAT_P216 = 0xa4,
MU_AD_FORMAT_YUY2 = 0xa5,
MU_AD_FORMAT_Y210 = 0xa6,
MU_AD_FORMAT_Y216 = 0xa7,
MU_AD_FORMAT_AYUV = 0xa8,
MU_AD_FORMAT_Y410 = 0xa9,
MU_AD_FORMAT_Y416 = 0xb1,
MU_AD_FORMAT_Y444_PLANAR8 = 0xb2,
MU_AD_FORMAT_Y444_PLANAR10 = 0xb3,
MU_AD_FORMAT_YUV444_8bit_SemiPlanar = 0xb4,
MU_AD_FORMAT_YUV444_16bit_SemiPlanar = 0xb5,
MU_AD_FORMAT_UNORM_INT_101010_2 = 0x50,
MU_AD_FORMAT_UINT8_PACKED_422 = 0x51,
MU_AD_FORMAT_UINT8_PACKED_444 = 0x52,
MU_AD_FORMAT_UINT8_SEMIPLANAR_420 = 0x53,
MU_AD_FORMAT_UINT16_SEMIPLANAR_420 = 0x54,
MU_AD_FORMAT_UINT8_SEMIPLANAR_422 = 0x55,
MU_AD_FORMAT_UINT16_SEMIPLANAR_422 = 0x56,
MU_AD_FORMAT_UINT8_SEMIPLANAR_444 = 0x57,
MU_AD_FORMAT_UINT16_SEMIPLANAR_444 = 0x58,
MU_AD_FORMAT_UINT8_PLANAR_420 = 0x59,
MU_AD_FORMAT_UINT16_PLANAR_420 = 0x5a,
MU_AD_FORMAT_UINT8_PLANAR_422 = 0x5b,
MU_AD_FORMAT_UINT16_PLANAR_422 = 0x5c,
MU_AD_FORMAT_UINT8_PLANAR_444 = 0x5d,
MU_AD_FORMAT_UINT16_PLANAR_444 = 0x5e,
} MUarray_format;
- NumChannels specifies the number of packed components per MUSA array element; it may be 1, 2, or 4;
- Here are examples of MUSA array descriptions:
- Description for a MUSA array of 2048 floats: MUSA_ARRAY_DESCRIPTORdesc; desc.Format=MU_AD_FORMAT_FLOAT; desc.NumChannels=1; desc.Width=2048; desc.Height=1;
- Description for a 64 x 64 MUSA array of floats: MUSA_ARRAY_DESCRIPTORdesc; desc.Format=MU_AD_FORMAT_FLOAT; desc.NumChannels=1; desc.Width=64; desc.Height=64;
- Description for a width x height MUSA array of 64-bit, 4x16-bit float16's: MUSA_ARRAY_DESCRIPTORdesc; desc.Format=MU_AD_FORMAT_HALF; desc.NumChannels=4; desc.Width=width; desc.Height=height;
- Description for a width x height MUSA array of 16-bit elements, each of which is two 8-bit unsigned chars: MUSA_ARRAY_DESCRIPTORarrayDesc; desc.Format=MU_AD_FORMAT_UNSIGNED_INT8; desc.NumChannels=2; desc.Width=width; desc.Height=height;
Parameters
pHandle(MUarray *): Returned arraypAllocateArray(const MUSA_ARRAY_DESCRIPTOR *): Array descriptor
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_UNKNOWN
Note
- Additional exported symbol names in scope:
muArrayCreate_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMallocArray
muArrayGetDescriptor
MUresult muArrayGetDescriptor(MUSA_ARRAY_DESCRIPTOR *pArrayDescriptor, MUarray hArray)
Description
- Get a 1D or 2D MUSA array descriptor.
- Returns in *pArrayDescriptor a descriptor containing information on the format and dimensions of the MUSA array hArray. It is useful for subroutines that have been passed a MUSA array, but need to know the MUSA array parameters for validation or other purposes.
Parameters
pArrayDescriptor(MUSA_ARRAY_DESCRIPTOR *): Returned array descriptorhArray(MUarray): Array to get descriptor of
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muArrayGetDescriptor_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaArrayGetInfo
muArrayGetMemoryRequirements
MUresult muArrayGetMemoryRequirements(MUSA_ARRAY_MEMORY_REQUIREMENTS *memoryRequirements, MUarray array, MUdevice device)
Description
- Returns the layout properties of a sparse MUSA array.
- Returns the layout properties of a sparse MUSA array in sparseProperties If the MUSA array is not allocated with flag MUSA_ARRAY3D_SPARSE MUSA_ERROR_INVALID_VALUE will be returned.
- If the returned value in MUSA_ARRAY_SPARSE_PROPERTIES::flags contains MU_ARRAY_SPARSE_PROPERTIES_SINGLE_MIPTAIL, then MUSA_ARRAY_SPARSE_PROPERTIES::miptailSize represents the total size of the array. Otherwise, it will be zero. Also, the returned value in MUSA_ARRAY_SPARSE_PROPERTIES::miptailFirstLevel is always zero. Note that the array must have been allocated using muArrayCreate or muArray3DCreate. For MUSA arrays obtained using muMipmappedArrayGetLevel, MUSA_ERROR_INVALID_VALUE will be returned. Instead, muMipmappedArrayGetSparseProperties must be used to obtain the sparse properties of the entire MUSA mipmapped array to which array belongs to.
- Returns the sparse array layout properties in sparseProperties If the MUSA mipmapped array is not allocated with flag MUSA_ARRAY3D_SPARSE MUSA_ERROR_INVALID_VALUE will be returned.
- For non-layered MUSA mipmapped arrays, MUSA_ARRAY_SPARSE_PROPERTIES::miptailSize returns the size of the mip tail region. The mip tail region includes all mip levels whose width, height or depth is less than that of the tile. For layered MUSA mipmapped arrays, if MUSA_ARRAY_SPARSE_PROPERTIES::flags contains MU_ARRAY_SPARSE_PROPERTIES_SINGLE_MIPTAIL, then MUSA_ARRAY_SPARSE_PROPERTIES::miptailSize specifies the size of the mip tail of all layers combined. Otherwise, MUSA_ARRAY_SPARSE_PROPERTIES::miptailSize specifies mip tail size per layer. The returned value of MUSA_ARRAY_SPARSE_PROPERTIES::miptailFirstLevel is valid only if MUSA_ARRAY_SPARSE_PROPERTIES::miptailSize is non-zero.
- Returns the memory requirements of a MUSA array in memoryRequirements If the MUSA array is not allocated with flag MUSA_ARRAY3D_DEFERRED_MAPPING MUSA_ERROR_INVALID_VALUE will be returned.
- The returned value in MUSA_ARRAY_MEMORY_REQUIREMENTS::size represents the total size of the MUSA array. The returned value in MUSA_ARRAY_MEMORY_REQUIREMENTS::alignment represents the alignment necessary for mapping the MUSA array.
Parameters
memoryRequirements(MUSA_ARRAY_MEMORY_REQUIREMENTS *): Pointer to MUSA_ARRAY_MEMORY_REQUIREMENTSarray(MUarray): MUSA array to get the memory requirements ofdevice(MUdevice): Device to get the memory requirements for
Returns
- MUSA_SUCCESS MUSA_ERROR_INVALID_VALUE
See also
- muMipmappedArrayGetSparseProperties, muMemMapArrayAsync
- muArrayGetSparseProperties, muMemMapArrayAsync
- muMipmappedArrayGetMemoryRequirements, muMemMapArrayAsync
muMipmappedArrayGetMemoryRequirements
MUresult muMipmappedArrayGetMemoryRequirements(MUSA_ARRAY_MEMORY_REQUIREMENTS *memoryRequirements, MUmipmappedArray mipmap, MUdevice device)
Description
- Returns the memory requirements of a MUSA mipmapped array.
- Returns the memory requirements of a MUSA mipmapped array in memoryRequirements If the MUSA mipmapped array is not allocated with flag MUSA_ARRAY3D_DEFERRED_MAPPING MUSA_ERROR_INVALID_VALUE will be returned.
- The returned value in MUSA_ARRAY_MEMORY_REQUIREMENTS::size represents the total size of the MUSA mipmapped array. The returned value in MUSA_ARRAY_MEMORY_REQUIREMENTS::alignment represents the alignment necessary for mapping the MUSA mipmapped array.
Parameters
memoryRequirements(MUSA_ARRAY_MEMORY_REQUIREMENTS *): Pointer to MUSA_ARRAY_MEMORY_REQUIREMENTSmipmap(MUmipmappedArray): MUSA mipmapped array to get the memory requirements ofdevice(MUdevice): Device to get the memory requirements for
Returns
- MUSA_SUCCESS MUSA_ERROR_INVALID_VALUE
See also
- muArrayGetMemoryRequirements, muMemMapArrayAsync
muArrayDestroy
MUresult muArrayDestroy(MUarray hArray)
Description
- Gets a MUSA array plane from a MUSA array.
- Returns in pPlaneArray a MUSA array that represents a single format plane of the MUSA array hArray.
- If planeIdx is greater than the maximum number of planes in this array or if the array does not have a multi-planar format e.g: MU_AD_FORMAT_NV12, then MUSA_ERROR_INVALID_VALUE is returned.
- Note that if the hArray has format MU_AD_FORMAT_NV12, then passing in 0 for planeIdx returns a MUSA array of the same size as hArray but with one channel and MU_AD_FORMAT_UNSIGNED_INT8 as its format. If 1 is passed for planeIdx, then the returned MUSA array has half the height and width of hArray with two channels and MU_AD_FORMAT_UNSIGNED_INT8 as its format.
- Destroys the MUSA array hArray.
Parameters
hArray(MUarray): Array to destroy
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_ARRAY_IS_MAPPED, MUSA_ERROR_CONTEXT_IS_DESTROYED
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muArrayCreate, musaArrayGetPlane
- muArray3DCreate, muArray3DGetDescriptor, muArrayCreate, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaFreeArray
muArray3DCreate
MUresult muArray3DCreate(MUarray *pHandle, const MUSA_ARRAY3D_DESCRIPTOR *pAllocateArray)
Description
- Creates a 3D MUSA array.
- Creates a MUSA array according to the MUSA_ARRAY3D_DESCRIPTOR structure pAllocateArray and returns a handle to the new MUSA array in *pHandle. The MUSA_ARRAY3D_DESCRIPTOR is defined as:
typedef struct {
unsigned int Width;
unsigned int Height;
unsigned int Depth;
MUarray_format Format;
unsigned int NumChannels;
unsigned int Flags;
} MUSA_ARRAY3D_DESCRIPTOR;
- where:
- Width, Height, and Depth are the width, height, and depth of the MUSA array (in elements); the following types of MUSA arrays can be allocated: A 1D array is allocated if Height and Depth extents are both zero. A 2D array is allocated if only Depth extent is zero. A 3D array is allocated if all three extents are non-zero. A 1D layered MUSA array is allocated if only Height is zero and the MUSA_ARRAY3D_LAYERED flag is set. Each layer is a 1D array. The number of layers is determined by the depth extent. A 2D layered MUSA array is allocated if all three extents are non-zero and the MUSA_ARRAY3D_LAYERED flag is set. Each layer is a 2D array. The number of layers is determined by the depth extent. A cubemap MUSA array is allocated if all three extents are non-zero and the MUSA_ARRAY3D_CUBEMAP flag is set. Width must be equal to Height, and Depth must be six. A cubemap is a special type of 2D layered MUSA array, where the six layers represent the six faces of a cube. The order of the six layers in memory is the same as that listed in MUarray_cubemap_face. A cubemap layered MUSA array is allocated if all three extents are non-zero, and both, MUSA_ARRAY3D_CUBEMAP and MUSA_ARRAY3D_LAYERED flags are set. Width must be equal to Height, and Depth must be a multiple of six. A cubemap layered MUSA array is a special type of 2D layered MUSA array that consists of a collection of cubemaps. The first six layers represent the first cubemap, the next six layers form the second cubemap, and so on. Format specifies the format of the elements; MUarray_format is defined as:
typedef enum MUarray_format_enum {
MU_AD_FORMAT_UNSIGNED_INT8 = 0x01,
MU_AD_FORMAT_UNSIGNED_INT16 = 0x02,
MU_AD_FORMAT_UNSIGNED_INT32 = 0x03,
MU_AD_FORMAT_SIGNED_INT8 = 0x08,
MU_AD_FORMAT_SIGNED_INT16 = 0x09,
MU_AD_FORMAT_SIGNED_INT32 = 0x0a,
MU_AD_FORMAT_HALF = 0x10,
MU_AD_FORMAT_FLOAT = 0x20,
MU_AD_FORMAT_NV12 = 0xb0,
MU_AD_FORMAT_UNORM_INT8X1 = 0xc0,
MU_AD_FORMAT_UNORM_INT8X2 = 0xc1,
MU_AD_FORMAT_UNORM_INT8X4 = 0xc2,
MU_AD_FORMAT_UNORM_INT16X1 = 0xc3,
MU_AD_FORMAT_UNORM_INT16X2 = 0xc4,
MU_AD_FORMAT_UNORM_INT16X4 = 0xc5,
MU_AD_FORMAT_SNORM_INT8X1 = 0xc6,
MU_AD_FORMAT_SNORM_INT8X2 = 0xc7,
MU_AD_FORMAT_SNORM_INT8X4 = 0xc8,
MU_AD_FORMAT_SNORM_INT16X1 = 0xc9,
MU_AD_FORMAT_SNORM_INT16X2 = 0xca,
MU_AD_FORMAT_SNORM_INT16X4 = 0xcb,
MU_AD_FORMAT_BC1_UNORM = 0x91,
MU_AD_FORMAT_BC1_UNORM_SRGB = 0x92,
MU_AD_FORMAT_BC2_UNORM = 0x93,
MU_AD_FORMAT_BC2_UNORM_SRGB = 0x94,
MU_AD_FORMAT_BC3_UNORM = 0x95,
MU_AD_FORMAT_BC3_UNORM_SRGB = 0x96,
MU_AD_FORMAT_BC4_UNORM = 0x97,
MU_AD_FORMAT_BC4_SNORM = 0x98,
MU_AD_FORMAT_BC5_UNORM = 0x99,
MU_AD_FORMAT_BC5_SNORM = 0x9a,
MU_AD_FORMAT_BC6H_UF16 = 0x9b,
MU_AD_FORMAT_BC6H_SF16 = 0x9c,
MU_AD_FORMAT_BC7_UNORM = 0x9d,
MU_AD_FORMAT_BC7_UNORM_SRGB = 0x9e,
MU_AD_FORMAT_P010 = 0x9f,
MU_AD_FORMAT_P016 = 0xa1,
MU_AD_FORMAT_NV16 = 0xa2,
MU_AD_FORMAT_P210 = 0xa3,
MU_AD_FORMAT_P216 = 0xa4,
MU_AD_FORMAT_YUY2 = 0xa5,
MU_AD_FORMAT_Y210 = 0xa6,
MU_AD_FORMAT_Y216 = 0xa7,
MU_AD_FORMAT_AYUV = 0xa8,
MU_AD_FORMAT_Y410 = 0xa9,
MU_AD_FORMAT_Y416 = 0xb1,
MU_AD_FORMAT_Y444_PLANAR8 = 0xb2,
MU_AD_FORMAT_Y444_PLANAR10 = 0xb3,
MU_AD_FORMAT_YUV444_8bit_SemiPlanar = 0xb4,
MU_AD_FORMAT_YUV444_16bit_SemiPlanar = 0xb5,
MU_AD_FORMAT_UNORM_INT_101010_2 = 0x50,
} MUarray_format;
- NumChannels specifies the number of packed components per MUSA array element; it may be 1, 2, or 4; Flags may be set to MUSA_ARRAY3D_LAYERED to enable creation of layered MUSA arrays. If this flag is set, Depth specifies the number of layers, not the depth of a 3D array. MUSA_ARRAY3D_SURFACE_LDST to enable surface references to be bound to the MUSA array. If this flag is not set, muSurfRefSetArray will fail when attempting to bind the MUSA array to a surface reference. MUSA_ARRAY3D_CUBEMAP to enable creation of cubemaps. If this flag is set, Width must be equal to Height, and Depth must be six. If the MUSA_ARRAY3D_LAYERED flag is also set, then Depth must be a multiple of six. MUSA_ARRAY3D_TEXTURE_GATHER to indicate that the MUSA array will be used for texture gather. Texture gather can only be performed on 2D MUSA arrays.
- Width, Height and Depth must meet certain size requirements as listed in the following table. All values are specified in elements. Note that for brevity's sake, the full name of the device attribute is not specified. For ex., TEXTURE1D_WIDTH refers to the device attribute MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_WIDTH.
- Note that 2D MUSA arrays have different size requirements if the MUSA_ARRAY3D_TEXTURE_GATHER flag is set. Width and Height must not be greater than MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_GATHER_WIDTH and MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_GATHER_HEIGHT respectively, in that case.
- MUSA array type Valid extents that must always be met {(width range in elements), (height range), (depth range)} Valid extents with MUSA_ARRAY3D_SURFACE_LDST set {(width range in elements), (height range), (depth range)} 1D { (1,TEXTURE1D_WIDTH), 0, 0 } { (1,SURFACE1D_WIDTH), 0, 0 } 2D { (1,TEXTURE2D_WIDTH), (1,TEXTURE2D_HEIGHT), 0 } { (1,SURFACE2D_WIDTH), (1,SURFACE2D_HEIGHT), 0 } 3D { (1,TEXTURE3D_WIDTH), (1,TEXTURE3D_HEIGHT), (1,TEXTURE3D_DEPTH) } OR { (1,TEXTURE3D_WIDTH_ALTERNATE), (1,TEXTURE3D_HEIGHT_ALTERNATE), (1,TEXTURE3D_DEPTH_ALTERNATE) } { (1,SURFACE3D_WIDTH), (1,SURFACE3D_HEIGHT), (1,SURFACE3D_DEPTH) } 1D Layered { (1,TEXTURE1D_LAYERED_WIDTH), 0, (1,TEXTURE1D_LAYERED_LAYERS) } { (1,SURFACE1D_LAYERED_WIDTH), 0, (1,SURFACE1D_LAYERED_LAYERS) } 2D Layered { (1,TEXTURE2D_LAYERED_WIDTH), (1,TEXTURE2D_LAYERED_HEIGHT), (1,TEXTURE2D_LAYERED_LAYERS) } { (1,SURFACE2D_LAYERED_WIDTH), (1,SURFACE2D_LAYERED_HEIGHT), (1,SURFACE2D_LAYERED_LAYERS) } Cubemap { (1,TEXTURECUBEMAP_WIDTH), (1,TEXTURECUBEMAP_WIDTH), 6 } { (1,SURFACECUBEMAP_WIDTH), (1,SURFACECUBEMAP_WIDTH), 6 } Cubemap Layered { (1,TEXTURECUBEMAP_LAYERED_WIDTH), (1,TEXTURECUBEMAP_LAYERED_WIDTH), (1,TEXTURECUBEMAP_LAYERED_LAYERS) } { (1,SURFACECUBEMAP_LAYERED_WIDTH), (1,SURFACECUBEMAP_LAYERED_WIDTH), (1,SURFACECUBEMAP_LAYERED_LAYERS) }
- Here are examples of MUSA array descriptions:
- Description for a MUSA array of 2048 floats: MUSA_ARRAY3D_DESCRIPTORdesc; desc.Format=MU_AD_FORMAT_FLOAT; desc.NumChannels=1; desc.Width=2048; desc.Height=0; desc.Depth=0;
- Description for a 64 x 64 MUSA array of floats: MUSA_ARRAY3D_DESCRIPTORdesc; desc.Format=MU_AD_FORMAT_FLOAT; desc.NumChannels=1; desc.Width=64; desc.Height=64; desc.Depth=0;
- Description for a width x height x depth MUSA array of 64-bit, 4x16-bit float16's: MUSA_ARRAY3D_DESCRIPTORdesc; desc.Format=MU_AD_FORMAT_HALF; desc.NumChannels=4; desc.Width=width; desc.Height=height; desc.Depth=depth;
Parameters
pHandle(MUarray *): Returned arraypAllocateArray(const MUSA_ARRAY3D_DESCRIPTOR *): 3D array descriptor
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_UNKNOWN
Note
- Additional exported symbol names in scope:
muArray3DCreate_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DGetDescriptor, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaMalloc3DArray
muArray3DGetDescriptor
MUresult muArray3DGetDescriptor(MUSA_ARRAY3D_DESCRIPTOR *pArrayDescriptor, MUarray hArray)
Description
- Get a 3D MUSA array descriptor.
- Returns in *pArrayDescriptor a descriptor containing information on the format and dimensions of the MUSA array hArray. It is useful for subroutines that have been passed a MUSA array, but need to know the MUSA array parameters for validation or other purposes.
- This function may be called on 1D and 2D arrays, in which case the Height and/or Depth members of the descriptor struct will be set to 0.
Parameters
pArrayDescriptor(MUSA_ARRAY3D_DESCRIPTOR *): Returned 3D array descriptorhArray(MUarray): 3D array to get descriptor of
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_CONTEXT_IS_DESTROYED
Note
- Additional exported symbol names in scope:
muArray3DGetDescriptor_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muArray3DCreate, muArrayCreate, muArrayDestroy, muArrayGetDescriptor, muMemAlloc, muMemAllocHost, muMemAllocPitch, muMemcpy2D, muMemcpy2DAsync, muMemcpy2DUnaligned, muMemcpy3D, muMemcpy3DAsync, muMemcpyAtoA, muMemcpyAtoD, muMemcpyAtoH, muMemcpyAtoHAsync, muMemcpyDtoA, muMemcpyDtoD, muMemcpyDtoDAsync, muMemcpyDtoH, muMemcpyDtoHAsync, muMemcpyHtoA, muMemcpyHtoAAsync, muMemcpyHtoD, muMemcpyHtoDAsync, muMemFree, muMemFreeHost, muMemGetAddressRange, muMemGetInfo, muMemHostAlloc, muMemHostGetDevicePointer, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32, muMemsetD8, muMemsetD16, muMemsetD32, musaArrayGetInfo
muMipmappedArrayCreate
MUresult muMipmappedArrayCreate(MUmipmappedArray *pHandle, const MUSA_ARRAY3D_DESCRIPTOR *pMipmappedArrayDesc, unsigned int numMipmapLevels)
Description
- Creates a MUSA mipmapped array.
- Creates a MUSA mipmapped array according to the MUSA_ARRAY3D_DESCRIPTOR structure pMipmappedArrayDesc and returns a handle to the new MUSA mipmapped array in *pHandle. numMipmapLevels specifies the number of mipmap levels to be allocated. This value is clamped to the range [1, 1 + floor(log2(max(width, height, depth)))].
- The MUSA_ARRAY3D_DESCRIPTOR is defined as:
typedef struct {
unsigned int Width;
unsigned int Height;
unsigned int Depth;
MUarray_format Format;
unsigned int NumChannels;
unsigned int Flags;
} MUSA_ARRAY3D_DESCRIPTOR;
- where:
- Width, Height, and Depth are the width, height, and depth of the MUSA array (in elements); the following types of MUSA arrays can be allocated: A 1D mipmapped array is allocated if Height and Depth extents are both zero. A 2D mipmapped array is allocated if only Depth extent is zero. A 3D mipmapped array is allocated if all three extents are non-zero. A 1D layered MUSA mipmapped array is allocated if only Height is zero and the MUSA_ARRAY3D_LAYERED flag is set. Each layer is a 1D array. The number of layers is determined by the depth extent. A 2D layered MUSA mipmapped array is allocated if all three extents are non-zero and the MUSA_ARRAY3D_LAYERED flag is set. Each layer is a 2D array. The number of layers is determined by the depth extent. A cubemap MUSA mipmapped array is allocated if all three extents are non-zero and the MUSA_ARRAY3D_CUBEMAP flag is set. Width must be equal to Height, and Depth must be six. A cubemap is a special type of 2D layered MUSA array, where the six layers represent the six faces of a cube. The order of the six layers in memory is the same as that listed in MUarray_cubemap_face. A cubemap layered MUSA mipmapped array is allocated if all three extents are non-zero, and both, MUSA_ARRAY3D_CUBEMAP and MUSA_ARRAY3D_LAYERED flags are set. Width must be equal to Height, and Depth must be a multiple of six. A cubemap layered MUSA array is a special type of 2D layered MUSA array that consists of a collection of cubemaps. The first six layers represent the first cubemap, the next six layers form the second cubemap, and so on. Format specifies the format of the elements; MUarray_format is defined as:
typedef enum MUarray_format_enum {
MU_AD_FORMAT_UNSIGNED_INT8 = 0x01,
MU_AD_FORMAT_UNSIGNED_INT16 = 0x02,
MU_AD_FORMAT_UNSIGNED_INT32 = 0x03,
MU_AD_FORMAT_SIGNED_INT8 = 0x08,
MU_AD_FORMAT_SIGNED_INT16 = 0x09,
MU_AD_FORMAT_SIGNED_INT32 = 0x0a,
MU_AD_FORMAT_HALF = 0x10,
MU_AD_FORMAT_FLOAT = 0x20,
MU_AD_FORMAT_NV12 = 0xb0,
MU_AD_FORMAT_UNORM_INT8X1 = 0xc0,
MU_AD_FORMAT_UNORM_INT8X2 = 0xc1,
MU_AD_FORMAT_UNORM_INT8X4 = 0xc2,
MU_AD_FORMAT_UNORM_INT16X1 = 0xc3,
MU_AD_FORMAT_UNORM_INT16X2 = 0xc4,
MU_AD_FORMAT_UNORM_INT16X4 = 0xc5,
MU_AD_FORMAT_SNORM_INT8X1 = 0xc6,
MU_AD_FORMAT_SNORM_INT8X2 = 0xc7,
MU_AD_FORMAT_SNORM_INT8X4 = 0xc8,
MU_AD_FORMAT_SNORM_INT16X1 = 0xc9,
MU_AD_FORMAT_SNORM_INT16X2 = 0xca,
MU_AD_FORMAT_SNORM_INT16X4 = 0xcb,
MU_AD_FORMAT_BC1_UNORM = 0x91,
MU_AD_FORMAT_BC1_UNORM_SRGB = 0x92,
MU_AD_FORMAT_BC2_UNORM = 0x93,
MU_AD_FORMAT_BC2_UNORM_SRGB = 0x94,
MU_AD_FORMAT_BC3_UNORM = 0x95,
MU_AD_FORMAT_BC3_UNORM_SRGB = 0x96,
MU_AD_FORMAT_BC4_UNORM = 0x97,
MU_AD_FORMAT_BC4_SNORM = 0x98,
MU_AD_FORMAT_BC5_UNORM = 0x99,
MU_AD_FORMAT_BC5_SNORM = 0x9a,
MU_AD_FORMAT_BC6H_UF16 = 0x9b,
MU_AD_FORMAT_BC6H_SF16 = 0x9c,
MU_AD_FORMAT_BC7_UNORM = 0x9d,
MU_AD_FORMAT_BC7_UNORM_SRGB = 0x9e,
MU_AD_FORMAT_P010 = 0x9f,
MU_AD_FORMAT_P016 = 0xa1,
MU_AD_FORMAT_NV16 = 0xa2,
MU_AD_FORMAT_P210 = 0xa3,
MU_AD_FORMAT_P216 = 0xa4,
MU_AD_FORMAT_YUY2 = 0xa5,
MU_AD_FORMAT_Y210 = 0xa6,
MU_AD_FORMAT_Y216 = 0xa7,
MU_AD_FORMAT_AYUV = 0xa8,
MU_AD_FORMAT_Y410 = 0xa9,
MU_AD_FORMAT_Y416 = 0xb1,
MU_AD_FORMAT_Y444_PLANAR8 = 0xb2,
MU_AD_FORMAT_Y444_PLANAR10 = 0xb3,
MU_AD_FORMAT_YUV444_8bit_SemiPlanar = 0xb4,
MU_AD_FORMAT_YUV444_16bit_SemiPlanar = 0xb5,
MU_AD_FORMAT_UNORM_INT_101010_2 = 0x50,
MU_AD_FORMAT_UINT8_PACKED_422 = 0x51,
MU_AD_FORMAT_UINT8_PACKED_444 = 0x52,
MU_AD_FORMAT_UINT8_SEMIPLANAR_420 = 0x53,
MU_AD_FORMAT_UINT16_SEMIPLANAR_420 = 0x54,
MU_AD_FORMAT_UINT8_SEMIPLANAR_422 = 0x55,
MU_AD_FORMAT_UINT16_SEMIPLANAR_422 = 0x56,
MU_AD_FORMAT_UINT8_SEMIPLANAR_444 = 0x57,
MU_AD_FORMAT_UINT16_SEMIPLANAR_444 = 0x58,
MU_AD_FORMAT_UINT8_PLANAR_420 = 0x59,
MU_AD_FORMAT_UINT16_PLANAR_420 = 0x5a,
MU_AD_FORMAT_UINT8_PLANAR_422 = 0x5b,
MU_AD_FORMAT_UINT16_PLANAR_422 = 0x5c,
MU_AD_FORMAT_UINT8_PLANAR_444 = 0x5d,
MU_AD_FORMAT_UINT16_PLANAR_444 = 0x5e,
} MUarray_format;
- NumChannels specifies the number of packed components per MUSA array element; it may be 1, 2, or 4; Flags may be set to MUSA_ARRAY3D_LAYERED to enable creation of layered MUSA mipmapped arrays. If this flag is set, Depth specifies the number of layers, not the depth of a 3D array. MUSA_ARRAY3D_SURFACE_LDST to enable surface references to be bound to individual mipmap levels of the MUSA mipmapped array. If this flag is not set, muSurfRefSetArray will fail when attempting to bind a mipmap level of the MUSA mipmapped array to a surface reference. MUSA_ARRAY3D_CUBEMAP to enable creation of mipmapped cubemaps. If this flag is set, Width must be equal to Height, and Depth must be six. If the MUSA_ARRAY3D_LAYERED flag is also set, then Depth must be a multiple of six. MUSA_ARRAY3D_TEXTURE_GATHER to indicate that the MUSA mipmapped array will be used for texture gather. Texture gather can only be performed on 2D MUSA mipmapped arrays.
- Width, Height and Depth must meet certain size requirements as listed in the following table. All values are specified in elements. Note that for brevity's sake, the full name of the device attribute is not specified. For ex., TEXTURE1D_MIPMAPPED_WIDTH refers to the device attribute MU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_MIPMAPPED_WIDTH.
- MUSA array type Valid extents that must always be met {(width range in elements), (height range), (depth range)} Valid extents with MUSA_ARRAY3D_SURFACE_LDST set {(width range in elements), (height range), (depth range)} 1D { (1,TEXTURE1D_MIPMAPPED_WIDTH), 0, 0 } { (1,SURFACE1D_WIDTH), 0, 0 } 2D { (1,TEXTURE2D_MIPMAPPED_WIDTH), (1,TEXTURE2D_MIPMAPPED_HEIGHT), 0 } { (1,SURFACE2D_WIDTH), (1,SURFACE2D_HEIGHT), 0 } 3D { (1,TEXTURE3D_WIDTH), (1,TEXTURE3D_HEIGHT), (1,TEXTURE3D_DEPTH) } OR { (1,TEXTURE3D_WIDTH_ALTERNATE), (1,TEXTURE3D_HEIGHT_ALTERNATE), (1,TEXTURE3D_DEPTH_ALTERNATE) } { (1,SURFACE3D_WIDTH), (1,SURFACE3D_HEIGHT), (1,SURFACE3D_DEPTH) } 1D Layered { (1,TEXTURE1D_LAYERED_WIDTH), 0, (1,TEXTURE1D_LAYERED_LAYERS) } { (1,SURFACE1D_LAYERED_WIDTH), 0, (1,SURFACE1D_LAYERED_LAYERS) } 2D Layered { (1,TEXTURE2D_LAYERED_WIDTH), (1,TEXTURE2D_LAYERED_HEIGHT), (1,TEXTURE2D_LAYERED_LAYERS) } { (1,SURFACE2D_LAYERED_WIDTH), (1,SURFACE2D_LAYERED_HEIGHT), (1,SURFACE2D_LAYERED_LAYERS) } Cubemap { (1,TEXTURECUBEMAP_WIDTH), (1,TEXTURECUBEMAP_WIDTH), 6 } { (1,SURFACECUBEMAP_WIDTH), (1,SURFACECUBEMAP_WIDTH), 6 } Cubemap Layered { (1,TEXTURECUBEMAP_LAYERED_WIDTH), (1,TEXTURECUBEMAP_LAYERED_WIDTH), (1,TEXTURECUBEMAP_LAYERED_LAYERS) } { (1,SURFACECUBEMAP_LAYERED_WIDTH), (1,SURFACECUBEMAP_LAYERED_WIDTH), (1,SURFACECUBEMAP_LAYERED_LAYERS) }
Parameters
pHandle(MUmipmappedArray *): Returned mipmapped arraypMipmappedArrayDesc(const MUSA_ARRAY3D_DESCRIPTOR *): mipmapped array descriptornumMipmapLevels(unsigned int): Number of mipmap levels
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_UNKNOWN
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muMipmappedArrayGetLevel
MUresult muMipmappedArrayGetLevel(MUarray *pLevelArray, MUmipmappedArray hMipmappedArray, unsigned int level)
Description
- Gets a mipmap level of a MUSA mipmapped array.
- Returns in *pLevelArray a MUSA array that represents a single mipmap level of the MUSA mipmapped array hMipmappedArray.
- If level is greater than the maximum number of levels in this mipmapped array, MUSA_ERROR_INVALID_VALUE is returned.
Parameters
pLevelArray(MUarray *): Returned mipmap level MUSA arrayhMipmappedArray(MUmipmappedArray): MUSA mipmapped arraylevel(unsigned int): Mipmap level
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muMipmappedArrayDestroy
MUresult muMipmappedArrayDestroy(MUmipmappedArray hMipmappedArray)
Description
- Destroys a MUSA mipmapped array.
- Destroys the MUSA mipmapped array hMipmappedArray.
Parameters
hMipmappedArray(MUmipmappedArray): Mipmapped array to destroy
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_ARRAY_IS_MAPPED, MUSA_ERROR_CONTEXT_IS_DESTROYED
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muMemGetHandleForAddressRange
MUresult muMemGetHandleForAddressRange(void *handle, MUdeviceptr dptr, size_t size, MUmemRangeHandleType handleType, unsigned long long flags)
Description
- Retrieve handle for an address range.
- Get a handle of the specified type to an address range. The address range must have been obtained by a prior call to either muMemAlloc or muMemAddressReserve. If the address range was obtained via muMemAddressReserve, it must also be fully mapped via muMemMap. The address range must have been obtained by a prior call to either muMemAllocHost or muMemHostAlloc on Tegra.
- Users must ensure the dptr and size are aligned to the host page size.
- When requesting MUmemRangeHandleType::MU_MEM_RANGE_HANDLE_TYPE_DMA_BUF_FD, users are expected to query for dma_buf support for the platform by using MU_DEVICE_ATTRIBUTE_DMA_BUF_SUPPORTED device attribute before calling this API. The handle will be interpreted as a pointer to an integer to store the dma_buf file descriptor. Users must ensure the entire address range is backed and mapped when the address range is allocated by muMemAddressReserve. All the physical allocations backing the address range must be resident on the same device and have identical allocation properties. Users are also expected to retrieve a new handle every time the underlying physical allocation(s) corresponding to a previously queried VA range are changed.
- For MUmemRangeHandleType::MU_MEM_RANGE_HANDLE_TYPE_DMA_BUF_FD, users may set flags to MU_MEM_RANGE_FLAG_DMA_BUF_MAPPING_TYPE_PCIE. Which when set on a supported platform, will give a DMA_BUF handle mapped via PCIE BAR1 or will return an error otherwise.
Parameters
handle(void *): Pointer to the location where the returned handle will be stored.dptr(MUdeviceptr): Pointer to a valid MUSA device allocation. Must be aligned to host page size.size(size_t): Length of the address range. Must be aligned to host page size.handleType(MUmemRangeHandleType): Type of handle requested (defines type and size of the handle output parameter)flags(unsigned long long): When requesting MUmemRangeHandleType::MU_MEM_RANGE_HANDLE_TYPE_DMA_BUF_FD the value could be MU_MEM_RANGE_FLAG_DMA_BUF_MAPPING_TYPE_PCIE, otherwise 0.
Returns
- MUSA_SUCCESS MUSA_ERROR_INVALID_VALUE MUSA_ERROR_NOT_SUPPORTED
muMemoryTransfer
MUresult muMemoryTransfer(MUdeviceptr dst, MUdeviceptr src, size_t ByteCount)
Description
- Copies memory from Device to Device by transfer engine.
- Copies from device memory to device memory. dst and src are the base pointers of the destination and source, respectively. ByteCount specifies the number of bytes to copy.
Parameters
dst(MUdeviceptr): Destination device pointersrc(MUdeviceptr): Source device pointerByteCount(size_t): Size of memory copy in bytes
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muMemoryTransfer_ptds. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for synchronization behavior.
See also
muMemoryTransferAsync
MUresult muMemoryTransferAsync(MUdeviceptr dst, MUdeviceptr src, size_t ByteCount, MUstream hStream)
Description
- Copies memory from Device to Device by transfer engine asynchronously.
- Copies from device memory to device memory. dst and src are the base pointers of the destination and source, respectively. ByteCount specifies the number of bytes to copy.
Parameters
dst(MUdeviceptr): Destination device pointersrc(MUdeviceptr): Source device pointerByteCount(size_t): Size of memory copy in byteshStream(MUstream): Stream identifier
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muMemoryTransferAsync_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
3.13 Virtual Memory Management
muMemAddressReserve
MUresult muMemAddressReserve(MUdeviceptr *ptr, size_t size, size_t alignment, MUdeviceptr addr, unsigned long long flags)
Description
- Allocate an address range reservation.
- Reserves a virtual address range based on the given parameters, giving the starting address of the range in ptr. This API requires a system that supports UVA. The size and address parameters must be a multiple of the host page size and the alignment must be a power of two or zero for default alignment.
Parameters
ptr(MUdeviceptr *): Resulting pointer to start of virtual address range allocatedsize(size_t): Size of the reserved virtual address range requestedalignment(size_t): Alignment of the reserved virtual address range requestedaddr(MUdeviceptr): Fixed starting address range requestedflags(unsigned long long): Currently unused, must be zero
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_PERMITTED, MUSA_ERROR_NOT_SUPPORTED
See also
muMemAddressFree
MUresult muMemAddressFree(MUdeviceptr ptr, size_t size)
Description
- Free an address range reservation.
- Frees a virtual address range reserved by muMemAddressReserve. The size must match what was given to memAddressReserve and the ptr given must match what was returned from memAddressReserve.
Parameters
ptr(MUdeviceptr): Starting address of the virtual address range to freesize(size_t): Size of the virtual address region to free
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_PERMITTED, MUSA_ERROR_NOT_SUPPORTED
See also
muMemCreate
MUresult muMemCreate(MUmemGenericAllocationHandle *handle, size_t size, const MUmemAllocationProp *prop, unsigned long long flags)
Description
- Create a MUSA memory handle representing a memory allocation of a given size described by the given properties.
- This creates a memory allocation on the target device specified through the prop structure. The created allocation will not have any device or host mappings. The generic memory handle for the allocation can be mapped to the address space of calling process via muMemMap. This handle cannot be transmitted directly to other processes (see muMemExportToShareableHandle). On Windows, the caller must also pass an LPSECURITYATTRIBUTE in prop to be associated with this handle which limits or allows access to this handle for a recipient process (see MUmemAllocationProp::win32HandleMetaData for more). The size of this allocation must be a multiple of the the value given via muMemGetAllocationGranularity with the MU_MEM_ALLOC_GRANULARITY_MINIMUM flag. To create a CPU allocation that doesn't target any specific NUMA nodes, applications must set MUmemAllocationProp::MUmemLocation::type to MU_MEM_LOCATION_TYPE_HOST. MUmemAllocationProp::MUmemLocation::id is ignored for HOST allocations. HOST allocations are not IPC capable and MUmemAllocationProp::requestedHandleTypes must be 0, any other value will result in MUSA_ERROR_INVALID_VALUE. To create a CPU allocation targeting a specific host NUMA node, applications must set MUmemAllocationProp::MUmemLocation::type to MU_MEM_LOCATION_TYPE_HOST_NUMA and MUmemAllocationProp::MUmemLocation::id must specify the NUMA ID of the CPU. On systems where NUMA is not available MUmemAllocationProp::MUmemLocation::id must be set to 0. Specifying MU_MEM_LOCATION_TYPE_HOST_NUMA_CURRENT or MU_MEM_LOCATION_TYPE_HOST as the MUmemLocation::type will result in MUSA_ERROR_INVALID_VALUE.
- Applications that intend to use MU_MEM_HANDLE_TYPE_FABRIC based memory sharing must ensure: (1) mthreads-caps-imex-channels character device is created by the driver and is listed under /proc/devices (2) have at least one IMEX channel file accessible by the user launching the application.
- When exporter and importer MUSA processes have been granted access to the same IMEX channel, they can securely share memory.
- The IMEX channel security model works on a per user basis. Which means all processes under a user can share memory if the user has access to a valid IMEX channel. When multi-user isolation is desired, a separate IMEX channel is required for each user.
- These channel files exist in /dev/mthreads-caps-imex-channels/channel* and can be created using standard OS native calls like mknod on Linux. For example: To create channel0 with the major number from /proc/devices users can execute the following command:
mknod /dev/mthreads-caps-imex-channels/channel0 c <major number> 0 - If MUmemAllocationProp::allocFlags::usage contains MU_MEM_CREATE_USAGE_TILE_POOL flag then the memory allocation is intended only to be used as backing tile pool for sparse MUSA arrays and sparse MUSA mipmapped arrays. (see muMemMapArrayAsync).
Parameters
handle(MUmemGenericAllocationHandle *): Value of handle returned. All operations on this allocation are to be performed using this handle.size(size_t): Size of the allocation requestedprop(const MUmemAllocationProp *): Properties of the allocation to create.flags(unsigned long long): flags for future use, must be zero now.
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_PERMITTED, MUSA_ERROR_NOT_SUPPORTED
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muMemRelease
MUresult muMemRelease(MUmemGenericAllocationHandle handle)
Description
- Release a memory handle representing a memory allocation which was previously allocated through muMemCreate.
- Frees the memory that was allocated on a device through muMemCreate.
- The memory allocation will be freed when all outstanding mappings to the memory are unmapped and when all outstanding references to the handle (including it's shareable counterparts) are also released. The generic memory handle can be freed when there are still outstanding mappings made with this handle. Each time a recipient process imports a shareable handle, it needs to pair it with muMemRelease for the handle to be freed. If handle is not a valid handle the behavior is undefined.
Parameters
handle(MUmemGenericAllocationHandle): Value of handle which was returned previously by muMemCreate.
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_PERMITTED, MUSA_ERROR_NOT_SUPPORTED
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muMemMap
MUresult muMemMap(MUdeviceptr ptr, size_t size, size_t offset, MUmemGenericAllocationHandle handle, unsigned long long flags)
Description
- Maps an allocation handle to a reserved virtual address range.
- Maps bytes of memory represented by handle starting from byte offset to size to address range [addr, addr + size]. This range must be an address reservation previously reserved with muMemAddressReserve, and offset + size must be less than the size of the memory allocation. Both ptr, size, and offset must be a multiple of the value given via muMemGetAllocationGranularity with the MU_MEM_ALLOC_GRANULARITY_MINIMUM flag. If handle represents a multicast object, ptr, size and offset must be aligned to the value returned by muMulticastGetGranularity with the flag MU_MULTICAST_MINIMUM_GRANULARITY. For best performance however, it is recommended that ptr, size and offset be aligned to the value returned by muMulticastGetGranularity with the flag MU_MULTICAST_RECOMMENDED_GRANULARITY.
- When handle represents a multicast object, this call may return MUSA_ERROR_ILLEGAL_STATE if the system configuration is in an illegal state. In such cases, to continue using multicast, verify that the system configuration is in a valid state and all required driver daemons are running properly.
- Please note calling muMemMap does not make the address accessible, the caller needs to update accessibility of a contiguous mapped VA range by calling muMemSetAccess.
- Once a recipient process obtains a shareable memory handle from muMemImportFromShareableHandle, the process must use muMemMap to map the memory into its address ranges before setting accessibility with muMemSetAccess.
- muMemMap can only create mappings on VA range reservations that are not currently mapped.
Parameters
ptr(MUdeviceptr): Address where memory will be mapped.size(size_t): Size of the memory mapping.offset(size_t): Offset into the memory represented by handle from which to start mapping Note: currently must be zero. handle from which to start mapping Note: currently must be zero.handle(MUmemGenericAllocationHandle): Handle to a shareable memoryflags(unsigned long long): flags for future use, must be zero now.
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_PERMITTED, MUSA_ERROR_NOT_SUPPORTED, MUSA_ERROR_ILLEGAL_STATE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muMemUnmap
MUresult muMemUnmap(MUdeviceptr ptr, size_t size)
Description
- Maps or unmaps subregions of sparse MUSA arrays and sparse MUSA mipmapped arrays.
- Performs map or unmap operations on subregions of sparse MUSA arrays and sparse MUSA mipmapped arrays. Each operation is specified by a MUarrayMapInfo entry in the mapInfoList array of size count. The structure MUarrayMapInfo is defined as follow:
typedef struct MUarray MapInfo_st {
MUresourcetype resourceType;
union {
MUmipmappedArray mipmap;
MUarray array;
} resource;
MUarray SparseSubresourceTypesubresourceType;
union {
struct {
unsigned int level;
unsigned int layer;
unsigned int offsetX;
unsigned int offsetY;
unsigned int offsetZ;
unsigned int extentWidth;
unsigned int extentHeight;
unsigned int extentDepth;
} sparseLevel;
struct {
unsigned int layer;
unsigned long long offset;
unsigned long long size;
} miptail;
} subresource;
MUmemOperationTypememOperationType;
MUmemHandleTypememHandleType;
union {
MUmemGenericAllocationHandlememHandle;
} memHandle;
unsigned long long offset;
unsigned int deviceBitMask;
unsigned int flags;
unsigned int reserved[2];
} MUarray MapInfo;
- where MUarrayMapInfo::resourceType specifies the type of resource to be operated on. If MUarrayMapInfo::resourceType is set to MUresourcetype::MU_RESOURCE_TYPE_ARRAY then MUarrayMapInfo::resource::array must be set to a valid sparse MUSA array handle. The MUSA array must be either a 2D, 2D layered or 3D MUSA array and must have been allocated using muArrayCreate or muArray3DCreate with the flag MUSA_ARRAY3D_SPARSE or MUSA_ARRAY3D_DEFERRED_MAPPING. For MUSA arrays obtained using muMipmappedArrayGetLevel, MUSA_ERROR_INVALID_VALUE will be returned. If MUarrayMapInfo::resourceType is set to MUresourcetype::MU_RESOURCE_TYPE_MIPMAPPED_ARRAY then MUarrayMapInfo::resource::mipmap must be set to a valid sparse MUSA mipmapped array handle. The MUSA mipmapped array must be either a 2D, 2D layered or 3D MUSA mipmapped array and must have been allocated using muMipmappedArrayCreate with the flag MUSA_ARRAY3D_SPARSE or MUSA_ARRAY3D_DEFERRED_MAPPING.
- MUarrayMapInfo::subresourceType specifies the type of subresource within the resource. MUarraySparseSubresourceType_enum is defined as:
typedef enum MUarray SparseSubresourceType_enum {
MU_ARRAY_SPARSE_SUBRESOURCE_TYPE_SPARSE_LEVEL = 0,
MU_ARRAY_SPARSE_SUBRESOURCE_TYPE_MIPTAIL = 1;
} MUarray SparseSubresourceType;
- where MUarraySparseSubresourceType::MU_ARRAY_SPARSE_SUBRESOURCE_TYPE_SPARSE_LEVEL indicates a sparse-miplevel which spans at least one tile in every dimension. The remaining miplevels which are too small to span at least one tile in any dimension constitute the mip tail region as indicated by MUarraySparseSubresourceType::MU_ARRAY_SPARSE_SUBRESOURCE_TYPE_MIPTAIL subresource type.
- If MUarrayMapInfo::subresourceType is set to MUarraySparseSubresourceType::MU_ARRAY_SPARSE_SUBRESOURCE_TYPE_SPARSE_LEVEL then MUarrayMapInfo::subresource::sparseLevel struct must contain valid array subregion offsets and extents. The MUarrayMapInfo::subresource::sparseLevel::offsetX, MUarrayMapInfo::subresource::sparseLevel::offsetY and MUarrayMapInfo::subresource::sparseLevel::offsetZ must specify valid X, Y and Z offsets respectively. The MUarrayMapInfo::subresource::sparseLevel::extentWidth, MUarrayMapInfo::subresource::sparseLevel::extentHeight and MUarrayMapInfo::subresource::sparseLevel::extentDepth must specify valid width, height and depth extents respectively. These offsets and extents must be aligned to the corresponding tile dimension. For MUSA mipmapped arrays MUarrayMapInfo::subresource::sparseLevel::level must specify a valid mip level index. Otherwise, must be zero. For layered MUSA arrays and layered MUSA mipmapped arrays MUarrayMapInfo::subresource::sparseLevel::layer must specify a valid layer index. Otherwise, must be zero. MUarrayMapInfo::subresource::sparseLevel::offsetZ must be zero and MUarrayMapInfo::subresource::sparseLevel::extentDepth must be set to 1 for 2D and 2D layered MUSA arrays and MUSA mipmapped arrays. Tile extents can be obtained by calling muArrayGetSparseProperties and muMipmappedArrayGetSparseProperties
- If MUarrayMapInfo::subresourceType is set to MUarraySparseSubresourceType::MU_ARRAY_SPARSE_SUBRESOURCE_TYPE_MIPTAIL then MUarrayMapInfo::subresource::miptail struct must contain valid mip tail offset in MUarrayMapInfo::subresource::miptail::offset and size in MUarrayMapInfo::subresource::miptail::size. Both, mip tail offset and mip tail size must be aligned to the tile size. For layered MUSA mipmapped arrays which don't have the flag MU_ARRAY_SPARSE_PROPERTIES_SINGLE_MIPTAIL set in MUSA_ARRAY_SPARSE_PROPERTIES::flags as returned by muMipmappedArrayGetSparseProperties, MUarrayMapInfo::subresource::miptail::layer must specify a valid layer index. Otherwise, must be zero.
- If MUarrayMapInfo::resource::array or MUarrayMapInfo::resource::mipmap was created with MUSA_ARRAY3D_DEFERRED_MAPPING flag set the MUarrayMapInfo::subresourceType and the contents of MUarrayMapInfo::subresource will be ignored.
- MUarrayMapInfo::memOperationType specifies the type of operation. MUmemOperationType is defined as:
typedef enum MUmemOperationType_enum {
MU_MEM_OPERATION_TYPE_MAP = 1,
MU_MEM_OPERATION_TYPE_UNMAP = 2;
} MUmemOperationType;
- If MUarrayMapInfo::memOperationType is set to MUmemOperationType::MU_MEM_OPERATION_TYPE_MAP then the subresource will be mapped onto the tile pool memory specified by MUarrayMapInfo::memHandle at offset MUarrayMapInfo::offset. The tile pool allocation has to be created by specifying the MU_MEM_CREATE_USAGE_TILE_POOL flag when calling muMemCreate. Also, MUarrayMapInfo::memHandleType must be set to MUmemHandleType::MU_MEM_HANDLE_TYPE_GENERIC.
- If MUarrayMapInfo::memOperationType is set to MUmemOperationType::MU_MEM_OPERATION_TYPE_UNMAP then an unmapping operation is performed. MUarrayMapInfo::memHandle must be NULL.
- MUarrayMapInfo::deviceBitMask specifies the list of devices that must map or unmap physical memory. Currently, this mask must have exactly one bit set, and the corresponding device must match the device associated with the stream. If MUarrayMapInfo::memOperationType is set to MUmemOperationType::MU_MEM_OPERATION_TYPE_MAP, the device must also match the device associated with the tile pool memory allocation as specified by MUarrayMapInfo::memHandle.
- MUarrayMapInfo::flags and MUarrayMapInfo::reserved[] are unused and must be set to zero.
- The range must be the entire contiguous address range that was mapped to. In other words, muMemUnmap cannot unmap a sub-range of an address range mapped by muMemCreate / muMemMap. Any backing memory allocations will be freed if there are no existing mappings and there are no unreleased memory handles.
- When muMemUnmap returns successfully the address range is converted to an address reservation and can be used for a future calls to muMemMap. Any new mapping to this virtual address will need to have access granted through muMemSetAccess, as all mappings start with no accessibility setup.
Parameters
ptr(MUdeviceptr): Starting address for the virtual address range to unmapsize(size_t): Size of the virtual address range to unmap
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_PERMITTED, MUSA_ERROR_NOT_SUPPORTED
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for synchronization behavior.
See also
- muMipmappedArrayCreate, muArrayCreate, muArray3DCreate, muMemCreate, muArrayGetSparseProperties, muMipmappedArrayGetSparseProperties
- muMemCreate, muMemAddressReserve
muMemSetAccess
MUresult muMemSetAccess(MUdeviceptr ptr, size_t size, const MUmemAccessDesc *desc, size_t count)
Description
- Set the access flags for each location specified in desc for the given virtual address range.
- Given the virtual address range via ptr and size, and the locations in the array given by desc and count, set the access flags for the target locations. The range must be a fully mapped address range containing all allocations created by muMemMap / muMemCreate. Users cannot specify MU_MEM_LOCATION_TYPE_HOST_NUMA accessibility for allocations created on with other location types. Note: When MUmemAccessDesc::MUmemLocation::type is MU_MEM_LOCATION_TYPE_HOST_NUMA, MUmemAccessDesc::MUmemLocation::id is ignored. When setting the access flags for a virtual address range mapping a multicast object, ptr and size must be aligned to the value returned by muMulticastGetGranularity with the flag MU_MULTICAST_MINIMUM_GRANULARITY. For best performance however, it is recommended that ptr and size be aligned to the value returned by muMulticastGetGranularity with the flag MU_MULTICAST_RECOMMENDED_GRANULARITY.
Parameters
ptr(MUdeviceptr): Starting address for the virtual address rangesize(size_t): Length of the virtual address rangedesc(const MUmemAccessDesc *): Array of MUmemAccessDesc that describe how to change the mapping for each location specified mapping for each location specifiedcount(size_t): Number of MUmemAccessDesc in desc
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_NOT_SUPPORTED
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for synchronization behavior.
See also
muMemGetAccess
MUresult muMemGetAccess(unsigned long long *flags, const MUmemLocation *location, MUdeviceptr ptr)
Description
- Get the access flags set for the given location and ptr.
Parameters
flags(unsigned long long *): Flags set for this locationlocation(const MUmemLocation *): Location in which to check the flags forptr(MUdeviceptr): Address in which to check the access flags for
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_PERMITTED, MUSA_ERROR_NOT_SUPPORTED
See also
muMemExportToShareableHandle
MUresult muMemExportToShareableHandle(void *shareableHandle, MUmemGenericAllocationHandle handle, MUmemAllocationHandleType handleType, unsigned long long flags)
Description
- Exports an allocation to a requested shareable handle type.
- Given a MUSA memory handle, create a shareable memory allocation handle that can be used to share the memory with other processes. The recipient process can convert the shareable handle back into a MUSA memory handle using muMemImportFromShareableHandle and map it with muMemMap. The implementation of what this handle is and how it can be transferred is defined by the requested handle type in handleType
- Once all shareable handles are closed and the allocation is released, the allocated memory referenced will be released back to the OS and uses of the MUSA handle afterward will lead to undefined behavior.
- This API can also be used in conjunction with other APIs (e.g. Vulkan, OpenGL) that support importing memory from the shareable type
Parameters
shareableHandle(void *): Pointer to the location in which to store the requested handle typehandle(MUmemGenericAllocationHandle): MUSA handle for the memory allocationhandleType(MUmemAllocationHandleType): Type of shareable handle requested (defines type and size of the shareableHandle output parameter)flags(unsigned long long): Reserved, must be zero
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_PERMITTED, MUSA_ERROR_NOT_SUPPORTED
See also
muMemImportFromShareableHandle
MUresult muMemImportFromShareableHandle(MUmemGenericAllocationHandle *handle, void *osHandle, MUmemAllocationHandleType shHandleType)
Description
- Imports an allocation from a requested shareable handle type.
- If the current process cannot support the memory described by this shareable handle, this API will error as MUSA_ERROR_NOT_SUPPORTED.
- If shHandleType is MU_MEM_HANDLE_TYPE_FABRIC and the importer process has not been granted access to the same IMEX channel as the exporter process, this API will error as MUSA_ERROR_NOT_PERMITTED.
Parameters
handle(MUmemGenericAllocationHandle *): MUSA Memory handle for the memory allocation.osHandle(void *): Shareable Handle representing the memory allocation that is to be imported.shHandleType(MUmemAllocationHandleType): handle type of the exported handle MUmemAllocationHandleType.
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_PERMITTED, MUSA_ERROR_NOT_SUPPORTED
Note
- Importing shareable handles exported from some graphics APIs(VUlkan, OpenGL, etc) created on devices under an SLI group may not be supported, and thus this API will return MUSA_ERROR_NOT_SUPPORTED. There is no guarantee that the contents of handle will be the same MUSA memory handle for the same given OS shareable handle, or the same underlying allocation.
See also
muMemGetAllocationGranularity
MUresult muMemGetAllocationGranularity(size_t *granularity, const MUmemAllocationProp *prop, MUmemAllocationGranularity_flags option)
Description
- Calculates either the minimal or recommended granularity.
- Calculates either the minimal or recommended granularity for a given allocation specification and returns it in granularity. This granularity can be used as a multiple for alignment, size, or address mapping.
Parameters
granularity(size_t *): Returned granularity.prop(const MUmemAllocationProp *): Property for which to determine the granularity foroption(MUmemAllocationGranularity_flags): Determines which granularity to return
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_PERMITTED, MUSA_ERROR_NOT_SUPPORTED
See also
muMemGetAllocationPropertiesFromHandle
MUresult muMemGetAllocationPropertiesFromHandle(MUmemAllocationProp *prop, MUmemGenericAllocationHandle handle)
Description
- Retrieve the contents of the property structure defining properties for this handle.
Parameters
prop(MUmemAllocationProp *): Pointer to a properties structure which will hold the information about this handlehandle(MUmemGenericAllocationHandle): Handle which to perform the query on
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_PERMITTED, MUSA_ERROR_NOT_SUPPORTED
See also
muMemRetainAllocationHandle
MUresult muMemRetainAllocationHandle(MUmemGenericAllocationHandle *handle, void *addr)
Description
- Given an address addr, returns the allocation handle of the backing memory allocation.
- The handle is guaranteed to be the same handle value used to map the memory. If the address requested is not mapped, the function will fail. The returned handle must be released with corresponding number of calls to muMemRelease.
Parameters
handle(MUmemGenericAllocationHandle *): MUSA Memory handle for the backing memory allocation.addr(void *): Memory address to query, that has been mapped previously.
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_PERMITTED, MUSA_ERROR_NOT_SUPPORTED
Note
- The address addr, can be any address in a range previously mapped by muMemMap, and not necessarily the start address.
See also
3.14 Stream Ordered Memory Allocator
muMemFreeAsync
MUresult muMemFreeAsync(MUdeviceptr dptr, MUstream hStream)
Description
- Frees memory with stream ordered semantics.
- Inserts a free operation into hStream. The allocation must not be accessed after stream execution reaches the free. After this API returns, accessing the memory from any subsequent work launched on the GPU or querying its pointer attributes results in undefined behavior.
Parameters
dptr(MUdeviceptr): memory to freehStream(MUstream): The stream establishing the stream ordering contract.
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT (default stream specified with no current context), MUSA_ERROR_NOT_SUPPORTED
Note
- During stream capture, this function results in the creation of a free node and must therefore be passed the address of a graph allocation.
muMemAllocAsync
MUresult muMemAllocAsync(MUdeviceptr *dptr, size_t bytesize, MUstream hStream)
Description
- Allocates memory with stream ordered semantics.
- Inserts an allocation operation into hStream. A pointer to the allocated memory is returned immediately in *dptr. The allocation must not be accessed until the the allocation operation completes. The allocation comes from the memory pool current to the stream's device.
Parameters
dptr(MUdeviceptr *): Returned device pointerbytesize(size_t): Number of bytes to allocatehStream(MUstream): The stream establishing the stream ordering contract and the memory pool to allocate from
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT (default stream specified with no current context), MUSA_ERROR_NOT_SUPPORTED, MUSA_ERROR_OUT_OF_MEMORY
Note
- The default memory pool of a device contains device memory from that device.
- Basic stream ordering allows future work submitted into the same stream to use the allocation. Stream query, stream synchronize, and MUSA events can be used to guarantee that the allocation operation completes before work submitted in a separate stream runs.
- During stream capture, this function results in the creation of an allocation node. In this case, the allocation is owned by the graph instead of the memory pool. The memory pool's properties are used to set the node's creation parameters.
See also
- muMemAllocFromPoolAsync, muMemFreeAsync, muDeviceSetMemPool, muDeviceGetDefaultMemPool, muDeviceGetMemPool, muMemPoolCreate, muMemPoolSetAccess, muMemPoolSetAttribute
muMemPoolTrimTo
MUresult muMemPoolTrimTo(MUmemoryPool pool, size_t minBytesToKeep)
Description
- Tries to release memory back to the OS.
- Releases memory back to the OS until the pool contains fewer than minBytesToKeep reserved bytes, or there is no more memory that the allocator can safely release. The allocator cannot release OS allocations that back outstanding asynchronous allocations. The OS allocations may happen at different granularity from the user allocations.
Parameters
pool(MUmemoryPool): The memory pool to trimminBytesToKeep(size_t): If the pool has less than minBytesToKeep reserved, the TrimTo operation is a no-op. Otherwise the pool will be guaranteed to have at least minBytesToKeep bytes reserved after the operation.
Returns
- MUSA_SUCCESS, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE
Note
- : Allocations that have not been freed count as outstanding.
- : Allocations that have been asynchronously freed but whose completion has not been observed on the host (eg. by a synchronize) can count as outstanding.
See also
muMemPoolSetAttribute
MUresult muMemPoolSetAttribute(MUmemoryPool pool, MUmemPool_attribute attr, void *value)
Description
- Sets attributes of a memory pool.
- Supported attributes are: MU_MEMPOOL_ATTR_RELEASE_THRESHOLD: (value type = muuint64_t) Amount of reserved memory in bytes to hold onto before trying to release memory back to the OS. When more than the release threshold bytes of memory are held by the memory pool, the allocator will try to release memory back to the OS on the next call to stream, event or context synchronize. (default 0) MU_MEMPOOL_ATTR_REUSE_FOLLOW_EVENT_DEPENDENCIES: (value type = int) Allow muMemAllocAsync to use memory asynchronously freed in another stream as long as a stream ordering dependency of the allocating stream on the free action exists. Musa events and null stream interactions can create the required stream ordered dependencies. (default enabled) MU_MEMPOOL_ATTR_REUSE_ALLOW_OPPORTUNISTIC: (value type = int) Allow reuse of already completed frees when there is no dependency between the free and allocation. (default enabled) MU_MEMPOOL_ATTR_REUSE_ALLOW_INTERNAL_DEPENDENCIES: (value type = int) Allow muMemAllocAsync to insert new stream dependencies in order to establish the stream ordering required to reuse a piece of memory released by muMemFreeAsync (default enabled). MU_MEMPOOL_ATTR_RESERVED_MEM_HIGH: (value type = muuint64_t) Reset the high watermark that tracks the amount of backing memory that was allocated for the memory pool. It is illegal to set this attribute to a non-zero value. MU_MEMPOOL_ATTR_USED_MEM_HIGH: (value type = muuint64_t) Reset the high watermark that tracks the amount of used memory that was allocated for the memory pool.
Parameters
pool(MUmemoryPool): The memory pool to modifyattr(MUmemPool_attribute): The attribute to modifyvalue(void *): Pointer to the value to assign
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
See also
muMemPoolGetAttribute
MUresult muMemPoolGetAttribute(MUmemoryPool pool, MUmemPool_attribute attr, void *value)
Description
- Gets attributes of a memory pool.
- Supported attributes are: MU_MEMPOOL_ATTR_RELEASE_THRESHOLD: (value type = muuint64_t) Amount of reserved memory in bytes to hold onto before trying to release memory back to the OS. When more than the release threshold bytes of memory are held by the memory pool, the allocator will try to release memory back to the OS on the next call to stream, event or context synchronize. (default 0) MU_MEMPOOL_ATTR_REUSE_FOLLOW_EVENT_DEPENDENCIES: (value type = int) Allow muMemAllocAsync to use memory asynchronously freed in another stream as long as a stream ordering dependency of the allocating stream on the free action exists. Musa events and null stream interactions can create the required stream ordered dependencies. (default enabled) MU_MEMPOOL_ATTR_REUSE_ALLOW_OPPORTUNISTIC: (value type = int) Allow reuse of already completed frees when there is no dependency between the free and allocation. (default enabled) MU_MEMPOOL_ATTR_REUSE_ALLOW_INTERNAL_DEPENDENCIES: (value type = int) Allow muMemAllocAsync to insert new stream dependencies in order to establish the stream ordering required to reuse a piece of memory released by muMemFreeAsync (default enabled). MU_MEMPOOL_ATTR_RESERVED_MEM_CURRENT: (value type = muuint64_t) Amount of backing memory currently allocated for the mempool MU_MEMPOOL_ATTR_RESERVED_MEM_HIGH: (value type = muuint64_t) High watermark of backing memory allocated for the mempool since the last time it was reset. MU_MEMPOOL_ATTR_USED_MEM_CURRENT: (value type = muuint64_t) Amount of memory from the pool that is currently in use by the application. MU_MEMPOOL_ATTR_USED_MEM_HIGH: (value type = muuint64_t) High watermark of the amount of memory from the pool that was in use by the application.
- The following properties can be also be queried on imported and default pools: MU_MEMPOOL_ATTR_ALLOCATION_TYPE: (value type = MUmemAllocationType) The allocation type of the mempool MU_MEMPOOL_ATTR_EXPORT_HANDLE_TYPES: (value type = MUmemAllocationHandleType) Available export handle types for the mempool. For imported pools this value is always MU_MEM_HANDLE_TYPE_NONE as an imported pool cannot be re-exported MU_MEMPOOL_ATTR_LOCATION_ID: (value type = int) The location id for the mempool. If the location type for this pool is MU_MEM_LOCATION_TYPE_INVISIBLE then ID will be MU_DEVICE_INVALID. MU_MEMPOOL_ATTR_LOCATION_TYPE: (value type = MUmemLocationType) The location type for the mempool. For imported memory pools where the device is not directly visible to the importing process or pools imported via fabric handles across nodes this will be MU_MEM_LOCATION_TYPE_INVISIBLE. MU_MEMPOOL_ATTR_MAX_POOL_SIZE: (value type = muuint64_t) Maximum size of the pool in bytes, this value may be higher than what was initially passed to muMemPoolCreate due to alignment requirements. A value of 0 indicates no maximum size. For MU__MEM_ALLOCATION_TYPE_MANAGED and IPC imported pools this value will be system dependent. MU_MEMPOOL_ATTR_HW_DECOMPRESS_ENABLED: (value type = int) Indicates whether the pool has hardware compresssion enabled pool - The memory pool to get attributes of attr - The attribute to get value - Retrieved value MUSA_SUCCESS, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE muMemAllocAsync, muMemFreeAsync, muDeviceGetDefaultMemPool, muDeviceGetMemPool, muMemPoolCreate
Parameters
pool(MUmemoryPool): The memory pool to get attributes ofattr(MUmemPool_attribute): The attribute to getvalue(void *): Retrieved value
Returns
- MUSA_SUCCESS, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE
See also
muMemPoolSetAccess
MUresult muMemPoolSetAccess(MUmemoryPool pool, const MUmemAccessDesc *map, size_t count)
Description
- Controls visibility of pools between devices.
Parameters
pool(MUmemoryPool): The pool being modifiedmap(const MUmemAccessDesc *): Array of access descriptors. Each descriptor instructs the access to enable for a single gpu.count(size_t): Number of descriptors in the map array.
Returns
- MUSA_SUCCESS, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE
See also
muMemPoolGetAccess
MUresult muMemPoolGetAccess(MUmemAccess_flags *flags, MUmemoryPool memPool, MUmemLocation *location)
Description
- Returns the accessibility of a pool from a device.
- Returns the accessibility of the pool's memory from the specified location.
Parameters
flags(MUmemAccess_flags *): the accessibility of the pool from the specified locationmemPool(MUmemoryPool): the pool being queriedlocation(MUmemLocation *): the location accessing the pool
Returns
- Return type:
MUresult.
See also
muMemPoolCreate
MUresult muMemPoolCreate(MUmemoryPool *pool, const MUmemPoolProps *poolProps)
Description
- Creates a memory pool.
- Creates a MUSA memory pool and returns the handle in pool. The poolProps determines the properties of the pool such as the backing device and IPC capabilities.
- To create a memory pool for HOST memory not targeting a specific NUMA node, applications must set set MUmemPoolProps::MUmemLocation::type to MU_MEM_LOCATION_TYPE_HOST. MUmemPoolProps::MUmemLocation::id is ignored for such pools. Pools created with the type MU_MEM_LOCATION_TYPE_HOST are not IPC capable and MUmemPoolProps::handleTypes must be 0, any other values will result in MUSA_ERROR_INVALID_VALUE. To create a memory pool targeting a specific host NUMA node, applications must set MUmemPoolProps::MUmemLocation::type to MU_MEM_LOCATION_TYPE_HOST_NUMA and MUmemPoolProps::MUmemLocation::id must specify the NUMA ID of the host memory node. Specifying MU_MEM_LOCATION_TYPE_HOST_NUMA_CURRENT or MU_MEM_LOCATION_TYPE_HOST as the MUmemPoolProps::MUmemLocation::type will result in MUSA_ERROR_INVALID_VALUE. By default, the pool's memory will be accessible from the device it is allocated on. In the case of pools created with MU_MEM_LOCATION_TYPE_HOST_NUMA, their default accessibility will be from the host CPU. Applications can control the maximum size of the pool by specifying a non-zero value for MUmemPoolProps::maxSize. If set to 0, the maximum size of the pool will default to a system dependent value.
- Applications that intend to use MU_MEM_HANDLE_TYPE_FABRIC based memory sharing must ensure: (1) mthreads-caps-imex-channels character device is created by the driver and is listed under /proc/devices (2) have at least one IMEX channel file accessible by the user launching the application.
- When exporter and importer MUSA processes have been granted access to the same IMEX channel, they can securely share memory.
- The IMEX channel security model works on a per user basis. Which means all processes under a user can share memory if the user has access to a valid IMEX channel. When multi-user isolation is desired, a separate IMEX channel is required for each user.
- These channel files exist in /dev/mthreads-caps-imex-channels/channel* and can be created using standard OS native calls like mknod on Linux. For example: To create channel0 with the major number from /proc/devices users can execute the following command:
mknod /dev/mthreads-caps-imex-channels/channel0 c <major number> 0 - To create a managed memory pool, applications must set MUmemPoolProps::MUmemAllocationType to MU_MEM_ALLOCATION_TYPE_MANAGED. MUmemPoolProps::MUmemAllocationHandleType must also be set to MU_MEM_HANDLE_TYPE_NONE since IPC is not supported. For managed memory pools, MUmemPoolProps::MUmemLocation will be treated as the preferred location for all allocations created from the pool. An application can also set MU_MEM_LOCATION_TYPE_NONE to indicate no preferred location. MUmemPoolProps::maxSize must be set to zero for managed memory pools. MUmemPoolProps::usage should be zero as decompress for managed memory is not supported. For managed memory pools, all devices on the system must have non-zero concurrentManagedAccess. If not, this call returns MUSA_ERROR_NOT_SUPPORTED
Parameters
pool(MUmemoryPool *)poolProps(const MUmemPoolProps *)
Returns
- MUSA_SUCCESS, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY, MUSA_ERROR_NOT_PERMITTED MUSA_ERROR_NOT_SUPPORTED
Note
- Specifying MU_MEM_HANDLE_TYPE_NONE creates a memory pool that will not support IPC.
See also
- muDeviceSetMemPool, muDeviceGetMemPool, muDeviceGetDefaultMemPool, muMemAllocFromPoolAsync, muMemPoolExportToShareableHandle
muMemPoolDestroy
MUresult muMemPoolDestroy(MUmemoryPool pool)
Description
- Destroys the specified memory pool.
- If any pointers obtained from this pool haven't been freed or the pool has free operations that haven't completed when muMemPoolDestroy is invoked, the function will return immediately and the resources associated with the pool will be released automatically once there are no more outstanding allocations.
- Destroying the current mempool of a device sets the default mempool of that device as the current mempool for that device.
Parameters
pool(MUmemoryPool)
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
Note
- A device's default memory pool cannot be destroyed.
See also
muMemGetDefaultMemPool
MUresult muMemGetDefaultMemPool(MUmemoryPool *pool_out, MUmemLocation *location, MUmemAllocationType type)
Description
- Returns the default memory pool for a given location and allocation type.
- The memory location can be of one of MU_MEM_LOCATION_TYPE_DEVICE, MU_MEM_LOCATION_TYPE_HOST or MU_MEM_LOCATION_TYPE_HOST_NUMA. The allocation type can be one of MU_MEM_ALLOCATION_TYPE_PINNED or MU_MEM_ALLOCATION_TYPE_MANAGED. When the allocation type is MU_MEM_ALLOCATION_TYPE_MANAGED, the location type can also be MU_MEM_LOCATION_TYPE_NONE to indicate no preferred location for the managed memory pool. In all other cases, the call returns MUSA_ERROR_INVALID_VALUE.
Parameters
pool_out(MUmemoryPool *)location(MUmemLocation *)type(MUmemAllocationType)
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE, MUSA_ERROR_NOT_SUPPORTED
Note
- Experimental in the current MUSA SDK 5.2.0 delivery scope.
- This function may also return error codes from previous, asynchronous launches.
See also
- muMemAllocAsync, muMemPoolTrimTo, muMemPoolGetAttribute, muMemPoolSetAttribute, muMemPoolSetAccess, muMemGetMemPool, muMemPoolCreate
muMemGetMemPool
MUresult muMemGetMemPool(MUmemoryPool *pool, MUmemLocation *location, MUmemAllocationType type)
Description
- Gets the current memory pool for a memory location and of a particular allocation type.
- The memory location can be of one of MU_MEM_LOCATION_TYPE_DEVICE, MU_MEM_LOCATION_TYPE_HOST or MU_MEM_LOCATION_TYPE_HOST_NUMA. The allocation type can be one of MU_MEM_ALLOCATION_TYPE_PINNED or MU_MEM_ALLOCATION_TYPE_MANAGED. When the allocation type is MU_MEM_ALLOCATION_TYPE_MANAGED, the location type can also be MU_MEM_LOCATION_TYPE_NONE to indicate no preferred location for the managed memory pool. In all other cases, the call returns MUSA_ERROR_INVALID_VALUE.
- Returns the last pool provided to muMemSetMemPool or muDeviceSetMemPool for this location and allocation type or the location's default memory pool if muMemSetMemPool or muDeviceSetMemPool for that allocType and location has never been called. By default the current mempool of a location is the default mempool for a device. Otherwise the returned pool must have been set with muDeviceSetMemPool.
Parameters
pool(MUmemoryPool *)location(MUmemLocation *)type(MUmemAllocationType)
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
Note
- Experimental in the current MUSA SDK 5.2.0 delivery scope.
See also
muMemSetMemPool
MUresult muMemSetMemPool(MUmemLocation *location, MUmemAllocationType type, MUmemoryPool pool)
Description
- Sets the current memory pool for a memory location and allocation type.
- The memory location can be of one of MU_MEM_LOCATION_TYPE_DEVICE, MU_MEM_LOCATION_TYPE_HOST or MU_MEM_LOCATION_TYPE_HOST_NUMA. The allocation type can be one of MU_MEM_ALLOCATION_TYPE_PINNED or MU_MEM_ALLOCATION_TYPE_MANAGED. When the allocation type is MU_MEM_ALLOCATION_TYPE_MANAGED, the location type can also be MU_MEM_LOCATION_TYPE_NONE to indicate no preferred location for the managed memory pool. In all other cases, the call returns MUSA_ERROR_INVALID_VALUE.
- When a memory pool is set as the current memory pool, the location parameter should be the same as the location of the pool. The location and allocation type specified must match those of the pool otherwise MUSA_ERROR_INVALID_VALUE is returned. By default, a memory location's current memory pool is its default memory pool that can be obtained via muMemGetDefaultMemPool. If the location type is MU_MEM_LOCATION_TYPE_DEVICE and the allocation type is MU_MEM_ALLOCATION_TYPE_PINNED, then this API is the equivalent of calling muDeviceSetMemPool with the location id as the device. For further details on the implications, please refer to the documentation for muDeviceSetMemPool.
Parameters
location(MUmemLocation *)type(MUmemAllocationType)pool(MUmemoryPool)
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
Note
- Experimental in the current MUSA SDK 5.2.0 delivery scope.
- Use muMemAllocFromPoolAsync to specify asynchronous allocations from a device different than the one the stream runs on.
See also
- muDeviceGetDefaultMemPool, muDeviceGetMemPool, muMemGetMemPool, muMemPoolCreate, muMemPoolDestroy, muMemAllocFromPoolAsync
muMemAllocFromPoolAsync
MUresult muMemAllocFromPoolAsync(MUdeviceptr *dptr, size_t bytesize, MUmemoryPool pool, MUstream hStream)
Description
- Allocates memory from a specified pool with stream ordered semantics.
- Inserts an allocation operation into hStream. A pointer to the allocated memory is returned immediately in *dptr. The allocation must not be accessed until the the allocation operation completes. The allocation comes from the specified memory pool.
Parameters
dptr(MUdeviceptr *): Returned device pointerbytesize(size_t): Number of bytes to allocatepool(MUmemoryPool): The pool to allocate fromhStream(MUstream): The stream establishing the stream ordering semantic
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT (default stream specified with no current context), MUSA_ERROR_NOT_SUPPORTED, MUSA_ERROR_OUT_OF_MEMORY
Note
- The specified memory pool may be from a device different than that of the specified hStream. Basic stream ordering allows future work submitted into the same stream to use the allocation. Stream query, stream synchronize, and MUSA events can be used to guarantee that the allocation operation completes before work submitted in a separate stream runs. The specified memory pool may be from a device different than that of the specified hStream. Basic stream ordering allows future work submitted into the same stream to use the allocation. Stream query, stream synchronize, and MUSA events can be used to guarantee that the allocation operation completes before work submitted in a separate stream runs.
- During stream capture, this function results in the creation of an allocation node. In this case, the allocation is owned by the graph instead of the memory pool. The memory pool's properties are used to set the node's creation parameters.
See also
- muMemAllocAsync, muMemFreeAsync, muDeviceGetDefaultMemPool, muDeviceGetMemPool, muMemPoolCreate, muMemPoolSetAccess, muMemPoolSetAttribute
muMemPoolExportToShareableHandle
MUresult muMemPoolExportToShareableHandle(void *handle_out, MUmemoryPool pool, MUmemAllocationHandleType handleType, unsigned long long flags)
Description
- Exports a memory pool to the requested handle type.
- Given an IPC capable mempool, create an OS handle to share the pool with another process. A recipient process can convert the shareable handle into a mempool with muMemPoolImportFromShareableHandle. Individual pointers can then be shared with the muMemPoolExportPointer and muMemPoolImportPointer APIs. The implementation of what the shareable handle is and how it can be transferred is defined by the requested handle type.
Parameters
handle_out(void *): Returned OS handlepool(MUmemoryPool): pool to exporthandleType(MUmemAllocationHandleType): the type of handle to createflags(unsigned long long): must be 0
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_OUT_OF_MEMORY
Note
- : To create an IPC capable mempool, create a mempool with a MUmemAllocationHandleType other than MU_MEM_HANDLE_TYPE_NONE.
See also
- muMemPoolImportFromShareableHandle, muMemPoolExportPointer, muMemPoolImportPointer, muMemAllocAsync, muMemFreeAsync, muDeviceGetDefaultMemPool, muDeviceGetMemPool, muMemPoolCreate, muMemPoolSetAccess, muMemPoolSetAttribute
muMemPoolImportFromShareableHandle
MUresult muMemPoolImportFromShareableHandle(MUmemoryPool *pool_out, void *handle, MUmemAllocationHandleType handleType, unsigned long long flags)
Description
- imports a memory pool from a shared handle.
- Specific allocations can be imported from the imported pool with muMemPoolImportPointer.
- If handleType is MU_MEM_HANDLE_TYPE_FABRIC and the importer process has not been granted access to the same IMEX channel as the exporter process, this API will error as MUSA_ERROR_NOT_PERMITTED.
Parameters
pool_out(MUmemoryPool *): Returned memory poolhandle(void *): OS handle of the pool to openhandleType(MUmemAllocationHandleType): The type of handle being importedflags(unsigned long long): must be 0
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_OUT_OF_MEMORY
Note
- Imported memory pools do not support creating new allocations. As such imported memory pools may not be used in muDeviceSetMemPool or muMemAllocFromPoolAsync calls.
See also
muMemPoolExportPointer
MUresult muMemPoolExportPointer(MUmemPoolPtrExportData *shareData_out, MUdeviceptr ptr)
Description
- Export data to share a memory pool allocation between processes.
- Constructs shareData_out for sharing a specific allocation from an already shared memory pool. The recipient process can import the allocation with the muMemPoolImportPointer api. The data is not a handle and may be shared through any IPC mechanism.
Parameters
shareData_out(MUmemPoolPtrExportData *): Returned export dataptr(MUdeviceptr): pointer to memory being exported
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_OUT_OF_MEMORY
See also
muMemPoolImportPointer
MUresult muMemPoolImportPointer(MUdeviceptr *ptr_out, MUmemoryPool pool, MUmemPoolPtrExportData *shareData)
Description
- Import a memory pool allocation from another process.
- Returns in ptr_out a pointer to the imported memory. The imported memory must not be accessed before the allocation operation completes in the exporting process. The imported memory must be freed from all importing processes before being freed in the exporting process. The pointer may be freed with muMemFree or muMemFreeAsync. If muMemFreeAsync is used, the free must be completed on the importing process before the free operation on the exporting process.
Parameters
ptr_out(MUdeviceptr *): pointer to imported memorypool(MUmemoryPool): pool from which to importshareData(MUmemPoolPtrExportData *): data specifying the memory to import
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_OUT_OF_MEMORY
Note
- The muMemFreeAsync api may be used in the exporting process before the muMemFreeAsync operation completes in its stream as long as the muMemFreeAsync in the exporting process specifies a stream with a stream dependency on the importing process's muMemFreeAsync.
See also
3.15 Unified Addressing
muPointerGetAttribute
MUresult muPointerGetAttribute(void *data, MUpointer_attribute attribute, MUdeviceptr ptr)
Description
- Returns information about a pointer.
- The supported attributes are:
- MU_POINTER_ATTRIBUTE_CONTEXT: Returns in *data the MUcontext in which ptr was allocated or registered. The type of data must be MUcontext *. If ptr was not allocated by, mapped by, or registered with a MUcontext which uses unified virtual addressing then MUSA_ERROR_INVALID_VALUE is returned. MU_POINTER_ATTRIBUTE_MEMORY_TYPE: Returns in *data the physical memory type of the memory that ptr addresses as a MUmemorytype enumerated value. The type of data must be unsigned int. If ptr addresses device memory then *data is set to MU_MEMORYTYPE_DEVICE. The particular MUdevice on which the memory resides is the MUdevice of the MUcontext returned by the MU_POINTER_ATTRIBUTE_CONTEXT attribute of ptr. If ptr addresses host memory then *data is set to MU_MEMORYTYPE_HOST. If ptr was not allocated by, mapped by, or registered with a MUcontext which uses unified virtual addressing then MUSA_ERROR_INVALID_VALUE is returned. If the current MUcontext does not support unified virtual addressing then MUSA_ERROR_INVALID_CONTEXT is returned. MU_POINTER_ATTRIBUTE_DEVICE_POINTER: Returns in *data the device pointer value through which ptr may be accessed by kernels running in the current MUcontext. The type of data must be MUdeviceptr *. If there exists no device pointer value through which kernels running in the current MUcontext may access ptr then MUSA_ERROR_INVALID_VALUE is returned. If there is no current MUcontext then MUSA_ERROR_INVALID_CONTEXT is returned. Except in the exceptional disjoint addressing cases discussed below, the value returned in *data will equal the input value ptr. MU_POINTER_ATTRIBUTE_HOST_POINTER: Returns in *data the host pointer value through which ptr may be accessed by by the host program. The type of data must be void **. If there exists no host pointer value through which the host program may directly access ptr then MUSA_ERROR_INVALID_VALUE is returned. Except in the exceptional disjoint addressing cases discussed below, the value returned in *data will equal the input value ptr. MU_POINTER_ATTRIBUTE_P2P_TOKENS: Returns in *data two tokens for use with the nv-p2p.h Linux kernel interface. data must be a struct of type MUSA_POINTER_ATTRIBUTE_P2P_TOKENS. ptr must be a pointer to memory obtained from :muMemAlloc(). Note that p2pToken and vaSpaceToken are only valid for the lifetime of the source allocation. A subsequent allocation at the same address may return completely different tokens. Querying this attribute has a side effect of setting the attribute MU_POINTER_ATTRIBUTE_SYNC_MEMOPS for the region of memory that ptr points to. MU_POINTER_ATTRIBUTE_SYNC_MEMOPS: A boolean attribute which when set, ensures that synchronous memory operations initiated on the region of memory that ptr points to will always synchronize. See further documentation in the section titled "API synchronization behavior" to learn more about cases when synchronous memory operations can exhibit asynchronous behavior. MU_POINTER_ATTRIBUTE_BUFFER_ID: Returns in *data a buffer ID which is guaranteed to be unique within the process. data must point to an unsigned long long. ptr must be a pointer to memory obtained from a MUSA memory allocation API. Every memory allocation from any of the MUSA memory allocation APIs will have a unique ID over a process lifetime. Subsequent allocations do not reuse IDs from previous freed allocations. IDs are only unique within a single process. MU_POINTER_ATTRIBUTE_IS_MANAGED: Returns in *data a boolean that indicates whether the pointer points to managed memory or not. If ptr is not a valid MUSA pointer then MUSA_ERROR_INVALID_VALUE is returned. MU_POINTER_ATTRIBUTE_DEVICE_ORDINAL: Returns in *data an integer representing a device ordinal of a device against which the memory was allocated or registered. MU_POINTER_ATTRIBUTE_IS_LEGACY_MUSA_IPC_CAPABLE: Returns in *data a boolean that indicates if this pointer maps to an allocation that is suitable for musaIpcGetMemHandle. MU_POINTER_ATTRIBUTE_RANGE_START_ADDR: Returns in *data the starting address for the allocation referenced by the device pointer ptr. Note that this is not necessarily the address of the mapped region, but the address of the mappable address range ptr references (e.g. from muMemAddressReserve). MU_POINTER_ATTRIBUTE_RANGE_SIZE: Returns in *data the size for the allocation referenced by the device pointer ptr. Note that this is not necessarily the size of the mapped region, but the size of the mappable address range ptr references (e.g. from muMemAddressReserve). To retrieve the size of the mapped region, see muMemGetAddressRange MU_POINTER_ATTRIBUTE_MAPPED: Returns in *data a boolean that indicates if this pointer is in a valid address range that is mapped to a backing allocation. MU_POINTER_ATTRIBUTE_ALLOWED_HANDLE_TYPES: Returns a bitmask of the allowed handle types for an allocation that may be passed to muMemExportToShareableHandle. MU_POINTER_ATTRIBUTE_MEMPOOL_HANDLE: Returns in *data the handle to the mempool that the allocation was obtained from. MU_POINTER_ATTRIBUTE_IS_HW_DECOMPRESS_CAPABLE: Returns in *data a boolean that indicates whether the pointer points to memory that is capable to be used for hardware accelerated decompression.
Parameters
data(void *): Returned pointer attribute valueattribute(MUpointer_attribute): Pointer attribute to queryptr(MUdeviceptr): Pointer
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muPointerSetAttribute, muMemAlloc, muMemFree, muMemAllocHost, muMemFreeHost, muMemHostAlloc, muMemHostRegister, muMemHostUnregister, musaPointerGetAttributes
muMemPrefetchAsync
MUresult muMemPrefetchAsync(MUdeviceptr devPtr, size_t count, MUdevice dstDevice, MUstream hStream)
Description
- Prefetches memory to the specified destination device.
- Note there is a later version of this API, muMemPrefetchAsync_v2. It will supplant this version in 13.0, which is retained for minor version compatibility.
- Prefetches memory to the specified destination device. devPtr is the base device pointer of the memory to be prefetched and dstDevice is the destination device. count specifies the number of bytes to copy. hStream is the stream in which the operation is enqueued. The memory range must refer to managed memory allocated via muMemAllocManaged or declared via managed variables or it may also refer to system-allocated memory on systems with non-zero MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS.
- Passing in MU_DEVICE_CPU for dstDevice will prefetch the data to host memory. If dstDevice is a GPU, then the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS must be non-zero. Additionally, hStream must be associated with a device that has a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS.
- The start address and end address of the memory range will be rounded down and rounded up respectively to be aligned to CPU page size before the prefetch operation is enqueued in the stream.
- If no physical memory has been allocated for this region, then this memory region will be populated and mapped on the destination device. If there's insufficient memory to prefetch the desired region, the Unified Memory driver may evict pages from other muMemAllocManaged allocations to host memory in order to make room. Device memory allocated using muMemAlloc or muArrayCreate will not be evicted.
- By default, any mappings to the previous location of the migrated pages are removed and mappings for the new location are only setup on dstDevice. The exact behavior however also depends on the settings applied to this memory range via muMemAdvise as described below:
- If MU_MEM_ADVISE_SET_READ_MOSTLY was set on any subset of this memory range, then that subset will create a read-only copy of the pages on dstDevice.
- If MU_MEM_ADVISE_SET_PREFERRED_LOCATION was called on any subset of this memory range, then the pages will be migrated to dstDevice even if dstDevice is not the preferred location of any pages in the memory range.
- If MU_MEM_ADVISE_SET_ACCESSED_BY was called on any subset of this memory range, then mappings to those pages from all the appropriate processors are updated to refer to the new location if establishing such a mapping is possible. Otherwise, those mappings are cleared.
- Note that this API is not required for functionality and only serves to improve performance by allowing the application to migrate data to a suitable location before it is accessed. Memory accesses to this range are always coherent and are allowed even when the data is actively being migrated.
- Note that this function is asynchronous with respect to the host and all work on other devices.
Parameters
devPtr(MUdeviceptr): Pointer to be prefetchedcount(size_t): Size in bytesdstDevice(MUdevice): Destination device to prefetch tohStream(MUstream): Stream to enqueue prefetch operation
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muMemcpy, muMemcpyPeer, muMemcpyAsync, muMemcpy3DPeerAsync, muMemAdvise, muMemPrefetchAsync musaMemPrefetchAsync_v2
muMemPrefetchAsync_v2
MUresult muMemPrefetchAsync_v2(MUdeviceptr devPtr, size_t count, MUmemLocation location, unsigned int flags, MUstream hStream)
Description
- Prefetches memory to the specified destination location.
- Prefetches memory to the specified destination location. devPtr is the base device pointer of the memory to be prefetched and location specifies the destination location. count specifies the number of bytes to copy. hStream is the stream in which the operation is enqueued. The memory range must refer to managed memory allocated via muMemAllocManaged or declared via managed variables.
- Specifying MU_MEM_LOCATION_TYPE_DEVICE for MUmemLocation::type will prefetch memory to GPU specified by device ordinal MUmemLocation::id which must have non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS. Additionally, hStream must be associated with a device that has a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS. Specifying MU_MEM_LOCATION_TYPE_HOST as MUmemLocation::type will prefetch data to host memory. Applications can request prefetching memory to a specific host NUMA node by specifying MU_MEM_LOCATION_TYPE_HOST_NUMA for MUmemLocation::type and a valid host NUMA node id in MUmemLocation::id Users can also request prefetching memory to the host NUMA node closest to the current thread's CPU by specifying MU_MEM_LOCATION_TYPE_HOST_NUMA_CURRENT for MUmemLocation::type. Note when MUmemLocation::type is etiher MU_MEM_LOCATION_TYPE_HOST OR MU_MEM_LOCATION_TYPE_HOST_NUMA_CURRENT, MUmemLocation::id will be ignored.
- The start address and end address of the memory range will be rounded down and rounded up respectively to be aligned to CPU page size before the prefetch operation is enqueued in the stream.
- If no physical memory has been allocated for this region, then this memory region will be populated and mapped on the destination device. If there's insufficient memory to prefetch the desired region, the Unified Memory driver may evict pages from other muMemAllocManaged allocations to host memory in order to make room. Device memory allocated using muMemAlloc or muArrayCreate will not be evicted.
- By default, any mappings to the previous location of the migrated pages are removed and mappings for the new location are only setup on the destination location. The exact behavior however also depends on the settings applied to this memory range via muMemAdvise as described below:
- If MU_MEM_ADVISE_SET_READ_MOSTLY was set on any subset of this memory range, then that subset will create a read-only copy of the pages on destination location. If however the destination location is a host NUMA node, then any pages of that subset that are already in another host NUMA node will be transferred to the destination.
- If MU_MEM_ADVISE_SET_PREFERRED_LOCATION was called on any subset of this memory range, then the pages will be migrated to location even if location is not the preferred location of any pages in the memory range.
- If MU_MEM_ADVISE_SET_ACCESSED_BY was called on any subset of this memory range, then mappings to those pages from all the appropriate processors are updated to refer to the new location if establishing such a mapping is possible. Otherwise, those mappings are cleared.
- Note that this API is not required for functionality and only serves to improve performance by allowing the application to migrate data to a suitable location before it is accessed. Memory accesses to this range are always coherent and are allowed even when the data is actively being migrated.
- Note that this function is asynchronous with respect to the host and all work on other devices.
Parameters
devPtr(MUdeviceptr): Pointer to be prefetchedcount(size_t): Size in byteslocation(MUmemLocation)flags(unsigned int): flags for future use, must be zero now.hStream(MUstream): Stream to enqueue prefetch operation
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muMemcpy, muMemcpyPeer, muMemcpyAsync, muMemcpy3DPeerAsync, muMemAdvise, muMemPrefetchAsync musaMemPrefetchAsync_v2
muMemAdvise
MUresult muMemAdvise(MUdeviceptr devPtr, size_t count, MUmem_advise advice, MUdevice device)
Description
- Advise about the usage of a given memory range.
- Note there is a later version of this API, muMemAdvise_v2. It will supplant this version in 13.0, which is retained for minor version compatibility.
- Advise the Unified Memory subsystem about the usage pattern for the memory range starting at devPtr with a size of count bytes. The start address and end address of the memory range will be rounded down and rounded up respectively to be aligned to CPU page size before the advice is applied. The memory range must refer to managed memory allocated via muMemAllocManaged or declared via managed variables. The memory range could also refer to system-allocated pageable memory provided it represents a valid, host-accessible region of memory and all additional constraints imposed by advice as outlined below are also satisfied. Specifying an invalid system-allocated pageable memory range results in an error being returned.
- The advice parameter can take the following values: MU_MEM_ADVISE_SET_READ_MOSTLY: This implies that the data is mostly going to be read from and only occasionally written to. Any read accesses from any processor to this region will create a read-only copy of at least the accessed pages in that processor's memory. Additionally, if muMemPrefetchAsync is called on this region, it will create a read-only copy of the data on the destination processor. If any processor writes to this region, all copies of the corresponding page will be invalidated except for the one where the write occurred. The device argument is ignored for this advice. Note that for a page to be read-duplicated, the accessing processor must either be the CPU or a GPU that has a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS. Also, if a context is created on a device that does not have the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS set, then read-duplication will not occur until all such contexts are destroyed. If the memory region refers to valid system-allocated pageable memory, then the accessing device must have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS for a read-only copy to be created on that device. Note however that if the accessing device also has a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES, then setting this advice will not create a read-only copy when that device accesses this memory region. MU_MEM_ADVISE_UNSET_READ_MOSTLY: Undoes the effect of MU_MEM_ADVISE_SET_READ_MOSTLY and also prevents the Unified Memory driver from attempting heuristic read-duplication on the memory range. Any read-duplicated copies of the data will be collapsed into a single copy. The location for the collapsed copy will be the preferred location if the page has a preferred location and one of the read-duplicated copies was resident at that location. Otherwise, the location chosen is arbitrary. MU_MEM_ADVISE_SET_PREFERRED_LOCATION: This advice sets the preferred location for the data to be the memory belonging to device. Passing in MU_DEVICE_CPU for device sets the preferred location as host memory. If device is a GPU, then it must have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS. Setting the preferred location does not cause data to migrate to that location immediately. Instead, it guides the migration policy when a fault occurs on that memory region. If the data is already in its preferred location and the faulting processor can establish a mapping without requiring the data to be migrated, then data migration will be avoided. On the other hand, if the data is not in its preferred location or if a direct mapping cannot be established, then it will be migrated to the processor accessing it. It is important to note that setting the preferred location does not prevent data prefetching done using muMemPrefetchAsync. Having a preferred location can override the page thrash detection and resolution logic in the Unified Memory driver. Normally, if a page is detected to be constantly thrashing between for example host and device memory, the page may eventually be pinned to host memory by the Unified Memory driver. But if the preferred location is set as device memory, then the page will continue to thrash indefinitely. If MU_MEM_ADVISE_SET_READ_MOSTLY is also set on this memory region or any subset of it, then the policies associated with that advice will override the policies of this advice, unless read accesses from device will not result in a read-only copy being created on that device as outlined in description for the advice MU_MEM_ADVISE_SET_READ_MOSTLY. If the memory region refers to valid system-allocated pageable memory, then device must have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS. MU_MEM_ADVISE_UNSET_PREFERRED_LOCATION: Undoes the effect of MU_MEM_ADVISE_SET_PREFERRED_LOCATION and changes the preferred location to none. MU_MEM_ADVISE_SET_ACCESSED_BY: This advice implies that the data will be accessed by device. Passing in MU_DEVICE_CPU for device will set the advice for the CPU. If device is a GPU, then the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS must be non-zero. This advice does not cause data migration and has no impact on the location of the data per se. Instead, it causes the data to always be mapped in the specified processor's page tables, as long as the location of the data permits a mapping to be established. If the data gets migrated for any reason, the mappings are updated accordingly. This advice is recommended in scenarios where data locality is not important, but avoiding faults is. Consider for example a system containing multiple GPUs with peer-to-peer access enabled, where the data located on one GPU is occasionally accessed by peer GPUs. In such scenarios, migrating data over to the other GPUs is not as important because the accesses are infrequent and the overhead of migration may be too high. But preventing faults can still help improve performance, and so having a mapping set up in advance is useful. Note that on CPU access of this data, the data may be migrated to host memory because the CPU typically cannot access device memory directly. Any GPU that had the MU_MEM_ADVISE_SET_ACCESSED_BY flag set for this data will now have its mapping updated to point to the page in host memory. If MU_MEM_ADVISE_SET_READ_MOSTLY is also set on this memory region or any subset of it, then the policies associated with that advice will override the policies of this advice. Additionally, if the preferred location of this memory region or any subset of it is also device, then the policies associated with MU_MEM_ADVISE_SET_PREFERRED_LOCATION will override the policies of this advice. If the memory region refers to valid system-allocated pageable memory, then device must have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS. Additionally, if device has a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES, then this call has no effect. MU_MEM_ADVISE_UNSET_ACCESSED_BY: Undoes the effect of MU_MEM_ADVISE_SET_ACCESSED_BY. Any mappings to the data from device may be removed at any time causing accesses to result in non-fatal page faults. If the memory region refers to valid system-allocated pageable memory, then device must have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS. Additionally, if device has a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES, then this call has no effect.
Parameters
devPtr(MUdeviceptr): Pointer to memory to set the advice forcount(size_t): Size in bytes of the memory rangeadvice(MUmem_advise): Advice to be applied for the specified memory rangedevice(MUdevice): Device to apply the advice for
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muMemcpy, muMemcpyPeer, muMemcpyAsync, muMemcpy3DPeerAsync, muMemPrefetchAsync, muMemAdvise_v2 musaMemAdvise
muMemAdvise_v2
MUresult muMemAdvise_v2(MUdeviceptr devPtr, size_t count, MUmem_advise advice, MUmemLocation location)
Description
- Advise about the usage of a given memory range.
- Advise the Unified Memory subsystem about the usage pattern for the memory range starting at devPtr with a size of count bytes. The start address and end address of the memory range will be rounded down and rounded up respectively to be aligned to CPU page size before the advice is applied. The memory range must refer to managed memory allocated via muMemAllocManaged or declared via managed variables. The memory range could also refer to system-allocated pageable memory provided it represents a valid, host-accessible region of memory and all additional constraints imposed by advice as outlined below are also satisfied. Specifying an invalid system-allocated pageable memory range results in an error being returned.
- The advice parameter can take the following values: MU_MEM_ADVISE_SET_READ_MOSTLY: This implies that the data is mostly going to be read from and only occasionally written to. Any read accesses from any processor to this region will create a read-only copy of at least the accessed pages in that processor's memory. Additionally, if muMemPrefetchAsync or muMemPrefetchAsync_v2 is called on this region, it will create a read-only copy of the data on the destination processor. If the target location for muMemPrefetchAsync_v2 is a host NUMA node and a read-only copy already exists on another host NUMA node, that copy will be migrated to the targeted host NUMA node. If any processor writes to this region, all copies of the corresponding page will be invalidated except for the one where the write occurred. If the writing processor is the CPU and the preferred location of the page is a host NUMA node, then the page will also be migrated to that host NUMA node. The location argument is ignored for this advice. Note that for a page to be read-duplicated, the accessing processor must either be the CPU or a GPU that has a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS. Also, if a context is created on a device that does not have the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS set, then read-duplication will not occur until all such contexts are destroyed. If the memory region refers to valid system-allocated pageable memory, then the accessing device must have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS for a read-only copy to be created on that device. Note however that if the accessing device also has a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES, then setting this advice will not create a read-only copy when that device accesses this memory region. MU_MEM_ADVISE_UNSET_READ_MOSTLY: Undoes the effect of MU_MEM_ADVISE_SET_READ_MOSTLY and also prevents the Unified Memory driver from attempting heuristic read-duplication on the memory range. Any read-duplicated copies of the data will be collapsed into a single copy. The location for the collapsed copy will be the preferred location if the page has a preferred location and one of the read-duplicated copies was resident at that location. Otherwise, the location chosen is arbitrary. Note: The location argument is ignored for this advice. MU_MEM_ADVISE_SET_PREFERRED_LOCATION: This advice sets the preferred location for the data to be the memory belonging to location. When MUmemLocation::type is MU_MEM_LOCATION_TYPE_HOST, MUmemLocation::id is ignored and the preferred location is set to be host memory. To set the preferred location to a specific host NUMA node, applications must set MUmemLocation::type to MU_MEM_LOCATION_TYPE_HOST_NUMA and MUmemLocation::id must specify the NUMA ID of the host NUMA node. If MUmemLocation::type is set to MU_MEM_LOCATION_TYPE_HOST_NUMA_CURRENT, MUmemLocation::id will be ignored and the the host NUMA node closest to the calling thread's CPU will be used as the preferred location. If MUmemLocation::type is a MU_MEM_LOCATION_TYPE_DEVICE, then MUmemLocation::id must be a valid device ordinal and the device must have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS. Setting the preferred location does not cause data to migrate to that location immediately. Instead, it guides the migration policy when a fault occurs on that memory region. If the data is already in its preferred location and the faulting processor can establish a mapping without requiring the data to be migrated, then data migration will be avoided. On the other hand, if the data is not in its preferred location or if a direct mapping cannot be established, then it will be migrated to the processor accessing it. It is important to note that setting the preferred location does not prevent data prefetching done using muMemPrefetchAsync. Having a preferred location can override the page thrash detection and resolution logic in the Unified Memory driver. Normally, if a page is detected to be constantly thrashing between for example host and device memory, the page may eventually be pinned to host memory by the Unified Memory driver. But if the preferred location is set as device memory, then the page will continue to thrash indefinitely. If MU_MEM_ADVISE_SET_READ_MOSTLY is also set on this memory region or any subset of it, then the policies associated with that advice will override the policies of this advice, unless read accesses from location will not result in a read-only copy being created on that procesor as outlined in description for the advice MU_MEM_ADVISE_SET_READ_MOSTLY. If the memory region refers to valid system-allocated pageable memory, and MUmemLocation::type is MU_MEM_LOCATION_TYPE_DEVICE then MUmemLocation::id must be a valid device that has a non-zero alue for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS. MU_MEM_ADVISE_UNSET_PREFERRED_LOCATION: Undoes the effect of MU_MEM_ADVISE_SET_PREFERRED_LOCATION and changes the preferred location to none. The location argument is ignored for this advice. MU_MEM_ADVISE_SET_ACCESSED_BY: This advice implies that the data will be accessed by processor location. The MUmemLocation::type must be either MU_MEM_LOCATION_TYPE_DEVICE with MUmemLocation::id representing a valid device ordinal or MU_MEM_LOCATION_TYPE_HOST and MUmemLocation::id will be ignored. All other location types are invalid. If MUmemLocation::id is a GPU, then the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS must be non-zero. This advice does not cause data migration and has no impact on the location of the data per se. Instead, it causes the data to always be mapped in the specified processor's page tables, as long as the location of the data permits a mapping to be established. If the data gets migrated for any reason, the mappings are updated accordingly. This advice is recommended in scenarios where data locality is not important, but avoiding faults is. Consider for example a system containing multiple GPUs with peer-to-peer access enabled, where the data located on one GPU is occasionally accessed by peer GPUs. In such scenarios, migrating data over to the other GPUs is not as important because the accesses are infrequent and the overhead of migration may be too high. But preventing faults can still help improve performance, and so having a mapping set up in advance is useful. Note that on CPU access of this data, the data may be migrated to host memory because the CPU typically cannot access device memory directly. Any GPU that had the MU_MEM_ADVISE_SET_ACCESSED_BY flag set for this data will now have its mapping updated to point to the page in host memory. If MU_MEM_ADVISE_SET_READ_MOSTLY is also set on this memory region or any subset of it, then the policies associated with that advice will override the policies of this advice. Additionally, if the preferred location of this memory region or any subset of it is also location, then the policies associated with MU_MEM_ADVISE_SET_PREFERRED_LOCATION will override the policies of this advice. If the memory region refers to valid system-allocated pageable memory, and MUmemLocation::type is MU_MEM_LOCATION_TYPE_DEVICE then device in MUmemLocation::id must have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS. Additionally, if MUmemLocation::id has a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES, then this call has no effect. MU_MEM_ADVISE_UNSET_ACCESSED_BY: Undoes the effect of MU_MEM_ADVISE_SET_ACCESSED_BY. Any mappings to the data from location may be removed at any time causing accesses to result in non-fatal page faults. If the memory region refers to valid system-allocated pageable memory, and MUmemLocation::type is MU_MEM_LOCATION_TYPE_DEVICE then device in MUmemLocation::id must have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS. Additionally, if MUmemLocation::id has a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES, then this call has no effect.
Parameters
devPtr(MUdeviceptr): Pointer to memory to set the advice forcount(size_t): Size in bytes of the memory rangeadvice(MUmem_advise): Advice to be applied for the specified memory rangelocation(MUmemLocation): location to apply the advice for
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- muMemcpy, muMemcpyPeer, muMemcpyAsync, muMemcpy3DPeerAsync, muMemPrefetchAsync, muMemAdvise musaMemAdvise
muMemRangeGetAttribute
MUresult muMemRangeGetAttribute(void *data, size_t dataSize, MUmem_range_attribute attribute, MUdeviceptr devPtr, size_t count)
Description
- Performs a batch of memory prefetches asynchronously.
- Performs a batch of memory prefetches. The batch as a whole executes in stream order but operations within a batch are not guaranteed to execute in any specific order. All devices in the system must have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS otherwise the API will return an error.
- The semantics of the individual prefetch operations are as described in muMemPrefetchAsync.
- Performs memory prefetch on address ranges specified in dptrs and sizes. Both arrays must be of the same length as specified by count. Each memory range specified must refer to managed memory allocated via muMemAllocManaged or declared via managed variables or it may also refer to system-allocated memory when all devices have a non-zero value for MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS. The prefetch location for every operation in the batch is specified in the prefetchLocs array. Each entry in this array can apply to more than one operation. This can be done by specifying in the prefetchLocIdxs array, the index of the first prefetch operation that the corresponding entry in the prefetchLocs array applies to. Both prefetchLocs and prefetchLocIdxs must be of the same length as specified by numPrefetchLocs. For example, if a batch has 10 prefetches listed in dptrs/sizes, the first 4 of which are to be prefetched to one location and the remaining 6 are to be prefetched to another, then numPrefetchLocs will be 2, prefetchLocIdxs will be {0, 4} and prefetchLocs will contain the two locations. Note the first entry in prefetchLocIdxs must always be 0. Also, each entry must be greater than the previous entry and the last entry should be less than count. Furthermore, numPrefetchLocs must be lesser than or equal to count.
- Performs a batch of memory discards. The batch as a whole executes in stream order but operations within a batch are not guaranteed to execute in any specific order. All devices in the system must have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS otherwise the API will return an error.
- Discarding a memory range informs the driver that the contents of that range are no longer useful. Discarding memory ranges allows the driver to optimize certain data migrations and can also help reduce memory pressure. This operation can be undone on any part of the range by either writing to it or prefetching it via muMemPrefetchAsync or muMemPrefetchBatchAsync. Reading from a discarded range, without a subsequent write or prefetch to that part of the range, will return an indeterminate value. Note that any reads, writes or prefetches to any part of the memory range that occur simultaneously with the discard operation result in undefined behavior.
- Performs memory discard on address ranges specified in dptrs and sizes. Both arrays must be of the same length as specified by count. Each memory range specified must refer to managed memory allocated via muMemAllocManaged or declared via managed variables or it may also refer to system-allocated memory when all devices have a non-zero value for MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS.
- Performs a batch of memory discards followed by prefetches. The batch as a whole executes in stream order but operations within a batch are not guaranteed to execute in any specific order. All devices in the system must have a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS otherwise the API will return an error.
- Calling muMemDiscardAndPrefetchBatchAsync is semantically equivalent to calling muMemDiscardBatchAsync followed by muMemPrefetchBatchAsync, but is more optimal. For more details on what discarding and prefetching imply, please refer to muMemDiscardBatchAsync and muMemPrefetchBatchAsync respectively. Note that any reads, writes or prefetches to any part of the memory range that occur simultaneously with this combined discard+prefetch operation result in undefined behavior.
- Performs memory discard and prefetch on address ranges specified in dptrs and sizes. Both arrays must be of the same length as specified by count. Each memory range specified must refer to managed memory allocated via muMemAllocManaged or declared via managed variables or it may also refer to system-allocated memory when all devices have a non-zero value for MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS. Every operation in the batch has to be associated with a valid location to prefetch the address range to and specified in the prefetchLocs array. Each entry in this array can apply to more than one operation. This can be done by specifying in the prefetchLocIdxs array, the index of the first operation that the corresponding entry in the prefetchLocs array applies to. Both prefetchLocs and prefetchLocIdxs must be of the same length as specified by numPrefetchLocs. For example, if a batch has 10 operations listed in dptrs/sizes, the first 6 of which are to be prefetched to one location and the remaining 4 are to be prefetched to another, then numPrefetchLocs will be 2, prefetchLocIdxs will be {0, 6} and prefetchLocs will contain the two set of locations. Note the first entry in prefetchLocIdxs must always be 0. Also, each entry must be greater than the previous entry and the last entry should be less than count. Furthermore, numPrefetchLocs must be lesser than or equal to count.
- Query an attribute about the memory range starting at devPtr with a size of count bytes. The memory range must refer to managed memory allocated via muMemAllocManaged or declared via managed variables.
- The attribute parameter can take the following values: MU_MEM_RANGE_ATTRIBUTE_READ_MOSTLY: If this attribute is specified, data will be interpreted as a 32-bit integer, and dataSize must be 4. The result returned will be 1 if all pages in the given memory range have read-duplication enabled, or 0 otherwise. MU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION: If this attribute is specified, data will be interpreted as a 32-bit integer, and dataSize must be 4. The result returned will be a GPU device id if all pages in the memory range have that GPU as their preferred location, or it will be MU_DEVICE_CPU if all pages in the memory range have the CPU as their preferred location, or it will be MU_DEVICE_INVALID if either all the pages don't have the same preferred location or some of the pages don't have a preferred location at all. Note that the actual location of the pages in the memory range at the time of the query may be different from the preferred location. MU_MEM_RANGE_ATTRIBUTE_ACCESSED_BY: If this attribute is specified, data will be interpreted as an array of 32-bit integers, and dataSize must be a non-zero multiple of 4. The result returned will be a list of device ids that had MU_MEM_ADVISE_SET_ACCESSED_BY set for that entire memory range. If any device does not have that advice set for the entire memory range, that device will not be included. If data is larger than the number of devices that have that advice set for that memory range, MU_DEVICE_INVALID will be returned in all the extra space provided. For ex., if dataSize is 12 (i.e. data has 3 elements) and only device 0 has the advice set, then the result returned will be { 0, MU_DEVICE_INVALID, MU_DEVICE_INVALID }. If data is smaller than the number of devices that have that advice set, then only as many devices will be returned as can fit in the array. There is no guarantee on which specific devices will be returned, however. MU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION: If this attribute is specified, data will be interpreted as a 32-bit integer, and dataSize must be 4. The result returned will be the last location to which all pages in the memory range were prefetched explicitly via muMemPrefetchAsync. This will either be a GPU id or MU_DEVICE_CPU depending on whether the last location for prefetch was a GPU or the CPU respectively. If any page in the memory range was never explicitly prefetched or if all pages were not prefetched to the same location, MU_DEVICE_INVALID will be returned. Note that this simply returns the last location that the application requested to prefetch the memory range to. It gives no indication as to whether the prefetch operation to that location has completed or even begun. MU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION_TYPE: If this attribute is specified, data will be interpreted as a MUmemLocationType, and dataSize must be sizeof(MUmemLocationType). The MUmemLocationType returned will be MU_MEM_LOCATION_TYPE_DEVICE if all pages in the memory range have the same GPU as their preferred location, or MUmemLocationType will be MU_MEM_LOCATION_TYPE_HOST if all pages in the memory range have the CPU as their preferred location, or it will be MU_MEM_LOCATION_TYPE_HOST_NUMA if all the pages in the memory range have the same host NUMA node ID as their preferred location or it will be MU_MEM_LOCATION_TYPE_INVALID if either all the pages don't have the same preferred location or some of the pages don't have a preferred location at all. Note that the actual location type of the pages in the memory range at the time of the query may be different from the preferred location type. MU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION_ID: If this attribute is specified, data will be interpreted as a 32-bit integer, and dataSize must be 4. If the MU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION_TYPE query for the same address range returns MU_MEM_LOCATION_TYPE_DEVICE, it will be a valid device ordinal or if it returns MU_MEM_LOCATION_TYPE_HOST_NUMA, it will be a valid host NUMA node ID or if it returns any other location type, the id should be ignored. MU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION_TYPE: If this attribute is specified, data will be interpreted as a MUmemLocationType, and dataSize must be sizeof(MUmemLocationType). The result returned will be the last location to which all pages in the memory range were prefetched explicitly via muMemPrefetchAsync. The MUmemLocationType returned will be MU_MEM_LOCATION_TYPE_DEVICE if the last prefetch location was a GPU or MU_MEM_LOCATION_TYPE_HOST if it was the CPU or MU_MEM_LOCATION_TYPE_HOST_NUMA if the last prefetch location was a specific host NUMA node. If any page in the memory range was never explicitly prefetched or if all pages were not prefetched to the same location, MUmemLocationType will be MU_MEM_LOCATION_TYPE_INVALID. Note that this simply returns the last location type that the application requested to prefetch the memory range to. It gives no indication as to whether the prefetch operation to that location has completed or even begun. MU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION_ID: If this attribute is specified, data will be interpreted as a 32-bit integer, and dataSize must be 4. If the MU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION_TYPE query for the same address range returns MU_MEM_LOCATION_TYPE_DEVICE, it will be a valid device ordinal or if it returns MU_MEM_LOCATION_TYPE_HOST_NUMA, it will be a valid host NUMA node ID or if it returns any other location type, the id should be ignored.
Parameters
data(void *): A pointers to a memory location where the result of each attribute query will be written to.dataSize(size_t): Array containing the size of dataattribute(MUmem_range_attribute): The attribute to querydevPtr(MUdeviceptr): Start of the range to querycount(size_t): Size of the range to query
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
muMemRangeGetAttributes
MUresult muMemRangeGetAttributes(void **data, size_t *dataSizes, MUmem_range_attribute *attributes, size_t numAttributes, MUdeviceptr devPtr, size_t count)
Description
- Query attributes of a given memory range.
- Query attributes of the memory range starting at devPtr with a size of count bytes. The memory range must refer to managed memory allocated via muMemAllocManaged or declared via managed variables. The attributes array will be interpreted to have numAttributes entries. The dataSizes array will also be interpreted to have numAttributes entries. The results of the query will be stored in data.
- The list of supported attributes are given below. Please refer to muMemRangeGetAttribute for attribute descriptions and restrictions.
- MU_MEM_RANGE_ATTRIBUTE_READ_MOSTLY MU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION MU_MEM_RANGE_ATTRIBUTE_ACCESSED_BY MU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION MU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION_TYPE MU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION_ID MU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION_TYPE MU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION_ID
Parameters
data(void **): A two-dimensional array containing pointers to memory locations where the result of each attribute query will be written to.dataSizes(size_t *): Array containing the sizes of each resultattributes(MUmem_range_attribute *): An array of attributes to query (numAttributes and the number of attributes in this array should match)numAttributes(size_t): Number of attributes to querydevPtr(MUdeviceptr): Start of the range to querycount(size_t): Size of the range to query
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muPointerSetAttribute
MUresult muPointerSetAttribute(const void *value, MUpointer_attribute attribute, MUdeviceptr ptr)
Description
- Set attributes on a previously allocated memory region.
- The supported attributes are:
- MU_POINTER_ATTRIBUTE_SYNC_MEMOPS: A boolean attribute that can either be set (1) or unset (0). When set, the region of memory that ptr points to is guaranteed to always synchronize memory operations that are synchronous. If there are some previously initiated synchronous memory operations that are pending when this attribute is set, the function does not return until those memory operations are complete. See further documentation in the section titled "API synchronization behavior" to learn more about cases when synchronous memory operations can exhibit asynchronous behavior. value will be considered as a pointer to an unsigned integer to which this attribute is to be set.
Parameters
value(const void *): Pointer to memory containing the value to be setattribute(MUpointer_attribute): Pointer attribute to setptr(MUdeviceptr): Pointer to a memory region allocated using MUSA memory allocation APIs
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muPointerGetAttribute, muPointerGetAttributes, muMemAlloc, muMemFree, muMemAllocHost, muMemFreeHost, muMemHostAlloc, muMemHostRegister, muMemHostUnregister
muPointerGetAttributes
MUresult muPointerGetAttributes(unsigned int numAttributes, MUpointer_attribute *attributes, void **data, MUdeviceptr ptr)
Description
- Returns information about a pointer.
- The supported attributes are (refer to muPointerGetAttribute for attribute descriptions and restrictions):
- MU_POINTER_ATTRIBUTE_CONTEXT MU_POINTER_ATTRIBUTE_MEMORY_TYPE MU_POINTER_ATTRIBUTE_DEVICE_POINTER MU_POINTER_ATTRIBUTE_HOST_POINTER MU_POINTER_ATTRIBUTE_SYNC_MEMOPS MU_POINTER_ATTRIBUTE_BUFFER_ID MU_POINTER_ATTRIBUTE_IS_MANAGED MU_POINTER_ATTRIBUTE_DEVICE_ORDINAL MU_POINTER_ATTRIBUTE_RANGE_START_ADDR MU_POINTER_ATTRIBUTE_RANGE_SIZE MU_POINTER_ATTRIBUTE_MAPPED MU_POINTER_ATTRIBUTE_IS_LEGACY_MUSA_IPC_CAPABLE MU_POINTER_ATTRIBUTE_ALLOWED_HANDLE_TYPES MU_POINTER_ATTRIBUTE_MEMPOOL_HANDLE MU_POINTER_ATTRIBUTE_IS_HW_DECOMPRESS_CAPABLE
- If ptr was not allocated by, mapped by, or registered with a MUcontext which uses UVA (Unified Virtual Addressing), MUSA_ERROR_INVALID_CONTEXT is returned.
Parameters
numAttributes(unsigned int): Number of attributes to queryattributes(MUpointer_attribute *): An array of attributes to query (numAttributes and the number of attributes in this array should match)data(void **): A two-dimensional array containing pointers to memory locations where the result of each attribute query will be written to.ptr(MUdeviceptr): Pointer to query
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_DEVICE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
3.16 Stream Management
muStreamCreate
MUresult muStreamCreate(MUstream *phStream, unsigned int Flags)
Description
- Create a stream.
- Creates a stream and returns a handle in phStream. The Flags argument determines behaviors of the stream.
- Valid values for Flags are: MU_STREAM_DEFAULT: Default stream creation flag. MU_STREAM_NON_BLOCKING: Specifies that work running in the created stream may run concurrently with work in stream 0 (the NULL stream), and that the created stream should perform no implicit synchronization with stream 0.
Parameters
phStream(MUstream *): Returned newly created streamFlags(unsigned int): Parameters for stream creation
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muStreamDestroy, muStreamCreateWithPriority, muGreenCtxStreamCreate, muStreamGetPriority, muStreamGetFlags, muStreamGetDevice muStreamWaitEvent, muStreamQuery, muStreamSynchronize, muStreamAddCallback, musaStreamCreate, musaStreamCreateWithFlags
muStreamCreateWithPriority
MUresult muStreamCreateWithPriority(MUstream *phStream, unsigned int flags, int priority)
Description
- Create a stream with the given priority.
- Creates a stream with the specified priority and returns a handle in phStream. This affects the scheduling priority of work in the stream. Priorities provide a hint to preferentially run work with higher priority when possible, but do not preempt already-running work or provide any other functional guarantee on execution order.
- priority follows a convention where lower numbers represent higher priorities. '0' represents default priority. The range of meaningful numerical priorities can be queried using muCtxGetStreamPriorityRange. If the specified priority is outside the numerical range returned by muCtxGetStreamPriorityRange, it will automatically be clamped to the lowest or the highest number in the range.
Parameters
phStream(MUstream *): Returned newly created streamflags(unsigned int): Flags for stream creation. See muStreamCreate for a list of valid flagspriority(int): Stream priority. Lower numbers represent higher priorities. See muCtxGetStreamPriorityRange for more information about meaningful stream priorities that can be passed.
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY
Note
- This function may also return error codes from previous, asynchronous launches.
- Stream priorities are supported only on GPUs with compute capability 3.5 or higher.
- In the current implementation, only compute kernels launched in priority streams are affected by the stream's priority. Stream priorities have no effect on host-to-device and device-to-host memory operations.
See also
- muStreamDestroy, muStreamCreate, muGreenCtxStreamCreate, muStreamGetPriority, muCtxGetStreamPriorityRange, muStreamGetFlags, muStreamGetDevice muStreamWaitEvent, muStreamQuery, muStreamSynchronize, muStreamAddCallback, musaStreamCreateWithPriority
muStreamGetPriority
MUresult muStreamGetPriority(MUstream hStream, int *priority)
Description
- Begins capture to CIG on a stream.
- Begin CIG (MUSA in Graphics) capture on hStream for the graphics API as provided in streamCigCaptureParams. When a stream is in CIG capture mode, all operations pushed into the stream will not be executed, but will instead be captured into a graphics API command list/command buffer. All kernel launches and memory copy/memory set operations on the CIG stream will be recorded. When the command list is executed by the graphics API, all the stream's operations will execute in order along with other graphics API commands in the command list.
- CIG stream capture may not be initiated if stream is MU_STREAM_LEGACY. Capture must be ended on the same stream in which it was initiated, and it may only be initiated if the stream is not already in CIG capture mode.
- The context must be also created in CIG mode previously, otherwise this operation will fail and MUSA_ERROR_INVALID_CONTEXT will be returned.
- Data from the graphics client can be shared with MUSA via the streamSharedData in streamCigCaptureParams. The format of streamSharedData is dependent on the type of the graphics client. For D3D12, streamSharedData is an ID3D12CommandList object pointer. The command list must be in ready state for recording commands whenever kernels are launched on the stream. The command list provided must belong to the graphics API device that the CIG context was created with, otherwise the behavior will be undefined.
- The stream object may not be destroyed until its associated command list has finished executing on the GPU. The command list/command buffer used for capture may not be submitted for execution before a call to muStreamEndCaptureToCig is made on the associated stream.
- Graphics resources to be accessed by work recorded on the CIG stream must use UAV barriers on the command list prior to recording work that accesses them on the stream.
- Resubmission of the same recorded command list is not allowed. Further more, care must be taken for the order of execution of the recorded MUSA work with regards to other MUSA work submitted under the same CIG context. Out-of-order execution can lead to device hangs or exceptions.
- CIG capture mode operates similarly to muStreamBeginCapture with the MU_STREAM_CAPTURE_MODE_RELAXED option. There are additional limitations to streams in CIG capture mode. The following functions are not allowed for CIG streams whether directly or indirectly via a recorded graph launch: muLaunchHostFunc muStreamAddCallback muStreamSynchronize muStreamWaitValue32 muStreamWaitValue64 muStreamBatchMemOp muStreamBeginCapture muStreamBeginCaptureToGraph muMemAllocAsync muMemFreeAsync
- End CIG capture on hStream. Capture must have been initiated on hStream via a call to muStreamBeginCaptureToCig. Once this function is called, hStream will exit CIG capture mode and return to its original state, thus removing all CIG stream restrictions. Also, the command list/command buffer that was associated with hStream in the previous call to muStreamBeginCaptureToCig is now allowed to be submitted for execution on the graphics API. However, the stream may not be destroyed until execution of the command list is fully done on the GPU. This requirements extends also to all streams dependant on the CIG stream (e.g. via event waits).
- Query the priority of a stream created using muStreamCreate, muStreamCreateWithPriority or muGreenCtxStreamCreate and return the priority in priority. Note that if the stream was created with a priority outside the numerical range returned by muCtxGetStreamPriorityRange, this function returns the clamped priority. See muStreamCreateWithPriority for details about priority clamping.
Parameters
hStream(MUstream): Handle to the stream to be queriedpriority(int *): Pointer to a signed integer in which the stream's priority is returned
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_NOT_SUPPORTED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_STREAM_CAPTURE_WRONG_THREAD
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_OUT_OF_MEMORY
Note
- Additional exported symbol names in scope:
muStreamGetPriority_ptsz. - This function may also return error codes from previous, asynchronous launches.
See also
- muStreamEndCaptureToCig, muStreamBeginCapture, muStreamWaitEvent, muStreamQuery, muStreamSynchronize, muStreamAddCallback
- muStreamBeginCaptureToCig
- muStreamDestroy, muStreamCreate, muStreamCreateWithPriority, muGreenCtxStreamCreate, muCtxGetStreamPriorityRange, muStreamGetFlags, muStreamGetDevice musaStreamGetPriority
muStreamGetDevice
MUresult muStreamGetDevice(MUstream hStream, MUdevice *device)
Description
- Returns the device handle of the stream.
- Returns in *device the device handle of the stream
Parameters
hStream(MUstream): Handle to the stream to be querieddevice(MUdevice *): Returns the device to which a stream belongs
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_OUT_OF_MEMORY
Note
- Additional exported symbol names in scope:
muStreamGetDevice_ptsz. - This function may also return error codes from previous, asynchronous launches.
See also
muStreamGetFlags
MUresult muStreamGetFlags(MUstream hStream, unsigned int *flags)
Description
- Query the flags of a given stream.
- Query the flags of a stream created using muStreamCreate, muStreamCreateWithPriority or muGreenCtxStreamCreate and return the flags in flags.
Parameters
hStream(MUstream): Handle to the stream to be queriedflags(unsigned int *): Pointer to an unsigned integer in which the stream's flags are returned The value returned in flags is a logical 'OR' of all flags that were used while creating this stream. See muStreamCreate for the list of valid flags
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_OUT_OF_MEMORY
Note
- Additional exported symbol names in scope:
muStreamGetFlags_ptsz. - This function may also return error codes from previous, asynchronous launches.
See also
- muStreamDestroy, muStreamCreate, muGreenCtxStreamCreate, muStreamGetPriority, musaStreamGetFlags muStreamGetDevice
muStreamGetId
MUresult muStreamGetId(MUstream hStream, unsigned long long *streamId)
Description
- Returns the unique Id associated with the stream handle supplied.
- Returns in streamId the unique Id which is associated with the given stream handle. The Id is unique for the life of the program.
- The stream handle hStream can refer to any of the following: a stream created via any of the MUSA driver APIs such as muStreamCreate and muStreamCreateWithPriority, or their runtime API equivalents such as musaStreamCreate, musaStreamCreateWithFlags and musaStreamCreateWithPriority. Passing an invalid handle will result in undefined behavior. any of the special streams such as the NULL stream, MU_STREAM_LEGACY and MU_STREAM_PER_THREAD. The runtime API equivalents of these are also accepted, which are NULL, musaStreamLegacy and musaStreamPerThread respectively.
Parameters
hStream(MUstream): Handle to the stream to be queriedstreamId(unsigned long long *): Pointer to store the Id of the stream
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muStreamGetId_ptsz. - This function may also return error codes from previous, asynchronous launches.
See also
muStreamGetCtx
MUresult muStreamGetCtx(MUstream hStream, MUcontext *pctx)
Description
- Query the context associated with a stream.
- Returns the MUSA context that the stream is associated with.
- Note there is a later version of this API, muStreamGetCtx_v2. It will supplant this version in MUSA 13.0. It is recommended to use muStreamGetCtx_v2 till then as this version will return MUSA_ERROR_NOT_SUPPORTED for streams created via the API muGreenCtxStreamCreate.
- The stream handle hStream can refer to any of the following: a stream created via any of the MUSA driver APIs such as muStreamCreate and muStreamCreateWithPriority, or their runtime API equivalents such as musaStreamCreate, musaStreamCreateWithFlags and musaStreamCreateWithPriority. The returned context is the context that was active in the calling thread when the stream was created. Passing an invalid handle will result in undefined behavior. any of the special streams such as the NULL stream, MU_STREAM_LEGACY and MU_STREAM_PER_THREAD. The runtime API equivalents of these are also accepted, which are NULL, musaStreamLegacy and musaStreamPerThread respectively. Specifying any of the special handles will return the context current to the calling thread. If no context is current to the calling thread, MUSA_ERROR_INVALID_CONTEXT is returned.
Parameters
hStream(MUstream): Handle to the stream to be queriedpctx(MUcontext *): Returned context associated with the stream
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_SUPPORTED
Note
- Additional exported symbol names in scope:
muStreamGetCtx_ptsz. - This function may also return error codes from previous, asynchronous launches.
See also
- muStreamDestroy, muStreamCreateWithPriority, muStreamGetPriority, muStreamGetFlags, muStreamGetDevice muStreamWaitEvent, muStreamQuery, muStreamSynchronize, muStreamAddCallback, musaStreamCreate, muStreamGetCtx_v2, musaStreamCreateWithFlags
muStreamGetCtx_v2
MUresult muStreamGetCtx_v2(MUstream hStream, MUcontext *pCtx, MUgreenCtx *pGreenCtx)
Description
- Query the contexts associated with a stream.
- Returns the contexts that the stream is associated with.
- If the stream is associated with a green context, the API returns the green context in pGreenCtx and the primary context of the associated device in pCtx.
- If the stream is associated with a regular context, the API returns the regular context in pCtx and NULL in pGreenCtx.
- The stream handle hStream can refer to any of the following: a stream created via any of the MUSA driver APIs such as muStreamCreate, muStreamCreateWithPriority and muGreenCtxStreamCreate, or their runtime API equivalents such as musaStreamCreate, musaStreamCreateWithFlags and musaStreamCreateWithPriority. Passing an invalid handle will result in undefined behavior. any of the special streams such as the NULL stream, MU_STREAM_LEGACY and MU_STREAM_PER_THREAD. The runtime API equivalents of these are also accepted, which are NULL, musaStreamLegacy and musaStreamPerThread respectively. If any of the special handles are specified, the API will operate on the context current to the calling thread. If a green context (that was converted via muCtxFromGreenCtx() before setting it current) is current to the calling thread, the API will return the green context in pGreenCtx and the primary context of the associated device in pCtx. If a regular context is current, the API returns the regular context in pCtx and NULL in pGreenCtx. Note that specifying MU_STREAM_PER_THREAD or musaStreamPerThread will return MUSA_ERROR_INVALID_HANDLE if a green context is current to the calling thread. If no context is current to the calling thread, MUSA_ERROR_INVALID_CONTEXT is returned.
Parameters
hStream(MUstream): Handle to the stream to be queriedpCtx(MUcontext *): Returned regular context associated with the streampGreenCtx(MUgreenCtx *): Returned green context if the stream is associated with a green context or NULL if not
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muStreamDestroy, muStreamCreate muStreamCreateWithPriority, muGreenCtxStreamCreate, muStreamGetPriority, muStreamGetFlags, muStreamGetDevice muStreamWaitEvent, muStreamQuery, muStreamSynchronize, muStreamAddCallback, musaStreamCreate, musaStreamCreateWithFlags,
muStreamWaitEvent
MUresult muStreamWaitEvent(MUstream hStream, MUevent hEvent, unsigned int Flags)
Description
- Make a compute stream wait on an event.
- Makes all future work submitted to hStream wait for all work captured in hEvent. See muEventRecord() for details on what is captured by an event. The synchronization will be performed efficiently on the device when applicable. hEvent may be from a different context or device than hStream.
- flags include: MU_EVENT_WAIT_DEFAULT: Default event creation flag. MU_EVENT_WAIT_EXTERNAL: Event is captured in the graph as an external event node when performing stream capture. This flag is invalid outside of stream capture.
Parameters
hStream(MUstream): Stream to waithEvent(MUevent): Event to wait on (may not be NULL)Flags(unsigned int): See MUevent_capture_flags
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muStreamWaitEvent_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the default-stream note for NULL stream semantics.
See also
- muStreamCreate, muEventRecord, muStreamQuery, muStreamSynchronize, muStreamAddCallback, muStreamDestroy, musaStreamWaitEvent
muStreamAddCallback
MUresult muStreamAddCallback(MUstream hStream, MUstreamCallback callback, void *userData, unsigned int flags)
Description
- Add a callback to a compute stream.
- The callback may be passed MUSA_SUCCESS or an error code. In the event of a device error, all subsequently executed callbacks will receive an appropriate MUresult.
- Callbacks must not make any MUSA API calls. Attempting to use a MUSA API will result in MUSA_ERROR_NOT_PERMITTED. Callbacks must not perform any synchronization that may depend on outstanding device work or other callbacks that are not mandated to run earlier. Callbacks without a mandated order (in independent streams) execute in undefined order and may be serialized.
- For the purposes of Unified Memory, callback execution makes a number of guarantees: The callback stream is considered idle for the duration of the callback. Thus, for example, a callback may always use memory attached to the callback stream. The start of execution of a callback has the same effect as synchronizing an event recorded in the same stream immediately prior to the callback. It thus synchronizes streams which have been "joined" prior to the callback. Adding device work to any stream does not have the effect of making the stream active until all preceding host functions and stream callbacks have executed. Thus, for example, a callback might use global attached memory even if work has been added to another stream, if the work has been ordered behind the callback with an event. Completion of a callback does not cause a stream to become active except as described above. The callback stream will remain idle if no device work follows the callback, and will remain idle across consecutive callbacks without device work in between. Thus, for example, stream synchronization can be done by signaling from a callback at the end of the stream.
Parameters
hStream(MUstream): Stream to add callback tocallback(MUstreamCallback): The function to call once preceding stream operations are completeuserData(void *): User specified data to be passed to the callback functionflags(unsigned int): Reserved for future use, must be 0
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_SUPPORTED
Note
- Additional exported symbol names in scope:
muStreamAddCallback_ptsz. - This function is slated for eventual deprecation and removal. If you do not require the callback to execute in case of a device error, consider using muLaunchHostFunc. Additionally, this function is not supported with muStreamBeginCapture and muStreamEndCapture, unlike muLaunchHostFunc.
- This function may also return error codes from previous, asynchronous launches.
- See the default-stream note for NULL stream semantics.
See also
- muStreamCreate, muStreamQuery, muStreamSynchronize, muStreamWaitEvent, muStreamDestroy, muMemAllocManaged, muStreamAttachMemAsync, muLaunchHostFunc, musaStreamAddCallback
muStreamBeginCapture
MUresult muStreamBeginCapture(MUstream hStream, MUstreamCaptureMode mode)
Description
- Begins graph capture on a stream.
- Begin graph capture on hStream. When a stream is in capture mode, all operations pushed into the stream will not be executed, but will instead be captured into a graph, which will be returned via muStreamEndCapture. Capture may not be initiated if stream is MU_STREAM_LEGACY. Capture must be ended on the same stream in which it was initiated, and it may only be initiated if the stream is not already in capture mode. The capture mode may be queried via muStreamIsCapturing. A unique id representing the capture sequence may be queried via muStreamGetCaptureInfo.
- If mode is not MU_STREAM_CAPTURE_MODE_RELAXED, muStreamEndCapture must be called on this stream from the same thread.
Parameters
hStream(MUstream): Stream in which to initiate capturemode(MUstreamCaptureMode): Controls the interaction of this capture sequence with other API calls that are potentially unsafe. For more details see muThreadExchangeStreamCaptureMode.
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muStreamBeginCapture_v2. - Kernels captured using this API must not use texture and surface references. Reading or writing through any texture or surface reference is undefined behavior. This restriction does not apply to texture and surface objects.
- This function may also return error codes from previous, asynchronous launches.
See also
muStreamBeginCaptureToGraph
MUresult muStreamBeginCaptureToGraph(MUstream hStream, MUgraph hGraph, const MUgraphNode *dependencies, const MUgraphEdgeData *dependencyData, size_t numDependencies, MUstreamCaptureMode mode)
Description
- Begins graph capture on a stream to an existing graph.
- Begin graph capture on hStream, placing new nodes into an existing graph. When a stream is in capture mode, all operations pushed into the stream will not be executed, but will instead be captured into hGraph. The graph will not be instantiable until the user calls muStreamEndCapture.
- Capture may not be initiated if stream is MU_STREAM_LEGACY. Capture must be ended on the same stream in which it was initiated, and it may only be initiated if the stream is not already in capture mode. The capture mode may be queried via muStreamIsCapturing. A unique id representing the capture sequence may be queried via muStreamGetCaptureInfo.
- If mode is not MU_STREAM_CAPTURE_MODE_RELAXED, muStreamEndCapture must be called on this stream from the same thread.
Parameters
hStream(MUstream): Stream in which to initiate capture.hGraph(MUgraph): Graph to capture into.dependencies(const MUgraphNode *): Dependencies of the first node captured in the stream. Can be NULL if numDependencies is 0.dependencyData(const MUgraphEdgeData *): Optional array of data associated with each dependency.numDependencies(size_t): Number of dependencies.mode(MUstreamCaptureMode): Controls the interaction of this capture sequence with other API calls that are potentially unsafe. For more details see muThreadExchangeStreamCaptureMode.
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE
Note
- Kernels captured using this API must not use texture and surface references. Reading or writing through any texture or surface reference is undefined behavior. This restriction does not apply to texture and surface objects.
- This function may also return error codes from previous, asynchronous launches.
See also
- muStreamBeginCapture, muStreamCreate, muStreamIsCapturing, muStreamEndCapture, muThreadExchangeStreamCaptureMode, muGraphAddNode,
muThreadExchangeStreamCaptureMode
MUresult muThreadExchangeStreamCaptureMode(MUstreamCaptureMode *mode)
Description
- Swaps the stream capture interaction mode for a thread.
- Sets the calling thread's stream capture interaction mode to the value contained in *mode, and overwrites *mode with the previous mode for the thread. To facilitate deterministic behavior across function or module boundaries, callers are encouraged to use this API in a push-pop fashion:MUstreamCaptureModemode=desiredMode; muThreadExchangeStreamCaptureMode(&mode); ... muThreadExchangeStreamCaptureMode(&mode);//restorepreviousmode
- During stream capture (see muStreamBeginCapture), some actions, such as a call to musaMalloc, may be unsafe. In the case of musaMalloc, the operation is not enqueued asynchronously to a stream, and is not observed by stream capture. Therefore, if the sequence of operations captured via muStreamBeginCapture depended on the allocation being replayed whenever the graph is launched, the captured graph would be invalid.
- Therefore, stream capture places restrictions on API calls that can be made within or concurrently to a muStreamBeginCapture-muStreamEndCapture sequence. This behavior can be controlled via this API and flags to muStreamBeginCapture.
- A thread's mode is one of the following: MU_STREAM_CAPTURE_MODE_GLOBAL: This is the default mode. If the local thread has an ongoing capture sequence that was not initiated with MU_STREAM_CAPTURE_MODE_RELAXED at muStreamBeginCapture, or if any other thread has a concurrent capture sequence initiated with MU_STREAM_CAPTURE_MODE_GLOBAL, this thread is prohibited from potentially unsafe API calls. MU_STREAM_CAPTURE_MODE_THREAD_LOCAL: If the local thread has an ongoing capture sequence not initiated with MU_STREAM_CAPTURE_MODE_RELAXED, it is prohibited from potentially unsafe API calls. Concurrent capture sequences in other threads are ignored. MU_STREAM_CAPTURE_MODE_RELAXED: The local thread is not prohibited from potentially unsafe API calls. Note that the thread is still prohibited from API calls which necessarily conflict with stream capture, for example, attempting muEventQuery on an event that was last recorded inside a capture sequence.
Parameters
mode(MUstreamCaptureMode *): Pointer to mode value to swap with the current mode
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muStreamEndCapture
MUresult muStreamEndCapture(MUstream hStream, MUgraph *phGraph)
Description
- Ends capture on a stream, returning the captured graph.
- End capture on hStream, returning the captured graph via phGraph. Capture must have been initiated on hStream via a call to muStreamBeginCapture. If capture was invalidated, due to a violation of the rules of stream capture, then a NULL graph will be returned.
- If the mode argument to muStreamBeginCapture was not MU_STREAM_CAPTURE_MODE_RELAXED, this call must be from the same thread as muStreamBeginCapture.
Parameters
hStream(MUstream): Stream to queryphGraph(MUgraph *): The captured graph
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_STREAM_CAPTURE_WRONG_THREAD
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muStreamIsCapturing
MUresult muStreamIsCapturing(MUstream hStream, MUstreamCaptureStatus *captureStatus)
Description
- Returns a stream's capture status.
- Return the capture status of hStream via captureStatus. After a successful call, *captureStatus will contain one of the following: MU_STREAM_CAPTURE_STATUS_NONE: The stream is not capturing. MU_STREAM_CAPTURE_STATUS_ACTIVE: The stream is capturing. MU_STREAM_CAPTURE_STATUS_INVALIDATED: The stream was capturing but an error has invalidated the capture sequence. The capture sequence must be terminated with muStreamEndCapture on the stream where it was initiated in order to continue using hStream.
- Note that, if this is called on MU_STREAM_LEGACY (the "null stream") while a blocking stream in the same context is capturing, it will return MUSA_ERROR_STREAM_CAPTURE_IMPLICIT and *captureStatus is unspecified after the call. The blocking stream capture is not invalidated.
- When a blocking stream is capturing, the legacy stream is in an unusable state until the blocking stream capture is terminated. The legacy stream is not supported for stream capture, but attempted use would have an implicit dependency on the capturing stream(s).
Parameters
hStream(MUstream): Stream to querycaptureStatus(MUstreamCaptureStatus *): Returns the stream's capture status
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_STREAM_CAPTURE_IMPLICIT
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muStreamGetCaptureInfo
MUresult muStreamGetCaptureInfo(MUstream hStream, MUstreamCaptureStatus *captureStatus_out, muuint64_t *id_out, MUgraph *graph_out, const MUgraphNode **dependencies_out, size_t *numDependencies_out)
Description
- Query a stream's capture state.
- Query stream state related to stream capture.
- If called on MU_STREAM_LEGACY (the "null stream") while a stream not created with MU_STREAM_NON_BLOCKING is capturing, returns MUSA_ERROR_STREAM_CAPTURE_IMPLICIT.
- Valid data (other than capture status) is returned only if both of the following are true: the call returns MUSA_SUCCESS the returned capture status is MU_STREAM_CAPTURE_STATUS_ACTIVE
Parameters
hStream(MUstream): The stream to querycaptureStatus_out(MUstreamCaptureStatus *): Location to return the capture status of the stream; requiredid_out(muuint64_t *): Optional location to return an id for the capture sequence, which is unique over the lifetime of the processgraph_out(MUgraph *): Optional location to return the graph being captured into. All operations other than destroy and node removal are permitted on the graph while the capture sequence is in progress. This API does not transfer ownership of the graph, which is transferred or destroyed at muStreamEndCapture. Note that the graph handle may be invalidated before end of capture for certain errors. Nodes that are or become unreachable from the original stream at muStreamEndCapture due to direct actions on the graph do not trigger MUSA_ERROR_STREAM_CAPTURE_UNJOINED.dependencies_out(const MUgraphNode **): Optional location to store a pointer to an array of nodes. The next node to be captured in the stream will depend on this set of nodes, absent operations such as event wait which modify this set. The array pointer is valid until the next API call which operates on the stream or until the capture is terminated. The node handles may be copied out and are valid until they or the graph is destroyed. The driver-owned array may also be passed directly to APIs that operate on the graph (not the stream) without copying.numDependencies_out(size_t *): Optional location to store the size of the array returned in dependencies_out.
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_STREAM_CAPTURE_IMPLICIT
Note
- Additional exported symbol names in scope:
muStreamGetCaptureInfo_v2. - This function may also return error codes from previous, asynchronous launches.
- Graph objects are not thread-safe.
See also
- muStreamGetCaptureInfo_v3 muStreamBeginCapture, muStreamIsCapturing, muStreamUpdateCaptureDependencies
muStreamGetCaptureInfo_v3
MUresult muStreamGetCaptureInfo_v3(MUstream hStream, MUstreamCaptureStatus *captureStatus_out, muuint64_t *id_out, MUgraph *graph_out, const MUgraphNode **dependencies_out, const MUgraphEdgeData **edgeData_out, size_t *numDependencies_out)
Description
- Query a stream's capture state (12.3+)
- Query stream state related to stream capture.
- If called on MU_STREAM_LEGACY (the "null stream") while a stream not created with MU_STREAM_NON_BLOCKING is capturing, returns MUSA_ERROR_STREAM_CAPTURE_IMPLICIT.
- Valid data (other than capture status) is returned only if both of the following are true: the call returns MUSA_SUCCESS the returned capture status is MU_STREAM_CAPTURE_STATUS_ACTIVE
- If edgeData_out is non-NULL then dependencies_out must be as well. If dependencies_out is non-NULL and edgeData_out is NULL, but there is non-zero edge data for one or more of the current stream dependencies, the call will return MUSA_ERROR_LOSSY_QUERY.
Parameters
hStream(MUstream): The stream to querycaptureStatus_out(MUstreamCaptureStatus *): Location to return the capture status of the stream; requiredid_out(muuint64_t *): Optional location to return an id for the capture sequence, which is unique over the lifetime of the processgraph_out(MUgraph *): Optional location to return the graph being captured into. All operations other than destroy and node removal are permitted on the graph while the capture sequence is in progress. This API does not transfer ownership of the graph, which is transferred or destroyed at muStreamEndCapture. Note that the graph handle may be invalidated before end of capture for certain errors. Nodes that are or become unreachable from the original stream at muStreamEndCapture due to direct actions on the graph do not trigger MUSA_ERROR_STREAM_CAPTURE_UNJOINED.dependencies_out(const MUgraphNode **): Optional location to store a pointer to an array of nodes. The next node to be captured in the stream will depend on this set of nodes, absent operations such as event wait which modify this set. The array pointer is valid until the next API call which operates on the stream or until the capture is terminated. The node handles may be copied out and are valid until they or the graph is destroyed. The driver-owned array may also be passed directly to APIs that operate on the graph (not the stream) without copying.edgeData_out(const MUgraphEdgeData **): Optional location to store a pointer to an array of graph edge data. This array parallels dependencies_out; the next node to be added has an edge to dependencies_out[i] with annotation edgeData_out[i] for each i. The array pointer is valid until the next API call which operates on the stream or until the capture is terminated.numDependencies_out(size_t *): Optional location to store the size of the array returned in dependencies_out.
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_STREAM_CAPTURE_IMPLICIT, MUSA_ERROR_LOSSY_QUERY
Note
- This function may also return error codes from previous, asynchronous launches.
- Graph objects are not thread-safe.
See also
muStreamUpdateCaptureDependencies
MUresult muStreamUpdateCaptureDependencies(MUstream hStream, MUgraphNode *dependencies, size_t numDependencies, unsigned int flags)
Description
- Update the set of dependencies in a capturing stream (11.3+)
- Modifies the dependency set of a capturing stream. The dependency set is the set of nodes that the next captured node in the stream will depend on.
- Valid flags are MU_STREAM_ADD_CAPTURE_DEPENDENCIES and MU_STREAM_SET_CAPTURE_DEPENDENCIES. These control whether the set passed to the API is added to the existing set or replaces it. A flags value of 0 defaults to MU_STREAM_ADD_CAPTURE_DEPENDENCIES.
- Nodes that are removed from the dependency set via this API do not result in MUSA_ERROR_STREAM_CAPTURE_UNJOINED if they are unreachable from the stream at muStreamEndCapture.
- Returns MUSA_ERROR_ILLEGAL_STATE if the stream is not capturing.
- This API is new in MUSA 11.3. Developers requiring compatibility across minor versions to MUSA 11.0 should not use this API or provide a fallback.
Parameters
hStream(MUstream): The stream to updatedependencies(MUgraphNode *): The set of dependencies to addnumDependencies(size_t): The size of the dependencies arrayflags(unsigned int): See above
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_ILLEGAL_STATE
See also
muStreamUpdateCaptureDependencies_v2
MUresult muStreamUpdateCaptureDependencies_v2(MUstream hStream, MUgraphNode *dependencies, const MUgraphEdgeData *dependencyData, size_t numDependencies, unsigned int flags)
Description
- Update the set of dependencies in a capturing stream (12.3+)
- Modifies the dependency set of a capturing stream. The dependency set is the set of nodes that the next captured node in the stream will depend on along with the edge data for those dependencies.
- Valid flags are MU_STREAM_ADD_CAPTURE_DEPENDENCIES and MU_STREAM_SET_CAPTURE_DEPENDENCIES. These control whether the set passed to the API is added to the existing set or replaces it. A flags value of 0 defaults to MU_STREAM_ADD_CAPTURE_DEPENDENCIES.
- Nodes that are removed from the dependency set via this API do not result in MUSA_ERROR_STREAM_CAPTURE_UNJOINED if they are unreachable from the stream at muStreamEndCapture.
- Returns MUSA_ERROR_ILLEGAL_STATE if the stream is not capturing.
Parameters
hStream(MUstream): The stream to updatedependencies(MUgraphNode *): The set of dependencies to adddependencyData(const MUgraphEdgeData *): Optional array of data associated with each dependency.numDependencies(size_t): The size of the dependencies arrayflags(unsigned int): See above
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_ILLEGAL_STATE
See also
muStreamAttachMemAsync
MUresult muStreamAttachMemAsync(MUstream hStream, MUdeviceptr dptr, size_t length, unsigned int flags)
Description
- Attach memory to a stream asynchronously.
- Enqueues an operation in hStream to specify stream association of length bytes of memory starting from dptr. This function is a stream-ordered operation, meaning that it is dependent on, and will only take effect when, previous work in stream has completed. Any previous association is automatically replaced.
- dptr must point to one of the following types of memories: managed memory declared using the managed keyword or allocated with muMemAllocManaged. a valid host-accessible region of system-allocated pageable memory. This type of memory may only be specified if the device associated with the stream reports a non-zero value for the device attribute MU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS.
- For managed allocations, length must be either zero or the entire allocation's size. Both indicate that the entire allocation's stream association is being changed. Currently, it is not possible to change stream association for a portion of a managed allocation.
- For pageable host allocations, length must be non-zero.
- The stream association is specified using flags which must be one of MUmemAttach_flags. If the MU_MEM_ATTACH_GLOBAL flag is specified, the memory can be accessed by any stream on any device. If the MU_MEM_ATTACH_HOST flag is specified, the program makes a guarantee that it won't access the memory on the device from any stream on a device that has a zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS. If the MU_MEM_ATTACH_SINGLE flag is specified and hStream is associated with a device that has a zero value for the device attribute MU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS, the program makes a guarantee that it will only access the memory on the device from hStream. It is illegal to attach singly to the NULL stream, because the NULL stream is a virtual global stream and not a specific stream. An error will be returned in this case.
- When memory is associated with a single stream, the Unified Memory system will allow CPU access to this memory region so long as all operations in hStream have completed, regardless of whether other streams are active. In effect, this constrains exclusive ownership of the managed memory region by an active GPU to per-stream activity instead of whole-GPU activity.
- Accessing memory on the device from streams that are not associated with it will produce undefined results. No error checking is performed by the Unified Memory system to ensure that kernels launched into other streams do not access this region.
- It is a program's responsibility to order calls to muStreamAttachMemAsync via events, synchronization or other means to ensure legal access to memory at all times. Data visibility and coherency will be changed appropriately for all kernels which follow a stream-association change.
- If hStream is destroyed while data is associated with it, the association is removed and the association reverts to the default visibility of the allocation as specified at muMemAllocManaged. For managed variables, the default association is always MU_MEM_ATTACH_GLOBAL. Note that destroying a stream is an asynchronous operation, and as a result, the change to default association won't happen until all work in the stream has completed.
Parameters
hStream(MUstream): Stream in which to enqueue the attach operationdptr(MUdeviceptr): Pointer to memory (must be a pointer to managed memory or to a valid host-accessible region of system-allocated pageable memory)length(size_t): Length of memoryflags(unsigned int): Must be one of MUmemAttach_flags
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_SUPPORTED
Note
- Additional exported symbol names in scope:
muStreamAttachMemAsync_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the default-stream note for NULL stream semantics.
See also
- muStreamCreate, muStreamQuery, muStreamSynchronize, muStreamWaitEvent, muStreamDestroy, muMemAllocManaged, musaStreamAttachMemAsync
muStreamQuery
MUresult muStreamQuery(MUstream hStream)
Description
- Determine status of a compute stream.
- Returns MUSA_SUCCESS if all operations in the stream specified by hStream have completed, or MUSA_ERROR_NOT_READY if not.
- For the purposes of Unified Memory, a return value of MUSA_SUCCESS is equivalent to having called muStreamSynchronize().
Parameters
hStream(MUstream): Stream to query status of
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_READY
Note
- Additional exported symbol names in scope:
muStreamQuery_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the default-stream note for NULL stream semantics.
See also
- muStreamCreate, muStreamWaitEvent, muStreamDestroy, muStreamSynchronize, muStreamAddCallback, musaStreamQuery
muStreamSynchronize
MUresult muStreamSynchronize(MUstream hStream)
Description
- Wait until a stream's tasks are completed.
- Waits until the device has completed all operations in the stream specified by hStream. If the context was created with the MU_CTX_SCHED_BLOCKING_SYNC flag, the CPU thread will block until the stream is finished with all of its tasks.
Parameters
hStream(MUstream): Stream to wait for
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muStreamSynchronize_ptsz.
See also
- muStreamCreate, muStreamDestroy, muStreamWaitEvent, muStreamQuery, muStreamAddCallback, musaStreamSynchronize
muStreamDestroy
MUresult muStreamDestroy(MUstream hStream)
Description
- Destroys a stream.
- Destroys the stream specified by hStream.
- In case the device is still doing work in the stream hStream when muStreamDestroy() is called, the function will return immediately and the resources associated with hStream will be released automatically once the device has completed all work in hStream.
Parameters
hStream(MUstream): Stream to destroy
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muStreamDestroy_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muStreamCreate, muStreamWaitEvent, muStreamQuery, muStreamSynchronize, muStreamAddCallback, musaStreamDestroy
muStreamCopyAttributes
MUresult muStreamCopyAttributes(MUstream dst, MUstream src)
Description
- Copies attributes from source stream to destination stream.
- Copies attributes from source stream src to destination stream dst. Both streams must have the same context.
Parameters
dst(MUstream): Destination streamsrc(MUstream): Source stream For list of attributes see MUstreamAttrID
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- MUaccessPolicyWindow
muStreamGetAttribute
MUresult muStreamGetAttribute(MUstream hStream, MUstreamAttrID attr, MUstreamAttrValue *value_out)
Description
- Queries stream attribute.
- Queries attribute attr from hStream and stores it in corresponding member of value_out.
Parameters
hStream(MUstream)attr(MUstreamAttrID)value_out(MUstreamAttrValue *)
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- MUaccessPolicyWindow
muStreamSetAttribute
MUresult muStreamSetAttribute(MUstream hStream, MUstreamAttrID attr, const MUstreamAttrValue *value)
Description
- Sets stream attribute.
- Sets attribute attr on hStream from corresponding attribute of value. The updated attribute will be applied to subsequent work submitted to the stream. It will not affect previously submitted work.
Parameters
hStream(MUstream)attr(MUstreamAttrID)value(const MUstreamAttrValue *)
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- MUaccessPolicyWindow
3.17 Event Management
muEventCreate
MUresult muEventCreate(MUevent *phEvent, unsigned int Flags)
Description
- Creates an event.
- Creates an event *phEvent for the current context with the flags specified via Flags. Valid flags include: MU_EVENT_DEFAULT: Default event creation flag. MU_EVENT_BLOCKING_SYNC: Specifies that the created event should use blocking synchronization. A CPU thread that uses muEventSynchronize() to wait on an event created with this flag will block until the event has actually been recorded. MU_EVENT_DISABLE_TIMING: Specifies that the created event does not need to record timing data. Events created with this flag specified and the MU_EVENT_BLOCKING_SYNC flag not specified will provide the best performance when used with muStreamWaitEvent() and muEventQuery(). MU_EVENT_INTERPROCESS: Specifies that the created event may be used as an interprocess event by muIpcGetEventHandle(). MU_EVENT_INTERPROCESS must be specified along with MU_EVENT_DISABLE_TIMING.
Parameters
phEvent(MUevent *): Returns newly created eventFlags(unsigned int): Event creation flags
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_OUT_OF_MEMORY
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muEventRecord, muEventQuery, muEventSynchronize, muEventDestroy, muEventElapsedTime, musaEventCreate, musaEventCreateWithFlags
muEventRecord
MUresult muEventRecord(MUevent hEvent, MUstream hStream)
Description
- Records an event.
- Captures in hEvent the contents of hStream at the time of this call. hEvent and hStream must be from the same context otherwise MUSA_ERROR_INVALID_HANDLE is returned. Calls such as muEventQuery() or muStreamWaitEvent() will then examine or wait for completion of the work that was captured. Uses of hStream after this call do not modify hEvent. See note on default stream behavior for what is captured in the default case.
- muEventRecord() can be called multiple times on the same event and will overwrite the previously captured state. Other APIs such as muStreamWaitEvent() use the most recently captured state at the time of the API call, and are not affected by later calls to muEventRecord(). Before the first call to muEventRecord(), an event represents an empty set of work, so for example muEventQuery() would return MUSA_SUCCESS.
Parameters
hEvent(MUevent): Event to recordhStream(MUstream): Stream to record event for
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muEventRecord_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the default-stream note for NULL stream semantics.
See also
- muEventCreate, muEventQuery, muEventSynchronize, muStreamWaitEvent, muEventDestroy, muEventElapsedTime, musaEventRecord, muEventRecordWithFlags
muEventRecordWithFlags
MUresult muEventRecordWithFlags(MUevent hEvent, MUstream hStream, unsigned int flags)
Description
- Records an event.
- Captures in hEvent the contents of hStream at the time of this call. hEvent and hStream must be from the same context otherwise MUSA_ERROR_INVALID_HANDLE is returned. Calls such as muEventQuery() or muStreamWaitEvent() will then examine or wait for completion of the work that was captured. Uses of hStream after this call do not modify hEvent. See note on default stream behavior for what is captured in the default case.
- muEventRecordWithFlags() can be called multiple times on the same event and will overwrite the previously captured state. Other APIs such as muStreamWaitEvent() use the most recently captured state at the time of the API call, and are not affected by later calls to muEventRecordWithFlags(). Before the first call to muEventRecordWithFlags(), an event represents an empty set of work, so for example muEventQuery() would return MUSA_SUCCESS.
- flags include: MU_EVENT_RECORD_DEFAULT: Default event creation flag. MU_EVENT_RECORD_EXTERNAL: Event is captured in the graph as an external event node when performing stream capture. This flag is invalid outside of stream capture.
Parameters
hEvent(MUevent): Event to recordhStream(MUstream): Stream to record event forflags(unsigned int): See MUevent_capture_flags
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_INVALID_VALUE
Note
- Additional exported symbol names in scope:
muEventRecordWithFlags_ptsz. - This function may also return error codes from previous, asynchronous launches.
- See the default-stream note for NULL stream semantics.
See also
- muEventCreate, muEventQuery, muEventSynchronize, muStreamWaitEvent, muEventDestroy, muEventElapsedTime, muEventRecord, musaEventRecord
muEventQuery
MUresult muEventQuery(MUevent hEvent)
Description
- Queries an event's status.
- Queries the status of all work currently captured by hEvent. See muEventRecord() for details on what is captured by an event.
- Returns MUSA_SUCCESS if all captured work has been completed, or MUSA_ERROR_NOT_READY if any captured work is incomplete.
- For the purposes of Unified Memory, a return value of MUSA_SUCCESS is equivalent to having called muEventSynchronize().
Parameters
hEvent(MUevent): Event to query
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_NOT_READY
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muEventCreate, muEventRecord, muEventSynchronize, muEventDestroy, muEventElapsedTime, musaEventQuery
muEventSynchronize
MUresult muEventSynchronize(MUevent hEvent)
Description
- Waits for an event to complete.
- Waits until the completion of all work currently captured in hEvent. See muEventRecord() for details on what is captured by an event.
- Waiting for an event that was created with the MU_EVENT_BLOCKING_SYNC flag will cause the calling CPU thread to block until the event has been completed by the device. If the MU_EVENT_BLOCKING_SYNC flag has not been set, then the CPU thread will busy-wait until the event has been completed by the device.
Parameters
hEvent(MUevent): Event to wait for
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muEventCreate, muEventRecord, muEventQuery, muEventDestroy, muEventElapsedTime, musaEventSynchronize
muEventDestroy
MUresult muEventDestroy(MUevent hEvent)
Description
- Destroys an event.
- Destroys the event specified by hEvent.
- An event may be destroyed before it is complete (i.e., while muEventQuery() would return MUSA_ERROR_NOT_READY). In this case, the call does not block on completion of the event, and any associated resources will automatically be released asynchronously at completion.
Parameters
hEvent(MUevent): Event to destroy
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE
Note
- Additional exported symbol names in scope:
muEventDestroy_v2. - This function may also return error codes from previous, asynchronous launches.
See also
- muEventCreate, muEventRecord, muEventQuery, muEventSynchronize, muEventElapsedTime, musaEventDestroy
muEventElapsedTime
MUresult muEventElapsedTime(float *pMilliseconds, MUevent hStart, MUevent hEnd)
Description
- Computes the elapsed time between two events.
- Computes the elapsed time between two events (in milliseconds with a resolution of around 0.5 microseconds).
- If either event was last recorded in a non-NULL stream, the resulting time may be greater than expected (even if both used the same stream handle). This happens because the muEventRecord() operation takes place asynchronously and there is no guarantee that the measured latency is actually just between the two events. Any number of other different stream operations could execute in between the two measured events, thus altering the timing in a significant way.
- If muEventRecord() has not been called on either event then MUSA_ERROR_INVALID_HANDLE is returned. If muEventRecord() has been called on both events but one or both of them has not yet been completed (that is, muEventQuery() would return MUSA_ERROR_NOT_READY on at least one of the events), MUSA_ERROR_NOT_READY is returned. If either event was created with the MU_EVENT_DISABLE_TIMING flag, then this function will return MUSA_ERROR_INVALID_HANDLE.
- Note there is a later version of this API, muEventElapsedTime_v2. It will supplant this version in MUSA 13.0, which is retained for minor version compatibility.
Parameters
pMilliseconds(float *): Time between hStart and hEnd in mshStart(MUevent): Starting eventhEnd(MUevent): Ending event
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_READY, MUSA_ERROR_UNKNOWN
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muEventCreate, muEventRecord, muEventQuery, muEventSynchronize, muEventDestroy, musaEventElapsedTime
muEventElapsedTime_v2
MUresult muEventElapsedTime_v2(float *pMilliseconds, MUevent hStart, MUevent hEnd)
Description
- Computes the elapsed time between two events.
- Computes the elapsed time between two events (in milliseconds with a resolution of around 0.5 microseconds). Note this API is not guaranteed to return the latest errors for pending work. As such this API is intended to serve as an elapsed time calculation only and any polling for completion on the events to be compared should be done with muEventQuery instead.
- If either event was last recorded in a non-NULL stream, the resulting time may be greater than expected (even if both used the same stream handle). This happens because the muEventRecord() operation takes place asynchronously and there is no guarantee that the measured latency is actually just between the two events. Any number of other different stream operations could execute in between the two measured events, thus altering the timing in a significant way.
- If muEventRecord() has not been called on either event then MUSA_ERROR_INVALID_HANDLE is returned. If muEventRecord() has been called on both events but one or both of them has not yet been completed (that is, muEventQuery() would return MUSA_ERROR_NOT_READY on at least one of the events), MUSA_ERROR_NOT_READY is returned. If either event was created with the MU_EVENT_DISABLE_TIMING flag, then this function will return MUSA_ERROR_INVALID_HANDLE.
Parameters
pMilliseconds(float *): Time between hStart and hEnd in mshStart(MUevent): Starting eventhEnd(MUevent): Ending event
Returns
- MUSA_SUCCESS, MUSA_ERROR_DEINITIALIZED, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_CONTEXT, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_READY, MUSA_ERROR_UNKNOWN
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- muEventCreate, muEventRecord, muEventQuery, muEventSynchronize, muEventDestroy, musaEventElapsedTime
3.18 External Resource Interoperability
muImportExternalMemory
MUresult muImportExternalMemory(MUexternalMemory *extMem_out, const MUSA_EXTERNAL_MEMORY_HANDLE_DESC *memHandleDesc)
Description
- Imports an external memory object.
- Imports an externally allocated memory object and returns a handle to that in extMem_out.
- The properties of the handle being imported must be described in memHandleDesc. The MUSA_EXTERNAL_MEMORY_HANDLE_DESC structure is defined as follows:
typedef struct MUSA_EXTERNAL_MEMORY_HANDLE_DESC_st {
MUexternalMemoryHandleTypetype;
union {
int fd;
struct {
void *handle;
const void *name;
} win32;
const void *mtSciBufObject;
} handle;
unsigned long long size;
unsigned int flags;
} MUSA_EXTERNAL_MEMORY_HANDLE_DESC;
- where MUSA_EXTERNAL_MEMORY_HANDLE_DESC::type specifies the type of handle being imported. MUexternalMemoryHandleType is defined as:
typedef enum MUexternalMemoryHandleType_enum {
MU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD = 1,
MU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32 = 2,
MU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT = 3,
MU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP = 4,
MU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE = 5,
MU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_RESOURCE = 6,
MU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_RESOURCE_KMT = 7,
MU_EXTERNAL_MEMORY_HANDLE_TYPE_MTSCIBUF = 8,
} MUexternalMemoryHandleType;
- If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::type is MU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD, then MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::fd must be a valid file descriptor referencing a memory object. Ownership of the file descriptor is transferred to the MUSA driver when the handle is imported successfully. Performing any operations on the file descriptor after it is imported results in undefined behavior.
- If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::type is MU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32, then exactly one of MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::handle and MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::name must not be NULL. If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::handle is not NULL, then it must represent a valid shared NT handle that references a memory object. Ownership of this handle is not transferred to MUSA after the import operation, so the application must release the handle using the appropriate system call. If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::name is not NULL, then it must point to a NULL-terminated array of UTF-16 characters that refers to a memory object.
- If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::type is MU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT, then MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::handle must be non-NULL and MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::name must be NULL. The handle specified must be a globally shared KMT handle. This handle does not hold a reference to the underlying object, and thus will be invalid when all references to the memory object are destroyed.
- If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::type is MU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP, then exactly one of MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::handle and MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::name must not be NULL. If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::handle is not NULL, then it must represent a valid shared NT handle that is returned by ID3D12Device::CreateSharedHandle when referring to a ID3D12Heap object. This handle holds a reference to the underlying object. If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::name is not NULL, then it must point to a NULL-terminated array of UTF-16 characters that refers to a ID3D12Heap object.
- If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::type is MU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE, then exactly one of MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::handle and MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::name must not be NULL. If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::handle is not NULL, then it must represent a valid shared NT handle that is returned by ID3D12Device::CreateSharedHandle when referring to a ID3D12Resource object. This handle holds a reference to the underlying object. If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::name is not NULL, then it must point to a NULL-terminated array of UTF-16 characters that refers to a ID3D12Resource object.
- If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::type is MU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_RESOURCE, then MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::handle must represent a valid shared NT handle that is returned by IDXGIResource1::CreateSharedHandle when referring to a ID3D11Resource object. If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::name is not NULL, then it must point to a NULL-terminated array of UTF-16 characters that refers to a ID3D11Resource object.
- If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::type is MU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_RESOURCE_KMT, then MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::handle must represent a valid shared KMT handle that is returned by IDXGIResource::GetSharedHandle when referring to a ID3D11Resource object and MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::win32::name must be NULL.
- If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::type is MU_EXTERNAL_MEMORY_HANDLE_TYPE_MTSCIBUF, then MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::mtSciBufObject must be non-NULL and reference a valid NvSciBuf object. If the NvSciBuf object imported into MUSA is also mapped by other drivers, then the application must use muWaitExternalSemaphoresAsync or muSignalExternalSemaphoresAsync as appropriate barriers to maintain coherence between MUSA and the other drivers. See MUSA_EXTERNAL_SEMAPHORE_SIGNAL_SKIP_MTSCIBUF_MEMSYNC and MUSA_EXTERNAL_SEMAPHORE_WAIT_SKIP_MTSCIBUF_MEMSYNC for memory synchronization.
- If MUSA_EXTERNAL_MEMORY_HANDLE_DESC::type is MU_EXTERNAL_MEMORY_HANDLE_TYPE_DMABUF_FD, then MUSA_EXTERNAL_MEMORY_HANDLE_DESC::handle::fd must be a valid file descriptor referencing a dma_buf object and MUSA_EXTERNAL_MEMORY_HANDLE_DESC::flags must be zero. Importing a dma_buf object is supported only on Tegra Jetson platform starting with Thor series. Mapping an imported dma_buf object as MUSA mipmapped array using muExternalMemoryGetMappedMipmappedArray is not supported.
- The size of the memory object must be specified in MUSA_EXTERNAL_MEMORY_HANDLE_DESC::size.
- Specifying the flag MUSA_EXTERNAL_MEMORY_DEDICATED in MUSA_EXTERNAL_MEMORY_HANDLE_DESC::flags indicates that the resource is a dedicated resource. The definition of what a dedicated resource is outside the scope of this extension. This flag must be set if MUSA_EXTERNAL_MEMORY_HANDLE_DESC::type is one of the following: MU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE MU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_RESOURCE MU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_RESOURCE_KMT
Parameters
extMem_out(MUexternalMemory *): Returned handle to an external memory objectmemHandleDesc(const MUSA_EXTERNAL_MEMORY_HANDLE_DESC *): Memory import handle descriptor
Returns
- MUSA_SUCCESS, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_OPERATING_SYSTEM
Note
- This function may also return error codes from previous, asynchronous launches.
- If the Vulkan memory imported into MUSA is mapped on the CPU then the application must use vkInvalidateMappedMemoryRanges/vkFlushMappedMemoryRanges as well as appropriate Vulkan pipeline barriers to maintain coherence between CPU and GPU. For more information on these APIs, please refer to "Synchronization and Cache Control" chapter from Vulkan specification.
See also
muExternalMemoryGetMappedBuffer
MUresult muExternalMemoryGetMappedBuffer(MUdeviceptr *devPtr, MUexternalMemory extMem, const MUSA_EXTERNAL_MEMORY_BUFFER_DESC *bufferDesc)
Description
- Maps a buffer onto an imported memory object.
- Maps a buffer onto an imported memory object and returns a device pointer in devPtr.
- The properties of the buffer being mapped must be described in bufferDesc. The MUSA_EXTERNAL_MEMORY_BUFFER_DESC structure is defined as follows:
typedef struct MUSA_EXTERNAL_MEMORY_BUFFER_DESC_st {
unsigned long long offset;
unsigned long long size;
unsigned int flags;
} MUSA_EXTERNAL_MEMORY_BUFFER_DESC;
- where MUSA_EXTERNAL_MEMORY_BUFFER_DESC::offset is the offset in the memory object where the buffer's base address is. MUSA_EXTERNAL_MEMORY_BUFFER_DESC::size is the size of the buffer. MUSA_EXTERNAL_MEMORY_BUFFER_DESC::flags must be zero.
- The offset and size have to be suitably aligned to match the requirements of the external API. Mapping two buffers whose ranges overlap may or may not result in the same virtual address being returned for the overlapped portion. In such cases, the application must ensure that all accesses to that region from the GPU are volatile. Otherwise writes made via one address are not guaranteed to be visible via the other address, even if they're issued by the same thread. It is recommended that applications map the combined range instead of mapping separate buffers and then apply the appropriate offsets to the returned pointer to derive the individual buffers.
- The returned pointer devPtr must be freed using muMemFree.
Parameters
devPtr(MUdeviceptr *): Returned device pointer to bufferextMem(MUexternalMemory): Handle to external memory objectbufferDesc(const MUSA_EXTERNAL_MEMORY_BUFFER_DESC *): Buffer descriptor
Returns
- MUSA_SUCCESS, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muExternalMemoryGetMappedMipmappedArray
MUresult muExternalMemoryGetMappedMipmappedArray(MUmipmappedArray *mipmap, MUexternalMemory extMem, const MUSA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC *mipmapDesc)
Description
- Maps a MUSA mipmapped array onto an external memory object.
- Maps a MUSA mipmapped array onto an external object and returns a handle to it in mipmap.
- The properties of the MUSA mipmapped array being mapped must be described in mipmapDesc. The structure MUSA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC is defined as follows:
typedef struct MUSA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC_st {
unsigned long long offset;
MUSA_ARRAY3D_DESCRIPTORarrayDesc;
unsigned int numLevels;
} MUSA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC;
- where MUSA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC::offset is the offset in the memory object where the base level of the mipmap chain is. MUSA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC::arrayDesc describes the format, dimensions and type of the base level of the mipmap chain. For further details on these parameters, please refer to the documentation for muMipmappedArrayCreate. Note that if the mipmapped array is bound as a color target in the graphics API, then the flag MUSA_ARRAY3D_COLOR_ATTACHMENT must be specified in MUSA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC::arrayDesc::Flags. MUSA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC::numLevels specifies the total number of levels in the mipmap chain.
- If extMem was imported from a handle of type MU_EXTERNAL_MEMORY_HANDLE_TYPE_MTSCIBUF, then MUSA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC::numLevels must be equal to 1.
- Mapping extMem imported from a handle of type MU_EXTERNAL_MEMORY_HANDLE_TYPE_DMABUF_FD, is not supported.
- The returned MUSA mipmapped array must be freed using muMipmappedArrayDestroy.
Parameters
mipmap(MUmipmappedArray *): Returned MUSA mipmapped arrayextMem(MUexternalMemory): Handle to external memory objectmipmapDesc(const MUSA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC *): MUSA array descriptor
Returns
- MUSA_SUCCESS, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_VALUE, MUSA_ERROR_INVALID_HANDLE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muDestroyExternalMemory
MUresult muDestroyExternalMemory(MUexternalMemory extMem)
Description
- Destroys an external memory object.
- Destroys the specified external memory object. Any existing buffers and MUSA mipmapped arrays mapped onto this object must no longer be used and must be explicitly freed using muMemFree and muMipmappedArrayDestroy respectively.
Parameters
extMem(MUexternalMemory): External memory object to be destroyed
Returns
- MUSA_SUCCESS, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_HANDLE
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muImportExternalSemaphore
MUresult muImportExternalSemaphore(MUexternalSemaphore *extSem_out, const MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC *semHandleDesc)
Description
- Imports an external semaphore.
- Imports an externally allocated synchronization object and returns a handle to that in extSem_out.
- The properties of the handle being imported must be described in semHandleDesc. The MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC is defined as follows:
typedef struct MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC_st {
MUexternalSemaphoreHandleTypetype;
union {
int fd;
struct {
void *handle;
const void *name;
} win32;
const void *NvSciSyncObj;
} handle;
unsigned int flags;
} MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC;
- where MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::type specifies the type of handle being imported. MUexternalSemaphoreHandleType is defined as:
typedef enum MUexternalSemaphoreHandleType_enum {
MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD = 1,
MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32 = 2,
MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT = 3,
MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE = 4,
MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D11_FENCE = 5,
MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_MTSCISYNC = 6,
MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D11_KEYED_MUTEX = 7,
MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D11_KEYED_MUTEX_KMT = 8,
MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_FD = 9,
MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_WIN32 = 10;
} MUexternalSemaphoreHandleType;
- If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::type is MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD, then MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::fd must be a valid file descriptor referencing a synchronization object. Ownership of the file descriptor is transferred to the MUSA driver when the handle is imported successfully. Performing any operations on the file descriptor after it is imported results in undefined behavior.
- If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::type is MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32, then exactly one of MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::handle and MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::name must not be NULL. If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::handle is not NULL, then it must represent a valid shared NT handle that references a synchronization object. Ownership of this handle is not transferred to MUSA after the import operation, so the application must release the handle using the appropriate system call. If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::name is not NULL, then it must name a valid synchronization object.
- If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::type is MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT, then MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::handle must be non-NULL and MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::name must be NULL. The handle specified must be a globally shared KMT handle. This handle does not hold a reference to the underlying object, and thus will be invalid when all references to the synchronization object are destroyed.
- If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::type is MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE, then exactly one of MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::handle and MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::name must not be NULL. If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::handle is not NULL, then it must represent a valid shared NT handle that is returned by ID3D12Device::CreateSharedHandle when referring to a ID3D12Fence object. This handle holds a reference to the underlying object. If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::name is not NULL, then it must name a valid synchronization object that refers to a valid ID3D12Fence object.
- If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::type is MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D11_FENCE, then MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::handle represents a valid shared NT handle that is returned by ID3D11Fence::CreateSharedHandle. If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::name is not NULL, then it must name a valid synchronization object that refers to a valid ID3D11Fence object.
- If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::type is MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_MTSCISYNC, then MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::mtSciSyncObj represents a valid NvSciSyncObj.
- MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D11_KEYED_MUTEX, then MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::handle represents a valid shared NT handle that is returned by IDXGIResource1::CreateSharedHandle when referring to a IDXGIKeyedMutex object. If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::name is not NULL, then it must name a valid synchronization object that refers to a valid IDXGIKeyedMutex object.
- If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::type is MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D11_KEYED_MUTEX_KMT, then MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::handle represents a valid shared KMT handle that is returned by IDXGIResource::GetSharedHandle when referring to a IDXGIKeyedMutex object and MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::name must be NULL.
- If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::type is MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_FD, then MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::fd must be a valid file descriptor referencing a synchronization object. Ownership of the file descriptor is transferred to the MUSA driver when the handle is imported successfully. Performing any operations on the file descriptor after it is imported results in undefined behavior.
- If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::type is MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_WIN32, then exactly one of MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::handle and MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::name must not be NULL. If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::handle is not NULL, then it must represent a valid shared NT handle that references a synchronization object. Ownership of this handle is not transferred to MUSA after the import operation, so the application must release the handle using the appropriate system call. If MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC::handle::win32::name is not NULL, then it must name a valid synchronization object.
Parameters
extSem_out(MUexternalSemaphore *): Returned handle to an external semaphoresemHandleDesc(const MUSA_EXTERNAL_SEMAPHORE_HANDLE_DESC *): Semaphore import handle descriptor
Returns
- MUSA_SUCCESS, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_NOT_SUPPORTED, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_OPERATING_SYSTEM
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muSignalExternalSemaphoresAsync
MUresult muSignalExternalSemaphoresAsync(const MUexternalSemaphore *extSemArray, const MUSA_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS *paramsArray, unsigned int numExtSems, MUstream stream)
Description
- Signals a set of external semaphore objects.
- Enqueues a signal operation on a set of externally allocated semaphore object in the specified stream. The operations will be executed when all prior operations in the stream complete.
- The exact semantics of signaling a semaphore depends on the type of the object.
- If the semaphore object is any one of the following types: MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD, MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32, MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT then signaling the semaphore will set it to the signaled state.
- If the semaphore object is any one of the following types: MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE, MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D11_FENCE, MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_FD, MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_WIN32 then the semaphore will be set to the value specified in MUSA_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS::params::fence::value.
- If the semaphore object is of the type MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_MTSCISYNC this API sets MUSA_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS::params::mtSciSync::fence to a value that can be used by subsequent waiters of the same NvSciSync object to order operations with those currently submitted in stream. Such an update will overwrite previous contents of MUSA_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS::params::mtSciSync::fence. By default, signaling such an external semaphore object causes appropriate memory synchronization operations to be performed over all external memory objects that are imported as MU_EXTERNAL_MEMORY_HANDLE_TYPE_MTSCIBUF. This ensures that any subsequent accesses made by other importers of the same set of NvSciBuf memory object(s) are coherent. These operations can be skipped by specifying the flag MUSA_EXTERNAL_SEMAPHORE_SIGNAL_SKIP_MTSCIBUF_MEMSYNC, which can be used as a performance optimization when data coherency is not required. But specifying this flag in scenarios where data coherency is required results in undefined behavior. Also, for semaphore object of the type MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_MTSCISYNC, if the NvSciSyncAttrList used to create the NvSciSyncObj had not set the flags in muDeviceGetMtSciSyncAttributes to MUSA_MTSCISYNC_ATTR_SIGNAL, this API will return MUSA_ERROR_NOT_SUPPORTED. NvSciSyncFence associated with semaphore object of the type MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_MTSCISYNC can be deterministic. For this the NvSciSyncAttrList used to create the semaphore object must have value of NvSciSyncAttrKey_RequireDeterministicFences key set to true. Deterministic fences allow users to enqueue a wait over the semaphore object even before corresponding signal is enqueued. For such a semaphore object, MUSA guarantees that each signal operation will increment the fence value by '1'. Users are expected to track count of signals enqueued on the semaphore object and insert waits accordingly. When such a semaphore object is signaled from multiple streams, due to concurrent stream execution, it is possible that the order in which the semaphore gets signaled is indeterministic. This could lead to waiters of the semaphore getting unblocked incorrectly. Users are expected to handle such situations, either by not using the same semaphore object with deterministic fence support enabled in different streams or by adding explicit dependency amongst such streams so that the semaphore is signaled in order. NvSciSyncFence associated with semaphore object of the type MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_NVSCISYNC can be timestamp enabled. For this the NvSciSyncAttrList used to create the object must have the value of NvSciSyncAttrKey_WaiterRequireTimestamps key set to true. Timestamps are emitted asynchronously by the GPU and MUSA saves the GPU timestamp in the corresponding NvSciSyncFence at the time of signal on GPU. Users are expected to convert GPU clocks to CPU clocks using appropriate scaling functions. Users are expected to wait for the completion of the fence before extracting timestamp using appropriate NvSciSync APIs. Users are expected to ensure that there is only one outstanding timestamp enabled fence per Musa-MtSciSync object at any point of time, failing which leads to undefined behavior. Extracting the timestamp before the corresponding fence is signalled could lead to undefined behaviour. Timestamp extracted via appropriate NvSciSync API would be in microseconds.
- If the semaphore object is any one of the following types: MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D11_KEYED_MUTEX, MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D11_KEYED_MUTEX_KMT then the keyed mutex will be released with the key specified in MUSA_EXTERNAL_SEMAPHORE_PARAMS::params::keyedmutex::key.
Parameters
extSemArray(const MUexternalSemaphore *): Set of external semaphores to be signaledparamsArray(const MUSA_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS *): Array of semaphore parametersnumExtSems(unsigned int): Number of semaphores to signalstream(MUstream): Stream to enqueue the signal operations in
Returns
- MUSA_SUCCESS, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_SUPPORTED
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muWaitExternalSemaphoresAsync
MUresult muWaitExternalSemaphoresAsync(const MUexternalSemaphore *extSemArray, const MUSA_EXTERNAL_SEMAPHORE_WAIT_PARAMS *paramsArray, unsigned int numExtSems, MUstream stream)
Description
- Waits on a set of external semaphore objects.
- Enqueues a wait operation on a set of externally allocated semaphore object in the specified stream. The operations will be executed when all prior operations in the stream complete.
- The exact semantics of waiting on a semaphore depends on the type of the object.
- If the semaphore object is any one of the following types: MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD, MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32, MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT then waiting on the semaphore will wait until the semaphore reaches the signaled state. The semaphore will then be reset to the unsignaled state. Therefore for every signal operation, there can only be one wait operation.
- If the semaphore object is any one of the following types: MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE, MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D11_FENCE, MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_FD, MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TIMELINE_SEMAPHORE_WIN32 then waiting on the semaphore will wait until the value of the semaphore is greater than or equal to MUSA_EXTERNAL_SEMAPHORE_WAIT_PARAMS::params::fence::value.
- If the semaphore object is of the type MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_MTSCISYNC then, waiting on the semaphore will wait until the MUSA_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS::params::mtSciSync::fence is signaled by the signaler of the NvSciSyncObj that was associated with this semaphore object. By default, waiting on such an external semaphore object causes appropriate memory synchronization operations to be performed over all external memory objects that are imported as MU_EXTERNAL_MEMORY_HANDLE_TYPE_MTSCIBUF. This ensures that any subsequent accesses made by other importers of the same set of NvSciBuf memory object(s) are coherent. These operations can be skipped by specifying the flag MUSA_EXTERNAL_SEMAPHORE_WAIT_SKIP_MTSCIBUF_MEMSYNC, which can be used as a performance optimization when data coherency is not required. But specifying this flag in scenarios where data coherency is required results in undefined behavior. Also, for semaphore object of the type MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_MTSCISYNC, if the NvSciSyncAttrList used to create the NvSciSyncObj had not set the flags in muDeviceGetMtSciSyncAttributes to MUSA_MTSCISYNC_ATTR_WAIT, this API will return MUSA_ERROR_NOT_SUPPORTED.
- If the semaphore object is any one of the following types: MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D11_KEYED_MUTEX, MU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D11_KEYED_MUTEX_KMT then the keyed mutex will be acquired when it is released with the key specified in MUSA_EXTERNAL_SEMAPHORE_WAIT_PARAMS::params::keyedmutex::key or until the timeout specified by MUSA_EXTERNAL_SEMAPHORE_WAIT_PARAMS::params::keyedmutex::timeoutMs has lapsed. The timeout interval can either be a finite value specified in milliseconds or an infinite value. In case an infinite value is specified the timeout never elapses. The windows INFINITE macro must be used to specify infinite timeout.
Parameters
extSemArray(const MUexternalSemaphore *): External semaphores to be waited onparamsArray(const MUSA_EXTERNAL_SEMAPHORE_WAIT_PARAMS *): Array of semaphore parametersnumExtSems(unsigned int): Number of semaphores to wait onstream(MUstream): Stream to enqueue the wait operations in
Returns
- MUSA_SUCCESS, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_HANDLE, MUSA_ERROR_NOT_SUPPORTED, MUSA_ERROR_TIMEOUT
Note
- This function may also return error codes from previous, asynchronous launches.
See also
muDestroyExternalSemaphore
MUresult muDestroyExternalSemaphore(MUexternalSemaphore extSem)
Description
- Destroys an external semaphore.
- Destroys an external semaphore object and releases any references to the underlying resource. Any outstanding signals or waits must have completed before the semaphore is destroyed.
Parameters
extSem(MUexternalSemaphore): External semaphore to be destroyed
Returns
- MUSA_SUCCESS, MUSA_ERROR_NOT_INITIALIZED, MUSA_ERROR_INVALID_HANDLE
Note
- This function may also return error codes from previous, asynchronous launches.
See also